From 8b9cdb94410dce2f27c7d759ea138ed4dc7906f4 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 19 Sep 2018 09:01:00 -0700 Subject: [PATCH 001/569] Refactor implementation of to/fromJson methods on fields (#317) The ConvertHelper class exposed in 1.3.0 is effectively worthless outside of json_serializable because it relies on internal state that assumes the in-box generator. This commit exposes the hooks necessary for another generator to use ConvertHelper by providing callbacks for providing ConvertData for a given context. Eliminates the internal JsonKeyWithConversion class Exposes a new ConvertData class Refactors the to/fromJson logic out of `json_key_with_conversion.dart` into its own file - which should make maintenance easier --- json_serializable/CHANGELOG.md | 10 + json_serializable/lib/src/convert_pair.dart | 89 +++++++++ json_serializable/lib/src/helper_core.dart | 3 +- .../lib/src/json_key_with_conversion.dart | 186 ++++++------------ .../lib/src/json_serializable_generator.dart | 3 +- .../lib/src/type_helper_context.dart | 19 +- .../lib/src/type_helpers/convert_helper.dart | 17 +- json_serializable/pubspec.yaml | 2 +- 8 files changed, 187 insertions(+), 142 deletions(-) create mode 100644 json_serializable/lib/src/convert_pair.dart diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 3b250375b..7d4dce02f 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,13 @@ +## 2.0.0 + +* `package:json_serializable/type_helper.dart` + + * **BREAKING** `ConvertHelper` constructor now has two required arguments + which allow it to find `ConvertData` associated with custom field serialize + methods. + + * Added new class `ConvertData`. + ## 1.3.0 * Add support for types annotated with classes that extend `JsonConverter` from diff --git a/json_serializable/lib/src/convert_pair.dart b/json_serializable/lib/src/convert_pair.dart new file mode 100644 index 000000000..f85f6605d --- /dev/null +++ b/json_serializable/lib/src/convert_pair.dart @@ -0,0 +1,89 @@ +// Copyright (c) 2018, 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:analyzer/dart/element/element.dart'; +import 'package:analyzer/dart/element/type.dart'; +import 'package:analyzer/dart/constant/value.dart'; +import 'package:json_annotation/json_annotation.dart'; + +import 'type_helpers/convert_helper.dart'; +import 'utils.dart'; + +class ConvertPair { + static final _expando = Expando(); + static ConvertPair fromJsonKey(JsonKey key) => _expando[key]; + + final ConvertData fromJson, toJson; + + ConvertPair._(this.fromJson, this.toJson); + + factory ConvertPair(DartObject obj, FieldElement element) { + var toJson = _convertData(obj, element, false); + var fromJson = _convertData(obj, element, true); + + return ConvertPair._(fromJson, toJson); + } + + void populate(JsonKey key) { + _expando[key] = this; + } +} + +ConvertData _convertData(DartObject obj, FieldElement element, bool isFrom) { + var paramName = isFrom ? 'fromJson' : 'toJson'; + var objectValue = obj.getField(paramName); + + if (objectValue.isNull) { + return null; + } + + var type = objectValue.type as FunctionType; + + var executableElement = type.element as ExecutableElement; + + if (executableElement.parameters.isEmpty || + executableElement.parameters.first.isNamed || + executableElement.parameters.where((pe) => !pe.isOptional).length > 1) { + throwUnsupported( + element, + 'The `$paramName` function `${executableElement.name}` must have one ' + 'positional paramater.'); + } + + var argType = executableElement.parameters.first.type; + if (isFrom) { + var returnType = executableElement.returnType; + + if (returnType is TypeParameterType) { + // We keep things simple in this case. We rely on inferred type arguments + // to the `fromJson` function. + // TODO: consider adding error checking here if there is confusion. + } else if (!returnType.isAssignableTo(element.type)) { + throwUnsupported( + element, + 'The `$paramName` function `${executableElement.name}` return type ' + '`$returnType` is not compatible with field type `${element.type}`.'); + } + } else { + if (argType is TypeParameterType) { + // We keep things simple in this case. We rely on inferred type arguments + // to the `fromJson` function. + // TODO: consider adding error checking here if there is confusion. + } else if (!element.type.isAssignableTo(argType)) { + throwUnsupported( + element, + 'The `$paramName` function `${executableElement.name}` argument type ' + '`$argType` is not compatible with field type' + ' `${element.type}`.'); + } + } + + var name = executableElement.name; + + if (executableElement is MethodElement) { + name = '${executableElement.enclosingElement.name}.$name'; + } + + return ConvertData(name, argType); +} diff --git a/json_serializable/lib/src/helper_core.dart b/json_serializable/lib/src/helper_core.dart index ebc7d2419..a49398325 100644 --- a/json_serializable/lib/src/helper_core.dart +++ b/json_serializable/lib/src/helper_core.dart @@ -39,8 +39,7 @@ abstract class HelperCore { String genericClassArgumentsImpl(bool withConstraints) => genericClassArguments(element, withConstraints); - JsonKeyWithConversion jsonKeyFor(FieldElement field) => - JsonKeyWithConversion(field, annotation); + JsonKey jsonKeyFor(FieldElement field) => jsonKeyForField(field, annotation); TypeHelperContext getHelperContext(FieldElement field) => TypeHelperContext(this, field.metadata, jsonKeyFor(field)); diff --git a/json_serializable/lib/src/json_key_with_conversion.dart b/json_serializable/lib/src/json_key_with_conversion.dart index 03df04cf3..29a5fcb0d 100644 --- a/json_serializable/lib/src/json_key_with_conversion.dart +++ b/json_serializable/lib/src/json_key_with_conversion.dart @@ -5,10 +5,10 @@ import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/type.dart'; import 'package:analyzer/dart/constant/value.dart'; - import 'package:json_annotation/json_annotation.dart'; import 'package:source_gen/source_gen.dart'; +import 'convert_pair.dart'; import 'json_literal_generator.dart'; import 'utils.dart'; @@ -24,18 +24,20 @@ DartObject _jsonKeyAnnotation(FieldElement element) => bool hasJsonKeyAnnotation(FieldElement element) => _jsonKeyAnnotation(element) != null; -JsonKeyWithConversion _from( - FieldElement element, JsonSerializable classAnnotation) { +final _jsonKeyExpando = Expando(); + +JsonKey jsonKeyForField(FieldElement field, JsonSerializable classAnnotation) => + _jsonKeyExpando[field] ??= _from(field, classAnnotation); + +JsonKey _from(FieldElement element, JsonSerializable classAnnotation) { // If an annotation exists on `element` the source is a 'real' field. // If the result is `null`, check the getter – it is a property. // TODO(kevmoo) setters: github.com/dart-lang/json_serializable/issues/24 var obj = _jsonKeyAnnotation(element); if (obj == null) { - return JsonKeyWithConversion._(classAnnotation, element); + return _populateJsonKey(classAnnotation, element); } - var fromJsonName = _getFunctionName(obj, element, true); - var toJsonName = _getFunctionName(obj, element, false); Object _getLiteral(DartObject dartObject, Iterable things) { if (dartObject.isNull) { @@ -114,143 +116,69 @@ JsonKeyWithConversion _from( } } - return JsonKeyWithConversion._(classAnnotation, element, - name: obj.getField('name').toStringValue(), - nullable: obj.getField('nullable').toBoolValue(), - includeIfNull: includeIfNull, - ignore: obj.getField('ignore').toBoolValue(), - defaultValue: defaultValueLiteral, - required: obj.getField('required').toBoolValue(), - disallowNullValue: disallowNullValue, - fromJsonData: fromJsonName, - toJsonData: toJsonName); + return _populateJsonKey( + classAnnotation, + element, + name: obj.getField('name').toStringValue(), + nullable: obj.getField('nullable').toBoolValue(), + includeIfNull: includeIfNull, + ignore: obj.getField('ignore').toBoolValue(), + defaultValue: defaultValueLiteral, + required: obj.getField('required').toBoolValue(), + disallowNullValue: disallowNullValue, + jsonConvertPair: ConvertPair(obj, element), + ); } -class ConvertData { - final String name; - final DartType paramType; - - ConvertData._(this.name, this.paramType); -} - -class JsonKeyWithConversion extends JsonKey { - static final _jsonKeyExpando = Expando(); - - final ConvertData fromJsonData; - final ConvertData toJsonData; - - factory JsonKeyWithConversion( - FieldElement element, JsonSerializable classAnnotation) => - _jsonKeyExpando[element] ??= _from(element, classAnnotation); - - JsonKeyWithConversion._( - JsonSerializable classAnnotation, - FieldElement fieldElement, { - String name, +JsonKey _populateJsonKey( + JsonSerializable classAnnotation, FieldElement fieldElement, + {String name, bool nullable, bool includeIfNull, bool ignore, Object defaultValue, bool required, bool disallowNullValue, - this.fromJsonData, - this.toJsonData, - }) : super( - name: _processName(classAnnotation, name, fieldElement), - nullable: nullable ?? classAnnotation.nullable, - includeIfNull: _includeIfNull(includeIfNull, disallowNullValue, - classAnnotation.includeIfNull), - ignore: ignore ?? false, - defaultValue: defaultValue, - required: required ?? false, - disallowNullValue: disallowNullValue ?? false) { - assert(!this.includeIfNull || !this.disallowNullValue); - } - - static String _processName(JsonSerializable classAnnotation, - String jsonKeyNameValue, FieldElement fieldElement) { - if (jsonKeyNameValue != null) { - return jsonKeyNameValue; - } - - switch (classAnnotation.fieldRename) { - case FieldRename.none: - // noop - break; - case FieldRename.snake: - return snakeCase(fieldElement.name); - case FieldRename.kebab: - return kebabCase(fieldElement.name); - } - - return fieldElement.name; - } - - static bool _includeIfNull(bool keyIncludeIfNull, bool keyDisallowNullValue, - bool classIncludeIfNull) { - if (keyDisallowNullValue == true) { - assert(keyIncludeIfNull != true); - return false; - } - return keyIncludeIfNull ?? classIncludeIfNull; - } + ConvertPair jsonConvertPair}) { + var jsonKey = JsonKey( + name: _encodedFieldName(classAnnotation, name, fieldElement), + nullable: nullable ?? classAnnotation.nullable, + includeIfNull: _includeIfNull( + includeIfNull, disallowNullValue, classAnnotation.includeIfNull), + ignore: ignore ?? false, + defaultValue: defaultValue, + required: required ?? false, + disallowNullValue: disallowNullValue ?? false); + + jsonConvertPair?.populate(jsonKey); + + return jsonKey; } -ConvertData _getFunctionName( - DartObject obj, FieldElement element, bool isFrom) { - var paramName = isFrom ? 'fromJson' : 'toJson'; - var objectValue = obj.getField(paramName); - - if (objectValue.isNull) { - return null; +String _encodedFieldName(JsonSerializable classAnnotation, + String jsonKeyNameValue, FieldElement fieldElement) { + if (jsonKeyNameValue != null) { + return jsonKeyNameValue; } - var type = objectValue.type as FunctionType; - - var executableElement = type.element as ExecutableElement; - - if (executableElement.parameters.isEmpty || - executableElement.parameters.first.isNamed || - executableElement.parameters.where((pe) => !pe.isOptional).length > 1) { - throwUnsupported( - element, - 'The `$paramName` function `${executableElement.name}` must have one ' - 'positional paramater.'); - } - - var argType = executableElement.parameters.first.type; - if (isFrom) { - var returnType = executableElement.returnType; - - if (returnType is TypeParameterType) { - // We keep things simple in this case. We rely on inferred type arguments - // to the `fromJson` function. - // TODO: consider adding error checking here if there is confusion. - } else if (!returnType.isAssignableTo(element.type)) { - throwUnsupported( - element, - 'The `$paramName` function `${executableElement.name}` return type ' - '`$returnType` is not compatible with field type `${element.type}`.'); - } - } else { - if (argType is TypeParameterType) { - // We keep things simple in this case. We rely on inferred type arguments - // to the `fromJson` function. - // TODO: consider adding error checking here if there is confusion. - } else if (!element.type.isAssignableTo(argType)) { - throwUnsupported( - element, - 'The `$paramName` function `${executableElement.name}` argument type ' - '`$argType` is not compatible with field type' - ' `${element.type}`.'); - } + switch (classAnnotation.fieldRename) { + case FieldRename.none: + // noop + break; + case FieldRename.snake: + return snakeCase(fieldElement.name); + case FieldRename.kebab: + return kebabCase(fieldElement.name); } - var name = executableElement.name; + return fieldElement.name; +} - if (executableElement is MethodElement) { - name = '${executableElement.enclosingElement.name}.$name'; +bool _includeIfNull( + bool keyIncludeIfNull, bool keyDisallowNullValue, bool classIncludeIfNull) { + if (keyDisallowNullValue == true) { + assert(keyIncludeIfNull != true); + return false; } - - return ConvertData._(name, argType); + return keyIncludeIfNull ?? classIncludeIfNull; } diff --git a/json_serializable/lib/src/json_serializable_generator.dart b/json_serializable/lib/src/json_serializable_generator.dart index deb94daf5..a0095abed 100644 --- a/json_serializable/lib/src/json_serializable_generator.dart +++ b/json_serializable/lib/src/json_serializable_generator.dart @@ -12,6 +12,7 @@ import 'encoder_helper.dart'; import 'field_helpers.dart'; import 'helper_core.dart'; import 'type_helper.dart'; +import 'type_helper_context.dart'; import 'type_helpers/convert_helper.dart'; import 'type_helpers/date_time_helper.dart'; import 'type_helpers/enum_helper.dart'; @@ -40,7 +41,7 @@ class JsonSerializableGenerator final List _typeHelpers; Iterable get _allHelpers => const [ - ConvertHelper(), + ConvertHelper(serializeData, deserializeData), JsonConverterHelper() ].followedBy(_typeHelpers).followedBy(_coreHelpers); diff --git a/json_serializable/lib/src/type_helper_context.dart b/json_serializable/lib/src/type_helper_context.dart index 42135af14..de7e6d47c 100644 --- a/json_serializable/lib/src/type_helper_context.dart +++ b/json_serializable/lib/src/type_helper_context.dart @@ -4,19 +4,31 @@ import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/type.dart'; +import 'package:json_annotation/json_annotation.dart'; +import 'convert_pair.dart'; import 'helper_core.dart'; -import 'json_key_with_conversion.dart'; import 'json_serializable_generator.dart'; import 'type_helper.dart'; +import 'type_helpers/convert_helper.dart'; + +ConvertData serializeData(SerializeContext ctx) => + _pairFromContext(ctx as TypeHelperContext)?.toJson; + +ConvertData deserializeData(DeserializeContext ctx) => + _pairFromContext(ctx as TypeHelperContext)?.fromJson; + +ConvertPair _pairFromContext(TypeHelperContext ctx) => + ConvertPair.fromJsonKey(ctx._key); + class TypeHelperContext implements SerializeContext, DeserializeContext { final HelperCore _helperCore; @override final List metadata; - final JsonKeyWithConversion _key; + final JsonKey _key; @override bool get useWrappers => _helperCore.generator.useWrappers; @@ -30,9 +42,6 @@ class TypeHelperContext implements SerializeContext, DeserializeContext { @override bool get nullable => _key.nullable; - ConvertData get fromJsonData => _key.fromJsonData; - ConvertData get toJsonData => _key.toJsonData; - TypeHelperContext(this._helperCore, this.metadata, this._key); @override diff --git a/json_serializable/lib/src/type_helpers/convert_helper.dart b/json_serializable/lib/src/type_helpers/convert_helper.dart index c8ca63240..ab69ae284 100644 --- a/json_serializable/lib/src/type_helpers/convert_helper.dart +++ b/json_serializable/lib/src/type_helpers/convert_helper.dart @@ -6,15 +6,24 @@ import 'package:analyzer/dart/element/type.dart'; import '../shared_checkers.dart'; import '../type_helper.dart'; -import '../type_helper_context.dart'; + +class ConvertData { + final String name; + final DartType paramType; + + ConvertData(this.name, this.paramType); +} class ConvertHelper extends TypeHelper { - const ConvertHelper(); + final ConvertData Function(SerializeContext) serializeConvertData; + final ConvertData Function(DeserializeContext) deserializeConvertData; + + const ConvertHelper(this.serializeConvertData, this.deserializeConvertData); @override String serialize( DartType targetType, String expression, SerializeContext context) { - var toJsonData = (context as TypeHelperContext).toJsonData; + var toJsonData = serializeConvertData(context); if (toJsonData != null) { assert(toJsonData.paramType is TypeParameterType || targetType.isAssignableTo(toJsonData.paramType)); @@ -27,7 +36,7 @@ class ConvertHelper extends TypeHelper { @override String deserialize( DartType targetType, String expression, DeserializeContext context) { - var fromJsonData = (context as TypeHelperContext).fromJsonData; + var fromJsonData = deserializeConvertData(context); if (fromJsonData != null) { var asContent = asStatement(fromJsonData.paramType); var result = '${fromJsonData.name}($expression$asContent)'; diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 62af1dd9c..e23294834 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 1.3.0 +version: 2.0.0-dev author: Dart Team description: Generates utilities to aid in serializing to/from JSON. homepage: https://github.com/dart-lang/json_serializable From cdc2c275ac496750beda548d6439bd982a2f6a1d Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 19 Sep 2018 14:49:11 -0700 Subject: [PATCH 002/569] Replace *erializeContext with TypeHelperContext (#318) Eliminates special knowledge of internal implementation types from exported TypeHelpers --- json_serializable/CHANGELOG.md | 5 ++- json_serializable/lib/src/helper_core.dart | 4 +- .../lib/src/json_serializable_generator.dart | 2 +- json_serializable/lib/src/type_helper.dart | 39 +++++++++++-------- ...lper_context.dart => type_helper_ctx.dart} | 35 ++++++++++------- .../lib/src/type_helpers/convert_helper.dart | 8 ++-- .../src/type_helpers/date_time_helper.dart | 4 +- .../lib/src/type_helpers/enum_helper.dart | 4 +- .../lib/src/type_helpers/iterable_helper.dart | 4 +- .../type_helpers/json_converter_helper.dart | 9 ++--- .../lib/src/type_helpers/json_helper.dart | 9 ++--- .../lib/src/type_helpers/map_helper.dart | 12 +++--- .../lib/src/type_helpers/uri_helper.dart | 4 +- .../lib/src/type_helpers/value_helper.dart | 4 +- json_serializable/lib/type_helper.dart | 2 +- 15 files changed, 78 insertions(+), 67 deletions(-) rename json_serializable/lib/src/{type_helper_context.dart => type_helper_ctx.dart} (76%) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 7d4dce02f..13da5ad65 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,6 +1,9 @@ ## 2.0.0 -* `package:json_serializable/type_helper.dart` +* `type_helper.dart` + + * **BREAKING** `SerializeContext` and `DeserializeContext` have been replaced + with new `TypeHelperContext` class. * **BREAKING** `ConvertHelper` constructor now has two required arguments which allow it to find `ConvertData` associated with custom field serialize diff --git a/json_serializable/lib/src/helper_core.dart b/json_serializable/lib/src/helper_core.dart index a49398325..ea7bb4c14 100644 --- a/json_serializable/lib/src/helper_core.dart +++ b/json_serializable/lib/src/helper_core.dart @@ -10,7 +10,7 @@ import 'package:source_gen/source_gen.dart'; import 'json_key_with_conversion.dart'; import 'json_serializable_generator.dart'; import 'type_helper.dart'; -import 'type_helper_context.dart'; +import 'type_helper_ctx.dart'; import 'utils.dart'; abstract class HelperCore { @@ -42,7 +42,7 @@ abstract class HelperCore { JsonKey jsonKeyFor(FieldElement field) => jsonKeyForField(field, annotation); TypeHelperContext getHelperContext(FieldElement field) => - TypeHelperContext(this, field.metadata, jsonKeyFor(field)); + typeHelperContext(this, field, jsonKeyFor(field)); } InvalidGenerationSourceError createInvalidGenerationError( diff --git a/json_serializable/lib/src/json_serializable_generator.dart b/json_serializable/lib/src/json_serializable_generator.dart index a0095abed..e1d60e5c4 100644 --- a/json_serializable/lib/src/json_serializable_generator.dart +++ b/json_serializable/lib/src/json_serializable_generator.dart @@ -12,7 +12,7 @@ import 'encoder_helper.dart'; import 'field_helpers.dart'; import 'helper_core.dart'; import 'type_helper.dart'; -import 'type_helper_context.dart'; +import 'type_helper_ctx.dart'; import 'type_helpers/convert_helper.dart'; import 'type_helpers/date_time_helper.dart'; import 'type_helpers/enum_helper.dart'; diff --git a/json_serializable/lib/src/type_helper.dart b/json_serializable/lib/src/type_helper.dart index f4ea5d4e8..37c204e82 100644 --- a/json_serializable/lib/src/type_helper.dart +++ b/json_serializable/lib/src/type_helper.dart @@ -5,25 +5,34 @@ import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/type.dart'; -abstract class SerializeContext { - /// `true` if [serialize] should handle the case of `expression` being null. - bool get nullable; +/// Context information provided in calls to [TypeHelper.serialize] and +/// [TypeHelper.deserialize]. +abstract class TypeHelperContext { + /// The annotated class that code is being generated for. + ClassElement get classElement; + + /// The field that code is being generated for. + FieldElement get fieldElement; + + /// Represents the corresponding configuration on `JsonSerializableGenerator`. + bool get explicitToJson; + + /// Represents the corresponding configuration on `JsonSerializableGenerator`. + bool get anyMap; + + /// Represents the corresponding configuration on `JsonSerializableGenerator`. bool get useWrappers; + /// Returns `true` if [fieldElement] could potentially contain a `null` value. + bool get nullable; + /// [expression] may be just the name of the field or it may an expression /// representing the serialization of a value. String serialize(DartType fieldType, String expression); - List get metadata; - /// Adds [memberContent] to the set of generated, top-level members. - void addMember(String memberContent); -} - -abstract class DeserializeContext { - /// `true` if [deserialize] should handle the case of `expression` being null. - bool get nullable; + /// [expression] may be just the name of the field or it may an expression + /// representing the serialization of a value. String deserialize(DartType fieldType, String expression); - List get metadata; /// Adds [memberContent] to the set of generated, top-level members. void addMember(String memberContent); @@ -47,9 +56,8 @@ abstract class TypeHelper { /// String serialize(DartType targetType, String expression) => /// "$expression.id"; /// ```. - // TODO(kevmoo) – document `context` String serialize( - DartType targetType, String expression, SerializeContext context); + DartType targetType, String expression, TypeHelperContext context); /// Returns Dart code that deserializes an [expression] representing a JSON /// literal to into [targetType]. @@ -74,9 +82,8 @@ abstract class TypeHelper { /// String deserialize(DartType targetType, String expression) => /// "new ${targetType.name}.fromInt($expression)"; /// ```. - // TODO(kevmoo) – document `context` String deserialize( - DartType targetType, String expression, DeserializeContext context); + DartType targetType, String expression, TypeHelperContext context); } class UnsupportedTypeError extends Error { diff --git a/json_serializable/lib/src/type_helper_context.dart b/json_serializable/lib/src/type_helper_ctx.dart similarity index 76% rename from json_serializable/lib/src/type_helper_context.dart rename to json_serializable/lib/src/type_helper_ctx.dart index de7e6d47c..52e80a86f 100644 --- a/json_serializable/lib/src/type_helper_context.dart +++ b/json_serializable/lib/src/type_helper_ctx.dart @@ -10,39 +10,44 @@ import 'convert_pair.dart'; import 'helper_core.dart'; import 'json_serializable_generator.dart'; import 'type_helper.dart'; - import 'type_helpers/convert_helper.dart'; -ConvertData serializeData(SerializeContext ctx) => - _pairFromContext(ctx as TypeHelperContext)?.toJson; +ConvertData serializeData(TypeHelperContext ctx) => + _pairFromContext(ctx)?.toJson; -ConvertData deserializeData(DeserializeContext ctx) => - _pairFromContext(ctx as TypeHelperContext)?.fromJson; +ConvertData deserializeData(TypeHelperContext ctx) => + _pairFromContext(ctx)?.fromJson; ConvertPair _pairFromContext(TypeHelperContext ctx) => - ConvertPair.fromJsonKey(ctx._key); + ConvertPair.fromJsonKey((ctx as _TypeHelperCtx)._key); + +TypeHelperContext typeHelperContext( + HelperCore helperCore, FieldElement fieldElement, JsonKey key) => + _TypeHelperCtx(helperCore, fieldElement, key); -class TypeHelperContext implements SerializeContext, DeserializeContext { +class _TypeHelperCtx implements TypeHelperContext { final HelperCore _helperCore; + final JsonKey _key; @override - final List metadata; + final FieldElement fieldElement; - final JsonKey _key; + @override + bool get nullable => _key.nullable; + + @override + ClassElement get classElement => _helperCore.element; @override bool get useWrappers => _helperCore.generator.useWrappers; + @override bool get anyMap => _helperCore.generator.anyMap; - bool get explicitToJson => _helperCore.generator.explicitToJson; - - ClassElement get classElement => _helperCore.element; - @override - bool get nullable => _key.nullable; + bool get explicitToJson => _helperCore.generator.explicitToJson; - TypeHelperContext(this._helperCore, this.metadata, this._key); + _TypeHelperCtx(this._helperCore, this.fieldElement, this._key); @override void addMember(String memberContent) { diff --git a/json_serializable/lib/src/type_helpers/convert_helper.dart b/json_serializable/lib/src/type_helpers/convert_helper.dart index ab69ae284..1e7e4252a 100644 --- a/json_serializable/lib/src/type_helpers/convert_helper.dart +++ b/json_serializable/lib/src/type_helpers/convert_helper.dart @@ -15,14 +15,14 @@ class ConvertData { } class ConvertHelper extends TypeHelper { - final ConvertData Function(SerializeContext) serializeConvertData; - final ConvertData Function(DeserializeContext) deserializeConvertData; + final ConvertData Function(TypeHelperContext) serializeConvertData; + final ConvertData Function(TypeHelperContext) deserializeConvertData; const ConvertHelper(this.serializeConvertData, this.deserializeConvertData); @override String serialize( - DartType targetType, String expression, SerializeContext context) { + DartType targetType, String expression, TypeHelperContext context) { var toJsonData = serializeConvertData(context); if (toJsonData != null) { assert(toJsonData.paramType is TypeParameterType || @@ -35,7 +35,7 @@ class ConvertHelper extends TypeHelper { @override String deserialize( - DartType targetType, String expression, DeserializeContext context) { + DartType targetType, String expression, TypeHelperContext context) { var fromJsonData = deserializeConvertData(context); if (fromJsonData != null) { var asContent = asStatement(fromJsonData.paramType); diff --git a/json_serializable/lib/src/type_helpers/date_time_helper.dart b/json_serializable/lib/src/type_helpers/date_time_helper.dart index 36baa52e3..d09301db1 100644 --- a/json_serializable/lib/src/type_helpers/date_time_helper.dart +++ b/json_serializable/lib/src/type_helpers/date_time_helper.dart @@ -11,7 +11,7 @@ class DateTimeHelper extends TypeHelper { @override String serialize( - DartType targetType, String expression, SerializeContext context) { + DartType targetType, String expression, TypeHelperContext context) { if (!_matchesType(targetType)) { return null; } @@ -29,7 +29,7 @@ class DateTimeHelper extends TypeHelper { @override String deserialize( - DartType targetType, String expression, DeserializeContext context) { + DartType targetType, String expression, TypeHelperContext context) { if (!_matchesType(targetType)) { return null; } diff --git a/json_serializable/lib/src/type_helpers/enum_helper.dart b/json_serializable/lib/src/type_helpers/enum_helper.dart index 0c11a31fe..f5c061f1e 100644 --- a/json_serializable/lib/src/type_helpers/enum_helper.dart +++ b/json_serializable/lib/src/type_helpers/enum_helper.dart @@ -15,7 +15,7 @@ class EnumHelper extends TypeHelper { @override String serialize( - DartType targetType, String expression, SerializeContext context) { + DartType targetType, String expression, TypeHelperContext context) { var memberContent = _enumValueMapFromType(targetType); if (memberContent == null) { @@ -29,7 +29,7 @@ class EnumHelper extends TypeHelper { @override String deserialize( - DartType targetType, String expression, DeserializeContext context) { + DartType targetType, String expression, TypeHelperContext context) { var memberContent = _enumValueMapFromType(targetType); if (memberContent == null) { diff --git a/json_serializable/lib/src/type_helpers/iterable_helper.dart b/json_serializable/lib/src/type_helpers/iterable_helper.dart index 252855909..308585505 100644 --- a/json_serializable/lib/src/type_helpers/iterable_helper.dart +++ b/json_serializable/lib/src/type_helpers/iterable_helper.dart @@ -14,7 +14,7 @@ class IterableHelper extends TypeHelper { @override String serialize( - DartType targetType, String expression, SerializeContext context) { + DartType targetType, String expression, TypeHelperContext context) { if (!coreIterableTypeChecker.isAssignableFromType(targetType)) { return null; } @@ -61,7 +61,7 @@ class IterableHelper extends TypeHelper { @override String deserialize( - DartType targetType, String expression, DeserializeContext context) { + DartType targetType, String expression, TypeHelperContext context) { if (!coreIterableTypeChecker.isAssignableFromType(targetType)) { return null; } diff --git a/json_serializable/lib/src/type_helpers/json_converter_helper.dart b/json_serializable/lib/src/type_helpers/json_converter_helper.dart index 4fb94ee46..2ddd2f883 100644 --- a/json_serializable/lib/src/type_helpers/json_converter_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_converter_helper.dart @@ -11,7 +11,6 @@ import 'package:source_gen/source_gen.dart'; import '../shared_checkers.dart'; import '../type_helper.dart'; -import '../type_helper_context.dart'; /// A [TypeHelper] that supports classes annotated with implementations of /// [JsonConverter]. @@ -20,8 +19,8 @@ class JsonConverterHelper extends TypeHelper { @override String serialize( - DartType targetType, String expression, SerializeContext context) { - var converter = _typeConverter(targetType, context as TypeHelperContext); + DartType targetType, String expression, TypeHelperContext context) { + var converter = _typeConverter(targetType, context); if (converter == null) { return null; @@ -32,8 +31,8 @@ class JsonConverterHelper extends TypeHelper { @override String deserialize( - DartType targetType, String expression, DeserializeContext context) { - var converter = _typeConverter(targetType, context as TypeHelperContext); + DartType targetType, String expression, TypeHelperContext context) { + var converter = _typeConverter(targetType, context); if (converter == null) { return null; } diff --git a/json_serializable/lib/src/type_helpers/json_helper.dart b/json_serializable/lib/src/type_helpers/json_helper.dart index 534c202fb..7e8e3dee1 100644 --- a/json_serializable/lib/src/type_helpers/json_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_helper.dart @@ -10,7 +10,6 @@ import 'package:source_gen/source_gen.dart'; import '../shared_checkers.dart'; import '../type_helper.dart'; -import '../type_helper_context.dart'; import '../utils.dart'; class JsonHelper extends TypeHelper { @@ -22,12 +21,12 @@ class JsonHelper extends TypeHelper { /// provided objects. @override String serialize( - DartType targetType, String expression, SerializeContext context) { + DartType targetType, String expression, TypeHelperContext context) { if (!_canSerialize(targetType)) { return null; } - if (context is TypeHelperContext && context.explicitToJson) { + if (context.explicitToJson) { return '$expression${context.nullable ? '?' : ''}.toJson()'; } return expression; @@ -35,7 +34,7 @@ class JsonHelper extends TypeHelper { @override String deserialize( - DartType targetType, String expression, DeserializeContext context) { + DartType targetType, String expression, TypeHelperContext context) { if (targetType is! InterfaceType) { return null; } @@ -52,7 +51,7 @@ class JsonHelper extends TypeHelper { var asCastType = fromJsonCtor.parameters.first.type; asCast = asStatement(asCastType); } else if (_annotation(type)?.createFactory == true) { - if ((context as TypeHelperContext).anyMap) { + if (context.anyMap) { asCast = ' as Map'; } else { asCast = ' as Map'; diff --git a/json_serializable/lib/src/type_helpers/map_helper.dart b/json_serializable/lib/src/type_helpers/map_helper.dart index 926012121..d411cab7f 100644 --- a/json_serializable/lib/src/type_helpers/map_helper.dart +++ b/json_serializable/lib/src/type_helpers/map_helper.dart @@ -7,7 +7,6 @@ import 'package:analyzer/dart/element/type.dart'; import '../constants.dart'; import '../shared_checkers.dart'; import '../type_helper.dart'; -import '../type_helper_context.dart'; import '../utils.dart'; const _keyParam = 'k'; @@ -17,7 +16,7 @@ class MapHelper extends TypeHelper { @override String serialize( - DartType targetType, String expression, SerializeContext context) { + DartType targetType, String expression, TypeHelperContext context) { if (!coreMapTypeChecker.isAssignableFromType(targetType)) { return null; } @@ -53,7 +52,7 @@ class MapHelper extends TypeHelper { @override String deserialize( - DartType targetType, String expression, DeserializeContext context) { + DartType targetType, String expression, TypeHelperContext context) { if (!coreMapTypeChecker.isAssignableFromType(targetType)) { return null; } @@ -66,12 +65,11 @@ class MapHelper extends TypeHelper { _checkSafeKeyType(expression, keyArg); final valueArgIsAny = _isObjectOrDynamic(valueArg); - var isAnyMap = context is TypeHelperContext && context.anyMap; final isEnumKey = isEnum(keyArg); if (!isEnumKey) { if (valueArgIsAny) { - if (isAnyMap) { + if (context.anyMap) { if (_isObjectOrDynamic(keyArg)) { return '$expression as Map'; } @@ -97,12 +95,12 @@ class MapHelper extends TypeHelper { final optionalQuestion = context.nullable ? '?' : ''; - final mapCast = isAnyMap ? 'as Map' : 'as Map'; + final mapCast = context.anyMap ? 'as Map' : 'as Map'; String keyUsage; if (isEnumKey) { keyUsage = context.deserialize(keyArg, _keyParam); - } else if (isAnyMap && !_isObjectOrDynamic(keyArg)) { + } else if (context.anyMap && !_isObjectOrDynamic(keyArg)) { keyUsage = '$_keyParam as String'; } else { keyUsage = _keyParam; diff --git a/json_serializable/lib/src/type_helpers/uri_helper.dart b/json_serializable/lib/src/type_helpers/uri_helper.dart index ba63e3dc3..b865bacf1 100644 --- a/json_serializable/lib/src/type_helpers/uri_helper.dart +++ b/json_serializable/lib/src/type_helpers/uri_helper.dart @@ -11,7 +11,7 @@ class UriHelper extends TypeHelper { @override String serialize( - DartType targetType, String expression, SerializeContext context) { + DartType targetType, String expression, TypeHelperContext context) { if (!_matchesType(targetType)) { return null; } @@ -29,7 +29,7 @@ class UriHelper extends TypeHelper { @override String deserialize( - DartType targetType, String expression, DeserializeContext context) { + DartType targetType, String expression, TypeHelperContext context) { if (!_matchesType(targetType)) { return null; } diff --git a/json_serializable/lib/src/type_helpers/value_helper.dart b/json_serializable/lib/src/type_helpers/value_helper.dart index 67f263187..8fc52bd7d 100644 --- a/json_serializable/lib/src/type_helpers/value_helper.dart +++ b/json_serializable/lib/src/type_helpers/value_helper.dart @@ -13,7 +13,7 @@ class ValueHelper extends TypeHelper { @override String serialize( - DartType targetType, String expression, SerializeContext context) { + DartType targetType, String expression, TypeHelperContext context) { if (targetType.isUndefined) { return null; } @@ -28,7 +28,7 @@ class ValueHelper extends TypeHelper { @override String deserialize( - DartType targetType, String expression, DeserializeContext context) { + DartType targetType, String expression, TypeHelperContext context) { if (targetType.isUndefined) { return null; } diff --git a/json_serializable/lib/type_helper.dart b/json_serializable/lib/type_helper.dart index 6f582d48e..81cf59f75 100644 --- a/json_serializable/lib/type_helper.dart +++ b/json_serializable/lib/type_helper.dart @@ -4,7 +4,7 @@ export 'src/shared_checkers.dart' show simpleJsonTypeChecker, typeArgumentsOf; export 'src/type_helper.dart' - show SerializeContext, DeserializeContext, TypeHelper, UnsupportedTypeError; + show TypeHelperContext, TypeHelper, UnsupportedTypeError; export 'src/type_helpers/convert_helper.dart'; export 'src/type_helpers/date_time_helper.dart'; export 'src/type_helpers/enum_helper.dart'; From 8dfbdfbd43c85658ed89051874c00564a23bfbe7 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 20 Sep 2018 08:30:43 -0700 Subject: [PATCH 003/569] Update TypeHelper to allow implementations to require richer context (#319) Replaces approach taken in 8b9cdb94410dce2f27c7d759ea138ed4dc7906f4 Much easier for implementations to run with other generators --- json_serializable/CHANGELOG.md | 9 +++---- .../lib/src/json_serializable_generator.dart | 11 +++++--- json_serializable/lib/src/type_helper.dart | 25 ++++++++----------- .../lib/src/type_helper_ctx.dart | 20 +++++++-------- .../lib/src/type_helpers/convert_helper.dart | 24 ++++++++++-------- .../lib/src/type_helpers/iterable_helper.dart | 6 ++--- .../lib/src/type_helpers/json_helper.dart | 10 ++++---- .../lib/src/type_helpers/map_helper.dart | 10 ++++---- 8 files changed, 59 insertions(+), 56 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 13da5ad65..0e647f7d0 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -5,11 +5,10 @@ * **BREAKING** `SerializeContext` and `DeserializeContext` have been replaced with new `TypeHelperContext` class. - * **BREAKING** `ConvertHelper` constructor now has two required arguments - which allow it to find `ConvertData` associated with custom field serialize - methods. - - * Added new class `ConvertData`. + * `TypeHelper` now has a type argument allowing implementors to specify a + specific implementation of `TypeHelperContext` for calls to `serialize` and + `deserialize`. Many of the included `TypeHelper` implementations have been + updated to indicate they expect more information from the source generator. ## 1.3.0 diff --git a/json_serializable/lib/src/json_serializable_generator.dart b/json_serializable/lib/src/json_serializable_generator.dart index e1d60e5c4..bd5f4a9c3 100644 --- a/json_serializable/lib/src/json_serializable_generator.dart +++ b/json_serializable/lib/src/json_serializable_generator.dart @@ -12,7 +12,6 @@ import 'encoder_helper.dart'; import 'field_helpers.dart'; import 'helper_core.dart'; import 'type_helper.dart'; -import 'type_helper_ctx.dart'; import 'type_helpers/convert_helper.dart'; import 'type_helpers/date_time_helper.dart'; import 'type_helpers/enum_helper.dart'; @@ -29,19 +28,23 @@ Iterable allHelpersImpl(JsonSerializableGenerator generator) => class JsonSerializableGenerator extends GeneratorForAnnotation { - static const _coreHelpers = [ + static const _coreHelpers = [ IterableHelper(), MapHelper(), EnumHelper(), ValueHelper(), ]; - static const _defaultHelpers = [JsonHelper(), DateTimeHelper(), UriHelper()]; + static const _defaultHelpers = [ + JsonHelper(), + DateTimeHelper(), + UriHelper() + ]; final List _typeHelpers; Iterable get _allHelpers => const [ - ConvertHelper(serializeData, deserializeData), + ConvertHelper(), JsonConverterHelper() ].followedBy(_typeHelpers).followedBy(_coreHelpers); diff --git a/json_serializable/lib/src/type_helper.dart b/json_serializable/lib/src/type_helper.dart index 37c204e82..b18a0216d 100644 --- a/json_serializable/lib/src/type_helper.dart +++ b/json_serializable/lib/src/type_helper.dart @@ -14,15 +14,6 @@ abstract class TypeHelperContext { /// The field that code is being generated for. FieldElement get fieldElement; - /// Represents the corresponding configuration on `JsonSerializableGenerator`. - bool get explicitToJson; - - /// Represents the corresponding configuration on `JsonSerializableGenerator`. - bool get anyMap; - - /// Represents the corresponding configuration on `JsonSerializableGenerator`. - bool get useWrappers; - /// Returns `true` if [fieldElement] could potentially contain a `null` value. bool get nullable; @@ -38,7 +29,15 @@ abstract class TypeHelperContext { void addMember(String memberContent); } -abstract class TypeHelper { +/// Extended context information with includes configuration values +/// corresponding to `JsonSerializableGenerator` settings. +abstract class TypeHelperContextWithConfig extends TypeHelperContext { + bool get explicitToJson; + bool get anyMap; + bool get useWrappers; +} + +abstract class TypeHelper { const TypeHelper(); /// Returns Dart code that serializes an [expression] representing a Dart @@ -56,8 +55,7 @@ abstract class TypeHelper { /// String serialize(DartType targetType, String expression) => /// "$expression.id"; /// ```. - String serialize( - DartType targetType, String expression, TypeHelperContext context); + String serialize(DartType targetType, String expression, T context); /// Returns Dart code that deserializes an [expression] representing a JSON /// literal to into [targetType]. @@ -82,8 +80,7 @@ abstract class TypeHelper { /// String deserialize(DartType targetType, String expression) => /// "new ${targetType.name}.fromInt($expression)"; /// ```. - String deserialize( - DartType targetType, String expression, TypeHelperContext context); + String deserialize(DartType targetType, String expression, T context); } class UnsupportedTypeError extends Error { diff --git a/json_serializable/lib/src/type_helper_ctx.dart b/json_serializable/lib/src/type_helper_ctx.dart index 52e80a86f..4cf6fc535 100644 --- a/json_serializable/lib/src/type_helper_ctx.dart +++ b/json_serializable/lib/src/type_helper_ctx.dart @@ -12,20 +12,12 @@ import 'json_serializable_generator.dart'; import 'type_helper.dart'; import 'type_helpers/convert_helper.dart'; -ConvertData serializeData(TypeHelperContext ctx) => - _pairFromContext(ctx)?.toJson; - -ConvertData deserializeData(TypeHelperContext ctx) => - _pairFromContext(ctx)?.fromJson; - -ConvertPair _pairFromContext(TypeHelperContext ctx) => - ConvertPair.fromJsonKey((ctx as _TypeHelperCtx)._key); - TypeHelperContext typeHelperContext( HelperCore helperCore, FieldElement fieldElement, JsonKey key) => _TypeHelperCtx(helperCore, fieldElement, key); -class _TypeHelperCtx implements TypeHelperContext { +class _TypeHelperCtx + implements TypeHelperContextWithConfig, TypeHelperContextWithConvert { final HelperCore _helperCore; final JsonKey _key; @@ -49,6 +41,14 @@ class _TypeHelperCtx implements TypeHelperContext { _TypeHelperCtx(this._helperCore, this.fieldElement, this._key); + @override + ConvertData get serializeConvertData => _pairFromContext?.toJson; + + @override + ConvertData get deserializeConvertData => _pairFromContext?.fromJson; + + ConvertPair get _pairFromContext => ConvertPair.fromJsonKey(_key); + @override void addMember(String memberContent) { _helperCore.addMember(memberContent); diff --git a/json_serializable/lib/src/type_helpers/convert_helper.dart b/json_serializable/lib/src/type_helpers/convert_helper.dart index 1e7e4252a..1708575dd 100644 --- a/json_serializable/lib/src/type_helpers/convert_helper.dart +++ b/json_serializable/lib/src/type_helpers/convert_helper.dart @@ -7,6 +7,8 @@ import 'package:analyzer/dart/element/type.dart'; import '../shared_checkers.dart'; import '../type_helper.dart'; +/// Information used by [ConvertHelper] when handling `JsonKey`-annotated +/// fields with `toJson` or `fromJson` values set. class ConvertData { final String name; final DartType paramType; @@ -14,16 +16,18 @@ class ConvertData { ConvertData(this.name, this.paramType); } -class ConvertHelper extends TypeHelper { - final ConvertData Function(TypeHelperContext) serializeConvertData; - final ConvertData Function(TypeHelperContext) deserializeConvertData; +abstract class TypeHelperContextWithConvert extends TypeHelperContext { + ConvertData get serializeConvertData; + ConvertData get deserializeConvertData; +} - const ConvertHelper(this.serializeConvertData, this.deserializeConvertData); +class ConvertHelper extends TypeHelper { + const ConvertHelper(); @override - String serialize( - DartType targetType, String expression, TypeHelperContext context) { - var toJsonData = serializeConvertData(context); + String serialize(DartType targetType, String expression, + TypeHelperContextWithConvert context) { + var toJsonData = context.serializeConvertData; if (toJsonData != null) { assert(toJsonData.paramType is TypeParameterType || targetType.isAssignableTo(toJsonData.paramType)); @@ -34,9 +38,9 @@ class ConvertHelper extends TypeHelper { } @override - String deserialize( - DartType targetType, String expression, TypeHelperContext context) { - var fromJsonData = deserializeConvertData(context); + String deserialize(DartType targetType, String expression, + TypeHelperContextWithConvert context) { + var fromJsonData = context.deserializeConvertData; if (fromJsonData != null) { var asContent = asStatement(fromJsonData.paramType); var result = '${fromJsonData.name}($expression$asContent)'; diff --git a/json_serializable/lib/src/type_helpers/iterable_helper.dart b/json_serializable/lib/src/type_helpers/iterable_helper.dart index 308585505..c856a39b8 100644 --- a/json_serializable/lib/src/type_helpers/iterable_helper.dart +++ b/json_serializable/lib/src/type_helpers/iterable_helper.dart @@ -9,12 +9,12 @@ import '../constants.dart'; import '../shared_checkers.dart'; import '../type_helper.dart'; -class IterableHelper extends TypeHelper { +class IterableHelper extends TypeHelper { const IterableHelper(); @override - String serialize( - DartType targetType, String expression, TypeHelperContext context) { + String serialize(DartType targetType, String expression, + TypeHelperContextWithConfig context) { if (!coreIterableTypeChecker.isAssignableFromType(targetType)) { return null; } diff --git a/json_serializable/lib/src/type_helpers/json_helper.dart b/json_serializable/lib/src/type_helpers/json_helper.dart index 7e8e3dee1..2cd349372 100644 --- a/json_serializable/lib/src/type_helpers/json_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_helper.dart @@ -12,7 +12,7 @@ import '../shared_checkers.dart'; import '../type_helper.dart'; import '../utils.dart'; -class JsonHelper extends TypeHelper { +class JsonHelper extends TypeHelper { const JsonHelper(); /// Simply returns the [expression] provided. @@ -20,8 +20,8 @@ class JsonHelper extends TypeHelper { /// By default, JSON encoding in from `dart:convert` calls `toJson()` on /// provided objects. @override - String serialize( - DartType targetType, String expression, TypeHelperContext context) { + String serialize(DartType targetType, String expression, + TypeHelperContextWithConfig context) { if (!_canSerialize(targetType)) { return null; } @@ -33,8 +33,8 @@ class JsonHelper extends TypeHelper { } @override - String deserialize( - DartType targetType, String expression, TypeHelperContext context) { + String deserialize(DartType targetType, String expression, + TypeHelperContextWithConfig context) { if (targetType is! InterfaceType) { return null; } diff --git a/json_serializable/lib/src/type_helpers/map_helper.dart b/json_serializable/lib/src/type_helpers/map_helper.dart index d411cab7f..5dba66f6d 100644 --- a/json_serializable/lib/src/type_helpers/map_helper.dart +++ b/json_serializable/lib/src/type_helpers/map_helper.dart @@ -11,12 +11,12 @@ import '../utils.dart'; const _keyParam = 'k'; -class MapHelper extends TypeHelper { +class MapHelper extends TypeHelper { const MapHelper(); @override - String serialize( - DartType targetType, String expression, TypeHelperContext context) { + String serialize(DartType targetType, String expression, + TypeHelperContextWithConfig context) { if (!coreMapTypeChecker.isAssignableFromType(targetType)) { return null; } @@ -51,8 +51,8 @@ class MapHelper extends TypeHelper { } @override - String deserialize( - DartType targetType, String expression, TypeHelperContext context) { + String deserialize(DartType targetType, String expression, + TypeHelperContextWithConfig context) { if (!coreMapTypeChecker.isAssignableFromType(targetType)) { return null; } From 1e96567b54e87315739a9a1c78d629b49dc80ebf Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 20 Sep 2018 09:38:55 -0700 Subject: [PATCH 004/569] enable lints (#320) * Add back prefer_const_constructor lint Dev SDK has been updated with fix * Re-enable unnecessary_const lint Associated bug has been fixed in pkg:test --- .travis.yml | 13 +++++++++---- analysis_options.yaml | 6 ++---- example/test/ensure_build_test.dart | 2 +- json_serializable/mono_pkg.yaml | 3 +++ json_serializable/pubspec.yaml | 2 +- json_serializable/test/ensure_build_test.dart | 2 +- .../test/kitchen_sink/json_converters.dart | 2 +- tool/travis.sh | 9 +++++++-- 8 files changed, 25 insertions(+), 14 deletions(-) diff --git a/.travis.yml b/.travis.yml index d329cc1b2..1b4131d7d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,7 +15,7 @@ jobs: dart: stable - stage: analyzer_and_format name: "SDK: stable - DIR: example - TASKS: dartanalyzer --fatal-infos --fatal-warnings ." - script: ./tool/travis.sh dartanalyzer + script: ./tool/travis.sh dartanalyzer_0 env: PKG="example" dart: stable - stage: unit_test @@ -30,7 +30,7 @@ jobs: dart: stable - stage: analyzer_and_format name: "SDK: stable - DIR: json_annotation - TASKS: dartanalyzer --fatal-infos --fatal-warnings ." - script: ./tool/travis.sh dartanalyzer + script: ./tool/travis.sh dartanalyzer_0 env: PKG="json_annotation" dart: stable - stage: analyzer_and_format @@ -39,8 +39,13 @@ jobs: env: PKG="json_serializable" dart: stable - stage: analyzer_and_format - name: "SDK: stable - DIR: json_serializable - TASKS: dartanalyzer --fatal-infos --fatal-warnings ." - script: ./tool/travis.sh dartanalyzer + name: "SDK: dev - DIR: json_serializable - TASKS: dartanalyzer --fatal-infos --fatal-warnings ." + script: ./tool/travis.sh dartanalyzer_0 + env: PKG="json_serializable" + dart: dev + - stage: analyzer_and_format + name: "SDK: stable - DIR: json_serializable - TASKS: dartanalyzer --fatal-warnings ." + script: ./tool/travis.sh dartanalyzer_1 env: PKG="json_serializable" dart: stable - stage: unit_test diff --git a/analysis_options.yaml b/analysis_options.yaml index be59fe4e9..88564c558 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -52,8 +52,7 @@ linter: - prefer_adjacent_string_concatenation - prefer_collection_literals - prefer_conditional_assignment - # Waiting on SDK >=2.1.0-dev.5.0 with linter fix - #- prefer_const_constructors + - prefer_const_constructors - prefer_contains - prefer_equal_for_default_values - prefer_final_fields @@ -71,8 +70,7 @@ linter: - type_init_formals - unawaited_futures - unnecessary_brace_in_string_interps - # Waiting on https://github.com/dart-lang/test/issues/915 - #- unnecessary_const + - unnecessary_const - unnecessary_getters_setters # We'll need a way to return a lambda from a TypeHelper to re-enable this #- unnecessary_lambdas diff --git a/example/test/ensure_build_test.dart b/example/test/ensure_build_test.dart index 1a795adcd..9a33eabb0 100644 --- a/example/test/ensure_build_test.dart +++ b/example/test/ensure_build_test.dart @@ -4,7 +4,7 @@ // TODO(kevmoo): replace with a common utility // https://github.com/dart-lang/build/issues/716 -@Tags(const ['presubmit-only']) +@Tags(['presubmit-only']) import 'dart:convert'; import 'dart:io'; diff --git a/json_serializable/mono_pkg.yaml b/json_serializable/mono_pkg.yaml index 13cf7aea5..2ec25a0f4 100644 --- a/json_serializable/mono_pkg.yaml +++ b/json_serializable/mono_pkg.yaml @@ -6,6 +6,9 @@ stages: - analyzer_and_format: - dartfmt - dartanalyzer: --fatal-infos --fatal-warnings . + dart: [dev] + - dartanalyzer: --fatal-warnings . + dart: [stable] - unit_test: # Run the tests -- include the default-skipped presubmit tests - test diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index e23294834..1583f4b31 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -25,5 +25,5 @@ dev_dependencies: collection: ^1.14.0 dart_style: ^1.0.0 logging: ^0.11.3+1 - test: ^1.0.0 + test: ^1.3.3 yaml: ^2.1.13 diff --git a/json_serializable/test/ensure_build_test.dart b/json_serializable/test/ensure_build_test.dart index af5aa7056..7bcf0b5f1 100644 --- a/json_serializable/test/ensure_build_test.dart +++ b/json_serializable/test/ensure_build_test.dart @@ -3,7 +3,7 @@ // BSD-style license that can be found in the LICENSE file. @TestOn('vm') -@Tags(const ['presubmit-only']) +@Tags(['presubmit-only']) import 'dart:convert'; import 'dart:io'; diff --git a/json_serializable/test/kitchen_sink/json_converters.dart b/json_serializable/test/kitchen_sink/json_converters.dart index 349af40b6..d927ba5f3 100644 --- a/json_serializable/test/kitchen_sink/json_converters.dart +++ b/json_serializable/test/kitchen_sink/json_converters.dart @@ -19,7 +19,7 @@ class TrivialNumber { } class TrivialNumberConverter implements JsonConverter { - static const instance = const TrivialNumberConverter(); + static const instance = TrivialNumberConverter(); const TrivialNumberConverter(); diff --git a/tool/travis.sh b/tool/travis.sh index 1e2ad858f..2fc8bdee0 100755 --- a/tool/travis.sh +++ b/tool/travis.sh @@ -24,11 +24,16 @@ while (( "$#" )); do echo -e 'pub run build_runner test -- -p chrome' pub run build_runner test -- -p chrome || EXIT_CODE=$? ;; - dartanalyzer) echo - echo -e '\033[1mTASK: dartanalyzer\033[22m' + dartanalyzer_0) echo + echo -e '\033[1mTASK: dartanalyzer_0\033[22m' echo -e 'dartanalyzer --fatal-infos --fatal-warnings .' dartanalyzer --fatal-infos --fatal-warnings . || EXIT_CODE=$? ;; + dartanalyzer_1) echo + echo -e '\033[1mTASK: dartanalyzer_1\033[22m' + echo -e 'dartanalyzer --fatal-warnings .' + dartanalyzer --fatal-warnings . || EXIT_CODE=$? + ;; dartfmt) echo echo -e '\033[1mTASK: dartfmt\033[22m' echo -e 'dartfmt -n --set-exit-if-changed .' From 8f75f73570765ab2826ce3051fb2dfb416c46212 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 20 Sep 2018 10:08:56 -0700 Subject: [PATCH 005/569] TypeHelper serialize/deserialize return Object instead of String (#321) This allows coordination between instances to support more advanced features. Added LambdaResult class and return it in JsonConvertHelper to avoid unnecessary lambdas --- analysis_options.yaml | 3 +-- json_serializable/CHANGELOG.md | 6 +++++ json_serializable/lib/src/decode_helper.dart | 6 +++-- json_serializable/lib/src/encoder_helper.dart | 4 +++- json_serializable/lib/src/type_helper.dart | 22 +++++++++++++++---- .../lib/src/type_helper_ctx.dart | 8 +++---- .../lib/src/type_helpers/iterable_helper.dart | 12 +++++----- .../type_helpers/json_converter_helper.dart | 9 ++++---- .../lib/src/type_helpers/map_helper.dart | 5 +++-- .../test/kitchen_sink/kitchen_sink.g.dart | 8 +++---- .../kitchen_sink.non_nullable.checked.g.dart | 11 ++++------ .../kitchen_sink.non_nullable.g.dart | 11 ++++------ .../kitchen_sink.non_nullable.wrapped.g.dart | 13 +++++------ .../kitchen_sink/kitchen_sink.wrapped.g.dart | 10 ++++----- 14 files changed, 71 insertions(+), 57 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index 88564c558..d7eaf1860 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -72,8 +72,7 @@ linter: - unnecessary_brace_in_string_interps - unnecessary_const - unnecessary_getters_setters - # We'll need a way to return a lambda from a TypeHelper to re-enable this - #- unnecessary_lambdas + - unnecessary_lambdas - unnecessary_new - unnecessary_null_aware_assignments - unnecessary_statements diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 0e647f7d0..153bb2385 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -10,6 +10,12 @@ `deserialize`. Many of the included `TypeHelper` implementations have been updated to indicate they expect more information from the source generator. + * `TypeHelper` `serialize` and `deserialize` have return type `Object` instead + of `String`. This allows coordination between instances to support more + advanced features – like using the new `LambdaResult` class to avoid + creating unnecessary lambdas. When creating `TypeHelper` implementations, + handle non-`String` results by calling `toString()` on unrecognized values. + ## 1.3.0 * Add support for types annotated with classes that extend `JsonConverter` from diff --git a/json_serializable/lib/src/decode_helper.dart b/json_serializable/lib/src/decode_helper.dart index 2efba8e8b..a46b31315 100644 --- a/json_serializable/lib/src/decode_helper.dart +++ b/json_serializable/lib/src/decode_helper.dart @@ -170,7 +170,7 @@ abstract class DecodeHelper implements HelperCore { String value; try { if (generator.checked) { - value = contextHelper.deserialize(targetType, 'v'); + value = contextHelper.deserialize(targetType, 'v').toString(); if (!checkedProperty) { value = '\$checkedConvert(json, $jsonKeyName, (v) => $value)'; } @@ -178,7 +178,9 @@ abstract class DecodeHelper implements HelperCore { assert(!checkedProperty, 'should only be true if `_generator.checked` is true.'); - value = contextHelper.deserialize(targetType, 'json[$jsonKeyName]'); + value = contextHelper + .deserialize(targetType, 'json[$jsonKeyName]') + .toString(); } } on UnsupportedTypeError catch (e) { throw createInvalidGenerationError('fromJson', field, e); diff --git a/json_serializable/lib/src/encoder_helper.dart b/json_serializable/lib/src/encoder_helper.dart index 381f792bd..13bdd3695 100644 --- a/json_serializable/lib/src/encoder_helper.dart +++ b/json_serializable/lib/src/encoder_helper.dart @@ -224,7 +224,9 @@ class ${_wrapperClassName(true)} extends \$JsonMapWrapper { String _serializeField(FieldElement field, String accessExpression) { try { - return getHelperContext(field).serialize(field.type, accessExpression); + return getHelperContext(field) + .serialize(field.type, accessExpression) + .toString(); } on UnsupportedTypeError catch (e) { throw createInvalidGenerationError('toJson', field, e); } diff --git a/json_serializable/lib/src/type_helper.dart b/json_serializable/lib/src/type_helper.dart index b18a0216d..97ca5f016 100644 --- a/json_serializable/lib/src/type_helper.dart +++ b/json_serializable/lib/src/type_helper.dart @@ -19,11 +19,11 @@ abstract class TypeHelperContext { /// [expression] may be just the name of the field or it may an expression /// representing the serialization of a value. - String serialize(DartType fieldType, String expression); + Object serialize(DartType fieldType, String expression); /// [expression] may be just the name of the field or it may an expression /// representing the serialization of a value. - String deserialize(DartType fieldType, String expression); + Object deserialize(DartType fieldType, String expression); /// Adds [memberContent] to the set of generated, top-level members. void addMember(String memberContent); @@ -55,7 +55,7 @@ abstract class TypeHelper { /// String serialize(DartType targetType, String expression) => /// "$expression.id"; /// ```. - String serialize(DartType targetType, String expression, T context); + Object serialize(DartType targetType, String expression, T context); /// Returns Dart code that deserializes an [expression] representing a JSON /// literal to into [targetType]. @@ -80,7 +80,21 @@ abstract class TypeHelper { /// String deserialize(DartType targetType, String expression) => /// "new ${targetType.name}.fromInt($expression)"; /// ```. - String deserialize(DartType targetType, String expression, T context); + Object deserialize(DartType targetType, String expression, T context); +} + +class LambdaResult { + final String expression; + final String lambda; + LambdaResult(this.expression, this.lambda); + + @override + String toString() => '$lambda($expression)'; + + static String process(Object subField, String closureArg) => + (subField is LambdaResult && closureArg == subField.expression) + ? subField.lambda + : '($closureArg) => $subField'; } class UnsupportedTypeError extends Error { diff --git a/json_serializable/lib/src/type_helper_ctx.dart b/json_serializable/lib/src/type_helper_ctx.dart index 4cf6fc535..ea52cc061 100644 --- a/json_serializable/lib/src/type_helper_ctx.dart +++ b/json_serializable/lib/src/type_helper_ctx.dart @@ -55,19 +55,19 @@ class _TypeHelperCtx } @override - String serialize(DartType targetType, String expression) => _run( + Object serialize(DartType targetType, String expression) => _run( targetType, expression, (TypeHelper th) => th.serialize(targetType, expression, this)); @override - String deserialize(DartType targetType, String expression) => _run( + Object deserialize(DartType targetType, String expression) => _run( targetType, expression, (TypeHelper th) => th.deserialize(targetType, expression, this)); - String _run(DartType targetType, String expression, - String invoke(TypeHelper instance)) => + Object _run(DartType targetType, String expression, + Object invoke(TypeHelper instance)) => allHelpersImpl(_helperCore.generator).map(invoke).firstWhere( (r) => r != null, orElse: () => throw UnsupportedTypeError( diff --git a/json_serializable/lib/src/type_helpers/iterable_helper.dart b/json_serializable/lib/src/type_helpers/iterable_helper.dart index c856a39b8..edfcad003 100644 --- a/json_serializable/lib/src/type_helpers/iterable_helper.dart +++ b/json_serializable/lib/src/type_helpers/iterable_helper.dart @@ -33,18 +33,17 @@ class IterableHelper extends TypeHelper { // will be identical to `substitute` – so no explicit mapping is needed. // If they are not equal, then we to write out the substitution. if (subField != closureArg) { + var lambda = LambdaResult.process(subField, closureArg); if (context.useWrappers && isList) { var method = '\$wrapList'; if (context.nullable) { method = '${method}HandleNull'; } - return '$method<$itemType>($expression, ($closureArg) => $subField)'; + return '$method<$itemType>($expression, $lambda)'; } - // TODO: the type could be imported from a library with a prefix! - expression = - '$expression$optionalQuestion.map(($closureArg) => $subField)'; + expression = '$expression$optionalQuestion.map($lambda)'; // expression now represents an Iterable (even if it started as a List // ...resetting `isList` to `false`. @@ -79,8 +78,9 @@ class IterableHelper extends TypeHelper { var optionalQuestion = context.nullable ? '?' : ''; - var output = - '($expression as List)$optionalQuestion.map(($closureArg) => $itemSubVal)'; + var lambda = LambdaResult.process(itemSubVal, closureArg); + + var output = '($expression as List)$optionalQuestion.map($lambda)'; if (_coreListChecker.isAssignableFromType(targetType)) { output += '$optionalQuestion.toList()'; diff --git a/json_serializable/lib/src/type_helpers/json_converter_helper.dart b/json_serializable/lib/src/type_helpers/json_converter_helper.dart index 2ddd2f883..86d8da21a 100644 --- a/json_serializable/lib/src/type_helpers/json_converter_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_converter_helper.dart @@ -18,7 +18,7 @@ class JsonConverterHelper extends TypeHelper { const JsonConverterHelper(); @override - String serialize( + LambdaResult serialize( DartType targetType, String expression, TypeHelperContext context) { var converter = _typeConverter(targetType, context); @@ -26,11 +26,11 @@ class JsonConverterHelper extends TypeHelper { return null; } - return '${converter.accessString}.toJson($expression)'; + return LambdaResult(expression, '${converter.accessString}.toJson'); } @override - String deserialize( + LambdaResult deserialize( DartType targetType, String expression, TypeHelperContext context) { var converter = _typeConverter(targetType, context); if (converter == null) { @@ -39,7 +39,8 @@ class JsonConverterHelper extends TypeHelper { var asContent = asStatement(converter.jsonType); - return '${converter.accessString}.fromJson($expression$asContent)'; + return LambdaResult( + '$expression$asContent', '${converter.accessString}.fromJson'); } } diff --git a/json_serializable/lib/src/type_helpers/map_helper.dart b/json_serializable/lib/src/type_helpers/map_helper.dart index 5dba66f6d..4b4f4cda5 100644 --- a/json_serializable/lib/src/type_helpers/map_helper.dart +++ b/json_serializable/lib/src/type_helpers/map_helper.dart @@ -41,7 +41,8 @@ class MapHelper extends TypeHelper { method = '${method}HandleNull'; } - return '$method<$keyType, $valueType>($expression, ($closureArg) => $subFieldValue)'; + var lambda = LambdaResult.process(subFieldValue, closureArg); + return '$method<$keyType, $valueType>($expression, $lambda)'; } final optionalQuestion = context.nullable ? '?' : ''; @@ -99,7 +100,7 @@ class MapHelper extends TypeHelper { String keyUsage; if (isEnumKey) { - keyUsage = context.deserialize(keyArg, _keyParam); + keyUsage = context.deserialize(keyArg, _keyParam).toString(); } else if (context.anyMap && !_isObjectOrDynamic(keyArg)) { keyUsage = '$_keyParam as String'; } else { diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g.dart index fda9c4c00..18be9a9b1 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g.dart @@ -167,14 +167,13 @@ abstract class _$JsonConverterTestClassSerializerMixin { DateTime get dateTime; Map toJson() => { 'duration': durationConverter.toJson(duration), - 'durationList': - durationList?.map((e) => durationConverter.toJson(e))?.toList(), + 'durationList': durationList?.map(durationConverter.toJson)?.toList(), 'bigInt': const BigIntStringConverter().toJson(bigInt), 'bigIntMap': bigIntMap?.map( (k, e) => MapEntry(k, const BigIntStringConverter().toJson(e))), 'numberSilly': TrivialNumberConverter.instance.toJson(numberSilly), 'numberSillySet': numberSillySet - ?.map((e) => TrivialNumberConverter.instance.toJson(e)) + ?.map(TrivialNumberConverter.instance.toJson) ?.toList(), 'dateTime': const EpochDateTimeConverter().toJson(dateTime) }; @@ -198,8 +197,7 @@ abstract class _$JsonConverterGenericSerializerMixin { Map get itemMap; Map toJson() => { 'item': GenericConverter().toJson(item), - 'itemList': - itemList?.map((e) => GenericConverter().toJson(e))?.toList(), + 'itemList': itemList?.map(GenericConverter().toJson)?.toList(), 'itemMap': itemMap?.map((k, e) => MapEntry(k, GenericConverter().toJson(e))) }; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.checked.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.checked.g.dart index ed66c6905..9bcc96368 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.checked.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.checked.g.dart @@ -208,15 +208,13 @@ abstract class _$JsonConverterTestClassSerializerMixin { DateTime get dateTime; Map toJson() => { 'duration': durationConverter.toJson(duration), - 'durationList': - durationList.map((e) => durationConverter.toJson(e)).toList(), + 'durationList': durationList.map(durationConverter.toJson).toList(), 'bigInt': const BigIntStringConverter().toJson(bigInt), 'bigIntMap': bigIntMap.map( (k, e) => MapEntry(k, const BigIntStringConverter().toJson(e))), 'numberSilly': TrivialNumberConverter.instance.toJson(numberSilly), - 'numberSillySet': numberSillySet - .map((e) => TrivialNumberConverter.instance.toJson(e)) - .toList(), + 'numberSillySet': + numberSillySet.map(TrivialNumberConverter.instance.toJson).toList(), 'dateTime': const EpochDateTimeConverter().toJson(dateTime) }; } @@ -252,8 +250,7 @@ abstract class _$JsonConverterGenericSerializerMixin { Map get itemMap; Map toJson() => { 'item': GenericConverter().toJson(item), - 'itemList': - itemList.map((e) => GenericConverter().toJson(e)).toList(), + 'itemList': itemList.map(GenericConverter().toJson).toList(), 'itemMap': itemMap.map((k, e) => MapEntry(k, GenericConverter().toJson(e))) }; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.g.dart index d648af300..22987076a 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.g.dart @@ -152,15 +152,13 @@ abstract class _$JsonConverterTestClassSerializerMixin { DateTime get dateTime; Map toJson() => { 'duration': durationConverter.toJson(duration), - 'durationList': - durationList.map((e) => durationConverter.toJson(e)).toList(), + 'durationList': durationList.map(durationConverter.toJson).toList(), 'bigInt': const BigIntStringConverter().toJson(bigInt), 'bigIntMap': bigIntMap.map( (k, e) => MapEntry(k, const BigIntStringConverter().toJson(e))), 'numberSilly': TrivialNumberConverter.instance.toJson(numberSilly), - 'numberSillySet': numberSillySet - .map((e) => TrivialNumberConverter.instance.toJson(e)) - .toList(), + 'numberSillySet': + numberSillySet.map(TrivialNumberConverter.instance.toJson).toList(), 'dateTime': const EpochDateTimeConverter().toJson(dateTime) }; } @@ -183,8 +181,7 @@ abstract class _$JsonConverterGenericSerializerMixin { Map get itemMap; Map toJson() => { 'item': GenericConverter().toJson(item), - 'itemList': - itemList.map((e) => GenericConverter().toJson(e)).toList(), + 'itemList': itemList.map(GenericConverter().toJson).toList(), 'itemMap': itemMap.map((k, e) => MapEntry(k, GenericConverter().toJson(e))) }; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.wrapped.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.wrapped.g.dart index f97d5f8d2..d1b9b0fff 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.wrapped.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.wrapped.g.dart @@ -249,18 +249,17 @@ class _$JsonConverterTestClassJsonMapWrapper extends $JsonMapWrapper { case 'duration': return durationConverter.toJson(_v.duration); case 'durationList': - return $wrapList( - _v.durationList, (e) => durationConverter.toJson(e)); + return $wrapList(_v.durationList, durationConverter.toJson); case 'bigInt': return const BigIntStringConverter().toJson(_v.bigInt); case 'bigIntMap': return $wrapMap( - _v.bigIntMap, (e) => const BigIntStringConverter().toJson(e)); + _v.bigIntMap, const BigIntStringConverter().toJson); case 'numberSilly': return TrivialNumberConverter.instance.toJson(_v.numberSilly); case 'numberSillySet': return _v.numberSillySet - .map((e) => TrivialNumberConverter.instance.toJson(e)) + .map(TrivialNumberConverter.instance.toJson) .toList(); case 'dateTime': return const EpochDateTimeConverter().toJson(_v.dateTime); @@ -304,11 +303,9 @@ class _$JsonConverterGenericJsonMapWrapper extends $JsonMapWrapper { case 'item': return GenericConverter().toJson(_v.item); case 'itemList': - return $wrapList( - _v.itemList, (e) => GenericConverter().toJson(e)); + return $wrapList(_v.itemList, GenericConverter().toJson); case 'itemMap': - return $wrapMap( - _v.itemMap, (e) => GenericConverter().toJson(e)); + return $wrapMap(_v.itemMap, GenericConverter().toJson); } } return null; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.wrapped.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.wrapped.g.dart index e9ef14b22..5f12442f8 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.wrapped.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.wrapped.g.dart @@ -264,17 +264,17 @@ class _$JsonConverterTestClassJsonMapWrapper extends $JsonMapWrapper { return durationConverter.toJson(_v.duration); case 'durationList': return $wrapListHandleNull( - _v.durationList, (e) => durationConverter.toJson(e)); + _v.durationList, durationConverter.toJson); case 'bigInt': return const BigIntStringConverter().toJson(_v.bigInt); case 'bigIntMap': return $wrapMapHandleNull( - _v.bigIntMap, (e) => const BigIntStringConverter().toJson(e)); + _v.bigIntMap, const BigIntStringConverter().toJson); case 'numberSilly': return TrivialNumberConverter.instance.toJson(_v.numberSilly); case 'numberSillySet': return _v.numberSillySet - ?.map((e) => TrivialNumberConverter.instance.toJson(e)) + ?.map(TrivialNumberConverter.instance.toJson) ?.toList(); case 'dateTime': return const EpochDateTimeConverter().toJson(_v.dateTime); @@ -319,10 +319,10 @@ class _$JsonConverterGenericJsonMapWrapper extends $JsonMapWrapper { return GenericConverter().toJson(_v.item); case 'itemList': return $wrapListHandleNull( - _v.itemList, (e) => GenericConverter().toJson(e)); + _v.itemList, GenericConverter().toJson); case 'itemMap': return $wrapMapHandleNull( - _v.itemMap, (e) => GenericConverter().toJson(e)); + _v.itemMap, GenericConverter().toJson); } } return null; From d4d43e1e17c37585dd5283b72517b3795b3ff4ff Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 4 Oct 2018 07:44:41 -0700 Subject: [PATCH 006/569] Support the latest pkg:build_runner --- json_serializable/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 2133f60ad..20c0795df 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -19,7 +19,7 @@ dependencies: source_gen: ^0.9.0 dev_dependencies: - build_runner: ^0.10.0 + build_runner: ^1.0.0 build_test: ^0.10.0 build_verify: ^1.1.0 build_web_compilers: ^0.4.0+1 From b022692d760da92bcf3ec2b83c49eb011f9703e6 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 4 Oct 2018 07:44:41 -0700 Subject: [PATCH 007/569] Support the latest pkg:build_runner --- json_serializable/pubspec.yaml | 1 + json_serializable/tool/build.dart | 1 + 2 files changed, 2 insertions(+) diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 20c0795df..3db172746 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -20,6 +20,7 @@ dependencies: dev_dependencies: build_runner: ^1.0.0 + build_runner_core: ^1.0.0 build_test: ^0.10.0 build_verify: ^1.1.0 build_web_compilers: ^0.4.0+1 diff --git a/json_serializable/tool/build.dart b/json_serializable/tool/build.dart index 93c70ff99..ab1de5e1d 100755 --- a/json_serializable/tool/build.dart +++ b/json_serializable/tool/build.dart @@ -8,6 +8,7 @@ import 'dart:io' show exitCode; import 'package:build/build.dart'; import 'package:build_config/build_config.dart'; import 'package:build_runner/build_runner.dart'; +import 'package:build_runner_core/build_runner_core.dart'; import 'package:build_test/builder.dart'; import 'package:json_serializable/src/json_part_builder.dart' as jpb; import 'package:source_gen/builder.dart'; From c025cf106482f9f226e332f4e857cae39db13326 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 4 Oct 2018 08:28:06 -0700 Subject: [PATCH 008/569] Small cleanup of tool/build.dart --- json_serializable/tool/build.dart | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/json_serializable/tool/build.dart b/json_serializable/tool/build.dart index ab1de5e1d..42a75dfbb 100755 --- a/json_serializable/tool/build.dart +++ b/json_serializable/tool/build.dart @@ -60,17 +60,11 @@ final List builders = [ generateFor: const InputSet( include: [ 'example/example.dart', - 'test/literal/json_literal.dart', - 'test/integration/json_test_example.dart', - 'test/integration/json_test_example.non_nullable.dart' - ], - ), - hideOutput: true), - applyToRoot(_jsonPartBuilder(), - generateFor: const InputSet( - include: [ - 'test/generic_files/generic_class.dart', 'test/default_value/default_value.dart', + 'test/generic_files/generic_class.dart', + 'test/integration/json_test_example.dart', + 'test/integration/json_test_example.non_nullable.dart', + 'test/literal/json_literal.dart', ], ), hideOutput: true), From 3f88f3e6f478bdd82ee94c16b9620e772bb18391 Mon Sep 17 00:00:00 2001 From: Hadrien Lejard Date: Thu, 4 Oct 2018 22:37:03 +0200 Subject: [PATCH 009/569] Support decode/encode of dart:core Duration (#336) fixes #310 --- json_serializable/CHANGELOG.md | 2 + .../lib/src/json_serializable_generator.dart | 8 ++-- .../lib/src/type_helpers/duration_helper.dart | 46 +++++++++++++++++++ .../test/integration/integration_test.dart | 33 +++++++++++++ .../test/integration/json_test_example.dart | 2 + .../test/integration/json_test_example.g.dart | 4 ++ .../json_test_example.non_nullable.dart | 2 + .../json_test_example.non_nullable.g.dart | 2 + ...son_test_example.non_nullable.wrapped.dart | 2 + ...n_test_example.non_nullable.wrapped.g.dart | 4 ++ .../json_test_example.wrapped.dart | 2 + .../json_test_example.wrapped.g.dart | 6 +++ 12 files changed, 110 insertions(+), 3 deletions(-) create mode 100644 json_serializable/lib/src/type_helpers/duration_helper.dart diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index c2b835f66..77344d100 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -10,6 +10,8 @@ `deserialize`. Many of the included `TypeHelper` implementations have been updated to indicate they expect more information from the source generator. +* Support decode/encode of `dart:core` `Duration` + ## 1.5.0 * Added support for `JsonConvert` annotation on fields. diff --git a/json_serializable/lib/src/json_serializable_generator.dart b/json_serializable/lib/src/json_serializable_generator.dart index bd5f4a9c3..85f296aae 100644 --- a/json_serializable/lib/src/json_serializable_generator.dart +++ b/json_serializable/lib/src/json_serializable_generator.dart @@ -14,6 +14,7 @@ import 'helper_core.dart'; import 'type_helper.dart'; import 'type_helpers/convert_helper.dart'; import 'type_helpers/date_time_helper.dart'; +import 'type_helpers/duration_helper.dart'; import 'type_helpers/enum_helper.dart'; import 'type_helpers/iterable_helper.dart'; import 'type_helpers/json_converter_helper.dart'; @@ -38,7 +39,8 @@ class JsonSerializableGenerator static const _defaultHelpers = [ JsonHelper(), DateTimeHelper(), - UriHelper() + UriHelper(), + DurationHelper(), ]; final List _typeHelpers; @@ -122,7 +124,7 @@ class JsonSerializableGenerator /// Creates an instance of [JsonSerializableGenerator]. /// /// If [typeHelpers] is not provided, three built-in helpers are used: - /// [JsonHelper], [DateTimeHelper], and [UriHelper]. + /// [JsonHelper], [DateTimeHelper], [DurationHelper] and [UriHelper]. const JsonSerializableGenerator({ List typeHelpers, bool useWrappers = false, @@ -141,7 +143,7 @@ class JsonSerializableGenerator /// /// [typeHelpers] provides a set of [TypeHelper] that will be used along with /// the built-in helpers: - /// [JsonHelper], [DateTimeHelper], and [UriHelper]. + /// [JsonHelper], [DateTimeHelper], [DurationHelper] and [UriHelper]. factory JsonSerializableGenerator.withDefaultHelpers( Iterable typeHelpers, { bool useWrappers = false, diff --git a/json_serializable/lib/src/type_helpers/duration_helper.dart b/json_serializable/lib/src/type_helpers/duration_helper.dart new file mode 100644 index 000000000..23637431d --- /dev/null +++ b/json_serializable/lib/src/type_helpers/duration_helper.dart @@ -0,0 +1,46 @@ +// Copyright (c) 2018, 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:analyzer/dart/element/type.dart'; +import 'package:source_gen/source_gen.dart' show TypeChecker; +import '../type_helper.dart'; + +class DurationHelper extends TypeHelper { + const DurationHelper(); + + @override + String serialize( + DartType targetType, String expression, TypeHelperContext context) { + if (!_matchesType(targetType)) { + return null; + } + + final buffer = StringBuffer(expression); + + if (context.nullable) { + buffer.write('?'); + } + + buffer.write('.inMicroseconds'); + + return buffer.toString(); + } + + @override + String deserialize( + DartType targetType, String expression, TypeHelperContext context) { + if (!_matchesType(targetType)) { + return null; + } + + return commonNullPrefix( + context.nullable, + expression, + 'Duration(microseconds: $expression as int)', + ); + } +} + +bool _matchesType(DartType type) => + const TypeChecker.fromUrl('dart:core#Duration').isExactlyType(type); diff --git a/json_serializable/test/integration/integration_test.dart b/json_serializable/test/integration/integration_test.dart index 20add605d..8f0179d42 100644 --- a/json_serializable/test/integration/integration_test.dart +++ b/json_serializable/test/integration/integration_test.dart @@ -133,6 +133,39 @@ void main() { expect(order.statusCode, StatusCode.notFound); roundTripOrder(order); }); + + test('duration toJson', () { + final order = Order(Category.notDiscoveredYet) + ..statusCode = StatusCode.success + ..duration = const Duration( + days: 2, + hours: 4, + minutes: 54, + seconds: 33, + milliseconds: 23, + microseconds: 12, + ); + expect(order.toJson()['duration'], equals(190473023012)); + roundTripOrder(order); + }); + + test('duration fromJson', () { + final order = Order.fromJson({ + 'category': 'not_discovered_yet', + 'duration': 190473023012, + }); + expect( + order.duration, + equals(const Duration( + days: 2, + hours: 4, + minutes: 54, + seconds: 33, + milliseconds: 23, + microseconds: 12, + ))); + roundTripOrder(order); + }); }); group('Item', () { diff --git a/json_serializable/test/integration/json_test_example.dart b/json_serializable/test/integration/json_test_example.dart index e4f4847f6..6db3b0d7c 100644 --- a/json_serializable/test/integration/json_test_example.dart +++ b/json_serializable/test/integration/json_test_example.dart @@ -47,6 +47,8 @@ class Order { int count; bool isRushed; + Duration duration; + @JsonKey(nullable: false) final Category category; final UnmodifiableListView items; diff --git a/json_serializable/test/integration/json_test_example.g.dart b/json_serializable/test/integration/json_test_example.g.dart index df94d702c..d227688a7 100644 --- a/json_serializable/test/integration/json_test_example.g.dart +++ b/json_serializable/test/integration/json_test_example.g.dart @@ -74,6 +74,9 @@ Order _$OrderFromJson(Map json) { (e) => e == null ? null : Item.fromJson(e as Map))) ..count = json['count'] as int ..isRushed = json['isRushed'] as bool + ..duration = json['duration'] == null + ? null + : Duration(microseconds: json['duration'] as int) ..platform = json['platform'] == null ? null : Platform.fromJson(json['platform'] as String) @@ -98,6 +101,7 @@ Map _$OrderToJson(Order instance) { writeNotNull('count', instance.count); val['isRushed'] = instance.isRushed; + val['duration'] = instance.duration?.inMicroseconds; val['category'] = _$CategoryEnumMap[instance.category]; val['items'] = instance.items; val['platform'] = instance.platform; diff --git a/json_serializable/test/integration/json_test_example.non_nullable.dart b/json_serializable/test/integration/json_test_example.non_nullable.dart index da7b3647a..be08014a8 100644 --- a/json_serializable/test/integration/json_test_example.non_nullable.dart +++ b/json_serializable/test/integration/json_test_example.non_nullable.dart @@ -53,6 +53,8 @@ class Order { int count; bool isRushed; + Duration duration; + @JsonKey(nullable: false) final Category category; final UnmodifiableListView items; diff --git a/json_serializable/test/integration/json_test_example.non_nullable.g.dart b/json_serializable/test/integration/json_test_example.non_nullable.g.dart index 86662d4d7..b6c663709 100644 --- a/json_serializable/test/integration/json_test_example.non_nullable.g.dart +++ b/json_serializable/test/integration/json_test_example.non_nullable.g.dart @@ -62,6 +62,7 @@ Order _$OrderFromJson(Map json) { .map((e) => Item.fromJson(e as Map))) ..count = json['count'] as int ..isRushed = json['isRushed'] as bool + ..duration = Duration(microseconds: json['duration'] as int) ..platform = Platform.fromJson(json['platform'] as String) ..altPlatforms = (json['altPlatforms'] as Map) .map((k, e) => MapEntry(k, Platform.fromJson(e as String))) @@ -74,6 +75,7 @@ Order _$OrderFromJson(Map json) { Map _$OrderToJson(Order instance) => { 'count': instance.count, 'isRushed': instance.isRushed, + 'duration': instance.duration.inMicroseconds, 'category': _$CategoryEnumMap[instance.category], 'items': instance.items, 'platform': instance.platform, diff --git a/json_serializable/test/integration/json_test_example.non_nullable.wrapped.dart b/json_serializable/test/integration/json_test_example.non_nullable.wrapped.dart index 3af4d36cf..e6b7501b8 100644 --- a/json_serializable/test/integration/json_test_example.non_nullable.wrapped.dart +++ b/json_serializable/test/integration/json_test_example.non_nullable.wrapped.dart @@ -59,6 +59,8 @@ class Order { int count; bool isRushed; + Duration duration; + @JsonKey(nullable: false) final Category category; final UnmodifiableListView items; diff --git a/json_serializable/test/integration/json_test_example.non_nullable.wrapped.g.dart b/json_serializable/test/integration/json_test_example.non_nullable.wrapped.g.dart index c14ed8882..809fcb930 100644 --- a/json_serializable/test/integration/json_test_example.non_nullable.wrapped.g.dart +++ b/json_serializable/test/integration/json_test_example.non_nullable.wrapped.g.dart @@ -95,6 +95,7 @@ Order _$OrderFromJson(Map json) { .map((e) => Item.fromJson(e as Map))) ..count = json['count'] as int ..isRushed = json['isRushed'] as bool + ..duration = Duration(microseconds: json['duration'] as int) ..platform = Platform.fromJson(json['platform'] as String) ..altPlatforms = (json['altPlatforms'] as Map) .map((k, e) => MapEntry(k, Platform.fromJson(e as String))) @@ -115,6 +116,7 @@ class _$OrderJsonMapWrapper extends $JsonMapWrapper { Iterable get keys => const [ 'count', 'isRushed', + 'duration', 'category', 'items', 'platform', @@ -131,6 +133,8 @@ class _$OrderJsonMapWrapper extends $JsonMapWrapper { return _v.count; case 'isRushed': return _v.isRushed; + case 'duration': + return _v.duration.inMicroseconds; case 'category': return _$CategoryEnumMap[_v.category]; case 'items': diff --git a/json_serializable/test/integration/json_test_example.wrapped.dart b/json_serializable/test/integration/json_test_example.wrapped.dart index b94d130b7..85d6d2976 100644 --- a/json_serializable/test/integration/json_test_example.wrapped.dart +++ b/json_serializable/test/integration/json_test_example.wrapped.dart @@ -53,6 +53,8 @@ class Order { int count; bool isRushed; + Duration duration; + @JsonKey(nullable: false) final Category category; final UnmodifiableListView items; diff --git a/json_serializable/test/integration/json_test_example.wrapped.g.dart b/json_serializable/test/integration/json_test_example.wrapped.g.dart index 0105db2f4..762f1ea77 100644 --- a/json_serializable/test/integration/json_test_example.wrapped.g.dart +++ b/json_serializable/test/integration/json_test_example.wrapped.g.dart @@ -107,6 +107,9 @@ Order _$OrderFromJson(Map json) { (e) => e == null ? null : Item.fromJson(e as Map))) ..count = json['count'] as int ..isRushed = json['isRushed'] as bool + ..duration = json['duration'] == null + ? null + : Duration(microseconds: json['duration'] as int) ..platform = json['platform'] == null ? null : Platform.fromJson(json['platform'] as String) @@ -133,6 +136,7 @@ class _$OrderJsonMapWrapper extends $JsonMapWrapper { yield 'count'; } yield 'isRushed'; + yield 'duration'; yield 'category'; yield 'items'; yield 'platform'; @@ -149,6 +153,8 @@ class _$OrderJsonMapWrapper extends $JsonMapWrapper { return _v.count; case 'isRushed': return _v.isRushed; + case 'duration': + return _v.duration?.inMicroseconds; case 'category': return _$CategoryEnumMap[_v.category]; case 'items': From b83d298d95e86a35b411531295770a41cb86c7cc Mon Sep 17 00:00:00 2001 From: Hadrien Lejard Date: Thu, 4 Oct 2018 23:33:17 +0200 Subject: [PATCH 010/569] Use final when possible. (#329) Fixes https://github.com/dart-lang/json_serializable/issues/290 --- analysis_options.yaml | 1 + .../lib/src/allowed_keys_helpers.dart | 7 +- json_serializable/lib/builder.dart | 4 +- json_serializable/lib/src/convert_pair.dart | 16 ++-- json_serializable/lib/src/decode_helper.dart | 58 +++++++------- json_serializable/lib/src/encoder_helper.dart | 38 ++++----- json_serializable/lib/src/field_helpers.dart | 26 +++---- json_serializable/lib/src/helper_core.dart | 6 +- .../lib/src/json_key_with_conversion.dart | 22 +++--- .../lib/src/json_literal_generator.dart | 16 ++-- .../lib/src/json_serializable_generator.dart | 18 ++--- .../lib/src/shared_checkers.dart | 6 +- .../lib/src/type_helpers/convert_helper.dart | 10 +-- .../src/type_helpers/date_time_helper.dart | 2 +- .../lib/src/type_helpers/enum_helper.dart | 13 ++-- .../lib/src/type_helpers/iterable_helper.dart | 16 ++-- .../type_helpers/json_converter_helper.dart | 22 +++--- .../lib/src/type_helpers/json_helper.dart | 14 ++-- .../lib/src/type_helpers/map_helper.dart | 20 ++--- .../lib/src/type_helpers/uri_helper.dart | 2 +- json_serializable/lib/src/utils.dart | 16 ++-- json_serializable/test/analysis_utils.dart | 9 ++- json_serializable/test/config_test.dart | 18 ++--- .../default_value.checked.g.dart | 4 +- .../test/default_value/default_value.g.dart | 2 +- .../default_value/default_value_test.dart | 6 +- json_serializable/test/enum_helper_test.dart | 4 +- .../test/generic_files/generic_test.dart | 6 +- .../test/integration/integration_test.dart | 25 +++--- .../test/integration/json_test_example.g.dart | 4 +- .../test/json_serializable_test.dart | 78 +++++++++---------- .../test/kitchen_sink/kitchen_sink.g.dart | 2 +- .../kitchen_sink.non_nullable.checked.g.dart | 6 +- .../test/kitchen_sink/kitchen_sink_test.dart | 36 ++++----- .../test/literal/json_literal_test.dart | 16 ++-- json_serializable/test/readme_test.dart | 10 +-- .../src/_json_serializable_test_input.dart | 2 +- .../test/src/checked_test_input.dart | 2 +- .../test/src/inheritance_test_input.dart | 4 +- json_serializable/test/test_file_utils.dart | 2 +- json_serializable/test/test_utils.dart | 8 +- json_serializable/test/utils_test.dart | 4 +- .../test/yaml/build_config.g.dart | 6 +- json_serializable/test/yaml/yaml_test.dart | 26 +++---- json_serializable/tool/builder.dart | 8 +- 45 files changed, 314 insertions(+), 307 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index d7eaf1860..9f85aa50a 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -56,6 +56,7 @@ linter: - prefer_contains - prefer_equal_for_default_values - prefer_final_fields + #- prefer_final_locals - prefer_initializing_formals - prefer_interpolation_to_compose_strings - prefer_is_empty diff --git a/json_annotation/lib/src/allowed_keys_helpers.dart b/json_annotation/lib/src/allowed_keys_helpers.dart index 3db26651e..dbee77863 100644 --- a/json_annotation/lib/src/allowed_keys_helpers.dart +++ b/json_annotation/lib/src/allowed_keys_helpers.dart @@ -12,7 +12,7 @@ void $checkKeys(Map map, List requiredKeys, List disallowNullValues}) { if (map != null && allowedKeys != null) { - var invalidKeys = + final invalidKeys = map.keys.cast().where((k) => !allowedKeys.contains(k)).toList(); if (invalidKeys.isNotEmpty) { throw UnrecognizedKeysException(invalidKeys, map, allowedKeys); @@ -20,14 +20,15 @@ void $checkKeys(Map map, } if (requiredKeys != null) { - var missingKeys = requiredKeys.where((k) => !map.keys.contains(k)).toList(); + final missingKeys = + requiredKeys.where((k) => !map.keys.contains(k)).toList(); if (missingKeys.isNotEmpty) { throw MissingRequiredKeysException(missingKeys, map); } } if (map != null && disallowNullValues != null) { - var nullValuedKeys = map.entries + final nullValuedKeys = map.entries .where((entry) => disallowNullValues.contains(entry.key) && entry.value == null) .map((entry) => entry.key as String) diff --git a/json_serializable/lib/builder.dart b/json_serializable/lib/builder.dart index 5bd6550b7..cce8f3c53 100644 --- a/json_serializable/lib/builder.dart +++ b/json_serializable/lib/builder.dart @@ -23,9 +23,9 @@ import 'src/json_part_builder.dart'; Builder jsonSerializable(BuilderOptions options) { // Paranoid copy of options.config - don't assume it's mutable or needed // elsewhere. - var optionsMap = Map.from(options.config); + final optionsMap = Map.from(options.config); - var builder = jsonPartBuilder( + final builder = jsonPartBuilder( useWrappers: optionsMap.remove('use_wrappers') as bool, checked: optionsMap.remove('checked') as bool, anyMap: optionsMap.remove('any_map') as bool, diff --git a/json_serializable/lib/src/convert_pair.dart b/json_serializable/lib/src/convert_pair.dart index f85f6605d..9fc37d2c0 100644 --- a/json_serializable/lib/src/convert_pair.dart +++ b/json_serializable/lib/src/convert_pair.dart @@ -19,8 +19,8 @@ class ConvertPair { ConvertPair._(this.fromJson, this.toJson); factory ConvertPair(DartObject obj, FieldElement element) { - var toJson = _convertData(obj, element, false); - var fromJson = _convertData(obj, element, true); + final toJson = _convertData(obj, element, false); + final fromJson = _convertData(obj, element, true); return ConvertPair._(fromJson, toJson); } @@ -31,16 +31,16 @@ class ConvertPair { } ConvertData _convertData(DartObject obj, FieldElement element, bool isFrom) { - var paramName = isFrom ? 'fromJson' : 'toJson'; - var objectValue = obj.getField(paramName); + final paramName = isFrom ? 'fromJson' : 'toJson'; + final objectValue = obj.getField(paramName); if (objectValue.isNull) { return null; } - var type = objectValue.type as FunctionType; + final type = objectValue.type as FunctionType; - var executableElement = type.element as ExecutableElement; + final executableElement = type.element as ExecutableElement; if (executableElement.parameters.isEmpty || executableElement.parameters.first.isNamed || @@ -51,9 +51,9 @@ ConvertData _convertData(DartObject obj, FieldElement element, bool isFrom) { 'positional paramater.'); } - var argType = executableElement.parameters.first.type; + final argType = executableElement.parameters.first.type; if (isFrom) { - var returnType = executableElement.returnType; + final returnType = executableElement.returnType; if (returnType is TypeParameterType) { // We keep things simple in this case. We rely on inferred type arguments diff --git a/json_serializable/lib/src/decode_helper.dart b/json_serializable/lib/src/decode_helper.dart index a46b31315..fcdcbabe3 100644 --- a/json_serializable/lib/src/decode_helper.dart +++ b/json_serializable/lib/src/decode_helper.dart @@ -26,7 +26,7 @@ abstract class DecodeHelper implements HelperCore { assert(annotation.createFactory); assert(_buffer.isEmpty); - var mapType = generator.anyMap ? 'Map' : 'Map'; + final mapType = generator.anyMap ? 'Map' : 'Map'; _buffer.write('$targetClassReference ' '${prefix}FromJson${genericClassArgumentsImpl(true)}' '($mapType json) {\n'); @@ -38,7 +38,7 @@ abstract class DecodeHelper implements HelperCore { _ConstructorData data; if (generator.checked) { - var classLiteral = escapeDartString(element.name); + final classLiteral = escapeDartString(element.name); _buffer.write(''' return \$checkedNew( @@ -62,11 +62,11 @@ abstract class DecodeHelper implements HelperCore { accessibleFields.values .where((fe) => data.usedCtorParamsAndFields.contains(fe.name))); _buffer.write(''' - var val = ${data.content};'''); + final val = ${data.content};'''); - for (var field in data.fieldsToSet) { + for (final field in data.fieldsToSet) { _buffer.writeln(); - var safeName = safeNameAccess(accessibleFields[field]); + final safeName = safeNameAccess(accessibleFields[field]); _buffer.write(''' \$checkedConvert(json, $safeName, (v) => '''); _buffer.write('val.$field = '); @@ -78,7 +78,7 @@ abstract class DecodeHelper implements HelperCore { _buffer.write('''\n return val; }'''); - var fieldKeyMap = Map.fromEntries(data.usedCtorParamsAndFields + final fieldKeyMap = Map.fromEntries(data.usedCtorParamsAndFields .map((k) => MapEntry(k, nameAccess(accessibleFields[k]))) .where((me) => me.key != me.value)); @@ -86,7 +86,7 @@ abstract class DecodeHelper implements HelperCore { if (fieldKeyMap.isEmpty) { fieldKeyMapArg = ''; } else { - var mapLiteral = jsonMapAsDart(fieldKeyMap); + final mapLiteral = jsonMapAsDart(fieldKeyMap); fieldKeyMapArg = ', fieldKeyMap: const $mapLiteral'; } @@ -112,7 +112,7 @@ abstract class DecodeHelper implements HelperCore { _buffer.write(''' return ${data.content}'''); - for (var field in data.fieldsToSet) { + for (final field in data.fieldsToSet) { _buffer.writeln(); _buffer.write(' ..$field = '); _buffer.write(deserializeFun(field)); @@ -127,30 +127,30 @@ abstract class DecodeHelper implements HelperCore { void _writeChecks(int indent, JsonSerializable classAnnotation, Iterable accessibleFields) { - var args = []; + final args = []; String constantList(Iterable things) => 'const ${jsonLiteralAsDart(things.map(nameAccess).toList())}'; if (classAnnotation.disallowUnrecognizedKeys) { - var allowKeysLiteral = constantList(accessibleFields); + final allowKeysLiteral = constantList(accessibleFields); args.add('allowedKeys: $allowKeysLiteral'); } - var requiredKeys = + final requiredKeys = accessibleFields.where((fe) => jsonKeyFor(fe).required).toList(); if (requiredKeys.isNotEmpty) { - var requiredKeyLiteral = constantList(requiredKeys); + final requiredKeyLiteral = constantList(requiredKeys); args.add('requiredKeys: $requiredKeyLiteral'); } - var disallowNullKeys = accessibleFields + final disallowNullKeys = accessibleFields .where((fe) => jsonKeyFor(fe).disallowNullValue) .toList(); if (disallowNullKeys.isNotEmpty) { - var dissallowNullKeyLiteral = constantList(disallowNullKeys); + final dissallowNullKeyLiteral = constantList(disallowNullKeys); args.add('disallowNullValues: $dissallowNullKeyLiteral'); } @@ -163,9 +163,9 @@ abstract class DecodeHelper implements HelperCore { String _deserializeForField(FieldElement field, {ParameterElement ctorParam, bool checkedProperty}) { checkedProperty ??= false; - var jsonKeyName = safeNameAccess(field); - var targetType = ctorParam?.type ?? field.type; - var contextHelper = getHelperContext(field); + final jsonKeyName = safeNameAccess(field); + final targetType = ctorParam?.type ?? field.type; + final contextHelper = getHelperContext(field); String value; try { @@ -186,7 +186,7 @@ abstract class DecodeHelper implements HelperCore { throw createInvalidGenerationError('fromJson', field, e); } - var defaultValue = jsonKeyFor(field).defaultValue; + final defaultValue = jsonKeyFor(field).defaultValue; if (defaultValue != null) { if (!contextHelper.nullable) { throwUnsupported(field, @@ -216,26 +216,26 @@ _ConstructorData _writeConstructorInvocation( Map unavailableReasons, String deserializeForField(String paramOrFieldName, {ParameterElement ctorParam})) { - var className = classElement.name; + final className = classElement.name; - var ctor = classElement.unnamedConstructor; + final ctor = classElement.unnamedConstructor; if (ctor == null) { // TODO(kevmoo): support using another ctor - dart-lang/json_serializable#50 throw UnsupportedError( 'The class `$className` has no default constructor.'); } - var usedCtorParamsAndFields = Set(); - var constructorArguments = []; - var namedConstructorArguments = []; + final usedCtorParamsAndFields = Set(); + final constructorArguments = []; + final namedConstructorArguments = []; - for (var arg in ctor.parameters) { + for (final arg in ctor.parameters) { if (!availableConstructorParameters.contains(arg.name)) { if (arg.isNotOptional) { var msg = 'Cannot populate the required constructor ' 'argument: ${arg.name}.'; - var additionalInfo = unavailableReasons[arg.name]; + final additionalInfo = unavailableReasons[arg.name]; if (additionalInfo != null) { msg = '$msg $additionalInfo'; @@ -260,15 +260,15 @@ _ConstructorData _writeConstructorInvocation( constructorArguments.followedBy(namedConstructorArguments)); // fields that aren't already set by the constructor and that aren't final - var remainingFieldsForInvocationBody = + final remainingFieldsForInvocationBody = writeableFields.toSet().difference(usedCtorParamsAndFields); - var buffer = StringBuffer(); + final buffer = StringBuffer(); buffer.write('$className${genericClassArguments(classElement, false)}('); if (constructorArguments.isNotEmpty) { buffer.writeln(); buffer.writeAll(constructorArguments.map((paramElement) { - var content = + final content = deserializeForField(paramElement.name, ctorParam: paramElement); return ' $content'; }), ',\n'); @@ -279,7 +279,7 @@ _ConstructorData _writeConstructorInvocation( if (namedConstructorArguments.isNotEmpty) { buffer.writeln(); buffer.writeAll(namedConstructorArguments.map((paramElement) { - var value = + final value = deserializeForField(paramElement.name, ctorParam: paramElement); return ' ${paramElement.name}: $value'; }), ',\n'); diff --git a/json_serializable/lib/src/encoder_helper.dart b/json_serializable/lib/src/encoder_helper.dart index 13bdd3695..92ea91db3 100644 --- a/json_serializable/lib/src/encoder_helper.dart +++ b/json_serializable/lib/src/encoder_helper.dart @@ -27,10 +27,10 @@ abstract class EncodeHelper implements HelperCore { Iterable createToJson(Set accessibleFields) sync* { assert(annotation.createToJson); - var buffer = StringBuffer(); + final buffer = StringBuffer(); if (generator.generateToJsonFunction) { - var functionName = '${prefix}ToJson${genericClassArgumentsImpl(true)}'; + final functionName = '${prefix}ToJson${genericClassArgumentsImpl(true)}'; buffer.write('Map $functionName' '($targetClassReference $_toJsonParamName) '); } else { @@ -41,7 +41,7 @@ abstract class EncodeHelper implements HelperCore { // write copies of the fields - this allows the toJson method to access // the fields of the target class - for (var field in accessibleFields) { + for (final field in accessibleFields) { //TODO - handle aliased imports buffer.writeln(' ${field.type} get ${field.name};'); } @@ -49,10 +49,11 @@ abstract class EncodeHelper implements HelperCore { buffer.write(' Map toJson() '); } - var writeNaive = accessibleFields.every(_writeJsonValueNaive); + final writeNaive = accessibleFields.every(_writeJsonValueNaive); if (generator.useWrappers) { - var param = generator.generateToJsonFunction ? _toJsonParamName : 'this'; + final param = + generator.generateToJsonFunction ? _toJsonParamName : 'this'; buffer.writeln('=> ${_wrapperClassName(false)}($param);'); } else { if (writeNaive) { @@ -77,11 +78,11 @@ abstract class EncodeHelper implements HelperCore { } String _createWrapperClass(Iterable fields) { - var buffer = StringBuffer(); + final buffer = StringBuffer(); buffer.writeln(); // TODO(kevmoo): write JsonMapWrapper if annotation lib is prefix-imported - var fieldType = generator.generateToJsonFunction + final fieldType = generator.generateToJsonFunction ? targetClassReference : _mixinClassName(false); @@ -94,7 +95,7 @@ class ${_wrapperClassName(true)} extends \$JsonMapWrapper { if (fields.every(_writeJsonValueNaive)) { // TODO(kevmoo): consider just doing one code path – if it's fast // enough - var jsonKeys = fields.map(safeNameAccess).join(', '); + final jsonKeys = fields.map(safeNameAccess).join(', '); // TODO(kevmoo): maybe put this in a static field instead? // const lists have unfortunate overhead @@ -106,8 +107,8 @@ class ${_wrapperClassName(true)} extends \$JsonMapWrapper { // At least one field should be excluded if null buffer.writeln(' @override\n Iterable get keys sync* {'); - for (var field in fields) { - var nullCheck = !_writeJsonValueNaive(field); + for (final field in fields) { + final nullCheck = !_writeJsonValueNaive(field); if (nullCheck) { buffer.write(' if (_v.${field.name} != null) {\n '); } @@ -126,8 +127,8 @@ class ${_wrapperClassName(true)} extends \$JsonMapWrapper { if (key is String) { switch (key) {'''); - for (var field in fields) { - var valueAccess = '_v.${field.name}'; + for (final field in fields) { + final valueAccess = '_v.${field.name}'; buffer.writeln(''' case ${safeNameAccess(field)}: return ${_serializeField(field, valueAccess)};'''); @@ -147,8 +148,9 @@ class ${_wrapperClassName(true)} extends \$JsonMapWrapper { buffer.writeln('=> {'); buffer.writeAll(fields.map((field) { - var access = _fieldAccess(field); - var value = '${safeNameAccess(field)}: ${_serializeField(field, access)}'; + final access = _fieldAccess(field); + final value = + '${safeNameAccess(field)}: ${_serializeField(field, access)}'; return ' $value'; }), ',\n'); @@ -167,7 +169,7 @@ class ${_wrapperClassName(true)} extends \$JsonMapWrapper { StringBuffer buffer, Iterable fields) { buffer.writeln('{'); - buffer.writeln(' var $generatedLocalVarName = {'); + buffer.writeln(' final $generatedLocalVarName = {'); // Note that the map literal is left open above. As long as target fields // don't need to be intercepted by the `only if null` logic, write them @@ -175,9 +177,9 @@ class ${_wrapperClassName(true)} extends \$JsonMapWrapper { // serialization. var directWrite = true; - for (var field in fields) { + for (final field in fields) { var safeFieldAccess = _fieldAccess(field); - var safeJsonKeyString = safeNameAccess(field); + final safeJsonKeyString = safeNameAccess(field); // If `fieldName` collides with one of the local helpers, prefix // access with `this.`. @@ -188,7 +190,7 @@ class ${_wrapperClassName(true)} extends \$JsonMapWrapper { safeFieldAccess = 'this.$safeFieldAccess'; } - var expression = _serializeField(field, safeFieldAccess); + final expression = _serializeField(field, safeFieldAccess); if (_writeJsonValueNaive(field)) { if (directWrite) { buffer.writeln(' $safeJsonKeyString: $expression,'); diff --git a/json_serializable/lib/src/field_helpers.dart b/json_serializable/lib/src/field_helpers.dart index f771ed9d2..0558b15d2 100644 --- a/json_serializable/lib/src/field_helpers.dart +++ b/json_serializable/lib/src/field_helpers.dart @@ -20,14 +20,14 @@ class _FieldSet implements Comparable<_FieldSet> { factory _FieldSet(FieldElement classField, FieldElement superField) { // At least one of these will != null, perhaps both. - var fields = [classField, superField].where((fe) => fe != null).toList(); + final fields = [classField, superField].where((fe) => fe != null).toList(); // Prefer the class field over the inherited field when sorting. - var sortField = fields.first; + final sortField = fields.first; // Prefer the field that's annotated with `JsonKey`, if any. // If not, use the class field. - var fieldHasJsonKey = + final fieldHasJsonKey = fields.firstWhere(hasJsonKeyAnnotation, orElse: () => fields.first); return _FieldSet._(fieldHasJsonKey, sortField); @@ -37,7 +37,7 @@ class _FieldSet implements Comparable<_FieldSet> { int compareTo(_FieldSet other) => _sortByLocation(sortField, other.sortField); static int _sortByLocation(FieldElement a, FieldElement b) { - var checkerA = TypeChecker.fromStatic(a.enclosingElement.type); + final checkerA = TypeChecker.fromStatic(a.enclosingElement.type); if (!checkerA.isExactly(b.enclosingElement)) { // in this case, you want to prioritize the enclosingElement that is more @@ -47,7 +47,7 @@ class _FieldSet implements Comparable<_FieldSet> { return -1; } - var checkerB = TypeChecker.fromStatic(b.enclosingElement.type); + final checkerB = TypeChecker.fromStatic(b.enclosingElement.type); if (checkerB.isSuperOf(a.enclosingElement)) { return 1; @@ -74,13 +74,13 @@ class _FieldSet implements Comparable<_FieldSet> { Iterable createSortedFieldSet(ClassElement element) { // Get all of the fields that need to be assigned // TODO: support overriding the field set with an annotation option - var elementInstanceFields = Map.fromEntries( + final elementInstanceFields = Map.fromEntries( element.fields.where((e) => !e.isStatic).map((e) => MapEntry(e.name, e))); - var inheritedFields = {}; - var manager = InheritanceManager(element.library); + final inheritedFields = {}; + final manager = InheritanceManager(element.library); - for (var v in manager.getMembersInheritedFromClasses(element).values) { + for (final v in manager.getMembersInheritedFromClasses(element).values) { assert(v is! FieldElement); if (_dartCoreObjectChecker.isExactly(v.enclosingElement)) { continue; @@ -88,24 +88,24 @@ Iterable createSortedFieldSet(ClassElement element) { if (v is PropertyAccessorElement && v.isGetter) { assert(v.variable is FieldElement); - var variable = v.variable as FieldElement; + final variable = v.variable as FieldElement; assert(!inheritedFields.containsKey(variable.name)); inheritedFields[variable.name] = variable; } } // Get the list of all fields for `element` - var allFields = + final allFields = elementInstanceFields.keys.toSet().union(inheritedFields.keys.toSet()); - var fields = allFields + final fields = allFields .map((e) => _FieldSet(elementInstanceFields[e], inheritedFields[e])) .toList(); // Sort the fields using the `compare` implementation in _FieldSet fields.sort(); - var fieldList = fields.map((fs) => fs.field).toList(); + final fieldList = fields.map((fs) => fs.field).toList(); warnUndefinedElements(fieldList); return fieldList; } diff --git a/json_serializable/lib/src/helper_core.dart b/json_serializable/lib/src/helper_core.dart index ea7bb4c14..7e4cbe9a0 100644 --- a/json_serializable/lib/src/helper_core.dart +++ b/json_serializable/lib/src/helper_core.dart @@ -93,15 +93,15 @@ String genericClassArguments(ClassElement element, bool withConstraints) { if (withConstraints == null || element.typeParameters.isEmpty) { return ''; } - var values = element.typeParameters + final values = element.typeParameters .map((t) => withConstraints ? t.toString() : t.name) .join(', '); return '<$values>'; } void warnUndefinedElements(Iterable elements) { - for (var element in elements.where((fe) => fe.type.isUndefined)) { - var span = spanForElement(element); + for (final element in elements.where((fe) => fe.type.isUndefined)) { + final span = spanForElement(element); log.warning(''' This element has an undefined type. It may causes issues when generated code. ${span.start.toolString} diff --git a/json_serializable/lib/src/json_key_with_conversion.dart b/json_serializable/lib/src/json_key_with_conversion.dart index 29a5fcb0d..a4de25d63 100644 --- a/json_serializable/lib/src/json_key_with_conversion.dart +++ b/json_serializable/lib/src/json_key_with_conversion.dart @@ -33,7 +33,7 @@ JsonKey _from(FieldElement element, JsonSerializable classAnnotation) { // If an annotation exists on `element` the source is a 'real' field. // If the result is `null`, check the getter – it is a property. // TODO(kevmoo) setters: github.com/dart-lang/json_serializable/issues/24 - var obj = _jsonKeyAnnotation(element); + final obj = _jsonKeyAnnotation(element); if (obj == null) { return _populateJsonKey(classAnnotation, element); @@ -44,7 +44,7 @@ JsonKey _from(FieldElement element, JsonSerializable classAnnotation) { return null; } - var reader = ConstantReader(dartObject); + final reader = ConstantReader(dartObject); String badType; if (reader.isSymbol) { @@ -64,7 +64,7 @@ JsonKey _from(FieldElement element, JsonSerializable classAnnotation) { element, '`defaultValue` is `$badType`, it must be a literal.'); } - var literal = reader.literalValue; + final literal = reader.literalValue; if (literal is num || literal is String || literal is bool) { return literal; @@ -73,7 +73,7 @@ JsonKey _from(FieldElement element, JsonSerializable classAnnotation) { .map((e) => _getLiteral(e, things.followedBy(['List']))) .toList(); } else if (literal is Map) { - var mapThings = things.followedBy(['Map']); + final mapThings = things.followedBy(['Map']); return literal.map((k, v) => MapEntry(_getLiteral(k, mapThings), _getLiteral(v, mapThings))); } @@ -87,14 +87,14 @@ JsonKey _from(FieldElement element, JsonSerializable classAnnotation) { 'Please rerun your build with `--verbose` and file an issue.'); } - var defaultValueObject = obj.getField('defaultValue'); + final defaultValueObject = obj.getField('defaultValue'); Object defaultValueLiteral; - var enumFields = iterateEnumFields(defaultValueObject.type); + final enumFields = iterateEnumFields(defaultValueObject.type); if (enumFields != null) { - var allowedValues = enumFields.map((p) => p.name).toList(); - var enumValueIndex = defaultValueObject.getField('index').toIntValue(); + final allowedValues = enumFields.map((p) => p.name).toList(); + final enumValueIndex = defaultValueObject.getField('index').toIntValue(); defaultValueLiteral = '${defaultValueObject.type.name}.${allowedValues[enumValueIndex]}'; } else { @@ -104,8 +104,8 @@ JsonKey _from(FieldElement element, JsonSerializable classAnnotation) { } } - var disallowNullValue = obj.getField('disallowNullValue').toBoolValue(); - var includeIfNull = obj.getField('includeIfNull').toBoolValue(); + final disallowNullValue = obj.getField('disallowNullValue').toBoolValue(); + final includeIfNull = obj.getField('includeIfNull').toBoolValue(); if (disallowNullValue == true) { if (includeIfNull == true) { @@ -140,7 +140,7 @@ JsonKey _populateJsonKey( bool required, bool disallowNullValue, ConvertPair jsonConvertPair}) { - var jsonKey = JsonKey( + final jsonKey = JsonKey( name: _encodedFieldName(classAnnotation, name, fieldElement), nullable: nullable ?? classAnnotation.nullable, includeIfNull: _includeIfNull( diff --git a/json_serializable/lib/src/json_literal_generator.dart b/json_serializable/lib/src/json_literal_generator.dart index 21f160daa..3498889ca 100644 --- a/json_serializable/lib/src/json_literal_generator.dart +++ b/json_serializable/lib/src/json_literal_generator.dart @@ -25,15 +25,15 @@ class JsonLiteralGenerator extends GeneratorForAnnotation { '`annotation.path` must be relative path to the source file.'); } - var sourcePathDir = p.dirname(buildStep.inputId.path); - var fileId = AssetId(buildStep.inputId.package, + final sourcePathDir = p.dirname(buildStep.inputId.path); + final fileId = AssetId(buildStep.inputId.package, p.join(sourcePathDir, annotation.read('path').stringValue)); - var content = json.decode(await buildStep.readAsString(fileId)); + final content = json.decode(await buildStep.readAsString(fileId)); - var asConst = annotation.read('asConst').boolValue; + final asConst = annotation.read('asConst').boolValue; - var thing = jsonLiteralAsDart(content).toString(); - var marked = asConst ? 'const' : 'final'; + final thing = jsonLiteralAsDart(content).toString(); + final marked = asConst ? 'const' : 'final'; return '$marked _\$${element.name}JsonLiteral = $thing;'; } @@ -48,7 +48,7 @@ String jsonLiteralAsDart(dynamic value) { if (value is bool || value is num) return value.toString(); if (value is List) { - var listItems = value.map(jsonLiteralAsDart).join(', '); + final listItems = value.map(jsonLiteralAsDart).join(', '); return '[$listItems]'; } @@ -59,7 +59,7 @@ String jsonLiteralAsDart(dynamic value) { } String jsonMapAsDart(Map value) { - var buffer = StringBuffer(); + final buffer = StringBuffer(); buffer.write('{'); var first = true; diff --git a/json_serializable/lib/src/json_serializable_generator.dart b/json_serializable/lib/src/json_serializable_generator.dart index 85f296aae..2745974f3 100644 --- a/json_serializable/lib/src/json_serializable_generator.dart +++ b/json_serializable/lib/src/json_serializable_generator.dart @@ -163,15 +163,15 @@ class JsonSerializableGenerator Iterable generateForAnnotatedElement( Element element, ConstantReader annotation, BuildStep buildStep) { if (element is! ClassElement) { - var name = element.name; + final name = element.name; throw InvalidGenerationSourceError('Generator cannot target `$name`.', todo: 'Remove the JsonSerializable annotation from `$name`.', element: element); } - var classElement = element as ClassElement; - var classAnnotation = valueForAnnotation(annotation); - var helper = _GeneratorHelper(this, classElement, classAnnotation); + final classElement = element as ClassElement; + final classAnnotation = valueForAnnotation(annotation); + final helper = _GeneratorHelper(this, classElement, classAnnotation); return helper._generate(); } } @@ -190,14 +190,14 @@ class _GeneratorHelper extends HelperCore with EncodeHelper, DecodeHelper { Iterable _generate() sync* { assert(_addedMembers.isEmpty); - var sortedFields = createSortedFieldSet(element); + final sortedFields = createSortedFieldSet(element); // Used to keep track of why a field is ignored. Useful for providing // helpful errors when generating constructor calls that try to use one of // these fields. - var unavailableReasons = {}; + final unavailableReasons = {}; - var accessibleFields = sortedFields.fold>( + final accessibleFields = sortedFields.fold>( {}, (map, field) { if (!field.isPublic) { unavailableReasons[field.name] = 'It is assigned to a private field.'; @@ -218,7 +218,7 @@ class _GeneratorHelper extends HelperCore with EncodeHelper, DecodeHelper { var accessibleFieldSet = accessibleFields.values.toSet(); if (annotation.createFactory) { - var createResult = createFactory(accessibleFields, unavailableReasons); + final createResult = createFactory(accessibleFields, unavailableReasons); yield createResult.output; accessibleFieldSet = accessibleFields.entries @@ -231,7 +231,7 @@ class _GeneratorHelper extends HelperCore with EncodeHelper, DecodeHelper { // We do this now, since we have a final field list after any pruning done // by `_writeCtor`. accessibleFieldSet.fold(Set(), (Set set, fe) { - var jsonKey = nameAccess(fe); + final jsonKey = nameAccess(fe); if (!set.add(jsonKey)) { throw InvalidGenerationSourceError( 'More than one field has the JSON key `$jsonKey`.', diff --git a/json_serializable/lib/src/shared_checkers.dart b/json_serializable/lib/src/shared_checkers.dart index 7c25b4b00..a522ed416 100644 --- a/json_serializable/lib/src/shared_checkers.dart +++ b/json_serializable/lib/src/shared_checkers.dart @@ -23,7 +23,7 @@ DartType coreIterableGenericType(DartType type) => /// /// If the [checker] [Type] doesn't have generic arguments, `null` is returned. List typeArgumentsOf(DartType type, TypeChecker checker) { - var implementation = _getImplementationType(type, checker) as InterfaceType; + final implementation = _getImplementationType(type, checker) as InterfaceType; return implementation?.typeArguments; } @@ -41,14 +41,14 @@ String asStatement(DartType type) { } if (coreIterableTypeChecker.isAssignableFromType(type)) { - var itemType = coreIterableGenericType(type); + final itemType = coreIterableGenericType(type); if (itemType.isDynamic || itemType.isObject) { return ' as List'; } } if (coreMapTypeChecker.isAssignableFromType(type)) { - var args = typeArgumentsOf(type, coreMapTypeChecker); + final args = typeArgumentsOf(type, coreMapTypeChecker); assert(args.length == 2); if (args.every((dt) => dt.isDynamic || dt.isObject)) { diff --git a/json_serializable/lib/src/type_helpers/convert_helper.dart b/json_serializable/lib/src/type_helpers/convert_helper.dart index 1708575dd..218be515e 100644 --- a/json_serializable/lib/src/type_helpers/convert_helper.dart +++ b/json_serializable/lib/src/type_helpers/convert_helper.dart @@ -27,11 +27,11 @@ class ConvertHelper extends TypeHelper { @override String serialize(DartType targetType, String expression, TypeHelperContextWithConvert context) { - var toJsonData = context.serializeConvertData; + final toJsonData = context.serializeConvertData; if (toJsonData != null) { assert(toJsonData.paramType is TypeParameterType || targetType.isAssignableTo(toJsonData.paramType)); - var result = '${toJsonData.name}($expression)'; + final result = '${toJsonData.name}($expression)'; return commonNullPrefix(context.nullable, expression, result); } return null; @@ -40,10 +40,10 @@ class ConvertHelper extends TypeHelper { @override String deserialize(DartType targetType, String expression, TypeHelperContextWithConvert context) { - var fromJsonData = context.deserializeConvertData; + final fromJsonData = context.deserializeConvertData; if (fromJsonData != null) { - var asContent = asStatement(fromJsonData.paramType); - var result = '${fromJsonData.name}($expression$asContent)'; + final asContent = asStatement(fromJsonData.paramType); + final result = '${fromJsonData.name}($expression$asContent)'; return commonNullPrefix(context.nullable, expression, result); } return null; diff --git a/json_serializable/lib/src/type_helpers/date_time_helper.dart b/json_serializable/lib/src/type_helpers/date_time_helper.dart index d09301db1..bca740106 100644 --- a/json_serializable/lib/src/type_helpers/date_time_helper.dart +++ b/json_serializable/lib/src/type_helpers/date_time_helper.dart @@ -16,7 +16,7 @@ class DateTimeHelper extends TypeHelper { return null; } - var buffer = StringBuffer(expression); + final buffer = StringBuffer(expression); if (context.nullable) { buffer.write('?'); diff --git a/json_serializable/lib/src/type_helpers/enum_helper.dart b/json_serializable/lib/src/type_helpers/enum_helper.dart index f5c061f1e..a126d43e4 100644 --- a/json_serializable/lib/src/type_helpers/enum_helper.dart +++ b/json_serializable/lib/src/type_helpers/enum_helper.dart @@ -16,7 +16,7 @@ class EnumHelper extends TypeHelper { @override String serialize( DartType targetType, String expression, TypeHelperContext context) { - var memberContent = _enumValueMapFromType(targetType); + final memberContent = _enumValueMapFromType(targetType); if (memberContent == null) { return null; @@ -30,7 +30,7 @@ class EnumHelper extends TypeHelper { @override String deserialize( DartType targetType, String expression, TypeHelperContext context) { - var memberContent = _enumValueMapFromType(targetType); + final memberContent = _enumValueMapFromType(targetType); if (memberContent == null) { return null; @@ -44,7 +44,7 @@ class EnumHelper extends TypeHelper { context.addMember(memberContent); - var functionName = + final functionName = context.nullable ? r'_$enumDecodeNullable' : r'_$enumDecode'; return '$functionName(${_constMapName(targetType)}, ' '$expression)'; @@ -54,14 +54,15 @@ class EnumHelper extends TypeHelper { String _constMapName(DartType targetType) => '_\$${targetType.name}EnumMap'; String _enumValueMapFromType(DartType targetType) { - var enumMap = enumFieldsMap(targetType); + final enumMap = enumFieldsMap(targetType); if (enumMap == null) { return null; } - var items = enumMap.entries.map((e) => ' ${targetType.name}.${e.key.name}: ' - '${jsonLiteralAsDart(e.value)}'); + final items = + enumMap.entries.map((e) => ' ${targetType.name}.${e.key.name}: ' + '${jsonLiteralAsDart(e.value)}'); return 'const ${_constMapName(targetType)} = ' '<${targetType.name}, dynamic>{\n${items.join(',\n')}\n};'; diff --git a/json_serializable/lib/src/type_helpers/iterable_helper.dart b/json_serializable/lib/src/type_helpers/iterable_helper.dart index edfcad003..ad8bc505e 100644 --- a/json_serializable/lib/src/type_helpers/iterable_helper.dart +++ b/json_serializable/lib/src/type_helpers/iterable_helper.dart @@ -19,21 +19,21 @@ class IterableHelper extends TypeHelper { return null; } - var itemType = coreIterableGenericType(targetType); + final itemType = coreIterableGenericType(targetType); // This block will yield a regular list, which works fine for JSON // Although it's possible that child elements may be marked unsafe var isList = _coreListChecker.isAssignableFromType(targetType); - var subField = context.serialize(itemType, closureArg); + final subField = context.serialize(itemType, closureArg); - var optionalQuestion = context.nullable ? '?' : ''; + final optionalQuestion = context.nullable ? '?' : ''; // In the case of trivial JSON types (int, String, etc), `subField` // will be identical to `substitute` – so no explicit mapping is needed. // If they are not equal, then we to write out the substitution. if (subField != closureArg) { - var lambda = LambdaResult.process(subField, closureArg); + final lambda = LambdaResult.process(subField, closureArg); if (context.useWrappers && isList) { var method = '\$wrapList'; if (context.nullable) { @@ -65,9 +65,9 @@ class IterableHelper extends TypeHelper { return null; } - var iterableGenericType = coreIterableGenericType(targetType); + final iterableGenericType = coreIterableGenericType(targetType); - var itemSubVal = context.deserialize(iterableGenericType, closureArg); + final itemSubVal = context.deserialize(iterableGenericType, closureArg); // If `itemSubVal` is the same and it's not a Set, then we don't need to do // anything fancy @@ -76,9 +76,9 @@ class IterableHelper extends TypeHelper { return '$expression as List'; } - var optionalQuestion = context.nullable ? '?' : ''; + final optionalQuestion = context.nullable ? '?' : ''; - var lambda = LambdaResult.process(itemSubVal, closureArg); + final lambda = LambdaResult.process(itemSubVal, closureArg); var output = '($expression as List)$optionalQuestion.map($lambda)'; diff --git a/json_serializable/lib/src/type_helpers/json_converter_helper.dart b/json_serializable/lib/src/type_helpers/json_converter_helper.dart index 86559b6f5..0f3b8a3e6 100644 --- a/json_serializable/lib/src/type_helpers/json_converter_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_converter_helper.dart @@ -20,7 +20,7 @@ class JsonConverterHelper extends TypeHelper { @override LambdaResult serialize( DartType targetType, String expression, TypeHelperContext context) { - var converter = _typeConverter(targetType, context); + final converter = _typeConverter(targetType, context); if (converter == null) { return null; @@ -32,12 +32,12 @@ class JsonConverterHelper extends TypeHelper { @override LambdaResult deserialize( DartType targetType, String expression, TypeHelperContext context) { - var converter = _typeConverter(targetType, context); + final converter = _typeConverter(targetType, context); if (converter == null) { return null; } - var asContent = asStatement(converter.jsonType); + final asContent = asStatement(converter.jsonType); return LambdaResult( '$expression$asContent', '${converter.accessString}.fromJson'); @@ -89,11 +89,11 @@ _JsonConvertData _typeConverterFrom( element: matchingAnnotations[1].elementAnnotation.element); } - var match = matchingAnnotations.single; + final match = matchingAnnotations.single; - var annotationElement = match.elementAnnotation.element; + final annotationElement = match.elementAnnotation.element; if (annotationElement is PropertyAccessorElement) { - var enclosing = annotationElement.enclosingElement; + final enclosing = annotationElement.enclosingElement; var accessString = annotationElement.name; @@ -104,7 +104,7 @@ _JsonConvertData _typeConverterFrom( return _JsonConvertData.propertyAccess(accessString, match.jsonType); } - var reviver = ConstantReader(match.annotation).revive(); + final reviver = ConstantReader(match.annotation).revive(); if (reviver.namedArguments.isNotEmpty || reviver.positionalArguments.isNotEmpty) { @@ -134,11 +134,11 @@ class _ConverterMatch { _ConverterMatch _compatibleMatch( DartType targetType, ElementAnnotation annotation) { - var constantValue = annotation.computeConstantValue(); + final constantValue = annotation.computeConstantValue(); - var converterClassElement = constantValue.type.element as ClassElement; + final converterClassElement = constantValue.type.element as ClassElement; - var jsonConverterSuper = converterClassElement.allSupertypes.singleWhere( + final jsonConverterSuper = converterClassElement.allSupertypes.singleWhere( (e) => e is InterfaceType && _jsonConverterChecker.isExactly(e.element), orElse: () => null); @@ -149,7 +149,7 @@ _ConverterMatch _compatibleMatch( assert(jsonConverterSuper.typeParameters.length == 2); assert(jsonConverterSuper.typeArguments.length == 2); - var fieldType = jsonConverterSuper.typeArguments[0]; + final fieldType = jsonConverterSuper.typeArguments[0]; if (fieldType.isEquivalentTo(targetType)) { return _ConverterMatch( diff --git a/json_serializable/lib/src/type_helpers/json_helper.dart b/json_serializable/lib/src/type_helpers/json_helper.dart index 2cd349372..9a8ee3577 100644 --- a/json_serializable/lib/src/type_helpers/json_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_helper.dart @@ -39,16 +39,16 @@ class JsonHelper extends TypeHelper { return null; } - var type = targetType as InterfaceType; - var classElement = type.element; + final type = targetType as InterfaceType; + final classElement = type.element; - var fromJsonCtor = classElement.constructors + final fromJsonCtor = classElement.constructors .singleWhere((ce) => ce.name == 'fromJson', orElse: () => null); String asCast; if (fromJsonCtor != null) { // TODO: should verify that this type is a valid JSON type - var asCastType = fromJsonCtor.parameters.first.type; + final asCastType = fromJsonCtor.parameters.first.type; asCast = asStatement(asCastType); } else if (_annotation(type)?.createFactory == true) { if (context.anyMap) { @@ -62,7 +62,7 @@ class JsonHelper extends TypeHelper { // TODO: the type could be imported from a library with a prefix! // github.com/dart-lang/json_serializable/issues/19 - var result = '${targetType.name}.fromJson($expression$asCast)'; + final result = '${targetType.name}.fromJson($expression$asCast)'; return commonNullPrefix(context.nullable, expression, result); } @@ -70,7 +70,7 @@ class JsonHelper extends TypeHelper { bool _canSerialize(DartType type) { if (type is InterfaceType) { - var toJsonMethod = _toJsonMethod(type); + final toJsonMethod = _toJsonMethod(type); if (toJsonMethod != null) { // TODO: validate there are no required parameters @@ -87,7 +87,7 @@ bool _canSerialize(DartType type) { } JsonSerializable _annotation(InterfaceType source) { - var annotations = const TypeChecker.fromRuntime(JsonSerializable) + final annotations = const TypeChecker.fromRuntime(JsonSerializable) .annotationsOfExact(source.element, throwOnUnresolved: false) .toList(); diff --git a/json_serializable/lib/src/type_helpers/map_helper.dart b/json_serializable/lib/src/type_helpers/map_helper.dart index 4b4f4cda5..fc37a0eed 100644 --- a/json_serializable/lib/src/type_helpers/map_helper.dart +++ b/json_serializable/lib/src/type_helpers/map_helper.dart @@ -20,16 +20,16 @@ class MapHelper extends TypeHelper { if (!coreMapTypeChecker.isAssignableFromType(targetType)) { return null; } - var args = typeArgumentsOf(targetType, coreMapTypeChecker); + final args = typeArgumentsOf(targetType, coreMapTypeChecker); assert(args.length == 2); - var keyType = args[0]; - var valueType = args[1]; + final keyType = args[0]; + final valueType = args[1]; _checkSafeKeyType(expression, keyType); - var subFieldValue = context.serialize(valueType, closureArg); - var subKeyValue = context.serialize(keyType, _keyParam); + final subFieldValue = context.serialize(valueType, closureArg); + final subKeyValue = context.serialize(keyType, _keyParam); if (closureArg == subFieldValue && _keyParam == subKeyValue) { return expression; @@ -41,7 +41,7 @@ class MapHelper extends TypeHelper { method = '${method}HandleNull'; } - var lambda = LambdaResult.process(subFieldValue, closureArg); + final lambda = LambdaResult.process(subFieldValue, closureArg); return '$method<$keyType, $valueType>($expression, $lambda)'; } @@ -58,10 +58,10 @@ class MapHelper extends TypeHelper { return null; } - var typeArgs = typeArgumentsOf(targetType, coreMapTypeChecker); + final typeArgs = typeArgumentsOf(targetType, coreMapTypeChecker); assert(typeArgs.length == 2); - var keyArg = typeArgs.first; - var valueArg = typeArgs.last; + final keyArg = typeArgs.first; + final valueArg = typeArgs.last; _checkSafeKeyType(expression, keyArg); @@ -117,7 +117,7 @@ bool _isObjectOrDynamic(DartType type) => type.isObject || type.isDynamic; void _checkSafeKeyType(String expression, DartType keyArg) { // We're not going to handle converting key types at the moment // So the only safe types for key are dynamic/Object/String/enum - var safeKey = _isObjectOrDynamic(keyArg) || + final safeKey = _isObjectOrDynamic(keyArg) || coreStringTypeChecker.isExactlyType(keyArg) || isEnum(keyArg); diff --git a/json_serializable/lib/src/type_helpers/uri_helper.dart b/json_serializable/lib/src/type_helpers/uri_helper.dart index b865bacf1..bec376f50 100644 --- a/json_serializable/lib/src/type_helpers/uri_helper.dart +++ b/json_serializable/lib/src/type_helpers/uri_helper.dart @@ -16,7 +16,7 @@ class UriHelper extends TypeHelper { return null; } - var buffer = StringBuffer(expression); + final buffer = StringBuffer(expression); if (context.nullable) { buffer.write('?'); diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index fd1a0a4bb..475e0ffd7 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -60,16 +60,16 @@ final _enumMapExpando = Expando>(); /// If [targetType] is not an enum, `null` is returned. Map enumFieldsMap(DartType targetType) { MapEntry _generateEntry(FieldElement fe) { - var annotation = + final annotation = const TypeChecker.fromRuntime(JsonValue).firstAnnotationOfExact(fe); dynamic fieldValue; if (annotation == null) { fieldValue = fe.name; } else { - var reader = ConstantReader(annotation); + final reader = ConstantReader(annotation); - var valueReader = reader.read('value'); + final valueReader = reader.read('value'); if (valueReader.isString || valueReader.isNull || valueReader.isInt) { fieldValue = valueReader.literalValue; @@ -81,7 +81,7 @@ Map enumFieldsMap(DartType targetType) { } } - var entry = MapEntry(fe, fieldValue); + final entry = MapEntry(fe, fieldValue); return entry; } @@ -111,7 +111,7 @@ String escapeDartString(String value) { var canBeRaw = true; value = value.replaceAllMapped(_escapeRegExp, (match) { - var value = match[0]; + final value = match[0]; if (value == "'") { hasSingleQuote = true; return value; @@ -153,7 +153,7 @@ String escapeDartString(String value) { // The only safe way to wrap the content is to escape all of the // problematic characters - `$`, `'`, and `"` - var string = value.replaceAll(_dollarQuoteRegexp, r'\'); + final string = value.replaceAll(_dollarQuoteRegexp, r'\'); return "'$string'"; } @@ -179,7 +179,7 @@ final _escapeRegExp = RegExp('[\$\'"\\x00-\\x07\\x0E-\\x1F$_escapeMapRegexp]'); /// Given single-character string, return the hex-escaped equivalent. String _getHexLiteral(String input) { - var rune = input.runes.single; - var value = rune.toRadixString(16).toUpperCase().padLeft(2, '0'); + final rune = input.runes.single; + final value = rune.toRadixString(16).toUpperCase().padLeft(2, '0'); return '\\x$value'; } diff --git a/json_serializable/test/analysis_utils.dart b/json_serializable/test/analysis_utils.dart index 2d0a62609..ebfee1c38 100644 --- a/json_serializable/test/analysis_utils.dart +++ b/json_serializable/test/analysis_utils.dart @@ -11,16 +11,17 @@ import 'package:path/path.dart' as p; import 'package:source_gen/source_gen.dart'; Future resolveCompilationUnit(String sourceDirectory) async { - var files = Directory(sourceDirectory).listSync().whereType().toList(); + final files = + Directory(sourceDirectory).listSync().whereType().toList(); // Sort files to ensure the "first" one is first files.sort((a, b) => p.basename(a.path).compareTo(p.basename(b.path))); - var fileMap = Map.fromEntries(files.map( + final fileMap = Map.fromEntries(files.map( (f) => MapEntry('a|lib/${p.basename(f.path)}', f.readAsStringSync()))); - var library = await resolveSources(fileMap, (item) async { - var assetId = AssetId.parse(fileMap.keys.first); + final library = await resolveSources(fileMap, (item) async { + final assetId = AssetId.parse(fileMap.keys.first); return await item.libraryFor(assetId); }); diff --git a/json_serializable/test/config_test.dart b/json_serializable/test/config_test.dart index aef9e01c4..3ff3f8cf1 100644 --- a/json_serializable/test/config_test.dart +++ b/json_serializable/test/config_test.dart @@ -30,20 +30,20 @@ void main() { setUp(records.clear); test('empty', () async { - var builder = jsonSerializable(BuilderOptions.empty); + final builder = jsonSerializable(BuilderOptions.empty); expect(builder, isNotNull); expect(records, isEmpty); }); test('valid config', () async { - var builder = jsonSerializable(const BuilderOptions(_validConfig)); + final builder = jsonSerializable(const BuilderOptions(_validConfig)); expect(builder, isNotNull); expect(records, isEmpty); }); test('readme config', () async { - var configExampleContent = File('README.md') + final configExampleContent = File('README.md') .readAsLinesSync() .skipWhile((line) => line != '```yaml') .skip(1) @@ -52,7 +52,7 @@ void main() { var yaml = loadYaml(configExampleContent) as YamlMap; - for (var key in [ + for (final key in [ 'targets', r'$default', 'builders', @@ -62,17 +62,17 @@ void main() { yaml = yaml[key] as YamlMap; } - var config = Map.from(yaml); + final config = Map.from(yaml); expect(config.keys, unorderedEquals(_validConfig.keys)); - var builder = jsonSerializable(BuilderOptions(config)); + final builder = jsonSerializable(BuilderOptions(config)); expect(builder, isNotNull); expect(records, isEmpty); }); test('unsupported configuration', () async { - var builder = + final builder = jsonSerializable(const BuilderOptions({'unsupported': 'config'})); expect(builder, isNotNull); @@ -81,9 +81,9 @@ void main() { }); group('invalid config', () { - for (var entry in _invalidConfig.entries) { + for (final entry in _invalidConfig.entries) { test(entry.key, () { - var config = Map.from(_validConfig); + final config = Map.from(_validConfig); config[entry.key] = entry.value; expect(() => jsonSerializable(BuilderOptions(config)), throwsCastError); diff --git a/json_serializable/test/default_value/default_value.checked.g.dart b/json_serializable/test/default_value/default_value.checked.g.dart index 3b906f911..ba5d62143 100644 --- a/json_serializable/test/default_value/default_value.checked.g.dart +++ b/json_serializable/test/default_value/default_value.checked.g.dart @@ -8,7 +8,7 @@ part of 'default_value.checked.dart'; DefaultValue _$DefaultValueFromJson(Map json) { return $checkedNew('DefaultValue', json, () { - var val = DefaultValue(); + final val = DefaultValue(); $checkedConvert( json, 'fieldBool', (v) => val.fieldBool = v as bool ?? true); $checkedConvert( @@ -49,7 +49,7 @@ DefaultValue _$DefaultValueFromJson(Map json) { } Map _$DefaultValueToJson(DefaultValue instance) { - var val = { + final val = { 'fieldBool': instance.fieldBool, }; diff --git a/json_serializable/test/default_value/default_value.g.dart b/json_serializable/test/default_value/default_value.g.dart index 625fcaada..1d29b97fa 100644 --- a/json_serializable/test/default_value/default_value.g.dart +++ b/json_serializable/test/default_value/default_value.g.dart @@ -31,7 +31,7 @@ DefaultValue _$DefaultValueFromJson(Map json) { } Map _$DefaultValueToJson(DefaultValue instance) { - var val = { + final val = { 'fieldBool': instance.fieldBool, }; diff --git a/json_serializable/test/default_value/default_value_test.dart b/json_serializable/test/default_value/default_value_test.dart index baa1455e6..1a3641b82 100644 --- a/json_serializable/test/default_value/default_value_test.dart +++ b/json_serializable/test/default_value/default_value_test.dart @@ -46,15 +46,15 @@ void main() { void _test(DefaultValue fromJson(Map json)) { test('empty map yields all default values', () { - var object = fromJson({}); + final object = fromJson({}); expect(loudEncode(object), loudEncode(_defaultInstance)); }); test('default value input round-trips', () { - var object = fromJson(_defaultInstance); + final object = fromJson(_defaultInstance); expect(loudEncode(object), loudEncode(_defaultInstance)); }); test('non-default values round-trip', () { - var object = fromJson(_otherValues); + final object = fromJson(_otherValues); expect(loudEncode(object), loudEncode(_otherValues)); }); } diff --git a/json_serializable/test/enum_helper_test.dart b/json_serializable/test/enum_helper_test.dart index 187803519..8043543b7 100644 --- a/json_serializable/test/enum_helper_test.dart +++ b/json_serializable/test/enum_helper_test.dart @@ -10,7 +10,7 @@ import 'package:json_serializable/src/type_helpers/enum_helper.dart'; void main() { group('expression test', () { group('simple', () { - for (var expression in [ + for (final expression in [ 'hello', 'HELLO', 'hi_to', @@ -24,7 +24,7 @@ void main() { }); group('not simple', () { - for (var expression in ['nice[thing]', 'a.b']) { + for (final expression in ['nice[thing]', 'a.b']) { test(expression, () { expect(simpleExpression.hasMatch(expression), isFalse); }); diff --git a/json_serializable/test/generic_files/generic_test.dart b/json_serializable/test/generic_files/generic_test.dart index 0184d4c6f..d4f6d1f4c 100644 --- a/json_serializable/test/generic_files/generic_test.dart +++ b/json_serializable/test/generic_files/generic_test.dart @@ -12,10 +12,10 @@ void main() { group('generic', () { GenericClass roundTripGenericClass( GenericClass p) { - var outputJson = loudEncode(p); - var p2 = GenericClass.fromJson( + final outputJson = loudEncode(p); + final p2 = GenericClass.fromJson( jsonDecode(outputJson) as Map); - var outputJson2 = loudEncode(p2); + final outputJson2 = loudEncode(p2); expect(outputJson2, outputJson); return p2; } diff --git a/json_serializable/test/integration/integration_test.dart b/json_serializable/test/integration/integration_test.dart index 8f0179d42..2c43e0eb1 100644 --- a/json_serializable/test/integration/integration_test.dart +++ b/json_serializable/test/integration/integration_test.dart @@ -37,13 +37,13 @@ void main() { }); test('empty json', () { - var person = Person.fromJson({}); + final person = Person.fromJson({}); expect(person.dateOfBirth, isNull); roundTripPerson(person); }); test('enum map', () { - var person = Person(null, null, null) + final person = Person(null, null, null) ..houseMap = {'bob': Category.strange} ..categoryCounts = {Category.strange: 1}; expect(person.dateOfBirth, isNull); @@ -79,7 +79,7 @@ void main() { }); test('almost empty json', () { - var order = Order.fromJson({'category': 'not_discovered_yet'}); + final order = Order.fromJson({'category': 'not_discovered_yet'}); expect(order.items, isEmpty); expect(order.category, Category.notDiscoveredYet); expect(order.statusCode, StatusCode.success); @@ -101,7 +101,7 @@ void main() { }); test('platform', () { - var order = Order(Category.charmed) + final order = Order(Category.charmed) ..statusCode = StatusCode.success ..platform = Platform.undefined ..altPlatforms = { @@ -114,7 +114,7 @@ void main() { }); test('homepage', () { - var order = Order(Category.charmed) + final order = Order(Category.charmed) ..platform = Platform.undefined ..statusCode = StatusCode.success ..altPlatforms = { @@ -128,7 +128,7 @@ void main() { }); test('statusCode', () { - var order = Order.fromJson( + final order = Order.fromJson( {'category': 'not_discovered_yet', 'status_code': 404}); expect(order.statusCode, StatusCode.notFound); roundTripOrder(order); @@ -174,7 +174,7 @@ void main() { } test('empty json', () { - var item = Item.fromJson({}); + final item = Item.fromJson({}); expect(item.saleDates, isNull); roundTripItem(item); @@ -183,7 +183,7 @@ void main() { }); test('set itemNumber - with custom JSON key', () { - var item = Item.fromJson({'item-number': 42}); + final item = Item.fromJson({'item-number': 42}); expect(item.itemNumber, 42); roundTripItem(item); @@ -209,13 +209,14 @@ void main() { }); test('custom DateTime', () { - var instance = Numbers()..date = DateTime.fromMillisecondsSinceEpoch(42); - var json = instance.toJson(); + final instance = Numbers() + ..date = DateTime.fromMillisecondsSinceEpoch(42); + final json = instance.toJson(); expect(json, containsPair('date', 42000)); }); test('support ints as doubles', () { - var value = { + final value = { 'doubles': [0, 0.0, null], 'nnDoubles': [0, 0.0] }; @@ -224,7 +225,7 @@ void main() { }); test('does not support doubles as ints', () { - var value = { + final value = { 'ints': [3.14, 0], }; diff --git a/json_serializable/test/integration/json_test_example.g.dart b/json_serializable/test/integration/json_test_example.g.dart index d227688a7..88617e7b5 100644 --- a/json_serializable/test/integration/json_test_example.g.dart +++ b/json_serializable/test/integration/json_test_example.g.dart @@ -91,7 +91,7 @@ Order _$OrderFromJson(Map json) { } Map _$OrderToJson(Order instance) { - var val = {}; + final val = {}; void writeNotNull(String key, dynamic value) { if (value != null) { @@ -126,7 +126,7 @@ Item _$ItemFromJson(Map json) { } Map _$ItemToJson(Item instance) { - var val = { + final val = { 'price': instance.price, }; diff --git a/json_serializable/test/json_serializable_test.dart b/json_serializable/test/json_serializable_test.dart index 06474dee2..369ba42a8 100644 --- a/json_serializable/test/json_serializable_test.dart +++ b/json_serializable/test/json_serializable_test.dart @@ -19,7 +19,7 @@ Matcher _matcherFromShouldGenerateAnnotation(ConstantReader reader, {bool wrapped = false}) { String expectedOutput; if (wrapped) { - var expectedWrappedOutput = reader.read('expectedWrappedOutput'); + final expectedWrappedOutput = reader.read('expectedWrappedOutput'); if (expectedWrappedOutput.isNull) { return null; } @@ -28,7 +28,7 @@ Matcher _matcherFromShouldGenerateAnnotation(ConstantReader reader, expectedOutput = reader.read('expectedOutput').stringValue; } - var isContains = reader.read('contains').boolValue; + final isContains = reader.read('contains').boolValue; if (isContains) { return contains(expectedOutput); @@ -128,7 +128,7 @@ const _expectedAnnotatedTests = { }; void main() async { - var path = testFilePath('test', 'src'); + final path = testFilePath('test', 'src'); _library = await resolveCompilationUnit(path); StreamSubscription logSubscription; @@ -145,7 +145,7 @@ void main() async { logSubscription = null; } - var remainingItems = _buildLogItems.toList(); + final remainingItems = _buildLogItems.toList(); _buildLogItems.clear(); expect(remainingItems, isEmpty, reason: @@ -158,14 +158,14 @@ void main() async { expect(_annotatedElements.keys, _expectedAnnotatedTests.keys); }); - for (var entry in _annotatedElements.entries) { + for (final entry in _annotatedElements.entries) { group(entry.key, () { test('[all expected classes]', () { expect(_expectedAnnotatedTests, containsPair(entry.key, entry.value.map((ae) => ae.element.name))); }); - for (var annotatedElement in entry.value) { + for (final annotatedElement in entry.value) { _testAnnotatedClass(annotatedElement); } }); @@ -179,7 +179,7 @@ void main() async { } void _testAnnotatedClass(AnnotatedElement annotatedElement) { - var annotationName = annotatedElement.annotation.objectValue.type.name; + final annotationName = annotatedElement.annotation.objectValue.type.name; switch (annotationName) { case 'ShouldThrow': _testShouldThrow(annotatedElement); @@ -193,9 +193,9 @@ void _testAnnotatedClass(AnnotatedElement annotatedElement) { } void _testShouldThrow(AnnotatedElement annotatedElement) { - var element = annotatedElement.element; - var constReader = annotatedElement.annotation; - var messageMatcher = constReader.read('errorMessage').stringValue; + final element = annotatedElement.element; + final constReader = annotatedElement.annotation; + final messageMatcher = constReader.read('errorMessage').stringValue; var todoMatcher = constReader.read('todo').literalValue; test(element.name, () { @@ -216,21 +216,21 @@ void _testShouldThrow(AnnotatedElement annotatedElement) { } void _testShouldGenerate(AnnotatedElement annotatedElement) { - var element = annotatedElement.element; + final element = annotatedElement.element; - var matcher = + final matcher = _matcherFromShouldGenerateAnnotation(annotatedElement.annotation); - var expectedLogItems = annotatedElement.annotation + final expectedLogItems = annotatedElement.annotation .read('expectedLogItems') .listValue .map((obj) => obj.toStringValue()) .toList(); - var checked = annotatedElement.annotation.read('checked').boolValue; + final checked = annotatedElement.annotation.read('checked').boolValue; test(element.name, () { - var output = _runForElementNamed( + final output = _runForElementNamed( JsonSerializableGenerator(checked: checked), element.name); expect(output, matcher); @@ -238,12 +238,12 @@ void _testShouldGenerate(AnnotatedElement annotatedElement) { _buildLogItems.clear(); }); - var wrappedMatcher = _matcherFromShouldGenerateAnnotation( + final wrappedMatcher = _matcherFromShouldGenerateAnnotation( annotatedElement.annotation, wrapped: true); if (wrappedMatcher != null) { test('${element.name} - (wrapped)', () { - var output = _runForElementNamed( + final output = _runForElementNamed( JsonSerializableGenerator(checked: checked, useWrappers: true), element.name); expect(output, wrappedMatcher); @@ -255,24 +255,24 @@ void _testShouldGenerate(AnnotatedElement annotatedElement) { } String _runForElementNamed(JsonSerializableGenerator generator, String name) { - var element = _library.allElements.singleWhere((e) => e.name == name); - var annotation = generator.typeChecker.firstAnnotationOf(element); - var generated = generator + final element = _library.allElements.singleWhere((e) => e.name == name); + final annotation = generator.typeChecker.firstAnnotationOf(element); + final generated = generator .generateForAnnotatedElement(element, ConstantReader(annotation), null) .map((e) => e.trim()) .where((e) => e.isNotEmpty) .map((e) => '$e\n\n') .join(); - var output = _formatter.format(generated); + final output = _formatter.format(generated); printOnFailure("r'''\n$output'''"); return output; } final _annotatedElements = _library.allElements .map((e) { - for (var md in e.metadata) { - var reader = ConstantReader(md.constantValue); + for (final md in e.metadata) { + final reader = ConstantReader(md.constantValue); if (const ['ShouldGenerate', 'ShouldThrow'] .contains(reader.objectValue.type.name)) { return AnnotatedElement(reader, e); @@ -283,7 +283,7 @@ final _annotatedElements = _library.allElements .where((ae) => ae != null) .fold>>( >{}, (map, annotatedElement) { - var list = map.putIfAbsent( + final list = map.putIfAbsent( annotatedElement.element.source.uri.pathSegments.last, () => []); list.add(annotatedElement); @@ -302,12 +302,12 @@ void _registerTests(JsonSerializableGenerator generator) { group('explicit toJson', () { test('nullable', () { - var output = _runForElementNamed( + final output = _runForElementNamed( JsonSerializableGenerator( explicitToJson: true, useWrappers: generator.useWrappers), 'TrivialNestedNullable'); - var expected = generator.useWrappers + final expected = generator.useWrappers ? r''' Map _$TrivialNestedNullableToJson( TrivialNestedNullable instance) => @@ -346,12 +346,12 @@ Map _$TrivialNestedNullableToJson( expect(output, expected); }); test('non-nullable', () { - var output = _runForElementNamed( + final output = _runForElementNamed( JsonSerializableGenerator( explicitToJson: true, useWrappers: generator.useWrappers), 'TrivialNestedNonNullable'); - var expected = generator.useWrappers + final expected = generator.useWrappers ? r''' Map _$TrivialNestedNonNullableToJson( TrivialNestedNonNullable instance) => @@ -408,8 +408,8 @@ Map _$TrivialNestedNonNullableToJson( 'in the associated `@JsonKey` annotation.'; group('fromJson', () { - var msg = flavorMessage('fromJson'); - var todo = flavorTodo('fromJson'); + final msg = flavorMessage('fromJson'); + final todo = flavorTodo('fromJson'); test('in constructor arguments', () { expectThrows('UnknownCtorParamType', msg, todo); }); @@ -427,7 +427,7 @@ Map _$TrivialNestedNonNullableToJson( }); test('with proper convert methods', () { - var output = runForElementNamed('UnknownFieldTypeWithConvert'); + final output = runForElementNamed('UnknownFieldTypeWithConvert'); expect(output, contains("_everythingIs42(json['number'])")); if (generator.useWrappers) { expect(output, contains('_everythingIs42(_v.number)')); @@ -471,7 +471,7 @@ Map _$TrivialNestedNonNullableToJson( }); test('class with final fields', () { - var generateResult = runForElementNamed('FinalFields'); + final generateResult = runForElementNamed('FinalFields'); expect( generateResult, contains( @@ -480,13 +480,13 @@ Map _$TrivialNestedNonNullableToJson( group('valid inputs', () { test('class with fromJson() constructor with optional parameters', () { - var output = runForElementNamed('FromJsonOptionalParameters'); + final output = runForElementNamed('FromJsonOptionalParameters'); expect(output, contains('ChildWithFromJson.fromJson')); }); test('class with child json-able object', () { - var output = runForElementNamed('ParentObject'); + final output = runForElementNamed('ParentObject'); expect( output, @@ -495,7 +495,7 @@ Map _$TrivialNestedNonNullableToJson( }); test('class with child json-able object - anyMap', () { - var output = _runForElementNamed( + final output = _runForElementNamed( JsonSerializableGenerator( anyMap: true, useWrappers: generator.useWrappers), 'ParentObject'); @@ -504,20 +504,20 @@ Map _$TrivialNestedNonNullableToJson( }); test('class with child list of json-able objects', () { - var output = runForElementNamed('ParentObjectWithChildren'); + final output = runForElementNamed('ParentObjectWithChildren'); expect(output, contains('.toList()')); expect(output, contains('ChildObject.fromJson')); }); test('class with child list of dynamic objects is left alone', () { - var output = runForElementNamed('ParentObjectWithDynamicChildren'); + final output = runForElementNamed('ParentObjectWithDynamicChildren'); expect(output, contains('children = json[\'children\'] as List;')); }); test('class with list of int is cast for strong mode', () { - var output = runForElementNamed('Person'); + final output = runForElementNamed('Person'); expect(output, contains("json['listOfInts'] as List)?.map((e) => e as int)")); @@ -526,7 +526,7 @@ Map _$TrivialNestedNonNullableToJson( group('includeIfNull', () { test('some', () { - var output = runForElementNamed('IncludeIfNullAll'); + final output = runForElementNamed('IncludeIfNullAll'); expect(output, isNot(contains(generatedLocalVarName))); expect(output, isNot(contains(toJsonMapHelperName))); }); diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g.dart index 18be9a9b1..43f19ed37 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g.dart @@ -83,7 +83,7 @@ abstract class _$KitchenSinkSerializerMixin { StrictKeysObject get strictKeysObject; int get validatedPropertyNo42; Map toJson() { - var val = { + final val = { 'no-42': ctorValidatedNo42, }; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.checked.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.checked.g.dart index 9bcc96368..ed10e11f1 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.checked.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.checked.g.dart @@ -8,7 +8,7 @@ part of 'kitchen_sink.non_nullable.checked.dart'; KitchenSink _$KitchenSinkFromJson(Map json) { return $checkedNew('KitchenSink', json, () { - var val = KitchenSink( + final val = KitchenSink( ctorValidatedNo42: $checkedConvert(json, 'no-42', (v) => v as int), iterable: $checkedConvert(json, 'iterable', (v) => v as List), dynamicIterable: @@ -159,7 +159,7 @@ abstract class _$KitchenSinkSerializerMixin { JsonConverterTestClass _$JsonConverterTestClassFromJson(Map json) { return $checkedNew('JsonConverterTestClass', json, () { - var val = JsonConverterTestClass(); + final val = JsonConverterTestClass(); $checkedConvert(json, 'duration', (v) => val.duration = durationConverter.fromJson(v as int)); $checkedConvert( @@ -222,7 +222,7 @@ abstract class _$JsonConverterTestClassSerializerMixin { JsonConverterGeneric _$JsonConverterGenericFromJson( Map json) { return $checkedNew('JsonConverterGeneric', json, () { - var val = JsonConverterGeneric(); + final val = JsonConverterGeneric(); $checkedConvert( json, 'item', diff --git a/json_serializable/test/kitchen_sink/kitchen_sink_test.dart b/json_serializable/test/kitchen_sink/kitchen_sink_test.dart index 7fb632b03..3ec047863 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink_test.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink_test.dart @@ -102,23 +102,23 @@ void _nullableTests(KitchenSinkCtor ctor, KitchenSink fromJson(Map json)) { } test('Fields with `!includeIfNull` should not be included when null', () { - var item = ctor(); + final item = ctor(); - var expectedDefaultKeys = _validValues.keys.toSet() + final expectedDefaultKeys = _validValues.keys.toSet() ..removeAll(_excludeIfNullKeys); - var encoded = item.toJson(); + final encoded = item.toJson(); expect(encoded.keys, orderedEquals(expectedDefaultKeys)); - for (var key in expectedDefaultKeys) { + for (final key in expectedDefaultKeys) { expect(encoded, containsPair(key, isNull)); } }); test('list and map of DateTime', () { - var now = DateTime.now(); - var item = ctor(dateTimeIterable: [now]) + final now = DateTime.now(); + final item = ctor(dateTimeIterable: [now]) ..dateTimeList = [now, null] ..objectDateTimeMap = {'value': now, 'null': null}; @@ -126,7 +126,7 @@ void _nullableTests(KitchenSinkCtor ctor, KitchenSink fromJson(Map json)) { }); test('complex nested type', () { - var item = ctor() + final item = ctor() ..crazyComplex = [ null, {}, @@ -157,13 +157,13 @@ void _sharedTests(KitchenSinkCtor ctor, KitchenSink fromJson(Map json), } test('empty', () { - var item = ctor(); + final item = ctor(); roundTripSink(item); }); test('list and map of DateTime - not null', () { - var now = DateTime.now(); - var item = ctor(dateTimeIterable: [now]) + final now = DateTime.now(); + final item = ctor(dateTimeIterable: [now]) ..dateTimeList = [now, now] ..objectDateTimeMap = {'value': now}; @@ -171,7 +171,7 @@ void _sharedTests(KitchenSinkCtor ctor, KitchenSink fromJson(Map json), }); test('complex nested type - not null', () { - var item = ctor() + final item = ctor() ..crazyComplex = [ {}, { @@ -191,13 +191,13 @@ void _sharedTests(KitchenSinkCtor ctor, KitchenSink fromJson(Map json), test('JSON keys should be defined in field/property order', () { /// Explicitly setting values from [_excludeIfNullKeys] to ensure /// they exist for KitchenSink where they are excluded when null - var item = ctor(iterable: []) + final item = ctor(iterable: []) ..dateTime = DateTime.now() ..dateTimeList = [] ..crazyComplex = [] ..val = {}; - var json = item.toJson(); + final json = item.toJson(); expect(json.keys, orderedEquals(_validValues.keys)); }); @@ -206,16 +206,16 @@ void _sharedTests(KitchenSinkCtor ctor, KitchenSink fromJson(Map json), }); test('valid values round-trip - yaml', () { - var jsonEncoded = loudEncode(_validValues); - var yaml = loadYaml(jsonEncoded, sourceUrl: 'input.yaml'); + final jsonEncoded = loudEncode(_validValues); + final yaml = loadYaml(jsonEncoded, sourceUrl: 'input.yaml'); expect(jsonEncoded, loudEncode(fromJson(yaml as YamlMap))); }); group('a bad value for', () { - for (var e in _invalidValueTypes.entries) { + for (final e in _invalidValueTypes.entries) { _testBadValue(isChecked, e.key, e.value, fromJson, false); } - for (var e in _invalidCheckedValues.entries) { + for (final e in _invalidCheckedValues.entries) { _testBadValue(isChecked, e.key, e.value, fromJson, true); } }); @@ -225,7 +225,7 @@ void _testBadValue(bool isChecked, String key, Object badValue, KitchenSink fromJson(Map json), bool checkedAssignment) { final matcher = _getMatcher(isChecked, key, checkedAssignment); - for (var isJson in [true, false]) { + for (final isJson in [true, false]) { test('`$key` fails with value `$badValue`- ${isJson ? 'json' : 'yaml'}', () { var copy = Map.from(_validValues); diff --git a/json_serializable/test/literal/json_literal_test.dart b/json_serializable/test/literal/json_literal_test.dart index 399cbfd23..140aba3dc 100644 --- a/json_serializable/test/literal/json_literal_test.dart +++ b/json_serializable/test/literal/json_literal_test.dart @@ -15,25 +15,25 @@ import 'json_literal.dart'; void main() { test('literal round-trip', () { - var dataFilePath = testFilePath('test', 'literal', 'json_literal.json'); - var dataFile = File(dataFilePath); + final dataFilePath = testFilePath('test', 'literal', 'json_literal.json'); + final dataFile = File(dataFilePath); - var dataString = loudEncode(json.decode(dataFile.readAsStringSync())); + final dataString = loudEncode(json.decode(dataFile.readAsStringSync())); // FYI: nice to re-write the test data when it's changed to keep it pretty // ... but not a good idea to ship this // dataFile.writeAsStringSync(dataString.replaceAll('\u007F', '\\u007F')); - var dartString = loudEncode(data); + final dartString = loudEncode(data); expect(dartString, dataString); }); test('naughty strings', () { - var dataFilePath = + final dataFilePath = testFilePath('test', 'literal', 'big-list-of-naughty-strings.json'); - var dataFile = File(dataFilePath); + final dataFile = File(dataFilePath); - var dataString = loudEncode(json.decode(dataFile.readAsStringSync())); - var dartString = loudEncode(naughtyStrings); + final dataString = loudEncode(json.decode(dataFile.readAsStringSync())); + final dartString = loudEncode(naughtyStrings); expect(dartString, dataString); }); diff --git a/json_serializable/test/readme_test.dart b/json_serializable/test/readme_test.dart index 8556c1762..5ca6bf84d 100644 --- a/json_serializable/test/readme_test.dart +++ b/json_serializable/test/readme_test.dart @@ -11,24 +11,24 @@ import 'package:path/path.dart' as p; void main() { test('README example', () { - var readmeContent = File('README.md').readAsStringSync(); + final readmeContent = File('README.md').readAsStringSync(); - var exampleContent = _getExampleContent('example.dart'); + final exampleContent = _getExampleContent('example.dart'); expect(readmeContent, contains(exampleContent)); - var exampleGeneratedContent = _getExampleContent('example.g.dart'); + final exampleGeneratedContent = _getExampleContent('example.g.dart'); expect(readmeContent, contains(exampleGeneratedContent)); }); } String _getExampleContent(String fileName) { - var lines = File(p.join('example', fileName)).readAsLinesSync(); + final lines = File(p.join('example', fileName)).readAsLinesSync(); var lastHadContent = false; // All lines with content, except those starting with `/`. // Also exclude blank lines that follow other blank lines - var cleanedSource = lines.where((l) { + final cleanedSource = lines.where((l) { if (l.startsWith(r'/')) { return false; } diff --git a/json_serializable/test/src/_json_serializable_test_input.dart b/json_serializable/test/src/_json_serializable_test_input.dart index 6a545a035..0707aff73 100644 --- a/json_serializable/test/src/_json_serializable_test_input.dart +++ b/json_serializable/test/src/_json_serializable_test_input.dart @@ -233,7 +233,7 @@ class IncludeIfNullAll { @ShouldGenerate(r''' Map _$IncludeIfNullOverrideToJson( IncludeIfNullOverride instance) { - var val = { + final val = { 'number': instance.number, }; diff --git a/json_serializable/test/src/checked_test_input.dart b/json_serializable/test/src/checked_test_input.dart index 7bcc562c9..c83935f88 100644 --- a/json_serializable/test/src/checked_test_input.dart +++ b/json_serializable/test/src/checked_test_input.dart @@ -8,7 +8,7 @@ WithANonCtorGetterChecked _$WithANonCtorGetterCheckedFromJson( allowedKeys: const ['items'], requiredKeys: const ['items'], disallowNullValues: const ['items']); - var val = WithANonCtorGetterChecked($checkedConvert( + final val = WithANonCtorGetterChecked($checkedConvert( json, 'items', (v) => (v as List)?.map((e) => e as String)?.toList())); return val; }); diff --git a/json_serializable/test/src/inheritance_test_input.dart b/json_serializable/test/src/inheritance_test_input.dart index 0df975237..0507d7e18 100644 --- a/json_serializable/test/src/inheritance_test_input.dart +++ b/json_serializable/test/src/inheritance_test_input.dart @@ -9,7 +9,7 @@ SubType _$SubTypeFromJson(Map json) { } Map _$SubTypeToJson(SubType instance) { - var val = { + final val = { 'super-final-field': instance.superFinalField, }; @@ -98,7 +98,7 @@ class SuperType { @ShouldGenerate(r''' Map _$SubTypeWithAnnotatedFieldOverrideExtendsToJson( SubTypeWithAnnotatedFieldOverrideExtends instance) { - var val = { + final val = { 'super-final-field': instance.superFinalField, }; diff --git a/json_serializable/test/test_file_utils.dart b/json_serializable/test/test_file_utils.dart index 90cf0cefa..f15fcf456 100644 --- a/json_serializable/test/test_file_utils.dart +++ b/json_serializable/test/test_file_utils.dart @@ -14,7 +14,7 @@ String _packagePathCache; String _packagePath() { if (_packagePathCache == null) { // Getting the location of this file – via reflection - var currentFilePath = (reflect(_packagePath) as ClosureMirror) + final currentFilePath = (reflect(_packagePath) as ClosureMirror) .function .location .sourceUri diff --git a/json_serializable/test/test_utils.dart b/json_serializable/test/test_utils.dart index 0ba2e2ea1..4412f0298 100644 --- a/json_serializable/test/test_utils.dart +++ b/json_serializable/test/test_utils.dart @@ -10,13 +10,13 @@ final isCastError = const TypeMatcher(); final throwsCastError = throwsA(isCastError); T roundTripObject(T object, T factory(Map json)) { - var data = loudEncode(object); + final data = loudEncode(object); - var object2 = factory(json.decode(data) as Map); + final object2 = factory(json.decode(data) as Map); expect(object2, equals(object)); - var json2 = loudEncode(object2); + final json2 = loudEncode(object2); expect(json2, equals(data)); return object2; @@ -29,7 +29,7 @@ String loudEncode(Object object) { } on JsonUnsupportedObjectError catch (e) { var error = e; do { - var cause = error.cause; + final cause = error.cause; print(cause); error = (cause is JsonUnsupportedObjectError) ? cause : null; } while (error != null); diff --git a/json_serializable/test/utils_test.dart b/json_serializable/test/utils_test.dart index 5052ffd60..7caf9cd8f 100644 --- a/json_serializable/test/utils_test.dart +++ b/json_serializable/test/utils_test.dart @@ -16,7 +16,7 @@ const _items = { void main() { group('kebab', () { - for (var entry in _items.entries) { + for (final entry in _items.entries) { test('"${entry.key}"', () { expect(kebabCase(entry.key), entry.value); }); @@ -24,7 +24,7 @@ void main() { }); group('snake', () { - for (var entry in _items.entries) { + for (final entry in _items.entries) { test('"${entry.key}"', () { expect(snakeCase(entry.key), entry.value.replaceAll('-', '_')); }); diff --git a/json_serializable/test/yaml/build_config.g.dart b/json_serializable/test/yaml/build_config.g.dart index cf318d4c2..0b7e74760 100644 --- a/json_serializable/test/yaml/build_config.g.dart +++ b/json_serializable/test/yaml/build_config.g.dart @@ -9,7 +9,7 @@ part of 'build_config.dart'; Config _$ConfigFromJson(Map json) { return $checkedNew('Config', json, () { $checkKeys(json, requiredKeys: const ['builders']); - var val = Config( + final val = Config( builders: $checkedConvert( json, 'builders', @@ -75,7 +75,7 @@ Builder _$BuilderFromJson(Map json) { 'configLocation', 'auto_apply' ]); - var val = Builder( + final val = Builder( import: $checkedConvert(json, 'import', (v) => v as String), target: $checkedConvert(json, 'target', (v) => v as String), isOptional: $checkedConvert(json, 'is_optional', (v) => v as bool), @@ -111,7 +111,7 @@ Builder _$BuilderFromJson(Map json) { } Map _$BuilderToJson(Builder instance) { - var val = {}; + final val = {}; void writeNotNull(String key, dynamic value) { if (value != null) { diff --git a/json_serializable/test/yaml/yaml_test.dart b/json_serializable/test/yaml/yaml_test.dart index 8b84a4df8..5d8fa79cb 100644 --- a/json_serializable/test/yaml/yaml_test.dart +++ b/json_serializable/test/yaml/yaml_test.dart @@ -24,13 +24,13 @@ List _getTests() => Directory(_root) void main() { group('valid configurations', () { - for (var filePath in _getTests()) { + for (final filePath in _getTests()) { test(p.basenameWithoutExtension(filePath), () { - var content = File(filePath).readAsStringSync(); - var yamlContent = loadYaml(content, sourceUrl: filePath) as YamlMap; + final content = File(filePath).readAsStringSync(); + final yamlContent = loadYaml(content, sourceUrl: filePath) as YamlMap; try { - var config = Config.fromJson(yamlContent); + final config = Config.fromJson(yamlContent); expect(config, isNotNull); } on CheckedFromJsonException catch (e) { print(_prettyPrintCheckedFromJsonException(e)); @@ -42,20 +42,20 @@ void main() { group('bad configs', () { var index = 0; - for (var entry in _badConfigs.entries) { + for (final entry in _badConfigs.entries) { test('${index++}', () { - var yamlContent = + final yamlContent = loadYaml(entry.key, sourceUrl: 'file.yaml') as YamlMap; expect(yamlContent, isNotNull); printOnFailure(entry.key); try { - var config = Config.fromJson(yamlContent); + final config = Config.fromJson(yamlContent); print(loudEncode(config)); fail('parse should fail'); } on CheckedFromJsonException catch (e) { - var prettyOutput = _prettyPrintCheckedFromJsonException(e); + final prettyOutput = _prettyPrintCheckedFromJsonException(e); printOnFailure(prettyOutput); expect(prettyOutput, entry.value); } @@ -146,14 +146,14 @@ builders: }; String _prettyPrintCheckedFromJsonException(CheckedFromJsonException err) { - var yamlMap = err.map as YamlMap; + final yamlMap = err.map as YamlMap; YamlScalar _getYamlKey(String key) { return yamlMap.nodes.keys.singleWhere((k) => (k as YamlScalar).value == key, orElse: () => null) as YamlScalar; } - var innerError = err.innerError; + final innerError = err.innerError; var message = 'Could not create `${err.className}`.'; if (innerError is BadKeyException) { @@ -161,8 +161,8 @@ String _prettyPrintCheckedFromJsonException(CheckedFromJsonException err) { if (innerError is UnrecognizedKeysException) { message += '\n${innerError.message}\n'; - for (var key in innerError.unrecognizedKeys) { - var yamlKey = _getYamlKey(key); + for (final key in innerError.unrecognizedKeys) { + final yamlKey = _getYamlKey(key); assert(yamlKey != null); message += '\n${yamlKey.span.message('Invalid key "$key"')}'; } @@ -176,7 +176,7 @@ String _prettyPrintCheckedFromJsonException(CheckedFromJsonException err) { throw UnsupportedError('${innerError.runtimeType} is not supported.'); } } else { - var yamlValue = yamlMap.nodes[err.key]; + final yamlValue = yamlMap.nodes[err.key]; if (yamlValue == null) { assert(err.key == null); diff --git a/json_serializable/tool/builder.dart b/json_serializable/tool/builder.dart index c91b01311..270cdcddf 100644 --- a/json_serializable/tool/builder.dart +++ b/json_serializable/tool/builder.dart @@ -32,7 +32,7 @@ class _NonNullableGenerator extends Generator { final baseName = p.basenameWithoutExtension(path); final content = await buildStep.readAsString(buildStep.inputId); - var replacements = [ + final replacements = [ _Replacement(_copyrightContent, ''), _Replacement( "part '$baseName.g.dart", @@ -71,7 +71,7 @@ class _CheckedGenerator extends Generator { final baseName = p.basenameWithoutExtension(path); final content = await buildStep.readAsString(buildStep.inputId); - var replacements = [ + final replacements = [ _Replacement(_copyrightContent, ''), _Replacement( "part '$baseName.g.dart", @@ -90,7 +90,7 @@ class _WrappedGenerator extends Generator { final baseName = p.basenameWithoutExtension(path); final content = await buildStep.readAsString(buildStep.inputId); - var replacements = [ + final replacements = [ _Replacement(_copyrightContent, ''), _Replacement( "part '$baseName.g.dart", @@ -112,7 +112,7 @@ class _Replacement { String inputContent, Iterable<_Replacement> replacements) { var outputContent = inputContent; - for (var r in replacements) { + for (final r in replacements) { if (!outputContent.contains(r.existing)) { throw StateError( 'Input string did not contain `${r.existing}` as expected.'); From cc15cbfa55fe1ddc08304379f8c78ef7953738ba Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 9 Oct 2018 07:55:20 -0700 Subject: [PATCH 011/569] 2 cleanup commits (#337) * Move logic for toJson/fromJson parsing out of JsonKey parsing Better separation of concerns * rename json_key_with_conversion to json_key_utils --- json_serializable/lib/src/convert_pair.dart | 89 ------------------- json_serializable/lib/src/field_helpers.dart | 2 +- json_serializable/lib/src/helper_core.dart | 2 +- ...th_conversion.dart => json_key_utils.dart} | 37 +++----- .../lib/src/type_helper_ctx.dart | 89 ++++++++++++++++++- json_serializable/lib/src/utils.dart | 13 +++ 6 files changed, 113 insertions(+), 119 deletions(-) delete mode 100644 json_serializable/lib/src/convert_pair.dart rename json_serializable/lib/src/{json_key_with_conversion.dart => json_key_utils.dart} (86%) diff --git a/json_serializable/lib/src/convert_pair.dart b/json_serializable/lib/src/convert_pair.dart deleted file mode 100644 index 9fc37d2c0..000000000 --- a/json_serializable/lib/src/convert_pair.dart +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright (c) 2018, 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:analyzer/dart/element/element.dart'; -import 'package:analyzer/dart/element/type.dart'; -import 'package:analyzer/dart/constant/value.dart'; -import 'package:json_annotation/json_annotation.dart'; - -import 'type_helpers/convert_helper.dart'; -import 'utils.dart'; - -class ConvertPair { - static final _expando = Expando(); - static ConvertPair fromJsonKey(JsonKey key) => _expando[key]; - - final ConvertData fromJson, toJson; - - ConvertPair._(this.fromJson, this.toJson); - - factory ConvertPair(DartObject obj, FieldElement element) { - final toJson = _convertData(obj, element, false); - final fromJson = _convertData(obj, element, true); - - return ConvertPair._(fromJson, toJson); - } - - void populate(JsonKey key) { - _expando[key] = this; - } -} - -ConvertData _convertData(DartObject obj, FieldElement element, bool isFrom) { - final paramName = isFrom ? 'fromJson' : 'toJson'; - final objectValue = obj.getField(paramName); - - if (objectValue.isNull) { - return null; - } - - final type = objectValue.type as FunctionType; - - final executableElement = type.element as ExecutableElement; - - if (executableElement.parameters.isEmpty || - executableElement.parameters.first.isNamed || - executableElement.parameters.where((pe) => !pe.isOptional).length > 1) { - throwUnsupported( - element, - 'The `$paramName` function `${executableElement.name}` must have one ' - 'positional paramater.'); - } - - final argType = executableElement.parameters.first.type; - if (isFrom) { - final returnType = executableElement.returnType; - - if (returnType is TypeParameterType) { - // We keep things simple in this case. We rely on inferred type arguments - // to the `fromJson` function. - // TODO: consider adding error checking here if there is confusion. - } else if (!returnType.isAssignableTo(element.type)) { - throwUnsupported( - element, - 'The `$paramName` function `${executableElement.name}` return type ' - '`$returnType` is not compatible with field type `${element.type}`.'); - } - } else { - if (argType is TypeParameterType) { - // We keep things simple in this case. We rely on inferred type arguments - // to the `fromJson` function. - // TODO: consider adding error checking here if there is confusion. - } else if (!element.type.isAssignableTo(argType)) { - throwUnsupported( - element, - 'The `$paramName` function `${executableElement.name}` argument type ' - '`$argType` is not compatible with field type' - ' `${element.type}`.'); - } - } - - var name = executableElement.name; - - if (executableElement is MethodElement) { - name = '${executableElement.enclosingElement.name}.$name'; - } - - return ConvertData(name, argType); -} diff --git a/json_serializable/lib/src/field_helpers.dart b/json_serializable/lib/src/field_helpers.dart index 8bd508a6f..6cab799a7 100644 --- a/json_serializable/lib/src/field_helpers.dart +++ b/json_serializable/lib/src/field_helpers.dart @@ -9,7 +9,7 @@ import 'package:analyzer/src/dart/resolver/inheritance_manager.dart' import 'package:source_gen/source_gen.dart'; import 'helper_core.dart'; -import 'json_key_with_conversion.dart'; +import 'utils.dart'; class _FieldSet implements Comparable<_FieldSet> { final FieldElement field; diff --git a/json_serializable/lib/src/helper_core.dart b/json_serializable/lib/src/helper_core.dart index 7e4cbe9a0..0b71c3294 100644 --- a/json_serializable/lib/src/helper_core.dart +++ b/json_serializable/lib/src/helper_core.dart @@ -7,7 +7,7 @@ import 'package:build/build.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:source_gen/source_gen.dart'; -import 'json_key_with_conversion.dart'; +import 'json_key_utils.dart'; import 'json_serializable_generator.dart'; import 'type_helper.dart'; import 'type_helper_ctx.dart'; diff --git a/json_serializable/lib/src/json_key_with_conversion.dart b/json_serializable/lib/src/json_key_utils.dart similarity index 86% rename from json_serializable/lib/src/json_key_with_conversion.dart rename to json_serializable/lib/src/json_key_utils.dart index a4de25d63..0fb7cf628 100644 --- a/json_serializable/lib/src/json_key_with_conversion.dart +++ b/json_serializable/lib/src/json_key_utils.dart @@ -8,22 +8,9 @@ import 'package:analyzer/dart/constant/value.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:source_gen/source_gen.dart'; -import 'convert_pair.dart'; import 'json_literal_generator.dart'; import 'utils.dart'; -final _jsonKeyChecker = const TypeChecker.fromRuntime(JsonKey); - -DartObject _jsonKeyAnnotation(FieldElement element) => - _jsonKeyChecker.firstAnnotationOfExact(element) ?? - (element.getter == null - ? null - : _jsonKeyChecker.firstAnnotationOfExact(element.getter)); - -/// Returns `true` if [element] is annotated with [JsonKey]. -bool hasJsonKeyAnnotation(FieldElement element) => - _jsonKeyAnnotation(element) != null; - final _jsonKeyExpando = Expando(); JsonKey jsonKeyForField(FieldElement field, JsonSerializable classAnnotation) => @@ -33,7 +20,7 @@ JsonKey _from(FieldElement element, JsonSerializable classAnnotation) { // If an annotation exists on `element` the source is a 'real' field. // If the result is `null`, check the getter – it is a property. // TODO(kevmoo) setters: github.com/dart-lang/json_serializable/issues/24 - final obj = _jsonKeyAnnotation(element); + final obj = jsonKeyAnnotation(element); if (obj == null) { return _populateJsonKey(classAnnotation, element); @@ -126,20 +113,20 @@ JsonKey _from(FieldElement element, JsonSerializable classAnnotation) { defaultValue: defaultValueLiteral, required: obj.getField('required').toBoolValue(), disallowNullValue: disallowNullValue, - jsonConvertPair: ConvertPair(obj, element), ); } JsonKey _populateJsonKey( - JsonSerializable classAnnotation, FieldElement fieldElement, - {String name, - bool nullable, - bool includeIfNull, - bool ignore, - Object defaultValue, - bool required, - bool disallowNullValue, - ConvertPair jsonConvertPair}) { + JsonSerializable classAnnotation, + FieldElement fieldElement, { + String name, + bool nullable, + bool includeIfNull, + bool ignore, + Object defaultValue, + bool required, + bool disallowNullValue, +}) { final jsonKey = JsonKey( name: _encodedFieldName(classAnnotation, name, fieldElement), nullable: nullable ?? classAnnotation.nullable, @@ -150,8 +137,6 @@ JsonKey _populateJsonKey( required: required ?? false, disallowNullValue: disallowNullValue ?? false); - jsonConvertPair?.populate(jsonKey); - return jsonKey; } diff --git a/json_serializable/lib/src/type_helper_ctx.dart b/json_serializable/lib/src/type_helper_ctx.dart index ea52cc061..3ff32f254 100644 --- a/json_serializable/lib/src/type_helper_ctx.dart +++ b/json_serializable/lib/src/type_helper_ctx.dart @@ -2,15 +2,16 @@ // 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:analyzer/dart/constant/value.dart'; import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/type.dart'; import 'package:json_annotation/json_annotation.dart'; -import 'convert_pair.dart'; import 'helper_core.dart'; import 'json_serializable_generator.dart'; import 'type_helper.dart'; import 'type_helpers/convert_helper.dart'; +import 'utils.dart'; TypeHelperContext typeHelperContext( HelperCore helperCore, FieldElement fieldElement, JsonKey key) => @@ -47,7 +48,7 @@ class _TypeHelperCtx @override ConvertData get deserializeConvertData => _pairFromContext?.fromJson; - ConvertPair get _pairFromContext => ConvertPair.fromJsonKey(_key); + _ConvertPair get _pairFromContext => _ConvertPair(fieldElement); @override void addMember(String memberContent) { @@ -76,3 +77,87 @@ class _TypeHelperCtx final _notSupportedWithTypeHelpersMsg = 'None of the provided `TypeHelper` instances support the defined type.'; + +class _ConvertPair { + static final _expando = Expando<_ConvertPair>(); + static _ConvertPair fromJsonKey(JsonKey key) => _expando[key]; + + final ConvertData fromJson, toJson; + + _ConvertPair._(this.fromJson, this.toJson); + + factory _ConvertPair(FieldElement element) { + var pair = _expando[element]; + + if (pair == null) { + var obj = jsonKeyAnnotation(element); + if (obj == null) { + pair = _ConvertPair._(null, null); + } else { + var toJson = _convertData(obj, element, false); + var fromJson = _convertData(obj, element, true); + pair = _ConvertPair._(fromJson, toJson); + } + _expando[element] = pair; + } + return pair; + } +} + +ConvertData _convertData(DartObject obj, FieldElement element, bool isFrom) { + var paramName = isFrom ? 'fromJson' : 'toJson'; + var objectValue = obj.getField(paramName); + + if (objectValue.isNull) { + return null; + } + + var type = objectValue.type as FunctionType; + + var executableElement = type.element as ExecutableElement; + + if (executableElement.parameters.isEmpty || + executableElement.parameters.first.isNamed || + executableElement.parameters.where((pe) => !pe.isOptional).length > 1) { + throwUnsupported( + element, + 'The `$paramName` function `${executableElement.name}` must have one ' + 'positional paramater.'); + } + + var argType = executableElement.parameters.first.type; + if (isFrom) { + var returnType = executableElement.returnType; + + if (returnType is TypeParameterType) { + // We keep things simple in this case. We rely on inferred type arguments + // to the `fromJson` function. + // TODO: consider adding error checking here if there is confusion. + } else if (!returnType.isAssignableTo(element.type)) { + throwUnsupported( + element, + 'The `$paramName` function `${executableElement.name}` return type ' + '`$returnType` is not compatible with field type `${element.type}`.'); + } + } else { + if (argType is TypeParameterType) { + // We keep things simple in this case. We rely on inferred type arguments + // to the `fromJson` function. + // TODO: consider adding error checking here if there is confusion. + } else if (!element.type.isAssignableTo(argType)) { + throwUnsupported( + element, + 'The `$paramName` function `${executableElement.name}` argument type ' + '`$argType` is not compatible with field type' + ' `${element.type}`.'); + } + } + + var name = executableElement.name; + + if (executableElement is MethodElement) { + name = '${executableElement.enclosingElement.name}.$name'; + } + + return ConvertData(name, argType); +} diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index 475e0ffd7..e4ef6026e 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -4,11 +4,24 @@ import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/type.dart'; +import 'package:analyzer/dart/constant/value.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:meta/meta.dart' show alwaysThrows; import 'package:source_gen/source_gen.dart'; +final _jsonKeyChecker = const TypeChecker.fromRuntime(JsonKey); + +DartObject jsonKeyAnnotation(FieldElement element) => + _jsonKeyChecker.firstAnnotationOfExact(element) ?? + (element.getter == null + ? null + : _jsonKeyChecker.firstAnnotationOfExact(element.getter)); + +/// Returns `true` if [element] is annotated with [JsonKey]. +bool hasJsonKeyAnnotation(FieldElement element) => + jsonKeyAnnotation(element) != null; + final _upperCase = RegExp('[A-Z]'); String kebabCase(String input) => _fixCase(input, '-'); From 055a497a2704e471543d816fe84183e6bc34d919 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 9 Oct 2018 08:17:54 -0700 Subject: [PATCH 012/569] Move JsonSerializableGenerator configuration to new GeneratorConfig (#342) --- json_serializable/CHANGELOG.md | 7 ++ json_serializable/lib/builder.dart | 6 +- json_serializable/lib/json_serializable.dart | 1 + json_serializable/lib/src/decode_helper.dart | 6 +- json_serializable/lib/src/encoder_helper.dart | 21 ++-- .../lib/src/generator_config.dart | 93 ++++++++++++++++ json_serializable/lib/src/helper_core.dart | 12 +- .../lib/src/json_part_builder.dart | 29 ++--- .../lib/src/json_serializable_generator.dart | 103 ++---------------- json_serializable/lib/src/type_helper.dart | 6 +- .../lib/src/type_helper_ctx.dart | 13 +-- .../lib/src/type_helpers/iterable_helper.dart | 2 +- .../lib/src/type_helpers/json_helper.dart | 4 +- .../lib/src/type_helpers/map_helper.dart | 9 +- .../test/json_serializable_test.dart | 27 +++-- json_serializable/tool/build.dart | 10 +- 16 files changed, 179 insertions(+), 170 deletions(-) create mode 100644 json_serializable/lib/src/generator_config.dart diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index ddd4247d2..baa502794 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,5 +1,12 @@ ## 2.0.0 +* `json_serializable.dart` + + * **BREAKING** `JsonSerializableGenerator` now exposes a `config` property + of type `GeneratorConfig` instead of individual properties for `checked`, + `anyMay`, etc. This will affect anyone creating or using this class via + code. + * `type_helper.dart` * **BREAKING** `SerializeContext` and `DeserializeContext` have been replaced diff --git a/json_serializable/lib/builder.dart b/json_serializable/lib/builder.dart index cce8f3c53..9e3ce10da 100644 --- a/json_serializable/lib/builder.dart +++ b/json_serializable/lib/builder.dart @@ -14,6 +14,7 @@ library json_serializable.builder; import 'package:build/build.dart'; +import 'src/generator_config.dart'; import 'src/json_part_builder.dart'; /// Supports `package:build_runner` creation and configuration of @@ -25,7 +26,7 @@ Builder jsonSerializable(BuilderOptions options) { // elsewhere. final optionsMap = Map.from(options.config); - final builder = jsonPartBuilder( + var config = GeneratorConfig( useWrappers: optionsMap.remove('use_wrappers') as bool, checked: optionsMap.remove('checked') as bool, anyMap: optionsMap.remove('any_map') as bool, @@ -41,5 +42,6 @@ Builder jsonSerializable(BuilderOptions options) { log.warning('These options were ignored: `$optionsMap`.'); } } - return builder; + + return jsonPartBuilder(config: config); } diff --git a/json_serializable/lib/json_serializable.dart b/json_serializable/lib/json_serializable.dart index 094597df6..ec9cae1a7 100644 --- a/json_serializable/lib/json_serializable.dart +++ b/json_serializable/lib/json_serializable.dart @@ -2,5 +2,6 @@ // 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. +export 'src/generator_config.dart' show GeneratorConfig; export 'src/json_literal_generator.dart' show JsonLiteralGenerator; export 'src/json_serializable_generator.dart' show JsonSerializableGenerator; diff --git a/json_serializable/lib/src/decode_helper.dart b/json_serializable/lib/src/decode_helper.dart index fcdcbabe3..4d08bea5b 100644 --- a/json_serializable/lib/src/decode_helper.dart +++ b/json_serializable/lib/src/decode_helper.dart @@ -26,7 +26,7 @@ abstract class DecodeHelper implements HelperCore { assert(annotation.createFactory); assert(_buffer.isEmpty); - final mapType = generator.anyMap ? 'Map' : 'Map'; + final mapType = config.anyMap ? 'Map' : 'Map'; _buffer.write('$targetClassReference ' '${prefix}FromJson${genericClassArgumentsImpl(true)}' '($mapType json) {\n'); @@ -37,7 +37,7 @@ abstract class DecodeHelper implements HelperCore { ctorParam: ctorParam); _ConstructorData data; - if (generator.checked) { + if (config.checked) { final classLiteral = escapeDartString(element.name); _buffer.write(''' @@ -169,7 +169,7 @@ abstract class DecodeHelper implements HelperCore { String value; try { - if (generator.checked) { + if (config.checked) { value = contextHelper.deserialize(targetType, 'v').toString(); if (!checkedProperty) { value = '\$checkedConvert(json, $jsonKeyName, (v) => $value)'; diff --git a/json_serializable/lib/src/encoder_helper.dart b/json_serializable/lib/src/encoder_helper.dart index 92ea91db3..c7e8db0de 100644 --- a/json_serializable/lib/src/encoder_helper.dart +++ b/json_serializable/lib/src/encoder_helper.dart @@ -5,14 +5,14 @@ import 'package:analyzer/dart/element/element.dart'; import 'constants.dart'; +import 'generator_config.dart'; import 'helper_core.dart'; -import 'json_serializable_generator.dart'; import 'type_helper.dart'; abstract class EncodeHelper implements HelperCore { String _fieldAccess(FieldElement field) { var fieldAccess = field.name; - if (generator.generateToJsonFunction) { + if (config.generateToJsonFunction) { fieldAccess = '$_toJsonParamName.$fieldAccess'; } return fieldAccess; @@ -29,7 +29,7 @@ abstract class EncodeHelper implements HelperCore { final buffer = StringBuffer(); - if (generator.generateToJsonFunction) { + if (config.generateToJsonFunction) { final functionName = '${prefix}ToJson${genericClassArgumentsImpl(true)}'; buffer.write('Map $functionName' '($targetClassReference $_toJsonParamName) '); @@ -51,9 +51,8 @@ abstract class EncodeHelper implements HelperCore { final writeNaive = accessibleFields.every(_writeJsonValueNaive); - if (generator.useWrappers) { - final param = - generator.generateToJsonFunction ? _toJsonParamName : 'this'; + if (config.useWrappers) { + final param = config.generateToJsonFunction ? _toJsonParamName : 'this'; buffer.writeln('=> ${_wrapperClassName(false)}($param);'); } else { if (writeNaive) { @@ -65,14 +64,14 @@ abstract class EncodeHelper implements HelperCore { } } - if (!generator.generateToJsonFunction) { + if (!config.generateToJsonFunction) { // end of the mixin class buffer.writeln('}'); } yield buffer.toString(); - if (generator.useWrappers) { + if (config.useWrappers) { yield _createWrapperClass(accessibleFields); } } @@ -82,7 +81,7 @@ abstract class EncodeHelper implements HelperCore { buffer.writeln(); // TODO(kevmoo): write JsonMapWrapper if annotation lib is prefix-imported - final fieldType = generator.generateToJsonFunction + final fieldType = config.generateToJsonFunction ? targetClassReference : _mixinClassName(false); @@ -162,7 +161,7 @@ class ${_wrapperClassName(true)} extends \$JsonMapWrapper { } /// Name of the parameter used when generating top-level `toJson` functions - /// if [JsonSerializableGenerator.generateToJsonFunction] is `true`. + /// if [GeneratorConfig.generateToJsonFunction] is `true`. static const _toJsonParamName = 'instance'; void _writeToJsonWithNullChecks( @@ -185,7 +184,7 @@ class ${_wrapperClassName(true)} extends \$JsonMapWrapper { // access with `this.`. if (safeFieldAccess == generatedLocalVarName || safeFieldAccess == toJsonMapHelperName) { - assert(!generator.generateToJsonFunction, + assert(!config.generateToJsonFunction, 'This code path should only be hit during the mixin codepath.'); safeFieldAccess = 'this.$safeFieldAccess'; } diff --git a/json_serializable/lib/src/generator_config.dart b/json_serializable/lib/src/generator_config.dart new file mode 100644 index 000000000..8dbb9b7c7 --- /dev/null +++ b/json_serializable/lib/src/generator_config.dart @@ -0,0 +1,93 @@ +// Copyright (c) 2018, 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:json_annotation/json_annotation.dart'; + +import 'json_serializable_generator.dart'; + +/// Represents the configuration for [JsonSerializableGenerator]. +class GeneratorConfig { + /// If `true`, [Map] types are *not* assumed to be [Map] + /// – which is the default type of [Map] instances return by JSON decode in + /// `dart:convert`. + /// + /// This will increase the code size, but allows [Map] types returned + /// from other sources, such as `package:yaml`. + /// + /// *Note: in many cases the key values are still assumed to be [String]*. + final bool anyMap; + + /// If `true`, wrappers are used to minimize the number of + /// [Map] and [List] instances created during serialization. + /// + /// This will increase the code size, but it may improve runtime performance, + /// especially for large object graphs. + final bool useWrappers; + + /// If `true`, generated `fromJson` functions include extra checks to validate + /// proper deserialization of types. + /// + /// If an exception is thrown during deserialization, a + /// [CheckedFromJsonException] is thrown. + final bool checked; + + /// If `true`, generated `toJson` methods will explicitly call `toJson` on + /// nested objects. + /// + /// When using JSON encoding support in `dart:convert`, `toJson` is + /// automatically called on objects, so the default behavior + /// (`explicitToJson: false`) is to omit the `toJson` call. + /// + /// Example of `explicitToJson: false` (default) + /// + /// ```dart + /// Map toJson() => {'child': child}; + /// ``` + /// + /// Example of `explicitToJson: true` + /// + /// ```dart + /// Map toJson() => {'child': child?.toJson()}; + /// ``` + final bool explicitToJson; + + /// Controls how `toJson` functionality is generated for all types processed + /// by this generator. + /// + /// If `true` (the default), then a top-level function is created that you can reference + /// from your class. + /// + /// ```dart + /// @JsonSerializable() + /// class Example { + /// // ... + /// Map toJson() => _$ExampleToJson(this); + /// } + /// ``` + /// + /// If `false`, a private `_$ClassNameSerializerMixin` class is + /// created in the generated part file which contains a `toJson` method. + /// + /// Mix in this class to the source class: + /// + /// ```dart + /// @JsonSerializable() + /// class Example extends Object with _$ExampleSerializerMixin { + /// // ... + /// } + /// ``` + final bool generateToJsonFunction; + + const GeneratorConfig({ + bool anyMap = false, + bool checked = false, + bool explicitToJson = false, + bool generateToJsonFunction = true, + bool useWrappers = false, + }) : this.anyMap = anyMap ?? false, + this.checked = checked ?? false, + this.explicitToJson = explicitToJson ?? false, + this.generateToJsonFunction = generateToJsonFunction ?? true, + this.useWrappers = useWrappers ?? false; +} diff --git a/json_serializable/lib/src/helper_core.dart b/json_serializable/lib/src/helper_core.dart index 0b71c3294..7c695122c 100644 --- a/json_serializable/lib/src/helper_core.dart +++ b/json_serializable/lib/src/helper_core.dart @@ -5,8 +5,10 @@ import 'package:analyzer/dart/element/element.dart'; import 'package:build/build.dart'; import 'package:json_annotation/json_annotation.dart'; +import 'package:meta/meta.dart'; import 'package:source_gen/source_gen.dart'; +import 'generator_config.dart'; import 'json_key_utils.dart'; import 'json_serializable_generator.dart'; import 'type_helper.dart'; @@ -14,10 +16,18 @@ import 'type_helper_ctx.dart'; import 'utils.dart'; abstract class HelperCore { - final ClassElement element; + @protected final JsonSerializable annotation; + + @protected final JsonSerializableGenerator generator; + final ClassElement element; + + GeneratorConfig get config => generator.config; + + Iterable get allTypeHelpers; + HelperCore(this.generator, this.element, this.annotation); void addMember(String memberContent); diff --git a/json_serializable/lib/src/json_part_builder.dart b/json_serializable/lib/src/json_part_builder.dart index 336f27a30..392b59597 100644 --- a/json_serializable/lib/src/json_part_builder.dart +++ b/json_serializable/lib/src/json_part_builder.dart @@ -5,6 +5,7 @@ import 'package:build/build.dart'; import 'package:source_gen/source_gen.dart'; +import 'generator_config.dart'; import 'json_literal_generator.dart'; import 'json_serializable_generator.dart'; @@ -13,25 +14,9 @@ import 'json_serializable_generator.dart'; /// /// [formatOutput] is called to format the generated code. If not provided, /// the default Dart code formatter is used. -/// -/// For details on [useWrappers], [anyMap], and [checked] see -/// [JsonSerializableGenerator]. -Builder jsonPartBuilder({ - String formatOutput(String code), - bool useWrappers = false, - bool anyMap = false, - bool checked = false, - bool explicitToJson = false, - bool generateToJsonFunction = true, -}) { - return SharedPartBuilder([ - JsonSerializableGenerator( - useWrappers: useWrappers, - anyMap: anyMap, - checked: checked, - explicitToJson: explicitToJson, - generateToJsonFunction: generateToJsonFunction, - ), - const JsonLiteralGenerator() - ], 'json_serializable', formatOutput: formatOutput); -} +Builder jsonPartBuilder( + {String formatOutput(String code), GeneratorConfig config}) => + SharedPartBuilder([ + JsonSerializableGenerator(config: config), + const JsonLiteralGenerator() + ], 'json_serializable', formatOutput: formatOutput); diff --git a/json_serializable/lib/src/json_serializable_generator.dart b/json_serializable/lib/src/json_serializable_generator.dart index 2745974f3..9e2a2a85f 100644 --- a/json_serializable/lib/src/json_serializable_generator.dart +++ b/json_serializable/lib/src/json_serializable_generator.dart @@ -10,6 +10,7 @@ import 'package:source_gen/source_gen.dart'; import 'decode_helper.dart'; import 'encoder_helper.dart'; import 'field_helpers.dart'; +import 'generator_config.dart'; import 'helper_core.dart'; import 'type_helper.dart'; import 'type_helpers/convert_helper.dart'; @@ -24,9 +25,6 @@ import 'type_helpers/uri_helper.dart'; import 'type_helpers/value_helper.dart'; import 'utils.dart'; -Iterable allHelpersImpl(JsonSerializableGenerator generator) => - generator._allHelpers; - class JsonSerializableGenerator extends GeneratorForAnnotation { static const _coreHelpers = [ @@ -50,93 +48,16 @@ class JsonSerializableGenerator JsonConverterHelper() ].followedBy(_typeHelpers).followedBy(_coreHelpers); - /// If `true`, wrappers are used to minimize the number of - /// [Map] and [List] instances created during serialization. - /// - /// This will increase the code size, but it may improve runtime performance, - /// especially for large object graphs. - final bool useWrappers; - - /// If `true`, [Map] types are *not* assumed to be [Map] - /// – which is the default type of [Map] instances return by JSON decode in - /// `dart:convert`. - /// - /// This will increase the code size, but allows [Map] types returned - /// from other sources, such as `package:yaml`. - /// - /// *Note: in many cases the key values are still assumed to be [String]*. - final bool anyMap; - - /// If `true`, generated `fromJson` functions include extra checks to validate - /// proper deserialization of types. - /// - /// If an exception is thrown during deserialization, a - /// [CheckedFromJsonException] is thrown. - final bool checked; - - /// If `true`, generated `toJson` methods will explicitly call `toJson` on - /// nested objects. - /// - /// When using JSON encoding support in `dart:convert`, `toJson` is - /// automatically called on objects, so the default behavior - /// (`explicitToJson: false`) is to omit the `toJson` call. - /// - /// Example of `explicitToJson: false` (default) - /// - /// ```dart - /// Map toJson() => {'child': child}; - /// ``` - /// - /// Example of `explicitToJson: true` - /// - /// ```dart - /// Map toJson() => {'child': child?.toJson()}; - /// ``` - final bool explicitToJson; - - /// Controls how `toJson` functionality is generated for all types processed - /// by this generator. - /// - /// If `true` (the default), then a top-level function is created that you can reference - /// from your class. - /// - /// ```dart - /// @JsonSerializable() - /// class Example { - /// // ... - /// Map toJson() => _$ExampleToJson(this); - /// } - /// ``` - /// - /// If `false`, a private `_$ClassNameSerializerMixin` class is - /// created in the generated part file which contains a `toJson` method. - /// - /// Mix in this class to the source class: - /// - /// ```dart - /// @JsonSerializable() - /// class Example extends Object with _$ExampleSerializerMixin { - /// // ... - /// } - /// ``` - final bool generateToJsonFunction; + final GeneratorConfig config; /// Creates an instance of [JsonSerializableGenerator]. /// /// If [typeHelpers] is not provided, three built-in helpers are used: /// [JsonHelper], [DateTimeHelper], [DurationHelper] and [UriHelper]. const JsonSerializableGenerator({ + GeneratorConfig config, List typeHelpers, - bool useWrappers = false, - bool anyMap = false, - bool checked = false, - bool explicitToJson = false, - bool generateToJsonFunction = true, - }) : this.useWrappers = useWrappers ?? false, - this.anyMap = anyMap ?? false, - this.checked = checked ?? false, - this.explicitToJson = explicitToJson ?? false, - this.generateToJsonFunction = generateToJsonFunction ?? true, + }) : this.config = config ?? const GeneratorConfig(), this._typeHelpers = typeHelpers ?? _defaultHelpers; /// Creates an instance of [JsonSerializableGenerator]. @@ -145,17 +66,10 @@ class JsonSerializableGenerator /// the built-in helpers: /// [JsonHelper], [DateTimeHelper], [DurationHelper] and [UriHelper]. factory JsonSerializableGenerator.withDefaultHelpers( - Iterable typeHelpers, { - bool useWrappers = false, - bool anyMap = false, - bool checked = false, - bool generateToJsonFunction = false, - }) => + Iterable typeHelpers, + {GeneratorConfig config}) => JsonSerializableGenerator( - useWrappers: useWrappers, - anyMap: anyMap, - checked: checked, - generateToJsonFunction: generateToJsonFunction, + config: config, typeHelpers: List.unmodifiable(typeHelpers.followedBy(_defaultHelpers))); @@ -188,6 +102,9 @@ class _GeneratorHelper extends HelperCore with EncodeHelper, DecodeHelper { _addedMembers.add(memberContent); } + @override + Iterable get allTypeHelpers => generator._allHelpers; + Iterable _generate() sync* { assert(_addedMembers.isEmpty); final sortedFields = createSortedFieldSet(element); diff --git a/json_serializable/lib/src/type_helper.dart b/json_serializable/lib/src/type_helper.dart index 97ca5f016..90477bde5 100644 --- a/json_serializable/lib/src/type_helper.dart +++ b/json_serializable/lib/src/type_helper.dart @@ -5,6 +5,8 @@ import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/type.dart'; +import 'generator_config.dart'; + /// Context information provided in calls to [TypeHelper.serialize] and /// [TypeHelper.deserialize]. abstract class TypeHelperContext { @@ -32,9 +34,7 @@ abstract class TypeHelperContext { /// Extended context information with includes configuration values /// corresponding to `JsonSerializableGenerator` settings. abstract class TypeHelperContextWithConfig extends TypeHelperContext { - bool get explicitToJson; - bool get anyMap; - bool get useWrappers; + GeneratorConfig get config; } abstract class TypeHelper { diff --git a/json_serializable/lib/src/type_helper_ctx.dart b/json_serializable/lib/src/type_helper_ctx.dart index 3ff32f254..3119e2206 100644 --- a/json_serializable/lib/src/type_helper_ctx.dart +++ b/json_serializable/lib/src/type_helper_ctx.dart @@ -6,9 +6,9 @@ import 'package:analyzer/dart/constant/value.dart'; import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/type.dart'; import 'package:json_annotation/json_annotation.dart'; +import 'package:json_serializable/src/generator_config.dart'; import 'helper_core.dart'; -import 'json_serializable_generator.dart'; import 'type_helper.dart'; import 'type_helpers/convert_helper.dart'; import 'utils.dart'; @@ -32,13 +32,7 @@ class _TypeHelperCtx ClassElement get classElement => _helperCore.element; @override - bool get useWrappers => _helperCore.generator.useWrappers; - - @override - bool get anyMap => _helperCore.generator.anyMap; - - @override - bool get explicitToJson => _helperCore.generator.explicitToJson; + GeneratorConfig get config => _helperCore.config; _TypeHelperCtx(this._helperCore, this.fieldElement, this._key); @@ -69,8 +63,7 @@ class _TypeHelperCtx Object _run(DartType targetType, String expression, Object invoke(TypeHelper instance)) => - allHelpersImpl(_helperCore.generator).map(invoke).firstWhere( - (r) => r != null, + _helperCore.allTypeHelpers.map(invoke).firstWhere((r) => r != null, orElse: () => throw UnsupportedTypeError( targetType, expression, _notSupportedWithTypeHelpersMsg)); } diff --git a/json_serializable/lib/src/type_helpers/iterable_helper.dart b/json_serializable/lib/src/type_helpers/iterable_helper.dart index ad8bc505e..21df85c4c 100644 --- a/json_serializable/lib/src/type_helpers/iterable_helper.dart +++ b/json_serializable/lib/src/type_helpers/iterable_helper.dart @@ -34,7 +34,7 @@ class IterableHelper extends TypeHelper { // If they are not equal, then we to write out the substitution. if (subField != closureArg) { final lambda = LambdaResult.process(subField, closureArg); - if (context.useWrappers && isList) { + if (context.config.useWrappers && isList) { var method = '\$wrapList'; if (context.nullable) { method = '${method}HandleNull'; diff --git a/json_serializable/lib/src/type_helpers/json_helper.dart b/json_serializable/lib/src/type_helpers/json_helper.dart index 9a8ee3577..ac8687fd3 100644 --- a/json_serializable/lib/src/type_helpers/json_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_helper.dart @@ -26,7 +26,7 @@ class JsonHelper extends TypeHelper { return null; } - if (context.explicitToJson) { + if (context.config.explicitToJson) { return '$expression${context.nullable ? '?' : ''}.toJson()'; } return expression; @@ -51,7 +51,7 @@ class JsonHelper extends TypeHelper { final asCastType = fromJsonCtor.parameters.first.type; asCast = asStatement(asCastType); } else if (_annotation(type)?.createFactory == true) { - if (context.anyMap) { + if (context.config.anyMap) { asCast = ' as Map'; } else { asCast = ' as Map'; diff --git a/json_serializable/lib/src/type_helpers/map_helper.dart b/json_serializable/lib/src/type_helpers/map_helper.dart index fc37a0eed..f8877d5a8 100644 --- a/json_serializable/lib/src/type_helpers/map_helper.dart +++ b/json_serializable/lib/src/type_helpers/map_helper.dart @@ -35,7 +35,7 @@ class MapHelper extends TypeHelper { return expression; } - if (context.useWrappers) { + if (context.config.useWrappers) { var method = '\$wrapMap'; if (context.nullable) { method = '${method}HandleNull'; @@ -70,7 +70,7 @@ class MapHelper extends TypeHelper { if (!isEnumKey) { if (valueArgIsAny) { - if (context.anyMap) { + if (context.config.anyMap) { if (_isObjectOrDynamic(keyArg)) { return '$expression as Map'; } @@ -96,12 +96,13 @@ class MapHelper extends TypeHelper { final optionalQuestion = context.nullable ? '?' : ''; - final mapCast = context.anyMap ? 'as Map' : 'as Map'; + final mapCast = + context.config.anyMap ? 'as Map' : 'as Map'; String keyUsage; if (isEnumKey) { keyUsage = context.deserialize(keyArg, _keyParam).toString(); - } else if (context.anyMap && !_isObjectOrDynamic(keyArg)) { + } else if (context.config.anyMap && !_isObjectOrDynamic(keyArg)) { keyUsage = '$_keyParam as String'; } else { keyUsage = _keyParam; diff --git a/json_serializable/test/json_serializable_test.dart b/json_serializable/test/json_serializable_test.dart index 369ba42a8..f02b8edd3 100644 --- a/json_serializable/test/json_serializable_test.dart +++ b/json_serializable/test/json_serializable_test.dart @@ -172,10 +172,10 @@ void main() async { } group('without wrappers', () { - _registerTests(const JsonSerializableGenerator()); + _registerTests(const GeneratorConfig()); }); group('with wrapper', - () => _registerTests(const JsonSerializableGenerator(useWrappers: true))); + () => _registerTests(const GeneratorConfig(useWrappers: true))); } void _testAnnotatedClass(AnnotatedElement annotatedElement) { @@ -203,13 +203,13 @@ void _testShouldThrow(AnnotatedElement annotatedElement) { expect( () => _runForElementNamed( - const JsonSerializableGenerator(useWrappers: false), element.name), + const GeneratorConfig(useWrappers: false), element.name), _throwsInvalidGenerationSourceError(messageMatcher, todoMatcher), reason: 'Should fail without wrappers.'); expect( () => _runForElementNamed( - const JsonSerializableGenerator(useWrappers: true), element.name), + const GeneratorConfig(useWrappers: true), element.name), _throwsInvalidGenerationSourceError(messageMatcher, todoMatcher), reason: 'Should fail with wrappers.'); }); @@ -230,8 +230,8 @@ void _testShouldGenerate(AnnotatedElement annotatedElement) { final checked = annotatedElement.annotation.read('checked').boolValue; test(element.name, () { - final output = _runForElementNamed( - JsonSerializableGenerator(checked: checked), element.name); + final output = + _runForElementNamed(GeneratorConfig(checked: checked), element.name); expect(output, matcher); expect(_buildLogItems, expectedLogItems); @@ -244,8 +244,7 @@ void _testShouldGenerate(AnnotatedElement annotatedElement) { if (wrappedMatcher != null) { test('${element.name} - (wrapped)', () { final output = _runForElementNamed( - JsonSerializableGenerator(checked: checked, useWrappers: true), - element.name); + GeneratorConfig(checked: checked, useWrappers: true), element.name); expect(output, wrappedMatcher); expect(_buildLogItems, expectedLogItems); @@ -254,8 +253,9 @@ void _testShouldGenerate(AnnotatedElement annotatedElement) { } } -String _runForElementNamed(JsonSerializableGenerator generator, String name) { +String _runForElementNamed(GeneratorConfig config, String name) { final element = _library.allElements.singleWhere((e) => e.name == name); + final generator = JsonSerializableGenerator(config: config); final annotation = generator.typeChecker.firstAnnotationOf(element); final generated = generator .generateForAnnotatedElement(element, ConstantReader(annotation), null) @@ -290,7 +290,7 @@ final _annotatedElements = _library.allElements return map; }); -void _registerTests(JsonSerializableGenerator generator) { +void _registerTests(GeneratorConfig generator) { String runForElementNamed(String name) => _runForElementNamed(generator, name); @@ -303,7 +303,7 @@ void _registerTests(JsonSerializableGenerator generator) { group('explicit toJson', () { test('nullable', () { final output = _runForElementNamed( - JsonSerializableGenerator( + GeneratorConfig( explicitToJson: true, useWrappers: generator.useWrappers), 'TrivialNestedNullable'); @@ -347,7 +347,7 @@ Map _$TrivialNestedNullableToJson( }); test('non-nullable', () { final output = _runForElementNamed( - JsonSerializableGenerator( + GeneratorConfig( explicitToJson: true, useWrappers: generator.useWrappers), 'TrivialNestedNonNullable'); @@ -496,8 +496,7 @@ Map _$TrivialNestedNonNullableToJson( test('class with child json-able object - anyMap', () { final output = _runForElementNamed( - JsonSerializableGenerator( - anyMap: true, useWrappers: generator.useWrappers), + GeneratorConfig(anyMap: true, useWrappers: generator.useWrappers), 'ParentObject'); expect(output, contains("ChildObject.fromJson(json['child'] as Map)")); diff --git a/json_serializable/tool/build.dart b/json_serializable/tool/build.dart index 42a75dfbb..3ad546c97 100755 --- a/json_serializable/tool/build.dart +++ b/json_serializable/tool/build.dart @@ -11,6 +11,7 @@ import 'package:build_runner/build_runner.dart'; import 'package:build_runner_core/build_runner_core.dart'; import 'package:build_test/builder.dart'; import 'package:json_serializable/src/json_part_builder.dart' as jpb; +import 'package:json_serializable/src/generator_config.dart'; import 'package:source_gen/builder.dart'; import 'builder.dart'; @@ -31,10 +32,11 @@ Builder _jsonPartBuilder({ return jpb.jsonPartBuilder( formatOutput: formatOutput, - useWrappers: useWrappers, - anyMap: anyMap, - checked: checked, - generateToJsonFunction: generateToJsonFunction); + config: GeneratorConfig( + useWrappers: useWrappers, + anyMap: anyMap, + checked: checked, + generateToJsonFunction: generateToJsonFunction)); } final List builders = [ From 030d1c12619f60eba32461d62d3bc7c2711e93ff Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 9 Oct 2018 12:33:38 -0700 Subject: [PATCH 013/569] Consolidate more build configuration --- json_serializable/tool/build.dart | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/json_serializable/tool/build.dart b/json_serializable/tool/build.dart index 3ad546c97..df714eba8 100755 --- a/json_serializable/tool/build.dart +++ b/json_serializable/tool/build.dart @@ -43,7 +43,7 @@ final List builders = [ applyToRoot(nonNull(), generateFor: const InputSet(include: [ 'test/kitchen_sink/kitchen_sink.dart', - 'test/integration/json_test_example.dart' + 'test/integration/json_test_example.dart', ])), applyToRoot(checked(), generateFor: const InputSet(include: [ @@ -76,7 +76,7 @@ final List builders = [ 'test/kitchen_sink/kitchen_sink.dart', 'test/kitchen_sink/kitchen_sink.non_nullable.dart', 'test/kitchen_sink/simple_object.dart', - 'test/kitchen_sink/strict_keys_object.dart' + 'test/kitchen_sink/strict_keys_object.dart', ], ), hideOutput: true), @@ -93,12 +93,6 @@ final List builders = [ generateFor: const InputSet( include: [ 'test/yaml/build_config.dart', - ], - ), - hideOutput: true), - applyToRoot(_jsonPartBuilder(checked: true, anyMap: true), - generateFor: const InputSet( - include: [ 'test/default_value/default_value.checked.dart', ], ), @@ -107,12 +101,6 @@ final List builders = [ generateFor: const InputSet( include: [ 'test/integration/json_test_example*wrapped.dart', - ], - ), - hideOutput: true), - applyToRoot(_jsonPartBuilder(useWrappers: true), - generateFor: const InputSet( - include: [ 'test/generic_files/generic_class*wrapped.dart', ], ), From 058242887b27cc65529651b2e25f9b87b2690207 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 9 Oct 2018 12:54:37 -0700 Subject: [PATCH 014/569] Throw an error when unsupported options are provided in build.yaml Use json_serializable to support configuration parsing --- json_serializable/CHANGELOG.md | 5 +++ json_serializable/lib/builder.dart | 22 +----------- .../lib/src/generator_config.dart | 13 +++++-- .../lib/src/generator_config.g.dart | 32 +++++++++++++++++ json_serializable/test/config_test.dart | 36 ++++++------------- json_serializable/tool/build.dart | 5 +++ 6 files changed, 64 insertions(+), 49 deletions(-) create mode 100644 json_serializable/lib/src/generator_config.g.dart diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index baa502794..4544506ce 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,5 +1,10 @@ ## 2.0.0 +* Build configuration + + * **BREAKING** Unsupported options defined in `build.yaml` will cause + exceptions instead of being logged and ignored. + * `json_serializable.dart` * **BREAKING** `JsonSerializableGenerator` now exposes a `config` property diff --git a/json_serializable/lib/builder.dart b/json_serializable/lib/builder.dart index 9e3ce10da..52295328e 100644 --- a/json_serializable/lib/builder.dart +++ b/json_serializable/lib/builder.dart @@ -22,26 +22,6 @@ import 'src/json_part_builder.dart'; /// /// Not meant to be invoked by hand-authored code. Builder jsonSerializable(BuilderOptions options) { - // Paranoid copy of options.config - don't assume it's mutable or needed - // elsewhere. - final optionsMap = Map.from(options.config); - - var config = GeneratorConfig( - useWrappers: optionsMap.remove('use_wrappers') as bool, - checked: optionsMap.remove('checked') as bool, - anyMap: optionsMap.remove('any_map') as bool, - explicitToJson: optionsMap.remove('explicit_to_json') as bool, - generateToJsonFunction: - optionsMap.remove('generate_to_json_function') as bool, - ); - - if (optionsMap.isNotEmpty) { - if (log == null) { - throw StateError('Upgrade `build_runner` to at least 0.8.2.'); - } else { - log.warning('These options were ignored: `$optionsMap`.'); - } - } - + var config = GeneratorConfig.fromJson(options.config); return jsonPartBuilder(config: config); } diff --git a/json_serializable/lib/src/generator_config.dart b/json_serializable/lib/src/generator_config.dart index 8dbb9b7c7..d2f79d624 100644 --- a/json_serializable/lib/src/generator_config.dart +++ b/json_serializable/lib/src/generator_config.dart @@ -6,7 +6,11 @@ import 'package:json_annotation/json_annotation.dart'; import 'json_serializable_generator.dart'; +part 'generator_config.g.dart'; + /// Represents the configuration for [JsonSerializableGenerator]. +@JsonSerializable( + disallowUnrecognizedKeys: true, fieldRename: FieldRename.snake) class GeneratorConfig { /// If `true`, [Map] types are *not* assumed to be [Map] /// – which is the default type of [Map] instances return by JSON decode in @@ -55,8 +59,8 @@ class GeneratorConfig { /// Controls how `toJson` functionality is generated for all types processed /// by this generator. /// - /// If `true` (the default), then a top-level function is created that you can reference - /// from your class. + /// If `true` (the default), then a top-level function is created that you can + /// reference from your class. /// /// ```dart /// @JsonSerializable() @@ -90,4 +94,9 @@ class GeneratorConfig { this.explicitToJson = explicitToJson ?? false, this.generateToJsonFunction = generateToJsonFunction ?? true, this.useWrappers = useWrappers ?? false; + + factory GeneratorConfig.fromJson(Map json) => + _$GeneratorConfigFromJson(json); + + Map toJson() => _$GeneratorConfigToJson(this); } diff --git a/json_serializable/lib/src/generator_config.g.dart b/json_serializable/lib/src/generator_config.g.dart new file mode 100644 index 000000000..e9fc890f3 --- /dev/null +++ b/json_serializable/lib/src/generator_config.g.dart @@ -0,0 +1,32 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'generator_config.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +GeneratorConfig _$GeneratorConfigFromJson(Map json) { + $checkKeys(json, allowedKeys: const [ + 'any_map', + 'use_wrappers', + 'checked', + 'explicit_to_json', + 'generate_to_json_function' + ]); + return GeneratorConfig( + anyMap: json['any_map'] as bool, + checked: json['checked'] as bool, + explicitToJson: json['explicit_to_json'] as bool, + generateToJsonFunction: json['generate_to_json_function'] as bool, + useWrappers: json['use_wrappers'] as bool); +} + +Map _$GeneratorConfigToJson(GeneratorConfig instance) => + { + 'any_map': instance.anyMap, + 'use_wrappers': instance.useWrappers, + 'checked': instance.checked, + 'explicit_to_json': instance.explicitToJson, + 'generate_to_json_function': instance.generateToJsonFunction + }; diff --git a/json_serializable/test/config_test.dart b/json_serializable/test/config_test.dart index 3ff3f8cf1..7bcf3fd17 100644 --- a/json_serializable/test/config_test.dart +++ b/json_serializable/test/config_test.dart @@ -3,43 +3,25 @@ // BSD-style license that can be found in the LICENSE file. @TestOn('vm') - -import 'dart:async'; import 'dart:io'; import 'package:build/build.dart'; +import 'package:json_annotation/json_annotation.dart'; import 'package:json_serializable/builder.dart'; -import 'package:logging/logging.dart'; import 'package:test/test.dart'; import 'package:yaml/yaml.dart'; import 'test_utils.dart'; void main() { - StreamSubscription sub; - final records = []; - - setUpAll(() { - sub = log.onRecord.listen(records.add); - }); - - tearDownAll(() async { - await sub.cancel(); - }); - - setUp(records.clear); - test('empty', () async { final builder = jsonSerializable(BuilderOptions.empty); expect(builder, isNotNull); - expect(records, isEmpty); }); test('valid config', () async { final builder = jsonSerializable(const BuilderOptions(_validConfig)); expect(builder, isNotNull); - - expect(records, isEmpty); }); test('readme config', () async { @@ -68,16 +50,18 @@ void main() { final builder = jsonSerializable(BuilderOptions(config)); expect(builder, isNotNull); - expect(records, isEmpty); }); test('unsupported configuration', () async { - final builder = - jsonSerializable(const BuilderOptions({'unsupported': 'config'})); - expect(builder, isNotNull); - - expect(records.single.message, - 'These options were ignored: `{unsupported: config}`.'); + var matcher = const TypeMatcher().having( + (e) => e.unrecognizedKeys, 'unrecognizedKeys', [ + 'unsupported' + ]).having((e) => e.allowedKeys, 'allowedKeys', + unorderedEquals(_validConfig.keys)); + + expect( + () => jsonSerializable(const BuilderOptions({'unsupported': 'config'})), + throwsA(matcher)); }); group('invalid config', () { diff --git a/json_serializable/tool/build.dart b/json_serializable/tool/build.dart index df714eba8..6b3407164 100755 --- a/json_serializable/tool/build.dart +++ b/json_serializable/tool/build.dart @@ -58,6 +58,11 @@ final List builders = [ 'test/integration/json_test_example.dart', 'test/integration/json_test_example.non_nullable.dart', ])), + applyToRoot(_jsonPartBuilder(), + generateFor: const InputSet(include: [ + 'lib/src/generator_config.dart', + ]), + hideOutput: true), applyToRoot(_jsonPartBuilder(), generateFor: const InputSet( include: [ From bfb1e210d2270f0b93701cb37aad5fd06b811276 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 9 Oct 2018 12:29:52 -0700 Subject: [PATCH 015/569] GeneratorConfig now extends JsonSerializable All values configurable with JsonSerializable as an annotation can now be set in `build.yaml`. --- json_annotation/CHANGELOG.md | 8 ++ .../lib/src/json_serializable.dart | 19 ++-- json_annotation/pubspec.yaml | 2 +- json_serializable/CHANGELOG.md | 3 + json_serializable/README.md | 8 +- json_serializable/lib/src/decode_helper.dart | 6 +- json_serializable/lib/src/encoder_helper.dart | 2 +- .../lib/src/generator_config.dart | 17 ++- .../lib/src/generator_config.g.dart | 47 +++++++- json_serializable/lib/src/helper_core.dart | 21 ++-- .../lib/src/json_serializable_generator.dart | 18 +-- .../lib/src/type_helpers/json_helper.dart | 14 +-- json_serializable/lib/src/utils.dart | 56 +++++++--- json_serializable/pubspec.yaml | 6 +- json_serializable/test/config_test.dart | 72 +++++++++--- .../test/json_serializable_test.dart | 105 +++++++++++++++++- json_serializable/test/shared_config.dart | 33 ++++++ .../src/_json_serializable_test_input.dart | 1 + .../test/src/configuration_input.dart | 28 +++++ 19 files changed, 385 insertions(+), 81 deletions(-) create mode 100644 json_serializable/test/shared_config.dart create mode 100644 json_serializable/test/src/configuration_input.dart diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index dca043d1b..2f4c69768 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -1,3 +1,11 @@ +## 2.0.0 + +* **Potentially Breaking** `JsonSerializable` no longer sets default values for + fields when constructor arguments are unset or `null`. This is not likely an + issue for developers using this class as an annotation with a compatible + version of `package:json_serializable`, but it may cause issues if class is + used in other contexts. + ## 1.2.0 * Added `JsonConverter` class to support custom conversion of types. diff --git a/json_annotation/lib/src/json_serializable.dart b/json_annotation/lib/src/json_serializable.dart index 92447efa5..b962ee078 100644 --- a/json_annotation/lib/src/json_serializable.dart +++ b/json_annotation/lib/src/json_serializable.dart @@ -98,18 +98,13 @@ class JsonSerializable { /// Creates a new [JsonSerializable] instance. const JsonSerializable({ - bool disallowUnrecognizedKeys = false, - bool createFactory = true, - bool createToJson = true, - bool includeIfNull = true, - bool nullable = true, - FieldRename fieldRename = FieldRename.none, - }) : this.disallowUnrecognizedKeys = disallowUnrecognizedKeys ?? false, - this.createFactory = createFactory ?? true, - this.createToJson = createToJson ?? true, - this.includeIfNull = includeIfNull ?? true, - this.nullable = nullable ?? true, - this.fieldRename = fieldRename ?? FieldRename.none; + this.disallowUnrecognizedKeys, + this.createFactory, + this.createToJson, + this.includeIfNull, + this.nullable, + this.fieldRename, + }); } /// An annotation used to specify how a field is serialized. diff --git a/json_annotation/pubspec.yaml b/json_annotation/pubspec.yaml index 59d14190a..04ef24b84 100644 --- a/json_annotation/pubspec.yaml +++ b/json_annotation/pubspec.yaml @@ -1,5 +1,5 @@ name: json_annotation -version: 1.2.0 +version: 2.0.0-dev description: >- Classes and helper functions that support JSON code generation via the `json_serializable` package. diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 4544506ce..a9a871890 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -2,6 +2,9 @@ * Build configuration + * You can now configure all settings exposed by the `JsonSerializable` + annotation within `build.yaml`. + * **BREAKING** Unsupported options defined in `build.yaml` will cause exceptions instead of being logged and ignored. diff --git a/json_serializable/README.md b/json_serializable/README.md index 67de947c5..8839e6214 100644 --- a/json_serializable/README.md +++ b/json_serializable/README.md @@ -74,11 +74,17 @@ targets: # # For usage information, reference the corresponding field in # `JsonSerializableGenerator`. - use_wrappers: false any_map: false checked: false + create_factory: true + create_to_json: true + disallow_unrecognized_keys: false explicit_to_json: false + field_rename: none generate_to_json_function: true + include_if_null: true + nullable: true + use_wrappers: false ``` [example]: https://github.com/dart-lang/json_serializable/blob/master/example diff --git a/json_serializable/lib/src/decode_helper.dart b/json_serializable/lib/src/decode_helper.dart index 4d08bea5b..2982d046f 100644 --- a/json_serializable/lib/src/decode_helper.dart +++ b/json_serializable/lib/src/decode_helper.dart @@ -23,7 +23,7 @@ abstract class DecodeHelper implements HelperCore { CreateFactoryResult createFactory(Map accessibleFields, Map unavailableReasons) { - assert(annotation.createFactory); + assert(config.createFactory); assert(_buffer.isEmpty); final mapType = config.anyMap ? 'Map' : 'Map'; @@ -58,7 +58,7 @@ abstract class DecodeHelper implements HelperCore { _writeChecks( 6, - annotation, + config, accessibleFields.values .where((fe) => data.usedCtorParamsAndFields.contains(fe.name))); _buffer.write(''' @@ -106,7 +106,7 @@ abstract class DecodeHelper implements HelperCore { _writeChecks( 2, - annotation, + config, accessibleFields.values .where((fe) => data.usedCtorParamsAndFields.contains(fe.name))); diff --git a/json_serializable/lib/src/encoder_helper.dart b/json_serializable/lib/src/encoder_helper.dart index c7e8db0de..d2b5166f8 100644 --- a/json_serializable/lib/src/encoder_helper.dart +++ b/json_serializable/lib/src/encoder_helper.dart @@ -25,7 +25,7 @@ abstract class EncodeHelper implements HelperCore { '${prefix}JsonMapWrapper${genericClassArgumentsImpl(withConstraints)}'; Iterable createToJson(Set accessibleFields) sync* { - assert(annotation.createToJson); + assert(config.createToJson); final buffer = StringBuffer(); diff --git a/json_serializable/lib/src/generator_config.dart b/json_serializable/lib/src/generator_config.dart index d2f79d624..717c3f538 100644 --- a/json_serializable/lib/src/generator_config.dart +++ b/json_serializable/lib/src/generator_config.dart @@ -11,7 +11,7 @@ part 'generator_config.g.dart'; /// Represents the configuration for [JsonSerializableGenerator]. @JsonSerializable( disallowUnrecognizedKeys: true, fieldRename: FieldRename.snake) -class GeneratorConfig { +class GeneratorConfig extends JsonSerializable { /// If `true`, [Map] types are *not* assumed to be [Map] /// – which is the default type of [Map] instances return by JSON decode in /// `dart:convert`. @@ -89,11 +89,24 @@ class GeneratorConfig { bool explicitToJson = false, bool generateToJsonFunction = true, bool useWrappers = false, + bool disallowUnrecognizedKeys = false, + bool createFactory = true, + bool createToJson = true, + bool includeIfNull = true, + bool nullable = true, + FieldRename fieldRename = FieldRename.none, }) : this.anyMap = anyMap ?? false, this.checked = checked ?? false, this.explicitToJson = explicitToJson ?? false, this.generateToJsonFunction = generateToJsonFunction ?? true, - this.useWrappers = useWrappers ?? false; + this.useWrappers = useWrappers ?? false, + super( + disallowUnrecognizedKeys: disallowUnrecognizedKeys ?? false, + createFactory: createFactory ?? true, + createToJson: createToJson ?? true, + includeIfNull: includeIfNull ?? true, + nullable: nullable ?? true, + fieldRename: fieldRename ?? FieldRename.none); factory GeneratorConfig.fromJson(Map json) => _$GeneratorConfigFromJson(json); diff --git a/json_serializable/lib/src/generator_config.g.dart b/json_serializable/lib/src/generator_config.g.dart index e9fc890f3..ea930391b 100644 --- a/json_serializable/lib/src/generator_config.g.dart +++ b/json_serializable/lib/src/generator_config.g.dart @@ -8,6 +8,12 @@ part of 'generator_config.dart'; GeneratorConfig _$GeneratorConfigFromJson(Map json) { $checkKeys(json, allowedKeys: const [ + 'disallow_unrecognized_keys', + 'create_factory', + 'create_to_json', + 'include_if_null', + 'nullable', + 'field_rename', 'any_map', 'use_wrappers', 'checked', @@ -19,14 +25,53 @@ GeneratorConfig _$GeneratorConfigFromJson(Map json) { checked: json['checked'] as bool, explicitToJson: json['explicit_to_json'] as bool, generateToJsonFunction: json['generate_to_json_function'] as bool, - useWrappers: json['use_wrappers'] as bool); + useWrappers: json['use_wrappers'] as bool, + disallowUnrecognizedKeys: json['disallow_unrecognized_keys'] as bool, + createFactory: json['create_factory'] as bool, + createToJson: json['create_to_json'] as bool, + includeIfNull: json['include_if_null'] as bool, + nullable: json['nullable'] as bool, + fieldRename: + _$enumDecodeNullable(_$FieldRenameEnumMap, json['field_rename'])); } Map _$GeneratorConfigToJson(GeneratorConfig instance) => { + 'disallow_unrecognized_keys': instance.disallowUnrecognizedKeys, + 'create_factory': instance.createFactory, + 'create_to_json': instance.createToJson, + 'include_if_null': instance.includeIfNull, + 'nullable': instance.nullable, + 'field_rename': _$FieldRenameEnumMap[instance.fieldRename], 'any_map': instance.anyMap, 'use_wrappers': instance.useWrappers, 'checked': instance.checked, 'explicit_to_json': instance.explicitToJson, 'generate_to_json_function': instance.generateToJsonFunction }; + +T _$enumDecode(Map enumValues, dynamic source) { + if (source == null) { + throw ArgumentError('A value must be provided. Supported values: ' + '${enumValues.values.join(', ')}'); + } + return enumValues.entries + .singleWhere((e) => e.value == source, + orElse: () => throw ArgumentError( + '`$source` is not one of the supported values: ' + '${enumValues.values.join(', ')}')) + .key; +} + +T _$enumDecodeNullable(Map enumValues, dynamic source) { + if (source == null) { + return null; + } + return _$enumDecode(enumValues, source); +} + +const _$FieldRenameEnumMap = { + FieldRename.none: 'none', + FieldRename.kebab: 'kebab', + FieldRename.snake: 'snake' +}; diff --git a/json_serializable/lib/src/helper_core.dart b/json_serializable/lib/src/helper_core.dart index 7c695122c..714b7aefe 100644 --- a/json_serializable/lib/src/helper_core.dart +++ b/json_serializable/lib/src/helper_core.dart @@ -10,47 +10,46 @@ import 'package:source_gen/source_gen.dart'; import 'generator_config.dart'; import 'json_key_utils.dart'; -import 'json_serializable_generator.dart'; import 'type_helper.dart'; import 'type_helper_ctx.dart'; import 'utils.dart'; abstract class HelperCore { - @protected - final JsonSerializable annotation; - - @protected - final JsonSerializableGenerator generator; - final ClassElement element; + final GeneratorConfig config; - GeneratorConfig get config => generator.config; + HelperCore(this.element, this.config); Iterable get allTypeHelpers; - HelperCore(this.generator, this.element, this.annotation); - void addMember(String memberContent); + @protected String get targetClassReference => '${element.name}${genericClassArgumentsImpl(false)}'; + @protected String nameAccess(FieldElement field) => jsonKeyFor(field).name; + @protected String safeNameAccess(FieldElement field) => escapeDartString(nameAccess(field)); + @protected String get prefix => '_\$${element.name}'; /// Returns a [String] representing the type arguments that exist on /// [element]. /// /// Returns the output of calling [genericClassArguments] with [element]. + @protected String genericClassArgumentsImpl(bool withConstraints) => genericClassArguments(element, withConstraints); - JsonKey jsonKeyFor(FieldElement field) => jsonKeyForField(field, annotation); + @protected + JsonKey jsonKeyFor(FieldElement field) => jsonKeyForField(field, config); + @protected TypeHelperContext getHelperContext(FieldElement field) => typeHelperContext(this, field, jsonKeyFor(field)); } diff --git a/json_serializable/lib/src/json_serializable_generator.dart b/json_serializable/lib/src/json_serializable_generator.dart index 9e2a2a85f..ba34f631b 100644 --- a/json_serializable/lib/src/json_serializable_generator.dart +++ b/json_serializable/lib/src/json_serializable_generator.dart @@ -84,26 +84,26 @@ class JsonSerializableGenerator } final classElement = element as ClassElement; - final classAnnotation = valueForAnnotation(annotation); - final helper = _GeneratorHelper(this, classElement, classAnnotation); + final helper = _GeneratorHelper(this, classElement, annotation); return helper._generate(); } } class _GeneratorHelper extends HelperCore with EncodeHelper, DecodeHelper { - _GeneratorHelper(JsonSerializableGenerator generator, ClassElement element, - JsonSerializable annotation) - : super(generator, element, annotation); - + final JsonSerializableGenerator _generator; final _addedMembers = Set(); + _GeneratorHelper( + this._generator, ClassElement element, ConstantReader annotation) + : super(element, mergeConfig(_generator.config, annotation)); + @override void addMember(String memberContent) { _addedMembers.add(memberContent); } @override - Iterable get allTypeHelpers => generator._allHelpers; + Iterable get allTypeHelpers => _generator._allHelpers; Iterable _generate() sync* { assert(_addedMembers.isEmpty); @@ -134,7 +134,7 @@ class _GeneratorHelper extends HelperCore with EncodeHelper, DecodeHelper { }); var accessibleFieldSet = accessibleFields.values.toSet(); - if (annotation.createFactory) { + if (config.createFactory) { final createResult = createFactory(accessibleFields, unavailableReasons); yield createResult.output; @@ -158,7 +158,7 @@ class _GeneratorHelper extends HelperCore with EncodeHelper, DecodeHelper { return set; }); - if (annotation.createToJson) { + if (config.createToJson) { yield* createToJson(accessibleFieldSet); } diff --git a/json_serializable/lib/src/type_helpers/json_helper.dart b/json_serializable/lib/src/type_helpers/json_helper.dart index ac8687fd3..33b9e82e4 100644 --- a/json_serializable/lib/src/type_helpers/json_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_helper.dart @@ -4,10 +4,10 @@ import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/type.dart'; - import 'package:json_annotation/json_annotation.dart'; import 'package:source_gen/source_gen.dart'; +import '../generator_config.dart'; import '../shared_checkers.dart'; import '../type_helper.dart'; import '../utils.dart'; @@ -22,7 +22,7 @@ class JsonHelper extends TypeHelper { @override String serialize(DartType targetType, String expression, TypeHelperContextWithConfig context) { - if (!_canSerialize(targetType)) { + if (!_canSerialize(context.config, targetType)) { return null; } @@ -50,7 +50,7 @@ class JsonHelper extends TypeHelper { // TODO: should verify that this type is a valid JSON type final asCastType = fromJsonCtor.parameters.first.type; asCast = asStatement(asCastType); - } else if (_annotation(type)?.createFactory == true) { + } else if (_annotation(context.config, type)?.createFactory == true) { if (context.config.anyMap) { asCast = ' as Map'; } else { @@ -68,7 +68,7 @@ class JsonHelper extends TypeHelper { } } -bool _canSerialize(DartType type) { +bool _canSerialize(GeneratorConfig config, DartType type) { if (type is InterfaceType) { final toJsonMethod = _toJsonMethod(type); @@ -77,7 +77,7 @@ bool _canSerialize(DartType type) { return true; } - if (_annotation(type)?.createToJson == true) { + if (_annotation(config, type)?.createToJson == true) { // TODO: consider logging that we're assuming a user will wire up the // generated mixin at some point... return true; @@ -86,7 +86,7 @@ bool _canSerialize(DartType type) { return false; } -JsonSerializable _annotation(InterfaceType source) { +JsonSerializable _annotation(GeneratorConfig config, InterfaceType source) { final annotations = const TypeChecker.fromRuntime(JsonSerializable) .annotationsOfExact(source.element, throwOnUnresolved: false) .toList(); @@ -95,7 +95,7 @@ JsonSerializable _annotation(InterfaceType source) { return null; } - return valueForAnnotation(ConstantReader(annotations.single)); + return mergeConfig(config, ConstantReader(annotations.single)); } MethodElement _toJsonMethod(DartType type) => typeImplementations(type) diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index e4ef6026e..657d3da74 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -2,14 +2,15 @@ // 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:analyzer/dart/constant/value.dart'; import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/type.dart'; -import 'package:analyzer/dart/constant/value.dart'; - import 'package:json_annotation/json_annotation.dart'; import 'package:meta/meta.dart' show alwaysThrows; import 'package:source_gen/source_gen.dart'; +import 'generator_config.dart'; + final _jsonKeyChecker = const TypeChecker.fromRuntime(JsonKey); DartObject jsonKeyAnnotation(FieldElement element) => @@ -25,6 +26,7 @@ bool hasJsonKeyAnnotation(FieldElement element) => final _upperCase = RegExp('[A-Z]'); String kebabCase(String input) => _fixCase(input, '-'); + String snakeCase(String input) => _fixCase(input, '_'); String _fixCase(String input, String seperator) => @@ -44,18 +46,44 @@ void throwUnsupported(FieldElement element, String message) => 'Error with `@JsonKey` on `${element.name}`. $message', element: element); -FieldRename _fromDartObject(ConstantReader reader) => - FieldRename.values[reader.objectValue.getField('index').toIntValue()]; - -JsonSerializable valueForAnnotation(ConstantReader annotation) => - JsonSerializable( - disallowUnrecognizedKeys: - annotation.read('disallowUnrecognizedKeys').boolValue, - createToJson: annotation.read('createToJson').boolValue, - createFactory: annotation.read('createFactory').boolValue, - nullable: annotation.read('nullable').boolValue, - includeIfNull: annotation.read('includeIfNull').boolValue, - fieldRename: _fromDartObject(annotation.read('fieldRename'))); +FieldRename _fromDartObject(ConstantReader reader) => reader.isNull + ? null + : FieldRename.values[reader.objectValue.getField('index').toIntValue()]; + +/// Return an instance of [JsonSerializable] corresponding to a the provided +/// [reader]. +JsonSerializable _valueForAnnotation(ConstantReader reader) => JsonSerializable( + disallowUnrecognizedKeys: + reader.read('disallowUnrecognizedKeys').literalValue as bool, + createToJson: reader.read('createToJson').literalValue as bool, + createFactory: reader.read('createFactory').literalValue as bool, + nullable: reader.read('nullable').literalValue as bool, + includeIfNull: reader.read('includeIfNull').literalValue as bool, + fieldRename: _fromDartObject(reader.read('fieldRename'))); + +/// Returns a [GeneratorConfig] with values from the [JsonSerializable] instance +/// represented by [reader]. +/// +/// For fields that are not defined in [JsonSerializable] or `null` in [reader], +/// use the values in [config]. +GeneratorConfig mergeConfig(GeneratorConfig config, ConstantReader reader) { + var annotation = _valueForAnnotation(reader); + + return GeneratorConfig( + anyMap: config.anyMap, + checked: config.checked, + createFactory: annotation.createFactory ?? config.createFactory, + createToJson: annotation.createToJson ?? config.createToJson, + disallowUnrecognizedKeys: + annotation.disallowUnrecognizedKeys ?? config.disallowUnrecognizedKeys, + explicitToJson: config.explicitToJson, + fieldRename: annotation.fieldRename ?? config.fieldRename, + generateToJsonFunction: config.generateToJsonFunction, + includeIfNull: annotation.includeIfNull ?? config.includeIfNull, + nullable: annotation.nullable ?? config.nullable, + useWrappers: config.useWrappers, + ); +} bool isEnum(DartType targetType) => targetType is InterfaceType && targetType.element.isEnum; diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 923723152..a07876a8f 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -13,7 +13,7 @@ dependencies: # Use a tight version constraint to ensure that a constraint on # `json_annotation`. Properly constrains all features it provides. - json_annotation: '>=1.2.0 <1.3.0' + json_annotation: '>=2.0.0 <2.1.0' meta: ^1.1.0 path: ^1.3.2 source_gen: ^0.9.0 @@ -29,3 +29,7 @@ dev_dependencies: logging: ^0.11.3+1 test: ^1.3.3 yaml: ^2.1.13 + +dependency_overrides: + json_annotation: + path: ../json_annotation diff --git a/json_serializable/test/config_test.dart b/json_serializable/test/config_test.dart index 7bcf3fd17..ec526f062 100644 --- a/json_serializable/test/config_test.dart +++ b/json_serializable/test/config_test.dart @@ -8,9 +8,11 @@ import 'dart:io'; import 'package:build/build.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:json_serializable/builder.dart'; +import 'package:json_serializable/src/generator_config.dart'; import 'package:test/test.dart'; import 'package:yaml/yaml.dart'; +import 'shared_config.dart'; import 'test_utils.dart'; void main() { @@ -19,11 +21,35 @@ void main() { expect(builder, isNotNull); }); - test('valid config', () async { - final builder = jsonSerializable(const BuilderOptions(_validConfig)); + test('valid default config', () async { + final builder = + jsonSerializable(BuilderOptions(generatorConfigDefaultJson)); expect(builder, isNotNull); }); + test('valid, non-default config', () { + expect(generatorConfigNonDefaultJson.keys, + unorderedEquals(generatorConfigDefaultJson.keys)); + + for (var entry in generatorConfigDefaultJson.entries) { + expect(generatorConfigNonDefaultJson, + containsPair(entry.key, isNot(entry.value)), + reason: 'should have values that are different than the defaults'); + } + + final builder = + jsonSerializable(BuilderOptions(generatorConfigNonDefaultJson)); + expect(builder, isNotNull); + }); + + test('config is null-protected', () { + var nullValueMap = Map.fromEntries( + generatorConfigDefaultJson.entries.map((e) => MapEntry(e.key, null))); + + var config = GeneratorConfig.fromJson(nullValueMap); + expect(config.toJson(), generatorConfigDefaultJson); + }); + test('readme config', () async { final configExampleContent = File('README.md') .readAsLinesSync() @@ -44,11 +70,16 @@ void main() { yaml = yaml[key] as YamlMap; } - final config = Map.from(yaml); + final configMap = Map.from(yaml); + + expect(configMap.keys, unorderedEquals(generatorConfigDefaultJson.keys), + reason: 'All supported keys are documented.'); - expect(config.keys, unorderedEquals(_validConfig.keys)); + expect(GeneratorConfig.fromJson(configMap).toJson(), + generatorConfigDefaultJson, + reason: 'All keys specify their default value.'); - final builder = jsonSerializable(BuilderOptions(config)); + final builder = jsonSerializable(BuilderOptions(configMap)); expect(builder, isNotNull); }); @@ -57,7 +88,7 @@ void main() { (e) => e.unrecognizedKeys, 'unrecognizedKeys', [ 'unsupported' ]).having((e) => e.allowedKeys, 'allowedKeys', - unorderedEquals(_validConfig.keys)); + unorderedEquals(generatorConfigDefaultJson.keys)); expect( () => jsonSerializable(const BuilderOptions({'unsupported': 'config'})), @@ -65,28 +96,35 @@ void main() { }); group('invalid config', () { + test('validated for all supported keys', () { + expect(_invalidConfig.keys, generatorConfigDefaultJson.keys); + }); for (final entry in _invalidConfig.entries) { test(entry.key, () { - final config = Map.from(_validConfig); + final config = Map.from(generatorConfigDefaultJson); config[entry.key] = entry.value; - expect(() => jsonSerializable(BuilderOptions(config)), throwsCastError); + var matcher = (entry.key == 'field_rename') + ? isArgumentError.having((e) => e.message, 'message', + '`42` is not one of the supported values: none, kebab, snake') + : isCastError; + + expect( + () => jsonSerializable(BuilderOptions(config)), throwsA(matcher)); }); } }); } -const _validConfig = { - 'use_wrappers': true, - 'any_map': true, - 'checked': true, - 'explicit_to_json': true, - 'generate_to_json_function': false, -}; - const _invalidConfig = { - 'use_wrappers': 42, + 'disallow_unrecognized_keys': 42, + 'create_factory': 42, + 'create_to_json': 42, + 'include_if_null': 42, + 'nullable': 42, + 'field_rename': 42, 'any_map': 42, + 'use_wrappers': 42, 'checked': 42, 'explicit_to_json': 42, 'generate_to_json_function': 42, diff --git a/json_serializable/test/json_serializable_test.dart b/json_serializable/test/json_serializable_test.dart index f02b8edd3..cda5c55f4 100644 --- a/json_serializable/test/json_serializable_test.dart +++ b/json_serializable/test/json_serializable_test.dart @@ -5,14 +5,17 @@ @TestOn('vm') import 'dart:async'; +import 'package:analyzer/dart/element/type.dart'; import 'package:build/build.dart'; import 'package:dart_style/dart_style.dart' as dart_style; import 'package:json_serializable/json_serializable.dart'; import 'package:json_serializable/src/constants.dart'; +import 'package:json_serializable/src/type_helper.dart'; import 'package:source_gen/source_gen.dart'; import 'package:test/test.dart'; import 'analysis_utils.dart'; +import 'shared_config.dart'; import 'test_file_utils.dart'; Matcher _matcherFromShouldGenerateAnnotation(ConstantReader reader, @@ -176,6 +179,81 @@ void main() async { }); group('with wrapper', () => _registerTests(const GeneratorConfig(useWrappers: true))); + + group('configuration', () { + void runWithConfigAndLogger(GeneratorConfig config, String className) { + _runForElementNamedWithGenerator( + JsonSerializableGenerator( + config: config, typeHelpers: const [_ConfigLogger()]), + className); + } + + setUp(_ConfigLogger.configurations.clear); + + group('defaults', () { + for (var className in [ + 'ConfigurationImplicitDefaults', + 'ConfigurationExplicitDefaults', + ]) { + for (var nullConfig in [true, false]) { + var testDescription = + '$className with ${nullConfig ? 'null' : 'default'} config'; + + test(testDescription, () { + runWithConfigAndLogger( + nullConfig ? null : const GeneratorConfig(), className); + + expect(_ConfigLogger.configurations, hasLength(2)); + expect(_ConfigLogger.configurations.first, + same(_ConfigLogger.configurations.last)); + expect(_ConfigLogger.configurations.first.toJson(), + generatorConfigDefaultJson); + }); + } + } + }); + + test( + 'values in config override unconfigured (default) values in annotation', + () { + runWithConfigAndLogger( + GeneratorConfig.fromJson(generatorConfigNonDefaultJson), + 'ConfigurationImplicitDefaults'); + + expect(_ConfigLogger.configurations, isEmpty, + reason: 'all generation is disabled'); + + // Create a configuration with just `create_to_json` set to true so we + // can validate the configuration that is run with + var configMap = Map.from(generatorConfigNonDefaultJson); + configMap['create_to_json'] = true; + + runWithConfigAndLogger( + GeneratorConfig.fromJson(configMap), 'ConfigurationImplicitDefaults'); + }); + + test( + 'explicit values in annotation override corresponding settings in config', + () { + runWithConfigAndLogger( + GeneratorConfig.fromJson(generatorConfigNonDefaultJson), + 'ConfigurationExplicitDefaults'); + + expect(_ConfigLogger.configurations, hasLength(2)); + expect(_ConfigLogger.configurations.first, + same(_ConfigLogger.configurations.last)); + + // The effective configuration should be non-Default configuration, but + // with all fields set from JsonSerializable as the defaults + + var expected = Map.from(generatorConfigNonDefaultJson); + for (var jsonSerialKey in jsonSerializableFields) { + expected[jsonSerialKey] = generatorConfigDefaultJson[jsonSerialKey]; + } + + expect(_ConfigLogger.configurations.first.toJson(), expected); + }); + }); } void _testAnnotatedClass(AnnotatedElement annotatedElement) { @@ -254,8 +332,13 @@ void _testShouldGenerate(AnnotatedElement annotatedElement) { } String _runForElementNamed(GeneratorConfig config, String name) { - final element = _library.allElements.singleWhere((e) => e.name == name); final generator = JsonSerializableGenerator(config: config); + return _runForElementNamedWithGenerator(generator, name); +} + +String _runForElementNamedWithGenerator( + JsonSerializableGenerator generator, String name) { + final element = _library.allElements.singleWhere((e) => e.name == name); final annotation = generator.typeChecker.firstAnnotationOf(element); final generated = generator .generateForAnnotatedElement(element, ConstantReader(annotation), null) @@ -538,3 +621,23 @@ Map _$TrivialNestedNonNullableToJson( 'The class `NoCtorClass` has no default constructor.')); }); } + +class _ConfigLogger implements TypeHelper { + static final configurations = []; + + const _ConfigLogger(); + + @override + Object deserialize(DartType targetType, String expression, + TypeHelperContextWithConfig context) { + configurations.add(context.config); + return null; + } + + @override + Object serialize(DartType targetType, String expression, + TypeHelperContextWithConfig context) { + configurations.add(context.config); + return null; + } +} diff --git a/json_serializable/test/shared_config.dart b/json_serializable/test/shared_config.dart new file mode 100644 index 000000000..29b0db483 --- /dev/null +++ b/json_serializable/test/shared_config.dart @@ -0,0 +1,33 @@ +// Copyright (c) 2018, 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:json_annotation/json_annotation.dart'; +import 'package:json_serializable/src/generator_config.dart'; + +const jsonSerializableFields = [ + 'create_factory', + 'create_to_json', + 'disallow_unrecognized_keys', + 'include_if_null', + 'nullable', + 'field_rename', +]; + +final generatorConfigDefaultJson = + Map.unmodifiable(const GeneratorConfig().toJson()); + +final generatorConfigNonDefaultJson = Map.unmodifiable( + const GeneratorConfig( + createFactory: false, + fieldRename: FieldRename.kebab, + disallowUnrecognizedKeys: true, + nullable: false, + includeIfNull: false, + createToJson: false, + useWrappers: true, + explicitToJson: true, + generateToJsonFunction: false, + checked: true, + anyMap: true) + .toJson()); diff --git a/json_serializable/test/src/_json_serializable_test_input.dart b/json_serializable/test/src/_json_serializable_test_input.dart index 0707aff73..e4fbc9d61 100644 --- a/json_serializable/test/src/_json_serializable_test_input.dart +++ b/json_serializable/test/src/_json_serializable_test_input.dart @@ -8,6 +8,7 @@ import 'package:json_annotation/json_annotation.dart'; import 'annotation.dart'; part 'checked_test_input.dart'; +part 'configuration_input.dart'; part 'default_value_input.dart'; part 'field_namer_input.dart'; part 'generic_test_input.dart'; diff --git a/json_serializable/test/src/configuration_input.dart b/json_serializable/test/src/configuration_input.dart new file mode 100644 index 000000000..c7d17f722 --- /dev/null +++ b/json_serializable/test/src/configuration_input.dart @@ -0,0 +1,28 @@ +part of '_json_serializable_test_input.dart'; + +@JsonSerializable() +class ConfigurationImplicitDefaults { + int field; +} + +@JsonSerializable( + createToJson: true, + includeIfNull: true, + nullable: true, + disallowUnrecognizedKeys: false, + fieldRename: FieldRename.none, + createFactory: true) +class ConfigurationExplicitDefaults { + int field; +} + +@JsonSerializable( + createToJson: true, + includeIfNull: true, + nullable: true, + disallowUnrecognizedKeys: true, + fieldRename: FieldRename.snake, + createFactory: true) +class ConfigurationAllDefaultsOpposite { + int field; +} From 742b0ed434d35add04714cbe1ae28f539bf0e268 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 10 Oct 2018 14:30:32 -0700 Subject: [PATCH 016/569] Fix new instances of unnecessary_this in latest SDK (#346) Also fixed a number of prefer_final_locals outside of the example pkg --- example/lib/example.dart | 2 +- json_annotation/lib/src/json_literal.dart | 2 +- json_serializable/lib/builder.dart | 2 +- .../lib/src/generator_config.dart | 10 +++++----- .../lib/src/json_serializable_generator.dart | 4 ++-- json_serializable/lib/src/type_helper_ctx.dart | 18 +++++++++--------- .../type_helpers/json_converter_helper.dart | 4 ++-- json_serializable/lib/src/utils.dart | 2 +- json_serializable/test/config_test.dart | 8 ++++---- .../test/integration/json_test_example.dart | 2 +- .../json_test_example.non_nullable.dart | 2 +- ...json_test_example.non_nullable.wrapped.dart | 2 +- .../integration/json_test_example.wrapped.dart | 2 +- .../test/json_serializable_test.dart | 7 ++++--- .../src/_json_serializable_test_input.dart | 5 ++--- 15 files changed, 36 insertions(+), 36 deletions(-) diff --git a/example/lib/example.dart b/example/lib/example.dart index 38b745991..77e010c1f 100644 --- a/example/lib/example.dart +++ b/example/lib/example.dart @@ -23,7 +23,7 @@ class Person { Person(this.firstName, this.lastName, this.dateOfBirth, {this.middleName, this.lastOrder, List orders}) - : this.orders = orders ?? []; + : orders = orders ?? []; factory Person.fromJson(Map json) => _$PersonFromJson(json); diff --git a/json_annotation/lib/src/json_literal.dart b/json_annotation/lib/src/json_literal.dart index 2e4b5da69..06551d62a 100644 --- a/json_annotation/lib/src/json_literal.dart +++ b/json_annotation/lib/src/json_literal.dart @@ -25,5 +25,5 @@ class JsonLiteral { /// Creates a new [JsonLiteral] instance. const JsonLiteral(this.path, {bool asConst = false}) - : this.asConst = asConst ?? false; + : asConst = asConst ?? false; } diff --git a/json_serializable/lib/builder.dart b/json_serializable/lib/builder.dart index 52295328e..df78b4292 100644 --- a/json_serializable/lib/builder.dart +++ b/json_serializable/lib/builder.dart @@ -22,6 +22,6 @@ import 'src/json_part_builder.dart'; /// /// Not meant to be invoked by hand-authored code. Builder jsonSerializable(BuilderOptions options) { - var config = GeneratorConfig.fromJson(options.config); + final config = GeneratorConfig.fromJson(options.config); return jsonPartBuilder(config: config); } diff --git a/json_serializable/lib/src/generator_config.dart b/json_serializable/lib/src/generator_config.dart index 717c3f538..f9f5a71a5 100644 --- a/json_serializable/lib/src/generator_config.dart +++ b/json_serializable/lib/src/generator_config.dart @@ -95,11 +95,11 @@ class GeneratorConfig extends JsonSerializable { bool includeIfNull = true, bool nullable = true, FieldRename fieldRename = FieldRename.none, - }) : this.anyMap = anyMap ?? false, - this.checked = checked ?? false, - this.explicitToJson = explicitToJson ?? false, - this.generateToJsonFunction = generateToJsonFunction ?? true, - this.useWrappers = useWrappers ?? false, + }) : anyMap = anyMap ?? false, + checked = checked ?? false, + explicitToJson = explicitToJson ?? false, + generateToJsonFunction = generateToJsonFunction ?? true, + useWrappers = useWrappers ?? false, super( disallowUnrecognizedKeys: disallowUnrecognizedKeys ?? false, createFactory: createFactory ?? true, diff --git a/json_serializable/lib/src/json_serializable_generator.dart b/json_serializable/lib/src/json_serializable_generator.dart index ba34f631b..5ce134765 100644 --- a/json_serializable/lib/src/json_serializable_generator.dart +++ b/json_serializable/lib/src/json_serializable_generator.dart @@ -57,8 +57,8 @@ class JsonSerializableGenerator const JsonSerializableGenerator({ GeneratorConfig config, List typeHelpers, - }) : this.config = config ?? const GeneratorConfig(), - this._typeHelpers = typeHelpers ?? _defaultHelpers; + }) : config = config ?? const GeneratorConfig(), + _typeHelpers = typeHelpers ?? _defaultHelpers; /// Creates an instance of [JsonSerializableGenerator]. /// diff --git a/json_serializable/lib/src/type_helper_ctx.dart b/json_serializable/lib/src/type_helper_ctx.dart index 3119e2206..9992c37dc 100644 --- a/json_serializable/lib/src/type_helper_ctx.dart +++ b/json_serializable/lib/src/type_helper_ctx.dart @@ -83,12 +83,12 @@ class _ConvertPair { var pair = _expando[element]; if (pair == null) { - var obj = jsonKeyAnnotation(element); + final obj = jsonKeyAnnotation(element); if (obj == null) { pair = _ConvertPair._(null, null); } else { - var toJson = _convertData(obj, element, false); - var fromJson = _convertData(obj, element, true); + final toJson = _convertData(obj, element, false); + final fromJson = _convertData(obj, element, true); pair = _ConvertPair._(fromJson, toJson); } _expando[element] = pair; @@ -98,16 +98,16 @@ class _ConvertPair { } ConvertData _convertData(DartObject obj, FieldElement element, bool isFrom) { - var paramName = isFrom ? 'fromJson' : 'toJson'; - var objectValue = obj.getField(paramName); + final paramName = isFrom ? 'fromJson' : 'toJson'; + final objectValue = obj.getField(paramName); if (objectValue.isNull) { return null; } - var type = objectValue.type as FunctionType; + final type = objectValue.type as FunctionType; - var executableElement = type.element as ExecutableElement; + final executableElement = type.element as ExecutableElement; if (executableElement.parameters.isEmpty || executableElement.parameters.first.isNamed || @@ -118,9 +118,9 @@ ConvertData _convertData(DartObject obj, FieldElement element, bool isFrom) { 'positional paramater.'); } - var argType = executableElement.parameters.first.type; + final argType = executableElement.parameters.first.type; if (isFrom) { - var returnType = executableElement.returnType; + final returnType = executableElement.returnType; if (returnType is TypeParameterType) { // We keep things simple in this case. We rely on inferred type arguments diff --git a/json_serializable/lib/src/type_helpers/json_converter_helper.dart b/json_serializable/lib/src/type_helpers/json_converter_helper.dart index 0f3b8a3e6..13599b5ce 100644 --- a/json_serializable/lib/src/type_helpers/json_converter_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_converter_helper.dart @@ -49,11 +49,11 @@ class _JsonConvertData { final DartType jsonType; _JsonConvertData.className(String className, String accessor, this.jsonType) - : this.accessString = 'const $className${_withAccessor(accessor)}()'; + : accessString = 'const $className${_withAccessor(accessor)}()'; _JsonConvertData.genericClass( String className, String genericTypeArg, String accessor, this.jsonType) - : this.accessString = + : accessString = '$className<$genericTypeArg>${_withAccessor(accessor)}()'; _JsonConvertData.propertyAccess(this.accessString, this.jsonType); diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index 657d3da74..c4ae5a82c 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -67,7 +67,7 @@ JsonSerializable _valueForAnnotation(ConstantReader reader) => JsonSerializable( /// For fields that are not defined in [JsonSerializable] or `null` in [reader], /// use the values in [config]. GeneratorConfig mergeConfig(GeneratorConfig config, ConstantReader reader) { - var annotation = _valueForAnnotation(reader); + final annotation = _valueForAnnotation(reader); return GeneratorConfig( anyMap: config.anyMap, diff --git a/json_serializable/test/config_test.dart b/json_serializable/test/config_test.dart index ec526f062..80cbe1f0d 100644 --- a/json_serializable/test/config_test.dart +++ b/json_serializable/test/config_test.dart @@ -43,10 +43,10 @@ void main() { }); test('config is null-protected', () { - var nullValueMap = Map.fromEntries( + final nullValueMap = Map.fromEntries( generatorConfigDefaultJson.entries.map((e) => MapEntry(e.key, null))); - var config = GeneratorConfig.fromJson(nullValueMap); + final config = GeneratorConfig.fromJson(nullValueMap); expect(config.toJson(), generatorConfigDefaultJson); }); @@ -84,7 +84,7 @@ void main() { }); test('unsupported configuration', () async { - var matcher = const TypeMatcher().having( + final matcher = const TypeMatcher().having( (e) => e.unrecognizedKeys, 'unrecognizedKeys', [ 'unsupported' ]).having((e) => e.allowedKeys, 'allowedKeys', @@ -104,7 +104,7 @@ void main() { final config = Map.from(generatorConfigDefaultJson); config[entry.key] = entry.value; - var matcher = (entry.key == 'field_rename') + final matcher = (entry.key == 'field_rename') ? isArgumentError.having((e) => e.message, 'message', '`42` is not one of the supported values: none, kebab, snake') : isCastError; diff --git a/json_serializable/test/integration/json_test_example.dart b/json_serializable/test/integration/json_test_example.dart index 6db3b0d7c..e524ebe58 100644 --- a/json_serializable/test/integration/json_test_example.dart +++ b/json_serializable/test/integration/json_test_example.dart @@ -75,7 +75,7 @@ class Order { bool shouldBeCached; Order(this.category, [Iterable items]) - : this.items = UnmodifiableListView( + : items = UnmodifiableListView( List.unmodifiable(items ?? const [])); factory Order.fromJson(Map json) => _$OrderFromJson(json); diff --git a/json_serializable/test/integration/json_test_example.non_nullable.dart b/json_serializable/test/integration/json_test_example.non_nullable.dart index be08014a8..ee86724e4 100644 --- a/json_serializable/test/integration/json_test_example.non_nullable.dart +++ b/json_serializable/test/integration/json_test_example.non_nullable.dart @@ -81,7 +81,7 @@ class Order { bool shouldBeCached; Order(this.category, [Iterable items]) - : this.items = UnmodifiableListView( + : items = UnmodifiableListView( List.unmodifiable(items ?? const [])); factory Order.fromJson(Map json) => _$OrderFromJson(json); diff --git a/json_serializable/test/integration/json_test_example.non_nullable.wrapped.dart b/json_serializable/test/integration/json_test_example.non_nullable.wrapped.dart index e6b7501b8..d0b41ee44 100644 --- a/json_serializable/test/integration/json_test_example.non_nullable.wrapped.dart +++ b/json_serializable/test/integration/json_test_example.non_nullable.wrapped.dart @@ -87,7 +87,7 @@ class Order { bool shouldBeCached; Order(this.category, [Iterable items]) - : this.items = UnmodifiableListView( + : items = UnmodifiableListView( List.unmodifiable(items ?? const [])); factory Order.fromJson(Map json) => _$OrderFromJson(json); diff --git a/json_serializable/test/integration/json_test_example.wrapped.dart b/json_serializable/test/integration/json_test_example.wrapped.dart index 85d6d2976..bdea0ac1c 100644 --- a/json_serializable/test/integration/json_test_example.wrapped.dart +++ b/json_serializable/test/integration/json_test_example.wrapped.dart @@ -81,7 +81,7 @@ class Order { bool shouldBeCached; Order(this.category, [Iterable items]) - : this.items = UnmodifiableListView( + : items = UnmodifiableListView( List.unmodifiable(items ?? const [])); factory Order.fromJson(Map json) => _$OrderFromJson(json); diff --git a/json_serializable/test/json_serializable_test.dart b/json_serializable/test/json_serializable_test.dart index cda5c55f4..978c20a16 100644 --- a/json_serializable/test/json_serializable_test.dart +++ b/json_serializable/test/json_serializable_test.dart @@ -196,7 +196,7 @@ void main() async { 'ConfigurationExplicitDefaults', ]) { for (var nullConfig in [true, false]) { - var testDescription = + final testDescription = '$className with ${nullConfig ? 'null' : 'default'} config'; test(testDescription, () { @@ -225,7 +225,8 @@ void main() async { // Create a configuration with just `create_to_json` set to true so we // can validate the configuration that is run with - var configMap = Map.from(generatorConfigNonDefaultJson); + final configMap = + Map.from(generatorConfigNonDefaultJson); configMap['create_to_json'] = true; runWithConfigAndLogger( @@ -246,7 +247,7 @@ void main() async { // The effective configuration should be non-Default configuration, but // with all fields set from JsonSerializable as the defaults - var expected = Map.from(generatorConfigNonDefaultJson); + final expected = Map.from(generatorConfigNonDefaultJson); for (var jsonSerialKey in jsonSerializableFields) { expected[jsonSerialKey] = generatorConfigDefaultJson[jsonSerialKey]; } diff --git a/json_serializable/test/src/_json_serializable_test_input.dart b/json_serializable/test/src/_json_serializable_test_input.dart index e4fbc9d61..a506e2bdd 100644 --- a/json_serializable/test/src/_json_serializable_test_input.dart +++ b/json_serializable/test/src/_json_serializable_test_input.dart @@ -85,8 +85,7 @@ class Order { int height; DateTime dateOfBirth; - Order(this.height, String firstName, [this.lastName]) - : this.firstName = firstName; + Order(this.height, String firstName, [this.lastName]) : firstName = firstName; } @ShouldGenerate(r''' @@ -180,7 +179,7 @@ class UnknownCtorParamType { int number; // ignore: undefined_class, field_initializer_not_assignable - UnknownCtorParamType(Bob number) : this.number = number; + UnknownCtorParamType(Bob number) : number = number; } @JsonSerializable() From d798d38e61595d3d423db346f3b66f89e3286429 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 10 Oct 2018 15:35:14 -0700 Subject: [PATCH 017/569] Support all builder configuration via class annotation (#345) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Eliminate the (never-published) GeneratorConfig class All builder and class configuration is now centralized in JsonSerializable Also removed the custom `tool/build.dart` file – all configured via build.yaml now --- json_annotation/CHANGELOG.md | 14 +- .../lib/src/json_serializable.dart | 153 ++++++++++++++++-- .../lib/src/json_serializable.g.dart | 36 ++--- json_serializable/CHANGELOG.md | 8 +- json_serializable/build.yaml | 52 +++++- json_serializable/lib/builder.dart | 4 +- json_serializable/lib/json_serializable.dart | 1 - json_serializable/lib/src/encoder_helper.dart | 4 +- .../lib/src/generator_config.dart | 115 ------------- json_serializable/lib/src/helper_core.dart | 3 +- .../lib/src/json_part_builder.dart | 4 +- .../lib/src/json_serializable_generator.dart | 11 +- json_serializable/lib/src/type_helper.dart | 6 +- .../lib/src/type_helper_ctx.dart | 3 +- .../lib/src/type_helpers/json_helper.dart | 5 +- json_serializable/lib/src/utils.dart | 42 ++--- json_serializable/pubspec.yaml | 1 - json_serializable/test/config_test.dart | 29 ++-- .../default_value/default_value.checked.dart | 5 +- json_serializable/test/ensure_build_test.dart | 14 +- .../generic_files/generic_class.wrapped.dart | 8 +- .../json_test_example.non_nullable.dart | 16 +- ...son_test_example.non_nullable.wrapped.dart | 20 ++- .../json_test_example.wrapped.dart | 16 +- .../test/json_serializable_test.dart | 41 ++--- .../test/kitchen_sink/kitchen_sink.dart | 6 +- .../kitchen_sink.non_nullable.checked.dart | 9 +- .../kitchen_sink.non_nullable.dart | 6 +- .../kitchen_sink.non_nullable.wrapped.dart | 18 ++- .../kitchen_sink/kitchen_sink.wrapped.dart | 9 +- .../test/kitchen_sink/simple_object.dart | 2 +- .../test/kitchen_sink/strict_keys_object.dart | 3 +- json_serializable/test/shared_config.dart | 42 ++--- .../test/src/configuration_input.dart | 18 ++- json_serializable/test/yaml/build_config.dart | 9 +- json_serializable/tool/build.dart | 129 --------------- json_serializable/tool/builder.dart | 13 +- 37 files changed, 438 insertions(+), 437 deletions(-) rename json_serializable/lib/src/generator_config.g.dart => json_annotation/lib/src/json_serializable.g.dart (88%) delete mode 100644 json_serializable/lib/src/generator_config.dart delete mode 100755 json_serializable/tool/build.dart diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index 2f4c69768..5436759ce 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -4,7 +4,11 @@ fields when constructor arguments are unset or `null`. This is not likely an issue for developers using this class as an annotation with a compatible version of `package:json_serializable`, but it may cause issues if class is - used in other contexts. + used in other contexts. + +* Support all `build.yaml` configuration options on classes by adding a number + of fields to `JsonSerializable`: `anyMap`, `checked`, `explicitToJson`, + `generateToJsonFunction`, and `useWrappers`. ## 1.2.0 @@ -13,7 +17,7 @@ ## 1.1.0 * Added the `fieldRename` option to `JsonSerializable` and the associated - `FieldRename` enum. + `FieldRename` enum. ## 1.0.0 @@ -37,7 +41,7 @@ * Added `$checkKeys` helper function and deprecated `$checkAllowedKeys`. Upgrading to the latest `json_serializable` and re-running your build will eliminate any `@deprecated` hints you see. - + * Added `BadKeyException` exception which is the abstract super class for `MissingRequiredKeysException`, `UnrecognizedKeysException`, and `DisallowedNullValueException`. @@ -45,8 +49,8 @@ * Added `JsonKey.required` field and an associated `MissingRequiredKeysException` that is thrown when `required` fields don't have corresponding keys in a source JSON map. - -* Added `JsonKey.disallowNullValue` field and an associated + +* Added `JsonKey.disallowNullValue` field and an associated `DisallowedNullValueException` that is thrown when corresponding keys exist in a source JSON map, but their values are `null`. diff --git a/json_annotation/lib/src/json_serializable.dart b/json_annotation/lib/src/json_serializable.dart index b962ee078..66a4f3729 100644 --- a/json_annotation/lib/src/json_serializable.dart +++ b/json_annotation/lib/src/json_serializable.dart @@ -2,6 +2,11 @@ // 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 'allowed_keys_helpers.dart'; +import 'checked_helpers.dart'; + +part 'json_serializable.g.dart'; + /// Values for the automatic field renaming behavior for [JsonSerializable]. enum FieldRename { /// Use the field name without changes. @@ -16,11 +21,22 @@ enum FieldRename { /// An annotation used to specify a class to generate code for. class JsonSerializable { - /// If `false` (the default), then any unrecognized keys passed to the - /// generated FromJson factory will be ignored. + /// If `true`, [Map] types are *not* assumed to be [Map] + /// – which is the default type of [Map] instances return by JSON decode in + /// `dart:convert`. /// - /// If `true`, any unrecognized keys will be treated as an error. - final bool disallowUnrecognizedKeys; + /// This will increase the code size, but allows [Map] types returned + /// from other sources, such as `package:yaml`. + /// + /// *Note: in many cases the key values are still assumed to be [String]*. + final bool anyMap; + + /// If `true`, generated `fromJson` functions include extra checks to validate + /// proper deserialization of types. + /// + /// If an exception is thrown during deserialization, a + /// [CheckedFromJsonException] is thrown. + final bool checked; /// If `true` (the default), a private, static `_$ExampleFromJson` method /// is created in the generated part file. @@ -64,6 +80,71 @@ class JsonSerializable { /// ``` final bool createToJson; + /// If `false` (the default), then any unrecognized keys passed to the + /// generated FromJson factory will be ignored. + /// + /// If `true`, any unrecognized keys will be treated as an error. + final bool disallowUnrecognizedKeys; + + /// If `true`, generated `toJson` methods will explicitly call `toJson` on + /// nested objects. + /// + /// When using JSON encoding support in `dart:convert`, `toJson` is + /// automatically called on objects, so the default behavior + /// (`explicitToJson: false`) is to omit the `toJson` call. + /// + /// Example of `explicitToJson: false` (default) + /// + /// ```dart + /// Map toJson() => {'child': child}; + /// ``` + /// + /// Example of `explicitToJson: true` + /// + /// ```dart + /// Map toJson() => {'child': child?.toJson()}; + /// ``` + final bool explicitToJson; + + /// Defines the automatic naming strategy when converting class field names + /// into JSON map keys. + /// + /// With a value [FieldRename.none], the default, the name of the field is + /// used without modification. + /// + /// See [FieldRename] for details on the other options. + /// + /// Note: the value for [JsonKey.name] takes precedence over this option for + /// fields annotated with [JsonKey]. + final FieldRename fieldRename; + + /// Controls how `toJson` functionality is generated for all types processed + /// by this generator. + /// + /// If `true` (the default), then a top-level function is created that you can + /// reference from your class. + /// + /// ```dart + /// @JsonSerializable() + /// class Example { + /// // ... + /// Map toJson() => _$ExampleToJson(this); + /// } + /// ``` + /// + /// If `false`, a private `_$ClassNameSerializerMixin` class is + /// created in the generated part file which contains a `toJson` method. + /// + /// Mix in this class to the source class: + /// + /// ```dart + /// @JsonSerializable() + /// class Example extends Object with _$ExampleSerializerMixin { + /// // ... + /// } + /// ``` + final bool generateToJsonFunction; + /// Whether the generator should include fields with `null` values in the /// serialized output. /// @@ -84,27 +165,67 @@ class JsonSerializable { /// `null` runtime validation if it's critical. final bool nullable; - /// Defines the automatic naming strategy when converting class field names - /// into JSON map keys. - /// - /// With a value [FieldRename.none], the default, the name of the field is - /// used without modification. + /// If `true`, wrappers are used to minimize the number of + /// [Map] and [List] instances created during serialization. /// - /// See [FieldRename] for details on the other options. - /// - /// Note: the value for [JsonKey.name] takes precedence over this option for - /// fields annotated with [JsonKey]. - final FieldRename fieldRename; + /// This will increase the code size, but it may improve runtime performance, + /// especially for large object graphs. + final bool useWrappers; /// Creates a new [JsonSerializable] instance. const JsonSerializable({ - this.disallowUnrecognizedKeys, + this.anyMap, + this.checked, this.createFactory, this.createToJson, + this.disallowUnrecognizedKeys, + this.explicitToJson, + this.fieldRename, + this.generateToJsonFunction, this.includeIfNull, this.nullable, - this.fieldRename, + this.useWrappers, }); + + factory JsonSerializable.fromJson(Map json) => + _$JsonSerializableFromJson(json); + + /// An instance of [JsonSerializable] with all fields set to their default + /// values. + static const defaults = JsonSerializable( + anyMap: false, + checked: false, + createFactory: true, + createToJson: true, + disallowUnrecognizedKeys: false, + explicitToJson: false, + fieldRename: FieldRename.none, + generateToJsonFunction: true, + includeIfNull: true, + nullable: true, + useWrappers: false); + + /// Returns a new [JsonSerializable] instance with fields equal to the + /// corresponding values in `this`, if not `null`. + /// + /// Otherwise, the returned value has the default value as defined in + /// [defaults]. + JsonSerializable withDefaults() => JsonSerializable( + anyMap: anyMap ?? defaults.anyMap, + checked: checked ?? defaults.checked, + createFactory: createFactory ?? defaults.createFactory, + createToJson: createToJson ?? defaults.createToJson, + disallowUnrecognizedKeys: + disallowUnrecognizedKeys ?? defaults.disallowUnrecognizedKeys, + explicitToJson: explicitToJson ?? defaults.explicitToJson, + fieldRename: fieldRename ?? defaults.fieldRename, + generateToJsonFunction: + generateToJsonFunction ?? defaults.generateToJsonFunction, + includeIfNull: includeIfNull ?? defaults.includeIfNull, + nullable: nullable ?? defaults.nullable, + useWrappers: useWrappers ?? defaults.useWrappers); + + Map toJson() => _$JsonSerializableToJson(this); } /// An annotation used to specify how a field is serialized. diff --git a/json_serializable/lib/src/generator_config.g.dart b/json_annotation/lib/src/json_serializable.g.dart similarity index 88% rename from json_serializable/lib/src/generator_config.g.dart rename to json_annotation/lib/src/json_serializable.g.dart index ea930391b..dc43fe7e1 100644 --- a/json_serializable/lib/src/generator_config.g.dart +++ b/json_annotation/lib/src/json_serializable.g.dart @@ -1,26 +1,26 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -part of 'generator_config.dart'; +part of 'json_serializable.dart'; // ************************************************************************** // JsonSerializableGenerator // ************************************************************************** -GeneratorConfig _$GeneratorConfigFromJson(Map json) { +JsonSerializable _$JsonSerializableFromJson(Map json) { $checkKeys(json, allowedKeys: const [ - 'disallow_unrecognized_keys', + 'any_map', + 'checked', 'create_factory', 'create_to_json', + 'disallow_unrecognized_keys', + 'explicit_to_json', + 'field_rename', + 'generate_to_json_function', 'include_if_null', 'nullable', - 'field_rename', - 'any_map', - 'use_wrappers', - 'checked', - 'explicit_to_json', - 'generate_to_json_function' + 'use_wrappers' ]); - return GeneratorConfig( + return JsonSerializable( anyMap: json['any_map'] as bool, checked: json['checked'] as bool, explicitToJson: json['explicit_to_json'] as bool, @@ -35,19 +35,19 @@ GeneratorConfig _$GeneratorConfigFromJson(Map json) { _$enumDecodeNullable(_$FieldRenameEnumMap, json['field_rename'])); } -Map _$GeneratorConfigToJson(GeneratorConfig instance) => +Map _$JsonSerializableToJson(JsonSerializable instance) => { - 'disallow_unrecognized_keys': instance.disallowUnrecognizedKeys, + 'any_map': instance.anyMap, + 'checked': instance.checked, 'create_factory': instance.createFactory, 'create_to_json': instance.createToJson, + 'disallow_unrecognized_keys': instance.disallowUnrecognizedKeys, + 'explicit_to_json': instance.explicitToJson, + 'field_rename': _$FieldRenameEnumMap[instance.fieldRename], + 'generate_to_json_function': instance.generateToJsonFunction, 'include_if_null': instance.includeIfNull, 'nullable': instance.nullable, - 'field_rename': _$FieldRenameEnumMap[instance.fieldRename], - 'any_map': instance.anyMap, - 'use_wrappers': instance.useWrappers, - 'checked': instance.checked, - 'explicit_to_json': instance.explicitToJson, - 'generate_to_json_function': instance.generateToJsonFunction + 'use_wrappers': instance.useWrappers }; T _$enumDecode(Map enumValues, dynamic source) { diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index a9a871890..e0000f688 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -10,8 +10,12 @@ * `json_serializable.dart` +* Support all `build.yaml` configuration options on classes by adding a number + of fields to `JsonSerializable`: `anyMap`, `checked`, `explicitToJson`, + `generateToJsonFunction`, and `useWrappers`. + * **BREAKING** `JsonSerializableGenerator` now exposes a `config` property - of type `GeneratorConfig` instead of individual properties for `checked`, + of type `JsonSerializable` instead of individual properties for `checked`, `anyMay`, etc. This will affect anyone creating or using this class via code. @@ -21,7 +25,7 @@ with new `TypeHelperContext` class. * `TypeHelper` now has a type argument allowing implementors to specify a - specific implementation of `TypeHelperContext` for calls to `serialize` and + specific implementation of `TypeHelperContext` for calls to `serialize` and `deserialize`. Many of the included `TypeHelper` implementations have been updated to indicate they expect more information from the source generator. diff --git a/json_serializable/build.yaml b/json_serializable/build.yaml index c1a870f5d..765e4d866 100644 --- a/json_serializable/build.yaml +++ b/json_serializable/build.yaml @@ -1,6 +1,18 @@ +# Read about `build.yaml` at https://pub.dartlang.org/packages/build_config targets: $default: builders: + json_serializable: + enabled: true + generate_for: + include: + - example/* + - test/default_value/* + - test/generic_files/* + - test/integration/* + - test/kitchen_sink/* + - test/literal/* + - test/yaml/* build_web_compilers|entrypoint: generate_for: - test/default_value/** @@ -8,8 +20,46 @@ targets: - test/integration/*_test.dart - test/kitchen_sink/** -# Read about `build.yaml` at https://pub.dartlang.org/packages/build_config builders: + checked: + import: 'tool/builder.dart' + builder_factories: ['checked'] + build_extensions: {".dart": [".checked.dart"]} + auto_apply: root_package + build_to: source + runs_before: ["json_serializable"] + defaults: + generate_for: + - test/default_value/default_value.dart + - test/kitchen_sink/kitchen_sink.non_nullable.dart + + non_null: + import: 'tool/builder.dart' + builder_factories: ['nonNull'] + build_extensions: {".dart": [".non_nullable.dart"]} + auto_apply: root_package + build_to: source + runs_before: ["json_serializable"] + defaults: + generate_for: + - test/kitchen_sink/kitchen_sink.dart + - test/integration/json_test_example.dart + + wrapped: + import: 'tool/builder.dart' + builder_factories: ['wrapped'] + build_extensions: {".dart": [".wrapped.dart"]} + auto_apply: root_package + build_to: source + runs_before: ["json_serializable"] + defaults: + generate_for: + - test/generic_files/generic_class.dart + - test/kitchen_sink/kitchen_sink.dart + - test/kitchen_sink/kitchen_sink.non_nullable.dart + - test/integration/json_test_example.dart + - test/integration/json_test_example.non_nullable.dart + json_serializable: import: "package:json_serializable/builder.dart" builder_factories: ["jsonSerializable"] diff --git a/json_serializable/lib/builder.dart b/json_serializable/lib/builder.dart index df78b4292..c4f735d09 100644 --- a/json_serializable/lib/builder.dart +++ b/json_serializable/lib/builder.dart @@ -13,8 +13,8 @@ library json_serializable.builder; import 'package:build/build.dart'; +import 'package:json_annotation/json_annotation.dart'; -import 'src/generator_config.dart'; import 'src/json_part_builder.dart'; /// Supports `package:build_runner` creation and configuration of @@ -22,6 +22,6 @@ import 'src/json_part_builder.dart'; /// /// Not meant to be invoked by hand-authored code. Builder jsonSerializable(BuilderOptions options) { - final config = GeneratorConfig.fromJson(options.config); + final config = JsonSerializable.fromJson(options.config); return jsonPartBuilder(config: config); } diff --git a/json_serializable/lib/json_serializable.dart b/json_serializable/lib/json_serializable.dart index ec9cae1a7..094597df6 100644 --- a/json_serializable/lib/json_serializable.dart +++ b/json_serializable/lib/json_serializable.dart @@ -2,6 +2,5 @@ // 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. -export 'src/generator_config.dart' show GeneratorConfig; export 'src/json_literal_generator.dart' show JsonLiteralGenerator; export 'src/json_serializable_generator.dart' show JsonSerializableGenerator; diff --git a/json_serializable/lib/src/encoder_helper.dart b/json_serializable/lib/src/encoder_helper.dart index d2b5166f8..a0f046373 100644 --- a/json_serializable/lib/src/encoder_helper.dart +++ b/json_serializable/lib/src/encoder_helper.dart @@ -3,9 +3,9 @@ // BSD-style license that can be found in the LICENSE file. import 'package:analyzer/dart/element/element.dart'; +import 'package:json_annotation/json_annotation.dart'; import 'constants.dart'; -import 'generator_config.dart'; import 'helper_core.dart'; import 'type_helper.dart'; @@ -161,7 +161,7 @@ class ${_wrapperClassName(true)} extends \$JsonMapWrapper { } /// Name of the parameter used when generating top-level `toJson` functions - /// if [GeneratorConfig.generateToJsonFunction] is `true`. + /// if [JsonSerializable.generateToJsonFunction] is `true`. static const _toJsonParamName = 'instance'; void _writeToJsonWithNullChecks( diff --git a/json_serializable/lib/src/generator_config.dart b/json_serializable/lib/src/generator_config.dart deleted file mode 100644 index f9f5a71a5..000000000 --- a/json_serializable/lib/src/generator_config.dart +++ /dev/null @@ -1,115 +0,0 @@ -// Copyright (c) 2018, 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:json_annotation/json_annotation.dart'; - -import 'json_serializable_generator.dart'; - -part 'generator_config.g.dart'; - -/// Represents the configuration for [JsonSerializableGenerator]. -@JsonSerializable( - disallowUnrecognizedKeys: true, fieldRename: FieldRename.snake) -class GeneratorConfig extends JsonSerializable { - /// If `true`, [Map] types are *not* assumed to be [Map] - /// – which is the default type of [Map] instances return by JSON decode in - /// `dart:convert`. - /// - /// This will increase the code size, but allows [Map] types returned - /// from other sources, such as `package:yaml`. - /// - /// *Note: in many cases the key values are still assumed to be [String]*. - final bool anyMap; - - /// If `true`, wrappers are used to minimize the number of - /// [Map] and [List] instances created during serialization. - /// - /// This will increase the code size, but it may improve runtime performance, - /// especially for large object graphs. - final bool useWrappers; - - /// If `true`, generated `fromJson` functions include extra checks to validate - /// proper deserialization of types. - /// - /// If an exception is thrown during deserialization, a - /// [CheckedFromJsonException] is thrown. - final bool checked; - - /// If `true`, generated `toJson` methods will explicitly call `toJson` on - /// nested objects. - /// - /// When using JSON encoding support in `dart:convert`, `toJson` is - /// automatically called on objects, so the default behavior - /// (`explicitToJson: false`) is to omit the `toJson` call. - /// - /// Example of `explicitToJson: false` (default) - /// - /// ```dart - /// Map toJson() => {'child': child}; - /// ``` - /// - /// Example of `explicitToJson: true` - /// - /// ```dart - /// Map toJson() => {'child': child?.toJson()}; - /// ``` - final bool explicitToJson; - - /// Controls how `toJson` functionality is generated for all types processed - /// by this generator. - /// - /// If `true` (the default), then a top-level function is created that you can - /// reference from your class. - /// - /// ```dart - /// @JsonSerializable() - /// class Example { - /// // ... - /// Map toJson() => _$ExampleToJson(this); - /// } - /// ``` - /// - /// If `false`, a private `_$ClassNameSerializerMixin` class is - /// created in the generated part file which contains a `toJson` method. - /// - /// Mix in this class to the source class: - /// - /// ```dart - /// @JsonSerializable() - /// class Example extends Object with _$ExampleSerializerMixin { - /// // ... - /// } - /// ``` - final bool generateToJsonFunction; - - const GeneratorConfig({ - bool anyMap = false, - bool checked = false, - bool explicitToJson = false, - bool generateToJsonFunction = true, - bool useWrappers = false, - bool disallowUnrecognizedKeys = false, - bool createFactory = true, - bool createToJson = true, - bool includeIfNull = true, - bool nullable = true, - FieldRename fieldRename = FieldRename.none, - }) : anyMap = anyMap ?? false, - checked = checked ?? false, - explicitToJson = explicitToJson ?? false, - generateToJsonFunction = generateToJsonFunction ?? true, - useWrappers = useWrappers ?? false, - super( - disallowUnrecognizedKeys: disallowUnrecognizedKeys ?? false, - createFactory: createFactory ?? true, - createToJson: createToJson ?? true, - includeIfNull: includeIfNull ?? true, - nullable: nullable ?? true, - fieldRename: fieldRename ?? FieldRename.none); - - factory GeneratorConfig.fromJson(Map json) => - _$GeneratorConfigFromJson(json); - - Map toJson() => _$GeneratorConfigToJson(this); -} diff --git a/json_serializable/lib/src/helper_core.dart b/json_serializable/lib/src/helper_core.dart index 714b7aefe..11d14a51d 100644 --- a/json_serializable/lib/src/helper_core.dart +++ b/json_serializable/lib/src/helper_core.dart @@ -8,7 +8,6 @@ import 'package:json_annotation/json_annotation.dart'; import 'package:meta/meta.dart'; import 'package:source_gen/source_gen.dart'; -import 'generator_config.dart'; import 'json_key_utils.dart'; import 'type_helper.dart'; import 'type_helper_ctx.dart'; @@ -16,7 +15,7 @@ import 'utils.dart'; abstract class HelperCore { final ClassElement element; - final GeneratorConfig config; + final JsonSerializable config; HelperCore(this.element, this.config); diff --git a/json_serializable/lib/src/json_part_builder.dart b/json_serializable/lib/src/json_part_builder.dart index 392b59597..ce8cd9210 100644 --- a/json_serializable/lib/src/json_part_builder.dart +++ b/json_serializable/lib/src/json_part_builder.dart @@ -3,9 +3,9 @@ // BSD-style license that can be found in the LICENSE file. import 'package:build/build.dart'; +import 'package:json_annotation/json_annotation.dart'; import 'package:source_gen/source_gen.dart'; -import 'generator_config.dart'; import 'json_literal_generator.dart'; import 'json_serializable_generator.dart'; @@ -15,7 +15,7 @@ import 'json_serializable_generator.dart'; /// [formatOutput] is called to format the generated code. If not provided, /// the default Dart code formatter is used. Builder jsonPartBuilder( - {String formatOutput(String code), GeneratorConfig config}) => + {String formatOutput(String code), JsonSerializable config}) => SharedPartBuilder([ JsonSerializableGenerator(config: config), const JsonLiteralGenerator() diff --git a/json_serializable/lib/src/json_serializable_generator.dart b/json_serializable/lib/src/json_serializable_generator.dart index 5ce134765..228ff7bb6 100644 --- a/json_serializable/lib/src/json_serializable_generator.dart +++ b/json_serializable/lib/src/json_serializable_generator.dart @@ -10,7 +10,6 @@ import 'package:source_gen/source_gen.dart'; import 'decode_helper.dart'; import 'encoder_helper.dart'; import 'field_helpers.dart'; -import 'generator_config.dart'; import 'helper_core.dart'; import 'type_helper.dart'; import 'type_helpers/convert_helper.dart'; @@ -48,16 +47,18 @@ class JsonSerializableGenerator JsonConverterHelper() ].followedBy(_typeHelpers).followedBy(_coreHelpers); - final GeneratorConfig config; + final JsonSerializable _config; + + JsonSerializable get config => _config.withDefaults(); /// Creates an instance of [JsonSerializableGenerator]. /// /// If [typeHelpers] is not provided, three built-in helpers are used: /// [JsonHelper], [DateTimeHelper], [DurationHelper] and [UriHelper]. const JsonSerializableGenerator({ - GeneratorConfig config, + JsonSerializable config, List typeHelpers, - }) : config = config ?? const GeneratorConfig(), + }) : _config = config ?? JsonSerializable.defaults, _typeHelpers = typeHelpers ?? _defaultHelpers; /// Creates an instance of [JsonSerializableGenerator]. @@ -67,7 +68,7 @@ class JsonSerializableGenerator /// [JsonHelper], [DateTimeHelper], [DurationHelper] and [UriHelper]. factory JsonSerializableGenerator.withDefaultHelpers( Iterable typeHelpers, - {GeneratorConfig config}) => + {JsonSerializable config}) => JsonSerializableGenerator( config: config, typeHelpers: diff --git a/json_serializable/lib/src/type_helper.dart b/json_serializable/lib/src/type_helper.dart index 90477bde5..f34845137 100644 --- a/json_serializable/lib/src/type_helper.dart +++ b/json_serializable/lib/src/type_helper.dart @@ -4,8 +4,7 @@ import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/type.dart'; - -import 'generator_config.dart'; +import 'package:json_annotation/json_annotation.dart'; /// Context information provided in calls to [TypeHelper.serialize] and /// [TypeHelper.deserialize]. @@ -34,7 +33,7 @@ abstract class TypeHelperContext { /// Extended context information with includes configuration values /// corresponding to `JsonSerializableGenerator` settings. abstract class TypeHelperContextWithConfig extends TypeHelperContext { - GeneratorConfig get config; + JsonSerializable get config; } abstract class TypeHelper { @@ -86,6 +85,7 @@ abstract class TypeHelper { class LambdaResult { final String expression; final String lambda; + LambdaResult(this.expression, this.lambda); @override diff --git a/json_serializable/lib/src/type_helper_ctx.dart b/json_serializable/lib/src/type_helper_ctx.dart index 9992c37dc..253ca58c5 100644 --- a/json_serializable/lib/src/type_helper_ctx.dart +++ b/json_serializable/lib/src/type_helper_ctx.dart @@ -6,7 +6,6 @@ import 'package:analyzer/dart/constant/value.dart'; import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/type.dart'; import 'package:json_annotation/json_annotation.dart'; -import 'package:json_serializable/src/generator_config.dart'; import 'helper_core.dart'; import 'type_helper.dart'; @@ -32,7 +31,7 @@ class _TypeHelperCtx ClassElement get classElement => _helperCore.element; @override - GeneratorConfig get config => _helperCore.config; + JsonSerializable get config => _helperCore.config; _TypeHelperCtx(this._helperCore, this.fieldElement, this._key); diff --git a/json_serializable/lib/src/type_helpers/json_helper.dart b/json_serializable/lib/src/type_helpers/json_helper.dart index 33b9e82e4..26e634a85 100644 --- a/json_serializable/lib/src/type_helpers/json_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_helper.dart @@ -7,7 +7,6 @@ import 'package:analyzer/dart/element/type.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:source_gen/source_gen.dart'; -import '../generator_config.dart'; import '../shared_checkers.dart'; import '../type_helper.dart'; import '../utils.dart'; @@ -68,7 +67,7 @@ class JsonHelper extends TypeHelper { } } -bool _canSerialize(GeneratorConfig config, DartType type) { +bool _canSerialize(JsonSerializable config, DartType type) { if (type is InterfaceType) { final toJsonMethod = _toJsonMethod(type); @@ -86,7 +85,7 @@ bool _canSerialize(GeneratorConfig config, DartType type) { return false; } -JsonSerializable _annotation(GeneratorConfig config, InterfaceType source) { +JsonSerializable _annotation(JsonSerializable config, InterfaceType source) { final annotations = const TypeChecker.fromRuntime(JsonSerializable) .annotationsOfExact(source.element, throwOnUnresolved: false) .toList(); diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index c4ae5a82c..74a2741f7 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -9,8 +9,6 @@ import 'package:json_annotation/json_annotation.dart'; import 'package:meta/meta.dart' show alwaysThrows; import 'package:source_gen/source_gen.dart'; -import 'generator_config.dart'; - final _jsonKeyChecker = const TypeChecker.fromRuntime(JsonKey); DartObject jsonKeyAnnotation(FieldElement element) => @@ -53,35 +51,43 @@ FieldRename _fromDartObject(ConstantReader reader) => reader.isNull /// Return an instance of [JsonSerializable] corresponding to a the provided /// [reader]. JsonSerializable _valueForAnnotation(ConstantReader reader) => JsonSerializable( - disallowUnrecognizedKeys: - reader.read('disallowUnrecognizedKeys').literalValue as bool, - createToJson: reader.read('createToJson').literalValue as bool, - createFactory: reader.read('createFactory').literalValue as bool, - nullable: reader.read('nullable').literalValue as bool, - includeIfNull: reader.read('includeIfNull').literalValue as bool, - fieldRename: _fromDartObject(reader.read('fieldRename'))); - -/// Returns a [GeneratorConfig] with values from the [JsonSerializable] instance + anyMap: reader.read('anyMap').literalValue as bool, + checked: reader.read('checked').literalValue as bool, + createFactory: reader.read('createFactory').literalValue as bool, + createToJson: reader.read('createToJson').literalValue as bool, + disallowUnrecognizedKeys: + reader.read('disallowUnrecognizedKeys').literalValue as bool, + explicitToJson: reader.read('explicitToJson').literalValue as bool, + fieldRename: _fromDartObject(reader.read('fieldRename')), + generateToJsonFunction: + reader.read('generateToJsonFunction').literalValue as bool, + includeIfNull: reader.read('includeIfNull').literalValue as bool, + nullable: reader.read('nullable').literalValue as bool, + useWrappers: reader.read('useWrappers').literalValue as bool, + ); + +/// Returns a [JsonSerializable] with values from the [JsonSerializable] instance /// represented by [reader]. /// /// For fields that are not defined in [JsonSerializable] or `null` in [reader], /// use the values in [config]. -GeneratorConfig mergeConfig(GeneratorConfig config, ConstantReader reader) { +JsonSerializable mergeConfig(JsonSerializable config, ConstantReader reader) { final annotation = _valueForAnnotation(reader); - return GeneratorConfig( - anyMap: config.anyMap, - checked: config.checked, + return JsonSerializable( + anyMap: annotation.anyMap ?? config.anyMap, + checked: annotation.checked ?? config.checked, createFactory: annotation.createFactory ?? config.createFactory, createToJson: annotation.createToJson ?? config.createToJson, disallowUnrecognizedKeys: annotation.disallowUnrecognizedKeys ?? config.disallowUnrecognizedKeys, - explicitToJson: config.explicitToJson, + explicitToJson: annotation.explicitToJson ?? config.explicitToJson, fieldRename: annotation.fieldRename ?? config.fieldRename, - generateToJsonFunction: config.generateToJsonFunction, + generateToJsonFunction: + annotation.generateToJsonFunction ?? config.generateToJsonFunction, includeIfNull: annotation.includeIfNull ?? config.includeIfNull, nullable: annotation.nullable ?? config.nullable, - useWrappers: config.useWrappers, + useWrappers: annotation.useWrappers ?? config.useWrappers, ); } diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index a07876a8f..9ff1bdeb0 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -20,7 +20,6 @@ dependencies: dev_dependencies: build_runner: ^1.0.0 - build_runner_core: ^1.0.0 build_test: ^0.10.0 build_verify: ^1.1.0 build_web_compilers: ^0.4.0+1 diff --git a/json_serializable/test/config_test.dart b/json_serializable/test/config_test.dart index 80cbe1f0d..474f401af 100644 --- a/json_serializable/test/config_test.dart +++ b/json_serializable/test/config_test.dart @@ -8,7 +8,7 @@ import 'dart:io'; import 'package:build/build.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:json_serializable/builder.dart'; -import 'package:json_serializable/src/generator_config.dart'; +import 'package:json_serializable/src/json_serializable_generator.dart'; import 'package:test/test.dart'; import 'package:yaml/yaml.dart'; @@ -16,6 +16,11 @@ import 'shared_config.dart'; import 'test_utils.dart'; void main() { + test('fields in JsonSerializable are sorted', () { + expect(generatorConfigDefaultJson.keys, + orderedEquals(generatorConfigDefaultJson.keys.toList()..sort())); + }); + test('empty', () async { final builder = jsonSerializable(BuilderOptions.empty); expect(builder, isNotNull); @@ -42,12 +47,12 @@ void main() { expect(builder, isNotNull); }); - test('config is null-protected', () { + test('config is null-protected when passed to JsonSerializableGenerator', () { final nullValueMap = Map.fromEntries( generatorConfigDefaultJson.entries.map((e) => MapEntry(e.key, null))); - - final config = GeneratorConfig.fromJson(nullValueMap); - expect(config.toJson(), generatorConfigDefaultJson); + final config = JsonSerializable.fromJson(nullValueMap); + final generator = JsonSerializableGenerator(config: config); + expect(generator.config.toJson(), generatorConfigDefaultJson); }); test('readme config', () async { @@ -75,7 +80,7 @@ void main() { expect(configMap.keys, unorderedEquals(generatorConfigDefaultJson.keys), reason: 'All supported keys are documented.'); - expect(GeneratorConfig.fromJson(configMap).toJson(), + expect(JsonSerializable.fromJson(configMap).toJson(), generatorConfigDefaultJson, reason: 'All keys specify their default value.'); @@ -117,15 +122,15 @@ void main() { } const _invalidConfig = { - 'disallow_unrecognized_keys': 42, + 'any_map': 42, + 'checked': 42, 'create_factory': 42, 'create_to_json': 42, + 'disallow_unrecognized_keys': 42, + 'explicit_to_json': 42, + 'field_rename': 42, + 'generate_to_json_function': 42, 'include_if_null': 42, 'nullable': 42, - 'field_rename': 42, - 'any_map': 42, 'use_wrappers': 42, - 'checked': 42, - 'explicit_to_json': 42, - 'generate_to_json_function': 42, }; diff --git a/json_serializable/test/default_value/default_value.checked.dart b/json_serializable/test/default_value/default_value.checked.dart index 0ed1826b1..00ce1cbd7 100644 --- a/json_serializable/test/default_value/default_value.checked.dart +++ b/json_serializable/test/default_value/default_value.checked.dart @@ -22,7 +22,10 @@ const _intValue = 42; dvi.DefaultValue fromJson(Map json) => _$DefaultValueFromJson(json); -@JsonSerializable() +@JsonSerializable( + anyMap: true, + checked: true, +) class DefaultValue implements dvi.DefaultValue { @JsonKey(defaultValue: true) bool fieldBool; diff --git a/json_serializable/test/ensure_build_test.dart b/json_serializable/test/ensure_build_test.dart index 61a8b7a7c..487646cb3 100644 --- a/json_serializable/test/ensure_build_test.dart +++ b/json_serializable/test/ensure_build_test.dart @@ -4,20 +4,10 @@ @TestOn('vm') @Tags(['presubmit-only']) - import 'package:build_verify/build_verify.dart'; -import 'package:path/path.dart' as p; import 'package:test/test.dart'; void main() { - test( - 'ensure_build', - () => expectBuildClean( - packageRelativeDirectory: 'json_serializable', - customCommand: [ - 'DART', - p.join('tool', 'build.dart'), - 'build', - '--delete-conflicting-outputs', - ])); + test('ensure_build', + () => expectBuildClean(packageRelativeDirectory: 'json_serializable')); } diff --git a/json_serializable/test/generic_files/generic_class.wrapped.dart b/json_serializable/test/generic_files/generic_class.wrapped.dart index e071aa431..4709e5103 100644 --- a/json_serializable/test/generic_files/generic_class.wrapped.dart +++ b/json_serializable/test/generic_files/generic_class.wrapped.dart @@ -12,7 +12,9 @@ import 'package:json_annotation/json_annotation.dart'; part 'generic_class.wrapped.g.dart'; -@JsonSerializable() +@JsonSerializable( + useWrappers: true, +) class GenericClass { @JsonKey(fromJson: _dataFromJson, toJson: _dataToJson) Object fieldObject; @@ -45,7 +47,9 @@ class GenericClass { {'value': input}; } -@JsonSerializable() +@JsonSerializable( + useWrappers: true, +) @_DurationMillisecondConverter() @_DurationListMillisecondConverter() class GenericClassWithConverter { diff --git a/json_serializable/test/integration/json_test_example.non_nullable.dart b/json_serializable/test/integration/json_test_example.non_nullable.dart index ee86724e4..62257caf6 100644 --- a/json_serializable/test/integration/json_test_example.non_nullable.dart +++ b/json_serializable/test/integration/json_test_example.non_nullable.dart @@ -16,7 +16,9 @@ import 'json_test_common.dart'; part 'json_test_example.non_nullable.g.dart'; -@JsonSerializable(nullable: false) +@JsonSerializable( + nullable: false, +) class Person { final String firstName, middleName, lastName; final DateTime dateOfBirth; @@ -46,7 +48,9 @@ class Person { deepEquals(houseMap, other.houseMap); } -@JsonSerializable(nullable: false) +@JsonSerializable( + nullable: false, +) class Order { /// Used to test that `disallowNullValues: true` forces `includeIfNull: false` @JsonKey(disallowNullValue: true) @@ -97,7 +101,9 @@ class Order { deepEquals(altPlatforms, other.altPlatforms); } -@JsonSerializable(nullable: false) +@JsonSerializable( + nullable: false, +) class Item extends ItemCore { @JsonKey(includeIfNull: false, name: 'item-number') int itemNumber; @@ -118,7 +124,9 @@ class Item extends ItemCore { deepEquals(saleDates, other.saleDates); } -@JsonSerializable(nullable: false) +@JsonSerializable( + nullable: false, +) class Numbers { List ints; List nums; diff --git a/json_serializable/test/integration/json_test_example.non_nullable.wrapped.dart b/json_serializable/test/integration/json_test_example.non_nullable.wrapped.dart index d0b41ee44..7893dc642 100644 --- a/json_serializable/test/integration/json_test_example.non_nullable.wrapped.dart +++ b/json_serializable/test/integration/json_test_example.non_nullable.wrapped.dart @@ -22,7 +22,10 @@ import 'json_test_common.dart'; part 'json_test_example.non_nullable.wrapped.g.dart'; -@JsonSerializable(nullable: false) +@JsonSerializable( + useWrappers: true, + nullable: false, +) class Person { final String firstName, middleName, lastName; final DateTime dateOfBirth; @@ -52,7 +55,10 @@ class Person { deepEquals(houseMap, other.houseMap); } -@JsonSerializable(nullable: false) +@JsonSerializable( + useWrappers: true, + nullable: false, +) class Order { /// Used to test that `disallowNullValues: true` forces `includeIfNull: false` @JsonKey(disallowNullValue: true) @@ -103,7 +109,10 @@ class Order { deepEquals(altPlatforms, other.altPlatforms); } -@JsonSerializable(nullable: false) +@JsonSerializable( + useWrappers: true, + nullable: false, +) class Item extends ItemCore { @JsonKey(includeIfNull: false, name: 'item-number') int itemNumber; @@ -124,7 +133,10 @@ class Item extends ItemCore { deepEquals(saleDates, other.saleDates); } -@JsonSerializable(nullable: false) +@JsonSerializable( + useWrappers: true, + nullable: false, +) class Numbers { List ints; List nums; diff --git a/json_serializable/test/integration/json_test_example.wrapped.dart b/json_serializable/test/integration/json_test_example.wrapped.dart index bdea0ac1c..4443c2982 100644 --- a/json_serializable/test/integration/json_test_example.wrapped.dart +++ b/json_serializable/test/integration/json_test_example.wrapped.dart @@ -16,7 +16,9 @@ import 'json_test_common.dart'; part 'json_test_example.wrapped.g.dart'; -@JsonSerializable() +@JsonSerializable( + useWrappers: true, +) class Person { final String firstName, middleName, lastName; final DateTime dateOfBirth; @@ -46,7 +48,9 @@ class Person { deepEquals(houseMap, other.houseMap); } -@JsonSerializable() +@JsonSerializable( + useWrappers: true, +) class Order { /// Used to test that `disallowNullValues: true` forces `includeIfNull: false` @JsonKey(disallowNullValue: true) @@ -97,7 +101,9 @@ class Order { deepEquals(altPlatforms, other.altPlatforms); } -@JsonSerializable() +@JsonSerializable( + useWrappers: true, +) class Item extends ItemCore { @JsonKey(includeIfNull: false, name: 'item-number') int itemNumber; @@ -118,7 +124,9 @@ class Item extends ItemCore { deepEquals(saleDates, other.saleDates); } -@JsonSerializable() +@JsonSerializable( + useWrappers: true, +) class Numbers { List ints; List nums; diff --git a/json_serializable/test/json_serializable_test.dart b/json_serializable/test/json_serializable_test.dart index 978c20a16..80d16156d 100644 --- a/json_serializable/test/json_serializable_test.dart +++ b/json_serializable/test/json_serializable_test.dart @@ -8,6 +8,7 @@ import 'dart:async'; import 'package:analyzer/dart/element/type.dart'; import 'package:build/build.dart'; import 'package:dart_style/dart_style.dart' as dart_style; +import 'package:json_annotation/json_annotation.dart'; import 'package:json_serializable/json_serializable.dart'; import 'package:json_serializable/src/constants.dart'; import 'package:json_serializable/src/type_helper.dart'; @@ -175,13 +176,15 @@ void main() async { } group('without wrappers', () { - _registerTests(const GeneratorConfig()); + _registerTests(JsonSerializable.defaults); }); - group('with wrapper', - () => _registerTests(const GeneratorConfig(useWrappers: true))); + group( + 'with wrapper', + () => _registerTests( + const JsonSerializable(useWrappers: true).withDefaults())); group('configuration', () { - void runWithConfigAndLogger(GeneratorConfig config, String className) { + void runWithConfigAndLogger(JsonSerializable config, String className) { _runForElementNamedWithGenerator( JsonSerializableGenerator( config: config, typeHelpers: const [_ConfigLogger()]), @@ -201,7 +204,7 @@ void main() async { test(testDescription, () { runWithConfigAndLogger( - nullConfig ? null : const GeneratorConfig(), className); + nullConfig ? null : const JsonSerializable(), className); expect(_ConfigLogger.configurations, hasLength(2)); expect(_ConfigLogger.configurations.first, @@ -217,7 +220,7 @@ void main() async { 'values in config override unconfigured (default) values in annotation', () { runWithConfigAndLogger( - GeneratorConfig.fromJson(generatorConfigNonDefaultJson), + JsonSerializable.fromJson(generatorConfigNonDefaultJson), 'ConfigurationImplicitDefaults'); expect(_ConfigLogger.configurations, isEmpty, @@ -229,15 +232,15 @@ void main() async { Map.from(generatorConfigNonDefaultJson); configMap['create_to_json'] = true; - runWithConfigAndLogger( - GeneratorConfig.fromJson(configMap), 'ConfigurationImplicitDefaults'); + runWithConfigAndLogger(JsonSerializable.fromJson(configMap), + 'ConfigurationImplicitDefaults'); }); test( 'explicit values in annotation override corresponding settings in config', () { runWithConfigAndLogger( - GeneratorConfig.fromJson(generatorConfigNonDefaultJson), + JsonSerializable.fromJson(generatorConfigNonDefaultJson), 'ConfigurationExplicitDefaults'); expect(_ConfigLogger.configurations, hasLength(2)); @@ -282,13 +285,13 @@ void _testShouldThrow(AnnotatedElement annotatedElement) { expect( () => _runForElementNamed( - const GeneratorConfig(useWrappers: false), element.name), + const JsonSerializable(useWrappers: false), element.name), _throwsInvalidGenerationSourceError(messageMatcher, todoMatcher), reason: 'Should fail without wrappers.'); expect( () => _runForElementNamed( - const GeneratorConfig(useWrappers: true), element.name), + const JsonSerializable(useWrappers: true), element.name), _throwsInvalidGenerationSourceError(messageMatcher, todoMatcher), reason: 'Should fail with wrappers.'); }); @@ -310,7 +313,7 @@ void _testShouldGenerate(AnnotatedElement annotatedElement) { test(element.name, () { final output = - _runForElementNamed(GeneratorConfig(checked: checked), element.name); + _runForElementNamed(JsonSerializable(checked: checked), element.name); expect(output, matcher); expect(_buildLogItems, expectedLogItems); @@ -323,7 +326,7 @@ void _testShouldGenerate(AnnotatedElement annotatedElement) { if (wrappedMatcher != null) { test('${element.name} - (wrapped)', () { final output = _runForElementNamed( - GeneratorConfig(checked: checked, useWrappers: true), element.name); + JsonSerializable(checked: checked, useWrappers: true), element.name); expect(output, wrappedMatcher); expect(_buildLogItems, expectedLogItems); @@ -332,7 +335,7 @@ void _testShouldGenerate(AnnotatedElement annotatedElement) { } } -String _runForElementNamed(GeneratorConfig config, String name) { +String _runForElementNamed(JsonSerializable config, String name) { final generator = JsonSerializableGenerator(config: config); return _runForElementNamedWithGenerator(generator, name); } @@ -374,7 +377,7 @@ final _annotatedElements = _library.allElements return map; }); -void _registerTests(GeneratorConfig generator) { +void _registerTests(JsonSerializable generator) { String runForElementNamed(String name) => _runForElementNamed(generator, name); @@ -387,7 +390,7 @@ void _registerTests(GeneratorConfig generator) { group('explicit toJson', () { test('nullable', () { final output = _runForElementNamed( - GeneratorConfig( + JsonSerializable( explicitToJson: true, useWrappers: generator.useWrappers), 'TrivialNestedNullable'); @@ -431,7 +434,7 @@ Map _$TrivialNestedNullableToJson( }); test('non-nullable', () { final output = _runForElementNamed( - GeneratorConfig( + JsonSerializable( explicitToJson: true, useWrappers: generator.useWrappers), 'TrivialNestedNonNullable'); @@ -580,7 +583,7 @@ Map _$TrivialNestedNonNullableToJson( test('class with child json-able object - anyMap', () { final output = _runForElementNamed( - GeneratorConfig(anyMap: true, useWrappers: generator.useWrappers), + JsonSerializable(anyMap: true, useWrappers: generator.useWrappers), 'ParentObject'); expect(output, contains("ChildObject.fromJson(json['child'] as Map)")); @@ -624,7 +627,7 @@ Map _$TrivialNestedNonNullableToJson( } class _ConfigLogger implements TypeHelper { - static final configurations = []; + static final configurations = []; const _ConfigLogger(); diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.dart b/json_serializable/test/kitchen_sink/kitchen_sink.dart index a7da29b23..662c082cf 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.dart @@ -37,7 +37,7 @@ k.KitchenSink testFactory( k.KitchenSink testFromJson(Map json) => KitchenSink.fromJson(json); -@JsonSerializable() +@JsonSerializable(anyMap: true, generateToJsonFunction: false) class KitchenSink extends Object with _$KitchenSinkSerializerMixin implements k.KitchenSink { @@ -136,7 +136,7 @@ class KitchenSink extends Object bool operator ==(Object other) => k.sinkEquals(this, other); } -@JsonSerializable() +@JsonSerializable(anyMap: true, generateToJsonFunction: false) // referencing a top-level field should work @durationConverter // referencing via a const constructor should work @@ -162,7 +162,7 @@ class JsonConverterTestClass extends Object DateTime dateTime; } -@JsonSerializable() +@JsonSerializable(anyMap: true, generateToJsonFunction: false) @GenericConverter() class JsonConverterGeneric extends Object with _$JsonConverterGenericSerializerMixin { diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.checked.dart b/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.checked.dart index 3c72d1133..7791d72a2 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.checked.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.checked.dart @@ -49,7 +49,8 @@ k.KitchenSink testFactory( k.KitchenSink testFromJson(Map json) => KitchenSink.fromJson(json); -@JsonSerializable(nullable: false) +@JsonSerializable( + checked: true, nullable: false, anyMap: true, generateToJsonFunction: false) class KitchenSink extends Object with _$KitchenSinkSerializerMixin implements k.KitchenSink { @@ -148,7 +149,8 @@ class KitchenSink extends Object bool operator ==(Object other) => k.sinkEquals(this, other); } -@JsonSerializable(nullable: false) +@JsonSerializable( + checked: true, nullable: false, anyMap: true, generateToJsonFunction: false) // referencing a top-level field should work @durationConverter // referencing via a const constructor should work @@ -174,7 +176,8 @@ class JsonConverterTestClass extends Object DateTime dateTime = DateTime(1981, 6, 5); } -@JsonSerializable(nullable: false) +@JsonSerializable( + checked: true, nullable: false, anyMap: true, generateToJsonFunction: false) @GenericConverter() class JsonConverterGeneric extends Object with _$JsonConverterGenericSerializerMixin { diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.dart b/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.dart index 662b7d850..89c7fd4dd 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.dart @@ -43,7 +43,7 @@ k.KitchenSink testFactory( k.KitchenSink testFromJson(Map json) => KitchenSink.fromJson(json); -@JsonSerializable(nullable: false) +@JsonSerializable(nullable: false, anyMap: true, generateToJsonFunction: false) class KitchenSink extends Object with _$KitchenSinkSerializerMixin implements k.KitchenSink { @@ -142,7 +142,7 @@ class KitchenSink extends Object bool operator ==(Object other) => k.sinkEquals(this, other); } -@JsonSerializable(nullable: false) +@JsonSerializable(nullable: false, anyMap: true, generateToJsonFunction: false) // referencing a top-level field should work @durationConverter // referencing via a const constructor should work @@ -168,7 +168,7 @@ class JsonConverterTestClass extends Object DateTime dateTime = DateTime(1981, 6, 5); } -@JsonSerializable(nullable: false) +@JsonSerializable(nullable: false, anyMap: true, generateToJsonFunction: false) @GenericConverter() class JsonConverterGeneric extends Object with _$JsonConverterGenericSerializerMixin { diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.wrapped.dart b/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.wrapped.dart index ce71687bc..10cef19a9 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.wrapped.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.wrapped.dart @@ -49,7 +49,11 @@ k.KitchenSink testFactory( k.KitchenSink testFromJson(Map json) => KitchenSink.fromJson(json); -@JsonSerializable(nullable: false) +@JsonSerializable( + useWrappers: true, + nullable: false, + anyMap: true, + generateToJsonFunction: false) class KitchenSink extends Object with _$KitchenSinkSerializerMixin implements k.KitchenSink { @@ -148,7 +152,11 @@ class KitchenSink extends Object bool operator ==(Object other) => k.sinkEquals(this, other); } -@JsonSerializable(nullable: false) +@JsonSerializable( + useWrappers: true, + nullable: false, + anyMap: true, + generateToJsonFunction: false) // referencing a top-level field should work @durationConverter // referencing via a const constructor should work @@ -174,7 +182,11 @@ class JsonConverterTestClass extends Object DateTime dateTime = DateTime(1981, 6, 5); } -@JsonSerializable(nullable: false) +@JsonSerializable( + useWrappers: true, + nullable: false, + anyMap: true, + generateToJsonFunction: false) @GenericConverter() class JsonConverterGeneric extends Object with _$JsonConverterGenericSerializerMixin { diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.wrapped.dart b/json_serializable/test/kitchen_sink/kitchen_sink.wrapped.dart index f8944e3a4..cbd1f81c6 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.wrapped.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.wrapped.dart @@ -43,7 +43,8 @@ k.KitchenSink testFactory( k.KitchenSink testFromJson(Map json) => KitchenSink.fromJson(json); -@JsonSerializable() +@JsonSerializable( + useWrappers: true, anyMap: true, generateToJsonFunction: false) class KitchenSink extends Object with _$KitchenSinkSerializerMixin implements k.KitchenSink { @@ -142,7 +143,8 @@ class KitchenSink extends Object bool operator ==(Object other) => k.sinkEquals(this, other); } -@JsonSerializable() +@JsonSerializable( + useWrappers: true, anyMap: true, generateToJsonFunction: false) // referencing a top-level field should work @durationConverter // referencing via a const constructor should work @@ -168,7 +170,8 @@ class JsonConverterTestClass extends Object DateTime dateTime; } -@JsonSerializable() +@JsonSerializable( + useWrappers: true, anyMap: true, generateToJsonFunction: false) @GenericConverter() class JsonConverterGeneric extends Object with _$JsonConverterGenericSerializerMixin { diff --git a/json_serializable/test/kitchen_sink/simple_object.dart b/json_serializable/test/kitchen_sink/simple_object.dart index a56cacaa2..dfa5ea6d5 100644 --- a/json_serializable/test/kitchen_sink/simple_object.dart +++ b/json_serializable/test/kitchen_sink/simple_object.dart @@ -6,7 +6,7 @@ import 'package:json_annotation/json_annotation.dart'; part 'simple_object.g.dart'; -@JsonSerializable() +@JsonSerializable(anyMap: true, generateToJsonFunction: false) class SimpleObject extends Object with _$SimpleObjectSerializerMixin { @override final int value; diff --git a/json_serializable/test/kitchen_sink/strict_keys_object.dart b/json_serializable/test/kitchen_sink/strict_keys_object.dart index ded038c99..4b72e942a 100644 --- a/json_serializable/test/kitchen_sink/strict_keys_object.dart +++ b/json_serializable/test/kitchen_sink/strict_keys_object.dart @@ -6,7 +6,8 @@ import 'package:json_annotation/json_annotation.dart'; part 'strict_keys_object.g.dart'; -@JsonSerializable(disallowUnrecognizedKeys: true) +@JsonSerializable( + disallowUnrecognizedKeys: true, anyMap: true, generateToJsonFunction: false) class StrictKeysObject extends Object with _$StrictKeysObjectSerializerMixin { @override @JsonKey(required: true) diff --git a/json_serializable/test/shared_config.dart b/json_serializable/test/shared_config.dart index 29b0db483..af0a87ced 100644 --- a/json_serializable/test/shared_config.dart +++ b/json_serializable/test/shared_config.dart @@ -3,31 +3,23 @@ // BSD-style license that can be found in the LICENSE file. import 'package:json_annotation/json_annotation.dart'; -import 'package:json_serializable/src/generator_config.dart'; -const jsonSerializableFields = [ - 'create_factory', - 'create_to_json', - 'disallow_unrecognized_keys', - 'include_if_null', - 'nullable', - 'field_rename', -]; +final jsonSerializableFields = generatorConfigDefaultJson.keys.toList(); -final generatorConfigDefaultJson = - Map.unmodifiable(const GeneratorConfig().toJson()); +final generatorConfigDefaultJson = Map.unmodifiable( + const JsonSerializable().withDefaults().toJson()); -final generatorConfigNonDefaultJson = Map.unmodifiable( - const GeneratorConfig( - createFactory: false, - fieldRename: FieldRename.kebab, - disallowUnrecognizedKeys: true, - nullable: false, - includeIfNull: false, - createToJson: false, - useWrappers: true, - explicitToJson: true, - generateToJsonFunction: false, - checked: true, - anyMap: true) - .toJson()); +final generatorConfigNonDefaultJson = + Map.unmodifiable(const JsonSerializable( + anyMap: true, + checked: true, + createFactory: false, + createToJson: false, + disallowUnrecognizedKeys: true, + explicitToJson: true, + fieldRename: FieldRename.kebab, + generateToJsonFunction: false, + includeIfNull: false, + nullable: false, + useWrappers: true, +).toJson()); diff --git a/json_serializable/test/src/configuration_input.dart b/json_serializable/test/src/configuration_input.dart index c7d17f722..d23f195e0 100644 --- a/json_serializable/test/src/configuration_input.dart +++ b/json_serializable/test/src/configuration_input.dart @@ -6,12 +6,18 @@ class ConfigurationImplicitDefaults { } @JsonSerializable( - createToJson: true, - includeIfNull: true, - nullable: true, - disallowUnrecognizedKeys: false, - fieldRename: FieldRename.none, - createFactory: true) + anyMap: false, + checked: false, + createFactory: true, + createToJson: true, + disallowUnrecognizedKeys: false, + explicitToJson: false, + fieldRename: FieldRename.none, + generateToJsonFunction: true, + includeIfNull: true, + nullable: true, + useWrappers: false, +) class ConfigurationExplicitDefaults { int field; } diff --git a/json_serializable/test/yaml/build_config.dart b/json_serializable/test/yaml/build_config.dart index e27b52f17..ce48d7a78 100644 --- a/json_serializable/test/yaml/build_config.dart +++ b/json_serializable/test/yaml/build_config.dart @@ -7,7 +7,7 @@ import 'package:meta/meta.dart'; part 'build_config.g.dart'; -@JsonSerializable() +@JsonSerializable(checked: true, anyMap: true) class Config { @JsonKey(required: true) final Map builders; @@ -18,10 +18,15 @@ class Config { Config({@required this.builders}); factory Config.fromJson(Map map) => _$ConfigFromJson(map); + Map toJson() => _$ConfigToJson(this); } -@JsonSerializable(includeIfNull: false, disallowUnrecognizedKeys: true) +@JsonSerializable( + includeIfNull: false, + disallowUnrecognizedKeys: true, + checked: true, + anyMap: true) class Builder { @JsonKey(nullable: true) final String target; diff --git a/json_serializable/tool/build.dart b/json_serializable/tool/build.dart deleted file mode 100755 index 6b3407164..000000000 --- a/json_serializable/tool/build.dart +++ /dev/null @@ -1,129 +0,0 @@ -#!/usr/bin/env dart --enable-asserts -// Copyright (c) 2015, 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 'dart:io' show exitCode; - -import 'package:build/build.dart'; -import 'package:build_config/build_config.dart'; -import 'package:build_runner/build_runner.dart'; -import 'package:build_runner_core/build_runner_core.dart'; -import 'package:build_test/builder.dart'; -import 'package:json_serializable/src/json_part_builder.dart' as jpb; -import 'package:json_serializable/src/generator_config.dart'; -import 'package:source_gen/builder.dart'; - -import 'builder.dart'; - -Builder _jsonPartBuilder({ - bool useWrappers, - bool anyMap, - bool checked, - bool format, - bool generateToJsonFunction, -}) { - format ??= true; - String Function(String code) formatOutput; - - if (!format) { - formatOutput = (s) => s; - } - - return jpb.jsonPartBuilder( - formatOutput: formatOutput, - config: GeneratorConfig( - useWrappers: useWrappers, - anyMap: anyMap, - checked: checked, - generateToJsonFunction: generateToJsonFunction)); -} - -final List builders = [ - applyToRoot(nonNull(), - generateFor: const InputSet(include: [ - 'test/kitchen_sink/kitchen_sink.dart', - 'test/integration/json_test_example.dart', - ])), - applyToRoot(checked(), - generateFor: const InputSet(include: [ - 'test/default_value/default_value.dart', - 'test/kitchen_sink/kitchen_sink.non_nullable.dart', - ])), - applyToRoot(wrapped(), - generateFor: const InputSet(include: [ - 'test/generic_files/generic_class.dart', - 'test/kitchen_sink/kitchen_sink.dart', - 'test/kitchen_sink/kitchen_sink.non_nullable.dart', - 'test/integration/json_test_example.dart', - 'test/integration/json_test_example.non_nullable.dart', - ])), - applyToRoot(_jsonPartBuilder(), - generateFor: const InputSet(include: [ - 'lib/src/generator_config.dart', - ]), - hideOutput: true), - applyToRoot(_jsonPartBuilder(), - generateFor: const InputSet( - include: [ - 'example/example.dart', - 'test/default_value/default_value.dart', - 'test/generic_files/generic_class.dart', - 'test/integration/json_test_example.dart', - 'test/integration/json_test_example.non_nullable.dart', - 'test/literal/json_literal.dart', - ], - ), - hideOutput: true), - applyToRoot(_jsonPartBuilder(anyMap: true, generateToJsonFunction: false), - generateFor: const InputSet( - include: [ - 'test/kitchen_sink/kitchen_sink.dart', - 'test/kitchen_sink/kitchen_sink.non_nullable.dart', - 'test/kitchen_sink/simple_object.dart', - 'test/kitchen_sink/strict_keys_object.dart', - ], - ), - hideOutput: true), - applyToRoot( - _jsonPartBuilder( - checked: true, anyMap: true, generateToJsonFunction: false), - generateFor: const InputSet( - include: [ - 'test/kitchen_sink/kitchen_sink.non_nullable.checked.dart', - ], - ), - hideOutput: true), - applyToRoot(_jsonPartBuilder(checked: true, anyMap: true), - generateFor: const InputSet( - include: [ - 'test/yaml/build_config.dart', - 'test/default_value/default_value.checked.dart', - ], - ), - hideOutput: true), - applyToRoot(_jsonPartBuilder(useWrappers: true), - generateFor: const InputSet( - include: [ - 'test/integration/json_test_example*wrapped.dart', - 'test/generic_files/generic_class*wrapped.dart', - ], - ), - hideOutput: true), - applyToRoot( - _jsonPartBuilder( - useWrappers: true, anyMap: true, generateToJsonFunction: false), - generateFor: const InputSet( - include: [ - 'test/kitchen_sink/kitchen_sink*wrapped.dart', - ], - ), - hideOutput: true), - applyToRoot(combiningBuilder()), - applyToRoot(testBootstrapBuilder(null), - generateFor: const InputSet(include: ['test/**']), hideOutput: true), -]; - -void main(List args) async { - exitCode = await run(args, builders); -} diff --git a/json_serializable/tool/builder.dart b/json_serializable/tool/builder.dart index 270cdcddf..482436e99 100644 --- a/json_serializable/tool/builder.dart +++ b/json_serializable/tool/builder.dart @@ -3,8 +3,8 @@ // BSD-style license that can be found in the LICENSE file. import 'dart:async'; -import 'package:build/build.dart'; +import 'package:build/build.dart'; import 'package:path/path.dart' as p; import 'package:source_gen/source_gen.dart'; @@ -38,7 +38,7 @@ class _NonNullableGenerator extends Generator { "part '$baseName.g.dart", "part '$baseName.non_nullable.g.dart", ), - _Replacement('@JsonSerializable()', '@JsonSerializable(nullable: false)'), + _Replacement('@JsonSerializable(', '@JsonSerializable(nullable: false,'), ]; if (baseName == 'kitchen_sink') { @@ -72,6 +72,7 @@ class _CheckedGenerator extends Generator { final content = await buildStep.readAsString(buildStep.inputId); final replacements = [ + _Replacement('@JsonSerializable(', '@JsonSerializable(checked: true,'), _Replacement(_copyrightContent, ''), _Replacement( "part '$baseName.g.dart", @@ -79,6 +80,12 @@ class _CheckedGenerator extends Generator { ), ]; + if (baseName == 'default_value') { + replacements.add( + _Replacement('@JsonSerializable(', '@JsonSerializable(anyMap: true,'), + ); + } + return _Replacement.generate(content, replacements); } } @@ -96,6 +103,8 @@ class _WrappedGenerator extends Generator { "part '$baseName.g.dart", "part '$baseName.wrapped.g.dart", ), + _Replacement( + '@JsonSerializable(', '@JsonSerializable(useWrappers: true,'), ]; return _Replacement.generate(content, replacements); From b2a274e315c1f78530c3fa4d64c42c4ebd106079 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Fri, 12 Oct 2018 10:51:56 -0700 Subject: [PATCH 018/569] Move json_key and json_value into their own file --- json_annotation/lib/json_annotation.dart | 2 + json_annotation/lib/src/json_key.dart | 113 +++++++++++++++++ .../lib/src/json_serializable.dart | 119 +----------------- json_annotation/lib/src/json_value.dart | 13 ++ 4 files changed, 129 insertions(+), 118 deletions(-) create mode 100644 json_annotation/lib/src/json_key.dart create mode 100644 json_annotation/lib/src/json_value.dart diff --git a/json_annotation/lib/json_annotation.dart b/json_annotation/lib/json_annotation.dart index fd1390e8c..1e7e58d9c 100644 --- a/json_annotation/lib/json_annotation.dart +++ b/json_annotation/lib/json_annotation.dart @@ -13,6 +13,8 @@ library json_annotation; export 'src/allowed_keys_helpers.dart'; export 'src/checked_helpers.dart'; export 'src/json_converter.dart'; +export 'src/json_key.dart'; export 'src/json_literal.dart'; export 'src/json_serializable.dart'; +export 'src/json_value.dart'; export 'src/wrapper_helpers.dart'; diff --git a/json_annotation/lib/src/json_key.dart b/json_annotation/lib/src/json_key.dart new file mode 100644 index 000000000..57b6e86b0 --- /dev/null +++ b/json_annotation/lib/src/json_key.dart @@ -0,0 +1,113 @@ +// Copyright (c) 2018, 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 'json_serializable.dart'; + +/// An annotation used to specify how a field is serialized. +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; + + /// When `true`, `null` values are handled gracefully when + /// serializing the field to JSON and when deserializing `null` and + /// nonexistent values from a JSON map. + /// + /// Setting to `false` eliminates `null` verification in the generated code + /// for the annotated field, which reduces the code size. Errors may be thrown + /// at runtime if `null` values are encountered, but the original class should + /// also implement `null` runtime validation if it's critical. + /// + /// The default value, `null`, indicates that the behavior should be + /// acquired from the [JsonSerializable.nullable] annotation on the + /// enclosing class. + final bool nullable; + + /// `true` if the generator should include the this field in the serialized + /// output, even if the value is `null`. + /// + /// The default value, `null`, indicates that the behavior should be + /// acquired from the [JsonSerializable.includeIfNull] annotation on the + /// enclosing class. + /// + /// If [disallowNullValue] is `true`, this value is treated as `false` to + /// ensure compatibility between `toJson` and `fromJson`. + /// + /// If both [includeIfNull] and [disallowNullValue] are set to `true` on the + /// same field, an exception will be thrown during code generation. + final bool includeIfNull; + + /// `true` if the generator should ignore this field completely. + /// + /// If `null` (the default) or `false`, the field will be considered for + /// serialization. + final bool ignore; + + /// A top-level [Function] to use when deserializing the associated JSON + /// value to the annotated field. + /// + /// The [Function] should take one argument that maps to the expected JSON + /// value and return a value that can be assigned to the type of the annotated + /// field. + /// + /// When creating a class that supports both `toJson` and `fromJson` + /// (the default), you should also set [toJson] if you set [fromJson]. + /// Values returned by [toJson] should "round-trip" through [fromJson]. + final Function fromJson; + + /// A top-level [Function] to use when serializing the annotated field to + /// JSON. + /// + /// The [Function] should take one argument that is compatible with the field + /// being serialized and return a JSON-compatible value. + /// + /// When creating a class that supports both `toJson` and `fromJson` + /// (the default), you should also set [fromJson] if you set [toJson]. + /// Values returned by [toJson] should "round-trip" through [fromJson]. + final Function toJson; + + /// The value to use if the source JSON does not contain this key or if the + /// value is `null`. + final Object defaultValue; + + /// When `true`, generated code for `fromJson` will verify that the source + /// JSON map contains the associated key. + /// + /// If the key does not exist, a `MissingRequiredKeysException` exception is + /// thrown. + /// + /// Note: only the existence of the key is checked. A key with a `null` value + /// is considered valid. + final bool required; + + /// If `true`, generated code will throw a `DisallowedNullValueException` if + /// the corresponding key exits, but the value is `null`. + /// + /// Note: this value does not affect the behavior of a JSON map *without* the + /// associated key. + /// + /// If [disallowNullValue] is `true`, [includeIfNull] will be treated as + /// `false` to ensure compatibility between `toJson` and `fromJson`. + /// + /// If both [includeIfNull] and [disallowNullValue] are set to `true` on the + /// same field, an exception will be thrown during code generation. + final bool disallowNullValue; + + /// Creates a new [JsonKey] instance. + /// + /// Only required when the default behavior is not desired. + const JsonKey({ + this.name, + this.nullable, + this.includeIfNull, + this.ignore, + this.fromJson, + this.toJson, + this.defaultValue, + this.required, + this.disallowNullValue, + }); +} diff --git a/json_annotation/lib/src/json_serializable.dart b/json_annotation/lib/src/json_serializable.dart index 66a4f3729..b44f9a1fd 100644 --- a/json_annotation/lib/src/json_serializable.dart +++ b/json_annotation/lib/src/json_serializable.dart @@ -4,6 +4,7 @@ import 'allowed_keys_helpers.dart'; import 'checked_helpers.dart'; +import 'json_key.dart'; part 'json_serializable.g.dart'; @@ -227,121 +228,3 @@ class JsonSerializable { Map toJson() => _$JsonSerializableToJson(this); } - -/// An annotation used to specify how a field is serialized. -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; - - /// When `true`, `null` values are handled gracefully when - /// serializing the field to JSON and when deserializing `null` and - /// nonexistent values from a JSON map. - /// - /// Setting to `false` eliminates `null` verification in the generated code - /// for the annotated field, which reduces the code size. Errors may be thrown - /// at runtime if `null` values are encountered, but the original class should - /// also implement `null` runtime validation if it's critical. - /// - /// The default value, `null`, indicates that the behavior should be - /// acquired from the [JsonSerializable.nullable] annotation on the - /// enclosing class. - final bool nullable; - - /// `true` if the generator should include the this field in the serialized - /// output, even if the value is `null`. - /// - /// The default value, `null`, indicates that the behavior should be - /// acquired from the [JsonSerializable.includeIfNull] annotation on the - /// enclosing class. - /// - /// If [disallowNullValue] is `true`, this value is treated as `false` to - /// ensure compatibility between `toJson` and `fromJson`. - /// - /// If both [includeIfNull] and [disallowNullValue] are set to `true` on the - /// same field, an exception will be thrown during code generation. - final bool includeIfNull; - - /// `true` if the generator should ignore this field completely. - /// - /// If `null` (the default) or `false`, the field will be considered for - /// serialization. - final bool ignore; - - /// A top-level [Function] to use when deserializing the associated JSON - /// value to the annotated field. - /// - /// The [Function] should take one argument that maps to the expected JSON - /// value and return a value that can be assigned to the type of the annotated - /// field. - /// - /// When creating a class that supports both `toJson` and `fromJson` - /// (the default), you should also set [toJson] if you set [fromJson]. - /// Values returned by [toJson] should "round-trip" through [fromJson]. - final Function fromJson; - - /// A top-level [Function] to use when serializing the annotated field to - /// JSON. - /// - /// The [Function] should take one argument that is compatible with the field - /// being serialized and return a JSON-compatible value. - /// - /// When creating a class that supports both `toJson` and `fromJson` - /// (the default), you should also set [fromJson] if you set [toJson]. - /// Values returned by [toJson] should "round-trip" through [fromJson]. - final Function toJson; - - /// The value to use if the source JSON does not contain this key or if the - /// value is `null`. - final Object defaultValue; - - /// When `true`, generated code for `fromJson` will verify that the source - /// JSON map contains the associated key. - /// - /// If the key does not exist, a `MissingRequiredKeysException` exception is - /// thrown. - /// - /// Note: only the existence of the key is checked. A key with a `null` value - /// is considered valid. - final bool required; - - /// If `true`, generated code will throw a `DisallowedNullValueException` if - /// the corresponding key exits, but the value is `null`. - /// - /// Note: this value does not affect the behavior of a JSON map *without* the - /// associated key. - /// - /// If [disallowNullValue] is `true`, [includeIfNull] will be treated as - /// `false` to ensure compatibility between `toJson` and `fromJson`. - /// - /// If both [includeIfNull] and [disallowNullValue] are set to `true` on the - /// same field, an exception will be thrown during code generation. - final bool disallowNullValue; - - /// Creates a new [JsonKey] instance. - /// - /// Only required when the default behavior is not desired. - const JsonKey({ - this.name, - this.nullable, - this.includeIfNull, - this.ignore, - this.fromJson, - this.toJson, - this.defaultValue, - this.required, - this.disallowNullValue, - }); -} - -/// An annotation used to specify how a enum value is serialized. -class JsonValue { - /// The value to use when serializing and deserializing. - /// - /// Can be a [String] or an [int]. - final dynamic value; - - const JsonValue(this.value); -} diff --git a/json_annotation/lib/src/json_value.dart b/json_annotation/lib/src/json_value.dart new file mode 100644 index 000000000..4e5cb4f2b --- /dev/null +++ b/json_annotation/lib/src/json_value.dart @@ -0,0 +1,13 @@ +// Copyright (c) 2018, 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. + +/// An annotation used to specify how a enum value is serialized. +class JsonValue { + /// The value to use when serializing and deserializing. + /// + /// Can be a [String] or an [int]. + final dynamic value; + + const JsonValue(this.value); +} From 888f6a96e433a6c7896ac7a5aa28b3572903c7a8 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 15 Oct 2018 10:12:05 -0700 Subject: [PATCH 019/569] Failing test for nullable support in JsonConverter logic --- .../test/kitchen_sink/json_converters.dart | 20 ++++---- .../test/kitchen_sink/kitchen_sink_test.dart | 46 +++++++++++++++++-- 2 files changed, 51 insertions(+), 15 deletions(-) diff --git a/json_serializable/test/kitchen_sink/json_converters.dart b/json_serializable/test/kitchen_sink/json_converters.dart index d927ba5f3..11779f98f 100644 --- a/json_serializable/test/kitchen_sink/json_converters.dart +++ b/json_serializable/test/kitchen_sink/json_converters.dart @@ -9,12 +9,14 @@ class GenericConverter implements JsonConverter> { @override T fromJson(Map json) => null; + @override Map toJson(T object) => {}; } class TrivialNumber { final int value; + TrivialNumber(this.value); } @@ -24,20 +26,20 @@ class TrivialNumberConverter implements JsonConverter { const TrivialNumberConverter(); @override - TrivialNumber fromJson(int json) => json == null ? null : TrivialNumber(json); + TrivialNumber fromJson(int json) => TrivialNumber(json); @override - int toJson(TrivialNumber object) => object?.value; + int toJson(TrivialNumber object) => object.value; } class BigIntStringConverter implements JsonConverter { const BigIntStringConverter(); @override - BigInt fromJson(String json) => json == null ? null : BigInt.parse(json); + BigInt fromJson(String json) => BigInt.parse(json); @override - String toJson(BigInt object) => object?.toString(); + String toJson(BigInt object) => object.toString(); } const durationConverter = DurationMillisecondConverter(); @@ -46,20 +48,18 @@ class DurationMillisecondConverter implements JsonConverter { const DurationMillisecondConverter(); @override - Duration fromJson(int json) => - json == null ? null : Duration(milliseconds: json); + Duration fromJson(int json) => Duration(milliseconds: json); @override - int toJson(Duration object) => object?.inMilliseconds; + int toJson(Duration object) => object.inMilliseconds; } class EpochDateTimeConverter implements JsonConverter { const EpochDateTimeConverter(); @override - DateTime fromJson(int json) => - json == null ? null : DateTime.fromMillisecondsSinceEpoch(json); + DateTime fromJson(int json) => DateTime.fromMillisecondsSinceEpoch(json); @override - int toJson(DateTime object) => object?.millisecondsSinceEpoch; + int toJson(DateTime object) => object.millisecondsSinceEpoch; } diff --git a/json_serializable/test/kitchen_sink/kitchen_sink_test.dart b/json_serializable/test/kitchen_sink/kitchen_sink_test.dart index 3ec047863..fd8063597 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink_test.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink_test.dart @@ -2,20 +2,20 @@ // 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:test/test.dart'; - import 'package:json_annotation/json_annotation.dart'; +import 'package:test/test.dart'; import 'package:yaml/yaml.dart'; import '../test_utils.dart'; -import 'kitchen_sink.dart' as nullable show testFactory, testFromJson; +import 'kitchen_sink.dart' as nullable + show testFactory, testFromJson, JsonConverterTestClass; import 'kitchen_sink.non_nullable.checked.dart' as checked show testFactory, testFromJson; -import 'kitchen_sink.non_nullable.dart' as nn show testFactory, testFromJson; +import 'kitchen_sink.non_nullable.dart' as nn + show testFactory, testFromJson, JsonConverterTestClass; import 'kitchen_sink.non_nullable.wrapped.dart' as nnwrapped show testFactory, testFromJson; import 'kitchen_sink.wrapped.dart' as wrapped show testFactory, testFromJson; - import 'kitchen_sink_interface.dart'; import 'strict_keys_object.dart'; @@ -69,6 +69,42 @@ void main() { _nonNullableTests(nnwrapped.testFactory, nnwrapped.testFromJson); }); }); + + group('JsonConverterTestClass', () { + final validValues = { + 'duration': 5, + 'durationList': [5], + 'bigInt': '5', + 'bigIntMap': {'vaule': '5'}, + 'numberSilly': 5, + 'numberSillySet': [5], + 'dateTime': 5 + }; + + test('nullable values are allowed in the nullable version', () { + var instance = nullable.JsonConverterTestClass(); + var json = instance.toJson(); + expect(json.values, everyElement(isNull)); + expect(json.keys, unorderedEquals(validValues.keys)); + + var instance2 = nullable.JsonConverterTestClass.fromJson(json); + expect(instance2.toJson(), json); + }); + + test('nullable values are not allowed in non-nullable version', () { + var instance = nn.JsonConverterTestClass(); + expect(() => instance.toJson(), throwsNoSuchMethodError, + reason: 'Trying to call `map` on a null list'); + + instance = nn.JsonConverterTestClass.fromJson(validValues); + var json = instance.toJson(); + expect(json, validValues); + expect(json.values, everyElement(isNotNull)); + + var instance2 = nn.JsonConverterTestClass.fromJson(json); + expect(instance2.toJson(), json); + }); + }); } typedef KitchenSink KitchenSinkCtor( From d957fb69356eb93f5453aa13b4c911730002b3e5 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 15 Oct 2018 09:22:09 -0700 Subject: [PATCH 020/569] Correctly support nullable fields with JsonConvert --- json_serializable/CHANGELOG.md | 3 + json_serializable/lib/src/type_helper.dart | 4 +- .../lib/src/type_helpers/convert_helper.dart | 4 +- .../src/type_helpers/date_time_helper.dart | 6 +- .../lib/src/type_helpers/duration_helper.dart | 2 +- .../type_helpers/json_converter_helper.dart | 15 ++-- .../lib/src/type_helpers/json_helper.dart | 2 +- .../lib/src/type_helpers/uri_helper.dart | 4 +- .../test/generic_files/generic_class.g.dart | 41 ++++++---- .../generic_class.wrapped.g.dart | 40 +++++++--- .../test/kitchen_sink/kitchen_sink.g.dart | 79 ++++++++++++------ .../kitchen_sink/kitchen_sink.wrapped.g.dart | 80 ++++++++++++------- .../test/src/json_converter_test_input.dart | 64 +++++++++------ 13 files changed, 226 insertions(+), 118 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index e0000f688..50731abf5 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,5 +1,8 @@ ## 2.0.0 +* Code generated for fields and classes annotated with `JsonConverter` instances + now properly handles nullable fields. + * Build configuration * You can now configure all settings exposed by the `JsonSerializable` diff --git a/json_serializable/lib/src/type_helper.dart b/json_serializable/lib/src/type_helper.dart index f34845137..d38c1b2e3 100644 --- a/json_serializable/lib/src/type_helper.dart +++ b/json_serializable/lib/src/type_helper.dart @@ -105,8 +105,8 @@ class UnsupportedTypeError extends Error { UnsupportedTypeError(this.type, this.expression, this.reason); } -String commonNullPrefix( - bool nullable, String expression, String unsafeExpression) => +Object commonNullPrefix( + bool nullable, String expression, Object unsafeExpression) => nullable ? '$expression == null ? null : $unsafeExpression' : unsafeExpression; diff --git a/json_serializable/lib/src/type_helpers/convert_helper.dart b/json_serializable/lib/src/type_helpers/convert_helper.dart index 218be515e..8d353c4e6 100644 --- a/json_serializable/lib/src/type_helpers/convert_helper.dart +++ b/json_serializable/lib/src/type_helpers/convert_helper.dart @@ -32,7 +32,7 @@ class ConvertHelper extends TypeHelper { assert(toJsonData.paramType is TypeParameterType || targetType.isAssignableTo(toJsonData.paramType)); final result = '${toJsonData.name}($expression)'; - return commonNullPrefix(context.nullable, expression, result); + return commonNullPrefix(context.nullable, expression, result).toString(); } return null; } @@ -44,7 +44,7 @@ class ConvertHelper extends TypeHelper { if (fromJsonData != null) { final asContent = asStatement(fromJsonData.paramType); final result = '${fromJsonData.name}($expression$asContent)'; - return commonNullPrefix(context.nullable, expression, result); + return commonNullPrefix(context.nullable, expression, result).toString(); } return null; } diff --git a/json_serializable/lib/src/type_helpers/date_time_helper.dart b/json_serializable/lib/src/type_helpers/date_time_helper.dart index bca740106..d66f05ee9 100644 --- a/json_serializable/lib/src/type_helpers/date_time_helper.dart +++ b/json_serializable/lib/src/type_helpers/date_time_helper.dart @@ -4,6 +4,7 @@ import 'package:analyzer/dart/element/type.dart'; import 'package:source_gen/source_gen.dart' show TypeChecker; + import '../type_helper.dart'; class DateTimeHelper extends TypeHelper { @@ -34,8 +35,9 @@ class DateTimeHelper extends TypeHelper { return null; } - return commonNullPrefix( - context.nullable, expression, 'DateTime.parse($expression as String)'); + return commonNullPrefix(context.nullable, expression, + 'DateTime.parse($expression as String)') + .toString(); } } diff --git a/json_serializable/lib/src/type_helpers/duration_helper.dart b/json_serializable/lib/src/type_helpers/duration_helper.dart index 23637431d..64d999d71 100644 --- a/json_serializable/lib/src/type_helpers/duration_helper.dart +++ b/json_serializable/lib/src/type_helpers/duration_helper.dart @@ -38,7 +38,7 @@ class DurationHelper extends TypeHelper { context.nullable, expression, 'Duration(microseconds: $expression as int)', - ); + ).toString(); } } diff --git a/json_serializable/lib/src/type_helpers/json_converter_helper.dart b/json_serializable/lib/src/type_helpers/json_converter_helper.dart index 13599b5ce..d7f5a42c0 100644 --- a/json_serializable/lib/src/type_helpers/json_converter_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_converter_helper.dart @@ -5,7 +5,6 @@ import 'package:analyzer/dart/constant/value.dart'; import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/type.dart'; - import 'package:json_annotation/json_annotation.dart'; import 'package:source_gen/source_gen.dart'; @@ -18,7 +17,7 @@ class JsonConverterHelper extends TypeHelper { const JsonConverterHelper(); @override - LambdaResult serialize( + Object serialize( DartType targetType, String expression, TypeHelperContext context) { final converter = _typeConverter(targetType, context); @@ -26,11 +25,12 @@ class JsonConverterHelper extends TypeHelper { return null; } - return LambdaResult(expression, '${converter.accessString}.toJson'); + return commonNullPrefix(context.nullable, expression, + LambdaResult(expression, '${converter.accessString}.toJson')); } @override - LambdaResult deserialize( + Object deserialize( DartType targetType, String expression, TypeHelperContext context) { final converter = _typeConverter(targetType, context); if (converter == null) { @@ -39,8 +39,11 @@ class JsonConverterHelper extends TypeHelper { final asContent = asStatement(converter.jsonType); - return LambdaResult( - '$expression$asContent', '${converter.accessString}.fromJson'); + return commonNullPrefix( + context.nullable, + expression, + LambdaResult( + '$expression$asContent', '${converter.accessString}.fromJson')); } } diff --git a/json_serializable/lib/src/type_helpers/json_helper.dart b/json_serializable/lib/src/type_helpers/json_helper.dart index 26e634a85..284478812 100644 --- a/json_serializable/lib/src/type_helpers/json_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_helper.dart @@ -63,7 +63,7 @@ class JsonHelper extends TypeHelper { // github.com/dart-lang/json_serializable/issues/19 final result = '${targetType.name}.fromJson($expression$asCast)'; - return commonNullPrefix(context.nullable, expression, result); + return commonNullPrefix(context.nullable, expression, result).toString(); } } diff --git a/json_serializable/lib/src/type_helpers/uri_helper.dart b/json_serializable/lib/src/type_helpers/uri_helper.dart index bec376f50..e7c94854e 100644 --- a/json_serializable/lib/src/type_helpers/uri_helper.dart +++ b/json_serializable/lib/src/type_helpers/uri_helper.dart @@ -4,6 +4,7 @@ import 'package:analyzer/dart/element/type.dart'; import 'package:source_gen/source_gen.dart' show TypeChecker; + import '../type_helper.dart'; class UriHelper extends TypeHelper { @@ -35,7 +36,8 @@ class UriHelper extends TypeHelper { } return commonNullPrefix( - context.nullable, expression, 'Uri.parse($expression as String)'); + context.nullable, expression, 'Uri.parse($expression as String)') + .toString(); } } diff --git a/json_serializable/test/generic_files/generic_class.g.dart b/json_serializable/test/generic_files/generic_class.g.dart index ca340be6e..ebd98f635 100644 --- a/json_serializable/test/generic_files/generic_class.g.dart +++ b/json_serializable/test/generic_files/generic_class.g.dart @@ -55,14 +55,20 @@ GenericClassWithConverter ..fieldObject = json['fieldObject'] ..fieldDynamic = json['fieldDynamic'] ..fieldInt = json['fieldInt'] as int - ..fieldT = - _SimpleConverter().fromJson(json['fieldT'] as Map) - ..fieldS = - _SimpleConverter().fromJson(json['fieldS'] as Map) - ..duration = - const _DurationMillisecondConverter().fromJson(json['duration'] as int) - ..listDuration = const _DurationListMillisecondConverter() - .fromJson(json['listDuration'] as int); + ..fieldT = json['fieldT'] == null + ? null + : _SimpleConverter().fromJson(json['fieldT'] as Map) + ..fieldS = json['fieldS'] == null + ? null + : _SimpleConverter().fromJson(json['fieldS'] as Map) + ..duration = json['duration'] == null + ? null + : const _DurationMillisecondConverter() + .fromJson(json['duration'] as int) + ..listDuration = json['listDuration'] == null + ? null + : const _DurationListMillisecondConverter() + .fromJson(json['listDuration'] as int); } Map _$GenericClassWithConverterToJson( @@ -71,10 +77,17 @@ Map _$GenericClassWithConverterToJson( 'fieldObject': instance.fieldObject, 'fieldDynamic': instance.fieldDynamic, 'fieldInt': instance.fieldInt, - 'fieldT': _SimpleConverter().toJson(instance.fieldT), - 'fieldS': _SimpleConverter().toJson(instance.fieldS), - 'duration': - const _DurationMillisecondConverter().toJson(instance.duration), - 'listDuration': const _DurationListMillisecondConverter() - .toJson(instance.listDuration) + 'fieldT': instance.fieldT == null + ? null + : _SimpleConverter().toJson(instance.fieldT), + 'fieldS': instance.fieldS == null + ? null + : _SimpleConverter().toJson(instance.fieldS), + 'duration': instance.duration == null + ? null + : const _DurationMillisecondConverter().toJson(instance.duration), + 'listDuration': instance.listDuration == null + ? null + : const _DurationListMillisecondConverter() + .toJson(instance.listDuration) }; diff --git a/json_serializable/test/generic_files/generic_class.wrapped.g.dart b/json_serializable/test/generic_files/generic_class.wrapped.g.dart index 35a42d6c6..395904adf 100644 --- a/json_serializable/test/generic_files/generic_class.wrapped.g.dart +++ b/json_serializable/test/generic_files/generic_class.wrapped.g.dart @@ -73,14 +73,20 @@ GenericClassWithConverter ..fieldObject = json['fieldObject'] ..fieldDynamic = json['fieldDynamic'] ..fieldInt = json['fieldInt'] as int - ..fieldT = - _SimpleConverter().fromJson(json['fieldT'] as Map) - ..fieldS = - _SimpleConverter().fromJson(json['fieldS'] as Map) - ..duration = - const _DurationMillisecondConverter().fromJson(json['duration'] as int) - ..listDuration = const _DurationListMillisecondConverter() - .fromJson(json['listDuration'] as int); + ..fieldT = json['fieldT'] == null + ? null + : _SimpleConverter().fromJson(json['fieldT'] as Map) + ..fieldS = json['fieldS'] == null + ? null + : _SimpleConverter().fromJson(json['fieldS'] as Map) + ..duration = json['duration'] == null + ? null + : const _DurationMillisecondConverter() + .fromJson(json['duration'] as int) + ..listDuration = json['listDuration'] == null + ? null + : const _DurationListMillisecondConverter() + .fromJson(json['listDuration'] as int); } Map _$GenericClassWithConverterToJson( @@ -114,14 +120,22 @@ class _$GenericClassWithConverterJsonMapWrapper case 'fieldInt': return _v.fieldInt; case 'fieldT': - return _SimpleConverter().toJson(_v.fieldT); + return _v.fieldT == null + ? null + : _SimpleConverter().toJson(_v.fieldT); case 'fieldS': - return _SimpleConverter().toJson(_v.fieldS); + return _v.fieldS == null + ? null + : _SimpleConverter().toJson(_v.fieldS); case 'duration': - return const _DurationMillisecondConverter().toJson(_v.duration); + return _v.duration == null + ? null + : const _DurationMillisecondConverter().toJson(_v.duration); case 'listDuration': - return const _DurationListMillisecondConverter() - .toJson(_v.listDuration); + return _v.listDuration == null + ? null + : const _DurationListMillisecondConverter() + .toJson(_v.listDuration); } } return null; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g.dart index 43f19ed37..04d402dee 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g.dart @@ -141,20 +141,29 @@ abstract class _$KitchenSinkSerializerMixin { JsonConverterTestClass _$JsonConverterTestClassFromJson(Map json) { return JsonConverterTestClass() - ..duration = durationConverter.fromJson(json['duration'] as int) + ..duration = json['duration'] == null + ? null + : durationConverter.fromJson(json['duration'] as int) ..durationList = (json['durationList'] as List) - ?.map((e) => durationConverter.fromJson(e as int)) + ?.map((e) => e == null ? null : durationConverter.fromJson(e as int)) ?.toList() - ..bigInt = const BigIntStringConverter().fromJson(json['bigInt'] as String) + ..bigInt = json['bigInt'] == null + ? null + : const BigIntStringConverter().fromJson(json['bigInt'] as String) ..bigIntMap = (json['bigIntMap'] as Map)?.map((k, e) => MapEntry( - k as String, const BigIntStringConverter().fromJson(e as String))) - ..numberSilly = - TrivialNumberConverter.instance.fromJson(json['numberSilly'] as int) + k as String, + e == null ? null : const BigIntStringConverter().fromJson(e as String))) + ..numberSilly = json['numberSilly'] == null + ? null + : TrivialNumberConverter.instance.fromJson(json['numberSilly'] as int) ..numberSillySet = (json['numberSillySet'] as List) - ?.map((e) => TrivialNumberConverter.instance.fromJson(e as int)) + ?.map((e) => e == null + ? null + : TrivialNumberConverter.instance.fromJson(e as int)) ?.toSet() - ..dateTime = - const EpochDateTimeConverter().fromJson(json['dateTime'] as int); + ..dateTime = json['dateTime'] == null + ? null + : const EpochDateTimeConverter().fromJson(json['dateTime'] as int); } abstract class _$JsonConverterTestClassSerializerMixin { @@ -166,29 +175,45 @@ abstract class _$JsonConverterTestClassSerializerMixin { Set get numberSillySet; DateTime get dateTime; Map toJson() => { - 'duration': durationConverter.toJson(duration), - 'durationList': durationList?.map(durationConverter.toJson)?.toList(), - 'bigInt': const BigIntStringConverter().toJson(bigInt), - 'bigIntMap': bigIntMap?.map( - (k, e) => MapEntry(k, const BigIntStringConverter().toJson(e))), - 'numberSilly': TrivialNumberConverter.instance.toJson(numberSilly), + 'duration': + duration == null ? null : durationConverter.toJson(duration), + 'durationList': durationList + ?.map((e) => e == null ? null : durationConverter.toJson(e)) + ?.toList(), + 'bigInt': bigInt == null + ? null + : const BigIntStringConverter().toJson(bigInt), + 'bigIntMap': bigIntMap?.map((k, e) => MapEntry( + k, e == null ? null : const BigIntStringConverter().toJson(e))), + 'numberSilly': numberSilly == null + ? null + : TrivialNumberConverter.instance.toJson(numberSilly), 'numberSillySet': numberSillySet - ?.map(TrivialNumberConverter.instance.toJson) + ?.map((e) => + e == null ? null : TrivialNumberConverter.instance.toJson(e)) ?.toList(), - 'dateTime': const EpochDateTimeConverter().toJson(dateTime) + 'dateTime': dateTime == null + ? null + : const EpochDateTimeConverter().toJson(dateTime) }; } JsonConverterGeneric _$JsonConverterGenericFromJson( Map json) { return JsonConverterGeneric() - ..item = - GenericConverter().fromJson(json['item'] as Map) + ..item = json['item'] == null + ? null + : GenericConverter().fromJson(json['item'] as Map) ..itemList = (json['itemList'] as List) - ?.map((e) => GenericConverter().fromJson(e as Map)) + ?.map((e) => e == null + ? null + : GenericConverter().fromJson(e as Map)) ?.toList() - ..itemMap = (json['itemMap'] as Map)?.map((k, e) => MapEntry(k as String, - GenericConverter().fromJson(e as Map))); + ..itemMap = (json['itemMap'] as Map)?.map((k, e) => MapEntry( + k as String, + e == null + ? null + : GenericConverter().fromJson(e as Map))); } abstract class _$JsonConverterGenericSerializerMixin { @@ -196,9 +221,11 @@ abstract class _$JsonConverterGenericSerializerMixin { List get itemList; Map get itemMap; Map toJson() => { - 'item': GenericConverter().toJson(item), - 'itemList': itemList?.map(GenericConverter().toJson)?.toList(), - 'itemMap': - itemMap?.map((k, e) => MapEntry(k, GenericConverter().toJson(e))) + 'item': item == null ? null : GenericConverter().toJson(item), + 'itemList': itemList + ?.map((e) => e == null ? null : GenericConverter().toJson(e)) + ?.toList(), + 'itemMap': itemMap?.map((k, e) => + MapEntry(k, e == null ? null : GenericConverter().toJson(e))) }; } diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.wrapped.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.wrapped.g.dart index 5f12442f8..07396d5f5 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.wrapped.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.wrapped.g.dart @@ -214,20 +214,29 @@ class _$KitchenSinkJsonMapWrapper extends $JsonMapWrapper { JsonConverterTestClass _$JsonConverterTestClassFromJson(Map json) { return JsonConverterTestClass() - ..duration = durationConverter.fromJson(json['duration'] as int) + ..duration = json['duration'] == null + ? null + : durationConverter.fromJson(json['duration'] as int) ..durationList = (json['durationList'] as List) - ?.map((e) => durationConverter.fromJson(e as int)) + ?.map((e) => e == null ? null : durationConverter.fromJson(e as int)) ?.toList() - ..bigInt = const BigIntStringConverter().fromJson(json['bigInt'] as String) + ..bigInt = json['bigInt'] == null + ? null + : const BigIntStringConverter().fromJson(json['bigInt'] as String) ..bigIntMap = (json['bigIntMap'] as Map)?.map((k, e) => MapEntry( - k as String, const BigIntStringConverter().fromJson(e as String))) - ..numberSilly = - TrivialNumberConverter.instance.fromJson(json['numberSilly'] as int) + k as String, + e == null ? null : const BigIntStringConverter().fromJson(e as String))) + ..numberSilly = json['numberSilly'] == null + ? null + : TrivialNumberConverter.instance.fromJson(json['numberSilly'] as int) ..numberSillySet = (json['numberSillySet'] as List) - ?.map((e) => TrivialNumberConverter.instance.fromJson(e as int)) + ?.map((e) => e == null + ? null + : TrivialNumberConverter.instance.fromJson(e as int)) ?.toSet() - ..dateTime = - const EpochDateTimeConverter().fromJson(json['dateTime'] as int); + ..dateTime = json['dateTime'] == null + ? null + : const EpochDateTimeConverter().fromJson(json['dateTime'] as int); } abstract class _$JsonConverterTestClassSerializerMixin { @@ -261,23 +270,34 @@ class _$JsonConverterTestClassJsonMapWrapper extends $JsonMapWrapper { if (key is String) { switch (key) { case 'duration': - return durationConverter.toJson(_v.duration); + return _v.duration == null + ? null + : durationConverter.toJson(_v.duration); case 'durationList': - return $wrapListHandleNull( - _v.durationList, durationConverter.toJson); + return $wrapListHandleNull(_v.durationList, + (e) => e == null ? null : durationConverter.toJson(e)); case 'bigInt': - return const BigIntStringConverter().toJson(_v.bigInt); + return _v.bigInt == null + ? null + : const BigIntStringConverter().toJson(_v.bigInt); case 'bigIntMap': return $wrapMapHandleNull( - _v.bigIntMap, const BigIntStringConverter().toJson); + _v.bigIntMap, + (e) => + e == null ? null : const BigIntStringConverter().toJson(e)); case 'numberSilly': - return TrivialNumberConverter.instance.toJson(_v.numberSilly); + return _v.numberSilly == null + ? null + : TrivialNumberConverter.instance.toJson(_v.numberSilly); case 'numberSillySet': return _v.numberSillySet - ?.map(TrivialNumberConverter.instance.toJson) + ?.map((e) => + e == null ? null : TrivialNumberConverter.instance.toJson(e)) ?.toList(); case 'dateTime': - return const EpochDateTimeConverter().toJson(_v.dateTime); + return _v.dateTime == null + ? null + : const EpochDateTimeConverter().toJson(_v.dateTime); } } return null; @@ -287,13 +307,19 @@ class _$JsonConverterTestClassJsonMapWrapper extends $JsonMapWrapper { JsonConverterGeneric _$JsonConverterGenericFromJson( Map json) { return JsonConverterGeneric() - ..item = - GenericConverter().fromJson(json['item'] as Map) + ..item = json['item'] == null + ? null + : GenericConverter().fromJson(json['item'] as Map) ..itemList = (json['itemList'] as List) - ?.map((e) => GenericConverter().fromJson(e as Map)) + ?.map((e) => e == null + ? null + : GenericConverter().fromJson(e as Map)) ?.toList() - ..itemMap = (json['itemMap'] as Map)?.map((k, e) => MapEntry(k as String, - GenericConverter().fromJson(e as Map))); + ..itemMap = (json['itemMap'] as Map)?.map((k, e) => MapEntry( + k as String, + e == null + ? null + : GenericConverter().fromJson(e as Map))); } abstract class _$JsonConverterGenericSerializerMixin { @@ -316,13 +342,13 @@ class _$JsonConverterGenericJsonMapWrapper extends $JsonMapWrapper { if (key is String) { switch (key) { case 'item': - return GenericConverter().toJson(_v.item); + return _v.item == null ? null : GenericConverter().toJson(_v.item); case 'itemList': - return $wrapListHandleNull( - _v.itemList, GenericConverter().toJson); + return $wrapListHandleNull(_v.itemList, + (e) => e == null ? null : GenericConverter().toJson(e)); case 'itemMap': - return $wrapMapHandleNull( - _v.itemMap, GenericConverter().toJson); + return $wrapMapHandleNull(_v.itemMap, + (e) => e == null ? null : GenericConverter().toJson(e)); } } return null; diff --git a/json_serializable/test/src/json_converter_test_input.dart b/json_serializable/test/src/json_converter_test_input.dart index c56cf304a..19d647eda 100644 --- a/json_serializable/test/src/json_converter_test_input.dart +++ b/json_serializable/test/src/json_converter_test_input.dart @@ -8,10 +8,13 @@ part of '_json_serializable_test_input.dart'; JsonConverterNamedCtor _$JsonConverterNamedCtorFromJson( Map json) { return JsonConverterNamedCtor() - ..value = const _DurationMillisecondConverter.named() - .fromJson(json['value'] as int) - ..genericValue = - _GenericConverter.named().fromJson(json['genericValue'] as int) + ..value = json['value'] == null + ? null + : const _DurationMillisecondConverter.named() + .fromJson(json['value'] as int) + ..genericValue = json['genericValue'] == null + ? null + : _GenericConverter.named().fromJson(json['genericValue'] as int) ..keyAnnotationFirst = json['keyAnnotationFirst'] == null ? null : JsonConverterNamedCtor._fromJson(json['keyAnnotationFirst'] as int); @@ -20,10 +23,12 @@ JsonConverterNamedCtor _$JsonConverterNamedCtorFromJson( Map _$JsonConverterNamedCtorToJson( JsonConverterNamedCtor instance) => { - 'value': - const _DurationMillisecondConverter.named().toJson(instance.value), - 'genericValue': - _GenericConverter.named().toJson(instance.genericValue), + 'value': instance.value == null + ? null + : const _DurationMillisecondConverter.named().toJson(instance.value), + 'genericValue': instance.genericValue == null + ? null + : _GenericConverter.named().toJson(instance.genericValue), 'keyAnnotationFirst': instance.keyAnnotationFirst == null ? null : JsonConverterNamedCtor._toJson(instance.keyAnnotationFirst) @@ -48,26 +53,39 @@ class JsonConverterNamedCtor { JsonConvertOnField _$JsonConvertOnFieldFromJson( Map json) { return JsonConvertOnField() - ..annotatedField = const _DurationMillisecondConverter() - .fromJson(json['annotatedField'] as int) - ..annotatedWithNamedCtor = const _DurationMillisecondConverter.named() - .fromJson(json['annotatedWithNamedCtor'] as int) - ..classAnnotatedWithField = - _durationConverter.fromJson(json['classAnnotatedWithField'] as int) - ..genericValue = - _GenericConverter().fromJson(json['genericValue'] as int); + ..annotatedField = json['annotatedField'] == null + ? null + : const _DurationMillisecondConverter() + .fromJson(json['annotatedField'] as int) + ..annotatedWithNamedCtor = json['annotatedWithNamedCtor'] == null + ? null + : const _DurationMillisecondConverter.named() + .fromJson(json['annotatedWithNamedCtor'] as int) + ..classAnnotatedWithField = json['classAnnotatedWithField'] == null + ? null + : _durationConverter.fromJson(json['classAnnotatedWithField'] as int) + ..genericValue = json['genericValue'] == null + ? null + : _GenericConverter().fromJson(json['genericValue'] as int); } Map _$JsonConvertOnFieldToJson( JsonConvertOnField instance) => { - 'annotatedField': - const _DurationMillisecondConverter().toJson(instance.annotatedField), - 'annotatedWithNamedCtor': const _DurationMillisecondConverter.named() - .toJson(instance.annotatedWithNamedCtor), - 'classAnnotatedWithField': - _durationConverter.toJson(instance.classAnnotatedWithField), - 'genericValue': _GenericConverter().toJson(instance.genericValue) + 'annotatedField': instance.annotatedField == null + ? null + : const _DurationMillisecondConverter() + .toJson(instance.annotatedField), + 'annotatedWithNamedCtor': instance.annotatedWithNamedCtor == null + ? null + : const _DurationMillisecondConverter.named() + .toJson(instance.annotatedWithNamedCtor), + 'classAnnotatedWithField': instance.classAnnotatedWithField == null + ? null + : _durationConverter.toJson(instance.classAnnotatedWithField), + 'genericValue': instance.genericValue == null + ? null + : _GenericConverter().toJson(instance.genericValue) }; ''') @JsonSerializable() From 4c0f30e1e34f34882db5f317378355c0bd20f15f Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 15 Oct 2018 10:16:46 -0700 Subject: [PATCH 021/569] Fix ordering of changelog entries for v2 --- json_serializable/CHANGELOG.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 50731abf5..1d2c9ba3e 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,5 +1,11 @@ ## 2.0.0 +* Support all `build.yaml` configuration options on classes by adding a number + of fields to `JsonSerializable`: `anyMap`, `checked`, `explicitToJson`, + `generateToJsonFunction`, and `useWrappers`. + +* Support decode/encode of `dart:core` `Duration` + * Code generated for fields and classes annotated with `JsonConverter` instances now properly handles nullable fields. @@ -13,10 +19,6 @@ * `json_serializable.dart` -* Support all `build.yaml` configuration options on classes by adding a number - of fields to `JsonSerializable`: `anyMap`, `checked`, `explicitToJson`, - `generateToJsonFunction`, and `useWrappers`. - * **BREAKING** `JsonSerializableGenerator` now exposes a `config` property of type `JsonSerializable` instead of individual properties for `checked`, `anyMay`, etc. This will affect anyone creating or using this class via @@ -32,8 +34,6 @@ `deserialize`. Many of the included `TypeHelper` implementations have been updated to indicate they expect more information from the source generator. -* Support decode/encode of `dart:core` `Duration` - ## 1.5.1 * Support the latest `pkg:analyzer`. From 294bdcbe3cc3001b035418dd07edba9244ff3eeb Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Fri, 19 Oct 2018 18:48:43 -0700 Subject: [PATCH 022/569] Example updates (#350) * Update example pkg versions and small tweaks to the code * Add an example of custom conversion in generic classes See https://github.com/dart-lang/json_serializable/issues/202#issuecomment-431429279 --- .travis.yml | 15 ++-- example/README.md | 6 +- example/lib/example.dart | 21 +++-- example/lib/example.g.dart | 13 +-- example/lib/json_converter_example.dart | 76 ++++++++++++++++++ example/lib/json_converter_example.g.dart | 32 ++++++++ example/mono_pkg.yaml | 15 +++- example/pubspec.yaml | 8 +- example/test/json_convert_example_test.dart | 87 +++++++++++++++++++++ example/test/readme_test.dart | 6 +- tool/travis.sh | 2 +- 11 files changed, 247 insertions(+), 34 deletions(-) create mode 100644 example/lib/json_converter_example.dart create mode 100644 example/lib/json_converter_example.g.dart create mode 100644 example/test/json_convert_example_test.dart diff --git a/.travis.yml b/.travis.yml index b74187a26..b8c232b03 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,4 @@ -# Created with package:mono_repo v1.2.0 +# Created with package:mono_repo v1.2.1 language: dart # Custom configuration @@ -13,13 +13,13 @@ branches: jobs: include: - stage: analyzer_and_format - name: "SDK: stable - DIR: example - TASKS: dartfmt -n --set-exit-if-changed ." - script: ./tool/travis.sh dartfmt + name: "SDK: dev - DIR: example - TASKS: [dartfmt -n --set-exit-if-changed ., dartanalyzer --fatal-infos --fatal-warnings .]" + script: ./tool/travis.sh dartfmt dartanalyzer_0 env: PKG="example" - dart: stable - - stage: analyzer_and_format - name: "SDK: stable - DIR: example - TASKS: dartanalyzer --fatal-infos --fatal-warnings ." - script: ./tool/travis.sh dartanalyzer_0 + dart: dev + - stage: analyzer_and_format_stable + name: "SDK: stable - DIR: example - TASKS: [dartfmt -n --set-exit-if-changed ., dartanalyzer --fatal-warnings .]" + script: ./tool/travis.sh dartfmt dartanalyzer_1 env: PKG="example" dart: stable - stage: unit_test @@ -71,4 +71,5 @@ stages: cache: directories: - "$HOME/.pub-cache" + - example/.dart_tool/build - json_serializable/.dart_tool/build diff --git a/example/README.md b/example/README.md index 2725dbf6b..895ecf9a9 100644 --- a/example/README.md +++ b/example/README.md @@ -8,11 +8,11 @@ dependencies to your `pubspec.yaml`. ```yaml dependencies: - json_annotation: ^1.0.0 + json_annotation: ^1.2.0 dev_dependencies: - build_runner: ^0.10.0 - json_serializable: ^1.0.0 + build_runner: ^1.0.0 + json_serializable: ^1.5.1 ``` Annotate your code with classes defined in diff --git a/example/lib/example.dart b/example/lib/example.dart index 77e010c1f..4df531329 100644 --- a/example/lib/example.dart +++ b/example/lib/example.dart @@ -3,6 +3,7 @@ // BSD-style license that can be found in the LICENSE file. import 'package:json_annotation/json_annotation.dart'; + part 'example.g.dart'; @JsonSerializable() @@ -39,7 +40,7 @@ class Order { @JsonKey( name: 'prep-time', - fromJson: _durationFromMillseconds, + fromJson: _durationFromMilliseconds, toJson: _durationToMilliseconds) Duration prepTime; @@ -51,15 +52,19 @@ class Order { factory Order.fromJson(Map json) => _$OrderFromJson(json); Map toJson() => _$OrderToJson(this); -} -Duration _durationFromMillseconds(int milliseconds) => - Duration(milliseconds: milliseconds); -int _durationToMilliseconds(Duration duration) => duration.inMilliseconds; + static Duration _durationFromMilliseconds(int milliseconds) => + Duration(milliseconds: milliseconds); + + static int _durationToMilliseconds(Duration duration) => + duration.inMilliseconds; -DateTime _dateTimeFromEpochUs(int us) => - DateTime.fromMicrosecondsSinceEpoch(us); -int _dateTimeToEpochUs(DateTime dateTime) => dateTime.microsecondsSinceEpoch; + static DateTime _dateTimeFromEpochUs(int us) => + DateTime.fromMicrosecondsSinceEpoch(us); + + static int _dateTimeToEpochUs(DateTime dateTime) => + dateTime.microsecondsSinceEpoch; +} @JsonSerializable() class Item { diff --git a/example/lib/example.g.dart b/example/lib/example.g.dart index 55e89f296..77df6f1b3 100644 --- a/example/lib/example.g.dart +++ b/example/lib/example.g.dart @@ -38,8 +38,9 @@ Map _$PersonToJson(Person instance) { } Order _$OrderFromJson(Map json) { - return Order( - json['date'] == null ? null : _dateTimeFromEpochUs(json['date'] as int)) + return Order(json['date'] == null + ? null + : Order._dateTimeFromEpochUs(json['date'] as int)) ..count = json['count'] as int ..itemNumber = json['itemNumber'] as int ..isRushed = json['isRushed'] as bool @@ -48,7 +49,7 @@ Order _$OrderFromJson(Map json) { : Item.fromJson(json['item'] as Map) ..prepTime = json['prep-time'] == null ? null - : _durationFromMillseconds(json['prep-time'] as int); + : Order._durationFromMilliseconds(json['prep-time'] as int); } Map _$OrderToJson(Order instance) { @@ -68,9 +69,9 @@ Map _$OrderToJson(Order instance) { 'prep-time', instance.prepTime == null ? null - : _durationToMilliseconds(instance.prepTime)); - writeNotNull( - 'date', instance.date == null ? null : _dateTimeToEpochUs(instance.date)); + : Order._durationToMilliseconds(instance.prepTime)); + writeNotNull('date', + instance.date == null ? null : Order._dateTimeToEpochUs(instance.date)); return val; } diff --git a/example/lib/json_converter_example.dart b/example/lib/json_converter_example.dart new file mode 100644 index 000000000..75c5f613e --- /dev/null +++ b/example/lib/json_converter_example.dart @@ -0,0 +1,76 @@ +// Copyright (c) 2018, 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:json_annotation/json_annotation.dart'; + +part 'json_converter_example.g.dart'; + +@JsonSerializable() +class GenericCollection { + @JsonKey(name: 'page') + final int page; + + @JsonKey(name: 'total_results') + final int totalResults; + + @JsonKey(name: 'total_pages') + final int totalPages; + + @JsonKey(name: 'results') + @_Converter() + final List results; + + GenericCollection( + {this.page, this.totalResults, this.totalPages, this.results}); + + factory GenericCollection.fromJson(Map json) => + _$GenericCollectionFromJson(json); + + Map toJson() => _$GenericCollectionToJson(this); +} + +class _Converter implements JsonConverter { + const _Converter(); + + @override + T fromJson(Object json) { + if (json is Map && + json.containsKey('name') && + json.containsKey('size')) { + return CustomResult.fromJson(json) as T; + } + // This will only work if `json` is a native JSON type: + // num, String, bool, null, etc + // *and* is assignable to `T`. + return json as T; + } + + @override + Object toJson(T object) { + // This will only work if `object` is a native JSON type: + // num, String, bool, null, etc + // Or if it has a `toJson()` function`. + return object; + } +} + +@JsonSerializable() +class CustomResult { + final String name; + final int size; + + CustomResult(this.name, this.size); + + factory CustomResult.fromJson(Map json) => + _$CustomResultFromJson(json); + + Map toJson() => _$CustomResultToJson(this); + + @override + bool operator ==(Object other) => + other is CustomResult && other.name == name && other.size == size; + + @override + int get hashCode => name.hashCode * 31 ^ size.hashCode; +} diff --git a/example/lib/json_converter_example.g.dart b/example/lib/json_converter_example.g.dart new file mode 100644 index 000000000..5fa8fb0b0 --- /dev/null +++ b/example/lib/json_converter_example.g.dart @@ -0,0 +1,32 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'json_converter_example.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +GenericCollection _$GenericCollectionFromJson(Map json) { + return GenericCollection( + page: json['page'] as int, + totalResults: json['total_results'] as int, + totalPages: json['total_pages'] as int, + results: + (json['results'] as List)?.map(_Converter().fromJson)?.toList()); +} + +Map _$GenericCollectionToJson( + GenericCollection instance) => + { + 'page': instance.page, + 'total_results': instance.totalResults, + 'total_pages': instance.totalPages, + 'results': instance.results?.map(_Converter().toJson)?.toList() + }; + +CustomResult _$CustomResultFromJson(Map json) { + return CustomResult(json['name'] as String, json['size'] as int); +} + +Map _$CustomResultToJson(CustomResult instance) => + {'name': instance.name, 'size': instance.size}; diff --git a/example/mono_pkg.yaml b/example/mono_pkg.yaml index ab02145f2..2b5ea1a52 100644 --- a/example/mono_pkg.yaml +++ b/example/mono_pkg.yaml @@ -4,8 +4,19 @@ dart: stages: - analyzer_and_format: - - dartfmt - - dartanalyzer: --fatal-infos --fatal-warnings . + - group: + - dartfmt + - dartanalyzer: --fatal-infos --fatal-warnings . + dart: [dev] + - analyzer_and_format_stable: + - group: + - dartfmt + - dartanalyzer: --fatal-warnings . + dart: [stable] - unit_test: # Run the tests -- include the default-skipped presubmit tests - test: --run-skipped + +cache: + directories: + - .dart_tool/build diff --git a/example/pubspec.yaml b/example/pubspec.yaml index c10f7ea58..b6faffe76 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -2,14 +2,14 @@ name: example author: Dart Team environment: - sdk: '>=2.0.0-dev.54 <3.0.0' + sdk: '>=2.0.0 <3.0.0' dependencies: - json_annotation: ^1.0.0 + json_annotation: ^1.2.0 dev_dependencies: - build_runner: ^0.10.0 - json_serializable: ^1.0.0 + build_runner: ^1.0.0 + json_serializable: ^1.5.1 # Used by tests. Not required to use `json_serializable`. build_verify: ^1.0.0 diff --git a/example/test/json_convert_example_test.dart b/example/test/json_convert_example_test.dart new file mode 100644 index 000000000..5c37648ab --- /dev/null +++ b/example/test/json_convert_example_test.dart @@ -0,0 +1,87 @@ +// Copyright (c) 2018, 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 'dart:convert'; + +import 'package:example/json_converter_example.dart'; +import 'package:test/test.dart'; + +void main() { + test('trivial case', () { + var collection = GenericCollection( + page: 0, totalPages: 3, totalResults: 10, results: [1, 2, 3]); + + var encoded = _encode(collection); + var collection2 = GenericCollection.fromJson( + jsonDecode(encoded) as Map); + + expect(collection2.results, [1, 2, 3]); + + expect(_encode(collection2), encoded); + }); + + test('custom result', () { + var collection = GenericCollection( + page: 0, + totalPages: 3, + totalResults: 10, + results: [CustomResult('bob', 42)]); + + var encoded = _encode(collection); + var collection2 = GenericCollection.fromJson( + jsonDecode(encoded) as Map); + + expect(collection2.results, [CustomResult('bob', 42)]); + + expect(_encode(collection2), encoded); + }); + + test('mixed values in generic collection', () { + var collection = + GenericCollection(page: 0, totalPages: 3, totalResults: 10, results: [ + 1, + 3.14, + null, + 'bob', + ['list'], + {'map': 'map'}, + CustomResult('bob', 42) + ]); + + var encoded = _encode(collection); + + expect( + () => GenericCollection.fromJson( + jsonDecode(encoded) as Map), + _throwsCastSomething); + expect( + () => GenericCollection.fromJson( + jsonDecode(encoded) as Map), + _throwsCastSomething); + expect( + () => GenericCollection.fromJson( + jsonDecode(encoded) as Map), + _throwsCastSomething); + + var collection2 = + GenericCollection.fromJson(jsonDecode(encoded) as Map); + + expect(collection2.results, [ + 1, + 3.14, + null, + 'bob', + ['list'], + {'map': 'map'}, + CustomResult('bob', 42) + ]); + + expect(_encode(collection2), encoded); + }); +} + +final _throwsCastSomething = throwsA(const TypeMatcher()); + +String _encode(Object object) => + const JsonEncoder.withIndent(' ').convert(object); diff --git a/example/test/readme_test.dart b/example/test/readme_test.dart index fef069e4a..18255d32d 100644 --- a/example/test/readme_test.dart +++ b/example/test/readme_test.dart @@ -20,9 +20,9 @@ void _expect(String fileName) { final _pubspecContent = r''' dependencies: - json_annotation: ^1.0.0 + json_annotation: ^1.2.0 dev_dependencies: - build_runner: ^0.10.0 - json_serializable: ^1.0.0 + build_runner: ^1.0.0 + json_serializable: ^1.5.1 '''; diff --git a/tool/travis.sh b/tool/travis.sh index 78aafe12f..c2faca891 100755 --- a/tool/travis.sh +++ b/tool/travis.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Created with package:mono_repo v1.2.0 +# Created with package:mono_repo v1.2.1 if [ -z "$PKG" ]; then echo -e '\033[31mPKG environment variable must be set!\033[0m' From fa0f936de6c5a9f153da5cf5a9a6364ee984f706 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 22 Oct 2018 07:36:27 -0700 Subject: [PATCH 023/569] =?UTF-8?q?Fix=20remaining=20`prefer=5Ffinal`=20li?= =?UTF-8?q?nts=20=E2=80=93=20outside=20generated=20example=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/test/json_convert_example_test.dart | 18 +++++++++--------- .../test/kitchen_sink/kitchen_sink_test.dart | 10 +++++----- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/example/test/json_convert_example_test.dart b/example/test/json_convert_example_test.dart index 5c37648ab..b79f5c67e 100644 --- a/example/test/json_convert_example_test.dart +++ b/example/test/json_convert_example_test.dart @@ -9,11 +9,11 @@ import 'package:test/test.dart'; void main() { test('trivial case', () { - var collection = GenericCollection( + final collection = GenericCollection( page: 0, totalPages: 3, totalResults: 10, results: [1, 2, 3]); - var encoded = _encode(collection); - var collection2 = GenericCollection.fromJson( + final encoded = _encode(collection); + final collection2 = GenericCollection.fromJson( jsonDecode(encoded) as Map); expect(collection2.results, [1, 2, 3]); @@ -22,14 +22,14 @@ void main() { }); test('custom result', () { - var collection = GenericCollection( + final collection = GenericCollection( page: 0, totalPages: 3, totalResults: 10, results: [CustomResult('bob', 42)]); - var encoded = _encode(collection); - var collection2 = GenericCollection.fromJson( + final encoded = _encode(collection); + final collection2 = GenericCollection.fromJson( jsonDecode(encoded) as Map); expect(collection2.results, [CustomResult('bob', 42)]); @@ -38,7 +38,7 @@ void main() { }); test('mixed values in generic collection', () { - var collection = + final collection = GenericCollection(page: 0, totalPages: 3, totalResults: 10, results: [ 1, 3.14, @@ -49,7 +49,7 @@ void main() { CustomResult('bob', 42) ]); - var encoded = _encode(collection); + final encoded = _encode(collection); expect( () => GenericCollection.fromJson( @@ -64,7 +64,7 @@ void main() { jsonDecode(encoded) as Map), _throwsCastSomething); - var collection2 = + final collection2 = GenericCollection.fromJson(jsonDecode(encoded) as Map); expect(collection2.results, [ diff --git a/json_serializable/test/kitchen_sink/kitchen_sink_test.dart b/json_serializable/test/kitchen_sink/kitchen_sink_test.dart index fd8063597..4f7b7dd3d 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink_test.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink_test.dart @@ -82,12 +82,12 @@ void main() { }; test('nullable values are allowed in the nullable version', () { - var instance = nullable.JsonConverterTestClass(); - var json = instance.toJson(); + final instance = nullable.JsonConverterTestClass(); + final json = instance.toJson(); expect(json.values, everyElement(isNull)); expect(json.keys, unorderedEquals(validValues.keys)); - var instance2 = nullable.JsonConverterTestClass.fromJson(json); + final instance2 = nullable.JsonConverterTestClass.fromJson(json); expect(instance2.toJson(), json); }); @@ -97,11 +97,11 @@ void main() { reason: 'Trying to call `map` on a null list'); instance = nn.JsonConverterTestClass.fromJson(validValues); - var json = instance.toJson(); + final json = instance.toJson(); expect(json, validValues); expect(json.values, everyElement(isNotNull)); - var instance2 = nn.JsonConverterTestClass.fromJson(json); + final instance2 = nn.JsonConverterTestClass.fromJson(json); expect(instance2.toJson(), json); }); }); From 77f5a47ff6427fbf502413590ac51f76f500467a Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 22 Oct 2018 07:38:07 -0700 Subject: [PATCH 024/569] prepare to release json_annotation 2.0.0 --- json_annotation/pubspec.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/json_annotation/pubspec.yaml b/json_annotation/pubspec.yaml index 04ef24b84..8938c9c1b 100644 --- a/json_annotation/pubspec.yaml +++ b/json_annotation/pubspec.yaml @@ -1,9 +1,9 @@ name: json_annotation -version: 2.0.0-dev +version: 2.0.0 description: >- Classes and helper functions that support JSON code generation via the `json_serializable` package. homepage: https://github.com/dart-lang/json_serializable author: Dart Team environment: - sdk: '>=2.0.0-dev.54.0 <3.0.0' + sdk: '>=2.0.0 <3.0.0' From b0a0cbbdc04ac69094c4e58b6772d5589c866ffe Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 23 Oct 2018 14:58:32 -0700 Subject: [PATCH 025/569] json_serializable: Prepare to release v2 (#353) --- json_serializable/pubspec.yaml | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 9ff1bdeb0..474070982 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,10 +1,10 @@ name: json_serializable -version: 2.0.0-dev +version: 2.0.0 author: Dart Team description: Generates utilities to aid in serializing to/from JSON. homepage: https://github.com/dart-lang/json_serializable environment: - sdk: '>=2.0.0-dev.65 <3.0.0' + sdk: '>=2.0.0 <3.0.0' dependencies: analyzer: '>=0.32.2 <0.34.0' @@ -12,7 +12,7 @@ dependencies: build_config: '>=0.2.6 <0.4.0' # Use a tight version constraint to ensure that a constraint on - # `json_annotation`. Properly constrains all features it provides. + # `json_annotation` properly constrains all features it provides. json_annotation: '>=2.0.0 <2.1.0' meta: ^1.1.0 path: ^1.3.2 @@ -28,7 +28,3 @@ dev_dependencies: logging: ^0.11.3+1 test: ^1.3.3 yaml: ^2.1.13 - -dependency_overrides: - json_annotation: - path: ../json_annotation From dbd39bc3dde737b9743cdff5300dc364f2d033a0 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 23 Oct 2018 15:29:38 -0700 Subject: [PATCH 026/569] Update example for latest release (#354) --- example/README.md | 4 ++-- example/lib/example.g.dart | 4 ++-- example/lib/json_converter_example.g.dart | 9 ++++++--- example/pubspec.yaml | 4 ++-- example/test/readme_test.dart | 4 ++-- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/example/README.md b/example/README.md index 895ecf9a9..2c154e1b5 100644 --- a/example/README.md +++ b/example/README.md @@ -8,11 +8,11 @@ dependencies to your `pubspec.yaml`. ```yaml dependencies: - json_annotation: ^1.2.0 + json_annotation: ^2.0.0 dev_dependencies: build_runner: ^1.0.0 - json_serializable: ^1.5.1 + json_serializable: ^2.0.0 ``` Annotate your code with classes defined in diff --git a/example/lib/example.g.dart b/example/lib/example.g.dart index 77df6f1b3..f03273f98 100644 --- a/example/lib/example.g.dart +++ b/example/lib/example.g.dart @@ -19,7 +19,7 @@ Person _$PersonFromJson(Map json) { } Map _$PersonToJson(Person instance) { - var val = { + final val = { 'firstName': instance.firstName, }; @@ -53,7 +53,7 @@ Order _$OrderFromJson(Map json) { } Map _$OrderToJson(Order instance) { - var val = {}; + final val = {}; void writeNotNull(String key, dynamic value) { if (value != null) { diff --git a/example/lib/json_converter_example.g.dart b/example/lib/json_converter_example.g.dart index 5fa8fb0b0..69100f475 100644 --- a/example/lib/json_converter_example.g.dart +++ b/example/lib/json_converter_example.g.dart @@ -11,8 +11,9 @@ GenericCollection _$GenericCollectionFromJson(Map json) { page: json['page'] as int, totalResults: json['total_results'] as int, totalPages: json['total_pages'] as int, - results: - (json['results'] as List)?.map(_Converter().fromJson)?.toList()); + results: (json['results'] as List) + ?.map((e) => e == null ? null : _Converter().fromJson(e)) + ?.toList()); } Map _$GenericCollectionToJson( @@ -21,7 +22,9 @@ Map _$GenericCollectionToJson( 'page': instance.page, 'total_results': instance.totalResults, 'total_pages': instance.totalPages, - 'results': instance.results?.map(_Converter().toJson)?.toList() + 'results': instance.results + ?.map((e) => e == null ? null : _Converter().toJson(e)) + ?.toList() }; CustomResult _$CustomResultFromJson(Map json) { diff --git a/example/pubspec.yaml b/example/pubspec.yaml index b6faffe76..1ec5c4474 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -5,11 +5,11 @@ environment: sdk: '>=2.0.0 <3.0.0' dependencies: - json_annotation: ^1.2.0 + json_annotation: ^2.0.0 dev_dependencies: build_runner: ^1.0.0 - json_serializable: ^1.5.1 + json_serializable: ^2.0.0 # Used by tests. Not required to use `json_serializable`. build_verify: ^1.0.0 diff --git a/example/test/readme_test.dart b/example/test/readme_test.dart index 18255d32d..61626d31f 100644 --- a/example/test/readme_test.dart +++ b/example/test/readme_test.dart @@ -20,9 +20,9 @@ void _expect(String fileName) { final _pubspecContent = r''' dependencies: - json_annotation: ^1.2.0 + json_annotation: ^2.0.0 dev_dependencies: build_runner: ^1.0.0 - json_serializable: ^1.5.1 + json_serializable: ^2.0.0 '''; From 91614af85ba9e95d7843c1facda8f930924bae10 Mon Sep 17 00:00:00 2001 From: Jonas Finnemann Jensen Date: Thu, 6 Dec 2018 13:01:55 +0100 Subject: [PATCH 027/569] Fix documentation comment typo (#358) --- json_annotation/lib/src/json_serializable.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/json_annotation/lib/src/json_serializable.dart b/json_annotation/lib/src/json_serializable.dart index b44f9a1fd..d138a11db 100644 --- a/json_annotation/lib/src/json_serializable.dart +++ b/json_annotation/lib/src/json_serializable.dart @@ -54,7 +54,7 @@ class JsonSerializable { /// ``` final bool createFactory; - /// If `true` (the default), code for decoding JSON is generated fon this + /// If `true` (the default), code for encoding JSON is generated for this /// class. /// /// By default, a private `_$ClassNameMixin` class is created From d9e30634bbded11cd7da8b4705719bbfa0f231d3 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 10 Dec 2018 07:11:44 -0800 Subject: [PATCH 028/569] Expand travis testing to include stable and 2.0.0 --- .travis.yml | 31 ++++++++++++++++++++++++++++++- json_serializable/mono_pkg.yaml | 2 ++ mono_repo.yaml | 1 - 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index b8c232b03..9aa963251 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,6 @@ addons: branches: only: - master - - v1_x jobs: include: @@ -52,16 +51,46 @@ jobs: script: ./tool/travis.sh test_1 env: PKG="json_serializable" dart: stable + - stage: unit_test + name: "SDK: 2.0.0 - DIR: json_serializable - TASKS: pub run test" + script: ./tool/travis.sh test_1 + env: PKG="json_serializable" + dart: "2.0.0" + - stage: unit_test + name: "SDK: dev - DIR: json_serializable - TASKS: pub run test" + script: ./tool/travis.sh test_1 + env: PKG="json_serializable" + dart: dev - stage: unit_test name: "SDK: stable - DIR: json_serializable - TASKS: pub run test --run-skipped test/ensure_build_test.dart" script: ./tool/travis.sh test_2 env: PKG="json_serializable" dart: stable + - stage: unit_test + name: "SDK: 2.0.0 - DIR: json_serializable - TASKS: pub run test --run-skipped test/ensure_build_test.dart" + script: ./tool/travis.sh test_2 + env: PKG="json_serializable" + dart: "2.0.0" + - stage: unit_test + name: "SDK: dev - DIR: json_serializable - TASKS: pub run test --run-skipped test/ensure_build_test.dart" + script: ./tool/travis.sh test_2 + env: PKG="json_serializable" + dart: dev - stage: unit_test name: "SDK: stable - DIR: json_serializable - TASKS: pub run build_runner test -- -p chrome" script: ./tool/travis.sh command env: PKG="json_serializable" dart: stable + - stage: unit_test + name: "SDK: 2.0.0 - DIR: json_serializable - TASKS: pub run build_runner test -- -p chrome" + script: ./tool/travis.sh command + env: PKG="json_serializable" + dart: "2.0.0" + - stage: unit_test + name: "SDK: dev - DIR: json_serializable - TASKS: pub run build_runner test -- -p chrome" + script: ./tool/travis.sh command + env: PKG="json_serializable" + dart: dev stages: - analyzer_and_format diff --git a/json_serializable/mono_pkg.yaml b/json_serializable/mono_pkg.yaml index ba7c8b7ad..86eb39b00 100644 --- a/json_serializable/mono_pkg.yaml +++ b/json_serializable/mono_pkg.yaml @@ -1,6 +1,8 @@ # See https://github.com/dart-lang/mono_repo for details dart: - stable + - 2.0.0 + - dev stages: - analyzer_and_format: diff --git a/mono_repo.yaml b/mono_repo.yaml index f4953efb8..18400672f 100644 --- a/mono_repo.yaml +++ b/mono_repo.yaml @@ -6,4 +6,3 @@ travis: branches: only: - master - - v1_x From d9c64237af633fab39ff518ee5d9f4d7ffbc042e Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 10 Dec 2018 07:13:20 -0800 Subject: [PATCH 029/569] Support pkg:analyzer v0.34.0, prepare for patch release --- json_serializable/CHANGELOG.md | 4 ++++ json_serializable/pubspec.yaml | 4 ++-- json_serializable/test/json_serializable_test.dart | 10 +++++++--- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 1d2c9ba3e..cccd95a87 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.0.1 + +* Support `pkg:analyzer` v0.34.0. + ## 2.0.0 * Support all `build.yaml` configuration options on classes by adding a number diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 474070982..574ee6207 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 2.0.0 +version: 2.0.1 author: Dart Team description: Generates utilities to aid in serializing to/from JSON. homepage: https://github.com/dart-lang/json_serializable @@ -7,7 +7,7 @@ environment: sdk: '>=2.0.0 <3.0.0' dependencies: - analyzer: '>=0.32.2 <0.34.0' + analyzer: '>=0.32.2 <0.35.0' build: '>=0.12.6 <2.0.0' build_config: '>=0.2.6 <0.4.0' diff --git a/json_serializable/test/json_serializable_test.dart b/json_serializable/test/json_serializable_test.dart index 80d16156d..72ef25af7 100644 --- a/json_serializable/test/json_serializable_test.dart +++ b/json_serializable/test/json_serializable_test.dart @@ -6,6 +6,7 @@ import 'dart:async'; import 'package:analyzer/dart/element/type.dart'; +import 'package:analyzer/src/dart/element/element.dart'; import 'package:build/build.dart'; import 'package:dart_style/dart_style.dart' as dart_style; import 'package:json_annotation/json_annotation.dart'; @@ -165,8 +166,10 @@ void main() async { for (final entry in _annotatedElements.entries) { group(entry.key, () { test('[all expected classes]', () { - expect(_expectedAnnotatedTests, - containsPair(entry.key, entry.value.map((ae) => ae.element.name))); + expect( + _expectedAnnotatedTests, + containsPair(entry.key, + unorderedEquals(entry.value.map((ae) => ae.element.name)))); }); for (final annotatedElement in entry.value) { @@ -342,7 +345,8 @@ String _runForElementNamed(JsonSerializable config, String name) { String _runForElementNamedWithGenerator( JsonSerializableGenerator generator, String name) { - final element = _library.allElements.singleWhere((e) => e.name == name); + final element = _library.allElements + .singleWhere((e) => e is! ConstVariableElement && e.name == name); final annotation = generator.typeChecker.firstAnnotationOf(element); final generated = generator .generateForAnnotatedElement(element, ConstantReader(annotation), null) From 78e2994125fa1755130ecdb42d41d31a8d1ba1c3 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 10 Dec 2018 19:52:13 -0800 Subject: [PATCH 030/569] latest build_web_compilers --- json_serializable/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 574ee6207..2cf901b82 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -22,7 +22,7 @@ dev_dependencies: build_runner: ^1.0.0 build_test: ^0.10.0 build_verify: ^1.1.0 - build_web_compilers: ^0.4.0+1 + build_web_compilers: ^1.0.0 collection: ^1.14.0 dart_style: ^1.0.0 logging: ^0.11.3+1 From 16d5489f3a737c8fd3d1d90ef14fccd2629c4637 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 20 Dec 2018 13:18:45 -0800 Subject: [PATCH 031/569] Warn when using defaultValue with toJson in a JsonKey (#362) Fixes https://github.com/dart-lang/json_serializable/issues/361 --- json_serializable/CHANGELOG.md | 5 ++++ json_serializable/lib/src/decode_helper.dart | 9 ++++++- json_serializable/lib/src/helper_core.dart | 2 +- .../lib/src/type_helper_ctx.dart | 8 +++--- json_serializable/pubspec.yaml | 2 +- .../test/json_serializable_test.dart | 3 ++- .../test/src/default_value_input.dart | 26 +++++++++++++++++++ 7 files changed, 47 insertions(+), 8 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index cccd95a87..b91ad6a67 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,8 @@ +## 2.0.2 + +* Log a warning when `defaultValue` is used with `toJson` in `JsonKey`. In this + case, use `nullable: false` instead of `defaultValue`. + ## 2.0.1 * Support `pkg:analyzer` v0.34.0. diff --git a/json_serializable/lib/src/decode_helper.dart b/json_serializable/lib/src/decode_helper.dart index 2982d046f..19239efc4 100644 --- a/json_serializable/lib/src/decode_helper.dart +++ b/json_serializable/lib/src/decode_helper.dart @@ -3,6 +3,7 @@ // BSD-style license that can be found in the LICENSE file. import 'package:analyzer/dart/element/element.dart'; +import 'package:build/build.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:source_gen/source_gen.dart'; @@ -192,7 +193,12 @@ abstract class DecodeHelper implements HelperCore { throwUnsupported(field, 'Cannot use `defaultValue` on a field with `nullable` false.'); } - + if (contextHelper.deserializeConvertData != null) { + log.warning('The field `${field.name}` has both `defaultValue` and ' + '`fromJson` defined which likely won\'t work for your scenario.\n' + 'Instead of using `defaultValue`, set `nullable: false` and handle ' + '`null` in the `fromJson` function.'); + } value = '$value ?? $defaultValue'; } return value; @@ -297,6 +303,7 @@ class _ConstructorData { final String content; final Set fieldsToSet; final Set usedCtorParamsAndFields; + _ConstructorData( this.content, this.fieldsToSet, this.usedCtorParamsAndFields); } diff --git a/json_serializable/lib/src/helper_core.dart b/json_serializable/lib/src/helper_core.dart index 11d14a51d..ea23a353b 100644 --- a/json_serializable/lib/src/helper_core.dart +++ b/json_serializable/lib/src/helper_core.dart @@ -49,7 +49,7 @@ abstract class HelperCore { JsonKey jsonKeyFor(FieldElement field) => jsonKeyForField(field, config); @protected - TypeHelperContext getHelperContext(FieldElement field) => + TypeHelperCtx getHelperContext(FieldElement field) => typeHelperContext(this, field, jsonKeyFor(field)); } diff --git a/json_serializable/lib/src/type_helper_ctx.dart b/json_serializable/lib/src/type_helper_ctx.dart index 253ca58c5..6b21fec14 100644 --- a/json_serializable/lib/src/type_helper_ctx.dart +++ b/json_serializable/lib/src/type_helper_ctx.dart @@ -12,11 +12,11 @@ import 'type_helper.dart'; import 'type_helpers/convert_helper.dart'; import 'utils.dart'; -TypeHelperContext typeHelperContext( +TypeHelperCtx typeHelperContext( HelperCore helperCore, FieldElement fieldElement, JsonKey key) => - _TypeHelperCtx(helperCore, fieldElement, key); + TypeHelperCtx._(helperCore, fieldElement, key); -class _TypeHelperCtx +class TypeHelperCtx implements TypeHelperContextWithConfig, TypeHelperContextWithConvert { final HelperCore _helperCore; final JsonKey _key; @@ -33,7 +33,7 @@ class _TypeHelperCtx @override JsonSerializable get config => _helperCore.config; - _TypeHelperCtx(this._helperCore, this.fieldElement, this._key); + TypeHelperCtx._(this._helperCore, this.fieldElement, this._key); @override ConvertData get serializeConvertData => _pairFromContext?.toJson; diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 2cf901b82..090cb481e 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 2.0.1 +version: 2.0.2-dev author: Dart Team description: Generates utilities to aid in serializing to/from JSON. homepage: https://github.com/dart-lang/json_serializable diff --git a/json_serializable/test/json_serializable_test.dart b/json_serializable/test/json_serializable_test.dart index 72ef25af7..e3f9549db 100644 --- a/json_serializable/test/json_serializable_test.dart +++ b/json_serializable/test/json_serializable_test.dart @@ -87,7 +87,8 @@ const _expectedAnnotatedTests = { 'DefaultWithConstObject', 'DefaultWithNestedEnum', 'DefaultWithNonNullableField', - 'DefaultWithNonNullableClass' + 'DefaultWithNonNullableClass', + 'DefaultWithToJsonClass', ], 'field_namer_input.dart': [ 'FieldNamerNone', diff --git a/json_serializable/test/src/default_value_input.dart b/json_serializable/test/src/default_value_input.dart index 3759ae9b2..961b7c430 100644 --- a/json_serializable/test/src/default_value_input.dart +++ b/json_serializable/test/src/default_value_input.dart @@ -77,3 +77,29 @@ class DefaultWithNonNullableClass { DefaultWithNonNullableClass(); } + +@ShouldGenerate(r''' +DefaultWithToJsonClass _$DefaultWithToJsonClassFromJson( + Map json) { + $checkKeys(json, allowedKeys: const ['fieldDefaultValueToJson']); + return DefaultWithToJsonClass() + ..fieldDefaultValueToJson = json['fieldDefaultValueToJson'] == null + ? null + : DefaultWithToJsonClass._fromJson( + json['fieldDefaultValueToJson'] as String) ?? + 7; +} +''', expectedLogItems: [ + ''' +The field `fieldDefaultValueToJson` has both `defaultValue` and `fromJson` defined which likely won't work for your scenario. +Instead of using `defaultValue`, set `nullable: false` and handle `null` in the `fromJson` function.''' +]) +@JsonSerializable(disallowUnrecognizedKeys: true, createToJson: false) +class DefaultWithToJsonClass { + @JsonKey(defaultValue: 7, fromJson: _fromJson) + int fieldDefaultValueToJson; + + DefaultWithToJsonClass(); + + static int _fromJson(String input) => 41; +} From 607e17ff4792bba26ef4fc54fdbad626ff76ab94 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 8 Jan 2019 15:34:10 -0800 Subject: [PATCH 032/569] Add file for no-reply hook (#367) --- .github/no-response.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 .github/no-response.yml diff --git a/.github/no-response.yml b/.github/no-response.yml new file mode 100644 index 000000000..b5567e94c --- /dev/null +++ b/.github/no-response.yml @@ -0,0 +1,16 @@ +# Configuration for probot-no-response - https://github.com/probot/no-response + +# Number of days of inactivity before an issue is closed for lack of response. +daysUntilClose: 21 + +# Label requiring a response. +responseRequiredLabel: "State: needs info" + +# Comment to post when closing an Issue for lack of response. +closeComment: >- + Without additional information, we are unfortunately not sure how to + resolve this issue. We are therefore reluctantly going to close this + bug for now. Please don't hesitate to comment on the bug if you have + any more information for us; we will reopen it right away! + + Thanks for your contribution. From 4b2628a5475fce1ff11676f7edc2f520e3b0842a Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 8 Jan 2019 15:43:24 -0800 Subject: [PATCH 033/569] Revert "Add file for no-reply hook (#367)" This reverts commit 607e17ff4792bba26ef4fc54fdbad626ff76ab94. --- .github/no-response.yml | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 .github/no-response.yml diff --git a/.github/no-response.yml b/.github/no-response.yml deleted file mode 100644 index b5567e94c..000000000 --- a/.github/no-response.yml +++ /dev/null @@ -1,16 +0,0 @@ -# Configuration for probot-no-response - https://github.com/probot/no-response - -# Number of days of inactivity before an issue is closed for lack of response. -daysUntilClose: 21 - -# Label requiring a response. -responseRequiredLabel: "State: needs info" - -# Comment to post when closing an Issue for lack of response. -closeComment: >- - Without additional information, we are unfortunately not sure how to - resolve this issue. We are therefore reluctantly going to close this - bug for now. Please don't hesitate to comment on the bug if you have - any more information for us; we will reopen it right away! - - Thanks for your contribution. From 4b035b6ea2669118cfde06c42e759acc85030cad Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 8 Jan 2019 15:34:10 -0800 Subject: [PATCH 034/569] Add file for no-reply hook (#367) --- .github/no-response.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 .github/no-response.yml diff --git a/.github/no-response.yml b/.github/no-response.yml new file mode 100644 index 000000000..b5567e94c --- /dev/null +++ b/.github/no-response.yml @@ -0,0 +1,16 @@ +# Configuration for probot-no-response - https://github.com/probot/no-response + +# Number of days of inactivity before an issue is closed for lack of response. +daysUntilClose: 21 + +# Label requiring a response. +responseRequiredLabel: "State: needs info" + +# Comment to post when closing an Issue for lack of response. +closeComment: >- + Without additional information, we are unfortunately not sure how to + resolve this issue. We are therefore reluctantly going to close this + bug for now. Please don't hesitate to comment on the bug if you have + any more information for us; we will reopen it right away! + + Thanks for your contribution. From 44fc4e659b24b180048822d9af5a96ada2fbdcad Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 14 Jan 2019 10:11:57 -0800 Subject: [PATCH 035/569] Fix new implicit cast issue with latest dev SDK --- json_serializable/test/kitchen_sink/kitchen_sink.dart | 2 +- json_serializable/test/kitchen_sink/kitchen_sink.wrapped.dart | 2 +- json_serializable/tool/builder.dart | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.dart b/json_serializable/test/kitchen_sink/kitchen_sink.dart index 662c082cf..c9f7c4829 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.dart @@ -16,7 +16,7 @@ part 'kitchen_sink.g.dart'; // non-null values. List _defaultList() => null; Set _defaultSet() => null; -Map _defaultMap() => null; +Map _defaultMap() => null; SimpleObject _defaultSimpleObject() => null; StrictKeysObject _defaultStrictKeysObject() => null; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.wrapped.dart b/json_serializable/test/kitchen_sink/kitchen_sink.wrapped.dart index cbd1f81c6..d0d284727 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.wrapped.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.wrapped.dart @@ -22,7 +22,7 @@ part 'kitchen_sink.wrapped.g.dart'; // non-null values. List _defaultList() => null; Set _defaultSet() => null; -Map _defaultMap() => null; +Map _defaultMap() => null; SimpleObject _defaultSimpleObject() => null; StrictKeysObject _defaultStrictKeysObject() => null; diff --git a/json_serializable/tool/builder.dart b/json_serializable/tool/builder.dart index 482436e99..c321ce3d5 100644 --- a/json_serializable/tool/builder.dart +++ b/json_serializable/tool/builder.dart @@ -47,7 +47,7 @@ class _NonNullableGenerator extends Generator { 'List _defaultList() => [];'), _Replacement('Set _defaultSet() => null;', 'Set _defaultSet() => Set();'), - _Replacement('Map _defaultMap() => null;', + _Replacement('Map _defaultMap() => null;', 'Map _defaultMap() => {};'), _Replacement('SimpleObject _defaultSimpleObject() => null;', 'SimpleObject _defaultSimpleObject() => SimpleObject(42);'), From a9e0346a9bf7447f65ec0b85fe80a223ef60d694 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 14 Jan 2019 10:16:59 -0800 Subject: [PATCH 036/569] travis-ci: align tasks run on stable SDK --- .travis.yml | 11 +++-------- json_annotation/mono_pkg.yaml | 8 +++++--- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9aa963251..3bcc834af 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,14 +26,9 @@ jobs: script: ./tool/travis.sh test_0 env: PKG="example" dart: stable - - stage: analyzer_and_format - name: "SDK: stable - DIR: json_annotation - TASKS: dartfmt -n --set-exit-if-changed ." - script: ./tool/travis.sh dartfmt - env: PKG="json_annotation" - dart: stable - - stage: analyzer_and_format - name: "SDK: stable - DIR: json_annotation - TASKS: dartanalyzer --fatal-infos --fatal-warnings ." - script: ./tool/travis.sh dartanalyzer_0 + - stage: analyzer_and_format_stable + name: "SDK: stable - DIR: json_annotation - TASKS: [dartfmt -n --set-exit-if-changed ., dartanalyzer --fatal-warnings .]" + script: ./tool/travis.sh dartfmt dartanalyzer_1 env: PKG="json_annotation" dart: stable - stage: analyzer_and_format diff --git a/json_annotation/mono_pkg.yaml b/json_annotation/mono_pkg.yaml index 83b362e4a..27edaedf4 100644 --- a/json_annotation/mono_pkg.yaml +++ b/json_annotation/mono_pkg.yaml @@ -3,6 +3,8 @@ dart: - stable stages: - - analyzer_and_format: - - dartfmt - - dartanalyzer: --fatal-infos --fatal-warnings . + - analyzer_and_format_stable: + - group: + - dartfmt + - dartanalyzer: --fatal-warnings . + dart: [stable] From 4033f6ad4e3c96bc2ed16d93c0995e11fcfe42df Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 14 Jan 2019 11:47:20 -0800 Subject: [PATCH 037/569] Fix tests for latest pkg:source_span --- json_serializable/test/yaml/yaml_test.dart | 73 ++++++++++++++-------- 1 file changed, 46 insertions(+), 27 deletions(-) diff --git a/json_serializable/test/yaml/yaml_test.dart b/json_serializable/test/yaml/yaml_test.dart index 5d8fa79cb..7811a4877 100644 --- a/json_serializable/test/yaml/yaml_test.dart +++ b/json_serializable/test/yaml/yaml_test.dart @@ -3,7 +3,6 @@ // BSD-style license that can be found in the LICENSE file. @TestOn('vm') - import 'dart:io'; import 'package:json_annotation/json_annotation.dart'; @@ -56,7 +55,7 @@ void main() { fail('parse should fail'); } on CheckedFromJsonException catch (e) { final prettyOutput = _prettyPrintCheckedFromJsonException(e); - printOnFailure(prettyOutput); + printOnFailure("r'''\n$prettyOutput'''"); expect(prettyOutput, entry.value); } }); @@ -71,24 +70,30 @@ builders: - b ''': r''' line 2, column 1 of file.yaml: Could not create `Config`. Unsupported value for `builders`. -- a -^^^^''', + ╷ +2 │ ┌ - a +3 │ └ - b + ╵''', r''' builders: sample: defaultEnumTest: bob ''': r''' line 3, column 22 of file.yaml: Could not create `Builder`. Unsupported value for `defaultEnumTest`. `bob` is not one of the supported values: none, dependents, all_packages, root_package - defaultEnumTest: bob - ^^^''', + ╷ +3 │ defaultEnumTest: bob + │ ^^^ + ╵''', r''' builders: a: target: 42 ''': r''' line 3, column 13 of file.yaml: Could not create `Builder`. Unsupported value for `target`. - target: 42 - ^^''', + ╷ +3 │ target: 42 + │ ^^ + ╵''', r''' builders: a: @@ -96,16 +101,20 @@ builders: auto_apply: unsupported ''': r''' line 4, column 17 of file.yaml: Could not create `Builder`. Unsupported value for `auto_apply`. `unsupported` is not one of the supported values: none, dependents, all_packages, root_package - auto_apply: unsupported - ^^^^^^^^^^^''', + ╷ +4 │ auto_apply: unsupported + │ ^^^^^^^^^^^ + ╵''', r''' builders: a: builder_factories: [] ''': r''' line 3, column 24 of file.yaml: Could not create `Builder`. Unsupported value for `builder_factories`. Must have at least one value. - builder_factories: [] - ^^''', + ╷ +3 │ builder_factories: [] + │ ^^ + ╵''', r''' builders: a: @@ -116,33 +125,43 @@ Could not create `Builder`. Unrecognized keys: [baz, foo]; supported keys: [target, import, is_optional, configLocation, auto_apply, build_to, defaultEnumTest, builder_factories, applies_builders, required_inputs, build_extensions] line 4, column 5 of file.yaml: Invalid key "baz" - baz: zap - ^^^ + ╷ +4 │ baz: zap + │ ^^^ + ╵ line 3, column 5 of file.yaml: Invalid key "foo" - foo: bar - ^^^''', + ╷ +3 │ foo: bar + │ ^^^ + ╵''', r''' - bob: cool - ''': ''' + bob: cool''': r''' Could not create `Config`. line 1, column 3 of file.yaml: Required keys are missing: builders. - bob: cool - ^^^^^^^^^^''', + ╷ +1 │ bob: cool + │ ^^^^^^^^^ + ╵''', r''' builders: builder_name: - auto_apply:''': '''Could not create `Builder`. + auto_apply:''': ''' +Could not create `Builder`. line 3, column 5 of file.yaml: These keys had `null` values, which is not allowed: [auto_apply] - auto_apply: - ^^^^^^^^^^^''', + ╷ +3 │ auto_apply: + │ ^^^^^^^^^^^ + ╵''', r''' builders: builder_name: builder_factories: ["scssBuilder"] - configLocation: "user@host:invalid/uri"''': - '''line 4, column 21 of file.yaml: Could not create `Builder`. Unsupported value for `configLocation`. Illegal scheme character at offset 4. - configLocation: "user@host:invalid/uri" - ^^^^^^^^^^^^^^^^^^^^^^^''' + configLocation: "user@host:invalid/uri"''': ''' +line 4, column 21 of file.yaml: Could not create `Builder`. Unsupported value for `configLocation`. Illegal scheme character at offset 4. + ╷ +4 │ configLocation: "user@host:invalid/uri" + │ ^^^^^^^^^^^^^^^^^^^^^^^ + ╵''' }; String _prettyPrintCheckedFromJsonException(CheckedFromJsonException err) { From 678f978bac9da0738de2e285f49ede67ddf2c948 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 6 Dec 2018 10:27:25 +0000 Subject: [PATCH 038/569] Doc fixes --- json_annotation/lib/src/json_key.dart | 10 ++++++---- json_annotation/lib/src/json_serializable.dart | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/json_annotation/lib/src/json_key.dart b/json_annotation/lib/src/json_key.dart index 57b6e86b0..9e76bb6da 100644 --- a/json_annotation/lib/src/json_key.dart +++ b/json_annotation/lib/src/json_key.dart @@ -12,9 +12,8 @@ class JsonKey { /// If `null`, the field name is used. final String name; - /// When `true`, `null` values are handled gracefully when - /// serializing the field to JSON and when deserializing `null` and - /// nonexistent values from a JSON map. + /// When `true`, `null` values are handled gracefully when serializing to JSON + /// and when deserializing `null` and nonexistent values from a JSON map. /// /// Setting to `false` eliminates `null` verification in the generated code /// for the annotated field, which reduces the code size. Errors may be thrown @@ -26,7 +25,10 @@ class JsonKey { /// enclosing class. final bool nullable; - /// `true` if the generator should include the this field in the serialized + /// Whether the generator should include fields with `null` values in the + /// serialized output. + /// + /// If `true`, the generator should include the field in the serialized /// output, even if the value is `null`. /// /// The default value, `null`, indicates that the behavior should be diff --git a/json_annotation/lib/src/json_serializable.dart b/json_annotation/lib/src/json_serializable.dart index d138a11db..15ddd8b5e 100644 --- a/json_annotation/lib/src/json_serializable.dart +++ b/json_annotation/lib/src/json_serializable.dart @@ -157,8 +157,8 @@ class JsonSerializable { final bool includeIfNull; /// When `true` (the default), `null` values are handled gracefully when - /// serializing fields to JSON and when deserializing `null` and nonexistent - /// values from a JSON map. + /// serializing to JSON and when deserializing `null` and nonexistent values + /// from a JSON map. /// /// Setting to `false` eliminates `null` verification in the generated code, /// which reduces the code size. Errors may be thrown at runtime if `null` From d28312a77c9c56fe6ee03268f6206bacaf4e3c37 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Fri, 25 Jan 2019 11:01:38 -0800 Subject: [PATCH 039/569] format build.yaml --- json_serializable/build.yaml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/json_serializable/build.yaml b/json_serializable/build.yaml index 765e4d866..c595b3afd 100644 --- a/json_serializable/build.yaml +++ b/json_serializable/build.yaml @@ -30,8 +30,8 @@ builders: runs_before: ["json_serializable"] defaults: generate_for: - - test/default_value/default_value.dart - - test/kitchen_sink/kitchen_sink.non_nullable.dart + - test/default_value/default_value.dart + - test/kitchen_sink/kitchen_sink.non_nullable.dart non_null: import: 'tool/builder.dart' @@ -42,8 +42,8 @@ builders: runs_before: ["json_serializable"] defaults: generate_for: - - test/kitchen_sink/kitchen_sink.dart - - test/integration/json_test_example.dart + - test/kitchen_sink/kitchen_sink.dart + - test/integration/json_test_example.dart wrapped: import: 'tool/builder.dart' @@ -54,11 +54,11 @@ builders: runs_before: ["json_serializable"] defaults: generate_for: - - test/generic_files/generic_class.dart - - test/kitchen_sink/kitchen_sink.dart - - test/kitchen_sink/kitchen_sink.non_nullable.dart - - test/integration/json_test_example.dart - - test/integration/json_test_example.non_nullable.dart + - test/generic_files/generic_class.dart + - test/kitchen_sink/kitchen_sink.dart + - test/kitchen_sink/kitchen_sink.non_nullable.dart + - test/integration/json_test_example.dart + - test/integration/json_test_example.non_nullable.dart json_serializable: import: "package:json_serializable/builder.dart" From 06718b94d8e213e7b057326e3d3c555c940c1362 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Fri, 25 Jan 2019 12:24:25 -0800 Subject: [PATCH 040/569] generate kitche_sink variants with correct formatting avoiding format in the generator saves a lot of time DRY up custom builders --- .../test/kitchen_sink/kitchen_sink.dart | 15 +- .../kitchen_sink.non_nullable.checked.dart | 18 ++- .../kitchen_sink.non_nullable.dart | 18 ++- .../kitchen_sink.non_nullable.wrapped.dart | 27 ++-- .../kitchen_sink/kitchen_sink.wrapped.dart | 15 +- json_serializable/tool/builder.dart | 136 +++++++++--------- 6 files changed, 138 insertions(+), 91 deletions(-) diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.dart b/json_serializable/test/kitchen_sink/kitchen_sink.dart index c9f7c4829..e7e01f590 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.dart @@ -37,7 +37,10 @@ k.KitchenSink testFactory( k.KitchenSink testFromJson(Map json) => KitchenSink.fromJson(json); -@JsonSerializable(anyMap: true, generateToJsonFunction: false) +@JsonSerializable( + anyMap: true, + generateToJsonFunction: false, +) class KitchenSink extends Object with _$KitchenSinkSerializerMixin implements k.KitchenSink { @@ -136,7 +139,10 @@ class KitchenSink extends Object bool operator ==(Object other) => k.sinkEquals(this, other); } -@JsonSerializable(anyMap: true, generateToJsonFunction: false) +@JsonSerializable( + anyMap: true, + generateToJsonFunction: false, +) // referencing a top-level field should work @durationConverter // referencing via a const constructor should work @@ -162,7 +168,10 @@ class JsonConverterTestClass extends Object DateTime dateTime; } -@JsonSerializable(anyMap: true, generateToJsonFunction: false) +@JsonSerializable( + anyMap: true, + generateToJsonFunction: false, +) @GenericConverter() class JsonConverterGeneric extends Object with _$JsonConverterGenericSerializerMixin { diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.checked.dart b/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.checked.dart index 7791d72a2..82a8180b1 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.checked.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.checked.dart @@ -50,7 +50,11 @@ k.KitchenSink testFactory( k.KitchenSink testFromJson(Map json) => KitchenSink.fromJson(json); @JsonSerializable( - checked: true, nullable: false, anyMap: true, generateToJsonFunction: false) + checked: true, + nullable: false, + anyMap: true, + generateToJsonFunction: false, +) class KitchenSink extends Object with _$KitchenSinkSerializerMixin implements k.KitchenSink { @@ -150,7 +154,11 @@ class KitchenSink extends Object } @JsonSerializable( - checked: true, nullable: false, anyMap: true, generateToJsonFunction: false) + checked: true, + nullable: false, + anyMap: true, + generateToJsonFunction: false, +) // referencing a top-level field should work @durationConverter // referencing via a const constructor should work @@ -177,7 +185,11 @@ class JsonConverterTestClass extends Object } @JsonSerializable( - checked: true, nullable: false, anyMap: true, generateToJsonFunction: false) + checked: true, + nullable: false, + anyMap: true, + generateToJsonFunction: false, +) @GenericConverter() class JsonConverterGeneric extends Object with _$JsonConverterGenericSerializerMixin { diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.dart b/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.dart index 89c7fd4dd..a8ace5ef1 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.dart @@ -43,7 +43,11 @@ k.KitchenSink testFactory( k.KitchenSink testFromJson(Map json) => KitchenSink.fromJson(json); -@JsonSerializable(nullable: false, anyMap: true, generateToJsonFunction: false) +@JsonSerializable( + nullable: false, + anyMap: true, + generateToJsonFunction: false, +) class KitchenSink extends Object with _$KitchenSinkSerializerMixin implements k.KitchenSink { @@ -142,7 +146,11 @@ class KitchenSink extends Object bool operator ==(Object other) => k.sinkEquals(this, other); } -@JsonSerializable(nullable: false, anyMap: true, generateToJsonFunction: false) +@JsonSerializable( + nullable: false, + anyMap: true, + generateToJsonFunction: false, +) // referencing a top-level field should work @durationConverter // referencing via a const constructor should work @@ -168,7 +176,11 @@ class JsonConverterTestClass extends Object DateTime dateTime = DateTime(1981, 6, 5); } -@JsonSerializable(nullable: false, anyMap: true, generateToJsonFunction: false) +@JsonSerializable( + nullable: false, + anyMap: true, + generateToJsonFunction: false, +) @GenericConverter() class JsonConverterGeneric extends Object with _$JsonConverterGenericSerializerMixin { diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.wrapped.dart b/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.wrapped.dart index 10cef19a9..6e39dd7bf 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.wrapped.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.wrapped.dart @@ -50,10 +50,11 @@ k.KitchenSink testFactory( k.KitchenSink testFromJson(Map json) => KitchenSink.fromJson(json); @JsonSerializable( - useWrappers: true, - nullable: false, - anyMap: true, - generateToJsonFunction: false) + useWrappers: true, + nullable: false, + anyMap: true, + generateToJsonFunction: false, +) class KitchenSink extends Object with _$KitchenSinkSerializerMixin implements k.KitchenSink { @@ -153,10 +154,11 @@ class KitchenSink extends Object } @JsonSerializable( - useWrappers: true, - nullable: false, - anyMap: true, - generateToJsonFunction: false) + useWrappers: true, + nullable: false, + anyMap: true, + generateToJsonFunction: false, +) // referencing a top-level field should work @durationConverter // referencing via a const constructor should work @@ -183,10 +185,11 @@ class JsonConverterTestClass extends Object } @JsonSerializable( - useWrappers: true, - nullable: false, - anyMap: true, - generateToJsonFunction: false) + useWrappers: true, + nullable: false, + anyMap: true, + generateToJsonFunction: false, +) @GenericConverter() class JsonConverterGeneric extends Object with _$JsonConverterGenericSerializerMixin { diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.wrapped.dart b/json_serializable/test/kitchen_sink/kitchen_sink.wrapped.dart index d0d284727..02c3976ab 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.wrapped.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.wrapped.dart @@ -44,7 +44,10 @@ k.KitchenSink testFactory( k.KitchenSink testFromJson(Map json) => KitchenSink.fromJson(json); @JsonSerializable( - useWrappers: true, anyMap: true, generateToJsonFunction: false) + useWrappers: true, + anyMap: true, + generateToJsonFunction: false, +) class KitchenSink extends Object with _$KitchenSinkSerializerMixin implements k.KitchenSink { @@ -144,7 +147,10 @@ class KitchenSink extends Object } @JsonSerializable( - useWrappers: true, anyMap: true, generateToJsonFunction: false) + useWrappers: true, + anyMap: true, + generateToJsonFunction: false, +) // referencing a top-level field should work @durationConverter // referencing via a const constructor should work @@ -171,7 +177,10 @@ class JsonConverterTestClass extends Object } @JsonSerializable( - useWrappers: true, anyMap: true, generateToJsonFunction: false) + useWrappers: true, + anyMap: true, + generateToJsonFunction: false, +) @GenericConverter() class JsonConverterGeneric extends Object with _$JsonConverterGenericSerializerMixin { diff --git a/json_serializable/tool/builder.dart b/json_serializable/tool/builder.dart index c321ce3d5..07ef11626 100644 --- a/json_serializable/tool/builder.dart +++ b/json_serializable/tool/builder.dart @@ -16,98 +16,95 @@ final _copyrightContent = final copyrightHeader = '$_copyrightContent\n$defaultFileHeader'; -Builder nonNull([_]) => LibraryBuilder(_NonNullableGenerator(), - generatedExtension: '.non_nullable.dart', header: copyrightHeader); +LibraryBuilder _builder(_ReplaceGenerator generator) => LibraryBuilder( + generator, + generatedExtension: '.${generator.gName}.dart', + header: copyrightHeader, + formatOutput: (a) => a, + ); -Builder wrapped([_]) => LibraryBuilder(_WrappedGenerator(), - generatedExtension: '.wrapped.dart', header: copyrightHeader); +Builder nonNull([_]) => _builder(_NonNullableGenerator()); -Builder checked([_]) => LibraryBuilder(_CheckedGenerator(), - generatedExtension: '.checked.dart', header: copyrightHeader); +Builder wrapped([_]) => _builder(_WrappedGenerator()); + +Builder checked([_]) => _builder(_CheckedGenerator()); + +abstract class _ReplaceGenerator extends Generator { + final String gName; + + _ReplaceGenerator(this.gName); -class _NonNullableGenerator extends Generator { @override FutureOr generate(LibraryReader library, BuildStep buildStep) async { final path = buildStep.inputId.path; final baseName = p.basenameWithoutExtension(path); final content = await buildStep.readAsString(buildStep.inputId); - final replacements = [ - _Replacement(_copyrightContent, ''), - _Replacement( - "part '$baseName.g.dart", - "part '$baseName.non_nullable.g.dart", - ), - _Replacement('@JsonSerializable(', '@JsonSerializable(nullable: false,'), - ]; + + return _Replacement.generate(content, createReplacements(baseName)); + } + + Iterable<_Replacement> createReplacements(String baseName) sync* { + yield _Replacement(_copyrightContent, ''); + + yield _Replacement( + "part '$baseName.g.dart", + "part '$baseName.$gName.g.dart", + ); + } +} + +class _NonNullableGenerator extends _ReplaceGenerator { + _NonNullableGenerator() : super('non_nullable'); + + @override + Iterable<_Replacement> createReplacements(String baseName) sync* { + yield* super.createReplacements(baseName); + + yield _Replacement.addJsonSerializableKey('nullable', false); if (baseName == 'kitchen_sink') { - replacements.addAll([ - _Replacement('List _defaultList() => null;', - 'List _defaultList() => [];'), - _Replacement('Set _defaultSet() => null;', - 'Set _defaultSet() => Set();'), - _Replacement('Map _defaultMap() => null;', - 'Map _defaultMap() => {};'), - _Replacement('SimpleObject _defaultSimpleObject() => null;', - 'SimpleObject _defaultSimpleObject() => SimpleObject(42);'), - _Replacement( - 'StrictKeysObject _defaultStrictKeysObject() => null;', - 'StrictKeysObject _defaultStrictKeysObject() => ' - "StrictKeysObject(10, 'cool');"), - _Replacement( - 'DateTime dateTime;', 'DateTime dateTime = DateTime(1981, 6, 5);') - ]); + yield _Replacement('List _defaultList() => null;', + 'List _defaultList() => [];'); + yield _Replacement('Set _defaultSet() => null;', + 'Set _defaultSet() => Set();'); + yield _Replacement('Map _defaultMap() => null;', + 'Map _defaultMap() => {};'); + yield _Replacement('SimpleObject _defaultSimpleObject() => null;', + 'SimpleObject _defaultSimpleObject() => SimpleObject(42);'); + yield _Replacement( + 'StrictKeysObject _defaultStrictKeysObject() => null;', + 'StrictKeysObject _defaultStrictKeysObject() => ' + "StrictKeysObject(10, 'cool');"); + yield _Replacement( + 'DateTime dateTime;', 'DateTime dateTime = DateTime(1981, 6, 5);'); } - - return _Replacement.generate(content, replacements); } } -class _CheckedGenerator extends Generator { +class _CheckedGenerator extends _ReplaceGenerator { + _CheckedGenerator() : super('checked'); + @override - FutureOr generate(LibraryReader library, BuildStep buildStep) async { - final path = buildStep.inputId.path; - final baseName = p.basenameWithoutExtension(path); + Iterable<_Replacement> createReplacements(String baseName) sync* { + yield* super.createReplacements(baseName); - final content = await buildStep.readAsString(buildStep.inputId); - final replacements = [ - _Replacement('@JsonSerializable(', '@JsonSerializable(checked: true,'), - _Replacement(_copyrightContent, ''), - _Replacement( - "part '$baseName.g.dart", - "part '$baseName.checked.g.dart", - ), - ]; + yield _Replacement.addJsonSerializableKey('checked', true); if (baseName == 'default_value') { - replacements.add( - _Replacement('@JsonSerializable(', '@JsonSerializable(anyMap: true,'), - ); + yield _Replacement.addJsonSerializableKey('anyMap', true); } - - return _Replacement.generate(content, replacements); } } -class _WrappedGenerator extends Generator { +class _WrappedGenerator extends _ReplaceGenerator { + _WrappedGenerator() : super('wrapped'); + @override - FutureOr generate(LibraryReader library, BuildStep buildStep) async { - final path = buildStep.inputId.path; - final baseName = p.basenameWithoutExtension(path); + Iterable<_Replacement> createReplacements(String baseName) sync* { + yield* super.createReplacements(baseName); - final content = await buildStep.readAsString(buildStep.inputId); - final replacements = [ - _Replacement(_copyrightContent, ''), - _Replacement( - "part '$baseName.g.dart", - "part '$baseName.wrapped.g.dart", - ), - _Replacement( - '@JsonSerializable(', '@JsonSerializable(useWrappers: true,'), - ]; - - return _Replacement.generate(content, replacements); + yield _Replacement.addJsonSerializableKey('useWrappers', true); } } @@ -117,6 +114,9 @@ class _Replacement { _Replacement(this.existing, this.replacement); + factory _Replacement.addJsonSerializableKey(String key, bool value) => + _Replacement('@JsonSerializable(', '@JsonSerializable(\n $key: $value,'); + static String generate( String inputContent, Iterable<_Replacement> replacements) { var outputContent = inputContent; @@ -129,6 +129,8 @@ class _Replacement { outputContent = outputContent.replaceAll(r.existing, r.replacement); } + outputContent = outputContent.replaceAll(',)', ',\n)'); + return outputContent; } } From 860787f7c2411f82ad3e2e2d3386ede12df8eb33 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 28 Jan 2019 08:29:36 -0800 Subject: [PATCH 041/569] Fix: avoid a no-op call to `map` when creating a Set (#376) --- json_serializable/CHANGELOG.md | 2 ++ .../lib/src/type_helpers/iterable_helper.dart | 7 +++++-- json_serializable/test/kitchen_sink/kitchen_sink.g.dart | 6 +++--- .../kitchen_sink.non_nullable.checked.g.dart | 9 ++++----- .../test/kitchen_sink/kitchen_sink.non_nullable.g.dart | 6 +++--- .../kitchen_sink.non_nullable.wrapped.g.dart | 6 +++--- .../test/kitchen_sink/kitchen_sink.wrapped.g.dart | 6 +++--- 7 files changed, 23 insertions(+), 19 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index b91ad6a67..d5ba4e8d8 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -3,6 +3,8 @@ * Log a warning when `defaultValue` is used with `toJson` in `JsonKey`. In this case, use `nullable: false` instead of `defaultValue`. +* Avoid no-op call to `map` when decoding a field of type `Set`. + ## 2.0.1 * Support `pkg:analyzer` v0.34.0. diff --git a/json_serializable/lib/src/type_helpers/iterable_helper.dart b/json_serializable/lib/src/type_helpers/iterable_helper.dart index 21df85c4c..357546b59 100644 --- a/json_serializable/lib/src/type_helpers/iterable_helper.dart +++ b/json_serializable/lib/src/type_helpers/iterable_helper.dart @@ -78,9 +78,12 @@ class IterableHelper extends TypeHelper { final optionalQuestion = context.nullable ? '?' : ''; - final lambda = LambdaResult.process(itemSubVal, closureArg); + var output = '($expression as List)'; - var output = '($expression as List)$optionalQuestion.map($lambda)'; + if (closureArg != itemSubVal) { + final lambda = LambdaResult.process(itemSubVal, closureArg); + output += '$optionalQuestion.map($lambda)'; + } if (_coreListChecker.isAssignableFromType(targetType)) { output += '$optionalQuestion.toList()'; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g.dart index 04d402dee..4fdfdc6e4 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g.dart @@ -18,9 +18,9 @@ KitchenSink _$KitchenSinkFromJson(Map json) { ..dateTime = json['dateTime'] == null ? null : DateTime.parse(json['dateTime'] as String) - ..set = (json['set'] as List)?.map((e) => e)?.toSet() - ..dynamicSet = (json['dynamicSet'] as List)?.map((e) => e)?.toSet() - ..objectSet = (json['objectSet'] as List)?.map((e) => e)?.toSet() + ..set = (json['set'] as List)?.toSet() + ..dynamicSet = (json['dynamicSet'] as List)?.toSet() + ..objectSet = (json['objectSet'] as List)?.toSet() ..intSet = (json['intSet'] as List)?.map((e) => e as int)?.toSet() ..dateTimeSet = (json['dateTimeSet'] as List) ?.map((e) => e == null ? null : DateTime.parse(e as String)) diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.checked.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.checked.g.dart index ed10e11f1..b5aedfe5c 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.checked.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.checked.g.dart @@ -21,12 +21,11 @@ KitchenSink _$KitchenSinkFromJson(Map json) { (v) => (v as List).map((e) => DateTime.parse(e as String)))); $checkedConvert( json, 'dateTime', (v) => val.dateTime = DateTime.parse(v as String)); + $checkedConvert(json, 'set', (v) => val.set = (v as List).toSet()); $checkedConvert( - json, 'set', (v) => val.set = (v as List).map((e) => e).toSet()); - $checkedConvert(json, 'dynamicSet', - (v) => val.dynamicSet = (v as List).map((e) => e).toSet()); - $checkedConvert(json, 'objectSet', - (v) => val.objectSet = (v as List).map((e) => e).toSet()); + json, 'dynamicSet', (v) => val.dynamicSet = (v as List).toSet()); + $checkedConvert( + json, 'objectSet', (v) => val.objectSet = (v as List).toSet()); $checkedConvert(json, 'intSet', (v) => val.intSet = (v as List).map((e) => e as int).toSet()); $checkedConvert( diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.g.dart index 22987076a..15dbad040 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.g.dart @@ -16,9 +16,9 @@ KitchenSink _$KitchenSinkFromJson(Map json) { dateTimeIterable: (json['datetime-iterable'] as List) .map((e) => DateTime.parse(e as String))) ..dateTime = DateTime.parse(json['dateTime'] as String) - ..set = (json['set'] as List).map((e) => e).toSet() - ..dynamicSet = (json['dynamicSet'] as List).map((e) => e).toSet() - ..objectSet = (json['objectSet'] as List).map((e) => e).toSet() + ..set = (json['set'] as List).toSet() + ..dynamicSet = (json['dynamicSet'] as List).toSet() + ..objectSet = (json['objectSet'] as List).toSet() ..intSet = (json['intSet'] as List).map((e) => e as int).toSet() ..dateTimeSet = (json['dateTimeSet'] as List) .map((e) => DateTime.parse(e as String)) diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.wrapped.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.wrapped.g.dart index d1b9b0fff..322a45bf9 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.wrapped.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.wrapped.g.dart @@ -16,9 +16,9 @@ KitchenSink _$KitchenSinkFromJson(Map json) { dateTimeIterable: (json['datetime-iterable'] as List) .map((e) => DateTime.parse(e as String))) ..dateTime = DateTime.parse(json['dateTime'] as String) - ..set = (json['set'] as List).map((e) => e).toSet() - ..dynamicSet = (json['dynamicSet'] as List).map((e) => e).toSet() - ..objectSet = (json['objectSet'] as List).map((e) => e).toSet() + ..set = (json['set'] as List).toSet() + ..dynamicSet = (json['dynamicSet'] as List).toSet() + ..objectSet = (json['objectSet'] as List).toSet() ..intSet = (json['intSet'] as List).map((e) => e as int).toSet() ..dateTimeSet = (json['dateTimeSet'] as List) .map((e) => DateTime.parse(e as String)) diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.wrapped.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.wrapped.g.dart index 07396d5f5..14e89ac09 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.wrapped.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.wrapped.g.dart @@ -18,9 +18,9 @@ KitchenSink _$KitchenSinkFromJson(Map json) { ..dateTime = json['dateTime'] == null ? null : DateTime.parse(json['dateTime'] as String) - ..set = (json['set'] as List)?.map((e) => e)?.toSet() - ..dynamicSet = (json['dynamicSet'] as List)?.map((e) => e)?.toSet() - ..objectSet = (json['objectSet'] as List)?.map((e) => e)?.toSet() + ..set = (json['set'] as List)?.toSet() + ..dynamicSet = (json['dynamicSet'] as List)?.toSet() + ..objectSet = (json['objectSet'] as List)?.toSet() ..intSet = (json['intSet'] as List)?.map((e) => e as int)?.toSet() ..dateTimeSet = (json['dateTimeSet'] as List) ?.map((e) => e == null ? null : DateTime.parse(e as String)) From 4114ab87fb2e1d4ca708826b8525fa07aaa1d920 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 29 Jan 2019 12:19:18 -0800 Subject: [PATCH 042/569] Simplify DefaultWithToJsonClass test case --- json_serializable/test/src/default_value_input.dart | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/json_serializable/test/src/default_value_input.dart b/json_serializable/test/src/default_value_input.dart index 961b7c430..98985ccc7 100644 --- a/json_serializable/test/src/default_value_input.dart +++ b/json_serializable/test/src/default_value_input.dart @@ -81,7 +81,6 @@ class DefaultWithNonNullableClass { @ShouldGenerate(r''' DefaultWithToJsonClass _$DefaultWithToJsonClassFromJson( Map json) { - $checkKeys(json, allowedKeys: const ['fieldDefaultValueToJson']); return DefaultWithToJsonClass() ..fieldDefaultValueToJson = json['fieldDefaultValueToJson'] == null ? null @@ -94,7 +93,7 @@ DefaultWithToJsonClass _$DefaultWithToJsonClassFromJson( The field `fieldDefaultValueToJson` has both `defaultValue` and `fromJson` defined which likely won't work for your scenario. Instead of using `defaultValue`, set `nullable: false` and handle `null` in the `fromJson` function.''' ]) -@JsonSerializable(disallowUnrecognizedKeys: true, createToJson: false) +@JsonSerializable(createToJson: false) class DefaultWithToJsonClass { @JsonKey(defaultValue: 7, fromJson: _fromJson) int fieldDefaultValueToJson; From 7e368ebd5909be193ca985c0bd4b81069a5436b8 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 29 Jan 2019 12:38:35 -0800 Subject: [PATCH 043/569] print a warning for fields with `defaultValue` and inconsistent options Namely `disallowNullValue` and `required` set to `true` --- json_serializable/CHANGELOG.md | 3 +++ json_serializable/lib/src/decode_helper.dart | 8 +++++++- .../test/json_serializable_test.dart | 1 + .../test/src/default_value_input.dart | 19 +++++++++++++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index d5ba4e8d8..5afedfd54 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -5,6 +5,9 @@ * Avoid no-op call to `map` when decoding a field of type `Set`. +* A warning is now printed if a field as a `defaultValue` and both + `disallowNullValue` and `required` set to `true`. + ## 2.0.1 * Support `pkg:analyzer` v0.34.0. diff --git a/json_serializable/lib/src/decode_helper.dart b/json_serializable/lib/src/decode_helper.dart index 19239efc4..fb8ba3772 100644 --- a/json_serializable/lib/src/decode_helper.dart +++ b/json_serializable/lib/src/decode_helper.dart @@ -187,12 +187,18 @@ abstract class DecodeHelper implements HelperCore { throw createInvalidGenerationError('fromJson', field, e); } - final defaultValue = jsonKeyFor(field).defaultValue; + final jsonKey = jsonKeyFor(field); + final defaultValue = jsonKey.defaultValue; if (defaultValue != null) { if (!contextHelper.nullable) { throwUnsupported(field, 'Cannot use `defaultValue` on a field with `nullable` false.'); } + if (jsonKey.disallowNullValue && jsonKey.required) { + log.warning('The `defaultValue` on field `${field.name}` will have no ' + 'effect because both `disallowNullValue` and `required` are set to ' + '`true`.'); + } if (contextHelper.deserializeConvertData != null) { log.warning('The field `${field.name}` has both `defaultValue` and ' '`fromJson` defined which likely won\'t work for your scenario.\n' diff --git a/json_serializable/test/json_serializable_test.dart b/json_serializable/test/json_serializable_test.dart index e3f9549db..de4583850 100644 --- a/json_serializable/test/json_serializable_test.dart +++ b/json_serializable/test/json_serializable_test.dart @@ -89,6 +89,7 @@ const _expectedAnnotatedTests = { 'DefaultWithNonNullableField', 'DefaultWithNonNullableClass', 'DefaultWithToJsonClass', + 'DefaultWithDisallowNullRequiredClass', ], 'field_namer_input.dart': [ 'FieldNamerNone', diff --git a/json_serializable/test/src/default_value_input.dart b/json_serializable/test/src/default_value_input.dart index 98985ccc7..ef760a055 100644 --- a/json_serializable/test/src/default_value_input.dart +++ b/json_serializable/test/src/default_value_input.dart @@ -102,3 +102,22 @@ class DefaultWithToJsonClass { static int _fromJson(String input) => 41; } + +@ShouldGenerate(r''' +DefaultWithDisallowNullRequiredClass + _$DefaultWithDisallowNullRequiredClassFromJson(Map json) { + $checkKeys(json, + requiredKeys: const ['theField'], disallowNullValues: const ['theField']); + return DefaultWithDisallowNullRequiredClass() + ..theField = json['theField'] as int ?? 7; +} +''', expectedLogItems: [ + 'The `defaultValue` on field `theField` will have no effect because both `disallowNullValue` and `required` are set to `true`.' +]) +@JsonSerializable(createToJson: false) +class DefaultWithDisallowNullRequiredClass { + @JsonKey(defaultValue: 7, disallowNullValue: true, required: true) + int theField; + + DefaultWithDisallowNullRequiredClass(); +} From ea07a798e8e09a9e683e0afa9291c6129b094082 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 28 Jan 2019 08:44:05 -0800 Subject: [PATCH 044/569] Cleanup to JsonSerializable annotation params in several places --- .../lib/src/json_serializable.dart | 23 ++++++------- .../lib/src/json_serializable.g.dart | 27 +++++++-------- json_serializable/lib/src/json_key_utils.dart | 33 ++++++++++--------- .../test/src/configuration_input.dart | 13 ++++---- 4 files changed, 50 insertions(+), 46 deletions(-) diff --git a/json_annotation/lib/src/json_serializable.dart b/json_annotation/lib/src/json_serializable.dart index 15ddd8b5e..58d24a050 100644 --- a/json_annotation/lib/src/json_serializable.dart +++ b/json_annotation/lib/src/json_serializable.dart @@ -194,17 +194,18 @@ class JsonSerializable { /// An instance of [JsonSerializable] with all fields set to their default /// values. static const defaults = JsonSerializable( - anyMap: false, - checked: false, - createFactory: true, - createToJson: true, - disallowUnrecognizedKeys: false, - explicitToJson: false, - fieldRename: FieldRename.none, - generateToJsonFunction: true, - includeIfNull: true, - nullable: true, - useWrappers: false); + anyMap: false, + checked: false, + createFactory: true, + createToJson: true, + disallowUnrecognizedKeys: false, + explicitToJson: false, + fieldRename: FieldRename.none, + generateToJsonFunction: true, + includeIfNull: true, + nullable: true, + useWrappers: false, + ); /// Returns a new [JsonSerializable] instance with fields equal to the /// corresponding values in `this`, if not `null`. diff --git a/json_annotation/lib/src/json_serializable.g.dart b/json_annotation/lib/src/json_serializable.g.dart index dc43fe7e1..ab9320693 100644 --- a/json_annotation/lib/src/json_serializable.g.dart +++ b/json_annotation/lib/src/json_serializable.g.dart @@ -18,21 +18,22 @@ JsonSerializable _$JsonSerializableFromJson(Map json) { 'generate_to_json_function', 'include_if_null', 'nullable', - 'use_wrappers' + 'use_wrappers', ]); return JsonSerializable( - anyMap: json['any_map'] as bool, - checked: json['checked'] as bool, - explicitToJson: json['explicit_to_json'] as bool, - generateToJsonFunction: json['generate_to_json_function'] as bool, - useWrappers: json['use_wrappers'] as bool, - disallowUnrecognizedKeys: json['disallow_unrecognized_keys'] as bool, - createFactory: json['create_factory'] as bool, - createToJson: json['create_to_json'] as bool, - includeIfNull: json['include_if_null'] as bool, - nullable: json['nullable'] as bool, - fieldRename: - _$enumDecodeNullable(_$FieldRenameEnumMap, json['field_rename'])); + anyMap: json['any_map'] as bool, + checked: json['checked'] as bool, + createFactory: json['create_factory'] as bool, + createToJson: json['create_to_json'] as bool, + disallowUnrecognizedKeys: json['disallow_unrecognized_keys'] as bool, + explicitToJson: json['explicit_to_json'] as bool, + fieldRename: + _$enumDecodeNullable(_$FieldRenameEnumMap, json['field_rename']), + generateToJsonFunction: json['generate_to_json_function'] as bool, + includeIfNull: json['include_if_null'] as bool, + nullable: json['nullable'] as bool, + useWrappers: json['use_wrappers'] as bool, + ); } Map _$JsonSerializableToJson(JsonSerializable instance) => diff --git a/json_serializable/lib/src/json_key_utils.dart b/json_serializable/lib/src/json_key_utils.dart index 0fb7cf628..188bac18f 100644 --- a/json_serializable/lib/src/json_key_utils.dart +++ b/json_serializable/lib/src/json_key_utils.dart @@ -106,36 +106,37 @@ JsonKey _from(FieldElement element, JsonSerializable classAnnotation) { return _populateJsonKey( classAnnotation, element, + defaultValue: defaultValueLiteral, + disallowNullValue: disallowNullValue, + ignore: obj.getField('ignore').toBoolValue(), + includeIfNull: includeIfNull, name: obj.getField('name').toStringValue(), nullable: obj.getField('nullable').toBoolValue(), - includeIfNull: includeIfNull, - ignore: obj.getField('ignore').toBoolValue(), - defaultValue: defaultValueLiteral, required: obj.getField('required').toBoolValue(), - disallowNullValue: disallowNullValue, ); } JsonKey _populateJsonKey( JsonSerializable classAnnotation, FieldElement fieldElement, { + Object defaultValue, + bool disallowNullValue, + bool ignore, + bool includeIfNull, String name, bool nullable, - bool includeIfNull, - bool ignore, - Object defaultValue, bool required, - bool disallowNullValue, }) { final jsonKey = JsonKey( - name: _encodedFieldName(classAnnotation, name, fieldElement), - nullable: nullable ?? classAnnotation.nullable, - includeIfNull: _includeIfNull( - includeIfNull, disallowNullValue, classAnnotation.includeIfNull), - ignore: ignore ?? false, - defaultValue: defaultValue, - required: required ?? false, - disallowNullValue: disallowNullValue ?? false); + defaultValue: defaultValue, + disallowNullValue: disallowNullValue ?? false, + ignore: ignore ?? false, + includeIfNull: _includeIfNull( + includeIfNull, disallowNullValue, classAnnotation.includeIfNull), + name: _encodedFieldName(classAnnotation, name, fieldElement), + nullable: nullable ?? classAnnotation.nullable, + required: required ?? false, + ); return jsonKey; } diff --git a/json_serializable/test/src/configuration_input.dart b/json_serializable/test/src/configuration_input.dart index d23f195e0..bb134a5e9 100644 --- a/json_serializable/test/src/configuration_input.dart +++ b/json_serializable/test/src/configuration_input.dart @@ -23,12 +23,13 @@ class ConfigurationExplicitDefaults { } @JsonSerializable( - createToJson: true, - includeIfNull: true, - nullable: true, - disallowUnrecognizedKeys: true, - fieldRename: FieldRename.snake, - createFactory: true) + createFactory: true, + createToJson: true, + disallowUnrecognizedKeys: true, + fieldRename: FieldRename.snake, + includeIfNull: true, + nullable: true, +) class ConfigurationAllDefaultsOpposite { int field; } From d4e7f6c15f1b4ffa06ed52412aae068f1c78aac0 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 28 Jan 2019 08:57:32 -0800 Subject: [PATCH 045/569] Remove unused test class --- json_serializable/test/src/configuration_input.dart | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/json_serializable/test/src/configuration_input.dart b/json_serializable/test/src/configuration_input.dart index bb134a5e9..0765f3457 100644 --- a/json_serializable/test/src/configuration_input.dart +++ b/json_serializable/test/src/configuration_input.dart @@ -21,15 +21,3 @@ class ConfigurationImplicitDefaults { class ConfigurationExplicitDefaults { int field; } - -@JsonSerializable( - createFactory: true, - createToJson: true, - disallowUnrecognizedKeys: true, - fieldRename: FieldRename.snake, - includeIfNull: true, - nullable: true, -) -class ConfigurationAllDefaultsOpposite { - int field; -} From 0f9ce369b4379a40ea6ffbf4d75dd4dc7e85aab8 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 31 Jan 2019 17:54:11 -0800 Subject: [PATCH 046/569] Support the latest version of pkg:analyzer, prepare v2.0.2 for release --- json_serializable/CHANGELOG.md | 12 ++++++------ json_serializable/lib/src/json_key_utils.dart | 14 +++++++++----- json_serializable/lib/src/utils.dart | 14 +++++++++++++- json_serializable/pubspec.yaml | 4 ++-- json_serializable/test/json_serializable_test.dart | 1 + 5 files changed, 31 insertions(+), 14 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 5afedfd54..93bf767bd 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,16 +1,16 @@ ## 2.0.2 -* Log a warning when `defaultValue` is used with `toJson` in `JsonKey`. In this - case, use `nullable: false` instead of `defaultValue`. +* Log warnings when `JsonKey.defaultValue` is set with other fields. + * With `toJson`: use `nullable: false` instead of `defaultValue`. + * With both `disallowNullValue` and `required` set to `true`. * Avoid no-op call to `map` when decoding a field of type `Set`. -* A warning is now printed if a field as a `defaultValue` and both - `disallowNullValue` and `required` set to `true`. +* Support `package:analyzer` `>=0.33.3 <0.36.0` ## 2.0.1 -* Support `pkg:analyzer` v0.34.0. +* Support `package:analyzer` v0.34.0. ## 2.0.0 @@ -50,7 +50,7 @@ ## 1.5.1 -* Support the latest `pkg:analyzer`. +* Support the latest `package:analyzer`. ## 1.5.0 diff --git a/json_serializable/lib/src/json_key_utils.dart b/json_serializable/lib/src/json_key_utils.dart index 188bac18f..233fc4ab9 100644 --- a/json_serializable/lib/src/json_key_utils.dart +++ b/json_serializable/lib/src/json_key_utils.dart @@ -2,9 +2,9 @@ // 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:analyzer/dart/constant/value.dart'; import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/type.dart'; -import 'package:analyzer/dart/constant/value.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:source_gen/source_gen.dart'; @@ -80,10 +80,14 @@ JsonKey _from(FieldElement element, JsonSerializable classAnnotation) { final enumFields = iterateEnumFields(defaultValueObject.type); if (enumFields != null) { - final allowedValues = enumFields.map((p) => p.name).toList(); - final enumValueIndex = defaultValueObject.getField('index').toIntValue(); - defaultValueLiteral = - '${defaultValueObject.type.name}.${allowedValues[enumValueIndex]}'; + var enumValueName = enumFields.map((p) => p.name).singleWhere( + (s) => defaultValueObject.getField(s) != null, + // TODO: remove once pkg:analyzer < 0.35.0 is no longer supported + orElse: () => + enumFields.elementAt(getEnumIndex(defaultValueObject)).name, + ); + + defaultValueLiteral = '${defaultValueObject.type.name}.$enumValueName'; } else { defaultValueLiteral = _getLiteral(defaultValueObject, []); if (defaultValueLiteral != null) { diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index 74a2741f7..64926f0ab 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -46,7 +46,19 @@ void throwUnsupported(FieldElement element, String message) => FieldRename _fromDartObject(ConstantReader reader) => reader.isNull ? null - : FieldRename.values[reader.objectValue.getField('index').toIntValue()]; + : FieldRename.values.singleWhere( + (thing) { + var name = thing.toString().split('.')[1]; + var result = reader.objectValue.getField(name); + return result != null; + }, + // TODO: remove once pkg:analyzer < 0.35.0 is no longer supported + orElse: () => FieldRename.values[getEnumIndex(reader.objectValue)], + ); + +// TODO: remove once pkg:analyzer < 0.35.0 is no longer supported +/// Only valid for for pkg:analyzer < 0.35.0 +int getEnumIndex(DartObject object) => object.getField('index').toIntValue(); /// Return an instance of [JsonSerializable] corresponding to a the provided /// [reader]. diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 090cb481e..b997b712a 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 2.0.2-dev +version: 2.0.2 author: Dart Team description: Generates utilities to aid in serializing to/from JSON. homepage: https://github.com/dart-lang/json_serializable @@ -7,7 +7,7 @@ environment: sdk: '>=2.0.0 <3.0.0' dependencies: - analyzer: '>=0.32.2 <0.35.0' + analyzer: '>=0.33.3 <0.36.0' build: '>=0.12.6 <2.0.0' build_config: '>=0.2.6 <0.4.0' diff --git a/json_serializable/test/json_serializable_test.dart b/json_serializable/test/json_serializable_test.dart index de4583850..13b3b36a3 100644 --- a/json_serializable/test/json_serializable_test.dart +++ b/json_serializable/test/json_serializable_test.dart @@ -365,6 +365,7 @@ String _runForElementNamedWithGenerator( final _annotatedElements = _library.allElements .map((e) { for (final md in e.metadata) { + md.computeConstantValue(); final reader = ConstantReader(md.constantValue); if (const ['ShouldGenerate', 'ShouldThrow'] .contains(reader.objectValue.type.name)) { From b00294fdc5f5d44fc34375316f084c33d1152324 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 31 Jan 2019 20:26:19 -0800 Subject: [PATCH 047/569] DRY up the enum value logic --- json_serializable/lib/src/json_key_utils.dart | 10 ++++---- json_serializable/lib/src/utils.dart | 23 ++++++++----------- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/json_serializable/lib/src/json_key_utils.dart b/json_serializable/lib/src/json_key_utils.dart index 233fc4ab9..183c941f5 100644 --- a/json_serializable/lib/src/json_key_utils.dart +++ b/json_serializable/lib/src/json_key_utils.dart @@ -80,12 +80,10 @@ JsonKey _from(FieldElement element, JsonSerializable classAnnotation) { final enumFields = iterateEnumFields(defaultValueObject.type); if (enumFields != null) { - var enumValueName = enumFields.map((p) => p.name).singleWhere( - (s) => defaultValueObject.getField(s) != null, - // TODO: remove once pkg:analyzer < 0.35.0 is no longer supported - orElse: () => - enumFields.elementAt(getEnumIndex(defaultValueObject)).name, - ); + var enumValueNames = enumFields.map((p) => p.name).toList(growable: false); + + var enumValueName = enumValueForDartObject( + defaultValueObject, enumValueNames, (n) => n); defaultValueLiteral = '${defaultValueObject.type.name}.$enumValueName'; } else { diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index 64926f0ab..6a6629aa0 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -46,19 +46,16 @@ void throwUnsupported(FieldElement element, String message) => FieldRename _fromDartObject(ConstantReader reader) => reader.isNull ? null - : FieldRename.values.singleWhere( - (thing) { - var name = thing.toString().split('.')[1]; - var result = reader.objectValue.getField(name); - return result != null; - }, - // TODO: remove once pkg:analyzer < 0.35.0 is no longer supported - orElse: () => FieldRename.values[getEnumIndex(reader.objectValue)], - ); - -// TODO: remove once pkg:analyzer < 0.35.0 is no longer supported -/// Only valid for for pkg:analyzer < 0.35.0 -int getEnumIndex(DartObject object) => object.getField('index').toIntValue(); + : enumValueForDartObject(reader.objectValue, FieldRename.values, + (f) => f.toString().split('.')[1]); + +T enumValueForDartObject( + DartObject source, List items, String Function(T) name) => + items.singleWhere( + (v) => source.getField(name(v)) != null, + // TODO: remove once pkg:analyzer < 0.35.0 is no longer supported + orElse: () => items[source.getField('index').toIntValue()], + ); /// Return an instance of [JsonSerializable] corresponding to a the provided /// [reader]. From a3e556cc7854ecf815324b3182e1690cb87e477a Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 12 Feb 2019 15:25:15 -0800 Subject: [PATCH 048/569] Small nit to improve failing test output --- json_serializable/test/json_serializable_test.dart | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/json_serializable/test/json_serializable_test.dart b/json_serializable/test/json_serializable_test.dart index 13b3b36a3..eebf08c72 100644 --- a/json_serializable/test/json_serializable_test.dart +++ b/json_serializable/test/json_serializable_test.dart @@ -43,7 +43,10 @@ Matcher _matcherFromShouldGenerateAnnotation(ConstantReader reader, Matcher _throwsInvalidGenerationSourceError(messageMatcher, todoMatcher) => throwsA(const TypeMatcher() - .having((e) => e.message, 'message', messageMatcher) + .having((e) { + printOnFailure("r'''\n${e.message}'''"); + return e.message; + }, 'message', messageMatcher) .having((e) => e.todo, 'todo', todoMatcher) .having((e) => e.element, 'element', isNotNull)); From 4f19d468bf05eed3e4a8ebc27244fc3b8d411dc9 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 12 Feb 2019 15:26:17 -0800 Subject: [PATCH 049/569] Throw an error when an unsupported List, Set, or Map type is used... ...without a corresponding converter Previously, invalid code would be generated. --- json_serializable/CHANGELOG.md | 6 ++++ .../lib/src/type_helpers/iterable_helper.dart | 10 ++++--- .../lib/src/type_helpers/map_helper.dart | 2 +- json_serializable/pubspec.yaml | 2 +- .../test/json_serializable_test.dart | 5 ++++ .../src/_json_serializable_test_input.dart | 4 +++ .../test/src/collection_type_input.dart | 30 +++++++++++++++++++ 7 files changed, 53 insertions(+), 6 deletions(-) create mode 100644 json_serializable/test/src/collection_type_input.dart diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 93bf767bd..40d9a0b9d 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,9 @@ +## 2.0.3 + +* Throw an error when an unsupported `List`, `Set`, or `Map` type is used + without a corresponding converter. + (Previously, invalid code would be generated.) + ## 2.0.2 * Log warnings when `JsonKey.defaultValue` is set with other fields. diff --git a/json_serializable/lib/src/type_helpers/iterable_helper.dart b/json_serializable/lib/src/type_helpers/iterable_helper.dart index 357546b59..3c146e316 100644 --- a/json_serializable/lib/src/type_helpers/iterable_helper.dart +++ b/json_serializable/lib/src/type_helpers/iterable_helper.dart @@ -61,7 +61,9 @@ class IterableHelper extends TypeHelper { @override String deserialize( DartType targetType, String expression, TypeHelperContext context) { - if (!coreIterableTypeChecker.isAssignableFromType(targetType)) { + if (!(coreIterableTypeChecker.isExactlyType(targetType) || + _coreListChecker.isExactlyType(targetType) || + _coreSetChecker.isExactlyType(targetType))) { return null; } @@ -72,7 +74,7 @@ class IterableHelper extends TypeHelper { // If `itemSubVal` is the same and it's not a Set, then we don't need to do // anything fancy if (closureArg == itemSubVal && - !_coreSetChecker.isAssignableFromType(targetType)) { + !_coreSetChecker.isExactlyType(targetType)) { return '$expression as List'; } @@ -85,9 +87,9 @@ class IterableHelper extends TypeHelper { output += '$optionalQuestion.map($lambda)'; } - if (_coreListChecker.isAssignableFromType(targetType)) { + if (_coreListChecker.isExactlyType(targetType)) { output += '$optionalQuestion.toList()'; - } else if (_coreSetChecker.isAssignableFromType(targetType)) { + } else if (_coreSetChecker.isExactlyType(targetType)) { output += '$optionalQuestion.toSet()'; } diff --git a/json_serializable/lib/src/type_helpers/map_helper.dart b/json_serializable/lib/src/type_helpers/map_helper.dart index f8877d5a8..a4ca7366e 100644 --- a/json_serializable/lib/src/type_helpers/map_helper.dart +++ b/json_serializable/lib/src/type_helpers/map_helper.dart @@ -54,7 +54,7 @@ class MapHelper extends TypeHelper { @override String deserialize(DartType targetType, String expression, TypeHelperContextWithConfig context) { - if (!coreMapTypeChecker.isAssignableFromType(targetType)) { + if (!coreMapTypeChecker.isExactlyType(targetType)) { return null; } diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index b997b712a..12d596413 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 2.0.2 +version: 2.0.3-dev author: Dart Team description: Generates utilities to aid in serializing to/from JSON. homepage: https://github.com/dart-lang/json_serializable diff --git a/json_serializable/test/json_serializable_test.dart b/json_serializable/test/json_serializable_test.dart index eebf08c72..74df65964 100644 --- a/json_serializable/test/json_serializable_test.dart +++ b/json_serializable/test/json_serializable_test.dart @@ -83,6 +83,11 @@ const _expectedAnnotatedTests = { 'WithANonCtorGetterChecked', 'WithANonCtorGetter' ], + 'collection_type_input.dart': [ + 'UnsupportedMapField', + 'UnsupportedListField', + 'UnsupportedSetField', + ], 'default_value_input.dart': [ 'DefaultWithSymbol', 'DefaultWithFunction', diff --git a/json_serializable/test/src/_json_serializable_test_input.dart b/json_serializable/test/src/_json_serializable_test_input.dart index a506e2bdd..51a15112d 100644 --- a/json_serializable/test/src/_json_serializable_test_input.dart +++ b/json_serializable/test/src/_json_serializable_test_input.dart @@ -3,11 +3,15 @@ // BSD-style license that can be found in the LICENSE file. //ignore_for_file: avoid_unused_constructor_parameters, prefer_initializing_formals + +import 'dart:collection'; + import 'package:json_annotation/json_annotation.dart'; import 'annotation.dart'; part 'checked_test_input.dart'; +part 'collection_type_input.dart'; part 'configuration_input.dart'; part 'default_value_input.dart'; part 'field_namer_input.dart'; diff --git a/json_serializable/test/src/collection_type_input.dart b/json_serializable/test/src/collection_type_input.dart new file mode 100644 index 000000000..25b25b83a --- /dev/null +++ b/json_serializable/test/src/collection_type_input.dart @@ -0,0 +1,30 @@ +part of '_json_serializable_test_input.dart'; + +@ShouldThrow(r''' +Could not generate `fromJson` code for `mapView`. +None of the provided `TypeHelper` instances support the defined type.''', + 'Make sure all of the types are serializable.') +@JsonSerializable(createToJson: false) +class UnsupportedMapField { + MapView mapView; +} + +@ShouldThrow(r''' +Could not generate `fromJson` code for `listView`. +None of the provided `TypeHelper` instances support the defined type.''', + 'Make sure all of the types are serializable.') +@JsonSerializable(createToJson: false) +class UnsupportedListField { + UnmodifiableListView listView; +} + +@ShouldThrow(r''' +Could not generate `fromJson` code for `customSet`. +None of the provided `TypeHelper` instances support the defined type.''', + 'Make sure all of the types are serializable.') +@JsonSerializable(createToJson: false) +class UnsupportedSetField { + _CustomSet customSet; +} + +abstract class _CustomSet implements Set {} From 7db5fb3e34ab560129a26ba4d7c91407fea8100f Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 12 Feb 2019 16:19:54 -0800 Subject: [PATCH 050/569] Ignore deprecated usage of InheritanceManager Hoping to move to it's replacement, pending fix related to https://github.com/dart-lang/sdk/issues/35927 --- json_serializable/lib/src/field_helpers.dart | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/json_serializable/lib/src/field_helpers.dart b/json_serializable/lib/src/field_helpers.dart index 6cab799a7..ad5d5a3fe 100644 --- a/json_serializable/lib/src/field_helpers.dart +++ b/json_serializable/lib/src/field_helpers.dart @@ -3,9 +3,10 @@ // BSD-style license that can be found in the LICENSE file. import 'package:analyzer/dart/element/element.dart'; + // ignore: implementation_imports import 'package:analyzer/src/dart/resolver/inheritance_manager.dart' - show InheritanceManager; + show InheritanceManager; // ignore: deprecated_member_use import 'package:source_gen/source_gen.dart'; import 'helper_core.dart'; @@ -78,6 +79,7 @@ Iterable createSortedFieldSet(ClassElement element) { element.fields.where((e) => !e.isStatic).map((e) => MapEntry(e.name, e))); final inheritedFields = {}; + // ignore: deprecated_member_use final manager = InheritanceManager(element.library); // ignore: deprecated_member_use From 14d6634025582d8a54e2568ef0711ed2380a8325 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 13 Feb 2019 20:24:16 -0800 Subject: [PATCH 051/569] Update 2.0.3 changelog to be more clear about the new behavior --- json_serializable/CHANGELOG.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 40d9a0b9d..57afb73f8 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,8 +1,9 @@ ## 2.0.3 -* Throw an error when an unsupported `List`, `Set`, or `Map` type is used - without a corresponding converter. - (Previously, invalid code would be generated.) +* Be more strict about the supported `List`, `Set`, or `Map` types. + This may causes errors to be raised in cases where invalid code was generated + before. It also allows implementations of these types to add a `fromJson` + constructor to support custom decoding. ## 2.0.2 From 8f3e07ea5267426a8af90519529d3b970db5058b Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 13 Feb 2019 20:28:25 -0800 Subject: [PATCH 052/569] tiny streamline of IterableHelper --- .../lib/src/type_helpers/iterable_helper.dart | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/json_serializable/lib/src/type_helpers/iterable_helper.dart b/json_serializable/lib/src/type_helpers/iterable_helper.dart index 3c146e316..42d078d4f 100644 --- a/json_serializable/lib/src/type_helpers/iterable_helper.dart +++ b/json_serializable/lib/src/type_helpers/iterable_helper.dart @@ -71,16 +71,18 @@ class IterableHelper extends TypeHelper { final itemSubVal = context.deserialize(iterableGenericType, closureArg); + var output = '$expression as List'; + // If `itemSubVal` is the same and it's not a Set, then we don't need to do // anything fancy if (closureArg == itemSubVal && !_coreSetChecker.isExactlyType(targetType)) { - return '$expression as List'; + return output; } - final optionalQuestion = context.nullable ? '?' : ''; + output = '($output)'; - var output = '($expression as List)'; + final optionalQuestion = context.nullable ? '?' : ''; if (closureArg != itemSubVal) { final lambda = LambdaResult.process(itemSubVal, closureArg); From 43e2a4ff2d01d12b56d637af12c7192811ad813f Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 13 Feb 2019 20:31:42 -0800 Subject: [PATCH 053/569] Improve package description --- json_serializable/pubspec.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 12d596413..a6fb9ea69 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,7 +1,9 @@ name: json_serializable version: 2.0.3-dev author: Dart Team -description: Generates utilities to aid in serializing to/from JSON. +description: >- + Automatically generate code for converting to and from JSON by annotating + Dart classes. homepage: https://github.com/dart-lang/json_serializable environment: sdk: '>=2.0.0 <3.0.0' From 657a6d8948bd87c6fbbb24153b13e74bb9f938e5 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 13 Feb 2019 20:53:49 -0800 Subject: [PATCH 054/569] Add tests for other dart:core types for which we require exact matches --- .../test/json_serializable_test.dart | 5 +- .../src/_json_serializable_test_input.dart | 2 +- .../test/src/collection_type_input.dart | 30 --------- .../test/src/core_subclass_type_input.dart | 63 +++++++++++++++++++ 4 files changed, 68 insertions(+), 32 deletions(-) delete mode 100644 json_serializable/test/src/collection_type_input.dart create mode 100644 json_serializable/test/src/core_subclass_type_input.dart diff --git a/json_serializable/test/json_serializable_test.dart b/json_serializable/test/json_serializable_test.dart index 74df65964..79a8f5080 100644 --- a/json_serializable/test/json_serializable_test.dart +++ b/json_serializable/test/json_serializable_test.dart @@ -83,10 +83,13 @@ const _expectedAnnotatedTests = { 'WithANonCtorGetterChecked', 'WithANonCtorGetter' ], - 'collection_type_input.dart': [ + 'core_subclass_type_input.dart': [ 'UnsupportedMapField', 'UnsupportedListField', 'UnsupportedSetField', + 'UnsupportedDurationField', + 'UnsupportedUriField', + 'UnsupportedDateTimeField', ], 'default_value_input.dart': [ 'DefaultWithSymbol', diff --git a/json_serializable/test/src/_json_serializable_test_input.dart b/json_serializable/test/src/_json_serializable_test_input.dart index 51a15112d..544a717e6 100644 --- a/json_serializable/test/src/_json_serializable_test_input.dart +++ b/json_serializable/test/src/_json_serializable_test_input.dart @@ -11,7 +11,7 @@ import 'package:json_annotation/json_annotation.dart'; import 'annotation.dart'; part 'checked_test_input.dart'; -part 'collection_type_input.dart'; +part 'core_subclass_type_input.dart'; part 'configuration_input.dart'; part 'default_value_input.dart'; part 'field_namer_input.dart'; diff --git a/json_serializable/test/src/collection_type_input.dart b/json_serializable/test/src/collection_type_input.dart deleted file mode 100644 index 25b25b83a..000000000 --- a/json_serializable/test/src/collection_type_input.dart +++ /dev/null @@ -1,30 +0,0 @@ -part of '_json_serializable_test_input.dart'; - -@ShouldThrow(r''' -Could not generate `fromJson` code for `mapView`. -None of the provided `TypeHelper` instances support the defined type.''', - 'Make sure all of the types are serializable.') -@JsonSerializable(createToJson: false) -class UnsupportedMapField { - MapView mapView; -} - -@ShouldThrow(r''' -Could not generate `fromJson` code for `listView`. -None of the provided `TypeHelper` instances support the defined type.''', - 'Make sure all of the types are serializable.') -@JsonSerializable(createToJson: false) -class UnsupportedListField { - UnmodifiableListView listView; -} - -@ShouldThrow(r''' -Could not generate `fromJson` code for `customSet`. -None of the provided `TypeHelper` instances support the defined type.''', - 'Make sure all of the types are serializable.') -@JsonSerializable(createToJson: false) -class UnsupportedSetField { - _CustomSet customSet; -} - -abstract class _CustomSet implements Set {} diff --git a/json_serializable/test/src/core_subclass_type_input.dart b/json_serializable/test/src/core_subclass_type_input.dart new file mode 100644 index 000000000..1be03515d --- /dev/null +++ b/json_serializable/test/src/core_subclass_type_input.dart @@ -0,0 +1,63 @@ +part of '_json_serializable_test_input.dart'; + +@ShouldThrow(r''' +Could not generate `fromJson` code for `mapView`. +None of the provided `TypeHelper` instances support the defined type.''', + 'Make sure all of the types are serializable.') +@JsonSerializable(createToJson: false) +class UnsupportedMapField { + MapView mapView; +} + +@ShouldThrow(r''' +Could not generate `fromJson` code for `listView`. +None of the provided `TypeHelper` instances support the defined type.''', + 'Make sure all of the types are serializable.') +@JsonSerializable(createToJson: false) +class UnsupportedListField { + UnmodifiableListView listView; +} + +@ShouldThrow(r''' +Could not generate `fromJson` code for `customSet`. +None of the provided `TypeHelper` instances support the defined type.''', + 'Make sure all of the types are serializable.') +@JsonSerializable(createToJson: false) +class UnsupportedSetField { + _CustomSet customSet; +} + +abstract class _CustomSet implements Set {} + +@ShouldThrow(r''' +Could not generate `fromJson` code for `customDuration`. +None of the provided `TypeHelper` instances support the defined type.''', + 'Make sure all of the types are serializable.') +@JsonSerializable(createToJson: false) +class UnsupportedDurationField { + _CustomDuration customDuration; +} + +abstract class _CustomDuration implements Duration {} + +@ShouldThrow(r''' +Could not generate `fromJson` code for `customUri`. +None of the provided `TypeHelper` instances support the defined type.''', + 'Make sure all of the types are serializable.') +@JsonSerializable(createToJson: false) +class UnsupportedUriField { + _CustomUri customUri; +} + +abstract class _CustomUri implements Uri {} + +@ShouldThrow(r''' +Could not generate `fromJson` code for `customDateTime`. +None of the provided `TypeHelper` instances support the defined type.''', + 'Make sure all of the types are serializable.') +@JsonSerializable(createToJson: false) +class UnsupportedDateTimeField { + _CustomDateTime customDateTime; +} + +abstract class _CustomDateTime implements DateTime {} From bd60790290631082627df1aa9093568389af04f5 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 13 Feb 2019 22:49:13 -0800 Subject: [PATCH 055/569] fix spelling --- json_serializable/README.md | 2 +- json_serializable/lib/src/decode_helper.dart | 10 +++++----- json_serializable/lib/src/utils.dart | 4 ++-- json_serializable/test/src/checked_test_input.dart | 4 ++-- json_serializable/test/yaml/build_config.dart | 4 ++-- json_serializable/test/yaml/build_config.g.dart | 6 +++--- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/json_serializable/README.md b/json_serializable/README.md index 8839e6214..cf86aea9c 100644 --- a/json_serializable/README.md +++ b/json_serializable/README.md @@ -10,7 +10,7 @@ in [package:json_annotation]. configure the generated code. You can also customize individual fields by annotating them with `JsonKey` and providing custom arguments. -- To generate a Dart field with the contents of a file containting JSON, use the +- To generate a Dart field with the contents of a file containing JSON, use the `JsonLiteral` annotation. To configure your project for the latest released version of, diff --git a/json_serializable/lib/src/decode_helper.dart b/json_serializable/lib/src/decode_helper.dart index fb8ba3772..3e4e06f55 100644 --- a/json_serializable/lib/src/decode_helper.dart +++ b/json_serializable/lib/src/decode_helper.dart @@ -151,9 +151,9 @@ abstract class DecodeHelper implements HelperCore { .where((fe) => jsonKeyFor(fe).disallowNullValue) .toList(); if (disallowNullKeys.isNotEmpty) { - final dissallowNullKeyLiteral = constantList(disallowNullKeys); + final disallowNullKeyLiteral = constantList(disallowNullKeys); - args.add('disallowNullValues: $dissallowNullKeyLiteral'); + args.add('disallowNullValues: $disallowNullKeyLiteral'); } if (args.isNotEmpty) { @@ -219,12 +219,12 @@ abstract class DecodeHelper implements HelperCore { /// unavailable constructor parameter. If the value is not `null`, it is /// included in the [UnsupportedError] message. /// -/// [writeableFields] are also populated, but only if they have not already +/// [writableFields] are also populated, but only if they have not already /// been defined by a constructor parameter with the same name. _ConstructorData _writeConstructorInvocation( ClassElement classElement, Iterable availableConstructorParameters, - Iterable writeableFields, + Iterable writableFields, Map unavailableReasons, String deserializeForField(String paramOrFieldName, {ParameterElement ctorParam})) { @@ -273,7 +273,7 @@ _ConstructorData _writeConstructorInvocation( // fields that aren't already set by the constructor and that aren't final final remainingFieldsForInvocationBody = - writeableFields.toSet().difference(usedCtorParamsAndFields); + writableFields.toSet().difference(usedCtorParamsAndFields); final buffer = StringBuffer(); buffer.write('$className${genericClassArguments(classElement, false)}('); diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index 6a6629aa0..63c862102 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -27,12 +27,12 @@ String kebabCase(String input) => _fixCase(input, '-'); String snakeCase(String input) => _fixCase(input, '_'); -String _fixCase(String input, String seperator) => +String _fixCase(String input, String separator) => input.replaceAllMapped(_upperCase, (match) { var lower = match.group(0).toLowerCase(); if (match.start > 0) { - lower = '$seperator$lower'; + lower = '$separator$lower'; } return lower; diff --git a/json_serializable/test/src/checked_test_input.dart b/json_serializable/test/src/checked_test_input.dart index c83935f88..297b27ad3 100644 --- a/json_serializable/test/src/checked_test_input.dart +++ b/json_serializable/test/src/checked_test_input.dart @@ -18,7 +18,7 @@ WithANonCtorGetterChecked _$WithANonCtorGetterCheckedFromJson( class WithANonCtorGetterChecked { @JsonKey(required: true, disallowNullValue: true) final List items; - int get legth => items.length; + int get length => items.length; WithANonCtorGetterChecked(this.items); } @@ -37,7 +37,7 @@ WithANonCtorGetter _$WithANonCtorGetterFromJson(Map json) { class WithANonCtorGetter { @JsonKey(required: true, disallowNullValue: true) final List items; - int get legth => items.length; + int get length => items.length; WithANonCtorGetter(this.items); } diff --git a/json_serializable/test/yaml/build_config.dart b/json_serializable/test/yaml/build_config.dart index ce48d7a78..7d5f707fd 100644 --- a/json_serializable/test/yaml/build_config.dart +++ b/json_serializable/test/yaml/build_config.dart @@ -57,7 +57,7 @@ class Builder { final List requiredInputs; @JsonKey(name: 'build_extensions') - final Map> buildExtentions; + final Map> buildExtensions; Builder( {@required this.import, @@ -69,7 +69,7 @@ class Builder { this.builderFactories, this.appliesBuilders, this.requiredInputs, - this.buildExtentions, + this.buildExtensions, this.configLocation}) { if (builderFactories.isEmpty) { throw ArgumentError.value(builderFactories, 'builderFactories', diff --git a/json_serializable/test/yaml/build_config.g.dart b/json_serializable/test/yaml/build_config.g.dart index 0b7e74760..1396469aa 100644 --- a/json_serializable/test/yaml/build_config.g.dart +++ b/json_serializable/test/yaml/build_config.g.dart @@ -91,7 +91,7 @@ Builder _$BuilderFromJson(Map json) { (v) => (v as List)?.map((e) => e as String)?.toList()), requiredInputs: $checkedConvert(json, 'required_inputs', (v) => (v as List)?.map((e) => e as String)?.toList()), - buildExtentions: $checkedConvert( + buildExtensions: $checkedConvert( json, 'build_extensions', (v) => (v as Map)?.map((k, e) => MapEntry( @@ -106,7 +106,7 @@ Builder _$BuilderFromJson(Map json) { 'builderFactories': 'builder_factories', 'appliesBuilders': 'applies_builders', 'requiredInputs': 'required_inputs', - 'buildExtentions': 'build_extensions' + 'buildExtensions': 'build_extensions' }); } @@ -129,7 +129,7 @@ Map _$BuilderToJson(Builder instance) { val['builder_factories'] = instance.builderFactories; writeNotNull('applies_builders', instance.appliesBuilders); writeNotNull('required_inputs', instance.requiredInputs); - writeNotNull('build_extensions', instance.buildExtentions); + writeNotNull('build_extensions', instance.buildExtensions); return val; } From 1dcd8f353cedff7431bcc84c15b70fe696636e48 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 13 Feb 2019 22:42:38 -0800 Subject: [PATCH 056/569] Generate a conversion expression for fromJson param type Previously we just did a cast to the raw param type, which was often wrong See https://stackoverflow.com/q/54654171/39827 --- json_serializable/CHANGELOG.md | 3 ++ .../lib/src/type_helpers/json_helper.dart | 47 +++++++++++++++---- .../test/integration/json_test_common.dart | 26 ++++++++++ .../test/integration/json_test_example.dart | 2 + .../test/integration/json_test_example.g.dart | 7 +++ .../json_test_example.non_nullable.dart | 2 + .../json_test_example.non_nullable.g.dart | 4 ++ ...son_test_example.non_nullable.wrapped.dart | 2 + ...n_test_example.non_nullable.wrapped.g.dart | 6 +++ .../json_test_example.wrapped.dart | 2 + .../json_test_example.wrapped.g.dart | 9 ++++ .../test/json_serializable_test.dart | 3 +- .../src/_json_serializable_test_input.dart | 41 ++++++++++++++++ 13 files changed, 145 insertions(+), 9 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 57afb73f8..b71154450 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,5 +1,8 @@ ## 2.0.3 +* When invoking a `fromJson` constructor on a field type, generate a conversion + expression derived from the the constructor parameter type. + * Be more strict about the supported `List`, `Set`, or `Map` types. This may causes errors to be raised in cases where invalid code was generated before. It also allows implementations of these types to add a `fromJson` diff --git a/json_serializable/lib/src/type_helpers/json_helper.dart b/json_serializable/lib/src/type_helpers/json_helper.dart index 284478812..583997c7e 100644 --- a/json_serializable/lib/src/type_helpers/json_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_helper.dart @@ -44,16 +44,24 @@ class JsonHelper extends TypeHelper { final fromJsonCtor = classElement.constructors .singleWhere((ce) => ce.name == 'fromJson', orElse: () => null); - String asCast; + var output = expression; if (fromJsonCtor != null) { - // TODO: should verify that this type is a valid JSON type - final asCastType = fromJsonCtor.parameters.first.type; - asCast = asStatement(asCastType); + var asCastType = + fromJsonCtor.parameters.singleWhere((pe) => pe.isPositional).type; + + if (asCastType is InterfaceType) { + var instantiated = _instantiate(asCastType as InterfaceType, type); + if (instantiated != null) { + asCastType = instantiated; + } + } + + output = context.deserialize(asCastType, output).toString(); } else if (_annotation(context.config, type)?.createFactory == true) { if (context.config.anyMap) { - asCast = ' as Map'; + output += ' as Map'; } else { - asCast = ' as Map'; + output += ' as Map'; } } else { return null; @@ -61,9 +69,9 @@ class JsonHelper extends TypeHelper { // TODO: the type could be imported from a library with a prefix! // github.com/dart-lang/json_serializable/issues/19 - final result = '${targetType.name}.fromJson($expression$asCast)'; + output = '${targetType.name}.fromJson($output)'; - return commonNullPrefix(context.nullable, expression, result).toString(); + return commonNullPrefix(context.nullable, expression, output).toString(); } } @@ -85,6 +93,29 @@ bool _canSerialize(JsonSerializable config, DartType type) { return false; } +/// Returns an instantiation of [ctorParamType] by providing argument types +/// derived by matching corresponding type parameters from [classType]. +InterfaceType _instantiate( + InterfaceType ctorParamType, InterfaceType classType) { + var argTypes = ctorParamType.typeArguments.map((arg) { + final typeParamIndex = + classType.typeParameters.indexWhere((e) => e.type == arg); + if (typeParamIndex >= 0) { + return classType.typeArguments[typeParamIndex]; + } else { + // TODO: perhaps throw UnsupportedTypeError? + return null; + } + }).toList(); + + if (argTypes.any((e) => e == null)) { + // TODO: perhaps throw UnsupportedTypeError? + return null; + } + + return ctorParamType.instantiate(argTypes); +} + JsonSerializable _annotation(JsonSerializable config, InterfaceType source) { final annotations = const TypeChecker.fromRuntime(JsonSerializable) .annotationsOfExact(source.element, throwOnUnresolved: false) diff --git a/json_serializable/test/integration/json_test_common.dart b/json_serializable/test/integration/json_test_common.dart index 8de031caf..86c4b4c16 100644 --- a/json_serializable/test/integration/json_test_common.dart +++ b/json_serializable/test/integration/json_test_common.dart @@ -2,6 +2,8 @@ // 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 'dart:collection'; + import 'package:collection/collection.dart'; import 'package:json_annotation/json_annotation.dart'; @@ -57,3 +59,27 @@ abstract class ItemCore { ItemCore(this.price); } + +class MyList extends ListBase { + final List _data; + + MyList(Iterable source) : _data = source.toList() ?? []; + + factory MyList.fromJson(List items) => MyList(items); + + @override + int get length => _data.length; + + @override + set length(int value) { + _data.length = value; + } + + @override + T operator [](int index) => _data[index]; + + @override + void operator []=(int index, T value) { + _data[index] = value; + } +} diff --git a/json_serializable/test/integration/json_test_example.dart b/json_serializable/test/integration/json_test_example.dart index e524ebe58..49c1f516d 100644 --- a/json_serializable/test/integration/json_test_example.dart +++ b/json_serializable/test/integration/json_test_example.dart @@ -19,6 +19,8 @@ class Person { Order order; + MyList customOrders; + Map houseMap; Map categoryCounts; diff --git a/json_serializable/test/integration/json_test_example.g.dart b/json_serializable/test/integration/json_test_example.g.dart index 88617e7b5..a0296ba22 100644 --- a/json_serializable/test/integration/json_test_example.g.dart +++ b/json_serializable/test/integration/json_test_example.g.dart @@ -16,6 +16,12 @@ Person _$PersonFromJson(Map json) { ..order = json['order'] == null ? null : Order.fromJson(json['order'] as Map) + ..customOrders = json['customOrders'] == null + ? null + : MyList.fromJson((json['customOrders'] as List) + ?.map((e) => + e == null ? null : Order.fromJson(e as Map)) + ?.toList()) ..houseMap = (json['houseMap'] as Map) ?.map((k, e) => MapEntry(k, _$enumDecodeNullable(_$CategoryEnumMap, e))) ..categoryCounts = (json['categoryCounts'] as Map)?.map( @@ -30,6 +36,7 @@ Map _$PersonToJson(Person instance) => { 'dateOfBirth': instance.dateOfBirth?.toIso8601String(), r'$house': _$CategoryEnumMap[instance.house], 'order': instance.order, + 'customOrders': instance.customOrders, 'houseMap': instance.houseMap?.map((k, e) => MapEntry(k, _$CategoryEnumMap[e])), 'categoryCounts': instance.categoryCounts diff --git a/json_serializable/test/integration/json_test_example.non_nullable.dart b/json_serializable/test/integration/json_test_example.non_nullable.dart index 62257caf6..0d686bdc0 100644 --- a/json_serializable/test/integration/json_test_example.non_nullable.dart +++ b/json_serializable/test/integration/json_test_example.non_nullable.dart @@ -27,6 +27,8 @@ class Person { Order order; + MyList customOrders; + Map houseMap; Map categoryCounts; diff --git a/json_serializable/test/integration/json_test_example.non_nullable.g.dart b/json_serializable/test/integration/json_test_example.non_nullable.g.dart index b6c663709..b958cb6ff 100644 --- a/json_serializable/test/integration/json_test_example.non_nullable.g.dart +++ b/json_serializable/test/integration/json_test_example.non_nullable.g.dart @@ -12,6 +12,9 @@ Person _$PersonFromJson(Map json) { middleName: json['middleName'] as String, dateOfBirth: DateTime.parse(json['dateOfBirth'] as String)) ..order = Order.fromJson(json['order'] as Map) + ..customOrders = MyList.fromJson((json['customOrders'] as List) + .map((e) => Order.fromJson(e as Map)) + .toList()) ..houseMap = (json['houseMap'] as Map) .map((k, e) => MapEntry(k, _$enumDecode(_$CategoryEnumMap, e))) ..categoryCounts = (json['categoryCounts'] as Map) @@ -25,6 +28,7 @@ Map _$PersonToJson(Person instance) => { 'dateOfBirth': instance.dateOfBirth.toIso8601String(), r'$house': _$CategoryEnumMap[instance.house], 'order': instance.order, + 'customOrders': instance.customOrders, 'houseMap': instance.houseMap.map((k, e) => MapEntry(k, _$CategoryEnumMap[e])), 'categoryCounts': instance.categoryCounts diff --git a/json_serializable/test/integration/json_test_example.non_nullable.wrapped.dart b/json_serializable/test/integration/json_test_example.non_nullable.wrapped.dart index 7893dc642..e66b226f6 100644 --- a/json_serializable/test/integration/json_test_example.non_nullable.wrapped.dart +++ b/json_serializable/test/integration/json_test_example.non_nullable.wrapped.dart @@ -34,6 +34,8 @@ class Person { Order order; + MyList customOrders; + Map houseMap; Map categoryCounts; diff --git a/json_serializable/test/integration/json_test_example.non_nullable.wrapped.g.dart b/json_serializable/test/integration/json_test_example.non_nullable.wrapped.g.dart index 809fcb930..4ac171a1c 100644 --- a/json_serializable/test/integration/json_test_example.non_nullable.wrapped.g.dart +++ b/json_serializable/test/integration/json_test_example.non_nullable.wrapped.g.dart @@ -12,6 +12,9 @@ Person _$PersonFromJson(Map json) { middleName: json['middleName'] as String, dateOfBirth: DateTime.parse(json['dateOfBirth'] as String)) ..order = Order.fromJson(json['order'] as Map) + ..customOrders = MyList.fromJson((json['customOrders'] as List) + .map((e) => Order.fromJson(e as Map)) + .toList()) ..houseMap = (json['houseMap'] as Map) .map((k, e) => MapEntry(k, _$enumDecode(_$CategoryEnumMap, e))) ..categoryCounts = (json['categoryCounts'] as Map) @@ -33,6 +36,7 @@ class _$PersonJsonMapWrapper extends $JsonMapWrapper { 'dateOfBirth', r'$house', 'order', + 'customOrders', 'houseMap', 'categoryCounts' ]; @@ -53,6 +57,8 @@ class _$PersonJsonMapWrapper extends $JsonMapWrapper { return _$CategoryEnumMap[_v.house]; case 'order': return _v.order; + case 'customOrders': + return _v.customOrders; case 'houseMap': return $wrapMap( _v.houseMap, (e) => _$CategoryEnumMap[e]); diff --git a/json_serializable/test/integration/json_test_example.wrapped.dart b/json_serializable/test/integration/json_test_example.wrapped.dart index 4443c2982..3b926857e 100644 --- a/json_serializable/test/integration/json_test_example.wrapped.dart +++ b/json_serializable/test/integration/json_test_example.wrapped.dart @@ -27,6 +27,8 @@ class Person { Order order; + MyList customOrders; + Map houseMap; Map categoryCounts; diff --git a/json_serializable/test/integration/json_test_example.wrapped.g.dart b/json_serializable/test/integration/json_test_example.wrapped.g.dart index 762f1ea77..c7533a657 100644 --- a/json_serializable/test/integration/json_test_example.wrapped.g.dart +++ b/json_serializable/test/integration/json_test_example.wrapped.g.dart @@ -16,6 +16,12 @@ Person _$PersonFromJson(Map json) { ..order = json['order'] == null ? null : Order.fromJson(json['order'] as Map) + ..customOrders = json['customOrders'] == null + ? null + : MyList.fromJson((json['customOrders'] as List) + ?.map((e) => + e == null ? null : Order.fromJson(e as Map)) + ?.toList()) ..houseMap = (json['houseMap'] as Map) ?.map((k, e) => MapEntry(k, _$enumDecodeNullable(_$CategoryEnumMap, e))) ..categoryCounts = (json['categoryCounts'] as Map)?.map( @@ -38,6 +44,7 @@ class _$PersonJsonMapWrapper extends $JsonMapWrapper { 'dateOfBirth', r'$house', 'order', + 'customOrders', 'houseMap', 'categoryCounts' ]; @@ -58,6 +65,8 @@ class _$PersonJsonMapWrapper extends $JsonMapWrapper { return _$CategoryEnumMap[_v.house]; case 'order': return _v.order; + case 'customOrders': + return _v.customOrders; case 'houseMap': return $wrapMapHandleNull( _v.houseMap, (e) => _$CategoryEnumMap[e]); diff --git a/json_serializable/test/json_serializable_test.dart b/json_serializable/test/json_serializable_test.dart index 79a8f5080..20da0afff 100644 --- a/json_serializable/test/json_serializable_test.dart +++ b/json_serializable/test/json_serializable_test.dart @@ -77,7 +77,8 @@ const _expectedAnnotatedTests = { 'PrivateFieldCtorClass', 'IncludeIfNullDisallowNullClass', 'JsonValueWithBool', - 'JsonValueValid' + 'JsonValueValid', + 'FieldWithFromJsonCtorAndTypeParams', ], 'checked_test_input.dart': [ 'WithANonCtorGetterChecked', diff --git a/json_serializable/test/src/_json_serializable_test_input.dart b/json_serializable/test/src/_json_serializable_test_input.dart index 544a717e6..c1f364a6d 100644 --- a/json_serializable/test/src/_json_serializable_test_input.dart +++ b/json_serializable/test/src/_json_serializable_test_input.dart @@ -381,3 +381,44 @@ enum GoodEnum { @JsonValue(null) nullValue } + +@ShouldGenerate(r''' +FieldWithFromJsonCtorAndTypeParams _$FieldWithFromJsonCtorAndTypeParamsFromJson( + Map json) { + return FieldWithFromJsonCtorAndTypeParams() + ..customOrders = json['customOrders'] == null + ? null + : MyList.fromJson((json['customOrders'] as List) + ?.map((e) => + e == null ? null : Order.fromJson(e as Map)) + ?.toList()); +} +''') +@JsonSerializable(createToJson: false) +class FieldWithFromJsonCtorAndTypeParams { + MyList customOrders; +} + +class MyList extends ListBase { + final List _data; + + MyList(Iterable source) : _data = source.toList() ?? []; + + factory MyList.fromJson(List items) => MyList(items); + + @override + int get length => _data.length; + + @override + set length(int value) { + _data.length = value; + } + + @override + T operator [](int index) => _data[index]; + + @override + void operator []=(int index, T value) { + _data[index] = value; + } +} From 741df254034156684b55f5249a92052ec1703a55 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 25 Feb 2019 08:50:24 -0800 Subject: [PATCH 057/569] Remove an unneeded field in the test annotation type (#392) Thinking towards https://github.com/dart-lang/json_serializable/issues/364 --- json_serializable/test/json_serializable_test.dart | 7 ++----- json_serializable/test/src/annotation.dart | 14 ++++++++------ json_serializable/test/src/checked_test_input.dart | 10 ++++++++-- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/json_serializable/test/json_serializable_test.dart b/json_serializable/test/json_serializable_test.dart index 20da0afff..70911fea9 100644 --- a/json_serializable/test/json_serializable_test.dart +++ b/json_serializable/test/json_serializable_test.dart @@ -326,11 +326,8 @@ void _testShouldGenerate(AnnotatedElement annotatedElement) { .map((obj) => obj.toStringValue()) .toList(); - final checked = annotatedElement.annotation.read('checked').boolValue; - test(element.name, () { - final output = - _runForElementNamed(JsonSerializable(checked: checked), element.name); + final output = _runForElementNamed(const JsonSerializable(), element.name); expect(output, matcher); expect(_buildLogItems, expectedLogItems); @@ -343,7 +340,7 @@ void _testShouldGenerate(AnnotatedElement annotatedElement) { if (wrappedMatcher != null) { test('${element.name} - (wrapped)', () { final output = _runForElementNamed( - JsonSerializable(checked: checked, useWrappers: true), element.name); + const JsonSerializable(useWrappers: true), element.name); expect(output, wrappedMatcher); expect(_buildLogItems, expectedLogItems); diff --git a/json_serializable/test/src/annotation.dart b/json_serializable/test/src/annotation.dart index 327055f3a..2c57d03b2 100644 --- a/json_serializable/test/src/annotation.dart +++ b/json_serializable/test/src/annotation.dart @@ -5,6 +5,7 @@ class ShouldThrow { final String errorMessage; final String todo; + const ShouldThrow(this.errorMessage, [this.todo]); } @@ -13,10 +14,11 @@ class ShouldGenerate { final String expectedWrappedOutput; final bool contains; final List expectedLogItems; - final bool checked; - const ShouldGenerate(this.expectedOutput, - {this.expectedWrappedOutput, - this.contains = false, - this.expectedLogItems = const [], - this.checked = false}); + + const ShouldGenerate( + this.expectedOutput, { + this.expectedWrappedOutput, + this.contains = false, + this.expectedLogItems = const [], + }); } diff --git a/json_serializable/test/src/checked_test_input.dart b/json_serializable/test/src/checked_test_input.dart index 297b27ad3..f8a7d3c6e 100644 --- a/json_serializable/test/src/checked_test_input.dart +++ b/json_serializable/test/src/checked_test_input.dart @@ -13,11 +13,16 @@ WithANonCtorGetterChecked _$WithANonCtorGetterCheckedFromJson( return val; }); } -''', checked: true) -@JsonSerializable(disallowUnrecognizedKeys: true, createToJson: false) +''') +@JsonSerializable( + disallowUnrecognizedKeys: true, + createToJson: false, + checked: true, +) class WithANonCtorGetterChecked { @JsonKey(required: true, disallowNullValue: true) final List items; + int get length => items.length; WithANonCtorGetterChecked(this.items); @@ -37,6 +42,7 @@ WithANonCtorGetter _$WithANonCtorGetterFromJson(Map json) { class WithANonCtorGetter { @JsonKey(required: true, disallowNullValue: true) final List items; + int get length => items.length; WithANonCtorGetter(this.items); From f5d440c1212de88329f19b9de18cc16084f317c1 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 25 Feb 2019 16:21:03 -0800 Subject: [PATCH 058/569] Add latest pedantic lints (#391) --- analysis_options.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/analysis_options.yaml b/analysis_options.yaml index 9f85aa50a..8db7b726b 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -19,6 +19,7 @@ linter: - avoid_renaming_method_parameters - avoid_return_types_on_setters - avoid_returning_null + - avoid_shadowing_type_parameters - avoid_types_as_parameter_names - avoid_unused_constructor_parameters - await_only_futures @@ -43,6 +44,7 @@ linter: - no_adjacent_strings_in_list - no_duplicate_case_values - non_constant_identifier_names + - null_closures - omit_local_variable_types - only_throw_errors - overridden_fields From fd8cfb87af548751bdff320e9314a9fa924b333c Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 26 Feb 2019 07:40:07 -0800 Subject: [PATCH 059/569] tweak analysis_options with latest Dart 2.2.0-dev release (#394) --- analysis_options.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index 8db7b726b..6e7d864e5 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -52,7 +52,8 @@ linter: - package_names - package_prefixed_library_names - prefer_adjacent_string_concatenation - - prefer_collection_literals + # TODO: re-enable when we want to support Dart 2.2+ + #- prefer_collection_literals - prefer_conditional_assignment - prefer_const_constructors - prefer_contains @@ -67,7 +68,6 @@ linter: - prefer_typing_uninitialized_variables - recursive_getters - slash_for_doc_comments - - super_goes_last - test_types_in_equals - throw_in_finally - type_init_formals From 079a32b27dff80ab39099e552fa6da7c5f6656a9 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 4 Mar 2019 16:45:58 -0800 Subject: [PATCH 060/569] Migrate to pkg:source_gen_test (#401) --- json_serializable/pubspec.yaml | 3 +- json_serializable/test/analysis_utils.dart | 29 -- .../test/json_serializable_test.dart | 464 +++++------------- .../src/_json_serializable_test_input.dart | 137 ++++-- json_serializable/test/src/annotation.dart | 24 - .../test/src/core_subclass_type_input.dart | 42 +- .../test/src/default_value_input.dart | 49 +- .../test/src/field_namer_input.dart | 21 +- .../test/src/generic_test_input.dart | 9 +- .../test/src/inheritance_test_input.dart | 34 +- .../test/src/json_converter_test_input.dart | 34 +- .../test/src/setter_test_input.dart | 24 +- .../test/src/to_from_json_test_input.dart | 83 +++- 13 files changed, 446 insertions(+), 507 deletions(-) delete mode 100644 json_serializable/test/analysis_utils.dart delete mode 100644 json_serializable/test/src/annotation.dart diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index a6fb9ea69..03a20df86 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -22,11 +22,10 @@ dependencies: dev_dependencies: build_runner: ^1.0.0 - build_test: ^0.10.0 build_verify: ^1.1.0 build_web_compilers: ^1.0.0 collection: ^1.14.0 - dart_style: ^1.0.0 logging: ^0.11.3+1 + source_gen_test: ^0.1.0 test: ^1.3.3 yaml: ^2.1.13 diff --git a/json_serializable/test/analysis_utils.dart b/json_serializable/test/analysis_utils.dart deleted file mode 100644 index ebfee1c38..000000000 --- a/json_serializable/test/analysis_utils.dart +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) 2017, 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 'dart:async'; -import 'dart:io'; - -import 'package:build/build.dart'; -import 'package:build_test/build_test.dart'; -import 'package:path/path.dart' as p; -import 'package:source_gen/source_gen.dart'; - -Future resolveCompilationUnit(String sourceDirectory) async { - final files = - Directory(sourceDirectory).listSync().whereType().toList(); - - // Sort files to ensure the "first" one is first - files.sort((a, b) => p.basename(a.path).compareTo(p.basename(b.path))); - - final fileMap = Map.fromEntries(files.map( - (f) => MapEntry('a|lib/${p.basename(f.path)}', f.readAsStringSync()))); - - final library = await resolveSources(fileMap, (item) async { - final assetId = AssetId.parse(fileMap.keys.first); - return await item.libraryFor(assetId); - }); - - return LibraryReader(library); -} diff --git a/json_serializable/test/json_serializable_test.dart b/json_serializable/test/json_serializable_test.dart index 70911fea9..db7cbd7a5 100644 --- a/json_serializable/test/json_serializable_test.dart +++ b/json_serializable/test/json_serializable_test.dart @@ -6,191 +6,110 @@ import 'dart:async'; import 'package:analyzer/dart/element/type.dart'; -import 'package:analyzer/src/dart/element/element.dart'; -import 'package:build/build.dart'; -import 'package:dart_style/dart_style.dart' as dart_style; import 'package:json_annotation/json_annotation.dart'; import 'package:json_serializable/json_serializable.dart'; import 'package:json_serializable/src/constants.dart'; import 'package:json_serializable/src/type_helper.dart'; import 'package:source_gen/source_gen.dart'; +import 'package:source_gen_test/source_gen_test.dart'; import 'package:test/test.dart'; -import 'analysis_utils.dart'; import 'shared_config.dart'; import 'test_file_utils.dart'; -Matcher _matcherFromShouldGenerateAnnotation(ConstantReader reader, - {bool wrapped = false}) { - String expectedOutput; - if (wrapped) { - final expectedWrappedOutput = reader.read('expectedWrappedOutput'); - if (expectedWrappedOutput.isNull) { - return null; - } - expectedOutput = expectedWrappedOutput.stringValue; - } else { - expectedOutput = reader.read('expectedOutput').stringValue; - } - - final isContains = reader.read('contains').boolValue; - - if (isContains) { - return contains(expectedOutput); - } - return equals(expectedOutput); -} - -Matcher _throwsInvalidGenerationSourceError(messageMatcher, todoMatcher) => - throwsA(const TypeMatcher() - .having((e) { - printOnFailure("r'''\n${e.message}'''"); - return e.message; - }, 'message', messageMatcher) - .having((e) => e.todo, 'todo', todoMatcher) - .having((e) => e.element, 'element', isNotNull)); - Matcher _throwsUnsupportedError(matcher) => throwsA(const TypeMatcher() .having((e) => e.message, 'message', matcher)); -final _formatter = dart_style.DartFormatter(); - -LibraryReader _library; - -final _buildLogItems = []; - -const _expectedAnnotatedTests = { - '_json_serializable_test_input.dart': [ - 'theAnswer', - 'annotatedMethod', - 'Person', - 'Order', - 'FinalFields', - 'FinalFieldsNotSetInCtor', - 'SetSupport', - 'IncludeIfNullOverride', - 'KeyDupesField', - 'DupeKeys', - 'IgnoredFieldClass', - 'IgnoredFieldCtorClass', - 'PrivateFieldCtorClass', - 'IncludeIfNullDisallowNullClass', - 'JsonValueWithBool', - 'JsonValueValid', - 'FieldWithFromJsonCtorAndTypeParams', - ], - 'checked_test_input.dart': [ - 'WithANonCtorGetterChecked', - 'WithANonCtorGetter' - ], - 'core_subclass_type_input.dart': [ - 'UnsupportedMapField', - 'UnsupportedListField', - 'UnsupportedSetField', - 'UnsupportedDurationField', - 'UnsupportedUriField', - 'UnsupportedDateTimeField', - ], - 'default_value_input.dart': [ - 'DefaultWithSymbol', - 'DefaultWithFunction', - 'DefaultWithType', - 'DefaultWithConstObject', - 'DefaultWithNestedEnum', - 'DefaultWithNonNullableField', - 'DefaultWithNonNullableClass', - 'DefaultWithToJsonClass', - 'DefaultWithDisallowNullRequiredClass', - ], - 'field_namer_input.dart': [ - 'FieldNamerNone', - 'FieldNamerKebab', - 'FieldNamerSnake' - ], - 'generic_test_input.dart': ['GenericClass'], - 'inheritance_test_input.dart': [ - 'SubType', - 'SubTypeWithAnnotatedFieldOverrideExtends', - 'SubTypeWithAnnotatedFieldOverrideExtendsWithOverrides', - 'SubTypeWithAnnotatedFieldOverrideImplements' - ], - 'json_converter_test_input.dart': [ - 'JsonConverterNamedCtor', - 'JsonConvertOnField', - 'JsonConverterWithBadTypeArg', - 'JsonConverterDuplicateAnnotations', - 'JsonConverterCtorParams', - ], - 'setter_test_input.dart': [ - 'JustSetter', - 'JustSetterNoToJson', - 'JustSetterNoFromJson' - ], - 'to_from_json_test_input.dart': [ - 'BadFromFuncReturnType', - 'InvalidFromFunc2Args', - 'ValidToFromFuncClassStatic', - 'BadToFuncReturnType', - 'InvalidToFunc2Args', - 'ObjectConvertMethods', - 'DynamicConvertMethods', - 'TypedConvertMethods', - 'FromDynamicCollection', - 'BadNoArgs', - 'BadTwoRequiredPositional', - 'BadOneNamed', - 'OkayOneNormalOptionalPositional', - 'OkayOneNormalOptionalNamed', - 'OkayOnlyOptionalPositional' - ], -}; +const _expectedAnnotatedTests = [ + 'theAnswer', + 'annotatedMethod', + 'FinalFields', + 'FinalFieldsNotSetInCtor', + 'SetSupport', + 'IncludeIfNullOverride', + 'KeyDupesField', + 'DupeKeys', + 'IgnoredFieldClass', + 'IgnoredFieldCtorClass', + 'PrivateFieldCtorClass', + 'IncludeIfNullDisallowNullClass', + 'JsonValueWithBool', + 'JsonValueValid', + 'FieldWithFromJsonCtorAndTypeParams', + 'WithANonCtorGetterChecked', + 'WithANonCtorGetter', + 'UnsupportedMapField', + 'UnsupportedListField', + 'UnsupportedSetField', + 'UnsupportedDurationField', + 'UnsupportedUriField', + 'UnsupportedDateTimeField', + 'DefaultWithSymbol', + 'DefaultWithFunction', + 'DefaultWithType', + 'DefaultWithConstObject', + 'DefaultWithNestedEnum', + 'DefaultWithNonNullableField', + 'DefaultWithNonNullableClass', + 'DefaultWithToJsonClass', + 'DefaultWithDisallowNullRequiredClass', + 'FieldNamerNone', + 'FieldNamerKebab', + 'FieldNamerSnake', + 'GenericClass', + 'GenericClass', + 'SubType', + 'SubType', + 'SubTypeWithAnnotatedFieldOverrideExtends', + 'SubTypeWithAnnotatedFieldOverrideExtendsWithOverrides', + 'SubTypeWithAnnotatedFieldOverrideImplements', + 'JsonConverterNamedCtor', + 'JsonConvertOnField', + 'JsonConverterWithBadTypeArg', + 'JsonConverterDuplicateAnnotations', + 'JsonConverterCtorParams', + 'JustSetter', + 'JustSetterNoToJson', + 'GeneralTestClass1', + 'GeneralTestClass2', + 'JustSetterNoFromJson', + 'BadFromFuncReturnType', + 'InvalidFromFunc2Args', + 'ValidToFromFuncClassStatic', + 'BadToFuncReturnType', + 'InvalidToFunc2Args', + 'ObjectConvertMethods', + 'DynamicConvertMethods', + 'TypedConvertMethods', + 'FromDynamicCollection', + 'BadNoArgs', + 'BadTwoRequiredPositional', + 'BadOneNamed', + 'OkayOneNormalOptionalPositional', + 'OkayOneNormalOptionalNamed', + 'OkayOnlyOptionalPositional' +]; + +LibraryReader _libraryReader; void main() async { - final path = testFilePath('test', 'src'); - _library = await resolveCompilationUnit(path); - - StreamSubscription logSubscription; - - setUp(() { - assert(_buildLogItems.isEmpty); - assert(logSubscription == null); - logSubscription = log.onRecord.listen((r) => _buildLogItems.add(r.message)); - }); - - tearDown(() async { - if (logSubscription != null) { - await logSubscription.cancel(); - logSubscription = null; - } - - final remainingItems = _buildLogItems.toList(); - _buildLogItems.clear(); - expect(remainingItems, isEmpty, - reason: - 'Tests should validate entries and clear this before `tearDown`.'); - _buildLogItems.clear(); - }); - - // Only need to run this check once! - test('[all expected files]', () { - expect(_annotatedElements.keys, _expectedAnnotatedTests.keys); - }); - - for (final entry in _annotatedElements.entries) { - group(entry.key, () { - test('[all expected classes]', () { - expect( - _expectedAnnotatedTests, - containsPair(entry.key, - unorderedEquals(entry.value.map((ae) => ae.element.name)))); - }); - - for (final annotatedElement in entry.value) { - _testAnnotatedClass(annotatedElement); - } - }); - } + initializeBuildLogTracking(); + _libraryReader = await initializeLibraryReaderForDirectory( + testFilePath('test', 'src'), + '_json_serializable_test_input.dart', + ); + + testAnnotatedElements( + _libraryReader, + const JsonSerializableGenerator(), + additionalGenerators: const { + 'wrapped': JsonSerializableGenerator( + config: JsonSerializable(useWrappers: true), + ), + }, + expectedAnnotatedTests: _expectedAnnotatedTests, + ); group('without wrappers', () { _registerTests(JsonSerializable.defaults); @@ -201,10 +120,12 @@ void main() async { const JsonSerializable(useWrappers: true).withDefaults())); group('configuration', () { - void runWithConfigAndLogger(JsonSerializable config, String className) { - _runForElementNamedWithGenerator( + Future runWithConfigAndLogger( + JsonSerializable config, String className) async { + await generateForElement( JsonSerializableGenerator( config: config, typeHelpers: const [_ConfigLogger()]), + _libraryReader, className); } @@ -219,8 +140,8 @@ void main() async { final testDescription = '$className with ${nullConfig ? 'null' : 'default'} config'; - test(testDescription, () { - runWithConfigAndLogger( + test(testDescription, () async { + await runWithConfigAndLogger( nullConfig ? null : const JsonSerializable(), className); expect(_ConfigLogger.configurations, hasLength(2)); @@ -235,8 +156,8 @@ void main() async { test( 'values in config override unconfigured (default) values in annotation', - () { - runWithConfigAndLogger( + () async { + await runWithConfigAndLogger( JsonSerializable.fromJson(generatorConfigNonDefaultJson), 'ConfigurationImplicitDefaults'); @@ -249,14 +170,14 @@ void main() async { Map.from(generatorConfigNonDefaultJson); configMap['create_to_json'] = true; - runWithConfigAndLogger(JsonSerializable.fromJson(configMap), + await runWithConfigAndLogger(JsonSerializable.fromJson(configMap), 'ConfigurationImplicitDefaults'); }); test( 'explicit values in annotation override corresponding settings in config', - () { - runWithConfigAndLogger( + () async { + await runWithConfigAndLogger( JsonSerializable.fromJson(generatorConfigNonDefaultJson), 'ConfigurationExplicitDefaults'); @@ -277,137 +198,30 @@ void main() async { }); } -void _testAnnotatedClass(AnnotatedElement annotatedElement) { - final annotationName = annotatedElement.annotation.objectValue.type.name; - switch (annotationName) { - case 'ShouldThrow': - _testShouldThrow(annotatedElement); - break; - case 'ShouldGenerate': - _testShouldGenerate(annotatedElement); - break; - default: - throw UnsupportedError("We don't support $annotationName"); - } -} - -void _testShouldThrow(AnnotatedElement annotatedElement) { - final element = annotatedElement.element; - final constReader = annotatedElement.annotation; - final messageMatcher = constReader.read('errorMessage').stringValue; - var todoMatcher = constReader.read('todo').literalValue; - - test(element.name, () { - todoMatcher ??= isEmpty; - - expect( - () => _runForElementNamed( - const JsonSerializable(useWrappers: false), element.name), - _throwsInvalidGenerationSourceError(messageMatcher, todoMatcher), - reason: 'Should fail without wrappers.'); - - expect( - () => _runForElementNamed( - const JsonSerializable(useWrappers: true), element.name), - _throwsInvalidGenerationSourceError(messageMatcher, todoMatcher), - reason: 'Should fail with wrappers.'); - }); -} - -void _testShouldGenerate(AnnotatedElement annotatedElement) { - final element = annotatedElement.element; - - final matcher = - _matcherFromShouldGenerateAnnotation(annotatedElement.annotation); - - final expectedLogItems = annotatedElement.annotation - .read('expectedLogItems') - .listValue - .map((obj) => obj.toStringValue()) - .toList(); - - test(element.name, () { - final output = _runForElementNamed(const JsonSerializable(), element.name); - expect(output, matcher); - - expect(_buildLogItems, expectedLogItems); - _buildLogItems.clear(); - }); - - final wrappedMatcher = _matcherFromShouldGenerateAnnotation( - annotatedElement.annotation, - wrapped: true); - if (wrappedMatcher != null) { - test('${element.name} - (wrapped)', () { - final output = _runForElementNamed( - const JsonSerializable(useWrappers: true), element.name); - expect(output, wrappedMatcher); - - expect(_buildLogItems, expectedLogItems); - _buildLogItems.clear(); - }); - } -} - -String _runForElementNamed(JsonSerializable config, String name) { +Future _runForElementNamed(JsonSerializable config, String name) async { final generator = JsonSerializableGenerator(config: config); - return _runForElementNamedWithGenerator(generator, name); + return generateForElement(generator, _libraryReader, name); } -String _runForElementNamedWithGenerator( - JsonSerializableGenerator generator, String name) { - final element = _library.allElements - .singleWhere((e) => e is! ConstVariableElement && e.name == name); - final annotation = generator.typeChecker.firstAnnotationOf(element); - final generated = generator - .generateForAnnotatedElement(element, ConstantReader(annotation), null) - .map((e) => e.trim()) - .where((e) => e.isNotEmpty) - .map((e) => '$e\n\n') - .join(); - - final output = _formatter.format(generated); - printOnFailure("r'''\n$output'''"); - return output; -} - -final _annotatedElements = _library.allElements - .map((e) { - for (final md in e.metadata) { - md.computeConstantValue(); - final reader = ConstantReader(md.constantValue); - if (const ['ShouldGenerate', 'ShouldThrow'] - .contains(reader.objectValue.type.name)) { - return AnnotatedElement(reader, e); - } - } - return null; - }) - .where((ae) => ae != null) - .fold>>( - >{}, (map, annotatedElement) { - final list = map.putIfAbsent( - annotatedElement.element.source.uri.pathSegments.last, - () => []); - list.add(annotatedElement); - return map; - }); - void _registerTests(JsonSerializable generator) { - String runForElementNamed(String name) => + Future runForElementNamed(String name) => _runForElementNamed(generator, name); void expectThrows(String elementName, messageMatcher, [todoMatcher]) { todoMatcher ??= isEmpty; - expect(() => runForElementNamed(elementName), - _throwsInvalidGenerationSourceError(messageMatcher, todoMatcher)); + expect( + () => runForElementNamed(elementName), + throwsInvalidGenerationSourceError( + messageMatcher, + todoMatcher: todoMatcher, + ), + ); } group('explicit toJson', () { - test('nullable', () { - final output = _runForElementNamed( - JsonSerializable( - explicitToJson: true, useWrappers: generator.useWrappers), + test('nullable', () async { + final output = await _runForElementNamed( + JsonSerializable(useWrappers: generator.useWrappers), 'TrivialNestedNullable'); final expected = generator.useWrappers @@ -448,10 +262,9 @@ Map _$TrivialNestedNullableToJson( expect(output, expected); }); - test('non-nullable', () { - final output = _runForElementNamed( - JsonSerializable( - explicitToJson: true, useWrappers: generator.useWrappers), + test('non-nullable', () async { + final output = await _runForElementNamed( + JsonSerializable(useWrappers: generator.useWrappers), 'TrivialNestedNonNullable'); final expected = generator.useWrappers @@ -496,10 +309,10 @@ Map _$TrivialNestedNonNullableToJson( group('unknown types', () { tearDown(() { - expect(_buildLogItems, hasLength(1)); - expect(_buildLogItems.first, + expect(buildLogItems, hasLength(1)); + expect(buildLogItems.first, startsWith('This element has an undefined type.')); - _buildLogItems.clear(); + clearBuildLog(); }); String flavorMessage(String flavor) => 'Could not generate `$flavor` code for `number` ' @@ -529,8 +342,8 @@ Map _$TrivialNestedNonNullableToJson( }); }); - test('with proper convert methods', () { - final output = runForElementNamed('UnknownFieldTypeWithConvert'); + test('with proper convert methods', () async { + final output = await runForElementNamed('UnknownFieldTypeWithConvert'); expect(output, contains("_everythingIs42(json['number'])")); if (generator.useWrappers) { expect(output, contains('_everythingIs42(_v.number)')); @@ -573,8 +386,8 @@ Map _$TrivialNestedNonNullableToJson( }); }); - test('class with final fields', () { - final generateResult = runForElementNamed('FinalFields'); + test('class with final fields', () async { + final generateResult = await runForElementNamed('FinalFields'); expect( generateResult, contains( @@ -582,14 +395,15 @@ Map _$TrivialNestedNonNullableToJson( }); group('valid inputs', () { - test('class with fromJson() constructor with optional parameters', () { - final output = runForElementNamed('FromJsonOptionalParameters'); + test('class with fromJson() constructor with optional parameters', + () async { + final output = await runForElementNamed('FromJsonOptionalParameters'); expect(output, contains('ChildWithFromJson.fromJson')); }); - test('class with child json-able object', () { - final output = runForElementNamed('ParentObject'); + test('class with child json-able object', () async { + final output = await runForElementNamed('ParentObject'); expect( output, @@ -597,38 +411,32 @@ Map _$TrivialNestedNonNullableToJson( 'as Map)')); }); - test('class with child json-able object - anyMap', () { - final output = _runForElementNamed( + test('class with child json-able object - anyMap', () async { + final output = await _runForElementNamed( JsonSerializable(anyMap: true, useWrappers: generator.useWrappers), 'ParentObject'); expect(output, contains("ChildObject.fromJson(json['child'] as Map)")); }); - test('class with child list of json-able objects', () { - final output = runForElementNamed('ParentObjectWithChildren'); + test('class with child list of json-able objects', () async { + final output = await runForElementNamed('ParentObjectWithChildren'); expect(output, contains('.toList()')); expect(output, contains('ChildObject.fromJson')); }); - test('class with child list of dynamic objects is left alone', () { - final output = runForElementNamed('ParentObjectWithDynamicChildren'); + test('class with child list of dynamic objects is left alone', () async { + final output = + await runForElementNamed('ParentObjectWithDynamicChildren'); expect(output, contains('children = json[\'children\'] as List;')); }); - - test('class with list of int is cast for strong mode', () { - final output = runForElementNamed('Person'); - - expect(output, - contains("json['listOfInts'] as List)?.map((e) => e as int)")); - }); }); group('includeIfNull', () { - test('some', () { - final output = runForElementNamed('IncludeIfNullAll'); + test('some', () async { + final output = await runForElementNamed('IncludeIfNullAll'); expect(output, isNot(contains(generatedLocalVarName))); expect(output, isNot(contains(toJsonMapHelperName))); }); diff --git a/json_serializable/test/src/_json_serializable_test_input.dart b/json_serializable/test/src/_json_serializable_test_input.dart index c1f364a6d..679631ed6 100644 --- a/json_serializable/test/src/_json_serializable_test_input.dart +++ b/json_serializable/test/src/_json_serializable_test_input.dart @@ -7,12 +7,11 @@ import 'dart:collection'; import 'package:json_annotation/json_annotation.dart'; - -import 'annotation.dart'; +import 'package:source_gen_test/annotations.dart'; part 'checked_test_input.dart'; -part 'core_subclass_type_input.dart'; part 'configuration_input.dart'; +part 'core_subclass_type_input.dart'; part 'default_value_input.dart'; part 'field_namer_input.dart'; part 'generic_test_input.dart'; @@ -22,18 +21,19 @@ part 'setter_test_input.dart'; part 'to_from_json_test_input.dart'; @ShouldThrow('Generator cannot target `theAnswer`.', - 'Remove the JsonSerializable annotation from `theAnswer`.') + todo: 'Remove the JsonSerializable annotation from `theAnswer`.') @JsonSerializable() const theAnswer = 42; @ShouldThrow('Generator cannot target `annotatedMethod`.', - 'Remove the JsonSerializable annotation from `annotatedMethod`.') + todo: 'Remove the JsonSerializable annotation from `annotatedMethod`.') @JsonSerializable() void annotatedMethod() => null; -@ShouldGenerate(r''' -Person _$PersonFromJson(Map json) { - return Person() +@ShouldGenerate( + r''' +GeneralTestClass1 _$GeneralTestClass1FromJson(Map json) { + return GeneralTestClass1() ..firstName = json['firstName'] as String ..lastName = json['lastName'] as String ..height = json['h'] as int @@ -45,7 +45,8 @@ Person _$PersonFromJson(Map json) { ..listOfInts = (json['listOfInts'] as List)?.map((e) => e as int)?.toList(); } -Map _$PersonToJson(Person instance) => { +Map _$GeneralTestClass1ToJson(GeneralTestClass1 instance) => + { 'firstName': instance.firstName, 'lastName': instance.lastName, 'h': instance.height, @@ -54,61 +55,74 @@ Map _$PersonToJson(Person instance) => { 'varType': instance.varType, 'listOfInts': instance.listOfInts }; -''') +''', + configurations: ['default'], +) @JsonSerializable() -class Person { +class GeneralTestClass1 { String firstName, lastName; @JsonKey(name: 'h') int height; DateTime dateOfBirth; dynamic dynamicType; + //ignore: prefer_typing_uninitialized_variables var varType; List listOfInts; } -@ShouldGenerate(r''' -Order _$OrderFromJson(Map json) { - return Order(json['height'] as int, json['firstName'] as String, +@ShouldGenerate( + r''' +GeneralTestClass2 _$GeneralTestClass2FromJson(Map json) { + return GeneralTestClass2(json['height'] as int, json['firstName'] as String, json['lastName'] as String) ..dateOfBirth = json['dateOfBirth'] == null ? null : DateTime.parse(json['dateOfBirth'] as String); } -Map _$OrderToJson(Order instance) => { +Map _$GeneralTestClass2ToJson(GeneralTestClass2 instance) => + { 'firstName': instance.firstName, 'lastName': instance.lastName, 'height': instance.height, 'dateOfBirth': instance.dateOfBirth?.toIso8601String() }; -''') +''', + configurations: ['default'], +) @JsonSerializable() -class Order { +class GeneralTestClass2 { final String firstName, lastName; int height; DateTime dateOfBirth; - Order(this.height, String firstName, [this.lastName]) : firstName = firstName; + GeneralTestClass2(this.height, String firstName, [this.lastName]) + : firstName = firstName; } -@ShouldGenerate(r''' +@ShouldGenerate( + r''' FinalFields _$FinalFieldsFromJson(Map json) { return FinalFields(json['a'] as int); } Map _$FinalFieldsToJson(FinalFields instance) => {'a': instance.a}; -''') +''', + configurations: ['default'], +) @JsonSerializable() class FinalFields { final int a; + int get b => 4; FinalFields(this.a); } -@ShouldGenerate(r''' +@ShouldGenerate( + r''' FinalFieldsNotSetInCtor _$FinalFieldsNotSetInCtorFromJson( Map json) { return FinalFieldsNotSetInCtor(); @@ -117,7 +131,9 @@ FinalFieldsNotSetInCtor _$FinalFieldsNotSetInCtorFromJson( Map _$FinalFieldsNotSetInCtorToJson( FinalFieldsNotSetInCtor instance) => {}; -''') +''', + configurations: ['default'], +) @JsonSerializable() class FinalFieldsNotSetInCtor { final int a = 1; @@ -125,14 +141,17 @@ class FinalFieldsNotSetInCtor { FinalFieldsNotSetInCtor(); } -@ShouldGenerate(r''' +@ShouldGenerate( + r''' SetSupport _$SetSupportFromJson(Map json) { return SetSupport((json['values'] as List)?.map((e) => e as int)?.toSet()); } Map _$SetSupportToJson(SetSupport instance) => {'values': instance.values?.toList()}; -''') +''', + configurations: ['default'], +) @JsonSerializable() class SetSupport { final Set values; @@ -234,7 +253,8 @@ class IncludeIfNullAll { String str; } -@ShouldGenerate(r''' +@ShouldGenerate( + r''' Map _$IncludeIfNullOverrideToJson( IncludeIfNullOverride instance) { final val = { @@ -250,7 +270,9 @@ Map _$IncludeIfNullOverrideToJson( writeNotNull('str', instance.str); return val; } -''') +''', + configurations: ['default'], +) @JsonSerializable(createFactory: false, includeIfNull: false) class IncludeIfNullOverride { @JsonKey(includeIfNull: true) @@ -266,8 +288,11 @@ class NoCtorClass { factory NoCtorClass.fromJson(Map json) => null; } -@ShouldThrow('More than one field has the JSON key `str`.', - 'Check the `JsonKey` annotations on fields.') +@ShouldThrow( + 'More than one field has the JSON key `str`.', + todo: 'Check the `JsonKey` annotations on fields.', + element: 'str', +) @JsonSerializable(createFactory: false) class KeyDupesField { @JsonKey(name: 'str') @@ -276,8 +301,11 @@ class KeyDupesField { String str; } -@ShouldThrow('More than one field has the JSON key `a`.', - 'Check the `JsonKey` annotations on fields.') +@ShouldThrow( + 'More than one field has the JSON key `a`.', + todo: 'Check the `JsonKey` annotations on fields.', + element: 'str', +) @JsonSerializable(createFactory: false) class DupeKeys { @JsonKey(name: 'a') @@ -287,13 +315,16 @@ class DupeKeys { String str; } -@ShouldGenerate(r''' +@ShouldGenerate( + r''' Map _$IgnoredFieldClassToJson(IgnoredFieldClass instance) => { 'ignoredFalseField': instance.ignoredFalseField, 'ignoredNullField': instance.ignoredNullField }; -''') +''', + configurations: ['default'], +) @JsonSerializable(createFactory: false) class IgnoredFieldClass { @JsonKey(ignore: true) @@ -305,48 +336,61 @@ class IgnoredFieldClass { int ignoredNullField; } -@ShouldThrow('Cannot populate the required constructor argument: ' - 'ignoredTrueField. It is assigned to an ignored field.') +@ShouldThrow( + 'Cannot populate the required constructor argument: ' + 'ignoredTrueField. It is assigned to an ignored field.', + element: '', +) @JsonSerializable() class IgnoredFieldCtorClass { @JsonKey(ignore: true) int ignoredTrueField; + IgnoredFieldCtorClass(this.ignoredTrueField); } -@ShouldThrow('Cannot populate the required constructor argument: ' - '_privateField. It is assigned to a private field.') +@ShouldThrow( + 'Cannot populate the required constructor argument: ' + '_privateField. It is assigned to a private field.', + element: '', +) @JsonSerializable() class PrivateFieldCtorClass { // ignore: unused_field int _privateField; + PrivateFieldCtorClass(this._privateField); } -@ShouldThrow('Error with `@JsonKey` on `field`. ' - 'Cannot set both `disallowNullvalue` and `includeIfNull` to `true`. ' - 'This leads to incompatible `toJson` and `fromJson` behavior.') +@ShouldThrow( + 'Error with `@JsonKey` on `field`. ' + 'Cannot set both `disallowNullvalue` and `includeIfNull` to `true`. ' + 'This leads to incompatible `toJson` and `fromJson` behavior.', + element: 'field', +) @JsonSerializable() class IncludeIfNullDisallowNullClass { @JsonKey(includeIfNull: true, disallowNullValue: true) int field; } -@JsonSerializable(createFactory: false) +@JsonSerializable(createFactory: false, explicitToJson: true) class TrivialNestedNullable { TrivialNestedNullable child; int otherField; } -@JsonSerializable(createFactory: false, nullable: false) +@JsonSerializable(createFactory: false, nullable: false, explicitToJson: true) class TrivialNestedNonNullable { TrivialNestedNonNullable child; int otherField; } @ShouldThrow( - 'The `JsonValue` annotation on `BadEnum.value` does not have a value ' - 'of type String, int, or null.') + 'The `JsonValue` annotation on `BadEnum.value` does not have a value ' + 'of type String, int, or null.', + element: 'value', +) @JsonSerializable() class JsonValueWithBool { BadEnum field; @@ -389,14 +433,15 @@ FieldWithFromJsonCtorAndTypeParams _$FieldWithFromJsonCtorAndTypeParamsFromJson( ..customOrders = json['customOrders'] == null ? null : MyList.fromJson((json['customOrders'] as List) - ?.map((e) => - e == null ? null : Order.fromJson(e as Map)) + ?.map((e) => e == null + ? null + : GeneralTestClass2.fromJson(e as Map)) ?.toList()); } ''') @JsonSerializable(createToJson: false) class FieldWithFromJsonCtorAndTypeParams { - MyList customOrders; + MyList customOrders; } class MyList extends ListBase { diff --git a/json_serializable/test/src/annotation.dart b/json_serializable/test/src/annotation.dart deleted file mode 100644 index 2c57d03b2..000000000 --- a/json_serializable/test/src/annotation.dart +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) 2018, 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. - -class ShouldThrow { - final String errorMessage; - final String todo; - - const ShouldThrow(this.errorMessage, [this.todo]); -} - -class ShouldGenerate { - final String expectedOutput; - final String expectedWrappedOutput; - final bool contains; - final List expectedLogItems; - - const ShouldGenerate( - this.expectedOutput, { - this.expectedWrappedOutput, - this.contains = false, - this.expectedLogItems = const [], - }); -} diff --git a/json_serializable/test/src/core_subclass_type_input.dart b/json_serializable/test/src/core_subclass_type_input.dart index 1be03515d..cb5d91cf3 100644 --- a/json_serializable/test/src/core_subclass_type_input.dart +++ b/json_serializable/test/src/core_subclass_type_input.dart @@ -1,27 +1,36 @@ part of '_json_serializable_test_input.dart'; -@ShouldThrow(r''' +@ShouldThrow( + r''' Could not generate `fromJson` code for `mapView`. None of the provided `TypeHelper` instances support the defined type.''', - 'Make sure all of the types are serializable.') + todo: 'Make sure all of the types are serializable.', + element: 'mapView', +) @JsonSerializable(createToJson: false) class UnsupportedMapField { MapView mapView; } -@ShouldThrow(r''' +@ShouldThrow( + r''' Could not generate `fromJson` code for `listView`. None of the provided `TypeHelper` instances support the defined type.''', - 'Make sure all of the types are serializable.') + todo: 'Make sure all of the types are serializable.', + element: 'listView', +) @JsonSerializable(createToJson: false) class UnsupportedListField { UnmodifiableListView listView; } -@ShouldThrow(r''' +@ShouldThrow( + r''' Could not generate `fromJson` code for `customSet`. None of the provided `TypeHelper` instances support the defined type.''', - 'Make sure all of the types are serializable.') + todo: 'Make sure all of the types are serializable.', + element: 'customSet', +) @JsonSerializable(createToJson: false) class UnsupportedSetField { _CustomSet customSet; @@ -29,10 +38,13 @@ class UnsupportedSetField { abstract class _CustomSet implements Set {} -@ShouldThrow(r''' +@ShouldThrow( + r''' Could not generate `fromJson` code for `customDuration`. None of the provided `TypeHelper` instances support the defined type.''', - 'Make sure all of the types are serializable.') + todo: 'Make sure all of the types are serializable.', + element: 'customDuration', +) @JsonSerializable(createToJson: false) class UnsupportedDurationField { _CustomDuration customDuration; @@ -40,10 +52,13 @@ class UnsupportedDurationField { abstract class _CustomDuration implements Duration {} -@ShouldThrow(r''' +@ShouldThrow( + r''' Could not generate `fromJson` code for `customUri`. None of the provided `TypeHelper` instances support the defined type.''', - 'Make sure all of the types are serializable.') + todo: 'Make sure all of the types are serializable.', + element: 'customUri', +) @JsonSerializable(createToJson: false) class UnsupportedUriField { _CustomUri customUri; @@ -51,10 +66,13 @@ class UnsupportedUriField { abstract class _CustomUri implements Uri {} -@ShouldThrow(r''' +@ShouldThrow( + r''' Could not generate `fromJson` code for `customDateTime`. None of the provided `TypeHelper` instances support the defined type.''', - 'Make sure all of the types are serializable.') + todo: 'Make sure all of the types are serializable.', + element: 'customDateTime', +) @JsonSerializable(createToJson: false) class UnsupportedDateTimeField { _CustomDateTime customDateTime; diff --git a/json_serializable/test/src/default_value_input.dart b/json_serializable/test/src/default_value_input.dart index ef760a055..37261fdc5 100644 --- a/json_serializable/test/src/default_value_input.dart +++ b/json_serializable/test/src/default_value_input.dart @@ -4,8 +4,11 @@ part of '_json_serializable_test_input.dart'; -@ShouldThrow('Error with `@JsonKey` on `field`. ' - '`defaultValue` is `Symbol`, it must be a literal.') +@ShouldThrow( + 'Error with `@JsonKey` on `field`. ' + '`defaultValue` is `Symbol`, it must be a literal.', + element: 'field', +) @JsonSerializable() class DefaultWithSymbol { @JsonKey(defaultValue: #symbol) @@ -16,8 +19,11 @@ class DefaultWithSymbol { int _function() => 42; -@ShouldThrow('Error with `@JsonKey` on `field`. ' - '`defaultValue` is `Function`, it must be a literal.') +@ShouldThrow( + 'Error with `@JsonKey` on `field`. ' + '`defaultValue` is `Function`, it must be a literal.', + element: 'field', +) @JsonSerializable() class DefaultWithFunction { @JsonKey(defaultValue: _function) @@ -26,8 +32,11 @@ class DefaultWithFunction { DefaultWithFunction(); } -@ShouldThrow('Error with `@JsonKey` on `field`. ' - '`defaultValue` is `Type`, it must be a literal.') +@ShouldThrow( + 'Error with `@JsonKey` on `field`. ' + '`defaultValue` is `Type`, it must be a literal.', + element: 'field', +) @JsonSerializable() class DefaultWithType { @JsonKey(defaultValue: Object) @@ -36,8 +45,11 @@ class DefaultWithType { DefaultWithType(); } -@ShouldThrow('Error with `@JsonKey` on `field`. ' - '`defaultValue` is `Duration`, it must be a literal.') +@ShouldThrow( + 'Error with `@JsonKey` on `field`. ' + '`defaultValue` is `Duration`, it must be a literal.', + element: 'field', +) @JsonSerializable() class DefaultWithConstObject { @JsonKey(defaultValue: Duration()) @@ -48,8 +60,11 @@ class DefaultWithConstObject { enum Enum { value } -@ShouldThrow('Error with `@JsonKey` on `field`. ' - '`defaultValue` is `List > Enum`, it must be a literal.') +@ShouldThrow( + 'Error with `@JsonKey` on `field`. ' + '`defaultValue` is `List > Enum`, it must be a literal.', + element: 'field', +) @JsonSerializable() class DefaultWithNestedEnum { @JsonKey(defaultValue: [Enum.value]) @@ -58,8 +73,11 @@ class DefaultWithNestedEnum { DefaultWithNestedEnum(); } -@ShouldThrow('Error with `@JsonKey` on `field`. ' - 'Cannot use `defaultValue` on a field with `nullable` false.') +@ShouldThrow( + 'Error with `@JsonKey` on `field`. ' + 'Cannot use `defaultValue` on a field with `nullable` false.', + element: 'field', +) @JsonSerializable() class DefaultWithNonNullableField { @JsonKey(defaultValue: 42, nullable: false) @@ -68,8 +86,11 @@ class DefaultWithNonNullableField { DefaultWithNonNullableField(); } -@ShouldThrow('Error with `@JsonKey` on `field`. ' - 'Cannot use `defaultValue` on a field with `nullable` false.') +@ShouldThrow( + 'Error with `@JsonKey` on `field`. ' + 'Cannot use `defaultValue` on a field with `nullable` false.', + element: 'field', +) @JsonSerializable(nullable: false) class DefaultWithNonNullableClass { @JsonKey(defaultValue: 42) diff --git a/json_serializable/test/src/field_namer_input.dart b/json_serializable/test/src/field_namer_input.dart index c3eba3f4b..f25754804 100644 --- a/json_serializable/test/src/field_namer_input.dart +++ b/json_serializable/test/src/field_namer_input.dart @@ -1,12 +1,15 @@ part of '_json_serializable_test_input.dart'; -@ShouldGenerate(r''' +@ShouldGenerate( + r''' Map _$FieldNamerNoneToJson(FieldNamerNone instance) => { 'theField': instance.theField, 'NAME_OVERRIDE': instance.nameOverride }; -''') +''', + configurations: ['default'], +) @JsonSerializable(fieldRename: FieldRename.none, createFactory: false) class FieldNamerNone { String theField; @@ -15,13 +18,16 @@ class FieldNamerNone { String nameOverride; } -@ShouldGenerate(r''' +@ShouldGenerate( + r''' Map _$FieldNamerKebabToJson(FieldNamerKebab instance) => { 'the-field': instance.theField, 'NAME_OVERRIDE': instance.nameOverride }; -''') +''', + configurations: ['default'], +) @JsonSerializable(fieldRename: FieldRename.kebab, createFactory: false) class FieldNamerKebab { String theField; @@ -30,13 +36,16 @@ class FieldNamerKebab { String nameOverride; } -@ShouldGenerate(r''' +@ShouldGenerate( + r''' Map _$FieldNamerSnakeToJson(FieldNamerSnake instance) => { 'the_field': instance.theField, 'NAME_OVERRIDE': instance.nameOverride }; -''') +''', + configurations: ['default'], +) @JsonSerializable(fieldRename: FieldRename.snake, createFactory: false) class FieldNamerSnake { String theField; diff --git a/json_serializable/test/src/generic_test_input.dart b/json_serializable/test/src/generic_test_input.dart index 2f6525ce2..1a0364915 100644 --- a/json_serializable/test/src/generic_test_input.dart +++ b/json_serializable/test/src/generic_test_input.dart @@ -33,7 +33,9 @@ Map _$GenericClassToJson( 'fieldT': instance.fieldT == null ? null : _dataToJson(instance.fieldT), 'fieldS': instance.fieldS == null ? null : _dataToJson(instance.fieldS) }; -''', expectedWrappedOutput: r''' +''') +@ShouldGenerate( + r''' GenericClass _$GenericClassFromJson( Map json) { return GenericClass() @@ -79,7 +81,9 @@ class _$GenericClassJsonMapWrapper extends $JsonMapWrapper { return null; } } -''') +''', + configurations: ['wrapped'], +) @JsonSerializable() class GenericClass { @JsonKey(fromJson: _dataFromJson, toJson: _dataToJson) @@ -101,4 +105,5 @@ class GenericClass { } T _dataFromJson(Object input) => null; + Object _dataToJson(T input) => null; diff --git a/json_serializable/test/src/inheritance_test_input.dart b/json_serializable/test/src/inheritance_test_input.dart index 0507d7e18..92a60e36a 100644 --- a/json_serializable/test/src/inheritance_test_input.dart +++ b/json_serializable/test/src/inheritance_test_input.dart @@ -1,6 +1,7 @@ part of '_json_serializable_test_input.dart'; -@ShouldGenerate(r''' +@ShouldGenerate( + r''' SubType _$SubTypeFromJson(Map json) { return SubType( json['subTypeViaCtor'] as int, json['super-final-field'] as int) @@ -24,7 +25,11 @@ Map _$SubTypeToJson(SubType instance) { val['subTypeReadWrite'] = instance.subTypeReadWrite; return val; } -''', expectedWrappedOutput: r''' +''', + configurations: ['default'], +) +@ShouldGenerate( + r''' SubType _$SubTypeFromJson(Map json) { return SubType( json['subTypeViaCtor'] as int, json['super-final-field'] as int) @@ -66,7 +71,9 @@ class _$SubTypeJsonMapWrapper extends $JsonMapWrapper { return null; } } -''') +''', + configurations: ['wrapped'], +) @JsonSerializable() class SubType extends SuperType { final int subTypeViaCtor; @@ -95,7 +102,8 @@ class SuperType { superFinalField == null ? null : superFinalField ~/ other; } -@ShouldGenerate(r''' +@ShouldGenerate( + r''' Map _$SubTypeWithAnnotatedFieldOverrideExtendsToJson( SubTypeWithAnnotatedFieldOverrideExtends instance) { final val = { @@ -112,14 +120,17 @@ Map _$SubTypeWithAnnotatedFieldOverrideExtendsToJson( val['priceHalf'] = instance.priceHalf; return val; } -''') +''', + configurations: ['default'], +) @JsonSerializable(createFactory: false) class SubTypeWithAnnotatedFieldOverrideExtends extends SuperType { SubTypeWithAnnotatedFieldOverrideExtends(int superTypeViaCtor) : super(superTypeViaCtor); } -@ShouldGenerate(r''' +@ShouldGenerate( + r''' Map _$SubTypeWithAnnotatedFieldOverrideExtendsWithOverridesToJson( SubTypeWithAnnotatedFieldOverrideExtendsWithOverrides instance) => @@ -128,7 +139,9 @@ Map 'superReadWriteField': instance.superReadWriteField, 'super-final-field': instance.superFinalField }; -''') +''', + configurations: ['default'], +) @JsonSerializable(createFactory: false) class SubTypeWithAnnotatedFieldOverrideExtendsWithOverrides extends SuperType { SubTypeWithAnnotatedFieldOverrideExtendsWithOverrides(int superTypeViaCtor) @@ -150,14 +163,17 @@ class SubTypeWithAnnotatedFieldOverrideExtendsWithOverrides extends SuperType { int get superFinalField => super.superFinalField; } -@ShouldGenerate(r''' +@ShouldGenerate( + r''' Map _$SubTypeWithAnnotatedFieldOverrideImplementsToJson( SubTypeWithAnnotatedFieldOverrideImplements instance) => { 'superReadWriteField': instance.superReadWriteField, 'superFinalField': instance.superFinalField }; -''') +''', + configurations: ['default'], +) @JsonSerializable(createFactory: false) class SubTypeWithAnnotatedFieldOverrideImplements implements SuperType { // Note the order of fields in the output is determined by this class diff --git a/json_serializable/test/src/json_converter_test_input.dart b/json_serializable/test/src/json_converter_test_input.dart index 19d647eda..854f37d25 100644 --- a/json_serializable/test/src/json_converter_test_input.dart +++ b/json_serializable/test/src/json_converter_test_input.dart @@ -4,7 +4,8 @@ part of '_json_serializable_test_input.dart'; -@ShouldGenerate(r''' +@ShouldGenerate( + r''' JsonConverterNamedCtor _$JsonConverterNamedCtorFromJson( Map json) { return JsonConverterNamedCtor() @@ -33,7 +34,9 @@ Map _$JsonConverterNamedCtorToJson( ? null : JsonConverterNamedCtor._toJson(instance.keyAnnotationFirst) }; -''') +''', + configurations: ['default'], +) @JsonSerializable() @_DurationMillisecondConverter.named() @_GenericConverter.named() @@ -46,10 +49,12 @@ class JsonConverterNamedCtor { Duration keyAnnotationFirst; static Duration _fromJson(int value) => null; + static int _toJson(Duration object) => 42; } -@ShouldGenerate(r''' +@ShouldGenerate( + r''' JsonConvertOnField _$JsonConvertOnFieldFromJson( Map json) { return JsonConvertOnField() @@ -87,7 +92,9 @@ Map _$JsonConvertOnFieldToJson( ? null : _GenericConverter().toJson(instance.genericValue) }; -''') +''', + configurations: ['default'], +) @JsonSerializable() @_durationConverter class JsonConvertOnField { @@ -105,6 +112,7 @@ class JsonConvertOnField { class _GenericConverter implements JsonConverter { const _GenericConverter(); + const _GenericConverter.named(); @override @@ -114,8 +122,11 @@ class _GenericConverter implements JsonConverter { int toJson(T object) => 0; } -@ShouldThrow('`JsonConverter` implementations can have no more than one type ' - 'argument. `_BadConverter` has 2.') +@ShouldThrow( + '`JsonConverter` implementations can have no more than one type argument. ' + '`_BadConverter` has 2.', + element: '_BadConverter', +) @JsonSerializable() @_BadConverter() class JsonConverterWithBadTypeArg { @@ -132,7 +143,10 @@ class _BadConverter implements JsonConverter { int toJson(S object) => 0; } -@ShouldThrow('Found more than one matching converter for `Duration`.') +@ShouldThrow( + 'Found more than one matching converter for `Duration`.', + element: '', +) @JsonSerializable() @_durationConverter @_DurationMillisecondConverter() @@ -155,7 +169,10 @@ class _DurationMillisecondConverter implements JsonConverter { int toJson(Duration object) => object?.inMilliseconds; } -@ShouldThrow('Generators with constructor arguments are not supported.') +@ShouldThrow( + 'Generators with constructor arguments are not supported.', + element: '', +) @JsonSerializable() @_ConverterWithCtorParams(42) class JsonConverterCtorParams { @@ -164,6 +181,7 @@ class JsonConverterCtorParams { class _ConverterWithCtorParams implements JsonConverter { final int param; + const _ConverterWithCtorParams(this.param); @override diff --git a/json_serializable/test/src/setter_test_input.dart b/json_serializable/test/src/setter_test_input.dart index ab9190eeb..b951dfeb5 100644 --- a/json_serializable/test/src/setter_test_input.dart +++ b/json_serializable/test/src/setter_test_input.dart @@ -1,33 +1,45 @@ part of '_json_serializable_test_input.dart'; -@ShouldGenerate(r''' +@ShouldGenerate( + r''' JustSetter _$JustSetterFromJson(Map json) { return JustSetter(); } Map _$JustSetterToJson(JustSetter instance) => {}; -''', expectedLogItems: ['Setters are ignored: JustSetter.someSetter']) +''', + expectedLogItems: ['Setters are ignored: JustSetter.someSetter'], + configurations: ['default'], +) @JsonSerializable() class JustSetter { set someSetter(Object name) {} } -@ShouldGenerate(r''' +@ShouldGenerate( + r''' JustSetterNoToJson _$JustSetterNoToJsonFromJson(Map json) { return JustSetterNoToJson(); } -''', expectedLogItems: ['Setters are ignored: JustSetterNoToJson.someSetter']) +''', + expectedLogItems: ['Setters are ignored: JustSetterNoToJson.someSetter'], + configurations: ['default'], +) @JsonSerializable(createToJson: false) class JustSetterNoToJson { set someSetter(Object name) {} } -@ShouldGenerate(r''' +@ShouldGenerate( + r''' Map _$JustSetterNoFromJsonToJson( JustSetterNoFromJson instance) => {}; -''', expectedLogItems: ['Setters are ignored: JustSetterNoFromJson.someSetter']) +''', + expectedLogItems: ['Setters are ignored: JustSetterNoFromJson.someSetter'], + configurations: ['default'], +) @JsonSerializable(createFactory: false) class JustSetterNoFromJson { set someSetter(Object name) {} diff --git a/json_serializable/test/src/to_from_json_test_input.dart b/json_serializable/test/src/to_from_json_test_input.dart index 91b520fba..32f9486f5 100644 --- a/json_serializable/test/src/to_from_json_test_input.dart +++ b/json_serializable/test/src/to_from_json_test_input.dart @@ -5,29 +5,37 @@ part of '_json_serializable_test_input.dart'; int _toInt(bool input) => 42; + int _twoArgFunction(int a, int b) => 42; dynamic _toDynamic(dynamic input) => null; + Object _toObject(Object input) => null; @ShouldThrow( - 'Error with `@JsonKey` on `field`. The `fromJson` function `_toInt` ' - 'return type `int` is not compatible with field type `String`.') + 'Error with `@JsonKey` on `field`. The `fromJson` function `_toInt` ' + 'return type `int` is not compatible with field type `String`.', + element: 'field', +) @JsonSerializable() class BadFromFuncReturnType { @JsonKey(fromJson: _toInt) String field; } -@ShouldThrow('Error with `@JsonKey` on `field`. The `fromJson` function ' - '`_twoArgFunction` must have one positional paramater.') +@ShouldThrow( + 'Error with `@JsonKey` on `field`. The `fromJson` function ' + '`_twoArgFunction` must have one positional paramater.', + element: 'field', +) @JsonSerializable() class InvalidFromFunc2Args { @JsonKey(fromJson: _twoArgFunction) String field; } -@ShouldGenerate(r''' +@ShouldGenerate( + r''' ValidToFromFuncClassStatic _$ValidToFromFuncClassStaticFromJson( Map json) { return ValidToFromFuncClassStatic() @@ -43,7 +51,9 @@ Map _$ValidToFromFuncClassStaticToJson( ? null : ValidToFromFuncClassStatic._staticFunc(instance.field) }; -''') +''', + configurations: ['default'], +) @JsonSerializable() class ValidToFromFuncClassStatic { static String _staticFunc(String param) => null; @@ -52,30 +62,43 @@ class ValidToFromFuncClassStatic { String field; } -@ShouldThrow('Error with `@JsonKey` on `field`. The `toJson` function `_toInt` ' - 'argument type `bool` is not compatible with field type `String`.') +@ShouldThrow( + 'Error with `@JsonKey` on `field`. The `toJson` function `_toInt` ' + 'argument type `bool` is not compatible with field type `String`.', + element: 'field', +) @JsonSerializable() class BadToFuncReturnType { @JsonKey(toJson: _toInt) String field; } -@ShouldThrow('Error with `@JsonKey` on `field`. The `toJson` function ' - '`_twoArgFunction` must have one positional paramater.') +@ShouldThrow( + 'Error with `@JsonKey` on `field`. The `toJson` function ' + '`_twoArgFunction` must have one positional paramater.', + element: 'field', +) @JsonSerializable() class InvalidToFunc2Args { @JsonKey(toJson: _twoArgFunction) String field; } -@ShouldGenerate("_toObject(json['field'])", contains: true) +@ShouldGenerate( + "_toObject(json['field'])", + contains: true, +) @JsonSerializable() class ObjectConvertMethods { @JsonKey(fromJson: _toObject, toJson: _toObject) String field; } -@ShouldGenerate("_toDynamic(json['field'])", contains: true) +@ShouldGenerate( + "_toDynamic(json['field'])", + contains: true, + configurations: ['default'], +) @JsonSerializable() class DynamicConvertMethods { @JsonKey(fromJson: _toDynamic, toJson: _toDynamic) @@ -84,7 +107,11 @@ class DynamicConvertMethods { String _toString(String input) => null; -@ShouldGenerate("_toString(json['field'] as String)", contains: true) +@ShouldGenerate( + "_toString(json['field'] as String)", + contains: true, + configurations: ['default'], +) @JsonSerializable() class TypedConvertMethods { @JsonKey(fromJson: _toString, toJson: _toString) @@ -92,10 +119,13 @@ class TypedConvertMethods { } String _fromDynamicMap(Map input) => null; + String _fromDynamicList(List input) => null; + String _fromDynamicIterable(Iterable input) => null; -@ShouldGenerate(r''' +@ShouldGenerate( + r''' FromDynamicCollection _$FromDynamicCollectionFromJson( Map json) { return FromDynamicCollection() @@ -109,7 +139,9 @@ FromDynamicCollection _$FromDynamicCollectionFromJson( ? null : _fromDynamicIterable(json['iterableField'] as List); } -''') +''', + configurations: ['default'], +) @JsonSerializable(createToJson: false) class FromDynamicCollection { @JsonKey(fromJson: _fromDynamicMap) @@ -122,8 +154,11 @@ class FromDynamicCollection { String _noArgs() => null; -@ShouldThrow('Error with `@JsonKey` on `field`. The `fromJson` function ' - '`_noArgs` must have one positional paramater.') +@ShouldThrow( + 'Error with `@JsonKey` on `field`. The `fromJson` function ' + '`_noArgs` must have one positional paramater.', + element: 'field', +) @JsonSerializable(createToJson: false) class BadNoArgs { @JsonKey(fromJson: _noArgs) @@ -132,8 +167,11 @@ class BadNoArgs { String _twoArgs(a, b) => null; -@ShouldThrow('Error with `@JsonKey` on `field`. The `fromJson` function ' - '`_twoArgs` must have one positional paramater.') +@ShouldThrow( + 'Error with `@JsonKey` on `field`. The `fromJson` function ' + '`_twoArgs` must have one positional paramater.', + element: 'field', +) @JsonSerializable(createToJson: false) class BadTwoRequiredPositional { @JsonKey(fromJson: _twoArgs) @@ -142,8 +180,11 @@ class BadTwoRequiredPositional { String _oneNamed({a}) => null; -@ShouldThrow('Error with `@JsonKey` on `field`. The `fromJson` function ' - '`_oneNamed` must have one positional paramater.') +@ShouldThrow( + 'Error with `@JsonKey` on `field`. The `fromJson` function ' + '`_oneNamed` must have one positional paramater.', + element: 'field', +) @JsonSerializable(createToJson: false) class BadOneNamed { @JsonKey(fromJson: _oneNamed) From be5e4d9f2d75a903181550e6e22a4b42d4ae11d7 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 5 Mar 2019 11:44:10 -0800 Subject: [PATCH 061/569] move unknown type test to annotations --- .../test/json_serializable_test.dart | 156 +++++++----------- .../src/_json_serializable_test_input.dart | 36 +--- .../test/src/unknown_type_test_input.dart | 149 +++++++++++++++++ 3 files changed, 212 insertions(+), 129 deletions(-) create mode 100644 json_serializable/test/src/unknown_type_test_input.dart diff --git a/json_serializable/test/json_serializable_test.dart b/json_serializable/test/json_serializable_test.dart index db7cbd7a5..ed8ee8ae9 100644 --- a/json_serializable/test/json_serializable_test.dart +++ b/json_serializable/test/json_serializable_test.dart @@ -22,73 +22,78 @@ Matcher _throwsUnsupportedError(matcher) => .having((e) => e.message, 'message', matcher)); const _expectedAnnotatedTests = [ - 'theAnswer', 'annotatedMethod', - 'FinalFields', - 'FinalFieldsNotSetInCtor', - 'SetSupport', - 'IncludeIfNullOverride', - 'KeyDupesField', - 'DupeKeys', - 'IgnoredFieldClass', - 'IgnoredFieldCtorClass', - 'PrivateFieldCtorClass', - 'IncludeIfNullDisallowNullClass', - 'JsonValueWithBool', - 'JsonValueValid', - 'FieldWithFromJsonCtorAndTypeParams', - 'WithANonCtorGetterChecked', - 'WithANonCtorGetter', - 'UnsupportedMapField', - 'UnsupportedListField', - 'UnsupportedSetField', - 'UnsupportedDurationField', - 'UnsupportedUriField', - 'UnsupportedDateTimeField', - 'DefaultWithSymbol', - 'DefaultWithFunction', - 'DefaultWithType', + 'BadFromFuncReturnType', + 'BadNoArgs', + 'BadOneNamed', + 'BadToFuncReturnType', + 'BadTwoRequiredPositional', 'DefaultWithConstObject', + 'DefaultWithDisallowNullRequiredClass', + 'DefaultWithFunction', 'DefaultWithNestedEnum', - 'DefaultWithNonNullableField', 'DefaultWithNonNullableClass', + 'DefaultWithNonNullableField', + 'DefaultWithSymbol', 'DefaultWithToJsonClass', - 'DefaultWithDisallowNullRequiredClass', - 'FieldNamerNone', + 'DefaultWithType', + 'DupeKeys', + 'DynamicConvertMethods', 'FieldNamerKebab', + 'FieldNamerNone', 'FieldNamerSnake', + 'FieldWithFromJsonCtorAndTypeParams', + 'FinalFields', + 'FinalFieldsNotSetInCtor', + 'FromDynamicCollection', + 'GeneralTestClass1', + 'GeneralTestClass2', 'GenericClass', 'GenericClass', - 'SubType', - 'SubType', - 'SubTypeWithAnnotatedFieldOverrideExtends', - 'SubTypeWithAnnotatedFieldOverrideExtendsWithOverrides', - 'SubTypeWithAnnotatedFieldOverrideImplements', + 'IgnoredFieldClass', + 'IgnoredFieldCtorClass', + 'IncludeIfNullDisallowNullClass', + 'IncludeIfNullOverride', + 'InvalidFromFunc2Args', + 'InvalidToFunc2Args', + 'JsonConverterCtorParams', + 'JsonConverterDuplicateAnnotations', 'JsonConverterNamedCtor', - 'JsonConvertOnField', 'JsonConverterWithBadTypeArg', - 'JsonConverterDuplicateAnnotations', - 'JsonConverterCtorParams', + 'JsonConvertOnField', + 'JsonValueValid', + 'JsonValueWithBool', 'JustSetter', - 'JustSetterNoToJson', - 'GeneralTestClass1', - 'GeneralTestClass2', 'JustSetterNoFromJson', - 'BadFromFuncReturnType', - 'InvalidFromFunc2Args', - 'ValidToFromFuncClassStatic', - 'BadToFuncReturnType', - 'InvalidToFunc2Args', + 'JustSetterNoToJson', + 'KeyDupesField', 'ObjectConvertMethods', - 'DynamicConvertMethods', - 'TypedConvertMethods', - 'FromDynamicCollection', - 'BadNoArgs', - 'BadTwoRequiredPositional', - 'BadOneNamed', - 'OkayOneNormalOptionalPositional', 'OkayOneNormalOptionalNamed', - 'OkayOnlyOptionalPositional' + 'OkayOneNormalOptionalPositional', + 'OkayOnlyOptionalPositional', + 'PrivateFieldCtorClass', + 'SetSupport', + 'SubType', + 'SubType', + 'SubTypeWithAnnotatedFieldOverrideExtends', + 'SubTypeWithAnnotatedFieldOverrideExtendsWithOverrides', + 'SubTypeWithAnnotatedFieldOverrideImplements', + 'theAnswer', + 'TypedConvertMethods', + 'UnknownCtorParamType', + 'UnknownFieldType', + 'UnknownFieldTypeToJsonOnly', + 'UnknownFieldTypeWithConvert', + 'UnknownFieldTypeWithConvert', + 'UnsupportedDateTimeField', + 'UnsupportedDurationField', + 'UnsupportedListField', + 'UnsupportedMapField', + 'UnsupportedSetField', + 'UnsupportedUriField', + 'ValidToFromFuncClassStatic', + 'WithANonCtorGetter', + 'WithANonCtorGetterChecked', ]; LibraryReader _libraryReader; @@ -207,6 +212,7 @@ void _registerTests(JsonSerializable generator) { Future runForElementNamed(String name) => _runForElementNamed(generator, name); + @deprecated void expectThrows(String elementName, messageMatcher, [todoMatcher]) { todoMatcher ??= isEmpty; expect( @@ -307,52 +313,6 @@ Map _$TrivialNestedNonNullableToJson( }); }); - group('unknown types', () { - tearDown(() { - expect(buildLogItems, hasLength(1)); - expect(buildLogItems.first, - startsWith('This element has an undefined type.')); - clearBuildLog(); - }); - String flavorMessage(String flavor) => - 'Could not generate `$flavor` code for `number` ' - 'because the type is undefined.'; - - String flavorTodo(String flavor) => - 'Check your imports. If you\'re trying to generate code for a ' - 'Platform-provided type, you may have to specify a custom `$flavor` ' - 'in the associated `@JsonKey` annotation.'; - - group('fromJson', () { - final msg = flavorMessage('fromJson'); - final todo = flavorTodo('fromJson'); - test('in constructor arguments', () { - expectThrows('UnknownCtorParamType', msg, todo); - }); - - test('in fields', () { - expectThrows('UnknownFieldType', msg, todo); - }); - }); - - group('toJson', () { - test('in fields', () { - expectThrows('UnknownFieldTypeToJsonOnly', flavorMessage('toJson'), - flavorTodo('toJson')); - }); - }); - - test('with proper convert methods', () async { - final output = await runForElementNamed('UnknownFieldTypeWithConvert'); - expect(output, contains("_everythingIs42(json['number'])")); - if (generator.useWrappers) { - expect(output, contains('_everythingIs42(_v.number)')); - } else { - expect(output, contains('_everythingIs42(instance.number)')); - } - }); - }); - group('unserializable types', () { final noSupportHelperFyi = 'Could not generate `toJson` code for `watch`.\n' 'None of the provided `TypeHelper` instances support the defined type.'; diff --git a/json_serializable/test/src/_json_serializable_test_input.dart b/json_serializable/test/src/_json_serializable_test_input.dart index 679631ed6..4e265dfda 100644 --- a/json_serializable/test/src/_json_serializable_test_input.dart +++ b/json_serializable/test/src/_json_serializable_test_input.dart @@ -2,7 +2,7 @@ // 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. -//ignore_for_file: avoid_unused_constructor_parameters, prefer_initializing_formals +//ignore_for_file: avoid_unused_constructor_parameters import 'dart:collection'; @@ -19,6 +19,7 @@ part 'inheritance_test_input.dart'; part 'json_converter_test_input.dart'; part 'setter_test_input.dart'; part 'to_from_json_test_input.dart'; +part 'unknown_type_test_input.dart'; @ShouldThrow('Generator cannot target `theAnswer`.', todo: 'Remove the JsonSerializable annotation from `theAnswer`.') @@ -98,7 +99,9 @@ class GeneralTestClass2 { DateTime dateOfBirth; GeneralTestClass2(this.height, String firstName, [this.lastName]) - : firstName = firstName; + : + // ignore: prefer_initializing_formals + firstName = firstName; } @ShouldGenerate( @@ -197,35 +200,6 @@ class ParentObjectWithDynamicChildren { List children; } -@JsonSerializable() -class UnknownCtorParamType { - int number; - - // ignore: undefined_class, field_initializer_not_assignable - UnknownCtorParamType(Bob number) : number = number; -} - -@JsonSerializable() -class UnknownFieldType { - // ignore: undefined_class - Bob number; -} - -@JsonSerializable(createFactory: false) -class UnknownFieldTypeToJsonOnly { - // ignore: undefined_class - Bob number; -} - -@JsonSerializable() -class UnknownFieldTypeWithConvert { - @JsonKey(fromJson: _everythingIs42, toJson: _everythingIs42) - // ignore: undefined_class - Bob number; -} - -dynamic _everythingIs42(Object input) => 42; - @JsonSerializable(createFactory: false) class NoSerializeFieldType { Stopwatch watch; diff --git a/json_serializable/test/src/unknown_type_test_input.dart b/json_serializable/test/src/unknown_type_test_input.dart new file mode 100644 index 000000000..fe540e21f --- /dev/null +++ b/json_serializable/test/src/unknown_type_test_input.dart @@ -0,0 +1,149 @@ +part of '_json_serializable_test_input.dart'; + +@ShouldThrow( + 'Could not generate `fromJson` code for `number` because the type ' + 'is undefined.', + expectedLogItems: [ + ''' +This element has an undefined type. It may causes issues when generated code. +package:__test__/unknown_type_test_input.dart:25:28 + ╷ +25 │ UnknownCtorParamType(Bob number) : number = number; + │ ^^^^^^ + ╵''' + ], + todo: 'Check your imports. If you\'re trying to generate code for a ' + 'Platform-provided type, you may have to specify a custom `fromJson` ' + 'in the associated `@JsonKey` annotation.', + configurations: ['default'], +) +@JsonSerializable() +class UnknownCtorParamType { + int number; + + // ignore: undefined_class, field_initializer_not_assignable, prefer_initializing_formals + UnknownCtorParamType(Bob number) : number = number; +} + +@ShouldThrow( + 'Could not generate `fromJson` code for `number` because the type ' + 'is undefined.', + expectedLogItems: [ + ''' +This element has an undefined type. It may causes issues when generated code. +package:__test__/unknown_type_test_input.dart:48:7 + ╷ +48 │ Bob number; + │ ^^^^^^ + ╵''' + ], + todo: 'Check your imports. If you\'re trying to generate code for a ' + 'Platform-provided type, you may have to specify a custom `fromJson` ' + 'in the associated `@JsonKey` annotation.', + configurations: ['default'], +) +@JsonSerializable() +class UnknownFieldType { + // ignore: undefined_class + Bob number; +} + +@ShouldThrow( + 'Could not generate `toJson` code for `number` because the type ' + 'is undefined.', + expectedLogItems: [ + ''' +This element has an undefined type. It may causes issues when generated code. +package:__test__/unknown_type_test_input.dart:71:7 + ╷ +71 │ Bob number; + │ ^^^^^^ + ╵''' + ], + todo: 'Check your imports. If you\'re trying to generate code for a ' + 'Platform-provided type, you may have to specify a custom `toJson` ' + 'in the associated `@JsonKey` annotation.', + configurations: ['default'], +) +@JsonSerializable(createFactory: false) +class UnknownFieldTypeToJsonOnly { + // ignore: undefined_class + Bob number; +} + +@ShouldGenerate( + r''' +UnknownFieldTypeWithConvert _$UnknownFieldTypeWithConvertFromJson( + Map json) { + return UnknownFieldTypeWithConvert() + ..number = json['number'] == null ? null : _everythingIs42(json['number']); +} + +Map _$UnknownFieldTypeWithConvertToJson( + UnknownFieldTypeWithConvert instance) => + _$UnknownFieldTypeWithConvertJsonMapWrapper(instance); + +class _$UnknownFieldTypeWithConvertJsonMapWrapper extends $JsonMapWrapper { + final UnknownFieldTypeWithConvert _v; + _$UnknownFieldTypeWithConvertJsonMapWrapper(this._v); + + @override + Iterable get keys => const ['number']; + + @override + dynamic operator [](Object key) { + if (key is String) { + switch (key) { + case 'number': + return _v.number == null ? null : _everythingIs42(_v.number); + } + } + return null; + } +} +''', + configurations: ['wrapped'], + expectedLogItems: [ + ''' +This element has an undefined type. It may causes issues when generated code. +package:__test__/unknown_type_test_input.dart:146:7 + ╷ +146 │ Bob number; + │ ^^^^^^ + ╵''' + ], +) +@ShouldGenerate( + r''' +UnknownFieldTypeWithConvert _$UnknownFieldTypeWithConvertFromJson( + Map json) { + return UnknownFieldTypeWithConvert() + ..number = json['number'] == null ? null : _everythingIs42(json['number']); +} + +Map _$UnknownFieldTypeWithConvertToJson( + UnknownFieldTypeWithConvert instance) => + { + 'number': + instance.number == null ? null : _everythingIs42(instance.number) + }; +''', + configurations: ['default'], + expectedLogItems: [ + ''' +This element has an undefined type. It may causes issues when generated code. +package:__test__/unknown_type_test_input.dart:146:7 + ╷ +146 │ Bob number; + │ ^^^^^^ + ╵''' + ], +) +@JsonSerializable() +class UnknownFieldTypeWithConvert { + @JsonKey(fromJson: _everythingIs42, toJson: _everythingIs42) + // ignore: undefined_class + Bob number; +} + +dynamic _everythingIs42(Object input) => 42; From 52b4665c71a5ff68cf71f78424201b29906e3357 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 5 Mar 2019 12:00:09 -0800 Subject: [PATCH 062/569] migrate the rest of the expectThrows tests to annotations --- .../test/json_serializable_test.dart | 49 ++----------------- .../src/_json_serializable_test_input.dart | 20 ++++++++ 2 files changed, 24 insertions(+), 45 deletions(-) diff --git a/json_serializable/test/json_serializable_test.dart b/json_serializable/test/json_serializable_test.dart index ed8ee8ae9..69e712094 100644 --- a/json_serializable/test/json_serializable_test.dart +++ b/json_serializable/test/json_serializable_test.dart @@ -67,6 +67,10 @@ const _expectedAnnotatedTests = [ 'JustSetterNoFromJson', 'JustSetterNoToJson', 'KeyDupesField', + 'NoDeserializeBadKey', + 'NoDeserializeFieldType', + 'NoSerializeBadKey', + 'NoSerializeFieldType', 'ObjectConvertMethods', 'OkayOneNormalOptionalNamed', 'OkayOneNormalOptionalPositional', @@ -212,18 +216,6 @@ void _registerTests(JsonSerializable generator) { Future runForElementNamed(String name) => _runForElementNamed(generator, name); - @deprecated - void expectThrows(String elementName, messageMatcher, [todoMatcher]) { - todoMatcher ??= isEmpty; - expect( - () => runForElementNamed(elementName), - throwsInvalidGenerationSourceError( - messageMatcher, - todoMatcher: todoMatcher, - ), - ); - } - group('explicit toJson', () { test('nullable', () async { final output = await _runForElementNamed( @@ -313,39 +305,6 @@ Map _$TrivialNestedNonNullableToJson( }); }); - group('unserializable types', () { - final noSupportHelperFyi = 'Could not generate `toJson` code for `watch`.\n' - 'None of the provided `TypeHelper` instances support the defined type.'; - - test('for toJson', () { - expectThrows('NoSerializeFieldType', noSupportHelperFyi, - 'Make sure all of the types are serializable.'); - }); - - test('for fromJson', () { - expectThrows( - 'NoDeserializeFieldType', - noSupportHelperFyi.replaceFirst('toJson', 'fromJson'), - 'Make sure all of the types are serializable.'); - }); - - final mapKeyFyi = 'Could not generate `toJson` code for `intDateTimeMap` ' - 'because of type `int`.\nMap keys must be of type ' - '`String`, enum, `Object` or `dynamic`.'; - - test('for toJson in Map key', () { - expectThrows('NoSerializeBadKey', mapKeyFyi, - 'Make sure all of the types are serializable.'); - }); - - test('for fromJson', () { - expectThrows( - 'NoDeserializeBadKey', - mapKeyFyi.replaceFirst('toJson', 'fromJson'), - 'Make sure all of the types are serializable.'); - }); - }); - test('class with final fields', () async { final generateResult = await runForElementNamed('FinalFields'); expect( diff --git a/json_serializable/test/src/_json_serializable_test_input.dart b/json_serializable/test/src/_json_serializable_test_input.dart index 4e265dfda..4d381b9ba 100644 --- a/json_serializable/test/src/_json_serializable_test_input.dart +++ b/json_serializable/test/src/_json_serializable_test_input.dart @@ -200,21 +200,41 @@ class ParentObjectWithDynamicChildren { List children; } +@ShouldThrow( + 'Could not generate `toJson` code for `watch`.\n' + 'None of the provided `TypeHelper` instances support the defined type.', + configurations: ['default'], +) @JsonSerializable(createFactory: false) class NoSerializeFieldType { Stopwatch watch; } +@ShouldThrow( + 'Could not generate `fromJson` code for `watch`.\n' + 'None of the provided `TypeHelper` instances support the defined type.', + configurations: ['default'], +) @JsonSerializable(createToJson: false) class NoDeserializeFieldType { Stopwatch watch; } +@ShouldThrow( + 'Could not generate `toJson` code for `intDateTimeMap` because of type `int`.\n' + 'Map keys must be of type `String`, enum, `Object` or `dynamic`.', + configurations: ['default'], +) @JsonSerializable(createFactory: false) class NoSerializeBadKey { Map intDateTimeMap; } +@ShouldThrow( + 'Could not generate `fromJson` code for `intDateTimeMap` because of type `int`.\n' + 'Map keys must be of type `String`, enum, `Object` or `dynamic`.', + configurations: ['default'], +) @JsonSerializable(createToJson: false) class NoDeserializeBadKey { Map intDateTimeMap; From df35309fb76aa5d0c064686e178d0302320372fb Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 5 Mar 2019 12:03:52 -0800 Subject: [PATCH 063/569] Migrate the final exceptional test - and update the corresponding error --- json_serializable/lib/src/decode_helper.dart | 5 +++-- json_serializable/test/json_serializable_test.dart | 12 +----------- .../test/src/_json_serializable_test_input.dart | 4 ++++ 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/json_serializable/lib/src/decode_helper.dart b/json_serializable/lib/src/decode_helper.dart index 3e4e06f55..279cb585d 100644 --- a/json_serializable/lib/src/decode_helper.dart +++ b/json_serializable/lib/src/decode_helper.dart @@ -233,8 +233,9 @@ _ConstructorData _writeConstructorInvocation( final ctor = classElement.unnamedConstructor; if (ctor == null) { // TODO(kevmoo): support using another ctor - dart-lang/json_serializable#50 - throw UnsupportedError( - 'The class `$className` has no default constructor.'); + throw InvalidGenerationSourceError( + 'The class `$className` has no default constructor.', + element: classElement); } final usedCtorParamsAndFields = Set(); diff --git a/json_serializable/test/json_serializable_test.dart b/json_serializable/test/json_serializable_test.dart index 69e712094..8acc99666 100644 --- a/json_serializable/test/json_serializable_test.dart +++ b/json_serializable/test/json_serializable_test.dart @@ -17,10 +17,6 @@ import 'package:test/test.dart'; import 'shared_config.dart'; import 'test_file_utils.dart'; -Matcher _throwsUnsupportedError(matcher) => - throwsA(const TypeMatcher() - .having((e) => e.message, 'message', matcher)); - const _expectedAnnotatedTests = [ 'annotatedMethod', 'BadFromFuncReturnType', @@ -67,6 +63,7 @@ const _expectedAnnotatedTests = [ 'JustSetterNoFromJson', 'JustSetterNoToJson', 'KeyDupesField', + 'NoCtorClass', 'NoDeserializeBadKey', 'NoDeserializeFieldType', 'NoSerializeBadKey', @@ -360,13 +357,6 @@ Map _$TrivialNestedNonNullableToJson( expect(output, isNot(contains(toJsonMapHelperName))); }); }); - - test('missing default ctor with a factory', () { - expect( - () => runForElementNamed('NoCtorClass'), - _throwsUnsupportedError( - 'The class `NoCtorClass` has no default constructor.')); - }); } class _ConfigLogger implements TypeHelper { diff --git a/json_serializable/test/src/_json_serializable_test_input.dart b/json_serializable/test/src/_json_serializable_test_input.dart index 4d381b9ba..c423feb38 100644 --- a/json_serializable/test/src/_json_serializable_test_input.dart +++ b/json_serializable/test/src/_json_serializable_test_input.dart @@ -275,6 +275,10 @@ class IncludeIfNullOverride { } // https://github.com/dart-lang/json_serializable/issues/7 regression +@ShouldThrow( + 'The class `NoCtorClass` has no default constructor.', + configurations: ['default'], +) @JsonSerializable() class NoCtorClass { final int member; From b0b0b2bd927c56d6aae1a64ee1689f6dad2a43f6 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 5 Mar 2019 12:19:06 -0800 Subject: [PATCH 064/569] separate out test files: annotation-based vs manual --- .../test/custom_configuration_test.dart | 281 ++++++++++++++++ .../test/json_serializable_test.dart | 309 ++---------------- .../test/literal/json_literal_test.dart | 7 +- .../src/_json_serializable_test_input.dart | 61 +--- .../test/src/configuration_input.dart | 23 -- json_serializable/test/test_file_utils.dart | 26 -- .../test/test_sources/test_sources.dart | 81 +++++ 7 files changed, 385 insertions(+), 403 deletions(-) create mode 100644 json_serializable/test/custom_configuration_test.dart delete mode 100644 json_serializable/test/src/configuration_input.dart delete mode 100644 json_serializable/test/test_file_utils.dart create mode 100644 json_serializable/test/test_sources/test_sources.dart diff --git a/json_serializable/test/custom_configuration_test.dart b/json_serializable/test/custom_configuration_test.dart new file mode 100644 index 000000000..50b094eea --- /dev/null +++ b/json_serializable/test/custom_configuration_test.dart @@ -0,0 +1,281 @@ +// Copyright (c) 2015, 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. + +@TestOn('vm') +import 'dart:async'; + +import 'package:analyzer/dart/element/type.dart'; +import 'package:json_annotation/json_annotation.dart'; +import 'package:json_serializable/json_serializable.dart'; +import 'package:json_serializable/src/constants.dart'; +import 'package:json_serializable/src/type_helper.dart'; +import 'package:path/path.dart' as p; +import 'package:source_gen/source_gen.dart'; +import 'package:source_gen_test/source_gen_test.dart'; +import 'package:test/test.dart'; + +import 'shared_config.dart'; + +LibraryReader _libraryReader; + +void main() async { + initializeBuildLogTracking(); + _libraryReader = await initializeLibraryReaderForDirectory( + p.join('test', 'test_sources'), + 'test_sources.dart', + ); + + group('without wrappers', () { + _registerTests(JsonSerializable.defaults); + }); + group( + 'with wrapper', + () => _registerTests( + const JsonSerializable(useWrappers: true).withDefaults())); + + group('configuration', () { + Future runWithConfigAndLogger( + JsonSerializable config, String className) async { + await generateForElement( + JsonSerializableGenerator( + config: config, typeHelpers: const [_ConfigLogger()]), + _libraryReader, + className); + } + + setUp(_ConfigLogger.configurations.clear); + + group('defaults', () { + for (var className in [ + 'ConfigurationImplicitDefaults', + 'ConfigurationExplicitDefaults', + ]) { + for (var nullConfig in [true, false]) { + final testDescription = + '$className with ${nullConfig ? 'null' : 'default'} config'; + + test(testDescription, () async { + await runWithConfigAndLogger( + nullConfig ? null : const JsonSerializable(), className); + + expect(_ConfigLogger.configurations, hasLength(2)); + expect(_ConfigLogger.configurations.first, + same(_ConfigLogger.configurations.last)); + expect(_ConfigLogger.configurations.first.toJson(), + generatorConfigDefaultJson); + }); + } + } + }); + + test( + 'values in config override unconfigured (default) values in annotation', + () async { + await runWithConfigAndLogger( + JsonSerializable.fromJson(generatorConfigNonDefaultJson), + 'ConfigurationImplicitDefaults'); + + expect(_ConfigLogger.configurations, isEmpty, + reason: 'all generation is disabled'); + + // Create a configuration with just `create_to_json` set to true so we + // can validate the configuration that is run with + final configMap = + Map.from(generatorConfigNonDefaultJson); + configMap['create_to_json'] = true; + + await runWithConfigAndLogger(JsonSerializable.fromJson(configMap), + 'ConfigurationImplicitDefaults'); + }); + + test( + 'explicit values in annotation override corresponding settings in config', + () async { + await runWithConfigAndLogger( + JsonSerializable.fromJson(generatorConfigNonDefaultJson), + 'ConfigurationExplicitDefaults'); + + expect(_ConfigLogger.configurations, hasLength(2)); + expect(_ConfigLogger.configurations.first, + same(_ConfigLogger.configurations.last)); + + // The effective configuration should be non-Default configuration, but + // with all fields set from JsonSerializable as the defaults + + final expected = Map.from(generatorConfigNonDefaultJson); + for (var jsonSerialKey in jsonSerializableFields) { + expected[jsonSerialKey] = generatorConfigDefaultJson[jsonSerialKey]; + } + + expect(_ConfigLogger.configurations.first.toJson(), expected); + }); + }); +} + +Future _runForElementNamed(JsonSerializable config, String name) async { + final generator = JsonSerializableGenerator(config: config); + return generateForElement(generator, _libraryReader, name); +} + +void _registerTests(JsonSerializable generator) { + Future runForElementNamed(String name) => + _runForElementNamed(generator, name); + + group('explicit toJson', () { + test('nullable', () async { + final output = await _runForElementNamed( + JsonSerializable(useWrappers: generator.useWrappers), + 'TrivialNestedNullable'); + + final expected = generator.useWrappers + ? r''' +Map _$TrivialNestedNullableToJson( + TrivialNestedNullable instance) => + _$TrivialNestedNullableJsonMapWrapper(instance); + +class _$TrivialNestedNullableJsonMapWrapper extends $JsonMapWrapper { + final TrivialNestedNullable _v; + _$TrivialNestedNullableJsonMapWrapper(this._v); + + @override + Iterable get keys => const ['child', 'otherField']; + + @override + dynamic operator [](Object key) { + if (key is String) { + switch (key) { + case 'child': + return _v.child?.toJson(); + case 'otherField': + return _v.otherField; + } + } + return null; + } +} +''' + : r''' +Map _$TrivialNestedNullableToJson( + TrivialNestedNullable instance) => + { + 'child': instance.child?.toJson(), + 'otherField': instance.otherField + }; +'''; + + expect(output, expected); + }); + test('non-nullable', () async { + final output = await _runForElementNamed( + JsonSerializable(useWrappers: generator.useWrappers), + 'TrivialNestedNonNullable'); + + final expected = generator.useWrappers + ? r''' +Map _$TrivialNestedNonNullableToJson( + TrivialNestedNonNullable instance) => + _$TrivialNestedNonNullableJsonMapWrapper(instance); + +class _$TrivialNestedNonNullableJsonMapWrapper extends $JsonMapWrapper { + final TrivialNestedNonNullable _v; + _$TrivialNestedNonNullableJsonMapWrapper(this._v); + + @override + Iterable get keys => const ['child', 'otherField']; + + @override + dynamic operator [](Object key) { + if (key is String) { + switch (key) { + case 'child': + return _v.child.toJson(); + case 'otherField': + return _v.otherField; + } + } + return null; + } +} +''' + : r''' +Map _$TrivialNestedNonNullableToJson( + TrivialNestedNonNullable instance) => + { + 'child': instance.child.toJson(), + 'otherField': instance.otherField + }; +'''; + + expect(output, expected); + }); + }); + + group('valid inputs', () { + test('class with fromJson() constructor with optional parameters', + () async { + final output = await runForElementNamed('FromJsonOptionalParameters'); + + expect(output, contains('ChildWithFromJson.fromJson')); + }); + + test('class with child json-able object', () async { + final output = await runForElementNamed('ParentObject'); + + expect( + output, + contains("ChildObject.fromJson(json['child'] " + 'as Map)')); + }); + + test('class with child json-able object - anyMap', () async { + final output = await _runForElementNamed( + JsonSerializable(anyMap: true, useWrappers: generator.useWrappers), + 'ParentObject'); + + expect(output, contains("ChildObject.fromJson(json['child'] as Map)")); + }); + + test('class with child list of json-able objects', () async { + final output = await runForElementNamed('ParentObjectWithChildren'); + + expect(output, contains('.toList()')); + expect(output, contains('ChildObject.fromJson')); + }); + + test('class with child list of dynamic objects is left alone', () async { + final output = + await runForElementNamed('ParentObjectWithDynamicChildren'); + + expect(output, contains('children = json[\'children\'] as List;')); + }); + }); + + group('includeIfNull', () { + test('some', () async { + final output = await runForElementNamed('IncludeIfNullAll'); + expect(output, isNot(contains(generatedLocalVarName))); + expect(output, isNot(contains(toJsonMapHelperName))); + }); + }); +} + +class _ConfigLogger implements TypeHelper { + static final configurations = []; + + const _ConfigLogger(); + + @override + Object deserialize(DartType targetType, String expression, + TypeHelperContextWithConfig context) { + configurations.add(context.config); + return null; + } + + @override + Object serialize(DartType targetType, String expression, + TypeHelperContextWithConfig context) { + configurations.add(context.config); + return null; + } +} diff --git a/json_serializable/test/json_serializable_test.dart b/json_serializable/test/json_serializable_test.dart index 8acc99666..d008fc311 100644 --- a/json_serializable/test/json_serializable_test.dart +++ b/json_serializable/test/json_serializable_test.dart @@ -3,19 +3,30 @@ // BSD-style license that can be found in the LICENSE file. @TestOn('vm') -import 'dart:async'; - -import 'package:analyzer/dart/element/type.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:json_serializable/json_serializable.dart'; -import 'package:json_serializable/src/constants.dart'; -import 'package:json_serializable/src/type_helper.dart'; -import 'package:source_gen/source_gen.dart'; +import 'package:path/path.dart' as p; import 'package:source_gen_test/source_gen_test.dart'; import 'package:test/test.dart'; -import 'shared_config.dart'; -import 'test_file_utils.dart'; +void main() async { + initializeBuildLogTracking(); + final reader = await initializeLibraryReaderForDirectory( + p.join('test', 'src'), + '_json_serializable_test_input.dart', + ); + + testAnnotatedElements( + reader, + const JsonSerializableGenerator(), + additionalGenerators: const { + 'wrapped': JsonSerializableGenerator( + config: JsonSerializable(useWrappers: true), + ), + }, + expectedAnnotatedTests: _expectedAnnotatedTests, + ); +} const _expectedAnnotatedTests = [ 'annotatedMethod', @@ -96,285 +107,3 @@ const _expectedAnnotatedTests = [ 'WithANonCtorGetter', 'WithANonCtorGetterChecked', ]; - -LibraryReader _libraryReader; - -void main() async { - initializeBuildLogTracking(); - _libraryReader = await initializeLibraryReaderForDirectory( - testFilePath('test', 'src'), - '_json_serializable_test_input.dart', - ); - - testAnnotatedElements( - _libraryReader, - const JsonSerializableGenerator(), - additionalGenerators: const { - 'wrapped': JsonSerializableGenerator( - config: JsonSerializable(useWrappers: true), - ), - }, - expectedAnnotatedTests: _expectedAnnotatedTests, - ); - - group('without wrappers', () { - _registerTests(JsonSerializable.defaults); - }); - group( - 'with wrapper', - () => _registerTests( - const JsonSerializable(useWrappers: true).withDefaults())); - - group('configuration', () { - Future runWithConfigAndLogger( - JsonSerializable config, String className) async { - await generateForElement( - JsonSerializableGenerator( - config: config, typeHelpers: const [_ConfigLogger()]), - _libraryReader, - className); - } - - setUp(_ConfigLogger.configurations.clear); - - group('defaults', () { - for (var className in [ - 'ConfigurationImplicitDefaults', - 'ConfigurationExplicitDefaults', - ]) { - for (var nullConfig in [true, false]) { - final testDescription = - '$className with ${nullConfig ? 'null' : 'default'} config'; - - test(testDescription, () async { - await runWithConfigAndLogger( - nullConfig ? null : const JsonSerializable(), className); - - expect(_ConfigLogger.configurations, hasLength(2)); - expect(_ConfigLogger.configurations.first, - same(_ConfigLogger.configurations.last)); - expect(_ConfigLogger.configurations.first.toJson(), - generatorConfigDefaultJson); - }); - } - } - }); - - test( - 'values in config override unconfigured (default) values in annotation', - () async { - await runWithConfigAndLogger( - JsonSerializable.fromJson(generatorConfigNonDefaultJson), - 'ConfigurationImplicitDefaults'); - - expect(_ConfigLogger.configurations, isEmpty, - reason: 'all generation is disabled'); - - // Create a configuration with just `create_to_json` set to true so we - // can validate the configuration that is run with - final configMap = - Map.from(generatorConfigNonDefaultJson); - configMap['create_to_json'] = true; - - await runWithConfigAndLogger(JsonSerializable.fromJson(configMap), - 'ConfigurationImplicitDefaults'); - }); - - test( - 'explicit values in annotation override corresponding settings in config', - () async { - await runWithConfigAndLogger( - JsonSerializable.fromJson(generatorConfigNonDefaultJson), - 'ConfigurationExplicitDefaults'); - - expect(_ConfigLogger.configurations, hasLength(2)); - expect(_ConfigLogger.configurations.first, - same(_ConfigLogger.configurations.last)); - - // The effective configuration should be non-Default configuration, but - // with all fields set from JsonSerializable as the defaults - - final expected = Map.from(generatorConfigNonDefaultJson); - for (var jsonSerialKey in jsonSerializableFields) { - expected[jsonSerialKey] = generatorConfigDefaultJson[jsonSerialKey]; - } - - expect(_ConfigLogger.configurations.first.toJson(), expected); - }); - }); -} - -Future _runForElementNamed(JsonSerializable config, String name) async { - final generator = JsonSerializableGenerator(config: config); - return generateForElement(generator, _libraryReader, name); -} - -void _registerTests(JsonSerializable generator) { - Future runForElementNamed(String name) => - _runForElementNamed(generator, name); - - group('explicit toJson', () { - test('nullable', () async { - final output = await _runForElementNamed( - JsonSerializable(useWrappers: generator.useWrappers), - 'TrivialNestedNullable'); - - final expected = generator.useWrappers - ? r''' -Map _$TrivialNestedNullableToJson( - TrivialNestedNullable instance) => - _$TrivialNestedNullableJsonMapWrapper(instance); - -class _$TrivialNestedNullableJsonMapWrapper extends $JsonMapWrapper { - final TrivialNestedNullable _v; - _$TrivialNestedNullableJsonMapWrapper(this._v); - - @override - Iterable get keys => const ['child', 'otherField']; - - @override - dynamic operator [](Object key) { - if (key is String) { - switch (key) { - case 'child': - return _v.child?.toJson(); - case 'otherField': - return _v.otherField; - } - } - return null; - } -} -''' - : r''' -Map _$TrivialNestedNullableToJson( - TrivialNestedNullable instance) => - { - 'child': instance.child?.toJson(), - 'otherField': instance.otherField - }; -'''; - - expect(output, expected); - }); - test('non-nullable', () async { - final output = await _runForElementNamed( - JsonSerializable(useWrappers: generator.useWrappers), - 'TrivialNestedNonNullable'); - - final expected = generator.useWrappers - ? r''' -Map _$TrivialNestedNonNullableToJson( - TrivialNestedNonNullable instance) => - _$TrivialNestedNonNullableJsonMapWrapper(instance); - -class _$TrivialNestedNonNullableJsonMapWrapper extends $JsonMapWrapper { - final TrivialNestedNonNullable _v; - _$TrivialNestedNonNullableJsonMapWrapper(this._v); - - @override - Iterable get keys => const ['child', 'otherField']; - - @override - dynamic operator [](Object key) { - if (key is String) { - switch (key) { - case 'child': - return _v.child.toJson(); - case 'otherField': - return _v.otherField; - } - } - return null; - } -} -''' - : r''' -Map _$TrivialNestedNonNullableToJson( - TrivialNestedNonNullable instance) => - { - 'child': instance.child.toJson(), - 'otherField': instance.otherField - }; -'''; - - expect(output, expected); - }); - }); - - test('class with final fields', () async { - final generateResult = await runForElementNamed('FinalFields'); - expect( - generateResult, - contains( - r'Map _$FinalFieldsToJson(FinalFields instance)')); - }); - - group('valid inputs', () { - test('class with fromJson() constructor with optional parameters', - () async { - final output = await runForElementNamed('FromJsonOptionalParameters'); - - expect(output, contains('ChildWithFromJson.fromJson')); - }); - - test('class with child json-able object', () async { - final output = await runForElementNamed('ParentObject'); - - expect( - output, - contains("ChildObject.fromJson(json['child'] " - 'as Map)')); - }); - - test('class with child json-able object - anyMap', () async { - final output = await _runForElementNamed( - JsonSerializable(anyMap: true, useWrappers: generator.useWrappers), - 'ParentObject'); - - expect(output, contains("ChildObject.fromJson(json['child'] as Map)")); - }); - - test('class with child list of json-able objects', () async { - final output = await runForElementNamed('ParentObjectWithChildren'); - - expect(output, contains('.toList()')); - expect(output, contains('ChildObject.fromJson')); - }); - - test('class with child list of dynamic objects is left alone', () async { - final output = - await runForElementNamed('ParentObjectWithDynamicChildren'); - - expect(output, contains('children = json[\'children\'] as List;')); - }); - }); - - group('includeIfNull', () { - test('some', () async { - final output = await runForElementNamed('IncludeIfNullAll'); - expect(output, isNot(contains(generatedLocalVarName))); - expect(output, isNot(contains(toJsonMapHelperName))); - }); - }); -} - -class _ConfigLogger implements TypeHelper { - static final configurations = []; - - const _ConfigLogger(); - - @override - Object deserialize(DartType targetType, String expression, - TypeHelperContextWithConfig context) { - configurations.add(context.config); - return null; - } - - @override - Object serialize(DartType targetType, String expression, - TypeHelperContextWithConfig context) { - configurations.add(context.config); - return null; - } -} diff --git a/json_serializable/test/literal/json_literal_test.dart b/json_serializable/test/literal/json_literal_test.dart index 140aba3dc..d8d6c2643 100644 --- a/json_serializable/test/literal/json_literal_test.dart +++ b/json_serializable/test/literal/json_literal_test.dart @@ -3,19 +3,18 @@ // BSD-style license that can be found in the LICENSE file. @TestOn('vm') - import 'dart:convert'; import 'dart:io'; +import 'package:path/path.dart' as p; import 'package:test/test.dart'; -import '../test_file_utils.dart'; import '../test_utils.dart'; import 'json_literal.dart'; void main() { test('literal round-trip', () { - final dataFilePath = testFilePath('test', 'literal', 'json_literal.json'); + final dataFilePath = p.join('test', 'literal', 'json_literal.json'); final dataFile = File(dataFilePath); final dataString = loudEncode(json.decode(dataFile.readAsStringSync())); @@ -29,7 +28,7 @@ void main() { test('naughty strings', () { final dataFilePath = - testFilePath('test', 'literal', 'big-list-of-naughty-strings.json'); + p.join('test', 'literal', 'big-list-of-naughty-strings.json'); final dataFile = File(dataFilePath); final dataString = loudEncode(json.decode(dataFile.readAsStringSync())); diff --git a/json_serializable/test/src/_json_serializable_test_input.dart b/json_serializable/test/src/_json_serializable_test_input.dart index c423feb38..181abfdb2 100644 --- a/json_serializable/test/src/_json_serializable_test_input.dart +++ b/json_serializable/test/src/_json_serializable_test_input.dart @@ -2,15 +2,12 @@ // 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. -//ignore_for_file: avoid_unused_constructor_parameters - import 'dart:collection'; import 'package:json_annotation/json_annotation.dart'; import 'package:source_gen_test/annotations.dart'; part 'checked_test_input.dart'; -part 'configuration_input.dart'; part 'core_subclass_type_input.dart'; part 'default_value_input.dart'; part 'field_namer_input.dart'; @@ -162,44 +159,6 @@ class SetSupport { SetSupport(this.values); } -@JsonSerializable(createToJson: false) -class FromJsonOptionalParameters { - final ChildWithFromJson child; - - FromJsonOptionalParameters(this.child); -} - -class ChildWithFromJson { - ChildWithFromJson.fromJson(json, {initValue = false}); -} - -@JsonSerializable() -class ParentObject { - int number; - String str; - ChildObject child; -} - -@JsonSerializable() -class ChildObject { - int number; - String str; -} - -@JsonSerializable() -class ParentObjectWithChildren { - int number; - String str; - List children; -} - -@JsonSerializable() -class ParentObjectWithDynamicChildren { - int number; - String str; - List children; -} - @ShouldThrow( 'Could not generate `toJson` code for `watch`.\n' 'None of the provided `TypeHelper` instances support the defined type.', @@ -240,13 +199,6 @@ class NoDeserializeBadKey { Map intDateTimeMap; } -@JsonSerializable(createFactory: false) -class IncludeIfNullAll { - @JsonKey(includeIfNull: true) - int number; - String str; -} - @ShouldGenerate( r''' Map _$IncludeIfNullOverrideToJson( @@ -283,6 +235,7 @@ class IncludeIfNullOverride { class NoCtorClass { final int member; + //ignore: avoid_unused_constructor_parameters factory NoCtorClass.fromJson(Map json) => null; } @@ -372,18 +325,6 @@ class IncludeIfNullDisallowNullClass { int field; } -@JsonSerializable(createFactory: false, explicitToJson: true) -class TrivialNestedNullable { - TrivialNestedNullable child; - int otherField; -} - -@JsonSerializable(createFactory: false, nullable: false, explicitToJson: true) -class TrivialNestedNonNullable { - TrivialNestedNonNullable child; - int otherField; -} - @ShouldThrow( 'The `JsonValue` annotation on `BadEnum.value` does not have a value ' 'of type String, int, or null.', diff --git a/json_serializable/test/src/configuration_input.dart b/json_serializable/test/src/configuration_input.dart deleted file mode 100644 index 0765f3457..000000000 --- a/json_serializable/test/src/configuration_input.dart +++ /dev/null @@ -1,23 +0,0 @@ -part of '_json_serializable_test_input.dart'; - -@JsonSerializable() -class ConfigurationImplicitDefaults { - int field; -} - -@JsonSerializable( - anyMap: false, - checked: false, - createFactory: true, - createToJson: true, - disallowUnrecognizedKeys: false, - explicitToJson: false, - fieldRename: FieldRename.none, - generateToJsonFunction: true, - includeIfNull: true, - nullable: true, - useWrappers: false, -) -class ConfigurationExplicitDefaults { - int field; -} diff --git a/json_serializable/test/test_file_utils.dart b/json_serializable/test/test_file_utils.dart deleted file mode 100644 index f15fcf456..000000000 --- a/json_serializable/test/test_file_utils.dart +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (c) 2018, 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 'dart:mirrors'; - -import 'package:path/path.dart' as p; - -String testFilePath(String part1, [String part2, String part3]) => - p.join(_packagePath(), part1, part2, part3); - -String _packagePathCache; - -String _packagePath() { - if (_packagePathCache == null) { - // Getting the location of this file – via reflection - final currentFilePath = (reflect(_packagePath) as ClosureMirror) - .function - .location - .sourceUri - .path; - - _packagePathCache = p.normalize(p.join(p.dirname(currentFilePath), '..')); - } - return _packagePathCache; -} diff --git a/json_serializable/test/test_sources/test_sources.dart b/json_serializable/test/test_sources/test_sources.dart new file mode 100644 index 000000000..3d9f69293 --- /dev/null +++ b/json_serializable/test/test_sources/test_sources.dart @@ -0,0 +1,81 @@ +import 'package:json_annotation/json_annotation.dart'; + +@JsonSerializable() +class ConfigurationImplicitDefaults { + int field; +} + +@JsonSerializable( + anyMap: false, + checked: false, + createFactory: true, + createToJson: true, + disallowUnrecognizedKeys: false, + explicitToJson: false, + fieldRename: FieldRename.none, + generateToJsonFunction: true, + includeIfNull: true, + nullable: true, + useWrappers: false, +) +class ConfigurationExplicitDefaults { + int field; +} + +@JsonSerializable(createFactory: false) +class IncludeIfNullAll { + @JsonKey(includeIfNull: true) + int number; + String str; +} + +@JsonSerializable(createToJson: false) +class FromJsonOptionalParameters { + final ChildWithFromJson child; + + FromJsonOptionalParameters(this.child); +} + +class ChildWithFromJson { + //ignore: avoid_unused_constructor_parameters + ChildWithFromJson.fromJson(json, {initValue = false}); +} + +@JsonSerializable() +class ParentObject { + int number; + String str; + ChildObject child; +} + +@JsonSerializable() +class ChildObject { + int number; + String str; +} + +@JsonSerializable() +class ParentObjectWithChildren { + int number; + String str; + List children; +} + +@JsonSerializable() +class ParentObjectWithDynamicChildren { + int number; + String str; + List children; +} + +@JsonSerializable(createFactory: false, explicitToJson: true) +class TrivialNestedNullable { + TrivialNestedNullable child; + int otherField; +} + +@JsonSerializable(createFactory: false, nullable: false, explicitToJson: true) +class TrivialNestedNonNullable { + TrivialNestedNonNullable child; + int otherField; +} From 709410118cd1770932d184ef5f4a41e201c08380 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Fri, 8 Mar 2019 10:26:05 -0800 Subject: [PATCH 065/569] Fix to map conversion formatting (#403) --- json_serializable/CHANGELOG.md | 3 + .../lib/src/type_helpers/map_helper.dart | 2 +- .../default_value.checked.g.dart | 13 ++-- .../test/default_value/default_value.g.dart | 19 +++--- .../test/integration/json_test_example.g.dart | 13 ++-- .../json_test_example.non_nullable.g.dart | 15 +++-- ...n_test_example.non_nullable.wrapped.g.dart | 15 +++-- .../json_test_example.wrapped.g.dart | 13 ++-- .../test/kitchen_sink/kitchen_sink.g.dart | 66 +++++++++++++------ .../kitchen_sink.non_nullable.checked.g.dart | 39 ++++++----- .../kitchen_sink.non_nullable.g.dart | 41 +++++++----- .../kitchen_sink.non_nullable.wrapped.g.dart | 41 +++++++----- .../kitchen_sink/kitchen_sink.wrapped.g.dart | 66 +++++++++++++------ .../test/yaml/build_config.g.dart | 18 +++-- 14 files changed, 235 insertions(+), 129 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index b71154450..2efcf8402 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -8,6 +8,9 @@ before. It also allows implementations of these types to add a `fromJson` constructor 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.defaultValue` is set with other fields. diff --git a/json_serializable/lib/src/type_helpers/map_helper.dart b/json_serializable/lib/src/type_helpers/map_helper.dart index a4ca7366e..b2ac2e69c 100644 --- a/json_serializable/lib/src/type_helpers/map_helper.dart +++ b/json_serializable/lib/src/type_helpers/map_helper.dart @@ -109,7 +109,7 @@ class MapHelper extends TypeHelper { } return '($expression $mapCast)$optionalQuestion.map(' - '($_keyParam, $closureArg) => MapEntry($keyUsage, $itemSubVal))'; + '($_keyParam, $closureArg) => MapEntry($keyUsage, $itemSubVal),)'; } } diff --git a/json_serializable/test/default_value/default_value.checked.g.dart b/json_serializable/test/default_value/default_value.checked.g.dart index ba5d62143..ac148235c 100644 --- a/json_serializable/test/default_value/default_value.checked.g.dart +++ b/json_serializable/test/default_value/default_value.checked.g.dart @@ -28,14 +28,17 @@ DefaultValue _$DefaultValueFromJson(Map json) { $checkedConvert( json, 'fieldMapSimple', - (v) => val.fieldMapSimple = - (v as Map)?.map((k, e) => MapEntry(k as String, e as int)) ?? - {'answer': 42}); + (v) => val.fieldMapSimple = (v as Map)?.map( + (k, e) => MapEntry(k as String, e as int), + ) ?? + {'answer': 42}); $checkedConvert( json, 'fieldMapListString', - (v) => val.fieldMapListString = (v as Map)?.map((k, e) => MapEntry( - k as String, (e as List)?.map((e) => e as String)?.toList())) ?? + (v) => val.fieldMapListString = (v as Map)?.map( + (k, e) => MapEntry( + k as String, (e as List)?.map((e) => e as String)?.toList()), + ) ?? { 'root': ['child'] }); diff --git a/json_serializable/test/default_value/default_value.g.dart b/json_serializable/test/default_value/default_value.g.dart index 1d29b97fa..4c68ed43e 100644 --- a/json_serializable/test/default_value/default_value.g.dart +++ b/json_serializable/test/default_value/default_value.g.dart @@ -17,15 +17,18 @@ DefaultValue _$DefaultValueFromJson(Map json) { ..fieldListSimple = (json['fieldListSimple'] as List)?.map((e) => e as int)?.toList() ?? [1, 2, 3] - ..fieldMapSimple = (json['fieldMapSimple'] as Map) - ?.map((k, e) => MapEntry(k, e as int)) ?? + ..fieldMapSimple = (json['fieldMapSimple'] as Map)?.map( + (k, e) => MapEntry(k, e as int), + ) ?? {'answer': 42} - ..fieldMapListString = (json['fieldMapListString'] as Map) - ?.map((k, e) => - MapEntry(k, (e as List)?.map((e) => e as String)?.toList())) ?? - { - 'root': ['child'] - } + ..fieldMapListString = + (json['fieldMapListString'] as Map)?.map( + (k, e) => + MapEntry(k, (e as List)?.map((e) => e as String)?.toList()), + ) ?? + { + 'root': ['child'] + } ..fieldEnum = _$enumDecodeNullable(_$GreekEnumMap, json['fieldEnum']) ?? Greek.beta; } diff --git a/json_serializable/test/integration/json_test_example.g.dart b/json_serializable/test/integration/json_test_example.g.dart index a0296ba22..27ee513b7 100644 --- a/json_serializable/test/integration/json_test_example.g.dart +++ b/json_serializable/test/integration/json_test_example.g.dart @@ -22,11 +22,12 @@ Person _$PersonFromJson(Map json) { ?.map((e) => e == null ? null : Order.fromJson(e as Map)) ?.toList()) - ..houseMap = (json['houseMap'] as Map) - ?.map((k, e) => MapEntry(k, _$enumDecodeNullable(_$CategoryEnumMap, e))) + ..houseMap = (json['houseMap'] as Map)?.map( + (k, e) => MapEntry(k, _$enumDecodeNullable(_$CategoryEnumMap, e)), + ) ..categoryCounts = (json['categoryCounts'] as Map)?.map( - (k, e) => - MapEntry(_$enumDecodeNullable(_$CategoryEnumMap, k), e as int)); + (k, e) => MapEntry(_$enumDecodeNullable(_$CategoryEnumMap, k), e as int), + ); } Map _$PersonToJson(Person instance) => { @@ -88,8 +89,8 @@ Order _$OrderFromJson(Map json) { ? null : Platform.fromJson(json['platform'] as String) ..altPlatforms = (json['altPlatforms'] as Map)?.map( - (k, e) => - MapEntry(k, e == null ? null : Platform.fromJson(e as String))) + (k, e) => MapEntry(k, e == null ? null : Platform.fromJson(e as String)), + ) ..homepage = json['homepage'] == null ? null : Uri.parse(json['homepage'] as String) ..statusCode = diff --git a/json_serializable/test/integration/json_test_example.non_nullable.g.dart b/json_serializable/test/integration/json_test_example.non_nullable.g.dart index b958cb6ff..3e756ca4d 100644 --- a/json_serializable/test/integration/json_test_example.non_nullable.g.dart +++ b/json_serializable/test/integration/json_test_example.non_nullable.g.dart @@ -15,10 +15,12 @@ Person _$PersonFromJson(Map json) { ..customOrders = MyList.fromJson((json['customOrders'] as List) .map((e) => Order.fromJson(e as Map)) .toList()) - ..houseMap = (json['houseMap'] as Map) - .map((k, e) => MapEntry(k, _$enumDecode(_$CategoryEnumMap, e))) - ..categoryCounts = (json['categoryCounts'] as Map) - .map((k, e) => MapEntry(_$enumDecode(_$CategoryEnumMap, k), e as int)); + ..houseMap = (json['houseMap'] as Map).map( + (k, e) => MapEntry(k, _$enumDecode(_$CategoryEnumMap, e)), + ) + ..categoryCounts = (json['categoryCounts'] as Map).map( + (k, e) => MapEntry(_$enumDecode(_$CategoryEnumMap, k), e as int), + ); } Map _$PersonToJson(Person instance) => { @@ -68,8 +70,9 @@ Order _$OrderFromJson(Map json) { ..isRushed = json['isRushed'] as bool ..duration = Duration(microseconds: json['duration'] as int) ..platform = Platform.fromJson(json['platform'] as String) - ..altPlatforms = (json['altPlatforms'] as Map) - .map((k, e) => MapEntry(k, Platform.fromJson(e as String))) + ..altPlatforms = (json['altPlatforms'] as Map).map( + (k, e) => MapEntry(k, Platform.fromJson(e as String)), + ) ..homepage = Uri.parse(json['homepage'] as String) ..statusCode = _$enumDecodeNullable(_$StatusCodeEnumMap, json['status_code']) ?? diff --git a/json_serializable/test/integration/json_test_example.non_nullable.wrapped.g.dart b/json_serializable/test/integration/json_test_example.non_nullable.wrapped.g.dart index 4ac171a1c..d146f1d18 100644 --- a/json_serializable/test/integration/json_test_example.non_nullable.wrapped.g.dart +++ b/json_serializable/test/integration/json_test_example.non_nullable.wrapped.g.dart @@ -15,10 +15,12 @@ Person _$PersonFromJson(Map json) { ..customOrders = MyList.fromJson((json['customOrders'] as List) .map((e) => Order.fromJson(e as Map)) .toList()) - ..houseMap = (json['houseMap'] as Map) - .map((k, e) => MapEntry(k, _$enumDecode(_$CategoryEnumMap, e))) - ..categoryCounts = (json['categoryCounts'] as Map) - .map((k, e) => MapEntry(_$enumDecode(_$CategoryEnumMap, k), e as int)); + ..houseMap = (json['houseMap'] as Map).map( + (k, e) => MapEntry(k, _$enumDecode(_$CategoryEnumMap, e)), + ) + ..categoryCounts = (json['categoryCounts'] as Map).map( + (k, e) => MapEntry(_$enumDecode(_$CategoryEnumMap, k), e as int), + ); } Map _$PersonToJson(Person instance) => @@ -103,8 +105,9 @@ Order _$OrderFromJson(Map json) { ..isRushed = json['isRushed'] as bool ..duration = Duration(microseconds: json['duration'] as int) ..platform = Platform.fromJson(json['platform'] as String) - ..altPlatforms = (json['altPlatforms'] as Map) - .map((k, e) => MapEntry(k, Platform.fromJson(e as String))) + ..altPlatforms = (json['altPlatforms'] as Map).map( + (k, e) => MapEntry(k, Platform.fromJson(e as String)), + ) ..homepage = Uri.parse(json['homepage'] as String) ..statusCode = _$enumDecodeNullable(_$StatusCodeEnumMap, json['status_code']) ?? diff --git a/json_serializable/test/integration/json_test_example.wrapped.g.dart b/json_serializable/test/integration/json_test_example.wrapped.g.dart index c7533a657..8fb4dbdb4 100644 --- a/json_serializable/test/integration/json_test_example.wrapped.g.dart +++ b/json_serializable/test/integration/json_test_example.wrapped.g.dart @@ -22,11 +22,12 @@ Person _$PersonFromJson(Map json) { ?.map((e) => e == null ? null : Order.fromJson(e as Map)) ?.toList()) - ..houseMap = (json['houseMap'] as Map) - ?.map((k, e) => MapEntry(k, _$enumDecodeNullable(_$CategoryEnumMap, e))) + ..houseMap = (json['houseMap'] as Map)?.map( + (k, e) => MapEntry(k, _$enumDecodeNullable(_$CategoryEnumMap, e)), + ) ..categoryCounts = (json['categoryCounts'] as Map)?.map( - (k, e) => - MapEntry(_$enumDecodeNullable(_$CategoryEnumMap, k), e as int)); + (k, e) => MapEntry(_$enumDecodeNullable(_$CategoryEnumMap, k), e as int), + ); } Map _$PersonToJson(Person instance) => @@ -123,8 +124,8 @@ Order _$OrderFromJson(Map json) { ? null : Platform.fromJson(json['platform'] as String) ..altPlatforms = (json['altPlatforms'] as Map)?.map( - (k, e) => - MapEntry(k, e == null ? null : Platform.fromJson(e as String))) + (k, e) => MapEntry(k, e == null ? null : Platform.fromJson(e as String)), + ) ..homepage = json['homepage'] == null ? null : Uri.parse(json['homepage'] as String) ..statusCode = diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g.dart index 4fdfdc6e4..5d66f4db7 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g.dart @@ -33,23 +33,43 @@ KitchenSink _$KitchenSinkFromJson(Map json) { ?.map((e) => e == null ? null : DateTime.parse(e as String)) ?.toList() ..map = json['map'] as Map - ..stringStringMap = (json['stringStringMap'] as Map) - ?.map((k, e) => MapEntry(k as String, e as String)) - ..dynamicIntMap = - (json['dynamicIntMap'] as Map)?.map((k, e) => MapEntry(k, e as int)) + ..stringStringMap = (json['stringStringMap'] as Map)?.map( + (k, e) => MapEntry(k as String, e as String), + ) + ..dynamicIntMap = (json['dynamicIntMap'] as Map)?.map( + (k, e) => MapEntry(k, e as int), + ) ..objectDateTimeMap = (json['objectDateTimeMap'] as Map)?.map( - (k, e) => MapEntry(k, e == null ? null : DateTime.parse(e as String))) + (k, e) => MapEntry(k, e == null ? null : DateTime.parse(e as String)), + ) ..crazyComplex = (json['crazyComplex'] as List) - ?.map((e) => (e as Map)?.map((k, e) => MapEntry( - k as String, - (e as Map)?.map((k, e) => MapEntry(k as String, - (e as List)?.map((e) => (e as List)?.map((e) => e == null ? null : DateTime.parse(e as String))?.toList())?.toList()))))) + ?.map((e) => (e as Map)?.map( + (k, e) => MapEntry( + k as String, + (e as Map)?.map( + (k, e) => MapEntry( + k as String, + (e as List) + ?.map((e) => (e as List) + ?.map((e) => e == null + ? null + : DateTime.parse(e as String)) + ?.toList()) + ?.toList()), + )), + )) ?.toList() - ..val = (json['val'] as Map)?.map((k, e) => MapEntry(k as String, e as bool)) + ..val = (json['val'] as Map)?.map( + (k, e) => MapEntry(k as String, e as bool), + ) ..writeNotNull = json['writeNotNull'] as bool ..string = json[r'$string'] as String - ..simpleObject = json['simpleObject'] == null ? null : SimpleObject.fromJson(json['simpleObject'] as Map) - ..strictKeysObject = json['strictKeysObject'] == null ? null : StrictKeysObject.fromJson(json['strictKeysObject'] as Map) + ..simpleObject = json['simpleObject'] == null + ? null + : SimpleObject.fromJson(json['simpleObject'] as Map) + ..strictKeysObject = json['strictKeysObject'] == null + ? null + : StrictKeysObject.fromJson(json['strictKeysObject'] as Map) ..validatedPropertyNo42 = json['validatedPropertyNo42'] as int; } @@ -150,9 +170,13 @@ JsonConverterTestClass _$JsonConverterTestClassFromJson(Map json) { ..bigInt = json['bigInt'] == null ? null : const BigIntStringConverter().fromJson(json['bigInt'] as String) - ..bigIntMap = (json['bigIntMap'] as Map)?.map((k, e) => MapEntry( - k as String, - e == null ? null : const BigIntStringConverter().fromJson(e as String))) + ..bigIntMap = (json['bigIntMap'] as Map)?.map( + (k, e) => MapEntry( + k as String, + e == null + ? null + : const BigIntStringConverter().fromJson(e as String)), + ) ..numberSilly = json['numberSilly'] == null ? null : TrivialNumberConverter.instance.fromJson(json['numberSilly'] as int) @@ -209,11 +233,13 @@ JsonConverterGeneric _$JsonConverterGenericFromJson( ? null : GenericConverter().fromJson(e as Map)) ?.toList() - ..itemMap = (json['itemMap'] as Map)?.map((k, e) => MapEntry( - k as String, - e == null - ? null - : GenericConverter().fromJson(e as Map))); + ..itemMap = (json['itemMap'] as Map)?.map( + (k, e) => MapEntry( + k as String, + e == null + ? null + : GenericConverter().fromJson(e as Map)), + ); } abstract class _$JsonConverterGenericSerializerMixin { diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.checked.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.checked.g.dart index b5aedfe5c..e356b9abf 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.checked.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.checked.g.dart @@ -51,21 +51,26 @@ KitchenSink _$KitchenSinkFromJson(Map json) { $checkedConvert( json, 'objectDateTimeMap', - (v) => val.objectDateTimeMap = - (v as Map).map((k, e) => MapEntry(k, DateTime.parse(e as String)))); + (v) => val.objectDateTimeMap = (v as Map).map( + (k, e) => MapEntry(k, DateTime.parse(e as String)), + )); $checkedConvert( json, 'crazyComplex', (v) => val.crazyComplex = (v as List) - .map((e) => (e as Map).map((k, e) => MapEntry( - k as String, - (e as Map).map((k, e) => MapEntry( - k as String, - (e as List) - .map((e) => (e as List) - .map((e) => DateTime.parse(e as String)) - .toList()) - .toList()))))) + .map((e) => (e as Map).map( + (k, e) => MapEntry( + k as String, + (e as Map).map( + (k, e) => MapEntry( + k as String, + (e as List) + .map((e) => (e as List) + .map((e) => DateTime.parse(e as String)) + .toList()) + .toList()), + )), + )) .toList()); $checkedConvert( json, 'val', (v) => val.val = Map.from(v as Map)); @@ -175,8 +180,10 @@ JsonConverterTestClass _$JsonConverterTestClassFromJson(Map json) { $checkedConvert( json, 'bigIntMap', - (v) => val.bigIntMap = (v as Map).map((k, e) => MapEntry( - k as String, const BigIntStringConverter().fromJson(e as String)))); + (v) => val.bigIntMap = (v as Map).map( + (k, e) => MapEntry(k as String, + const BigIntStringConverter().fromJson(e as String)), + )); $checkedConvert( json, 'numberSilly', @@ -237,8 +244,10 @@ JsonConverterGeneric _$JsonConverterGenericFromJson( $checkedConvert( json, 'itemMap', - (v) => val.itemMap = (v as Map).map((k, e) => MapEntry(k as String, - GenericConverter().fromJson(e as Map)))); + (v) => val.itemMap = (v as Map).map( + (k, e) => MapEntry(k as String, + GenericConverter().fromJson(e as Map)), + )); return val; }); } diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.g.dart index 15dbad040..ffedbb951 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.g.dart @@ -33,23 +33,30 @@ KitchenSink _$KitchenSinkFromJson(Map json) { ..map = json['map'] as Map ..stringStringMap = Map.from(json['stringStringMap'] as Map) ..dynamicIntMap = Map.from(json['dynamicIntMap'] as Map) - ..objectDateTimeMap = (json['objectDateTimeMap'] as Map) - .map((k, e) => MapEntry(k, DateTime.parse(e as String))) + ..objectDateTimeMap = (json['objectDateTimeMap'] as Map).map( + (k, e) => MapEntry(k, DateTime.parse(e as String)), + ) ..crazyComplex = (json['crazyComplex'] as List) - .map((e) => (e as Map).map((k, e) => MapEntry( - k as String, - (e as Map).map((k, e) => MapEntry( - k as String, - (e as List) - .map((e) => - (e as List).map((e) => DateTime.parse(e as String)).toList()) - .toList()))))) + .map((e) => (e as Map).map( + (k, e) => MapEntry( + k as String, + (e as Map).map( + (k, e) => MapEntry( + k as String, + (e as List) + .map((e) => (e as List) + .map((e) => DateTime.parse(e as String)) + .toList()) + .toList()), + )), + )) .toList() ..val = Map.from(json['val'] as Map) ..writeNotNull = json['writeNotNull'] as bool ..string = json[r'$string'] as String ..simpleObject = SimpleObject.fromJson(json['simpleObject'] as Map) - ..strictKeysObject = StrictKeysObject.fromJson(json['strictKeysObject'] as Map) + ..strictKeysObject = + StrictKeysObject.fromJson(json['strictKeysObject'] as Map) ..validatedPropertyNo42 = json['validatedPropertyNo42'] as int; } @@ -131,8 +138,10 @@ JsonConverterTestClass _$JsonConverterTestClassFromJson(Map json) { .map((e) => durationConverter.fromJson(e as int)) .toList() ..bigInt = const BigIntStringConverter().fromJson(json['bigInt'] as String) - ..bigIntMap = (json['bigIntMap'] as Map).map((k, e) => MapEntry( - k as String, const BigIntStringConverter().fromJson(e as String))) + ..bigIntMap = (json['bigIntMap'] as Map).map( + (k, e) => MapEntry( + k as String, const BigIntStringConverter().fromJson(e as String)), + ) ..numberSilly = TrivialNumberConverter.instance.fromJson(json['numberSilly'] as int) ..numberSillySet = (json['numberSillySet'] as List) @@ -171,8 +180,10 @@ JsonConverterGeneric _$JsonConverterGenericFromJson( ..itemList = (json['itemList'] as List) .map((e) => GenericConverter().fromJson(e as Map)) .toList() - ..itemMap = (json['itemMap'] as Map).map((k, e) => MapEntry(k as String, - GenericConverter().fromJson(e as Map))); + ..itemMap = (json['itemMap'] as Map).map( + (k, e) => MapEntry(k as String, + GenericConverter().fromJson(e as Map)), + ); } abstract class _$JsonConverterGenericSerializerMixin { diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.wrapped.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.wrapped.g.dart index 322a45bf9..fccf2d05e 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.wrapped.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.wrapped.g.dart @@ -33,23 +33,30 @@ KitchenSink _$KitchenSinkFromJson(Map json) { ..map = json['map'] as Map ..stringStringMap = Map.from(json['stringStringMap'] as Map) ..dynamicIntMap = Map.from(json['dynamicIntMap'] as Map) - ..objectDateTimeMap = (json['objectDateTimeMap'] as Map) - .map((k, e) => MapEntry(k, DateTime.parse(e as String))) + ..objectDateTimeMap = (json['objectDateTimeMap'] as Map).map( + (k, e) => MapEntry(k, DateTime.parse(e as String)), + ) ..crazyComplex = (json['crazyComplex'] as List) - .map((e) => (e as Map).map((k, e) => MapEntry( - k as String, - (e as Map).map((k, e) => MapEntry( - k as String, - (e as List) - .map((e) => - (e as List).map((e) => DateTime.parse(e as String)).toList()) - .toList()))))) + .map((e) => (e as Map).map( + (k, e) => MapEntry( + k as String, + (e as Map).map( + (k, e) => MapEntry( + k as String, + (e as List) + .map((e) => (e as List) + .map((e) => DateTime.parse(e as String)) + .toList()) + .toList()), + )), + )) .toList() ..val = Map.from(json['val'] as Map) ..writeNotNull = json['writeNotNull'] as bool ..string = json[r'$string'] as String ..simpleObject = SimpleObject.fromJson(json['simpleObject'] as Map) - ..strictKeysObject = StrictKeysObject.fromJson(json['strictKeysObject'] as Map) + ..strictKeysObject = + StrictKeysObject.fromJson(json['strictKeysObject'] as Map) ..validatedPropertyNo42 = json['validatedPropertyNo42'] as int; } @@ -205,8 +212,10 @@ JsonConverterTestClass _$JsonConverterTestClassFromJson(Map json) { .map((e) => durationConverter.fromJson(e as int)) .toList() ..bigInt = const BigIntStringConverter().fromJson(json['bigInt'] as String) - ..bigIntMap = (json['bigIntMap'] as Map).map((k, e) => MapEntry( - k as String, const BigIntStringConverter().fromJson(e as String))) + ..bigIntMap = (json['bigIntMap'] as Map).map( + (k, e) => MapEntry( + k as String, const BigIntStringConverter().fromJson(e as String)), + ) ..numberSilly = TrivialNumberConverter.instance.fromJson(json['numberSilly'] as int) ..numberSillySet = (json['numberSillySet'] as List) @@ -277,8 +286,10 @@ JsonConverterGeneric _$JsonConverterGenericFromJson( ..itemList = (json['itemList'] as List) .map((e) => GenericConverter().fromJson(e as Map)) .toList() - ..itemMap = (json['itemMap'] as Map).map((k, e) => MapEntry(k as String, - GenericConverter().fromJson(e as Map))); + ..itemMap = (json['itemMap'] as Map).map( + (k, e) => MapEntry(k as String, + GenericConverter().fromJson(e as Map)), + ); } abstract class _$JsonConverterGenericSerializerMixin { diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.wrapped.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.wrapped.g.dart index 14e89ac09..4e3029618 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.wrapped.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.wrapped.g.dart @@ -33,23 +33,43 @@ KitchenSink _$KitchenSinkFromJson(Map json) { ?.map((e) => e == null ? null : DateTime.parse(e as String)) ?.toList() ..map = json['map'] as Map - ..stringStringMap = (json['stringStringMap'] as Map) - ?.map((k, e) => MapEntry(k as String, e as String)) - ..dynamicIntMap = - (json['dynamicIntMap'] as Map)?.map((k, e) => MapEntry(k, e as int)) + ..stringStringMap = (json['stringStringMap'] as Map)?.map( + (k, e) => MapEntry(k as String, e as String), + ) + ..dynamicIntMap = (json['dynamicIntMap'] as Map)?.map( + (k, e) => MapEntry(k, e as int), + ) ..objectDateTimeMap = (json['objectDateTimeMap'] as Map)?.map( - (k, e) => MapEntry(k, e == null ? null : DateTime.parse(e as String))) + (k, e) => MapEntry(k, e == null ? null : DateTime.parse(e as String)), + ) ..crazyComplex = (json['crazyComplex'] as List) - ?.map((e) => (e as Map)?.map((k, e) => MapEntry( - k as String, - (e as Map)?.map((k, e) => MapEntry(k as String, - (e as List)?.map((e) => (e as List)?.map((e) => e == null ? null : DateTime.parse(e as String))?.toList())?.toList()))))) + ?.map((e) => (e as Map)?.map( + (k, e) => MapEntry( + k as String, + (e as Map)?.map( + (k, e) => MapEntry( + k as String, + (e as List) + ?.map((e) => (e as List) + ?.map((e) => e == null + ? null + : DateTime.parse(e as String)) + ?.toList()) + ?.toList()), + )), + )) ?.toList() - ..val = (json['val'] as Map)?.map((k, e) => MapEntry(k as String, e as bool)) + ..val = (json['val'] as Map)?.map( + (k, e) => MapEntry(k as String, e as bool), + ) ..writeNotNull = json['writeNotNull'] as bool ..string = json[r'$string'] as String - ..simpleObject = json['simpleObject'] == null ? null : SimpleObject.fromJson(json['simpleObject'] as Map) - ..strictKeysObject = json['strictKeysObject'] == null ? null : StrictKeysObject.fromJson(json['strictKeysObject'] as Map) + ..simpleObject = json['simpleObject'] == null + ? null + : SimpleObject.fromJson(json['simpleObject'] as Map) + ..strictKeysObject = json['strictKeysObject'] == null + ? null + : StrictKeysObject.fromJson(json['strictKeysObject'] as Map) ..validatedPropertyNo42 = json['validatedPropertyNo42'] as int; } @@ -223,9 +243,13 @@ JsonConverterTestClass _$JsonConverterTestClassFromJson(Map json) { ..bigInt = json['bigInt'] == null ? null : const BigIntStringConverter().fromJson(json['bigInt'] as String) - ..bigIntMap = (json['bigIntMap'] as Map)?.map((k, e) => MapEntry( - k as String, - e == null ? null : const BigIntStringConverter().fromJson(e as String))) + ..bigIntMap = (json['bigIntMap'] as Map)?.map( + (k, e) => MapEntry( + k as String, + e == null + ? null + : const BigIntStringConverter().fromJson(e as String)), + ) ..numberSilly = json['numberSilly'] == null ? null : TrivialNumberConverter.instance.fromJson(json['numberSilly'] as int) @@ -315,11 +339,13 @@ JsonConverterGeneric _$JsonConverterGenericFromJson( ? null : GenericConverter().fromJson(e as Map)) ?.toList() - ..itemMap = (json['itemMap'] as Map)?.map((k, e) => MapEntry( - k as String, - e == null - ? null - : GenericConverter().fromJson(e as Map))); + ..itemMap = (json['itemMap'] as Map)?.map( + (k, e) => MapEntry( + k as String, + e == null + ? null + : GenericConverter().fromJson(e as Map)), + ); } abstract class _$JsonConverterGenericSerializerMixin { diff --git a/json_serializable/test/yaml/build_config.g.dart b/json_serializable/test/yaml/build_config.g.dart index 1396469aa..f4938333e 100644 --- a/json_serializable/test/yaml/build_config.g.dart +++ b/json_serializable/test/yaml/build_config.g.dart @@ -13,13 +13,17 @@ Config _$ConfigFromJson(Map json) { builders: $checkedConvert( json, 'builders', - (v) => (v as Map)?.map((k, e) => MapEntry( - k as String, e == null ? null : Builder.fromJson(e as Map))))); + (v) => (v as Map)?.map( + (k, e) => MapEntry(k as String, + e == null ? null : Builder.fromJson(e as Map)), + ))); $checkedConvert( json, 'weights', - (v) => val.weights = (v as Map)?.map((k, e) => - MapEntry(_$enumDecodeNullable(_$AutoApplyEnumMap, k), e as int))); + (v) => val.weights = (v as Map)?.map( + (k, e) => MapEntry( + _$enumDecodeNullable(_$AutoApplyEnumMap, k), e as int), + )); return val; }); } @@ -94,8 +98,10 @@ Builder _$BuilderFromJson(Map json) { buildExtensions: $checkedConvert( json, 'build_extensions', - (v) => (v as Map)?.map((k, e) => MapEntry( - k as String, (e as List)?.map((e) => e as String)?.toList()))), + (v) => (v as Map)?.map( + (k, e) => MapEntry(k as String, + (e as List)?.map((e) => e as String)?.toList()), + )), configLocation: $checkedConvert(json, 'configLocation', (v) => v == null ? null : Uri.parse(v as String))); return val; From f5b93a8b89a1c563d2b7b019ca462b0233fea040 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 11 Mar 2019 17:39:01 -0700 Subject: [PATCH 066/569] Prepare to release v2.0.3 (#404) --- json_serializable/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 03a20df86..1d1dda632 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 2.0.3-dev +version: 2.0.3 author: Dart Team description: >- Automatically generate code for converting to and from JSON by annotating From c97316933e104fb1cf5d34704d2a86405d00d13e Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 13 Mar 2019 13:15:08 -0700 Subject: [PATCH 067/569] Add unit test for mixin (generateToJsonFunction: false) flow (#405) --- .../test/json_serializable_test.dart | 4 +++ .../src/_json_serializable_test_input.dart | 36 +++++++++++++++++++ .../test/src/generic_test_input.dart | 33 +++++++++++++++++ 3 files changed, 73 insertions(+) diff --git a/json_serializable/test/json_serializable_test.dart b/json_serializable/test/json_serializable_test.dart index d008fc311..aee2d0d02 100644 --- a/json_serializable/test/json_serializable_test.dart +++ b/json_serializable/test/json_serializable_test.dart @@ -23,6 +23,8 @@ void main() async { 'wrapped': JsonSerializableGenerator( config: JsonSerializable(useWrappers: true), ), + 'mixin': JsonSerializableGenerator( + config: JsonSerializable(generateToJsonFunction: false)), }, expectedAnnotatedTests: _expectedAnnotatedTests, ); @@ -54,9 +56,11 @@ const _expectedAnnotatedTests = [ 'FinalFieldsNotSetInCtor', 'FromDynamicCollection', 'GeneralTestClass1', + 'GeneralTestClass1', 'GeneralTestClass2', 'GenericClass', 'GenericClass', + 'GenericClass', 'IgnoredFieldClass', 'IgnoredFieldCtorClass', 'IncludeIfNullDisallowNullClass', diff --git a/json_serializable/test/src/_json_serializable_test_input.dart b/json_serializable/test/src/_json_serializable_test_input.dart index 181abfdb2..ee5105af6 100644 --- a/json_serializable/test/src/_json_serializable_test_input.dart +++ b/json_serializable/test/src/_json_serializable_test_input.dart @@ -56,6 +56,42 @@ Map _$GeneralTestClass1ToJson(GeneralTestClass1 instance) => ''', configurations: ['default'], ) +@ShouldGenerate( + r''' +GeneralTestClass1 _$GeneralTestClass1FromJson(Map json) { + return GeneralTestClass1() + ..firstName = json['firstName'] as String + ..lastName = json['lastName'] as String + ..height = json['h'] as int + ..dateOfBirth = json['dateOfBirth'] == null + ? null + : DateTime.parse(json['dateOfBirth'] as String) + ..dynamicType = json['dynamicType'] + ..varType = json['varType'] + ..listOfInts = (json['listOfInts'] as List)?.map((e) => e as int)?.toList(); +} + +abstract class _$GeneralTestClass1SerializerMixin { + String get firstName; + String get lastName; + int get height; + DateTime get dateOfBirth; + dynamic get dynamicType; + dynamic get varType; + List get listOfInts; + Map toJson() => { + 'firstName': firstName, + 'lastName': lastName, + 'h': height, + 'dateOfBirth': dateOfBirth?.toIso8601String(), + 'dynamicType': dynamicType, + 'varType': varType, + 'listOfInts': listOfInts + }; +} +''', + configurations: ['mixin'], +) @JsonSerializable() class GeneralTestClass1 { String firstName, lastName; diff --git a/json_serializable/test/src/generic_test_input.dart b/json_serializable/test/src/generic_test_input.dart index 1a0364915..13df8eb3a 100644 --- a/json_serializable/test/src/generic_test_input.dart +++ b/json_serializable/test/src/generic_test_input.dart @@ -84,6 +84,39 @@ class _$GenericClassJsonMapWrapper extends $JsonMapWrapper { ''', configurations: ['wrapped'], ) +@ShouldGenerate( + r''' +GenericClass _$GenericClassFromJson( + Map json) { + return GenericClass() + ..fieldObject = + json['fieldObject'] == null ? null : _dataFromJson(json['fieldObject']) + ..fieldDynamic = json['fieldDynamic'] == null + ? null + : _dataFromJson(json['fieldDynamic']) + ..fieldInt = + json['fieldInt'] == null ? null : _dataFromJson(json['fieldInt']) + ..fieldT = json['fieldT'] == null ? null : _dataFromJson(json['fieldT']) + ..fieldS = json['fieldS'] == null ? null : _dataFromJson(json['fieldS']); +} + +abstract class _$GenericClassSerializerMixin { + Object get fieldObject; + dynamic get fieldDynamic; + int get fieldInt; + T get fieldT; + S get fieldS; + Map toJson() => { + 'fieldObject': fieldObject == null ? null : _dataToJson(fieldObject), + 'fieldDynamic': fieldDynamic == null ? null : _dataToJson(fieldDynamic), + 'fieldInt': fieldInt == null ? null : _dataToJson(fieldInt), + 'fieldT': fieldT == null ? null : _dataToJson(fieldT), + 'fieldS': fieldS == null ? null : _dataToJson(fieldS) + }; +} +''', + configurations: ['mixin'], +) @JsonSerializable() class GenericClass { @JsonKey(fromJson: _dataFromJson, toJson: _dataToJson) From 6a39a76ff8967de50db0f4b344181328269cf978 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 13 Mar 2019 13:23:58 -0700 Subject: [PATCH 068/569] prefer final locals (#406) --- analysis_options.yaml | 2 +- json_serializable/lib/src/json_key_utils.dart | 5 +++-- json_serializable/lib/src/type_helpers/json_helper.dart | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index 6e7d864e5..1e88b2d41 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -59,7 +59,7 @@ linter: - prefer_contains - prefer_equal_for_default_values - prefer_final_fields - #- prefer_final_locals + - prefer_final_locals - prefer_initializing_formals - prefer_interpolation_to_compose_strings - prefer_is_empty diff --git a/json_serializable/lib/src/json_key_utils.dart b/json_serializable/lib/src/json_key_utils.dart index 183c941f5..468c306a1 100644 --- a/json_serializable/lib/src/json_key_utils.dart +++ b/json_serializable/lib/src/json_key_utils.dart @@ -80,9 +80,10 @@ JsonKey _from(FieldElement element, JsonSerializable classAnnotation) { final enumFields = iterateEnumFields(defaultValueObject.type); if (enumFields != null) { - var enumValueNames = enumFields.map((p) => p.name).toList(growable: false); + final enumValueNames = + enumFields.map((p) => p.name).toList(growable: false); - var enumValueName = enumValueForDartObject( + final enumValueName = enumValueForDartObject( defaultValueObject, enumValueNames, (n) => n); defaultValueLiteral = '${defaultValueObject.type.name}.$enumValueName'; diff --git a/json_serializable/lib/src/type_helpers/json_helper.dart b/json_serializable/lib/src/type_helpers/json_helper.dart index 583997c7e..6f6bb42f7 100644 --- a/json_serializable/lib/src/type_helpers/json_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_helper.dart @@ -50,7 +50,7 @@ class JsonHelper extends TypeHelper { fromJsonCtor.parameters.singleWhere((pe) => pe.isPositional).type; if (asCastType is InterfaceType) { - var instantiated = _instantiate(asCastType as InterfaceType, type); + final instantiated = _instantiate(asCastType as InterfaceType, type); if (instantiated != null) { asCastType = instantiated; } @@ -97,7 +97,7 @@ bool _canSerialize(JsonSerializable config, DartType type) { /// derived by matching corresponding type parameters from [classType]. InterfaceType _instantiate( InterfaceType ctorParamType, InterfaceType classType) { - var argTypes = ctorParamType.typeArguments.map((arg) { + final argTypes = ctorParamType.typeArguments.map((arg) { final typeParamIndex = classType.typeParameters.indexWhere((e) => e.type == arg); if (typeParamIndex >= 0) { From 4f36261f5949678396cf3efdd44d97de10f4f7a6 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 13 Mar 2019 13:40:06 -0700 Subject: [PATCH 069/569] Unify testing around dev and oldest supported (2.0) (#407) --- .travis.yml | 50 +++++++++++++++------------------ example/mono_pkg.yaml | 28 +++++++++--------- json_annotation/mono_pkg.yaml | 19 +++++++++---- json_serializable/build.yaml | 40 +++++++++++++------------- json_serializable/mono_pkg.yaml | 34 +++++++++++----------- tool/travis.sh | 7 ++++- 6 files changed, 91 insertions(+), 87 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3bcc834af..94d8c7795 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,4 @@ -# Created with package:mono_repo v1.2.1 +# Created with package:mono_repo v1.2.2 language: dart # Custom configuration @@ -16,36 +16,41 @@ jobs: script: ./tool/travis.sh dartfmt dartanalyzer_0 env: PKG="example" dart: dev - - stage: analyzer_and_format_stable - name: "SDK: stable - DIR: example - TASKS: [dartfmt -n --set-exit-if-changed ., dartanalyzer --fatal-warnings .]" + - stage: analyzer_and_format + name: "SDK: 2.0.0 - DIR: example - TASKS: [dartfmt -n --set-exit-if-changed ., dartanalyzer --fatal-warnings .]" script: ./tool/travis.sh dartfmt dartanalyzer_1 env: PKG="example" - dart: stable + dart: "2.0.0" + - stage: unit_test + name: "SDK: 2.0.0 - DIR: example - TASKS: pub run test --run-skipped" + script: ./tool/travis.sh test_0 + env: PKG="example" + dart: "2.0.0" - stage: unit_test - name: "SDK: stable - DIR: example - TASKS: pub run test --run-skipped" + name: "SDK: dev - DIR: example - TASKS: pub run test --run-skipped" script: ./tool/travis.sh test_0 env: PKG="example" - dart: stable - - stage: analyzer_and_format_stable - name: "SDK: stable - DIR: json_annotation - TASKS: [dartfmt -n --set-exit-if-changed ., dartanalyzer --fatal-warnings .]" + dart: dev + - stage: analyzer_and_format + name: "SDK: dev - DIR: json_annotation - TASKS: [dartfmt -n --set-exit-if-changed ., dartanalyzer --fatal-warnings --fatal-infos .]" + script: ./tool/travis.sh dartfmt dartanalyzer_2 + env: PKG="json_annotation" + dart: dev + - stage: analyzer_and_format + name: "SDK: 2.0.0 - DIR: json_annotation - TASKS: [dartfmt -n --set-exit-if-changed ., dartanalyzer --fatal-warnings .]" script: ./tool/travis.sh dartfmt dartanalyzer_1 env: PKG="json_annotation" - dart: stable + dart: "2.0.0" - stage: analyzer_and_format name: "SDK: dev - DIR: json_serializable - TASKS: [dartfmt -n --set-exit-if-changed ., dartanalyzer --fatal-infos --fatal-warnings .]" script: ./tool/travis.sh dartfmt dartanalyzer_0 env: PKG="json_serializable" dart: dev - - stage: analyzer_and_format_stable - name: "SDK: stable - DIR: json_serializable - TASKS: [dartfmt -n --set-exit-if-changed ., dartanalyzer --fatal-warnings .]" + - stage: analyzer_and_format + name: "SDK: 2.0.0 - DIR: json_serializable - TASKS: [dartfmt -n --set-exit-if-changed ., dartanalyzer --fatal-warnings .]" script: ./tool/travis.sh dartfmt dartanalyzer_1 env: PKG="json_serializable" - dart: stable - - stage: unit_test - name: "SDK: stable - DIR: json_serializable - TASKS: pub run test" - script: ./tool/travis.sh test_1 - env: PKG="json_serializable" - dart: stable + dart: "2.0.0" - stage: unit_test name: "SDK: 2.0.0 - DIR: json_serializable - TASKS: pub run test" script: ./tool/travis.sh test_1 @@ -56,11 +61,6 @@ jobs: script: ./tool/travis.sh test_1 env: PKG="json_serializable" dart: dev - - stage: unit_test - name: "SDK: stable - DIR: json_serializable - TASKS: pub run test --run-skipped test/ensure_build_test.dart" - script: ./tool/travis.sh test_2 - env: PKG="json_serializable" - dart: stable - stage: unit_test name: "SDK: 2.0.0 - DIR: json_serializable - TASKS: pub run test --run-skipped test/ensure_build_test.dart" script: ./tool/travis.sh test_2 @@ -71,11 +71,6 @@ jobs: script: ./tool/travis.sh test_2 env: PKG="json_serializable" dart: dev - - stage: unit_test - name: "SDK: stable - DIR: json_serializable - TASKS: pub run build_runner test -- -p chrome" - script: ./tool/travis.sh command - env: PKG="json_serializable" - dart: stable - stage: unit_test name: "SDK: 2.0.0 - DIR: json_serializable - TASKS: pub run build_runner test -- -p chrome" script: ./tool/travis.sh command @@ -89,7 +84,6 @@ jobs: stages: - analyzer_and_format - - analyzer_and_format_stable - unit_test cache: diff --git a/example/mono_pkg.yaml b/example/mono_pkg.yaml index 2b5ea1a52..e2c823dc9 100644 --- a/example/mono_pkg.yaml +++ b/example/mono_pkg.yaml @@ -1,21 +1,21 @@ # See https://github.com/dart-lang/mono_repo for details dart: - - stable +- 2.0.0 +- dev stages: - - analyzer_and_format: - - group: - - dartfmt - - dartanalyzer: --fatal-infos --fatal-warnings . - dart: [dev] - - analyzer_and_format_stable: - - group: - - dartfmt - - dartanalyzer: --fatal-warnings . - dart: [stable] - - unit_test: - # Run the tests -- include the default-skipped presubmit tests - - test: --run-skipped +- analyzer_and_format: + - group: + - dartfmt + - dartanalyzer: --fatal-infos --fatal-warnings . + dart: [dev] + - group: + - dartfmt + - dartanalyzer: --fatal-warnings . + dart: [2.0.0] +- unit_test: + # Run the tests -- include the default-skipped presubmit tests + - test: --run-skipped cache: directories: diff --git a/json_annotation/mono_pkg.yaml b/json_annotation/mono_pkg.yaml index 27edaedf4..c35bde03c 100644 --- a/json_annotation/mono_pkg.yaml +++ b/json_annotation/mono_pkg.yaml @@ -1,10 +1,17 @@ # See https://github.com/dart-lang/mono_repo for details dart: - - stable +- dev +- 2.0.0 stages: - - analyzer_and_format_stable: - - group: - - dartfmt - - dartanalyzer: --fatal-warnings . - dart: [stable] +- analyzer_and_format: + - group: + - dartfmt + - dartanalyzer: --fatal-warnings --fatal-infos . + dart: [dev] + - group: + - dartfmt + - dartanalyzer: --fatal-warnings . + dart: [2.0.0] + + diff --git a/json_serializable/build.yaml b/json_serializable/build.yaml index c595b3afd..61e4461c4 100644 --- a/json_serializable/build.yaml +++ b/json_serializable/build.yaml @@ -6,19 +6,19 @@ targets: enabled: true generate_for: include: - - example/* - - test/default_value/* - - test/generic_files/* - - test/integration/* - - test/kitchen_sink/* - - test/literal/* - - test/yaml/* + - example/* + - test/default_value/* + - test/generic_files/* + - test/integration/* + - test/kitchen_sink/* + - test/literal/* + - test/yaml/* build_web_compilers|entrypoint: generate_for: - - test/default_value/** - - test/generic_files/*_test.dart - - test/integration/*_test.dart - - test/kitchen_sink/** + - test/default_value/** + - test/generic_files/*_test.dart + - test/integration/*_test.dart + - test/kitchen_sink/** builders: checked: @@ -30,8 +30,8 @@ builders: runs_before: ["json_serializable"] defaults: generate_for: - - test/default_value/default_value.dart - - test/kitchen_sink/kitchen_sink.non_nullable.dart + - test/default_value/default_value.dart + - test/kitchen_sink/kitchen_sink.non_nullable.dart non_null: import: 'tool/builder.dart' @@ -42,8 +42,8 @@ builders: runs_before: ["json_serializable"] defaults: generate_for: - - test/kitchen_sink/kitchen_sink.dart - - test/integration/json_test_example.dart + - test/kitchen_sink/kitchen_sink.dart + - test/integration/json_test_example.dart wrapped: import: 'tool/builder.dart' @@ -54,11 +54,11 @@ builders: runs_before: ["json_serializable"] defaults: generate_for: - - test/generic_files/generic_class.dart - - test/kitchen_sink/kitchen_sink.dart - - test/kitchen_sink/kitchen_sink.non_nullable.dart - - test/integration/json_test_example.dart - - test/integration/json_test_example.non_nullable.dart + - test/generic_files/generic_class.dart + - test/kitchen_sink/kitchen_sink.dart + - test/kitchen_sink/kitchen_sink.non_nullable.dart + - test/integration/json_test_example.dart + - test/integration/json_test_example.non_nullable.dart json_serializable: import: "package:json_serializable/builder.dart" diff --git a/json_serializable/mono_pkg.yaml b/json_serializable/mono_pkg.yaml index 86eb39b00..86528602e 100644 --- a/json_serializable/mono_pkg.yaml +++ b/json_serializable/mono_pkg.yaml @@ -1,25 +1,23 @@ # See https://github.com/dart-lang/mono_repo for details dart: - - stable - - 2.0.0 - - dev +- 2.0.0 +- dev stages: - - analyzer_and_format: - - group: - - dartfmt - - dartanalyzer: --fatal-infos --fatal-warnings . - dart: [dev] - - analyzer_and_format_stable: - - group: - - dartfmt - - dartanalyzer: --fatal-warnings . - dart: [stable] - - unit_test: - # Run the tests -- include the default-skipped presubmit tests - - test - - test: --run-skipped test/ensure_build_test.dart - - command: pub run build_runner test -- -p chrome +- analyzer_and_format: + - group: + - dartfmt + - dartanalyzer: --fatal-infos --fatal-warnings . + dart: [dev] + - group: + - dartfmt + - dartanalyzer: --fatal-warnings . + dart: [2.0.0] +- unit_test: + # Run the tests -- include the default-skipped presubmit tests + - test + - test: --run-skipped test/ensure_build_test.dart + - command: pub run build_runner test -- -p chrome cache: directories: diff --git a/tool/travis.sh b/tool/travis.sh index c2faca891..126bf5bf7 100755 --- a/tool/travis.sh +++ b/tool/travis.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Created with package:mono_repo v1.2.1 +# Created with package:mono_repo v1.2.2 if [ -z "$PKG" ]; then echo -e '\033[31mPKG environment variable must be set!\033[0m' @@ -34,6 +34,11 @@ while (( "$#" )); do echo -e 'dartanalyzer --fatal-warnings .' dartanalyzer --fatal-warnings . || EXIT_CODE=$? ;; + dartanalyzer_2) echo + echo -e '\033[1mTASK: dartanalyzer_2\033[22m' + echo -e 'dartanalyzer --fatal-warnings --fatal-infos .' + dartanalyzer --fatal-warnings --fatal-infos . || EXIT_CODE=$? + ;; dartfmt) echo echo -e '\033[1mTASK: dartfmt\033[22m' echo -e 'dartfmt -n --set-exit-if-changed .' From 7e229d9030e160613ac9215be2db4da52c80c5b4 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Fri, 8 Mar 2019 11:04:04 -0800 Subject: [PATCH 070/569] test: move KitchenSink to just use test functions --- .../test/kitchen_sink/kitchen_sink.dart | 19 +- .../test/kitchen_sink/kitchen_sink.g.dart | 213 ++++++++---------- .../kitchen_sink.non_nullable.checked.dart | 19 +- .../kitchen_sink.non_nullable.checked.g.dart | 168 ++++++-------- .../kitchen_sink.non_nullable.dart | 19 +- .../kitchen_sink.non_nullable.g.dart | 168 ++++++-------- .../kitchen_sink.non_nullable.wrapped.dart | 19 +- .../kitchen_sink.non_nullable.wrapped.g.dart | 62 +---- .../kitchen_sink/kitchen_sink.wrapped.dart | 19 +- .../kitchen_sink/kitchen_sink.wrapped.g.dart | 62 +---- 10 files changed, 289 insertions(+), 479 deletions(-) diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.dart b/json_serializable/test/kitchen_sink/kitchen_sink.dart index e7e01f590..501aa10d0 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.dart @@ -39,11 +39,8 @@ k.KitchenSink testFromJson(Map json) => KitchenSink.fromJson(json); @JsonSerializable( anyMap: true, - generateToJsonFunction: false, ) -class KitchenSink extends Object - with _$KitchenSinkSerializerMixin - implements k.KitchenSink { +class KitchenSink implements k.KitchenSink { // To ensure static members are not considered for serialization. static const answer = 42; static final reason = 42; @@ -80,6 +77,8 @@ class KitchenSink extends Object factory KitchenSink.fromJson(Map json) => _$KitchenSinkFromJson(json); + Map toJson() => _$KitchenSinkToJson(this); + @JsonKey(includeIfNull: false) DateTime dateTime; @@ -141,7 +140,6 @@ class KitchenSink extends Object @JsonSerializable( anyMap: true, - generateToJsonFunction: false, ) // referencing a top-level field should work @durationConverter @@ -149,13 +147,14 @@ class KitchenSink extends Object @BigIntStringConverter() @TrivialNumberConverter.instance @EpochDateTimeConverter() -class JsonConverterTestClass extends Object - with _$JsonConverterTestClassSerializerMixin { +class JsonConverterTestClass { JsonConverterTestClass(); factory JsonConverterTestClass.fromJson(Map json) => _$JsonConverterTestClassFromJson(json); + Map toJson() => _$JsonConverterTestClassToJson(this); + Duration duration; List durationList; @@ -170,11 +169,9 @@ class JsonConverterTestClass extends Object @JsonSerializable( anyMap: true, - generateToJsonFunction: false, ) @GenericConverter() -class JsonConverterGeneric extends Object - with _$JsonConverterGenericSerializerMixin { +class JsonConverterGeneric { S item; List itemList; Map itemMap; @@ -183,4 +180,6 @@ class JsonConverterGeneric extends Object factory JsonConverterGeneric.fromJson(Map json) => _$JsonConverterGenericFromJson(json); + + Map toJson() => _$JsonConverterGenericToJson(this); } diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g.dart index 5d66f4db7..0a2be4caf 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g.dart @@ -73,90 +73,60 @@ KitchenSink _$KitchenSinkFromJson(Map json) { ..validatedPropertyNo42 = json['validatedPropertyNo42'] as int; } -abstract class _$KitchenSinkSerializerMixin { - int get ctorValidatedNo42; - DateTime get dateTime; - Iterable get iterable; - Iterable get dynamicIterable; - Iterable get objectIterable; - Iterable get intIterable; - Set get set; - Set get dynamicSet; - Set get objectSet; - Set get intSet; - Set get dateTimeSet; - Iterable get dateTimeIterable; - List get list; - List get dynamicList; - List get objectList; - List get intList; - List get dateTimeList; - Map get map; - Map get stringStringMap; - Map get dynamicIntMap; - Map get objectDateTimeMap; - List>>>> get crazyComplex; - Map get val; - bool get writeNotNull; - String get string; - SimpleObject get simpleObject; - StrictKeysObject get strictKeysObject; - int get validatedPropertyNo42; - Map toJson() { - final val = { - 'no-42': ctorValidatedNo42, - }; +Map _$KitchenSinkToJson(KitchenSink instance) { + final val = { + 'no-42': instance.ctorValidatedNo42, + }; - void writeNotNull(String key, dynamic value) { - if (value != null) { - val[key] = value; - } + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; } - - writeNotNull('dateTime', dateTime?.toIso8601String()); - writeNotNull('iterable', iterable?.toList()); - val['dynamicIterable'] = dynamicIterable?.toList(); - val['objectIterable'] = objectIterable?.toList(); - val['intIterable'] = intIterable?.toList(); - val['set'] = set?.toList(); - val['dynamicSet'] = dynamicSet?.toList(); - val['objectSet'] = objectSet?.toList(); - val['intSet'] = intSet?.toList(); - val['dateTimeSet'] = - dateTimeSet?.map((e) => e?.toIso8601String())?.toList(); - val['datetime-iterable'] = - dateTimeIterable?.map((e) => e?.toIso8601String())?.toList(); - val['list'] = list; - val['dynamicList'] = dynamicList; - val['objectList'] = objectList; - val['intList'] = intList; - writeNotNull('dateTimeList', - dateTimeList?.map((e) => e?.toIso8601String())?.toList()); - val['map'] = map; - val['stringStringMap'] = stringStringMap; - val['dynamicIntMap'] = dynamicIntMap; - val['objectDateTimeMap'] = - objectDateTimeMap?.map((k, e) => MapEntry(k, e?.toIso8601String())); - writeNotNull( - 'crazyComplex', - crazyComplex - ?.map((e) => e?.map((k, e) => MapEntry( - k, - e?.map((k, e) => MapEntry( - k, - e - ?.map((e) => - e?.map((e) => e?.toIso8601String())?.toList()) - ?.toList()))))) - ?.toList()); - writeNotNull('val', this.val); - val['writeNotNull'] = this.writeNotNull; - val[r'$string'] = string; - val['simpleObject'] = simpleObject; - val['strictKeysObject'] = strictKeysObject; - val['validatedPropertyNo42'] = validatedPropertyNo42; - return val; } + + writeNotNull('dateTime', instance.dateTime?.toIso8601String()); + writeNotNull('iterable', instance.iterable?.toList()); + val['dynamicIterable'] = instance.dynamicIterable?.toList(); + val['objectIterable'] = instance.objectIterable?.toList(); + val['intIterable'] = instance.intIterable?.toList(); + val['set'] = instance.set?.toList(); + val['dynamicSet'] = instance.dynamicSet?.toList(); + val['objectSet'] = instance.objectSet?.toList(); + val['intSet'] = instance.intSet?.toList(); + val['dateTimeSet'] = + instance.dateTimeSet?.map((e) => e?.toIso8601String())?.toList(); + val['datetime-iterable'] = + instance.dateTimeIterable?.map((e) => e?.toIso8601String())?.toList(); + val['list'] = instance.list; + val['dynamicList'] = instance.dynamicList; + val['objectList'] = instance.objectList; + val['intList'] = instance.intList; + writeNotNull('dateTimeList', + instance.dateTimeList?.map((e) => e?.toIso8601String())?.toList()); + val['map'] = instance.map; + val['stringStringMap'] = instance.stringStringMap; + val['dynamicIntMap'] = instance.dynamicIntMap; + val['objectDateTimeMap'] = instance.objectDateTimeMap + ?.map((k, e) => MapEntry(k, e?.toIso8601String())); + writeNotNull( + 'crazyComplex', + instance.crazyComplex + ?.map((e) => e?.map((k, e) => MapEntry( + k, + e?.map((k, e) => MapEntry( + k, + e + ?.map( + (e) => e?.map((e) => e?.toIso8601String())?.toList()) + ?.toList()))))) + ?.toList()); + writeNotNull('val', instance.val); + val['writeNotNull'] = instance.writeNotNull; + val[r'$string'] = instance.string; + val['simpleObject'] = instance.simpleObject; + val['strictKeysObject'] = instance.strictKeysObject; + val['validatedPropertyNo42'] = instance.validatedPropertyNo42; + return val; } JsonConverterTestClass _$JsonConverterTestClassFromJson(Map json) { @@ -190,37 +160,31 @@ JsonConverterTestClass _$JsonConverterTestClassFromJson(Map json) { : const EpochDateTimeConverter().fromJson(json['dateTime'] as int); } -abstract class _$JsonConverterTestClassSerializerMixin { - Duration get duration; - List get durationList; - BigInt get bigInt; - Map get bigIntMap; - TrivialNumber get numberSilly; - Set get numberSillySet; - DateTime get dateTime; - Map toJson() => { - 'duration': - duration == null ? null : durationConverter.toJson(duration), - 'durationList': durationList - ?.map((e) => e == null ? null : durationConverter.toJson(e)) - ?.toList(), - 'bigInt': bigInt == null - ? null - : const BigIntStringConverter().toJson(bigInt), - 'bigIntMap': bigIntMap?.map((k, e) => MapEntry( - k, e == null ? null : const BigIntStringConverter().toJson(e))), - 'numberSilly': numberSilly == null - ? null - : TrivialNumberConverter.instance.toJson(numberSilly), - 'numberSillySet': numberSillySet - ?.map((e) => - e == null ? null : TrivialNumberConverter.instance.toJson(e)) - ?.toList(), - 'dateTime': dateTime == null - ? null - : const EpochDateTimeConverter().toJson(dateTime) - }; -} +Map _$JsonConverterTestClassToJson( + JsonConverterTestClass instance) => + { + 'duration': instance.duration == null + ? null + : durationConverter.toJson(instance.duration), + 'durationList': instance.durationList + ?.map((e) => e == null ? null : durationConverter.toJson(e)) + ?.toList(), + 'bigInt': instance.bigInt == null + ? null + : const BigIntStringConverter().toJson(instance.bigInt), + 'bigIntMap': instance.bigIntMap?.map((k, e) => MapEntry( + k, e == null ? null : const BigIntStringConverter().toJson(e))), + 'numberSilly': instance.numberSilly == null + ? null + : TrivialNumberConverter.instance.toJson(instance.numberSilly), + 'numberSillySet': instance.numberSillySet + ?.map((e) => + e == null ? null : TrivialNumberConverter.instance.toJson(e)) + ?.toList(), + 'dateTime': instance.dateTime == null + ? null + : const EpochDateTimeConverter().toJson(instance.dateTime) + }; JsonConverterGeneric _$JsonConverterGenericFromJson( Map json) { @@ -242,16 +206,15 @@ JsonConverterGeneric _$JsonConverterGenericFromJson( ); } -abstract class _$JsonConverterGenericSerializerMixin { - S get item; - List get itemList; - Map get itemMap; - Map toJson() => { - 'item': item == null ? null : GenericConverter().toJson(item), - 'itemList': itemList - ?.map((e) => e == null ? null : GenericConverter().toJson(e)) - ?.toList(), - 'itemMap': itemMap?.map((k, e) => - MapEntry(k, e == null ? null : GenericConverter().toJson(e))) - }; -} +Map _$JsonConverterGenericToJson( + JsonConverterGeneric instance) => + { + 'item': instance.item == null + ? null + : GenericConverter().toJson(instance.item), + 'itemList': instance.itemList + ?.map((e) => e == null ? null : GenericConverter().toJson(e)) + ?.toList(), + 'itemMap': instance.itemMap?.map((k, e) => + MapEntry(k, e == null ? null : GenericConverter().toJson(e))) + }; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.checked.dart b/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.checked.dart index 82a8180b1..d8ce2282b 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.checked.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.checked.dart @@ -53,11 +53,8 @@ k.KitchenSink testFromJson(Map json) => KitchenSink.fromJson(json); checked: true, nullable: false, anyMap: true, - generateToJsonFunction: false, ) -class KitchenSink extends Object - with _$KitchenSinkSerializerMixin - implements k.KitchenSink { +class KitchenSink implements k.KitchenSink { // To ensure static members are not considered for serialization. static const answer = 42; static final reason = 42; @@ -94,6 +91,8 @@ class KitchenSink extends Object factory KitchenSink.fromJson(Map json) => _$KitchenSinkFromJson(json); + Map toJson() => _$KitchenSinkToJson(this); + @JsonKey(includeIfNull: false) DateTime dateTime = DateTime(1981, 6, 5); @@ -157,7 +156,6 @@ class KitchenSink extends Object checked: true, nullable: false, anyMap: true, - generateToJsonFunction: false, ) // referencing a top-level field should work @durationConverter @@ -165,13 +163,14 @@ class KitchenSink extends Object @BigIntStringConverter() @TrivialNumberConverter.instance @EpochDateTimeConverter() -class JsonConverterTestClass extends Object - with _$JsonConverterTestClassSerializerMixin { +class JsonConverterTestClass { JsonConverterTestClass(); factory JsonConverterTestClass.fromJson(Map json) => _$JsonConverterTestClassFromJson(json); + Map toJson() => _$JsonConverterTestClassToJson(this); + Duration duration; List durationList; @@ -188,11 +187,9 @@ class JsonConverterTestClass extends Object checked: true, nullable: false, anyMap: true, - generateToJsonFunction: false, ) @GenericConverter() -class JsonConverterGeneric extends Object - with _$JsonConverterGenericSerializerMixin { +class JsonConverterGeneric { S item; List itemList; Map itemMap; @@ -201,4 +198,6 @@ class JsonConverterGeneric extends Object factory JsonConverterGeneric.fromJson(Map json) => _$JsonConverterGenericFromJson(json); + + Map toJson() => _$JsonConverterGenericToJson(this); } diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.checked.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.checked.g.dart index e356b9abf..74267cf53 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.checked.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.checked.g.dart @@ -90,76 +90,49 @@ KitchenSink _$KitchenSinkFromJson(Map json) { }); } -abstract class _$KitchenSinkSerializerMixin { - int get ctorValidatedNo42; - DateTime get dateTime; - Iterable get iterable; - Iterable get dynamicIterable; - Iterable get objectIterable; - Iterable get intIterable; - Set get set; - Set get dynamicSet; - Set get objectSet; - Set get intSet; - Set get dateTimeSet; - Iterable get dateTimeIterable; - List get list; - List get dynamicList; - List get objectList; - List get intList; - List get dateTimeList; - Map get map; - Map get stringStringMap; - Map get dynamicIntMap; - Map get objectDateTimeMap; - List>>>> get crazyComplex; - Map get val; - bool get writeNotNull; - String get string; - SimpleObject get simpleObject; - StrictKeysObject get strictKeysObject; - int get validatedPropertyNo42; - Map toJson() => { - 'no-42': ctorValidatedNo42, - 'dateTime': dateTime.toIso8601String(), - 'iterable': iterable.toList(), - 'dynamicIterable': dynamicIterable.toList(), - 'objectIterable': objectIterable.toList(), - 'intIterable': intIterable.toList(), - 'set': set.toList(), - 'dynamicSet': dynamicSet.toList(), - 'objectSet': objectSet.toList(), - 'intSet': intSet.toList(), - 'dateTimeSet': dateTimeSet.map((e) => e.toIso8601String()).toList(), - 'datetime-iterable': - dateTimeIterable.map((e) => e.toIso8601String()).toList(), - 'list': list, - 'dynamicList': dynamicList, - 'objectList': objectList, - 'intList': intList, - 'dateTimeList': dateTimeList.map((e) => e.toIso8601String()).toList(), - 'map': map, - 'stringStringMap': stringStringMap, - 'dynamicIntMap': dynamicIntMap, - 'objectDateTimeMap': - objectDateTimeMap.map((k, e) => MapEntry(k, e.toIso8601String())), - 'crazyComplex': crazyComplex - .map((e) => e.map((k, e) => MapEntry( - k, - e.map((k, e) => MapEntry( - k, - e - .map((e) => e.map((e) => e.toIso8601String()).toList()) - .toList()))))) - .toList(), - 'val': val, - 'writeNotNull': writeNotNull, - r'$string': string, - 'simpleObject': simpleObject, - 'strictKeysObject': strictKeysObject, - 'validatedPropertyNo42': validatedPropertyNo42 - }; -} +Map _$KitchenSinkToJson(KitchenSink instance) => + { + 'no-42': instance.ctorValidatedNo42, + 'dateTime': instance.dateTime.toIso8601String(), + 'iterable': instance.iterable.toList(), + 'dynamicIterable': instance.dynamicIterable.toList(), + 'objectIterable': instance.objectIterable.toList(), + 'intIterable': instance.intIterable.toList(), + 'set': instance.set.toList(), + 'dynamicSet': instance.dynamicSet.toList(), + 'objectSet': instance.objectSet.toList(), + 'intSet': instance.intSet.toList(), + 'dateTimeSet': + instance.dateTimeSet.map((e) => e.toIso8601String()).toList(), + 'datetime-iterable': + instance.dateTimeIterable.map((e) => e.toIso8601String()).toList(), + 'list': instance.list, + 'dynamicList': instance.dynamicList, + 'objectList': instance.objectList, + 'intList': instance.intList, + 'dateTimeList': + instance.dateTimeList.map((e) => e.toIso8601String()).toList(), + 'map': instance.map, + 'stringStringMap': instance.stringStringMap, + 'dynamicIntMap': instance.dynamicIntMap, + 'objectDateTimeMap': instance.objectDateTimeMap + .map((k, e) => MapEntry(k, e.toIso8601String())), + 'crazyComplex': instance.crazyComplex + .map((e) => e.map((k, e) => MapEntry( + k, + e.map((k, e) => MapEntry( + k, + e + .map((e) => e.map((e) => e.toIso8601String()).toList()) + .toList()))))) + .toList(), + 'val': instance.val, + 'writeNotNull': instance.writeNotNull, + r'$string': instance.string, + 'simpleObject': instance.simpleObject, + 'strictKeysObject': instance.strictKeysObject, + 'validatedPropertyNo42': instance.validatedPropertyNo42 + }; JsonConverterTestClass _$JsonConverterTestClassFromJson(Map json) { return $checkedNew('JsonConverterTestClass', json, () { @@ -204,26 +177,22 @@ JsonConverterTestClass _$JsonConverterTestClassFromJson(Map json) { }); } -abstract class _$JsonConverterTestClassSerializerMixin { - Duration get duration; - List get durationList; - BigInt get bigInt; - Map get bigIntMap; - TrivialNumber get numberSilly; - Set get numberSillySet; - DateTime get dateTime; - Map toJson() => { - 'duration': durationConverter.toJson(duration), - 'durationList': durationList.map(durationConverter.toJson).toList(), - 'bigInt': const BigIntStringConverter().toJson(bigInt), - 'bigIntMap': bigIntMap.map( - (k, e) => MapEntry(k, const BigIntStringConverter().toJson(e))), - 'numberSilly': TrivialNumberConverter.instance.toJson(numberSilly), - 'numberSillySet': - numberSillySet.map(TrivialNumberConverter.instance.toJson).toList(), - 'dateTime': const EpochDateTimeConverter().toJson(dateTime) - }; -} +Map _$JsonConverterTestClassToJson( + JsonConverterTestClass instance) => + { + 'duration': durationConverter.toJson(instance.duration), + 'durationList': + instance.durationList.map(durationConverter.toJson).toList(), + 'bigInt': const BigIntStringConverter().toJson(instance.bigInt), + 'bigIntMap': instance.bigIntMap + .map((k, e) => MapEntry(k, const BigIntStringConverter().toJson(e))), + 'numberSilly': + TrivialNumberConverter.instance.toJson(instance.numberSilly), + 'numberSillySet': instance.numberSillySet + .map(TrivialNumberConverter.instance.toJson) + .toList(), + 'dateTime': const EpochDateTimeConverter().toJson(instance.dateTime) + }; JsonConverterGeneric _$JsonConverterGenericFromJson( Map json) { @@ -252,14 +221,11 @@ JsonConverterGeneric _$JsonConverterGenericFromJson( }); } -abstract class _$JsonConverterGenericSerializerMixin { - S get item; - List get itemList; - Map get itemMap; - Map toJson() => { - 'item': GenericConverter().toJson(item), - 'itemList': itemList.map(GenericConverter().toJson).toList(), - 'itemMap': - itemMap.map((k, e) => MapEntry(k, GenericConverter().toJson(e))) - }; -} +Map _$JsonConverterGenericToJson( + JsonConverterGeneric instance) => + { + 'item': GenericConverter().toJson(instance.item), + 'itemList': instance.itemList.map(GenericConverter().toJson).toList(), + 'itemMap': instance.itemMap + .map((k, e) => MapEntry(k, GenericConverter().toJson(e))) + }; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.dart b/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.dart index a8ace5ef1..f39f560d9 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.dart @@ -46,11 +46,8 @@ k.KitchenSink testFromJson(Map json) => KitchenSink.fromJson(json); @JsonSerializable( nullable: false, anyMap: true, - generateToJsonFunction: false, ) -class KitchenSink extends Object - with _$KitchenSinkSerializerMixin - implements k.KitchenSink { +class KitchenSink implements k.KitchenSink { // To ensure static members are not considered for serialization. static const answer = 42; static final reason = 42; @@ -87,6 +84,8 @@ class KitchenSink extends Object factory KitchenSink.fromJson(Map json) => _$KitchenSinkFromJson(json); + Map toJson() => _$KitchenSinkToJson(this); + @JsonKey(includeIfNull: false) DateTime dateTime = DateTime(1981, 6, 5); @@ -149,7 +148,6 @@ class KitchenSink extends Object @JsonSerializable( nullable: false, anyMap: true, - generateToJsonFunction: false, ) // referencing a top-level field should work @durationConverter @@ -157,13 +155,14 @@ class KitchenSink extends Object @BigIntStringConverter() @TrivialNumberConverter.instance @EpochDateTimeConverter() -class JsonConverterTestClass extends Object - with _$JsonConverterTestClassSerializerMixin { +class JsonConverterTestClass { JsonConverterTestClass(); factory JsonConverterTestClass.fromJson(Map json) => _$JsonConverterTestClassFromJson(json); + Map toJson() => _$JsonConverterTestClassToJson(this); + Duration duration; List durationList; @@ -179,11 +178,9 @@ class JsonConverterTestClass extends Object @JsonSerializable( nullable: false, anyMap: true, - generateToJsonFunction: false, ) @GenericConverter() -class JsonConverterGeneric extends Object - with _$JsonConverterGenericSerializerMixin { +class JsonConverterGeneric { S item; List itemList; Map itemMap; @@ -192,4 +189,6 @@ class JsonConverterGeneric extends Object factory JsonConverterGeneric.fromJson(Map json) => _$JsonConverterGenericFromJson(json); + + Map toJson() => _$JsonConverterGenericToJson(this); } diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.g.dart index ffedbb951..aefffe998 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.g.dart @@ -60,76 +60,49 @@ KitchenSink _$KitchenSinkFromJson(Map json) { ..validatedPropertyNo42 = json['validatedPropertyNo42'] as int; } -abstract class _$KitchenSinkSerializerMixin { - int get ctorValidatedNo42; - DateTime get dateTime; - Iterable get iterable; - Iterable get dynamicIterable; - Iterable get objectIterable; - Iterable get intIterable; - Set get set; - Set get dynamicSet; - Set get objectSet; - Set get intSet; - Set get dateTimeSet; - Iterable get dateTimeIterable; - List get list; - List get dynamicList; - List get objectList; - List get intList; - List get dateTimeList; - Map get map; - Map get stringStringMap; - Map get dynamicIntMap; - Map get objectDateTimeMap; - List>>>> get crazyComplex; - Map get val; - bool get writeNotNull; - String get string; - SimpleObject get simpleObject; - StrictKeysObject get strictKeysObject; - int get validatedPropertyNo42; - Map toJson() => { - 'no-42': ctorValidatedNo42, - 'dateTime': dateTime.toIso8601String(), - 'iterable': iterable.toList(), - 'dynamicIterable': dynamicIterable.toList(), - 'objectIterable': objectIterable.toList(), - 'intIterable': intIterable.toList(), - 'set': set.toList(), - 'dynamicSet': dynamicSet.toList(), - 'objectSet': objectSet.toList(), - 'intSet': intSet.toList(), - 'dateTimeSet': dateTimeSet.map((e) => e.toIso8601String()).toList(), - 'datetime-iterable': - dateTimeIterable.map((e) => e.toIso8601String()).toList(), - 'list': list, - 'dynamicList': dynamicList, - 'objectList': objectList, - 'intList': intList, - 'dateTimeList': dateTimeList.map((e) => e.toIso8601String()).toList(), - 'map': map, - 'stringStringMap': stringStringMap, - 'dynamicIntMap': dynamicIntMap, - 'objectDateTimeMap': - objectDateTimeMap.map((k, e) => MapEntry(k, e.toIso8601String())), - 'crazyComplex': crazyComplex - .map((e) => e.map((k, e) => MapEntry( - k, - e.map((k, e) => MapEntry( - k, - e - .map((e) => e.map((e) => e.toIso8601String()).toList()) - .toList()))))) - .toList(), - 'val': val, - 'writeNotNull': writeNotNull, - r'$string': string, - 'simpleObject': simpleObject, - 'strictKeysObject': strictKeysObject, - 'validatedPropertyNo42': validatedPropertyNo42 - }; -} +Map _$KitchenSinkToJson(KitchenSink instance) => + { + 'no-42': instance.ctorValidatedNo42, + 'dateTime': instance.dateTime.toIso8601String(), + 'iterable': instance.iterable.toList(), + 'dynamicIterable': instance.dynamicIterable.toList(), + 'objectIterable': instance.objectIterable.toList(), + 'intIterable': instance.intIterable.toList(), + 'set': instance.set.toList(), + 'dynamicSet': instance.dynamicSet.toList(), + 'objectSet': instance.objectSet.toList(), + 'intSet': instance.intSet.toList(), + 'dateTimeSet': + instance.dateTimeSet.map((e) => e.toIso8601String()).toList(), + 'datetime-iterable': + instance.dateTimeIterable.map((e) => e.toIso8601String()).toList(), + 'list': instance.list, + 'dynamicList': instance.dynamicList, + 'objectList': instance.objectList, + 'intList': instance.intList, + 'dateTimeList': + instance.dateTimeList.map((e) => e.toIso8601String()).toList(), + 'map': instance.map, + 'stringStringMap': instance.stringStringMap, + 'dynamicIntMap': instance.dynamicIntMap, + 'objectDateTimeMap': instance.objectDateTimeMap + .map((k, e) => MapEntry(k, e.toIso8601String())), + 'crazyComplex': instance.crazyComplex + .map((e) => e.map((k, e) => MapEntry( + k, + e.map((k, e) => MapEntry( + k, + e + .map((e) => e.map((e) => e.toIso8601String()).toList()) + .toList()))))) + .toList(), + 'val': instance.val, + 'writeNotNull': instance.writeNotNull, + r'$string': instance.string, + 'simpleObject': instance.simpleObject, + 'strictKeysObject': instance.strictKeysObject, + 'validatedPropertyNo42': instance.validatedPropertyNo42 + }; JsonConverterTestClass _$JsonConverterTestClassFromJson(Map json) { return JsonConverterTestClass() @@ -151,26 +124,22 @@ JsonConverterTestClass _$JsonConverterTestClassFromJson(Map json) { const EpochDateTimeConverter().fromJson(json['dateTime'] as int); } -abstract class _$JsonConverterTestClassSerializerMixin { - Duration get duration; - List get durationList; - BigInt get bigInt; - Map get bigIntMap; - TrivialNumber get numberSilly; - Set get numberSillySet; - DateTime get dateTime; - Map toJson() => { - 'duration': durationConverter.toJson(duration), - 'durationList': durationList.map(durationConverter.toJson).toList(), - 'bigInt': const BigIntStringConverter().toJson(bigInt), - 'bigIntMap': bigIntMap.map( - (k, e) => MapEntry(k, const BigIntStringConverter().toJson(e))), - 'numberSilly': TrivialNumberConverter.instance.toJson(numberSilly), - 'numberSillySet': - numberSillySet.map(TrivialNumberConverter.instance.toJson).toList(), - 'dateTime': const EpochDateTimeConverter().toJson(dateTime) - }; -} +Map _$JsonConverterTestClassToJson( + JsonConverterTestClass instance) => + { + 'duration': durationConverter.toJson(instance.duration), + 'durationList': + instance.durationList.map(durationConverter.toJson).toList(), + 'bigInt': const BigIntStringConverter().toJson(instance.bigInt), + 'bigIntMap': instance.bigIntMap + .map((k, e) => MapEntry(k, const BigIntStringConverter().toJson(e))), + 'numberSilly': + TrivialNumberConverter.instance.toJson(instance.numberSilly), + 'numberSillySet': instance.numberSillySet + .map(TrivialNumberConverter.instance.toJson) + .toList(), + 'dateTime': const EpochDateTimeConverter().toJson(instance.dateTime) + }; JsonConverterGeneric _$JsonConverterGenericFromJson( Map json) { @@ -186,14 +155,11 @@ JsonConverterGeneric _$JsonConverterGenericFromJson( ); } -abstract class _$JsonConverterGenericSerializerMixin { - S get item; - List get itemList; - Map get itemMap; - Map toJson() => { - 'item': GenericConverter().toJson(item), - 'itemList': itemList.map(GenericConverter().toJson).toList(), - 'itemMap': - itemMap.map((k, e) => MapEntry(k, GenericConverter().toJson(e))) - }; -} +Map _$JsonConverterGenericToJson( + JsonConverterGeneric instance) => + { + 'item': GenericConverter().toJson(instance.item), + 'itemList': instance.itemList.map(GenericConverter().toJson).toList(), + 'itemMap': instance.itemMap + .map((k, e) => MapEntry(k, GenericConverter().toJson(e))) + }; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.wrapped.dart b/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.wrapped.dart index 6e39dd7bf..2dc36ef2b 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.wrapped.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.wrapped.dart @@ -53,11 +53,8 @@ k.KitchenSink testFromJson(Map json) => KitchenSink.fromJson(json); useWrappers: true, nullable: false, anyMap: true, - generateToJsonFunction: false, ) -class KitchenSink extends Object - with _$KitchenSinkSerializerMixin - implements k.KitchenSink { +class KitchenSink implements k.KitchenSink { // To ensure static members are not considered for serialization. static const answer = 42; static final reason = 42; @@ -94,6 +91,8 @@ class KitchenSink extends Object factory KitchenSink.fromJson(Map json) => _$KitchenSinkFromJson(json); + Map toJson() => _$KitchenSinkToJson(this); + @JsonKey(includeIfNull: false) DateTime dateTime = DateTime(1981, 6, 5); @@ -157,7 +156,6 @@ class KitchenSink extends Object useWrappers: true, nullable: false, anyMap: true, - generateToJsonFunction: false, ) // referencing a top-level field should work @durationConverter @@ -165,13 +163,14 @@ class KitchenSink extends Object @BigIntStringConverter() @TrivialNumberConverter.instance @EpochDateTimeConverter() -class JsonConverterTestClass extends Object - with _$JsonConverterTestClassSerializerMixin { +class JsonConverterTestClass { JsonConverterTestClass(); factory JsonConverterTestClass.fromJson(Map json) => _$JsonConverterTestClassFromJson(json); + Map toJson() => _$JsonConverterTestClassToJson(this); + Duration duration; List durationList; @@ -188,11 +187,9 @@ class JsonConverterTestClass extends Object useWrappers: true, nullable: false, anyMap: true, - generateToJsonFunction: false, ) @GenericConverter() -class JsonConverterGeneric extends Object - with _$JsonConverterGenericSerializerMixin { +class JsonConverterGeneric { S item; List itemList; Map itemMap; @@ -201,4 +198,6 @@ class JsonConverterGeneric extends Object factory JsonConverterGeneric.fromJson(Map json) => _$JsonConverterGenericFromJson(json); + + Map toJson() => _$JsonConverterGenericToJson(this); } diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.wrapped.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.wrapped.g.dart index fccf2d05e..abb876aab 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.wrapped.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.wrapped.g.dart @@ -60,40 +60,11 @@ KitchenSink _$KitchenSinkFromJson(Map json) { ..validatedPropertyNo42 = json['validatedPropertyNo42'] as int; } -abstract class _$KitchenSinkSerializerMixin { - int get ctorValidatedNo42; - DateTime get dateTime; - Iterable get iterable; - Iterable get dynamicIterable; - Iterable get objectIterable; - Iterable get intIterable; - Set get set; - Set get dynamicSet; - Set get objectSet; - Set get intSet; - Set get dateTimeSet; - Iterable get dateTimeIterable; - List get list; - List get dynamicList; - List get objectList; - List get intList; - List get dateTimeList; - Map get map; - Map get stringStringMap; - Map get dynamicIntMap; - Map get objectDateTimeMap; - List>>>> get crazyComplex; - Map get val; - bool get writeNotNull; - String get string; - SimpleObject get simpleObject; - StrictKeysObject get strictKeysObject; - int get validatedPropertyNo42; - Map toJson() => _$KitchenSinkJsonMapWrapper(this); -} +Map _$KitchenSinkToJson(KitchenSink instance) => + _$KitchenSinkJsonMapWrapper(instance); class _$KitchenSinkJsonMapWrapper extends $JsonMapWrapper { - final _$KitchenSinkSerializerMixin _v; + final KitchenSink _v; _$KitchenSinkJsonMapWrapper(this._v); @override @@ -225,19 +196,12 @@ JsonConverterTestClass _$JsonConverterTestClassFromJson(Map json) { const EpochDateTimeConverter().fromJson(json['dateTime'] as int); } -abstract class _$JsonConverterTestClassSerializerMixin { - Duration get duration; - List get durationList; - BigInt get bigInt; - Map get bigIntMap; - TrivialNumber get numberSilly; - Set get numberSillySet; - DateTime get dateTime; - Map toJson() => _$JsonConverterTestClassJsonMapWrapper(this); -} +Map _$JsonConverterTestClassToJson( + JsonConverterTestClass instance) => + _$JsonConverterTestClassJsonMapWrapper(instance); class _$JsonConverterTestClassJsonMapWrapper extends $JsonMapWrapper { - final _$JsonConverterTestClassSerializerMixin _v; + final JsonConverterTestClass _v; _$JsonConverterTestClassJsonMapWrapper(this._v); @override @@ -292,16 +256,12 @@ JsonConverterGeneric _$JsonConverterGenericFromJson( ); } -abstract class _$JsonConverterGenericSerializerMixin { - S get item; - List get itemList; - Map get itemMap; - Map toJson() => - _$JsonConverterGenericJsonMapWrapper(this); -} +Map _$JsonConverterGenericToJson( + JsonConverterGeneric instance) => + _$JsonConverterGenericJsonMapWrapper(instance); class _$JsonConverterGenericJsonMapWrapper extends $JsonMapWrapper { - final _$JsonConverterGenericSerializerMixin _v; + final JsonConverterGeneric _v; _$JsonConverterGenericJsonMapWrapper(this._v); @override diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.wrapped.dart b/json_serializable/test/kitchen_sink/kitchen_sink.wrapped.dart index 02c3976ab..a7f3f8e6e 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.wrapped.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.wrapped.dart @@ -46,11 +46,8 @@ k.KitchenSink testFromJson(Map json) => KitchenSink.fromJson(json); @JsonSerializable( useWrappers: true, anyMap: true, - generateToJsonFunction: false, ) -class KitchenSink extends Object - with _$KitchenSinkSerializerMixin - implements k.KitchenSink { +class KitchenSink implements k.KitchenSink { // To ensure static members are not considered for serialization. static const answer = 42; static final reason = 42; @@ -87,6 +84,8 @@ class KitchenSink extends Object factory KitchenSink.fromJson(Map json) => _$KitchenSinkFromJson(json); + Map toJson() => _$KitchenSinkToJson(this); + @JsonKey(includeIfNull: false) DateTime dateTime; @@ -149,7 +148,6 @@ class KitchenSink extends Object @JsonSerializable( useWrappers: true, anyMap: true, - generateToJsonFunction: false, ) // referencing a top-level field should work @durationConverter @@ -157,13 +155,14 @@ class KitchenSink extends Object @BigIntStringConverter() @TrivialNumberConverter.instance @EpochDateTimeConverter() -class JsonConverterTestClass extends Object - with _$JsonConverterTestClassSerializerMixin { +class JsonConverterTestClass { JsonConverterTestClass(); factory JsonConverterTestClass.fromJson(Map json) => _$JsonConverterTestClassFromJson(json); + Map toJson() => _$JsonConverterTestClassToJson(this); + Duration duration; List durationList; @@ -179,11 +178,9 @@ class JsonConverterTestClass extends Object @JsonSerializable( useWrappers: true, anyMap: true, - generateToJsonFunction: false, ) @GenericConverter() -class JsonConverterGeneric extends Object - with _$JsonConverterGenericSerializerMixin { +class JsonConverterGeneric { S item; List itemList; Map itemMap; @@ -192,4 +189,6 @@ class JsonConverterGeneric extends Object factory JsonConverterGeneric.fromJson(Map json) => _$JsonConverterGenericFromJson(json); + + Map toJson() => _$JsonConverterGenericToJson(this); } diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.wrapped.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.wrapped.g.dart index 4e3029618..cd277bce9 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.wrapped.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.wrapped.g.dart @@ -73,40 +73,11 @@ KitchenSink _$KitchenSinkFromJson(Map json) { ..validatedPropertyNo42 = json['validatedPropertyNo42'] as int; } -abstract class _$KitchenSinkSerializerMixin { - int get ctorValidatedNo42; - DateTime get dateTime; - Iterable get iterable; - Iterable get dynamicIterable; - Iterable get objectIterable; - Iterable get intIterable; - Set get set; - Set get dynamicSet; - Set get objectSet; - Set get intSet; - Set get dateTimeSet; - Iterable get dateTimeIterable; - List get list; - List get dynamicList; - List get objectList; - List get intList; - List get dateTimeList; - Map get map; - Map get stringStringMap; - Map get dynamicIntMap; - Map get objectDateTimeMap; - List>>>> get crazyComplex; - Map get val; - bool get writeNotNull; - String get string; - SimpleObject get simpleObject; - StrictKeysObject get strictKeysObject; - int get validatedPropertyNo42; - Map toJson() => _$KitchenSinkJsonMapWrapper(this); -} +Map _$KitchenSinkToJson(KitchenSink instance) => + _$KitchenSinkJsonMapWrapper(instance); class _$KitchenSinkJsonMapWrapper extends $JsonMapWrapper { - final _$KitchenSinkSerializerMixin _v; + final KitchenSink _v; _$KitchenSinkJsonMapWrapper(this._v); @override @@ -263,19 +234,12 @@ JsonConverterTestClass _$JsonConverterTestClassFromJson(Map json) { : const EpochDateTimeConverter().fromJson(json['dateTime'] as int); } -abstract class _$JsonConverterTestClassSerializerMixin { - Duration get duration; - List get durationList; - BigInt get bigInt; - Map get bigIntMap; - TrivialNumber get numberSilly; - Set get numberSillySet; - DateTime get dateTime; - Map toJson() => _$JsonConverterTestClassJsonMapWrapper(this); -} +Map _$JsonConverterTestClassToJson( + JsonConverterTestClass instance) => + _$JsonConverterTestClassJsonMapWrapper(instance); class _$JsonConverterTestClassJsonMapWrapper extends $JsonMapWrapper { - final _$JsonConverterTestClassSerializerMixin _v; + final JsonConverterTestClass _v; _$JsonConverterTestClassJsonMapWrapper(this._v); @override @@ -348,16 +312,12 @@ JsonConverterGeneric _$JsonConverterGenericFromJson( ); } -abstract class _$JsonConverterGenericSerializerMixin { - S get item; - List get itemList; - Map get itemMap; - Map toJson() => - _$JsonConverterGenericJsonMapWrapper(this); -} +Map _$JsonConverterGenericToJson( + JsonConverterGeneric instance) => + _$JsonConverterGenericJsonMapWrapper(instance); class _$JsonConverterGenericJsonMapWrapper extends $JsonMapWrapper { - final _$JsonConverterGenericSerializerMixin _v; + final JsonConverterGeneric _v; _$JsonConverterGenericJsonMapWrapper(this._v); @override From 25bb371af5d30f8c7f064bc29bd1906f2bb3ec4e Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 13 Mar 2019 12:51:27 -0700 Subject: [PATCH 071/569] Move to a Builder for generating test cases Much easier to extend and maintain --- json_serializable/build.yaml | 57 ++-- json_serializable/pubspec.yaml | 1 + ... => default_value.g_any_map__checked.dart} | 10 +- ...> default_value.g_any_map__checked.g.dart} | 2 +- .../default_value/default_value_test.dart | 2 +- ...dart => generic_class.g_use_wrappers.dart} | 8 +- ...rt => generic_class.g_use_wrappers.g.dart} | 2 +- ... => json_test_example.g_non_nullable.dart} | 8 +- ...> json_test_example.g_non_nullable.g.dart} | 2 +- ...example.g_non_nullable__use_wrappers.dart} | 12 +- ...ample.g_non_nullable__use_wrappers.g.dart} | 2 +- ... => json_test_example.g_use_wrappers.dart} | 18 +- ...> json_test_example.g_use_wrappers.g.dart} | 2 +- .../test/kitchen_sink/kitchen_sink.dart | 18 +- .../test/kitchen_sink/kitchen_sink.g.dart | 43 +-- .../kitchen_sink/kitchen_sink.g_any_map.dart | 185 +++++++++++++ .../kitchen_sink.g_any_map.g.dart | 220 ++++++++++++++++ ...ink.g_any_map__checked__non_nullable.dart} | 11 +- ...k.g_any_map__checked__non_nullable.g.dart} | 2 +- ...kitchen_sink.g_any_map__non_nullable.dart} | 17 +- ...tchen_sink.g_any_map__non_nullable.g.dart} | 2 +- ..._any_map__non_nullable__use_wrappers.dart} | 14 +- ...ny_map__non_nullable__use_wrappers.g.dart} | 2 +- ...kitchen_sink.g_any_map__use_wrappers.dart} | 8 +- ...tchen_sink.g_any_map__use_wrappers.g.dart} | 2 +- .../test/kitchen_sink/kitchen_sink_test.dart | 11 +- json_serializable/tool/builder.dart | 245 ++++++++++++------ 27 files changed, 661 insertions(+), 245 deletions(-) rename json_serializable/test/default_value/{default_value.checked.dart => default_value.g_any_map__checked.dart} (85%) rename json_serializable/test/default_value/{default_value.checked.g.dart => default_value.g_any_map__checked.g.dart} (98%) rename json_serializable/test/generic_files/{generic_class.wrapped.dart => generic_class.g_use_wrappers.dart} (91%) rename json_serializable/test/generic_files/{generic_class.wrapped.g.dart => generic_class.g_use_wrappers.g.dart} (99%) rename json_serializable/test/integration/{json_test_example.non_nullable.dart => json_test_example.g_non_nullable.dart} (93%) rename json_serializable/test/integration/{json_test_example.non_nullable.g.dart => json_test_example.g_non_nullable.g.dart} (99%) rename json_serializable/test/integration/{json_test_example.wrapped.dart => json_test_example.g_non_nullable__use_wrappers.dart} (93%) rename json_serializable/test/integration/{json_test_example.non_nullable.wrapped.g.dart => json_test_example.g_non_nullable__use_wrappers.g.dart} (99%) rename json_serializable/test/integration/{json_test_example.non_nullable.wrapped.dart => json_test_example.g_use_wrappers.dart} (87%) rename json_serializable/test/integration/{json_test_example.wrapped.g.dart => json_test_example.g_use_wrappers.g.dart} (99%) create mode 100644 json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart create mode 100644 json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart rename json_serializable/test/kitchen_sink/{kitchen_sink.non_nullable.dart => kitchen_sink.g_any_map__checked__non_nullable.dart} (95%) rename json_serializable/test/kitchen_sink/{kitchen_sink.non_nullable.checked.g.dart => kitchen_sink.g_any_map__checked__non_nullable.g.dart} (99%) rename json_serializable/test/kitchen_sink/{kitchen_sink.non_nullable.checked.dart => kitchen_sink.g_any_map__non_nullable.dart} (91%) rename json_serializable/test/kitchen_sink/{kitchen_sink.non_nullable.g.dart => kitchen_sink.g_any_map__non_nullable.g.dart} (99%) rename json_serializable/test/kitchen_sink/{kitchen_sink.non_nullable.wrapped.dart => kitchen_sink.g_any_map__non_nullable__use_wrappers.dart} (92%) rename json_serializable/test/kitchen_sink/{kitchen_sink.non_nullable.wrapped.g.dart => kitchen_sink.g_any_map__non_nullable__use_wrappers.g.dart} (99%) rename json_serializable/test/kitchen_sink/{kitchen_sink.wrapped.dart => kitchen_sink.g_any_map__use_wrappers.dart} (95%) rename json_serializable/test/kitchen_sink/{kitchen_sink.wrapped.g.dart => kitchen_sink.g_any_map__use_wrappers.g.dart} (99%) diff --git a/json_serializable/build.yaml b/json_serializable/build.yaml index 61e4461c4..8995f6072 100644 --- a/json_serializable/build.yaml +++ b/json_serializable/build.yaml @@ -20,45 +20,32 @@ targets: - test/integration/*_test.dart - test/kitchen_sink/** -builders: - checked: - import: 'tool/builder.dart' - builder_factories: ['checked'] - build_extensions: {".dart": [".checked.dart"]} - auto_apply: root_package - build_to: source - runs_before: ["json_serializable"] - defaults: - generate_for: - - test/default_value/default_value.dart - - test/kitchen_sink/kitchen_sink.non_nullable.dart - - non_null: - import: 'tool/builder.dart' - builder_factories: ['nonNull'] - build_extensions: {".dart": [".non_nullable.dart"]} - auto_apply: root_package - build_to: source - runs_before: ["json_serializable"] - defaults: - generate_for: - - test/kitchen_sink/kitchen_sink.dart - - test/integration/json_test_example.dart + json_serializable|_internal: + generate_for: + - test/default_value/default_value.dart + - test/kitchen_sink/kitchen_sink.dart + - test/integration/json_test_example.dart + - test/generic_files/generic_class.dart + - test/integration/json_test_example.dart + - test/integration/json_test_example.non_nullable.dart - wrapped: +builders: + _internal: import: 'tool/builder.dart' - builder_factories: ['wrapped'] - build_extensions: {".dart": [".wrapped.dart"]} - auto_apply: root_package + builder_factories: ['internal'] + build_extensions: + .dart: + - .g_non_nullable.dart + - .g_use_wrappers.dart + - .g_non_nullable__use_wrappers.dart + - .g_any_map.dart + - .g_any_map__non_nullable.dart + - .g_any_map__use_wrappers.dart + - .g_any_map__non_nullable__use_wrappers.dart + - .g_any_map__checked.dart + - .g_any_map__checked__non_nullable.dart build_to: source runs_before: ["json_serializable"] - defaults: - generate_for: - - test/generic_files/generic_class.dart - - test/kitchen_sink/kitchen_sink.dart - - test/kitchen_sink/kitchen_sink.non_nullable.dart - - test/integration/json_test_example.dart - - test/integration/json_test_example.non_nullable.dart json_serializable: import: "package:json_serializable/builder.dart" diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 1d1dda632..d061e5c7b 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -25,6 +25,7 @@ dev_dependencies: build_verify: ^1.1.0 build_web_compilers: ^1.0.0 collection: ^1.14.0 + dart_style: ^1.2.0 logging: ^0.11.3+1 source_gen_test: ^0.1.0 test: ^1.3.3 diff --git a/json_serializable/test/default_value/default_value.checked.dart b/json_serializable/test/default_value/default_value.g_any_map__checked.dart similarity index 85% rename from json_serializable/test/default_value/default_value.checked.dart rename to json_serializable/test/default_value/default_value.g_any_map__checked.dart index 00ce1cbd7..7bd6dd8cd 100644 --- a/json_serializable/test/default_value/default_value.checked.dart +++ b/json_serializable/test/default_value/default_value.g_any_map__checked.dart @@ -2,12 +2,6 @@ // 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. -// GENERATED CODE - DO NOT MODIFY BY HAND - -// ************************************************************************** -// _CheckedGenerator -// ************************************************************************** - // ignore_for_file: annotate_overrides import 'package:json_annotation/json_annotation.dart'; @@ -15,7 +9,7 @@ import 'package:json_annotation/json_annotation.dart'; import 'default_value_interface.dart' as dvi hide Greek; import 'default_value_interface.dart' show Greek; -part 'default_value.checked.g.dart'; +part 'default_value.g_any_map__checked.g.dart'; const _intValue = 42; @@ -23,8 +17,8 @@ dvi.DefaultValue fromJson(Map json) => _$DefaultValueFromJson(json); @JsonSerializable( - anyMap: true, checked: true, + anyMap: true, ) class DefaultValue implements dvi.DefaultValue { @JsonKey(defaultValue: true) diff --git a/json_serializable/test/default_value/default_value.checked.g.dart b/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart similarity index 98% rename from json_serializable/test/default_value/default_value.checked.g.dart rename to json_serializable/test/default_value/default_value.g_any_map__checked.g.dart index ac148235c..f0496f4cb 100644 --- a/json_serializable/test/default_value/default_value.checked.g.dart +++ b/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -part of 'default_value.checked.dart'; +part of 'default_value.g_any_map__checked.dart'; // ************************************************************************** // JsonSerializableGenerator diff --git a/json_serializable/test/default_value/default_value_test.dart b/json_serializable/test/default_value/default_value_test.dart index 1a3641b82..64bdf46ed 100644 --- a/json_serializable/test/default_value/default_value_test.dart +++ b/json_serializable/test/default_value/default_value_test.dart @@ -5,8 +5,8 @@ import 'package:test/test.dart'; import '../test_utils.dart'; -import 'default_value.checked.dart' as checked; import 'default_value.dart' as normal; +import 'default_value.g_any_map__checked.dart' as checked; import 'default_value_interface.dart'; const _defaultInstance = { diff --git a/json_serializable/test/generic_files/generic_class.wrapped.dart b/json_serializable/test/generic_files/generic_class.g_use_wrappers.dart similarity index 91% rename from json_serializable/test/generic_files/generic_class.wrapped.dart rename to json_serializable/test/generic_files/generic_class.g_use_wrappers.dart index 4709e5103..bc0a04374 100644 --- a/json_serializable/test/generic_files/generic_class.wrapped.dart +++ b/json_serializable/test/generic_files/generic_class.g_use_wrappers.dart @@ -2,15 +2,9 @@ // 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. -// GENERATED CODE - DO NOT MODIFY BY HAND - -// ************************************************************************** -// _WrappedGenerator -// ************************************************************************** - import 'package:json_annotation/json_annotation.dart'; -part 'generic_class.wrapped.g.dart'; +part 'generic_class.g_use_wrappers.g.dart'; @JsonSerializable( useWrappers: true, diff --git a/json_serializable/test/generic_files/generic_class.wrapped.g.dart b/json_serializable/test/generic_files/generic_class.g_use_wrappers.g.dart similarity index 99% rename from json_serializable/test/generic_files/generic_class.wrapped.g.dart rename to json_serializable/test/generic_files/generic_class.g_use_wrappers.g.dart index 395904adf..7f2b144b2 100644 --- a/json_serializable/test/generic_files/generic_class.wrapped.g.dart +++ b/json_serializable/test/generic_files/generic_class.g_use_wrappers.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -part of 'generic_class.wrapped.dart'; +part of 'generic_class.g_use_wrappers.dart'; // ************************************************************************** // JsonSerializableGenerator diff --git a/json_serializable/test/integration/json_test_example.non_nullable.dart b/json_serializable/test/integration/json_test_example.g_non_nullable.dart similarity index 93% rename from json_serializable/test/integration/json_test_example.non_nullable.dart rename to json_serializable/test/integration/json_test_example.g_non_nullable.dart index 0d686bdc0..6eef16418 100644 --- a/json_serializable/test/integration/json_test_example.non_nullable.dart +++ b/json_serializable/test/integration/json_test_example.g_non_nullable.dart @@ -2,19 +2,13 @@ // 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. -// GENERATED CODE - DO NOT MODIFY BY HAND - -// ************************************************************************** -// _NonNullableGenerator -// ************************************************************************** - // ignore_for_file: hash_and_equals import 'dart:collection'; import 'package:json_annotation/json_annotation.dart'; import 'json_test_common.dart'; -part 'json_test_example.non_nullable.g.dart'; +part 'json_test_example.g_non_nullable.g.dart'; @JsonSerializable( nullable: false, diff --git a/json_serializable/test/integration/json_test_example.non_nullable.g.dart b/json_serializable/test/integration/json_test_example.g_non_nullable.g.dart similarity index 99% rename from json_serializable/test/integration/json_test_example.non_nullable.g.dart rename to json_serializable/test/integration/json_test_example.g_non_nullable.g.dart index 3e756ca4d..712a0b902 100644 --- a/json_serializable/test/integration/json_test_example.non_nullable.g.dart +++ b/json_serializable/test/integration/json_test_example.g_non_nullable.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -part of 'json_test_example.non_nullable.dart'; +part of 'json_test_example.g_non_nullable.dart'; // ************************************************************************** // JsonSerializableGenerator diff --git a/json_serializable/test/integration/json_test_example.wrapped.dart b/json_serializable/test/integration/json_test_example.g_non_nullable__use_wrappers.dart similarity index 93% rename from json_serializable/test/integration/json_test_example.wrapped.dart rename to json_serializable/test/integration/json_test_example.g_non_nullable__use_wrappers.dart index 3b926857e..c680e6fb0 100644 --- a/json_serializable/test/integration/json_test_example.wrapped.dart +++ b/json_serializable/test/integration/json_test_example.g_non_nullable__use_wrappers.dart @@ -2,22 +2,17 @@ // 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. -// GENERATED CODE - DO NOT MODIFY BY HAND - -// ************************************************************************** -// _WrappedGenerator -// ************************************************************************** - // ignore_for_file: hash_and_equals import 'dart:collection'; import 'package:json_annotation/json_annotation.dart'; import 'json_test_common.dart'; -part 'json_test_example.wrapped.g.dart'; +part 'json_test_example.g_non_nullable__use_wrappers.g.dart'; @JsonSerializable( useWrappers: true, + nullable: false, ) class Person { final String firstName, middleName, lastName; @@ -52,6 +47,7 @@ class Person { @JsonSerializable( useWrappers: true, + nullable: false, ) class Order { /// Used to test that `disallowNullValues: true` forces `includeIfNull: false` @@ -105,6 +101,7 @@ class Order { @JsonSerializable( useWrappers: true, + nullable: false, ) class Item extends ItemCore { @JsonKey(includeIfNull: false, name: 'item-number') @@ -128,6 +125,7 @@ class Item extends ItemCore { @JsonSerializable( useWrappers: true, + nullable: false, ) class Numbers { List ints; diff --git a/json_serializable/test/integration/json_test_example.non_nullable.wrapped.g.dart b/json_serializable/test/integration/json_test_example.g_non_nullable__use_wrappers.g.dart similarity index 99% rename from json_serializable/test/integration/json_test_example.non_nullable.wrapped.g.dart rename to json_serializable/test/integration/json_test_example.g_non_nullable__use_wrappers.g.dart index d146f1d18..e82904856 100644 --- a/json_serializable/test/integration/json_test_example.non_nullable.wrapped.g.dart +++ b/json_serializable/test/integration/json_test_example.g_non_nullable__use_wrappers.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -part of 'json_test_example.non_nullable.wrapped.dart'; +part of 'json_test_example.g_non_nullable__use_wrappers.dart'; // ************************************************************************** // JsonSerializableGenerator diff --git a/json_serializable/test/integration/json_test_example.non_nullable.wrapped.dart b/json_serializable/test/integration/json_test_example.g_use_wrappers.dart similarity index 87% rename from json_serializable/test/integration/json_test_example.non_nullable.wrapped.dart rename to json_serializable/test/integration/json_test_example.g_use_wrappers.dart index e66b226f6..6c8644347 100644 --- a/json_serializable/test/integration/json_test_example.non_nullable.wrapped.dart +++ b/json_serializable/test/integration/json_test_example.g_use_wrappers.dart @@ -2,29 +2,16 @@ // 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. -// GENERATED CODE - DO NOT MODIFY BY HAND - -// ************************************************************************** -// _WrappedGenerator -// ************************************************************************** - -// GENERATED CODE - DO NOT MODIFY BY HAND - -// ************************************************************************** -// _NonNullableGenerator -// ************************************************************************** - // ignore_for_file: hash_and_equals import 'dart:collection'; import 'package:json_annotation/json_annotation.dart'; import 'json_test_common.dart'; -part 'json_test_example.non_nullable.wrapped.g.dart'; +part 'json_test_example.g_use_wrappers.g.dart'; @JsonSerializable( useWrappers: true, - nullable: false, ) class Person { final String firstName, middleName, lastName; @@ -59,7 +46,6 @@ class Person { @JsonSerializable( useWrappers: true, - nullable: false, ) class Order { /// Used to test that `disallowNullValues: true` forces `includeIfNull: false` @@ -113,7 +99,6 @@ class Order { @JsonSerializable( useWrappers: true, - nullable: false, ) class Item extends ItemCore { @JsonKey(includeIfNull: false, name: 'item-number') @@ -137,7 +122,6 @@ class Item extends ItemCore { @JsonSerializable( useWrappers: true, - nullable: false, ) class Numbers { List ints; diff --git a/json_serializable/test/integration/json_test_example.wrapped.g.dart b/json_serializable/test/integration/json_test_example.g_use_wrappers.g.dart similarity index 99% rename from json_serializable/test/integration/json_test_example.wrapped.g.dart rename to json_serializable/test/integration/json_test_example.g_use_wrappers.g.dart index 8fb4dbdb4..4038aba89 100644 --- a/json_serializable/test/integration/json_test_example.wrapped.g.dart +++ b/json_serializable/test/integration/json_test_example.g_use_wrappers.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -part of 'json_test_example.wrapped.dart'; +part of 'json_test_example.g_use_wrappers.dart'; // ************************************************************************** // JsonSerializableGenerator diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.dart b/json_serializable/test/kitchen_sink/kitchen_sink.dart index 501aa10d0..49ad1d448 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.dart @@ -35,11 +35,10 @@ k.KitchenSink testFactory( intIterable: intIterable, dateTimeIterable: dateTimeIterable); -k.KitchenSink testFromJson(Map json) => KitchenSink.fromJson(json); +k.KitchenSink testFromJson(Map json) => + KitchenSink.fromJson(json); -@JsonSerializable( - anyMap: true, -) +@JsonSerializable() class KitchenSink implements k.KitchenSink { // To ensure static members are not considered for serialization. static const answer = 42; @@ -75,7 +74,8 @@ class KitchenSink implements k.KitchenSink { } } - factory KitchenSink.fromJson(Map json) => _$KitchenSinkFromJson(json); + factory KitchenSink.fromJson(Map json) => + _$KitchenSinkFromJson(json); Map toJson() => _$KitchenSinkToJson(this); @@ -138,9 +138,7 @@ class KitchenSink implements k.KitchenSink { bool operator ==(Object other) => k.sinkEquals(this, other); } -@JsonSerializable( - anyMap: true, -) +@JsonSerializable() // referencing a top-level field should work @durationConverter // referencing via a const constructor should work @@ -167,9 +165,7 @@ class JsonConverterTestClass { DateTime dateTime; } -@JsonSerializable( - anyMap: true, -) +@JsonSerializable() @GenericConverter() class JsonConverterGeneric { S item; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g.dart index 0a2be4caf..3134b670f 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g.dart @@ -6,7 +6,7 @@ part of 'kitchen_sink.dart'; // JsonSerializableGenerator // ************************************************************************** -KitchenSink _$KitchenSinkFromJson(Map json) { +KitchenSink _$KitchenSinkFromJson(Map json) { return KitchenSink( ctorValidatedNo42: json['no-42'] as int, iterable: json['iterable'] as List, @@ -32,23 +32,24 @@ KitchenSink _$KitchenSinkFromJson(Map json) { ..dateTimeList = (json['dateTimeList'] as List) ?.map((e) => e == null ? null : DateTime.parse(e as String)) ?.toList() - ..map = json['map'] as Map - ..stringStringMap = (json['stringStringMap'] as Map)?.map( - (k, e) => MapEntry(k as String, e as String), + ..map = json['map'] as Map + ..stringStringMap = (json['stringStringMap'] as Map)?.map( + (k, e) => MapEntry(k, e as String), ) - ..dynamicIntMap = (json['dynamicIntMap'] as Map)?.map( + ..dynamicIntMap = (json['dynamicIntMap'] as Map)?.map( (k, e) => MapEntry(k, e as int), ) - ..objectDateTimeMap = (json['objectDateTimeMap'] as Map)?.map( + ..objectDateTimeMap = + (json['objectDateTimeMap'] as Map)?.map( (k, e) => MapEntry(k, e == null ? null : DateTime.parse(e as String)), ) ..crazyComplex = (json['crazyComplex'] as List) - ?.map((e) => (e as Map)?.map( + ?.map((e) => (e as Map)?.map( (k, e) => MapEntry( - k as String, - (e as Map)?.map( + k, + (e as Map)?.map( (k, e) => MapEntry( - k as String, + k, (e as List) ?.map((e) => (e as List) ?.map((e) => e == null @@ -59,17 +60,18 @@ KitchenSink _$KitchenSinkFromJson(Map json) { )), )) ?.toList() - ..val = (json['val'] as Map)?.map( - (k, e) => MapEntry(k as String, e as bool), + ..val = (json['val'] as Map)?.map( + (k, e) => MapEntry(k, e as bool), ) ..writeNotNull = json['writeNotNull'] as bool ..string = json[r'$string'] as String ..simpleObject = json['simpleObject'] == null ? null - : SimpleObject.fromJson(json['simpleObject'] as Map) + : SimpleObject.fromJson(json['simpleObject'] as Map) ..strictKeysObject = json['strictKeysObject'] == null ? null - : StrictKeysObject.fromJson(json['strictKeysObject'] as Map) + : StrictKeysObject.fromJson( + json['strictKeysObject'] as Map) ..validatedPropertyNo42 = json['validatedPropertyNo42'] as int; } @@ -129,7 +131,8 @@ Map _$KitchenSinkToJson(KitchenSink instance) { return val; } -JsonConverterTestClass _$JsonConverterTestClassFromJson(Map json) { +JsonConverterTestClass _$JsonConverterTestClassFromJson( + Map json) { return JsonConverterTestClass() ..duration = json['duration'] == null ? null @@ -140,9 +143,9 @@ JsonConverterTestClass _$JsonConverterTestClassFromJson(Map json) { ..bigInt = json['bigInt'] == null ? null : const BigIntStringConverter().fromJson(json['bigInt'] as String) - ..bigIntMap = (json['bigIntMap'] as Map)?.map( + ..bigIntMap = (json['bigIntMap'] as Map)?.map( (k, e) => MapEntry( - k as String, + k, e == null ? null : const BigIntStringConverter().fromJson(e as String)), @@ -187,7 +190,7 @@ Map _$JsonConverterTestClassToJson( }; JsonConverterGeneric _$JsonConverterGenericFromJson( - Map json) { + Map json) { return JsonConverterGeneric() ..item = json['item'] == null ? null @@ -197,9 +200,9 @@ JsonConverterGeneric _$JsonConverterGenericFromJson( ? null : GenericConverter().fromJson(e as Map)) ?.toList() - ..itemMap = (json['itemMap'] as Map)?.map( + ..itemMap = (json['itemMap'] as Map)?.map( (k, e) => MapEntry( - k as String, + k, e == null ? null : GenericConverter().fromJson(e as Map)), diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart new file mode 100644 index 000000000..655416c56 --- /dev/null +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart @@ -0,0 +1,185 @@ +// Copyright (c) 2018, 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. + +// ignore_for_file: annotate_overrides, hash_and_equals +import 'package:json_annotation/json_annotation.dart'; + +import 'json_converters.dart'; +import 'kitchen_sink_interface.dart' as k; +import 'simple_object.dart'; +import 'strict_keys_object.dart'; + +part 'kitchen_sink.g_any_map.g.dart'; + +// NOTE: these methods are replaced in the `non_nullable` cases to return +// non-null values. +List _defaultList() => null; +Set _defaultSet() => null; +Map _defaultMap() => null; +SimpleObject _defaultSimpleObject() => null; +StrictKeysObject _defaultStrictKeysObject() => null; + +k.KitchenSink testFactory( + {int ctorValidatedNo42, + Iterable iterable, + Iterable dynamicIterable, + Iterable objectIterable, + Iterable intIterable, + Iterable dateTimeIterable}) => + KitchenSink( + ctorValidatedNo42: ctorValidatedNo42, + iterable: iterable, + dynamicIterable: dynamicIterable, + objectIterable: objectIterable, + intIterable: intIterable, + dateTimeIterable: dateTimeIterable); + +k.KitchenSink testFromJson(Map json) => KitchenSink.fromJson(json); + +@JsonSerializable( + anyMap: true, +) +class KitchenSink implements k.KitchenSink { + // To ensure static members are not considered for serialization. + static const answer = 42; + static final reason = 42; + static int get understand => 42; + + // NOTE: exposing these as Iterable, but storing the values as List + // to make the equality test work trivially. + final Iterable _iterable; + final Iterable _dynamicIterable; + final Iterable _objectIterable; + final Iterable _intIterable; + final Iterable _dateTimeIterable; + + @JsonKey(name: 'no-42') + final int ctorValidatedNo42; + + KitchenSink( + {this.ctorValidatedNo42, + Iterable iterable, + Iterable dynamicIterable, + Iterable objectIterable, + Iterable intIterable, + Iterable dateTimeIterable}) + : _iterable = iterable?.toList() ?? _defaultList(), + _dynamicIterable = dynamicIterable?.toList() ?? _defaultList(), + _objectIterable = objectIterable?.toList() ?? _defaultList(), + _intIterable = intIterable?.toList() ?? _defaultList(), + _dateTimeIterable = dateTimeIterable?.toList() ?? _defaultList() { + if (ctorValidatedNo42 == 42) { + throw ArgumentError.value( + 42, 'ctorValidatedNo42', 'The value `42` is not allowed.'); + } + } + + factory KitchenSink.fromJson(Map json) => _$KitchenSinkFromJson(json); + + Map toJson() => _$KitchenSinkToJson(this); + + @JsonKey(includeIfNull: false) + DateTime dateTime; + + @JsonKey(includeIfNull: false) + Iterable get iterable => _iterable; + Iterable get dynamicIterable => _dynamicIterable; + Iterable get objectIterable => _objectIterable; + Iterable get intIterable => _intIterable; + + Set set = _defaultSet(); + Set dynamicSet = _defaultSet(); + Set objectSet = _defaultSet(); + Set intSet = _defaultSet(); + Set dateTimeSet = _defaultSet(); + + // Added a one-off annotation on a property (not a field) + @JsonKey(name: 'datetime-iterable') + Iterable get dateTimeIterable => _dateTimeIterable; + + List list = _defaultList(); + List dynamicList = _defaultList(); + List objectList = _defaultList(); + List intList = _defaultList(); + @JsonKey(includeIfNull: false) + List dateTimeList = _defaultList(); + + Map map = _defaultMap(); + Map stringStringMap = _defaultMap(); + Map dynamicIntMap = _defaultMap(); + Map objectDateTimeMap = _defaultMap(); + + @JsonKey(includeIfNull: false) + List>>>> crazyComplex = + _defaultList(); + + // Handle fields with names that collide with helper names + @JsonKey(includeIfNull: false) + Map val = _defaultMap(); + bool writeNotNull; + @JsonKey(name: r'$string') + String string; + + SimpleObject simpleObject = _defaultSimpleObject(); + + StrictKeysObject strictKeysObject = _defaultStrictKeysObject(); + + int _validatedPropertyNo42; + int get validatedPropertyNo42 => _validatedPropertyNo42; + + set validatedPropertyNo42(int value) { + if (value == 42) { + throw StateError('Cannot be 42!'); + } + _validatedPropertyNo42 = value; + } + + bool operator ==(Object other) => k.sinkEquals(this, other); +} + +@JsonSerializable( + anyMap: true, +) +// referencing a top-level field should work +@durationConverter +// referencing via a const constructor should work +@BigIntStringConverter() +@TrivialNumberConverter.instance +@EpochDateTimeConverter() +class JsonConverterTestClass { + JsonConverterTestClass(); + + factory JsonConverterTestClass.fromJson(Map json) => + _$JsonConverterTestClassFromJson(json); + + Map toJson() => _$JsonConverterTestClassToJson(this); + + Duration duration; + List durationList; + + BigInt bigInt; + Map bigIntMap; + + TrivialNumber numberSilly; + Set numberSillySet; + + DateTime dateTime; +} + +@JsonSerializable( + anyMap: true, +) +@GenericConverter() +class JsonConverterGeneric { + S item; + List itemList; + Map itemMap; + + JsonConverterGeneric(); + + factory JsonConverterGeneric.fromJson(Map json) => + _$JsonConverterGenericFromJson(json); + + Map toJson() => _$JsonConverterGenericToJson(this); +} diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart new file mode 100644 index 000000000..b2293ebd2 --- /dev/null +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart @@ -0,0 +1,220 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'kitchen_sink.g_any_map.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +KitchenSink _$KitchenSinkFromJson(Map json) { + return KitchenSink( + ctorValidatedNo42: json['no-42'] as int, + iterable: json['iterable'] as List, + dynamicIterable: json['dynamicIterable'] as List, + objectIterable: json['objectIterable'] as List, + intIterable: (json['intIterable'] as List)?.map((e) => e as int), + dateTimeIterable: (json['datetime-iterable'] as List) + ?.map((e) => e == null ? null : DateTime.parse(e as String))) + ..dateTime = json['dateTime'] == null + ? null + : DateTime.parse(json['dateTime'] as String) + ..set = (json['set'] as List)?.toSet() + ..dynamicSet = (json['dynamicSet'] as List)?.toSet() + ..objectSet = (json['objectSet'] as List)?.toSet() + ..intSet = (json['intSet'] as List)?.map((e) => e as int)?.toSet() + ..dateTimeSet = (json['dateTimeSet'] as List) + ?.map((e) => e == null ? null : DateTime.parse(e as String)) + ?.toSet() + ..list = json['list'] as List + ..dynamicList = json['dynamicList'] as List + ..objectList = json['objectList'] as List + ..intList = (json['intList'] as List)?.map((e) => e as int)?.toList() + ..dateTimeList = (json['dateTimeList'] as List) + ?.map((e) => e == null ? null : DateTime.parse(e as String)) + ?.toList() + ..map = json['map'] as Map + ..stringStringMap = (json['stringStringMap'] as Map)?.map( + (k, e) => MapEntry(k as String, e as String), + ) + ..dynamicIntMap = (json['dynamicIntMap'] as Map)?.map( + (k, e) => MapEntry(k, e as int), + ) + ..objectDateTimeMap = (json['objectDateTimeMap'] as Map)?.map( + (k, e) => MapEntry(k, e == null ? null : DateTime.parse(e as String)), + ) + ..crazyComplex = (json['crazyComplex'] as List) + ?.map((e) => (e as Map)?.map( + (k, e) => MapEntry( + k as String, + (e as Map)?.map( + (k, e) => MapEntry( + k as String, + (e as List) + ?.map((e) => (e as List) + ?.map((e) => e == null + ? null + : DateTime.parse(e as String)) + ?.toList()) + ?.toList()), + )), + )) + ?.toList() + ..val = (json['val'] as Map)?.map( + (k, e) => MapEntry(k as String, e as bool), + ) + ..writeNotNull = json['writeNotNull'] as bool + ..string = json[r'$string'] as String + ..simpleObject = json['simpleObject'] == null + ? null + : SimpleObject.fromJson(json['simpleObject'] as Map) + ..strictKeysObject = json['strictKeysObject'] == null + ? null + : StrictKeysObject.fromJson(json['strictKeysObject'] as Map) + ..validatedPropertyNo42 = json['validatedPropertyNo42'] as int; +} + +Map _$KitchenSinkToJson(KitchenSink instance) { + final val = { + 'no-42': instance.ctorValidatedNo42, + }; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('dateTime', instance.dateTime?.toIso8601String()); + writeNotNull('iterable', instance.iterable?.toList()); + val['dynamicIterable'] = instance.dynamicIterable?.toList(); + val['objectIterable'] = instance.objectIterable?.toList(); + val['intIterable'] = instance.intIterable?.toList(); + val['set'] = instance.set?.toList(); + val['dynamicSet'] = instance.dynamicSet?.toList(); + val['objectSet'] = instance.objectSet?.toList(); + val['intSet'] = instance.intSet?.toList(); + val['dateTimeSet'] = + instance.dateTimeSet?.map((e) => e?.toIso8601String())?.toList(); + val['datetime-iterable'] = + instance.dateTimeIterable?.map((e) => e?.toIso8601String())?.toList(); + val['list'] = instance.list; + val['dynamicList'] = instance.dynamicList; + val['objectList'] = instance.objectList; + val['intList'] = instance.intList; + writeNotNull('dateTimeList', + instance.dateTimeList?.map((e) => e?.toIso8601String())?.toList()); + val['map'] = instance.map; + val['stringStringMap'] = instance.stringStringMap; + val['dynamicIntMap'] = instance.dynamicIntMap; + val['objectDateTimeMap'] = instance.objectDateTimeMap + ?.map((k, e) => MapEntry(k, e?.toIso8601String())); + writeNotNull( + 'crazyComplex', + instance.crazyComplex + ?.map((e) => e?.map((k, e) => MapEntry( + k, + e?.map((k, e) => MapEntry( + k, + e + ?.map( + (e) => e?.map((e) => e?.toIso8601String())?.toList()) + ?.toList()))))) + ?.toList()); + writeNotNull('val', instance.val); + val['writeNotNull'] = instance.writeNotNull; + val[r'$string'] = instance.string; + val['simpleObject'] = instance.simpleObject; + val['strictKeysObject'] = instance.strictKeysObject; + val['validatedPropertyNo42'] = instance.validatedPropertyNo42; + return val; +} + +JsonConverterTestClass _$JsonConverterTestClassFromJson(Map json) { + return JsonConverterTestClass() + ..duration = json['duration'] == null + ? null + : durationConverter.fromJson(json['duration'] as int) + ..durationList = (json['durationList'] as List) + ?.map((e) => e == null ? null : durationConverter.fromJson(e as int)) + ?.toList() + ..bigInt = json['bigInt'] == null + ? null + : const BigIntStringConverter().fromJson(json['bigInt'] as String) + ..bigIntMap = (json['bigIntMap'] as Map)?.map( + (k, e) => MapEntry( + k as String, + e == null + ? null + : const BigIntStringConverter().fromJson(e as String)), + ) + ..numberSilly = json['numberSilly'] == null + ? null + : TrivialNumberConverter.instance.fromJson(json['numberSilly'] as int) + ..numberSillySet = (json['numberSillySet'] as List) + ?.map((e) => e == null + ? null + : TrivialNumberConverter.instance.fromJson(e as int)) + ?.toSet() + ..dateTime = json['dateTime'] == null + ? null + : const EpochDateTimeConverter().fromJson(json['dateTime'] as int); +} + +Map _$JsonConverterTestClassToJson( + JsonConverterTestClass instance) => + { + 'duration': instance.duration == null + ? null + : durationConverter.toJson(instance.duration), + 'durationList': instance.durationList + ?.map((e) => e == null ? null : durationConverter.toJson(e)) + ?.toList(), + 'bigInt': instance.bigInt == null + ? null + : const BigIntStringConverter().toJson(instance.bigInt), + 'bigIntMap': instance.bigIntMap?.map((k, e) => MapEntry( + k, e == null ? null : const BigIntStringConverter().toJson(e))), + 'numberSilly': instance.numberSilly == null + ? null + : TrivialNumberConverter.instance.toJson(instance.numberSilly), + 'numberSillySet': instance.numberSillySet + ?.map((e) => + e == null ? null : TrivialNumberConverter.instance.toJson(e)) + ?.toList(), + 'dateTime': instance.dateTime == null + ? null + : const EpochDateTimeConverter().toJson(instance.dateTime) + }; + +JsonConverterGeneric _$JsonConverterGenericFromJson( + Map json) { + return JsonConverterGeneric() + ..item = json['item'] == null + ? null + : GenericConverter().fromJson(json['item'] as Map) + ..itemList = (json['itemList'] as List) + ?.map((e) => e == null + ? null + : GenericConverter().fromJson(e as Map)) + ?.toList() + ..itemMap = (json['itemMap'] as Map)?.map( + (k, e) => MapEntry( + k as String, + e == null + ? null + : GenericConverter().fromJson(e as Map)), + ); +} + +Map _$JsonConverterGenericToJson( + JsonConverterGeneric instance) => + { + 'item': instance.item == null + ? null + : GenericConverter().toJson(instance.item), + 'itemList': instance.itemList + ?.map((e) => e == null ? null : GenericConverter().toJson(e)) + ?.toList(), + 'itemMap': instance.itemMap?.map((k, e) => + MapEntry(k, e == null ? null : GenericConverter().toJson(e))) + }; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked__non_nullable.dart similarity index 95% rename from json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.dart rename to json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked__non_nullable.dart index f39f560d9..cc5eeb7ad 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked__non_nullable.dart @@ -2,12 +2,6 @@ // 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. -// GENERATED CODE - DO NOT MODIFY BY HAND - -// ************************************************************************** -// _NonNullableGenerator -// ************************************************************************** - // ignore_for_file: annotate_overrides, hash_and_equals import 'package:json_annotation/json_annotation.dart'; @@ -16,7 +10,7 @@ import 'kitchen_sink_interface.dart' as k; import 'simple_object.dart'; import 'strict_keys_object.dart'; -part 'kitchen_sink.non_nullable.g.dart'; +part 'kitchen_sink.g_any_map__checked__non_nullable.g.dart'; // NOTE: these methods are replaced in the `non_nullable` cases to return // non-null values. @@ -45,6 +39,7 @@ k.KitchenSink testFromJson(Map json) => KitchenSink.fromJson(json); @JsonSerializable( nullable: false, + checked: true, anyMap: true, ) class KitchenSink implements k.KitchenSink { @@ -147,6 +142,7 @@ class KitchenSink implements k.KitchenSink { @JsonSerializable( nullable: false, + checked: true, anyMap: true, ) // referencing a top-level field should work @@ -177,6 +173,7 @@ class JsonConverterTestClass { @JsonSerializable( nullable: false, + checked: true, anyMap: true, ) @GenericConverter() diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.checked.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked__non_nullable.g.dart similarity index 99% rename from json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.checked.g.dart rename to json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked__non_nullable.g.dart index 74267cf53..e4cef7bcf 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.checked.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked__non_nullable.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -part of 'kitchen_sink.non_nullable.checked.dart'; +part of 'kitchen_sink.g_any_map__checked__non_nullable.dart'; // ************************************************************************** // JsonSerializableGenerator diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.checked.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable.dart similarity index 91% rename from json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.checked.dart rename to json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable.dart index d8ce2282b..d787754f9 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.checked.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable.dart @@ -2,18 +2,6 @@ // 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. -// GENERATED CODE - DO NOT MODIFY BY HAND - -// ************************************************************************** -// _CheckedGenerator -// ************************************************************************** - -// GENERATED CODE - DO NOT MODIFY BY HAND - -// ************************************************************************** -// _NonNullableGenerator -// ************************************************************************** - // ignore_for_file: annotate_overrides, hash_and_equals import 'package:json_annotation/json_annotation.dart'; @@ -22,7 +10,7 @@ import 'kitchen_sink_interface.dart' as k; import 'simple_object.dart'; import 'strict_keys_object.dart'; -part 'kitchen_sink.non_nullable.checked.g.dart'; +part 'kitchen_sink.g_any_map__non_nullable.g.dart'; // NOTE: these methods are replaced in the `non_nullable` cases to return // non-null values. @@ -50,7 +38,6 @@ k.KitchenSink testFactory( k.KitchenSink testFromJson(Map json) => KitchenSink.fromJson(json); @JsonSerializable( - checked: true, nullable: false, anyMap: true, ) @@ -153,7 +140,6 @@ class KitchenSink implements k.KitchenSink { } @JsonSerializable( - checked: true, nullable: false, anyMap: true, ) @@ -184,7 +170,6 @@ class JsonConverterTestClass { } @JsonSerializable( - checked: true, nullable: false, anyMap: true, ) diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable.g.dart similarity index 99% rename from json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.g.dart rename to json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable.g.dart index aefffe998..65636196b 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -part of 'kitchen_sink.non_nullable.dart'; +part of 'kitchen_sink.g_any_map__non_nullable.dart'; // ************************************************************************** // JsonSerializableGenerator diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.wrapped.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable__use_wrappers.dart similarity index 92% rename from json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.wrapped.dart rename to json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable__use_wrappers.dart index 2dc36ef2b..013118e1f 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.wrapped.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable__use_wrappers.dart @@ -2,18 +2,6 @@ // 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. -// GENERATED CODE - DO NOT MODIFY BY HAND - -// ************************************************************************** -// _WrappedGenerator -// ************************************************************************** - -// GENERATED CODE - DO NOT MODIFY BY HAND - -// ************************************************************************** -// _NonNullableGenerator -// ************************************************************************** - // ignore_for_file: annotate_overrides, hash_and_equals import 'package:json_annotation/json_annotation.dart'; @@ -22,7 +10,7 @@ import 'kitchen_sink_interface.dart' as k; import 'simple_object.dart'; import 'strict_keys_object.dart'; -part 'kitchen_sink.non_nullable.wrapped.g.dart'; +part 'kitchen_sink.g_any_map__non_nullable__use_wrappers.g.dart'; // NOTE: these methods are replaced in the `non_nullable` cases to return // non-null values. diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.wrapped.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable__use_wrappers.g.dart similarity index 99% rename from json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.wrapped.g.dart rename to json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable__use_wrappers.g.dart index abb876aab..d566a5068 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.non_nullable.wrapped.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable__use_wrappers.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -part of 'kitchen_sink.non_nullable.wrapped.dart'; +part of 'kitchen_sink.g_any_map__non_nullable__use_wrappers.dart'; // ************************************************************************** // JsonSerializableGenerator diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.wrapped.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__use_wrappers.dart similarity index 95% rename from json_serializable/test/kitchen_sink/kitchen_sink.wrapped.dart rename to json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__use_wrappers.dart index a7f3f8e6e..c2a2cc9dc 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.wrapped.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__use_wrappers.dart @@ -2,12 +2,6 @@ // 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. -// GENERATED CODE - DO NOT MODIFY BY HAND - -// ************************************************************************** -// _WrappedGenerator -// ************************************************************************** - // ignore_for_file: annotate_overrides, hash_and_equals import 'package:json_annotation/json_annotation.dart'; @@ -16,7 +10,7 @@ import 'kitchen_sink_interface.dart' as k; import 'simple_object.dart'; import 'strict_keys_object.dart'; -part 'kitchen_sink.wrapped.g.dart'; +part 'kitchen_sink.g_any_map__use_wrappers.g.dart'; // NOTE: these methods are replaced in the `non_nullable` cases to return // non-null values. diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.wrapped.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__use_wrappers.g.dart similarity index 99% rename from json_serializable/test/kitchen_sink/kitchen_sink.wrapped.g.dart rename to json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__use_wrappers.g.dart index cd277bce9..40425ea48 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.wrapped.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__use_wrappers.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -part of 'kitchen_sink.wrapped.dart'; +part of 'kitchen_sink.g_any_map__use_wrappers.dart'; // ************************************************************************** // JsonSerializableGenerator diff --git a/json_serializable/test/kitchen_sink/kitchen_sink_test.dart b/json_serializable/test/kitchen_sink/kitchen_sink_test.dart index 4f7b7dd3d..0359a8adc 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink_test.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink_test.dart @@ -7,15 +7,16 @@ import 'package:test/test.dart'; import 'package:yaml/yaml.dart'; import '../test_utils.dart'; -import 'kitchen_sink.dart' as nullable +import 'kitchen_sink.g_any_map.dart' as nullable show testFactory, testFromJson, JsonConverterTestClass; -import 'kitchen_sink.non_nullable.checked.dart' as checked +import 'kitchen_sink.g_any_map__checked__non_nullable.dart' as checked show testFactory, testFromJson; -import 'kitchen_sink.non_nullable.dart' as nn +import 'kitchen_sink.g_any_map__non_nullable.dart' as nn show testFactory, testFromJson, JsonConverterTestClass; -import 'kitchen_sink.non_nullable.wrapped.dart' as nnwrapped +import 'kitchen_sink.g_any_map__non_nullable__use_wrappers.dart' as nnwrapped + show testFactory, testFromJson; +import 'kitchen_sink.g_any_map__use_wrappers.dart' as wrapped show testFactory, testFromJson; -import 'kitchen_sink.wrapped.dart' as wrapped show testFactory, testFromJson; import 'kitchen_sink_interface.dart'; import 'strict_keys_object.dart'; diff --git a/json_serializable/tool/builder.dart b/json_serializable/tool/builder.dart index 07ef11626..677157eca 100644 --- a/json_serializable/tool/builder.dart +++ b/json_serializable/tool/builder.dart @@ -3,111 +3,206 @@ // BSD-style license that can be found in the LICENSE file. import 'dart:async'; +import 'dart:io'; import 'package:build/build.dart'; +import 'package:dart_style/dart_style.dart'; import 'package:path/path.dart' as p; -import 'package:source_gen/source_gen.dart'; +import 'package:yaml/yaml.dart'; -final _copyrightContent = - '''// Copyright (c) 2018, 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. -'''; +final _formatter = DartFormatter(); + +Builder internal([_]) { + final builder = const _SmartBuilder(); + _validateBuilder(builder); + return builder; +} -final copyrightHeader = '$_copyrightContent\n$defaultFileHeader'; +// Until we have verification in pkg:build and friends +// https://github.com/dart-lang/build/issues/590 +void _validateBuilder(_SmartBuilder builder) { + var buildYaml = loadYaml( + File('build.yaml').readAsStringSync(), + sourceUrl: 'build.yaml', + ) as YamlMap; -LibraryBuilder _builder(_ReplaceGenerator generator) => LibraryBuilder( - generator, - generatedExtension: '.${generator.gName}.dart', - header: copyrightHeader, - formatOutput: (a) => a, - ); + for (var key in ['builders', '_internal', 'build_extensions']) { + buildYaml = buildYaml[key] as YamlMap; + } -Builder nonNull([_]) => _builder(_NonNullableGenerator()); + final extensions = Set.from(buildYaml['.dart'] as YamlList); -Builder wrapped([_]) => _builder(_WrappedGenerator()); + final codedExtensions = builder.buildExtensions['.dart'].toSet(); -Builder checked([_]) => _builder(_CheckedGenerator()); + final tooMany = extensions.difference(codedExtensions); + if (tooMany.isNotEmpty) { + log.warning('Too many extensions in build.yaml:\n${tooMany.join('\n')}'); + } -abstract class _ReplaceGenerator extends Generator { - final String gName; + final missing = codedExtensions.difference(extensions); + if (missing.isNotEmpty) { + log.warning('Missing extensions in build.yaml:\n${missing.join('\n')}'); + } +} - _ReplaceGenerator(this.gName); +class _SmartBuilder implements Builder { + const _SmartBuilder(); @override - FutureOr generate(LibraryReader library, BuildStep buildStep) async { - final path = buildStep.inputId.path; - final baseName = p.basenameWithoutExtension(path); + FutureOr build(BuildStep buildStep) async { + final baseName = p.basenameWithoutExtension(buildStep.inputId.path); - final content = await buildStep.readAsString(buildStep.inputId); + final sourceContent = await buildStep.readAsString(buildStep.inputId); - return _Replacement.generate(content, createReplacements(baseName)); - } + for (var config in _fileConfigurationMap[baseName]) { + final extension = _configToExtension(config); + final newId = buildStep.inputId.changeExtension(extension); - Iterable<_Replacement> createReplacements(String baseName) sync* { - yield _Replacement(_copyrightContent, ''); + final partName = extension.substring(0, extension.length - 5); - yield _Replacement( - "part '$baseName.g.dart", - "part '$baseName.$gName.g.dart", - ); - } -} + final replacements = <_Replacement>[ + _Replacement( + "part '$baseName.g.dart';", + "part '$baseName$partName.g.dart';", + ) + ]; -class _NonNullableGenerator extends _ReplaceGenerator { - _NonNullableGenerator() : super('non_nullable'); + for (var entry in config.entries) { + replacements + .addAll(_optionReplacement(baseName, entry.key, entry.value)); + } - @override - Iterable<_Replacement> createReplacements(String baseName) sync* { - yield* super.createReplacements(baseName); - - yield _Replacement.addJsonSerializableKey('nullable', false); - - if (baseName == 'kitchen_sink') { - yield _Replacement('List _defaultList() => null;', - 'List _defaultList() => [];'); - yield _Replacement('Set _defaultSet() => null;', - 'Set _defaultSet() => Set();'); - yield _Replacement('Map _defaultMap() => null;', - 'Map _defaultMap() => {};'); - yield _Replacement('SimpleObject _defaultSimpleObject() => null;', - 'SimpleObject _defaultSimpleObject() => SimpleObject(42);'); - yield _Replacement( - 'StrictKeysObject _defaultStrictKeysObject() => null;', - 'StrictKeysObject _defaultStrictKeysObject() => ' - "StrictKeysObject(10, 'cool');"); - yield _Replacement( - 'DateTime dateTime;', 'DateTime dateTime = DateTime(1981, 6, 5);'); + final content = _Replacement.generate(sourceContent, replacements); + + await buildStep.writeAsString(newId, _formatter.format(content)); } } -} - -class _CheckedGenerator extends _ReplaceGenerator { - _CheckedGenerator() : super('checked'); @override - Iterable<_Replacement> createReplacements(String baseName) sync* { - yield* super.createReplacements(baseName); - - yield _Replacement.addJsonSerializableKey('checked', true); + Map> get buildExtensions => + {'.dart': _fileConfigurations}; +} - if (baseName == 'default_value') { - yield _Replacement.addJsonSerializableKey('anyMap', true); - } +Iterable<_Replacement> _optionReplacement( + String baseName, + String optionKey, + bool value, +) sync* { + switch (optionKey) { + case 'any_map': + if (value) { + yield _Replacement.addJsonSerializableKey('anyMap', true); + + if (baseName == 'kitchen_sink') { + yield _Replacement( + 'testFromJson(Map json)', + 'testFromJson(Map json)', + ); + yield _Replacement( + 'factory KitchenSink.fromJson(Map json)', + 'factory KitchenSink.fromJson(Map json)', + ); + } + } + break; + case 'checked': + if (value) { + yield _Replacement.addJsonSerializableKey('checked', true); + } + break; + case 'non_nullable': + if (value) { + yield _Replacement.addJsonSerializableKey('nullable', false); + + if (baseName == 'kitchen_sink') { + yield _Replacement('List _defaultList() => null;', + 'List _defaultList() => [];'); + yield _Replacement('Set _defaultSet() => null;', + 'Set _defaultSet() => Set();'); + yield _Replacement('Map _defaultMap() => null;', + 'Map _defaultMap() => {};'); + yield _Replacement('SimpleObject _defaultSimpleObject() => null;', + 'SimpleObject _defaultSimpleObject() => SimpleObject(42);'); + yield _Replacement( + 'StrictKeysObject _defaultStrictKeysObject() => null;', + 'StrictKeysObject _defaultStrictKeysObject() => ' + "StrictKeysObject(10, 'cool');"); + yield _Replacement('DateTime dateTime;', + 'DateTime dateTime = DateTime(1981, 6, 5);'); + } + } + break; + case 'use_wrappers': + if (value) { + yield _Replacement.addJsonSerializableKey('useWrappers', true); + } + break; + default: + throw UnimplementedError('not yet!: $optionKey'); } } -class _WrappedGenerator extends _ReplaceGenerator { - _WrappedGenerator() : super('wrapped'); - - @override - Iterable<_Replacement> createReplacements(String baseName) sync* { - yield* super.createReplacements(baseName); - - yield _Replacement.addJsonSerializableKey('useWrappers', true); +String _configToExtension(Map config) => + '.g_${_configToName(config)}.dart'; + +String _configToName(Map config) => + (config.entries.where((e) => e.value != false).map((e) => e.key).toList() + ..sort()) + .join('__'); + +const _options = >{ + 'any_map': [false, true], + 'checked': [false, true], + 'use_wrappers': [false, true], + 'non_nullable': [false, true], +}; + +Iterable> allConfigurations({ + Map parts = const {}, +}) sync* { + assert(parts.length <= _options.length); + if (parts.length == _options.length) { + if (parts.values.any((v) => v)) { + yield parts; + } + } else { + final entry = _options.entries.skip(parts.length).first; + for (var option in entry.value) { + final newMap = Map.of(parts); + assert(!newMap.containsKey(entry.key)); + newMap[entry.key] = option; + yield* allConfigurations(parts: newMap); + } } } +List get _fileConfigurations => _fileConfigurationMap.values + .expand((v) => v) + .map(_configToExtension) + .toSet() + .toList(); + +const _fileConfigurationMap = { + 'kitchen_sink': [ + {'any_map': true}, + {'any_map': true, 'checked': true, 'non_nullable': true}, + {'any_map': true, 'non_nullable': true}, + {'any_map': true, 'non_nullable': true, 'use_wrappers': true}, + {'any_map': true, 'use_wrappers': true}, + ], + 'default_value': [ + {'any_map': true, 'checked': true}, + ], + 'generic_class': [ + {'use_wrappers': true}, + ], + 'json_test_example': [ + {'non_nullable': true, 'use_wrappers': true}, + {'non_nullable': true}, + {'use_wrappers': true}, + ] +}; + class _Replacement { final Pattern existing; final String replacement; From 94a5f20575feeab39b18a289d17302176426b345 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 13 Mar 2019 16:59:02 -0700 Subject: [PATCH 072/569] enable and fix one lint (#410) --- analysis_options.yaml | 2 ++ json_annotation/lib/src/wrapper_helpers.dart | 2 +- json_serializable/test/kitchen_sink/kitchen_sink_test.dart | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index 1e88b2d41..edcf7501f 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -60,6 +60,7 @@ linter: - prefer_equal_for_default_values - prefer_final_fields - prefer_final_locals + - prefer_generic_function_type_aliases - prefer_initializing_formals - prefer_interpolation_to_compose_strings - prefer_is_empty @@ -81,5 +82,6 @@ linter: - unnecessary_statements - unnecessary_this - unrelated_type_equality_checks + #- use_function_type_syntax_for_parameters - use_rethrow_when_possible - valid_regexps diff --git a/json_annotation/lib/src/wrapper_helpers.dart b/json_annotation/lib/src/wrapper_helpers.dart index 2bdca2248..73b019167 100644 --- a/json_annotation/lib/src/wrapper_helpers.dart +++ b/json_annotation/lib/src/wrapper_helpers.dart @@ -41,7 +41,7 @@ List $wrapListHandleNull( List source, dynamic converter(T key)) => source == null ? null : _MappingList(source, converter); -typedef dynamic _Convert(S value); +typedef _Convert = dynamic Function(S value); class _MappingList extends ListBase { final List _source; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink_test.dart b/json_serializable/test/kitchen_sink/kitchen_sink_test.dart index 0359a8adc..99fd7bdfb 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink_test.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink_test.dart @@ -108,7 +108,7 @@ void main() { }); } -typedef KitchenSink KitchenSinkCtor( +typedef KitchenSinkCtor = KitchenSink Function( {int ctorValidatedNo42, Iterable iterable, Iterable dynamicIterable, From 9d4ef97389560eca43898f30581d9c39cbd2383d Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 13 Mar 2019 14:54:12 -0700 Subject: [PATCH 073/569] Refactor kitchen sink tests Have each test `factory` describe itself Run the right tests given the factor configuration Will make it much easier to add tests and configurations later --- .../test/kitchen_sink/kitchen_sink.dart | 57 ++++-- .../kitchen_sink/kitchen_sink.g_any_map.dart | 56 ++++-- ...sink.g_any_map__checked__non_nullable.dart | 56 ++++-- .../kitchen_sink.g_any_map__non_nullable.dart | 56 ++++-- ...g_any_map__non_nullable__use_wrappers.dart | 56 ++++-- .../kitchen_sink.g_any_map__use_wrappers.dart | 56 ++++-- .../kitchen_sink/kitchen_sink_interface.dart | 24 +++ .../test/kitchen_sink/kitchen_sink_test.dart | 180 ++++++++---------- json_serializable/tool/builder.dart | 57 ++++-- 9 files changed, 363 insertions(+), 235 deletions(-) diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.dart b/json_serializable/test/kitchen_sink/kitchen_sink.dart index 49ad1d448..f1ec4e344 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.dart @@ -20,23 +20,40 @@ Map _defaultMap() => null; SimpleObject _defaultSimpleObject() => null; StrictKeysObject _defaultStrictKeysObject() => null; -k.KitchenSink testFactory( - {int ctorValidatedNo42, - Iterable iterable, - Iterable dynamicIterable, - Iterable objectIterable, - Iterable intIterable, - Iterable dateTimeIterable}) => - KitchenSink( +const k.KitchenSinkFactory factory = _Factory(); + +class _Factory implements k.KitchenSinkFactory { + const _Factory(); + + bool get checked => false; + bool get nullable => true; + + k.KitchenSink ctor({ + int ctorValidatedNo42, + Iterable iterable, + Iterable dynamicIterable, + Iterable objectIterable, + Iterable intIterable, + Iterable dateTimeIterable, + }) => + KitchenSink( ctorValidatedNo42: ctorValidatedNo42, iterable: iterable, dynamicIterable: dynamicIterable, objectIterable: objectIterable, intIterable: intIterable, - dateTimeIterable: dateTimeIterable); + dateTimeIterable: dateTimeIterable, + ); -k.KitchenSink testFromJson(Map json) => - KitchenSink.fromJson(json); + k.KitchenSink fromJson(Map json) { + return KitchenSink.fromJson(json.cast()); + } + + k.JsonConverterTestClass jsonConverterCtor() => JsonConverterTestClass(); + + k.JsonConverterTestClass jsonConverterFromJson(Map json) => + JsonConverterTestClass.fromJson(json); +} @JsonSerializable() class KitchenSink implements k.KitchenSink { @@ -56,14 +73,14 @@ class KitchenSink implements k.KitchenSink { @JsonKey(name: 'no-42') final int ctorValidatedNo42; - KitchenSink( - {this.ctorValidatedNo42, - Iterable iterable, - Iterable dynamicIterable, - Iterable objectIterable, - Iterable intIterable, - Iterable dateTimeIterable}) - : _iterable = iterable?.toList() ?? _defaultList(), + KitchenSink({ + this.ctorValidatedNo42, + Iterable iterable, + Iterable dynamicIterable, + Iterable objectIterable, + Iterable intIterable, + Iterable dateTimeIterable, + }) : _iterable = iterable?.toList() ?? _defaultList(), _dynamicIterable = dynamicIterable?.toList() ?? _defaultList(), _objectIterable = objectIterable?.toList() ?? _defaultList(), _intIterable = intIterable?.toList() ?? _defaultList(), @@ -145,7 +162,7 @@ class KitchenSink implements k.KitchenSink { @BigIntStringConverter() @TrivialNumberConverter.instance @EpochDateTimeConverter() -class JsonConverterTestClass { +class JsonConverterTestClass implements k.JsonConverterTestClass { JsonConverterTestClass(); factory JsonConverterTestClass.fromJson(Map json) => diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart index 655416c56..31390d391 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart @@ -20,22 +20,40 @@ Map _defaultMap() => null; SimpleObject _defaultSimpleObject() => null; StrictKeysObject _defaultStrictKeysObject() => null; -k.KitchenSink testFactory( - {int ctorValidatedNo42, - Iterable iterable, - Iterable dynamicIterable, - Iterable objectIterable, - Iterable intIterable, - Iterable dateTimeIterable}) => - KitchenSink( +const k.KitchenSinkFactory factory = _Factory(); + +class _Factory implements k.KitchenSinkFactory { + const _Factory(); + + bool get checked => false; + bool get nullable => true; + + k.KitchenSink ctor({ + int ctorValidatedNo42, + Iterable iterable, + Iterable dynamicIterable, + Iterable objectIterable, + Iterable intIterable, + Iterable dateTimeIterable, + }) => + KitchenSink( ctorValidatedNo42: ctorValidatedNo42, iterable: iterable, dynamicIterable: dynamicIterable, objectIterable: objectIterable, intIterable: intIterable, - dateTimeIterable: dateTimeIterable); + dateTimeIterable: dateTimeIterable, + ); -k.KitchenSink testFromJson(Map json) => KitchenSink.fromJson(json); + k.KitchenSink fromJson(Map json) { + return KitchenSink.fromJson(json); + } + + k.JsonConverterTestClass jsonConverterCtor() => JsonConverterTestClass(); + + k.JsonConverterTestClass jsonConverterFromJson(Map json) => + JsonConverterTestClass.fromJson(json); +} @JsonSerializable( anyMap: true, @@ -57,14 +75,14 @@ class KitchenSink implements k.KitchenSink { @JsonKey(name: 'no-42') final int ctorValidatedNo42; - KitchenSink( - {this.ctorValidatedNo42, - Iterable iterable, - Iterable dynamicIterable, - Iterable objectIterable, - Iterable intIterable, - Iterable dateTimeIterable}) - : _iterable = iterable?.toList() ?? _defaultList(), + KitchenSink({ + this.ctorValidatedNo42, + Iterable iterable, + Iterable dynamicIterable, + Iterable objectIterable, + Iterable intIterable, + Iterable dateTimeIterable, + }) : _iterable = iterable?.toList() ?? _defaultList(), _dynamicIterable = dynamicIterable?.toList() ?? _defaultList(), _objectIterable = objectIterable?.toList() ?? _defaultList(), _intIterable = intIterable?.toList() ?? _defaultList(), @@ -147,7 +165,7 @@ class KitchenSink implements k.KitchenSink { @BigIntStringConverter() @TrivialNumberConverter.instance @EpochDateTimeConverter() -class JsonConverterTestClass { +class JsonConverterTestClass implements k.JsonConverterTestClass { JsonConverterTestClass(); factory JsonConverterTestClass.fromJson(Map json) => diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked__non_nullable.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked__non_nullable.dart index cc5eeb7ad..b200a5bd6 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked__non_nullable.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked__non_nullable.dart @@ -20,22 +20,40 @@ Map _defaultMap() => {}; SimpleObject _defaultSimpleObject() => SimpleObject(42); StrictKeysObject _defaultStrictKeysObject() => StrictKeysObject(10, 'cool'); -k.KitchenSink testFactory( - {int ctorValidatedNo42, - Iterable iterable, - Iterable dynamicIterable, - Iterable objectIterable, - Iterable intIterable, - Iterable dateTimeIterable}) => - KitchenSink( +const k.KitchenSinkFactory factory = _Factory(); + +class _Factory implements k.KitchenSinkFactory { + const _Factory(); + + bool get checked => true; + bool get nullable => false; + + k.KitchenSink ctor({ + int ctorValidatedNo42, + Iterable iterable, + Iterable dynamicIterable, + Iterable objectIterable, + Iterable intIterable, + Iterable dateTimeIterable, + }) => + KitchenSink( ctorValidatedNo42: ctorValidatedNo42, iterable: iterable, dynamicIterable: dynamicIterable, objectIterable: objectIterable, intIterable: intIterable, - dateTimeIterable: dateTimeIterable); + dateTimeIterable: dateTimeIterable, + ); -k.KitchenSink testFromJson(Map json) => KitchenSink.fromJson(json); + k.KitchenSink fromJson(Map json) { + return KitchenSink.fromJson(json); + } + + k.JsonConverterTestClass jsonConverterCtor() => JsonConverterTestClass(); + + k.JsonConverterTestClass jsonConverterFromJson(Map json) => + JsonConverterTestClass.fromJson(json); +} @JsonSerializable( nullable: false, @@ -59,14 +77,14 @@ class KitchenSink implements k.KitchenSink { @JsonKey(name: 'no-42') final int ctorValidatedNo42; - KitchenSink( - {this.ctorValidatedNo42, - Iterable iterable, - Iterable dynamicIterable, - Iterable objectIterable, - Iterable intIterable, - Iterable dateTimeIterable}) - : _iterable = iterable?.toList() ?? _defaultList(), + KitchenSink({ + this.ctorValidatedNo42, + Iterable iterable, + Iterable dynamicIterable, + Iterable objectIterable, + Iterable intIterable, + Iterable dateTimeIterable, + }) : _iterable = iterable?.toList() ?? _defaultList(), _dynamicIterable = dynamicIterable?.toList() ?? _defaultList(), _objectIterable = objectIterable?.toList() ?? _defaultList(), _intIterable = intIterable?.toList() ?? _defaultList(), @@ -151,7 +169,7 @@ class KitchenSink implements k.KitchenSink { @BigIntStringConverter() @TrivialNumberConverter.instance @EpochDateTimeConverter() -class JsonConverterTestClass { +class JsonConverterTestClass implements k.JsonConverterTestClass { JsonConverterTestClass(); factory JsonConverterTestClass.fromJson(Map json) => diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable.dart index d787754f9..9580d0c9c 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable.dart @@ -20,22 +20,40 @@ Map _defaultMap() => {}; SimpleObject _defaultSimpleObject() => SimpleObject(42); StrictKeysObject _defaultStrictKeysObject() => StrictKeysObject(10, 'cool'); -k.KitchenSink testFactory( - {int ctorValidatedNo42, - Iterable iterable, - Iterable dynamicIterable, - Iterable objectIterable, - Iterable intIterable, - Iterable dateTimeIterable}) => - KitchenSink( +const k.KitchenSinkFactory factory = _Factory(); + +class _Factory implements k.KitchenSinkFactory { + const _Factory(); + + bool get checked => false; + bool get nullable => false; + + k.KitchenSink ctor({ + int ctorValidatedNo42, + Iterable iterable, + Iterable dynamicIterable, + Iterable objectIterable, + Iterable intIterable, + Iterable dateTimeIterable, + }) => + KitchenSink( ctorValidatedNo42: ctorValidatedNo42, iterable: iterable, dynamicIterable: dynamicIterable, objectIterable: objectIterable, intIterable: intIterable, - dateTimeIterable: dateTimeIterable); + dateTimeIterable: dateTimeIterable, + ); -k.KitchenSink testFromJson(Map json) => KitchenSink.fromJson(json); + k.KitchenSink fromJson(Map json) { + return KitchenSink.fromJson(json); + } + + k.JsonConverterTestClass jsonConverterCtor() => JsonConverterTestClass(); + + k.JsonConverterTestClass jsonConverterFromJson(Map json) => + JsonConverterTestClass.fromJson(json); +} @JsonSerializable( nullable: false, @@ -58,14 +76,14 @@ class KitchenSink implements k.KitchenSink { @JsonKey(name: 'no-42') final int ctorValidatedNo42; - KitchenSink( - {this.ctorValidatedNo42, - Iterable iterable, - Iterable dynamicIterable, - Iterable objectIterable, - Iterable intIterable, - Iterable dateTimeIterable}) - : _iterable = iterable?.toList() ?? _defaultList(), + KitchenSink({ + this.ctorValidatedNo42, + Iterable iterable, + Iterable dynamicIterable, + Iterable objectIterable, + Iterable intIterable, + Iterable dateTimeIterable, + }) : _iterable = iterable?.toList() ?? _defaultList(), _dynamicIterable = dynamicIterable?.toList() ?? _defaultList(), _objectIterable = objectIterable?.toList() ?? _defaultList(), _intIterable = intIterable?.toList() ?? _defaultList(), @@ -149,7 +167,7 @@ class KitchenSink implements k.KitchenSink { @BigIntStringConverter() @TrivialNumberConverter.instance @EpochDateTimeConverter() -class JsonConverterTestClass { +class JsonConverterTestClass implements k.JsonConverterTestClass { JsonConverterTestClass(); factory JsonConverterTestClass.fromJson(Map json) => diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable__use_wrappers.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable__use_wrappers.dart index 013118e1f..ae6bdb61e 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable__use_wrappers.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable__use_wrappers.dart @@ -20,22 +20,40 @@ Map _defaultMap() => {}; SimpleObject _defaultSimpleObject() => SimpleObject(42); StrictKeysObject _defaultStrictKeysObject() => StrictKeysObject(10, 'cool'); -k.KitchenSink testFactory( - {int ctorValidatedNo42, - Iterable iterable, - Iterable dynamicIterable, - Iterable objectIterable, - Iterable intIterable, - Iterable dateTimeIterable}) => - KitchenSink( +const k.KitchenSinkFactory factory = _Factory(); + +class _Factory implements k.KitchenSinkFactory { + const _Factory(); + + bool get checked => false; + bool get nullable => false; + + k.KitchenSink ctor({ + int ctorValidatedNo42, + Iterable iterable, + Iterable dynamicIterable, + Iterable objectIterable, + Iterable intIterable, + Iterable dateTimeIterable, + }) => + KitchenSink( ctorValidatedNo42: ctorValidatedNo42, iterable: iterable, dynamicIterable: dynamicIterable, objectIterable: objectIterable, intIterable: intIterable, - dateTimeIterable: dateTimeIterable); + dateTimeIterable: dateTimeIterable, + ); -k.KitchenSink testFromJson(Map json) => KitchenSink.fromJson(json); + k.KitchenSink fromJson(Map json) { + return KitchenSink.fromJson(json); + } + + k.JsonConverterTestClass jsonConverterCtor() => JsonConverterTestClass(); + + k.JsonConverterTestClass jsonConverterFromJson(Map json) => + JsonConverterTestClass.fromJson(json); +} @JsonSerializable( useWrappers: true, @@ -59,14 +77,14 @@ class KitchenSink implements k.KitchenSink { @JsonKey(name: 'no-42') final int ctorValidatedNo42; - KitchenSink( - {this.ctorValidatedNo42, - Iterable iterable, - Iterable dynamicIterable, - Iterable objectIterable, - Iterable intIterable, - Iterable dateTimeIterable}) - : _iterable = iterable?.toList() ?? _defaultList(), + KitchenSink({ + this.ctorValidatedNo42, + Iterable iterable, + Iterable dynamicIterable, + Iterable objectIterable, + Iterable intIterable, + Iterable dateTimeIterable, + }) : _iterable = iterable?.toList() ?? _defaultList(), _dynamicIterable = dynamicIterable?.toList() ?? _defaultList(), _objectIterable = objectIterable?.toList() ?? _defaultList(), _intIterable = intIterable?.toList() ?? _defaultList(), @@ -151,7 +169,7 @@ class KitchenSink implements k.KitchenSink { @BigIntStringConverter() @TrivialNumberConverter.instance @EpochDateTimeConverter() -class JsonConverterTestClass { +class JsonConverterTestClass implements k.JsonConverterTestClass { JsonConverterTestClass(); factory JsonConverterTestClass.fromJson(Map json) => diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__use_wrappers.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__use_wrappers.dart index c2a2cc9dc..8d22abefe 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__use_wrappers.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__use_wrappers.dart @@ -20,22 +20,40 @@ Map _defaultMap() => null; SimpleObject _defaultSimpleObject() => null; StrictKeysObject _defaultStrictKeysObject() => null; -k.KitchenSink testFactory( - {int ctorValidatedNo42, - Iterable iterable, - Iterable dynamicIterable, - Iterable objectIterable, - Iterable intIterable, - Iterable dateTimeIterable}) => - KitchenSink( +const k.KitchenSinkFactory factory = _Factory(); + +class _Factory implements k.KitchenSinkFactory { + const _Factory(); + + bool get checked => false; + bool get nullable => true; + + k.KitchenSink ctor({ + int ctorValidatedNo42, + Iterable iterable, + Iterable dynamicIterable, + Iterable objectIterable, + Iterable intIterable, + Iterable dateTimeIterable, + }) => + KitchenSink( ctorValidatedNo42: ctorValidatedNo42, iterable: iterable, dynamicIterable: dynamicIterable, objectIterable: objectIterable, intIterable: intIterable, - dateTimeIterable: dateTimeIterable); + dateTimeIterable: dateTimeIterable, + ); -k.KitchenSink testFromJson(Map json) => KitchenSink.fromJson(json); + k.KitchenSink fromJson(Map json) { + return KitchenSink.fromJson(json); + } + + k.JsonConverterTestClass jsonConverterCtor() => JsonConverterTestClass(); + + k.JsonConverterTestClass jsonConverterFromJson(Map json) => + JsonConverterTestClass.fromJson(json); +} @JsonSerializable( useWrappers: true, @@ -58,14 +76,14 @@ class KitchenSink implements k.KitchenSink { @JsonKey(name: 'no-42') final int ctorValidatedNo42; - KitchenSink( - {this.ctorValidatedNo42, - Iterable iterable, - Iterable dynamicIterable, - Iterable objectIterable, - Iterable intIterable, - Iterable dateTimeIterable}) - : _iterable = iterable?.toList() ?? _defaultList(), + KitchenSink({ + this.ctorValidatedNo42, + Iterable iterable, + Iterable dynamicIterable, + Iterable objectIterable, + Iterable intIterable, + Iterable dateTimeIterable, + }) : _iterable = iterable?.toList() ?? _defaultList(), _dynamicIterable = dynamicIterable?.toList() ?? _defaultList(), _objectIterable = objectIterable?.toList() ?? _defaultList(), _intIterable = intIterable?.toList() ?? _defaultList(), @@ -149,7 +167,7 @@ class KitchenSink implements k.KitchenSink { @BigIntStringConverter() @TrivialNumberConverter.instance @EpochDateTimeConverter() -class JsonConverterTestClass { +class JsonConverterTestClass implements k.JsonConverterTestClass { JsonConverterTestClass(); factory JsonConverterTestClass.fromJson(Map json) => diff --git a/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart b/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart index 265f83bd5..76bd56013 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart @@ -5,6 +5,30 @@ import 'package:collection/collection.dart'; import 'simple_object.dart'; +abstract class KitchenSinkFactory { + bool get checked; + bool get nullable; + + KitchenSink ctor({ + int ctorValidatedNo42, + Iterable iterable, + Iterable dynamicIterable, + Iterable objectIterable, + Iterable intIterable, + Iterable dateTimeIterable, + }); + + KitchenSink fromJson(Map json); + + JsonConverterTestClass jsonConverterCtor(); + + JsonConverterTestClass jsonConverterFromJson(Map json); +} + +abstract class JsonConverterTestClass { + Map toJson(); +} + abstract class KitchenSink { int get ctorValidatedNo42; DateTime dateTime; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink_test.dart b/json_serializable/test/kitchen_sink/kitchen_sink_test.dart index 99fd7bdfb..ebff26bb7 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink_test.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink_test.dart @@ -7,16 +7,13 @@ import 'package:test/test.dart'; import 'package:yaml/yaml.dart'; import '../test_utils.dart'; -import 'kitchen_sink.g_any_map.dart' as nullable - show testFactory, testFromJson, JsonConverterTestClass; +import 'kitchen_sink.g_any_map.dart' as nullable show factory; import 'kitchen_sink.g_any_map__checked__non_nullable.dart' as checked - show testFactory, testFromJson; -import 'kitchen_sink.g_any_map__non_nullable.dart' as nn - show testFactory, testFromJson, JsonConverterTestClass; -import 'kitchen_sink.g_any_map__non_nullable__use_wrappers.dart' as nnwrapped - show testFactory, testFromJson; -import 'kitchen_sink.g_any_map__use_wrappers.dart' as wrapped - show testFactory, testFromJson; + show factory; +import 'kitchen_sink.g_any_map__non_nullable.dart' as non_null show factory; +import 'kitchen_sink.g_any_map__non_nullable__use_wrappers.dart' + as non_null_wrapped show factory; +import 'kitchen_sink.g_any_map__use_wrappers.dart' as wrapped show factory; import 'kitchen_sink_interface.dart'; import 'strict_keys_object.dart'; @@ -26,7 +23,7 @@ const _toJsonMapHelperName = 'writeNotNull'; final _isATypeError = const TypeMatcher(); -Matcher _isAUnrecognizedKeysEexception(expectedMessage) => +Matcher _isAUnrecognizedKeysException(expectedMessage) => const TypeMatcher() .having((e) => e.message, 'message', expectedMessage); @@ -46,100 +43,81 @@ void main() { 'Required keys are missing: value, custom_field.'))); }); - group('nullable', () { - group('unwrapped', () { - _nullableTests(nullable.testFactory, nullable.testFromJson); - }); - - group('wrapped', () { - _nullableTests(wrapped.testFactory, wrapped.testFromJson); - }); - }); - - group('non-nullable', () { - group('checked', () { - _nonNullableTests(checked.testFactory, checked.testFromJson, - isChecked: true); - }); - - group('unwrapped', () { - _nonNullableTests(nn.testFactory, nn.testFromJson); - }); - - group('wrapped', () { - _nonNullableTests(nnwrapped.testFactory, nnwrapped.testFromJson); - }); - }); - - group('JsonConverterTestClass', () { - final validValues = { - 'duration': 5, - 'durationList': [5], - 'bigInt': '5', - 'bigIntMap': {'vaule': '5'}, - 'numberSilly': 5, - 'numberSillySet': [5], - 'dateTime': 5 - }; - - test('nullable values are allowed in the nullable version', () { - final instance = nullable.JsonConverterTestClass(); - final json = instance.toJson(); - expect(json.values, everyElement(isNull)); - expect(json.keys, unorderedEquals(validValues.keys)); - - final instance2 = nullable.JsonConverterTestClass.fromJson(json); - expect(instance2.toJson(), json); - }); - - test('nullable values are not allowed in non-nullable version', () { - var instance = nn.JsonConverterTestClass(); - expect(() => instance.toJson(), throwsNoSuchMethodError, - reason: 'Trying to call `map` on a null list'); - - instance = nn.JsonConverterTestClass.fromJson(validValues); - final json = instance.toJson(); - expect(json, validValues); - expect(json.values, everyElement(isNotNull)); + for (var factory in [ + nullable.factory, + checked.factory, + non_null.factory, + non_null_wrapped.factory, + wrapped.factory, + ]) { + if (factory.nullable) { + _nullableTests(factory); + } else { + _nonNullableTests(factory, isChecked: factory.checked); + } - final instance2 = nn.JsonConverterTestClass.fromJson(json); - expect(instance2.toJson(), json); - }); - }); + _sharedTests(factory, isChecked: factory.checked); + } } -typedef KitchenSinkCtor = KitchenSink Function( - {int ctorValidatedNo42, - Iterable iterable, - Iterable dynamicIterable, - Iterable objectIterable, - Iterable intIterable, - Iterable dateTimeIterable}); +const _jsonConverterValidValues = { + 'duration': 5, + 'durationList': [5], + 'bigInt': '5', + 'bigIntMap': {'vaule': '5'}, + 'numberSilly': 5, + 'numberSillySet': [5], + 'dateTime': 5 +}; -void _nonNullableTests(KitchenSinkCtor ctor, KitchenSink fromJson(Map json), - {bool isChecked = false}) { +void _nonNullableTests(KitchenSinkFactory factory, {bool isChecked = false}) { test('with null values fails serialization', () { - expect(() => (ctor()..objectDateTimeMap = null).toJson(), + expect(() => (factory.ctor()..objectDateTimeMap = null).toJson(), throwsNoSuchMethodError); }); test('with empty json fails deserialization', () { if (isChecked) { - expect(() => fromJson({}), throwsA(_checkedMatcher('intIterable'))); + expect( + () => factory.fromJson({}), throwsA(_checkedMatcher('intIterable'))); } else { - expect(() => fromJson({}), throwsNoSuchMethodError); + expect(() => factory.fromJson({}), throwsNoSuchMethodError); } }); - _sharedTests(ctor, fromJson, isChecked: isChecked); + + test('nullable values are not allowed in non-nullable version', () { + var instance = non_null.factory.jsonConverterCtor(); + expect(() => instance.toJson(), throwsNoSuchMethodError, + reason: 'Trying to call `map` on a null list'); + + instance = + non_null.factory.jsonConverterFromJson(_jsonConverterValidValues); + final json = instance.toJson(); + expect(json, _jsonConverterValidValues); + expect(json.values, everyElement(isNotNull)); + + final instance2 = non_null.factory.jsonConverterFromJson(json); + expect(instance2.toJson(), json); + }); } -void _nullableTests(KitchenSinkCtor ctor, KitchenSink fromJson(Map json)) { +void _nullableTests(KitchenSinkFactory factory) { void roundTripItem(KitchenSink p) { - roundTripObject(p, (json) => fromJson(json)); + roundTripObject(p, (json) => factory.fromJson(json)); } + test('nullable values are allowed in the nullable version', () { + final instance = nullable.factory.jsonConverterCtor(); + final json = instance.toJson(); + expect(json.values, everyElement(isNull)); + expect(json.keys, unorderedEquals(_jsonConverterValidValues.keys)); + + final instance2 = nullable.factory.jsonConverterFromJson(json); + expect(instance2.toJson(), json); + }); + test('Fields with `!includeIfNull` should not be included when null', () { - final item = ctor(); + final item = factory.ctor(); final expectedDefaultKeys = _validValues.keys.toSet() ..removeAll(_excludeIfNullKeys); @@ -155,7 +133,7 @@ void _nullableTests(KitchenSinkCtor ctor, KitchenSink fromJson(Map json)) { test('list and map of DateTime', () { final now = DateTime.now(); - final item = ctor(dateTimeIterable: [now]) + final item = factory.ctor(dateTimeIterable: [now]) ..dateTimeList = [now, null] ..objectDateTimeMap = {'value': now, 'null': null}; @@ -163,7 +141,7 @@ void _nullableTests(KitchenSinkCtor ctor, KitchenSink fromJson(Map json)) { }); test('complex nested type', () { - final item = ctor() + final item = factory.ctor() ..crazyComplex = [ null, {}, @@ -183,24 +161,21 @@ void _nullableTests(KitchenSinkCtor ctor, KitchenSink fromJson(Map json)) { ]; roundTripItem(item); }); - - _sharedTests(ctor, fromJson); } -void _sharedTests(KitchenSinkCtor ctor, KitchenSink fromJson(Map json), - {bool isChecked = false}) { +void _sharedTests(KitchenSinkFactory factory, {bool isChecked = false}) { void roundTripSink(KitchenSink p) { - roundTripObject(p, fromJson); + roundTripObject(p, factory.fromJson); } test('empty', () { - final item = ctor(); + final item = factory.ctor(); roundTripSink(item); }); test('list and map of DateTime - not null', () { final now = DateTime.now(); - final item = ctor(dateTimeIterable: [now]) + final item = factory.ctor(dateTimeIterable: [now]) ..dateTimeList = [now, now] ..objectDateTimeMap = {'value': now}; @@ -208,7 +183,7 @@ void _sharedTests(KitchenSinkCtor ctor, KitchenSink fromJson(Map json), }); test('complex nested type - not null', () { - final item = ctor() + final item = factory.ctor() ..crazyComplex = [ {}, { @@ -228,7 +203,7 @@ void _sharedTests(KitchenSinkCtor ctor, KitchenSink fromJson(Map json), test('JSON keys should be defined in field/property order', () { /// Explicitly setting values from [_excludeIfNullKeys] to ensure /// they exist for KitchenSink where they are excluded when null - final item = ctor(iterable: []) + final item = factory.ctor(iterable: []) ..dateTime = DateTime.now() ..dateTimeList = [] ..crazyComplex = [] @@ -239,21 +214,22 @@ void _sharedTests(KitchenSinkCtor ctor, KitchenSink fromJson(Map json), }); test('valid values round-trip - json', () { - expect(loudEncode(_validValues), loudEncode(fromJson(_validValues))); + expect( + loudEncode(_validValues), loudEncode(factory.fromJson(_validValues))); }); test('valid values round-trip - yaml', () { final jsonEncoded = loudEncode(_validValues); final yaml = loadYaml(jsonEncoded, sourceUrl: 'input.yaml'); - expect(jsonEncoded, loudEncode(fromJson(yaml as YamlMap))); + expect(jsonEncoded, loudEncode(factory.fromJson(yaml as YamlMap))); }); group('a bad value for', () { for (final e in _invalidValueTypes.entries) { - _testBadValue(isChecked, e.key, e.value, fromJson, false); + _testBadValue(isChecked, e.key, e.value, factory.fromJson, false); } for (final e in _invalidCheckedValues.entries) { - _testBadValue(isChecked, e.key, e.value, fromJson, true); + _testBadValue(isChecked, e.key, e.value, factory.fromJson, true); } }); } @@ -296,7 +272,7 @@ Matcher _getMatcher(bool checked, String expectedKey, bool checkedAssignment) { innerMatcher = anyOf( isCastError, _isATypeError, - _isAUnrecognizedKeysEexception( + _isAUnrecognizedKeysException( 'Unrecognized keys: [invalid_key]; supported keys: [value, custom_field]')); if (checkedAssignment) { @@ -308,7 +284,7 @@ Matcher _getMatcher(bool checked, String expectedKey, bool checkedAssignment) { innerMatcher = isArgumentError; break; case 'strictKeysObject': - innerMatcher = _isAUnrecognizedKeysEexception('bob'); + innerMatcher = _isAUnrecognizedKeysException('bob'); break; case 'intIterable': case 'datetime-iterable': diff --git a/json_serializable/tool/builder.dart b/json_serializable/tool/builder.dart index 677157eca..82b597907 100644 --- a/json_serializable/tool/builder.dart +++ b/json_serializable/tool/builder.dart @@ -95,8 +95,8 @@ Iterable<_Replacement> _optionReplacement( if (baseName == 'kitchen_sink') { yield _Replacement( - 'testFromJson(Map json)', - 'testFromJson(Map json)', + 'return KitchenSink.fromJson(json.cast());', + 'return KitchenSink.fromJson(json);', ); yield _Replacement( 'factory KitchenSink.fromJson(Map json)', @@ -108,6 +108,12 @@ Iterable<_Replacement> _optionReplacement( case 'checked': if (value) { yield _Replacement.addJsonSerializableKey('checked', true); + if (baseName == 'kitchen_sink') { + yield _Replacement( + 'bool get checked => false;', + 'bool get checked => true;', + ); + } } break; case 'non_nullable': @@ -115,20 +121,35 @@ Iterable<_Replacement> _optionReplacement( yield _Replacement.addJsonSerializableKey('nullable', false); if (baseName == 'kitchen_sink') { - yield _Replacement('List _defaultList() => null;', - 'List _defaultList() => [];'); - yield _Replacement('Set _defaultSet() => null;', - 'Set _defaultSet() => Set();'); - yield _Replacement('Map _defaultMap() => null;', - 'Map _defaultMap() => {};'); - yield _Replacement('SimpleObject _defaultSimpleObject() => null;', - 'SimpleObject _defaultSimpleObject() => SimpleObject(42);'); yield _Replacement( - 'StrictKeysObject _defaultStrictKeysObject() => null;', - 'StrictKeysObject _defaultStrictKeysObject() => ' - "StrictKeysObject(10, 'cool');"); - yield _Replacement('DateTime dateTime;', - 'DateTime dateTime = DateTime(1981, 6, 5);'); + 'List _defaultList() => null;', + 'List _defaultList() => [];', + ); + yield _Replacement( + 'Set _defaultSet() => null;', + 'Set _defaultSet() => Set();', + ); + yield _Replacement( + 'Map _defaultMap() => null;', + 'Map _defaultMap() => {};', + ); + yield _Replacement( + 'SimpleObject _defaultSimpleObject() => null;', + 'SimpleObject _defaultSimpleObject() => SimpleObject(42);', + ); + yield _Replacement( + 'StrictKeysObject _defaultStrictKeysObject() => null;', + 'StrictKeysObject _defaultStrictKeysObject() => ' + "StrictKeysObject(10, 'cool');", + ); + yield _Replacement( + 'DateTime dateTime;', + 'DateTime dateTime = DateTime(1981, 6, 5);', + ); + yield _Replacement( + 'bool get nullable => true;', + 'bool get nullable => false;', + ); } } break; @@ -218,10 +239,10 @@ class _Replacement { for (final r in replacements) { if (!outputContent.contains(r.existing)) { - throw StateError( - 'Input string did not contain `${r.existing}` as expected.'); + print('Input string did not contain `${r.existing}` as expected.'); + } else { + outputContent = outputContent.replaceAll(r.existing, r.replacement); } - outputContent = outputContent.replaceAll(r.existing, r.replacement); } outputContent = outputContent.replaceAll(',)', ',\n)'); From d509d9dfb29160352364db7996c4cdb0126f5de5 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 13 Mar 2019 21:55:45 -0700 Subject: [PATCH 074/569] builder cleanup Eliminate unused members Use lists instead of maps --- json_serializable/tool/builder.dart | 177 +++++++++++----------------- 1 file changed, 69 insertions(+), 108 deletions(-) diff --git a/json_serializable/tool/builder.dart b/json_serializable/tool/builder.dart index 82b597907..f3ab62421 100644 --- a/json_serializable/tool/builder.dart +++ b/json_serializable/tool/builder.dart @@ -67,9 +67,8 @@ class _SmartBuilder implements Builder { ) ]; - for (var entry in config.entries) { - replacements - .addAll(_optionReplacement(baseName, entry.key, entry.value)); + for (var entry in config) { + replacements.addAll(_optionReplacement(baseName, entry)); } final content = _Replacement.generate(sourceContent, replacements); @@ -84,118 +83,79 @@ class _SmartBuilder implements Builder { } Iterable<_Replacement> _optionReplacement( - String baseName, - String optionKey, - bool value, -) sync* { + String baseName, String optionKey) sync* { switch (optionKey) { case 'any_map': - if (value) { - yield _Replacement.addJsonSerializableKey('anyMap', true); - - if (baseName == 'kitchen_sink') { - yield _Replacement( - 'return KitchenSink.fromJson(json.cast());', - 'return KitchenSink.fromJson(json);', - ); - yield _Replacement( - 'factory KitchenSink.fromJson(Map json)', - 'factory KitchenSink.fromJson(Map json)', - ); - } + yield _Replacement.addJsonSerializableKey('anyMap', true); + + if (baseName == 'kitchen_sink') { + yield _Replacement( + 'return KitchenSink.fromJson(json.cast());', + 'return KitchenSink.fromJson(json);', + ); + yield _Replacement( + 'factory KitchenSink.fromJson(Map json)', + 'factory KitchenSink.fromJson(Map json)', + ); } break; case 'checked': - if (value) { - yield _Replacement.addJsonSerializableKey('checked', true); - if (baseName == 'kitchen_sink') { - yield _Replacement( - 'bool get checked => false;', - 'bool get checked => true;', - ); - } + yield _Replacement.addJsonSerializableKey('checked', true); + if (baseName == 'kitchen_sink') { + yield _Replacement( + 'bool get checked => false;', + 'bool get checked => true;', + ); } break; case 'non_nullable': - if (value) { - yield _Replacement.addJsonSerializableKey('nullable', false); - - if (baseName == 'kitchen_sink') { - yield _Replacement( - 'List _defaultList() => null;', - 'List _defaultList() => [];', - ); - yield _Replacement( - 'Set _defaultSet() => null;', - 'Set _defaultSet() => Set();', - ); - yield _Replacement( - 'Map _defaultMap() => null;', - 'Map _defaultMap() => {};', - ); - yield _Replacement( - 'SimpleObject _defaultSimpleObject() => null;', - 'SimpleObject _defaultSimpleObject() => SimpleObject(42);', - ); - yield _Replacement( - 'StrictKeysObject _defaultStrictKeysObject() => null;', - 'StrictKeysObject _defaultStrictKeysObject() => ' - "StrictKeysObject(10, 'cool');", - ); - yield _Replacement( - 'DateTime dateTime;', - 'DateTime dateTime = DateTime(1981, 6, 5);', - ); - yield _Replacement( - 'bool get nullable => true;', - 'bool get nullable => false;', - ); - } + yield _Replacement.addJsonSerializableKey('nullable', false); + + if (baseName == 'kitchen_sink') { + yield _Replacement( + 'List _defaultList() => null;', + 'List _defaultList() => [];', + ); + yield _Replacement( + 'Set _defaultSet() => null;', + 'Set _defaultSet() => Set();', + ); + yield _Replacement( + 'Map _defaultMap() => null;', + 'Map _defaultMap() => {};', + ); + yield _Replacement( + 'SimpleObject _defaultSimpleObject() => null;', + 'SimpleObject _defaultSimpleObject() => SimpleObject(42);', + ); + yield _Replacement( + 'StrictKeysObject _defaultStrictKeysObject() => null;', + 'StrictKeysObject _defaultStrictKeysObject() => ' + "StrictKeysObject(10, 'cool');", + ); + yield _Replacement( + 'DateTime dateTime;', + 'DateTime dateTime = DateTime(1981, 6, 5);', + ); + yield _Replacement( + 'bool get nullable => true;', + 'bool get nullable => false;', + ); } break; case 'use_wrappers': - if (value) { - yield _Replacement.addJsonSerializableKey('useWrappers', true); - } + yield _Replacement.addJsonSerializableKey('useWrappers', true); break; default: throw UnimplementedError('not yet!: $optionKey'); } } -String _configToExtension(Map config) => - '.g_${_configToName(config)}.dart'; - -String _configToName(Map config) => - (config.entries.where((e) => e.value != false).map((e) => e.key).toList() - ..sort()) - .join('__'); - -const _options = >{ - 'any_map': [false, true], - 'checked': [false, true], - 'use_wrappers': [false, true], - 'non_nullable': [false, true], -}; +String _configToExtension(Iterable config) => + '.g_${_configToName(config.toSet())}.dart'; -Iterable> allConfigurations({ - Map parts = const {}, -}) sync* { - assert(parts.length <= _options.length); - if (parts.length == _options.length) { - if (parts.values.any((v) => v)) { - yield parts; - } - } else { - final entry = _options.entries.skip(parts.length).first; - for (var option in entry.value) { - final newMap = Map.of(parts); - assert(!newMap.containsKey(entry.key)); - newMap[entry.key] = option; - yield* allConfigurations(parts: newMap); - } - } -} +String _configToName(Set config) => + (config.toList()..sort()).join('__'); List get _fileConfigurations => _fileConfigurationMap.values .expand((v) => v) @@ -203,24 +163,25 @@ List get _fileConfigurations => _fileConfigurationMap.values .toSet() .toList(); -const _fileConfigurationMap = { +// TODO: use a set of sets, once we're >=2.2.0 +const _fileConfigurationMap = >>{ 'kitchen_sink': [ - {'any_map': true}, - {'any_map': true, 'checked': true, 'non_nullable': true}, - {'any_map': true, 'non_nullable': true}, - {'any_map': true, 'non_nullable': true, 'use_wrappers': true}, - {'any_map': true, 'use_wrappers': true}, + ['any_map'], + ['any_map', 'checked', 'non_nullable'], + ['any_map', 'non_nullable'], + ['any_map', 'non_nullable', 'use_wrappers'], + ['any_map', 'use_wrappers'], ], 'default_value': [ - {'any_map': true, 'checked': true}, + ['any_map', 'checked'], ], 'generic_class': [ - {'use_wrappers': true}, + ['use_wrappers'], ], 'json_test_example': [ - {'non_nullable': true, 'use_wrappers': true}, - {'non_nullable': true}, - {'use_wrappers': true}, + ['non_nullable', 'use_wrappers'], + ['non_nullable'], + ['use_wrappers'], ] }; From 6299ba260b85fe4ea2ab5403cea67d57c3113612 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 14 Mar 2019 08:42:16 -0700 Subject: [PATCH 075/569] Add a description to KitchenSinkFactory, use it in tests --- .../test/kitchen_sink/kitchen_sink.dart | 1 + .../test/kitchen_sink/kitchen_sink.g_any_map.dart | 1 + ...chen_sink.g_any_map__checked__non_nullable.dart | 1 + .../kitchen_sink.g_any_map__non_nullable.dart | 1 + ...sink.g_any_map__non_nullable__use_wrappers.dart | 1 + .../kitchen_sink.g_any_map__use_wrappers.dart | 1 + .../test/kitchen_sink/kitchen_sink_interface.dart | 4 ++++ .../test/kitchen_sink/kitchen_sink_test.dart | 14 ++++++++------ json_serializable/tool/builder.dart | 8 ++++++++ 9 files changed, 26 insertions(+), 6 deletions(-) diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.dart b/json_serializable/test/kitchen_sink/kitchen_sink.dart index f1ec4e344..de65c86d1 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.dart @@ -25,6 +25,7 @@ const k.KitchenSinkFactory factory = _Factory(); class _Factory implements k.KitchenSinkFactory { const _Factory(); + String get description => '--defaults--'; bool get checked => false; bool get nullable => true; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart index 31390d391..c7367f649 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart @@ -25,6 +25,7 @@ const k.KitchenSinkFactory factory = _Factory(); class _Factory implements k.KitchenSinkFactory { const _Factory(); + String get description => 'any_map'; bool get checked => false; bool get nullable => true; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked__non_nullable.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked__non_nullable.dart index b200a5bd6..7d778f3d9 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked__non_nullable.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked__non_nullable.dart @@ -25,6 +25,7 @@ const k.KitchenSinkFactory factory = _Factory(); class _Factory implements k.KitchenSinkFactory { const _Factory(); + String get description => 'any_map__checked__non_nullable'; bool get checked => true; bool get nullable => false; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable.dart index 9580d0c9c..ed3eb07bd 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable.dart @@ -25,6 +25,7 @@ const k.KitchenSinkFactory factory = _Factory(); class _Factory implements k.KitchenSinkFactory { const _Factory(); + String get description => 'any_map__non_nullable'; bool get checked => false; bool get nullable => false; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable__use_wrappers.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable__use_wrappers.dart index ae6bdb61e..4813cb29a 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable__use_wrappers.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable__use_wrappers.dart @@ -25,6 +25,7 @@ const k.KitchenSinkFactory factory = _Factory(); class _Factory implements k.KitchenSinkFactory { const _Factory(); + String get description => 'any_map__non_nullable__use_wrappers'; bool get checked => false; bool get nullable => false; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__use_wrappers.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__use_wrappers.dart index 8d22abefe..1458e5387 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__use_wrappers.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__use_wrappers.dart @@ -25,6 +25,7 @@ const k.KitchenSinkFactory factory = _Factory(); class _Factory implements k.KitchenSinkFactory { const _Factory(); + String get description => 'any_map__use_wrappers'; bool get checked => false; bool get nullable => true; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart b/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart index 76bd56013..829fdeb42 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart @@ -6,6 +6,7 @@ import 'package:collection/collection.dart'; import 'simple_object.dart'; abstract class KitchenSinkFactory { + String get description; bool get checked; bool get nullable; @@ -23,6 +24,9 @@ abstract class KitchenSinkFactory { JsonConverterTestClass jsonConverterCtor(); JsonConverterTestClass jsonConverterFromJson(Map json); + + @override + String toString() => description; } abstract class JsonConverterTestClass { diff --git a/json_serializable/test/kitchen_sink/kitchen_sink_test.dart b/json_serializable/test/kitchen_sink/kitchen_sink_test.dart index ebff26bb7..31fe52094 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink_test.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink_test.dart @@ -50,13 +50,15 @@ void main() { non_null_wrapped.factory, wrapped.factory, ]) { - if (factory.nullable) { - _nullableTests(factory); - } else { - _nonNullableTests(factory, isChecked: factory.checked); - } + group(factory.description, () { + if (factory.nullable) { + _nullableTests(factory); + } else { + _nonNullableTests(factory, isChecked: factory.checked); + } - _sharedTests(factory, isChecked: factory.checked); + _sharedTests(factory, isChecked: factory.checked); + }); } } diff --git a/json_serializable/tool/builder.dart b/json_serializable/tool/builder.dart index f3ab62421..9fce91772 100644 --- a/json_serializable/tool/builder.dart +++ b/json_serializable/tool/builder.dart @@ -67,6 +67,14 @@ class _SmartBuilder implements Builder { ) ]; + if (baseName == 'kitchen_sink') { + final description = _configToName(config.toSet()); + replacements.add(_Replacement( + "String get description => '--defaults--';", + "String get description => '$description';", + )); + } + for (var entry in config) { replacements.addAll(_optionReplacement(baseName, entry)); } From 37cfe4abe87d97af17f2abd763983a5fc4904f06 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 14 Mar 2019 11:23:56 -0700 Subject: [PATCH 076/569] Remove static verification from kitchen sink tests --- .../test/json_serializable_test.dart | 1 + .../test/kitchen_sink/kitchen_sink.dart | 5 ----- .../kitchen_sink/kitchen_sink.g_any_map.dart | 5 ----- ...sink.g_any_map__checked__non_nullable.dart | 5 ----- .../kitchen_sink.g_any_map__non_nullable.dart | 5 ----- ...g_any_map__non_nullable__use_wrappers.dart | 5 ----- .../kitchen_sink.g_any_map__use_wrappers.dart | 5 ----- .../src/_json_serializable_test_input.dart | 19 +++++++++++++++++++ 8 files changed, 20 insertions(+), 30 deletions(-) diff --git a/json_serializable/test/json_serializable_test.dart b/json_serializable/test/json_serializable_test.dart index aee2d0d02..736781b1a 100644 --- a/json_serializable/test/json_serializable_test.dart +++ b/json_serializable/test/json_serializable_test.dart @@ -87,6 +87,7 @@ const _expectedAnnotatedTests = [ 'OkayOneNormalOptionalNamed', 'OkayOneNormalOptionalPositional', 'OkayOnlyOptionalPositional', + 'OnlyStaticMembers', 'PrivateFieldCtorClass', 'SetSupport', 'SubType', diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.dart b/json_serializable/test/kitchen_sink/kitchen_sink.dart index de65c86d1..78884cf2c 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.dart @@ -58,11 +58,6 @@ class _Factory implements k.KitchenSinkFactory { @JsonSerializable() class KitchenSink implements k.KitchenSink { - // To ensure static members are not considered for serialization. - static const answer = 42; - static final reason = 42; - static int get understand => 42; - // NOTE: exposing these as Iterable, but storing the values as List // to make the equality test work trivially. final Iterable _iterable; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart index c7367f649..0284c827f 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart @@ -60,11 +60,6 @@ class _Factory implements k.KitchenSinkFactory { anyMap: true, ) class KitchenSink implements k.KitchenSink { - // To ensure static members are not considered for serialization. - static const answer = 42; - static final reason = 42; - static int get understand => 42; - // NOTE: exposing these as Iterable, but storing the values as List // to make the equality test work trivially. final Iterable _iterable; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked__non_nullable.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked__non_nullable.dart index 7d778f3d9..1d956051f 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked__non_nullable.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked__non_nullable.dart @@ -62,11 +62,6 @@ class _Factory implements k.KitchenSinkFactory { anyMap: true, ) class KitchenSink implements k.KitchenSink { - // To ensure static members are not considered for serialization. - static const answer = 42; - static final reason = 42; - static int get understand => 42; - // NOTE: exposing these as Iterable, but storing the values as List // to make the equality test work trivially. final Iterable _iterable; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable.dart index ed3eb07bd..632e7802d 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable.dart @@ -61,11 +61,6 @@ class _Factory implements k.KitchenSinkFactory { anyMap: true, ) class KitchenSink implements k.KitchenSink { - // To ensure static members are not considered for serialization. - static const answer = 42; - static final reason = 42; - static int get understand => 42; - // NOTE: exposing these as Iterable, but storing the values as List // to make the equality test work trivially. final Iterable _iterable; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable__use_wrappers.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable__use_wrappers.dart index 4813cb29a..205fa534f 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable__use_wrappers.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable__use_wrappers.dart @@ -62,11 +62,6 @@ class _Factory implements k.KitchenSinkFactory { anyMap: true, ) class KitchenSink implements k.KitchenSink { - // To ensure static members are not considered for serialization. - static const answer = 42; - static final reason = 42; - static int get understand => 42; - // NOTE: exposing these as Iterable, but storing the values as List // to make the equality test work trivially. final Iterable _iterable; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__use_wrappers.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__use_wrappers.dart index 1458e5387..b18fcf04d 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__use_wrappers.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__use_wrappers.dart @@ -61,11 +61,6 @@ class _Factory implements k.KitchenSinkFactory { anyMap: true, ) class KitchenSink implements k.KitchenSink { - // To ensure static members are not considered for serialization. - static const answer = 42; - static final reason = 42; - static int get understand => 42; - // NOTE: exposing these as Iterable, but storing the values as List // to make the equality test work trivially. final Iterable _iterable; diff --git a/json_serializable/test/src/_json_serializable_test_input.dart b/json_serializable/test/src/_json_serializable_test_input.dart index ee5105af6..b5a71a91e 100644 --- a/json_serializable/test/src/_json_serializable_test_input.dart +++ b/json_serializable/test/src/_json_serializable_test_input.dart @@ -28,6 +28,25 @@ const theAnswer = 42; @JsonSerializable() void annotatedMethod() => null; +@ShouldGenerate( + r''' +OnlyStaticMembers _$OnlyStaticMembersFromJson(Map json) { + return OnlyStaticMembers(); +} + +Map _$OnlyStaticMembersToJson(OnlyStaticMembers instance) => + {}; +''', + configurations: ['default'], +) +@JsonSerializable() +class OnlyStaticMembers { + // To ensure static members are not considered for serialization. + static const answer = 42; + static final reason = 42; + static int get understand => 42; +} + @ShouldGenerate( r''' GeneralTestClass1 _$GeneralTestClass1FromJson(Map json) { From e7ec70ebd5bf6e03aa54990e15b0d78e57448db9 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 14 Mar 2019 11:17:13 -0700 Subject: [PATCH 077/569] Add support for dart:core BigInt type Fixes https://github.com/dart-lang/json_serializable/issues/412 --- json_serializable/CHANGELOG.md | 6 +++ .../lib/src/json_serializable_generator.dart | 14 ++++-- .../lib/src/type_helpers/big_int_helper.dart | 46 +++++++++++++++++++ json_serializable/lib/type_helper.dart | 1 + json_serializable/pubspec.yaml | 2 +- .../test/kitchen_sink/kitchen_sink.dart | 3 ++ .../test/kitchen_sink/kitchen_sink.g.dart | 3 ++ .../kitchen_sink/kitchen_sink.g_any_map.dart | 3 ++ .../kitchen_sink.g_any_map.g.dart | 3 ++ ...sink.g_any_map__checked__non_nullable.dart | 5 +- ...nk.g_any_map__checked__non_nullable.g.dart | 3 ++ .../kitchen_sink.g_any_map__non_nullable.dart | 5 +- ...itchen_sink.g_any_map__non_nullable.g.dart | 2 + ...g_any_map__non_nullable__use_wrappers.dart | 5 +- ...any_map__non_nullable__use_wrappers.g.dart | 4 ++ .../kitchen_sink.g_any_map__use_wrappers.dart | 3 ++ ...itchen_sink.g_any_map__use_wrappers.g.dart | 7 +++ .../kitchen_sink/kitchen_sink_interface.dart | 1 + .../test/kitchen_sink/kitchen_sink_test.dart | 4 ++ json_serializable/tool/builder.dart | 4 ++ 20 files changed, 115 insertions(+), 9 deletions(-) create mode 100644 json_serializable/lib/src/type_helpers/big_int_helper.dart diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 2efcf8402..7f2b77eed 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,9 @@ +## 2.1.0 + +* Added support for `BigInt`. + +* Added `BigIntTypeHelper` to `type_helper.dart` library. + ## 2.0.3 * When invoking a `fromJson` constructor on a field type, generate a conversion diff --git a/json_serializable/lib/src/json_serializable_generator.dart b/json_serializable/lib/src/json_serializable_generator.dart index 228ff7bb6..68ef09fd3 100644 --- a/json_serializable/lib/src/json_serializable_generator.dart +++ b/json_serializable/lib/src/json_serializable_generator.dart @@ -12,6 +12,7 @@ import 'encoder_helper.dart'; import 'field_helpers.dart'; import 'helper_core.dart'; import 'type_helper.dart'; +import 'type_helpers/big_int_helper.dart'; import 'type_helpers/convert_helper.dart'; import 'type_helpers/date_time_helper.dart'; import 'type_helpers/duration_helper.dart'; @@ -34,10 +35,11 @@ class JsonSerializableGenerator ]; static const _defaultHelpers = [ - JsonHelper(), + BigIntHelper(), DateTimeHelper(), - UriHelper(), DurationHelper(), + JsonHelper(), + UriHelper(), ]; final List _typeHelpers; @@ -53,8 +55,9 @@ class JsonSerializableGenerator /// Creates an instance of [JsonSerializableGenerator]. /// - /// If [typeHelpers] is not provided, three built-in helpers are used: - /// [JsonHelper], [DateTimeHelper], [DurationHelper] and [UriHelper]. + /// If [typeHelpers] is not provided, the built-in helpers are used: + /// [BigIntHelper], [DateTimeHelper], [DurationHelper], [JsonHelper], and + /// [UriHelper]. const JsonSerializableGenerator({ JsonSerializable config, List typeHelpers, @@ -65,7 +68,8 @@ class JsonSerializableGenerator /// /// [typeHelpers] provides a set of [TypeHelper] that will be used along with /// the built-in helpers: - /// [JsonHelper], [DateTimeHelper], [DurationHelper] and [UriHelper]. + /// [BigIntHelper], [DateTimeHelper], [DurationHelper], [JsonHelper], and + /// [UriHelper]. factory JsonSerializableGenerator.withDefaultHelpers( Iterable typeHelpers, {JsonSerializable config}) => diff --git a/json_serializable/lib/src/type_helpers/big_int_helper.dart b/json_serializable/lib/src/type_helpers/big_int_helper.dart new file mode 100644 index 000000000..61f781ae7 --- /dev/null +++ b/json_serializable/lib/src/type_helpers/big_int_helper.dart @@ -0,0 +1,46 @@ +// Copyright (c) 2018, 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:analyzer/dart/element/type.dart'; +import 'package:source_gen/source_gen.dart' show TypeChecker; +import '../type_helper.dart'; + +class BigIntHelper extends TypeHelper { + const BigIntHelper(); + + @override + String serialize( + DartType targetType, String expression, TypeHelperContext context) { + if (!_matchesType(targetType)) { + return null; + } + + final buffer = StringBuffer(expression); + + if (context.nullable) { + buffer.write('?'); + } + + buffer.write('.toString()'); + + return buffer.toString(); + } + + @override + String deserialize( + DartType targetType, String expression, TypeHelperContext context) { + if (!_matchesType(targetType)) { + return null; + } + + return commonNullPrefix( + context.nullable, + expression, + 'BigInt.parse($expression as String)', + ).toString(); + } +} + +bool _matchesType(DartType type) => + const TypeChecker.fromUrl('dart:core#BigInt').isExactlyType(type); diff --git a/json_serializable/lib/type_helper.dart b/json_serializable/lib/type_helper.dart index 81cf59f75..167123fd0 100644 --- a/json_serializable/lib/type_helper.dart +++ b/json_serializable/lib/type_helper.dart @@ -5,6 +5,7 @@ export 'src/shared_checkers.dart' show simpleJsonTypeChecker, typeArgumentsOf; export 'src/type_helper.dart' show TypeHelperContext, TypeHelper, UnsupportedTypeError; +export 'src/type_helpers/big_int_helper.dart'; export 'src/type_helpers/convert_helper.dart'; export 'src/type_helpers/date_time_helper.dart'; export 'src/type_helpers/enum_helper.dart'; diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index d061e5c7b..cd4f56834 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 2.0.3 +version: 2.1.0-dev author: Dart Team description: >- Automatically generate code for converting to and from JSON by annotating diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.dart b/json_serializable/test/kitchen_sink/kitchen_sink.dart index 78884cf2c..074ac6542 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.dart @@ -95,6 +95,9 @@ class KitchenSink implements k.KitchenSink { @JsonKey(includeIfNull: false) DateTime dateTime; + @JsonKey(includeIfNull: false) + BigInt bigInt; + @JsonKey(includeIfNull: false) Iterable get iterable => _iterable; Iterable get dynamicIterable => _dynamicIterable; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g.dart index 3134b670f..ac470b6af 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g.dart @@ -18,6 +18,8 @@ KitchenSink _$KitchenSinkFromJson(Map json) { ..dateTime = json['dateTime'] == null ? null : DateTime.parse(json['dateTime'] as String) + ..bigInt = + json['bigInt'] == null ? null : BigInt.parse(json['bigInt'] as String) ..set = (json['set'] as List)?.toSet() ..dynamicSet = (json['dynamicSet'] as List)?.toSet() ..objectSet = (json['objectSet'] as List)?.toSet() @@ -87,6 +89,7 @@ Map _$KitchenSinkToJson(KitchenSink instance) { } writeNotNull('dateTime', instance.dateTime?.toIso8601String()); + writeNotNull('bigInt', instance.bigInt?.toString()); writeNotNull('iterable', instance.iterable?.toList()); val['dynamicIterable'] = instance.dynamicIterable?.toList(); val['objectIterable'] = instance.objectIterable?.toList(); diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart index 0284c827f..c602c1959 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart @@ -96,6 +96,9 @@ class KitchenSink implements k.KitchenSink { @JsonKey(includeIfNull: false) DateTime dateTime; + @JsonKey(includeIfNull: false) + BigInt bigInt; + @JsonKey(includeIfNull: false) Iterable get iterable => _iterable; Iterable get dynamicIterable => _dynamicIterable; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart index b2293ebd2..c1a1d8bab 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart @@ -18,6 +18,8 @@ KitchenSink _$KitchenSinkFromJson(Map json) { ..dateTime = json['dateTime'] == null ? null : DateTime.parse(json['dateTime'] as String) + ..bigInt = + json['bigInt'] == null ? null : BigInt.parse(json['bigInt'] as String) ..set = (json['set'] as List)?.toSet() ..dynamicSet = (json['dynamicSet'] as List)?.toSet() ..objectSet = (json['objectSet'] as List)?.toSet() @@ -85,6 +87,7 @@ Map _$KitchenSinkToJson(KitchenSink instance) { } writeNotNull('dateTime', instance.dateTime?.toIso8601String()); + writeNotNull('bigInt', instance.bigInt?.toString()); writeNotNull('iterable', instance.iterable?.toList()); val['dynamicIterable'] = instance.dynamicIterable?.toList(); val['objectIterable'] = instance.objectIterable?.toList(); diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked__non_nullable.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked__non_nullable.dart index 1d956051f..a5bbcb91c 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked__non_nullable.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked__non_nullable.dart @@ -98,6 +98,9 @@ class KitchenSink implements k.KitchenSink { @JsonKey(includeIfNull: false) DateTime dateTime = DateTime(1981, 6, 5); + @JsonKey(includeIfNull: false) + BigInt bigInt = BigInt.parse('10000000000000000000'); + @JsonKey(includeIfNull: false) Iterable get iterable => _iterable; Iterable get dynamicIterable => _dynamicIterable; @@ -176,7 +179,7 @@ class JsonConverterTestClass implements k.JsonConverterTestClass { Duration duration; List durationList; - BigInt bigInt; + BigInt bigInt = BigInt.parse('10000000000000000000'); Map bigIntMap; TrivialNumber numberSilly; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked__non_nullable.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked__non_nullable.g.dart index e4cef7bcf..4edd71ca4 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked__non_nullable.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked__non_nullable.g.dart @@ -21,6 +21,8 @@ KitchenSink _$KitchenSinkFromJson(Map json) { (v) => (v as List).map((e) => DateTime.parse(e as String)))); $checkedConvert( json, 'dateTime', (v) => val.dateTime = DateTime.parse(v as String)); + $checkedConvert( + json, 'bigInt', (v) => val.bigInt = BigInt.parse(v as String)); $checkedConvert(json, 'set', (v) => val.set = (v as List).toSet()); $checkedConvert( json, 'dynamicSet', (v) => val.dynamicSet = (v as List).toSet()); @@ -94,6 +96,7 @@ Map _$KitchenSinkToJson(KitchenSink instance) => { 'no-42': instance.ctorValidatedNo42, 'dateTime': instance.dateTime.toIso8601String(), + 'bigInt': instance.bigInt.toString(), 'iterable': instance.iterable.toList(), 'dynamicIterable': instance.dynamicIterable.toList(), 'objectIterable': instance.objectIterable.toList(), diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable.dart index 632e7802d..9d62791d9 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable.dart @@ -97,6 +97,9 @@ class KitchenSink implements k.KitchenSink { @JsonKey(includeIfNull: false) DateTime dateTime = DateTime(1981, 6, 5); + @JsonKey(includeIfNull: false) + BigInt bigInt = BigInt.parse('10000000000000000000'); + @JsonKey(includeIfNull: false) Iterable get iterable => _iterable; Iterable get dynamicIterable => _dynamicIterable; @@ -174,7 +177,7 @@ class JsonConverterTestClass implements k.JsonConverterTestClass { Duration duration; List durationList; - BigInt bigInt; + BigInt bigInt = BigInt.parse('10000000000000000000'); Map bigIntMap; TrivialNumber numberSilly; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable.g.dart index 65636196b..3329d68dd 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable.g.dart @@ -16,6 +16,7 @@ KitchenSink _$KitchenSinkFromJson(Map json) { dateTimeIterable: (json['datetime-iterable'] as List) .map((e) => DateTime.parse(e as String))) ..dateTime = DateTime.parse(json['dateTime'] as String) + ..bigInt = BigInt.parse(json['bigInt'] as String) ..set = (json['set'] as List).toSet() ..dynamicSet = (json['dynamicSet'] as List).toSet() ..objectSet = (json['objectSet'] as List).toSet() @@ -64,6 +65,7 @@ Map _$KitchenSinkToJson(KitchenSink instance) => { 'no-42': instance.ctorValidatedNo42, 'dateTime': instance.dateTime.toIso8601String(), + 'bigInt': instance.bigInt.toString(), 'iterable': instance.iterable.toList(), 'dynamicIterable': instance.dynamicIterable.toList(), 'objectIterable': instance.objectIterable.toList(), diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable__use_wrappers.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable__use_wrappers.dart index 205fa534f..0087d1ed9 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable__use_wrappers.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable__use_wrappers.dart @@ -98,6 +98,9 @@ class KitchenSink implements k.KitchenSink { @JsonKey(includeIfNull: false) DateTime dateTime = DateTime(1981, 6, 5); + @JsonKey(includeIfNull: false) + BigInt bigInt = BigInt.parse('10000000000000000000'); + @JsonKey(includeIfNull: false) Iterable get iterable => _iterable; Iterable get dynamicIterable => _dynamicIterable; @@ -176,7 +179,7 @@ class JsonConverterTestClass implements k.JsonConverterTestClass { Duration duration; List durationList; - BigInt bigInt; + BigInt bigInt = BigInt.parse('10000000000000000000'); Map bigIntMap; TrivialNumber numberSilly; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable__use_wrappers.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable__use_wrappers.g.dart index d566a5068..39f0ba2b0 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable__use_wrappers.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable__use_wrappers.g.dart @@ -16,6 +16,7 @@ KitchenSink _$KitchenSinkFromJson(Map json) { dateTimeIterable: (json['datetime-iterable'] as List) .map((e) => DateTime.parse(e as String))) ..dateTime = DateTime.parse(json['dateTime'] as String) + ..bigInt = BigInt.parse(json['bigInt'] as String) ..set = (json['set'] as List).toSet() ..dynamicSet = (json['dynamicSet'] as List).toSet() ..objectSet = (json['objectSet'] as List).toSet() @@ -71,6 +72,7 @@ class _$KitchenSinkJsonMapWrapper extends $JsonMapWrapper { Iterable get keys => const [ 'no-42', 'dateTime', + 'bigInt', 'iterable', 'dynamicIterable', 'objectIterable', @@ -107,6 +109,8 @@ class _$KitchenSinkJsonMapWrapper extends $JsonMapWrapper { return _v.ctorValidatedNo42; case 'dateTime': return _v.dateTime.toIso8601String(); + case 'bigInt': + return _v.bigInt.toString(); case 'iterable': return _v.iterable.toList(); case 'dynamicIterable': diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__use_wrappers.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__use_wrappers.dart index b18fcf04d..206fec289 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__use_wrappers.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__use_wrappers.dart @@ -97,6 +97,9 @@ class KitchenSink implements k.KitchenSink { @JsonKey(includeIfNull: false) DateTime dateTime; + @JsonKey(includeIfNull: false) + BigInt bigInt; + @JsonKey(includeIfNull: false) Iterable get iterable => _iterable; Iterable get dynamicIterable => _dynamicIterable; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__use_wrappers.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__use_wrappers.g.dart index 40425ea48..86c8d6728 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__use_wrappers.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__use_wrappers.g.dart @@ -18,6 +18,8 @@ KitchenSink _$KitchenSinkFromJson(Map json) { ..dateTime = json['dateTime'] == null ? null : DateTime.parse(json['dateTime'] as String) + ..bigInt = + json['bigInt'] == null ? null : BigInt.parse(json['bigInt'] as String) ..set = (json['set'] as List)?.toSet() ..dynamicSet = (json['dynamicSet'] as List)?.toSet() ..objectSet = (json['objectSet'] as List)?.toSet() @@ -86,6 +88,9 @@ class _$KitchenSinkJsonMapWrapper extends $JsonMapWrapper { if (_v.dateTime != null) { yield 'dateTime'; } + if (_v.bigInt != null) { + yield 'bigInt'; + } if (_v.iterable != null) { yield 'iterable'; } @@ -130,6 +135,8 @@ class _$KitchenSinkJsonMapWrapper extends $JsonMapWrapper { return _v.ctorValidatedNo42; case 'dateTime': return _v.dateTime?.toIso8601String(); + case 'bigInt': + return _v.bigInt?.toString(); case 'iterable': return _v.iterable?.toList(); case 'dynamicIterable': diff --git a/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart b/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart index 829fdeb42..79da6f79d 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart @@ -36,6 +36,7 @@ abstract class JsonConverterTestClass { abstract class KitchenSink { int get ctorValidatedNo42; DateTime dateTime; + BigInt bigInt; Iterable get iterable; Iterable get dynamicIterable; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink_test.dart b/json_serializable/test/kitchen_sink/kitchen_sink_test.dart index 31fe52094..195e11e03 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink_test.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink_test.dart @@ -207,6 +207,7 @@ void _sharedTests(KitchenSinkFactory factory, {bool isChecked = false}) { /// they exist for KitchenSink where they are excluded when null final item = factory.ctor(iterable: []) ..dateTime = DateTime.now() + ..bigInt = BigInt.from(42) ..dateTimeList = [] ..crazyComplex = [] ..val = {}; @@ -304,6 +305,7 @@ Matcher _getMatcher(bool checked, String expectedKey, bool checkedAssignment) { final _validValues = const { 'no-42': 0, 'dateTime': '2018-05-10T14:20:58.927', + 'bigInt': '10000000000000000000', 'iterable': [], 'dynamicIterable': [], 'objectIterable': [], @@ -335,6 +337,7 @@ final _validValues = const { final _invalidValueTypes = const { 'no-42': true, 'dateTime': true, + 'bigInt': true, 'iterable': true, 'dynamicIterable': true, 'objectIterable': true, @@ -375,6 +378,7 @@ final _invalidCheckedValues = const { }; final _excludeIfNullKeys = const [ + 'bigInt', 'dateTime', 'iterable', 'dateTimeList', diff --git a/json_serializable/tool/builder.dart b/json_serializable/tool/builder.dart index 9fce91772..28846b2e8 100644 --- a/json_serializable/tool/builder.dart +++ b/json_serializable/tool/builder.dart @@ -145,6 +145,10 @@ Iterable<_Replacement> _optionReplacement( 'DateTime dateTime;', 'DateTime dateTime = DateTime(1981, 6, 5);', ); + yield _Replacement( + 'BigInt bigInt;', + "BigInt bigInt = BigInt.parse('10000000000000000000');", + ); yield _Replacement( 'bool get nullable => true;', 'bool get nullable => false;', From fdcabd7d99b8cba3759d9c548fd90803fdb86946 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Fri, 15 Mar 2019 12:19:33 -0700 Subject: [PATCH 078/569] Continued cleanup of kitchen_sink tests (#417) --- .travis.yml | 4 +- json_serializable/build.yaml | 13 +- json_serializable/mono_pkg.yaml | 2 +- .../test/kitchen_sink/kitchen_sink.dart | 8 +- .../kitchen_sink/kitchen_sink.factories.dart | 17 ++ .../kitchen_sink/kitchen_sink.g_any_map.dart | 7 +- ...sink.g_any_map__checked__non_nullable.dart | 7 +- .../kitchen_sink.g_any_map__non_nullable.dart | 7 +- ...g_any_map__non_nullable__use_wrappers.dart | 7 +- .../kitchen_sink.g_any_map__use_wrappers.dart | 7 +- .../kitchen_sink/kitchen_sink_interface.dart | 5 +- .../test/kitchen_sink/kitchen_sink_test.dart | 144 ++++++++------ json_serializable/tool/builder.dart | 178 ++++++++++-------- tool/travis.sh | 4 +- 14 files changed, 242 insertions(+), 168 deletions(-) create mode 100644 json_serializable/test/kitchen_sink/kitchen_sink.factories.dart diff --git a/.travis.yml b/.travis.yml index 94d8c7795..d0004a9bd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -72,12 +72,12 @@ jobs: env: PKG="json_serializable" dart: dev - stage: unit_test - name: "SDK: 2.0.0 - DIR: json_serializable - TASKS: pub run build_runner test -- -p chrome" + name: "SDK: 2.0.0 - DIR: json_serializable - TASKS: pub run build_runner test --delete-conflicting-outputs -- -p chrome" script: ./tool/travis.sh command env: PKG="json_serializable" dart: "2.0.0" - stage: unit_test - name: "SDK: dev - DIR: json_serializable - TASKS: pub run build_runner test -- -p chrome" + name: "SDK: dev - DIR: json_serializable - TASKS: pub run build_runner test --delete-conflicting-outputs -- -p chrome" script: ./tool/travis.sh command env: PKG="json_serializable" dart: dev diff --git a/json_serializable/build.yaml b/json_serializable/build.yaml index 8995f6072..2a8190b79 100644 --- a/json_serializable/build.yaml +++ b/json_serializable/build.yaml @@ -35,15 +35,16 @@ builders: builder_factories: ['internal'] build_extensions: .dart: - - .g_non_nullable.dart - - .g_use_wrappers.dart - - .g_non_nullable__use_wrappers.dart + - .factories.dart - .g_any_map.dart - - .g_any_map__non_nullable.dart - - .g_any_map__use_wrappers.dart - - .g_any_map__non_nullable__use_wrappers.dart - .g_any_map__checked.dart - .g_any_map__checked__non_nullable.dart + - .g_any_map__non_nullable.dart + - .g_any_map__non_nullable__use_wrappers.dart + - .g_any_map__use_wrappers.dart + - .g_non_nullable.dart + - .g_non_nullable__use_wrappers.dart + - .g_use_wrappers.dart build_to: source runs_before: ["json_serializable"] diff --git a/json_serializable/mono_pkg.yaml b/json_serializable/mono_pkg.yaml index 86528602e..905043a2c 100644 --- a/json_serializable/mono_pkg.yaml +++ b/json_serializable/mono_pkg.yaml @@ -17,7 +17,7 @@ stages: # Run the tests -- include the default-skipped presubmit tests - test - test: --run-skipped test/ensure_build_test.dart - - command: pub run build_runner test -- -p chrome + - command: pub run build_runner test --delete-conflicting-outputs -- -p chrome cache: directories: diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.dart b/json_serializable/test/kitchen_sink/kitchen_sink.dart index 074ac6542..5eea937d7 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.dart @@ -22,10 +22,11 @@ StrictKeysObject _defaultStrictKeysObject() => null; const k.KitchenSinkFactory factory = _Factory(); -class _Factory implements k.KitchenSinkFactory { +class _Factory implements k.KitchenSinkFactory { const _Factory(); String get description => '--defaults--'; + bool get anyMap => false; bool get checked => false; bool get nullable => true; @@ -46,9 +47,8 @@ class _Factory implements k.KitchenSinkFactory { dateTimeIterable: dateTimeIterable, ); - k.KitchenSink fromJson(Map json) { - return KitchenSink.fromJson(json.cast()); - } + k.KitchenSink fromJson(Map json) => + KitchenSink.fromJson(json); k.JsonConverterTestClass jsonConverterCtor() => JsonConverterTestClass(); diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.factories.dart b/json_serializable/test/kitchen_sink/kitchen_sink.factories.dart new file mode 100644 index 000000000..7e9fd94d0 --- /dev/null +++ b/json_serializable/test/kitchen_sink/kitchen_sink.factories.dart @@ -0,0 +1,17 @@ +import 'kitchen_sink.dart' as normal; +import 'kitchen_sink.g_any_map.dart' as any_map; +import 'kitchen_sink.g_any_map__checked__non_nullable.dart' + as any_map__checked__non_nullable; +import 'kitchen_sink.g_any_map__non_nullable.dart' as any_map__non_nullable; +import 'kitchen_sink.g_any_map__non_nullable__use_wrappers.dart' + as any_map__non_nullable__use_wrappers; +import 'kitchen_sink.g_any_map__use_wrappers.dart' as any_map__use_wrappers; + +const factories = [ + normal.factory, + any_map.factory, + any_map__checked__non_nullable.factory, + any_map__non_nullable.factory, + any_map__non_nullable__use_wrappers.factory, + any_map__use_wrappers.factory, +]; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart index c602c1959..799ade9a9 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart @@ -22,10 +22,11 @@ StrictKeysObject _defaultStrictKeysObject() => null; const k.KitchenSinkFactory factory = _Factory(); -class _Factory implements k.KitchenSinkFactory { +class _Factory implements k.KitchenSinkFactory { const _Factory(); String get description => 'any_map'; + bool get anyMap => true; bool get checked => false; bool get nullable => true; @@ -46,9 +47,7 @@ class _Factory implements k.KitchenSinkFactory { dateTimeIterable: dateTimeIterable, ); - k.KitchenSink fromJson(Map json) { - return KitchenSink.fromJson(json); - } + k.KitchenSink fromJson(Map json) => KitchenSink.fromJson(json); k.JsonConverterTestClass jsonConverterCtor() => JsonConverterTestClass(); diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked__non_nullable.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked__non_nullable.dart index a5bbcb91c..3d6b9ebf4 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked__non_nullable.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked__non_nullable.dart @@ -22,10 +22,11 @@ StrictKeysObject _defaultStrictKeysObject() => StrictKeysObject(10, 'cool'); const k.KitchenSinkFactory factory = _Factory(); -class _Factory implements k.KitchenSinkFactory { +class _Factory implements k.KitchenSinkFactory { const _Factory(); String get description => 'any_map__checked__non_nullable'; + bool get anyMap => true; bool get checked => true; bool get nullable => false; @@ -46,9 +47,7 @@ class _Factory implements k.KitchenSinkFactory { dateTimeIterable: dateTimeIterable, ); - k.KitchenSink fromJson(Map json) { - return KitchenSink.fromJson(json); - } + k.KitchenSink fromJson(Map json) => KitchenSink.fromJson(json); k.JsonConverterTestClass jsonConverterCtor() => JsonConverterTestClass(); diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable.dart index 9d62791d9..597db8a44 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable.dart @@ -22,10 +22,11 @@ StrictKeysObject _defaultStrictKeysObject() => StrictKeysObject(10, 'cool'); const k.KitchenSinkFactory factory = _Factory(); -class _Factory implements k.KitchenSinkFactory { +class _Factory implements k.KitchenSinkFactory { const _Factory(); String get description => 'any_map__non_nullable'; + bool get anyMap => true; bool get checked => false; bool get nullable => false; @@ -46,9 +47,7 @@ class _Factory implements k.KitchenSinkFactory { dateTimeIterable: dateTimeIterable, ); - k.KitchenSink fromJson(Map json) { - return KitchenSink.fromJson(json); - } + k.KitchenSink fromJson(Map json) => KitchenSink.fromJson(json); k.JsonConverterTestClass jsonConverterCtor() => JsonConverterTestClass(); diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable__use_wrappers.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable__use_wrappers.dart index 0087d1ed9..b6b06c767 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable__use_wrappers.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable__use_wrappers.dart @@ -22,10 +22,11 @@ StrictKeysObject _defaultStrictKeysObject() => StrictKeysObject(10, 'cool'); const k.KitchenSinkFactory factory = _Factory(); -class _Factory implements k.KitchenSinkFactory { +class _Factory implements k.KitchenSinkFactory { const _Factory(); String get description => 'any_map__non_nullable__use_wrappers'; + bool get anyMap => true; bool get checked => false; bool get nullable => false; @@ -46,9 +47,7 @@ class _Factory implements k.KitchenSinkFactory { dateTimeIterable: dateTimeIterable, ); - k.KitchenSink fromJson(Map json) { - return KitchenSink.fromJson(json); - } + k.KitchenSink fromJson(Map json) => KitchenSink.fromJson(json); k.JsonConverterTestClass jsonConverterCtor() => JsonConverterTestClass(); diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__use_wrappers.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__use_wrappers.dart index 206fec289..12ca6e1b5 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__use_wrappers.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__use_wrappers.dart @@ -22,10 +22,11 @@ StrictKeysObject _defaultStrictKeysObject() => null; const k.KitchenSinkFactory factory = _Factory(); -class _Factory implements k.KitchenSinkFactory { +class _Factory implements k.KitchenSinkFactory { const _Factory(); String get description => 'any_map__use_wrappers'; + bool get anyMap => true; bool get checked => false; bool get nullable => true; @@ -46,9 +47,7 @@ class _Factory implements k.KitchenSinkFactory { dateTimeIterable: dateTimeIterable, ); - k.KitchenSink fromJson(Map json) { - return KitchenSink.fromJson(json); - } + k.KitchenSink fromJson(Map json) => KitchenSink.fromJson(json); k.JsonConverterTestClass jsonConverterCtor() => JsonConverterTestClass(); diff --git a/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart b/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart index 79da6f79d..a11169c96 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart @@ -5,8 +5,9 @@ import 'package:collection/collection.dart'; import 'simple_object.dart'; -abstract class KitchenSinkFactory { +abstract class KitchenSinkFactory { String get description; + bool get anyMap; bool get checked; bool get nullable; @@ -19,7 +20,7 @@ abstract class KitchenSinkFactory { Iterable dateTimeIterable, }); - KitchenSink fromJson(Map json); + KitchenSink fromJson(Map json); JsonConverterTestClass jsonConverterCtor(); diff --git a/json_serializable/test/kitchen_sink/kitchen_sink_test.dart b/json_serializable/test/kitchen_sink/kitchen_sink_test.dart index 195e11e03..f33138b43 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink_test.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink_test.dart @@ -7,13 +7,7 @@ import 'package:test/test.dart'; import 'package:yaml/yaml.dart'; import '../test_utils.dart'; -import 'kitchen_sink.g_any_map.dart' as nullable show factory; -import 'kitchen_sink.g_any_map__checked__non_nullable.dart' as checked - show factory; -import 'kitchen_sink.g_any_map__non_nullable.dart' as non_null show factory; -import 'kitchen_sink.g_any_map__non_nullable__use_wrappers.dart' - as non_null_wrapped show factory; -import 'kitchen_sink.g_any_map__use_wrappers.dart' as wrapped show factory; +import 'kitchen_sink.factories.dart'; import 'kitchen_sink_interface.dart'; import 'strict_keys_object.dart'; @@ -43,21 +37,18 @@ void main() { 'Required keys are missing: value, custom_field.'))); }); - for (var factory in [ - nullable.factory, - checked.factory, - non_null.factory, - non_null_wrapped.factory, - wrapped.factory, - ]) { + for (var factory in factories) { group(factory.description, () { if (factory.nullable) { _nullableTests(factory); } else { - _nonNullableTests(factory, isChecked: factory.checked); + _nonNullableTests(factory); } - _sharedTests(factory, isChecked: factory.checked); + _sharedTests(factory); + if (factory.anyMap) { + _anyMapTests(factory); + } }); } } @@ -72,33 +63,33 @@ const _jsonConverterValidValues = { 'dateTime': 5 }; -void _nonNullableTests(KitchenSinkFactory factory, {bool isChecked = false}) { +void _nonNullableTests(KitchenSinkFactory factory) { test('with null values fails serialization', () { expect(() => (factory.ctor()..objectDateTimeMap = null).toJson(), throwsNoSuchMethodError); }); test('with empty json fails deserialization', () { - if (isChecked) { - expect( - () => factory.fromJson({}), throwsA(_checkedMatcher('intIterable'))); + if (factory.checked) { + expect(() => factory.fromJson({}), + throwsA(_checkedMatcher('intIterable'))); } else { - expect(() => factory.fromJson({}), throwsNoSuchMethodError); + expect( + () => factory.fromJson({}), throwsNoSuchMethodError); } }); test('nullable values are not allowed in non-nullable version', () { - var instance = non_null.factory.jsonConverterCtor(); + var instance = factory.jsonConverterCtor(); expect(() => instance.toJson(), throwsNoSuchMethodError, reason: 'Trying to call `map` on a null list'); - instance = - non_null.factory.jsonConverterFromJson(_jsonConverterValidValues); + instance = factory.jsonConverterFromJson(_jsonConverterValidValues); final json = instance.toJson(); expect(json, _jsonConverterValidValues); expect(json.values, everyElement(isNotNull)); - final instance2 = non_null.factory.jsonConverterFromJson(json); + final instance2 = factory.jsonConverterFromJson(json); expect(instance2.toJson(), json); }); } @@ -109,12 +100,12 @@ void _nullableTests(KitchenSinkFactory factory) { } test('nullable values are allowed in the nullable version', () { - final instance = nullable.factory.jsonConverterCtor(); + final instance = factory.jsonConverterCtor(); final json = instance.toJson(); expect(json.values, everyElement(isNull)); expect(json.keys, unorderedEquals(_jsonConverterValidValues.keys)); - final instance2 = nullable.factory.jsonConverterFromJson(json); + final instance2 = factory.jsonConverterFromJson(json); expect(instance2.toJson(), json); }); @@ -165,7 +156,24 @@ void _nullableTests(KitchenSinkFactory factory) { }); } -void _sharedTests(KitchenSinkFactory factory, {bool isChecked = false}) { +void _anyMapTests(KitchenSinkFactory factory) { + test('valid values round-trip - yaml', () { + final jsonEncoded = loudEncode(_validValues); + final yaml = loadYaml(jsonEncoded, sourceUrl: 'input.yaml'); + expect(jsonEncoded, loudEncode(factory.fromJson(yaml as YamlMap))); + }); + + group('a bad value for', () { + for (final e in _invalidValueTypes.entries) { + _testBadValue(e.key, e.value, factory, false); + } + for (final e in _invalidCheckedValues.entries) { + _testBadValue(e.key, e.value, factory, true); + } + }); +} + +void _sharedTests(KitchenSinkFactory factory) { void roundTripSink(KitchenSink p) { roundTripObject(p, factory.fromJson); } @@ -217,29 +225,27 @@ void _sharedTests(KitchenSinkFactory factory, {bool isChecked = false}) { }); test('valid values round-trip - json', () { - expect( - loudEncode(_validValues), loudEncode(factory.fromJson(_validValues))); - }); - - test('valid values round-trip - yaml', () { - final jsonEncoded = loudEncode(_validValues); - final yaml = loadYaml(jsonEncoded, sourceUrl: 'input.yaml'); - expect(jsonEncoded, loudEncode(factory.fromJson(yaml as YamlMap))); - }); - - group('a bad value for', () { - for (final e in _invalidValueTypes.entries) { - _testBadValue(isChecked, e.key, e.value, factory.fromJson, false); - } - for (final e in _invalidCheckedValues.entries) { - _testBadValue(isChecked, e.key, e.value, factory.fromJson, true); + final validInstance = factory.fromJson(_validValues); + for (var entry in validInstance.toJson().entries) { + expect(entry.value, isNotNull, + reason: 'key "${entry.key}" should not be null'); + + if (_iterableMapKeys.contains(entry.key)) { + expect(entry.value, anyOf(isMap, isList), + reason: 'key "${entry.key}" should be a Map/List'); + } else { + expect(entry.value, isNot(anyOf(isMap, isList)), + reason: 'key "${entry.key}" should not be a Map/List'); + } } + + expect(loudEncode(_validValues), loudEncode(validInstance)); }); } -void _testBadValue(bool isChecked, String key, Object badValue, - KitchenSink fromJson(Map json), bool checkedAssignment) { - final matcher = _getMatcher(isChecked, key, checkedAssignment); +void _testBadValue(String key, Object badValue, KitchenSinkFactory factory, + bool checkedAssignment) { + final matcher = _getMatcher(factory.checked, key, checkedAssignment); for (final isJson in [true, false]) { test('`$key` fails with value `$badValue`- ${isJson ? 'json' : 'yaml'}', @@ -251,7 +257,7 @@ void _testBadValue(bool isChecked, String key, Object badValue, copy = loadYaml(loudEncode(copy)) as YamlMap; } - expect(() => fromJson(copy), matcher); + expect(() => factory.fromJson(copy), matcher); }); } } @@ -302,7 +308,7 @@ Matcher _getMatcher(bool checked, String expectedKey, bool checkedAssignment) { return throwsA(innerMatcher); } -final _validValues = const { +const _validValues = { 'no-42': 0, 'dateTime': '2018-05-10T14:20:58.927', 'bigInt': '10000000000000000000', @@ -322,19 +328,19 @@ final _validValues = const { 'intList': [], 'dateTimeList': [], 'map': {}, - 'stringStringMap': {}, - 'dynamicIntMap': {}, + 'stringStringMap': {}, + 'dynamicIntMap': {}, 'objectDateTimeMap': {}, 'crazyComplex': [], - _generatedLocalVarName: {}, - _toJsonMapHelperName: null, - r'$string': null, + _generatedLocalVarName: {}, + _toJsonMapHelperName: true, + r'$string': 'string', 'simpleObject': {'value': 42}, 'strictKeysObject': {'value': 10, 'custom_field': 'cool'}, 'validatedPropertyNo42': 0 }; -final _invalidValueTypes = const { +const _invalidValueTypes = { 'no-42': true, 'dateTime': true, 'bigInt': true, @@ -370,14 +376,14 @@ final _invalidValueTypes = const { }; /// Invalid values that are found after the property set or ctor call -final _invalidCheckedValues = const { +const _invalidCheckedValues = { 'no-42': 42, 'validatedPropertyNo42': 42, 'intIterable': [true], 'datetime-iterable': [true], }; -final _excludeIfNullKeys = const [ +const _excludeIfNullKeys = [ 'bigInt', 'dateTime', 'iterable', @@ -385,3 +391,27 @@ final _excludeIfNullKeys = const [ 'crazyComplex', _generatedLocalVarName ]; + +const _iterableMapKeys = [ + 'crazyComplex', + 'datetime-iterable', + 'dateTimeList', + 'dateTimeSet', + 'dynamicIntMap', + 'dynamicIterable', + 'dynamicList', + 'dynamicSet', + 'intIterable', + 'intList', + 'intSet', + 'iterable', + 'list', + 'map', + 'objectDateTimeMap', + 'objectIterable', + 'objectList', + 'objectSet', + 'set', + 'stringStringMap', + _generatedLocalVarName, +]; diff --git a/json_serializable/tool/builder.dart b/json_serializable/tool/builder.dart index 28846b2e8..9ff0c96ae 100644 --- a/json_serializable/tool/builder.dart +++ b/json_serializable/tool/builder.dart @@ -3,6 +3,7 @@ // BSD-style license that can be found in the LICENSE file. import 'dart:async'; +import 'dart:collection'; import 'dart:io'; import 'package:build/build.dart'; @@ -54,6 +55,9 @@ class _SmartBuilder implements Builder { final sourceContent = await buildStep.readAsString(buildStep.inputId); + final factories = + SplayTreeMap.from({'$_kitchenSinkBaseName.dart': 'normal'}); + for (var config in _fileConfigurationMap[baseName]) { final extension = _configToExtension(config); final newId = buildStep.inputId.changeExtension(extension); @@ -67,12 +71,14 @@ class _SmartBuilder implements Builder { ) ]; - if (baseName == 'kitchen_sink') { + if (baseName == _kitchenSinkBaseName) { final description = _configToName(config.toSet()); replacements.add(_Replacement( "String get description => '--defaults--';", "String get description => '$description';", )); + + factories['$baseName$partName.dart'] = description; } for (var entry in config) { @@ -83,6 +89,19 @@ class _SmartBuilder implements Builder { await buildStep.writeAsString(newId, _formatter.format(content)); } + + if (baseName == _kitchenSinkBaseName) { + final newId = buildStep.inputId.changeExtension('.factories.dart'); + + final lines = []..addAll( + factories.entries.map((e) => "import '${e.key}' as ${e.value};")); + + lines.add('const factories = ['); + lines.addAll(factories.values.map((e) => '$e.factory,')); + lines.add('];'); + + await buildStep.writeAsString(newId, _formatter.format(lines.join('\n'))); + } } @override @@ -90,76 +109,82 @@ class _SmartBuilder implements Builder { {'.dart': _fileConfigurations}; } +const _configReplacements = { + 'any_map': _Replacement.addJsonSerializableKey('anyMap', true), + 'checked': _Replacement.addJsonSerializableKey('checked', true), + 'non_nullable': _Replacement.addJsonSerializableKey('nullable', false), + 'use_wrappers': _Replacement.addJsonSerializableKey('useWrappers', true), +}; + +const _kitchenSinkReplacements = { + 'any_map': [ + _Replacement( + 'bool get anyMap => false;', + 'bool get anyMap => true;', + ), + _Replacement( + 'class _Factory implements k.KitchenSinkFactory', + 'class _Factory implements k.KitchenSinkFactory', + ), + _Replacement( + 'k.KitchenSink fromJson(Map json)', + 'k.KitchenSink fromJson(Map json)', + ), + _Replacement( + 'factory KitchenSink.fromJson(Map json)', + 'factory KitchenSink.fromJson(Map json)', + ), + ], + 'checked': [ + _Replacement( + 'bool get checked => false;', + 'bool get checked => true;', + ) + ], + 'non_nullable': [ + _Replacement( + 'List _defaultList() => null;', + 'List _defaultList() => [];', + ), + _Replacement( + 'Set _defaultSet() => null;', + 'Set _defaultSet() => Set();', + ), + _Replacement( + 'Map _defaultMap() => null;', + 'Map _defaultMap() => {};', + ), + _Replacement( + 'SimpleObject _defaultSimpleObject() => null;', + 'SimpleObject _defaultSimpleObject() => SimpleObject(42);', + ), + _Replacement( + 'StrictKeysObject _defaultStrictKeysObject() => null;', + 'StrictKeysObject _defaultStrictKeysObject() => ' + "StrictKeysObject(10, 'cool');", + ), + _Replacement( + 'DateTime dateTime;', + 'DateTime dateTime = DateTime(1981, 6, 5);', + ), + _Replacement( + 'BigInt bigInt;', + "BigInt bigInt = BigInt.parse('10000000000000000000');", + ), + _Replacement( + 'bool get nullable => true;', + 'bool get nullable => false;', + ) + ], +}; + Iterable<_Replacement> _optionReplacement( String baseName, String optionKey) sync* { - switch (optionKey) { - case 'any_map': - yield _Replacement.addJsonSerializableKey('anyMap', true); - - if (baseName == 'kitchen_sink') { - yield _Replacement( - 'return KitchenSink.fromJson(json.cast());', - 'return KitchenSink.fromJson(json);', - ); - yield _Replacement( - 'factory KitchenSink.fromJson(Map json)', - 'factory KitchenSink.fromJson(Map json)', - ); - } - break; - case 'checked': - yield _Replacement.addJsonSerializableKey('checked', true); - if (baseName == 'kitchen_sink') { - yield _Replacement( - 'bool get checked => false;', - 'bool get checked => true;', - ); - } - break; - case 'non_nullable': - yield _Replacement.addJsonSerializableKey('nullable', false); - - if (baseName == 'kitchen_sink') { - yield _Replacement( - 'List _defaultList() => null;', - 'List _defaultList() => [];', - ); - yield _Replacement( - 'Set _defaultSet() => null;', - 'Set _defaultSet() => Set();', - ); - yield _Replacement( - 'Map _defaultMap() => null;', - 'Map _defaultMap() => {};', - ); - yield _Replacement( - 'SimpleObject _defaultSimpleObject() => null;', - 'SimpleObject _defaultSimpleObject() => SimpleObject(42);', - ); - yield _Replacement( - 'StrictKeysObject _defaultStrictKeysObject() => null;', - 'StrictKeysObject _defaultStrictKeysObject() => ' - "StrictKeysObject(10, 'cool');", - ); - yield _Replacement( - 'DateTime dateTime;', - 'DateTime dateTime = DateTime(1981, 6, 5);', - ); - yield _Replacement( - 'BigInt bigInt;', - "BigInt bigInt = BigInt.parse('10000000000000000000');", - ); - yield _Replacement( - 'bool get nullable => true;', - 'bool get nullable => false;', - ); - } - break; - case 'use_wrappers': - yield _Replacement.addJsonSerializableKey('useWrappers', true); - break; - default: - throw UnimplementedError('not yet!: $optionKey'); + yield _configReplacements[optionKey]; + + if (baseName == _kitchenSinkBaseName && + _kitchenSinkReplacements.containsKey(optionKey)) { + yield* _kitchenSinkReplacements[optionKey]; } } @@ -172,12 +197,16 @@ String _configToName(Set config) => List get _fileConfigurations => _fileConfigurationMap.values .expand((v) => v) .map(_configToExtension) + .followedBy(['.factories.dart']) .toSet() - .toList(); + .toList() + ..sort(); + +const _kitchenSinkBaseName = 'kitchen_sink'; // TODO: use a set of sets, once we're >=2.2.0 const _fileConfigurationMap = >>{ - 'kitchen_sink': [ + _kitchenSinkBaseName: [ ['any_map'], ['any_map', 'checked', 'non_nullable'], ['any_map', 'non_nullable'], @@ -201,10 +230,11 @@ class _Replacement { final Pattern existing; final String replacement; - _Replacement(this.existing, this.replacement); + const _Replacement(this.existing, this.replacement); - factory _Replacement.addJsonSerializableKey(String key, bool value) => - _Replacement('@JsonSerializable(', '@JsonSerializable(\n $key: $value,'); + const _Replacement.addJsonSerializableKey(String key, bool value) + : existing = '@JsonSerializable(', + replacement = '@JsonSerializable(\n $key: $value,'; static String generate( String inputContent, Iterable<_Replacement> replacements) { diff --git a/tool/travis.sh b/tool/travis.sh index 126bf5bf7..9bc3cf155 100755 --- a/tool/travis.sh +++ b/tool/travis.sh @@ -21,8 +21,8 @@ while (( "$#" )); do case $TASK in command) echo echo -e '\033[1mTASK: command\033[22m' - echo -e 'pub run build_runner test -- -p chrome' - pub run build_runner test -- -p chrome || EXIT_CODE=$? + echo -e 'pub run build_runner test --delete-conflicting-outputs -- -p chrome' + pub run build_runner test --delete-conflicting-outputs -- -p chrome || EXIT_CODE=$? ;; dartanalyzer_0) echo echo -e '\033[1mTASK: dartanalyzer_0\033[22m' From 017f612cc45fe41ec22bff9c3cf59fe73ca05216 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Fri, 15 Mar 2019 18:33:53 -0700 Subject: [PATCH 079/569] kitchen sink tests: add exclude non-null and explicit toJson (#418) --- json_serializable/build.yaml | 3 + .../test/kitchen_sink/kitchen_sink.dart | 2 + .../kitchen_sink/kitchen_sink.factories.dart | 7 + .../kitchen_sink/kitchen_sink.g_any_map.dart | 2 + ...sink.g_any_map__checked__non_nullable.dart | 2 + .../kitchen_sink.g_any_map__non_nullable.dart | 2 + ...g_any_map__non_nullable__use_wrappers.dart | 2 + .../kitchen_sink.g_any_map__use_wrappers.dart | 2 + .../kitchen_sink.g_exclude_null.dart | 205 ++++++++++++++ .../kitchen_sink.g_exclude_null.g.dart | 263 ++++++++++++++++++ ...hen_sink.g_exclude_null__non_nullable.dart | 208 ++++++++++++++ ...n_sink.g_exclude_null__non_nullable.g.dart | 170 +++++++++++ .../kitchen_sink.g_explicit_to_json.dart | 205 ++++++++++++++ .../kitchen_sink.g_explicit_to_json.g.dart | 226 +++++++++++++++ .../kitchen_sink/kitchen_sink_interface.dart | 2 + .../test/kitchen_sink/kitchen_sink_test.dart | 65 +++-- json_serializable/tool/builder.dart | 30 +- 17 files changed, 1373 insertions(+), 23 deletions(-) create mode 100644 json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.dart create mode 100644 json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart create mode 100644 json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__non_nullable.dart create mode 100644 json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__non_nullable.g.dart create mode 100644 json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.dart create mode 100644 json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart diff --git a/json_serializable/build.yaml b/json_serializable/build.yaml index 2a8190b79..ce6e5e2f5 100644 --- a/json_serializable/build.yaml +++ b/json_serializable/build.yaml @@ -42,6 +42,9 @@ builders: - .g_any_map__non_nullable.dart - .g_any_map__non_nullable__use_wrappers.dart - .g_any_map__use_wrappers.dart + - .g_exclude_null.dart + - .g_exclude_null__non_nullable.dart + - .g_explicit_to_json.dart - .g_non_nullable.dart - .g_non_nullable__use_wrappers.dart - .g_use_wrappers.dart diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.dart b/json_serializable/test/kitchen_sink/kitchen_sink.dart index 5eea937d7..8140c876e 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.dart @@ -29,6 +29,8 @@ class _Factory implements k.KitchenSinkFactory { bool get anyMap => false; bool get checked => false; bool get nullable => true; + bool get excludeNull => false; + bool get explicitToJson => false; k.KitchenSink ctor({ int ctorValidatedNo42, diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.factories.dart b/json_serializable/test/kitchen_sink/kitchen_sink.factories.dart index 7e9fd94d0..7527c6970 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.factories.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.factories.dart @@ -6,6 +6,10 @@ import 'kitchen_sink.g_any_map__non_nullable.dart' as any_map__non_nullable; import 'kitchen_sink.g_any_map__non_nullable__use_wrappers.dart' as any_map__non_nullable__use_wrappers; import 'kitchen_sink.g_any_map__use_wrappers.dart' as any_map__use_wrappers; +import 'kitchen_sink.g_exclude_null.dart' as exclude_null; +import 'kitchen_sink.g_exclude_null__non_nullable.dart' + as exclude_null__non_nullable; +import 'kitchen_sink.g_explicit_to_json.dart' as explicit_to_json; const factories = [ normal.factory, @@ -14,4 +18,7 @@ const factories = [ any_map__non_nullable.factory, any_map__non_nullable__use_wrappers.factory, any_map__use_wrappers.factory, + exclude_null.factory, + exclude_null__non_nullable.factory, + explicit_to_json.factory, ]; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart index 799ade9a9..6c0b7e9d1 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart @@ -29,6 +29,8 @@ class _Factory implements k.KitchenSinkFactory { bool get anyMap => true; bool get checked => false; bool get nullable => true; + bool get excludeNull => false; + bool get explicitToJson => false; k.KitchenSink ctor({ int ctorValidatedNo42, diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked__non_nullable.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked__non_nullable.dart index 3d6b9ebf4..ab9044018 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked__non_nullable.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked__non_nullable.dart @@ -29,6 +29,8 @@ class _Factory implements k.KitchenSinkFactory { bool get anyMap => true; bool get checked => true; bool get nullable => false; + bool get excludeNull => false; + bool get explicitToJson => false; k.KitchenSink ctor({ int ctorValidatedNo42, diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable.dart index 597db8a44..a7d910f03 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable.dart @@ -29,6 +29,8 @@ class _Factory implements k.KitchenSinkFactory { bool get anyMap => true; bool get checked => false; bool get nullable => false; + bool get excludeNull => false; + bool get explicitToJson => false; k.KitchenSink ctor({ int ctorValidatedNo42, diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable__use_wrappers.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable__use_wrappers.dart index b6b06c767..0009c587b 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable__use_wrappers.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable__use_wrappers.dart @@ -29,6 +29,8 @@ class _Factory implements k.KitchenSinkFactory { bool get anyMap => true; bool get checked => false; bool get nullable => false; + bool get excludeNull => false; + bool get explicitToJson => false; k.KitchenSink ctor({ int ctorValidatedNo42, diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__use_wrappers.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__use_wrappers.dart index 12ca6e1b5..479c465d2 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__use_wrappers.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__use_wrappers.dart @@ -29,6 +29,8 @@ class _Factory implements k.KitchenSinkFactory { bool get anyMap => true; bool get checked => false; bool get nullable => true; + bool get excludeNull => false; + bool get explicitToJson => false; k.KitchenSink ctor({ int ctorValidatedNo42, diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.dart new file mode 100644 index 000000000..ccd2a6138 --- /dev/null +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.dart @@ -0,0 +1,205 @@ +// Copyright (c) 2018, 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. + +// ignore_for_file: annotate_overrides, hash_and_equals +import 'package:json_annotation/json_annotation.dart'; + +import 'json_converters.dart'; +import 'kitchen_sink_interface.dart' as k; +import 'simple_object.dart'; +import 'strict_keys_object.dart'; + +part 'kitchen_sink.g_exclude_null.g.dart'; + +// NOTE: these methods are replaced in the `non_nullable` cases to return +// non-null values. +List _defaultList() => null; +Set _defaultSet() => null; +Map _defaultMap() => null; +SimpleObject _defaultSimpleObject() => null; +StrictKeysObject _defaultStrictKeysObject() => null; + +const k.KitchenSinkFactory factory = _Factory(); + +class _Factory implements k.KitchenSinkFactory { + const _Factory(); + + String get description => 'exclude_null'; + bool get anyMap => false; + bool get checked => false; + bool get nullable => true; + bool get excludeNull => true; + bool get explicitToJson => false; + + k.KitchenSink ctor({ + int ctorValidatedNo42, + Iterable iterable, + Iterable dynamicIterable, + Iterable objectIterable, + Iterable intIterable, + Iterable dateTimeIterable, + }) => + KitchenSink( + ctorValidatedNo42: ctorValidatedNo42, + iterable: iterable, + dynamicIterable: dynamicIterable, + objectIterable: objectIterable, + intIterable: intIterable, + dateTimeIterable: dateTimeIterable, + ); + + k.KitchenSink fromJson(Map json) => + KitchenSink.fromJson(json); + + k.JsonConverterTestClass jsonConverterCtor() => JsonConverterTestClass(); + + k.JsonConverterTestClass jsonConverterFromJson(Map json) => + JsonConverterTestClass.fromJson(json); +} + +@JsonSerializable( + includeIfNull: false, +) +class KitchenSink implements k.KitchenSink { + // NOTE: exposing these as Iterable, but storing the values as List + // to make the equality test work trivially. + final Iterable _iterable; + final Iterable _dynamicIterable; + final Iterable _objectIterable; + final Iterable _intIterable; + final Iterable _dateTimeIterable; + + @JsonKey(name: 'no-42') + final int ctorValidatedNo42; + + KitchenSink({ + this.ctorValidatedNo42, + Iterable iterable, + Iterable dynamicIterable, + Iterable objectIterable, + Iterable intIterable, + Iterable dateTimeIterable, + }) : _iterable = iterable?.toList() ?? _defaultList(), + _dynamicIterable = dynamicIterable?.toList() ?? _defaultList(), + _objectIterable = objectIterable?.toList() ?? _defaultList(), + _intIterable = intIterable?.toList() ?? _defaultList(), + _dateTimeIterable = dateTimeIterable?.toList() ?? _defaultList() { + if (ctorValidatedNo42 == 42) { + throw ArgumentError.value( + 42, 'ctorValidatedNo42', 'The value `42` is not allowed.'); + } + } + + factory KitchenSink.fromJson(Map json) => + _$KitchenSinkFromJson(json); + + Map toJson() => _$KitchenSinkToJson(this); + + @JsonKey(includeIfNull: false) + DateTime dateTime; + + @JsonKey(includeIfNull: false) + BigInt bigInt; + + @JsonKey(includeIfNull: false) + Iterable get iterable => _iterable; + Iterable get dynamicIterable => _dynamicIterable; + Iterable get objectIterable => _objectIterable; + Iterable get intIterable => _intIterable; + + Set set = _defaultSet(); + Set dynamicSet = _defaultSet(); + Set objectSet = _defaultSet(); + Set intSet = _defaultSet(); + Set dateTimeSet = _defaultSet(); + + // Added a one-off annotation on a property (not a field) + @JsonKey(name: 'datetime-iterable') + Iterable get dateTimeIterable => _dateTimeIterable; + + List list = _defaultList(); + List dynamicList = _defaultList(); + List objectList = _defaultList(); + List intList = _defaultList(); + @JsonKey(includeIfNull: false) + List dateTimeList = _defaultList(); + + Map map = _defaultMap(); + Map stringStringMap = _defaultMap(); + Map dynamicIntMap = _defaultMap(); + Map objectDateTimeMap = _defaultMap(); + + @JsonKey(includeIfNull: false) + List>>>> crazyComplex = + _defaultList(); + + // Handle fields with names that collide with helper names + @JsonKey(includeIfNull: false) + Map val = _defaultMap(); + bool writeNotNull; + @JsonKey(name: r'$string') + String string; + + SimpleObject simpleObject = _defaultSimpleObject(); + + StrictKeysObject strictKeysObject = _defaultStrictKeysObject(); + + int _validatedPropertyNo42; + int get validatedPropertyNo42 => _validatedPropertyNo42; + + set validatedPropertyNo42(int value) { + if (value == 42) { + throw StateError('Cannot be 42!'); + } + _validatedPropertyNo42 = value; + } + + bool operator ==(Object other) => k.sinkEquals(this, other); +} + +@JsonSerializable( + includeIfNull: false, +) +// referencing a top-level field should work +@durationConverter +// referencing via a const constructor should work +@BigIntStringConverter() +@TrivialNumberConverter.instance +@EpochDateTimeConverter() +class JsonConverterTestClass implements k.JsonConverterTestClass { + JsonConverterTestClass(); + + factory JsonConverterTestClass.fromJson(Map json) => + _$JsonConverterTestClassFromJson(json); + + Map toJson() => _$JsonConverterTestClassToJson(this); + + Duration duration; + List durationList; + + BigInt bigInt; + Map bigIntMap; + + TrivialNumber numberSilly; + Set numberSillySet; + + DateTime dateTime; +} + +@JsonSerializable( + includeIfNull: false, +) +@GenericConverter() +class JsonConverterGeneric { + S item; + List itemList; + Map itemMap; + + JsonConverterGeneric(); + + factory JsonConverterGeneric.fromJson(Map json) => + _$JsonConverterGenericFromJson(json); + + Map toJson() => _$JsonConverterGenericToJson(this); +} diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart new file mode 100644 index 000000000..7ce6be28e --- /dev/null +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart @@ -0,0 +1,263 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'kitchen_sink.g_exclude_null.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +KitchenSink _$KitchenSinkFromJson(Map json) { + return KitchenSink( + ctorValidatedNo42: json['no-42'] as int, + iterable: json['iterable'] as List, + dynamicIterable: json['dynamicIterable'] as List, + objectIterable: json['objectIterable'] as List, + intIterable: (json['intIterable'] as List)?.map((e) => e as int), + dateTimeIterable: (json['datetime-iterable'] as List) + ?.map((e) => e == null ? null : DateTime.parse(e as String))) + ..dateTime = json['dateTime'] == null + ? null + : DateTime.parse(json['dateTime'] as String) + ..bigInt = + json['bigInt'] == null ? null : BigInt.parse(json['bigInt'] as String) + ..set = (json['set'] as List)?.toSet() + ..dynamicSet = (json['dynamicSet'] as List)?.toSet() + ..objectSet = (json['objectSet'] as List)?.toSet() + ..intSet = (json['intSet'] as List)?.map((e) => e as int)?.toSet() + ..dateTimeSet = (json['dateTimeSet'] as List) + ?.map((e) => e == null ? null : DateTime.parse(e as String)) + ?.toSet() + ..list = json['list'] as List + ..dynamicList = json['dynamicList'] as List + ..objectList = json['objectList'] as List + ..intList = (json['intList'] as List)?.map((e) => e as int)?.toList() + ..dateTimeList = (json['dateTimeList'] as List) + ?.map((e) => e == null ? null : DateTime.parse(e as String)) + ?.toList() + ..map = json['map'] as Map + ..stringStringMap = (json['stringStringMap'] as Map)?.map( + (k, e) => MapEntry(k, e as String), + ) + ..dynamicIntMap = (json['dynamicIntMap'] as Map)?.map( + (k, e) => MapEntry(k, e as int), + ) + ..objectDateTimeMap = + (json['objectDateTimeMap'] as Map)?.map( + (k, e) => MapEntry(k, e == null ? null : DateTime.parse(e as String)), + ) + ..crazyComplex = (json['crazyComplex'] as List) + ?.map((e) => (e as Map)?.map( + (k, e) => MapEntry( + k, + (e as Map)?.map( + (k, e) => MapEntry( + k, + (e as List) + ?.map((e) => (e as List) + ?.map((e) => e == null + ? null + : DateTime.parse(e as String)) + ?.toList()) + ?.toList()), + )), + )) + ?.toList() + ..val = (json['val'] as Map)?.map( + (k, e) => MapEntry(k, e as bool), + ) + ..writeNotNull = json['writeNotNull'] as bool + ..string = json[r'$string'] as String + ..simpleObject = json['simpleObject'] == null + ? null + : SimpleObject.fromJson(json['simpleObject'] as Map) + ..strictKeysObject = json['strictKeysObject'] == null + ? null + : StrictKeysObject.fromJson( + json['strictKeysObject'] as Map) + ..validatedPropertyNo42 = json['validatedPropertyNo42'] as int; +} + +Map _$KitchenSinkToJson(KitchenSink instance) { + final val = {}; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('no-42', instance.ctorValidatedNo42); + writeNotNull('dateTime', instance.dateTime?.toIso8601String()); + writeNotNull('bigInt', instance.bigInt?.toString()); + writeNotNull('iterable', instance.iterable?.toList()); + writeNotNull('dynamicIterable', instance.dynamicIterable?.toList()); + writeNotNull('objectIterable', instance.objectIterable?.toList()); + writeNotNull('intIterable', instance.intIterable?.toList()); + writeNotNull('set', instance.set?.toList()); + writeNotNull('dynamicSet', instance.dynamicSet?.toList()); + writeNotNull('objectSet', instance.objectSet?.toList()); + writeNotNull('intSet', instance.intSet?.toList()); + writeNotNull('dateTimeSet', + instance.dateTimeSet?.map((e) => e?.toIso8601String())?.toList()); + writeNotNull('datetime-iterable', + instance.dateTimeIterable?.map((e) => e?.toIso8601String())?.toList()); + writeNotNull('list', instance.list); + writeNotNull('dynamicList', instance.dynamicList); + writeNotNull('objectList', instance.objectList); + writeNotNull('intList', instance.intList); + writeNotNull('dateTimeList', + instance.dateTimeList?.map((e) => e?.toIso8601String())?.toList()); + writeNotNull('map', instance.map); + writeNotNull('stringStringMap', instance.stringStringMap); + writeNotNull('dynamicIntMap', instance.dynamicIntMap); + writeNotNull( + 'objectDateTimeMap', + instance.objectDateTimeMap + ?.map((k, e) => MapEntry(k, e?.toIso8601String()))); + writeNotNull( + 'crazyComplex', + instance.crazyComplex + ?.map((e) => e?.map((k, e) => MapEntry( + k, + e?.map((k, e) => MapEntry( + k, + e + ?.map( + (e) => e?.map((e) => e?.toIso8601String())?.toList()) + ?.toList()))))) + ?.toList()); + writeNotNull('val', instance.val); + writeNotNull('writeNotNull', instance.writeNotNull); + writeNotNull(r'$string', instance.string); + writeNotNull('simpleObject', instance.simpleObject); + writeNotNull('strictKeysObject', instance.strictKeysObject); + writeNotNull('validatedPropertyNo42', instance.validatedPropertyNo42); + return val; +} + +JsonConverterTestClass _$JsonConverterTestClassFromJson( + Map json) { + return JsonConverterTestClass() + ..duration = json['duration'] == null + ? null + : durationConverter.fromJson(json['duration'] as int) + ..durationList = (json['durationList'] as List) + ?.map((e) => e == null ? null : durationConverter.fromJson(e as int)) + ?.toList() + ..bigInt = json['bigInt'] == null + ? null + : const BigIntStringConverter().fromJson(json['bigInt'] as String) + ..bigIntMap = (json['bigIntMap'] as Map)?.map( + (k, e) => MapEntry( + k, + e == null + ? null + : const BigIntStringConverter().fromJson(e as String)), + ) + ..numberSilly = json['numberSilly'] == null + ? null + : TrivialNumberConverter.instance.fromJson(json['numberSilly'] as int) + ..numberSillySet = (json['numberSillySet'] as List) + ?.map((e) => e == null + ? null + : TrivialNumberConverter.instance.fromJson(e as int)) + ?.toSet() + ..dateTime = json['dateTime'] == null + ? null + : const EpochDateTimeConverter().fromJson(json['dateTime'] as int); +} + +Map _$JsonConverterTestClassToJson( + JsonConverterTestClass instance) { + final val = {}; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull( + 'duration', + instance.duration == null + ? null + : durationConverter.toJson(instance.duration)); + writeNotNull( + 'durationList', + instance.durationList + ?.map((e) => e == null ? null : durationConverter.toJson(e)) + ?.toList()); + writeNotNull( + 'bigInt', + instance.bigInt == null + ? null + : const BigIntStringConverter().toJson(instance.bigInt)); + writeNotNull( + 'bigIntMap', + instance.bigIntMap?.map((k, e) => MapEntry( + k, e == null ? null : const BigIntStringConverter().toJson(e)))); + writeNotNull( + 'numberSilly', + instance.numberSilly == null + ? null + : TrivialNumberConverter.instance.toJson(instance.numberSilly)); + writeNotNull( + 'numberSillySet', + instance.numberSillySet + ?.map((e) => + e == null ? null : TrivialNumberConverter.instance.toJson(e)) + ?.toList()); + writeNotNull( + 'dateTime', + instance.dateTime == null + ? null + : const EpochDateTimeConverter().toJson(instance.dateTime)); + return val; +} + +JsonConverterGeneric _$JsonConverterGenericFromJson( + Map json) { + return JsonConverterGeneric() + ..item = json['item'] == null + ? null + : GenericConverter().fromJson(json['item'] as Map) + ..itemList = (json['itemList'] as List) + ?.map((e) => e == null + ? null + : GenericConverter().fromJson(e as Map)) + ?.toList() + ..itemMap = (json['itemMap'] as Map)?.map( + (k, e) => MapEntry( + k, + e == null + ? null + : GenericConverter().fromJson(e as Map)), + ); +} + +Map _$JsonConverterGenericToJson( + JsonConverterGeneric instance) { + final val = {}; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull( + 'item', + instance.item == null + ? null + : GenericConverter().toJson(instance.item)); + writeNotNull( + 'itemList', + instance.itemList + ?.map((e) => e == null ? null : GenericConverter().toJson(e)) + ?.toList()); + writeNotNull( + 'itemMap', + instance.itemMap?.map((k, e) => + MapEntry(k, e == null ? null : GenericConverter().toJson(e)))); + return val; +} diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__non_nullable.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__non_nullable.dart new file mode 100644 index 000000000..099403eb4 --- /dev/null +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__non_nullable.dart @@ -0,0 +1,208 @@ +// Copyright (c) 2018, 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. + +// ignore_for_file: annotate_overrides, hash_and_equals +import 'package:json_annotation/json_annotation.dart'; + +import 'json_converters.dart'; +import 'kitchen_sink_interface.dart' as k; +import 'simple_object.dart'; +import 'strict_keys_object.dart'; + +part 'kitchen_sink.g_exclude_null__non_nullable.g.dart'; + +// NOTE: these methods are replaced in the `non_nullable` cases to return +// non-null values. +List _defaultList() => []; +Set _defaultSet() => Set(); +Map _defaultMap() => {}; +SimpleObject _defaultSimpleObject() => SimpleObject(42); +StrictKeysObject _defaultStrictKeysObject() => StrictKeysObject(10, 'cool'); + +const k.KitchenSinkFactory factory = _Factory(); + +class _Factory implements k.KitchenSinkFactory { + const _Factory(); + + String get description => 'exclude_null__non_nullable'; + bool get anyMap => false; + bool get checked => false; + bool get nullable => false; + bool get excludeNull => true; + bool get explicitToJson => false; + + k.KitchenSink ctor({ + int ctorValidatedNo42, + Iterable iterable, + Iterable dynamicIterable, + Iterable objectIterable, + Iterable intIterable, + Iterable dateTimeIterable, + }) => + KitchenSink( + ctorValidatedNo42: ctorValidatedNo42, + iterable: iterable, + dynamicIterable: dynamicIterable, + objectIterable: objectIterable, + intIterable: intIterable, + dateTimeIterable: dateTimeIterable, + ); + + k.KitchenSink fromJson(Map json) => + KitchenSink.fromJson(json); + + k.JsonConverterTestClass jsonConverterCtor() => JsonConverterTestClass(); + + k.JsonConverterTestClass jsonConverterFromJson(Map json) => + JsonConverterTestClass.fromJson(json); +} + +@JsonSerializable( + nullable: false, + includeIfNull: false, +) +class KitchenSink implements k.KitchenSink { + // NOTE: exposing these as Iterable, but storing the values as List + // to make the equality test work trivially. + final Iterable _iterable; + final Iterable _dynamicIterable; + final Iterable _objectIterable; + final Iterable _intIterable; + final Iterable _dateTimeIterable; + + @JsonKey(name: 'no-42') + final int ctorValidatedNo42; + + KitchenSink({ + this.ctorValidatedNo42, + Iterable iterable, + Iterable dynamicIterable, + Iterable objectIterable, + Iterable intIterable, + Iterable dateTimeIterable, + }) : _iterable = iterable?.toList() ?? _defaultList(), + _dynamicIterable = dynamicIterable?.toList() ?? _defaultList(), + _objectIterable = objectIterable?.toList() ?? _defaultList(), + _intIterable = intIterable?.toList() ?? _defaultList(), + _dateTimeIterable = dateTimeIterable?.toList() ?? _defaultList() { + if (ctorValidatedNo42 == 42) { + throw ArgumentError.value( + 42, 'ctorValidatedNo42', 'The value `42` is not allowed.'); + } + } + + factory KitchenSink.fromJson(Map json) => + _$KitchenSinkFromJson(json); + + Map toJson() => _$KitchenSinkToJson(this); + + @JsonKey(includeIfNull: false) + DateTime dateTime = DateTime(1981, 6, 5); + + @JsonKey(includeIfNull: false) + BigInt bigInt = BigInt.parse('10000000000000000000'); + + @JsonKey(includeIfNull: false) + Iterable get iterable => _iterable; + Iterable get dynamicIterable => _dynamicIterable; + Iterable get objectIterable => _objectIterable; + Iterable get intIterable => _intIterable; + + Set set = _defaultSet(); + Set dynamicSet = _defaultSet(); + Set objectSet = _defaultSet(); + Set intSet = _defaultSet(); + Set dateTimeSet = _defaultSet(); + + // Added a one-off annotation on a property (not a field) + @JsonKey(name: 'datetime-iterable') + Iterable get dateTimeIterable => _dateTimeIterable; + + List list = _defaultList(); + List dynamicList = _defaultList(); + List objectList = _defaultList(); + List intList = _defaultList(); + @JsonKey(includeIfNull: false) + List dateTimeList = _defaultList(); + + Map map = _defaultMap(); + Map stringStringMap = _defaultMap(); + Map dynamicIntMap = _defaultMap(); + Map objectDateTimeMap = _defaultMap(); + + @JsonKey(includeIfNull: false) + List>>>> crazyComplex = + _defaultList(); + + // Handle fields with names that collide with helper names + @JsonKey(includeIfNull: false) + Map val = _defaultMap(); + bool writeNotNull; + @JsonKey(name: r'$string') + String string; + + SimpleObject simpleObject = _defaultSimpleObject(); + + StrictKeysObject strictKeysObject = _defaultStrictKeysObject(); + + int _validatedPropertyNo42; + int get validatedPropertyNo42 => _validatedPropertyNo42; + + set validatedPropertyNo42(int value) { + if (value == 42) { + throw StateError('Cannot be 42!'); + } + _validatedPropertyNo42 = value; + } + + bool operator ==(Object other) => k.sinkEquals(this, other); +} + +@JsonSerializable( + nullable: false, + includeIfNull: false, +) +// referencing a top-level field should work +@durationConverter +// referencing via a const constructor should work +@BigIntStringConverter() +@TrivialNumberConverter.instance +@EpochDateTimeConverter() +class JsonConverterTestClass implements k.JsonConverterTestClass { + JsonConverterTestClass(); + + factory JsonConverterTestClass.fromJson(Map json) => + _$JsonConverterTestClassFromJson(json); + + Map toJson() => _$JsonConverterTestClassToJson(this); + + Duration duration; + List durationList; + + BigInt bigInt = BigInt.parse('10000000000000000000'); + Map bigIntMap; + + TrivialNumber numberSilly; + Set numberSillySet; + + DateTime dateTime = DateTime(1981, 6, 5); +} + +@JsonSerializable( + nullable: false, + includeIfNull: false, +) +@GenericConverter() +class JsonConverterGeneric { + S item; + List itemList; + Map itemMap; + + JsonConverterGeneric(); + + factory JsonConverterGeneric.fromJson(Map json) => + _$JsonConverterGenericFromJson(json); + + Map toJson() => _$JsonConverterGenericToJson(this); +} diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__non_nullable.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__non_nullable.g.dart new file mode 100644 index 000000000..b992e4121 --- /dev/null +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__non_nullable.g.dart @@ -0,0 +1,170 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'kitchen_sink.g_exclude_null__non_nullable.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +KitchenSink _$KitchenSinkFromJson(Map json) { + return KitchenSink( + ctorValidatedNo42: json['no-42'] as int, + iterable: json['iterable'] as List, + dynamicIterable: json['dynamicIterable'] as List, + objectIterable: json['objectIterable'] as List, + intIterable: (json['intIterable'] as List).map((e) => e as int), + dateTimeIterable: (json['datetime-iterable'] as List) + .map((e) => DateTime.parse(e as String))) + ..dateTime = DateTime.parse(json['dateTime'] as String) + ..bigInt = BigInt.parse(json['bigInt'] as String) + ..set = (json['set'] as List).toSet() + ..dynamicSet = (json['dynamicSet'] as List).toSet() + ..objectSet = (json['objectSet'] as List).toSet() + ..intSet = (json['intSet'] as List).map((e) => e as int).toSet() + ..dateTimeSet = (json['dateTimeSet'] as List) + .map((e) => DateTime.parse(e as String)) + .toSet() + ..list = json['list'] as List + ..dynamicList = json['dynamicList'] as List + ..objectList = json['objectList'] as List + ..intList = (json['intList'] as List).map((e) => e as int).toList() + ..dateTimeList = (json['dateTimeList'] as List) + .map((e) => DateTime.parse(e as String)) + .toList() + ..map = json['map'] as Map + ..stringStringMap = Map.from(json['stringStringMap'] as Map) + ..dynamicIntMap = Map.from(json['dynamicIntMap'] as Map) + ..objectDateTimeMap = + (json['objectDateTimeMap'] as Map).map( + (k, e) => MapEntry(k, DateTime.parse(e as String)), + ) + ..crazyComplex = (json['crazyComplex'] as List) + .map((e) => (e as Map).map( + (k, e) => MapEntry( + k, + (e as Map).map( + (k, e) => MapEntry( + k, + (e as List) + .map((e) => (e as List) + .map((e) => DateTime.parse(e as String)) + .toList()) + .toList()), + )), + )) + .toList() + ..val = Map.from(json['val'] as Map) + ..writeNotNull = json['writeNotNull'] as bool + ..string = json[r'$string'] as String + ..simpleObject = + SimpleObject.fromJson(json['simpleObject'] as Map) + ..strictKeysObject = StrictKeysObject.fromJson( + json['strictKeysObject'] as Map) + ..validatedPropertyNo42 = json['validatedPropertyNo42'] as int; +} + +Map _$KitchenSinkToJson(KitchenSink instance) => + { + 'no-42': instance.ctorValidatedNo42, + 'dateTime': instance.dateTime.toIso8601String(), + 'bigInt': instance.bigInt.toString(), + 'iterable': instance.iterable.toList(), + 'dynamicIterable': instance.dynamicIterable.toList(), + 'objectIterable': instance.objectIterable.toList(), + 'intIterable': instance.intIterable.toList(), + 'set': instance.set.toList(), + 'dynamicSet': instance.dynamicSet.toList(), + 'objectSet': instance.objectSet.toList(), + 'intSet': instance.intSet.toList(), + 'dateTimeSet': + instance.dateTimeSet.map((e) => e.toIso8601String()).toList(), + 'datetime-iterable': + instance.dateTimeIterable.map((e) => e.toIso8601String()).toList(), + 'list': instance.list, + 'dynamicList': instance.dynamicList, + 'objectList': instance.objectList, + 'intList': instance.intList, + 'dateTimeList': + instance.dateTimeList.map((e) => e.toIso8601String()).toList(), + 'map': instance.map, + 'stringStringMap': instance.stringStringMap, + 'dynamicIntMap': instance.dynamicIntMap, + 'objectDateTimeMap': instance.objectDateTimeMap + .map((k, e) => MapEntry(k, e.toIso8601String())), + 'crazyComplex': instance.crazyComplex + .map((e) => e.map((k, e) => MapEntry( + k, + e.map((k, e) => MapEntry( + k, + e + .map((e) => e.map((e) => e.toIso8601String()).toList()) + .toList()))))) + .toList(), + 'val': instance.val, + 'writeNotNull': instance.writeNotNull, + r'$string': instance.string, + 'simpleObject': instance.simpleObject, + 'strictKeysObject': instance.strictKeysObject, + 'validatedPropertyNo42': instance.validatedPropertyNo42 + }; + +JsonConverterTestClass _$JsonConverterTestClassFromJson( + Map json) { + return JsonConverterTestClass() + ..duration = durationConverter.fromJson(json['duration'] as int) + ..durationList = (json['durationList'] as List) + .map((e) => durationConverter.fromJson(e as int)) + .toList() + ..bigInt = const BigIntStringConverter().fromJson(json['bigInt'] as String) + ..bigIntMap = (json['bigIntMap'] as Map).map( + (k, e) => + MapEntry(k, const BigIntStringConverter().fromJson(e as String)), + ) + ..numberSilly = + TrivialNumberConverter.instance.fromJson(json['numberSilly'] as int) + ..numberSillySet = (json['numberSillySet'] as List) + .map((e) => TrivialNumberConverter.instance.fromJson(e as int)) + .toSet() + ..dateTime = + const EpochDateTimeConverter().fromJson(json['dateTime'] as int); +} + +Map _$JsonConverterTestClassToJson( + JsonConverterTestClass instance) => + { + 'duration': durationConverter.toJson(instance.duration), + 'durationList': + instance.durationList.map(durationConverter.toJson).toList(), + 'bigInt': const BigIntStringConverter().toJson(instance.bigInt), + 'bigIntMap': instance.bigIntMap + .map((k, e) => MapEntry(k, const BigIntStringConverter().toJson(e))), + 'numberSilly': + TrivialNumberConverter.instance.toJson(instance.numberSilly), + 'numberSillySet': instance.numberSillySet + .map(TrivialNumberConverter.instance.toJson) + .toList(), + 'dateTime': const EpochDateTimeConverter().toJson(instance.dateTime) + }; + +JsonConverterGeneric _$JsonConverterGenericFromJson( + Map json) { + return JsonConverterGeneric() + ..item = + GenericConverter().fromJson(json['item'] as Map) + ..itemList = (json['itemList'] as List) + .map((e) => GenericConverter().fromJson(e as Map)) + .toList() + ..itemMap = (json['itemMap'] as Map).map( + (k, e) => MapEntry( + k, GenericConverter().fromJson(e as Map)), + ); +} + +Map _$JsonConverterGenericToJson( + JsonConverterGeneric instance) => + { + 'item': GenericConverter().toJson(instance.item), + 'itemList': instance.itemList.map(GenericConverter().toJson).toList(), + 'itemMap': instance.itemMap + .map((k, e) => MapEntry(k, GenericConverter().toJson(e))) + }; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.dart new file mode 100644 index 000000000..101479bae --- /dev/null +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.dart @@ -0,0 +1,205 @@ +// Copyright (c) 2018, 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. + +// ignore_for_file: annotate_overrides, hash_and_equals +import 'package:json_annotation/json_annotation.dart'; + +import 'json_converters.dart'; +import 'kitchen_sink_interface.dart' as k; +import 'simple_object.dart'; +import 'strict_keys_object.dart'; + +part 'kitchen_sink.g_explicit_to_json.g.dart'; + +// NOTE: these methods are replaced in the `non_nullable` cases to return +// non-null values. +List _defaultList() => null; +Set _defaultSet() => null; +Map _defaultMap() => null; +SimpleObject _defaultSimpleObject() => null; +StrictKeysObject _defaultStrictKeysObject() => null; + +const k.KitchenSinkFactory factory = _Factory(); + +class _Factory implements k.KitchenSinkFactory { + const _Factory(); + + String get description => 'explicit_to_json'; + bool get anyMap => false; + bool get checked => false; + bool get nullable => true; + bool get excludeNull => false; + bool get explicitToJson => true; + + k.KitchenSink ctor({ + int ctorValidatedNo42, + Iterable iterable, + Iterable dynamicIterable, + Iterable objectIterable, + Iterable intIterable, + Iterable dateTimeIterable, + }) => + KitchenSink( + ctorValidatedNo42: ctorValidatedNo42, + iterable: iterable, + dynamicIterable: dynamicIterable, + objectIterable: objectIterable, + intIterable: intIterable, + dateTimeIterable: dateTimeIterable, + ); + + k.KitchenSink fromJson(Map json) => + KitchenSink.fromJson(json); + + k.JsonConverterTestClass jsonConverterCtor() => JsonConverterTestClass(); + + k.JsonConverterTestClass jsonConverterFromJson(Map json) => + JsonConverterTestClass.fromJson(json); +} + +@JsonSerializable( + explicitToJson: true, +) +class KitchenSink implements k.KitchenSink { + // NOTE: exposing these as Iterable, but storing the values as List + // to make the equality test work trivially. + final Iterable _iterable; + final Iterable _dynamicIterable; + final Iterable _objectIterable; + final Iterable _intIterable; + final Iterable _dateTimeIterable; + + @JsonKey(name: 'no-42') + final int ctorValidatedNo42; + + KitchenSink({ + this.ctorValidatedNo42, + Iterable iterable, + Iterable dynamicIterable, + Iterable objectIterable, + Iterable intIterable, + Iterable dateTimeIterable, + }) : _iterable = iterable?.toList() ?? _defaultList(), + _dynamicIterable = dynamicIterable?.toList() ?? _defaultList(), + _objectIterable = objectIterable?.toList() ?? _defaultList(), + _intIterable = intIterable?.toList() ?? _defaultList(), + _dateTimeIterable = dateTimeIterable?.toList() ?? _defaultList() { + if (ctorValidatedNo42 == 42) { + throw ArgumentError.value( + 42, 'ctorValidatedNo42', 'The value `42` is not allowed.'); + } + } + + factory KitchenSink.fromJson(Map json) => + _$KitchenSinkFromJson(json); + + Map toJson() => _$KitchenSinkToJson(this); + + @JsonKey(includeIfNull: false) + DateTime dateTime; + + @JsonKey(includeIfNull: false) + BigInt bigInt; + + @JsonKey(includeIfNull: false) + Iterable get iterable => _iterable; + Iterable get dynamicIterable => _dynamicIterable; + Iterable get objectIterable => _objectIterable; + Iterable get intIterable => _intIterable; + + Set set = _defaultSet(); + Set dynamicSet = _defaultSet(); + Set objectSet = _defaultSet(); + Set intSet = _defaultSet(); + Set dateTimeSet = _defaultSet(); + + // Added a one-off annotation on a property (not a field) + @JsonKey(name: 'datetime-iterable') + Iterable get dateTimeIterable => _dateTimeIterable; + + List list = _defaultList(); + List dynamicList = _defaultList(); + List objectList = _defaultList(); + List intList = _defaultList(); + @JsonKey(includeIfNull: false) + List dateTimeList = _defaultList(); + + Map map = _defaultMap(); + Map stringStringMap = _defaultMap(); + Map dynamicIntMap = _defaultMap(); + Map objectDateTimeMap = _defaultMap(); + + @JsonKey(includeIfNull: false) + List>>>> crazyComplex = + _defaultList(); + + // Handle fields with names that collide with helper names + @JsonKey(includeIfNull: false) + Map val = _defaultMap(); + bool writeNotNull; + @JsonKey(name: r'$string') + String string; + + SimpleObject simpleObject = _defaultSimpleObject(); + + StrictKeysObject strictKeysObject = _defaultStrictKeysObject(); + + int _validatedPropertyNo42; + int get validatedPropertyNo42 => _validatedPropertyNo42; + + set validatedPropertyNo42(int value) { + if (value == 42) { + throw StateError('Cannot be 42!'); + } + _validatedPropertyNo42 = value; + } + + bool operator ==(Object other) => k.sinkEquals(this, other); +} + +@JsonSerializable( + explicitToJson: true, +) +// referencing a top-level field should work +@durationConverter +// referencing via a const constructor should work +@BigIntStringConverter() +@TrivialNumberConverter.instance +@EpochDateTimeConverter() +class JsonConverterTestClass implements k.JsonConverterTestClass { + JsonConverterTestClass(); + + factory JsonConverterTestClass.fromJson(Map json) => + _$JsonConverterTestClassFromJson(json); + + Map toJson() => _$JsonConverterTestClassToJson(this); + + Duration duration; + List durationList; + + BigInt bigInt; + Map bigIntMap; + + TrivialNumber numberSilly; + Set numberSillySet; + + DateTime dateTime; +} + +@JsonSerializable( + explicitToJson: true, +) +@GenericConverter() +class JsonConverterGeneric { + S item; + List itemList; + Map itemMap; + + JsonConverterGeneric(); + + factory JsonConverterGeneric.fromJson(Map json) => + _$JsonConverterGenericFromJson(json); + + Map toJson() => _$JsonConverterGenericToJson(this); +} diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart new file mode 100644 index 000000000..981600c51 --- /dev/null +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart @@ -0,0 +1,226 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'kitchen_sink.g_explicit_to_json.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +KitchenSink _$KitchenSinkFromJson(Map json) { + return KitchenSink( + ctorValidatedNo42: json['no-42'] as int, + iterable: json['iterable'] as List, + dynamicIterable: json['dynamicIterable'] as List, + objectIterable: json['objectIterable'] as List, + intIterable: (json['intIterable'] as List)?.map((e) => e as int), + dateTimeIterable: (json['datetime-iterable'] as List) + ?.map((e) => e == null ? null : DateTime.parse(e as String))) + ..dateTime = json['dateTime'] == null + ? null + : DateTime.parse(json['dateTime'] as String) + ..bigInt = + json['bigInt'] == null ? null : BigInt.parse(json['bigInt'] as String) + ..set = (json['set'] as List)?.toSet() + ..dynamicSet = (json['dynamicSet'] as List)?.toSet() + ..objectSet = (json['objectSet'] as List)?.toSet() + ..intSet = (json['intSet'] as List)?.map((e) => e as int)?.toSet() + ..dateTimeSet = (json['dateTimeSet'] as List) + ?.map((e) => e == null ? null : DateTime.parse(e as String)) + ?.toSet() + ..list = json['list'] as List + ..dynamicList = json['dynamicList'] as List + ..objectList = json['objectList'] as List + ..intList = (json['intList'] as List)?.map((e) => e as int)?.toList() + ..dateTimeList = (json['dateTimeList'] as List) + ?.map((e) => e == null ? null : DateTime.parse(e as String)) + ?.toList() + ..map = json['map'] as Map + ..stringStringMap = (json['stringStringMap'] as Map)?.map( + (k, e) => MapEntry(k, e as String), + ) + ..dynamicIntMap = (json['dynamicIntMap'] as Map)?.map( + (k, e) => MapEntry(k, e as int), + ) + ..objectDateTimeMap = + (json['objectDateTimeMap'] as Map)?.map( + (k, e) => MapEntry(k, e == null ? null : DateTime.parse(e as String)), + ) + ..crazyComplex = (json['crazyComplex'] as List) + ?.map((e) => (e as Map)?.map( + (k, e) => MapEntry( + k, + (e as Map)?.map( + (k, e) => MapEntry( + k, + (e as List) + ?.map((e) => (e as List) + ?.map((e) => e == null + ? null + : DateTime.parse(e as String)) + ?.toList()) + ?.toList()), + )), + )) + ?.toList() + ..val = (json['val'] as Map)?.map( + (k, e) => MapEntry(k, e as bool), + ) + ..writeNotNull = json['writeNotNull'] as bool + ..string = json[r'$string'] as String + ..simpleObject = json['simpleObject'] == null + ? null + : SimpleObject.fromJson(json['simpleObject'] as Map) + ..strictKeysObject = json['strictKeysObject'] == null + ? null + : StrictKeysObject.fromJson( + json['strictKeysObject'] as Map) + ..validatedPropertyNo42 = json['validatedPropertyNo42'] as int; +} + +Map _$KitchenSinkToJson(KitchenSink instance) { + final val = { + 'no-42': instance.ctorValidatedNo42, + }; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('dateTime', instance.dateTime?.toIso8601String()); + writeNotNull('bigInt', instance.bigInt?.toString()); + writeNotNull('iterable', instance.iterable?.toList()); + val['dynamicIterable'] = instance.dynamicIterable?.toList(); + val['objectIterable'] = instance.objectIterable?.toList(); + val['intIterable'] = instance.intIterable?.toList(); + val['set'] = instance.set?.toList(); + val['dynamicSet'] = instance.dynamicSet?.toList(); + val['objectSet'] = instance.objectSet?.toList(); + val['intSet'] = instance.intSet?.toList(); + val['dateTimeSet'] = + instance.dateTimeSet?.map((e) => e?.toIso8601String())?.toList(); + val['datetime-iterable'] = + instance.dateTimeIterable?.map((e) => e?.toIso8601String())?.toList(); + val['list'] = instance.list; + val['dynamicList'] = instance.dynamicList; + val['objectList'] = instance.objectList; + val['intList'] = instance.intList; + writeNotNull('dateTimeList', + instance.dateTimeList?.map((e) => e?.toIso8601String())?.toList()); + val['map'] = instance.map; + val['stringStringMap'] = instance.stringStringMap; + val['dynamicIntMap'] = instance.dynamicIntMap; + val['objectDateTimeMap'] = instance.objectDateTimeMap + ?.map((k, e) => MapEntry(k, e?.toIso8601String())); + writeNotNull( + 'crazyComplex', + instance.crazyComplex + ?.map((e) => e?.map((k, e) => MapEntry( + k, + e?.map((k, e) => MapEntry( + k, + e + ?.map( + (e) => e?.map((e) => e?.toIso8601String())?.toList()) + ?.toList()))))) + ?.toList()); + writeNotNull('val', instance.val); + val['writeNotNull'] = instance.writeNotNull; + val[r'$string'] = instance.string; + val['simpleObject'] = instance.simpleObject?.toJson(); + val['strictKeysObject'] = instance.strictKeysObject?.toJson(); + val['validatedPropertyNo42'] = instance.validatedPropertyNo42; + return val; +} + +JsonConverterTestClass _$JsonConverterTestClassFromJson( + Map json) { + return JsonConverterTestClass() + ..duration = json['duration'] == null + ? null + : durationConverter.fromJson(json['duration'] as int) + ..durationList = (json['durationList'] as List) + ?.map((e) => e == null ? null : durationConverter.fromJson(e as int)) + ?.toList() + ..bigInt = json['bigInt'] == null + ? null + : const BigIntStringConverter().fromJson(json['bigInt'] as String) + ..bigIntMap = (json['bigIntMap'] as Map)?.map( + (k, e) => MapEntry( + k, + e == null + ? null + : const BigIntStringConverter().fromJson(e as String)), + ) + ..numberSilly = json['numberSilly'] == null + ? null + : TrivialNumberConverter.instance.fromJson(json['numberSilly'] as int) + ..numberSillySet = (json['numberSillySet'] as List) + ?.map((e) => e == null + ? null + : TrivialNumberConverter.instance.fromJson(e as int)) + ?.toSet() + ..dateTime = json['dateTime'] == null + ? null + : const EpochDateTimeConverter().fromJson(json['dateTime'] as int); +} + +Map _$JsonConverterTestClassToJson( + JsonConverterTestClass instance) => + { + 'duration': instance.duration == null + ? null + : durationConverter.toJson(instance.duration), + 'durationList': instance.durationList + ?.map((e) => e == null ? null : durationConverter.toJson(e)) + ?.toList(), + 'bigInt': instance.bigInt == null + ? null + : const BigIntStringConverter().toJson(instance.bigInt), + 'bigIntMap': instance.bigIntMap?.map((k, e) => MapEntry( + k, e == null ? null : const BigIntStringConverter().toJson(e))), + 'numberSilly': instance.numberSilly == null + ? null + : TrivialNumberConverter.instance.toJson(instance.numberSilly), + 'numberSillySet': instance.numberSillySet + ?.map((e) => + e == null ? null : TrivialNumberConverter.instance.toJson(e)) + ?.toList(), + 'dateTime': instance.dateTime == null + ? null + : const EpochDateTimeConverter().toJson(instance.dateTime) + }; + +JsonConverterGeneric _$JsonConverterGenericFromJson( + Map json) { + return JsonConverterGeneric() + ..item = json['item'] == null + ? null + : GenericConverter().fromJson(json['item'] as Map) + ..itemList = (json['itemList'] as List) + ?.map((e) => e == null + ? null + : GenericConverter().fromJson(e as Map)) + ?.toList() + ..itemMap = (json['itemMap'] as Map)?.map( + (k, e) => MapEntry( + k, + e == null + ? null + : GenericConverter().fromJson(e as Map)), + ); +} + +Map _$JsonConverterGenericToJson( + JsonConverterGeneric instance) => + { + 'item': instance.item == null + ? null + : GenericConverter().toJson(instance.item), + 'itemList': instance.itemList + ?.map((e) => e == null ? null : GenericConverter().toJson(e)) + ?.toList(), + 'itemMap': instance.itemMap?.map((k, e) => + MapEntry(k, e == null ? null : GenericConverter().toJson(e))) + }; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart b/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart index a11169c96..28f1b4a2e 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart @@ -10,6 +10,8 @@ abstract class KitchenSinkFactory { bool get anyMap; bool get checked; bool get nullable; + bool get excludeNull; + bool get explicitToJson; KitchenSink ctor({ int ctorValidatedNo42, diff --git a/json_serializable/test/kitchen_sink/kitchen_sink_test.dart b/json_serializable/test/kitchen_sink/kitchen_sink_test.dart index f33138b43..c2ef97548 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink_test.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink_test.dart @@ -95,32 +95,40 @@ void _nonNullableTests(KitchenSinkFactory factory) { } void _nullableTests(KitchenSinkFactory factory) { - void roundTripItem(KitchenSink p) { - roundTripObject(p, (json) => factory.fromJson(json)); + void roundTripSink(KitchenSink p) { + roundTripObject(p, factory.fromJson); } test('nullable values are allowed in the nullable version', () { final instance = factory.jsonConverterCtor(); final json = instance.toJson(); - expect(json.values, everyElement(isNull)); - expect(json.keys, unorderedEquals(_jsonConverterValidValues.keys)); - final instance2 = factory.jsonConverterFromJson(json); - expect(instance2.toJson(), json); + if (factory.excludeNull) { + expect(json, isEmpty); + } else { + expect(json.values, everyElement(isNull)); + expect(json.keys, unorderedEquals(_jsonConverterValidValues.keys)); + + final instance2 = factory.jsonConverterFromJson(json); + expect(instance2.toJson(), json); + } }); test('Fields with `!includeIfNull` should not be included when null', () { final item = factory.ctor(); - - final expectedDefaultKeys = _validValues.keys.toSet() - ..removeAll(_excludeIfNullKeys); - final encoded = item.toJson(); - expect(encoded.keys, orderedEquals(expectedDefaultKeys)); + if (factory.excludeNull) { + expect(encoded, isEmpty); + } else { + final expectedDefaultKeys = _validValues.keys.toSet() + ..removeAll(_excludeIfNullKeys); + + expect(encoded.keys, orderedEquals(expectedDefaultKeys)); - for (final key in expectedDefaultKeys) { - expect(encoded, containsPair(key, isNull)); + for (final key in expectedDefaultKeys) { + expect(encoded, containsPair(key, isNull)); + } } }); @@ -130,7 +138,7 @@ void _nullableTests(KitchenSinkFactory factory) { ..dateTimeList = [now, null] ..objectDateTimeMap = {'value': now, 'null': null}; - roundTripItem(item); + roundTripSink(item); }); test('complex nested type', () { @@ -152,7 +160,7 @@ void _nullableTests(KitchenSinkFactory factory) { } } ]; - roundTripItem(item); + roundTripSink(item); }); } @@ -221,16 +229,37 @@ void _sharedTests(KitchenSinkFactory factory) { ..val = {}; final json = item.toJson(); - expect(json.keys, orderedEquals(_validValues.keys)); + + if (factory.excludeNull && factory.nullable) { + expect( + json.keys, + orderedEquals([ + 'dateTime', + 'bigInt', + 'iterable', + 'dateTimeList', + 'crazyComplex', + 'val' + ]), + ); + } else { + expect(json.keys, orderedEquals(_validValues.keys)); + } }); test('valid values round-trip - json', () { final validInstance = factory.fromJson(_validValues); + + bool containsKey(String key) { + return _iterableMapKeys.contains(key) || + (factory.explicitToJson && _encodedAsMapKeys.contains(key)); + } + for (var entry in validInstance.toJson().entries) { expect(entry.value, isNotNull, reason: 'key "${entry.key}" should not be null'); - if (_iterableMapKeys.contains(entry.key)) { + if (containsKey(entry.key)) { expect(entry.value, anyOf(isMap, isList), reason: 'key "${entry.key}" should be a Map/List'); } else { @@ -392,6 +421,8 @@ const _excludeIfNullKeys = [ _generatedLocalVarName ]; +const _encodedAsMapKeys = ['simpleObject', 'strictKeysObject']; + const _iterableMapKeys = [ 'crazyComplex', 'datetime-iterable', diff --git a/json_serializable/tool/builder.dart b/json_serializable/tool/builder.dart index 9ff0c96ae..c9a06c120 100644 --- a/json_serializable/tool/builder.dart +++ b/json_serializable/tool/builder.dart @@ -114,6 +114,9 @@ const _configReplacements = { 'checked': _Replacement.addJsonSerializableKey('checked', true), 'non_nullable': _Replacement.addJsonSerializableKey('nullable', false), 'use_wrappers': _Replacement.addJsonSerializableKey('useWrappers', true), + 'explicit_to_json': + _Replacement.addJsonSerializableKey('explicitToJson', true), + 'exclude_null': _Replacement.addJsonSerializableKey('includeIfNull', false), }; const _kitchenSinkReplacements = { @@ -141,7 +144,23 @@ const _kitchenSinkReplacements = { 'bool get checked => true;', ) ], + 'exclude_null': [ + _Replacement( + 'bool get excludeNull => false;', + 'bool get excludeNull => true;', + ), + ], + 'explicit_to_json': [ + _Replacement( + 'bool get explicitToJson => false;', + 'bool get explicitToJson => true;', + ), + ], 'non_nullable': [ + _Replacement( + 'bool get nullable => true;', + 'bool get nullable => false;', + ), _Replacement( 'List _defaultList() => null;', 'List _defaultList() => [];', @@ -171,10 +190,6 @@ const _kitchenSinkReplacements = { 'BigInt bigInt;', "BigInt bigInt = BigInt.parse('10000000000000000000');", ), - _Replacement( - 'bool get nullable => true;', - 'bool get nullable => false;', - ) ], }; @@ -207,11 +222,14 @@ const _kitchenSinkBaseName = 'kitchen_sink'; // TODO: use a set of sets, once we're >=2.2.0 const _fileConfigurationMap = >>{ _kitchenSinkBaseName: [ - ['any_map'], ['any_map', 'checked', 'non_nullable'], - ['any_map', 'non_nullable'], ['any_map', 'non_nullable', 'use_wrappers'], + ['any_map', 'non_nullable'], ['any_map', 'use_wrappers'], + ['any_map'], + ['exclude_null', 'non_nullable'], + ['exclude_null'], + ['explicit_to_json'], ], 'default_value': [ ['any_map', 'checked'], From 5218eebb9a144c8cbd499ad9b9fdbaf52e4cede6 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Fri, 15 Mar 2019 20:41:53 -0700 Subject: [PATCH 080/569] Kitchen sink test cleanup (#419) Remove one-off nullable configuration since we do it as a whole class --- json_serializable/build.yaml | 2 +- .../test/kitchen_sink/kitchen_sink.dart | 6 - .../kitchen_sink/kitchen_sink.factories.dart | 5 +- .../test/kitchen_sink/kitchen_sink.g.dart | 85 ++++---- .../kitchen_sink/kitchen_sink.g_any_map.dart | 6 - .../kitchen_sink.g_any_map.g.dart | 85 ++++---- ...sink.g_any_map__checked__non_nullable.dart | 6 - .../kitchen_sink.g_any_map__non_nullable.dart | 6 - ...g_any_map__non_nullable__use_wrappers.dart | 6 - .../kitchen_sink.g_exclude_null.dart | 6 - ...hen_sink.g_exclude_null__non_nullable.dart | 6 - ...en_sink.g_exclude_null__use_wrappers.dart} | 28 ++- ..._sink.g_exclude_null__use_wrappers.g.dart} | 181 ++++++++++++------ .../kitchen_sink.g_explicit_to_json.dart | 6 - .../kitchen_sink.g_explicit_to_json.g.dart | 85 ++++---- .../test/kitchen_sink/kitchen_sink_test.dart | 40 +--- json_serializable/tool/builder.dart | 2 +- 17 files changed, 259 insertions(+), 302 deletions(-) rename json_serializable/test/kitchen_sink/{kitchen_sink.g_any_map__use_wrappers.dart => kitchen_sink.g_exclude_null__use_wrappers.dart} (90%) rename json_serializable/test/kitchen_sink/{kitchen_sink.g_any_map__use_wrappers.g.dart => kitchen_sink.g_exclude_null__use_wrappers.g.dart} (74%) diff --git a/json_serializable/build.yaml b/json_serializable/build.yaml index ce6e5e2f5..4ba0b2ee3 100644 --- a/json_serializable/build.yaml +++ b/json_serializable/build.yaml @@ -41,9 +41,9 @@ builders: - .g_any_map__checked__non_nullable.dart - .g_any_map__non_nullable.dart - .g_any_map__non_nullable__use_wrappers.dart - - .g_any_map__use_wrappers.dart - .g_exclude_null.dart - .g_exclude_null__non_nullable.dart + - .g_exclude_null__use_wrappers.dart - .g_explicit_to_json.dart - .g_non_nullable.dart - .g_non_nullable__use_wrappers.dart diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.dart b/json_serializable/test/kitchen_sink/kitchen_sink.dart index 8140c876e..aeaa57dde 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.dart @@ -94,13 +94,10 @@ class KitchenSink implements k.KitchenSink { Map toJson() => _$KitchenSinkToJson(this); - @JsonKey(includeIfNull: false) DateTime dateTime; - @JsonKey(includeIfNull: false) BigInt bigInt; - @JsonKey(includeIfNull: false) Iterable get iterable => _iterable; Iterable get dynamicIterable => _dynamicIterable; Iterable get objectIterable => _objectIterable; @@ -120,7 +117,6 @@ class KitchenSink implements k.KitchenSink { List dynamicList = _defaultList(); List objectList = _defaultList(); List intList = _defaultList(); - @JsonKey(includeIfNull: false) List dateTimeList = _defaultList(); Map map = _defaultMap(); @@ -128,12 +124,10 @@ class KitchenSink implements k.KitchenSink { Map dynamicIntMap = _defaultMap(); Map objectDateTimeMap = _defaultMap(); - @JsonKey(includeIfNull: false) List>>>> crazyComplex = _defaultList(); // Handle fields with names that collide with helper names - @JsonKey(includeIfNull: false) Map val = _defaultMap(); bool writeNotNull; @JsonKey(name: r'$string') diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.factories.dart b/json_serializable/test/kitchen_sink/kitchen_sink.factories.dart index 7527c6970..089d1e2ee 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.factories.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.factories.dart @@ -5,10 +5,11 @@ import 'kitchen_sink.g_any_map__checked__non_nullable.dart' import 'kitchen_sink.g_any_map__non_nullable.dart' as any_map__non_nullable; import 'kitchen_sink.g_any_map__non_nullable__use_wrappers.dart' as any_map__non_nullable__use_wrappers; -import 'kitchen_sink.g_any_map__use_wrappers.dart' as any_map__use_wrappers; import 'kitchen_sink.g_exclude_null.dart' as exclude_null; import 'kitchen_sink.g_exclude_null__non_nullable.dart' as exclude_null__non_nullable; +import 'kitchen_sink.g_exclude_null__use_wrappers.dart' + as exclude_null__use_wrappers; import 'kitchen_sink.g_explicit_to_json.dart' as explicit_to_json; const factories = [ @@ -17,8 +18,8 @@ const factories = [ any_map__checked__non_nullable.factory, any_map__non_nullable.factory, any_map__non_nullable__use_wrappers.factory, - any_map__use_wrappers.factory, exclude_null.factory, exclude_null__non_nullable.factory, + exclude_null__use_wrappers.factory, explicit_to_json.factory, ]; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g.dart index ac470b6af..7f68f6054 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g.dart @@ -77,45 +77,35 @@ KitchenSink _$KitchenSinkFromJson(Map json) { ..validatedPropertyNo42 = json['validatedPropertyNo42'] as int; } -Map _$KitchenSinkToJson(KitchenSink instance) { - final val = { - 'no-42': instance.ctorValidatedNo42, - }; - - void writeNotNull(String key, dynamic value) { - if (value != null) { - val[key] = value; - } - } - - writeNotNull('dateTime', instance.dateTime?.toIso8601String()); - writeNotNull('bigInt', instance.bigInt?.toString()); - writeNotNull('iterable', instance.iterable?.toList()); - val['dynamicIterable'] = instance.dynamicIterable?.toList(); - val['objectIterable'] = instance.objectIterable?.toList(); - val['intIterable'] = instance.intIterable?.toList(); - val['set'] = instance.set?.toList(); - val['dynamicSet'] = instance.dynamicSet?.toList(); - val['objectSet'] = instance.objectSet?.toList(); - val['intSet'] = instance.intSet?.toList(); - val['dateTimeSet'] = - instance.dateTimeSet?.map((e) => e?.toIso8601String())?.toList(); - val['datetime-iterable'] = - instance.dateTimeIterable?.map((e) => e?.toIso8601String())?.toList(); - val['list'] = instance.list; - val['dynamicList'] = instance.dynamicList; - val['objectList'] = instance.objectList; - val['intList'] = instance.intList; - writeNotNull('dateTimeList', - instance.dateTimeList?.map((e) => e?.toIso8601String())?.toList()); - val['map'] = instance.map; - val['stringStringMap'] = instance.stringStringMap; - val['dynamicIntMap'] = instance.dynamicIntMap; - val['objectDateTimeMap'] = instance.objectDateTimeMap - ?.map((k, e) => MapEntry(k, e?.toIso8601String())); - writeNotNull( - 'crazyComplex', - instance.crazyComplex +Map _$KitchenSinkToJson(KitchenSink instance) => + { + 'no-42': instance.ctorValidatedNo42, + 'dateTime': instance.dateTime?.toIso8601String(), + 'bigInt': instance.bigInt?.toString(), + 'iterable': instance.iterable?.toList(), + 'dynamicIterable': instance.dynamicIterable?.toList(), + 'objectIterable': instance.objectIterable?.toList(), + 'intIterable': instance.intIterable?.toList(), + 'set': instance.set?.toList(), + 'dynamicSet': instance.dynamicSet?.toList(), + 'objectSet': instance.objectSet?.toList(), + 'intSet': instance.intSet?.toList(), + 'dateTimeSet': + instance.dateTimeSet?.map((e) => e?.toIso8601String())?.toList(), + 'datetime-iterable': + instance.dateTimeIterable?.map((e) => e?.toIso8601String())?.toList(), + 'list': instance.list, + 'dynamicList': instance.dynamicList, + 'objectList': instance.objectList, + 'intList': instance.intList, + 'dateTimeList': + instance.dateTimeList?.map((e) => e?.toIso8601String())?.toList(), + 'map': instance.map, + 'stringStringMap': instance.stringStringMap, + 'dynamicIntMap': instance.dynamicIntMap, + 'objectDateTimeMap': instance.objectDateTimeMap + ?.map((k, e) => MapEntry(k, e?.toIso8601String())), + 'crazyComplex': instance.crazyComplex ?.map((e) => e?.map((k, e) => MapEntry( k, e?.map((k, e) => MapEntry( @@ -124,15 +114,14 @@ Map _$KitchenSinkToJson(KitchenSink instance) { ?.map( (e) => e?.map((e) => e?.toIso8601String())?.toList()) ?.toList()))))) - ?.toList()); - writeNotNull('val', instance.val); - val['writeNotNull'] = instance.writeNotNull; - val[r'$string'] = instance.string; - val['simpleObject'] = instance.simpleObject; - val['strictKeysObject'] = instance.strictKeysObject; - val['validatedPropertyNo42'] = instance.validatedPropertyNo42; - return val; -} + ?.toList(), + 'val': instance.val, + 'writeNotNull': instance.writeNotNull, + r'$string': instance.string, + 'simpleObject': instance.simpleObject, + 'strictKeysObject': instance.strictKeysObject, + 'validatedPropertyNo42': instance.validatedPropertyNo42 + }; JsonConverterTestClass _$JsonConverterTestClassFromJson( Map json) { diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart index 6c0b7e9d1..b68578374 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart @@ -94,13 +94,10 @@ class KitchenSink implements k.KitchenSink { Map toJson() => _$KitchenSinkToJson(this); - @JsonKey(includeIfNull: false) DateTime dateTime; - @JsonKey(includeIfNull: false) BigInt bigInt; - @JsonKey(includeIfNull: false) Iterable get iterable => _iterable; Iterable get dynamicIterable => _dynamicIterable; Iterable get objectIterable => _objectIterable; @@ -120,7 +117,6 @@ class KitchenSink implements k.KitchenSink { List dynamicList = _defaultList(); List objectList = _defaultList(); List intList = _defaultList(); - @JsonKey(includeIfNull: false) List dateTimeList = _defaultList(); Map map = _defaultMap(); @@ -128,12 +124,10 @@ class KitchenSink implements k.KitchenSink { Map dynamicIntMap = _defaultMap(); Map objectDateTimeMap = _defaultMap(); - @JsonKey(includeIfNull: false) List>>>> crazyComplex = _defaultList(); // Handle fields with names that collide with helper names - @JsonKey(includeIfNull: false) Map val = _defaultMap(); bool writeNotNull; @JsonKey(name: r'$string') diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart index c1a1d8bab..a4061b5b9 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart @@ -75,45 +75,35 @@ KitchenSink _$KitchenSinkFromJson(Map json) { ..validatedPropertyNo42 = json['validatedPropertyNo42'] as int; } -Map _$KitchenSinkToJson(KitchenSink instance) { - final val = { - 'no-42': instance.ctorValidatedNo42, - }; - - void writeNotNull(String key, dynamic value) { - if (value != null) { - val[key] = value; - } - } - - writeNotNull('dateTime', instance.dateTime?.toIso8601String()); - writeNotNull('bigInt', instance.bigInt?.toString()); - writeNotNull('iterable', instance.iterable?.toList()); - val['dynamicIterable'] = instance.dynamicIterable?.toList(); - val['objectIterable'] = instance.objectIterable?.toList(); - val['intIterable'] = instance.intIterable?.toList(); - val['set'] = instance.set?.toList(); - val['dynamicSet'] = instance.dynamicSet?.toList(); - val['objectSet'] = instance.objectSet?.toList(); - val['intSet'] = instance.intSet?.toList(); - val['dateTimeSet'] = - instance.dateTimeSet?.map((e) => e?.toIso8601String())?.toList(); - val['datetime-iterable'] = - instance.dateTimeIterable?.map((e) => e?.toIso8601String())?.toList(); - val['list'] = instance.list; - val['dynamicList'] = instance.dynamicList; - val['objectList'] = instance.objectList; - val['intList'] = instance.intList; - writeNotNull('dateTimeList', - instance.dateTimeList?.map((e) => e?.toIso8601String())?.toList()); - val['map'] = instance.map; - val['stringStringMap'] = instance.stringStringMap; - val['dynamicIntMap'] = instance.dynamicIntMap; - val['objectDateTimeMap'] = instance.objectDateTimeMap - ?.map((k, e) => MapEntry(k, e?.toIso8601String())); - writeNotNull( - 'crazyComplex', - instance.crazyComplex +Map _$KitchenSinkToJson(KitchenSink instance) => + { + 'no-42': instance.ctorValidatedNo42, + 'dateTime': instance.dateTime?.toIso8601String(), + 'bigInt': instance.bigInt?.toString(), + 'iterable': instance.iterable?.toList(), + 'dynamicIterable': instance.dynamicIterable?.toList(), + 'objectIterable': instance.objectIterable?.toList(), + 'intIterable': instance.intIterable?.toList(), + 'set': instance.set?.toList(), + 'dynamicSet': instance.dynamicSet?.toList(), + 'objectSet': instance.objectSet?.toList(), + 'intSet': instance.intSet?.toList(), + 'dateTimeSet': + instance.dateTimeSet?.map((e) => e?.toIso8601String())?.toList(), + 'datetime-iterable': + instance.dateTimeIterable?.map((e) => e?.toIso8601String())?.toList(), + 'list': instance.list, + 'dynamicList': instance.dynamicList, + 'objectList': instance.objectList, + 'intList': instance.intList, + 'dateTimeList': + instance.dateTimeList?.map((e) => e?.toIso8601String())?.toList(), + 'map': instance.map, + 'stringStringMap': instance.stringStringMap, + 'dynamicIntMap': instance.dynamicIntMap, + 'objectDateTimeMap': instance.objectDateTimeMap + ?.map((k, e) => MapEntry(k, e?.toIso8601String())), + 'crazyComplex': instance.crazyComplex ?.map((e) => e?.map((k, e) => MapEntry( k, e?.map((k, e) => MapEntry( @@ -122,15 +112,14 @@ Map _$KitchenSinkToJson(KitchenSink instance) { ?.map( (e) => e?.map((e) => e?.toIso8601String())?.toList()) ?.toList()))))) - ?.toList()); - writeNotNull('val', instance.val); - val['writeNotNull'] = instance.writeNotNull; - val[r'$string'] = instance.string; - val['simpleObject'] = instance.simpleObject; - val['strictKeysObject'] = instance.strictKeysObject; - val['validatedPropertyNo42'] = instance.validatedPropertyNo42; - return val; -} + ?.toList(), + 'val': instance.val, + 'writeNotNull': instance.writeNotNull, + r'$string': instance.string, + 'simpleObject': instance.simpleObject, + 'strictKeysObject': instance.strictKeysObject, + 'validatedPropertyNo42': instance.validatedPropertyNo42 + }; JsonConverterTestClass _$JsonConverterTestClassFromJson(Map json) { return JsonConverterTestClass() diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked__non_nullable.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked__non_nullable.dart index ab9044018..a91b6d2e0 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked__non_nullable.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked__non_nullable.dart @@ -96,13 +96,10 @@ class KitchenSink implements k.KitchenSink { Map toJson() => _$KitchenSinkToJson(this); - @JsonKey(includeIfNull: false) DateTime dateTime = DateTime(1981, 6, 5); - @JsonKey(includeIfNull: false) BigInt bigInt = BigInt.parse('10000000000000000000'); - @JsonKey(includeIfNull: false) Iterable get iterable => _iterable; Iterable get dynamicIterable => _dynamicIterable; Iterable get objectIterable => _objectIterable; @@ -122,7 +119,6 @@ class KitchenSink implements k.KitchenSink { List dynamicList = _defaultList(); List objectList = _defaultList(); List intList = _defaultList(); - @JsonKey(includeIfNull: false) List dateTimeList = _defaultList(); Map map = _defaultMap(); @@ -130,12 +126,10 @@ class KitchenSink implements k.KitchenSink { Map dynamicIntMap = _defaultMap(); Map objectDateTimeMap = _defaultMap(); - @JsonKey(includeIfNull: false) List>>>> crazyComplex = _defaultList(); // Handle fields with names that collide with helper names - @JsonKey(includeIfNull: false) Map val = _defaultMap(); bool writeNotNull; @JsonKey(name: r'$string') diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable.dart index a7d910f03..b3a1549ce 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable.dart @@ -95,13 +95,10 @@ class KitchenSink implements k.KitchenSink { Map toJson() => _$KitchenSinkToJson(this); - @JsonKey(includeIfNull: false) DateTime dateTime = DateTime(1981, 6, 5); - @JsonKey(includeIfNull: false) BigInt bigInt = BigInt.parse('10000000000000000000'); - @JsonKey(includeIfNull: false) Iterable get iterable => _iterable; Iterable get dynamicIterable => _dynamicIterable; Iterable get objectIterable => _objectIterable; @@ -121,7 +118,6 @@ class KitchenSink implements k.KitchenSink { List dynamicList = _defaultList(); List objectList = _defaultList(); List intList = _defaultList(); - @JsonKey(includeIfNull: false) List dateTimeList = _defaultList(); Map map = _defaultMap(); @@ -129,12 +125,10 @@ class KitchenSink implements k.KitchenSink { Map dynamicIntMap = _defaultMap(); Map objectDateTimeMap = _defaultMap(); - @JsonKey(includeIfNull: false) List>>>> crazyComplex = _defaultList(); // Handle fields with names that collide with helper names - @JsonKey(includeIfNull: false) Map val = _defaultMap(); bool writeNotNull; @JsonKey(name: r'$string') diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable__use_wrappers.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable__use_wrappers.dart index 0009c587b..74459196d 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable__use_wrappers.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable__use_wrappers.dart @@ -96,13 +96,10 @@ class KitchenSink implements k.KitchenSink { Map toJson() => _$KitchenSinkToJson(this); - @JsonKey(includeIfNull: false) DateTime dateTime = DateTime(1981, 6, 5); - @JsonKey(includeIfNull: false) BigInt bigInt = BigInt.parse('10000000000000000000'); - @JsonKey(includeIfNull: false) Iterable get iterable => _iterable; Iterable get dynamicIterable => _dynamicIterable; Iterable get objectIterable => _objectIterable; @@ -122,7 +119,6 @@ class KitchenSink implements k.KitchenSink { List dynamicList = _defaultList(); List objectList = _defaultList(); List intList = _defaultList(); - @JsonKey(includeIfNull: false) List dateTimeList = _defaultList(); Map map = _defaultMap(); @@ -130,12 +126,10 @@ class KitchenSink implements k.KitchenSink { Map dynamicIntMap = _defaultMap(); Map objectDateTimeMap = _defaultMap(); - @JsonKey(includeIfNull: false) List>>>> crazyComplex = _defaultList(); // Handle fields with names that collide with helper names - @JsonKey(includeIfNull: false) Map val = _defaultMap(); bool writeNotNull; @JsonKey(name: r'$string') diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.dart index ccd2a6138..27cedf69b 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.dart @@ -96,13 +96,10 @@ class KitchenSink implements k.KitchenSink { Map toJson() => _$KitchenSinkToJson(this); - @JsonKey(includeIfNull: false) DateTime dateTime; - @JsonKey(includeIfNull: false) BigInt bigInt; - @JsonKey(includeIfNull: false) Iterable get iterable => _iterable; Iterable get dynamicIterable => _dynamicIterable; Iterable get objectIterable => _objectIterable; @@ -122,7 +119,6 @@ class KitchenSink implements k.KitchenSink { List dynamicList = _defaultList(); List objectList = _defaultList(); List intList = _defaultList(); - @JsonKey(includeIfNull: false) List dateTimeList = _defaultList(); Map map = _defaultMap(); @@ -130,12 +126,10 @@ class KitchenSink implements k.KitchenSink { Map dynamicIntMap = _defaultMap(); Map objectDateTimeMap = _defaultMap(); - @JsonKey(includeIfNull: false) List>>>> crazyComplex = _defaultList(); // Handle fields with names that collide with helper names - @JsonKey(includeIfNull: false) Map val = _defaultMap(); bool writeNotNull; @JsonKey(name: r'$string') diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__non_nullable.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__non_nullable.dart index 099403eb4..6753d04c5 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__non_nullable.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__non_nullable.dart @@ -97,13 +97,10 @@ class KitchenSink implements k.KitchenSink { Map toJson() => _$KitchenSinkToJson(this); - @JsonKey(includeIfNull: false) DateTime dateTime = DateTime(1981, 6, 5); - @JsonKey(includeIfNull: false) BigInt bigInt = BigInt.parse('10000000000000000000'); - @JsonKey(includeIfNull: false) Iterable get iterable => _iterable; Iterable get dynamicIterable => _dynamicIterable; Iterable get objectIterable => _objectIterable; @@ -123,7 +120,6 @@ class KitchenSink implements k.KitchenSink { List dynamicList = _defaultList(); List objectList = _defaultList(); List intList = _defaultList(); - @JsonKey(includeIfNull: false) List dateTimeList = _defaultList(); Map map = _defaultMap(); @@ -131,12 +127,10 @@ class KitchenSink implements k.KitchenSink { Map dynamicIntMap = _defaultMap(); Map objectDateTimeMap = _defaultMap(); - @JsonKey(includeIfNull: false) List>>>> crazyComplex = _defaultList(); // Handle fields with names that collide with helper names - @JsonKey(includeIfNull: false) Map val = _defaultMap(); bool writeNotNull; @JsonKey(name: r'$string') diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__use_wrappers.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__use_wrappers.dart similarity index 90% rename from json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__use_wrappers.dart rename to json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__use_wrappers.dart index 479c465d2..9430d2974 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__use_wrappers.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__use_wrappers.dart @@ -10,7 +10,7 @@ import 'kitchen_sink_interface.dart' as k; import 'simple_object.dart'; import 'strict_keys_object.dart'; -part 'kitchen_sink.g_any_map__use_wrappers.g.dart'; +part 'kitchen_sink.g_exclude_null__use_wrappers.g.dart'; // NOTE: these methods are replaced in the `non_nullable` cases to return // non-null values. @@ -22,14 +22,14 @@ StrictKeysObject _defaultStrictKeysObject() => null; const k.KitchenSinkFactory factory = _Factory(); -class _Factory implements k.KitchenSinkFactory { +class _Factory implements k.KitchenSinkFactory { const _Factory(); - String get description => 'any_map__use_wrappers'; - bool get anyMap => true; + String get description => 'exclude_null__use_wrappers'; + bool get anyMap => false; bool get checked => false; bool get nullable => true; - bool get excludeNull => false; + bool get excludeNull => true; bool get explicitToJson => false; k.KitchenSink ctor({ @@ -49,7 +49,8 @@ class _Factory implements k.KitchenSinkFactory { dateTimeIterable: dateTimeIterable, ); - k.KitchenSink fromJson(Map json) => KitchenSink.fromJson(json); + k.KitchenSink fromJson(Map json) => + KitchenSink.fromJson(json); k.JsonConverterTestClass jsonConverterCtor() => JsonConverterTestClass(); @@ -59,7 +60,7 @@ class _Factory implements k.KitchenSinkFactory { @JsonSerializable( useWrappers: true, - anyMap: true, + includeIfNull: false, ) class KitchenSink implements k.KitchenSink { // NOTE: exposing these as Iterable, but storing the values as List @@ -91,17 +92,15 @@ class KitchenSink implements k.KitchenSink { } } - factory KitchenSink.fromJson(Map json) => _$KitchenSinkFromJson(json); + factory KitchenSink.fromJson(Map json) => + _$KitchenSinkFromJson(json); Map toJson() => _$KitchenSinkToJson(this); - @JsonKey(includeIfNull: false) DateTime dateTime; - @JsonKey(includeIfNull: false) BigInt bigInt; - @JsonKey(includeIfNull: false) Iterable get iterable => _iterable; Iterable get dynamicIterable => _dynamicIterable; Iterable get objectIterable => _objectIterable; @@ -121,7 +120,6 @@ class KitchenSink implements k.KitchenSink { List dynamicList = _defaultList(); List objectList = _defaultList(); List intList = _defaultList(); - @JsonKey(includeIfNull: false) List dateTimeList = _defaultList(); Map map = _defaultMap(); @@ -129,12 +127,10 @@ class KitchenSink implements k.KitchenSink { Map dynamicIntMap = _defaultMap(); Map objectDateTimeMap = _defaultMap(); - @JsonKey(includeIfNull: false) List>>>> crazyComplex = _defaultList(); // Handle fields with names that collide with helper names - @JsonKey(includeIfNull: false) Map val = _defaultMap(); bool writeNotNull; @JsonKey(name: r'$string') @@ -159,7 +155,7 @@ class KitchenSink implements k.KitchenSink { @JsonSerializable( useWrappers: true, - anyMap: true, + includeIfNull: false, ) // referencing a top-level field should work @durationConverter @@ -189,7 +185,7 @@ class JsonConverterTestClass implements k.JsonConverterTestClass { @JsonSerializable( useWrappers: true, - anyMap: true, + includeIfNull: false, ) @GenericConverter() class JsonConverterGeneric { diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__use_wrappers.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__use_wrappers.g.dart similarity index 74% rename from json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__use_wrappers.g.dart rename to json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__use_wrappers.g.dart index 86c8d6728..20bd8c11a 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__use_wrappers.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__use_wrappers.g.dart @@ -1,12 +1,12 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -part of 'kitchen_sink.g_any_map__use_wrappers.dart'; +part of 'kitchen_sink.g_exclude_null__use_wrappers.dart'; // ************************************************************************** // JsonSerializableGenerator // ************************************************************************** -KitchenSink _$KitchenSinkFromJson(Map json) { +KitchenSink _$KitchenSinkFromJson(Map json) { return KitchenSink( ctorValidatedNo42: json['no-42'] as int, iterable: json['iterable'] as List, @@ -34,23 +34,24 @@ KitchenSink _$KitchenSinkFromJson(Map json) { ..dateTimeList = (json['dateTimeList'] as List) ?.map((e) => e == null ? null : DateTime.parse(e as String)) ?.toList() - ..map = json['map'] as Map - ..stringStringMap = (json['stringStringMap'] as Map)?.map( - (k, e) => MapEntry(k as String, e as String), + ..map = json['map'] as Map + ..stringStringMap = (json['stringStringMap'] as Map)?.map( + (k, e) => MapEntry(k, e as String), ) - ..dynamicIntMap = (json['dynamicIntMap'] as Map)?.map( + ..dynamicIntMap = (json['dynamicIntMap'] as Map)?.map( (k, e) => MapEntry(k, e as int), ) - ..objectDateTimeMap = (json['objectDateTimeMap'] as Map)?.map( + ..objectDateTimeMap = + (json['objectDateTimeMap'] as Map)?.map( (k, e) => MapEntry(k, e == null ? null : DateTime.parse(e as String)), ) ..crazyComplex = (json['crazyComplex'] as List) - ?.map((e) => (e as Map)?.map( + ?.map((e) => (e as Map)?.map( (k, e) => MapEntry( - k as String, - (e as Map)?.map( + k, + (e as Map)?.map( (k, e) => MapEntry( - k as String, + k, (e as List) ?.map((e) => (e as List) ?.map((e) => e == null @@ -61,17 +62,18 @@ KitchenSink _$KitchenSinkFromJson(Map json) { )), )) ?.toList() - ..val = (json['val'] as Map)?.map( - (k, e) => MapEntry(k as String, e as bool), + ..val = (json['val'] as Map)?.map( + (k, e) => MapEntry(k, e as bool), ) ..writeNotNull = json['writeNotNull'] as bool ..string = json[r'$string'] as String ..simpleObject = json['simpleObject'] == null ? null - : SimpleObject.fromJson(json['simpleObject'] as Map) + : SimpleObject.fromJson(json['simpleObject'] as Map) ..strictKeysObject = json['strictKeysObject'] == null ? null - : StrictKeysObject.fromJson(json['strictKeysObject'] as Map) + : StrictKeysObject.fromJson( + json['strictKeysObject'] as Map) ..validatedPropertyNo42 = json['validatedPropertyNo42'] as int; } @@ -84,7 +86,9 @@ class _$KitchenSinkJsonMapWrapper extends $JsonMapWrapper { @override Iterable get keys sync* { - yield 'no-42'; + if (_v.ctorValidatedNo42 != null) { + yield 'no-42'; + } if (_v.dateTime != null) { yield 'dateTime'; } @@ -94,37 +98,81 @@ class _$KitchenSinkJsonMapWrapper extends $JsonMapWrapper { if (_v.iterable != null) { yield 'iterable'; } - yield 'dynamicIterable'; - yield 'objectIterable'; - yield 'intIterable'; - yield 'set'; - yield 'dynamicSet'; - yield 'objectSet'; - yield 'intSet'; - yield 'dateTimeSet'; - yield 'datetime-iterable'; - yield 'list'; - yield 'dynamicList'; - yield 'objectList'; - yield 'intList'; + if (_v.dynamicIterable != null) { + yield 'dynamicIterable'; + } + if (_v.objectIterable != null) { + yield 'objectIterable'; + } + if (_v.intIterable != null) { + yield 'intIterable'; + } + if (_v.set != null) { + yield 'set'; + } + if (_v.dynamicSet != null) { + yield 'dynamicSet'; + } + if (_v.objectSet != null) { + yield 'objectSet'; + } + if (_v.intSet != null) { + yield 'intSet'; + } + if (_v.dateTimeSet != null) { + yield 'dateTimeSet'; + } + if (_v.dateTimeIterable != null) { + yield 'datetime-iterable'; + } + if (_v.list != null) { + yield 'list'; + } + if (_v.dynamicList != null) { + yield 'dynamicList'; + } + if (_v.objectList != null) { + yield 'objectList'; + } + if (_v.intList != null) { + yield 'intList'; + } if (_v.dateTimeList != null) { yield 'dateTimeList'; } - yield 'map'; - yield 'stringStringMap'; - yield 'dynamicIntMap'; - yield 'objectDateTimeMap'; + if (_v.map != null) { + yield 'map'; + } + if (_v.stringStringMap != null) { + yield 'stringStringMap'; + } + if (_v.dynamicIntMap != null) { + yield 'dynamicIntMap'; + } + if (_v.objectDateTimeMap != null) { + yield 'objectDateTimeMap'; + } if (_v.crazyComplex != null) { yield 'crazyComplex'; } if (_v.val != null) { yield 'val'; } - yield 'writeNotNull'; - yield r'$string'; - yield 'simpleObject'; - yield 'strictKeysObject'; - yield 'validatedPropertyNo42'; + if (_v.writeNotNull != null) { + yield 'writeNotNull'; + } + if (_v.string != null) { + yield r'$string'; + } + if (_v.simpleObject != null) { + yield 'simpleObject'; + } + if (_v.strictKeysObject != null) { + yield 'strictKeysObject'; + } + if (_v.validatedPropertyNo42 != null) { + yield 'validatedPropertyNo42'; + } } @override @@ -210,7 +258,8 @@ class _$KitchenSinkJsonMapWrapper extends $JsonMapWrapper { } } -JsonConverterTestClass _$JsonConverterTestClassFromJson(Map json) { +JsonConverterTestClass _$JsonConverterTestClassFromJson( + Map json) { return JsonConverterTestClass() ..duration = json['duration'] == null ? null @@ -221,9 +270,9 @@ JsonConverterTestClass _$JsonConverterTestClassFromJson(Map json) { ..bigInt = json['bigInt'] == null ? null : const BigIntStringConverter().fromJson(json['bigInt'] as String) - ..bigIntMap = (json['bigIntMap'] as Map)?.map( + ..bigIntMap = (json['bigIntMap'] as Map)?.map( (k, e) => MapEntry( - k as String, + k, e == null ? null : const BigIntStringConverter().fromJson(e as String)), @@ -250,15 +299,29 @@ class _$JsonConverterTestClassJsonMapWrapper extends $JsonMapWrapper { _$JsonConverterTestClassJsonMapWrapper(this._v); @override - Iterable get keys => const [ - 'duration', - 'durationList', - 'bigInt', - 'bigIntMap', - 'numberSilly', - 'numberSillySet', - 'dateTime' - ]; + Iterable get keys sync* { + if (_v.duration != null) { + yield 'duration'; + } + if (_v.durationList != null) { + yield 'durationList'; + } + if (_v.bigInt != null) { + yield 'bigInt'; + } + if (_v.bigIntMap != null) { + yield 'bigIntMap'; + } + if (_v.numberSilly != null) { + yield 'numberSilly'; + } + if (_v.numberSillySet != null) { + yield 'numberSillySet'; + } + if (_v.dateTime != null) { + yield 'dateTime'; + } + } @override dynamic operator [](Object key) { @@ -300,7 +363,7 @@ class _$JsonConverterTestClassJsonMapWrapper extends $JsonMapWrapper { } JsonConverterGeneric _$JsonConverterGenericFromJson( - Map json) { + Map json) { return JsonConverterGeneric() ..item = json['item'] == null ? null @@ -310,9 +373,9 @@ JsonConverterGeneric _$JsonConverterGenericFromJson( ? null : GenericConverter().fromJson(e as Map)) ?.toList() - ..itemMap = (json['itemMap'] as Map)?.map( + ..itemMap = (json['itemMap'] as Map)?.map( (k, e) => MapEntry( - k as String, + k, e == null ? null : GenericConverter().fromJson(e as Map)), @@ -328,7 +391,17 @@ class _$JsonConverterGenericJsonMapWrapper extends $JsonMapWrapper { _$JsonConverterGenericJsonMapWrapper(this._v); @override - Iterable get keys => const ['item', 'itemList', 'itemMap']; + Iterable get keys sync* { + if (_v.item != null) { + yield 'item'; + } + if (_v.itemList != null) { + yield 'itemList'; + } + if (_v.itemMap != null) { + yield 'itemMap'; + } + } @override dynamic operator [](Object key) { diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.dart index 101479bae..5a4fbeb20 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.dart @@ -96,13 +96,10 @@ class KitchenSink implements k.KitchenSink { Map toJson() => _$KitchenSinkToJson(this); - @JsonKey(includeIfNull: false) DateTime dateTime; - @JsonKey(includeIfNull: false) BigInt bigInt; - @JsonKey(includeIfNull: false) Iterable get iterable => _iterable; Iterable get dynamicIterable => _dynamicIterable; Iterable get objectIterable => _objectIterable; @@ -122,7 +119,6 @@ class KitchenSink implements k.KitchenSink { List dynamicList = _defaultList(); List objectList = _defaultList(); List intList = _defaultList(); - @JsonKey(includeIfNull: false) List dateTimeList = _defaultList(); Map map = _defaultMap(); @@ -130,12 +126,10 @@ class KitchenSink implements k.KitchenSink { Map dynamicIntMap = _defaultMap(); Map objectDateTimeMap = _defaultMap(); - @JsonKey(includeIfNull: false) List>>>> crazyComplex = _defaultList(); // Handle fields with names that collide with helper names - @JsonKey(includeIfNull: false) Map val = _defaultMap(); bool writeNotNull; @JsonKey(name: r'$string') diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart index 981600c51..bf40058d7 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart @@ -77,45 +77,35 @@ KitchenSink _$KitchenSinkFromJson(Map json) { ..validatedPropertyNo42 = json['validatedPropertyNo42'] as int; } -Map _$KitchenSinkToJson(KitchenSink instance) { - final val = { - 'no-42': instance.ctorValidatedNo42, - }; - - void writeNotNull(String key, dynamic value) { - if (value != null) { - val[key] = value; - } - } - - writeNotNull('dateTime', instance.dateTime?.toIso8601String()); - writeNotNull('bigInt', instance.bigInt?.toString()); - writeNotNull('iterable', instance.iterable?.toList()); - val['dynamicIterable'] = instance.dynamicIterable?.toList(); - val['objectIterable'] = instance.objectIterable?.toList(); - val['intIterable'] = instance.intIterable?.toList(); - val['set'] = instance.set?.toList(); - val['dynamicSet'] = instance.dynamicSet?.toList(); - val['objectSet'] = instance.objectSet?.toList(); - val['intSet'] = instance.intSet?.toList(); - val['dateTimeSet'] = - instance.dateTimeSet?.map((e) => e?.toIso8601String())?.toList(); - val['datetime-iterable'] = - instance.dateTimeIterable?.map((e) => e?.toIso8601String())?.toList(); - val['list'] = instance.list; - val['dynamicList'] = instance.dynamicList; - val['objectList'] = instance.objectList; - val['intList'] = instance.intList; - writeNotNull('dateTimeList', - instance.dateTimeList?.map((e) => e?.toIso8601String())?.toList()); - val['map'] = instance.map; - val['stringStringMap'] = instance.stringStringMap; - val['dynamicIntMap'] = instance.dynamicIntMap; - val['objectDateTimeMap'] = instance.objectDateTimeMap - ?.map((k, e) => MapEntry(k, e?.toIso8601String())); - writeNotNull( - 'crazyComplex', - instance.crazyComplex +Map _$KitchenSinkToJson(KitchenSink instance) => + { + 'no-42': instance.ctorValidatedNo42, + 'dateTime': instance.dateTime?.toIso8601String(), + 'bigInt': instance.bigInt?.toString(), + 'iterable': instance.iterable?.toList(), + 'dynamicIterable': instance.dynamicIterable?.toList(), + 'objectIterable': instance.objectIterable?.toList(), + 'intIterable': instance.intIterable?.toList(), + 'set': instance.set?.toList(), + 'dynamicSet': instance.dynamicSet?.toList(), + 'objectSet': instance.objectSet?.toList(), + 'intSet': instance.intSet?.toList(), + 'dateTimeSet': + instance.dateTimeSet?.map((e) => e?.toIso8601String())?.toList(), + 'datetime-iterable': + instance.dateTimeIterable?.map((e) => e?.toIso8601String())?.toList(), + 'list': instance.list, + 'dynamicList': instance.dynamicList, + 'objectList': instance.objectList, + 'intList': instance.intList, + 'dateTimeList': + instance.dateTimeList?.map((e) => e?.toIso8601String())?.toList(), + 'map': instance.map, + 'stringStringMap': instance.stringStringMap, + 'dynamicIntMap': instance.dynamicIntMap, + 'objectDateTimeMap': instance.objectDateTimeMap + ?.map((k, e) => MapEntry(k, e?.toIso8601String())), + 'crazyComplex': instance.crazyComplex ?.map((e) => e?.map((k, e) => MapEntry( k, e?.map((k, e) => MapEntry( @@ -124,15 +114,14 @@ Map _$KitchenSinkToJson(KitchenSink instance) { ?.map( (e) => e?.map((e) => e?.toIso8601String())?.toList()) ?.toList()))))) - ?.toList()); - writeNotNull('val', instance.val); - val['writeNotNull'] = instance.writeNotNull; - val[r'$string'] = instance.string; - val['simpleObject'] = instance.simpleObject?.toJson(); - val['strictKeysObject'] = instance.strictKeysObject?.toJson(); - val['validatedPropertyNo42'] = instance.validatedPropertyNo42; - return val; -} + ?.toList(), + 'val': instance.val, + 'writeNotNull': instance.writeNotNull, + r'$string': instance.string, + 'simpleObject': instance.simpleObject?.toJson(), + 'strictKeysObject': instance.strictKeysObject?.toJson(), + 'validatedPropertyNo42': instance.validatedPropertyNo42 + }; JsonConverterTestClass _$JsonConverterTestClassFromJson( Map json) { diff --git a/json_serializable/test/kitchen_sink/kitchen_sink_test.dart b/json_serializable/test/kitchen_sink/kitchen_sink_test.dart index c2ef97548..490987a9c 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink_test.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink_test.dart @@ -121,12 +121,9 @@ void _nullableTests(KitchenSinkFactory factory) { if (factory.excludeNull) { expect(encoded, isEmpty); } else { - final expectedDefaultKeys = _validValues.keys.toSet() - ..removeAll(_excludeIfNullKeys); + expect(encoded.keys, orderedEquals(_validValues.keys)); - expect(encoded.keys, orderedEquals(expectedDefaultKeys)); - - for (final key in expectedDefaultKeys) { + for (final key in _validValues.keys) { expect(encoded, containsPair(key, isNull)); } } @@ -219,29 +216,9 @@ void _sharedTests(KitchenSinkFactory factory) { }); test('JSON keys should be defined in field/property order', () { - /// Explicitly setting values from [_excludeIfNullKeys] to ensure - /// they exist for KitchenSink where they are excluded when null - final item = factory.ctor(iterable: []) - ..dateTime = DateTime.now() - ..bigInt = BigInt.from(42) - ..dateTimeList = [] - ..crazyComplex = [] - ..val = {}; - - final json = item.toJson(); - + final json = factory.ctor().toJson(); if (factory.excludeNull && factory.nullable) { - expect( - json.keys, - orderedEquals([ - 'dateTime', - 'bigInt', - 'iterable', - 'dateTimeList', - 'crazyComplex', - 'val' - ]), - ); + expect(json.keys, isEmpty); } else { expect(json.keys, orderedEquals(_validValues.keys)); } @@ -412,15 +389,6 @@ const _invalidCheckedValues = { 'datetime-iterable': [true], }; -const _excludeIfNullKeys = [ - 'bigInt', - 'dateTime', - 'iterable', - 'dateTimeList', - 'crazyComplex', - _generatedLocalVarName -]; - const _encodedAsMapKeys = ['simpleObject', 'strictKeysObject']; const _iterableMapKeys = [ diff --git a/json_serializable/tool/builder.dart b/json_serializable/tool/builder.dart index c9a06c120..0ce3e2adc 100644 --- a/json_serializable/tool/builder.dart +++ b/json_serializable/tool/builder.dart @@ -225,9 +225,9 @@ const _fileConfigurationMap = >>{ ['any_map', 'checked', 'non_nullable'], ['any_map', 'non_nullable', 'use_wrappers'], ['any_map', 'non_nullable'], - ['any_map', 'use_wrappers'], ['any_map'], ['exclude_null', 'non_nullable'], + ['exclude_null', 'use_wrappers'], ['exclude_null'], ['explicit_to_json'], ], From 70a6a9b28bad4814ca4b3aef57b43233326fd33d Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Fri, 15 Mar 2019 21:06:29 -0700 Subject: [PATCH 081/569] kitchen_sink_test: track Map/Iterable valid values correctly --- .../test/kitchen_sink/kitchen_sink_test.dart | 30 +++++++------------ 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/json_serializable/test/kitchen_sink/kitchen_sink_test.dart b/json_serializable/test/kitchen_sink/kitchen_sink_test.dart index 490987a9c..61e5562ae 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink_test.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink_test.dart @@ -30,6 +30,17 @@ void main() { expect(_invalidValueTypes.keys, orderedEquals(_validValues.keys)); }); + test('tracking Map/Iterable types correctly', () { + for (var entry in _validValues.entries) { + if (_iterableMapKeys.contains(entry.key) || + _encodedAsMapKeys.contains(entry.key)) { + expect(entry.value, anyOf(isMap, isList)); + } else { + expect(entry.value, isNot(anyOf(isMap, isList))); + } + } + }); + test('required keys', () { expect( () => StrictKeysObject.fromJson({}), @@ -226,25 +237,6 @@ void _sharedTests(KitchenSinkFactory factory) { test('valid values round-trip - json', () { final validInstance = factory.fromJson(_validValues); - - bool containsKey(String key) { - return _iterableMapKeys.contains(key) || - (factory.explicitToJson && _encodedAsMapKeys.contains(key)); - } - - for (var entry in validInstance.toJson().entries) { - expect(entry.value, isNotNull, - reason: 'key "${entry.key}" should not be null'); - - if (containsKey(entry.key)) { - expect(entry.value, anyOf(isMap, isList), - reason: 'key "${entry.key}" should be a Map/List'); - } else { - expect(entry.value, isNot(anyOf(isMap, isList)), - reason: 'key "${entry.key}" should not be a Map/List'); - } - } - expect(loudEncode(_validValues), loudEncode(validInstance)); }); } From 9fcee71528f17f8e9e80e90003264e84d048977b Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Fri, 22 Mar 2019 15:23:01 -0700 Subject: [PATCH 082/569] Add encodeEmptyCollection config to classes and fields (#420) Fixes https://github.com/dart-lang/json_serializable/issues/6 json_annotation: update JsonKey and JsonSerializable annotation classes json_serializable: update corresponding logic for processing annotations and build config Added tracking for the "root" of a TypeHelper call Added a number of corresponding tests --- json_annotation/CHANGELOG.md | 4 + json_annotation/lib/src/json_key.dart | 30 +- .../lib/src/json_serializable.dart | 23 + .../lib/src/json_serializable.g.dart | 30 +- json_annotation/pubspec.yaml | 7 +- json_serializable/CHANGELOG.md | 2 + json_serializable/README.md | 1 + json_serializable/build.yaml | 5 + json_serializable/lib/src/encoder_helper.dart | 26 +- json_serializable/lib/src/json_key_utils.dart | 66 ++- json_serializable/lib/src/type_helper.dart | 21 + .../lib/src/type_helper_ctx.dart | 23 +- .../lib/src/type_helpers/iterable_helper.dart | 17 +- .../lib/src/type_helpers/map_helper.dart | 16 +- json_serializable/lib/src/utils.dart | 11 +- json_serializable/pubspec.yaml | 4 + json_serializable/test/config_test.dart | 23 +- .../test/json_serializable_test.dart | 4 + .../test/kitchen_sink/kitchen_sink.dart | 1 + .../kitchen_sink/kitchen_sink.factories.dart | 14 + .../kitchen_sink/kitchen_sink.g_any_map.dart | 1 + ...sink.g_any_map__checked__non_nullable.dart | 1 + .../kitchen_sink.g_any_map__non_nullable.dart | 1 + ...g_any_map__non_nullable__use_wrappers.dart | 1 + .../kitchen_sink.g_exclude_null.dart | 1 + ..._sink.g_exclude_null__no_encode_empty.dart | 203 ++++++++ ...ink.g_exclude_null__no_encode_empty.g.dart | 283 ++++++++++++ ...ode_empty__non_nullable__use_wrappers.dart | 210 +++++++++ ...e_empty__non_nullable__use_wrappers.g.dart | 364 +++++++++++++++ ...e_null__no_encode_empty__use_wrappers.dart | 206 +++++++++ ...null__no_encode_empty__use_wrappers.g.dart | 433 ++++++++++++++++++ ...hen_sink.g_exclude_null__non_nullable.dart | 1 + ...hen_sink.g_exclude_null__use_wrappers.dart | 1 + .../kitchen_sink.g_explicit_to_json.dart | 1 + .../kitchen_sink.g_no_encode_empty.dart | 200 ++++++++ .../kitchen_sink.g_no_encode_empty.g.dart | 276 +++++++++++ ..._sink.g_no_encode_empty__non_nullable.dart | 203 ++++++++ ...ink.g_no_encode_empty__non_nullable.g.dart | 234 ++++++++++ .../kitchen_sink/kitchen_sink_interface.dart | 1 + .../test/kitchen_sink/kitchen_sink_test.dart | 161 ++++--- json_serializable/test/shared_config.dart | 1 + .../src/_json_serializable_test_input.dart | 97 ++++ .../test/test_sources/test_sources.dart | 1 + json_serializable/test/test_utils.dart | 10 +- json_serializable/tool/builder.dart | 13 + 45 files changed, 3112 insertions(+), 120 deletions(-) create mode 100644 json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty.dart create mode 100644 json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty.g.dart create mode 100644 json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty__non_nullable__use_wrappers.dart create mode 100644 json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty__non_nullable__use_wrappers.g.dart create mode 100644 json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty__use_wrappers.dart create mode 100644 json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty__use_wrappers.g.dart create mode 100644 json_serializable/test/kitchen_sink/kitchen_sink.g_no_encode_empty.dart create mode 100644 json_serializable/test/kitchen_sink/kitchen_sink.g_no_encode_empty.g.dart create mode 100644 json_serializable/test/kitchen_sink/kitchen_sink.g_no_encode_empty__non_nullable.dart create mode 100644 json_serializable/test/kitchen_sink/kitchen_sink.g_no_encode_empty__non_nullable.g.dart diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index 5436759ce..840e3f5fe 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.1.0 + +* Added to `encodeEmptyCollection` to `JsonKey` and `JsonSerializable`. + ## 2.0.0 * **Potentially Breaking** `JsonSerializable` no longer sets default values for diff --git a/json_annotation/lib/src/json_key.dart b/json_annotation/lib/src/json_key.dart index 9e76bb6da..d38083d4a 100644 --- a/json_annotation/lib/src/json_key.dart +++ b/json_annotation/lib/src/json_key.dart @@ -98,18 +98,36 @@ class JsonKey { /// same field, an exception will be thrown during code generation. final bool disallowNullValue; + /// Whether the generator should include the annotated field value in the + /// serialized output if it is empty. + /// + /// If `true` (the default), empty values are included in the generated + /// `toJson` function. + /// + /// If `false`, fields with empty collections are omitted from `toJson`. + /// + /// Note: setting this property to `false` overrides the [includeIfNull] + /// value to `false` as well. Explicitly setting [includeIfNull] to `true` + /// and setting this property to `false` will cause an error at build time. + /// + /// Note: setting this property to `false` on a non-collection field + /// (of types other than [Iterable], [Set], [List], and [Map]) + /// will cause an error at build time. + final bool encodeEmptyCollection; + /// Creates a new [JsonKey] instance. /// /// Only required when the default behavior is not desired. const JsonKey({ + this.defaultValue, + this.disallowNullValue, + this.encodeEmptyCollection, + this.fromJson, + this.ignore, + this.includeIfNull, this.name, this.nullable, - this.includeIfNull, - this.ignore, - this.fromJson, - this.toJson, - this.defaultValue, this.required, - this.disallowNullValue, + this.toJson, }); } diff --git a/json_annotation/lib/src/json_serializable.dart b/json_annotation/lib/src/json_serializable.dart index 58d24a050..917c92cc5 100644 --- a/json_annotation/lib/src/json_serializable.dart +++ b/json_annotation/lib/src/json_serializable.dart @@ -21,6 +21,10 @@ enum FieldRename { } /// An annotation used to specify a class to generate code for. +@JsonSerializable( + fieldRename: FieldRename.snake, + disallowUnrecognizedKeys: true, +) class JsonSerializable { /// If `true`, [Map] types are *not* assumed to be [Map] /// – which is the default type of [Map] instances return by JSON decode in @@ -87,6 +91,21 @@ class JsonSerializable { /// If `true`, any unrecognized keys will be treated as an error. final bool disallowUnrecognizedKeys; + /// Whether the generator should include empty collection field values in the + /// serialized output. + /// + /// If `true` (the default), empty collection fields + /// (of type [Iterable], [Set], [List], and [Map]) + /// are included in generated `toJson` functions. + /// + /// If `false`, fields with empty collections are omitted from `toJson`. + /// + /// Note: setting this property to `false` overrides the [includeIfNull] + /// value to `false` as well. + /// + /// This value has no effect on non-collection fields. + final bool encodeEmptyCollection; + /// If `true`, generated `toJson` methods will explicitly call `toJson` on /// nested objects. /// @@ -180,6 +199,7 @@ class JsonSerializable { this.createFactory, this.createToJson, this.disallowUnrecognizedKeys, + this.encodeEmptyCollection, this.explicitToJson, this.fieldRename, this.generateToJsonFunction, @@ -199,6 +219,7 @@ class JsonSerializable { createFactory: true, createToJson: true, disallowUnrecognizedKeys: false, + encodeEmptyCollection: true, explicitToJson: false, fieldRename: FieldRename.none, generateToJsonFunction: true, @@ -219,6 +240,8 @@ class JsonSerializable { createToJson: createToJson ?? defaults.createToJson, disallowUnrecognizedKeys: disallowUnrecognizedKeys ?? defaults.disallowUnrecognizedKeys, + encodeEmptyCollection: + encodeEmptyCollection ?? defaults.encodeEmptyCollection, explicitToJson: explicitToJson ?? defaults.explicitToJson, fieldRename: fieldRename ?? defaults.fieldRename, generateToJsonFunction: diff --git a/json_annotation/lib/src/json_serializable.g.dart b/json_annotation/lib/src/json_serializable.g.dart index ab9320693..28cfae160 100644 --- a/json_annotation/lib/src/json_serializable.g.dart +++ b/json_annotation/lib/src/json_serializable.g.dart @@ -13,27 +13,28 @@ JsonSerializable _$JsonSerializableFromJson(Map json) { 'create_factory', 'create_to_json', 'disallow_unrecognized_keys', + 'encode_empty_collection', 'explicit_to_json', 'field_rename', 'generate_to_json_function', 'include_if_null', 'nullable', - 'use_wrappers', + 'use_wrappers' ]); return JsonSerializable( - anyMap: json['any_map'] as bool, - checked: json['checked'] as bool, - createFactory: json['create_factory'] as bool, - createToJson: json['create_to_json'] as bool, - disallowUnrecognizedKeys: json['disallow_unrecognized_keys'] as bool, - explicitToJson: json['explicit_to_json'] as bool, - fieldRename: - _$enumDecodeNullable(_$FieldRenameEnumMap, json['field_rename']), - generateToJsonFunction: json['generate_to_json_function'] as bool, - includeIfNull: json['include_if_null'] as bool, - nullable: json['nullable'] as bool, - useWrappers: json['use_wrappers'] as bool, - ); + anyMap: json['any_map'] as bool, + checked: json['checked'] as bool, + createFactory: json['create_factory'] as bool, + createToJson: json['create_to_json'] as bool, + disallowUnrecognizedKeys: json['disallow_unrecognized_keys'] as bool, + encodeEmptyCollection: json['encode_empty_collection'] as bool, + explicitToJson: json['explicit_to_json'] as bool, + fieldRename: + _$enumDecodeNullable(_$FieldRenameEnumMap, json['field_rename']), + generateToJsonFunction: json['generate_to_json_function'] as bool, + includeIfNull: json['include_if_null'] as bool, + nullable: json['nullable'] as bool, + useWrappers: json['use_wrappers'] as bool); } Map _$JsonSerializableToJson(JsonSerializable instance) => @@ -43,6 +44,7 @@ Map _$JsonSerializableToJson(JsonSerializable instance) => 'create_factory': instance.createFactory, 'create_to_json': instance.createToJson, 'disallow_unrecognized_keys': instance.disallowUnrecognizedKeys, + 'encode_empty_collection': instance.encodeEmptyCollection, 'explicit_to_json': instance.explicitToJson, 'field_rename': _$FieldRenameEnumMap[instance.fieldRename], 'generate_to_json_function': instance.generateToJsonFunction, diff --git a/json_annotation/pubspec.yaml b/json_annotation/pubspec.yaml index 8938c9c1b..ec43a6e84 100644 --- a/json_annotation/pubspec.yaml +++ b/json_annotation/pubspec.yaml @@ -1,5 +1,5 @@ name: json_annotation -version: 2.0.0 +version: 2.1.0-dev description: >- Classes and helper functions that support JSON code generation via the `json_serializable` package. @@ -7,3 +7,8 @@ homepage: https://github.com/dart-lang/json_serializable author: Dart Team environment: sdk: '>=2.0.0 <3.0.0' + +# When changing JsonSerializable class. +# dev_dependencies: +# build_runner: ^1.0.0 +# json_serializable: ^2.0.0 diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 7f2b77eed..e9ce9aaf8 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,5 +1,7 @@ ## 2.1.0 +* Added support for `encodeEmptyCollection` on `JsonKey` and `JsonSerializable`. + * Added support for `BigInt`. * Added `BigIntTypeHelper` to `type_helper.dart` library. diff --git a/json_serializable/README.md b/json_serializable/README.md index cf86aea9c..15e6b6cec 100644 --- a/json_serializable/README.md +++ b/json_serializable/README.md @@ -79,6 +79,7 @@ targets: create_factory: true create_to_json: true disallow_unrecognized_keys: false + encode_empty_collection: true explicit_to_json: false field_rename: none generate_to_json_function: true diff --git a/json_serializable/build.yaml b/json_serializable/build.yaml index 4ba0b2ee3..866a8c7f7 100644 --- a/json_serializable/build.yaml +++ b/json_serializable/build.yaml @@ -42,9 +42,14 @@ builders: - .g_any_map__non_nullable.dart - .g_any_map__non_nullable__use_wrappers.dart - .g_exclude_null.dart + - .g_exclude_null__no_encode_empty.dart + - .g_exclude_null__no_encode_empty__non_nullable__use_wrappers.dart + - .g_exclude_null__no_encode_empty__use_wrappers.dart - .g_exclude_null__non_nullable.dart - .g_exclude_null__use_wrappers.dart - .g_explicit_to_json.dart + - .g_no_encode_empty.dart + - .g_no_encode_empty__non_nullable.dart - .g_non_nullable.dart - .g_non_nullable__use_wrappers.dart - .g_use_wrappers.dart diff --git a/json_serializable/lib/src/encoder_helper.dart b/json_serializable/lib/src/encoder_helper.dart index a0f046373..bd4bd591b 100644 --- a/json_serializable/lib/src/encoder_helper.dart +++ b/json_serializable/lib/src/encoder_helper.dart @@ -107,12 +107,25 @@ class ${_wrapperClassName(true)} extends \$JsonMapWrapper { buffer.writeln(' @override\n Iterable get keys sync* {'); for (final field in fields) { - final nullCheck = !_writeJsonValueNaive(field); - if (nullCheck) { - buffer.write(' if (_v.${field.name} != null) {\n '); + String check; + + if (!_writeJsonValueNaive(field)) { + check = '_v.${field.name} != null'; + + if (!jsonKeyFor(field).encodeEmptyCollection) { + assert(!jsonKeyFor(field).includeIfNull); + if (jsonKeyFor(field).nullable) { + check = '_v.${field.name}?.isNotEmpty ?? false'; + } else { + check = '_v.${field.name}.isNotEmpty'; + } + } + } + if (check != null) { + buffer.writeln(' if ($check) {\n '); } buffer.writeln(' yield ${safeNameAccess(field)};'); - if (nullCheck) { + if (check != null) { buffer.writeln(' }'); } } @@ -239,7 +252,8 @@ class ${_wrapperClassName(true)} extends \$JsonMapWrapper { /// `true` if either: /// `includeIfNull` is `true` /// or - /// `nullable` is `false`. + /// `nullable` is `false` and `encodeEmptyCollection` is true bool _writeJsonValueNaive(FieldElement field) => - jsonKeyFor(field).includeIfNull || !jsonKeyFor(field).nullable; + jsonKeyFor(field).includeIfNull || + (!jsonKeyFor(field).nullable && jsonKeyFor(field).encodeEmptyCollection); } diff --git a/json_serializable/lib/src/json_key_utils.dart b/json_serializable/lib/src/json_key_utils.dart index 468c306a1..097ea1fe2 100644 --- a/json_serializable/lib/src/json_key_utils.dart +++ b/json_serializable/lib/src/json_key_utils.dart @@ -9,6 +9,7 @@ import 'package:json_annotation/json_annotation.dart'; import 'package:source_gen/source_gen.dart'; import 'json_literal_generator.dart'; +import 'shared_checkers.dart'; import 'utils.dart'; final _jsonKeyExpando = Expando(); @@ -94,34 +95,26 @@ JsonKey _from(FieldElement element, JsonSerializable classAnnotation) { } } - final disallowNullValue = obj.getField('disallowNullValue').toBoolValue(); - final includeIfNull = obj.getField('includeIfNull').toBoolValue(); - - if (disallowNullValue == true) { - if (includeIfNull == true) { - throwUnsupported( - element, - 'Cannot set both `disallowNullvalue` and `includeIfNull` to `true`. ' - 'This leads to incompatible `toJson` and `fromJson` behavior.'); - } - } - return _populateJsonKey( classAnnotation, element, defaultValue: defaultValueLiteral, - disallowNullValue: disallowNullValue, + disallowNullValue: obj.getField('disallowNullValue').toBoolValue(), + encodeEmptyCollection: obj.getField('encodeEmptyCollection').toBoolValue(), ignore: obj.getField('ignore').toBoolValue(), - includeIfNull: includeIfNull, + includeIfNull: obj.getField('includeIfNull').toBoolValue(), name: obj.getField('name').toStringValue(), nullable: obj.getField('nullable').toBoolValue(), required: obj.getField('required').toBoolValue(), ); } +const _iterableOrMapChecker = + TypeChecker.any([coreIterableTypeChecker, coreMapTypeChecker]); + JsonKey _populateJsonKey( JsonSerializable classAnnotation, - FieldElement fieldElement, { + FieldElement element, { Object defaultValue, bool disallowNullValue, bool ignore, @@ -129,16 +122,57 @@ JsonKey _populateJsonKey( String name, bool nullable, bool required, + bool encodeEmptyCollection, }) { + if (disallowNullValue == true) { + if (includeIfNull == true) { + throwUnsupported( + element, + 'Cannot set both `disallowNullvalue` and `includeIfNull` to `true`. ' + 'This leads to incompatible `toJson` and `fromJson` behavior.'); + } + } + + if (encodeEmptyCollection == null) { + // If set on the class, but not set on the field – set the key to false + // iif the type is compatible. + if (_iterableOrMapChecker.isAssignableFromType(element.type) && + !classAnnotation.encodeEmptyCollection) { + encodeEmptyCollection = false; + } else { + encodeEmptyCollection = true; + } + } else if (encodeEmptyCollection == false && + !_iterableOrMapChecker.isAssignableFromType(element.type)) { + // If explicitly set of the field, throw an error if the type is not a + // compatible type. + throwUnsupported( + element, + '`encodeEmptyCollection: false` is only valid fields of type ' + 'Iterable, List, Set, or Map.', + ); + } + + if (!encodeEmptyCollection) { + if (includeIfNull == true) { + throwUnsupported( + element, + 'Cannot set `encodeEmptyCollection: false` if `includeIfNull: true`.', + ); + } + includeIfNull = false; + } + final jsonKey = JsonKey( defaultValue: defaultValue, disallowNullValue: disallowNullValue ?? false, ignore: ignore ?? false, includeIfNull: _includeIfNull( includeIfNull, disallowNullValue, classAnnotation.includeIfNull), - name: _encodedFieldName(classAnnotation, name, fieldElement), + name: _encodedFieldName(classAnnotation, name, element), nullable: nullable ?? classAnnotation.nullable, required: required ?? false, + encodeEmptyCollection: encodeEmptyCollection, ); return jsonKey; diff --git a/json_serializable/lib/src/type_helper.dart b/json_serializable/lib/src/type_helper.dart index d38c1b2e3..e83d054de 100644 --- a/json_serializable/lib/src/type_helper.dart +++ b/json_serializable/lib/src/type_helper.dart @@ -30,6 +30,17 @@ abstract class TypeHelperContext { void addMember(String memberContent); } +abstract class TypeHelperContextWithEmptyCollectionLogic + extends TypeHelperContext { + /// Returns `true` if `this` is being used in the first (or "root") invocation + /// of a [TypeHelper.serialize] or [TypeHelper.deserialize] call. + bool get skipEncodingEmptyCollection; + + static bool isSkipEncodingEmptyCollection(TypeHelperContext context) => + context is TypeHelperContextWithEmptyCollectionLogic && + context.skipEncodingEmptyCollection; +} + /// Extended context information with includes configuration values /// corresponding to `JsonSerializableGenerator` settings. abstract class TypeHelperContextWithConfig extends TypeHelperContext { @@ -110,3 +121,13 @@ Object commonNullPrefix( nullable ? '$expression == null ? null : $unsafeExpression' : unsafeExpression; + +/// Returns `true` if [context] represents a field where +/// `encodeEmptyCollection` is `false` and the caller is running on the +/// "root" value and not for a nested type. +/// +/// This ensures we don't add wrapper functions for the nested lists within +/// `Map`, for instance. +bool encodeEmptyAsNullRoot(TypeHelperContext context) => + TypeHelperContextWithEmptyCollectionLogic.isSkipEncodingEmptyCollection( + context); diff --git a/json_serializable/lib/src/type_helper_ctx.dart b/json_serializable/lib/src/type_helper_ctx.dart index 6b21fec14..d8fd6b1db 100644 --- a/json_serializable/lib/src/type_helper_ctx.dart +++ b/json_serializable/lib/src/type_helper_ctx.dart @@ -17,7 +17,10 @@ TypeHelperCtx typeHelperContext( TypeHelperCtx._(helperCore, fieldElement, key); class TypeHelperCtx - implements TypeHelperContextWithConfig, TypeHelperContextWithConvert { + implements + TypeHelperContextWithConfig, + TypeHelperContextWithConvert, + TypeHelperContextWithEmptyCollectionLogic { final HelperCore _helperCore; final JsonKey _key; @@ -61,10 +64,23 @@ class TypeHelperCtx (TypeHelper th) => th.deserialize(targetType, expression, this)); Object _run(DartType targetType, String expression, - Object invoke(TypeHelper instance)) => - _helperCore.allTypeHelpers.map(invoke).firstWhere((r) => r != null, + Object invoke(TypeHelper instance)) { + _depth++; + + try { + return _helperCore.allTypeHelpers.map(invoke).firstWhere((r) => r != null, orElse: () => throw UnsupportedTypeError( targetType, expression, _notSupportedWithTypeHelpersMsg)); + } finally { + _depth--; + } + } + + int _depth = 0; + + @override + bool get skipEncodingEmptyCollection => + !_key.encodeEmptyCollection && _depth == 1; } final _notSupportedWithTypeHelpersMsg = @@ -72,6 +88,7 @@ final _notSupportedWithTypeHelpersMsg = class _ConvertPair { static final _expando = Expando<_ConvertPair>(); + static _ConvertPair fromJsonKey(JsonKey key) => _expando[key]; final ConvertData fromJson, toJson; diff --git a/json_serializable/lib/src/type_helpers/iterable_helper.dart b/json_serializable/lib/src/type_helpers/iterable_helper.dart index 42d078d4f..da2d5b9ce 100644 --- a/json_serializable/lib/src/type_helpers/iterable_helper.dart +++ b/json_serializable/lib/src/type_helpers/iterable_helper.dart @@ -9,6 +9,12 @@ import '../constants.dart'; import '../shared_checkers.dart'; import '../type_helper.dart'; +const _helperFunctionDefinition = + '''T $_helperName(T source) => + (source == null || source.isEmpty) ? null : source;'''; + +const _helperName = r'_$nullIfEmptyIterable'; + class IterableHelper extends TypeHelper { const IterableHelper(); @@ -27,7 +33,14 @@ class IterableHelper extends TypeHelper { var isList = _coreListChecker.isAssignableFromType(targetType); final subField = context.serialize(itemType, closureArg); - final optionalQuestion = context.nullable ? '?' : ''; + final contextNullable = context.nullable || encodeEmptyAsNullRoot(context); + + final optionalQuestion = contextNullable ? '?' : ''; + + if (encodeEmptyAsNullRoot(context)) { + context.addMember(_helperFunctionDefinition); + expression = '$_helperName($expression)'; + } // In the case of trivial JSON types (int, String, etc), `subField` // will be identical to `substitute` – so no explicit mapping is needed. @@ -36,7 +49,7 @@ class IterableHelper extends TypeHelper { final lambda = LambdaResult.process(subField, closureArg); if (context.config.useWrappers && isList) { var method = '\$wrapList'; - if (context.nullable) { + if (contextNullable) { method = '${method}HandleNull'; } diff --git a/json_serializable/lib/src/type_helpers/map_helper.dart b/json_serializable/lib/src/type_helpers/map_helper.dart index b2ac2e69c..44a889c7a 100644 --- a/json_serializable/lib/src/type_helpers/map_helper.dart +++ b/json_serializable/lib/src/type_helpers/map_helper.dart @@ -11,6 +11,11 @@ import '../utils.dart'; const _keyParam = 'k'; +const _helperFunctionDefinition = '''T $_helperName(T source) => + (source == null || source.isEmpty) ? null : source;'''; + +const _helperName = r'_$nullIfEmptyMap'; + class MapHelper extends TypeHelper { const MapHelper(); @@ -31,13 +36,20 @@ class MapHelper extends TypeHelper { final subFieldValue = context.serialize(valueType, closureArg); final subKeyValue = context.serialize(keyType, _keyParam); + final contextNullable = context.nullable || encodeEmptyAsNullRoot(context); + + if (encodeEmptyAsNullRoot(context)) { + context.addMember(_helperFunctionDefinition); + expression = '$_helperName($expression)'; + } + if (closureArg == subFieldValue && _keyParam == subKeyValue) { return expression; } if (context.config.useWrappers) { var method = '\$wrapMap'; - if (context.nullable) { + if (contextNullable) { method = '${method}HandleNull'; } @@ -45,7 +57,7 @@ class MapHelper extends TypeHelper { return '$method<$keyType, $valueType>($expression, $lambda)'; } - final optionalQuestion = context.nullable ? '?' : ''; + final optionalQuestion = contextNullable ? '?' : ''; return '$expression$optionalQuestion' '.map(($_keyParam, $closureArg) => MapEntry($subKeyValue, $subFieldValue))'; diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index 63c862102..9c1866cf8 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -46,8 +46,11 @@ void throwUnsupported(FieldElement element, String message) => FieldRename _fromDartObject(ConstantReader reader) => reader.isNull ? null - : enumValueForDartObject(reader.objectValue, FieldRename.values, - (f) => f.toString().split('.')[1]); + : enumValueForDartObject( + reader.objectValue, + FieldRename.values, + (f) => f.toString().split('.')[1], + ); T enumValueForDartObject( DartObject source, List items, String Function(T) name) => @@ -66,6 +69,8 @@ JsonSerializable _valueForAnnotation(ConstantReader reader) => JsonSerializable( createToJson: reader.read('createToJson').literalValue as bool, disallowUnrecognizedKeys: reader.read('disallowUnrecognizedKeys').literalValue as bool, + encodeEmptyCollection: + reader.read('encodeEmptyCollection').literalValue as bool, explicitToJson: reader.read('explicitToJson').literalValue as bool, fieldRename: _fromDartObject(reader.read('fieldRename')), generateToJsonFunction: @@ -90,6 +95,8 @@ JsonSerializable mergeConfig(JsonSerializable config, ConstantReader reader) { createToJson: annotation.createToJson ?? config.createToJson, disallowUnrecognizedKeys: annotation.disallowUnrecognizedKeys ?? config.disallowUnrecognizedKeys, + encodeEmptyCollection: + annotation.encodeEmptyCollection ?? config.encodeEmptyCollection, explicitToJson: annotation.explicitToJson ?? config.explicitToJson, fieldRename: annotation.fieldRename ?? config.fieldRename, generateToJsonFunction: diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index cd4f56834..64167c962 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -30,3 +30,7 @@ dev_dependencies: source_gen_test: ^0.1.0 test: ^1.3.3 yaml: ^2.1.13 + +dependency_overrides: + json_annotation: + path: ../json_annotation diff --git a/json_serializable/test/config_test.dart b/json_serializable/test/config_test.dart index 474f401af..b981c0508 100644 --- a/json_serializable/test/config_test.dart +++ b/json_serializable/test/config_test.dart @@ -109,10 +109,24 @@ void main() { final config = Map.from(generatorConfigDefaultJson); config[entry.key] = entry.value; - final matcher = (entry.key == 'field_rename') - ? isArgumentError.having((e) => e.message, 'message', - '`42` is not one of the supported values: none, kebab, snake') - : isCastError; + Matcher matcher; + switch (entry.key) { + case 'field_rename': + matcher = isArgumentError.having((e) => e.message, 'message', + '`42` is not one of the supported values: none, kebab, snake'); + break; + case 'empty_collection_behavior': + matcher = isArgumentError.having( + (e) => e.message, + 'message', + '`42` is not one of the supported values: no_change, ' + 'empty_as_null, null_as_empty', + ); + break; + default: + matcher = isCastError; + break; + } expect( () => jsonSerializable(BuilderOptions(config)), throwsA(matcher)); @@ -127,6 +141,7 @@ const _invalidConfig = { 'create_factory': 42, 'create_to_json': 42, 'disallow_unrecognized_keys': 42, + 'encode_empty_collection': 42, 'explicit_to_json': 42, 'field_rename': 42, 'generate_to_json_function': 42, diff --git a/json_serializable/test/json_serializable_test.dart b/json_serializable/test/json_serializable_test.dart index 736781b1a..3e2befcda 100644 --- a/json_serializable/test/json_serializable_test.dart +++ b/json_serializable/test/json_serializable_test.dart @@ -48,6 +48,10 @@ const _expectedAnnotatedTests = [ 'DefaultWithType', 'DupeKeys', 'DynamicConvertMethods', + 'EmptyCollectionAsNullAndIncludeIfNullClass', + 'EmptyCollectionAsNullAndIncludeIfNullField', + 'EncodeEmptyCollectionAsNullOnField', + 'EncodeEmptyCollectionAsNullOnNonCollectionField', 'FieldNamerKebab', 'FieldNamerNone', 'FieldNamerSnake', diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.dart b/json_serializable/test/kitchen_sink/kitchen_sink.dart index aeaa57dde..5be9abdb0 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.dart @@ -31,6 +31,7 @@ class _Factory implements k.KitchenSinkFactory { bool get nullable => true; bool get excludeNull => false; bool get explicitToJson => false; + bool get noEncodeEmpty => false; k.KitchenSink ctor({ int ctorValidatedNo42, diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.factories.dart b/json_serializable/test/kitchen_sink/kitchen_sink.factories.dart index 089d1e2ee..f5b4db0da 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.factories.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.factories.dart @@ -6,11 +6,20 @@ import 'kitchen_sink.g_any_map__non_nullable.dart' as any_map__non_nullable; import 'kitchen_sink.g_any_map__non_nullable__use_wrappers.dart' as any_map__non_nullable__use_wrappers; import 'kitchen_sink.g_exclude_null.dart' as exclude_null; +import 'kitchen_sink.g_exclude_null__no_encode_empty.dart' + as exclude_null__no_encode_empty; +import 'kitchen_sink.g_exclude_null__no_encode_empty__non_nullable__use_wrappers.dart' + as exclude_null__no_encode_empty__non_nullable__use_wrappers; +import 'kitchen_sink.g_exclude_null__no_encode_empty__use_wrappers.dart' + as exclude_null__no_encode_empty__use_wrappers; import 'kitchen_sink.g_exclude_null__non_nullable.dart' as exclude_null__non_nullable; import 'kitchen_sink.g_exclude_null__use_wrappers.dart' as exclude_null__use_wrappers; import 'kitchen_sink.g_explicit_to_json.dart' as explicit_to_json; +import 'kitchen_sink.g_no_encode_empty.dart' as no_encode_empty; +import 'kitchen_sink.g_no_encode_empty__non_nullable.dart' + as no_encode_empty__non_nullable; const factories = [ normal.factory, @@ -19,7 +28,12 @@ const factories = [ any_map__non_nullable.factory, any_map__non_nullable__use_wrappers.factory, exclude_null.factory, + exclude_null__no_encode_empty.factory, + exclude_null__no_encode_empty__non_nullable__use_wrappers.factory, + exclude_null__no_encode_empty__use_wrappers.factory, exclude_null__non_nullable.factory, exclude_null__use_wrappers.factory, explicit_to_json.factory, + no_encode_empty.factory, + no_encode_empty__non_nullable.factory, ]; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart index b68578374..4da12315d 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart @@ -31,6 +31,7 @@ class _Factory implements k.KitchenSinkFactory { bool get nullable => true; bool get excludeNull => false; bool get explicitToJson => false; + bool get noEncodeEmpty => false; k.KitchenSink ctor({ int ctorValidatedNo42, diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked__non_nullable.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked__non_nullable.dart index a91b6d2e0..56d4f4c4e 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked__non_nullable.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked__non_nullable.dart @@ -31,6 +31,7 @@ class _Factory implements k.KitchenSinkFactory { bool get nullable => false; bool get excludeNull => false; bool get explicitToJson => false; + bool get noEncodeEmpty => false; k.KitchenSink ctor({ int ctorValidatedNo42, diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable.dart index b3a1549ce..c6fed2511 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable.dart @@ -31,6 +31,7 @@ class _Factory implements k.KitchenSinkFactory { bool get nullable => false; bool get excludeNull => false; bool get explicitToJson => false; + bool get noEncodeEmpty => false; k.KitchenSink ctor({ int ctorValidatedNo42, diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable__use_wrappers.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable__use_wrappers.dart index 74459196d..7c3b4be8d 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable__use_wrappers.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable__use_wrappers.dart @@ -31,6 +31,7 @@ class _Factory implements k.KitchenSinkFactory { bool get nullable => false; bool get excludeNull => false; bool get explicitToJson => false; + bool get noEncodeEmpty => false; k.KitchenSink ctor({ int ctorValidatedNo42, diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.dart index 27cedf69b..41c2400a6 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.dart @@ -31,6 +31,7 @@ class _Factory implements k.KitchenSinkFactory { bool get nullable => true; bool get excludeNull => true; bool get explicitToJson => false; + bool get noEncodeEmpty => false; k.KitchenSink ctor({ int ctorValidatedNo42, diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty.dart new file mode 100644 index 000000000..7d2599600 --- /dev/null +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty.dart @@ -0,0 +1,203 @@ +// Copyright (c) 2018, 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. + +// ignore_for_file: annotate_overrides, hash_and_equals +import 'package:json_annotation/json_annotation.dart'; + +import 'json_converters.dart'; +import 'kitchen_sink_interface.dart' as k; +import 'simple_object.dart'; +import 'strict_keys_object.dart'; + +part 'kitchen_sink.g_exclude_null__no_encode_empty.g.dart'; + +// NOTE: these methods are replaced in the `non_nullable` cases to return +// non-null values. +List _defaultList() => null; +Set _defaultSet() => null; +Map _defaultMap() => null; +SimpleObject _defaultSimpleObject() => null; +StrictKeysObject _defaultStrictKeysObject() => null; + +const k.KitchenSinkFactory factory = _Factory(); + +class _Factory implements k.KitchenSinkFactory { + const _Factory(); + + String get description => 'exclude_null__no_encode_empty'; + bool get anyMap => false; + bool get checked => false; + bool get nullable => true; + bool get excludeNull => true; + bool get explicitToJson => false; + bool get noEncodeEmpty => true; + + k.KitchenSink ctor({ + int ctorValidatedNo42, + Iterable iterable, + Iterable dynamicIterable, + Iterable objectIterable, + Iterable intIterable, + Iterable dateTimeIterable, + }) => + KitchenSink( + ctorValidatedNo42: ctorValidatedNo42, + iterable: iterable, + dynamicIterable: dynamicIterable, + objectIterable: objectIterable, + intIterable: intIterable, + dateTimeIterable: dateTimeIterable, + ); + + k.KitchenSink fromJson(Map json) => + KitchenSink.fromJson(json); + + k.JsonConverterTestClass jsonConverterCtor() => JsonConverterTestClass(); + + k.JsonConverterTestClass jsonConverterFromJson(Map json) => + JsonConverterTestClass.fromJson(json); +} + +@JsonSerializable( + includeIfNull: false, + encodeEmptyCollection: false, +) +class KitchenSink implements k.KitchenSink { + // NOTE: exposing these as Iterable, but storing the values as List + // to make the equality test work trivially. + final Iterable _iterable; + final Iterable _dynamicIterable; + final Iterable _objectIterable; + final Iterable _intIterable; + final Iterable _dateTimeIterable; + + @JsonKey(name: 'no-42') + final int ctorValidatedNo42; + + KitchenSink({ + this.ctorValidatedNo42, + Iterable iterable, + Iterable dynamicIterable, + Iterable objectIterable, + Iterable intIterable, + Iterable dateTimeIterable, + }) : _iterable = iterable?.toList() ?? _defaultList(), + _dynamicIterable = dynamicIterable?.toList() ?? _defaultList(), + _objectIterable = objectIterable?.toList() ?? _defaultList(), + _intIterable = intIterable?.toList() ?? _defaultList(), + _dateTimeIterable = dateTimeIterable?.toList() ?? _defaultList() { + if (ctorValidatedNo42 == 42) { + throw ArgumentError.value( + 42, 'ctorValidatedNo42', 'The value `42` is not allowed.'); + } + } + + factory KitchenSink.fromJson(Map json) => + _$KitchenSinkFromJson(json); + + Map toJson() => _$KitchenSinkToJson(this); + + DateTime dateTime; + + BigInt bigInt; + + Iterable get iterable => _iterable; + Iterable get dynamicIterable => _dynamicIterable; + Iterable get objectIterable => _objectIterable; + Iterable get intIterable => _intIterable; + + Set set = _defaultSet(); + Set dynamicSet = _defaultSet(); + Set objectSet = _defaultSet(); + Set intSet = _defaultSet(); + Set dateTimeSet = _defaultSet(); + + // Added a one-off annotation on a property (not a field) + @JsonKey(name: 'datetime-iterable') + Iterable get dateTimeIterable => _dateTimeIterable; + + List list = _defaultList(); + List dynamicList = _defaultList(); + List objectList = _defaultList(); + List intList = _defaultList(); + List dateTimeList = _defaultList(); + + Map map = _defaultMap(); + Map stringStringMap = _defaultMap(); + Map dynamicIntMap = _defaultMap(); + Map objectDateTimeMap = _defaultMap(); + + List>>>> crazyComplex = + _defaultList(); + + // Handle fields with names that collide with helper names + Map val = _defaultMap(); + bool writeNotNull; + @JsonKey(name: r'$string') + String string; + + SimpleObject simpleObject = _defaultSimpleObject(); + + StrictKeysObject strictKeysObject = _defaultStrictKeysObject(); + + int _validatedPropertyNo42; + int get validatedPropertyNo42 => _validatedPropertyNo42; + + set validatedPropertyNo42(int value) { + if (value == 42) { + throw StateError('Cannot be 42!'); + } + _validatedPropertyNo42 = value; + } + + bool operator ==(Object other) => k.sinkEquals(this, other); +} + +@JsonSerializable( + includeIfNull: false, + encodeEmptyCollection: false, +) +// referencing a top-level field should work +@durationConverter +// referencing via a const constructor should work +@BigIntStringConverter() +@TrivialNumberConverter.instance +@EpochDateTimeConverter() +class JsonConverterTestClass implements k.JsonConverterTestClass { + JsonConverterTestClass(); + + factory JsonConverterTestClass.fromJson(Map json) => + _$JsonConverterTestClassFromJson(json); + + Map toJson() => _$JsonConverterTestClassToJson(this); + + Duration duration; + List durationList; + + BigInt bigInt; + Map bigIntMap; + + TrivialNumber numberSilly; + Set numberSillySet; + + DateTime dateTime; +} + +@JsonSerializable( + includeIfNull: false, + encodeEmptyCollection: false, +) +@GenericConverter() +class JsonConverterGeneric { + S item; + List itemList; + Map itemMap; + + JsonConverterGeneric(); + + factory JsonConverterGeneric.fromJson(Map json) => + _$JsonConverterGenericFromJson(json); + + Map toJson() => _$JsonConverterGenericToJson(this); +} diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty.g.dart new file mode 100644 index 000000000..c0cbbe9c3 --- /dev/null +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty.g.dart @@ -0,0 +1,283 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'kitchen_sink.g_exclude_null__no_encode_empty.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +KitchenSink _$KitchenSinkFromJson(Map json) { + return KitchenSink( + ctorValidatedNo42: json['no-42'] as int, + iterable: json['iterable'] as List, + dynamicIterable: json['dynamicIterable'] as List, + objectIterable: json['objectIterable'] as List, + intIterable: (json['intIterable'] as List)?.map((e) => e as int), + dateTimeIterable: (json['datetime-iterable'] as List) + ?.map((e) => e == null ? null : DateTime.parse(e as String))) + ..dateTime = json['dateTime'] == null + ? null + : DateTime.parse(json['dateTime'] as String) + ..bigInt = + json['bigInt'] == null ? null : BigInt.parse(json['bigInt'] as String) + ..set = (json['set'] as List)?.toSet() + ..dynamicSet = (json['dynamicSet'] as List)?.toSet() + ..objectSet = (json['objectSet'] as List)?.toSet() + ..intSet = (json['intSet'] as List)?.map((e) => e as int)?.toSet() + ..dateTimeSet = (json['dateTimeSet'] as List) + ?.map((e) => e == null ? null : DateTime.parse(e as String)) + ?.toSet() + ..list = json['list'] as List + ..dynamicList = json['dynamicList'] as List + ..objectList = json['objectList'] as List + ..intList = (json['intList'] as List)?.map((e) => e as int)?.toList() + ..dateTimeList = (json['dateTimeList'] as List) + ?.map((e) => e == null ? null : DateTime.parse(e as String)) + ?.toList() + ..map = json['map'] as Map + ..stringStringMap = (json['stringStringMap'] as Map)?.map( + (k, e) => MapEntry(k, e as String), + ) + ..dynamicIntMap = (json['dynamicIntMap'] as Map)?.map( + (k, e) => MapEntry(k, e as int), + ) + ..objectDateTimeMap = + (json['objectDateTimeMap'] as Map)?.map( + (k, e) => MapEntry(k, e == null ? null : DateTime.parse(e as String)), + ) + ..crazyComplex = (json['crazyComplex'] as List) + ?.map((e) => (e as Map)?.map( + (k, e) => MapEntry( + k, + (e as Map)?.map( + (k, e) => MapEntry( + k, + (e as List) + ?.map((e) => (e as List) + ?.map((e) => e == null + ? null + : DateTime.parse(e as String)) + ?.toList()) + ?.toList()), + )), + )) + ?.toList() + ..val = (json['val'] as Map)?.map( + (k, e) => MapEntry(k, e as bool), + ) + ..writeNotNull = json['writeNotNull'] as bool + ..string = json[r'$string'] as String + ..simpleObject = json['simpleObject'] == null + ? null + : SimpleObject.fromJson(json['simpleObject'] as Map) + ..strictKeysObject = json['strictKeysObject'] == null + ? null + : StrictKeysObject.fromJson( + json['strictKeysObject'] as Map) + ..validatedPropertyNo42 = json['validatedPropertyNo42'] as int; +} + +Map _$KitchenSinkToJson(KitchenSink instance) { + final val = {}; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('no-42', instance.ctorValidatedNo42); + writeNotNull('dateTime', instance.dateTime?.toIso8601String()); + writeNotNull('bigInt', instance.bigInt?.toString()); + writeNotNull('iterable', _$nullIfEmptyIterable(instance.iterable)?.toList()); + writeNotNull('dynamicIterable', + _$nullIfEmptyIterable(instance.dynamicIterable)?.toList()); + writeNotNull('objectIterable', + _$nullIfEmptyIterable(instance.objectIterable)?.toList()); + writeNotNull( + 'intIterable', _$nullIfEmptyIterable(instance.intIterable)?.toList()); + writeNotNull('set', _$nullIfEmptyIterable(instance.set)?.toList()); + writeNotNull( + 'dynamicSet', _$nullIfEmptyIterable(instance.dynamicSet)?.toList()); + writeNotNull( + 'objectSet', _$nullIfEmptyIterable(instance.objectSet)?.toList()); + writeNotNull('intSet', _$nullIfEmptyIterable(instance.intSet)?.toList()); + writeNotNull( + 'dateTimeSet', + _$nullIfEmptyIterable(instance.dateTimeSet) + ?.map((e) => e?.toIso8601String()) + ?.toList()); + writeNotNull( + 'datetime-iterable', + _$nullIfEmptyIterable(instance.dateTimeIterable) + ?.map((e) => e?.toIso8601String()) + ?.toList()); + writeNotNull('list', _$nullIfEmptyIterable(instance.list)); + writeNotNull('dynamicList', _$nullIfEmptyIterable(instance.dynamicList)); + writeNotNull('objectList', _$nullIfEmptyIterable(instance.objectList)); + writeNotNull('intList', _$nullIfEmptyIterable(instance.intList)); + writeNotNull( + 'dateTimeList', + _$nullIfEmptyIterable(instance.dateTimeList) + ?.map((e) => e?.toIso8601String()) + ?.toList()); + writeNotNull('map', _$nullIfEmptyMap(instance.map)); + writeNotNull('stringStringMap', _$nullIfEmptyMap(instance.stringStringMap)); + writeNotNull('dynamicIntMap', _$nullIfEmptyMap(instance.dynamicIntMap)); + writeNotNull( + 'objectDateTimeMap', + _$nullIfEmptyMap(instance.objectDateTimeMap) + ?.map((k, e) => MapEntry(k, e?.toIso8601String()))); + writeNotNull( + 'crazyComplex', + _$nullIfEmptyIterable(instance.crazyComplex) + ?.map((e) => e?.map((k, e) => MapEntry( + k, + e?.map((k, e) => MapEntry( + k, + e + ?.map( + (e) => e?.map((e) => e?.toIso8601String())?.toList()) + ?.toList()))))) + ?.toList()); + writeNotNull('val', _$nullIfEmptyMap(instance.val)); + writeNotNull('writeNotNull', instance.writeNotNull); + writeNotNull(r'$string', instance.string); + writeNotNull('simpleObject', instance.simpleObject); + writeNotNull('strictKeysObject', instance.strictKeysObject); + writeNotNull('validatedPropertyNo42', instance.validatedPropertyNo42); + return val; +} + +T _$nullIfEmptyIterable(T source) => + (source == null || source.isEmpty) ? null : source; + +T _$nullIfEmptyMap(T source) => + (source == null || source.isEmpty) ? null : source; + +JsonConverterTestClass _$JsonConverterTestClassFromJson( + Map json) { + return JsonConverterTestClass() + ..duration = json['duration'] == null + ? null + : durationConverter.fromJson(json['duration'] as int) + ..durationList = (json['durationList'] as List) + ?.map((e) => e == null ? null : durationConverter.fromJson(e as int)) + ?.toList() + ..bigInt = json['bigInt'] == null + ? null + : const BigIntStringConverter().fromJson(json['bigInt'] as String) + ..bigIntMap = (json['bigIntMap'] as Map)?.map( + (k, e) => MapEntry( + k, + e == null + ? null + : const BigIntStringConverter().fromJson(e as String)), + ) + ..numberSilly = json['numberSilly'] == null + ? null + : TrivialNumberConverter.instance.fromJson(json['numberSilly'] as int) + ..numberSillySet = (json['numberSillySet'] as List) + ?.map((e) => e == null + ? null + : TrivialNumberConverter.instance.fromJson(e as int)) + ?.toSet() + ..dateTime = json['dateTime'] == null + ? null + : const EpochDateTimeConverter().fromJson(json['dateTime'] as int); +} + +Map _$JsonConverterTestClassToJson( + JsonConverterTestClass instance) { + final val = {}; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull( + 'duration', + instance.duration == null + ? null + : durationConverter.toJson(instance.duration)); + writeNotNull( + 'durationList', + _$nullIfEmptyIterable(instance.durationList) + ?.map((e) => e == null ? null : durationConverter.toJson(e)) + ?.toList()); + writeNotNull( + 'bigInt', + instance.bigInt == null + ? null + : const BigIntStringConverter().toJson(instance.bigInt)); + writeNotNull( + 'bigIntMap', + _$nullIfEmptyMap(instance.bigIntMap)?.map((k, e) => MapEntry( + k, e == null ? null : const BigIntStringConverter().toJson(e)))); + writeNotNull( + 'numberSilly', + instance.numberSilly == null + ? null + : TrivialNumberConverter.instance.toJson(instance.numberSilly)); + writeNotNull( + 'numberSillySet', + _$nullIfEmptyIterable(instance.numberSillySet) + ?.map((e) => + e == null ? null : TrivialNumberConverter.instance.toJson(e)) + ?.toList()); + writeNotNull( + 'dateTime', + instance.dateTime == null + ? null + : const EpochDateTimeConverter().toJson(instance.dateTime)); + return val; +} + +JsonConverterGeneric _$JsonConverterGenericFromJson( + Map json) { + return JsonConverterGeneric() + ..item = json['item'] == null + ? null + : GenericConverter().fromJson(json['item'] as Map) + ..itemList = (json['itemList'] as List) + ?.map((e) => e == null + ? null + : GenericConverter().fromJson(e as Map)) + ?.toList() + ..itemMap = (json['itemMap'] as Map)?.map( + (k, e) => MapEntry( + k, + e == null + ? null + : GenericConverter().fromJson(e as Map)), + ); +} + +Map _$JsonConverterGenericToJson( + JsonConverterGeneric instance) { + final val = {}; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull( + 'item', + instance.item == null + ? null + : GenericConverter().toJson(instance.item)); + writeNotNull( + 'itemList', + _$nullIfEmptyIterable(instance.itemList) + ?.map((e) => e == null ? null : GenericConverter().toJson(e)) + ?.toList()); + writeNotNull( + 'itemMap', + _$nullIfEmptyMap(instance.itemMap)?.map((k, e) => + MapEntry(k, e == null ? null : GenericConverter().toJson(e)))); + return val; +} diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty__non_nullable__use_wrappers.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty__non_nullable__use_wrappers.dart new file mode 100644 index 000000000..e02030806 --- /dev/null +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty__non_nullable__use_wrappers.dart @@ -0,0 +1,210 @@ +// Copyright (c) 2018, 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. + +// ignore_for_file: annotate_overrides, hash_and_equals +import 'package:json_annotation/json_annotation.dart'; + +import 'json_converters.dart'; +import 'kitchen_sink_interface.dart' as k; +import 'simple_object.dart'; +import 'strict_keys_object.dart'; + +part 'kitchen_sink.g_exclude_null__no_encode_empty__non_nullable__use_wrappers.g.dart'; + +// NOTE: these methods are replaced in the `non_nullable` cases to return +// non-null values. +List _defaultList() => []; +Set _defaultSet() => Set(); +Map _defaultMap() => {}; +SimpleObject _defaultSimpleObject() => SimpleObject(42); +StrictKeysObject _defaultStrictKeysObject() => StrictKeysObject(10, 'cool'); + +const k.KitchenSinkFactory factory = _Factory(); + +class _Factory implements k.KitchenSinkFactory { + const _Factory(); + + String get description => + 'exclude_null__no_encode_empty__non_nullable__use_wrappers'; + bool get anyMap => false; + bool get checked => false; + bool get nullable => false; + bool get excludeNull => true; + bool get explicitToJson => false; + bool get noEncodeEmpty => true; + + k.KitchenSink ctor({ + int ctorValidatedNo42, + Iterable iterable, + Iterable dynamicIterable, + Iterable objectIterable, + Iterable intIterable, + Iterable dateTimeIterable, + }) => + KitchenSink( + ctorValidatedNo42: ctorValidatedNo42, + iterable: iterable, + dynamicIterable: dynamicIterable, + objectIterable: objectIterable, + intIterable: intIterable, + dateTimeIterable: dateTimeIterable, + ); + + k.KitchenSink fromJson(Map json) => + KitchenSink.fromJson(json); + + k.JsonConverterTestClass jsonConverterCtor() => JsonConverterTestClass(); + + k.JsonConverterTestClass jsonConverterFromJson(Map json) => + JsonConverterTestClass.fromJson(json); +} + +@JsonSerializable( + useWrappers: true, + nullable: false, + includeIfNull: false, + encodeEmptyCollection: false, +) +class KitchenSink implements k.KitchenSink { + // NOTE: exposing these as Iterable, but storing the values as List + // to make the equality test work trivially. + final Iterable _iterable; + final Iterable _dynamicIterable; + final Iterable _objectIterable; + final Iterable _intIterable; + final Iterable _dateTimeIterable; + + @JsonKey(name: 'no-42') + final int ctorValidatedNo42; + + KitchenSink({ + this.ctorValidatedNo42, + Iterable iterable, + Iterable dynamicIterable, + Iterable objectIterable, + Iterable intIterable, + Iterable dateTimeIterable, + }) : _iterable = iterable?.toList() ?? _defaultList(), + _dynamicIterable = dynamicIterable?.toList() ?? _defaultList(), + _objectIterable = objectIterable?.toList() ?? _defaultList(), + _intIterable = intIterable?.toList() ?? _defaultList(), + _dateTimeIterable = dateTimeIterable?.toList() ?? _defaultList() { + if (ctorValidatedNo42 == 42) { + throw ArgumentError.value( + 42, 'ctorValidatedNo42', 'The value `42` is not allowed.'); + } + } + + factory KitchenSink.fromJson(Map json) => + _$KitchenSinkFromJson(json); + + Map toJson() => _$KitchenSinkToJson(this); + + DateTime dateTime = DateTime(1981, 6, 5); + + BigInt bigInt = BigInt.parse('10000000000000000000'); + + Iterable get iterable => _iterable; + Iterable get dynamicIterable => _dynamicIterable; + Iterable get objectIterable => _objectIterable; + Iterable get intIterable => _intIterable; + + Set set = _defaultSet(); + Set dynamicSet = _defaultSet(); + Set objectSet = _defaultSet(); + Set intSet = _defaultSet(); + Set dateTimeSet = _defaultSet(); + + // Added a one-off annotation on a property (not a field) + @JsonKey(name: 'datetime-iterable') + Iterable get dateTimeIterable => _dateTimeIterable; + + List list = _defaultList(); + List dynamicList = _defaultList(); + List objectList = _defaultList(); + List intList = _defaultList(); + List dateTimeList = _defaultList(); + + Map map = _defaultMap(); + Map stringStringMap = _defaultMap(); + Map dynamicIntMap = _defaultMap(); + Map objectDateTimeMap = _defaultMap(); + + List>>>> crazyComplex = + _defaultList(); + + // Handle fields with names that collide with helper names + Map val = _defaultMap(); + bool writeNotNull; + @JsonKey(name: r'$string') + String string; + + SimpleObject simpleObject = _defaultSimpleObject(); + + StrictKeysObject strictKeysObject = _defaultStrictKeysObject(); + + int _validatedPropertyNo42; + int get validatedPropertyNo42 => _validatedPropertyNo42; + + set validatedPropertyNo42(int value) { + if (value == 42) { + throw StateError('Cannot be 42!'); + } + _validatedPropertyNo42 = value; + } + + bool operator ==(Object other) => k.sinkEquals(this, other); +} + +@JsonSerializable( + useWrappers: true, + nullable: false, + includeIfNull: false, + encodeEmptyCollection: false, +) +// referencing a top-level field should work +@durationConverter +// referencing via a const constructor should work +@BigIntStringConverter() +@TrivialNumberConverter.instance +@EpochDateTimeConverter() +class JsonConverterTestClass implements k.JsonConverterTestClass { + JsonConverterTestClass(); + + factory JsonConverterTestClass.fromJson(Map json) => + _$JsonConverterTestClassFromJson(json); + + Map toJson() => _$JsonConverterTestClassToJson(this); + + Duration duration; + List durationList; + + BigInt bigInt = BigInt.parse('10000000000000000000'); + Map bigIntMap; + + TrivialNumber numberSilly; + Set numberSillySet; + + DateTime dateTime = DateTime(1981, 6, 5); +} + +@JsonSerializable( + useWrappers: true, + nullable: false, + includeIfNull: false, + encodeEmptyCollection: false, +) +@GenericConverter() +class JsonConverterGeneric { + S item; + List itemList; + Map itemMap; + + JsonConverterGeneric(); + + factory JsonConverterGeneric.fromJson(Map json) => + _$JsonConverterGenericFromJson(json); + + Map toJson() => _$JsonConverterGenericToJson(this); +} diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty__non_nullable__use_wrappers.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty__non_nullable__use_wrappers.g.dart new file mode 100644 index 000000000..50bc4243a --- /dev/null +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty__non_nullable__use_wrappers.g.dart @@ -0,0 +1,364 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'kitchen_sink.g_exclude_null__no_encode_empty__non_nullable__use_wrappers.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +KitchenSink _$KitchenSinkFromJson(Map json) { + return KitchenSink( + ctorValidatedNo42: json['no-42'] as int, + iterable: json['iterable'] as List, + dynamicIterable: json['dynamicIterable'] as List, + objectIterable: json['objectIterable'] as List, + intIterable: (json['intIterable'] as List).map((e) => e as int), + dateTimeIterable: (json['datetime-iterable'] as List) + .map((e) => DateTime.parse(e as String))) + ..dateTime = DateTime.parse(json['dateTime'] as String) + ..bigInt = BigInt.parse(json['bigInt'] as String) + ..set = (json['set'] as List).toSet() + ..dynamicSet = (json['dynamicSet'] as List).toSet() + ..objectSet = (json['objectSet'] as List).toSet() + ..intSet = (json['intSet'] as List).map((e) => e as int).toSet() + ..dateTimeSet = (json['dateTimeSet'] as List) + .map((e) => DateTime.parse(e as String)) + .toSet() + ..list = json['list'] as List + ..dynamicList = json['dynamicList'] as List + ..objectList = json['objectList'] as List + ..intList = (json['intList'] as List).map((e) => e as int).toList() + ..dateTimeList = (json['dateTimeList'] as List) + .map((e) => DateTime.parse(e as String)) + .toList() + ..map = json['map'] as Map + ..stringStringMap = Map.from(json['stringStringMap'] as Map) + ..dynamicIntMap = Map.from(json['dynamicIntMap'] as Map) + ..objectDateTimeMap = + (json['objectDateTimeMap'] as Map).map( + (k, e) => MapEntry(k, DateTime.parse(e as String)), + ) + ..crazyComplex = (json['crazyComplex'] as List) + .map((e) => (e as Map).map( + (k, e) => MapEntry( + k, + (e as Map).map( + (k, e) => MapEntry( + k, + (e as List) + .map((e) => (e as List) + .map((e) => DateTime.parse(e as String)) + .toList()) + .toList()), + )), + )) + .toList() + ..val = Map.from(json['val'] as Map) + ..writeNotNull = json['writeNotNull'] as bool + ..string = json[r'$string'] as String + ..simpleObject = + SimpleObject.fromJson(json['simpleObject'] as Map) + ..strictKeysObject = StrictKeysObject.fromJson( + json['strictKeysObject'] as Map) + ..validatedPropertyNo42 = json['validatedPropertyNo42'] as int; +} + +Map _$KitchenSinkToJson(KitchenSink instance) => + _$KitchenSinkJsonMapWrapper(instance); + +class _$KitchenSinkJsonMapWrapper extends $JsonMapWrapper { + final KitchenSink _v; + _$KitchenSinkJsonMapWrapper(this._v); + + @override + Iterable get keys sync* { + yield 'no-42'; + yield 'dateTime'; + yield 'bigInt'; + if (_v.iterable.isNotEmpty) { + yield 'iterable'; + } + if (_v.dynamicIterable.isNotEmpty) { + yield 'dynamicIterable'; + } + if (_v.objectIterable.isNotEmpty) { + yield 'objectIterable'; + } + if (_v.intIterable.isNotEmpty) { + yield 'intIterable'; + } + if (_v.set.isNotEmpty) { + yield 'set'; + } + if (_v.dynamicSet.isNotEmpty) { + yield 'dynamicSet'; + } + if (_v.objectSet.isNotEmpty) { + yield 'objectSet'; + } + if (_v.intSet.isNotEmpty) { + yield 'intSet'; + } + if (_v.dateTimeSet.isNotEmpty) { + yield 'dateTimeSet'; + } + if (_v.dateTimeIterable.isNotEmpty) { + yield 'datetime-iterable'; + } + if (_v.list.isNotEmpty) { + yield 'list'; + } + if (_v.dynamicList.isNotEmpty) { + yield 'dynamicList'; + } + if (_v.objectList.isNotEmpty) { + yield 'objectList'; + } + if (_v.intList.isNotEmpty) { + yield 'intList'; + } + if (_v.dateTimeList.isNotEmpty) { + yield 'dateTimeList'; + } + if (_v.map.isNotEmpty) { + yield 'map'; + } + if (_v.stringStringMap.isNotEmpty) { + yield 'stringStringMap'; + } + if (_v.dynamicIntMap.isNotEmpty) { + yield 'dynamicIntMap'; + } + if (_v.objectDateTimeMap.isNotEmpty) { + yield 'objectDateTimeMap'; + } + if (_v.crazyComplex.isNotEmpty) { + yield 'crazyComplex'; + } + if (_v.val.isNotEmpty) { + yield 'val'; + } + yield 'writeNotNull'; + yield r'$string'; + yield 'simpleObject'; + yield 'strictKeysObject'; + yield 'validatedPropertyNo42'; + } + + @override + dynamic operator [](Object key) { + if (key is String) { + switch (key) { + case 'no-42': + return _v.ctorValidatedNo42; + case 'dateTime': + return _v.dateTime.toIso8601String(); + case 'bigInt': + return _v.bigInt.toString(); + case 'iterable': + return _$nullIfEmptyIterable(_v.iterable)?.toList(); + case 'dynamicIterable': + return _$nullIfEmptyIterable(_v.dynamicIterable)?.toList(); + case 'objectIterable': + return _$nullIfEmptyIterable(_v.objectIterable)?.toList(); + case 'intIterable': + return _$nullIfEmptyIterable(_v.intIterable)?.toList(); + case 'set': + return _$nullIfEmptyIterable(_v.set)?.toList(); + case 'dynamicSet': + return _$nullIfEmptyIterable(_v.dynamicSet)?.toList(); + case 'objectSet': + return _$nullIfEmptyIterable(_v.objectSet)?.toList(); + case 'intSet': + return _$nullIfEmptyIterable(_v.intSet)?.toList(); + case 'dateTimeSet': + return _$nullIfEmptyIterable(_v.dateTimeSet) + ?.map((e) => e.toIso8601String()) + ?.toList(); + case 'datetime-iterable': + return _$nullIfEmptyIterable(_v.dateTimeIterable) + ?.map((e) => e.toIso8601String()) + ?.toList(); + case 'list': + return _$nullIfEmptyIterable(_v.list); + case 'dynamicList': + return _$nullIfEmptyIterable(_v.dynamicList); + case 'objectList': + return _$nullIfEmptyIterable(_v.objectList); + case 'intList': + return _$nullIfEmptyIterable(_v.intList); + case 'dateTimeList': + return $wrapListHandleNull( + _$nullIfEmptyIterable(_v.dateTimeList), + (e) => e.toIso8601String()); + case 'map': + return _$nullIfEmptyMap(_v.map); + case 'stringStringMap': + return _$nullIfEmptyMap(_v.stringStringMap); + case 'dynamicIntMap': + return _$nullIfEmptyMap(_v.dynamicIntMap); + case 'objectDateTimeMap': + return $wrapMapHandleNull( + _$nullIfEmptyMap(_v.objectDateTimeMap), + (e) => e.toIso8601String()); + case 'crazyComplex': + return $wrapListHandleNull< + Map>>>>( + _$nullIfEmptyIterable(_v.crazyComplex), + (e) => $wrapMap>>>( + e, + (e) => $wrapMap>>( + e, + (e) => $wrapList>( + e, + (e) => $wrapList( + e, (e) => e.toIso8601String()))))); + case 'val': + return _$nullIfEmptyMap(_v.val); + case 'writeNotNull': + return _v.writeNotNull; + case r'$string': + return _v.string; + case 'simpleObject': + return _v.simpleObject; + case 'strictKeysObject': + return _v.strictKeysObject; + case 'validatedPropertyNo42': + return _v.validatedPropertyNo42; + } + } + return null; + } +} + +T _$nullIfEmptyIterable(T source) => + (source == null || source.isEmpty) ? null : source; + +T _$nullIfEmptyMap(T source) => + (source == null || source.isEmpty) ? null : source; + +JsonConverterTestClass _$JsonConverterTestClassFromJson( + Map json) { + return JsonConverterTestClass() + ..duration = durationConverter.fromJson(json['duration'] as int) + ..durationList = (json['durationList'] as List) + .map((e) => durationConverter.fromJson(e as int)) + .toList() + ..bigInt = const BigIntStringConverter().fromJson(json['bigInt'] as String) + ..bigIntMap = (json['bigIntMap'] as Map).map( + (k, e) => + MapEntry(k, const BigIntStringConverter().fromJson(e as String)), + ) + ..numberSilly = + TrivialNumberConverter.instance.fromJson(json['numberSilly'] as int) + ..numberSillySet = (json['numberSillySet'] as List) + .map((e) => TrivialNumberConverter.instance.fromJson(e as int)) + .toSet() + ..dateTime = + const EpochDateTimeConverter().fromJson(json['dateTime'] as int); +} + +Map _$JsonConverterTestClassToJson( + JsonConverterTestClass instance) => + _$JsonConverterTestClassJsonMapWrapper(instance); + +class _$JsonConverterTestClassJsonMapWrapper extends $JsonMapWrapper { + final JsonConverterTestClass _v; + _$JsonConverterTestClassJsonMapWrapper(this._v); + + @override + Iterable get keys sync* { + yield 'duration'; + if (_v.durationList.isNotEmpty) { + yield 'durationList'; + } + yield 'bigInt'; + if (_v.bigIntMap.isNotEmpty) { + yield 'bigIntMap'; + } + yield 'numberSilly'; + if (_v.numberSillySet.isNotEmpty) { + yield 'numberSillySet'; + } + yield 'dateTime'; + } + + @override + dynamic operator [](Object key) { + if (key is String) { + switch (key) { + case 'duration': + return durationConverter.toJson(_v.duration); + case 'durationList': + return $wrapListHandleNull( + _$nullIfEmptyIterable(_v.durationList), durationConverter.toJson); + case 'bigInt': + return const BigIntStringConverter().toJson(_v.bigInt); + case 'bigIntMap': + return $wrapMapHandleNull( + _$nullIfEmptyMap(_v.bigIntMap), + const BigIntStringConverter().toJson); + case 'numberSilly': + return TrivialNumberConverter.instance.toJson(_v.numberSilly); + case 'numberSillySet': + return _$nullIfEmptyIterable(_v.numberSillySet) + ?.map(TrivialNumberConverter.instance.toJson) + ?.toList(); + case 'dateTime': + return const EpochDateTimeConverter().toJson(_v.dateTime); + } + } + return null; + } +} + +JsonConverterGeneric _$JsonConverterGenericFromJson( + Map json) { + return JsonConverterGeneric() + ..item = + GenericConverter().fromJson(json['item'] as Map) + ..itemList = (json['itemList'] as List) + .map((e) => GenericConverter().fromJson(e as Map)) + .toList() + ..itemMap = (json['itemMap'] as Map).map( + (k, e) => MapEntry( + k, GenericConverter().fromJson(e as Map)), + ); +} + +Map _$JsonConverterGenericToJson( + JsonConverterGeneric instance) => + _$JsonConverterGenericJsonMapWrapper(instance); + +class _$JsonConverterGenericJsonMapWrapper extends $JsonMapWrapper { + final JsonConverterGeneric _v; + _$JsonConverterGenericJsonMapWrapper(this._v); + + @override + Iterable get keys sync* { + yield 'item'; + if (_v.itemList.isNotEmpty) { + yield 'itemList'; + } + if (_v.itemMap.isNotEmpty) { + yield 'itemMap'; + } + } + + @override + dynamic operator [](Object key) { + if (key is String) { + switch (key) { + case 'item': + return GenericConverter().toJson(_v.item); + case 'itemList': + return $wrapListHandleNull( + _$nullIfEmptyIterable(_v.itemList), GenericConverter().toJson); + case 'itemMap': + return $wrapMapHandleNull( + _$nullIfEmptyMap(_v.itemMap), GenericConverter().toJson); + } + } + return null; + } +} diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty__use_wrappers.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty__use_wrappers.dart new file mode 100644 index 000000000..9a0db7303 --- /dev/null +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty__use_wrappers.dart @@ -0,0 +1,206 @@ +// Copyright (c) 2018, 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. + +// ignore_for_file: annotate_overrides, hash_and_equals +import 'package:json_annotation/json_annotation.dart'; + +import 'json_converters.dart'; +import 'kitchen_sink_interface.dart' as k; +import 'simple_object.dart'; +import 'strict_keys_object.dart'; + +part 'kitchen_sink.g_exclude_null__no_encode_empty__use_wrappers.g.dart'; + +// NOTE: these methods are replaced in the `non_nullable` cases to return +// non-null values. +List _defaultList() => null; +Set _defaultSet() => null; +Map _defaultMap() => null; +SimpleObject _defaultSimpleObject() => null; +StrictKeysObject _defaultStrictKeysObject() => null; + +const k.KitchenSinkFactory factory = _Factory(); + +class _Factory implements k.KitchenSinkFactory { + const _Factory(); + + String get description => 'exclude_null__no_encode_empty__use_wrappers'; + bool get anyMap => false; + bool get checked => false; + bool get nullable => true; + bool get excludeNull => true; + bool get explicitToJson => false; + bool get noEncodeEmpty => true; + + k.KitchenSink ctor({ + int ctorValidatedNo42, + Iterable iterable, + Iterable dynamicIterable, + Iterable objectIterable, + Iterable intIterable, + Iterable dateTimeIterable, + }) => + KitchenSink( + ctorValidatedNo42: ctorValidatedNo42, + iterable: iterable, + dynamicIterable: dynamicIterable, + objectIterable: objectIterable, + intIterable: intIterable, + dateTimeIterable: dateTimeIterable, + ); + + k.KitchenSink fromJson(Map json) => + KitchenSink.fromJson(json); + + k.JsonConverterTestClass jsonConverterCtor() => JsonConverterTestClass(); + + k.JsonConverterTestClass jsonConverterFromJson(Map json) => + JsonConverterTestClass.fromJson(json); +} + +@JsonSerializable( + useWrappers: true, + includeIfNull: false, + encodeEmptyCollection: false, +) +class KitchenSink implements k.KitchenSink { + // NOTE: exposing these as Iterable, but storing the values as List + // to make the equality test work trivially. + final Iterable _iterable; + final Iterable _dynamicIterable; + final Iterable _objectIterable; + final Iterable _intIterable; + final Iterable _dateTimeIterable; + + @JsonKey(name: 'no-42') + final int ctorValidatedNo42; + + KitchenSink({ + this.ctorValidatedNo42, + Iterable iterable, + Iterable dynamicIterable, + Iterable objectIterable, + Iterable intIterable, + Iterable dateTimeIterable, + }) : _iterable = iterable?.toList() ?? _defaultList(), + _dynamicIterable = dynamicIterable?.toList() ?? _defaultList(), + _objectIterable = objectIterable?.toList() ?? _defaultList(), + _intIterable = intIterable?.toList() ?? _defaultList(), + _dateTimeIterable = dateTimeIterable?.toList() ?? _defaultList() { + if (ctorValidatedNo42 == 42) { + throw ArgumentError.value( + 42, 'ctorValidatedNo42', 'The value `42` is not allowed.'); + } + } + + factory KitchenSink.fromJson(Map json) => + _$KitchenSinkFromJson(json); + + Map toJson() => _$KitchenSinkToJson(this); + + DateTime dateTime; + + BigInt bigInt; + + Iterable get iterable => _iterable; + Iterable get dynamicIterable => _dynamicIterable; + Iterable get objectIterable => _objectIterable; + Iterable get intIterable => _intIterable; + + Set set = _defaultSet(); + Set dynamicSet = _defaultSet(); + Set objectSet = _defaultSet(); + Set intSet = _defaultSet(); + Set dateTimeSet = _defaultSet(); + + // Added a one-off annotation on a property (not a field) + @JsonKey(name: 'datetime-iterable') + Iterable get dateTimeIterable => _dateTimeIterable; + + List list = _defaultList(); + List dynamicList = _defaultList(); + List objectList = _defaultList(); + List intList = _defaultList(); + List dateTimeList = _defaultList(); + + Map map = _defaultMap(); + Map stringStringMap = _defaultMap(); + Map dynamicIntMap = _defaultMap(); + Map objectDateTimeMap = _defaultMap(); + + List>>>> crazyComplex = + _defaultList(); + + // Handle fields with names that collide with helper names + Map val = _defaultMap(); + bool writeNotNull; + @JsonKey(name: r'$string') + String string; + + SimpleObject simpleObject = _defaultSimpleObject(); + + StrictKeysObject strictKeysObject = _defaultStrictKeysObject(); + + int _validatedPropertyNo42; + int get validatedPropertyNo42 => _validatedPropertyNo42; + + set validatedPropertyNo42(int value) { + if (value == 42) { + throw StateError('Cannot be 42!'); + } + _validatedPropertyNo42 = value; + } + + bool operator ==(Object other) => k.sinkEquals(this, other); +} + +@JsonSerializable( + useWrappers: true, + includeIfNull: false, + encodeEmptyCollection: false, +) +// referencing a top-level field should work +@durationConverter +// referencing via a const constructor should work +@BigIntStringConverter() +@TrivialNumberConverter.instance +@EpochDateTimeConverter() +class JsonConverterTestClass implements k.JsonConverterTestClass { + JsonConverterTestClass(); + + factory JsonConverterTestClass.fromJson(Map json) => + _$JsonConverterTestClassFromJson(json); + + Map toJson() => _$JsonConverterTestClassToJson(this); + + Duration duration; + List durationList; + + BigInt bigInt; + Map bigIntMap; + + TrivialNumber numberSilly; + Set numberSillySet; + + DateTime dateTime; +} + +@JsonSerializable( + useWrappers: true, + includeIfNull: false, + encodeEmptyCollection: false, +) +@GenericConverter() +class JsonConverterGeneric { + S item; + List itemList; + Map itemMap; + + JsonConverterGeneric(); + + factory JsonConverterGeneric.fromJson(Map json) => + _$JsonConverterGenericFromJson(json); + + Map toJson() => _$JsonConverterGenericToJson(this); +} diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty__use_wrappers.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty__use_wrappers.g.dart new file mode 100644 index 000000000..5845fbf59 --- /dev/null +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty__use_wrappers.g.dart @@ -0,0 +1,433 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'kitchen_sink.g_exclude_null__no_encode_empty__use_wrappers.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +KitchenSink _$KitchenSinkFromJson(Map json) { + return KitchenSink( + ctorValidatedNo42: json['no-42'] as int, + iterable: json['iterable'] as List, + dynamicIterable: json['dynamicIterable'] as List, + objectIterable: json['objectIterable'] as List, + intIterable: (json['intIterable'] as List)?.map((e) => e as int), + dateTimeIterable: (json['datetime-iterable'] as List) + ?.map((e) => e == null ? null : DateTime.parse(e as String))) + ..dateTime = json['dateTime'] == null + ? null + : DateTime.parse(json['dateTime'] as String) + ..bigInt = + json['bigInt'] == null ? null : BigInt.parse(json['bigInt'] as String) + ..set = (json['set'] as List)?.toSet() + ..dynamicSet = (json['dynamicSet'] as List)?.toSet() + ..objectSet = (json['objectSet'] as List)?.toSet() + ..intSet = (json['intSet'] as List)?.map((e) => e as int)?.toSet() + ..dateTimeSet = (json['dateTimeSet'] as List) + ?.map((e) => e == null ? null : DateTime.parse(e as String)) + ?.toSet() + ..list = json['list'] as List + ..dynamicList = json['dynamicList'] as List + ..objectList = json['objectList'] as List + ..intList = (json['intList'] as List)?.map((e) => e as int)?.toList() + ..dateTimeList = (json['dateTimeList'] as List) + ?.map((e) => e == null ? null : DateTime.parse(e as String)) + ?.toList() + ..map = json['map'] as Map + ..stringStringMap = (json['stringStringMap'] as Map)?.map( + (k, e) => MapEntry(k, e as String), + ) + ..dynamicIntMap = (json['dynamicIntMap'] as Map)?.map( + (k, e) => MapEntry(k, e as int), + ) + ..objectDateTimeMap = + (json['objectDateTimeMap'] as Map)?.map( + (k, e) => MapEntry(k, e == null ? null : DateTime.parse(e as String)), + ) + ..crazyComplex = (json['crazyComplex'] as List) + ?.map((e) => (e as Map)?.map( + (k, e) => MapEntry( + k, + (e as Map)?.map( + (k, e) => MapEntry( + k, + (e as List) + ?.map((e) => (e as List) + ?.map((e) => e == null + ? null + : DateTime.parse(e as String)) + ?.toList()) + ?.toList()), + )), + )) + ?.toList() + ..val = (json['val'] as Map)?.map( + (k, e) => MapEntry(k, e as bool), + ) + ..writeNotNull = json['writeNotNull'] as bool + ..string = json[r'$string'] as String + ..simpleObject = json['simpleObject'] == null + ? null + : SimpleObject.fromJson(json['simpleObject'] as Map) + ..strictKeysObject = json['strictKeysObject'] == null + ? null + : StrictKeysObject.fromJson( + json['strictKeysObject'] as Map) + ..validatedPropertyNo42 = json['validatedPropertyNo42'] as int; +} + +Map _$KitchenSinkToJson(KitchenSink instance) => + _$KitchenSinkJsonMapWrapper(instance); + +class _$KitchenSinkJsonMapWrapper extends $JsonMapWrapper { + final KitchenSink _v; + _$KitchenSinkJsonMapWrapper(this._v); + + @override + Iterable get keys sync* { + if (_v.ctorValidatedNo42 != null) { + yield 'no-42'; + } + if (_v.dateTime != null) { + yield 'dateTime'; + } + if (_v.bigInt != null) { + yield 'bigInt'; + } + if (_v.iterable?.isNotEmpty ?? false) { + yield 'iterable'; + } + if (_v.dynamicIterable?.isNotEmpty ?? false) { + yield 'dynamicIterable'; + } + if (_v.objectIterable?.isNotEmpty ?? false) { + yield 'objectIterable'; + } + if (_v.intIterable?.isNotEmpty ?? false) { + yield 'intIterable'; + } + if (_v.set?.isNotEmpty ?? false) { + yield 'set'; + } + if (_v.dynamicSet?.isNotEmpty ?? false) { + yield 'dynamicSet'; + } + if (_v.objectSet?.isNotEmpty ?? false) { + yield 'objectSet'; + } + if (_v.intSet?.isNotEmpty ?? false) { + yield 'intSet'; + } + if (_v.dateTimeSet?.isNotEmpty ?? false) { + yield 'dateTimeSet'; + } + if (_v.dateTimeIterable?.isNotEmpty ?? false) { + yield 'datetime-iterable'; + } + if (_v.list?.isNotEmpty ?? false) { + yield 'list'; + } + if (_v.dynamicList?.isNotEmpty ?? false) { + yield 'dynamicList'; + } + if (_v.objectList?.isNotEmpty ?? false) { + yield 'objectList'; + } + if (_v.intList?.isNotEmpty ?? false) { + yield 'intList'; + } + if (_v.dateTimeList?.isNotEmpty ?? false) { + yield 'dateTimeList'; + } + if (_v.map?.isNotEmpty ?? false) { + yield 'map'; + } + if (_v.stringStringMap?.isNotEmpty ?? false) { + yield 'stringStringMap'; + } + if (_v.dynamicIntMap?.isNotEmpty ?? false) { + yield 'dynamicIntMap'; + } + if (_v.objectDateTimeMap?.isNotEmpty ?? false) { + yield 'objectDateTimeMap'; + } + if (_v.crazyComplex?.isNotEmpty ?? false) { + yield 'crazyComplex'; + } + if (_v.val?.isNotEmpty ?? false) { + yield 'val'; + } + if (_v.writeNotNull != null) { + yield 'writeNotNull'; + } + if (_v.string != null) { + yield r'$string'; + } + if (_v.simpleObject != null) { + yield 'simpleObject'; + } + if (_v.strictKeysObject != null) { + yield 'strictKeysObject'; + } + if (_v.validatedPropertyNo42 != null) { + yield 'validatedPropertyNo42'; + } + } + + @override + dynamic operator [](Object key) { + if (key is String) { + switch (key) { + case 'no-42': + return _v.ctorValidatedNo42; + case 'dateTime': + return _v.dateTime?.toIso8601String(); + case 'bigInt': + return _v.bigInt?.toString(); + case 'iterable': + return _$nullIfEmptyIterable(_v.iterable)?.toList(); + case 'dynamicIterable': + return _$nullIfEmptyIterable(_v.dynamicIterable)?.toList(); + case 'objectIterable': + return _$nullIfEmptyIterable(_v.objectIterable)?.toList(); + case 'intIterable': + return _$nullIfEmptyIterable(_v.intIterable)?.toList(); + case 'set': + return _$nullIfEmptyIterable(_v.set)?.toList(); + case 'dynamicSet': + return _$nullIfEmptyIterable(_v.dynamicSet)?.toList(); + case 'objectSet': + return _$nullIfEmptyIterable(_v.objectSet)?.toList(); + case 'intSet': + return _$nullIfEmptyIterable(_v.intSet)?.toList(); + case 'dateTimeSet': + return _$nullIfEmptyIterable(_v.dateTimeSet) + ?.map((e) => e?.toIso8601String()) + ?.toList(); + case 'datetime-iterable': + return _$nullIfEmptyIterable(_v.dateTimeIterable) + ?.map((e) => e?.toIso8601String()) + ?.toList(); + case 'list': + return _$nullIfEmptyIterable(_v.list); + case 'dynamicList': + return _$nullIfEmptyIterable(_v.dynamicList); + case 'objectList': + return _$nullIfEmptyIterable(_v.objectList); + case 'intList': + return _$nullIfEmptyIterable(_v.intList); + case 'dateTimeList': + return $wrapListHandleNull( + _$nullIfEmptyIterable(_v.dateTimeList), + (e) => e?.toIso8601String()); + case 'map': + return _$nullIfEmptyMap(_v.map); + case 'stringStringMap': + return _$nullIfEmptyMap(_v.stringStringMap); + case 'dynamicIntMap': + return _$nullIfEmptyMap(_v.dynamicIntMap); + case 'objectDateTimeMap': + return $wrapMapHandleNull( + _$nullIfEmptyMap(_v.objectDateTimeMap), + (e) => e?.toIso8601String()); + case 'crazyComplex': + return $wrapListHandleNull< + Map>>>>( + _$nullIfEmptyIterable(_v.crazyComplex), + (e) => + $wrapMapHandleNull>>>( + e, + (e) => $wrapMapHandleNull>>( + e, + (e) => $wrapListHandleNull>( + e, + (e) => $wrapListHandleNull( + e, (e) => e?.toIso8601String()))))); + case 'val': + return _$nullIfEmptyMap(_v.val); + case 'writeNotNull': + return _v.writeNotNull; + case r'$string': + return _v.string; + case 'simpleObject': + return _v.simpleObject; + case 'strictKeysObject': + return _v.strictKeysObject; + case 'validatedPropertyNo42': + return _v.validatedPropertyNo42; + } + } + return null; + } +} + +T _$nullIfEmptyIterable(T source) => + (source == null || source.isEmpty) ? null : source; + +T _$nullIfEmptyMap(T source) => + (source == null || source.isEmpty) ? null : source; + +JsonConverterTestClass _$JsonConverterTestClassFromJson( + Map json) { + return JsonConverterTestClass() + ..duration = json['duration'] == null + ? null + : durationConverter.fromJson(json['duration'] as int) + ..durationList = (json['durationList'] as List) + ?.map((e) => e == null ? null : durationConverter.fromJson(e as int)) + ?.toList() + ..bigInt = json['bigInt'] == null + ? null + : const BigIntStringConverter().fromJson(json['bigInt'] as String) + ..bigIntMap = (json['bigIntMap'] as Map)?.map( + (k, e) => MapEntry( + k, + e == null + ? null + : const BigIntStringConverter().fromJson(e as String)), + ) + ..numberSilly = json['numberSilly'] == null + ? null + : TrivialNumberConverter.instance.fromJson(json['numberSilly'] as int) + ..numberSillySet = (json['numberSillySet'] as List) + ?.map((e) => e == null + ? null + : TrivialNumberConverter.instance.fromJson(e as int)) + ?.toSet() + ..dateTime = json['dateTime'] == null + ? null + : const EpochDateTimeConverter().fromJson(json['dateTime'] as int); +} + +Map _$JsonConverterTestClassToJson( + JsonConverterTestClass instance) => + _$JsonConverterTestClassJsonMapWrapper(instance); + +class _$JsonConverterTestClassJsonMapWrapper extends $JsonMapWrapper { + final JsonConverterTestClass _v; + _$JsonConverterTestClassJsonMapWrapper(this._v); + + @override + Iterable get keys sync* { + if (_v.duration != null) { + yield 'duration'; + } + if (_v.durationList?.isNotEmpty ?? false) { + yield 'durationList'; + } + if (_v.bigInt != null) { + yield 'bigInt'; + } + if (_v.bigIntMap?.isNotEmpty ?? false) { + yield 'bigIntMap'; + } + if (_v.numberSilly != null) { + yield 'numberSilly'; + } + if (_v.numberSillySet?.isNotEmpty ?? false) { + yield 'numberSillySet'; + } + if (_v.dateTime != null) { + yield 'dateTime'; + } + } + + @override + dynamic operator [](Object key) { + if (key is String) { + switch (key) { + case 'duration': + return _v.duration == null + ? null + : durationConverter.toJson(_v.duration); + case 'durationList': + return $wrapListHandleNull( + _$nullIfEmptyIterable(_v.durationList), + (e) => e == null ? null : durationConverter.toJson(e)); + case 'bigInt': + return _v.bigInt == null + ? null + : const BigIntStringConverter().toJson(_v.bigInt); + case 'bigIntMap': + return $wrapMapHandleNull( + _$nullIfEmptyMap(_v.bigIntMap), + (e) => + e == null ? null : const BigIntStringConverter().toJson(e)); + case 'numberSilly': + return _v.numberSilly == null + ? null + : TrivialNumberConverter.instance.toJson(_v.numberSilly); + case 'numberSillySet': + return _$nullIfEmptyIterable(_v.numberSillySet) + ?.map((e) => + e == null ? null : TrivialNumberConverter.instance.toJson(e)) + ?.toList(); + case 'dateTime': + return _v.dateTime == null + ? null + : const EpochDateTimeConverter().toJson(_v.dateTime); + } + } + return null; + } +} + +JsonConverterGeneric _$JsonConverterGenericFromJson( + Map json) { + return JsonConverterGeneric() + ..item = json['item'] == null + ? null + : GenericConverter().fromJson(json['item'] as Map) + ..itemList = (json['itemList'] as List) + ?.map((e) => e == null + ? null + : GenericConverter().fromJson(e as Map)) + ?.toList() + ..itemMap = (json['itemMap'] as Map)?.map( + (k, e) => MapEntry( + k, + e == null + ? null + : GenericConverter().fromJson(e as Map)), + ); +} + +Map _$JsonConverterGenericToJson( + JsonConverterGeneric instance) => + _$JsonConverterGenericJsonMapWrapper(instance); + +class _$JsonConverterGenericJsonMapWrapper extends $JsonMapWrapper { + final JsonConverterGeneric _v; + _$JsonConverterGenericJsonMapWrapper(this._v); + + @override + Iterable get keys sync* { + if (_v.item != null) { + yield 'item'; + } + if (_v.itemList?.isNotEmpty ?? false) { + yield 'itemList'; + } + if (_v.itemMap?.isNotEmpty ?? false) { + yield 'itemMap'; + } + } + + @override + dynamic operator [](Object key) { + if (key is String) { + switch (key) { + case 'item': + return _v.item == null ? null : GenericConverter().toJson(_v.item); + case 'itemList': + return $wrapListHandleNull(_$nullIfEmptyIterable(_v.itemList), + (e) => e == null ? null : GenericConverter().toJson(e)); + case 'itemMap': + return $wrapMapHandleNull(_$nullIfEmptyMap(_v.itemMap), + (e) => e == null ? null : GenericConverter().toJson(e)); + } + } + return null; + } +} diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__non_nullable.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__non_nullable.dart index 6753d04c5..282421e85 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__non_nullable.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__non_nullable.dart @@ -31,6 +31,7 @@ class _Factory implements k.KitchenSinkFactory { bool get nullable => false; bool get excludeNull => true; bool get explicitToJson => false; + bool get noEncodeEmpty => false; k.KitchenSink ctor({ int ctorValidatedNo42, diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__use_wrappers.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__use_wrappers.dart index 9430d2974..d41e8da94 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__use_wrappers.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__use_wrappers.dart @@ -31,6 +31,7 @@ class _Factory implements k.KitchenSinkFactory { bool get nullable => true; bool get excludeNull => true; bool get explicitToJson => false; + bool get noEncodeEmpty => false; k.KitchenSink ctor({ int ctorValidatedNo42, diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.dart index 5a4fbeb20..7de661d43 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.dart @@ -31,6 +31,7 @@ class _Factory implements k.KitchenSinkFactory { bool get nullable => true; bool get excludeNull => false; bool get explicitToJson => true; + bool get noEncodeEmpty => false; k.KitchenSink ctor({ int ctorValidatedNo42, diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_no_encode_empty.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_no_encode_empty.dart new file mode 100644 index 000000000..ff8759979 --- /dev/null +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_no_encode_empty.dart @@ -0,0 +1,200 @@ +// Copyright (c) 2018, 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. + +// ignore_for_file: annotate_overrides, hash_and_equals +import 'package:json_annotation/json_annotation.dart'; + +import 'json_converters.dart'; +import 'kitchen_sink_interface.dart' as k; +import 'simple_object.dart'; +import 'strict_keys_object.dart'; + +part 'kitchen_sink.g_no_encode_empty.g.dart'; + +// NOTE: these methods are replaced in the `non_nullable` cases to return +// non-null values. +List _defaultList() => null; +Set _defaultSet() => null; +Map _defaultMap() => null; +SimpleObject _defaultSimpleObject() => null; +StrictKeysObject _defaultStrictKeysObject() => null; + +const k.KitchenSinkFactory factory = _Factory(); + +class _Factory implements k.KitchenSinkFactory { + const _Factory(); + + String get description => 'no_encode_empty'; + bool get anyMap => false; + bool get checked => false; + bool get nullable => true; + bool get excludeNull => false; + bool get explicitToJson => false; + bool get noEncodeEmpty => true; + + k.KitchenSink ctor({ + int ctorValidatedNo42, + Iterable iterable, + Iterable dynamicIterable, + Iterable objectIterable, + Iterable intIterable, + Iterable dateTimeIterable, + }) => + KitchenSink( + ctorValidatedNo42: ctorValidatedNo42, + iterable: iterable, + dynamicIterable: dynamicIterable, + objectIterable: objectIterable, + intIterable: intIterable, + dateTimeIterable: dateTimeIterable, + ); + + k.KitchenSink fromJson(Map json) => + KitchenSink.fromJson(json); + + k.JsonConverterTestClass jsonConverterCtor() => JsonConverterTestClass(); + + k.JsonConverterTestClass jsonConverterFromJson(Map json) => + JsonConverterTestClass.fromJson(json); +} + +@JsonSerializable( + encodeEmptyCollection: false, +) +class KitchenSink implements k.KitchenSink { + // NOTE: exposing these as Iterable, but storing the values as List + // to make the equality test work trivially. + final Iterable _iterable; + final Iterable _dynamicIterable; + final Iterable _objectIterable; + final Iterable _intIterable; + final Iterable _dateTimeIterable; + + @JsonKey(name: 'no-42') + final int ctorValidatedNo42; + + KitchenSink({ + this.ctorValidatedNo42, + Iterable iterable, + Iterable dynamicIterable, + Iterable objectIterable, + Iterable intIterable, + Iterable dateTimeIterable, + }) : _iterable = iterable?.toList() ?? _defaultList(), + _dynamicIterable = dynamicIterable?.toList() ?? _defaultList(), + _objectIterable = objectIterable?.toList() ?? _defaultList(), + _intIterable = intIterable?.toList() ?? _defaultList(), + _dateTimeIterable = dateTimeIterable?.toList() ?? _defaultList() { + if (ctorValidatedNo42 == 42) { + throw ArgumentError.value( + 42, 'ctorValidatedNo42', 'The value `42` is not allowed.'); + } + } + + factory KitchenSink.fromJson(Map json) => + _$KitchenSinkFromJson(json); + + Map toJson() => _$KitchenSinkToJson(this); + + DateTime dateTime; + + BigInt bigInt; + + Iterable get iterable => _iterable; + Iterable get dynamicIterable => _dynamicIterable; + Iterable get objectIterable => _objectIterable; + Iterable get intIterable => _intIterable; + + Set set = _defaultSet(); + Set dynamicSet = _defaultSet(); + Set objectSet = _defaultSet(); + Set intSet = _defaultSet(); + Set dateTimeSet = _defaultSet(); + + // Added a one-off annotation on a property (not a field) + @JsonKey(name: 'datetime-iterable') + Iterable get dateTimeIterable => _dateTimeIterable; + + List list = _defaultList(); + List dynamicList = _defaultList(); + List objectList = _defaultList(); + List intList = _defaultList(); + List dateTimeList = _defaultList(); + + Map map = _defaultMap(); + Map stringStringMap = _defaultMap(); + Map dynamicIntMap = _defaultMap(); + Map objectDateTimeMap = _defaultMap(); + + List>>>> crazyComplex = + _defaultList(); + + // Handle fields with names that collide with helper names + Map val = _defaultMap(); + bool writeNotNull; + @JsonKey(name: r'$string') + String string; + + SimpleObject simpleObject = _defaultSimpleObject(); + + StrictKeysObject strictKeysObject = _defaultStrictKeysObject(); + + int _validatedPropertyNo42; + int get validatedPropertyNo42 => _validatedPropertyNo42; + + set validatedPropertyNo42(int value) { + if (value == 42) { + throw StateError('Cannot be 42!'); + } + _validatedPropertyNo42 = value; + } + + bool operator ==(Object other) => k.sinkEquals(this, other); +} + +@JsonSerializable( + encodeEmptyCollection: false, +) +// referencing a top-level field should work +@durationConverter +// referencing via a const constructor should work +@BigIntStringConverter() +@TrivialNumberConverter.instance +@EpochDateTimeConverter() +class JsonConverterTestClass implements k.JsonConverterTestClass { + JsonConverterTestClass(); + + factory JsonConverterTestClass.fromJson(Map json) => + _$JsonConverterTestClassFromJson(json); + + Map toJson() => _$JsonConverterTestClassToJson(this); + + Duration duration; + List durationList; + + BigInt bigInt; + Map bigIntMap; + + TrivialNumber numberSilly; + Set numberSillySet; + + DateTime dateTime; +} + +@JsonSerializable( + encodeEmptyCollection: false, +) +@GenericConverter() +class JsonConverterGeneric { + S item; + List itemList; + Map itemMap; + + JsonConverterGeneric(); + + factory JsonConverterGeneric.fromJson(Map json) => + _$JsonConverterGenericFromJson(json); + + Map toJson() => _$JsonConverterGenericToJson(this); +} diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_no_encode_empty.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_no_encode_empty.g.dart new file mode 100644 index 000000000..3c6534656 --- /dev/null +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_no_encode_empty.g.dart @@ -0,0 +1,276 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'kitchen_sink.g_no_encode_empty.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +KitchenSink _$KitchenSinkFromJson(Map json) { + return KitchenSink( + ctorValidatedNo42: json['no-42'] as int, + iterable: json['iterable'] as List, + dynamicIterable: json['dynamicIterable'] as List, + objectIterable: json['objectIterable'] as List, + intIterable: (json['intIterable'] as List)?.map((e) => e as int), + dateTimeIterable: (json['datetime-iterable'] as List) + ?.map((e) => e == null ? null : DateTime.parse(e as String))) + ..dateTime = json['dateTime'] == null + ? null + : DateTime.parse(json['dateTime'] as String) + ..bigInt = + json['bigInt'] == null ? null : BigInt.parse(json['bigInt'] as String) + ..set = (json['set'] as List)?.toSet() + ..dynamicSet = (json['dynamicSet'] as List)?.toSet() + ..objectSet = (json['objectSet'] as List)?.toSet() + ..intSet = (json['intSet'] as List)?.map((e) => e as int)?.toSet() + ..dateTimeSet = (json['dateTimeSet'] as List) + ?.map((e) => e == null ? null : DateTime.parse(e as String)) + ?.toSet() + ..list = json['list'] as List + ..dynamicList = json['dynamicList'] as List + ..objectList = json['objectList'] as List + ..intList = (json['intList'] as List)?.map((e) => e as int)?.toList() + ..dateTimeList = (json['dateTimeList'] as List) + ?.map((e) => e == null ? null : DateTime.parse(e as String)) + ?.toList() + ..map = json['map'] as Map + ..stringStringMap = (json['stringStringMap'] as Map)?.map( + (k, e) => MapEntry(k, e as String), + ) + ..dynamicIntMap = (json['dynamicIntMap'] as Map)?.map( + (k, e) => MapEntry(k, e as int), + ) + ..objectDateTimeMap = + (json['objectDateTimeMap'] as Map)?.map( + (k, e) => MapEntry(k, e == null ? null : DateTime.parse(e as String)), + ) + ..crazyComplex = (json['crazyComplex'] as List) + ?.map((e) => (e as Map)?.map( + (k, e) => MapEntry( + k, + (e as Map)?.map( + (k, e) => MapEntry( + k, + (e as List) + ?.map((e) => (e as List) + ?.map((e) => e == null + ? null + : DateTime.parse(e as String)) + ?.toList()) + ?.toList()), + )), + )) + ?.toList() + ..val = (json['val'] as Map)?.map( + (k, e) => MapEntry(k, e as bool), + ) + ..writeNotNull = json['writeNotNull'] as bool + ..string = json[r'$string'] as String + ..simpleObject = json['simpleObject'] == null + ? null + : SimpleObject.fromJson(json['simpleObject'] as Map) + ..strictKeysObject = json['strictKeysObject'] == null + ? null + : StrictKeysObject.fromJson( + json['strictKeysObject'] as Map) + ..validatedPropertyNo42 = json['validatedPropertyNo42'] as int; +} + +Map _$KitchenSinkToJson(KitchenSink instance) { + final val = { + 'no-42': instance.ctorValidatedNo42, + 'dateTime': instance.dateTime?.toIso8601String(), + 'bigInt': instance.bigInt?.toString(), + }; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('iterable', _$nullIfEmptyIterable(instance.iterable)?.toList()); + writeNotNull('dynamicIterable', + _$nullIfEmptyIterable(instance.dynamicIterable)?.toList()); + writeNotNull('objectIterable', + _$nullIfEmptyIterable(instance.objectIterable)?.toList()); + writeNotNull( + 'intIterable', _$nullIfEmptyIterable(instance.intIterable)?.toList()); + writeNotNull('set', _$nullIfEmptyIterable(instance.set)?.toList()); + writeNotNull( + 'dynamicSet', _$nullIfEmptyIterable(instance.dynamicSet)?.toList()); + writeNotNull( + 'objectSet', _$nullIfEmptyIterable(instance.objectSet)?.toList()); + writeNotNull('intSet', _$nullIfEmptyIterable(instance.intSet)?.toList()); + writeNotNull( + 'dateTimeSet', + _$nullIfEmptyIterable(instance.dateTimeSet) + ?.map((e) => e?.toIso8601String()) + ?.toList()); + writeNotNull( + 'datetime-iterable', + _$nullIfEmptyIterable(instance.dateTimeIterable) + ?.map((e) => e?.toIso8601String()) + ?.toList()); + writeNotNull('list', _$nullIfEmptyIterable(instance.list)); + writeNotNull('dynamicList', _$nullIfEmptyIterable(instance.dynamicList)); + writeNotNull('objectList', _$nullIfEmptyIterable(instance.objectList)); + writeNotNull('intList', _$nullIfEmptyIterable(instance.intList)); + writeNotNull( + 'dateTimeList', + _$nullIfEmptyIterable(instance.dateTimeList) + ?.map((e) => e?.toIso8601String()) + ?.toList()); + writeNotNull('map', _$nullIfEmptyMap(instance.map)); + writeNotNull('stringStringMap', _$nullIfEmptyMap(instance.stringStringMap)); + writeNotNull('dynamicIntMap', _$nullIfEmptyMap(instance.dynamicIntMap)); + writeNotNull( + 'objectDateTimeMap', + _$nullIfEmptyMap(instance.objectDateTimeMap) + ?.map((k, e) => MapEntry(k, e?.toIso8601String()))); + writeNotNull( + 'crazyComplex', + _$nullIfEmptyIterable(instance.crazyComplex) + ?.map((e) => e?.map((k, e) => MapEntry( + k, + e?.map((k, e) => MapEntry( + k, + e + ?.map( + (e) => e?.map((e) => e?.toIso8601String())?.toList()) + ?.toList()))))) + ?.toList()); + writeNotNull('val', _$nullIfEmptyMap(instance.val)); + val['writeNotNull'] = instance.writeNotNull; + val[r'$string'] = instance.string; + val['simpleObject'] = instance.simpleObject; + val['strictKeysObject'] = instance.strictKeysObject; + val['validatedPropertyNo42'] = instance.validatedPropertyNo42; + return val; +} + +T _$nullIfEmptyIterable(T source) => + (source == null || source.isEmpty) ? null : source; + +T _$nullIfEmptyMap(T source) => + (source == null || source.isEmpty) ? null : source; + +JsonConverterTestClass _$JsonConverterTestClassFromJson( + Map json) { + return JsonConverterTestClass() + ..duration = json['duration'] == null + ? null + : durationConverter.fromJson(json['duration'] as int) + ..durationList = (json['durationList'] as List) + ?.map((e) => e == null ? null : durationConverter.fromJson(e as int)) + ?.toList() + ..bigInt = json['bigInt'] == null + ? null + : const BigIntStringConverter().fromJson(json['bigInt'] as String) + ..bigIntMap = (json['bigIntMap'] as Map)?.map( + (k, e) => MapEntry( + k, + e == null + ? null + : const BigIntStringConverter().fromJson(e as String)), + ) + ..numberSilly = json['numberSilly'] == null + ? null + : TrivialNumberConverter.instance.fromJson(json['numberSilly'] as int) + ..numberSillySet = (json['numberSillySet'] as List) + ?.map((e) => e == null + ? null + : TrivialNumberConverter.instance.fromJson(e as int)) + ?.toSet() + ..dateTime = json['dateTime'] == null + ? null + : const EpochDateTimeConverter().fromJson(json['dateTime'] as int); +} + +Map _$JsonConverterTestClassToJson( + JsonConverterTestClass instance) { + final val = { + 'duration': instance.duration == null + ? null + : durationConverter.toJson(instance.duration), + }; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull( + 'durationList', + _$nullIfEmptyIterable(instance.durationList) + ?.map((e) => e == null ? null : durationConverter.toJson(e)) + ?.toList()); + val['bigInt'] = instance.bigInt == null + ? null + : const BigIntStringConverter().toJson(instance.bigInt); + writeNotNull( + 'bigIntMap', + _$nullIfEmptyMap(instance.bigIntMap)?.map((k, e) => MapEntry( + k, e == null ? null : const BigIntStringConverter().toJson(e)))); + val['numberSilly'] = instance.numberSilly == null + ? null + : TrivialNumberConverter.instance.toJson(instance.numberSilly); + writeNotNull( + 'numberSillySet', + _$nullIfEmptyIterable(instance.numberSillySet) + ?.map((e) => + e == null ? null : TrivialNumberConverter.instance.toJson(e)) + ?.toList()); + val['dateTime'] = instance.dateTime == null + ? null + : const EpochDateTimeConverter().toJson(instance.dateTime); + return val; +} + +JsonConverterGeneric _$JsonConverterGenericFromJson( + Map json) { + return JsonConverterGeneric() + ..item = json['item'] == null + ? null + : GenericConverter().fromJson(json['item'] as Map) + ..itemList = (json['itemList'] as List) + ?.map((e) => e == null + ? null + : GenericConverter().fromJson(e as Map)) + ?.toList() + ..itemMap = (json['itemMap'] as Map)?.map( + (k, e) => MapEntry( + k, + e == null + ? null + : GenericConverter().fromJson(e as Map)), + ); +} + +Map _$JsonConverterGenericToJson( + JsonConverterGeneric instance) { + final val = { + 'item': instance.item == null + ? null + : GenericConverter().toJson(instance.item), + }; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull( + 'itemList', + _$nullIfEmptyIterable(instance.itemList) + ?.map((e) => e == null ? null : GenericConverter().toJson(e)) + ?.toList()); + writeNotNull( + 'itemMap', + _$nullIfEmptyMap(instance.itemMap)?.map((k, e) => + MapEntry(k, e == null ? null : GenericConverter().toJson(e)))); + return val; +} diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_no_encode_empty__non_nullable.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_no_encode_empty__non_nullable.dart new file mode 100644 index 000000000..aa2e6924c --- /dev/null +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_no_encode_empty__non_nullable.dart @@ -0,0 +1,203 @@ +// Copyright (c) 2018, 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. + +// ignore_for_file: annotate_overrides, hash_and_equals +import 'package:json_annotation/json_annotation.dart'; + +import 'json_converters.dart'; +import 'kitchen_sink_interface.dart' as k; +import 'simple_object.dart'; +import 'strict_keys_object.dart'; + +part 'kitchen_sink.g_no_encode_empty__non_nullable.g.dart'; + +// NOTE: these methods are replaced in the `non_nullable` cases to return +// non-null values. +List _defaultList() => []; +Set _defaultSet() => Set(); +Map _defaultMap() => {}; +SimpleObject _defaultSimpleObject() => SimpleObject(42); +StrictKeysObject _defaultStrictKeysObject() => StrictKeysObject(10, 'cool'); + +const k.KitchenSinkFactory factory = _Factory(); + +class _Factory implements k.KitchenSinkFactory { + const _Factory(); + + String get description => 'no_encode_empty__non_nullable'; + bool get anyMap => false; + bool get checked => false; + bool get nullable => false; + bool get excludeNull => false; + bool get explicitToJson => false; + bool get noEncodeEmpty => true; + + k.KitchenSink ctor({ + int ctorValidatedNo42, + Iterable iterable, + Iterable dynamicIterable, + Iterable objectIterable, + Iterable intIterable, + Iterable dateTimeIterable, + }) => + KitchenSink( + ctorValidatedNo42: ctorValidatedNo42, + iterable: iterable, + dynamicIterable: dynamicIterable, + objectIterable: objectIterable, + intIterable: intIterable, + dateTimeIterable: dateTimeIterable, + ); + + k.KitchenSink fromJson(Map json) => + KitchenSink.fromJson(json); + + k.JsonConverterTestClass jsonConverterCtor() => JsonConverterTestClass(); + + k.JsonConverterTestClass jsonConverterFromJson(Map json) => + JsonConverterTestClass.fromJson(json); +} + +@JsonSerializable( + nullable: false, + encodeEmptyCollection: false, +) +class KitchenSink implements k.KitchenSink { + // NOTE: exposing these as Iterable, but storing the values as List + // to make the equality test work trivially. + final Iterable _iterable; + final Iterable _dynamicIterable; + final Iterable _objectIterable; + final Iterable _intIterable; + final Iterable _dateTimeIterable; + + @JsonKey(name: 'no-42') + final int ctorValidatedNo42; + + KitchenSink({ + this.ctorValidatedNo42, + Iterable iterable, + Iterable dynamicIterable, + Iterable objectIterable, + Iterable intIterable, + Iterable dateTimeIterable, + }) : _iterable = iterable?.toList() ?? _defaultList(), + _dynamicIterable = dynamicIterable?.toList() ?? _defaultList(), + _objectIterable = objectIterable?.toList() ?? _defaultList(), + _intIterable = intIterable?.toList() ?? _defaultList(), + _dateTimeIterable = dateTimeIterable?.toList() ?? _defaultList() { + if (ctorValidatedNo42 == 42) { + throw ArgumentError.value( + 42, 'ctorValidatedNo42', 'The value `42` is not allowed.'); + } + } + + factory KitchenSink.fromJson(Map json) => + _$KitchenSinkFromJson(json); + + Map toJson() => _$KitchenSinkToJson(this); + + DateTime dateTime = DateTime(1981, 6, 5); + + BigInt bigInt = BigInt.parse('10000000000000000000'); + + Iterable get iterable => _iterable; + Iterable get dynamicIterable => _dynamicIterable; + Iterable get objectIterable => _objectIterable; + Iterable get intIterable => _intIterable; + + Set set = _defaultSet(); + Set dynamicSet = _defaultSet(); + Set objectSet = _defaultSet(); + Set intSet = _defaultSet(); + Set dateTimeSet = _defaultSet(); + + // Added a one-off annotation on a property (not a field) + @JsonKey(name: 'datetime-iterable') + Iterable get dateTimeIterable => _dateTimeIterable; + + List list = _defaultList(); + List dynamicList = _defaultList(); + List objectList = _defaultList(); + List intList = _defaultList(); + List dateTimeList = _defaultList(); + + Map map = _defaultMap(); + Map stringStringMap = _defaultMap(); + Map dynamicIntMap = _defaultMap(); + Map objectDateTimeMap = _defaultMap(); + + List>>>> crazyComplex = + _defaultList(); + + // Handle fields with names that collide with helper names + Map val = _defaultMap(); + bool writeNotNull; + @JsonKey(name: r'$string') + String string; + + SimpleObject simpleObject = _defaultSimpleObject(); + + StrictKeysObject strictKeysObject = _defaultStrictKeysObject(); + + int _validatedPropertyNo42; + int get validatedPropertyNo42 => _validatedPropertyNo42; + + set validatedPropertyNo42(int value) { + if (value == 42) { + throw StateError('Cannot be 42!'); + } + _validatedPropertyNo42 = value; + } + + bool operator ==(Object other) => k.sinkEquals(this, other); +} + +@JsonSerializable( + nullable: false, + encodeEmptyCollection: false, +) +// referencing a top-level field should work +@durationConverter +// referencing via a const constructor should work +@BigIntStringConverter() +@TrivialNumberConverter.instance +@EpochDateTimeConverter() +class JsonConverterTestClass implements k.JsonConverterTestClass { + JsonConverterTestClass(); + + factory JsonConverterTestClass.fromJson(Map json) => + _$JsonConverterTestClassFromJson(json); + + Map toJson() => _$JsonConverterTestClassToJson(this); + + Duration duration; + List durationList; + + BigInt bigInt = BigInt.parse('10000000000000000000'); + Map bigIntMap; + + TrivialNumber numberSilly; + Set numberSillySet; + + DateTime dateTime = DateTime(1981, 6, 5); +} + +@JsonSerializable( + nullable: false, + encodeEmptyCollection: false, +) +@GenericConverter() +class JsonConverterGeneric { + S item; + List itemList; + Map itemMap; + + JsonConverterGeneric(); + + factory JsonConverterGeneric.fromJson(Map json) => + _$JsonConverterGenericFromJson(json); + + Map toJson() => _$JsonConverterGenericToJson(this); +} diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_no_encode_empty__non_nullable.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_no_encode_empty__non_nullable.g.dart new file mode 100644 index 000000000..5bdfb5b63 --- /dev/null +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_no_encode_empty__non_nullable.g.dart @@ -0,0 +1,234 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'kitchen_sink.g_no_encode_empty__non_nullable.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +KitchenSink _$KitchenSinkFromJson(Map json) { + return KitchenSink( + ctorValidatedNo42: json['no-42'] as int, + iterable: json['iterable'] as List, + dynamicIterable: json['dynamicIterable'] as List, + objectIterable: json['objectIterable'] as List, + intIterable: (json['intIterable'] as List).map((e) => e as int), + dateTimeIterable: (json['datetime-iterable'] as List) + .map((e) => DateTime.parse(e as String))) + ..dateTime = DateTime.parse(json['dateTime'] as String) + ..bigInt = BigInt.parse(json['bigInt'] as String) + ..set = (json['set'] as List).toSet() + ..dynamicSet = (json['dynamicSet'] as List).toSet() + ..objectSet = (json['objectSet'] as List).toSet() + ..intSet = (json['intSet'] as List).map((e) => e as int).toSet() + ..dateTimeSet = (json['dateTimeSet'] as List) + .map((e) => DateTime.parse(e as String)) + .toSet() + ..list = json['list'] as List + ..dynamicList = json['dynamicList'] as List + ..objectList = json['objectList'] as List + ..intList = (json['intList'] as List).map((e) => e as int).toList() + ..dateTimeList = (json['dateTimeList'] as List) + .map((e) => DateTime.parse(e as String)) + .toList() + ..map = json['map'] as Map + ..stringStringMap = Map.from(json['stringStringMap'] as Map) + ..dynamicIntMap = Map.from(json['dynamicIntMap'] as Map) + ..objectDateTimeMap = + (json['objectDateTimeMap'] as Map).map( + (k, e) => MapEntry(k, DateTime.parse(e as String)), + ) + ..crazyComplex = (json['crazyComplex'] as List) + .map((e) => (e as Map).map( + (k, e) => MapEntry( + k, + (e as Map).map( + (k, e) => MapEntry( + k, + (e as List) + .map((e) => (e as List) + .map((e) => DateTime.parse(e as String)) + .toList()) + .toList()), + )), + )) + .toList() + ..val = Map.from(json['val'] as Map) + ..writeNotNull = json['writeNotNull'] as bool + ..string = json[r'$string'] as String + ..simpleObject = + SimpleObject.fromJson(json['simpleObject'] as Map) + ..strictKeysObject = StrictKeysObject.fromJson( + json['strictKeysObject'] as Map) + ..validatedPropertyNo42 = json['validatedPropertyNo42'] as int; +} + +Map _$KitchenSinkToJson(KitchenSink instance) { + final val = { + 'no-42': instance.ctorValidatedNo42, + 'dateTime': instance.dateTime.toIso8601String(), + 'bigInt': instance.bigInt.toString(), + }; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('iterable', _$nullIfEmptyIterable(instance.iterable)?.toList()); + writeNotNull('dynamicIterable', + _$nullIfEmptyIterable(instance.dynamicIterable)?.toList()); + writeNotNull('objectIterable', + _$nullIfEmptyIterable(instance.objectIterable)?.toList()); + writeNotNull( + 'intIterable', _$nullIfEmptyIterable(instance.intIterable)?.toList()); + writeNotNull('set', _$nullIfEmptyIterable(instance.set)?.toList()); + writeNotNull( + 'dynamicSet', _$nullIfEmptyIterable(instance.dynamicSet)?.toList()); + writeNotNull( + 'objectSet', _$nullIfEmptyIterable(instance.objectSet)?.toList()); + writeNotNull('intSet', _$nullIfEmptyIterable(instance.intSet)?.toList()); + writeNotNull( + 'dateTimeSet', + _$nullIfEmptyIterable(instance.dateTimeSet) + ?.map((e) => e.toIso8601String()) + ?.toList()); + writeNotNull( + 'datetime-iterable', + _$nullIfEmptyIterable(instance.dateTimeIterable) + ?.map((e) => e.toIso8601String()) + ?.toList()); + writeNotNull('list', _$nullIfEmptyIterable(instance.list)); + writeNotNull('dynamicList', _$nullIfEmptyIterable(instance.dynamicList)); + writeNotNull('objectList', _$nullIfEmptyIterable(instance.objectList)); + writeNotNull('intList', _$nullIfEmptyIterable(instance.intList)); + writeNotNull( + 'dateTimeList', + _$nullIfEmptyIterable(instance.dateTimeList) + ?.map((e) => e.toIso8601String()) + ?.toList()); + writeNotNull('map', _$nullIfEmptyMap(instance.map)); + writeNotNull('stringStringMap', _$nullIfEmptyMap(instance.stringStringMap)); + writeNotNull('dynamicIntMap', _$nullIfEmptyMap(instance.dynamicIntMap)); + writeNotNull( + 'objectDateTimeMap', + _$nullIfEmptyMap(instance.objectDateTimeMap) + ?.map((k, e) => MapEntry(k, e.toIso8601String()))); + writeNotNull( + 'crazyComplex', + _$nullIfEmptyIterable(instance.crazyComplex) + ?.map((e) => e.map((k, e) => MapEntry( + k, + e.map((k, e) => MapEntry( + k, + e + .map((e) => e.map((e) => e.toIso8601String()).toList()) + .toList()))))) + ?.toList()); + writeNotNull('val', _$nullIfEmptyMap(instance.val)); + val['writeNotNull'] = instance.writeNotNull; + val[r'$string'] = instance.string; + val['simpleObject'] = instance.simpleObject; + val['strictKeysObject'] = instance.strictKeysObject; + val['validatedPropertyNo42'] = instance.validatedPropertyNo42; + return val; +} + +T _$nullIfEmptyIterable(T source) => + (source == null || source.isEmpty) ? null : source; + +T _$nullIfEmptyMap(T source) => + (source == null || source.isEmpty) ? null : source; + +JsonConverterTestClass _$JsonConverterTestClassFromJson( + Map json) { + return JsonConverterTestClass() + ..duration = durationConverter.fromJson(json['duration'] as int) + ..durationList = (json['durationList'] as List) + .map((e) => durationConverter.fromJson(e as int)) + .toList() + ..bigInt = const BigIntStringConverter().fromJson(json['bigInt'] as String) + ..bigIntMap = (json['bigIntMap'] as Map).map( + (k, e) => + MapEntry(k, const BigIntStringConverter().fromJson(e as String)), + ) + ..numberSilly = + TrivialNumberConverter.instance.fromJson(json['numberSilly'] as int) + ..numberSillySet = (json['numberSillySet'] as List) + .map((e) => TrivialNumberConverter.instance.fromJson(e as int)) + .toSet() + ..dateTime = + const EpochDateTimeConverter().fromJson(json['dateTime'] as int); +} + +Map _$JsonConverterTestClassToJson( + JsonConverterTestClass instance) { + final val = { + 'duration': durationConverter.toJson(instance.duration), + }; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull( + 'durationList', + _$nullIfEmptyIterable(instance.durationList) + ?.map(durationConverter.toJson) + ?.toList()); + val['bigInt'] = const BigIntStringConverter().toJson(instance.bigInt); + writeNotNull( + 'bigIntMap', + _$nullIfEmptyMap(instance.bigIntMap)?.map( + (k, e) => MapEntry(k, const BigIntStringConverter().toJson(e)))); + val['numberSilly'] = + TrivialNumberConverter.instance.toJson(instance.numberSilly); + writeNotNull( + 'numberSillySet', + _$nullIfEmptyIterable(instance.numberSillySet) + ?.map(TrivialNumberConverter.instance.toJson) + ?.toList()); + val['dateTime'] = const EpochDateTimeConverter().toJson(instance.dateTime); + return val; +} + +JsonConverterGeneric _$JsonConverterGenericFromJson( + Map json) { + return JsonConverterGeneric() + ..item = + GenericConverter().fromJson(json['item'] as Map) + ..itemList = (json['itemList'] as List) + .map((e) => GenericConverter().fromJson(e as Map)) + .toList() + ..itemMap = (json['itemMap'] as Map).map( + (k, e) => MapEntry( + k, GenericConverter().fromJson(e as Map)), + ); +} + +Map _$JsonConverterGenericToJson( + JsonConverterGeneric instance) { + final val = { + 'item': GenericConverter().toJson(instance.item), + }; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull( + 'itemList', + _$nullIfEmptyIterable(instance.itemList) + ?.map(GenericConverter().toJson) + ?.toList()); + writeNotNull( + 'itemMap', + _$nullIfEmptyMap(instance.itemMap) + ?.map((k, e) => MapEntry(k, GenericConverter().toJson(e)))); + return val; +} diff --git a/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart b/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart index 28f1b4a2e..77abe60ee 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart @@ -12,6 +12,7 @@ abstract class KitchenSinkFactory { bool get nullable; bool get excludeNull; bool get explicitToJson; + bool get noEncodeEmpty; KitchenSink ctor({ int ctorValidatedNo42, diff --git a/json_serializable/test/kitchen_sink/kitchen_sink_test.dart b/json_serializable/test/kitchen_sink/kitchen_sink_test.dart index 61e5562ae..e3ec1f476 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink_test.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink_test.dart @@ -55,11 +55,10 @@ void main() { } else { _nonNullableTests(factory); } - - _sharedTests(factory); if (factory.anyMap) { _anyMapTests(factory); } + _sharedTests(factory); }); } } @@ -75,19 +74,21 @@ const _jsonConverterValidValues = { }; void _nonNullableTests(KitchenSinkFactory factory) { - test('with null values fails serialization', () { - expect(() => (factory.ctor()..objectDateTimeMap = null).toJson(), - throwsNoSuchMethodError); - }); + if (!factory.noEncodeEmpty) { + test('with null values fails serialization', () { + expect(() => (factory.ctor()..objectDateTimeMap = null).toJson(), + throwsNoSuchMethodError); + }); + } test('with empty json fails deserialization', () { + Matcher matcher; if (factory.checked) { - expect(() => factory.fromJson({}), - throwsA(_checkedMatcher('intIterable'))); + matcher = _checkedMatcher('intIterable'); } else { - expect( - () => factory.fromJson({}), throwsNoSuchMethodError); + matcher = isNoSuchMethodError; } + expect(() => factory.fromJson({}), throwsA(matcher)); }); test('nullable values are not allowed in non-nullable version', () { @@ -107,7 +108,8 @@ void _nonNullableTests(KitchenSinkFactory factory) { void _nullableTests(KitchenSinkFactory factory) { void roundTripSink(KitchenSink p) { - roundTripObject(p, factory.fromJson); + roundTripObject(p, factory.fromJson, + skipObjectEquals: factory.noEncodeEmpty); } test('nullable values are allowed in the nullable version', () { @@ -116,6 +118,9 @@ void _nullableTests(KitchenSinkFactory factory) { if (factory.excludeNull) { expect(json, isEmpty); + } else if (factory.noEncodeEmpty) { + expect(json.keys, + _jsonConverterValidValues.keys.toSet()..removeAll(_iterableMapKeys)); } else { expect(json.values, everyElement(isNull)); expect(json.keys, unorderedEquals(_jsonConverterValidValues.keys)); @@ -131,6 +136,8 @@ void _nullableTests(KitchenSinkFactory factory) { if (factory.excludeNull) { expect(encoded, isEmpty); + } else if (factory.noEncodeEmpty) { + expect(encoded.keys, _validValueMinusIterableMapKeys); } else { expect(encoded.keys, orderedEquals(_validValues.keys)); @@ -190,46 +197,70 @@ void _anyMapTests(KitchenSinkFactory factory) { } void _sharedTests(KitchenSinkFactory factory) { - void roundTripSink(KitchenSink p) { - roundTripObject(p, factory.fromJson); - } + if (factory.noEncodeEmpty && !factory.nullable) { + test('empty collections throw errors on round-trip', () { + final item = factory.ctor(); + expect(() => factory.fromJson(item.toJson()), throwsNoSuchMethodError); + }); + } else { + test('empty', () { + final item = factory.ctor(); + roundTripObject(item, factory.fromJson); + }); - test('empty', () { - final item = factory.ctor(); - roundTripSink(item); - }); + test('list and map of DateTime - not null', () { + final now = DateTime.now(); + final item = factory.ctor(dateTimeIterable: [now]) + ..dateTimeList = [now, now] + ..objectDateTimeMap = {'value': now}; - test('list and map of DateTime - not null', () { - final now = DateTime.now(); - final item = factory.ctor(dateTimeIterable: [now]) - ..dateTimeList = [now, now] - ..objectDateTimeMap = {'value': now}; + roundTripObject(item, factory.fromJson); + }); - roundTripSink(item); - }); + test('complex nested type - not null', () { + final item = factory.ctor() + ..crazyComplex = [ + {}, + { + 'empty': {}, + 'items': { + 'empty': [], + 'items': [ + [], + [DateTime.now()] + ] + } + } + ]; + roundTripObject(item, factory.fromJson); + }); - test('complex nested type - not null', () { - final item = factory.ctor() - ..crazyComplex = [ - {}, - { - 'empty': {}, - 'items': { - 'empty': [], - 'items': [ - [], - [DateTime.now()] - ] + test('round trip valid, empty values', () { + final values = Map.fromEntries(_validValues.entries.map((e) { + var value = e.value; + if (_iterableMapKeys.contains(e.key)) { + if (value is List) { + value = []; + } else { + assert(value is Map); + value = {}; } } - ]; - roundTripSink(item); - }); + return MapEntry(e.key, value); + })); + + final validInstance = factory.fromJson(values); + + roundTripObject(validInstance, factory.fromJson, skipObjectEquals: true); + }); + } test('JSON keys should be defined in field/property order', () { final json = factory.ctor().toJson(); if (factory.excludeNull && factory.nullable) { expect(json.keys, isEmpty); + } else if (factory.noEncodeEmpty) { + expect(json.keys, orderedEquals(_validValueMinusIterableMapKeys)); } else { expect(json.keys, orderedEquals(_validValues.keys)); } @@ -237,7 +268,7 @@ void _sharedTests(KitchenSinkFactory factory) { test('valid values round-trip - json', () { final validInstance = factory.fromJson(_validValues); - expect(loudEncode(_validValues), loudEncode(validInstance)); + roundTripObject(validInstance, factory.fromJson); }); } @@ -310,27 +341,27 @@ const _validValues = { 'no-42': 0, 'dateTime': '2018-05-10T14:20:58.927', 'bigInt': '10000000000000000000', - 'iterable': [], - 'dynamicIterable': [], - 'objectIterable': [], - 'intIterable': [], - 'set': [], - 'dynamicSet': [], - 'objectSet': [], - 'intSet': [], - 'dateTimeSet': [], - 'datetime-iterable': [], - 'list': [], - 'dynamicList': [], - 'objectList': [], - 'intList': [], - 'dateTimeList': [], - 'map': {}, - 'stringStringMap': {}, - 'dynamicIntMap': {}, - 'objectDateTimeMap': {}, - 'crazyComplex': [], - _generatedLocalVarName: {}, + 'iterable': [true], + 'dynamicIterable': [true], + 'objectIterable': [true], + 'intIterable': [42], + 'set': [true], + 'dynamicSet': [true], + 'objectSet': [true], + 'intSet': [42], + 'dateTimeSet': ['2018-05-10T14:20:58.927'], + 'datetime-iterable': ['2018-05-10T14:20:58.927'], + 'list': [true], + 'dynamicList': [true], + 'objectList': [true], + 'intList': [42], + 'dateTimeList': ['2018-05-10T14:20:58.927'], + 'map': {'key': true}, + 'stringStringMap': {'key': 'vaule'}, + 'dynamicIntMap': {'key': 42}, + 'objectDateTimeMap': {'key': '2018-05-10T14:20:58.927'}, + 'crazyComplex': [{}], + _generatedLocalVarName: {'key': true}, _toJsonMapHelperName: true, r'$string': 'string', 'simpleObject': {'value': 42}, @@ -384,10 +415,12 @@ const _invalidCheckedValues = { const _encodedAsMapKeys = ['simpleObject', 'strictKeysObject']; const _iterableMapKeys = [ + 'bigIntMap', 'crazyComplex', 'datetime-iterable', 'dateTimeList', 'dateTimeSet', + 'durationList', 'dynamicIntMap', 'dynamicIterable', 'dynamicList', @@ -398,6 +431,7 @@ const _iterableMapKeys = [ 'iterable', 'list', 'map', + 'numberSillySet', 'objectDateTimeMap', 'objectIterable', 'objectList', @@ -406,3 +440,6 @@ const _iterableMapKeys = [ 'stringStringMap', _generatedLocalVarName, ]; + +final _validValueMinusIterableMapKeys = + List.unmodifiable(_validValues.keys.toSet()..removeAll(_iterableMapKeys)); diff --git a/json_serializable/test/shared_config.dart b/json_serializable/test/shared_config.dart index af0a87ced..e6dca2dd3 100644 --- a/json_serializable/test/shared_config.dart +++ b/json_serializable/test/shared_config.dart @@ -16,6 +16,7 @@ final generatorConfigNonDefaultJson = createFactory: false, createToJson: false, disallowUnrecognizedKeys: true, + encodeEmptyCollection: false, explicitToJson: true, fieldRename: FieldRename.kebab, generateToJsonFunction: false, diff --git a/json_serializable/test/src/_json_serializable_test_input.dart b/json_serializable/test/src/_json_serializable_test_input.dart index b5a71a91e..ef7b52d71 100644 --- a/json_serializable/test/src/_json_serializable_test_input.dart +++ b/json_serializable/test/src/_json_serializable_test_input.dart @@ -8,14 +8,23 @@ import 'package:json_annotation/json_annotation.dart'; import 'package:source_gen_test/annotations.dart'; part 'checked_test_input.dart'; + part 'core_subclass_type_input.dart'; + part 'default_value_input.dart'; + part 'field_namer_input.dart'; + part 'generic_test_input.dart'; + part 'inheritance_test_input.dart'; + part 'json_converter_test_input.dart'; + part 'setter_test_input.dart'; + part 'to_from_json_test_input.dart'; + part 'unknown_type_test_input.dart'; @ShouldThrow('Generator cannot target `theAnswer`.', @@ -44,6 +53,7 @@ class OnlyStaticMembers { // To ensure static members are not considered for serialization. static const answer = 42; static final reason = 42; + static int get understand => 42; } @@ -461,3 +471,90 @@ class MyList extends ListBase { _data[index] = value; } } + +@ShouldGenerate( + r''' +EncodeEmptyCollectionAsNullOnField _$EncodeEmptyCollectionAsNullOnFieldFromJson( + Map json) { + return EncodeEmptyCollectionAsNullOnField()..field = json['field'] as List; +} + +Map _$EncodeEmptyCollectionAsNullOnFieldToJson( + EncodeEmptyCollectionAsNullOnField instance) { + final val = {}; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('field', _$nullIfEmptyIterable(instance.field)); + return val; +} + +T _$nullIfEmptyIterable(T source) => + (source == null || source.isEmpty) ? null : source; +''', + configurations: ['default'], +) +@JsonSerializable() +class EncodeEmptyCollectionAsNullOnField { + @JsonKey(encodeEmptyCollection: false) + List field; +} + +@ShouldThrow( + 'Error with `@JsonKey` on `field`. `encodeEmptyCollection: false` is only ' + 'valid fields of type Iterable, List, Set, or Map.', + element: 'field', +) +@JsonSerializable() +class EncodeEmptyCollectionAsNullOnNonCollectionField { + @JsonKey(encodeEmptyCollection: false) + int field; +} + +@ShouldThrow( + 'Error with `@JsonKey` on `field`. Cannot set `encodeEmptyCollection: false` ' + 'if `includeIfNull: true`.', + element: 'field', +) +@JsonSerializable() +class EmptyCollectionAsNullAndIncludeIfNullField { + @JsonKey(encodeEmptyCollection: false, includeIfNull: true) + List field; +} + +@ShouldGenerate( + r''' +EmptyCollectionAsNullAndIncludeIfNullClass + _$EmptyCollectionAsNullAndIncludeIfNullClassFromJson( + Map json) { + return EmptyCollectionAsNullAndIncludeIfNullClass() + ..field = json['field'] as List; +} + +Map _$EmptyCollectionAsNullAndIncludeIfNullClassToJson( + EmptyCollectionAsNullAndIncludeIfNullClass instance) { + final val = {}; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('field', _$nullIfEmptyIterable(instance.field)); + return val; +} + +T _$nullIfEmptyIterable(T source) => + (source == null || source.isEmpty) ? null : source; +''', + configurations: ['default'], +) +@JsonSerializable(encodeEmptyCollection: false, includeIfNull: true) +class EmptyCollectionAsNullAndIncludeIfNullClass { + List field; +} diff --git a/json_serializable/test/test_sources/test_sources.dart b/json_serializable/test/test_sources/test_sources.dart index 3d9f69293..9582bd6a6 100644 --- a/json_serializable/test/test_sources/test_sources.dart +++ b/json_serializable/test/test_sources/test_sources.dart @@ -11,6 +11,7 @@ class ConfigurationImplicitDefaults { createFactory: true, createToJson: true, disallowUnrecognizedKeys: false, + encodeEmptyCollection: true, explicitToJson: false, fieldRename: FieldRename.none, generateToJsonFunction: true, diff --git a/json_serializable/test/test_utils.dart b/json_serializable/test/test_utils.dart index 4412f0298..9197e2baa 100644 --- a/json_serializable/test/test_utils.dart +++ b/json_serializable/test/test_utils.dart @@ -9,12 +9,18 @@ import 'package:test/test.dart'; final isCastError = const TypeMatcher(); final throwsCastError = throwsA(isCastError); -T roundTripObject(T object, T factory(Map json)) { +T roundTripObject( + T object, + T factory(Map json), { + bool skipObjectEquals = false, +}) { final data = loudEncode(object); final object2 = factory(json.decode(data) as Map); - expect(object2, equals(object)); + if (!skipObjectEquals) { + expect(object2, equals(object)); + } final json2 = loudEncode(object2); diff --git a/json_serializable/tool/builder.dart b/json_serializable/tool/builder.dart index 0ce3e2adc..fed238942 100644 --- a/json_serializable/tool/builder.dart +++ b/json_serializable/tool/builder.dart @@ -117,6 +117,8 @@ const _configReplacements = { 'explicit_to_json': _Replacement.addJsonSerializableKey('explicitToJson', true), 'exclude_null': _Replacement.addJsonSerializableKey('includeIfNull', false), + 'no_encode_empty': + _Replacement.addJsonSerializableKey('encodeEmptyCollection', false), }; const _kitchenSinkReplacements = { @@ -144,6 +146,12 @@ const _kitchenSinkReplacements = { 'bool get checked => true;', ) ], + 'no_encode_empty': [ + _Replacement( + 'bool get noEncodeEmpty => false;', + 'bool get noEncodeEmpty => true;', + ), + ], 'exclude_null': [ _Replacement( 'bool get excludeNull => false;', @@ -226,6 +234,11 @@ const _fileConfigurationMap = >>{ ['any_map', 'non_nullable', 'use_wrappers'], ['any_map', 'non_nullable'], ['any_map'], + ['no_encode_empty'], + ['no_encode_empty', 'exclude_null', 'use_wrappers'], + ['no_encode_empty', 'non_nullable'], + ['no_encode_empty', 'exclude_null'], + ['no_encode_empty', 'exclude_null', 'non_nullable', 'use_wrappers'], ['exclude_null', 'non_nullable'], ['exclude_null', 'use_wrappers'], ['exclude_null'], From 64889f0e6bf4e2ee1782282d17fe84abde98996d Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 25 Mar 2019 09:06:14 -0700 Subject: [PATCH 083/569] Improve error handling with invalid build configuration (#422) - `JsonSerializable.fromJson` now throws `CheckedFromJsonException` on errors. - Added a more helpful `toString` to `CheckedFromJsonException`. --- json_annotation/CHANGELOG.md | 5 ++ json_annotation/lib/src/checked_helpers.dart | 18 +++++ .../lib/src/json_serializable.dart | 3 +- .../lib/src/json_serializable.g.dart | 76 ++++++++++++------- json_serializable/CHANGELOG.md | 2 + json_serializable/build.yaml | 1 - json_serializable/lib/builder.dart | 21 ++++- json_serializable/test/config_test.dart | 44 +++++------ 8 files changed, 113 insertions(+), 57 deletions(-) diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index 840e3f5fe..db63d4e2b 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -2,6 +2,11 @@ * Added to `encodeEmptyCollection` to `JsonKey` and `JsonSerializable`. +* `JsonSerializable.fromJson` now throws `CheckedFromJsonException` on errors. + This is potentially a breaking change. + +* Added a more helpful `toString` to `CheckedFromJsonException`. + ## 2.0.0 * **Potentially Breaking** `JsonSerializable` no longer sets default values for diff --git a/json_annotation/lib/src/checked_helpers.dart b/json_annotation/lib/src/checked_helpers.dart index f259d4b30..8212aec41 100644 --- a/json_annotation/lib/src/checked_helpers.dart +++ b/json_annotation/lib/src/checked_helpers.dart @@ -105,4 +105,22 @@ class CheckedFromJsonException implements Exception { } return null; } + + @override + String toString() { + final lines = ['CheckedFromJsonException']; + + if (_className != null) { + lines.add('Could not create `$_className`.'); + } + if (key != null) { + lines.add('There is a problem with "$key".'); + } + if (message != null) { + lines.add(message); + } else if (innerError != null) { + lines.add(innerError.toString()); + } + return lines.join('\n'); + } } diff --git a/json_annotation/lib/src/json_serializable.dart b/json_annotation/lib/src/json_serializable.dart index 917c92cc5..5fd18d4d5 100644 --- a/json_annotation/lib/src/json_serializable.dart +++ b/json_annotation/lib/src/json_serializable.dart @@ -22,8 +22,9 @@ enum FieldRename { /// An annotation used to specify a class to generate code for. @JsonSerializable( - fieldRename: FieldRename.snake, + checked: true, disallowUnrecognizedKeys: true, + fieldRename: FieldRename.snake, ) class JsonSerializable { /// If `true`, [Map] types are *not* assumed to be [Map] diff --git a/json_annotation/lib/src/json_serializable.g.dart b/json_annotation/lib/src/json_serializable.g.dart index 28cfae160..bc2ab4192 100644 --- a/json_annotation/lib/src/json_serializable.g.dart +++ b/json_annotation/lib/src/json_serializable.g.dart @@ -7,34 +7,54 @@ part of 'json_serializable.dart'; // ************************************************************************** JsonSerializable _$JsonSerializableFromJson(Map json) { - $checkKeys(json, allowedKeys: const [ - 'any_map', - 'checked', - 'create_factory', - 'create_to_json', - 'disallow_unrecognized_keys', - 'encode_empty_collection', - 'explicit_to_json', - 'field_rename', - 'generate_to_json_function', - 'include_if_null', - 'nullable', - 'use_wrappers' - ]); - return JsonSerializable( - anyMap: json['any_map'] as bool, - checked: json['checked'] as bool, - createFactory: json['create_factory'] as bool, - createToJson: json['create_to_json'] as bool, - disallowUnrecognizedKeys: json['disallow_unrecognized_keys'] as bool, - encodeEmptyCollection: json['encode_empty_collection'] as bool, - explicitToJson: json['explicit_to_json'] as bool, - fieldRename: - _$enumDecodeNullable(_$FieldRenameEnumMap, json['field_rename']), - generateToJsonFunction: json['generate_to_json_function'] as bool, - includeIfNull: json['include_if_null'] as bool, - nullable: json['nullable'] as bool, - useWrappers: json['use_wrappers'] as bool); + return $checkedNew('JsonSerializable', json, () { + $checkKeys(json, allowedKeys: const [ + 'any_map', + 'checked', + 'create_factory', + 'create_to_json', + 'disallow_unrecognized_keys', + 'encode_empty_collection', + 'explicit_to_json', + 'field_rename', + 'generate_to_json_function', + 'include_if_null', + 'nullable', + 'use_wrappers' + ]); + final val = JsonSerializable( + anyMap: $checkedConvert(json, 'any_map', (v) => v as bool), + checked: $checkedConvert(json, 'checked', (v) => v as bool), + createFactory: + $checkedConvert(json, 'create_factory', (v) => v as bool), + createToJson: $checkedConvert(json, 'create_to_json', (v) => v as bool), + disallowUnrecognizedKeys: $checkedConvert( + json, 'disallow_unrecognized_keys', (v) => v as bool), + encodeEmptyCollection: + $checkedConvert(json, 'encode_empty_collection', (v) => v as bool), + explicitToJson: + $checkedConvert(json, 'explicit_to_json', (v) => v as bool), + fieldRename: $checkedConvert(json, 'field_rename', + (v) => _$enumDecodeNullable(_$FieldRenameEnumMap, v)), + generateToJsonFunction: $checkedConvert( + json, 'generate_to_json_function', (v) => v as bool), + includeIfNull: + $checkedConvert(json, 'include_if_null', (v) => v as bool), + nullable: $checkedConvert(json, 'nullable', (v) => v as bool), + useWrappers: $checkedConvert(json, 'use_wrappers', (v) => v as bool)); + return val; + }, fieldKeyMap: const { + 'anyMap': 'any_map', + 'createFactory': 'create_factory', + 'createToJson': 'create_to_json', + 'disallowUnrecognizedKeys': 'disallow_unrecognized_keys', + 'encodeEmptyCollection': 'encode_empty_collection', + 'explicitToJson': 'explicit_to_json', + 'fieldRename': 'field_rename', + 'generateToJsonFunction': 'generate_to_json_function', + 'includeIfNull': 'include_if_null', + 'useWrappers': 'use_wrappers' + }); } Map _$JsonSerializableToJson(JsonSerializable instance) => diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index e9ce9aaf8..dd12d6172 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -6,6 +6,8 @@ * Added `BigIntTypeHelper` to `type_helper.dart` library. +* Provide a more helpful error if the builder is improperly configured. + ## 2.0.3 * When invoking a `fromJson` constructor on a field type, generate a conversion diff --git a/json_serializable/build.yaml b/json_serializable/build.yaml index 866a8c7f7..a725ae634 100644 --- a/json_serializable/build.yaml +++ b/json_serializable/build.yaml @@ -3,7 +3,6 @@ targets: $default: builders: json_serializable: - enabled: true generate_for: include: - example/* diff --git a/json_serializable/lib/builder.dart b/json_serializable/lib/builder.dart index c4f735d09..fc465702e 100644 --- a/json_serializable/lib/builder.dart +++ b/json_serializable/lib/builder.dart @@ -22,6 +22,23 @@ import 'src/json_part_builder.dart'; /// /// Not meant to be invoked by hand-authored code. Builder jsonSerializable(BuilderOptions options) { - final config = JsonSerializable.fromJson(options.config); - return jsonPartBuilder(config: config); + try { + final config = JsonSerializable.fromJson(options.config); + return jsonPartBuilder(config: config); + } on CheckedFromJsonException catch (e) { + final lines = [ + 'Could not parse the options provided for `json_serializable`.' + ]; + + if (e.key != null) { + lines.add('There is a problem with "${e.key}".'); + } + if (e.message != null) { + lines.add(e.message); + } else if (e.innerError != null) { + lines.add(e.innerError.toString()); + } + + throw StateError(lines.join('\n')); + } } diff --git a/json_serializable/test/config_test.dart b/json_serializable/test/config_test.dart index b981c0508..c35a0a305 100644 --- a/json_serializable/test/config_test.dart +++ b/json_serializable/test/config_test.dart @@ -13,7 +13,6 @@ import 'package:test/test.dart'; import 'package:yaml/yaml.dart'; import 'shared_config.dart'; -import 'test_utils.dart'; void main() { test('fields in JsonSerializable are sorted', () { @@ -89,11 +88,13 @@ void main() { }); test('unsupported configuration', () async { - final matcher = const TypeMatcher().having( - (e) => e.unrecognizedKeys, 'unrecognizedKeys', [ - 'unsupported' - ]).having((e) => e.allowedKeys, 'allowedKeys', - unorderedEquals(generatorConfigDefaultJson.keys)); + final matcher = const TypeMatcher().having( + (v) => v.message, + 'message', + 'Could not parse the options provided for `json_serializable`.\n' + 'Unrecognized keys: [unsupported]; ' + 'supported keys: [${_invalidConfig.keys.join(', ')}]', + ); expect( () => jsonSerializable(const BuilderOptions({'unsupported': 'config'})), @@ -109,25 +110,18 @@ void main() { final config = Map.from(generatorConfigDefaultJson); config[entry.key] = entry.value; - Matcher matcher; - switch (entry.key) { - case 'field_rename': - matcher = isArgumentError.having((e) => e.message, 'message', - '`42` is not one of the supported values: none, kebab, snake'); - break; - case 'empty_collection_behavior': - matcher = isArgumentError.having( - (e) => e.message, - 'message', - '`42` is not one of the supported values: no_change, ' - 'empty_as_null, null_as_empty', - ); - break; - default: - matcher = isCastError; - break; - } - + final lastLine = entry.key == 'field_rename' + ? '`42` is not one of the supported values: none, kebab, snake' + : "type 'int' is not a subtype of type 'bool' in type cast"; + + final matcher = const TypeMatcher().having( + ((v) => v.message), + 'message', + ''' +Could not parse the options provided for `json_serializable`. +There is a problem with "${entry.key}". +$lastLine''', + ); expect( () => jsonSerializable(BuilderOptions(config)), throwsA(matcher)); }); From 3551be4798aba88d24fa4d2c8e468495b68fce43 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 25 Mar 2019 10:39:12 -0700 Subject: [PATCH 084/569] rename tool/builder -> tool/test_builder --- json_serializable/build.yaml | 2 +- json_serializable/tool/{builder.dart => test_builder.dart} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename json_serializable/tool/{builder.dart => test_builder.dart} (100%) diff --git a/json_serializable/build.yaml b/json_serializable/build.yaml index a725ae634..517490745 100644 --- a/json_serializable/build.yaml +++ b/json_serializable/build.yaml @@ -30,7 +30,7 @@ targets: builders: _internal: - import: 'tool/builder.dart' + import: 'tool/test_builder.dart' builder_factories: ['internal'] build_extensions: .dart: diff --git a/json_serializable/tool/builder.dart b/json_serializable/tool/test_builder.dart similarity index 100% rename from json_serializable/tool/builder.dart rename to json_serializable/tool/test_builder.dart From 5f97aabb8cebde437cb0dabd93a46dc2c4167611 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 25 Mar 2019 10:41:28 -0700 Subject: [PATCH 085/569] Starting on automatic doc generation for annotations and config values Towards https://github.com/dart-lang/json_serializable/issues/416 --- json_serializable/build.yaml | 8 ++ json_serializable/doc/doc.md | 99 +++++++++++++++++++ json_serializable/tool/doc_builder.dart | 126 ++++++++++++++++++++++++ 3 files changed, 233 insertions(+) create mode 100644 json_serializable/doc/doc.md create mode 100644 json_serializable/tool/doc_builder.dart diff --git a/json_serializable/build.yaml b/json_serializable/build.yaml index 517490745..e69b41081 100644 --- a/json_serializable/build.yaml +++ b/json_serializable/build.yaml @@ -55,6 +55,14 @@ builders: build_to: source runs_before: ["json_serializable"] + _doc_builder: + import: "tool/doc_builder.dart" + builder_factories: ["docBuilder"] + build_extensions: {"lib/json_serializable.dart": ["doc/doc.md"]} + build_to: source + auto_apply: root_package + runs_before: ["json_serializable"] + json_serializable: import: "package:json_serializable/builder.dart" builder_factories: ["jsonSerializable"] diff --git a/json_serializable/doc/doc.md b/json_serializable/doc/doc.md new file mode 100644 index 000000000..e8eaf3ae9 --- /dev/null +++ b/json_serializable/doc/doc.md @@ -0,0 +1,99 @@ +# fields + +
+
anyMap
+
+ Support classes: JsonSerializable
+ If true, Map types are *not* assumed to be Map<String, dynamic> – which is the default type of Map instances return by JSON decode in dart:convert. +
+
checked
+
+ Support classes: JsonSerializable
+ If true, generated fromJson functions include extra checks to validate proper deserialization of types. +
+
createFactory
+
+ Support classes: JsonSerializable
+ If true, a private, static _$ExampleFromJson method is created in the generated part file. +
+
createToJson
+
+ Support classes: JsonSerializable
+ If true, code for encoding JSON is generated for this class. +
+
defaultValue
+
+ Support classes: JsonKey
+ The value to use if the source JSON does not contain this key or if the value is null. +
+
disallowNullValue
+
+ Support classes: JsonKey
+ If true, generated code will throw a DisallowedNullValueException if the corresponding key exits, but the value is null. +
+
disallowUnrecognizedKeys
+
+ Support classes: JsonSerializable
+ If false, then any unrecognized keys passed to the generated FromJson factory will be ignored. +
+
encodeEmptyCollection
+
+ Support classes: JsonSerializable, JsonKey
+ Whether the generator should include the annotated field value in the serialized output if it is empty. +
+
explicitToJson
+
+ Support classes: JsonSerializable
+ If true, generated toJson methods will explicitly call toJson on nested objects. +
+
fieldRename
+
+ Support classes: JsonSerializable
+ Defines the automatic naming strategy when converting class field names into JSON map keys. +
+
fromJson
+
+ Support classes: JsonKey
+ A top-level Function to use when deserializing the associated JSON value to the annotated field. +
+
generateToJsonFunction
+
+ Support classes: JsonSerializable
+ Controls how toJson functionality is generated for all types processed by this generator. +
+
ignore
+
+ Support classes: JsonKey
+ true if the generator should ignore this field completely. +
+
includeIfNull
+
+ Support classes: JsonSerializable, JsonKey
+ Whether the generator should include fields with null values in the serialized output. +
+
name
+
+ Support classes: JsonKey
+ The key in a JSON map to use when reading and writing values corresponding to the annotated fields. +
+
nullable
+
+ Support classes: JsonSerializable, JsonKey
+ When true, null values are handled gracefully when serializing to JSON and when deserializing null and nonexistent values from a JSON map. +
+
required
+
+ Support classes: JsonKey
+ When true, generated code for fromJson will verify that the source JSON map contains the associated key. +
+
toJson
+
+ Support classes: JsonKey
+ A top-level Function to use when serializing the annotated field to JSON. +
+
useWrappers
+
+ Support classes: JsonSerializable
+ If true, wrappers are used to minimize the number of Map and List instances created during serialization. +
+
diff --git a/json_serializable/tool/doc_builder.dart b/json_serializable/tool/doc_builder.dart new file mode 100644 index 000000000..8b84bdcd9 --- /dev/null +++ b/json_serializable/tool/doc_builder.dart @@ -0,0 +1,126 @@ +import 'dart:async'; +import 'dart:convert'; + +import 'package:analyzer/dart/element/element.dart'; +import 'package:build/build.dart'; +import 'package:source_gen/source_gen.dart'; + +Builder docBuilder([_]) => _DocBuilder(); + +final _ref = RegExp('\\[([^\\]]+)\\]'); + +class _FieldInfo implements Comparable<_FieldInfo> { + final FieldElement field; + + ClassElement get owner => field.enclosingElement; + + String get description { + final description = LineSplitter.split(field.documentationComment) + .map((line) { + if (line.startsWith('///')) { + line = line.substring(3).trim(); + } + return line; + }) + .takeWhile((line) => line.isNotEmpty) + .join(' '); + + return description + .replaceAllMapped(_ref, (m) => '`${m[1]}`') + .replaceAll(' (the default)', ''); + } + + String get defaultValue => owner.constructors.single.parameters + .singleWhere((pe) => pe.name == field.name) + .defaultValueCode; + + _FieldInfo(this.field); + + @override + int compareTo(_FieldInfo other) => field.name.compareTo(other.field.name); + + @override + String toString() => '_FieldThing($field)'; +} + +final _doubleTickEscape = RegExp('`([ &;,:\\\$_a-zA-Z]+)`'); + +String _escapeDescription(String input) { + input = htmlEscape.convert(input); + input = input.replaceAllMapped(_doubleTickEscape, (e) { + return '${e[1]}'; + }); + + return input; +} + +class _DocBuilder extends Builder { + @override + FutureOr build(BuildStep buildStep) async { + final lib = LibraryReader(await buildStep.resolver.libraryFor( + AssetId.resolve('package:json_annotation/json_annotation.dart'))); + + final descriptions = {}; + final fieldMap = >{}; + + void processClass(ClassElement ce) { + for (var fe in ce.fields.where((fe) => !fe.isStatic)) { + final list = fieldMap.putIfAbsent(ce.name, () => <_FieldInfo>[]); + final newThing = descriptions[fe.name] = _FieldInfo(fe); + list.add(newThing); + list.sort(); + + final existing = descriptions[fe.name]; + if (existing != null && newThing.description != existing.description) { + log.severe([ + 'Duplicate field with different description', + fe.name, + existing.description, + newThing.description + ].join('\n')); + } + } + } + + for (var ce in [ + lib.findType('JsonSerializable'), + lib.findType('JsonKey') + ]) { + processClass(ce); + } + + final buffer = StringBuffer('# fields\n\n'); + buffer.writeln('
'); + + for (var description in descriptions.entries.toList() + ..sort((a, b) => a.key.compareTo(b.key))) { + final supportedClasses = fieldMap.entries + .where((e) => + e.value.indexWhere( + (fe) => fe.field.name == description.value.field.name) >= + 0) + .map((e) => e.key) + .toList(); + + final supportedClassesHtml = + supportedClasses.map((c) => '$c').join(', '); + + buffer.writeln(''' +
${description.key}
+
+ Support classes: $supportedClassesHtml
+ ${_escapeDescription(description.value.description)} +
'''); + } + + buffer.writeln('
'); + + await buildStep.writeAsString( + AssetId(buildStep.inputId.package, 'doc/doc.md'), buffer.toString()); + } + + @override + final buildExtensions = const { + r'lib/json_serializable.dart': ['doc/doc.md'] + }; +} From fc3cc4222bf9e06ab0d239ee7948a8e3443c8824 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 25 Mar 2019 17:18:40 -0700 Subject: [PATCH 086/569] Migrate to pkg:test 1.6.0 (#426) - Fix colliding definitions of isCastError - Bump min SDK for all packages to 2.1.1 - Updated changelogs and travis configuration accordingly --- .travis.yml | 28 +++++++++---------- example/mono_pkg.yaml | 4 +-- example/pubspec.yaml | 4 +-- example/test/json_convert_example_test.dart | 2 +- json_annotation/CHANGELOG.md | 2 ++ json_annotation/mono_pkg.yaml | 4 +-- json_annotation/pubspec.yaml | 2 +- json_serializable/CHANGELOG.md | 2 ++ json_serializable/mono_pkg.yaml | 4 +-- json_serializable/pubspec.yaml | 4 +-- json_serializable/test/config_test.dart | 4 +-- .../test/kitchen_sink/kitchen_sink_test.dart | 13 ++++----- json_serializable/test/test_utils.dart | 1 - 13 files changed, 38 insertions(+), 36 deletions(-) diff --git a/.travis.yml b/.travis.yml index d0004a9bd..03acbb7c0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,15 +17,15 @@ jobs: env: PKG="example" dart: dev - stage: analyzer_and_format - name: "SDK: 2.0.0 - DIR: example - TASKS: [dartfmt -n --set-exit-if-changed ., dartanalyzer --fatal-warnings .]" + name: "SDK: 2.1.1 - DIR: example - TASKS: [dartfmt -n --set-exit-if-changed ., dartanalyzer --fatal-warnings .]" script: ./tool/travis.sh dartfmt dartanalyzer_1 env: PKG="example" - dart: "2.0.0" + dart: "2.1.1" - stage: unit_test - name: "SDK: 2.0.0 - DIR: example - TASKS: pub run test --run-skipped" + name: "SDK: 2.1.1 - DIR: example - TASKS: pub run test --run-skipped" script: ./tool/travis.sh test_0 env: PKG="example" - dart: "2.0.0" + dart: "2.1.1" - stage: unit_test name: "SDK: dev - DIR: example - TASKS: pub run test --run-skipped" script: ./tool/travis.sh test_0 @@ -37,45 +37,45 @@ jobs: env: PKG="json_annotation" dart: dev - stage: analyzer_and_format - name: "SDK: 2.0.0 - DIR: json_annotation - TASKS: [dartfmt -n --set-exit-if-changed ., dartanalyzer --fatal-warnings .]" + name: "SDK: 2.1.1 - DIR: json_annotation - TASKS: [dartfmt -n --set-exit-if-changed ., dartanalyzer --fatal-warnings .]" script: ./tool/travis.sh dartfmt dartanalyzer_1 env: PKG="json_annotation" - dart: "2.0.0" + dart: "2.1.1" - stage: analyzer_and_format name: "SDK: dev - DIR: json_serializable - TASKS: [dartfmt -n --set-exit-if-changed ., dartanalyzer --fatal-infos --fatal-warnings .]" script: ./tool/travis.sh dartfmt dartanalyzer_0 env: PKG="json_serializable" dart: dev - stage: analyzer_and_format - name: "SDK: 2.0.0 - DIR: json_serializable - TASKS: [dartfmt -n --set-exit-if-changed ., dartanalyzer --fatal-warnings .]" + name: "SDK: 2.1.1 - DIR: json_serializable - TASKS: [dartfmt -n --set-exit-if-changed ., dartanalyzer --fatal-warnings .]" script: ./tool/travis.sh dartfmt dartanalyzer_1 env: PKG="json_serializable" - dart: "2.0.0" + dart: "2.1.1" - stage: unit_test - name: "SDK: 2.0.0 - DIR: json_serializable - TASKS: pub run test" + name: "SDK: 2.1.1 - DIR: json_serializable - TASKS: pub run test" script: ./tool/travis.sh test_1 env: PKG="json_serializable" - dart: "2.0.0" + dart: "2.1.1" - stage: unit_test name: "SDK: dev - DIR: json_serializable - TASKS: pub run test" script: ./tool/travis.sh test_1 env: PKG="json_serializable" dart: dev - stage: unit_test - name: "SDK: 2.0.0 - DIR: json_serializable - TASKS: pub run test --run-skipped test/ensure_build_test.dart" + name: "SDK: 2.1.1 - DIR: json_serializable - TASKS: pub run test --run-skipped test/ensure_build_test.dart" script: ./tool/travis.sh test_2 env: PKG="json_serializable" - dart: "2.0.0" + dart: "2.1.1" - stage: unit_test name: "SDK: dev - DIR: json_serializable - TASKS: pub run test --run-skipped test/ensure_build_test.dart" script: ./tool/travis.sh test_2 env: PKG="json_serializable" dart: dev - stage: unit_test - name: "SDK: 2.0.0 - DIR: json_serializable - TASKS: pub run build_runner test --delete-conflicting-outputs -- -p chrome" + name: "SDK: 2.1.1 - DIR: json_serializable - TASKS: pub run build_runner test --delete-conflicting-outputs -- -p chrome" script: ./tool/travis.sh command env: PKG="json_serializable" - dart: "2.0.0" + dart: "2.1.1" - stage: unit_test name: "SDK: dev - DIR: json_serializable - TASKS: pub run build_runner test --delete-conflicting-outputs -- -p chrome" script: ./tool/travis.sh command diff --git a/example/mono_pkg.yaml b/example/mono_pkg.yaml index e2c823dc9..1cb308c01 100644 --- a/example/mono_pkg.yaml +++ b/example/mono_pkg.yaml @@ -1,6 +1,6 @@ # See https://github.com/dart-lang/mono_repo for details dart: -- 2.0.0 +- 2.1.1 - dev stages: @@ -12,7 +12,7 @@ stages: - group: - dartfmt - dartanalyzer: --fatal-warnings . - dart: [2.0.0] + dart: [2.1.1] - unit_test: # Run the tests -- include the default-skipped presubmit tests - test: --run-skipped diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 1ec5c4474..a93f09aba 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -2,7 +2,7 @@ name: example author: Dart Team environment: - sdk: '>=2.0.0 <3.0.0' + sdk: '>=2.1.1 <3.0.0' dependencies: json_annotation: ^2.0.0 @@ -14,4 +14,4 @@ dev_dependencies: # Used by tests. Not required to use `json_serializable`. build_verify: ^1.0.0 path: ^1.5.1 - test: ^1.3.3 + test: ^1.6.0 diff --git a/example/test/json_convert_example_test.dart b/example/test/json_convert_example_test.dart index b79f5c67e..091168e4a 100644 --- a/example/test/json_convert_example_test.dart +++ b/example/test/json_convert_example_test.dart @@ -81,7 +81,7 @@ void main() { }); } -final _throwsCastSomething = throwsA(const TypeMatcher()); +final _throwsCastSomething = throwsA(isA()); String _encode(Object object) => const JsonEncoder.withIndent(' ').convert(object); diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index db63d4e2b..4f77933ab 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -1,5 +1,7 @@ ## 2.1.0 +* Require at least Dart `2.1.1`. + * Added to `encodeEmptyCollection` to `JsonKey` and `JsonSerializable`. * `JsonSerializable.fromJson` now throws `CheckedFromJsonException` on errors. diff --git a/json_annotation/mono_pkg.yaml b/json_annotation/mono_pkg.yaml index c35bde03c..8f3d348fe 100644 --- a/json_annotation/mono_pkg.yaml +++ b/json_annotation/mono_pkg.yaml @@ -1,7 +1,7 @@ # See https://github.com/dart-lang/mono_repo for details dart: +- 2.1.1 - dev -- 2.0.0 stages: - analyzer_and_format: @@ -12,6 +12,6 @@ stages: - group: - dartfmt - dartanalyzer: --fatal-warnings . - dart: [2.0.0] + dart: [2.1.1] diff --git a/json_annotation/pubspec.yaml b/json_annotation/pubspec.yaml index ec43a6e84..8b1f7a6a2 100644 --- a/json_annotation/pubspec.yaml +++ b/json_annotation/pubspec.yaml @@ -6,7 +6,7 @@ description: >- homepage: https://github.com/dart-lang/json_serializable author: Dart Team environment: - sdk: '>=2.0.0 <3.0.0' + sdk: '>=2.1.1 <3.0.0' # When changing JsonSerializable class. # dev_dependencies: diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index dd12d6172..04f01f772 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,5 +1,7 @@ ## 2.1.0 +* Require at least Dart `2.1.1`. + * Added support for `encodeEmptyCollection` on `JsonKey` and `JsonSerializable`. * Added support for `BigInt`. diff --git a/json_serializable/mono_pkg.yaml b/json_serializable/mono_pkg.yaml index 905043a2c..1361271b3 100644 --- a/json_serializable/mono_pkg.yaml +++ b/json_serializable/mono_pkg.yaml @@ -1,6 +1,6 @@ # See https://github.com/dart-lang/mono_repo for details dart: -- 2.0.0 +- 2.1.1 - dev stages: @@ -12,7 +12,7 @@ stages: - group: - dartfmt - dartanalyzer: --fatal-warnings . - dart: [2.0.0] + dart: [2.1.1] - unit_test: # Run the tests -- include the default-skipped presubmit tests - test diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 64167c962..d0a41f57f 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -6,7 +6,7 @@ description: >- Dart classes. homepage: https://github.com/dart-lang/json_serializable environment: - sdk: '>=2.0.0 <3.0.0' + sdk: '>=2.1.1 <3.0.0' dependencies: analyzer: '>=0.33.3 <0.36.0' @@ -28,7 +28,7 @@ dev_dependencies: dart_style: ^1.2.0 logging: ^0.11.3+1 source_gen_test: ^0.1.0 - test: ^1.3.3 + test: ^1.6.0 yaml: ^2.1.13 dependency_overrides: diff --git a/json_serializable/test/config_test.dart b/json_serializable/test/config_test.dart index c35a0a305..e55f931ab 100644 --- a/json_serializable/test/config_test.dart +++ b/json_serializable/test/config_test.dart @@ -88,7 +88,7 @@ void main() { }); test('unsupported configuration', () async { - final matcher = const TypeMatcher().having( + final matcher = isA().having( (v) => v.message, 'message', 'Could not parse the options provided for `json_serializable`.\n' @@ -114,7 +114,7 @@ void main() { ? '`42` is not one of the supported values: none, kebab, snake' : "type 'int' is not a subtype of type 'bool' in type cast"; - final matcher = const TypeMatcher().having( + final matcher = isA().having( ((v) => v.message), 'message', ''' diff --git a/json_serializable/test/kitchen_sink/kitchen_sink_test.dart b/json_serializable/test/kitchen_sink/kitchen_sink_test.dart index e3ec1f476..feb58d436 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink_test.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink_test.dart @@ -15,14 +15,14 @@ import 'strict_keys_object.dart'; const _generatedLocalVarName = 'val'; const _toJsonMapHelperName = 'writeNotNull'; -final _isATypeError = const TypeMatcher(); +final _isATypeError = isA(); Matcher _isAUnrecognizedKeysException(expectedMessage) => - const TypeMatcher() + isA() .having((e) => e.message, 'message', expectedMessage); Matcher _isMissingKeyException(expectedMessage) => - const TypeMatcher() + isA() .having((e) => e.message, 'message', expectedMessage); void main() { @@ -291,10 +291,9 @@ void _testBadValue(String key, Object badValue, KitchenSinkFactory factory, } } -Matcher _checkedMatcher(String expectedKey) => - const TypeMatcher() - .having((e) => e.className, 'className', 'KitchenSink') - .having((e) => e.key, 'key', expectedKey); +Matcher _checkedMatcher(String expectedKey) => isA() + .having((e) => e.className, 'className', 'KitchenSink') + .having((e) => e.key, 'key', expectedKey); Matcher _getMatcher(bool checked, String expectedKey, bool checkedAssignment) { Matcher innerMatcher; diff --git a/json_serializable/test/test_utils.dart b/json_serializable/test/test_utils.dart index 9197e2baa..5057ac67c 100644 --- a/json_serializable/test/test_utils.dart +++ b/json_serializable/test/test_utils.dart @@ -6,7 +6,6 @@ import 'dart:convert'; import 'package:test/test.dart'; -final isCastError = const TypeMatcher(); final throwsCastError = throwsA(isCastError); T roundTripObject( From d60c0a51169ea82e8381a1f902710cfa079143f2 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 26 Mar 2019 06:59:58 -0700 Subject: [PATCH 087/569] Update doc generation (#427) - split out JsonKey and JsonSerializable - document the build.yaml key for JsonSerializable - include all of the content of the doc comments - wire up anchor links correctly --- json_serializable/doc/doc.md | 368 ++++++++++++++++++++---- json_serializable/tool/doc_builder.dart | 184 ++++++------ 2 files changed, 402 insertions(+), 150 deletions(-) diff --git a/json_serializable/doc/doc.md b/json_serializable/doc/doc.md index e8eaf3ae9..b24964605 100644 --- a/json_serializable/doc/doc.md +++ b/json_serializable/doc/doc.md @@ -1,99 +1,349 @@ -# fields - +

JsonSerializable

-
anyMap
+
JsonSerializable.anyMap
+
+ +`build.yaml` config key: `any_map` + +If `true`, `Map` types are *not* assumed to be `Map` +– which is the default type of `Map` instances return by JSON decode in +`dart:convert`. + +This will increase the code size, but allows `Map` types returned +from other sources, such as `package:yaml`. + +*Note: in many cases the key values are still assumed to be `String`*. +
+
JsonSerializable.checked
+
+ +`build.yaml` config key: `checked` + +If `true`, generated `fromJson` functions include extra checks to validate +proper deserialization of types. + +If an exception is thrown during deserialization, a +`CheckedFromJsonException` is thrown. +
+
JsonSerializable.createFactory
- Support classes: JsonSerializable
- If true, Map types are *not* assumed to be Map<String, dynamic> – which is the default type of Map instances return by JSON decode in dart:convert. + +`build.yaml` config key: `create_factory` + +If `true` (the default), a private, static `_$ExampleFromJson` method +is created in the generated part file. + +Call this method from a factory constructor added to the source class: + +```dart +@JsonSerializable() +class Example { + // ... + factory Example.fromJson(Map json) => + _$ExampleFromJson(json); +} +``` +
+
JsonSerializable.createToJson
+
+ +`build.yaml` config key: `create_to_json` + +If `true` (the default), code for encoding JSON is generated for this +class. + +By default, a private `_$ClassNameMixin` class is created +in the generated part file which contains a `toJson` method. + +Mix in this class to the source class: + +```dart +@JsonSerializable() +class Example extends Object with _$ExampleSerializerMixin { + // ... +} +``` + +If `json_serializable` is configured with +`generate_to_json_function: true`, then a top-level function is created +that you can reference from your class. + +```dart +@JsonSerializable() +class Example { + Map toJson() => _$ExampleToJson(this); +} +```
-
checked
+
JsonSerializable.disallowUnrecognizedKeys
- Support classes: JsonSerializable
- If true, generated fromJson functions include extra checks to validate proper deserialization of types. + +`build.yaml` config key: `disallow_unrecognized_keys` + +If `false` (the default), then any unrecognized keys passed to the +generated FromJson factory will be ignored. + +If `true`, any unrecognized keys will be treated as an error.
-
createFactory
+
JsonSerializable.encodeEmptyCollection
- Support classes: JsonSerializable
- If true, a private, static _$ExampleFromJson method is created in the generated part file. + +`build.yaml` config key: `encode_empty_collection` + +Whether the generator should include empty collection field values in the +serialized output. + +If `true` (the default), empty collection fields +(of type `Iterable`, `Set`, `List`, and `Map`) +are included in generated `toJson` functions. + +If `false`, fields with empty collections are omitted from `toJson`. + +Note: setting this property to `false` overrides the [`JsonSerializable.includeIfNull`](#JsonSerializable-includeIfNull) +value to `false` as well. + +This value has no effect on non-collection fields.
-
createToJson
+
JsonSerializable.explicitToJson
- Support classes: JsonSerializable
- If true, code for encoding JSON is generated for this class. + +`build.yaml` config key: `explicit_to_json` + +If `true`, generated `toJson` methods will explicitly call `toJson` on +nested objects. + +When using JSON encoding support in `dart:convert`, `toJson` is +automatically called on objects, so the default behavior +(`explicitToJson: false`) is to omit the `toJson` call. + +Example of `explicitToJson: false` (default) + +```dart +Map toJson() => {'child': child}; +``` + +Example of `explicitToJson: true` + +```dart +Map toJson() => {'child': child?.toJson()}; +```
-
defaultValue
+
JsonSerializable.fieldRename
- Support classes: JsonKey
- The value to use if the source JSON does not contain this key or if the value is null. + +`build.yaml` config key: `field_rename` + +Defines the automatic naming strategy when converting class field names +into JSON map keys. + +With a value `FieldRename.none`, the default, the name of the field is +used without modification. + +See `FieldRename` for details on the other options. + +Note: the value for [`JsonKey.name`](#JsonKey-name) takes precedence over this option for +fields annotated with `JsonKey`.
-
disallowNullValue
+
JsonSerializable.generateToJsonFunction
- Support classes: JsonKey
- If true, generated code will throw a DisallowedNullValueException if the corresponding key exits, but the value is null. + +`build.yaml` config key: `generate_to_json_function` + +Controls how `toJson` functionality is generated for all types processed +by this generator. + +If `true` (the default), then a top-level function is created that you can +reference from your class. + +```dart +@JsonSerializable() +class Example { + // ... + Map toJson() => _$ExampleToJson(this); +} +``` + +If `false`, a private `_$ClassNameSerializerMixin` class is +created in the generated part file which contains a `toJson` method. + +Mix in this class to the source class: + +```dart +@JsonSerializable() +class Example extends Object with _$ExampleSerializerMixin { + // ... +} +```
-
disallowUnrecognizedKeys
+
JsonSerializable.includeIfNull
- Support classes: JsonSerializable
- If false, then any unrecognized keys passed to the generated FromJson factory will be ignored. + +`build.yaml` config key: `include_if_null` + +Whether the generator should include fields with `null` values in the +serialized output. + +If `true` (the default), all fields are written to JSON, even if they are +`null`. + +If a field is annotated with `JsonKey` with a non-`null` value for +`includeIfNull`, that value takes precedent.
-
encodeEmptyCollection
+
JsonSerializable.nullable
- Support classes: JsonSerializable, JsonKey
- Whether the generator should include the annotated field value in the serialized output if it is empty. + +`build.yaml` config key: `nullable` + +When `true` (the default), `null` values are handled gracefully when +serializing to JSON and when deserializing `null` and nonexistent values +from a JSON map. + +Setting to `false` eliminates `null` verification in the generated code, +which reduces the code size. Errors may be thrown at runtime if `null` +values are encountered, but the original class should also implement +`null` runtime validation if it's critical.
-
explicitToJson
+
JsonSerializable.useWrappers
- Support classes: JsonSerializable
- If true, generated toJson methods will explicitly call toJson on nested objects. + +`build.yaml` config key: `use_wrappers` + +If `true`, wrappers are used to minimize the number of +`Map` and `List` instances created during serialization. + +This will increase the code size, but it may improve runtime performance, +especially for large object graphs.
-
fieldRename
+
+

JsonKey

+
+
JsonKey.defaultValue
- Support classes: JsonSerializable
- Defines the automatic naming strategy when converting class field names into JSON map keys. + +The value to use if the source JSON does not contain this key or if the +value is `null`.
-
fromJson
+
JsonKey.disallowNullValue
- Support classes: JsonKey
- A top-level Function to use when deserializing the associated JSON value to the annotated field. + +If `true`, generated code will throw a `DisallowedNullValueException` if +the corresponding key exits, but the value is `null`. + +Note: this value does not affect the behavior of a JSON map *without* the +associated key. + +If [`JsonKey.disallowNullValue`](#JsonKey-disallowNullValue) is `true`, [`JsonKey.includeIfNull`](#JsonKey-includeIfNull) will be treated as +`false` to ensure compatibility between `toJson` and `fromJson`. + +If both [`JsonKey.includeIfNull`](#JsonKey-includeIfNull) and [`JsonKey.disallowNullValue`](#JsonKey-disallowNullValue) are set to `true` on the +same field, an exception will be thrown during code generation.
-
generateToJsonFunction
+
JsonKey.encodeEmptyCollection
- Support classes: JsonSerializable
- Controls how toJson functionality is generated for all types processed by this generator. + +Whether the generator should include the annotated field value in the +serialized output if it is empty. + +If `true` (the default), empty values are included in the generated +`toJson` function. + +If `false`, fields with empty collections are omitted from `toJson`. + +Note: setting this property to `false` overrides the [`JsonKey.includeIfNull`](#JsonKey-includeIfNull) +value to `false` as well. Explicitly setting [`JsonKey.includeIfNull`](#JsonKey-includeIfNull) to `true` +and setting this property to `false` will cause an error at build time. + +Note: setting this property to `false` on a non-collection field +(of types other than `Iterable`, `Set`, `List`, and `Map`) +will cause an error at build time.
-
ignore
+
JsonKey.fromJson
- Support classes: JsonKey
- true if the generator should ignore this field completely. + +A top-level `Function` to use when deserializing the associated JSON +value to the annotated field. + +The `Function` should take one argument that maps to the expected JSON +value and return a value that can be assigned to the type of the annotated +field. + +When creating a class that supports both `toJson` and `fromJson` +(the default), you should also set [`JsonKey.toJson`](#JsonKey-toJson) if you set [`JsonKey.fromJson`](#JsonKey-fromJson). +Values returned by [`JsonKey.toJson`](#JsonKey-toJson) should "round-trip" through [`JsonKey.fromJson`](#JsonKey-fromJson).
-
includeIfNull
+
JsonKey.ignore
- Support classes: JsonSerializable, JsonKey
- Whether the generator should include fields with null values in the serialized output. + +`true` if the generator should ignore this field completely. + +If `null` (the default) or `false`, the field will be considered for +serialization.
-
name
+
JsonKey.includeIfNull
- Support classes: JsonKey
- The key in a JSON map to use when reading and writing values corresponding to the annotated fields. + +Whether the generator should include fields with `null` values in the +serialized output. + +If `true`, the generator should include the field in the serialized +output, even if the value is `null`. + +The default value, `null`, indicates that the behavior should be +acquired from the [`JsonSerializable.includeIfNull`](#JsonSerializable-includeIfNull) annotation on the +enclosing class. + +If [`JsonKey.disallowNullValue`](#JsonKey-disallowNullValue) is `true`, this value is treated as `false` to +ensure compatibility between `toJson` and `fromJson`. + +If both [`JsonKey.includeIfNull`](#JsonKey-includeIfNull) and [`JsonKey.disallowNullValue`](#JsonKey-disallowNullValue) are set to `true` on the +same field, an exception will be thrown during code generation.
-
nullable
+
JsonKey.name
- Support classes: JsonSerializable, JsonKey
- When true, null values are handled gracefully when serializing to JSON and when deserializing null and nonexistent values from a JSON map. + +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.
-
required
+
JsonKey.nullable
- Support classes: JsonKey
- When true, generated code for fromJson will verify that the source JSON map contains the associated key. + +When `true`, `null` values are handled gracefully when serializing to JSON +and when deserializing `null` and nonexistent values from a JSON map. + +Setting to `false` eliminates `null` verification in the generated code +for the annotated field, which reduces the code size. Errors may be thrown +at runtime if `null` values are encountered, but the original class should +also implement `null` runtime validation if it's critical. + +The default value, `null`, indicates that the behavior should be +acquired from the [`JsonSerializable.nullable`](#JsonSerializable-nullable) annotation on the +enclosing class.
-
toJson
+
JsonKey.required
- Support classes: JsonKey
- A top-level Function to use when serializing the annotated field to JSON. + +When `true`, generated code for `fromJson` will verify that the source +JSON map contains the associated key. + +If the key does not exist, a `MissingRequiredKeysException` exception is +thrown. + +Note: only the existence of the key is checked. A key with a `null` value +is considered valid.
-
useWrappers
+
JsonKey.toJson
- Support classes: JsonSerializable
- If true, wrappers are used to minimize the number of Map and List instances created during serialization. + +A top-level `Function` to use when serializing the annotated field to +JSON. + +The `Function` should take one argument that is compatible with the field +being serialized and return a JSON-compatible value. + +When creating a class that supports both `toJson` and `fromJson` +(the default), you should also set [`JsonKey.fromJson`](#JsonKey-fromJson) if you set [`JsonKey.toJson`](#JsonKey-toJson). +Values returned by [`JsonKey.toJson`](#JsonKey-toJson) should "round-trip" through [`JsonKey.fromJson`](#JsonKey-fromJson).
diff --git a/json_serializable/tool/doc_builder.dart b/json_serializable/tool/doc_builder.dart index 8b84bdcd9..881a716bb 100644 --- a/json_serializable/tool/doc_builder.dart +++ b/json_serializable/tool/doc_builder.dart @@ -3,124 +3,126 @@ import 'dart:convert'; import 'package:analyzer/dart/element/element.dart'; import 'package:build/build.dart'; +import 'package:json_serializable/src/utils.dart'; import 'package:source_gen/source_gen.dart'; Builder docBuilder([_]) => _DocBuilder(); -final _ref = RegExp('\\[([^\\]]+)\\]'); +class _DocBuilder extends Builder { + @override + FutureOr build(BuildStep buildStep) async { + final lib = LibraryReader(await buildStep.resolver.libraryFor( + AssetId.resolve('package:json_annotation/json_annotation.dart'))); -class _FieldInfo implements Comparable<_FieldInfo> { - final FieldElement field; + final descriptionMap = >{}; - ClassElement get owner => field.enclosingElement; + for (var className in _annotationClasses) { + final descriptions = <_FieldInfo>[]; - String get description { - final description = LineSplitter.split(field.documentationComment) - .map((line) { - if (line.startsWith('///')) { - line = line.substring(3).trim(); - } - return line; - }) - .takeWhile((line) => line.isNotEmpty) - .join(' '); - - return description - .replaceAllMapped(_ref, (m) => '`${m[1]}`') - .replaceAll(' (the default)', ''); - } + for (var fe + in lib.findType(className).fields.where((fe) => !fe.isStatic)) { + descriptions.add(_FieldInfo(className, fe)); + } - String get defaultValue => owner.constructors.single.parameters - .singleWhere((pe) => pe.name == field.name) - .defaultValueCode; + descriptions.sort(); - _FieldInfo(this.field); + descriptionMap[className] = descriptions; + } - @override - int compareTo(_FieldInfo other) => field.name.compareTo(other.field.name); + final buffer = StringBuffer(); + + for (var entry in descriptionMap.entries) { + buffer.writeln('

${entry.key}

'); + buffer.writeln('
'); + + for (var description in entry.value) { + final anchor = _anchorUriForName(entry.key, description.field.name); + buffer.writeln(''' +
${description.parent}.${description.field.name}
+
+ +${description.description} +
'''); + } + + buffer.writeln('
'); + } + + await buildStep.writeAsString( + AssetId(buildStep.inputId.package, 'doc/doc.md'), buffer.toString()); + } @override - String toString() => '_FieldThing($field)'; + final buildExtensions = const { + r'lib/json_serializable.dart': ['doc/doc.md'] + }; } -final _doubleTickEscape = RegExp('`([ &;,:\\\$_a-zA-Z]+)`'); +const _annotationClasses = ['JsonSerializable', 'JsonKey']; -String _escapeDescription(String input) { - input = htmlEscape.convert(input); - input = input.replaceAllMapped(_doubleTickEscape, (e) { - return '${e[1]}'; - }); +String _anchorUriForName(String owner, String name) => '$owner-$name'; - return input; -} +class _FieldInfo implements Comparable<_FieldInfo> { + static final _ref = RegExp('\\[([^\\]]+)\\]'); + static final _knownEntities = >{}; -class _DocBuilder extends Builder { - @override - FutureOr build(BuildStep buildStep) async { - final lib = LibraryReader(await buildStep.resolver.libraryFor( - AssetId.resolve('package:json_annotation/json_annotation.dart'))); + final String parent; + final FieldElement field; - final descriptions = {}; - final fieldMap = >{}; - - void processClass(ClassElement ce) { - for (var fe in ce.fields.where((fe) => !fe.isStatic)) { - final list = fieldMap.putIfAbsent(ce.name, () => <_FieldInfo>[]); - final newThing = descriptions[fe.name] = _FieldInfo(fe); - list.add(newThing); - list.sort(); - - final existing = descriptions[fe.name]; - if (existing != null && newThing.description != existing.description) { - log.severe([ - 'Duplicate field with different description', - fe.name, - existing.description, - newThing.description - ].join('\n')); + String get description { + var description = + LineSplitter.split(field.documentationComment).map((line) { + if (line.startsWith('///')) { + line = line.substring(3).trimRight(); + } + if (line.startsWith(' ')) { + // If the line is not empty, then it starts with a blank space + line = line.substring(1); + } + return line; + }).join('\n'); + + description = description.replaceAllMapped(_ref, (m) { + final ref = m[1]; + + String refParentClass, refName; + if (_knownEntities[parent].contains(ref)) { + refName = ref; + refParentClass = parent; + } else if (ref.contains('.')) { + final split = ref.split('.'); + if (split.length == 2 && + _annotationClasses.contains(split[0]) && + _knownEntities[split[0]].contains(split[1])) { + refParentClass = split[0]; + refName = split[1]; } } - } - - for (var ce in [ - lib.findType('JsonSerializable'), - lib.findType('JsonKey') - ]) { - processClass(ce); - } - final buffer = StringBuffer('# fields\n\n'); - buffer.writeln('
'); - - for (var description in descriptions.entries.toList() - ..sort((a, b) => a.key.compareTo(b.key))) { - final supportedClasses = fieldMap.entries - .where((e) => - e.value.indexWhere( - (fe) => fe.field.name == description.value.field.name) >= - 0) - .map((e) => e.key) - .toList(); + if (refParentClass != null) { + assert(refName != null); + return '[`$refParentClass.$refName`]' + '(#${_anchorUriForName(refParentClass, refName)})'; + } - final supportedClassesHtml = - supportedClasses.map((c) => '$c').join(', '); + return '`$ref`'; + }); - buffer.writeln(''' -
${description.key}
-
- Support classes: $supportedClassesHtml
- ${_escapeDescription(description.value.description)} -
'''); + if (parent == 'JsonSerializable') { + final yamlConfigKey = snakeCase(field.name); + description = '`build.yaml` config key: `$yamlConfigKey`\n\n$description'; } - buffer.writeln('
'); + return description; + } - await buildStep.writeAsString( - AssetId(buildStep.inputId.package, 'doc/doc.md'), buffer.toString()); + _FieldInfo(this.parent, this.field) { + _knownEntities.putIfAbsent(parent, () => Set()).add(field.name); } @override - final buildExtensions = const { - r'lib/json_serializable.dart': ['doc/doc.md'] - }; + int compareTo(_FieldInfo other) => field.name.compareTo(other.field.name); + + @override + String toString() => '_FieldThing($field)'; } From fa1c7dd6b95586e490c4cf7a7f79cac94195ed41 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 27 Mar 2019 15:35:12 -0700 Subject: [PATCH 088/569] Fix doc comments on JsonKey and JsonSerialiazble (#428) Also ordered fields in JsonKey --- json_annotation/lib/src/json_key.dart | 141 +++++++++--------- .../lib/src/json_serializable.dart | 41 ++--- json_serializable/doc/doc.md | 65 ++++---- 3 files changed, 127 insertions(+), 120 deletions(-) diff --git a/json_annotation/lib/src/json_key.dart b/json_annotation/lib/src/json_key.dart index d38083d4a..62a77175b 100644 --- a/json_annotation/lib/src/json_key.dart +++ b/json_annotation/lib/src/json_key.dart @@ -2,28 +2,65 @@ // 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 'allowed_keys_helpers.dart'; import 'json_serializable.dart'; /// An annotation used to specify how a field is serialized. class JsonKey { - /// The key in a JSON map to use when reading and writing values corresponding - /// to the annotated fields. + /// The value to use if the source JSON does not contain this key or if the + /// value is `null`. + final Object defaultValue; + + /// If `true`, generated code will throw a [DisallowedNullValueException] if + /// the corresponding key exits, but the value is `null`. /// - /// If `null`, the field name is used. - final String name; + /// Note: this value does not affect the behavior of a JSON map *without* the + /// associated key. + /// + /// If [disallowNullValue] is `true`, [includeIfNull] will be treated as + /// `false` to ensure compatibility between `toJson` and `fromJson`. + /// + /// If both [includeIfNull] and [disallowNullValue] are set to `true` on the + /// same field, an exception will be thrown during code generation. + final bool disallowNullValue; - /// When `true`, `null` values are handled gracefully when serializing to JSON - /// and when deserializing `null` and nonexistent values from a JSON map. + /// Whether the generator should include the annotated field value in the + /// serialized output if it is empty. /// - /// Setting to `false` eliminates `null` verification in the generated code - /// for the annotated field, which reduces the code size. Errors may be thrown - /// at runtime if `null` values are encountered, but the original class should - /// also implement `null` runtime validation if it's critical. + /// If `true` (the default), empty values are included in the generated + /// `toJson` function. + /// + /// If `false`, fields with empty collections are omitted from `toJson`. + /// + /// Note: setting this property to `false` overrides the [includeIfNull] + /// value to `false` as well. Explicitly setting [includeIfNull] to `true` + /// and setting this property to `false` will cause an error at build time. + /// + /// Note: setting this property to `false` on a non-collection field + /// (of types other than [Iterable], [Set], [List], and [Map]) + /// will cause an error at build time. /// /// The default value, `null`, indicates that the behavior should be - /// acquired from the [JsonSerializable.nullable] annotation on the - /// enclosing class. - final bool nullable; + /// acquired from the [JsonSerializable.encodeEmptyCollection] annotation on + /// the enclosing class. + final bool encodeEmptyCollection; + + /// A [Function] to use when decoding the associated JSON value to the + /// annotated field. + /// + /// Must be a top-level or static [Function] that takes one argument mapping + /// a JSON literal to a value compatible with the type of the annotated field. + /// + /// When creating a class that supports both `toJson` and `fromJson` + /// (the default), you should also set [toJson] if you set [fromJson]. + /// Values returned by [toJson] should "round-trip" through [fromJson]. + final Function fromJson; + + /// `true` if the generator should ignore this field completely. + /// + /// If `null` (the default) or `false`, the field will be considered for + /// serialization. + final bool ignore; /// Whether the generator should include fields with `null` values in the /// serialized output. @@ -42,78 +79,44 @@ class JsonKey { /// same field, an exception will be thrown during code generation. final bool includeIfNull; - /// `true` if the generator should ignore this field completely. - /// - /// If `null` (the default) or `false`, the field will be considered for - /// serialization. - final bool ignore; - - /// A top-level [Function] to use when deserializing the associated JSON - /// value to the annotated field. - /// - /// The [Function] should take one argument that maps to the expected JSON - /// value and return a value that can be assigned to the type of the annotated - /// field. + /// The key in a JSON map to use when reading and writing values corresponding + /// to the annotated fields. /// - /// When creating a class that supports both `toJson` and `fromJson` - /// (the default), you should also set [toJson] if you set [fromJson]. - /// Values returned by [toJson] should "round-trip" through [fromJson]. - final Function fromJson; + /// If `null`, the field name is used. + final String name; - /// A top-level [Function] to use when serializing the annotated field to - /// JSON. + /// When `true`, `null` fields are handled gracefully when encoding to JSON + /// and when decoding `null` and nonexistent values from JSON. /// - /// The [Function] should take one argument that is compatible with the field - /// being serialized and return a JSON-compatible value. + /// Setting to `false` eliminates `null` verification in the generated code + /// for the annotated field, which reduces the code size. Errors may be thrown + /// at runtime if `null` values are encountered, but the original class should + /// also implement `null` runtime validation if it's critical. /// - /// When creating a class that supports both `toJson` and `fromJson` - /// (the default), you should also set [fromJson] if you set [toJson]. - /// Values returned by [toJson] should "round-trip" through [fromJson]. - final Function toJson; - - /// The value to use if the source JSON does not contain this key or if the - /// value is `null`. - final Object defaultValue; + /// The default value, `null`, indicates that the behavior should be + /// acquired from the [JsonSerializable.nullable] annotation on the + /// enclosing class. + final bool nullable; /// When `true`, generated code for `fromJson` will verify that the source /// JSON map contains the associated key. /// - /// If the key does not exist, a `MissingRequiredKeysException` exception is + /// If the key does not exist, a [MissingRequiredKeysException] exception is /// thrown. /// /// Note: only the existence of the key is checked. A key with a `null` value /// is considered valid. final bool required; - /// If `true`, generated code will throw a `DisallowedNullValueException` if - /// the corresponding key exits, but the value is `null`. + /// A [Function] to use when encoding the annotated field to JSON. /// - /// Note: this value does not affect the behavior of a JSON map *without* the - /// associated key. - /// - /// If [disallowNullValue] is `true`, [includeIfNull] will be treated as - /// `false` to ensure compatibility between `toJson` and `fromJson`. - /// - /// If both [includeIfNull] and [disallowNullValue] are set to `true` on the - /// same field, an exception will be thrown during code generation. - final bool disallowNullValue; - - /// Whether the generator should include the annotated field value in the - /// serialized output if it is empty. - /// - /// If `true` (the default), empty values are included in the generated - /// `toJson` function. + /// Must be a top-level or static [Function] with one parameter compatible + /// with the field being serialized that returns a JSON-compatible value. /// - /// If `false`, fields with empty collections are omitted from `toJson`. - /// - /// Note: setting this property to `false` overrides the [includeIfNull] - /// value to `false` as well. Explicitly setting [includeIfNull] to `true` - /// and setting this property to `false` will cause an error at build time. - /// - /// Note: setting this property to `false` on a non-collection field - /// (of types other than [Iterable], [Set], [List], and [Map]) - /// will cause an error at build time. - final bool encodeEmptyCollection; + /// When creating a class that supports both `toJson` and `fromJson` + /// (the default), you should also set [fromJson] if you set [toJson]. + /// Values returned by [toJson] should "round-trip" through [fromJson]. + final Function toJson; /// Creates a new [JsonKey] instance. /// diff --git a/json_annotation/lib/src/json_serializable.dart b/json_annotation/lib/src/json_serializable.dart index 5fd18d4d5..f41e0812d 100644 --- a/json_annotation/lib/src/json_serializable.dart +++ b/json_annotation/lib/src/json_serializable.dart @@ -62,34 +62,36 @@ class JsonSerializable { /// If `true` (the default), code for encoding JSON is generated for this /// class. /// - /// By default, a private `_$ClassNameMixin` class is created - /// in the generated part file which contains a `toJson` method. - /// - /// Mix in this class to the source class: + /// If `json_serializable` is configured with + /// `generate_to_json_function: true` (the default), a top-level function is + /// created that you can reference from your class. /// /// ```dart /// @JsonSerializable() - /// class Example extends Object with _$ExampleSerializerMixin { - /// // ... + /// class Example { + /// Map toJson() => _$ExampleToJson(this); /// } /// ``` /// /// If `json_serializable` is configured with - /// `generate_to_json_function: true`, then a top-level function is created - /// that you can reference from your class. + /// `generate_to_json_function: false`, a private `_$ClassNameMixin` class is + /// created in the generated part file which contains a `toJson` method. + /// + /// Mix in this class to the source class: /// /// ```dart /// @JsonSerializable() - /// class Example { - /// Map toJson() => _$ExampleToJson(this); + /// class Example extends Object with _$ExampleSerializerMixin { + /// // ... /// } /// ``` final bool createToJson; - /// If `false` (the default), then any unrecognized keys passed to the - /// generated FromJson factory will be ignored. + /// If `false` (the default), then the generated `FromJson` function will + /// ignore unrecognized keys in the provided JSON [Map]. /// - /// If `true`, any unrecognized keys will be treated as an error. + /// If `true`, unrecognized keys will cause an [UnrecognizedKeysException] to + /// be thrown. final bool disallowUnrecognizedKeys; /// Whether the generator should include empty collection field values in the @@ -104,7 +106,7 @@ class JsonSerializable { /// Note: setting this property to `false` overrides the [includeIfNull] /// value to `false` as well. /// - /// This value has no effect on non-collection fields. + /// Note: non-collection fields are not affected by this value. final bool encodeEmptyCollection; /// If `true`, generated `toJson` methods will explicitly call `toJson` on @@ -130,7 +132,7 @@ class JsonSerializable { /// Defines the automatic naming strategy when converting class field names /// into JSON map keys. /// - /// With a value [FieldRename.none], the default, the name of the field is + /// With a value [FieldRename.none] (the default), the name of the field is /// used without modification. /// /// See [FieldRename] for details on the other options. @@ -142,8 +144,7 @@ class JsonSerializable { /// Controls how `toJson` functionality is generated for all types processed /// by this generator. /// - /// If `true` (the default), then a top-level function is created that you can - /// reference from your class. + /// If `true` (the default), a top-level function is created. /// /// ```dart /// @JsonSerializable() @@ -176,9 +177,9 @@ class JsonSerializable { /// `includeIfNull`, that value takes precedent. final bool includeIfNull; - /// When `true` (the default), `null` values are handled gracefully when - /// serializing to JSON and when deserializing `null` and nonexistent values - /// from a JSON map. + /// When `true` (the default), `null` fields are handled gracefully when + /// encoding to JSON and when decoding `null` and nonexistent values from + /// JSON. /// /// Setting to `false` eliminates `null` verification in the generated code, /// which reduces the code size. Errors may be thrown at runtime if `null` diff --git a/json_serializable/doc/doc.md b/json_serializable/doc/doc.md index b24964605..9ff9325be 100644 --- a/json_serializable/doc/doc.md +++ b/json_serializable/doc/doc.md @@ -52,26 +52,27 @@ class Example { If `true` (the default), code for encoding JSON is generated for this class. -By default, a private `_$ClassNameMixin` class is created -in the generated part file which contains a `toJson` method. - -Mix in this class to the source class: +If `json_serializable` is configured with +`generate_to_json_function: true` (the default), a top-level function is +created that you can reference from your class. ```dart @JsonSerializable() -class Example extends Object with _$ExampleSerializerMixin { - // ... +class Example { + Map toJson() => _$ExampleToJson(this); } ``` If `json_serializable` is configured with -`generate_to_json_function: true`, then a top-level function is created -that you can reference from your class. +`generate_to_json_function: false`, a private `_$ClassNameMixin` class is +created in the generated part file which contains a `toJson` method. + +Mix in this class to the source class: ```dart @JsonSerializable() -class Example { - Map toJson() => _$ExampleToJson(this); +class Example extends Object with _$ExampleSerializerMixin { + // ... } ``` @@ -80,10 +81,11 @@ class Example { `build.yaml` config key: `disallow_unrecognized_keys` -If `false` (the default), then any unrecognized keys passed to the -generated FromJson factory will be ignored. +If `false` (the default), then the generated `FromJson` function will +ignore unrecognized keys in the provided JSON `Map`. -If `true`, any unrecognized keys will be treated as an error. +If `true`, unrecognized keys will cause an `UnrecognizedKeysException` to +be thrown.
JsonSerializable.encodeEmptyCollection
@@ -102,7 +104,7 @@ If `false`, fields with empty collections are omitted from `toJson`. Note: setting this property to `false` overrides the [`JsonSerializable.includeIfNull`](#JsonSerializable-includeIfNull) value to `false` as well. -This value has no effect on non-collection fields. +Note: non-collection fields are not affected by this value.
JsonSerializable.explicitToJson
@@ -136,7 +138,7 @@ Map toJson() => {'child': child?.toJson()}; Defines the automatic naming strategy when converting class field names into JSON map keys. -With a value `FieldRename.none`, the default, the name of the field is +With a value `FieldRename.none` (the default), the name of the field is used without modification. See `FieldRename` for details on the other options. @@ -152,8 +154,7 @@ fields annotated with `JsonKey`. Controls how `toJson` functionality is generated for all types processed by this generator. -If `true` (the default), then a top-level function is created that you can -reference from your class. +If `true` (the default), a top-level function is created. ```dart @JsonSerializable() @@ -194,9 +195,9 @@ If a field is annotated with `JsonKey` with a non-`null` value for `build.yaml` config key: `nullable` -When `true` (the default), `null` values are handled gracefully when -serializing to JSON and when deserializing `null` and nonexistent values -from a JSON map. +When `true` (the default), `null` fields are handled gracefully when +encoding to JSON and when decoding `null` and nonexistent values from +JSON. Setting to `false` eliminates `null` verification in the generated code, which reduces the code size. Errors may be thrown at runtime if `null` @@ -256,16 +257,19 @@ and setting this property to `false` will cause an error at build time. Note: setting this property to `false` on a non-collection field (of types other than `Iterable`, `Set`, `List`, and `Map`) will cause an error at build time. + +The default value, `null`, indicates that the behavior should be +acquired from the [`JsonSerializable.encodeEmptyCollection`](#JsonSerializable-encodeEmptyCollection) annotation on +the enclosing class.
JsonKey.fromJson
-A top-level `Function` to use when deserializing the associated JSON -value to the annotated field. +A `Function` to use when decoding the associated JSON value to the +annotated field. -The `Function` should take one argument that maps to the expected JSON -value and return a value that can be assigned to the type of the annotated -field. +Must be a top-level or static `Function` that takes one argument mapping +a JSON literal to a value compatible with the type of the annotated field. When creating a class that supports both `toJson` and `fromJson` (the default), you should also set [`JsonKey.toJson`](#JsonKey-toJson) if you set [`JsonKey.fromJson`](#JsonKey-fromJson). @@ -309,8 +313,8 @@ If `null`, the field name is used.
JsonKey.nullable
-When `true`, `null` values are handled gracefully when serializing to JSON -and when deserializing `null` and nonexistent values from a JSON map. +When `true`, `null` fields are handled gracefully when encoding to JSON +and when decoding `null` and nonexistent values from JSON. Setting to `false` eliminates `null` verification in the generated code for the annotated field, which reduces the code size. Errors may be thrown @@ -336,11 +340,10 @@ is considered valid.
JsonKey.toJson
-A top-level `Function` to use when serializing the annotated field to -JSON. +A `Function` to use when encoding the annotated field to JSON. -The `Function` should take one argument that is compatible with the field -being serialized and return a JSON-compatible value. +Must be a top-level or static `Function` with one parameter compatible +with the field being serialized that returns a JSON-compatible value. When creating a class that supports both `toJson` and `fromJson` (the default), you should also set [`JsonKey.fromJson`](#JsonKey-fromJson) if you set [`JsonKey.toJson`](#JsonKey-toJson). From f90841ef5d31b46fc77644ea67f4a68f5b1340f3 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 1 Apr 2019 10:14:26 -0700 Subject: [PATCH 089/569] Use mono_repo v2 (#430) Merge analyze_and_format tasks --- .travis.yml | 82 +++++++++--------------- example/mono_pkg.yaml | 2 +- json_annotation/mono_pkg.yaml | 4 -- json_serializable/mono_pkg.yaml | 2 +- mono_repo.yaml | 5 +- tool/travis.sh | 109 ++++++++++++++++---------------- 6 files changed, 90 insertions(+), 114 deletions(-) diff --git a/.travis.yml b/.travis.yml index 03acbb7c0..7cb83c767 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,4 @@ -# Created with package:mono_repo v1.2.2 +# Created with package:mono_repo v2.0.0 language: dart # Custom configuration @@ -12,75 +12,55 @@ branches: jobs: include: - stage: analyzer_and_format - name: "SDK: dev - DIR: example - TASKS: [dartfmt -n --set-exit-if-changed ., dartanalyzer --fatal-infos --fatal-warnings .]" - script: ./tool/travis.sh dartfmt dartanalyzer_0 - env: PKG="example" + name: "SDK: dev; PKGS: example, json_annotation, json_serializable; TASKS: [`dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-warnings --fatal-infos .`]" dart: dev + env: PKGS="example json_annotation json_serializable" + script: ./tool/travis.sh dartfmt dartanalyzer_0 - stage: analyzer_and_format - name: "SDK: 2.1.1 - DIR: example - TASKS: [dartfmt -n --set-exit-if-changed ., dartanalyzer --fatal-warnings .]" - script: ./tool/travis.sh dartfmt dartanalyzer_1 - env: PKG="example" + name: "SDK: 2.1.1; PKGS: example, json_annotation, json_serializable; TASKS: [`dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-warnings .`]" dart: "2.1.1" + env: PKGS="example json_annotation json_serializable" + script: ./tool/travis.sh dartfmt dartanalyzer_1 - stage: unit_test - name: "SDK: 2.1.1 - DIR: example - TASKS: pub run test --run-skipped" - script: ./tool/travis.sh test_0 - env: PKG="example" + name: "SDK: 2.1.1; PKG: example; TASKS: `pub run test --run-skipped`" dart: "2.1.1" - - stage: unit_test - name: "SDK: dev - DIR: example - TASKS: pub run test --run-skipped" + env: PKGS="example" script: ./tool/travis.sh test_0 - env: PKG="example" - dart: dev - - stage: analyzer_and_format - name: "SDK: dev - DIR: json_annotation - TASKS: [dartfmt -n --set-exit-if-changed ., dartanalyzer --fatal-warnings --fatal-infos .]" - script: ./tool/travis.sh dartfmt dartanalyzer_2 - env: PKG="json_annotation" - dart: dev - - stage: analyzer_and_format - name: "SDK: 2.1.1 - DIR: json_annotation - TASKS: [dartfmt -n --set-exit-if-changed ., dartanalyzer --fatal-warnings .]" - script: ./tool/travis.sh dartfmt dartanalyzer_1 - env: PKG="json_annotation" - dart: "2.1.1" - - stage: analyzer_and_format - name: "SDK: dev - DIR: json_serializable - TASKS: [dartfmt -n --set-exit-if-changed ., dartanalyzer --fatal-infos --fatal-warnings .]" - script: ./tool/travis.sh dartfmt dartanalyzer_0 - env: PKG="json_serializable" + - stage: unit_test + name: "SDK: dev; PKG: example; TASKS: `pub run test --run-skipped`" dart: dev - - stage: analyzer_and_format - name: "SDK: 2.1.1 - DIR: json_serializable - TASKS: [dartfmt -n --set-exit-if-changed ., dartanalyzer --fatal-warnings .]" - script: ./tool/travis.sh dartfmt dartanalyzer_1 - env: PKG="json_serializable" - dart: "2.1.1" + env: PKGS="example" + script: ./tool/travis.sh test_0 - stage: unit_test - name: "SDK: 2.1.1 - DIR: json_serializable - TASKS: pub run test" - script: ./tool/travis.sh test_1 - env: PKG="json_serializable" + name: "SDK: 2.1.1; PKG: json_serializable; TASKS: `pub run test`" dart: "2.1.1" - - stage: unit_test - name: "SDK: dev - DIR: json_serializable - TASKS: pub run test" + env: PKGS="json_serializable" script: ./tool/travis.sh test_1 - env: PKG="json_serializable" + - stage: unit_test + name: "SDK: dev; PKG: json_serializable; TASKS: `pub run test`" dart: dev + env: PKGS="json_serializable" + script: ./tool/travis.sh test_1 - stage: unit_test - name: "SDK: 2.1.1 - DIR: json_serializable - TASKS: pub run test --run-skipped test/ensure_build_test.dart" - script: ./tool/travis.sh test_2 - env: PKG="json_serializable" + name: "SDK: 2.1.1; PKG: json_serializable; TASKS: `pub run test --run-skipped test/ensure_build_test.dart`" dart: "2.1.1" - - stage: unit_test - name: "SDK: dev - DIR: json_serializable - TASKS: pub run test --run-skipped test/ensure_build_test.dart" + env: PKGS="json_serializable" script: ./tool/travis.sh test_2 - env: PKG="json_serializable" + - stage: unit_test + name: "SDK: dev; PKG: json_serializable; TASKS: `pub run test --run-skipped test/ensure_build_test.dart`" dart: dev + env: PKGS="json_serializable" + script: ./tool/travis.sh test_2 - stage: unit_test - name: "SDK: 2.1.1 - DIR: json_serializable - TASKS: pub run build_runner test --delete-conflicting-outputs -- -p chrome" - script: ./tool/travis.sh command - env: PKG="json_serializable" + name: "SDK: 2.1.1; PKG: json_serializable; TASKS: `pub run build_runner test --delete-conflicting-outputs -- -p chrome`" dart: "2.1.1" - - stage: unit_test - name: "SDK: dev - DIR: json_serializable - TASKS: pub run build_runner test --delete-conflicting-outputs -- -p chrome" + env: PKGS="json_serializable" script: ./tool/travis.sh command - env: PKG="json_serializable" + - stage: unit_test + name: "SDK: dev; PKG: json_serializable; TASKS: `pub run build_runner test --delete-conflicting-outputs -- -p chrome`" dart: dev + env: PKGS="json_serializable" + script: ./tool/travis.sh command stages: - analyzer_and_format diff --git a/example/mono_pkg.yaml b/example/mono_pkg.yaml index 1cb308c01..f824f9d4c 100644 --- a/example/mono_pkg.yaml +++ b/example/mono_pkg.yaml @@ -7,7 +7,7 @@ stages: - analyzer_and_format: - group: - dartfmt - - dartanalyzer: --fatal-infos --fatal-warnings . + - dartanalyzer: --fatal-warnings --fatal-infos . dart: [dev] - group: - dartfmt diff --git a/json_annotation/mono_pkg.yaml b/json_annotation/mono_pkg.yaml index 8f3d348fe..b23291f40 100644 --- a/json_annotation/mono_pkg.yaml +++ b/json_annotation/mono_pkg.yaml @@ -1,8 +1,4 @@ # See https://github.com/dart-lang/mono_repo for details -dart: -- 2.1.1 -- dev - stages: - analyzer_and_format: - group: diff --git a/json_serializable/mono_pkg.yaml b/json_serializable/mono_pkg.yaml index 1361271b3..8754b9fe4 100644 --- a/json_serializable/mono_pkg.yaml +++ b/json_serializable/mono_pkg.yaml @@ -7,7 +7,7 @@ stages: - analyzer_and_format: - group: - dartfmt - - dartanalyzer: --fatal-infos --fatal-warnings . + - dartanalyzer: --fatal-warnings --fatal-infos . dart: [dev] - group: - dartfmt diff --git a/mono_repo.yaml b/mono_repo.yaml index 18400672f..d2112e2c0 100644 --- a/mono_repo.yaml +++ b/mono_repo.yaml @@ -5,4 +5,7 @@ travis: chrome: stable branches: only: - - master + - master + +merge_stages: +- analyzer_and_format diff --git a/tool/travis.sh b/tool/travis.sh index 9bc3cf155..27cd515dc 100755 --- a/tool/travis.sh +++ b/tool/travis.sh @@ -1,70 +1,67 @@ #!/bin/bash -# Created with package:mono_repo v1.2.2 +# Created with package:mono_repo v2.0.0 -if [ -z "$PKG" ]; then - echo -e '\033[31mPKG environment variable must be set!\033[0m' +if [[ -z ${PKGS} ]]; then + echo -e '\033[31mPKGS environment variable must be set!\033[0m' exit 1 fi -if [ "$#" == "0" ]; then +if [[ "$#" == "0" ]]; then echo -e '\033[31mAt least one task argument must be provided!\033[0m' exit 1 fi -pushd $PKG -pub upgrade || exit $? - EXIT_CODE=0 -while (( "$#" )); do - TASK=$1 - case $TASK in - command) echo - echo -e '\033[1mTASK: command\033[22m' - echo -e 'pub run build_runner test --delete-conflicting-outputs -- -p chrome' - pub run build_runner test --delete-conflicting-outputs -- -p chrome || EXIT_CODE=$? - ;; - dartanalyzer_0) echo - echo -e '\033[1mTASK: dartanalyzer_0\033[22m' - echo -e 'dartanalyzer --fatal-infos --fatal-warnings .' - dartanalyzer --fatal-infos --fatal-warnings . || EXIT_CODE=$? - ;; - dartanalyzer_1) echo - echo -e '\033[1mTASK: dartanalyzer_1\033[22m' - echo -e 'dartanalyzer --fatal-warnings .' - dartanalyzer --fatal-warnings . || EXIT_CODE=$? - ;; - dartanalyzer_2) echo - echo -e '\033[1mTASK: dartanalyzer_2\033[22m' - echo -e 'dartanalyzer --fatal-warnings --fatal-infos .' - dartanalyzer --fatal-warnings --fatal-infos . || EXIT_CODE=$? - ;; - dartfmt) echo - echo -e '\033[1mTASK: dartfmt\033[22m' - echo -e 'dartfmt -n --set-exit-if-changed .' - dartfmt -n --set-exit-if-changed . || EXIT_CODE=$? - ;; - test_0) echo - echo -e '\033[1mTASK: test_0\033[22m' - echo -e 'pub run test --run-skipped' - pub run test --run-skipped || EXIT_CODE=$? - ;; - test_1) echo - echo -e '\033[1mTASK: test_1\033[22m' - echo -e 'pub run test' - pub run test || EXIT_CODE=$? - ;; - test_2) echo - echo -e '\033[1mTASK: test_2\033[22m' - echo -e 'pub run test --run-skipped test/ensure_build_test.dart' - pub run test --run-skipped test/ensure_build_test.dart || EXIT_CODE=$? - ;; - *) echo -e "\033[31mNot expecting TASK '${TASK}'. Error!\033[0m" - EXIT_CODE=1 - ;; - esac +for PKG in ${PKGS}; do + echo -e "\033[1mPKG: ${PKG}\033[22m" + pushd "${PKG}" || exit $? + pub upgrade --no-precompile || exit $? + + for TASK in "$@"; do + case ${TASK} in + command) echo + echo -e '\033[1mTASK: command\033[22m' + echo -e 'pub run build_runner test --delete-conflicting-outputs -- -p chrome' + pub run build_runner test --delete-conflicting-outputs -- -p chrome || EXIT_CODE=$? + ;; + dartanalyzer_0) echo + echo -e '\033[1mTASK: dartanalyzer_0\033[22m' + echo -e 'dartanalyzer --fatal-warnings --fatal-infos .' + dartanalyzer --fatal-warnings --fatal-infos . || EXIT_CODE=$? + ;; + dartanalyzer_1) echo + echo -e '\033[1mTASK: dartanalyzer_1\033[22m' + echo -e 'dartanalyzer --fatal-warnings .' + dartanalyzer --fatal-warnings . || EXIT_CODE=$? + ;; + dartfmt) echo + echo -e '\033[1mTASK: dartfmt\033[22m' + echo -e 'dartfmt -n --set-exit-if-changed .' + dartfmt -n --set-exit-if-changed . || EXIT_CODE=$? + ;; + test_0) echo + echo -e '\033[1mTASK: test_0\033[22m' + echo -e 'pub run test --run-skipped' + pub run test --run-skipped || EXIT_CODE=$? + ;; + test_1) echo + echo -e '\033[1mTASK: test_1\033[22m' + echo -e 'pub run test' + pub run test || EXIT_CODE=$? + ;; + test_2) echo + echo -e '\033[1mTASK: test_2\033[22m' + echo -e 'pub run test --run-skipped test/ensure_build_test.dart' + pub run test --run-skipped test/ensure_build_test.dart || EXIT_CODE=$? + ;; + *) echo -e "\033[31mNot expecting TASK '${TASK}'. Error!\033[0m" + EXIT_CODE=1 + ;; + esac + done - shift + popd done -exit $EXIT_CODE +exit ${EXIT_CODE} From 3e43cd977802c2bb6381455f5fbbc6c65ac6f652 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 1 Apr 2019 14:14:59 -0700 Subject: [PATCH 090/569] prepare to release json_annotation v2.1.0 (#432) --- json_annotation/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/json_annotation/pubspec.yaml b/json_annotation/pubspec.yaml index 8b1f7a6a2..624aea1c5 100644 --- a/json_annotation/pubspec.yaml +++ b/json_annotation/pubspec.yaml @@ -1,5 +1,5 @@ name: json_annotation -version: 2.1.0-dev +version: 2.1.0 description: >- Classes and helper functions that support JSON code generation via the `json_serializable` package. From bc44a87b7accd7b1295d805ca682d8ab439e537b Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 26 Mar 2019 20:37:09 -0700 Subject: [PATCH 091/569] Doc generation: move content to a table --- json_serializable/doc/doc.md | 396 +++--------------------- json_serializable/tool/doc_builder.dart | 185 ++++++----- 2 files changed, 158 insertions(+), 423 deletions(-) diff --git a/json_serializable/doc/doc.md b/json_serializable/doc/doc.md index 9ff9325be..3ad862758 100644 --- a/json_serializable/doc/doc.md +++ b/json_serializable/doc/doc.md @@ -1,352 +1,44 @@ -

JsonSerializable

-
-
JsonSerializable.anyMap
-
- -`build.yaml` config key: `any_map` - -If `true`, `Map` types are *not* assumed to be `Map` -– which is the default type of `Map` instances return by JSON decode in -`dart:convert`. - -This will increase the code size, but allows `Map` types returned -from other sources, such as `package:yaml`. - -*Note: in many cases the key values are still assumed to be `String`*. -
-
JsonSerializable.checked
-
- -`build.yaml` config key: `checked` - -If `true`, generated `fromJson` functions include extra checks to validate -proper deserialization of types. - -If an exception is thrown during deserialization, a -`CheckedFromJsonException` is thrown. -
-
JsonSerializable.createFactory
-
- -`build.yaml` config key: `create_factory` - -If `true` (the default), a private, static `_$ExampleFromJson` method -is created in the generated part file. - -Call this method from a factory constructor added to the source class: - -```dart -@JsonSerializable() -class Example { - // ... - factory Example.fromJson(Map json) => - _$ExampleFromJson(json); -} -``` -
-
JsonSerializable.createToJson
-
- -`build.yaml` config key: `create_to_json` - -If `true` (the default), code for encoding JSON is generated for this -class. - -If `json_serializable` is configured with -`generate_to_json_function: true` (the default), a top-level function is -created that you can reference from your class. - -```dart -@JsonSerializable() -class Example { - Map toJson() => _$ExampleToJson(this); -} -``` - -If `json_serializable` is configured with -`generate_to_json_function: false`, a private `_$ClassNameMixin` class is -created in the generated part file which contains a `toJson` method. - -Mix in this class to the source class: - -```dart -@JsonSerializable() -class Example extends Object with _$ExampleSerializerMixin { - // ... -} -``` -
-
JsonSerializable.disallowUnrecognizedKeys
-
- -`build.yaml` config key: `disallow_unrecognized_keys` - -If `false` (the default), then the generated `FromJson` function will -ignore unrecognized keys in the provided JSON `Map`. - -If `true`, unrecognized keys will cause an `UnrecognizedKeysException` to -be thrown. -
-
JsonSerializable.encodeEmptyCollection
-
- -`build.yaml` config key: `encode_empty_collection` - -Whether the generator should include empty collection field values in the -serialized output. - -If `true` (the default), empty collection fields -(of type `Iterable`, `Set`, `List`, and `Map`) -are included in generated `toJson` functions. - -If `false`, fields with empty collections are omitted from `toJson`. - -Note: setting this property to `false` overrides the [`JsonSerializable.includeIfNull`](#JsonSerializable-includeIfNull) -value to `false` as well. - -Note: non-collection fields are not affected by this value. -
-
JsonSerializable.explicitToJson
-
- -`build.yaml` config key: `explicit_to_json` - -If `true`, generated `toJson` methods will explicitly call `toJson` on -nested objects. - -When using JSON encoding support in `dart:convert`, `toJson` is -automatically called on objects, so the default behavior -(`explicitToJson: false`) is to omit the `toJson` call. - -Example of `explicitToJson: false` (default) - -```dart -Map toJson() => {'child': child}; -``` - -Example of `explicitToJson: true` - -```dart -Map toJson() => {'child': child?.toJson()}; -``` -
-
JsonSerializable.fieldRename
-
- -`build.yaml` config key: `field_rename` - -Defines the automatic naming strategy when converting class field names -into JSON map keys. - -With a value `FieldRename.none` (the default), the name of the field is -used without modification. - -See `FieldRename` for details on the other options. - -Note: the value for [`JsonKey.name`](#JsonKey-name) takes precedence over this option for -fields annotated with `JsonKey`. -
-
JsonSerializable.generateToJsonFunction
-
- -`build.yaml` config key: `generate_to_json_function` - -Controls how `toJson` functionality is generated for all types processed -by this generator. - -If `true` (the default), a top-level function is created. - -```dart -@JsonSerializable() -class Example { - // ... - Map toJson() => _$ExampleToJson(this); -} -``` - -If `false`, a private `_$ClassNameSerializerMixin` class is -created in the generated part file which contains a `toJson` method. - -Mix in this class to the source class: - -```dart -@JsonSerializable() -class Example extends Object with _$ExampleSerializerMixin { - // ... -} -``` -
-
JsonSerializable.includeIfNull
-
- -`build.yaml` config key: `include_if_null` - -Whether the generator should include fields with `null` values in the -serialized output. - -If `true` (the default), all fields are written to JSON, even if they are -`null`. - -If a field is annotated with `JsonKey` with a non-`null` value for -`includeIfNull`, that value takes precedent. -
-
JsonSerializable.nullable
-
- -`build.yaml` config key: `nullable` - -When `true` (the default), `null` fields are handled gracefully when -encoding to JSON and when decoding `null` and nonexistent values from -JSON. - -Setting to `false` eliminates `null` verification in the generated code, -which reduces the code size. Errors may be thrown at runtime if `null` -values are encountered, but the original class should also implement -`null` runtime validation if it's critical. -
-
JsonSerializable.useWrappers
-
- -`build.yaml` config key: `use_wrappers` - -If `true`, wrappers are used to minimize the number of -`Map` and `List` instances created during serialization. - -This will increase the code size, but it may improve runtime performance, -especially for large object graphs. -
-
-

JsonKey

-
-
JsonKey.defaultValue
-
- -The value to use if the source JSON does not contain this key or if the -value is `null`. -
-
JsonKey.disallowNullValue
-
- -If `true`, generated code will throw a `DisallowedNullValueException` if -the corresponding key exits, but the value is `null`. - -Note: this value does not affect the behavior of a JSON map *without* the -associated key. - -If [`JsonKey.disallowNullValue`](#JsonKey-disallowNullValue) is `true`, [`JsonKey.includeIfNull`](#JsonKey-includeIfNull) will be treated as -`false` to ensure compatibility between `toJson` and `fromJson`. - -If both [`JsonKey.includeIfNull`](#JsonKey-includeIfNull) and [`JsonKey.disallowNullValue`](#JsonKey-disallowNullValue) are set to `true` on the -same field, an exception will be thrown during code generation. -
-
JsonKey.encodeEmptyCollection
-
- -Whether the generator should include the annotated field value in the -serialized output if it is empty. - -If `true` (the default), empty values are included in the generated -`toJson` function. - -If `false`, fields with empty collections are omitted from `toJson`. - -Note: setting this property to `false` overrides the [`JsonKey.includeIfNull`](#JsonKey-includeIfNull) -value to `false` as well. Explicitly setting [`JsonKey.includeIfNull`](#JsonKey-includeIfNull) to `true` -and setting this property to `false` will cause an error at build time. - -Note: setting this property to `false` on a non-collection field -(of types other than `Iterable`, `Set`, `List`, and `Map`) -will cause an error at build time. - -The default value, `null`, indicates that the behavior should be -acquired from the [`JsonSerializable.encodeEmptyCollection`](#JsonSerializable-encodeEmptyCollection) annotation on -the enclosing class. -
-
JsonKey.fromJson
-
- -A `Function` to use when decoding the associated JSON value to the -annotated field. - -Must be a top-level or static `Function` that takes one argument mapping -a JSON literal to a value compatible with the type of the annotated field. - -When creating a class that supports both `toJson` and `fromJson` -(the default), you should also set [`JsonKey.toJson`](#JsonKey-toJson) if you set [`JsonKey.fromJson`](#JsonKey-fromJson). -Values returned by [`JsonKey.toJson`](#JsonKey-toJson) should "round-trip" through [`JsonKey.fromJson`](#JsonKey-fromJson). -
-
JsonKey.ignore
-
- -`true` if the generator should ignore this field completely. - -If `null` (the default) or `false`, the field will be considered for -serialization. -
-
JsonKey.includeIfNull
-
- -Whether the generator should include fields with `null` values in the -serialized output. - -If `true`, the generator should include the field in the serialized -output, even if the value is `null`. - -The default value, `null`, indicates that the behavior should be -acquired from the [`JsonSerializable.includeIfNull`](#JsonSerializable-includeIfNull) annotation on the -enclosing class. - -If [`JsonKey.disallowNullValue`](#JsonKey-disallowNullValue) is `true`, this value is treated as `false` to -ensure compatibility between `toJson` and `fromJson`. - -If both [`JsonKey.includeIfNull`](#JsonKey-includeIfNull) and [`JsonKey.disallowNullValue`](#JsonKey-disallowNullValue) are set to `true` on the -same field, an exception will be thrown during code generation. -
-
JsonKey.name
-
- -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. -
-
JsonKey.nullable
-
- -When `true`, `null` fields are handled gracefully when encoding to JSON -and when decoding `null` and nonexistent values from JSON. - -Setting to `false` eliminates `null` verification in the generated code -for the annotated field, which reduces the code size. Errors may be thrown -at runtime if `null` values are encountered, but the original class should -also implement `null` runtime validation if it's critical. - -The default value, `null`, indicates that the behavior should be -acquired from the [`JsonSerializable.nullable`](#JsonSerializable-nullable) annotation on the -enclosing class. -
-
JsonKey.required
-
- -When `true`, generated code for `fromJson` will verify that the source -JSON map contains the associated key. - -If the key does not exist, a `MissingRequiredKeysException` exception is -thrown. - -Note: only the existence of the key is checked. A key with a `null` value -is considered valid. -
-
JsonKey.toJson
-
- -A `Function` to use when encoding the annotated field to JSON. - -Must be a top-level or static `Function` with one parameter compatible -with the field being serialized that returns a JSON-compatible value. - -When creating a class that supports both `toJson` and `fromJson` -(the default), you should also set [`JsonKey.fromJson`](#JsonKey-fromJson) if you set [`JsonKey.toJson`](#JsonKey-toJson). -Values returned by [`JsonKey.toJson`](#JsonKey-toJson) should "round-trip" through [`JsonKey.fromJson`](#JsonKey-fromJson). -
-
+| build key | JsonSerializable | JsonKey | +| -------------------------- | ------------------------------------------- | ------------------------------- | +| any_map | [JsonSerializable.anyMap] | | +| checked | [JsonSerializable.checked] | | +| create_factory | [JsonSerializable.createFactory] | | +| create_to_json | [JsonSerializable.createToJson] | | +| disallow_unrecognized_keys | [JsonSerializable.disallowUnrecognizedKeys] | | +| explicit_to_json | [JsonSerializable.explicitToJson] | | +| field_rename | [JsonSerializable.fieldRename] | | +| generate_to_json_function | [JsonSerializable.generateToJsonFunction] | | +| use_wrappers | [JsonSerializable.useWrappers] | | +| encode_empty_collection | [JsonSerializable.encodeEmptyCollection] | [JsonKey.encodeEmptyCollection] | +| include_if_null | [JsonSerializable.includeIfNull] | [JsonKey.includeIfNull] | +| nullable | [JsonSerializable.nullable] | [JsonKey.nullable] | +| | | [JsonKey.defaultValue] | +| | | [JsonKey.disallowNullValue] | +| | | [JsonKey.fromJson] | +| | | [JsonKey.ignore] | +| | | [JsonKey.name] | +| | | [JsonKey.required] | +| | | [JsonKey.toJson] | + +[JsonSerializable.anyMap]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonSerializable/anyMap.html +[JsonSerializable.checked]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonSerializable/checked.html +[JsonSerializable.createFactory]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonSerializable/createFactory.html +[JsonSerializable.createToJson]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonSerializable/createToJson.html +[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html +[JsonSerializable.explicitToJson]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonSerializable/explicitToJson.html +[JsonSerializable.fieldRename]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonSerializable/fieldRename.html +[JsonSerializable.generateToJsonFunction]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonSerializable/generateToJsonFunction.html +[JsonSerializable.useWrappers]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonSerializable/useWrappers.html +[JsonSerializable.encodeEmptyCollection]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonSerializable/encodeEmptyCollection.html +[JsonKey.encodeEmptyCollection]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonKey/encodeEmptyCollection.html +[JsonSerializable.includeIfNull]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonSerializable/includeIfNull.html +[JsonKey.includeIfNull]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonKey/includeIfNull.html +[JsonSerializable.nullable]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonSerializable/nullable.html +[JsonKey.nullable]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonKey/nullable.html +[JsonKey.defaultValue]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonKey/defaultValue.html +[JsonKey.disallowNullValue]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonKey/disallowNullValue.html +[JsonKey.fromJson]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonKey/fromJson.html +[JsonKey.ignore]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonKey/ignore.html +[JsonKey.name]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonKey/name.html +[JsonKey.required]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonKey/required.html +[JsonKey.toJson]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonKey/toJson.html diff --git a/json_serializable/tool/doc_builder.dart b/json_serializable/tool/doc_builder.dart index 881a716bb..696deb75d 100644 --- a/json_serializable/tool/doc_builder.dart +++ b/json_serializable/tool/doc_builder.dart @@ -1,5 +1,4 @@ import 'dart:async'; -import 'dart:convert'; import 'package:analyzer/dart/element/element.dart'; import 'package:build/build.dart'; @@ -8,44 +7,73 @@ import 'package:source_gen/source_gen.dart'; Builder docBuilder([_]) => _DocBuilder(); +const _jsonKey = 'JsonKey'; +const _jsonSerializable = 'JsonSerializable'; + class _DocBuilder extends Builder { @override FutureOr build(BuildStep buildStep) async { final lib = LibraryReader(await buildStep.resolver.libraryFor( AssetId.resolve('package:json_annotation/json_annotation.dart'))); - final descriptionMap = >{}; + final descriptionMap = {}; for (var className in _annotationClasses) { - final descriptions = <_FieldInfo>[]; - for (var fe in lib.findType(className).fields.where((fe) => !fe.isStatic)) { - descriptions.add(_FieldInfo(className, fe)); + descriptionMap[fe.name] = + _FieldInfo.update(fe, descriptionMap[fe.name]); } - - descriptions.sort(); - - descriptionMap[className] = descriptions; } final buffer = StringBuffer(); - for (var entry in descriptionMap.entries) { - buffer.writeln('

${entry.key}

'); - buffer.writeln('
'); + final rows = >[]; + + rows.add(['build key', _jsonSerializable, _jsonKey]); + rows.add(['-', '-', '-']); - for (var description in entry.value) { - final anchor = _anchorUriForName(entry.key, description.field.name); - buffer.writeln(''' -
${description.parent}.${description.field.name}
-
+ final sortedValues = descriptionMap.values.toList()..sort(); -${description.description} -
'''); + for (var info in sortedValues) { + rows.add([ + info.buildKey, + info.classAnnotationName, + info.fieldAnnotationName, + ]); + } + + final longest = List.generate(rows.first.length, (_) => 0); + for (var row in rows) { + for (var column = 0; column < longest.length; column++) { + if (row[column].length > longest[column]) { + longest[column] = row[column].length; + } } + } - buffer.writeln('
'); + for (var row in rows) { + for (var column = 0; column < longest.length; column++) { + var content = row[column]; + if (content == '-') { + content *= longest[column]; + } else { + content = content.padRight(longest[column]); + } + buffer.write('| $content '); + } + buffer.writeln('|'); + } + + buffer.writeln(); + + for (var info in sortedValues) { + if (info._classField != null) { + buffer.writeln(_link('latest', _jsonSerializable, info.name)); + } + if (info._keyField != null) { + buffer.writeln(_link('latest', _jsonKey, info.name)); + } } await buildStep.writeAsString( @@ -58,71 +86,86 @@ ${description.description} }; } -const _annotationClasses = ['JsonSerializable', 'JsonKey']; +const _annotationClasses = [_jsonSerializable, _jsonKey]; -String _anchorUriForName(String owner, String name) => '$owner-$name'; +String _anchorUriForName(String owner, String name) => '[$owner.$name]'; -class _FieldInfo implements Comparable<_FieldInfo> { - static final _ref = RegExp('\\[([^\\]]+)\\]'); - static final _knownEntities = >{}; +String _link(String version, String owner, String name) => + '${_anchorUriForName(owner, name)}: ' + 'https://pub.dartlang.org/documentation/json_annotation/$version/' + 'json_annotation/$owner/$name.html'; - final String parent; - final FieldElement field; +class _FieldInfo implements Comparable<_FieldInfo> { + final FieldElement _keyField, _classField; - String get description { - var description = - LineSplitter.split(field.documentationComment).map((line) { - if (line.startsWith('///')) { - line = line.substring(3).trimRight(); - } - if (line.startsWith(' ')) { - // If the line is not empty, then it starts with a blank space - line = line.substring(1); - } - return line; - }).join('\n'); - - description = description.replaceAllMapped(_ref, (m) { - final ref = m[1]; - - String refParentClass, refName; - if (_knownEntities[parent].contains(ref)) { - refName = ref; - refParentClass = parent; - } else if (ref.contains('.')) { - final split = ref.split('.'); - if (split.length == 2 && - _annotationClasses.contains(split[0]) && - _knownEntities[split[0]].contains(split[1])) { - refParentClass = split[0]; - refName = split[1]; - } - } + String get name => _keyField?.name ?? _classField.name; - if (refParentClass != null) { - assert(refName != null); - return '[`$refParentClass.$refName`]' - '(#${_anchorUriForName(refParentClass, refName)})'; - } + String get classAnnotationName { + if (_classField == null) { + return ''; + } + return _anchorUriForName(_jsonSerializable, name); + } - return '`$ref`'; - }); + String get fieldAnnotationName { + if (_keyField == null) { + return ''; + } + return _anchorUriForName(_jsonKey, name); + } - if (parent == 'JsonSerializable') { - final yamlConfigKey = snakeCase(field.name); - description = '`build.yaml` config key: `$yamlConfigKey`\n\n$description'; + String get buildKey { + if (_classField == null) { + return ''; } - return description; + return snakeCase(_classField.name); } - _FieldInfo(this.parent, this.field) { - _knownEntities.putIfAbsent(parent, () => Set()).add(field.name); + _FieldInfo(this._keyField, this._classField); + + static _FieldInfo update(FieldElement field, _FieldInfo existing) { + final parent = field.enclosingElement.name; + + FieldElement keyField, classField; + switch (parent) { + case _jsonSerializable: + classField = field; + keyField = existing?._keyField; + break; + case _jsonKey: + keyField = field; + classField = existing?._classField; + break; + default: + throw FallThroughError(); + } + + return _FieldInfo(keyField, classField); } @override - int compareTo(_FieldInfo other) => field.name.compareTo(other.field.name); + int compareTo(_FieldInfo other) { + var value = _sortValue.compareTo(other._sortValue); + + if (value == 0) { + value = name.compareTo(other.name); + } + return value; + } + + int get _sortValue { + if (_classField == null) { + return 0; + } + + if (_keyField == null) { + return -2; + } + + return -1; + } @override - String toString() => '_FieldThing($field)'; + String toString() => '_FieldThing($_keyField)'; } From 1999a3f8981cc2b0b4fc91204648430b05172d16 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 1 Apr 2019 10:51:45 -0700 Subject: [PATCH 092/569] Add annotation doc links to readme Fixes https://github.com/dart-lang/json_serializable/issues/416 --- json_serializable/README.md | 76 +++++++++++++++++++++++-- json_serializable/doc/doc.md | 2 +- json_serializable/test/readme_test.dart | 18 ++++-- json_serializable/tool/doc_builder.dart | 2 +- 4 files changed, 87 insertions(+), 11 deletions(-) diff --git a/json_serializable/README.md b/json_serializable/README.md index 15e6b6cec..071c224cc 100644 --- a/json_serializable/README.md +++ b/json_serializable/README.md @@ -6,9 +6,11 @@ The builders generate code when they find members annotated with classes defined in [package:json_annotation]. - To generate to/from JSON code for a class, annotate it with - `JsonSerializable`. You can provide arguments to `JsonSerializable` to + `@JsonSerializable`. You can provide arguments to `JsonSerializable` to configure the generated code. You can also customize individual fields - by annotating them with `JsonKey` and providing custom arguments. + by annotating them with `@JsonKey` and providing custom arguments. + See the table below for details on the + [annotation values](#annotation-values). - To generate a Dart field with the contents of a file containing JSON, use the `JsonLiteral` annotation. @@ -56,6 +58,73 @@ Map _$PersonToJson(Person instance) => { }; ``` +# Annotation values + +The only annotation required to use this package is `@JsonSerializable`. When +applied to a class (in a correctly configured package), `toJson` and `fromJson` +code will be generated when you build. There are three ways to control how code +is generated: + +1. Set properties on `@JsonSerializable`. +2. Add a `@JsonKey` annotation to a field and set properties there. +3. Add configuration to `build.yaml` – [see below](#build-configuration). + +| `build.yaml` key | JsonSerializable | JsonKey | +| -------------------------- | ------------------------------------------- | ------------------------------- | +| any_map | [JsonSerializable.anyMap] | | +| checked | [JsonSerializable.checked] | | +| create_factory | [JsonSerializable.createFactory] | | +| create_to_json | [JsonSerializable.createToJson] | | +| disallow_unrecognized_keys | [JsonSerializable.disallowUnrecognizedKeys] | | +| explicit_to_json | [JsonSerializable.explicitToJson] | | +| field_rename | [JsonSerializable.fieldRename] | | +| generate_to_json_function | [JsonSerializable.generateToJsonFunction] | | +| use_wrappers | [JsonSerializable.useWrappers] | | +| encode_empty_collection | [JsonSerializable.encodeEmptyCollection] | [JsonKey.encodeEmptyCollection] | +| include_if_null | [JsonSerializable.includeIfNull] | [JsonKey.includeIfNull] | +| nullable | [JsonSerializable.nullable] | [JsonKey.nullable] | +| | | [JsonKey.defaultValue] | +| | | [JsonKey.disallowNullValue] | +| | | [JsonKey.fromJson] | +| | | [JsonKey.ignore] | +| | | [JsonKey.name] | +| | | [JsonKey.required] | +| | | [JsonKey.toJson] | + +[JsonSerializable.anyMap]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonSerializable/anyMap.html +[JsonSerializable.checked]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonSerializable/checked.html +[JsonSerializable.createFactory]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonSerializable/createFactory.html +[JsonSerializable.createToJson]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonSerializable/createToJson.html +[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html +[JsonSerializable.explicitToJson]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonSerializable/explicitToJson.html +[JsonSerializable.fieldRename]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonSerializable/fieldRename.html +[JsonSerializable.generateToJsonFunction]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonSerializable/generateToJsonFunction.html +[JsonSerializable.useWrappers]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonSerializable/useWrappers.html +[JsonSerializable.encodeEmptyCollection]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonSerializable/encodeEmptyCollection.html +[JsonKey.encodeEmptyCollection]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonKey/encodeEmptyCollection.html +[JsonSerializable.includeIfNull]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonSerializable/includeIfNull.html +[JsonKey.includeIfNull]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonKey/includeIfNull.html +[JsonSerializable.nullable]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonSerializable/nullable.html +[JsonKey.nullable]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonKey/nullable.html +[JsonKey.defaultValue]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonKey/defaultValue.html +[JsonKey.disallowNullValue]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonKey/disallowNullValue.html +[JsonKey.fromJson]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonKey/fromJson.html +[JsonKey.ignore]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonKey/ignore.html +[JsonKey.name]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonKey/name.html +[JsonKey.required]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonKey/required.html +[JsonKey.toJson]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonKey/toJson.html + +> Note: every `JsonSerializable` field is configurable via `build.yaml` – + see the table for the corresponding key. + If you find you want all or most of your classes with the same configuration, + it may be easier to specify values once in the YAML file. Values set + explicitly on `@JsonSerializable` take precedence over settings in + `buildy.yaml`. + +> Note: There is some overlap between fields on `JsonKey` and + `JsonSerializable`. In these cases, if a value is set explicitly via `JsonKey` + it will take precedence over any value set on `JsonSerializable`. + # Build configuration Besides setting arguments on the associated annotation classes, you can also @@ -71,9 +140,6 @@ targets: # `@JsonSerializable`-annotated class in the package. # # The default value for each is listed. - # - # For usage information, reference the corresponding field in - # `JsonSerializableGenerator`. any_map: false checked: false create_factory: true diff --git a/json_serializable/doc/doc.md b/json_serializable/doc/doc.md index 3ad862758..efa87dd21 100644 --- a/json_serializable/doc/doc.md +++ b/json_serializable/doc/doc.md @@ -1,4 +1,4 @@ -| build key | JsonSerializable | JsonKey | +| `build.yaml` key | JsonSerializable | JsonKey | | -------------------------- | ------------------------------------------- | ------------------------------- | | any_map | [JsonSerializable.anyMap] | | | checked | [JsonSerializable.checked] | | diff --git a/json_serializable/test/readme_test.dart b/json_serializable/test/readme_test.dart index 5ca6bf84d..c11c50a98 100644 --- a/json_serializable/test/readme_test.dart +++ b/json_serializable/test/readme_test.dart @@ -3,22 +3,32 @@ // BSD-style license that can be found in the LICENSE file. @TestOn('vm') - import 'dart:io'; -import 'package:test/test.dart'; import 'package:path/path.dart' as p; +import 'package:test/test.dart'; void main() { - test('README example', () { - final readmeContent = File('README.md').readAsStringSync(); + String readmeContent; + + setUpAll(() { + readmeContent = File('README.md').readAsStringSync(); + }); + test('example.dart', () { final exampleContent = _getExampleContent('example.dart'); expect(readmeContent, contains(exampleContent)); + }); + test('example.g.dart', () { final exampleGeneratedContent = _getExampleContent('example.g.dart'); expect(readmeContent, contains(exampleGeneratedContent)); }); + + test('doc/doc.md', () { + final docContent = File(p.join('doc', 'doc.md')).readAsStringSync(); + expect(readmeContent, contains(docContent)); + }); } String _getExampleContent(String fileName) { diff --git a/json_serializable/tool/doc_builder.dart b/json_serializable/tool/doc_builder.dart index 696deb75d..769faf786 100644 --- a/json_serializable/tool/doc_builder.dart +++ b/json_serializable/tool/doc_builder.dart @@ -30,7 +30,7 @@ class _DocBuilder extends Builder { final rows = >[]; - rows.add(['build key', _jsonSerializable, _jsonKey]); + rows.add(['`build.yaml` key', _jsonSerializable, _jsonKey]); rows.add(['-', '-', '-']); final sortedValues = descriptionMap.values.toList()..sort(); From a999a095c0b68023a53016f0c8afd62060a2c748 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 1 Apr 2019 11:34:36 -0700 Subject: [PATCH 093/569] README table: Generate links to the correct version of json_annotation If the current version is a release version --- json_serializable/build.yaml | 9 +++++ .../doc/json_annotation_version.txt | 1 + json_serializable/pubspec.yaml | 1 + json_serializable/tool/doc_builder.dart | 22 +++++++++- json_serializable/tool/version_builder.dart | 40 +++++++++++++++++++ 5 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 json_serializable/doc/json_annotation_version.txt create mode 100644 json_serializable/tool/version_builder.dart diff --git a/json_serializable/build.yaml b/json_serializable/build.yaml index e69b41081..c67734a94 100644 --- a/json_serializable/build.yaml +++ b/json_serializable/build.yaml @@ -55,6 +55,14 @@ builders: build_to: source runs_before: ["json_serializable"] + _version_builder: + import: "tool/version_builder.dart" + builder_factories: ["buildVersion"] + build_extensions: {"lib/$lib$": ["doc/json_annotation_version.txt"]} + build_to: source + auto_apply: root_package + runs_before: ["_doc_builder"] + _doc_builder: import: "tool/doc_builder.dart" builder_factories: ["docBuilder"] @@ -62,6 +70,7 @@ builders: build_to: source auto_apply: root_package runs_before: ["json_serializable"] + required_inputs: ["doc/json_annotation_version.txt"] json_serializable: import: "package:json_serializable/builder.dart" diff --git a/json_serializable/doc/json_annotation_version.txt b/json_serializable/doc/json_annotation_version.txt new file mode 100644 index 000000000..c10edc3fa --- /dev/null +++ b/json_serializable/doc/json_annotation_version.txt @@ -0,0 +1 @@ +2.1.0-dev diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index d0a41f57f..66c19e8b3 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -27,6 +27,7 @@ dev_dependencies: collection: ^1.14.0 dart_style: ^1.2.0 logging: ^0.11.3+1 + pub_semver: ^1.4.0 source_gen_test: ^0.1.0 test: ^1.6.0 yaml: ^2.1.13 diff --git a/json_serializable/tool/doc_builder.dart b/json_serializable/tool/doc_builder.dart index 769faf786..660bb3894 100644 --- a/json_serializable/tool/doc_builder.dart +++ b/json_serializable/tool/doc_builder.dart @@ -1,10 +1,16 @@ +// Copyright (c) 2019, 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 'dart:async'; import 'package:analyzer/dart/element/element.dart'; import 'package:build/build.dart'; import 'package:json_serializable/src/utils.dart'; +import 'package:pub_semver/pub_semver.dart'; import 'package:source_gen/source_gen.dart'; +import 'version_builder.dart'; + Builder docBuilder([_]) => _DocBuilder(); const _jsonKey = 'JsonKey'; @@ -13,6 +19,18 @@ const _jsonSerializable = 'JsonSerializable'; class _DocBuilder extends Builder { @override FutureOr build(BuildStep buildStep) async { + final jsonAnnotationVersionAsset = + AssetId(buildStep.inputId.package, jsonAnnotationVersionFile); + + final jsonAnnotationVersionString = + await buildStep.readAsString(jsonAnnotationVersionAsset); + final jsonAnnotationVersion = + Version.parse(jsonAnnotationVersionString.trim()); + + final targetVersion = jsonAnnotationVersion.isPreRelease + ? 'latest' + : jsonAnnotationVersion.toString(); + final lib = LibraryReader(await buildStep.resolver.libraryFor( AssetId.resolve('package:json_annotation/json_annotation.dart'))); @@ -69,10 +87,10 @@ class _DocBuilder extends Builder { for (var info in sortedValues) { if (info._classField != null) { - buffer.writeln(_link('latest', _jsonSerializable, info.name)); + buffer.writeln(_link(targetVersion, _jsonSerializable, info.name)); } if (info._keyField != null) { - buffer.writeln(_link('latest', _jsonKey, info.name)); + buffer.writeln(_link(targetVersion, _jsonKey, info.name)); } } diff --git a/json_serializable/tool/version_builder.dart b/json_serializable/tool/version_builder.dart new file mode 100644 index 000000000..8794b3cff --- /dev/null +++ b/json_serializable/tool/version_builder.dart @@ -0,0 +1,40 @@ +// Copyright (c) 2019, 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 'dart:async'; + +import 'package:build/build.dart'; +import 'package:yaml/yaml.dart'; + +const jsonAnnotationVersionFile = 'doc/json_annotation_version.txt'; + +Builder buildVersion([BuilderOptions options]) => _VersionBuilder(); + +/// Extracts the version of `package:json_annotation` for the currently +/// solved version locally. Used to populate the currently versioned URL +/// when linked to docs. +class _VersionBuilder implements Builder { + @override + Future build(BuildStep buildStep) async { + final assetId = AssetId(buildStep.inputId.package, 'pubspec.lock'); + + final content = await buildStep.readAsString(assetId); + + final yaml = loadYaml(content, sourceUrl: assetId.uri); + + final pkgMap = yaml['packages'] as YamlMap; + final jsonAnnotationMap = pkgMap['json_annotation'] as YamlMap; + final version = jsonAnnotationMap['version'] as String; + + await buildStep.writeAsString( + AssetId(buildStep.inputId.package, jsonAnnotationVersionFile), ''' +$version +'''); + } + + @override + final buildExtensions = const { + r'lib/$lib$': [jsonAnnotationVersionFile] + }; +} From 2b62387a62819b0e4273ff90b140bcdc4f032390 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 1 Apr 2019 14:29:58 -0700 Subject: [PATCH 094/569] Update json_annotation to published version --- json_serializable/README.md | 44 +++++++++---------- json_serializable/doc/doc.md | 44 +++++++++---------- .../doc/json_annotation_version.txt | 2 +- json_serializable/pubspec.yaml | 6 +-- 4 files changed, 46 insertions(+), 50 deletions(-) diff --git a/json_serializable/README.md b/json_serializable/README.md index 071c224cc..920d74f62 100644 --- a/json_serializable/README.md +++ b/json_serializable/README.md @@ -91,28 +91,28 @@ is generated: | | | [JsonKey.required] | | | | [JsonKey.toJson] | -[JsonSerializable.anyMap]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonSerializable/anyMap.html -[JsonSerializable.checked]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonSerializable/checked.html -[JsonSerializable.createFactory]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonSerializable/createFactory.html -[JsonSerializable.createToJson]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonSerializable/createToJson.html -[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html -[JsonSerializable.explicitToJson]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonSerializable/explicitToJson.html -[JsonSerializable.fieldRename]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonSerializable/fieldRename.html -[JsonSerializable.generateToJsonFunction]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonSerializable/generateToJsonFunction.html -[JsonSerializable.useWrappers]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonSerializable/useWrappers.html -[JsonSerializable.encodeEmptyCollection]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonSerializable/encodeEmptyCollection.html -[JsonKey.encodeEmptyCollection]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonKey/encodeEmptyCollection.html -[JsonSerializable.includeIfNull]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonSerializable/includeIfNull.html -[JsonKey.includeIfNull]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonKey/includeIfNull.html -[JsonSerializable.nullable]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonSerializable/nullable.html -[JsonKey.nullable]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonKey/nullable.html -[JsonKey.defaultValue]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonKey/defaultValue.html -[JsonKey.disallowNullValue]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonKey/disallowNullValue.html -[JsonKey.fromJson]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonKey/fromJson.html -[JsonKey.ignore]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonKey/ignore.html -[JsonKey.name]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonKey/name.html -[JsonKey.required]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonKey/required.html -[JsonKey.toJson]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonKey/toJson.html +[JsonSerializable.anyMap]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonSerializable/anyMap.html +[JsonSerializable.checked]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonSerializable/checked.html +[JsonSerializable.createFactory]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonSerializable/createFactory.html +[JsonSerializable.createToJson]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonSerializable/createToJson.html +[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html +[JsonSerializable.explicitToJson]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonSerializable/explicitToJson.html +[JsonSerializable.fieldRename]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonSerializable/fieldRename.html +[JsonSerializable.generateToJsonFunction]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonSerializable/generateToJsonFunction.html +[JsonSerializable.useWrappers]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonSerializable/useWrappers.html +[JsonSerializable.encodeEmptyCollection]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonSerializable/encodeEmptyCollection.html +[JsonKey.encodeEmptyCollection]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonKey/encodeEmptyCollection.html +[JsonSerializable.includeIfNull]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonSerializable/includeIfNull.html +[JsonKey.includeIfNull]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonKey/includeIfNull.html +[JsonSerializable.nullable]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonSerializable/nullable.html +[JsonKey.nullable]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonKey/nullable.html +[JsonKey.defaultValue]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonKey/defaultValue.html +[JsonKey.disallowNullValue]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonKey/disallowNullValue.html +[JsonKey.fromJson]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonKey/fromJson.html +[JsonKey.ignore]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonKey/ignore.html +[JsonKey.name]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonKey/name.html +[JsonKey.required]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonKey/required.html +[JsonKey.toJson]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonKey/toJson.html > Note: every `JsonSerializable` field is configurable via `build.yaml` – see the table for the corresponding key. diff --git a/json_serializable/doc/doc.md b/json_serializable/doc/doc.md index efa87dd21..fe1cb95a6 100644 --- a/json_serializable/doc/doc.md +++ b/json_serializable/doc/doc.md @@ -20,25 +20,25 @@ | | | [JsonKey.required] | | | | [JsonKey.toJson] | -[JsonSerializable.anyMap]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonSerializable/anyMap.html -[JsonSerializable.checked]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonSerializable/checked.html -[JsonSerializable.createFactory]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonSerializable/createFactory.html -[JsonSerializable.createToJson]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonSerializable/createToJson.html -[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html -[JsonSerializable.explicitToJson]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonSerializable/explicitToJson.html -[JsonSerializable.fieldRename]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonSerializable/fieldRename.html -[JsonSerializable.generateToJsonFunction]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonSerializable/generateToJsonFunction.html -[JsonSerializable.useWrappers]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonSerializable/useWrappers.html -[JsonSerializable.encodeEmptyCollection]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonSerializable/encodeEmptyCollection.html -[JsonKey.encodeEmptyCollection]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonKey/encodeEmptyCollection.html -[JsonSerializable.includeIfNull]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonSerializable/includeIfNull.html -[JsonKey.includeIfNull]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonKey/includeIfNull.html -[JsonSerializable.nullable]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonSerializable/nullable.html -[JsonKey.nullable]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonKey/nullable.html -[JsonKey.defaultValue]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonKey/defaultValue.html -[JsonKey.disallowNullValue]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonKey/disallowNullValue.html -[JsonKey.fromJson]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonKey/fromJson.html -[JsonKey.ignore]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonKey/ignore.html -[JsonKey.name]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonKey/name.html -[JsonKey.required]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonKey/required.html -[JsonKey.toJson]: https://pub.dartlang.org/documentation/json_annotation/latest/json_annotation/JsonKey/toJson.html +[JsonSerializable.anyMap]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonSerializable/anyMap.html +[JsonSerializable.checked]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonSerializable/checked.html +[JsonSerializable.createFactory]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonSerializable/createFactory.html +[JsonSerializable.createToJson]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonSerializable/createToJson.html +[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html +[JsonSerializable.explicitToJson]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonSerializable/explicitToJson.html +[JsonSerializable.fieldRename]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonSerializable/fieldRename.html +[JsonSerializable.generateToJsonFunction]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonSerializable/generateToJsonFunction.html +[JsonSerializable.useWrappers]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonSerializable/useWrappers.html +[JsonSerializable.encodeEmptyCollection]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonSerializable/encodeEmptyCollection.html +[JsonKey.encodeEmptyCollection]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonKey/encodeEmptyCollection.html +[JsonSerializable.includeIfNull]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonSerializable/includeIfNull.html +[JsonKey.includeIfNull]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonKey/includeIfNull.html +[JsonSerializable.nullable]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonSerializable/nullable.html +[JsonKey.nullable]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonKey/nullable.html +[JsonKey.defaultValue]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonKey/defaultValue.html +[JsonKey.disallowNullValue]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonKey/disallowNullValue.html +[JsonKey.fromJson]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonKey/fromJson.html +[JsonKey.ignore]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonKey/ignore.html +[JsonKey.name]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonKey/name.html +[JsonKey.required]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonKey/required.html +[JsonKey.toJson]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonKey/toJson.html diff --git a/json_serializable/doc/json_annotation_version.txt b/json_serializable/doc/json_annotation_version.txt index c10edc3fa..7ec1d6db4 100644 --- a/json_serializable/doc/json_annotation_version.txt +++ b/json_serializable/doc/json_annotation_version.txt @@ -1 +1 @@ -2.1.0-dev +2.1.0 diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 66c19e8b3..ba76a57e8 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -15,7 +15,7 @@ dependencies: # Use a tight version constraint to ensure that a constraint on # `json_annotation` properly constrains all features it provides. - json_annotation: '>=2.0.0 <2.1.0' + json_annotation: '>=2.1.0 <2.2.0' meta: ^1.1.0 path: ^1.3.2 source_gen: ^0.9.0 @@ -31,7 +31,3 @@ dev_dependencies: source_gen_test: ^0.1.0 test: ^1.6.0 yaml: ^2.1.13 - -dependency_overrides: - json_annotation: - path: ../json_annotation From e74ea880820c18028d2556d4a1f6a117350f2051 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 1 Apr 2019 14:49:07 -0700 Subject: [PATCH 095/569] Eliminate superfluous version builder --- json_serializable/build.yaml | 8 ---- .../doc/json_annotation_version.txt | 1 - json_serializable/tool/doc_builder.dart | 14 ++++--- json_serializable/tool/version_builder.dart | 40 ------------------- 4 files changed, 8 insertions(+), 55 deletions(-) delete mode 100644 json_serializable/doc/json_annotation_version.txt delete mode 100644 json_serializable/tool/version_builder.dart diff --git a/json_serializable/build.yaml b/json_serializable/build.yaml index c67734a94..43c300205 100644 --- a/json_serializable/build.yaml +++ b/json_serializable/build.yaml @@ -55,14 +55,6 @@ builders: build_to: source runs_before: ["json_serializable"] - _version_builder: - import: "tool/version_builder.dart" - builder_factories: ["buildVersion"] - build_extensions: {"lib/$lib$": ["doc/json_annotation_version.txt"]} - build_to: source - auto_apply: root_package - runs_before: ["_doc_builder"] - _doc_builder: import: "tool/doc_builder.dart" builder_factories: ["docBuilder"] diff --git a/json_serializable/doc/json_annotation_version.txt b/json_serializable/doc/json_annotation_version.txt deleted file mode 100644 index 7ec1d6db4..000000000 --- a/json_serializable/doc/json_annotation_version.txt +++ /dev/null @@ -1 +0,0 @@ -2.1.0 diff --git a/json_serializable/tool/doc_builder.dart b/json_serializable/tool/doc_builder.dart index 660bb3894..a9a098a6a 100644 --- a/json_serializable/tool/doc_builder.dart +++ b/json_serializable/tool/doc_builder.dart @@ -8,8 +8,7 @@ import 'package:build/build.dart'; import 'package:json_serializable/src/utils.dart'; import 'package:pub_semver/pub_semver.dart'; import 'package:source_gen/source_gen.dart'; - -import 'version_builder.dart'; +import 'package:yaml/yaml.dart'; Builder docBuilder([_]) => _DocBuilder(); @@ -19,11 +18,14 @@ const _jsonSerializable = 'JsonSerializable'; class _DocBuilder extends Builder { @override FutureOr build(BuildStep buildStep) async { - final jsonAnnotationVersionAsset = - AssetId(buildStep.inputId.package, jsonAnnotationVersionFile); + final lockFileAssetId = AssetId(buildStep.inputId.package, 'pubspec.lock'); + final lockFileContent = await buildStep.readAsString(lockFileAssetId); + final lockFileYaml = + loadYaml(lockFileContent, sourceUrl: lockFileAssetId.uri); + final pkgMap = lockFileYaml['packages'] as YamlMap; + final jsonAnnotationMap = pkgMap['json_annotation'] as YamlMap; + final jsonAnnotationVersionString = jsonAnnotationMap['version'] as String; - final jsonAnnotationVersionString = - await buildStep.readAsString(jsonAnnotationVersionAsset); final jsonAnnotationVersion = Version.parse(jsonAnnotationVersionString.trim()); diff --git a/json_serializable/tool/version_builder.dart b/json_serializable/tool/version_builder.dart deleted file mode 100644 index 8794b3cff..000000000 --- a/json_serializable/tool/version_builder.dart +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (c) 2019, 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 'dart:async'; - -import 'package:build/build.dart'; -import 'package:yaml/yaml.dart'; - -const jsonAnnotationVersionFile = 'doc/json_annotation_version.txt'; - -Builder buildVersion([BuilderOptions options]) => _VersionBuilder(); - -/// Extracts the version of `package:json_annotation` for the currently -/// solved version locally. Used to populate the currently versioned URL -/// when linked to docs. -class _VersionBuilder implements Builder { - @override - Future build(BuildStep buildStep) async { - final assetId = AssetId(buildStep.inputId.package, 'pubspec.lock'); - - final content = await buildStep.readAsString(assetId); - - final yaml = loadYaml(content, sourceUrl: assetId.uri); - - final pkgMap = yaml['packages'] as YamlMap; - final jsonAnnotationMap = pkgMap['json_annotation'] as YamlMap; - final version = jsonAnnotationMap['version'] as String; - - await buildStep.writeAsString( - AssetId(buildStep.inputId.package, jsonAnnotationVersionFile), ''' -$version -'''); - } - - @override - final buildExtensions = const { - r'lib/$lib$': [jsonAnnotationVersionFile] - }; -} From c7015845bca76563e339a257a6f9fbb571bdca90 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 1 Apr 2019 14:49:39 -0700 Subject: [PATCH 096/569] Prepare to release json_serializable v2.1.0 --- json_serializable/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index ba76a57e8..d0611fdff 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 2.1.0-dev +version: 2.1.0 author: Dart Team description: >- Automatically generate code for converting to and from JSON by annotating From b950dd2cab827e5e53716862486ccd60632e631b Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 3 Apr 2019 17:44:04 -0700 Subject: [PATCH 097/569] Support the latest pkg:analyzer, prepare to release 2.1.1 --- json_serializable/CHANGELOG.md | 4 ++++ json_serializable/pubspec.yaml | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 04f01f772..58b5a5706 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.1.1 + +* Support `package:analyzer` `>=0.33.3 <0.37.0` + ## 2.1.0 * Require at least Dart `2.1.1`. diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index d0611fdff..50bbe2285 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 2.1.0 +version: 2.1.1 author: Dart Team description: >- Automatically generate code for converting to and from JSON by annotating @@ -9,7 +9,7 @@ environment: sdk: '>=2.1.1 <3.0.0' dependencies: - analyzer: '>=0.33.3 <0.36.0' + analyzer: '>=0.33.3 <0.37.0' build: '>=0.12.6 <2.0.0' build_config: '>=0.2.6 <0.4.0' From 7807337d0d58ed41c78877e73d83b9fdc5d2cac0 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 3 Apr 2019 17:50:45 -0700 Subject: [PATCH 098/569] Travis: skip dartfmt task on dev while we're waiting on dart_style issue https://github.com/dart-lang/dart_style/issues/799 --- .travis.yml | 9 +++++++-- json_serializable/mono_pkg.yaml | 3 ++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7cb83c767..d0b448df4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,9 +12,9 @@ branches: jobs: include: - stage: analyzer_and_format - name: "SDK: dev; PKGS: example, json_annotation, json_serializable; TASKS: [`dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-warnings --fatal-infos .`]" + name: "SDK: dev; PKGS: example, json_annotation; TASKS: [`dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-warnings --fatal-infos .`]" dart: dev - env: PKGS="example json_annotation json_serializable" + env: PKGS="example json_annotation" script: ./tool/travis.sh dartfmt dartanalyzer_0 - stage: analyzer_and_format name: "SDK: 2.1.1; PKGS: example, json_annotation, json_serializable; TASKS: [`dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-warnings .`]" @@ -31,6 +31,11 @@ jobs: dart: dev env: PKGS="example" script: ./tool/travis.sh test_0 + - stage: analyzer_and_format + name: "SDK: dev; PKG: json_serializable; TASKS: `dartanalyzer --fatal-warnings --fatal-infos .`" + dart: dev + env: PKGS="json_serializable" + script: ./tool/travis.sh dartanalyzer_0 - stage: unit_test name: "SDK: 2.1.1; PKG: json_serializable; TASKS: `pub run test`" dart: "2.1.1" diff --git a/json_serializable/mono_pkg.yaml b/json_serializable/mono_pkg.yaml index 8754b9fe4..d199ec3a8 100644 --- a/json_serializable/mono_pkg.yaml +++ b/json_serializable/mono_pkg.yaml @@ -6,7 +6,8 @@ dart: stages: - analyzer_and_format: - group: - - dartfmt + # skipping while https://github.com/dart-lang/dart_style/issues/799 is live + #- dartfmt - dartanalyzer: --fatal-warnings --fatal-infos . dart: [dev] - group: From 86834a0566194c3d769f33e036dd9d504ec2c298 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 8 Apr 2019 08:42:19 -0700 Subject: [PATCH 099/569] travis: Enable, fix dartfmt on latest dev SDK (#436) --- .travis.yml | 14 ++++++------ json_serializable/lib/src/json_key_utils.dart | 2 +- json_serializable/mono_pkg.yaml | 4 +--- .../src/_json_serializable_test_input.dart | 22 +++++++++---------- .../test/src/default_value_input.dart | 14 ++++++------ .../test/src/json_converter_test_input.dart | 2 +- .../test/src/to_from_json_test_input.dart | 14 ++++++------ .../test/src/unknown_type_test_input.dart | 6 ++--- 8 files changed, 38 insertions(+), 40 deletions(-) diff --git a/.travis.yml b/.travis.yml index d0b448df4..c3c77da45 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,14 +12,14 @@ branches: jobs: include: - stage: analyzer_and_format - name: "SDK: dev; PKGS: example, json_annotation; TASKS: [`dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-warnings --fatal-infos .`]" + name: "SDK: dev; PKGS: example, json_annotation, json_serializable; TASKS: [`dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-warnings --fatal-infos .`]" dart: dev - env: PKGS="example json_annotation" + env: PKGS="example json_annotation json_serializable" script: ./tool/travis.sh dartfmt dartanalyzer_0 - stage: analyzer_and_format - name: "SDK: 2.1.1; PKGS: example, json_annotation, json_serializable; TASKS: [`dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-warnings .`]" + name: "SDK: 2.1.1; PKGS: example, json_annotation; TASKS: [`dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-warnings .`]" dart: "2.1.1" - env: PKGS="example json_annotation json_serializable" + env: PKGS="example json_annotation" script: ./tool/travis.sh dartfmt dartanalyzer_1 - stage: unit_test name: "SDK: 2.1.1; PKG: example; TASKS: `pub run test --run-skipped`" @@ -32,10 +32,10 @@ jobs: env: PKGS="example" script: ./tool/travis.sh test_0 - stage: analyzer_and_format - name: "SDK: dev; PKG: json_serializable; TASKS: `dartanalyzer --fatal-warnings --fatal-infos .`" - dart: dev + name: "SDK: 2.1.1; PKG: json_serializable; TASKS: `dartanalyzer --fatal-warnings .`" + dart: "2.1.1" env: PKGS="json_serializable" - script: ./tool/travis.sh dartanalyzer_0 + script: ./tool/travis.sh dartanalyzer_1 - stage: unit_test name: "SDK: 2.1.1; PKG: json_serializable; TASKS: `pub run test`" dart: "2.1.1" diff --git a/json_serializable/lib/src/json_key_utils.dart b/json_serializable/lib/src/json_key_utils.dart index 097ea1fe2..749e0094c 100644 --- a/json_serializable/lib/src/json_key_utils.dart +++ b/json_serializable/lib/src/json_key_utils.dart @@ -149,7 +149,7 @@ JsonKey _populateJsonKey( throwUnsupported( element, '`encodeEmptyCollection: false` is only valid fields of type ' - 'Iterable, List, Set, or Map.', + 'Iterable, List, Set, or Map.', ); } diff --git a/json_serializable/mono_pkg.yaml b/json_serializable/mono_pkg.yaml index d199ec3a8..5b41699ab 100644 --- a/json_serializable/mono_pkg.yaml +++ b/json_serializable/mono_pkg.yaml @@ -6,12 +6,10 @@ dart: stages: - analyzer_and_format: - group: - # skipping while https://github.com/dart-lang/dart_style/issues/799 is live - #- dartfmt + - dartfmt - dartanalyzer: --fatal-warnings --fatal-infos . dart: [dev] - group: - - dartfmt - dartanalyzer: --fatal-warnings . dart: [2.1.1] - unit_test: diff --git a/json_serializable/test/src/_json_serializable_test_input.dart b/json_serializable/test/src/_json_serializable_test_input.dart index ef7b52d71..55e819096 100644 --- a/json_serializable/test/src/_json_serializable_test_input.dart +++ b/json_serializable/test/src/_json_serializable_test_input.dart @@ -226,7 +226,7 @@ class SetSupport { @ShouldThrow( 'Could not generate `toJson` code for `watch`.\n' - 'None of the provided `TypeHelper` instances support the defined type.', + 'None of the provided `TypeHelper` instances support the defined type.', configurations: ['default'], ) @JsonSerializable(createFactory: false) @@ -236,7 +236,7 @@ class NoSerializeFieldType { @ShouldThrow( 'Could not generate `fromJson` code for `watch`.\n' - 'None of the provided `TypeHelper` instances support the defined type.', + 'None of the provided `TypeHelper` instances support the defined type.', configurations: ['default'], ) @JsonSerializable(createToJson: false) @@ -246,7 +246,7 @@ class NoDeserializeFieldType { @ShouldThrow( 'Could not generate `toJson` code for `intDateTimeMap` because of type `int`.\n' - 'Map keys must be of type `String`, enum, `Object` or `dynamic`.', + 'Map keys must be of type `String`, enum, `Object` or `dynamic`.', configurations: ['default'], ) @JsonSerializable(createFactory: false) @@ -256,7 +256,7 @@ class NoSerializeBadKey { @ShouldThrow( 'Could not generate `fromJson` code for `intDateTimeMap` because of type `int`.\n' - 'Map keys must be of type `String`, enum, `Object` or `dynamic`.', + 'Map keys must be of type `String`, enum, `Object` or `dynamic`.', configurations: ['default'], ) @JsonSerializable(createToJson: false) @@ -354,7 +354,7 @@ class IgnoredFieldClass { @ShouldThrow( 'Cannot populate the required constructor argument: ' - 'ignoredTrueField. It is assigned to an ignored field.', + 'ignoredTrueField. It is assigned to an ignored field.', element: '', ) @JsonSerializable() @@ -367,7 +367,7 @@ class IgnoredFieldCtorClass { @ShouldThrow( 'Cannot populate the required constructor argument: ' - '_privateField. It is assigned to a private field.', + '_privateField. It is assigned to a private field.', element: '', ) @JsonSerializable() @@ -380,8 +380,8 @@ class PrivateFieldCtorClass { @ShouldThrow( 'Error with `@JsonKey` on `field`. ' - 'Cannot set both `disallowNullvalue` and `includeIfNull` to `true`. ' - 'This leads to incompatible `toJson` and `fromJson` behavior.', + 'Cannot set both `disallowNullvalue` and `includeIfNull` to `true`. ' + 'This leads to incompatible `toJson` and `fromJson` behavior.', element: 'field', ) @JsonSerializable() @@ -392,7 +392,7 @@ class IncludeIfNullDisallowNullClass { @ShouldThrow( 'The `JsonValue` annotation on `BadEnum.value` does not have a value ' - 'of type String, int, or null.', + 'of type String, int, or null.', element: 'value', ) @JsonSerializable() @@ -506,7 +506,7 @@ class EncodeEmptyCollectionAsNullOnField { @ShouldThrow( 'Error with `@JsonKey` on `field`. `encodeEmptyCollection: false` is only ' - 'valid fields of type Iterable, List, Set, or Map.', + 'valid fields of type Iterable, List, Set, or Map.', element: 'field', ) @JsonSerializable() @@ -517,7 +517,7 @@ class EncodeEmptyCollectionAsNullOnNonCollectionField { @ShouldThrow( 'Error with `@JsonKey` on `field`. Cannot set `encodeEmptyCollection: false` ' - 'if `includeIfNull: true`.', + 'if `includeIfNull: true`.', element: 'field', ) @JsonSerializable() diff --git a/json_serializable/test/src/default_value_input.dart b/json_serializable/test/src/default_value_input.dart index 37261fdc5..3884868c4 100644 --- a/json_serializable/test/src/default_value_input.dart +++ b/json_serializable/test/src/default_value_input.dart @@ -6,7 +6,7 @@ part of '_json_serializable_test_input.dart'; @ShouldThrow( 'Error with `@JsonKey` on `field`. ' - '`defaultValue` is `Symbol`, it must be a literal.', + '`defaultValue` is `Symbol`, it must be a literal.', element: 'field', ) @JsonSerializable() @@ -21,7 +21,7 @@ int _function() => 42; @ShouldThrow( 'Error with `@JsonKey` on `field`. ' - '`defaultValue` is `Function`, it must be a literal.', + '`defaultValue` is `Function`, it must be a literal.', element: 'field', ) @JsonSerializable() @@ -34,7 +34,7 @@ class DefaultWithFunction { @ShouldThrow( 'Error with `@JsonKey` on `field`. ' - '`defaultValue` is `Type`, it must be a literal.', + '`defaultValue` is `Type`, it must be a literal.', element: 'field', ) @JsonSerializable() @@ -47,7 +47,7 @@ class DefaultWithType { @ShouldThrow( 'Error with `@JsonKey` on `field`. ' - '`defaultValue` is `Duration`, it must be a literal.', + '`defaultValue` is `Duration`, it must be a literal.', element: 'field', ) @JsonSerializable() @@ -62,7 +62,7 @@ enum Enum { value } @ShouldThrow( 'Error with `@JsonKey` on `field`. ' - '`defaultValue` is `List > Enum`, it must be a literal.', + '`defaultValue` is `List > Enum`, it must be a literal.', element: 'field', ) @JsonSerializable() @@ -75,7 +75,7 @@ class DefaultWithNestedEnum { @ShouldThrow( 'Error with `@JsonKey` on `field`. ' - 'Cannot use `defaultValue` on a field with `nullable` false.', + 'Cannot use `defaultValue` on a field with `nullable` false.', element: 'field', ) @JsonSerializable() @@ -88,7 +88,7 @@ class DefaultWithNonNullableField { @ShouldThrow( 'Error with `@JsonKey` on `field`. ' - 'Cannot use `defaultValue` on a field with `nullable` false.', + 'Cannot use `defaultValue` on a field with `nullable` false.', element: 'field', ) @JsonSerializable(nullable: false) diff --git a/json_serializable/test/src/json_converter_test_input.dart b/json_serializable/test/src/json_converter_test_input.dart index 854f37d25..d5effffae 100644 --- a/json_serializable/test/src/json_converter_test_input.dart +++ b/json_serializable/test/src/json_converter_test_input.dart @@ -124,7 +124,7 @@ class _GenericConverter implements JsonConverter { @ShouldThrow( '`JsonConverter` implementations can have no more than one type argument. ' - '`_BadConverter` has 2.', + '`_BadConverter` has 2.', element: '_BadConverter', ) @JsonSerializable() diff --git a/json_serializable/test/src/to_from_json_test_input.dart b/json_serializable/test/src/to_from_json_test_input.dart index 32f9486f5..54cbddb33 100644 --- a/json_serializable/test/src/to_from_json_test_input.dart +++ b/json_serializable/test/src/to_from_json_test_input.dart @@ -14,7 +14,7 @@ Object _toObject(Object input) => null; @ShouldThrow( 'Error with `@JsonKey` on `field`. The `fromJson` function `_toInt` ' - 'return type `int` is not compatible with field type `String`.', + 'return type `int` is not compatible with field type `String`.', element: 'field', ) @JsonSerializable() @@ -25,7 +25,7 @@ class BadFromFuncReturnType { @ShouldThrow( 'Error with `@JsonKey` on `field`. The `fromJson` function ' - '`_twoArgFunction` must have one positional paramater.', + '`_twoArgFunction` must have one positional paramater.', element: 'field', ) @JsonSerializable() @@ -64,7 +64,7 @@ class ValidToFromFuncClassStatic { @ShouldThrow( 'Error with `@JsonKey` on `field`. The `toJson` function `_toInt` ' - 'argument type `bool` is not compatible with field type `String`.', + 'argument type `bool` is not compatible with field type `String`.', element: 'field', ) @JsonSerializable() @@ -75,7 +75,7 @@ class BadToFuncReturnType { @ShouldThrow( 'Error with `@JsonKey` on `field`. The `toJson` function ' - '`_twoArgFunction` must have one positional paramater.', + '`_twoArgFunction` must have one positional paramater.', element: 'field', ) @JsonSerializable() @@ -156,7 +156,7 @@ String _noArgs() => null; @ShouldThrow( 'Error with `@JsonKey` on `field`. The `fromJson` function ' - '`_noArgs` must have one positional paramater.', + '`_noArgs` must have one positional paramater.', element: 'field', ) @JsonSerializable(createToJson: false) @@ -169,7 +169,7 @@ String _twoArgs(a, b) => null; @ShouldThrow( 'Error with `@JsonKey` on `field`. The `fromJson` function ' - '`_twoArgs` must have one positional paramater.', + '`_twoArgs` must have one positional paramater.', element: 'field', ) @JsonSerializable(createToJson: false) @@ -182,7 +182,7 @@ String _oneNamed({a}) => null; @ShouldThrow( 'Error with `@JsonKey` on `field`. The `fromJson` function ' - '`_oneNamed` must have one positional paramater.', + '`_oneNamed` must have one positional paramater.', element: 'field', ) @JsonSerializable(createToJson: false) diff --git a/json_serializable/test/src/unknown_type_test_input.dart b/json_serializable/test/src/unknown_type_test_input.dart index fe540e21f..ff36f0c37 100644 --- a/json_serializable/test/src/unknown_type_test_input.dart +++ b/json_serializable/test/src/unknown_type_test_input.dart @@ -2,7 +2,7 @@ part of '_json_serializable_test_input.dart'; @ShouldThrow( 'Could not generate `fromJson` code for `number` because the type ' - 'is undefined.', + 'is undefined.', expectedLogItems: [ ''' This element has an undefined type. It may causes issues when generated code. @@ -27,7 +27,7 @@ class UnknownCtorParamType { @ShouldThrow( 'Could not generate `fromJson` code for `number` because the type ' - 'is undefined.', + 'is undefined.', expectedLogItems: [ ''' This element has an undefined type. It may causes issues when generated code. @@ -50,7 +50,7 @@ class UnknownFieldType { @ShouldThrow( 'Could not generate `toJson` code for `number` because the type ' - 'is undefined.', + 'is undefined.', expectedLogItems: [ ''' This element has an undefined type. It may causes issues when generated code. From ffa68a04723c3a83f3eaf2c8d5644070694e7790 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 8 Apr 2019 17:23:29 -0700 Subject: [PATCH 100/569] Remove gratuitous CONTRIBUTING.md, AUTHORS from json_serializable dir --- json_serializable/AUTHORS | 6 ------ json_serializable/CONTRIBUTING.md | 33 ------------------------------- 2 files changed, 39 deletions(-) delete mode 100644 json_serializable/AUTHORS delete mode 100644 json_serializable/CONTRIBUTING.md diff --git a/json_serializable/AUTHORS b/json_serializable/AUTHORS deleted file mode 100644 index e8063a8cd..000000000 --- a/json_serializable/AUTHORS +++ /dev/null @@ -1,6 +0,0 @@ -# Below is a list of people and organizations that have contributed -# to the project. Names should be added to the list like so: -# -# Name/Organization - -Google Inc. diff --git a/json_serializable/CONTRIBUTING.md b/json_serializable/CONTRIBUTING.md deleted file mode 100644 index 6f5e0ea67..000000000 --- a/json_serializable/CONTRIBUTING.md +++ /dev/null @@ -1,33 +0,0 @@ -Want to contribute? Great! First, read this page (including the small print at -the end). - -### Before you contribute -Before we can use your code, you must sign the -[Google Individual Contributor License Agreement](https://cla.developers.google.com/about/google-individual) -(CLA), which you can do online. The CLA is necessary mainly because you own the -copyright to your changes, even after your contribution becomes part of our -codebase, so we need your permission to use and distribute your code. We also -need to be sure of various other things—for instance that you'll tell us if you -know that your code infringes on other people's patents. You don't have to sign -the CLA until after you've submitted your code for review and a member has -approved it, but you must do it before we can put your code into our codebase. - -Before you start working on a larger contribution, you should get in touch with -us first through the issue tracker with your idea so that we can help out and -possibly guide you. Coordinating up front makes it much easier to avoid -frustration later on. - -### Code reviews -All submissions, including submissions by project members, require review. - -### File headers -All files in the project must start with the following header. - - // Copyright (c) 2015, 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. - -### The small print -Contributions made by corporations are covered by a different agreement than the -one above, the -[Software Grant and Corporate Contributor License Agreement](https://developers.google.com/open-source/cla/corporate). From 3d8be282a86d9781e242fcc88b8142ae48f460c8 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 9 Apr 2019 08:49:31 -0700 Subject: [PATCH 101/569] Add `badKey` field to CheckedFromJsonException, bump versions, release Towards https://github.com/dart-lang/json_serializable/issues/437 --- json_annotation/CHANGELOG.md | 5 ++++ json_annotation/lib/src/checked_helpers.dart | 24 ++++++++++++++++---- json_annotation/mono_pkg.yaml | 2 -- json_annotation/pubspec.yaml | 2 +- json_serializable/CHANGELOG.md | 4 ++++ json_serializable/pubspec.yaml | 4 ++-- 6 files changed, 31 insertions(+), 10 deletions(-) diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index 4f77933ab..2c998d940 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -1,3 +1,8 @@ +## 2.2.0 + +* Add an optional (named) `badKey` parameter and field to + `CheckedFromJsonException`. + ## 2.1.0 * Require at least Dart `2.1.1`. diff --git a/json_annotation/lib/src/checked_helpers.dart b/json_annotation/lib/src/checked_helpers.dart index 8212aec41..8c91c49f8 100644 --- a/json_annotation/lib/src/checked_helpers.dart +++ b/json_annotation/lib/src/checked_helpers.dart @@ -79,16 +79,30 @@ class CheckedFromJsonException implements Exception { String get className => _className; String _className; + /// If this was thrown due to an invalid or unsupported key, as opposed to an + /// invalid value. + final bool badKey; + /// Creates a new instance of [CheckedFromJsonException]. - CheckedFromJsonException(this.map, this.key, String className, this.message) - : _className = className, + CheckedFromJsonException( + this.map, + this.key, + String className, + this.message, { + bool badKey = false, + }) : _className = className, + badKey = badKey ?? false, innerError = null, innerStack = null; CheckedFromJsonException._( - this.innerError, this.innerStack, this.map, this.key, - {String className}) - : _className = className, + this.innerError, + this.innerStack, + this.map, + this.key, { + String className, + }) : _className = className, + badKey = innerError is BadKeyException, message = _getMessage(innerError); static String _getMessage(Object error) { diff --git a/json_annotation/mono_pkg.yaml b/json_annotation/mono_pkg.yaml index b23291f40..f939b9d38 100644 --- a/json_annotation/mono_pkg.yaml +++ b/json_annotation/mono_pkg.yaml @@ -9,5 +9,3 @@ stages: - dartfmt - dartanalyzer: --fatal-warnings . dart: [2.1.1] - - diff --git a/json_annotation/pubspec.yaml b/json_annotation/pubspec.yaml index 624aea1c5..9a6d185ba 100644 --- a/json_annotation/pubspec.yaml +++ b/json_annotation/pubspec.yaml @@ -1,5 +1,5 @@ name: json_annotation -version: 2.1.0 +version: 2.2.0 description: >- Classes and helper functions that support JSON code generation via the `json_serializable` package. diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 58b5a5706..a17316201 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,7 @@ +## 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` diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 50bbe2285..4106d5ea8 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 2.1.1 +version: 2.1.2 author: Dart Team description: >- Automatically generate code for converting to and from JSON by annotating @@ -15,7 +15,7 @@ dependencies: # Use a tight version constraint to ensure that a constraint on # `json_annotation` properly constrains all features it provides. - json_annotation: '>=2.1.0 <2.2.0' + json_annotation: '>=2.1.0 <2.3.0' meta: ^1.1.0 path: ^1.3.2 source_gen: ^0.9.0 From 8525ee5d61f06506d4800ea128206c7823c267ab Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 10 Apr 2019 10:19:06 -0700 Subject: [PATCH 102/569] Update generated doc --- json_serializable/README.md | 44 ++++++++++++++++++------------------ json_serializable/doc/doc.md | 44 ++++++++++++++++++------------------ 2 files changed, 44 insertions(+), 44 deletions(-) diff --git a/json_serializable/README.md b/json_serializable/README.md index 920d74f62..db635ea43 100644 --- a/json_serializable/README.md +++ b/json_serializable/README.md @@ -91,28 +91,28 @@ is generated: | | | [JsonKey.required] | | | | [JsonKey.toJson] | -[JsonSerializable.anyMap]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonSerializable/anyMap.html -[JsonSerializable.checked]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonSerializable/checked.html -[JsonSerializable.createFactory]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonSerializable/createFactory.html -[JsonSerializable.createToJson]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonSerializable/createToJson.html -[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html -[JsonSerializable.explicitToJson]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonSerializable/explicitToJson.html -[JsonSerializable.fieldRename]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonSerializable/fieldRename.html -[JsonSerializable.generateToJsonFunction]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonSerializable/generateToJsonFunction.html -[JsonSerializable.useWrappers]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonSerializable/useWrappers.html -[JsonSerializable.encodeEmptyCollection]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonSerializable/encodeEmptyCollection.html -[JsonKey.encodeEmptyCollection]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonKey/encodeEmptyCollection.html -[JsonSerializable.includeIfNull]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonSerializable/includeIfNull.html -[JsonKey.includeIfNull]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonKey/includeIfNull.html -[JsonSerializable.nullable]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonSerializable/nullable.html -[JsonKey.nullable]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonKey/nullable.html -[JsonKey.defaultValue]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonKey/defaultValue.html -[JsonKey.disallowNullValue]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonKey/disallowNullValue.html -[JsonKey.fromJson]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonKey/fromJson.html -[JsonKey.ignore]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonKey/ignore.html -[JsonKey.name]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonKey/name.html -[JsonKey.required]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonKey/required.html -[JsonKey.toJson]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonKey/toJson.html +[JsonSerializable.anyMap]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/anyMap.html +[JsonSerializable.checked]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/checked.html +[JsonSerializable.createFactory]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/createFactory.html +[JsonSerializable.createToJson]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/createToJson.html +[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html +[JsonSerializable.explicitToJson]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/explicitToJson.html +[JsonSerializable.fieldRename]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/fieldRename.html +[JsonSerializable.generateToJsonFunction]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/generateToJsonFunction.html +[JsonSerializable.useWrappers]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/useWrappers.html +[JsonSerializable.encodeEmptyCollection]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/encodeEmptyCollection.html +[JsonKey.encodeEmptyCollection]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonKey/encodeEmptyCollection.html +[JsonSerializable.includeIfNull]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/includeIfNull.html +[JsonKey.includeIfNull]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonKey/includeIfNull.html +[JsonSerializable.nullable]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/nullable.html +[JsonKey.nullable]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonKey/nullable.html +[JsonKey.defaultValue]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonKey/defaultValue.html +[JsonKey.disallowNullValue]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonKey/disallowNullValue.html +[JsonKey.fromJson]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonKey/fromJson.html +[JsonKey.ignore]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonKey/ignore.html +[JsonKey.name]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonKey/name.html +[JsonKey.required]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonKey/required.html +[JsonKey.toJson]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonKey/toJson.html > Note: every `JsonSerializable` field is configurable via `build.yaml` – see the table for the corresponding key. diff --git a/json_serializable/doc/doc.md b/json_serializable/doc/doc.md index fe1cb95a6..6a51104b3 100644 --- a/json_serializable/doc/doc.md +++ b/json_serializable/doc/doc.md @@ -20,25 +20,25 @@ | | | [JsonKey.required] | | | | [JsonKey.toJson] | -[JsonSerializable.anyMap]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonSerializable/anyMap.html -[JsonSerializable.checked]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonSerializable/checked.html -[JsonSerializable.createFactory]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonSerializable/createFactory.html -[JsonSerializable.createToJson]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonSerializable/createToJson.html -[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html -[JsonSerializable.explicitToJson]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonSerializable/explicitToJson.html -[JsonSerializable.fieldRename]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonSerializable/fieldRename.html -[JsonSerializable.generateToJsonFunction]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonSerializable/generateToJsonFunction.html -[JsonSerializable.useWrappers]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonSerializable/useWrappers.html -[JsonSerializable.encodeEmptyCollection]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonSerializable/encodeEmptyCollection.html -[JsonKey.encodeEmptyCollection]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonKey/encodeEmptyCollection.html -[JsonSerializable.includeIfNull]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonSerializable/includeIfNull.html -[JsonKey.includeIfNull]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonKey/includeIfNull.html -[JsonSerializable.nullable]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonSerializable/nullable.html -[JsonKey.nullable]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonKey/nullable.html -[JsonKey.defaultValue]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonKey/defaultValue.html -[JsonKey.disallowNullValue]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonKey/disallowNullValue.html -[JsonKey.fromJson]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonKey/fromJson.html -[JsonKey.ignore]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonKey/ignore.html -[JsonKey.name]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonKey/name.html -[JsonKey.required]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonKey/required.html -[JsonKey.toJson]: https://pub.dartlang.org/documentation/json_annotation/2.1.0/json_annotation/JsonKey/toJson.html +[JsonSerializable.anyMap]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/anyMap.html +[JsonSerializable.checked]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/checked.html +[JsonSerializable.createFactory]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/createFactory.html +[JsonSerializable.createToJson]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/createToJson.html +[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html +[JsonSerializable.explicitToJson]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/explicitToJson.html +[JsonSerializable.fieldRename]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/fieldRename.html +[JsonSerializable.generateToJsonFunction]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/generateToJsonFunction.html +[JsonSerializable.useWrappers]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/useWrappers.html +[JsonSerializable.encodeEmptyCollection]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/encodeEmptyCollection.html +[JsonKey.encodeEmptyCollection]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonKey/encodeEmptyCollection.html +[JsonSerializable.includeIfNull]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/includeIfNull.html +[JsonKey.includeIfNull]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonKey/includeIfNull.html +[JsonSerializable.nullable]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/nullable.html +[JsonKey.nullable]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonKey/nullable.html +[JsonKey.defaultValue]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonKey/defaultValue.html +[JsonKey.disallowNullValue]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonKey/disallowNullValue.html +[JsonKey.fromJson]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonKey/fromJson.html +[JsonKey.ignore]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonKey/ignore.html +[JsonKey.name]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonKey/name.html +[JsonKey.required]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonKey/required.html +[JsonKey.toJson]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonKey/toJson.html From 15aeb4ccda85d5152da547a20c3c77aad980a411 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 10 Apr 2019 13:22:44 -0700 Subject: [PATCH 103/569] enable and fix some lints --- analysis_options.yaml | 3 +++ json_serializable/lib/src/json_key_utils.dart | 4 +--- json_serializable/test/config_test.dart | 2 +- json_serializable/tool/test_builder.dart | 4 +--- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index edcf7501f..f17e32559 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -37,6 +37,7 @@ linter: - implementation_imports - invariant_booleans - iterable_contains_unrelated_type + - join_return_with_assignment - library_names - library_prefixes - list_remove_unrelated_type @@ -69,6 +70,7 @@ linter: - prefer_typing_uninitialized_variables - recursive_getters - slash_for_doc_comments + - sort_pub_dependencies - test_types_in_equals - throw_in_finally - type_init_formals @@ -79,6 +81,7 @@ linter: - unnecessary_lambdas - unnecessary_new - unnecessary_null_aware_assignments + - unnecessary_parenthesis - unnecessary_statements - unnecessary_this - unrelated_type_equality_checks diff --git a/json_serializable/lib/src/json_key_utils.dart b/json_serializable/lib/src/json_key_utils.dart index 749e0094c..815e6ed73 100644 --- a/json_serializable/lib/src/json_key_utils.dart +++ b/json_serializable/lib/src/json_key_utils.dart @@ -163,7 +163,7 @@ JsonKey _populateJsonKey( includeIfNull = false; } - final jsonKey = JsonKey( + return JsonKey( defaultValue: defaultValue, disallowNullValue: disallowNullValue ?? false, ignore: ignore ?? false, @@ -174,8 +174,6 @@ JsonKey _populateJsonKey( required: required ?? false, encodeEmptyCollection: encodeEmptyCollection, ); - - return jsonKey; } String _encodedFieldName(JsonSerializable classAnnotation, diff --git a/json_serializable/test/config_test.dart b/json_serializable/test/config_test.dart index e55f931ab..f6445df60 100644 --- a/json_serializable/test/config_test.dart +++ b/json_serializable/test/config_test.dart @@ -115,7 +115,7 @@ void main() { : "type 'int' is not a subtype of type 'bool' in type cast"; final matcher = isA().having( - ((v) => v.message), + (v) => v.message, 'message', ''' Could not parse the options provided for `json_serializable`. diff --git a/json_serializable/tool/test_builder.dart b/json_serializable/tool/test_builder.dart index fed238942..22f34302c 100644 --- a/json_serializable/tool/test_builder.dart +++ b/json_serializable/tool/test_builder.dart @@ -279,8 +279,6 @@ class _Replacement { } } - outputContent = outputContent.replaceAll(',)', ',\n)'); - - return outputContent; + return outputContent.replaceAll(',)', ',\n)'); } } From 93f8da4dc9fbab20b83ace90443ca4e6e525730b Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 10 Apr 2019 17:36:05 -0700 Subject: [PATCH 104/569] Handle the intersection of convert function, !nullable & !includeIfNull (#443) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If a field has a conversion function defined – either `JsonKey.toJson` or a custom `JsonConverter` annotation – handle the case where the function returns `null` and both `nullable` and `includeIfNull` are `false`. Before this change, you could still get `null` values in output JSON even if `includeIfNull` is `false`. Prepare to release v2.2.0 --- json_serializable/CHANGELOG.md | 6 ++ json_serializable/lib/src/encoder_helper.dart | 95 ++++++++++++++++-- .../lib/src/type_helpers/convert_helper.dart | 10 +- json_serializable/lib/type_helper.dart | 2 +- json_serializable/pubspec.yaml | 2 +- .../test/json_serializable_test.dart | 3 + ...e_empty__non_nullable__use_wrappers.g.dart | 20 +++- ...null__no_encode_empty__use_wrappers.g.dart | 21 +++- ...n_sink.g_exclude_null__non_nullable.g.dart | 62 +++++++----- ...n_sink.g_exclude_null__use_wrappers.g.dart | 21 +++- .../test/src/to_from_json_test_input.dart | 99 +++++++++++++++++++ 11 files changed, 292 insertions(+), 49 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index a17316201..c1bef6ece 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,9 @@ +## 2.2.0 + +- If a field has a conversion function defined – either `JsonKey.toJson` or a + custom `JsonConverter` annotation – handle the case where the function + returns `null` and both `nullable` and `includeIfNull` are `false`. + ## 2.1.2 * Support `package:json_annotation` `>=2.1.0 <2.3.0`. diff --git a/json_serializable/lib/src/encoder_helper.dart b/json_serializable/lib/src/encoder_helper.dart index bd4bd591b..60961fe4b 100644 --- a/json_serializable/lib/src/encoder_helper.dart +++ b/json_serializable/lib/src/encoder_helper.dart @@ -8,6 +8,8 @@ import 'package:json_annotation/json_annotation.dart'; import 'constants.dart'; import 'helper_core.dart'; import 'type_helper.dart'; +import 'type_helpers/convert_helper.dart'; +import 'type_helpers/json_converter_helper.dart'; abstract class EncodeHelper implements HelperCore { String _fieldAccess(FieldElement field) { @@ -110,7 +112,8 @@ class ${_wrapperClassName(true)} extends \$JsonMapWrapper { String check; if (!_writeJsonValueNaive(field)) { - check = '_v.${field.name} != null'; + final expression = _wrapCustomEncoder('_v.${field.name}', field); + check = '$expression != null'; if (!jsonKeyFor(field).encodeEmptyCollection) { assert(!jsonKeyFor(field).includeIfNull); @@ -248,12 +251,88 @@ class ${_wrapperClassName(true)} extends \$JsonMapWrapper { /// Returns `true` if the field can be written to JSON 'naively' – meaning /// we can avoid checking for `null`. + bool _writeJsonValueNaive(FieldElement field) { + final jsonKey = jsonKeyFor(field); + + if (jsonKey.includeIfNull) { + return true; + } + + if (!jsonKey.nullable && + jsonKey.encodeEmptyCollection && + !_fieldHasCustomEncoder(field)) { + return true; + } + + return false; + } + + /// Returns `true` if [field] has a user-defined encoder. /// - /// `true` if either: - /// `includeIfNull` is `true` - /// or - /// `nullable` is `false` and `encodeEmptyCollection` is true - bool _writeJsonValueNaive(FieldElement field) => - jsonKeyFor(field).includeIfNull || - (!jsonKeyFor(field).nullable && jsonKeyFor(field).encodeEmptyCollection); + /// This can be either a `toJson` function in [JsonKey] or a [JsonConverter] + /// annotation. + bool _fieldHasCustomEncoder(FieldElement field) { + final helperContext = getHelperContext(field); + + if (helperContext.serializeConvertData != null) { + return true; + } + + final output = const JsonConverterHelper() + .serialize(field.type, 'test', helperContext); + + if (output != null) { + return true; + } + return false; + } + + /// If [field] has a user-defined encoder, return [expression] wrapped in + /// the corresponding conversion logic so we can do a correct `null` check. + /// + /// This can be either a `toJson` function in [JsonKey] or a [JsonConverter] + /// annotation. + /// + /// If there is no user-defined encoder, just return [expression] as-is. + String _wrapCustomEncoder(String expression, FieldElement field) { + final helperContext = getHelperContext(field); + + final convertData = helperContext.serializeConvertData; + + var result = expression; + if (convertData != null) { + result = toJsonSerializeImpl( + getHelperContext(field).serializeConvertData.name, + expression, + jsonKeyFor(field).nullable, + ); + } else { + final output = const JsonConverterHelper() + .serialize(field.type, expression, helperContext); + + if (output != null) { + result = output.toString(); + } + } + + assert( + (result != expression) == _fieldHasCustomEncoder(field), + 'If the output expression is different, then it should map to a field ' + 'with a custom encoder', + ); + + if (result == expression) { + // No conversion + return expression; + } + + if (jsonKeyFor(field).nullable) { + // If there was a conversion and the field is nullable, wrap the output + // in () – there will be null checks that will break the comparison + // in the caller + result = '($result)'; + } + + return result; + } } diff --git a/json_serializable/lib/src/type_helpers/convert_helper.dart b/json_serializable/lib/src/type_helpers/convert_helper.dart index 8d353c4e6..e617d8c09 100644 --- a/json_serializable/lib/src/type_helpers/convert_helper.dart +++ b/json_serializable/lib/src/type_helpers/convert_helper.dart @@ -31,8 +31,7 @@ class ConvertHelper extends TypeHelper { if (toJsonData != null) { assert(toJsonData.paramType is TypeParameterType || targetType.isAssignableTo(toJsonData.paramType)); - final result = '${toJsonData.name}($expression)'; - return commonNullPrefix(context.nullable, expression, result).toString(); + return toJsonSerializeImpl(toJsonData.name, expression, context.nullable); } return null; } @@ -49,3 +48,10 @@ class ConvertHelper extends TypeHelper { return null; } } + +/// Exposed to support `EncodeHelper` – not exposed publicly. +String toJsonSerializeImpl( + String toJsonDataName, String expression, bool nullable) { + final result = '$toJsonDataName($expression)'; + return commonNullPrefix(nullable, expression, result).toString(); +} diff --git a/json_serializable/lib/type_helper.dart b/json_serializable/lib/type_helper.dart index 167123fd0..785d949f8 100644 --- a/json_serializable/lib/type_helper.dart +++ b/json_serializable/lib/type_helper.dart @@ -6,7 +6,7 @@ export 'src/shared_checkers.dart' show simpleJsonTypeChecker, typeArgumentsOf; export 'src/type_helper.dart' show TypeHelperContext, TypeHelper, UnsupportedTypeError; export 'src/type_helpers/big_int_helper.dart'; -export 'src/type_helpers/convert_helper.dart'; +export 'src/type_helpers/convert_helper.dart' hide toJsonSerializeImpl; export 'src/type_helpers/date_time_helper.dart'; export 'src/type_helpers/enum_helper.dart'; export 'src/type_helpers/iterable_helper.dart'; diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 4106d5ea8..fb9bec6c7 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 2.1.2 +version: 2.2.0 author: Dart Team description: >- Automatically generate code for converting to and from JSON by annotating diff --git a/json_serializable/test/json_serializable_test.dart b/json_serializable/test/json_serializable_test.dart index 3e2befcda..4228481cc 100644 --- a/json_serializable/test/json_serializable_test.dart +++ b/json_serializable/test/json_serializable_test.dart @@ -100,6 +100,9 @@ const _expectedAnnotatedTests = [ 'SubTypeWithAnnotatedFieldOverrideExtendsWithOverrides', 'SubTypeWithAnnotatedFieldOverrideImplements', 'theAnswer', + 'ToJsonIncludeIfNullFalseWrapped', + 'ToJsonNullableFalseIncludeIfNullFalse', + 'ToJsonNullableFalseIncludeIfNullFalseWrapped', 'TypedConvertMethods', 'UnknownCtorParamType', 'UnknownFieldType', diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty__non_nullable__use_wrappers.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty__non_nullable__use_wrappers.g.dart index 50bc4243a..112026f0b 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty__non_nullable__use_wrappers.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty__non_nullable__use_wrappers.g.dart @@ -268,19 +268,27 @@ class _$JsonConverterTestClassJsonMapWrapper extends $JsonMapWrapper { @override Iterable get keys sync* { - yield 'duration'; + if (durationConverter.toJson(_v.duration) != null) { + yield 'duration'; + } if (_v.durationList.isNotEmpty) { yield 'durationList'; } - yield 'bigInt'; + if (const BigIntStringConverter().toJson(_v.bigInt) != null) { + yield 'bigInt'; + } if (_v.bigIntMap.isNotEmpty) { yield 'bigIntMap'; } - yield 'numberSilly'; + if (TrivialNumberConverter.instance.toJson(_v.numberSilly) != null) { + yield 'numberSilly'; + } if (_v.numberSillySet.isNotEmpty) { yield 'numberSillySet'; } - yield 'dateTime'; + if (const EpochDateTimeConverter().toJson(_v.dateTime) != null) { + yield 'dateTime'; + } } @override @@ -336,7 +344,9 @@ class _$JsonConverterGenericJsonMapWrapper extends $JsonMapWrapper { @override Iterable get keys sync* { - yield 'item'; + if (GenericConverter().toJson(_v.item) != null) { + yield 'item'; + } if (_v.itemList.isNotEmpty) { yield 'itemList'; } diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty__use_wrappers.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty__use_wrappers.g.dart index 5845fbf59..60d981579 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty__use_wrappers.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty__use_wrappers.g.dart @@ -310,25 +310,35 @@ class _$JsonConverterTestClassJsonMapWrapper extends $JsonMapWrapper { @override Iterable get keys sync* { - if (_v.duration != null) { + if ((_v.duration == null ? null : durationConverter.toJson(_v.duration)) != + null) { yield 'duration'; } if (_v.durationList?.isNotEmpty ?? false) { yield 'durationList'; } - if (_v.bigInt != null) { + if ((_v.bigInt == null + ? null + : const BigIntStringConverter().toJson(_v.bigInt)) != + null) { yield 'bigInt'; } if (_v.bigIntMap?.isNotEmpty ?? false) { yield 'bigIntMap'; } - if (_v.numberSilly != null) { + if ((_v.numberSilly == null + ? null + : TrivialNumberConverter.instance.toJson(_v.numberSilly)) != + null) { yield 'numberSilly'; } if (_v.numberSillySet?.isNotEmpty ?? false) { yield 'numberSillySet'; } - if (_v.dateTime != null) { + if ((_v.dateTime == null + ? null + : const EpochDateTimeConverter().toJson(_v.dateTime)) != + null) { yield 'dateTime'; } } @@ -403,7 +413,8 @@ class _$JsonConverterGenericJsonMapWrapper extends $JsonMapWrapper { @override Iterable get keys sync* { - if (_v.item != null) { + if ((_v.item == null ? null : GenericConverter().toJson(_v.item)) != + null) { yield 'item'; } if (_v.itemList?.isNotEmpty ?? false) { diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__non_nullable.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__non_nullable.g.dart index b992e4121..40889434d 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__non_nullable.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__non_nullable.g.dart @@ -130,21 +130,30 @@ JsonConverterTestClass _$JsonConverterTestClassFromJson( } Map _$JsonConverterTestClassToJson( - JsonConverterTestClass instance) => - { - 'duration': durationConverter.toJson(instance.duration), - 'durationList': - instance.durationList.map(durationConverter.toJson).toList(), - 'bigInt': const BigIntStringConverter().toJson(instance.bigInt), - 'bigIntMap': instance.bigIntMap - .map((k, e) => MapEntry(k, const BigIntStringConverter().toJson(e))), - 'numberSilly': - TrivialNumberConverter.instance.toJson(instance.numberSilly), - 'numberSillySet': instance.numberSillySet - .map(TrivialNumberConverter.instance.toJson) - .toList(), - 'dateTime': const EpochDateTimeConverter().toJson(instance.dateTime) - }; + JsonConverterTestClass instance) { + final val = {}; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('duration', durationConverter.toJson(instance.duration)); + val['durationList'] = + instance.durationList.map(durationConverter.toJson).toList(); + writeNotNull('bigInt', const BigIntStringConverter().toJson(instance.bigInt)); + val['bigIntMap'] = instance.bigIntMap + .map((k, e) => MapEntry(k, const BigIntStringConverter().toJson(e))); + writeNotNull('numberSilly', + TrivialNumberConverter.instance.toJson(instance.numberSilly)); + val['numberSillySet'] = instance.numberSillySet + .map(TrivialNumberConverter.instance.toJson) + .toList(); + writeNotNull( + 'dateTime', const EpochDateTimeConverter().toJson(instance.dateTime)); + return val; +} JsonConverterGeneric _$JsonConverterGenericFromJson( Map json) { @@ -161,10 +170,19 @@ JsonConverterGeneric _$JsonConverterGenericFromJson( } Map _$JsonConverterGenericToJson( - JsonConverterGeneric instance) => - { - 'item': GenericConverter().toJson(instance.item), - 'itemList': instance.itemList.map(GenericConverter().toJson).toList(), - 'itemMap': instance.itemMap - .map((k, e) => MapEntry(k, GenericConverter().toJson(e))) - }; + JsonConverterGeneric instance) { + final val = {}; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('item', GenericConverter().toJson(instance.item)); + val['itemList'] = + instance.itemList.map(GenericConverter().toJson).toList(); + val['itemMap'] = instance.itemMap + .map((k, e) => MapEntry(k, GenericConverter().toJson(e))); + return val; +} diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__use_wrappers.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__use_wrappers.g.dart index 20bd8c11a..bb99b4743 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__use_wrappers.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__use_wrappers.g.dart @@ -300,25 +300,35 @@ class _$JsonConverterTestClassJsonMapWrapper extends $JsonMapWrapper { @override Iterable get keys sync* { - if (_v.duration != null) { + if ((_v.duration == null ? null : durationConverter.toJson(_v.duration)) != + null) { yield 'duration'; } if (_v.durationList != null) { yield 'durationList'; } - if (_v.bigInt != null) { + if ((_v.bigInt == null + ? null + : const BigIntStringConverter().toJson(_v.bigInt)) != + null) { yield 'bigInt'; } if (_v.bigIntMap != null) { yield 'bigIntMap'; } - if (_v.numberSilly != null) { + if ((_v.numberSilly == null + ? null + : TrivialNumberConverter.instance.toJson(_v.numberSilly)) != + null) { yield 'numberSilly'; } if (_v.numberSillySet != null) { yield 'numberSillySet'; } - if (_v.dateTime != null) { + if ((_v.dateTime == null + ? null + : const EpochDateTimeConverter().toJson(_v.dateTime)) != + null) { yield 'dateTime'; } } @@ -392,7 +402,8 @@ class _$JsonConverterGenericJsonMapWrapper extends $JsonMapWrapper { @override Iterable get keys sync* { - if (_v.item != null) { + if ((_v.item == null ? null : GenericConverter().toJson(_v.item)) != + null) { yield 'item'; } if (_v.itemList != null) { diff --git a/json_serializable/test/src/to_from_json_test_input.dart b/json_serializable/test/src/to_from_json_test_input.dart index 54cbddb33..c381bf7ac 100644 --- a/json_serializable/test/src/to_from_json_test_input.dart +++ b/json_serializable/test/src/to_from_json_test_input.dart @@ -118,6 +118,105 @@ class TypedConvertMethods { String field; } +@ShouldGenerate( + r''' +Map _$ToJsonNullableFalseIncludeIfNullFalseToJson( + ToJsonNullableFalseIncludeIfNullFalse instance) { + final val = {}; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('field', _toString(instance.field)); + return val; +} +''', + configurations: ['default'], +) +@JsonSerializable(createFactory: false) +class ToJsonNullableFalseIncludeIfNullFalse { + @JsonKey(toJson: _toString, includeIfNull: false, nullable: false) + String field; +} + +@ShouldGenerate( + r''' +Map _$ToJsonNullableFalseIncludeIfNullFalseWrappedToJson( + ToJsonNullableFalseIncludeIfNullFalseWrapped instance) => + _$ToJsonNullableFalseIncludeIfNullFalseWrappedJsonMapWrapper(instance); + +class _$ToJsonNullableFalseIncludeIfNullFalseWrappedJsonMapWrapper + extends $JsonMapWrapper { + final ToJsonNullableFalseIncludeIfNullFalseWrapped _v; + _$ToJsonNullableFalseIncludeIfNullFalseWrappedJsonMapWrapper(this._v); + + @override + Iterable get keys sync* { + if (_toString(_v.field) != null) { + yield 'field'; + } + } + + @override + dynamic operator [](Object key) { + if (key is String) { + switch (key) { + case 'field': + return _toString(_v.field); + } + } + return null; + } +} +''', + configurations: ['wrapped'], +) +@JsonSerializable(createFactory: false) +class ToJsonNullableFalseIncludeIfNullFalseWrapped { + @JsonKey(toJson: _toString, includeIfNull: false, nullable: false) + String field; +} + +@ShouldGenerate( + r''' +Map _$ToJsonIncludeIfNullFalseWrappedToJson( + ToJsonIncludeIfNullFalseWrapped instance) => + _$ToJsonIncludeIfNullFalseWrappedJsonMapWrapper(instance); + +class _$ToJsonIncludeIfNullFalseWrappedJsonMapWrapper extends $JsonMapWrapper { + final ToJsonIncludeIfNullFalseWrapped _v; + _$ToJsonIncludeIfNullFalseWrappedJsonMapWrapper(this._v); + + @override + Iterable get keys sync* { + if ((_v.field == null ? null : _toString(_v.field)) != null) { + yield 'field'; + } + } + + @override + dynamic operator [](Object key) { + if (key is String) { + switch (key) { + case 'field': + return _v.field == null ? null : _toString(_v.field); + } + } + return null; + } +} +''', + configurations: ['wrapped'], +) +@JsonSerializable(createFactory: false) +class ToJsonIncludeIfNullFalseWrapped { + @JsonKey(toJson: _toString, includeIfNull: false) + String field; +} + String _fromDynamicMap(Map input) => null; String _fromDynamicList(List input) => null; From b534dffe492d5806042cf42af0fe6336a585a70f Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 15 Apr 2019 10:15:51 -0700 Subject: [PATCH 105/569] Fix an NPE thrown when a prop is defined in a mixin (#450) Fixes https://github.com/dart-lang/json_serializable/issues/448 --- json_serializable/CHANGELOG.md | 4 +++ json_serializable/lib/src/field_helpers.dart | 4 +-- json_serializable/pubspec.yaml | 2 +- .../test/json_serializable_test.dart | 1 + .../src/_json_serializable_test_input.dart | 29 +++++++++++++++++++ 5 files changed, 37 insertions(+), 3 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index c1bef6ece..4b2fa9b30 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,7 @@ +## 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.toJson` or a diff --git a/json_serializable/lib/src/field_helpers.dart b/json_serializable/lib/src/field_helpers.dart index ad5d5a3fe..f29674ef2 100644 --- a/json_serializable/lib/src/field_helpers.dart +++ b/json_serializable/lib/src/field_helpers.dart @@ -44,13 +44,13 @@ class _FieldSet implements Comparable<_FieldSet> { // in this case, you want to prioritize the enclosingElement that is more // "super". - if (checkerA.isSuperOf(b.enclosingElement)) { + if (checkerA.isAssignableFrom(b.enclosingElement)) { return -1; } final checkerB = TypeChecker.fromStatic(b.enclosingElement.type); - if (checkerB.isSuperOf(a.enclosingElement)) { + if (checkerB.isAssignableFrom(a.enclosingElement)) { return 1; } } diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index fb9bec6c7..2ebe9b265 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 2.2.0 +version: 2.2.1 author: Dart Team description: >- Automatically generate code for converting to and from JSON by annotating diff --git a/json_serializable/test/json_serializable_test.dart b/json_serializable/test/json_serializable_test.dart index 4228481cc..7fdc9d95e 100644 --- a/json_serializable/test/json_serializable_test.dart +++ b/json_serializable/test/json_serializable_test.dart @@ -93,6 +93,7 @@ const _expectedAnnotatedTests = [ 'OkayOnlyOptionalPositional', 'OnlyStaticMembers', 'PrivateFieldCtorClass', + 'PropInMixinI448Regression', 'SetSupport', 'SubType', 'SubType', diff --git a/json_serializable/test/src/_json_serializable_test_input.dart b/json_serializable/test/src/_json_serializable_test_input.dart index 55e819096..570275900 100644 --- a/json_serializable/test/src/_json_serializable_test_input.dart +++ b/json_serializable/test/src/_json_serializable_test_input.dart @@ -558,3 +558,32 @@ T _$nullIfEmptyIterable(T source) => class EmptyCollectionAsNullAndIncludeIfNullClass { List field; } + +mixin _PropInMixinI448RegressionMixin { + @JsonKey(nullable: true) + int nullable; +} + +@ShouldGenerate( + r''' +PropInMixinI448Regression _$PropInMixinI448RegressionFromJson( + Map json) { + return PropInMixinI448Regression() + ..nullable = json['nullable'] as int + ..notNullable = json['notNullable'] as int; +} + +Map _$PropInMixinI448RegressionToJson( + PropInMixinI448Regression instance) => + { + 'nullable': instance.nullable, + 'notNullable': instance.notNullable + }; +''', + configurations: ['default'], +) +@JsonSerializable() +class PropInMixinI448Regression with _PropInMixinI448RegressionMixin { + @JsonKey(nullable: false) + int notNullable; +} From 5cbe2f9b3009cd78c7a55277f5278ea09952340d Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 10 Apr 2019 14:11:19 -0700 Subject: [PATCH 106/569] require Dart ^2.2 --- .travis.yml | 24 ++++---- analysis_options.yaml | 3 +- example/mono_pkg.yaml | 4 +- example/pubspec.yaml | 2 +- json_annotation/CHANGELOG.md | 4 ++ json_annotation/mono_pkg.yaml | 2 +- json_annotation/pubspec.yaml | 4 +- json_serializable/CHANGELOG.md | 4 ++ json_serializable/lib/src/decode_helper.dart | 2 +- .../lib/src/json_serializable_generator.dart | 4 +- json_serializable/mono_pkg.yaml | 4 +- json_serializable/pubspec.yaml | 4 +- ...sink.g_any_map__checked__non_nullable.dart | 2 +- .../kitchen_sink.g_any_map__non_nullable.dart | 2 +- ...g_any_map__non_nullable__use_wrappers.dart | 2 +- ...ode_empty__non_nullable__use_wrappers.dart | 2 +- ...hen_sink.g_exclude_null__non_nullable.dart | 2 +- ..._sink.g_no_encode_empty__non_nullable.dart | 2 +- json_serializable/tool/test_builder.dart | 57 +++++++++---------- 19 files changed, 68 insertions(+), 62 deletions(-) diff --git a/.travis.yml b/.travis.yml index c3c77da45..61a1d93fe 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,13 +17,13 @@ jobs: env: PKGS="example json_annotation json_serializable" script: ./tool/travis.sh dartfmt dartanalyzer_0 - stage: analyzer_and_format - name: "SDK: 2.1.1; PKGS: example, json_annotation; TASKS: [`dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-warnings .`]" - dart: "2.1.1" + name: "SDK: 2.2.0; PKGS: example, json_annotation; TASKS: [`dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-warnings .`]" + dart: "2.2.0" env: PKGS="example json_annotation" script: ./tool/travis.sh dartfmt dartanalyzer_1 - stage: unit_test - name: "SDK: 2.1.1; PKG: example; TASKS: `pub run test --run-skipped`" - dart: "2.1.1" + name: "SDK: 2.2.0; PKG: example; TASKS: `pub run test --run-skipped`" + dart: "2.2.0" env: PKGS="example" script: ./tool/travis.sh test_0 - stage: unit_test @@ -32,13 +32,13 @@ jobs: env: PKGS="example" script: ./tool/travis.sh test_0 - stage: analyzer_and_format - name: "SDK: 2.1.1; PKG: json_serializable; TASKS: `dartanalyzer --fatal-warnings .`" - dart: "2.1.1" + name: "SDK: 2.2.0; PKG: json_serializable; TASKS: `dartanalyzer --fatal-warnings .`" + dart: "2.2.0" env: PKGS="json_serializable" script: ./tool/travis.sh dartanalyzer_1 - stage: unit_test - name: "SDK: 2.1.1; PKG: json_serializable; TASKS: `pub run test`" - dart: "2.1.1" + name: "SDK: 2.2.0; PKG: json_serializable; TASKS: `pub run test`" + dart: "2.2.0" env: PKGS="json_serializable" script: ./tool/travis.sh test_1 - stage: unit_test @@ -47,8 +47,8 @@ jobs: env: PKGS="json_serializable" script: ./tool/travis.sh test_1 - stage: unit_test - name: "SDK: 2.1.1; PKG: json_serializable; TASKS: `pub run test --run-skipped test/ensure_build_test.dart`" - dart: "2.1.1" + name: "SDK: 2.2.0; PKG: json_serializable; TASKS: `pub run test --run-skipped test/ensure_build_test.dart`" + dart: "2.2.0" env: PKGS="json_serializable" script: ./tool/travis.sh test_2 - stage: unit_test @@ -57,8 +57,8 @@ jobs: env: PKGS="json_serializable" script: ./tool/travis.sh test_2 - stage: unit_test - name: "SDK: 2.1.1; PKG: json_serializable; TASKS: `pub run build_runner test --delete-conflicting-outputs -- -p chrome`" - dart: "2.1.1" + name: "SDK: 2.2.0; PKG: json_serializable; TASKS: `pub run build_runner test --delete-conflicting-outputs -- -p chrome`" + dart: "2.2.0" env: PKGS="json_serializable" script: ./tool/travis.sh command - stage: unit_test diff --git a/analysis_options.yaml b/analysis_options.yaml index f17e32559..4b73f7c12 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -53,8 +53,7 @@ linter: - package_names - package_prefixed_library_names - prefer_adjacent_string_concatenation - # TODO: re-enable when we want to support Dart 2.2+ - #- prefer_collection_literals + - prefer_collection_literals - prefer_conditional_assignment - prefer_const_constructors - prefer_contains diff --git a/example/mono_pkg.yaml b/example/mono_pkg.yaml index f824f9d4c..6552c64d3 100644 --- a/example/mono_pkg.yaml +++ b/example/mono_pkg.yaml @@ -1,6 +1,6 @@ # See https://github.com/dart-lang/mono_repo for details dart: -- 2.1.1 +- 2.2.0 - dev stages: @@ -12,7 +12,7 @@ stages: - group: - dartfmt - dartanalyzer: --fatal-warnings . - dart: [2.1.1] + dart: [2.2.0] - unit_test: # Run the tests -- include the default-skipped presubmit tests - test: --run-skipped diff --git a/example/pubspec.yaml b/example/pubspec.yaml index a93f09aba..6efa64d51 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -2,7 +2,7 @@ name: example author: Dart Team environment: - sdk: '>=2.1.1 <3.0.0' + sdk: '>=2.2.0 <3.0.0' dependencies: json_annotation: ^2.0.0 diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index 2c998d940..25f6614d3 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.2.1 + +- Require at least Dart `2.2.0`. + ## 2.2.0 * Add an optional (named) `badKey` parameter and field to diff --git a/json_annotation/mono_pkg.yaml b/json_annotation/mono_pkg.yaml index f939b9d38..78a5eb005 100644 --- a/json_annotation/mono_pkg.yaml +++ b/json_annotation/mono_pkg.yaml @@ -8,4 +8,4 @@ stages: - group: - dartfmt - dartanalyzer: --fatal-warnings . - dart: [2.1.1] + dart: [2.2.0] diff --git a/json_annotation/pubspec.yaml b/json_annotation/pubspec.yaml index 9a6d185ba..26d9e1e76 100644 --- a/json_annotation/pubspec.yaml +++ b/json_annotation/pubspec.yaml @@ -1,12 +1,12 @@ name: json_annotation -version: 2.2.0 +version: 2.2.1-dev description: >- Classes and helper functions that support JSON code generation via the `json_serializable` package. homepage: https://github.com/dart-lang/json_serializable author: Dart Team environment: - sdk: '>=2.1.1 <3.0.0' + sdk: '>=2.2.0 <3.0.0' # When changing JsonSerializable class. # dev_dependencies: diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 4b2fa9b30..ec427c596 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.2.2 + +- Require at least Dart `2.2.0`. + ## 2.2.1 - Fixed an error when a property/field is defined in a `mixin`. diff --git a/json_serializable/lib/src/decode_helper.dart b/json_serializable/lib/src/decode_helper.dart index 279cb585d..e5f3b50f6 100644 --- a/json_serializable/lib/src/decode_helper.dart +++ b/json_serializable/lib/src/decode_helper.dart @@ -238,7 +238,7 @@ _ConstructorData _writeConstructorInvocation( element: classElement); } - final usedCtorParamsAndFields = Set(); + final usedCtorParamsAndFields = {}; final constructorArguments = []; final namedConstructorArguments = []; diff --git a/json_serializable/lib/src/json_serializable_generator.dart b/json_serializable/lib/src/json_serializable_generator.dart index 68ef09fd3..8f02ba072 100644 --- a/json_serializable/lib/src/json_serializable_generator.dart +++ b/json_serializable/lib/src/json_serializable_generator.dart @@ -96,7 +96,7 @@ class JsonSerializableGenerator class _GeneratorHelper extends HelperCore with EncodeHelper, DecodeHelper { final JsonSerializableGenerator _generator; - final _addedMembers = Set(); + final _addedMembers = {}; _GeneratorHelper( this._generator, ClassElement element, ConstantReader annotation) @@ -152,7 +152,7 @@ class _GeneratorHelper extends HelperCore with EncodeHelper, DecodeHelper { // Check for duplicate JSON keys due to colliding annotations. // We do this now, since we have a final field list after any pruning done // by `_writeCtor`. - accessibleFieldSet.fold(Set(), (Set set, fe) { + accessibleFieldSet.fold({}, (Set set, fe) { final jsonKey = nameAccess(fe); if (!set.add(jsonKey)) { throw InvalidGenerationSourceError( diff --git a/json_serializable/mono_pkg.yaml b/json_serializable/mono_pkg.yaml index 5b41699ab..c106b35fb 100644 --- a/json_serializable/mono_pkg.yaml +++ b/json_serializable/mono_pkg.yaml @@ -1,6 +1,6 @@ # See https://github.com/dart-lang/mono_repo for details dart: -- 2.1.1 +- 2.2.0 - dev stages: @@ -11,7 +11,7 @@ stages: dart: [dev] - group: - dartanalyzer: --fatal-warnings . - dart: [2.1.1] + dart: [2.2.0] - unit_test: # Run the tests -- include the default-skipped presubmit tests - test diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 2ebe9b265..363377d09 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,12 +1,12 @@ name: json_serializable -version: 2.2.1 +version: 2.2.2-dev author: Dart Team description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. homepage: https://github.com/dart-lang/json_serializable environment: - sdk: '>=2.1.1 <3.0.0' + sdk: '>=2.2.0 <3.0.0' dependencies: analyzer: '>=0.33.3 <0.37.0' diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked__non_nullable.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked__non_nullable.dart index 56d4f4c4e..3fc6dfcba 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked__non_nullable.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked__non_nullable.dart @@ -15,7 +15,7 @@ part 'kitchen_sink.g_any_map__checked__non_nullable.g.dart'; // NOTE: these methods are replaced in the `non_nullable` cases to return // non-null values. List _defaultList() => []; -Set _defaultSet() => Set(); +Set _defaultSet() => {}; Map _defaultMap() => {}; SimpleObject _defaultSimpleObject() => SimpleObject(42); StrictKeysObject _defaultStrictKeysObject() => StrictKeysObject(10, 'cool'); diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable.dart index c6fed2511..7bccbf450 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable.dart @@ -15,7 +15,7 @@ part 'kitchen_sink.g_any_map__non_nullable.g.dart'; // NOTE: these methods are replaced in the `non_nullable` cases to return // non-null values. List _defaultList() => []; -Set _defaultSet() => Set(); +Set _defaultSet() => {}; Map _defaultMap() => {}; SimpleObject _defaultSimpleObject() => SimpleObject(42); StrictKeysObject _defaultStrictKeysObject() => StrictKeysObject(10, 'cool'); diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable__use_wrappers.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable__use_wrappers.dart index 7c3b4be8d..1451e59e8 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable__use_wrappers.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable__use_wrappers.dart @@ -15,7 +15,7 @@ part 'kitchen_sink.g_any_map__non_nullable__use_wrappers.g.dart'; // NOTE: these methods are replaced in the `non_nullable` cases to return // non-null values. List _defaultList() => []; -Set _defaultSet() => Set(); +Set _defaultSet() => {}; Map _defaultMap() => {}; SimpleObject _defaultSimpleObject() => SimpleObject(42); StrictKeysObject _defaultStrictKeysObject() => StrictKeysObject(10, 'cool'); diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty__non_nullable__use_wrappers.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty__non_nullable__use_wrappers.dart index e02030806..f5e03d848 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty__non_nullable__use_wrappers.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty__non_nullable__use_wrappers.dart @@ -15,7 +15,7 @@ part 'kitchen_sink.g_exclude_null__no_encode_empty__non_nullable__use_wrappers.g // NOTE: these methods are replaced in the `non_nullable` cases to return // non-null values. List _defaultList() => []; -Set _defaultSet() => Set(); +Set _defaultSet() => {}; Map _defaultMap() => {}; SimpleObject _defaultSimpleObject() => SimpleObject(42); StrictKeysObject _defaultStrictKeysObject() => StrictKeysObject(10, 'cool'); diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__non_nullable.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__non_nullable.dart index 282421e85..7ab6f61ad 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__non_nullable.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__non_nullable.dart @@ -15,7 +15,7 @@ part 'kitchen_sink.g_exclude_null__non_nullable.g.dart'; // NOTE: these methods are replaced in the `non_nullable` cases to return // non-null values. List _defaultList() => []; -Set _defaultSet() => Set(); +Set _defaultSet() => {}; Map _defaultMap() => {}; SimpleObject _defaultSimpleObject() => SimpleObject(42); StrictKeysObject _defaultStrictKeysObject() => StrictKeysObject(10, 'cool'); diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_no_encode_empty__non_nullable.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_no_encode_empty__non_nullable.dart index aa2e6924c..70eb8ca52 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_no_encode_empty__non_nullable.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_no_encode_empty__non_nullable.dart @@ -15,7 +15,7 @@ part 'kitchen_sink.g_no_encode_empty__non_nullable.g.dart'; // NOTE: these methods are replaced in the `non_nullable` cases to return // non-null values. List _defaultList() => []; -Set _defaultSet() => Set(); +Set _defaultSet() => {}; Map _defaultMap() => {}; SimpleObject _defaultSimpleObject() => SimpleObject(42); StrictKeysObject _defaultStrictKeysObject() => StrictKeysObject(10, 'cool'); diff --git a/json_serializable/tool/test_builder.dart b/json_serializable/tool/test_builder.dart index 22f34302c..1db780ce0 100644 --- a/json_serializable/tool/test_builder.dart +++ b/json_serializable/tool/test_builder.dart @@ -175,7 +175,7 @@ const _kitchenSinkReplacements = { ), _Replacement( 'Set _defaultSet() => null;', - 'Set _defaultSet() => Set();', + 'Set _defaultSet() => {};', ), _Replacement( 'Map _defaultMap() => null;', @@ -227,34 +227,33 @@ List get _fileConfigurations => _fileConfigurationMap.values const _kitchenSinkBaseName = 'kitchen_sink'; -// TODO: use a set of sets, once we're >=2.2.0 -const _fileConfigurationMap = >>{ - _kitchenSinkBaseName: [ - ['any_map', 'checked', 'non_nullable'], - ['any_map', 'non_nullable', 'use_wrappers'], - ['any_map', 'non_nullable'], - ['any_map'], - ['no_encode_empty'], - ['no_encode_empty', 'exclude_null', 'use_wrappers'], - ['no_encode_empty', 'non_nullable'], - ['no_encode_empty', 'exclude_null'], - ['no_encode_empty', 'exclude_null', 'non_nullable', 'use_wrappers'], - ['exclude_null', 'non_nullable'], - ['exclude_null', 'use_wrappers'], - ['exclude_null'], - ['explicit_to_json'], - ], - 'default_value': [ - ['any_map', 'checked'], - ], - 'generic_class': [ - ['use_wrappers'], - ], - 'json_test_example': [ - ['non_nullable', 'use_wrappers'], - ['non_nullable'], - ['use_wrappers'], - ] +const _fileConfigurationMap = >>{ + _kitchenSinkBaseName: { + {'any_map', 'checked', 'non_nullable'}, + {'any_map', 'non_nullable', 'use_wrappers'}, + {'any_map', 'non_nullable'}, + {'any_map'}, + {'no_encode_empty'}, + {'no_encode_empty', 'exclude_null', 'use_wrappers'}, + {'no_encode_empty', 'non_nullable'}, + {'no_encode_empty', 'exclude_null'}, + {'no_encode_empty', 'exclude_null', 'non_nullable', 'use_wrappers'}, + {'exclude_null', 'non_nullable'}, + {'exclude_null', 'use_wrappers'}, + {'exclude_null'}, + {'explicit_to_json'}, + }, + 'default_value': { + {'any_map', 'checked'}, + }, + 'generic_class': { + {'use_wrappers'}, + }, + 'json_test_example': { + {'non_nullable', 'use_wrappers'}, + {'non_nullable'}, + {'use_wrappers'}, + } }; class _Replacement { From 6a2a12ea8abb6690fcefabbe51b4d45fcaa4f172 Mon Sep 17 00:00:00 2001 From: Nate Bosch Date: Tue, 23 Apr 2019 13:02:27 -0700 Subject: [PATCH 107/569] Allow the latest build_config (#455) Breaking changes were only for uses of the Dart API, no breaking changes to parsing `build.yaml`. --- json_serializable/CHANGELOG.md | 1 + json_serializable/pubspec.yaml | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index ec427c596..da4ac4539 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,6 +1,7 @@ ## 2.2.2 - Require at least Dart `2.2.0`. +- Allow `build_config` `0.4.x`. ## 2.2.1 diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 363377d09..561706904 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 2.2.2-dev +version: 2.2.2 author: Dart Team description: >- Automatically generate code for converting to and from JSON by annotating @@ -11,7 +11,7 @@ environment: dependencies: analyzer: '>=0.33.3 <0.37.0' build: '>=0.12.6 <2.0.0' - build_config: '>=0.2.6 <0.4.0' + build_config: '>=0.2.6 <0.5.0' # Use a tight version constraint to ensure that a constraint on # `json_annotation` properly constrains all features it provides. From 014042134d94a24a1f2842ec3dc125e171f8a415 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 23 Apr 2019 16:08:50 -0700 Subject: [PATCH 108/569] Support the latest build_web_compliers (alpha) dev dependency Allows us to get the latest pkg:analyzer --- json_serializable/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 561706904..2e501b7b7 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -23,7 +23,7 @@ dependencies: dev_dependencies: build_runner: ^1.0.0 build_verify: ^1.1.0 - build_web_compilers: ^1.0.0 + build_web_compilers: '>=1.0.0 <=2.0.0-alpha.2' collection: ^1.14.0 dart_style: ^1.2.0 logging: ^0.11.3+1 From 3b3e25e7522ad71011aa23656b3cd66cdc8b860c Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 23 Apr 2019 16:26:34 -0700 Subject: [PATCH 109/569] Removed special handling of undefined types due to pkg:analyzer changes These types are now treated as `dynamic` --- json_serializable/CHANGELOG.md | 5 ++ json_serializable/lib/src/decode_helper.dart | 3 - json_serializable/lib/src/field_helpers.dart | 5 +- json_serializable/lib/src/helper_core.dart | 29 +----- .../lib/src/type_helpers/value_helper.dart | 6 -- json_serializable/pubspec.yaml | 2 +- .../test/src/unknown_type_test_input.dart | 88 ++++++------------- 7 files changed, 36 insertions(+), 102 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index da4ac4539..713933e9b 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,8 @@ +## 2.2.3 + +- Removed special handling of undefined types due to changes in + `package:analyzer`. These types are now treated as `dynamic`. + ## 2.2.2 - Require at least Dart `2.2.0`. diff --git a/json_serializable/lib/src/decode_helper.dart b/json_serializable/lib/src/decode_helper.dart index e5f3b50f6..e737e4c03 100644 --- a/json_serializable/lib/src/decode_helper.dart +++ b/json_serializable/lib/src/decode_helper.dart @@ -269,9 +269,6 @@ _ConstructorData _writeConstructorInvocation( usedCtorParamsAndFields.add(arg.name); } - warnUndefinedElements( - constructorArguments.followedBy(namedConstructorArguments)); - // fields that aren't already set by the constructor and that aren't final final remainingFieldsForInvocationBody = writableFields.toSet().difference(usedCtorParamsAndFields); diff --git a/json_serializable/lib/src/field_helpers.dart b/json_serializable/lib/src/field_helpers.dart index f29674ef2..fe18ef38b 100644 --- a/json_serializable/lib/src/field_helpers.dart +++ b/json_serializable/lib/src/field_helpers.dart @@ -9,7 +9,6 @@ import 'package:analyzer/src/dart/resolver/inheritance_manager.dart' show InheritanceManager; // ignore: deprecated_member_use import 'package:source_gen/source_gen.dart'; -import 'helper_core.dart'; import 'utils.dart'; class _FieldSet implements Comparable<_FieldSet> { @@ -108,9 +107,7 @@ Iterable createSortedFieldSet(ClassElement element) { // Sort the fields using the `compare` implementation in _FieldSet fields.sort(); - final fieldList = fields.map((fs) => fs.field).toList(); - warnUndefinedElements(fieldList); - return fieldList; + return fields.map((fs) => fs.field).toList(); } const _dartCoreObjectChecker = TypeChecker.fromRuntime(Object); diff --git a/json_serializable/lib/src/helper_core.dart b/json_serializable/lib/src/helper_core.dart index ea23a353b..b8e663bf4 100644 --- a/json_serializable/lib/src/helper_core.dart +++ b/json_serializable/lib/src/helper_core.dart @@ -3,7 +3,6 @@ // BSD-style license that can be found in the LICENSE file. import 'package:analyzer/dart/element/element.dart'; -import 'package:build/build.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:meta/meta.dart'; import 'package:source_gen/source_gen.dart'; @@ -56,22 +55,12 @@ abstract class HelperCore { InvalidGenerationSourceError createInvalidGenerationError( String targetMember, FieldElement field, UnsupportedTypeError e) { var message = 'Could not generate `$targetMember` code for `${field.name}`'; - - var todo = 'Make sure all of the types are serializable.'; - - if (e.type.isUndefined) { - message = '$message because the type is undefined.'; - todo = "Check your imports. If you're trying to generate code for a " - 'Platform-provided type, you may have to specify a custom ' - '`$targetMember` in the associated `@JsonKey` annotation.'; - } else { - if (field.type != e.type) { - message = '$message because of type `${e.type}`'; - } - - message = '$message.\n${e.reason}'; + if (field.type != e.type) { + message = '$message because of type `${e.type}`'; } + message = '$message.\n${e.reason}'; + final todo = 'Make sure all of the types are serializable.'; return InvalidGenerationSourceError(message, todo: todo, element: field); } @@ -106,13 +95,3 @@ String genericClassArguments(ClassElement element, bool withConstraints) { .join(', '); return '<$values>'; } - -void warnUndefinedElements(Iterable elements) { - for (final element in elements.where((fe) => fe.type.isUndefined)) { - final span = spanForElement(element); - log.warning(''' -This element has an undefined type. It may causes issues when generated code. -${span.start.toolString} -${span.highlight()}'''); - } -} diff --git a/json_serializable/lib/src/type_helpers/value_helper.dart b/json_serializable/lib/src/type_helpers/value_helper.dart index 8fc52bd7d..361451db5 100644 --- a/json_serializable/lib/src/type_helpers/value_helper.dart +++ b/json_serializable/lib/src/type_helpers/value_helper.dart @@ -14,9 +14,6 @@ class ValueHelper extends TypeHelper { @override String serialize( DartType targetType, String expression, TypeHelperContext context) { - if (targetType.isUndefined) { - return null; - } if (targetType.isDynamic || targetType.isObject || simpleJsonTypeChecker.isAssignableFromType(targetType)) { @@ -29,9 +26,6 @@ class ValueHelper extends TypeHelper { @override String deserialize( DartType targetType, String expression, TypeHelperContext context) { - if (targetType.isUndefined) { - return null; - } if (targetType.isDynamic || targetType.isObject) { // just return it as-is. We'll hope it's safe. return expression; diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 2e501b7b7..3d190d142 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 2.2.2 +version: 2.2.3-dev author: Dart Team description: >- Automatically generate code for converting to and from JSON by annotating diff --git a/json_serializable/test/src/unknown_type_test_input.dart b/json_serializable/test/src/unknown_type_test_input.dart index ff36f0c37..cb98f7e3e 100644 --- a/json_serializable/test/src/unknown_type_test_input.dart +++ b/json_serializable/test/src/unknown_type_test_input.dart @@ -1,20 +1,15 @@ part of '_json_serializable_test_input.dart'; -@ShouldThrow( - 'Could not generate `fromJson` code for `number` because the type ' - 'is undefined.', - expectedLogItems: [ - ''' -This element has an undefined type. It may causes issues when generated code. -package:__test__/unknown_type_test_input.dart:25:28 - ╷ -25 │ UnknownCtorParamType(Bob number) : number = number; - │ ^^^^^^ - ╵''' - ], - todo: 'Check your imports. If you\'re trying to generate code for a ' - 'Platform-provided type, you may have to specify a custom `fromJson` ' - 'in the associated `@JsonKey` annotation.', +@ShouldGenerate( + r''' +UnknownCtorParamType _$UnknownCtorParamTypeFromJson(Map json) { + return UnknownCtorParamType(json['number']); +} + +Map _$UnknownCtorParamTypeToJson( + UnknownCtorParamType instance) => + {'number': instance.number}; +''', configurations: ['default'], ) @JsonSerializable() @@ -25,21 +20,15 @@ class UnknownCtorParamType { UnknownCtorParamType(Bob number) : number = number; } -@ShouldThrow( - 'Could not generate `fromJson` code for `number` because the type ' - 'is undefined.', - expectedLogItems: [ - ''' -This element has an undefined type. It may causes issues when generated code. -package:__test__/unknown_type_test_input.dart:48:7 - ╷ -48 │ Bob number; - │ ^^^^^^ - ╵''' - ], - todo: 'Check your imports. If you\'re trying to generate code for a ' - 'Platform-provided type, you may have to specify a custom `fromJson` ' - 'in the associated `@JsonKey` annotation.', +@ShouldGenerate( + r''' +UnknownFieldType _$UnknownFieldTypeFromJson(Map json) { + return UnknownFieldType()..number = json['number']; +} + +Map _$UnknownFieldTypeToJson(UnknownFieldType instance) => + {'number': instance.number}; +''', configurations: ['default'], ) @JsonSerializable() @@ -48,21 +37,12 @@ class UnknownFieldType { Bob number; } -@ShouldThrow( - 'Could not generate `toJson` code for `number` because the type ' - 'is undefined.', - expectedLogItems: [ - ''' -This element has an undefined type. It may causes issues when generated code. -package:__test__/unknown_type_test_input.dart:71:7 - ╷ -71 │ Bob number; - │ ^^^^^^ - ╵''' - ], - todo: 'Check your imports. If you\'re trying to generate code for a ' - 'Platform-provided type, you may have to specify a custom `toJson` ' - 'in the associated `@JsonKey` annotation.', +@ShouldGenerate( + r''' +Map _$UnknownFieldTypeToJsonOnlyToJson( + UnknownFieldTypeToJsonOnly instance) => + {'number': instance.number}; +''', configurations: ['default'], ) @JsonSerializable(createFactory: false) @@ -103,15 +83,6 @@ class _$UnknownFieldTypeWithConvertJsonMapWrapper extends $JsonMapWrapper { } ''', configurations: ['wrapped'], - expectedLogItems: [ - ''' -This element has an undefined type. It may causes issues when generated code. -package:__test__/unknown_type_test_input.dart:146:7 - ╷ -146 │ Bob number; - │ ^^^^^^ - ╵''' - ], ) @ShouldGenerate( r''' @@ -129,15 +100,6 @@ Map _$UnknownFieldTypeWithConvertToJson( }; ''', configurations: ['default'], - expectedLogItems: [ - ''' -This element has an undefined type. It may causes issues when generated code. -package:__test__/unknown_type_test_input.dart:146:7 - ╷ -146 │ Bob number; - │ ^^^^^^ - ╵''' - ], ) @JsonSerializable() class UnknownFieldTypeWithConvert { From 19761932a45a971f76cdc2d2c76f99360af0192f Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 23 Apr 2019 16:53:55 -0700 Subject: [PATCH 110/569] use latest mono_repo --- .travis.yml | 28 ++++++++++++++-------------- tool/travis.sh | 42 +++++++++++++++++++----------------------- 2 files changed, 33 insertions(+), 37 deletions(-) diff --git a/.travis.yml b/.travis.yml index 61a1d93fe..36705f505 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,4 @@ -# Created with package:mono_repo v2.0.0 +# Created with package:mono_repo v2.1.0 language: dart # Custom configuration @@ -21,6 +21,11 @@ jobs: dart: "2.2.0" env: PKGS="example json_annotation" script: ./tool/travis.sh dartfmt dartanalyzer_1 + - stage: analyzer_and_format + name: "SDK: 2.2.0; PKG: json_serializable; TASKS: `dartanalyzer --fatal-warnings .`" + dart: "2.2.0" + env: PKGS="json_serializable" + script: ./tool/travis.sh dartanalyzer_1 - stage: unit_test name: "SDK: 2.2.0; PKG: example; TASKS: `pub run test --run-skipped`" dart: "2.2.0" @@ -31,11 +36,16 @@ jobs: dart: dev env: PKGS="example" script: ./tool/travis.sh test_0 - - stage: analyzer_and_format - name: "SDK: 2.2.0; PKG: json_serializable; TASKS: `dartanalyzer --fatal-warnings .`" + - stage: unit_test + name: "SDK: 2.2.0; PKG: json_serializable; TASKS: `pub run build_runner test --delete-conflicting-outputs -- -p chrome`" dart: "2.2.0" env: PKGS="json_serializable" - script: ./tool/travis.sh dartanalyzer_1 + script: ./tool/travis.sh command + - stage: unit_test + name: "SDK: dev; PKG: json_serializable; TASKS: `pub run build_runner test --delete-conflicting-outputs -- -p chrome`" + dart: dev + env: PKGS="json_serializable" + script: ./tool/travis.sh command - stage: unit_test name: "SDK: 2.2.0; PKG: json_serializable; TASKS: `pub run test`" dart: "2.2.0" @@ -56,16 +66,6 @@ jobs: dart: dev env: PKGS="json_serializable" script: ./tool/travis.sh test_2 - - stage: unit_test - name: "SDK: 2.2.0; PKG: json_serializable; TASKS: `pub run build_runner test --delete-conflicting-outputs -- -p chrome`" - dart: "2.2.0" - env: PKGS="json_serializable" - script: ./tool/travis.sh command - - stage: unit_test - name: "SDK: dev; PKG: json_serializable; TASKS: `pub run build_runner test --delete-conflicting-outputs -- -p chrome`" - dart: dev - env: PKGS="json_serializable" - script: ./tool/travis.sh command stages: - analyzer_and_format diff --git a/tool/travis.sh b/tool/travis.sh index 27cd515dc..2a414963d 100755 --- a/tool/travis.sh +++ b/tool/travis.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Created with package:mono_repo v2.0.0 +# Created with package:mono_repo v2.1.0 if [[ -z ${PKGS} ]]; then echo -e '\033[31mPKGS environment variable must be set!\033[0m' @@ -19,43 +19,39 @@ for PKG in ${PKGS}; do pub upgrade --no-precompile || exit $? for TASK in "$@"; do + echo + echo -e "\033[1mPKG: ${PKG}; TASK: ${TASK}\033[22m" case ${TASK} in - command) echo - echo -e '\033[1mTASK: command\033[22m' - echo -e 'pub run build_runner test --delete-conflicting-outputs -- -p chrome' + command) + echo 'pub run build_runner test --delete-conflicting-outputs -- -p chrome' pub run build_runner test --delete-conflicting-outputs -- -p chrome || EXIT_CODE=$? ;; - dartanalyzer_0) echo - echo -e '\033[1mTASK: dartanalyzer_0\033[22m' - echo -e 'dartanalyzer --fatal-warnings --fatal-infos .' + dartanalyzer_0) + echo 'dartanalyzer --fatal-warnings --fatal-infos .' dartanalyzer --fatal-warnings --fatal-infos . || EXIT_CODE=$? ;; - dartanalyzer_1) echo - echo -e '\033[1mTASK: dartanalyzer_1\033[22m' - echo -e 'dartanalyzer --fatal-warnings .' + dartanalyzer_1) + echo 'dartanalyzer --fatal-warnings .' dartanalyzer --fatal-warnings . || EXIT_CODE=$? ;; - dartfmt) echo - echo -e '\033[1mTASK: dartfmt\033[22m' - echo -e 'dartfmt -n --set-exit-if-changed .' + dartfmt) + echo 'dartfmt -n --set-exit-if-changed .' dartfmt -n --set-exit-if-changed . || EXIT_CODE=$? ;; - test_0) echo - echo -e '\033[1mTASK: test_0\033[22m' - echo -e 'pub run test --run-skipped' + test_0) + echo 'pub run test --run-skipped' pub run test --run-skipped || EXIT_CODE=$? ;; - test_1) echo - echo -e '\033[1mTASK: test_1\033[22m' - echo -e 'pub run test' + test_1) + echo 'pub run test' pub run test || EXIT_CODE=$? ;; - test_2) echo - echo -e '\033[1mTASK: test_2\033[22m' - echo -e 'pub run test --run-skipped test/ensure_build_test.dart' + test_2) + echo 'pub run test --run-skipped test/ensure_build_test.dart' pub run test --run-skipped test/ensure_build_test.dart || EXIT_CODE=$? ;; - *) echo -e "\033[31mNot expecting TASK '${TASK}'. Error!\033[0m" + *) + echo -e "\033[31mNot expecting TASK '${TASK}'. Error!\033[0m" EXIT_CODE=1 ;; esac From e8a82fb3e0a22f0c02fcdba99b0620740deebaed Mon Sep 17 00:00:00 2001 From: Jonathan White Date: Wed, 24 Apr 2019 12:14:31 -0700 Subject: [PATCH 111/569] Update README.md (#457) fix(documentation): Typo - Changed "buildy.yaml" to build.yaml --- json_serializable/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/json_serializable/README.md b/json_serializable/README.md index db635ea43..6958f6b07 100644 --- a/json_serializable/README.md +++ b/json_serializable/README.md @@ -119,7 +119,7 @@ is generated: If you find you want all or most of your classes with the same configuration, it may be easier to specify values once in the YAML file. Values set explicitly on `@JsonSerializable` take precedence over settings in - `buildy.yaml`. + `build.yaml`. > Note: There is some overlap between fields on `JsonKey` and `JsonSerializable`. In these cases, if a value is set explicitly via `JsonKey` From 08164fb60d6807a638a21b24d72fd29d217fd804 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 24 Apr 2019 12:42:54 -0700 Subject: [PATCH 112/569] support the latest pkg:build_web_compilers (#458) --- json_serializable/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 3d190d142..e9fd02aa4 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -23,7 +23,7 @@ dependencies: dev_dependencies: build_runner: ^1.0.0 build_verify: ^1.1.0 - build_web_compilers: '>=1.0.0 <=2.0.0-alpha.2' + build_web_compilers: '>=1.0.0 <3.0.0' collection: ^1.14.0 dart_style: ^1.2.0 logging: ^0.11.3+1 From 1362f34cc6358363b42d132382e4bcc517eaf582 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 30 Apr 2019 13:12:32 -0700 Subject: [PATCH 113/569] Add yaml_decode package (#459) Helps create helpful error messages when YAML decoding fails Towards https://github.com/dart-lang/json_serializable/issues/437 --- .travis.yml | 29 ++- json_serializable/build.yaml | 1 - json_serializable/test/yaml/yaml_test.dart | 213 ------------------ tool/travis.sh | 4 + yaml_decode/changelog.md | 3 + yaml_decode/lib/yaml_decode.dart | 84 +++++++ yaml_decode/mono_pkg.yaml | 10 + yaml_decode/pubspec.yaml | 16 ++ yaml_decode/readme.md | 1 + yaml_test/dart_test.yaml | 3 + yaml_test/mono_pkg.yaml | 21 ++ yaml_test/pubspec.yaml | 23 ++ yaml_test/test/ensure_build_test.dart | 13 ++ .../test/src}/angular_comp.yaml | 0 .../test/src}/angular_config.yaml | 0 .../test/src}/build_config.dart | 0 .../test/src}/build_config.g.dart | 0 .../test/src}/config_test.yaml | 0 yaml_test/test/yaml_test.dart | 190 ++++++++++++++++ 19 files changed, 393 insertions(+), 218 deletions(-) delete mode 100644 json_serializable/test/yaml/yaml_test.dart create mode 100644 yaml_decode/changelog.md create mode 100644 yaml_decode/lib/yaml_decode.dart create mode 100644 yaml_decode/mono_pkg.yaml create mode 100644 yaml_decode/pubspec.yaml create mode 100644 yaml_decode/readme.md create mode 100644 yaml_test/dart_test.yaml create mode 100644 yaml_test/mono_pkg.yaml create mode 100644 yaml_test/pubspec.yaml create mode 100644 yaml_test/test/ensure_build_test.dart rename {json_serializable/test/yaml => yaml_test/test/src}/angular_comp.yaml (100%) rename {json_serializable/test/yaml => yaml_test/test/src}/angular_config.yaml (100%) rename {json_serializable/test/yaml => yaml_test/test/src}/build_config.dart (100%) rename {json_serializable/test/yaml => yaml_test/test/src}/build_config.g.dart (100%) rename {json_serializable/test/yaml => yaml_test/test/src}/config_test.yaml (100%) create mode 100644 yaml_test/test/yaml_test.dart diff --git a/.travis.yml b/.travis.yml index 36705f505..cfc4bbffa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,9 +12,9 @@ branches: jobs: include: - stage: analyzer_and_format - name: "SDK: dev; PKGS: example, json_annotation, json_serializable; TASKS: [`dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-warnings --fatal-infos .`]" + name: "SDK: dev; PKGS: example, json_annotation, json_serializable, yaml_decode, yaml_test; TASKS: [`dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-warnings --fatal-infos .`]" dart: dev - env: PKGS="example json_annotation json_serializable" + env: PKGS="example json_annotation json_serializable yaml_decode yaml_test" script: ./tool/travis.sh dartfmt dartanalyzer_0 - stage: analyzer_and_format name: "SDK: 2.2.0; PKGS: example, json_annotation; TASKS: [`dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-warnings .`]" @@ -22,9 +22,9 @@ jobs: env: PKGS="example json_annotation" script: ./tool/travis.sh dartfmt dartanalyzer_1 - stage: analyzer_and_format - name: "SDK: 2.2.0; PKG: json_serializable; TASKS: `dartanalyzer --fatal-warnings .`" + name: "SDK: 2.2.0; PKGS: json_serializable, yaml_decode, yaml_test; TASKS: `dartanalyzer --fatal-warnings .`" dart: "2.2.0" - env: PKGS="json_serializable" + env: PKGS="json_serializable yaml_decode yaml_test" script: ./tool/travis.sh dartanalyzer_1 - stage: unit_test name: "SDK: 2.2.0; PKG: example; TASKS: `pub run test --run-skipped`" @@ -66,6 +66,26 @@ jobs: dart: dev env: PKGS="json_serializable" script: ./tool/travis.sh test_2 + - stage: unit_test + name: "SDK: 2.2.0; PKG: yaml_test; TASKS: `pub run test`" + dart: "2.2.0" + env: PKGS="yaml_test" + script: ./tool/travis.sh test_1 + - stage: unit_test + name: "SDK: dev; PKG: yaml_test; TASKS: `pub run test`" + dart: dev + env: PKGS="yaml_test" + script: ./tool/travis.sh test_1 + - stage: unit_test + name: "SDK: 2.2.0; PKG: yaml_test; TASKS: `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`" + dart: "2.2.0" + env: PKGS="yaml_test" + script: ./tool/travis.sh test_3 + - stage: unit_test + name: "SDK: dev; PKG: yaml_test; TASKS: `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`" + dart: dev + env: PKGS="yaml_test" + script: ./tool/travis.sh test_3 stages: - analyzer_and_format @@ -76,3 +96,4 @@ cache: - "$HOME/.pub-cache" - example/.dart_tool/build - json_serializable/.dart_tool/build + - yaml_test/.dart_tool diff --git a/json_serializable/build.yaml b/json_serializable/build.yaml index 43c300205..3551bc949 100644 --- a/json_serializable/build.yaml +++ b/json_serializable/build.yaml @@ -11,7 +11,6 @@ targets: - test/integration/* - test/kitchen_sink/* - test/literal/* - - test/yaml/* build_web_compilers|entrypoint: generate_for: - test/default_value/** diff --git a/json_serializable/test/yaml/yaml_test.dart b/json_serializable/test/yaml/yaml_test.dart deleted file mode 100644 index 7811a4877..000000000 --- a/json_serializable/test/yaml/yaml_test.dart +++ /dev/null @@ -1,213 +0,0 @@ -// Copyright (c) 2018, 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. - -@TestOn('vm') -import 'dart:io'; - -import 'package:json_annotation/json_annotation.dart'; -import 'package:path/path.dart' as p; -import 'package:test/test.dart'; -import 'package:yaml/yaml.dart'; - -import '../test_utils.dart'; -import 'build_config.dart'; - -final _root = p.join('test', 'yaml'); - -List _getTests() => Directory(_root) - .listSync() - .where((fse) => fse is File && p.extension(fse.path) == '.yaml') - .map((fse) => fse.path) - .toList(); - -void main() { - group('valid configurations', () { - for (final filePath in _getTests()) { - test(p.basenameWithoutExtension(filePath), () { - final content = File(filePath).readAsStringSync(); - final yamlContent = loadYaml(content, sourceUrl: filePath) as YamlMap; - - try { - final config = Config.fromJson(yamlContent); - expect(config, isNotNull); - } on CheckedFromJsonException catch (e) { - print(_prettyPrintCheckedFromJsonException(e)); - rethrow; - } - }); - } - }); - - group('bad configs', () { - var index = 0; - for (final entry in _badConfigs.entries) { - test('${index++}', () { - final yamlContent = - loadYaml(entry.key, sourceUrl: 'file.yaml') as YamlMap; - - expect(yamlContent, isNotNull); - printOnFailure(entry.key); - - try { - final config = Config.fromJson(yamlContent); - print(loudEncode(config)); - fail('parse should fail'); - } on CheckedFromJsonException catch (e) { - final prettyOutput = _prettyPrintCheckedFromJsonException(e); - printOnFailure("r'''\n$prettyOutput'''"); - expect(prettyOutput, entry.value); - } - }); - } - }); -} - -final _badConfigs = const { - r''' -builders: -- a -- b -''': r''' -line 2, column 1 of file.yaml: Could not create `Config`. Unsupported value for `builders`. - ╷ -2 │ ┌ - a -3 │ └ - b - ╵''', - r''' -builders: - sample: - defaultEnumTest: bob -''': r''' -line 3, column 22 of file.yaml: Could not create `Builder`. Unsupported value for `defaultEnumTest`. `bob` is not one of the supported values: none, dependents, all_packages, root_package - ╷ -3 │ defaultEnumTest: bob - │ ^^^ - ╵''', - r''' -builders: - a: - target: 42 - ''': r''' -line 3, column 13 of file.yaml: Could not create `Builder`. Unsupported value for `target`. - ╷ -3 │ target: 42 - │ ^^ - ╵''', - r''' -builders: - a: - target: "a target" - auto_apply: unsupported -''': r''' -line 4, column 17 of file.yaml: Could not create `Builder`. Unsupported value for `auto_apply`. `unsupported` is not one of the supported values: none, dependents, all_packages, root_package - ╷ -4 │ auto_apply: unsupported - │ ^^^^^^^^^^^ - ╵''', - r''' -builders: - a: - builder_factories: [] - ''': r''' -line 3, column 24 of file.yaml: Could not create `Builder`. Unsupported value for `builder_factories`. Must have at least one value. - ╷ -3 │ builder_factories: [] - │ ^^ - ╵''', - r''' -builders: - a: - foo: bar - baz: zap -''': r''' -Could not create `Builder`. -Unrecognized keys: [baz, foo]; supported keys: [target, import, is_optional, configLocation, auto_apply, build_to, defaultEnumTest, builder_factories, applies_builders, required_inputs, build_extensions] - -line 4, column 5 of file.yaml: Invalid key "baz" - ╷ -4 │ baz: zap - │ ^^^ - ╵ -line 3, column 5 of file.yaml: Invalid key "foo" - ╷ -3 │ foo: bar - │ ^^^ - ╵''', - r''' - bob: cool''': r''' -Could not create `Config`. -line 1, column 3 of file.yaml: Required keys are missing: builders. - ╷ -1 │ bob: cool - │ ^^^^^^^^^ - ╵''', - r''' -builders: - builder_name: - auto_apply:''': ''' -Could not create `Builder`. -line 3, column 5 of file.yaml: These keys had `null` values, which is not allowed: [auto_apply] - ╷ -3 │ auto_apply: - │ ^^^^^^^^^^^ - ╵''', - r''' -builders: - builder_name: - builder_factories: ["scssBuilder"] - configLocation: "user@host:invalid/uri"''': ''' -line 4, column 21 of file.yaml: Could not create `Builder`. Unsupported value for `configLocation`. Illegal scheme character at offset 4. - ╷ -4 │ configLocation: "user@host:invalid/uri" - │ ^^^^^^^^^^^^^^^^^^^^^^^ - ╵''' -}; - -String _prettyPrintCheckedFromJsonException(CheckedFromJsonException err) { - final yamlMap = err.map as YamlMap; - - YamlScalar _getYamlKey(String key) { - return yamlMap.nodes.keys.singleWhere((k) => (k as YamlScalar).value == key, - orElse: () => null) as YamlScalar; - } - - final innerError = err.innerError; - - var message = 'Could not create `${err.className}`.'; - if (innerError is BadKeyException) { - expect(err.message, innerError.message); - - if (innerError is UnrecognizedKeysException) { - message += '\n${innerError.message}\n'; - for (final key in innerError.unrecognizedKeys) { - final yamlKey = _getYamlKey(key); - assert(yamlKey != null); - message += '\n${yamlKey.span.message('Invalid key "$key"')}'; - } - } else if (innerError is MissingRequiredKeysException) { - expect(err.key, innerError.missingKeys.first); - message += '\n${yamlMap.span.message(innerError.message)}'; - } else if (innerError is DisallowedNullValueException) { - expect(err.key, innerError.keysWithNullValues.first); - message += '\n${yamlMap.span.message(innerError.message)}'; - } else { - throw UnsupportedError('${innerError.runtimeType} is not supported.'); - } - } else { - final yamlValue = yamlMap.nodes[err.key]; - - if (yamlValue == null) { - assert(err.key == null); - message = '${yamlMap.span.message(message)} ${err.innerError}'; - } else { - message = '$message Unsupported value for `${err.key}`.'; - if (err.message != null) { - message = '$message ${err.message}'; - } - message = yamlValue.span.message(message); - } - } - - return message; -} diff --git a/tool/travis.sh b/tool/travis.sh index 2a414963d..e6b0ab5c1 100755 --- a/tool/travis.sh +++ b/tool/travis.sh @@ -50,6 +50,10 @@ for PKG in ${PKGS}; do echo 'pub run test --run-skipped test/ensure_build_test.dart' pub run test --run-skipped test/ensure_build_test.dart || EXIT_CODE=$? ;; + test_3) + echo 'pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart' + pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart || EXIT_CODE=$? + ;; *) echo -e "\033[31mNot expecting TASK '${TASK}'. Error!\033[0m" EXIT_CODE=1 diff --git a/yaml_decode/changelog.md b/yaml_decode/changelog.md new file mode 100644 index 000000000..ef4ae7244 --- /dev/null +++ b/yaml_decode/changelog.md @@ -0,0 +1,3 @@ +## 1.0.0 + +- Initial release. diff --git a/yaml_decode/lib/yaml_decode.dart b/yaml_decode/lib/yaml_decode.dart new file mode 100644 index 000000000..1735f9c2c --- /dev/null +++ b/yaml_decode/lib/yaml_decode.dart @@ -0,0 +1,84 @@ +// Copyright (c) 2019, 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:json_annotation/json_annotation.dart'; +import 'package:yaml/yaml.dart'; + +/// Returns a [ParsedYamlException] for the provided [exception]. +/// +/// This function assumes `exception.map` is of type `YamlMap` from +/// `package:yaml`. If not, you may provide an alternative via [exceptionMap]. +ParsedYamlException toParsedYamlException( + CheckedFromJsonException exception, { + YamlMap exceptionMap, +}) { + final yamlMap = exceptionMap ?? exception.map as YamlMap; + + YamlNode _getYamlKey(String key) => + yamlMap.nodes.keys.singleWhere((k) => (k as YamlScalar).value == key, + orElse: () => null) as YamlScalar; + + final innerError = exception.innerError; + + if (exception.badKey) { + final key = (innerError is UnrecognizedKeysException) + ? innerError.unrecognizedKeys.first + : exception.key; + + final node = _getYamlKey(key) ?? yamlMap; + return ParsedYamlException( + exception.message, + node, + innerError: exception, + ); + } else { + final yamlValue = yamlMap.nodes[exception.key]; + + if (yamlValue == null) { + return ParsedYamlException( + exception.message, + yamlMap, + innerError: exception, + ); + } else { + var message = 'Unsupported value for "${exception.key}".'; + if (exception.message != null) { + message = '$message ${exception.message}'; + } + return ParsedYamlException( + message, + yamlValue, + innerError: exception, + ); + } + } +} + +/// An exception thrown when parsing YAML that contains information about the +/// location in the source where the exception occurred. +class ParsedYamlException implements Exception { + /// Describes the nature of the parse failure. + final String message; + + /// The node associated with this exception. + final YamlNode yamlNode; + + /// If this exception was thrown as a result of another error, + /// contains the source error object. + final Object innerError; + + ParsedYamlException( + this.message, + this.yamlNode, { + this.innerError, + }) : assert(message != null), + assert(yamlNode != null); + + /// Returns [message] formatted with source information provided by + /// [yamlNode]. + String get formattedMessage => yamlNode.span.message(message); + + @override + String toString() => 'ParsedYamlException: $message'; +} diff --git a/yaml_decode/mono_pkg.yaml b/yaml_decode/mono_pkg.yaml new file mode 100644 index 000000000..ae4462102 --- /dev/null +++ b/yaml_decode/mono_pkg.yaml @@ -0,0 +1,10 @@ +# See https://github.com/dart-lang/mono_repo for details +stages: +- analyzer_and_format: + - group: + - dartfmt + - dartanalyzer: --fatal-warnings --fatal-infos . + dart: [dev] + - group: + - dartanalyzer: --fatal-warnings . + dart: [2.2.0] diff --git a/yaml_decode/pubspec.yaml b/yaml_decode/pubspec.yaml new file mode 100644 index 000000000..3e21564ae --- /dev/null +++ b/yaml_decode/pubspec.yaml @@ -0,0 +1,16 @@ +name: yaml_decode +version: 1.0.0-dev +author: Dart Team +description: >- + Utilities for generating helpful error messages when decoding YAML documents + using package:json_serializable and package:yaml. +homepage: https://github.com/dart-lang/json_serializable +environment: + sdk: '>=2.2.0 <3.0.0' + +dependencies: + json_annotation: ^2.2.0 + yaml: ^2.1.13 + +dev_dependencies: + test: ^1.6.0 diff --git a/yaml_decode/readme.md b/yaml_decode/readme.md new file mode 100644 index 000000000..1fee59ede --- /dev/null +++ b/yaml_decode/readme.md @@ -0,0 +1 @@ +[![Pub Package](https://img.shields.io/pub/v/yaml_decode.svg)](https://pub.dartlang.org/packages/yaml_decode) diff --git a/yaml_test/dart_test.yaml b/yaml_test/dart_test.yaml new file mode 100644 index 000000000..1d7ac69cc --- /dev/null +++ b/yaml_test/dart_test.yaml @@ -0,0 +1,3 @@ +tags: + presubmit-only: + skip: "Should only be run during presubmit" diff --git a/yaml_test/mono_pkg.yaml b/yaml_test/mono_pkg.yaml new file mode 100644 index 000000000..d92eda8f6 --- /dev/null +++ b/yaml_test/mono_pkg.yaml @@ -0,0 +1,21 @@ +# See https://github.com/dart-lang/mono_repo for details +dart: +- 2.2.0 +- dev + +stages: +- analyzer_and_format: + - group: + - dartfmt + - dartanalyzer: --fatal-warnings --fatal-infos . + dart: [dev] + - group: + - dartanalyzer: --fatal-warnings . + dart: [2.2.0] +- unit_test: + - test + - test: --run-skipped -t presubmit-only test/ensure_build_test.dart + +cache: + directories: + - .dart_tool diff --git a/yaml_test/pubspec.yaml b/yaml_test/pubspec.yaml new file mode 100644 index 000000000..9730ee301 --- /dev/null +++ b/yaml_test/pubspec.yaml @@ -0,0 +1,23 @@ +name: yaml_test +publish_to: none + +environment: + sdk: '>=2.2.0 <3.0.0' + +dev_dependencies: + build_runner: ^1.0.0 + build_verify: ^1.1.0 + test: ^1.6.0 + + # Repo packages + json_annotation: any + json_serializable: any + yaml_decode: any + +dependency_overrides: + json_annotation: + path: ../json_annotation + json_serializable: + path: ../json_serializable + yaml_decode: + path: ../yaml_decode diff --git a/yaml_test/test/ensure_build_test.dart b/yaml_test/test/ensure_build_test.dart new file mode 100644 index 000000000..d9c8c6d0c --- /dev/null +++ b/yaml_test/test/ensure_build_test.dart @@ -0,0 +1,13 @@ +// Copyright (c) 2017, 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. + +@TestOn('vm') +@Tags(['presubmit-only']) +import 'package:build_verify/build_verify.dart'; +import 'package:test/test.dart'; + +void main() { + test('ensure_build', + () => expectBuildClean(packageRelativeDirectory: 'yaml_test')); +} diff --git a/json_serializable/test/yaml/angular_comp.yaml b/yaml_test/test/src/angular_comp.yaml similarity index 100% rename from json_serializable/test/yaml/angular_comp.yaml rename to yaml_test/test/src/angular_comp.yaml diff --git a/json_serializable/test/yaml/angular_config.yaml b/yaml_test/test/src/angular_config.yaml similarity index 100% rename from json_serializable/test/yaml/angular_config.yaml rename to yaml_test/test/src/angular_config.yaml diff --git a/json_serializable/test/yaml/build_config.dart b/yaml_test/test/src/build_config.dart similarity index 100% rename from json_serializable/test/yaml/build_config.dart rename to yaml_test/test/src/build_config.dart diff --git a/json_serializable/test/yaml/build_config.g.dart b/yaml_test/test/src/build_config.g.dart similarity index 100% rename from json_serializable/test/yaml/build_config.g.dart rename to yaml_test/test/src/build_config.g.dart diff --git a/json_serializable/test/yaml/config_test.yaml b/yaml_test/test/src/config_test.yaml similarity index 100% rename from json_serializable/test/yaml/config_test.yaml rename to yaml_test/test/src/config_test.yaml diff --git a/yaml_test/test/yaml_test.dart b/yaml_test/test/yaml_test.dart new file mode 100644 index 000000000..fcc20156e --- /dev/null +++ b/yaml_test/test/yaml_test.dart @@ -0,0 +1,190 @@ +// Copyright (c) 2018, 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. + +@TestOn('vm') +import 'dart:convert'; +import 'dart:io'; + +import 'package:json_annotation/json_annotation.dart'; +import 'package:path/path.dart' as p; +import 'package:test/test.dart'; +import 'package:yaml/yaml.dart'; +import 'package:yaml_decode/yaml_decode.dart'; + +import 'src/build_config.dart'; + +List _getTests() => Directory(p.join('test', 'src')) + .listSync() + .where((fse) => fse is File && p.extension(fse.path) == '.yaml') + .map((fse) => fse.path) + .toList(); + +void main() { + group('valid configurations', () { + for (final filePath in _getTests()) { + test(p.basenameWithoutExtension(filePath), () { + final content = File(filePath).readAsStringSync(); + final yamlContent = loadYaml(content, sourceUrl: filePath) as YamlMap; + + try { + final config = Config.fromJson(yamlContent); + expect(config, isNotNull); + } on CheckedFromJsonException catch (e) { + print(toParsedYamlException(e).formattedMessage); + rethrow; + } + }); + } + }); + + group('bad configs', () { + var index = 0; + for (final entry in _badConfigs.entries) { + test('${index++}', () { + final yamlContent = + loadYaml(entry.key, sourceUrl: 'file.yaml') as YamlMap; + + expect(yamlContent, isNotNull); + printOnFailure(entry.key); + + try { + final config = Config.fromJson(yamlContent); + print(loudEncode(config)); + fail('parse should fail'); + } on CheckedFromJsonException catch (e) { + final prettyOutput = toParsedYamlException(e).formattedMessage; + printOnFailure("r'''\n$prettyOutput'''"); + expect(prettyOutput, entry.value); + } + }); + } + }); +} + +final _badConfigs = const { + r''' +builders: +- a +- b +''': r''' +line 2, column 1 of file.yaml: Unsupported value for "builders". + ╷ +2 │ ┌ - a +3 │ └ - b + ╵''', + r''' +builders: + sample: + defaultEnumTest: bob +''': r''' +line 3, column 22 of file.yaml: Unsupported value for "defaultEnumTest". `bob` is not one of the supported values: none, dependents, all_packages, root_package + ╷ +3 │ defaultEnumTest: bob + │ ^^^ + ╵''', + r''' +builders: + a: + target: 42 + ''': r''' +line 3, column 13 of file.yaml: Unsupported value for "target". + ╷ +3 │ target: 42 + │ ^^ + ╵''', + r''' +builders: + a: + target: "a target" + auto_apply: unsupported +''': r''' +line 4, column 17 of file.yaml: Unsupported value for "auto_apply". `unsupported` is not one of the supported values: none, dependents, all_packages, root_package + ╷ +4 │ auto_apply: unsupported + │ ^^^^^^^^^^^ + ╵''', + r''' +builders: + a: + builder_factories: [] + ''': r''' +line 3, column 24 of file.yaml: Unsupported value for "builder_factories". Must have at least one value. + ╷ +3 │ builder_factories: [] + │ ^^ + ╵''', + r''' +builders: + a: + foo: bar + baz: zap +''': r''' +line 4, column 5 of file.yaml: Unrecognized keys: [baz, foo]; supported keys: [target, import, is_optional, configLocation, auto_apply, build_to, defaultEnumTest, builder_factories, applies_builders, required_inputs, build_extensions] + ╷ +4 │ baz: zap + │ ^^^ + ╵''', + r''' + bob: cool''': r''' +line 1, column 3 of file.yaml: Required keys are missing: builders. + ╷ +1 │ bob: cool + │ ^^^^^^^^^ + ╵''', + r''' +builders: + builder_name: + auto_apply:''': ''' +line 3, column 5 of file.yaml: These keys had `null` values, which is not allowed: [auto_apply] + ╷ +3 │ auto_apply: + │ ^^^^^^^^^^ + ╵''', + r''' +builders: + builder_name: + builder_factories: ["scssBuilder"] + configLocation: "user@host:invalid/uri"''': ''' +line 4, column 21 of file.yaml: Unsupported value for "configLocation". Illegal scheme character at offset 4. + ╷ +4 │ configLocation: "user@host:invalid/uri" + │ ^^^^^^^^^^^^^^^^^^^^^^^ + ╵''' +}; + +final throwsCastError = throwsA(isCastError); + +T roundTripObject( + T object, + T factory(Map json), { + bool skipObjectEquals = false, +}) { + final data = loudEncode(object); + + final object2 = factory(json.decode(data) as Map); + + if (!skipObjectEquals) { + expect(object2, equals(object)); + } + + final json2 = loudEncode(object2); + + expect(json2, equals(data)); + return object2; +} + +/// Prints out nested causes before throwing `JsonUnsupportedObjectError`. +String loudEncode(Object object) { + try { + return const JsonEncoder.withIndent(' ').convert(object); + } on JsonUnsupportedObjectError catch (e) { + var error = e; + do { + final cause = error.cause; + print(cause); + error = (cause is JsonUnsupportedObjectError) ? cause : null; + } while (error != null); + rethrow; + } +} From e8c302c9dc05b5f694dfda965d0288ab58b3a019 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 30 Apr 2019 13:33:53 -0700 Subject: [PATCH 114/569] yaml_decode: add example and associated tests --- .travis.yml | 20 ++++++++++++++++++++ yaml_decode/dart_test.yaml | 3 +++ yaml_decode/example/example.dart | 13 +++++++++++++ yaml_decode/example/example.g.dart | 16 ++++++++++++++++ yaml_decode/mono_pkg.yaml | 8 ++++++++ yaml_decode/pubspec.yaml | 3 +++ yaml_decode/test/ensure_build_test.dart | 13 +++++++++++++ 7 files changed, 76 insertions(+) create mode 100644 yaml_decode/dart_test.yaml create mode 100644 yaml_decode/example/example.dart create mode 100644 yaml_decode/example/example.g.dart create mode 100644 yaml_decode/test/ensure_build_test.dart diff --git a/.travis.yml b/.travis.yml index cfc4bbffa..354b9e0a8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -66,6 +66,26 @@ jobs: dart: dev env: PKGS="json_serializable" script: ./tool/travis.sh test_2 + - stage: unit_test + name: "SDK: 2.2.0; PKG: yaml_decode; TASKS: `pub run test`" + dart: "2.2.0" + env: PKGS="yaml_decode" + script: ./tool/travis.sh test_1 + - stage: unit_test + name: "SDK: dev; PKG: yaml_decode; TASKS: `pub run test`" + dart: dev + env: PKGS="yaml_decode" + script: ./tool/travis.sh test_1 + - stage: unit_test + name: "SDK: 2.2.0; PKG: yaml_decode; TASKS: `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`" + dart: "2.2.0" + env: PKGS="yaml_decode" + script: ./tool/travis.sh test_3 + - stage: unit_test + name: "SDK: dev; PKG: yaml_decode; TASKS: `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`" + dart: dev + env: PKGS="yaml_decode" + script: ./tool/travis.sh test_3 - stage: unit_test name: "SDK: 2.2.0; PKG: yaml_test; TASKS: `pub run test`" dart: "2.2.0" diff --git a/yaml_decode/dart_test.yaml b/yaml_decode/dart_test.yaml new file mode 100644 index 000000000..1d7ac69cc --- /dev/null +++ b/yaml_decode/dart_test.yaml @@ -0,0 +1,3 @@ +tags: + presubmit-only: + skip: "Should only be run during presubmit" diff --git a/yaml_decode/example/example.dart b/yaml_decode/example/example.dart new file mode 100644 index 000000000..bf37910ba --- /dev/null +++ b/yaml_decode/example/example.dart @@ -0,0 +1,13 @@ +import 'package:json_annotation/json_annotation.dart'; + +part 'example.g.dart'; + +@JsonSerializable(anyMap: true, checked: true, createToJson: false) +class Configuration { + final String name; + final int count; + + Configuration({this.name, this.count}); + + factory Configuration.fromJson(Map json) => _$ConfigurationFromJson(json); +} diff --git a/yaml_decode/example/example.g.dart b/yaml_decode/example/example.g.dart new file mode 100644 index 000000000..a4f672d4e --- /dev/null +++ b/yaml_decode/example/example.g.dart @@ -0,0 +1,16 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'example.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +Configuration _$ConfigurationFromJson(Map json) { + return $checkedNew('Configuration', json, () { + final val = Configuration( + name: $checkedConvert(json, 'name', (v) => v as String), + count: $checkedConvert(json, 'count', (v) => v as int)); + return val; + }); +} diff --git a/yaml_decode/mono_pkg.yaml b/yaml_decode/mono_pkg.yaml index ae4462102..0dcebd8b5 100644 --- a/yaml_decode/mono_pkg.yaml +++ b/yaml_decode/mono_pkg.yaml @@ -1,4 +1,8 @@ # See https://github.com/dart-lang/mono_repo for details +dart: +- 2.2.0 +- dev + stages: - analyzer_and_format: - group: @@ -8,3 +12,7 @@ stages: - group: - dartanalyzer: --fatal-warnings . dart: [2.2.0] + +- unit_test: + - test + - test: --run-skipped -t presubmit-only test/ensure_build_test.dart diff --git a/yaml_decode/pubspec.yaml b/yaml_decode/pubspec.yaml index 3e21564ae..fb3a29fe4 100644 --- a/yaml_decode/pubspec.yaml +++ b/yaml_decode/pubspec.yaml @@ -13,4 +13,7 @@ dependencies: yaml: ^2.1.13 dev_dependencies: + json_serializable: ^2.0.0 + build_runner: ^1.0.0 + build_verify: ^1.1.0 test: ^1.6.0 diff --git a/yaml_decode/test/ensure_build_test.dart b/yaml_decode/test/ensure_build_test.dart new file mode 100644 index 000000000..c66a84371 --- /dev/null +++ b/yaml_decode/test/ensure_build_test.dart @@ -0,0 +1,13 @@ +// Copyright (c) 2019, 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. + +@TestOn('vm') +@Tags(['presubmit-only']) +import 'package:build_verify/build_verify.dart'; +import 'package:test/test.dart'; + +void main() { + test('ensure_build', + () => expectBuildClean(packageRelativeDirectory: 'yaml_decode')); +} From 87e41b3f77a8d79e23b00e9cba009b5675b26952 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 30 Apr 2019 13:37:54 -0700 Subject: [PATCH 115/569] Merge all ensure_build tests into one stage --- .travis.yml | 53 +++++++++++---------------------- example/mono_pkg.yaml | 5 ++-- json_serializable/mono_pkg.yaml | 4 +-- mono_repo.yaml | 1 + tool/travis.sh | 10 +------ yaml_decode/mono_pkg.yaml | 1 + yaml_test/mono_pkg.yaml | 1 + 7 files changed, 26 insertions(+), 49 deletions(-) diff --git a/.travis.yml b/.travis.yml index 354b9e0a8..8d88ff829 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,12 +27,12 @@ jobs: env: PKGS="json_serializable yaml_decode yaml_test" script: ./tool/travis.sh dartanalyzer_1 - stage: unit_test - name: "SDK: 2.2.0; PKG: example; TASKS: `pub run test --run-skipped`" + name: "SDK: 2.2.0; PKG: example; TASKS: `pub run test`" dart: "2.2.0" env: PKGS="example" script: ./tool/travis.sh test_0 - stage: unit_test - name: "SDK: dev; PKG: example; TASKS: `pub run test --run-skipped`" + name: "SDK: dev; PKG: example; TASKS: `pub run test`" dart: dev env: PKGS="example" script: ./tool/travis.sh test_0 @@ -50,66 +50,47 @@ jobs: name: "SDK: 2.2.0; PKG: json_serializable; TASKS: `pub run test`" dart: "2.2.0" env: PKGS="json_serializable" - script: ./tool/travis.sh test_1 + script: ./tool/travis.sh test_0 - stage: unit_test name: "SDK: dev; PKG: json_serializable; TASKS: `pub run test`" dart: dev env: PKGS="json_serializable" - script: ./tool/travis.sh test_1 - - stage: unit_test - name: "SDK: 2.2.0; PKG: json_serializable; TASKS: `pub run test --run-skipped test/ensure_build_test.dart`" - dart: "2.2.0" - env: PKGS="json_serializable" - script: ./tool/travis.sh test_2 - - stage: unit_test - name: "SDK: dev; PKG: json_serializable; TASKS: `pub run test --run-skipped test/ensure_build_test.dart`" - dart: dev - env: PKGS="json_serializable" - script: ./tool/travis.sh test_2 + script: ./tool/travis.sh test_0 - stage: unit_test name: "SDK: 2.2.0; PKG: yaml_decode; TASKS: `pub run test`" dart: "2.2.0" env: PKGS="yaml_decode" - script: ./tool/travis.sh test_1 + script: ./tool/travis.sh test_0 - stage: unit_test name: "SDK: dev; PKG: yaml_decode; TASKS: `pub run test`" dart: dev env: PKGS="yaml_decode" - script: ./tool/travis.sh test_1 - - stage: unit_test - name: "SDK: 2.2.0; PKG: yaml_decode; TASKS: `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`" - dart: "2.2.0" - env: PKGS="yaml_decode" - script: ./tool/travis.sh test_3 - - stage: unit_test - name: "SDK: dev; PKG: yaml_decode; TASKS: `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`" - dart: dev - env: PKGS="yaml_decode" - script: ./tool/travis.sh test_3 + script: ./tool/travis.sh test_0 - stage: unit_test name: "SDK: 2.2.0; PKG: yaml_test; TASKS: `pub run test`" dart: "2.2.0" env: PKGS="yaml_test" - script: ./tool/travis.sh test_1 + script: ./tool/travis.sh test_0 - stage: unit_test name: "SDK: dev; PKG: yaml_test; TASKS: `pub run test`" dart: dev env: PKGS="yaml_test" - script: ./tool/travis.sh test_1 - - stage: unit_test - name: "SDK: 2.2.0; PKG: yaml_test; TASKS: `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`" + script: ./tool/travis.sh test_0 + - stage: ensure_build + name: "SDK: 2.2.0; PKGS: example, json_serializable, yaml_decode, yaml_test; TASKS: `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`" dart: "2.2.0" - env: PKGS="yaml_test" - script: ./tool/travis.sh test_3 - - stage: unit_test - name: "SDK: dev; PKG: yaml_test; TASKS: `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`" + env: PKGS="example json_serializable yaml_decode yaml_test" + script: ./tool/travis.sh test_1 + - stage: ensure_build + name: "SDK: dev; PKGS: example, json_serializable, yaml_decode, yaml_test; TASKS: `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`" dart: dev - env: PKGS="yaml_test" - script: ./tool/travis.sh test_3 + env: PKGS="example json_serializable yaml_decode yaml_test" + script: ./tool/travis.sh test_1 stages: - analyzer_and_format - unit_test + - ensure_build cache: directories: diff --git a/example/mono_pkg.yaml b/example/mono_pkg.yaml index 6552c64d3..e43ba1842 100644 --- a/example/mono_pkg.yaml +++ b/example/mono_pkg.yaml @@ -14,8 +14,9 @@ stages: - dartanalyzer: --fatal-warnings . dart: [2.2.0] - unit_test: - # Run the tests -- include the default-skipped presubmit tests - - test: --run-skipped + - test +- ensure_build: + - test: --run-skipped -t presubmit-only test/ensure_build_test.dart cache: directories: diff --git a/json_serializable/mono_pkg.yaml b/json_serializable/mono_pkg.yaml index c106b35fb..4ac6ea0d5 100644 --- a/json_serializable/mono_pkg.yaml +++ b/json_serializable/mono_pkg.yaml @@ -13,10 +13,10 @@ stages: - dartanalyzer: --fatal-warnings . dart: [2.2.0] - unit_test: - # Run the tests -- include the default-skipped presubmit tests - test - - test: --run-skipped test/ensure_build_test.dart - command: pub run build_runner test --delete-conflicting-outputs -- -p chrome +- ensure_build: + - test: --run-skipped -t presubmit-only test/ensure_build_test.dart cache: directories: diff --git a/mono_repo.yaml b/mono_repo.yaml index d2112e2c0..f86fdee31 100644 --- a/mono_repo.yaml +++ b/mono_repo.yaml @@ -9,3 +9,4 @@ travis: merge_stages: - analyzer_and_format +- ensure_build diff --git a/tool/travis.sh b/tool/travis.sh index e6b0ab5c1..becfa6d0c 100755 --- a/tool/travis.sh +++ b/tool/travis.sh @@ -39,18 +39,10 @@ for PKG in ${PKGS}; do dartfmt -n --set-exit-if-changed . || EXIT_CODE=$? ;; test_0) - echo 'pub run test --run-skipped' - pub run test --run-skipped || EXIT_CODE=$? - ;; - test_1) echo 'pub run test' pub run test || EXIT_CODE=$? ;; - test_2) - echo 'pub run test --run-skipped test/ensure_build_test.dart' - pub run test --run-skipped test/ensure_build_test.dart || EXIT_CODE=$? - ;; - test_3) + test_1) echo 'pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart' pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart || EXIT_CODE=$? ;; diff --git a/yaml_decode/mono_pkg.yaml b/yaml_decode/mono_pkg.yaml index 0dcebd8b5..aa71047e9 100644 --- a/yaml_decode/mono_pkg.yaml +++ b/yaml_decode/mono_pkg.yaml @@ -15,4 +15,5 @@ stages: - unit_test: - test +- ensure_build: - test: --run-skipped -t presubmit-only test/ensure_build_test.dart diff --git a/yaml_test/mono_pkg.yaml b/yaml_test/mono_pkg.yaml index d92eda8f6..3a90eb477 100644 --- a/yaml_test/mono_pkg.yaml +++ b/yaml_test/mono_pkg.yaml @@ -14,6 +14,7 @@ stages: dart: [2.2.0] - unit_test: - test +- ensure_build: - test: --run-skipped -t presubmit-only test/ensure_build_test.dart cache: From bfd8a06afb90bc1a6d426422aa19690d90d23dce Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 30 Apr 2019 15:49:56 -0700 Subject: [PATCH 116/569] Travis: Merge all stages (#462) 5 minutes faster! --- .travis.yml | 38 ++++---------------------------------- mono_repo.yaml | 1 + 2 files changed, 5 insertions(+), 34 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8d88ff829..98995d6e3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,14 +27,14 @@ jobs: env: PKGS="json_serializable yaml_decode yaml_test" script: ./tool/travis.sh dartanalyzer_1 - stage: unit_test - name: "SDK: 2.2.0; PKG: example; TASKS: `pub run test`" + name: "SDK: 2.2.0; PKGS: example, json_serializable, yaml_decode, yaml_test; TASKS: `pub run test`" dart: "2.2.0" - env: PKGS="example" + env: PKGS="example json_serializable yaml_decode yaml_test" script: ./tool/travis.sh test_0 - stage: unit_test - name: "SDK: dev; PKG: example; TASKS: `pub run test`" + name: "SDK: dev; PKGS: example, json_serializable, yaml_decode, yaml_test; TASKS: `pub run test`" dart: dev - env: PKGS="example" + env: PKGS="example json_serializable yaml_decode yaml_test" script: ./tool/travis.sh test_0 - stage: unit_test name: "SDK: 2.2.0; PKG: json_serializable; TASKS: `pub run build_runner test --delete-conflicting-outputs -- -p chrome`" @@ -46,36 +46,6 @@ jobs: dart: dev env: PKGS="json_serializable" script: ./tool/travis.sh command - - stage: unit_test - name: "SDK: 2.2.0; PKG: json_serializable; TASKS: `pub run test`" - dart: "2.2.0" - env: PKGS="json_serializable" - script: ./tool/travis.sh test_0 - - stage: unit_test - name: "SDK: dev; PKG: json_serializable; TASKS: `pub run test`" - dart: dev - env: PKGS="json_serializable" - script: ./tool/travis.sh test_0 - - stage: unit_test - name: "SDK: 2.2.0; PKG: yaml_decode; TASKS: `pub run test`" - dart: "2.2.0" - env: PKGS="yaml_decode" - script: ./tool/travis.sh test_0 - - stage: unit_test - name: "SDK: dev; PKG: yaml_decode; TASKS: `pub run test`" - dart: dev - env: PKGS="yaml_decode" - script: ./tool/travis.sh test_0 - - stage: unit_test - name: "SDK: 2.2.0; PKG: yaml_test; TASKS: `pub run test`" - dart: "2.2.0" - env: PKGS="yaml_test" - script: ./tool/travis.sh test_0 - - stage: unit_test - name: "SDK: dev; PKG: yaml_test; TASKS: `pub run test`" - dart: dev - env: PKGS="yaml_test" - script: ./tool/travis.sh test_0 - stage: ensure_build name: "SDK: 2.2.0; PKGS: example, json_serializable, yaml_decode, yaml_test; TASKS: `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`" dart: "2.2.0" diff --git a/mono_repo.yaml b/mono_repo.yaml index f86fdee31..12ed8f1fe 100644 --- a/mono_repo.yaml +++ b/mono_repo.yaml @@ -10,3 +10,4 @@ travis: merge_stages: - analyzer_and_format - ensure_build +- unit_test From 672d34dd79941130203eac1e1c33f76f001b2e4d Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 1 May 2019 07:32:28 -0700 Subject: [PATCH 117/569] yaml_decode: fill out example and add tests (#461) --- yaml_decode/example/example.dart | 42 +++++++++- yaml_decode/example/example.g.dart | 6 ++ yaml_decode/lib/yaml_decode.dart | 3 +- yaml_decode/pubspec.yaml | 3 + yaml_decode/test/example_test.dart | 123 +++++++++++++++++++++++++++++ 5 files changed, 174 insertions(+), 3 deletions(-) create mode 100644 yaml_decode/test/example_test.dart diff --git a/yaml_decode/example/example.dart b/yaml_decode/example/example.dart index bf37910ba..419f83903 100644 --- a/yaml_decode/example/example.dart +++ b/yaml_decode/example/example.dart @@ -1,13 +1,51 @@ +// Copyright (c) 2019, 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 'dart:io'; + import 'package:json_annotation/json_annotation.dart'; +import 'package:yaml/yaml.dart'; +import 'package:yaml_decode/yaml_decode.dart'; part 'example.g.dart'; -@JsonSerializable(anyMap: true, checked: true, createToJson: false) +@JsonSerializable( + anyMap: true, + checked: true, + disallowUnrecognizedKeys: true, + nullable: false, +) class Configuration { + @JsonKey(required: true) final String name; + @JsonKey(required: true) final int count; - Configuration({this.name, this.count}); + Configuration({this.name, this.count}) { + if (name.isEmpty) { + throw ArgumentError.value(name, 'name', 'Cannot be empty.'); + } + } factory Configuration.fromJson(Map json) => _$ConfigurationFromJson(json); + + Map toJson() => _$ConfigurationToJson(this); + + @override + String toString() => 'Configuration: ${toJson()}'; +} + +void main(List arguments) { + final fileContents = File(arguments.single).readAsStringSync(); + + final yamlMap = + loadYaml(fileContents, sourceUrl: arguments.single) as YamlMap; + + try { + final config = Configuration.fromJson(yamlMap); + print(config); + } on CheckedFromJsonException catch (e) { + throw toParsedYamlException(e); + } } diff --git a/yaml_decode/example/example.g.dart b/yaml_decode/example/example.g.dart index a4f672d4e..7c303ebd4 100644 --- a/yaml_decode/example/example.g.dart +++ b/yaml_decode/example/example.g.dart @@ -8,9 +8,15 @@ part of 'example.dart'; Configuration _$ConfigurationFromJson(Map json) { return $checkedNew('Configuration', json, () { + $checkKeys(json, + allowedKeys: const ['name', 'count'], + requiredKeys: const ['name', 'count']); final val = Configuration( name: $checkedConvert(json, 'name', (v) => v as String), count: $checkedConvert(json, 'count', (v) => v as int)); return val; }); } + +Map _$ConfigurationToJson(Configuration instance) => + {'name': instance.name, 'count': instance.count}; diff --git a/yaml_decode/lib/yaml_decode.dart b/yaml_decode/lib/yaml_decode.dart index 1735f9c2c..34ed9143b 100644 --- a/yaml_decode/lib/yaml_decode.dart +++ b/yaml_decode/lib/yaml_decode.dart @@ -36,6 +36,7 @@ ParsedYamlException toParsedYamlException( final yamlValue = yamlMap.nodes[exception.key]; if (yamlValue == null) { + // TODO(kevmoo): test this case! return ParsedYamlException( exception.message, yamlMap, @@ -80,5 +81,5 @@ class ParsedYamlException implements Exception { String get formattedMessage => yamlNode.span.message(message); @override - String toString() => 'ParsedYamlException: $message'; + String toString() => 'ParsedYamlException: $formattedMessage'; } diff --git a/yaml_decode/pubspec.yaml b/yaml_decode/pubspec.yaml index fb3a29fe4..53854ef16 100644 --- a/yaml_decode/pubspec.yaml +++ b/yaml_decode/pubspec.yaml @@ -16,4 +16,7 @@ dev_dependencies: json_serializable: ^2.0.0 build_runner: ^1.0.0 build_verify: ^1.1.0 + path: ^1.0.0 test: ^1.6.0 + test_descriptor: ^1.1.1 + test_process: ^1.0.1 diff --git a/yaml_decode/test/example_test.dart b/yaml_decode/test/example_test.dart new file mode 100644 index 000000000..5100a4e63 --- /dev/null +++ b/yaml_decode/test/example_test.dart @@ -0,0 +1,123 @@ +// Copyright (c) 2019, 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 'dart:convert'; +import 'dart:io'; + +import 'package:path/path.dart' as p; +import 'package:test/test.dart'; +import 'package:test_descriptor/test_descriptor.dart' as d; +import 'package:test_process/test_process.dart'; + +void main() { + test('valid input', () async { + final proc = await _run('{"name": "bob", "count": 42}'); + + await expectLater( + proc.stdout, + emitsInOrder(['Configuration: {name: bob, count: 42}']), + ); + + await proc.shouldExit(0); + }); + + test('empty map', () async { + final proc = await _run('{}'); + + await expectLater( + proc.stderr, + emitsInOrder( + LineSplitter.split(''' +Unhandled exception: +ParsedYamlException: line 1, column 1 of $_testYamlPath: Required keys are missing: name, count. + ╷ +1 │ {} + │ ^^ + ╵ +'''), + ), + ); + + await proc.shouldExit(isNot(0)); + }); + + test('unexpected key', () async { + final proc = await _run('{"bob": 42}'); + + await expectLater( + proc.stderr, + emitsInOrder( + LineSplitter.split(''' +Unhandled exception: +ParsedYamlException: line 1, column 2 of $_testYamlPath: Unrecognized keys: [bob]; supported keys: [name, count] + ╷ +1 │ {"bob": 42} + │ ^^^^^ + ╵ +'''), + ), + ); + + await proc.shouldExit(isNot(0)); + }); + + test('bad name type', () async { + final proc = await _run('{"name": 42, "count": 42}'); + + await expectLater( + proc.stderr, + emitsInOrder( + LineSplitter.split(''' +Unhandled exception: +ParsedYamlException: line 1, column 10 of $_testYamlPath: Unsupported value for "name". + ╷ +1 │ {"name": 42, "count": 42} + │ ^^ +'''), + ), + ); + + await proc.shouldExit(isNot(0)); + }); + test('bad name contents', () async { + final proc = await _run('{"name": "", "count": 42}'); + + await expectLater( + proc.stderr, + emitsInOrder( + LineSplitter.split(''' +Unhandled exception: +ParsedYamlException: line 1, column 10 of $_testYamlPath: Unsupported value for "name". Cannot be empty. + ╷ +1 │ {"name": "", "count": 42} + │ ^^ +'''), + ), + ); + + await proc.shouldExit(isNot(0)); + }); +} + +String get _testYamlPath => p.join(d.sandbox, 'test.yaml'); + +Future _run(String yamlContent) async { + await d.file('test.yaml', yamlContent).create(); + + return TestProcess.start( + dartPath, + ['example/example.dart', _testYamlPath], + ); +} + +final String dartPath = p.join(_sdkDir, 'bin', 'dart'); + +/// The path to the root directory of the SDK. +final String _sdkDir = (() { + // The Dart executable is in "/path/to/sdk/bin/dart", so two levels up is + // "/path/to/sdk". + final aboveExecutable = p.dirname(p.dirname(Platform.resolvedExecutable)); + assert(FileSystemEntity.isFileSync(p.join(aboveExecutable, 'version'))); + return aboveExecutable; +})(); From 259bccda195a87e772ac9cf5170856cb86ebe3a5 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 1 May 2019 08:31:14 -0700 Subject: [PATCH 118/569] example_test: no points for Rube Goldberg dart SDK path (#464) --- yaml_decode/test/example_test.dart | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/yaml_decode/test/example_test.dart b/yaml_decode/test/example_test.dart index 5100a4e63..313965055 100644 --- a/yaml_decode/test/example_test.dart +++ b/yaml_decode/test/example_test.dart @@ -106,18 +106,7 @@ Future _run(String yamlContent) async { await d.file('test.yaml', yamlContent).create(); return TestProcess.start( - dartPath, + Platform.resolvedExecutable, ['example/example.dart', _testYamlPath], ); } - -final String dartPath = p.join(_sdkDir, 'bin', 'dart'); - -/// The path to the root directory of the SDK. -final String _sdkDir = (() { - // The Dart executable is in "/path/to/sdk/bin/dart", so two levels up is - // "/path/to/sdk". - final aboveExecutable = p.dirname(p.dirname(Platform.resolvedExecutable)); - assert(FileSystemEntity.isFileSync(p.join(aboveExecutable, 'version'))); - return aboveExecutable; -})(); From e4b429316cd243ae386bb910056789d14d03631d Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 1 May 2019 18:27:44 -0700 Subject: [PATCH 119/569] Add pub version badges to json_serial + annotation (#465) Remove build badge from json_serializable We have it on the repo root readme. Unclear this is useful on the pub site --- json_annotation/README.md | 2 ++ json_serializable/README.md | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/json_annotation/README.md b/json_annotation/README.md index 3785e101a..301ed865f 100644 --- a/json_annotation/README.md +++ b/json_annotation/README.md @@ -1,3 +1,5 @@ +[![Pub Package](https://img.shields.io/pub/v/json_annotation.svg)](https://pub.dartlang.org/packages/json_annotation) + Defines the annotations used by [json_serializable] to create code for JSON serialization and deserialization. diff --git a/json_serializable/README.md b/json_serializable/README.md index 6958f6b07..74fbb73d1 100644 --- a/json_serializable/README.md +++ b/json_serializable/README.md @@ -1,4 +1,4 @@ -[![Build Status](https://travis-ci.org/dart-lang/json_serializable.svg?branch=master)](https://travis-ci.org/dart-lang/json_serializable) +[![Pub Package](https://img.shields.io/pub/v/json_serializable.svg)](https://pub.dartlang.org/packages/json_serializable) Provides [Dart Build System] builders for handling JSON. From b73502b3395eb839731846e9351e082efc795193 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 2 May 2019 09:51:26 -0700 Subject: [PATCH 120/569] Add checkedYamlDecode function and associated tests (#467) --- yaml_decode/example/example.dart | 14 ++----- yaml_decode/lib/yaml_decode.dart | 57 ++++++++++++++++++++++++++++ yaml_decode/pubspec.yaml | 1 + yaml_decode/test/example_test.dart | 60 ++++++++++++++++++++++++++++++ 4 files changed, 122 insertions(+), 10 deletions(-) diff --git a/yaml_decode/example/example.dart b/yaml_decode/example/example.dart index 419f83903..ae81a9331 100644 --- a/yaml_decode/example/example.dart +++ b/yaml_decode/example/example.dart @@ -5,7 +5,6 @@ import 'dart:io'; import 'package:json_annotation/json_annotation.dart'; -import 'package:yaml/yaml.dart'; import 'package:yaml_decode/yaml_decode.dart'; part 'example.g.dart'; @@ -39,13 +38,8 @@ class Configuration { void main(List arguments) { final fileContents = File(arguments.single).readAsStringSync(); - final yamlMap = - loadYaml(fileContents, sourceUrl: arguments.single) as YamlMap; - - try { - final config = Configuration.fromJson(yamlMap); - print(config); - } on CheckedFromJsonException catch (e) { - throw toParsedYamlException(e); - } + final config = checkedYamlDecode( + fileContents, (m) => Configuration.fromJson(m), + sourceUrl: arguments.single); + print(config); } diff --git a/yaml_decode/lib/yaml_decode.dart b/yaml_decode/lib/yaml_decode.dart index 34ed9143b..c7f44e965 100644 --- a/yaml_decode/lib/yaml_decode.dart +++ b/yaml_decode/lib/yaml_decode.dart @@ -5,6 +5,39 @@ import 'package:json_annotation/json_annotation.dart'; import 'package:yaml/yaml.dart'; +/// Decodes [yamlContent] as YAML and calls [constructor] with the resulting +/// [Map]. +/// +/// If there are errors thrown while decoding [yamlContent], if it is not a +/// [Map] or if [CheckedFromJsonException] is thrown when calling [constructor], +/// a [ParsedYamlException] will be thrown. +/// +/// If [sourceUrl] is passed, it's used as the URL from which the YAML +/// originated for error reporting. It can be a [String], a [Uri], or `null`. +T checkedYamlDecode( + String yamlContent, + T Function(Map) constructor, { + sourceUrl, +}) { + YamlNode yaml; + + try { + yaml = loadYamlNode(yamlContent, sourceUrl: sourceUrl); + } on YamlException catch (e) { + throw ParsedYamlException.fromYamlException(e); + } + + if (yaml is YamlMap) { + try { + return constructor(yaml); + } on CheckedFromJsonException catch (e) { + throw toParsedYamlException(e); + } + } + + throw ParsedYamlException('Not a map', yaml); +} + /// Returns a [ParsedYamlException] for the provided [exception]. /// /// This function assumes `exception.map` is of type `YamlMap` from @@ -63,6 +96,8 @@ class ParsedYamlException implements Exception { final String message; /// The node associated with this exception. + /// + /// May be `null` if there was an error decoding. final YamlNode yamlNode; /// If this exception was thrown as a result of another error, @@ -76,6 +111,9 @@ class ParsedYamlException implements Exception { }) : assert(message != null), assert(yamlNode != null); + factory ParsedYamlException.fromYamlException(YamlException exception) => + _WrappedYamlException(exception); + /// Returns [message] formatted with source information provided by /// [yamlNode]. String get formattedMessage => yamlNode.span.message(message); @@ -83,3 +121,22 @@ class ParsedYamlException implements Exception { @override String toString() => 'ParsedYamlException: $formattedMessage'; } + +class _WrappedYamlException implements ParsedYamlException { + _WrappedYamlException(this.innerError); + + @override + String get formattedMessage => innerError.span.message(innerError.message); + + @override + final YamlException innerError; + + @override + String get message => innerError.message; + + @override + YamlNode get yamlNode => null; + + @override + String toString() => 'ParsedYamlException: $formattedMessage'; +} diff --git a/yaml_decode/pubspec.yaml b/yaml_decode/pubspec.yaml index 53854ef16..a2ffa2eda 100644 --- a/yaml_decode/pubspec.yaml +++ b/yaml_decode/pubspec.yaml @@ -10,6 +10,7 @@ environment: dependencies: json_annotation: ^2.2.0 + source_span: ^1.0.0 yaml: ^2.1.13 dev_dependencies: diff --git a/yaml_decode/test/example_test.dart b/yaml_decode/test/example_test.dart index 313965055..af384feaa 100644 --- a/yaml_decode/test/example_test.dart +++ b/yaml_decode/test/example_test.dart @@ -42,6 +42,66 @@ ParsedYamlException: line 1, column 1 of $_testYamlPath: Required keys are missi await proc.shouldExit(isNot(0)); }); + test('not a map', () async { + final proc = await _run('42'); + + await expectLater( + proc.stderr, + emitsInOrder( + LineSplitter.split(''' +Unhandled exception: +ParsedYamlException: line 1, column 1 of $_testYamlPath: Not a map + ╷ +1 │ 42 + │ ^^ + ╵ +'''), + ), + ); + + await proc.shouldExit(isNot(0)); + }); + + test('invalid yaml', () async { + final proc = await _run('{'); + + await expectLater( + proc.stderr, + emitsInOrder( + LineSplitter.split(''' +Unhandled exception: +ParsedYamlException: line 1, column 2 of $_testYamlPath: Expected node content. + ╷ +1 │ { + │ ^ + ╵ +'''), + ), + ); + + await proc.shouldExit(isNot(0)); + }); + + test('duplicate keys', () async { + final proc = await _run('{"a":null, "a":null}'); + + await expectLater( + proc.stderr, + emitsInOrder( + LineSplitter.split(''' +Unhandled exception: +ParsedYamlException: line 1, column 12 of $_testYamlPath: Duplicate mapping key. + ╷ +1 │ {"a":null, "a":null} + │ ^^^ + ╵ +'''), + ), + ); + + await proc.shouldExit(isNot(0)); + }); + test('unexpected key', () async { final proc = await _run('{"bob": 42}'); From 0bc6f25b44d80e008b0f663a513810f754dfd9ac Mon Sep 17 00:00:00 2001 From: Nate Bosch Date: Thu, 2 May 2019 10:19:42 -0700 Subject: [PATCH 121/569] Eliminate new methods named with "get" (#468) https://dart.dev/guides/language/effective-dart/design#avoid-starting-a-method-name-with-get - Change `_getTests()` to `get _tests`. - Inline `_getYamlKey` since we can also inline the `orElse` case rather than using `null` and then `??`. --- yaml_decode/lib/yaml_decode.dart | 8 +++----- yaml_test/test/yaml_test.dart | 4 ++-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/yaml_decode/lib/yaml_decode.dart b/yaml_decode/lib/yaml_decode.dart index c7f44e965..790ba7a16 100644 --- a/yaml_decode/lib/yaml_decode.dart +++ b/yaml_decode/lib/yaml_decode.dart @@ -48,10 +48,6 @@ ParsedYamlException toParsedYamlException( }) { final yamlMap = exceptionMap ?? exception.map as YamlMap; - YamlNode _getYamlKey(String key) => - yamlMap.nodes.keys.singleWhere((k) => (k as YamlScalar).value == key, - orElse: () => null) as YamlScalar; - final innerError = exception.innerError; if (exception.badKey) { @@ -59,7 +55,9 @@ ParsedYamlException toParsedYamlException( ? innerError.unrecognizedKeys.first : exception.key; - final node = _getYamlKey(key) ?? yamlMap; + final node = yamlMap.nodes.keys.singleWhere( + (k) => (k as YamlScalar).value == key, + orElse: () => yamlMap) as YamlNode; return ParsedYamlException( exception.message, node, diff --git a/yaml_test/test/yaml_test.dart b/yaml_test/test/yaml_test.dart index fcc20156e..db767ab86 100644 --- a/yaml_test/test/yaml_test.dart +++ b/yaml_test/test/yaml_test.dart @@ -14,7 +14,7 @@ import 'package:yaml_decode/yaml_decode.dart'; import 'src/build_config.dart'; -List _getTests() => Directory(p.join('test', 'src')) +List get _tests => Directory(p.join('test', 'src')) .listSync() .where((fse) => fse is File && p.extension(fse.path) == '.yaml') .map((fse) => fse.path) @@ -22,7 +22,7 @@ List _getTests() => Directory(p.join('test', 'src')) void main() { group('valid configurations', () { - for (final filePath in _getTests()) { + for (final filePath in _tests) { test(p.basenameWithoutExtension(filePath), () { final content = File(filePath).readAsStringSync(); final yamlContent = loadYaml(content, sourceUrl: filePath) as YamlMap; From f7d262f3b88712053c44fc2f120cca86e69de941 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 2 May 2019 10:44:39 -0700 Subject: [PATCH 122/569] =?UTF-8?q?Add=20`allowNull`=20named=20arg=20?= =?UTF-8?q?=E2=80=93=C2=A0needed=20by=20build=5Fconfig=20(#469)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yaml_decode/lib/yaml_decode.dart | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/yaml_decode/lib/yaml_decode.dart b/yaml_decode/lib/yaml_decode.dart index 790ba7a16..aabf3570c 100644 --- a/yaml_decode/lib/yaml_decode.dart +++ b/yaml_decode/lib/yaml_decode.dart @@ -14,11 +14,17 @@ import 'package:yaml/yaml.dart'; /// /// If [sourceUrl] is passed, it's used as the URL from which the YAML /// originated for error reporting. It can be a [String], a [Uri], or `null`. +/// +/// If [allowNull] is `true`, a `null` value from [yamlContent] will be allowed +/// and passed to [constructor]. [constructor], therefore, will need to handle +/// `null` values. T checkedYamlDecode( String yamlContent, T Function(Map) constructor, { sourceUrl, + bool allowNull = false, }) { + allowNull ??= false; YamlNode yaml; try { @@ -27,15 +33,21 @@ T checkedYamlDecode( throw ParsedYamlException.fromYamlException(e); } + Map map; if (yaml is YamlMap) { - try { - return constructor(yaml); - } on CheckedFromJsonException catch (e) { - throw toParsedYamlException(e); - } + map = yaml; + } else if (allowNull && yaml is YamlScalar && yaml.value == null) { + // TODO(kevmoo): test this case! + map = null; + } else { + throw ParsedYamlException('Not a map', yaml); } - throw ParsedYamlException('Not a map', yaml); + try { + return constructor(map); + } on CheckedFromJsonException catch (e) { + throw toParsedYamlException(e); + } } /// Returns a [ParsedYamlException] for the provided [exception]. From 1d917cb26849db94d57decd3f5295b7cff8100ec Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 2 May 2019 12:19:29 -0700 Subject: [PATCH 123/569] Rename to checked_yaml (#470) --- .travis.yml | 32 +++++++++---------- {yaml_decode => _test_yaml}/dart_test.yaml | 0 {yaml_test => _test_yaml}/mono_pkg.yaml | 0 {yaml_test => _test_yaml}/pubspec.yaml | 8 ++--- .../test/ensure_build_test.dart | 2 +- .../test/src/angular_comp.yaml | 0 .../test/src/angular_config.yaml | 0 .../test/src/build_config.dart | 0 .../test/src/build_config.g.dart | 0 .../test/src/config_test.yaml | 0 {yaml_test => _test_yaml}/test/yaml_test.dart | 2 +- {yaml_decode => checked_yaml}/changelog.md | 0 {yaml_test => checked_yaml}/dart_test.yaml | 0 .../example/example.dart | 2 +- .../example/example.g.dart | 0 .../lib/checked_yaml.dart | 0 {yaml_decode => checked_yaml}/mono_pkg.yaml | 0 {yaml_decode => checked_yaml}/pubspec.yaml | 2 +- checked_yaml/readme.md | 1 + .../test/ensure_build_test.dart | 2 +- .../test/example_test.dart | 0 yaml_decode/readme.md | 1 - 22 files changed, 26 insertions(+), 26 deletions(-) rename {yaml_decode => _test_yaml}/dart_test.yaml (100%) rename {yaml_test => _test_yaml}/mono_pkg.yaml (100%) rename {yaml_test => _test_yaml}/pubspec.yaml (80%) rename {yaml_test => _test_yaml}/test/ensure_build_test.dart (84%) rename {yaml_test => _test_yaml}/test/src/angular_comp.yaml (100%) rename {yaml_test => _test_yaml}/test/src/angular_config.yaml (100%) rename {yaml_test => _test_yaml}/test/src/build_config.dart (100%) rename {yaml_test => _test_yaml}/test/src/build_config.g.dart (100%) rename {yaml_test => _test_yaml}/test/src/config_test.yaml (100%) rename {yaml_test => _test_yaml}/test/yaml_test.dart (99%) rename {yaml_decode => checked_yaml}/changelog.md (100%) rename {yaml_test => checked_yaml}/dart_test.yaml (100%) rename {yaml_decode => checked_yaml}/example/example.dart (95%) rename {yaml_decode => checked_yaml}/example/example.g.dart (100%) rename yaml_decode/lib/yaml_decode.dart => checked_yaml/lib/checked_yaml.dart (100%) rename {yaml_decode => checked_yaml}/mono_pkg.yaml (100%) rename {yaml_decode => checked_yaml}/pubspec.yaml (96%) create mode 100644 checked_yaml/readme.md rename {yaml_decode => checked_yaml}/test/ensure_build_test.dart (83%) rename {yaml_decode => checked_yaml}/test/example_test.dart (100%) delete mode 100644 yaml_decode/readme.md diff --git a/.travis.yml b/.travis.yml index 98995d6e3..b432f7c24 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,29 +12,29 @@ branches: jobs: include: - stage: analyzer_and_format - name: "SDK: dev; PKGS: example, json_annotation, json_serializable, yaml_decode, yaml_test; TASKS: [`dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-warnings --fatal-infos .`]" + name: "SDK: dev; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; TASKS: [`dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-warnings --fatal-infos .`]" dart: dev - env: PKGS="example json_annotation json_serializable yaml_decode yaml_test" + env: PKGS="_test_yaml checked_yaml example json_annotation json_serializable" script: ./tool/travis.sh dartfmt dartanalyzer_0 + - stage: analyzer_and_format + name: "SDK: 2.2.0; PKGS: _test_yaml, checked_yaml, json_serializable; TASKS: `dartanalyzer --fatal-warnings .`" + dart: "2.2.0" + env: PKGS="_test_yaml checked_yaml json_serializable" + script: ./tool/travis.sh dartanalyzer_1 - stage: analyzer_and_format name: "SDK: 2.2.0; PKGS: example, json_annotation; TASKS: [`dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-warnings .`]" dart: "2.2.0" env: PKGS="example json_annotation" script: ./tool/travis.sh dartfmt dartanalyzer_1 - - stage: analyzer_and_format - name: "SDK: 2.2.0; PKGS: json_serializable, yaml_decode, yaml_test; TASKS: `dartanalyzer --fatal-warnings .`" - dart: "2.2.0" - env: PKGS="json_serializable yaml_decode yaml_test" - script: ./tool/travis.sh dartanalyzer_1 - stage: unit_test - name: "SDK: 2.2.0; PKGS: example, json_serializable, yaml_decode, yaml_test; TASKS: `pub run test`" + name: "SDK: 2.2.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test`" dart: "2.2.0" - env: PKGS="example json_serializable yaml_decode yaml_test" + env: PKGS="_test_yaml checked_yaml example json_serializable" script: ./tool/travis.sh test_0 - stage: unit_test - name: "SDK: dev; PKGS: example, json_serializable, yaml_decode, yaml_test; TASKS: `pub run test`" + name: "SDK: dev; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test`" dart: dev - env: PKGS="example json_serializable yaml_decode yaml_test" + env: PKGS="_test_yaml checked_yaml example json_serializable" script: ./tool/travis.sh test_0 - stage: unit_test name: "SDK: 2.2.0; PKG: json_serializable; TASKS: `pub run build_runner test --delete-conflicting-outputs -- -p chrome`" @@ -47,14 +47,14 @@ jobs: env: PKGS="json_serializable" script: ./tool/travis.sh command - stage: ensure_build - name: "SDK: 2.2.0; PKGS: example, json_serializable, yaml_decode, yaml_test; TASKS: `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`" + name: "SDK: 2.2.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`" dart: "2.2.0" - env: PKGS="example json_serializable yaml_decode yaml_test" + env: PKGS="_test_yaml checked_yaml example json_serializable" script: ./tool/travis.sh test_1 - stage: ensure_build - name: "SDK: dev; PKGS: example, json_serializable, yaml_decode, yaml_test; TASKS: `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`" + name: "SDK: dev; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`" dart: dev - env: PKGS="example json_serializable yaml_decode yaml_test" + env: PKGS="_test_yaml checked_yaml example json_serializable" script: ./tool/travis.sh test_1 stages: @@ -65,6 +65,6 @@ stages: cache: directories: - "$HOME/.pub-cache" + - _test_yaml/.dart_tool - example/.dart_tool/build - json_serializable/.dart_tool/build - - yaml_test/.dart_tool diff --git a/yaml_decode/dart_test.yaml b/_test_yaml/dart_test.yaml similarity index 100% rename from yaml_decode/dart_test.yaml rename to _test_yaml/dart_test.yaml diff --git a/yaml_test/mono_pkg.yaml b/_test_yaml/mono_pkg.yaml similarity index 100% rename from yaml_test/mono_pkg.yaml rename to _test_yaml/mono_pkg.yaml diff --git a/yaml_test/pubspec.yaml b/_test_yaml/pubspec.yaml similarity index 80% rename from yaml_test/pubspec.yaml rename to _test_yaml/pubspec.yaml index 9730ee301..6877c0147 100644 --- a/yaml_test/pubspec.yaml +++ b/_test_yaml/pubspec.yaml @@ -1,4 +1,4 @@ -name: yaml_test +name: _test_yaml publish_to: none environment: @@ -10,14 +10,14 @@ dev_dependencies: test: ^1.6.0 # Repo packages + checked_yaml: any json_annotation: any json_serializable: any - yaml_decode: any dependency_overrides: + checked_yaml: + path: ../checked_yaml json_annotation: path: ../json_annotation json_serializable: path: ../json_serializable - yaml_decode: - path: ../yaml_decode diff --git a/yaml_test/test/ensure_build_test.dart b/_test_yaml/test/ensure_build_test.dart similarity index 84% rename from yaml_test/test/ensure_build_test.dart rename to _test_yaml/test/ensure_build_test.dart index d9c8c6d0c..acd110e44 100644 --- a/yaml_test/test/ensure_build_test.dart +++ b/_test_yaml/test/ensure_build_test.dart @@ -9,5 +9,5 @@ import 'package:test/test.dart'; void main() { test('ensure_build', - () => expectBuildClean(packageRelativeDirectory: 'yaml_test')); + () => expectBuildClean(packageRelativeDirectory: '_test_yaml')); } diff --git a/yaml_test/test/src/angular_comp.yaml b/_test_yaml/test/src/angular_comp.yaml similarity index 100% rename from yaml_test/test/src/angular_comp.yaml rename to _test_yaml/test/src/angular_comp.yaml diff --git a/yaml_test/test/src/angular_config.yaml b/_test_yaml/test/src/angular_config.yaml similarity index 100% rename from yaml_test/test/src/angular_config.yaml rename to _test_yaml/test/src/angular_config.yaml diff --git a/yaml_test/test/src/build_config.dart b/_test_yaml/test/src/build_config.dart similarity index 100% rename from yaml_test/test/src/build_config.dart rename to _test_yaml/test/src/build_config.dart diff --git a/yaml_test/test/src/build_config.g.dart b/_test_yaml/test/src/build_config.g.dart similarity index 100% rename from yaml_test/test/src/build_config.g.dart rename to _test_yaml/test/src/build_config.g.dart diff --git a/yaml_test/test/src/config_test.yaml b/_test_yaml/test/src/config_test.yaml similarity index 100% rename from yaml_test/test/src/config_test.yaml rename to _test_yaml/test/src/config_test.yaml diff --git a/yaml_test/test/yaml_test.dart b/_test_yaml/test/yaml_test.dart similarity index 99% rename from yaml_test/test/yaml_test.dart rename to _test_yaml/test/yaml_test.dart index db767ab86..cb77b188b 100644 --- a/yaml_test/test/yaml_test.dart +++ b/_test_yaml/test/yaml_test.dart @@ -6,11 +6,11 @@ import 'dart:convert'; import 'dart:io'; +import 'package:checked_yaml/checked_yaml.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:path/path.dart' as p; import 'package:test/test.dart'; import 'package:yaml/yaml.dart'; -import 'package:yaml_decode/yaml_decode.dart'; import 'src/build_config.dart'; diff --git a/yaml_decode/changelog.md b/checked_yaml/changelog.md similarity index 100% rename from yaml_decode/changelog.md rename to checked_yaml/changelog.md diff --git a/yaml_test/dart_test.yaml b/checked_yaml/dart_test.yaml similarity index 100% rename from yaml_test/dart_test.yaml rename to checked_yaml/dart_test.yaml diff --git a/yaml_decode/example/example.dart b/checked_yaml/example/example.dart similarity index 95% rename from yaml_decode/example/example.dart rename to checked_yaml/example/example.dart index ae81a9331..5ed03edc8 100644 --- a/yaml_decode/example/example.dart +++ b/checked_yaml/example/example.dart @@ -4,8 +4,8 @@ import 'dart:io'; +import 'package:checked_yaml/checked_yaml.dart'; import 'package:json_annotation/json_annotation.dart'; -import 'package:yaml_decode/yaml_decode.dart'; part 'example.g.dart'; diff --git a/yaml_decode/example/example.g.dart b/checked_yaml/example/example.g.dart similarity index 100% rename from yaml_decode/example/example.g.dart rename to checked_yaml/example/example.g.dart diff --git a/yaml_decode/lib/yaml_decode.dart b/checked_yaml/lib/checked_yaml.dart similarity index 100% rename from yaml_decode/lib/yaml_decode.dart rename to checked_yaml/lib/checked_yaml.dart diff --git a/yaml_decode/mono_pkg.yaml b/checked_yaml/mono_pkg.yaml similarity index 100% rename from yaml_decode/mono_pkg.yaml rename to checked_yaml/mono_pkg.yaml diff --git a/yaml_decode/pubspec.yaml b/checked_yaml/pubspec.yaml similarity index 96% rename from yaml_decode/pubspec.yaml rename to checked_yaml/pubspec.yaml index a2ffa2eda..6293e2c8d 100644 --- a/yaml_decode/pubspec.yaml +++ b/checked_yaml/pubspec.yaml @@ -1,4 +1,4 @@ -name: yaml_decode +name: checked_yaml version: 1.0.0-dev author: Dart Team description: >- diff --git a/checked_yaml/readme.md b/checked_yaml/readme.md new file mode 100644 index 000000000..1a223c731 --- /dev/null +++ b/checked_yaml/readme.md @@ -0,0 +1 @@ +[![Pub Package](https://img.shields.io/pub/v/checked_yaml.svg)](https://pub.dartlang.org/packages/checked_yaml) diff --git a/yaml_decode/test/ensure_build_test.dart b/checked_yaml/test/ensure_build_test.dart similarity index 83% rename from yaml_decode/test/ensure_build_test.dart rename to checked_yaml/test/ensure_build_test.dart index c66a84371..bcb52649d 100644 --- a/yaml_decode/test/ensure_build_test.dart +++ b/checked_yaml/test/ensure_build_test.dart @@ -9,5 +9,5 @@ import 'package:test/test.dart'; void main() { test('ensure_build', - () => expectBuildClean(packageRelativeDirectory: 'yaml_decode')); + () => expectBuildClean(packageRelativeDirectory: 'checked_yaml')); } diff --git a/yaml_decode/test/example_test.dart b/checked_yaml/test/example_test.dart similarity index 100% rename from yaml_decode/test/example_test.dart rename to checked_yaml/test/example_test.dart diff --git a/yaml_decode/readme.md b/yaml_decode/readme.md deleted file mode 100644 index 1fee59ede..000000000 --- a/yaml_decode/readme.md +++ /dev/null @@ -1 +0,0 @@ -[![Pub Package](https://img.shields.io/pub/v/yaml_decode.svg)](https://pub.dartlang.org/packages/yaml_decode) From 033476956c245a3682b91fd6b7914fd1eec23aca Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 2 May 2019 12:17:07 -0700 Subject: [PATCH 124/569] Populate and test readme contents Update example to allow passing yaml directly on command line --- checked_yaml/example/example.dart | 14 ++++-- checked_yaml/readme.md | 80 +++++++++++++++++++++++++++++- checked_yaml/test/readme_test.dart | 68 +++++++++++++++++++++++++ 3 files changed, 158 insertions(+), 4 deletions(-) create mode 100644 checked_yaml/test/readme_test.dart diff --git a/checked_yaml/example/example.dart b/checked_yaml/example/example.dart index 5ed03edc8..7e9b820a0 100644 --- a/checked_yaml/example/example.dart +++ b/checked_yaml/example/example.dart @@ -36,10 +36,18 @@ class Configuration { } void main(List arguments) { - final fileContents = File(arguments.single).readAsStringSync(); + var sourcePathOrYaml = arguments.single; + String yamlContent; + + if (FileSystemEntity.isFileSync(sourcePathOrYaml)) { + yamlContent = File(sourcePathOrYaml).readAsStringSync(); + } else { + yamlContent = sourcePathOrYaml; + sourcePathOrYaml = null; + } final config = checkedYamlDecode( - fileContents, (m) => Configuration.fromJson(m), - sourceUrl: arguments.single); + yamlContent, (m) => Configuration.fromJson(m), + sourceUrl: sourcePathOrYaml); print(config); } diff --git a/checked_yaml/readme.md b/checked_yaml/readme.md index 1a223c731..f764b94c4 100644 --- a/checked_yaml/readme.md +++ b/checked_yaml/readme.md @@ -1 +1,79 @@ -[![Pub Package](https://img.shields.io/pub/v/checked_yaml.svg)](https://pub.dartlang.org/packages/checked_yaml) +[![Pub Package](https://img.shields.io/pub/v/yaml_decode.svg)](https://pub.dartlang.org/packages/yaml_decode) + +`package:yaml_decode` provides a `checkedYamlDecode` function that wraps the +the creation of classes annotated for [`package:json_serializable`] it helps +provide more helpful exceptions when the provided YAML is not compatible with +the target type. + +[`package:json_serializable`] can generate classes that can parse the +[`YamlMap`] type provided by [`package:yaml`] when `anyMap: true` is specified +for the class annotation. + +```dart +@JsonSerializable( + anyMap: true, + checked: true, + disallowUnrecognizedKeys: true, + nullable: false, +) +class Configuration { + @JsonKey(required: true) + final String name; + @JsonKey(required: true) + final int count; + + Configuration({this.name, this.count}) { + if (name.isEmpty) { + throw ArgumentError.value(name, 'name', 'Cannot be empty.'); + } + } + + factory Configuration.fromJson(Map json) => _$ConfigurationFromJson(json); + + Map toJson() => _$ConfigurationToJson(this); + + @override + String toString() => 'Configuration: ${toJson()}'; +} +``` + +When `checked: true` is set, exceptions thrown when decoding an instance from a +`Map` are wrapped in a `CheckedFromJsonException`. The +`checkedYamlDecode` function catches these exceptions and throws a +`ParsedYamlException` which maps the exception to the location in the input +YAML with the error. + +```dart +void main(List arguments) { + var sourcePathOrYaml = arguments.single; + String yamlContent; + + if (FileSystemEntity.isFileSync(sourcePathOrYaml)) { + yamlContent = File(sourcePathOrYaml).readAsStringSync(); + } else { + yamlContent = sourcePathOrYaml; + sourcePathOrYaml = null; + } + + final config = checkedYamlDecode( + yamlContent, (m) => Configuration.fromJson(m), + sourceUrl: sourcePathOrYaml); + print(config); +} +``` + +When parsing an invalid YAML file, an actionable error message is produced. + +```console +$ dart example/example.dart '{"name": "", "count": 1}' +Unhandled exception: +ParsedYamlException: line 1, column 10: Unsupported value for "name". Cannot be empty. + ╷ +1 │ {"name": "", "count": 1} + │ ^^ + ╵ +``` + +[`package:json_serializable`]: https://pub.dartlang.org/packages/json_serializable +[`package:yaml`]: https://pub.dartlang.org/packages/yaml +[`YamlMap`]: https://pub.dartlang.org/documentation/yaml/latest/yaml/YamlMap-class.html diff --git a/checked_yaml/test/readme_test.dart b/checked_yaml/test/readme_test.dart new file mode 100644 index 000000000..62ccb440d --- /dev/null +++ b/checked_yaml/test/readme_test.dart @@ -0,0 +1,68 @@ +// Copyright (c) 2019, 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 'dart:convert'; +import 'dart:io'; + +import 'package:path/path.dart' as p; +import 'package:test/test.dart'; +import 'package:test_process/test_process.dart'; + +final _examplePath = p.join('example', 'example.dart'); + +final _readmeContent = File('readme.md').readAsStringSync(); +final _exampleContent = File(_examplePath).readAsStringSync(); + +const _memberEnd = '\n}'; + +void _member(String startToken) { + final start = _exampleContent.indexOf(startToken); + expect(start, greaterThanOrEqualTo(0)); + + final classEnd = _exampleContent.indexOf(_memberEnd, start); + expect(classEnd, greaterThan(start)); + + final content = + _exampleContent.substring(start, classEnd + _memberEnd.length).trim(); + + expect(_readmeContent, contains(''' +```dart +$content +``` +''')); +} + +void main() { + test('class test', () { + _member('\n@JsonSerializable'); + }); + + test('main test', () { + _member('\nvoid main('); + }); + + test('ran example', () async { + final inputContent = '{"name": "", "count": 1}'; + final errorContent = r''' +Unhandled exception: +ParsedYamlException: line 1, column 10: Unsupported value for "name". Cannot be empty. + ╷ +1 │ {"name": "", "count": 1} + │ ^^ + ╵'''; + + expect(_readmeContent, contains(''' +```console +\$ dart example/example.dart '$inputContent' +$errorContent +```''')); + + final proc = await TestProcess.start( + Platform.resolvedExecutable, [_examplePath, inputContent]); + await expectLater( + proc.stderr, emitsInOrder(LineSplitter.split(errorContent))); + + await proc.shouldExit(isNot(0)); + }); +} From 0815cee5ee5327cc5881a20cda3967046f5f6e83 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 2 May 2019 12:17:40 -0700 Subject: [PATCH 125/569] Dramatically simplify example_test --- checked_yaml/pubspec.yaml | 1 - checked_yaml/test/example_test.dart | 176 +++++++++------------------- 2 files changed, 58 insertions(+), 119 deletions(-) diff --git a/checked_yaml/pubspec.yaml b/checked_yaml/pubspec.yaml index 6293e2c8d..2f4d4dd4a 100644 --- a/checked_yaml/pubspec.yaml +++ b/checked_yaml/pubspec.yaml @@ -19,5 +19,4 @@ dev_dependencies: build_verify: ^1.1.0 path: ^1.0.0 test: ^1.6.0 - test_descriptor: ^1.1.1 test_process: ^1.0.1 diff --git a/checked_yaml/test/example_test.dart b/checked_yaml/test/example_test.dart index af384feaa..8da3a11d5 100644 --- a/checked_yaml/test/example_test.dart +++ b/checked_yaml/test/example_test.dart @@ -2,171 +2,111 @@ // 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 'dart:convert'; -import 'dart:io'; - -import 'package:path/path.dart' as p; +import 'package:checked_yaml/checked_yaml.dart'; import 'package:test/test.dart'; -import 'package:test_descriptor/test_descriptor.dart' as d; -import 'package:test_process/test_process.dart'; -void main() { - test('valid input', () async { - final proc = await _run('{"name": "bob", "count": 42}'); +import '../example/example.dart' as example; - await expectLater( - proc.stdout, - emitsInOrder(['Configuration: {name: bob, count: 42}']), +void main() { + test('valid input', () { + expect( + () => _run('{"name": "bob", "count": 42}'), + prints(''' +Configuration: {name: bob, count: 42} +'''), ); - - await proc.shouldExit(0); }); - test('empty map', () async { - final proc = await _run('{}'); - - await expectLater( - proc.stderr, - emitsInOrder( - LineSplitter.split(''' -Unhandled exception: -ParsedYamlException: line 1, column 1 of $_testYamlPath: Required keys are missing: name, count. + test('empty map', () { + _expectThrows( + '{}', + r''' +line 1, column 1: Required keys are missing: name, count. ╷ 1 │ {} │ ^^ - ╵ -'''), - ), + ╵''', ); - - await proc.shouldExit(isNot(0)); }); - test('not a map', () async { - final proc = await _run('42'); - - await expectLater( - proc.stderr, - emitsInOrder( - LineSplitter.split(''' -Unhandled exception: -ParsedYamlException: line 1, column 1 of $_testYamlPath: Not a map + test('not a map', () { + _expectThrows( + '42', + r''' +line 1, column 1: Not a map ╷ 1 │ 42 │ ^^ - ╵ -'''), - ), + ╵''', ); - - await proc.shouldExit(isNot(0)); }); - test('invalid yaml', () async { - final proc = await _run('{'); - - await expectLater( - proc.stderr, - emitsInOrder( - LineSplitter.split(''' -Unhandled exception: -ParsedYamlException: line 1, column 2 of $_testYamlPath: Expected node content. + test('invalid yaml', () { + _expectThrows( + '{', + r''' +line 1, column 2: Expected node content. ╷ 1 │ { │ ^ - ╵ -'''), - ), + ╵''', ); - - await proc.shouldExit(isNot(0)); }); - test('duplicate keys', () async { - final proc = await _run('{"a":null, "a":null}'); - - await expectLater( - proc.stderr, - emitsInOrder( - LineSplitter.split(''' -Unhandled exception: -ParsedYamlException: line 1, column 12 of $_testYamlPath: Duplicate mapping key. + test('duplicate keys', () { + _expectThrows( + '{"a":null, "a":null}', + r''' +line 1, column 12: Duplicate mapping key. ╷ 1 │ {"a":null, "a":null} │ ^^^ - ╵ -'''), - ), + ╵''', ); - - await proc.shouldExit(isNot(0)); }); - test('unexpected key', () async { - final proc = await _run('{"bob": 42}'); - - await expectLater( - proc.stderr, - emitsInOrder( - LineSplitter.split(''' -Unhandled exception: -ParsedYamlException: line 1, column 2 of $_testYamlPath: Unrecognized keys: [bob]; supported keys: [name, count] + test('unexpected key', () { + _expectThrows( + '{"bob": 42}', + r''' +line 1, column 2: Unrecognized keys: [bob]; supported keys: [name, count] ╷ 1 │ {"bob": 42} │ ^^^^^ - ╵ -'''), - ), + ╵''', ); - - await proc.shouldExit(isNot(0)); }); - test('bad name type', () async { - final proc = await _run('{"name": 42, "count": 42}'); - - await expectLater( - proc.stderr, - emitsInOrder( - LineSplitter.split(''' -Unhandled exception: -ParsedYamlException: line 1, column 10 of $_testYamlPath: Unsupported value for "name". + test('bad name type', () { + _expectThrows( + '{"name": 42, "count": 42}', + r''' +line 1, column 10: Unsupported value for "name". ╷ 1 │ {"name": 42, "count": 42} │ ^^ -'''), - ), + ╵''', ); - - await proc.shouldExit(isNot(0)); }); - test('bad name contents', () async { - final proc = await _run('{"name": "", "count": 42}'); - await expectLater( - proc.stderr, - emitsInOrder( - LineSplitter.split(''' -Unhandled exception: -ParsedYamlException: line 1, column 10 of $_testYamlPath: Unsupported value for "name". Cannot be empty. + test('bad name contents', () { + _expectThrows( + '{"name": "", "count": 42}', + r''' +line 1, column 10: Unsupported value for "name". Cannot be empty. ╷ 1 │ {"name": "", "count": 42} │ ^^ -'''), - ), + ╵''', ); - - await proc.shouldExit(isNot(0)); }); } -String get _testYamlPath => p.join(d.sandbox, 'test.yaml'); - -Future _run(String yamlContent) async { - await d.file('test.yaml', yamlContent).create(); +void _expectThrows(String yamlContent, matcher) => expect( + () => _run(yamlContent), + throwsA(isA().having((e) { + printOnFailure("r'''\n${e.formattedMessage}'''"); + return e.formattedMessage; + }, 'formattedMessage', matcher))); - return TestProcess.start( - Platform.resolvedExecutable, - ['example/example.dart', _testYamlPath], - ); -} +void _run(String yamlContent) => example.main([yamlContent]); From edb6797e68a3949748c67d8808ebf7f67d17cd92 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 2 May 2019 12:17:49 -0700 Subject: [PATCH 126/569] pubspec: update description, prepare to release v1 --- checked_yaml/pubspec.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/checked_yaml/pubspec.yaml b/checked_yaml/pubspec.yaml index 2f4d4dd4a..2bd587d37 100644 --- a/checked_yaml/pubspec.yaml +++ b/checked_yaml/pubspec.yaml @@ -1,9 +1,9 @@ name: checked_yaml -version: 1.0.0-dev +version: 1.0.0 author: Dart Team description: >- - Utilities for generating helpful error messages when decoding YAML documents - using package:json_serializable and package:yaml. + Generate more helpful exceptions when decoding YAML documents using + package:json_serializable and package:yaml. homepage: https://github.com/dart-lang/json_serializable environment: sdk: '>=2.2.0 <3.0.0' From 10349de6843db695e6b60deb45d7eca85f5b545a Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 2 May 2019 12:48:20 -0700 Subject: [PATCH 127/569] checked_yaml: Add LICENSE, update repo readme --- README.md | 10 ++++++++++ checked_yaml/LICENSE | 26 ++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 checked_yaml/LICENSE diff --git a/README.md b/README.md index bee72733a..448e8b3a6 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,16 @@ The annotation package which has no dependencies. Import it into your pubspec `dependencies:` section. +## checked_yaml + +* Package: https://pub.dartlang.org/packages/checked_yaml +* [Source code](checked_yaml) + +Generate more helpful exceptions when decoding YAML documents using +`package:json_serializable` and `package:yaml`. + +Import it into your pubspec `dependencies:` section. + ## example * [Source code](example) diff --git a/checked_yaml/LICENSE b/checked_yaml/LICENSE new file mode 100644 index 000000000..f75d7c237 --- /dev/null +++ b/checked_yaml/LICENSE @@ -0,0 +1,26 @@ +Copyright 2019, the Dart project authors. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + * Neither the name of Google Inc. nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. From dd24f51a95cc01aa9db8aca724aea05c6a82feee Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 2 May 2019 13:18:26 -0700 Subject: [PATCH 128/569] Fix readme badge and package reference, release 1.0.1 --- checked_yaml/changelog.md | 4 ++++ checked_yaml/pubspec.yaml | 2 +- checked_yaml/readme.md | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/checked_yaml/changelog.md b/checked_yaml/changelog.md index ef4ae7244..12d709eef 100644 --- a/checked_yaml/changelog.md +++ b/checked_yaml/changelog.md @@ -1,3 +1,7 @@ +## 1.0.1 + +- Fix readme. + ## 1.0.0 - Initial release. diff --git a/checked_yaml/pubspec.yaml b/checked_yaml/pubspec.yaml index 2bd587d37..1090da527 100644 --- a/checked_yaml/pubspec.yaml +++ b/checked_yaml/pubspec.yaml @@ -1,5 +1,5 @@ name: checked_yaml -version: 1.0.0 +version: 1.0.1 author: Dart Team description: >- Generate more helpful exceptions when decoding YAML documents using diff --git a/checked_yaml/readme.md b/checked_yaml/readme.md index f764b94c4..44299b42b 100644 --- a/checked_yaml/readme.md +++ b/checked_yaml/readme.md @@ -1,6 +1,6 @@ -[![Pub Package](https://img.shields.io/pub/v/yaml_decode.svg)](https://pub.dartlang.org/packages/yaml_decode) +[![Pub Package](https://img.shields.io/pub/v/checked_yaml.svg)](https://pub.dartlang.org/packages/checked_yaml) -`package:yaml_decode` provides a `checkedYamlDecode` function that wraps the +`package:checked_yaml` provides a `checkedYamlDecode` function that wraps the the creation of classes annotated for [`package:json_serializable`] it helps provide more helpful exceptions when the provided YAML is not compatible with the target type. From 493cd4ec983c8ea9d36b3364066b5971acb4fb76 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 6 May 2019 23:15:29 -0700 Subject: [PATCH 129/569] Update links for pub.dev --- json_annotation/lib/json_annotation.dart | 2 +- json_serializable/README.md | 44 ++++++++++++------------ json_serializable/doc/doc.md | 44 ++++++++++++------------ json_serializable/lib/builder.dart | 2 +- json_serializable/tool/doc_builder.dart | 2 +- 5 files changed, 47 insertions(+), 47 deletions(-) diff --git a/json_annotation/lib/json_annotation.dart b/json_annotation/lib/json_annotation.dart index 1e7e58d9c..b9050657a 100644 --- a/json_annotation/lib/json_annotation.dart +++ b/json_annotation/lib/json_annotation.dart @@ -3,7 +3,7 @@ // BSD-style license that can be found in the LICENSE file. /// Provides annotation classes to use with -/// [json_serializable](https://pub.dartlang.org/packages/json_serializable). +/// [json_serializable](https://pub.dev/packages/json_serializable). /// /// Also contains helper functions and classes – prefixed with `$` used by /// `json_serializable` when the `use_wrappers` or `checked` options are diff --git a/json_serializable/README.md b/json_serializable/README.md index 74fbb73d1..8d98bd509 100644 --- a/json_serializable/README.md +++ b/json_serializable/README.md @@ -91,28 +91,28 @@ is generated: | | | [JsonKey.required] | | | | [JsonKey.toJson] | -[JsonSerializable.anyMap]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/anyMap.html -[JsonSerializable.checked]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/checked.html -[JsonSerializable.createFactory]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/createFactory.html -[JsonSerializable.createToJson]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/createToJson.html -[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html -[JsonSerializable.explicitToJson]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/explicitToJson.html -[JsonSerializable.fieldRename]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/fieldRename.html -[JsonSerializable.generateToJsonFunction]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/generateToJsonFunction.html -[JsonSerializable.useWrappers]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/useWrappers.html -[JsonSerializable.encodeEmptyCollection]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/encodeEmptyCollection.html -[JsonKey.encodeEmptyCollection]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonKey/encodeEmptyCollection.html -[JsonSerializable.includeIfNull]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/includeIfNull.html -[JsonKey.includeIfNull]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonKey/includeIfNull.html -[JsonSerializable.nullable]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/nullable.html -[JsonKey.nullable]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonKey/nullable.html -[JsonKey.defaultValue]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonKey/defaultValue.html -[JsonKey.disallowNullValue]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonKey/disallowNullValue.html -[JsonKey.fromJson]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonKey/fromJson.html -[JsonKey.ignore]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonKey/ignore.html -[JsonKey.name]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonKey/name.html -[JsonKey.required]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonKey/required.html -[JsonKey.toJson]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonKey/toJson.html +[JsonSerializable.anyMap]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/anyMap.html +[JsonSerializable.checked]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/checked.html +[JsonSerializable.createFactory]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/createFactory.html +[JsonSerializable.createToJson]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/createToJson.html +[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html +[JsonSerializable.explicitToJson]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/explicitToJson.html +[JsonSerializable.fieldRename]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/fieldRename.html +[JsonSerializable.generateToJsonFunction]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/generateToJsonFunction.html +[JsonSerializable.useWrappers]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/useWrappers.html +[JsonSerializable.encodeEmptyCollection]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/encodeEmptyCollection.html +[JsonKey.encodeEmptyCollection]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonKey/encodeEmptyCollection.html +[JsonSerializable.includeIfNull]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/includeIfNull.html +[JsonKey.includeIfNull]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonKey/includeIfNull.html +[JsonSerializable.nullable]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/nullable.html +[JsonKey.nullable]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonKey/nullable.html +[JsonKey.defaultValue]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonKey/defaultValue.html +[JsonKey.disallowNullValue]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonKey/disallowNullValue.html +[JsonKey.fromJson]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonKey/fromJson.html +[JsonKey.ignore]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonKey/ignore.html +[JsonKey.name]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonKey/name.html +[JsonKey.required]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonKey/required.html +[JsonKey.toJson]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonKey/toJson.html > Note: every `JsonSerializable` field is configurable via `build.yaml` – see the table for the corresponding key. diff --git a/json_serializable/doc/doc.md b/json_serializable/doc/doc.md index 6a51104b3..bc5de6710 100644 --- a/json_serializable/doc/doc.md +++ b/json_serializable/doc/doc.md @@ -20,25 +20,25 @@ | | | [JsonKey.required] | | | | [JsonKey.toJson] | -[JsonSerializable.anyMap]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/anyMap.html -[JsonSerializable.checked]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/checked.html -[JsonSerializable.createFactory]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/createFactory.html -[JsonSerializable.createToJson]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/createToJson.html -[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html -[JsonSerializable.explicitToJson]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/explicitToJson.html -[JsonSerializable.fieldRename]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/fieldRename.html -[JsonSerializable.generateToJsonFunction]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/generateToJsonFunction.html -[JsonSerializable.useWrappers]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/useWrappers.html -[JsonSerializable.encodeEmptyCollection]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/encodeEmptyCollection.html -[JsonKey.encodeEmptyCollection]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonKey/encodeEmptyCollection.html -[JsonSerializable.includeIfNull]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/includeIfNull.html -[JsonKey.includeIfNull]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonKey/includeIfNull.html -[JsonSerializable.nullable]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/nullable.html -[JsonKey.nullable]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonKey/nullable.html -[JsonKey.defaultValue]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonKey/defaultValue.html -[JsonKey.disallowNullValue]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonKey/disallowNullValue.html -[JsonKey.fromJson]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonKey/fromJson.html -[JsonKey.ignore]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonKey/ignore.html -[JsonKey.name]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonKey/name.html -[JsonKey.required]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonKey/required.html -[JsonKey.toJson]: https://pub.dartlang.org/documentation/json_annotation/2.2.0/json_annotation/JsonKey/toJson.html +[JsonSerializable.anyMap]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/anyMap.html +[JsonSerializable.checked]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/checked.html +[JsonSerializable.createFactory]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/createFactory.html +[JsonSerializable.createToJson]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/createToJson.html +[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html +[JsonSerializable.explicitToJson]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/explicitToJson.html +[JsonSerializable.fieldRename]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/fieldRename.html +[JsonSerializable.generateToJsonFunction]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/generateToJsonFunction.html +[JsonSerializable.useWrappers]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/useWrappers.html +[JsonSerializable.encodeEmptyCollection]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/encodeEmptyCollection.html +[JsonKey.encodeEmptyCollection]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonKey/encodeEmptyCollection.html +[JsonSerializable.includeIfNull]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/includeIfNull.html +[JsonKey.includeIfNull]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonKey/includeIfNull.html +[JsonSerializable.nullable]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/nullable.html +[JsonKey.nullable]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonKey/nullable.html +[JsonKey.defaultValue]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonKey/defaultValue.html +[JsonKey.disallowNullValue]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonKey/disallowNullValue.html +[JsonKey.fromJson]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonKey/fromJson.html +[JsonKey.ignore]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonKey/ignore.html +[JsonKey.name]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonKey/name.html +[JsonKey.required]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonKey/required.html +[JsonKey.toJson]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonKey/toJson.html diff --git a/json_serializable/lib/builder.dart b/json_serializable/lib/builder.dart index fc465702e..cd9014e26 100644 --- a/json_serializable/lib/builder.dart +++ b/json_serializable/lib/builder.dart @@ -5,7 +5,7 @@ /// Configuration for using `package:build`-compatible build systems. /// /// See: -/// * [build_runner](https://pub.dartlang.org/packages/build_runner) +/// * [build_runner](https://pub.dev/packages/build_runner) /// /// This library is **not** intended to be imported by typical end-users unless /// you are creating a custom compilation pipeline. See documentation for diff --git a/json_serializable/tool/doc_builder.dart b/json_serializable/tool/doc_builder.dart index a9a098a6a..864b744a6 100644 --- a/json_serializable/tool/doc_builder.dart +++ b/json_serializable/tool/doc_builder.dart @@ -112,7 +112,7 @@ String _anchorUriForName(String owner, String name) => '[$owner.$name]'; String _link(String version, String owner, String name) => '${_anchorUriForName(owner, name)}: ' - 'https://pub.dartlang.org/documentation/json_annotation/$version/' + 'https://pub.dev/documentation/json_annotation/$version/' 'json_annotation/$owner/$name.html'; class _FieldInfo implements Comparable<_FieldInfo> { From 818099560c8124c6653d0452ad6a2c8af6b9d902 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 7 May 2019 07:55:44 -0700 Subject: [PATCH 130/569] Update links for pub.dev --- README.md | 8 ++++---- checked_yaml/readme.md | 8 ++++---- example/README.md | 4 ++-- json_annotation/README.md | 4 ++-- json_serializable/CHANGELOG.md | 2 +- json_serializable/README.md | 4 ++-- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 448e8b3a6..f9bb8c746 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ deserialization. ## json_serializable -* Package: https://pub.dartlang.org/packages/json_serializable +* Package: https://pub.dev/packages/json_serializable * [Source code](json_serializable) The core package providing Generators for JSON-specific tasks. @@ -14,7 +14,7 @@ Import it into your pubspec `dev_dependencies:` section. ## json_annotation -* Package: https://pub.dartlang.org/packages/json_annotation +* Package: https://pub.dev/packages/json_annotation * [Source code](json_annotation) The annotation package which has no dependencies. @@ -23,7 +23,7 @@ Import it into your pubspec `dependencies:` section. ## checked_yaml -* Package: https://pub.dartlang.org/packages/checked_yaml +* Package: https://pub.dev/packages/checked_yaml * [Source code](checked_yaml) Generate more helpful exceptions when decoding YAML documents using @@ -38,4 +38,4 @@ Import it into your pubspec `dependencies:` section. An example showing how to setup and use `json_serializable` and `json_annotation`. -[source_gen]: https://pub.dartlang.org/packages/source_gen +[source_gen]: https://pub.dev/packages/source_gen diff --git a/checked_yaml/readme.md b/checked_yaml/readme.md index 44299b42b..0e60c0a8d 100644 --- a/checked_yaml/readme.md +++ b/checked_yaml/readme.md @@ -1,4 +1,4 @@ -[![Pub Package](https://img.shields.io/pub/v/checked_yaml.svg)](https://pub.dartlang.org/packages/checked_yaml) +[![Pub Package](https://img.shields.io/pub/v/checked_yaml.svg)](https://pub.dev/packages/checked_yaml) `package:checked_yaml` provides a `checkedYamlDecode` function that wraps the the creation of classes annotated for [`package:json_serializable`] it helps @@ -74,6 +74,6 @@ ParsedYamlException: line 1, column 10: Unsupported value for "name". Cannot be ╵ ``` -[`package:json_serializable`]: https://pub.dartlang.org/packages/json_serializable -[`package:yaml`]: https://pub.dartlang.org/packages/yaml -[`YamlMap`]: https://pub.dartlang.org/documentation/yaml/latest/yaml/YamlMap-class.html +[`package:json_serializable`]: https://pub.dev/packages/json_serializable +[`package:yaml`]: https://pub.dev/packages/yaml +[`YamlMap`]: https://pub.dev/documentation/yaml/latest/yaml/YamlMap-class.html diff --git a/example/README.md b/example/README.md index 2c154e1b5..97da92efe 100644 --- a/example/README.md +++ b/example/README.md @@ -39,5 +39,5 @@ Run `pub run build_runner build` to generate files into your source directory. [example]: lib/example.dart [example_g]: lib/example.g.dart -[json_annotation]: https://pub.dartlang.org/packages/json_annotation -[json_serializable]: https://pub.dartlang.org/packages/json_serializable +[json_annotation]: https://pub.dev/packages/json_annotation +[json_serializable]: https://pub.dev/packages/json_serializable diff --git a/json_annotation/README.md b/json_annotation/README.md index 301ed865f..008e9c7d0 100644 --- a/json_annotation/README.md +++ b/json_annotation/README.md @@ -1,4 +1,4 @@ -[![Pub Package](https://img.shields.io/pub/v/json_annotation.svg)](https://pub.dartlang.org/packages/json_annotation) +[![Pub Package](https://img.shields.io/pub/v/json_annotation.svg)](https://pub.dev/packages/json_annotation) Defines the annotations used by [json_serializable] to create code for JSON serialization and deserialization. @@ -11,4 +11,4 @@ Please file feature requests and bugs at the [issue tracker][tracker]. [example]: https://github.com/dart-lang/json_serializable/blob/master/example [tracker]: https://github.com/dart-lang/json_serializable/issues -[json_serializable]: https://pub.dartlang.org/packages/json_serializable +[json_serializable]: https://pub.dev/packages/json_serializable diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 713933e9b..af72447ae 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -483,7 +483,7 @@ ## 0.1.0 -* Split off from [source_gen](https://pub.dartlang.org/packages/source_gen). +* Split off from [source_gen](https://pub.dev/packages/source_gen). * Add `/* unsafe */` comments to generated output likely to be unsafe. diff --git a/json_serializable/README.md b/json_serializable/README.md index 8d98bd509..03a8b4c55 100644 --- a/json_serializable/README.md +++ b/json_serializable/README.md @@ -1,4 +1,4 @@ -[![Pub Package](https://img.shields.io/pub/v/json_serializable.svg)](https://pub.dartlang.org/packages/json_serializable) +[![Pub Package](https://img.shields.io/pub/v/json_serializable.svg)](https://pub.dev/packages/json_serializable) Provides [Dart Build System] builders for handling JSON. @@ -156,4 +156,4 @@ targets: [example]: https://github.com/dart-lang/json_serializable/blob/master/example [Dart Build System]: https://github.com/dart-lang/build -[package:json_annotation]: https://pub.dartlang.org/packages/json_annotation +[package:json_annotation]: https://pub.dev/packages/json_annotation From 7a67f6237a6a913720cd3d051ac99ed606e0610a Mon Sep 17 00:00:00 2001 From: Lynn Date: Thu, 9 May 2019 21:15:26 +0200 Subject: [PATCH 131/569] Add FieldRename.pascal (#475) Fixes https://github.com/dart-lang/json_serializable/issues/474 --- .../lib/src/json_serializable.dart | 5 +++- .../lib/src/json_serializable.g.dart | 3 +- json_serializable/lib/src/json_key_utils.dart | 2 ++ json_serializable/lib/src/utils.dart | 8 ++++++ json_serializable/pubspec.yaml | 4 +++ json_serializable/test/config_test.dart | 2 +- .../test/json_serializable_test.dart | 1 + .../test/src/field_namer_input.dart | 18 ++++++++++++ json_serializable/test/utils_test.dart | 28 ++++++++++++++++--- 9 files changed, 64 insertions(+), 7 deletions(-) diff --git a/json_annotation/lib/src/json_serializable.dart b/json_annotation/lib/src/json_serializable.dart index f41e0812d..d174f3816 100644 --- a/json_annotation/lib/src/json_serializable.dart +++ b/json_annotation/lib/src/json_serializable.dart @@ -17,7 +17,10 @@ enum FieldRename { kebab, /// Encodes a field named `snakeCase` with a JSON key `snake_case`. - snake + snake, + + /// Encodes a field named `pascalCase` with a JSON key `PascalCase`. + pascal } /// An annotation used to specify a class to generate code for. diff --git a/json_annotation/lib/src/json_serializable.g.dart b/json_annotation/lib/src/json_serializable.g.dart index bc2ab4192..2e9ef9a41 100644 --- a/json_annotation/lib/src/json_serializable.g.dart +++ b/json_annotation/lib/src/json_serializable.g.dart @@ -96,5 +96,6 @@ T _$enumDecodeNullable(Map enumValues, dynamic source) { const _$FieldRenameEnumMap = { FieldRename.none: 'none', FieldRename.kebab: 'kebab', - FieldRename.snake: 'snake' + FieldRename.snake: 'snake', + FieldRename.pascal: 'pascal' }; diff --git a/json_serializable/lib/src/json_key_utils.dart b/json_serializable/lib/src/json_key_utils.dart index 815e6ed73..1b952a178 100644 --- a/json_serializable/lib/src/json_key_utils.dart +++ b/json_serializable/lib/src/json_key_utils.dart @@ -190,6 +190,8 @@ String _encodedFieldName(JsonSerializable classAnnotation, return snakeCase(fieldElement.name); case FieldRename.kebab: return kebabCase(fieldElement.name); + case FieldRename.pascal: + return pascalCase(fieldElement.name); } return fieldElement.name; diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index 9c1866cf8..6adc6a5ed 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -27,6 +27,14 @@ String kebabCase(String input) => _fixCase(input, '-'); String snakeCase(String input) => _fixCase(input, '_'); +String pascalCase(String input) { + if (input.isEmpty) { + return ''; + } + + return input[0].toUpperCase() + input.substring(1); +} + String _fixCase(String input, String separator) => input.replaceAllMapped(_upperCase, (match) { var lower = match.group(0).toLowerCase(); diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index e9fd02aa4..1f4e029e9 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -31,3 +31,7 @@ dev_dependencies: source_gen_test: ^0.1.0 test: ^1.6.0 yaml: ^2.1.13 + +dependency_overrides: + json_annotation: + path: ../json_annotation diff --git a/json_serializable/test/config_test.dart b/json_serializable/test/config_test.dart index f6445df60..3eae88d26 100644 --- a/json_serializable/test/config_test.dart +++ b/json_serializable/test/config_test.dart @@ -111,7 +111,7 @@ void main() { config[entry.key] = entry.value; final lastLine = entry.key == 'field_rename' - ? '`42` is not one of the supported values: none, kebab, snake' + ? '`42` is not one of the supported values: none, kebab, snake, pascal' : "type 'int' is not a subtype of type 'bool' in type cast"; final matcher = isA().having( diff --git a/json_serializable/test/json_serializable_test.dart b/json_serializable/test/json_serializable_test.dart index 7fdc9d95e..db9dc0923 100644 --- a/json_serializable/test/json_serializable_test.dart +++ b/json_serializable/test/json_serializable_test.dart @@ -54,6 +54,7 @@ const _expectedAnnotatedTests = [ 'EncodeEmptyCollectionAsNullOnNonCollectionField', 'FieldNamerKebab', 'FieldNamerNone', + 'FieldNamerPascal', 'FieldNamerSnake', 'FieldWithFromJsonCtorAndTypeParams', 'FinalFields', diff --git a/json_serializable/test/src/field_namer_input.dart b/json_serializable/test/src/field_namer_input.dart index f25754804..06039ec89 100644 --- a/json_serializable/test/src/field_namer_input.dart +++ b/json_serializable/test/src/field_namer_input.dart @@ -36,6 +36,24 @@ class FieldNamerKebab { String nameOverride; } +@ShouldGenerate( + r''' +Map _$FieldNamerPascalToJson(FieldNamerPascal instance) => + { + 'TheField': instance.theField, + 'NAME_OVERRIDE': instance.nameOverride + }; +''', + configurations: ['default'], +) +@JsonSerializable(fieldRename: FieldRename.pascal, createFactory: false) +class FieldNamerPascal { + String theField; + + @JsonKey(name: 'NAME_OVERRIDE') + String nameOverride; +} + @ShouldGenerate( r''' Map _$FieldNamerSnakeToJson(FieldNamerSnake instance) => diff --git a/json_serializable/test/utils_test.dart b/json_serializable/test/utils_test.dart index 7caf9cd8f..aedc7d0a1 100644 --- a/json_serializable/test/utils_test.dart +++ b/json_serializable/test/utils_test.dart @@ -8,25 +8,45 @@ import 'package:test/test.dart'; import 'package:json_serializable/src/utils.dart'; -const _items = { +const _kebabItems = { 'simple': 'simple', 'twoWords': 'two-words', 'FirstBig': 'first-big' }; +const _pascalItems = { + 'simple': 'Simple', + 'twoWords': 'TwoWords', + 'FirstBig': 'FirstBig' +}; + +const _snakeItems = { + 'simple': 'simple', + 'twoWords': 'two_words', + 'FirstBig': 'first_big' +}; + void main() { group('kebab', () { - for (final entry in _items.entries) { + for (final entry in _kebabItems.entries) { test('"${entry.key}"', () { expect(kebabCase(entry.key), entry.value); }); } }); + group('pascal', () { + for (final entry in _pascalItems.entries) { + test('"${entry.key}"', () { + expect(pascalCase(entry.key), entry.value); + }); + } + }); + group('snake', () { - for (final entry in _items.entries) { + for (final entry in _snakeItems.entries) { test('"${entry.key}"', () { - expect(snakeCase(entry.key), entry.value.replaceAll('-', '_')); + expect(snakeCase(entry.key), entry.value); }); } }); From c98660b112728b0bf16caf7c086dbbf8dab4f51f Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 9 May 2019 14:24:38 -0700 Subject: [PATCH 132/569] Update pubspecs & changelogs for latest feature (#477) Prepare to release pkg:json_annotation v2.3.0 --- json_annotation/CHANGELOG.md | 3 ++- json_annotation/pubspec.yaml | 2 +- json_serializable/CHANGELOG.md | 4 ++++ json_serializable/pubspec.yaml | 4 ++-- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index 25f6614d3..fd138bfaa 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -1,5 +1,6 @@ -## 2.2.1 +## 2.3.0 +- Added `pascal` as an additional `fieldRename` option. - Require at least Dart `2.2.0`. ## 2.2.0 diff --git a/json_annotation/pubspec.yaml b/json_annotation/pubspec.yaml index 26d9e1e76..170e052e4 100644 --- a/json_annotation/pubspec.yaml +++ b/json_annotation/pubspec.yaml @@ -1,5 +1,5 @@ name: json_annotation -version: 2.2.1-dev +version: 2.3.0 description: >- Classes and helper functions that support JSON code generation via the `json_serializable` package. diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index af72447ae..8935aadae 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.3.0 + +- Added `pascal` as an additional `fieldRename` option. + ## 2.2.3 - Removed special handling of undefined types due to changes in diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 1f4e029e9..582c407d1 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 2.2.3-dev +version: 2.3.0-dev author: Dart Team description: >- Automatically generate code for converting to and from JSON by annotating @@ -15,7 +15,7 @@ dependencies: # Use a tight version constraint to ensure that a constraint on # `json_annotation` properly constrains all features it provides. - json_annotation: '>=2.1.0 <2.3.0' + json_annotation: '>=2.3.0 <2.4.0' meta: ^1.1.0 path: ^1.3.2 source_gen: ^0.9.0 From 80b3131c43246ca9f05d406ac961a7c8e3846041 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Fri, 10 May 2019 09:49:23 -0700 Subject: [PATCH 133/569] Prepare to release json_serializable 2.3.0 (#478) --- json_serializable/README.md | 44 +++++++++++++++++----------------- json_serializable/doc/doc.md | 44 +++++++++++++++++----------------- json_serializable/pubspec.yaml | 6 +---- 3 files changed, 45 insertions(+), 49 deletions(-) diff --git a/json_serializable/README.md b/json_serializable/README.md index 03a8b4c55..23abd24e0 100644 --- a/json_serializable/README.md +++ b/json_serializable/README.md @@ -91,28 +91,28 @@ is generated: | | | [JsonKey.required] | | | | [JsonKey.toJson] | -[JsonSerializable.anyMap]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/anyMap.html -[JsonSerializable.checked]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/checked.html -[JsonSerializable.createFactory]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/createFactory.html -[JsonSerializable.createToJson]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/createToJson.html -[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html -[JsonSerializable.explicitToJson]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/explicitToJson.html -[JsonSerializable.fieldRename]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/fieldRename.html -[JsonSerializable.generateToJsonFunction]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/generateToJsonFunction.html -[JsonSerializable.useWrappers]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/useWrappers.html -[JsonSerializable.encodeEmptyCollection]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/encodeEmptyCollection.html -[JsonKey.encodeEmptyCollection]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonKey/encodeEmptyCollection.html -[JsonSerializable.includeIfNull]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/includeIfNull.html -[JsonKey.includeIfNull]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonKey/includeIfNull.html -[JsonSerializable.nullable]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/nullable.html -[JsonKey.nullable]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonKey/nullable.html -[JsonKey.defaultValue]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonKey/defaultValue.html -[JsonKey.disallowNullValue]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonKey/disallowNullValue.html -[JsonKey.fromJson]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonKey/fromJson.html -[JsonKey.ignore]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonKey/ignore.html -[JsonKey.name]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonKey/name.html -[JsonKey.required]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonKey/required.html -[JsonKey.toJson]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonKey/toJson.html +[JsonSerializable.anyMap]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonSerializable/anyMap.html +[JsonSerializable.checked]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonSerializable/checked.html +[JsonSerializable.createFactory]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonSerializable/createFactory.html +[JsonSerializable.createToJson]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonSerializable/createToJson.html +[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html +[JsonSerializable.explicitToJson]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonSerializable/explicitToJson.html +[JsonSerializable.fieldRename]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonSerializable/fieldRename.html +[JsonSerializable.generateToJsonFunction]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonSerializable/generateToJsonFunction.html +[JsonSerializable.useWrappers]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonSerializable/useWrappers.html +[JsonSerializable.encodeEmptyCollection]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonSerializable/encodeEmptyCollection.html +[JsonKey.encodeEmptyCollection]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonKey/encodeEmptyCollection.html +[JsonSerializable.includeIfNull]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonSerializable/includeIfNull.html +[JsonKey.includeIfNull]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonKey/includeIfNull.html +[JsonSerializable.nullable]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonSerializable/nullable.html +[JsonKey.nullable]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonKey/nullable.html +[JsonKey.defaultValue]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonKey/defaultValue.html +[JsonKey.disallowNullValue]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonKey/disallowNullValue.html +[JsonKey.fromJson]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonKey/fromJson.html +[JsonKey.ignore]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonKey/ignore.html +[JsonKey.name]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonKey/name.html +[JsonKey.required]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonKey/required.html +[JsonKey.toJson]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonKey/toJson.html > Note: every `JsonSerializable` field is configurable via `build.yaml` – see the table for the corresponding key. diff --git a/json_serializable/doc/doc.md b/json_serializable/doc/doc.md index bc5de6710..f16114529 100644 --- a/json_serializable/doc/doc.md +++ b/json_serializable/doc/doc.md @@ -20,25 +20,25 @@ | | | [JsonKey.required] | | | | [JsonKey.toJson] | -[JsonSerializable.anyMap]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/anyMap.html -[JsonSerializable.checked]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/checked.html -[JsonSerializable.createFactory]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/createFactory.html -[JsonSerializable.createToJson]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/createToJson.html -[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html -[JsonSerializable.explicitToJson]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/explicitToJson.html -[JsonSerializable.fieldRename]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/fieldRename.html -[JsonSerializable.generateToJsonFunction]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/generateToJsonFunction.html -[JsonSerializable.useWrappers]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/useWrappers.html -[JsonSerializable.encodeEmptyCollection]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/encodeEmptyCollection.html -[JsonKey.encodeEmptyCollection]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonKey/encodeEmptyCollection.html -[JsonSerializable.includeIfNull]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/includeIfNull.html -[JsonKey.includeIfNull]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonKey/includeIfNull.html -[JsonSerializable.nullable]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonSerializable/nullable.html -[JsonKey.nullable]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonKey/nullable.html -[JsonKey.defaultValue]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonKey/defaultValue.html -[JsonKey.disallowNullValue]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonKey/disallowNullValue.html -[JsonKey.fromJson]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonKey/fromJson.html -[JsonKey.ignore]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonKey/ignore.html -[JsonKey.name]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonKey/name.html -[JsonKey.required]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonKey/required.html -[JsonKey.toJson]: https://pub.dev/documentation/json_annotation/2.2.0/json_annotation/JsonKey/toJson.html +[JsonSerializable.anyMap]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonSerializable/anyMap.html +[JsonSerializable.checked]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonSerializable/checked.html +[JsonSerializable.createFactory]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonSerializable/createFactory.html +[JsonSerializable.createToJson]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonSerializable/createToJson.html +[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html +[JsonSerializable.explicitToJson]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonSerializable/explicitToJson.html +[JsonSerializable.fieldRename]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonSerializable/fieldRename.html +[JsonSerializable.generateToJsonFunction]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonSerializable/generateToJsonFunction.html +[JsonSerializable.useWrappers]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonSerializable/useWrappers.html +[JsonSerializable.encodeEmptyCollection]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonSerializable/encodeEmptyCollection.html +[JsonKey.encodeEmptyCollection]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonKey/encodeEmptyCollection.html +[JsonSerializable.includeIfNull]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonSerializable/includeIfNull.html +[JsonKey.includeIfNull]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonKey/includeIfNull.html +[JsonSerializable.nullable]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonSerializable/nullable.html +[JsonKey.nullable]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonKey/nullable.html +[JsonKey.defaultValue]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonKey/defaultValue.html +[JsonKey.disallowNullValue]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonKey/disallowNullValue.html +[JsonKey.fromJson]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonKey/fromJson.html +[JsonKey.ignore]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonKey/ignore.html +[JsonKey.name]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonKey/name.html +[JsonKey.required]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonKey/required.html +[JsonKey.toJson]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonKey/toJson.html diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 582c407d1..aba615947 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 2.3.0-dev +version: 2.3.0 author: Dart Team description: >- Automatically generate code for converting to and from JSON by annotating @@ -31,7 +31,3 @@ dev_dependencies: source_gen_test: ^0.1.0 test: ^1.6.0 yaml: ^2.1.13 - -dependency_overrides: - json_annotation: - path: ../json_annotation From a2a8d69fe69645b9465652cb38b24fc66ce35ef2 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 10 Apr 2019 14:05:04 -0700 Subject: [PATCH 134/569] Removed `JsonSerializable.useWrappers` Fixes https://github.com/dart-lang/json_serializable/issues/441 --- json_annotation/CHANGELOG.md | 5 + json_annotation/lib/json_annotation.dart | 1 - .../lib/src/json_serializable.dart | 12 +- .../lib/src/json_serializable.g.dart | 6 +- json_annotation/lib/src/wrapper_helpers.dart | 76 --- json_annotation/pubspec.yaml | 2 +- json_serializable/CHANGELOG.md | 4 + json_serializable/README.md | 45 +- json_serializable/build.yaml | 7 +- json_serializable/doc/doc.md | 44 +- json_serializable/lib/src/encoder_helper.dart | 153 +----- .../lib/src/type_helpers/iterable_helper.dart | 8 - .../lib/src/type_helpers/map_helper.dart | 10 - json_serializable/lib/src/utils.dart | 2 - json_serializable/pubspec.yaml | 10 +- json_serializable/test/config_test.dart | 1 - .../test/custom_configuration_test.dart | 71 +-- .../generic_class.g_use_wrappers.dart | 111 ----- .../generic_class.g_use_wrappers.g.dart | 143 ------ ..._example.g_non_nullable__use_wrappers.dart | 160 ------- ...xample.g_non_nullable__use_wrappers.g.dart | 258 ---------- .../json_test_example.g_use_wrappers.dart | 156 ------ .../json_test_example.g_use_wrappers.g.dart | 282 ----------- .../test/json_serializable_test.dart | 8 - .../kitchen_sink/kitchen_sink.factories.dart | 15 +- ...g_any_map__non_nullable__use_wrappers.dart | 204 -------- ...any_map__non_nullable__use_wrappers.g.dart | 288 ------------ ..._null__no_encode_empty__non_nullable.dart} | 8 +- ...null__no_encode_empty__non_nullable.g.dart | 233 +++++++++ ...e_empty__non_nullable__use_wrappers.g.dart | 374 --------------- ...e_null__no_encode_empty__use_wrappers.dart | 206 -------- ...null__no_encode_empty__use_wrappers.g.dart | 444 ------------------ ...hen_sink.g_exclude_null__use_wrappers.dart | 203 -------- ...n_sink.g_exclude_null__use_wrappers.g.dart | 433 ----------------- json_serializable/test/shared_config.dart | 1 - .../test/src/generic_test_input.dart | 50 -- .../test/src/inheritance_test_input.dart | 46 -- .../test/src/to_from_json_test_input.dart | 75 --- .../test/src/unknown_type_test_input.dart | 33 -- .../test/test_sources/test_sources.dart | 1 - json_serializable/tool/test_builder.dart | 14 +- 41 files changed, 314 insertions(+), 3889 deletions(-) delete mode 100644 json_annotation/lib/src/wrapper_helpers.dart delete mode 100644 json_serializable/test/generic_files/generic_class.g_use_wrappers.dart delete mode 100644 json_serializable/test/generic_files/generic_class.g_use_wrappers.g.dart delete mode 100644 json_serializable/test/integration/json_test_example.g_non_nullable__use_wrappers.dart delete mode 100644 json_serializable/test/integration/json_test_example.g_non_nullable__use_wrappers.g.dart delete mode 100644 json_serializable/test/integration/json_test_example.g_use_wrappers.dart delete mode 100644 json_serializable/test/integration/json_test_example.g_use_wrappers.g.dart delete mode 100644 json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable__use_wrappers.dart delete mode 100644 json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable__use_wrappers.g.dart rename json_serializable/test/kitchen_sink/{kitchen_sink.g_exclude_null__no_encode_empty__non_nullable__use_wrappers.dart => kitchen_sink.g_exclude_null__no_encode_empty__non_nullable.dart} (97%) create mode 100644 json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty__non_nullable.g.dart delete mode 100644 json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty__non_nullable__use_wrappers.g.dart delete mode 100644 json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty__use_wrappers.dart delete mode 100644 json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty__use_wrappers.g.dart delete mode 100644 json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__use_wrappers.dart delete mode 100644 json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__use_wrappers.g.dart diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index fd138bfaa..ce94329f3 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -1,3 +1,8 @@ +## 3.0.0 + +- **BREAKING** Removed `JsonSerializable.useWrappers` and associated + `$`-prefixed helpers. + ## 2.3.0 - Added `pascal` as an additional `fieldRename` option. diff --git a/json_annotation/lib/json_annotation.dart b/json_annotation/lib/json_annotation.dart index b9050657a..9d1c39706 100644 --- a/json_annotation/lib/json_annotation.dart +++ b/json_annotation/lib/json_annotation.dart @@ -17,4 +17,3 @@ export 'src/json_key.dart'; export 'src/json_literal.dart'; export 'src/json_serializable.dart'; export 'src/json_value.dart'; -export 'src/wrapper_helpers.dart'; diff --git a/json_annotation/lib/src/json_serializable.dart b/json_annotation/lib/src/json_serializable.dart index d174f3816..52e6630c9 100644 --- a/json_annotation/lib/src/json_serializable.dart +++ b/json_annotation/lib/src/json_serializable.dart @@ -190,13 +190,6 @@ class JsonSerializable { /// `null` runtime validation if it's critical. final bool nullable; - /// If `true`, wrappers are used to minimize the number of - /// [Map] and [List] instances created during serialization. - /// - /// This will increase the code size, but it may improve runtime performance, - /// especially for large object graphs. - final bool useWrappers; - /// Creates a new [JsonSerializable] instance. const JsonSerializable({ this.anyMap, @@ -210,7 +203,6 @@ class JsonSerializable { this.generateToJsonFunction, this.includeIfNull, this.nullable, - this.useWrappers, }); factory JsonSerializable.fromJson(Map json) => @@ -230,7 +222,6 @@ class JsonSerializable { generateToJsonFunction: true, includeIfNull: true, nullable: true, - useWrappers: false, ); /// Returns a new [JsonSerializable] instance with fields equal to the @@ -252,8 +243,7 @@ class JsonSerializable { generateToJsonFunction: generateToJsonFunction ?? defaults.generateToJsonFunction, includeIfNull: includeIfNull ?? defaults.includeIfNull, - nullable: nullable ?? defaults.nullable, - useWrappers: useWrappers ?? defaults.useWrappers); + nullable: nullable ?? defaults.nullable); Map toJson() => _$JsonSerializableToJson(this); } diff --git a/json_annotation/lib/src/json_serializable.g.dart b/json_annotation/lib/src/json_serializable.g.dart index 2e9ef9a41..5cf57e2e0 100644 --- a/json_annotation/lib/src/json_serializable.g.dart +++ b/json_annotation/lib/src/json_serializable.g.dart @@ -20,7 +20,6 @@ JsonSerializable _$JsonSerializableFromJson(Map json) { 'generate_to_json_function', 'include_if_null', 'nullable', - 'use_wrappers' ]); final val = JsonSerializable( anyMap: $checkedConvert(json, 'any_map', (v) => v as bool), @@ -40,8 +39,7 @@ JsonSerializable _$JsonSerializableFromJson(Map json) { json, 'generate_to_json_function', (v) => v as bool), includeIfNull: $checkedConvert(json, 'include_if_null', (v) => v as bool), - nullable: $checkedConvert(json, 'nullable', (v) => v as bool), - useWrappers: $checkedConvert(json, 'use_wrappers', (v) => v as bool)); + nullable: $checkedConvert(json, 'nullable', (v) => v as bool)); return val; }, fieldKeyMap: const { 'anyMap': 'any_map', @@ -53,7 +51,6 @@ JsonSerializable _$JsonSerializableFromJson(Map json) { 'fieldRename': 'field_rename', 'generateToJsonFunction': 'generate_to_json_function', 'includeIfNull': 'include_if_null', - 'useWrappers': 'use_wrappers' }); } @@ -70,7 +67,6 @@ Map _$JsonSerializableToJson(JsonSerializable instance) => 'generate_to_json_function': instance.generateToJsonFunction, 'include_if_null': instance.includeIfNull, 'nullable': instance.nullable, - 'use_wrappers': instance.useWrappers }; T _$enumDecode(Map enumValues, dynamic source) { diff --git a/json_annotation/lib/src/wrapper_helpers.dart b/json_annotation/lib/src/wrapper_helpers.dart deleted file mode 100644 index 73b019167..000000000 --- a/json_annotation/lib/src/wrapper_helpers.dart +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright (c) 2018, 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 'dart:collection'; - -/// Helper class used in generated code when -/// `JsonSerializableGenerator.useWrappers` is `true`. -/// -/// Should not be used directly. -abstract class $JsonMapWrapper extends UnmodifiableMapBase {} - -/// Helper function used in generated code when -/// `JsonSerializableGenerator.useWrappers` is `true`. -/// -/// Should not be used directly. -Map $wrapMap( - Map source, dynamic converter(V key)) => - _MappingMap(source, converter); - -/// Helper function used in generated code when -/// `JsonSerializableGenerator.useWrappers` is `true`. -/// -/// Should not be used directly. -Map $wrapMapHandleNull( - Map source, dynamic converter(V key)) => - source == null ? null : _MappingMap(source, converter); - -/// Helper function used in generated code when -/// `JsonSerializableGenerator.useWrappers` is `true`. -/// -/// Should not be used directly. -List $wrapList(List source, dynamic converter(T key)) => - _MappingList(source, converter); - -/// Helper function used in generated code when -/// `JsonSerializableGenerator.useWrappers` is `true`. -/// -/// Should not be used directly. -List $wrapListHandleNull( - List source, dynamic converter(T key)) => - source == null ? null : _MappingList(source, converter); - -typedef _Convert = dynamic Function(S value); - -class _MappingList extends ListBase { - final List _source; - final _Convert _converter; - - _MappingList(this._source, this._converter); - - @override - dynamic operator [](int index) => _converter(_source[index]); - - @override - operator []=(int index, dynamic value) => throw UnsupportedError(''); - - @override - int get length => _source.length; - - @override - set length(int value) => throw UnsupportedError(''); -} - -class _MappingMap extends UnmodifiableMapBase { - final Map _source; - final _Convert _converter; - - _MappingMap(this._source, this._converter); - - @override - Iterable get keys => _source.keys.map((k) => k as String); - - @override - dynamic operator [](Object key) => _converter(_source[key]); -} diff --git a/json_annotation/pubspec.yaml b/json_annotation/pubspec.yaml index 170e052e4..13b79e3c0 100644 --- a/json_annotation/pubspec.yaml +++ b/json_annotation/pubspec.yaml @@ -1,5 +1,5 @@ name: json_annotation -version: 2.3.0 +version: 3.0.0-dev description: >- Classes and helper functions that support JSON code generation via the `json_serializable` package. diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 8935aadae..c841fe221 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,7 @@ +## 3.0.0 + +- **BREAKING** Removed support for `JsonSerializable.useWrappers`. + ## 2.3.0 - Added `pascal` as an additional `fieldRename` option. diff --git a/json_serializable/README.md b/json_serializable/README.md index 23abd24e0..649368382 100644 --- a/json_serializable/README.md +++ b/json_serializable/README.md @@ -79,7 +79,6 @@ is generated: | explicit_to_json | [JsonSerializable.explicitToJson] | | | field_rename | [JsonSerializable.fieldRename] | | | generate_to_json_function | [JsonSerializable.generateToJsonFunction] | | -| use_wrappers | [JsonSerializable.useWrappers] | | | encode_empty_collection | [JsonSerializable.encodeEmptyCollection] | [JsonKey.encodeEmptyCollection] | | include_if_null | [JsonSerializable.includeIfNull] | [JsonKey.includeIfNull] | | nullable | [JsonSerializable.nullable] | [JsonKey.nullable] | @@ -91,28 +90,27 @@ is generated: | | | [JsonKey.required] | | | | [JsonKey.toJson] | -[JsonSerializable.anyMap]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonSerializable/anyMap.html -[JsonSerializable.checked]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonSerializable/checked.html -[JsonSerializable.createFactory]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonSerializable/createFactory.html -[JsonSerializable.createToJson]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonSerializable/createToJson.html -[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html -[JsonSerializable.explicitToJson]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonSerializable/explicitToJson.html -[JsonSerializable.fieldRename]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonSerializable/fieldRename.html -[JsonSerializable.generateToJsonFunction]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonSerializable/generateToJsonFunction.html -[JsonSerializable.useWrappers]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonSerializable/useWrappers.html -[JsonSerializable.encodeEmptyCollection]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonSerializable/encodeEmptyCollection.html -[JsonKey.encodeEmptyCollection]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonKey/encodeEmptyCollection.html -[JsonSerializable.includeIfNull]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonSerializable/includeIfNull.html -[JsonKey.includeIfNull]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonKey/includeIfNull.html -[JsonSerializable.nullable]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonSerializable/nullable.html -[JsonKey.nullable]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonKey/nullable.html -[JsonKey.defaultValue]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonKey/defaultValue.html -[JsonKey.disallowNullValue]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonKey/disallowNullValue.html -[JsonKey.fromJson]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonKey/fromJson.html -[JsonKey.ignore]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonKey/ignore.html -[JsonKey.name]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonKey/name.html -[JsonKey.required]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonKey/required.html -[JsonKey.toJson]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonKey/toJson.html +[JsonSerializable.anyMap]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/anyMap.html +[JsonSerializable.checked]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/checked.html +[JsonSerializable.createFactory]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/createFactory.html +[JsonSerializable.createToJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/createToJson.html +[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html +[JsonSerializable.explicitToJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/explicitToJson.html +[JsonSerializable.fieldRename]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/fieldRename.html +[JsonSerializable.generateToJsonFunction]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/generateToJsonFunction.html +[JsonSerializable.encodeEmptyCollection]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/encodeEmptyCollection.html +[JsonKey.encodeEmptyCollection]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/encodeEmptyCollection.html +[JsonSerializable.includeIfNull]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/includeIfNull.html +[JsonKey.includeIfNull]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/includeIfNull.html +[JsonSerializable.nullable]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/nullable.html +[JsonKey.nullable]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/nullable.html +[JsonKey.defaultValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/defaultValue.html +[JsonKey.disallowNullValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/disallowNullValue.html +[JsonKey.fromJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/fromJson.html +[JsonKey.ignore]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/ignore.html +[JsonKey.name]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/name.html +[JsonKey.required]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/required.html +[JsonKey.toJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/toJson.html > Note: every `JsonSerializable` field is configurable via `build.yaml` – see the table for the corresponding key. @@ -151,7 +149,6 @@ targets: generate_to_json_function: true include_if_null: true nullable: true - use_wrappers: false ``` [example]: https://github.com/dart-lang/json_serializable/blob/master/example diff --git a/json_serializable/build.yaml b/json_serializable/build.yaml index 3551bc949..0e367f3b1 100644 --- a/json_serializable/build.yaml +++ b/json_serializable/build.yaml @@ -38,19 +38,14 @@ builders: - .g_any_map__checked.dart - .g_any_map__checked__non_nullable.dart - .g_any_map__non_nullable.dart - - .g_any_map__non_nullable__use_wrappers.dart - .g_exclude_null.dart - .g_exclude_null__no_encode_empty.dart - - .g_exclude_null__no_encode_empty__non_nullable__use_wrappers.dart - - .g_exclude_null__no_encode_empty__use_wrappers.dart + - .g_exclude_null__no_encode_empty__non_nullable.dart - .g_exclude_null__non_nullable.dart - - .g_exclude_null__use_wrappers.dart - .g_explicit_to_json.dart - .g_no_encode_empty.dart - .g_no_encode_empty__non_nullable.dart - .g_non_nullable.dart - - .g_non_nullable__use_wrappers.dart - - .g_use_wrappers.dart build_to: source runs_before: ["json_serializable"] diff --git a/json_serializable/doc/doc.md b/json_serializable/doc/doc.md index f16114529..b8bd2a6ce 100644 --- a/json_serializable/doc/doc.md +++ b/json_serializable/doc/doc.md @@ -8,7 +8,6 @@ | explicit_to_json | [JsonSerializable.explicitToJson] | | | field_rename | [JsonSerializable.fieldRename] | | | generate_to_json_function | [JsonSerializable.generateToJsonFunction] | | -| use_wrappers | [JsonSerializable.useWrappers] | | | encode_empty_collection | [JsonSerializable.encodeEmptyCollection] | [JsonKey.encodeEmptyCollection] | | include_if_null | [JsonSerializable.includeIfNull] | [JsonKey.includeIfNull] | | nullable | [JsonSerializable.nullable] | [JsonKey.nullable] | @@ -20,25 +19,24 @@ | | | [JsonKey.required] | | | | [JsonKey.toJson] | -[JsonSerializable.anyMap]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonSerializable/anyMap.html -[JsonSerializable.checked]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonSerializable/checked.html -[JsonSerializable.createFactory]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonSerializable/createFactory.html -[JsonSerializable.createToJson]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonSerializable/createToJson.html -[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html -[JsonSerializable.explicitToJson]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonSerializable/explicitToJson.html -[JsonSerializable.fieldRename]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonSerializable/fieldRename.html -[JsonSerializable.generateToJsonFunction]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonSerializable/generateToJsonFunction.html -[JsonSerializable.useWrappers]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonSerializable/useWrappers.html -[JsonSerializable.encodeEmptyCollection]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonSerializable/encodeEmptyCollection.html -[JsonKey.encodeEmptyCollection]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonKey/encodeEmptyCollection.html -[JsonSerializable.includeIfNull]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonSerializable/includeIfNull.html -[JsonKey.includeIfNull]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonKey/includeIfNull.html -[JsonSerializable.nullable]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonSerializable/nullable.html -[JsonKey.nullable]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonKey/nullable.html -[JsonKey.defaultValue]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonKey/defaultValue.html -[JsonKey.disallowNullValue]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonKey/disallowNullValue.html -[JsonKey.fromJson]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonKey/fromJson.html -[JsonKey.ignore]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonKey/ignore.html -[JsonKey.name]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonKey/name.html -[JsonKey.required]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonKey/required.html -[JsonKey.toJson]: https://pub.dev/documentation/json_annotation/2.3.0/json_annotation/JsonKey/toJson.html +[JsonSerializable.anyMap]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/anyMap.html +[JsonSerializable.checked]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/checked.html +[JsonSerializable.createFactory]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/createFactory.html +[JsonSerializable.createToJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/createToJson.html +[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html +[JsonSerializable.explicitToJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/explicitToJson.html +[JsonSerializable.fieldRename]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/fieldRename.html +[JsonSerializable.generateToJsonFunction]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/generateToJsonFunction.html +[JsonSerializable.encodeEmptyCollection]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/encodeEmptyCollection.html +[JsonKey.encodeEmptyCollection]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/encodeEmptyCollection.html +[JsonSerializable.includeIfNull]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/includeIfNull.html +[JsonKey.includeIfNull]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/includeIfNull.html +[JsonSerializable.nullable]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/nullable.html +[JsonKey.nullable]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/nullable.html +[JsonKey.defaultValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/defaultValue.html +[JsonKey.disallowNullValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/disallowNullValue.html +[JsonKey.fromJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/fromJson.html +[JsonKey.ignore]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/ignore.html +[JsonKey.name]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/name.html +[JsonKey.required]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/required.html +[JsonKey.toJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/toJson.html diff --git a/json_serializable/lib/src/encoder_helper.dart b/json_serializable/lib/src/encoder_helper.dart index 60961fe4b..33b9ebddf 100644 --- a/json_serializable/lib/src/encoder_helper.dart +++ b/json_serializable/lib/src/encoder_helper.dart @@ -8,7 +8,6 @@ import 'package:json_annotation/json_annotation.dart'; import 'constants.dart'; import 'helper_core.dart'; import 'type_helper.dart'; -import 'type_helpers/convert_helper.dart'; import 'type_helpers/json_converter_helper.dart'; abstract class EncodeHelper implements HelperCore { @@ -23,9 +22,6 @@ abstract class EncodeHelper implements HelperCore { String _mixinClassName(bool withConstraints) => '${prefix}SerializerMixin${genericClassArgumentsImpl(withConstraints)}'; - String _wrapperClassName([bool withConstraints]) => - '${prefix}JsonMapWrapper${genericClassArgumentsImpl(withConstraints)}'; - Iterable createToJson(Set accessibleFields) sync* { assert(config.createToJson); @@ -53,17 +49,12 @@ abstract class EncodeHelper implements HelperCore { final writeNaive = accessibleFields.every(_writeJsonValueNaive); - if (config.useWrappers) { - final param = config.generateToJsonFunction ? _toJsonParamName : 'this'; - buffer.writeln('=> ${_wrapperClassName(false)}($param);'); + if (writeNaive) { + // write simple `toJson` method that includes all keys... + _writeToJsonSimple(buffer, accessibleFields); } else { - if (writeNaive) { - // write simple `toJson` method that includes all keys... - _writeToJsonSimple(buffer, accessibleFields); - } else { - // At least one field should be excluded if null - _writeToJsonWithNullChecks(buffer, accessibleFields); - } + // At least one field should be excluded if null + _writeToJsonWithNullChecks(buffer, accessibleFields); } if (!config.generateToJsonFunction) { @@ -72,91 +63,6 @@ abstract class EncodeHelper implements HelperCore { } yield buffer.toString(); - - if (config.useWrappers) { - yield _createWrapperClass(accessibleFields); - } - } - - String _createWrapperClass(Iterable fields) { - final buffer = StringBuffer(); - buffer.writeln(); - // TODO(kevmoo): write JsonMapWrapper if annotation lib is prefix-imported - - final fieldType = config.generateToJsonFunction - ? targetClassReference - : _mixinClassName(false); - - buffer.writeln(''' -class ${_wrapperClassName(true)} extends \$JsonMapWrapper { - final $fieldType _v; - ${_wrapperClassName()}(this._v); -'''); - - if (fields.every(_writeJsonValueNaive)) { - // TODO(kevmoo): consider just doing one code path – if it's fast - // enough - final jsonKeys = fields.map(safeNameAccess).join(', '); - - // TODO(kevmoo): maybe put this in a static field instead? - // const lists have unfortunate overhead - buffer.writeln(''' - @override - Iterable get keys => const [$jsonKeys]; -'''); - } else { - // At least one field should be excluded if null - buffer.writeln(' @override\n Iterable get keys sync* {'); - - for (final field in fields) { - String check; - - if (!_writeJsonValueNaive(field)) { - final expression = _wrapCustomEncoder('_v.${field.name}', field); - check = '$expression != null'; - - if (!jsonKeyFor(field).encodeEmptyCollection) { - assert(!jsonKeyFor(field).includeIfNull); - if (jsonKeyFor(field).nullable) { - check = '_v.${field.name}?.isNotEmpty ?? false'; - } else { - check = '_v.${field.name}.isNotEmpty'; - } - } - } - if (check != null) { - buffer.writeln(' if ($check) {\n '); - } - buffer.writeln(' yield ${safeNameAccess(field)};'); - if (check != null) { - buffer.writeln(' }'); - } - } - - buffer.writeln(' }\n'); - } - - buffer.writeln(''' - @override - dynamic operator [](Object key) { - if (key is String) { - switch (key) {'''); - - for (final field in fields) { - final valueAccess = '_v.${field.name}'; - buffer.writeln(''' - case ${safeNameAccess(field)}: - return ${_serializeField(field, valueAccess)};'''); - } - - buffer.writeln(''' - } - } - return null; - }'''); - - buffer.writeln('}'); - return buffer.toString(); } void _writeToJsonSimple(StringBuffer buffer, Iterable fields) { @@ -286,53 +192,4 @@ class ${_wrapperClassName(true)} extends \$JsonMapWrapper { } return false; } - - /// If [field] has a user-defined encoder, return [expression] wrapped in - /// the corresponding conversion logic so we can do a correct `null` check. - /// - /// This can be either a `toJson` function in [JsonKey] or a [JsonConverter] - /// annotation. - /// - /// If there is no user-defined encoder, just return [expression] as-is. - String _wrapCustomEncoder(String expression, FieldElement field) { - final helperContext = getHelperContext(field); - - final convertData = helperContext.serializeConvertData; - - var result = expression; - if (convertData != null) { - result = toJsonSerializeImpl( - getHelperContext(field).serializeConvertData.name, - expression, - jsonKeyFor(field).nullable, - ); - } else { - final output = const JsonConverterHelper() - .serialize(field.type, expression, helperContext); - - if (output != null) { - result = output.toString(); - } - } - - assert( - (result != expression) == _fieldHasCustomEncoder(field), - 'If the output expression is different, then it should map to a field ' - 'with a custom encoder', - ); - - if (result == expression) { - // No conversion - return expression; - } - - if (jsonKeyFor(field).nullable) { - // If there was a conversion and the field is nullable, wrap the output - // in () – there will be null checks that will break the comparison - // in the caller - result = '($result)'; - } - - return result; - } } diff --git a/json_serializable/lib/src/type_helpers/iterable_helper.dart b/json_serializable/lib/src/type_helpers/iterable_helper.dart index da2d5b9ce..e47ef6e4e 100644 --- a/json_serializable/lib/src/type_helpers/iterable_helper.dart +++ b/json_serializable/lib/src/type_helpers/iterable_helper.dart @@ -47,14 +47,6 @@ class IterableHelper extends TypeHelper { // If they are not equal, then we to write out the substitution. if (subField != closureArg) { final lambda = LambdaResult.process(subField, closureArg); - if (context.config.useWrappers && isList) { - var method = '\$wrapList'; - if (contextNullable) { - method = '${method}HandleNull'; - } - - return '$method<$itemType>($expression, $lambda)'; - } expression = '$expression$optionalQuestion.map($lambda)'; diff --git a/json_serializable/lib/src/type_helpers/map_helper.dart b/json_serializable/lib/src/type_helpers/map_helper.dart index 44a889c7a..7ab946948 100644 --- a/json_serializable/lib/src/type_helpers/map_helper.dart +++ b/json_serializable/lib/src/type_helpers/map_helper.dart @@ -47,16 +47,6 @@ class MapHelper extends TypeHelper { return expression; } - if (context.config.useWrappers) { - var method = '\$wrapMap'; - if (contextNullable) { - method = '${method}HandleNull'; - } - - final lambda = LambdaResult.process(subFieldValue, closureArg); - return '$method<$keyType, $valueType>($expression, $lambda)'; - } - final optionalQuestion = contextNullable ? '?' : ''; return '$expression$optionalQuestion' diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index 6adc6a5ed..cbcde6f32 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -85,7 +85,6 @@ JsonSerializable _valueForAnnotation(ConstantReader reader) => JsonSerializable( reader.read('generateToJsonFunction').literalValue as bool, includeIfNull: reader.read('includeIfNull').literalValue as bool, nullable: reader.read('nullable').literalValue as bool, - useWrappers: reader.read('useWrappers').literalValue as bool, ); /// Returns a [JsonSerializable] with values from the [JsonSerializable] instance @@ -111,7 +110,6 @@ JsonSerializable mergeConfig(JsonSerializable config, ConstantReader reader) { annotation.generateToJsonFunction ?? config.generateToJsonFunction, includeIfNull: annotation.includeIfNull ?? config.includeIfNull, nullable: annotation.nullable ?? config.nullable, - useWrappers: annotation.useWrappers ?? config.useWrappers, ); } diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index aba615947..373dd2b06 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 2.3.0 +version: 3.0.0-dev author: Dart Team description: >- Automatically generate code for converting to and from JSON by annotating @@ -15,7 +15,9 @@ dependencies: # Use a tight version constraint to ensure that a constraint on # `json_annotation` properly constrains all features it provides. - json_annotation: '>=2.3.0 <2.4.0' + # For v3 only – allow a wide range since the only change was to REMOVE things + # from json_annotation + json_annotation: '>=2.3.0 <3.0.0' meta: ^1.1.0 path: ^1.3.2 source_gen: ^0.9.0 @@ -31,3 +33,7 @@ dev_dependencies: source_gen_test: ^0.1.0 test: ^1.6.0 yaml: ^2.1.13 + +dependency_overrides: + json_annotation: + path: ../json_annotation diff --git a/json_serializable/test/config_test.dart b/json_serializable/test/config_test.dart index 3eae88d26..a4249accd 100644 --- a/json_serializable/test/config_test.dart +++ b/json_serializable/test/config_test.dart @@ -141,5 +141,4 @@ const _invalidConfig = { 'generate_to_json_function': 42, 'include_if_null': 42, 'nullable': 42, - 'use_wrappers': 42, }; diff --git a/json_serializable/test/custom_configuration_test.dart b/json_serializable/test/custom_configuration_test.dart index 50b094eea..07c4dc27d 100644 --- a/json_serializable/test/custom_configuration_test.dart +++ b/json_serializable/test/custom_configuration_test.dart @@ -29,10 +29,6 @@ void main() async { group('without wrappers', () { _registerTests(JsonSerializable.defaults); }); - group( - 'with wrapper', - () => _registerTests( - const JsonSerializable(useWrappers: true).withDefaults())); group('configuration', () { Future runWithConfigAndLogger( @@ -125,37 +121,9 @@ void _registerTests(JsonSerializable generator) { group('explicit toJson', () { test('nullable', () async { final output = await _runForElementNamed( - JsonSerializable(useWrappers: generator.useWrappers), - 'TrivialNestedNullable'); + const JsonSerializable(), 'TrivialNestedNullable'); - final expected = generator.useWrappers - ? r''' -Map _$TrivialNestedNullableToJson( - TrivialNestedNullable instance) => - _$TrivialNestedNullableJsonMapWrapper(instance); - -class _$TrivialNestedNullableJsonMapWrapper extends $JsonMapWrapper { - final TrivialNestedNullable _v; - _$TrivialNestedNullableJsonMapWrapper(this._v); - - @override - Iterable get keys => const ['child', 'otherField']; - - @override - dynamic operator [](Object key) { - if (key is String) { - switch (key) { - case 'child': - return _v.child?.toJson(); - case 'otherField': - return _v.otherField; - } - } - return null; - } -} -''' - : r''' + final expected = r''' Map _$TrivialNestedNullableToJson( TrivialNestedNullable instance) => { @@ -168,37 +136,9 @@ Map _$TrivialNestedNullableToJson( }); test('non-nullable', () async { final output = await _runForElementNamed( - JsonSerializable(useWrappers: generator.useWrappers), - 'TrivialNestedNonNullable'); + const JsonSerializable(), 'TrivialNestedNonNullable'); - final expected = generator.useWrappers - ? r''' -Map _$TrivialNestedNonNullableToJson( - TrivialNestedNonNullable instance) => - _$TrivialNestedNonNullableJsonMapWrapper(instance); - -class _$TrivialNestedNonNullableJsonMapWrapper extends $JsonMapWrapper { - final TrivialNestedNonNullable _v; - _$TrivialNestedNonNullableJsonMapWrapper(this._v); - - @override - Iterable get keys => const ['child', 'otherField']; - - @override - dynamic operator [](Object key) { - if (key is String) { - switch (key) { - case 'child': - return _v.child.toJson(); - case 'otherField': - return _v.otherField; - } - } - return null; - } -} -''' - : r''' + final expected = r''' Map _$TrivialNestedNonNullableToJson( TrivialNestedNonNullable instance) => { @@ -230,8 +170,7 @@ Map _$TrivialNestedNonNullableToJson( test('class with child json-able object - anyMap', () async { final output = await _runForElementNamed( - JsonSerializable(anyMap: true, useWrappers: generator.useWrappers), - 'ParentObject'); + const JsonSerializable(anyMap: true), 'ParentObject'); expect(output, contains("ChildObject.fromJson(json['child'] as Map)")); }); diff --git a/json_serializable/test/generic_files/generic_class.g_use_wrappers.dart b/json_serializable/test/generic_files/generic_class.g_use_wrappers.dart deleted file mode 100644 index bc0a04374..000000000 --- a/json_serializable/test/generic_files/generic_class.g_use_wrappers.dart +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright (c) 2018, 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:json_annotation/json_annotation.dart'; - -part 'generic_class.g_use_wrappers.g.dart'; - -@JsonSerializable( - useWrappers: true, -) -class GenericClass { - @JsonKey(fromJson: _dataFromJson, toJson: _dataToJson) - Object fieldObject; - - @JsonKey(fromJson: _dataFromJson, toJson: _dataToJson) - dynamic fieldDynamic; - - @JsonKey(fromJson: _dataFromJson, toJson: _dataToJson) - int fieldInt; - - @JsonKey(fromJson: _dataFromJson, toJson: _dataToJson) - T fieldT; - - @JsonKey(fromJson: _dataFromJson, toJson: _dataToJson) - S fieldS; - - GenericClass(); - - factory GenericClass.fromJson(Map json) => - _$GenericClassFromJson(json); - - Map toJson() => _$GenericClassToJson(this); - - static T _dataFromJson(Map input, - [S other1, U other2]) => - input['value'] as T; - - static Map _dataToJson(T input, - [S other1, U other2]) => - {'value': input}; -} - -@JsonSerializable( - useWrappers: true, -) -@_DurationMillisecondConverter() -@_DurationListMillisecondConverter() -class GenericClassWithConverter { - @_SimpleConverter() - Object fieldObject; - - @_SimpleConverter() - dynamic fieldDynamic; - - @_SimpleConverter() - int fieldInt; - - @_SimpleConverter() - T fieldT; - - @_SimpleConverter() - S fieldS; - - Duration duration; - - List listDuration; - - GenericClassWithConverter(); - - factory GenericClassWithConverter.fromJson(Map json) => - _$GenericClassWithConverterFromJson(json); - - Map toJson() => _$GenericClassWithConverterToJson(this); -} - -class _SimpleConverter implements JsonConverter> { - const _SimpleConverter(); - - @override - T fromJson(Map json) => json['value'] as T; - - @override - Map toJson(T object) => {'value': object}; -} - -class _DurationMillisecondConverter implements JsonConverter { - const _DurationMillisecondConverter(); - - const _DurationMillisecondConverter.named(); - - @override - Duration fromJson(int json) => - json == null ? null : Duration(milliseconds: json); - - @override - int toJson(Duration object) => object?.inMilliseconds; -} - -class _DurationListMillisecondConverter - implements JsonConverter, int> { - const _DurationListMillisecondConverter(); - - @override - List fromJson(int json) => [Duration(milliseconds: json)]; - - @override - int toJson(List object) => object?.fold(0, (sum, obj) { - return sum + obj.inMilliseconds; - }); -} diff --git a/json_serializable/test/generic_files/generic_class.g_use_wrappers.g.dart b/json_serializable/test/generic_files/generic_class.g_use_wrappers.g.dart deleted file mode 100644 index 7f2b144b2..000000000 --- a/json_serializable/test/generic_files/generic_class.g_use_wrappers.g.dart +++ /dev/null @@ -1,143 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'generic_class.g_use_wrappers.dart'; - -// ************************************************************************** -// JsonSerializableGenerator -// ************************************************************************** - -GenericClass _$GenericClassFromJson( - Map json) { - return GenericClass() - ..fieldObject = json['fieldObject'] == null - ? null - : GenericClass._dataFromJson( - json['fieldObject'] as Map) - ..fieldDynamic = json['fieldDynamic'] == null - ? null - : GenericClass._dataFromJson( - json['fieldDynamic'] as Map) - ..fieldInt = json['fieldInt'] == null - ? null - : GenericClass._dataFromJson(json['fieldInt'] as Map) - ..fieldT = json['fieldT'] == null - ? null - : GenericClass._dataFromJson(json['fieldT'] as Map) - ..fieldS = json['fieldS'] == null - ? null - : GenericClass._dataFromJson(json['fieldS'] as Map); -} - -Map _$GenericClassToJson( - GenericClass instance) => - _$GenericClassJsonMapWrapper(instance); - -class _$GenericClassJsonMapWrapper extends $JsonMapWrapper { - final GenericClass _v; - _$GenericClassJsonMapWrapper(this._v); - - @override - Iterable get keys => - const ['fieldObject', 'fieldDynamic', 'fieldInt', 'fieldT', 'fieldS']; - - @override - dynamic operator [](Object key) { - if (key is String) { - switch (key) { - case 'fieldObject': - return _v.fieldObject == null - ? null - : GenericClass._dataToJson(_v.fieldObject); - case 'fieldDynamic': - return _v.fieldDynamic == null - ? null - : GenericClass._dataToJson(_v.fieldDynamic); - case 'fieldInt': - return _v.fieldInt == null - ? null - : GenericClass._dataToJson(_v.fieldInt); - case 'fieldT': - return _v.fieldT == null ? null : GenericClass._dataToJson(_v.fieldT); - case 'fieldS': - return _v.fieldS == null ? null : GenericClass._dataToJson(_v.fieldS); - } - } - return null; - } -} - -GenericClassWithConverter - _$GenericClassWithConverterFromJson( - Map json) { - return GenericClassWithConverter() - ..fieldObject = json['fieldObject'] - ..fieldDynamic = json['fieldDynamic'] - ..fieldInt = json['fieldInt'] as int - ..fieldT = json['fieldT'] == null - ? null - : _SimpleConverter().fromJson(json['fieldT'] as Map) - ..fieldS = json['fieldS'] == null - ? null - : _SimpleConverter().fromJson(json['fieldS'] as Map) - ..duration = json['duration'] == null - ? null - : const _DurationMillisecondConverter() - .fromJson(json['duration'] as int) - ..listDuration = json['listDuration'] == null - ? null - : const _DurationListMillisecondConverter() - .fromJson(json['listDuration'] as int); -} - -Map _$GenericClassWithConverterToJson( - GenericClassWithConverter instance) => - _$GenericClassWithConverterJsonMapWrapper(instance); - -class _$GenericClassWithConverterJsonMapWrapper - extends $JsonMapWrapper { - final GenericClassWithConverter _v; - _$GenericClassWithConverterJsonMapWrapper(this._v); - - @override - Iterable get keys => const [ - 'fieldObject', - 'fieldDynamic', - 'fieldInt', - 'fieldT', - 'fieldS', - 'duration', - 'listDuration' - ]; - - @override - dynamic operator [](Object key) { - if (key is String) { - switch (key) { - case 'fieldObject': - return _v.fieldObject; - case 'fieldDynamic': - return _v.fieldDynamic; - case 'fieldInt': - return _v.fieldInt; - case 'fieldT': - return _v.fieldT == null - ? null - : _SimpleConverter().toJson(_v.fieldT); - case 'fieldS': - return _v.fieldS == null - ? null - : _SimpleConverter().toJson(_v.fieldS); - case 'duration': - return _v.duration == null - ? null - : const _DurationMillisecondConverter().toJson(_v.duration); - case 'listDuration': - return _v.listDuration == null - ? null - : const _DurationListMillisecondConverter() - .toJson(_v.listDuration); - } - } - return null; - } -} diff --git a/json_serializable/test/integration/json_test_example.g_non_nullable__use_wrappers.dart b/json_serializable/test/integration/json_test_example.g_non_nullable__use_wrappers.dart deleted file mode 100644 index c680e6fb0..000000000 --- a/json_serializable/test/integration/json_test_example.g_non_nullable__use_wrappers.dart +++ /dev/null @@ -1,160 +0,0 @@ -// Copyright (c) 2018, 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. - -// ignore_for_file: hash_and_equals -import 'dart:collection'; - -import 'package:json_annotation/json_annotation.dart'; -import 'json_test_common.dart'; - -part 'json_test_example.g_non_nullable__use_wrappers.g.dart'; - -@JsonSerializable( - useWrappers: true, - nullable: false, -) -class Person { - final String firstName, middleName, lastName; - final DateTime dateOfBirth; - @JsonKey(name: '\$house') - final Category house; - - Order order; - - MyList customOrders; - - Map houseMap; - Map categoryCounts; - - Person(this.firstName, this.lastName, this.house, - {this.middleName, this.dateOfBirth}); - - factory Person.fromJson(Map json) => _$PersonFromJson(json); - - Map toJson() => _$PersonToJson(this); - - @override - bool operator ==(Object other) => - other is Person && - firstName == other.firstName && - middleName == other.middleName && - lastName == other.lastName && - dateOfBirth == other.dateOfBirth && - house == other.house && - deepEquals(houseMap, other.houseMap); -} - -@JsonSerializable( - useWrappers: true, - nullable: false, -) -class Order { - /// Used to test that `disallowNullValues: true` forces `includeIfNull: false` - @JsonKey(disallowNullValue: true) - int count; - bool isRushed; - - Duration duration; - - @JsonKey(nullable: false) - final Category category; - final UnmodifiableListView items; - Platform platform; - Map altPlatforms; - - Uri homepage; - - @JsonKey( - name: 'status_code', defaultValue: StatusCode.success, nullable: true) - StatusCode statusCode; - - @JsonKey(ignore: true) - String get platformValue => platform?.description; - - set platformValue(String value) { - throw UnimplementedError('not impld'); - } - - // Ignored getter without value set in ctor - int get price => items.fold(0, (total, item) => item.price + total); - - @JsonKey(ignore: true) - bool shouldBeCached; - - Order(this.category, [Iterable items]) - : items = UnmodifiableListView( - List.unmodifiable(items ?? const [])); - - factory Order.fromJson(Map json) => _$OrderFromJson(json); - - Map toJson() => _$OrderToJson(this); - - @override - bool operator ==(Object other) => - other is Order && - count == other.count && - isRushed == other.isRushed && - deepEquals(items, other.items) && - deepEquals(altPlatforms, other.altPlatforms); -} - -@JsonSerializable( - useWrappers: true, - nullable: false, -) -class Item extends ItemCore { - @JsonKey(includeIfNull: false, name: 'item-number') - int itemNumber; - List saleDates; - List rates; - - Item([int price]) : super(price); - - factory Item.fromJson(Map json) => _$ItemFromJson(json); - - Map toJson() => _$ItemToJson(this); - - @override - bool operator ==(Object other) => - other is Item && - price == other.price && - itemNumber == other.itemNumber && - deepEquals(saleDates, other.saleDates); -} - -@JsonSerializable( - useWrappers: true, - nullable: false, -) -class Numbers { - List ints; - List nums; - List doubles; - - @JsonKey(nullable: false) - List nnDoubles; - - @JsonKey(fromJson: durationFromInt, toJson: durationToInt) - Duration duration; - - @JsonKey(fromJson: dateTimeFromEpochUs, toJson: dateTimeToEpochUs) - DateTime date; - - Numbers(); - - factory Numbers.fromJson(Map json) => - _$NumbersFromJson(json); - - Map toJson() => _$NumbersToJson(this); - - @override - bool operator ==(Object other) => - other is Numbers && - deepEquals(ints, other.ints) && - deepEquals(nums, other.nums) && - deepEquals(doubles, other.doubles) && - deepEquals(nnDoubles, other.nnDoubles) && - deepEquals(duration, other.duration) && - deepEquals(date, other.date); -} diff --git a/json_serializable/test/integration/json_test_example.g_non_nullable__use_wrappers.g.dart b/json_serializable/test/integration/json_test_example.g_non_nullable__use_wrappers.g.dart deleted file mode 100644 index e82904856..000000000 --- a/json_serializable/test/integration/json_test_example.g_non_nullable__use_wrappers.g.dart +++ /dev/null @@ -1,258 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'json_test_example.g_non_nullable__use_wrappers.dart'; - -// ************************************************************************** -// JsonSerializableGenerator -// ************************************************************************** - -Person _$PersonFromJson(Map json) { - return Person(json['firstName'] as String, json['lastName'] as String, - _$enumDecode(_$CategoryEnumMap, json[r'$house']), - middleName: json['middleName'] as String, - dateOfBirth: DateTime.parse(json['dateOfBirth'] as String)) - ..order = Order.fromJson(json['order'] as Map) - ..customOrders = MyList.fromJson((json['customOrders'] as List) - .map((e) => Order.fromJson(e as Map)) - .toList()) - ..houseMap = (json['houseMap'] as Map).map( - (k, e) => MapEntry(k, _$enumDecode(_$CategoryEnumMap, e)), - ) - ..categoryCounts = (json['categoryCounts'] as Map).map( - (k, e) => MapEntry(_$enumDecode(_$CategoryEnumMap, k), e as int), - ); -} - -Map _$PersonToJson(Person instance) => - _$PersonJsonMapWrapper(instance); - -class _$PersonJsonMapWrapper extends $JsonMapWrapper { - final Person _v; - _$PersonJsonMapWrapper(this._v); - - @override - Iterable get keys => const [ - 'firstName', - 'middleName', - 'lastName', - 'dateOfBirth', - r'$house', - 'order', - 'customOrders', - 'houseMap', - 'categoryCounts' - ]; - - @override - dynamic operator [](Object key) { - if (key is String) { - switch (key) { - case 'firstName': - return _v.firstName; - case 'middleName': - return _v.middleName; - case 'lastName': - return _v.lastName; - case 'dateOfBirth': - return _v.dateOfBirth.toIso8601String(); - case r'$house': - return _$CategoryEnumMap[_v.house]; - case 'order': - return _v.order; - case 'customOrders': - return _v.customOrders; - case 'houseMap': - return $wrapMap( - _v.houseMap, (e) => _$CategoryEnumMap[e]); - case 'categoryCounts': - return $wrapMap(_v.categoryCounts, (e) => e); - } - } - return null; - } -} - -T _$enumDecode(Map enumValues, dynamic source) { - if (source == null) { - throw ArgumentError('A value must be provided. Supported values: ' - '${enumValues.values.join(', ')}'); - } - return enumValues.entries - .singleWhere((e) => e.value == source, - orElse: () => throw ArgumentError( - '`$source` is not one of the supported values: ' - '${enumValues.values.join(', ')}')) - .key; -} - -const _$CategoryEnumMap = { - Category.top: 'top', - Category.bottom: 'bottom', - Category.strange: 'strange', - Category.charmed: 'charmed', - Category.up: 'up', - Category.down: 'down', - Category.notDiscoveredYet: 'not_discovered_yet' -}; - -Order _$OrderFromJson(Map json) { - $checkKeys(json, disallowNullValues: const ['count']); - return Order( - _$enumDecode(_$CategoryEnumMap, json['category']), - (json['items'] as List) - .map((e) => Item.fromJson(e as Map))) - ..count = json['count'] as int - ..isRushed = json['isRushed'] as bool - ..duration = Duration(microseconds: json['duration'] as int) - ..platform = Platform.fromJson(json['platform'] as String) - ..altPlatforms = (json['altPlatforms'] as Map).map( - (k, e) => MapEntry(k, Platform.fromJson(e as String)), - ) - ..homepage = Uri.parse(json['homepage'] as String) - ..statusCode = - _$enumDecodeNullable(_$StatusCodeEnumMap, json['status_code']) ?? - StatusCode.success; -} - -Map _$OrderToJson(Order instance) => - _$OrderJsonMapWrapper(instance); - -class _$OrderJsonMapWrapper extends $JsonMapWrapper { - final Order _v; - _$OrderJsonMapWrapper(this._v); - - @override - Iterable get keys => const [ - 'count', - 'isRushed', - 'duration', - 'category', - 'items', - 'platform', - 'altPlatforms', - 'homepage', - 'status_code' - ]; - - @override - dynamic operator [](Object key) { - if (key is String) { - switch (key) { - case 'count': - return _v.count; - case 'isRushed': - return _v.isRushed; - case 'duration': - return _v.duration.inMicroseconds; - case 'category': - return _$CategoryEnumMap[_v.category]; - case 'items': - return _v.items; - case 'platform': - return _v.platform; - case 'altPlatforms': - return _v.altPlatforms; - case 'homepage': - return _v.homepage.toString(); - case 'status_code': - return _$StatusCodeEnumMap[_v.statusCode]; - } - } - return null; - } -} - -T _$enumDecodeNullable(Map enumValues, dynamic source) { - if (source == null) { - return null; - } - return _$enumDecode(enumValues, source); -} - -const _$StatusCodeEnumMap = { - StatusCode.success: 200, - StatusCode.notFound: 404 -}; - -Item _$ItemFromJson(Map json) { - return Item(json['price'] as int) - ..itemNumber = json['item-number'] as int - ..saleDates = (json['saleDates'] as List) - .map((e) => DateTime.parse(e as String)) - .toList() - ..rates = (json['rates'] as List).map((e) => e as int).toList(); -} - -Map _$ItemToJson(Item instance) => - _$ItemJsonMapWrapper(instance); - -class _$ItemJsonMapWrapper extends $JsonMapWrapper { - final Item _v; - _$ItemJsonMapWrapper(this._v); - - @override - Iterable get keys => - const ['price', 'item-number', 'saleDates', 'rates']; - - @override - dynamic operator [](Object key) { - if (key is String) { - switch (key) { - case 'price': - return _v.price; - case 'item-number': - return _v.itemNumber; - case 'saleDates': - return $wrapList(_v.saleDates, (e) => e.toIso8601String()); - case 'rates': - return _v.rates; - } - } - return null; - } -} - -Numbers _$NumbersFromJson(Map json) { - return Numbers() - ..ints = (json['ints'] as List).map((e) => e as int).toList() - ..nums = (json['nums'] as List).map((e) => e as num).toList() - ..doubles = - (json['doubles'] as List).map((e) => (e as num).toDouble()).toList() - ..nnDoubles = - (json['nnDoubles'] as List).map((e) => (e as num).toDouble()).toList() - ..duration = durationFromInt(json['duration'] as int) - ..date = dateTimeFromEpochUs(json['date'] as int); -} - -Map _$NumbersToJson(Numbers instance) => - _$NumbersJsonMapWrapper(instance); - -class _$NumbersJsonMapWrapper extends $JsonMapWrapper { - final Numbers _v; - _$NumbersJsonMapWrapper(this._v); - - @override - Iterable get keys => - const ['ints', 'nums', 'doubles', 'nnDoubles', 'duration', 'date']; - - @override - dynamic operator [](Object key) { - if (key is String) { - switch (key) { - case 'ints': - return _v.ints; - case 'nums': - return _v.nums; - case 'doubles': - return _v.doubles; - case 'nnDoubles': - return _v.nnDoubles; - case 'duration': - return durationToInt(_v.duration); - case 'date': - return dateTimeToEpochUs(_v.date); - } - } - return null; - } -} diff --git a/json_serializable/test/integration/json_test_example.g_use_wrappers.dart b/json_serializable/test/integration/json_test_example.g_use_wrappers.dart deleted file mode 100644 index 6c8644347..000000000 --- a/json_serializable/test/integration/json_test_example.g_use_wrappers.dart +++ /dev/null @@ -1,156 +0,0 @@ -// Copyright (c) 2018, 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. - -// ignore_for_file: hash_and_equals -import 'dart:collection'; - -import 'package:json_annotation/json_annotation.dart'; -import 'json_test_common.dart'; - -part 'json_test_example.g_use_wrappers.g.dart'; - -@JsonSerializable( - useWrappers: true, -) -class Person { - final String firstName, middleName, lastName; - final DateTime dateOfBirth; - @JsonKey(name: '\$house') - final Category house; - - Order order; - - MyList customOrders; - - Map houseMap; - Map categoryCounts; - - Person(this.firstName, this.lastName, this.house, - {this.middleName, this.dateOfBirth}); - - factory Person.fromJson(Map json) => _$PersonFromJson(json); - - Map toJson() => _$PersonToJson(this); - - @override - bool operator ==(Object other) => - other is Person && - firstName == other.firstName && - middleName == other.middleName && - lastName == other.lastName && - dateOfBirth == other.dateOfBirth && - house == other.house && - deepEquals(houseMap, other.houseMap); -} - -@JsonSerializable( - useWrappers: true, -) -class Order { - /// Used to test that `disallowNullValues: true` forces `includeIfNull: false` - @JsonKey(disallowNullValue: true) - int count; - bool isRushed; - - Duration duration; - - @JsonKey(nullable: false) - final Category category; - final UnmodifiableListView items; - Platform platform; - Map altPlatforms; - - Uri homepage; - - @JsonKey( - name: 'status_code', defaultValue: StatusCode.success, nullable: true) - StatusCode statusCode; - - @JsonKey(ignore: true) - String get platformValue => platform?.description; - - set platformValue(String value) { - throw UnimplementedError('not impld'); - } - - // Ignored getter without value set in ctor - int get price => items.fold(0, (total, item) => item.price + total); - - @JsonKey(ignore: true) - bool shouldBeCached; - - Order(this.category, [Iterable items]) - : items = UnmodifiableListView( - List.unmodifiable(items ?? const [])); - - factory Order.fromJson(Map json) => _$OrderFromJson(json); - - Map toJson() => _$OrderToJson(this); - - @override - bool operator ==(Object other) => - other is Order && - count == other.count && - isRushed == other.isRushed && - deepEquals(items, other.items) && - deepEquals(altPlatforms, other.altPlatforms); -} - -@JsonSerializable( - useWrappers: true, -) -class Item extends ItemCore { - @JsonKey(includeIfNull: false, name: 'item-number') - int itemNumber; - List saleDates; - List rates; - - Item([int price]) : super(price); - - factory Item.fromJson(Map json) => _$ItemFromJson(json); - - Map toJson() => _$ItemToJson(this); - - @override - bool operator ==(Object other) => - other is Item && - price == other.price && - itemNumber == other.itemNumber && - deepEquals(saleDates, other.saleDates); -} - -@JsonSerializable( - useWrappers: true, -) -class Numbers { - List ints; - List nums; - List doubles; - - @JsonKey(nullable: false) - List nnDoubles; - - @JsonKey(fromJson: durationFromInt, toJson: durationToInt) - Duration duration; - - @JsonKey(fromJson: dateTimeFromEpochUs, toJson: dateTimeToEpochUs) - DateTime date; - - Numbers(); - - factory Numbers.fromJson(Map json) => - _$NumbersFromJson(json); - - Map toJson() => _$NumbersToJson(this); - - @override - bool operator ==(Object other) => - other is Numbers && - deepEquals(ints, other.ints) && - deepEquals(nums, other.nums) && - deepEquals(doubles, other.doubles) && - deepEquals(nnDoubles, other.nnDoubles) && - deepEquals(duration, other.duration) && - deepEquals(date, other.date); -} diff --git a/json_serializable/test/integration/json_test_example.g_use_wrappers.g.dart b/json_serializable/test/integration/json_test_example.g_use_wrappers.g.dart deleted file mode 100644 index 4038aba89..000000000 --- a/json_serializable/test/integration/json_test_example.g_use_wrappers.g.dart +++ /dev/null @@ -1,282 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'json_test_example.g_use_wrappers.dart'; - -// ************************************************************************** -// JsonSerializableGenerator -// ************************************************************************** - -Person _$PersonFromJson(Map json) { - return Person(json['firstName'] as String, json['lastName'] as String, - _$enumDecodeNullable(_$CategoryEnumMap, json[r'$house']), - middleName: json['middleName'] as String, - dateOfBirth: json['dateOfBirth'] == null - ? null - : DateTime.parse(json['dateOfBirth'] as String)) - ..order = json['order'] == null - ? null - : Order.fromJson(json['order'] as Map) - ..customOrders = json['customOrders'] == null - ? null - : MyList.fromJson((json['customOrders'] as List) - ?.map((e) => - e == null ? null : Order.fromJson(e as Map)) - ?.toList()) - ..houseMap = (json['houseMap'] as Map)?.map( - (k, e) => MapEntry(k, _$enumDecodeNullable(_$CategoryEnumMap, e)), - ) - ..categoryCounts = (json['categoryCounts'] as Map)?.map( - (k, e) => MapEntry(_$enumDecodeNullable(_$CategoryEnumMap, k), e as int), - ); -} - -Map _$PersonToJson(Person instance) => - _$PersonJsonMapWrapper(instance); - -class _$PersonJsonMapWrapper extends $JsonMapWrapper { - final Person _v; - _$PersonJsonMapWrapper(this._v); - - @override - Iterable get keys => const [ - 'firstName', - 'middleName', - 'lastName', - 'dateOfBirth', - r'$house', - 'order', - 'customOrders', - 'houseMap', - 'categoryCounts' - ]; - - @override - dynamic operator [](Object key) { - if (key is String) { - switch (key) { - case 'firstName': - return _v.firstName; - case 'middleName': - return _v.middleName; - case 'lastName': - return _v.lastName; - case 'dateOfBirth': - return _v.dateOfBirth?.toIso8601String(); - case r'$house': - return _$CategoryEnumMap[_v.house]; - case 'order': - return _v.order; - case 'customOrders': - return _v.customOrders; - case 'houseMap': - return $wrapMapHandleNull( - _v.houseMap, (e) => _$CategoryEnumMap[e]); - case 'categoryCounts': - return $wrapMapHandleNull(_v.categoryCounts, (e) => e); - } - } - return null; - } -} - -T _$enumDecode(Map enumValues, dynamic source) { - if (source == null) { - throw ArgumentError('A value must be provided. Supported values: ' - '${enumValues.values.join(', ')}'); - } - return enumValues.entries - .singleWhere((e) => e.value == source, - orElse: () => throw ArgumentError( - '`$source` is not one of the supported values: ' - '${enumValues.values.join(', ')}')) - .key; -} - -T _$enumDecodeNullable(Map enumValues, dynamic source) { - if (source == null) { - return null; - } - return _$enumDecode(enumValues, source); -} - -const _$CategoryEnumMap = { - Category.top: 'top', - Category.bottom: 'bottom', - Category.strange: 'strange', - Category.charmed: 'charmed', - Category.up: 'up', - Category.down: 'down', - Category.notDiscoveredYet: 'not_discovered_yet' -}; - -Order _$OrderFromJson(Map json) { - $checkKeys(json, disallowNullValues: const ['count']); - return Order( - _$enumDecode(_$CategoryEnumMap, json['category']), - (json['items'] as List)?.map( - (e) => e == null ? null : Item.fromJson(e as Map))) - ..count = json['count'] as int - ..isRushed = json['isRushed'] as bool - ..duration = json['duration'] == null - ? null - : Duration(microseconds: json['duration'] as int) - ..platform = json['platform'] == null - ? null - : Platform.fromJson(json['platform'] as String) - ..altPlatforms = (json['altPlatforms'] as Map)?.map( - (k, e) => MapEntry(k, e == null ? null : Platform.fromJson(e as String)), - ) - ..homepage = - json['homepage'] == null ? null : Uri.parse(json['homepage'] as String) - ..statusCode = - _$enumDecodeNullable(_$StatusCodeEnumMap, json['status_code']) ?? - StatusCode.success; -} - -Map _$OrderToJson(Order instance) => - _$OrderJsonMapWrapper(instance); - -class _$OrderJsonMapWrapper extends $JsonMapWrapper { - final Order _v; - _$OrderJsonMapWrapper(this._v); - - @override - Iterable get keys sync* { - if (_v.count != null) { - yield 'count'; - } - yield 'isRushed'; - yield 'duration'; - yield 'category'; - yield 'items'; - yield 'platform'; - yield 'altPlatforms'; - yield 'homepage'; - yield 'status_code'; - } - - @override - dynamic operator [](Object key) { - if (key is String) { - switch (key) { - case 'count': - return _v.count; - case 'isRushed': - return _v.isRushed; - case 'duration': - return _v.duration?.inMicroseconds; - case 'category': - return _$CategoryEnumMap[_v.category]; - case 'items': - return _v.items; - case 'platform': - return _v.platform; - case 'altPlatforms': - return _v.altPlatforms; - case 'homepage': - return _v.homepage?.toString(); - case 'status_code': - return _$StatusCodeEnumMap[_v.statusCode]; - } - } - return null; - } -} - -const _$StatusCodeEnumMap = { - StatusCode.success: 200, - StatusCode.notFound: 404 -}; - -Item _$ItemFromJson(Map json) { - return Item(json['price'] as int) - ..itemNumber = json['item-number'] as int - ..saleDates = (json['saleDates'] as List) - ?.map((e) => e == null ? null : DateTime.parse(e as String)) - ?.toList() - ..rates = (json['rates'] as List)?.map((e) => e as int)?.toList(); -} - -Map _$ItemToJson(Item instance) => - _$ItemJsonMapWrapper(instance); - -class _$ItemJsonMapWrapper extends $JsonMapWrapper { - final Item _v; - _$ItemJsonMapWrapper(this._v); - - @override - Iterable get keys sync* { - yield 'price'; - if (_v.itemNumber != null) { - yield 'item-number'; - } - yield 'saleDates'; - yield 'rates'; - } - - @override - dynamic operator [](Object key) { - if (key is String) { - switch (key) { - case 'price': - return _v.price; - case 'item-number': - return _v.itemNumber; - case 'saleDates': - return $wrapListHandleNull( - _v.saleDates, (e) => e?.toIso8601String()); - case 'rates': - return _v.rates; - } - } - return null; - } -} - -Numbers _$NumbersFromJson(Map json) { - return Numbers() - ..ints = (json['ints'] as List)?.map((e) => e as int)?.toList() - ..nums = (json['nums'] as List)?.map((e) => e as num)?.toList() - ..doubles = - (json['doubles'] as List)?.map((e) => (e as num)?.toDouble())?.toList() - ..nnDoubles = - (json['nnDoubles'] as List).map((e) => (e as num).toDouble()).toList() - ..duration = json['duration'] == null - ? null - : durationFromInt(json['duration'] as int) - ..date = - json['date'] == null ? null : dateTimeFromEpochUs(json['date'] as int); -} - -Map _$NumbersToJson(Numbers instance) => - _$NumbersJsonMapWrapper(instance); - -class _$NumbersJsonMapWrapper extends $JsonMapWrapper { - final Numbers _v; - _$NumbersJsonMapWrapper(this._v); - - @override - Iterable get keys => - const ['ints', 'nums', 'doubles', 'nnDoubles', 'duration', 'date']; - - @override - dynamic operator [](Object key) { - if (key is String) { - switch (key) { - case 'ints': - return _v.ints; - case 'nums': - return _v.nums; - case 'doubles': - return _v.doubles; - case 'nnDoubles': - return _v.nnDoubles; - case 'duration': - return _v.duration == null ? null : durationToInt(_v.duration); - case 'date': - return _v.date == null ? null : dateTimeToEpochUs(_v.date); - } - } - return null; - } -} diff --git a/json_serializable/test/json_serializable_test.dart b/json_serializable/test/json_serializable_test.dart index db9dc0923..22207c9e3 100644 --- a/json_serializable/test/json_serializable_test.dart +++ b/json_serializable/test/json_serializable_test.dart @@ -20,9 +20,6 @@ void main() async { reader, const JsonSerializableGenerator(), additionalGenerators: const { - 'wrapped': JsonSerializableGenerator( - config: JsonSerializable(useWrappers: true), - ), 'mixin': JsonSerializableGenerator( config: JsonSerializable(generateToJsonFunction: false)), }, @@ -65,7 +62,6 @@ const _expectedAnnotatedTests = [ 'GeneralTestClass2', 'GenericClass', 'GenericClass', - 'GenericClass', 'IgnoredFieldClass', 'IgnoredFieldCtorClass', 'IncludeIfNullDisallowNullClass', @@ -97,20 +93,16 @@ const _expectedAnnotatedTests = [ 'PropInMixinI448Regression', 'SetSupport', 'SubType', - 'SubType', 'SubTypeWithAnnotatedFieldOverrideExtends', 'SubTypeWithAnnotatedFieldOverrideExtendsWithOverrides', 'SubTypeWithAnnotatedFieldOverrideImplements', 'theAnswer', - 'ToJsonIncludeIfNullFalseWrapped', 'ToJsonNullableFalseIncludeIfNullFalse', - 'ToJsonNullableFalseIncludeIfNullFalseWrapped', 'TypedConvertMethods', 'UnknownCtorParamType', 'UnknownFieldType', 'UnknownFieldTypeToJsonOnly', 'UnknownFieldTypeWithConvert', - 'UnknownFieldTypeWithConvert', 'UnsupportedDateTimeField', 'UnsupportedDurationField', 'UnsupportedListField', diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.factories.dart b/json_serializable/test/kitchen_sink/kitchen_sink.factories.dart index f5b4db0da..4ee2f1413 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.factories.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.factories.dart @@ -3,19 +3,13 @@ import 'kitchen_sink.g_any_map.dart' as any_map; import 'kitchen_sink.g_any_map__checked__non_nullable.dart' as any_map__checked__non_nullable; import 'kitchen_sink.g_any_map__non_nullable.dart' as any_map__non_nullable; -import 'kitchen_sink.g_any_map__non_nullable__use_wrappers.dart' - as any_map__non_nullable__use_wrappers; import 'kitchen_sink.g_exclude_null.dart' as exclude_null; import 'kitchen_sink.g_exclude_null__no_encode_empty.dart' as exclude_null__no_encode_empty; -import 'kitchen_sink.g_exclude_null__no_encode_empty__non_nullable__use_wrappers.dart' - as exclude_null__no_encode_empty__non_nullable__use_wrappers; -import 'kitchen_sink.g_exclude_null__no_encode_empty__use_wrappers.dart' - as exclude_null__no_encode_empty__use_wrappers; +import 'kitchen_sink.g_exclude_null__no_encode_empty__non_nullable.dart' + as exclude_null__no_encode_empty__non_nullable; import 'kitchen_sink.g_exclude_null__non_nullable.dart' as exclude_null__non_nullable; -import 'kitchen_sink.g_exclude_null__use_wrappers.dart' - as exclude_null__use_wrappers; import 'kitchen_sink.g_explicit_to_json.dart' as explicit_to_json; import 'kitchen_sink.g_no_encode_empty.dart' as no_encode_empty; import 'kitchen_sink.g_no_encode_empty__non_nullable.dart' @@ -26,13 +20,10 @@ const factories = [ any_map.factory, any_map__checked__non_nullable.factory, any_map__non_nullable.factory, - any_map__non_nullable__use_wrappers.factory, exclude_null.factory, exclude_null__no_encode_empty.factory, - exclude_null__no_encode_empty__non_nullable__use_wrappers.factory, - exclude_null__no_encode_empty__use_wrappers.factory, + exclude_null__no_encode_empty__non_nullable.factory, exclude_null__non_nullable.factory, - exclude_null__use_wrappers.factory, explicit_to_json.factory, no_encode_empty.factory, no_encode_empty__non_nullable.factory, diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable__use_wrappers.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable__use_wrappers.dart deleted file mode 100644 index 1451e59e8..000000000 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable__use_wrappers.dart +++ /dev/null @@ -1,204 +0,0 @@ -// Copyright (c) 2018, 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. - -// ignore_for_file: annotate_overrides, hash_and_equals -import 'package:json_annotation/json_annotation.dart'; - -import 'json_converters.dart'; -import 'kitchen_sink_interface.dart' as k; -import 'simple_object.dart'; -import 'strict_keys_object.dart'; - -part 'kitchen_sink.g_any_map__non_nullable__use_wrappers.g.dart'; - -// NOTE: these methods are replaced in the `non_nullable` cases to return -// non-null values. -List _defaultList() => []; -Set _defaultSet() => {}; -Map _defaultMap() => {}; -SimpleObject _defaultSimpleObject() => SimpleObject(42); -StrictKeysObject _defaultStrictKeysObject() => StrictKeysObject(10, 'cool'); - -const k.KitchenSinkFactory factory = _Factory(); - -class _Factory implements k.KitchenSinkFactory { - const _Factory(); - - String get description => 'any_map__non_nullable__use_wrappers'; - bool get anyMap => true; - bool get checked => false; - bool get nullable => false; - bool get excludeNull => false; - bool get explicitToJson => false; - bool get noEncodeEmpty => false; - - k.KitchenSink ctor({ - int ctorValidatedNo42, - Iterable iterable, - Iterable dynamicIterable, - Iterable objectIterable, - Iterable intIterable, - Iterable dateTimeIterable, - }) => - KitchenSink( - ctorValidatedNo42: ctorValidatedNo42, - iterable: iterable, - dynamicIterable: dynamicIterable, - objectIterable: objectIterable, - intIterable: intIterable, - dateTimeIterable: dateTimeIterable, - ); - - k.KitchenSink fromJson(Map json) => KitchenSink.fromJson(json); - - k.JsonConverterTestClass jsonConverterCtor() => JsonConverterTestClass(); - - k.JsonConverterTestClass jsonConverterFromJson(Map json) => - JsonConverterTestClass.fromJson(json); -} - -@JsonSerializable( - useWrappers: true, - nullable: false, - anyMap: true, -) -class KitchenSink implements k.KitchenSink { - // NOTE: exposing these as Iterable, but storing the values as List - // to make the equality test work trivially. - final Iterable _iterable; - final Iterable _dynamicIterable; - final Iterable _objectIterable; - final Iterable _intIterable; - final Iterable _dateTimeIterable; - - @JsonKey(name: 'no-42') - final int ctorValidatedNo42; - - KitchenSink({ - this.ctorValidatedNo42, - Iterable iterable, - Iterable dynamicIterable, - Iterable objectIterable, - Iterable intIterable, - Iterable dateTimeIterable, - }) : _iterable = iterable?.toList() ?? _defaultList(), - _dynamicIterable = dynamicIterable?.toList() ?? _defaultList(), - _objectIterable = objectIterable?.toList() ?? _defaultList(), - _intIterable = intIterable?.toList() ?? _defaultList(), - _dateTimeIterable = dateTimeIterable?.toList() ?? _defaultList() { - if (ctorValidatedNo42 == 42) { - throw ArgumentError.value( - 42, 'ctorValidatedNo42', 'The value `42` is not allowed.'); - } - } - - factory KitchenSink.fromJson(Map json) => _$KitchenSinkFromJson(json); - - Map toJson() => _$KitchenSinkToJson(this); - - DateTime dateTime = DateTime(1981, 6, 5); - - BigInt bigInt = BigInt.parse('10000000000000000000'); - - Iterable get iterable => _iterable; - Iterable get dynamicIterable => _dynamicIterable; - Iterable get objectIterable => _objectIterable; - Iterable get intIterable => _intIterable; - - Set set = _defaultSet(); - Set dynamicSet = _defaultSet(); - Set objectSet = _defaultSet(); - Set intSet = _defaultSet(); - Set dateTimeSet = _defaultSet(); - - // Added a one-off annotation on a property (not a field) - @JsonKey(name: 'datetime-iterable') - Iterable get dateTimeIterable => _dateTimeIterable; - - List list = _defaultList(); - List dynamicList = _defaultList(); - List objectList = _defaultList(); - List intList = _defaultList(); - List dateTimeList = _defaultList(); - - Map map = _defaultMap(); - Map stringStringMap = _defaultMap(); - Map dynamicIntMap = _defaultMap(); - Map objectDateTimeMap = _defaultMap(); - - List>>>> crazyComplex = - _defaultList(); - - // Handle fields with names that collide with helper names - Map val = _defaultMap(); - bool writeNotNull; - @JsonKey(name: r'$string') - String string; - - SimpleObject simpleObject = _defaultSimpleObject(); - - StrictKeysObject strictKeysObject = _defaultStrictKeysObject(); - - int _validatedPropertyNo42; - int get validatedPropertyNo42 => _validatedPropertyNo42; - - set validatedPropertyNo42(int value) { - if (value == 42) { - throw StateError('Cannot be 42!'); - } - _validatedPropertyNo42 = value; - } - - bool operator ==(Object other) => k.sinkEquals(this, other); -} - -@JsonSerializable( - useWrappers: true, - nullable: false, - anyMap: true, -) -// referencing a top-level field should work -@durationConverter -// referencing via a const constructor should work -@BigIntStringConverter() -@TrivialNumberConverter.instance -@EpochDateTimeConverter() -class JsonConverterTestClass implements k.JsonConverterTestClass { - JsonConverterTestClass(); - - factory JsonConverterTestClass.fromJson(Map json) => - _$JsonConverterTestClassFromJson(json); - - Map toJson() => _$JsonConverterTestClassToJson(this); - - Duration duration; - List durationList; - - BigInt bigInt = BigInt.parse('10000000000000000000'); - Map bigIntMap; - - TrivialNumber numberSilly; - Set numberSillySet; - - DateTime dateTime = DateTime(1981, 6, 5); -} - -@JsonSerializable( - useWrappers: true, - nullable: false, - anyMap: true, -) -@GenericConverter() -class JsonConverterGeneric { - S item; - List itemList; - Map itemMap; - - JsonConverterGeneric(); - - factory JsonConverterGeneric.fromJson(Map json) => - _$JsonConverterGenericFromJson(json); - - Map toJson() => _$JsonConverterGenericToJson(this); -} diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable__use_wrappers.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable__use_wrappers.g.dart deleted file mode 100644 index 39f0ba2b0..000000000 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable__use_wrappers.g.dart +++ /dev/null @@ -1,288 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'kitchen_sink.g_any_map__non_nullable__use_wrappers.dart'; - -// ************************************************************************** -// JsonSerializableGenerator -// ************************************************************************** - -KitchenSink _$KitchenSinkFromJson(Map json) { - return KitchenSink( - ctorValidatedNo42: json['no-42'] as int, - iterable: json['iterable'] as List, - dynamicIterable: json['dynamicIterable'] as List, - objectIterable: json['objectIterable'] as List, - intIterable: (json['intIterable'] as List).map((e) => e as int), - dateTimeIterable: (json['datetime-iterable'] as List) - .map((e) => DateTime.parse(e as String))) - ..dateTime = DateTime.parse(json['dateTime'] as String) - ..bigInt = BigInt.parse(json['bigInt'] as String) - ..set = (json['set'] as List).toSet() - ..dynamicSet = (json['dynamicSet'] as List).toSet() - ..objectSet = (json['objectSet'] as List).toSet() - ..intSet = (json['intSet'] as List).map((e) => e as int).toSet() - ..dateTimeSet = (json['dateTimeSet'] as List) - .map((e) => DateTime.parse(e as String)) - .toSet() - ..list = json['list'] as List - ..dynamicList = json['dynamicList'] as List - ..objectList = json['objectList'] as List - ..intList = (json['intList'] as List).map((e) => e as int).toList() - ..dateTimeList = (json['dateTimeList'] as List) - .map((e) => DateTime.parse(e as String)) - .toList() - ..map = json['map'] as Map - ..stringStringMap = Map.from(json['stringStringMap'] as Map) - ..dynamicIntMap = Map.from(json['dynamicIntMap'] as Map) - ..objectDateTimeMap = (json['objectDateTimeMap'] as Map).map( - (k, e) => MapEntry(k, DateTime.parse(e as String)), - ) - ..crazyComplex = (json['crazyComplex'] as List) - .map((e) => (e as Map).map( - (k, e) => MapEntry( - k as String, - (e as Map).map( - (k, e) => MapEntry( - k as String, - (e as List) - .map((e) => (e as List) - .map((e) => DateTime.parse(e as String)) - .toList()) - .toList()), - )), - )) - .toList() - ..val = Map.from(json['val'] as Map) - ..writeNotNull = json['writeNotNull'] as bool - ..string = json[r'$string'] as String - ..simpleObject = SimpleObject.fromJson(json['simpleObject'] as Map) - ..strictKeysObject = - StrictKeysObject.fromJson(json['strictKeysObject'] as Map) - ..validatedPropertyNo42 = json['validatedPropertyNo42'] as int; -} - -Map _$KitchenSinkToJson(KitchenSink instance) => - _$KitchenSinkJsonMapWrapper(instance); - -class _$KitchenSinkJsonMapWrapper extends $JsonMapWrapper { - final KitchenSink _v; - _$KitchenSinkJsonMapWrapper(this._v); - - @override - Iterable get keys => const [ - 'no-42', - 'dateTime', - 'bigInt', - 'iterable', - 'dynamicIterable', - 'objectIterable', - 'intIterable', - 'set', - 'dynamicSet', - 'objectSet', - 'intSet', - 'dateTimeSet', - 'datetime-iterable', - 'list', - 'dynamicList', - 'objectList', - 'intList', - 'dateTimeList', - 'map', - 'stringStringMap', - 'dynamicIntMap', - 'objectDateTimeMap', - 'crazyComplex', - 'val', - 'writeNotNull', - r'$string', - 'simpleObject', - 'strictKeysObject', - 'validatedPropertyNo42' - ]; - - @override - dynamic operator [](Object key) { - if (key is String) { - switch (key) { - case 'no-42': - return _v.ctorValidatedNo42; - case 'dateTime': - return _v.dateTime.toIso8601String(); - case 'bigInt': - return _v.bigInt.toString(); - case 'iterable': - return _v.iterable.toList(); - case 'dynamicIterable': - return _v.dynamicIterable.toList(); - case 'objectIterable': - return _v.objectIterable.toList(); - case 'intIterable': - return _v.intIterable.toList(); - case 'set': - return _v.set.toList(); - case 'dynamicSet': - return _v.dynamicSet.toList(); - case 'objectSet': - return _v.objectSet.toList(); - case 'intSet': - return _v.intSet.toList(); - case 'dateTimeSet': - return _v.dateTimeSet.map((e) => e.toIso8601String()).toList(); - case 'datetime-iterable': - return _v.dateTimeIterable.map((e) => e.toIso8601String()).toList(); - case 'list': - return _v.list; - case 'dynamicList': - return _v.dynamicList; - case 'objectList': - return _v.objectList; - case 'intList': - return _v.intList; - case 'dateTimeList': - return $wrapList( - _v.dateTimeList, (e) => e.toIso8601String()); - case 'map': - return _v.map; - case 'stringStringMap': - return _v.stringStringMap; - case 'dynamicIntMap': - return _v.dynamicIntMap; - case 'objectDateTimeMap': - return $wrapMap( - _v.objectDateTimeMap, (e) => e.toIso8601String()); - case 'crazyComplex': - return $wrapList>>>>( - _v.crazyComplex, - (e) => $wrapMap>>>( - e, - (e) => $wrapMap>>( - e, - (e) => $wrapList>( - e, - (e) => $wrapList( - e, (e) => e.toIso8601String()))))); - case 'val': - return _v.val; - case 'writeNotNull': - return _v.writeNotNull; - case r'$string': - return _v.string; - case 'simpleObject': - return _v.simpleObject; - case 'strictKeysObject': - return _v.strictKeysObject; - case 'validatedPropertyNo42': - return _v.validatedPropertyNo42; - } - } - return null; - } -} - -JsonConverterTestClass _$JsonConverterTestClassFromJson(Map json) { - return JsonConverterTestClass() - ..duration = durationConverter.fromJson(json['duration'] as int) - ..durationList = (json['durationList'] as List) - .map((e) => durationConverter.fromJson(e as int)) - .toList() - ..bigInt = const BigIntStringConverter().fromJson(json['bigInt'] as String) - ..bigIntMap = (json['bigIntMap'] as Map).map( - (k, e) => MapEntry( - k as String, const BigIntStringConverter().fromJson(e as String)), - ) - ..numberSilly = - TrivialNumberConverter.instance.fromJson(json['numberSilly'] as int) - ..numberSillySet = (json['numberSillySet'] as List) - .map((e) => TrivialNumberConverter.instance.fromJson(e as int)) - .toSet() - ..dateTime = - const EpochDateTimeConverter().fromJson(json['dateTime'] as int); -} - -Map _$JsonConverterTestClassToJson( - JsonConverterTestClass instance) => - _$JsonConverterTestClassJsonMapWrapper(instance); - -class _$JsonConverterTestClassJsonMapWrapper extends $JsonMapWrapper { - final JsonConverterTestClass _v; - _$JsonConverterTestClassJsonMapWrapper(this._v); - - @override - Iterable get keys => const [ - 'duration', - 'durationList', - 'bigInt', - 'bigIntMap', - 'numberSilly', - 'numberSillySet', - 'dateTime' - ]; - - @override - dynamic operator [](Object key) { - if (key is String) { - switch (key) { - case 'duration': - return durationConverter.toJson(_v.duration); - case 'durationList': - return $wrapList(_v.durationList, durationConverter.toJson); - case 'bigInt': - return const BigIntStringConverter().toJson(_v.bigInt); - case 'bigIntMap': - return $wrapMap( - _v.bigIntMap, const BigIntStringConverter().toJson); - case 'numberSilly': - return TrivialNumberConverter.instance.toJson(_v.numberSilly); - case 'numberSillySet': - return _v.numberSillySet - .map(TrivialNumberConverter.instance.toJson) - .toList(); - case 'dateTime': - return const EpochDateTimeConverter().toJson(_v.dateTime); - } - } - return null; - } -} - -JsonConverterGeneric _$JsonConverterGenericFromJson( - Map json) { - return JsonConverterGeneric() - ..item = - GenericConverter().fromJson(json['item'] as Map) - ..itemList = (json['itemList'] as List) - .map((e) => GenericConverter().fromJson(e as Map)) - .toList() - ..itemMap = (json['itemMap'] as Map).map( - (k, e) => MapEntry(k as String, - GenericConverter().fromJson(e as Map)), - ); -} - -Map _$JsonConverterGenericToJson( - JsonConverterGeneric instance) => - _$JsonConverterGenericJsonMapWrapper(instance); - -class _$JsonConverterGenericJsonMapWrapper extends $JsonMapWrapper { - final JsonConverterGeneric _v; - _$JsonConverterGenericJsonMapWrapper(this._v); - - @override - Iterable get keys => const ['item', 'itemList', 'itemMap']; - - @override - dynamic operator [](Object key) { - if (key is String) { - switch (key) { - case 'item': - return GenericConverter().toJson(_v.item); - case 'itemList': - return $wrapList(_v.itemList, GenericConverter().toJson); - case 'itemMap': - return $wrapMap(_v.itemMap, GenericConverter().toJson); - } - } - return null; - } -} diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty__non_nullable__use_wrappers.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty__non_nullable.dart similarity index 97% rename from json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty__non_nullable__use_wrappers.dart rename to json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty__non_nullable.dart index f5e03d848..abf4f925d 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty__non_nullable__use_wrappers.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty__non_nullable.dart @@ -10,7 +10,7 @@ import 'kitchen_sink_interface.dart' as k; import 'simple_object.dart'; import 'strict_keys_object.dart'; -part 'kitchen_sink.g_exclude_null__no_encode_empty__non_nullable__use_wrappers.g.dart'; +part 'kitchen_sink.g_exclude_null__no_encode_empty__non_nullable.g.dart'; // NOTE: these methods are replaced in the `non_nullable` cases to return // non-null values. @@ -25,8 +25,7 @@ const k.KitchenSinkFactory factory = _Factory(); class _Factory implements k.KitchenSinkFactory { const _Factory(); - String get description => - 'exclude_null__no_encode_empty__non_nullable__use_wrappers'; + String get description => 'exclude_null__no_encode_empty__non_nullable'; bool get anyMap => false; bool get checked => false; bool get nullable => false; @@ -61,7 +60,6 @@ class _Factory implements k.KitchenSinkFactory { } @JsonSerializable( - useWrappers: true, nullable: false, includeIfNull: false, encodeEmptyCollection: false, @@ -158,7 +156,6 @@ class KitchenSink implements k.KitchenSink { } @JsonSerializable( - useWrappers: true, nullable: false, includeIfNull: false, encodeEmptyCollection: false, @@ -190,7 +187,6 @@ class JsonConverterTestClass implements k.JsonConverterTestClass { } @JsonSerializable( - useWrappers: true, nullable: false, includeIfNull: false, encodeEmptyCollection: false, diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty__non_nullable.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty__non_nullable.g.dart new file mode 100644 index 000000000..6337fc66f --- /dev/null +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty__non_nullable.g.dart @@ -0,0 +1,233 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'kitchen_sink.g_exclude_null__no_encode_empty__non_nullable.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +KitchenSink _$KitchenSinkFromJson(Map json) { + return KitchenSink( + ctorValidatedNo42: json['no-42'] as int, + iterable: json['iterable'] as List, + dynamicIterable: json['dynamicIterable'] as List, + objectIterable: json['objectIterable'] as List, + intIterable: (json['intIterable'] as List).map((e) => e as int), + dateTimeIterable: (json['datetime-iterable'] as List) + .map((e) => DateTime.parse(e as String))) + ..dateTime = DateTime.parse(json['dateTime'] as String) + ..bigInt = BigInt.parse(json['bigInt'] as String) + ..set = (json['set'] as List).toSet() + ..dynamicSet = (json['dynamicSet'] as List).toSet() + ..objectSet = (json['objectSet'] as List).toSet() + ..intSet = (json['intSet'] as List).map((e) => e as int).toSet() + ..dateTimeSet = (json['dateTimeSet'] as List) + .map((e) => DateTime.parse(e as String)) + .toSet() + ..list = json['list'] as List + ..dynamicList = json['dynamicList'] as List + ..objectList = json['objectList'] as List + ..intList = (json['intList'] as List).map((e) => e as int).toList() + ..dateTimeList = (json['dateTimeList'] as List) + .map((e) => DateTime.parse(e as String)) + .toList() + ..map = json['map'] as Map + ..stringStringMap = Map.from(json['stringStringMap'] as Map) + ..dynamicIntMap = Map.from(json['dynamicIntMap'] as Map) + ..objectDateTimeMap = + (json['objectDateTimeMap'] as Map).map( + (k, e) => MapEntry(k, DateTime.parse(e as String)), + ) + ..crazyComplex = (json['crazyComplex'] as List) + .map((e) => (e as Map).map( + (k, e) => MapEntry( + k, + (e as Map).map( + (k, e) => MapEntry( + k, + (e as List) + .map((e) => (e as List) + .map((e) => DateTime.parse(e as String)) + .toList()) + .toList()), + )), + )) + .toList() + ..val = Map.from(json['val'] as Map) + ..writeNotNull = json['writeNotNull'] as bool + ..string = json[r'$string'] as String + ..simpleObject = + SimpleObject.fromJson(json['simpleObject'] as Map) + ..strictKeysObject = StrictKeysObject.fromJson( + json['strictKeysObject'] as Map) + ..validatedPropertyNo42 = json['validatedPropertyNo42'] as int; +} + +Map _$KitchenSinkToJson(KitchenSink instance) { + final val = { + 'no-42': instance.ctorValidatedNo42, + 'dateTime': instance.dateTime.toIso8601String(), + 'bigInt': instance.bigInt.toString(), + }; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('iterable', _$nullIfEmptyIterable(instance.iterable)?.toList()); + writeNotNull('dynamicIterable', + _$nullIfEmptyIterable(instance.dynamicIterable)?.toList()); + writeNotNull('objectIterable', + _$nullIfEmptyIterable(instance.objectIterable)?.toList()); + writeNotNull( + 'intIterable', _$nullIfEmptyIterable(instance.intIterable)?.toList()); + writeNotNull('set', _$nullIfEmptyIterable(instance.set)?.toList()); + writeNotNull( + 'dynamicSet', _$nullIfEmptyIterable(instance.dynamicSet)?.toList()); + writeNotNull( + 'objectSet', _$nullIfEmptyIterable(instance.objectSet)?.toList()); + writeNotNull('intSet', _$nullIfEmptyIterable(instance.intSet)?.toList()); + writeNotNull( + 'dateTimeSet', + _$nullIfEmptyIterable(instance.dateTimeSet) + ?.map((e) => e.toIso8601String()) + ?.toList()); + writeNotNull( + 'datetime-iterable', + _$nullIfEmptyIterable(instance.dateTimeIterable) + ?.map((e) => e.toIso8601String()) + ?.toList()); + writeNotNull('list', _$nullIfEmptyIterable(instance.list)); + writeNotNull('dynamicList', _$nullIfEmptyIterable(instance.dynamicList)); + writeNotNull('objectList', _$nullIfEmptyIterable(instance.objectList)); + writeNotNull('intList', _$nullIfEmptyIterable(instance.intList)); + writeNotNull( + 'dateTimeList', + _$nullIfEmptyIterable(instance.dateTimeList) + ?.map((e) => e.toIso8601String()) + ?.toList()); + writeNotNull('map', _$nullIfEmptyMap(instance.map)); + writeNotNull('stringStringMap', _$nullIfEmptyMap(instance.stringStringMap)); + writeNotNull('dynamicIntMap', _$nullIfEmptyMap(instance.dynamicIntMap)); + writeNotNull( + 'objectDateTimeMap', + _$nullIfEmptyMap(instance.objectDateTimeMap) + ?.map((k, e) => MapEntry(k, e.toIso8601String()))); + writeNotNull( + 'crazyComplex', + _$nullIfEmptyIterable(instance.crazyComplex) + ?.map((e) => e.map((k, e) => MapEntry( + k, + e.map((k, e) => MapEntry( + k, + e + .map((e) => e.map((e) => e.toIso8601String()).toList()) + .toList()))))) + ?.toList()); + writeNotNull('val', _$nullIfEmptyMap(instance.val)); + val['writeNotNull'] = instance.writeNotNull; + val[r'$string'] = instance.string; + val['simpleObject'] = instance.simpleObject; + val['strictKeysObject'] = instance.strictKeysObject; + val['validatedPropertyNo42'] = instance.validatedPropertyNo42; + return val; +} + +T _$nullIfEmptyIterable(T source) => + (source == null || source.isEmpty) ? null : source; + +T _$nullIfEmptyMap(T source) => + (source == null || source.isEmpty) ? null : source; + +JsonConverterTestClass _$JsonConverterTestClassFromJson( + Map json) { + return JsonConverterTestClass() + ..duration = durationConverter.fromJson(json['duration'] as int) + ..durationList = (json['durationList'] as List) + .map((e) => durationConverter.fromJson(e as int)) + .toList() + ..bigInt = const BigIntStringConverter().fromJson(json['bigInt'] as String) + ..bigIntMap = (json['bigIntMap'] as Map).map( + (k, e) => + MapEntry(k, const BigIntStringConverter().fromJson(e as String)), + ) + ..numberSilly = + TrivialNumberConverter.instance.fromJson(json['numberSilly'] as int) + ..numberSillySet = (json['numberSillySet'] as List) + .map((e) => TrivialNumberConverter.instance.fromJson(e as int)) + .toSet() + ..dateTime = + const EpochDateTimeConverter().fromJson(json['dateTime'] as int); +} + +Map _$JsonConverterTestClassToJson( + JsonConverterTestClass instance) { + final val = {}; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('duration', durationConverter.toJson(instance.duration)); + writeNotNull( + 'durationList', + _$nullIfEmptyIterable(instance.durationList) + ?.map(durationConverter.toJson) + ?.toList()); + writeNotNull('bigInt', const BigIntStringConverter().toJson(instance.bigInt)); + writeNotNull( + 'bigIntMap', + _$nullIfEmptyMap(instance.bigIntMap)?.map( + (k, e) => MapEntry(k, const BigIntStringConverter().toJson(e)))); + writeNotNull('numberSilly', + TrivialNumberConverter.instance.toJson(instance.numberSilly)); + writeNotNull( + 'numberSillySet', + _$nullIfEmptyIterable(instance.numberSillySet) + ?.map(TrivialNumberConverter.instance.toJson) + ?.toList()); + writeNotNull( + 'dateTime', const EpochDateTimeConverter().toJson(instance.dateTime)); + return val; +} + +JsonConverterGeneric _$JsonConverterGenericFromJson( + Map json) { + return JsonConverterGeneric() + ..item = + GenericConverter().fromJson(json['item'] as Map) + ..itemList = (json['itemList'] as List) + .map((e) => GenericConverter().fromJson(e as Map)) + .toList() + ..itemMap = (json['itemMap'] as Map).map( + (k, e) => MapEntry( + k, GenericConverter().fromJson(e as Map)), + ); +} + +Map _$JsonConverterGenericToJson( + JsonConverterGeneric instance) { + final val = {}; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('item', GenericConverter().toJson(instance.item)); + writeNotNull( + 'itemList', + _$nullIfEmptyIterable(instance.itemList) + ?.map(GenericConverter().toJson) + ?.toList()); + writeNotNull( + 'itemMap', + _$nullIfEmptyMap(instance.itemMap) + ?.map((k, e) => MapEntry(k, GenericConverter().toJson(e)))); + return val; +} diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty__non_nullable__use_wrappers.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty__non_nullable__use_wrappers.g.dart deleted file mode 100644 index 112026f0b..000000000 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty__non_nullable__use_wrappers.g.dart +++ /dev/null @@ -1,374 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'kitchen_sink.g_exclude_null__no_encode_empty__non_nullable__use_wrappers.dart'; - -// ************************************************************************** -// JsonSerializableGenerator -// ************************************************************************** - -KitchenSink _$KitchenSinkFromJson(Map json) { - return KitchenSink( - ctorValidatedNo42: json['no-42'] as int, - iterable: json['iterable'] as List, - dynamicIterable: json['dynamicIterable'] as List, - objectIterable: json['objectIterable'] as List, - intIterable: (json['intIterable'] as List).map((e) => e as int), - dateTimeIterable: (json['datetime-iterable'] as List) - .map((e) => DateTime.parse(e as String))) - ..dateTime = DateTime.parse(json['dateTime'] as String) - ..bigInt = BigInt.parse(json['bigInt'] as String) - ..set = (json['set'] as List).toSet() - ..dynamicSet = (json['dynamicSet'] as List).toSet() - ..objectSet = (json['objectSet'] as List).toSet() - ..intSet = (json['intSet'] as List).map((e) => e as int).toSet() - ..dateTimeSet = (json['dateTimeSet'] as List) - .map((e) => DateTime.parse(e as String)) - .toSet() - ..list = json['list'] as List - ..dynamicList = json['dynamicList'] as List - ..objectList = json['objectList'] as List - ..intList = (json['intList'] as List).map((e) => e as int).toList() - ..dateTimeList = (json['dateTimeList'] as List) - .map((e) => DateTime.parse(e as String)) - .toList() - ..map = json['map'] as Map - ..stringStringMap = Map.from(json['stringStringMap'] as Map) - ..dynamicIntMap = Map.from(json['dynamicIntMap'] as Map) - ..objectDateTimeMap = - (json['objectDateTimeMap'] as Map).map( - (k, e) => MapEntry(k, DateTime.parse(e as String)), - ) - ..crazyComplex = (json['crazyComplex'] as List) - .map((e) => (e as Map).map( - (k, e) => MapEntry( - k, - (e as Map).map( - (k, e) => MapEntry( - k, - (e as List) - .map((e) => (e as List) - .map((e) => DateTime.parse(e as String)) - .toList()) - .toList()), - )), - )) - .toList() - ..val = Map.from(json['val'] as Map) - ..writeNotNull = json['writeNotNull'] as bool - ..string = json[r'$string'] as String - ..simpleObject = - SimpleObject.fromJson(json['simpleObject'] as Map) - ..strictKeysObject = StrictKeysObject.fromJson( - json['strictKeysObject'] as Map) - ..validatedPropertyNo42 = json['validatedPropertyNo42'] as int; -} - -Map _$KitchenSinkToJson(KitchenSink instance) => - _$KitchenSinkJsonMapWrapper(instance); - -class _$KitchenSinkJsonMapWrapper extends $JsonMapWrapper { - final KitchenSink _v; - _$KitchenSinkJsonMapWrapper(this._v); - - @override - Iterable get keys sync* { - yield 'no-42'; - yield 'dateTime'; - yield 'bigInt'; - if (_v.iterable.isNotEmpty) { - yield 'iterable'; - } - if (_v.dynamicIterable.isNotEmpty) { - yield 'dynamicIterable'; - } - if (_v.objectIterable.isNotEmpty) { - yield 'objectIterable'; - } - if (_v.intIterable.isNotEmpty) { - yield 'intIterable'; - } - if (_v.set.isNotEmpty) { - yield 'set'; - } - if (_v.dynamicSet.isNotEmpty) { - yield 'dynamicSet'; - } - if (_v.objectSet.isNotEmpty) { - yield 'objectSet'; - } - if (_v.intSet.isNotEmpty) { - yield 'intSet'; - } - if (_v.dateTimeSet.isNotEmpty) { - yield 'dateTimeSet'; - } - if (_v.dateTimeIterable.isNotEmpty) { - yield 'datetime-iterable'; - } - if (_v.list.isNotEmpty) { - yield 'list'; - } - if (_v.dynamicList.isNotEmpty) { - yield 'dynamicList'; - } - if (_v.objectList.isNotEmpty) { - yield 'objectList'; - } - if (_v.intList.isNotEmpty) { - yield 'intList'; - } - if (_v.dateTimeList.isNotEmpty) { - yield 'dateTimeList'; - } - if (_v.map.isNotEmpty) { - yield 'map'; - } - if (_v.stringStringMap.isNotEmpty) { - yield 'stringStringMap'; - } - if (_v.dynamicIntMap.isNotEmpty) { - yield 'dynamicIntMap'; - } - if (_v.objectDateTimeMap.isNotEmpty) { - yield 'objectDateTimeMap'; - } - if (_v.crazyComplex.isNotEmpty) { - yield 'crazyComplex'; - } - if (_v.val.isNotEmpty) { - yield 'val'; - } - yield 'writeNotNull'; - yield r'$string'; - yield 'simpleObject'; - yield 'strictKeysObject'; - yield 'validatedPropertyNo42'; - } - - @override - dynamic operator [](Object key) { - if (key is String) { - switch (key) { - case 'no-42': - return _v.ctorValidatedNo42; - case 'dateTime': - return _v.dateTime.toIso8601String(); - case 'bigInt': - return _v.bigInt.toString(); - case 'iterable': - return _$nullIfEmptyIterable(_v.iterable)?.toList(); - case 'dynamicIterable': - return _$nullIfEmptyIterable(_v.dynamicIterable)?.toList(); - case 'objectIterable': - return _$nullIfEmptyIterable(_v.objectIterable)?.toList(); - case 'intIterable': - return _$nullIfEmptyIterable(_v.intIterable)?.toList(); - case 'set': - return _$nullIfEmptyIterable(_v.set)?.toList(); - case 'dynamicSet': - return _$nullIfEmptyIterable(_v.dynamicSet)?.toList(); - case 'objectSet': - return _$nullIfEmptyIterable(_v.objectSet)?.toList(); - case 'intSet': - return _$nullIfEmptyIterable(_v.intSet)?.toList(); - case 'dateTimeSet': - return _$nullIfEmptyIterable(_v.dateTimeSet) - ?.map((e) => e.toIso8601String()) - ?.toList(); - case 'datetime-iterable': - return _$nullIfEmptyIterable(_v.dateTimeIterable) - ?.map((e) => e.toIso8601String()) - ?.toList(); - case 'list': - return _$nullIfEmptyIterable(_v.list); - case 'dynamicList': - return _$nullIfEmptyIterable(_v.dynamicList); - case 'objectList': - return _$nullIfEmptyIterable(_v.objectList); - case 'intList': - return _$nullIfEmptyIterable(_v.intList); - case 'dateTimeList': - return $wrapListHandleNull( - _$nullIfEmptyIterable(_v.dateTimeList), - (e) => e.toIso8601String()); - case 'map': - return _$nullIfEmptyMap(_v.map); - case 'stringStringMap': - return _$nullIfEmptyMap(_v.stringStringMap); - case 'dynamicIntMap': - return _$nullIfEmptyMap(_v.dynamicIntMap); - case 'objectDateTimeMap': - return $wrapMapHandleNull( - _$nullIfEmptyMap(_v.objectDateTimeMap), - (e) => e.toIso8601String()); - case 'crazyComplex': - return $wrapListHandleNull< - Map>>>>( - _$nullIfEmptyIterable(_v.crazyComplex), - (e) => $wrapMap>>>( - e, - (e) => $wrapMap>>( - e, - (e) => $wrapList>( - e, - (e) => $wrapList( - e, (e) => e.toIso8601String()))))); - case 'val': - return _$nullIfEmptyMap(_v.val); - case 'writeNotNull': - return _v.writeNotNull; - case r'$string': - return _v.string; - case 'simpleObject': - return _v.simpleObject; - case 'strictKeysObject': - return _v.strictKeysObject; - case 'validatedPropertyNo42': - return _v.validatedPropertyNo42; - } - } - return null; - } -} - -T _$nullIfEmptyIterable(T source) => - (source == null || source.isEmpty) ? null : source; - -T _$nullIfEmptyMap(T source) => - (source == null || source.isEmpty) ? null : source; - -JsonConverterTestClass _$JsonConverterTestClassFromJson( - Map json) { - return JsonConverterTestClass() - ..duration = durationConverter.fromJson(json['duration'] as int) - ..durationList = (json['durationList'] as List) - .map((e) => durationConverter.fromJson(e as int)) - .toList() - ..bigInt = const BigIntStringConverter().fromJson(json['bigInt'] as String) - ..bigIntMap = (json['bigIntMap'] as Map).map( - (k, e) => - MapEntry(k, const BigIntStringConverter().fromJson(e as String)), - ) - ..numberSilly = - TrivialNumberConverter.instance.fromJson(json['numberSilly'] as int) - ..numberSillySet = (json['numberSillySet'] as List) - .map((e) => TrivialNumberConverter.instance.fromJson(e as int)) - .toSet() - ..dateTime = - const EpochDateTimeConverter().fromJson(json['dateTime'] as int); -} - -Map _$JsonConverterTestClassToJson( - JsonConverterTestClass instance) => - _$JsonConverterTestClassJsonMapWrapper(instance); - -class _$JsonConverterTestClassJsonMapWrapper extends $JsonMapWrapper { - final JsonConverterTestClass _v; - _$JsonConverterTestClassJsonMapWrapper(this._v); - - @override - Iterable get keys sync* { - if (durationConverter.toJson(_v.duration) != null) { - yield 'duration'; - } - if (_v.durationList.isNotEmpty) { - yield 'durationList'; - } - if (const BigIntStringConverter().toJson(_v.bigInt) != null) { - yield 'bigInt'; - } - if (_v.bigIntMap.isNotEmpty) { - yield 'bigIntMap'; - } - if (TrivialNumberConverter.instance.toJson(_v.numberSilly) != null) { - yield 'numberSilly'; - } - if (_v.numberSillySet.isNotEmpty) { - yield 'numberSillySet'; - } - if (const EpochDateTimeConverter().toJson(_v.dateTime) != null) { - yield 'dateTime'; - } - } - - @override - dynamic operator [](Object key) { - if (key is String) { - switch (key) { - case 'duration': - return durationConverter.toJson(_v.duration); - case 'durationList': - return $wrapListHandleNull( - _$nullIfEmptyIterable(_v.durationList), durationConverter.toJson); - case 'bigInt': - return const BigIntStringConverter().toJson(_v.bigInt); - case 'bigIntMap': - return $wrapMapHandleNull( - _$nullIfEmptyMap(_v.bigIntMap), - const BigIntStringConverter().toJson); - case 'numberSilly': - return TrivialNumberConverter.instance.toJson(_v.numberSilly); - case 'numberSillySet': - return _$nullIfEmptyIterable(_v.numberSillySet) - ?.map(TrivialNumberConverter.instance.toJson) - ?.toList(); - case 'dateTime': - return const EpochDateTimeConverter().toJson(_v.dateTime); - } - } - return null; - } -} - -JsonConverterGeneric _$JsonConverterGenericFromJson( - Map json) { - return JsonConverterGeneric() - ..item = - GenericConverter().fromJson(json['item'] as Map) - ..itemList = (json['itemList'] as List) - .map((e) => GenericConverter().fromJson(e as Map)) - .toList() - ..itemMap = (json['itemMap'] as Map).map( - (k, e) => MapEntry( - k, GenericConverter().fromJson(e as Map)), - ); -} - -Map _$JsonConverterGenericToJson( - JsonConverterGeneric instance) => - _$JsonConverterGenericJsonMapWrapper(instance); - -class _$JsonConverterGenericJsonMapWrapper extends $JsonMapWrapper { - final JsonConverterGeneric _v; - _$JsonConverterGenericJsonMapWrapper(this._v); - - @override - Iterable get keys sync* { - if (GenericConverter().toJson(_v.item) != null) { - yield 'item'; - } - if (_v.itemList.isNotEmpty) { - yield 'itemList'; - } - if (_v.itemMap.isNotEmpty) { - yield 'itemMap'; - } - } - - @override - dynamic operator [](Object key) { - if (key is String) { - switch (key) { - case 'item': - return GenericConverter().toJson(_v.item); - case 'itemList': - return $wrapListHandleNull( - _$nullIfEmptyIterable(_v.itemList), GenericConverter().toJson); - case 'itemMap': - return $wrapMapHandleNull( - _$nullIfEmptyMap(_v.itemMap), GenericConverter().toJson); - } - } - return null; - } -} diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty__use_wrappers.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty__use_wrappers.dart deleted file mode 100644 index 9a0db7303..000000000 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty__use_wrappers.dart +++ /dev/null @@ -1,206 +0,0 @@ -// Copyright (c) 2018, 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. - -// ignore_for_file: annotate_overrides, hash_and_equals -import 'package:json_annotation/json_annotation.dart'; - -import 'json_converters.dart'; -import 'kitchen_sink_interface.dart' as k; -import 'simple_object.dart'; -import 'strict_keys_object.dart'; - -part 'kitchen_sink.g_exclude_null__no_encode_empty__use_wrappers.g.dart'; - -// NOTE: these methods are replaced in the `non_nullable` cases to return -// non-null values. -List _defaultList() => null; -Set _defaultSet() => null; -Map _defaultMap() => null; -SimpleObject _defaultSimpleObject() => null; -StrictKeysObject _defaultStrictKeysObject() => null; - -const k.KitchenSinkFactory factory = _Factory(); - -class _Factory implements k.KitchenSinkFactory { - const _Factory(); - - String get description => 'exclude_null__no_encode_empty__use_wrappers'; - bool get anyMap => false; - bool get checked => false; - bool get nullable => true; - bool get excludeNull => true; - bool get explicitToJson => false; - bool get noEncodeEmpty => true; - - k.KitchenSink ctor({ - int ctorValidatedNo42, - Iterable iterable, - Iterable dynamicIterable, - Iterable objectIterable, - Iterable intIterable, - Iterable dateTimeIterable, - }) => - KitchenSink( - ctorValidatedNo42: ctorValidatedNo42, - iterable: iterable, - dynamicIterable: dynamicIterable, - objectIterable: objectIterable, - intIterable: intIterable, - dateTimeIterable: dateTimeIterable, - ); - - k.KitchenSink fromJson(Map json) => - KitchenSink.fromJson(json); - - k.JsonConverterTestClass jsonConverterCtor() => JsonConverterTestClass(); - - k.JsonConverterTestClass jsonConverterFromJson(Map json) => - JsonConverterTestClass.fromJson(json); -} - -@JsonSerializable( - useWrappers: true, - includeIfNull: false, - encodeEmptyCollection: false, -) -class KitchenSink implements k.KitchenSink { - // NOTE: exposing these as Iterable, but storing the values as List - // to make the equality test work trivially. - final Iterable _iterable; - final Iterable _dynamicIterable; - final Iterable _objectIterable; - final Iterable _intIterable; - final Iterable _dateTimeIterable; - - @JsonKey(name: 'no-42') - final int ctorValidatedNo42; - - KitchenSink({ - this.ctorValidatedNo42, - Iterable iterable, - Iterable dynamicIterable, - Iterable objectIterable, - Iterable intIterable, - Iterable dateTimeIterable, - }) : _iterable = iterable?.toList() ?? _defaultList(), - _dynamicIterable = dynamicIterable?.toList() ?? _defaultList(), - _objectIterable = objectIterable?.toList() ?? _defaultList(), - _intIterable = intIterable?.toList() ?? _defaultList(), - _dateTimeIterable = dateTimeIterable?.toList() ?? _defaultList() { - if (ctorValidatedNo42 == 42) { - throw ArgumentError.value( - 42, 'ctorValidatedNo42', 'The value `42` is not allowed.'); - } - } - - factory KitchenSink.fromJson(Map json) => - _$KitchenSinkFromJson(json); - - Map toJson() => _$KitchenSinkToJson(this); - - DateTime dateTime; - - BigInt bigInt; - - Iterable get iterable => _iterable; - Iterable get dynamicIterable => _dynamicIterable; - Iterable get objectIterable => _objectIterable; - Iterable get intIterable => _intIterable; - - Set set = _defaultSet(); - Set dynamicSet = _defaultSet(); - Set objectSet = _defaultSet(); - Set intSet = _defaultSet(); - Set dateTimeSet = _defaultSet(); - - // Added a one-off annotation on a property (not a field) - @JsonKey(name: 'datetime-iterable') - Iterable get dateTimeIterable => _dateTimeIterable; - - List list = _defaultList(); - List dynamicList = _defaultList(); - List objectList = _defaultList(); - List intList = _defaultList(); - List dateTimeList = _defaultList(); - - Map map = _defaultMap(); - Map stringStringMap = _defaultMap(); - Map dynamicIntMap = _defaultMap(); - Map objectDateTimeMap = _defaultMap(); - - List>>>> crazyComplex = - _defaultList(); - - // Handle fields with names that collide with helper names - Map val = _defaultMap(); - bool writeNotNull; - @JsonKey(name: r'$string') - String string; - - SimpleObject simpleObject = _defaultSimpleObject(); - - StrictKeysObject strictKeysObject = _defaultStrictKeysObject(); - - int _validatedPropertyNo42; - int get validatedPropertyNo42 => _validatedPropertyNo42; - - set validatedPropertyNo42(int value) { - if (value == 42) { - throw StateError('Cannot be 42!'); - } - _validatedPropertyNo42 = value; - } - - bool operator ==(Object other) => k.sinkEquals(this, other); -} - -@JsonSerializable( - useWrappers: true, - includeIfNull: false, - encodeEmptyCollection: false, -) -// referencing a top-level field should work -@durationConverter -// referencing via a const constructor should work -@BigIntStringConverter() -@TrivialNumberConverter.instance -@EpochDateTimeConverter() -class JsonConverterTestClass implements k.JsonConverterTestClass { - JsonConverterTestClass(); - - factory JsonConverterTestClass.fromJson(Map json) => - _$JsonConverterTestClassFromJson(json); - - Map toJson() => _$JsonConverterTestClassToJson(this); - - Duration duration; - List durationList; - - BigInt bigInt; - Map bigIntMap; - - TrivialNumber numberSilly; - Set numberSillySet; - - DateTime dateTime; -} - -@JsonSerializable( - useWrappers: true, - includeIfNull: false, - encodeEmptyCollection: false, -) -@GenericConverter() -class JsonConverterGeneric { - S item; - List itemList; - Map itemMap; - - JsonConverterGeneric(); - - factory JsonConverterGeneric.fromJson(Map json) => - _$JsonConverterGenericFromJson(json); - - Map toJson() => _$JsonConverterGenericToJson(this); -} diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty__use_wrappers.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty__use_wrappers.g.dart deleted file mode 100644 index 60d981579..000000000 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty__use_wrappers.g.dart +++ /dev/null @@ -1,444 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'kitchen_sink.g_exclude_null__no_encode_empty__use_wrappers.dart'; - -// ************************************************************************** -// JsonSerializableGenerator -// ************************************************************************** - -KitchenSink _$KitchenSinkFromJson(Map json) { - return KitchenSink( - ctorValidatedNo42: json['no-42'] as int, - iterable: json['iterable'] as List, - dynamicIterable: json['dynamicIterable'] as List, - objectIterable: json['objectIterable'] as List, - intIterable: (json['intIterable'] as List)?.map((e) => e as int), - dateTimeIterable: (json['datetime-iterable'] as List) - ?.map((e) => e == null ? null : DateTime.parse(e as String))) - ..dateTime = json['dateTime'] == null - ? null - : DateTime.parse(json['dateTime'] as String) - ..bigInt = - json['bigInt'] == null ? null : BigInt.parse(json['bigInt'] as String) - ..set = (json['set'] as List)?.toSet() - ..dynamicSet = (json['dynamicSet'] as List)?.toSet() - ..objectSet = (json['objectSet'] as List)?.toSet() - ..intSet = (json['intSet'] as List)?.map((e) => e as int)?.toSet() - ..dateTimeSet = (json['dateTimeSet'] as List) - ?.map((e) => e == null ? null : DateTime.parse(e as String)) - ?.toSet() - ..list = json['list'] as List - ..dynamicList = json['dynamicList'] as List - ..objectList = json['objectList'] as List - ..intList = (json['intList'] as List)?.map((e) => e as int)?.toList() - ..dateTimeList = (json['dateTimeList'] as List) - ?.map((e) => e == null ? null : DateTime.parse(e as String)) - ?.toList() - ..map = json['map'] as Map - ..stringStringMap = (json['stringStringMap'] as Map)?.map( - (k, e) => MapEntry(k, e as String), - ) - ..dynamicIntMap = (json['dynamicIntMap'] as Map)?.map( - (k, e) => MapEntry(k, e as int), - ) - ..objectDateTimeMap = - (json['objectDateTimeMap'] as Map)?.map( - (k, e) => MapEntry(k, e == null ? null : DateTime.parse(e as String)), - ) - ..crazyComplex = (json['crazyComplex'] as List) - ?.map((e) => (e as Map)?.map( - (k, e) => MapEntry( - k, - (e as Map)?.map( - (k, e) => MapEntry( - k, - (e as List) - ?.map((e) => (e as List) - ?.map((e) => e == null - ? null - : DateTime.parse(e as String)) - ?.toList()) - ?.toList()), - )), - )) - ?.toList() - ..val = (json['val'] as Map)?.map( - (k, e) => MapEntry(k, e as bool), - ) - ..writeNotNull = json['writeNotNull'] as bool - ..string = json[r'$string'] as String - ..simpleObject = json['simpleObject'] == null - ? null - : SimpleObject.fromJson(json['simpleObject'] as Map) - ..strictKeysObject = json['strictKeysObject'] == null - ? null - : StrictKeysObject.fromJson( - json['strictKeysObject'] as Map) - ..validatedPropertyNo42 = json['validatedPropertyNo42'] as int; -} - -Map _$KitchenSinkToJson(KitchenSink instance) => - _$KitchenSinkJsonMapWrapper(instance); - -class _$KitchenSinkJsonMapWrapper extends $JsonMapWrapper { - final KitchenSink _v; - _$KitchenSinkJsonMapWrapper(this._v); - - @override - Iterable get keys sync* { - if (_v.ctorValidatedNo42 != null) { - yield 'no-42'; - } - if (_v.dateTime != null) { - yield 'dateTime'; - } - if (_v.bigInt != null) { - yield 'bigInt'; - } - if (_v.iterable?.isNotEmpty ?? false) { - yield 'iterable'; - } - if (_v.dynamicIterable?.isNotEmpty ?? false) { - yield 'dynamicIterable'; - } - if (_v.objectIterable?.isNotEmpty ?? false) { - yield 'objectIterable'; - } - if (_v.intIterable?.isNotEmpty ?? false) { - yield 'intIterable'; - } - if (_v.set?.isNotEmpty ?? false) { - yield 'set'; - } - if (_v.dynamicSet?.isNotEmpty ?? false) { - yield 'dynamicSet'; - } - if (_v.objectSet?.isNotEmpty ?? false) { - yield 'objectSet'; - } - if (_v.intSet?.isNotEmpty ?? false) { - yield 'intSet'; - } - if (_v.dateTimeSet?.isNotEmpty ?? false) { - yield 'dateTimeSet'; - } - if (_v.dateTimeIterable?.isNotEmpty ?? false) { - yield 'datetime-iterable'; - } - if (_v.list?.isNotEmpty ?? false) { - yield 'list'; - } - if (_v.dynamicList?.isNotEmpty ?? false) { - yield 'dynamicList'; - } - if (_v.objectList?.isNotEmpty ?? false) { - yield 'objectList'; - } - if (_v.intList?.isNotEmpty ?? false) { - yield 'intList'; - } - if (_v.dateTimeList?.isNotEmpty ?? false) { - yield 'dateTimeList'; - } - if (_v.map?.isNotEmpty ?? false) { - yield 'map'; - } - if (_v.stringStringMap?.isNotEmpty ?? false) { - yield 'stringStringMap'; - } - if (_v.dynamicIntMap?.isNotEmpty ?? false) { - yield 'dynamicIntMap'; - } - if (_v.objectDateTimeMap?.isNotEmpty ?? false) { - yield 'objectDateTimeMap'; - } - if (_v.crazyComplex?.isNotEmpty ?? false) { - yield 'crazyComplex'; - } - if (_v.val?.isNotEmpty ?? false) { - yield 'val'; - } - if (_v.writeNotNull != null) { - yield 'writeNotNull'; - } - if (_v.string != null) { - yield r'$string'; - } - if (_v.simpleObject != null) { - yield 'simpleObject'; - } - if (_v.strictKeysObject != null) { - yield 'strictKeysObject'; - } - if (_v.validatedPropertyNo42 != null) { - yield 'validatedPropertyNo42'; - } - } - - @override - dynamic operator [](Object key) { - if (key is String) { - switch (key) { - case 'no-42': - return _v.ctorValidatedNo42; - case 'dateTime': - return _v.dateTime?.toIso8601String(); - case 'bigInt': - return _v.bigInt?.toString(); - case 'iterable': - return _$nullIfEmptyIterable(_v.iterable)?.toList(); - case 'dynamicIterable': - return _$nullIfEmptyIterable(_v.dynamicIterable)?.toList(); - case 'objectIterable': - return _$nullIfEmptyIterable(_v.objectIterable)?.toList(); - case 'intIterable': - return _$nullIfEmptyIterable(_v.intIterable)?.toList(); - case 'set': - return _$nullIfEmptyIterable(_v.set)?.toList(); - case 'dynamicSet': - return _$nullIfEmptyIterable(_v.dynamicSet)?.toList(); - case 'objectSet': - return _$nullIfEmptyIterable(_v.objectSet)?.toList(); - case 'intSet': - return _$nullIfEmptyIterable(_v.intSet)?.toList(); - case 'dateTimeSet': - return _$nullIfEmptyIterable(_v.dateTimeSet) - ?.map((e) => e?.toIso8601String()) - ?.toList(); - case 'datetime-iterable': - return _$nullIfEmptyIterable(_v.dateTimeIterable) - ?.map((e) => e?.toIso8601String()) - ?.toList(); - case 'list': - return _$nullIfEmptyIterable(_v.list); - case 'dynamicList': - return _$nullIfEmptyIterable(_v.dynamicList); - case 'objectList': - return _$nullIfEmptyIterable(_v.objectList); - case 'intList': - return _$nullIfEmptyIterable(_v.intList); - case 'dateTimeList': - return $wrapListHandleNull( - _$nullIfEmptyIterable(_v.dateTimeList), - (e) => e?.toIso8601String()); - case 'map': - return _$nullIfEmptyMap(_v.map); - case 'stringStringMap': - return _$nullIfEmptyMap(_v.stringStringMap); - case 'dynamicIntMap': - return _$nullIfEmptyMap(_v.dynamicIntMap); - case 'objectDateTimeMap': - return $wrapMapHandleNull( - _$nullIfEmptyMap(_v.objectDateTimeMap), - (e) => e?.toIso8601String()); - case 'crazyComplex': - return $wrapListHandleNull< - Map>>>>( - _$nullIfEmptyIterable(_v.crazyComplex), - (e) => - $wrapMapHandleNull>>>( - e, - (e) => $wrapMapHandleNull>>( - e, - (e) => $wrapListHandleNull>( - e, - (e) => $wrapListHandleNull( - e, (e) => e?.toIso8601String()))))); - case 'val': - return _$nullIfEmptyMap(_v.val); - case 'writeNotNull': - return _v.writeNotNull; - case r'$string': - return _v.string; - case 'simpleObject': - return _v.simpleObject; - case 'strictKeysObject': - return _v.strictKeysObject; - case 'validatedPropertyNo42': - return _v.validatedPropertyNo42; - } - } - return null; - } -} - -T _$nullIfEmptyIterable(T source) => - (source == null || source.isEmpty) ? null : source; - -T _$nullIfEmptyMap(T source) => - (source == null || source.isEmpty) ? null : source; - -JsonConverterTestClass _$JsonConverterTestClassFromJson( - Map json) { - return JsonConverterTestClass() - ..duration = json['duration'] == null - ? null - : durationConverter.fromJson(json['duration'] as int) - ..durationList = (json['durationList'] as List) - ?.map((e) => e == null ? null : durationConverter.fromJson(e as int)) - ?.toList() - ..bigInt = json['bigInt'] == null - ? null - : const BigIntStringConverter().fromJson(json['bigInt'] as String) - ..bigIntMap = (json['bigIntMap'] as Map)?.map( - (k, e) => MapEntry( - k, - e == null - ? null - : const BigIntStringConverter().fromJson(e as String)), - ) - ..numberSilly = json['numberSilly'] == null - ? null - : TrivialNumberConverter.instance.fromJson(json['numberSilly'] as int) - ..numberSillySet = (json['numberSillySet'] as List) - ?.map((e) => e == null - ? null - : TrivialNumberConverter.instance.fromJson(e as int)) - ?.toSet() - ..dateTime = json['dateTime'] == null - ? null - : const EpochDateTimeConverter().fromJson(json['dateTime'] as int); -} - -Map _$JsonConverterTestClassToJson( - JsonConverterTestClass instance) => - _$JsonConverterTestClassJsonMapWrapper(instance); - -class _$JsonConverterTestClassJsonMapWrapper extends $JsonMapWrapper { - final JsonConverterTestClass _v; - _$JsonConverterTestClassJsonMapWrapper(this._v); - - @override - Iterable get keys sync* { - if ((_v.duration == null ? null : durationConverter.toJson(_v.duration)) != - null) { - yield 'duration'; - } - if (_v.durationList?.isNotEmpty ?? false) { - yield 'durationList'; - } - if ((_v.bigInt == null - ? null - : const BigIntStringConverter().toJson(_v.bigInt)) != - null) { - yield 'bigInt'; - } - if (_v.bigIntMap?.isNotEmpty ?? false) { - yield 'bigIntMap'; - } - if ((_v.numberSilly == null - ? null - : TrivialNumberConverter.instance.toJson(_v.numberSilly)) != - null) { - yield 'numberSilly'; - } - if (_v.numberSillySet?.isNotEmpty ?? false) { - yield 'numberSillySet'; - } - if ((_v.dateTime == null - ? null - : const EpochDateTimeConverter().toJson(_v.dateTime)) != - null) { - yield 'dateTime'; - } - } - - @override - dynamic operator [](Object key) { - if (key is String) { - switch (key) { - case 'duration': - return _v.duration == null - ? null - : durationConverter.toJson(_v.duration); - case 'durationList': - return $wrapListHandleNull( - _$nullIfEmptyIterable(_v.durationList), - (e) => e == null ? null : durationConverter.toJson(e)); - case 'bigInt': - return _v.bigInt == null - ? null - : const BigIntStringConverter().toJson(_v.bigInt); - case 'bigIntMap': - return $wrapMapHandleNull( - _$nullIfEmptyMap(_v.bigIntMap), - (e) => - e == null ? null : const BigIntStringConverter().toJson(e)); - case 'numberSilly': - return _v.numberSilly == null - ? null - : TrivialNumberConverter.instance.toJson(_v.numberSilly); - case 'numberSillySet': - return _$nullIfEmptyIterable(_v.numberSillySet) - ?.map((e) => - e == null ? null : TrivialNumberConverter.instance.toJson(e)) - ?.toList(); - case 'dateTime': - return _v.dateTime == null - ? null - : const EpochDateTimeConverter().toJson(_v.dateTime); - } - } - return null; - } -} - -JsonConverterGeneric _$JsonConverterGenericFromJson( - Map json) { - return JsonConverterGeneric() - ..item = json['item'] == null - ? null - : GenericConverter().fromJson(json['item'] as Map) - ..itemList = (json['itemList'] as List) - ?.map((e) => e == null - ? null - : GenericConverter().fromJson(e as Map)) - ?.toList() - ..itemMap = (json['itemMap'] as Map)?.map( - (k, e) => MapEntry( - k, - e == null - ? null - : GenericConverter().fromJson(e as Map)), - ); -} - -Map _$JsonConverterGenericToJson( - JsonConverterGeneric instance) => - _$JsonConverterGenericJsonMapWrapper(instance); - -class _$JsonConverterGenericJsonMapWrapper extends $JsonMapWrapper { - final JsonConverterGeneric _v; - _$JsonConverterGenericJsonMapWrapper(this._v); - - @override - Iterable get keys sync* { - if ((_v.item == null ? null : GenericConverter().toJson(_v.item)) != - null) { - yield 'item'; - } - if (_v.itemList?.isNotEmpty ?? false) { - yield 'itemList'; - } - if (_v.itemMap?.isNotEmpty ?? false) { - yield 'itemMap'; - } - } - - @override - dynamic operator [](Object key) { - if (key is String) { - switch (key) { - case 'item': - return _v.item == null ? null : GenericConverter().toJson(_v.item); - case 'itemList': - return $wrapListHandleNull(_$nullIfEmptyIterable(_v.itemList), - (e) => e == null ? null : GenericConverter().toJson(e)); - case 'itemMap': - return $wrapMapHandleNull(_$nullIfEmptyMap(_v.itemMap), - (e) => e == null ? null : GenericConverter().toJson(e)); - } - } - return null; - } -} diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__use_wrappers.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__use_wrappers.dart deleted file mode 100644 index d41e8da94..000000000 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__use_wrappers.dart +++ /dev/null @@ -1,203 +0,0 @@ -// Copyright (c) 2018, 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. - -// ignore_for_file: annotate_overrides, hash_and_equals -import 'package:json_annotation/json_annotation.dart'; - -import 'json_converters.dart'; -import 'kitchen_sink_interface.dart' as k; -import 'simple_object.dart'; -import 'strict_keys_object.dart'; - -part 'kitchen_sink.g_exclude_null__use_wrappers.g.dart'; - -// NOTE: these methods are replaced in the `non_nullable` cases to return -// non-null values. -List _defaultList() => null; -Set _defaultSet() => null; -Map _defaultMap() => null; -SimpleObject _defaultSimpleObject() => null; -StrictKeysObject _defaultStrictKeysObject() => null; - -const k.KitchenSinkFactory factory = _Factory(); - -class _Factory implements k.KitchenSinkFactory { - const _Factory(); - - String get description => 'exclude_null__use_wrappers'; - bool get anyMap => false; - bool get checked => false; - bool get nullable => true; - bool get excludeNull => true; - bool get explicitToJson => false; - bool get noEncodeEmpty => false; - - k.KitchenSink ctor({ - int ctorValidatedNo42, - Iterable iterable, - Iterable dynamicIterable, - Iterable objectIterable, - Iterable intIterable, - Iterable dateTimeIterable, - }) => - KitchenSink( - ctorValidatedNo42: ctorValidatedNo42, - iterable: iterable, - dynamicIterable: dynamicIterable, - objectIterable: objectIterable, - intIterable: intIterable, - dateTimeIterable: dateTimeIterable, - ); - - k.KitchenSink fromJson(Map json) => - KitchenSink.fromJson(json); - - k.JsonConverterTestClass jsonConverterCtor() => JsonConverterTestClass(); - - k.JsonConverterTestClass jsonConverterFromJson(Map json) => - JsonConverterTestClass.fromJson(json); -} - -@JsonSerializable( - useWrappers: true, - includeIfNull: false, -) -class KitchenSink implements k.KitchenSink { - // NOTE: exposing these as Iterable, but storing the values as List - // to make the equality test work trivially. - final Iterable _iterable; - final Iterable _dynamicIterable; - final Iterable _objectIterable; - final Iterable _intIterable; - final Iterable _dateTimeIterable; - - @JsonKey(name: 'no-42') - final int ctorValidatedNo42; - - KitchenSink({ - this.ctorValidatedNo42, - Iterable iterable, - Iterable dynamicIterable, - Iterable objectIterable, - Iterable intIterable, - Iterable dateTimeIterable, - }) : _iterable = iterable?.toList() ?? _defaultList(), - _dynamicIterable = dynamicIterable?.toList() ?? _defaultList(), - _objectIterable = objectIterable?.toList() ?? _defaultList(), - _intIterable = intIterable?.toList() ?? _defaultList(), - _dateTimeIterable = dateTimeIterable?.toList() ?? _defaultList() { - if (ctorValidatedNo42 == 42) { - throw ArgumentError.value( - 42, 'ctorValidatedNo42', 'The value `42` is not allowed.'); - } - } - - factory KitchenSink.fromJson(Map json) => - _$KitchenSinkFromJson(json); - - Map toJson() => _$KitchenSinkToJson(this); - - DateTime dateTime; - - BigInt bigInt; - - Iterable get iterable => _iterable; - Iterable get dynamicIterable => _dynamicIterable; - Iterable get objectIterable => _objectIterable; - Iterable get intIterable => _intIterable; - - Set set = _defaultSet(); - Set dynamicSet = _defaultSet(); - Set objectSet = _defaultSet(); - Set intSet = _defaultSet(); - Set dateTimeSet = _defaultSet(); - - // Added a one-off annotation on a property (not a field) - @JsonKey(name: 'datetime-iterable') - Iterable get dateTimeIterable => _dateTimeIterable; - - List list = _defaultList(); - List dynamicList = _defaultList(); - List objectList = _defaultList(); - List intList = _defaultList(); - List dateTimeList = _defaultList(); - - Map map = _defaultMap(); - Map stringStringMap = _defaultMap(); - Map dynamicIntMap = _defaultMap(); - Map objectDateTimeMap = _defaultMap(); - - List>>>> crazyComplex = - _defaultList(); - - // Handle fields with names that collide with helper names - Map val = _defaultMap(); - bool writeNotNull; - @JsonKey(name: r'$string') - String string; - - SimpleObject simpleObject = _defaultSimpleObject(); - - StrictKeysObject strictKeysObject = _defaultStrictKeysObject(); - - int _validatedPropertyNo42; - int get validatedPropertyNo42 => _validatedPropertyNo42; - - set validatedPropertyNo42(int value) { - if (value == 42) { - throw StateError('Cannot be 42!'); - } - _validatedPropertyNo42 = value; - } - - bool operator ==(Object other) => k.sinkEquals(this, other); -} - -@JsonSerializable( - useWrappers: true, - includeIfNull: false, -) -// referencing a top-level field should work -@durationConverter -// referencing via a const constructor should work -@BigIntStringConverter() -@TrivialNumberConverter.instance -@EpochDateTimeConverter() -class JsonConverterTestClass implements k.JsonConverterTestClass { - JsonConverterTestClass(); - - factory JsonConverterTestClass.fromJson(Map json) => - _$JsonConverterTestClassFromJson(json); - - Map toJson() => _$JsonConverterTestClassToJson(this); - - Duration duration; - List durationList; - - BigInt bigInt; - Map bigIntMap; - - TrivialNumber numberSilly; - Set numberSillySet; - - DateTime dateTime; -} - -@JsonSerializable( - useWrappers: true, - includeIfNull: false, -) -@GenericConverter() -class JsonConverterGeneric { - S item; - List itemList; - Map itemMap; - - JsonConverterGeneric(); - - factory JsonConverterGeneric.fromJson(Map json) => - _$JsonConverterGenericFromJson(json); - - Map toJson() => _$JsonConverterGenericToJson(this); -} diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__use_wrappers.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__use_wrappers.g.dart deleted file mode 100644 index bb99b4743..000000000 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__use_wrappers.g.dart +++ /dev/null @@ -1,433 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'kitchen_sink.g_exclude_null__use_wrappers.dart'; - -// ************************************************************************** -// JsonSerializableGenerator -// ************************************************************************** - -KitchenSink _$KitchenSinkFromJson(Map json) { - return KitchenSink( - ctorValidatedNo42: json['no-42'] as int, - iterable: json['iterable'] as List, - dynamicIterable: json['dynamicIterable'] as List, - objectIterable: json['objectIterable'] as List, - intIterable: (json['intIterable'] as List)?.map((e) => e as int), - dateTimeIterable: (json['datetime-iterable'] as List) - ?.map((e) => e == null ? null : DateTime.parse(e as String))) - ..dateTime = json['dateTime'] == null - ? null - : DateTime.parse(json['dateTime'] as String) - ..bigInt = - json['bigInt'] == null ? null : BigInt.parse(json['bigInt'] as String) - ..set = (json['set'] as List)?.toSet() - ..dynamicSet = (json['dynamicSet'] as List)?.toSet() - ..objectSet = (json['objectSet'] as List)?.toSet() - ..intSet = (json['intSet'] as List)?.map((e) => e as int)?.toSet() - ..dateTimeSet = (json['dateTimeSet'] as List) - ?.map((e) => e == null ? null : DateTime.parse(e as String)) - ?.toSet() - ..list = json['list'] as List - ..dynamicList = json['dynamicList'] as List - ..objectList = json['objectList'] as List - ..intList = (json['intList'] as List)?.map((e) => e as int)?.toList() - ..dateTimeList = (json['dateTimeList'] as List) - ?.map((e) => e == null ? null : DateTime.parse(e as String)) - ?.toList() - ..map = json['map'] as Map - ..stringStringMap = (json['stringStringMap'] as Map)?.map( - (k, e) => MapEntry(k, e as String), - ) - ..dynamicIntMap = (json['dynamicIntMap'] as Map)?.map( - (k, e) => MapEntry(k, e as int), - ) - ..objectDateTimeMap = - (json['objectDateTimeMap'] as Map)?.map( - (k, e) => MapEntry(k, e == null ? null : DateTime.parse(e as String)), - ) - ..crazyComplex = (json['crazyComplex'] as List) - ?.map((e) => (e as Map)?.map( - (k, e) => MapEntry( - k, - (e as Map)?.map( - (k, e) => MapEntry( - k, - (e as List) - ?.map((e) => (e as List) - ?.map((e) => e == null - ? null - : DateTime.parse(e as String)) - ?.toList()) - ?.toList()), - )), - )) - ?.toList() - ..val = (json['val'] as Map)?.map( - (k, e) => MapEntry(k, e as bool), - ) - ..writeNotNull = json['writeNotNull'] as bool - ..string = json[r'$string'] as String - ..simpleObject = json['simpleObject'] == null - ? null - : SimpleObject.fromJson(json['simpleObject'] as Map) - ..strictKeysObject = json['strictKeysObject'] == null - ? null - : StrictKeysObject.fromJson( - json['strictKeysObject'] as Map) - ..validatedPropertyNo42 = json['validatedPropertyNo42'] as int; -} - -Map _$KitchenSinkToJson(KitchenSink instance) => - _$KitchenSinkJsonMapWrapper(instance); - -class _$KitchenSinkJsonMapWrapper extends $JsonMapWrapper { - final KitchenSink _v; - _$KitchenSinkJsonMapWrapper(this._v); - - @override - Iterable get keys sync* { - if (_v.ctorValidatedNo42 != null) { - yield 'no-42'; - } - if (_v.dateTime != null) { - yield 'dateTime'; - } - if (_v.bigInt != null) { - yield 'bigInt'; - } - if (_v.iterable != null) { - yield 'iterable'; - } - if (_v.dynamicIterable != null) { - yield 'dynamicIterable'; - } - if (_v.objectIterable != null) { - yield 'objectIterable'; - } - if (_v.intIterable != null) { - yield 'intIterable'; - } - if (_v.set != null) { - yield 'set'; - } - if (_v.dynamicSet != null) { - yield 'dynamicSet'; - } - if (_v.objectSet != null) { - yield 'objectSet'; - } - if (_v.intSet != null) { - yield 'intSet'; - } - if (_v.dateTimeSet != null) { - yield 'dateTimeSet'; - } - if (_v.dateTimeIterable != null) { - yield 'datetime-iterable'; - } - if (_v.list != null) { - yield 'list'; - } - if (_v.dynamicList != null) { - yield 'dynamicList'; - } - if (_v.objectList != null) { - yield 'objectList'; - } - if (_v.intList != null) { - yield 'intList'; - } - if (_v.dateTimeList != null) { - yield 'dateTimeList'; - } - if (_v.map != null) { - yield 'map'; - } - if (_v.stringStringMap != null) { - yield 'stringStringMap'; - } - if (_v.dynamicIntMap != null) { - yield 'dynamicIntMap'; - } - if (_v.objectDateTimeMap != null) { - yield 'objectDateTimeMap'; - } - if (_v.crazyComplex != null) { - yield 'crazyComplex'; - } - if (_v.val != null) { - yield 'val'; - } - if (_v.writeNotNull != null) { - yield 'writeNotNull'; - } - if (_v.string != null) { - yield r'$string'; - } - if (_v.simpleObject != null) { - yield 'simpleObject'; - } - if (_v.strictKeysObject != null) { - yield 'strictKeysObject'; - } - if (_v.validatedPropertyNo42 != null) { - yield 'validatedPropertyNo42'; - } - } - - @override - dynamic operator [](Object key) { - if (key is String) { - switch (key) { - case 'no-42': - return _v.ctorValidatedNo42; - case 'dateTime': - return _v.dateTime?.toIso8601String(); - case 'bigInt': - return _v.bigInt?.toString(); - case 'iterable': - return _v.iterable?.toList(); - case 'dynamicIterable': - return _v.dynamicIterable?.toList(); - case 'objectIterable': - return _v.objectIterable?.toList(); - case 'intIterable': - return _v.intIterable?.toList(); - case 'set': - return _v.set?.toList(); - case 'dynamicSet': - return _v.dynamicSet?.toList(); - case 'objectSet': - return _v.objectSet?.toList(); - case 'intSet': - return _v.intSet?.toList(); - case 'dateTimeSet': - return _v.dateTimeSet?.map((e) => e?.toIso8601String())?.toList(); - case 'datetime-iterable': - return _v.dateTimeIterable - ?.map((e) => e?.toIso8601String()) - ?.toList(); - case 'list': - return _v.list; - case 'dynamicList': - return _v.dynamicList; - case 'objectList': - return _v.objectList; - case 'intList': - return _v.intList; - case 'dateTimeList': - return $wrapListHandleNull( - _v.dateTimeList, (e) => e?.toIso8601String()); - case 'map': - return _v.map; - case 'stringStringMap': - return _v.stringStringMap; - case 'dynamicIntMap': - return _v.dynamicIntMap; - case 'objectDateTimeMap': - return $wrapMapHandleNull( - _v.objectDateTimeMap, (e) => e?.toIso8601String()); - case 'crazyComplex': - return $wrapListHandleNull< - Map>>>>( - _v.crazyComplex, - (e) => - $wrapMapHandleNull>>>( - e, - (e) => $wrapMapHandleNull>>( - e, - (e) => $wrapListHandleNull>( - e, - (e) => $wrapListHandleNull( - e, (e) => e?.toIso8601String()))))); - case 'val': - return _v.val; - case 'writeNotNull': - return _v.writeNotNull; - case r'$string': - return _v.string; - case 'simpleObject': - return _v.simpleObject; - case 'strictKeysObject': - return _v.strictKeysObject; - case 'validatedPropertyNo42': - return _v.validatedPropertyNo42; - } - } - return null; - } -} - -JsonConverterTestClass _$JsonConverterTestClassFromJson( - Map json) { - return JsonConverterTestClass() - ..duration = json['duration'] == null - ? null - : durationConverter.fromJson(json['duration'] as int) - ..durationList = (json['durationList'] as List) - ?.map((e) => e == null ? null : durationConverter.fromJson(e as int)) - ?.toList() - ..bigInt = json['bigInt'] == null - ? null - : const BigIntStringConverter().fromJson(json['bigInt'] as String) - ..bigIntMap = (json['bigIntMap'] as Map)?.map( - (k, e) => MapEntry( - k, - e == null - ? null - : const BigIntStringConverter().fromJson(e as String)), - ) - ..numberSilly = json['numberSilly'] == null - ? null - : TrivialNumberConverter.instance.fromJson(json['numberSilly'] as int) - ..numberSillySet = (json['numberSillySet'] as List) - ?.map((e) => e == null - ? null - : TrivialNumberConverter.instance.fromJson(e as int)) - ?.toSet() - ..dateTime = json['dateTime'] == null - ? null - : const EpochDateTimeConverter().fromJson(json['dateTime'] as int); -} - -Map _$JsonConverterTestClassToJson( - JsonConverterTestClass instance) => - _$JsonConverterTestClassJsonMapWrapper(instance); - -class _$JsonConverterTestClassJsonMapWrapper extends $JsonMapWrapper { - final JsonConverterTestClass _v; - _$JsonConverterTestClassJsonMapWrapper(this._v); - - @override - Iterable get keys sync* { - if ((_v.duration == null ? null : durationConverter.toJson(_v.duration)) != - null) { - yield 'duration'; - } - if (_v.durationList != null) { - yield 'durationList'; - } - if ((_v.bigInt == null - ? null - : const BigIntStringConverter().toJson(_v.bigInt)) != - null) { - yield 'bigInt'; - } - if (_v.bigIntMap != null) { - yield 'bigIntMap'; - } - if ((_v.numberSilly == null - ? null - : TrivialNumberConverter.instance.toJson(_v.numberSilly)) != - null) { - yield 'numberSilly'; - } - if (_v.numberSillySet != null) { - yield 'numberSillySet'; - } - if ((_v.dateTime == null - ? null - : const EpochDateTimeConverter().toJson(_v.dateTime)) != - null) { - yield 'dateTime'; - } - } - - @override - dynamic operator [](Object key) { - if (key is String) { - switch (key) { - case 'duration': - return _v.duration == null - ? null - : durationConverter.toJson(_v.duration); - case 'durationList': - return $wrapListHandleNull(_v.durationList, - (e) => e == null ? null : durationConverter.toJson(e)); - case 'bigInt': - return _v.bigInt == null - ? null - : const BigIntStringConverter().toJson(_v.bigInt); - case 'bigIntMap': - return $wrapMapHandleNull( - _v.bigIntMap, - (e) => - e == null ? null : const BigIntStringConverter().toJson(e)); - case 'numberSilly': - return _v.numberSilly == null - ? null - : TrivialNumberConverter.instance.toJson(_v.numberSilly); - case 'numberSillySet': - return _v.numberSillySet - ?.map((e) => - e == null ? null : TrivialNumberConverter.instance.toJson(e)) - ?.toList(); - case 'dateTime': - return _v.dateTime == null - ? null - : const EpochDateTimeConverter().toJson(_v.dateTime); - } - } - return null; - } -} - -JsonConverterGeneric _$JsonConverterGenericFromJson( - Map json) { - return JsonConverterGeneric() - ..item = json['item'] == null - ? null - : GenericConverter().fromJson(json['item'] as Map) - ..itemList = (json['itemList'] as List) - ?.map((e) => e == null - ? null - : GenericConverter().fromJson(e as Map)) - ?.toList() - ..itemMap = (json['itemMap'] as Map)?.map( - (k, e) => MapEntry( - k, - e == null - ? null - : GenericConverter().fromJson(e as Map)), - ); -} - -Map _$JsonConverterGenericToJson( - JsonConverterGeneric instance) => - _$JsonConverterGenericJsonMapWrapper(instance); - -class _$JsonConverterGenericJsonMapWrapper extends $JsonMapWrapper { - final JsonConverterGeneric _v; - _$JsonConverterGenericJsonMapWrapper(this._v); - - @override - Iterable get keys sync* { - if ((_v.item == null ? null : GenericConverter().toJson(_v.item)) != - null) { - yield 'item'; - } - if (_v.itemList != null) { - yield 'itemList'; - } - if (_v.itemMap != null) { - yield 'itemMap'; - } - } - - @override - dynamic operator [](Object key) { - if (key is String) { - switch (key) { - case 'item': - return _v.item == null ? null : GenericConverter().toJson(_v.item); - case 'itemList': - return $wrapListHandleNull(_v.itemList, - (e) => e == null ? null : GenericConverter().toJson(e)); - case 'itemMap': - return $wrapMapHandleNull(_v.itemMap, - (e) => e == null ? null : GenericConverter().toJson(e)); - } - } - return null; - } -} diff --git a/json_serializable/test/shared_config.dart b/json_serializable/test/shared_config.dart index e6dca2dd3..74be513a6 100644 --- a/json_serializable/test/shared_config.dart +++ b/json_serializable/test/shared_config.dart @@ -22,5 +22,4 @@ final generatorConfigNonDefaultJson = generateToJsonFunction: false, includeIfNull: false, nullable: false, - useWrappers: true, ).toJson()); diff --git a/json_serializable/test/src/generic_test_input.dart b/json_serializable/test/src/generic_test_input.dart index 13df8eb3a..c12fcbc04 100644 --- a/json_serializable/test/src/generic_test_input.dart +++ b/json_serializable/test/src/generic_test_input.dart @@ -50,56 +50,6 @@ GenericClass _$GenericClassFromJson( ..fieldS = json['fieldS'] == null ? null : _dataFromJson(json['fieldS']); } -Map _$GenericClassToJson( - GenericClass instance) => - _$GenericClassJsonMapWrapper(instance); - -class _$GenericClassJsonMapWrapper extends $JsonMapWrapper { - final GenericClass _v; - _$GenericClassJsonMapWrapper(this._v); - - @override - Iterable get keys => - const ['fieldObject', 'fieldDynamic', 'fieldInt', 'fieldT', 'fieldS']; - - @override - dynamic operator [](Object key) { - if (key is String) { - switch (key) { - case 'fieldObject': - return _v.fieldObject == null ? null : _dataToJson(_v.fieldObject); - case 'fieldDynamic': - return _v.fieldDynamic == null ? null : _dataToJson(_v.fieldDynamic); - case 'fieldInt': - return _v.fieldInt == null ? null : _dataToJson(_v.fieldInt); - case 'fieldT': - return _v.fieldT == null ? null : _dataToJson(_v.fieldT); - case 'fieldS': - return _v.fieldS == null ? null : _dataToJson(_v.fieldS); - } - } - return null; - } -} -''', - configurations: ['wrapped'], -) -@ShouldGenerate( - r''' -GenericClass _$GenericClassFromJson( - Map json) { - return GenericClass() - ..fieldObject = - json['fieldObject'] == null ? null : _dataFromJson(json['fieldObject']) - ..fieldDynamic = json['fieldDynamic'] == null - ? null - : _dataFromJson(json['fieldDynamic']) - ..fieldInt = - json['fieldInt'] == null ? null : _dataFromJson(json['fieldInt']) - ..fieldT = json['fieldT'] == null ? null : _dataFromJson(json['fieldT']) - ..fieldS = json['fieldS'] == null ? null : _dataFromJson(json['fieldS']); -} - abstract class _$GenericClassSerializerMixin { Object get fieldObject; dynamic get fieldDynamic; diff --git a/json_serializable/test/src/inheritance_test_input.dart b/json_serializable/test/src/inheritance_test_input.dart index 92a60e36a..4dd9553ae 100644 --- a/json_serializable/test/src/inheritance_test_input.dart +++ b/json_serializable/test/src/inheritance_test_input.dart @@ -28,52 +28,6 @@ Map _$SubTypeToJson(SubType instance) { ''', configurations: ['default'], ) -@ShouldGenerate( - r''' -SubType _$SubTypeFromJson(Map json) { - return SubType( - json['subTypeViaCtor'] as int, json['super-final-field'] as int) - ..superReadWriteField = json['superReadWriteField'] as int - ..subTypeReadWrite = json['subTypeReadWrite'] as int; -} - -Map _$SubTypeToJson(SubType instance) => - _$SubTypeJsonMapWrapper(instance); - -class _$SubTypeJsonMapWrapper extends $JsonMapWrapper { - final SubType _v; - _$SubTypeJsonMapWrapper(this._v); - - @override - Iterable get keys sync* { - yield 'super-final-field'; - if (_v.superReadWriteField != null) { - yield 'superReadWriteField'; - } - yield 'subTypeViaCtor'; - yield 'subTypeReadWrite'; - } - - @override - dynamic operator [](Object key) { - if (key is String) { - switch (key) { - case 'super-final-field': - return _v.superFinalField; - case 'superReadWriteField': - return _v.superReadWriteField; - case 'subTypeViaCtor': - return _v.subTypeViaCtor; - case 'subTypeReadWrite': - return _v.subTypeReadWrite; - } - } - return null; - } -} -''', - configurations: ['wrapped'], -) @JsonSerializable() class SubType extends SuperType { final int subTypeViaCtor; diff --git a/json_serializable/test/src/to_from_json_test_input.dart b/json_serializable/test/src/to_from_json_test_input.dart index c381bf7ac..7c34e8b00 100644 --- a/json_serializable/test/src/to_from_json_test_input.dart +++ b/json_serializable/test/src/to_from_json_test_input.dart @@ -142,81 +142,6 @@ class ToJsonNullableFalseIncludeIfNullFalse { String field; } -@ShouldGenerate( - r''' -Map _$ToJsonNullableFalseIncludeIfNullFalseWrappedToJson( - ToJsonNullableFalseIncludeIfNullFalseWrapped instance) => - _$ToJsonNullableFalseIncludeIfNullFalseWrappedJsonMapWrapper(instance); - -class _$ToJsonNullableFalseIncludeIfNullFalseWrappedJsonMapWrapper - extends $JsonMapWrapper { - final ToJsonNullableFalseIncludeIfNullFalseWrapped _v; - _$ToJsonNullableFalseIncludeIfNullFalseWrappedJsonMapWrapper(this._v); - - @override - Iterable get keys sync* { - if (_toString(_v.field) != null) { - yield 'field'; - } - } - - @override - dynamic operator [](Object key) { - if (key is String) { - switch (key) { - case 'field': - return _toString(_v.field); - } - } - return null; - } -} -''', - configurations: ['wrapped'], -) -@JsonSerializable(createFactory: false) -class ToJsonNullableFalseIncludeIfNullFalseWrapped { - @JsonKey(toJson: _toString, includeIfNull: false, nullable: false) - String field; -} - -@ShouldGenerate( - r''' -Map _$ToJsonIncludeIfNullFalseWrappedToJson( - ToJsonIncludeIfNullFalseWrapped instance) => - _$ToJsonIncludeIfNullFalseWrappedJsonMapWrapper(instance); - -class _$ToJsonIncludeIfNullFalseWrappedJsonMapWrapper extends $JsonMapWrapper { - final ToJsonIncludeIfNullFalseWrapped _v; - _$ToJsonIncludeIfNullFalseWrappedJsonMapWrapper(this._v); - - @override - Iterable get keys sync* { - if ((_v.field == null ? null : _toString(_v.field)) != null) { - yield 'field'; - } - } - - @override - dynamic operator [](Object key) { - if (key is String) { - switch (key) { - case 'field': - return _v.field == null ? null : _toString(_v.field); - } - } - return null; - } -} -''', - configurations: ['wrapped'], -) -@JsonSerializable(createFactory: false) -class ToJsonIncludeIfNullFalseWrapped { - @JsonKey(toJson: _toString, includeIfNull: false) - String field; -} - String _fromDynamicMap(Map input) => null; String _fromDynamicList(List input) => null; diff --git a/json_serializable/test/src/unknown_type_test_input.dart b/json_serializable/test/src/unknown_type_test_input.dart index cb98f7e3e..ad51b289c 100644 --- a/json_serializable/test/src/unknown_type_test_input.dart +++ b/json_serializable/test/src/unknown_type_test_input.dart @@ -59,39 +59,6 @@ UnknownFieldTypeWithConvert _$UnknownFieldTypeWithConvertFromJson( ..number = json['number'] == null ? null : _everythingIs42(json['number']); } -Map _$UnknownFieldTypeWithConvertToJson( - UnknownFieldTypeWithConvert instance) => - _$UnknownFieldTypeWithConvertJsonMapWrapper(instance); - -class _$UnknownFieldTypeWithConvertJsonMapWrapper extends $JsonMapWrapper { - final UnknownFieldTypeWithConvert _v; - _$UnknownFieldTypeWithConvertJsonMapWrapper(this._v); - - @override - Iterable get keys => const ['number']; - - @override - dynamic operator [](Object key) { - if (key is String) { - switch (key) { - case 'number': - return _v.number == null ? null : _everythingIs42(_v.number); - } - } - return null; - } -} -''', - configurations: ['wrapped'], -) -@ShouldGenerate( - r''' -UnknownFieldTypeWithConvert _$UnknownFieldTypeWithConvertFromJson( - Map json) { - return UnknownFieldTypeWithConvert() - ..number = json['number'] == null ? null : _everythingIs42(json['number']); -} - Map _$UnknownFieldTypeWithConvertToJson( UnknownFieldTypeWithConvert instance) => { diff --git a/json_serializable/test/test_sources/test_sources.dart b/json_serializable/test/test_sources/test_sources.dart index 9582bd6a6..27e43394a 100644 --- a/json_serializable/test/test_sources/test_sources.dart +++ b/json_serializable/test/test_sources/test_sources.dart @@ -17,7 +17,6 @@ class ConfigurationImplicitDefaults { generateToJsonFunction: true, includeIfNull: true, nullable: true, - useWrappers: false, ) class ConfigurationExplicitDefaults { int field; diff --git a/json_serializable/tool/test_builder.dart b/json_serializable/tool/test_builder.dart index 1db780ce0..ee0b41afb 100644 --- a/json_serializable/tool/test_builder.dart +++ b/json_serializable/tool/test_builder.dart @@ -113,7 +113,6 @@ const _configReplacements = { 'any_map': _Replacement.addJsonSerializableKey('anyMap', true), 'checked': _Replacement.addJsonSerializableKey('checked', true), 'non_nullable': _Replacement.addJsonSerializableKey('nullable', false), - 'use_wrappers': _Replacement.addJsonSerializableKey('useWrappers', true), 'explicit_to_json': _Replacement.addJsonSerializableKey('explicitToJson', true), 'exclude_null': _Replacement.addJsonSerializableKey('includeIfNull', false), @@ -230,29 +229,22 @@ const _kitchenSinkBaseName = 'kitchen_sink'; const _fileConfigurationMap = >>{ _kitchenSinkBaseName: { {'any_map', 'checked', 'non_nullable'}, - {'any_map', 'non_nullable', 'use_wrappers'}, {'any_map', 'non_nullable'}, {'any_map'}, {'no_encode_empty'}, - {'no_encode_empty', 'exclude_null', 'use_wrappers'}, - {'no_encode_empty', 'non_nullable'}, {'no_encode_empty', 'exclude_null'}, - {'no_encode_empty', 'exclude_null', 'non_nullable', 'use_wrappers'}, + {'no_encode_empty', 'non_nullable'}, + {'no_encode_empty', 'exclude_null', 'non_nullable'}, {'exclude_null', 'non_nullable'}, - {'exclude_null', 'use_wrappers'}, {'exclude_null'}, {'explicit_to_json'}, }, 'default_value': { {'any_map', 'checked'}, }, - 'generic_class': { - {'use_wrappers'}, - }, + 'generic_class': >{}, 'json_test_example': { - {'non_nullable', 'use_wrappers'}, {'non_nullable'}, - {'use_wrappers'}, } }; From 8ce520b2032c3695b38c620af1e4c6c5cd278451 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 10 Apr 2019 14:25:12 -0700 Subject: [PATCH 135/569] Remove generateToJsonFunction Fixes https://github.com/dart-lang/json_serializable/issues/444 --- json_annotation/CHANGELOG.md | 1 + .../lib/src/json_serializable.dart | 51 +------------------ .../lib/src/json_serializable.g.dart | 5 -- json_serializable/CHANGELOG.md | 1 + json_serializable/README.md | 3 -- json_serializable/doc/doc.md | 2 - json_serializable/lib/src/encoder_helper.dart | 42 ++------------- json_serializable/lib/src/utils.dart | 4 -- json_serializable/test/config_test.dart | 1 - .../test/json_serializable_test.dart | 7 --- .../test/kitchen_sink/simple_object.dart | 7 +-- .../test/kitchen_sink/simple_object.g.dart | 6 +-- .../test/kitchen_sink/strict_keys_object.dart | 9 ++-- .../kitchen_sink/strict_keys_object.g.dart | 11 ++-- json_serializable/test/shared_config.dart | 1 - .../src/_json_serializable_test_input.dart | 38 -------------- .../test/src/generic_test_input.dart | 33 ------------ .../test/test_sources/test_sources.dart | 1 - 18 files changed, 23 insertions(+), 200 deletions(-) diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index ce94329f3..9294132a8 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -2,6 +2,7 @@ - **BREAKING** Removed `JsonSerializable.useWrappers` and associated `$`-prefixed helpers. +- **BREAKING** Removed `JsonSerializable.generateToJsonFunction`. ## 2.3.0 diff --git a/json_annotation/lib/src/json_serializable.dart b/json_annotation/lib/src/json_serializable.dart index 52e6630c9..8d12a08d7 100644 --- a/json_annotation/lib/src/json_serializable.dart +++ b/json_annotation/lib/src/json_serializable.dart @@ -62,12 +62,8 @@ class JsonSerializable { /// ``` final bool createFactory; - /// If `true` (the default), code for encoding JSON is generated for this - /// class. - /// - /// If `json_serializable` is configured with - /// `generate_to_json_function: true` (the default), a top-level function is - /// created that you can reference from your class. + /// If `true` (the default), A top-level function is created that you can + /// reference from your class. /// /// ```dart /// @JsonSerializable() @@ -75,19 +71,6 @@ class JsonSerializable { /// Map toJson() => _$ExampleToJson(this); /// } /// ``` - /// - /// If `json_serializable` is configured with - /// `generate_to_json_function: false`, a private `_$ClassNameMixin` class is - /// created in the generated part file which contains a `toJson` method. - /// - /// Mix in this class to the source class: - /// - /// ```dart - /// @JsonSerializable() - /// class Example extends Object with _$ExampleSerializerMixin { - /// // ... - /// } - /// ``` final bool createToJson; /// If `false` (the default), then the generated `FromJson` function will @@ -144,32 +127,6 @@ class JsonSerializable { /// fields annotated with [JsonKey]. final FieldRename fieldRename; - /// Controls how `toJson` functionality is generated for all types processed - /// by this generator. - /// - /// If `true` (the default), a top-level function is created. - /// - /// ```dart - /// @JsonSerializable() - /// class Example { - /// // ... - /// Map toJson() => _$ExampleToJson(this); - /// } - /// ``` - /// - /// If `false`, a private `_$ClassNameSerializerMixin` class is - /// created in the generated part file which contains a `toJson` method. - /// - /// Mix in this class to the source class: - /// - /// ```dart - /// @JsonSerializable() - /// class Example extends Object with _$ExampleSerializerMixin { - /// // ... - /// } - /// ``` - final bool generateToJsonFunction; - /// Whether the generator should include fields with `null` values in the /// serialized output. /// @@ -200,7 +157,6 @@ class JsonSerializable { this.encodeEmptyCollection, this.explicitToJson, this.fieldRename, - this.generateToJsonFunction, this.includeIfNull, this.nullable, }); @@ -219,7 +175,6 @@ class JsonSerializable { encodeEmptyCollection: true, explicitToJson: false, fieldRename: FieldRename.none, - generateToJsonFunction: true, includeIfNull: true, nullable: true, ); @@ -240,8 +195,6 @@ class JsonSerializable { encodeEmptyCollection ?? defaults.encodeEmptyCollection, explicitToJson: explicitToJson ?? defaults.explicitToJson, fieldRename: fieldRename ?? defaults.fieldRename, - generateToJsonFunction: - generateToJsonFunction ?? defaults.generateToJsonFunction, includeIfNull: includeIfNull ?? defaults.includeIfNull, nullable: nullable ?? defaults.nullable); diff --git a/json_annotation/lib/src/json_serializable.g.dart b/json_annotation/lib/src/json_serializable.g.dart index 5cf57e2e0..6e2fcf245 100644 --- a/json_annotation/lib/src/json_serializable.g.dart +++ b/json_annotation/lib/src/json_serializable.g.dart @@ -17,7 +17,6 @@ JsonSerializable _$JsonSerializableFromJson(Map json) { 'encode_empty_collection', 'explicit_to_json', 'field_rename', - 'generate_to_json_function', 'include_if_null', 'nullable', ]); @@ -35,8 +34,6 @@ JsonSerializable _$JsonSerializableFromJson(Map json) { $checkedConvert(json, 'explicit_to_json', (v) => v as bool), fieldRename: $checkedConvert(json, 'field_rename', (v) => _$enumDecodeNullable(_$FieldRenameEnumMap, v)), - generateToJsonFunction: $checkedConvert( - json, 'generate_to_json_function', (v) => v as bool), includeIfNull: $checkedConvert(json, 'include_if_null', (v) => v as bool), nullable: $checkedConvert(json, 'nullable', (v) => v as bool)); @@ -49,7 +46,6 @@ JsonSerializable _$JsonSerializableFromJson(Map json) { 'encodeEmptyCollection': 'encode_empty_collection', 'explicitToJson': 'explicit_to_json', 'fieldRename': 'field_rename', - 'generateToJsonFunction': 'generate_to_json_function', 'includeIfNull': 'include_if_null', }); } @@ -64,7 +60,6 @@ Map _$JsonSerializableToJson(JsonSerializable instance) => 'encode_empty_collection': instance.encodeEmptyCollection, 'explicit_to_json': instance.explicitToJson, 'field_rename': _$FieldRenameEnumMap[instance.fieldRename], - 'generate_to_json_function': instance.generateToJsonFunction, 'include_if_null': instance.includeIfNull, 'nullable': instance.nullable, }; diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index c841fe221..f4a4d9efe 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,6 +1,7 @@ ## 3.0.0 - **BREAKING** Removed support for `JsonSerializable.useWrappers`. +- **BREAKING** Removed support for `JsonSerializable.generateToJsonFunction`. ## 2.3.0 diff --git a/json_serializable/README.md b/json_serializable/README.md index 649368382..1df577a7f 100644 --- a/json_serializable/README.md +++ b/json_serializable/README.md @@ -78,7 +78,6 @@ is generated: | disallow_unrecognized_keys | [JsonSerializable.disallowUnrecognizedKeys] | | | explicit_to_json | [JsonSerializable.explicitToJson] | | | field_rename | [JsonSerializable.fieldRename] | | -| generate_to_json_function | [JsonSerializable.generateToJsonFunction] | | | encode_empty_collection | [JsonSerializable.encodeEmptyCollection] | [JsonKey.encodeEmptyCollection] | | include_if_null | [JsonSerializable.includeIfNull] | [JsonKey.includeIfNull] | | nullable | [JsonSerializable.nullable] | [JsonKey.nullable] | @@ -97,7 +96,6 @@ is generated: [JsonSerializable.disallowUnrecognizedKeys]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html [JsonSerializable.explicitToJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/explicitToJson.html [JsonSerializable.fieldRename]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/fieldRename.html -[JsonSerializable.generateToJsonFunction]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/generateToJsonFunction.html [JsonSerializable.encodeEmptyCollection]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/encodeEmptyCollection.html [JsonKey.encodeEmptyCollection]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/encodeEmptyCollection.html [JsonSerializable.includeIfNull]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/includeIfNull.html @@ -146,7 +144,6 @@ targets: encode_empty_collection: true explicit_to_json: false field_rename: none - generate_to_json_function: true include_if_null: true nullable: true ``` diff --git a/json_serializable/doc/doc.md b/json_serializable/doc/doc.md index b8bd2a6ce..639e94a04 100644 --- a/json_serializable/doc/doc.md +++ b/json_serializable/doc/doc.md @@ -7,7 +7,6 @@ | disallow_unrecognized_keys | [JsonSerializable.disallowUnrecognizedKeys] | | | explicit_to_json | [JsonSerializable.explicitToJson] | | | field_rename | [JsonSerializable.fieldRename] | | -| generate_to_json_function | [JsonSerializable.generateToJsonFunction] | | | encode_empty_collection | [JsonSerializable.encodeEmptyCollection] | [JsonKey.encodeEmptyCollection] | | include_if_null | [JsonSerializable.includeIfNull] | [JsonKey.includeIfNull] | | nullable | [JsonSerializable.nullable] | [JsonKey.nullable] | @@ -26,7 +25,6 @@ [JsonSerializable.disallowUnrecognizedKeys]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html [JsonSerializable.explicitToJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/explicitToJson.html [JsonSerializable.fieldRename]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/fieldRename.html -[JsonSerializable.generateToJsonFunction]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/generateToJsonFunction.html [JsonSerializable.encodeEmptyCollection]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/encodeEmptyCollection.html [JsonKey.encodeEmptyCollection]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/encodeEmptyCollection.html [JsonSerializable.includeIfNull]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/includeIfNull.html diff --git a/json_serializable/lib/src/encoder_helper.dart b/json_serializable/lib/src/encoder_helper.dart index 33b9ebddf..ff3ad60c3 100644 --- a/json_serializable/lib/src/encoder_helper.dart +++ b/json_serializable/lib/src/encoder_helper.dart @@ -11,41 +11,16 @@ import 'type_helper.dart'; import 'type_helpers/json_converter_helper.dart'; abstract class EncodeHelper implements HelperCore { - String _fieldAccess(FieldElement field) { - var fieldAccess = field.name; - if (config.generateToJsonFunction) { - fieldAccess = '$_toJsonParamName.$fieldAccess'; - } - return fieldAccess; - } - - String _mixinClassName(bool withConstraints) => - '${prefix}SerializerMixin${genericClassArgumentsImpl(withConstraints)}'; + String _fieldAccess(FieldElement field) => '$_toJsonParamName.${field.name}'; Iterable createToJson(Set accessibleFields) sync* { assert(config.createToJson); final buffer = StringBuffer(); - if (config.generateToJsonFunction) { - final functionName = '${prefix}ToJson${genericClassArgumentsImpl(true)}'; - buffer.write('Map $functionName' - '($targetClassReference $_toJsonParamName) '); - } else { - // - // Generate the mixin class - // - buffer.writeln('abstract class ${_mixinClassName(true)} {'); - - // write copies of the fields - this allows the toJson method to access - // the fields of the target class - for (final field in accessibleFields) { - //TODO - handle aliased imports - buffer.writeln(' ${field.type} get ${field.name};'); - } - - buffer.write(' Map toJson() '); - } + final functionName = '${prefix}ToJson${genericClassArgumentsImpl(true)}'; + buffer.write('Map $functionName' + '($targetClassReference $_toJsonParamName) '); final writeNaive = accessibleFields.every(_writeJsonValueNaive); @@ -57,11 +32,6 @@ abstract class EncodeHelper implements HelperCore { _writeToJsonWithNullChecks(buffer, accessibleFields); } - if (!config.generateToJsonFunction) { - // end of the mixin class - buffer.writeln('}'); - } - yield buffer.toString(); } @@ -82,8 +52,6 @@ abstract class EncodeHelper implements HelperCore { buffer.writeln('};'); } - /// Name of the parameter used when generating top-level `toJson` functions - /// if [JsonSerializable.generateToJsonFunction] is `true`. static const _toJsonParamName = 'instance'; void _writeToJsonWithNullChecks( @@ -106,8 +74,6 @@ abstract class EncodeHelper implements HelperCore { // access with `this.`. if (safeFieldAccess == generatedLocalVarName || safeFieldAccess == toJsonMapHelperName) { - assert(!config.generateToJsonFunction, - 'This code path should only be hit during the mixin codepath.'); safeFieldAccess = 'this.$safeFieldAccess'; } diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index cbcde6f32..7153fd85a 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -81,8 +81,6 @@ JsonSerializable _valueForAnnotation(ConstantReader reader) => JsonSerializable( reader.read('encodeEmptyCollection').literalValue as bool, explicitToJson: reader.read('explicitToJson').literalValue as bool, fieldRename: _fromDartObject(reader.read('fieldRename')), - generateToJsonFunction: - reader.read('generateToJsonFunction').literalValue as bool, includeIfNull: reader.read('includeIfNull').literalValue as bool, nullable: reader.read('nullable').literalValue as bool, ); @@ -106,8 +104,6 @@ JsonSerializable mergeConfig(JsonSerializable config, ConstantReader reader) { annotation.encodeEmptyCollection ?? config.encodeEmptyCollection, explicitToJson: annotation.explicitToJson ?? config.explicitToJson, fieldRename: annotation.fieldRename ?? config.fieldRename, - generateToJsonFunction: - annotation.generateToJsonFunction ?? config.generateToJsonFunction, includeIfNull: annotation.includeIfNull ?? config.includeIfNull, nullable: annotation.nullable ?? config.nullable, ); diff --git a/json_serializable/test/config_test.dart b/json_serializable/test/config_test.dart index a4249accd..a95570a1f 100644 --- a/json_serializable/test/config_test.dart +++ b/json_serializable/test/config_test.dart @@ -138,7 +138,6 @@ const _invalidConfig = { 'encode_empty_collection': 42, 'explicit_to_json': 42, 'field_rename': 42, - 'generate_to_json_function': 42, 'include_if_null': 42, 'nullable': 42, }; diff --git a/json_serializable/test/json_serializable_test.dart b/json_serializable/test/json_serializable_test.dart index 22207c9e3..1299bfdaa 100644 --- a/json_serializable/test/json_serializable_test.dart +++ b/json_serializable/test/json_serializable_test.dart @@ -3,7 +3,6 @@ // BSD-style license that can be found in the LICENSE file. @TestOn('vm') -import 'package:json_annotation/json_annotation.dart'; import 'package:json_serializable/json_serializable.dart'; import 'package:path/path.dart' as p; import 'package:source_gen_test/source_gen_test.dart'; @@ -19,10 +18,6 @@ void main() async { testAnnotatedElements( reader, const JsonSerializableGenerator(), - additionalGenerators: const { - 'mixin': JsonSerializableGenerator( - config: JsonSerializable(generateToJsonFunction: false)), - }, expectedAnnotatedTests: _expectedAnnotatedTests, ); } @@ -58,10 +53,8 @@ const _expectedAnnotatedTests = [ 'FinalFieldsNotSetInCtor', 'FromDynamicCollection', 'GeneralTestClass1', - 'GeneralTestClass1', 'GeneralTestClass2', 'GenericClass', - 'GenericClass', 'IgnoredFieldClass', 'IgnoredFieldCtorClass', 'IncludeIfNullDisallowNullClass', diff --git a/json_serializable/test/kitchen_sink/simple_object.dart b/json_serializable/test/kitchen_sink/simple_object.dart index dfa5ea6d5..c02cefc31 100644 --- a/json_serializable/test/kitchen_sink/simple_object.dart +++ b/json_serializable/test/kitchen_sink/simple_object.dart @@ -6,12 +6,13 @@ import 'package:json_annotation/json_annotation.dart'; part 'simple_object.g.dart'; -@JsonSerializable(anyMap: true, generateToJsonFunction: false) -class SimpleObject extends Object with _$SimpleObjectSerializerMixin { - @override +@JsonSerializable(anyMap: true) +class SimpleObject { final int value; SimpleObject(this.value); factory SimpleObject.fromJson(Map json) => _$SimpleObjectFromJson(json); + + Map toJson() => _$SimpleObjectToJson(this); } diff --git a/json_serializable/test/kitchen_sink/simple_object.g.dart b/json_serializable/test/kitchen_sink/simple_object.g.dart index 9f0fd0225..55136e42b 100644 --- a/json_serializable/test/kitchen_sink/simple_object.g.dart +++ b/json_serializable/test/kitchen_sink/simple_object.g.dart @@ -10,7 +10,5 @@ SimpleObject _$SimpleObjectFromJson(Map json) { return SimpleObject(json['value'] as int); } -abstract class _$SimpleObjectSerializerMixin { - int get value; - Map toJson() => {'value': value}; -} +Map _$SimpleObjectToJson(SimpleObject instance) => + {'value': instance.value}; diff --git a/json_serializable/test/kitchen_sink/strict_keys_object.dart b/json_serializable/test/kitchen_sink/strict_keys_object.dart index 4b72e942a..757f3eb5c 100644 --- a/json_serializable/test/kitchen_sink/strict_keys_object.dart +++ b/json_serializable/test/kitchen_sink/strict_keys_object.dart @@ -6,14 +6,11 @@ import 'package:json_annotation/json_annotation.dart'; part 'strict_keys_object.g.dart'; -@JsonSerializable( - disallowUnrecognizedKeys: true, anyMap: true, generateToJsonFunction: false) -class StrictKeysObject extends Object with _$StrictKeysObjectSerializerMixin { - @override +@JsonSerializable(disallowUnrecognizedKeys: true, anyMap: true) +class StrictKeysObject { @JsonKey(required: true) final int value; - @override @JsonKey(name: 'custom_field', required: true) final String customField; @@ -21,4 +18,6 @@ class StrictKeysObject extends Object with _$StrictKeysObjectSerializerMixin { factory StrictKeysObject.fromJson(Map json) => _$StrictKeysObjectFromJson(json); + + Map toJson() => _$StrictKeysObjectToJson(this); } diff --git a/json_serializable/test/kitchen_sink/strict_keys_object.g.dart b/json_serializable/test/kitchen_sink/strict_keys_object.g.dart index 964d90b51..a41271690 100644 --- a/json_serializable/test/kitchen_sink/strict_keys_object.g.dart +++ b/json_serializable/test/kitchen_sink/strict_keys_object.g.dart @@ -13,9 +13,8 @@ StrictKeysObject _$StrictKeysObjectFromJson(Map json) { return StrictKeysObject(json['value'] as int, json['custom_field'] as String); } -abstract class _$StrictKeysObjectSerializerMixin { - int get value; - String get customField; - Map toJson() => - {'value': value, 'custom_field': customField}; -} +Map _$StrictKeysObjectToJson(StrictKeysObject instance) => + { + 'value': instance.value, + 'custom_field': instance.customField + }; diff --git a/json_serializable/test/shared_config.dart b/json_serializable/test/shared_config.dart index 74be513a6..e9e1500ba 100644 --- a/json_serializable/test/shared_config.dart +++ b/json_serializable/test/shared_config.dart @@ -19,7 +19,6 @@ final generatorConfigNonDefaultJson = encodeEmptyCollection: false, explicitToJson: true, fieldRename: FieldRename.kebab, - generateToJsonFunction: false, includeIfNull: false, nullable: false, ).toJson()); diff --git a/json_serializable/test/src/_json_serializable_test_input.dart b/json_serializable/test/src/_json_serializable_test_input.dart index 570275900..d92e91632 100644 --- a/json_serializable/test/src/_json_serializable_test_input.dart +++ b/json_serializable/test/src/_json_serializable_test_input.dart @@ -83,43 +83,6 @@ Map _$GeneralTestClass1ToJson(GeneralTestClass1 instance) => 'listOfInts': instance.listOfInts }; ''', - configurations: ['default'], -) -@ShouldGenerate( - r''' -GeneralTestClass1 _$GeneralTestClass1FromJson(Map json) { - return GeneralTestClass1() - ..firstName = json['firstName'] as String - ..lastName = json['lastName'] as String - ..height = json['h'] as int - ..dateOfBirth = json['dateOfBirth'] == null - ? null - : DateTime.parse(json['dateOfBirth'] as String) - ..dynamicType = json['dynamicType'] - ..varType = json['varType'] - ..listOfInts = (json['listOfInts'] as List)?.map((e) => e as int)?.toList(); -} - -abstract class _$GeneralTestClass1SerializerMixin { - String get firstName; - String get lastName; - int get height; - DateTime get dateOfBirth; - dynamic get dynamicType; - dynamic get varType; - List get listOfInts; - Map toJson() => { - 'firstName': firstName, - 'lastName': lastName, - 'h': height, - 'dateOfBirth': dateOfBirth?.toIso8601String(), - 'dynamicType': dynamicType, - 'varType': varType, - 'listOfInts': listOfInts - }; -} -''', - configurations: ['mixin'], ) @JsonSerializable() class GeneralTestClass1 { @@ -152,7 +115,6 @@ Map _$GeneralTestClass2ToJson(GeneralTestClass2 instance) => 'dateOfBirth': instance.dateOfBirth?.toIso8601String() }; ''', - configurations: ['default'], ) @JsonSerializable() class GeneralTestClass2 { diff --git a/json_serializable/test/src/generic_test_input.dart b/json_serializable/test/src/generic_test_input.dart index c12fcbc04..0c9c372f7 100644 --- a/json_serializable/test/src/generic_test_input.dart +++ b/json_serializable/test/src/generic_test_input.dart @@ -34,39 +34,6 @@ Map _$GenericClassToJson( 'fieldS': instance.fieldS == null ? null : _dataToJson(instance.fieldS) }; ''') -@ShouldGenerate( - r''' -GenericClass _$GenericClassFromJson( - Map json) { - return GenericClass() - ..fieldObject = - json['fieldObject'] == null ? null : _dataFromJson(json['fieldObject']) - ..fieldDynamic = json['fieldDynamic'] == null - ? null - : _dataFromJson(json['fieldDynamic']) - ..fieldInt = - json['fieldInt'] == null ? null : _dataFromJson(json['fieldInt']) - ..fieldT = json['fieldT'] == null ? null : _dataFromJson(json['fieldT']) - ..fieldS = json['fieldS'] == null ? null : _dataFromJson(json['fieldS']); -} - -abstract class _$GenericClassSerializerMixin { - Object get fieldObject; - dynamic get fieldDynamic; - int get fieldInt; - T get fieldT; - S get fieldS; - Map toJson() => { - 'fieldObject': fieldObject == null ? null : _dataToJson(fieldObject), - 'fieldDynamic': fieldDynamic == null ? null : _dataToJson(fieldDynamic), - 'fieldInt': fieldInt == null ? null : _dataToJson(fieldInt), - 'fieldT': fieldT == null ? null : _dataToJson(fieldT), - 'fieldS': fieldS == null ? null : _dataToJson(fieldS) - }; -} -''', - configurations: ['mixin'], -) @JsonSerializable() class GenericClass { @JsonKey(fromJson: _dataFromJson, toJson: _dataToJson) diff --git a/json_serializable/test/test_sources/test_sources.dart b/json_serializable/test/test_sources/test_sources.dart index 27e43394a..53f332423 100644 --- a/json_serializable/test/test_sources/test_sources.dart +++ b/json_serializable/test/test_sources/test_sources.dart @@ -14,7 +14,6 @@ class ConfigurationImplicitDefaults { encodeEmptyCollection: true, explicitToJson: false, fieldRename: FieldRename.none, - generateToJsonFunction: true, includeIfNull: true, nullable: true, ) From 0c5f606f4c252282e8471e9e763e60e003930aa3 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Fri, 10 May 2019 16:45:37 -0700 Subject: [PATCH 136/569] Update fall-through case (#481) --- json_serializable/lib/src/json_key_utils.dart | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/json_serializable/lib/src/json_key_utils.dart b/json_serializable/lib/src/json_key_utils.dart index 1b952a178..d78842016 100644 --- a/json_serializable/lib/src/json_key_utils.dart +++ b/json_serializable/lib/src/json_key_utils.dart @@ -184,8 +184,7 @@ String _encodedFieldName(JsonSerializable classAnnotation, switch (classAnnotation.fieldRename) { case FieldRename.none: - // noop - break; + return fieldElement.name; case FieldRename.snake: return snakeCase(fieldElement.name); case FieldRename.kebab: @@ -194,7 +193,12 @@ String _encodedFieldName(JsonSerializable classAnnotation, return pascalCase(fieldElement.name); } - return fieldElement.name; + throw ArgumentError.value( + classAnnotation, + 'classAnnotation', + 'The provided `fieldRename` (${classAnnotation.fieldRename}) is not ' + 'supported.', + ); } bool _includeIfNull( From d7e6612cf947e150710007a63b439f8f0c316d42 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Fri, 10 May 2019 16:46:01 -0700 Subject: [PATCH 137/569] remove encode_empty_collection (#482) Fixes https://github.com/dart-lang/json_serializable/issues/446 --- json_annotation/CHANGELOG.md | 2 + json_annotation/lib/src/json_key.dart | 22 -- .../lib/src/json_serializable.dart | 19 -- .../lib/src/json_serializable.g.dart | 5 - json_serializable/CHANGELOG.md | 1 + json_serializable/README.md | 40 ++- json_serializable/build.yaml | 4 - json_serializable/doc/doc.md | 39 ++- json_serializable/lib/src/encoder_helper.dart | 4 +- json_serializable/lib/src/json_key_utils.dart | 37 --- json_serializable/lib/src/type_helper.dart | 21 -- .../lib/src/type_helper_ctx.dart | 22 +- .../lib/src/type_helpers/iterable_helper.dart | 15 +- .../lib/src/type_helpers/map_helper.dart | 14 +- json_serializable/lib/src/utils.dart | 4 - json_serializable/test/config_test.dart | 1 - .../test/json_serializable_test.dart | 4 - .../test/kitchen_sink/kitchen_sink.dart | 1 - .../kitchen_sink/kitchen_sink.factories.dart | 13 +- .../kitchen_sink/kitchen_sink.g_any_map.dart | 1 - ...sink.g_any_map__checked__non_nullable.dart | 1 - .../kitchen_sink.g_any_map__non_nullable.dart | 1 - .../kitchen_sink.g_exclude_null.dart | 1 - ..._sink.g_exclude_null__no_encode_empty.dart | 203 ------------- ...ink.g_exclude_null__no_encode_empty.g.dart | 283 ------------------ ...e_null__no_encode_empty__non_nullable.dart | 206 ------------- ...null__no_encode_empty__non_nullable.g.dart | 233 -------------- ...hen_sink.g_exclude_null__non_nullable.dart | 1 - .../kitchen_sink.g_explicit_to_json.dart | 1 - .../kitchen_sink.g_no_encode_empty.dart | 200 ------------- .../kitchen_sink.g_no_encode_empty.g.dart | 276 ----------------- ....dart => kitchen_sink.g_non_nullable.dart} | 8 +- ...art => kitchen_sink.g_non_nullable.g.dart} | 186 ++++-------- .../kitchen_sink/kitchen_sink_interface.dart | 1 - .../test/kitchen_sink/kitchen_sink_test.dart | 114 +++---- json_serializable/test/shared_config.dart | 1 - .../src/_json_serializable_test_input.dart | 87 ------ .../test/test_sources/test_sources.dart | 1 - json_serializable/test/test_utils.dart | 10 +- json_serializable/tool/test_builder.dart | 15 +- 40 files changed, 161 insertions(+), 1937 deletions(-) delete mode 100644 json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty.dart delete mode 100644 json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty.g.dart delete mode 100644 json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty__non_nullable.dart delete mode 100644 json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty__non_nullable.g.dart delete mode 100644 json_serializable/test/kitchen_sink/kitchen_sink.g_no_encode_empty.dart delete mode 100644 json_serializable/test/kitchen_sink/kitchen_sink.g_no_encode_empty.g.dart rename json_serializable/test/kitchen_sink/{kitchen_sink.g_no_encode_empty__non_nullable.dart => kitchen_sink.g_non_nullable.dart} (96%) rename json_serializable/test/kitchen_sink/{kitchen_sink.g_no_encode_empty__non_nullable.g.dart => kitchen_sink.g_non_nullable.g.dart} (50%) diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index 9294132a8..037fadba5 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -3,6 +3,8 @@ - **BREAKING** Removed `JsonSerializable.useWrappers` and associated `$`-prefixed helpers. - **BREAKING** Removed `JsonSerializable.generateToJsonFunction`. +- **BREAKING** Removed `encodeEmptyCollection` from `JsonSerializable` and + `JsonKey`. ## 2.3.0 diff --git a/json_annotation/lib/src/json_key.dart b/json_annotation/lib/src/json_key.dart index 62a77175b..7d468a32b 100644 --- a/json_annotation/lib/src/json_key.dart +++ b/json_annotation/lib/src/json_key.dart @@ -24,27 +24,6 @@ class JsonKey { /// same field, an exception will be thrown during code generation. final bool disallowNullValue; - /// Whether the generator should include the annotated field value in the - /// serialized output if it is empty. - /// - /// If `true` (the default), empty values are included in the generated - /// `toJson` function. - /// - /// If `false`, fields with empty collections are omitted from `toJson`. - /// - /// Note: setting this property to `false` overrides the [includeIfNull] - /// value to `false` as well. Explicitly setting [includeIfNull] to `true` - /// and setting this property to `false` will cause an error at build time. - /// - /// Note: setting this property to `false` on a non-collection field - /// (of types other than [Iterable], [Set], [List], and [Map]) - /// will cause an error at build time. - /// - /// The default value, `null`, indicates that the behavior should be - /// acquired from the [JsonSerializable.encodeEmptyCollection] annotation on - /// the enclosing class. - final bool encodeEmptyCollection; - /// A [Function] to use when decoding the associated JSON value to the /// annotated field. /// @@ -124,7 +103,6 @@ class JsonKey { const JsonKey({ this.defaultValue, this.disallowNullValue, - this.encodeEmptyCollection, this.fromJson, this.ignore, this.includeIfNull, diff --git a/json_annotation/lib/src/json_serializable.dart b/json_annotation/lib/src/json_serializable.dart index 8d12a08d7..95361e114 100644 --- a/json_annotation/lib/src/json_serializable.dart +++ b/json_annotation/lib/src/json_serializable.dart @@ -80,21 +80,6 @@ class JsonSerializable { /// be thrown. final bool disallowUnrecognizedKeys; - /// Whether the generator should include empty collection field values in the - /// serialized output. - /// - /// If `true` (the default), empty collection fields - /// (of type [Iterable], [Set], [List], and [Map]) - /// are included in generated `toJson` functions. - /// - /// If `false`, fields with empty collections are omitted from `toJson`. - /// - /// Note: setting this property to `false` overrides the [includeIfNull] - /// value to `false` as well. - /// - /// Note: non-collection fields are not affected by this value. - final bool encodeEmptyCollection; - /// If `true`, generated `toJson` methods will explicitly call `toJson` on /// nested objects. /// @@ -154,7 +139,6 @@ class JsonSerializable { this.createFactory, this.createToJson, this.disallowUnrecognizedKeys, - this.encodeEmptyCollection, this.explicitToJson, this.fieldRename, this.includeIfNull, @@ -172,7 +156,6 @@ class JsonSerializable { createFactory: true, createToJson: true, disallowUnrecognizedKeys: false, - encodeEmptyCollection: true, explicitToJson: false, fieldRename: FieldRename.none, includeIfNull: true, @@ -191,8 +174,6 @@ class JsonSerializable { createToJson: createToJson ?? defaults.createToJson, disallowUnrecognizedKeys: disallowUnrecognizedKeys ?? defaults.disallowUnrecognizedKeys, - encodeEmptyCollection: - encodeEmptyCollection ?? defaults.encodeEmptyCollection, explicitToJson: explicitToJson ?? defaults.explicitToJson, fieldRename: fieldRename ?? defaults.fieldRename, includeIfNull: includeIfNull ?? defaults.includeIfNull, diff --git a/json_annotation/lib/src/json_serializable.g.dart b/json_annotation/lib/src/json_serializable.g.dart index 6e2fcf245..795201b50 100644 --- a/json_annotation/lib/src/json_serializable.g.dart +++ b/json_annotation/lib/src/json_serializable.g.dart @@ -14,7 +14,6 @@ JsonSerializable _$JsonSerializableFromJson(Map json) { 'create_factory', 'create_to_json', 'disallow_unrecognized_keys', - 'encode_empty_collection', 'explicit_to_json', 'field_rename', 'include_if_null', @@ -28,8 +27,6 @@ JsonSerializable _$JsonSerializableFromJson(Map json) { createToJson: $checkedConvert(json, 'create_to_json', (v) => v as bool), disallowUnrecognizedKeys: $checkedConvert( json, 'disallow_unrecognized_keys', (v) => v as bool), - encodeEmptyCollection: - $checkedConvert(json, 'encode_empty_collection', (v) => v as bool), explicitToJson: $checkedConvert(json, 'explicit_to_json', (v) => v as bool), fieldRename: $checkedConvert(json, 'field_rename', @@ -43,7 +40,6 @@ JsonSerializable _$JsonSerializableFromJson(Map json) { 'createFactory': 'create_factory', 'createToJson': 'create_to_json', 'disallowUnrecognizedKeys': 'disallow_unrecognized_keys', - 'encodeEmptyCollection': 'encode_empty_collection', 'explicitToJson': 'explicit_to_json', 'fieldRename': 'field_rename', 'includeIfNull': 'include_if_null', @@ -57,7 +53,6 @@ Map _$JsonSerializableToJson(JsonSerializable instance) => 'create_factory': instance.createFactory, 'create_to_json': instance.createToJson, 'disallow_unrecognized_keys': instance.disallowUnrecognizedKeys, - 'encode_empty_collection': instance.encodeEmptyCollection, 'explicit_to_json': instance.explicitToJson, 'field_rename': _$FieldRenameEnumMap[instance.fieldRename], 'include_if_null': instance.includeIfNull, diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index f4a4d9efe..24db63ad0 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -2,6 +2,7 @@ - **BREAKING** Removed support for `JsonSerializable.useWrappers`. - **BREAKING** Removed support for `JsonSerializable.generateToJsonFunction`. +- **BREAKING** Removed support for `encodeEmptyCollection`. ## 2.3.0 diff --git a/json_serializable/README.md b/json_serializable/README.md index 1df577a7f..c152c80a9 100644 --- a/json_serializable/README.md +++ b/json_serializable/README.md @@ -69,25 +69,24 @@ is generated: 2. Add a `@JsonKey` annotation to a field and set properties there. 3. Add configuration to `build.yaml` – [see below](#build-configuration). -| `build.yaml` key | JsonSerializable | JsonKey | -| -------------------------- | ------------------------------------------- | ------------------------------- | -| any_map | [JsonSerializable.anyMap] | | -| checked | [JsonSerializable.checked] | | -| create_factory | [JsonSerializable.createFactory] | | -| create_to_json | [JsonSerializable.createToJson] | | -| disallow_unrecognized_keys | [JsonSerializable.disallowUnrecognizedKeys] | | -| explicit_to_json | [JsonSerializable.explicitToJson] | | -| field_rename | [JsonSerializable.fieldRename] | | -| encode_empty_collection | [JsonSerializable.encodeEmptyCollection] | [JsonKey.encodeEmptyCollection] | -| include_if_null | [JsonSerializable.includeIfNull] | [JsonKey.includeIfNull] | -| nullable | [JsonSerializable.nullable] | [JsonKey.nullable] | -| | | [JsonKey.defaultValue] | -| | | [JsonKey.disallowNullValue] | -| | | [JsonKey.fromJson] | -| | | [JsonKey.ignore] | -| | | [JsonKey.name] | -| | | [JsonKey.required] | -| | | [JsonKey.toJson] | +| `build.yaml` key | JsonSerializable | JsonKey | +| -------------------------- | ------------------------------------------- | --------------------------- | +| any_map | [JsonSerializable.anyMap] | | +| checked | [JsonSerializable.checked] | | +| create_factory | [JsonSerializable.createFactory] | | +| create_to_json | [JsonSerializable.createToJson] | | +| disallow_unrecognized_keys | [JsonSerializable.disallowUnrecognizedKeys] | | +| explicit_to_json | [JsonSerializable.explicitToJson] | | +| field_rename | [JsonSerializable.fieldRename] | | +| include_if_null | [JsonSerializable.includeIfNull] | [JsonKey.includeIfNull] | +| nullable | [JsonSerializable.nullable] | [JsonKey.nullable] | +| | | [JsonKey.defaultValue] | +| | | [JsonKey.disallowNullValue] | +| | | [JsonKey.fromJson] | +| | | [JsonKey.ignore] | +| | | [JsonKey.name] | +| | | [JsonKey.required] | +| | | [JsonKey.toJson] | [JsonSerializable.anyMap]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/anyMap.html [JsonSerializable.checked]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/checked.html @@ -96,8 +95,6 @@ is generated: [JsonSerializable.disallowUnrecognizedKeys]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html [JsonSerializable.explicitToJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/explicitToJson.html [JsonSerializable.fieldRename]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/fieldRename.html -[JsonSerializable.encodeEmptyCollection]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/encodeEmptyCollection.html -[JsonKey.encodeEmptyCollection]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/encodeEmptyCollection.html [JsonSerializable.includeIfNull]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/includeIfNull.html [JsonKey.includeIfNull]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/includeIfNull.html [JsonSerializable.nullable]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/nullable.html @@ -141,7 +138,6 @@ targets: create_factory: true create_to_json: true disallow_unrecognized_keys: false - encode_empty_collection: true explicit_to_json: false field_rename: none include_if_null: true diff --git a/json_serializable/build.yaml b/json_serializable/build.yaml index 0e367f3b1..20f6b4dbb 100644 --- a/json_serializable/build.yaml +++ b/json_serializable/build.yaml @@ -39,12 +39,8 @@ builders: - .g_any_map__checked__non_nullable.dart - .g_any_map__non_nullable.dart - .g_exclude_null.dart - - .g_exclude_null__no_encode_empty.dart - - .g_exclude_null__no_encode_empty__non_nullable.dart - .g_exclude_null__non_nullable.dart - .g_explicit_to_json.dart - - .g_no_encode_empty.dart - - .g_no_encode_empty__non_nullable.dart - .g_non_nullable.dart build_to: source runs_before: ["json_serializable"] diff --git a/json_serializable/doc/doc.md b/json_serializable/doc/doc.md index 639e94a04..acba5502f 100644 --- a/json_serializable/doc/doc.md +++ b/json_serializable/doc/doc.md @@ -1,22 +1,21 @@ -| `build.yaml` key | JsonSerializable | JsonKey | -| -------------------------- | ------------------------------------------- | ------------------------------- | -| any_map | [JsonSerializable.anyMap] | | -| checked | [JsonSerializable.checked] | | -| create_factory | [JsonSerializable.createFactory] | | -| create_to_json | [JsonSerializable.createToJson] | | -| disallow_unrecognized_keys | [JsonSerializable.disallowUnrecognizedKeys] | | -| explicit_to_json | [JsonSerializable.explicitToJson] | | -| field_rename | [JsonSerializable.fieldRename] | | -| encode_empty_collection | [JsonSerializable.encodeEmptyCollection] | [JsonKey.encodeEmptyCollection] | -| include_if_null | [JsonSerializable.includeIfNull] | [JsonKey.includeIfNull] | -| nullable | [JsonSerializable.nullable] | [JsonKey.nullable] | -| | | [JsonKey.defaultValue] | -| | | [JsonKey.disallowNullValue] | -| | | [JsonKey.fromJson] | -| | | [JsonKey.ignore] | -| | | [JsonKey.name] | -| | | [JsonKey.required] | -| | | [JsonKey.toJson] | +| `build.yaml` key | JsonSerializable | JsonKey | +| -------------------------- | ------------------------------------------- | --------------------------- | +| any_map | [JsonSerializable.anyMap] | | +| checked | [JsonSerializable.checked] | | +| create_factory | [JsonSerializable.createFactory] | | +| create_to_json | [JsonSerializable.createToJson] | | +| disallow_unrecognized_keys | [JsonSerializable.disallowUnrecognizedKeys] | | +| explicit_to_json | [JsonSerializable.explicitToJson] | | +| field_rename | [JsonSerializable.fieldRename] | | +| include_if_null | [JsonSerializable.includeIfNull] | [JsonKey.includeIfNull] | +| nullable | [JsonSerializable.nullable] | [JsonKey.nullable] | +| | | [JsonKey.defaultValue] | +| | | [JsonKey.disallowNullValue] | +| | | [JsonKey.fromJson] | +| | | [JsonKey.ignore] | +| | | [JsonKey.name] | +| | | [JsonKey.required] | +| | | [JsonKey.toJson] | [JsonSerializable.anyMap]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/anyMap.html [JsonSerializable.checked]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/checked.html @@ -25,8 +24,6 @@ [JsonSerializable.disallowUnrecognizedKeys]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html [JsonSerializable.explicitToJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/explicitToJson.html [JsonSerializable.fieldRename]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/fieldRename.html -[JsonSerializable.encodeEmptyCollection]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/encodeEmptyCollection.html -[JsonKey.encodeEmptyCollection]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/encodeEmptyCollection.html [JsonSerializable.includeIfNull]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/includeIfNull.html [JsonKey.includeIfNull]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/includeIfNull.html [JsonSerializable.nullable]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/nullable.html diff --git a/json_serializable/lib/src/encoder_helper.dart b/json_serializable/lib/src/encoder_helper.dart index ff3ad60c3..ada4be389 100644 --- a/json_serializable/lib/src/encoder_helper.dart +++ b/json_serializable/lib/src/encoder_helper.dart @@ -130,9 +130,7 @@ abstract class EncodeHelper implements HelperCore { return true; } - if (!jsonKey.nullable && - jsonKey.encodeEmptyCollection && - !_fieldHasCustomEncoder(field)) { + if (!jsonKey.nullable && !_fieldHasCustomEncoder(field)) { return true; } diff --git a/json_serializable/lib/src/json_key_utils.dart b/json_serializable/lib/src/json_key_utils.dart index d78842016..9f14444ed 100644 --- a/json_serializable/lib/src/json_key_utils.dart +++ b/json_serializable/lib/src/json_key_utils.dart @@ -9,7 +9,6 @@ import 'package:json_annotation/json_annotation.dart'; import 'package:source_gen/source_gen.dart'; import 'json_literal_generator.dart'; -import 'shared_checkers.dart'; import 'utils.dart'; final _jsonKeyExpando = Expando(); @@ -100,7 +99,6 @@ JsonKey _from(FieldElement element, JsonSerializable classAnnotation) { element, defaultValue: defaultValueLiteral, disallowNullValue: obj.getField('disallowNullValue').toBoolValue(), - encodeEmptyCollection: obj.getField('encodeEmptyCollection').toBoolValue(), ignore: obj.getField('ignore').toBoolValue(), includeIfNull: obj.getField('includeIfNull').toBoolValue(), name: obj.getField('name').toStringValue(), @@ -109,9 +107,6 @@ JsonKey _from(FieldElement element, JsonSerializable classAnnotation) { ); } -const _iterableOrMapChecker = - TypeChecker.any([coreIterableTypeChecker, coreMapTypeChecker]); - JsonKey _populateJsonKey( JsonSerializable classAnnotation, FieldElement element, { @@ -122,7 +117,6 @@ JsonKey _populateJsonKey( String name, bool nullable, bool required, - bool encodeEmptyCollection, }) { if (disallowNullValue == true) { if (includeIfNull == true) { @@ -133,36 +127,6 @@ JsonKey _populateJsonKey( } } - if (encodeEmptyCollection == null) { - // If set on the class, but not set on the field – set the key to false - // iif the type is compatible. - if (_iterableOrMapChecker.isAssignableFromType(element.type) && - !classAnnotation.encodeEmptyCollection) { - encodeEmptyCollection = false; - } else { - encodeEmptyCollection = true; - } - } else if (encodeEmptyCollection == false && - !_iterableOrMapChecker.isAssignableFromType(element.type)) { - // If explicitly set of the field, throw an error if the type is not a - // compatible type. - throwUnsupported( - element, - '`encodeEmptyCollection: false` is only valid fields of type ' - 'Iterable, List, Set, or Map.', - ); - } - - if (!encodeEmptyCollection) { - if (includeIfNull == true) { - throwUnsupported( - element, - 'Cannot set `encodeEmptyCollection: false` if `includeIfNull: true`.', - ); - } - includeIfNull = false; - } - return JsonKey( defaultValue: defaultValue, disallowNullValue: disallowNullValue ?? false, @@ -172,7 +136,6 @@ JsonKey _populateJsonKey( name: _encodedFieldName(classAnnotation, name, element), nullable: nullable ?? classAnnotation.nullable, required: required ?? false, - encodeEmptyCollection: encodeEmptyCollection, ); } diff --git a/json_serializable/lib/src/type_helper.dart b/json_serializable/lib/src/type_helper.dart index e83d054de..d38c1b2e3 100644 --- a/json_serializable/lib/src/type_helper.dart +++ b/json_serializable/lib/src/type_helper.dart @@ -30,17 +30,6 @@ abstract class TypeHelperContext { void addMember(String memberContent); } -abstract class TypeHelperContextWithEmptyCollectionLogic - extends TypeHelperContext { - /// Returns `true` if `this` is being used in the first (or "root") invocation - /// of a [TypeHelper.serialize] or [TypeHelper.deserialize] call. - bool get skipEncodingEmptyCollection; - - static bool isSkipEncodingEmptyCollection(TypeHelperContext context) => - context is TypeHelperContextWithEmptyCollectionLogic && - context.skipEncodingEmptyCollection; -} - /// Extended context information with includes configuration values /// corresponding to `JsonSerializableGenerator` settings. abstract class TypeHelperContextWithConfig extends TypeHelperContext { @@ -121,13 +110,3 @@ Object commonNullPrefix( nullable ? '$expression == null ? null : $unsafeExpression' : unsafeExpression; - -/// Returns `true` if [context] represents a field where -/// `encodeEmptyCollection` is `false` and the caller is running on the -/// "root" value and not for a nested type. -/// -/// This ensures we don't add wrapper functions for the nested lists within -/// `Map`, for instance. -bool encodeEmptyAsNullRoot(TypeHelperContext context) => - TypeHelperContextWithEmptyCollectionLogic.isSkipEncodingEmptyCollection( - context); diff --git a/json_serializable/lib/src/type_helper_ctx.dart b/json_serializable/lib/src/type_helper_ctx.dart index d8fd6b1db..6f6465b46 100644 --- a/json_serializable/lib/src/type_helper_ctx.dart +++ b/json_serializable/lib/src/type_helper_ctx.dart @@ -17,10 +17,7 @@ TypeHelperCtx typeHelperContext( TypeHelperCtx._(helperCore, fieldElement, key); class TypeHelperCtx - implements - TypeHelperContextWithConfig, - TypeHelperContextWithConvert, - TypeHelperContextWithEmptyCollectionLogic { + implements TypeHelperContextWithConfig, TypeHelperContextWithConvert { final HelperCore _helperCore; final JsonKey _key; @@ -64,23 +61,10 @@ class TypeHelperCtx (TypeHelper th) => th.deserialize(targetType, expression, this)); Object _run(DartType targetType, String expression, - Object invoke(TypeHelper instance)) { - _depth++; - - try { - return _helperCore.allTypeHelpers.map(invoke).firstWhere((r) => r != null, + Object invoke(TypeHelper instance)) => + _helperCore.allTypeHelpers.map(invoke).firstWhere((r) => r != null, orElse: () => throw UnsupportedTypeError( targetType, expression, _notSupportedWithTypeHelpersMsg)); - } finally { - _depth--; - } - } - - int _depth = 0; - - @override - bool get skipEncodingEmptyCollection => - !_key.encodeEmptyCollection && _depth == 1; } final _notSupportedWithTypeHelpersMsg = diff --git a/json_serializable/lib/src/type_helpers/iterable_helper.dart b/json_serializable/lib/src/type_helpers/iterable_helper.dart index e47ef6e4e..8ee8a68eb 100644 --- a/json_serializable/lib/src/type_helpers/iterable_helper.dart +++ b/json_serializable/lib/src/type_helpers/iterable_helper.dart @@ -9,12 +9,6 @@ import '../constants.dart'; import '../shared_checkers.dart'; import '../type_helper.dart'; -const _helperFunctionDefinition = - '''T $_helperName(T source) => - (source == null || source.isEmpty) ? null : source;'''; - -const _helperName = r'_$nullIfEmptyIterable'; - class IterableHelper extends TypeHelper { const IterableHelper(); @@ -33,14 +27,7 @@ class IterableHelper extends TypeHelper { var isList = _coreListChecker.isAssignableFromType(targetType); final subField = context.serialize(itemType, closureArg); - final contextNullable = context.nullable || encodeEmptyAsNullRoot(context); - - final optionalQuestion = contextNullable ? '?' : ''; - - if (encodeEmptyAsNullRoot(context)) { - context.addMember(_helperFunctionDefinition); - expression = '$_helperName($expression)'; - } + final optionalQuestion = context.nullable ? '?' : ''; // In the case of trivial JSON types (int, String, etc), `subField` // will be identical to `substitute` – so no explicit mapping is needed. diff --git a/json_serializable/lib/src/type_helpers/map_helper.dart b/json_serializable/lib/src/type_helpers/map_helper.dart index 7ab946948..d3a88d6e8 100644 --- a/json_serializable/lib/src/type_helpers/map_helper.dart +++ b/json_serializable/lib/src/type_helpers/map_helper.dart @@ -11,11 +11,6 @@ import '../utils.dart'; const _keyParam = 'k'; -const _helperFunctionDefinition = '''T $_helperName(T source) => - (source == null || source.isEmpty) ? null : source;'''; - -const _helperName = r'_$nullIfEmptyMap'; - class MapHelper extends TypeHelper { const MapHelper(); @@ -36,18 +31,11 @@ class MapHelper extends TypeHelper { final subFieldValue = context.serialize(valueType, closureArg); final subKeyValue = context.serialize(keyType, _keyParam); - final contextNullable = context.nullable || encodeEmptyAsNullRoot(context); - - if (encodeEmptyAsNullRoot(context)) { - context.addMember(_helperFunctionDefinition); - expression = '$_helperName($expression)'; - } - if (closureArg == subFieldValue && _keyParam == subKeyValue) { return expression; } - final optionalQuestion = contextNullable ? '?' : ''; + final optionalQuestion = context.nullable ? '?' : ''; return '$expression$optionalQuestion' '.map(($_keyParam, $closureArg) => MapEntry($subKeyValue, $subFieldValue))'; diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index 7153fd85a..4f36f0d23 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -77,8 +77,6 @@ JsonSerializable _valueForAnnotation(ConstantReader reader) => JsonSerializable( createToJson: reader.read('createToJson').literalValue as bool, disallowUnrecognizedKeys: reader.read('disallowUnrecognizedKeys').literalValue as bool, - encodeEmptyCollection: - reader.read('encodeEmptyCollection').literalValue as bool, explicitToJson: reader.read('explicitToJson').literalValue as bool, fieldRename: _fromDartObject(reader.read('fieldRename')), includeIfNull: reader.read('includeIfNull').literalValue as bool, @@ -100,8 +98,6 @@ JsonSerializable mergeConfig(JsonSerializable config, ConstantReader reader) { createToJson: annotation.createToJson ?? config.createToJson, disallowUnrecognizedKeys: annotation.disallowUnrecognizedKeys ?? config.disallowUnrecognizedKeys, - encodeEmptyCollection: - annotation.encodeEmptyCollection ?? config.encodeEmptyCollection, explicitToJson: annotation.explicitToJson ?? config.explicitToJson, fieldRename: annotation.fieldRename ?? config.fieldRename, includeIfNull: annotation.includeIfNull ?? config.includeIfNull, diff --git a/json_serializable/test/config_test.dart b/json_serializable/test/config_test.dart index a95570a1f..34ddbff99 100644 --- a/json_serializable/test/config_test.dart +++ b/json_serializable/test/config_test.dart @@ -135,7 +135,6 @@ const _invalidConfig = { 'create_factory': 42, 'create_to_json': 42, 'disallow_unrecognized_keys': 42, - 'encode_empty_collection': 42, 'explicit_to_json': 42, 'field_rename': 42, 'include_if_null': 42, diff --git a/json_serializable/test/json_serializable_test.dart b/json_serializable/test/json_serializable_test.dart index 1299bfdaa..312212682 100644 --- a/json_serializable/test/json_serializable_test.dart +++ b/json_serializable/test/json_serializable_test.dart @@ -40,10 +40,6 @@ const _expectedAnnotatedTests = [ 'DefaultWithType', 'DupeKeys', 'DynamicConvertMethods', - 'EmptyCollectionAsNullAndIncludeIfNullClass', - 'EmptyCollectionAsNullAndIncludeIfNullField', - 'EncodeEmptyCollectionAsNullOnField', - 'EncodeEmptyCollectionAsNullOnNonCollectionField', 'FieldNamerKebab', 'FieldNamerNone', 'FieldNamerPascal', diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.dart b/json_serializable/test/kitchen_sink/kitchen_sink.dart index 5be9abdb0..aeaa57dde 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.dart @@ -31,7 +31,6 @@ class _Factory implements k.KitchenSinkFactory { bool get nullable => true; bool get excludeNull => false; bool get explicitToJson => false; - bool get noEncodeEmpty => false; k.KitchenSink ctor({ int ctorValidatedNo42, diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.factories.dart b/json_serializable/test/kitchen_sink/kitchen_sink.factories.dart index 4ee2f1413..8248cdc8a 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.factories.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.factories.dart @@ -4,16 +4,10 @@ import 'kitchen_sink.g_any_map__checked__non_nullable.dart' as any_map__checked__non_nullable; import 'kitchen_sink.g_any_map__non_nullable.dart' as any_map__non_nullable; import 'kitchen_sink.g_exclude_null.dart' as exclude_null; -import 'kitchen_sink.g_exclude_null__no_encode_empty.dart' - as exclude_null__no_encode_empty; -import 'kitchen_sink.g_exclude_null__no_encode_empty__non_nullable.dart' - as exclude_null__no_encode_empty__non_nullable; import 'kitchen_sink.g_exclude_null__non_nullable.dart' as exclude_null__non_nullable; import 'kitchen_sink.g_explicit_to_json.dart' as explicit_to_json; -import 'kitchen_sink.g_no_encode_empty.dart' as no_encode_empty; -import 'kitchen_sink.g_no_encode_empty__non_nullable.dart' - as no_encode_empty__non_nullable; +import 'kitchen_sink.g_non_nullable.dart' as non_nullable; const factories = [ normal.factory, @@ -21,10 +15,7 @@ const factories = [ any_map__checked__non_nullable.factory, any_map__non_nullable.factory, exclude_null.factory, - exclude_null__no_encode_empty.factory, - exclude_null__no_encode_empty__non_nullable.factory, exclude_null__non_nullable.factory, explicit_to_json.factory, - no_encode_empty.factory, - no_encode_empty__non_nullable.factory, + non_nullable.factory, ]; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart index 4da12315d..b68578374 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart @@ -31,7 +31,6 @@ class _Factory implements k.KitchenSinkFactory { bool get nullable => true; bool get excludeNull => false; bool get explicitToJson => false; - bool get noEncodeEmpty => false; k.KitchenSink ctor({ int ctorValidatedNo42, diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked__non_nullable.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked__non_nullable.dart index 3fc6dfcba..dedc28fd4 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked__non_nullable.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked__non_nullable.dart @@ -31,7 +31,6 @@ class _Factory implements k.KitchenSinkFactory { bool get nullable => false; bool get excludeNull => false; bool get explicitToJson => false; - bool get noEncodeEmpty => false; k.KitchenSink ctor({ int ctorValidatedNo42, diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable.dart index 7bccbf450..7185c5243 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable.dart @@ -31,7 +31,6 @@ class _Factory implements k.KitchenSinkFactory { bool get nullable => false; bool get excludeNull => false; bool get explicitToJson => false; - bool get noEncodeEmpty => false; k.KitchenSink ctor({ int ctorValidatedNo42, diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.dart index 41c2400a6..27cedf69b 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.dart @@ -31,7 +31,6 @@ class _Factory implements k.KitchenSinkFactory { bool get nullable => true; bool get excludeNull => true; bool get explicitToJson => false; - bool get noEncodeEmpty => false; k.KitchenSink ctor({ int ctorValidatedNo42, diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty.dart deleted file mode 100644 index 7d2599600..000000000 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty.dart +++ /dev/null @@ -1,203 +0,0 @@ -// Copyright (c) 2018, 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. - -// ignore_for_file: annotate_overrides, hash_and_equals -import 'package:json_annotation/json_annotation.dart'; - -import 'json_converters.dart'; -import 'kitchen_sink_interface.dart' as k; -import 'simple_object.dart'; -import 'strict_keys_object.dart'; - -part 'kitchen_sink.g_exclude_null__no_encode_empty.g.dart'; - -// NOTE: these methods are replaced in the `non_nullable` cases to return -// non-null values. -List _defaultList() => null; -Set _defaultSet() => null; -Map _defaultMap() => null; -SimpleObject _defaultSimpleObject() => null; -StrictKeysObject _defaultStrictKeysObject() => null; - -const k.KitchenSinkFactory factory = _Factory(); - -class _Factory implements k.KitchenSinkFactory { - const _Factory(); - - String get description => 'exclude_null__no_encode_empty'; - bool get anyMap => false; - bool get checked => false; - bool get nullable => true; - bool get excludeNull => true; - bool get explicitToJson => false; - bool get noEncodeEmpty => true; - - k.KitchenSink ctor({ - int ctorValidatedNo42, - Iterable iterable, - Iterable dynamicIterable, - Iterable objectIterable, - Iterable intIterable, - Iterable dateTimeIterable, - }) => - KitchenSink( - ctorValidatedNo42: ctorValidatedNo42, - iterable: iterable, - dynamicIterable: dynamicIterable, - objectIterable: objectIterable, - intIterable: intIterable, - dateTimeIterable: dateTimeIterable, - ); - - k.KitchenSink fromJson(Map json) => - KitchenSink.fromJson(json); - - k.JsonConverterTestClass jsonConverterCtor() => JsonConverterTestClass(); - - k.JsonConverterTestClass jsonConverterFromJson(Map json) => - JsonConverterTestClass.fromJson(json); -} - -@JsonSerializable( - includeIfNull: false, - encodeEmptyCollection: false, -) -class KitchenSink implements k.KitchenSink { - // NOTE: exposing these as Iterable, but storing the values as List - // to make the equality test work trivially. - final Iterable _iterable; - final Iterable _dynamicIterable; - final Iterable _objectIterable; - final Iterable _intIterable; - final Iterable _dateTimeIterable; - - @JsonKey(name: 'no-42') - final int ctorValidatedNo42; - - KitchenSink({ - this.ctorValidatedNo42, - Iterable iterable, - Iterable dynamicIterable, - Iterable objectIterable, - Iterable intIterable, - Iterable dateTimeIterable, - }) : _iterable = iterable?.toList() ?? _defaultList(), - _dynamicIterable = dynamicIterable?.toList() ?? _defaultList(), - _objectIterable = objectIterable?.toList() ?? _defaultList(), - _intIterable = intIterable?.toList() ?? _defaultList(), - _dateTimeIterable = dateTimeIterable?.toList() ?? _defaultList() { - if (ctorValidatedNo42 == 42) { - throw ArgumentError.value( - 42, 'ctorValidatedNo42', 'The value `42` is not allowed.'); - } - } - - factory KitchenSink.fromJson(Map json) => - _$KitchenSinkFromJson(json); - - Map toJson() => _$KitchenSinkToJson(this); - - DateTime dateTime; - - BigInt bigInt; - - Iterable get iterable => _iterable; - Iterable get dynamicIterable => _dynamicIterable; - Iterable get objectIterable => _objectIterable; - Iterable get intIterable => _intIterable; - - Set set = _defaultSet(); - Set dynamicSet = _defaultSet(); - Set objectSet = _defaultSet(); - Set intSet = _defaultSet(); - Set dateTimeSet = _defaultSet(); - - // Added a one-off annotation on a property (not a field) - @JsonKey(name: 'datetime-iterable') - Iterable get dateTimeIterable => _dateTimeIterable; - - List list = _defaultList(); - List dynamicList = _defaultList(); - List objectList = _defaultList(); - List intList = _defaultList(); - List dateTimeList = _defaultList(); - - Map map = _defaultMap(); - Map stringStringMap = _defaultMap(); - Map dynamicIntMap = _defaultMap(); - Map objectDateTimeMap = _defaultMap(); - - List>>>> crazyComplex = - _defaultList(); - - // Handle fields with names that collide with helper names - Map val = _defaultMap(); - bool writeNotNull; - @JsonKey(name: r'$string') - String string; - - SimpleObject simpleObject = _defaultSimpleObject(); - - StrictKeysObject strictKeysObject = _defaultStrictKeysObject(); - - int _validatedPropertyNo42; - int get validatedPropertyNo42 => _validatedPropertyNo42; - - set validatedPropertyNo42(int value) { - if (value == 42) { - throw StateError('Cannot be 42!'); - } - _validatedPropertyNo42 = value; - } - - bool operator ==(Object other) => k.sinkEquals(this, other); -} - -@JsonSerializable( - includeIfNull: false, - encodeEmptyCollection: false, -) -// referencing a top-level field should work -@durationConverter -// referencing via a const constructor should work -@BigIntStringConverter() -@TrivialNumberConverter.instance -@EpochDateTimeConverter() -class JsonConverterTestClass implements k.JsonConverterTestClass { - JsonConverterTestClass(); - - factory JsonConverterTestClass.fromJson(Map json) => - _$JsonConverterTestClassFromJson(json); - - Map toJson() => _$JsonConverterTestClassToJson(this); - - Duration duration; - List durationList; - - BigInt bigInt; - Map bigIntMap; - - TrivialNumber numberSilly; - Set numberSillySet; - - DateTime dateTime; -} - -@JsonSerializable( - includeIfNull: false, - encodeEmptyCollection: false, -) -@GenericConverter() -class JsonConverterGeneric { - S item; - List itemList; - Map itemMap; - - JsonConverterGeneric(); - - factory JsonConverterGeneric.fromJson(Map json) => - _$JsonConverterGenericFromJson(json); - - Map toJson() => _$JsonConverterGenericToJson(this); -} diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty.g.dart deleted file mode 100644 index c0cbbe9c3..000000000 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty.g.dart +++ /dev/null @@ -1,283 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'kitchen_sink.g_exclude_null__no_encode_empty.dart'; - -// ************************************************************************** -// JsonSerializableGenerator -// ************************************************************************** - -KitchenSink _$KitchenSinkFromJson(Map json) { - return KitchenSink( - ctorValidatedNo42: json['no-42'] as int, - iterable: json['iterable'] as List, - dynamicIterable: json['dynamicIterable'] as List, - objectIterable: json['objectIterable'] as List, - intIterable: (json['intIterable'] as List)?.map((e) => e as int), - dateTimeIterable: (json['datetime-iterable'] as List) - ?.map((e) => e == null ? null : DateTime.parse(e as String))) - ..dateTime = json['dateTime'] == null - ? null - : DateTime.parse(json['dateTime'] as String) - ..bigInt = - json['bigInt'] == null ? null : BigInt.parse(json['bigInt'] as String) - ..set = (json['set'] as List)?.toSet() - ..dynamicSet = (json['dynamicSet'] as List)?.toSet() - ..objectSet = (json['objectSet'] as List)?.toSet() - ..intSet = (json['intSet'] as List)?.map((e) => e as int)?.toSet() - ..dateTimeSet = (json['dateTimeSet'] as List) - ?.map((e) => e == null ? null : DateTime.parse(e as String)) - ?.toSet() - ..list = json['list'] as List - ..dynamicList = json['dynamicList'] as List - ..objectList = json['objectList'] as List - ..intList = (json['intList'] as List)?.map((e) => e as int)?.toList() - ..dateTimeList = (json['dateTimeList'] as List) - ?.map((e) => e == null ? null : DateTime.parse(e as String)) - ?.toList() - ..map = json['map'] as Map - ..stringStringMap = (json['stringStringMap'] as Map)?.map( - (k, e) => MapEntry(k, e as String), - ) - ..dynamicIntMap = (json['dynamicIntMap'] as Map)?.map( - (k, e) => MapEntry(k, e as int), - ) - ..objectDateTimeMap = - (json['objectDateTimeMap'] as Map)?.map( - (k, e) => MapEntry(k, e == null ? null : DateTime.parse(e as String)), - ) - ..crazyComplex = (json['crazyComplex'] as List) - ?.map((e) => (e as Map)?.map( - (k, e) => MapEntry( - k, - (e as Map)?.map( - (k, e) => MapEntry( - k, - (e as List) - ?.map((e) => (e as List) - ?.map((e) => e == null - ? null - : DateTime.parse(e as String)) - ?.toList()) - ?.toList()), - )), - )) - ?.toList() - ..val = (json['val'] as Map)?.map( - (k, e) => MapEntry(k, e as bool), - ) - ..writeNotNull = json['writeNotNull'] as bool - ..string = json[r'$string'] as String - ..simpleObject = json['simpleObject'] == null - ? null - : SimpleObject.fromJson(json['simpleObject'] as Map) - ..strictKeysObject = json['strictKeysObject'] == null - ? null - : StrictKeysObject.fromJson( - json['strictKeysObject'] as Map) - ..validatedPropertyNo42 = json['validatedPropertyNo42'] as int; -} - -Map _$KitchenSinkToJson(KitchenSink instance) { - final val = {}; - - void writeNotNull(String key, dynamic value) { - if (value != null) { - val[key] = value; - } - } - - writeNotNull('no-42', instance.ctorValidatedNo42); - writeNotNull('dateTime', instance.dateTime?.toIso8601String()); - writeNotNull('bigInt', instance.bigInt?.toString()); - writeNotNull('iterable', _$nullIfEmptyIterable(instance.iterable)?.toList()); - writeNotNull('dynamicIterable', - _$nullIfEmptyIterable(instance.dynamicIterable)?.toList()); - writeNotNull('objectIterable', - _$nullIfEmptyIterable(instance.objectIterable)?.toList()); - writeNotNull( - 'intIterable', _$nullIfEmptyIterable(instance.intIterable)?.toList()); - writeNotNull('set', _$nullIfEmptyIterable(instance.set)?.toList()); - writeNotNull( - 'dynamicSet', _$nullIfEmptyIterable(instance.dynamicSet)?.toList()); - writeNotNull( - 'objectSet', _$nullIfEmptyIterable(instance.objectSet)?.toList()); - writeNotNull('intSet', _$nullIfEmptyIterable(instance.intSet)?.toList()); - writeNotNull( - 'dateTimeSet', - _$nullIfEmptyIterable(instance.dateTimeSet) - ?.map((e) => e?.toIso8601String()) - ?.toList()); - writeNotNull( - 'datetime-iterable', - _$nullIfEmptyIterable(instance.dateTimeIterable) - ?.map((e) => e?.toIso8601String()) - ?.toList()); - writeNotNull('list', _$nullIfEmptyIterable(instance.list)); - writeNotNull('dynamicList', _$nullIfEmptyIterable(instance.dynamicList)); - writeNotNull('objectList', _$nullIfEmptyIterable(instance.objectList)); - writeNotNull('intList', _$nullIfEmptyIterable(instance.intList)); - writeNotNull( - 'dateTimeList', - _$nullIfEmptyIterable(instance.dateTimeList) - ?.map((e) => e?.toIso8601String()) - ?.toList()); - writeNotNull('map', _$nullIfEmptyMap(instance.map)); - writeNotNull('stringStringMap', _$nullIfEmptyMap(instance.stringStringMap)); - writeNotNull('dynamicIntMap', _$nullIfEmptyMap(instance.dynamicIntMap)); - writeNotNull( - 'objectDateTimeMap', - _$nullIfEmptyMap(instance.objectDateTimeMap) - ?.map((k, e) => MapEntry(k, e?.toIso8601String()))); - writeNotNull( - 'crazyComplex', - _$nullIfEmptyIterable(instance.crazyComplex) - ?.map((e) => e?.map((k, e) => MapEntry( - k, - e?.map((k, e) => MapEntry( - k, - e - ?.map( - (e) => e?.map((e) => e?.toIso8601String())?.toList()) - ?.toList()))))) - ?.toList()); - writeNotNull('val', _$nullIfEmptyMap(instance.val)); - writeNotNull('writeNotNull', instance.writeNotNull); - writeNotNull(r'$string', instance.string); - writeNotNull('simpleObject', instance.simpleObject); - writeNotNull('strictKeysObject', instance.strictKeysObject); - writeNotNull('validatedPropertyNo42', instance.validatedPropertyNo42); - return val; -} - -T _$nullIfEmptyIterable(T source) => - (source == null || source.isEmpty) ? null : source; - -T _$nullIfEmptyMap(T source) => - (source == null || source.isEmpty) ? null : source; - -JsonConverterTestClass _$JsonConverterTestClassFromJson( - Map json) { - return JsonConverterTestClass() - ..duration = json['duration'] == null - ? null - : durationConverter.fromJson(json['duration'] as int) - ..durationList = (json['durationList'] as List) - ?.map((e) => e == null ? null : durationConverter.fromJson(e as int)) - ?.toList() - ..bigInt = json['bigInt'] == null - ? null - : const BigIntStringConverter().fromJson(json['bigInt'] as String) - ..bigIntMap = (json['bigIntMap'] as Map)?.map( - (k, e) => MapEntry( - k, - e == null - ? null - : const BigIntStringConverter().fromJson(e as String)), - ) - ..numberSilly = json['numberSilly'] == null - ? null - : TrivialNumberConverter.instance.fromJson(json['numberSilly'] as int) - ..numberSillySet = (json['numberSillySet'] as List) - ?.map((e) => e == null - ? null - : TrivialNumberConverter.instance.fromJson(e as int)) - ?.toSet() - ..dateTime = json['dateTime'] == null - ? null - : const EpochDateTimeConverter().fromJson(json['dateTime'] as int); -} - -Map _$JsonConverterTestClassToJson( - JsonConverterTestClass instance) { - final val = {}; - - void writeNotNull(String key, dynamic value) { - if (value != null) { - val[key] = value; - } - } - - writeNotNull( - 'duration', - instance.duration == null - ? null - : durationConverter.toJson(instance.duration)); - writeNotNull( - 'durationList', - _$nullIfEmptyIterable(instance.durationList) - ?.map((e) => e == null ? null : durationConverter.toJson(e)) - ?.toList()); - writeNotNull( - 'bigInt', - instance.bigInt == null - ? null - : const BigIntStringConverter().toJson(instance.bigInt)); - writeNotNull( - 'bigIntMap', - _$nullIfEmptyMap(instance.bigIntMap)?.map((k, e) => MapEntry( - k, e == null ? null : const BigIntStringConverter().toJson(e)))); - writeNotNull( - 'numberSilly', - instance.numberSilly == null - ? null - : TrivialNumberConverter.instance.toJson(instance.numberSilly)); - writeNotNull( - 'numberSillySet', - _$nullIfEmptyIterable(instance.numberSillySet) - ?.map((e) => - e == null ? null : TrivialNumberConverter.instance.toJson(e)) - ?.toList()); - writeNotNull( - 'dateTime', - instance.dateTime == null - ? null - : const EpochDateTimeConverter().toJson(instance.dateTime)); - return val; -} - -JsonConverterGeneric _$JsonConverterGenericFromJson( - Map json) { - return JsonConverterGeneric() - ..item = json['item'] == null - ? null - : GenericConverter().fromJson(json['item'] as Map) - ..itemList = (json['itemList'] as List) - ?.map((e) => e == null - ? null - : GenericConverter().fromJson(e as Map)) - ?.toList() - ..itemMap = (json['itemMap'] as Map)?.map( - (k, e) => MapEntry( - k, - e == null - ? null - : GenericConverter().fromJson(e as Map)), - ); -} - -Map _$JsonConverterGenericToJson( - JsonConverterGeneric instance) { - final val = {}; - - void writeNotNull(String key, dynamic value) { - if (value != null) { - val[key] = value; - } - } - - writeNotNull( - 'item', - instance.item == null - ? null - : GenericConverter().toJson(instance.item)); - writeNotNull( - 'itemList', - _$nullIfEmptyIterable(instance.itemList) - ?.map((e) => e == null ? null : GenericConverter().toJson(e)) - ?.toList()); - writeNotNull( - 'itemMap', - _$nullIfEmptyMap(instance.itemMap)?.map((k, e) => - MapEntry(k, e == null ? null : GenericConverter().toJson(e)))); - return val; -} diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty__non_nullable.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty__non_nullable.dart deleted file mode 100644 index abf4f925d..000000000 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty__non_nullable.dart +++ /dev/null @@ -1,206 +0,0 @@ -// Copyright (c) 2018, 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. - -// ignore_for_file: annotate_overrides, hash_and_equals -import 'package:json_annotation/json_annotation.dart'; - -import 'json_converters.dart'; -import 'kitchen_sink_interface.dart' as k; -import 'simple_object.dart'; -import 'strict_keys_object.dart'; - -part 'kitchen_sink.g_exclude_null__no_encode_empty__non_nullable.g.dart'; - -// NOTE: these methods are replaced in the `non_nullable` cases to return -// non-null values. -List _defaultList() => []; -Set _defaultSet() => {}; -Map _defaultMap() => {}; -SimpleObject _defaultSimpleObject() => SimpleObject(42); -StrictKeysObject _defaultStrictKeysObject() => StrictKeysObject(10, 'cool'); - -const k.KitchenSinkFactory factory = _Factory(); - -class _Factory implements k.KitchenSinkFactory { - const _Factory(); - - String get description => 'exclude_null__no_encode_empty__non_nullable'; - bool get anyMap => false; - bool get checked => false; - bool get nullable => false; - bool get excludeNull => true; - bool get explicitToJson => false; - bool get noEncodeEmpty => true; - - k.KitchenSink ctor({ - int ctorValidatedNo42, - Iterable iterable, - Iterable dynamicIterable, - Iterable objectIterable, - Iterable intIterable, - Iterable dateTimeIterable, - }) => - KitchenSink( - ctorValidatedNo42: ctorValidatedNo42, - iterable: iterable, - dynamicIterable: dynamicIterable, - objectIterable: objectIterable, - intIterable: intIterable, - dateTimeIterable: dateTimeIterable, - ); - - k.KitchenSink fromJson(Map json) => - KitchenSink.fromJson(json); - - k.JsonConverterTestClass jsonConverterCtor() => JsonConverterTestClass(); - - k.JsonConverterTestClass jsonConverterFromJson(Map json) => - JsonConverterTestClass.fromJson(json); -} - -@JsonSerializable( - nullable: false, - includeIfNull: false, - encodeEmptyCollection: false, -) -class KitchenSink implements k.KitchenSink { - // NOTE: exposing these as Iterable, but storing the values as List - // to make the equality test work trivially. - final Iterable _iterable; - final Iterable _dynamicIterable; - final Iterable _objectIterable; - final Iterable _intIterable; - final Iterable _dateTimeIterable; - - @JsonKey(name: 'no-42') - final int ctorValidatedNo42; - - KitchenSink({ - this.ctorValidatedNo42, - Iterable iterable, - Iterable dynamicIterable, - Iterable objectIterable, - Iterable intIterable, - Iterable dateTimeIterable, - }) : _iterable = iterable?.toList() ?? _defaultList(), - _dynamicIterable = dynamicIterable?.toList() ?? _defaultList(), - _objectIterable = objectIterable?.toList() ?? _defaultList(), - _intIterable = intIterable?.toList() ?? _defaultList(), - _dateTimeIterable = dateTimeIterable?.toList() ?? _defaultList() { - if (ctorValidatedNo42 == 42) { - throw ArgumentError.value( - 42, 'ctorValidatedNo42', 'The value `42` is not allowed.'); - } - } - - factory KitchenSink.fromJson(Map json) => - _$KitchenSinkFromJson(json); - - Map toJson() => _$KitchenSinkToJson(this); - - DateTime dateTime = DateTime(1981, 6, 5); - - BigInt bigInt = BigInt.parse('10000000000000000000'); - - Iterable get iterable => _iterable; - Iterable get dynamicIterable => _dynamicIterable; - Iterable get objectIterable => _objectIterable; - Iterable get intIterable => _intIterable; - - Set set = _defaultSet(); - Set dynamicSet = _defaultSet(); - Set objectSet = _defaultSet(); - Set intSet = _defaultSet(); - Set dateTimeSet = _defaultSet(); - - // Added a one-off annotation on a property (not a field) - @JsonKey(name: 'datetime-iterable') - Iterable get dateTimeIterable => _dateTimeIterable; - - List list = _defaultList(); - List dynamicList = _defaultList(); - List objectList = _defaultList(); - List intList = _defaultList(); - List dateTimeList = _defaultList(); - - Map map = _defaultMap(); - Map stringStringMap = _defaultMap(); - Map dynamicIntMap = _defaultMap(); - Map objectDateTimeMap = _defaultMap(); - - List>>>> crazyComplex = - _defaultList(); - - // Handle fields with names that collide with helper names - Map val = _defaultMap(); - bool writeNotNull; - @JsonKey(name: r'$string') - String string; - - SimpleObject simpleObject = _defaultSimpleObject(); - - StrictKeysObject strictKeysObject = _defaultStrictKeysObject(); - - int _validatedPropertyNo42; - int get validatedPropertyNo42 => _validatedPropertyNo42; - - set validatedPropertyNo42(int value) { - if (value == 42) { - throw StateError('Cannot be 42!'); - } - _validatedPropertyNo42 = value; - } - - bool operator ==(Object other) => k.sinkEquals(this, other); -} - -@JsonSerializable( - nullable: false, - includeIfNull: false, - encodeEmptyCollection: false, -) -// referencing a top-level field should work -@durationConverter -// referencing via a const constructor should work -@BigIntStringConverter() -@TrivialNumberConverter.instance -@EpochDateTimeConverter() -class JsonConverterTestClass implements k.JsonConverterTestClass { - JsonConverterTestClass(); - - factory JsonConverterTestClass.fromJson(Map json) => - _$JsonConverterTestClassFromJson(json); - - Map toJson() => _$JsonConverterTestClassToJson(this); - - Duration duration; - List durationList; - - BigInt bigInt = BigInt.parse('10000000000000000000'); - Map bigIntMap; - - TrivialNumber numberSilly; - Set numberSillySet; - - DateTime dateTime = DateTime(1981, 6, 5); -} - -@JsonSerializable( - nullable: false, - includeIfNull: false, - encodeEmptyCollection: false, -) -@GenericConverter() -class JsonConverterGeneric { - S item; - List itemList; - Map itemMap; - - JsonConverterGeneric(); - - factory JsonConverterGeneric.fromJson(Map json) => - _$JsonConverterGenericFromJson(json); - - Map toJson() => _$JsonConverterGenericToJson(this); -} diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty__non_nullable.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty__non_nullable.g.dart deleted file mode 100644 index 6337fc66f..000000000 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__no_encode_empty__non_nullable.g.dart +++ /dev/null @@ -1,233 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'kitchen_sink.g_exclude_null__no_encode_empty__non_nullable.dart'; - -// ************************************************************************** -// JsonSerializableGenerator -// ************************************************************************** - -KitchenSink _$KitchenSinkFromJson(Map json) { - return KitchenSink( - ctorValidatedNo42: json['no-42'] as int, - iterable: json['iterable'] as List, - dynamicIterable: json['dynamicIterable'] as List, - objectIterable: json['objectIterable'] as List, - intIterable: (json['intIterable'] as List).map((e) => e as int), - dateTimeIterable: (json['datetime-iterable'] as List) - .map((e) => DateTime.parse(e as String))) - ..dateTime = DateTime.parse(json['dateTime'] as String) - ..bigInt = BigInt.parse(json['bigInt'] as String) - ..set = (json['set'] as List).toSet() - ..dynamicSet = (json['dynamicSet'] as List).toSet() - ..objectSet = (json['objectSet'] as List).toSet() - ..intSet = (json['intSet'] as List).map((e) => e as int).toSet() - ..dateTimeSet = (json['dateTimeSet'] as List) - .map((e) => DateTime.parse(e as String)) - .toSet() - ..list = json['list'] as List - ..dynamicList = json['dynamicList'] as List - ..objectList = json['objectList'] as List - ..intList = (json['intList'] as List).map((e) => e as int).toList() - ..dateTimeList = (json['dateTimeList'] as List) - .map((e) => DateTime.parse(e as String)) - .toList() - ..map = json['map'] as Map - ..stringStringMap = Map.from(json['stringStringMap'] as Map) - ..dynamicIntMap = Map.from(json['dynamicIntMap'] as Map) - ..objectDateTimeMap = - (json['objectDateTimeMap'] as Map).map( - (k, e) => MapEntry(k, DateTime.parse(e as String)), - ) - ..crazyComplex = (json['crazyComplex'] as List) - .map((e) => (e as Map).map( - (k, e) => MapEntry( - k, - (e as Map).map( - (k, e) => MapEntry( - k, - (e as List) - .map((e) => (e as List) - .map((e) => DateTime.parse(e as String)) - .toList()) - .toList()), - )), - )) - .toList() - ..val = Map.from(json['val'] as Map) - ..writeNotNull = json['writeNotNull'] as bool - ..string = json[r'$string'] as String - ..simpleObject = - SimpleObject.fromJson(json['simpleObject'] as Map) - ..strictKeysObject = StrictKeysObject.fromJson( - json['strictKeysObject'] as Map) - ..validatedPropertyNo42 = json['validatedPropertyNo42'] as int; -} - -Map _$KitchenSinkToJson(KitchenSink instance) { - final val = { - 'no-42': instance.ctorValidatedNo42, - 'dateTime': instance.dateTime.toIso8601String(), - 'bigInt': instance.bigInt.toString(), - }; - - void writeNotNull(String key, dynamic value) { - if (value != null) { - val[key] = value; - } - } - - writeNotNull('iterable', _$nullIfEmptyIterable(instance.iterable)?.toList()); - writeNotNull('dynamicIterable', - _$nullIfEmptyIterable(instance.dynamicIterable)?.toList()); - writeNotNull('objectIterable', - _$nullIfEmptyIterable(instance.objectIterable)?.toList()); - writeNotNull( - 'intIterable', _$nullIfEmptyIterable(instance.intIterable)?.toList()); - writeNotNull('set', _$nullIfEmptyIterable(instance.set)?.toList()); - writeNotNull( - 'dynamicSet', _$nullIfEmptyIterable(instance.dynamicSet)?.toList()); - writeNotNull( - 'objectSet', _$nullIfEmptyIterable(instance.objectSet)?.toList()); - writeNotNull('intSet', _$nullIfEmptyIterable(instance.intSet)?.toList()); - writeNotNull( - 'dateTimeSet', - _$nullIfEmptyIterable(instance.dateTimeSet) - ?.map((e) => e.toIso8601String()) - ?.toList()); - writeNotNull( - 'datetime-iterable', - _$nullIfEmptyIterable(instance.dateTimeIterable) - ?.map((e) => e.toIso8601String()) - ?.toList()); - writeNotNull('list', _$nullIfEmptyIterable(instance.list)); - writeNotNull('dynamicList', _$nullIfEmptyIterable(instance.dynamicList)); - writeNotNull('objectList', _$nullIfEmptyIterable(instance.objectList)); - writeNotNull('intList', _$nullIfEmptyIterable(instance.intList)); - writeNotNull( - 'dateTimeList', - _$nullIfEmptyIterable(instance.dateTimeList) - ?.map((e) => e.toIso8601String()) - ?.toList()); - writeNotNull('map', _$nullIfEmptyMap(instance.map)); - writeNotNull('stringStringMap', _$nullIfEmptyMap(instance.stringStringMap)); - writeNotNull('dynamicIntMap', _$nullIfEmptyMap(instance.dynamicIntMap)); - writeNotNull( - 'objectDateTimeMap', - _$nullIfEmptyMap(instance.objectDateTimeMap) - ?.map((k, e) => MapEntry(k, e.toIso8601String()))); - writeNotNull( - 'crazyComplex', - _$nullIfEmptyIterable(instance.crazyComplex) - ?.map((e) => e.map((k, e) => MapEntry( - k, - e.map((k, e) => MapEntry( - k, - e - .map((e) => e.map((e) => e.toIso8601String()).toList()) - .toList()))))) - ?.toList()); - writeNotNull('val', _$nullIfEmptyMap(instance.val)); - val['writeNotNull'] = instance.writeNotNull; - val[r'$string'] = instance.string; - val['simpleObject'] = instance.simpleObject; - val['strictKeysObject'] = instance.strictKeysObject; - val['validatedPropertyNo42'] = instance.validatedPropertyNo42; - return val; -} - -T _$nullIfEmptyIterable(T source) => - (source == null || source.isEmpty) ? null : source; - -T _$nullIfEmptyMap(T source) => - (source == null || source.isEmpty) ? null : source; - -JsonConverterTestClass _$JsonConverterTestClassFromJson( - Map json) { - return JsonConverterTestClass() - ..duration = durationConverter.fromJson(json['duration'] as int) - ..durationList = (json['durationList'] as List) - .map((e) => durationConverter.fromJson(e as int)) - .toList() - ..bigInt = const BigIntStringConverter().fromJson(json['bigInt'] as String) - ..bigIntMap = (json['bigIntMap'] as Map).map( - (k, e) => - MapEntry(k, const BigIntStringConverter().fromJson(e as String)), - ) - ..numberSilly = - TrivialNumberConverter.instance.fromJson(json['numberSilly'] as int) - ..numberSillySet = (json['numberSillySet'] as List) - .map((e) => TrivialNumberConverter.instance.fromJson(e as int)) - .toSet() - ..dateTime = - const EpochDateTimeConverter().fromJson(json['dateTime'] as int); -} - -Map _$JsonConverterTestClassToJson( - JsonConverterTestClass instance) { - final val = {}; - - void writeNotNull(String key, dynamic value) { - if (value != null) { - val[key] = value; - } - } - - writeNotNull('duration', durationConverter.toJson(instance.duration)); - writeNotNull( - 'durationList', - _$nullIfEmptyIterable(instance.durationList) - ?.map(durationConverter.toJson) - ?.toList()); - writeNotNull('bigInt', const BigIntStringConverter().toJson(instance.bigInt)); - writeNotNull( - 'bigIntMap', - _$nullIfEmptyMap(instance.bigIntMap)?.map( - (k, e) => MapEntry(k, const BigIntStringConverter().toJson(e)))); - writeNotNull('numberSilly', - TrivialNumberConverter.instance.toJson(instance.numberSilly)); - writeNotNull( - 'numberSillySet', - _$nullIfEmptyIterable(instance.numberSillySet) - ?.map(TrivialNumberConverter.instance.toJson) - ?.toList()); - writeNotNull( - 'dateTime', const EpochDateTimeConverter().toJson(instance.dateTime)); - return val; -} - -JsonConverterGeneric _$JsonConverterGenericFromJson( - Map json) { - return JsonConverterGeneric() - ..item = - GenericConverter().fromJson(json['item'] as Map) - ..itemList = (json['itemList'] as List) - .map((e) => GenericConverter().fromJson(e as Map)) - .toList() - ..itemMap = (json['itemMap'] as Map).map( - (k, e) => MapEntry( - k, GenericConverter().fromJson(e as Map)), - ); -} - -Map _$JsonConverterGenericToJson( - JsonConverterGeneric instance) { - final val = {}; - - void writeNotNull(String key, dynamic value) { - if (value != null) { - val[key] = value; - } - } - - writeNotNull('item', GenericConverter().toJson(instance.item)); - writeNotNull( - 'itemList', - _$nullIfEmptyIterable(instance.itemList) - ?.map(GenericConverter().toJson) - ?.toList()); - writeNotNull( - 'itemMap', - _$nullIfEmptyMap(instance.itemMap) - ?.map((k, e) => MapEntry(k, GenericConverter().toJson(e)))); - return val; -} diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__non_nullable.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__non_nullable.dart index 7ab6f61ad..194d406a8 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__non_nullable.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__non_nullable.dart @@ -31,7 +31,6 @@ class _Factory implements k.KitchenSinkFactory { bool get nullable => false; bool get excludeNull => true; bool get explicitToJson => false; - bool get noEncodeEmpty => false; k.KitchenSink ctor({ int ctorValidatedNo42, diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.dart index 7de661d43..5a4fbeb20 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.dart @@ -31,7 +31,6 @@ class _Factory implements k.KitchenSinkFactory { bool get nullable => true; bool get excludeNull => false; bool get explicitToJson => true; - bool get noEncodeEmpty => false; k.KitchenSink ctor({ int ctorValidatedNo42, diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_no_encode_empty.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_no_encode_empty.dart deleted file mode 100644 index ff8759979..000000000 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_no_encode_empty.dart +++ /dev/null @@ -1,200 +0,0 @@ -// Copyright (c) 2018, 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. - -// ignore_for_file: annotate_overrides, hash_and_equals -import 'package:json_annotation/json_annotation.dart'; - -import 'json_converters.dart'; -import 'kitchen_sink_interface.dart' as k; -import 'simple_object.dart'; -import 'strict_keys_object.dart'; - -part 'kitchen_sink.g_no_encode_empty.g.dart'; - -// NOTE: these methods are replaced in the `non_nullable` cases to return -// non-null values. -List _defaultList() => null; -Set _defaultSet() => null; -Map _defaultMap() => null; -SimpleObject _defaultSimpleObject() => null; -StrictKeysObject _defaultStrictKeysObject() => null; - -const k.KitchenSinkFactory factory = _Factory(); - -class _Factory implements k.KitchenSinkFactory { - const _Factory(); - - String get description => 'no_encode_empty'; - bool get anyMap => false; - bool get checked => false; - bool get nullable => true; - bool get excludeNull => false; - bool get explicitToJson => false; - bool get noEncodeEmpty => true; - - k.KitchenSink ctor({ - int ctorValidatedNo42, - Iterable iterable, - Iterable dynamicIterable, - Iterable objectIterable, - Iterable intIterable, - Iterable dateTimeIterable, - }) => - KitchenSink( - ctorValidatedNo42: ctorValidatedNo42, - iterable: iterable, - dynamicIterable: dynamicIterable, - objectIterable: objectIterable, - intIterable: intIterable, - dateTimeIterable: dateTimeIterable, - ); - - k.KitchenSink fromJson(Map json) => - KitchenSink.fromJson(json); - - k.JsonConverterTestClass jsonConverterCtor() => JsonConverterTestClass(); - - k.JsonConverterTestClass jsonConverterFromJson(Map json) => - JsonConverterTestClass.fromJson(json); -} - -@JsonSerializable( - encodeEmptyCollection: false, -) -class KitchenSink implements k.KitchenSink { - // NOTE: exposing these as Iterable, but storing the values as List - // to make the equality test work trivially. - final Iterable _iterable; - final Iterable _dynamicIterable; - final Iterable _objectIterable; - final Iterable _intIterable; - final Iterable _dateTimeIterable; - - @JsonKey(name: 'no-42') - final int ctorValidatedNo42; - - KitchenSink({ - this.ctorValidatedNo42, - Iterable iterable, - Iterable dynamicIterable, - Iterable objectIterable, - Iterable intIterable, - Iterable dateTimeIterable, - }) : _iterable = iterable?.toList() ?? _defaultList(), - _dynamicIterable = dynamicIterable?.toList() ?? _defaultList(), - _objectIterable = objectIterable?.toList() ?? _defaultList(), - _intIterable = intIterable?.toList() ?? _defaultList(), - _dateTimeIterable = dateTimeIterable?.toList() ?? _defaultList() { - if (ctorValidatedNo42 == 42) { - throw ArgumentError.value( - 42, 'ctorValidatedNo42', 'The value `42` is not allowed.'); - } - } - - factory KitchenSink.fromJson(Map json) => - _$KitchenSinkFromJson(json); - - Map toJson() => _$KitchenSinkToJson(this); - - DateTime dateTime; - - BigInt bigInt; - - Iterable get iterable => _iterable; - Iterable get dynamicIterable => _dynamicIterable; - Iterable get objectIterable => _objectIterable; - Iterable get intIterable => _intIterable; - - Set set = _defaultSet(); - Set dynamicSet = _defaultSet(); - Set objectSet = _defaultSet(); - Set intSet = _defaultSet(); - Set dateTimeSet = _defaultSet(); - - // Added a one-off annotation on a property (not a field) - @JsonKey(name: 'datetime-iterable') - Iterable get dateTimeIterable => _dateTimeIterable; - - List list = _defaultList(); - List dynamicList = _defaultList(); - List objectList = _defaultList(); - List intList = _defaultList(); - List dateTimeList = _defaultList(); - - Map map = _defaultMap(); - Map stringStringMap = _defaultMap(); - Map dynamicIntMap = _defaultMap(); - Map objectDateTimeMap = _defaultMap(); - - List>>>> crazyComplex = - _defaultList(); - - // Handle fields with names that collide with helper names - Map val = _defaultMap(); - bool writeNotNull; - @JsonKey(name: r'$string') - String string; - - SimpleObject simpleObject = _defaultSimpleObject(); - - StrictKeysObject strictKeysObject = _defaultStrictKeysObject(); - - int _validatedPropertyNo42; - int get validatedPropertyNo42 => _validatedPropertyNo42; - - set validatedPropertyNo42(int value) { - if (value == 42) { - throw StateError('Cannot be 42!'); - } - _validatedPropertyNo42 = value; - } - - bool operator ==(Object other) => k.sinkEquals(this, other); -} - -@JsonSerializable( - encodeEmptyCollection: false, -) -// referencing a top-level field should work -@durationConverter -// referencing via a const constructor should work -@BigIntStringConverter() -@TrivialNumberConverter.instance -@EpochDateTimeConverter() -class JsonConverterTestClass implements k.JsonConverterTestClass { - JsonConverterTestClass(); - - factory JsonConverterTestClass.fromJson(Map json) => - _$JsonConverterTestClassFromJson(json); - - Map toJson() => _$JsonConverterTestClassToJson(this); - - Duration duration; - List durationList; - - BigInt bigInt; - Map bigIntMap; - - TrivialNumber numberSilly; - Set numberSillySet; - - DateTime dateTime; -} - -@JsonSerializable( - encodeEmptyCollection: false, -) -@GenericConverter() -class JsonConverterGeneric { - S item; - List itemList; - Map itemMap; - - JsonConverterGeneric(); - - factory JsonConverterGeneric.fromJson(Map json) => - _$JsonConverterGenericFromJson(json); - - Map toJson() => _$JsonConverterGenericToJson(this); -} diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_no_encode_empty.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_no_encode_empty.g.dart deleted file mode 100644 index 3c6534656..000000000 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_no_encode_empty.g.dart +++ /dev/null @@ -1,276 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'kitchen_sink.g_no_encode_empty.dart'; - -// ************************************************************************** -// JsonSerializableGenerator -// ************************************************************************** - -KitchenSink _$KitchenSinkFromJson(Map json) { - return KitchenSink( - ctorValidatedNo42: json['no-42'] as int, - iterable: json['iterable'] as List, - dynamicIterable: json['dynamicIterable'] as List, - objectIterable: json['objectIterable'] as List, - intIterable: (json['intIterable'] as List)?.map((e) => e as int), - dateTimeIterable: (json['datetime-iterable'] as List) - ?.map((e) => e == null ? null : DateTime.parse(e as String))) - ..dateTime = json['dateTime'] == null - ? null - : DateTime.parse(json['dateTime'] as String) - ..bigInt = - json['bigInt'] == null ? null : BigInt.parse(json['bigInt'] as String) - ..set = (json['set'] as List)?.toSet() - ..dynamicSet = (json['dynamicSet'] as List)?.toSet() - ..objectSet = (json['objectSet'] as List)?.toSet() - ..intSet = (json['intSet'] as List)?.map((e) => e as int)?.toSet() - ..dateTimeSet = (json['dateTimeSet'] as List) - ?.map((e) => e == null ? null : DateTime.parse(e as String)) - ?.toSet() - ..list = json['list'] as List - ..dynamicList = json['dynamicList'] as List - ..objectList = json['objectList'] as List - ..intList = (json['intList'] as List)?.map((e) => e as int)?.toList() - ..dateTimeList = (json['dateTimeList'] as List) - ?.map((e) => e == null ? null : DateTime.parse(e as String)) - ?.toList() - ..map = json['map'] as Map - ..stringStringMap = (json['stringStringMap'] as Map)?.map( - (k, e) => MapEntry(k, e as String), - ) - ..dynamicIntMap = (json['dynamicIntMap'] as Map)?.map( - (k, e) => MapEntry(k, e as int), - ) - ..objectDateTimeMap = - (json['objectDateTimeMap'] as Map)?.map( - (k, e) => MapEntry(k, e == null ? null : DateTime.parse(e as String)), - ) - ..crazyComplex = (json['crazyComplex'] as List) - ?.map((e) => (e as Map)?.map( - (k, e) => MapEntry( - k, - (e as Map)?.map( - (k, e) => MapEntry( - k, - (e as List) - ?.map((e) => (e as List) - ?.map((e) => e == null - ? null - : DateTime.parse(e as String)) - ?.toList()) - ?.toList()), - )), - )) - ?.toList() - ..val = (json['val'] as Map)?.map( - (k, e) => MapEntry(k, e as bool), - ) - ..writeNotNull = json['writeNotNull'] as bool - ..string = json[r'$string'] as String - ..simpleObject = json['simpleObject'] == null - ? null - : SimpleObject.fromJson(json['simpleObject'] as Map) - ..strictKeysObject = json['strictKeysObject'] == null - ? null - : StrictKeysObject.fromJson( - json['strictKeysObject'] as Map) - ..validatedPropertyNo42 = json['validatedPropertyNo42'] as int; -} - -Map _$KitchenSinkToJson(KitchenSink instance) { - final val = { - 'no-42': instance.ctorValidatedNo42, - 'dateTime': instance.dateTime?.toIso8601String(), - 'bigInt': instance.bigInt?.toString(), - }; - - void writeNotNull(String key, dynamic value) { - if (value != null) { - val[key] = value; - } - } - - writeNotNull('iterable', _$nullIfEmptyIterable(instance.iterable)?.toList()); - writeNotNull('dynamicIterable', - _$nullIfEmptyIterable(instance.dynamicIterable)?.toList()); - writeNotNull('objectIterable', - _$nullIfEmptyIterable(instance.objectIterable)?.toList()); - writeNotNull( - 'intIterable', _$nullIfEmptyIterable(instance.intIterable)?.toList()); - writeNotNull('set', _$nullIfEmptyIterable(instance.set)?.toList()); - writeNotNull( - 'dynamicSet', _$nullIfEmptyIterable(instance.dynamicSet)?.toList()); - writeNotNull( - 'objectSet', _$nullIfEmptyIterable(instance.objectSet)?.toList()); - writeNotNull('intSet', _$nullIfEmptyIterable(instance.intSet)?.toList()); - writeNotNull( - 'dateTimeSet', - _$nullIfEmptyIterable(instance.dateTimeSet) - ?.map((e) => e?.toIso8601String()) - ?.toList()); - writeNotNull( - 'datetime-iterable', - _$nullIfEmptyIterable(instance.dateTimeIterable) - ?.map((e) => e?.toIso8601String()) - ?.toList()); - writeNotNull('list', _$nullIfEmptyIterable(instance.list)); - writeNotNull('dynamicList', _$nullIfEmptyIterable(instance.dynamicList)); - writeNotNull('objectList', _$nullIfEmptyIterable(instance.objectList)); - writeNotNull('intList', _$nullIfEmptyIterable(instance.intList)); - writeNotNull( - 'dateTimeList', - _$nullIfEmptyIterable(instance.dateTimeList) - ?.map((e) => e?.toIso8601String()) - ?.toList()); - writeNotNull('map', _$nullIfEmptyMap(instance.map)); - writeNotNull('stringStringMap', _$nullIfEmptyMap(instance.stringStringMap)); - writeNotNull('dynamicIntMap', _$nullIfEmptyMap(instance.dynamicIntMap)); - writeNotNull( - 'objectDateTimeMap', - _$nullIfEmptyMap(instance.objectDateTimeMap) - ?.map((k, e) => MapEntry(k, e?.toIso8601String()))); - writeNotNull( - 'crazyComplex', - _$nullIfEmptyIterable(instance.crazyComplex) - ?.map((e) => e?.map((k, e) => MapEntry( - k, - e?.map((k, e) => MapEntry( - k, - e - ?.map( - (e) => e?.map((e) => e?.toIso8601String())?.toList()) - ?.toList()))))) - ?.toList()); - writeNotNull('val', _$nullIfEmptyMap(instance.val)); - val['writeNotNull'] = instance.writeNotNull; - val[r'$string'] = instance.string; - val['simpleObject'] = instance.simpleObject; - val['strictKeysObject'] = instance.strictKeysObject; - val['validatedPropertyNo42'] = instance.validatedPropertyNo42; - return val; -} - -T _$nullIfEmptyIterable(T source) => - (source == null || source.isEmpty) ? null : source; - -T _$nullIfEmptyMap(T source) => - (source == null || source.isEmpty) ? null : source; - -JsonConverterTestClass _$JsonConverterTestClassFromJson( - Map json) { - return JsonConverterTestClass() - ..duration = json['duration'] == null - ? null - : durationConverter.fromJson(json['duration'] as int) - ..durationList = (json['durationList'] as List) - ?.map((e) => e == null ? null : durationConverter.fromJson(e as int)) - ?.toList() - ..bigInt = json['bigInt'] == null - ? null - : const BigIntStringConverter().fromJson(json['bigInt'] as String) - ..bigIntMap = (json['bigIntMap'] as Map)?.map( - (k, e) => MapEntry( - k, - e == null - ? null - : const BigIntStringConverter().fromJson(e as String)), - ) - ..numberSilly = json['numberSilly'] == null - ? null - : TrivialNumberConverter.instance.fromJson(json['numberSilly'] as int) - ..numberSillySet = (json['numberSillySet'] as List) - ?.map((e) => e == null - ? null - : TrivialNumberConverter.instance.fromJson(e as int)) - ?.toSet() - ..dateTime = json['dateTime'] == null - ? null - : const EpochDateTimeConverter().fromJson(json['dateTime'] as int); -} - -Map _$JsonConverterTestClassToJson( - JsonConverterTestClass instance) { - final val = { - 'duration': instance.duration == null - ? null - : durationConverter.toJson(instance.duration), - }; - - void writeNotNull(String key, dynamic value) { - if (value != null) { - val[key] = value; - } - } - - writeNotNull( - 'durationList', - _$nullIfEmptyIterable(instance.durationList) - ?.map((e) => e == null ? null : durationConverter.toJson(e)) - ?.toList()); - val['bigInt'] = instance.bigInt == null - ? null - : const BigIntStringConverter().toJson(instance.bigInt); - writeNotNull( - 'bigIntMap', - _$nullIfEmptyMap(instance.bigIntMap)?.map((k, e) => MapEntry( - k, e == null ? null : const BigIntStringConverter().toJson(e)))); - val['numberSilly'] = instance.numberSilly == null - ? null - : TrivialNumberConverter.instance.toJson(instance.numberSilly); - writeNotNull( - 'numberSillySet', - _$nullIfEmptyIterable(instance.numberSillySet) - ?.map((e) => - e == null ? null : TrivialNumberConverter.instance.toJson(e)) - ?.toList()); - val['dateTime'] = instance.dateTime == null - ? null - : const EpochDateTimeConverter().toJson(instance.dateTime); - return val; -} - -JsonConverterGeneric _$JsonConverterGenericFromJson( - Map json) { - return JsonConverterGeneric() - ..item = json['item'] == null - ? null - : GenericConverter().fromJson(json['item'] as Map) - ..itemList = (json['itemList'] as List) - ?.map((e) => e == null - ? null - : GenericConverter().fromJson(e as Map)) - ?.toList() - ..itemMap = (json['itemMap'] as Map)?.map( - (k, e) => MapEntry( - k, - e == null - ? null - : GenericConverter().fromJson(e as Map)), - ); -} - -Map _$JsonConverterGenericToJson( - JsonConverterGeneric instance) { - final val = { - 'item': instance.item == null - ? null - : GenericConverter().toJson(instance.item), - }; - - void writeNotNull(String key, dynamic value) { - if (value != null) { - val[key] = value; - } - } - - writeNotNull( - 'itemList', - _$nullIfEmptyIterable(instance.itemList) - ?.map((e) => e == null ? null : GenericConverter().toJson(e)) - ?.toList()); - writeNotNull( - 'itemMap', - _$nullIfEmptyMap(instance.itemMap)?.map((k, e) => - MapEntry(k, e == null ? null : GenericConverter().toJson(e)))); - return val; -} diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_no_encode_empty__non_nullable.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_non_nullable.dart similarity index 96% rename from json_serializable/test/kitchen_sink/kitchen_sink.g_no_encode_empty__non_nullable.dart rename to json_serializable/test/kitchen_sink/kitchen_sink.g_non_nullable.dart index 70eb8ca52..71d5919c4 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_no_encode_empty__non_nullable.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_non_nullable.dart @@ -10,7 +10,7 @@ import 'kitchen_sink_interface.dart' as k; import 'simple_object.dart'; import 'strict_keys_object.dart'; -part 'kitchen_sink.g_no_encode_empty__non_nullable.g.dart'; +part 'kitchen_sink.g_non_nullable.g.dart'; // NOTE: these methods are replaced in the `non_nullable` cases to return // non-null values. @@ -25,13 +25,12 @@ const k.KitchenSinkFactory factory = _Factory(); class _Factory implements k.KitchenSinkFactory { const _Factory(); - String get description => 'no_encode_empty__non_nullable'; + String get description => 'non_nullable'; bool get anyMap => false; bool get checked => false; bool get nullable => false; bool get excludeNull => false; bool get explicitToJson => false; - bool get noEncodeEmpty => true; k.KitchenSink ctor({ int ctorValidatedNo42, @@ -61,7 +60,6 @@ class _Factory implements k.KitchenSinkFactory { @JsonSerializable( nullable: false, - encodeEmptyCollection: false, ) class KitchenSink implements k.KitchenSink { // NOTE: exposing these as Iterable, but storing the values as List @@ -156,7 +154,6 @@ class KitchenSink implements k.KitchenSink { @JsonSerializable( nullable: false, - encodeEmptyCollection: false, ) // referencing a top-level field should work @durationConverter @@ -186,7 +183,6 @@ class JsonConverterTestClass implements k.JsonConverterTestClass { @JsonSerializable( nullable: false, - encodeEmptyCollection: false, ) @GenericConverter() class JsonConverterGeneric { diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_no_encode_empty__non_nullable.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_non_nullable.g.dart similarity index 50% rename from json_serializable/test/kitchen_sink/kitchen_sink.g_no_encode_empty__non_nullable.g.dart rename to json_serializable/test/kitchen_sink/kitchen_sink.g_non_nullable.g.dart index 5bdfb5b63..dc26d4699 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_no_encode_empty__non_nullable.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_non_nullable.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -part of 'kitchen_sink.g_no_encode_empty__non_nullable.dart'; +part of 'kitchen_sink.g_non_nullable.dart'; // ************************************************************************** // JsonSerializableGenerator @@ -63,83 +63,50 @@ KitchenSink _$KitchenSinkFromJson(Map json) { ..validatedPropertyNo42 = json['validatedPropertyNo42'] as int; } -Map _$KitchenSinkToJson(KitchenSink instance) { - final val = { - 'no-42': instance.ctorValidatedNo42, - 'dateTime': instance.dateTime.toIso8601String(), - 'bigInt': instance.bigInt.toString(), - }; - - void writeNotNull(String key, dynamic value) { - if (value != null) { - val[key] = value; - } - } - - writeNotNull('iterable', _$nullIfEmptyIterable(instance.iterable)?.toList()); - writeNotNull('dynamicIterable', - _$nullIfEmptyIterable(instance.dynamicIterable)?.toList()); - writeNotNull('objectIterable', - _$nullIfEmptyIterable(instance.objectIterable)?.toList()); - writeNotNull( - 'intIterable', _$nullIfEmptyIterable(instance.intIterable)?.toList()); - writeNotNull('set', _$nullIfEmptyIterable(instance.set)?.toList()); - writeNotNull( - 'dynamicSet', _$nullIfEmptyIterable(instance.dynamicSet)?.toList()); - writeNotNull( - 'objectSet', _$nullIfEmptyIterable(instance.objectSet)?.toList()); - writeNotNull('intSet', _$nullIfEmptyIterable(instance.intSet)?.toList()); - writeNotNull( - 'dateTimeSet', - _$nullIfEmptyIterable(instance.dateTimeSet) - ?.map((e) => e.toIso8601String()) - ?.toList()); - writeNotNull( - 'datetime-iterable', - _$nullIfEmptyIterable(instance.dateTimeIterable) - ?.map((e) => e.toIso8601String()) - ?.toList()); - writeNotNull('list', _$nullIfEmptyIterable(instance.list)); - writeNotNull('dynamicList', _$nullIfEmptyIterable(instance.dynamicList)); - writeNotNull('objectList', _$nullIfEmptyIterable(instance.objectList)); - writeNotNull('intList', _$nullIfEmptyIterable(instance.intList)); - writeNotNull( - 'dateTimeList', - _$nullIfEmptyIterable(instance.dateTimeList) - ?.map((e) => e.toIso8601String()) - ?.toList()); - writeNotNull('map', _$nullIfEmptyMap(instance.map)); - writeNotNull('stringStringMap', _$nullIfEmptyMap(instance.stringStringMap)); - writeNotNull('dynamicIntMap', _$nullIfEmptyMap(instance.dynamicIntMap)); - writeNotNull( - 'objectDateTimeMap', - _$nullIfEmptyMap(instance.objectDateTimeMap) - ?.map((k, e) => MapEntry(k, e.toIso8601String()))); - writeNotNull( - 'crazyComplex', - _$nullIfEmptyIterable(instance.crazyComplex) - ?.map((e) => e.map((k, e) => MapEntry( +Map _$KitchenSinkToJson(KitchenSink instance) => + { + 'no-42': instance.ctorValidatedNo42, + 'dateTime': instance.dateTime.toIso8601String(), + 'bigInt': instance.bigInt.toString(), + 'iterable': instance.iterable.toList(), + 'dynamicIterable': instance.dynamicIterable.toList(), + 'objectIterable': instance.objectIterable.toList(), + 'intIterable': instance.intIterable.toList(), + 'set': instance.set.toList(), + 'dynamicSet': instance.dynamicSet.toList(), + 'objectSet': instance.objectSet.toList(), + 'intSet': instance.intSet.toList(), + 'dateTimeSet': + instance.dateTimeSet.map((e) => e.toIso8601String()).toList(), + 'datetime-iterable': + instance.dateTimeIterable.map((e) => e.toIso8601String()).toList(), + 'list': instance.list, + 'dynamicList': instance.dynamicList, + 'objectList': instance.objectList, + 'intList': instance.intList, + 'dateTimeList': + instance.dateTimeList.map((e) => e.toIso8601String()).toList(), + 'map': instance.map, + 'stringStringMap': instance.stringStringMap, + 'dynamicIntMap': instance.dynamicIntMap, + 'objectDateTimeMap': instance.objectDateTimeMap + .map((k, e) => MapEntry(k, e.toIso8601String())), + 'crazyComplex': instance.crazyComplex + .map((e) => e.map((k, e) => MapEntry( k, e.map((k, e) => MapEntry( k, e .map((e) => e.map((e) => e.toIso8601String()).toList()) .toList()))))) - ?.toList()); - writeNotNull('val', _$nullIfEmptyMap(instance.val)); - val['writeNotNull'] = instance.writeNotNull; - val[r'$string'] = instance.string; - val['simpleObject'] = instance.simpleObject; - val['strictKeysObject'] = instance.strictKeysObject; - val['validatedPropertyNo42'] = instance.validatedPropertyNo42; - return val; -} - -T _$nullIfEmptyIterable(T source) => - (source == null || source.isEmpty) ? null : source; - -T _$nullIfEmptyMap(T source) => - (source == null || source.isEmpty) ? null : source; + .toList(), + 'val': instance.val, + 'writeNotNull': instance.writeNotNull, + r'$string': instance.string, + 'simpleObject': instance.simpleObject, + 'strictKeysObject': instance.strictKeysObject, + 'validatedPropertyNo42': instance.validatedPropertyNo42 + }; JsonConverterTestClass _$JsonConverterTestClassFromJson( Map json) { @@ -163,37 +130,21 @@ JsonConverterTestClass _$JsonConverterTestClassFromJson( } Map _$JsonConverterTestClassToJson( - JsonConverterTestClass instance) { - final val = { - 'duration': durationConverter.toJson(instance.duration), - }; - - void writeNotNull(String key, dynamic value) { - if (value != null) { - val[key] = value; - } - } - - writeNotNull( - 'durationList', - _$nullIfEmptyIterable(instance.durationList) - ?.map(durationConverter.toJson) - ?.toList()); - val['bigInt'] = const BigIntStringConverter().toJson(instance.bigInt); - writeNotNull( - 'bigIntMap', - _$nullIfEmptyMap(instance.bigIntMap)?.map( - (k, e) => MapEntry(k, const BigIntStringConverter().toJson(e)))); - val['numberSilly'] = - TrivialNumberConverter.instance.toJson(instance.numberSilly); - writeNotNull( - 'numberSillySet', - _$nullIfEmptyIterable(instance.numberSillySet) - ?.map(TrivialNumberConverter.instance.toJson) - ?.toList()); - val['dateTime'] = const EpochDateTimeConverter().toJson(instance.dateTime); - return val; -} + JsonConverterTestClass instance) => + { + 'duration': durationConverter.toJson(instance.duration), + 'durationList': + instance.durationList.map(durationConverter.toJson).toList(), + 'bigInt': const BigIntStringConverter().toJson(instance.bigInt), + 'bigIntMap': instance.bigIntMap + .map((k, e) => MapEntry(k, const BigIntStringConverter().toJson(e))), + 'numberSilly': + TrivialNumberConverter.instance.toJson(instance.numberSilly), + 'numberSillySet': instance.numberSillySet + .map(TrivialNumberConverter.instance.toJson) + .toList(), + 'dateTime': const EpochDateTimeConverter().toJson(instance.dateTime) + }; JsonConverterGeneric _$JsonConverterGenericFromJson( Map json) { @@ -210,25 +161,10 @@ JsonConverterGeneric _$JsonConverterGenericFromJson( } Map _$JsonConverterGenericToJson( - JsonConverterGeneric instance) { - final val = { - 'item': GenericConverter().toJson(instance.item), - }; - - void writeNotNull(String key, dynamic value) { - if (value != null) { - val[key] = value; - } - } - - writeNotNull( - 'itemList', - _$nullIfEmptyIterable(instance.itemList) - ?.map(GenericConverter().toJson) - ?.toList()); - writeNotNull( - 'itemMap', - _$nullIfEmptyMap(instance.itemMap) - ?.map((k, e) => MapEntry(k, GenericConverter().toJson(e)))); - return val; -} + JsonConverterGeneric instance) => + { + 'item': GenericConverter().toJson(instance.item), + 'itemList': instance.itemList.map(GenericConverter().toJson).toList(), + 'itemMap': instance.itemMap + .map((k, e) => MapEntry(k, GenericConverter().toJson(e))) + }; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart b/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart index 77abe60ee..28f1b4a2e 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart @@ -12,7 +12,6 @@ abstract class KitchenSinkFactory { bool get nullable; bool get excludeNull; bool get explicitToJson; - bool get noEncodeEmpty; KitchenSink ctor({ int ctorValidatedNo42, diff --git a/json_serializable/test/kitchen_sink/kitchen_sink_test.dart b/json_serializable/test/kitchen_sink/kitchen_sink_test.dart index feb58d436..6351ddedb 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink_test.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink_test.dart @@ -74,12 +74,10 @@ const _jsonConverterValidValues = { }; void _nonNullableTests(KitchenSinkFactory factory) { - if (!factory.noEncodeEmpty) { - test('with null values fails serialization', () { - expect(() => (factory.ctor()..objectDateTimeMap = null).toJson(), - throwsNoSuchMethodError); - }); - } + test('with null values fails serialization', () { + expect(() => (factory.ctor()..objectDateTimeMap = null).toJson(), + throwsNoSuchMethodError); + }); test('with empty json fails deserialization', () { Matcher matcher; @@ -108,8 +106,7 @@ void _nonNullableTests(KitchenSinkFactory factory) { void _nullableTests(KitchenSinkFactory factory) { void roundTripSink(KitchenSink p) { - roundTripObject(p, factory.fromJson, - skipObjectEquals: factory.noEncodeEmpty); + roundTripObject(p, factory.fromJson); } test('nullable values are allowed in the nullable version', () { @@ -118,9 +115,6 @@ void _nullableTests(KitchenSinkFactory factory) { if (factory.excludeNull) { expect(json, isEmpty); - } else if (factory.noEncodeEmpty) { - expect(json.keys, - _jsonConverterValidValues.keys.toSet()..removeAll(_iterableMapKeys)); } else { expect(json.values, everyElement(isNull)); expect(json.keys, unorderedEquals(_jsonConverterValidValues.keys)); @@ -136,8 +130,6 @@ void _nullableTests(KitchenSinkFactory factory) { if (factory.excludeNull) { expect(encoded, isEmpty); - } else if (factory.noEncodeEmpty) { - expect(encoded.keys, _validValueMinusIterableMapKeys); } else { expect(encoded.keys, orderedEquals(_validValues.keys)); @@ -197,70 +189,61 @@ void _anyMapTests(KitchenSinkFactory factory) { } void _sharedTests(KitchenSinkFactory factory) { - if (factory.noEncodeEmpty && !factory.nullable) { - test('empty collections throw errors on round-trip', () { - final item = factory.ctor(); - expect(() => factory.fromJson(item.toJson()), throwsNoSuchMethodError); - }); - } else { - test('empty', () { - final item = factory.ctor(); - roundTripObject(item, factory.fromJson); - }); + test('empty', () { + final item = factory.ctor(); + roundTripObject(item, factory.fromJson); + }); - test('list and map of DateTime - not null', () { - final now = DateTime.now(); - final item = factory.ctor(dateTimeIterable: [now]) - ..dateTimeList = [now, now] - ..objectDateTimeMap = {'value': now}; + test('list and map of DateTime - not null', () { + final now = DateTime.now(); + final item = factory.ctor(dateTimeIterable: [now]) + ..dateTimeList = [now, now] + ..objectDateTimeMap = {'value': now}; - roundTripObject(item, factory.fromJson); - }); + roundTripObject(item, factory.fromJson); + }); - test('complex nested type - not null', () { - final item = factory.ctor() - ..crazyComplex = [ - {}, - { - 'empty': {}, - 'items': { - 'empty': [], - 'items': [ - [], - [DateTime.now()] - ] - } + test('complex nested type - not null', () { + final item = factory.ctor() + ..crazyComplex = [ + {}, + { + 'empty': {}, + 'items': { + 'empty': [], + 'items': [ + [], + [DateTime.now()] + ] } - ]; - roundTripObject(item, factory.fromJson); - }); + } + ]; + roundTripObject(item, factory.fromJson); + }); - test('round trip valid, empty values', () { - final values = Map.fromEntries(_validValues.entries.map((e) { - var value = e.value; - if (_iterableMapKeys.contains(e.key)) { - if (value is List) { - value = []; - } else { - assert(value is Map); - value = {}; - } + test('round trip valid, empty values', () { + final values = Map.fromEntries(_validValues.entries.map((e) { + var value = e.value; + if (_iterableMapKeys.contains(e.key)) { + if (value is List) { + value = []; + } else { + assert(value is Map); + value = {}; } - return MapEntry(e.key, value); - })); + } + return MapEntry(e.key, value); + })); - final validInstance = factory.fromJson(values); + final validInstance = factory.fromJson(values); - roundTripObject(validInstance, factory.fromJson, skipObjectEquals: true); - }); - } + roundTripObject(validInstance, factory.fromJson); + }); test('JSON keys should be defined in field/property order', () { final json = factory.ctor().toJson(); if (factory.excludeNull && factory.nullable) { expect(json.keys, isEmpty); - } else if (factory.noEncodeEmpty) { - expect(json.keys, orderedEquals(_validValueMinusIterableMapKeys)); } else { expect(json.keys, orderedEquals(_validValues.keys)); } @@ -439,6 +422,3 @@ const _iterableMapKeys = [ 'stringStringMap', _generatedLocalVarName, ]; - -final _validValueMinusIterableMapKeys = - List.unmodifiable(_validValues.keys.toSet()..removeAll(_iterableMapKeys)); diff --git a/json_serializable/test/shared_config.dart b/json_serializable/test/shared_config.dart index e9e1500ba..94f69f4f0 100644 --- a/json_serializable/test/shared_config.dart +++ b/json_serializable/test/shared_config.dart @@ -16,7 +16,6 @@ final generatorConfigNonDefaultJson = createFactory: false, createToJson: false, disallowUnrecognizedKeys: true, - encodeEmptyCollection: false, explicitToJson: true, fieldRename: FieldRename.kebab, includeIfNull: false, diff --git a/json_serializable/test/src/_json_serializable_test_input.dart b/json_serializable/test/src/_json_serializable_test_input.dart index d92e91632..afe880f13 100644 --- a/json_serializable/test/src/_json_serializable_test_input.dart +++ b/json_serializable/test/src/_json_serializable_test_input.dart @@ -434,93 +434,6 @@ class MyList extends ListBase { } } -@ShouldGenerate( - r''' -EncodeEmptyCollectionAsNullOnField _$EncodeEmptyCollectionAsNullOnFieldFromJson( - Map json) { - return EncodeEmptyCollectionAsNullOnField()..field = json['field'] as List; -} - -Map _$EncodeEmptyCollectionAsNullOnFieldToJson( - EncodeEmptyCollectionAsNullOnField instance) { - final val = {}; - - void writeNotNull(String key, dynamic value) { - if (value != null) { - val[key] = value; - } - } - - writeNotNull('field', _$nullIfEmptyIterable(instance.field)); - return val; -} - -T _$nullIfEmptyIterable(T source) => - (source == null || source.isEmpty) ? null : source; -''', - configurations: ['default'], -) -@JsonSerializable() -class EncodeEmptyCollectionAsNullOnField { - @JsonKey(encodeEmptyCollection: false) - List field; -} - -@ShouldThrow( - 'Error with `@JsonKey` on `field`. `encodeEmptyCollection: false` is only ' - 'valid fields of type Iterable, List, Set, or Map.', - element: 'field', -) -@JsonSerializable() -class EncodeEmptyCollectionAsNullOnNonCollectionField { - @JsonKey(encodeEmptyCollection: false) - int field; -} - -@ShouldThrow( - 'Error with `@JsonKey` on `field`. Cannot set `encodeEmptyCollection: false` ' - 'if `includeIfNull: true`.', - element: 'field', -) -@JsonSerializable() -class EmptyCollectionAsNullAndIncludeIfNullField { - @JsonKey(encodeEmptyCollection: false, includeIfNull: true) - List field; -} - -@ShouldGenerate( - r''' -EmptyCollectionAsNullAndIncludeIfNullClass - _$EmptyCollectionAsNullAndIncludeIfNullClassFromJson( - Map json) { - return EmptyCollectionAsNullAndIncludeIfNullClass() - ..field = json['field'] as List; -} - -Map _$EmptyCollectionAsNullAndIncludeIfNullClassToJson( - EmptyCollectionAsNullAndIncludeIfNullClass instance) { - final val = {}; - - void writeNotNull(String key, dynamic value) { - if (value != null) { - val[key] = value; - } - } - - writeNotNull('field', _$nullIfEmptyIterable(instance.field)); - return val; -} - -T _$nullIfEmptyIterable(T source) => - (source == null || source.isEmpty) ? null : source; -''', - configurations: ['default'], -) -@JsonSerializable(encodeEmptyCollection: false, includeIfNull: true) -class EmptyCollectionAsNullAndIncludeIfNullClass { - List field; -} - mixin _PropInMixinI448RegressionMixin { @JsonKey(nullable: true) int nullable; diff --git a/json_serializable/test/test_sources/test_sources.dart b/json_serializable/test/test_sources/test_sources.dart index 53f332423..d87b7da8e 100644 --- a/json_serializable/test/test_sources/test_sources.dart +++ b/json_serializable/test/test_sources/test_sources.dart @@ -11,7 +11,6 @@ class ConfigurationImplicitDefaults { createFactory: true, createToJson: true, disallowUnrecognizedKeys: false, - encodeEmptyCollection: true, explicitToJson: false, fieldRename: FieldRename.none, includeIfNull: true, diff --git a/json_serializable/test/test_utils.dart b/json_serializable/test/test_utils.dart index 5057ac67c..cae65023a 100644 --- a/json_serializable/test/test_utils.dart +++ b/json_serializable/test/test_utils.dart @@ -8,18 +8,12 @@ import 'package:test/test.dart'; final throwsCastError = throwsA(isCastError); -T roundTripObject( - T object, - T factory(Map json), { - bool skipObjectEquals = false, -}) { +T roundTripObject(T object, T factory(Map json)) { final data = loudEncode(object); final object2 = factory(json.decode(data) as Map); - if (!skipObjectEquals) { - expect(object2, equals(object)); - } + expect(object2, equals(object)); final json2 = loudEncode(object2); diff --git a/json_serializable/tool/test_builder.dart b/json_serializable/tool/test_builder.dart index ee0b41afb..1e3eaf2b2 100644 --- a/json_serializable/tool/test_builder.dart +++ b/json_serializable/tool/test_builder.dart @@ -116,8 +116,6 @@ const _configReplacements = { 'explicit_to_json': _Replacement.addJsonSerializableKey('explicitToJson', true), 'exclude_null': _Replacement.addJsonSerializableKey('includeIfNull', false), - 'no_encode_empty': - _Replacement.addJsonSerializableKey('encodeEmptyCollection', false), }; const _kitchenSinkReplacements = { @@ -145,12 +143,6 @@ const _kitchenSinkReplacements = { 'bool get checked => true;', ) ], - 'no_encode_empty': [ - _Replacement( - 'bool get noEncodeEmpty => false;', - 'bool get noEncodeEmpty => true;', - ), - ], 'exclude_null': [ _Replacement( 'bool get excludeNull => false;', @@ -231,12 +223,9 @@ const _fileConfigurationMap = >>{ {'any_map', 'checked', 'non_nullable'}, {'any_map', 'non_nullable'}, {'any_map'}, - {'no_encode_empty'}, - {'no_encode_empty', 'exclude_null'}, - {'no_encode_empty', 'non_nullable'}, - {'no_encode_empty', 'exclude_null', 'non_nullable'}, - {'exclude_null', 'non_nullable'}, {'exclude_null'}, + {'non_nullable'}, + {'exclude_null', 'non_nullable'}, {'explicit_to_json'}, }, 'default_value': { From a581e5cc9ee25bf4ad61e8f825a311289ade905c Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 13 May 2019 08:36:19 -0700 Subject: [PATCH 138/569] Always pass the source value to conversion functions, even if nullable is false (#483) Fixes https://github.com/dart-lang/json_serializable/issues/442 --- analysis_options.yaml | 1 - json_serializable/CHANGELOG.md | 6 ++ json_serializable/lib/src/json_key_utils.dart | 24 ++++- .../lib/src/type_helpers/convert_helper.dart | 34 +++--- .../type_helpers/json_converter_helper.dart | 15 +-- json_serializable/lib/type_helper.dart | 2 +- .../test/generic_files/generic_class.g.dart | 88 +++++---------- .../test/integration/json_test_common.dart | 13 ++- .../test/integration/json_test_example.g.dart | 12 +-- .../test/kitchen_sink/json_converters.dart | 16 +-- .../test/kitchen_sink/kitchen_sink.g.dart | 87 +++++---------- .../kitchen_sink.g_any_map.g.dart | 87 +++++---------- .../kitchen_sink.g_exclude_null.g.dart | 100 +++++------------- .../kitchen_sink.g_explicit_to_json.g.dart | 87 +++++---------- .../test/src/default_value_input.dart | 19 ++-- .../test/src/generic_test_input.dart | 35 +++--- .../test/src/json_converter_test_input.dart | 74 +++++-------- .../test/src/to_from_json_test_input.dart | 25 ++--- .../test/src/unknown_type_test_input.dart | 7 +- 19 files changed, 285 insertions(+), 447 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index 4b73f7c12..4d865a45c 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -42,7 +42,6 @@ linter: - library_prefixes - list_remove_unrelated_type - literal_only_boolean_expressions - - no_adjacent_strings_in_list - no_duplicate_case_values - non_constant_identifier_names - null_closures diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 24db63ad0..26c8989a9 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -3,6 +3,12 @@ - **BREAKING** Removed support for `JsonSerializable.useWrappers`. - **BREAKING** Removed support for `JsonSerializable.generateToJsonFunction`. - **BREAKING** Removed support for `encodeEmptyCollection`. +- **BREAKING** If a field has a conversion function defined – either + `JsonKey.toJson` or a custom `JsonConverter` annotation – don't intercept + `null` values, even if `nullable` is explicitly set to `false`. This allows + these functions to provide alternative values for `null` – such as an empty + collection – which replaces the functionality provided by + `encodeEmptyCollection`. ## 2.3.0 diff --git a/json_serializable/lib/src/json_key_utils.dart b/json_serializable/lib/src/json_key_utils.dart index 9f14444ed..0d66f25d8 100644 --- a/json_serializable/lib/src/json_key_utils.dart +++ b/json_serializable/lib/src/json_key_utils.dart @@ -5,6 +5,7 @@ import 'package:analyzer/dart/constant/value.dart'; import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/type.dart'; +import 'package:build/build.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:source_gen/source_gen.dart'; @@ -16,6 +17,21 @@ final _jsonKeyExpando = Expando(); JsonKey jsonKeyForField(FieldElement field, JsonSerializable classAnnotation) => _jsonKeyExpando[field] ??= _from(field, classAnnotation); +/// Will log "info" if [element] has an explicit value for [JsonKey.nullable] +/// telling the programmer that it will be ignored. +void logFieldWithConversionFunction(FieldElement element) { + final jsonKey = _jsonKeyExpando[element]; + if (_explicitNullableExpando[jsonKey] ?? false) { + log.info( + 'The `JsonKey.nullable` value on ' + '`${element.enclosingElement.name}.${element.name}` will be ignored ' + 'because a custom conversion function is being used.', + ); + + _explicitNullableExpando[jsonKey] = null; + } +} + JsonKey _from(FieldElement element, JsonSerializable classAnnotation) { // If an annotation exists on `element` the source is a 'real' field. // If the result is `null`, check the getter – it is a property. @@ -127,7 +143,7 @@ JsonKey _populateJsonKey( } } - return JsonKey( + final jsonKey = JsonKey( defaultValue: defaultValue, disallowNullValue: disallowNullValue ?? false, ignore: ignore ?? false, @@ -137,8 +153,14 @@ JsonKey _populateJsonKey( nullable: nullable ?? classAnnotation.nullable, required: required ?? false, ); + + _explicitNullableExpando[jsonKey] = nullable != null; + + return jsonKey; } +final _explicitNullableExpando = Expando('explicit nullable'); + String _encodedFieldName(JsonSerializable classAnnotation, String jsonKeyNameValue, FieldElement fieldElement) { if (jsonKeyNameValue != null) { diff --git a/json_serializable/lib/src/type_helpers/convert_helper.dart b/json_serializable/lib/src/type_helpers/convert_helper.dart index e617d8c09..b281161d1 100644 --- a/json_serializable/lib/src/type_helpers/convert_helper.dart +++ b/json_serializable/lib/src/type_helpers/convert_helper.dart @@ -4,6 +4,7 @@ import 'package:analyzer/dart/element/type.dart'; +import '../json_key_utils.dart'; import '../shared_checkers.dart'; import '../type_helper.dart'; @@ -18,6 +19,7 @@ class ConvertData { abstract class TypeHelperContextWithConvert extends TypeHelperContext { ConvertData get serializeConvertData; + ConvertData get deserializeConvertData; } @@ -28,30 +30,28 @@ class ConvertHelper extends TypeHelper { String serialize(DartType targetType, String expression, TypeHelperContextWithConvert context) { final toJsonData = context.serializeConvertData; - if (toJsonData != null) { - assert(toJsonData.paramType is TypeParameterType || - targetType.isAssignableTo(toJsonData.paramType)); - return toJsonSerializeImpl(toJsonData.name, expression, context.nullable); + if (toJsonData == null) { + return null; } - return null; + + logFieldWithConversionFunction(context.fieldElement); + + assert(toJsonData.paramType is TypeParameterType || + targetType.isAssignableTo(toJsonData.paramType)); + return '${toJsonData.name}($expression)'; } @override String deserialize(DartType targetType, String expression, TypeHelperContextWithConvert context) { final fromJsonData = context.deserializeConvertData; - if (fromJsonData != null) { - final asContent = asStatement(fromJsonData.paramType); - final result = '${fromJsonData.name}($expression$asContent)'; - return commonNullPrefix(context.nullable, expression, result).toString(); + if (fromJsonData == null) { + return null; } - return null; - } -} -/// Exposed to support `EncodeHelper` – not exposed publicly. -String toJsonSerializeImpl( - String toJsonDataName, String expression, bool nullable) { - final result = '$toJsonDataName($expression)'; - return commonNullPrefix(nullable, expression, result).toString(); + logFieldWithConversionFunction(context.fieldElement); + + final asContent = asStatement(fromJsonData.paramType); + return '${fromJsonData.name}($expression$asContent)'; + } } diff --git a/json_serializable/lib/src/type_helpers/json_converter_helper.dart b/json_serializable/lib/src/type_helpers/json_converter_helper.dart index d7f5a42c0..7eb8a0b5c 100644 --- a/json_serializable/lib/src/type_helpers/json_converter_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_converter_helper.dart @@ -8,6 +8,7 @@ import 'package:analyzer/dart/element/type.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:source_gen/source_gen.dart'; +import '../json_key_utils.dart'; import '../shared_checkers.dart'; import '../type_helper.dart'; @@ -25,8 +26,9 @@ class JsonConverterHelper extends TypeHelper { return null; } - return commonNullPrefix(context.nullable, expression, - LambdaResult(expression, '${converter.accessString}.toJson')); + logFieldWithConversionFunction(context.fieldElement); + + return LambdaResult(expression, '${converter.accessString}.toJson'); } @override @@ -39,11 +41,10 @@ class JsonConverterHelper extends TypeHelper { final asContent = asStatement(converter.jsonType); - return commonNullPrefix( - context.nullable, - expression, - LambdaResult( - '$expression$asContent', '${converter.accessString}.fromJson')); + logFieldWithConversionFunction(context.fieldElement); + + return LambdaResult( + '$expression$asContent', '${converter.accessString}.fromJson'); } } diff --git a/json_serializable/lib/type_helper.dart b/json_serializable/lib/type_helper.dart index 785d949f8..167123fd0 100644 --- a/json_serializable/lib/type_helper.dart +++ b/json_serializable/lib/type_helper.dart @@ -6,7 +6,7 @@ export 'src/shared_checkers.dart' show simpleJsonTypeChecker, typeArgumentsOf; export 'src/type_helper.dart' show TypeHelperContext, TypeHelper, UnsupportedTypeError; export 'src/type_helpers/big_int_helper.dart'; -export 'src/type_helpers/convert_helper.dart' hide toJsonSerializeImpl; +export 'src/type_helpers/convert_helper.dart'; export 'src/type_helpers/date_time_helper.dart'; export 'src/type_helpers/enum_helper.dart'; export 'src/type_helpers/iterable_helper.dart'; diff --git a/json_serializable/test/generic_files/generic_class.g.dart b/json_serializable/test/generic_files/generic_class.g.dart index ebd98f635..ff93fc0cd 100644 --- a/json_serializable/test/generic_files/generic_class.g.dart +++ b/json_serializable/test/generic_files/generic_class.g.dart @@ -9,43 +9,26 @@ part of 'generic_class.dart'; GenericClass _$GenericClassFromJson( Map json) { return GenericClass() - ..fieldObject = json['fieldObject'] == null - ? null - : GenericClass._dataFromJson( - json['fieldObject'] as Map) - ..fieldDynamic = json['fieldDynamic'] == null - ? null - : GenericClass._dataFromJson( - json['fieldDynamic'] as Map) - ..fieldInt = json['fieldInt'] == null - ? null - : GenericClass._dataFromJson(json['fieldInt'] as Map) - ..fieldT = json['fieldT'] == null - ? null - : GenericClass._dataFromJson(json['fieldT'] as Map) - ..fieldS = json['fieldS'] == null - ? null - : GenericClass._dataFromJson(json['fieldS'] as Map); + ..fieldObject = + GenericClass._dataFromJson(json['fieldObject'] as Map) + ..fieldDynamic = + GenericClass._dataFromJson(json['fieldDynamic'] as Map) + ..fieldInt = + GenericClass._dataFromJson(json['fieldInt'] as Map) + ..fieldT = + GenericClass._dataFromJson(json['fieldT'] as Map) + ..fieldS = + GenericClass._dataFromJson(json['fieldS'] as Map); } Map _$GenericClassToJson( GenericClass instance) => { - 'fieldObject': instance.fieldObject == null - ? null - : GenericClass._dataToJson(instance.fieldObject), - 'fieldDynamic': instance.fieldDynamic == null - ? null - : GenericClass._dataToJson(instance.fieldDynamic), - 'fieldInt': instance.fieldInt == null - ? null - : GenericClass._dataToJson(instance.fieldInt), - 'fieldT': instance.fieldT == null - ? null - : GenericClass._dataToJson(instance.fieldT), - 'fieldS': instance.fieldS == null - ? null - : GenericClass._dataToJson(instance.fieldS) + 'fieldObject': GenericClass._dataToJson(instance.fieldObject), + 'fieldDynamic': GenericClass._dataToJson(instance.fieldDynamic), + 'fieldInt': GenericClass._dataToJson(instance.fieldInt), + 'fieldT': GenericClass._dataToJson(instance.fieldT), + 'fieldS': GenericClass._dataToJson(instance.fieldS) }; GenericClassWithConverter @@ -55,20 +38,14 @@ GenericClassWithConverter ..fieldObject = json['fieldObject'] ..fieldDynamic = json['fieldDynamic'] ..fieldInt = json['fieldInt'] as int - ..fieldT = json['fieldT'] == null - ? null - : _SimpleConverter().fromJson(json['fieldT'] as Map) - ..fieldS = json['fieldS'] == null - ? null - : _SimpleConverter().fromJson(json['fieldS'] as Map) - ..duration = json['duration'] == null - ? null - : const _DurationMillisecondConverter() - .fromJson(json['duration'] as int) - ..listDuration = json['listDuration'] == null - ? null - : const _DurationListMillisecondConverter() - .fromJson(json['listDuration'] as int); + ..fieldT = + _SimpleConverter().fromJson(json['fieldT'] as Map) + ..fieldS = + _SimpleConverter().fromJson(json['fieldS'] as Map) + ..duration = + const _DurationMillisecondConverter().fromJson(json['duration'] as int) + ..listDuration = const _DurationListMillisecondConverter() + .fromJson(json['listDuration'] as int); } Map _$GenericClassWithConverterToJson( @@ -77,17 +54,10 @@ Map _$GenericClassWithConverterToJson( 'fieldObject': instance.fieldObject, 'fieldDynamic': instance.fieldDynamic, 'fieldInt': instance.fieldInt, - 'fieldT': instance.fieldT == null - ? null - : _SimpleConverter().toJson(instance.fieldT), - 'fieldS': instance.fieldS == null - ? null - : _SimpleConverter().toJson(instance.fieldS), - 'duration': instance.duration == null - ? null - : const _DurationMillisecondConverter().toJson(instance.duration), - 'listDuration': instance.listDuration == null - ? null - : const _DurationListMillisecondConverter() - .toJson(instance.listDuration) + 'fieldT': _SimpleConverter().toJson(instance.fieldT), + 'fieldS': _SimpleConverter().toJson(instance.fieldS), + 'duration': + const _DurationMillisecondConverter().toJson(instance.duration), + 'listDuration': const _DurationListMillisecondConverter() + .toJson(instance.listDuration) }; diff --git a/json_serializable/test/integration/json_test_common.dart b/json_serializable/test/integration/json_test_common.dart index 86c4b4c16..3fb55e77d 100644 --- a/json_serializable/test/integration/json_test_common.dart +++ b/json_serializable/test/integration/json_test_common.dart @@ -25,11 +25,15 @@ enum StatusCode { notFound } -Duration durationFromInt(int ms) => Duration(milliseconds: ms); -int durationToInt(Duration duration) => duration.inMilliseconds; +Duration durationFromInt(int ms) => + ms == null ? null : Duration(milliseconds: ms); -DateTime dateTimeFromEpochUs(int us) => DateTime.fromMicrosecondsSinceEpoch(us); -int dateTimeToEpochUs(DateTime dateTime) => dateTime.microsecondsSinceEpoch; +int durationToInt(Duration duration) => duration?.inMilliseconds; + +DateTime dateTimeFromEpochUs(int us) => + us == null ? null : DateTime.fromMicrosecondsSinceEpoch(us); + +int dateTimeToEpochUs(DateTime dateTime) => dateTime?.microsecondsSinceEpoch; bool deepEquals(a, b) => const DeepCollectionEquality().equals(a, b); @@ -38,6 +42,7 @@ class Platform { static const Platform foo = Platform._('foo'); static const Platform undefined = Platform._('undefined'); + const Platform._(this.description); factory Platform.fromJson(String value) { diff --git a/json_serializable/test/integration/json_test_example.g.dart b/json_serializable/test/integration/json_test_example.g.dart index 27ee513b7..54164e8ea 100644 --- a/json_serializable/test/integration/json_test_example.g.dart +++ b/json_serializable/test/integration/json_test_example.g.dart @@ -159,11 +159,8 @@ Numbers _$NumbersFromJson(Map json) { (json['doubles'] as List)?.map((e) => (e as num)?.toDouble())?.toList() ..nnDoubles = (json['nnDoubles'] as List).map((e) => (e as num).toDouble()).toList() - ..duration = json['duration'] == null - ? null - : durationFromInt(json['duration'] as int) - ..date = - json['date'] == null ? null : dateTimeFromEpochUs(json['date'] as int); + ..duration = durationFromInt(json['duration'] as int) + ..date = dateTimeFromEpochUs(json['date'] as int); } Map _$NumbersToJson(Numbers instance) => { @@ -171,7 +168,6 @@ Map _$NumbersToJson(Numbers instance) => { 'nums': instance.nums, 'doubles': instance.doubles, 'nnDoubles': instance.nnDoubles, - 'duration': - instance.duration == null ? null : durationToInt(instance.duration), - 'date': instance.date == null ? null : dateTimeToEpochUs(instance.date) + 'duration': durationToInt(instance.duration), + 'date': dateTimeToEpochUs(instance.date) }; diff --git a/json_serializable/test/kitchen_sink/json_converters.dart b/json_serializable/test/kitchen_sink/json_converters.dart index 11779f98f..f4b24d8b1 100644 --- a/json_serializable/test/kitchen_sink/json_converters.dart +++ b/json_serializable/test/kitchen_sink/json_converters.dart @@ -29,17 +29,17 @@ class TrivialNumberConverter implements JsonConverter { TrivialNumber fromJson(int json) => TrivialNumber(json); @override - int toJson(TrivialNumber object) => object.value; + int toJson(TrivialNumber object) => object?.value; } class BigIntStringConverter implements JsonConverter { const BigIntStringConverter(); @override - BigInt fromJson(String json) => BigInt.parse(json); + BigInt fromJson(String json) => json == null ? null : BigInt.parse(json); @override - String toJson(BigInt object) => object.toString(); + String toJson(BigInt object) => object?.toString(); } const durationConverter = DurationMillisecondConverter(); @@ -48,18 +48,20 @@ class DurationMillisecondConverter implements JsonConverter { const DurationMillisecondConverter(); @override - Duration fromJson(int json) => Duration(milliseconds: json); + Duration fromJson(int json) => + json == null ? null : Duration(milliseconds: json); @override - int toJson(Duration object) => object.inMilliseconds; + int toJson(Duration object) => object?.inMilliseconds; } class EpochDateTimeConverter implements JsonConverter { const EpochDateTimeConverter(); @override - DateTime fromJson(int json) => DateTime.fromMillisecondsSinceEpoch(json); + DateTime fromJson(int json) => + json == null ? null : DateTime.fromMillisecondsSinceEpoch(json); @override - int toJson(DateTime object) => object.millisecondsSinceEpoch; + int toJson(DateTime object) => object?.millisecondsSinceEpoch; } diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g.dart index 7f68f6054..ec0723c72 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g.dart @@ -126,90 +126,61 @@ Map _$KitchenSinkToJson(KitchenSink instance) => JsonConverterTestClass _$JsonConverterTestClassFromJson( Map json) { return JsonConverterTestClass() - ..duration = json['duration'] == null - ? null - : durationConverter.fromJson(json['duration'] as int) + ..duration = durationConverter.fromJson(json['duration'] as int) ..durationList = (json['durationList'] as List) - ?.map((e) => e == null ? null : durationConverter.fromJson(e as int)) + ?.map((e) => durationConverter.fromJson(e as int)) ?.toList() - ..bigInt = json['bigInt'] == null - ? null - : const BigIntStringConverter().fromJson(json['bigInt'] as String) + ..bigInt = const BigIntStringConverter().fromJson(json['bigInt'] as String) ..bigIntMap = (json['bigIntMap'] as Map)?.map( - (k, e) => MapEntry( - k, - e == null - ? null - : const BigIntStringConverter().fromJson(e as String)), + (k, e) => + MapEntry(k, const BigIntStringConverter().fromJson(e as String)), ) - ..numberSilly = json['numberSilly'] == null - ? null - : TrivialNumberConverter.instance.fromJson(json['numberSilly'] as int) + ..numberSilly = + TrivialNumberConverter.instance.fromJson(json['numberSilly'] as int) ..numberSillySet = (json['numberSillySet'] as List) - ?.map((e) => e == null - ? null - : TrivialNumberConverter.instance.fromJson(e as int)) + ?.map((e) => TrivialNumberConverter.instance.fromJson(e as int)) ?.toSet() - ..dateTime = json['dateTime'] == null - ? null - : const EpochDateTimeConverter().fromJson(json['dateTime'] as int); + ..dateTime = + const EpochDateTimeConverter().fromJson(json['dateTime'] as int); } Map _$JsonConverterTestClassToJson( JsonConverterTestClass instance) => { - 'duration': instance.duration == null - ? null - : durationConverter.toJson(instance.duration), - 'durationList': instance.durationList - ?.map((e) => e == null ? null : durationConverter.toJson(e)) - ?.toList(), - 'bigInt': instance.bigInt == null - ? null - : const BigIntStringConverter().toJson(instance.bigInt), - 'bigIntMap': instance.bigIntMap?.map((k, e) => MapEntry( - k, e == null ? null : const BigIntStringConverter().toJson(e))), - 'numberSilly': instance.numberSilly == null - ? null - : TrivialNumberConverter.instance.toJson(instance.numberSilly), + 'duration': durationConverter.toJson(instance.duration), + 'durationList': + instance.durationList?.map(durationConverter.toJson)?.toList(), + 'bigInt': const BigIntStringConverter().toJson(instance.bigInt), + 'bigIntMap': instance.bigIntMap + ?.map((k, e) => MapEntry(k, const BigIntStringConverter().toJson(e))), + 'numberSilly': + TrivialNumberConverter.instance.toJson(instance.numberSilly), 'numberSillySet': instance.numberSillySet - ?.map((e) => - e == null ? null : TrivialNumberConverter.instance.toJson(e)) + ?.map(TrivialNumberConverter.instance.toJson) ?.toList(), - 'dateTime': instance.dateTime == null - ? null - : const EpochDateTimeConverter().toJson(instance.dateTime) + 'dateTime': const EpochDateTimeConverter().toJson(instance.dateTime) }; JsonConverterGeneric _$JsonConverterGenericFromJson( Map json) { return JsonConverterGeneric() - ..item = json['item'] == null - ? null - : GenericConverter().fromJson(json['item'] as Map) + ..item = + GenericConverter().fromJson(json['item'] as Map) ..itemList = (json['itemList'] as List) - ?.map((e) => e == null - ? null - : GenericConverter().fromJson(e as Map)) + ?.map((e) => GenericConverter().fromJson(e as Map)) ?.toList() ..itemMap = (json['itemMap'] as Map)?.map( (k, e) => MapEntry( - k, - e == null - ? null - : GenericConverter().fromJson(e as Map)), + k, GenericConverter().fromJson(e as Map)), ); } Map _$JsonConverterGenericToJson( JsonConverterGeneric instance) => { - 'item': instance.item == null - ? null - : GenericConverter().toJson(instance.item), - 'itemList': instance.itemList - ?.map((e) => e == null ? null : GenericConverter().toJson(e)) - ?.toList(), - 'itemMap': instance.itemMap?.map((k, e) => - MapEntry(k, e == null ? null : GenericConverter().toJson(e))) + 'item': GenericConverter().toJson(instance.item), + 'itemList': + instance.itemList?.map(GenericConverter().toJson)?.toList(), + 'itemMap': instance.itemMap + ?.map((k, e) => MapEntry(k, GenericConverter().toJson(e))) }; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart index a4061b5b9..37bdb00e9 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart @@ -123,90 +123,61 @@ Map _$KitchenSinkToJson(KitchenSink instance) => JsonConverterTestClass _$JsonConverterTestClassFromJson(Map json) { return JsonConverterTestClass() - ..duration = json['duration'] == null - ? null - : durationConverter.fromJson(json['duration'] as int) + ..duration = durationConverter.fromJson(json['duration'] as int) ..durationList = (json['durationList'] as List) - ?.map((e) => e == null ? null : durationConverter.fromJson(e as int)) + ?.map((e) => durationConverter.fromJson(e as int)) ?.toList() - ..bigInt = json['bigInt'] == null - ? null - : const BigIntStringConverter().fromJson(json['bigInt'] as String) + ..bigInt = const BigIntStringConverter().fromJson(json['bigInt'] as String) ..bigIntMap = (json['bigIntMap'] as Map)?.map( (k, e) => MapEntry( - k as String, - e == null - ? null - : const BigIntStringConverter().fromJson(e as String)), + k as String, const BigIntStringConverter().fromJson(e as String)), ) - ..numberSilly = json['numberSilly'] == null - ? null - : TrivialNumberConverter.instance.fromJson(json['numberSilly'] as int) + ..numberSilly = + TrivialNumberConverter.instance.fromJson(json['numberSilly'] as int) ..numberSillySet = (json['numberSillySet'] as List) - ?.map((e) => e == null - ? null - : TrivialNumberConverter.instance.fromJson(e as int)) + ?.map((e) => TrivialNumberConverter.instance.fromJson(e as int)) ?.toSet() - ..dateTime = json['dateTime'] == null - ? null - : const EpochDateTimeConverter().fromJson(json['dateTime'] as int); + ..dateTime = + const EpochDateTimeConverter().fromJson(json['dateTime'] as int); } Map _$JsonConverterTestClassToJson( JsonConverterTestClass instance) => { - 'duration': instance.duration == null - ? null - : durationConverter.toJson(instance.duration), - 'durationList': instance.durationList - ?.map((e) => e == null ? null : durationConverter.toJson(e)) - ?.toList(), - 'bigInt': instance.bigInt == null - ? null - : const BigIntStringConverter().toJson(instance.bigInt), - 'bigIntMap': instance.bigIntMap?.map((k, e) => MapEntry( - k, e == null ? null : const BigIntStringConverter().toJson(e))), - 'numberSilly': instance.numberSilly == null - ? null - : TrivialNumberConverter.instance.toJson(instance.numberSilly), + 'duration': durationConverter.toJson(instance.duration), + 'durationList': + instance.durationList?.map(durationConverter.toJson)?.toList(), + 'bigInt': const BigIntStringConverter().toJson(instance.bigInt), + 'bigIntMap': instance.bigIntMap + ?.map((k, e) => MapEntry(k, const BigIntStringConverter().toJson(e))), + 'numberSilly': + TrivialNumberConverter.instance.toJson(instance.numberSilly), 'numberSillySet': instance.numberSillySet - ?.map((e) => - e == null ? null : TrivialNumberConverter.instance.toJson(e)) + ?.map(TrivialNumberConverter.instance.toJson) ?.toList(), - 'dateTime': instance.dateTime == null - ? null - : const EpochDateTimeConverter().toJson(instance.dateTime) + 'dateTime': const EpochDateTimeConverter().toJson(instance.dateTime) }; JsonConverterGeneric _$JsonConverterGenericFromJson( Map json) { return JsonConverterGeneric() - ..item = json['item'] == null - ? null - : GenericConverter().fromJson(json['item'] as Map) + ..item = + GenericConverter().fromJson(json['item'] as Map) ..itemList = (json['itemList'] as List) - ?.map((e) => e == null - ? null - : GenericConverter().fromJson(e as Map)) + ?.map((e) => GenericConverter().fromJson(e as Map)) ?.toList() ..itemMap = (json['itemMap'] as Map)?.map( - (k, e) => MapEntry( - k as String, - e == null - ? null - : GenericConverter().fromJson(e as Map)), + (k, e) => MapEntry(k as String, + GenericConverter().fromJson(e as Map)), ); } Map _$JsonConverterGenericToJson( JsonConverterGeneric instance) => { - 'item': instance.item == null - ? null - : GenericConverter().toJson(instance.item), - 'itemList': instance.itemList - ?.map((e) => e == null ? null : GenericConverter().toJson(e)) - ?.toList(), - 'itemMap': instance.itemMap?.map((k, e) => - MapEntry(k, e == null ? null : GenericConverter().toJson(e))) + 'item': GenericConverter().toJson(instance.item), + 'itemList': + instance.itemList?.map(GenericConverter().toJson)?.toList(), + 'itemMap': instance.itemMap + ?.map((k, e) => MapEntry(k, GenericConverter().toJson(e))) }; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart index 7ce6be28e..d8be027cc 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart @@ -138,33 +138,22 @@ Map _$KitchenSinkToJson(KitchenSink instance) { JsonConverterTestClass _$JsonConverterTestClassFromJson( Map json) { return JsonConverterTestClass() - ..duration = json['duration'] == null - ? null - : durationConverter.fromJson(json['duration'] as int) + ..duration = durationConverter.fromJson(json['duration'] as int) ..durationList = (json['durationList'] as List) - ?.map((e) => e == null ? null : durationConverter.fromJson(e as int)) + ?.map((e) => durationConverter.fromJson(e as int)) ?.toList() - ..bigInt = json['bigInt'] == null - ? null - : const BigIntStringConverter().fromJson(json['bigInt'] as String) + ..bigInt = const BigIntStringConverter().fromJson(json['bigInt'] as String) ..bigIntMap = (json['bigIntMap'] as Map)?.map( - (k, e) => MapEntry( - k, - e == null - ? null - : const BigIntStringConverter().fromJson(e as String)), + (k, e) => + MapEntry(k, const BigIntStringConverter().fromJson(e as String)), ) - ..numberSilly = json['numberSilly'] == null - ? null - : TrivialNumberConverter.instance.fromJson(json['numberSilly'] as int) + ..numberSilly = + TrivialNumberConverter.instance.fromJson(json['numberSilly'] as int) ..numberSillySet = (json['numberSillySet'] as List) - ?.map((e) => e == null - ? null - : TrivialNumberConverter.instance.fromJson(e as int)) + ?.map((e) => TrivialNumberConverter.instance.fromJson(e as int)) ?.toSet() - ..dateTime = json['dateTime'] == null - ? null - : const EpochDateTimeConverter().fromJson(json['dateTime'] as int); + ..dateTime = + const EpochDateTimeConverter().fromJson(json['dateTime'] as int); } Map _$JsonConverterTestClassToJson( @@ -177,61 +166,37 @@ Map _$JsonConverterTestClassToJson( } } - writeNotNull( - 'duration', - instance.duration == null - ? null - : durationConverter.toJson(instance.duration)); - writeNotNull( - 'durationList', - instance.durationList - ?.map((e) => e == null ? null : durationConverter.toJson(e)) - ?.toList()); - writeNotNull( - 'bigInt', - instance.bigInt == null - ? null - : const BigIntStringConverter().toJson(instance.bigInt)); + writeNotNull('duration', durationConverter.toJson(instance.duration)); + writeNotNull('durationList', + instance.durationList?.map(durationConverter.toJson)?.toList()); + writeNotNull('bigInt', const BigIntStringConverter().toJson(instance.bigInt)); writeNotNull( 'bigIntMap', - instance.bigIntMap?.map((k, e) => MapEntry( - k, e == null ? null : const BigIntStringConverter().toJson(e)))); - writeNotNull( - 'numberSilly', - instance.numberSilly == null - ? null - : TrivialNumberConverter.instance.toJson(instance.numberSilly)); + instance.bigIntMap?.map( + (k, e) => MapEntry(k, const BigIntStringConverter().toJson(e)))); + writeNotNull('numberSilly', + TrivialNumberConverter.instance.toJson(instance.numberSilly)); writeNotNull( 'numberSillySet', instance.numberSillySet - ?.map((e) => - e == null ? null : TrivialNumberConverter.instance.toJson(e)) + ?.map(TrivialNumberConverter.instance.toJson) ?.toList()); writeNotNull( - 'dateTime', - instance.dateTime == null - ? null - : const EpochDateTimeConverter().toJson(instance.dateTime)); + 'dateTime', const EpochDateTimeConverter().toJson(instance.dateTime)); return val; } JsonConverterGeneric _$JsonConverterGenericFromJson( Map json) { return JsonConverterGeneric() - ..item = json['item'] == null - ? null - : GenericConverter().fromJson(json['item'] as Map) + ..item = + GenericConverter().fromJson(json['item'] as Map) ..itemList = (json['itemList'] as List) - ?.map((e) => e == null - ? null - : GenericConverter().fromJson(e as Map)) + ?.map((e) => GenericConverter().fromJson(e as Map)) ?.toList() ..itemMap = (json['itemMap'] as Map)?.map( (k, e) => MapEntry( - k, - e == null - ? null - : GenericConverter().fromJson(e as Map)), + k, GenericConverter().fromJson(e as Map)), ); } @@ -245,19 +210,12 @@ Map _$JsonConverterGenericToJson( } } - writeNotNull( - 'item', - instance.item == null - ? null - : GenericConverter().toJson(instance.item)); - writeNotNull( - 'itemList', - instance.itemList - ?.map((e) => e == null ? null : GenericConverter().toJson(e)) - ?.toList()); + writeNotNull('item', GenericConverter().toJson(instance.item)); + writeNotNull('itemList', + instance.itemList?.map(GenericConverter().toJson)?.toList()); writeNotNull( 'itemMap', - instance.itemMap?.map((k, e) => - MapEntry(k, e == null ? null : GenericConverter().toJson(e)))); + instance.itemMap + ?.map((k, e) => MapEntry(k, GenericConverter().toJson(e)))); return val; } diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart index bf40058d7..fbfbcbef1 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart @@ -126,90 +126,61 @@ Map _$KitchenSinkToJson(KitchenSink instance) => JsonConverterTestClass _$JsonConverterTestClassFromJson( Map json) { return JsonConverterTestClass() - ..duration = json['duration'] == null - ? null - : durationConverter.fromJson(json['duration'] as int) + ..duration = durationConverter.fromJson(json['duration'] as int) ..durationList = (json['durationList'] as List) - ?.map((e) => e == null ? null : durationConverter.fromJson(e as int)) + ?.map((e) => durationConverter.fromJson(e as int)) ?.toList() - ..bigInt = json['bigInt'] == null - ? null - : const BigIntStringConverter().fromJson(json['bigInt'] as String) + ..bigInt = const BigIntStringConverter().fromJson(json['bigInt'] as String) ..bigIntMap = (json['bigIntMap'] as Map)?.map( - (k, e) => MapEntry( - k, - e == null - ? null - : const BigIntStringConverter().fromJson(e as String)), + (k, e) => + MapEntry(k, const BigIntStringConverter().fromJson(e as String)), ) - ..numberSilly = json['numberSilly'] == null - ? null - : TrivialNumberConverter.instance.fromJson(json['numberSilly'] as int) + ..numberSilly = + TrivialNumberConverter.instance.fromJson(json['numberSilly'] as int) ..numberSillySet = (json['numberSillySet'] as List) - ?.map((e) => e == null - ? null - : TrivialNumberConverter.instance.fromJson(e as int)) + ?.map((e) => TrivialNumberConverter.instance.fromJson(e as int)) ?.toSet() - ..dateTime = json['dateTime'] == null - ? null - : const EpochDateTimeConverter().fromJson(json['dateTime'] as int); + ..dateTime = + const EpochDateTimeConverter().fromJson(json['dateTime'] as int); } Map _$JsonConverterTestClassToJson( JsonConverterTestClass instance) => { - 'duration': instance.duration == null - ? null - : durationConverter.toJson(instance.duration), - 'durationList': instance.durationList - ?.map((e) => e == null ? null : durationConverter.toJson(e)) - ?.toList(), - 'bigInt': instance.bigInt == null - ? null - : const BigIntStringConverter().toJson(instance.bigInt), - 'bigIntMap': instance.bigIntMap?.map((k, e) => MapEntry( - k, e == null ? null : const BigIntStringConverter().toJson(e))), - 'numberSilly': instance.numberSilly == null - ? null - : TrivialNumberConverter.instance.toJson(instance.numberSilly), + 'duration': durationConverter.toJson(instance.duration), + 'durationList': + instance.durationList?.map(durationConverter.toJson)?.toList(), + 'bigInt': const BigIntStringConverter().toJson(instance.bigInt), + 'bigIntMap': instance.bigIntMap + ?.map((k, e) => MapEntry(k, const BigIntStringConverter().toJson(e))), + 'numberSilly': + TrivialNumberConverter.instance.toJson(instance.numberSilly), 'numberSillySet': instance.numberSillySet - ?.map((e) => - e == null ? null : TrivialNumberConverter.instance.toJson(e)) + ?.map(TrivialNumberConverter.instance.toJson) ?.toList(), - 'dateTime': instance.dateTime == null - ? null - : const EpochDateTimeConverter().toJson(instance.dateTime) + 'dateTime': const EpochDateTimeConverter().toJson(instance.dateTime) }; JsonConverterGeneric _$JsonConverterGenericFromJson( Map json) { return JsonConverterGeneric() - ..item = json['item'] == null - ? null - : GenericConverter().fromJson(json['item'] as Map) + ..item = + GenericConverter().fromJson(json['item'] as Map) ..itemList = (json['itemList'] as List) - ?.map((e) => e == null - ? null - : GenericConverter().fromJson(e as Map)) + ?.map((e) => GenericConverter().fromJson(e as Map)) ?.toList() ..itemMap = (json['itemMap'] as Map)?.map( (k, e) => MapEntry( - k, - e == null - ? null - : GenericConverter().fromJson(e as Map)), + k, GenericConverter().fromJson(e as Map)), ); } Map _$JsonConverterGenericToJson( JsonConverterGeneric instance) => { - 'item': instance.item == null - ? null - : GenericConverter().toJson(instance.item), - 'itemList': instance.itemList - ?.map((e) => e == null ? null : GenericConverter().toJson(e)) - ?.toList(), - 'itemMap': instance.itemMap?.map((k, e) => - MapEntry(k, e == null ? null : GenericConverter().toJson(e))) + 'item': GenericConverter().toJson(instance.item), + 'itemList': + instance.itemList?.map(GenericConverter().toJson)?.toList(), + 'itemMap': instance.itemMap + ?.map((k, e) => MapEntry(k, GenericConverter().toJson(e))) }; diff --git a/json_serializable/test/src/default_value_input.dart b/json_serializable/test/src/default_value_input.dart index 3884868c4..e6f693578 100644 --- a/json_serializable/test/src/default_value_input.dart +++ b/json_serializable/test/src/default_value_input.dart @@ -99,21 +99,22 @@ class DefaultWithNonNullableClass { DefaultWithNonNullableClass(); } -@ShouldGenerate(r''' +@ShouldGenerate( + r''' DefaultWithToJsonClass _$DefaultWithToJsonClassFromJson( Map json) { return DefaultWithToJsonClass() - ..fieldDefaultValueToJson = json['fieldDefaultValueToJson'] == null - ? null - : DefaultWithToJsonClass._fromJson( - json['fieldDefaultValueToJson'] as String) ?? - 7; + ..fieldDefaultValueToJson = DefaultWithToJsonClass._fromJson( + json['fieldDefaultValueToJson'] as String) ?? + 7; } -''', expectedLogItems: [ - ''' +''', + expectedLogItems: [ + ''' The field `fieldDefaultValueToJson` has both `defaultValue` and `fromJson` defined which likely won't work for your scenario. Instead of using `defaultValue`, set `nullable: false` and handle `null` in the `fromJson` function.''' -]) + ], +) @JsonSerializable(createToJson: false) class DefaultWithToJsonClass { @JsonKey(defaultValue: 7, fromJson: _fromJson) diff --git a/json_serializable/test/src/generic_test_input.dart b/json_serializable/test/src/generic_test_input.dart index 0c9c372f7..e896c72a7 100644 --- a/json_serializable/test/src/generic_test_input.dart +++ b/json_serializable/test/src/generic_test_input.dart @@ -4,36 +4,29 @@ part of '_json_serializable_test_input.dart'; -@ShouldGenerate(r''' +@ShouldGenerate( + r''' GenericClass _$GenericClassFromJson( Map json) { return GenericClass() - ..fieldObject = - json['fieldObject'] == null ? null : _dataFromJson(json['fieldObject']) - ..fieldDynamic = json['fieldDynamic'] == null - ? null - : _dataFromJson(json['fieldDynamic']) - ..fieldInt = - json['fieldInt'] == null ? null : _dataFromJson(json['fieldInt']) - ..fieldT = json['fieldT'] == null ? null : _dataFromJson(json['fieldT']) - ..fieldS = json['fieldS'] == null ? null : _dataFromJson(json['fieldS']); + ..fieldObject = _dataFromJson(json['fieldObject']) + ..fieldDynamic = _dataFromJson(json['fieldDynamic']) + ..fieldInt = _dataFromJson(json['fieldInt']) + ..fieldT = _dataFromJson(json['fieldT']) + ..fieldS = _dataFromJson(json['fieldS']); } Map _$GenericClassToJson( GenericClass instance) => { - 'fieldObject': instance.fieldObject == null - ? null - : _dataToJson(instance.fieldObject), - 'fieldDynamic': instance.fieldDynamic == null - ? null - : _dataToJson(instance.fieldDynamic), - 'fieldInt': - instance.fieldInt == null ? null : _dataToJson(instance.fieldInt), - 'fieldT': instance.fieldT == null ? null : _dataToJson(instance.fieldT), - 'fieldS': instance.fieldS == null ? null : _dataToJson(instance.fieldS) + 'fieldObject': _dataToJson(instance.fieldObject), + 'fieldDynamic': _dataToJson(instance.fieldDynamic), + 'fieldInt': _dataToJson(instance.fieldInt), + 'fieldT': _dataToJson(instance.fieldT), + 'fieldS': _dataToJson(instance.fieldS) }; -''') +''', +) @JsonSerializable() class GenericClass { @JsonKey(fromJson: _dataFromJson, toJson: _dataToJson) diff --git a/json_serializable/test/src/json_converter_test_input.dart b/json_serializable/test/src/json_converter_test_input.dart index d5effffae..9363a827d 100644 --- a/json_serializable/test/src/json_converter_test_input.dart +++ b/json_serializable/test/src/json_converter_test_input.dart @@ -9,30 +9,23 @@ part of '_json_serializable_test_input.dart'; JsonConverterNamedCtor _$JsonConverterNamedCtorFromJson( Map json) { return JsonConverterNamedCtor() - ..value = json['value'] == null - ? null - : const _DurationMillisecondConverter.named() - .fromJson(json['value'] as int) - ..genericValue = json['genericValue'] == null - ? null - : _GenericConverter.named().fromJson(json['genericValue'] as int) - ..keyAnnotationFirst = json['keyAnnotationFirst'] == null - ? null - : JsonConverterNamedCtor._fromJson(json['keyAnnotationFirst'] as int); + ..value = const _DurationMillisecondConverter.named() + .fromJson(json['value'] as int) + ..genericValue = + _GenericConverter.named().fromJson(json['genericValue'] as int) + ..keyAnnotationFirst = + JsonConverterNamedCtor._fromJson(json['keyAnnotationFirst'] as int); } Map _$JsonConverterNamedCtorToJson( JsonConverterNamedCtor instance) => { - 'value': instance.value == null - ? null - : const _DurationMillisecondConverter.named().toJson(instance.value), - 'genericValue': instance.genericValue == null - ? null - : _GenericConverter.named().toJson(instance.genericValue), - 'keyAnnotationFirst': instance.keyAnnotationFirst == null - ? null - : JsonConverterNamedCtor._toJson(instance.keyAnnotationFirst) + 'value': + const _DurationMillisecondConverter.named().toJson(instance.value), + 'genericValue': + _GenericConverter.named().toJson(instance.genericValue), + 'keyAnnotationFirst': + JsonConverterNamedCtor._toJson(instance.keyAnnotationFirst) }; ''', configurations: ['default'], @@ -58,39 +51,26 @@ class JsonConverterNamedCtor { JsonConvertOnField _$JsonConvertOnFieldFromJson( Map json) { return JsonConvertOnField() - ..annotatedField = json['annotatedField'] == null - ? null - : const _DurationMillisecondConverter() - .fromJson(json['annotatedField'] as int) - ..annotatedWithNamedCtor = json['annotatedWithNamedCtor'] == null - ? null - : const _DurationMillisecondConverter.named() - .fromJson(json['annotatedWithNamedCtor'] as int) - ..classAnnotatedWithField = json['classAnnotatedWithField'] == null - ? null - : _durationConverter.fromJson(json['classAnnotatedWithField'] as int) - ..genericValue = json['genericValue'] == null - ? null - : _GenericConverter().fromJson(json['genericValue'] as int); + ..annotatedField = const _DurationMillisecondConverter() + .fromJson(json['annotatedField'] as int) + ..annotatedWithNamedCtor = const _DurationMillisecondConverter.named() + .fromJson(json['annotatedWithNamedCtor'] as int) + ..classAnnotatedWithField = + _durationConverter.fromJson(json['classAnnotatedWithField'] as int) + ..genericValue = + _GenericConverter().fromJson(json['genericValue'] as int); } Map _$JsonConvertOnFieldToJson( JsonConvertOnField instance) => { - 'annotatedField': instance.annotatedField == null - ? null - : const _DurationMillisecondConverter() - .toJson(instance.annotatedField), - 'annotatedWithNamedCtor': instance.annotatedWithNamedCtor == null - ? null - : const _DurationMillisecondConverter.named() - .toJson(instance.annotatedWithNamedCtor), - 'classAnnotatedWithField': instance.classAnnotatedWithField == null - ? null - : _durationConverter.toJson(instance.classAnnotatedWithField), - 'genericValue': instance.genericValue == null - ? null - : _GenericConverter().toJson(instance.genericValue) + 'annotatedField': + const _DurationMillisecondConverter().toJson(instance.annotatedField), + 'annotatedWithNamedCtor': const _DurationMillisecondConverter.named() + .toJson(instance.annotatedWithNamedCtor), + 'classAnnotatedWithField': + _durationConverter.toJson(instance.classAnnotatedWithField), + 'genericValue': _GenericConverter().toJson(instance.genericValue) }; ''', configurations: ['default'], diff --git a/json_serializable/test/src/to_from_json_test_input.dart b/json_serializable/test/src/to_from_json_test_input.dart index 7c34e8b00..576c991a3 100644 --- a/json_serializable/test/src/to_from_json_test_input.dart +++ b/json_serializable/test/src/to_from_json_test_input.dart @@ -39,17 +39,13 @@ class InvalidFromFunc2Args { ValidToFromFuncClassStatic _$ValidToFromFuncClassStaticFromJson( Map json) { return ValidToFromFuncClassStatic() - ..field = json['field'] == null - ? null - : ValidToFromFuncClassStatic._staticFunc(json['field'] as String); + ..field = ValidToFromFuncClassStatic._staticFunc(json['field'] as String); } Map _$ValidToFromFuncClassStaticToJson( ValidToFromFuncClassStatic instance) => { - 'field': instance.field == null - ? null - : ValidToFromFuncClassStatic._staticFunc(instance.field) + 'field': ValidToFromFuncClassStatic._staticFunc(instance.field) }; ''', configurations: ['default'], @@ -134,6 +130,11 @@ Map _$ToJsonNullableFalseIncludeIfNullFalseToJson( return val; } ''', + expectedLogItems: [ + 'The `JsonKey.nullable` value on ' + '`ToJsonNullableFalseIncludeIfNullFalse.field` will be ignored because ' + 'a custom conversion function is being used.', + ], configurations: ['default'], ) @JsonSerializable(createFactory: false) @@ -153,15 +154,9 @@ String _fromDynamicIterable(Iterable input) => null; FromDynamicCollection _$FromDynamicCollectionFromJson( Map json) { return FromDynamicCollection() - ..mapField = json['mapField'] == null - ? null - : _fromDynamicMap(json['mapField'] as Map) - ..listField = json['listField'] == null - ? null - : _fromDynamicList(json['listField'] as List) - ..iterableField = json['iterableField'] == null - ? null - : _fromDynamicIterable(json['iterableField'] as List); + ..mapField = _fromDynamicMap(json['mapField'] as Map) + ..listField = _fromDynamicList(json['listField'] as List) + ..iterableField = _fromDynamicIterable(json['iterableField'] as List); } ''', configurations: ['default'], diff --git a/json_serializable/test/src/unknown_type_test_input.dart b/json_serializable/test/src/unknown_type_test_input.dart index ad51b289c..106974d08 100644 --- a/json_serializable/test/src/unknown_type_test_input.dart +++ b/json_serializable/test/src/unknown_type_test_input.dart @@ -56,15 +56,12 @@ class UnknownFieldTypeToJsonOnly { UnknownFieldTypeWithConvert _$UnknownFieldTypeWithConvertFromJson( Map json) { return UnknownFieldTypeWithConvert() - ..number = json['number'] == null ? null : _everythingIs42(json['number']); + ..number = _everythingIs42(json['number']); } Map _$UnknownFieldTypeWithConvertToJson( UnknownFieldTypeWithConvert instance) => - { - 'number': - instance.number == null ? null : _everythingIs42(instance.number) - }; + {'number': _everythingIs42(instance.number)}; ''', configurations: ['default'], ) From 21c4e2285494376c8a4aa729d88d7fdee843701f Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 16 May 2019 15:42:04 -0600 Subject: [PATCH 139/569] json_annotation: deprecate members that will be removed in v3 (#485) prepare to release v2.4 --- .travis.yml | 1 + json_annotation/CHANGELOG.md | 8 ++++++++ json_annotation/lib/src/json_key.dart | 1 + json_annotation/lib/src/json_serializable.dart | 5 +++++ json_annotation/lib/src/json_serializable.g.dart | 2 ++ json_annotation/lib/src/wrapper_helpers.dart | 5 +++++ json_annotation/pubspec.yaml | 2 +- mono_repo.yaml | 1 + 8 files changed, 24 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index b432f7c24..02f50e5fb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,7 @@ addons: branches: only: - master + - v2_x jobs: include: diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index fd138bfaa..1ce1c893a 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -1,3 +1,11 @@ +## 2.4.0 + +- Deprecate members that will be removed in `json_annotation` `3.0.0` and that + are not supported in `json_serializable` `3.0.0`. + - `JsonSerializable.useWrappers` and associated `$`-prefixed helpers + - `JsonSerializable.generateToJsonFunction`, + - `encodeEmptyCollection` from `JsonSerializable` and `JsonKey`. + ## 2.3.0 - Added `pascal` as an additional `fieldRename` option. diff --git a/json_annotation/lib/src/json_key.dart b/json_annotation/lib/src/json_key.dart index 62a77175b..df76fced3 100644 --- a/json_annotation/lib/src/json_key.dart +++ b/json_annotation/lib/src/json_key.dart @@ -43,6 +43,7 @@ class JsonKey { /// The default value, `null`, indicates that the behavior should be /// acquired from the [JsonSerializable.encodeEmptyCollection] annotation on /// the enclosing class. + @Deprecated('Will be removed in 3.0.0.') final bool encodeEmptyCollection; /// A [Function] to use when decoding the associated JSON value to the diff --git a/json_annotation/lib/src/json_serializable.dart b/json_annotation/lib/src/json_serializable.dart index d174f3816..590957c2f 100644 --- a/json_annotation/lib/src/json_serializable.dart +++ b/json_annotation/lib/src/json_serializable.dart @@ -2,6 +2,8 @@ // 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. +// ignore_for_file: deprecated_member_use,deprecated_member_use_from_same_package + import 'allowed_keys_helpers.dart'; import 'checked_helpers.dart'; import 'json_key.dart'; @@ -110,6 +112,7 @@ class JsonSerializable { /// value to `false` as well. /// /// Note: non-collection fields are not affected by this value. + @Deprecated('Will be removed in 3.0.0.') final bool encodeEmptyCollection; /// If `true`, generated `toJson` methods will explicitly call `toJson` on @@ -168,6 +171,7 @@ class JsonSerializable { /// // ... /// } /// ``` + @Deprecated('Will be removed in 3.0.0.') final bool generateToJsonFunction; /// Whether the generator should include fields with `null` values in the @@ -195,6 +199,7 @@ class JsonSerializable { /// /// This will increase the code size, but it may improve runtime performance, /// especially for large object graphs. + @Deprecated('Will be removed in 3.0.0.') final bool useWrappers; /// Creates a new [JsonSerializable] instance. diff --git a/json_annotation/lib/src/json_serializable.g.dart b/json_annotation/lib/src/json_serializable.g.dart index 2e9ef9a41..85b62c4bc 100644 --- a/json_annotation/lib/src/json_serializable.g.dart +++ b/json_annotation/lib/src/json_serializable.g.dart @@ -1,3 +1,5 @@ +// ignore_for_file: deprecated_member_use,deprecated_member_use_from_same_package + // GENERATED CODE - DO NOT MODIFY BY HAND part of 'json_serializable.dart'; diff --git a/json_annotation/lib/src/wrapper_helpers.dart b/json_annotation/lib/src/wrapper_helpers.dart index 73b019167..e7309d66d 100644 --- a/json_annotation/lib/src/wrapper_helpers.dart +++ b/json_annotation/lib/src/wrapper_helpers.dart @@ -8,12 +8,14 @@ import 'dart:collection'; /// `JsonSerializableGenerator.useWrappers` is `true`. /// /// Should not be used directly. +@Deprecated('Will be removed in 3.0.0.') abstract class $JsonMapWrapper extends UnmodifiableMapBase {} /// Helper function used in generated code when /// `JsonSerializableGenerator.useWrappers` is `true`. /// /// Should not be used directly. +@Deprecated('Will be removed in 3.0.0.') Map $wrapMap( Map source, dynamic converter(V key)) => _MappingMap(source, converter); @@ -22,6 +24,7 @@ Map $wrapMap( /// `JsonSerializableGenerator.useWrappers` is `true`. /// /// Should not be used directly. +@Deprecated('Will be removed in 3.0.0.') Map $wrapMapHandleNull( Map source, dynamic converter(V key)) => source == null ? null : _MappingMap(source, converter); @@ -30,6 +33,7 @@ Map $wrapMapHandleNull( /// `JsonSerializableGenerator.useWrappers` is `true`. /// /// Should not be used directly. +@Deprecated('Will be removed in 3.0.0.') List $wrapList(List source, dynamic converter(T key)) => _MappingList(source, converter); @@ -37,6 +41,7 @@ List $wrapList(List source, dynamic converter(T key)) => /// `JsonSerializableGenerator.useWrappers` is `true`. /// /// Should not be used directly. +@Deprecated('Will be removed in 3.0.0.') List $wrapListHandleNull( List source, dynamic converter(T key)) => source == null ? null : _MappingList(source, converter); diff --git a/json_annotation/pubspec.yaml b/json_annotation/pubspec.yaml index 170e052e4..b7f691d33 100644 --- a/json_annotation/pubspec.yaml +++ b/json_annotation/pubspec.yaml @@ -1,5 +1,5 @@ name: json_annotation -version: 2.3.0 +version: 2.4.0 description: >- Classes and helper functions that support JSON code generation via the `json_serializable` package. diff --git a/mono_repo.yaml b/mono_repo.yaml index 12ed8f1fe..938b3f6b6 100644 --- a/mono_repo.yaml +++ b/mono_repo.yaml @@ -6,6 +6,7 @@ travis: branches: only: - master + - v2_x merge_stages: - analyzer_and_format From 53c8691309c0a2da38616fb64501930e97d892c0 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 20 May 2019 10:59:30 -0700 Subject: [PATCH 140/569] json_serializable: prepare for release (#487) --- json_serializable/CHANGELOG.md | 17 ++++++--- json_serializable/README.md | 36 +++++++++---------- json_serializable/build.yaml | 22 ++++++------ json_serializable/doc/doc.md | 36 +++++++++---------- json_serializable/pubspec.yaml | 6 +--- json_serializable/test/config_test.dart | 15 +++++--- .../test/custom_configuration_test.dart | 8 +++-- json_serializable/test/shared_config.dart | 19 ++++++++++ json_serializable/tool/doc_builder.dart | 6 ++-- 9 files changed, 99 insertions(+), 66 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 26c8989a9..fef32f0eb 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,15 +1,22 @@ ## 3.0.0 -- **BREAKING** Removed support for `JsonSerializable.useWrappers`. -- **BREAKING** Removed support for `JsonSerializable.generateToJsonFunction`. -- **BREAKING** Removed support for `encodeEmptyCollection`. -- **BREAKING** If a field has a conversion function defined – either +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.toJson` or a custom `JsonConverter` annotation – don't intercept `null` values, even if `nullable` is explicitly set to `false`. This allows these functions to provide alternative values for `null` – such as an empty collection – which replaces the functionality provided by `encodeEmptyCollection`. - + - **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 `pascal` as an additional `fieldRename` option. diff --git a/json_serializable/README.md b/json_serializable/README.md index c152c80a9..60d52c671 100644 --- a/json_serializable/README.md +++ b/json_serializable/README.md @@ -88,24 +88,24 @@ is generated: | | | [JsonKey.required] | | | | [JsonKey.toJson] | -[JsonSerializable.anyMap]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/anyMap.html -[JsonSerializable.checked]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/checked.html -[JsonSerializable.createFactory]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/createFactory.html -[JsonSerializable.createToJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/createToJson.html -[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html -[JsonSerializable.explicitToJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/explicitToJson.html -[JsonSerializable.fieldRename]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/fieldRename.html -[JsonSerializable.includeIfNull]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/includeIfNull.html -[JsonKey.includeIfNull]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/includeIfNull.html -[JsonSerializable.nullable]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/nullable.html -[JsonKey.nullable]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/nullable.html -[JsonKey.defaultValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/defaultValue.html -[JsonKey.disallowNullValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/disallowNullValue.html -[JsonKey.fromJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/fromJson.html -[JsonKey.ignore]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/ignore.html -[JsonKey.name]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/name.html -[JsonKey.required]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/required.html -[JsonKey.toJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/toJson.html +[JsonSerializable.anyMap]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonSerializable/anyMap.html +[JsonSerializable.checked]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonSerializable/checked.html +[JsonSerializable.createFactory]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonSerializable/createFactory.html +[JsonSerializable.createToJson]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonSerializable/createToJson.html +[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html +[JsonSerializable.explicitToJson]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonSerializable/explicitToJson.html +[JsonSerializable.fieldRename]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonSerializable/fieldRename.html +[JsonSerializable.includeIfNull]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonSerializable/includeIfNull.html +[JsonKey.includeIfNull]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonKey/includeIfNull.html +[JsonSerializable.nullable]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonSerializable/nullable.html +[JsonKey.nullable]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonKey/nullable.html +[JsonKey.defaultValue]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonKey/defaultValue.html +[JsonKey.disallowNullValue]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonKey/disallowNullValue.html +[JsonKey.fromJson]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonKey/fromJson.html +[JsonKey.ignore]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonKey/ignore.html +[JsonKey.name]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonKey/name.html +[JsonKey.required]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonKey/required.html +[JsonKey.toJson]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonKey/toJson.html > Note: every `JsonSerializable` field is configurable via `build.yaml` – see the table for the corresponding key. diff --git a/json_serializable/build.yaml b/json_serializable/build.yaml index 20f6b4dbb..dd3ea2919 100644 --- a/json_serializable/build.yaml +++ b/json_serializable/build.yaml @@ -4,19 +4,19 @@ targets: builders: json_serializable: generate_for: - include: - - example/* - - test/default_value/* - - test/generic_files/* - - test/integration/* - - test/kitchen_sink/* - - test/literal/* + - example/* + - test/default_value/* + - test/generic_files/* + - test/integration/* + - test/kitchen_sink/* + - test/literal/* + build_web_compilers|entrypoint: generate_for: - - test/default_value/** - - test/generic_files/*_test.dart - - test/integration/*_test.dart - - test/kitchen_sink/** + - test/default_value/**.browser_test.dart + - test/generic_files/*.browser_test.dart + - test/integration/*.browser_test.dart + - test/kitchen_sink/**.browser_test.dart json_serializable|_internal: generate_for: diff --git a/json_serializable/doc/doc.md b/json_serializable/doc/doc.md index acba5502f..78de4649a 100644 --- a/json_serializable/doc/doc.md +++ b/json_serializable/doc/doc.md @@ -17,21 +17,21 @@ | | | [JsonKey.required] | | | | [JsonKey.toJson] | -[JsonSerializable.anyMap]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/anyMap.html -[JsonSerializable.checked]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/checked.html -[JsonSerializable.createFactory]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/createFactory.html -[JsonSerializable.createToJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/createToJson.html -[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html -[JsonSerializable.explicitToJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/explicitToJson.html -[JsonSerializable.fieldRename]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/fieldRename.html -[JsonSerializable.includeIfNull]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/includeIfNull.html -[JsonKey.includeIfNull]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/includeIfNull.html -[JsonSerializable.nullable]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/nullable.html -[JsonKey.nullable]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/nullable.html -[JsonKey.defaultValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/defaultValue.html -[JsonKey.disallowNullValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/disallowNullValue.html -[JsonKey.fromJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/fromJson.html -[JsonKey.ignore]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/ignore.html -[JsonKey.name]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/name.html -[JsonKey.required]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/required.html -[JsonKey.toJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/toJson.html +[JsonSerializable.anyMap]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonSerializable/anyMap.html +[JsonSerializable.checked]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonSerializable/checked.html +[JsonSerializable.createFactory]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonSerializable/createFactory.html +[JsonSerializable.createToJson]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonSerializable/createToJson.html +[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html +[JsonSerializable.explicitToJson]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonSerializable/explicitToJson.html +[JsonSerializable.fieldRename]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonSerializable/fieldRename.html +[JsonSerializable.includeIfNull]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonSerializable/includeIfNull.html +[JsonKey.includeIfNull]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonKey/includeIfNull.html +[JsonSerializable.nullable]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonSerializable/nullable.html +[JsonKey.nullable]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonKey/nullable.html +[JsonKey.defaultValue]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonKey/defaultValue.html +[JsonKey.disallowNullValue]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonKey/disallowNullValue.html +[JsonKey.fromJson]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonKey/fromJson.html +[JsonKey.ignore]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonKey/ignore.html +[JsonKey.name]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonKey/name.html +[JsonKey.required]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonKey/required.html +[JsonKey.toJson]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonKey/toJson.html diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 373dd2b06..74199658a 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 3.0.0-dev +version: 3.0.0 author: Dart Team description: >- Automatically generate code for converting to and from JSON by annotating @@ -33,7 +33,3 @@ dev_dependencies: source_gen_test: ^0.1.0 test: ^1.6.0 yaml: ^2.1.13 - -dependency_overrides: - json_annotation: - path: ../json_annotation diff --git a/json_serializable/test/config_test.dart b/json_serializable/test/config_test.dart index 34ddbff99..33d7d8228 100644 --- a/json_serializable/test/config_test.dart +++ b/json_serializable/test/config_test.dart @@ -76,12 +76,16 @@ void main() { final configMap = Map.from(yaml); - expect(configMap.keys, unorderedEquals(generatorConfigDefaultJson.keys), + expect( + configMap.keys, + unorderedEquals(generatorConfigDefaultJson.keys + .where((k) => !deprecatedKeys.contains(k))), reason: 'All supported keys are documented.'); - expect(JsonSerializable.fromJson(configMap).toJson(), - generatorConfigDefaultJson, - reason: 'All keys specify their default value.'); + expectMapMatchExcludingDeprecated( + JsonSerializable.fromJson(configMap).toJson(), + generatorConfigDefaultJson, + ); final builder = jsonSerializable(BuilderOptions(configMap)); expect(builder, isNotNull); @@ -135,8 +139,11 @@ const _invalidConfig = { 'create_factory': 42, 'create_to_json': 42, 'disallow_unrecognized_keys': 42, + 'encode_empty_collection': 42, 'explicit_to_json': 42, 'field_rename': 42, + 'generate_to_json_function': 42, 'include_if_null': 42, 'nullable': 42, + 'use_wrappers': 42, }; diff --git a/json_serializable/test/custom_configuration_test.dart b/json_serializable/test/custom_configuration_test.dart index 07c4dc27d..19defbdef 100644 --- a/json_serializable/test/custom_configuration_test.dart +++ b/json_serializable/test/custom_configuration_test.dart @@ -58,7 +58,8 @@ void main() async { expect(_ConfigLogger.configurations, hasLength(2)); expect(_ConfigLogger.configurations.first, same(_ConfigLogger.configurations.last)); - expect(_ConfigLogger.configurations.first.toJson(), + expectMapMatchExcludingDeprecated( + _ConfigLogger.configurations.first.toJson(), generatorConfigDefaultJson); }); } @@ -99,12 +100,13 @@ void main() async { // The effective configuration should be non-Default configuration, but // with all fields set from JsonSerializable as the defaults - final expected = Map.from(generatorConfigNonDefaultJson); + final expected = Map.from(generatorConfigNonDefaultJson); for (var jsonSerialKey in jsonSerializableFields) { expected[jsonSerialKey] = generatorConfigDefaultJson[jsonSerialKey]; } - expect(_ConfigLogger.configurations.first.toJson(), expected); + expectMapMatchExcludingDeprecated( + _ConfigLogger.configurations.first.toJson(), expected); }); }); } diff --git a/json_serializable/test/shared_config.dart b/json_serializable/test/shared_config.dart index 94f69f4f0..11aab7dbd 100644 --- a/json_serializable/test/shared_config.dart +++ b/json_serializable/test/shared_config.dart @@ -3,6 +3,7 @@ // BSD-style license that can be found in the LICENSE file. import 'package:json_annotation/json_annotation.dart'; +import 'package:test/test.dart'; final jsonSerializableFields = generatorConfigDefaultJson.keys.toList(); @@ -21,3 +22,21 @@ final generatorConfigNonDefaultJson = includeIfNull: false, nullable: false, ).toJson()); + +// TODO(kevmoo): remove all of this logic once json_annotation v3 exists +void expectMapMatchExcludingDeprecated( + Map actual, Map expected) { + Map exclude(Map source) => Map.fromEntries( + source.entries.where((e) => !deprecatedKeys.contains(e.key))); + + expect( + exclude(actual), + exclude(expected), + ); +} + +const deprecatedKeys = { + 'encode_empty_collection', + 'generate_to_json_function', + 'use_wrappers', +}; diff --git a/json_serializable/tool/doc_builder.dart b/json_serializable/tool/doc_builder.dart index 864b744a6..acceff11f 100644 --- a/json_serializable/tool/doc_builder.dart +++ b/json_serializable/tool/doc_builder.dart @@ -39,8 +39,10 @@ class _DocBuilder extends Builder { final descriptionMap = {}; for (var className in _annotationClasses) { - for (var fe - in lib.findType(className).fields.where((fe) => !fe.isStatic)) { + for (var fe in lib + .findType(className) + .fields + .where((fe) => !fe.isStatic && !fe.hasDeprecated)) { descriptionMap[fe.name] = _FieldInfo.update(fe, descriptionMap[fe.name]); } From 526e8405003afd04d3d7c77bff78975e995fff2f Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 20 May 2019 12:09:51 -0700 Subject: [PATCH 141/569] Bump json_serializable dep in checked_yaml and example (#489) --- checked_yaml/pubspec.yaml | 4 ++-- example/README.md | 4 ++-- example/lib/example.dart | 8 ++++---- example/lib/example.g.dart | 17 ++++------------- example/lib/json_converter_example.g.dart | 9 +++------ example/pubspec.yaml | 4 ++-- example/test/readme_test.dart | 4 ++-- 7 files changed, 19 insertions(+), 31 deletions(-) diff --git a/checked_yaml/pubspec.yaml b/checked_yaml/pubspec.yaml index 1090da527..cb3e8d19f 100644 --- a/checked_yaml/pubspec.yaml +++ b/checked_yaml/pubspec.yaml @@ -1,5 +1,5 @@ name: checked_yaml -version: 1.0.1 +version: 1.0.2-dev author: Dart Team description: >- Generate more helpful exceptions when decoding YAML documents using @@ -14,7 +14,7 @@ dependencies: yaml: ^2.1.13 dev_dependencies: - json_serializable: ^2.0.0 + json_serializable: ^3.0.0 build_runner: ^1.0.0 build_verify: ^1.1.0 path: ^1.0.0 diff --git a/example/README.md b/example/README.md index 97da92efe..fa92c1e1b 100644 --- a/example/README.md +++ b/example/README.md @@ -8,11 +8,11 @@ dependencies to your `pubspec.yaml`. ```yaml dependencies: - json_annotation: ^2.0.0 + json_annotation: ^2.4.0 dev_dependencies: build_runner: ^1.0.0 - json_serializable: ^2.0.0 + json_serializable: ^3.0.0 ``` Annotate your code with classes defined in diff --git a/example/lib/example.dart b/example/lib/example.dart index 4df531329..0cd0e650f 100644 --- a/example/lib/example.dart +++ b/example/lib/example.dart @@ -54,16 +54,16 @@ class Order { Map toJson() => _$OrderToJson(this); static Duration _durationFromMilliseconds(int milliseconds) => - Duration(milliseconds: milliseconds); + milliseconds == null ? null : Duration(milliseconds: milliseconds); static int _durationToMilliseconds(Duration duration) => - duration.inMilliseconds; + duration?.inMilliseconds; static DateTime _dateTimeFromEpochUs(int us) => - DateTime.fromMicrosecondsSinceEpoch(us); + us == null ? null : DateTime.fromMicrosecondsSinceEpoch(us); static int _dateTimeToEpochUs(DateTime dateTime) => - dateTime.microsecondsSinceEpoch; + dateTime?.microsecondsSinceEpoch; } @JsonSerializable() diff --git a/example/lib/example.g.dart b/example/lib/example.g.dart index f03273f98..bf46ba52a 100644 --- a/example/lib/example.g.dart +++ b/example/lib/example.g.dart @@ -38,18 +38,14 @@ Map _$PersonToJson(Person instance) { } Order _$OrderFromJson(Map json) { - return Order(json['date'] == null - ? null - : Order._dateTimeFromEpochUs(json['date'] as int)) + return Order(Order._dateTimeFromEpochUs(json['date'] as int)) ..count = json['count'] as int ..itemNumber = json['itemNumber'] as int ..isRushed = json['isRushed'] as bool ..item = json['item'] == null ? null : Item.fromJson(json['item'] as Map) - ..prepTime = json['prep-time'] == null - ? null - : Order._durationFromMilliseconds(json['prep-time'] as int); + ..prepTime = Order._durationFromMilliseconds(json['prep-time'] as int); } Map _$OrderToJson(Order instance) { @@ -65,13 +61,8 @@ Map _$OrderToJson(Order instance) { writeNotNull('itemNumber', instance.itemNumber); writeNotNull('isRushed', instance.isRushed); writeNotNull('item', instance.item); - writeNotNull( - 'prep-time', - instance.prepTime == null - ? null - : Order._durationToMilliseconds(instance.prepTime)); - writeNotNull('date', - instance.date == null ? null : Order._dateTimeToEpochUs(instance.date)); + writeNotNull('prep-time', Order._durationToMilliseconds(instance.prepTime)); + writeNotNull('date', Order._dateTimeToEpochUs(instance.date)); return val; } diff --git a/example/lib/json_converter_example.g.dart b/example/lib/json_converter_example.g.dart index 69100f475..5fa8fb0b0 100644 --- a/example/lib/json_converter_example.g.dart +++ b/example/lib/json_converter_example.g.dart @@ -11,9 +11,8 @@ GenericCollection _$GenericCollectionFromJson(Map json) { page: json['page'] as int, totalResults: json['total_results'] as int, totalPages: json['total_pages'] as int, - results: (json['results'] as List) - ?.map((e) => e == null ? null : _Converter().fromJson(e)) - ?.toList()); + results: + (json['results'] as List)?.map(_Converter().fromJson)?.toList()); } Map _$GenericCollectionToJson( @@ -22,9 +21,7 @@ Map _$GenericCollectionToJson( 'page': instance.page, 'total_results': instance.totalResults, 'total_pages': instance.totalPages, - 'results': instance.results - ?.map((e) => e == null ? null : _Converter().toJson(e)) - ?.toList() + 'results': instance.results?.map(_Converter().toJson)?.toList() }; CustomResult _$CustomResultFromJson(Map json) { diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 6efa64d51..b0f9ac38d 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -5,11 +5,11 @@ environment: sdk: '>=2.2.0 <3.0.0' dependencies: - json_annotation: ^2.0.0 + json_annotation: ^2.4.0 dev_dependencies: build_runner: ^1.0.0 - json_serializable: ^2.0.0 + json_serializable: ^3.0.0 # Used by tests. Not required to use `json_serializable`. build_verify: ^1.0.0 diff --git a/example/test/readme_test.dart b/example/test/readme_test.dart index 61626d31f..5b705c535 100644 --- a/example/test/readme_test.dart +++ b/example/test/readme_test.dart @@ -20,9 +20,9 @@ void _expect(String fileName) { final _pubspecContent = r''' dependencies: - json_annotation: ^2.0.0 + json_annotation: ^2.4.0 dev_dependencies: build_runner: ^1.0.0 - json_serializable: ^2.0.0 + json_serializable: ^3.0.0 '''; From 025bb1480aebe92ae46efe796bb581ec4907b685 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 22 May 2019 18:38:46 -0700 Subject: [PATCH 142/569] Use TypeChecker.fromUrl for all checkers Eliminates usage of dart:mirrors --- json_serializable/lib/src/shared_checkers.dart | 6 +++--- json_serializable/lib/src/type_helpers/value_helper.dart | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/json_serializable/lib/src/shared_checkers.dart b/json_serializable/lib/src/shared_checkers.dart index a522ed416..d32abe67a 100644 --- a/json_serializable/lib/src/shared_checkers.dart +++ b/json_serializable/lib/src/shared_checkers.dart @@ -8,7 +8,7 @@ import 'package:source_gen/source_gen.dart' show TypeChecker; /// A [TypeChecker] for [Iterable]. const coreIterableTypeChecker = TypeChecker.fromUrl('dart:core#Iterable'); -const coreStringTypeChecker = TypeChecker.fromRuntime(String); +const coreStringTypeChecker = TypeChecker.fromUrl('dart:core#String'); const coreMapTypeChecker = TypeChecker.fromUrl('dart:core#Map'); @@ -31,8 +31,8 @@ List typeArgumentsOf(DartType type, TypeChecker checker) { /// A [TypeChecker] for [String], [bool] and [num]. const simpleJsonTypeChecker = TypeChecker.any([ coreStringTypeChecker, - TypeChecker.fromRuntime(bool), - TypeChecker.fromRuntime(num) + TypeChecker.fromUrl('dart:core#bool'), + TypeChecker.fromUrl('dart:core#num') ]); String asStatement(DartType type) { diff --git a/json_serializable/lib/src/type_helpers/value_helper.dart b/json_serializable/lib/src/type_helpers/value_helper.dart index 361451db5..b0777de99 100644 --- a/json_serializable/lib/src/type_helpers/value_helper.dart +++ b/json_serializable/lib/src/type_helpers/value_helper.dart @@ -29,7 +29,7 @@ class ValueHelper extends TypeHelper { if (targetType.isDynamic || targetType.isObject) { // just return it as-is. We'll hope it's safe. return expression; - } else if (const TypeChecker.fromRuntime(double) + } else if (const TypeChecker.fromUrl('dart:core#double') .isExactlyType(targetType)) { return '($expression as num)${context.nullable ? '?' : ''}.toDouble()'; } else if (simpleJsonTypeChecker.isAssignableFromType(targetType)) { From 2dceb1bdb22dd6ee9f57879545d7ae983f1ff0e2 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 22 May 2019 18:41:34 -0700 Subject: [PATCH 143/569] DRY up implementation of TypeHelper impls that map to String --- .../lib/src/type_helpers/big_int_helper.dart | 36 ++-------- .../src/type_helpers/date_time_helper.dart | 34 ++------- .../lib/src/type_helpers/to_from_string.dart | 72 +++++++++++++++++++ .../lib/src/type_helpers/uri_helper.dart | 33 ++------- 4 files changed, 89 insertions(+), 86 deletions(-) create mode 100644 json_serializable/lib/src/type_helpers/to_from_string.dart diff --git a/json_serializable/lib/src/type_helpers/big_int_helper.dart b/json_serializable/lib/src/type_helpers/big_int_helper.dart index 61f781ae7..6a21f2218 100644 --- a/json_serializable/lib/src/type_helpers/big_int_helper.dart +++ b/json_serializable/lib/src/type_helpers/big_int_helper.dart @@ -3,44 +3,20 @@ // BSD-style license that can be found in the LICENSE file. import 'package:analyzer/dart/element/type.dart'; -import 'package:source_gen/source_gen.dart' show TypeChecker; + import '../type_helper.dart'; +import 'to_from_string.dart'; class BigIntHelper extends TypeHelper { const BigIntHelper(); @override String serialize( - DartType targetType, String expression, TypeHelperContext context) { - if (!_matchesType(targetType)) { - return null; - } - - final buffer = StringBuffer(expression); - - if (context.nullable) { - buffer.write('?'); - } - - buffer.write('.toString()'); - - return buffer.toString(); - } + DartType targetType, String expression, TypeHelperContext context) => + bigIntString.serialize(targetType, expression, context.nullable); @override String deserialize( - DartType targetType, String expression, TypeHelperContext context) { - if (!_matchesType(targetType)) { - return null; - } - - return commonNullPrefix( - context.nullable, - expression, - 'BigInt.parse($expression as String)', - ).toString(); - } + DartType targetType, String expression, TypeHelperContext context) => + bigIntString.deserialize(targetType, expression, context.nullable, false); } - -bool _matchesType(DartType type) => - const TypeChecker.fromUrl('dart:core#BigInt').isExactlyType(type); diff --git a/json_serializable/lib/src/type_helpers/date_time_helper.dart b/json_serializable/lib/src/type_helpers/date_time_helper.dart index d66f05ee9..17a6cc7b0 100644 --- a/json_serializable/lib/src/type_helpers/date_time_helper.dart +++ b/json_serializable/lib/src/type_helpers/date_time_helper.dart @@ -3,43 +3,21 @@ // BSD-style license that can be found in the LICENSE file. import 'package:analyzer/dart/element/type.dart'; -import 'package:source_gen/source_gen.dart' show TypeChecker; import '../type_helper.dart'; +import 'to_from_string.dart'; class DateTimeHelper extends TypeHelper { const DateTimeHelper(); @override String serialize( - DartType targetType, String expression, TypeHelperContext context) { - if (!_matchesType(targetType)) { - return null; - } - - final buffer = StringBuffer(expression); - - if (context.nullable) { - buffer.write('?'); - } - - buffer.write('.toIso8601String()'); - - return buffer.toString(); - } + DartType targetType, String expression, TypeHelperContext context) => + dateTimeString.serialize(targetType, expression, context.nullable); @override String deserialize( - DartType targetType, String expression, TypeHelperContext context) { - if (!_matchesType(targetType)) { - return null; - } - - return commonNullPrefix(context.nullable, expression, - 'DateTime.parse($expression as String)') - .toString(); - } + DartType targetType, String expression, TypeHelperContext context) => + dateTimeString.deserialize( + targetType, expression, context.nullable, false); } - -bool _matchesType(DartType type) => - const TypeChecker.fromUrl('dart:core#DateTime').isExactlyType(type); diff --git a/json_serializable/lib/src/type_helpers/to_from_string.dart b/json_serializable/lib/src/type_helpers/to_from_string.dart new file mode 100644 index 000000000..fde575256 --- /dev/null +++ b/json_serializable/lib/src/type_helpers/to_from_string.dart @@ -0,0 +1,72 @@ +// Copyright (c) 2019, 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:analyzer/dart/element/type.dart'; +import 'package:source_gen/source_gen.dart'; + +import '../type_helper.dart'; + +const bigIntString = ToFromStringHelper( + 'BigInt.parse', + 'toString()', + TypeChecker.fromUrl('dart:core#BigInt'), +); + +const dateTimeString = ToFromStringHelper( + 'DateTime.parse', + 'toIso8601String()', + TypeChecker.fromUrl('dart:core#DateTime'), +); + +const uriString = ToFromStringHelper( + 'Uri.parse', + 'toString()', + TypeChecker.fromUrl('dart:core#Uri'), +); + +/// Package-internal helper that unifies implementations of [Type]s that convert +/// trivially to-from [String]. +class ToFromStringHelper { + /// The function or constructor to call when creating the associated type. + /// + /// Assumed to have one parameter of type [String]. + /// + /// Example: `MyClass.parse` + final String _parse; + + /// Represents an invocation – property access or function call – on an + /// instance of the target type that returns [String]. + /// + /// Examples: `toString()` for a function or `stringValue` for a property. + final String _toString; + final TypeChecker _checker; + + const ToFromStringHelper(this._parse, this._toString, this._checker); + + bool matches(DartType type) => _checker.isExactlyType(type); + + String serialize(DartType type, String expression, bool nullable) { + if (!matches(type)) { + return null; + } + + if (nullable) { + expression = '$expression?'; + } + + return '$expression.$_toString'; + } + + String deserialize( + DartType type, String expression, bool nullable, bool isString) { + if (!matches(type)) { + return null; + } + + final parseParam = isString ? expression : '$expression as String'; + + return commonNullPrefix(nullable, expression, '$_parse($parseParam)') + .toString(); + } +} diff --git a/json_serializable/lib/src/type_helpers/uri_helper.dart b/json_serializable/lib/src/type_helpers/uri_helper.dart index e7c94854e..3a855a7ef 100644 --- a/json_serializable/lib/src/type_helpers/uri_helper.dart +++ b/json_serializable/lib/src/type_helpers/uri_helper.dart @@ -3,43 +3,20 @@ // BSD-style license that can be found in the LICENSE file. import 'package:analyzer/dart/element/type.dart'; -import 'package:source_gen/source_gen.dart' show TypeChecker; import '../type_helper.dart'; +import 'to_from_string.dart'; class UriHelper extends TypeHelper { const UriHelper(); @override String serialize( - DartType targetType, String expression, TypeHelperContext context) { - if (!_matchesType(targetType)) { - return null; - } - - final buffer = StringBuffer(expression); - - if (context.nullable) { - buffer.write('?'); - } - - buffer.write('.toString()'); - - return buffer.toString(); - } + DartType targetType, String expression, TypeHelperContext context) => + uriString.serialize(targetType, expression, context.nullable); @override String deserialize( - DartType targetType, String expression, TypeHelperContext context) { - if (!_matchesType(targetType)) { - return null; - } - - return commonNullPrefix( - context.nullable, expression, 'Uri.parse($expression as String)') - .toString(); - } + DartType targetType, String expression, TypeHelperContext context) => + uriString.deserialize(targetType, expression, context.nullable, false); } - -bool _matchesType(DartType type) => - const TypeChecker.fromUrl('dart:core#Uri').isExactlyType(type); From 4d3318213b2390a9d04ef5c95b2dfbaa14fa5263 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Fri, 24 May 2019 09:46:20 -0700 Subject: [PATCH 144/569] Fix old dartlang.org URLs (#492) --- example/README.md | 3 --- json_serializable/build.yaml | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/example/README.md b/example/README.md index fa92c1e1b..6e5e5b38d 100644 --- a/example/README.md +++ b/example/README.md @@ -1,8 +1,5 @@ *This example assumes you're using a recent version of the Dart or Flutter SDK.* -* Dart: you need [Dart 2](https://www.dartlang.org/dart-2). -* Flutter: at least 0.6.0 (August 16, 2018). - To use [package:json_serializable][json_serializable] in your package, add these dependencies to your `pubspec.yaml`. diff --git a/json_serializable/build.yaml b/json_serializable/build.yaml index dd3ea2919..bfba2eb8d 100644 --- a/json_serializable/build.yaml +++ b/json_serializable/build.yaml @@ -1,4 +1,4 @@ -# Read about `build.yaml` at https://pub.dartlang.org/packages/build_config +# Read about `build.yaml` at https://pub.dev/packages/build_config targets: $default: builders: From a1921301550743a930ed4ad3e295fb2760ca8728 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 29 May 2019 13:34:21 -0700 Subject: [PATCH 145/569] Support more non-String Map keys of obvious dart:core types (#493) Partially addresses https://github.com/dart-lang/json_serializable/issues/396 --- json_serializable/CHANGELOG.md | 4 + .../lib/src/type_helpers/map_helper.dart | 50 ++++- .../lib/src/type_helpers/to_from_string.dart | 16 +- json_serializable/pubspec.yaml | 2 +- .../test/integration/integration_test.dart | 13 ++ .../test/integration/json_test_example.dart | 24 ++ .../test/integration/json_test_example.g.dart | 25 +++ .../json_test_example.g_any_map.dart | 182 +++++++++++++++ .../json_test_example.g_any_map.g.dart | 208 ++++++++++++++++++ .../json_test_example.g_non_nullable.dart | 26 +++ .../json_test_example.g_non_nullable.g.dart | 25 +++ .../test/json_serializable_test.dart | 1 + .../src/_json_serializable_test_input.dart | 16 +- .../test/src/map_key_variety_test_input.dart | 21 ++ json_serializable/tool/test_builder.dart | 1 + 15 files changed, 594 insertions(+), 20 deletions(-) create mode 100644 json_serializable/test/integration/json_test_example.g_any_map.dart create mode 100644 json_serializable/test/integration/json_test_example.g_any_map.g.dart create mode 100644 json_serializable/test/src/map_key_variety_test_input.dart diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index fef32f0eb..cf09d70e2 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,7 @@ +## 3.1.0 + +- Support `Map` keys of type `int`, `BigInt`, `DateTime`, and `Uri`. + ## 3.0.0 This release is entirely **BREAKING** changes. It removes underused features diff --git a/json_serializable/lib/src/type_helpers/map_helper.dart b/json_serializable/lib/src/type_helpers/map_helper.dart index d3a88d6e8..ceb4be596 100644 --- a/json_serializable/lib/src/type_helpers/map_helper.dart +++ b/json_serializable/lib/src/type_helpers/map_helper.dart @@ -8,6 +8,7 @@ import '../constants.dart'; import '../shared_checkers.dart'; import '../type_helper.dart'; import '../utils.dart'; +import 'to_from_string.dart'; const _keyParam = 'k'; @@ -29,7 +30,9 @@ class MapHelper extends TypeHelper { _checkSafeKeyType(expression, keyType); final subFieldValue = context.serialize(valueType, closureArg); - final subKeyValue = context.serialize(keyType, _keyParam); + final subKeyValue = + _forType(keyType)?.serialize(keyType, _keyParam, false) ?? + context.serialize(keyType, _keyParam); if (closureArg == subFieldValue && _keyParam == subKeyValue) { return expression; @@ -56,9 +59,9 @@ class MapHelper extends TypeHelper { _checkSafeKeyType(expression, keyArg); final valueArgIsAny = _isObjectOrDynamic(valueArg); - final isEnumKey = isEnum(keyArg); + final isKeyStringable = _isKeyStringable(keyArg); - if (!isEnumKey) { + if (!isKeyStringable) { if (valueArgIsAny) { if (context.config.anyMap) { if (_isObjectOrDynamic(keyArg)) { @@ -90,7 +93,7 @@ class MapHelper extends TypeHelper { context.config.anyMap ? 'as Map' : 'as Map'; String keyUsage; - if (isEnumKey) { + if (isEnum(keyArg)) { keyUsage = context.deserialize(keyArg, _keyParam).toString(); } else if (context.config.anyMap && !_isObjectOrDynamic(keyArg)) { keyUsage = '$_keyParam as String'; @@ -98,22 +101,57 @@ class MapHelper extends TypeHelper { keyUsage = _keyParam; } + final toFromString = _forType(keyArg); + if (toFromString != null) { + keyUsage = toFromString.deserialize(keyArg, keyUsage, false, true); + } + return '($expression $mapCast)$optionalQuestion.map(' '($_keyParam, $closureArg) => MapEntry($keyUsage, $itemSubVal),)'; } } +final _intString = ToFromStringHelper('int.parse', 'toString()', 'int'); + +/// [ToFromStringHelper] instances representing non-String types that can +/// be used as [Map] keys. +final _instances = [ + bigIntString, + dateTimeString, + _intString, + uriString, +]; + +ToFromStringHelper _forType(DartType type) => + _instances.singleWhere((i) => i.matches(type), orElse: () => null); + bool _isObjectOrDynamic(DartType type) => type.isObject || type.isDynamic; +/// Returns `true` if [keyType] can be automatically converted to/from String – +/// and is therefor usable as a key in a [Map]. +bool _isKeyStringable(DartType keyType) => + isEnum(keyType) || _instances.any((inst) => inst.matches(keyType)); + void _checkSafeKeyType(String expression, DartType keyArg) { // We're not going to handle converting key types at the moment // So the only safe types for key are dynamic/Object/String/enum final safeKey = _isObjectOrDynamic(keyArg) || coreStringTypeChecker.isExactlyType(keyArg) || - isEnum(keyArg); + _isKeyStringable(keyArg); if (!safeKey) { throw UnsupportedTypeError(keyArg, expression, - 'Map keys must be of type `String`, enum, `Object` or `dynamic`.'); + 'Map keys must be one of: ${_allowedTypeNames.join(', ')}.'); } } + +/// The names of types that can be used as [Map] keys. +/// +/// Used in [_checkSafeKeyType] to provide a helpful error with unsupported +/// types. +Iterable get _allowedTypeNames => const [ + 'Object', + 'dynamic', + 'enum', + 'String', + ].followedBy(_instances.map((i) => i.coreTypeName)); diff --git a/json_serializable/lib/src/type_helpers/to_from_string.dart b/json_serializable/lib/src/type_helpers/to_from_string.dart index fde575256..5de4ca6e9 100644 --- a/json_serializable/lib/src/type_helpers/to_from_string.dart +++ b/json_serializable/lib/src/type_helpers/to_from_string.dart @@ -7,22 +7,22 @@ import 'package:source_gen/source_gen.dart'; import '../type_helper.dart'; -const bigIntString = ToFromStringHelper( +final bigIntString = ToFromStringHelper( 'BigInt.parse', 'toString()', - TypeChecker.fromUrl('dart:core#BigInt'), + 'BigInt', ); -const dateTimeString = ToFromStringHelper( +final dateTimeString = ToFromStringHelper( 'DateTime.parse', 'toIso8601String()', - TypeChecker.fromUrl('dart:core#DateTime'), + 'DateTime', ); -const uriString = ToFromStringHelper( +final uriString = ToFromStringHelper( 'Uri.parse', 'toString()', - TypeChecker.fromUrl('dart:core#Uri'), + 'Uri', ); /// Package-internal helper that unifies implementations of [Type]s that convert @@ -40,9 +40,11 @@ class ToFromStringHelper { /// /// Examples: `toString()` for a function or `stringValue` for a property. final String _toString; + final String coreTypeName; final TypeChecker _checker; - const ToFromStringHelper(this._parse, this._toString, this._checker); + ToFromStringHelper(this._parse, this._toString, this.coreTypeName) + : _checker = TypeChecker.fromUrl('dart:core#$coreTypeName'); bool matches(DartType type) => _checker.isExactlyType(type); diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 74199658a..b1aff4261 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 3.0.0 +version: 3.1.0-dev author: Dart Team description: >- Automatically generate code for converting to and from JSON by annotating diff --git a/json_serializable/test/integration/integration_test.dart b/json_serializable/test/integration/integration_test.dart index 2c43e0eb1..b9ebb6767 100644 --- a/json_serializable/test/integration/integration_test.dart +++ b/json_serializable/test/integration/integration_test.dart @@ -232,4 +232,17 @@ void main() { expect(() => Numbers.fromJson(value), throwsCastError); }); }); + + test('MapKeyVariety', () { + final instance = MapKeyVariety() + ..bigIntMap = {BigInt.from(1): 1} + ..dateTimeIntMap = {DateTime.parse('2018-01-01'): 2} + ..intIntMap = {3: 3} + ..uriIntMap = {Uri.parse('https://example.com'): 4}; + + final roundTrip = + roundTripObject(instance, (j) => MapKeyVariety.fromJson(j)); + + expect(roundTrip, instance); + }); } diff --git a/json_serializable/test/integration/json_test_example.dart b/json_serializable/test/integration/json_test_example.dart index 49c1f516d..a4dd9d379 100644 --- a/json_serializable/test/integration/json_test_example.dart +++ b/json_serializable/test/integration/json_test_example.dart @@ -6,6 +6,7 @@ import 'dart:collection'; import 'package:json_annotation/json_annotation.dart'; + import 'json_test_common.dart'; part 'json_test_example.g.dart'; @@ -146,3 +147,26 @@ class Numbers { deepEquals(duration, other.duration) && deepEquals(date, other.date); } + +@JsonSerializable() +class MapKeyVariety { + Map intIntMap; + Map uriIntMap; + Map dateTimeIntMap; + Map bigIntMap; + + MapKeyVariety(); + + factory MapKeyVariety.fromJson(Map json) => + _$MapKeyVarietyFromJson(json); + + Map toJson() => _$MapKeyVarietyToJson(this); + + @override + bool operator ==(Object other) => + other is MapKeyVariety && + deepEquals(other.intIntMap, intIntMap) && + deepEquals(other.uriIntMap, uriIntMap) && + deepEquals(other.dateTimeIntMap, dateTimeIntMap) && + deepEquals(other.bigIntMap, bigIntMap); +} diff --git a/json_serializable/test/integration/json_test_example.g.dart b/json_serializable/test/integration/json_test_example.g.dart index 54164e8ea..4677d022e 100644 --- a/json_serializable/test/integration/json_test_example.g.dart +++ b/json_serializable/test/integration/json_test_example.g.dart @@ -171,3 +171,28 @@ Map _$NumbersToJson(Numbers instance) => { 'duration': durationToInt(instance.duration), 'date': dateTimeToEpochUs(instance.date) }; + +MapKeyVariety _$MapKeyVarietyFromJson(Map json) { + return MapKeyVariety() + ..intIntMap = (json['intIntMap'] as Map)?.map( + (k, e) => MapEntry(int.parse(k), e as int), + ) + ..uriIntMap = (json['uriIntMap'] as Map)?.map( + (k, e) => MapEntry(Uri.parse(k), e as int), + ) + ..dateTimeIntMap = (json['dateTimeIntMap'] as Map)?.map( + (k, e) => MapEntry(DateTime.parse(k), e as int), + ) + ..bigIntMap = (json['bigIntMap'] as Map)?.map( + (k, e) => MapEntry(BigInt.parse(k), e as int), + ); +} + +Map _$MapKeyVarietyToJson(MapKeyVariety instance) => + { + 'intIntMap': instance.intIntMap?.map((k, e) => MapEntry(k.toString(), e)), + 'uriIntMap': instance.uriIntMap?.map((k, e) => MapEntry(k.toString(), e)), + 'dateTimeIntMap': instance.dateTimeIntMap + ?.map((k, e) => MapEntry(k.toIso8601String(), e)), + 'bigIntMap': instance.bigIntMap?.map((k, e) => MapEntry(k.toString(), e)) + }; diff --git a/json_serializable/test/integration/json_test_example.g_any_map.dart b/json_serializable/test/integration/json_test_example.g_any_map.dart new file mode 100644 index 000000000..a357963a3 --- /dev/null +++ b/json_serializable/test/integration/json_test_example.g_any_map.dart @@ -0,0 +1,182 @@ +// Copyright (c) 2018, 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. + +// ignore_for_file: hash_and_equals +import 'dart:collection'; + +import 'package:json_annotation/json_annotation.dart'; + +import 'json_test_common.dart'; + +part 'json_test_example.g_any_map.g.dart'; + +@JsonSerializable( + anyMap: true, +) +class Person { + final String firstName, middleName, lastName; + final DateTime dateOfBirth; + @JsonKey(name: '\$house') + final Category house; + + Order order; + + MyList customOrders; + + Map houseMap; + Map categoryCounts; + + Person(this.firstName, this.lastName, this.house, + {this.middleName, this.dateOfBirth}); + + factory Person.fromJson(Map json) => _$PersonFromJson(json); + + Map toJson() => _$PersonToJson(this); + + @override + bool operator ==(Object other) => + other is Person && + firstName == other.firstName && + middleName == other.middleName && + lastName == other.lastName && + dateOfBirth == other.dateOfBirth && + house == other.house && + deepEquals(houseMap, other.houseMap); +} + +@JsonSerializable( + anyMap: true, +) +class Order { + /// Used to test that `disallowNullValues: true` forces `includeIfNull: false` + @JsonKey(disallowNullValue: true) + int count; + bool isRushed; + + Duration duration; + + @JsonKey(nullable: false) + final Category category; + final UnmodifiableListView items; + Platform platform; + Map altPlatforms; + + Uri homepage; + + @JsonKey( + name: 'status_code', defaultValue: StatusCode.success, nullable: true) + StatusCode statusCode; + + @JsonKey(ignore: true) + String get platformValue => platform?.description; + + set platformValue(String value) { + throw UnimplementedError('not impld'); + } + + // Ignored getter without value set in ctor + int get price => items.fold(0, (total, item) => item.price + total); + + @JsonKey(ignore: true) + bool shouldBeCached; + + Order(this.category, [Iterable items]) + : items = UnmodifiableListView( + List.unmodifiable(items ?? const [])); + + factory Order.fromJson(Map json) => _$OrderFromJson(json); + + Map toJson() => _$OrderToJson(this); + + @override + bool operator ==(Object other) => + other is Order && + count == other.count && + isRushed == other.isRushed && + deepEquals(items, other.items) && + deepEquals(altPlatforms, other.altPlatforms); +} + +@JsonSerializable( + anyMap: true, +) +class Item extends ItemCore { + @JsonKey(includeIfNull: false, name: 'item-number') + int itemNumber; + List saleDates; + List rates; + + Item([int price]) : super(price); + + factory Item.fromJson(Map json) => _$ItemFromJson(json); + + Map toJson() => _$ItemToJson(this); + + @override + bool operator ==(Object other) => + other is Item && + price == other.price && + itemNumber == other.itemNumber && + deepEquals(saleDates, other.saleDates); +} + +@JsonSerializable( + anyMap: true, +) +class Numbers { + List ints; + List nums; + List doubles; + + @JsonKey(nullable: false) + List nnDoubles; + + @JsonKey(fromJson: durationFromInt, toJson: durationToInt) + Duration duration; + + @JsonKey(fromJson: dateTimeFromEpochUs, toJson: dateTimeToEpochUs) + DateTime date; + + Numbers(); + + factory Numbers.fromJson(Map json) => + _$NumbersFromJson(json); + + Map toJson() => _$NumbersToJson(this); + + @override + bool operator ==(Object other) => + other is Numbers && + deepEquals(ints, other.ints) && + deepEquals(nums, other.nums) && + deepEquals(doubles, other.doubles) && + deepEquals(nnDoubles, other.nnDoubles) && + deepEquals(duration, other.duration) && + deepEquals(date, other.date); +} + +@JsonSerializable( + anyMap: true, +) +class MapKeyVariety { + Map intIntMap; + Map uriIntMap; + Map dateTimeIntMap; + Map bigIntMap; + + MapKeyVariety(); + + factory MapKeyVariety.fromJson(Map json) => + _$MapKeyVarietyFromJson(json); + + Map toJson() => _$MapKeyVarietyToJson(this); + + @override + bool operator ==(Object other) => + other is MapKeyVariety && + deepEquals(other.intIntMap, intIntMap) && + deepEquals(other.uriIntMap, uriIntMap) && + deepEquals(other.dateTimeIntMap, dateTimeIntMap) && + deepEquals(other.bigIntMap, bigIntMap); +} diff --git a/json_serializable/test/integration/json_test_example.g_any_map.g.dart b/json_serializable/test/integration/json_test_example.g_any_map.g.dart new file mode 100644 index 000000000..b6ce0e298 --- /dev/null +++ b/json_serializable/test/integration/json_test_example.g_any_map.g.dart @@ -0,0 +1,208 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'json_test_example.g_any_map.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +Person _$PersonFromJson(Map json) { + return Person(json['firstName'] as String, json['lastName'] as String, + _$enumDecodeNullable(_$CategoryEnumMap, json[r'$house']), + middleName: json['middleName'] as String, + dateOfBirth: json['dateOfBirth'] == null + ? null + : DateTime.parse(json['dateOfBirth'] as String)) + ..order = json['order'] == null + ? null + : Order.fromJson((json['order'] as Map)?.map( + (k, e) => MapEntry(k as String, e), + )) + ..customOrders = json['customOrders'] == null + ? null + : MyList.fromJson((json['customOrders'] as List) + ?.map((e) => e == null + ? null + : Order.fromJson((e as Map)?.map( + (k, e) => MapEntry(k as String, e), + ))) + ?.toList()) + ..houseMap = (json['houseMap'] as Map)?.map( + (k, e) => + MapEntry(k as String, _$enumDecodeNullable(_$CategoryEnumMap, e)), + ) + ..categoryCounts = (json['categoryCounts'] as Map)?.map( + (k, e) => MapEntry(_$enumDecodeNullable(_$CategoryEnumMap, k), e as int), + ); +} + +Map _$PersonToJson(Person instance) => { + 'firstName': instance.firstName, + 'middleName': instance.middleName, + 'lastName': instance.lastName, + 'dateOfBirth': instance.dateOfBirth?.toIso8601String(), + r'$house': _$CategoryEnumMap[instance.house], + 'order': instance.order, + 'customOrders': instance.customOrders, + 'houseMap': + instance.houseMap?.map((k, e) => MapEntry(k, _$CategoryEnumMap[e])), + 'categoryCounts': instance.categoryCounts + ?.map((k, e) => MapEntry(_$CategoryEnumMap[k], e)) + }; + +T _$enumDecode(Map enumValues, dynamic source) { + if (source == null) { + throw ArgumentError('A value must be provided. Supported values: ' + '${enumValues.values.join(', ')}'); + } + return enumValues.entries + .singleWhere((e) => e.value == source, + orElse: () => throw ArgumentError( + '`$source` is not one of the supported values: ' + '${enumValues.values.join(', ')}')) + .key; +} + +T _$enumDecodeNullable(Map enumValues, dynamic source) { + if (source == null) { + return null; + } + return _$enumDecode(enumValues, source); +} + +const _$CategoryEnumMap = { + Category.top: 'top', + Category.bottom: 'bottom', + Category.strange: 'strange', + Category.charmed: 'charmed', + Category.up: 'up', + Category.down: 'down', + Category.notDiscoveredYet: 'not_discovered_yet' +}; + +Order _$OrderFromJson(Map json) { + $checkKeys(json, disallowNullValues: const ['count']); + return Order( + _$enumDecode(_$CategoryEnumMap, json['category']), + (json['items'] as List)?.map((e) => e == null + ? null + : Item.fromJson((e as Map)?.map( + (k, e) => MapEntry(k as String, e), + )))) + ..count = json['count'] as int + ..isRushed = json['isRushed'] as bool + ..duration = json['duration'] == null + ? null + : Duration(microseconds: json['duration'] as int) + ..platform = json['platform'] == null + ? null + : Platform.fromJson(json['platform'] as String) + ..altPlatforms = (json['altPlatforms'] as Map)?.map( + (k, e) => MapEntry( + k as String, e == null ? null : Platform.fromJson(e as String)), + ) + ..homepage = + json['homepage'] == null ? null : Uri.parse(json['homepage'] as String) + ..statusCode = + _$enumDecodeNullable(_$StatusCodeEnumMap, json['status_code']) ?? + StatusCode.success; +} + +Map _$OrderToJson(Order instance) { + final val = {}; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('count', instance.count); + val['isRushed'] = instance.isRushed; + val['duration'] = instance.duration?.inMicroseconds; + val['category'] = _$CategoryEnumMap[instance.category]; + val['items'] = instance.items; + val['platform'] = instance.platform; + val['altPlatforms'] = instance.altPlatforms; + val['homepage'] = instance.homepage?.toString(); + val['status_code'] = _$StatusCodeEnumMap[instance.statusCode]; + return val; +} + +const _$StatusCodeEnumMap = { + StatusCode.success: 200, + StatusCode.notFound: 404 +}; + +Item _$ItemFromJson(Map json) { + return Item(json['price'] as int) + ..itemNumber = json['item-number'] as int + ..saleDates = (json['saleDates'] as List) + ?.map((e) => e == null ? null : DateTime.parse(e as String)) + ?.toList() + ..rates = (json['rates'] as List)?.map((e) => e as int)?.toList(); +} + +Map _$ItemToJson(Item instance) { + final val = { + 'price': instance.price, + }; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('item-number', instance.itemNumber); + val['saleDates'] = + instance.saleDates?.map((e) => e?.toIso8601String())?.toList(); + val['rates'] = instance.rates; + return val; +} + +Numbers _$NumbersFromJson(Map json) { + return Numbers() + ..ints = (json['ints'] as List)?.map((e) => e as int)?.toList() + ..nums = (json['nums'] as List)?.map((e) => e as num)?.toList() + ..doubles = + (json['doubles'] as List)?.map((e) => (e as num)?.toDouble())?.toList() + ..nnDoubles = + (json['nnDoubles'] as List).map((e) => (e as num).toDouble()).toList() + ..duration = durationFromInt(json['duration'] as int) + ..date = dateTimeFromEpochUs(json['date'] as int); +} + +Map _$NumbersToJson(Numbers instance) => { + 'ints': instance.ints, + 'nums': instance.nums, + 'doubles': instance.doubles, + 'nnDoubles': instance.nnDoubles, + 'duration': durationToInt(instance.duration), + 'date': dateTimeToEpochUs(instance.date) + }; + +MapKeyVariety _$MapKeyVarietyFromJson(Map json) { + return MapKeyVariety() + ..intIntMap = (json['intIntMap'] as Map)?.map( + (k, e) => MapEntry(int.parse(k as String), e as int), + ) + ..uriIntMap = (json['uriIntMap'] as Map)?.map( + (k, e) => MapEntry(Uri.parse(k as String), e as int), + ) + ..dateTimeIntMap = (json['dateTimeIntMap'] as Map)?.map( + (k, e) => MapEntry(DateTime.parse(k as String), e as int), + ) + ..bigIntMap = (json['bigIntMap'] as Map)?.map( + (k, e) => MapEntry(BigInt.parse(k as String), e as int), + ); +} + +Map _$MapKeyVarietyToJson(MapKeyVariety instance) => + { + 'intIntMap': instance.intIntMap?.map((k, e) => MapEntry(k.toString(), e)), + 'uriIntMap': instance.uriIntMap?.map((k, e) => MapEntry(k.toString(), e)), + 'dateTimeIntMap': instance.dateTimeIntMap + ?.map((k, e) => MapEntry(k.toIso8601String(), e)), + 'bigIntMap': instance.bigIntMap?.map((k, e) => MapEntry(k.toString(), e)) + }; diff --git a/json_serializable/test/integration/json_test_example.g_non_nullable.dart b/json_serializable/test/integration/json_test_example.g_non_nullable.dart index 6eef16418..ec073990d 100644 --- a/json_serializable/test/integration/json_test_example.g_non_nullable.dart +++ b/json_serializable/test/integration/json_test_example.g_non_nullable.dart @@ -6,6 +6,7 @@ import 'dart:collection'; import 'package:json_annotation/json_annotation.dart'; + import 'json_test_common.dart'; part 'json_test_example.g_non_nullable.g.dart'; @@ -154,3 +155,28 @@ class Numbers { deepEquals(duration, other.duration) && deepEquals(date, other.date); } + +@JsonSerializable( + nullable: false, +) +class MapKeyVariety { + Map intIntMap; + Map uriIntMap; + Map dateTimeIntMap; + Map bigIntMap; + + MapKeyVariety(); + + factory MapKeyVariety.fromJson(Map json) => + _$MapKeyVarietyFromJson(json); + + Map toJson() => _$MapKeyVarietyToJson(this); + + @override + bool operator ==(Object other) => + other is MapKeyVariety && + deepEquals(other.intIntMap, intIntMap) && + deepEquals(other.uriIntMap, uriIntMap) && + deepEquals(other.dateTimeIntMap, dateTimeIntMap) && + deepEquals(other.bigIntMap, bigIntMap); +} diff --git a/json_serializable/test/integration/json_test_example.g_non_nullable.g.dart b/json_serializable/test/integration/json_test_example.g_non_nullable.g.dart index 712a0b902..3ea80cb38 100644 --- a/json_serializable/test/integration/json_test_example.g_non_nullable.g.dart +++ b/json_serializable/test/integration/json_test_example.g_non_nullable.g.dart @@ -139,3 +139,28 @@ Map _$NumbersToJson(Numbers instance) => { 'duration': durationToInt(instance.duration), 'date': dateTimeToEpochUs(instance.date) }; + +MapKeyVariety _$MapKeyVarietyFromJson(Map json) { + return MapKeyVariety() + ..intIntMap = (json['intIntMap'] as Map).map( + (k, e) => MapEntry(int.parse(k), e as int), + ) + ..uriIntMap = (json['uriIntMap'] as Map).map( + (k, e) => MapEntry(Uri.parse(k), e as int), + ) + ..dateTimeIntMap = (json['dateTimeIntMap'] as Map).map( + (k, e) => MapEntry(DateTime.parse(k), e as int), + ) + ..bigIntMap = (json['bigIntMap'] as Map).map( + (k, e) => MapEntry(BigInt.parse(k), e as int), + ); +} + +Map _$MapKeyVarietyToJson(MapKeyVariety instance) => + { + 'intIntMap': instance.intIntMap.map((k, e) => MapEntry(k.toString(), e)), + 'uriIntMap': instance.uriIntMap.map((k, e) => MapEntry(k.toString(), e)), + 'dateTimeIntMap': instance.dateTimeIntMap + .map((k, e) => MapEntry(k.toIso8601String(), e)), + 'bigIntMap': instance.bigIntMap.map((k, e) => MapEntry(k.toString(), e)) + }; diff --git a/json_serializable/test/json_serializable_test.dart b/json_serializable/test/json_serializable_test.dart index 312212682..de372631c 100644 --- a/json_serializable/test/json_serializable_test.dart +++ b/json_serializable/test/json_serializable_test.dart @@ -68,6 +68,7 @@ const _expectedAnnotatedTests = [ 'JustSetterNoFromJson', 'JustSetterNoToJson', 'KeyDupesField', + 'MapKeyVariety', 'NoCtorClass', 'NoDeserializeBadKey', 'NoDeserializeFieldType', diff --git a/json_serializable/test/src/_json_serializable_test_input.dart b/json_serializable/test/src/_json_serializable_test_input.dart index afe880f13..62b7da242 100644 --- a/json_serializable/test/src/_json_serializable_test_input.dart +++ b/json_serializable/test/src/_json_serializable_test_input.dart @@ -21,6 +21,8 @@ part 'inheritance_test_input.dart'; part 'json_converter_test_input.dart'; +part 'map_key_variety_test_input.dart'; + part 'setter_test_input.dart'; part 'to_from_json_test_input.dart'; @@ -207,23 +209,25 @@ class NoDeserializeFieldType { } @ShouldThrow( - 'Could not generate `toJson` code for `intDateTimeMap` because of type `int`.\n' - 'Map keys must be of type `String`, enum, `Object` or `dynamic`.', + ''' +Could not generate `toJson` code for `durationDateTimeMap` because of type `Duration`. +Map keys must be one of: Object, dynamic, enum, String, BigInt, DateTime, int, Uri.''', configurations: ['default'], ) @JsonSerializable(createFactory: false) class NoSerializeBadKey { - Map intDateTimeMap; + Map durationDateTimeMap; } @ShouldThrow( - 'Could not generate `fromJson` code for `intDateTimeMap` because of type `int`.\n' - 'Map keys must be of type `String`, enum, `Object` or `dynamic`.', + ''' +Could not generate `fromJson` code for `durationDateTimeMap` because of type `Duration`. +Map keys must be one of: Object, dynamic, enum, String, BigInt, DateTime, int, Uri.''', configurations: ['default'], ) @JsonSerializable(createToJson: false) class NoDeserializeBadKey { - Map intDateTimeMap; + Map durationDateTimeMap; } @ShouldGenerate( diff --git a/json_serializable/test/src/map_key_variety_test_input.dart b/json_serializable/test/src/map_key_variety_test_input.dart new file mode 100644 index 000000000..93d92422b --- /dev/null +++ b/json_serializable/test/src/map_key_variety_test_input.dart @@ -0,0 +1,21 @@ +part of '_json_serializable_test_input.dart'; + +@ShouldGenerate( + r''' +MapKeyVariety _$MapKeyVarietyFromJson(Map json) { + return MapKeyVariety() + ..intIntMap = (json['intIntMap'] as Map)?.map( + (k, e) => MapEntry(int.parse(k), e as int), + ); +} + +Map _$MapKeyVarietyToJson(MapKeyVariety instance) => + { + 'intIntMap': instance.intIntMap?.map((k, e) => MapEntry(k.toString(), e)) + }; +''', +) +@JsonSerializable() +class MapKeyVariety { + Map intIntMap; +} diff --git a/json_serializable/tool/test_builder.dart b/json_serializable/tool/test_builder.dart index 1e3eaf2b2..f596cf6b0 100644 --- a/json_serializable/tool/test_builder.dart +++ b/json_serializable/tool/test_builder.dart @@ -233,6 +233,7 @@ const _fileConfigurationMap = >>{ }, 'generic_class': >{}, 'json_test_example': { + {'any_map'}, {'non_nullable'}, } }; From c88a6321a5531009ab209551998a28cf46c4d479 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 29 May 2019 15:12:51 -0700 Subject: [PATCH 146/569] enable latest pendantic lints (#495) --- analysis_options.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/analysis_options.yaml b/analysis_options.yaml index 4d865a45c..b37f52617 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -29,6 +29,7 @@ linter: - comment_references - constant_identifier_names - control_flow_in_finally + - curly_braces_in_flow_control_structures - directives_ordering - empty_catches - empty_constructor_bodies @@ -79,6 +80,7 @@ linter: - unnecessary_lambdas - unnecessary_new - unnecessary_null_aware_assignments + - unnecessary_null_in_if_null_operators - unnecessary_parenthesis - unnecessary_statements - unnecessary_this From f50b6c3ce1a742dbf6651eae1909968d23e74cad Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 29 May 2019 20:05:12 -0700 Subject: [PATCH 147/569] Add trailing commas to constructor invocations and Map literals (#494) Subjective, but it seems to make the generated code more readable --- _test_yaml/test/src/build_config.g.dart | 66 ++++++++-------- json_serializable/CHANGELOG.md | 2 + json_serializable/README.md | 9 ++- json_serializable/example/example.g.dart | 9 ++- json_serializable/lib/src/decode_helper.dart | 11 +-- json_serializable/lib/src/encoder_helper.dart | 8 +- .../test/custom_configuration_test.dart | 4 +- .../test/generic_files/generic_class.g.dart | 4 +- .../test/integration/json_test_example.g.dart | 32 ++++---- .../json_test_example.g_any_map.g.dart | 38 ++++++---- .../json_test_example.g_non_nullable.g.dart | 32 ++++---- .../test/kitchen_sink/kitchen_sink.g.dart | 21 ++--- .../kitchen_sink.g_any_map.g.dart | 21 ++--- ...nk.g_any_map__checked__non_nullable.g.dart | 26 +++---- ...itchen_sink.g_any_map__non_nullable.g.dart | 21 ++--- .../kitchen_sink.g_exclude_null.g.dart | 15 ++-- ...n_sink.g_exclude_null__non_nullable.g.dart | 17 +++-- .../kitchen_sink.g_explicit_to_json.g.dart | 21 ++--- .../kitchen_sink.g_non_nullable.g.dart | 21 ++--- .../test/kitchen_sink/simple_object.g.dart | 8 +- .../kitchen_sink/strict_keys_object.g.dart | 7 +- .../src/_json_serializable_test_input.dart | 76 +++++++++---------- .../test/src/checked_test_input.dart | 9 ++- .../test/src/field_namer_input.dart | 36 +++------ .../test/src/generic_test_input.dart | 8 +- .../test/src/inheritance_test_input.dart | 36 ++++----- .../test/src/json_converter_test_input.dart | 18 ++--- .../test/src/map_key_variety_test_input.dart | 8 +- .../test/src/to_from_json_test_input.dart | 2 +- .../test/src/unknown_type_test_input.dart | 48 ++++++------ 30 files changed, 314 insertions(+), 320 deletions(-) diff --git a/_test_yaml/test/src/build_config.g.dart b/_test_yaml/test/src/build_config.g.dart index f4938333e..d71377ee0 100644 --- a/_test_yaml/test/src/build_config.g.dart +++ b/_test_yaml/test/src/build_config.g.dart @@ -10,13 +10,14 @@ Config _$ConfigFromJson(Map json) { return $checkedNew('Config', json, () { $checkKeys(json, requiredKeys: const ['builders']); final val = Config( - builders: $checkedConvert( - json, - 'builders', - (v) => (v as Map)?.map( - (k, e) => MapEntry(k as String, - e == null ? null : Builder.fromJson(e as Map)), - ))); + builders: $checkedConvert( + json, + 'builders', + (v) => (v as Map)?.map( + (k, e) => MapEntry( + k as String, e == null ? null : Builder.fromJson(e as Map)), + )), + ); $checkedConvert( json, 'weights', @@ -31,7 +32,7 @@ Config _$ConfigFromJson(Map json) { Map _$ConfigToJson(Config instance) => { 'builders': instance.builders, 'weights': - instance.weights?.map((k, e) => MapEntry(_$AutoApplyEnumMap[k], e)) + instance.weights?.map((k, e) => MapEntry(_$AutoApplyEnumMap[k], e)), }; T _$enumDecode(Map enumValues, dynamic source) { @@ -80,30 +81,31 @@ Builder _$BuilderFromJson(Map json) { 'auto_apply' ]); final val = Builder( - import: $checkedConvert(json, 'import', (v) => v as String), - target: $checkedConvert(json, 'target', (v) => v as String), - isOptional: $checkedConvert(json, 'is_optional', (v) => v as bool), - autoApply: $checkedConvert(json, 'auto_apply', - (v) => _$enumDecodeNullable(_$AutoApplyEnumMap, v)), - buildTo: $checkedConvert( - json, 'build_to', (v) => _$enumDecodeNullable(_$BuildToEnumMap, v)), - defaultEnumTest: $checkedConvert(json, 'defaultEnumTest', - (v) => _$enumDecodeNullable(_$AutoApplyEnumMap, v)), - builderFactories: $checkedConvert(json, 'builder_factories', - (v) => (v as List).map((e) => e as String).toList()), - appliesBuilders: $checkedConvert(json, 'applies_builders', - (v) => (v as List)?.map((e) => e as String)?.toList()), - requiredInputs: $checkedConvert(json, 'required_inputs', - (v) => (v as List)?.map((e) => e as String)?.toList()), - buildExtensions: $checkedConvert( - json, - 'build_extensions', - (v) => (v as Map)?.map( - (k, e) => MapEntry(k as String, - (e as List)?.map((e) => e as String)?.toList()), - )), - configLocation: $checkedConvert(json, 'configLocation', - (v) => v == null ? null : Uri.parse(v as String))); + import: $checkedConvert(json, 'import', (v) => v as String), + target: $checkedConvert(json, 'target', (v) => v as String), + isOptional: $checkedConvert(json, 'is_optional', (v) => v as bool), + autoApply: $checkedConvert(json, 'auto_apply', + (v) => _$enumDecodeNullable(_$AutoApplyEnumMap, v)), + buildTo: $checkedConvert( + json, 'build_to', (v) => _$enumDecodeNullable(_$BuildToEnumMap, v)), + defaultEnumTest: $checkedConvert(json, 'defaultEnumTest', + (v) => _$enumDecodeNullable(_$AutoApplyEnumMap, v)), + builderFactories: $checkedConvert(json, 'builder_factories', + (v) => (v as List).map((e) => e as String).toList()), + appliesBuilders: $checkedConvert(json, 'applies_builders', + (v) => (v as List)?.map((e) => e as String)?.toList()), + requiredInputs: $checkedConvert(json, 'required_inputs', + (v) => (v as List)?.map((e) => e as String)?.toList()), + buildExtensions: $checkedConvert( + json, + 'build_extensions', + (v) => (v as Map)?.map( + (k, e) => MapEntry(k as String, + (e as List)?.map((e) => e as String)?.toList()), + )), + configLocation: $checkedConvert(json, 'configLocation', + (v) => v == null ? null : Uri.parse(v as String)), + ); return val; }, fieldKeyMap: const { 'isOptional': 'is_optional', diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index cf09d70e2..8ac24f2be 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,6 +1,8 @@ ## 3.1.0 - Support `Map` keys of type `int`, `BigInt`, `DateTime`, and `Uri`. +- Trailing commas are now added to generated constructor arguments and the + elements in `Map` literals. ## 3.0.0 diff --git a/json_serializable/README.md b/json_serializable/README.md index 60d52c671..b89ceb105 100644 --- a/json_serializable/README.md +++ b/json_serializable/README.md @@ -46,15 +46,16 @@ part of 'example.dart'; Person _$PersonFromJson(Map json) { return Person( - firstName: json['firstName'] as String, - lastName: json['lastName'] as String, - dateOfBirth: DateTime.parse(json['dateOfBirth'] as String)); + firstName: json['firstName'] as String, + lastName: json['lastName'] as String, + dateOfBirth: DateTime.parse(json['dateOfBirth'] as String), + ); } Map _$PersonToJson(Person instance) => { 'firstName': instance.firstName, 'lastName': instance.lastName, - 'dateOfBirth': instance.dateOfBirth.toIso8601String() + 'dateOfBirth': instance.dateOfBirth.toIso8601String(), }; ``` diff --git a/json_serializable/example/example.g.dart b/json_serializable/example/example.g.dart index 2c15a02e3..4d790cf8c 100644 --- a/json_serializable/example/example.g.dart +++ b/json_serializable/example/example.g.dart @@ -8,13 +8,14 @@ part of 'example.dart'; Person _$PersonFromJson(Map json) { return Person( - firstName: json['firstName'] as String, - lastName: json['lastName'] as String, - dateOfBirth: DateTime.parse(json['dateOfBirth'] as String)); + firstName: json['firstName'] as String, + lastName: json['lastName'] as String, + dateOfBirth: DateTime.parse(json['dateOfBirth'] as String), + ); } Map _$PersonToJson(Person instance) => { 'firstName': instance.firstName, 'lastName': instance.lastName, - 'dateOfBirth': instance.dateOfBirth.toIso8601String() + 'dateOfBirth': instance.dateOfBirth.toIso8601String(), }; diff --git a/json_serializable/lib/src/decode_helper.dart b/json_serializable/lib/src/decode_helper.dart index e737e4c03..e8a058190 100644 --- a/json_serializable/lib/src/decode_helper.dart +++ b/json_serializable/lib/src/decode_helper.dart @@ -280,19 +280,16 @@ _ConstructorData _writeConstructorInvocation( buffer.writeAll(constructorArguments.map((paramElement) { final content = deserializeForField(paramElement.name, ctorParam: paramElement); - return ' $content'; - }), ',\n'); - if (namedConstructorArguments.isNotEmpty) { - buffer.write(','); - } + return ' $content,\n'; + })); } if (namedConstructorArguments.isNotEmpty) { buffer.writeln(); buffer.writeAll(namedConstructorArguments.map((paramElement) { final value = deserializeForField(paramElement.name, ctorParam: paramElement); - return ' ${paramElement.name}: $value'; - }), ',\n'); + return ' ${paramElement.name}: $value,\n'; + })); } buffer.write(')'); diff --git a/json_serializable/lib/src/encoder_helper.dart b/json_serializable/lib/src/encoder_helper.dart index ada4be389..2c4afb27a 100644 --- a/json_serializable/lib/src/encoder_helper.dart +++ b/json_serializable/lib/src/encoder_helper.dart @@ -42,12 +42,8 @@ abstract class EncodeHelper implements HelperCore { final access = _fieldAccess(field); final value = '${safeNameAccess(field)}: ${_serializeField(field, access)}'; - return ' $value'; - }), ',\n'); - - if (fields.isNotEmpty) { - buffer.write('\n '); - } + return ' $value,\n'; + })); buffer.writeln('};'); } diff --git a/json_serializable/test/custom_configuration_test.dart b/json_serializable/test/custom_configuration_test.dart index 19defbdef..220d1cca4 100644 --- a/json_serializable/test/custom_configuration_test.dart +++ b/json_serializable/test/custom_configuration_test.dart @@ -130,7 +130,7 @@ Map _$TrivialNestedNullableToJson( TrivialNestedNullable instance) => { 'child': instance.child?.toJson(), - 'otherField': instance.otherField + 'otherField': instance.otherField, }; '''; @@ -145,7 +145,7 @@ Map _$TrivialNestedNonNullableToJson( TrivialNestedNonNullable instance) => { 'child': instance.child.toJson(), - 'otherField': instance.otherField + 'otherField': instance.otherField, }; '''; diff --git a/json_serializable/test/generic_files/generic_class.g.dart b/json_serializable/test/generic_files/generic_class.g.dart index ff93fc0cd..afa8c824d 100644 --- a/json_serializable/test/generic_files/generic_class.g.dart +++ b/json_serializable/test/generic_files/generic_class.g.dart @@ -28,7 +28,7 @@ Map _$GenericClassToJson( 'fieldDynamic': GenericClass._dataToJson(instance.fieldDynamic), 'fieldInt': GenericClass._dataToJson(instance.fieldInt), 'fieldT': GenericClass._dataToJson(instance.fieldT), - 'fieldS': GenericClass._dataToJson(instance.fieldS) + 'fieldS': GenericClass._dataToJson(instance.fieldS), }; GenericClassWithConverter @@ -59,5 +59,5 @@ Map _$GenericClassWithConverterToJson( 'duration': const _DurationMillisecondConverter().toJson(instance.duration), 'listDuration': const _DurationListMillisecondConverter() - .toJson(instance.listDuration) + .toJson(instance.listDuration), }; diff --git a/json_serializable/test/integration/json_test_example.g.dart b/json_serializable/test/integration/json_test_example.g.dart index 4677d022e..17a43a9a0 100644 --- a/json_serializable/test/integration/json_test_example.g.dart +++ b/json_serializable/test/integration/json_test_example.g.dart @@ -7,12 +7,15 @@ part of 'json_test_example.dart'; // ************************************************************************** Person _$PersonFromJson(Map json) { - return Person(json['firstName'] as String, json['lastName'] as String, - _$enumDecodeNullable(_$CategoryEnumMap, json[r'$house']), - middleName: json['middleName'] as String, - dateOfBirth: json['dateOfBirth'] == null - ? null - : DateTime.parse(json['dateOfBirth'] as String)) + return Person( + json['firstName'] as String, + json['lastName'] as String, + _$enumDecodeNullable(_$CategoryEnumMap, json[r'$house']), + middleName: json['middleName'] as String, + dateOfBirth: json['dateOfBirth'] == null + ? null + : DateTime.parse(json['dateOfBirth'] as String), + ) ..order = json['order'] == null ? null : Order.fromJson(json['order'] as Map) @@ -41,7 +44,7 @@ Map _$PersonToJson(Person instance) => { 'houseMap': instance.houseMap?.map((k, e) => MapEntry(k, _$CategoryEnumMap[e])), 'categoryCounts': instance.categoryCounts - ?.map((k, e) => MapEntry(_$CategoryEnumMap[k], e)) + ?.map((k, e) => MapEntry(_$CategoryEnumMap[k], e)), }; T _$enumDecode(Map enumValues, dynamic source) { @@ -77,9 +80,10 @@ const _$CategoryEnumMap = { Order _$OrderFromJson(Map json) { $checkKeys(json, disallowNullValues: const ['count']); return Order( - _$enumDecode(_$CategoryEnumMap, json['category']), - (json['items'] as List)?.map( - (e) => e == null ? null : Item.fromJson(e as Map))) + _$enumDecode(_$CategoryEnumMap, json['category']), + (json['items'] as List)?.map( + (e) => e == null ? null : Item.fromJson(e as Map)), + ) ..count = json['count'] as int ..isRushed = json['isRushed'] as bool ..duration = json['duration'] == null @@ -125,7 +129,9 @@ const _$StatusCodeEnumMap = { }; Item _$ItemFromJson(Map json) { - return Item(json['price'] as int) + return Item( + json['price'] as int, + ) ..itemNumber = json['item-number'] as int ..saleDates = (json['saleDates'] as List) ?.map((e) => e == null ? null : DateTime.parse(e as String)) @@ -169,7 +175,7 @@ Map _$NumbersToJson(Numbers instance) => { 'doubles': instance.doubles, 'nnDoubles': instance.nnDoubles, 'duration': durationToInt(instance.duration), - 'date': dateTimeToEpochUs(instance.date) + 'date': dateTimeToEpochUs(instance.date), }; MapKeyVariety _$MapKeyVarietyFromJson(Map json) { @@ -194,5 +200,5 @@ Map _$MapKeyVarietyToJson(MapKeyVariety instance) => 'uriIntMap': instance.uriIntMap?.map((k, e) => MapEntry(k.toString(), e)), 'dateTimeIntMap': instance.dateTimeIntMap ?.map((k, e) => MapEntry(k.toIso8601String(), e)), - 'bigIntMap': instance.bigIntMap?.map((k, e) => MapEntry(k.toString(), e)) + 'bigIntMap': instance.bigIntMap?.map((k, e) => MapEntry(k.toString(), e)), }; diff --git a/json_serializable/test/integration/json_test_example.g_any_map.g.dart b/json_serializable/test/integration/json_test_example.g_any_map.g.dart index b6ce0e298..69ae256e3 100644 --- a/json_serializable/test/integration/json_test_example.g_any_map.g.dart +++ b/json_serializable/test/integration/json_test_example.g_any_map.g.dart @@ -7,12 +7,15 @@ part of 'json_test_example.g_any_map.dart'; // ************************************************************************** Person _$PersonFromJson(Map json) { - return Person(json['firstName'] as String, json['lastName'] as String, - _$enumDecodeNullable(_$CategoryEnumMap, json[r'$house']), - middleName: json['middleName'] as String, - dateOfBirth: json['dateOfBirth'] == null - ? null - : DateTime.parse(json['dateOfBirth'] as String)) + return Person( + json['firstName'] as String, + json['lastName'] as String, + _$enumDecodeNullable(_$CategoryEnumMap, json[r'$house']), + middleName: json['middleName'] as String, + dateOfBirth: json['dateOfBirth'] == null + ? null + : DateTime.parse(json['dateOfBirth'] as String), + ) ..order = json['order'] == null ? null : Order.fromJson((json['order'] as Map)?.map( @@ -47,7 +50,7 @@ Map _$PersonToJson(Person instance) => { 'houseMap': instance.houseMap?.map((k, e) => MapEntry(k, _$CategoryEnumMap[e])), 'categoryCounts': instance.categoryCounts - ?.map((k, e) => MapEntry(_$CategoryEnumMap[k], e)) + ?.map((k, e) => MapEntry(_$CategoryEnumMap[k], e)), }; T _$enumDecode(Map enumValues, dynamic source) { @@ -83,12 +86,13 @@ const _$CategoryEnumMap = { Order _$OrderFromJson(Map json) { $checkKeys(json, disallowNullValues: const ['count']); return Order( - _$enumDecode(_$CategoryEnumMap, json['category']), - (json['items'] as List)?.map((e) => e == null - ? null - : Item.fromJson((e as Map)?.map( - (k, e) => MapEntry(k as String, e), - )))) + _$enumDecode(_$CategoryEnumMap, json['category']), + (json['items'] as List)?.map((e) => e == null + ? null + : Item.fromJson((e as Map)?.map( + (k, e) => MapEntry(k as String, e), + ))), + ) ..count = json['count'] as int ..isRushed = json['isRushed'] as bool ..duration = json['duration'] == null @@ -135,7 +139,9 @@ const _$StatusCodeEnumMap = { }; Item _$ItemFromJson(Map json) { - return Item(json['price'] as int) + return Item( + json['price'] as int, + ) ..itemNumber = json['item-number'] as int ..saleDates = (json['saleDates'] as List) ?.map((e) => e == null ? null : DateTime.parse(e as String)) @@ -179,7 +185,7 @@ Map _$NumbersToJson(Numbers instance) => { 'doubles': instance.doubles, 'nnDoubles': instance.nnDoubles, 'duration': durationToInt(instance.duration), - 'date': dateTimeToEpochUs(instance.date) + 'date': dateTimeToEpochUs(instance.date), }; MapKeyVariety _$MapKeyVarietyFromJson(Map json) { @@ -204,5 +210,5 @@ Map _$MapKeyVarietyToJson(MapKeyVariety instance) => 'uriIntMap': instance.uriIntMap?.map((k, e) => MapEntry(k.toString(), e)), 'dateTimeIntMap': instance.dateTimeIntMap ?.map((k, e) => MapEntry(k.toIso8601String(), e)), - 'bigIntMap': instance.bigIntMap?.map((k, e) => MapEntry(k.toString(), e)) + 'bigIntMap': instance.bigIntMap?.map((k, e) => MapEntry(k.toString(), e)), }; diff --git a/json_serializable/test/integration/json_test_example.g_non_nullable.g.dart b/json_serializable/test/integration/json_test_example.g_non_nullable.g.dart index 3ea80cb38..8ac55bff8 100644 --- a/json_serializable/test/integration/json_test_example.g_non_nullable.g.dart +++ b/json_serializable/test/integration/json_test_example.g_non_nullable.g.dart @@ -7,10 +7,13 @@ part of 'json_test_example.g_non_nullable.dart'; // ************************************************************************** Person _$PersonFromJson(Map json) { - return Person(json['firstName'] as String, json['lastName'] as String, - _$enumDecode(_$CategoryEnumMap, json[r'$house']), - middleName: json['middleName'] as String, - dateOfBirth: DateTime.parse(json['dateOfBirth'] as String)) + return Person( + json['firstName'] as String, + json['lastName'] as String, + _$enumDecode(_$CategoryEnumMap, json[r'$house']), + middleName: json['middleName'] as String, + dateOfBirth: DateTime.parse(json['dateOfBirth'] as String), + ) ..order = Order.fromJson(json['order'] as Map) ..customOrders = MyList.fromJson((json['customOrders'] as List) .map((e) => Order.fromJson(e as Map)) @@ -34,7 +37,7 @@ Map _$PersonToJson(Person instance) => { 'houseMap': instance.houseMap.map((k, e) => MapEntry(k, _$CategoryEnumMap[e])), 'categoryCounts': instance.categoryCounts - .map((k, e) => MapEntry(_$CategoryEnumMap[k], e)) + .map((k, e) => MapEntry(_$CategoryEnumMap[k], e)), }; T _$enumDecode(Map enumValues, dynamic source) { @@ -63,9 +66,10 @@ const _$CategoryEnumMap = { Order _$OrderFromJson(Map json) { $checkKeys(json, disallowNullValues: const ['count']); return Order( - _$enumDecode(_$CategoryEnumMap, json['category']), - (json['items'] as List) - .map((e) => Item.fromJson(e as Map))) + _$enumDecode(_$CategoryEnumMap, json['category']), + (json['items'] as List) + .map((e) => Item.fromJson(e as Map)), + ) ..count = json['count'] as int ..isRushed = json['isRushed'] as bool ..duration = Duration(microseconds: json['duration'] as int) @@ -88,7 +92,7 @@ Map _$OrderToJson(Order instance) => { 'platform': instance.platform, 'altPlatforms': instance.altPlatforms, 'homepage': instance.homepage.toString(), - 'status_code': _$StatusCodeEnumMap[instance.statusCode] + 'status_code': _$StatusCodeEnumMap[instance.statusCode], }; T _$enumDecodeNullable(Map enumValues, dynamic source) { @@ -104,7 +108,9 @@ const _$StatusCodeEnumMap = { }; Item _$ItemFromJson(Map json) { - return Item(json['price'] as int) + return Item( + json['price'] as int, + ) ..itemNumber = json['item-number'] as int ..saleDates = (json['saleDates'] as List) .map((e) => DateTime.parse(e as String)) @@ -116,7 +122,7 @@ Map _$ItemToJson(Item instance) => { 'price': instance.price, 'item-number': instance.itemNumber, 'saleDates': instance.saleDates.map((e) => e.toIso8601String()).toList(), - 'rates': instance.rates + 'rates': instance.rates, }; Numbers _$NumbersFromJson(Map json) { @@ -137,7 +143,7 @@ Map _$NumbersToJson(Numbers instance) => { 'doubles': instance.doubles, 'nnDoubles': instance.nnDoubles, 'duration': durationToInt(instance.duration), - 'date': dateTimeToEpochUs(instance.date) + 'date': dateTimeToEpochUs(instance.date), }; MapKeyVariety _$MapKeyVarietyFromJson(Map json) { @@ -162,5 +168,5 @@ Map _$MapKeyVarietyToJson(MapKeyVariety instance) => 'uriIntMap': instance.uriIntMap.map((k, e) => MapEntry(k.toString(), e)), 'dateTimeIntMap': instance.dateTimeIntMap .map((k, e) => MapEntry(k.toIso8601String(), e)), - 'bigIntMap': instance.bigIntMap.map((k, e) => MapEntry(k.toString(), e)) + 'bigIntMap': instance.bigIntMap.map((k, e) => MapEntry(k.toString(), e)), }; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g.dart index ec0723c72..a6f1555ca 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g.dart @@ -8,13 +8,14 @@ part of 'kitchen_sink.dart'; KitchenSink _$KitchenSinkFromJson(Map json) { return KitchenSink( - ctorValidatedNo42: json['no-42'] as int, - iterable: json['iterable'] as List, - dynamicIterable: json['dynamicIterable'] as List, - objectIterable: json['objectIterable'] as List, - intIterable: (json['intIterable'] as List)?.map((e) => e as int), - dateTimeIterable: (json['datetime-iterable'] as List) - ?.map((e) => e == null ? null : DateTime.parse(e as String))) + ctorValidatedNo42: json['no-42'] as int, + iterable: json['iterable'] as List, + dynamicIterable: json['dynamicIterable'] as List, + objectIterable: json['objectIterable'] as List, + intIterable: (json['intIterable'] as List)?.map((e) => e as int), + dateTimeIterable: (json['datetime-iterable'] as List) + ?.map((e) => e == null ? null : DateTime.parse(e as String)), + ) ..dateTime = json['dateTime'] == null ? null : DateTime.parse(json['dateTime'] as String) @@ -120,7 +121,7 @@ Map _$KitchenSinkToJson(KitchenSink instance) => r'$string': instance.string, 'simpleObject': instance.simpleObject, 'strictKeysObject': instance.strictKeysObject, - 'validatedPropertyNo42': instance.validatedPropertyNo42 + 'validatedPropertyNo42': instance.validatedPropertyNo42, }; JsonConverterTestClass _$JsonConverterTestClassFromJson( @@ -158,7 +159,7 @@ Map _$JsonConverterTestClassToJson( 'numberSillySet': instance.numberSillySet ?.map(TrivialNumberConverter.instance.toJson) ?.toList(), - 'dateTime': const EpochDateTimeConverter().toJson(instance.dateTime) + 'dateTime': const EpochDateTimeConverter().toJson(instance.dateTime), }; JsonConverterGeneric _$JsonConverterGenericFromJson( @@ -182,5 +183,5 @@ Map _$JsonConverterGenericToJson( 'itemList': instance.itemList?.map(GenericConverter().toJson)?.toList(), 'itemMap': instance.itemMap - ?.map((k, e) => MapEntry(k, GenericConverter().toJson(e))) + ?.map((k, e) => MapEntry(k, GenericConverter().toJson(e))), }; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart index 37bdb00e9..f57bdf7c6 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart @@ -8,13 +8,14 @@ part of 'kitchen_sink.g_any_map.dart'; KitchenSink _$KitchenSinkFromJson(Map json) { return KitchenSink( - ctorValidatedNo42: json['no-42'] as int, - iterable: json['iterable'] as List, - dynamicIterable: json['dynamicIterable'] as List, - objectIterable: json['objectIterable'] as List, - intIterable: (json['intIterable'] as List)?.map((e) => e as int), - dateTimeIterable: (json['datetime-iterable'] as List) - ?.map((e) => e == null ? null : DateTime.parse(e as String))) + ctorValidatedNo42: json['no-42'] as int, + iterable: json['iterable'] as List, + dynamicIterable: json['dynamicIterable'] as List, + objectIterable: json['objectIterable'] as List, + intIterable: (json['intIterable'] as List)?.map((e) => e as int), + dateTimeIterable: (json['datetime-iterable'] as List) + ?.map((e) => e == null ? null : DateTime.parse(e as String)), + ) ..dateTime = json['dateTime'] == null ? null : DateTime.parse(json['dateTime'] as String) @@ -118,7 +119,7 @@ Map _$KitchenSinkToJson(KitchenSink instance) => r'$string': instance.string, 'simpleObject': instance.simpleObject, 'strictKeysObject': instance.strictKeysObject, - 'validatedPropertyNo42': instance.validatedPropertyNo42 + 'validatedPropertyNo42': instance.validatedPropertyNo42, }; JsonConverterTestClass _$JsonConverterTestClassFromJson(Map json) { @@ -155,7 +156,7 @@ Map _$JsonConverterTestClassToJson( 'numberSillySet': instance.numberSillySet ?.map(TrivialNumberConverter.instance.toJson) ?.toList(), - 'dateTime': const EpochDateTimeConverter().toJson(instance.dateTime) + 'dateTime': const EpochDateTimeConverter().toJson(instance.dateTime), }; JsonConverterGeneric _$JsonConverterGenericFromJson( @@ -179,5 +180,5 @@ Map _$JsonConverterGenericToJson( 'itemList': instance.itemList?.map(GenericConverter().toJson)?.toList(), 'itemMap': instance.itemMap - ?.map((k, e) => MapEntry(k, GenericConverter().toJson(e))) + ?.map((k, e) => MapEntry(k, GenericConverter().toJson(e))), }; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked__non_nullable.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked__non_nullable.g.dart index 4edd71ca4..ec4f758f2 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked__non_nullable.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked__non_nullable.g.dart @@ -9,16 +9,16 @@ part of 'kitchen_sink.g_any_map__checked__non_nullable.dart'; KitchenSink _$KitchenSinkFromJson(Map json) { return $checkedNew('KitchenSink', json, () { final val = KitchenSink( - ctorValidatedNo42: $checkedConvert(json, 'no-42', (v) => v as int), - iterable: $checkedConvert(json, 'iterable', (v) => v as List), - dynamicIterable: - $checkedConvert(json, 'dynamicIterable', (v) => v as List), - objectIterable: - $checkedConvert(json, 'objectIterable', (v) => v as List), - intIterable: $checkedConvert( - json, 'intIterable', (v) => (v as List).map((e) => e as int)), - dateTimeIterable: $checkedConvert(json, 'datetime-iterable', - (v) => (v as List).map((e) => DateTime.parse(e as String)))); + ctorValidatedNo42: $checkedConvert(json, 'no-42', (v) => v as int), + iterable: $checkedConvert(json, 'iterable', (v) => v as List), + dynamicIterable: + $checkedConvert(json, 'dynamicIterable', (v) => v as List), + objectIterable: $checkedConvert(json, 'objectIterable', (v) => v as List), + intIterable: $checkedConvert( + json, 'intIterable', (v) => (v as List).map((e) => e as int)), + dateTimeIterable: $checkedConvert(json, 'datetime-iterable', + (v) => (v as List).map((e) => DateTime.parse(e as String))), + ); $checkedConvert( json, 'dateTime', (v) => val.dateTime = DateTime.parse(v as String)); $checkedConvert( @@ -134,7 +134,7 @@ Map _$KitchenSinkToJson(KitchenSink instance) => r'$string': instance.string, 'simpleObject': instance.simpleObject, 'strictKeysObject': instance.strictKeysObject, - 'validatedPropertyNo42': instance.validatedPropertyNo42 + 'validatedPropertyNo42': instance.validatedPropertyNo42, }; JsonConverterTestClass _$JsonConverterTestClassFromJson(Map json) { @@ -194,7 +194,7 @@ Map _$JsonConverterTestClassToJson( 'numberSillySet': instance.numberSillySet .map(TrivialNumberConverter.instance.toJson) .toList(), - 'dateTime': const EpochDateTimeConverter().toJson(instance.dateTime) + 'dateTime': const EpochDateTimeConverter().toJson(instance.dateTime), }; JsonConverterGeneric _$JsonConverterGenericFromJson( @@ -230,5 +230,5 @@ Map _$JsonConverterGenericToJson( 'item': GenericConverter().toJson(instance.item), 'itemList': instance.itemList.map(GenericConverter().toJson).toList(), 'itemMap': instance.itemMap - .map((k, e) => MapEntry(k, GenericConverter().toJson(e))) + .map((k, e) => MapEntry(k, GenericConverter().toJson(e))), }; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable.g.dart index 3329d68dd..e06c0f1be 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable.g.dart @@ -8,13 +8,14 @@ part of 'kitchen_sink.g_any_map__non_nullable.dart'; KitchenSink _$KitchenSinkFromJson(Map json) { return KitchenSink( - ctorValidatedNo42: json['no-42'] as int, - iterable: json['iterable'] as List, - dynamicIterable: json['dynamicIterable'] as List, - objectIterable: json['objectIterable'] as List, - intIterable: (json['intIterable'] as List).map((e) => e as int), - dateTimeIterable: (json['datetime-iterable'] as List) - .map((e) => DateTime.parse(e as String))) + ctorValidatedNo42: json['no-42'] as int, + iterable: json['iterable'] as List, + dynamicIterable: json['dynamicIterable'] as List, + objectIterable: json['objectIterable'] as List, + intIterable: (json['intIterable'] as List).map((e) => e as int), + dateTimeIterable: (json['datetime-iterable'] as List) + .map((e) => DateTime.parse(e as String)), + ) ..dateTime = DateTime.parse(json['dateTime'] as String) ..bigInt = BigInt.parse(json['bigInt'] as String) ..set = (json['set'] as List).toSet() @@ -103,7 +104,7 @@ Map _$KitchenSinkToJson(KitchenSink instance) => r'$string': instance.string, 'simpleObject': instance.simpleObject, 'strictKeysObject': instance.strictKeysObject, - 'validatedPropertyNo42': instance.validatedPropertyNo42 + 'validatedPropertyNo42': instance.validatedPropertyNo42, }; JsonConverterTestClass _$JsonConverterTestClassFromJson(Map json) { @@ -140,7 +141,7 @@ Map _$JsonConverterTestClassToJson( 'numberSillySet': instance.numberSillySet .map(TrivialNumberConverter.instance.toJson) .toList(), - 'dateTime': const EpochDateTimeConverter().toJson(instance.dateTime) + 'dateTime': const EpochDateTimeConverter().toJson(instance.dateTime), }; JsonConverterGeneric _$JsonConverterGenericFromJson( @@ -163,5 +164,5 @@ Map _$JsonConverterGenericToJson( 'item': GenericConverter().toJson(instance.item), 'itemList': instance.itemList.map(GenericConverter().toJson).toList(), 'itemMap': instance.itemMap - .map((k, e) => MapEntry(k, GenericConverter().toJson(e))) + .map((k, e) => MapEntry(k, GenericConverter().toJson(e))), }; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart index d8be027cc..52c5be511 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart @@ -8,13 +8,14 @@ part of 'kitchen_sink.g_exclude_null.dart'; KitchenSink _$KitchenSinkFromJson(Map json) { return KitchenSink( - ctorValidatedNo42: json['no-42'] as int, - iterable: json['iterable'] as List, - dynamicIterable: json['dynamicIterable'] as List, - objectIterable: json['objectIterable'] as List, - intIterable: (json['intIterable'] as List)?.map((e) => e as int), - dateTimeIterable: (json['datetime-iterable'] as List) - ?.map((e) => e == null ? null : DateTime.parse(e as String))) + ctorValidatedNo42: json['no-42'] as int, + iterable: json['iterable'] as List, + dynamicIterable: json['dynamicIterable'] as List, + objectIterable: json['objectIterable'] as List, + intIterable: (json['intIterable'] as List)?.map((e) => e as int), + dateTimeIterable: (json['datetime-iterable'] as List) + ?.map((e) => e == null ? null : DateTime.parse(e as String)), + ) ..dateTime = json['dateTime'] == null ? null : DateTime.parse(json['dateTime'] as String) diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__non_nullable.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__non_nullable.g.dart index 40889434d..91ba7b1e9 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__non_nullable.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__non_nullable.g.dart @@ -8,13 +8,14 @@ part of 'kitchen_sink.g_exclude_null__non_nullable.dart'; KitchenSink _$KitchenSinkFromJson(Map json) { return KitchenSink( - ctorValidatedNo42: json['no-42'] as int, - iterable: json['iterable'] as List, - dynamicIterable: json['dynamicIterable'] as List, - objectIterable: json['objectIterable'] as List, - intIterable: (json['intIterable'] as List).map((e) => e as int), - dateTimeIterable: (json['datetime-iterable'] as List) - .map((e) => DateTime.parse(e as String))) + ctorValidatedNo42: json['no-42'] as int, + iterable: json['iterable'] as List, + dynamicIterable: json['dynamicIterable'] as List, + objectIterable: json['objectIterable'] as List, + intIterable: (json['intIterable'] as List).map((e) => e as int), + dateTimeIterable: (json['datetime-iterable'] as List) + .map((e) => DateTime.parse(e as String)), + ) ..dateTime = DateTime.parse(json['dateTime'] as String) ..bigInt = BigInt.parse(json['bigInt'] as String) ..set = (json['set'] as List).toSet() @@ -105,7 +106,7 @@ Map _$KitchenSinkToJson(KitchenSink instance) => r'$string': instance.string, 'simpleObject': instance.simpleObject, 'strictKeysObject': instance.strictKeysObject, - 'validatedPropertyNo42': instance.validatedPropertyNo42 + 'validatedPropertyNo42': instance.validatedPropertyNo42, }; JsonConverterTestClass _$JsonConverterTestClassFromJson( diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart index fbfbcbef1..353b5c35d 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart @@ -8,13 +8,14 @@ part of 'kitchen_sink.g_explicit_to_json.dart'; KitchenSink _$KitchenSinkFromJson(Map json) { return KitchenSink( - ctorValidatedNo42: json['no-42'] as int, - iterable: json['iterable'] as List, - dynamicIterable: json['dynamicIterable'] as List, - objectIterable: json['objectIterable'] as List, - intIterable: (json['intIterable'] as List)?.map((e) => e as int), - dateTimeIterable: (json['datetime-iterable'] as List) - ?.map((e) => e == null ? null : DateTime.parse(e as String))) + ctorValidatedNo42: json['no-42'] as int, + iterable: json['iterable'] as List, + dynamicIterable: json['dynamicIterable'] as List, + objectIterable: json['objectIterable'] as List, + intIterable: (json['intIterable'] as List)?.map((e) => e as int), + dateTimeIterable: (json['datetime-iterable'] as List) + ?.map((e) => e == null ? null : DateTime.parse(e as String)), + ) ..dateTime = json['dateTime'] == null ? null : DateTime.parse(json['dateTime'] as String) @@ -120,7 +121,7 @@ Map _$KitchenSinkToJson(KitchenSink instance) => r'$string': instance.string, 'simpleObject': instance.simpleObject?.toJson(), 'strictKeysObject': instance.strictKeysObject?.toJson(), - 'validatedPropertyNo42': instance.validatedPropertyNo42 + 'validatedPropertyNo42': instance.validatedPropertyNo42, }; JsonConverterTestClass _$JsonConverterTestClassFromJson( @@ -158,7 +159,7 @@ Map _$JsonConverterTestClassToJson( 'numberSillySet': instance.numberSillySet ?.map(TrivialNumberConverter.instance.toJson) ?.toList(), - 'dateTime': const EpochDateTimeConverter().toJson(instance.dateTime) + 'dateTime': const EpochDateTimeConverter().toJson(instance.dateTime), }; JsonConverterGeneric _$JsonConverterGenericFromJson( @@ -182,5 +183,5 @@ Map _$JsonConverterGenericToJson( 'itemList': instance.itemList?.map(GenericConverter().toJson)?.toList(), 'itemMap': instance.itemMap - ?.map((k, e) => MapEntry(k, GenericConverter().toJson(e))) + ?.map((k, e) => MapEntry(k, GenericConverter().toJson(e))), }; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_non_nullable.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_non_nullable.g.dart index dc26d4699..2c85c5a13 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_non_nullable.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_non_nullable.g.dart @@ -8,13 +8,14 @@ part of 'kitchen_sink.g_non_nullable.dart'; KitchenSink _$KitchenSinkFromJson(Map json) { return KitchenSink( - ctorValidatedNo42: json['no-42'] as int, - iterable: json['iterable'] as List, - dynamicIterable: json['dynamicIterable'] as List, - objectIterable: json['objectIterable'] as List, - intIterable: (json['intIterable'] as List).map((e) => e as int), - dateTimeIterable: (json['datetime-iterable'] as List) - .map((e) => DateTime.parse(e as String))) + ctorValidatedNo42: json['no-42'] as int, + iterable: json['iterable'] as List, + dynamicIterable: json['dynamicIterable'] as List, + objectIterable: json['objectIterable'] as List, + intIterable: (json['intIterable'] as List).map((e) => e as int), + dateTimeIterable: (json['datetime-iterable'] as List) + .map((e) => DateTime.parse(e as String)), + ) ..dateTime = DateTime.parse(json['dateTime'] as String) ..bigInt = BigInt.parse(json['bigInt'] as String) ..set = (json['set'] as List).toSet() @@ -105,7 +106,7 @@ Map _$KitchenSinkToJson(KitchenSink instance) => r'$string': instance.string, 'simpleObject': instance.simpleObject, 'strictKeysObject': instance.strictKeysObject, - 'validatedPropertyNo42': instance.validatedPropertyNo42 + 'validatedPropertyNo42': instance.validatedPropertyNo42, }; JsonConverterTestClass _$JsonConverterTestClassFromJson( @@ -143,7 +144,7 @@ Map _$JsonConverterTestClassToJson( 'numberSillySet': instance.numberSillySet .map(TrivialNumberConverter.instance.toJson) .toList(), - 'dateTime': const EpochDateTimeConverter().toJson(instance.dateTime) + 'dateTime': const EpochDateTimeConverter().toJson(instance.dateTime), }; JsonConverterGeneric _$JsonConverterGenericFromJson( @@ -166,5 +167,5 @@ Map _$JsonConverterGenericToJson( 'item': GenericConverter().toJson(instance.item), 'itemList': instance.itemList.map(GenericConverter().toJson).toList(), 'itemMap': instance.itemMap - .map((k, e) => MapEntry(k, GenericConverter().toJson(e))) + .map((k, e) => MapEntry(k, GenericConverter().toJson(e))), }; diff --git a/json_serializable/test/kitchen_sink/simple_object.g.dart b/json_serializable/test/kitchen_sink/simple_object.g.dart index 55136e42b..42d584b69 100644 --- a/json_serializable/test/kitchen_sink/simple_object.g.dart +++ b/json_serializable/test/kitchen_sink/simple_object.g.dart @@ -7,8 +7,12 @@ part of 'simple_object.dart'; // ************************************************************************** SimpleObject _$SimpleObjectFromJson(Map json) { - return SimpleObject(json['value'] as int); + return SimpleObject( + json['value'] as int, + ); } Map _$SimpleObjectToJson(SimpleObject instance) => - {'value': instance.value}; + { + 'value': instance.value, + }; diff --git a/json_serializable/test/kitchen_sink/strict_keys_object.g.dart b/json_serializable/test/kitchen_sink/strict_keys_object.g.dart index a41271690..dfdda8eaa 100644 --- a/json_serializable/test/kitchen_sink/strict_keys_object.g.dart +++ b/json_serializable/test/kitchen_sink/strict_keys_object.g.dart @@ -10,11 +10,14 @@ StrictKeysObject _$StrictKeysObjectFromJson(Map json) { $checkKeys(json, allowedKeys: const ['value', 'custom_field'], requiredKeys: const ['value', 'custom_field']); - return StrictKeysObject(json['value'] as int, json['custom_field'] as String); + return StrictKeysObject( + json['value'] as int, + json['custom_field'] as String, + ); } Map _$StrictKeysObjectToJson(StrictKeysObject instance) => { 'value': instance.value, - 'custom_field': instance.customField + 'custom_field': instance.customField, }; diff --git a/json_serializable/test/src/_json_serializable_test_input.dart b/json_serializable/test/src/_json_serializable_test_input.dart index 62b7da242..ad7c76cc6 100644 --- a/json_serializable/test/src/_json_serializable_test_input.dart +++ b/json_serializable/test/src/_json_serializable_test_input.dart @@ -59,8 +59,7 @@ class OnlyStaticMembers { static int get understand => 42; } -@ShouldGenerate( - r''' +@ShouldGenerate(r''' GeneralTestClass1 _$GeneralTestClass1FromJson(Map json) { return GeneralTestClass1() ..firstName = json['firstName'] as String @@ -82,10 +81,9 @@ Map _$GeneralTestClass1ToJson(GeneralTestClass1 instance) => 'dateOfBirth': instance.dateOfBirth?.toIso8601String(), 'dynamicType': instance.dynamicType, 'varType': instance.varType, - 'listOfInts': instance.listOfInts + 'listOfInts': instance.listOfInts, }; -''', -) +''') @JsonSerializable() class GeneralTestClass1 { String firstName, lastName; @@ -99,14 +97,15 @@ class GeneralTestClass1 { List listOfInts; } -@ShouldGenerate( - r''' +@ShouldGenerate(r''' GeneralTestClass2 _$GeneralTestClass2FromJson(Map json) { - return GeneralTestClass2(json['height'] as int, json['firstName'] as String, - json['lastName'] as String) - ..dateOfBirth = json['dateOfBirth'] == null - ? null - : DateTime.parse(json['dateOfBirth'] as String); + return GeneralTestClass2( + json['height'] as int, + json['firstName'] as String, + json['lastName'] as String, + )..dateOfBirth = json['dateOfBirth'] == null + ? null + : DateTime.parse(json['dateOfBirth'] as String); } Map _$GeneralTestClass2ToJson(GeneralTestClass2 instance) => @@ -114,10 +113,9 @@ Map _$GeneralTestClass2ToJson(GeneralTestClass2 instance) => 'firstName': instance.firstName, 'lastName': instance.lastName, 'height': instance.height, - 'dateOfBirth': instance.dateOfBirth?.toIso8601String() + 'dateOfBirth': instance.dateOfBirth?.toIso8601String(), }; -''', -) +''') @JsonSerializable() class GeneralTestClass2 { final String firstName, lastName; @@ -130,17 +128,18 @@ class GeneralTestClass2 { firstName = firstName; } -@ShouldGenerate( - r''' +@ShouldGenerate(r''' FinalFields _$FinalFieldsFromJson(Map json) { - return FinalFields(json['a'] as int); + return FinalFields( + json['a'] as int, + ); } Map _$FinalFieldsToJson(FinalFields instance) => - {'a': instance.a}; -''', - configurations: ['default'], -) + { + 'a': instance.a, + }; +''') @JsonSerializable() class FinalFields { final int a; @@ -170,17 +169,18 @@ class FinalFieldsNotSetInCtor { FinalFieldsNotSetInCtor(); } -@ShouldGenerate( - r''' +@ShouldGenerate(r''' SetSupport _$SetSupportFromJson(Map json) { - return SetSupport((json['values'] as List)?.map((e) => e as int)?.toSet()); + return SetSupport( + (json['values'] as List)?.map((e) => e as int)?.toSet(), + ); } Map _$SetSupportToJson(SetSupport instance) => - {'values': instance.values?.toList()}; -''', - configurations: ['default'], -) + { + 'values': instance.values?.toList(), + }; +''') @JsonSerializable() class SetSupport { final Set values; @@ -297,16 +297,13 @@ class DupeKeys { String str; } -@ShouldGenerate( - r''' +@ShouldGenerate(r''' Map _$IgnoredFieldClassToJson(IgnoredFieldClass instance) => { 'ignoredFalseField': instance.ignoredFalseField, - 'ignoredNullField': instance.ignoredNullField + 'ignoredNullField': instance.ignoredNullField, }; -''', - configurations: ['default'], -) +''') @JsonSerializable(createFactory: false) class IgnoredFieldClass { @JsonKey(ignore: true) @@ -443,8 +440,7 @@ mixin _PropInMixinI448RegressionMixin { int nullable; } -@ShouldGenerate( - r''' +@ShouldGenerate(r''' PropInMixinI448Regression _$PropInMixinI448RegressionFromJson( Map json) { return PropInMixinI448Regression() @@ -456,11 +452,9 @@ Map _$PropInMixinI448RegressionToJson( PropInMixinI448Regression instance) => { 'nullable': instance.nullable, - 'notNullable': instance.notNullable + 'notNullable': instance.notNullable, }; -''', - configurations: ['default'], -) +''') @JsonSerializable() class PropInMixinI448Regression with _PropInMixinI448RegressionMixin { @JsonKey(nullable: false) diff --git a/json_serializable/test/src/checked_test_input.dart b/json_serializable/test/src/checked_test_input.dart index f8a7d3c6e..a7e6e151a 100644 --- a/json_serializable/test/src/checked_test_input.dart +++ b/json_serializable/test/src/checked_test_input.dart @@ -8,8 +8,10 @@ WithANonCtorGetterChecked _$WithANonCtorGetterCheckedFromJson( allowedKeys: const ['items'], requiredKeys: const ['items'], disallowNullValues: const ['items']); - final val = WithANonCtorGetterChecked($checkedConvert( - json, 'items', (v) => (v as List)?.map((e) => e as String)?.toList())); + final val = WithANonCtorGetterChecked( + $checkedConvert( + json, 'items', (v) => (v as List)?.map((e) => e as String)?.toList()), + ); return val; }); } @@ -35,7 +37,8 @@ WithANonCtorGetter _$WithANonCtorGetterFromJson(Map json) { requiredKeys: const ['items'], disallowNullValues: const ['items']); return WithANonCtorGetter( - (json['items'] as List)?.map((e) => e as String)?.toList()); + (json['items'] as List)?.map((e) => e as String)?.toList(), + ); } ''') @JsonSerializable(disallowUnrecognizedKeys: true, createToJson: false) diff --git a/json_serializable/test/src/field_namer_input.dart b/json_serializable/test/src/field_namer_input.dart index 06039ec89..f8ec3c66e 100644 --- a/json_serializable/test/src/field_namer_input.dart +++ b/json_serializable/test/src/field_namer_input.dart @@ -1,15 +1,12 @@ part of '_json_serializable_test_input.dart'; -@ShouldGenerate( - r''' +@ShouldGenerate(r''' Map _$FieldNamerNoneToJson(FieldNamerNone instance) => { 'theField': instance.theField, - 'NAME_OVERRIDE': instance.nameOverride + 'NAME_OVERRIDE': instance.nameOverride, }; -''', - configurations: ['default'], -) +''') @JsonSerializable(fieldRename: FieldRename.none, createFactory: false) class FieldNamerNone { String theField; @@ -18,16 +15,13 @@ class FieldNamerNone { String nameOverride; } -@ShouldGenerate( - r''' +@ShouldGenerate(r''' Map _$FieldNamerKebabToJson(FieldNamerKebab instance) => { 'the-field': instance.theField, - 'NAME_OVERRIDE': instance.nameOverride + 'NAME_OVERRIDE': instance.nameOverride, }; -''', - configurations: ['default'], -) +''') @JsonSerializable(fieldRename: FieldRename.kebab, createFactory: false) class FieldNamerKebab { String theField; @@ -36,16 +30,13 @@ class FieldNamerKebab { String nameOverride; } -@ShouldGenerate( - r''' +@ShouldGenerate(r''' Map _$FieldNamerPascalToJson(FieldNamerPascal instance) => { 'TheField': instance.theField, - 'NAME_OVERRIDE': instance.nameOverride + 'NAME_OVERRIDE': instance.nameOverride, }; -''', - configurations: ['default'], -) +''') @JsonSerializable(fieldRename: FieldRename.pascal, createFactory: false) class FieldNamerPascal { String theField; @@ -54,16 +45,13 @@ class FieldNamerPascal { String nameOverride; } -@ShouldGenerate( - r''' +@ShouldGenerate(r''' Map _$FieldNamerSnakeToJson(FieldNamerSnake instance) => { 'the_field': instance.theField, - 'NAME_OVERRIDE': instance.nameOverride + 'NAME_OVERRIDE': instance.nameOverride, }; -''', - configurations: ['default'], -) +''') @JsonSerializable(fieldRename: FieldRename.snake, createFactory: false) class FieldNamerSnake { String theField; diff --git a/json_serializable/test/src/generic_test_input.dart b/json_serializable/test/src/generic_test_input.dart index e896c72a7..3adeafea9 100644 --- a/json_serializable/test/src/generic_test_input.dart +++ b/json_serializable/test/src/generic_test_input.dart @@ -4,8 +4,7 @@ part of '_json_serializable_test_input.dart'; -@ShouldGenerate( - r''' +@ShouldGenerate(r''' GenericClass _$GenericClassFromJson( Map json) { return GenericClass() @@ -23,10 +22,9 @@ Map _$GenericClassToJson( 'fieldDynamic': _dataToJson(instance.fieldDynamic), 'fieldInt': _dataToJson(instance.fieldInt), 'fieldT': _dataToJson(instance.fieldT), - 'fieldS': _dataToJson(instance.fieldS) + 'fieldS': _dataToJson(instance.fieldS), }; -''', -) +''') @JsonSerializable() class GenericClass { @JsonKey(fromJson: _dataFromJson, toJson: _dataToJson) diff --git a/json_serializable/test/src/inheritance_test_input.dart b/json_serializable/test/src/inheritance_test_input.dart index 4dd9553ae..68be3de05 100644 --- a/json_serializable/test/src/inheritance_test_input.dart +++ b/json_serializable/test/src/inheritance_test_input.dart @@ -1,10 +1,11 @@ part of '_json_serializable_test_input.dart'; -@ShouldGenerate( - r''' +@ShouldGenerate(r''' SubType _$SubTypeFromJson(Map json) { return SubType( - json['subTypeViaCtor'] as int, json['super-final-field'] as int) + json['subTypeViaCtor'] as int, + json['super-final-field'] as int, + ) ..superReadWriteField = json['superReadWriteField'] as int ..subTypeReadWrite = json['subTypeReadWrite'] as int; } @@ -25,9 +26,7 @@ Map _$SubTypeToJson(SubType instance) { val['subTypeReadWrite'] = instance.subTypeReadWrite; return val; } -''', - configurations: ['default'], -) +''') @JsonSerializable() class SubType extends SuperType { final int subTypeViaCtor; @@ -56,8 +55,7 @@ class SuperType { superFinalField == null ? null : superFinalField ~/ other; } -@ShouldGenerate( - r''' +@ShouldGenerate(r''' Map _$SubTypeWithAnnotatedFieldOverrideExtendsToJson( SubTypeWithAnnotatedFieldOverrideExtends instance) { final val = { @@ -74,28 +72,23 @@ Map _$SubTypeWithAnnotatedFieldOverrideExtendsToJson( val['priceHalf'] = instance.priceHalf; return val; } -''', - configurations: ['default'], -) +''') @JsonSerializable(createFactory: false) class SubTypeWithAnnotatedFieldOverrideExtends extends SuperType { SubTypeWithAnnotatedFieldOverrideExtends(int superTypeViaCtor) : super(superTypeViaCtor); } -@ShouldGenerate( - r''' +@ShouldGenerate(r''' Map _$SubTypeWithAnnotatedFieldOverrideExtendsWithOverridesToJson( SubTypeWithAnnotatedFieldOverrideExtendsWithOverrides instance) => { 'priceHalf': instance.priceHalf, 'superReadWriteField': instance.superReadWriteField, - 'super-final-field': instance.superFinalField + 'super-final-field': instance.superFinalField, }; -''', - configurations: ['default'], -) +''') @JsonSerializable(createFactory: false) class SubTypeWithAnnotatedFieldOverrideExtendsWithOverrides extends SuperType { SubTypeWithAnnotatedFieldOverrideExtendsWithOverrides(int superTypeViaCtor) @@ -117,17 +110,14 @@ class SubTypeWithAnnotatedFieldOverrideExtendsWithOverrides extends SuperType { int get superFinalField => super.superFinalField; } -@ShouldGenerate( - r''' +@ShouldGenerate(r''' Map _$SubTypeWithAnnotatedFieldOverrideImplementsToJson( SubTypeWithAnnotatedFieldOverrideImplements instance) => { 'superReadWriteField': instance.superReadWriteField, - 'superFinalField': instance.superFinalField + 'superFinalField': instance.superFinalField, }; -''', - configurations: ['default'], -) +''') @JsonSerializable(createFactory: false) class SubTypeWithAnnotatedFieldOverrideImplements implements SuperType { // Note the order of fields in the output is determined by this class diff --git a/json_serializable/test/src/json_converter_test_input.dart b/json_serializable/test/src/json_converter_test_input.dart index 9363a827d..e4e1f841d 100644 --- a/json_serializable/test/src/json_converter_test_input.dart +++ b/json_serializable/test/src/json_converter_test_input.dart @@ -4,8 +4,7 @@ part of '_json_serializable_test_input.dart'; -@ShouldGenerate( - r''' +@ShouldGenerate(r''' JsonConverterNamedCtor _$JsonConverterNamedCtorFromJson( Map json) { return JsonConverterNamedCtor() @@ -25,11 +24,9 @@ Map _$JsonConverterNamedCtorToJson( 'genericValue': _GenericConverter.named().toJson(instance.genericValue), 'keyAnnotationFirst': - JsonConverterNamedCtor._toJson(instance.keyAnnotationFirst) + JsonConverterNamedCtor._toJson(instance.keyAnnotationFirst), }; -''', - configurations: ['default'], -) +''') @JsonSerializable() @_DurationMillisecondConverter.named() @_GenericConverter.named() @@ -46,8 +43,7 @@ class JsonConverterNamedCtor { static int _toJson(Duration object) => 42; } -@ShouldGenerate( - r''' +@ShouldGenerate(r''' JsonConvertOnField _$JsonConvertOnFieldFromJson( Map json) { return JsonConvertOnField() @@ -70,11 +66,9 @@ Map _$JsonConvertOnFieldToJson( .toJson(instance.annotatedWithNamedCtor), 'classAnnotatedWithField': _durationConverter.toJson(instance.classAnnotatedWithField), - 'genericValue': _GenericConverter().toJson(instance.genericValue) + 'genericValue': _GenericConverter().toJson(instance.genericValue), }; -''', - configurations: ['default'], -) +''') @JsonSerializable() @_durationConverter class JsonConvertOnField { diff --git a/json_serializable/test/src/map_key_variety_test_input.dart b/json_serializable/test/src/map_key_variety_test_input.dart index 93d92422b..41abe7029 100644 --- a/json_serializable/test/src/map_key_variety_test_input.dart +++ b/json_serializable/test/src/map_key_variety_test_input.dart @@ -1,7 +1,6 @@ part of '_json_serializable_test_input.dart'; -@ShouldGenerate( - r''' +@ShouldGenerate(r''' MapKeyVariety _$MapKeyVarietyFromJson(Map json) { return MapKeyVariety() ..intIntMap = (json['intIntMap'] as Map)?.map( @@ -11,10 +10,9 @@ MapKeyVariety _$MapKeyVarietyFromJson(Map json) { Map _$MapKeyVarietyToJson(MapKeyVariety instance) => { - 'intIntMap': instance.intIntMap?.map((k, e) => MapEntry(k.toString(), e)) + 'intIntMap': instance.intIntMap?.map((k, e) => MapEntry(k.toString(), e)), }; -''', -) +''') @JsonSerializable() class MapKeyVariety { Map intIntMap; diff --git a/json_serializable/test/src/to_from_json_test_input.dart b/json_serializable/test/src/to_from_json_test_input.dart index 576c991a3..6608bfc1e 100644 --- a/json_serializable/test/src/to_from_json_test_input.dart +++ b/json_serializable/test/src/to_from_json_test_input.dart @@ -45,7 +45,7 @@ ValidToFromFuncClassStatic _$ValidToFromFuncClassStaticFromJson( Map _$ValidToFromFuncClassStaticToJson( ValidToFromFuncClassStatic instance) => { - 'field': ValidToFromFuncClassStatic._staticFunc(instance.field) + 'field': ValidToFromFuncClassStatic._staticFunc(instance.field), }; ''', configurations: ['default'], diff --git a/json_serializable/test/src/unknown_type_test_input.dart b/json_serializable/test/src/unknown_type_test_input.dart index 106974d08..360d31685 100644 --- a/json_serializable/test/src/unknown_type_test_input.dart +++ b/json_serializable/test/src/unknown_type_test_input.dart @@ -1,17 +1,18 @@ part of '_json_serializable_test_input.dart'; -@ShouldGenerate( - r''' +@ShouldGenerate(r''' UnknownCtorParamType _$UnknownCtorParamTypeFromJson(Map json) { - return UnknownCtorParamType(json['number']); + return UnknownCtorParamType( + json['number'], + ); } Map _$UnknownCtorParamTypeToJson( UnknownCtorParamType instance) => - {'number': instance.number}; -''', - configurations: ['default'], -) + { + 'number': instance.number, + }; +''') @JsonSerializable() class UnknownCtorParamType { int number; @@ -20,39 +21,36 @@ class UnknownCtorParamType { UnknownCtorParamType(Bob number) : number = number; } -@ShouldGenerate( - r''' +@ShouldGenerate(r''' UnknownFieldType _$UnknownFieldTypeFromJson(Map json) { return UnknownFieldType()..number = json['number']; } Map _$UnknownFieldTypeToJson(UnknownFieldType instance) => - {'number': instance.number}; -''', - configurations: ['default'], -) + { + 'number': instance.number, + }; +''') @JsonSerializable() class UnknownFieldType { // ignore: undefined_class Bob number; } -@ShouldGenerate( - r''' +@ShouldGenerate(r''' Map _$UnknownFieldTypeToJsonOnlyToJson( UnknownFieldTypeToJsonOnly instance) => - {'number': instance.number}; -''', - configurations: ['default'], -) + { + 'number': instance.number, + }; +''') @JsonSerializable(createFactory: false) class UnknownFieldTypeToJsonOnly { // ignore: undefined_class Bob number; } -@ShouldGenerate( - r''' +@ShouldGenerate(r''' UnknownFieldTypeWithConvert _$UnknownFieldTypeWithConvertFromJson( Map json) { return UnknownFieldTypeWithConvert() @@ -61,10 +59,10 @@ UnknownFieldTypeWithConvert _$UnknownFieldTypeWithConvertFromJson( Map _$UnknownFieldTypeWithConvertToJson( UnknownFieldTypeWithConvert instance) => - {'number': _everythingIs42(instance.number)}; -''', - configurations: ['default'], -) + { + 'number': _everythingIs42(instance.number), + }; +''') @JsonSerializable() class UnknownFieldTypeWithConvert { @JsonKey(fromJson: _everythingIs42, toJson: _everythingIs42) From 16d21dcbda904592e129ea67d9ea85bfd38db150 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 10 Jun 2019 14:25:05 -0700 Subject: [PATCH 148/569] move LambdaResult into its own file --- json_serializable/lib/src/lambda_result.dart | 18 ++++++++++++++++++ json_serializable/lib/src/type_helper.dart | 15 --------------- .../lib/src/type_helpers/iterable_helper.dart | 1 + .../type_helpers/json_converter_helper.dart | 1 + 4 files changed, 20 insertions(+), 15 deletions(-) create mode 100644 json_serializable/lib/src/lambda_result.dart diff --git a/json_serializable/lib/src/lambda_result.dart b/json_serializable/lib/src/lambda_result.dart new file mode 100644 index 000000000..b87f433de --- /dev/null +++ b/json_serializable/lib/src/lambda_result.dart @@ -0,0 +1,18 @@ +// Copyright (c) 2019, 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. + +class LambdaResult { + final String expression; + final String lambda; + + LambdaResult(this.expression, this.lambda); + + @override + String toString() => '$lambda($expression)'; + + static String process(Object subField, String closureArg) => + (subField is LambdaResult && closureArg == subField.expression) + ? subField.lambda + : '($closureArg) => $subField'; +} diff --git a/json_serializable/lib/src/type_helper.dart b/json_serializable/lib/src/type_helper.dart index d38c1b2e3..44d79a8a9 100644 --- a/json_serializable/lib/src/type_helper.dart +++ b/json_serializable/lib/src/type_helper.dart @@ -82,21 +82,6 @@ abstract class TypeHelper { Object deserialize(DartType targetType, String expression, T context); } -class LambdaResult { - final String expression; - final String lambda; - - LambdaResult(this.expression, this.lambda); - - @override - String toString() => '$lambda($expression)'; - - static String process(Object subField, String closureArg) => - (subField is LambdaResult && closureArg == subField.expression) - ? subField.lambda - : '($closureArg) => $subField'; -} - class UnsupportedTypeError extends Error { final String expression; final DartType type; diff --git a/json_serializable/lib/src/type_helpers/iterable_helper.dart b/json_serializable/lib/src/type_helpers/iterable_helper.dart index 8ee8a68eb..e5b6f5e99 100644 --- a/json_serializable/lib/src/type_helpers/iterable_helper.dart +++ b/json_serializable/lib/src/type_helpers/iterable_helper.dart @@ -6,6 +6,7 @@ import 'package:analyzer/dart/element/type.dart'; import 'package:source_gen/source_gen.dart' show TypeChecker; import '../constants.dart'; +import '../lambda_result.dart'; import '../shared_checkers.dart'; import '../type_helper.dart'; diff --git a/json_serializable/lib/src/type_helpers/json_converter_helper.dart b/json_serializable/lib/src/type_helpers/json_converter_helper.dart index 7eb8a0b5c..436596ba2 100644 --- a/json_serializable/lib/src/type_helpers/json_converter_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_converter_helper.dart @@ -9,6 +9,7 @@ import 'package:json_annotation/json_annotation.dart'; import 'package:source_gen/source_gen.dart'; import '../json_key_utils.dart'; +import '../lambda_result.dart'; import '../shared_checkers.dart'; import '../type_helper.dart'; From b322157a3867ca682c0538559e05eaabda46e2cf Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 10 Jun 2019 14:31:15 -0700 Subject: [PATCH 149/569] Move UnsupportedTypeError to its own library --- json_serializable/lib/src/decode_helper.dart | 2 +- json_serializable/lib/src/encoder_helper.dart | 2 +- json_serializable/lib/src/helper_core.dart | 1 + json_serializable/lib/src/type_helper.dart | 8 -------- json_serializable/lib/src/type_helper_ctx.dart | 1 + .../lib/src/type_helpers/map_helper.dart | 1 + .../lib/src/unsupported_type_error.dart | 17 +++++++++++++++++ json_serializable/lib/type_helper.dart | 4 ++-- 8 files changed, 24 insertions(+), 12 deletions(-) create mode 100644 json_serializable/lib/src/unsupported_type_error.dart diff --git a/json_serializable/lib/src/decode_helper.dart b/json_serializable/lib/src/decode_helper.dart index e8a058190..c3aab5d8f 100644 --- a/json_serializable/lib/src/decode_helper.dart +++ b/json_serializable/lib/src/decode_helper.dart @@ -9,7 +9,7 @@ import 'package:source_gen/source_gen.dart'; import 'helper_core.dart'; import 'json_literal_generator.dart'; -import 'type_helper.dart'; +import 'unsupported_type_error.dart'; import 'utils.dart'; class CreateFactoryResult { diff --git a/json_serializable/lib/src/encoder_helper.dart b/json_serializable/lib/src/encoder_helper.dart index 2c4afb27a..427236be4 100644 --- a/json_serializable/lib/src/encoder_helper.dart +++ b/json_serializable/lib/src/encoder_helper.dart @@ -7,8 +7,8 @@ import 'package:json_annotation/json_annotation.dart'; import 'constants.dart'; import 'helper_core.dart'; -import 'type_helper.dart'; import 'type_helpers/json_converter_helper.dart'; +import 'unsupported_type_error.dart'; abstract class EncodeHelper implements HelperCore { String _fieldAccess(FieldElement field) => '$_toJsonParamName.${field.name}'; diff --git a/json_serializable/lib/src/helper_core.dart b/json_serializable/lib/src/helper_core.dart index b8e663bf4..59f46916c 100644 --- a/json_serializable/lib/src/helper_core.dart +++ b/json_serializable/lib/src/helper_core.dart @@ -10,6 +10,7 @@ import 'package:source_gen/source_gen.dart'; import 'json_key_utils.dart'; import 'type_helper.dart'; import 'type_helper_ctx.dart'; +import 'unsupported_type_error.dart'; import 'utils.dart'; abstract class HelperCore { diff --git a/json_serializable/lib/src/type_helper.dart b/json_serializable/lib/src/type_helper.dart index 44d79a8a9..3589eabc0 100644 --- a/json_serializable/lib/src/type_helper.dart +++ b/json_serializable/lib/src/type_helper.dart @@ -82,14 +82,6 @@ abstract class TypeHelper { Object deserialize(DartType targetType, String expression, T context); } -class UnsupportedTypeError extends Error { - final String expression; - final DartType type; - final String reason; - - UnsupportedTypeError(this.type, this.expression, this.reason); -} - Object commonNullPrefix( bool nullable, String expression, Object unsafeExpression) => nullable diff --git a/json_serializable/lib/src/type_helper_ctx.dart b/json_serializable/lib/src/type_helper_ctx.dart index 6f6465b46..c2a64d6d5 100644 --- a/json_serializable/lib/src/type_helper_ctx.dart +++ b/json_serializable/lib/src/type_helper_ctx.dart @@ -10,6 +10,7 @@ import 'package:json_annotation/json_annotation.dart'; import 'helper_core.dart'; import 'type_helper.dart'; import 'type_helpers/convert_helper.dart'; +import 'unsupported_type_error.dart'; import 'utils.dart'; TypeHelperCtx typeHelperContext( diff --git a/json_serializable/lib/src/type_helpers/map_helper.dart b/json_serializable/lib/src/type_helpers/map_helper.dart index ceb4be596..9a0d89dbf 100644 --- a/json_serializable/lib/src/type_helpers/map_helper.dart +++ b/json_serializable/lib/src/type_helpers/map_helper.dart @@ -7,6 +7,7 @@ import 'package:analyzer/dart/element/type.dart'; import '../constants.dart'; import '../shared_checkers.dart'; import '../type_helper.dart'; +import '../unsupported_type_error.dart'; import '../utils.dart'; import 'to_from_string.dart'; diff --git a/json_serializable/lib/src/unsupported_type_error.dart b/json_serializable/lib/src/unsupported_type_error.dart new file mode 100644 index 000000000..ea80e15a6 --- /dev/null +++ b/json_serializable/lib/src/unsupported_type_error.dart @@ -0,0 +1,17 @@ +// Copyright (c) 2019, 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:analyzer/dart/element/type.dart'; + +/// Error thrown when code generation fails due to [type] being unsupported for +/// [reason]. +class UnsupportedTypeError extends Error { + final DartType type; + final String reason; + + /// Not currently accesses. Will likely be removed in a future release. + final String expression; + + UnsupportedTypeError(this.type, this.expression, this.reason); +} diff --git a/json_serializable/lib/type_helper.dart b/json_serializable/lib/type_helper.dart index 167123fd0..21b2097ae 100644 --- a/json_serializable/lib/type_helper.dart +++ b/json_serializable/lib/type_helper.dart @@ -3,8 +3,7 @@ // BSD-style license that can be found in the LICENSE file. export 'src/shared_checkers.dart' show simpleJsonTypeChecker, typeArgumentsOf; -export 'src/type_helper.dart' - show TypeHelperContext, TypeHelper, UnsupportedTypeError; +export 'src/type_helper.dart' show TypeHelperContext, TypeHelper; export 'src/type_helpers/big_int_helper.dart'; export 'src/type_helpers/convert_helper.dart'; export 'src/type_helpers/date_time_helper.dart'; @@ -15,3 +14,4 @@ export 'src/type_helpers/json_helper.dart'; export 'src/type_helpers/map_helper.dart'; export 'src/type_helpers/uri_helper.dart'; export 'src/type_helpers/value_helper.dart'; +export 'src/unsupported_type_error.dart'; From edb78edfeff09d00b0e85a776ac2270a2f11e797 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tour=C3=A9=20Holder?= Date: Thu, 27 Jun 2019 23:50:17 -0300 Subject: [PATCH 150/569] Fix typo in json_key.dart (#505) --- json_annotation/lib/src/json_key.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/json_annotation/lib/src/json_key.dart b/json_annotation/lib/src/json_key.dart index 7d468a32b..71aee1e0c 100644 --- a/json_annotation/lib/src/json_key.dart +++ b/json_annotation/lib/src/json_key.dart @@ -12,7 +12,7 @@ class JsonKey { final Object defaultValue; /// If `true`, generated code will throw a [DisallowedNullValueException] if - /// the corresponding key exits, but the value is `null`. + /// the corresponding key exists, but the value is `null`. /// /// Note: this value does not affect the behavior of a JSON map *without* the /// associated key. From 3654de80dcf18cbb3ff204ed126728fb30d38a7c Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 10 Jul 2019 15:49:44 -0700 Subject: [PATCH 151/569] enable prefer_iterable_whereType (#508) --- analysis_options.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/analysis_options.yaml b/analysis_options.yaml index b37f52617..107b442f7 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -63,6 +63,7 @@ linter: - prefer_generic_function_type_aliases - prefer_initializing_formals - prefer_interpolation_to_compose_strings + - prefer_iterable_whereType - prefer_is_empty - prefer_is_not_empty - prefer_single_quotes From 8f4ee63a7aeffa1d5480ac602e02740004e0e850 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 10 Jul 2019 16:44:40 -0700 Subject: [PATCH 152/569] fix lint (#509) --- json_serializable/test/src/_json_serializable_test_input.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/json_serializable/test/src/_json_serializable_test_input.dart b/json_serializable/test/src/_json_serializable_test_input.dart index ad7c76cc6..2acd5c2ab 100644 --- a/json_serializable/test/src/_json_serializable_test_input.dart +++ b/json_serializable/test/src/_json_serializable_test_input.dart @@ -336,7 +336,7 @@ class IgnoredFieldCtorClass { @JsonSerializable() class PrivateFieldCtorClass { // ignore: unused_field - int _privateField; + final int _privateField; PrivateFieldCtorClass(this._privateField); } From 95ddcceee94508d238890bd56f9594400bba709f Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Fri, 19 Jul 2019 20:37:06 -0700 Subject: [PATCH 153/569] support latest pkg:analyzer (#510) --- json_serializable/CHANGELOG.md | 1 + json_serializable/pubspec.yaml | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 8ac24f2be..363364d94 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -3,6 +3,7 @@ - Support `Map` keys of type `int`, `BigInt`, `DateTime`, and `Uri`. - Trailing commas are now added to generated constructor arguments and the elements in `Map` literals. +- Support `package:analyzer` `>=0.33.3 <0.38.0` ## 3.0.0 diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index b1aff4261..12235acde 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 3.1.0-dev +version: 3.1.0 author: Dart Team description: >- Automatically generate code for converting to and from JSON by annotating @@ -9,7 +9,7 @@ environment: sdk: '>=2.2.0 <3.0.0' dependencies: - analyzer: '>=0.33.3 <0.37.0' + analyzer: '>=0.33.3 <0.38.0' build: '>=0.12.6 <2.0.0' build_config: '>=0.2.6 <0.5.0' From 0608d0a21298c14b2573fa9f7a561156f0dbf4c8 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Fri, 19 Jul 2019 21:23:07 -0700 Subject: [PATCH 154/569] rebuild sources (#511) --- checked_yaml/example/example.g.dart | 10 ++++++--- example/lib/example.g.dart | 27 ++++++++++++++--------- example/lib/json_converter_example.g.dart | 22 +++++++++++------- 3 files changed, 37 insertions(+), 22 deletions(-) diff --git a/checked_yaml/example/example.g.dart b/checked_yaml/example/example.g.dart index 7c303ebd4..854bcbaf5 100644 --- a/checked_yaml/example/example.g.dart +++ b/checked_yaml/example/example.g.dart @@ -12,11 +12,15 @@ Configuration _$ConfigurationFromJson(Map json) { allowedKeys: const ['name', 'count'], requiredKeys: const ['name', 'count']); final val = Configuration( - name: $checkedConvert(json, 'name', (v) => v as String), - count: $checkedConvert(json, 'count', (v) => v as int)); + name: $checkedConvert(json, 'name', (v) => v as String), + count: $checkedConvert(json, 'count', (v) => v as int), + ); return val; }); } Map _$ConfigurationToJson(Configuration instance) => - {'name': instance.name, 'count': instance.count}; + { + 'name': instance.name, + 'count': instance.count, + }; diff --git a/example/lib/example.g.dart b/example/lib/example.g.dart index bf46ba52a..44599902e 100644 --- a/example/lib/example.g.dart +++ b/example/lib/example.g.dart @@ -7,15 +7,18 @@ part of 'example.dart'; // ************************************************************************** Person _$PersonFromJson(Map json) { - return Person(json['firstName'] as String, json['lastName'] as String, - DateTime.parse(json['date-of-birth'] as String), - middleName: json['middleName'] as String, - lastOrder: json['last-order'] == null - ? null - : DateTime.parse(json['last-order'] as String), - orders: (json['orders'] as List) - .map((e) => Order.fromJson(e as Map)) - .toList()); + return Person( + json['firstName'] as String, + json['lastName'] as String, + DateTime.parse(json['date-of-birth'] as String), + middleName: json['middleName'] as String, + lastOrder: json['last-order'] == null + ? null + : DateTime.parse(json['last-order'] as String), + orders: (json['orders'] as List) + .map((e) => Order.fromJson(e as Map)) + .toList(), + ); } Map _$PersonToJson(Person instance) { @@ -38,7 +41,9 @@ Map _$PersonToJson(Person instance) { } Order _$OrderFromJson(Map json) { - return Order(Order._dateTimeFromEpochUs(json['date'] as int)) + return Order( + Order._dateTimeFromEpochUs(json['date'] as int), + ) ..count = json['count'] as int ..itemNumber = json['itemNumber'] as int ..isRushed = json['isRushed'] as bool @@ -76,7 +81,7 @@ Item _$ItemFromJson(Map json) { Map _$ItemToJson(Item instance) => { 'count': instance.count, 'itemNumber': instance.itemNumber, - 'isRushed': instance.isRushed + 'isRushed': instance.isRushed, }; // ************************************************************************** diff --git a/example/lib/json_converter_example.g.dart b/example/lib/json_converter_example.g.dart index 5fa8fb0b0..709e2e79b 100644 --- a/example/lib/json_converter_example.g.dart +++ b/example/lib/json_converter_example.g.dart @@ -8,11 +8,11 @@ part of 'json_converter_example.dart'; GenericCollection _$GenericCollectionFromJson(Map json) { return GenericCollection( - page: json['page'] as int, - totalResults: json['total_results'] as int, - totalPages: json['total_pages'] as int, - results: - (json['results'] as List)?.map(_Converter().fromJson)?.toList()); + page: json['page'] as int, + totalResults: json['total_results'] as int, + totalPages: json['total_pages'] as int, + results: (json['results'] as List)?.map(_Converter().fromJson)?.toList(), + ); } Map _$GenericCollectionToJson( @@ -21,12 +21,18 @@ Map _$GenericCollectionToJson( 'page': instance.page, 'total_results': instance.totalResults, 'total_pages': instance.totalPages, - 'results': instance.results?.map(_Converter().toJson)?.toList() + 'results': instance.results?.map(_Converter().toJson)?.toList(), }; CustomResult _$CustomResultFromJson(Map json) { - return CustomResult(json['name'] as String, json['size'] as int); + return CustomResult( + json['name'] as String, + json['size'] as int, + ); } Map _$CustomResultToJson(CustomResult instance) => - {'name': instance.name, 'size': instance.size}; + { + 'name': instance.name, + 'size': instance.size, + }; From 5de34a43dfc59916812b8af45561be69f20c1882 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 24 Jul 2019 13:54:23 -0700 Subject: [PATCH 155/569] fix a dartlang.org url (#513) --- json_serializable/test/integration/integration_test.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/json_serializable/test/integration/integration_test.dart b/json_serializable/test/integration/integration_test.dart index b9ebb6767..c99c7664a 100644 --- a/json_serializable/test/integration/integration_test.dart +++ b/json_serializable/test/integration/integration_test.dart @@ -122,7 +122,7 @@ void main() { 'f': Platform.foo, 'null': null } - ..homepage = Uri.parse('https://dartlang.org'); + ..homepage = Uri.parse('https://dart.dev'); roundTripOrder(order); }); From afcd92734800ebb1dc22260f55c24d5310a2858d Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 29 Jul 2019 13:21:07 -0700 Subject: [PATCH 156/569] Add JsonSerializable.ignoreUnannotated (#514) Closes https://github.com/dart-lang/json_serializable/issues/399 --- json_annotation/CHANGELOG.md | 1 + .../lib/src/json_serializable.dart | 31 ++++++++++----- .../lib/src/json_serializable.g.dart | 32 ++++++++------- json_annotation/pubspec.yaml | 2 +- json_serializable/CHANGELOG.md | 5 +++ json_serializable/README.md | 39 ++++++++++--------- json_serializable/doc/doc.md | 38 +++++++++--------- json_serializable/lib/src/json_key_utils.dart | 6 ++- json_serializable/lib/src/utils.dart | 6 ++- json_serializable/pubspec.yaml | 8 +++- json_serializable/test/config_test.dart | 11 ++---- .../test/custom_configuration_test.dart | 6 +-- .../test/json_serializable_test.dart | 1 + json_serializable/test/shared_config.dart | 20 +--------- .../src/_json_serializable_test_input.dart | 20 ++++++++++ .../test/test_sources/test_sources.dart | 1 + 16 files changed, 130 insertions(+), 97 deletions(-) diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index 60df426e0..a3b18acfb 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -5,6 +5,7 @@ - **BREAKING** Removed `JsonSerializable.generateToJsonFunction`. - **BREAKING** Removed `encodeEmptyCollection` from `JsonSerializable` and `JsonKey`. +- Added `JsonSerializable.ignoreUnannotated`. ## 2.4.0 diff --git a/json_annotation/lib/src/json_serializable.dart b/json_annotation/lib/src/json_serializable.dart index 95361e114..08f74940f 100644 --- a/json_annotation/lib/src/json_serializable.dart +++ b/json_annotation/lib/src/json_serializable.dart @@ -112,6 +112,13 @@ class JsonSerializable { /// fields annotated with [JsonKey]. final FieldRename fieldRename; + /// When `true`, only fields annotated with [JsonKey] will have code + /// generated. + /// + /// It will have the same effect as if those fields had been annotated with + /// `@JsonKey(ignore: true)`. + final bool ignoreUnannotated; + /// Whether the generator should include fields with `null` values in the /// serialized output. /// @@ -141,6 +148,7 @@ class JsonSerializable { this.disallowUnrecognizedKeys, this.explicitToJson, this.fieldRename, + this.ignoreUnannotated, this.includeIfNull, this.nullable, }); @@ -158,6 +166,7 @@ class JsonSerializable { disallowUnrecognizedKeys: false, explicitToJson: false, fieldRename: FieldRename.none, + ignoreUnannotated: false, includeIfNull: true, nullable: true, ); @@ -168,16 +177,18 @@ class JsonSerializable { /// Otherwise, the returned value has the default value as defined in /// [defaults]. JsonSerializable withDefaults() => JsonSerializable( - anyMap: anyMap ?? defaults.anyMap, - checked: checked ?? defaults.checked, - createFactory: createFactory ?? defaults.createFactory, - createToJson: createToJson ?? defaults.createToJson, - disallowUnrecognizedKeys: - disallowUnrecognizedKeys ?? defaults.disallowUnrecognizedKeys, - explicitToJson: explicitToJson ?? defaults.explicitToJson, - fieldRename: fieldRename ?? defaults.fieldRename, - includeIfNull: includeIfNull ?? defaults.includeIfNull, - nullable: nullable ?? defaults.nullable); + anyMap: anyMap ?? defaults.anyMap, + checked: checked ?? defaults.checked, + createFactory: createFactory ?? defaults.createFactory, + createToJson: createToJson ?? defaults.createToJson, + disallowUnrecognizedKeys: + disallowUnrecognizedKeys ?? defaults.disallowUnrecognizedKeys, + explicitToJson: explicitToJson ?? defaults.explicitToJson, + fieldRename: fieldRename ?? defaults.fieldRename, + ignoreUnannotated: ignoreUnannotated ?? defaults.ignoreUnannotated, + includeIfNull: includeIfNull ?? defaults.includeIfNull, + nullable: nullable ?? defaults.nullable, + ); Map toJson() => _$JsonSerializableToJson(this); } diff --git a/json_annotation/lib/src/json_serializable.g.dart b/json_annotation/lib/src/json_serializable.g.dart index 795201b50..68cec418b 100644 --- a/json_annotation/lib/src/json_serializable.g.dart +++ b/json_annotation/lib/src/json_serializable.g.dart @@ -16,24 +16,26 @@ JsonSerializable _$JsonSerializableFromJson(Map json) { 'disallow_unrecognized_keys', 'explicit_to_json', 'field_rename', + 'ignore_unannotated', 'include_if_null', 'nullable', ]); final val = JsonSerializable( - anyMap: $checkedConvert(json, 'any_map', (v) => v as bool), - checked: $checkedConvert(json, 'checked', (v) => v as bool), - createFactory: - $checkedConvert(json, 'create_factory', (v) => v as bool), - createToJson: $checkedConvert(json, 'create_to_json', (v) => v as bool), - disallowUnrecognizedKeys: $checkedConvert( - json, 'disallow_unrecognized_keys', (v) => v as bool), - explicitToJson: - $checkedConvert(json, 'explicit_to_json', (v) => v as bool), - fieldRename: $checkedConvert(json, 'field_rename', - (v) => _$enumDecodeNullable(_$FieldRenameEnumMap, v)), - includeIfNull: - $checkedConvert(json, 'include_if_null', (v) => v as bool), - nullable: $checkedConvert(json, 'nullable', (v) => v as bool)); + anyMap: $checkedConvert(json, 'any_map', (v) => v as bool), + checked: $checkedConvert(json, 'checked', (v) => v as bool), + createFactory: $checkedConvert(json, 'create_factory', (v) => v as bool), + createToJson: $checkedConvert(json, 'create_to_json', (v) => v as bool), + disallowUnrecognizedKeys: + $checkedConvert(json, 'disallow_unrecognized_keys', (v) => v as bool), + explicitToJson: + $checkedConvert(json, 'explicit_to_json', (v) => v as bool), + fieldRename: $checkedConvert(json, 'field_rename', + (v) => _$enumDecodeNullable(_$FieldRenameEnumMap, v)), + ignoreUnannotated: + $checkedConvert(json, 'ignore_unannotated', (v) => v as bool), + includeIfNull: $checkedConvert(json, 'include_if_null', (v) => v as bool), + nullable: $checkedConvert(json, 'nullable', (v) => v as bool), + ); return val; }, fieldKeyMap: const { 'anyMap': 'any_map', @@ -42,6 +44,7 @@ JsonSerializable _$JsonSerializableFromJson(Map json) { 'disallowUnrecognizedKeys': 'disallow_unrecognized_keys', 'explicitToJson': 'explicit_to_json', 'fieldRename': 'field_rename', + 'ignoreUnannotated': 'ignore_unannotated', 'includeIfNull': 'include_if_null', }); } @@ -55,6 +58,7 @@ Map _$JsonSerializableToJson(JsonSerializable instance) => 'disallow_unrecognized_keys': instance.disallowUnrecognizedKeys, 'explicit_to_json': instance.explicitToJson, 'field_rename': _$FieldRenameEnumMap[instance.fieldRename], + 'ignore_unannotated': instance.ignoreUnannotated, 'include_if_null': instance.includeIfNull, 'nullable': instance.nullable, }; diff --git a/json_annotation/pubspec.yaml b/json_annotation/pubspec.yaml index 13b79e3c0..55b88c500 100644 --- a/json_annotation/pubspec.yaml +++ b/json_annotation/pubspec.yaml @@ -11,4 +11,4 @@ environment: # When changing JsonSerializable class. # dev_dependencies: # build_runner: ^1.0.0 -# json_serializable: ^2.0.0 +# json_serializable: ^3.1.0 diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 363364d94..7844d4bb9 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,8 @@ +## 3.2.0 + +- Require `package:json_annotation` `^3.0.0`. +- Added support for `@JsonSerializable(ignoreUnannotated: true)`. + ## 3.1.0 - Support `Map` keys of type `int`, `BigInt`, `DateTime`, and `Uri`. diff --git a/json_serializable/README.md b/json_serializable/README.md index b89ceb105..23a92c564 100644 --- a/json_serializable/README.md +++ b/json_serializable/README.md @@ -79,6 +79,7 @@ is generated: | disallow_unrecognized_keys | [JsonSerializable.disallowUnrecognizedKeys] | | | explicit_to_json | [JsonSerializable.explicitToJson] | | | field_rename | [JsonSerializable.fieldRename] | | +| ignore_unannotated | [JsonSerializable.ignoreUnannotated] | | | include_if_null | [JsonSerializable.includeIfNull] | [JsonKey.includeIfNull] | | nullable | [JsonSerializable.nullable] | [JsonKey.nullable] | | | | [JsonKey.defaultValue] | @@ -89,24 +90,25 @@ is generated: | | | [JsonKey.required] | | | | [JsonKey.toJson] | -[JsonSerializable.anyMap]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonSerializable/anyMap.html -[JsonSerializable.checked]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonSerializable/checked.html -[JsonSerializable.createFactory]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonSerializable/createFactory.html -[JsonSerializable.createToJson]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonSerializable/createToJson.html -[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html -[JsonSerializable.explicitToJson]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonSerializable/explicitToJson.html -[JsonSerializable.fieldRename]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonSerializable/fieldRename.html -[JsonSerializable.includeIfNull]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonSerializable/includeIfNull.html -[JsonKey.includeIfNull]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonKey/includeIfNull.html -[JsonSerializable.nullable]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonSerializable/nullable.html -[JsonKey.nullable]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonKey/nullable.html -[JsonKey.defaultValue]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonKey/defaultValue.html -[JsonKey.disallowNullValue]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonKey/disallowNullValue.html -[JsonKey.fromJson]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonKey/fromJson.html -[JsonKey.ignore]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonKey/ignore.html -[JsonKey.name]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonKey/name.html -[JsonKey.required]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonKey/required.html -[JsonKey.toJson]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonKey/toJson.html +[JsonSerializable.anyMap]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/anyMap.html +[JsonSerializable.checked]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/checked.html +[JsonSerializable.createFactory]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/createFactory.html +[JsonSerializable.createToJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/createToJson.html +[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html +[JsonSerializable.explicitToJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/explicitToJson.html +[JsonSerializable.fieldRename]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/fieldRename.html +[JsonSerializable.ignoreUnannotated]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/ignoreUnannotated.html +[JsonSerializable.includeIfNull]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/includeIfNull.html +[JsonKey.includeIfNull]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/includeIfNull.html +[JsonSerializable.nullable]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/nullable.html +[JsonKey.nullable]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/nullable.html +[JsonKey.defaultValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/defaultValue.html +[JsonKey.disallowNullValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/disallowNullValue.html +[JsonKey.fromJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/fromJson.html +[JsonKey.ignore]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/ignore.html +[JsonKey.name]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/name.html +[JsonKey.required]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/required.html +[JsonKey.toJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/toJson.html > Note: every `JsonSerializable` field is configurable via `build.yaml` – see the table for the corresponding key. @@ -141,6 +143,7 @@ targets: disallow_unrecognized_keys: false explicit_to_json: false field_rename: none + ignore_unannotated: false include_if_null: true nullable: true ``` diff --git a/json_serializable/doc/doc.md b/json_serializable/doc/doc.md index 78de4649a..ac28ea7e1 100644 --- a/json_serializable/doc/doc.md +++ b/json_serializable/doc/doc.md @@ -7,6 +7,7 @@ | disallow_unrecognized_keys | [JsonSerializable.disallowUnrecognizedKeys] | | | explicit_to_json | [JsonSerializable.explicitToJson] | | | field_rename | [JsonSerializable.fieldRename] | | +| ignore_unannotated | [JsonSerializable.ignoreUnannotated] | | | include_if_null | [JsonSerializable.includeIfNull] | [JsonKey.includeIfNull] | | nullable | [JsonSerializable.nullable] | [JsonKey.nullable] | | | | [JsonKey.defaultValue] | @@ -17,21 +18,22 @@ | | | [JsonKey.required] | | | | [JsonKey.toJson] | -[JsonSerializable.anyMap]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonSerializable/anyMap.html -[JsonSerializable.checked]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonSerializable/checked.html -[JsonSerializable.createFactory]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonSerializable/createFactory.html -[JsonSerializable.createToJson]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonSerializable/createToJson.html -[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html -[JsonSerializable.explicitToJson]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonSerializable/explicitToJson.html -[JsonSerializable.fieldRename]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonSerializable/fieldRename.html -[JsonSerializable.includeIfNull]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonSerializable/includeIfNull.html -[JsonKey.includeIfNull]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonKey/includeIfNull.html -[JsonSerializable.nullable]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonSerializable/nullable.html -[JsonKey.nullable]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonKey/nullable.html -[JsonKey.defaultValue]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonKey/defaultValue.html -[JsonKey.disallowNullValue]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonKey/disallowNullValue.html -[JsonKey.fromJson]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonKey/fromJson.html -[JsonKey.ignore]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonKey/ignore.html -[JsonKey.name]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonKey/name.html -[JsonKey.required]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonKey/required.html -[JsonKey.toJson]: https://pub.dev/documentation/json_annotation/2.4.0/json_annotation/JsonKey/toJson.html +[JsonSerializable.anyMap]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/anyMap.html +[JsonSerializable.checked]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/checked.html +[JsonSerializable.createFactory]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/createFactory.html +[JsonSerializable.createToJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/createToJson.html +[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html +[JsonSerializable.explicitToJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/explicitToJson.html +[JsonSerializable.fieldRename]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/fieldRename.html +[JsonSerializable.ignoreUnannotated]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/ignoreUnannotated.html +[JsonSerializable.includeIfNull]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/includeIfNull.html +[JsonKey.includeIfNull]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/includeIfNull.html +[JsonSerializable.nullable]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/nullable.html +[JsonKey.nullable]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/nullable.html +[JsonKey.defaultValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/defaultValue.html +[JsonKey.disallowNullValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/disallowNullValue.html +[JsonKey.fromJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/fromJson.html +[JsonKey.ignore]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/ignore.html +[JsonKey.name]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/name.html +[JsonKey.required]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/required.html +[JsonKey.toJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/toJson.html diff --git a/json_serializable/lib/src/json_key_utils.dart b/json_serializable/lib/src/json_key_utils.dart index 0d66f25d8..2a5c1fac5 100644 --- a/json_serializable/lib/src/json_key_utils.dart +++ b/json_serializable/lib/src/json_key_utils.dart @@ -39,7 +39,11 @@ JsonKey _from(FieldElement element, JsonSerializable classAnnotation) { final obj = jsonKeyAnnotation(element); if (obj == null) { - return _populateJsonKey(classAnnotation, element); + return _populateJsonKey( + classAnnotation, + element, + ignore: classAnnotation.ignoreUnannotated, + ); } Object _getLiteral(DartObject dartObject, Iterable things) { diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index 4f36f0d23..d8094d434 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -79,12 +79,13 @@ JsonSerializable _valueForAnnotation(ConstantReader reader) => JsonSerializable( reader.read('disallowUnrecognizedKeys').literalValue as bool, explicitToJson: reader.read('explicitToJson').literalValue as bool, fieldRename: _fromDartObject(reader.read('fieldRename')), + ignoreUnannotated: reader.read('ignoreUnannotated').literalValue as bool, includeIfNull: reader.read('includeIfNull').literalValue as bool, nullable: reader.read('nullable').literalValue as bool, ); -/// Returns a [JsonSerializable] with values from the [JsonSerializable] instance -/// represented by [reader]. +/// Returns a [JsonSerializable] with values from the [JsonSerializable] +/// instance represented by [reader]. /// /// For fields that are not defined in [JsonSerializable] or `null` in [reader], /// use the values in [config]. @@ -100,6 +101,7 @@ JsonSerializable mergeConfig(JsonSerializable config, ConstantReader reader) { annotation.disallowUnrecognizedKeys ?? config.disallowUnrecognizedKeys, explicitToJson: annotation.explicitToJson ?? config.explicitToJson, fieldRename: annotation.fieldRename ?? config.fieldRename, + ignoreUnannotated: annotation.ignoreUnannotated ?? config.ignoreUnannotated, includeIfNull: annotation.includeIfNull ?? config.includeIfNull, nullable: annotation.nullable ?? config.nullable, ); diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 12235acde..95b0d1a0d 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 3.1.0 +version: 3.2.0-dev author: Dart Team description: >- Automatically generate code for converting to and from JSON by annotating @@ -17,7 +17,7 @@ dependencies: # `json_annotation` properly constrains all features it provides. # For v3 only – allow a wide range since the only change was to REMOVE things # from json_annotation - json_annotation: '>=2.3.0 <3.0.0' + json_annotation: '>=3.0.0 <3.1.0' meta: ^1.1.0 path: ^1.3.2 source_gen: ^0.9.0 @@ -33,3 +33,7 @@ dev_dependencies: source_gen_test: ^0.1.0 test: ^1.6.0 yaml: ^2.1.13 + +dependency_overrides: + json_annotation: + path: ../json_annotation diff --git a/json_serializable/test/config_test.dart b/json_serializable/test/config_test.dart index 33d7d8228..ab9d79f35 100644 --- a/json_serializable/test/config_test.dart +++ b/json_serializable/test/config_test.dart @@ -76,13 +76,10 @@ void main() { final configMap = Map.from(yaml); - expect( - configMap.keys, - unorderedEquals(generatorConfigDefaultJson.keys - .where((k) => !deprecatedKeys.contains(k))), + expect(configMap.keys, unorderedEquals(generatorConfigDefaultJson.keys), reason: 'All supported keys are documented.'); - expectMapMatchExcludingDeprecated( + expect( JsonSerializable.fromJson(configMap).toJson(), generatorConfigDefaultJson, ); @@ -139,11 +136,9 @@ const _invalidConfig = { 'create_factory': 42, 'create_to_json': 42, 'disallow_unrecognized_keys': 42, - 'encode_empty_collection': 42, 'explicit_to_json': 42, 'field_rename': 42, - 'generate_to_json_function': 42, + 'ignore_unannotated': 42, 'include_if_null': 42, 'nullable': 42, - 'use_wrappers': 42, }; diff --git a/json_serializable/test/custom_configuration_test.dart b/json_serializable/test/custom_configuration_test.dart index 220d1cca4..e5923b584 100644 --- a/json_serializable/test/custom_configuration_test.dart +++ b/json_serializable/test/custom_configuration_test.dart @@ -58,8 +58,7 @@ void main() async { expect(_ConfigLogger.configurations, hasLength(2)); expect(_ConfigLogger.configurations.first, same(_ConfigLogger.configurations.last)); - expectMapMatchExcludingDeprecated( - _ConfigLogger.configurations.first.toJson(), + expect(_ConfigLogger.configurations.first.toJson(), generatorConfigDefaultJson); }); } @@ -105,8 +104,7 @@ void main() async { expected[jsonSerialKey] = generatorConfigDefaultJson[jsonSerialKey]; } - expectMapMatchExcludingDeprecated( - _ConfigLogger.configurations.first.toJson(), expected); + expect(_ConfigLogger.configurations.first.toJson(), expected); }); }); } diff --git a/json_serializable/test/json_serializable_test.dart b/json_serializable/test/json_serializable_test.dart index de372631c..b964f6815 100644 --- a/json_serializable/test/json_serializable_test.dart +++ b/json_serializable/test/json_serializable_test.dart @@ -53,6 +53,7 @@ const _expectedAnnotatedTests = [ 'GenericClass', 'IgnoredFieldClass', 'IgnoredFieldCtorClass', + 'IgnoreUnannotated', 'IncludeIfNullDisallowNullClass', 'IncludeIfNullOverride', 'InvalidFromFunc2Args', diff --git a/json_serializable/test/shared_config.dart b/json_serializable/test/shared_config.dart index 11aab7dbd..1a74c1453 100644 --- a/json_serializable/test/shared_config.dart +++ b/json_serializable/test/shared_config.dart @@ -3,7 +3,6 @@ // BSD-style license that can be found in the LICENSE file. import 'package:json_annotation/json_annotation.dart'; -import 'package:test/test.dart'; final jsonSerializableFields = generatorConfigDefaultJson.keys.toList(); @@ -19,24 +18,7 @@ final generatorConfigNonDefaultJson = disallowUnrecognizedKeys: true, explicitToJson: true, fieldRename: FieldRename.kebab, + ignoreUnannotated: true, includeIfNull: false, nullable: false, ).toJson()); - -// TODO(kevmoo): remove all of this logic once json_annotation v3 exists -void expectMapMatchExcludingDeprecated( - Map actual, Map expected) { - Map exclude(Map source) => Map.fromEntries( - source.entries.where((e) => !deprecatedKeys.contains(e.key))); - - expect( - exclude(actual), - exclude(expected), - ); -} - -const deprecatedKeys = { - 'encode_empty_collection', - 'generate_to_json_function', - 'use_wrappers', -}; diff --git a/json_serializable/test/src/_json_serializable_test_input.dart b/json_serializable/test/src/_json_serializable_test_input.dart index 2acd5c2ab..760550f72 100644 --- a/json_serializable/test/src/_json_serializable_test_input.dart +++ b/json_serializable/test/src/_json_serializable_test_input.dart @@ -460,3 +460,23 @@ class PropInMixinI448Regression with _PropInMixinI448RegressionMixin { @JsonKey(nullable: false) int notNullable; } + +@ShouldGenerate( + r''' +IgnoreUnannotated _$IgnoreUnannotatedFromJson(Map json) { + return IgnoreUnannotated()..annotated = json['annotated'] as int; +} + +Map _$IgnoreUnannotatedToJson(IgnoreUnannotated instance) => + { + 'annotated': instance.annotated, + }; +''', +) +@JsonSerializable(ignoreUnannotated: true) +class IgnoreUnannotated { + @JsonKey() + int annotated; + + int unannotated; +} diff --git a/json_serializable/test/test_sources/test_sources.dart b/json_serializable/test/test_sources/test_sources.dart index d87b7da8e..0a44c53de 100644 --- a/json_serializable/test/test_sources/test_sources.dart +++ b/json_serializable/test/test_sources/test_sources.dart @@ -13,6 +13,7 @@ class ConfigurationImplicitDefaults { disallowUnrecognizedKeys: false, explicitToJson: false, fieldRename: FieldRename.none, + ignoreUnannotated: false, includeIfNull: true, nullable: true, ) From 24dd6bd660d035873eeb6b4292d4be41fbe6eb5b Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 30 Jul 2019 13:06:07 -0700 Subject: [PATCH 157/569] Enum convert map: Remove explicit type and add trailing comma (#515) Also added a mismatched value type to json_test_common --- _test_yaml/test/src/build_config.g.dart | 8 ++++---- json_serializable/CHANGELOG.md | 1 + .../lib/src/type_helpers/enum_helper.dart | 10 +++++----- .../test/default_value/default_value.g.dart | 4 ++-- .../default_value.g_any_map__checked.g.dart | 4 ++-- .../test/integration/json_test_common.dart | 4 +++- .../test/integration/json_test_example.g.dart | 9 +++++---- .../integration/json_test_example.g_any_map.g.dart | 9 +++++---- .../json_test_example.g_non_nullable.g.dart | 9 +++++---- .../test/src/_json_serializable_test_input.dart | 4 ++-- 10 files changed, 34 insertions(+), 28 deletions(-) diff --git a/_test_yaml/test/src/build_config.g.dart b/_test_yaml/test/src/build_config.g.dart index d71377ee0..cab07d9db 100644 --- a/_test_yaml/test/src/build_config.g.dart +++ b/_test_yaml/test/src/build_config.g.dart @@ -55,11 +55,11 @@ T _$enumDecodeNullable(Map enumValues, dynamic source) { return _$enumDecode(enumValues, source); } -const _$AutoApplyEnumMap = { +const _$AutoApplyEnumMap = { AutoApply.none: 'none', AutoApply.dependents: 'dependents', AutoApply.allPackages: 'all_packages', - AutoApply.rootPackage: 'root_package' + AutoApply.rootPackage: 'root_package', }; Builder _$BuilderFromJson(Map json) { @@ -141,7 +141,7 @@ Map _$BuilderToJson(Builder instance) { return val; } -const _$BuildToEnumMap = { +const _$BuildToEnumMap = { BuildTo.cache: 'cache', - BuildTo.source: 'source' + BuildTo.source: 'source', }; diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 7844d4bb9..c1b4e67ff 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -2,6 +2,7 @@ - Require `package:json_annotation` `^3.0.0`. - Added support for `@JsonSerializable(ignoreUnannotated: true)`. +- Small change to how `enum` support code is generated. ## 3.1.0 diff --git a/json_serializable/lib/src/type_helpers/enum_helper.dart b/json_serializable/lib/src/type_helpers/enum_helper.dart index a126d43e4..3b5b931d2 100644 --- a/json_serializable/lib/src/type_helpers/enum_helper.dart +++ b/json_serializable/lib/src/type_helpers/enum_helper.dart @@ -60,12 +60,12 @@ String _enumValueMapFromType(DartType targetType) { return null; } - final items = - enumMap.entries.map((e) => ' ${targetType.name}.${e.key.name}: ' - '${jsonLiteralAsDart(e.value)}'); + final items = enumMap.entries + .map((e) => + ' ${targetType.name}.${e.key.name}: ${jsonLiteralAsDart(e.value)},') + .join(); - return 'const ${_constMapName(targetType)} = ' - '<${targetType.name}, dynamic>{\n${items.join(',\n')}\n};'; + return 'const ${_constMapName(targetType)} = {\n$items\n};'; } const _enumDecodeHelper = r''' diff --git a/json_serializable/test/default_value/default_value.g.dart b/json_serializable/test/default_value/default_value.g.dart index 4c68ed43e..fe0c810c4 100644 --- a/json_serializable/test/default_value/default_value.g.dart +++ b/json_serializable/test/default_value/default_value.g.dart @@ -76,9 +76,9 @@ T _$enumDecodeNullable(Map enumValues, dynamic source) { return _$enumDecode(enumValues, source); } -const _$GreekEnumMap = { +const _$GreekEnumMap = { Greek.alpha: 'alpha', Greek.beta: 'beta', Greek.gamma: 'gamma', - Greek.delta: 'delta' + Greek.delta: 'delta', }; diff --git a/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart b/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart index f0496f4cb..5ca37e32e 100644 --- a/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart +++ b/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart @@ -94,9 +94,9 @@ T _$enumDecodeNullable(Map enumValues, dynamic source) { return _$enumDecode(enumValues, source); } -const _$GreekEnumMap = { +const _$GreekEnumMap = { Greek.alpha: 'alpha', Greek.beta: 'beta', Greek.gamma: 'gamma', - Greek.delta: 'delta' + Greek.delta: 'delta', }; diff --git a/json_serializable/test/integration/json_test_common.dart b/json_serializable/test/integration/json_test_common.dart index 3fb55e77d..6a5a6df82 100644 --- a/json_serializable/test/integration/json_test_common.dart +++ b/json_serializable/test/integration/json_test_common.dart @@ -22,7 +22,9 @@ enum StatusCode { @JsonValue(200) success, @JsonValue(404) - notFound + notFound, + @JsonValue('500') + weird, } Duration durationFromInt(int ms) => diff --git a/json_serializable/test/integration/json_test_example.g.dart b/json_serializable/test/integration/json_test_example.g.dart index 17a43a9a0..8faf12013 100644 --- a/json_serializable/test/integration/json_test_example.g.dart +++ b/json_serializable/test/integration/json_test_example.g.dart @@ -67,14 +67,14 @@ T _$enumDecodeNullable(Map enumValues, dynamic source) { return _$enumDecode(enumValues, source); } -const _$CategoryEnumMap = { +const _$CategoryEnumMap = { Category.top: 'top', Category.bottom: 'bottom', Category.strange: 'strange', Category.charmed: 'charmed', Category.up: 'up', Category.down: 'down', - Category.notDiscoveredYet: 'not_discovered_yet' + Category.notDiscoveredYet: 'not_discovered_yet', }; Order _$OrderFromJson(Map json) { @@ -123,9 +123,10 @@ Map _$OrderToJson(Order instance) { return val; } -const _$StatusCodeEnumMap = { +const _$StatusCodeEnumMap = { StatusCode.success: 200, - StatusCode.notFound: 404 + StatusCode.notFound: 404, + StatusCode.weird: '500', }; Item _$ItemFromJson(Map json) { diff --git a/json_serializable/test/integration/json_test_example.g_any_map.g.dart b/json_serializable/test/integration/json_test_example.g_any_map.g.dart index 69ae256e3..498525d4b 100644 --- a/json_serializable/test/integration/json_test_example.g_any_map.g.dart +++ b/json_serializable/test/integration/json_test_example.g_any_map.g.dart @@ -73,14 +73,14 @@ T _$enumDecodeNullable(Map enumValues, dynamic source) { return _$enumDecode(enumValues, source); } -const _$CategoryEnumMap = { +const _$CategoryEnumMap = { Category.top: 'top', Category.bottom: 'bottom', Category.strange: 'strange', Category.charmed: 'charmed', Category.up: 'up', Category.down: 'down', - Category.notDiscoveredYet: 'not_discovered_yet' + Category.notDiscoveredYet: 'not_discovered_yet', }; Order _$OrderFromJson(Map json) { @@ -133,9 +133,10 @@ Map _$OrderToJson(Order instance) { return val; } -const _$StatusCodeEnumMap = { +const _$StatusCodeEnumMap = { StatusCode.success: 200, - StatusCode.notFound: 404 + StatusCode.notFound: 404, + StatusCode.weird: '500', }; Item _$ItemFromJson(Map json) { diff --git a/json_serializable/test/integration/json_test_example.g_non_nullable.g.dart b/json_serializable/test/integration/json_test_example.g_non_nullable.g.dart index 8ac55bff8..3be8a03ee 100644 --- a/json_serializable/test/integration/json_test_example.g_non_nullable.g.dart +++ b/json_serializable/test/integration/json_test_example.g_non_nullable.g.dart @@ -53,14 +53,14 @@ T _$enumDecode(Map enumValues, dynamic source) { .key; } -const _$CategoryEnumMap = { +const _$CategoryEnumMap = { Category.top: 'top', Category.bottom: 'bottom', Category.strange: 'strange', Category.charmed: 'charmed', Category.up: 'up', Category.down: 'down', - Category.notDiscoveredYet: 'not_discovered_yet' + Category.notDiscoveredYet: 'not_discovered_yet', }; Order _$OrderFromJson(Map json) { @@ -102,9 +102,10 @@ T _$enumDecodeNullable(Map enumValues, dynamic source) { return _$enumDecode(enumValues, source); } -const _$StatusCodeEnumMap = { +const _$StatusCodeEnumMap = { StatusCode.success: 200, - StatusCode.notFound: 404 + StatusCode.notFound: 404, + StatusCode.weird: '500', }; Item _$ItemFromJson(Map json) { diff --git a/json_serializable/test/src/_json_serializable_test_input.dart b/json_serializable/test/src/_json_serializable_test_input.dart index 760550f72..ca7353e4a 100644 --- a/json_serializable/test/src/_json_serializable_test_input.dart +++ b/json_serializable/test/src/_json_serializable_test_input.dart @@ -368,12 +368,12 @@ enum BadEnum { value } -@ShouldGenerate(r'''const _$GoodEnumEnumMap = { +@ShouldGenerate(r'''const _$GoodEnumEnumMap = { GoodEnum.noAnnotation: 'noAnnotation', GoodEnum.stringAnnotation: 'string annotation', GoodEnum.stringAnnotationWeird: r"string annotation with $ funky 'values'", GoodEnum.intValue: 42, - GoodEnum.nullValue: null + GoodEnum.nullValue: null, }; ''', contains: true) @JsonSerializable() From 4aaf8e01bbd5f15e0f201fcb98420b109dfe134a Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 30 Jul 2019 18:42:27 -0700 Subject: [PATCH 158/569] Add JsonKey.unknownEnumValue (#516) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Allows annotated enum fields with a fall-back value when an unknown input is encountered during decode (`fromJson`). Common when client code has not been updated to handle changing output from an external source of JSON data. `EnumHelper` now extends `TypeHelper`. `TypeHelperContextWithConfig` provides access to field information – which allows access to the `JsonKey` annotation – which allows access to the `unknownEnumValue` annotation field. Fixes https://github.com/dart-lang/json_serializable/issues/504 --- _test_yaml/test/src/build_config.g.dart | 30 +++++-- json_annotation/CHANGELOG.md | 1 + json_annotation/lib/src/json_key.dart | 7 ++ json_serializable/CHANGELOG.md | 3 +- json_serializable/README.md | 2 + json_serializable/doc/doc.md | 2 + json_serializable/lib/src/json_key_utils.dart | 77 +++++++++++------ .../lib/src/type_helpers/enum_helper.dart | 61 +++++++++---- .../test/default_value/default_value.g.dart | 30 +++++-- .../default_value.g_any_map__checked.g.dart | 30 +++++-- .../test/integration/integration_test.dart | 25 +++++- .../test/integration/json_test_common.dart | 5 ++ .../test/integration/json_test_example.dart | 6 +- .../test/integration/json_test_example.g.dart | 38 ++++++--- .../json_test_example.g_any_map.dart | 6 +- .../json_test_example.g_any_map.g.dart | 38 ++++++--- .../json_test_example.g_non_nullable.dart | 6 +- .../json_test_example.g_non_nullable.g.dart | 38 ++++++--- .../test/json_serializable_test.dart | 3 + .../src/_json_serializable_test_input.dart | 2 + .../src/unknown_enum_value_test_input.dart | 85 +++++++++++++++++++ 21 files changed, 386 insertions(+), 109 deletions(-) create mode 100644 json_serializable/test/src/unknown_enum_value_test_input.dart diff --git a/_test_yaml/test/src/build_config.g.dart b/_test_yaml/test/src/build_config.g.dart index cab07d9db..7e247020a 100644 --- a/_test_yaml/test/src/build_config.g.dart +++ b/_test_yaml/test/src/build_config.g.dart @@ -35,24 +35,36 @@ Map _$ConfigToJson(Config instance) => { instance.weights?.map((k, e) => MapEntry(_$AutoApplyEnumMap[k], e)), }; -T _$enumDecode(Map enumValues, dynamic source) { +T _$enumDecode( + Map enumValues, + dynamic source, { + T unknownValue, +}) { if (source == null) { throw ArgumentError('A value must be provided. Supported values: ' '${enumValues.values.join(', ')}'); } - return enumValues.entries - .singleWhere((e) => e.value == source, - orElse: () => throw ArgumentError( - '`$source` is not one of the supported values: ' - '${enumValues.values.join(', ')}')) - .key; + + final value = enumValues.entries + .singleWhere((e) => e.value == source, orElse: () => null) + ?.key; + + if (value == null && unknownValue == null) { + throw ArgumentError('`$source` is not one of the supported values: ' + '${enumValues.values.join(', ')}'); + } + return value ?? unknownValue; } -T _$enumDecodeNullable(Map enumValues, dynamic source) { +T _$enumDecodeNullable( + Map enumValues, + dynamic source, { + T unknownValue, +}) { if (source == null) { return null; } - return _$enumDecode(enumValues, source); + return _$enumDecode(enumValues, source, unknownValue: unknownValue); } const _$AutoApplyEnumMap = { diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index a3b18acfb..4a7b8bb71 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -6,6 +6,7 @@ - **BREAKING** Removed `encodeEmptyCollection` from `JsonSerializable` and `JsonKey`. - Added `JsonSerializable.ignoreUnannotated`. +- Added `JsonKey.unknownEnumValue`. ## 2.4.0 diff --git a/json_annotation/lib/src/json_key.dart b/json_annotation/lib/src/json_key.dart index 71aee1e0c..718a87187 100644 --- a/json_annotation/lib/src/json_key.dart +++ b/json_annotation/lib/src/json_key.dart @@ -97,6 +97,12 @@ class JsonKey { /// Values returned by [toJson] should "round-trip" through [fromJson]. final Function toJson; + /// The value to use for an enum field when the value provided is not in the + /// source enum. + /// + /// Valid only on enum fields with a compatible enum value. + final Object unknownEnumValue; + /// Creates a new [JsonKey] instance. /// /// Only required when the default behavior is not desired. @@ -110,5 +116,6 @@ class JsonKey { this.nullable, this.required, this.toJson, + this.unknownEnumValue, }); } diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index c1b4e67ff..8cddbdd12 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,7 +1,8 @@ ## 3.2.0 - Require `package:json_annotation` `^3.0.0`. -- Added support for `@JsonSerializable(ignoreUnannotated: true)`. +- Added support for `JsonSerializable.ignoreUnannotated`. +- Added support for `JsonKey.unknownEnumValue`. - Small change to how `enum` support code is generated. ## 3.1.0 diff --git a/json_serializable/README.md b/json_serializable/README.md index 23a92c564..32134db82 100644 --- a/json_serializable/README.md +++ b/json_serializable/README.md @@ -89,6 +89,7 @@ is generated: | | | [JsonKey.name] | | | | [JsonKey.required] | | | | [JsonKey.toJson] | +| | | [JsonKey.unknownEnumValue] | [JsonSerializable.anyMap]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/anyMap.html [JsonSerializable.checked]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/checked.html @@ -109,6 +110,7 @@ is generated: [JsonKey.name]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/name.html [JsonKey.required]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/required.html [JsonKey.toJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/toJson.html +[JsonKey.unknownEnumValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/unknownEnumValue.html > Note: every `JsonSerializable` field is configurable via `build.yaml` – see the table for the corresponding key. diff --git a/json_serializable/doc/doc.md b/json_serializable/doc/doc.md index ac28ea7e1..da2daa83c 100644 --- a/json_serializable/doc/doc.md +++ b/json_serializable/doc/doc.md @@ -17,6 +17,7 @@ | | | [JsonKey.name] | | | | [JsonKey.required] | | | | [JsonKey.toJson] | +| | | [JsonKey.unknownEnumValue] | [JsonSerializable.anyMap]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/anyMap.html [JsonSerializable.checked]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/checked.html @@ -37,3 +38,4 @@ [JsonKey.name]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/name.html [JsonKey.required]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/required.html [JsonKey.toJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/toJson.html +[JsonKey.unknownEnumValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/unknownEnumValue.html diff --git a/json_serializable/lib/src/json_key_utils.dart b/json_serializable/lib/src/json_key_utils.dart index 2a5c1fac5..dbfdc523f 100644 --- a/json_serializable/lib/src/json_key_utils.dart +++ b/json_serializable/lib/src/json_key_utils.dart @@ -46,7 +46,13 @@ JsonKey _from(FieldElement element, JsonSerializable classAnnotation) { ); } - Object _getLiteral(DartObject dartObject, Iterable things) { + /// Returns a literal value for [dartObject] if possible, otherwise throws + /// an [InvalidGenerationSourceError] using [typeInformation] to describe + /// the unsupported type. + Object literalForObject( + DartObject dartObject, + Iterable typeInformation, + ) { if (dartObject.isNull) { return null; } @@ -66,7 +72,7 @@ JsonKey _from(FieldElement element, JsonSerializable classAnnotation) { } if (badType != null) { - badType = things.followedBy([badType]).join(' > '); + badType = typeInformation.followedBy([badType]).join(' > '); throwUnsupported( element, '`defaultValue` is `$badType`, it must be a literal.'); } @@ -77,15 +83,15 @@ JsonKey _from(FieldElement element, JsonSerializable classAnnotation) { return literal; } else if (literal is List) { return literal - .map((e) => _getLiteral(e, things.followedBy(['List']))) + .map((e) => literalForObject(e, typeInformation.followedBy(['List']))) .toList(); } else if (literal is Map) { - final mapThings = things.followedBy(['Map']); - return literal.map((k, v) => - MapEntry(_getLiteral(k, mapThings), _getLiteral(v, mapThings))); + final mapThings = typeInformation.followedBy(['Map']); + return literal.map((k, v) => MapEntry( + literalForObject(k, mapThings), literalForObject(v, mapThings))); } - badType = things.followedBy(['$dartObject']).join(' > '); + badType = typeInformation.followedBy(['$dartObject']).join(' > '); throwUnsupported( element, @@ -94,36 +100,55 @@ JsonKey _from(FieldElement element, JsonSerializable classAnnotation) { 'Please rerun your build with `--verbose` and file an issue.'); } - final defaultValueObject = obj.getField('defaultValue'); - - Object defaultValueLiteral; - - final enumFields = iterateEnumFields(defaultValueObject.type); - if (enumFields != null) { - final enumValueNames = - enumFields.map((p) => p.name).toList(growable: false); - - final enumValueName = enumValueForDartObject( - defaultValueObject, enumValueNames, (n) => n); - - defaultValueLiteral = '${defaultValueObject.type.name}.$enumValueName'; - } else { - defaultValueLiteral = _getLiteral(defaultValueObject, []); - if (defaultValueLiteral != null) { - defaultValueLiteral = jsonLiteralAsDart(defaultValueLiteral); + /// Returns a literal object representing the value of [fieldName] in [obj]. + /// + /// If [mustBeEnum] is `true`, throws an [InvalidGenerationSourceError] if + /// either the annotated field is not an `enum` or if the value in + /// [fieldName] is not an `enum` value. + Object _annotationValue(String fieldName, {bool mustBeEnum = false}) { + final annotationValue = obj.getField(fieldName); + + final enumFields = iterateEnumFields(annotationValue.type); + if (enumFields != null) { + if (mustBeEnum && !isEnum(element.type)) { + throwUnsupported( + element, + '`$fieldName` can only be set on fields of type enum.', + ); + } + final enumValueNames = + enumFields.map((p) => p.name).toList(growable: false); + + final enumValueName = enumValueForDartObject( + annotationValue, enumValueNames, (n) => n); + + return '${annotationValue.type.name}.$enumValueName'; + } else { + final defaultValueLiteral = literalForObject(annotationValue, []); + if (defaultValueLiteral == null) { + return null; + } + if (mustBeEnum) { + throwUnsupported( + element, + 'The value provided for `$fieldName` must be a matching enum.', + ); + } + return jsonLiteralAsDart(defaultValueLiteral); } } return _populateJsonKey( classAnnotation, element, - defaultValue: defaultValueLiteral, + defaultValue: _annotationValue('defaultValue'), disallowNullValue: obj.getField('disallowNullValue').toBoolValue(), ignore: obj.getField('ignore').toBoolValue(), includeIfNull: obj.getField('includeIfNull').toBoolValue(), name: obj.getField('name').toStringValue(), nullable: obj.getField('nullable').toBoolValue(), required: obj.getField('required').toBoolValue(), + unknownEnumValue: _annotationValue('unknownEnumValue', mustBeEnum: true), ); } @@ -137,6 +162,7 @@ JsonKey _populateJsonKey( String name, bool nullable, bool required, + Object unknownEnumValue, }) { if (disallowNullValue == true) { if (includeIfNull == true) { @@ -156,6 +182,7 @@ JsonKey _populateJsonKey( name: _encodedFieldName(classAnnotation, name, element), nullable: nullable ?? classAnnotation.nullable, required: required ?? false, + unknownEnumValue: unknownEnumValue, ); _explicitNullableExpando[jsonKey] = nullable != null; diff --git a/json_serializable/lib/src/type_helpers/enum_helper.dart b/json_serializable/lib/src/type_helpers/enum_helper.dart index 3b5b931d2..8e83c138a 100644 --- a/json_serializable/lib/src/type_helpers/enum_helper.dart +++ b/json_serializable/lib/src/type_helpers/enum_helper.dart @@ -4,18 +4,22 @@ import 'package:analyzer/dart/element/type.dart'; +import '../json_key_utils.dart'; import '../json_literal_generator.dart'; import '../type_helper.dart'; import '../utils.dart'; final simpleExpression = RegExp('^[a-zA-Z_]+\$'); -class EnumHelper extends TypeHelper { +class EnumHelper extends TypeHelper { const EnumHelper(); @override String serialize( - DartType targetType, String expression, TypeHelperContext context) { + DartType targetType, + String expression, + TypeHelperContextWithConfig context, + ) { final memberContent = _enumValueMapFromType(targetType); if (memberContent == null) { @@ -29,7 +33,10 @@ class EnumHelper extends TypeHelper { @override String deserialize( - DartType targetType, String expression, TypeHelperContext context) { + DartType targetType, + String expression, + TypeHelperContextWithConfig context, + ) { final memberContent = _enumValueMapFromType(targetType); if (memberContent == null) { @@ -46,8 +53,19 @@ class EnumHelper extends TypeHelper { final functionName = context.nullable ? r'_$enumDecodeNullable' : r'_$enumDecode'; - return '$functionName(${_constMapName(targetType)}, ' - '$expression)'; + + final args = [ + _constMapName(targetType), + expression, + ]; + + final jsonKey = jsonKeyForField(context.fieldElement, context.config); + // TODO(kevmoo): use collection expressions once min-SDK is >= 2.3.0 + if (jsonKey.unknownEnumValue != null) { + args.add('unknownValue: ${jsonKey.unknownEnumValue}'); + } + + return '$functionName(${args.join(', ')})'; } } @@ -69,23 +87,36 @@ String _enumValueMapFromType(DartType targetType) { } const _enumDecodeHelper = r''' -T _$enumDecode(Map enumValues, dynamic source) { +T _$enumDecode( + Map enumValues, + dynamic source, { + T unknownValue, +}) { if (source == null) { throw ArgumentError('A value must be provided. Supported values: ' '${enumValues.values.join(', ')}'); } - return enumValues.entries - .singleWhere((e) => e.value == source, - orElse: () => throw ArgumentError( - '`$source` is not one of the supported values: ' - '${enumValues.values.join(', ')}')) - .key; -}'''; + + final value = enumValues.entries + .singleWhere((e) => e.value == source, orElse: () => null) + ?.key; + + if (value == null && unknownValue == null) { + throw ArgumentError('`$source` is not one of the supported values: ' + '${enumValues.values.join(', ')}'); + } + return value ?? unknownValue; +} +'''; const _enumDecodeHelperNullable = r''' -T _$enumDecodeNullable(Map enumValues, dynamic source) { +T _$enumDecodeNullable( + Map enumValues, + dynamic source, { + T unknownValue, +}) { if (source == null) { return null; } - return _$enumDecode(enumValues, source); + return _$enumDecode(enumValues, source, unknownValue: unknownValue); }'''; diff --git a/json_serializable/test/default_value/default_value.g.dart b/json_serializable/test/default_value/default_value.g.dart index fe0c810c4..e481851ac 100644 --- a/json_serializable/test/default_value/default_value.g.dart +++ b/json_serializable/test/default_value/default_value.g.dart @@ -56,24 +56,36 @@ Map _$DefaultValueToJson(DefaultValue instance) { return val; } -T _$enumDecode(Map enumValues, dynamic source) { +T _$enumDecode( + Map enumValues, + dynamic source, { + T unknownValue, +}) { if (source == null) { throw ArgumentError('A value must be provided. Supported values: ' '${enumValues.values.join(', ')}'); } - return enumValues.entries - .singleWhere((e) => e.value == source, - orElse: () => throw ArgumentError( - '`$source` is not one of the supported values: ' - '${enumValues.values.join(', ')}')) - .key; + + final value = enumValues.entries + .singleWhere((e) => e.value == source, orElse: () => null) + ?.key; + + if (value == null && unknownValue == null) { + throw ArgumentError('`$source` is not one of the supported values: ' + '${enumValues.values.join(', ')}'); + } + return value ?? unknownValue; } -T _$enumDecodeNullable(Map enumValues, dynamic source) { +T _$enumDecodeNullable( + Map enumValues, + dynamic source, { + T unknownValue, +}) { if (source == null) { return null; } - return _$enumDecode(enumValues, source); + return _$enumDecode(enumValues, source, unknownValue: unknownValue); } const _$GreekEnumMap = { diff --git a/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart b/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart index 5ca37e32e..f114c16b4 100644 --- a/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart +++ b/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart @@ -74,24 +74,36 @@ Map _$DefaultValueToJson(DefaultValue instance) { return val; } -T _$enumDecode(Map enumValues, dynamic source) { +T _$enumDecode( + Map enumValues, + dynamic source, { + T unknownValue, +}) { if (source == null) { throw ArgumentError('A value must be provided. Supported values: ' '${enumValues.values.join(', ')}'); } - return enumValues.entries - .singleWhere((e) => e.value == source, - orElse: () => throw ArgumentError( - '`$source` is not one of the supported values: ' - '${enumValues.values.join(', ')}')) - .key; + + final value = enumValues.entries + .singleWhere((e) => e.value == source, orElse: () => null) + ?.key; + + if (value == null && unknownValue == null) { + throw ArgumentError('`$source` is not one of the supported values: ' + '${enumValues.values.join(', ')}'); + } + return value ?? unknownValue; } -T _$enumDecodeNullable(Map enumValues, dynamic source) { +T _$enumDecodeNullable( + Map enumValues, + dynamic source, { + T unknownValue, +}) { if (source == null) { return null; } - return _$enumDecode(enumValues, source); + return _$enumDecode(enumValues, source, unknownValue: unknownValue); } const _$GreekEnumMap = { diff --git a/json_serializable/test/integration/integration_test.dart b/json_serializable/test/integration/integration_test.dart index c99c7664a..6c6954971 100644 --- a/json_serializable/test/integration/integration_test.dart +++ b/json_serializable/test/integration/integration_test.dart @@ -82,7 +82,11 @@ void main() { final order = Order.fromJson({'category': 'not_discovered_yet'}); expect(order.items, isEmpty); expect(order.category, Category.notDiscoveredYet); - expect(order.statusCode, StatusCode.success); + expect( + order.statusCode, + StatusCode.success, + reason: 'success is the default on an unset value', + ); roundTripOrder(order); }); @@ -129,11 +133,28 @@ void main() { test('statusCode', () { final order = Order.fromJson( - {'category': 'not_discovered_yet', 'status_code': 404}); + {'category': 'not_discovered_yet', 'status_code': 404}, + ); expect(order.statusCode, StatusCode.notFound); roundTripOrder(order); }); + test('statusCode "500" - weird', () { + final order = Order.fromJson( + {'category': 'not_discovered_yet', 'status_code': '500'}, + ); + expect(order.statusCode, StatusCode.weird); + roundTripOrder(order); + }); + + test('statusCode `500` - unknown', () { + final order = Order.fromJson( + {'category': 'not_discovered_yet', 'status_code': 500}, + ); + expect(order.statusCode, StatusCode.unknown); + roundTripOrder(order); + }); + test('duration toJson', () { final order = Order(Category.notDiscoveredYet) ..statusCode = StatusCode.success diff --git a/json_serializable/test/integration/json_test_common.dart b/json_serializable/test/integration/json_test_common.dart index 6a5a6df82..295d6df85 100644 --- a/json_serializable/test/integration/json_test_common.dart +++ b/json_serializable/test/integration/json_test_common.dart @@ -23,8 +23,13 @@ enum StatusCode { success, @JsonValue(404) notFound, + + // Intentionally using a non-int value to validate heterogeneous + // type-inference. @JsonValue('500') weird, + + unknown, } Duration durationFromInt(int ms) => diff --git a/json_serializable/test/integration/json_test_example.dart b/json_serializable/test/integration/json_test_example.dart index a4dd9d379..911c4b11b 100644 --- a/json_serializable/test/integration/json_test_example.dart +++ b/json_serializable/test/integration/json_test_example.dart @@ -61,7 +61,11 @@ class Order { Uri homepage; @JsonKey( - name: 'status_code', defaultValue: StatusCode.success, nullable: true) + name: 'status_code', + defaultValue: StatusCode.success, + nullable: true, + unknownEnumValue: StatusCode.unknown, + ) StatusCode statusCode; @JsonKey(ignore: true) diff --git a/json_serializable/test/integration/json_test_example.g.dart b/json_serializable/test/integration/json_test_example.g.dart index 8faf12013..09f7f3dc9 100644 --- a/json_serializable/test/integration/json_test_example.g.dart +++ b/json_serializable/test/integration/json_test_example.g.dart @@ -47,24 +47,36 @@ Map _$PersonToJson(Person instance) => { ?.map((k, e) => MapEntry(_$CategoryEnumMap[k], e)), }; -T _$enumDecode(Map enumValues, dynamic source) { +T _$enumDecode( + Map enumValues, + dynamic source, { + T unknownValue, +}) { if (source == null) { throw ArgumentError('A value must be provided. Supported values: ' '${enumValues.values.join(', ')}'); } - return enumValues.entries - .singleWhere((e) => e.value == source, - orElse: () => throw ArgumentError( - '`$source` is not one of the supported values: ' - '${enumValues.values.join(', ')}')) - .key; + + final value = enumValues.entries + .singleWhere((e) => e.value == source, orElse: () => null) + ?.key; + + if (value == null && unknownValue == null) { + throw ArgumentError('`$source` is not one of the supported values: ' + '${enumValues.values.join(', ')}'); + } + return value ?? unknownValue; } -T _$enumDecodeNullable(Map enumValues, dynamic source) { +T _$enumDecodeNullable( + Map enumValues, + dynamic source, { + T unknownValue, +}) { if (source == null) { return null; } - return _$enumDecode(enumValues, source); + return _$enumDecode(enumValues, source, unknownValue: unknownValue); } const _$CategoryEnumMap = { @@ -97,9 +109,10 @@ Order _$OrderFromJson(Map json) { ) ..homepage = json['homepage'] == null ? null : Uri.parse(json['homepage'] as String) - ..statusCode = - _$enumDecodeNullable(_$StatusCodeEnumMap, json['status_code']) ?? - StatusCode.success; + ..statusCode = _$enumDecodeNullable( + _$StatusCodeEnumMap, json['status_code'], + unknownValue: StatusCode.unknown) ?? + StatusCode.success; } Map _$OrderToJson(Order instance) { @@ -127,6 +140,7 @@ const _$StatusCodeEnumMap = { StatusCode.success: 200, StatusCode.notFound: 404, StatusCode.weird: '500', + StatusCode.unknown: 'unknown', }; Item _$ItemFromJson(Map json) { diff --git a/json_serializable/test/integration/json_test_example.g_any_map.dart b/json_serializable/test/integration/json_test_example.g_any_map.dart index a357963a3..fe5f1422a 100644 --- a/json_serializable/test/integration/json_test_example.g_any_map.dart +++ b/json_serializable/test/integration/json_test_example.g_any_map.dart @@ -65,7 +65,11 @@ class Order { Uri homepage; @JsonKey( - name: 'status_code', defaultValue: StatusCode.success, nullable: true) + name: 'status_code', + defaultValue: StatusCode.success, + nullable: true, + unknownEnumValue: StatusCode.unknown, + ) StatusCode statusCode; @JsonKey(ignore: true) diff --git a/json_serializable/test/integration/json_test_example.g_any_map.g.dart b/json_serializable/test/integration/json_test_example.g_any_map.g.dart index 498525d4b..79bd46a2d 100644 --- a/json_serializable/test/integration/json_test_example.g_any_map.g.dart +++ b/json_serializable/test/integration/json_test_example.g_any_map.g.dart @@ -53,24 +53,36 @@ Map _$PersonToJson(Person instance) => { ?.map((k, e) => MapEntry(_$CategoryEnumMap[k], e)), }; -T _$enumDecode(Map enumValues, dynamic source) { +T _$enumDecode( + Map enumValues, + dynamic source, { + T unknownValue, +}) { if (source == null) { throw ArgumentError('A value must be provided. Supported values: ' '${enumValues.values.join(', ')}'); } - return enumValues.entries - .singleWhere((e) => e.value == source, - orElse: () => throw ArgumentError( - '`$source` is not one of the supported values: ' - '${enumValues.values.join(', ')}')) - .key; + + final value = enumValues.entries + .singleWhere((e) => e.value == source, orElse: () => null) + ?.key; + + if (value == null && unknownValue == null) { + throw ArgumentError('`$source` is not one of the supported values: ' + '${enumValues.values.join(', ')}'); + } + return value ?? unknownValue; } -T _$enumDecodeNullable(Map enumValues, dynamic source) { +T _$enumDecodeNullable( + Map enumValues, + dynamic source, { + T unknownValue, +}) { if (source == null) { return null; } - return _$enumDecode(enumValues, source); + return _$enumDecode(enumValues, source, unknownValue: unknownValue); } const _$CategoryEnumMap = { @@ -107,9 +119,10 @@ Order _$OrderFromJson(Map json) { ) ..homepage = json['homepage'] == null ? null : Uri.parse(json['homepage'] as String) - ..statusCode = - _$enumDecodeNullable(_$StatusCodeEnumMap, json['status_code']) ?? - StatusCode.success; + ..statusCode = _$enumDecodeNullable( + _$StatusCodeEnumMap, json['status_code'], + unknownValue: StatusCode.unknown) ?? + StatusCode.success; } Map _$OrderToJson(Order instance) { @@ -137,6 +150,7 @@ const _$StatusCodeEnumMap = { StatusCode.success: 200, StatusCode.notFound: 404, StatusCode.weird: '500', + StatusCode.unknown: 'unknown', }; Item _$ItemFromJson(Map json) { diff --git a/json_serializable/test/integration/json_test_example.g_non_nullable.dart b/json_serializable/test/integration/json_test_example.g_non_nullable.dart index ec073990d..500ba60ee 100644 --- a/json_serializable/test/integration/json_test_example.g_non_nullable.dart +++ b/json_serializable/test/integration/json_test_example.g_non_nullable.dart @@ -65,7 +65,11 @@ class Order { Uri homepage; @JsonKey( - name: 'status_code', defaultValue: StatusCode.success, nullable: true) + name: 'status_code', + defaultValue: StatusCode.success, + nullable: true, + unknownEnumValue: StatusCode.unknown, + ) StatusCode statusCode; @JsonKey(ignore: true) diff --git a/json_serializable/test/integration/json_test_example.g_non_nullable.g.dart b/json_serializable/test/integration/json_test_example.g_non_nullable.g.dart index 3be8a03ee..ff4978e3b 100644 --- a/json_serializable/test/integration/json_test_example.g_non_nullable.g.dart +++ b/json_serializable/test/integration/json_test_example.g_non_nullable.g.dart @@ -40,17 +40,25 @@ Map _$PersonToJson(Person instance) => { .map((k, e) => MapEntry(_$CategoryEnumMap[k], e)), }; -T _$enumDecode(Map enumValues, dynamic source) { +T _$enumDecode( + Map enumValues, + dynamic source, { + T unknownValue, +}) { if (source == null) { throw ArgumentError('A value must be provided. Supported values: ' '${enumValues.values.join(', ')}'); } - return enumValues.entries - .singleWhere((e) => e.value == source, - orElse: () => throw ArgumentError( - '`$source` is not one of the supported values: ' - '${enumValues.values.join(', ')}')) - .key; + + final value = enumValues.entries + .singleWhere((e) => e.value == source, orElse: () => null) + ?.key; + + if (value == null && unknownValue == null) { + throw ArgumentError('`$source` is not one of the supported values: ' + '${enumValues.values.join(', ')}'); + } + return value ?? unknownValue; } const _$CategoryEnumMap = { @@ -78,9 +86,10 @@ Order _$OrderFromJson(Map json) { (k, e) => MapEntry(k, Platform.fromJson(e as String)), ) ..homepage = Uri.parse(json['homepage'] as String) - ..statusCode = - _$enumDecodeNullable(_$StatusCodeEnumMap, json['status_code']) ?? - StatusCode.success; + ..statusCode = _$enumDecodeNullable( + _$StatusCodeEnumMap, json['status_code'], + unknownValue: StatusCode.unknown) ?? + StatusCode.success; } Map _$OrderToJson(Order instance) => { @@ -95,17 +104,22 @@ Map _$OrderToJson(Order instance) => { 'status_code': _$StatusCodeEnumMap[instance.statusCode], }; -T _$enumDecodeNullable(Map enumValues, dynamic source) { +T _$enumDecodeNullable( + Map enumValues, + dynamic source, { + T unknownValue, +}) { if (source == null) { return null; } - return _$enumDecode(enumValues, source); + return _$enumDecode(enumValues, source, unknownValue: unknownValue); } const _$StatusCodeEnumMap = { StatusCode.success: 200, StatusCode.notFound: 404, StatusCode.weird: '500', + StatusCode.unknown: 'unknown', }; Item _$ItemFromJson(Map json) { diff --git a/json_serializable/test/json_serializable_test.dart b/json_serializable/test/json_serializable_test.dart index b964f6815..92f8ef5a3 100644 --- a/json_serializable/test/json_serializable_test.dart +++ b/json_serializable/test/json_serializable_test.dart @@ -91,6 +91,9 @@ const _expectedAnnotatedTests = [ 'ToJsonNullableFalseIncludeIfNullFalse', 'TypedConvertMethods', 'UnknownCtorParamType', + 'UnknownEnumValue', + 'UnknownEnumValueNotEnumValue', + 'UnknownEnumValueNotEnumField', 'UnknownFieldType', 'UnknownFieldTypeToJsonOnly', 'UnknownFieldTypeWithConvert', diff --git a/json_serializable/test/src/_json_serializable_test_input.dart b/json_serializable/test/src/_json_serializable_test_input.dart index ca7353e4a..0e0a658dd 100644 --- a/json_serializable/test/src/_json_serializable_test_input.dart +++ b/json_serializable/test/src/_json_serializable_test_input.dart @@ -27,6 +27,8 @@ part 'setter_test_input.dart'; part 'to_from_json_test_input.dart'; +part 'unknown_enum_value_test_input.dart'; + part 'unknown_type_test_input.dart'; @ShouldThrow('Generator cannot target `theAnswer`.', diff --git a/json_serializable/test/src/unknown_enum_value_test_input.dart b/json_serializable/test/src/unknown_enum_value_test_input.dart new file mode 100644 index 000000000..221e7f819 --- /dev/null +++ b/json_serializable/test/src/unknown_enum_value_test_input.dart @@ -0,0 +1,85 @@ +part of '_json_serializable_test_input.dart'; + +@ShouldGenerate( + r''' +UnknownEnumValue _$UnknownEnumValueFromJson(Map json) { + return UnknownEnumValue() + ..value = _$enumDecodeNullable( + _$UnknownEnumValueItemsEnumMap, json['value'], + unknownValue: UnknownEnumValueItems.vUnknown) ?? + UnknownEnumValueItems.vNull; +} + +T _$enumDecode( + Map enumValues, + dynamic source, { + T unknownValue, +}) { + if (source == null) { + throw ArgumentError('A value must be provided. Supported values: ' + '${enumValues.values.join(', ')}'); + } + + final value = enumValues.entries + .singleWhere((e) => e.value == source, orElse: () => null) + ?.key; + + if (value == null && unknownValue == null) { + throw ArgumentError('`$source` is not one of the supported values: ' + '${enumValues.values.join(', ')}'); + } + return value ?? unknownValue; +} + +T _$enumDecodeNullable( + Map enumValues, + dynamic source, { + T unknownValue, +}) { + if (source == null) { + return null; + } + return _$enumDecode(enumValues, source, unknownValue: unknownValue); +} + +const _$UnknownEnumValueItemsEnumMap = { + UnknownEnumValueItems.v0: 'v0', + UnknownEnumValueItems.v1: 'v1', + UnknownEnumValueItems.v2: 'v2', + UnknownEnumValueItems.vUnknown: 'vUnknown', + UnknownEnumValueItems.vNull: 'vNull', +}; +''', +) +@JsonSerializable( + createToJson: false, +) +class UnknownEnumValue { + @JsonKey( + defaultValue: UnknownEnumValueItems.vNull, + unknownEnumValue: UnknownEnumValueItems.vUnknown, + ) + UnknownEnumValueItems value; +} + +enum UnknownEnumValueItems { v0, v1, v2, vUnknown, vNull } + +@ShouldThrow( + 'Error with `@JsonKey` on `value`. The value provided ' + 'for `unknownEnumValue` must be a matching enum.', +) +@JsonSerializable() +class UnknownEnumValueNotEnumValue { + @JsonKey(unknownEnumValue: 'not enum value') + UnknownEnumValueItems value; +} + +@ShouldThrow( + 'Error with `@JsonKey` on `value`. `unknownEnumValue` can only be set on ' + 'fields of type enum.', +) +@JsonSerializable() +class UnknownEnumValueNotEnumField { + @JsonKey(unknownEnumValue: UnknownEnumValueItems.vUnknown) + int value; +} From f6463597713f06a54a8514bbd2e6849a9d205f2e Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 31 Jul 2019 10:57:48 -0700 Subject: [PATCH 159/569] Update min SDK to 2.3, use UI-as-code collection features (#518) Updated all packages to `>=2.3.0` so we could keep merging tests across all of them. Used ui-as-code features where it made sense. Updated Travis testing accordingly --- .travis.yml | 20 ++++++++-------- _test_yaml/mono_pkg.yaml | 4 ++-- _test_yaml/pubspec.yaml | 2 +- checked_yaml/changelog.md | 4 ++++ checked_yaml/mono_pkg.yaml | 4 ++-- checked_yaml/pubspec.yaml | 2 +- example/mono_pkg.yaml | 4 ++-- example/pubspec.yaml | 2 +- json_annotation/CHANGELOG.md | 1 + json_annotation/lib/src/checked_helpers.dart | 23 ++++++------------- json_annotation/mono_pkg.yaml | 2 +- json_annotation/pubspec.yaml | 2 +- json_serializable/CHANGELOG.md | 1 + json_serializable/lib/src/json_key_utils.dart | 23 ++++++++++++++----- .../lib/src/type_helpers/enum_helper.dart | 9 +++----- json_serializable/mono_pkg.yaml | 4 ++-- json_serializable/pubspec.yaml | 2 +- json_serializable/tool/doc_builder.dart | 22 ++++++++---------- json_serializable/tool/test_builder.dart | 12 +++++----- 19 files changed, 73 insertions(+), 70 deletions(-) diff --git a/.travis.yml b/.travis.yml index b432f7c24..6fa758bf0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,18 +17,18 @@ jobs: env: PKGS="_test_yaml checked_yaml example json_annotation json_serializable" script: ./tool/travis.sh dartfmt dartanalyzer_0 - stage: analyzer_and_format - name: "SDK: 2.2.0; PKGS: _test_yaml, checked_yaml, json_serializable; TASKS: `dartanalyzer --fatal-warnings .`" - dart: "2.2.0" + name: "SDK: 2.3.0; PKGS: _test_yaml, checked_yaml, json_serializable; TASKS: `dartanalyzer --fatal-warnings .`" + dart: "2.3.0" env: PKGS="_test_yaml checked_yaml json_serializable" script: ./tool/travis.sh dartanalyzer_1 - stage: analyzer_and_format - name: "SDK: 2.2.0; PKGS: example, json_annotation; TASKS: [`dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-warnings .`]" - dart: "2.2.0" + name: "SDK: 2.3.0; PKGS: example, json_annotation; TASKS: [`dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-warnings .`]" + dart: "2.3.0" env: PKGS="example json_annotation" script: ./tool/travis.sh dartfmt dartanalyzer_1 - stage: unit_test - name: "SDK: 2.2.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test`" - dart: "2.2.0" + name: "SDK: 2.3.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test`" + dart: "2.3.0" env: PKGS="_test_yaml checked_yaml example json_serializable" script: ./tool/travis.sh test_0 - stage: unit_test @@ -37,8 +37,8 @@ jobs: env: PKGS="_test_yaml checked_yaml example json_serializable" script: ./tool/travis.sh test_0 - stage: unit_test - name: "SDK: 2.2.0; PKG: json_serializable; TASKS: `pub run build_runner test --delete-conflicting-outputs -- -p chrome`" - dart: "2.2.0" + name: "SDK: 2.3.0; PKG: json_serializable; TASKS: `pub run build_runner test --delete-conflicting-outputs -- -p chrome`" + dart: "2.3.0" env: PKGS="json_serializable" script: ./tool/travis.sh command - stage: unit_test @@ -47,8 +47,8 @@ jobs: env: PKGS="json_serializable" script: ./tool/travis.sh command - stage: ensure_build - name: "SDK: 2.2.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`" - dart: "2.2.0" + name: "SDK: 2.3.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`" + dart: "2.3.0" env: PKGS="_test_yaml checked_yaml example json_serializable" script: ./tool/travis.sh test_1 - stage: ensure_build diff --git a/_test_yaml/mono_pkg.yaml b/_test_yaml/mono_pkg.yaml index 3a90eb477..6b257bd39 100644 --- a/_test_yaml/mono_pkg.yaml +++ b/_test_yaml/mono_pkg.yaml @@ -1,6 +1,6 @@ # See https://github.com/dart-lang/mono_repo for details dart: -- 2.2.0 +- 2.3.0 - dev stages: @@ -11,7 +11,7 @@ stages: dart: [dev] - group: - dartanalyzer: --fatal-warnings . - dart: [2.2.0] + dart: [2.3.0] - unit_test: - test - ensure_build: diff --git a/_test_yaml/pubspec.yaml b/_test_yaml/pubspec.yaml index 6877c0147..0c9db1d5f 100644 --- a/_test_yaml/pubspec.yaml +++ b/_test_yaml/pubspec.yaml @@ -2,7 +2,7 @@ name: _test_yaml publish_to: none environment: - sdk: '>=2.2.0 <3.0.0' + sdk: '>=2.3.0 <3.0.0' dev_dependencies: build_runner: ^1.0.0 diff --git a/checked_yaml/changelog.md b/checked_yaml/changelog.md index 12d709eef..923a95e61 100644 --- a/checked_yaml/changelog.md +++ b/checked_yaml/changelog.md @@ -1,3 +1,7 @@ +## 1.0.2 + +- Require at least Dart `2.3.0`. + ## 1.0.1 - Fix readme. diff --git a/checked_yaml/mono_pkg.yaml b/checked_yaml/mono_pkg.yaml index aa71047e9..1db1b960d 100644 --- a/checked_yaml/mono_pkg.yaml +++ b/checked_yaml/mono_pkg.yaml @@ -1,6 +1,6 @@ # See https://github.com/dart-lang/mono_repo for details dart: -- 2.2.0 +- 2.3.0 - dev stages: @@ -11,7 +11,7 @@ stages: dart: [dev] - group: - dartanalyzer: --fatal-warnings . - dart: [2.2.0] + dart: [2.3.0] - unit_test: - test diff --git a/checked_yaml/pubspec.yaml b/checked_yaml/pubspec.yaml index cb3e8d19f..57128c1ae 100644 --- a/checked_yaml/pubspec.yaml +++ b/checked_yaml/pubspec.yaml @@ -6,7 +6,7 @@ description: >- package:json_serializable and package:yaml. homepage: https://github.com/dart-lang/json_serializable environment: - sdk: '>=2.2.0 <3.0.0' + sdk: '>=2.3.0 <3.0.0' dependencies: json_annotation: ^2.2.0 diff --git a/example/mono_pkg.yaml b/example/mono_pkg.yaml index e43ba1842..a25b7e82b 100644 --- a/example/mono_pkg.yaml +++ b/example/mono_pkg.yaml @@ -1,6 +1,6 @@ # See https://github.com/dart-lang/mono_repo for details dart: -- 2.2.0 +- 2.3.0 - dev stages: @@ -12,7 +12,7 @@ stages: - group: - dartfmt - dartanalyzer: --fatal-warnings . - dart: [2.2.0] + dart: [2.3.0] - unit_test: - test - ensure_build: diff --git a/example/pubspec.yaml b/example/pubspec.yaml index b0f9ac38d..b8ca9ac19 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -2,7 +2,7 @@ name: example author: Dart Team environment: - sdk: '>=2.2.0 <3.0.0' + sdk: '>=2.3.0 <3.0.0' dependencies: json_annotation: ^2.4.0 diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index 4a7b8bb71..f501de917 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -7,6 +7,7 @@ `JsonKey`. - Added `JsonSerializable.ignoreUnannotated`. - Added `JsonKey.unknownEnumValue`. +- Require at least Dart `2.3.0`. ## 2.4.0 diff --git a/json_annotation/lib/src/checked_helpers.dart b/json_annotation/lib/src/checked_helpers.dart index 8c91c49f8..f24fd3197 100644 --- a/json_annotation/lib/src/checked_helpers.dart +++ b/json_annotation/lib/src/checked_helpers.dart @@ -121,20 +121,11 @@ class CheckedFromJsonException implements Exception { } @override - String toString() { - final lines = ['CheckedFromJsonException']; - - if (_className != null) { - lines.add('Could not create `$_className`.'); - } - if (key != null) { - lines.add('There is a problem with "$key".'); - } - if (message != null) { - lines.add(message); - } else if (innerError != null) { - lines.add(innerError.toString()); - } - return lines.join('\n'); - } + String toString() => [ + 'CheckedFromJsonException', + if (_className != null) 'Could not create `$_className`.', + if (key != null) 'There is a problem with "$key".', + if (message != null) message, + if (message == null && innerError != null) innerError.toString(), + ].join('\n'); } diff --git a/json_annotation/mono_pkg.yaml b/json_annotation/mono_pkg.yaml index 78a5eb005..6da78e459 100644 --- a/json_annotation/mono_pkg.yaml +++ b/json_annotation/mono_pkg.yaml @@ -8,4 +8,4 @@ stages: - group: - dartfmt - dartanalyzer: --fatal-warnings . - dart: [2.2.0] + dart: [2.3.0] diff --git a/json_annotation/pubspec.yaml b/json_annotation/pubspec.yaml index 55b88c500..35960e378 100644 --- a/json_annotation/pubspec.yaml +++ b/json_annotation/pubspec.yaml @@ -6,7 +6,7 @@ description: >- homepage: https://github.com/dart-lang/json_serializable author: Dart Team environment: - sdk: '>=2.2.0 <3.0.0' + sdk: '>=2.3.0 <3.0.0' # When changing JsonSerializable class. # dev_dependencies: diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 8cddbdd12..6100efbeb 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -4,6 +4,7 @@ - Added support for `JsonSerializable.ignoreUnannotated`. - Added support for `JsonKey.unknownEnumValue`. - Small change to how `enum` support code is generated. +- Require at least Dart `2.3.0`. ## 3.1.0 diff --git a/json_serializable/lib/src/json_key_utils.dart b/json_serializable/lib/src/json_key_utils.dart index dbfdc523f..024aa7f30 100644 --- a/json_serializable/lib/src/json_key_utils.dart +++ b/json_serializable/lib/src/json_key_utils.dart @@ -82,13 +82,24 @@ JsonKey _from(FieldElement element, JsonSerializable classAnnotation) { if (literal is num || literal is String || literal is bool) { return literal; } else if (literal is List) { - return literal - .map((e) => literalForObject(e, typeInformation.followedBy(['List']))) - .toList(); + return [ + for (var e in literal) + literalForObject(e, [ + ...typeInformation, + 'List', + ]) + ]; } else if (literal is Map) { - final mapThings = typeInformation.followedBy(['Map']); - return literal.map((k, v) => MapEntry( - literalForObject(k, mapThings), literalForObject(v, mapThings))); + final mapTypeInformation = [ + ...typeInformation, + 'Map', + ]; + return literal.map( + (k, v) => MapEntry( + literalForObject(k, mapTypeInformation), + literalForObject(v, mapTypeInformation), + ), + ); } badType = typeInformation.followedBy(['$dartObject']).join(' > '); diff --git a/json_serializable/lib/src/type_helpers/enum_helper.dart b/json_serializable/lib/src/type_helpers/enum_helper.dart index 8e83c138a..5a1f7b4f9 100644 --- a/json_serializable/lib/src/type_helpers/enum_helper.dart +++ b/json_serializable/lib/src/type_helpers/enum_helper.dart @@ -54,17 +54,14 @@ class EnumHelper extends TypeHelper { final functionName = context.nullable ? r'_$enumDecodeNullable' : r'_$enumDecode'; + final jsonKey = jsonKeyForField(context.fieldElement, context.config); final args = [ _constMapName(targetType), expression, + if (jsonKey.unknownEnumValue != null) + 'unknownValue: ${jsonKey.unknownEnumValue}', ]; - final jsonKey = jsonKeyForField(context.fieldElement, context.config); - // TODO(kevmoo): use collection expressions once min-SDK is >= 2.3.0 - if (jsonKey.unknownEnumValue != null) { - args.add('unknownValue: ${jsonKey.unknownEnumValue}'); - } - return '$functionName(${args.join(', ')})'; } } diff --git a/json_serializable/mono_pkg.yaml b/json_serializable/mono_pkg.yaml index 4ac6ea0d5..d32dde025 100644 --- a/json_serializable/mono_pkg.yaml +++ b/json_serializable/mono_pkg.yaml @@ -1,6 +1,6 @@ # See https://github.com/dart-lang/mono_repo for details dart: -- 2.2.0 +- 2.3.0 - dev stages: @@ -11,7 +11,7 @@ stages: dart: [dev] - group: - dartanalyzer: --fatal-warnings . - dart: [2.2.0] + dart: [2.3.0] - unit_test: - test - command: pub run build_runner test --delete-conflicting-outputs -- -p chrome diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 95b0d1a0d..c90e3df58 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -6,7 +6,7 @@ description: >- Dart classes. homepage: https://github.com/dart-lang/json_serializable environment: - sdk: '>=2.2.0 <3.0.0' + sdk: '>=2.3.0 <3.0.0' dependencies: analyzer: '>=0.33.3 <0.38.0' diff --git a/json_serializable/tool/doc_builder.dart b/json_serializable/tool/doc_builder.dart index acceff11f..37e5de5db 100644 --- a/json_serializable/tool/doc_builder.dart +++ b/json_serializable/tool/doc_builder.dart @@ -50,20 +50,18 @@ class _DocBuilder extends Builder { final buffer = StringBuffer(); - final rows = >[]; - - rows.add(['`build.yaml` key', _jsonSerializable, _jsonKey]); - rows.add(['-', '-', '-']); - final sortedValues = descriptionMap.values.toList()..sort(); - for (var info in sortedValues) { - rows.add([ - info.buildKey, - info.classAnnotationName, - info.fieldAnnotationName, - ]); - } + final rows = >[ + ['`build.yaml` key', _jsonSerializable, _jsonKey], + ['-', '-', '-'], + for (var info in sortedValues) + [ + info.buildKey, + info.classAnnotationName, + info.fieldAnnotationName, + ], + ]; final longest = List.generate(rows.first.length, (_) => 0); for (var row in rows) { diff --git a/json_serializable/tool/test_builder.dart b/json_serializable/tool/test_builder.dart index f596cf6b0..c2bff9285 100644 --- a/json_serializable/tool/test_builder.dart +++ b/json_serializable/tool/test_builder.dart @@ -93,12 +93,12 @@ class _SmartBuilder implements Builder { if (baseName == _kitchenSinkBaseName) { final newId = buildStep.inputId.changeExtension('.factories.dart'); - final lines = []..addAll( - factories.entries.map((e) => "import '${e.key}' as ${e.value};")); - - lines.add('const factories = ['); - lines.addAll(factories.values.map((e) => '$e.factory,')); - lines.add('];'); + final lines = [ + ...factories.entries.map((e) => "import '${e.key}' as ${e.value};"), + 'const factories = [', + ...factories.values.map((e) => '$e.factory,'), + '];', + ]; await buildStep.writeAsString(newId, _formatter.format(lines.join('\n'))); } From 8ed8bee43d989413b26ac895240a2b1c9bda042d Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 7 Aug 2019 16:18:23 -0700 Subject: [PATCH 160/569] json_annotation: prepare to release v3 (#524) --- json_annotation/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/json_annotation/pubspec.yaml b/json_annotation/pubspec.yaml index 35960e378..e4354d00d 100644 --- a/json_annotation/pubspec.yaml +++ b/json_annotation/pubspec.yaml @@ -1,5 +1,5 @@ name: json_annotation -version: 3.0.0-dev +version: 3.0.0 description: >- Classes and helper functions that support JSON code generation via the `json_serializable` package. From 3ccadec220c90182c9455445954e6797e88d7fd1 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 7 Aug 2019 16:39:11 -0700 Subject: [PATCH 161/569] checked_yaml: prepare next release, support latest json_annotation (#525) --- checked_yaml/changelog.md | 1 + checked_yaml/pubspec.yaml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/checked_yaml/changelog.md b/checked_yaml/changelog.md index 923a95e61..9b707b82f 100644 --- a/checked_yaml/changelog.md +++ b/checked_yaml/changelog.md @@ -1,6 +1,7 @@ ## 1.0.2 - Require at least Dart `2.3.0`. +- Support the latest `package:json_annotation`. ## 1.0.1 diff --git a/checked_yaml/pubspec.yaml b/checked_yaml/pubspec.yaml index 57128c1ae..1b6fe1403 100644 --- a/checked_yaml/pubspec.yaml +++ b/checked_yaml/pubspec.yaml @@ -9,7 +9,7 @@ environment: sdk: '>=2.3.0 <3.0.0' dependencies: - json_annotation: ^2.2.0 + json_annotation: '>=2.2.0 <4.0.0' source_span: ^1.0.0 yaml: ^2.1.13 From 895c5f7cac059b464a75cad1b2d592dbf52d6513 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 7 Aug 2019 16:40:44 -0700 Subject: [PATCH 162/569] checked_yaml: bump version to 1.0.2 --- checked_yaml/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/checked_yaml/pubspec.yaml b/checked_yaml/pubspec.yaml index 1b6fe1403..a962f6e48 100644 --- a/checked_yaml/pubspec.yaml +++ b/checked_yaml/pubspec.yaml @@ -1,5 +1,5 @@ name: checked_yaml -version: 1.0.2-dev +version: 1.0.2 author: Dart Team description: >- Generate more helpful exceptions when decoding YAML documents using From d50bcde044a2e14d2ad6394a1069dd252bbbe437 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 8 Aug 2019 18:58:57 -0700 Subject: [PATCH 163/569] prepare to release 3.2.0 (#526) --- json_serializable/pubspec.yaml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index c90e3df58..467240d0a 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 3.2.0-dev +version: 3.2.0 author: Dart Team description: >- Automatically generate code for converting to and from JSON by annotating @@ -33,7 +33,3 @@ dev_dependencies: source_gen_test: ^0.1.0 test: ^1.6.0 yaml: ^2.1.13 - -dependency_overrides: - json_annotation: - path: ../json_annotation From 7640bb93fbcd5c3c90f5d27319790e7c2de2066d Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 8 Aug 2019 21:45:48 -0700 Subject: [PATCH 164/569] example: bump dependencies (#527) --- example/README.md | 4 ++-- example/pubspec.yaml | 4 ++-- example/test/readme_test.dart | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/example/README.md b/example/README.md index 6e5e5b38d..96ca7440e 100644 --- a/example/README.md +++ b/example/README.md @@ -5,11 +5,11 @@ dependencies to your `pubspec.yaml`. ```yaml dependencies: - json_annotation: ^2.4.0 + json_annotation: ^3.0.0 dev_dependencies: build_runner: ^1.0.0 - json_serializable: ^3.0.0 + json_serializable: ^3.2.0 ``` Annotate your code with classes defined in diff --git a/example/pubspec.yaml b/example/pubspec.yaml index b8ca9ac19..ba9f834e5 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -5,11 +5,11 @@ environment: sdk: '>=2.3.0 <3.0.0' dependencies: - json_annotation: ^2.4.0 + json_annotation: ^3.0.0 dev_dependencies: build_runner: ^1.0.0 - json_serializable: ^3.0.0 + json_serializable: ^3.2.0 # Used by tests. Not required to use `json_serializable`. build_verify: ^1.0.0 diff --git a/example/test/readme_test.dart b/example/test/readme_test.dart index 5b705c535..bf3e9729b 100644 --- a/example/test/readme_test.dart +++ b/example/test/readme_test.dart @@ -20,9 +20,9 @@ void _expect(String fileName) { final _pubspecContent = r''' dependencies: - json_annotation: ^2.4.0 + json_annotation: ^3.0.0 dev_dependencies: build_runner: ^1.0.0 - json_serializable: ^3.0.0 + json_serializable: ^3.2.0 '''; From 317ad242e5bf8821b5eed7f95faac076d50115ba Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 20 Aug 2019 09:46:26 -0700 Subject: [PATCH 165/569] Ignore deprecated pkg:analyzer API usage (#532) Follow-up issue: #531 --- json_serializable/lib/src/type_helper_ctx.dart | 10 ++++++++-- .../lib/src/type_helpers/convert_helper.dart | 2 ++ .../lib/src/type_helpers/json_converter_helper.dart | 2 ++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/json_serializable/lib/src/type_helper_ctx.dart b/json_serializable/lib/src/type_helper_ctx.dart index c2a64d6d5..42a4c3a6c 100644 --- a/json_serializable/lib/src/type_helper_ctx.dart +++ b/json_serializable/lib/src/type_helper_ctx.dart @@ -127,7 +127,10 @@ ConvertData _convertData(DartObject obj, FieldElement element, bool isFrom) { // We keep things simple in this case. We rely on inferred type arguments // to the `fromJson` function. // TODO: consider adding error checking here if there is confusion. - } else if (!returnType.isAssignableTo(element.type)) { + } else if + // TODO: dart-lang/json_serializable#531 - fix deprecated API usage + // ignore: deprecated_member_use + (!returnType.isAssignableTo(element.type)) { throwUnsupported( element, 'The `$paramName` function `${executableElement.name}` return type ' @@ -138,7 +141,10 @@ ConvertData _convertData(DartObject obj, FieldElement element, bool isFrom) { // We keep things simple in this case. We rely on inferred type arguments // to the `fromJson` function. // TODO: consider adding error checking here if there is confusion. - } else if (!element.type.isAssignableTo(argType)) { + } else if + // TODO: dart-lang/json_serializable#531 - fix deprecated API usage + // ignore: deprecated_member_use + (!element.type.isAssignableTo(argType)) { throwUnsupported( element, 'The `$paramName` function `${executableElement.name}` argument type ' diff --git a/json_serializable/lib/src/type_helpers/convert_helper.dart b/json_serializable/lib/src/type_helpers/convert_helper.dart index b281161d1..c2ccd1c5c 100644 --- a/json_serializable/lib/src/type_helpers/convert_helper.dart +++ b/json_serializable/lib/src/type_helpers/convert_helper.dart @@ -37,6 +37,8 @@ class ConvertHelper extends TypeHelper { logFieldWithConversionFunction(context.fieldElement); assert(toJsonData.paramType is TypeParameterType || + // TODO: dart-lang/json_serializable#531 - fix deprecated API usage + // ignore: deprecated_member_use targetType.isAssignableTo(toJsonData.paramType)); return '${toJsonData.name}($expression)'; } diff --git a/json_serializable/lib/src/type_helpers/json_converter_helper.dart b/json_serializable/lib/src/type_helpers/json_converter_helper.dart index 436596ba2..e6da3af97 100644 --- a/json_serializable/lib/src/type_helpers/json_converter_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_converter_helper.dart @@ -156,6 +156,8 @@ _ConverterMatch _compatibleMatch( final fieldType = jsonConverterSuper.typeArguments[0]; + // TODO: dart-lang/json_serializable#531 - fix deprecated API usage + // ignore: deprecated_member_use if (fieldType.isEquivalentTo(targetType)) { return _ConverterMatch( annotation, constantValue, jsonConverterSuper.typeArguments[1], null); From d11aa2212d8d148ee80c78005f2bcd770168a27b Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 21 Aug 2019 15:56:00 -0700 Subject: [PATCH 166/569] support latest pkg:analyzer, prepare to release 3.2.1 (#534) Note: doing a cast because `enclosingElement` is now `Element` as of pkg:analyzer v0.38.0 --- json_serializable/CHANGELOG.md | 4 ++++ json_serializable/lib/src/field_helpers.dart | 10 ++++++++-- json_serializable/pubspec.yaml | 4 ++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 6100efbeb..e0ffeadd0 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,7 @@ +## 3.2.1 + +* Support `package:analyzer` `>=0.33.3 <0.39.0` + ## 3.2.0 - Require `package:json_annotation` `^3.0.0`. diff --git a/json_serializable/lib/src/field_helpers.dart b/json_serializable/lib/src/field_helpers.dart index fe18ef38b..f80bb7bf0 100644 --- a/json_serializable/lib/src/field_helpers.dart +++ b/json_serializable/lib/src/field_helpers.dart @@ -37,7 +37,10 @@ class _FieldSet implements Comparable<_FieldSet> { int compareTo(_FieldSet other) => _sortByLocation(sortField, other.sortField); static int _sortByLocation(FieldElement a, FieldElement b) { - final checkerA = TypeChecker.fromStatic(a.enclosingElement.type); + final checkerA = TypeChecker.fromStatic( + // TODO: remove `ignore` when min pkg:analyzer >= 0.38.0 + // ignore: unnecessary_cast + (a.enclosingElement as ClassElement).type); if (!checkerA.isExactly(b.enclosingElement)) { // in this case, you want to prioritize the enclosingElement that is more @@ -47,7 +50,10 @@ class _FieldSet implements Comparable<_FieldSet> { return -1; } - final checkerB = TypeChecker.fromStatic(b.enclosingElement.type); + final checkerB = TypeChecker.fromStatic( + // TODO: remove `ignore` when min pkg:analyzer >= 0.38.0 + // ignore: unnecessary_cast + (b.enclosingElement as ClassElement).type); if (checkerB.isAssignableFrom(a.enclosingElement)) { return 1; diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 467240d0a..5abca09ff 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 3.2.0 +version: 3.2.1 author: Dart Team description: >- Automatically generate code for converting to and from JSON by annotating @@ -9,7 +9,7 @@ environment: sdk: '>=2.3.0 <3.0.0' dependencies: - analyzer: '>=0.33.3 <0.38.0' + analyzer: '>=0.33.3 <0.39.0' build: '>=0.12.6 <2.0.0' build_config: '>=0.2.6 <0.5.0' From 6d5948508b65d8bec873b3fc213c17c884546156 Mon Sep 17 00:00:00 2001 From: Todd Volkert Date: Thu, 22 Aug 2019 09:37:30 -0700 Subject: [PATCH 167/569] Support JsonConverter annotations on property getters (#535) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes a bug whereby the following code: ```dart @JsonSerializable(createFactory: false) class JsonConverterOnGetter { @JsonKey() @NeedsConversionConverter() NeedsConversion get annotatedGetter => NeedsConversion(); } ``` would yield the following error: ``` Could not generate `toJson` code for `annotatedGetter`. None of the provided `TypeHelper` instances support the defined type. package::: ╷ ... │ NeedsConversion get annotatedGetter => NeedsConversion(); │ ^^^^^^^^^^^^^^^ ╵ ``` --- json_serializable/CHANGELOG.md | 4 +++ .../type_helpers/json_converter_helper.dart | 7 ++++- json_serializable/pubspec.yaml | 2 +- .../test/json_serializable_test.dart | 1 + .../test/src/json_converter_test_input.dart | 28 +++++++++++++++++++ 5 files changed, 40 insertions(+), 2 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index e0ffeadd0..9aab8820e 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,7 @@ +## 3.2.2 + +* Support `JsonConverter` annotations on property getters + ## 3.2.1 * Support `package:analyzer` `>=0.33.3 <0.39.0` diff --git a/json_serializable/lib/src/type_helpers/json_converter_helper.dart b/json_serializable/lib/src/type_helpers/json_converter_helper.dart index e6da3af97..6ba902b80 100644 --- a/json_serializable/lib/src/type_helpers/json_converter_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_converter_helper.dart @@ -76,7 +76,12 @@ _JsonConvertData _typeConverter(DartType targetType, TypeHelperContext ctx) { var matchingAnnotations = converterMatches(ctx.fieldElement.metadata); if (matchingAnnotations.isEmpty) { - matchingAnnotations = converterMatches(ctx.classElement.metadata); + matchingAnnotations = + converterMatches(ctx.fieldElement.getter?.metadata ?? []); + + if (matchingAnnotations.isEmpty) { + matchingAnnotations = converterMatches(ctx.classElement.metadata); + } } return _typeConverterFrom(matchingAnnotations, targetType); diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 5abca09ff..bc991f944 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 3.2.1 +version: 3.2.2 author: Dart Team description: >- Automatically generate code for converting to and from JSON by annotating diff --git a/json_serializable/test/json_serializable_test.dart b/json_serializable/test/json_serializable_test.dart index 92f8ef5a3..746d31b8c 100644 --- a/json_serializable/test/json_serializable_test.dart +++ b/json_serializable/test/json_serializable_test.dart @@ -61,6 +61,7 @@ const _expectedAnnotatedTests = [ 'JsonConverterCtorParams', 'JsonConverterDuplicateAnnotations', 'JsonConverterNamedCtor', + 'JsonConverterOnGetter', 'JsonConverterWithBadTypeArg', 'JsonConvertOnField', 'JsonValueValid', diff --git a/json_serializable/test/src/json_converter_test_input.dart b/json_serializable/test/src/json_converter_test_input.dart index e4e1f841d..988886941 100644 --- a/json_serializable/test/src/json_converter_test_input.dart +++ b/json_serializable/test/src/json_converter_test_input.dart @@ -164,3 +164,31 @@ class _ConverterWithCtorParams implements JsonConverter { @override int toJson(Duration object) => 0; } + +@ShouldGenerate(r''' +Map _$JsonConverterOnGetterToJson( + JsonConverterOnGetter instance) => + { + 'annotatedGetter': + const _NeedsConversionConverter().toJson(instance.annotatedGetter), + }; +''') +@JsonSerializable(createFactory: false) +class JsonConverterOnGetter { + @JsonKey() + @_NeedsConversionConverter() + _NeedsConversion get annotatedGetter => _NeedsConversion(); +} + +class _NeedsConversion {} + +class _NeedsConversionConverter + implements JsonConverter<_NeedsConversion, int> { + const _NeedsConversionConverter(); + + @override + _NeedsConversion fromJson(int json) => _NeedsConversion(); + + @override + int toJson(_NeedsConversion object) => 0; +} From 0295d1ef7c3eb24dc508f02334ae155ee0278be2 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Sat, 28 Sep 2019 15:29:47 -0700 Subject: [PATCH 168/569] fix yaml test (#544) --- _test_yaml/test/yaml_test.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/_test_yaml/test/yaml_test.dart b/_test_yaml/test/yaml_test.dart index cb77b188b..cbd405a3a 100644 --- a/_test_yaml/test/yaml_test.dart +++ b/_test_yaml/test/yaml_test.dart @@ -120,9 +120,9 @@ builders: foo: bar baz: zap ''': r''' -line 4, column 5 of file.yaml: Unrecognized keys: [baz, foo]; supported keys: [target, import, is_optional, configLocation, auto_apply, build_to, defaultEnumTest, builder_factories, applies_builders, required_inputs, build_extensions] +line 3, column 5 of file.yaml: Unrecognized keys: [foo, baz]; supported keys: [target, import, is_optional, configLocation, auto_apply, build_to, defaultEnumTest, builder_factories, applies_builders, required_inputs, build_extensions] ╷ -4 │ baz: zap +3 │ foo: bar │ ^^^ ╵''', r''' From 13547e6dee95572541a09ed77e495c06adcbbb08 Mon Sep 17 00:00:00 2001 From: Jacob MacDonald Date: Tue, 8 Oct 2019 14:23:18 -0700 Subject: [PATCH 169/569] bug fix for analyzer 0.38.5 (#549) Fixes https://github.com/dart-lang/json_serializable/issues/548 --- example/pubspec.yaml | 4 ++++ json_serializable/CHANGELOG.md | 4 ++++ json_serializable/lib/src/type_helper_ctx.dart | 4 +--- json_serializable/pubspec.yaml | 4 ++-- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/example/pubspec.yaml b/example/pubspec.yaml index ba9f834e5..a545044ae 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -15,3 +15,7 @@ dev_dependencies: build_verify: ^1.0.0 path: ^1.5.1 test: ^1.6.0 + +dependency_overrides: + json_serializable: + path: ../json_serializable diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 9aab8820e..6adc2973c 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,7 @@ +## 3.2.3 + +* Bug fix for analyzer 0.38.5. + ## 3.2.2 * Support `JsonConverter` annotations on property getters diff --git a/json_serializable/lib/src/type_helper_ctx.dart b/json_serializable/lib/src/type_helper_ctx.dart index 42a4c3a6c..feb631cb3 100644 --- a/json_serializable/lib/src/type_helper_ctx.dart +++ b/json_serializable/lib/src/type_helper_ctx.dart @@ -106,9 +106,7 @@ ConvertData _convertData(DartObject obj, FieldElement element, bool isFrom) { return null; } - final type = objectValue.type as FunctionType; - - final executableElement = type.element as ExecutableElement; + final executableElement = objectValue.toFunctionValue(); if (executableElement.parameters.isEmpty || executableElement.parameters.first.isNamed || diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index bc991f944..ec339989b 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 3.2.2 +version: 3.2.3 author: Dart Team description: >- Automatically generate code for converting to and from JSON by annotating @@ -9,7 +9,7 @@ environment: sdk: '>=2.3.0 <3.0.0' dependencies: - analyzer: '>=0.33.3 <0.39.0' + analyzer: '>=0.37.1 <0.39.0' build: '>=0.12.6 <2.0.0' build_config: '>=0.2.6 <0.5.0' From 0f1ef9f65c95dd029097fe201cfb0ed08ab73490 Mon Sep 17 00:00:00 2001 From: Konstantin Scheglov Date: Thu, 17 Oct 2019 13:19:25 -0700 Subject: [PATCH 170/569] Don't use DartType.toString() to build Dart code for types. (#550) --- json_serializable/lib/src/helper_core.dart | 35 ++++++++++++++++--- .../lib/src/shared_checkers.dart | 5 ++- .../lib/src/type_helper_ctx.dart | 11 ++++-- .../type_helpers/json_converter_helper.dart | 4 ++- .../lib/src/type_helpers/value_helper.dart | 4 ++- json_serializable/lib/src/utils.dart | 5 ++- 6 files changed, 53 insertions(+), 11 deletions(-) diff --git a/json_serializable/lib/src/helper_core.dart b/json_serializable/lib/src/helper_core.dart index 59f46916c..b540c2de8 100644 --- a/json_serializable/lib/src/helper_core.dart +++ b/json_serializable/lib/src/helper_core.dart @@ -3,6 +3,7 @@ // BSD-style license that can be found in the LICENSE file. import 'package:analyzer/dart/element/element.dart'; +import 'package:analyzer/dart/element/type.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:meta/meta.dart'; import 'package:source_gen/source_gen.dart'; @@ -57,7 +58,7 @@ InvalidGenerationSourceError createInvalidGenerationError( String targetMember, FieldElement field, UnsupportedTypeError e) { var message = 'Could not generate `$targetMember` code for `${field.name}`'; if (field.type != e.type) { - message = '$message because of type `${e.type}`'; + message = '$message because of type `${typeToCode(e.type)}`'; } message = '$message.\n${e.reason}'; @@ -91,8 +92,34 @@ String genericClassArguments(ClassElement element, bool withConstraints) { if (withConstraints == null || element.typeParameters.isEmpty) { return ''; } - final values = element.typeParameters - .map((t) => withConstraints ? t.toString() : t.name) - .join(', '); + final values = element.typeParameters.map((t) { + if (withConstraints && t.bound != null) { + final boundCode = typeToCode(t.bound); + return '${t.name} extends $boundCode'; + } else { + return t.name; + } + }).join(', '); return '<$values>'; } + +/// Return the Dart code presentation for the given [type]. +/// +/// This function is intentionally limited, and does not support all possible +/// types and locations of these files in code. Specifically, it supports +/// only [InterfaceType]s, with optional type arguments that are also should +/// be [InterfaceType]s. +String typeToCode(DartType type) { + if (type.isDynamic) { + return 'dynamic'; + } else if (type is InterfaceType) { + final typeArguments = type.typeArguments; + if (typeArguments.isEmpty) { + return type.element.name; + } else { + final typeArgumentsCode = typeArguments.map(typeToCode).join(', '); + return '${type.element.name}<$typeArgumentsCode>'; + } + } + throw UnimplementedError('(${type.runtimeType}) $type'); +} diff --git a/json_serializable/lib/src/shared_checkers.dart b/json_serializable/lib/src/shared_checkers.dart index d32abe67a..17b5e507f 100644 --- a/json_serializable/lib/src/shared_checkers.dart +++ b/json_serializable/lib/src/shared_checkers.dart @@ -5,6 +5,8 @@ import 'package:analyzer/dart/element/type.dart'; import 'package:source_gen/source_gen.dart' show TypeChecker; +import 'helper_core.dart'; + /// A [TypeChecker] for [Iterable]. const coreIterableTypeChecker = TypeChecker.fromUrl('dart:core#Iterable'); @@ -56,7 +58,8 @@ String asStatement(DartType type) { } } - return ' as $type'; + final typeCode = typeToCode(type); + return ' as $typeCode'; } /// Returns all of the [DartType] types that [type] implements, mixes-in, and diff --git a/json_serializable/lib/src/type_helper_ctx.dart b/json_serializable/lib/src/type_helper_ctx.dart index feb631cb3..51c9764d4 100644 --- a/json_serializable/lib/src/type_helper_ctx.dart +++ b/json_serializable/lib/src/type_helper_ctx.dart @@ -129,10 +129,13 @@ ConvertData _convertData(DartObject obj, FieldElement element, bool isFrom) { // TODO: dart-lang/json_serializable#531 - fix deprecated API usage // ignore: deprecated_member_use (!returnType.isAssignableTo(element.type)) { + final returnTypeCode = typeToCode(returnType); + final elementTypeCode = typeToCode(element.type); throwUnsupported( element, 'The `$paramName` function `${executableElement.name}` return type ' - '`$returnType` is not compatible with field type `${element.type}`.'); + '`$returnTypeCode` is not compatible with field type ' + '`$elementTypeCode`.'); } } else { if (argType is TypeParameterType) { @@ -143,11 +146,13 @@ ConvertData _convertData(DartObject obj, FieldElement element, bool isFrom) { // TODO: dart-lang/json_serializable#531 - fix deprecated API usage // ignore: deprecated_member_use (!element.type.isAssignableTo(argType)) { + final argTypeCode = typeToCode(argType); + final elementTypeCode = typeToCode(element.type); throwUnsupported( element, 'The `$paramName` function `${executableElement.name}` argument type ' - '`$argType` is not compatible with field type' - ' `${element.type}`.'); + '`$argTypeCode` is not compatible with field type' + ' `$elementTypeCode`.'); } } diff --git a/json_serializable/lib/src/type_helpers/json_converter_helper.dart b/json_serializable/lib/src/type_helpers/json_converter_helper.dart index 6ba902b80..1ebc8dbd1 100644 --- a/json_serializable/lib/src/type_helpers/json_converter_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_converter_helper.dart @@ -8,6 +8,7 @@ import 'package:analyzer/dart/element/type.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:source_gen/source_gen.dart'; +import '../helper_core.dart'; import '../json_key_utils.dart'; import '../lambda_result.dart'; import '../shared_checkers.dart'; @@ -94,8 +95,9 @@ _JsonConvertData _typeConverterFrom( } if (matchingAnnotations.length > 1) { + final targetTypeCode = typeToCode(targetType); throw InvalidGenerationSourceError( - 'Found more than one matching converter for `$targetType`.', + 'Found more than one matching converter for `$targetTypeCode`.', element: matchingAnnotations[1].elementAnnotation.element); } diff --git a/json_serializable/lib/src/type_helpers/value_helper.dart b/json_serializable/lib/src/type_helpers/value_helper.dart index b0777de99..14923ec1b 100644 --- a/json_serializable/lib/src/type_helpers/value_helper.dart +++ b/json_serializable/lib/src/type_helpers/value_helper.dart @@ -5,6 +5,7 @@ import 'package:analyzer/dart/element/type.dart'; import 'package:source_gen/source_gen.dart' show TypeChecker; +import '../helper_core.dart'; import '../shared_checkers.dart'; import '../type_helper.dart'; @@ -33,7 +34,8 @@ class ValueHelper extends TypeHelper { .isExactlyType(targetType)) { return '($expression as num)${context.nullable ? '?' : ''}.toDouble()'; } else if (simpleJsonTypeChecker.isAssignableFromType(targetType)) { - return '$expression as $targetType'; + final typeCode = typeToCode(targetType); + return '$expression as $typeCode'; } return null; diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index d8094d434..2cc24c243 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -9,6 +9,8 @@ import 'package:json_annotation/json_annotation.dart'; import 'package:meta/meta.dart' show alwaysThrows; import 'package:source_gen/source_gen.dart'; +import 'helper_core.dart'; + final _jsonKeyChecker = const TypeChecker.fromRuntime(JsonKey); DartObject jsonKeyAnnotation(FieldElement element) => @@ -137,8 +139,9 @@ Map enumFieldsMap(DartType targetType) { if (valueReader.isString || valueReader.isNull || valueReader.isInt) { fieldValue = valueReader.literalValue; } else { + final targetTypeCode = typeToCode(targetType); throw InvalidGenerationSourceError( - 'The `JsonValue` annotation on `$targetType.${fe.name}` does ' + 'The `JsonValue` annotation on `$targetTypeCode.${fe.name}` does ' 'not have a value of type String, int, or null.', element: fe); } From 78cba3d5eb292817357c4044e3fbee0410350d76 Mon Sep 17 00:00:00 2001 From: Nate Bosch Date: Fri, 25 Oct 2019 14:51:27 -0700 Subject: [PATCH 171/569] Refactor return of boolean literals (#553) For simple conditions without side effects `return condition` is more straightforward than `if (condition) {return true;} return false;` --- json_serializable/lib/src/encoder_helper.dart | 28 ++++--------------- json_serializable/pubspec.yaml | 2 +- 2 files changed, 7 insertions(+), 23 deletions(-) diff --git a/json_serializable/lib/src/encoder_helper.dart b/json_serializable/lib/src/encoder_helper.dart index 427236be4..4d6b888a0 100644 --- a/json_serializable/lib/src/encoder_helper.dart +++ b/json_serializable/lib/src/encoder_helper.dart @@ -121,16 +121,8 @@ abstract class EncodeHelper implements HelperCore { /// we can avoid checking for `null`. bool _writeJsonValueNaive(FieldElement field) { final jsonKey = jsonKeyFor(field); - - if (jsonKey.includeIfNull) { - return true; - } - - if (!jsonKey.nullable && !_fieldHasCustomEncoder(field)) { - return true; - } - - return false; + return jsonKey.includeIfNull || + (!jsonKey.nullable && !_fieldHasCustomEncoder(field)); } /// Returns `true` if [field] has a user-defined encoder. @@ -139,17 +131,9 @@ abstract class EncodeHelper implements HelperCore { /// annotation. bool _fieldHasCustomEncoder(FieldElement field) { final helperContext = getHelperContext(field); - - if (helperContext.serializeConvertData != null) { - return true; - } - - final output = const JsonConverterHelper() - .serialize(field.type, 'test', helperContext); - - if (output != null) { - return true; - } - return false; + return helperContext.serializeConvertData != null || + const JsonConverterHelper() + .serialize(field.type, 'test', helperContext) != + null; } } diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index ec339989b..1b89b0adb 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 3.2.3 +version: 3.2.4-dev author: Dart Team description: >- Automatically generate code for converting to and from JSON by annotating From 4cb725d8db6bc3a252ab03f2f5146426547aac9e Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Sat, 21 Dec 2019 10:11:39 -0800 Subject: [PATCH 172/569] Use the latest pkg:analyzer, fix deprecated usages (#576) Fixes https://github.com/dart-lang/json_serializable/issues/531 Fixes https://github.com/dart-lang/json_serializable/issues/552 Fixes https://github.com/dart-lang/json_serializable/issues/560 --- .travis.yml | 65 ++++++++++++++----- _test_yaml/mono_pkg.yaml | 4 +- _test_yaml/pubspec.yaml | 2 +- analysis_options.yaml | 7 +- example/mono_pkg.yaml | 4 +- example/pubspec.yaml | 2 +- json_serializable/CHANGELOG.md | 4 ++ json_serializable/lib/src/field_helpers.dart | 14 ++-- .../lib/src/type_helper_ctx.dart | 10 +-- .../lib/src/type_helpers/convert_helper.dart | 3 +- .../type_helpers/json_converter_helper.dart | 6 +- .../lib/src/type_helpers/json_helper.dart | 13 +++- json_serializable/lib/src/utils.dart | 7 ++ json_serializable/mono_pkg.yaml | 4 +- json_serializable/pubspec.yaml | 4 +- tool/travis.sh | 36 +++++++++- 16 files changed, 127 insertions(+), 58 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6fa758bf0..0709c4359 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,4 @@ -# Created with package:mono_repo v2.1.0 +# Created with package:mono_repo v2.3.0 language: dart # Custom configuration @@ -14,48 +14,81 @@ jobs: - stage: analyzer_and_format name: "SDK: dev; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; TASKS: [`dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-warnings --fatal-infos .`]" dart: dev + os: linux env: PKGS="_test_yaml checked_yaml example json_annotation json_serializable" script: ./tool/travis.sh dartfmt dartanalyzer_0 - stage: analyzer_and_format - name: "SDK: 2.3.0; PKGS: _test_yaml, checked_yaml, json_serializable; TASKS: `dartanalyzer --fatal-warnings .`" - dart: "2.3.0" - env: PKGS="_test_yaml checked_yaml json_serializable" + name: "SDK: 2.6.0; PKGS: _test_yaml, json_serializable; TASKS: `dartanalyzer --fatal-warnings .`" + dart: "2.6.0" + os: linux + env: PKGS="_test_yaml json_serializable" script: ./tool/travis.sh dartanalyzer_1 - stage: analyzer_and_format - name: "SDK: 2.3.0; PKGS: example, json_annotation; TASKS: [`dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-warnings .`]" + name: "SDK: 2.3.0; PKG: checked_yaml; TASKS: `dartanalyzer --fatal-warnings .`" dart: "2.3.0" - env: PKGS="example json_annotation" + os: linux + env: PKGS="checked_yaml" + script: ./tool/travis.sh dartanalyzer_1 + - stage: analyzer_and_format + name: "SDK: 2.6.0; PKG: example; TASKS: [`dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-warnings .`]" + dart: "2.6.0" + os: linux + env: PKGS="example" script: ./tool/travis.sh dartfmt dartanalyzer_1 - - stage: unit_test - name: "SDK: 2.3.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test`" + - stage: analyzer_and_format + name: "SDK: 2.3.0; PKG: json_annotation; TASKS: [`dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-warnings .`]" dart: "2.3.0" - env: PKGS="_test_yaml checked_yaml example json_serializable" - script: ./tool/travis.sh test_0 + os: linux + env: PKGS="json_annotation" + script: ./tool/travis.sh dartfmt dartanalyzer_1 - stage: unit_test name: "SDK: dev; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test`" dart: dev + os: linux env: PKGS="_test_yaml checked_yaml example json_serializable" script: ./tool/travis.sh test_0 - stage: unit_test - name: "SDK: 2.3.0; PKG: json_serializable; TASKS: `pub run build_runner test --delete-conflicting-outputs -- -p chrome`" + name: "SDK: 2.6.0; PKGS: _test_yaml, example, json_serializable; TASKS: `pub run test`" + dart: "2.6.0" + os: linux + env: PKGS="_test_yaml example json_serializable" + script: ./tool/travis.sh test_0 + - stage: unit_test + name: "SDK: 2.3.0; PKG: checked_yaml; TASKS: `pub run test`" dart: "2.3.0" + os: linux + env: PKGS="checked_yaml" + script: ./tool/travis.sh test_0 + - stage: unit_test + name: "SDK: 2.6.0; PKG: json_serializable; TASKS: `pub run build_runner test --delete-conflicting-outputs -- -p chrome`" + dart: "2.6.0" + os: linux env: PKGS="json_serializable" script: ./tool/travis.sh command - stage: unit_test name: "SDK: dev; PKG: json_serializable; TASKS: `pub run build_runner test --delete-conflicting-outputs -- -p chrome`" dart: dev + os: linux env: PKGS="json_serializable" script: ./tool/travis.sh command - - stage: ensure_build - name: "SDK: 2.3.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`" - dart: "2.3.0" - env: PKGS="_test_yaml checked_yaml example json_serializable" - script: ./tool/travis.sh test_1 - stage: ensure_build name: "SDK: dev; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`" dart: dev + os: linux env: PKGS="_test_yaml checked_yaml example json_serializable" script: ./tool/travis.sh test_1 + - stage: ensure_build + name: "SDK: 2.6.0; PKGS: _test_yaml, example, json_serializable; TASKS: `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`" + dart: "2.6.0" + os: linux + env: PKGS="_test_yaml example json_serializable" + script: ./tool/travis.sh test_1 + - stage: ensure_build + name: "SDK: 2.3.0; PKG: checked_yaml; TASKS: `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`" + dart: "2.3.0" + os: linux + env: PKGS="checked_yaml" + script: ./tool/travis.sh test_1 stages: - analyzer_and_format diff --git a/_test_yaml/mono_pkg.yaml b/_test_yaml/mono_pkg.yaml index 6b257bd39..4ee5b8d99 100644 --- a/_test_yaml/mono_pkg.yaml +++ b/_test_yaml/mono_pkg.yaml @@ -1,6 +1,6 @@ # See https://github.com/dart-lang/mono_repo for details dart: -- 2.3.0 +- 2.6.0 - dev stages: @@ -11,7 +11,7 @@ stages: dart: [dev] - group: - dartanalyzer: --fatal-warnings . - dart: [2.3.0] + dart: [2.6.0] - unit_test: - test - ensure_build: diff --git a/_test_yaml/pubspec.yaml b/_test_yaml/pubspec.yaml index 0c9db1d5f..531395dcc 100644 --- a/_test_yaml/pubspec.yaml +++ b/_test_yaml/pubspec.yaml @@ -2,7 +2,7 @@ name: _test_yaml publish_to: none environment: - sdk: '>=2.3.0 <3.0.0' + sdk: '>=2.6.0 <3.0.0' dev_dependencies: build_runner: ^1.0.0 diff --git a/analysis_options.yaml b/analysis_options.yaml index 107b442f7..547941318 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1,12 +1,7 @@ analyzer: strong-mode: implicit-casts: false - errors: - dead_code: error - override_on_non_overriding_method: error - unused_element: error - unused_import: error - unused_local_variable: error + linter: rules: - always_declare_return_types diff --git a/example/mono_pkg.yaml b/example/mono_pkg.yaml index a25b7e82b..934fc7c4c 100644 --- a/example/mono_pkg.yaml +++ b/example/mono_pkg.yaml @@ -1,6 +1,6 @@ # See https://github.com/dart-lang/mono_repo for details dart: -- 2.3.0 +- 2.6.0 - dev stages: @@ -12,7 +12,7 @@ stages: - group: - dartfmt - dartanalyzer: --fatal-warnings . - dart: [2.3.0] + dart: [2.6.0] - unit_test: - test - ensure_build: diff --git a/example/pubspec.yaml b/example/pubspec.yaml index a545044ae..14c7464a8 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -2,7 +2,7 @@ name: example author: Dart Team environment: - sdk: '>=2.3.0 <3.0.0' + sdk: '>=2.6.0 <3.0.0' dependencies: json_annotation: ^3.0.0 diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 6adc2973c..4df5947dd 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,7 @@ +## 3.2.4 + +* Require `package:analyzer` `^0.39.0`. + ## 3.2.3 * Bug fix for analyzer 0.38.5. diff --git a/json_serializable/lib/src/field_helpers.dart b/json_serializable/lib/src/field_helpers.dart index f80bb7bf0..2d298dbfb 100644 --- a/json_serializable/lib/src/field_helpers.dart +++ b/json_serializable/lib/src/field_helpers.dart @@ -5,8 +5,8 @@ import 'package:analyzer/dart/element/element.dart'; // ignore: implementation_imports -import 'package:analyzer/src/dart/resolver/inheritance_manager.dart' - show InheritanceManager; // ignore: deprecated_member_use +import 'package:analyzer/src/dart/element/inheritance_manager3.dart' + show InheritanceManager3; import 'package:source_gen/source_gen.dart'; import 'utils.dart'; @@ -40,7 +40,7 @@ class _FieldSet implements Comparable<_FieldSet> { final checkerA = TypeChecker.fromStatic( // TODO: remove `ignore` when min pkg:analyzer >= 0.38.0 // ignore: unnecessary_cast - (a.enclosingElement as ClassElement).type); + (a.enclosingElement as ClassElement).thisType); if (!checkerA.isExactly(b.enclosingElement)) { // in this case, you want to prioritize the enclosingElement that is more @@ -53,7 +53,7 @@ class _FieldSet implements Comparable<_FieldSet> { final checkerB = TypeChecker.fromStatic( // TODO: remove `ignore` when min pkg:analyzer >= 0.38.0 // ignore: unnecessary_cast - (b.enclosingElement as ClassElement).type); + (b.enclosingElement as ClassElement).thisType); if (checkerB.isAssignableFrom(a.enclosingElement)) { return 1; @@ -84,11 +84,9 @@ Iterable createSortedFieldSet(ClassElement element) { element.fields.where((e) => !e.isStatic).map((e) => MapEntry(e.name, e))); final inheritedFields = {}; - // ignore: deprecated_member_use - final manager = InheritanceManager(element.library); + final manager = InheritanceManager3(); - // ignore: deprecated_member_use - for (final v in manager.getMembersInheritedFromClasses(element).values) { + for (final v in manager.getInheritedConcreteMap(element.thisType).values) { assert(v is! FieldElement); if (_dartCoreObjectChecker.isExactly(v.enclosingElement)) { continue; diff --git a/json_serializable/lib/src/type_helper_ctx.dart b/json_serializable/lib/src/type_helper_ctx.dart index 51c9764d4..0d72ab563 100644 --- a/json_serializable/lib/src/type_helper_ctx.dart +++ b/json_serializable/lib/src/type_helper_ctx.dart @@ -125,10 +125,7 @@ ConvertData _convertData(DartObject obj, FieldElement element, bool isFrom) { // We keep things simple in this case. We rely on inferred type arguments // to the `fromJson` function. // TODO: consider adding error checking here if there is confusion. - } else if - // TODO: dart-lang/json_serializable#531 - fix deprecated API usage - // ignore: deprecated_member_use - (!returnType.isAssignableTo(element.type)) { + } else if (!returnType.isAssignableTo(element.type)) { final returnTypeCode = typeToCode(returnType); final elementTypeCode = typeToCode(element.type); throwUnsupported( @@ -142,10 +139,7 @@ ConvertData _convertData(DartObject obj, FieldElement element, bool isFrom) { // We keep things simple in this case. We rely on inferred type arguments // to the `fromJson` function. // TODO: consider adding error checking here if there is confusion. - } else if - // TODO: dart-lang/json_serializable#531 - fix deprecated API usage - // ignore: deprecated_member_use - (!element.type.isAssignableTo(argType)) { + } else if (!element.type.isAssignableTo(argType)) { final argTypeCode = typeToCode(argType); final elementTypeCode = typeToCode(element.type); throwUnsupported( diff --git a/json_serializable/lib/src/type_helpers/convert_helper.dart b/json_serializable/lib/src/type_helpers/convert_helper.dart index c2ccd1c5c..ce6a5cfb8 100644 --- a/json_serializable/lib/src/type_helpers/convert_helper.dart +++ b/json_serializable/lib/src/type_helpers/convert_helper.dart @@ -7,6 +7,7 @@ import 'package:analyzer/dart/element/type.dart'; import '../json_key_utils.dart'; import '../shared_checkers.dart'; import '../type_helper.dart'; +import '../utils.dart'; /// Information used by [ConvertHelper] when handling `JsonKey`-annotated /// fields with `toJson` or `fromJson` values set. @@ -38,7 +39,7 @@ class ConvertHelper extends TypeHelper { assert(toJsonData.paramType is TypeParameterType || // TODO: dart-lang/json_serializable#531 - fix deprecated API usage - // ignore: deprecated_member_use + // ignore: ),); targetType.isAssignableTo(toJsonData.paramType)); return '${toJsonData.name}($expression)'; } diff --git a/json_serializable/lib/src/type_helpers/json_converter_helper.dart b/json_serializable/lib/src/type_helpers/json_converter_helper.dart index 1ebc8dbd1..490ab8088 100644 --- a/json_serializable/lib/src/type_helpers/json_converter_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_converter_helper.dart @@ -158,14 +158,12 @@ _ConverterMatch _compatibleMatch( return null; } - assert(jsonConverterSuper.typeParameters.length == 2); + assert(jsonConverterSuper.element.typeParameters.length == 2); assert(jsonConverterSuper.typeArguments.length == 2); final fieldType = jsonConverterSuper.typeArguments[0]; - // TODO: dart-lang/json_serializable#531 - fix deprecated API usage - // ignore: deprecated_member_use - if (fieldType.isEquivalentTo(targetType)) { + if (fieldType == targetType) { return _ConverterMatch( annotation, constantValue, jsonConverterSuper.typeArguments[1], null); } diff --git a/json_serializable/lib/src/type_helpers/json_helper.dart b/json_serializable/lib/src/type_helpers/json_helper.dart index 6f6bb42f7..d8ea77c68 100644 --- a/json_serializable/lib/src/type_helpers/json_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_helper.dart @@ -3,6 +3,7 @@ // BSD-style license that can be found in the LICENSE file. import 'package:analyzer/dart/element/element.dart'; +import 'package:analyzer/dart/element/nullability_suffix.dart'; import 'package:analyzer/dart/element/type.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:source_gen/source_gen.dart'; @@ -98,8 +99,9 @@ bool _canSerialize(JsonSerializable config, DartType type) { InterfaceType _instantiate( InterfaceType ctorParamType, InterfaceType classType) { final argTypes = ctorParamType.typeArguments.map((arg) { - final typeParamIndex = - classType.typeParameters.indexWhere((e) => e.type == arg); + final typeParamIndex = classType.element.typeParameters.indexWhere( + // TODO(kevmoo): not 100% sure `nullabilitySuffix` is right + (e) => e.instantiate(nullabilitySuffix: arg.nullabilitySuffix) == arg); if (typeParamIndex >= 0) { return classType.typeArguments[typeParamIndex]; } else { @@ -113,7 +115,12 @@ InterfaceType _instantiate( return null; } - return ctorParamType.instantiate(argTypes); + // ignore: deprecated_member_use + return ctorParamType.element.instantiate( + typeArguments: argTypes, + // TODO(kevmoo): not 100% sure nullabilitySuffix is right... Works for now + nullabilitySuffix: NullabilitySuffix.none, + ); } JsonSerializable _annotation(JsonSerializable config, InterfaceType source) { diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index 2cc24c243..1ce30f9ef 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -249,3 +249,10 @@ String _getHexLiteral(String input) { final value = rune.toRadixString(16).toUpperCase().padLeft(2, '0'); return '\\x$value'; } + +extension DartTypeExtension on DartType { + bool isAssignableTo(DartType other) => + // If the library is `null`, treat it like dynamic => `true` + element.library == null || + element.library.typeSystem.isAssignableTo(this, other); +} diff --git a/json_serializable/mono_pkg.yaml b/json_serializable/mono_pkg.yaml index d32dde025..716aa8c15 100644 --- a/json_serializable/mono_pkg.yaml +++ b/json_serializable/mono_pkg.yaml @@ -1,6 +1,6 @@ # See https://github.com/dart-lang/mono_repo for details dart: -- 2.3.0 +- 2.6.0 - dev stages: @@ -11,7 +11,7 @@ stages: dart: [dev] - group: - dartanalyzer: --fatal-warnings . - dart: [2.3.0] + dart: [2.6.0] - unit_test: - test - command: pub run build_runner test --delete-conflicting-outputs -- -p chrome diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 1b89b0adb..31ce1c8f7 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -6,10 +6,10 @@ description: >- Dart classes. homepage: https://github.com/dart-lang/json_serializable environment: - sdk: '>=2.3.0 <3.0.0' + sdk: '>=2.6.0 <3.0.0' dependencies: - analyzer: '>=0.37.1 <0.39.0' + analyzer: ^0.39.0 build: '>=0.12.6 <2.0.0' build_config: '>=0.2.6 <0.5.0' diff --git a/tool/travis.sh b/tool/travis.sh index becfa6d0c..da9accd71 100755 --- a/tool/travis.sh +++ b/tool/travis.sh @@ -1,5 +1,28 @@ #!/bin/bash -# Created with package:mono_repo v2.1.0 +# Created with package:mono_repo v2.3.0 + +# Support built in commands on windows out of the box. +function pub { + if [[ $TRAVIS_OS_NAME == "windows" ]]; then + command pub.bat "$@" + else + command pub "$@" + fi +} +function dartfmt { + if [[ $TRAVIS_OS_NAME == "windows" ]]; then + command dartfmt.bat "$@" + else + command dartfmt "$@" + fi +} +function dartanalyzer { + if [[ $TRAVIS_OS_NAME == "windows" ]]; then + command dartanalyzer.bat "$@" + else + command dartanalyzer "$@" + fi +} if [[ -z ${PKGS} ]]; then echo -e '\033[31mPKGS environment variable must be set!\033[0m' @@ -16,7 +39,16 @@ EXIT_CODE=0 for PKG in ${PKGS}; do echo -e "\033[1mPKG: ${PKG}\033[22m" pushd "${PKG}" || exit $? - pub upgrade --no-precompile || exit $? + + PUB_EXIT_CODE=0 + pub upgrade --no-precompile || PUB_EXIT_CODE=$? + + if [[ ${PUB_EXIT_CODE} -ne 0 ]]; then + EXIT_CODE=1 + echo -e '\033[31mpub upgrade failed\033[0m' + popd + continue + fi for TASK in "$@"; do echo From 4b5189cc9779ebe10779e940408165e6f8c6c93e Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Sat, 21 Dec 2019 10:38:44 -0800 Subject: [PATCH 173/569] Prepare to release json_serializable v3.2.4 --- json_serializable/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 31ce1c8f7..ec3105d26 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 3.2.4-dev +version: 3.2.4 author: Dart Team description: >- Automatically generate code for converting to and from JSON by annotating From a4af02f083953719f41b31cae0781ff2a9d480b8 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Sat, 21 Dec 2019 10:39:18 -0800 Subject: [PATCH 174/569] remove author field --- json_serializable/pubspec.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index ec3105d26..3d18adb95 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,6 +1,5 @@ name: json_serializable version: 3.2.4 -author: Dart Team description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. From 7135ca6728733c5284612800c42e6320be7f2b18 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 23 Dec 2019 11:04:18 -0800 Subject: [PATCH 175/569] Enable and fix use_function_type_syntax_for_parameters lint (#578) Prepare to release +1 releases for serializable and annotation Bump SDK constraint on annotation --- .travis.yml | 10 ++-------- _test_yaml/test/yaml_test.dart | 2 +- analysis_options.yaml | 2 +- json_annotation/CHANGELOG.md | 5 +++++ json_annotation/lib/src/checked_helpers.dart | 4 ++-- json_annotation/mono_pkg.yaml | 2 +- json_annotation/pubspec.yaml | 5 ++--- json_serializable/CHANGELOG.md | 4 ++++ json_serializable/lib/src/decode_helper.dart | 4 ++-- json_serializable/lib/src/json_part_builder.dart | 2 +- json_serializable/lib/src/type_helper_ctx.dart | 2 +- .../lib/src/type_helpers/convert_helper.dart | 2 -- json_serializable/pubspec.yaml | 2 +- .../test/default_value/default_value_test.dart | 2 +- json_serializable/test/test_utils.dart | 2 +- 15 files changed, 25 insertions(+), 25 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0709c4359..d100c52b1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,16 +30,10 @@ jobs: env: PKGS="checked_yaml" script: ./tool/travis.sh dartanalyzer_1 - stage: analyzer_and_format - name: "SDK: 2.6.0; PKG: example; TASKS: [`dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-warnings .`]" + name: "SDK: 2.6.0; PKGS: example, json_annotation; TASKS: [`dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-warnings .`]" dart: "2.6.0" os: linux - env: PKGS="example" - script: ./tool/travis.sh dartfmt dartanalyzer_1 - - stage: analyzer_and_format - name: "SDK: 2.3.0; PKG: json_annotation; TASKS: [`dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-warnings .`]" - dart: "2.3.0" - os: linux - env: PKGS="json_annotation" + env: PKGS="example json_annotation" script: ./tool/travis.sh dartfmt dartanalyzer_1 - stage: unit_test name: "SDK: dev; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test`" diff --git a/_test_yaml/test/yaml_test.dart b/_test_yaml/test/yaml_test.dart index cbd405a3a..adba72014 100644 --- a/_test_yaml/test/yaml_test.dart +++ b/_test_yaml/test/yaml_test.dart @@ -157,7 +157,7 @@ final throwsCastError = throwsA(isCastError); T roundTripObject( T object, - T factory(Map json), { + T Function(Map json) factory, { bool skipObjectEquals = false, }) { final data = loudEncode(object); diff --git a/analysis_options.yaml b/analysis_options.yaml index 547941318..9b1b46f02 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -81,6 +81,6 @@ linter: - unnecessary_statements - unnecessary_this - unrelated_type_equality_checks - #- use_function_type_syntax_for_parameters + - use_function_type_syntax_for_parameters - use_rethrow_when_possible - valid_regexps diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index f501de917..3dedfef66 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -1,3 +1,8 @@ +## 3.0.1 + +- Require at least Dart `2.6.0`. +- Fix lint that was affecting `pub.dev` score. + ## 3.0.0 - **BREAKING** Removed `JsonSerializable.useWrappers` and associated diff --git a/json_annotation/lib/src/checked_helpers.dart b/json_annotation/lib/src/checked_helpers.dart index f24fd3197..eb2da567c 100644 --- a/json_annotation/lib/src/checked_helpers.dart +++ b/json_annotation/lib/src/checked_helpers.dart @@ -8,7 +8,7 @@ import 'allowed_keys_helpers.dart'; /// `JsonSerializableGenerator.checked` is `true`. /// /// Should not be used directly. -T $checkedNew(String className, Map map, T constructor(), +T $checkedNew(String className, Map map, T Function() constructor, {Map fieldKeyMap}) { fieldKeyMap ??= const {}; @@ -37,7 +37,7 @@ T $checkedNew(String className, Map map, T constructor(), /// `JsonSerializableGenerator.checked` is `true`. /// /// Should not be used directly. -T $checkedConvert(Map map, String key, T castFunc(Object value)) { +T $checkedConvert(Map map, String key, T Function(Object) castFunc) { try { return castFunc(map[key]); } on CheckedFromJsonException { diff --git a/json_annotation/mono_pkg.yaml b/json_annotation/mono_pkg.yaml index 6da78e459..456a4d185 100644 --- a/json_annotation/mono_pkg.yaml +++ b/json_annotation/mono_pkg.yaml @@ -8,4 +8,4 @@ stages: - group: - dartfmt - dartanalyzer: --fatal-warnings . - dart: [2.3.0] + dart: [2.6.0] diff --git a/json_annotation/pubspec.yaml b/json_annotation/pubspec.yaml index e4354d00d..023ec0765 100644 --- a/json_annotation/pubspec.yaml +++ b/json_annotation/pubspec.yaml @@ -1,12 +1,11 @@ name: json_annotation -version: 3.0.0 +version: 3.0.1 description: >- Classes and helper functions that support JSON code generation via the `json_serializable` package. homepage: https://github.com/dart-lang/json_serializable -author: Dart Team environment: - sdk: '>=2.3.0 <3.0.0' + sdk: '>=2.6.0 <3.0.0' # When changing JsonSerializable class. # dev_dependencies: diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 4df5947dd..aa8e02181 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,7 @@ +## 3.2.5 + +- Fix lint affecting `pub.dev` score. + ## 3.2.4 * Require `package:analyzer` `^0.39.0`. diff --git a/json_serializable/lib/src/decode_helper.dart b/json_serializable/lib/src/decode_helper.dart index c3aab5d8f..0a99da494 100644 --- a/json_serializable/lib/src/decode_helper.dart +++ b/json_serializable/lib/src/decode_helper.dart @@ -226,8 +226,8 @@ _ConstructorData _writeConstructorInvocation( Iterable availableConstructorParameters, Iterable writableFields, Map unavailableReasons, - String deserializeForField(String paramOrFieldName, - {ParameterElement ctorParam})) { + String Function(String paramOrFieldName, {ParameterElement ctorParam}) + deserializeForField) { final className = classElement.name; final ctor = classElement.unnamedConstructor; diff --git a/json_serializable/lib/src/json_part_builder.dart b/json_serializable/lib/src/json_part_builder.dart index ce8cd9210..e0db6de3e 100644 --- a/json_serializable/lib/src/json_part_builder.dart +++ b/json_serializable/lib/src/json_part_builder.dart @@ -15,7 +15,7 @@ import 'json_serializable_generator.dart'; /// [formatOutput] is called to format the generated code. If not provided, /// the default Dart code formatter is used. Builder jsonPartBuilder( - {String formatOutput(String code), JsonSerializable config}) => + {String Function(String code) formatOutput, JsonSerializable config}) => SharedPartBuilder([ JsonSerializableGenerator(config: config), const JsonLiteralGenerator() diff --git a/json_serializable/lib/src/type_helper_ctx.dart b/json_serializable/lib/src/type_helper_ctx.dart index 0d72ab563..6f635e32a 100644 --- a/json_serializable/lib/src/type_helper_ctx.dart +++ b/json_serializable/lib/src/type_helper_ctx.dart @@ -62,7 +62,7 @@ class TypeHelperCtx (TypeHelper th) => th.deserialize(targetType, expression, this)); Object _run(DartType targetType, String expression, - Object invoke(TypeHelper instance)) => + Object Function(TypeHelper) invoke) => _helperCore.allTypeHelpers.map(invoke).firstWhere((r) => r != null, orElse: () => throw UnsupportedTypeError( targetType, expression, _notSupportedWithTypeHelpersMsg)); diff --git a/json_serializable/lib/src/type_helpers/convert_helper.dart b/json_serializable/lib/src/type_helpers/convert_helper.dart index ce6a5cfb8..f5f228f66 100644 --- a/json_serializable/lib/src/type_helpers/convert_helper.dart +++ b/json_serializable/lib/src/type_helpers/convert_helper.dart @@ -38,8 +38,6 @@ class ConvertHelper extends TypeHelper { logFieldWithConversionFunction(context.fieldElement); assert(toJsonData.paramType is TypeParameterType || - // TODO: dart-lang/json_serializable#531 - fix deprecated API usage - // ignore: ),); targetType.isAssignableTo(toJsonData.paramType)); return '${toJsonData.name}($expression)'; } diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 3d18adb95..4e4ac3f3d 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 3.2.4 +version: 3.2.5 description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. diff --git a/json_serializable/test/default_value/default_value_test.dart b/json_serializable/test/default_value/default_value_test.dart index 64bdf46ed..f59918cc3 100644 --- a/json_serializable/test/default_value/default_value_test.dart +++ b/json_serializable/test/default_value/default_value_test.dart @@ -44,7 +44,7 @@ void main() { group('non-nullable', () => _test(checked.fromJson)); } -void _test(DefaultValue fromJson(Map json)) { +void _test(DefaultValue Function(Map json) fromJson) { test('empty map yields all default values', () { final object = fromJson({}); expect(loudEncode(object), loudEncode(_defaultInstance)); diff --git a/json_serializable/test/test_utils.dart b/json_serializable/test/test_utils.dart index cae65023a..7cd84da93 100644 --- a/json_serializable/test/test_utils.dart +++ b/json_serializable/test/test_utils.dart @@ -8,7 +8,7 @@ import 'package:test/test.dart'; final throwsCastError = throwsA(isCastError); -T roundTripObject(T object, T factory(Map json)) { +T roundTripObject(T object, T Function(Map json) factory) { final data = loudEncode(object); final object2 = factory(json.decode(data) as Map); From 10b671b8cc745a8a3b63483b71466427dc1f22f9 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 23 Dec 2019 11:29:27 -0800 Subject: [PATCH 176/569] add remaining pedantic lints --- analysis_options.yaml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index 9b1b46f02..ba6768122 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -5,6 +5,7 @@ analyzer: linter: rules: - always_declare_return_types + - always_require_non_null_named_parameters - annotate_overrides - avoid_empty_else - avoid_function_literals_in_foreach_calls @@ -18,9 +19,9 @@ linter: - avoid_types_as_parameter_names - avoid_unused_constructor_parameters - await_only_futures + - camel_case_extensions - camel_case_types - cancel_subscriptions - #- cascade_invocations - comment_references - constant_identifier_names - control_flow_in_finally @@ -55,13 +56,16 @@ linter: - prefer_equal_for_default_values - prefer_final_fields - prefer_final_locals + - prefer_for_elements_to_map_fromIterable - prefer_generic_function_type_aliases + - prefer_if_null_operators - prefer_initializing_formals - prefer_interpolation_to_compose_strings - - prefer_iterable_whereType - prefer_is_empty - prefer_is_not_empty + - prefer_iterable_whereType - prefer_single_quotes + - prefer_spread_collections - prefer_typing_uninitialized_variables - recursive_getters - slash_for_doc_comments From 44341bc4ed721825539aca1127d9be8dfb55567f Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 16 Jan 2020 12:59:47 -0800 Subject: [PATCH 177/569] fix deprecated analyzer (#589) and removed unused constructor on private class --- json_serializable/lib/src/json_key_utils.dart | 4 ++-- .../lib/src/type_helper_ctx.dart | 2 -- .../lib/src/type_helpers/enum_helper.dart | 5 +++-- .../type_helpers/json_converter_helper.dart | 21 ++++++++++++++----- .../lib/src/type_helpers/json_helper.dart | 2 +- 5 files changed, 22 insertions(+), 12 deletions(-) diff --git a/json_serializable/lib/src/json_key_utils.dart b/json_serializable/lib/src/json_key_utils.dart index 024aa7f30..2432e69e9 100644 --- a/json_serializable/lib/src/json_key_utils.dart +++ b/json_serializable/lib/src/json_key_utils.dart @@ -68,7 +68,7 @@ JsonKey _from(FieldElement element, JsonSerializable classAnnotation) { // TODO(kevmoo): Support calling function for the default value? badType = 'Function'; } else if (!reader.isLiteral) { - badType = dartObject.type.name; + badType = dartObject.type.element.name; } if (badType != null) { @@ -133,7 +133,7 @@ JsonKey _from(FieldElement element, JsonSerializable classAnnotation) { final enumValueName = enumValueForDartObject( annotationValue, enumValueNames, (n) => n); - return '${annotationValue.type.name}.$enumValueName'; + return '${annotationValue.type.element.name}.$enumValueName'; } else { final defaultValueLiteral = literalForObject(annotationValue, []); if (defaultValueLiteral == null) { diff --git a/json_serializable/lib/src/type_helper_ctx.dart b/json_serializable/lib/src/type_helper_ctx.dart index 6f635e32a..3262dd05e 100644 --- a/json_serializable/lib/src/type_helper_ctx.dart +++ b/json_serializable/lib/src/type_helper_ctx.dart @@ -74,8 +74,6 @@ final _notSupportedWithTypeHelpersMsg = class _ConvertPair { static final _expando = Expando<_ConvertPair>(); - static _ConvertPair fromJsonKey(JsonKey key) => _expando[key]; - final ConvertData fromJson, toJson; _ConvertPair._(this.fromJson, this.toJson); diff --git a/json_serializable/lib/src/type_helpers/enum_helper.dart b/json_serializable/lib/src/type_helpers/enum_helper.dart index 5a1f7b4f9..7188aceba 100644 --- a/json_serializable/lib/src/type_helpers/enum_helper.dart +++ b/json_serializable/lib/src/type_helpers/enum_helper.dart @@ -66,7 +66,8 @@ class EnumHelper extends TypeHelper { } } -String _constMapName(DartType targetType) => '_\$${targetType.name}EnumMap'; +String _constMapName(DartType targetType) => + '_\$${targetType.element.name}EnumMap'; String _enumValueMapFromType(DartType targetType) { final enumMap = enumFieldsMap(targetType); @@ -77,7 +78,7 @@ String _enumValueMapFromType(DartType targetType) { final items = enumMap.entries .map((e) => - ' ${targetType.name}.${e.key.name}: ${jsonLiteralAsDart(e.value)},') + ' ${targetType.element.name}.${e.key.name}: ${jsonLiteralAsDart(e.value)},') .join(); return 'const ${_constMapName(targetType)} = {\n$items\n};'; diff --git a/json_serializable/lib/src/type_helpers/json_converter_helper.dart b/json_serializable/lib/src/type_helpers/json_converter_helper.dart index 490ab8088..6a509aa6f 100644 --- a/json_serializable/lib/src/type_helpers/json_converter_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_converter_helper.dart @@ -126,12 +126,19 @@ _JsonConvertData _typeConverterFrom( } if (match.genericTypeArg != null) { - return _JsonConvertData.genericClass(match.annotation.type.name, - match.genericTypeArg, reviver.accessor, match.jsonType); + return _JsonConvertData.genericClass( + match.annotation.type.element.name, + match.genericTypeArg, + reviver.accessor, + match.jsonType, + ); } return _JsonConvertData.className( - match.annotation.type.name, reviver.accessor, match.jsonType); + match.annotation.type.element.name, + reviver.accessor, + match.jsonType, + ); } class _ConverterMatch { @@ -179,8 +186,12 @@ _ConverterMatch _compatibleMatch( element: converterClassElement); } - return _ConverterMatch(annotation, constantValue, - jsonConverterSuper.typeArguments[1], targetType.name); + return _ConverterMatch( + annotation, + constantValue, + jsonConverterSuper.typeArguments[1], + targetType.element.name, + ); } return null; diff --git a/json_serializable/lib/src/type_helpers/json_helper.dart b/json_serializable/lib/src/type_helpers/json_helper.dart index d8ea77c68..3783ca353 100644 --- a/json_serializable/lib/src/type_helpers/json_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_helper.dart @@ -70,7 +70,7 @@ class JsonHelper extends TypeHelper { // TODO: the type could be imported from a library with a prefix! // github.com/dart-lang/json_serializable/issues/19 - output = '${targetType.name}.fromJson($output)'; + output = '${targetType.element.name}.fromJson($output)'; return commonNullPrefix(context.nullable, expression, output).toString(); } From acbba7836c943fa3040be043666803a8f1802ed6 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 16 Jan 2020 14:40:49 -0800 Subject: [PATCH 178/569] Update min SDK for checked_yaml to 2.6 (#592) Align all packages. Decrease CI time --- .travis.yml | 42 +++++++++++--------------------------- checked_yaml/changelog.md | 4 ++++ checked_yaml/mono_pkg.yaml | 4 ++-- checked_yaml/pubspec.yaml | 4 ++-- 4 files changed, 20 insertions(+), 34 deletions(-) diff --git a/.travis.yml b/.travis.yml index d100c52b1..7b59d78ce 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,16 +18,10 @@ jobs: env: PKGS="_test_yaml checked_yaml example json_annotation json_serializable" script: ./tool/travis.sh dartfmt dartanalyzer_0 - stage: analyzer_and_format - name: "SDK: 2.6.0; PKGS: _test_yaml, json_serializable; TASKS: `dartanalyzer --fatal-warnings .`" + name: "SDK: 2.6.0; PKGS: _test_yaml, checked_yaml, json_serializable; TASKS: `dartanalyzer --fatal-warnings .`" dart: "2.6.0" os: linux - env: PKGS="_test_yaml json_serializable" - script: ./tool/travis.sh dartanalyzer_1 - - stage: analyzer_and_format - name: "SDK: 2.3.0; PKG: checked_yaml; TASKS: `dartanalyzer --fatal-warnings .`" - dart: "2.3.0" - os: linux - env: PKGS="checked_yaml" + env: PKGS="_test_yaml checked_yaml json_serializable" script: ./tool/travis.sh dartanalyzer_1 - stage: analyzer_and_format name: "SDK: 2.6.0; PKGS: example, json_annotation; TASKS: [`dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-warnings .`]" @@ -36,22 +30,16 @@ jobs: env: PKGS="example json_annotation" script: ./tool/travis.sh dartfmt dartanalyzer_1 - stage: unit_test - name: "SDK: dev; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test`" - dart: dev - os: linux - env: PKGS="_test_yaml checked_yaml example json_serializable" - script: ./tool/travis.sh test_0 - - stage: unit_test - name: "SDK: 2.6.0; PKGS: _test_yaml, example, json_serializable; TASKS: `pub run test`" + name: "SDK: 2.6.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test`" dart: "2.6.0" os: linux - env: PKGS="_test_yaml example json_serializable" + env: PKGS="_test_yaml checked_yaml example json_serializable" script: ./tool/travis.sh test_0 - stage: unit_test - name: "SDK: 2.3.0; PKG: checked_yaml; TASKS: `pub run test`" - dart: "2.3.0" + name: "SDK: dev; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test`" + dart: dev os: linux - env: PKGS="checked_yaml" + env: PKGS="_test_yaml checked_yaml example json_serializable" script: ./tool/travis.sh test_0 - stage: unit_test name: "SDK: 2.6.0; PKG: json_serializable; TASKS: `pub run build_runner test --delete-conflicting-outputs -- -p chrome`" @@ -66,22 +54,16 @@ jobs: env: PKGS="json_serializable" script: ./tool/travis.sh command - stage: ensure_build - name: "SDK: dev; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`" - dart: dev - os: linux - env: PKGS="_test_yaml checked_yaml example json_serializable" - script: ./tool/travis.sh test_1 - - stage: ensure_build - name: "SDK: 2.6.0; PKGS: _test_yaml, example, json_serializable; TASKS: `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`" + name: "SDK: 2.6.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`" dart: "2.6.0" os: linux - env: PKGS="_test_yaml example json_serializable" + env: PKGS="_test_yaml checked_yaml example json_serializable" script: ./tool/travis.sh test_1 - stage: ensure_build - name: "SDK: 2.3.0; PKG: checked_yaml; TASKS: `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`" - dart: "2.3.0" + name: "SDK: dev; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`" + dart: dev os: linux - env: PKGS="checked_yaml" + env: PKGS="_test_yaml checked_yaml example json_serializable" script: ./tool/travis.sh test_1 stages: diff --git a/checked_yaml/changelog.md b/checked_yaml/changelog.md index 9b707b82f..2751393ee 100644 --- a/checked_yaml/changelog.md +++ b/checked_yaml/changelog.md @@ -1,3 +1,7 @@ +## 1.0.3-dev + +- Require at least Dart `2.6.0`. + ## 1.0.2 - Require at least Dart `2.3.0`. diff --git a/checked_yaml/mono_pkg.yaml b/checked_yaml/mono_pkg.yaml index 1db1b960d..ff48d74f3 100644 --- a/checked_yaml/mono_pkg.yaml +++ b/checked_yaml/mono_pkg.yaml @@ -1,6 +1,6 @@ # See https://github.com/dart-lang/mono_repo for details dart: -- 2.3.0 +- 2.6.0 - dev stages: @@ -11,7 +11,7 @@ stages: dart: [dev] - group: - dartanalyzer: --fatal-warnings . - dart: [2.3.0] + dart: [2.6.0] - unit_test: - test diff --git a/checked_yaml/pubspec.yaml b/checked_yaml/pubspec.yaml index a962f6e48..6dbf7fd40 100644 --- a/checked_yaml/pubspec.yaml +++ b/checked_yaml/pubspec.yaml @@ -1,12 +1,12 @@ name: checked_yaml -version: 1.0.2 +version: 1.0.3-dev author: Dart Team description: >- Generate more helpful exceptions when decoding YAML documents using package:json_serializable and package:yaml. homepage: https://github.com/dart-lang/json_serializable environment: - sdk: '>=2.3.0 <3.0.0' + sdk: '>=2.6.0 <3.0.0' dependencies: json_annotation: '>=2.2.0 <4.0.0' From e8d6b8d29ed600c3c9ed47be3e6a68c36ff9f5c4 Mon Sep 17 00:00:00 2001 From: Peter Fern Date: Thu, 13 Feb 2020 02:42:13 +1100 Subject: [PATCH 179/569] Export DurationHelper (#602) --- json_serializable/lib/type_helper.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/json_serializable/lib/type_helper.dart b/json_serializable/lib/type_helper.dart index 21b2097ae..d29317cd1 100644 --- a/json_serializable/lib/type_helper.dart +++ b/json_serializable/lib/type_helper.dart @@ -7,6 +7,7 @@ export 'src/type_helper.dart' show TypeHelperContext, TypeHelper; export 'src/type_helpers/big_int_helper.dart'; export 'src/type_helpers/convert_helper.dart'; export 'src/type_helpers/date_time_helper.dart'; +export 'src/type_helpers/duration_helper.dart'; export 'src/type_helpers/enum_helper.dart'; export 'src/type_helpers/iterable_helper.dart'; export 'src/type_helpers/json_converter_helper.dart'; From 38ade4e0d1301823c8d68515cf802456ccca392a Mon Sep 17 00:00:00 2001 From: Peter Fern Date: Wed, 19 Feb 2020 04:32:22 +1100 Subject: [PATCH 180/569] Export TypeHelperContextWithConfig in json_serializable/type_helper.dart (#603) --- json_serializable/CHANGELOG.md | 7 +++++++ json_serializable/lib/type_helper.dart | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index aa8e02181..696e47895 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,10 @@ +## unreleased + +- Export the following `TypeHelper` implementations and interfaces in + `package:json_serializable/type_helper.dart`: + - `DurationHelper` + - `TypeHelperContextWithConfig` + ## 3.2.5 - Fix lint affecting `pub.dev` score. diff --git a/json_serializable/lib/type_helper.dart b/json_serializable/lib/type_helper.dart index d29317cd1..6d574f4b5 100644 --- a/json_serializable/lib/type_helper.dart +++ b/json_serializable/lib/type_helper.dart @@ -3,7 +3,8 @@ // BSD-style license that can be found in the LICENSE file. export 'src/shared_checkers.dart' show simpleJsonTypeChecker, typeArgumentsOf; -export 'src/type_helper.dart' show TypeHelperContext, TypeHelper; +export 'src/type_helper.dart' + show TypeHelperContext, TypeHelperContextWithConfig, TypeHelper; export 'src/type_helpers/big_int_helper.dart'; export 'src/type_helpers/convert_helper.dart'; export 'src/type_helpers/date_time_helper.dart'; From 21d8a7dde8f68489378fa6232659a4a4fbb5062b Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 18 Feb 2020 11:03:53 -0800 Subject: [PATCH 181/569] Enable and fix a number of lints (#607) --- _test_yaml/test/yaml_test.dart | 5 +- analysis_options.yaml | 19 ++++++ checked_yaml/test/readme_test.dart | 4 +- example/test/readme_test.dart | 2 +- json_serializable/lib/src/constants.dart | 2 +- json_serializable/lib/src/decode_helper.dart | 60 ++++++++++--------- json_serializable/lib/src/encoder_helper.dart | 42 ++++++------- json_serializable/lib/src/field_helpers.dart | 13 ++-- json_serializable/lib/src/helper_core.dart | 7 ++- .../lib/src/json_literal_generator.dart | 13 ++-- .../lib/src/type_helper_ctx.dart | 2 +- .../lib/src/type_helpers/iterable_helper.dart | 4 +- json_serializable/lib/src/utils.dart | 2 +- json_serializable/test/config_test.dart | 3 +- .../test/custom_configuration_test.dart | 48 ++++++++------- .../test/json_serializable_test.dart | 2 +- .../test/kitchen_sink/kitchen_sink_test.dart | 11 ++-- .../src/_json_serializable_test_input.dart | 4 +- .../test/src/default_value_input.dart | 12 ++-- json_serializable/test/test_utils.dart | 3 +- json_serializable/tool/test_builder.dart | 2 +- 21 files changed, 146 insertions(+), 114 deletions(-) diff --git a/_test_yaml/test/yaml_test.dart b/_test_yaml/test/yaml_test.dart index adba72014..eed0cc45a 100644 --- a/_test_yaml/test/yaml_test.dart +++ b/_test_yaml/test/yaml_test.dart @@ -62,7 +62,7 @@ void main() { }); } -final _badConfigs = const { +const _badConfigs = { r''' builders: - a @@ -178,7 +178,8 @@ T roundTripObject( String loudEncode(Object object) { try { return const JsonEncoder.withIndent(' ').convert(object); - } on JsonUnsupportedObjectError catch (e) { + } on JsonUnsupportedObjectError catch (e) // ignore: avoid_catching_errors + { var error = e; do { final cause = error.cause; diff --git a/analysis_options.yaml b/analysis_options.yaml index ba6768122..804e4f82c 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -7,21 +7,27 @@ linter: - always_declare_return_types - always_require_non_null_named_parameters - annotate_overrides + - avoid_catching_errors - avoid_empty_else - avoid_function_literals_in_foreach_calls - avoid_init_to_null - avoid_null_checks_in_equality_operators + - avoid_private_typedef_functions + - avoid_redundant_argument_values - avoid_relative_lib_imports - avoid_renaming_method_parameters - avoid_return_types_on_setters - avoid_returning_null + - avoid_returning_null_for_void - avoid_shadowing_type_parameters - avoid_types_as_parameter_names - avoid_unused_constructor_parameters + - avoid_void_async - await_only_futures - camel_case_extensions - camel_case_types - cancel_subscriptions + - cascade_invocations - comment_references - constant_identifier_names - control_flow_in_finally @@ -30,6 +36,7 @@ linter: - empty_catches - empty_constructor_bodies - empty_statements + - file_names - hash_and_equals - implementation_imports - invariant_booleans @@ -40,6 +47,7 @@ linter: - list_remove_unrelated_type - literal_only_boolean_expressions - no_duplicate_case_values + - no_runtimeType_toString - non_constant_identifier_names - null_closures - omit_local_variable_types @@ -49,24 +57,32 @@ linter: - package_names - package_prefixed_library_names - prefer_adjacent_string_concatenation + - prefer_asserts_in_initializer_lists - prefer_collection_literals - prefer_conditional_assignment - prefer_const_constructors + - prefer_const_declarations - prefer_contains - prefer_equal_for_default_values - prefer_final_fields - prefer_final_locals - prefer_for_elements_to_map_fromIterable + - prefer_function_declarations_over_variables - prefer_generic_function_type_aliases - prefer_if_null_operators - prefer_initializing_formals + - prefer_inlined_adds - prefer_interpolation_to_compose_strings - prefer_is_empty - prefer_is_not_empty + - prefer_is_not_operator - prefer_iterable_whereType + - prefer_null_aware_operators + - prefer_relative_imports - prefer_single_quotes - prefer_spread_collections - prefer_typing_uninitialized_variables + - prefer_void_to_null - recursive_getters - slash_for_doc_comments - sort_pub_dependencies @@ -81,10 +97,13 @@ linter: - unnecessary_new - unnecessary_null_aware_assignments - unnecessary_null_in_if_null_operators + - unnecessary_overrides - unnecessary_parenthesis - unnecessary_statements + - unnecessary_string_interpolations - unnecessary_this - unrelated_type_equality_checks - use_function_type_syntax_for_parameters - use_rethrow_when_possible - valid_regexps + - void_checks diff --git a/checked_yaml/test/readme_test.dart b/checked_yaml/test/readme_test.dart index 62ccb440d..2e05f8283 100644 --- a/checked_yaml/test/readme_test.dart +++ b/checked_yaml/test/readme_test.dart @@ -43,8 +43,8 @@ void main() { }); test('ran example', () async { - final inputContent = '{"name": "", "count": 1}'; - final errorContent = r''' + const inputContent = '{"name": "", "count": 1}'; + const errorContent = r''' Unhandled exception: ParsedYamlException: line 1, column 10: Unsupported value for "name". Cannot be empty. ╷ diff --git a/example/test/readme_test.dart b/example/test/readme_test.dart index bf3e9729b..414b97af9 100644 --- a/example/test/readme_test.dart +++ b/example/test/readme_test.dart @@ -18,7 +18,7 @@ void _expect(String fileName) { }); } -final _pubspecContent = r''' +const _pubspecContent = r''' dependencies: json_annotation: ^3.0.0 diff --git a/json_serializable/lib/src/constants.dart b/json_serializable/lib/src/constants.dart index aba1a821b..2a4b34de3 100644 --- a/json_serializable/lib/src/constants.dart +++ b/json_serializable/lib/src/constants.dart @@ -3,7 +3,7 @@ // BSD-style license that can be found in the LICENSE file. /// Name used for closure argument when generating calls to `map`. -final closureArg = 'e'; +const closureArg = 'e'; const generatedLocalVarName = 'val'; const toJsonMapHelperName = 'writeNotNull'; diff --git a/json_serializable/lib/src/decode_helper.dart b/json_serializable/lib/src/decode_helper.dart index 0a99da494..72ed7b73b 100644 --- a/json_serializable/lib/src/decode_helper.dart +++ b/json_serializable/lib/src/decode_helper.dart @@ -68,12 +68,13 @@ abstract class DecodeHelper implements HelperCore { for (final field in data.fieldsToSet) { _buffer.writeln(); final safeName = safeNameAccess(accessibleFields[field]); - _buffer.write(''' - \$checkedConvert(json, $safeName, (v) => '''); - _buffer.write('val.$field = '); - _buffer.write(_deserializeForField(accessibleFields[field], - checkedProperty: true)); - _buffer.write(');'); + _buffer + ..write(''' + \$checkedConvert(json, $safeName, (v) => ''') + ..write('val.$field = ') + ..write(_deserializeForField(accessibleFields[field], + checkedProperty: true)) + ..write(');'); } _buffer.write('''\n return val; @@ -91,9 +92,7 @@ abstract class DecodeHelper implements HelperCore { fieldKeyMapArg = ', fieldKeyMap: const $mapLiteral'; } - _buffer.write(fieldKeyMapArg); - - _buffer.write(')'); + _buffer..write(fieldKeyMapArg)..write(')'); } else { data = _writeConstructorInvocation( element, @@ -114,13 +113,13 @@ abstract class DecodeHelper implements HelperCore { _buffer.write(''' return ${data.content}'''); for (final field in data.fieldsToSet) { - _buffer.writeln(); - _buffer.write(' ..$field = '); - _buffer.write(deserializeFun(field)); + _buffer + ..writeln() + ..write(' ..$field = ') + ..write(deserializeFun(field)); } } - _buffer.writeln(';\n}'); - _buffer.writeln(); + _buffer..writeln(';\n}')..writeln(); return CreateFactoryResult( _buffer.toString(), data.usedCtorParamsAndFields); @@ -183,7 +182,8 @@ abstract class DecodeHelper implements HelperCore { .deserialize(targetType, 'json[$jsonKeyName]') .toString(); } - } on UnsupportedTypeError catch (e) { + } on UnsupportedTypeError catch (e) // ignore: avoid_catching_errors + { throw createInvalidGenerationError('fromJson', field, e); } @@ -273,23 +273,25 @@ _ConstructorData _writeConstructorInvocation( final remainingFieldsForInvocationBody = writableFields.toSet().difference(usedCtorParamsAndFields); - final buffer = StringBuffer(); - buffer.write('$className${genericClassArguments(classElement, false)}('); + final buffer = StringBuffer() + ..write('$className${genericClassArguments(classElement, false)}('); if (constructorArguments.isNotEmpty) { - buffer.writeln(); - buffer.writeAll(constructorArguments.map((paramElement) { - final content = - deserializeForField(paramElement.name, ctorParam: paramElement); - return ' $content,\n'; - })); + buffer + ..writeln() + ..writeAll(constructorArguments.map((paramElement) { + final content = + deserializeForField(paramElement.name, ctorParam: paramElement); + return ' $content,\n'; + })); } if (namedConstructorArguments.isNotEmpty) { - buffer.writeln(); - buffer.writeAll(namedConstructorArguments.map((paramElement) { - final value = - deserializeForField(paramElement.name, ctorParam: paramElement); - return ' ${paramElement.name}: $value,\n'; - })); + buffer + ..writeln() + ..writeAll(namedConstructorArguments.map((paramElement) { + final value = + deserializeForField(paramElement.name, ctorParam: paramElement); + return ' ${paramElement.name}: $value,\n'; + })); } buffer.write(')'); diff --git a/json_serializable/lib/src/encoder_helper.dart b/json_serializable/lib/src/encoder_helper.dart index 4d6b888a0..36238cb60 100644 --- a/json_serializable/lib/src/encoder_helper.dart +++ b/json_serializable/lib/src/encoder_helper.dart @@ -36,25 +36,24 @@ abstract class EncodeHelper implements HelperCore { } void _writeToJsonSimple(StringBuffer buffer, Iterable fields) { - buffer.writeln('=> {'); - - buffer.writeAll(fields.map((field) { - final access = _fieldAccess(field); - final value = - '${safeNameAccess(field)}: ${_serializeField(field, access)}'; - return ' $value,\n'; - })); - - buffer.writeln('};'); + buffer + ..writeln('=> {') + ..writeAll(fields.map((field) { + final access = _fieldAccess(field); + final value = + '${safeNameAccess(field)}: ${_serializeField(field, access)}'; + return ' $value,\n'; + })) + ..writeln('};'); } static const _toJsonParamName = 'instance'; void _writeToJsonWithNullChecks( StringBuffer buffer, Iterable fields) { - buffer.writeln('{'); - - buffer.writeln(' final $generatedLocalVarName = {'); + buffer + ..writeln('{') + ..writeln(' final $generatedLocalVarName = {'); // Note that the map literal is left open above. As long as target fields // don't need to be intercepted by the `only if null` logic, write them @@ -84,12 +83,13 @@ abstract class EncodeHelper implements HelperCore { } else { if (directWrite) { // close the still-open map literal - buffer.writeln(' };'); - buffer.writeln(); + buffer + ..writeln(' };') + ..writeln() - // write the helper to be used by all following null-excluding - // fields - buffer.writeln(''' + // write the helper to be used by all following null-excluding + // fields + ..writeln(''' void $toJsonMapHelperName(String key, dynamic value) { if (value != null) { $generatedLocalVarName[key] = value; @@ -103,8 +103,7 @@ abstract class EncodeHelper implements HelperCore { } } - buffer.writeln(' return $generatedLocalVarName;'); - buffer.writeln(' }'); + buffer..writeln(' return $generatedLocalVarName;')..writeln(' }'); } String _serializeField(FieldElement field, String accessExpression) { @@ -112,7 +111,8 @@ abstract class EncodeHelper implements HelperCore { return getHelperContext(field) .serialize(field.type, accessExpression) .toString(); - } on UnsupportedTypeError catch (e) { + } on UnsupportedTypeError catch (e) // ignore: avoid_catching_errors + { throw createInvalidGenerationError('toJson', field, e); } } diff --git a/json_serializable/lib/src/field_helpers.dart b/json_serializable/lib/src/field_helpers.dart index 2d298dbfb..fe425dfab 100644 --- a/json_serializable/lib/src/field_helpers.dart +++ b/json_serializable/lib/src/field_helpers.dart @@ -3,10 +3,9 @@ // BSD-style license that can be found in the LICENSE file. import 'package:analyzer/dart/element/element.dart'; - -// ignore: implementation_imports -import 'package:analyzer/src/dart/element/inheritance_manager3.dart' - show InheritanceManager3; +import 'package:analyzer/src/dart/element/inheritance_manager3.dart' // ignore: implementation_imports + show + InheritanceManager3; import 'package:source_gen/source_gen.dart'; import 'utils.dart'; @@ -106,10 +105,8 @@ Iterable createSortedFieldSet(ClassElement element) { final fields = allFields .map((e) => _FieldSet(elementInstanceFields[e], inheritedFields[e])) - .toList(); - - // Sort the fields using the `compare` implementation in _FieldSet - fields.sort(); + .toList() + ..sort(); return fields.map((fs) => fs.field).toList(); } diff --git a/json_serializable/lib/src/helper_core.dart b/json_serializable/lib/src/helper_core.dart index b540c2de8..5e51fdc2b 100644 --- a/json_serializable/lib/src/helper_core.dart +++ b/json_serializable/lib/src/helper_core.dart @@ -62,8 +62,11 @@ InvalidGenerationSourceError createInvalidGenerationError( } message = '$message.\n${e.reason}'; - final todo = 'Make sure all of the types are serializable.'; - return InvalidGenerationSourceError(message, todo: todo, element: field); + return InvalidGenerationSourceError( + message, + todo: 'Make sure all of the types are serializable.', + element: field, + ); } /// Returns a [String] representing the type arguments that exist on diff --git a/json_serializable/lib/src/json_literal_generator.dart b/json_serializable/lib/src/json_literal_generator.dart index 3498889ca..1cce1c1d7 100644 --- a/json_serializable/lib/src/json_literal_generator.dart +++ b/json_serializable/lib/src/json_literal_generator.dart @@ -7,11 +7,10 @@ import 'dart:convert'; import 'package:analyzer/dart/element/element.dart'; import 'package:build/build.dart'; +import 'package:json_annotation/json_annotation.dart'; import 'package:path/path.dart' as p; import 'package:source_gen/source_gen.dart'; -import 'package:json_annotation/json_annotation.dart'; - import 'utils.dart'; class JsonLiteralGenerator extends GeneratorForAnnotation { @@ -59,8 +58,7 @@ String jsonLiteralAsDart(dynamic value) { } String jsonMapAsDart(Map value) { - final buffer = StringBuffer(); - buffer.write('{'); + final buffer = StringBuffer()..write('{'); var first = true; value.forEach((k, v) { @@ -69,9 +67,10 @@ String jsonMapAsDart(Map value) { } else { buffer.writeln(','); } - buffer.write(escapeDartString(k as String)); - buffer.write(': '); - buffer.write(jsonLiteralAsDart(v)); + buffer + ..write(escapeDartString(k as String)) + ..write(': ') + ..write(jsonLiteralAsDart(v)); }); buffer.write('}'); diff --git a/json_serializable/lib/src/type_helper_ctx.dart b/json_serializable/lib/src/type_helper_ctx.dart index 3262dd05e..c58121655 100644 --- a/json_serializable/lib/src/type_helper_ctx.dart +++ b/json_serializable/lib/src/type_helper_ctx.dart @@ -68,7 +68,7 @@ class TypeHelperCtx targetType, expression, _notSupportedWithTypeHelpersMsg)); } -final _notSupportedWithTypeHelpersMsg = +const _notSupportedWithTypeHelpersMsg = 'None of the provided `TypeHelper` instances support the defined type.'; class _ConvertPair { diff --git a/json_serializable/lib/src/type_helpers/iterable_helper.dart b/json_serializable/lib/src/type_helpers/iterable_helper.dart index e5b6f5e99..3ea686703 100644 --- a/json_serializable/lib/src/type_helpers/iterable_helper.dart +++ b/json_serializable/lib/src/type_helpers/iterable_helper.dart @@ -92,5 +92,5 @@ class IterableHelper extends TypeHelper { } } -final _coreListChecker = const TypeChecker.fromUrl('dart:core#List'); -final _coreSetChecker = const TypeChecker.fromUrl('dart:core#Set'); +const _coreListChecker = TypeChecker.fromUrl('dart:core#List'); +const _coreSetChecker = TypeChecker.fromUrl('dart:core#Set'); diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index 1ce30f9ef..ef30ca54f 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -11,7 +11,7 @@ import 'package:source_gen/source_gen.dart'; import 'helper_core.dart'; -final _jsonKeyChecker = const TypeChecker.fromRuntime(JsonKey); +const _jsonKeyChecker = TypeChecker.fromRuntime(JsonKey); DartObject jsonKeyAnnotation(FieldElement element) => _jsonKeyChecker.firstAnnotationOfExact(element) ?? diff --git a/json_serializable/test/config_test.dart b/json_serializable/test/config_test.dart index ab9d79f35..a26d32b72 100644 --- a/json_serializable/test/config_test.dart +++ b/json_serializable/test/config_test.dart @@ -112,7 +112,8 @@ void main() { config[entry.key] = entry.value; final lastLine = entry.key == 'field_rename' - ? '`42` is not one of the supported values: none, kebab, snake, pascal' + ? '`42` is not one of the supported values: none, kebab, snake, ' + 'pascal' : "type 'int' is not a subtype of type 'bool' in type cast"; final matcher = isA().having( diff --git a/json_serializable/test/custom_configuration_test.dart b/json_serializable/test/custom_configuration_test.dart index e5923b584..87857934b 100644 --- a/json_serializable/test/custom_configuration_test.dart +++ b/json_serializable/test/custom_configuration_test.dart @@ -19,7 +19,7 @@ import 'shared_config.dart'; LibraryReader _libraryReader; -void main() async { +Future main() async { initializeBuildLogTracking(); _libraryReader = await initializeLibraryReaderForDirectory( p.join('test', 'test_sources'), @@ -31,7 +31,7 @@ void main() async { }); group('configuration', () { - Future runWithConfigAndLogger( + Future runWithConfigAndLogger( JsonSerializable config, String className) async { await generateForElement( JsonSerializableGenerator( @@ -86,26 +86,28 @@ void main() async { }); test( - 'explicit values in annotation override corresponding settings in config', - () async { - await runWithConfigAndLogger( - JsonSerializable.fromJson(generatorConfigNonDefaultJson), - 'ConfigurationExplicitDefaults'); - - expect(_ConfigLogger.configurations, hasLength(2)); - expect(_ConfigLogger.configurations.first, - same(_ConfigLogger.configurations.last)); - - // The effective configuration should be non-Default configuration, but - // with all fields set from JsonSerializable as the defaults - - final expected = Map.from(generatorConfigNonDefaultJson); - for (var jsonSerialKey in jsonSerializableFields) { - expected[jsonSerialKey] = generatorConfigDefaultJson[jsonSerialKey]; - } + 'explicit values in annotation override corresponding settings in config', + () async { + await runWithConfigAndLogger( + JsonSerializable.fromJson(generatorConfigNonDefaultJson), + 'ConfigurationExplicitDefaults'); + + expect(_ConfigLogger.configurations, hasLength(2)); + expect(_ConfigLogger.configurations.first, + same(_ConfigLogger.configurations.last)); + + // The effective configuration should be non-Default configuration, but + // with all fields set from JsonSerializable as the defaults + + final expected = + Map.from(generatorConfigNonDefaultJson); + for (var jsonSerialKey in jsonSerializableFields) { + expected[jsonSerialKey] = generatorConfigDefaultJson[jsonSerialKey]; + } - expect(_ConfigLogger.configurations.first.toJson(), expected); - }); + expect(_ConfigLogger.configurations.first.toJson(), expected); + }, + ); }); } @@ -123,7 +125,7 @@ void _registerTests(JsonSerializable generator) { final output = await _runForElementNamed( const JsonSerializable(), 'TrivialNestedNullable'); - final expected = r''' + const expected = r''' Map _$TrivialNestedNullableToJson( TrivialNestedNullable instance) => { @@ -138,7 +140,7 @@ Map _$TrivialNestedNullableToJson( final output = await _runForElementNamed( const JsonSerializable(), 'TrivialNestedNonNullable'); - final expected = r''' + const expected = r''' Map _$TrivialNestedNonNullableToJson( TrivialNestedNonNullable instance) => { diff --git a/json_serializable/test/json_serializable_test.dart b/json_serializable/test/json_serializable_test.dart index 746d31b8c..0d970229e 100644 --- a/json_serializable/test/json_serializable_test.dart +++ b/json_serializable/test/json_serializable_test.dart @@ -8,7 +8,7 @@ import 'package:path/path.dart' as p; import 'package:source_gen_test/source_gen_test.dart'; import 'package:test/test.dart'; -void main() async { +Future main() async { initializeBuildLogTracking(); final reader = await initializeLibraryReaderForDirectory( p.join('test', 'src'), diff --git a/json_serializable/test/kitchen_sink/kitchen_sink_test.dart b/json_serializable/test/kitchen_sink/kitchen_sink_test.dart index 6351ddedb..ce7ba4d1b 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink_test.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink_test.dart @@ -290,10 +290,13 @@ Matcher _getMatcher(bool checked, String expectedKey, bool checkedAssignment) { innerMatcher = _checkedMatcher(expectedKey); } else { innerMatcher = anyOf( - isCastError, - _isATypeError, - _isAUnrecognizedKeysException( - 'Unrecognized keys: [invalid_key]; supported keys: [value, custom_field]')); + isCastError, + _isATypeError, + _isAUnrecognizedKeysException( + 'Unrecognized keys: [invalid_key]; supported keys: ' + '[value, custom_field]', + ), + ); if (checkedAssignment) { switch (expectedKey) { diff --git a/json_serializable/test/src/_json_serializable_test_input.dart b/json_serializable/test/src/_json_serializable_test_input.dart index 0e0a658dd..3fd9dbe49 100644 --- a/json_serializable/test/src/_json_serializable_test_input.dart +++ b/json_serializable/test/src/_json_serializable_test_input.dart @@ -39,7 +39,7 @@ const theAnswer = 42; @ShouldThrow('Generator cannot target `annotatedMethod`.', todo: 'Remove the JsonSerializable annotation from `annotatedMethod`.') @JsonSerializable() -void annotatedMethod() => null; +Object annotatedMethod() => null; @ShouldGenerate( r''' @@ -56,7 +56,7 @@ Map _$OnlyStaticMembersToJson(OnlyStaticMembers instance) => class OnlyStaticMembers { // To ensure static members are not considered for serialization. static const answer = 42; - static final reason = 42; + static final reason = DateTime.now(); static int get understand => 42; } diff --git a/json_serializable/test/src/default_value_input.dart b/json_serializable/test/src/default_value_input.dart index e6f693578..724ebb7af 100644 --- a/json_serializable/test/src/default_value_input.dart +++ b/json_serializable/test/src/default_value_input.dart @@ -125,7 +125,8 @@ class DefaultWithToJsonClass { static int _fromJson(String input) => 41; } -@ShouldGenerate(r''' +@ShouldGenerate( + r''' DefaultWithDisallowNullRequiredClass _$DefaultWithDisallowNullRequiredClassFromJson(Map json) { $checkKeys(json, @@ -133,9 +134,12 @@ DefaultWithDisallowNullRequiredClass return DefaultWithDisallowNullRequiredClass() ..theField = json['theField'] as int ?? 7; } -''', expectedLogItems: [ - 'The `defaultValue` on field `theField` will have no effect because both `disallowNullValue` and `required` are set to `true`.' -]) +''', + expectedLogItems: [ + 'The `defaultValue` on field `theField` will have no effect because both ' + '`disallowNullValue` and `required` are set to `true`.', + ], +) @JsonSerializable(createToJson: false) class DefaultWithDisallowNullRequiredClass { @JsonKey(defaultValue: 7, disallowNullValue: true, required: true) diff --git a/json_serializable/test/test_utils.dart b/json_serializable/test/test_utils.dart index 7cd84da93..87ac687eb 100644 --- a/json_serializable/test/test_utils.dart +++ b/json_serializable/test/test_utils.dart @@ -25,7 +25,8 @@ T roundTripObject(T object, T Function(Map json) factory) { String loudEncode(Object object) { try { return const JsonEncoder.withIndent(' ').convert(object); - } on JsonUnsupportedObjectError catch (e) { + } on JsonUnsupportedObjectError catch (e) // ignore: avoid_catching_errors + { var error = e; do { final cause = error.cause; diff --git a/json_serializable/tool/test_builder.dart b/json_serializable/tool/test_builder.dart index c2bff9285..86a93f6f5 100644 --- a/json_serializable/tool/test_builder.dart +++ b/json_serializable/tool/test_builder.dart @@ -14,7 +14,7 @@ import 'package:yaml/yaml.dart'; final _formatter = DartFormatter(); Builder internal([_]) { - final builder = const _SmartBuilder(); + const builder = _SmartBuilder(); _validateBuilder(builder); return builder; } From 6a628c922d025ace8e2c25358b6ccea2df5f6317 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 18 Feb 2020 12:12:30 -0800 Subject: [PATCH 182/569] Tiny whitespace cleanup (#609) --- .../lib/src/json_part_builder.dart | 15 ++-- .../lib/src/json_serializable_generator.dart | 77 +++++++++++-------- .../lib/src/type_helper_ctx.dart | 31 +++++--- 3 files changed, 72 insertions(+), 51 deletions(-) diff --git a/json_serializable/lib/src/json_part_builder.dart b/json_serializable/lib/src/json_part_builder.dart index e0db6de3e..104d2d2b7 100644 --- a/json_serializable/lib/src/json_part_builder.dart +++ b/json_serializable/lib/src/json_part_builder.dart @@ -14,9 +14,12 @@ import 'json_serializable_generator.dart'; /// /// [formatOutput] is called to format the generated code. If not provided, /// the default Dart code formatter is used. -Builder jsonPartBuilder( - {String Function(String code) formatOutput, JsonSerializable config}) => - SharedPartBuilder([ - JsonSerializableGenerator(config: config), - const JsonLiteralGenerator() - ], 'json_serializable', formatOutput: formatOutput); +Builder jsonPartBuilder({ + String Function(String code) formatOutput, + JsonSerializable config, +}) => + SharedPartBuilder( + [JsonSerializableGenerator(config: config), const JsonLiteralGenerator()], + 'json_serializable', + formatOutput: formatOutput, + ); diff --git a/json_serializable/lib/src/json_serializable_generator.dart b/json_serializable/lib/src/json_serializable_generator.dart index 8f02ba072..230457e72 100644 --- a/json_serializable/lib/src/json_serializable_generator.dart +++ b/json_serializable/lib/src/json_serializable_generator.dart @@ -74,13 +74,16 @@ class JsonSerializableGenerator Iterable typeHelpers, {JsonSerializable config}) => JsonSerializableGenerator( - config: config, - typeHelpers: - List.unmodifiable(typeHelpers.followedBy(_defaultHelpers))); + config: config, + typeHelpers: List.unmodifiable(typeHelpers.followedBy(_defaultHelpers)), + ); @override Iterable generateForAnnotatedElement( - Element element, ConstantReader annotation, BuildStep buildStep) { + Element element, + ConstantReader annotation, + BuildStep buildStep, + ) { if (element is! ClassElement) { final name = element.name; throw InvalidGenerationSourceError('Generator cannot target `$name`.', @@ -99,8 +102,10 @@ class _GeneratorHelper extends HelperCore with EncodeHelper, DecodeHelper { final _addedMembers = {}; _GeneratorHelper( - this._generator, ClassElement element, ConstantReader annotation) - : super(element, mergeConfig(_generator.config, annotation)); + this._generator, + ClassElement element, + ConstantReader annotation, + ) : super(element, mergeConfig(_generator.config, annotation)); @override void addMember(String memberContent) { @@ -120,23 +125,26 @@ class _GeneratorHelper extends HelperCore with EncodeHelper, DecodeHelper { final unavailableReasons = {}; final accessibleFields = sortedFields.fold>( - {}, (map, field) { - if (!field.isPublic) { - unavailableReasons[field.name] = 'It is assigned to a private field.'; - } else if (field.getter == null) { - assert(field.setter != null); - unavailableReasons[field.name] = - 'Setter-only properties are not supported.'; - log.warning('Setters are ignored: ${element.name}.${field.name}'); - } else if (jsonKeyFor(field).ignore) { - unavailableReasons[field.name] = 'It is assigned to an ignored field.'; - } else { - assert(!map.containsKey(field.name)); - map[field.name] = field; - } - - return map; - }); + {}, + (map, field) { + if (!field.isPublic) { + unavailableReasons[field.name] = 'It is assigned to a private field.'; + } else if (field.getter == null) { + assert(field.setter != null); + unavailableReasons[field.name] = + 'Setter-only properties are not supported.'; + log.warning('Setters are ignored: ${element.name}.${field.name}'); + } else if (jsonKeyFor(field).ignore) { + unavailableReasons[field.name] = + 'It is assigned to an ignored field.'; + } else { + assert(!map.containsKey(field.name)); + map[field.name] = field; + } + + return map; + }, + ); var accessibleFieldSet = accessibleFields.values.toSet(); if (config.createFactory) { @@ -152,16 +160,19 @@ class _GeneratorHelper extends HelperCore with EncodeHelper, DecodeHelper { // Check for duplicate JSON keys due to colliding annotations. // We do this now, since we have a final field list after any pruning done // by `_writeCtor`. - accessibleFieldSet.fold({}, (Set set, fe) { - final jsonKey = nameAccess(fe); - if (!set.add(jsonKey)) { - throw InvalidGenerationSourceError( - 'More than one field has the JSON key `$jsonKey`.', - todo: 'Check the `JsonKey` annotations on fields.', - element: fe); - } - return set; - }); + accessibleFieldSet.fold( + {}, + (Set set, fe) { + final jsonKey = nameAccess(fe); + if (!set.add(jsonKey)) { + throw InvalidGenerationSourceError( + 'More than one field has the JSON key `$jsonKey`.', + todo: 'Check the `JsonKey` annotations on fields.', + element: fe); + } + return set; + }, + ); if (config.createToJson) { yield* createToJson(accessibleFieldSet); diff --git a/json_serializable/lib/src/type_helper_ctx.dart b/json_serializable/lib/src/type_helper_ctx.dart index c58121655..3c80a378b 100644 --- a/json_serializable/lib/src/type_helper_ctx.dart +++ b/json_serializable/lib/src/type_helper_ctx.dart @@ -51,21 +51,28 @@ class TypeHelperCtx @override Object serialize(DartType targetType, String expression) => _run( - targetType, - expression, - (TypeHelper th) => th.serialize(targetType, expression, this)); + targetType, + expression, + (TypeHelper th) => th.serialize(targetType, expression, this), + ); @override Object deserialize(DartType targetType, String expression) => _run( - targetType, - expression, - (TypeHelper th) => th.deserialize(targetType, expression, this)); - - Object _run(DartType targetType, String expression, - Object Function(TypeHelper) invoke) => - _helperCore.allTypeHelpers.map(invoke).firstWhere((r) => r != null, - orElse: () => throw UnsupportedTypeError( - targetType, expression, _notSupportedWithTypeHelpersMsg)); + targetType, + expression, + (TypeHelper th) => th.deserialize(targetType, expression, this), + ); + + Object _run( + DartType targetType, + String expression, + Object Function(TypeHelper) invoke, + ) => + _helperCore.allTypeHelpers.map(invoke).firstWhere( + (r) => r != null, + orElse: () => throw UnsupportedTypeError( + targetType, expression, _notSupportedWithTypeHelpersMsg), + ); } const _notSupportedWithTypeHelpersMsg = From 2f1318c0f1add42b468eb02e989032fd2684b290 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 3 Mar 2020 08:31:30 -0800 Subject: [PATCH 183/569] enable and fix 3 more lints (#615) --- analysis_options.yaml | 3 +++ json_serializable/lib/src/encoder_helper.dart | 4 ++-- json_serializable/lib/src/type_helpers/enum_helper.dart | 4 ++-- json_serializable/lib/src/type_helpers/map_helper.dart | 9 +++++---- json_serializable/test/generic_files/generic_class.dart | 5 ++--- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index 804e4f82c..74a2d9a9a 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -46,6 +46,7 @@ linter: - library_prefixes - list_remove_unrelated_type - literal_only_boolean_expressions + - missing_whitespace_between_adjacent_strings - no_duplicate_case_values - no_runtimeType_toString - non_constant_identifier_names @@ -83,6 +84,7 @@ linter: - prefer_spread_collections - prefer_typing_uninitialized_variables - prefer_void_to_null + - provide_deprecation_message - recursive_getters - slash_for_doc_comments - sort_pub_dependencies @@ -105,5 +107,6 @@ linter: - unrelated_type_equality_checks - use_function_type_syntax_for_parameters - use_rethrow_when_possible + - use_string_buffers - valid_regexps - void_checks diff --git a/json_serializable/lib/src/encoder_helper.dart b/json_serializable/lib/src/encoder_helper.dart index 36238cb60..da7aeddf9 100644 --- a/json_serializable/lib/src/encoder_helper.dart +++ b/json_serializable/lib/src/encoder_helper.dart @@ -19,8 +19,8 @@ abstract class EncodeHelper implements HelperCore { final buffer = StringBuffer(); final functionName = '${prefix}ToJson${genericClassArgumentsImpl(true)}'; - buffer.write('Map $functionName' - '($targetClassReference $_toJsonParamName) '); + buffer.write('Map ' + '$functionName($targetClassReference $_toJsonParamName) '); final writeNaive = accessibleFields.every(_writeJsonValueNaive); diff --git a/json_serializable/lib/src/type_helpers/enum_helper.dart b/json_serializable/lib/src/type_helpers/enum_helper.dart index 7188aceba..bf1128fcd 100644 --- a/json_serializable/lib/src/type_helpers/enum_helper.dart +++ b/json_serializable/lib/src/type_helpers/enum_helper.dart @@ -77,8 +77,8 @@ String _enumValueMapFromType(DartType targetType) { } final items = enumMap.entries - .map((e) => - ' ${targetType.element.name}.${e.key.name}: ${jsonLiteralAsDart(e.value)},') + .map((e) => ' ${targetType.element.name}.${e.key.name}: ' + '${jsonLiteralAsDart(e.value)},') .join(); return 'const ${_constMapName(targetType)} = {\n$items\n};'; diff --git a/json_serializable/lib/src/type_helpers/map_helper.dart b/json_serializable/lib/src/type_helpers/map_helper.dart index 9a0d89dbf..a96aff455 100644 --- a/json_serializable/lib/src/type_helpers/map_helper.dart +++ b/json_serializable/lib/src/type_helpers/map_helper.dart @@ -42,7 +42,8 @@ class MapHelper extends TypeHelper { final optionalQuestion = context.nullable ? '?' : ''; return '$expression$optionalQuestion' - '.map(($_keyParam, $closureArg) => MapEntry($subKeyValue, $subFieldValue))'; + '.map(($_keyParam, $closureArg) => ' + 'MapEntry($subKeyValue, $subFieldValue))'; } @override @@ -69,8 +70,8 @@ class MapHelper extends TypeHelper { return '$expression as Map'; } } else { - // this is the trivial case. Do a runtime cast to the known type of JSON - // map values - `Map` + // this is the trivial case. Do a runtime cast to the known type of + // JSON map values - `Map` return '$expression as Map'; } } @@ -107,7 +108,7 @@ class MapHelper extends TypeHelper { keyUsage = toFromString.deserialize(keyArg, keyUsage, false, true); } - return '($expression $mapCast)$optionalQuestion.map(' + return '($expression $mapCast)$optionalQuestion.map( ' '($_keyParam, $closureArg) => MapEntry($keyUsage, $itemSubVal),)'; } } diff --git a/json_serializable/test/generic_files/generic_class.dart b/json_serializable/test/generic_files/generic_class.dart index 4d39dba4f..e6dbe12c1 100644 --- a/json_serializable/test/generic_files/generic_class.dart +++ b/json_serializable/test/generic_files/generic_class.dart @@ -101,7 +101,6 @@ class _DurationListMillisecondConverter List fromJson(int json) => [Duration(milliseconds: json)]; @override - int toJson(List object) => object?.fold(0, (sum, obj) { - return sum + obj.inMilliseconds; - }); + int toJson(List object) => + object?.fold(0, (sum, obj) => sum + obj.inMilliseconds); } From 4e89afeb60530fe8c9e309e9325a75ab6d3ab523 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 3 Mar 2020 08:58:59 -0800 Subject: [PATCH 184/569] Fix generated documentation (#614) --- json_serializable/README.md | 40 ++++++++++++++++++------------------ json_serializable/doc/doc.md | 40 ++++++++++++++++++------------------ 2 files changed, 40 insertions(+), 40 deletions(-) diff --git a/json_serializable/README.md b/json_serializable/README.md index 32134db82..53c7e66ca 100644 --- a/json_serializable/README.md +++ b/json_serializable/README.md @@ -91,26 +91,26 @@ is generated: | | | [JsonKey.toJson] | | | | [JsonKey.unknownEnumValue] | -[JsonSerializable.anyMap]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/anyMap.html -[JsonSerializable.checked]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/checked.html -[JsonSerializable.createFactory]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/createFactory.html -[JsonSerializable.createToJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/createToJson.html -[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html -[JsonSerializable.explicitToJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/explicitToJson.html -[JsonSerializable.fieldRename]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/fieldRename.html -[JsonSerializable.ignoreUnannotated]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/ignoreUnannotated.html -[JsonSerializable.includeIfNull]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/includeIfNull.html -[JsonKey.includeIfNull]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/includeIfNull.html -[JsonSerializable.nullable]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/nullable.html -[JsonKey.nullable]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/nullable.html -[JsonKey.defaultValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/defaultValue.html -[JsonKey.disallowNullValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/disallowNullValue.html -[JsonKey.fromJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/fromJson.html -[JsonKey.ignore]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/ignore.html -[JsonKey.name]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/name.html -[JsonKey.required]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/required.html -[JsonKey.toJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/toJson.html -[JsonKey.unknownEnumValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/unknownEnumValue.html +[JsonSerializable.anyMap]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonSerializable/anyMap.html +[JsonSerializable.checked]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonSerializable/checked.html +[JsonSerializable.createFactory]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonSerializable/createFactory.html +[JsonSerializable.createToJson]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonSerializable/createToJson.html +[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html +[JsonSerializable.explicitToJson]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonSerializable/explicitToJson.html +[JsonSerializable.fieldRename]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonSerializable/fieldRename.html +[JsonSerializable.ignoreUnannotated]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonSerializable/ignoreUnannotated.html +[JsonSerializable.includeIfNull]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonSerializable/includeIfNull.html +[JsonKey.includeIfNull]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonKey/includeIfNull.html +[JsonSerializable.nullable]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonSerializable/nullable.html +[JsonKey.nullable]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonKey/nullable.html +[JsonKey.defaultValue]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonKey/defaultValue.html +[JsonKey.disallowNullValue]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonKey/disallowNullValue.html +[JsonKey.fromJson]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonKey/fromJson.html +[JsonKey.ignore]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonKey/ignore.html +[JsonKey.name]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonKey/name.html +[JsonKey.required]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonKey/required.html +[JsonKey.toJson]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonKey/toJson.html +[JsonKey.unknownEnumValue]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonKey/unknownEnumValue.html > Note: every `JsonSerializable` field is configurable via `build.yaml` – see the table for the corresponding key. diff --git a/json_serializable/doc/doc.md b/json_serializable/doc/doc.md index da2daa83c..569a63d58 100644 --- a/json_serializable/doc/doc.md +++ b/json_serializable/doc/doc.md @@ -19,23 +19,23 @@ | | | [JsonKey.toJson] | | | | [JsonKey.unknownEnumValue] | -[JsonSerializable.anyMap]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/anyMap.html -[JsonSerializable.checked]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/checked.html -[JsonSerializable.createFactory]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/createFactory.html -[JsonSerializable.createToJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/createToJson.html -[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html -[JsonSerializable.explicitToJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/explicitToJson.html -[JsonSerializable.fieldRename]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/fieldRename.html -[JsonSerializable.ignoreUnannotated]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/ignoreUnannotated.html -[JsonSerializable.includeIfNull]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/includeIfNull.html -[JsonKey.includeIfNull]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/includeIfNull.html -[JsonSerializable.nullable]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/nullable.html -[JsonKey.nullable]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/nullable.html -[JsonKey.defaultValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/defaultValue.html -[JsonKey.disallowNullValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/disallowNullValue.html -[JsonKey.fromJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/fromJson.html -[JsonKey.ignore]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/ignore.html -[JsonKey.name]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/name.html -[JsonKey.required]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/required.html -[JsonKey.toJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/toJson.html -[JsonKey.unknownEnumValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/unknownEnumValue.html +[JsonSerializable.anyMap]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonSerializable/anyMap.html +[JsonSerializable.checked]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonSerializable/checked.html +[JsonSerializable.createFactory]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonSerializable/createFactory.html +[JsonSerializable.createToJson]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonSerializable/createToJson.html +[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html +[JsonSerializable.explicitToJson]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonSerializable/explicitToJson.html +[JsonSerializable.fieldRename]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonSerializable/fieldRename.html +[JsonSerializable.ignoreUnannotated]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonSerializable/ignoreUnannotated.html +[JsonSerializable.includeIfNull]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonSerializable/includeIfNull.html +[JsonKey.includeIfNull]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonKey/includeIfNull.html +[JsonSerializable.nullable]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonSerializable/nullable.html +[JsonKey.nullable]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonKey/nullable.html +[JsonKey.defaultValue]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonKey/defaultValue.html +[JsonKey.disallowNullValue]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonKey/disallowNullValue.html +[JsonKey.fromJson]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonKey/fromJson.html +[JsonKey.ignore]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonKey/ignore.html +[JsonKey.name]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonKey/name.html +[JsonKey.required]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonKey/required.html +[JsonKey.toJson]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonKey/toJson.html +[JsonKey.unknownEnumValue]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonKey/unknownEnumValue.html From 970279cecd78f554bdd06264b8a6830b850dd9ac Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 23 Mar 2020 13:13:19 -0700 Subject: [PATCH 185/569] Refactor DecodeHelper (#622) Less code duplication Eliminate state in the class --- json_serializable/lib/src/decode_helper.dart | 99 ++++++++------------ 1 file changed, 40 insertions(+), 59 deletions(-) diff --git a/json_serializable/lib/src/decode_helper.dart b/json_serializable/lib/src/decode_helper.dart index 72ed7b73b..cdbdafe40 100644 --- a/json_serializable/lib/src/decode_helper.dart +++ b/json_serializable/lib/src/decode_helper.dart @@ -4,7 +4,6 @@ import 'package:analyzer/dart/element/element.dart'; import 'package:build/build.dart'; -import 'package:json_annotation/json_annotation.dart'; import 'package:source_gen/source_gen.dart'; import 'helper_core.dart'; @@ -20,15 +19,15 @@ class CreateFactoryResult { } abstract class DecodeHelper implements HelperCore { - final StringBuffer _buffer = StringBuffer(); - - CreateFactoryResult createFactory(Map accessibleFields, - Map unavailableReasons) { + CreateFactoryResult createFactory( + Map accessibleFields, + Map unavailableReasons, + ) { assert(config.createFactory); - assert(_buffer.isEmpty); + final buffer = StringBuffer(); final mapType = config.anyMap ? 'Map' : 'Map'; - _buffer.write('$targetClassReference ' + buffer.write('$targetClassReference ' '${prefix}FromJson${genericClassArgumentsImpl(true)}' '($mapType json) {\n'); @@ -37,38 +36,33 @@ abstract class DecodeHelper implements HelperCore { _deserializeForField(accessibleFields[paramOrFieldName], ctorParam: ctorParam); - _ConstructorData data; + final data = _writeConstructorInvocation( + element, + accessibleFields.keys, + accessibleFields.values + .where((fe) => !fe.isFinal) + .map((fe) => fe.name) + .toList(), + unavailableReasons, + deserializeFun); + + final checks = _checkKeys(accessibleFields.values + .where((fe) => data.usedCtorParamsAndFields.contains(fe.name))); + if (config.checked) { final classLiteral = escapeDartString(element.name); - _buffer.write(''' + buffer..write(''' return \$checkedNew( $classLiteral, json, - () {\n'''); - - data = _writeConstructorInvocation( - element, - accessibleFields.keys, - accessibleFields.values - .where((fe) => !fe.isFinal) - .map((fe) => fe.name) - .toList(), - unavailableReasons, - deserializeFun); - - _writeChecks( - 6, - config, - accessibleFields.values - .where((fe) => data.usedCtorParamsAndFields.contains(fe.name))); - _buffer.write(''' + () {\n''')..write(checks)..write(''' final val = ${data.content};'''); for (final field in data.fieldsToSet) { - _buffer.writeln(); + buffer.writeln(); final safeName = safeNameAccess(accessibleFields[field]); - _buffer + buffer ..write(''' \$checkedConvert(json, $safeName, (v) => ''') ..write('val.$field = ') @@ -77,7 +71,7 @@ abstract class DecodeHelper implements HelperCore { ..write(');'); } - _buffer.write('''\n return val; + buffer.write('''\n return val; }'''); final fieldKeyMap = Map.fromEntries(data.usedCtorParamsAndFields @@ -92,47 +86,29 @@ abstract class DecodeHelper implements HelperCore { fieldKeyMapArg = ', fieldKeyMap: const $mapLiteral'; } - _buffer..write(fieldKeyMapArg)..write(')'); + buffer..write(fieldKeyMapArg)..write(')'); } else { - data = _writeConstructorInvocation( - element, - accessibleFields.keys, - accessibleFields.values - .where((fe) => !fe.isFinal) - .map((fe) => fe.name) - .toList(), - unavailableReasons, - deserializeFun); - - _writeChecks( - 2, - config, - accessibleFields.values - .where((fe) => data.usedCtorParamsAndFields.contains(fe.name))); - - _buffer.write(''' + buffer..write(checks)..write(''' return ${data.content}'''); for (final field in data.fieldsToSet) { - _buffer + buffer ..writeln() ..write(' ..$field = ') ..write(deserializeFun(field)); } } - _buffer..writeln(';\n}')..writeln(); + buffer..writeln(';\n}')..writeln(); - return CreateFactoryResult( - _buffer.toString(), data.usedCtorParamsAndFields); + return CreateFactoryResult(buffer.toString(), data.usedCtorParamsAndFields); } - void _writeChecks(int indent, JsonSerializable classAnnotation, - Iterable accessibleFields) { + String _checkKeys(Iterable accessibleFields) { final args = []; String constantList(Iterable things) => 'const ${jsonLiteralAsDart(things.map(nameAccess).toList())}'; - if (classAnnotation.disallowUnrecognizedKeys) { + if (config.disallowUnrecognizedKeys) { final allowKeysLiteral = constantList(accessibleFields); args.add('allowedKeys: $allowKeysLiteral'); @@ -155,13 +131,18 @@ abstract class DecodeHelper implements HelperCore { args.add('disallowNullValues: $disallowNullKeyLiteral'); } - if (args.isNotEmpty) { - _buffer.writeln('${' ' * indent}\$checkKeys(json, ${args.join(', ')});'); + if (args.isEmpty) { + return ''; + } else { + return '\$checkKeys(json, ${args.join(', ')});\n'; } } - String _deserializeForField(FieldElement field, - {ParameterElement ctorParam, bool checkedProperty}) { + String _deserializeForField( + FieldElement field, { + ParameterElement ctorParam, + bool checkedProperty, + }) { checkedProperty ??= false; final jsonKeyName = safeNameAccess(field); final targetType = ctorParam?.type ?? field.type; From 3ea5351cb73f1e1131a252533276e1887bb883c8 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 25 Mar 2020 12:10:12 -0700 Subject: [PATCH 186/569] Add support for annotating fields with subclasses on JsonKey (#623) Fixes https://github.com/dart-lang/json_serializable/issues/575 --- json_serializable/CHANGELOG.md | 3 +- json_serializable/lib/src/json_key_utils.dart | 28 +++++++++++-------- .../lib/src/type_helper_ctx.dart | 8 +++--- json_serializable/lib/src/utils.dart | 11 +++++--- json_serializable/pubspec.yaml | 2 +- .../test/json_serializable_test.dart | 1 + .../src/_json_serializable_test_input.dart | 22 +++++++++++++++ 7 files changed, 53 insertions(+), 22 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 696e47895..8bdd6920d 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,5 +1,6 @@ -## unreleased +## 3.3.0 +- Add support for fields annotated subclasses of `JsonKey`. - Export the following `TypeHelper` implementations and interfaces in `package:json_serializable/type_helper.dart`: - `DurationHelper` diff --git a/json_serializable/lib/src/json_key_utils.dart b/json_serializable/lib/src/json_key_utils.dart index 2432e69e9..89c478374 100644 --- a/json_serializable/lib/src/json_key_utils.dart +++ b/json_serializable/lib/src/json_key_utils.dart @@ -38,7 +38,7 @@ JsonKey _from(FieldElement element, JsonSerializable classAnnotation) { // TODO(kevmoo) setters: github.com/dart-lang/json_serializable/issues/24 final obj = jsonKeyAnnotation(element); - if (obj == null) { + if (obj.isNull) { return _populateJsonKey( classAnnotation, element, @@ -117,9 +117,11 @@ JsonKey _from(FieldElement element, JsonSerializable classAnnotation) { /// either the annotated field is not an `enum` or if the value in /// [fieldName] is not an `enum` value. Object _annotationValue(String fieldName, {bool mustBeEnum = false}) { - final annotationValue = obj.getField(fieldName); + final annotationValue = obj.read(fieldName); - final enumFields = iterateEnumFields(annotationValue.type); + final enumFields = annotationValue.isNull + ? null + : iterateEnumFields(annotationValue.objectValue.type); if (enumFields != null) { if (mustBeEnum && !isEnum(element.type)) { throwUnsupported( @@ -131,11 +133,13 @@ JsonKey _from(FieldElement element, JsonSerializable classAnnotation) { enumFields.map((p) => p.name).toList(growable: false); final enumValueName = enumValueForDartObject( - annotationValue, enumValueNames, (n) => n); + annotationValue.objectValue, enumValueNames, (n) => n); - return '${annotationValue.type.element.name}.$enumValueName'; + return '${annotationValue.objectValue.type.element.name}.$enumValueName'; } else { - final defaultValueLiteral = literalForObject(annotationValue, []); + final defaultValueLiteral = annotationValue.isNull + ? null + : literalForObject(annotationValue.objectValue, []); if (defaultValueLiteral == null) { return null; } @@ -153,12 +157,12 @@ JsonKey _from(FieldElement element, JsonSerializable classAnnotation) { classAnnotation, element, defaultValue: _annotationValue('defaultValue'), - disallowNullValue: obj.getField('disallowNullValue').toBoolValue(), - ignore: obj.getField('ignore').toBoolValue(), - includeIfNull: obj.getField('includeIfNull').toBoolValue(), - name: obj.getField('name').toStringValue(), - nullable: obj.getField('nullable').toBoolValue(), - required: obj.getField('required').toBoolValue(), + disallowNullValue: obj.read('disallowNullValue').literalValue as bool, + ignore: obj.read('ignore').literalValue as bool, + includeIfNull: obj.read('includeIfNull').literalValue as bool, + name: obj.read('name').literalValue as String, + nullable: obj.read('nullable').literalValue as bool, + required: obj.read('required').literalValue as bool, unknownEnumValue: _annotationValue('unknownEnumValue', mustBeEnum: true), ); } diff --git a/json_serializable/lib/src/type_helper_ctx.dart b/json_serializable/lib/src/type_helper_ctx.dart index 3c80a378b..5de3f4590 100644 --- a/json_serializable/lib/src/type_helper_ctx.dart +++ b/json_serializable/lib/src/type_helper_ctx.dart @@ -90,11 +90,11 @@ class _ConvertPair { if (pair == null) { final obj = jsonKeyAnnotation(element); - if (obj == null) { + if (obj.isNull) { pair = _ConvertPair._(null, null); } else { - final toJson = _convertData(obj, element, false); - final fromJson = _convertData(obj, element, true); + final toJson = _convertData(obj.objectValue, element, false); + final fromJson = _convertData(obj.objectValue, element, true); pair = _ConvertPair._(fromJson, toJson); } _expando[element] = pair; @@ -107,7 +107,7 @@ ConvertData _convertData(DartObject obj, FieldElement element, bool isFrom) { final paramName = isFrom ? 'fromJson' : 'toJson'; final objectValue = obj.getField(paramName); - if (objectValue.isNull) { + if (objectValue == null || objectValue.isNull) { return null; } diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index ef30ca54f..40ac04a20 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -13,15 +13,18 @@ import 'helper_core.dart'; const _jsonKeyChecker = TypeChecker.fromRuntime(JsonKey); -DartObject jsonKeyAnnotation(FieldElement element) => - _jsonKeyChecker.firstAnnotationOfExact(element) ?? +DartObject _jsonKeyAnnotation(FieldElement element) => + _jsonKeyChecker.firstAnnotationOf(element) ?? (element.getter == null ? null - : _jsonKeyChecker.firstAnnotationOfExact(element.getter)); + : _jsonKeyChecker.firstAnnotationOf(element.getter)); + +ConstantReader jsonKeyAnnotation(FieldElement element) => + ConstantReader(_jsonKeyAnnotation(element)); /// Returns `true` if [element] is annotated with [JsonKey]. bool hasJsonKeyAnnotation(FieldElement element) => - jsonKeyAnnotation(element) != null; + _jsonKeyAnnotation(element) != null; final _upperCase = RegExp('[A-Z]'); diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 4e4ac3f3d..e63ac5a75 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 3.2.5 +version: 3.3.0 description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. diff --git a/json_serializable/test/json_serializable_test.dart b/json_serializable/test/json_serializable_test.dart index 0d970229e..e1d96918c 100644 --- a/json_serializable/test/json_serializable_test.dart +++ b/json_serializable/test/json_serializable_test.dart @@ -84,6 +84,7 @@ const _expectedAnnotatedTests = [ 'PrivateFieldCtorClass', 'PropInMixinI448Regression', 'SetSupport', + 'SubclassedJsonKey', 'SubType', 'SubTypeWithAnnotatedFieldOverrideExtends', 'SubTypeWithAnnotatedFieldOverrideExtendsWithOverrides', diff --git a/json_serializable/test/src/_json_serializable_test_input.dart b/json_serializable/test/src/_json_serializable_test_input.dart index 3fd9dbe49..8af01b3e6 100644 --- a/json_serializable/test/src/_json_serializable_test_input.dart +++ b/json_serializable/test/src/_json_serializable_test_input.dart @@ -482,3 +482,25 @@ class IgnoreUnannotated { int unannotated; } + +@ShouldGenerate( + r''' +SubclassedJsonKey _$SubclassedJsonKeyFromJson(Map json) { + return SubclassedJsonKey()..annotatedWithSubclass = json['bob'] as int; +} + +Map _$SubclassedJsonKeyToJson(SubclassedJsonKey instance) => + { + 'bob': instance.annotatedWithSubclass, + }; +''', +) +@JsonSerializable(ignoreUnannotated: true) +class SubclassedJsonKey { + @MyJsonKey() + int annotatedWithSubclass; +} + +class MyJsonKey extends JsonKey { + const MyJsonKey() : super(name: 'bob'); +} From 590b5a2aa74ea2a10b126d7371c3e034ef23f366 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 2 Apr 2020 09:43:17 -0700 Subject: [PATCH 187/569] Ignore use of CastError - deprecated in Dart 2.8.0-dev.18 (#627) --- example/test/json_convert_example_test.dart | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/example/test/json_convert_example_test.dart b/example/test/json_convert_example_test.dart index 091168e4a..ecb4bf1c3 100644 --- a/example/test/json_convert_example_test.dart +++ b/example/test/json_convert_example_test.dart @@ -54,15 +54,15 @@ void main() { expect( () => GenericCollection.fromJson( jsonDecode(encoded) as Map), - _throwsCastSomething); + _throwsCastError); expect( () => GenericCollection.fromJson( jsonDecode(encoded) as Map), - _throwsCastSomething); + _throwsCastError); expect( () => GenericCollection.fromJson( jsonDecode(encoded) as Map), - _throwsCastSomething); + _throwsCastError); final collection2 = GenericCollection.fromJson(jsonDecode(encoded) as Map); @@ -81,7 +81,8 @@ void main() { }); } -final _throwsCastSomething = throwsA(isA()); +// ignore: deprecated_member_use +final _throwsCastError = throwsA(isA()); String _encode(Object object) => const JsonEncoder.withIndent(' ').convert(object); From cb43a7d10253384d2a3c7cff140c798f940043f8 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 13 Apr 2020 11:00:16 -0700 Subject: [PATCH 188/569] Handle double Nan, +/- Infinity in default values (#630) Fixes https://github.com/dart-lang/json_serializable/issues/629 --- json_serializable/CHANGELOG.md | 4 +++ .../lib/src/json_literal_generator.dart | 13 +++++++ json_serializable/pubspec.yaml | 2 +- .../test/json_serializable_test.dart | 1 + .../test/src/default_value_input.dart | 35 +++++++++++++++++++ 5 files changed, 54 insertions(+), 1 deletion(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 8bdd6920d..a1142fda3 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,7 @@ +## 3.4.0-dev + +- Added support for `double` constants as default values. + ## 3.3.0 - Add support for fields annotated subclasses of `JsonKey`. diff --git a/json_serializable/lib/src/json_literal_generator.dart b/json_serializable/lib/src/json_literal_generator.dart index 1cce1c1d7..226117803 100644 --- a/json_serializable/lib/src/json_literal_generator.dart +++ b/json_serializable/lib/src/json_literal_generator.dart @@ -44,6 +44,19 @@ String jsonLiteralAsDart(dynamic value) { if (value is String) return escapeDartString(value); + if (value is double) { + if (value.isNaN) { + return 'double.nan'; + } + + if (value.isInfinite) { + if (value.isNegative) { + return 'double.negativeInfinity'; + } + return 'double.infinity'; + } + } + if (value is bool || value is num) return value.toString(); if (value is List) { diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index e63ac5a75..5d0626f78 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 3.3.0 +version: 3.4.0-dev description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. diff --git a/json_serializable/test/json_serializable_test.dart b/json_serializable/test/json_serializable_test.dart index e1d96918c..0d92a3d1c 100644 --- a/json_serializable/test/json_serializable_test.dart +++ b/json_serializable/test/json_serializable_test.dart @@ -29,6 +29,7 @@ const _expectedAnnotatedTests = [ 'BadOneNamed', 'BadToFuncReturnType', 'BadTwoRequiredPositional', + 'DefaultDoubleConstants', 'DefaultWithConstObject', 'DefaultWithDisallowNullRequiredClass', 'DefaultWithFunction', diff --git a/json_serializable/test/src/default_value_input.dart b/json_serializable/test/src/default_value_input.dart index 724ebb7af..94c14cacb 100644 --- a/json_serializable/test/src/default_value_input.dart +++ b/json_serializable/test/src/default_value_input.dart @@ -147,3 +147,38 @@ class DefaultWithDisallowNullRequiredClass { DefaultWithDisallowNullRequiredClass(); } + +@ShouldGenerate(r''' +DefaultDoubleConstants _$DefaultDoubleConstantsFromJson( + Map json) { + return DefaultDoubleConstants() + ..defaultNan = (json['defaultNan'] as num)?.toDouble() ?? double.nan + ..defaultNegativeInfinity = + (json['defaultNegativeInfinity'] as num)?.toDouble() ?? + double.negativeInfinity + ..defaultInfinity = + (json['defaultInfinity'] as num)?.toDouble() ?? double.infinity + ..defaultMinPositive = + (json['defaultMinPositive'] as num)?.toDouble() ?? 5e-324 + ..defaultMaxFinite = (json['defaultMaxFinite'] as num)?.toDouble() ?? + 1.7976931348623157e+308; +} +''') +@JsonSerializable(createToJson: false) +class DefaultDoubleConstants { + @JsonKey(defaultValue: double.nan) + double defaultNan; + @JsonKey(defaultValue: double.negativeInfinity) + double defaultNegativeInfinity; + @JsonKey(defaultValue: double.infinity) + double defaultInfinity; + + // Since these values can be represented as number literals, there is no + // special handling. Including them here for completeness, though. + @JsonKey(defaultValue: double.minPositive) + double defaultMinPositive; + @JsonKey(defaultValue: double.maxFinite) + double defaultMaxFinite; + + DefaultDoubleConstants(); +} From 1683e3428f9a6e457c3cad668a4ba6940596faa5 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 21 Apr 2020 13:39:19 -0700 Subject: [PATCH 189/569] remove author from pubspec --- checked_yaml/pubspec.yaml | 1 - example/pubspec.yaml | 1 - 2 files changed, 2 deletions(-) diff --git a/checked_yaml/pubspec.yaml b/checked_yaml/pubspec.yaml index 6dbf7fd40..7fbc21437 100644 --- a/checked_yaml/pubspec.yaml +++ b/checked_yaml/pubspec.yaml @@ -1,6 +1,5 @@ name: checked_yaml version: 1.0.3-dev -author: Dart Team description: >- Generate more helpful exceptions when decoding YAML documents using package:json_serializable and package:yaml. diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 14c7464a8..888586fe0 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -1,5 +1,4 @@ name: example -author: Dart Team environment: sdk: '>=2.6.0 <3.0.0' From 540c593a889b2823cbf2b1bb88a780933a57b4c4 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 22 Apr 2020 14:32:02 -0700 Subject: [PATCH 190/569] Currently failing with latest analyzer (#632) --- .../test/json_serializable_test.dart | 4 - .../src/_json_serializable_test_input.dart | 2 - .../test/src/unknown_type_test_input.dart | 73 ------------------- 3 files changed, 79 deletions(-) delete mode 100644 json_serializable/test/src/unknown_type_test_input.dart diff --git a/json_serializable/test/json_serializable_test.dart b/json_serializable/test/json_serializable_test.dart index 0d92a3d1c..71cbd7e62 100644 --- a/json_serializable/test/json_serializable_test.dart +++ b/json_serializable/test/json_serializable_test.dart @@ -93,13 +93,9 @@ const _expectedAnnotatedTests = [ 'theAnswer', 'ToJsonNullableFalseIncludeIfNullFalse', 'TypedConvertMethods', - 'UnknownCtorParamType', 'UnknownEnumValue', 'UnknownEnumValueNotEnumValue', 'UnknownEnumValueNotEnumField', - 'UnknownFieldType', - 'UnknownFieldTypeToJsonOnly', - 'UnknownFieldTypeWithConvert', 'UnsupportedDateTimeField', 'UnsupportedDurationField', 'UnsupportedListField', diff --git a/json_serializable/test/src/_json_serializable_test_input.dart b/json_serializable/test/src/_json_serializable_test_input.dart index 8af01b3e6..cd106983b 100644 --- a/json_serializable/test/src/_json_serializable_test_input.dart +++ b/json_serializable/test/src/_json_serializable_test_input.dart @@ -29,8 +29,6 @@ part 'to_from_json_test_input.dart'; part 'unknown_enum_value_test_input.dart'; -part 'unknown_type_test_input.dart'; - @ShouldThrow('Generator cannot target `theAnswer`.', todo: 'Remove the JsonSerializable annotation from `theAnswer`.') @JsonSerializable() diff --git a/json_serializable/test/src/unknown_type_test_input.dart b/json_serializable/test/src/unknown_type_test_input.dart deleted file mode 100644 index 360d31685..000000000 --- a/json_serializable/test/src/unknown_type_test_input.dart +++ /dev/null @@ -1,73 +0,0 @@ -part of '_json_serializable_test_input.dart'; - -@ShouldGenerate(r''' -UnknownCtorParamType _$UnknownCtorParamTypeFromJson(Map json) { - return UnknownCtorParamType( - json['number'], - ); -} - -Map _$UnknownCtorParamTypeToJson( - UnknownCtorParamType instance) => - { - 'number': instance.number, - }; -''') -@JsonSerializable() -class UnknownCtorParamType { - int number; - - // ignore: undefined_class, field_initializer_not_assignable, prefer_initializing_formals - UnknownCtorParamType(Bob number) : number = number; -} - -@ShouldGenerate(r''' -UnknownFieldType _$UnknownFieldTypeFromJson(Map json) { - return UnknownFieldType()..number = json['number']; -} - -Map _$UnknownFieldTypeToJson(UnknownFieldType instance) => - { - 'number': instance.number, - }; -''') -@JsonSerializable() -class UnknownFieldType { - // ignore: undefined_class - Bob number; -} - -@ShouldGenerate(r''' -Map _$UnknownFieldTypeToJsonOnlyToJson( - UnknownFieldTypeToJsonOnly instance) => - { - 'number': instance.number, - }; -''') -@JsonSerializable(createFactory: false) -class UnknownFieldTypeToJsonOnly { - // ignore: undefined_class - Bob number; -} - -@ShouldGenerate(r''' -UnknownFieldTypeWithConvert _$UnknownFieldTypeWithConvertFromJson( - Map json) { - return UnknownFieldTypeWithConvert() - ..number = _everythingIs42(json['number']); -} - -Map _$UnknownFieldTypeWithConvertToJson( - UnknownFieldTypeWithConvert instance) => - { - 'number': _everythingIs42(instance.number), - }; -''') -@JsonSerializable() -class UnknownFieldTypeWithConvert { - @JsonKey(fromJson: _everythingIs42, toJson: _everythingIs42) - // ignore: undefined_class - Bob number; -} - -dynamic _everythingIs42(Object input) => 42; From fa7b5758ff8b637c87a6b60d1cc8b803bf43c11d Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 12 May 2020 16:26:20 -0700 Subject: [PATCH 191/569] Remove unneeded travis-ci config (#641) --- .travis.yml | 3 --- mono_repo.yaml | 3 --- 2 files changed, 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7b59d78ce..59a238d95 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,9 +2,6 @@ language: dart # Custom configuration -sudo: required -addons: - chrome: stable branches: only: - master diff --git a/mono_repo.yaml b/mono_repo.yaml index 12ed8f1fe..c6554596f 100644 --- a/mono_repo.yaml +++ b/mono_repo.yaml @@ -1,8 +1,5 @@ # See https://github.com/dart-lang/mono_repo for details on this file travis: - sudo: required - addons: - chrome: stable branches: only: - master From e3ef5760659c380db5e2e4c5982308b3aa83a46d Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 21 May 2020 09:44:17 -0700 Subject: [PATCH 192/569] Fix test with recent analyzer update (#645) This is a good behavior change! The analyzer no longer considers assignment of `Object` -> `String` valid --- json_serializable/test/src/to_from_json_test_input.dart | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/json_serializable/test/src/to_from_json_test_input.dart b/json_serializable/test/src/to_from_json_test_input.dart index 6608bfc1e..c4a9b9a62 100644 --- a/json_serializable/test/src/to_from_json_test_input.dart +++ b/json_serializable/test/src/to_from_json_test_input.dart @@ -12,6 +12,8 @@ dynamic _toDynamic(dynamic input) => null; Object _toObject(Object input) => null; +String _toStringFromObject(Object input) => null; + @ShouldThrow( 'Error with `@JsonKey` on `field`. The `fromJson` function `_toInt` ' 'return type `int` is not compatible with field type `String`.', @@ -81,12 +83,12 @@ class InvalidToFunc2Args { } @ShouldGenerate( - "_toObject(json['field'])", + "_toStringFromObject(json['field'])", contains: true, ) @JsonSerializable() class ObjectConvertMethods { - @JsonKey(fromJson: _toObject, toJson: _toObject) + @JsonKey(fromJson: _toStringFromObject, toJson: _toObject) String field; } From f8c887f970d108dc12d20b19304cd030438d36ec Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 4 Jun 2020 14:58:17 -0700 Subject: [PATCH 193/569] Ignore deprecated member usage from pkg:analyzer (#650) DRY up use of typee.isObject --- json_serializable/lib/src/field_helpers.dart | 1 + json_serializable/lib/src/shared_checkers.dart | 9 ++++++--- json_serializable/lib/src/type_helpers/map_helper.dart | 10 ++++------ .../lib/src/type_helpers/value_helper.dart | 5 ++--- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/json_serializable/lib/src/field_helpers.dart b/json_serializable/lib/src/field_helpers.dart index fe425dfab..d035908e6 100644 --- a/json_serializable/lib/src/field_helpers.dart +++ b/json_serializable/lib/src/field_helpers.dart @@ -85,6 +85,7 @@ Iterable createSortedFieldSet(ClassElement element) { final inheritedFields = {}; final manager = InheritanceManager3(); + // ignore: deprecated_member_use for (final v in manager.getInheritedConcreteMap(element.thisType).values) { assert(v is! FieldElement); if (_dartCoreObjectChecker.isExactly(v.enclosingElement)) { diff --git a/json_serializable/lib/src/shared_checkers.dart b/json_serializable/lib/src/shared_checkers.dart index 17b5e507f..030d585a5 100644 --- a/json_serializable/lib/src/shared_checkers.dart +++ b/json_serializable/lib/src/shared_checkers.dart @@ -38,13 +38,13 @@ const simpleJsonTypeChecker = TypeChecker.any([ ]); String asStatement(DartType type) { - if (type.isDynamic || type.isObject) { + if (isObjectOrDynamic(type)) { return ''; } if (coreIterableTypeChecker.isAssignableFromType(type)) { final itemType = coreIterableGenericType(type); - if (itemType.isDynamic || itemType.isObject) { + if (isObjectOrDynamic(itemType)) { return ' as List'; } } @@ -53,7 +53,7 @@ String asStatement(DartType type) { final args = typeArgumentsOf(type, coreMapTypeChecker); assert(args.length == 2); - if (args.every((dt) => dt.isDynamic || dt.isObject)) { + if (args.every(isObjectOrDynamic)) { return ' as Map'; } } @@ -62,6 +62,9 @@ String asStatement(DartType type) { return ' as $typeCode'; } +// ignore: deprecated_member_use +bool isObjectOrDynamic(DartType type) => type.isObject || type.isDynamic; + /// Returns all of the [DartType] types that [type] implements, mixes-in, and /// extends, starting with [type] itself. Iterable typeImplementations(DartType type) sync* { diff --git a/json_serializable/lib/src/type_helpers/map_helper.dart b/json_serializable/lib/src/type_helpers/map_helper.dart index a96aff455..ffa3192e5 100644 --- a/json_serializable/lib/src/type_helpers/map_helper.dart +++ b/json_serializable/lib/src/type_helpers/map_helper.dart @@ -60,13 +60,13 @@ class MapHelper extends TypeHelper { _checkSafeKeyType(expression, keyArg); - final valueArgIsAny = _isObjectOrDynamic(valueArg); + final valueArgIsAny = isObjectOrDynamic(valueArg); final isKeyStringable = _isKeyStringable(keyArg); if (!isKeyStringable) { if (valueArgIsAny) { if (context.config.anyMap) { - if (_isObjectOrDynamic(keyArg)) { + if (isObjectOrDynamic(keyArg)) { return '$expression as Map'; } } else { @@ -97,7 +97,7 @@ class MapHelper extends TypeHelper { String keyUsage; if (isEnum(keyArg)) { keyUsage = context.deserialize(keyArg, _keyParam).toString(); - } else if (context.config.anyMap && !_isObjectOrDynamic(keyArg)) { + } else if (context.config.anyMap && !isObjectOrDynamic(keyArg)) { keyUsage = '$_keyParam as String'; } else { keyUsage = _keyParam; @@ -127,8 +127,6 @@ final _instances = [ ToFromStringHelper _forType(DartType type) => _instances.singleWhere((i) => i.matches(type), orElse: () => null); -bool _isObjectOrDynamic(DartType type) => type.isObject || type.isDynamic; - /// Returns `true` if [keyType] can be automatically converted to/from String – /// and is therefor usable as a key in a [Map]. bool _isKeyStringable(DartType keyType) => @@ -137,7 +135,7 @@ bool _isKeyStringable(DartType keyType) => void _checkSafeKeyType(String expression, DartType keyArg) { // We're not going to handle converting key types at the moment // So the only safe types for key are dynamic/Object/String/enum - final safeKey = _isObjectOrDynamic(keyArg) || + final safeKey = isObjectOrDynamic(keyArg) || coreStringTypeChecker.isExactlyType(keyArg) || _isKeyStringable(keyArg); diff --git a/json_serializable/lib/src/type_helpers/value_helper.dart b/json_serializable/lib/src/type_helpers/value_helper.dart index 14923ec1b..5d0bef367 100644 --- a/json_serializable/lib/src/type_helpers/value_helper.dart +++ b/json_serializable/lib/src/type_helpers/value_helper.dart @@ -15,8 +15,7 @@ class ValueHelper extends TypeHelper { @override String serialize( DartType targetType, String expression, TypeHelperContext context) { - if (targetType.isDynamic || - targetType.isObject || + if (isObjectOrDynamic(targetType) || simpleJsonTypeChecker.isAssignableFromType(targetType)) { return expression; } @@ -27,7 +26,7 @@ class ValueHelper extends TypeHelper { @override String deserialize( DartType targetType, String expression, TypeHelperContext context) { - if (targetType.isDynamic || targetType.isObject) { + if (isObjectOrDynamic(targetType)) { // just return it as-is. We'll hope it's safe. return expression; } else if (const TypeChecker.fromUrl('dart:core#double') From f8a4ca9c33c8a971d73f32df3357992131d9e06a Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 18 Jun 2020 10:40:30 -0700 Subject: [PATCH 194/569] Fix deprecated use of isCastError (#659) Although we're still referencing (deprecated) `CastError` --- _test_yaml/test/yaml_test.dart | 3 ++- json_serializable/test/kitchen_sink/kitchen_sink_test.dart | 7 +++++-- json_serializable/test/test_utils.dart | 3 ++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/_test_yaml/test/yaml_test.dart b/_test_yaml/test/yaml_test.dart index eed0cc45a..1d63a7c16 100644 --- a/_test_yaml/test/yaml_test.dart +++ b/_test_yaml/test/yaml_test.dart @@ -153,7 +153,8 @@ line 4, column 21 of file.yaml: Unsupported value for "configLocation". Illegal ╵''' }; -final throwsCastError = throwsA(isCastError); +// ignore: deprecated_member_use +final throwsCastError = throwsA(isA()); T roundTripObject( T object, diff --git a/json_serializable/test/kitchen_sink/kitchen_sink_test.dart b/json_serializable/test/kitchen_sink/kitchen_sink_test.dart index ce7ba4d1b..8a22ce025 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink_test.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink_test.dart @@ -17,6 +17,9 @@ const _toJsonMapHelperName = 'writeNotNull'; final _isATypeError = isA(); +// ignore: deprecated_member_use +final _isACastError = isA(); + Matcher _isAUnrecognizedKeysException(expectedMessage) => isA() .having((e) => e.message, 'message', expectedMessage); @@ -290,7 +293,7 @@ Matcher _getMatcher(bool checked, String expectedKey, bool checkedAssignment) { innerMatcher = _checkedMatcher(expectedKey); } else { innerMatcher = anyOf( - isCastError, + _isACastError, _isATypeError, _isAUnrecognizedKeysException( 'Unrecognized keys: [invalid_key]; supported keys: ' @@ -311,7 +314,7 @@ Matcher _getMatcher(bool checked, String expectedKey, bool checkedAssignment) { break; case 'intIterable': case 'datetime-iterable': - innerMatcher = isCastError; + innerMatcher = _isACastError; break; default: throw StateError('Not expected! - $expectedKey'); diff --git a/json_serializable/test/test_utils.dart b/json_serializable/test/test_utils.dart index 87ac687eb..51e6190f4 100644 --- a/json_serializable/test/test_utils.dart +++ b/json_serializable/test/test_utils.dart @@ -6,7 +6,8 @@ import 'dart:convert'; import 'package:test/test.dart'; -final throwsCastError = throwsA(isCastError); +// ignore: deprecated_member_use +final throwsCastError = throwsA(isA()); T roundTripObject(T object, T Function(Map json) factory) { final data = loudEncode(object); From bda9eb9ff51f68cbc0036cd8a923f6c03c46f91b Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 22 Jun 2020 13:04:57 -0700 Subject: [PATCH 195/569] Update github repo references (#662) dart-lang/json_serializable --> google/json_serializable.dart --- README.md | 2 +- _test_yaml/mono_pkg.yaml | 2 +- checked_yaml/mono_pkg.yaml | 2 +- checked_yaml/pubspec.yaml | 2 +- example/mono_pkg.yaml | 2 +- json_annotation/README.md | 4 ++-- json_annotation/mono_pkg.yaml | 2 +- json_annotation/pubspec.yaml | 2 +- json_serializable/README.md | 2 +- json_serializable/lib/src/decode_helper.dart | 2 +- json_serializable/lib/src/json_key_utils.dart | 2 +- json_serializable/lib/src/type_helpers/json_helper.dart | 2 +- json_serializable/mono_pkg.yaml | 2 +- json_serializable/pubspec.yaml | 2 +- json_serializable/test/src/_json_serializable_test_input.dart | 2 +- mono_repo.yaml | 2 +- 16 files changed, 17 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index f9bb8c746..62ab18738 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# [![Build Status](https://travis-ci.org/dart-lang/json_serializable.svg?branch=master)](https://travis-ci.org/dart-lang/json_serializable) +[![Build Status](https://travis-ci.org/google/json_serializable.dart.svg?branch=master)](https://travis-ci.org/google/json_serializable.dart) Provides [source_gen] `Generator`s to create code for JSON serialization and deserialization. diff --git a/_test_yaml/mono_pkg.yaml b/_test_yaml/mono_pkg.yaml index 4ee5b8d99..ec3196117 100644 --- a/_test_yaml/mono_pkg.yaml +++ b/_test_yaml/mono_pkg.yaml @@ -1,4 +1,4 @@ -# See https://github.com/dart-lang/mono_repo for details +# See https://github.com/google/mono_repo.dart for details on this file dart: - 2.6.0 - dev diff --git a/checked_yaml/mono_pkg.yaml b/checked_yaml/mono_pkg.yaml index ff48d74f3..ae2d9c498 100644 --- a/checked_yaml/mono_pkg.yaml +++ b/checked_yaml/mono_pkg.yaml @@ -1,4 +1,4 @@ -# See https://github.com/dart-lang/mono_repo for details +# See https://github.com/google/mono_repo.dart for details on this file dart: - 2.6.0 - dev diff --git a/checked_yaml/pubspec.yaml b/checked_yaml/pubspec.yaml index 7fbc21437..467e0cf2e 100644 --- a/checked_yaml/pubspec.yaml +++ b/checked_yaml/pubspec.yaml @@ -3,7 +3,7 @@ version: 1.0.3-dev description: >- Generate more helpful exceptions when decoding YAML documents using package:json_serializable and package:yaml. -homepage: https://github.com/dart-lang/json_serializable +homepage: https://github.com/google/json_serializable.dart environment: sdk: '>=2.6.0 <3.0.0' diff --git a/example/mono_pkg.yaml b/example/mono_pkg.yaml index 934fc7c4c..d114d438e 100644 --- a/example/mono_pkg.yaml +++ b/example/mono_pkg.yaml @@ -1,4 +1,4 @@ -# See https://github.com/dart-lang/mono_repo for details +# See https://github.com/google/mono_repo.dart for details on this file dart: - 2.6.0 - dev diff --git a/json_annotation/README.md b/json_annotation/README.md index 008e9c7d0..001334db6 100644 --- a/json_annotation/README.md +++ b/json_annotation/README.md @@ -9,6 +9,6 @@ See the [example] to understand how to configure your package. Please file feature requests and bugs at the [issue tracker][tracker]. -[example]: https://github.com/dart-lang/json_serializable/blob/master/example -[tracker]: https://github.com/dart-lang/json_serializable/issues +[example]: https://github.com/google/json_serializable.dart/tree/master/example +[tracker]: https://github.com/google/json_serializable.dart/issues [json_serializable]: https://pub.dev/packages/json_serializable diff --git a/json_annotation/mono_pkg.yaml b/json_annotation/mono_pkg.yaml index 456a4d185..3d822cb6a 100644 --- a/json_annotation/mono_pkg.yaml +++ b/json_annotation/mono_pkg.yaml @@ -1,4 +1,4 @@ -# See https://github.com/dart-lang/mono_repo for details +# See https://github.com/google/mono_repo.dart for details on this file stages: - analyzer_and_format: - group: diff --git a/json_annotation/pubspec.yaml b/json_annotation/pubspec.yaml index 023ec0765..3617b673b 100644 --- a/json_annotation/pubspec.yaml +++ b/json_annotation/pubspec.yaml @@ -3,7 +3,7 @@ version: 3.0.1 description: >- Classes and helper functions that support JSON code generation via the `json_serializable` package. -homepage: https://github.com/dart-lang/json_serializable +homepage: https://github.com/google/json_serializable.dart environment: sdk: '>=2.6.0 <3.0.0' diff --git a/json_serializable/README.md b/json_serializable/README.md index 53c7e66ca..f3b763275 100644 --- a/json_serializable/README.md +++ b/json_serializable/README.md @@ -150,6 +150,6 @@ targets: nullable: true ``` -[example]: https://github.com/dart-lang/json_serializable/blob/master/example +[example]: https://github.com/google/json_serializable.dart/tree/master/example [Dart Build System]: https://github.com/dart-lang/build [package:json_annotation]: https://pub.dev/packages/json_annotation diff --git a/json_serializable/lib/src/decode_helper.dart b/json_serializable/lib/src/decode_helper.dart index cdbdafe40..0a5748284 100644 --- a/json_serializable/lib/src/decode_helper.dart +++ b/json_serializable/lib/src/decode_helper.dart @@ -213,7 +213,7 @@ _ConstructorData _writeConstructorInvocation( final ctor = classElement.unnamedConstructor; if (ctor == null) { - // TODO(kevmoo): support using another ctor - dart-lang/json_serializable#50 + // TODO: support using another ctor - google/json_serializable.dart#50 throw InvalidGenerationSourceError( 'The class `$className` has no default constructor.', element: classElement); diff --git a/json_serializable/lib/src/json_key_utils.dart b/json_serializable/lib/src/json_key_utils.dart index 89c478374..f316f3663 100644 --- a/json_serializable/lib/src/json_key_utils.dart +++ b/json_serializable/lib/src/json_key_utils.dart @@ -35,7 +35,7 @@ void logFieldWithConversionFunction(FieldElement element) { JsonKey _from(FieldElement element, JsonSerializable classAnnotation) { // If an annotation exists on `element` the source is a 'real' field. // If the result is `null`, check the getter – it is a property. - // TODO(kevmoo) setters: github.com/dart-lang/json_serializable/issues/24 + // TODO(kevmoo) setters: github.com/google/json_serializable.dart/issues/24 final obj = jsonKeyAnnotation(element); if (obj.isNull) { diff --git a/json_serializable/lib/src/type_helpers/json_helper.dart b/json_serializable/lib/src/type_helpers/json_helper.dart index 3783ca353..e106604f5 100644 --- a/json_serializable/lib/src/type_helpers/json_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_helper.dart @@ -69,7 +69,7 @@ class JsonHelper extends TypeHelper { } // TODO: the type could be imported from a library with a prefix! - // github.com/dart-lang/json_serializable/issues/19 + // https://github.com/google/json_serializable.dart/issues/19 output = '${targetType.element.name}.fromJson($output)'; return commonNullPrefix(context.nullable, expression, output).toString(); diff --git a/json_serializable/mono_pkg.yaml b/json_serializable/mono_pkg.yaml index 716aa8c15..b3e0bd250 100644 --- a/json_serializable/mono_pkg.yaml +++ b/json_serializable/mono_pkg.yaml @@ -1,4 +1,4 @@ -# See https://github.com/dart-lang/mono_repo for details +# See https://github.com/google/mono_repo.dart for details on this file dart: - 2.6.0 - dev diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 5d0626f78..03ecfd590 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -3,7 +3,7 @@ version: 3.4.0-dev description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. -homepage: https://github.com/dart-lang/json_serializable +homepage: https://github.com/google/json_serializable.dart environment: sdk: '>=2.6.0 <3.0.0' diff --git a/json_serializable/test/src/_json_serializable_test_input.dart b/json_serializable/test/src/_json_serializable_test_input.dart index cd106983b..68b256381 100644 --- a/json_serializable/test/src/_json_serializable_test_input.dart +++ b/json_serializable/test/src/_json_serializable_test_input.dart @@ -257,7 +257,7 @@ class IncludeIfNullOverride { String str; } -// https://github.com/dart-lang/json_serializable/issues/7 regression +// https://github.com/google/json_serializable.dart/issues/7 regression @ShouldThrow( 'The class `NoCtorClass` has no default constructor.', configurations: ['default'], diff --git a/mono_repo.yaml b/mono_repo.yaml index c6554596f..1d276ac34 100644 --- a/mono_repo.yaml +++ b/mono_repo.yaml @@ -1,4 +1,4 @@ -# See https://github.com/dart-lang/mono_repo for details on this file +# See https://github.com/google/mono_repo.dart for details on this file travis: branches: only: From eed5b4bd26edca9e19ad223dd5b32e99b91615f5 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 7 Jul 2020 15:24:23 -0700 Subject: [PATCH 196/569] bump min SDK (#665) --- .travis.yml | 20 ++++++++++---------- _test_yaml/mono_pkg.yaml | 4 ++-- _test_yaml/pubspec.yaml | 2 +- checked_yaml/mono_pkg.yaml | 4 ++-- checked_yaml/pubspec.yaml | 2 +- example/mono_pkg.yaml | 4 ++-- example/pubspec.yaml | 2 +- json_annotation/mono_pkg.yaml | 2 +- json_annotation/pubspec.yaml | 2 +- json_serializable/mono_pkg.yaml | 4 ++-- json_serializable/pubspec.yaml | 2 +- 11 files changed, 24 insertions(+), 24 deletions(-) diff --git a/.travis.yml b/.travis.yml index 59a238d95..ab0c7c338 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,20 +15,20 @@ jobs: env: PKGS="_test_yaml checked_yaml example json_annotation json_serializable" script: ./tool/travis.sh dartfmt dartanalyzer_0 - stage: analyzer_and_format - name: "SDK: 2.6.0; PKGS: _test_yaml, checked_yaml, json_serializable; TASKS: `dartanalyzer --fatal-warnings .`" - dart: "2.6.0" + name: "SDK: 2.7.0; PKGS: _test_yaml, checked_yaml, json_serializable; TASKS: `dartanalyzer --fatal-warnings .`" + dart: "2.7.0" os: linux env: PKGS="_test_yaml checked_yaml json_serializable" script: ./tool/travis.sh dartanalyzer_1 - stage: analyzer_and_format - name: "SDK: 2.6.0; PKGS: example, json_annotation; TASKS: [`dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-warnings .`]" - dart: "2.6.0" + name: "SDK: 2.7.0; PKGS: example, json_annotation; TASKS: [`dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-warnings .`]" + dart: "2.7.0" os: linux env: PKGS="example json_annotation" script: ./tool/travis.sh dartfmt dartanalyzer_1 - stage: unit_test - name: "SDK: 2.6.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test`" - dart: "2.6.0" + name: "SDK: 2.7.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test`" + dart: "2.7.0" os: linux env: PKGS="_test_yaml checked_yaml example json_serializable" script: ./tool/travis.sh test_0 @@ -39,8 +39,8 @@ jobs: env: PKGS="_test_yaml checked_yaml example json_serializable" script: ./tool/travis.sh test_0 - stage: unit_test - name: "SDK: 2.6.0; PKG: json_serializable; TASKS: `pub run build_runner test --delete-conflicting-outputs -- -p chrome`" - dart: "2.6.0" + name: "SDK: 2.7.0; PKG: json_serializable; TASKS: `pub run build_runner test --delete-conflicting-outputs -- -p chrome`" + dart: "2.7.0" os: linux env: PKGS="json_serializable" script: ./tool/travis.sh command @@ -51,8 +51,8 @@ jobs: env: PKGS="json_serializable" script: ./tool/travis.sh command - stage: ensure_build - name: "SDK: 2.6.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`" - dart: "2.6.0" + name: "SDK: 2.7.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`" + dart: "2.7.0" os: linux env: PKGS="_test_yaml checked_yaml example json_serializable" script: ./tool/travis.sh test_1 diff --git a/_test_yaml/mono_pkg.yaml b/_test_yaml/mono_pkg.yaml index ec3196117..676aaa38d 100644 --- a/_test_yaml/mono_pkg.yaml +++ b/_test_yaml/mono_pkg.yaml @@ -1,6 +1,6 @@ # See https://github.com/google/mono_repo.dart for details on this file dart: -- 2.6.0 +- 2.7.0 - dev stages: @@ -11,7 +11,7 @@ stages: dart: [dev] - group: - dartanalyzer: --fatal-warnings . - dart: [2.6.0] + dart: [2.7.0] - unit_test: - test - ensure_build: diff --git a/_test_yaml/pubspec.yaml b/_test_yaml/pubspec.yaml index 531395dcc..0ea407c6a 100644 --- a/_test_yaml/pubspec.yaml +++ b/_test_yaml/pubspec.yaml @@ -2,7 +2,7 @@ name: _test_yaml publish_to: none environment: - sdk: '>=2.6.0 <3.0.0' + sdk: '>=2.7.0 <3.0.0' dev_dependencies: build_runner: ^1.0.0 diff --git a/checked_yaml/mono_pkg.yaml b/checked_yaml/mono_pkg.yaml index ae2d9c498..1d80a7151 100644 --- a/checked_yaml/mono_pkg.yaml +++ b/checked_yaml/mono_pkg.yaml @@ -1,6 +1,6 @@ # See https://github.com/google/mono_repo.dart for details on this file dart: -- 2.6.0 +- 2.7.0 - dev stages: @@ -11,7 +11,7 @@ stages: dart: [dev] - group: - dartanalyzer: --fatal-warnings . - dart: [2.6.0] + dart: [2.7.0] - unit_test: - test diff --git a/checked_yaml/pubspec.yaml b/checked_yaml/pubspec.yaml index 467e0cf2e..6c18a1020 100644 --- a/checked_yaml/pubspec.yaml +++ b/checked_yaml/pubspec.yaml @@ -5,7 +5,7 @@ description: >- package:json_serializable and package:yaml. homepage: https://github.com/google/json_serializable.dart environment: - sdk: '>=2.6.0 <3.0.0' + sdk: '>=2.7.0 <3.0.0' dependencies: json_annotation: '>=2.2.0 <4.0.0' diff --git a/example/mono_pkg.yaml b/example/mono_pkg.yaml index d114d438e..f4b867dc9 100644 --- a/example/mono_pkg.yaml +++ b/example/mono_pkg.yaml @@ -1,6 +1,6 @@ # See https://github.com/google/mono_repo.dart for details on this file dart: -- 2.6.0 +- 2.7.0 - dev stages: @@ -12,7 +12,7 @@ stages: - group: - dartfmt - dartanalyzer: --fatal-warnings . - dart: [2.6.0] + dart: [2.7.0] - unit_test: - test - ensure_build: diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 888586fe0..65def5a49 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -1,7 +1,7 @@ name: example environment: - sdk: '>=2.6.0 <3.0.0' + sdk: '>=2.7.0 <3.0.0' dependencies: json_annotation: ^3.0.0 diff --git a/json_annotation/mono_pkg.yaml b/json_annotation/mono_pkg.yaml index 3d822cb6a..69fc1ffa3 100644 --- a/json_annotation/mono_pkg.yaml +++ b/json_annotation/mono_pkg.yaml @@ -8,4 +8,4 @@ stages: - group: - dartfmt - dartanalyzer: --fatal-warnings . - dart: [2.6.0] + dart: [2.7.0] diff --git a/json_annotation/pubspec.yaml b/json_annotation/pubspec.yaml index 3617b673b..fc61a1605 100644 --- a/json_annotation/pubspec.yaml +++ b/json_annotation/pubspec.yaml @@ -5,7 +5,7 @@ description: >- `json_serializable` package. homepage: https://github.com/google/json_serializable.dart environment: - sdk: '>=2.6.0 <3.0.0' + sdk: '>=2.7.0 <3.0.0' # When changing JsonSerializable class. # dev_dependencies: diff --git a/json_serializable/mono_pkg.yaml b/json_serializable/mono_pkg.yaml index b3e0bd250..1933e6c12 100644 --- a/json_serializable/mono_pkg.yaml +++ b/json_serializable/mono_pkg.yaml @@ -1,6 +1,6 @@ # See https://github.com/google/mono_repo.dart for details on this file dart: -- 2.6.0 +- 2.7.0 - dev stages: @@ -11,7 +11,7 @@ stages: dart: [dev] - group: - dartanalyzer: --fatal-warnings . - dart: [2.6.0] + dart: [2.7.0] - unit_test: - test - command: pub run build_runner test --delete-conflicting-outputs -- -p chrome diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 03ecfd590..b70fc7764 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -5,7 +5,7 @@ description: >- Dart classes. homepage: https://github.com/google/json_serializable.dart environment: - sdk: '>=2.6.0 <3.0.0' + sdk: '>=2.7.0 <3.0.0' dependencies: analyzer: ^0.39.0 From 93780a80e8846e69061e3ec3cd44dcf2dcb2e133 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 7 Jul 2020 15:28:03 -0700 Subject: [PATCH 197/569] Fix changelogs for min SDK change --- checked_yaml/changelog.md | 2 +- json_annotation/CHANGELOG.md | 4 ++++ json_annotation/pubspec.yaml | 2 +- json_serializable/CHANGELOG.md | 1 + 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/checked_yaml/changelog.md b/checked_yaml/changelog.md index 2751393ee..d436fc9d3 100644 --- a/checked_yaml/changelog.md +++ b/checked_yaml/changelog.md @@ -1,6 +1,6 @@ ## 1.0.3-dev -- Require at least Dart `2.6.0`. +- Require at least Dart `2.7.0`. ## 1.0.2 diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index 3dedfef66..f77426e03 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -1,3 +1,7 @@ +## 3.0.2-dev + +- Require at least Dart `2.7.0`. + ## 3.0.1 - Require at least Dart `2.6.0`. diff --git a/json_annotation/pubspec.yaml b/json_annotation/pubspec.yaml index fc61a1605..bf2c5aa00 100644 --- a/json_annotation/pubspec.yaml +++ b/json_annotation/pubspec.yaml @@ -1,5 +1,5 @@ name: json_annotation -version: 3.0.1 +version: 3.0.2-dev description: >- Classes and helper functions that support JSON code generation via the `json_serializable` package. diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index a1142fda3..8b14afecf 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,6 +1,7 @@ ## 3.4.0-dev - Added support for `double` constants as default values. +- Require at least Dart `2.7.0`. ## 3.3.0 From cd796362d3233169521871e010abee14a06119c6 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 9 Jul 2020 15:45:28 -0700 Subject: [PATCH 198/569] add trailing commas to avoid wrapping param lists --- json_serializable/lib/src/decode_helper.dart | 18 ++++---- json_serializable/lib/src/encoder_helper.dart | 4 +- json_serializable/lib/src/helper_core.dart | 5 ++- json_serializable/lib/src/json_key_utils.dart | 14 ++++--- .../lib/src/json_literal_generator.dart | 5 ++- .../lib/src/json_serializable_generator.dart | 7 ++-- json_serializable/lib/src/type_helper.dart | 5 ++- .../lib/src/type_helpers/big_int_helper.dart | 10 ++++- .../lib/src/type_helpers/convert_helper.dart | 14 +++++-- .../src/type_helpers/date_time_helper.dart | 10 ++++- .../lib/src/type_helpers/duration_helper.dart | 11 ++++- .../lib/src/type_helpers/iterable_helper.dart | 12 ++++-- .../type_helpers/json_converter_helper.dart | 41 ++++++++++++++----- .../lib/src/type_helpers/json_helper.dart | 18 +++++--- .../lib/src/type_helpers/map_helper.dart | 14 +++++-- .../lib/src/type_helpers/to_from_string.dart | 12 +++++- .../lib/src/type_helpers/uri_helper.dart | 10 ++++- .../lib/src/type_helpers/value_helper.dart | 10 ++++- json_serializable/lib/src/utils.dart | 5 ++- 19 files changed, 166 insertions(+), 59 deletions(-) diff --git a/json_serializable/lib/src/decode_helper.dart b/json_serializable/lib/src/decode_helper.dart index 0a5748284..13df38e99 100644 --- a/json_serializable/lib/src/decode_helper.dart +++ b/json_serializable/lib/src/decode_helper.dart @@ -203,12 +203,13 @@ abstract class DecodeHelper implements HelperCore { /// [writableFields] are also populated, but only if they have not already /// been defined by a constructor parameter with the same name. _ConstructorData _writeConstructorInvocation( - ClassElement classElement, - Iterable availableConstructorParameters, - Iterable writableFields, - Map unavailableReasons, - String Function(String paramOrFieldName, {ParameterElement ctorParam}) - deserializeForField) { + ClassElement classElement, + Iterable availableConstructorParameters, + Iterable writableFields, + Map unavailableReasons, + String Function(String paramOrFieldName, {ParameterElement ctorParam}) + deserializeForField, +) { final className = classElement.name; final ctor = classElement.unnamedConstructor; @@ -289,5 +290,8 @@ class _ConstructorData { final Set usedCtorParamsAndFields; _ConstructorData( - this.content, this.fieldsToSet, this.usedCtorParamsAndFields); + this.content, + this.fieldsToSet, + this.usedCtorParamsAndFields, + ); } diff --git a/json_serializable/lib/src/encoder_helper.dart b/json_serializable/lib/src/encoder_helper.dart index da7aeddf9..12160bdab 100644 --- a/json_serializable/lib/src/encoder_helper.dart +++ b/json_serializable/lib/src/encoder_helper.dart @@ -50,7 +50,9 @@ abstract class EncodeHelper implements HelperCore { static const _toJsonParamName = 'instance'; void _writeToJsonWithNullChecks( - StringBuffer buffer, Iterable fields) { + StringBuffer buffer, + Iterable fields, + ) { buffer ..writeln('{') ..writeln(' final $generatedLocalVarName = {'); diff --git a/json_serializable/lib/src/helper_core.dart b/json_serializable/lib/src/helper_core.dart index 5e51fdc2b..6dadb7c1f 100644 --- a/json_serializable/lib/src/helper_core.dart +++ b/json_serializable/lib/src/helper_core.dart @@ -55,7 +55,10 @@ abstract class HelperCore { } InvalidGenerationSourceError createInvalidGenerationError( - String targetMember, FieldElement field, UnsupportedTypeError e) { + String targetMember, + FieldElement field, + UnsupportedTypeError e, +) { var message = 'Could not generate `$targetMember` code for `${field.name}`'; if (field.type != e.type) { message = '$message because of type `${typeToCode(e.type)}`'; diff --git a/json_serializable/lib/src/json_key_utils.dart b/json_serializable/lib/src/json_key_utils.dart index f316f3663..30d9217b5 100644 --- a/json_serializable/lib/src/json_key_utils.dart +++ b/json_serializable/lib/src/json_key_utils.dart @@ -105,10 +105,11 @@ JsonKey _from(FieldElement element, JsonSerializable classAnnotation) { badType = typeInformation.followedBy(['$dartObject']).join(' > '); throwUnsupported( - element, - 'The provided value is not supported: $badType. ' - 'This may be an error in package:json_serializable. ' - 'Please rerun your build with `--verbose` and file an issue.'); + element, + 'The provided value is not supported: $badType. ' + 'This may be an error in package:json_serializable. ' + 'Please rerun your build with `--verbose` and file an issue.', + ); } /// Returns a literal object representing the value of [fieldName] in [obj]. @@ -233,7 +234,10 @@ String _encodedFieldName(JsonSerializable classAnnotation, } bool _includeIfNull( - bool keyIncludeIfNull, bool keyDisallowNullValue, bool classIncludeIfNull) { + bool keyIncludeIfNull, + bool keyDisallowNullValue, + bool classIncludeIfNull, +) { if (keyDisallowNullValue == true) { assert(keyIncludeIfNull != true); return false; diff --git a/json_serializable/lib/src/json_literal_generator.dart b/json_serializable/lib/src/json_literal_generator.dart index 226117803..e2f155fdd 100644 --- a/json_serializable/lib/src/json_literal_generator.dart +++ b/json_serializable/lib/src/json_literal_generator.dart @@ -18,7 +18,10 @@ class JsonLiteralGenerator extends GeneratorForAnnotation { @override Future generateForAnnotatedElement( - Element element, ConstantReader annotation, BuildStep buildStep) async { + Element element, + ConstantReader annotation, + BuildStep buildStep, + ) async { if (p.isAbsolute(annotation.read('path').stringValue)) { throw ArgumentError( '`annotation.path` must be relative path to the source file.'); diff --git a/json_serializable/lib/src/json_serializable_generator.dart b/json_serializable/lib/src/json_serializable_generator.dart index 230457e72..0cbb26ea3 100644 --- a/json_serializable/lib/src/json_serializable_generator.dart +++ b/json_serializable/lib/src/json_serializable_generator.dart @@ -46,7 +46,7 @@ class JsonSerializableGenerator Iterable get _allHelpers => const [ ConvertHelper(), - JsonConverterHelper() + JsonConverterHelper(), ].followedBy(_typeHelpers).followedBy(_coreHelpers); final JsonSerializable _config; @@ -71,8 +71,9 @@ class JsonSerializableGenerator /// [BigIntHelper], [DateTimeHelper], [DurationHelper], [JsonHelper], and /// [UriHelper]. factory JsonSerializableGenerator.withDefaultHelpers( - Iterable typeHelpers, - {JsonSerializable config}) => + Iterable typeHelpers, { + JsonSerializable config, + }) => JsonSerializableGenerator( config: config, typeHelpers: List.unmodifiable(typeHelpers.followedBy(_defaultHelpers)), diff --git a/json_serializable/lib/src/type_helper.dart b/json_serializable/lib/src/type_helper.dart index 3589eabc0..cef3d4afb 100644 --- a/json_serializable/lib/src/type_helper.dart +++ b/json_serializable/lib/src/type_helper.dart @@ -83,7 +83,10 @@ abstract class TypeHelper { } Object commonNullPrefix( - bool nullable, String expression, Object unsafeExpression) => + bool nullable, + String expression, + Object unsafeExpression, +) => nullable ? '$expression == null ? null : $unsafeExpression' : unsafeExpression; diff --git a/json_serializable/lib/src/type_helpers/big_int_helper.dart b/json_serializable/lib/src/type_helpers/big_int_helper.dart index 6a21f2218..60017827f 100644 --- a/json_serializable/lib/src/type_helpers/big_int_helper.dart +++ b/json_serializable/lib/src/type_helpers/big_int_helper.dart @@ -12,11 +12,17 @@ class BigIntHelper extends TypeHelper { @override String serialize( - DartType targetType, String expression, TypeHelperContext context) => + DartType targetType, + String expression, + TypeHelperContext context, + ) => bigIntString.serialize(targetType, expression, context.nullable); @override String deserialize( - DartType targetType, String expression, TypeHelperContext context) => + DartType targetType, + String expression, + TypeHelperContext context, + ) => bigIntString.deserialize(targetType, expression, context.nullable, false); } diff --git a/json_serializable/lib/src/type_helpers/convert_helper.dart b/json_serializable/lib/src/type_helpers/convert_helper.dart index f5f228f66..10c9fc22c 100644 --- a/json_serializable/lib/src/type_helpers/convert_helper.dart +++ b/json_serializable/lib/src/type_helpers/convert_helper.dart @@ -28,8 +28,11 @@ class ConvertHelper extends TypeHelper { const ConvertHelper(); @override - String serialize(DartType targetType, String expression, - TypeHelperContextWithConvert context) { + String serialize( + DartType targetType, + String expression, + TypeHelperContextWithConvert context, + ) { final toJsonData = context.serializeConvertData; if (toJsonData == null) { return null; @@ -43,8 +46,11 @@ class ConvertHelper extends TypeHelper { } @override - String deserialize(DartType targetType, String expression, - TypeHelperContextWithConvert context) { + String deserialize( + DartType targetType, + String expression, + TypeHelperContextWithConvert context, + ) { final fromJsonData = context.deserializeConvertData; if (fromJsonData == null) { return null; diff --git a/json_serializable/lib/src/type_helpers/date_time_helper.dart b/json_serializable/lib/src/type_helpers/date_time_helper.dart index 17a6cc7b0..e10a6f96c 100644 --- a/json_serializable/lib/src/type_helpers/date_time_helper.dart +++ b/json_serializable/lib/src/type_helpers/date_time_helper.dart @@ -12,12 +12,18 @@ class DateTimeHelper extends TypeHelper { @override String serialize( - DartType targetType, String expression, TypeHelperContext context) => + DartType targetType, + String expression, + TypeHelperContext context, + ) => dateTimeString.serialize(targetType, expression, context.nullable); @override String deserialize( - DartType targetType, String expression, TypeHelperContext context) => + DartType targetType, + String expression, + TypeHelperContext context, + ) => dateTimeString.deserialize( targetType, expression, context.nullable, false); } diff --git a/json_serializable/lib/src/type_helpers/duration_helper.dart b/json_serializable/lib/src/type_helpers/duration_helper.dart index 64d999d71..63bdd52d7 100644 --- a/json_serializable/lib/src/type_helpers/duration_helper.dart +++ b/json_serializable/lib/src/type_helpers/duration_helper.dart @@ -4,6 +4,7 @@ import 'package:analyzer/dart/element/type.dart'; import 'package:source_gen/source_gen.dart' show TypeChecker; + import '../type_helper.dart'; class DurationHelper extends TypeHelper { @@ -11,7 +12,10 @@ class DurationHelper extends TypeHelper { @override String serialize( - DartType targetType, String expression, TypeHelperContext context) { + DartType targetType, + String expression, + TypeHelperContext context, + ) { if (!_matchesType(targetType)) { return null; } @@ -29,7 +33,10 @@ class DurationHelper extends TypeHelper { @override String deserialize( - DartType targetType, String expression, TypeHelperContext context) { + DartType targetType, + String expression, + TypeHelperContext context, + ) { if (!_matchesType(targetType)) { return null; } diff --git a/json_serializable/lib/src/type_helpers/iterable_helper.dart b/json_serializable/lib/src/type_helpers/iterable_helper.dart index 3ea686703..30be10767 100644 --- a/json_serializable/lib/src/type_helpers/iterable_helper.dart +++ b/json_serializable/lib/src/type_helpers/iterable_helper.dart @@ -14,8 +14,11 @@ class IterableHelper extends TypeHelper { const IterableHelper(); @override - String serialize(DartType targetType, String expression, - TypeHelperContextWithConfig context) { + String serialize( + DartType targetType, + String expression, + TypeHelperContextWithConfig context, + ) { if (!coreIterableTypeChecker.isAssignableFromType(targetType)) { return null; } @@ -53,7 +56,10 @@ class IterableHelper extends TypeHelper { @override String deserialize( - DartType targetType, String expression, TypeHelperContext context) { + DartType targetType, + String expression, + TypeHelperContext context, + ) { if (!(coreIterableTypeChecker.isExactlyType(targetType) || _coreListChecker.isExactlyType(targetType) || _coreSetChecker.isExactlyType(targetType))) { diff --git a/json_serializable/lib/src/type_helpers/json_converter_helper.dart b/json_serializable/lib/src/type_helpers/json_converter_helper.dart index 6a509aa6f..aae2dd580 100644 --- a/json_serializable/lib/src/type_helpers/json_converter_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_converter_helper.dart @@ -21,7 +21,10 @@ class JsonConverterHelper extends TypeHelper { @override Object serialize( - DartType targetType, String expression, TypeHelperContext context) { + DartType targetType, + String expression, + TypeHelperContext context, + ) { final converter = _typeConverter(targetType, context); if (converter == null) { @@ -35,7 +38,10 @@ class JsonConverterHelper extends TypeHelper { @override Object deserialize( - DartType targetType, String expression, TypeHelperContext context) { + DartType targetType, + String expression, + TypeHelperContext context, + ) { final converter = _typeConverter(targetType, context); if (converter == null) { return null; @@ -54,13 +60,18 @@ class _JsonConvertData { final String accessString; final DartType jsonType; - _JsonConvertData.className(String className, String accessor, this.jsonType) - : accessString = 'const $className${_withAccessor(accessor)}()'; + _JsonConvertData.className( + String className, + String accessor, + this.jsonType, + ) : accessString = 'const $className${_withAccessor(accessor)}()'; _JsonConvertData.genericClass( - String className, String genericTypeArg, String accessor, this.jsonType) - : accessString = - '$className<$genericTypeArg>${_withAccessor(accessor)}()'; + String className, + String genericTypeArg, + String accessor, + this.jsonType, + ) : accessString = '$className<$genericTypeArg>${_withAccessor(accessor)}()'; _JsonConvertData.propertyAccess(this.accessString, this.jsonType); @@ -89,7 +100,9 @@ _JsonConvertData _typeConverter(DartType targetType, TypeHelperContext ctx) { } _JsonConvertData _typeConverterFrom( - List<_ConverterMatch> matchingAnnotations, DartType targetType) { + List<_ConverterMatch> matchingAnnotations, + DartType targetType, +) { if (matchingAnnotations.isEmpty) { return null; } @@ -147,12 +160,18 @@ class _ConverterMatch { final ElementAnnotation elementAnnotation; final String genericTypeArg; - _ConverterMatch(this.elementAnnotation, this.annotation, this.jsonType, - this.genericTypeArg); + _ConverterMatch( + this.elementAnnotation, + this.annotation, + this.jsonType, + this.genericTypeArg, + ); } _ConverterMatch _compatibleMatch( - DartType targetType, ElementAnnotation annotation) { + DartType targetType, + ElementAnnotation annotation, +) { final constantValue = annotation.computeConstantValue(); final converterClassElement = constantValue.type.element as ClassElement; diff --git a/json_serializable/lib/src/type_helpers/json_helper.dart b/json_serializable/lib/src/type_helpers/json_helper.dart index e106604f5..4b64dbb0d 100644 --- a/json_serializable/lib/src/type_helpers/json_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_helper.dart @@ -20,8 +20,11 @@ class JsonHelper extends TypeHelper { /// By default, JSON encoding in from `dart:convert` calls `toJson()` on /// provided objects. @override - String serialize(DartType targetType, String expression, - TypeHelperContextWithConfig context) { + String serialize( + DartType targetType, + String expression, + TypeHelperContextWithConfig context, + ) { if (!_canSerialize(context.config, targetType)) { return null; } @@ -33,8 +36,11 @@ class JsonHelper extends TypeHelper { } @override - String deserialize(DartType targetType, String expression, - TypeHelperContextWithConfig context) { + String deserialize( + DartType targetType, + String expression, + TypeHelperContextWithConfig context, + ) { if (targetType is! InterfaceType) { return null; } @@ -97,7 +103,9 @@ bool _canSerialize(JsonSerializable config, DartType type) { /// Returns an instantiation of [ctorParamType] by providing argument types /// derived by matching corresponding type parameters from [classType]. InterfaceType _instantiate( - InterfaceType ctorParamType, InterfaceType classType) { + InterfaceType ctorParamType, + InterfaceType classType, +) { final argTypes = ctorParamType.typeArguments.map((arg) { final typeParamIndex = classType.element.typeParameters.indexWhere( // TODO(kevmoo): not 100% sure `nullabilitySuffix` is right diff --git a/json_serializable/lib/src/type_helpers/map_helper.dart b/json_serializable/lib/src/type_helpers/map_helper.dart index ffa3192e5..7eff332e6 100644 --- a/json_serializable/lib/src/type_helpers/map_helper.dart +++ b/json_serializable/lib/src/type_helpers/map_helper.dart @@ -17,8 +17,11 @@ class MapHelper extends TypeHelper { const MapHelper(); @override - String serialize(DartType targetType, String expression, - TypeHelperContextWithConfig context) { + String serialize( + DartType targetType, + String expression, + TypeHelperContextWithConfig context, + ) { if (!coreMapTypeChecker.isAssignableFromType(targetType)) { return null; } @@ -47,8 +50,11 @@ class MapHelper extends TypeHelper { } @override - String deserialize(DartType targetType, String expression, - TypeHelperContextWithConfig context) { + String deserialize( + DartType targetType, + String expression, + TypeHelperContextWithConfig context, + ) { if (!coreMapTypeChecker.isExactlyType(targetType)) { return null; } diff --git a/json_serializable/lib/src/type_helpers/to_from_string.dart b/json_serializable/lib/src/type_helpers/to_from_string.dart index 5de4ca6e9..7a5d94715 100644 --- a/json_serializable/lib/src/type_helpers/to_from_string.dart +++ b/json_serializable/lib/src/type_helpers/to_from_string.dart @@ -48,7 +48,11 @@ class ToFromStringHelper { bool matches(DartType type) => _checker.isExactlyType(type); - String serialize(DartType type, String expression, bool nullable) { + String serialize( + DartType type, + String expression, + bool nullable, + ) { if (!matches(type)) { return null; } @@ -61,7 +65,11 @@ class ToFromStringHelper { } String deserialize( - DartType type, String expression, bool nullable, bool isString) { + DartType type, + String expression, + bool nullable, + bool isString, + ) { if (!matches(type)) { return null; } diff --git a/json_serializable/lib/src/type_helpers/uri_helper.dart b/json_serializable/lib/src/type_helpers/uri_helper.dart index 3a855a7ef..81267d903 100644 --- a/json_serializable/lib/src/type_helpers/uri_helper.dart +++ b/json_serializable/lib/src/type_helpers/uri_helper.dart @@ -12,11 +12,17 @@ class UriHelper extends TypeHelper { @override String serialize( - DartType targetType, String expression, TypeHelperContext context) => + DartType targetType, + String expression, + TypeHelperContext context, + ) => uriString.serialize(targetType, expression, context.nullable); @override String deserialize( - DartType targetType, String expression, TypeHelperContext context) => + DartType targetType, + String expression, + TypeHelperContext context, + ) => uriString.deserialize(targetType, expression, context.nullable, false); } diff --git a/json_serializable/lib/src/type_helpers/value_helper.dart b/json_serializable/lib/src/type_helpers/value_helper.dart index 5d0bef367..ef898e0a4 100644 --- a/json_serializable/lib/src/type_helpers/value_helper.dart +++ b/json_serializable/lib/src/type_helpers/value_helper.dart @@ -14,7 +14,10 @@ class ValueHelper extends TypeHelper { @override String serialize( - DartType targetType, String expression, TypeHelperContext context) { + DartType targetType, + String expression, + TypeHelperContext context, + ) { if (isObjectOrDynamic(targetType) || simpleJsonTypeChecker.isAssignableFromType(targetType)) { return expression; @@ -25,7 +28,10 @@ class ValueHelper extends TypeHelper { @override String deserialize( - DartType targetType, String expression, TypeHelperContext context) { + DartType targetType, + String expression, + TypeHelperContext context, + ) { if (isObjectOrDynamic(targetType)) { // just return it as-is. We'll hope it's safe. return expression; diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index 40ac04a20..0c87fb6b3 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -66,7 +66,10 @@ FieldRename _fromDartObject(ConstantReader reader) => reader.isNull ); T enumValueForDartObject( - DartObject source, List items, String Function(T) name) => + DartObject source, + List items, + String Function(T) name, +) => items.singleWhere( (v) => source.getField(name(v)) != null, // TODO: remove once pkg:analyzer < 0.35.0 is no longer supported From a8f956375c1fd62c4c1be155f482422ec69b3b97 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 9 Jul 2020 15:52:20 -0700 Subject: [PATCH 199/569] sort entries in build.yaml --- json_serializable/build.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/json_serializable/build.yaml b/json_serializable/build.yaml index bfba2eb8d..97bc7a16a 100644 --- a/json_serializable/build.yaml +++ b/json_serializable/build.yaml @@ -21,11 +21,11 @@ targets: json_serializable|_internal: generate_for: - test/default_value/default_value.dart - - test/kitchen_sink/kitchen_sink.dart - - test/integration/json_test_example.dart - test/generic_files/generic_class.dart - test/integration/json_test_example.dart + - test/integration/json_test_example.dart - test/integration/json_test_example.non_nullable.dart + - test/kitchen_sink/kitchen_sink.dart builders: _internal: From 9f8763e33ef071d358e1ab0c446bd64a906b962a Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Fri, 10 Jul 2020 13:57:25 -0700 Subject: [PATCH 200/569] Support Set literals in JsonKey.defaultValue --- json_serializable/CHANGELOG.md | 1 + json_serializable/lib/src/json_key_utils.dart | 26 ++++++++++++++----- .../lib/src/json_literal_generator.dart | 5 ++++ json_serializable/pubspec.yaml | 2 +- .../test/default_value/default_value.dart | 6 +++++ .../test/default_value/default_value.g.dart | 6 +++++ .../default_value.g_any_map__checked.dart | 6 +++++ .../default_value.g_any_map__checked.g.dart | 10 +++++++ .../default_value_interface.dart | 2 ++ .../default_value/default_value_test.dart | 4 +++ 10 files changed, 60 insertions(+), 8 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 8b14afecf..41c3f3097 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,6 +1,7 @@ ## 3.4.0-dev - Added support for `double` constants as default values. +- Support `Set` literals in `JsonKey.defaultValue`. - Require at least Dart `2.7.0`. ## 3.3.0 diff --git a/json_serializable/lib/src/json_key_utils.dart b/json_serializable/lib/src/json_key_utils.dart index 30d9217b5..5c1a9c565 100644 --- a/json_serializable/lib/src/json_key_utils.dart +++ b/json_serializable/lib/src/json_key_utils.dart @@ -77,24 +77,36 @@ JsonKey _from(FieldElement element, JsonSerializable classAnnotation) { element, '`defaultValue` is `$badType`, it must be a literal.'); } - final literal = reader.literalValue; + if (reader.isDouble || reader.isInt || reader.isString || reader.isBool) { + return reader.literalValue; + } - if (literal is num || literal is String || literal is bool) { - return literal; - } else if (literal is List) { + if (reader.isList) { return [ - for (var e in literal) + for (var e in reader.listValue) literalForObject(e, [ ...typeInformation, 'List', ]) ]; - } else if (literal is Map) { + } + + if (reader.isSet) { + return { + for (var e in reader.setValue) + literalForObject(e, [ + ...typeInformation, + 'Set', + ]) + }; + } + + if (reader.isMap) { final mapTypeInformation = [ ...typeInformation, 'Map', ]; - return literal.map( + return reader.mapValue.map( (k, v) => MapEntry( literalForObject(k, mapTypeInformation), literalForObject(v, mapTypeInformation), diff --git a/json_serializable/lib/src/json_literal_generator.dart b/json_serializable/lib/src/json_literal_generator.dart index e2f155fdd..cf01a6852 100644 --- a/json_serializable/lib/src/json_literal_generator.dart +++ b/json_serializable/lib/src/json_literal_generator.dart @@ -67,6 +67,11 @@ String jsonLiteralAsDart(dynamic value) { return '[$listItems]'; } + if (value is Set) { + final listItems = value.map(jsonLiteralAsDart).join(', '); + return '{$listItems}'; + } + if (value is Map) return jsonMapAsDart(value); throw StateError( diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index b70fc7764..489c0da20 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -19,7 +19,7 @@ dependencies: json_annotation: '>=3.0.0 <3.1.0' meta: ^1.1.0 path: ^1.3.2 - source_gen: ^0.9.0 + source_gen: ^0.9.6 dev_dependencies: build_runner: ^1.0.0 diff --git a/json_serializable/test/default_value/default_value.dart b/json_serializable/test/default_value/default_value.dart index e34f490e6..083c60d05 100644 --- a/json_serializable/test/default_value/default_value.dart +++ b/json_serializable/test/default_value/default_value.dart @@ -33,12 +33,18 @@ class DefaultValue implements dvi.DefaultValue { @JsonKey(defaultValue: []) List fieldListEmpty; + @JsonKey(defaultValue: {}) + Set fieldSetEmpty; + @JsonKey(defaultValue: {}) Map fieldMapEmpty; @JsonKey(defaultValue: [1, 2, 3]) List fieldListSimple; + @JsonKey(defaultValue: {'entry1', 'entry2'}) + Set fieldSetSimple; + @JsonKey(defaultValue: {'answer': 42}) Map fieldMapSimple; diff --git a/json_serializable/test/default_value/default_value.g.dart b/json_serializable/test/default_value/default_value.g.dart index e481851ac..95bcdd973 100644 --- a/json_serializable/test/default_value/default_value.g.dart +++ b/json_serializable/test/default_value/default_value.g.dart @@ -13,10 +13,14 @@ DefaultValue _$DefaultValueFromJson(Map json) { ..fieldInt = json['fieldInt'] as int ?? 42 ..fieldDouble = (json['fieldDouble'] as num)?.toDouble() ?? 3.14 ..fieldListEmpty = json['fieldListEmpty'] as List ?? [] + ..fieldSetEmpty = (json['fieldSetEmpty'] as List)?.toSet() ?? {} ..fieldMapEmpty = json['fieldMapEmpty'] as Map ?? {} ..fieldListSimple = (json['fieldListSimple'] as List)?.map((e) => e as int)?.toList() ?? [1, 2, 3] + ..fieldSetSimple = + (json['fieldSetSimple'] as List)?.map((e) => e as String)?.toSet() ?? + {'entry1', 'entry2'} ..fieldMapSimple = (json['fieldMapSimple'] as Map)?.map( (k, e) => MapEntry(k, e as int), ) ?? @@ -48,8 +52,10 @@ Map _$DefaultValueToJson(DefaultValue instance) { val['fieldInt'] = instance.fieldInt; val['fieldDouble'] = instance.fieldDouble; val['fieldListEmpty'] = instance.fieldListEmpty; + val['fieldSetEmpty'] = instance.fieldSetEmpty?.toList(); val['fieldMapEmpty'] = instance.fieldMapEmpty; val['fieldListSimple'] = instance.fieldListSimple; + val['fieldSetSimple'] = instance.fieldSetSimple?.toList(); val['fieldMapSimple'] = instance.fieldMapSimple; val['fieldMapListString'] = instance.fieldMapListString; val['fieldEnum'] = _$GreekEnumMap[instance.fieldEnum]; diff --git a/json_serializable/test/default_value/default_value.g_any_map__checked.dart b/json_serializable/test/default_value/default_value.g_any_map__checked.dart index 7bd6dd8cd..d0b3ffae5 100644 --- a/json_serializable/test/default_value/default_value.g_any_map__checked.dart +++ b/json_serializable/test/default_value/default_value.g_any_map__checked.dart @@ -36,12 +36,18 @@ class DefaultValue implements dvi.DefaultValue { @JsonKey(defaultValue: []) List fieldListEmpty; + @JsonKey(defaultValue: {}) + Set fieldSetEmpty; + @JsonKey(defaultValue: {}) Map fieldMapEmpty; @JsonKey(defaultValue: [1, 2, 3]) List fieldListSimple; + @JsonKey(defaultValue: {'entry1', 'entry2'}) + Set fieldSetSimple; + @JsonKey(defaultValue: {'answer': 42}) Map fieldMapSimple; diff --git a/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart b/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart index f114c16b4..528e085e1 100644 --- a/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart +++ b/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart @@ -18,6 +18,8 @@ DefaultValue _$DefaultValueFromJson(Map json) { (v) => val.fieldDouble = (v as num)?.toDouble() ?? 3.14); $checkedConvert( json, 'fieldListEmpty', (v) => val.fieldListEmpty = v as List ?? []); + $checkedConvert(json, 'fieldSetEmpty', + (v) => val.fieldSetEmpty = (v as List)?.toSet() ?? {}); $checkedConvert( json, 'fieldMapEmpty', (v) => val.fieldMapEmpty = v as Map ?? {}); $checkedConvert( @@ -25,6 +27,12 @@ DefaultValue _$DefaultValueFromJson(Map json) { 'fieldListSimple', (v) => val.fieldListSimple = (v as List)?.map((e) => e as int)?.toList() ?? [1, 2, 3]); + $checkedConvert( + json, + 'fieldSetSimple', + (v) => val.fieldSetSimple = + (v as List)?.map((e) => e as String)?.toSet() ?? + {'entry1', 'entry2'}); $checkedConvert( json, 'fieldMapSimple', @@ -66,8 +74,10 @@ Map _$DefaultValueToJson(DefaultValue instance) { val['fieldInt'] = instance.fieldInt; val['fieldDouble'] = instance.fieldDouble; val['fieldListEmpty'] = instance.fieldListEmpty; + val['fieldSetEmpty'] = instance.fieldSetEmpty?.toList(); val['fieldMapEmpty'] = instance.fieldMapEmpty; val['fieldListSimple'] = instance.fieldListSimple; + val['fieldSetSimple'] = instance.fieldSetSimple?.toList(); val['fieldMapSimple'] = instance.fieldMapSimple; val['fieldMapListString'] = instance.fieldMapListString; val['fieldEnum'] = _$GreekEnumMap[instance.fieldEnum]; diff --git a/json_serializable/test/default_value/default_value_interface.dart b/json_serializable/test/default_value/default_value_interface.dart index 2f0643f6b..957889694 100644 --- a/json_serializable/test/default_value/default_value_interface.dart +++ b/json_serializable/test/default_value/default_value_interface.dart @@ -13,7 +13,9 @@ abstract class DefaultValue { double fieldDouble; List fieldListEmpty; Map fieldMapEmpty; + Set fieldSetEmpty; List fieldListSimple; + Set fieldSetSimple; Map fieldMapSimple; Map> fieldMapListString; Greek fieldEnum; diff --git a/json_serializable/test/default_value/default_value_test.dart b/json_serializable/test/default_value/default_value_test.dart index f59918cc3..00ef236ad 100644 --- a/json_serializable/test/default_value/default_value_test.dart +++ b/json_serializable/test/default_value/default_value_test.dart @@ -15,8 +15,10 @@ const _defaultInstance = { 'fieldInt': 42, 'fieldDouble': 3.14, 'fieldListEmpty': [], + 'fieldSetEmpty': [], 'fieldMapEmpty': {}, 'fieldListSimple': [1, 2, 3], + 'fieldSetSimple': ['entry1', 'entry2'], 'fieldMapSimple': {'answer': 42}, 'fieldMapListString': { 'root': ['child'] @@ -30,8 +32,10 @@ const _otherValues = { 'fieldInt': 43, 'fieldDouble': 2.718, 'fieldListEmpty': [42], + 'fieldSetEmpty': [42], 'fieldMapEmpty': {'question': false}, 'fieldListSimple': [4, 5, 6], + 'fieldSetSimple': ['entry3'], 'fieldMapSimple': {}, 'fieldMapListString': { 'root2': ['alpha'] From 94a654b9e50a08f1d0c3b3549a5f4d1d0388fd84 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Fri, 10 Jul 2020 17:51:51 -0700 Subject: [PATCH 201/569] Add new builder for each supported type (#668) Make it easy to validate basic behavior of each type in isolation --- json_serializable/build.yaml | 61 ++++- .../test/supported_types/input.dart | 28 ++ .../test/supported_types/input.g.dart | 21 ++ .../supported_types/input.type_bigint.dart | 25 ++ .../supported_types/input.type_bigint.g.dart | 20 ++ .../test/supported_types/input.type_bool.dart | 28 ++ .../supported_types/input.type_bool.g.dart | 21 ++ .../supported_types/input.type_datetime.dart | 25 ++ .../input.type_datetime.g.dart | 20 ++ .../supported_types/input.type_double.dart | 28 ++ .../supported_types/input.type_double.g.dart | 21 ++ .../supported_types/input.type_duration.dart | 25 ++ .../input.type_duration.g.dart | 20 ++ .../supported_types/input.type_dynamic.dart | 25 ++ .../supported_types/input.type_dynamic.g.dart | 20 ++ .../supported_types/input.type_iterable.dart | 28 ++ .../input.type_iterable.g.dart | 21 ++ .../test/supported_types/input.type_list.dart | 28 ++ .../supported_types/input.type_list.g.dart | 21 ++ .../test/supported_types/input.type_map.dart | 28 ++ .../supported_types/input.type_map.g.dart | 21 ++ .../supported_types/input.type_myenum.dart | 30 +++ .../supported_types/input.type_myenum.g.dart | 61 +++++ .../test/supported_types/input.type_num.dart | 28 ++ .../supported_types/input.type_num.g.dart | 21 ++ .../supported_types/input.type_object.dart | 25 ++ .../supported_types/input.type_object.g.dart | 20 ++ .../test/supported_types/input.type_set.dart | 28 ++ .../supported_types/input.type_set.g.dart | 22 ++ .../supported_types/input.type_string.dart | 28 ++ .../supported_types/input.type_string.g.dart | 21 ++ .../test/supported_types/input.type_uri.dart | 25 ++ .../supported_types/input.type_uri.g.dart | 20 ++ .../type_test.bigint_test.dart | 41 +++ .../supported_types/type_test.bool_test.dart | 43 ++++ .../test/supported_types/type_test.dart | 43 ++++ .../type_test.datetime_test.dart | 41 +++ .../type_test.double_test.dart | 43 ++++ .../type_test.duration_test.dart | 41 +++ .../type_test.dynamic_test.dart | 41 +++ .../type_test.iterable_test.dart | 43 ++++ .../supported_types/type_test.list_test.dart | 43 ++++ .../supported_types/type_test.map_test.dart | 43 ++++ .../type_test.myenum_test.dart | 43 ++++ .../supported_types/type_test.num_test.dart | 43 ++++ .../type_test.object_test.dart | 41 +++ .../supported_types/type_test.set_test.dart | 43 ++++ .../type_test.string_test.dart | 43 ++++ .../supported_types/type_test.uri_test.dart | 41 +++ json_serializable/tool/shared.dart | 71 +++++ json_serializable/tool/test_builder.dart | 117 +++------ json_serializable/tool/test_type_builder.dart | 243 ++++++++++++++++++ 52 files changed, 1881 insertions(+), 90 deletions(-) create mode 100644 json_serializable/test/supported_types/input.dart create mode 100644 json_serializable/test/supported_types/input.g.dart create mode 100644 json_serializable/test/supported_types/input.type_bigint.dart create mode 100644 json_serializable/test/supported_types/input.type_bigint.g.dart create mode 100644 json_serializable/test/supported_types/input.type_bool.dart create mode 100644 json_serializable/test/supported_types/input.type_bool.g.dart create mode 100644 json_serializable/test/supported_types/input.type_datetime.dart create mode 100644 json_serializable/test/supported_types/input.type_datetime.g.dart create mode 100644 json_serializable/test/supported_types/input.type_double.dart create mode 100644 json_serializable/test/supported_types/input.type_double.g.dart create mode 100644 json_serializable/test/supported_types/input.type_duration.dart create mode 100644 json_serializable/test/supported_types/input.type_duration.g.dart create mode 100644 json_serializable/test/supported_types/input.type_dynamic.dart create mode 100644 json_serializable/test/supported_types/input.type_dynamic.g.dart create mode 100644 json_serializable/test/supported_types/input.type_iterable.dart create mode 100644 json_serializable/test/supported_types/input.type_iterable.g.dart create mode 100644 json_serializable/test/supported_types/input.type_list.dart create mode 100644 json_serializable/test/supported_types/input.type_list.g.dart create mode 100644 json_serializable/test/supported_types/input.type_map.dart create mode 100644 json_serializable/test/supported_types/input.type_map.g.dart create mode 100644 json_serializable/test/supported_types/input.type_myenum.dart create mode 100644 json_serializable/test/supported_types/input.type_myenum.g.dart create mode 100644 json_serializable/test/supported_types/input.type_num.dart create mode 100644 json_serializable/test/supported_types/input.type_num.g.dart create mode 100644 json_serializable/test/supported_types/input.type_object.dart create mode 100644 json_serializable/test/supported_types/input.type_object.g.dart create mode 100644 json_serializable/test/supported_types/input.type_set.dart create mode 100644 json_serializable/test/supported_types/input.type_set.g.dart create mode 100644 json_serializable/test/supported_types/input.type_string.dart create mode 100644 json_serializable/test/supported_types/input.type_string.g.dart create mode 100644 json_serializable/test/supported_types/input.type_uri.dart create mode 100644 json_serializable/test/supported_types/input.type_uri.g.dart create mode 100644 json_serializable/test/supported_types/type_test.bigint_test.dart create mode 100644 json_serializable/test/supported_types/type_test.bool_test.dart create mode 100644 json_serializable/test/supported_types/type_test.dart create mode 100644 json_serializable/test/supported_types/type_test.datetime_test.dart create mode 100644 json_serializable/test/supported_types/type_test.double_test.dart create mode 100644 json_serializable/test/supported_types/type_test.duration_test.dart create mode 100644 json_serializable/test/supported_types/type_test.dynamic_test.dart create mode 100644 json_serializable/test/supported_types/type_test.iterable_test.dart create mode 100644 json_serializable/test/supported_types/type_test.list_test.dart create mode 100644 json_serializable/test/supported_types/type_test.map_test.dart create mode 100644 json_serializable/test/supported_types/type_test.myenum_test.dart create mode 100644 json_serializable/test/supported_types/type_test.num_test.dart create mode 100644 json_serializable/test/supported_types/type_test.object_test.dart create mode 100644 json_serializable/test/supported_types/type_test.set_test.dart create mode 100644 json_serializable/test/supported_types/type_test.string_test.dart create mode 100644 json_serializable/test/supported_types/type_test.uri_test.dart create mode 100644 json_serializable/tool/shared.dart create mode 100644 json_serializable/tool/test_type_builder.dart diff --git a/json_serializable/build.yaml b/json_serializable/build.yaml index 97bc7a16a..5263d6ac7 100644 --- a/json_serializable/build.yaml +++ b/json_serializable/build.yaml @@ -10,6 +10,7 @@ targets: - test/integration/* - test/kitchen_sink/* - test/literal/* + - test/supported_types/* build_web_compilers|entrypoint: generate_for: @@ -18,7 +19,7 @@ targets: - test/integration/*.browser_test.dart - test/kitchen_sink/**.browser_test.dart - json_serializable|_internal: + json_serializable|_test_builder: generate_for: - test/default_value/default_value.dart - test/generic_files/generic_class.dart @@ -27,10 +28,18 @@ targets: - test/integration/json_test_example.non_nullable.dart - test/kitchen_sink/kitchen_sink.dart + json_serializable|_type_builder: + generate_for: + - test/supported_types/input.dart + + json_serializable|_type_test_builder: + generate_for: + - test/supported_types/type_test.dart + builders: - _internal: + _test_builder: import: 'tool/test_builder.dart' - builder_factories: ['internal'] + builder_factories: ['testBuilder'] build_extensions: .dart: - .factories.dart @@ -45,6 +54,52 @@ builders: build_to: source runs_before: ["json_serializable"] + _type_builder: + import: 'tool/test_type_builder.dart' + builder_factories: ['typeBuilder'] + build_extensions: + .dart: + - .type_bigint.dart + - .type_bool.dart + - .type_datetime.dart + - .type_double.dart + - .type_duration.dart + - .type_dynamic.dart + - .type_iterable.dart + - .type_list.dart + - .type_map.dart + - .type_myenum.dart + - .type_num.dart + - .type_object.dart + - .type_set.dart + - .type_string.dart + - .type_uri.dart + build_to: source + runs_before: ["json_serializable"] + + _type_test_builder: + import: 'tool/test_type_builder.dart' + builder_factories: ['typeTestBuilder'] + build_extensions: + .dart: + - .bigint_test.dart + - .bool_test.dart + - .datetime_test.dart + - .double_test.dart + - .duration_test.dart + - .dynamic_test.dart + - .iterable_test.dart + - .list_test.dart + - .map_test.dart + - .myenum_test.dart + - .num_test.dart + - .object_test.dart + - .set_test.dart + - .string_test.dart + - .uri_test.dart + build_to: source + runs_before: ["json_serializable"] + _doc_builder: import: "tool/doc_builder.dart" builder_factories: ["docBuilder"] diff --git a/json_serializable/test/supported_types/input.dart b/json_serializable/test/supported_types/input.dart new file mode 100644 index 000000000..ec1359ed3 --- /dev/null +++ b/json_serializable/test/supported_types/input.dart @@ -0,0 +1,28 @@ +// Copyright (c) 2020, 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:json_annotation/json_annotation.dart'; + +part 'input.g.dart'; + +@JsonSerializable() +class SimpleClass { + final int value; + + @JsonKey(nullable: false) + final int nullable; + + @JsonKey(defaultValue: 42) + int withDefault; + + SimpleClass( + this.value, + this.nullable, + ); + + factory SimpleClass.fromJson(Map json) => + _$SimpleClassFromJson(json); + + Map toJson() => _$SimpleClassToJson(this); +} diff --git a/json_serializable/test/supported_types/input.g.dart b/json_serializable/test/supported_types/input.g.dart new file mode 100644 index 000000000..c04f3338a --- /dev/null +++ b/json_serializable/test/supported_types/input.g.dart @@ -0,0 +1,21 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'input.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +SimpleClass _$SimpleClassFromJson(Map json) { + return SimpleClass( + json['value'] as int, + json['nullable'] as int, + )..withDefault = json['withDefault'] as int ?? 42; +} + +Map _$SimpleClassToJson(SimpleClass instance) => + { + 'value': instance.value, + 'nullable': instance.nullable, + 'withDefault': instance.withDefault, + }; diff --git a/json_serializable/test/supported_types/input.type_bigint.dart b/json_serializable/test/supported_types/input.type_bigint.dart new file mode 100644 index 000000000..af17f1a45 --- /dev/null +++ b/json_serializable/test/supported_types/input.type_bigint.dart @@ -0,0 +1,25 @@ +// Copyright (c) 2020, 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:json_annotation/json_annotation.dart'; + +part 'input.type_bigint.g.dart'; + +@JsonSerializable() +class SimpleClass { + final BigInt value; + + @JsonKey(nullable: false) + final BigInt nullable; + + SimpleClass( + this.value, + this.nullable, + ); + + factory SimpleClass.fromJson(Map json) => + _$SimpleClassFromJson(json); + + Map toJson() => _$SimpleClassToJson(this); +} diff --git a/json_serializable/test/supported_types/input.type_bigint.g.dart b/json_serializable/test/supported_types/input.type_bigint.g.dart new file mode 100644 index 000000000..f558a9326 --- /dev/null +++ b/json_serializable/test/supported_types/input.type_bigint.g.dart @@ -0,0 +1,20 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'input.type_bigint.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +SimpleClass _$SimpleClassFromJson(Map json) { + return SimpleClass( + json['value'] == null ? null : BigInt.parse(json['value'] as String), + BigInt.parse(json['nullable'] as String), + ); +} + +Map _$SimpleClassToJson(SimpleClass instance) => + { + 'value': instance.value?.toString(), + 'nullable': instance.nullable.toString(), + }; diff --git a/json_serializable/test/supported_types/input.type_bool.dart b/json_serializable/test/supported_types/input.type_bool.dart new file mode 100644 index 000000000..6d2b100be --- /dev/null +++ b/json_serializable/test/supported_types/input.type_bool.dart @@ -0,0 +1,28 @@ +// Copyright (c) 2020, 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:json_annotation/json_annotation.dart'; + +part 'input.type_bool.g.dart'; + +@JsonSerializable() +class SimpleClass { + final bool value; + + @JsonKey(nullable: false) + final bool nullable; + + @JsonKey(defaultValue: true) + bool withDefault; + + SimpleClass( + this.value, + this.nullable, + ); + + factory SimpleClass.fromJson(Map json) => + _$SimpleClassFromJson(json); + + Map toJson() => _$SimpleClassToJson(this); +} diff --git a/json_serializable/test/supported_types/input.type_bool.g.dart b/json_serializable/test/supported_types/input.type_bool.g.dart new file mode 100644 index 000000000..6b0bb40d7 --- /dev/null +++ b/json_serializable/test/supported_types/input.type_bool.g.dart @@ -0,0 +1,21 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'input.type_bool.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +SimpleClass _$SimpleClassFromJson(Map json) { + return SimpleClass( + json['value'] as bool, + json['nullable'] as bool, + )..withDefault = json['withDefault'] as bool ?? true; +} + +Map _$SimpleClassToJson(SimpleClass instance) => + { + 'value': instance.value, + 'nullable': instance.nullable, + 'withDefault': instance.withDefault, + }; diff --git a/json_serializable/test/supported_types/input.type_datetime.dart b/json_serializable/test/supported_types/input.type_datetime.dart new file mode 100644 index 000000000..aae8b83db --- /dev/null +++ b/json_serializable/test/supported_types/input.type_datetime.dart @@ -0,0 +1,25 @@ +// Copyright (c) 2020, 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:json_annotation/json_annotation.dart'; + +part 'input.type_datetime.g.dart'; + +@JsonSerializable() +class SimpleClass { + final DateTime value; + + @JsonKey(nullable: false) + final DateTime nullable; + + SimpleClass( + this.value, + this.nullable, + ); + + factory SimpleClass.fromJson(Map json) => + _$SimpleClassFromJson(json); + + Map toJson() => _$SimpleClassToJson(this); +} diff --git a/json_serializable/test/supported_types/input.type_datetime.g.dart b/json_serializable/test/supported_types/input.type_datetime.g.dart new file mode 100644 index 000000000..efb459777 --- /dev/null +++ b/json_serializable/test/supported_types/input.type_datetime.g.dart @@ -0,0 +1,20 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'input.type_datetime.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +SimpleClass _$SimpleClassFromJson(Map json) { + return SimpleClass( + json['value'] == null ? null : DateTime.parse(json['value'] as String), + DateTime.parse(json['nullable'] as String), + ); +} + +Map _$SimpleClassToJson(SimpleClass instance) => + { + 'value': instance.value?.toIso8601String(), + 'nullable': instance.nullable.toIso8601String(), + }; diff --git a/json_serializable/test/supported_types/input.type_double.dart b/json_serializable/test/supported_types/input.type_double.dart new file mode 100644 index 000000000..14a42481f --- /dev/null +++ b/json_serializable/test/supported_types/input.type_double.dart @@ -0,0 +1,28 @@ +// Copyright (c) 2020, 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:json_annotation/json_annotation.dart'; + +part 'input.type_double.g.dart'; + +@JsonSerializable() +class SimpleClass { + final double value; + + @JsonKey(nullable: false) + final double nullable; + + @JsonKey(defaultValue: 3.14) + double withDefault; + + SimpleClass( + this.value, + this.nullable, + ); + + factory SimpleClass.fromJson(Map json) => + _$SimpleClassFromJson(json); + + Map toJson() => _$SimpleClassToJson(this); +} diff --git a/json_serializable/test/supported_types/input.type_double.g.dart b/json_serializable/test/supported_types/input.type_double.g.dart new file mode 100644 index 000000000..36681b7d6 --- /dev/null +++ b/json_serializable/test/supported_types/input.type_double.g.dart @@ -0,0 +1,21 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'input.type_double.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +SimpleClass _$SimpleClassFromJson(Map json) { + return SimpleClass( + (json['value'] as num)?.toDouble(), + (json['nullable'] as num).toDouble(), + )..withDefault = (json['withDefault'] as num)?.toDouble() ?? 3.14; +} + +Map _$SimpleClassToJson(SimpleClass instance) => + { + 'value': instance.value, + 'nullable': instance.nullable, + 'withDefault': instance.withDefault, + }; diff --git a/json_serializable/test/supported_types/input.type_duration.dart b/json_serializable/test/supported_types/input.type_duration.dart new file mode 100644 index 000000000..a38f9cd68 --- /dev/null +++ b/json_serializable/test/supported_types/input.type_duration.dart @@ -0,0 +1,25 @@ +// Copyright (c) 2020, 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:json_annotation/json_annotation.dart'; + +part 'input.type_duration.g.dart'; + +@JsonSerializable() +class SimpleClass { + final Duration value; + + @JsonKey(nullable: false) + final Duration nullable; + + SimpleClass( + this.value, + this.nullable, + ); + + factory SimpleClass.fromJson(Map json) => + _$SimpleClassFromJson(json); + + Map toJson() => _$SimpleClassToJson(this); +} diff --git a/json_serializable/test/supported_types/input.type_duration.g.dart b/json_serializable/test/supported_types/input.type_duration.g.dart new file mode 100644 index 000000000..f7a0bc777 --- /dev/null +++ b/json_serializable/test/supported_types/input.type_duration.g.dart @@ -0,0 +1,20 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'input.type_duration.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +SimpleClass _$SimpleClassFromJson(Map json) { + return SimpleClass( + json['value'] == null ? null : Duration(microseconds: json['value'] as int), + Duration(microseconds: json['nullable'] as int), + ); +} + +Map _$SimpleClassToJson(SimpleClass instance) => + { + 'value': instance.value?.inMicroseconds, + 'nullable': instance.nullable.inMicroseconds, + }; diff --git a/json_serializable/test/supported_types/input.type_dynamic.dart b/json_serializable/test/supported_types/input.type_dynamic.dart new file mode 100644 index 000000000..e02cacaa4 --- /dev/null +++ b/json_serializable/test/supported_types/input.type_dynamic.dart @@ -0,0 +1,25 @@ +// Copyright (c) 2020, 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:json_annotation/json_annotation.dart'; + +part 'input.type_dynamic.g.dart'; + +@JsonSerializable() +class SimpleClass { + final dynamic value; + + @JsonKey(nullable: false) + final dynamic nullable; + + SimpleClass( + this.value, + this.nullable, + ); + + factory SimpleClass.fromJson(Map json) => + _$SimpleClassFromJson(json); + + Map toJson() => _$SimpleClassToJson(this); +} diff --git a/json_serializable/test/supported_types/input.type_dynamic.g.dart b/json_serializable/test/supported_types/input.type_dynamic.g.dart new file mode 100644 index 000000000..e17aa9b11 --- /dev/null +++ b/json_serializable/test/supported_types/input.type_dynamic.g.dart @@ -0,0 +1,20 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'input.type_dynamic.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +SimpleClass _$SimpleClassFromJson(Map json) { + return SimpleClass( + json['value'], + json['nullable'], + ); +} + +Map _$SimpleClassToJson(SimpleClass instance) => + { + 'value': instance.value, + 'nullable': instance.nullable, + }; diff --git a/json_serializable/test/supported_types/input.type_iterable.dart b/json_serializable/test/supported_types/input.type_iterable.dart new file mode 100644 index 000000000..ef46df066 --- /dev/null +++ b/json_serializable/test/supported_types/input.type_iterable.dart @@ -0,0 +1,28 @@ +// Copyright (c) 2020, 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:json_annotation/json_annotation.dart'; + +part 'input.type_iterable.g.dart'; + +@JsonSerializable() +class SimpleClass { + final Iterable value; + + @JsonKey(nullable: false) + final Iterable nullable; + + @JsonKey(defaultValue: [42, true, false, null]) + Iterable withDefault; + + SimpleClass( + this.value, + this.nullable, + ); + + factory SimpleClass.fromJson(Map json) => + _$SimpleClassFromJson(json); + + Map toJson() => _$SimpleClassToJson(this); +} diff --git a/json_serializable/test/supported_types/input.type_iterable.g.dart b/json_serializable/test/supported_types/input.type_iterable.g.dart new file mode 100644 index 000000000..5d1b1d9c7 --- /dev/null +++ b/json_serializable/test/supported_types/input.type_iterable.g.dart @@ -0,0 +1,21 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'input.type_iterable.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +SimpleClass _$SimpleClassFromJson(Map json) { + return SimpleClass( + json['value'] as List, + json['nullable'] as List, + )..withDefault = json['withDefault'] as List ?? [42, true, false, null]; +} + +Map _$SimpleClassToJson(SimpleClass instance) => + { + 'value': instance.value?.toList(), + 'nullable': instance.nullable.toList(), + 'withDefault': instance.withDefault?.toList(), + }; diff --git a/json_serializable/test/supported_types/input.type_list.dart b/json_serializable/test/supported_types/input.type_list.dart new file mode 100644 index 000000000..b6a41d783 --- /dev/null +++ b/json_serializable/test/supported_types/input.type_list.dart @@ -0,0 +1,28 @@ +// Copyright (c) 2020, 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:json_annotation/json_annotation.dart'; + +part 'input.type_list.g.dart'; + +@JsonSerializable() +class SimpleClass { + final List value; + + @JsonKey(nullable: false) + final List nullable; + + @JsonKey(defaultValue: [42, true, false, null]) + List withDefault; + + SimpleClass( + this.value, + this.nullable, + ); + + factory SimpleClass.fromJson(Map json) => + _$SimpleClassFromJson(json); + + Map toJson() => _$SimpleClassToJson(this); +} diff --git a/json_serializable/test/supported_types/input.type_list.g.dart b/json_serializable/test/supported_types/input.type_list.g.dart new file mode 100644 index 000000000..b918179d2 --- /dev/null +++ b/json_serializable/test/supported_types/input.type_list.g.dart @@ -0,0 +1,21 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'input.type_list.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +SimpleClass _$SimpleClassFromJson(Map json) { + return SimpleClass( + json['value'] as List, + json['nullable'] as List, + )..withDefault = json['withDefault'] as List ?? [42, true, false, null]; +} + +Map _$SimpleClassToJson(SimpleClass instance) => + { + 'value': instance.value, + 'nullable': instance.nullable, + 'withDefault': instance.withDefault, + }; diff --git a/json_serializable/test/supported_types/input.type_map.dart b/json_serializable/test/supported_types/input.type_map.dart new file mode 100644 index 000000000..be8bab47f --- /dev/null +++ b/json_serializable/test/supported_types/input.type_map.dart @@ -0,0 +1,28 @@ +// Copyright (c) 2020, 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:json_annotation/json_annotation.dart'; + +part 'input.type_map.g.dart'; + +@JsonSerializable() +class SimpleClass { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + @JsonKey(defaultValue: {'a': 1}) + Map withDefault; + + SimpleClass( + this.value, + this.nullable, + ); + + factory SimpleClass.fromJson(Map json) => + _$SimpleClassFromJson(json); + + Map toJson() => _$SimpleClassToJson(this); +} diff --git a/json_serializable/test/supported_types/input.type_map.g.dart b/json_serializable/test/supported_types/input.type_map.g.dart new file mode 100644 index 000000000..beb8e44b8 --- /dev/null +++ b/json_serializable/test/supported_types/input.type_map.g.dart @@ -0,0 +1,21 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'input.type_map.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +SimpleClass _$SimpleClassFromJson(Map json) { + return SimpleClass( + json['value'] as Map, + json['nullable'] as Map, + )..withDefault = json['withDefault'] as Map ?? {'a': 1}; +} + +Map _$SimpleClassToJson(SimpleClass instance) => + { + 'value': instance.value, + 'nullable': instance.nullable, + 'withDefault': instance.withDefault, + }; diff --git a/json_serializable/test/supported_types/input.type_myenum.dart b/json_serializable/test/supported_types/input.type_myenum.dart new file mode 100644 index 000000000..9b1c04884 --- /dev/null +++ b/json_serializable/test/supported_types/input.type_myenum.dart @@ -0,0 +1,30 @@ +// Copyright (c) 2020, 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:json_annotation/json_annotation.dart'; + +part 'input.type_myenum.g.dart'; + +enum MyEnum { alpha, beta, gamma, delta } + +@JsonSerializable() +class SimpleClass { + final MyEnum value; + + @JsonKey(nullable: false) + final MyEnum nullable; + + @JsonKey(defaultValue: MyEnum.alpha) + MyEnum withDefault; + + SimpleClass( + this.value, + this.nullable, + ); + + factory SimpleClass.fromJson(Map json) => + _$SimpleClassFromJson(json); + + Map toJson() => _$SimpleClassToJson(this); +} diff --git a/json_serializable/test/supported_types/input.type_myenum.g.dart b/json_serializable/test/supported_types/input.type_myenum.g.dart new file mode 100644 index 000000000..24bc31f1b --- /dev/null +++ b/json_serializable/test/supported_types/input.type_myenum.g.dart @@ -0,0 +1,61 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'input.type_myenum.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +SimpleClass _$SimpleClassFromJson(Map json) { + return SimpleClass( + _$enumDecodeNullable(_$MyEnumEnumMap, json['value']), + _$enumDecode(_$MyEnumEnumMap, json['nullable']), + )..withDefault = _$enumDecodeNullable(_$MyEnumEnumMap, json['withDefault']) ?? + MyEnum.alpha; +} + +Map _$SimpleClassToJson(SimpleClass instance) => + { + 'value': _$MyEnumEnumMap[instance.value], + 'nullable': _$MyEnumEnumMap[instance.nullable], + 'withDefault': _$MyEnumEnumMap[instance.withDefault], + }; + +T _$enumDecode( + Map enumValues, + dynamic source, { + T unknownValue, +}) { + if (source == null) { + throw ArgumentError('A value must be provided. Supported values: ' + '${enumValues.values.join(', ')}'); + } + + final value = enumValues.entries + .singleWhere((e) => e.value == source, orElse: () => null) + ?.key; + + if (value == null && unknownValue == null) { + throw ArgumentError('`$source` is not one of the supported values: ' + '${enumValues.values.join(', ')}'); + } + return value ?? unknownValue; +} + +T _$enumDecodeNullable( + Map enumValues, + dynamic source, { + T unknownValue, +}) { + if (source == null) { + return null; + } + return _$enumDecode(enumValues, source, unknownValue: unknownValue); +} + +const _$MyEnumEnumMap = { + MyEnum.alpha: 'alpha', + MyEnum.beta: 'beta', + MyEnum.gamma: 'gamma', + MyEnum.delta: 'delta', +}; diff --git a/json_serializable/test/supported_types/input.type_num.dart b/json_serializable/test/supported_types/input.type_num.dart new file mode 100644 index 000000000..587656485 --- /dev/null +++ b/json_serializable/test/supported_types/input.type_num.dart @@ -0,0 +1,28 @@ +// Copyright (c) 2020, 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:json_annotation/json_annotation.dart'; + +part 'input.type_num.g.dart'; + +@JsonSerializable() +class SimpleClass { + final num value; + + @JsonKey(nullable: false) + final num nullable; + + @JsonKey(defaultValue: 88.6) + num withDefault; + + SimpleClass( + this.value, + this.nullable, + ); + + factory SimpleClass.fromJson(Map json) => + _$SimpleClassFromJson(json); + + Map toJson() => _$SimpleClassToJson(this); +} diff --git a/json_serializable/test/supported_types/input.type_num.g.dart b/json_serializable/test/supported_types/input.type_num.g.dart new file mode 100644 index 000000000..ddca5a84a --- /dev/null +++ b/json_serializable/test/supported_types/input.type_num.g.dart @@ -0,0 +1,21 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'input.type_num.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +SimpleClass _$SimpleClassFromJson(Map json) { + return SimpleClass( + json['value'] as num, + json['nullable'] as num, + )..withDefault = json['withDefault'] as num ?? 88.6; +} + +Map _$SimpleClassToJson(SimpleClass instance) => + { + 'value': instance.value, + 'nullable': instance.nullable, + 'withDefault': instance.withDefault, + }; diff --git a/json_serializable/test/supported_types/input.type_object.dart b/json_serializable/test/supported_types/input.type_object.dart new file mode 100644 index 000000000..06bba9e4b --- /dev/null +++ b/json_serializable/test/supported_types/input.type_object.dart @@ -0,0 +1,25 @@ +// Copyright (c) 2020, 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:json_annotation/json_annotation.dart'; + +part 'input.type_object.g.dart'; + +@JsonSerializable() +class SimpleClass { + final Object value; + + @JsonKey(nullable: false) + final Object nullable; + + SimpleClass( + this.value, + this.nullable, + ); + + factory SimpleClass.fromJson(Map json) => + _$SimpleClassFromJson(json); + + Map toJson() => _$SimpleClassToJson(this); +} diff --git a/json_serializable/test/supported_types/input.type_object.g.dart b/json_serializable/test/supported_types/input.type_object.g.dart new file mode 100644 index 000000000..e2dafc620 --- /dev/null +++ b/json_serializable/test/supported_types/input.type_object.g.dart @@ -0,0 +1,20 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'input.type_object.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +SimpleClass _$SimpleClassFromJson(Map json) { + return SimpleClass( + json['value'], + json['nullable'], + ); +} + +Map _$SimpleClassToJson(SimpleClass instance) => + { + 'value': instance.value, + 'nullable': instance.nullable, + }; diff --git a/json_serializable/test/supported_types/input.type_set.dart b/json_serializable/test/supported_types/input.type_set.dart new file mode 100644 index 000000000..94a1715c3 --- /dev/null +++ b/json_serializable/test/supported_types/input.type_set.dart @@ -0,0 +1,28 @@ +// Copyright (c) 2020, 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:json_annotation/json_annotation.dart'; + +part 'input.type_set.g.dart'; + +@JsonSerializable() +class SimpleClass { + final Set value; + + @JsonKey(nullable: false) + final Set nullable; + + @JsonKey(defaultValue: {42, true, false, null}) + Set withDefault; + + SimpleClass( + this.value, + this.nullable, + ); + + factory SimpleClass.fromJson(Map json) => + _$SimpleClassFromJson(json); + + Map toJson() => _$SimpleClassToJson(this); +} diff --git a/json_serializable/test/supported_types/input.type_set.g.dart b/json_serializable/test/supported_types/input.type_set.g.dart new file mode 100644 index 000000000..dfe0abf20 --- /dev/null +++ b/json_serializable/test/supported_types/input.type_set.g.dart @@ -0,0 +1,22 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'input.type_set.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +SimpleClass _$SimpleClassFromJson(Map json) { + return SimpleClass( + (json['value'] as List)?.toSet(), + (json['nullable'] as List).toSet(), + )..withDefault = + (json['withDefault'] as List)?.toSet() ?? {42, true, false, null}; +} + +Map _$SimpleClassToJson(SimpleClass instance) => + { + 'value': instance.value?.toList(), + 'nullable': instance.nullable.toList(), + 'withDefault': instance.withDefault?.toList(), + }; diff --git a/json_serializable/test/supported_types/input.type_string.dart b/json_serializable/test/supported_types/input.type_string.dart new file mode 100644 index 000000000..8dc10f032 --- /dev/null +++ b/json_serializable/test/supported_types/input.type_string.dart @@ -0,0 +1,28 @@ +// Copyright (c) 2020, 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:json_annotation/json_annotation.dart'; + +part 'input.type_string.g.dart'; + +@JsonSerializable() +class SimpleClass { + final String value; + + @JsonKey(nullable: false) + final String nullable; + + @JsonKey(defaultValue: 'a string') + String withDefault; + + SimpleClass( + this.value, + this.nullable, + ); + + factory SimpleClass.fromJson(Map json) => + _$SimpleClassFromJson(json); + + Map toJson() => _$SimpleClassToJson(this); +} diff --git a/json_serializable/test/supported_types/input.type_string.g.dart b/json_serializable/test/supported_types/input.type_string.g.dart new file mode 100644 index 000000000..d3ab769db --- /dev/null +++ b/json_serializable/test/supported_types/input.type_string.g.dart @@ -0,0 +1,21 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'input.type_string.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +SimpleClass _$SimpleClassFromJson(Map json) { + return SimpleClass( + json['value'] as String, + json['nullable'] as String, + )..withDefault = json['withDefault'] as String ?? 'a string'; +} + +Map _$SimpleClassToJson(SimpleClass instance) => + { + 'value': instance.value, + 'nullable': instance.nullable, + 'withDefault': instance.withDefault, + }; diff --git a/json_serializable/test/supported_types/input.type_uri.dart b/json_serializable/test/supported_types/input.type_uri.dart new file mode 100644 index 000000000..ce41b79ca --- /dev/null +++ b/json_serializable/test/supported_types/input.type_uri.dart @@ -0,0 +1,25 @@ +// Copyright (c) 2020, 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:json_annotation/json_annotation.dart'; + +part 'input.type_uri.g.dart'; + +@JsonSerializable() +class SimpleClass { + final Uri value; + + @JsonKey(nullable: false) + final Uri nullable; + + SimpleClass( + this.value, + this.nullable, + ); + + factory SimpleClass.fromJson(Map json) => + _$SimpleClassFromJson(json); + + Map toJson() => _$SimpleClassToJson(this); +} diff --git a/json_serializable/test/supported_types/input.type_uri.g.dart b/json_serializable/test/supported_types/input.type_uri.g.dart new file mode 100644 index 000000000..665a3b5a3 --- /dev/null +++ b/json_serializable/test/supported_types/input.type_uri.g.dart @@ -0,0 +1,20 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'input.type_uri.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +SimpleClass _$SimpleClassFromJson(Map json) { + return SimpleClass( + json['value'] == null ? null : Uri.parse(json['value'] as String), + Uri.parse(json['nullable'] as String), + ); +} + +Map _$SimpleClassToJson(SimpleClass instance) => + { + 'value': instance.value?.toString(), + 'nullable': instance.nullable.toString(), + }; diff --git a/json_serializable/test/supported_types/type_test.bigint_test.dart b/json_serializable/test/supported_types/type_test.bigint_test.dart new file mode 100644 index 000000000..d185cabd3 --- /dev/null +++ b/json_serializable/test/supported_types/type_test.bigint_test.dart @@ -0,0 +1,41 @@ +// Copyright (c) 2020, 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. + +// ignore_for_file: prefer_const_declarations + +@TestOn('vm') +import 'package:test/test.dart'; + +import '../test_utils.dart'; +import 'input.type_bigint.dart'; + +void main() { + test('round trip', () { + final object = SimpleClass.fromJson(_emptyInput); + expect(loudEncode(object), loudEncode(_defaultOutput)); + }); + + test('round trip alternate values', () { + final object = SimpleClass.fromJson(_nonDefaultJson); + expect(loudEncode(object), loudEncode(_nonDefaultJson)); + expect(loudEncode(object), isNot(loudEncode(_defaultOutput))); + }); +} + +final _defaultValue = '12345'; +final _altValue = '67890'; + +final _emptyInput = { + 'nullable': _defaultValue, +}; + +final _defaultOutput = { + 'value': null, + 'nullable': _defaultValue, +}; + +final _nonDefaultJson = { + 'value': null, + 'nullable': _altValue, +}; diff --git a/json_serializable/test/supported_types/type_test.bool_test.dart b/json_serializable/test/supported_types/type_test.bool_test.dart new file mode 100644 index 000000000..52f6764ce --- /dev/null +++ b/json_serializable/test/supported_types/type_test.bool_test.dart @@ -0,0 +1,43 @@ +// Copyright (c) 2020, 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. + +// ignore_for_file: prefer_const_declarations + +@TestOn('vm') +import 'package:test/test.dart'; + +import '../test_utils.dart'; +import 'input.type_bool.dart'; + +void main() { + test('round trip', () { + final object = SimpleClass.fromJson(_emptyInput); + expect(loudEncode(object), loudEncode(_defaultOutput)); + }); + + test('round trip alternate values', () { + final object = SimpleClass.fromJson(_nonDefaultJson); + expect(loudEncode(object), loudEncode(_nonDefaultJson)); + expect(loudEncode(object), isNot(loudEncode(_defaultOutput))); + }); +} + +final _defaultValue = true; +final _altValue = false; + +final _emptyInput = { + 'nullable': _defaultValue, +}; + +final _defaultOutput = { + 'value': null, + 'nullable': _defaultValue, + 'withDefault': _defaultValue, +}; + +final _nonDefaultJson = { + 'value': null, + 'nullable': _altValue, + 'withDefault': _altValue, +}; diff --git a/json_serializable/test/supported_types/type_test.dart b/json_serializable/test/supported_types/type_test.dart new file mode 100644 index 000000000..ce7436949 --- /dev/null +++ b/json_serializable/test/supported_types/type_test.dart @@ -0,0 +1,43 @@ +// Copyright (c) 2020, 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. + +// ignore_for_file: prefer_const_declarations + +@TestOn('vm') +import 'package:test/test.dart'; + +import '../test_utils.dart'; +import 'input.dart'; + +void main() { + test('round trip', () { + final object = SimpleClass.fromJson(_emptyInput); + expect(loudEncode(object), loudEncode(_defaultOutput)); + }); + + test('round trip alternate values', () { + final object = SimpleClass.fromJson(_nonDefaultJson); + expect(loudEncode(object), loudEncode(_nonDefaultJson)); + expect(loudEncode(object), isNot(loudEncode(_defaultOutput))); + }); +} + +final _defaultValue = 42; +final _altValue = 43; + +final _emptyInput = { + 'nullable': _defaultValue, +}; + +final _defaultOutput = { + 'value': null, + 'nullable': _defaultValue, + 'withDefault': _defaultValue, +}; + +final _nonDefaultJson = { + 'value': null, + 'nullable': _altValue, + 'withDefault': _altValue, +}; diff --git a/json_serializable/test/supported_types/type_test.datetime_test.dart b/json_serializable/test/supported_types/type_test.datetime_test.dart new file mode 100644 index 000000000..ec9f36619 --- /dev/null +++ b/json_serializable/test/supported_types/type_test.datetime_test.dart @@ -0,0 +1,41 @@ +// Copyright (c) 2020, 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. + +// ignore_for_file: prefer_const_declarations + +@TestOn('vm') +import 'package:test/test.dart'; + +import '../test_utils.dart'; +import 'input.type_datetime.dart'; + +void main() { + test('round trip', () { + final object = SimpleClass.fromJson(_emptyInput); + expect(loudEncode(object), loudEncode(_defaultOutput)); + }); + + test('round trip alternate values', () { + final object = SimpleClass.fromJson(_nonDefaultJson); + expect(loudEncode(object), loudEncode(_nonDefaultJson)); + expect(loudEncode(object), isNot(loudEncode(_defaultOutput))); + }); +} + +final _defaultValue = '2020-01-01T00:00:00.000'; +final _altValue = '2018-01-01T00:00:00.000'; + +final _emptyInput = { + 'nullable': _defaultValue, +}; + +final _defaultOutput = { + 'value': null, + 'nullable': _defaultValue, +}; + +final _nonDefaultJson = { + 'value': null, + 'nullable': _altValue, +}; diff --git a/json_serializable/test/supported_types/type_test.double_test.dart b/json_serializable/test/supported_types/type_test.double_test.dart new file mode 100644 index 000000000..466abab43 --- /dev/null +++ b/json_serializable/test/supported_types/type_test.double_test.dart @@ -0,0 +1,43 @@ +// Copyright (c) 2020, 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. + +// ignore_for_file: prefer_const_declarations + +@TestOn('vm') +import 'package:test/test.dart'; + +import '../test_utils.dart'; +import 'input.type_double.dart'; + +void main() { + test('round trip', () { + final object = SimpleClass.fromJson(_emptyInput); + expect(loudEncode(object), loudEncode(_defaultOutput)); + }); + + test('round trip alternate values', () { + final object = SimpleClass.fromJson(_nonDefaultJson); + expect(loudEncode(object), loudEncode(_nonDefaultJson)); + expect(loudEncode(object), isNot(loudEncode(_defaultOutput))); + }); +} + +final _defaultValue = 3.14; +final _altValue = 6.28; + +final _emptyInput = { + 'nullable': _defaultValue, +}; + +final _defaultOutput = { + 'value': null, + 'nullable': _defaultValue, + 'withDefault': _defaultValue, +}; + +final _nonDefaultJson = { + 'value': null, + 'nullable': _altValue, + 'withDefault': _altValue, +}; diff --git a/json_serializable/test/supported_types/type_test.duration_test.dart b/json_serializable/test/supported_types/type_test.duration_test.dart new file mode 100644 index 000000000..463298ea0 --- /dev/null +++ b/json_serializable/test/supported_types/type_test.duration_test.dart @@ -0,0 +1,41 @@ +// Copyright (c) 2020, 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. + +// ignore_for_file: prefer_const_declarations + +@TestOn('vm') +import 'package:test/test.dart'; + +import '../test_utils.dart'; +import 'input.type_duration.dart'; + +void main() { + test('round trip', () { + final object = SimpleClass.fromJson(_emptyInput); + expect(loudEncode(object), loudEncode(_defaultOutput)); + }); + + test('round trip alternate values', () { + final object = SimpleClass.fromJson(_nonDefaultJson); + expect(loudEncode(object), loudEncode(_nonDefaultJson)); + expect(loudEncode(object), isNot(loudEncode(_defaultOutput))); + }); +} + +final _defaultValue = 1234; +final _altValue = 2345; + +final _emptyInput = { + 'nullable': _defaultValue, +}; + +final _defaultOutput = { + 'value': null, + 'nullable': _defaultValue, +}; + +final _nonDefaultJson = { + 'value': null, + 'nullable': _altValue, +}; diff --git a/json_serializable/test/supported_types/type_test.dynamic_test.dart b/json_serializable/test/supported_types/type_test.dynamic_test.dart new file mode 100644 index 000000000..0487a2eb5 --- /dev/null +++ b/json_serializable/test/supported_types/type_test.dynamic_test.dart @@ -0,0 +1,41 @@ +// Copyright (c) 2020, 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. + +// ignore_for_file: prefer_const_declarations + +@TestOn('vm') +import 'package:test/test.dart'; + +import '../test_utils.dart'; +import 'input.type_dynamic.dart'; + +void main() { + test('round trip', () { + final object = SimpleClass.fromJson(_emptyInput); + expect(loudEncode(object), loudEncode(_defaultOutput)); + }); + + test('round trip alternate values', () { + final object = SimpleClass.fromJson(_nonDefaultJson); + expect(loudEncode(object), loudEncode(_nonDefaultJson)); + expect(loudEncode(object), isNot(loudEncode(_defaultOutput))); + }); +} + +final _defaultValue = null; +final _altValue = 'dynamic'; + +final _emptyInput = { + 'nullable': _defaultValue, +}; + +final _defaultOutput = { + 'value': null, + 'nullable': _defaultValue, +}; + +final _nonDefaultJson = { + 'value': null, + 'nullable': _altValue, +}; diff --git a/json_serializable/test/supported_types/type_test.iterable_test.dart b/json_serializable/test/supported_types/type_test.iterable_test.dart new file mode 100644 index 000000000..301725643 --- /dev/null +++ b/json_serializable/test/supported_types/type_test.iterable_test.dart @@ -0,0 +1,43 @@ +// Copyright (c) 2020, 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. + +// ignore_for_file: prefer_const_declarations + +@TestOn('vm') +import 'package:test/test.dart'; + +import '../test_utils.dart'; +import 'input.type_iterable.dart'; + +void main() { + test('round trip', () { + final object = SimpleClass.fromJson(_emptyInput); + expect(loudEncode(object), loudEncode(_defaultOutput)); + }); + + test('round trip alternate values', () { + final object = SimpleClass.fromJson(_nonDefaultJson); + expect(loudEncode(object), loudEncode(_nonDefaultJson)); + expect(loudEncode(object), isNot(loudEncode(_defaultOutput))); + }); +} + +final _defaultValue = [42, true, false, null]; +final _altValue = [43, false]; + +final _emptyInput = { + 'nullable': _defaultValue, +}; + +final _defaultOutput = { + 'value': null, + 'nullable': _defaultValue, + 'withDefault': _defaultValue, +}; + +final _nonDefaultJson = { + 'value': null, + 'nullable': _altValue, + 'withDefault': _altValue, +}; diff --git a/json_serializable/test/supported_types/type_test.list_test.dart b/json_serializable/test/supported_types/type_test.list_test.dart new file mode 100644 index 000000000..96ccc6751 --- /dev/null +++ b/json_serializable/test/supported_types/type_test.list_test.dart @@ -0,0 +1,43 @@ +// Copyright (c) 2020, 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. + +// ignore_for_file: prefer_const_declarations + +@TestOn('vm') +import 'package:test/test.dart'; + +import '../test_utils.dart'; +import 'input.type_list.dart'; + +void main() { + test('round trip', () { + final object = SimpleClass.fromJson(_emptyInput); + expect(loudEncode(object), loudEncode(_defaultOutput)); + }); + + test('round trip alternate values', () { + final object = SimpleClass.fromJson(_nonDefaultJson); + expect(loudEncode(object), loudEncode(_nonDefaultJson)); + expect(loudEncode(object), isNot(loudEncode(_defaultOutput))); + }); +} + +final _defaultValue = [42, true, false, null]; +final _altValue = [43, false]; + +final _emptyInput = { + 'nullable': _defaultValue, +}; + +final _defaultOutput = { + 'value': null, + 'nullable': _defaultValue, + 'withDefault': _defaultValue, +}; + +final _nonDefaultJson = { + 'value': null, + 'nullable': _altValue, + 'withDefault': _altValue, +}; diff --git a/json_serializable/test/supported_types/type_test.map_test.dart b/json_serializable/test/supported_types/type_test.map_test.dart new file mode 100644 index 000000000..62b062586 --- /dev/null +++ b/json_serializable/test/supported_types/type_test.map_test.dart @@ -0,0 +1,43 @@ +// Copyright (c) 2020, 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. + +// ignore_for_file: prefer_const_declarations + +@TestOn('vm') +import 'package:test/test.dart'; + +import '../test_utils.dart'; +import 'input.type_map.dart'; + +void main() { + test('round trip', () { + final object = SimpleClass.fromJson(_emptyInput); + expect(loudEncode(object), loudEncode(_defaultOutput)); + }); + + test('round trip alternate values', () { + final object = SimpleClass.fromJson(_nonDefaultJson); + expect(loudEncode(object), loudEncode(_nonDefaultJson)); + expect(loudEncode(object), isNot(loudEncode(_defaultOutput))); + }); +} + +final _defaultValue = {'a': 1}; +final _altValue = {'b': 2}; + +final _emptyInput = { + 'nullable': _defaultValue, +}; + +final _defaultOutput = { + 'value': null, + 'nullable': _defaultValue, + 'withDefault': _defaultValue, +}; + +final _nonDefaultJson = { + 'value': null, + 'nullable': _altValue, + 'withDefault': _altValue, +}; diff --git a/json_serializable/test/supported_types/type_test.myenum_test.dart b/json_serializable/test/supported_types/type_test.myenum_test.dart new file mode 100644 index 000000000..016d395b5 --- /dev/null +++ b/json_serializable/test/supported_types/type_test.myenum_test.dart @@ -0,0 +1,43 @@ +// Copyright (c) 2020, 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. + +// ignore_for_file: prefer_const_declarations + +@TestOn('vm') +import 'package:test/test.dart'; + +import '../test_utils.dart'; +import 'input.type_myenum.dart'; + +void main() { + test('round trip', () { + final object = SimpleClass.fromJson(_emptyInput); + expect(loudEncode(object), loudEncode(_defaultOutput)); + }); + + test('round trip alternate values', () { + final object = SimpleClass.fromJson(_nonDefaultJson); + expect(loudEncode(object), loudEncode(_nonDefaultJson)); + expect(loudEncode(object), isNot(loudEncode(_defaultOutput))); + }); +} + +final _defaultValue = 'alpha'; +final _altValue = 'beta'; + +final _emptyInput = { + 'nullable': _defaultValue, +}; + +final _defaultOutput = { + 'value': null, + 'nullable': _defaultValue, + 'withDefault': _defaultValue, +}; + +final _nonDefaultJson = { + 'value': null, + 'nullable': _altValue, + 'withDefault': _altValue, +}; diff --git a/json_serializable/test/supported_types/type_test.num_test.dart b/json_serializable/test/supported_types/type_test.num_test.dart new file mode 100644 index 000000000..0ab60c852 --- /dev/null +++ b/json_serializable/test/supported_types/type_test.num_test.dart @@ -0,0 +1,43 @@ +// Copyright (c) 2020, 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. + +// ignore_for_file: prefer_const_declarations + +@TestOn('vm') +import 'package:test/test.dart'; + +import '../test_utils.dart'; +import 'input.type_num.dart'; + +void main() { + test('round trip', () { + final object = SimpleClass.fromJson(_emptyInput); + expect(loudEncode(object), loudEncode(_defaultOutput)); + }); + + test('round trip alternate values', () { + final object = SimpleClass.fromJson(_nonDefaultJson); + expect(loudEncode(object), loudEncode(_nonDefaultJson)); + expect(loudEncode(object), isNot(loudEncode(_defaultOutput))); + }); +} + +final _defaultValue = 88.6; +final _altValue = 29; + +final _emptyInput = { + 'nullable': _defaultValue, +}; + +final _defaultOutput = { + 'value': null, + 'nullable': _defaultValue, + 'withDefault': _defaultValue, +}; + +final _nonDefaultJson = { + 'value': null, + 'nullable': _altValue, + 'withDefault': _altValue, +}; diff --git a/json_serializable/test/supported_types/type_test.object_test.dart b/json_serializable/test/supported_types/type_test.object_test.dart new file mode 100644 index 000000000..30b9c8642 --- /dev/null +++ b/json_serializable/test/supported_types/type_test.object_test.dart @@ -0,0 +1,41 @@ +// Copyright (c) 2020, 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. + +// ignore_for_file: prefer_const_declarations + +@TestOn('vm') +import 'package:test/test.dart'; + +import '../test_utils.dart'; +import 'input.type_object.dart'; + +void main() { + test('round trip', () { + final object = SimpleClass.fromJson(_emptyInput); + expect(loudEncode(object), loudEncode(_defaultOutput)); + }); + + test('round trip alternate values', () { + final object = SimpleClass.fromJson(_nonDefaultJson); + expect(loudEncode(object), loudEncode(_nonDefaultJson)); + expect(loudEncode(object), isNot(loudEncode(_defaultOutput))); + }); +} + +final _defaultValue = null; +final _altValue = 'Object'; + +final _emptyInput = { + 'nullable': _defaultValue, +}; + +final _defaultOutput = { + 'value': null, + 'nullable': _defaultValue, +}; + +final _nonDefaultJson = { + 'value': null, + 'nullable': _altValue, +}; diff --git a/json_serializable/test/supported_types/type_test.set_test.dart b/json_serializable/test/supported_types/type_test.set_test.dart new file mode 100644 index 000000000..10db9945f --- /dev/null +++ b/json_serializable/test/supported_types/type_test.set_test.dart @@ -0,0 +1,43 @@ +// Copyright (c) 2020, 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. + +// ignore_for_file: prefer_const_declarations + +@TestOn('vm') +import 'package:test/test.dart'; + +import '../test_utils.dart'; +import 'input.type_set.dart'; + +void main() { + test('round trip', () { + final object = SimpleClass.fromJson(_emptyInput); + expect(loudEncode(object), loudEncode(_defaultOutput)); + }); + + test('round trip alternate values', () { + final object = SimpleClass.fromJson(_nonDefaultJson); + expect(loudEncode(object), loudEncode(_nonDefaultJson)); + expect(loudEncode(object), isNot(loudEncode(_defaultOutput))); + }); +} + +final _defaultValue = [42, true, false, null]; +final _altValue = [43, false]; + +final _emptyInput = { + 'nullable': _defaultValue, +}; + +final _defaultOutput = { + 'value': null, + 'nullable': _defaultValue, + 'withDefault': _defaultValue, +}; + +final _nonDefaultJson = { + 'value': null, + 'nullable': _altValue, + 'withDefault': _altValue, +}; diff --git a/json_serializable/test/supported_types/type_test.string_test.dart b/json_serializable/test/supported_types/type_test.string_test.dart new file mode 100644 index 000000000..04556ee90 --- /dev/null +++ b/json_serializable/test/supported_types/type_test.string_test.dart @@ -0,0 +1,43 @@ +// Copyright (c) 2020, 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. + +// ignore_for_file: prefer_const_declarations + +@TestOn('vm') +import 'package:test/test.dart'; + +import '../test_utils.dart'; +import 'input.type_string.dart'; + +void main() { + test('round trip', () { + final object = SimpleClass.fromJson(_emptyInput); + expect(loudEncode(object), loudEncode(_defaultOutput)); + }); + + test('round trip alternate values', () { + final object = SimpleClass.fromJson(_nonDefaultJson); + expect(loudEncode(object), loudEncode(_nonDefaultJson)); + expect(loudEncode(object), isNot(loudEncode(_defaultOutput))); + }); +} + +final _defaultValue = 'a string'; +final _altValue = 'another string'; + +final _emptyInput = { + 'nullable': _defaultValue, +}; + +final _defaultOutput = { + 'value': null, + 'nullable': _defaultValue, + 'withDefault': _defaultValue, +}; + +final _nonDefaultJson = { + 'value': null, + 'nullable': _altValue, + 'withDefault': _altValue, +}; diff --git a/json_serializable/test/supported_types/type_test.uri_test.dart b/json_serializable/test/supported_types/type_test.uri_test.dart new file mode 100644 index 000000000..6784d840a --- /dev/null +++ b/json_serializable/test/supported_types/type_test.uri_test.dart @@ -0,0 +1,41 @@ +// Copyright (c) 2020, 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. + +// ignore_for_file: prefer_const_declarations + +@TestOn('vm') +import 'package:test/test.dart'; + +import '../test_utils.dart'; +import 'input.type_uri.dart'; + +void main() { + test('round trip', () { + final object = SimpleClass.fromJson(_emptyInput); + expect(loudEncode(object), loudEncode(_defaultOutput)); + }); + + test('round trip alternate values', () { + final object = SimpleClass.fromJson(_nonDefaultJson); + expect(loudEncode(object), loudEncode(_nonDefaultJson)); + expect(loudEncode(object), isNot(loudEncode(_defaultOutput))); + }); +} + +final _defaultValue = 'https://example.com'; +final _altValue = 'https://dart.dev'; + +final _emptyInput = { + 'nullable': _defaultValue, +}; + +final _defaultOutput = { + 'value': null, + 'nullable': _defaultValue, +}; + +final _nonDefaultJson = { + 'value': null, + 'nullable': _altValue, +}; diff --git a/json_serializable/tool/shared.dart b/json_serializable/tool/shared.dart new file mode 100644 index 000000000..58b3a9216 --- /dev/null +++ b/json_serializable/tool/shared.dart @@ -0,0 +1,71 @@ +// Copyright (c) 2020, 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 'dart:io'; + +import 'package:build/build.dart'; +import 'package:yaml/yaml.dart'; + +// Until we have verification in pkg:build and friends +// https://github.com/dart-lang/build/issues/590 +Builder validate(String builderName, Builder builder) { + var buildYaml = loadYaml( + File('build.yaml').readAsStringSync(), + sourceUrl: 'build.yaml', + ) as YamlMap; + + for (var key in ['builders', builderName, 'build_extensions']) { + buildYaml = buildYaml[key] as YamlMap; + } + + final extensions = Set.from(buildYaml['.dart'] as YamlList); + + final codedExtensions = builder.buildExtensions['.dart'].toSet(); + + final tooMany = extensions.difference(codedExtensions); + if (tooMany.isNotEmpty) { + log.warning( + '$builderName: Too many extensions in build.yaml:\n' + '${tooMany.join('\n')}', + ); + } + + final missing = codedExtensions.difference(extensions); + if (missing.isNotEmpty) { + log.warning( + '$builderName: Missing extensions in build.yaml:\n' + '${missing.join('\n')}', + ); + } + + return builder; +} + +class Replacement { + final Pattern existing; + final String replacement; + + const Replacement(this.existing, this.replacement); + + const Replacement.addJsonSerializableKey(String key, bool value) + : existing = '@JsonSerializable(', + replacement = '@JsonSerializable(\n $key: $value,'; + + static String generate( + String inputContent, + Iterable replacements, + ) { + var outputContent = inputContent; + + for (final r in replacements) { + if (!outputContent.contains(r.existing)) { + print('Input string did not contain `${r.existing}` as expected.'); + } else { + outputContent = outputContent.replaceAll(r.existing, r.replacement); + } + } + + return outputContent.replaceAll(',)', ',\n)'); + } +} diff --git a/json_serializable/tool/test_builder.dart b/json_serializable/tool/test_builder.dart index 86a93f6f5..ea69a84fc 100644 --- a/json_serializable/tool/test_builder.dart +++ b/json_serializable/tool/test_builder.dart @@ -4,50 +4,19 @@ import 'dart:async'; import 'dart:collection'; -import 'dart:io'; import 'package:build/build.dart'; import 'package:dart_style/dart_style.dart'; import 'package:path/path.dart' as p; -import 'package:yaml/yaml.dart'; -final _formatter = DartFormatter(); - -Builder internal([_]) { - const builder = _SmartBuilder(); - _validateBuilder(builder); - return builder; -} - -// Until we have verification in pkg:build and friends -// https://github.com/dart-lang/build/issues/590 -void _validateBuilder(_SmartBuilder builder) { - var buildYaml = loadYaml( - File('build.yaml').readAsStringSync(), - sourceUrl: 'build.yaml', - ) as YamlMap; - - for (var key in ['builders', '_internal', 'build_extensions']) { - buildYaml = buildYaml[key] as YamlMap; - } +import 'shared.dart'; - final extensions = Set.from(buildYaml['.dart'] as YamlList); - - final codedExtensions = builder.buildExtensions['.dart'].toSet(); - - final tooMany = extensions.difference(codedExtensions); - if (tooMany.isNotEmpty) { - log.warning('Too many extensions in build.yaml:\n${tooMany.join('\n')}'); - } +final _formatter = DartFormatter(); - final missing = codedExtensions.difference(extensions); - if (missing.isNotEmpty) { - log.warning('Missing extensions in build.yaml:\n${missing.join('\n')}'); - } -} +Builder testBuilder([_]) => validate('_test_builder', const _TestBuilder()); -class _SmartBuilder implements Builder { - const _SmartBuilder(); +class _TestBuilder implements Builder { + const _TestBuilder(); @override FutureOr build(BuildStep buildStep) async { @@ -64,8 +33,8 @@ class _SmartBuilder implements Builder { final partName = extension.substring(0, extension.length - 5); - final replacements = <_Replacement>[ - _Replacement( + final replacements = [ + Replacement( "part '$baseName.g.dart';", "part '$baseName$partName.g.dart';", ) @@ -73,7 +42,7 @@ class _SmartBuilder implements Builder { if (baseName == _kitchenSinkBaseName) { final description = _configToName(config.toSet()); - replacements.add(_Replacement( + replacements.add(Replacement( "String get description => '--defaults--';", "String get description => '$description';", )); @@ -85,7 +54,7 @@ class _SmartBuilder implements Builder { replacements.addAll(_optionReplacement(baseName, entry)); } - final content = _Replacement.generate(sourceContent, replacements); + final content = Replacement.generate(sourceContent, replacements); await buildStep.writeAsString(newId, _formatter.format(content)); } @@ -110,89 +79,89 @@ class _SmartBuilder implements Builder { } const _configReplacements = { - 'any_map': _Replacement.addJsonSerializableKey('anyMap', true), - 'checked': _Replacement.addJsonSerializableKey('checked', true), - 'non_nullable': _Replacement.addJsonSerializableKey('nullable', false), + 'any_map': Replacement.addJsonSerializableKey('anyMap', true), + 'checked': Replacement.addJsonSerializableKey('checked', true), + 'non_nullable': Replacement.addJsonSerializableKey('nullable', false), 'explicit_to_json': - _Replacement.addJsonSerializableKey('explicitToJson', true), - 'exclude_null': _Replacement.addJsonSerializableKey('includeIfNull', false), + Replacement.addJsonSerializableKey('explicitToJson', true), + 'exclude_null': Replacement.addJsonSerializableKey('includeIfNull', false), }; const _kitchenSinkReplacements = { 'any_map': [ - _Replacement( + Replacement( 'bool get anyMap => false;', 'bool get anyMap => true;', ), - _Replacement( + Replacement( 'class _Factory implements k.KitchenSinkFactory', 'class _Factory implements k.KitchenSinkFactory', ), - _Replacement( + Replacement( 'k.KitchenSink fromJson(Map json)', 'k.KitchenSink fromJson(Map json)', ), - _Replacement( + Replacement( 'factory KitchenSink.fromJson(Map json)', 'factory KitchenSink.fromJson(Map json)', ), ], 'checked': [ - _Replacement( + Replacement( 'bool get checked => false;', 'bool get checked => true;', ) ], 'exclude_null': [ - _Replacement( + Replacement( 'bool get excludeNull => false;', 'bool get excludeNull => true;', ), ], 'explicit_to_json': [ - _Replacement( + Replacement( 'bool get explicitToJson => false;', 'bool get explicitToJson => true;', ), ], 'non_nullable': [ - _Replacement( + Replacement( 'bool get nullable => true;', 'bool get nullable => false;', ), - _Replacement( + Replacement( 'List _defaultList() => null;', 'List _defaultList() => [];', ), - _Replacement( + Replacement( 'Set _defaultSet() => null;', 'Set _defaultSet() => {};', ), - _Replacement( + Replacement( 'Map _defaultMap() => null;', 'Map _defaultMap() => {};', ), - _Replacement( + Replacement( 'SimpleObject _defaultSimpleObject() => null;', 'SimpleObject _defaultSimpleObject() => SimpleObject(42);', ), - _Replacement( + Replacement( 'StrictKeysObject _defaultStrictKeysObject() => null;', 'StrictKeysObject _defaultStrictKeysObject() => ' "StrictKeysObject(10, 'cool');", ), - _Replacement( + Replacement( 'DateTime dateTime;', 'DateTime dateTime = DateTime(1981, 6, 5);', ), - _Replacement( + Replacement( 'BigInt bigInt;', "BigInt bigInt = BigInt.parse('10000000000000000000');", ), ], }; -Iterable<_Replacement> _optionReplacement( +Iterable _optionReplacement( String baseName, String optionKey) sync* { yield _configReplacements[optionKey]; @@ -237,29 +206,3 @@ const _fileConfigurationMap = >>{ {'non_nullable'}, } }; - -class _Replacement { - final Pattern existing; - final String replacement; - - const _Replacement(this.existing, this.replacement); - - const _Replacement.addJsonSerializableKey(String key, bool value) - : existing = '@JsonSerializable(', - replacement = '@JsonSerializable(\n $key: $value,'; - - static String generate( - String inputContent, Iterable<_Replacement> replacements) { - var outputContent = inputContent; - - for (final r in replacements) { - if (!outputContent.contains(r.existing)) { - print('Input string did not contain `${r.existing}` as expected.'); - } else { - outputContent = outputContent.replaceAll(r.existing, r.replacement); - } - } - - return outputContent.replaceAll(',)', ',\n)'); - } -} diff --git a/json_serializable/tool/test_type_builder.dart b/json_serializable/tool/test_type_builder.dart new file mode 100644 index 000000000..ed5df45a0 --- /dev/null +++ b/json_serializable/tool/test_type_builder.dart @@ -0,0 +1,243 @@ +// Copyright (c) 2018, 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 'dart:async'; + +import 'package:build/build.dart'; +import 'package:meta/meta.dart'; + +import 'shared.dart'; + +const _typesToTest = { + 'BigInt': _TestType( + jsonExpression: "'12345'", + altJsonExpression: "'67890'", + ), + 'bool': _TestType( + defaultExpression: 'true', + altJsonExpression: 'false', + ), + 'DateTime': _TestType( + jsonExpression: "'2020-01-01T00:00:00.000'", + altJsonExpression: "'2018-01-01T00:00:00.000'", + ), + 'double': _TestType( + defaultExpression: '3.14', + altJsonExpression: '6.28', + ), + 'Duration': _TestType( + jsonExpression: '1234', + altJsonExpression: '2345', + ), + 'dynamic': _TestType( + altJsonExpression: "'dynamic'", + ), + 'num': _TestType( + defaultExpression: '88.6', + altJsonExpression: '29', + ), + 'Object': _TestType( + altJsonExpression: "'Object'", + ), + 'String': _TestType( + defaultExpression: "'a string'", + altJsonExpression: "'another string'", + ), + 'Uri': _TestType( + jsonExpression: "'https://example.com'", + altJsonExpression: "'https://dart.dev'", + ), + 'MyEnum': _TestType( + defaultExpression: 'MyEnum.alpha', + jsonExpression: "'alpha'", + altJsonExpression: "'beta'", + replacements: [ + Replacement( + '@JsonSerializable()', + ''' +enum MyEnum { alpha, beta, gamma, delta } + +@JsonSerializable()''', + ) + ], + ), + // + // Collection types + // + 'Map': _TestType( + defaultExpression: "{'a': 1}", + altJsonExpression: "{'b': 2}", + ), + 'List': _TestType( + defaultExpression: '[$_defaultCollectionExpressions]', + altJsonExpression: '[$_altCollectionExpressions]', + ), + 'Set': _TestType( + defaultExpression: '{$_defaultCollectionExpressions}', + jsonExpression: '[$_defaultCollectionExpressions]', + altJsonExpression: '[$_altCollectionExpressions]', + ), + 'Iterable': _TestType( + defaultExpression: '[$_defaultCollectionExpressions]', + altJsonExpression: '[$_altCollectionExpressions]', + ), +}; + +const _defaultCollectionExpressions = '42, true, false, null'; +const _altCollectionExpressions = '43, false'; + +Builder typeBuilder([_]) => validate('_type_builder', const _TypeBuilder()); + +class _TypeBuilder implements Builder { + const _TypeBuilder(); + + @override + FutureOr build(BuildStep buildStep) async { + final inputId = buildStep.inputId; + + final sourceContent = await buildStep.readAsString(inputId); + + for (var entry in _typesToTest.entries) { + final type = entry.key; + final newId = buildStep.inputId.changeExtension(_toTypeExtension(type)); + + await buildStep.writeAsString( + newId, + Replacement.generate( + sourceContent, + entry.value.replacements(type), + ), + ); + } + } + + @override + Map> get buildExtensions => { + '.dart': _typesToTest.keys.map(_toTypeExtension).toSet().toList() + ..sort() + }; +} + +Builder typeTestBuilder([_]) => + validate('_type_test_builder', const _TypeTestBuilder()); + +class _TypeTestBuilder implements Builder { + const _TypeTestBuilder(); + + @override + FutureOr build(BuildStep buildStep) async { + final inputId = buildStep.inputId; + + final sourceContent = await buildStep.readAsString(inputId); + + for (var entry in _typesToTest.entries) { + final type = entry.key; + final newId = + buildStep.inputId.changeExtension(_toTypeTestExtension(type)); + + await buildStep.writeAsString( + newId, + Replacement.generate( + sourceContent, + entry.value.testReplacements(type), + ), + ); + } + } + + @override + Map> get buildExtensions => { + '.dart': _typesToTest.keys.map(_toTypeTestExtension).toSet().toList() + ..sort() + }; +} + +String _typeToPathPart(String type) => type.toLowerCase(); + +String _toTypeExtension(String e, {bool includeDotDart = true}) => + '.type_${_typeToPathPart(e)}${includeDotDart ? '.dart' : ''}'; + +String _toTypeTestExtension(String e) => '.${_typeToPathPart(e)}_test.dart'; + +class _TestType { + final List _replacements; + final String defaultExpression; + final String jsonExpression; + final String altJsonExpression; + + const _TestType({ + List replacements, + this.defaultExpression, + String jsonExpression, + @required String altJsonExpression, + }) : _replacements = replacements ?? const [], + jsonExpression = jsonExpression ?? defaultExpression, + altJsonExpression = + altJsonExpression ?? jsonExpression ?? defaultExpression; + + Iterable replacements(String type) sync* { + final newPart = _toTypeExtension(type, includeDotDart: false); + + yield Replacement( + "part 'input.g.dart';", + "part 'input$newPart.g.dart';", + ); + yield Replacement( + 'final int value;', + 'final $type value;', + ); + yield Replacement( + 'final int nullable;', + 'final $type nullable;', + ); + + yield* _replacements; + + final defaultReplacement = defaultExpression == null + ? '' + : _defaultSource + .replaceFirst('42', defaultExpression) + .replaceFirst('int', type); + + yield Replacement( + _defaultSource, + defaultReplacement, + ); + } + + Iterable testReplacements(String type) sync* { + yield Replacement( + "import 'input.dart';", + "import 'input.type_${_typeToPathPart(type)}.dart';", + ); + + yield Replacement( + ''' +final _defaultValue = 42; +final _altValue = 43; +''', + ''' +final _defaultValue = $jsonExpression; +final _altValue = $altJsonExpression; +''', + ); + + if (defaultExpression == null) { + yield const Replacement( + " 'withDefault': _defaultValue,\n", + '', + ); + yield const Replacement( + " 'withDefault': _altValue,\n", + '', + ); + } + } + + static const _defaultSource = r''' + @JsonKey(defaultValue: 42) + int withDefault; + +'''; +} From 4306af0a2db287920e332cf31ad2b8556508eaf0 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 21 Jul 2020 12:01:11 -0700 Subject: [PATCH 202/569] Add an example of handling a generic response object (#673) Closes https://github.com/google/json_serializable.dart/issues/671 Related to https://github.com/google/json_serializable.dart/issues/646 --- .../lib/generic_response_class_example.dart | 105 ++++++++++++++++++ .../lib/generic_response_class_example.g.dart | 43 +++++++ example/test/generic_response_class_test.dart | 82 ++++++++++++++ 3 files changed, 230 insertions(+) create mode 100644 example/lib/generic_response_class_example.dart create mode 100644 example/lib/generic_response_class_example.g.dart create mode 100644 example/test/generic_response_class_test.dart diff --git a/example/lib/generic_response_class_example.dart b/example/lib/generic_response_class_example.dart new file mode 100644 index 000000000..c1754ed93 --- /dev/null +++ b/example/lib/generic_response_class_example.dart @@ -0,0 +1,105 @@ +// Copyright (c) 2020, 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:json_annotation/json_annotation.dart'; + +part 'generic_response_class_example.g.dart'; + +// An example highlighting the problem outlined in +// https://github.com/google/json_serializable.dart/issues/646 +// https://github.com/google/json_serializable.dart/issues/671 + +@JsonSerializable(createToJson: false) +class BaseResponse { + final int status; + final String msg; + + @JsonKey(fromJson: _dataFromJson) + final T data; + + const BaseResponse({ + this.status, + this.msg, + this.data, + }); + + factory BaseResponse.fromJson(Map json) => + _$BaseResponseFromJson(json); + + /// Decodes [json] by "inspecting" its contents. + static T _dataFromJson(Object json) { + if (json is Map) { + if (json.containsKey('email')) { + return User.fromJson(json) as T; + } + + if (json.containsKey('title')) { + return Article.fromJson(json) as T; + } + } else if (json is List) { + // NOTE: this logic assumes the ONLY valid value for a `List` in this case + // is a List. If that assumption changes, then it will be + // necessary to "peak" into non-empty lists to determine the type! + + return json + .map((e) => Article.fromJson(e as Map)) + .toList() as T; + } + + throw ArgumentError.value( + json, + 'json', + 'Cannot convert the provided data.', + ); + } +} + +@JsonSerializable(createToJson: false) +class Article { + final int id; + final String title; + + @JsonKey(nullable: true) + final User author; + + @JsonKey(nullable: true) + final List comments; + + const Article({ + this.id, + this.title, + this.author, + this.comments, + }); + + factory Article.fromJson(Map json) => + _$ArticleFromJson(json); +} + +@JsonSerializable(createToJson: false) +class User { + final int id; + final String email; + + const User({ + this.id, + this.email, + }); + + factory User.fromJson(Map json) => _$UserFromJson(json); +} + +@JsonSerializable(createToJson: false) +class Comment { + final String content; + final int id; + + const Comment({ + this.id, + this.content, + }); + + factory Comment.fromJson(Map json) => + _$CommentFromJson(json); +} diff --git a/example/lib/generic_response_class_example.g.dart b/example/lib/generic_response_class_example.g.dart new file mode 100644 index 000000000..28b26b6dd --- /dev/null +++ b/example/lib/generic_response_class_example.g.dart @@ -0,0 +1,43 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'generic_response_class_example.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +BaseResponse _$BaseResponseFromJson(Map json) { + return BaseResponse( + status: json['status'] as int, + msg: json['msg'] as String, + data: BaseResponse._dataFromJson(json['data']), + ); +} + +Article _$ArticleFromJson(Map json) { + return Article( + id: json['id'] as int, + title: json['title'] as String, + author: json['author'] == null + ? null + : User.fromJson(json['author'] as Map), + comments: (json['comments'] as List) + ?.map((e) => + e == null ? null : Comment.fromJson(e as Map)) + ?.toList(), + ); +} + +User _$UserFromJson(Map json) { + return User( + id: json['id'] as int, + email: json['email'] as String, + ); +} + +Comment _$CommentFromJson(Map json) { + return Comment( + id: json['id'] as int, + content: json['content'] as String, + ); +} diff --git a/example/test/generic_response_class_test.dart b/example/test/generic_response_class_test.dart new file mode 100644 index 000000000..3ac596d8e --- /dev/null +++ b/example/test/generic_response_class_test.dart @@ -0,0 +1,82 @@ +// Copyright (c) 2020, 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:example/generic_response_class_example.dart'; +import 'package:test/test.dart'; + +const _jsonUser = { + 'status': 200, + 'msg': 'success', + 'data': {'id': 1, 'email': 'test@test.com'} +}; + +final _jsonArticle = { + 'status': 200, + 'msg': 'success', + 'data': { + 'id': 2, + 'title': 'title1', + 'author': _jsonUser['data'], + 'comments': [ + {'content': 'comment context', 'id': 1}, + {'content': 'comment context', 'id': 2}, + ] + } +}; + +final _jsonArticleList = { + 'status': 200, + 'msg': 'success', + 'data': [ + {'id': 1, 'title': 'title1'}, + _jsonArticle['data'], + ] +}; + +void _testResponse(BaseResponse response, void Function(T) testFunction) { + expect(response.status, 200); + expect(response.msg, 'success'); + testFunction(response.data as T); +} + +void _testUser(User user) { + expect(user.email, 'test@test.com'); + expect(user.id, 1); +} + +void _testArticle(Article article) { + expect(article.id, 2); + expect(article.title, 'title1'); + _testUser(article.author); + expect(article.comments, hasLength(2)); +} + +void _testArticleList(List
articles) { + expect(articles, hasLength(2)); + _testArticle(articles[1]); +} + +void main() { + test('user', () { + _testResponse(BaseResponse.fromJson(_jsonUser), _testUser); + // without generic + _testResponse(BaseResponse.fromJson(_jsonUser), _testUser); + }); + + test('article', () { + _testResponse(BaseResponse
.fromJson(_jsonArticle), _testArticle); + // without generic + _testResponse(BaseResponse.fromJson(_jsonArticle), _testArticle); + }); + + test('article list', () { + _testResponse( + BaseResponse>.fromJson(_jsonArticleList), + _testArticleList, + ); + + // without generic + _testResponse(BaseResponse.fromJson(_jsonArticleList), _testArticleList); + }); +} From ce98bcc08444c66112ac9e5e2452cf3f20fdd605 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 22 Jul 2020 21:05:01 -0700 Subject: [PATCH 203/569] test: use named private converter class (#674) Delete default constructor - it's not used! --- json_serializable/test/generic_files/generic_class.dart | 4 +--- json_serializable/test/generic_files/generic_class.g.dart | 6 +++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/json_serializable/test/generic_files/generic_class.dart b/json_serializable/test/generic_files/generic_class.dart index e6dbe12c1..b7cdf649c 100644 --- a/json_serializable/test/generic_files/generic_class.dart +++ b/json_serializable/test/generic_files/generic_class.dart @@ -40,7 +40,7 @@ class GenericClass { } @JsonSerializable() -@_DurationMillisecondConverter() +@_DurationMillisecondConverter.named() @_DurationListMillisecondConverter() class GenericClassWithConverter { @_SimpleConverter() @@ -81,8 +81,6 @@ class _SimpleConverter implements JsonConverter> { } class _DurationMillisecondConverter implements JsonConverter { - const _DurationMillisecondConverter(); - const _DurationMillisecondConverter.named(); @override diff --git a/json_serializable/test/generic_files/generic_class.g.dart b/json_serializable/test/generic_files/generic_class.g.dart index afa8c824d..ae3c03aad 100644 --- a/json_serializable/test/generic_files/generic_class.g.dart +++ b/json_serializable/test/generic_files/generic_class.g.dart @@ -42,8 +42,8 @@ GenericClassWithConverter _SimpleConverter().fromJson(json['fieldT'] as Map) ..fieldS = _SimpleConverter().fromJson(json['fieldS'] as Map) - ..duration = - const _DurationMillisecondConverter().fromJson(json['duration'] as int) + ..duration = const _DurationMillisecondConverter.named() + .fromJson(json['duration'] as int) ..listDuration = const _DurationListMillisecondConverter() .fromJson(json['listDuration'] as int); } @@ -57,7 +57,7 @@ Map _$GenericClassWithConverterToJson( 'fieldT': _SimpleConverter().toJson(instance.fieldT), 'fieldS': _SimpleConverter().toJson(instance.fieldS), 'duration': - const _DurationMillisecondConverter().toJson(instance.duration), + const _DurationMillisecondConverter.named().toJson(instance.duration), 'listDuration': const _DurationListMillisecondConverter() .toJson(instance.listDuration), }; From 0a08217cae11135b882138c81c878b5b29f1da67 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 20 Jul 2020 16:25:17 -0700 Subject: [PATCH 204/569] Supported types tests: generate generic collection types --- .../supported_types/input.type_iterable.dart | 180 +++ .../input.type_iterable.g.dart | 136 ++ .../test/supported_types/input.type_list.dart | 180 +++ .../supported_types/input.type_list.g.dart | 142 ++ .../test/supported_types/input.type_map.dart | 1260 ++++++++++++++++ .../supported_types/input.type_map.g.dart | 1339 +++++++++++++++++ .../test/supported_types/input.type_set.dart | 180 +++ .../supported_types/input.type_set.g.dart | 142 ++ json_serializable/tool/test_type_builder.dart | 164 +- json_serializable/tool/test_type_data.dart | 142 ++ 10 files changed, 3749 insertions(+), 116 deletions(-) create mode 100644 json_serializable/tool/test_type_data.dart diff --git a/json_serializable/test/supported_types/input.type_iterable.dart b/json_serializable/test/supported_types/input.type_iterable.dart index ef46df066..1cf4b8463 100644 --- a/json_serializable/test/supported_types/input.type_iterable.dart +++ b/json_serializable/test/supported_types/input.type_iterable.dart @@ -26,3 +26,183 @@ class SimpleClass { Map toJson() => _$SimpleClassToJson(this); } + +@JsonSerializable() +class SimpleClassBigInt { + final Iterable value; + + @JsonKey(nullable: false) + final Iterable nullable; + + SimpleClassBigInt( + this.value, + this.nullable, + ); + + factory SimpleClassBigInt.fromJson(Map json) => + _$SimpleClassBigIntFromJson(json); + + Map toJson() => _$SimpleClassBigIntToJson(this); +} + +@JsonSerializable() +class SimpleClassBool { + final Iterable value; + + @JsonKey(nullable: false) + final Iterable nullable; + + SimpleClassBool( + this.value, + this.nullable, + ); + + factory SimpleClassBool.fromJson(Map json) => + _$SimpleClassBoolFromJson(json); + + Map toJson() => _$SimpleClassBoolToJson(this); +} + +@JsonSerializable() +class SimpleClassDateTime { + final Iterable value; + + @JsonKey(nullable: false) + final Iterable nullable; + + SimpleClassDateTime( + this.value, + this.nullable, + ); + + factory SimpleClassDateTime.fromJson(Map json) => + _$SimpleClassDateTimeFromJson(json); + + Map toJson() => _$SimpleClassDateTimeToJson(this); +} + +@JsonSerializable() +class SimpleClassDouble { + final Iterable value; + + @JsonKey(nullable: false) + final Iterable nullable; + + SimpleClassDouble( + this.value, + this.nullable, + ); + + factory SimpleClassDouble.fromJson(Map json) => + _$SimpleClassDoubleFromJson(json); + + Map toJson() => _$SimpleClassDoubleToJson(this); +} + +@JsonSerializable() +class SimpleClassDuration { + final Iterable value; + + @JsonKey(nullable: false) + final Iterable nullable; + + SimpleClassDuration( + this.value, + this.nullable, + ); + + factory SimpleClassDuration.fromJson(Map json) => + _$SimpleClassDurationFromJson(json); + + Map toJson() => _$SimpleClassDurationToJson(this); +} + +@JsonSerializable() +class SimpleClassDynamic { + final Iterable value; + + @JsonKey(nullable: false) + final Iterable nullable; + + SimpleClassDynamic( + this.value, + this.nullable, + ); + + factory SimpleClassDynamic.fromJson(Map json) => + _$SimpleClassDynamicFromJson(json); + + Map toJson() => _$SimpleClassDynamicToJson(this); +} + +@JsonSerializable() +class SimpleClassNum { + final Iterable value; + + @JsonKey(nullable: false) + final Iterable nullable; + + SimpleClassNum( + this.value, + this.nullable, + ); + + factory SimpleClassNum.fromJson(Map json) => + _$SimpleClassNumFromJson(json); + + Map toJson() => _$SimpleClassNumToJson(this); +} + +@JsonSerializable() +class SimpleClassObject { + final Iterable value; + + @JsonKey(nullable: false) + final Iterable nullable; + + SimpleClassObject( + this.value, + this.nullable, + ); + + factory SimpleClassObject.fromJson(Map json) => + _$SimpleClassObjectFromJson(json); + + Map toJson() => _$SimpleClassObjectToJson(this); +} + +@JsonSerializable() +class SimpleClassString { + final Iterable value; + + @JsonKey(nullable: false) + final Iterable nullable; + + SimpleClassString( + this.value, + this.nullable, + ); + + factory SimpleClassString.fromJson(Map json) => + _$SimpleClassStringFromJson(json); + + Map toJson() => _$SimpleClassStringToJson(this); +} + +@JsonSerializable() +class SimpleClassUri { + final Iterable value; + + @JsonKey(nullable: false) + final Iterable nullable; + + SimpleClassUri( + this.value, + this.nullable, + ); + + factory SimpleClassUri.fromJson(Map json) => + _$SimpleClassUriFromJson(json); + + Map toJson() => _$SimpleClassUriToJson(this); +} diff --git a/json_serializable/test/supported_types/input.type_iterable.g.dart b/json_serializable/test/supported_types/input.type_iterable.g.dart index 5d1b1d9c7..7175714ef 100644 --- a/json_serializable/test/supported_types/input.type_iterable.g.dart +++ b/json_serializable/test/supported_types/input.type_iterable.g.dart @@ -19,3 +19,139 @@ Map _$SimpleClassToJson(SimpleClass instance) => 'nullable': instance.nullable.toList(), 'withDefault': instance.withDefault?.toList(), }; + +SimpleClassBigInt _$SimpleClassBigIntFromJson(Map json) { + return SimpleClassBigInt( + (json['value'] as List) + ?.map((e) => e == null ? null : BigInt.parse(e as String)), + (json['nullable'] as List).map((e) => BigInt.parse(e as String)), + ); +} + +Map _$SimpleClassBigIntToJson(SimpleClassBigInt instance) => + { + 'value': instance.value?.map((e) => e?.toString())?.toList(), + 'nullable': instance.nullable.map((e) => e.toString()).toList(), + }; + +SimpleClassBool _$SimpleClassBoolFromJson(Map json) { + return SimpleClassBool( + (json['value'] as List)?.map((e) => e as bool), + (json['nullable'] as List).map((e) => e as bool), + ); +} + +Map _$SimpleClassBoolToJson(SimpleClassBool instance) => + { + 'value': instance.value?.toList(), + 'nullable': instance.nullable.toList(), + }; + +SimpleClassDateTime _$SimpleClassDateTimeFromJson(Map json) { + return SimpleClassDateTime( + (json['value'] as List) + ?.map((e) => e == null ? null : DateTime.parse(e as String)), + (json['nullable'] as List).map((e) => DateTime.parse(e as String)), + ); +} + +Map _$SimpleClassDateTimeToJson( + SimpleClassDateTime instance) => + { + 'value': instance.value?.map((e) => e?.toIso8601String())?.toList(), + 'nullable': instance.nullable.map((e) => e.toIso8601String()).toList(), + }; + +SimpleClassDouble _$SimpleClassDoubleFromJson(Map json) { + return SimpleClassDouble( + (json['value'] as List)?.map((e) => (e as num)?.toDouble()), + (json['nullable'] as List).map((e) => (e as num).toDouble()), + ); +} + +Map _$SimpleClassDoubleToJson(SimpleClassDouble instance) => + { + 'value': instance.value?.toList(), + 'nullable': instance.nullable.toList(), + }; + +SimpleClassDuration _$SimpleClassDurationFromJson(Map json) { + return SimpleClassDuration( + (json['value'] as List) + ?.map((e) => e == null ? null : Duration(microseconds: e as int)), + (json['nullable'] as List).map((e) => Duration(microseconds: e as int)), + ); +} + +Map _$SimpleClassDurationToJson( + SimpleClassDuration instance) => + { + 'value': instance.value?.map((e) => e?.inMicroseconds)?.toList(), + 'nullable': instance.nullable.map((e) => e.inMicroseconds).toList(), + }; + +SimpleClassDynamic _$SimpleClassDynamicFromJson(Map json) { + return SimpleClassDynamic( + json['value'] as List, + json['nullable'] as List, + ); +} + +Map _$SimpleClassDynamicToJson(SimpleClassDynamic instance) => + { + 'value': instance.value?.toList(), + 'nullable': instance.nullable.toList(), + }; + +SimpleClassNum _$SimpleClassNumFromJson(Map json) { + return SimpleClassNum( + (json['value'] as List)?.map((e) => e as num), + (json['nullable'] as List).map((e) => e as num), + ); +} + +Map _$SimpleClassNumToJson(SimpleClassNum instance) => + { + 'value': instance.value?.toList(), + 'nullable': instance.nullable.toList(), + }; + +SimpleClassObject _$SimpleClassObjectFromJson(Map json) { + return SimpleClassObject( + json['value'] as List, + json['nullable'] as List, + ); +} + +Map _$SimpleClassObjectToJson(SimpleClassObject instance) => + { + 'value': instance.value?.toList(), + 'nullable': instance.nullable.toList(), + }; + +SimpleClassString _$SimpleClassStringFromJson(Map json) { + return SimpleClassString( + (json['value'] as List)?.map((e) => e as String), + (json['nullable'] as List).map((e) => e as String), + ); +} + +Map _$SimpleClassStringToJson(SimpleClassString instance) => + { + 'value': instance.value?.toList(), + 'nullable': instance.nullable.toList(), + }; + +SimpleClassUri _$SimpleClassUriFromJson(Map json) { + return SimpleClassUri( + (json['value'] as List) + ?.map((e) => e == null ? null : Uri.parse(e as String)), + (json['nullable'] as List).map((e) => Uri.parse(e as String)), + ); +} + +Map _$SimpleClassUriToJson(SimpleClassUri instance) => + { + 'value': instance.value?.map((e) => e?.toString())?.toList(), + 'nullable': instance.nullable.map((e) => e.toString()).toList(), + }; diff --git a/json_serializable/test/supported_types/input.type_list.dart b/json_serializable/test/supported_types/input.type_list.dart index b6a41d783..f63d38afe 100644 --- a/json_serializable/test/supported_types/input.type_list.dart +++ b/json_serializable/test/supported_types/input.type_list.dart @@ -26,3 +26,183 @@ class SimpleClass { Map toJson() => _$SimpleClassToJson(this); } + +@JsonSerializable() +class SimpleClassBigInt { + final List value; + + @JsonKey(nullable: false) + final List nullable; + + SimpleClassBigInt( + this.value, + this.nullable, + ); + + factory SimpleClassBigInt.fromJson(Map json) => + _$SimpleClassBigIntFromJson(json); + + Map toJson() => _$SimpleClassBigIntToJson(this); +} + +@JsonSerializable() +class SimpleClassBool { + final List value; + + @JsonKey(nullable: false) + final List nullable; + + SimpleClassBool( + this.value, + this.nullable, + ); + + factory SimpleClassBool.fromJson(Map json) => + _$SimpleClassBoolFromJson(json); + + Map toJson() => _$SimpleClassBoolToJson(this); +} + +@JsonSerializable() +class SimpleClassDateTime { + final List value; + + @JsonKey(nullable: false) + final List nullable; + + SimpleClassDateTime( + this.value, + this.nullable, + ); + + factory SimpleClassDateTime.fromJson(Map json) => + _$SimpleClassDateTimeFromJson(json); + + Map toJson() => _$SimpleClassDateTimeToJson(this); +} + +@JsonSerializable() +class SimpleClassDouble { + final List value; + + @JsonKey(nullable: false) + final List nullable; + + SimpleClassDouble( + this.value, + this.nullable, + ); + + factory SimpleClassDouble.fromJson(Map json) => + _$SimpleClassDoubleFromJson(json); + + Map toJson() => _$SimpleClassDoubleToJson(this); +} + +@JsonSerializable() +class SimpleClassDuration { + final List value; + + @JsonKey(nullable: false) + final List nullable; + + SimpleClassDuration( + this.value, + this.nullable, + ); + + factory SimpleClassDuration.fromJson(Map json) => + _$SimpleClassDurationFromJson(json); + + Map toJson() => _$SimpleClassDurationToJson(this); +} + +@JsonSerializable() +class SimpleClassDynamic { + final List value; + + @JsonKey(nullable: false) + final List nullable; + + SimpleClassDynamic( + this.value, + this.nullable, + ); + + factory SimpleClassDynamic.fromJson(Map json) => + _$SimpleClassDynamicFromJson(json); + + Map toJson() => _$SimpleClassDynamicToJson(this); +} + +@JsonSerializable() +class SimpleClassNum { + final List value; + + @JsonKey(nullable: false) + final List nullable; + + SimpleClassNum( + this.value, + this.nullable, + ); + + factory SimpleClassNum.fromJson(Map json) => + _$SimpleClassNumFromJson(json); + + Map toJson() => _$SimpleClassNumToJson(this); +} + +@JsonSerializable() +class SimpleClassObject { + final List value; + + @JsonKey(nullable: false) + final List nullable; + + SimpleClassObject( + this.value, + this.nullable, + ); + + factory SimpleClassObject.fromJson(Map json) => + _$SimpleClassObjectFromJson(json); + + Map toJson() => _$SimpleClassObjectToJson(this); +} + +@JsonSerializable() +class SimpleClassString { + final List value; + + @JsonKey(nullable: false) + final List nullable; + + SimpleClassString( + this.value, + this.nullable, + ); + + factory SimpleClassString.fromJson(Map json) => + _$SimpleClassStringFromJson(json); + + Map toJson() => _$SimpleClassStringToJson(this); +} + +@JsonSerializable() +class SimpleClassUri { + final List value; + + @JsonKey(nullable: false) + final List nullable; + + SimpleClassUri( + this.value, + this.nullable, + ); + + factory SimpleClassUri.fromJson(Map json) => + _$SimpleClassUriFromJson(json); + + Map toJson() => _$SimpleClassUriToJson(this); +} diff --git a/json_serializable/test/supported_types/input.type_list.g.dart b/json_serializable/test/supported_types/input.type_list.g.dart index b918179d2..f17bcfb3a 100644 --- a/json_serializable/test/supported_types/input.type_list.g.dart +++ b/json_serializable/test/supported_types/input.type_list.g.dart @@ -19,3 +19,145 @@ Map _$SimpleClassToJson(SimpleClass instance) => 'nullable': instance.nullable, 'withDefault': instance.withDefault, }; + +SimpleClassBigInt _$SimpleClassBigIntFromJson(Map json) { + return SimpleClassBigInt( + (json['value'] as List) + ?.map((e) => e == null ? null : BigInt.parse(e as String)) + ?.toList(), + (json['nullable'] as List).map((e) => BigInt.parse(e as String)).toList(), + ); +} + +Map _$SimpleClassBigIntToJson(SimpleClassBigInt instance) => + { + 'value': instance.value?.map((e) => e?.toString())?.toList(), + 'nullable': instance.nullable.map((e) => e.toString()).toList(), + }; + +SimpleClassBool _$SimpleClassBoolFromJson(Map json) { + return SimpleClassBool( + (json['value'] as List)?.map((e) => e as bool)?.toList(), + (json['nullable'] as List).map((e) => e as bool).toList(), + ); +} + +Map _$SimpleClassBoolToJson(SimpleClassBool instance) => + { + 'value': instance.value, + 'nullable': instance.nullable, + }; + +SimpleClassDateTime _$SimpleClassDateTimeFromJson(Map json) { + return SimpleClassDateTime( + (json['value'] as List) + ?.map((e) => e == null ? null : DateTime.parse(e as String)) + ?.toList(), + (json['nullable'] as List).map((e) => DateTime.parse(e as String)).toList(), + ); +} + +Map _$SimpleClassDateTimeToJson( + SimpleClassDateTime instance) => + { + 'value': instance.value?.map((e) => e?.toIso8601String())?.toList(), + 'nullable': instance.nullable.map((e) => e.toIso8601String()).toList(), + }; + +SimpleClassDouble _$SimpleClassDoubleFromJson(Map json) { + return SimpleClassDouble( + (json['value'] as List)?.map((e) => (e as num)?.toDouble())?.toList(), + (json['nullable'] as List).map((e) => (e as num).toDouble()).toList(), + ); +} + +Map _$SimpleClassDoubleToJson(SimpleClassDouble instance) => + { + 'value': instance.value, + 'nullable': instance.nullable, + }; + +SimpleClassDuration _$SimpleClassDurationFromJson(Map json) { + return SimpleClassDuration( + (json['value'] as List) + ?.map((e) => e == null ? null : Duration(microseconds: e as int)) + ?.toList(), + (json['nullable'] as List) + .map((e) => Duration(microseconds: e as int)) + .toList(), + ); +} + +Map _$SimpleClassDurationToJson( + SimpleClassDuration instance) => + { + 'value': instance.value?.map((e) => e?.inMicroseconds)?.toList(), + 'nullable': instance.nullable.map((e) => e.inMicroseconds).toList(), + }; + +SimpleClassDynamic _$SimpleClassDynamicFromJson(Map json) { + return SimpleClassDynamic( + json['value'] as List, + json['nullable'] as List, + ); +} + +Map _$SimpleClassDynamicToJson(SimpleClassDynamic instance) => + { + 'value': instance.value, + 'nullable': instance.nullable, + }; + +SimpleClassNum _$SimpleClassNumFromJson(Map json) { + return SimpleClassNum( + (json['value'] as List)?.map((e) => e as num)?.toList(), + (json['nullable'] as List).map((e) => e as num).toList(), + ); +} + +Map _$SimpleClassNumToJson(SimpleClassNum instance) => + { + 'value': instance.value, + 'nullable': instance.nullable, + }; + +SimpleClassObject _$SimpleClassObjectFromJson(Map json) { + return SimpleClassObject( + json['value'] as List, + json['nullable'] as List, + ); +} + +Map _$SimpleClassObjectToJson(SimpleClassObject instance) => + { + 'value': instance.value, + 'nullable': instance.nullable, + }; + +SimpleClassString _$SimpleClassStringFromJson(Map json) { + return SimpleClassString( + (json['value'] as List)?.map((e) => e as String)?.toList(), + (json['nullable'] as List).map((e) => e as String).toList(), + ); +} + +Map _$SimpleClassStringToJson(SimpleClassString instance) => + { + 'value': instance.value, + 'nullable': instance.nullable, + }; + +SimpleClassUri _$SimpleClassUriFromJson(Map json) { + return SimpleClassUri( + (json['value'] as List) + ?.map((e) => e == null ? null : Uri.parse(e as String)) + ?.toList(), + (json['nullable'] as List).map((e) => Uri.parse(e as String)).toList(), + ); +} + +Map _$SimpleClassUriToJson(SimpleClassUri instance) => + { + 'value': instance.value?.map((e) => e?.toString())?.toList(), + 'nullable': instance.nullable.map((e) => e.toString()).toList(), + }; diff --git a/json_serializable/test/supported_types/input.type_map.dart b/json_serializable/test/supported_types/input.type_map.dart index be8bab47f..fc9e4fdcd 100644 --- a/json_serializable/test/supported_types/input.type_map.dart +++ b/json_serializable/test/supported_types/input.type_map.dart @@ -26,3 +26,1263 @@ class SimpleClass { Map toJson() => _$SimpleClassToJson(this); } + +@JsonSerializable() +class SimpleClassBigIntToBigInt { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassBigIntToBigInt( + this.value, + this.nullable, + ); + + factory SimpleClassBigIntToBigInt.fromJson(Map json) => + _$SimpleClassBigIntToBigIntFromJson(json); + + Map toJson() => _$SimpleClassBigIntToBigIntToJson(this); +} + +@JsonSerializable() +class SimpleClassDateTimeToBigInt { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassDateTimeToBigInt( + this.value, + this.nullable, + ); + + factory SimpleClassDateTimeToBigInt.fromJson(Map json) => + _$SimpleClassDateTimeToBigIntFromJson(json); + + Map toJson() => _$SimpleClassDateTimeToBigIntToJson(this); +} + +@JsonSerializable() +class SimpleClassDynamicToBigInt { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassDynamicToBigInt( + this.value, + this.nullable, + ); + + factory SimpleClassDynamicToBigInt.fromJson(Map json) => + _$SimpleClassDynamicToBigIntFromJson(json); + + Map toJson() => _$SimpleClassDynamicToBigIntToJson(this); +} + +@JsonSerializable() +class SimpleClassIntToBigInt { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassIntToBigInt( + this.value, + this.nullable, + ); + + factory SimpleClassIntToBigInt.fromJson(Map json) => + _$SimpleClassIntToBigIntFromJson(json); + + Map toJson() => _$SimpleClassIntToBigIntToJson(this); +} + +@JsonSerializable() +class SimpleClassObjectToBigInt { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassObjectToBigInt( + this.value, + this.nullable, + ); + + factory SimpleClassObjectToBigInt.fromJson(Map json) => + _$SimpleClassObjectToBigIntFromJson(json); + + Map toJson() => _$SimpleClassObjectToBigIntToJson(this); +} + +@JsonSerializable() +class SimpleClassStringToBigInt { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassStringToBigInt( + this.value, + this.nullable, + ); + + factory SimpleClassStringToBigInt.fromJson(Map json) => + _$SimpleClassStringToBigIntFromJson(json); + + Map toJson() => _$SimpleClassStringToBigIntToJson(this); +} + +@JsonSerializable() +class SimpleClassUriToBigInt { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassUriToBigInt( + this.value, + this.nullable, + ); + + factory SimpleClassUriToBigInt.fromJson(Map json) => + _$SimpleClassUriToBigIntFromJson(json); + + Map toJson() => _$SimpleClassUriToBigIntToJson(this); +} + +@JsonSerializable() +class SimpleClassBigIntToBool { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassBigIntToBool( + this.value, + this.nullable, + ); + + factory SimpleClassBigIntToBool.fromJson(Map json) => + _$SimpleClassBigIntToBoolFromJson(json); + + Map toJson() => _$SimpleClassBigIntToBoolToJson(this); +} + +@JsonSerializable() +class SimpleClassDateTimeToBool { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassDateTimeToBool( + this.value, + this.nullable, + ); + + factory SimpleClassDateTimeToBool.fromJson(Map json) => + _$SimpleClassDateTimeToBoolFromJson(json); + + Map toJson() => _$SimpleClassDateTimeToBoolToJson(this); +} + +@JsonSerializable() +class SimpleClassDynamicToBool { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassDynamicToBool( + this.value, + this.nullable, + ); + + factory SimpleClassDynamicToBool.fromJson(Map json) => + _$SimpleClassDynamicToBoolFromJson(json); + + Map toJson() => _$SimpleClassDynamicToBoolToJson(this); +} + +@JsonSerializable() +class SimpleClassIntToBool { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassIntToBool( + this.value, + this.nullable, + ); + + factory SimpleClassIntToBool.fromJson(Map json) => + _$SimpleClassIntToBoolFromJson(json); + + Map toJson() => _$SimpleClassIntToBoolToJson(this); +} + +@JsonSerializable() +class SimpleClassObjectToBool { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassObjectToBool( + this.value, + this.nullable, + ); + + factory SimpleClassObjectToBool.fromJson(Map json) => + _$SimpleClassObjectToBoolFromJson(json); + + Map toJson() => _$SimpleClassObjectToBoolToJson(this); +} + +@JsonSerializable() +class SimpleClassStringToBool { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassStringToBool( + this.value, + this.nullable, + ); + + factory SimpleClassStringToBool.fromJson(Map json) => + _$SimpleClassStringToBoolFromJson(json); + + Map toJson() => _$SimpleClassStringToBoolToJson(this); +} + +@JsonSerializable() +class SimpleClassUriToBool { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassUriToBool( + this.value, + this.nullable, + ); + + factory SimpleClassUriToBool.fromJson(Map json) => + _$SimpleClassUriToBoolFromJson(json); + + Map toJson() => _$SimpleClassUriToBoolToJson(this); +} + +@JsonSerializable() +class SimpleClassBigIntToDateTime { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassBigIntToDateTime( + this.value, + this.nullable, + ); + + factory SimpleClassBigIntToDateTime.fromJson(Map json) => + _$SimpleClassBigIntToDateTimeFromJson(json); + + Map toJson() => _$SimpleClassBigIntToDateTimeToJson(this); +} + +@JsonSerializable() +class SimpleClassDateTimeToDateTime { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassDateTimeToDateTime( + this.value, + this.nullable, + ); + + factory SimpleClassDateTimeToDateTime.fromJson(Map json) => + _$SimpleClassDateTimeToDateTimeFromJson(json); + + Map toJson() => _$SimpleClassDateTimeToDateTimeToJson(this); +} + +@JsonSerializable() +class SimpleClassDynamicToDateTime { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassDynamicToDateTime( + this.value, + this.nullable, + ); + + factory SimpleClassDynamicToDateTime.fromJson(Map json) => + _$SimpleClassDynamicToDateTimeFromJson(json); + + Map toJson() => _$SimpleClassDynamicToDateTimeToJson(this); +} + +@JsonSerializable() +class SimpleClassIntToDateTime { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassIntToDateTime( + this.value, + this.nullable, + ); + + factory SimpleClassIntToDateTime.fromJson(Map json) => + _$SimpleClassIntToDateTimeFromJson(json); + + Map toJson() => _$SimpleClassIntToDateTimeToJson(this); +} + +@JsonSerializable() +class SimpleClassObjectToDateTime { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassObjectToDateTime( + this.value, + this.nullable, + ); + + factory SimpleClassObjectToDateTime.fromJson(Map json) => + _$SimpleClassObjectToDateTimeFromJson(json); + + Map toJson() => _$SimpleClassObjectToDateTimeToJson(this); +} + +@JsonSerializable() +class SimpleClassStringToDateTime { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassStringToDateTime( + this.value, + this.nullable, + ); + + factory SimpleClassStringToDateTime.fromJson(Map json) => + _$SimpleClassStringToDateTimeFromJson(json); + + Map toJson() => _$SimpleClassStringToDateTimeToJson(this); +} + +@JsonSerializable() +class SimpleClassUriToDateTime { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassUriToDateTime( + this.value, + this.nullable, + ); + + factory SimpleClassUriToDateTime.fromJson(Map json) => + _$SimpleClassUriToDateTimeFromJson(json); + + Map toJson() => _$SimpleClassUriToDateTimeToJson(this); +} + +@JsonSerializable() +class SimpleClassBigIntToDouble { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassBigIntToDouble( + this.value, + this.nullable, + ); + + factory SimpleClassBigIntToDouble.fromJson(Map json) => + _$SimpleClassBigIntToDoubleFromJson(json); + + Map toJson() => _$SimpleClassBigIntToDoubleToJson(this); +} + +@JsonSerializable() +class SimpleClassDateTimeToDouble { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassDateTimeToDouble( + this.value, + this.nullable, + ); + + factory SimpleClassDateTimeToDouble.fromJson(Map json) => + _$SimpleClassDateTimeToDoubleFromJson(json); + + Map toJson() => _$SimpleClassDateTimeToDoubleToJson(this); +} + +@JsonSerializable() +class SimpleClassDynamicToDouble { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassDynamicToDouble( + this.value, + this.nullable, + ); + + factory SimpleClassDynamicToDouble.fromJson(Map json) => + _$SimpleClassDynamicToDoubleFromJson(json); + + Map toJson() => _$SimpleClassDynamicToDoubleToJson(this); +} + +@JsonSerializable() +class SimpleClassIntToDouble { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassIntToDouble( + this.value, + this.nullable, + ); + + factory SimpleClassIntToDouble.fromJson(Map json) => + _$SimpleClassIntToDoubleFromJson(json); + + Map toJson() => _$SimpleClassIntToDoubleToJson(this); +} + +@JsonSerializable() +class SimpleClassObjectToDouble { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassObjectToDouble( + this.value, + this.nullable, + ); + + factory SimpleClassObjectToDouble.fromJson(Map json) => + _$SimpleClassObjectToDoubleFromJson(json); + + Map toJson() => _$SimpleClassObjectToDoubleToJson(this); +} + +@JsonSerializable() +class SimpleClassStringToDouble { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassStringToDouble( + this.value, + this.nullable, + ); + + factory SimpleClassStringToDouble.fromJson(Map json) => + _$SimpleClassStringToDoubleFromJson(json); + + Map toJson() => _$SimpleClassStringToDoubleToJson(this); +} + +@JsonSerializable() +class SimpleClassUriToDouble { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassUriToDouble( + this.value, + this.nullable, + ); + + factory SimpleClassUriToDouble.fromJson(Map json) => + _$SimpleClassUriToDoubleFromJson(json); + + Map toJson() => _$SimpleClassUriToDoubleToJson(this); +} + +@JsonSerializable() +class SimpleClassBigIntToDuration { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassBigIntToDuration( + this.value, + this.nullable, + ); + + factory SimpleClassBigIntToDuration.fromJson(Map json) => + _$SimpleClassBigIntToDurationFromJson(json); + + Map toJson() => _$SimpleClassBigIntToDurationToJson(this); +} + +@JsonSerializable() +class SimpleClassDateTimeToDuration { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassDateTimeToDuration( + this.value, + this.nullable, + ); + + factory SimpleClassDateTimeToDuration.fromJson(Map json) => + _$SimpleClassDateTimeToDurationFromJson(json); + + Map toJson() => _$SimpleClassDateTimeToDurationToJson(this); +} + +@JsonSerializable() +class SimpleClassDynamicToDuration { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassDynamicToDuration( + this.value, + this.nullable, + ); + + factory SimpleClassDynamicToDuration.fromJson(Map json) => + _$SimpleClassDynamicToDurationFromJson(json); + + Map toJson() => _$SimpleClassDynamicToDurationToJson(this); +} + +@JsonSerializable() +class SimpleClassIntToDuration { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassIntToDuration( + this.value, + this.nullable, + ); + + factory SimpleClassIntToDuration.fromJson(Map json) => + _$SimpleClassIntToDurationFromJson(json); + + Map toJson() => _$SimpleClassIntToDurationToJson(this); +} + +@JsonSerializable() +class SimpleClassObjectToDuration { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassObjectToDuration( + this.value, + this.nullable, + ); + + factory SimpleClassObjectToDuration.fromJson(Map json) => + _$SimpleClassObjectToDurationFromJson(json); + + Map toJson() => _$SimpleClassObjectToDurationToJson(this); +} + +@JsonSerializable() +class SimpleClassStringToDuration { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassStringToDuration( + this.value, + this.nullable, + ); + + factory SimpleClassStringToDuration.fromJson(Map json) => + _$SimpleClassStringToDurationFromJson(json); + + Map toJson() => _$SimpleClassStringToDurationToJson(this); +} + +@JsonSerializable() +class SimpleClassUriToDuration { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassUriToDuration( + this.value, + this.nullable, + ); + + factory SimpleClassUriToDuration.fromJson(Map json) => + _$SimpleClassUriToDurationFromJson(json); + + Map toJson() => _$SimpleClassUriToDurationToJson(this); +} + +@JsonSerializable() +class SimpleClassBigIntToDynamic { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassBigIntToDynamic( + this.value, + this.nullable, + ); + + factory SimpleClassBigIntToDynamic.fromJson(Map json) => + _$SimpleClassBigIntToDynamicFromJson(json); + + Map toJson() => _$SimpleClassBigIntToDynamicToJson(this); +} + +@JsonSerializable() +class SimpleClassDateTimeToDynamic { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassDateTimeToDynamic( + this.value, + this.nullable, + ); + + factory SimpleClassDateTimeToDynamic.fromJson(Map json) => + _$SimpleClassDateTimeToDynamicFromJson(json); + + Map toJson() => _$SimpleClassDateTimeToDynamicToJson(this); +} + +@JsonSerializable() +class SimpleClassDynamicToDynamic { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassDynamicToDynamic( + this.value, + this.nullable, + ); + + factory SimpleClassDynamicToDynamic.fromJson(Map json) => + _$SimpleClassDynamicToDynamicFromJson(json); + + Map toJson() => _$SimpleClassDynamicToDynamicToJson(this); +} + +@JsonSerializable() +class SimpleClassIntToDynamic { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassIntToDynamic( + this.value, + this.nullable, + ); + + factory SimpleClassIntToDynamic.fromJson(Map json) => + _$SimpleClassIntToDynamicFromJson(json); + + Map toJson() => _$SimpleClassIntToDynamicToJson(this); +} + +@JsonSerializable() +class SimpleClassObjectToDynamic { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassObjectToDynamic( + this.value, + this.nullable, + ); + + factory SimpleClassObjectToDynamic.fromJson(Map json) => + _$SimpleClassObjectToDynamicFromJson(json); + + Map toJson() => _$SimpleClassObjectToDynamicToJson(this); +} + +@JsonSerializable() +class SimpleClassStringToDynamic { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassStringToDynamic( + this.value, + this.nullable, + ); + + factory SimpleClassStringToDynamic.fromJson(Map json) => + _$SimpleClassStringToDynamicFromJson(json); + + Map toJson() => _$SimpleClassStringToDynamicToJson(this); +} + +@JsonSerializable() +class SimpleClassUriToDynamic { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassUriToDynamic( + this.value, + this.nullable, + ); + + factory SimpleClassUriToDynamic.fromJson(Map json) => + _$SimpleClassUriToDynamicFromJson(json); + + Map toJson() => _$SimpleClassUriToDynamicToJson(this); +} + +@JsonSerializable() +class SimpleClassBigIntToNum { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassBigIntToNum( + this.value, + this.nullable, + ); + + factory SimpleClassBigIntToNum.fromJson(Map json) => + _$SimpleClassBigIntToNumFromJson(json); + + Map toJson() => _$SimpleClassBigIntToNumToJson(this); +} + +@JsonSerializable() +class SimpleClassDateTimeToNum { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassDateTimeToNum( + this.value, + this.nullable, + ); + + factory SimpleClassDateTimeToNum.fromJson(Map json) => + _$SimpleClassDateTimeToNumFromJson(json); + + Map toJson() => _$SimpleClassDateTimeToNumToJson(this); +} + +@JsonSerializable() +class SimpleClassDynamicToNum { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassDynamicToNum( + this.value, + this.nullable, + ); + + factory SimpleClassDynamicToNum.fromJson(Map json) => + _$SimpleClassDynamicToNumFromJson(json); + + Map toJson() => _$SimpleClassDynamicToNumToJson(this); +} + +@JsonSerializable() +class SimpleClassIntToNum { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassIntToNum( + this.value, + this.nullable, + ); + + factory SimpleClassIntToNum.fromJson(Map json) => + _$SimpleClassIntToNumFromJson(json); + + Map toJson() => _$SimpleClassIntToNumToJson(this); +} + +@JsonSerializable() +class SimpleClassObjectToNum { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassObjectToNum( + this.value, + this.nullable, + ); + + factory SimpleClassObjectToNum.fromJson(Map json) => + _$SimpleClassObjectToNumFromJson(json); + + Map toJson() => _$SimpleClassObjectToNumToJson(this); +} + +@JsonSerializable() +class SimpleClassStringToNum { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassStringToNum( + this.value, + this.nullable, + ); + + factory SimpleClassStringToNum.fromJson(Map json) => + _$SimpleClassStringToNumFromJson(json); + + Map toJson() => _$SimpleClassStringToNumToJson(this); +} + +@JsonSerializable() +class SimpleClassUriToNum { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassUriToNum( + this.value, + this.nullable, + ); + + factory SimpleClassUriToNum.fromJson(Map json) => + _$SimpleClassUriToNumFromJson(json); + + Map toJson() => _$SimpleClassUriToNumToJson(this); +} + +@JsonSerializable() +class SimpleClassBigIntToObject { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassBigIntToObject( + this.value, + this.nullable, + ); + + factory SimpleClassBigIntToObject.fromJson(Map json) => + _$SimpleClassBigIntToObjectFromJson(json); + + Map toJson() => _$SimpleClassBigIntToObjectToJson(this); +} + +@JsonSerializable() +class SimpleClassDateTimeToObject { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassDateTimeToObject( + this.value, + this.nullable, + ); + + factory SimpleClassDateTimeToObject.fromJson(Map json) => + _$SimpleClassDateTimeToObjectFromJson(json); + + Map toJson() => _$SimpleClassDateTimeToObjectToJson(this); +} + +@JsonSerializable() +class SimpleClassDynamicToObject { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassDynamicToObject( + this.value, + this.nullable, + ); + + factory SimpleClassDynamicToObject.fromJson(Map json) => + _$SimpleClassDynamicToObjectFromJson(json); + + Map toJson() => _$SimpleClassDynamicToObjectToJson(this); +} + +@JsonSerializable() +class SimpleClassIntToObject { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassIntToObject( + this.value, + this.nullable, + ); + + factory SimpleClassIntToObject.fromJson(Map json) => + _$SimpleClassIntToObjectFromJson(json); + + Map toJson() => _$SimpleClassIntToObjectToJson(this); +} + +@JsonSerializable() +class SimpleClassObjectToObject { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassObjectToObject( + this.value, + this.nullable, + ); + + factory SimpleClassObjectToObject.fromJson(Map json) => + _$SimpleClassObjectToObjectFromJson(json); + + Map toJson() => _$SimpleClassObjectToObjectToJson(this); +} + +@JsonSerializable() +class SimpleClassStringToObject { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassStringToObject( + this.value, + this.nullable, + ); + + factory SimpleClassStringToObject.fromJson(Map json) => + _$SimpleClassStringToObjectFromJson(json); + + Map toJson() => _$SimpleClassStringToObjectToJson(this); +} + +@JsonSerializable() +class SimpleClassUriToObject { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassUriToObject( + this.value, + this.nullable, + ); + + factory SimpleClassUriToObject.fromJson(Map json) => + _$SimpleClassUriToObjectFromJson(json); + + Map toJson() => _$SimpleClassUriToObjectToJson(this); +} + +@JsonSerializable() +class SimpleClassBigIntToString { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassBigIntToString( + this.value, + this.nullable, + ); + + factory SimpleClassBigIntToString.fromJson(Map json) => + _$SimpleClassBigIntToStringFromJson(json); + + Map toJson() => _$SimpleClassBigIntToStringToJson(this); +} + +@JsonSerializable() +class SimpleClassDateTimeToString { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassDateTimeToString( + this.value, + this.nullable, + ); + + factory SimpleClassDateTimeToString.fromJson(Map json) => + _$SimpleClassDateTimeToStringFromJson(json); + + Map toJson() => _$SimpleClassDateTimeToStringToJson(this); +} + +@JsonSerializable() +class SimpleClassDynamicToString { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassDynamicToString( + this.value, + this.nullable, + ); + + factory SimpleClassDynamicToString.fromJson(Map json) => + _$SimpleClassDynamicToStringFromJson(json); + + Map toJson() => _$SimpleClassDynamicToStringToJson(this); +} + +@JsonSerializable() +class SimpleClassIntToString { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassIntToString( + this.value, + this.nullable, + ); + + factory SimpleClassIntToString.fromJson(Map json) => + _$SimpleClassIntToStringFromJson(json); + + Map toJson() => _$SimpleClassIntToStringToJson(this); +} + +@JsonSerializable() +class SimpleClassObjectToString { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassObjectToString( + this.value, + this.nullable, + ); + + factory SimpleClassObjectToString.fromJson(Map json) => + _$SimpleClassObjectToStringFromJson(json); + + Map toJson() => _$SimpleClassObjectToStringToJson(this); +} + +@JsonSerializable() +class SimpleClassStringToString { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassStringToString( + this.value, + this.nullable, + ); + + factory SimpleClassStringToString.fromJson(Map json) => + _$SimpleClassStringToStringFromJson(json); + + Map toJson() => _$SimpleClassStringToStringToJson(this); +} + +@JsonSerializable() +class SimpleClassUriToString { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassUriToString( + this.value, + this.nullable, + ); + + factory SimpleClassUriToString.fromJson(Map json) => + _$SimpleClassUriToStringFromJson(json); + + Map toJson() => _$SimpleClassUriToStringToJson(this); +} + +@JsonSerializable() +class SimpleClassBigIntToUri { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassBigIntToUri( + this.value, + this.nullable, + ); + + factory SimpleClassBigIntToUri.fromJson(Map json) => + _$SimpleClassBigIntToUriFromJson(json); + + Map toJson() => _$SimpleClassBigIntToUriToJson(this); +} + +@JsonSerializable() +class SimpleClassDateTimeToUri { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassDateTimeToUri( + this.value, + this.nullable, + ); + + factory SimpleClassDateTimeToUri.fromJson(Map json) => + _$SimpleClassDateTimeToUriFromJson(json); + + Map toJson() => _$SimpleClassDateTimeToUriToJson(this); +} + +@JsonSerializable() +class SimpleClassDynamicToUri { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassDynamicToUri( + this.value, + this.nullable, + ); + + factory SimpleClassDynamicToUri.fromJson(Map json) => + _$SimpleClassDynamicToUriFromJson(json); + + Map toJson() => _$SimpleClassDynamicToUriToJson(this); +} + +@JsonSerializable() +class SimpleClassIntToUri { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassIntToUri( + this.value, + this.nullable, + ); + + factory SimpleClassIntToUri.fromJson(Map json) => + _$SimpleClassIntToUriFromJson(json); + + Map toJson() => _$SimpleClassIntToUriToJson(this); +} + +@JsonSerializable() +class SimpleClassObjectToUri { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassObjectToUri( + this.value, + this.nullable, + ); + + factory SimpleClassObjectToUri.fromJson(Map json) => + _$SimpleClassObjectToUriFromJson(json); + + Map toJson() => _$SimpleClassObjectToUriToJson(this); +} + +@JsonSerializable() +class SimpleClassStringToUri { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassStringToUri( + this.value, + this.nullable, + ); + + factory SimpleClassStringToUri.fromJson(Map json) => + _$SimpleClassStringToUriFromJson(json); + + Map toJson() => _$SimpleClassStringToUriToJson(this); +} + +@JsonSerializable() +class SimpleClassUriToUri { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassUriToUri( + this.value, + this.nullable, + ); + + factory SimpleClassUriToUri.fromJson(Map json) => + _$SimpleClassUriToUriFromJson(json); + + Map toJson() => _$SimpleClassUriToUriToJson(this); +} diff --git a/json_serializable/test/supported_types/input.type_map.g.dart b/json_serializable/test/supported_types/input.type_map.g.dart index beb8e44b8..324c36974 100644 --- a/json_serializable/test/supported_types/input.type_map.g.dart +++ b/json_serializable/test/supported_types/input.type_map.g.dart @@ -19,3 +19,1342 @@ Map _$SimpleClassToJson(SimpleClass instance) => 'nullable': instance.nullable, 'withDefault': instance.withDefault, }; + +SimpleClassBigIntToBigInt _$SimpleClassBigIntToBigIntFromJson( + Map json) { + return SimpleClassBigIntToBigInt( + (json['value'] as Map)?.map( + (k, e) => MapEntry( + BigInt.parse(k), e == null ? null : BigInt.parse(e as String)), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(BigInt.parse(k), BigInt.parse(e as String)), + ), + ); +} + +Map _$SimpleClassBigIntToBigIntToJson( + SimpleClassBigIntToBigInt instance) => + { + 'value': + instance.value?.map((k, e) => MapEntry(k.toString(), e?.toString())), + 'nullable': + instance.nullable.map((k, e) => MapEntry(k.toString(), e.toString())), + }; + +SimpleClassDateTimeToBigInt _$SimpleClassDateTimeToBigIntFromJson( + Map json) { + return SimpleClassDateTimeToBigInt( + (json['value'] as Map)?.map( + (k, e) => MapEntry( + DateTime.parse(k), e == null ? null : BigInt.parse(e as String)), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(DateTime.parse(k), BigInt.parse(e as String)), + ), + ); +} + +Map _$SimpleClassDateTimeToBigIntToJson( + SimpleClassDateTimeToBigInt instance) => + { + 'value': instance.value + ?.map((k, e) => MapEntry(k.toIso8601String(), e?.toString())), + 'nullable': instance.nullable + .map((k, e) => MapEntry(k.toIso8601String(), e.toString())), + }; + +SimpleClassDynamicToBigInt _$SimpleClassDynamicToBigIntFromJson( + Map json) { + return SimpleClassDynamicToBigInt( + (json['value'] as Map)?.map( + (k, e) => MapEntry(k, e == null ? null : BigInt.parse(e as String)), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(k, BigInt.parse(e as String)), + ), + ); +} + +Map _$SimpleClassDynamicToBigIntToJson( + SimpleClassDynamicToBigInt instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k, e?.toString())), + 'nullable': instance.nullable.map((k, e) => MapEntry(k, e.toString())), + }; + +SimpleClassIntToBigInt _$SimpleClassIntToBigIntFromJson( + Map json) { + return SimpleClassIntToBigInt( + (json['value'] as Map)?.map( + (k, e) => + MapEntry(int.parse(k), e == null ? null : BigInt.parse(e as String)), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(int.parse(k), BigInt.parse(e as String)), + ), + ); +} + +Map _$SimpleClassIntToBigIntToJson( + SimpleClassIntToBigInt instance) => + { + 'value': + instance.value?.map((k, e) => MapEntry(k.toString(), e?.toString())), + 'nullable': + instance.nullable.map((k, e) => MapEntry(k.toString(), e.toString())), + }; + +SimpleClassObjectToBigInt _$SimpleClassObjectToBigIntFromJson( + Map json) { + return SimpleClassObjectToBigInt( + (json['value'] as Map)?.map( + (k, e) => MapEntry(k, e == null ? null : BigInt.parse(e as String)), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(k, BigInt.parse(e as String)), + ), + ); +} + +Map _$SimpleClassObjectToBigIntToJson( + SimpleClassObjectToBigInt instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k, e?.toString())), + 'nullable': instance.nullable.map((k, e) => MapEntry(k, e.toString())), + }; + +SimpleClassStringToBigInt _$SimpleClassStringToBigIntFromJson( + Map json) { + return SimpleClassStringToBigInt( + (json['value'] as Map)?.map( + (k, e) => MapEntry(k, e == null ? null : BigInt.parse(e as String)), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(k, BigInt.parse(e as String)), + ), + ); +} + +Map _$SimpleClassStringToBigIntToJson( + SimpleClassStringToBigInt instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k, e?.toString())), + 'nullable': instance.nullable.map((k, e) => MapEntry(k, e.toString())), + }; + +SimpleClassUriToBigInt _$SimpleClassUriToBigIntFromJson( + Map json) { + return SimpleClassUriToBigInt( + (json['value'] as Map)?.map( + (k, e) => + MapEntry(Uri.parse(k), e == null ? null : BigInt.parse(e as String)), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(Uri.parse(k), BigInt.parse(e as String)), + ), + ); +} + +Map _$SimpleClassUriToBigIntToJson( + SimpleClassUriToBigInt instance) => + { + 'value': + instance.value?.map((k, e) => MapEntry(k.toString(), e?.toString())), + 'nullable': + instance.nullable.map((k, e) => MapEntry(k.toString(), e.toString())), + }; + +SimpleClassBigIntToBool _$SimpleClassBigIntToBoolFromJson( + Map json) { + return SimpleClassBigIntToBool( + (json['value'] as Map)?.map( + (k, e) => MapEntry(BigInt.parse(k), e as bool), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(BigInt.parse(k), e as bool), + ), + ); +} + +Map _$SimpleClassBigIntToBoolToJson( + SimpleClassBigIntToBool instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), + 'nullable': instance.nullable.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassDateTimeToBool _$SimpleClassDateTimeToBoolFromJson( + Map json) { + return SimpleClassDateTimeToBool( + (json['value'] as Map)?.map( + (k, e) => MapEntry(DateTime.parse(k), e as bool), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(DateTime.parse(k), e as bool), + ), + ); +} + +Map _$SimpleClassDateTimeToBoolToJson( + SimpleClassDateTimeToBool instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k.toIso8601String(), e)), + 'nullable': + instance.nullable.map((k, e) => MapEntry(k.toIso8601String(), e)), + }; + +SimpleClassDynamicToBool _$SimpleClassDynamicToBoolFromJson( + Map json) { + return SimpleClassDynamicToBool( + (json['value'] as Map)?.map( + (k, e) => MapEntry(k, e as bool), + ), + Map.from(json['nullable'] as Map), + ); +} + +Map _$SimpleClassDynamicToBoolToJson( + SimpleClassDynamicToBool instance) => + { + 'value': instance.value, + 'nullable': instance.nullable, + }; + +SimpleClassIntToBool _$SimpleClassIntToBoolFromJson(Map json) { + return SimpleClassIntToBool( + (json['value'] as Map)?.map( + (k, e) => MapEntry(int.parse(k), e as bool), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(int.parse(k), e as bool), + ), + ); +} + +Map _$SimpleClassIntToBoolToJson( + SimpleClassIntToBool instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), + 'nullable': instance.nullable.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassObjectToBool _$SimpleClassObjectToBoolFromJson( + Map json) { + return SimpleClassObjectToBool( + (json['value'] as Map)?.map( + (k, e) => MapEntry(k, e as bool), + ), + Map.from(json['nullable'] as Map), + ); +} + +Map _$SimpleClassObjectToBoolToJson( + SimpleClassObjectToBool instance) => + { + 'value': instance.value, + 'nullable': instance.nullable, + }; + +SimpleClassStringToBool _$SimpleClassStringToBoolFromJson( + Map json) { + return SimpleClassStringToBool( + (json['value'] as Map)?.map( + (k, e) => MapEntry(k, e as bool), + ), + Map.from(json['nullable'] as Map), + ); +} + +Map _$SimpleClassStringToBoolToJson( + SimpleClassStringToBool instance) => + { + 'value': instance.value, + 'nullable': instance.nullable, + }; + +SimpleClassUriToBool _$SimpleClassUriToBoolFromJson(Map json) { + return SimpleClassUriToBool( + (json['value'] as Map)?.map( + (k, e) => MapEntry(Uri.parse(k), e as bool), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(Uri.parse(k), e as bool), + ), + ); +} + +Map _$SimpleClassUriToBoolToJson( + SimpleClassUriToBool instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), + 'nullable': instance.nullable.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassBigIntToDateTime _$SimpleClassBigIntToDateTimeFromJson( + Map json) { + return SimpleClassBigIntToDateTime( + (json['value'] as Map)?.map( + (k, e) => MapEntry( + BigInt.parse(k), e == null ? null : DateTime.parse(e as String)), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(BigInt.parse(k), DateTime.parse(e as String)), + ), + ); +} + +Map _$SimpleClassBigIntToDateTimeToJson( + SimpleClassBigIntToDateTime instance) => + { + 'value': instance.value + ?.map((k, e) => MapEntry(k.toString(), e?.toIso8601String())), + 'nullable': instance.nullable + .map((k, e) => MapEntry(k.toString(), e.toIso8601String())), + }; + +SimpleClassDateTimeToDateTime _$SimpleClassDateTimeToDateTimeFromJson( + Map json) { + return SimpleClassDateTimeToDateTime( + (json['value'] as Map)?.map( + (k, e) => MapEntry( + DateTime.parse(k), e == null ? null : DateTime.parse(e as String)), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(DateTime.parse(k), DateTime.parse(e as String)), + ), + ); +} + +Map _$SimpleClassDateTimeToDateTimeToJson( + SimpleClassDateTimeToDateTime instance) => + { + 'value': instance.value + ?.map((k, e) => MapEntry(k.toIso8601String(), e?.toIso8601String())), + 'nullable': instance.nullable + .map((k, e) => MapEntry(k.toIso8601String(), e.toIso8601String())), + }; + +SimpleClassDynamicToDateTime _$SimpleClassDynamicToDateTimeFromJson( + Map json) { + return SimpleClassDynamicToDateTime( + (json['value'] as Map)?.map( + (k, e) => MapEntry(k, e == null ? null : DateTime.parse(e as String)), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(k, DateTime.parse(e as String)), + ), + ); +} + +Map _$SimpleClassDynamicToDateTimeToJson( + SimpleClassDynamicToDateTime instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k, e?.toIso8601String())), + 'nullable': + instance.nullable.map((k, e) => MapEntry(k, e.toIso8601String())), + }; + +SimpleClassIntToDateTime _$SimpleClassIntToDateTimeFromJson( + Map json) { + return SimpleClassIntToDateTime( + (json['value'] as Map)?.map( + (k, e) => MapEntry( + int.parse(k), e == null ? null : DateTime.parse(e as String)), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(int.parse(k), DateTime.parse(e as String)), + ), + ); +} + +Map _$SimpleClassIntToDateTimeToJson( + SimpleClassIntToDateTime instance) => + { + 'value': instance.value + ?.map((k, e) => MapEntry(k.toString(), e?.toIso8601String())), + 'nullable': instance.nullable + .map((k, e) => MapEntry(k.toString(), e.toIso8601String())), + }; + +SimpleClassObjectToDateTime _$SimpleClassObjectToDateTimeFromJson( + Map json) { + return SimpleClassObjectToDateTime( + (json['value'] as Map)?.map( + (k, e) => MapEntry(k, e == null ? null : DateTime.parse(e as String)), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(k, DateTime.parse(e as String)), + ), + ); +} + +Map _$SimpleClassObjectToDateTimeToJson( + SimpleClassObjectToDateTime instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k, e?.toIso8601String())), + 'nullable': + instance.nullable.map((k, e) => MapEntry(k, e.toIso8601String())), + }; + +SimpleClassStringToDateTime _$SimpleClassStringToDateTimeFromJson( + Map json) { + return SimpleClassStringToDateTime( + (json['value'] as Map)?.map( + (k, e) => MapEntry(k, e == null ? null : DateTime.parse(e as String)), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(k, DateTime.parse(e as String)), + ), + ); +} + +Map _$SimpleClassStringToDateTimeToJson( + SimpleClassStringToDateTime instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k, e?.toIso8601String())), + 'nullable': + instance.nullable.map((k, e) => MapEntry(k, e.toIso8601String())), + }; + +SimpleClassUriToDateTime _$SimpleClassUriToDateTimeFromJson( + Map json) { + return SimpleClassUriToDateTime( + (json['value'] as Map)?.map( + (k, e) => MapEntry( + Uri.parse(k), e == null ? null : DateTime.parse(e as String)), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(Uri.parse(k), DateTime.parse(e as String)), + ), + ); +} + +Map _$SimpleClassUriToDateTimeToJson( + SimpleClassUriToDateTime instance) => + { + 'value': instance.value + ?.map((k, e) => MapEntry(k.toString(), e?.toIso8601String())), + 'nullable': instance.nullable + .map((k, e) => MapEntry(k.toString(), e.toIso8601String())), + }; + +SimpleClassBigIntToDouble _$SimpleClassBigIntToDoubleFromJson( + Map json) { + return SimpleClassBigIntToDouble( + (json['value'] as Map)?.map( + (k, e) => MapEntry(BigInt.parse(k), (e as num)?.toDouble()), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(BigInt.parse(k), (e as num).toDouble()), + ), + ); +} + +Map _$SimpleClassBigIntToDoubleToJson( + SimpleClassBigIntToDouble instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), + 'nullable': instance.nullable.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassDateTimeToDouble _$SimpleClassDateTimeToDoubleFromJson( + Map json) { + return SimpleClassDateTimeToDouble( + (json['value'] as Map)?.map( + (k, e) => MapEntry(DateTime.parse(k), (e as num)?.toDouble()), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(DateTime.parse(k), (e as num).toDouble()), + ), + ); +} + +Map _$SimpleClassDateTimeToDoubleToJson( + SimpleClassDateTimeToDouble instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k.toIso8601String(), e)), + 'nullable': + instance.nullable.map((k, e) => MapEntry(k.toIso8601String(), e)), + }; + +SimpleClassDynamicToDouble _$SimpleClassDynamicToDoubleFromJson( + Map json) { + return SimpleClassDynamicToDouble( + (json['value'] as Map)?.map( + (k, e) => MapEntry(k, (e as num)?.toDouble()), + ), + Map.from(json['nullable'] as Map), + ); +} + +Map _$SimpleClassDynamicToDoubleToJson( + SimpleClassDynamicToDouble instance) => + { + 'value': instance.value, + 'nullable': instance.nullable, + }; + +SimpleClassIntToDouble _$SimpleClassIntToDoubleFromJson( + Map json) { + return SimpleClassIntToDouble( + (json['value'] as Map)?.map( + (k, e) => MapEntry(int.parse(k), (e as num)?.toDouble()), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(int.parse(k), (e as num).toDouble()), + ), + ); +} + +Map _$SimpleClassIntToDoubleToJson( + SimpleClassIntToDouble instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), + 'nullable': instance.nullable.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassObjectToDouble _$SimpleClassObjectToDoubleFromJson( + Map json) { + return SimpleClassObjectToDouble( + (json['value'] as Map)?.map( + (k, e) => MapEntry(k, (e as num)?.toDouble()), + ), + Map.from(json['nullable'] as Map), + ); +} + +Map _$SimpleClassObjectToDoubleToJson( + SimpleClassObjectToDouble instance) => + { + 'value': instance.value, + 'nullable': instance.nullable, + }; + +SimpleClassStringToDouble _$SimpleClassStringToDoubleFromJson( + Map json) { + return SimpleClassStringToDouble( + (json['value'] as Map)?.map( + (k, e) => MapEntry(k, (e as num)?.toDouble()), + ), + Map.from(json['nullable'] as Map), + ); +} + +Map _$SimpleClassStringToDoubleToJson( + SimpleClassStringToDouble instance) => + { + 'value': instance.value, + 'nullable': instance.nullable, + }; + +SimpleClassUriToDouble _$SimpleClassUriToDoubleFromJson( + Map json) { + return SimpleClassUriToDouble( + (json['value'] as Map)?.map( + (k, e) => MapEntry(Uri.parse(k), (e as num)?.toDouble()), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(Uri.parse(k), (e as num).toDouble()), + ), + ); +} + +Map _$SimpleClassUriToDoubleToJson( + SimpleClassUriToDouble instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), + 'nullable': instance.nullable.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassBigIntToDuration _$SimpleClassBigIntToDurationFromJson( + Map json) { + return SimpleClassBigIntToDuration( + (json['value'] as Map)?.map( + (k, e) => MapEntry( + BigInt.parse(k), e == null ? null : Duration(microseconds: e as int)), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(BigInt.parse(k), Duration(microseconds: e as int)), + ), + ); +} + +Map _$SimpleClassBigIntToDurationToJson( + SimpleClassBigIntToDuration instance) => + { + 'value': instance.value + ?.map((k, e) => MapEntry(k.toString(), e?.inMicroseconds)), + 'nullable': instance.nullable + .map((k, e) => MapEntry(k.toString(), e.inMicroseconds)), + }; + +SimpleClassDateTimeToDuration _$SimpleClassDateTimeToDurationFromJson( + Map json) { + return SimpleClassDateTimeToDuration( + (json['value'] as Map)?.map( + (k, e) => MapEntry(DateTime.parse(k), + e == null ? null : Duration(microseconds: e as int)), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(DateTime.parse(k), Duration(microseconds: e as int)), + ), + ); +} + +Map _$SimpleClassDateTimeToDurationToJson( + SimpleClassDateTimeToDuration instance) => + { + 'value': instance.value + ?.map((k, e) => MapEntry(k.toIso8601String(), e?.inMicroseconds)), + 'nullable': instance.nullable + .map((k, e) => MapEntry(k.toIso8601String(), e.inMicroseconds)), + }; + +SimpleClassDynamicToDuration _$SimpleClassDynamicToDurationFromJson( + Map json) { + return SimpleClassDynamicToDuration( + (json['value'] as Map)?.map( + (k, e) => + MapEntry(k, e == null ? null : Duration(microseconds: e as int)), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(k, Duration(microseconds: e as int)), + ), + ); +} + +Map _$SimpleClassDynamicToDurationToJson( + SimpleClassDynamicToDuration instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k, e?.inMicroseconds)), + 'nullable': + instance.nullable.map((k, e) => MapEntry(k, e.inMicroseconds)), + }; + +SimpleClassIntToDuration _$SimpleClassIntToDurationFromJson( + Map json) { + return SimpleClassIntToDuration( + (json['value'] as Map)?.map( + (k, e) => MapEntry( + int.parse(k), e == null ? null : Duration(microseconds: e as int)), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(int.parse(k), Duration(microseconds: e as int)), + ), + ); +} + +Map _$SimpleClassIntToDurationToJson( + SimpleClassIntToDuration instance) => + { + 'value': instance.value + ?.map((k, e) => MapEntry(k.toString(), e?.inMicroseconds)), + 'nullable': instance.nullable + .map((k, e) => MapEntry(k.toString(), e.inMicroseconds)), + }; + +SimpleClassObjectToDuration _$SimpleClassObjectToDurationFromJson( + Map json) { + return SimpleClassObjectToDuration( + (json['value'] as Map)?.map( + (k, e) => + MapEntry(k, e == null ? null : Duration(microseconds: e as int)), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(k, Duration(microseconds: e as int)), + ), + ); +} + +Map _$SimpleClassObjectToDurationToJson( + SimpleClassObjectToDuration instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k, e?.inMicroseconds)), + 'nullable': + instance.nullable.map((k, e) => MapEntry(k, e.inMicroseconds)), + }; + +SimpleClassStringToDuration _$SimpleClassStringToDurationFromJson( + Map json) { + return SimpleClassStringToDuration( + (json['value'] as Map)?.map( + (k, e) => + MapEntry(k, e == null ? null : Duration(microseconds: e as int)), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(k, Duration(microseconds: e as int)), + ), + ); +} + +Map _$SimpleClassStringToDurationToJson( + SimpleClassStringToDuration instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k, e?.inMicroseconds)), + 'nullable': + instance.nullable.map((k, e) => MapEntry(k, e.inMicroseconds)), + }; + +SimpleClassUriToDuration _$SimpleClassUriToDurationFromJson( + Map json) { + return SimpleClassUriToDuration( + (json['value'] as Map)?.map( + (k, e) => MapEntry( + Uri.parse(k), e == null ? null : Duration(microseconds: e as int)), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(Uri.parse(k), Duration(microseconds: e as int)), + ), + ); +} + +Map _$SimpleClassUriToDurationToJson( + SimpleClassUriToDuration instance) => + { + 'value': instance.value + ?.map((k, e) => MapEntry(k.toString(), e?.inMicroseconds)), + 'nullable': instance.nullable + .map((k, e) => MapEntry(k.toString(), e.inMicroseconds)), + }; + +SimpleClassBigIntToDynamic _$SimpleClassBigIntToDynamicFromJson( + Map json) { + return SimpleClassBigIntToDynamic( + (json['value'] as Map)?.map( + (k, e) => MapEntry(BigInt.parse(k), e), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(BigInt.parse(k), e), + ), + ); +} + +Map _$SimpleClassBigIntToDynamicToJson( + SimpleClassBigIntToDynamic instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), + 'nullable': instance.nullable.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassDateTimeToDynamic _$SimpleClassDateTimeToDynamicFromJson( + Map json) { + return SimpleClassDateTimeToDynamic( + (json['value'] as Map)?.map( + (k, e) => MapEntry(DateTime.parse(k), e), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(DateTime.parse(k), e), + ), + ); +} + +Map _$SimpleClassDateTimeToDynamicToJson( + SimpleClassDateTimeToDynamic instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k.toIso8601String(), e)), + 'nullable': + instance.nullable.map((k, e) => MapEntry(k.toIso8601String(), e)), + }; + +SimpleClassDynamicToDynamic _$SimpleClassDynamicToDynamicFromJson( + Map json) { + return SimpleClassDynamicToDynamic( + json['value'] as Map, + json['nullable'] as Map, + ); +} + +Map _$SimpleClassDynamicToDynamicToJson( + SimpleClassDynamicToDynamic instance) => + { + 'value': instance.value, + 'nullable': instance.nullable, + }; + +SimpleClassIntToDynamic _$SimpleClassIntToDynamicFromJson( + Map json) { + return SimpleClassIntToDynamic( + (json['value'] as Map)?.map( + (k, e) => MapEntry(int.parse(k), e), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(int.parse(k), e), + ), + ); +} + +Map _$SimpleClassIntToDynamicToJson( + SimpleClassIntToDynamic instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), + 'nullable': instance.nullable.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassObjectToDynamic _$SimpleClassObjectToDynamicFromJson( + Map json) { + return SimpleClassObjectToDynamic( + json['value'] as Map, + json['nullable'] as Map, + ); +} + +Map _$SimpleClassObjectToDynamicToJson( + SimpleClassObjectToDynamic instance) => + { + 'value': instance.value, + 'nullable': instance.nullable, + }; + +SimpleClassStringToDynamic _$SimpleClassStringToDynamicFromJson( + Map json) { + return SimpleClassStringToDynamic( + json['value'] as Map, + json['nullable'] as Map, + ); +} + +Map _$SimpleClassStringToDynamicToJson( + SimpleClassStringToDynamic instance) => + { + 'value': instance.value, + 'nullable': instance.nullable, + }; + +SimpleClassUriToDynamic _$SimpleClassUriToDynamicFromJson( + Map json) { + return SimpleClassUriToDynamic( + (json['value'] as Map)?.map( + (k, e) => MapEntry(Uri.parse(k), e), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(Uri.parse(k), e), + ), + ); +} + +Map _$SimpleClassUriToDynamicToJson( + SimpleClassUriToDynamic instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), + 'nullable': instance.nullable.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassBigIntToNum _$SimpleClassBigIntToNumFromJson( + Map json) { + return SimpleClassBigIntToNum( + (json['value'] as Map)?.map( + (k, e) => MapEntry(BigInt.parse(k), e as num), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(BigInt.parse(k), e as num), + ), + ); +} + +Map _$SimpleClassBigIntToNumToJson( + SimpleClassBigIntToNum instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), + 'nullable': instance.nullable.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassDateTimeToNum _$SimpleClassDateTimeToNumFromJson( + Map json) { + return SimpleClassDateTimeToNum( + (json['value'] as Map)?.map( + (k, e) => MapEntry(DateTime.parse(k), e as num), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(DateTime.parse(k), e as num), + ), + ); +} + +Map _$SimpleClassDateTimeToNumToJson( + SimpleClassDateTimeToNum instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k.toIso8601String(), e)), + 'nullable': + instance.nullable.map((k, e) => MapEntry(k.toIso8601String(), e)), + }; + +SimpleClassDynamicToNum _$SimpleClassDynamicToNumFromJson( + Map json) { + return SimpleClassDynamicToNum( + (json['value'] as Map)?.map( + (k, e) => MapEntry(k, e as num), + ), + Map.from(json['nullable'] as Map), + ); +} + +Map _$SimpleClassDynamicToNumToJson( + SimpleClassDynamicToNum instance) => + { + 'value': instance.value, + 'nullable': instance.nullable, + }; + +SimpleClassIntToNum _$SimpleClassIntToNumFromJson(Map json) { + return SimpleClassIntToNum( + (json['value'] as Map)?.map( + (k, e) => MapEntry(int.parse(k), e as num), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(int.parse(k), e as num), + ), + ); +} + +Map _$SimpleClassIntToNumToJson( + SimpleClassIntToNum instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), + 'nullable': instance.nullable.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassObjectToNum _$SimpleClassObjectToNumFromJson( + Map json) { + return SimpleClassObjectToNum( + (json['value'] as Map)?.map( + (k, e) => MapEntry(k, e as num), + ), + Map.from(json['nullable'] as Map), + ); +} + +Map _$SimpleClassObjectToNumToJson( + SimpleClassObjectToNum instance) => + { + 'value': instance.value, + 'nullable': instance.nullable, + }; + +SimpleClassStringToNum _$SimpleClassStringToNumFromJson( + Map json) { + return SimpleClassStringToNum( + (json['value'] as Map)?.map( + (k, e) => MapEntry(k, e as num), + ), + Map.from(json['nullable'] as Map), + ); +} + +Map _$SimpleClassStringToNumToJson( + SimpleClassStringToNum instance) => + { + 'value': instance.value, + 'nullable': instance.nullable, + }; + +SimpleClassUriToNum _$SimpleClassUriToNumFromJson(Map json) { + return SimpleClassUriToNum( + (json['value'] as Map)?.map( + (k, e) => MapEntry(Uri.parse(k), e as num), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(Uri.parse(k), e as num), + ), + ); +} + +Map _$SimpleClassUriToNumToJson( + SimpleClassUriToNum instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), + 'nullable': instance.nullable.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassBigIntToObject _$SimpleClassBigIntToObjectFromJson( + Map json) { + return SimpleClassBigIntToObject( + (json['value'] as Map)?.map( + (k, e) => MapEntry(BigInt.parse(k), e), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(BigInt.parse(k), e), + ), + ); +} + +Map _$SimpleClassBigIntToObjectToJson( + SimpleClassBigIntToObject instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), + 'nullable': instance.nullable.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassDateTimeToObject _$SimpleClassDateTimeToObjectFromJson( + Map json) { + return SimpleClassDateTimeToObject( + (json['value'] as Map)?.map( + (k, e) => MapEntry(DateTime.parse(k), e), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(DateTime.parse(k), e), + ), + ); +} + +Map _$SimpleClassDateTimeToObjectToJson( + SimpleClassDateTimeToObject instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k.toIso8601String(), e)), + 'nullable': + instance.nullable.map((k, e) => MapEntry(k.toIso8601String(), e)), + }; + +SimpleClassDynamicToObject _$SimpleClassDynamicToObjectFromJson( + Map json) { + return SimpleClassDynamicToObject( + json['value'] as Map, + json['nullable'] as Map, + ); +} + +Map _$SimpleClassDynamicToObjectToJson( + SimpleClassDynamicToObject instance) => + { + 'value': instance.value, + 'nullable': instance.nullable, + }; + +SimpleClassIntToObject _$SimpleClassIntToObjectFromJson( + Map json) { + return SimpleClassIntToObject( + (json['value'] as Map)?.map( + (k, e) => MapEntry(int.parse(k), e), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(int.parse(k), e), + ), + ); +} + +Map _$SimpleClassIntToObjectToJson( + SimpleClassIntToObject instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), + 'nullable': instance.nullable.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassObjectToObject _$SimpleClassObjectToObjectFromJson( + Map json) { + return SimpleClassObjectToObject( + json['value'] as Map, + json['nullable'] as Map, + ); +} + +Map _$SimpleClassObjectToObjectToJson( + SimpleClassObjectToObject instance) => + { + 'value': instance.value, + 'nullable': instance.nullable, + }; + +SimpleClassStringToObject _$SimpleClassStringToObjectFromJson( + Map json) { + return SimpleClassStringToObject( + json['value'] as Map, + json['nullable'] as Map, + ); +} + +Map _$SimpleClassStringToObjectToJson( + SimpleClassStringToObject instance) => + { + 'value': instance.value, + 'nullable': instance.nullable, + }; + +SimpleClassUriToObject _$SimpleClassUriToObjectFromJson( + Map json) { + return SimpleClassUriToObject( + (json['value'] as Map)?.map( + (k, e) => MapEntry(Uri.parse(k), e), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(Uri.parse(k), e), + ), + ); +} + +Map _$SimpleClassUriToObjectToJson( + SimpleClassUriToObject instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), + 'nullable': instance.nullable.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassBigIntToString _$SimpleClassBigIntToStringFromJson( + Map json) { + return SimpleClassBigIntToString( + (json['value'] as Map)?.map( + (k, e) => MapEntry(BigInt.parse(k), e as String), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(BigInt.parse(k), e as String), + ), + ); +} + +Map _$SimpleClassBigIntToStringToJson( + SimpleClassBigIntToString instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), + 'nullable': instance.nullable.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassDateTimeToString _$SimpleClassDateTimeToStringFromJson( + Map json) { + return SimpleClassDateTimeToString( + (json['value'] as Map)?.map( + (k, e) => MapEntry(DateTime.parse(k), e as String), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(DateTime.parse(k), e as String), + ), + ); +} + +Map _$SimpleClassDateTimeToStringToJson( + SimpleClassDateTimeToString instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k.toIso8601String(), e)), + 'nullable': + instance.nullable.map((k, e) => MapEntry(k.toIso8601String(), e)), + }; + +SimpleClassDynamicToString _$SimpleClassDynamicToStringFromJson( + Map json) { + return SimpleClassDynamicToString( + (json['value'] as Map)?.map( + (k, e) => MapEntry(k, e as String), + ), + Map.from(json['nullable'] as Map), + ); +} + +Map _$SimpleClassDynamicToStringToJson( + SimpleClassDynamicToString instance) => + { + 'value': instance.value, + 'nullable': instance.nullable, + }; + +SimpleClassIntToString _$SimpleClassIntToStringFromJson( + Map json) { + return SimpleClassIntToString( + (json['value'] as Map)?.map( + (k, e) => MapEntry(int.parse(k), e as String), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(int.parse(k), e as String), + ), + ); +} + +Map _$SimpleClassIntToStringToJson( + SimpleClassIntToString instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), + 'nullable': instance.nullable.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassObjectToString _$SimpleClassObjectToStringFromJson( + Map json) { + return SimpleClassObjectToString( + (json['value'] as Map)?.map( + (k, e) => MapEntry(k, e as String), + ), + Map.from(json['nullable'] as Map), + ); +} + +Map _$SimpleClassObjectToStringToJson( + SimpleClassObjectToString instance) => + { + 'value': instance.value, + 'nullable': instance.nullable, + }; + +SimpleClassStringToString _$SimpleClassStringToStringFromJson( + Map json) { + return SimpleClassStringToString( + (json['value'] as Map)?.map( + (k, e) => MapEntry(k, e as String), + ), + Map.from(json['nullable'] as Map), + ); +} + +Map _$SimpleClassStringToStringToJson( + SimpleClassStringToString instance) => + { + 'value': instance.value, + 'nullable': instance.nullable, + }; + +SimpleClassUriToString _$SimpleClassUriToStringFromJson( + Map json) { + return SimpleClassUriToString( + (json['value'] as Map)?.map( + (k, e) => MapEntry(Uri.parse(k), e as String), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(Uri.parse(k), e as String), + ), + ); +} + +Map _$SimpleClassUriToStringToJson( + SimpleClassUriToString instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), + 'nullable': instance.nullable.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassBigIntToUri _$SimpleClassBigIntToUriFromJson( + Map json) { + return SimpleClassBigIntToUri( + (json['value'] as Map)?.map( + (k, e) => + MapEntry(BigInt.parse(k), e == null ? null : Uri.parse(e as String)), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(BigInt.parse(k), Uri.parse(e as String)), + ), + ); +} + +Map _$SimpleClassBigIntToUriToJson( + SimpleClassBigIntToUri instance) => + { + 'value': + instance.value?.map((k, e) => MapEntry(k.toString(), e?.toString())), + 'nullable': + instance.nullable.map((k, e) => MapEntry(k.toString(), e.toString())), + }; + +SimpleClassDateTimeToUri _$SimpleClassDateTimeToUriFromJson( + Map json) { + return SimpleClassDateTimeToUri( + (json['value'] as Map)?.map( + (k, e) => MapEntry( + DateTime.parse(k), e == null ? null : Uri.parse(e as String)), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(DateTime.parse(k), Uri.parse(e as String)), + ), + ); +} + +Map _$SimpleClassDateTimeToUriToJson( + SimpleClassDateTimeToUri instance) => + { + 'value': instance.value + ?.map((k, e) => MapEntry(k.toIso8601String(), e?.toString())), + 'nullable': instance.nullable + .map((k, e) => MapEntry(k.toIso8601String(), e.toString())), + }; + +SimpleClassDynamicToUri _$SimpleClassDynamicToUriFromJson( + Map json) { + return SimpleClassDynamicToUri( + (json['value'] as Map)?.map( + (k, e) => MapEntry(k, e == null ? null : Uri.parse(e as String)), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(k, Uri.parse(e as String)), + ), + ); +} + +Map _$SimpleClassDynamicToUriToJson( + SimpleClassDynamicToUri instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k, e?.toString())), + 'nullable': instance.nullable.map((k, e) => MapEntry(k, e.toString())), + }; + +SimpleClassIntToUri _$SimpleClassIntToUriFromJson(Map json) { + return SimpleClassIntToUri( + (json['value'] as Map)?.map( + (k, e) => + MapEntry(int.parse(k), e == null ? null : Uri.parse(e as String)), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(int.parse(k), Uri.parse(e as String)), + ), + ); +} + +Map _$SimpleClassIntToUriToJson( + SimpleClassIntToUri instance) => + { + 'value': + instance.value?.map((k, e) => MapEntry(k.toString(), e?.toString())), + 'nullable': + instance.nullable.map((k, e) => MapEntry(k.toString(), e.toString())), + }; + +SimpleClassObjectToUri _$SimpleClassObjectToUriFromJson( + Map json) { + return SimpleClassObjectToUri( + (json['value'] as Map)?.map( + (k, e) => MapEntry(k, e == null ? null : Uri.parse(e as String)), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(k, Uri.parse(e as String)), + ), + ); +} + +Map _$SimpleClassObjectToUriToJson( + SimpleClassObjectToUri instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k, e?.toString())), + 'nullable': instance.nullable.map((k, e) => MapEntry(k, e.toString())), + }; + +SimpleClassStringToUri _$SimpleClassStringToUriFromJson( + Map json) { + return SimpleClassStringToUri( + (json['value'] as Map)?.map( + (k, e) => MapEntry(k, e == null ? null : Uri.parse(e as String)), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(k, Uri.parse(e as String)), + ), + ); +} + +Map _$SimpleClassStringToUriToJson( + SimpleClassStringToUri instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k, e?.toString())), + 'nullable': instance.nullable.map((k, e) => MapEntry(k, e.toString())), + }; + +SimpleClassUriToUri _$SimpleClassUriToUriFromJson(Map json) { + return SimpleClassUriToUri( + (json['value'] as Map)?.map( + (k, e) => + MapEntry(Uri.parse(k), e == null ? null : Uri.parse(e as String)), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(Uri.parse(k), Uri.parse(e as String)), + ), + ); +} + +Map _$SimpleClassUriToUriToJson( + SimpleClassUriToUri instance) => + { + 'value': + instance.value?.map((k, e) => MapEntry(k.toString(), e?.toString())), + 'nullable': + instance.nullable.map((k, e) => MapEntry(k.toString(), e.toString())), + }; diff --git a/json_serializable/test/supported_types/input.type_set.dart b/json_serializable/test/supported_types/input.type_set.dart index 94a1715c3..d36a331c2 100644 --- a/json_serializable/test/supported_types/input.type_set.dart +++ b/json_serializable/test/supported_types/input.type_set.dart @@ -26,3 +26,183 @@ class SimpleClass { Map toJson() => _$SimpleClassToJson(this); } + +@JsonSerializable() +class SimpleClassBigInt { + final Set value; + + @JsonKey(nullable: false) + final Set nullable; + + SimpleClassBigInt( + this.value, + this.nullable, + ); + + factory SimpleClassBigInt.fromJson(Map json) => + _$SimpleClassBigIntFromJson(json); + + Map toJson() => _$SimpleClassBigIntToJson(this); +} + +@JsonSerializable() +class SimpleClassBool { + final Set value; + + @JsonKey(nullable: false) + final Set nullable; + + SimpleClassBool( + this.value, + this.nullable, + ); + + factory SimpleClassBool.fromJson(Map json) => + _$SimpleClassBoolFromJson(json); + + Map toJson() => _$SimpleClassBoolToJson(this); +} + +@JsonSerializable() +class SimpleClassDateTime { + final Set value; + + @JsonKey(nullable: false) + final Set nullable; + + SimpleClassDateTime( + this.value, + this.nullable, + ); + + factory SimpleClassDateTime.fromJson(Map json) => + _$SimpleClassDateTimeFromJson(json); + + Map toJson() => _$SimpleClassDateTimeToJson(this); +} + +@JsonSerializable() +class SimpleClassDouble { + final Set value; + + @JsonKey(nullable: false) + final Set nullable; + + SimpleClassDouble( + this.value, + this.nullable, + ); + + factory SimpleClassDouble.fromJson(Map json) => + _$SimpleClassDoubleFromJson(json); + + Map toJson() => _$SimpleClassDoubleToJson(this); +} + +@JsonSerializable() +class SimpleClassDuration { + final Set value; + + @JsonKey(nullable: false) + final Set nullable; + + SimpleClassDuration( + this.value, + this.nullable, + ); + + factory SimpleClassDuration.fromJson(Map json) => + _$SimpleClassDurationFromJson(json); + + Map toJson() => _$SimpleClassDurationToJson(this); +} + +@JsonSerializable() +class SimpleClassDynamic { + final Set value; + + @JsonKey(nullable: false) + final Set nullable; + + SimpleClassDynamic( + this.value, + this.nullable, + ); + + factory SimpleClassDynamic.fromJson(Map json) => + _$SimpleClassDynamicFromJson(json); + + Map toJson() => _$SimpleClassDynamicToJson(this); +} + +@JsonSerializable() +class SimpleClassNum { + final Set value; + + @JsonKey(nullable: false) + final Set nullable; + + SimpleClassNum( + this.value, + this.nullable, + ); + + factory SimpleClassNum.fromJson(Map json) => + _$SimpleClassNumFromJson(json); + + Map toJson() => _$SimpleClassNumToJson(this); +} + +@JsonSerializable() +class SimpleClassObject { + final Set value; + + @JsonKey(nullable: false) + final Set nullable; + + SimpleClassObject( + this.value, + this.nullable, + ); + + factory SimpleClassObject.fromJson(Map json) => + _$SimpleClassObjectFromJson(json); + + Map toJson() => _$SimpleClassObjectToJson(this); +} + +@JsonSerializable() +class SimpleClassString { + final Set value; + + @JsonKey(nullable: false) + final Set nullable; + + SimpleClassString( + this.value, + this.nullable, + ); + + factory SimpleClassString.fromJson(Map json) => + _$SimpleClassStringFromJson(json); + + Map toJson() => _$SimpleClassStringToJson(this); +} + +@JsonSerializable() +class SimpleClassUri { + final Set value; + + @JsonKey(nullable: false) + final Set nullable; + + SimpleClassUri( + this.value, + this.nullable, + ); + + factory SimpleClassUri.fromJson(Map json) => + _$SimpleClassUriFromJson(json); + + Map toJson() => _$SimpleClassUriToJson(this); +} diff --git a/json_serializable/test/supported_types/input.type_set.g.dart b/json_serializable/test/supported_types/input.type_set.g.dart index dfe0abf20..79c82233b 100644 --- a/json_serializable/test/supported_types/input.type_set.g.dart +++ b/json_serializable/test/supported_types/input.type_set.g.dart @@ -20,3 +20,145 @@ Map _$SimpleClassToJson(SimpleClass instance) => 'nullable': instance.nullable.toList(), 'withDefault': instance.withDefault?.toList(), }; + +SimpleClassBigInt _$SimpleClassBigIntFromJson(Map json) { + return SimpleClassBigInt( + (json['value'] as List) + ?.map((e) => e == null ? null : BigInt.parse(e as String)) + ?.toSet(), + (json['nullable'] as List).map((e) => BigInt.parse(e as String)).toSet(), + ); +} + +Map _$SimpleClassBigIntToJson(SimpleClassBigInt instance) => + { + 'value': instance.value?.map((e) => e?.toString())?.toList(), + 'nullable': instance.nullable.map((e) => e.toString()).toList(), + }; + +SimpleClassBool _$SimpleClassBoolFromJson(Map json) { + return SimpleClassBool( + (json['value'] as List)?.map((e) => e as bool)?.toSet(), + (json['nullable'] as List).map((e) => e as bool).toSet(), + ); +} + +Map _$SimpleClassBoolToJson(SimpleClassBool instance) => + { + 'value': instance.value?.toList(), + 'nullable': instance.nullable.toList(), + }; + +SimpleClassDateTime _$SimpleClassDateTimeFromJson(Map json) { + return SimpleClassDateTime( + (json['value'] as List) + ?.map((e) => e == null ? null : DateTime.parse(e as String)) + ?.toSet(), + (json['nullable'] as List).map((e) => DateTime.parse(e as String)).toSet(), + ); +} + +Map _$SimpleClassDateTimeToJson( + SimpleClassDateTime instance) => + { + 'value': instance.value?.map((e) => e?.toIso8601String())?.toList(), + 'nullable': instance.nullable.map((e) => e.toIso8601String()).toList(), + }; + +SimpleClassDouble _$SimpleClassDoubleFromJson(Map json) { + return SimpleClassDouble( + (json['value'] as List)?.map((e) => (e as num)?.toDouble())?.toSet(), + (json['nullable'] as List).map((e) => (e as num).toDouble()).toSet(), + ); +} + +Map _$SimpleClassDoubleToJson(SimpleClassDouble instance) => + { + 'value': instance.value?.toList(), + 'nullable': instance.nullable.toList(), + }; + +SimpleClassDuration _$SimpleClassDurationFromJson(Map json) { + return SimpleClassDuration( + (json['value'] as List) + ?.map((e) => e == null ? null : Duration(microseconds: e as int)) + ?.toSet(), + (json['nullable'] as List) + .map((e) => Duration(microseconds: e as int)) + .toSet(), + ); +} + +Map _$SimpleClassDurationToJson( + SimpleClassDuration instance) => + { + 'value': instance.value?.map((e) => e?.inMicroseconds)?.toList(), + 'nullable': instance.nullable.map((e) => e.inMicroseconds).toList(), + }; + +SimpleClassDynamic _$SimpleClassDynamicFromJson(Map json) { + return SimpleClassDynamic( + (json['value'] as List)?.toSet(), + (json['nullable'] as List).toSet(), + ); +} + +Map _$SimpleClassDynamicToJson(SimpleClassDynamic instance) => + { + 'value': instance.value?.toList(), + 'nullable': instance.nullable.toList(), + }; + +SimpleClassNum _$SimpleClassNumFromJson(Map json) { + return SimpleClassNum( + (json['value'] as List)?.map((e) => e as num)?.toSet(), + (json['nullable'] as List).map((e) => e as num).toSet(), + ); +} + +Map _$SimpleClassNumToJson(SimpleClassNum instance) => + { + 'value': instance.value?.toList(), + 'nullable': instance.nullable.toList(), + }; + +SimpleClassObject _$SimpleClassObjectFromJson(Map json) { + return SimpleClassObject( + (json['value'] as List)?.toSet(), + (json['nullable'] as List).toSet(), + ); +} + +Map _$SimpleClassObjectToJson(SimpleClassObject instance) => + { + 'value': instance.value?.toList(), + 'nullable': instance.nullable.toList(), + }; + +SimpleClassString _$SimpleClassStringFromJson(Map json) { + return SimpleClassString( + (json['value'] as List)?.map((e) => e as String)?.toSet(), + (json['nullable'] as List).map((e) => e as String).toSet(), + ); +} + +Map _$SimpleClassStringToJson(SimpleClassString instance) => + { + 'value': instance.value?.toList(), + 'nullable': instance.nullable.toList(), + }; + +SimpleClassUri _$SimpleClassUriFromJson(Map json) { + return SimpleClassUri( + (json['value'] as List) + ?.map((e) => e == null ? null : Uri.parse(e as String)) + ?.toSet(), + (json['nullable'] as List).map((e) => Uri.parse(e as String)).toSet(), + ); +} + +Map _$SimpleClassUriToJson(SimpleClassUri instance) => + { + 'value': instance.value?.map((e) => e?.toString())?.toList(), + 'nullable': instance.nullable.map((e) => e.toString()).toList(), + }; diff --git a/json_serializable/tool/test_type_builder.dart b/json_serializable/tool/test_type_builder.dart index ed5df45a0..0f12d849b 100644 --- a/json_serializable/tool/test_type_builder.dart +++ b/json_serializable/tool/test_type_builder.dart @@ -5,50 +5,57 @@ import 'dart:async'; import 'package:build/build.dart'; -import 'package:meta/meta.dart'; +import 'package:dart_style/dart_style.dart'; import 'shared.dart'; +import 'test_type_data.dart'; -const _typesToTest = { - 'BigInt': _TestType( +final _formatter = DartFormatter(); + +const _trivialTypesToTest = { + 'BigInt': TestTypeData( jsonExpression: "'12345'", altJsonExpression: "'67890'", ), - 'bool': _TestType( + 'bool': TestTypeData( defaultExpression: 'true', altJsonExpression: 'false', ), - 'DateTime': _TestType( + 'DateTime': TestTypeData( jsonExpression: "'2020-01-01T00:00:00.000'", altJsonExpression: "'2018-01-01T00:00:00.000'", ), - 'double': _TestType( + 'double': TestTypeData( defaultExpression: '3.14', altJsonExpression: '6.28', ), - 'Duration': _TestType( + 'Duration': TestTypeData( jsonExpression: '1234', altJsonExpression: '2345', ), - 'dynamic': _TestType( + 'dynamic': TestTypeData( altJsonExpression: "'dynamic'", ), - 'num': _TestType( + 'num': TestTypeData( defaultExpression: '88.6', altJsonExpression: '29', ), - 'Object': _TestType( + 'Object': TestTypeData( altJsonExpression: "'Object'", ), - 'String': _TestType( + 'String': TestTypeData( defaultExpression: "'a string'", altJsonExpression: "'another string'", ), - 'Uri': _TestType( + 'Uri': TestTypeData( jsonExpression: "'https://example.com'", altJsonExpression: "'https://dart.dev'", ), - 'MyEnum': _TestType( +}; + +final _typesToTest = { + ..._trivialTypesToTest, + 'MyEnum': const TestTypeData( defaultExpression: 'MyEnum.alpha', jsonExpression: "'alpha'", altJsonExpression: "'beta'", @@ -65,25 +72,44 @@ enum MyEnum { alpha, beta, gamma, delta } // // Collection types // - 'Map': _TestType( + 'Map': TestTypeData( defaultExpression: "{'a': 1}", altJsonExpression: "{'b': 2}", + genericArgs: _iterableGenericArgs + .expand((v) => _mapKeyTypes.map((k) => '$k,$v')) + .toSet(), ), - 'List': _TestType( + 'List': TestTypeData( defaultExpression: '[$_defaultCollectionExpressions]', altJsonExpression: '[$_altCollectionExpressions]', + genericArgs: _iterableGenericArgs, ), - 'Set': _TestType( + 'Set': TestTypeData( defaultExpression: '{$_defaultCollectionExpressions}', jsonExpression: '[$_defaultCollectionExpressions]', altJsonExpression: '[$_altCollectionExpressions]', + genericArgs: _iterableGenericArgs, ), - 'Iterable': _TestType( + 'Iterable': TestTypeData( defaultExpression: '[$_defaultCollectionExpressions]', altJsonExpression: '[$_altCollectionExpressions]', + genericArgs: _iterableGenericArgs, ), }; +const _mapKeyTypes = { + 'BigInt', + 'DateTime', + 'dynamic', + // need enum! + 'int', + 'Object', + 'String', + 'Uri', +}; + +final _iterableGenericArgs = _trivialTypesToTest.keys.toSet(); + const _defaultCollectionExpressions = '42, true, false, null'; const _altCollectionExpressions = '43, false'; @@ -100,22 +126,18 @@ class _TypeBuilder implements Builder { for (var entry in _typesToTest.entries) { final type = entry.key; - final newId = buildStep.inputId.changeExtension(_toTypeExtension(type)); + final newId = buildStep.inputId.changeExtension(toTypeExtension(type)); await buildStep.writeAsString( newId, - Replacement.generate( - sourceContent, - entry.value.replacements(type), - ), + _formatter.format(entry.value.libContent(sourceContent, type)), ); } } @override Map> get buildExtensions => { - '.dart': _typesToTest.keys.map(_toTypeExtension).toSet().toList() - ..sort() + '.dart': _typesToTest.keys.map(toTypeExtension).toSet().toList()..sort() }; } @@ -138,10 +160,7 @@ class _TypeTestBuilder implements Builder { await buildStep.writeAsString( newId, - Replacement.generate( - sourceContent, - entry.value.testReplacements(type), - ), + entry.value.testContent(sourceContent, type), ); } } @@ -153,91 +172,4 @@ class _TypeTestBuilder implements Builder { }; } -String _typeToPathPart(String type) => type.toLowerCase(); - -String _toTypeExtension(String e, {bool includeDotDart = true}) => - '.type_${_typeToPathPart(e)}${includeDotDart ? '.dart' : ''}'; - -String _toTypeTestExtension(String e) => '.${_typeToPathPart(e)}_test.dart'; - -class _TestType { - final List _replacements; - final String defaultExpression; - final String jsonExpression; - final String altJsonExpression; - - const _TestType({ - List replacements, - this.defaultExpression, - String jsonExpression, - @required String altJsonExpression, - }) : _replacements = replacements ?? const [], - jsonExpression = jsonExpression ?? defaultExpression, - altJsonExpression = - altJsonExpression ?? jsonExpression ?? defaultExpression; - - Iterable replacements(String type) sync* { - final newPart = _toTypeExtension(type, includeDotDart: false); - - yield Replacement( - "part 'input.g.dart';", - "part 'input$newPart.g.dart';", - ); - yield Replacement( - 'final int value;', - 'final $type value;', - ); - yield Replacement( - 'final int nullable;', - 'final $type nullable;', - ); - - yield* _replacements; - - final defaultReplacement = defaultExpression == null - ? '' - : _defaultSource - .replaceFirst('42', defaultExpression) - .replaceFirst('int', type); - - yield Replacement( - _defaultSource, - defaultReplacement, - ); - } - - Iterable testReplacements(String type) sync* { - yield Replacement( - "import 'input.dart';", - "import 'input.type_${_typeToPathPart(type)}.dart';", - ); - - yield Replacement( - ''' -final _defaultValue = 42; -final _altValue = 43; -''', - ''' -final _defaultValue = $jsonExpression; -final _altValue = $altJsonExpression; -''', - ); - - if (defaultExpression == null) { - yield const Replacement( - " 'withDefault': _defaultValue,\n", - '', - ); - yield const Replacement( - " 'withDefault': _altValue,\n", - '', - ); - } - } - - static const _defaultSource = r''' - @JsonKey(defaultValue: 42) - int withDefault; - -'''; -} +String _toTypeTestExtension(String e) => '.${typeToPathPart(e)}_test.dart'; diff --git a/json_serializable/tool/test_type_data.dart b/json_serializable/tool/test_type_data.dart new file mode 100644 index 000000000..fc18a44a9 --- /dev/null +++ b/json_serializable/tool/test_type_data.dart @@ -0,0 +1,142 @@ +import 'package:meta/meta.dart'; + +import 'shared.dart'; + +class TestTypeData { + final List _replacements; + final String defaultExpression; + final String jsonExpression; + final String altJsonExpression; + final Set genericArgs; + + const TestTypeData({ + List replacements, + this.defaultExpression, + String jsonExpression, + @required String altJsonExpression, + this.genericArgs = const {}, + }) : _replacements = replacements ?? const [], + jsonExpression = jsonExpression ?? defaultExpression, + altJsonExpression = + altJsonExpression ?? jsonExpression ?? defaultExpression; + + String libContent(String source, String type) { + const classAnnotationSplit = '@JsonSerializable()'; + + final split = source.split(classAnnotationSplit); + + assert(split.length == 2); + + final newPart = toTypeExtension(type, includeDotDart: false); + + final buffer = StringBuffer(Replacement.generate(split[0], [ + Replacement( + "part 'input.g.dart';", + "part 'input$newPart.g.dart';", + ) + ])); + + final simpleClassContent = '$classAnnotationSplit${split[1]}'; + + buffer.write(Replacement.generate( + simpleClassContent, + _libReplacements(type), + )); + + for (var genericArg in genericArgs) { + final genericArgClassPart = _genericClassPart(genericArg); + + final genericType = '$type<$genericArg>'; + + buffer.write(Replacement.generate( + simpleClassContent.replaceAll( + 'SimpleClass', + 'SimpleClass$genericArgClassPart', + ), + _libReplacements(genericType), + )); + } + + return buffer.toString(); + } + + Iterable _libReplacements(String type) sync* { + yield Replacement( + 'final int value;', + 'final $type value;', + ); + yield Replacement( + 'final int nullable;', + 'final $type nullable;', + ); + + yield* _replacements; + + final defaultReplacement = (defaultExpression == null // no default provided + || + type.contains('<') // no support for default values and generic args + ) + ? '' + : _defaultSource + .replaceFirst('42', defaultExpression) + .replaceFirst('int', type); + + yield Replacement( + _defaultSource, + defaultReplacement, + ); + } + + String testContent(String sourceContent, String type) => Replacement.generate( + sourceContent, + _testReplacements(type), + ); + + Iterable _testReplacements(String type) sync* { + yield Replacement( + "import 'input.dart';", + "import 'input.type_${typeToPathPart(type)}.dart';", + ); + + yield Replacement( + ''' +final _defaultValue = 42; +final _altValue = 43; +''', + ''' +final _defaultValue = $jsonExpression; +final _altValue = $altJsonExpression; +''', + ); + + if (defaultExpression == null) { + yield const Replacement( + " 'withDefault': _defaultValue,\n", + '', + ); + yield const Replacement( + " 'withDefault': _altValue,\n", + '', + ); + } + } + + static const _defaultSource = r''' + @JsonKey(defaultValue: 42) + int withDefault; + +'''; +} + +String _genericClassPart(String genericArg) => genericArg + .split(',') + .map((e) => [ + e.substring(0, 1).toUpperCase(), + e.substring(1), + ].join()) + .join('To'); + +String toTypeExtension(String e, {bool includeDotDart = true}) => + '.type_${typeToPathPart(e)}${includeDotDart ? '.dart' : ''}'; + +String typeToPathPart(String type) => type.toLowerCase(); From 4e287e7e76fdb2b582285afe69b74977b25b819b Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 22 Jul 2020 11:52:53 -0700 Subject: [PATCH 205/569] able to have enum type in generics rename enum type test --- json_serializable/build.yaml | 4 +- .../test/supported_types/enum_type.dart | 5 + ...e_myenum.dart => input.type_enumtype.dart} | 13 +- ...enum.g.dart => input.type_enumtype.g.dart} | 27 +- .../supported_types/input.type_iterable.dart | 19 + .../input.type_iterable.g.dart | 54 +++ .../test/supported_types/input.type_list.dart | 19 + .../supported_types/input.type_list.g.dart | 57 +++ .../test/supported_types/input.type_map.dart | 325 ++++++++++++++ .../supported_types/input.type_map.g.dart | 425 ++++++++++++++++++ .../test/supported_types/input.type_set.dart | 19 + .../supported_types/input.type_set.g.dart | 57 +++ ...test.dart => type_test.enumtype_test.dart} | 2 +- json_serializable/tool/test_type_builder.dart | 21 +- json_serializable/tool/test_type_data.dart | 26 +- 15 files changed, 1027 insertions(+), 46 deletions(-) create mode 100644 json_serializable/test/supported_types/enum_type.dart rename json_serializable/test/supported_types/{input.type_myenum.dart => input.type_enumtype.dart} (75%) rename json_serializable/test/supported_types/{input.type_myenum.g.dart => input.type_enumtype.g.dart} (67%) rename json_serializable/test/supported_types/{type_test.myenum_test.dart => type_test.enumtype_test.dart} (96%) diff --git a/json_serializable/build.yaml b/json_serializable/build.yaml index 5263d6ac7..566e85cd0 100644 --- a/json_serializable/build.yaml +++ b/json_serializable/build.yaml @@ -65,10 +65,10 @@ builders: - .type_double.dart - .type_duration.dart - .type_dynamic.dart + - .type_enumtype.dart - .type_iterable.dart - .type_list.dart - .type_map.dart - - .type_myenum.dart - .type_num.dart - .type_object.dart - .type_set.dart @@ -88,10 +88,10 @@ builders: - .double_test.dart - .duration_test.dart - .dynamic_test.dart + - .enumtype_test.dart - .iterable_test.dart - .list_test.dart - .map_test.dart - - .myenum_test.dart - .num_test.dart - .object_test.dart - .set_test.dart diff --git a/json_serializable/test/supported_types/enum_type.dart b/json_serializable/test/supported_types/enum_type.dart new file mode 100644 index 000000000..360a6bf8e --- /dev/null +++ b/json_serializable/test/supported_types/enum_type.dart @@ -0,0 +1,5 @@ +// Copyright (c) 2020, 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. + +enum EnumType { alpha, beta, gamma, delta } diff --git a/json_serializable/test/supported_types/input.type_myenum.dart b/json_serializable/test/supported_types/input.type_enumtype.dart similarity index 75% rename from json_serializable/test/supported_types/input.type_myenum.dart rename to json_serializable/test/supported_types/input.type_enumtype.dart index 9b1c04884..8c54e81d4 100644 --- a/json_serializable/test/supported_types/input.type_myenum.dart +++ b/json_serializable/test/supported_types/input.type_enumtype.dart @@ -3,20 +3,19 @@ // BSD-style license that can be found in the LICENSE file. import 'package:json_annotation/json_annotation.dart'; +import 'enum_type.dart'; -part 'input.type_myenum.g.dart'; - -enum MyEnum { alpha, beta, gamma, delta } +part 'input.type_enumtype.g.dart'; @JsonSerializable() class SimpleClass { - final MyEnum value; + final EnumType value; @JsonKey(nullable: false) - final MyEnum nullable; + final EnumType nullable; - @JsonKey(defaultValue: MyEnum.alpha) - MyEnum withDefault; + @JsonKey(defaultValue: EnumType.alpha) + EnumType withDefault; SimpleClass( this.value, diff --git a/json_serializable/test/supported_types/input.type_myenum.g.dart b/json_serializable/test/supported_types/input.type_enumtype.g.dart similarity index 67% rename from json_serializable/test/supported_types/input.type_myenum.g.dart rename to json_serializable/test/supported_types/input.type_enumtype.g.dart index 24bc31f1b..d79199ce6 100644 --- a/json_serializable/test/supported_types/input.type_myenum.g.dart +++ b/json_serializable/test/supported_types/input.type_enumtype.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -part of 'input.type_myenum.dart'; +part of 'input.type_enumtype.dart'; // ************************************************************************** // JsonSerializableGenerator @@ -8,17 +8,18 @@ part of 'input.type_myenum.dart'; SimpleClass _$SimpleClassFromJson(Map json) { return SimpleClass( - _$enumDecodeNullable(_$MyEnumEnumMap, json['value']), - _$enumDecode(_$MyEnumEnumMap, json['nullable']), - )..withDefault = _$enumDecodeNullable(_$MyEnumEnumMap, json['withDefault']) ?? - MyEnum.alpha; + _$enumDecodeNullable(_$EnumTypeEnumMap, json['value']), + _$enumDecode(_$EnumTypeEnumMap, json['nullable']), + )..withDefault = + _$enumDecodeNullable(_$EnumTypeEnumMap, json['withDefault']) ?? + EnumType.alpha; } Map _$SimpleClassToJson(SimpleClass instance) => { - 'value': _$MyEnumEnumMap[instance.value], - 'nullable': _$MyEnumEnumMap[instance.nullable], - 'withDefault': _$MyEnumEnumMap[instance.withDefault], + 'value': _$EnumTypeEnumMap[instance.value], + 'nullable': _$EnumTypeEnumMap[instance.nullable], + 'withDefault': _$EnumTypeEnumMap[instance.withDefault], }; T _$enumDecode( @@ -53,9 +54,9 @@ T _$enumDecodeNullable( return _$enumDecode(enumValues, source, unknownValue: unknownValue); } -const _$MyEnumEnumMap = { - MyEnum.alpha: 'alpha', - MyEnum.beta: 'beta', - MyEnum.gamma: 'gamma', - MyEnum.delta: 'delta', +const _$EnumTypeEnumMap = { + EnumType.alpha: 'alpha', + EnumType.beta: 'beta', + EnumType.gamma: 'gamma', + EnumType.delta: 'delta', }; diff --git a/json_serializable/test/supported_types/input.type_iterable.dart b/json_serializable/test/supported_types/input.type_iterable.dart index 1cf4b8463..ec2407a3b 100644 --- a/json_serializable/test/supported_types/input.type_iterable.dart +++ b/json_serializable/test/supported_types/input.type_iterable.dart @@ -3,6 +3,7 @@ // BSD-style license that can be found in the LICENSE file. import 'package:json_annotation/json_annotation.dart'; +import 'enum_type.dart'; part 'input.type_iterable.g.dart'; @@ -135,6 +136,24 @@ class SimpleClassDynamic { Map toJson() => _$SimpleClassDynamicToJson(this); } +@JsonSerializable() +class SimpleClassEnumType { + final Iterable value; + + @JsonKey(nullable: false) + final Iterable nullable; + + SimpleClassEnumType( + this.value, + this.nullable, + ); + + factory SimpleClassEnumType.fromJson(Map json) => + _$SimpleClassEnumTypeFromJson(json); + + Map toJson() => _$SimpleClassEnumTypeToJson(this); +} + @JsonSerializable() class SimpleClassNum { final Iterable value; diff --git a/json_serializable/test/supported_types/input.type_iterable.g.dart b/json_serializable/test/supported_types/input.type_iterable.g.dart index 7175714ef..fc4fd6abb 100644 --- a/json_serializable/test/supported_types/input.type_iterable.g.dart +++ b/json_serializable/test/supported_types/input.type_iterable.g.dart @@ -103,6 +103,60 @@ Map _$SimpleClassDynamicToJson(SimpleClassDynamic instance) => 'nullable': instance.nullable.toList(), }; +SimpleClassEnumType _$SimpleClassEnumTypeFromJson(Map json) { + return SimpleClassEnumType( + (json['value'] as List) + ?.map((e) => _$enumDecodeNullable(_$EnumTypeEnumMap, e)), + (json['nullable'] as List).map((e) => _$enumDecode(_$EnumTypeEnumMap, e)), + ); +} + +Map _$SimpleClassEnumTypeToJson( + SimpleClassEnumType instance) => + { + 'value': instance.value?.map((e) => _$EnumTypeEnumMap[e])?.toList(), + 'nullable': instance.nullable.map((e) => _$EnumTypeEnumMap[e]).toList(), + }; + +T _$enumDecode( + Map enumValues, + dynamic source, { + T unknownValue, +}) { + if (source == null) { + throw ArgumentError('A value must be provided. Supported values: ' + '${enumValues.values.join(', ')}'); + } + + final value = enumValues.entries + .singleWhere((e) => e.value == source, orElse: () => null) + ?.key; + + if (value == null && unknownValue == null) { + throw ArgumentError('`$source` is not one of the supported values: ' + '${enumValues.values.join(', ')}'); + } + return value ?? unknownValue; +} + +T _$enumDecodeNullable( + Map enumValues, + dynamic source, { + T unknownValue, +}) { + if (source == null) { + return null; + } + return _$enumDecode(enumValues, source, unknownValue: unknownValue); +} + +const _$EnumTypeEnumMap = { + EnumType.alpha: 'alpha', + EnumType.beta: 'beta', + EnumType.gamma: 'gamma', + EnumType.delta: 'delta', +}; + SimpleClassNum _$SimpleClassNumFromJson(Map json) { return SimpleClassNum( (json['value'] as List)?.map((e) => e as num), diff --git a/json_serializable/test/supported_types/input.type_list.dart b/json_serializable/test/supported_types/input.type_list.dart index f63d38afe..5b4e8e1c0 100644 --- a/json_serializable/test/supported_types/input.type_list.dart +++ b/json_serializable/test/supported_types/input.type_list.dart @@ -3,6 +3,7 @@ // BSD-style license that can be found in the LICENSE file. import 'package:json_annotation/json_annotation.dart'; +import 'enum_type.dart'; part 'input.type_list.g.dart'; @@ -135,6 +136,24 @@ class SimpleClassDynamic { Map toJson() => _$SimpleClassDynamicToJson(this); } +@JsonSerializable() +class SimpleClassEnumType { + final List value; + + @JsonKey(nullable: false) + final List nullable; + + SimpleClassEnumType( + this.value, + this.nullable, + ); + + factory SimpleClassEnumType.fromJson(Map json) => + _$SimpleClassEnumTypeFromJson(json); + + Map toJson() => _$SimpleClassEnumTypeToJson(this); +} + @JsonSerializable() class SimpleClassNum { final List value; diff --git a/json_serializable/test/supported_types/input.type_list.g.dart b/json_serializable/test/supported_types/input.type_list.g.dart index f17bcfb3a..1560546a9 100644 --- a/json_serializable/test/supported_types/input.type_list.g.dart +++ b/json_serializable/test/supported_types/input.type_list.g.dart @@ -108,6 +108,63 @@ Map _$SimpleClassDynamicToJson(SimpleClassDynamic instance) => 'nullable': instance.nullable, }; +SimpleClassEnumType _$SimpleClassEnumTypeFromJson(Map json) { + return SimpleClassEnumType( + (json['value'] as List) + ?.map((e) => _$enumDecodeNullable(_$EnumTypeEnumMap, e)) + ?.toList(), + (json['nullable'] as List) + .map((e) => _$enumDecode(_$EnumTypeEnumMap, e)) + .toList(), + ); +} + +Map _$SimpleClassEnumTypeToJson( + SimpleClassEnumType instance) => + { + 'value': instance.value?.map((e) => _$EnumTypeEnumMap[e])?.toList(), + 'nullable': instance.nullable.map((e) => _$EnumTypeEnumMap[e]).toList(), + }; + +T _$enumDecode( + Map enumValues, + dynamic source, { + T unknownValue, +}) { + if (source == null) { + throw ArgumentError('A value must be provided. Supported values: ' + '${enumValues.values.join(', ')}'); + } + + final value = enumValues.entries + .singleWhere((e) => e.value == source, orElse: () => null) + ?.key; + + if (value == null && unknownValue == null) { + throw ArgumentError('`$source` is not one of the supported values: ' + '${enumValues.values.join(', ')}'); + } + return value ?? unknownValue; +} + +T _$enumDecodeNullable( + Map enumValues, + dynamic source, { + T unknownValue, +}) { + if (source == null) { + return null; + } + return _$enumDecode(enumValues, source, unknownValue: unknownValue); +} + +const _$EnumTypeEnumMap = { + EnumType.alpha: 'alpha', + EnumType.beta: 'beta', + EnumType.gamma: 'gamma', + EnumType.delta: 'delta', +}; + SimpleClassNum _$SimpleClassNumFromJson(Map json) { return SimpleClassNum( (json['value'] as List)?.map((e) => e as num)?.toList(), diff --git a/json_serializable/test/supported_types/input.type_map.dart b/json_serializable/test/supported_types/input.type_map.dart index fc9e4fdcd..46bf00aa5 100644 --- a/json_serializable/test/supported_types/input.type_map.dart +++ b/json_serializable/test/supported_types/input.type_map.dart @@ -3,6 +3,7 @@ // BSD-style license that can be found in the LICENSE file. import 'package:json_annotation/json_annotation.dart'; +import 'enum_type.dart'; part 'input.type_map.g.dart'; @@ -81,6 +82,24 @@ class SimpleClassDynamicToBigInt { Map toJson() => _$SimpleClassDynamicToBigIntToJson(this); } +@JsonSerializable() +class SimpleClassEnumTypeToBigInt { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassEnumTypeToBigInt( + this.value, + this.nullable, + ); + + factory SimpleClassEnumTypeToBigInt.fromJson(Map json) => + _$SimpleClassEnumTypeToBigIntFromJson(json); + + Map toJson() => _$SimpleClassEnumTypeToBigIntToJson(this); +} + @JsonSerializable() class SimpleClassIntToBigInt { final Map value; @@ -207,6 +226,24 @@ class SimpleClassDynamicToBool { Map toJson() => _$SimpleClassDynamicToBoolToJson(this); } +@JsonSerializable() +class SimpleClassEnumTypeToBool { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassEnumTypeToBool( + this.value, + this.nullable, + ); + + factory SimpleClassEnumTypeToBool.fromJson(Map json) => + _$SimpleClassEnumTypeToBoolFromJson(json); + + Map toJson() => _$SimpleClassEnumTypeToBoolToJson(this); +} + @JsonSerializable() class SimpleClassIntToBool { final Map value; @@ -333,6 +370,24 @@ class SimpleClassDynamicToDateTime { Map toJson() => _$SimpleClassDynamicToDateTimeToJson(this); } +@JsonSerializable() +class SimpleClassEnumTypeToDateTime { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassEnumTypeToDateTime( + this.value, + this.nullable, + ); + + factory SimpleClassEnumTypeToDateTime.fromJson(Map json) => + _$SimpleClassEnumTypeToDateTimeFromJson(json); + + Map toJson() => _$SimpleClassEnumTypeToDateTimeToJson(this); +} + @JsonSerializable() class SimpleClassIntToDateTime { final Map value; @@ -459,6 +514,24 @@ class SimpleClassDynamicToDouble { Map toJson() => _$SimpleClassDynamicToDoubleToJson(this); } +@JsonSerializable() +class SimpleClassEnumTypeToDouble { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassEnumTypeToDouble( + this.value, + this.nullable, + ); + + factory SimpleClassEnumTypeToDouble.fromJson(Map json) => + _$SimpleClassEnumTypeToDoubleFromJson(json); + + Map toJson() => _$SimpleClassEnumTypeToDoubleToJson(this); +} + @JsonSerializable() class SimpleClassIntToDouble { final Map value; @@ -585,6 +658,24 @@ class SimpleClassDynamicToDuration { Map toJson() => _$SimpleClassDynamicToDurationToJson(this); } +@JsonSerializable() +class SimpleClassEnumTypeToDuration { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassEnumTypeToDuration( + this.value, + this.nullable, + ); + + factory SimpleClassEnumTypeToDuration.fromJson(Map json) => + _$SimpleClassEnumTypeToDurationFromJson(json); + + Map toJson() => _$SimpleClassEnumTypeToDurationToJson(this); +} + @JsonSerializable() class SimpleClassIntToDuration { final Map value; @@ -711,6 +802,24 @@ class SimpleClassDynamicToDynamic { Map toJson() => _$SimpleClassDynamicToDynamicToJson(this); } +@JsonSerializable() +class SimpleClassEnumTypeToDynamic { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassEnumTypeToDynamic( + this.value, + this.nullable, + ); + + factory SimpleClassEnumTypeToDynamic.fromJson(Map json) => + _$SimpleClassEnumTypeToDynamicFromJson(json); + + Map toJson() => _$SimpleClassEnumTypeToDynamicToJson(this); +} + @JsonSerializable() class SimpleClassIntToDynamic { final Map value; @@ -783,6 +892,150 @@ class SimpleClassUriToDynamic { Map toJson() => _$SimpleClassUriToDynamicToJson(this); } +@JsonSerializable() +class SimpleClassBigIntToEnumType { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassBigIntToEnumType( + this.value, + this.nullable, + ); + + factory SimpleClassBigIntToEnumType.fromJson(Map json) => + _$SimpleClassBigIntToEnumTypeFromJson(json); + + Map toJson() => _$SimpleClassBigIntToEnumTypeToJson(this); +} + +@JsonSerializable() +class SimpleClassDateTimeToEnumType { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassDateTimeToEnumType( + this.value, + this.nullable, + ); + + factory SimpleClassDateTimeToEnumType.fromJson(Map json) => + _$SimpleClassDateTimeToEnumTypeFromJson(json); + + Map toJson() => _$SimpleClassDateTimeToEnumTypeToJson(this); +} + +@JsonSerializable() +class SimpleClassDynamicToEnumType { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassDynamicToEnumType( + this.value, + this.nullable, + ); + + factory SimpleClassDynamicToEnumType.fromJson(Map json) => + _$SimpleClassDynamicToEnumTypeFromJson(json); + + Map toJson() => _$SimpleClassDynamicToEnumTypeToJson(this); +} + +@JsonSerializable() +class SimpleClassEnumTypeToEnumType { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassEnumTypeToEnumType( + this.value, + this.nullable, + ); + + factory SimpleClassEnumTypeToEnumType.fromJson(Map json) => + _$SimpleClassEnumTypeToEnumTypeFromJson(json); + + Map toJson() => _$SimpleClassEnumTypeToEnumTypeToJson(this); +} + +@JsonSerializable() +class SimpleClassIntToEnumType { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassIntToEnumType( + this.value, + this.nullable, + ); + + factory SimpleClassIntToEnumType.fromJson(Map json) => + _$SimpleClassIntToEnumTypeFromJson(json); + + Map toJson() => _$SimpleClassIntToEnumTypeToJson(this); +} + +@JsonSerializable() +class SimpleClassObjectToEnumType { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassObjectToEnumType( + this.value, + this.nullable, + ); + + factory SimpleClassObjectToEnumType.fromJson(Map json) => + _$SimpleClassObjectToEnumTypeFromJson(json); + + Map toJson() => _$SimpleClassObjectToEnumTypeToJson(this); +} + +@JsonSerializable() +class SimpleClassStringToEnumType { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassStringToEnumType( + this.value, + this.nullable, + ); + + factory SimpleClassStringToEnumType.fromJson(Map json) => + _$SimpleClassStringToEnumTypeFromJson(json); + + Map toJson() => _$SimpleClassStringToEnumTypeToJson(this); +} + +@JsonSerializable() +class SimpleClassUriToEnumType { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassUriToEnumType( + this.value, + this.nullable, + ); + + factory SimpleClassUriToEnumType.fromJson(Map json) => + _$SimpleClassUriToEnumTypeFromJson(json); + + Map toJson() => _$SimpleClassUriToEnumTypeToJson(this); +} + @JsonSerializable() class SimpleClassBigIntToNum { final Map value; @@ -837,6 +1090,24 @@ class SimpleClassDynamicToNum { Map toJson() => _$SimpleClassDynamicToNumToJson(this); } +@JsonSerializable() +class SimpleClassEnumTypeToNum { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassEnumTypeToNum( + this.value, + this.nullable, + ); + + factory SimpleClassEnumTypeToNum.fromJson(Map json) => + _$SimpleClassEnumTypeToNumFromJson(json); + + Map toJson() => _$SimpleClassEnumTypeToNumToJson(this); +} + @JsonSerializable() class SimpleClassIntToNum { final Map value; @@ -963,6 +1234,24 @@ class SimpleClassDynamicToObject { Map toJson() => _$SimpleClassDynamicToObjectToJson(this); } +@JsonSerializable() +class SimpleClassEnumTypeToObject { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassEnumTypeToObject( + this.value, + this.nullable, + ); + + factory SimpleClassEnumTypeToObject.fromJson(Map json) => + _$SimpleClassEnumTypeToObjectFromJson(json); + + Map toJson() => _$SimpleClassEnumTypeToObjectToJson(this); +} + @JsonSerializable() class SimpleClassIntToObject { final Map value; @@ -1089,6 +1378,24 @@ class SimpleClassDynamicToString { Map toJson() => _$SimpleClassDynamicToStringToJson(this); } +@JsonSerializable() +class SimpleClassEnumTypeToString { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassEnumTypeToString( + this.value, + this.nullable, + ); + + factory SimpleClassEnumTypeToString.fromJson(Map json) => + _$SimpleClassEnumTypeToStringFromJson(json); + + Map toJson() => _$SimpleClassEnumTypeToStringToJson(this); +} + @JsonSerializable() class SimpleClassIntToString { final Map value; @@ -1215,6 +1522,24 @@ class SimpleClassDynamicToUri { Map toJson() => _$SimpleClassDynamicToUriToJson(this); } +@JsonSerializable() +class SimpleClassEnumTypeToUri { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassEnumTypeToUri( + this.value, + this.nullable, + ); + + factory SimpleClassEnumTypeToUri.fromJson(Map json) => + _$SimpleClassEnumTypeToUriFromJson(json); + + Map toJson() => _$SimpleClassEnumTypeToUriToJson(this); +} + @JsonSerializable() class SimpleClassIntToUri { final Map value; diff --git a/json_serializable/test/supported_types/input.type_map.g.dart b/json_serializable/test/supported_types/input.type_map.g.dart index 324c36974..f793183e6 100644 --- a/json_serializable/test/supported_types/input.type_map.g.dart +++ b/json_serializable/test/supported_types/input.type_map.g.dart @@ -83,6 +83,68 @@ Map _$SimpleClassDynamicToBigIntToJson( 'nullable': instance.nullable.map((k, e) => MapEntry(k, e.toString())), }; +SimpleClassEnumTypeToBigInt _$SimpleClassEnumTypeToBigIntFromJson( + Map json) { + return SimpleClassEnumTypeToBigInt( + (json['value'] as Map)?.map( + (k, e) => MapEntry(_$enumDecodeNullable(_$EnumTypeEnumMap, k), + e == null ? null : BigInt.parse(e as String)), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry( + _$enumDecode(_$EnumTypeEnumMap, k), BigInt.parse(e as String)), + ), + ); +} + +Map _$SimpleClassEnumTypeToBigIntToJson( + SimpleClassEnumTypeToBigInt instance) => + { + 'value': instance.value + ?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e?.toString())), + 'nullable': instance.nullable + .map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e.toString())), + }; + +T _$enumDecode( + Map enumValues, + dynamic source, { + T unknownValue, +}) { + if (source == null) { + throw ArgumentError('A value must be provided. Supported values: ' + '${enumValues.values.join(', ')}'); + } + + final value = enumValues.entries + .singleWhere((e) => e.value == source, orElse: () => null) + ?.key; + + if (value == null && unknownValue == null) { + throw ArgumentError('`$source` is not one of the supported values: ' + '${enumValues.values.join(', ')}'); + } + return value ?? unknownValue; +} + +T _$enumDecodeNullable( + Map enumValues, + dynamic source, { + T unknownValue, +}) { + if (source == null) { + return null; + } + return _$enumDecode(enumValues, source, unknownValue: unknownValue); +} + +const _$EnumTypeEnumMap = { + EnumType.alpha: 'alpha', + EnumType.beta: 'beta', + EnumType.gamma: 'gamma', + EnumType.delta: 'delta', +}; + SimpleClassIntToBigInt _$SimpleClassIntToBigIntFromJson( Map json) { return SimpleClassIntToBigInt( @@ -221,6 +283,26 @@ Map _$SimpleClassDynamicToBoolToJson( 'nullable': instance.nullable, }; +SimpleClassEnumTypeToBool _$SimpleClassEnumTypeToBoolFromJson( + Map json) { + return SimpleClassEnumTypeToBool( + (json['value'] as Map)?.map( + (k, e) => MapEntry(_$enumDecodeNullable(_$EnumTypeEnumMap, k), e as bool), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as bool), + ), + ); +} + +Map _$SimpleClassEnumTypeToBoolToJson( + SimpleClassEnumTypeToBool instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), + 'nullable': + instance.nullable.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), + }; + SimpleClassIntToBool _$SimpleClassIntToBoolFromJson(Map json) { return SimpleClassIntToBool( (json['value'] as Map)?.map( @@ -355,6 +437,29 @@ Map _$SimpleClassDynamicToDateTimeToJson( instance.nullable.map((k, e) => MapEntry(k, e.toIso8601String())), }; +SimpleClassEnumTypeToDateTime _$SimpleClassEnumTypeToDateTimeFromJson( + Map json) { + return SimpleClassEnumTypeToDateTime( + (json['value'] as Map)?.map( + (k, e) => MapEntry(_$enumDecodeNullable(_$EnumTypeEnumMap, k), + e == null ? null : DateTime.parse(e as String)), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry( + _$enumDecode(_$EnumTypeEnumMap, k), DateTime.parse(e as String)), + ), + ); +} + +Map _$SimpleClassEnumTypeToDateTimeToJson( + SimpleClassEnumTypeToDateTime instance) => + { + 'value': instance.value + ?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e?.toIso8601String())), + 'nullable': instance.nullable + .map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e.toIso8601String())), + }; + SimpleClassIntToDateTime _$SimpleClassIntToDateTimeFromJson( Map json) { return SimpleClassIntToDateTime( @@ -495,6 +600,28 @@ Map _$SimpleClassDynamicToDoubleToJson( 'nullable': instance.nullable, }; +SimpleClassEnumTypeToDouble _$SimpleClassEnumTypeToDoubleFromJson( + Map json) { + return SimpleClassEnumTypeToDouble( + (json['value'] as Map)?.map( + (k, e) => MapEntry( + _$enumDecodeNullable(_$EnumTypeEnumMap, k), (e as num)?.toDouble()), + ), + (json['nullable'] as Map).map( + (k, e) => + MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), (e as num).toDouble()), + ), + ); +} + +Map _$SimpleClassEnumTypeToDoubleToJson( + SimpleClassEnumTypeToDouble instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), + 'nullable': + instance.nullable.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), + }; + SimpleClassIntToDouble _$SimpleClassIntToDoubleFromJson( Map json) { return SimpleClassIntToDouble( @@ -632,6 +759,29 @@ Map _$SimpleClassDynamicToDurationToJson( instance.nullable.map((k, e) => MapEntry(k, e.inMicroseconds)), }; +SimpleClassEnumTypeToDuration _$SimpleClassEnumTypeToDurationFromJson( + Map json) { + return SimpleClassEnumTypeToDuration( + (json['value'] as Map)?.map( + (k, e) => MapEntry(_$enumDecodeNullable(_$EnumTypeEnumMap, k), + e == null ? null : Duration(microseconds: e as int)), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry( + _$enumDecode(_$EnumTypeEnumMap, k), Duration(microseconds: e as int)), + ), + ); +} + +Map _$SimpleClassEnumTypeToDurationToJson( + SimpleClassEnumTypeToDuration instance) => + { + 'value': instance.value + ?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e?.inMicroseconds)), + 'nullable': instance.nullable + .map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e.inMicroseconds)), + }; + SimpleClassIntToDuration _$SimpleClassIntToDurationFromJson( Map json) { return SimpleClassIntToDuration( @@ -772,6 +922,26 @@ Map _$SimpleClassDynamicToDynamicToJson( 'nullable': instance.nullable, }; +SimpleClassEnumTypeToDynamic _$SimpleClassEnumTypeToDynamicFromJson( + Map json) { + return SimpleClassEnumTypeToDynamic( + (json['value'] as Map)?.map( + (k, e) => MapEntry(_$enumDecodeNullable(_$EnumTypeEnumMap, k), e), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e), + ), + ); +} + +Map _$SimpleClassEnumTypeToDynamicToJson( + SimpleClassEnumTypeToDynamic instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), + 'nullable': + instance.nullable.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), + }; + SimpleClassIntToDynamic _$SimpleClassIntToDynamicFromJson( Map json) { return SimpleClassIntToDynamic( @@ -840,6 +1010,177 @@ Map _$SimpleClassUriToDynamicToJson( 'nullable': instance.nullable.map((k, e) => MapEntry(k.toString(), e)), }; +SimpleClassBigIntToEnumType _$SimpleClassBigIntToEnumTypeFromJson( + Map json) { + return SimpleClassBigIntToEnumType( + (json['value'] as Map)?.map( + (k, e) => + MapEntry(BigInt.parse(k), _$enumDecodeNullable(_$EnumTypeEnumMap, e)), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(BigInt.parse(k), _$enumDecode(_$EnumTypeEnumMap, e)), + ), + ); +} + +Map _$SimpleClassBigIntToEnumTypeToJson( + SimpleClassBigIntToEnumType instance) => + { + 'value': instance.value + ?.map((k, e) => MapEntry(k.toString(), _$EnumTypeEnumMap[e])), + 'nullable': instance.nullable + .map((k, e) => MapEntry(k.toString(), _$EnumTypeEnumMap[e])), + }; + +SimpleClassDateTimeToEnumType _$SimpleClassDateTimeToEnumTypeFromJson( + Map json) { + return SimpleClassDateTimeToEnumType( + (json['value'] as Map)?.map( + (k, e) => MapEntry( + DateTime.parse(k), _$enumDecodeNullable(_$EnumTypeEnumMap, e)), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(DateTime.parse(k), _$enumDecode(_$EnumTypeEnumMap, e)), + ), + ); +} + +Map _$SimpleClassDateTimeToEnumTypeToJson( + SimpleClassDateTimeToEnumType instance) => + { + 'value': instance.value + ?.map((k, e) => MapEntry(k.toIso8601String(), _$EnumTypeEnumMap[e])), + 'nullable': instance.nullable + .map((k, e) => MapEntry(k.toIso8601String(), _$EnumTypeEnumMap[e])), + }; + +SimpleClassDynamicToEnumType _$SimpleClassDynamicToEnumTypeFromJson( + Map json) { + return SimpleClassDynamicToEnumType( + (json['value'] as Map)?.map( + (k, e) => MapEntry(k, _$enumDecodeNullable(_$EnumTypeEnumMap, e)), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(k, _$enumDecode(_$EnumTypeEnumMap, e)), + ), + ); +} + +Map _$SimpleClassDynamicToEnumTypeToJson( + SimpleClassDynamicToEnumType instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k, _$EnumTypeEnumMap[e])), + 'nullable': + instance.nullable.map((k, e) => MapEntry(k, _$EnumTypeEnumMap[e])), + }; + +SimpleClassEnumTypeToEnumType _$SimpleClassEnumTypeToEnumTypeFromJson( + Map json) { + return SimpleClassEnumTypeToEnumType( + (json['value'] as Map)?.map( + (k, e) => MapEntry(_$enumDecodeNullable(_$EnumTypeEnumMap, k), + _$enumDecodeNullable(_$EnumTypeEnumMap, e)), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), + _$enumDecode(_$EnumTypeEnumMap, e)), + ), + ); +} + +Map _$SimpleClassEnumTypeToEnumTypeToJson( + SimpleClassEnumTypeToEnumType instance) => + { + 'value': instance.value + ?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], _$EnumTypeEnumMap[e])), + 'nullable': instance.nullable + .map((k, e) => MapEntry(_$EnumTypeEnumMap[k], _$EnumTypeEnumMap[e])), + }; + +SimpleClassIntToEnumType _$SimpleClassIntToEnumTypeFromJson( + Map json) { + return SimpleClassIntToEnumType( + (json['value'] as Map)?.map( + (k, e) => + MapEntry(int.parse(k), _$enumDecodeNullable(_$EnumTypeEnumMap, e)), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(int.parse(k), _$enumDecode(_$EnumTypeEnumMap, e)), + ), + ); +} + +Map _$SimpleClassIntToEnumTypeToJson( + SimpleClassIntToEnumType instance) => + { + 'value': instance.value + ?.map((k, e) => MapEntry(k.toString(), _$EnumTypeEnumMap[e])), + 'nullable': instance.nullable + .map((k, e) => MapEntry(k.toString(), _$EnumTypeEnumMap[e])), + }; + +SimpleClassObjectToEnumType _$SimpleClassObjectToEnumTypeFromJson( + Map json) { + return SimpleClassObjectToEnumType( + (json['value'] as Map)?.map( + (k, e) => MapEntry(k, _$enumDecodeNullable(_$EnumTypeEnumMap, e)), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(k, _$enumDecode(_$EnumTypeEnumMap, e)), + ), + ); +} + +Map _$SimpleClassObjectToEnumTypeToJson( + SimpleClassObjectToEnumType instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k, _$EnumTypeEnumMap[e])), + 'nullable': + instance.nullable.map((k, e) => MapEntry(k, _$EnumTypeEnumMap[e])), + }; + +SimpleClassStringToEnumType _$SimpleClassStringToEnumTypeFromJson( + Map json) { + return SimpleClassStringToEnumType( + (json['value'] as Map)?.map( + (k, e) => MapEntry(k, _$enumDecodeNullable(_$EnumTypeEnumMap, e)), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(k, _$enumDecode(_$EnumTypeEnumMap, e)), + ), + ); +} + +Map _$SimpleClassStringToEnumTypeToJson( + SimpleClassStringToEnumType instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k, _$EnumTypeEnumMap[e])), + 'nullable': + instance.nullable.map((k, e) => MapEntry(k, _$EnumTypeEnumMap[e])), + }; + +SimpleClassUriToEnumType _$SimpleClassUriToEnumTypeFromJson( + Map json) { + return SimpleClassUriToEnumType( + (json['value'] as Map)?.map( + (k, e) => + MapEntry(Uri.parse(k), _$enumDecodeNullable(_$EnumTypeEnumMap, e)), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(Uri.parse(k), _$enumDecode(_$EnumTypeEnumMap, e)), + ), + ); +} + +Map _$SimpleClassUriToEnumTypeToJson( + SimpleClassUriToEnumType instance) => + { + 'value': instance.value + ?.map((k, e) => MapEntry(k.toString(), _$EnumTypeEnumMap[e])), + 'nullable': instance.nullable + .map((k, e) => MapEntry(k.toString(), _$EnumTypeEnumMap[e])), + }; + SimpleClassBigIntToNum _$SimpleClassBigIntToNumFromJson( Map json) { return SimpleClassBigIntToNum( @@ -896,6 +1237,26 @@ Map _$SimpleClassDynamicToNumToJson( 'nullable': instance.nullable, }; +SimpleClassEnumTypeToNum _$SimpleClassEnumTypeToNumFromJson( + Map json) { + return SimpleClassEnumTypeToNum( + (json['value'] as Map)?.map( + (k, e) => MapEntry(_$enumDecodeNullable(_$EnumTypeEnumMap, k), e as num), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as num), + ), + ); +} + +Map _$SimpleClassEnumTypeToNumToJson( + SimpleClassEnumTypeToNum instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), + 'nullable': + instance.nullable.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), + }; + SimpleClassIntToNum _$SimpleClassIntToNumFromJson(Map json) { return SimpleClassIntToNum( (json['value'] as Map)?.map( @@ -1020,6 +1381,26 @@ Map _$SimpleClassDynamicToObjectToJson( 'nullable': instance.nullable, }; +SimpleClassEnumTypeToObject _$SimpleClassEnumTypeToObjectFromJson( + Map json) { + return SimpleClassEnumTypeToObject( + (json['value'] as Map)?.map( + (k, e) => MapEntry(_$enumDecodeNullable(_$EnumTypeEnumMap, k), e), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e), + ), + ); +} + +Map _$SimpleClassEnumTypeToObjectToJson( + SimpleClassEnumTypeToObject instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), + 'nullable': + instance.nullable.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), + }; + SimpleClassIntToObject _$SimpleClassIntToObjectFromJson( Map json) { return SimpleClassIntToObject( @@ -1144,6 +1525,27 @@ Map _$SimpleClassDynamicToStringToJson( 'nullable': instance.nullable, }; +SimpleClassEnumTypeToString _$SimpleClassEnumTypeToStringFromJson( + Map json) { + return SimpleClassEnumTypeToString( + (json['value'] as Map)?.map( + (k, e) => + MapEntry(_$enumDecodeNullable(_$EnumTypeEnumMap, k), e as String), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as String), + ), + ); +} + +Map _$SimpleClassEnumTypeToStringToJson( + SimpleClassEnumTypeToString instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), + 'nullable': + instance.nullable.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), + }; + SimpleClassIntToString _$SimpleClassIntToStringFromJson( Map json) { return SimpleClassIntToString( @@ -1279,6 +1681,29 @@ Map _$SimpleClassDynamicToUriToJson( 'nullable': instance.nullable.map((k, e) => MapEntry(k, e.toString())), }; +SimpleClassEnumTypeToUri _$SimpleClassEnumTypeToUriFromJson( + Map json) { + return SimpleClassEnumTypeToUri( + (json['value'] as Map)?.map( + (k, e) => MapEntry(_$enumDecodeNullable(_$EnumTypeEnumMap, k), + e == null ? null : Uri.parse(e as String)), + ), + (json['nullable'] as Map).map( + (k, e) => + MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), Uri.parse(e as String)), + ), + ); +} + +Map _$SimpleClassEnumTypeToUriToJson( + SimpleClassEnumTypeToUri instance) => + { + 'value': instance.value + ?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e?.toString())), + 'nullable': instance.nullable + .map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e.toString())), + }; + SimpleClassIntToUri _$SimpleClassIntToUriFromJson(Map json) { return SimpleClassIntToUri( (json['value'] as Map)?.map( diff --git a/json_serializable/test/supported_types/input.type_set.dart b/json_serializable/test/supported_types/input.type_set.dart index d36a331c2..ef8301385 100644 --- a/json_serializable/test/supported_types/input.type_set.dart +++ b/json_serializable/test/supported_types/input.type_set.dart @@ -3,6 +3,7 @@ // BSD-style license that can be found in the LICENSE file. import 'package:json_annotation/json_annotation.dart'; +import 'enum_type.dart'; part 'input.type_set.g.dart'; @@ -135,6 +136,24 @@ class SimpleClassDynamic { Map toJson() => _$SimpleClassDynamicToJson(this); } +@JsonSerializable() +class SimpleClassEnumType { + final Set value; + + @JsonKey(nullable: false) + final Set nullable; + + SimpleClassEnumType( + this.value, + this.nullable, + ); + + factory SimpleClassEnumType.fromJson(Map json) => + _$SimpleClassEnumTypeFromJson(json); + + Map toJson() => _$SimpleClassEnumTypeToJson(this); +} + @JsonSerializable() class SimpleClassNum { final Set value; diff --git a/json_serializable/test/supported_types/input.type_set.g.dart b/json_serializable/test/supported_types/input.type_set.g.dart index 79c82233b..fadbed5ba 100644 --- a/json_serializable/test/supported_types/input.type_set.g.dart +++ b/json_serializable/test/supported_types/input.type_set.g.dart @@ -109,6 +109,63 @@ Map _$SimpleClassDynamicToJson(SimpleClassDynamic instance) => 'nullable': instance.nullable.toList(), }; +SimpleClassEnumType _$SimpleClassEnumTypeFromJson(Map json) { + return SimpleClassEnumType( + (json['value'] as List) + ?.map((e) => _$enumDecodeNullable(_$EnumTypeEnumMap, e)) + ?.toSet(), + (json['nullable'] as List) + .map((e) => _$enumDecode(_$EnumTypeEnumMap, e)) + .toSet(), + ); +} + +Map _$SimpleClassEnumTypeToJson( + SimpleClassEnumType instance) => + { + 'value': instance.value?.map((e) => _$EnumTypeEnumMap[e])?.toList(), + 'nullable': instance.nullable.map((e) => _$EnumTypeEnumMap[e]).toList(), + }; + +T _$enumDecode( + Map enumValues, + dynamic source, { + T unknownValue, +}) { + if (source == null) { + throw ArgumentError('A value must be provided. Supported values: ' + '${enumValues.values.join(', ')}'); + } + + final value = enumValues.entries + .singleWhere((e) => e.value == source, orElse: () => null) + ?.key; + + if (value == null && unknownValue == null) { + throw ArgumentError('`$source` is not one of the supported values: ' + '${enumValues.values.join(', ')}'); + } + return value ?? unknownValue; +} + +T _$enumDecodeNullable( + Map enumValues, + dynamic source, { + T unknownValue, +}) { + if (source == null) { + return null; + } + return _$enumDecode(enumValues, source, unknownValue: unknownValue); +} + +const _$EnumTypeEnumMap = { + EnumType.alpha: 'alpha', + EnumType.beta: 'beta', + EnumType.gamma: 'gamma', + EnumType.delta: 'delta', +}; + SimpleClassNum _$SimpleClassNumFromJson(Map json) { return SimpleClassNum( (json['value'] as List)?.map((e) => e as num)?.toSet(), diff --git a/json_serializable/test/supported_types/type_test.myenum_test.dart b/json_serializable/test/supported_types/type_test.enumtype_test.dart similarity index 96% rename from json_serializable/test/supported_types/type_test.myenum_test.dart rename to json_serializable/test/supported_types/type_test.enumtype_test.dart index 016d395b5..321452c71 100644 --- a/json_serializable/test/supported_types/type_test.myenum_test.dart +++ b/json_serializable/test/supported_types/type_test.enumtype_test.dart @@ -8,7 +8,7 @@ import 'package:test/test.dart'; import '../test_utils.dart'; -import 'input.type_myenum.dart'; +import 'input.type_enumtype.dart'; void main() { test('round trip', () { diff --git a/json_serializable/tool/test_type_builder.dart b/json_serializable/tool/test_type_builder.dart index 0f12d849b..0404f0d93 100644 --- a/json_serializable/tool/test_type_builder.dart +++ b/json_serializable/tool/test_type_builder.dart @@ -36,6 +36,11 @@ const _trivialTypesToTest = { 'dynamic': TestTypeData( altJsonExpression: "'dynamic'", ), + customEnumType: TestTypeData( + defaultExpression: '$customEnumType.alpha', + jsonExpression: "'alpha'", + altJsonExpression: "'beta'", + ), 'num': TestTypeData( defaultExpression: '88.6', altJsonExpression: '29', @@ -55,20 +60,6 @@ const _trivialTypesToTest = { final _typesToTest = { ..._trivialTypesToTest, - 'MyEnum': const TestTypeData( - defaultExpression: 'MyEnum.alpha', - jsonExpression: "'alpha'", - altJsonExpression: "'beta'", - replacements: [ - Replacement( - '@JsonSerializable()', - ''' -enum MyEnum { alpha, beta, gamma, delta } - -@JsonSerializable()''', - ) - ], - ), // // Collection types // @@ -101,7 +92,7 @@ const _mapKeyTypes = { 'BigInt', 'DateTime', 'dynamic', - // need enum! + 'EnumType', 'int', 'Object', 'String', diff --git a/json_serializable/tool/test_type_data.dart b/json_serializable/tool/test_type_data.dart index fc18a44a9..eaa8b265e 100644 --- a/json_serializable/tool/test_type_data.dart +++ b/json_serializable/tool/test_type_data.dart @@ -2,21 +2,23 @@ import 'package:meta/meta.dart'; import 'shared.dart'; +const customEnumType = 'EnumType'; + +const _annotationImport = + "import 'package:json_annotation/json_annotation.dart';"; + class TestTypeData { - final List _replacements; final String defaultExpression; final String jsonExpression; final String altJsonExpression; final Set genericArgs; const TestTypeData({ - List replacements, this.defaultExpression, String jsonExpression, @required String altJsonExpression, this.genericArgs = const {}, - }) : _replacements = replacements ?? const [], - jsonExpression = jsonExpression ?? defaultExpression, + }) : jsonExpression = jsonExpression ?? defaultExpression, altJsonExpression = altJsonExpression ?? jsonExpression ?? defaultExpression; @@ -29,12 +31,22 @@ class TestTypeData { final newPart = toTypeExtension(type, includeDotDart: false); - final buffer = StringBuffer(Replacement.generate(split[0], [ + final headerReplacements = [ + if (type == customEnumType || + genericArgs.any((element) => element.contains(customEnumType))) + const Replacement( + _annotationImport, + '$_annotationImport' + "import 'enum_type.dart';", + ), Replacement( "part 'input.g.dart';", "part 'input$newPart.g.dart';", ) - ])); + ]; + + final buffer = + StringBuffer(Replacement.generate(split[0], headerReplacements)); final simpleClassContent = '$classAnnotationSplit${split[1]}'; @@ -70,8 +82,6 @@ class TestTypeData { 'final $type nullable;', ); - yield* _replacements; - final defaultReplacement = (defaultExpression == null // no default provided || type.contains('<') // no support for default values and generic args From 85c58d166589a08cc5f4c86b0ba08e2027d9b2ba Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 6 Aug 2020 21:12:33 -0700 Subject: [PATCH 206/569] Change supported_types base type --- json_serializable/build.yaml | 4 +- .../test/supported_types/input.dart | 6 +- .../test/supported_types/input.g.dart | 6 +- ....type_dynamic.dart => input.type_int.dart} | 9 +- ...e_dynamic.g.dart => input.type_int.g.dart} | 9 +- .../supported_types/input.type_iterable.dart | 18 +++ .../input.type_iterable.g.dart | 13 ++ .../test/supported_types/input.type_list.dart | 18 +++ .../supported_types/input.type_list.g.dart | 13 ++ .../test/supported_types/input.type_map.dart | 144 +++++++++++++++++ .../supported_types/input.type_map.g.dart | 146 ++++++++++++++++++ .../test/supported_types/input.type_set.dart | 18 +++ .../supported_types/input.type_set.g.dart | 13 ++ ...amic_test.dart => type_test.int_test.dart} | 8 +- json_serializable/tool/test_type_builder.dart | 12 +- json_serializable/tool/test_type_data.dart | 8 +- 16 files changed, 420 insertions(+), 25 deletions(-) rename json_serializable/test/supported_types/{input.type_dynamic.dart => input.type_int.dart} (82%) rename json_serializable/test/supported_types/{input.type_dynamic.g.dart => input.type_int.g.dart} (72%) rename json_serializable/test/supported_types/{type_test.dynamic_test.dart => type_test.int_test.dart} (87%) diff --git a/json_serializable/build.yaml b/json_serializable/build.yaml index 566e85cd0..87e755c57 100644 --- a/json_serializable/build.yaml +++ b/json_serializable/build.yaml @@ -64,8 +64,8 @@ builders: - .type_datetime.dart - .type_double.dart - .type_duration.dart - - .type_dynamic.dart - .type_enumtype.dart + - .type_int.dart - .type_iterable.dart - .type_list.dart - .type_map.dart @@ -87,8 +87,8 @@ builders: - .datetime_test.dart - .double_test.dart - .duration_test.dart - - .dynamic_test.dart - .enumtype_test.dart + - .int_test.dart - .iterable_test.dart - .list_test.dart - .map_test.dart diff --git a/json_serializable/test/supported_types/input.dart b/json_serializable/test/supported_types/input.dart index ec1359ed3..61f84b8b5 100644 --- a/json_serializable/test/supported_types/input.dart +++ b/json_serializable/test/supported_types/input.dart @@ -8,13 +8,13 @@ part 'input.g.dart'; @JsonSerializable() class SimpleClass { - final int value; + final dynamic value; @JsonKey(nullable: false) - final int nullable; + final dynamic nullable; @JsonKey(defaultValue: 42) - int withDefault; + dynamic withDefault; SimpleClass( this.value, diff --git a/json_serializable/test/supported_types/input.g.dart b/json_serializable/test/supported_types/input.g.dart index c04f3338a..6200f9880 100644 --- a/json_serializable/test/supported_types/input.g.dart +++ b/json_serializable/test/supported_types/input.g.dart @@ -8,9 +8,9 @@ part of 'input.dart'; SimpleClass _$SimpleClassFromJson(Map json) { return SimpleClass( - json['value'] as int, - json['nullable'] as int, - )..withDefault = json['withDefault'] as int ?? 42; + json['value'], + json['nullable'], + )..withDefault = json['withDefault'] ?? 42; } Map _$SimpleClassToJson(SimpleClass instance) => diff --git a/json_serializable/test/supported_types/input.type_dynamic.dart b/json_serializable/test/supported_types/input.type_int.dart similarity index 82% rename from json_serializable/test/supported_types/input.type_dynamic.dart rename to json_serializable/test/supported_types/input.type_int.dart index e02cacaa4..42eb0e342 100644 --- a/json_serializable/test/supported_types/input.type_dynamic.dart +++ b/json_serializable/test/supported_types/input.type_int.dart @@ -4,14 +4,17 @@ import 'package:json_annotation/json_annotation.dart'; -part 'input.type_dynamic.g.dart'; +part 'input.type_int.g.dart'; @JsonSerializable() class SimpleClass { - final dynamic value; + final int value; @JsonKey(nullable: false) - final dynamic nullable; + final int nullable; + + @JsonKey(defaultValue: 42) + int withDefault; SimpleClass( this.value, diff --git a/json_serializable/test/supported_types/input.type_dynamic.g.dart b/json_serializable/test/supported_types/input.type_int.g.dart similarity index 72% rename from json_serializable/test/supported_types/input.type_dynamic.g.dart rename to json_serializable/test/supported_types/input.type_int.g.dart index e17aa9b11..99f4b297a 100644 --- a/json_serializable/test/supported_types/input.type_dynamic.g.dart +++ b/json_serializable/test/supported_types/input.type_int.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -part of 'input.type_dynamic.dart'; +part of 'input.type_int.dart'; // ************************************************************************** // JsonSerializableGenerator @@ -8,13 +8,14 @@ part of 'input.type_dynamic.dart'; SimpleClass _$SimpleClassFromJson(Map json) { return SimpleClass( - json['value'], - json['nullable'], - ); + json['value'] as int, + json['nullable'] as int, + )..withDefault = json['withDefault'] as int ?? 42; } Map _$SimpleClassToJson(SimpleClass instance) => { 'value': instance.value, 'nullable': instance.nullable, + 'withDefault': instance.withDefault, }; diff --git a/json_serializable/test/supported_types/input.type_iterable.dart b/json_serializable/test/supported_types/input.type_iterable.dart index ec2407a3b..0ba7d5f3c 100644 --- a/json_serializable/test/supported_types/input.type_iterable.dart +++ b/json_serializable/test/supported_types/input.type_iterable.dart @@ -154,6 +154,24 @@ class SimpleClassEnumType { Map toJson() => _$SimpleClassEnumTypeToJson(this); } +@JsonSerializable() +class SimpleClassInt { + final Iterable value; + + @JsonKey(nullable: false) + final Iterable nullable; + + SimpleClassInt( + this.value, + this.nullable, + ); + + factory SimpleClassInt.fromJson(Map json) => + _$SimpleClassIntFromJson(json); + + Map toJson() => _$SimpleClassIntToJson(this); +} + @JsonSerializable() class SimpleClassNum { final Iterable value; diff --git a/json_serializable/test/supported_types/input.type_iterable.g.dart b/json_serializable/test/supported_types/input.type_iterable.g.dart index fc4fd6abb..474f8ce78 100644 --- a/json_serializable/test/supported_types/input.type_iterable.g.dart +++ b/json_serializable/test/supported_types/input.type_iterable.g.dart @@ -157,6 +157,19 @@ const _$EnumTypeEnumMap = { EnumType.delta: 'delta', }; +SimpleClassInt _$SimpleClassIntFromJson(Map json) { + return SimpleClassInt( + (json['value'] as List)?.map((e) => e as int), + (json['nullable'] as List).map((e) => e as int), + ); +} + +Map _$SimpleClassIntToJson(SimpleClassInt instance) => + { + 'value': instance.value?.toList(), + 'nullable': instance.nullable.toList(), + }; + SimpleClassNum _$SimpleClassNumFromJson(Map json) { return SimpleClassNum( (json['value'] as List)?.map((e) => e as num), diff --git a/json_serializable/test/supported_types/input.type_list.dart b/json_serializable/test/supported_types/input.type_list.dart index 5b4e8e1c0..44219ef49 100644 --- a/json_serializable/test/supported_types/input.type_list.dart +++ b/json_serializable/test/supported_types/input.type_list.dart @@ -154,6 +154,24 @@ class SimpleClassEnumType { Map toJson() => _$SimpleClassEnumTypeToJson(this); } +@JsonSerializable() +class SimpleClassInt { + final List value; + + @JsonKey(nullable: false) + final List nullable; + + SimpleClassInt( + this.value, + this.nullable, + ); + + factory SimpleClassInt.fromJson(Map json) => + _$SimpleClassIntFromJson(json); + + Map toJson() => _$SimpleClassIntToJson(this); +} + @JsonSerializable() class SimpleClassNum { final List value; diff --git a/json_serializable/test/supported_types/input.type_list.g.dart b/json_serializable/test/supported_types/input.type_list.g.dart index 1560546a9..bcedf4688 100644 --- a/json_serializable/test/supported_types/input.type_list.g.dart +++ b/json_serializable/test/supported_types/input.type_list.g.dart @@ -165,6 +165,19 @@ const _$EnumTypeEnumMap = { EnumType.delta: 'delta', }; +SimpleClassInt _$SimpleClassIntFromJson(Map json) { + return SimpleClassInt( + (json['value'] as List)?.map((e) => e as int)?.toList(), + (json['nullable'] as List).map((e) => e as int).toList(), + ); +} + +Map _$SimpleClassIntToJson(SimpleClassInt instance) => + { + 'value': instance.value, + 'nullable': instance.nullable, + }; + SimpleClassNum _$SimpleClassNumFromJson(Map json) { return SimpleClassNum( (json['value'] as List)?.map((e) => e as num)?.toList(), diff --git a/json_serializable/test/supported_types/input.type_map.dart b/json_serializable/test/supported_types/input.type_map.dart index 46bf00aa5..8b351b6fc 100644 --- a/json_serializable/test/supported_types/input.type_map.dart +++ b/json_serializable/test/supported_types/input.type_map.dart @@ -1036,6 +1036,150 @@ class SimpleClassUriToEnumType { Map toJson() => _$SimpleClassUriToEnumTypeToJson(this); } +@JsonSerializable() +class SimpleClassBigIntToInt { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassBigIntToInt( + this.value, + this.nullable, + ); + + factory SimpleClassBigIntToInt.fromJson(Map json) => + _$SimpleClassBigIntToIntFromJson(json); + + Map toJson() => _$SimpleClassBigIntToIntToJson(this); +} + +@JsonSerializable() +class SimpleClassDateTimeToInt { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassDateTimeToInt( + this.value, + this.nullable, + ); + + factory SimpleClassDateTimeToInt.fromJson(Map json) => + _$SimpleClassDateTimeToIntFromJson(json); + + Map toJson() => _$SimpleClassDateTimeToIntToJson(this); +} + +@JsonSerializable() +class SimpleClassDynamicToInt { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassDynamicToInt( + this.value, + this.nullable, + ); + + factory SimpleClassDynamicToInt.fromJson(Map json) => + _$SimpleClassDynamicToIntFromJson(json); + + Map toJson() => _$SimpleClassDynamicToIntToJson(this); +} + +@JsonSerializable() +class SimpleClassEnumTypeToInt { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassEnumTypeToInt( + this.value, + this.nullable, + ); + + factory SimpleClassEnumTypeToInt.fromJson(Map json) => + _$SimpleClassEnumTypeToIntFromJson(json); + + Map toJson() => _$SimpleClassEnumTypeToIntToJson(this); +} + +@JsonSerializable() +class SimpleClassIntToInt { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassIntToInt( + this.value, + this.nullable, + ); + + factory SimpleClassIntToInt.fromJson(Map json) => + _$SimpleClassIntToIntFromJson(json); + + Map toJson() => _$SimpleClassIntToIntToJson(this); +} + +@JsonSerializable() +class SimpleClassObjectToInt { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassObjectToInt( + this.value, + this.nullable, + ); + + factory SimpleClassObjectToInt.fromJson(Map json) => + _$SimpleClassObjectToIntFromJson(json); + + Map toJson() => _$SimpleClassObjectToIntToJson(this); +} + +@JsonSerializable() +class SimpleClassStringToInt { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassStringToInt( + this.value, + this.nullable, + ); + + factory SimpleClassStringToInt.fromJson(Map json) => + _$SimpleClassStringToIntFromJson(json); + + Map toJson() => _$SimpleClassStringToIntToJson(this); +} + +@JsonSerializable() +class SimpleClassUriToInt { + final Map value; + + @JsonKey(nullable: false) + final Map nullable; + + SimpleClassUriToInt( + this.value, + this.nullable, + ); + + factory SimpleClassUriToInt.fromJson(Map json) => + _$SimpleClassUriToIntFromJson(json); + + Map toJson() => _$SimpleClassUriToIntToJson(this); +} + @JsonSerializable() class SimpleClassBigIntToNum { final Map value; diff --git a/json_serializable/test/supported_types/input.type_map.g.dart b/json_serializable/test/supported_types/input.type_map.g.dart index f793183e6..d1817bc25 100644 --- a/json_serializable/test/supported_types/input.type_map.g.dart +++ b/json_serializable/test/supported_types/input.type_map.g.dart @@ -1181,6 +1181,152 @@ Map _$SimpleClassUriToEnumTypeToJson( .map((k, e) => MapEntry(k.toString(), _$EnumTypeEnumMap[e])), }; +SimpleClassBigIntToInt _$SimpleClassBigIntToIntFromJson( + Map json) { + return SimpleClassBigIntToInt( + (json['value'] as Map)?.map( + (k, e) => MapEntry(BigInt.parse(k), e as int), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(BigInt.parse(k), e as int), + ), + ); +} + +Map _$SimpleClassBigIntToIntToJson( + SimpleClassBigIntToInt instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), + 'nullable': instance.nullable.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassDateTimeToInt _$SimpleClassDateTimeToIntFromJson( + Map json) { + return SimpleClassDateTimeToInt( + (json['value'] as Map)?.map( + (k, e) => MapEntry(DateTime.parse(k), e as int), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(DateTime.parse(k), e as int), + ), + ); +} + +Map _$SimpleClassDateTimeToIntToJson( + SimpleClassDateTimeToInt instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k.toIso8601String(), e)), + 'nullable': + instance.nullable.map((k, e) => MapEntry(k.toIso8601String(), e)), + }; + +SimpleClassDynamicToInt _$SimpleClassDynamicToIntFromJson( + Map json) { + return SimpleClassDynamicToInt( + (json['value'] as Map)?.map( + (k, e) => MapEntry(k, e as int), + ), + Map.from(json['nullable'] as Map), + ); +} + +Map _$SimpleClassDynamicToIntToJson( + SimpleClassDynamicToInt instance) => + { + 'value': instance.value, + 'nullable': instance.nullable, + }; + +SimpleClassEnumTypeToInt _$SimpleClassEnumTypeToIntFromJson( + Map json) { + return SimpleClassEnumTypeToInt( + (json['value'] as Map)?.map( + (k, e) => MapEntry(_$enumDecodeNullable(_$EnumTypeEnumMap, k), e as int), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as int), + ), + ); +} + +Map _$SimpleClassEnumTypeToIntToJson( + SimpleClassEnumTypeToInt instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), + 'nullable': + instance.nullable.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), + }; + +SimpleClassIntToInt _$SimpleClassIntToIntFromJson(Map json) { + return SimpleClassIntToInt( + (json['value'] as Map)?.map( + (k, e) => MapEntry(int.parse(k), e as int), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(int.parse(k), e as int), + ), + ); +} + +Map _$SimpleClassIntToIntToJson( + SimpleClassIntToInt instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), + 'nullable': instance.nullable.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassObjectToInt _$SimpleClassObjectToIntFromJson( + Map json) { + return SimpleClassObjectToInt( + (json['value'] as Map)?.map( + (k, e) => MapEntry(k, e as int), + ), + Map.from(json['nullable'] as Map), + ); +} + +Map _$SimpleClassObjectToIntToJson( + SimpleClassObjectToInt instance) => + { + 'value': instance.value, + 'nullable': instance.nullable, + }; + +SimpleClassStringToInt _$SimpleClassStringToIntFromJson( + Map json) { + return SimpleClassStringToInt( + (json['value'] as Map)?.map( + (k, e) => MapEntry(k, e as int), + ), + Map.from(json['nullable'] as Map), + ); +} + +Map _$SimpleClassStringToIntToJson( + SimpleClassStringToInt instance) => + { + 'value': instance.value, + 'nullable': instance.nullable, + }; + +SimpleClassUriToInt _$SimpleClassUriToIntFromJson(Map json) { + return SimpleClassUriToInt( + (json['value'] as Map)?.map( + (k, e) => MapEntry(Uri.parse(k), e as int), + ), + (json['nullable'] as Map).map( + (k, e) => MapEntry(Uri.parse(k), e as int), + ), + ); +} + +Map _$SimpleClassUriToIntToJson( + SimpleClassUriToInt instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), + 'nullable': instance.nullable.map((k, e) => MapEntry(k.toString(), e)), + }; + SimpleClassBigIntToNum _$SimpleClassBigIntToNumFromJson( Map json) { return SimpleClassBigIntToNum( diff --git a/json_serializable/test/supported_types/input.type_set.dart b/json_serializable/test/supported_types/input.type_set.dart index ef8301385..395345e2c 100644 --- a/json_serializable/test/supported_types/input.type_set.dart +++ b/json_serializable/test/supported_types/input.type_set.dart @@ -154,6 +154,24 @@ class SimpleClassEnumType { Map toJson() => _$SimpleClassEnumTypeToJson(this); } +@JsonSerializable() +class SimpleClassInt { + final Set value; + + @JsonKey(nullable: false) + final Set nullable; + + SimpleClassInt( + this.value, + this.nullable, + ); + + factory SimpleClassInt.fromJson(Map json) => + _$SimpleClassIntFromJson(json); + + Map toJson() => _$SimpleClassIntToJson(this); +} + @JsonSerializable() class SimpleClassNum { final Set value; diff --git a/json_serializable/test/supported_types/input.type_set.g.dart b/json_serializable/test/supported_types/input.type_set.g.dart index fadbed5ba..3958ec345 100644 --- a/json_serializable/test/supported_types/input.type_set.g.dart +++ b/json_serializable/test/supported_types/input.type_set.g.dart @@ -166,6 +166,19 @@ const _$EnumTypeEnumMap = { EnumType.delta: 'delta', }; +SimpleClassInt _$SimpleClassIntFromJson(Map json) { + return SimpleClassInt( + (json['value'] as List)?.map((e) => e as int)?.toSet(), + (json['nullable'] as List).map((e) => e as int).toSet(), + ); +} + +Map _$SimpleClassIntToJson(SimpleClassInt instance) => + { + 'value': instance.value?.toList(), + 'nullable': instance.nullable.toList(), + }; + SimpleClassNum _$SimpleClassNumFromJson(Map json) { return SimpleClassNum( (json['value'] as List)?.map((e) => e as num)?.toSet(), diff --git a/json_serializable/test/supported_types/type_test.dynamic_test.dart b/json_serializable/test/supported_types/type_test.int_test.dart similarity index 87% rename from json_serializable/test/supported_types/type_test.dynamic_test.dart rename to json_serializable/test/supported_types/type_test.int_test.dart index 0487a2eb5..53d59319c 100644 --- a/json_serializable/test/supported_types/type_test.dynamic_test.dart +++ b/json_serializable/test/supported_types/type_test.int_test.dart @@ -8,7 +8,7 @@ import 'package:test/test.dart'; import '../test_utils.dart'; -import 'input.type_dynamic.dart'; +import 'input.type_int.dart'; void main() { test('round trip', () { @@ -23,8 +23,8 @@ void main() { }); } -final _defaultValue = null; -final _altValue = 'dynamic'; +final _defaultValue = 42; +final _altValue = 43; final _emptyInput = { 'nullable': _defaultValue, @@ -33,9 +33,11 @@ final _emptyInput = { final _defaultOutput = { 'value': null, 'nullable': _defaultValue, + 'withDefault': _defaultValue, }; final _nonDefaultJson = { 'value': null, 'nullable': _altValue, + 'withDefault': _altValue, }; diff --git a/json_serializable/tool/test_type_builder.dart b/json_serializable/tool/test_type_builder.dart index 0404f0d93..a1eb4d18e 100644 --- a/json_serializable/tool/test_type_builder.dart +++ b/json_serializable/tool/test_type_builder.dart @@ -5,6 +5,7 @@ import 'dart:async'; import 'package:build/build.dart'; +import 'package:collection/collection.dart'; import 'package:dart_style/dart_style.dart'; import 'shared.dart'; @@ -33,8 +34,9 @@ const _trivialTypesToTest = { jsonExpression: '1234', altJsonExpression: '2345', ), - 'dynamic': TestTypeData( - altJsonExpression: "'dynamic'", + 'int': TestTypeData( + defaultExpression: '42', + altJsonExpression: '43', ), customEnumType: TestTypeData( defaultExpression: '$customEnumType.alpha', @@ -99,7 +101,11 @@ const _mapKeyTypes = { 'Uri', }; -final _iterableGenericArgs = _trivialTypesToTest.keys.toSet(); +final _iterableGenericArgs = ([ + ..._trivialTypesToTest.keys, + 'dynamic', +]..sort(compareAsciiLowerCase)) + .toSet(); const _defaultCollectionExpressions = '42, true, false, null'; const _altCollectionExpressions = '43, false'; diff --git a/json_serializable/tool/test_type_data.dart b/json_serializable/tool/test_type_data.dart index eaa8b265e..1036e3231 100644 --- a/json_serializable/tool/test_type_data.dart +++ b/json_serializable/tool/test_type_data.dart @@ -74,11 +74,11 @@ class TestTypeData { Iterable _libReplacements(String type) sync* { yield Replacement( - 'final int value;', + 'final dynamic value;', 'final $type value;', ); yield Replacement( - 'final int nullable;', + 'final dynamic nullable;', 'final $type nullable;', ); @@ -89,7 +89,7 @@ class TestTypeData { ? '' : _defaultSource .replaceFirst('42', defaultExpression) - .replaceFirst('int', type); + .replaceFirst('dynamic', type); yield Replacement( _defaultSource, @@ -133,7 +133,7 @@ final _altValue = $altJsonExpression; static const _defaultSource = r''' @JsonKey(defaultValue: 42) - int withDefault; + dynamic withDefault; '''; } From d74d97e9ce3346ca343f9f98da14c2c5bae6a387 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 10 Aug 2020 14:25:32 -0700 Subject: [PATCH 207/569] Prepare to release v3.4 (#686) --- json_serializable/CHANGELOG.md | 8 +++++--- json_serializable/pubspec.yaml | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 41c3f3097..91b238bd6 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,7 +1,9 @@ -## 3.4.0-dev +## 3.4.0 -- Added support for `double` constants as default values. -- Support `Set` literals in `JsonKey.defaultValue`. +- `JsonKey.defaultValue` + - Added support for `double.infinity`, `double.negativeInfinity`, and + `double.nan`. + - Added support for `Set` literals. - Require at least Dart `2.7.0`. ## 3.3.0 diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 489c0da20..c9a35f3e3 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 3.4.0-dev +version: 3.4.0 description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. From 28b382ef9da4d41fe1b04b48627f7b354f110820 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Fri, 14 Aug 2020 13:55:56 -0700 Subject: [PATCH 208/569] An example of using JsonConverter to change the encode/decode... ...of an existing type Closes https://github.com/google/json_serializable.dart/issues/660 --- example/lib/json_converter_example.dart | 25 +++++++++++++++++++++ example/lib/json_converter_example.g.dart | 11 +++++++++ example/test/json_convert_example_test.dart | 15 +++++++++++++ 3 files changed, 51 insertions(+) diff --git a/example/lib/json_converter_example.dart b/example/lib/json_converter_example.dart index 75c5f613e..172c38616 100644 --- a/example/lib/json_converter_example.dart +++ b/example/lib/json_converter_example.dart @@ -6,6 +6,31 @@ import 'package:json_annotation/json_annotation.dart'; part 'json_converter_example.g.dart'; +/// An example of using [JsonConverter] to change the encode/decode of a default +/// type. +@JsonSerializable(nullable: false) +@_DateTimeEpochConverter() +class DateTimeExample { + final DateTime when; + + DateTimeExample(this.when); + + factory DateTimeExample.fromJson(Map json) => + _$DateTimeExampleFromJson(json); + + Map toJson() => _$DateTimeExampleToJson(this); +} + +class _DateTimeEpochConverter implements JsonConverter { + const _DateTimeEpochConverter(); + + @override + DateTime fromJson(int json) => DateTime.fromMillisecondsSinceEpoch(json); + + @override + int toJson(DateTime object) => object.millisecondsSinceEpoch; +} + @JsonSerializable() class GenericCollection { @JsonKey(name: 'page') diff --git a/example/lib/json_converter_example.g.dart b/example/lib/json_converter_example.g.dart index 709e2e79b..334c76807 100644 --- a/example/lib/json_converter_example.g.dart +++ b/example/lib/json_converter_example.g.dart @@ -6,6 +6,17 @@ part of 'json_converter_example.dart'; // JsonSerializableGenerator // ************************************************************************** +DateTimeExample _$DateTimeExampleFromJson(Map json) { + return DateTimeExample( + const _DateTimeEpochConverter().fromJson(json['when'] as int), + ); +} + +Map _$DateTimeExampleToJson(DateTimeExample instance) => + { + 'when': const _DateTimeEpochConverter().toJson(instance.when), + }; + GenericCollection _$GenericCollectionFromJson(Map json) { return GenericCollection( page: json['page'] as int, diff --git a/example/test/json_convert_example_test.dart b/example/test/json_convert_example_test.dart index ecb4bf1c3..e3e09bce6 100644 --- a/example/test/json_convert_example_test.dart +++ b/example/test/json_convert_example_test.dart @@ -8,6 +8,21 @@ import 'package:example/json_converter_example.dart'; import 'package:test/test.dart'; void main() { + test('DateTime epoch', () { + const value = 42; + + final epochDateTime = DateTime.fromMillisecondsSinceEpoch(value); + final instance = DateTimeExample(epochDateTime); + final json = _encode(instance); + expect(json, '''{ + "when": $value +}'''); + + final copy = + DateTimeExample.fromJson(jsonDecode(json) as Map); + expect(copy.when, epochDateTime); + }); + test('trivial case', () { final collection = GenericCollection( page: 0, totalPages: 3, totalResults: 10, results: [1, 2, 3]); From 742460bf3cf0525bcdecd9dd1a2f1542697227f0 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Fri, 14 Aug 2020 14:36:06 -0700 Subject: [PATCH 209/569] small whitespace cleanup --- json_serializable/lib/src/decode_helper.dart | 24 ++++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/json_serializable/lib/src/decode_helper.dart b/json_serializable/lib/src/decode_helper.dart index 13df38e99..a8dff9406 100644 --- a/json_serializable/lib/src/decode_helper.dart +++ b/json_serializable/lib/src/decode_helper.dart @@ -37,14 +37,15 @@ abstract class DecodeHelper implements HelperCore { ctorParam: ctorParam); final data = _writeConstructorInvocation( - element, - accessibleFields.keys, - accessibleFields.values - .where((fe) => !fe.isFinal) - .map((fe) => fe.name) - .toList(), - unavailableReasons, - deserializeFun); + element, + accessibleFields.keys, + accessibleFields.values + .where((fe) => !fe.isFinal) + .map((fe) => fe.name) + .toList(), + unavailableReasons, + deserializeFun, + ); final checks = _checkKeys(accessibleFields.values .where((fe) => data.usedCtorParamsAndFields.contains(fe.name))); @@ -280,8 +281,11 @@ _ConstructorData _writeConstructorInvocation( usedCtorParamsAndFields.addAll(remainingFieldsForInvocationBody); - return _ConstructorData(buffer.toString(), remainingFieldsForInvocationBody, - usedCtorParamsAndFields); + return _ConstructorData( + buffer.toString(), + remainingFieldsForInvocationBody, + usedCtorParamsAndFields, + ); } class _ConstructorData { From 42403714727fe661ec33d6a528081bfd6aeedeab Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Fri, 14 Aug 2020 14:53:24 -0700 Subject: [PATCH 210/569] Support property with getter in a type and setter in super-type Fixes https://github.com/google/json_serializable.dart/issues/613 --- json_serializable/CHANGELOG.md | 5 ++++ json_serializable/lib/src/decode_helper.dart | 7 ++++- json_serializable/pubspec.yaml | 2 +- .../test/json_serializable_test.dart | 1 + .../src/_json_serializable_test_input.dart | 26 +++++++++++++++++++ 5 files changed, 39 insertions(+), 2 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 91b238bd6..85f075f06 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,8 @@ +## 3.4.1-dev + +- Support properties where the getter is defined in a class with a corresponding + setter in a super type. + ## 3.4.0 - `JsonKey.defaultValue` diff --git a/json_serializable/lib/src/decode_helper.dart b/json_serializable/lib/src/decode_helper.dart index a8dff9406..96c40f986 100644 --- a/json_serializable/lib/src/decode_helper.dart +++ b/json_serializable/lib/src/decode_helper.dart @@ -40,7 +40,12 @@ abstract class DecodeHelper implements HelperCore { element, accessibleFields.keys, accessibleFields.values - .where((fe) => !fe.isFinal) + .where((fe) => + !fe.isFinal || + // Handle the case where `fe` defines a getter in `element` + // and there is a setter in a super class + // See google/json_serializable.dart#613 + element.lookUpSetter(fe.name, element.library) != null) .map((fe) => fe.name) .toList(), unavailableReasons, diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index c9a35f3e3..cd764ba28 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 3.4.0 +version: 3.4.1-dev description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. diff --git a/json_serializable/test/json_serializable_test.dart b/json_serializable/test/json_serializable_test.dart index 71cbd7e62..9bfc6673c 100644 --- a/json_serializable/test/json_serializable_test.dart +++ b/json_serializable/test/json_serializable_test.dart @@ -82,6 +82,7 @@ const _expectedAnnotatedTests = [ 'OkayOneNormalOptionalPositional', 'OkayOnlyOptionalPositional', 'OnlyStaticMembers', + 'OverrideGetterExampleI613', 'PrivateFieldCtorClass', 'PropInMixinI448Regression', 'SetSupport', diff --git a/json_serializable/test/src/_json_serializable_test_input.dart b/json_serializable/test/src/_json_serializable_test_input.dart index 68b256381..cbe649eb1 100644 --- a/json_serializable/test/src/_json_serializable_test_input.dart +++ b/json_serializable/test/src/_json_serializable_test_input.dart @@ -502,3 +502,29 @@ class SubclassedJsonKey { class MyJsonKey extends JsonKey { const MyJsonKey() : super(name: 'bob'); } + +@ShouldGenerate( + r''' +OverrideGetterExampleI613 _$OverrideGetterExampleI613FromJson( + Map json) { + return OverrideGetterExampleI613()..id = json['id'] as String; +} + +Map _$OverrideGetterExampleI613ToJson( + OverrideGetterExampleI613 instance) => + { + 'id': instance.id, + }; +''', +) +@JsonSerializable(nullable: false) +class OverrideGetterExampleI613 extends OverrideGetterExampleI613Super { + @override + String get id => throw UnimplementedError(); +} + +class OverrideGetterExampleI613Super { + set id(String value) => throw UnimplementedError(); + + String get id => throw UnimplementedError(); +} From 609b2721d46bc0a96bff89d266bd0ce3ce2229da Mon Sep 17 00:00:00 2001 From: Evo Stamatov Date: Tue, 18 Aug 2020 03:21:52 +1000 Subject: [PATCH 211/569] Update README.md (#690) Make the setup part more prominent for newcomers. --- json_serializable/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/json_serializable/README.md b/json_serializable/README.md index f3b763275..e5dd8a0e3 100644 --- a/json_serializable/README.md +++ b/json_serializable/README.md @@ -15,6 +15,8 @@ in [package:json_annotation]. - To generate a Dart field with the contents of a file containing JSON, use the `JsonLiteral` annotation. +## Setup + To configure your project for the latest released version of, `json_serializable` see the [example]. From c6270c7c78d8c99f94729a41871609aae2653d16 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 25 Aug 2020 15:00:51 -0700 Subject: [PATCH 212/569] Update README.md Add version badges to each published package --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 62ab18738..3345319ae 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Provides [source_gen] `Generator`s to create code for JSON serialization and deserialization. -## json_serializable +## json_serializable [![Pub Package](https://img.shields.io/pub/v/json_serializable.svg)](https://pub.dev/packages/json_serializable) * Package: https://pub.dev/packages/json_serializable * [Source code](json_serializable) @@ -12,7 +12,7 @@ The core package providing Generators for JSON-specific tasks. Import it into your pubspec `dev_dependencies:` section. -## json_annotation +## json_annotation [![Pub Package](https://img.shields.io/pub/v/json_annotation.svg)](https://pub.dev/packages/json_annotation) * Package: https://pub.dev/packages/json_annotation * [Source code](json_annotation) @@ -21,7 +21,7 @@ The annotation package which has no dependencies. Import it into your pubspec `dependencies:` section. -## checked_yaml +## checked_yaml [![Pub Package](https://img.shields.io/pub/v/checked_yaml.svg)](https://pub.dev/packages/checked_yaml) * Package: https://pub.dev/packages/checked_yaml * [Source code](checked_yaml) From 48d8c249b2901e13a37bfd9a37981ca43d2981e4 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 25 Aug 2020 15:14:01 -0700 Subject: [PATCH 213/569] prepare to release v3.4.1 (#698) --- json_serializable/CHANGELOG.md | 2 +- json_serializable/pubspec.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 85f075f06..198ccc118 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,4 +1,4 @@ -## 3.4.1-dev +## 3.4.1 - Support properties where the getter is defined in a class with a corresponding setter in a super type. diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index cd764ba28..2e3a775bf 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 3.4.1-dev +version: 3.4.1 description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. From e17af52c10fc92fc488983c09e68ddc85d95b090 Mon Sep 17 00:00:00 2001 From: Johan Pelgrim Date: Thu, 27 Aug 2020 00:07:57 +0200 Subject: [PATCH 214/569] Allow annotated field with JsonKey.unknownEnumValue to be of type List (#691) Fixes https://github.com/google/json_serializable.dart/issues/585 --- json_serializable/CHANGELOG.md | 5 ++ json_serializable/lib/src/json_key_utils.dart | 7 +- json_serializable/pubspec.yaml | 2 +- .../test/json_serializable_test.dart | 1 + .../src/unknown_enum_value_test_input.dart | 65 ++++++++++++++++++- 5 files changed, 75 insertions(+), 5 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 198ccc118..d2bc7a7cf 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,8 @@ +## 3.4.2-dev + +- `JsonKey.unknownEnumValue` + - Added support for `unknownEnumValue` on `List` of enums + ## 3.4.1 - Support properties where the getter is defined in a class with a corresponding diff --git a/json_serializable/lib/src/json_key_utils.dart b/json_serializable/lib/src/json_key_utils.dart index 5c1a9c565..bce6e3900 100644 --- a/json_serializable/lib/src/json_key_utils.dart +++ b/json_serializable/lib/src/json_key_utils.dart @@ -127,7 +127,7 @@ JsonKey _from(FieldElement element, JsonSerializable classAnnotation) { /// Returns a literal object representing the value of [fieldName] in [obj]. /// /// If [mustBeEnum] is `true`, throws an [InvalidGenerationSourceError] if - /// either the annotated field is not an `enum` or if the value in + /// either the annotated field is not an `enum` or `List` or if the value in /// [fieldName] is not an `enum` value. Object _annotationValue(String fieldName, {bool mustBeEnum = false}) { final annotationValue = obj.read(fieldName); @@ -136,10 +136,11 @@ JsonKey _from(FieldElement element, JsonSerializable classAnnotation) { ? null : iterateEnumFields(annotationValue.objectValue.type); if (enumFields != null) { - if (mustBeEnum && !isEnum(element.type)) { + if (mustBeEnum && + !(isEnum(element.type) || element.type.isDartCoreList)) { throwUnsupported( element, - '`$fieldName` can only be set on fields of type enum.', + '`$fieldName` can only be set on fields of type enum or on lists.', ); } final enumValueNames = diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 2e3a775bf..c0d266e11 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 3.4.1 +version: 3.4.2-dev description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. diff --git a/json_serializable/test/json_serializable_test.dart b/json_serializable/test/json_serializable_test.dart index 9bfc6673c..2eb46c961 100644 --- a/json_serializable/test/json_serializable_test.dart +++ b/json_serializable/test/json_serializable_test.dart @@ -95,6 +95,7 @@ const _expectedAnnotatedTests = [ 'ToJsonNullableFalseIncludeIfNullFalse', 'TypedConvertMethods', 'UnknownEnumValue', + 'UnknownEnumValueList', 'UnknownEnumValueNotEnumValue', 'UnknownEnumValueNotEnumField', 'UnsupportedDateTimeField', diff --git a/json_serializable/test/src/unknown_enum_value_test_input.dart b/json_serializable/test/src/unknown_enum_value_test_input.dart index 221e7f819..dde4dcf9c 100644 --- a/json_serializable/test/src/unknown_enum_value_test_input.dart +++ b/json_serializable/test/src/unknown_enum_value_test_input.dart @@ -62,6 +62,69 @@ class UnknownEnumValue { UnknownEnumValueItems value; } +@ShouldGenerate( + r''' +UnknownEnumValueList _$UnknownEnumValueListFromJson(Map json) { + return UnknownEnumValueList() + ..value = (json['value'] as List) + ?.map((e) => _$enumDecodeNullable(_$UnknownEnumValueItemsEnumMap, e, + unknownValue: UnknownEnumValueItems.vUnknown)) + ?.toList() ?? + []; +} + +T _$enumDecode( + Map enumValues, + dynamic source, { + T unknownValue, +}) { + if (source == null) { + throw ArgumentError('A value must be provided. Supported values: ' + '${enumValues.values.join(', ')}'); + } + + final value = enumValues.entries + .singleWhere((e) => e.value == source, orElse: () => null) + ?.key; + + if (value == null && unknownValue == null) { + throw ArgumentError('`$source` is not one of the supported values: ' + '${enumValues.values.join(', ')}'); + } + return value ?? unknownValue; +} + +T _$enumDecodeNullable( + Map enumValues, + dynamic source, { + T unknownValue, +}) { + if (source == null) { + return null; + } + return _$enumDecode(enumValues, source, unknownValue: unknownValue); +} + +const _$UnknownEnumValueItemsEnumMap = { + UnknownEnumValueItems.v0: 'v0', + UnknownEnumValueItems.v1: 'v1', + UnknownEnumValueItems.v2: 'v2', + UnknownEnumValueItems.vUnknown: 'vUnknown', + UnknownEnumValueItems.vNull: 'vNull', +}; +''', +) +@JsonSerializable( + createToJson: false, +) +class UnknownEnumValueList { + @JsonKey( + defaultValue: [], + unknownEnumValue: UnknownEnumValueItems.vUnknown, + ) + List value; +} + enum UnknownEnumValueItems { v0, v1, v2, vUnknown, vNull } @ShouldThrow( @@ -76,7 +139,7 @@ class UnknownEnumValueNotEnumValue { @ShouldThrow( 'Error with `@JsonKey` on `value`. `unknownEnumValue` can only be set on ' - 'fields of type enum.', + 'fields of type enum or on lists.', ) @JsonSerializable() class UnknownEnumValueNotEnumField { From a22bd73eb8994f0884a10590f25b00080b2b3990 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 26 Aug 2020 16:08:08 -0700 Subject: [PATCH 215/569] Allow annotated field with JsonKey.unknownEnumValue to be Set or Iterable (#699) Throw an error in more cases if unknownEnumValue is used on an incompatible type Add a number of new tests Follow-up to https://github.com/google/json_serializable.dart/pull/691 --- json_serializable/CHANGELOG.md | 3 +- json_serializable/lib/src/json_key_utils.dart | 30 +++++-- .../test/integration/integration_test.dart | 14 +++ .../test/integration/json_test_example.dart | 20 +++++ .../test/integration/json_test_example.g.dart | 17 ++++ .../json_test_example.g_any_map.dart | 20 +++++ .../json_test_example.g_any_map.g.dart | 17 ++++ .../json_test_example.g_non_nullable.dart | 20 +++++ .../json_test_example.g_non_nullable.g.dart | 16 ++++ .../test/json_serializable_test.dart | 4 +- .../src/unknown_enum_value_test_input.dart | 88 +++++++------------ 11 files changed, 182 insertions(+), 67 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index d2bc7a7cf..5e82a95b6 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,7 +1,6 @@ ## 3.4.2-dev -- `JsonKey.unknownEnumValue` - - Added support for `unknownEnumValue` on `List` of enums +- `JsonKey.unknownEnumValue`: Added support `Iterable`, `List`, and `Set`. ## 3.4.1 diff --git a/json_serializable/lib/src/json_key_utils.dart b/json_serializable/lib/src/json_key_utils.dart index bce6e3900..28126e5e5 100644 --- a/json_serializable/lib/src/json_key_utils.dart +++ b/json_serializable/lib/src/json_key_utils.dart @@ -10,6 +10,7 @@ import 'package:json_annotation/json_annotation.dart'; import 'package:source_gen/source_gen.dart'; import 'json_literal_generator.dart'; +import 'shared_checkers.dart'; import 'utils.dart'; final _jsonKeyExpando = Expando(); @@ -136,13 +137,30 @@ JsonKey _from(FieldElement element, JsonSerializable classAnnotation) { ? null : iterateEnumFields(annotationValue.objectValue.type); if (enumFields != null) { - if (mustBeEnum && - !(isEnum(element.type) || element.type.isDartCoreList)) { - throwUnsupported( - element, - '`$fieldName` can only be set on fields of type enum or on lists.', - ); + if (mustBeEnum) { + DartType targetEnumType; + if (isEnum(element.type)) { + targetEnumType = element.type; + } else if (coreIterableTypeChecker.isAssignableFromType(element.type)) { + targetEnumType = coreIterableGenericType(element.type); + } else { + throwUnsupported( + element, + '`$fieldName` can only be set on fields of type enum or on ' + 'Iterable, List, or Set instances of an enum type.', + ); + } + assert(targetEnumType != null); + final annotatedEnumType = annotationValue.objectValue.type; + if (annotatedEnumType != targetEnumType) { + throwUnsupported( + element, + '`$fieldName` has type `$targetEnumType`, but the ' + 'provided unknownEnumValue is of type `$annotatedEnumType`.', + ); + } } + final enumValueNames = enumFields.map((p) => p.name).toList(growable: false); diff --git a/json_serializable/test/integration/integration_test.dart b/json_serializable/test/integration/integration_test.dart index 6c6954971..fa51cfbe2 100644 --- a/json_serializable/test/integration/integration_test.dart +++ b/json_serializable/test/integration/integration_test.dart @@ -266,4 +266,18 @@ void main() { expect(roundTrip, instance); }); + + test('UnknownEnumValue', () { + final instance = UnknownEnumValue.fromJson({ + 'enumValue': 'nope', + 'enumIterable': ['nope'], + 'enumList': ['nope'], + 'enumSet': ['nope'], + }); + + expect(instance.enumValue, Category.notDiscoveredYet); + expect(instance.enumIterable, [Category.notDiscoveredYet]); + expect(instance.enumList, [Category.notDiscoveredYet]); + expect(instance.enumSet, [Category.notDiscoveredYet]); + }); } diff --git a/json_serializable/test/integration/json_test_example.dart b/json_serializable/test/integration/json_test_example.dart index 911c4b11b..f23831961 100644 --- a/json_serializable/test/integration/json_test_example.dart +++ b/json_serializable/test/integration/json_test_example.dart @@ -174,3 +174,23 @@ class MapKeyVariety { deepEquals(other.dateTimeIntMap, dateTimeIntMap) && deepEquals(other.bigIntMap, bigIntMap); } + +@JsonSerializable(createToJson: false) +class UnknownEnumValue { + @JsonKey(unknownEnumValue: Category.notDiscoveredYet) + Category enumValue; + + @JsonKey(unknownEnumValue: Category.notDiscoveredYet) + Iterable enumIterable; + + @JsonKey(unknownEnumValue: Category.notDiscoveredYet) + List enumList; + + @JsonKey(unknownEnumValue: Category.notDiscoveredYet) + Set enumSet; + + UnknownEnumValue(); + + factory UnknownEnumValue.fromJson(Map json) => + _$UnknownEnumValueFromJson(json); +} diff --git a/json_serializable/test/integration/json_test_example.g.dart b/json_serializable/test/integration/json_test_example.g.dart index 09f7f3dc9..4ec605cc3 100644 --- a/json_serializable/test/integration/json_test_example.g.dart +++ b/json_serializable/test/integration/json_test_example.g.dart @@ -217,3 +217,20 @@ Map _$MapKeyVarietyToJson(MapKeyVariety instance) => ?.map((k, e) => MapEntry(k.toIso8601String(), e)), 'bigIntMap': instance.bigIntMap?.map((k, e) => MapEntry(k.toString(), e)), }; + +UnknownEnumValue _$UnknownEnumValueFromJson(Map json) { + return UnknownEnumValue() + ..enumValue = _$enumDecodeNullable(_$CategoryEnumMap, json['enumValue'], + unknownValue: Category.notDiscoveredYet) + ..enumIterable = (json['enumIterable'] as List)?.map((e) => + _$enumDecodeNullable(_$CategoryEnumMap, e, + unknownValue: Category.notDiscoveredYet)) + ..enumList = (json['enumList'] as List) + ?.map((e) => _$enumDecodeNullable(_$CategoryEnumMap, e, + unknownValue: Category.notDiscoveredYet)) + ?.toList() + ..enumSet = (json['enumSet'] as List) + ?.map((e) => _$enumDecodeNullable(_$CategoryEnumMap, e, + unknownValue: Category.notDiscoveredYet)) + ?.toSet(); +} diff --git a/json_serializable/test/integration/json_test_example.g_any_map.dart b/json_serializable/test/integration/json_test_example.g_any_map.dart index fe5f1422a..f781d5b5c 100644 --- a/json_serializable/test/integration/json_test_example.g_any_map.dart +++ b/json_serializable/test/integration/json_test_example.g_any_map.dart @@ -184,3 +184,23 @@ class MapKeyVariety { deepEquals(other.dateTimeIntMap, dateTimeIntMap) && deepEquals(other.bigIntMap, bigIntMap); } + +@JsonSerializable(anyMap: true, createToJson: false) +class UnknownEnumValue { + @JsonKey(unknownEnumValue: Category.notDiscoveredYet) + Category enumValue; + + @JsonKey(unknownEnumValue: Category.notDiscoveredYet) + Iterable enumIterable; + + @JsonKey(unknownEnumValue: Category.notDiscoveredYet) + List enumList; + + @JsonKey(unknownEnumValue: Category.notDiscoveredYet) + Set enumSet; + + UnknownEnumValue(); + + factory UnknownEnumValue.fromJson(Map json) => + _$UnknownEnumValueFromJson(json); +} diff --git a/json_serializable/test/integration/json_test_example.g_any_map.g.dart b/json_serializable/test/integration/json_test_example.g_any_map.g.dart index 79bd46a2d..e4f24df48 100644 --- a/json_serializable/test/integration/json_test_example.g_any_map.g.dart +++ b/json_serializable/test/integration/json_test_example.g_any_map.g.dart @@ -227,3 +227,20 @@ Map _$MapKeyVarietyToJson(MapKeyVariety instance) => ?.map((k, e) => MapEntry(k.toIso8601String(), e)), 'bigIntMap': instance.bigIntMap?.map((k, e) => MapEntry(k.toString(), e)), }; + +UnknownEnumValue _$UnknownEnumValueFromJson(Map json) { + return UnknownEnumValue() + ..enumValue = _$enumDecodeNullable(_$CategoryEnumMap, json['enumValue'], + unknownValue: Category.notDiscoveredYet) + ..enumIterable = (json['enumIterable'] as List)?.map((e) => + _$enumDecodeNullable(_$CategoryEnumMap, e, + unknownValue: Category.notDiscoveredYet)) + ..enumList = (json['enumList'] as List) + ?.map((e) => _$enumDecodeNullable(_$CategoryEnumMap, e, + unknownValue: Category.notDiscoveredYet)) + ?.toList() + ..enumSet = (json['enumSet'] as List) + ?.map((e) => _$enumDecodeNullable(_$CategoryEnumMap, e, + unknownValue: Category.notDiscoveredYet)) + ?.toSet(); +} diff --git a/json_serializable/test/integration/json_test_example.g_non_nullable.dart b/json_serializable/test/integration/json_test_example.g_non_nullable.dart index 500ba60ee..cb9928180 100644 --- a/json_serializable/test/integration/json_test_example.g_non_nullable.dart +++ b/json_serializable/test/integration/json_test_example.g_non_nullable.dart @@ -184,3 +184,23 @@ class MapKeyVariety { deepEquals(other.dateTimeIntMap, dateTimeIntMap) && deepEquals(other.bigIntMap, bigIntMap); } + +@JsonSerializable(nullable: false, createToJson: false) +class UnknownEnumValue { + @JsonKey(unknownEnumValue: Category.notDiscoveredYet) + Category enumValue; + + @JsonKey(unknownEnumValue: Category.notDiscoveredYet) + Iterable enumIterable; + + @JsonKey(unknownEnumValue: Category.notDiscoveredYet) + List enumList; + + @JsonKey(unknownEnumValue: Category.notDiscoveredYet) + Set enumSet; + + UnknownEnumValue(); + + factory UnknownEnumValue.fromJson(Map json) => + _$UnknownEnumValueFromJson(json); +} diff --git a/json_serializable/test/integration/json_test_example.g_non_nullable.g.dart b/json_serializable/test/integration/json_test_example.g_non_nullable.g.dart index ff4978e3b..6c0e324d6 100644 --- a/json_serializable/test/integration/json_test_example.g_non_nullable.g.dart +++ b/json_serializable/test/integration/json_test_example.g_non_nullable.g.dart @@ -185,3 +185,19 @@ Map _$MapKeyVarietyToJson(MapKeyVariety instance) => .map((k, e) => MapEntry(k.toIso8601String(), e)), 'bigIntMap': instance.bigIntMap.map((k, e) => MapEntry(k.toString(), e)), }; + +UnknownEnumValue _$UnknownEnumValueFromJson(Map json) { + return UnknownEnumValue() + ..enumValue = _$enumDecode(_$CategoryEnumMap, json['enumValue'], + unknownValue: Category.notDiscoveredYet) + ..enumIterable = (json['enumIterable'] as List).map((e) => _$enumDecode( + _$CategoryEnumMap, e, unknownValue: Category.notDiscoveredYet)) + ..enumList = (json['enumList'] as List) + .map((e) => _$enumDecode(_$CategoryEnumMap, e, + unknownValue: Category.notDiscoveredYet)) + .toList() + ..enumSet = (json['enumSet'] as List) + .map((e) => _$enumDecode(_$CategoryEnumMap, e, + unknownValue: Category.notDiscoveredYet)) + .toSet(); +} diff --git a/json_serializable/test/json_serializable_test.dart b/json_serializable/test/json_serializable_test.dart index 2eb46c961..597bd5362 100644 --- a/json_serializable/test/json_serializable_test.dart +++ b/json_serializable/test/json_serializable_test.dart @@ -95,8 +95,10 @@ const _expectedAnnotatedTests = [ 'ToJsonNullableFalseIncludeIfNullFalse', 'TypedConvertMethods', 'UnknownEnumValue', - 'UnknownEnumValueList', 'UnknownEnumValueNotEnumValue', + 'UnknownEnumValueListWrongEnumType', + 'UnknownEnumValueListWrongType', + 'UnknownEnumValueWrongEnumType', 'UnknownEnumValueNotEnumField', 'UnsupportedDateTimeField', 'UnsupportedDurationField', diff --git a/json_serializable/test/src/unknown_enum_value_test_input.dart b/json_serializable/test/src/unknown_enum_value_test_input.dart index dde4dcf9c..d156fa999 100644 --- a/json_serializable/test/src/unknown_enum_value_test_input.dart +++ b/json_serializable/test/src/unknown_enum_value_test_input.dart @@ -62,70 +62,42 @@ class UnknownEnumValue { UnknownEnumValueItems value; } -@ShouldGenerate( - r''' -UnknownEnumValueList _$UnknownEnumValueListFromJson(Map json) { - return UnknownEnumValueList() - ..value = (json['value'] as List) - ?.map((e) => _$enumDecodeNullable(_$UnknownEnumValueItemsEnumMap, e, - unknownValue: UnknownEnumValueItems.vUnknown)) - ?.toList() ?? - []; -} - -T _$enumDecode( - Map enumValues, - dynamic source, { - T unknownValue, -}) { - if (source == null) { - throw ArgumentError('A value must be provided. Supported values: ' - '${enumValues.values.join(', ')}'); - } - - final value = enumValues.entries - .singleWhere((e) => e.value == source, orElse: () => null) - ?.key; - - if (value == null && unknownValue == null) { - throw ArgumentError('`$source` is not one of the supported values: ' - '${enumValues.values.join(', ')}'); - } - return value ?? unknownValue; -} +enum UnknownEnumValueItems { v0, v1, v2, vUnknown, vNull } -T _$enumDecodeNullable( - Map enumValues, - dynamic source, { - T unknownValue, -}) { - if (source == null) { - return null; - } - return _$enumDecode(enumValues, source, unknownValue: unknownValue); +@ShouldThrow( + 'Error with `@JsonKey` on `value`. `unknownEnumValue` has type ' + '`int`, but the provided unknownEnumValue is of type ' + '`WrongEnumType`.', +) +@JsonSerializable() +class UnknownEnumValueListWrongType { + @JsonKey(unknownEnumValue: WrongEnumType.otherValue) + List value; } -const _$UnknownEnumValueItemsEnumMap = { - UnknownEnumValueItems.v0: 'v0', - UnknownEnumValueItems.v1: 'v1', - UnknownEnumValueItems.v2: 'v2', - UnknownEnumValueItems.vUnknown: 'vUnknown', - UnknownEnumValueItems.vNull: 'vNull', -}; -''', -) -@JsonSerializable( - createToJson: false, +@ShouldThrow( + 'Error with `@JsonKey` on `value`. `unknownEnumValue` has type ' + '`UnknownEnumValueItems`, but the provided unknownEnumValue is of type ' + '`WrongEnumType`.', ) -class UnknownEnumValueList { - @JsonKey( - defaultValue: [], - unknownEnumValue: UnknownEnumValueItems.vUnknown, - ) +@JsonSerializable() +class UnknownEnumValueListWrongEnumType { + @JsonKey(unknownEnumValue: WrongEnumType.otherValue) List value; } -enum UnknownEnumValueItems { v0, v1, v2, vUnknown, vNull } +enum WrongEnumType { otherValue } + +@ShouldThrow( + 'Error with `@JsonKey` on `value`. `unknownEnumValue` has type ' + '`UnknownEnumValueItems`, but the provided unknownEnumValue is of type ' + '`WrongEnumType`.', +) +@JsonSerializable() +class UnknownEnumValueWrongEnumType { + @JsonKey(unknownEnumValue: WrongEnumType.otherValue) + UnknownEnumValueItems value; +} @ShouldThrow( 'Error with `@JsonKey` on `value`. The value provided ' @@ -139,7 +111,7 @@ class UnknownEnumValueNotEnumValue { @ShouldThrow( 'Error with `@JsonKey` on `value`. `unknownEnumValue` can only be set on ' - 'fields of type enum or on lists.', + 'fields of type enum or on Iterable, List, or Set instances of an enum type.', ) @JsonSerializable() class UnknownEnumValueNotEnumField { From deaeae08f1f857b485be32df3088d917fd5a7a4e Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 26 Aug 2020 16:08:29 -0700 Subject: [PATCH 216/569] CI: Only validate format on dev (#700) --- .travis.yml | 18 ++++++------------ example/mono_pkg.yaml | 1 - json_annotation/mono_pkg.yaml | 1 - 3 files changed, 6 insertions(+), 14 deletions(-) diff --git a/.travis.yml b/.travis.yml index ab0c7c338..608a989ac 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,23 +9,17 @@ branches: jobs: include: - stage: analyzer_and_format - name: "SDK: dev; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; TASKS: [`dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-warnings --fatal-infos .`]" - dart: dev - os: linux - env: PKGS="_test_yaml checked_yaml example json_annotation json_serializable" - script: ./tool/travis.sh dartfmt dartanalyzer_0 - - stage: analyzer_and_format - name: "SDK: 2.7.0; PKGS: _test_yaml, checked_yaml, json_serializable; TASKS: `dartanalyzer --fatal-warnings .`" + name: "SDK: 2.7.0; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; TASKS: `dartanalyzer --fatal-warnings .`" dart: "2.7.0" os: linux - env: PKGS="_test_yaml checked_yaml json_serializable" + env: PKGS="_test_yaml checked_yaml example json_annotation json_serializable" script: ./tool/travis.sh dartanalyzer_1 - stage: analyzer_and_format - name: "SDK: 2.7.0; PKGS: example, json_annotation; TASKS: [`dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-warnings .`]" - dart: "2.7.0" + name: "SDK: dev; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; TASKS: [`dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-warnings --fatal-infos .`]" + dart: dev os: linux - env: PKGS="example json_annotation" - script: ./tool/travis.sh dartfmt dartanalyzer_1 + env: PKGS="_test_yaml checked_yaml example json_annotation json_serializable" + script: ./tool/travis.sh dartfmt dartanalyzer_0 - stage: unit_test name: "SDK: 2.7.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test`" dart: "2.7.0" diff --git a/example/mono_pkg.yaml b/example/mono_pkg.yaml index f4b867dc9..23b5859b6 100644 --- a/example/mono_pkg.yaml +++ b/example/mono_pkg.yaml @@ -10,7 +10,6 @@ stages: - dartanalyzer: --fatal-warnings --fatal-infos . dart: [dev] - group: - - dartfmt - dartanalyzer: --fatal-warnings . dart: [2.7.0] - unit_test: diff --git a/json_annotation/mono_pkg.yaml b/json_annotation/mono_pkg.yaml index 69fc1ffa3..1da53eb18 100644 --- a/json_annotation/mono_pkg.yaml +++ b/json_annotation/mono_pkg.yaml @@ -6,6 +6,5 @@ stages: - dartanalyzer: --fatal-warnings --fatal-infos . dart: [dev] - group: - - dartfmt - dartanalyzer: --fatal-warnings . dart: [2.7.0] From 316399adb2c0d50619f726f552e9c22bfbce12ab Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Sat, 5 Sep 2020 09:39:29 -0700 Subject: [PATCH 217/569] Remove no-longer-needed //ignore bits --- json_serializable/lib/src/field_helpers.dart | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/json_serializable/lib/src/field_helpers.dart b/json_serializable/lib/src/field_helpers.dart index d035908e6..932c43df5 100644 --- a/json_serializable/lib/src/field_helpers.dart +++ b/json_serializable/lib/src/field_helpers.dart @@ -36,10 +36,8 @@ class _FieldSet implements Comparable<_FieldSet> { int compareTo(_FieldSet other) => _sortByLocation(sortField, other.sortField); static int _sortByLocation(FieldElement a, FieldElement b) { - final checkerA = TypeChecker.fromStatic( - // TODO: remove `ignore` when min pkg:analyzer >= 0.38.0 - // ignore: unnecessary_cast - (a.enclosingElement as ClassElement).thisType); + final checkerA = + TypeChecker.fromStatic((a.enclosingElement as ClassElement).thisType); if (!checkerA.isExactly(b.enclosingElement)) { // in this case, you want to prioritize the enclosingElement that is more @@ -49,10 +47,8 @@ class _FieldSet implements Comparable<_FieldSet> { return -1; } - final checkerB = TypeChecker.fromStatic( - // TODO: remove `ignore` when min pkg:analyzer >= 0.38.0 - // ignore: unnecessary_cast - (b.enclosingElement as ClassElement).thisType); + final checkerB = + TypeChecker.fromStatic((b.enclosingElement as ClassElement).thisType); if (checkerB.isAssignableFrom(a.enclosingElement)) { return 1; From 4df9125d29456873e592faf62c0a7ce476d06a75 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Sat, 5 Sep 2020 11:39:18 -0700 Subject: [PATCH 218/569] Cleanup old API usage --- json_serializable/lib/src/utils.dart | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index 0c87fb6b3..56b942d8e 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -70,11 +70,7 @@ T enumValueForDartObject( List items, String Function(T) name, ) => - items.singleWhere( - (v) => source.getField(name(v)) != null, - // TODO: remove once pkg:analyzer < 0.35.0 is no longer supported - orElse: () => items[source.getField('index').toIntValue()], - ); + items.singleWhere((v) => source.getField(name(v)) != null); /// Return an instance of [JsonSerializable] corresponding to a the provided /// [reader]. From e8a5dbbf07c49f73355359ebb9a69daab1b6d3b1 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 26 Aug 2020 17:01:35 -0700 Subject: [PATCH 219/569] Regenerate JsonSerializable --- .../lib/src/json_serializable.g.dart | 38 ++++++++++++------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/json_annotation/lib/src/json_serializable.g.dart b/json_annotation/lib/src/json_serializable.g.dart index 68cec418b..f3d9112ea 100644 --- a/json_annotation/lib/src/json_serializable.g.dart +++ b/json_annotation/lib/src/json_serializable.g.dart @@ -18,7 +18,7 @@ JsonSerializable _$JsonSerializableFromJson(Map json) { 'field_rename', 'ignore_unannotated', 'include_if_null', - 'nullable', + 'nullable' ]); final val = JsonSerializable( anyMap: $checkedConvert(json, 'any_map', (v) => v as bool), @@ -45,7 +45,7 @@ JsonSerializable _$JsonSerializableFromJson(Map json) { 'explicitToJson': 'explicit_to_json', 'fieldRename': 'field_rename', 'ignoreUnannotated': 'ignore_unannotated', - 'includeIfNull': 'include_if_null', + 'includeIfNull': 'include_if_null' }); } @@ -63,29 +63,41 @@ Map _$JsonSerializableToJson(JsonSerializable instance) => 'nullable': instance.nullable, }; -T _$enumDecode(Map enumValues, dynamic source) { +T _$enumDecode( + Map enumValues, + dynamic source, { + T unknownValue, +}) { if (source == null) { throw ArgumentError('A value must be provided. Supported values: ' '${enumValues.values.join(', ')}'); } - return enumValues.entries - .singleWhere((e) => e.value == source, - orElse: () => throw ArgumentError( - '`$source` is not one of the supported values: ' - '${enumValues.values.join(', ')}')) - .key; + + final value = enumValues.entries + .singleWhere((e) => e.value == source, orElse: () => null) + ?.key; + + if (value == null && unknownValue == null) { + throw ArgumentError('`$source` is not one of the supported values: ' + '${enumValues.values.join(', ')}'); + } + return value ?? unknownValue; } -T _$enumDecodeNullable(Map enumValues, dynamic source) { +T _$enumDecodeNullable( + Map enumValues, + dynamic source, { + T unknownValue, +}) { if (source == null) { return null; } - return _$enumDecode(enumValues, source); + return _$enumDecode(enumValues, source, unknownValue: unknownValue); } -const _$FieldRenameEnumMap = { +const _$FieldRenameEnumMap = { FieldRename.none: 'none', FieldRename.kebab: 'kebab', FieldRename.snake: 'snake', - FieldRename.pascal: 'pascal' + FieldRename.pascal: 'pascal', }; From a92c1dae8ac7e66360cf8714516a154f7a9dfbce Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Sun, 6 Sep 2020 16:20:56 -0700 Subject: [PATCH 220/569] trailing comma cleanup --- json_serializable/lib/src/type_helper_ctx.dart | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/json_serializable/lib/src/type_helper_ctx.dart b/json_serializable/lib/src/type_helper_ctx.dart index 5de3f4590..8f4402521 100644 --- a/json_serializable/lib/src/type_helper_ctx.dart +++ b/json_serializable/lib/src/type_helper_ctx.dart @@ -71,7 +71,10 @@ class TypeHelperCtx _helperCore.allTypeHelpers.map(invoke).firstWhere( (r) => r != null, orElse: () => throw UnsupportedTypeError( - targetType, expression, _notSupportedWithTypeHelpersMsg), + targetType, + expression, + _notSupportedWithTypeHelpersMsg, + ), ); } From 4d88c4968db00f119e7688db3542bf5e9b0f0308 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 7 Sep 2020 14:21:04 -0700 Subject: [PATCH 221/569] cleanup TODOs --- checked_yaml/lib/checked_yaml.dart | 4 ++-- json_serializable/lib/src/json_key_utils.dart | 4 ++-- json_serializable/lib/src/type_helpers/json_helper.dart | 5 ++--- .../test/kitchen_sink/kitchen_sink_interface.dart | 2 +- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/checked_yaml/lib/checked_yaml.dart b/checked_yaml/lib/checked_yaml.dart index aabf3570c..f8d2aff94 100644 --- a/checked_yaml/lib/checked_yaml.dart +++ b/checked_yaml/lib/checked_yaml.dart @@ -37,7 +37,7 @@ T checkedYamlDecode( if (yaml is YamlMap) { map = yaml; } else if (allowNull && yaml is YamlScalar && yaml.value == null) { - // TODO(kevmoo): test this case! + // TODO: test this case! map = null; } else { throw ParsedYamlException('Not a map', yaml); @@ -79,7 +79,7 @@ ParsedYamlException toParsedYamlException( final yamlValue = yamlMap.nodes[exception.key]; if (yamlValue == null) { - // TODO(kevmoo): test this case! + // TODO: test this case! return ParsedYamlException( exception.message, yamlMap, diff --git a/json_serializable/lib/src/json_key_utils.dart b/json_serializable/lib/src/json_key_utils.dart index 28126e5e5..33fc48361 100644 --- a/json_serializable/lib/src/json_key_utils.dart +++ b/json_serializable/lib/src/json_key_utils.dart @@ -36,7 +36,7 @@ void logFieldWithConversionFunction(FieldElement element) { JsonKey _from(FieldElement element, JsonSerializable classAnnotation) { // If an annotation exists on `element` the source is a 'real' field. // If the result is `null`, check the getter – it is a property. - // TODO(kevmoo) setters: github.com/google/json_serializable.dart/issues/24 + // TODO: setters: github.com/google/json_serializable.dart/issues/24 final obj = jsonKeyAnnotation(element); if (obj.isNull) { @@ -66,7 +66,7 @@ JsonKey _from(FieldElement element, JsonSerializable classAnnotation) { } else if (reader.isType) { badType = 'Type'; } else if (dartObject.type is FunctionType) { - // TODO(kevmoo): Support calling function for the default value? + // TODO: Support calling function for the default value? badType = 'Function'; } else if (!reader.isLiteral) { badType = dartObject.type.element.name; diff --git a/json_serializable/lib/src/type_helpers/json_helper.dart b/json_serializable/lib/src/type_helpers/json_helper.dart index 4b64dbb0d..e9d75540c 100644 --- a/json_serializable/lib/src/type_helpers/json_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_helper.dart @@ -108,7 +108,7 @@ InterfaceType _instantiate( ) { final argTypes = ctorParamType.typeArguments.map((arg) { final typeParamIndex = classType.element.typeParameters.indexWhere( - // TODO(kevmoo): not 100% sure `nullabilitySuffix` is right + // TODO: not 100% sure `nullabilitySuffix` is right (e) => e.instantiate(nullabilitySuffix: arg.nullabilitySuffix) == arg); if (typeParamIndex >= 0) { return classType.typeArguments[typeParamIndex]; @@ -123,10 +123,9 @@ InterfaceType _instantiate( return null; } - // ignore: deprecated_member_use return ctorParamType.element.instantiate( typeArguments: argTypes, - // TODO(kevmoo): not 100% sure nullabilitySuffix is right... Works for now + // TODO: not 100% sure nullabilitySuffix is right... Works for now nullabilitySuffix: NullabilitySuffix.none, ); } diff --git a/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart b/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart index 28f1b4a2e..93916afac 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart @@ -78,7 +78,7 @@ abstract class KitchenSink { Map toJson(); } -//TODO(kevmoo) - finish this... +// TODO: finish this... bool sinkEquals(KitchenSink a, Object other) => other is KitchenSink && a.ctorValidatedNo42 == other.ctorValidatedNo42 && From 5b59e7f8f61f46dc365ca4bba43e0fc29d893baa Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 7 Sep 2020 14:21:40 -0700 Subject: [PATCH 222/569] MapHelper: tiny cleanup --- .../lib/src/type_helpers/map_helper.dart | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/json_serializable/lib/src/type_helpers/map_helper.dart b/json_serializable/lib/src/type_helpers/map_helper.dart index 7eff332e6..60d311d57 100644 --- a/json_serializable/lib/src/type_helpers/map_helper.dart +++ b/json_serializable/lib/src/type_helpers/map_helper.dart @@ -141,14 +141,17 @@ bool _isKeyStringable(DartType keyType) => void _checkSafeKeyType(String expression, DartType keyArg) { // We're not going to handle converting key types at the moment // So the only safe types for key are dynamic/Object/String/enum - final safeKey = isObjectOrDynamic(keyArg) || + if (isObjectOrDynamic(keyArg) || coreStringTypeChecker.isExactlyType(keyArg) || - _isKeyStringable(keyArg); - - if (!safeKey) { - throw UnsupportedTypeError(keyArg, expression, - 'Map keys must be one of: ${_allowedTypeNames.join(', ')}.'); + _isKeyStringable(keyArg)) { + return; } + + throw UnsupportedTypeError( + keyArg, + expression, + 'Map keys must be one of: ${_allowedTypeNames.join(', ')}.', + ); } /// The names of types that can be used as [Map] keys. From 2ef43c5dc9116aa9cb6d740020d640db849828c7 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 8 Sep 2020 15:41:49 -0700 Subject: [PATCH 223/569] Add JsonSerializable.genericArgumentFactories (#708) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When `true` on classes with type parameters (generic types), extra "helper" parameters will be generated for `fromJson` and/or `toJson` to support serializing values of those types. For example, the generated code for ```dart @JsonSerializable(genericArgumentFactories: true) class Response { int status; T value; } ``` Looks like ```dart Response _$ResponseFromJson( Map json, T Function(Object json) helperForT, ) { return Response() ..status = json['status'] as int ..value = helperForT(json['value']); } Map _$ResponseToJson( Response instance, Object Function(T value) helperForT, ) => { 'status': instance.status, 'value': helperForT(instance.value), }; ``` Note: this option has no effect on classes class without type parameters. A warning is printed in such cases. Note: if this option is set for all classes in a package via `build.yaml` it is only applied to classes with type parameters – so no warning is printed. Related to https://github.com/google/json_serializable.dart/issues/593 https://github.com/google/json_serializable.dart/issues/599 https://github.com/google/json_serializable.dart/issues/646 https://github.com/google/json_serializable.dart/issues/671 --- example/pubspec.yaml | 2 + json_annotation/CHANGELOG.md | 3 +- .../lib/src/json_serializable.dart | 48 +++++++++++++++++++ .../lib/src/json_serializable.g.dart | 7 ++- json_annotation/pubspec.yaml | 2 +- json_serializable/CHANGELOG.md | 5 +- json_serializable/README.md | 43 +++++++++-------- json_serializable/doc/doc.md | 42 ++++++++-------- json_serializable/lib/src/decode_helper.dart | 19 +++++++- json_serializable/lib/src/encoder_helper.dart | 17 ++++++- .../lib/src/json_serializable_generator.dart | 21 +++++++- .../type_helpers/generic_factory_helper.dart | 40 ++++++++++++++++ .../lib/src/type_helpers/json_helper.dart | 6 ++- json_serializable/lib/src/utils.dart | 17 ++++++- json_serializable/pubspec.yaml | 8 +++- json_serializable/test/config_test.dart | 1 + .../generic_argument_factories.dart | 35 ++++++++++++++ .../generic_argument_factories.g.dart | 30 ++++++++++++ .../test/generic_files/generic_test.dart | 34 +++++++++++++ .../test/json_serializable_test.dart | 1 + json_serializable/test/shared_config.dart | 1 + .../test/src/generic_test_input.dart | 23 +++++++++ .../test/test_sources/test_sources.dart | 1 + 23 files changed, 353 insertions(+), 53 deletions(-) create mode 100644 json_serializable/lib/src/type_helpers/generic_factory_helper.dart create mode 100644 json_serializable/test/generic_files/generic_argument_factories.dart create mode 100644 json_serializable/test/generic_files/generic_argument_factories.g.dart diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 65def5a49..dd154be3e 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -16,5 +16,7 @@ dev_dependencies: test: ^1.6.0 dependency_overrides: + json_annotation: + path: ../json_annotation json_serializable: path: ../json_serializable diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index f77426e03..f52224a20 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -1,5 +1,6 @@ -## 3.0.2-dev +## 3.1.0-dev +- Added `JsonSerializable.genericArgumentFactories` field. - Require at least Dart `2.7.0`. ## 3.0.1 diff --git a/json_annotation/lib/src/json_serializable.dart b/json_annotation/lib/src/json_serializable.dart index 08f74940f..61c730bf1 100644 --- a/json_annotation/lib/src/json_serializable.dart +++ b/json_annotation/lib/src/json_serializable.dart @@ -112,6 +112,50 @@ class JsonSerializable { /// fields annotated with [JsonKey]. final FieldRename fieldRename; + /// When `true` on classes with type parameters (generic types), extra + /// "helper" parameters will be generated for `fromJson` and/or `toJson` to + /// support serializing values of those types. + /// + /// For example, the generated code for + /// + /// ```dart + /// @JsonSerializable(genericArgumentFactories: true) + /// class Response { + /// int status; + /// T value; + /// } + /// ``` + /// + /// Looks like + /// + /// ```dart + /// Response _$ResponseFromJson( + /// Map json, + /// T Function(Object json) helperForT, + /// ) { + /// return Response() + /// ..status = json['status'] as int + /// ..value = helperForT(json['value']); + /// } + /// + /// Map _$ResponseToJson( + /// Response instance, + /// Object Function(T value) helperForT, + /// ) => + /// { + /// 'status': instance.status, + /// 'value': helperForT(instance.value), + /// }; + /// ``` + /// + /// Note: this option has no effect on classes class without type parameters. + /// A warning is printed in such cases. + /// + /// Note: if this option is set for all classes in a package via `build.yaml` + /// it is only applied to classes with type parameters – so no warning is + /// printed. + final bool genericArgumentFactories; + /// When `true`, only fields annotated with [JsonKey] will have code /// generated. /// @@ -151,6 +195,7 @@ class JsonSerializable { this.ignoreUnannotated, this.includeIfNull, this.nullable, + this.genericArgumentFactories, }); factory JsonSerializable.fromJson(Map json) => @@ -169,6 +214,7 @@ class JsonSerializable { ignoreUnannotated: false, includeIfNull: true, nullable: true, + genericArgumentFactories: false, ); /// Returns a new [JsonSerializable] instance with fields equal to the @@ -188,6 +234,8 @@ class JsonSerializable { ignoreUnannotated: ignoreUnannotated ?? defaults.ignoreUnannotated, includeIfNull: includeIfNull ?? defaults.includeIfNull, nullable: nullable ?? defaults.nullable, + genericArgumentFactories: + genericArgumentFactories ?? defaults.genericArgumentFactories, ); Map toJson() => _$JsonSerializableToJson(this); diff --git a/json_annotation/lib/src/json_serializable.g.dart b/json_annotation/lib/src/json_serializable.g.dart index f3d9112ea..1cf54e387 100644 --- a/json_annotation/lib/src/json_serializable.g.dart +++ b/json_annotation/lib/src/json_serializable.g.dart @@ -16,6 +16,7 @@ JsonSerializable _$JsonSerializableFromJson(Map json) { 'disallow_unrecognized_keys', 'explicit_to_json', 'field_rename', + 'generic_argument_factories', 'ignore_unannotated', 'include_if_null', 'nullable' @@ -35,6 +36,8 @@ JsonSerializable _$JsonSerializableFromJson(Map json) { $checkedConvert(json, 'ignore_unannotated', (v) => v as bool), includeIfNull: $checkedConvert(json, 'include_if_null', (v) => v as bool), nullable: $checkedConvert(json, 'nullable', (v) => v as bool), + genericArgumentFactories: + $checkedConvert(json, 'generic_argument_factories', (v) => v as bool), ); return val; }, fieldKeyMap: const { @@ -45,7 +48,8 @@ JsonSerializable _$JsonSerializableFromJson(Map json) { 'explicitToJson': 'explicit_to_json', 'fieldRename': 'field_rename', 'ignoreUnannotated': 'ignore_unannotated', - 'includeIfNull': 'include_if_null' + 'includeIfNull': 'include_if_null', + 'genericArgumentFactories': 'generic_argument_factories' }); } @@ -58,6 +62,7 @@ Map _$JsonSerializableToJson(JsonSerializable instance) => 'disallow_unrecognized_keys': instance.disallowUnrecognizedKeys, 'explicit_to_json': instance.explicitToJson, 'field_rename': _$FieldRenameEnumMap[instance.fieldRename], + 'generic_argument_factories': instance.genericArgumentFactories, 'ignore_unannotated': instance.ignoreUnannotated, 'include_if_null': instance.includeIfNull, 'nullable': instance.nullable, diff --git a/json_annotation/pubspec.yaml b/json_annotation/pubspec.yaml index bf2c5aa00..73571af85 100644 --- a/json_annotation/pubspec.yaml +++ b/json_annotation/pubspec.yaml @@ -1,5 +1,5 @@ name: json_annotation -version: 3.0.2-dev +version: 3.1.0-dev description: >- Classes and helper functions that support JSON code generation via the `json_serializable` package. diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 5e82a95b6..dffb4abf5 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,6 +1,7 @@ -## 3.4.2-dev +## 3.5.0-dev -- `JsonKey.unknownEnumValue`: Added support `Iterable`, `List`, and `Set`. +- Added support for `JsonSerializable.genericArgumentFactories`. +- `JsonKey.unknownEnumValue`: Added support for `Iterable`, `List`, and `Set`. ## 3.4.1 diff --git a/json_serializable/README.md b/json_serializable/README.md index e5dd8a0e3..31bd0e550 100644 --- a/json_serializable/README.md +++ b/json_serializable/README.md @@ -81,6 +81,7 @@ is generated: | disallow_unrecognized_keys | [JsonSerializable.disallowUnrecognizedKeys] | | | explicit_to_json | [JsonSerializable.explicitToJson] | | | field_rename | [JsonSerializable.fieldRename] | | +| generic_argument_factories | [JsonSerializable.genericArgumentFactories] | | | ignore_unannotated | [JsonSerializable.ignoreUnannotated] | | | include_if_null | [JsonSerializable.includeIfNull] | [JsonKey.includeIfNull] | | nullable | [JsonSerializable.nullable] | [JsonKey.nullable] | @@ -93,26 +94,27 @@ is generated: | | | [JsonKey.toJson] | | | | [JsonKey.unknownEnumValue] | -[JsonSerializable.anyMap]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonSerializable/anyMap.html -[JsonSerializable.checked]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonSerializable/checked.html -[JsonSerializable.createFactory]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonSerializable/createFactory.html -[JsonSerializable.createToJson]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonSerializable/createToJson.html -[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html -[JsonSerializable.explicitToJson]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonSerializable/explicitToJson.html -[JsonSerializable.fieldRename]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonSerializable/fieldRename.html -[JsonSerializable.ignoreUnannotated]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonSerializable/ignoreUnannotated.html -[JsonSerializable.includeIfNull]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonSerializable/includeIfNull.html -[JsonKey.includeIfNull]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonKey/includeIfNull.html -[JsonSerializable.nullable]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonSerializable/nullable.html -[JsonKey.nullable]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonKey/nullable.html -[JsonKey.defaultValue]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonKey/defaultValue.html -[JsonKey.disallowNullValue]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonKey/disallowNullValue.html -[JsonKey.fromJson]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonKey/fromJson.html -[JsonKey.ignore]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonKey/ignore.html -[JsonKey.name]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonKey/name.html -[JsonKey.required]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonKey/required.html -[JsonKey.toJson]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonKey/toJson.html -[JsonKey.unknownEnumValue]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonKey/unknownEnumValue.html +[JsonSerializable.anyMap]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/anyMap.html +[JsonSerializable.checked]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/checked.html +[JsonSerializable.createFactory]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/createFactory.html +[JsonSerializable.createToJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/createToJson.html +[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html +[JsonSerializable.explicitToJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/explicitToJson.html +[JsonSerializable.fieldRename]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/fieldRename.html +[JsonSerializable.genericArgumentFactories]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/genericArgumentFactories.html +[JsonSerializable.ignoreUnannotated]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/ignoreUnannotated.html +[JsonSerializable.includeIfNull]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/includeIfNull.html +[JsonKey.includeIfNull]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/includeIfNull.html +[JsonSerializable.nullable]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/nullable.html +[JsonKey.nullable]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/nullable.html +[JsonKey.defaultValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/defaultValue.html +[JsonKey.disallowNullValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/disallowNullValue.html +[JsonKey.fromJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/fromJson.html +[JsonKey.ignore]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/ignore.html +[JsonKey.name]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/name.html +[JsonKey.required]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/required.html +[JsonKey.toJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/toJson.html +[JsonKey.unknownEnumValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/unknownEnumValue.html > Note: every `JsonSerializable` field is configurable via `build.yaml` – see the table for the corresponding key. @@ -147,6 +149,7 @@ targets: disallow_unrecognized_keys: false explicit_to_json: false field_rename: none + generic_argument_factories: false ignore_unannotated: false include_if_null: true nullable: true diff --git a/json_serializable/doc/doc.md b/json_serializable/doc/doc.md index 569a63d58..0525ed7ac 100644 --- a/json_serializable/doc/doc.md +++ b/json_serializable/doc/doc.md @@ -7,6 +7,7 @@ | disallow_unrecognized_keys | [JsonSerializable.disallowUnrecognizedKeys] | | | explicit_to_json | [JsonSerializable.explicitToJson] | | | field_rename | [JsonSerializable.fieldRename] | | +| generic_argument_factories | [JsonSerializable.genericArgumentFactories] | | | ignore_unannotated | [JsonSerializable.ignoreUnannotated] | | | include_if_null | [JsonSerializable.includeIfNull] | [JsonKey.includeIfNull] | | nullable | [JsonSerializable.nullable] | [JsonKey.nullable] | @@ -19,23 +20,24 @@ | | | [JsonKey.toJson] | | | | [JsonKey.unknownEnumValue] | -[JsonSerializable.anyMap]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonSerializable/anyMap.html -[JsonSerializable.checked]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonSerializable/checked.html -[JsonSerializable.createFactory]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonSerializable/createFactory.html -[JsonSerializable.createToJson]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonSerializable/createToJson.html -[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html -[JsonSerializable.explicitToJson]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonSerializable/explicitToJson.html -[JsonSerializable.fieldRename]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonSerializable/fieldRename.html -[JsonSerializable.ignoreUnannotated]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonSerializable/ignoreUnannotated.html -[JsonSerializable.includeIfNull]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonSerializable/includeIfNull.html -[JsonKey.includeIfNull]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonKey/includeIfNull.html -[JsonSerializable.nullable]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonSerializable/nullable.html -[JsonKey.nullable]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonKey/nullable.html -[JsonKey.defaultValue]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonKey/defaultValue.html -[JsonKey.disallowNullValue]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonKey/disallowNullValue.html -[JsonKey.fromJson]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonKey/fromJson.html -[JsonKey.ignore]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonKey/ignore.html -[JsonKey.name]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonKey/name.html -[JsonKey.required]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonKey/required.html -[JsonKey.toJson]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonKey/toJson.html -[JsonKey.unknownEnumValue]: https://pub.dev/documentation/json_annotation/3.0.1/json_annotation/JsonKey/unknownEnumValue.html +[JsonSerializable.anyMap]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/anyMap.html +[JsonSerializable.checked]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/checked.html +[JsonSerializable.createFactory]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/createFactory.html +[JsonSerializable.createToJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/createToJson.html +[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html +[JsonSerializable.explicitToJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/explicitToJson.html +[JsonSerializable.fieldRename]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/fieldRename.html +[JsonSerializable.genericArgumentFactories]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/genericArgumentFactories.html +[JsonSerializable.ignoreUnannotated]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/ignoreUnannotated.html +[JsonSerializable.includeIfNull]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/includeIfNull.html +[JsonKey.includeIfNull]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/includeIfNull.html +[JsonSerializable.nullable]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/nullable.html +[JsonKey.nullable]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/nullable.html +[JsonKey.defaultValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/defaultValue.html +[JsonKey.disallowNullValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/disallowNullValue.html +[JsonKey.fromJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/fromJson.html +[JsonKey.ignore]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/ignore.html +[JsonKey.name]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/name.html +[JsonKey.required]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/required.html +[JsonKey.toJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/toJson.html +[JsonKey.unknownEnumValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/unknownEnumValue.html diff --git a/json_serializable/lib/src/decode_helper.dart b/json_serializable/lib/src/decode_helper.dart index 96c40f986..ca0da81c3 100644 --- a/json_serializable/lib/src/decode_helper.dart +++ b/json_serializable/lib/src/decode_helper.dart @@ -3,11 +3,13 @@ // BSD-style license that can be found in the LICENSE file. import 'package:analyzer/dart/element/element.dart'; +import 'package:analyzer/dart/element/nullability_suffix.dart'; import 'package:build/build.dart'; import 'package:source_gen/source_gen.dart'; import 'helper_core.dart'; import 'json_literal_generator.dart'; +import 'type_helpers/generic_factory_helper.dart'; import 'unsupported_type_error.dart'; import 'utils.dart'; @@ -29,7 +31,22 @@ abstract class DecodeHelper implements HelperCore { final mapType = config.anyMap ? 'Map' : 'Map'; buffer.write('$targetClassReference ' '${prefix}FromJson${genericClassArgumentsImpl(true)}' - '($mapType json) {\n'); + '($mapType json'); + + if (config.genericArgumentFactories) { + for (var arg in element.typeParameters) { + final helperName = helperForType( + arg.instantiate(nullabilitySuffix: NullabilitySuffix.none), + ); + + buffer.write(', ${arg.name} Function(Object json) $helperName'); + } + if (element.typeParameters.isNotEmpty) { + buffer.write(','); + } + } + + buffer.write(') {\n'); String deserializeFun(String paramOrFieldName, {ParameterElement ctorParam}) => diff --git a/json_serializable/lib/src/encoder_helper.dart b/json_serializable/lib/src/encoder_helper.dart index 12160bdab..52307c6ce 100644 --- a/json_serializable/lib/src/encoder_helper.dart +++ b/json_serializable/lib/src/encoder_helper.dart @@ -3,10 +3,12 @@ // BSD-style license that can be found in the LICENSE file. import 'package:analyzer/dart/element/element.dart'; +import 'package:analyzer/dart/element/nullability_suffix.dart'; import 'package:json_annotation/json_annotation.dart'; import 'constants.dart'; import 'helper_core.dart'; +import 'type_helpers/generic_factory_helper.dart'; import 'type_helpers/json_converter_helper.dart'; import 'unsupported_type_error.dart'; @@ -20,7 +22,20 @@ abstract class EncodeHelper implements HelperCore { final functionName = '${prefix}ToJson${genericClassArgumentsImpl(true)}'; buffer.write('Map ' - '$functionName($targetClassReference $_toJsonParamName) '); + '$functionName($targetClassReference $_toJsonParamName'); + + if (config.genericArgumentFactories) { + for (var arg in element.typeParameters) { + final helperName = helperForType( + arg.instantiate(nullabilitySuffix: NullabilitySuffix.none), + ); + buffer.write(',Object Function(${arg.name} value) $helperName'); + } + if (element.typeParameters.isNotEmpty) { + buffer.write(','); + } + } + buffer.write(') '); final writeNaive = accessibleFields.every(_writeJsonValueNaive); diff --git a/json_serializable/lib/src/json_serializable_generator.dart b/json_serializable/lib/src/json_serializable_generator.dart index 0cbb26ea3..388c0486e 100644 --- a/json_serializable/lib/src/json_serializable_generator.dart +++ b/json_serializable/lib/src/json_serializable_generator.dart @@ -17,6 +17,7 @@ import 'type_helpers/convert_helper.dart'; import 'type_helpers/date_time_helper.dart'; import 'type_helpers/duration_helper.dart'; import 'type_helpers/enum_helper.dart'; +import 'type_helpers/generic_factory_helper.dart'; import 'type_helpers/iterable_helper.dart'; import 'type_helpers/json_converter_helper.dart'; import 'type_helpers/json_helper.dart'; @@ -47,6 +48,7 @@ class JsonSerializableGenerator Iterable get _allHelpers => const [ ConvertHelper(), JsonConverterHelper(), + GenericFactoryHelper(), ].followedBy(_typeHelpers).followedBy(_coreHelpers); final JsonSerializable _config; @@ -106,7 +108,13 @@ class _GeneratorHelper extends HelperCore with EncodeHelper, DecodeHelper { this._generator, ClassElement element, ConstantReader annotation, - ) : super(element, mergeConfig(_generator.config, annotation)); + ) : super( + element, + mergeConfig( + _generator.config, + annotation, + classElement: element, + )); @override void addMember(String memberContent) { @@ -118,6 +126,17 @@ class _GeneratorHelper extends HelperCore with EncodeHelper, DecodeHelper { Iterable _generate() sync* { assert(_addedMembers.isEmpty); + + if (config.genericArgumentFactories && element.typeParameters.isEmpty) { + log.warning( + 'The class `${element.displayName}` is annotated ' + 'with `JsonSerializable` field `genericArgumentFactories: true`. ' + '`genericArgumentFactories: true` only affects classes with type ' + 'parameters. For classes without type parameters, the option is ' + 'ignored.', + ); + } + final sortedFields = createSortedFieldSet(element); // Used to keep track of why a field is ignored. Useful for providing diff --git a/json_serializable/lib/src/type_helpers/generic_factory_helper.dart b/json_serializable/lib/src/type_helpers/generic_factory_helper.dart new file mode 100644 index 000000000..de55c3ed7 --- /dev/null +++ b/json_serializable/lib/src/type_helpers/generic_factory_helper.dart @@ -0,0 +1,40 @@ +// Copyright (c) 2020, 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:analyzer/dart/element/type.dart'; + +import '../lambda_result.dart'; +import '../type_helper.dart'; + +class GenericFactoryHelper extends TypeHelper { + const GenericFactoryHelper(); + + @override + Object serialize( + DartType targetType, + String expression, + TypeHelperContextWithConfig context, + ) => + deserialize(targetType, expression, context); + + @override + Object deserialize( + DartType targetType, + String expression, + TypeHelperContextWithConfig context, + ) { + if (targetType is TypeParameterType) { + if (context.config.genericArgumentFactories) { + return LambdaResult(expression, helperForType(targetType)); + } + } + + return null; + } +} + +String helperForType(TypeParameterType type) => + helperForName(type.getDisplayString()); + +String helperForName(String genericType) => 'helperFor$genericType'; diff --git a/json_serializable/lib/src/type_helpers/json_helper.dart b/json_serializable/lib/src/type_helpers/json_helper.dart index e9d75540c..cce9f208f 100644 --- a/json_serializable/lib/src/type_helpers/json_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_helper.dart @@ -139,7 +139,11 @@ JsonSerializable _annotation(JsonSerializable config, InterfaceType source) { return null; } - return mergeConfig(config, ConstantReader(annotations.single)); + return mergeConfig( + config, + ConstantReader(annotations.single), + classElement: source.element, + ); } MethodElement _toJsonMethod(DartType type) => typeImplementations(type) diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index 56b942d8e..a353a8c20 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -6,7 +6,7 @@ import 'package:analyzer/dart/constant/value.dart'; import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/type.dart'; import 'package:json_annotation/json_annotation.dart'; -import 'package:meta/meta.dart' show alwaysThrows; +import 'package:meta/meta.dart' show alwaysThrows, required; import 'package:source_gen/source_gen.dart'; import 'helper_core.dart'; @@ -83,6 +83,8 @@ JsonSerializable _valueForAnnotation(ConstantReader reader) => JsonSerializable( reader.read('disallowUnrecognizedKeys').literalValue as bool, explicitToJson: reader.read('explicitToJson').literalValue as bool, fieldRename: _fromDartObject(reader.read('fieldRename')), + genericArgumentFactories: + reader.read('genericArgumentFactories').literalValue as bool, ignoreUnannotated: reader.read('ignoreUnannotated').literalValue as bool, includeIfNull: reader.read('includeIfNull').literalValue as bool, nullable: reader.read('nullable').literalValue as bool, @@ -93,7 +95,15 @@ JsonSerializable _valueForAnnotation(ConstantReader reader) => JsonSerializable( /// /// For fields that are not defined in [JsonSerializable] or `null` in [reader], /// use the values in [config]. -JsonSerializable mergeConfig(JsonSerializable config, ConstantReader reader) { +/// +/// Note: if [JsonSerializable.genericArgumentFactories] is `false` for [reader] +/// and `true` for [config], the corresponding field in the return value will +/// only be `true` if [classElement] has type parameters. +JsonSerializable mergeConfig( + JsonSerializable config, + ConstantReader reader, { + @required ClassElement classElement, +}) { final annotation = _valueForAnnotation(reader); return JsonSerializable( @@ -105,6 +115,9 @@ JsonSerializable mergeConfig(JsonSerializable config, ConstantReader reader) { annotation.disallowUnrecognizedKeys ?? config.disallowUnrecognizedKeys, explicitToJson: annotation.explicitToJson ?? config.explicitToJson, fieldRename: annotation.fieldRename ?? config.fieldRename, + genericArgumentFactories: annotation.genericArgumentFactories ?? + (classElement.typeParameters.isNotEmpty && + config.genericArgumentFactories), ignoreUnannotated: annotation.ignoreUnannotated ?? config.ignoreUnannotated, includeIfNull: annotation.includeIfNull ?? config.includeIfNull, nullable: annotation.nullable ?? config.nullable, diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index c0d266e11..4fbdd2ea1 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 3.4.2-dev +version: 3.5.0-dev description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. @@ -16,7 +16,7 @@ dependencies: # `json_annotation` properly constrains all features it provides. # For v3 only – allow a wide range since the only change was to REMOVE things # from json_annotation - json_annotation: '>=3.0.0 <3.1.0' + json_annotation: '>=3.1.0 <3.2.0' meta: ^1.1.0 path: ^1.3.2 source_gen: ^0.9.6 @@ -32,3 +32,7 @@ dev_dependencies: source_gen_test: ^0.1.0 test: ^1.6.0 yaml: ^2.1.13 + +dependency_overrides: + json_annotation: + path: ../json_annotation diff --git a/json_serializable/test/config_test.dart b/json_serializable/test/config_test.dart index a26d32b72..da4959572 100644 --- a/json_serializable/test/config_test.dart +++ b/json_serializable/test/config_test.dart @@ -139,6 +139,7 @@ const _invalidConfig = { 'disallow_unrecognized_keys': 42, 'explicit_to_json': 42, 'field_rename': 42, + 'generic_argument_factories': 42, 'ignore_unannotated': 42, 'include_if_null': 42, 'nullable': 42, diff --git a/json_serializable/test/generic_files/generic_argument_factories.dart b/json_serializable/test/generic_files/generic_argument_factories.dart new file mode 100644 index 000000000..79315c661 --- /dev/null +++ b/json_serializable/test/generic_files/generic_argument_factories.dart @@ -0,0 +1,35 @@ +// Copyright (c) 2018, 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:json_annotation/json_annotation.dart'; + +part 'generic_argument_factories.g.dart'; + +@JsonSerializable(genericArgumentFactories: true) +class GenericClassWithHelpers { + final T value; + + final List list; + + final Set someSet; + + GenericClassWithHelpers( + this.value, + this.list, + this.someSet, + ); + + factory GenericClassWithHelpers.fromJson( + Map json, + T Function(Object json) helperForT, + S Function(Object json) helperForS, + ) => + _$GenericClassWithHelpersFromJson(json, helperForT, helperForS); + + Map toJson( + Object Function(T value) helperForT, + Object Function(S value) helperForS, + ) => + _$GenericClassWithHelpersToJson(this, helperForT, helperForS); +} diff --git a/json_serializable/test/generic_files/generic_argument_factories.g.dart b/json_serializable/test/generic_files/generic_argument_factories.g.dart new file mode 100644 index 000000000..cf6546994 --- /dev/null +++ b/json_serializable/test/generic_files/generic_argument_factories.g.dart @@ -0,0 +1,30 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'generic_argument_factories.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +GenericClassWithHelpers _$GenericClassWithHelpersFromJson( + Map json, + T Function(Object json) helperForT, + S Function(Object json) helperForS, +) { + return GenericClassWithHelpers( + helperForT(json['value']), + (json['list'] as List)?.map(helperForT)?.toList(), + (json['someSet'] as List)?.map(helperForS)?.toSet(), + ); +} + +Map _$GenericClassWithHelpersToJson( + GenericClassWithHelpers instance, + Object Function(T value) helperForT, + Object Function(S value) helperForS, +) => + { + 'value': helperForT(instance.value), + 'list': instance.list?.map(helperForT)?.toList(), + 'someSet': instance.someSet?.map(helperForS)?.toList(), + }; diff --git a/json_serializable/test/generic_files/generic_test.dart b/json_serializable/test/generic_files/generic_test.dart index d4f6d1f4c..8e50345d5 100644 --- a/json_serializable/test/generic_files/generic_test.dart +++ b/json_serializable/test/generic_files/generic_test.dart @@ -3,9 +3,11 @@ // BSD-style license that can be found in the LICENSE file. import 'dart:convert'; + import 'package:test/test.dart'; import '../test_utils.dart'; +import 'generic_argument_factories.dart'; import 'generic_class.dart'; void main() { @@ -49,4 +51,36 @@ void main() { throwsCastError); }); }); + + group('genericArgumentFactories', () { + test('basic round-trip', () { + final instance = GenericClassWithHelpers( + DateTime.fromMillisecondsSinceEpoch(0).toUtc(), + [ + DateTime.fromMillisecondsSinceEpoch(1).toUtc(), + DateTime.fromMillisecondsSinceEpoch(2).toUtc(), + ], + {const Duration(milliseconds: 3), const Duration(milliseconds: 4)}, + ); + + String encodeDateTime(DateTime value) => value?.toIso8601String(); + int encodeDuration(Duration value) => value.inMilliseconds; + + final encodedJson = loudEncode( + instance.toJson(encodeDateTime, encodeDuration), + ); + + final decoded = GenericClassWithHelpers.fromJson( + jsonDecode(encodedJson) as Map, + (value) => DateTime.parse(value as String), + (value) => Duration(milliseconds: value as int), + ); + + final encodedJson2 = loudEncode( + decoded.toJson(encodeDateTime, encodeDuration), + ); + + expect(encodedJson2, encodedJson); + }); + }); } diff --git a/json_serializable/test/json_serializable_test.dart b/json_serializable/test/json_serializable_test.dart index 597bd5362..e7f1b4f66 100644 --- a/json_serializable/test/json_serializable_test.dart +++ b/json_serializable/test/json_serializable_test.dart @@ -51,6 +51,7 @@ const _expectedAnnotatedTests = [ 'FromDynamicCollection', 'GeneralTestClass1', 'GeneralTestClass2', + 'GenericArgumentFactoriesFlagWithoutGenericType', 'GenericClass', 'IgnoredFieldClass', 'IgnoredFieldCtorClass', diff --git a/json_serializable/test/shared_config.dart b/json_serializable/test/shared_config.dart index 1a74c1453..e8a38d5e0 100644 --- a/json_serializable/test/shared_config.dart +++ b/json_serializable/test/shared_config.dart @@ -21,4 +21,5 @@ final generatorConfigNonDefaultJson = ignoreUnannotated: true, includeIfNull: false, nullable: false, + genericArgumentFactories: true, ).toJson()); diff --git a/json_serializable/test/src/generic_test_input.dart b/json_serializable/test/src/generic_test_input.dart index 3adeafea9..6b7a143d9 100644 --- a/json_serializable/test/src/generic_test_input.dart +++ b/json_serializable/test/src/generic_test_input.dart @@ -48,3 +48,26 @@ class GenericClass { T _dataFromJson(Object input) => null; Object _dataToJson(T input) => null; + +@ShouldGenerate( + r''' +GenericArgumentFactoriesFlagWithoutGenericType + _$GenericArgumentFactoriesFlagWithoutGenericTypeFromJson( + Map json) { + return GenericArgumentFactoriesFlagWithoutGenericType(); +} + +Map _$GenericArgumentFactoriesFlagWithoutGenericTypeToJson( + GenericArgumentFactoriesFlagWithoutGenericType instance) => + {}; +''', + expectedLogItems: [ + 'The class `GenericArgumentFactoriesFlagWithoutGenericType` is annotated ' + 'with `JsonSerializable` field `genericArgumentFactories: true`. ' + '`genericArgumentFactories: true` only affects classes with type ' + 'parameters. For classes without type parameters, the option is ' + 'ignored.', + ], +) +@JsonSerializable(genericArgumentFactories: true) +class GenericArgumentFactoriesFlagWithoutGenericType {} diff --git a/json_serializable/test/test_sources/test_sources.dart b/json_serializable/test/test_sources/test_sources.dart index 0a44c53de..198398e53 100644 --- a/json_serializable/test/test_sources/test_sources.dart +++ b/json_serializable/test/test_sources/test_sources.dart @@ -16,6 +16,7 @@ class ConfigurationImplicitDefaults { ignoreUnannotated: false, includeIfNull: true, nullable: true, + genericArgumentFactories: false, ) class ConfigurationExplicitDefaults { int field; From ec2f0ce061b93fc78fc3d0858d992beaaf82f603 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 8 Sep 2020 17:25:49 -0700 Subject: [PATCH 224/569] Rename function params to have more descriptive names (#709) --- .../lib/src/json_serializable.dart | 8 +++--- json_serializable/lib/src/decode_helper.dart | 2 +- json_serializable/lib/src/encoder_helper.dart | 2 +- .../type_helpers/generic_factory_helper.dart | 28 +++++++++++++------ .../generic_argument_factories.dart | 12 ++++---- .../generic_argument_factories.g.dart | 20 ++++++------- 6 files changed, 41 insertions(+), 31 deletions(-) diff --git a/json_annotation/lib/src/json_serializable.dart b/json_annotation/lib/src/json_serializable.dart index 61c730bf1..d1fa14222 100644 --- a/json_annotation/lib/src/json_serializable.dart +++ b/json_annotation/lib/src/json_serializable.dart @@ -131,20 +131,20 @@ class JsonSerializable { /// ```dart /// Response _$ResponseFromJson( /// Map json, - /// T Function(Object json) helperForT, + /// T Function(Object json) fromJsonT, /// ) { /// return Response() /// ..status = json['status'] as int - /// ..value = helperForT(json['value']); + /// ..value = fromJsonT(json['value']); /// } /// /// Map _$ResponseToJson( /// Response instance, - /// Object Function(T value) helperForT, + /// Object Function(T value) toJsonT, /// ) => /// { /// 'status': instance.status, - /// 'value': helperForT(instance.value), + /// 'value': toJsonT(instance.value), /// }; /// ``` /// diff --git a/json_serializable/lib/src/decode_helper.dart b/json_serializable/lib/src/decode_helper.dart index ca0da81c3..1d18e69a5 100644 --- a/json_serializable/lib/src/decode_helper.dart +++ b/json_serializable/lib/src/decode_helper.dart @@ -35,7 +35,7 @@ abstract class DecodeHelper implements HelperCore { if (config.genericArgumentFactories) { for (var arg in element.typeParameters) { - final helperName = helperForType( + final helperName = fromJsonForType( arg.instantiate(nullabilitySuffix: NullabilitySuffix.none), ); diff --git a/json_serializable/lib/src/encoder_helper.dart b/json_serializable/lib/src/encoder_helper.dart index 52307c6ce..806737481 100644 --- a/json_serializable/lib/src/encoder_helper.dart +++ b/json_serializable/lib/src/encoder_helper.dart @@ -26,7 +26,7 @@ abstract class EncodeHelper implements HelperCore { if (config.genericArgumentFactories) { for (var arg in element.typeParameters) { - final helperName = helperForType( + final helperName = toJsonForType( arg.instantiate(nullabilitySuffix: NullabilitySuffix.none), ); buffer.write(',Object Function(${arg.name} value) $helperName'); diff --git a/json_serializable/lib/src/type_helpers/generic_factory_helper.dart b/json_serializable/lib/src/type_helpers/generic_factory_helper.dart index de55c3ed7..7f2f7119a 100644 --- a/json_serializable/lib/src/type_helpers/generic_factory_helper.dart +++ b/json_serializable/lib/src/type_helpers/generic_factory_helper.dart @@ -15,8 +15,14 @@ class GenericFactoryHelper extends TypeHelper { DartType targetType, String expression, TypeHelperContextWithConfig context, - ) => - deserialize(targetType, expression, context); + ) { + if (context.config.genericArgumentFactories && + targetType is TypeParameterType) { + return LambdaResult(expression, toJsonForType(targetType)); + } + + return null; + } @override Object deserialize( @@ -24,17 +30,21 @@ class GenericFactoryHelper extends TypeHelper { String expression, TypeHelperContextWithConfig context, ) { - if (targetType is TypeParameterType) { - if (context.config.genericArgumentFactories) { - return LambdaResult(expression, helperForType(targetType)); - } + if (context.config.genericArgumentFactories && + targetType is TypeParameterType) { + return LambdaResult(expression, fromJsonForType(targetType)); } return null; } } -String helperForType(TypeParameterType type) => - helperForName(type.getDisplayString()); +String toJsonForType(TypeParameterType type) => + toJsonForName(type.getDisplayString()); + +String toJsonForName(String genericType) => 'toJson$genericType'; + +String fromJsonForType(TypeParameterType type) => + fromJsonForName(type.getDisplayString()); -String helperForName(String genericType) => 'helperFor$genericType'; +String fromJsonForName(String genericType) => 'fromJson$genericType'; diff --git a/json_serializable/test/generic_files/generic_argument_factories.dart b/json_serializable/test/generic_files/generic_argument_factories.dart index 79315c661..bb83747f6 100644 --- a/json_serializable/test/generic_files/generic_argument_factories.dart +++ b/json_serializable/test/generic_files/generic_argument_factories.dart @@ -22,14 +22,14 @@ class GenericClassWithHelpers { factory GenericClassWithHelpers.fromJson( Map json, - T Function(Object json) helperForT, - S Function(Object json) helperForS, + T Function(Object json) fromJsonT, + S Function(Object json) fromJsonS, ) => - _$GenericClassWithHelpersFromJson(json, helperForT, helperForS); + _$GenericClassWithHelpersFromJson(json, fromJsonT, fromJsonS); Map toJson( - Object Function(T value) helperForT, - Object Function(S value) helperForS, + Object Function(T value) toJsonT, + Object Function(S value) toJsonS, ) => - _$GenericClassWithHelpersToJson(this, helperForT, helperForS); + _$GenericClassWithHelpersToJson(this, toJsonT, toJsonS); } diff --git a/json_serializable/test/generic_files/generic_argument_factories.g.dart b/json_serializable/test/generic_files/generic_argument_factories.g.dart index cf6546994..aa8fa7197 100644 --- a/json_serializable/test/generic_files/generic_argument_factories.g.dart +++ b/json_serializable/test/generic_files/generic_argument_factories.g.dart @@ -8,23 +8,23 @@ part of 'generic_argument_factories.dart'; GenericClassWithHelpers _$GenericClassWithHelpersFromJson( Map json, - T Function(Object json) helperForT, - S Function(Object json) helperForS, + T Function(Object json) fromJsonT, + S Function(Object json) fromJsonS, ) { return GenericClassWithHelpers( - helperForT(json['value']), - (json['list'] as List)?.map(helperForT)?.toList(), - (json['someSet'] as List)?.map(helperForS)?.toSet(), + fromJsonT(json['value']), + (json['list'] as List)?.map(fromJsonT)?.toList(), + (json['someSet'] as List)?.map(fromJsonS)?.toSet(), ); } Map _$GenericClassWithHelpersToJson( GenericClassWithHelpers instance, - Object Function(T value) helperForT, - Object Function(S value) helperForS, + Object Function(T value) toJsonT, + Object Function(S value) toJsonS, ) => { - 'value': helperForT(instance.value), - 'list': instance.list?.map(helperForT)?.toList(), - 'someSet': instance.someSet?.map(helperForS)?.toList(), + 'value': toJsonT(instance.value), + 'list': instance.list?.map(toJsonT)?.toList(), + 'someSet': instance.someSet?.map(toJsonS)?.toList(), }; From d09c99fb33696762bb1bfc32fbff65a745375d29 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 9 Sep 2020 13:34:18 -0700 Subject: [PATCH 225/569] Add support for generic helper functions for fields with generic type parameters (#710) Builds on support for `JsonSerializable.genericArgumentFactories` to populate the encode/decode parameters with functions corresponding to the provided type arguments. Fixes https://github.com/google/json_serializable.dart/issues/593 --- example/lib/tuple_example.dart | 43 ++++++ example/lib/tuple_example.g.dart | 51 +++++++ example/test/tuple_example_test.dart | 41 +++++ json_serializable/CHANGELOG.md | 37 +++++ .../lib/src/type_helpers/json_helper.dart | 143 +++++++++++++++++- .../generic_argument_factories.dart | 14 ++ .../generic_argument_factories.g.dart | 29 ++++ .../test/generic_files/generic_test.dart | 32 ++++ .../test/json_serializable_test.dart | 3 + .../src/_json_serializable_test_input.dart | 52 +++++++ 10 files changed, 440 insertions(+), 5 deletions(-) create mode 100644 example/lib/tuple_example.dart create mode 100644 example/lib/tuple_example.g.dart create mode 100644 example/test/tuple_example_test.dart diff --git a/example/lib/tuple_example.dart b/example/lib/tuple_example.dart new file mode 100644 index 000000000..697446e4a --- /dev/null +++ b/example/lib/tuple_example.dart @@ -0,0 +1,43 @@ +// Copyright (c) 2020, 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:json_annotation/json_annotation.dart'; + +part 'tuple_example.g.dart'; + +@JsonSerializable(genericArgumentFactories: true) +class Tuple { + final T value1; + + final S value2; + + Tuple(this.value1, this.value2); + + factory Tuple.fromJson( + Map json, + T Function(Object json) fromJsonT, + S Function(Object json) fromJsonS, + ) => + _$TupleFromJson(json, fromJsonT, fromJsonS); + + Map toJson( + Object Function(T value) toJsonT, + Object Function(S value) toJsonS, + ) => + _$TupleToJson(this, toJsonT, toJsonS); +} + +@JsonSerializable(nullable: false) +class ConcreteClass { + final Tuple tuple1; + + final Tuple tuple2; + + ConcreteClass(this.tuple1, this.tuple2); + + factory ConcreteClass.fromJson(Map json) => + _$ConcreteClassFromJson(json); + + Map toJson() => _$ConcreteClassToJson(this); +} diff --git a/example/lib/tuple_example.g.dart b/example/lib/tuple_example.g.dart new file mode 100644 index 000000000..e27d82219 --- /dev/null +++ b/example/lib/tuple_example.g.dart @@ -0,0 +1,51 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'tuple_example.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +Tuple _$TupleFromJson( + Map json, + T Function(Object json) fromJsonT, + S Function(Object json) fromJsonS, +) { + return Tuple( + fromJsonT(json['value1']), + fromJsonS(json['value2']), + ); +} + +Map _$TupleToJson( + Tuple instance, + Object Function(T value) toJsonT, + Object Function(S value) toJsonS, +) => + { + 'value1': toJsonT(instance.value1), + 'value2': toJsonS(instance.value2), + }; + +ConcreteClass _$ConcreteClassFromJson(Map json) { + return ConcreteClass( + Tuple.fromJson(json['tuple1'] as Map, + (value) => value as int, (value) => DateTime.parse(value as String)), + Tuple.fromJson( + json['tuple2'] as Map, + (value) => Duration(microseconds: value as int), + (value) => BigInt.parse(value as String)), + ); +} + +Map _$ConcreteClassToJson(ConcreteClass instance) => + { + 'tuple1': instance.tuple1.toJson( + (value) => value, + (value) => value.toIso8601String(), + ), + 'tuple2': instance.tuple2.toJson( + (value) => value.inMicroseconds, + (value) => value.toString(), + ), + }; diff --git a/example/test/tuple_example_test.dart b/example/test/tuple_example_test.dart new file mode 100644 index 000000000..67dc4fb43 --- /dev/null +++ b/example/test/tuple_example_test.dart @@ -0,0 +1,41 @@ +// Copyright (c) 2017, 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 'dart:convert'; + +import 'package:example/tuple_example.dart'; +import 'package:test/test.dart'; + +void main() { + test('ConcreteClass', () { + final instance = ConcreteClass( + Tuple(1, DateTime.fromMillisecondsSinceEpoch(24).toUtc()), + Tuple(const Duration(seconds: 42), BigInt.two), + ); + + final encoded = _encode(instance); + + const expected = r''' +{ + "tuple1": { + "value1": 1, + "value2": "1970-01-01T00:00:00.024Z" + }, + "tuple2": { + "value1": 42000000, + "value2": "2" + } +}'''; + + expect(encoded, expected); + final decoded = ConcreteClass.fromJson( + jsonDecode(encoded) as Map, + ); + final encoded2 = _encode(decoded); + expect(encoded2, encoded); + }); +} + +String _encode(Object object) => + const JsonEncoder.withIndent(' ').convert(object); diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index dffb4abf5..4c60d358e 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,6 +1,43 @@ ## 3.5.0-dev +- Added support for populating generic helper functions for fields with generic + type parameters. - Added support for `JsonSerializable.genericArgumentFactories`. + This adds extra parameters to generated `fromJson` and/or `toJson` functions + to support encoding and decoding generic types. + + For example, the generated code for + + ```dart + @JsonSerializable(genericArgumentFactories: true) + class Response { + int status; + T value; + } + ``` + + Looks like + + ```dart + Response _$ResponseFromJson( + Map json, + T Function(Object json) fromJsonT, + ) { + return Response() + ..status = json['status'] as int + ..value = fromJsonT(json['value']); + } + + Map _$ResponseToJson( + Response instance, + Object Function(T value) toJsonT, + ) => + { + 'status': instance.status, + 'value': toJsonT(instance.value), + }; + ``` + - `JsonKey.unknownEnumValue`: Added support for `Iterable`, `List`, and `Set`. ## 3.4.1 diff --git a/json_serializable/lib/src/type_helpers/json_helper.dart b/json_serializable/lib/src/type_helpers/json_helper.dart index cce9f208f..b783e19f3 100644 --- a/json_serializable/lib/src/type_helpers/json_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_helper.dart @@ -11,6 +11,9 @@ import 'package:source_gen/source_gen.dart'; import '../shared_checkers.dart'; import '../type_helper.dart'; import '../utils.dart'; +import 'generic_factory_helper.dart'; + +const _helperLambdaParam = 'value'; class JsonHelper extends TypeHelper { const JsonHelper(); @@ -29,8 +32,31 @@ class JsonHelper extends TypeHelper { return null; } - if (context.config.explicitToJson) { - return '$expression${context.nullable ? '?' : ''}.toJson()'; + final interfaceType = targetType as InterfaceType; + + final toJsonArgs = []; + + var toJson = _toJsonMethod(interfaceType); + + if (toJson != null) { + // Using the `declaration` here so we get the original definition – + // and not one with the generics already populated. + toJson = toJson.declaration; + + toJsonArgs.addAll( + _helperParams( + context.serialize, + _encodeHelper, + interfaceType, + toJson.parameters.where((element) => element.isRequiredPositional), + toJson, + ), + ); + } + + if (context.config.explicitToJson || toJsonArgs.isNotEmpty) { + return '$expression${context.nullable ? '?' : ''}' + '.toJson(${toJsonArgs.map((a) => '$a, ').join()} )'; } return expression; } @@ -53,8 +79,19 @@ class JsonHelper extends TypeHelper { var output = expression; if (fromJsonCtor != null) { - var asCastType = - fromJsonCtor.parameters.singleWhere((pe) => pe.isPositional).type; + final positionalParams = fromJsonCtor.parameters + .where((element) => element.isPositional) + .toList(); + + if (positionalParams.isEmpty) { + throw InvalidGenerationSourceError( + 'Expecting a `fromJson` constructor with exactly one positional ' + 'parameter. Found a constructor with 0 parameters.', + element: fromJsonCtor, + ); + } + + var asCastType = positionalParams.first.type; if (asCastType is InterfaceType) { final instantiated = _instantiate(asCastType as InterfaceType, type); @@ -64,6 +101,19 @@ class JsonHelper extends TypeHelper { } output = context.deserialize(asCastType, output).toString(); + + final args = [ + output, + ..._helperParams( + context.deserialize, + _decodeHelper, + targetType as InterfaceType, + positionalParams.skip(1), + fromJsonCtor, + ), + ]; + + output = args.join(', '); } else if (_annotation(context.config, type)?.createFactory == true) { if (context.config.anyMap) { output += ' as Map'; @@ -82,12 +132,95 @@ class JsonHelper extends TypeHelper { } } +List _helperParams( + Object Function(DartType, String) execute, + TypeParameterType Function(ParameterElement, Element) paramMapper, + InterfaceType type, + Iterable positionalParams, + Element targetElement, +) { + final rest = []; + for (var param in positionalParams) { + rest.add(paramMapper(param, targetElement)); + } + + final args = []; + + for (var helperArg in rest) { + final typeParamIndex = + type.element.typeParameters.indexOf(helperArg.element); + + // TODO: throw here if `typeParamIndex` is -1 ? + final typeArg = type.typeArguments[typeParamIndex]; + final body = execute(typeArg, _helperLambdaParam); + args.add('($_helperLambdaParam) => $body'); + } + + return args; +} + +TypeParameterType _decodeHelper( + ParameterElement param, + Element targetElement, +) { + final type = param.type; + + if (type is FunctionType && + type.returnType is TypeParameterType && + type.normalParameterTypes.length == 1) { + final funcReturnType = type.returnType; + + if (param.name == fromJsonForName(funcReturnType.element.name)) { + final funcParamType = type.normalParameterTypes.single; + + if (funcParamType.isDartCoreObject || funcParamType.isDynamic) { + return funcReturnType as TypeParameterType; + } + } + } + + throw InvalidGenerationSourceError( + 'Expecting a `fromJson` constructor with exactly one positional ' + 'parameter. ' + 'The only extra parameters allowed are functions of the form ' + '`T Function(Object) ${fromJsonForName('T')}` where `T` is a type ' + 'parameter of the target type.', + element: targetElement, + ); +} + +TypeParameterType _encodeHelper( + ParameterElement param, + Element targetElement, +) { + final type = param.type; + + if (type is FunctionType && + isObjectOrDynamic(type.returnType) && + type.normalParameterTypes.length == 1) { + final funcParamType = type.normalParameterTypes.single; + + if (param.name == toJsonForName(funcParamType.element.name)) { + if (funcParamType is TypeParameterType) { + return funcParamType; + } + } + } + + throw InvalidGenerationSourceError( + 'Expecting a `toJson` function with no required parameters. ' + 'The only extra parameters allowed are functions of the form ' + '`Object Function(T) toJsonT` where `T` is a type parameter of the target ' + ' type.', + element: targetElement, + ); +} + bool _canSerialize(JsonSerializable config, DartType type) { if (type is InterfaceType) { final toJsonMethod = _toJsonMethod(type); if (toJsonMethod != null) { - // TODO: validate there are no required parameters return true; } diff --git a/json_serializable/test/generic_files/generic_argument_factories.dart b/json_serializable/test/generic_files/generic_argument_factories.dart index bb83747f6..47d9987cf 100644 --- a/json_serializable/test/generic_files/generic_argument_factories.dart +++ b/json_serializable/test/generic_files/generic_argument_factories.dart @@ -33,3 +33,17 @@ class GenericClassWithHelpers { ) => _$GenericClassWithHelpersToJson(this, toJsonT, toJsonS); } + +@JsonSerializable() +class ConcreteClass { + final GenericClassWithHelpers value; + + final GenericClassWithHelpers value2; + + ConcreteClass(this.value, this.value2); + + factory ConcreteClass.fromJson(Map json) => + _$ConcreteClassFromJson(json); + + Map toJson() => _$ConcreteClassToJson(this); +} diff --git a/json_serializable/test/generic_files/generic_argument_factories.g.dart b/json_serializable/test/generic_files/generic_argument_factories.g.dart index aa8fa7197..b88167ada 100644 --- a/json_serializable/test/generic_files/generic_argument_factories.g.dart +++ b/json_serializable/test/generic_files/generic_argument_factories.g.dart @@ -28,3 +28,32 @@ Map _$GenericClassWithHelpersToJson( 'list': instance.list?.map(toJsonT)?.toList(), 'someSet': instance.someSet?.map(toJsonS)?.toList(), }; + +ConcreteClass _$ConcreteClassFromJson(Map json) { + return ConcreteClass( + json['value'] == null + ? null + : GenericClassWithHelpers.fromJson( + json['value'] as Map, + (value) => value as int, + (value) => value as String), + json['value2'] == null + ? null + : GenericClassWithHelpers.fromJson( + json['value2'] as Map, + (value) => (value as num)?.toDouble(), + (value) => value == null ? null : BigInt.parse(value as String)), + ); +} + +Map _$ConcreteClassToJson(ConcreteClass instance) => + { + 'value': instance.value?.toJson( + (value) => value, + (value) => value, + ), + 'value2': instance.value2?.toJson( + (value) => value, + (value) => value?.toString(), + ), + }; diff --git a/json_serializable/test/generic_files/generic_test.dart b/json_serializable/test/generic_files/generic_test.dart index 8e50345d5..19c43758a 100644 --- a/json_serializable/test/generic_files/generic_test.dart +++ b/json_serializable/test/generic_files/generic_test.dart @@ -83,4 +83,36 @@ void main() { expect(encodedJson2, encodedJson); }); }); + + group('argument factories', () { + test('round trip decode/decode', () { + const inputJson = r''' +{ + "value": { + "value": 5, + "list": [ + 5 + ], + "someSet": [ + "string" + ] + }, + "value2": { + "value": 3.14, + "list": [ + 3.14 + ], + "someSet": [ + "2" + ] + } +}'''; + + final instance = ConcreteClass.fromJson( + jsonDecode(inputJson) as Map, + ); + + expect(loudEncode(instance), inputJson); + }); + }); } diff --git a/json_serializable/test/json_serializable_test.dart b/json_serializable/test/json_serializable_test.dart index e7f1b4f66..d64363556 100644 --- a/json_serializable/test/json_serializable_test.dart +++ b/json_serializable/test/json_serializable_test.dart @@ -58,6 +58,9 @@ const _expectedAnnotatedTests = [ 'IgnoreUnannotated', 'IncludeIfNullDisallowNullClass', 'IncludeIfNullOverride', + 'InvalidChildClassFromJson', + 'InvalidChildClassFromJson2', + 'InvalidChildClassFromJson3', 'InvalidFromFunc2Args', 'InvalidToFunc2Args', 'JsonConverterCtorParams', diff --git a/json_serializable/test/src/_json_serializable_test_input.dart b/json_serializable/test/src/_json_serializable_test_input.dart index cbe649eb1..a03dcacdf 100644 --- a/json_serializable/test/src/_json_serializable_test_input.dart +++ b/json_serializable/test/src/_json_serializable_test_input.dart @@ -528,3 +528,55 @@ class OverrideGetterExampleI613Super { String get id => throw UnimplementedError(); } + +@ShouldThrow( + 'Expecting a `fromJson` constructor with exactly one positional parameter. ' + 'Found a constructor with 0 parameters.', + element: 'fromJson', +) +@JsonSerializable() +class InvalidChildClassFromJson { + NoParamFromJsonCtor field; +} + +class NoParamFromJsonCtor { + NoParamFromJsonCtor.fromJson(); +} + +@ShouldThrow( + 'Expecting a `fromJson` constructor with exactly one positional parameter. ' + 'The only extra parameters allowed are functions of the form ' + '`T Function(Object) fromJsonT` ' + 'where `T` is a type parameter of the target type.', + element: 'fromJson', +) +@JsonSerializable() +class InvalidChildClassFromJson2 { + ExtraParamFromJsonCtor field; +} + +class ExtraParamFromJsonCtor { + // ignore: avoid_unused_constructor_parameters + ExtraParamFromJsonCtor.fromJson(Map json, int oops); + + Map toJson() => null; +} + +@ShouldThrow( + 'Expecting a `toJson` function with no required parameters. ' + 'The only extra parameters allowed are functions of the form ' + '`Object Function(T) toJsonT` where `T` is a type parameter of the target ' + ' type.', + element: 'toJson', +) +@JsonSerializable() +class InvalidChildClassFromJson3 { + ExtraParamToJson field; +} + +class ExtraParamToJson { + // ignore: avoid_unused_constructor_parameters + ExtraParamToJson.fromJson(Map json); + + Map toJson(int bob) => null; +} From 295b2643f5f585596e0647c9d10d4990d0f76388 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 10 Sep 2020 09:27:49 -0700 Subject: [PATCH 226/569] Improve error output for types with type parameters (#714) Helps with https://github.com/google/json_serializable.dart/issues/713 --- json_serializable/lib/src/helper_core.dart | 2 ++ json_serializable/test/json_serializable_test.dart | 1 + json_serializable/test/src/generic_test_input.dart | 10 ++++++++++ 3 files changed, 13 insertions(+) diff --git a/json_serializable/lib/src/helper_core.dart b/json_serializable/lib/src/helper_core.dart index 6dadb7c1f..bf99f6962 100644 --- a/json_serializable/lib/src/helper_core.dart +++ b/json_serializable/lib/src/helper_core.dart @@ -126,6 +126,8 @@ String typeToCode(DartType type) { final typeArgumentsCode = typeArguments.map(typeToCode).join(', '); return '${type.element.name}<$typeArgumentsCode>'; } + } else if (type is TypeParameterType) { + return '${type.getDisplayString()} (type parameter)'; } throw UnimplementedError('(${type.runtimeType}) $type'); } diff --git a/json_serializable/test/json_serializable_test.dart b/json_serializable/test/json_serializable_test.dart index d64363556..cec29a125 100644 --- a/json_serializable/test/json_serializable_test.dart +++ b/json_serializable/test/json_serializable_test.dart @@ -63,6 +63,7 @@ const _expectedAnnotatedTests = [ 'InvalidChildClassFromJson3', 'InvalidFromFunc2Args', 'InvalidToFunc2Args', + 'Issue713', 'JsonConverterCtorParams', 'JsonConverterDuplicateAnnotations', 'JsonConverterNamedCtor', diff --git a/json_serializable/test/src/generic_test_input.dart b/json_serializable/test/src/generic_test_input.dart index 6b7a143d9..eeeaaf832 100644 --- a/json_serializable/test/src/generic_test_input.dart +++ b/json_serializable/test/src/generic_test_input.dart @@ -4,6 +4,16 @@ part of '_json_serializable_test_input.dart'; +@ShouldThrow( + 'Could not generate `fromJson` code for `result` because of type ' + '`TResult (type parameter)`.\n' + 'None of the provided `TypeHelper` instances support the defined type.', +) +@JsonSerializable() +class Issue713 { + List result; +} + @ShouldGenerate(r''' GenericClass _$GenericClassFromJson( Map json) { From 9f6c8b98e645d79a52aafbaf0fcee0d55e922b74 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 10 Sep 2020 13:53:18 -0700 Subject: [PATCH 227/569] Improve error message when @JsonSerializable is used with generics (#715) Follow-up on https://github.com/google/json_serializable.dart/pull/714 Also drop use of `InvalidGenerationSourceError.todo` See https://github.com/dart-lang/source_gen/issues/480 --- json_serializable/lib/src/helper_core.dart | 29 +++++++++++++++---- .../lib/src/json_serializable_generator.dart | 14 ++++----- .../src/_json_serializable_test_input.dart | 12 +++----- .../test/src/core_subclass_type_input.dart | 6 ---- .../test/src/generic_test_input.dart | 15 ++++++++-- 5 files changed, 46 insertions(+), 30 deletions(-) diff --git a/json_serializable/lib/src/helper_core.dart b/json_serializable/lib/src/helper_core.dart index bf99f6962..34d7fd7a0 100644 --- a/json_serializable/lib/src/helper_core.dart +++ b/json_serializable/lib/src/helper_core.dart @@ -60,14 +60,33 @@ InvalidGenerationSourceError createInvalidGenerationError( UnsupportedTypeError e, ) { var message = 'Could not generate `$targetMember` code for `${field.name}`'; - if (field.type != e.type) { + String todo; + + if (e.type is TypeParameterType) { + message = '$message because of type `${e.type.getDisplayString()}` ' + '(type parameter)'; + + todo = r''' +To support type paramaters (generic types) you can: +1) Use `JsonConverter` + https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonConverter-class.html +2) Use `JsonKey` fields `fromJson` and `toJson` + https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/fromJson.html + https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/toJson.html +3) Set `JsonSerializable.genericArgumentFactories` to `true` + https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/genericArgumentFactories.html'''; + } else if (field.type != e.type) { message = '$message because of type `${typeToCode(e.type)}`'; } - message = '$message.\n${e.reason}'; + + final messageItems = [ + '$message.', + e.reason, + if (todo != null) todo, + ]; return InvalidGenerationSourceError( - message, - todo: 'Make sure all of the types are serializable.', + messageItems.join('\n'), element: field, ); } @@ -126,8 +145,6 @@ String typeToCode(DartType type) { final typeArgumentsCode = typeArguments.map(typeToCode).join(', '); return '${type.element.name}<$typeArgumentsCode>'; } - } else if (type is TypeParameterType) { - return '${type.getDisplayString()} (type parameter)'; } throw UnimplementedError('(${type.runtimeType}) $type'); } diff --git a/json_serializable/lib/src/json_serializable_generator.dart b/json_serializable/lib/src/json_serializable_generator.dart index 388c0486e..84789ab87 100644 --- a/json_serializable/lib/src/json_serializable_generator.dart +++ b/json_serializable/lib/src/json_serializable_generator.dart @@ -88,10 +88,10 @@ class JsonSerializableGenerator BuildStep buildStep, ) { if (element is! ClassElement) { - final name = element.name; - throw InvalidGenerationSourceError('Generator cannot target `$name`.', - todo: 'Remove the JsonSerializable annotation from `$name`.', - element: element); + throw InvalidGenerationSourceError( + '`@JsonSerializable` can only be used on classes.', + element: element, + ); } final classElement = element as ClassElement; @@ -186,9 +186,9 @@ class _GeneratorHelper extends HelperCore with EncodeHelper, DecodeHelper { final jsonKey = nameAccess(fe); if (!set.add(jsonKey)) { throw InvalidGenerationSourceError( - 'More than one field has the JSON key `$jsonKey`.', - todo: 'Check the `JsonKey` annotations on fields.', - element: fe); + 'More than one field has the JSON key for name "$jsonKey".', + element: fe, + ); } return set; }, diff --git a/json_serializable/test/src/_json_serializable_test_input.dart b/json_serializable/test/src/_json_serializable_test_input.dart index a03dcacdf..441e399bc 100644 --- a/json_serializable/test/src/_json_serializable_test_input.dart +++ b/json_serializable/test/src/_json_serializable_test_input.dart @@ -29,13 +29,11 @@ part 'to_from_json_test_input.dart'; part 'unknown_enum_value_test_input.dart'; -@ShouldThrow('Generator cannot target `theAnswer`.', - todo: 'Remove the JsonSerializable annotation from `theAnswer`.') +@ShouldThrow('`@JsonSerializable` can only be used on classes.') @JsonSerializable() const theAnswer = 42; -@ShouldThrow('Generator cannot target `annotatedMethod`.', - todo: 'Remove the JsonSerializable annotation from `annotatedMethod`.') +@ShouldThrow('`@JsonSerializable` can only be used on classes.') @JsonSerializable() Object annotatedMethod() => null; @@ -271,8 +269,7 @@ class NoCtorClass { } @ShouldThrow( - 'More than one field has the JSON key `str`.', - todo: 'Check the `JsonKey` annotations on fields.', + 'More than one field has the JSON key for name "str".', element: 'str', ) @JsonSerializable(createFactory: false) @@ -284,8 +281,7 @@ class KeyDupesField { } @ShouldThrow( - 'More than one field has the JSON key `a`.', - todo: 'Check the `JsonKey` annotations on fields.', + 'More than one field has the JSON key for name "a".', element: 'str', ) @JsonSerializable(createFactory: false) diff --git a/json_serializable/test/src/core_subclass_type_input.dart b/json_serializable/test/src/core_subclass_type_input.dart index cb5d91cf3..1e796e703 100644 --- a/json_serializable/test/src/core_subclass_type_input.dart +++ b/json_serializable/test/src/core_subclass_type_input.dart @@ -4,7 +4,6 @@ part of '_json_serializable_test_input.dart'; r''' Could not generate `fromJson` code for `mapView`. None of the provided `TypeHelper` instances support the defined type.''', - todo: 'Make sure all of the types are serializable.', element: 'mapView', ) @JsonSerializable(createToJson: false) @@ -16,7 +15,6 @@ class UnsupportedMapField { r''' Could not generate `fromJson` code for `listView`. None of the provided `TypeHelper` instances support the defined type.''', - todo: 'Make sure all of the types are serializable.', element: 'listView', ) @JsonSerializable(createToJson: false) @@ -28,7 +26,6 @@ class UnsupportedListField { r''' Could not generate `fromJson` code for `customSet`. None of the provided `TypeHelper` instances support the defined type.''', - todo: 'Make sure all of the types are serializable.', element: 'customSet', ) @JsonSerializable(createToJson: false) @@ -42,7 +39,6 @@ abstract class _CustomSet implements Set {} r''' Could not generate `fromJson` code for `customDuration`. None of the provided `TypeHelper` instances support the defined type.''', - todo: 'Make sure all of the types are serializable.', element: 'customDuration', ) @JsonSerializable(createToJson: false) @@ -56,7 +52,6 @@ abstract class _CustomDuration implements Duration {} r''' Could not generate `fromJson` code for `customUri`. None of the provided `TypeHelper` instances support the defined type.''', - todo: 'Make sure all of the types are serializable.', element: 'customUri', ) @JsonSerializable(createToJson: false) @@ -70,7 +65,6 @@ abstract class _CustomUri implements Uri {} r''' Could not generate `fromJson` code for `customDateTime`. None of the provided `TypeHelper` instances support the defined type.''', - todo: 'Make sure all of the types are serializable.', element: 'customDateTime', ) @JsonSerializable(createToJson: false) diff --git a/json_serializable/test/src/generic_test_input.dart b/json_serializable/test/src/generic_test_input.dart index eeeaaf832..cfcef86f1 100644 --- a/json_serializable/test/src/generic_test_input.dart +++ b/json_serializable/test/src/generic_test_input.dart @@ -5,9 +5,18 @@ part of '_json_serializable_test_input.dart'; @ShouldThrow( - 'Could not generate `fromJson` code for `result` because of type ' - '`TResult (type parameter)`.\n' - 'None of the provided `TypeHelper` instances support the defined type.', + r''' +Could not generate `fromJson` code for `result` because of type `TResult` (type parameter). +None of the provided `TypeHelper` instances support the defined type. +To support type paramaters (generic types) you can: +1) Use `JsonConverter` + https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonConverter-class.html +2) Use `JsonKey` fields `fromJson` and `toJson` + https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/fromJson.html + https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/toJson.html +3) Set `JsonSerializable.genericArgumentFactories` to `true` + https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/genericArgumentFactories.html''', + element: 'result', ) @JsonSerializable() class Issue713 { From cfaa9a9dde3ebe19ee613a79f27081b673871bfb Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 22 Sep 2020 15:47:21 -0700 Subject: [PATCH 228/569] Prepare to release json_annotation for 3.1 (#721) --- json_annotation/CHANGELOG.md | 2 +- json_annotation/pubspec.yaml | 2 +- json_serializable/README.md | 42 +++++++++---------- json_serializable/doc/doc.md | 42 +++++++++---------- json_serializable/lib/src/helper_core.dart | 4 +- json_serializable/lib/src/json_key_utils.dart | 6 ++- .../lib/src/shared_checkers.dart | 4 +- .../type_helpers/generic_factory_helper.dart | 4 +- .../lib/src/type_helpers/map_helper.dart | 3 +- json_serializable/pubspec.yaml | 2 +- 10 files changed, 57 insertions(+), 54 deletions(-) diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index f52224a20..3d0966774 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -1,4 +1,4 @@ -## 3.1.0-dev +## 3.1.0 - Added `JsonSerializable.genericArgumentFactories` field. - Require at least Dart `2.7.0`. diff --git a/json_annotation/pubspec.yaml b/json_annotation/pubspec.yaml index 73571af85..b34284f08 100644 --- a/json_annotation/pubspec.yaml +++ b/json_annotation/pubspec.yaml @@ -1,5 +1,5 @@ name: json_annotation -version: 3.1.0-dev +version: 3.1.0 description: >- Classes and helper functions that support JSON code generation via the `json_serializable` package. diff --git a/json_serializable/README.md b/json_serializable/README.md index 31bd0e550..ef399eb9a 100644 --- a/json_serializable/README.md +++ b/json_serializable/README.md @@ -94,27 +94,27 @@ is generated: | | | [JsonKey.toJson] | | | | [JsonKey.unknownEnumValue] | -[JsonSerializable.anyMap]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/anyMap.html -[JsonSerializable.checked]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/checked.html -[JsonSerializable.createFactory]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/createFactory.html -[JsonSerializable.createToJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/createToJson.html -[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html -[JsonSerializable.explicitToJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/explicitToJson.html -[JsonSerializable.fieldRename]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/fieldRename.html -[JsonSerializable.genericArgumentFactories]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/genericArgumentFactories.html -[JsonSerializable.ignoreUnannotated]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/ignoreUnannotated.html -[JsonSerializable.includeIfNull]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/includeIfNull.html -[JsonKey.includeIfNull]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/includeIfNull.html -[JsonSerializable.nullable]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/nullable.html -[JsonKey.nullable]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/nullable.html -[JsonKey.defaultValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/defaultValue.html -[JsonKey.disallowNullValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/disallowNullValue.html -[JsonKey.fromJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/fromJson.html -[JsonKey.ignore]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/ignore.html -[JsonKey.name]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/name.html -[JsonKey.required]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/required.html -[JsonKey.toJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/toJson.html -[JsonKey.unknownEnumValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/unknownEnumValue.html +[JsonSerializable.anyMap]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonSerializable/anyMap.html +[JsonSerializable.checked]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonSerializable/checked.html +[JsonSerializable.createFactory]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonSerializable/createFactory.html +[JsonSerializable.createToJson]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonSerializable/createToJson.html +[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html +[JsonSerializable.explicitToJson]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonSerializable/explicitToJson.html +[JsonSerializable.fieldRename]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonSerializable/fieldRename.html +[JsonSerializable.genericArgumentFactories]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonSerializable/genericArgumentFactories.html +[JsonSerializable.ignoreUnannotated]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonSerializable/ignoreUnannotated.html +[JsonSerializable.includeIfNull]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonSerializable/includeIfNull.html +[JsonKey.includeIfNull]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonKey/includeIfNull.html +[JsonSerializable.nullable]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonSerializable/nullable.html +[JsonKey.nullable]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonKey/nullable.html +[JsonKey.defaultValue]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonKey/defaultValue.html +[JsonKey.disallowNullValue]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonKey/disallowNullValue.html +[JsonKey.fromJson]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonKey/fromJson.html +[JsonKey.ignore]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonKey/ignore.html +[JsonKey.name]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonKey/name.html +[JsonKey.required]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonKey/required.html +[JsonKey.toJson]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonKey/toJson.html +[JsonKey.unknownEnumValue]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonKey/unknownEnumValue.html > Note: every `JsonSerializable` field is configurable via `build.yaml` – see the table for the corresponding key. diff --git a/json_serializable/doc/doc.md b/json_serializable/doc/doc.md index 0525ed7ac..76c6c2d7d 100644 --- a/json_serializable/doc/doc.md +++ b/json_serializable/doc/doc.md @@ -20,24 +20,24 @@ | | | [JsonKey.toJson] | | | | [JsonKey.unknownEnumValue] | -[JsonSerializable.anyMap]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/anyMap.html -[JsonSerializable.checked]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/checked.html -[JsonSerializable.createFactory]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/createFactory.html -[JsonSerializable.createToJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/createToJson.html -[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html -[JsonSerializable.explicitToJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/explicitToJson.html -[JsonSerializable.fieldRename]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/fieldRename.html -[JsonSerializable.genericArgumentFactories]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/genericArgumentFactories.html -[JsonSerializable.ignoreUnannotated]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/ignoreUnannotated.html -[JsonSerializable.includeIfNull]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/includeIfNull.html -[JsonKey.includeIfNull]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/includeIfNull.html -[JsonSerializable.nullable]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/nullable.html -[JsonKey.nullable]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/nullable.html -[JsonKey.defaultValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/defaultValue.html -[JsonKey.disallowNullValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/disallowNullValue.html -[JsonKey.fromJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/fromJson.html -[JsonKey.ignore]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/ignore.html -[JsonKey.name]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/name.html -[JsonKey.required]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/required.html -[JsonKey.toJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/toJson.html -[JsonKey.unknownEnumValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/unknownEnumValue.html +[JsonSerializable.anyMap]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonSerializable/anyMap.html +[JsonSerializable.checked]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonSerializable/checked.html +[JsonSerializable.createFactory]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonSerializable/createFactory.html +[JsonSerializable.createToJson]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonSerializable/createToJson.html +[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html +[JsonSerializable.explicitToJson]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonSerializable/explicitToJson.html +[JsonSerializable.fieldRename]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonSerializable/fieldRename.html +[JsonSerializable.genericArgumentFactories]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonSerializable/genericArgumentFactories.html +[JsonSerializable.ignoreUnannotated]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonSerializable/ignoreUnannotated.html +[JsonSerializable.includeIfNull]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonSerializable/includeIfNull.html +[JsonKey.includeIfNull]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonKey/includeIfNull.html +[JsonSerializable.nullable]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonSerializable/nullable.html +[JsonKey.nullable]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonKey/nullable.html +[JsonKey.defaultValue]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonKey/defaultValue.html +[JsonKey.disallowNullValue]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonKey/disallowNullValue.html +[JsonKey.fromJson]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonKey/fromJson.html +[JsonKey.ignore]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonKey/ignore.html +[JsonKey.name]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonKey/name.html +[JsonKey.required]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonKey/required.html +[JsonKey.toJson]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonKey/toJson.html +[JsonKey.unknownEnumValue]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonKey/unknownEnumValue.html diff --git a/json_serializable/lib/src/helper_core.dart b/json_serializable/lib/src/helper_core.dart index 34d7fd7a0..c939677d8 100644 --- a/json_serializable/lib/src/helper_core.dart +++ b/json_serializable/lib/src/helper_core.dart @@ -63,8 +63,8 @@ InvalidGenerationSourceError createInvalidGenerationError( String todo; if (e.type is TypeParameterType) { - message = '$message because of type `${e.type.getDisplayString()}` ' - '(type parameter)'; + message = '$message because of type ' + '`${e.type.getDisplayString(withNullability: false)}` (type parameter)'; todo = r''' To support type paramaters (generic types) you can: diff --git a/json_serializable/lib/src/json_key_utils.dart b/json_serializable/lib/src/json_key_utils.dart index 33fc48361..cd6a42f0c 100644 --- a/json_serializable/lib/src/json_key_utils.dart +++ b/json_serializable/lib/src/json_key_utils.dart @@ -155,8 +155,10 @@ JsonKey _from(FieldElement element, JsonSerializable classAnnotation) { if (annotatedEnumType != targetEnumType) { throwUnsupported( element, - '`$fieldName` has type `$targetEnumType`, but the ' - 'provided unknownEnumValue is of type `$annotatedEnumType`.', + '`$fieldName` has type ' + '`${targetEnumType.getDisplayString(withNullability: false)}`, but ' + 'the provided unknownEnumValue is of type ' + '`${annotatedEnumType.getDisplayString(withNullability: false)}`.', ); } } diff --git a/json_serializable/lib/src/shared_checkers.dart b/json_serializable/lib/src/shared_checkers.dart index 030d585a5..2a63a477e 100644 --- a/json_serializable/lib/src/shared_checkers.dart +++ b/json_serializable/lib/src/shared_checkers.dart @@ -62,8 +62,8 @@ String asStatement(DartType type) { return ' as $typeCode'; } -// ignore: deprecated_member_use -bool isObjectOrDynamic(DartType type) => type.isObject || type.isDynamic; +bool isObjectOrDynamic(DartType type) => + type.isDartCoreObject || type.isDynamic; /// Returns all of the [DartType] types that [type] implements, mixes-in, and /// extends, starting with [type] itself. diff --git a/json_serializable/lib/src/type_helpers/generic_factory_helper.dart b/json_serializable/lib/src/type_helpers/generic_factory_helper.dart index 7f2f7119a..0a3bb8aba 100644 --- a/json_serializable/lib/src/type_helpers/generic_factory_helper.dart +++ b/json_serializable/lib/src/type_helpers/generic_factory_helper.dart @@ -40,11 +40,11 @@ class GenericFactoryHelper extends TypeHelper { } String toJsonForType(TypeParameterType type) => - toJsonForName(type.getDisplayString()); + toJsonForName(type.getDisplayString(withNullability: false)); String toJsonForName(String genericType) => 'toJson$genericType'; String fromJsonForType(TypeParameterType type) => - fromJsonForName(type.getDisplayString()); + fromJsonForName(type.getDisplayString(withNullability: false)); String fromJsonForName(String genericType) => 'fromJson$genericType'; diff --git a/json_serializable/lib/src/type_helpers/map_helper.dart b/json_serializable/lib/src/type_helpers/map_helper.dart index 60d311d57..09c8219c3 100644 --- a/json_serializable/lib/src/type_helpers/map_helper.dart +++ b/json_serializable/lib/src/type_helpers/map_helper.dart @@ -86,7 +86,8 @@ class MapHelper extends TypeHelper { (valueArgIsAny || simpleJsonTypeChecker.isAssignableFromType(valueArg))) { // No mapping of the values or null check required! - return 'Map.from($expression as Map)'; + final valueString = valueArg.getDisplayString(withNullability: false); + return 'Map.from($expression as Map)'; } } diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 4fbdd2ea1..026732100 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -8,7 +8,7 @@ environment: sdk: '>=2.7.0 <3.0.0' dependencies: - analyzer: ^0.39.0 + analyzer: '>=0.39.0 <0.41.0' build: '>=0.12.6 <2.0.0' build_config: '>=0.2.6 <0.5.0' From 6b584156229e9df72f57057917e5513f3cffdc1e Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 22 Sep 2020 16:19:55 -0700 Subject: [PATCH 229/569] json_serializable: Prepare to release v3.5.0 (#722) --- json_serializable/CHANGELOG.md | 3 ++- json_serializable/pubspec.yaml | 6 +----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 4c60d358e..febf43dbb 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,4 +1,4 @@ -## 3.5.0-dev +## 3.5.0 - Added support for populating generic helper functions for fields with generic type parameters. @@ -39,6 +39,7 @@ ``` - `JsonKey.unknownEnumValue`: Added support for `Iterable`, `List`, and `Set`. +- Require `package:analyzer` `>=0.39.0 <0.41.0`. ## 3.4.1 diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 026732100..0348ce73e 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 3.5.0-dev +version: 3.5.0 description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. @@ -32,7 +32,3 @@ dev_dependencies: source_gen_test: ^0.1.0 test: ^1.6.0 yaml: ^2.1.13 - -dependency_overrides: - json_annotation: - path: ../json_annotation From 6278a50d90b2920be4b291b04a13dc851e12e9ab Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 24 Sep 2020 15:02:31 -0700 Subject: [PATCH 230/569] json_annotation: fix doc comments (#724) --- json_annotation/CHANGELOG.md | 4 ++++ json_annotation/lib/src/json_serializable.dart | 11 ++++++----- json_annotation/pubspec.yaml | 2 +- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index 3d0966774..8f407c692 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -1,3 +1,7 @@ +## 3.1.1-dev + +- Fixed doc comments for `JsonSerializable.genericArgumentFactories`. + ## 3.1.0 - Added `JsonSerializable.genericArgumentFactories` field. diff --git a/json_annotation/lib/src/json_serializable.dart b/json_annotation/lib/src/json_serializable.dart index d1fa14222..d5ab9d5e7 100644 --- a/json_annotation/lib/src/json_serializable.dart +++ b/json_annotation/lib/src/json_serializable.dart @@ -148,12 +148,13 @@ class JsonSerializable { /// }; /// ``` /// - /// Note: this option has no effect on classes class without type parameters. - /// A warning is printed in such cases. + /// Notes: /// - /// Note: if this option is set for all classes in a package via `build.yaml` - /// it is only applied to classes with type parameters – so no warning is - /// printed. + /// 1. This option has no effect on classes without type parameters. + /// If used on such a class, a warning is echoed in the build log. + /// 1. If this option is set for all classes in a package via `build.yaml` + /// it is only applied to classes with type parameters – so no warning is + /// echoed. final bool genericArgumentFactories; /// When `true`, only fields annotated with [JsonKey] will have code diff --git a/json_annotation/pubspec.yaml b/json_annotation/pubspec.yaml index b34284f08..bdfff782d 100644 --- a/json_annotation/pubspec.yaml +++ b/json_annotation/pubspec.yaml @@ -1,5 +1,5 @@ name: json_annotation -version: 3.1.0 +version: 3.1.1-dev description: >- Classes and helper functions that support JSON code generation via the `json_serializable` package. From a34ff424772ca5d88818df8325a4cdfd44eb9688 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 24 Sep 2020 17:02:32 -0700 Subject: [PATCH 231/569] DRY up tests of unsupported types (#725) * Also fixed some spelling --- json_serializable/lib/src/helper_core.dart | 2 +- .../lib/src/type_helper_ctx.dart | 8 ++++--- .../src/_json_serializable_test_input.dart | 11 +++++---- .../test/src/core_subclass_type_input.dart | 24 +++++++++---------- .../test/src/generic_test_input.dart | 6 ++--- .../test/src/to_from_json_test_input.dart | 10 ++++---- 6 files changed, 33 insertions(+), 28 deletions(-) diff --git a/json_serializable/lib/src/helper_core.dart b/json_serializable/lib/src/helper_core.dart index c939677d8..027660145 100644 --- a/json_serializable/lib/src/helper_core.dart +++ b/json_serializable/lib/src/helper_core.dart @@ -67,7 +67,7 @@ InvalidGenerationSourceError createInvalidGenerationError( '`${e.type.getDisplayString(withNullability: false)}` (type parameter)'; todo = r''' -To support type paramaters (generic types) you can: +To support type parameters (generic types) you can: 1) Use `JsonConverter` https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonConverter-class.html 2) Use `JsonKey` fields `fromJson` and `toJson` diff --git a/json_serializable/lib/src/type_helper_ctx.dart b/json_serializable/lib/src/type_helper_ctx.dart index 8f4402521..72a97db30 100644 --- a/json_serializable/lib/src/type_helper_ctx.dart +++ b/json_serializable/lib/src/type_helper_ctx.dart @@ -6,6 +6,7 @@ import 'package:analyzer/dart/constant/value.dart'; import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/type.dart'; import 'package:json_annotation/json_annotation.dart'; +import 'package:meta/meta.dart'; import 'helper_core.dart'; import 'type_helper.dart'; @@ -73,12 +74,13 @@ class TypeHelperCtx orElse: () => throw UnsupportedTypeError( targetType, expression, - _notSupportedWithTypeHelpersMsg, + notSupportedWithTypeHelpersMsg, ), ); } -const _notSupportedWithTypeHelpersMsg = +@visibleForTesting +const notSupportedWithTypeHelpersMsg = 'None of the provided `TypeHelper` instances support the defined type.'; class _ConvertPair { @@ -122,7 +124,7 @@ ConvertData _convertData(DartObject obj, FieldElement element, bool isFrom) { throwUnsupported( element, 'The `$paramName` function `${executableElement.name}` must have one ' - 'positional paramater.'); + 'positional parameter.'); } final argType = executableElement.parameters.first.type; diff --git a/json_serializable/test/src/_json_serializable_test_input.dart b/json_serializable/test/src/_json_serializable_test_input.dart index 441e399bc..f54f10e33 100644 --- a/json_serializable/test/src/_json_serializable_test_input.dart +++ b/json_serializable/test/src/_json_serializable_test_input.dart @@ -5,6 +5,7 @@ import 'dart:collection'; import 'package:json_annotation/json_annotation.dart'; +import 'package:json_serializable/src/type_helper_ctx.dart'; import 'package:source_gen_test/annotations.dart'; part 'checked_test_input.dart'; @@ -187,8 +188,9 @@ class SetSupport { } @ShouldThrow( - 'Could not generate `toJson` code for `watch`.\n' - 'None of the provided `TypeHelper` instances support the defined type.', + ''' +Could not generate `toJson` code for `watch`. +$notSupportedWithTypeHelpersMsg''', configurations: ['default'], ) @JsonSerializable(createFactory: false) @@ -197,8 +199,9 @@ class NoSerializeFieldType { } @ShouldThrow( - 'Could not generate `fromJson` code for `watch`.\n' - 'None of the provided `TypeHelper` instances support the defined type.', + ''' +Could not generate `fromJson` code for `watch`. +$notSupportedWithTypeHelpersMsg''', configurations: ['default'], ) @JsonSerializable(createToJson: false) diff --git a/json_serializable/test/src/core_subclass_type_input.dart b/json_serializable/test/src/core_subclass_type_input.dart index 1e796e703..868ba7054 100644 --- a/json_serializable/test/src/core_subclass_type_input.dart +++ b/json_serializable/test/src/core_subclass_type_input.dart @@ -1,9 +1,9 @@ part of '_json_serializable_test_input.dart'; @ShouldThrow( - r''' + ''' Could not generate `fromJson` code for `mapView`. -None of the provided `TypeHelper` instances support the defined type.''', +$notSupportedWithTypeHelpersMsg''', element: 'mapView', ) @JsonSerializable(createToJson: false) @@ -12,9 +12,9 @@ class UnsupportedMapField { } @ShouldThrow( - r''' + ''' Could not generate `fromJson` code for `listView`. -None of the provided `TypeHelper` instances support the defined type.''', +$notSupportedWithTypeHelpersMsg''', element: 'listView', ) @JsonSerializable(createToJson: false) @@ -23,9 +23,9 @@ class UnsupportedListField { } @ShouldThrow( - r''' + ''' Could not generate `fromJson` code for `customSet`. -None of the provided `TypeHelper` instances support the defined type.''', +$notSupportedWithTypeHelpersMsg''', element: 'customSet', ) @JsonSerializable(createToJson: false) @@ -36,9 +36,9 @@ class UnsupportedSetField { abstract class _CustomSet implements Set {} @ShouldThrow( - r''' + ''' Could not generate `fromJson` code for `customDuration`. -None of the provided `TypeHelper` instances support the defined type.''', +$notSupportedWithTypeHelpersMsg''', element: 'customDuration', ) @JsonSerializable(createToJson: false) @@ -49,9 +49,9 @@ class UnsupportedDurationField { abstract class _CustomDuration implements Duration {} @ShouldThrow( - r''' + ''' Could not generate `fromJson` code for `customUri`. -None of the provided `TypeHelper` instances support the defined type.''', +$notSupportedWithTypeHelpersMsg''', element: 'customUri', ) @JsonSerializable(createToJson: false) @@ -62,9 +62,9 @@ class UnsupportedUriField { abstract class _CustomUri implements Uri {} @ShouldThrow( - r''' + ''' Could not generate `fromJson` code for `customDateTime`. -None of the provided `TypeHelper` instances support the defined type.''', +$notSupportedWithTypeHelpersMsg''', element: 'customDateTime', ) @JsonSerializable(createToJson: false) diff --git a/json_serializable/test/src/generic_test_input.dart b/json_serializable/test/src/generic_test_input.dart index cfcef86f1..9e62390e4 100644 --- a/json_serializable/test/src/generic_test_input.dart +++ b/json_serializable/test/src/generic_test_input.dart @@ -5,10 +5,10 @@ part of '_json_serializable_test_input.dart'; @ShouldThrow( - r''' + ''' Could not generate `fromJson` code for `result` because of type `TResult` (type parameter). -None of the provided `TypeHelper` instances support the defined type. -To support type paramaters (generic types) you can: +$notSupportedWithTypeHelpersMsg +To support type parameters (generic types) you can: 1) Use `JsonConverter` https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonConverter-class.html 2) Use `JsonKey` fields `fromJson` and `toJson` diff --git a/json_serializable/test/src/to_from_json_test_input.dart b/json_serializable/test/src/to_from_json_test_input.dart index c4a9b9a62..c98d317bd 100644 --- a/json_serializable/test/src/to_from_json_test_input.dart +++ b/json_serializable/test/src/to_from_json_test_input.dart @@ -27,7 +27,7 @@ class BadFromFuncReturnType { @ShouldThrow( 'Error with `@JsonKey` on `field`. The `fromJson` function ' - '`_twoArgFunction` must have one positional paramater.', + '`_twoArgFunction` must have one positional parameter.', element: 'field', ) @JsonSerializable() @@ -73,7 +73,7 @@ class BadToFuncReturnType { @ShouldThrow( 'Error with `@JsonKey` on `field`. The `toJson` function ' - '`_twoArgFunction` must have one positional paramater.', + '`_twoArgFunction` must have one positional parameter.', element: 'field', ) @JsonSerializable() @@ -177,7 +177,7 @@ String _noArgs() => null; @ShouldThrow( 'Error with `@JsonKey` on `field`. The `fromJson` function ' - '`_noArgs` must have one positional paramater.', + '`_noArgs` must have one positional parameter.', element: 'field', ) @JsonSerializable(createToJson: false) @@ -190,7 +190,7 @@ String _twoArgs(a, b) => null; @ShouldThrow( 'Error with `@JsonKey` on `field`. The `fromJson` function ' - '`_twoArgs` must have one positional paramater.', + '`_twoArgs` must have one positional parameter.', element: 'field', ) @JsonSerializable(createToJson: false) @@ -203,7 +203,7 @@ String _oneNamed({a}) => null; @ShouldThrow( 'Error with `@JsonKey` on `field`. The `fromJson` function ' - '`_oneNamed` must have one positional paramater.', + '`_oneNamed` must have one positional parameter.', element: 'field', ) @JsonSerializable(createToJson: false) From 2e323eef015b35f51d73f880953bbdcd87f54410 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 24 Sep 2020 17:09:00 -0700 Subject: [PATCH 232/569] More error message DRYing up and formatting --- json_serializable/lib/src/helper_core.dart | 18 +++++++++++------- .../src/_json_serializable_test_input.dart | 1 + .../test/src/generic_test_input.dart | 8 ++------ 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/json_serializable/lib/src/helper_core.dart b/json_serializable/lib/src/helper_core.dart index 027660145..4198c747d 100644 --- a/json_serializable/lib/src/helper_core.dart +++ b/json_serializable/lib/src/helper_core.dart @@ -66,14 +66,10 @@ InvalidGenerationSourceError createInvalidGenerationError( message = '$message because of type ' '`${e.type.getDisplayString(withNullability: false)}` (type parameter)'; - todo = r''' + todo = ''' To support type parameters (generic types) you can: -1) Use `JsonConverter` - https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonConverter-class.html -2) Use `JsonKey` fields `fromJson` and `toJson` - https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/fromJson.html - https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/toJson.html -3) Set `JsonSerializable.genericArgumentFactories` to `true` +$converterOrKeyInstructions +* Set `JsonSerializable.genericArgumentFactories` to `true` https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/genericArgumentFactories.html'''; } else if (field.type != e.type) { message = '$message because of type `${typeToCode(e.type)}`'; @@ -91,6 +87,14 @@ To support type parameters (generic types) you can: ); } +@visibleForTesting +const converterOrKeyInstructions = r''' +* Use `JsonConverter` + https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonConverter-class.html +* Use `JsonKey` fields `fromJson` and `toJson` + https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/fromJson.html + https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/toJson.html'''; + /// Returns a [String] representing the type arguments that exist on /// [element]. /// diff --git a/json_serializable/test/src/_json_serializable_test_input.dart b/json_serializable/test/src/_json_serializable_test_input.dart index f54f10e33..f5dca5369 100644 --- a/json_serializable/test/src/_json_serializable_test_input.dart +++ b/json_serializable/test/src/_json_serializable_test_input.dart @@ -5,6 +5,7 @@ import 'dart:collection'; import 'package:json_annotation/json_annotation.dart'; +import 'package:json_serializable/src/helper_core.dart'; import 'package:json_serializable/src/type_helper_ctx.dart'; import 'package:source_gen_test/annotations.dart'; diff --git a/json_serializable/test/src/generic_test_input.dart b/json_serializable/test/src/generic_test_input.dart index 9e62390e4..3d00f965c 100644 --- a/json_serializable/test/src/generic_test_input.dart +++ b/json_serializable/test/src/generic_test_input.dart @@ -9,12 +9,8 @@ part of '_json_serializable_test_input.dart'; Could not generate `fromJson` code for `result` because of type `TResult` (type parameter). $notSupportedWithTypeHelpersMsg To support type parameters (generic types) you can: -1) Use `JsonConverter` - https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonConverter-class.html -2) Use `JsonKey` fields `fromJson` and `toJson` - https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/fromJson.html - https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/toJson.html -3) Set `JsonSerializable.genericArgumentFactories` to `true` +$converterOrKeyInstructions +* Set `JsonSerializable.genericArgumentFactories` to `true` https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/genericArgumentFactories.html''', element: 'result', ) From b62f66a918827cf1ff483e424da0c830445ccd5a Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 24 Sep 2020 18:30:18 -0700 Subject: [PATCH 233/569] Improve error messages for unsupported types Progress towards https://github.com/google/json_serializable.dart/issues/236 --- json_serializable/CHANGELOG.md | 6 ++++ json_serializable/lib/src/helper_core.dart | 28 ++++++++++--------- .../lib/src/type_helper_ctx.dart | 11 +------- .../lib/src/unsupported_type_error.dart | 2 +- json_serializable/pubspec.yaml | 2 +- .../src/_json_serializable_test_input.dart | 7 +++-- .../test/src/core_subclass_type_input.dart | 18 ++++++++---- .../test/src/generic_test_input.dart | 1 - 8 files changed, 40 insertions(+), 35 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index febf43dbb..e78e7f946 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,9 @@ +## 3.5.1-dev + +- Improved error messages for unsupported types. +- `package:json_serializable/type_helper.dart` + - Made the third parameter to `UnsupportedTypeError` positional (optional). + ## 3.5.0 - Added support for populating generic helper functions for fields with generic diff --git a/json_serializable/lib/src/helper_core.dart b/json_serializable/lib/src/helper_core.dart index 4198c747d..ebd56fc0b 100644 --- a/json_serializable/lib/src/helper_core.dart +++ b/json_serializable/lib/src/helper_core.dart @@ -57,32 +57,34 @@ abstract class HelperCore { InvalidGenerationSourceError createInvalidGenerationError( String targetMember, FieldElement field, - UnsupportedTypeError e, + UnsupportedTypeError error, ) { var message = 'Could not generate `$targetMember` code for `${field.name}`'; - String todo; - if (e.type is TypeParameterType) { + String todo; + if (error.type is TypeParameterType) { message = '$message because of type ' - '`${e.type.getDisplayString(withNullability: false)}` (type parameter)'; + '`${error.type.getDisplayString(withNullability: false)}` (type parameter)'; todo = ''' To support type parameters (generic types) you can: $converterOrKeyInstructions * Set `JsonSerializable.genericArgumentFactories` to `true` https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/genericArgumentFactories.html'''; - } else if (field.type != e.type) { - message = '$message because of type `${typeToCode(e.type)}`'; + } else if (field.type != error.type) { + message = '$message because of type `${typeToCode(error.type)}`'; + } else { + todo = ''' +To support the type `${error.type.element.name}` you can: +$converterOrKeyInstructions'''; } - final messageItems = [ - '$message.', - e.reason, - if (todo != null) todo, - ]; - return InvalidGenerationSourceError( - messageItems.join('\n'), + [ + '$message.', + if (error.reason != null) error.reason, + if (todo != null) todo, + ].join('\n'), element: field, ); } diff --git a/json_serializable/lib/src/type_helper_ctx.dart b/json_serializable/lib/src/type_helper_ctx.dart index 72a97db30..84ea35199 100644 --- a/json_serializable/lib/src/type_helper_ctx.dart +++ b/json_serializable/lib/src/type_helper_ctx.dart @@ -6,7 +6,6 @@ import 'package:analyzer/dart/constant/value.dart'; import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/type.dart'; import 'package:json_annotation/json_annotation.dart'; -import 'package:meta/meta.dart'; import 'helper_core.dart'; import 'type_helper.dart'; @@ -71,18 +70,10 @@ class TypeHelperCtx ) => _helperCore.allTypeHelpers.map(invoke).firstWhere( (r) => r != null, - orElse: () => throw UnsupportedTypeError( - targetType, - expression, - notSupportedWithTypeHelpersMsg, - ), + orElse: () => throw UnsupportedTypeError(targetType, expression), ); } -@visibleForTesting -const notSupportedWithTypeHelpersMsg = - 'None of the provided `TypeHelper` instances support the defined type.'; - class _ConvertPair { static final _expando = Expando<_ConvertPair>(); diff --git a/json_serializable/lib/src/unsupported_type_error.dart b/json_serializable/lib/src/unsupported_type_error.dart index ea80e15a6..3642cc2c4 100644 --- a/json_serializable/lib/src/unsupported_type_error.dart +++ b/json_serializable/lib/src/unsupported_type_error.dart @@ -13,5 +13,5 @@ class UnsupportedTypeError extends Error { /// Not currently accesses. Will likely be removed in a future release. final String expression; - UnsupportedTypeError(this.type, this.expression, this.reason); + UnsupportedTypeError(this.type, this.expression, [this.reason]); } diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 0348ce73e..b898dd745 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 3.5.0 +version: 3.5.0-dev description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. diff --git a/json_serializable/test/src/_json_serializable_test_input.dart b/json_serializable/test/src/_json_serializable_test_input.dart index f5dca5369..ca5b848c9 100644 --- a/json_serializable/test/src/_json_serializable_test_input.dart +++ b/json_serializable/test/src/_json_serializable_test_input.dart @@ -6,7 +6,6 @@ import 'dart:collection'; import 'package:json_annotation/json_annotation.dart'; import 'package:json_serializable/src/helper_core.dart'; -import 'package:json_serializable/src/type_helper_ctx.dart'; import 'package:source_gen_test/annotations.dart'; part 'checked_test_input.dart'; @@ -191,7 +190,8 @@ class SetSupport { @ShouldThrow( ''' Could not generate `toJson` code for `watch`. -$notSupportedWithTypeHelpersMsg''', +To support the type `Stopwatch` you can: +$converterOrKeyInstructions''', configurations: ['default'], ) @JsonSerializable(createFactory: false) @@ -202,7 +202,8 @@ class NoSerializeFieldType { @ShouldThrow( ''' Could not generate `fromJson` code for `watch`. -$notSupportedWithTypeHelpersMsg''', +To support the type `Stopwatch` you can: +$converterOrKeyInstructions''', configurations: ['default'], ) @JsonSerializable(createToJson: false) diff --git a/json_serializable/test/src/core_subclass_type_input.dart b/json_serializable/test/src/core_subclass_type_input.dart index 868ba7054..bad046a8f 100644 --- a/json_serializable/test/src/core_subclass_type_input.dart +++ b/json_serializable/test/src/core_subclass_type_input.dart @@ -3,7 +3,8 @@ part of '_json_serializable_test_input.dart'; @ShouldThrow( ''' Could not generate `fromJson` code for `mapView`. -$notSupportedWithTypeHelpersMsg''', +To support the type `MapView` you can: +$converterOrKeyInstructions''', element: 'mapView', ) @JsonSerializable(createToJson: false) @@ -14,7 +15,8 @@ class UnsupportedMapField { @ShouldThrow( ''' Could not generate `fromJson` code for `listView`. -$notSupportedWithTypeHelpersMsg''', +To support the type `UnmodifiableListView` you can: +$converterOrKeyInstructions''', element: 'listView', ) @JsonSerializable(createToJson: false) @@ -25,7 +27,8 @@ class UnsupportedListField { @ShouldThrow( ''' Could not generate `fromJson` code for `customSet`. -$notSupportedWithTypeHelpersMsg''', +To support the type `_CustomSet` you can: +$converterOrKeyInstructions''', element: 'customSet', ) @JsonSerializable(createToJson: false) @@ -38,7 +41,8 @@ abstract class _CustomSet implements Set {} @ShouldThrow( ''' Could not generate `fromJson` code for `customDuration`. -$notSupportedWithTypeHelpersMsg''', +To support the type `_CustomDuration` you can: +$converterOrKeyInstructions''', element: 'customDuration', ) @JsonSerializable(createToJson: false) @@ -51,7 +55,8 @@ abstract class _CustomDuration implements Duration {} @ShouldThrow( ''' Could not generate `fromJson` code for `customUri`. -$notSupportedWithTypeHelpersMsg''', +To support the type `_CustomUri` you can: +$converterOrKeyInstructions''', element: 'customUri', ) @JsonSerializable(createToJson: false) @@ -64,7 +69,8 @@ abstract class _CustomUri implements Uri {} @ShouldThrow( ''' Could not generate `fromJson` code for `customDateTime`. -$notSupportedWithTypeHelpersMsg''', +To support the type `_CustomDateTime` you can: +$converterOrKeyInstructions''', element: 'customDateTime', ) @JsonSerializable(createToJson: false) diff --git a/json_serializable/test/src/generic_test_input.dart b/json_serializable/test/src/generic_test_input.dart index 3d00f965c..b8642c87c 100644 --- a/json_serializable/test/src/generic_test_input.dart +++ b/json_serializable/test/src/generic_test_input.dart @@ -7,7 +7,6 @@ part of '_json_serializable_test_input.dart'; @ShouldThrow( ''' Could not generate `fromJson` code for `result` because of type `TResult` (type parameter). -$notSupportedWithTypeHelpersMsg To support type parameters (generic types) you can: $converterOrKeyInstructions * Set `JsonSerializable.genericArgumentFactories` to `true` From 506649bef0bca69fe19260a04c2c688ed1a5580a Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 14 Sep 2020 13:40:04 -0700 Subject: [PATCH 234/569] Adding "Settings" --- .../lib/src/json_part_builder.dart | 19 +++-- .../lib/src/json_serializable_generator.dart | 54 ++++---------- json_serializable/lib/src/settings.dart | 74 +++++++++++++++++++ .../test/json_serializable_test.dart | 2 +- 4 files changed, 104 insertions(+), 45 deletions(-) create mode 100644 json_serializable/lib/src/settings.dart diff --git a/json_serializable/lib/src/json_part_builder.dart b/json_serializable/lib/src/json_part_builder.dart index 104d2d2b7..1bf2d38f3 100644 --- a/json_serializable/lib/src/json_part_builder.dart +++ b/json_serializable/lib/src/json_part_builder.dart @@ -8,6 +8,7 @@ import 'package:source_gen/source_gen.dart'; import 'json_literal_generator.dart'; import 'json_serializable_generator.dart'; +import 'settings.dart'; /// Returns a [Builder] for use within a `package:build_runner` /// `BuildAction`. @@ -17,9 +18,15 @@ import 'json_serializable_generator.dart'; Builder jsonPartBuilder({ String Function(String code) formatOutput, JsonSerializable config, -}) => - SharedPartBuilder( - [JsonSerializableGenerator(config: config), const JsonLiteralGenerator()], - 'json_serializable', - formatOutput: formatOutput, - ); +}) { + final settings = Settings(config: config); + + return SharedPartBuilder( + [ + JsonSerializableGenerator.fromSettings(settings), + const JsonLiteralGenerator(), + ], + 'json_serializable', + formatOutput: formatOutput, + ); +} diff --git a/json_serializable/lib/src/json_serializable_generator.dart b/json_serializable/lib/src/json_serializable_generator.dart index 84789ab87..ac73051ad 100644 --- a/json_serializable/lib/src/json_serializable_generator.dart +++ b/json_serializable/lib/src/json_serializable_generator.dart @@ -11,60 +11,36 @@ import 'decode_helper.dart'; import 'encoder_helper.dart'; import 'field_helpers.dart'; import 'helper_core.dart'; +import 'settings.dart'; import 'type_helper.dart'; import 'type_helpers/big_int_helper.dart'; -import 'type_helpers/convert_helper.dart'; import 'type_helpers/date_time_helper.dart'; import 'type_helpers/duration_helper.dart'; -import 'type_helpers/enum_helper.dart'; -import 'type_helpers/generic_factory_helper.dart'; -import 'type_helpers/iterable_helper.dart'; -import 'type_helpers/json_converter_helper.dart'; import 'type_helpers/json_helper.dart'; -import 'type_helpers/map_helper.dart'; import 'type_helpers/uri_helper.dart'; -import 'type_helpers/value_helper.dart'; import 'utils.dart'; class JsonSerializableGenerator extends GeneratorForAnnotation { - static const _coreHelpers = [ - IterableHelper(), - MapHelper(), - EnumHelper(), - ValueHelper(), - ]; + final Settings _settings; - static const _defaultHelpers = [ - BigIntHelper(), - DateTimeHelper(), - DurationHelper(), - JsonHelper(), - UriHelper(), - ]; + JsonSerializable get config => _settings.config; - final List _typeHelpers; - - Iterable get _allHelpers => const [ - ConvertHelper(), - JsonConverterHelper(), - GenericFactoryHelper(), - ].followedBy(_typeHelpers).followedBy(_coreHelpers); - - final JsonSerializable _config; - - JsonSerializable get config => _config.withDefaults(); + JsonSerializableGenerator.fromSettings(this._settings); /// Creates an instance of [JsonSerializableGenerator]. /// /// If [typeHelpers] is not provided, the built-in helpers are used: /// [BigIntHelper], [DateTimeHelper], [DurationHelper], [JsonHelper], and /// [UriHelper]. - const JsonSerializableGenerator({ + factory JsonSerializableGenerator({ JsonSerializable config, List typeHelpers, - }) : _config = config ?? JsonSerializable.defaults, - _typeHelpers = typeHelpers ?? _defaultHelpers; + }) => + JsonSerializableGenerator.fromSettings(Settings( + config: config, + typeHelpers: typeHelpers, + )); /// Creates an instance of [JsonSerializableGenerator]. /// @@ -78,7 +54,9 @@ class JsonSerializableGenerator }) => JsonSerializableGenerator( config: config, - typeHelpers: List.unmodifiable(typeHelpers.followedBy(_defaultHelpers)), + typeHelpers: List.unmodifiable( + typeHelpers.followedBy(Settings.defaultHelpers), + ), ); @override @@ -95,13 +73,13 @@ class JsonSerializableGenerator } final classElement = element as ClassElement; - final helper = _GeneratorHelper(this, classElement, annotation); + final helper = _GeneratorHelper(_settings, classElement, annotation); return helper._generate(); } } class _GeneratorHelper extends HelperCore with EncodeHelper, DecodeHelper { - final JsonSerializableGenerator _generator; + final Settings _generator; final _addedMembers = {}; _GeneratorHelper( @@ -122,7 +100,7 @@ class _GeneratorHelper extends HelperCore with EncodeHelper, DecodeHelper { } @override - Iterable get allTypeHelpers => _generator._allHelpers; + Iterable get allTypeHelpers => _generator.allHelpers; Iterable _generate() sync* { assert(_addedMembers.isEmpty); diff --git a/json_serializable/lib/src/settings.dart b/json_serializable/lib/src/settings.dart new file mode 100644 index 000000000..50b6639de --- /dev/null +++ b/json_serializable/lib/src/settings.dart @@ -0,0 +1,74 @@ +// Copyright (c) 2017, 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:json_annotation/json_annotation.dart'; + +import 'type_helper.dart'; +import 'type_helpers/big_int_helper.dart'; +import 'type_helpers/convert_helper.dart'; +import 'type_helpers/date_time_helper.dart'; +import 'type_helpers/duration_helper.dart'; +import 'type_helpers/enum_helper.dart'; +import 'type_helpers/generic_factory_helper.dart'; +import 'type_helpers/iterable_helper.dart'; +import 'type_helpers/json_converter_helper.dart'; +import 'type_helpers/json_helper.dart'; +import 'type_helpers/map_helper.dart'; +import 'type_helpers/uri_helper.dart'; +import 'type_helpers/value_helper.dart'; + +class Settings { + static const _coreHelpers = [ + IterableHelper(), + MapHelper(), + EnumHelper(), + ValueHelper(), + ]; + + static const defaultHelpers = [ + BigIntHelper(), + DateTimeHelper(), + DurationHelper(), + JsonHelper(), + UriHelper(), + ]; + + final List _typeHelpers; + + Iterable get allHelpers => const [ + ConvertHelper(), + JsonConverterHelper(), + GenericFactoryHelper(), + ].followedBy(_typeHelpers).followedBy(_coreHelpers); + + final JsonSerializable _config; + + JsonSerializable get config => _config.withDefaults(); + + /// Creates an instance of [Settings]. + /// + /// If [typeHelpers] is not provided, the built-in helpers are used: + /// [BigIntHelper], [DateTimeHelper], [DurationHelper], [JsonHelper], and + /// [UriHelper]. + const Settings({ + JsonSerializable config, + List typeHelpers, + }) : _config = config ?? JsonSerializable.defaults, + _typeHelpers = typeHelpers ?? defaultHelpers; + + /// Creates an instance of [Settings]. + /// + /// [typeHelpers] provides a set of [TypeHelper] that will be used along with + /// the built-in helpers: + /// [BigIntHelper], [DateTimeHelper], [DurationHelper], [JsonHelper], and + /// [UriHelper]. + factory Settings.withDefaultHelpers( + Iterable typeHelpers, { + JsonSerializable config, + }) => + Settings( + config: config, + typeHelpers: List.unmodifiable(typeHelpers.followedBy(defaultHelpers)), + ); +} diff --git a/json_serializable/test/json_serializable_test.dart b/json_serializable/test/json_serializable_test.dart index cec29a125..c834eb220 100644 --- a/json_serializable/test/json_serializable_test.dart +++ b/json_serializable/test/json_serializable_test.dart @@ -17,7 +17,7 @@ Future main() async { testAnnotatedElements( reader, - const JsonSerializableGenerator(), + JsonSerializableGenerator(), expectedAnnotatedTests: _expectedAnnotatedTests, ); } From 243e9b2de15743f621ab657297aa2dccc0cb2af9 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 21 Sep 2020 17:45:59 -0700 Subject: [PATCH 235/569] Move generator helper into its own file --- .../lib/src/generator_helper.dart | 117 ++++++++++++++++++ .../lib/src/json_serializable_generator.dart | 112 +---------------- 2 files changed, 120 insertions(+), 109 deletions(-) create mode 100644 json_serializable/lib/src/generator_helper.dart diff --git a/json_serializable/lib/src/generator_helper.dart b/json_serializable/lib/src/generator_helper.dart new file mode 100644 index 000000000..011fd46d3 --- /dev/null +++ b/json_serializable/lib/src/generator_helper.dart @@ -0,0 +1,117 @@ +// Copyright (c) 2020, 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:analyzer/dart/element/element.dart'; +import 'package:build/build.dart'; +import 'package:source_gen/source_gen.dart'; + +import 'decode_helper.dart'; +import 'encoder_helper.dart'; +import 'field_helpers.dart'; +import 'helper_core.dart'; +import 'settings.dart'; +import 'type_helper.dart'; +import 'utils.dart'; + +class GeneratorHelper extends HelperCore with EncodeHelper, DecodeHelper { + final Settings _generator; + final _addedMembers = {}; + + GeneratorHelper( + this._generator, + ClassElement element, + ConstantReader annotation, + ) : super( + element, + mergeConfig( + _generator.config, + annotation, + classElement: element, + )); + + @override + void addMember(String memberContent) { + _addedMembers.add(memberContent); + } + + @override + Iterable get allTypeHelpers => _generator.allHelpers; + + Iterable generate() sync* { + assert(_addedMembers.isEmpty); + + if (config.genericArgumentFactories && element.typeParameters.isEmpty) { + log.warning( + 'The class `${element.displayName}` is annotated ' + 'with `JsonSerializable` field `genericArgumentFactories: true`. ' + '`genericArgumentFactories: true` only affects classes with type ' + 'parameters. For classes without type parameters, the option is ' + 'ignored.', + ); + } + + final sortedFields = createSortedFieldSet(element); + + // Used to keep track of why a field is ignored. Useful for providing + // helpful errors when generating constructor calls that try to use one of + // these fields. + final unavailableReasons = {}; + + final accessibleFields = sortedFields.fold>( + {}, + (map, field) { + if (!field.isPublic) { + unavailableReasons[field.name] = 'It is assigned to a private field.'; + } else if (field.getter == null) { + assert(field.setter != null); + unavailableReasons[field.name] = + 'Setter-only properties are not supported.'; + log.warning('Setters are ignored: ${element.name}.${field.name}'); + } else if (jsonKeyFor(field).ignore) { + unavailableReasons[field.name] = + 'It is assigned to an ignored field.'; + } else { + assert(!map.containsKey(field.name)); + map[field.name] = field; + } + + return map; + }, + ); + + var accessibleFieldSet = accessibleFields.values.toSet(); + if (config.createFactory) { + final createResult = createFactory(accessibleFields, unavailableReasons); + yield createResult.output; + + accessibleFieldSet = accessibleFields.entries + .where((e) => createResult.usedFields.contains(e.key)) + .map((e) => e.value) + .toSet(); + } + + // Check for duplicate JSON keys due to colliding annotations. + // We do this now, since we have a final field list after any pruning done + // by `_writeCtor`. + accessibleFieldSet.fold( + {}, + (Set set, fe) { + final jsonKey = nameAccess(fe); + if (!set.add(jsonKey)) { + throw InvalidGenerationSourceError( + 'More than one field has the JSON key for name "$jsonKey".', + element: fe, + ); + } + return set; + }, + ); + + if (config.createToJson) { + yield* createToJson(accessibleFieldSet); + } + + yield* _addedMembers; + } +} diff --git a/json_serializable/lib/src/json_serializable_generator.dart b/json_serializable/lib/src/json_serializable_generator.dart index ac73051ad..244017aeb 100644 --- a/json_serializable/lib/src/json_serializable_generator.dart +++ b/json_serializable/lib/src/json_serializable_generator.dart @@ -7,10 +7,7 @@ import 'package:build/build.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:source_gen/source_gen.dart'; -import 'decode_helper.dart'; -import 'encoder_helper.dart'; -import 'field_helpers.dart'; -import 'helper_core.dart'; +import 'generator_helper.dart'; import 'settings.dart'; import 'type_helper.dart'; import 'type_helpers/big_int_helper.dart'; @@ -18,7 +15,6 @@ import 'type_helpers/date_time_helper.dart'; import 'type_helpers/duration_helper.dart'; import 'type_helpers/json_helper.dart'; import 'type_helpers/uri_helper.dart'; -import 'utils.dart'; class JsonSerializableGenerator extends GeneratorForAnnotation { @@ -73,109 +69,7 @@ class JsonSerializableGenerator } final classElement = element as ClassElement; - final helper = _GeneratorHelper(_settings, classElement, annotation); - return helper._generate(); - } -} - -class _GeneratorHelper extends HelperCore with EncodeHelper, DecodeHelper { - final Settings _generator; - final _addedMembers = {}; - - _GeneratorHelper( - this._generator, - ClassElement element, - ConstantReader annotation, - ) : super( - element, - mergeConfig( - _generator.config, - annotation, - classElement: element, - )); - - @override - void addMember(String memberContent) { - _addedMembers.add(memberContent); - } - - @override - Iterable get allTypeHelpers => _generator.allHelpers; - - Iterable _generate() sync* { - assert(_addedMembers.isEmpty); - - if (config.genericArgumentFactories && element.typeParameters.isEmpty) { - log.warning( - 'The class `${element.displayName}` is annotated ' - 'with `JsonSerializable` field `genericArgumentFactories: true`. ' - '`genericArgumentFactories: true` only affects classes with type ' - 'parameters. For classes without type parameters, the option is ' - 'ignored.', - ); - } - - final sortedFields = createSortedFieldSet(element); - - // Used to keep track of why a field is ignored. Useful for providing - // helpful errors when generating constructor calls that try to use one of - // these fields. - final unavailableReasons = {}; - - final accessibleFields = sortedFields.fold>( - {}, - (map, field) { - if (!field.isPublic) { - unavailableReasons[field.name] = 'It is assigned to a private field.'; - } else if (field.getter == null) { - assert(field.setter != null); - unavailableReasons[field.name] = - 'Setter-only properties are not supported.'; - log.warning('Setters are ignored: ${element.name}.${field.name}'); - } else if (jsonKeyFor(field).ignore) { - unavailableReasons[field.name] = - 'It is assigned to an ignored field.'; - } else { - assert(!map.containsKey(field.name)); - map[field.name] = field; - } - - return map; - }, - ); - - var accessibleFieldSet = accessibleFields.values.toSet(); - if (config.createFactory) { - final createResult = createFactory(accessibleFields, unavailableReasons); - yield createResult.output; - - accessibleFieldSet = accessibleFields.entries - .where((e) => createResult.usedFields.contains(e.key)) - .map((e) => e.value) - .toSet(); - } - - // Check for duplicate JSON keys due to colliding annotations. - // We do this now, since we have a final field list after any pruning done - // by `_writeCtor`. - accessibleFieldSet.fold( - {}, - (Set set, fe) { - final jsonKey = nameAccess(fe); - if (!set.add(jsonKey)) { - throw InvalidGenerationSourceError( - 'More than one field has the JSON key for name "$jsonKey".', - element: fe, - ); - } - return set; - }, - ); - - if (config.createToJson) { - yield* createToJson(accessibleFieldSet); - } - - yield* _addedMembers; + final helper = GeneratorHelper(_settings, classElement, annotation); + return helper.generate(); } } From 609046938d2af76555b94bf59fbaf8834b73d411 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Sat, 26 Sep 2020 13:34:09 -0700 Subject: [PATCH 236/569] build.yaml cleanup --- json_serializable/build.yaml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/json_serializable/build.yaml b/json_serializable/build.yaml index 87e755c57..ac2d9172d 100644 --- a/json_serializable/build.yaml +++ b/json_serializable/build.yaml @@ -14,10 +14,7 @@ targets: build_web_compilers|entrypoint: generate_for: - - test/default_value/**.browser_test.dart - - test/generic_files/*.browser_test.dart - - test/integration/*.browser_test.dart - - test/kitchen_sink/**.browser_test.dart + - test/**/**.browser_test.dart json_serializable|_test_builder: generate_for: From ff447b8cab9ff659ccfa70c63923399ce19a3e13 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 12 Oct 2020 15:03:33 -0700 Subject: [PATCH 237/569] pubspec lint fixes (#731) --- _test_yaml/pubspec.yaml | 6 ++---- checked_yaml/pubspec.yaml | 2 +- example/pubspec.yaml | 6 +++++- example/test/readme_test.dart | 7 ++++++- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/_test_yaml/pubspec.yaml b/_test_yaml/pubspec.yaml index 0ea407c6a..857050d0b 100644 --- a/_test_yaml/pubspec.yaml +++ b/_test_yaml/pubspec.yaml @@ -1,4 +1,4 @@ -name: _test_yaml +name: test_yaml publish_to: none environment: @@ -7,12 +7,10 @@ environment: dev_dependencies: build_runner: ^1.0.0 build_verify: ^1.1.0 - test: ^1.6.0 - - # Repo packages checked_yaml: any json_annotation: any json_serializable: any + test: ^1.6.0 dependency_overrides: checked_yaml: diff --git a/checked_yaml/pubspec.yaml b/checked_yaml/pubspec.yaml index 6c18a1020..ef0d6ecb2 100644 --- a/checked_yaml/pubspec.yaml +++ b/checked_yaml/pubspec.yaml @@ -13,9 +13,9 @@ dependencies: yaml: ^2.1.13 dev_dependencies: - json_serializable: ^3.0.0 build_runner: ^1.0.0 build_verify: ^1.1.0 + json_serializable: ^3.0.0 path: ^1.0.0 test: ^1.6.0 test_process: ^1.0.1 diff --git a/example/pubspec.yaml b/example/pubspec.yaml index dd154be3e..fe8692d14 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -8,11 +8,15 @@ dependencies: dev_dependencies: build_runner: ^1.0.0 - json_serializable: ^3.2.0 # Used by tests. Not required to use `json_serializable`. build_verify: ^1.0.0 + + json_serializable: ^3.2.0 + + # Used by tests. Not required to use `json_serializable`. path: ^1.5.1 + # Used by tests. Not required to use `json_serializable`. test: ^1.6.0 dependency_overrides: diff --git a/example/test/readme_test.dart b/example/test/readme_test.dart index 414b97af9..342c07df8 100644 --- a/example/test/readme_test.dart +++ b/example/test/readme_test.dart @@ -2,6 +2,7 @@ // 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 'dart:convert'; import 'dart:io'; import 'package:test/test.dart'; @@ -14,7 +15,11 @@ void main() { void _expect(String fileName) { test(fileName, () { final file = File(fileName); - expect(file.readAsStringSync(), contains(_pubspecContent)); + + expect( + file.readAsStringSync(), + stringContainsInOrder(LineSplitter.split(_pubspecContent).toList()), + ); }); } From 77111f2cad7a16bc802b778109782f1a7487964b Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 14 Oct 2020 15:45:25 -0700 Subject: [PATCH 238/569] revert rename of _test_yaml (#732) --- _test_yaml/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_test_yaml/pubspec.yaml b/_test_yaml/pubspec.yaml index 857050d0b..4339901fe 100644 --- a/_test_yaml/pubspec.yaml +++ b/_test_yaml/pubspec.yaml @@ -1,4 +1,4 @@ -name: test_yaml +name: _test_yaml publish_to: none environment: From f6fc5d365a9aeba844900cadb14d293373e381be Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Fri, 16 Oct 2020 13:38:22 -0700 Subject: [PATCH 239/569] Enable mono_repo self-validate (#733) --- .travis.yml | 23 ++++++++++++++--------- mono_repo.yaml | 1 + tool/mono_repo_self_validate.sh | 15 +++++++++++++++ tool/travis.sh | 32 ++++++++++++++++---------------- 4 files changed, 46 insertions(+), 25 deletions(-) create mode 100755 tool/mono_repo_self_validate.sh diff --git a/.travis.yml b/.travis.yml index 608a989ac..d5677d365 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,4 @@ -# Created with package:mono_repo v2.3.0 +# Created with package:mono_repo v2.5.0 language: dart # Custom configuration @@ -8,56 +8,61 @@ branches: jobs: include: + - stage: mono_repo_self_validate + name: mono_repo self validate + os: linux + script: tool/mono_repo_self_validate.sh - stage: analyzer_and_format name: "SDK: 2.7.0; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; TASKS: `dartanalyzer --fatal-warnings .`" dart: "2.7.0" os: linux env: PKGS="_test_yaml checked_yaml example json_annotation json_serializable" - script: ./tool/travis.sh dartanalyzer_1 + script: tool/travis.sh dartanalyzer_1 - stage: analyzer_and_format name: "SDK: dev; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; TASKS: [`dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-warnings --fatal-infos .`]" dart: dev os: linux env: PKGS="_test_yaml checked_yaml example json_annotation json_serializable" - script: ./tool/travis.sh dartfmt dartanalyzer_0 + script: tool/travis.sh dartfmt dartanalyzer_0 - stage: unit_test name: "SDK: 2.7.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test`" dart: "2.7.0" os: linux env: PKGS="_test_yaml checked_yaml example json_serializable" - script: ./tool/travis.sh test_0 + script: tool/travis.sh test_0 - stage: unit_test name: "SDK: dev; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test`" dart: dev os: linux env: PKGS="_test_yaml checked_yaml example json_serializable" - script: ./tool/travis.sh test_0 + script: tool/travis.sh test_0 - stage: unit_test name: "SDK: 2.7.0; PKG: json_serializable; TASKS: `pub run build_runner test --delete-conflicting-outputs -- -p chrome`" dart: "2.7.0" os: linux env: PKGS="json_serializable" - script: ./tool/travis.sh command + script: tool/travis.sh command - stage: unit_test name: "SDK: dev; PKG: json_serializable; TASKS: `pub run build_runner test --delete-conflicting-outputs -- -p chrome`" dart: dev os: linux env: PKGS="json_serializable" - script: ./tool/travis.sh command + script: tool/travis.sh command - stage: ensure_build name: "SDK: 2.7.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`" dart: "2.7.0" os: linux env: PKGS="_test_yaml checked_yaml example json_serializable" - script: ./tool/travis.sh test_1 + script: tool/travis.sh test_1 - stage: ensure_build name: "SDK: dev; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`" dart: dev os: linux env: PKGS="_test_yaml checked_yaml example json_serializable" - script: ./tool/travis.sh test_1 + script: tool/travis.sh test_1 stages: + - mono_repo_self_validate - analyzer_and_format - unit_test - ensure_build diff --git a/mono_repo.yaml b/mono_repo.yaml index 1d276ac34..5f826d9dc 100644 --- a/mono_repo.yaml +++ b/mono_repo.yaml @@ -1,4 +1,5 @@ # See https://github.com/google/mono_repo.dart for details on this file +self_validate: true travis: branches: only: diff --git a/tool/mono_repo_self_validate.sh b/tool/mono_repo_self_validate.sh new file mode 100755 index 000000000..ec70a289c --- /dev/null +++ b/tool/mono_repo_self_validate.sh @@ -0,0 +1,15 @@ +#!/bin/bash +# Created with package:mono_repo v2.5.0 + +# Support built in commands on windows out of the box. +function pub { + if [[ $TRAVIS_OS_NAME == "windows" ]]; then + command pub.bat "$@" + else + command pub "$@" + fi +} + +set -v -e +pub global activate mono_repo 2.5.0 +pub global run mono_repo travis --validate diff --git a/tool/travis.sh b/tool/travis.sh index da9accd71..13ef245cf 100755 --- a/tool/travis.sh +++ b/tool/travis.sh @@ -1,27 +1,27 @@ #!/bin/bash -# Created with package:mono_repo v2.3.0 +# Created with package:mono_repo v2.5.0 # Support built in commands on windows out of the box. function pub { - if [[ $TRAVIS_OS_NAME == "windows" ]]; then - command pub.bat "$@" - else - command pub "$@" - fi + if [[ $TRAVIS_OS_NAME == "windows" ]]; then + command pub.bat "$@" + else + command pub "$@" + fi } function dartfmt { - if [[ $TRAVIS_OS_NAME == "windows" ]]; then - command dartfmt.bat "$@" - else - command dartfmt "$@" - fi + if [[ $TRAVIS_OS_NAME == "windows" ]]; then + command dartfmt.bat "$@" + else + command dartfmt "$@" + fi } function dartanalyzer { - if [[ $TRAVIS_OS_NAME == "windows" ]]; then - command dartanalyzer.bat "$@" - else - command dartanalyzer "$@" - fi + if [[ $TRAVIS_OS_NAME == "windows" ]]; then + command dartanalyzer.bat "$@" + else + command dartanalyzer "$@" + fi } if [[ -z ${PKGS} ]]; then From 4a1a533e36382062e5d493784cea122616429c22 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Sat, 31 Oct 2020 13:51:25 -0700 Subject: [PATCH 240/569] latest mono_repo (#737) --- .travis.yml | 7 +- mono_repo.yaml | 2 +- tool/mono_repo_self_validate.sh | 15 ---- tool/travis.sh | 133 +++++++++++++++++++------------- 4 files changed, 84 insertions(+), 73 deletions(-) delete mode 100755 tool/mono_repo_self_validate.sh diff --git a/.travis.yml b/.travis.yml index d5677d365..a3544d742 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,4 @@ -# Created with package:mono_repo v2.5.0 +# Created with package:mono_repo v3.0.0 language: dart # Custom configuration @@ -8,10 +8,10 @@ branches: jobs: include: - - stage: mono_repo_self_validate + - stage: analyzer_and_format name: mono_repo self validate os: linux - script: tool/mono_repo_self_validate.sh + script: "pub global activate mono_repo 3.0.0 && pub global run mono_repo travis --validate" - stage: analyzer_and_format name: "SDK: 2.7.0; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; TASKS: `dartanalyzer --fatal-warnings .`" dart: "2.7.0" @@ -62,7 +62,6 @@ jobs: script: tool/travis.sh test_1 stages: - - mono_repo_self_validate - analyzer_and_format - unit_test - ensure_build diff --git a/mono_repo.yaml b/mono_repo.yaml index 5f826d9dc..83a944382 100644 --- a/mono_repo.yaml +++ b/mono_repo.yaml @@ -1,5 +1,5 @@ # See https://github.com/google/mono_repo.dart for details on this file -self_validate: true +self_validate: analyzer_and_format travis: branches: only: diff --git a/tool/mono_repo_self_validate.sh b/tool/mono_repo_self_validate.sh deleted file mode 100755 index ec70a289c..000000000 --- a/tool/mono_repo_self_validate.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash -# Created with package:mono_repo v2.5.0 - -# Support built in commands on windows out of the box. -function pub { - if [[ $TRAVIS_OS_NAME == "windows" ]]; then - command pub.bat "$@" - else - command pub "$@" - fi -} - -set -v -e -pub global activate mono_repo 2.5.0 -pub global run mono_repo travis --validate diff --git a/tool/travis.sh b/tool/travis.sh index 13ef245cf..6dd1603b7 100755 --- a/tool/travis.sh +++ b/tool/travis.sh @@ -1,22 +1,22 @@ #!/bin/bash -# Created with package:mono_repo v2.5.0 +# Created with package:mono_repo v3.0.0 # Support built in commands on windows out of the box. -function pub { +function pub() { if [[ $TRAVIS_OS_NAME == "windows" ]]; then command pub.bat "$@" else command pub "$@" fi } -function dartfmt { +function dartfmt() { if [[ $TRAVIS_OS_NAME == "windows" ]]; then command dartfmt.bat "$@" else command dartfmt "$@" fi } -function dartanalyzer { +function dartanalyzer() { if [[ $TRAVIS_OS_NAME == "windows" ]]; then command dartanalyzer.bat "$@" else @@ -25,67 +25,94 @@ function dartanalyzer { } if [[ -z ${PKGS} ]]; then - echo -e '\033[31mPKGS environment variable must be set!\033[0m' - exit 1 + echo -e '\033[31mPKGS environment variable must be set! - TERMINATING JOB\033[0m' + exit 64 fi if [[ "$#" == "0" ]]; then - echo -e '\033[31mAt least one task argument must be provided!\033[0m' - exit 1 + echo -e '\033[31mAt least one task argument must be provided! - TERMINATING JOB\033[0m' + exit 64 fi -EXIT_CODE=0 +SUCCESS_COUNT=0 +declare -a FAILURES for PKG in ${PKGS}; do echo -e "\033[1mPKG: ${PKG}\033[22m" - pushd "${PKG}" || exit $? + EXIT_CODE=0 + pushd "${PKG}" >/dev/null || EXIT_CODE=$? + + if [[ ${EXIT_CODE} -ne 0 ]]; then + echo -e "\033[31mPKG: '${PKG}' does not exist - TERMINATING JOB\033[0m" + exit 64 + fi + + pub upgrade --no-precompile || EXIT_CODE=$? - PUB_EXIT_CODE=0 - pub upgrade --no-precompile || PUB_EXIT_CODE=$? + if [[ ${EXIT_CODE} -ne 0 ]]; then + echo -e "\033[31mPKG: ${PKG}; 'pub upgrade' - FAILED (${EXIT_CODE})\033[0m" + FAILURES+=("${PKG}; 'pub upgrade'") + else + for TASK in "$@"; do + EXIT_CODE=0 + echo + echo -e "\033[1mPKG: ${PKG}; TASK: ${TASK}\033[22m" + case ${TASK} in + command) + echo 'pub run build_runner test --delete-conflicting-outputs -- -p chrome' + pub run build_runner test --delete-conflicting-outputs -- -p chrome || EXIT_CODE=$? + ;; + dartanalyzer_0) + echo 'dartanalyzer --fatal-warnings --fatal-infos .' + dartanalyzer --fatal-warnings --fatal-infos . || EXIT_CODE=$? + ;; + dartanalyzer_1) + echo 'dartanalyzer --fatal-warnings .' + dartanalyzer --fatal-warnings . || EXIT_CODE=$? + ;; + dartfmt) + echo 'dartfmt -n --set-exit-if-changed .' + dartfmt -n --set-exit-if-changed . || EXIT_CODE=$? + ;; + test_0) + echo 'pub run test' + pub run test || EXIT_CODE=$? + ;; + test_1) + echo 'pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart' + pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart || EXIT_CODE=$? + ;; + *) + echo -e "\033[31mUnknown TASK '${TASK}' - TERMINATING JOB\033[0m" + exit 64 + ;; + esac - if [[ ${PUB_EXIT_CODE} -ne 0 ]]; then - EXIT_CODE=1 - echo -e '\033[31mpub upgrade failed\033[0m' - popd - continue + if [[ ${EXIT_CODE} -ne 0 ]]; then + echo -e "\033[31mPKG: ${PKG}; TASK: ${TASK} - FAILED (${EXIT_CODE})\033[0m" + FAILURES+=("${PKG}; TASK: ${TASK}") + else + echo -e "\033[32mPKG: ${PKG}; TASK: ${TASK} - SUCCEEDED\033[0m" + SUCCESS_COUNT=$((SUCCESS_COUNT + 1)) + fi + + done fi - for TASK in "$@"; do - echo - echo -e "\033[1mPKG: ${PKG}; TASK: ${TASK}\033[22m" - case ${TASK} in - command) - echo 'pub run build_runner test --delete-conflicting-outputs -- -p chrome' - pub run build_runner test --delete-conflicting-outputs -- -p chrome || EXIT_CODE=$? - ;; - dartanalyzer_0) - echo 'dartanalyzer --fatal-warnings --fatal-infos .' - dartanalyzer --fatal-warnings --fatal-infos . || EXIT_CODE=$? - ;; - dartanalyzer_1) - echo 'dartanalyzer --fatal-warnings .' - dartanalyzer --fatal-warnings . || EXIT_CODE=$? - ;; - dartfmt) - echo 'dartfmt -n --set-exit-if-changed .' - dartfmt -n --set-exit-if-changed . || EXIT_CODE=$? - ;; - test_0) - echo 'pub run test' - pub run test || EXIT_CODE=$? - ;; - test_1) - echo 'pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart' - pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart || EXIT_CODE=$? - ;; - *) - echo -e "\033[31mNot expecting TASK '${TASK}'. Error!\033[0m" - EXIT_CODE=1 - ;; - esac - done + echo + echo -e "\033[32mSUCCESS COUNT: ${SUCCESS_COUNT}\033[0m" + + if [ ${#FAILURES[@]} -ne 0 ]; then + echo -e "\033[31mFAILURES: ${#FAILURES[@]}\033[0m" + for i in "${FAILURES[@]}"; do + echo -e "\033[31m $i\033[0m" + done + fi - popd + popd >/dev/null || exit 70 + echo done -exit ${EXIT_CODE} +if [ ${#FAILURES[@]} -ne 0 ]; then + exit 1 +fi From fa97d28fd245c2e93015ebec4b2a38af062d0c60 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 4 Nov 2020 08:32:10 -0800 Subject: [PATCH 241/569] Drop build_web_compilers (#739) Not needed Speeds up build and test...a LOT --- .travis.yml | 8 ++++---- json_serializable/mono_pkg.yaml | 2 +- json_serializable/pubspec.yaml | 1 - tool/travis.sh | 8 ++++---- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index a3544d742..87f05e6e7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -37,17 +37,17 @@ jobs: env: PKGS="_test_yaml checked_yaml example json_serializable" script: tool/travis.sh test_0 - stage: unit_test - name: "SDK: 2.7.0; PKG: json_serializable; TASKS: `pub run build_runner test --delete-conflicting-outputs -- -p chrome`" + name: "SDK: 2.7.0; PKG: json_serializable; TASKS: `pub run test -p chrome`" dart: "2.7.0" os: linux env: PKGS="json_serializable" - script: tool/travis.sh command + script: tool/travis.sh test_2 - stage: unit_test - name: "SDK: dev; PKG: json_serializable; TASKS: `pub run build_runner test --delete-conflicting-outputs -- -p chrome`" + name: "SDK: dev; PKG: json_serializable; TASKS: `pub run test -p chrome`" dart: dev os: linux env: PKGS="json_serializable" - script: tool/travis.sh command + script: tool/travis.sh test_2 - stage: ensure_build name: "SDK: 2.7.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`" dart: "2.7.0" diff --git a/json_serializable/mono_pkg.yaml b/json_serializable/mono_pkg.yaml index 1933e6c12..485700e0e 100644 --- a/json_serializable/mono_pkg.yaml +++ b/json_serializable/mono_pkg.yaml @@ -14,7 +14,7 @@ stages: dart: [2.7.0] - unit_test: - test - - command: pub run build_runner test --delete-conflicting-outputs -- -p chrome + - test: -p chrome - ensure_build: - test: --run-skipped -t presubmit-only test/ensure_build_test.dart diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index b898dd745..53bb2223c 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -24,7 +24,6 @@ dependencies: dev_dependencies: build_runner: ^1.0.0 build_verify: ^1.1.0 - build_web_compilers: '>=1.0.0 <3.0.0' collection: ^1.14.0 dart_style: ^1.2.0 logging: ^0.11.3+1 diff --git a/tool/travis.sh b/tool/travis.sh index 6dd1603b7..14d4d0d36 100755 --- a/tool/travis.sh +++ b/tool/travis.sh @@ -58,10 +58,6 @@ for PKG in ${PKGS}; do echo echo -e "\033[1mPKG: ${PKG}; TASK: ${TASK}\033[22m" case ${TASK} in - command) - echo 'pub run build_runner test --delete-conflicting-outputs -- -p chrome' - pub run build_runner test --delete-conflicting-outputs -- -p chrome || EXIT_CODE=$? - ;; dartanalyzer_0) echo 'dartanalyzer --fatal-warnings --fatal-infos .' dartanalyzer --fatal-warnings --fatal-infos . || EXIT_CODE=$? @@ -82,6 +78,10 @@ for PKG in ${PKGS}; do echo 'pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart' pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart || EXIT_CODE=$? ;; + test_2) + echo 'pub run test -p chrome' + pub run test -p chrome || EXIT_CODE=$? + ;; *) echo -e "\033[31mUnknown TASK '${TASK}' - TERMINATING JOB\033[0m" exit 64 From cbba355144894f5d225c7a8e3f5eccb1d5f9be50 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 4 Nov 2020 12:05:20 -0800 Subject: [PATCH 242/569] Ignore package_names lint for now RE https://github.com/dart-lang/linter/issues/2331 --- analysis_options.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/analysis_options.yaml b/analysis_options.yaml index 74a2d9a9a..6338172a6 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1,6 +1,9 @@ analyzer: strong-mode: implicit-casts: false + errors: + # https://github.com/dart-lang/linter/issues/2331 + package_names: ignore linter: rules: From 211a0d627baff3e6b686a056225ea43ed4714b17 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Fri, 13 Nov 2020 17:28:51 -0800 Subject: [PATCH 243/569] Enable github actions (#743) --- .github/workflows/dart.yml | 113 +++++++++++++++++++++++++++++++++++++ .travis.yml | 20 +++---- mono_repo.yaml | 5 ++ tool/{travis.sh => ci.sh} | 2 +- 4 files changed, 129 insertions(+), 11 deletions(-) create mode 100644 .github/workflows/dart.yml rename tool/{travis.sh => ci.sh} (98%) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml new file mode 100644 index 000000000..ba02e9578 --- /dev/null +++ b/.github/workflows/dart.yml @@ -0,0 +1,113 @@ +# Created with package:mono_repo v3.1.0-beta.1 +name: Dart CI + +on: + push: + branches: [ master ] + pull_request: + +defaults: + run: + shell: bash + +jobs: + job_001: + name: "OS: linux; SDK: dev; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; TASKS: [`dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-warnings --fatal-infos .`]" + runs-on: ubuntu-latest + steps: + - uses: cedx/setup-dart@v2 + with: + release-channel: dev + - uses: actions/checkout@v2 + - env: + PKGS: _test_yaml checked_yaml example json_annotation json_serializable + TRAVIS_OS_NAME: linux + run: tool/ci.sh dartfmt dartanalyzer_0 + job_002: + name: "OS: linux; SDK: 2.7.0; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; TASKS: `dartanalyzer --fatal-warnings .`" + runs-on: ubuntu-latest + steps: + - uses: cedx/setup-dart@v2 + with: + release-channel: stable + version: "2.7.0" + - uses: actions/checkout@v2 + - env: + PKGS: _test_yaml checked_yaml example json_annotation json_serializable + TRAVIS_OS_NAME: linux + run: tool/ci.sh dartanalyzer_1 + job_003: + name: "OS: linux; SDK: 2.7.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test`" + runs-on: ubuntu-latest + steps: + - uses: cedx/setup-dart@v2 + with: + release-channel: stable + version: "2.7.0" + - uses: actions/checkout@v2 + - env: + PKGS: _test_yaml checked_yaml example json_serializable + TRAVIS_OS_NAME: linux + run: tool/ci.sh test_0 + job_004: + name: "OS: linux; SDK: dev; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test`" + runs-on: ubuntu-latest + steps: + - uses: cedx/setup-dart@v2 + with: + release-channel: dev + - uses: actions/checkout@v2 + - env: + PKGS: _test_yaml checked_yaml example json_serializable + TRAVIS_OS_NAME: linux + run: tool/ci.sh test_0 + job_005: + name: "OS: linux; SDK: 2.7.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`" + runs-on: ubuntu-latest + steps: + - uses: cedx/setup-dart@v2 + with: + release-channel: stable + version: "2.7.0" + - uses: actions/checkout@v2 + - env: + PKGS: _test_yaml checked_yaml example json_serializable + TRAVIS_OS_NAME: linux + run: tool/ci.sh test_1 + job_006: + name: "OS: linux; SDK: dev; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`" + runs-on: ubuntu-latest + steps: + - uses: cedx/setup-dart@v2 + with: + release-channel: dev + - uses: actions/checkout@v2 + - env: + PKGS: _test_yaml checked_yaml example json_serializable + TRAVIS_OS_NAME: linux + run: tool/ci.sh test_1 + job_007: + name: "OS: linux; SDK: 2.7.0; PKG: json_serializable; TASKS: `pub run test -p chrome`" + runs-on: ubuntu-latest + steps: + - uses: cedx/setup-dart@v2 + with: + release-channel: stable + version: "2.7.0" + - uses: actions/checkout@v2 + - env: + PKGS: json_serializable + TRAVIS_OS_NAME: linux + run: tool/ci.sh test_2 + job_008: + name: "OS: linux; SDK: dev; PKG: json_serializable; TASKS: `pub run test -p chrome`" + runs-on: ubuntu-latest + steps: + - uses: cedx/setup-dart@v2 + with: + release-channel: dev + - uses: actions/checkout@v2 + - env: + PKGS: json_serializable + TRAVIS_OS_NAME: linux + run: tool/ci.sh test_2 diff --git a/.travis.yml b/.travis.yml index 87f05e6e7..8ead88ba2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,4 @@ -# Created with package:mono_repo v3.0.0 +# Created with package:mono_repo v3.1.0-beta.1 language: dart # Custom configuration @@ -11,55 +11,55 @@ jobs: - stage: analyzer_and_format name: mono_repo self validate os: linux - script: "pub global activate mono_repo 3.0.0 && pub global run mono_repo travis --validate" + script: "pub global activate mono_repo 3.1.0-beta.1 && pub global run mono_repo generate --validate" - stage: analyzer_and_format name: "SDK: 2.7.0; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; TASKS: `dartanalyzer --fatal-warnings .`" dart: "2.7.0" os: linux env: PKGS="_test_yaml checked_yaml example json_annotation json_serializable" - script: tool/travis.sh dartanalyzer_1 + script: tool/ci.sh dartanalyzer_1 - stage: analyzer_and_format name: "SDK: dev; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; TASKS: [`dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-warnings --fatal-infos .`]" dart: dev os: linux env: PKGS="_test_yaml checked_yaml example json_annotation json_serializable" - script: tool/travis.sh dartfmt dartanalyzer_0 + script: tool/ci.sh dartfmt dartanalyzer_0 - stage: unit_test name: "SDK: 2.7.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test`" dart: "2.7.0" os: linux env: PKGS="_test_yaml checked_yaml example json_serializable" - script: tool/travis.sh test_0 + script: tool/ci.sh test_0 - stage: unit_test name: "SDK: dev; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test`" dart: dev os: linux env: PKGS="_test_yaml checked_yaml example json_serializable" - script: tool/travis.sh test_0 + script: tool/ci.sh test_0 - stage: unit_test name: "SDK: 2.7.0; PKG: json_serializable; TASKS: `pub run test -p chrome`" dart: "2.7.0" os: linux env: PKGS="json_serializable" - script: tool/travis.sh test_2 + script: tool/ci.sh test_2 - stage: unit_test name: "SDK: dev; PKG: json_serializable; TASKS: `pub run test -p chrome`" dart: dev os: linux env: PKGS="json_serializable" - script: tool/travis.sh test_2 + script: tool/ci.sh test_2 - stage: ensure_build name: "SDK: 2.7.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`" dart: "2.7.0" os: linux env: PKGS="_test_yaml checked_yaml example json_serializable" - script: tool/travis.sh test_1 + script: tool/ci.sh test_1 - stage: ensure_build name: "SDK: dev; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`" dart: dev os: linux env: PKGS="_test_yaml checked_yaml example json_serializable" - script: tool/travis.sh test_1 + script: tool/ci.sh test_1 stages: - analyzer_and_format diff --git a/mono_repo.yaml b/mono_repo.yaml index 83a944382..c1c1ff979 100644 --- a/mono_repo.yaml +++ b/mono_repo.yaml @@ -1,5 +1,10 @@ # See https://github.com/google/mono_repo.dart for details on this file self_validate: analyzer_and_format + +ci: +- github +- travis + travis: branches: only: diff --git a/tool/travis.sh b/tool/ci.sh similarity index 98% rename from tool/travis.sh rename to tool/ci.sh index 14d4d0d36..5fe2f4047 100755 --- a/tool/travis.sh +++ b/tool/ci.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Created with package:mono_repo v3.0.0 +# Created with package:mono_repo v3.1.0-beta.1 # Support built in commands on windows out of the box. function pub() { From ab39af2b4df9bee491cb859dcd23e2bec9e40ba6 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 18 Nov 2020 11:04:33 -0800 Subject: [PATCH 244/569] Fully migrate to GitHub Actions (#746) --- .github/workflows/dart.yml | 45 +++++++++++++++++------ .travis.yml | 74 -------------------------------------- README.md | 2 +- mono_repo.yaml | 12 ++----- tool/ci.sh | 2 +- 5 files changed, 39 insertions(+), 96 deletions(-) delete mode 100644 .travis.yml diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index ba02e9578..06e660f61 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -1,29 +1,45 @@ -# Created with package:mono_repo v3.1.0-beta.1 +# Created with package:mono_repo v3.1.0-beta.2 name: Dart CI - on: push: - branches: [ master ] + branches: + - $default-branch pull_request: - + schedule: + - cron: "0 0 * * 0" defaults: run: shell: bash +env: + PUB_ENVIRONMENT: bot.github jobs: job_001: + name: mono_repo self validate + runs-on: ubuntu-latest + steps: + - uses: cedx/setup-dart@v2 + with: + release-channel: stable + version: latest + - run: dart --version + - uses: actions/checkout@v2 + - run: pub global activate mono_repo 3.1.0-beta.2 + - run: pub global run mono_repo generate --validate + job_002: name: "OS: linux; SDK: dev; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; TASKS: [`dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-warnings --fatal-infos .`]" runs-on: ubuntu-latest steps: - uses: cedx/setup-dart@v2 with: release-channel: dev + - run: dart --version - uses: actions/checkout@v2 - env: PKGS: _test_yaml checked_yaml example json_annotation json_serializable TRAVIS_OS_NAME: linux run: tool/ci.sh dartfmt dartanalyzer_0 - job_002: + job_003: name: "OS: linux; SDK: 2.7.0; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; TASKS: `dartanalyzer --fatal-warnings .`" runs-on: ubuntu-latest steps: @@ -31,12 +47,13 @@ jobs: with: release-channel: stable version: "2.7.0" + - run: dart --version - uses: actions/checkout@v2 - env: PKGS: _test_yaml checked_yaml example json_annotation json_serializable TRAVIS_OS_NAME: linux run: tool/ci.sh dartanalyzer_1 - job_003: + job_004: name: "OS: linux; SDK: 2.7.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test`" runs-on: ubuntu-latest steps: @@ -44,24 +61,26 @@ jobs: with: release-channel: stable version: "2.7.0" + - run: dart --version - uses: actions/checkout@v2 - env: PKGS: _test_yaml checked_yaml example json_serializable TRAVIS_OS_NAME: linux run: tool/ci.sh test_0 - job_004: + job_005: name: "OS: linux; SDK: dev; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test`" runs-on: ubuntu-latest steps: - uses: cedx/setup-dart@v2 with: release-channel: dev + - run: dart --version - uses: actions/checkout@v2 - env: PKGS: _test_yaml checked_yaml example json_serializable TRAVIS_OS_NAME: linux run: tool/ci.sh test_0 - job_005: + job_006: name: "OS: linux; SDK: 2.7.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest steps: @@ -69,24 +88,26 @@ jobs: with: release-channel: stable version: "2.7.0" + - run: dart --version - uses: actions/checkout@v2 - env: PKGS: _test_yaml checked_yaml example json_serializable TRAVIS_OS_NAME: linux run: tool/ci.sh test_1 - job_006: + job_007: name: "OS: linux; SDK: dev; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest steps: - uses: cedx/setup-dart@v2 with: release-channel: dev + - run: dart --version - uses: actions/checkout@v2 - env: PKGS: _test_yaml checked_yaml example json_serializable TRAVIS_OS_NAME: linux run: tool/ci.sh test_1 - job_007: + job_008: name: "OS: linux; SDK: 2.7.0; PKG: json_serializable; TASKS: `pub run test -p chrome`" runs-on: ubuntu-latest steps: @@ -94,18 +115,20 @@ jobs: with: release-channel: stable version: "2.7.0" + - run: dart --version - uses: actions/checkout@v2 - env: PKGS: json_serializable TRAVIS_OS_NAME: linux run: tool/ci.sh test_2 - job_008: + job_009: name: "OS: linux; SDK: dev; PKG: json_serializable; TASKS: `pub run test -p chrome`" runs-on: ubuntu-latest steps: - uses: cedx/setup-dart@v2 with: release-channel: dev + - run: dart --version - uses: actions/checkout@v2 - env: PKGS: json_serializable diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 8ead88ba2..000000000 --- a/.travis.yml +++ /dev/null @@ -1,74 +0,0 @@ -# Created with package:mono_repo v3.1.0-beta.1 -language: dart - -# Custom configuration -branches: - only: - - master - -jobs: - include: - - stage: analyzer_and_format - name: mono_repo self validate - os: linux - script: "pub global activate mono_repo 3.1.0-beta.1 && pub global run mono_repo generate --validate" - - stage: analyzer_and_format - name: "SDK: 2.7.0; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; TASKS: `dartanalyzer --fatal-warnings .`" - dart: "2.7.0" - os: linux - env: PKGS="_test_yaml checked_yaml example json_annotation json_serializable" - script: tool/ci.sh dartanalyzer_1 - - stage: analyzer_and_format - name: "SDK: dev; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; TASKS: [`dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-warnings --fatal-infos .`]" - dart: dev - os: linux - env: PKGS="_test_yaml checked_yaml example json_annotation json_serializable" - script: tool/ci.sh dartfmt dartanalyzer_0 - - stage: unit_test - name: "SDK: 2.7.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test`" - dart: "2.7.0" - os: linux - env: PKGS="_test_yaml checked_yaml example json_serializable" - script: tool/ci.sh test_0 - - stage: unit_test - name: "SDK: dev; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test`" - dart: dev - os: linux - env: PKGS="_test_yaml checked_yaml example json_serializable" - script: tool/ci.sh test_0 - - stage: unit_test - name: "SDK: 2.7.0; PKG: json_serializable; TASKS: `pub run test -p chrome`" - dart: "2.7.0" - os: linux - env: PKGS="json_serializable" - script: tool/ci.sh test_2 - - stage: unit_test - name: "SDK: dev; PKG: json_serializable; TASKS: `pub run test -p chrome`" - dart: dev - os: linux - env: PKGS="json_serializable" - script: tool/ci.sh test_2 - - stage: ensure_build - name: "SDK: 2.7.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`" - dart: "2.7.0" - os: linux - env: PKGS="_test_yaml checked_yaml example json_serializable" - script: tool/ci.sh test_1 - - stage: ensure_build - name: "SDK: dev; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`" - dart: dev - os: linux - env: PKGS="_test_yaml checked_yaml example json_serializable" - script: tool/ci.sh test_1 - -stages: - - analyzer_and_format - - unit_test - - ensure_build - -cache: - directories: - - "$HOME/.pub-cache" - - _test_yaml/.dart_tool - - example/.dart_tool/build - - json_serializable/.dart_tool/build diff --git a/README.md b/README.md index 3345319ae..5f995b2c1 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Build Status](https://travis-ci.org/google/json_serializable.dart.svg?branch=master)](https://travis-ci.org/google/json_serializable.dart) +[![Dart CI](https://github.com/google/json_serializable.dart/workflows/Dart%20CI/badge.svg)](https://github.com/google/json_serializable.dart/actions?query=workflow%3A%22Dart+CI%22) Provides [source_gen] `Generator`s to create code for JSON serialization and deserialization. diff --git a/mono_repo.yaml b/mono_repo.yaml index c1c1ff979..a3c1aafc8 100644 --- a/mono_repo.yaml +++ b/mono_repo.yaml @@ -1,14 +1,8 @@ # See https://github.com/google/mono_repo.dart for details on this file -self_validate: analyzer_and_format +self_validate: true -ci: -- github -- travis - -travis: - branches: - only: - - master +github: + cron: '0 0 * * 0' # “At 00:00 (UTC) on Sunday.” merge_stages: - analyzer_and_format diff --git a/tool/ci.sh b/tool/ci.sh index 5fe2f4047..563a50024 100755 --- a/tool/ci.sh +++ b/tool/ci.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Created with package:mono_repo v3.1.0-beta.1 +# Created with package:mono_repo v3.1.0-beta.2 # Support built in commands on windows out of the box. function pub() { From c708628c97d383b1a5f2835f9cf4581f5564dd7a Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 18 Nov 2020 15:14:39 -0800 Subject: [PATCH 245/569] fix github action setup --- .github/workflows/dart.yml | 7 ++++--- tool/ci.sh | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 06e660f61..1c54b1f44 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -1,9 +1,10 @@ -# Created with package:mono_repo v3.1.0-beta.2 +# Created with package:mono_repo v3.1.0-beta.3 name: Dart CI on: push: branches: - - $default-branch + - main + - master pull_request: schedule: - cron: "0 0 * * 0" @@ -24,7 +25,7 @@ jobs: version: latest - run: dart --version - uses: actions/checkout@v2 - - run: pub global activate mono_repo 3.1.0-beta.2 + - run: pub global activate mono_repo 3.1.0-beta.3 - run: pub global run mono_repo generate --validate job_002: name: "OS: linux; SDK: dev; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; TASKS: [`dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-warnings --fatal-infos .`]" diff --git a/tool/ci.sh b/tool/ci.sh index 563a50024..e69d067a0 100755 --- a/tool/ci.sh +++ b/tool/ci.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Created with package:mono_repo v3.1.0-beta.2 +# Created with package:mono_repo v3.1.0-beta.3 # Support built in commands on windows out of the box. function pub() { From 7f1eb7d68dbab6008d362d241a12c33de6ccefa4 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Fri, 20 Nov 2020 10:14:46 -0800 Subject: [PATCH 246/569] Added a helpful `UnrecognizedKeysException.toString()` Fixes https://github.com/google/json_serializable.dart/issues/742 --- json_annotation/CHANGELOG.md | 1 + json_annotation/lib/src/allowed_keys_helpers.dart | 3 +++ 2 files changed, 4 insertions(+) diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index 8f407c692..624de39fb 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -1,5 +1,6 @@ ## 3.1.1-dev +- Added a helpful `UnrecognizedKeysException.toString()`. - Fixed doc comments for `JsonSerializable.genericArgumentFactories`. ## 3.1.0 diff --git a/json_annotation/lib/src/allowed_keys_helpers.dart b/json_annotation/lib/src/allowed_keys_helpers.dart index dbee77863..b3b9490f6 100644 --- a/json_annotation/lib/src/allowed_keys_helpers.dart +++ b/json_annotation/lib/src/allowed_keys_helpers.dart @@ -67,6 +67,9 @@ class UnrecognizedKeysException extends BadKeyException { UnrecognizedKeysException(this.unrecognizedKeys, Map map, this.allowedKeys) : super._(map); + + @override + String toString() => message; } /// Exception thrown if there are missing required keys in a JSON map that was From f3be8df15add63ff438afc523fe88ecbd65e9671 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Fri, 20 Nov 2020 10:22:32 -0800 Subject: [PATCH 247/569] Avoid `null` values for `CheckedFromJsonException.message` ...by using `toString()` with unrecognized error types. Fixes https://github.com/google/json_serializable.dart/issues/745 --- _test_yaml/test/yaml_test.dart | 4 ++-- json_annotation/CHANGELOG.md | 2 ++ json_annotation/lib/src/checked_helpers.dart | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/_test_yaml/test/yaml_test.dart b/_test_yaml/test/yaml_test.dart index 1d63a7c16..cd98b68a1 100644 --- a/_test_yaml/test/yaml_test.dart +++ b/_test_yaml/test/yaml_test.dart @@ -68,7 +68,7 @@ builders: - a - b ''': r''' -line 2, column 1 of file.yaml: Unsupported value for "builders". +line 2, column 1 of file.yaml: Unsupported value for "builders". type 'YamlList' is not a subtype of type 'Map' in type cast ╷ 2 │ ┌ - a 3 │ └ - b @@ -88,7 +88,7 @@ builders: a: target: 42 ''': r''' -line 3, column 13 of file.yaml: Unsupported value for "target". +line 3, column 13 of file.yaml: Unsupported value for "target". type 'int' is not a subtype of type 'String' in type cast ╷ 3 │ target: 42 │ ^^ diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index 624de39fb..68adc7df9 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -1,5 +1,7 @@ ## 3.1.1-dev +- Avoid `null` values for `CheckedFromJsonException.message` by using + `toString()` with unrecognized error types. - Added a helpful `UnrecognizedKeysException.toString()`. - Fixed doc comments for `JsonSerializable.genericArgumentFactories`. diff --git a/json_annotation/lib/src/checked_helpers.dart b/json_annotation/lib/src/checked_helpers.dart index eb2da567c..f3311a3e9 100644 --- a/json_annotation/lib/src/checked_helpers.dart +++ b/json_annotation/lib/src/checked_helpers.dart @@ -117,7 +117,7 @@ class CheckedFromJsonException implements Exception { } return message; } - return null; + return error.toString(); } @override From ce84c36c5f3d9f57addfebd4eec9537efcd13d7c Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Fri, 20 Nov 2020 10:22:59 -0800 Subject: [PATCH 248/569] prepare to release json_annotation v3.1.1 --- json_annotation/CHANGELOG.md | 2 +- json_annotation/pubspec.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index 68adc7df9..be64d02a6 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -1,4 +1,4 @@ -## 3.1.1-dev +## 3.1.1 - Avoid `null` values for `CheckedFromJsonException.message` by using `toString()` with unrecognized error types. diff --git a/json_annotation/pubspec.yaml b/json_annotation/pubspec.yaml index bdfff782d..6be7a1e1f 100644 --- a/json_annotation/pubspec.yaml +++ b/json_annotation/pubspec.yaml @@ -1,5 +1,5 @@ name: json_annotation -version: 3.1.1-dev +version: 3.1.1 description: >- Classes and helper functions that support JSON code generation via the `json_serializable` package. From bcd5e461ed51ded6444b9bb5574a4b054a1ca0c0 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Sat, 21 Nov 2020 16:24:27 -0800 Subject: [PATCH 249/569] Fix checked_yaml test duo to latest pkg:json_annotation (#752) --- checked_yaml/test/example_test.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/checked_yaml/test/example_test.dart b/checked_yaml/test/example_test.dart index 8da3a11d5..be5014926 100644 --- a/checked_yaml/test/example_test.dart +++ b/checked_yaml/test/example_test.dart @@ -81,7 +81,7 @@ line 1, column 2: Unrecognized keys: [bob]; supported keys: [name, count] _expectThrows( '{"name": 42, "count": 42}', r''' -line 1, column 10: Unsupported value for "name". +line 1, column 10: Unsupported value for "name". type 'int' is not a subtype of type 'String' in type cast ╷ 1 │ {"name": 42, "count": 42} │ ^^ From 49599e3e167bb93f015bc9a97495692b01ff844f Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 23 Nov 2020 18:11:48 -0800 Subject: [PATCH 250/569] Update latest mono_repo (#753) --- .github/workflows/dart.yml | 92 +++++++++++++++++++++++++++++++++++++- tool/ci.sh | 2 +- 2 files changed, 91 insertions(+), 3 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 1c54b1f44..7dfbaac5d 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -1,4 +1,4 @@ -# Created with package:mono_repo v3.1.0-beta.3 +# Created with package:mono_repo v3.1.0 name: Dart CI on: push: @@ -19,18 +19,36 @@ jobs: name: mono_repo self validate runs-on: ubuntu-latest steps: + - name: Cache Pub hosted dependencies + uses: actions/cache@v2 + with: + path: "~/.pub-cache/hosted" + key: "os:ubuntu-latest;pub-cache-hosted;dart:stable" + restore-keys: | + os:ubuntu-latest;pub-cache-hosted + os:ubuntu-latest - uses: cedx/setup-dart@v2 with: release-channel: stable version: latest - run: dart --version - uses: actions/checkout@v2 - - run: pub global activate mono_repo 3.1.0-beta.3 + - run: pub global activate mono_repo 3.1.0 - run: pub global run mono_repo generate --validate job_002: name: "OS: linux; SDK: dev; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; TASKS: [`dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-warnings --fatal-infos .`]" runs-on: ubuntu-latest steps: + - name: Cache Pub hosted dependencies + uses: actions/cache@v2 + with: + path: "~/.pub-cache/hosted" + key: "os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:dartfmt-dartanalyzer_0" + restore-keys: | + os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable + os:ubuntu-latest;pub-cache-hosted;dart:dev + os:ubuntu-latest;pub-cache-hosted + os:ubuntu-latest - uses: cedx/setup-dart@v2 with: release-channel: dev @@ -44,6 +62,16 @@ jobs: name: "OS: linux; SDK: 2.7.0; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; TASKS: `dartanalyzer --fatal-warnings .`" runs-on: ubuntu-latest steps: + - name: Cache Pub hosted dependencies + uses: actions/cache@v2 + with: + path: "~/.pub-cache/hosted" + key: "os:ubuntu-latest;pub-cache-hosted;dart:2.7.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:dartanalyzer_1" + restore-keys: | + os:ubuntu-latest;pub-cache-hosted;dart:2.7.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable + os:ubuntu-latest;pub-cache-hosted;dart:2.7.0 + os:ubuntu-latest;pub-cache-hosted + os:ubuntu-latest - uses: cedx/setup-dart@v2 with: release-channel: stable @@ -58,6 +86,16 @@ jobs: name: "OS: linux; SDK: 2.7.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test`" runs-on: ubuntu-latest steps: + - name: Cache Pub hosted dependencies + uses: actions/cache@v2 + with: + path: "~/.pub-cache/hosted" + key: "os:ubuntu-latest;pub-cache-hosted;dart:2.7.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" + restore-keys: | + os:ubuntu-latest;pub-cache-hosted;dart:2.7.0;packages:_test_yaml-checked_yaml-example-json_serializable + os:ubuntu-latest;pub-cache-hosted;dart:2.7.0 + os:ubuntu-latest;pub-cache-hosted + os:ubuntu-latest - uses: cedx/setup-dart@v2 with: release-channel: stable @@ -72,6 +110,16 @@ jobs: name: "OS: linux; SDK: dev; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test`" runs-on: ubuntu-latest steps: + - name: Cache Pub hosted dependencies + uses: actions/cache@v2 + with: + path: "~/.pub-cache/hosted" + key: "os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" + restore-keys: | + os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:_test_yaml-checked_yaml-example-json_serializable + os:ubuntu-latest;pub-cache-hosted;dart:dev + os:ubuntu-latest;pub-cache-hosted + os:ubuntu-latest - uses: cedx/setup-dart@v2 with: release-channel: dev @@ -85,6 +133,16 @@ jobs: name: "OS: linux; SDK: 2.7.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest steps: + - name: Cache Pub hosted dependencies + uses: actions/cache@v2 + with: + path: "~/.pub-cache/hosted" + key: "os:ubuntu-latest;pub-cache-hosted;dart:2.7.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_1" + restore-keys: | + os:ubuntu-latest;pub-cache-hosted;dart:2.7.0;packages:_test_yaml-checked_yaml-example-json_serializable + os:ubuntu-latest;pub-cache-hosted;dart:2.7.0 + os:ubuntu-latest;pub-cache-hosted + os:ubuntu-latest - uses: cedx/setup-dart@v2 with: release-channel: stable @@ -99,6 +157,16 @@ jobs: name: "OS: linux; SDK: dev; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest steps: + - name: Cache Pub hosted dependencies + uses: actions/cache@v2 + with: + path: "~/.pub-cache/hosted" + key: "os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_1" + restore-keys: | + os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:_test_yaml-checked_yaml-example-json_serializable + os:ubuntu-latest;pub-cache-hosted;dart:dev + os:ubuntu-latest;pub-cache-hosted + os:ubuntu-latest - uses: cedx/setup-dart@v2 with: release-channel: dev @@ -112,6 +180,16 @@ jobs: name: "OS: linux; SDK: 2.7.0; PKG: json_serializable; TASKS: `pub run test -p chrome`" runs-on: ubuntu-latest steps: + - name: Cache Pub hosted dependencies + uses: actions/cache@v2 + with: + path: "~/.pub-cache/hosted" + key: "os:ubuntu-latest;pub-cache-hosted;dart:2.7.0;packages:json_serializable;commands:test_2" + restore-keys: | + os:ubuntu-latest;pub-cache-hosted;dart:2.7.0;packages:json_serializable + os:ubuntu-latest;pub-cache-hosted;dart:2.7.0 + os:ubuntu-latest;pub-cache-hosted + os:ubuntu-latest - uses: cedx/setup-dart@v2 with: release-channel: stable @@ -126,6 +204,16 @@ jobs: name: "OS: linux; SDK: dev; PKG: json_serializable; TASKS: `pub run test -p chrome`" runs-on: ubuntu-latest steps: + - name: Cache Pub hosted dependencies + uses: actions/cache@v2 + with: + path: "~/.pub-cache/hosted" + key: "os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:json_serializable;commands:test_2" + restore-keys: | + os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:json_serializable + os:ubuntu-latest;pub-cache-hosted;dart:dev + os:ubuntu-latest;pub-cache-hosted + os:ubuntu-latest - uses: cedx/setup-dart@v2 with: release-channel: dev diff --git a/tool/ci.sh b/tool/ci.sh index e69d067a0..a2849db9f 100755 --- a/tool/ci.sh +++ b/tool/ci.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Created with package:mono_repo v3.1.0-beta.3 +# Created with package:mono_repo v3.1.0 # Support built in commands on windows out of the box. function pub() { From d7099dc5d493e2eab5128ebd76122459e714b40d Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Sat, 28 Nov 2020 18:16:10 -0800 Subject: [PATCH 251/569] update to the latest mono_repo (#756) --- .github/workflows/dart.yml | 78 +++++++++++++++++++++++++------------- mono_repo.yaml | 2 +- tool/ci.sh | 2 +- 3 files changed, 54 insertions(+), 28 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 7dfbaac5d..7d633f72a 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -1,4 +1,4 @@ -# Created with package:mono_repo v3.1.0 +# Created with package:mono_repo v3.3.0 name: Dart CI on: push: @@ -33,7 +33,7 @@ jobs: version: latest - run: dart --version - uses: actions/checkout@v2 - - run: pub global activate mono_repo 3.1.0 + - run: pub global activate mono_repo 3.3.0 - run: pub global run mono_repo generate --validate job_002: name: "OS: linux; SDK: dev; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; TASKS: [`dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-warnings --fatal-infos .`]" @@ -106,6 +106,10 @@ jobs: PKGS: _test_yaml checked_yaml example json_serializable TRAVIS_OS_NAME: linux run: tool/ci.sh test_0 + needs: + - job_001 + - job_002 + - job_003 job_005: name: "OS: linux; SDK: dev; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test`" runs-on: ubuntu-latest @@ -129,17 +133,21 @@ jobs: PKGS: _test_yaml checked_yaml example json_serializable TRAVIS_OS_NAME: linux run: tool/ci.sh test_0 - job_006: - name: "OS: linux; SDK: 2.7.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`" + needs: + - job_001 + - job_002 + - job_003 + job_008: + name: "OS: linux; SDK: 2.7.0; PKG: json_serializable; TASKS: `pub run test -p chrome`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@v2 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;dart:2.7.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_1" + key: "os:ubuntu-latest;pub-cache-hosted;dart:2.7.0;packages:json_serializable;commands:test_2" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;dart:2.7.0;packages:_test_yaml-checked_yaml-example-json_serializable + os:ubuntu-latest;pub-cache-hosted;dart:2.7.0;packages:json_serializable os:ubuntu-latest;pub-cache-hosted;dart:2.7.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest @@ -150,20 +158,24 @@ jobs: - run: dart --version - uses: actions/checkout@v2 - env: - PKGS: _test_yaml checked_yaml example json_serializable + PKGS: json_serializable TRAVIS_OS_NAME: linux - run: tool/ci.sh test_1 - job_007: - name: "OS: linux; SDK: dev; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`" + run: tool/ci.sh test_2 + needs: + - job_001 + - job_002 + - job_003 + job_009: + name: "OS: linux; SDK: dev; PKG: json_serializable; TASKS: `pub run test -p chrome`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@v2 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_1" + key: "os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:json_serializable;commands:test_2" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:_test_yaml-checked_yaml-example-json_serializable + os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:json_serializable os:ubuntu-latest;pub-cache-hosted;dart:dev os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest @@ -173,20 +185,24 @@ jobs: - run: dart --version - uses: actions/checkout@v2 - env: - PKGS: _test_yaml checked_yaml example json_serializable + PKGS: json_serializable TRAVIS_OS_NAME: linux - run: tool/ci.sh test_1 - job_008: - name: "OS: linux; SDK: 2.7.0; PKG: json_serializable; TASKS: `pub run test -p chrome`" + run: tool/ci.sh test_2 + needs: + - job_001 + - job_002 + - job_003 + job_006: + name: "OS: linux; SDK: 2.7.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@v2 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;dart:2.7.0;packages:json_serializable;commands:test_2" + key: "os:ubuntu-latest;pub-cache-hosted;dart:2.7.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_1" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;dart:2.7.0;packages:json_serializable + os:ubuntu-latest;pub-cache-hosted;dart:2.7.0;packages:_test_yaml-checked_yaml-example-json_serializable os:ubuntu-latest;pub-cache-hosted;dart:2.7.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest @@ -197,20 +213,25 @@ jobs: - run: dart --version - uses: actions/checkout@v2 - env: - PKGS: json_serializable + PKGS: _test_yaml checked_yaml example json_serializable TRAVIS_OS_NAME: linux - run: tool/ci.sh test_2 - job_009: - name: "OS: linux; SDK: dev; PKG: json_serializable; TASKS: `pub run test -p chrome`" + run: tool/ci.sh test_1 + needs: + - job_004 + - job_005 + - job_008 + - job_009 + job_007: + name: "OS: linux; SDK: dev; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@v2 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:json_serializable;commands:test_2" + key: "os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_1" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:json_serializable + os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:_test_yaml-checked_yaml-example-json_serializable os:ubuntu-latest;pub-cache-hosted;dart:dev os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest @@ -220,6 +241,11 @@ jobs: - run: dart --version - uses: actions/checkout@v2 - env: - PKGS: json_serializable + PKGS: _test_yaml checked_yaml example json_serializable TRAVIS_OS_NAME: linux - run: tool/ci.sh test_2 + run: tool/ci.sh test_1 + needs: + - job_004 + - job_005 + - job_008 + - job_009 diff --git a/mono_repo.yaml b/mono_repo.yaml index a3c1aafc8..e4ceeb944 100644 --- a/mono_repo.yaml +++ b/mono_repo.yaml @@ -1,5 +1,5 @@ # See https://github.com/google/mono_repo.dart for details on this file -self_validate: true +self_validate: analyzer_and_format github: cron: '0 0 * * 0' # “At 00:00 (UTC) on Sunday.” diff --git a/tool/ci.sh b/tool/ci.sh index a2849db9f..7e4a12bbe 100755 --- a/tool/ci.sh +++ b/tool/ci.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Created with package:mono_repo v3.1.0 +# Created with package:mono_repo v3.3.0 # Support built in commands on windows out of the box. function pub() { From 6b5cfd6087e38308988b635392a558154a923613 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 2 Dec 2020 08:15:14 -0800 Subject: [PATCH 252/569] Support null safety (#740) Fixes https://github.com/google/json_serializable.dart/issues/712 --- .github/workflows/dart.yml | 98 +- _test_yaml/mono_pkg.yaml | 4 - _test_yaml/pubspec.yaml | 2 +- _test_yaml/test/ensure_build_test.dart | 2 + _test_yaml/test/src/build_config.dart | 53 +- _test_yaml/test/src/build_config.g.dart | 83 +- _test_yaml/test/yaml_test.dart | 8 +- analysis_options.yaml | 3 - example/lib/example.dart | 42 +- example/lib/example.g.dart | 20 +- .../lib/generic_response_class_example.dart | 24 +- .../lib/generic_response_class_example.g.dart | 21 +- example/lib/json_converter_example.dart | 24 +- example/lib/json_converter_example.g.dart | 12 +- example/lib/tuple_example.dart | 6 +- example/lib/tuple_example.g.dart | 4 +- example/mono_pkg.yaml | 5 - example/pubspec.yaml | 6 +- example/test/ensure_build_test.dart | 2 + example/test/example_test.dart | 2 +- example/test/generic_response_class_test.dart | 2 +- json_annotation/CHANGELOG.md | 7 + .../lib/src/allowed_keys_helpers.dart | 20 +- json_annotation/lib/src/checked_helpers.dart | 52 +- json_annotation/lib/src/json_key.dart | 33 +- json_annotation/lib/src/json_literal.dart | 3 +- .../lib/src/json_serializable.dart | 34 +- .../lib/src/json_serializable.g.dart | 14 +- json_annotation/mono_pkg.yaml | 3 - json_annotation/pubspec.yaml | 6 +- json_serializable/CHANGELOG.md | 7 +- json_serializable/README.md | 54 +- json_serializable/build.yaml | 9 - json_serializable/doc/doc.md | 41 +- json_serializable/example/example.dart | 8 +- json_serializable/example/example.g.dart | 7 +- json_serializable/lib/src/constants.dart | 9 + json_serializable/lib/src/decode_helper.dart | 21 +- json_serializable/lib/src/encoder_helper.dart | 4 +- json_serializable/lib/src/helper_core.dart | 19 +- json_serializable/lib/src/json_key_utils.dart | 23 - .../lib/src/json_serializable_generator.dart | 8 + .../lib/src/shared_checkers.dart | 12 +- json_serializable/lib/src/type_helper.dart | 10 +- .../lib/src/type_helper_ctx.dart | 25 +- .../lib/src/type_helpers/big_int_helper.dart | 15 +- .../lib/src/type_helpers/convert_helper.dart | 6 +- .../src/type_helpers/date_time_helper.dart | 14 +- .../lib/src/type_helpers/duration_helper.dart | 6 +- .../lib/src/type_helpers/enum_helper.dart | 56 +- .../type_helpers/generic_factory_helper.dart | 1 + .../lib/src/type_helpers/iterable_helper.dart | 19 +- .../type_helpers/json_converter_helper.dart | 9 +- .../lib/src/type_helpers/json_helper.dart | 13 +- .../lib/src/type_helpers/map_helper.dart | 39 +- .../lib/src/type_helpers/uri_helper.dart | 11 +- .../lib/src/type_helpers/value_helper.dart | 20 +- json_serializable/lib/src/utils.dart | 8 +- json_serializable/mono_pkg.yaml | 7 +- json_serializable/pubspec.yaml | 19 +- json_serializable/test/config_test.dart | 1 - .../test/custom_configuration_test.dart | 23 +- .../test/default_value/default_value.dart | 17 +- .../test/default_value/default_value.g.dart | 136 +- .../default_value.g_any_map__checked.dart | 17 +- .../default_value.g_any_map__checked.g.dart | 168 +- .../default_value_interface.dart | 19 +- .../default_value/default_value_test.dart | 2 + .../generic_argument_factories.dart | 6 +- .../generic_argument_factories.g.dart | 37 +- .../test/generic_files/generic_class.dart | 39 +- .../test/generic_files/generic_class.g.dart | 15 +- .../test/generic_files/generic_test.dart | 4 +- .../test/integration/integration_test.dart | 28 +- .../test/integration/json_test_common.dart | 14 +- .../test/integration/json_test_example.dart | 80 +- .../test/integration/json_test_example.g.dart | 151 +- .../json_test_example.g_any_map.dart | 80 +- .../json_test_example.g_any_map.g.dart | 163 +- .../json_test_example.g_non_nullable.dart | 206 - .../json_test_example.g_non_nullable.g.dart | 203 - .../test/json_serializable_test.dart | 21 +- .../test/kitchen_sink/json_converters.dart | 28 +- .../test/kitchen_sink/kitchen_sink.dart | 103 +- .../kitchen_sink/kitchen_sink.factories.dart | 15 +- .../test/kitchen_sink/kitchen_sink.g.dart | 188 +- .../kitchen_sink/kitchen_sink.g_any_map.dart | 103 +- .../kitchen_sink.g_any_map.g.dart | 186 +- ...t => kitchen_sink.g_any_map__checked.dart} | 112 +- ...=> kitchen_sink.g_any_map__checked.g.dart} | 206 +- .../kitchen_sink.g_any_map__non_nullable.dart | 200 - ...itchen_sink.g_any_map__non_nullable.g.dart | 168 - .../kitchen_sink.g_exclude_null.dart | 103 +- .../kitchen_sink.g_exclude_null.g.dart | 243 +- ...hen_sink.g_exclude_null__non_nullable.dart | 202 - ...n_sink.g_exclude_null__non_nullable.g.dart | 189 - .../kitchen_sink.g_explicit_to_json.dart | 103 +- .../kitchen_sink.g_explicit_to_json.g.dart | 192 +- .../kitchen_sink.g_non_nullable.dart | 199 - .../kitchen_sink.g_non_nullable.g.dart | 171 - .../kitchen_sink/kitchen_sink_interface.dart | 82 +- .../test/kitchen_sink/kitchen_sink_test.dart | 273 +- .../kitchen_sink_test_shared.dart | 80 + .../kitchen_sink/kitchen_sink_yaml_test.dart | 113 + .../test/kitchen_sink/simple_object.dart | 2 + .../test/kitchen_sink/simple_object.g.dart | 1 + .../test/kitchen_sink/strict_keys_object.dart | 2 + .../kitchen_sink/strict_keys_object.g.dart | 1 + json_serializable/test/shared_config.dart | 1 - .../src/_json_serializable_test_input.dart | 120 +- .../test/src/checked_test_input.dart | 8 +- .../test/src/core_subclass_type_input.dart | 14 +- .../test/src/default_value_input.dart | 64 +- .../test/src/field_namer_input.dart | 18 +- .../test/src/generic_test_input.dart | 16 +- .../test/src/inheritance_test_input.dart | 25 +- .../test/src/json_converter_test_input.dart | 35 +- .../test/src/map_key_variety_test_input.dart | 36 +- .../test/src/setter_test_input.dart | 2 + .../test/src/to_from_json_test_input.dart | 71 +- .../src/unknown_enum_value_test_input.dart | 57 +- .../test/supported_types/enum_type.dart | 2 + .../test/supported_types/input.dart | 11 +- .../test/supported_types/input.g.dart | 6 +- .../supported_types/input.type_bigint.dart | 24 +- .../supported_types/input.type_bigint.g.dart | 17 +- .../test/supported_types/input.type_bool.dart | 29 +- .../supported_types/input.type_bool.g.dart | 20 +- .../supported_types/input.type_datetime.dart | 24 +- .../input.type_datetime.g.dart | 17 +- .../supported_types/input.type_double.dart | 29 +- .../supported_types/input.type_double.g.dart | 22 +- .../supported_types/input.type_duration.dart | 24 +- .../input.type_duration.g.dart | 17 +- .../supported_types/input.type_enumtype.dart | 29 +- .../input.type_enumtype.g.dart | 81 +- .../test/supported_types/input.type_int.dart | 29 +- .../supported_types/input.type_int.g.dart | 20 +- .../supported_types/input.type_iterable.dart | 671 +- .../input.type_iterable.g.dart | 672 +- .../test/supported_types/input.type_list.dart | 671 +- .../supported_types/input.type_list.g.dart | 707 +- .../test/supported_types/input.type_map.dart | 5859 +++++++++++++--- .../supported_types/input.type_map.g.dart | 6096 ++++++++++++++--- .../test/supported_types/input.type_num.dart | 29 +- .../supported_types/input.type_num.g.dart | 20 +- .../supported_types/input.type_object.dart | 30 +- .../supported_types/input.type_object.g.dart | 21 +- .../test/supported_types/input.type_set.dart | 671 +- .../supported_types/input.type_set.g.dart | 706 +- .../supported_types/input.type_string.dart | 29 +- .../supported_types/input.type_string.g.dart | 20 +- .../test/supported_types/input.type_uri.dart | 24 +- .../supported_types/input.type_uri.g.dart | 17 +- .../type_test.bigint_test.dart | 97 +- .../supported_types/type_test.bool_test.dart | 98 +- .../test/supported_types/type_test.dart | 64 +- .../type_test.datetime_test.dart | 97 +- .../type_test.double_test.dart | 98 +- .../type_test.duration_test.dart | 97 +- .../type_test.enumtype_test.dart | 98 +- .../supported_types/type_test.int_test.dart | 98 +- .../type_test.iterable_test.dart | 98 +- .../supported_types/type_test.list_test.dart | 98 +- .../supported_types/type_test.map_test.dart | 98 +- .../supported_types/type_test.num_test.dart | 98 +- .../type_test.object_test.dart | 104 +- .../supported_types/type_test.set_test.dart | 98 +- .../type_test.string_test.dart | 98 +- .../supported_types/type_test.uri_test.dart | 97 +- .../test/test_sources/test_sources.dart | 43 +- json_serializable/test/test_utils.dart | 34 +- json_serializable/tool/test_builder.dart | 52 +- json_serializable/tool/test_type_builder.dart | 12 +- json_serializable/tool/test_type_data.dart | 110 +- 175 files changed, 17783 insertions(+), 6905 deletions(-) delete mode 100644 json_serializable/test/integration/json_test_example.g_non_nullable.dart delete mode 100644 json_serializable/test/integration/json_test_example.g_non_nullable.g.dart rename json_serializable/test/kitchen_sink/{kitchen_sink.g_any_map__checked__non_nullable.dart => kitchen_sink.g_any_map__checked.dart} (75%) rename json_serializable/test/kitchen_sink/{kitchen_sink.g_any_map__checked__non_nullable.g.dart => kitchen_sink.g_any_map__checked.g.dart} (56%) delete mode 100644 json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable.dart delete mode 100644 json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable.g.dart delete mode 100644 json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__non_nullable.dart delete mode 100644 json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__non_nullable.g.dart delete mode 100644 json_serializable/test/kitchen_sink/kitchen_sink.g_non_nullable.dart delete mode 100644 json_serializable/test/kitchen_sink/kitchen_sink.g_non_nullable.g.dart create mode 100644 json_serializable/test/kitchen_sink/kitchen_sink_test_shared.dart create mode 100644 json_serializable/test/kitchen_sink/kitchen_sink_yaml_test.dart diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 7d633f72a..463afb234 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -36,16 +36,16 @@ jobs: - run: pub global activate mono_repo 3.3.0 - run: pub global run mono_repo generate --validate job_002: - name: "OS: linux; SDK: dev; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; TASKS: [`dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-warnings --fatal-infos .`]" + name: "OS: linux; SDK: dev; PKGS: _test_yaml, checked_yaml, json_annotation, json_serializable; TASKS: [`dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-warnings --fatal-infos .`]" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@v2 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:dartfmt-dartanalyzer_0" + key: "os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:_test_yaml-checked_yaml-json_annotation-json_serializable;commands:dartfmt-dartanalyzer_0" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable + os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:_test_yaml-checked_yaml-json_annotation-json_serializable os:ubuntu-latest;pub-cache-hosted;dart:dev os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest @@ -55,20 +55,20 @@ jobs: - run: dart --version - uses: actions/checkout@v2 - env: - PKGS: _test_yaml checked_yaml example json_annotation json_serializable + PKGS: _test_yaml checked_yaml json_annotation json_serializable TRAVIS_OS_NAME: linux run: tool/ci.sh dartfmt dartanalyzer_0 - job_003: - name: "OS: linux; SDK: 2.7.0; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; TASKS: `dartanalyzer --fatal-warnings .`" + job_005: + name: "OS: linux; SDK: 2.7.0; PKG: checked_yaml; TASKS: `dartanalyzer --fatal-warnings .`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@v2 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;dart:2.7.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:dartanalyzer_1" + key: "os:ubuntu-latest;pub-cache-hosted;dart:2.7.0;packages:checked_yaml;commands:dartanalyzer_1" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;dart:2.7.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable + os:ubuntu-latest;pub-cache-hosted;dart:2.7.0;packages:checked_yaml os:ubuntu-latest;pub-cache-hosted;dart:2.7.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest @@ -79,38 +79,33 @@ jobs: - run: dart --version - uses: actions/checkout@v2 - env: - PKGS: _test_yaml checked_yaml example json_annotation json_serializable + PKGS: checked_yaml TRAVIS_OS_NAME: linux run: tool/ci.sh dartanalyzer_1 - job_004: - name: "OS: linux; SDK: 2.7.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test`" + job_008: + name: "OS: linux; SDK: dev; PKG: example; TASKS: [`dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-warnings .`]" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@v2 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;dart:2.7.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" + key: "os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:example;commands:dartfmt-dartanalyzer_1" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;dart:2.7.0;packages:_test_yaml-checked_yaml-example-json_serializable - os:ubuntu-latest;pub-cache-hosted;dart:2.7.0 + os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:example + os:ubuntu-latest;pub-cache-hosted;dart:dev os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - uses: cedx/setup-dart@v2 with: - release-channel: stable - version: "2.7.0" + release-channel: dev - run: dart --version - uses: actions/checkout@v2 - env: - PKGS: _test_yaml checked_yaml example json_serializable + PKGS: example TRAVIS_OS_NAME: linux - run: tool/ci.sh test_0 - needs: - - job_001 - - job_002 - - job_003 - job_005: + run: tool/ci.sh dartfmt dartanalyzer_1 + job_003: name: "OS: linux; SDK: dev; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test`" runs-on: ubuntu-latest steps: @@ -136,18 +131,19 @@ jobs: needs: - job_001 - job_002 - - job_003 - job_008: - name: "OS: linux; SDK: 2.7.0; PKG: json_serializable; TASKS: `pub run test -p chrome`" + - job_005 + - job_008 + job_006: + name: "OS: linux; SDK: 2.7.0; PKG: checked_yaml; TASKS: `pub run test`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@v2 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;dart:2.7.0;packages:json_serializable;commands:test_2" + key: "os:ubuntu-latest;pub-cache-hosted;dart:2.7.0;packages:checked_yaml;commands:test_0" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;dart:2.7.0;packages:json_serializable + os:ubuntu-latest;pub-cache-hosted;dart:2.7.0;packages:checked_yaml os:ubuntu-latest;pub-cache-hosted;dart:2.7.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest @@ -158,13 +154,14 @@ jobs: - run: dart --version - uses: actions/checkout@v2 - env: - PKGS: json_serializable + PKGS: checked_yaml TRAVIS_OS_NAME: linux - run: tool/ci.sh test_2 + run: tool/ci.sh test_0 needs: - job_001 - job_002 - - job_003 + - job_005 + - job_008 job_009: name: "OS: linux; SDK: dev; PKG: json_serializable; TASKS: `pub run test -p chrome`" runs-on: ubuntu-latest @@ -191,25 +188,25 @@ jobs: needs: - job_001 - job_002 - - job_003 - job_006: - name: "OS: linux; SDK: 2.7.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`" + - job_005 + - job_008 + job_004: + name: "OS: linux; SDK: dev; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@v2 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;dart:2.7.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_1" + key: "os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_1" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;dart:2.7.0;packages:_test_yaml-checked_yaml-example-json_serializable - os:ubuntu-latest;pub-cache-hosted;dart:2.7.0 + os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:_test_yaml-checked_yaml-example-json_serializable + os:ubuntu-latest;pub-cache-hosted;dart:dev os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - uses: cedx/setup-dart@v2 with: - release-channel: stable - version: "2.7.0" + release-channel: dev - run: dart --version - uses: actions/checkout@v2 - env: @@ -217,35 +214,34 @@ jobs: TRAVIS_OS_NAME: linux run: tool/ci.sh test_1 needs: - - job_004 - - job_005 - - job_008 + - job_003 + - job_006 - job_009 job_007: - name: "OS: linux; SDK: dev; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`" + name: "OS: linux; SDK: 2.7.0; PKG: checked_yaml; TASKS: `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@v2 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_1" + key: "os:ubuntu-latest;pub-cache-hosted;dart:2.7.0;packages:checked_yaml;commands:test_1" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:_test_yaml-checked_yaml-example-json_serializable - os:ubuntu-latest;pub-cache-hosted;dart:dev + os:ubuntu-latest;pub-cache-hosted;dart:2.7.0;packages:checked_yaml + os:ubuntu-latest;pub-cache-hosted;dart:2.7.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - uses: cedx/setup-dart@v2 with: - release-channel: dev + release-channel: stable + version: "2.7.0" - run: dart --version - uses: actions/checkout@v2 - env: - PKGS: _test_yaml checked_yaml example json_serializable + PKGS: checked_yaml TRAVIS_OS_NAME: linux run: tool/ci.sh test_1 needs: - - job_004 - - job_005 - - job_008 + - job_003 + - job_006 - job_009 diff --git a/_test_yaml/mono_pkg.yaml b/_test_yaml/mono_pkg.yaml index 676aaa38d..5525b49be 100644 --- a/_test_yaml/mono_pkg.yaml +++ b/_test_yaml/mono_pkg.yaml @@ -1,6 +1,5 @@ # See https://github.com/google/mono_repo.dart for details on this file dart: -- 2.7.0 - dev stages: @@ -9,9 +8,6 @@ stages: - dartfmt - dartanalyzer: --fatal-warnings --fatal-infos . dart: [dev] - - group: - - dartanalyzer: --fatal-warnings . - dart: [2.7.0] - unit_test: - test - ensure_build: diff --git a/_test_yaml/pubspec.yaml b/_test_yaml/pubspec.yaml index 4339901fe..819790eb4 100644 --- a/_test_yaml/pubspec.yaml +++ b/_test_yaml/pubspec.yaml @@ -2,7 +2,7 @@ name: _test_yaml publish_to: none environment: - sdk: '>=2.7.0 <3.0.0' + sdk: '>=2.12.0-0 <3.0.0' dev_dependencies: build_runner: ^1.0.0 diff --git a/_test_yaml/test/ensure_build_test.dart b/_test_yaml/test/ensure_build_test.dart index acd110e44..85f180ff7 100644 --- a/_test_yaml/test/ensure_build_test.dart +++ b/_test_yaml/test/ensure_build_test.dart @@ -2,6 +2,8 @@ // 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. +// @dart=2.9 + @TestOn('vm') @Tags(['presubmit-only']) import 'package:build_verify/build_verify.dart'; diff --git a/_test_yaml/test/src/build_config.dart b/_test_yaml/test/src/build_config.dart index 7d5f707fd..91e0383e8 100644 --- a/_test_yaml/test/src/build_config.dart +++ b/_test_yaml/test/src/build_config.dart @@ -3,7 +3,6 @@ // BSD-style license that can be found in the LICENSE file. import 'package:json_annotation/json_annotation.dart'; -import 'package:meta/meta.dart'; part 'build_config.g.dart'; @@ -13,9 +12,9 @@ class Config { final Map builders; // Verifying enum keys in map - Map weights; + Map? weights; - Config({@required this.builders}); + Config({required this.builders}); factory Config.fromJson(Map map) => _$ConfigFromJson(map); @@ -28,49 +27,49 @@ class Config { checked: true, anyMap: true) class Builder { - @JsonKey(nullable: true) - final String target; + final String? target; final String import; @JsonKey(name: 'is_optional') - final bool isOptional; + final bool? isOptional; @JsonKey(disallowNullValue: true) - final Uri configLocation; + final Uri? configLocation; @JsonKey(name: 'auto_apply', disallowNullValue: true) - final AutoApply autoApply; + final AutoApply? autoApply; @JsonKey(name: 'build_to') - final BuildTo buildTo; + final BuildTo? buildTo; - final AutoApply defaultEnumTest; + final AutoApply? defaultEnumTest; - @JsonKey(name: 'builder_factories', nullable: false) + @JsonKey(name: 'builder_factories') final List builderFactories; @JsonKey(name: 'applies_builders') - final List appliesBuilders; + final List? appliesBuilders; @JsonKey(name: 'required_inputs') - final List requiredInputs; + final List? requiredInputs; @JsonKey(name: 'build_extensions') - final Map> buildExtensions; - - Builder( - {@required this.import, - this.target, - this.isOptional, - this.autoApply, - this.buildTo, - this.defaultEnumTest, - this.builderFactories, - this.appliesBuilders, - this.requiredInputs, - this.buildExtensions, - this.configLocation}) { + final Map>? buildExtensions; + + Builder({ + required this.import, + this.target, + this.isOptional, + this.autoApply, + this.buildTo, + this.defaultEnumTest, + required this.builderFactories, + this.appliesBuilders, + this.requiredInputs, + this.buildExtensions, + this.configLocation, + }) { if (builderFactories.isEmpty) { throw ArgumentError.value(builderFactories, 'builderFactories', 'Must have at least one value.'); diff --git a/_test_yaml/test/src/build_config.g.dart b/_test_yaml/test/src/build_config.g.dart index 7e247020a..813cea427 100644 --- a/_test_yaml/test/src/build_config.g.dart +++ b/_test_yaml/test/src/build_config.g.dart @@ -13,17 +13,15 @@ Config _$ConfigFromJson(Map json) { builders: $checkedConvert( json, 'builders', - (v) => (v as Map)?.map( - (k, e) => MapEntry( - k as String, e == null ? null : Builder.fromJson(e as Map)), + (v) => (v as Map).map( + (k, e) => MapEntry(k as String, Builder.fromJson(e as Map)), )), ); $checkedConvert( json, 'weights', - (v) => val.weights = (v as Map)?.map( - (k, e) => MapEntry( - _$enumDecodeNullable(_$AutoApplyEnumMap, k), e as int), + (v) => val.weights = (v as Map?)?.map( + (k, e) => MapEntry(_$enumDecode(_$AutoApplyEnumMap, k), e as int), )); return val; }); @@ -35,36 +33,30 @@ Map _$ConfigToJson(Config instance) => { instance.weights?.map((k, e) => MapEntry(_$AutoApplyEnumMap[k], e)), }; -T _$enumDecode( - Map enumValues, - dynamic source, { - T unknownValue, +K _$enumDecode( + Map enumValues, + Object? source, { + K? unknownValue, }) { if (source == null) { - throw ArgumentError('A value must be provided. Supported values: ' - '${enumValues.values.join(', ')}'); + throw ArgumentError( + 'A value must be provided. Supported values: ' + '${enumValues.values.join(', ')}', + ); } - final value = enumValues.entries - .singleWhere((e) => e.value == source, orElse: () => null) - ?.key; - - if (value == null && unknownValue == null) { - throw ArgumentError('`$source` is not one of the supported values: ' - '${enumValues.values.join(', ')}'); - } - return value ?? unknownValue; -} - -T _$enumDecodeNullable( - Map enumValues, - dynamic source, { - T unknownValue, -}) { - if (source == null) { - return null; - } - return _$enumDecode(enumValues, source, unknownValue: unknownValue); + return enumValues.entries.singleWhere( + (e) => e.value == source, + orElse: () { + if (unknownValue == null) { + throw ArgumentError( + '`$source` is not one of the supported values: ' + '${enumValues.values.join(', ')}', + ); + } + return MapEntry(unknownValue, enumValues.values.first); + }, + ).key; } const _$AutoApplyEnumMap = { @@ -94,8 +86,8 @@ Builder _$BuilderFromJson(Map json) { ]); final val = Builder( import: $checkedConvert(json, 'import', (v) => v as String), - target: $checkedConvert(json, 'target', (v) => v as String), - isOptional: $checkedConvert(json, 'is_optional', (v) => v as bool), + target: $checkedConvert(json, 'target', (v) => v as String?), + isOptional: $checkedConvert(json, 'is_optional', (v) => v as bool?), autoApply: $checkedConvert(json, 'auto_apply', (v) => _$enumDecodeNullable(_$AutoApplyEnumMap, v)), buildTo: $checkedConvert( @@ -103,17 +95,17 @@ Builder _$BuilderFromJson(Map json) { defaultEnumTest: $checkedConvert(json, 'defaultEnumTest', (v) => _$enumDecodeNullable(_$AutoApplyEnumMap, v)), builderFactories: $checkedConvert(json, 'builder_factories', - (v) => (v as List).map((e) => e as String).toList()), + (v) => (v as List).map((e) => e as String).toList()), appliesBuilders: $checkedConvert(json, 'applies_builders', - (v) => (v as List)?.map((e) => e as String)?.toList()), + (v) => (v as List?)?.map((e) => e as String).toList()), requiredInputs: $checkedConvert(json, 'required_inputs', - (v) => (v as List)?.map((e) => e as String)?.toList()), + (v) => (v as List?)?.map((e) => e as String).toList()), buildExtensions: $checkedConvert( json, 'build_extensions', - (v) => (v as Map)?.map( + (v) => (v as Map?)?.map( (k, e) => MapEntry(k as String, - (e as List)?.map((e) => e as String)?.toList()), + (e as List).map((e) => e as String).toList()), )), configLocation: $checkedConvert(json, 'configLocation', (v) => v == null ? null : Uri.parse(v as String)), @@ -140,7 +132,7 @@ Map _$BuilderToJson(Builder instance) { } writeNotNull('target', instance.target); - writeNotNull('import', instance.import); + val['import'] = instance.import; writeNotNull('is_optional', instance.isOptional); writeNotNull('configLocation', instance.configLocation?.toString()); writeNotNull('auto_apply', _$AutoApplyEnumMap[instance.autoApply]); @@ -153,6 +145,17 @@ Map _$BuilderToJson(Builder instance) { return val; } +K? _$enumDecodeNullable( + Map enumValues, + dynamic source, { + K? unknownValue, +}) { + if (source == null) { + return null; + } + return _$enumDecode(enumValues, source, unknownValue: unknownValue); +} + const _$BuildToEnumMap = { BuildTo.cache: 'cache', BuildTo.source: 'source', diff --git a/_test_yaml/test/yaml_test.dart b/_test_yaml/test/yaml_test.dart index cd98b68a1..a869a8559 100644 --- a/_test_yaml/test/yaml_test.dart +++ b/_test_yaml/test/yaml_test.dart @@ -2,6 +2,8 @@ // 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. +// @dart=2.9 + @TestOn('vm') import 'dart:convert'; import 'dart:io'; @@ -31,7 +33,9 @@ void main() { final config = Config.fromJson(yamlContent); expect(config, isNotNull); } on CheckedFromJsonException catch (e) { - print(toParsedYamlException(e).formattedMessage); + if (e.message != null) { + print(toParsedYamlException(e).formattedMessage); + } rethrow; } }); @@ -88,7 +92,7 @@ builders: a: target: 42 ''': r''' -line 3, column 13 of file.yaml: Unsupported value for "target". type 'int' is not a subtype of type 'String' in type cast +line 3, column 13 of file.yaml: Unsupported value for "target". type 'int' is not a subtype of type 'String?' in type cast ╷ 3 │ target: 42 │ ^^ diff --git a/analysis_options.yaml b/analysis_options.yaml index 6338172a6..74a2d9a9a 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1,9 +1,6 @@ analyzer: strong-mode: implicit-casts: false - errors: - # https://github.com/dart-lang/linter/issues/2331 - package_names: ignore linter: rules: diff --git a/example/lib/example.dart b/example/lib/example.dart index 0cd0e650f..c928b5508 100644 --- a/example/lib/example.dart +++ b/example/lib/example.dart @@ -10,21 +10,25 @@ part 'example.g.dart'; class Person { final String firstName; @JsonKey(includeIfNull: false) - final String middleName; + final String? middleName; final String lastName; - @JsonKey(name: 'date-of-birth', nullable: false) + @JsonKey(name: 'date-of-birth') final DateTime dateOfBirth; @JsonKey(name: 'last-order') - final DateTime lastOrder; + final DateTime? lastOrder; - @JsonKey(nullable: false) List orders; - Person(this.firstName, this.lastName, this.dateOfBirth, - {this.middleName, this.lastOrder, List orders}) - : orders = orders ?? []; + Person( + this.firstName, + this.lastName, + this.dateOfBirth, { + this.middleName, + this.lastOrder, + List? orders, + }) : orders = orders ?? []; factory Person.fromJson(Map json) => _$PersonFromJson(json); @@ -33,16 +37,16 @@ class Person { @JsonSerializable(includeIfNull: false) class Order { - int count; - int itemNumber; - bool isRushed; - Item item; + int? count; + int? itemNumber; + bool? isRushed; + Item? item; @JsonKey( name: 'prep-time', fromJson: _durationFromMilliseconds, toJson: _durationToMilliseconds) - Duration prepTime; + Duration? prepTime; @JsonKey(fromJson: _dateTimeFromEpochUs, toJson: _dateTimeToEpochUs) final DateTime date; @@ -53,24 +57,24 @@ class Order { Map toJson() => _$OrderToJson(this); - static Duration _durationFromMilliseconds(int milliseconds) => + static Duration? _durationFromMilliseconds(int? milliseconds) => milliseconds == null ? null : Duration(milliseconds: milliseconds); - static int _durationToMilliseconds(Duration duration) => + static int? _durationToMilliseconds(Duration? duration) => duration?.inMilliseconds; static DateTime _dateTimeFromEpochUs(int us) => - us == null ? null : DateTime.fromMicrosecondsSinceEpoch(us); + DateTime.fromMicrosecondsSinceEpoch(us); - static int _dateTimeToEpochUs(DateTime dateTime) => + static int? _dateTimeToEpochUs(DateTime? dateTime) => dateTime?.microsecondsSinceEpoch; } @JsonSerializable() class Item { - int count; - int itemNumber; - bool isRushed; + int? count; + int? itemNumber; + bool? isRushed; Item(); diff --git a/example/lib/example.g.dart b/example/lib/example.g.dart index 44599902e..29f93504e 100644 --- a/example/lib/example.g.dart +++ b/example/lib/example.g.dart @@ -11,12 +11,12 @@ Person _$PersonFromJson(Map json) { json['firstName'] as String, json['lastName'] as String, DateTime.parse(json['date-of-birth'] as String), - middleName: json['middleName'] as String, + middleName: json['middleName'] as String?, lastOrder: json['last-order'] == null ? null : DateTime.parse(json['last-order'] as String), - orders: (json['orders'] as List) - .map((e) => Order.fromJson(e as Map)) + orders: (json['orders'] as List?) + ?.map((e) => Order.fromJson(e as Map)) .toList(), ); } @@ -44,13 +44,13 @@ Order _$OrderFromJson(Map json) { return Order( Order._dateTimeFromEpochUs(json['date'] as int), ) - ..count = json['count'] as int - ..itemNumber = json['itemNumber'] as int - ..isRushed = json['isRushed'] as bool + ..count = json['count'] as int? + ..itemNumber = json['itemNumber'] as int? + ..isRushed = json['isRushed'] as bool? ..item = json['item'] == null ? null : Item.fromJson(json['item'] as Map) - ..prepTime = Order._durationFromMilliseconds(json['prep-time'] as int); + ..prepTime = Order._durationFromMilliseconds(json['prep-time'] as int?); } Map _$OrderToJson(Order instance) { @@ -73,9 +73,9 @@ Map _$OrderToJson(Order instance) { Item _$ItemFromJson(Map json) { return Item() - ..count = json['count'] as int - ..itemNumber = json['itemNumber'] as int - ..isRushed = json['isRushed'] as bool; + ..count = json['count'] as int? + ..itemNumber = json['itemNumber'] as int? + ..isRushed = json['isRushed'] as bool?; } Map _$ItemToJson(Item instance) => { diff --git a/example/lib/generic_response_class_example.dart b/example/lib/generic_response_class_example.dart index c1754ed93..cde1e60eb 100644 --- a/example/lib/generic_response_class_example.dart +++ b/example/lib/generic_response_class_example.dart @@ -12,11 +12,11 @@ part 'generic_response_class_example.g.dart'; @JsonSerializable(createToJson: false) class BaseResponse { - final int status; - final String msg; + final int? status; + final String? msg; @JsonKey(fromJson: _dataFromJson) - final T data; + final T? data; const BaseResponse({ this.status, @@ -60,15 +60,13 @@ class Article { final int id; final String title; - @JsonKey(nullable: true) - final User author; + final User? author; - @JsonKey(nullable: true) - final List comments; + final List? comments; const Article({ - this.id, - this.title, + required this.id, + required this.title, this.author, this.comments, }); @@ -79,8 +77,8 @@ class Article { @JsonSerializable(createToJson: false) class User { - final int id; - final String email; + final int? id; + final String? email; const User({ this.id, @@ -92,8 +90,8 @@ class User { @JsonSerializable(createToJson: false) class Comment { - final String content; - final int id; + final String? content; + final int? id; const Comment({ this.id, diff --git a/example/lib/generic_response_class_example.g.dart b/example/lib/generic_response_class_example.g.dart index 28b26b6dd..ffd875507 100644 --- a/example/lib/generic_response_class_example.g.dart +++ b/example/lib/generic_response_class_example.g.dart @@ -8,9 +8,9 @@ part of 'generic_response_class_example.dart'; BaseResponse _$BaseResponseFromJson(Map json) { return BaseResponse( - status: json['status'] as int, - msg: json['msg'] as String, - data: BaseResponse._dataFromJson(json['data']), + status: json['status'] as int?, + msg: json['msg'] as String?, + data: BaseResponse._dataFromJson(json['data'] as Object), ); } @@ -21,23 +21,22 @@ Article _$ArticleFromJson(Map json) { author: json['author'] == null ? null : User.fromJson(json['author'] as Map), - comments: (json['comments'] as List) - ?.map((e) => - e == null ? null : Comment.fromJson(e as Map)) - ?.toList(), + comments: (json['comments'] as List?) + ?.map((e) => Comment.fromJson(e as Map)) + .toList(), ); } User _$UserFromJson(Map json) { return User( - id: json['id'] as int, - email: json['email'] as String, + id: json['id'] as int?, + email: json['email'] as String?, ); } Comment _$CommentFromJson(Map json) { return Comment( - id: json['id'] as int, - content: json['content'] as String, + id: json['id'] as int?, + content: json['content'] as String?, ); } diff --git a/example/lib/json_converter_example.dart b/example/lib/json_converter_example.dart index 172c38616..47789bd92 100644 --- a/example/lib/json_converter_example.dart +++ b/example/lib/json_converter_example.dart @@ -8,7 +8,7 @@ part 'json_converter_example.g.dart'; /// An example of using [JsonConverter] to change the encode/decode of a default /// type. -@JsonSerializable(nullable: false) +@JsonSerializable() @_DateTimeEpochConverter() class DateTimeExample { final DateTime when; @@ -34,20 +34,24 @@ class _DateTimeEpochConverter implements JsonConverter { @JsonSerializable() class GenericCollection { @JsonKey(name: 'page') - final int page; + final int? page; @JsonKey(name: 'total_results') - final int totalResults; + final int? totalResults; @JsonKey(name: 'total_pages') - final int totalPages; + final int? totalPages; @JsonKey(name: 'results') @_Converter() - final List results; + final List? results; - GenericCollection( - {this.page, this.totalResults, this.totalPages, this.results}); + GenericCollection({ + this.page, + this.totalResults, + this.totalPages, + this.results, + }); factory GenericCollection.fromJson(Map json) => _$GenericCollectionFromJson(json); @@ -55,11 +59,11 @@ class GenericCollection { Map toJson() => _$GenericCollectionToJson(this); } -class _Converter implements JsonConverter { +class _Converter implements JsonConverter { const _Converter(); @override - T fromJson(Object json) { + T fromJson(Object? json) { if (json is Map && json.containsKey('name') && json.containsKey('size')) { @@ -72,7 +76,7 @@ class _Converter implements JsonConverter { } @override - Object toJson(T object) { + Object? toJson(T object) { // This will only work if `object` is a native JSON type: // num, String, bool, null, etc // Or if it has a `toJson()` function`. diff --git a/example/lib/json_converter_example.g.dart b/example/lib/json_converter_example.g.dart index 334c76807..62b29746a 100644 --- a/example/lib/json_converter_example.g.dart +++ b/example/lib/json_converter_example.g.dart @@ -19,10 +19,12 @@ Map _$DateTimeExampleToJson(DateTimeExample instance) => GenericCollection _$GenericCollectionFromJson(Map json) { return GenericCollection( - page: json['page'] as int, - totalResults: json['total_results'] as int, - totalPages: json['total_pages'] as int, - results: (json['results'] as List)?.map(_Converter().fromJson)?.toList(), + page: json['page'] as int?, + totalResults: json['total_results'] as int?, + totalPages: json['total_pages'] as int?, + results: (json['results'] as List?) + ?.map(_Converter().fromJson) + .toList(), ); } @@ -32,7 +34,7 @@ Map _$GenericCollectionToJson( 'page': instance.page, 'total_results': instance.totalResults, 'total_pages': instance.totalPages, - 'results': instance.results?.map(_Converter().toJson)?.toList(), + 'results': instance.results?.map(_Converter().toJson).toList(), }; CustomResult _$CustomResultFromJson(Map json) { diff --git a/example/lib/tuple_example.dart b/example/lib/tuple_example.dart index 697446e4a..35bcbe6a7 100644 --- a/example/lib/tuple_example.dart +++ b/example/lib/tuple_example.dart @@ -16,8 +16,8 @@ class Tuple { factory Tuple.fromJson( Map json, - T Function(Object json) fromJsonT, - S Function(Object json) fromJsonS, + T Function(Object? json) fromJsonT, + S Function(Object? json) fromJsonS, ) => _$TupleFromJson(json, fromJsonT, fromJsonS); @@ -28,7 +28,7 @@ class Tuple { _$TupleToJson(this, toJsonT, toJsonS); } -@JsonSerializable(nullable: false) +@JsonSerializable() class ConcreteClass { final Tuple tuple1; diff --git a/example/lib/tuple_example.g.dart b/example/lib/tuple_example.g.dart index e27d82219..3032bdfcf 100644 --- a/example/lib/tuple_example.g.dart +++ b/example/lib/tuple_example.g.dart @@ -8,8 +8,8 @@ part of 'tuple_example.dart'; Tuple _$TupleFromJson( Map json, - T Function(Object json) fromJsonT, - S Function(Object json) fromJsonS, + T Function(Object? json) fromJsonT, + S Function(Object? json) fromJsonS, ) { return Tuple( fromJsonT(json['value1']), diff --git a/example/mono_pkg.yaml b/example/mono_pkg.yaml index 23b5859b6..80aa3fbcb 100644 --- a/example/mono_pkg.yaml +++ b/example/mono_pkg.yaml @@ -1,17 +1,12 @@ # See https://github.com/google/mono_repo.dart for details on this file dart: -- 2.7.0 - dev stages: - analyzer_and_format: - group: - dartfmt - - dartanalyzer: --fatal-warnings --fatal-infos . - dart: [dev] - - group: - dartanalyzer: --fatal-warnings . - dart: [2.7.0] - unit_test: - test - ensure_build: diff --git a/example/pubspec.yaml b/example/pubspec.yaml index fe8692d14..0c90886ed 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -1,7 +1,7 @@ name: example environment: - sdk: '>=2.7.0 <3.0.0' + sdk: '>=2.12.0-0 <3.0.0' dependencies: json_annotation: ^3.0.0 @@ -15,9 +15,9 @@ dev_dependencies: json_serializable: ^3.2.0 # Used by tests. Not required to use `json_serializable`. - path: ^1.5.1 + path: ^1.8.0-nullsafety.3 # Used by tests. Not required to use `json_serializable`. - test: ^1.6.0 + test: ^1.16.0-nullsafety.9 dependency_overrides: json_annotation: diff --git a/example/test/ensure_build_test.dart b/example/test/ensure_build_test.dart index a927b47a9..9a62c4a83 100644 --- a/example/test/ensure_build_test.dart +++ b/example/test/ensure_build_test.dart @@ -2,6 +2,8 @@ // 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. +// @dart=2.9 + @Tags(['presubmit-only']) import 'package:build_verify/build_verify.dart'; import 'package:test/test.dart'; diff --git a/example/test/example_test.dart b/example/test/example_test.dart index 28a71c7a4..55020c06b 100644 --- a/example/test/example_test.dart +++ b/example/test/example_test.dart @@ -21,7 +21,7 @@ void main() { expect(person.lastName, person2.lastName); expect(person.dateOfBirth, person2.dateOfBirth); expect(person.orders.single.date, person2.orders.single.date); - expect(person.orders.single.item.count, 42); + expect(person.orders.single.item!.count, 42); expect(_encode(person2), equals(personJson)); }); diff --git a/example/test/generic_response_class_test.dart b/example/test/generic_response_class_test.dart index 3ac596d8e..8faaf39ec 100644 --- a/example/test/generic_response_class_test.dart +++ b/example/test/generic_response_class_test.dart @@ -48,7 +48,7 @@ void _testUser(User user) { void _testArticle(Article article) { expect(article.id, 2); expect(article.title, 'title1'); - _testUser(article.author); + _testUser(article.author!); expect(article.comments, hasLength(2)); } diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index be64d02a6..f395247d4 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -1,3 +1,10 @@ +## 4.0.0-nullsafety.0 + +- Updated `$checkedConvert` helper to support null-safety. +- Removed the `nullable` field on `JsonKey` – 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 `null` values for `CheckedFromJsonException.message` by using diff --git a/json_annotation/lib/src/allowed_keys_helpers.dart b/json_annotation/lib/src/allowed_keys_helpers.dart index b3b9490f6..42d3e4ca9 100644 --- a/json_annotation/lib/src/allowed_keys_helpers.dart +++ b/json_annotation/lib/src/allowed_keys_helpers.dart @@ -7,11 +7,13 @@ /// `JsonKey.required` is `true` for any annotated fields. /// /// Should not be used directly. -void $checkKeys(Map map, - {List allowedKeys, - List requiredKeys, - List disallowNullValues}) { - if (map != null && allowedKeys != null) { +void $checkKeys( + Map map, { + List? allowedKeys, + List? requiredKeys, + List? disallowNullValues, +}) { + if (allowedKeys != null) { final invalidKeys = map.keys.cast().where((k) => !allowedKeys.contains(k)).toList(); if (invalidKeys.isNotEmpty) { @@ -27,10 +29,12 @@ void $checkKeys(Map map, } } - if (map != null && disallowNullValues != null) { + if (disallowNullValues != null) { final nullValuedKeys = map.entries - .where((entry) => - disallowNullValues.contains(entry.key) && entry.value == null) + .where( + (entry) => + disallowNullValues.contains(entry.key) && entry.value == null, + ) .map((entry) => entry.key as String) .toList(); diff --git a/json_annotation/lib/src/checked_helpers.dart b/json_annotation/lib/src/checked_helpers.dart index f3311a3e9..c844c80d7 100644 --- a/json_annotation/lib/src/checked_helpers.dart +++ b/json_annotation/lib/src/checked_helpers.dart @@ -8,8 +8,12 @@ import 'allowed_keys_helpers.dart'; /// `JsonSerializableGenerator.checked` is `true`. /// /// Should not be used directly. -T $checkedNew(String className, Map map, T Function() constructor, - {Map fieldKeyMap}) { +T $checkedNew( + String className, + Map map, + T Function() constructor, { + Map? fieldKeyMap, +}) { fieldKeyMap ??= const {}; try { @@ -20,7 +24,7 @@ T $checkedNew(String className, Map map, T Function() constructor, } rethrow; } catch (error, stack) { - String key; + String? key; if (error is ArgumentError) { key = fieldKeyMap[error.name] ?? error.name; } else if (error is MissingRequiredKeysException) { @@ -28,8 +32,13 @@ T $checkedNew(String className, Map map, T Function() constructor, } else if (error is DisallowedNullValueException) { key = error.keysWithNullValues.first; } - throw CheckedFromJsonException._(error, stack, map, key, - className: className); + throw CheckedFromJsonException._( + error, + stack, + map, + key, + className: className, + ); } } @@ -37,7 +46,7 @@ T $checkedNew(String className, Map map, T Function() constructor, /// `JsonSerializableGenerator.checked` is `true`. /// /// Should not be used directly. -T $checkedConvert(Map map, String key, T Function(Object) castFunc) { +T $checkedConvert(Map map, String key, T Function(dynamic) castFunc) { try { return castFunc(map[key]); } on CheckedFromJsonException { @@ -53,18 +62,18 @@ class CheckedFromJsonException implements Exception { /// The [Error] or [Exception] that triggered this exception. /// /// If this instance was created by user code, this field will be `null`. - final Object innerError; + final Object? innerError; /// The [StackTrace] for the [Error] or [Exception] that triggered this /// exception. /// /// If this instance was created by user code, this field will be `null`. - final StackTrace innerStack; + final StackTrace? innerStack; /// The key from [map] that corresponds to the thrown [innerError]. /// /// May be `null`. - final String key; + final String? key; /// The source [Map] that was used for decoding when the [innerError] was /// thrown. @@ -73,11 +82,11 @@ class CheckedFromJsonException implements Exception { /// A human-readable message corresponding to [innerError]. /// /// May be `null`. - final String message; + final String? message; /// The name of the class being created when [innerError] was thrown. - String get className => _className; - String _className; + String? get className => _className; + String? _className; /// If this was thrown due to an invalid or unsupported key, as opposed to an /// invalid value. @@ -89,9 +98,8 @@ class CheckedFromJsonException implements Exception { this.key, String className, this.message, { - bool badKey = false, + this.badKey = false, }) : _className = className, - badKey = badKey ?? false, innerError = null, innerStack = null; @@ -100,17 +108,19 @@ class CheckedFromJsonException implements Exception { this.innerStack, this.map, this.key, { - String className, + String? className, }) : _className = className, badKey = innerError is BadKeyException, message = _getMessage(innerError); - static String _getMessage(Object error) { + static String? _getMessage(Object? error) { if (error is ArgumentError) { return error.message?.toString(); - } else if (error is BadKeyException) { + } + if (error is BadKeyException) { return error.message; - } else if (error is FormatException) { + } + if (error is FormatException) { var message = error.message; if (error.offset != null) { message = '$message at offset ${error.offset}.'; @@ -125,7 +135,9 @@ class CheckedFromJsonException implements Exception { 'CheckedFromJsonException', if (_className != null) 'Could not create `$_className`.', if (key != null) 'There is a problem with "$key".', - if (message != null) message, - if (message == null && innerError != null) innerError.toString(), + if (message != null) + message! + else if (innerError != null) + innerError.toString(), ].join('\n'); } diff --git a/json_annotation/lib/src/json_key.dart b/json_annotation/lib/src/json_key.dart index 718a87187..ddf68330f 100644 --- a/json_annotation/lib/src/json_key.dart +++ b/json_annotation/lib/src/json_key.dart @@ -9,7 +9,7 @@ import 'json_serializable.dart'; class JsonKey { /// The value to use if the source JSON does not contain this key or if the /// value is `null`. - final Object defaultValue; + final Object? defaultValue; /// If `true`, generated code will throw a [DisallowedNullValueException] if /// the corresponding key exists, but the value is `null`. @@ -22,7 +22,7 @@ class JsonKey { /// /// If both [includeIfNull] and [disallowNullValue] are set to `true` on the /// same field, an exception will be thrown during code generation. - final bool disallowNullValue; + final bool? disallowNullValue; /// A [Function] to use when decoding the associated JSON value to the /// annotated field. @@ -33,13 +33,13 @@ class JsonKey { /// When creating a class that supports both `toJson` and `fromJson` /// (the default), you should also set [toJson] if you set [fromJson]. /// Values returned by [toJson] should "round-trip" through [fromJson]. - final Function fromJson; + final Function? fromJson; /// `true` if the generator should ignore this field completely. /// /// If `null` (the default) or `false`, the field will be considered for /// serialization. - final bool ignore; + final bool? ignore; /// Whether the generator should include fields with `null` values in the /// serialized output. @@ -56,26 +56,13 @@ class JsonKey { /// /// If both [includeIfNull] and [disallowNullValue] are set to `true` on the /// same field, an exception will be thrown during code generation. - final bool includeIfNull; + final bool? includeIfNull; /// 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; - - /// When `true`, `null` fields are handled gracefully when encoding to JSON - /// and when decoding `null` and nonexistent values from JSON. - /// - /// Setting to `false` eliminates `null` verification in the generated code - /// for the annotated field, which reduces the code size. Errors may be thrown - /// at runtime if `null` values are encountered, but the original class should - /// also implement `null` runtime validation if it's critical. - /// - /// The default value, `null`, indicates that the behavior should be - /// acquired from the [JsonSerializable.nullable] annotation on the - /// enclosing class. - final bool nullable; + final String? name; /// When `true`, generated code for `fromJson` will verify that the source /// JSON map contains the associated key. @@ -85,7 +72,7 @@ class JsonKey { /// /// Note: only the existence of the key is checked. A key with a `null` value /// is considered valid. - final bool required; + final bool? required; /// A [Function] to use when encoding the annotated field to JSON. /// @@ -95,25 +82,25 @@ class JsonKey { /// When creating a class that supports both `toJson` and `fromJson` /// (the default), you should also set [fromJson] if you set [toJson]. /// Values returned by [toJson] should "round-trip" through [fromJson]. - final Function toJson; + final Function? toJson; /// The value to use for an enum field when the value provided is not in the /// source enum. /// /// Valid only on enum fields with a compatible enum value. - final Object unknownEnumValue; + final Object? unknownEnumValue; /// Creates a new [JsonKey] instance. /// /// Only required when the default behavior is not desired. const JsonKey({ + @Deprecated('Has no effect') bool? nullable, this.defaultValue, this.disallowNullValue, this.fromJson, this.ignore, this.includeIfNull, this.name, - this.nullable, this.required, this.toJson, this.unknownEnumValue, diff --git a/json_annotation/lib/src/json_literal.dart b/json_annotation/lib/src/json_literal.dart index 06551d62a..9840e24ae 100644 --- a/json_annotation/lib/src/json_literal.dart +++ b/json_annotation/lib/src/json_literal.dart @@ -24,6 +24,5 @@ class JsonLiteral { final bool asConst; /// Creates a new [JsonLiteral] instance. - const JsonLiteral(this.path, {bool asConst = false}) - : asConst = asConst ?? false; + const JsonLiteral(this.path, {this.asConst = false}); } diff --git a/json_annotation/lib/src/json_serializable.dart b/json_annotation/lib/src/json_serializable.dart index d5ab9d5e7..019198a78 100644 --- a/json_annotation/lib/src/json_serializable.dart +++ b/json_annotation/lib/src/json_serializable.dart @@ -38,14 +38,14 @@ class JsonSerializable { /// from other sources, such as `package:yaml`. /// /// *Note: in many cases the key values are still assumed to be [String]*. - final bool anyMap; + final bool? anyMap; /// If `true`, generated `fromJson` functions include extra checks to validate /// proper deserialization of types. /// /// If an exception is thrown during deserialization, a /// [CheckedFromJsonException] is thrown. - final bool checked; + final bool? checked; /// If `true` (the default), a private, static `_$ExampleFromJson` method /// is created in the generated part file. @@ -60,7 +60,7 @@ class JsonSerializable { /// _$ExampleFromJson(json); /// } /// ``` - final bool createFactory; + final bool? createFactory; /// If `true` (the default), A top-level function is created that you can /// reference from your class. @@ -71,14 +71,14 @@ class JsonSerializable { /// Map toJson() => _$ExampleToJson(this); /// } /// ``` - final bool createToJson; + final bool? createToJson; /// If `false` (the default), then the generated `FromJson` function will /// ignore unrecognized keys in the provided JSON [Map]. /// /// If `true`, unrecognized keys will cause an [UnrecognizedKeysException] to /// be thrown. - final bool disallowUnrecognizedKeys; + final bool? disallowUnrecognizedKeys; /// If `true`, generated `toJson` methods will explicitly call `toJson` on /// nested objects. @@ -98,7 +98,7 @@ class JsonSerializable { /// ```dart /// Map toJson() => {'child': child?.toJson()}; /// ``` - final bool explicitToJson; + final bool? explicitToJson; /// Defines the automatic naming strategy when converting class field names /// into JSON map keys. @@ -110,7 +110,7 @@ class JsonSerializable { /// /// Note: the value for [JsonKey.name] takes precedence over this option for /// fields annotated with [JsonKey]. - final FieldRename fieldRename; + final FieldRename? fieldRename; /// When `true` on classes with type parameters (generic types), extra /// "helper" parameters will be generated for `fromJson` and/or `toJson` to @@ -155,14 +155,14 @@ class JsonSerializable { /// 1. If this option is set for all classes in a package via `build.yaml` /// it is only applied to classes with type parameters – so no warning is /// echoed. - final bool genericArgumentFactories; + final bool? genericArgumentFactories; /// When `true`, only fields annotated with [JsonKey] will have code /// generated. /// /// It will have the same effect as if those fields had been annotated with /// `@JsonKey(ignore: true)`. - final bool ignoreUnannotated; + final bool? ignoreUnannotated; /// Whether the generator should include fields with `null` values in the /// serialized output. @@ -172,20 +172,11 @@ class JsonSerializable { /// /// If a field is annotated with `JsonKey` with a non-`null` value for /// `includeIfNull`, that value takes precedent. - final bool includeIfNull; - - /// When `true` (the default), `null` fields are handled gracefully when - /// encoding to JSON and when decoding `null` and nonexistent values from - /// JSON. - /// - /// Setting to `false` eliminates `null` verification in the generated code, - /// which reduces the code size. Errors may be thrown at runtime if `null` - /// values are encountered, but the original class should also implement - /// `null` runtime validation if it's critical. - final bool nullable; + final bool? includeIfNull; /// Creates a new [JsonSerializable] instance. const JsonSerializable({ + @Deprecated('Has no effect') bool? nullable, this.anyMap, this.checked, this.createFactory, @@ -195,7 +186,6 @@ class JsonSerializable { this.fieldRename, this.ignoreUnannotated, this.includeIfNull, - this.nullable, this.genericArgumentFactories, }); @@ -214,7 +204,6 @@ class JsonSerializable { fieldRename: FieldRename.none, ignoreUnannotated: false, includeIfNull: true, - nullable: true, genericArgumentFactories: false, ); @@ -234,7 +223,6 @@ class JsonSerializable { fieldRename: fieldRename ?? defaults.fieldRename, ignoreUnannotated: ignoreUnannotated ?? defaults.ignoreUnannotated, includeIfNull: includeIfNull ?? defaults.includeIfNull, - nullable: nullable ?? defaults.nullable, genericArgumentFactories: genericArgumentFactories ?? defaults.genericArgumentFactories, ); diff --git a/json_annotation/lib/src/json_serializable.g.dart b/json_annotation/lib/src/json_serializable.g.dart index 1cf54e387..4aa268cb6 100644 --- a/json_annotation/lib/src/json_serializable.g.dart +++ b/json_annotation/lib/src/json_serializable.g.dart @@ -19,7 +19,6 @@ JsonSerializable _$JsonSerializableFromJson(Map json) { 'generic_argument_factories', 'ignore_unannotated', 'include_if_null', - 'nullable' ]); final val = JsonSerializable( anyMap: $checkedConvert(json, 'any_map', (v) => v as bool), @@ -35,7 +34,6 @@ JsonSerializable _$JsonSerializableFromJson(Map json) { ignoreUnannotated: $checkedConvert(json, 'ignore_unannotated', (v) => v as bool), includeIfNull: $checkedConvert(json, 'include_if_null', (v) => v as bool), - nullable: $checkedConvert(json, 'nullable', (v) => v as bool), genericArgumentFactories: $checkedConvert(json, 'generic_argument_factories', (v) => v as bool), ); @@ -65,13 +63,12 @@ Map _$JsonSerializableToJson(JsonSerializable instance) => 'generic_argument_factories': instance.genericArgumentFactories, 'ignore_unannotated': instance.ignoreUnannotated, 'include_if_null': instance.includeIfNull, - 'nullable': instance.nullable, }; T _$enumDecode( Map enumValues, dynamic source, { - T unknownValue, + T? unknownValue, }) { if (source == null) { throw ArgumentError('A value must be provided. Supported values: ' @@ -79,20 +76,21 @@ T _$enumDecode( } final value = enumValues.entries - .singleWhere((e) => e.value == source, orElse: () => null) + .cast?>() + .singleWhere((e) => e!.value == source, orElse: () => null) ?.key; if (value == null && unknownValue == null) { throw ArgumentError('`$source` is not one of the supported values: ' '${enumValues.values.join(', ')}'); } - return value ?? unknownValue; + return value ?? unknownValue!; } -T _$enumDecodeNullable( +T? _$enumDecodeNullable( Map enumValues, dynamic source, { - T unknownValue, + T? unknownValue, }) { if (source == null) { return null; diff --git a/json_annotation/mono_pkg.yaml b/json_annotation/mono_pkg.yaml index 1da53eb18..e18bc35a7 100644 --- a/json_annotation/mono_pkg.yaml +++ b/json_annotation/mono_pkg.yaml @@ -5,6 +5,3 @@ stages: - dartfmt - dartanalyzer: --fatal-warnings --fatal-infos . dart: [dev] - - group: - - dartanalyzer: --fatal-warnings . - dart: [2.7.0] diff --git a/json_annotation/pubspec.yaml b/json_annotation/pubspec.yaml index 6be7a1e1f..8e8dc63a4 100644 --- a/json_annotation/pubspec.yaml +++ b/json_annotation/pubspec.yaml @@ -1,11 +1,11 @@ name: json_annotation -version: 3.1.1 +version: 4.0.0-nullsafety.0 description: >- Classes and helper functions that support JSON code generation via the `json_serializable` package. -homepage: https://github.com/google/json_serializable.dart +repository: https://github.com/google/json_serializable.dart environment: - sdk: '>=2.7.0 <3.0.0' + sdk: '>=2.12.0-0 <3.0.0' # When changing JsonSerializable class. # dev_dependencies: diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index e78e7f946..97060f7b4 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,8 +1,13 @@ -## 3.5.1-dev +## 4.0.0-nullsafety.1 +- Generates null-safe code. + - The `nullable` field on `JsonKey` ignored. The nullability of a field is now + determined by the Dart type system. - Improved error messages for unsupported types. - `package:json_serializable/type_helper.dart` - Made the third parameter to `UnsupportedTypeError` positional (optional). +- **BREAKING** `bool defaultProvided` arg added to `TypeHelper.deserialize`. + *Only applies to folks using `TypeHelper` directly.* ## 3.5.0 diff --git a/json_serializable/README.md b/json_serializable/README.md index ef399eb9a..d6063dc28 100644 --- a/json_serializable/README.md +++ b/json_serializable/README.md @@ -30,12 +30,12 @@ import 'package:json_annotation/json_annotation.dart'; part 'example.g.dart'; -@JsonSerializable(nullable: false) +@JsonSerializable() class Person { final String firstName; final String lastName; - final DateTime dateOfBirth; - Person({this.firstName, this.lastName, this.dateOfBirth}); + final DateTime? dateOfBirth; + Person({required this.firstName, required this.lastName, this.dateOfBirth}); factory Person.fromJson(Map json) => _$PersonFromJson(json); Map toJson() => _$PersonToJson(this); } @@ -50,14 +50,16 @@ Person _$PersonFromJson(Map json) { return Person( firstName: json['firstName'] as String, lastName: json['lastName'] as String, - dateOfBirth: DateTime.parse(json['dateOfBirth'] as String), + dateOfBirth: json['dateOfBirth'] == null + ? null + : DateTime.parse(json['dateOfBirth'] as String), ); } Map _$PersonToJson(Person instance) => { 'firstName': instance.firstName, 'lastName': instance.lastName, - 'dateOfBirth': instance.dateOfBirth.toIso8601String(), + 'dateOfBirth': instance.dateOfBirth?.toIso8601String(), }; ``` @@ -84,7 +86,6 @@ is generated: | generic_argument_factories | [JsonSerializable.genericArgumentFactories] | | | ignore_unannotated | [JsonSerializable.ignoreUnannotated] | | | include_if_null | [JsonSerializable.includeIfNull] | [JsonKey.includeIfNull] | -| nullable | [JsonSerializable.nullable] | [JsonKey.nullable] | | | | [JsonKey.defaultValue] | | | | [JsonKey.disallowNullValue] | | | | [JsonKey.fromJson] | @@ -94,27 +95,25 @@ is generated: | | | [JsonKey.toJson] | | | | [JsonKey.unknownEnumValue] | -[JsonSerializable.anyMap]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonSerializable/anyMap.html -[JsonSerializable.checked]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonSerializable/checked.html -[JsonSerializable.createFactory]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonSerializable/createFactory.html -[JsonSerializable.createToJson]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonSerializable/createToJson.html -[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html -[JsonSerializable.explicitToJson]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonSerializable/explicitToJson.html -[JsonSerializable.fieldRename]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonSerializable/fieldRename.html -[JsonSerializable.genericArgumentFactories]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonSerializable/genericArgumentFactories.html -[JsonSerializable.ignoreUnannotated]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonSerializable/ignoreUnannotated.html -[JsonSerializable.includeIfNull]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonSerializable/includeIfNull.html -[JsonKey.includeIfNull]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonKey/includeIfNull.html -[JsonSerializable.nullable]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonSerializable/nullable.html -[JsonKey.nullable]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonKey/nullable.html -[JsonKey.defaultValue]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonKey/defaultValue.html -[JsonKey.disallowNullValue]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonKey/disallowNullValue.html -[JsonKey.fromJson]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonKey/fromJson.html -[JsonKey.ignore]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonKey/ignore.html -[JsonKey.name]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonKey/name.html -[JsonKey.required]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonKey/required.html -[JsonKey.toJson]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonKey/toJson.html -[JsonKey.unknownEnumValue]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonKey/unknownEnumValue.html +[JsonSerializable.anyMap]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/anyMap.html +[JsonSerializable.checked]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/checked.html +[JsonSerializable.createFactory]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/createFactory.html +[JsonSerializable.createToJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/createToJson.html +[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html +[JsonSerializable.explicitToJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/explicitToJson.html +[JsonSerializable.fieldRename]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/fieldRename.html +[JsonSerializable.genericArgumentFactories]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/genericArgumentFactories.html +[JsonSerializable.ignoreUnannotated]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/ignoreUnannotated.html +[JsonSerializable.includeIfNull]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/includeIfNull.html +[JsonKey.includeIfNull]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/includeIfNull.html +[JsonKey.defaultValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/defaultValue.html +[JsonKey.disallowNullValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/disallowNullValue.html +[JsonKey.fromJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/fromJson.html +[JsonKey.ignore]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/ignore.html +[JsonKey.name]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/name.html +[JsonKey.required]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/required.html +[JsonKey.toJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/toJson.html +[JsonKey.unknownEnumValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/unknownEnumValue.html > Note: every `JsonSerializable` field is configurable via `build.yaml` – see the table for the corresponding key. @@ -152,7 +151,6 @@ targets: generic_argument_factories: false ignore_unannotated: false include_if_null: true - nullable: true ``` [example]: https://github.com/google/json_serializable.dart/tree/master/example diff --git a/json_serializable/build.yaml b/json_serializable/build.yaml index ac2d9172d..e1c82f75f 100644 --- a/json_serializable/build.yaml +++ b/json_serializable/build.yaml @@ -12,17 +12,12 @@ targets: - test/literal/* - test/supported_types/* - build_web_compilers|entrypoint: - generate_for: - - test/**/**.browser_test.dart - json_serializable|_test_builder: generate_for: - test/default_value/default_value.dart - test/generic_files/generic_class.dart - test/integration/json_test_example.dart - test/integration/json_test_example.dart - - test/integration/json_test_example.non_nullable.dart - test/kitchen_sink/kitchen_sink.dart json_serializable|_type_builder: @@ -42,12 +37,8 @@ builders: - .factories.dart - .g_any_map.dart - .g_any_map__checked.dart - - .g_any_map__checked__non_nullable.dart - - .g_any_map__non_nullable.dart - .g_exclude_null.dart - - .g_exclude_null__non_nullable.dart - .g_explicit_to_json.dart - - .g_non_nullable.dart build_to: source runs_before: ["json_serializable"] diff --git a/json_serializable/doc/doc.md b/json_serializable/doc/doc.md index 76c6c2d7d..386068764 100644 --- a/json_serializable/doc/doc.md +++ b/json_serializable/doc/doc.md @@ -10,7 +10,6 @@ | generic_argument_factories | [JsonSerializable.genericArgumentFactories] | | | ignore_unannotated | [JsonSerializable.ignoreUnannotated] | | | include_if_null | [JsonSerializable.includeIfNull] | [JsonKey.includeIfNull] | -| nullable | [JsonSerializable.nullable] | [JsonKey.nullable] | | | | [JsonKey.defaultValue] | | | | [JsonKey.disallowNullValue] | | | | [JsonKey.fromJson] | @@ -20,24 +19,22 @@ | | | [JsonKey.toJson] | | | | [JsonKey.unknownEnumValue] | -[JsonSerializable.anyMap]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonSerializable/anyMap.html -[JsonSerializable.checked]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonSerializable/checked.html -[JsonSerializable.createFactory]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonSerializable/createFactory.html -[JsonSerializable.createToJson]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonSerializable/createToJson.html -[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html -[JsonSerializable.explicitToJson]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonSerializable/explicitToJson.html -[JsonSerializable.fieldRename]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonSerializable/fieldRename.html -[JsonSerializable.genericArgumentFactories]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonSerializable/genericArgumentFactories.html -[JsonSerializable.ignoreUnannotated]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonSerializable/ignoreUnannotated.html -[JsonSerializable.includeIfNull]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonSerializable/includeIfNull.html -[JsonKey.includeIfNull]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonKey/includeIfNull.html -[JsonSerializable.nullable]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonSerializable/nullable.html -[JsonKey.nullable]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonKey/nullable.html -[JsonKey.defaultValue]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonKey/defaultValue.html -[JsonKey.disallowNullValue]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonKey/disallowNullValue.html -[JsonKey.fromJson]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonKey/fromJson.html -[JsonKey.ignore]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonKey/ignore.html -[JsonKey.name]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonKey/name.html -[JsonKey.required]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonKey/required.html -[JsonKey.toJson]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonKey/toJson.html -[JsonKey.unknownEnumValue]: https://pub.dev/documentation/json_annotation/3.1.0/json_annotation/JsonKey/unknownEnumValue.html +[JsonSerializable.anyMap]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/anyMap.html +[JsonSerializable.checked]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/checked.html +[JsonSerializable.createFactory]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/createFactory.html +[JsonSerializable.createToJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/createToJson.html +[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html +[JsonSerializable.explicitToJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/explicitToJson.html +[JsonSerializable.fieldRename]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/fieldRename.html +[JsonSerializable.genericArgumentFactories]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/genericArgumentFactories.html +[JsonSerializable.ignoreUnannotated]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/ignoreUnannotated.html +[JsonSerializable.includeIfNull]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/includeIfNull.html +[JsonKey.includeIfNull]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/includeIfNull.html +[JsonKey.defaultValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/defaultValue.html +[JsonKey.disallowNullValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/disallowNullValue.html +[JsonKey.fromJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/fromJson.html +[JsonKey.ignore]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/ignore.html +[JsonKey.name]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/name.html +[JsonKey.required]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/required.html +[JsonKey.toJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/toJson.html +[JsonKey.unknownEnumValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/unknownEnumValue.html diff --git a/json_serializable/example/example.dart b/json_serializable/example/example.dart index b62fd38f1..025ae5459 100644 --- a/json_serializable/example/example.dart +++ b/json_serializable/example/example.dart @@ -2,16 +2,18 @@ // 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. +// @dart=2.12 + import 'package:json_annotation/json_annotation.dart'; part 'example.g.dart'; -@JsonSerializable(nullable: false) +@JsonSerializable() class Person { final String firstName; final String lastName; - final DateTime dateOfBirth; - Person({this.firstName, this.lastName, this.dateOfBirth}); + final DateTime? dateOfBirth; + Person({required this.firstName, required this.lastName, this.dateOfBirth}); factory Person.fromJson(Map json) => _$PersonFromJson(json); Map toJson() => _$PersonToJson(this); } diff --git a/json_serializable/example/example.g.dart b/json_serializable/example/example.g.dart index 4d790cf8c..b5d4ad39e 100644 --- a/json_serializable/example/example.g.dart +++ b/json_serializable/example/example.g.dart @@ -1,4 +1,5 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// @dart=2.12 part of 'example.dart'; @@ -10,12 +11,14 @@ Person _$PersonFromJson(Map json) { return Person( firstName: json['firstName'] as String, lastName: json['lastName'] as String, - dateOfBirth: DateTime.parse(json['dateOfBirth'] as String), + dateOfBirth: json['dateOfBirth'] == null + ? null + : DateTime.parse(json['dateOfBirth'] as String), ); } Map _$PersonToJson(Person instance) => { 'firstName': instance.firstName, 'lastName': instance.lastName, - 'dateOfBirth': instance.dateOfBirth.toIso8601String(), + 'dateOfBirth': instance.dateOfBirth?.toIso8601String(), }; diff --git a/json_serializable/lib/src/constants.dart b/json_serializable/lib/src/constants.dart index 2a4b34de3..697cc69ef 100644 --- a/json_serializable/lib/src/constants.dart +++ b/json_serializable/lib/src/constants.dart @@ -2,8 +2,17 @@ // 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. +// @dart=2.12 + /// Name used for closure argument when generating calls to `map`. const closureArg = 'e'; const generatedLocalVarName = 'val'; const toJsonMapHelperName = 'writeNotNull'; + +const converterOrKeyInstructions = r''' +* Use `JsonConverter` + https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonConverter-class.html +* Use `JsonKey` fields `fromJson` and `toJson` + https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/fromJson.html + https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/toJson.html'''; diff --git a/json_serializable/lib/src/decode_helper.dart b/json_serializable/lib/src/decode_helper.dart index 1d18e69a5..12002a865 100644 --- a/json_serializable/lib/src/decode_helper.dart +++ b/json_serializable/lib/src/decode_helper.dart @@ -39,7 +39,7 @@ abstract class DecodeHelper implements HelperCore { arg.instantiate(nullabilitySuffix: NullabilitySuffix.none), ); - buffer.write(', ${arg.name} Function(Object json) $helperName'); + buffer.write(', ${arg.name} Function(Object? json) $helperName'); } if (element.typeParameters.isNotEmpty) { buffer.write(','); @@ -170,11 +170,18 @@ abstract class DecodeHelper implements HelperCore { final jsonKeyName = safeNameAccess(field); final targetType = ctorParam?.type ?? field.type; final contextHelper = getHelperContext(field); + final defaultProvided = jsonKeyFor(field).defaultValue != null; String value; try { if (config.checked) { - value = contextHelper.deserialize(targetType, 'v').toString(); + value = contextHelper + .deserialize( + targetType, + 'v', + defaultProvided: defaultProvided, + ) + .toString(); if (!checkedProperty) { value = '\$checkedConvert(json, $jsonKeyName, (v) => $value)'; } @@ -183,7 +190,11 @@ abstract class DecodeHelper implements HelperCore { 'should only be true if `_generator.checked` is true.'); value = contextHelper - .deserialize(targetType, 'json[$jsonKeyName]') + .deserialize( + targetType, + 'json[$jsonKeyName]', + defaultProvided: defaultProvided, + ) .toString(); } } on UnsupportedTypeError catch (e) // ignore: avoid_catching_errors @@ -194,10 +205,6 @@ abstract class DecodeHelper implements HelperCore { final jsonKey = jsonKeyFor(field); final defaultValue = jsonKey.defaultValue; if (defaultValue != null) { - if (!contextHelper.nullable) { - throwUnsupported(field, - 'Cannot use `defaultValue` on a field with `nullable` false.'); - } if (jsonKey.disallowNullValue && jsonKey.required) { log.warning('The `defaultValue` on field `${field.name}` will have no ' 'effect because both `disallowNullValue` and `required` are set to ' diff --git a/json_serializable/lib/src/encoder_helper.dart b/json_serializable/lib/src/encoder_helper.dart index 806737481..f270c2da6 100644 --- a/json_serializable/lib/src/encoder_helper.dart +++ b/json_serializable/lib/src/encoder_helper.dart @@ -11,6 +11,7 @@ import 'helper_core.dart'; import 'type_helpers/generic_factory_helper.dart'; import 'type_helpers/json_converter_helper.dart'; import 'unsupported_type_error.dart'; +import 'utils.dart'; abstract class EncodeHelper implements HelperCore { String _fieldAccess(FieldElement field) => '$_toJsonParamName.${field.name}'; @@ -138,8 +139,9 @@ abstract class EncodeHelper implements HelperCore { /// we can avoid checking for `null`. bool _writeJsonValueNaive(FieldElement field) { final jsonKey = jsonKeyFor(field); + return jsonKey.includeIfNull || - (!jsonKey.nullable && !_fieldHasCustomEncoder(field)); + (!field.type.isNullableType && !_fieldHasCustomEncoder(field)); } /// Returns `true` if [field] has a user-defined encoder. diff --git a/json_serializable/lib/src/helper_core.dart b/json_serializable/lib/src/helper_core.dart index ebd56fc0b..4e389f58e 100644 --- a/json_serializable/lib/src/helper_core.dart +++ b/json_serializable/lib/src/helper_core.dart @@ -8,6 +8,7 @@ import 'package:json_annotation/json_annotation.dart'; import 'package:meta/meta.dart'; import 'package:source_gen/source_gen.dart'; +import 'constants.dart'; import 'json_key_utils.dart'; import 'type_helper.dart'; import 'type_helper_ctx.dart'; @@ -51,7 +52,7 @@ abstract class HelperCore { @protected TypeHelperCtx getHelperContext(FieldElement field) => - typeHelperContext(this, field, jsonKeyFor(field)); + typeHelperContext(this, field); } InvalidGenerationSourceError createInvalidGenerationError( @@ -89,14 +90,6 @@ $converterOrKeyInstructions'''; ); } -@visibleForTesting -const converterOrKeyInstructions = r''' -* Use `JsonConverter` - https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonConverter-class.html -* Use `JsonKey` fields `fromJson` and `toJson` - https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/fromJson.html - https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/toJson.html'''; - /// Returns a [String] representing the type arguments that exist on /// [element]. /// @@ -140,13 +133,17 @@ String genericClassArguments(ClassElement element, bool withConstraints) { /// types and locations of these files in code. Specifically, it supports /// only [InterfaceType]s, with optional type arguments that are also should /// be [InterfaceType]s. -String typeToCode(DartType type) { +String typeToCode( + DartType type, { + bool forceNullable = false, +}) { if (type.isDynamic) { return 'dynamic'; } else if (type is InterfaceType) { final typeArguments = type.typeArguments; if (typeArguments.isEmpty) { - return type.element.name; + final nullablePostfix = (type.isNullableType || forceNullable) ? '?' : ''; + return '${type.element.name}$nullablePostfix'; } else { final typeArgumentsCode = typeArguments.map(typeToCode).join(', '); return '${type.element.name}<$typeArgumentsCode>'; diff --git a/json_serializable/lib/src/json_key_utils.dart b/json_serializable/lib/src/json_key_utils.dart index cd6a42f0c..890479de4 100644 --- a/json_serializable/lib/src/json_key_utils.dart +++ b/json_serializable/lib/src/json_key_utils.dart @@ -5,7 +5,6 @@ import 'package:analyzer/dart/constant/value.dart'; import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/type.dart'; -import 'package:build/build.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:source_gen/source_gen.dart'; @@ -18,21 +17,6 @@ final _jsonKeyExpando = Expando(); JsonKey jsonKeyForField(FieldElement field, JsonSerializable classAnnotation) => _jsonKeyExpando[field] ??= _from(field, classAnnotation); -/// Will log "info" if [element] has an explicit value for [JsonKey.nullable] -/// telling the programmer that it will be ignored. -void logFieldWithConversionFunction(FieldElement element) { - final jsonKey = _jsonKeyExpando[element]; - if (_explicitNullableExpando[jsonKey] ?? false) { - log.info( - 'The `JsonKey.nullable` value on ' - '`${element.enclosingElement.name}.${element.name}` will be ignored ' - 'because a custom conversion function is being used.', - ); - - _explicitNullableExpando[jsonKey] = null; - } -} - JsonKey _from(FieldElement element, JsonSerializable classAnnotation) { // If an annotation exists on `element` the source is a 'real' field. // If the result is `null`, check the getter – it is a property. @@ -195,7 +179,6 @@ JsonKey _from(FieldElement element, JsonSerializable classAnnotation) { ignore: obj.read('ignore').literalValue as bool, includeIfNull: obj.read('includeIfNull').literalValue as bool, name: obj.read('name').literalValue as String, - nullable: obj.read('nullable').literalValue as bool, required: obj.read('required').literalValue as bool, unknownEnumValue: _annotationValue('unknownEnumValue', mustBeEnum: true), ); @@ -209,7 +192,6 @@ JsonKey _populateJsonKey( bool ignore, bool includeIfNull, String name, - bool nullable, bool required, Object unknownEnumValue, }) { @@ -229,18 +211,13 @@ JsonKey _populateJsonKey( includeIfNull: _includeIfNull( includeIfNull, disallowNullValue, classAnnotation.includeIfNull), name: _encodedFieldName(classAnnotation, name, element), - nullable: nullable ?? classAnnotation.nullable, required: required ?? false, unknownEnumValue: unknownEnumValue, ); - _explicitNullableExpando[jsonKey] = nullable != null; - return jsonKey; } -final _explicitNullableExpando = Expando('explicit nullable'); - String _encodedFieldName(JsonSerializable classAnnotation, String jsonKeyNameValue, FieldElement fieldElement) { if (jsonKeyNameValue != null) { diff --git a/json_serializable/lib/src/json_serializable_generator.dart b/json_serializable/lib/src/json_serializable_generator.dart index 244017aeb..e0894c58a 100644 --- a/json_serializable/lib/src/json_serializable_generator.dart +++ b/json_serializable/lib/src/json_serializable_generator.dart @@ -61,6 +61,14 @@ class JsonSerializableGenerator ConstantReader annotation, BuildStep buildStep, ) { + if (!element.library.isNonNullableByDefault) { + throw InvalidGenerationSourceError( + 'Generator cannot target libraries that have not been migrated to ' + 'null-safety.', + element: element, + ); + } + if (element is! ClassElement) { throw InvalidGenerationSourceError( '`@JsonSerializable` can only be used on classes.', diff --git a/json_serializable/lib/src/shared_checkers.dart b/json_serializable/lib/src/shared_checkers.dart index 2a63a477e..595f8ead4 100644 --- a/json_serializable/lib/src/shared_checkers.dart +++ b/json_serializable/lib/src/shared_checkers.dart @@ -6,6 +6,7 @@ import 'package:analyzer/dart/element/type.dart'; import 'package:source_gen/source_gen.dart' show TypeChecker; import 'helper_core.dart'; +import 'utils.dart'; /// A [TypeChecker] for [Iterable]. const coreIterableTypeChecker = TypeChecker.fromUrl('dart:core#Iterable'); @@ -38,13 +39,13 @@ const simpleJsonTypeChecker = TypeChecker.any([ ]); String asStatement(DartType type) { - if (isObjectOrDynamic(type)) { + if (isLikeDynamic(type)) { return ''; } if (coreIterableTypeChecker.isAssignableFromType(type)) { final itemType = coreIterableGenericType(type); - if (isObjectOrDynamic(itemType)) { + if (isLikeDynamic(itemType)) { return ' as List'; } } @@ -53,7 +54,7 @@ String asStatement(DartType type) { final args = typeArgumentsOf(type, coreMapTypeChecker); assert(args.length == 2); - if (args.every(isObjectOrDynamic)) { + if (args.every(isLikeDynamic)) { return ' as Map'; } } @@ -62,8 +63,9 @@ String asStatement(DartType type) { return ' as $typeCode'; } -bool isObjectOrDynamic(DartType type) => - type.isDartCoreObject || type.isDynamic; +/// Returns `true` if [type] is `dynamic` or `Obect?`. +bool isLikeDynamic(DartType type) => + (type.isDartCoreObject && type.isNullableType) || type.isDynamic; /// Returns all of the [DartType] types that [type] implements, mixes-in, and /// extends, starting with [type] itself. diff --git a/json_serializable/lib/src/type_helper.dart b/json_serializable/lib/src/type_helper.dart index cef3d4afb..af0c1167c 100644 --- a/json_serializable/lib/src/type_helper.dart +++ b/json_serializable/lib/src/type_helper.dart @@ -15,9 +15,6 @@ abstract class TypeHelperContext { /// The field that code is being generated for. FieldElement get fieldElement; - /// Returns `true` if [fieldElement] could potentially contain a `null` value. - bool get nullable; - /// [expression] may be just the name of the field or it may an expression /// representing the serialization of a value. Object serialize(DartType fieldType, String expression); @@ -79,7 +76,12 @@ abstract class TypeHelper { /// String deserialize(DartType targetType, String expression) => /// "new ${targetType.name}.fromInt($expression)"; /// ```. - Object deserialize(DartType targetType, String expression, T context); + Object deserialize( + DartType targetType, + String expression, + T context, + bool defaultProvided, + ); } Object commonNullPrefix( diff --git a/json_serializable/lib/src/type_helper_ctx.dart b/json_serializable/lib/src/type_helper_ctx.dart index 84ea35199..cd1efaff5 100644 --- a/json_serializable/lib/src/type_helper_ctx.dart +++ b/json_serializable/lib/src/type_helper_ctx.dart @@ -6,6 +6,7 @@ import 'package:analyzer/dart/constant/value.dart'; import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/type.dart'; import 'package:json_annotation/json_annotation.dart'; +import 'package:meta/meta.dart'; import 'helper_core.dart'; import 'type_helper.dart'; @@ -14,27 +15,23 @@ import 'unsupported_type_error.dart'; import 'utils.dart'; TypeHelperCtx typeHelperContext( - HelperCore helperCore, FieldElement fieldElement, JsonKey key) => - TypeHelperCtx._(helperCore, fieldElement, key); + HelperCore helperCore, FieldElement fieldElement) => + TypeHelperCtx._(helperCore, fieldElement); class TypeHelperCtx implements TypeHelperContextWithConfig, TypeHelperContextWithConvert { final HelperCore _helperCore; - final JsonKey _key; @override final FieldElement fieldElement; - @override - bool get nullable => _key.nullable; - @override ClassElement get classElement => _helperCore.element; @override JsonSerializable get config => _helperCore.config; - TypeHelperCtx._(this._helperCore, this.fieldElement, this._key); + TypeHelperCtx._(this._helperCore, this.fieldElement); @override ConvertData get serializeConvertData => _pairFromContext?.toJson; @@ -57,10 +54,20 @@ class TypeHelperCtx ); @override - Object deserialize(DartType targetType, String expression) => _run( + Object deserialize( + DartType targetType, + String expression, { + @required bool defaultProvided, + }) => + _run( targetType, expression, - (TypeHelper th) => th.deserialize(targetType, expression, this), + (TypeHelper th) => th.deserialize( + targetType, + expression, + this, + defaultProvided ?? false, + ), ); Object _run( diff --git a/json_serializable/lib/src/type_helpers/big_int_helper.dart b/json_serializable/lib/src/type_helpers/big_int_helper.dart index 60017827f..4a4166d91 100644 --- a/json_serializable/lib/src/type_helpers/big_int_helper.dart +++ b/json_serializable/lib/src/type_helpers/big_int_helper.dart @@ -5,6 +5,7 @@ import 'package:analyzer/dart/element/type.dart'; import '../type_helper.dart'; +import '../utils.dart'; import 'to_from_string.dart'; class BigIntHelper extends TypeHelper { @@ -16,13 +17,23 @@ class BigIntHelper extends TypeHelper { String expression, TypeHelperContext context, ) => - bigIntString.serialize(targetType, expression, context.nullable); + bigIntString.serialize( + targetType, + expression, + targetType.isNullableType, + ); @override String deserialize( DartType targetType, String expression, TypeHelperContext context, + bool defaultProvided, ) => - bigIntString.deserialize(targetType, expression, context.nullable, false); + bigIntString.deserialize( + targetType, + expression, + targetType.isNullableType, + false, + ); } diff --git a/json_serializable/lib/src/type_helpers/convert_helper.dart b/json_serializable/lib/src/type_helpers/convert_helper.dart index 10c9fc22c..b605c5c4d 100644 --- a/json_serializable/lib/src/type_helpers/convert_helper.dart +++ b/json_serializable/lib/src/type_helpers/convert_helper.dart @@ -4,7 +4,6 @@ import 'package:analyzer/dart/element/type.dart'; -import '../json_key_utils.dart'; import '../shared_checkers.dart'; import '../type_helper.dart'; import '../utils.dart'; @@ -38,8 +37,6 @@ class ConvertHelper extends TypeHelper { return null; } - logFieldWithConversionFunction(context.fieldElement); - assert(toJsonData.paramType is TypeParameterType || targetType.isAssignableTo(toJsonData.paramType)); return '${toJsonData.name}($expression)'; @@ -50,14 +47,13 @@ class ConvertHelper extends TypeHelper { DartType targetType, String expression, TypeHelperContextWithConvert context, + bool defaultProvided, ) { final fromJsonData = context.deserializeConvertData; if (fromJsonData == null) { return null; } - logFieldWithConversionFunction(context.fieldElement); - final asContent = asStatement(fromJsonData.paramType); return '${fromJsonData.name}($expression$asContent)'; } diff --git a/json_serializable/lib/src/type_helpers/date_time_helper.dart b/json_serializable/lib/src/type_helpers/date_time_helper.dart index e10a6f96c..beefd0065 100644 --- a/json_serializable/lib/src/type_helpers/date_time_helper.dart +++ b/json_serializable/lib/src/type_helpers/date_time_helper.dart @@ -5,6 +5,7 @@ import 'package:analyzer/dart/element/type.dart'; import '../type_helper.dart'; +import '../utils.dart'; import 'to_from_string.dart'; class DateTimeHelper extends TypeHelper { @@ -16,14 +17,23 @@ class DateTimeHelper extends TypeHelper { String expression, TypeHelperContext context, ) => - dateTimeString.serialize(targetType, expression, context.nullable); + dateTimeString.serialize( + targetType, + expression, + targetType.isNullableType, + ); @override String deserialize( DartType targetType, String expression, TypeHelperContext context, + bool defaultProvided, ) => dateTimeString.deserialize( - targetType, expression, context.nullable, false); + targetType, + expression, + targetType.isNullableType, + false, + ); } diff --git a/json_serializable/lib/src/type_helpers/duration_helper.dart b/json_serializable/lib/src/type_helpers/duration_helper.dart index 63bdd52d7..95acda21a 100644 --- a/json_serializable/lib/src/type_helpers/duration_helper.dart +++ b/json_serializable/lib/src/type_helpers/duration_helper.dart @@ -6,6 +6,7 @@ import 'package:analyzer/dart/element/type.dart'; import 'package:source_gen/source_gen.dart' show TypeChecker; import '../type_helper.dart'; +import '../utils.dart'; class DurationHelper extends TypeHelper { const DurationHelper(); @@ -22,7 +23,7 @@ class DurationHelper extends TypeHelper { final buffer = StringBuffer(expression); - if (context.nullable) { + if (targetType.isNullableType) { buffer.write('?'); } @@ -36,13 +37,14 @@ class DurationHelper extends TypeHelper { DartType targetType, String expression, TypeHelperContext context, + bool defaultProvided, ) { if (!_matchesType(targetType)) { return null; } return commonNullPrefix( - context.nullable, + targetType.isNullableType, expression, 'Duration(microseconds: $expression as int)', ).toString(); diff --git a/json_serializable/lib/src/type_helpers/enum_helper.dart b/json_serializable/lib/src/type_helpers/enum_helper.dart index bf1128fcd..f12c54740 100644 --- a/json_serializable/lib/src/type_helpers/enum_helper.dart +++ b/json_serializable/lib/src/type_helpers/enum_helper.dart @@ -36,6 +36,7 @@ class EnumHelper extends TypeHelper { DartType targetType, String expression, TypeHelperContextWithConfig context, + bool defaultProvided, ) { final memberContent = _enumValueMapFromType(targetType); @@ -45,15 +46,16 @@ class EnumHelper extends TypeHelper { context.addMember(_enumDecodeHelper); - if (context.nullable) { + String functionName; + if (targetType.isNullableType || defaultProvided) { + functionName = r'_$enumDecodeNullable'; context.addMember(_enumDecodeHelperNullable); + } else { + functionName = r'_$enumDecode'; } context.addMember(memberContent); - final functionName = - context.nullable ? r'_$enumDecodeNullable' : r'_$enumDecode'; - final jsonKey = jsonKeyForField(context.fieldElement, context.config); final args = [ _constMapName(targetType), @@ -85,36 +87,40 @@ String _enumValueMapFromType(DartType targetType) { } const _enumDecodeHelper = r''' -T _$enumDecode( - Map enumValues, - dynamic source, { - T unknownValue, +K _$enumDecode( + Map enumValues, + Object? source, { + K? unknownValue, }) { if (source == null) { - throw ArgumentError('A value must be provided. Supported values: ' - '${enumValues.values.join(', ')}'); + throw ArgumentError( + 'A value must be provided. Supported values: ' + '${enumValues.values.join(', ')}', + ); } - final value = enumValues.entries - .singleWhere((e) => e.value == source, orElse: () => null) - ?.key; - - if (value == null && unknownValue == null) { - throw ArgumentError('`$source` is not one of the supported values: ' - '${enumValues.values.join(', ')}'); - } - return value ?? unknownValue; -} -'''; + return enumValues.entries.singleWhere( + (e) => e.value == source, + orElse: () { + if (unknownValue == null) { + throw ArgumentError( + '`$source` is not one of the supported values: ' + '${enumValues.values.join(', ')}', + ); + } + return MapEntry(unknownValue, enumValues.values.first); + }, + ).key; +}'''; const _enumDecodeHelperNullable = r''' -T _$enumDecodeNullable( - Map enumValues, +K? _$enumDecodeNullable( + Map enumValues, dynamic source, { - T unknownValue, + K? unknownValue, }) { if (source == null) { return null; } - return _$enumDecode(enumValues, source, unknownValue: unknownValue); + return _$enumDecode(enumValues, source, unknownValue: unknownValue); }'''; diff --git a/json_serializable/lib/src/type_helpers/generic_factory_helper.dart b/json_serializable/lib/src/type_helpers/generic_factory_helper.dart index 0a3bb8aba..a8f8dc88c 100644 --- a/json_serializable/lib/src/type_helpers/generic_factory_helper.dart +++ b/json_serializable/lib/src/type_helpers/generic_factory_helper.dart @@ -29,6 +29,7 @@ class GenericFactoryHelper extends TypeHelper { DartType targetType, String expression, TypeHelperContextWithConfig context, + bool defaultProvided, ) { if (context.config.genericArgumentFactories && targetType is TypeParameterType) { diff --git a/json_serializable/lib/src/type_helpers/iterable_helper.dart b/json_serializable/lib/src/type_helpers/iterable_helper.dart index 30be10767..53f2fcf69 100644 --- a/json_serializable/lib/src/type_helpers/iterable_helper.dart +++ b/json_serializable/lib/src/type_helpers/iterable_helper.dart @@ -9,6 +9,7 @@ import '../constants.dart'; import '../lambda_result.dart'; import '../shared_checkers.dart'; import '../type_helper.dart'; +import '../utils.dart'; class IterableHelper extends TypeHelper { const IterableHelper(); @@ -31,7 +32,7 @@ class IterableHelper extends TypeHelper { var isList = _coreListChecker.isAssignableFromType(targetType); final subField = context.serialize(itemType, closureArg); - final optionalQuestion = context.nullable ? '?' : ''; + var optionalQuestion = targetType.isNullableType ? '?' : ''; // In the case of trivial JSON types (int, String, etc), `subField` // will be identical to `substitute` – so no explicit mapping is needed. @@ -44,6 +45,9 @@ class IterableHelper extends TypeHelper { // expression now represents an Iterable (even if it started as a List // ...resetting `isList` to `false`. isList = false; + + // No need to include the optional question below – it was used here! + optionalQuestion = ''; } if (!isList) { @@ -59,6 +63,7 @@ class IterableHelper extends TypeHelper { DartType targetType, String expression, TypeHelperContext context, + bool defaultProvided, ) { if (!(coreIterableTypeChecker.isExactlyType(targetType) || _coreListChecker.isExactlyType(targetType) || @@ -70,7 +75,13 @@ class IterableHelper extends TypeHelper { final itemSubVal = context.deserialize(iterableGenericType, closureArg); - var output = '$expression as List'; + var output = '$expression as List'; + + final targetTypeIsNullable = defaultProvided || targetType.isNullableType; + + if (targetTypeIsNullable) { + output += '?'; + } // If `itemSubVal` is the same and it's not a Set, then we don't need to do // anything fancy @@ -81,11 +92,13 @@ class IterableHelper extends TypeHelper { output = '($output)'; - final optionalQuestion = context.nullable ? '?' : ''; + var optionalQuestion = targetTypeIsNullable ? '?' : ''; if (closureArg != itemSubVal) { final lambda = LambdaResult.process(itemSubVal, closureArg); output += '$optionalQuestion.map($lambda)'; + // No need to include the optional question below – it was used here! + optionalQuestion = ''; } if (_coreListChecker.isExactlyType(targetType)) { diff --git a/json_serializable/lib/src/type_helpers/json_converter_helper.dart b/json_serializable/lib/src/type_helpers/json_converter_helper.dart index aae2dd580..f1f2bdfd1 100644 --- a/json_serializable/lib/src/type_helpers/json_converter_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_converter_helper.dart @@ -9,10 +9,10 @@ import 'package:json_annotation/json_annotation.dart'; import 'package:source_gen/source_gen.dart'; import '../helper_core.dart'; -import '../json_key_utils.dart'; import '../lambda_result.dart'; import '../shared_checkers.dart'; import '../type_helper.dart'; +import '../utils.dart'; /// A [TypeHelper] that supports classes annotated with implementations of /// [JsonConverter]. @@ -31,8 +31,6 @@ class JsonConverterHelper extends TypeHelper { return null; } - logFieldWithConversionFunction(context.fieldElement); - return LambdaResult(expression, '${converter.accessString}.toJson'); } @@ -41,6 +39,7 @@ class JsonConverterHelper extends TypeHelper { DartType targetType, String expression, TypeHelperContext context, + bool defaultProvided, ) { final converter = _typeConverter(targetType, context); if (converter == null) { @@ -49,8 +48,6 @@ class JsonConverterHelper extends TypeHelper { final asContent = asStatement(converter.jsonType); - logFieldWithConversionFunction(context.fieldElement); - return LambdaResult( '$expression$asContent', '${converter.accessString}.fromJson'); } @@ -209,7 +206,7 @@ _ConverterMatch _compatibleMatch( annotation, constantValue, jsonConverterSuper.typeArguments[1], - targetType.element.name, + '${targetType.element.name}${targetType.isNullableType ? '?' : ''}', ); } diff --git a/json_serializable/lib/src/type_helpers/json_helper.dart b/json_serializable/lib/src/type_helpers/json_helper.dart index b783e19f3..a678a309e 100644 --- a/json_serializable/lib/src/type_helpers/json_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_helper.dart @@ -55,7 +55,7 @@ class JsonHelper extends TypeHelper { } if (context.config.explicitToJson || toJsonArgs.isNotEmpty) { - return '$expression${context.nullable ? '?' : ''}' + return '$expression${interfaceType.isNullableType ? '?' : ''}' '.toJson(${toJsonArgs.map((a) => '$a, ').join()} )'; } return expression; @@ -66,6 +66,7 @@ class JsonHelper extends TypeHelper { DartType targetType, String expression, TypeHelperContextWithConfig context, + bool defaultProvided, ) { if (targetType is! InterfaceType) { return null; @@ -128,7 +129,8 @@ class JsonHelper extends TypeHelper { // https://github.com/google/json_serializable.dart/issues/19 output = '${targetType.element.name}.fromJson($output)'; - return commonNullPrefix(context.nullable, expression, output).toString(); + return commonNullPrefix(targetType.isNullableType, expression, output) + .toString(); } } @@ -173,7 +175,8 @@ TypeParameterType _decodeHelper( if (param.name == fromJsonForName(funcReturnType.element.name)) { final funcParamType = type.normalParameterTypes.single; - if (funcParamType.isDartCoreObject || funcParamType.isDynamic) { + if ((funcParamType.isDartCoreObject && funcParamType.isNullableType) || + funcParamType.isDynamic) { return funcReturnType as TypeParameterType; } } @@ -183,7 +186,7 @@ TypeParameterType _decodeHelper( 'Expecting a `fromJson` constructor with exactly one positional ' 'parameter. ' 'The only extra parameters allowed are functions of the form ' - '`T Function(Object) ${fromJsonForName('T')}` where `T` is a type ' + '`T Function(Object?) ${fromJsonForName('T')}` where `T` is a type ' 'parameter of the target type.', element: targetElement, ); @@ -196,7 +199,7 @@ TypeParameterType _encodeHelper( final type = param.type; if (type is FunctionType && - isObjectOrDynamic(type.returnType) && + (type.returnType.isDartCoreObject || type.returnType.isDynamic) && type.normalParameterTypes.length == 1) { final funcParamType = type.normalParameterTypes.single; diff --git a/json_serializable/lib/src/type_helpers/map_helper.dart b/json_serializable/lib/src/type_helpers/map_helper.dart index 09c8219c3..5eb83300b 100644 --- a/json_serializable/lib/src/type_helpers/map_helper.dart +++ b/json_serializable/lib/src/type_helpers/map_helper.dart @@ -42,7 +42,7 @@ class MapHelper extends TypeHelper { return expression; } - final optionalQuestion = context.nullable ? '?' : ''; + final optionalQuestion = targetType.isNullableType ? '?' : ''; return '$expression$optionalQuestion' '.map(($_keyParam, $closureArg) => ' @@ -54,6 +54,7 @@ class MapHelper extends TypeHelper { DartType targetType, String expression, TypeHelperContextWithConfig context, + bool defaultProvided, ) { if (!coreMapTypeChecker.isExactlyType(targetType)) { return null; @@ -66,23 +67,27 @@ class MapHelper extends TypeHelper { _checkSafeKeyType(expression, keyArg); - final valueArgIsAny = isObjectOrDynamic(valueArg); + final valueArgIsAny = valueArg.isDynamic || + (valueArg.isDartCoreObject && valueArg.isNullableType); final isKeyStringable = _isKeyStringable(keyArg); + final targetTypeIsNullable = defaultProvided || targetType.isNullableType; + final optionalQuestion = targetTypeIsNullable ? '?' : ''; + if (!isKeyStringable) { if (valueArgIsAny) { if (context.config.anyMap) { - if (isObjectOrDynamic(keyArg)) { - return '$expression as Map'; + if (isLikeDynamic(keyArg)) { + return '$expression as Map$optionalQuestion'; } } else { // this is the trivial case. Do a runtime cast to the known type of // JSON map values - `Map` - return '$expression as Map'; + return '$expression as Map$optionalQuestion'; } } - if (!context.nullable && + if (!targetTypeIsNullable && (valueArgIsAny || simpleJsonTypeChecker.isAssignableFromType(valueArg))) { // No mapping of the values or null check required! @@ -96,16 +101,22 @@ class MapHelper extends TypeHelper { final itemSubVal = context.deserialize(valueArg, closureArg); - final optionalQuestion = context.nullable ? '?' : ''; + var mapCast = context.config.anyMap ? 'as Map' : 'as Map'; - final mapCast = - context.config.anyMap ? 'as Map' : 'as Map'; + if (targetTypeIsNullable) { + mapCast += '?'; + } String keyUsage; if (isEnum(keyArg)) { keyUsage = context.deserialize(keyArg, _keyParam).toString(); - } else if (context.config.anyMap && !isObjectOrDynamic(keyArg)) { + } else if (context.config.anyMap && + !(keyArg.isDartCoreObject || keyArg.isDynamic)) { keyUsage = '$_keyParam as String'; + } else if (context.config.anyMap && + keyArg.isDartCoreObject && + !keyArg.isNullableType) { + keyUsage = '$_keyParam as Object'; } else { keyUsage = _keyParam; } @@ -142,9 +153,11 @@ bool _isKeyStringable(DartType keyType) => void _checkSafeKeyType(String expression, DartType keyArg) { // We're not going to handle converting key types at the moment // So the only safe types for key are dynamic/Object/String/enum - if (isObjectOrDynamic(keyArg) || - coreStringTypeChecker.isExactlyType(keyArg) || - _isKeyStringable(keyArg)) { + if (keyArg.isDynamic || + (!keyArg.isNullableType && + (keyArg.isDartCoreObject || + coreStringTypeChecker.isExactlyType(keyArg) || + _isKeyStringable(keyArg)))) { return; } diff --git a/json_serializable/lib/src/type_helpers/uri_helper.dart b/json_serializable/lib/src/type_helpers/uri_helper.dart index 81267d903..2100812a5 100644 --- a/json_serializable/lib/src/type_helpers/uri_helper.dart +++ b/json_serializable/lib/src/type_helpers/uri_helper.dart @@ -5,6 +5,7 @@ import 'package:analyzer/dart/element/type.dart'; import '../type_helper.dart'; +import '../utils.dart'; import 'to_from_string.dart'; class UriHelper extends TypeHelper { @@ -16,13 +17,19 @@ class UriHelper extends TypeHelper { String expression, TypeHelperContext context, ) => - uriString.serialize(targetType, expression, context.nullable); + uriString.serialize( + targetType, + expression, + targetType.isNullableType, + ); @override String deserialize( DartType targetType, String expression, TypeHelperContext context, + bool defaultProvided, ) => - uriString.deserialize(targetType, expression, context.nullable, false); + uriString.deserialize( + targetType, expression, targetType.isNullableType, false); } diff --git a/json_serializable/lib/src/type_helpers/value_helper.dart b/json_serializable/lib/src/type_helpers/value_helper.dart index ef898e0a4..0f9c0b43f 100644 --- a/json_serializable/lib/src/type_helpers/value_helper.dart +++ b/json_serializable/lib/src/type_helpers/value_helper.dart @@ -3,11 +3,11 @@ // BSD-style license that can be found in the LICENSE file. import 'package:analyzer/dart/element/type.dart'; -import 'package:source_gen/source_gen.dart' show TypeChecker; import '../helper_core.dart'; import '../shared_checkers.dart'; import '../type_helper.dart'; +import '../utils.dart'; class ValueHelper extends TypeHelper { const ValueHelper(); @@ -18,7 +18,8 @@ class ValueHelper extends TypeHelper { String expression, TypeHelperContext context, ) { - if (isObjectOrDynamic(targetType) || + if (targetType.isDartCoreObject || + targetType.isDynamic || simpleJsonTypeChecker.isAssignableFromType(targetType)) { return expression; } @@ -31,15 +32,20 @@ class ValueHelper extends TypeHelper { DartType targetType, String expression, TypeHelperContext context, + bool defaultProvided, ) { - if (isObjectOrDynamic(targetType)) { + if (targetType.isDartCoreObject && !targetType.isNullableType) { + final question = defaultProvided ? '?' : ''; + return '$expression as Object$question'; + } else if (targetType.isDartCoreObject || targetType.isDynamic) { // just return it as-is. We'll hope it's safe. return expression; - } else if (const TypeChecker.fromUrl('dart:core#double') - .isExactlyType(targetType)) { - return '($expression as num)${context.nullable ? '?' : ''}.toDouble()'; + } else if (targetType.isDartCoreDouble) { + final targetTypeNullable = defaultProvided || targetType.isNullableType; + final question = targetTypeNullable ? '?' : ''; + return '($expression as num$question)$question.toDouble()'; } else if (simpleJsonTypeChecker.isAssignableFromType(targetType)) { - final typeCode = typeToCode(targetType); + final typeCode = typeToCode(targetType, forceNullable: defaultProvided); return '$expression as $typeCode'; } diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index a353a8c20..3b94f13bd 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -4,6 +4,7 @@ import 'package:analyzer/dart/constant/value.dart'; import 'package:analyzer/dart/element/element.dart'; +import 'package:analyzer/dart/element/nullability_suffix.dart'; import 'package:analyzer/dart/element/type.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:meta/meta.dart' show alwaysThrows, required; @@ -87,7 +88,6 @@ JsonSerializable _valueForAnnotation(ConstantReader reader) => JsonSerializable( reader.read('genericArgumentFactories').literalValue as bool, ignoreUnannotated: reader.read('ignoreUnannotated').literalValue as bool, includeIfNull: reader.read('includeIfNull').literalValue as bool, - nullable: reader.read('nullable').literalValue as bool, ); /// Returns a [JsonSerializable] with values from the [JsonSerializable] @@ -120,7 +120,6 @@ JsonSerializable mergeConfig( config.genericArgumentFactories), ignoreUnannotated: annotation.ignoreUnannotated ?? config.ignoreUnannotated, includeIfNull: annotation.includeIfNull ?? config.includeIfNull, - nullable: annotation.nullable ?? config.nullable, ); } @@ -271,3 +270,8 @@ extension DartTypeExtension on DartType { element.library == null || element.library.typeSystem.isAssignableTo(this, other); } + +extension TypeExtension on DartType { + bool get isNullableType => + isDynamic || nullabilitySuffix == NullabilitySuffix.question; +} diff --git a/json_serializable/mono_pkg.yaml b/json_serializable/mono_pkg.yaml index 485700e0e..48a0642be 100644 --- a/json_serializable/mono_pkg.yaml +++ b/json_serializable/mono_pkg.yaml @@ -1,6 +1,5 @@ # See https://github.com/google/mono_repo.dart for details on this file dart: -- 2.7.0 - dev stages: @@ -8,12 +7,8 @@ stages: - group: - dartfmt - dartanalyzer: --fatal-warnings --fatal-infos . - dart: [dev] - - group: - - dartanalyzer: --fatal-warnings . - dart: [2.7.0] - unit_test: - - test + - test: - test: -p chrome - ensure_build: - test: --run-skipped -t presubmit-only test/ensure_build_test.dart diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 53bb2223c..82d71cc5d 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,14 +1,14 @@ name: json_serializable -version: 3.5.0-dev +version: 4.0.0-nullsafety.1 description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. -homepage: https://github.com/google/json_serializable.dart +repository: https://github.com/google/json_serializable.dart environment: - sdk: '>=2.7.0 <3.0.0' + sdk: '>=2.11.0 <3.0.0' dependencies: - analyzer: '>=0.39.0 <0.41.0' + analyzer: ^0.40.6 build: '>=0.12.6 <2.0.0' build_config: '>=0.2.6 <0.5.0' @@ -17,8 +17,8 @@ dependencies: # For v3 only – allow a wide range since the only change was to REMOVE things # from json_annotation json_annotation: '>=3.1.0 <3.2.0' - meta: ^1.1.0 - path: ^1.3.2 + meta: ^1.3.0-nullsafety.5 + path: ^1.8.0-nullsafety.2 source_gen: ^0.9.6 dev_dependencies: @@ -29,5 +29,10 @@ dev_dependencies: logging: ^0.11.3+1 pub_semver: ^1.4.0 source_gen_test: ^0.1.0 - test: ^1.6.0 + stack_trace: ^1.10.0-nullsafety.5 + test: ^1.16.0-nullsafety.7 yaml: ^2.1.13 + +dependency_overrides: + json_annotation: + path: ../json_annotation diff --git a/json_serializable/test/config_test.dart b/json_serializable/test/config_test.dart index da4959572..7356a47f6 100644 --- a/json_serializable/test/config_test.dart +++ b/json_serializable/test/config_test.dart @@ -142,5 +142,4 @@ const _invalidConfig = { 'generic_argument_factories': 42, 'ignore_unannotated': 42, 'include_if_null': 42, - 'nullable': 42, }; diff --git a/json_serializable/test/custom_configuration_test.dart b/json_serializable/test/custom_configuration_test.dart index 87857934b..02a04cf1b 100644 --- a/json_serializable/test/custom_configuration_test.dart +++ b/json_serializable/test/custom_configuration_test.dart @@ -6,6 +6,7 @@ import 'dart:async'; import 'package:analyzer/dart/element/type.dart'; +import 'package:build/experiments.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:json_serializable/json_serializable.dart'; import 'package:json_serializable/src/constants.dart'; @@ -21,9 +22,12 @@ LibraryReader _libraryReader; Future main() async { initializeBuildLogTracking(); - _libraryReader = await initializeLibraryReaderForDirectory( - p.join('test', 'test_sources'), - 'test_sources.dart', + _libraryReader = await withEnabledExperiments( + () => initializeLibraryReaderForDirectory( + p.join('test', 'test_sources'), + 'test_sources.dart', + ), + ['non-nullable'], ); group('without wrappers', () { @@ -188,7 +192,10 @@ Map _$TrivialNestedNonNullableToJson( final output = await runForElementNamed('ParentObjectWithDynamicChildren'); - expect(output, contains('children = json[\'children\'] as List;')); + expect( + output, + contains('children = json[\'children\'] as List;'), + ); }); }); @@ -207,8 +214,12 @@ class _ConfigLogger implements TypeHelper { const _ConfigLogger(); @override - Object deserialize(DartType targetType, String expression, - TypeHelperContextWithConfig context) { + Object deserialize( + DartType targetType, + String expression, + TypeHelperContextWithConfig context, + bool defaultProvided, + ) { configurations.add(context.config); return null; } diff --git a/json_serializable/test/default_value/default_value.dart b/json_serializable/test/default_value/default_value.dart index 083c60d05..84f1b972e 100644 --- a/json_serializable/test/default_value/default_value.dart +++ b/json_serializable/test/default_value/default_value.dart @@ -2,6 +2,8 @@ // 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. +// @dart=2.12 + // ignore_for_file: annotate_overrides import 'package:json_annotation/json_annotation.dart'; @@ -56,7 +58,20 @@ class DefaultValue implements dvi.DefaultValue { @JsonKey(defaultValue: Greek.beta) Greek fieldEnum; - DefaultValue(); + DefaultValue( + this.fieldBool, + this.fieldString, + this.fieldInt, + this.fieldDouble, + this.fieldListEmpty, + this.fieldSetEmpty, + this.fieldMapEmpty, + this.fieldListSimple, + this.fieldSetSimple, + this.fieldMapSimple, + this.fieldMapListString, + this.fieldEnum, + ); factory DefaultValue.fromJson(Map json) => _$DefaultValueFromJson(json); diff --git a/json_serializable/test/default_value/default_value.g.dart b/json_serializable/test/default_value/default_value.g.dart index 95bcdd973..0c29c64b8 100644 --- a/json_serializable/test/default_value/default_value.g.dart +++ b/json_serializable/test/default_value/default_value.g.dart @@ -1,4 +1,5 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// @dart=2.12 part of 'default_value.dart'; @@ -7,91 +8,88 @@ part of 'default_value.dart'; // ************************************************************************** DefaultValue _$DefaultValueFromJson(Map json) { - return DefaultValue() - ..fieldBool = json['fieldBool'] as bool ?? true - ..fieldString = json['fieldString'] as String ?? 'string' - ..fieldInt = json['fieldInt'] as int ?? 42 - ..fieldDouble = (json['fieldDouble'] as num)?.toDouble() ?? 3.14 - ..fieldListEmpty = json['fieldListEmpty'] as List ?? [] - ..fieldSetEmpty = (json['fieldSetEmpty'] as List)?.toSet() ?? {} - ..fieldMapEmpty = json['fieldMapEmpty'] as Map ?? {} - ..fieldListSimple = - (json['fieldListSimple'] as List)?.map((e) => e as int)?.toList() ?? - [1, 2, 3] - ..fieldSetSimple = - (json['fieldSetSimple'] as List)?.map((e) => e as String)?.toSet() ?? - {'entry1', 'entry2'} - ..fieldMapSimple = (json['fieldMapSimple'] as Map)?.map( + return DefaultValue( + json['fieldBool'] as bool? ?? true, + json['fieldString'] as String? ?? 'string', + json['fieldInt'] as int? ?? 42, + (json['fieldDouble'] as num?)?.toDouble() ?? 3.14, + json['fieldListEmpty'] as List? ?? [], + (json['fieldSetEmpty'] as List?)?.toSet() ?? {}, + json['fieldMapEmpty'] as Map? ?? {}, + (json['fieldListSimple'] as List?) + ?.map((e) => e as int) + .toList() ?? + [1, 2, 3], + (json['fieldSetSimple'] as List?) + ?.map((e) => e as String) + .toSet() ?? + {'entry1', 'entry2'}, + (json['fieldMapSimple'] as Map?)?.map( (k, e) => MapEntry(k, e as int), ) ?? - {'answer': 42} - ..fieldMapListString = - (json['fieldMapListString'] as Map)?.map( - (k, e) => - MapEntry(k, (e as List)?.map((e) => e as String)?.toList()), - ) ?? - { - 'root': ['child'] - } - ..fieldEnum = - _$enumDecodeNullable(_$GreekEnumMap, json['fieldEnum']) ?? Greek.beta; + {'answer': 42}, + (json['fieldMapListString'] as Map?)?.map( + (k, e) => MapEntry( + k, (e as List).map((e) => e as String).toList()), + ) ?? + { + 'root': ['child'] + }, + _$enumDecodeNullable(_$GreekEnumMap, json['fieldEnum']) ?? Greek.beta, + ); } -Map _$DefaultValueToJson(DefaultValue instance) { - final val = { - 'fieldBool': instance.fieldBool, - }; - - void writeNotNull(String key, dynamic value) { - if (value != null) { - val[key] = value; - } - } - - writeNotNull('fieldString', instance.fieldString); - val['fieldInt'] = instance.fieldInt; - val['fieldDouble'] = instance.fieldDouble; - val['fieldListEmpty'] = instance.fieldListEmpty; - val['fieldSetEmpty'] = instance.fieldSetEmpty?.toList(); - val['fieldMapEmpty'] = instance.fieldMapEmpty; - val['fieldListSimple'] = instance.fieldListSimple; - val['fieldSetSimple'] = instance.fieldSetSimple?.toList(); - val['fieldMapSimple'] = instance.fieldMapSimple; - val['fieldMapListString'] = instance.fieldMapListString; - val['fieldEnum'] = _$GreekEnumMap[instance.fieldEnum]; - return val; -} +Map _$DefaultValueToJson(DefaultValue instance) => + { + 'fieldBool': instance.fieldBool, + 'fieldString': instance.fieldString, + 'fieldInt': instance.fieldInt, + 'fieldDouble': instance.fieldDouble, + 'fieldListEmpty': instance.fieldListEmpty, + 'fieldSetEmpty': instance.fieldSetEmpty.toList(), + 'fieldMapEmpty': instance.fieldMapEmpty, + 'fieldListSimple': instance.fieldListSimple, + 'fieldSetSimple': instance.fieldSetSimple.toList(), + 'fieldMapSimple': instance.fieldMapSimple, + 'fieldMapListString': instance.fieldMapListString, + 'fieldEnum': _$GreekEnumMap[instance.fieldEnum], + }; -T _$enumDecode( - Map enumValues, - dynamic source, { - T unknownValue, +K _$enumDecode( + Map enumValues, + Object? source, { + K? unknownValue, }) { if (source == null) { - throw ArgumentError('A value must be provided. Supported values: ' - '${enumValues.values.join(', ')}'); + throw ArgumentError( + 'A value must be provided. Supported values: ' + '${enumValues.values.join(', ')}', + ); } - final value = enumValues.entries - .singleWhere((e) => e.value == source, orElse: () => null) - ?.key; - - if (value == null && unknownValue == null) { - throw ArgumentError('`$source` is not one of the supported values: ' - '${enumValues.values.join(', ')}'); - } - return value ?? unknownValue; + return enumValues.entries.singleWhere( + (e) => e.value == source, + orElse: () { + if (unknownValue == null) { + throw ArgumentError( + '`$source` is not one of the supported values: ' + '${enumValues.values.join(', ')}', + ); + } + return MapEntry(unknownValue, enumValues.values.first); + }, + ).key; } -T _$enumDecodeNullable( - Map enumValues, +K? _$enumDecodeNullable( + Map enumValues, dynamic source, { - T unknownValue, + K? unknownValue, }) { if (source == null) { return null; } - return _$enumDecode(enumValues, source, unknownValue: unknownValue); + return _$enumDecode(enumValues, source, unknownValue: unknownValue); } const _$GreekEnumMap = { diff --git a/json_serializable/test/default_value/default_value.g_any_map__checked.dart b/json_serializable/test/default_value/default_value.g_any_map__checked.dart index d0b3ffae5..615505145 100644 --- a/json_serializable/test/default_value/default_value.g_any_map__checked.dart +++ b/json_serializable/test/default_value/default_value.g_any_map__checked.dart @@ -2,6 +2,8 @@ // 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. +// @dart=2.12 + // ignore_for_file: annotate_overrides import 'package:json_annotation/json_annotation.dart'; @@ -59,7 +61,20 @@ class DefaultValue implements dvi.DefaultValue { @JsonKey(defaultValue: Greek.beta) Greek fieldEnum; - DefaultValue(); + DefaultValue( + this.fieldBool, + this.fieldString, + this.fieldInt, + this.fieldDouble, + this.fieldListEmpty, + this.fieldSetEmpty, + this.fieldMapEmpty, + this.fieldListSimple, + this.fieldSetSimple, + this.fieldMapSimple, + this.fieldMapListString, + this.fieldEnum, + ); factory DefaultValue.fromJson(Map json) => _$DefaultValueFromJson(json); diff --git a/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart b/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart index 528e085e1..5aa38d430 100644 --- a/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart +++ b/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart @@ -1,4 +1,5 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// @dart=2.12 part of 'default_value.g_any_map__checked.dart'; @@ -8,112 +9,99 @@ part of 'default_value.g_any_map__checked.dart'; DefaultValue _$DefaultValueFromJson(Map json) { return $checkedNew('DefaultValue', json, () { - final val = DefaultValue(); - $checkedConvert( - json, 'fieldBool', (v) => val.fieldBool = v as bool ?? true); - $checkedConvert( - json, 'fieldString', (v) => val.fieldString = v as String ?? 'string'); - $checkedConvert(json, 'fieldInt', (v) => val.fieldInt = v as int ?? 42); - $checkedConvert(json, 'fieldDouble', - (v) => val.fieldDouble = (v as num)?.toDouble() ?? 3.14); - $checkedConvert( - json, 'fieldListEmpty', (v) => val.fieldListEmpty = v as List ?? []); - $checkedConvert(json, 'fieldSetEmpty', - (v) => val.fieldSetEmpty = (v as List)?.toSet() ?? {}); - $checkedConvert( - json, 'fieldMapEmpty', (v) => val.fieldMapEmpty = v as Map ?? {}); - $checkedConvert( - json, - 'fieldListSimple', - (v) => val.fieldListSimple = - (v as List)?.map((e) => e as int)?.toList() ?? [1, 2, 3]); - $checkedConvert( - json, - 'fieldSetSimple', - (v) => val.fieldSetSimple = - (v as List)?.map((e) => e as String)?.toSet() ?? - {'entry1', 'entry2'}); - $checkedConvert( - json, - 'fieldMapSimple', - (v) => val.fieldMapSimple = (v as Map)?.map( - (k, e) => MapEntry(k as String, e as int), - ) ?? - {'answer': 42}); - $checkedConvert( - json, - 'fieldMapListString', - (v) => val.fieldMapListString = (v as Map)?.map( - (k, e) => MapEntry( - k as String, (e as List)?.map((e) => e as String)?.toList()), - ) ?? - { - 'root': ['child'] - }); - $checkedConvert( - json, - 'fieldEnum', - (v) => val.fieldEnum = - _$enumDecodeNullable(_$GreekEnumMap, v) ?? Greek.beta); + final val = DefaultValue( + $checkedConvert(json, 'fieldBool', (v) => v as bool?) ?? true, + $checkedConvert(json, 'fieldString', (v) => v as String?) ?? 'string', + $checkedConvert(json, 'fieldInt', (v) => v as int?) ?? 42, + $checkedConvert(json, 'fieldDouble', (v) => (v as num?)?.toDouble()) ?? + 3.14, + $checkedConvert(json, 'fieldListEmpty', (v) => v as List?) ?? [], + $checkedConvert( + json, 'fieldSetEmpty', (v) => (v as List?)?.toSet()) ?? + {}, + $checkedConvert(json, 'fieldMapEmpty', (v) => v as Map?) ?? {}, + $checkedConvert(json, 'fieldListSimple', + (v) => (v as List?)?.map((e) => e as int).toList()) ?? + [1, 2, 3], + $checkedConvert(json, 'fieldSetSimple', + (v) => (v as List?)?.map((e) => e as String).toSet()) ?? + {'entry1', 'entry2'}, + $checkedConvert( + json, + 'fieldMapSimple', + (v) => (v as Map?)?.map( + (k, e) => MapEntry(k as String, e as int), + )) ?? + {'answer': 42}, + $checkedConvert( + json, + 'fieldMapListString', + (v) => (v as Map?)?.map( + (k, e) => MapEntry(k as String, + (e as List).map((e) => e as String).toList()), + )) ?? + { + 'root': ['child'] + }, + $checkedConvert(json, 'fieldEnum', + (v) => _$enumDecodeNullable(_$GreekEnumMap, v)) ?? + Greek.beta, + ); return val; }); } -Map _$DefaultValueToJson(DefaultValue instance) { - final val = { - 'fieldBool': instance.fieldBool, - }; +Map _$DefaultValueToJson(DefaultValue instance) => + { + 'fieldBool': instance.fieldBool, + 'fieldString': instance.fieldString, + 'fieldInt': instance.fieldInt, + 'fieldDouble': instance.fieldDouble, + 'fieldListEmpty': instance.fieldListEmpty, + 'fieldSetEmpty': instance.fieldSetEmpty.toList(), + 'fieldMapEmpty': instance.fieldMapEmpty, + 'fieldListSimple': instance.fieldListSimple, + 'fieldSetSimple': instance.fieldSetSimple.toList(), + 'fieldMapSimple': instance.fieldMapSimple, + 'fieldMapListString': instance.fieldMapListString, + 'fieldEnum': _$GreekEnumMap[instance.fieldEnum], + }; - void writeNotNull(String key, dynamic value) { - if (value != null) { - val[key] = value; - } - } - - writeNotNull('fieldString', instance.fieldString); - val['fieldInt'] = instance.fieldInt; - val['fieldDouble'] = instance.fieldDouble; - val['fieldListEmpty'] = instance.fieldListEmpty; - val['fieldSetEmpty'] = instance.fieldSetEmpty?.toList(); - val['fieldMapEmpty'] = instance.fieldMapEmpty; - val['fieldListSimple'] = instance.fieldListSimple; - val['fieldSetSimple'] = instance.fieldSetSimple?.toList(); - val['fieldMapSimple'] = instance.fieldMapSimple; - val['fieldMapListString'] = instance.fieldMapListString; - val['fieldEnum'] = _$GreekEnumMap[instance.fieldEnum]; - return val; -} - -T _$enumDecode( - Map enumValues, - dynamic source, { - T unknownValue, +K _$enumDecode( + Map enumValues, + Object? source, { + K? unknownValue, }) { if (source == null) { - throw ArgumentError('A value must be provided. Supported values: ' - '${enumValues.values.join(', ')}'); + throw ArgumentError( + 'A value must be provided. Supported values: ' + '${enumValues.values.join(', ')}', + ); } - final value = enumValues.entries - .singleWhere((e) => e.value == source, orElse: () => null) - ?.key; - - if (value == null && unknownValue == null) { - throw ArgumentError('`$source` is not one of the supported values: ' - '${enumValues.values.join(', ')}'); - } - return value ?? unknownValue; + return enumValues.entries.singleWhere( + (e) => e.value == source, + orElse: () { + if (unknownValue == null) { + throw ArgumentError( + '`$source` is not one of the supported values: ' + '${enumValues.values.join(', ')}', + ); + } + return MapEntry(unknownValue, enumValues.values.first); + }, + ).key; } -T _$enumDecodeNullable( - Map enumValues, +K? _$enumDecodeNullable( + Map enumValues, dynamic source, { - T unknownValue, + K? unknownValue, }) { if (source == null) { return null; } - return _$enumDecode(enumValues, source, unknownValue: unknownValue); + return _$enumDecode(enumValues, source, unknownValue: unknownValue); } const _$GreekEnumMap = { diff --git a/json_serializable/test/default_value/default_value_interface.dart b/json_serializable/test/default_value/default_value_interface.dart index 957889694..65076e6eb 100644 --- a/json_serializable/test/default_value/default_value_interface.dart +++ b/json_serializable/test/default_value/default_value_interface.dart @@ -2,9 +2,7 @@ // 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. -// Copyright (c) 2018, 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. +// @dart=2.12 abstract class DefaultValue { bool fieldBool; @@ -19,6 +17,21 @@ abstract class DefaultValue { Map fieldMapSimple; Map> fieldMapListString; Greek fieldEnum; + + DefaultValue( + this.fieldBool, + this.fieldString, + this.fieldInt, + this.fieldDouble, + this.fieldListEmpty, + this.fieldSetEmpty, + this.fieldMapEmpty, + this.fieldListSimple, + this.fieldSetSimple, + this.fieldMapSimple, + this.fieldMapListString, + this.fieldEnum, + ); } enum Greek { alpha, beta, gamma, delta } diff --git a/json_serializable/test/default_value/default_value_test.dart b/json_serializable/test/default_value/default_value_test.dart index 00ef236ad..8a0a83ff1 100644 --- a/json_serializable/test/default_value/default_value_test.dart +++ b/json_serializable/test/default_value/default_value_test.dart @@ -2,6 +2,8 @@ // 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. +// @dart=2.12 + import 'package:test/test.dart'; import '../test_utils.dart'; diff --git a/json_serializable/test/generic_files/generic_argument_factories.dart b/json_serializable/test/generic_files/generic_argument_factories.dart index 47d9987cf..cae60d363 100644 --- a/json_serializable/test/generic_files/generic_argument_factories.dart +++ b/json_serializable/test/generic_files/generic_argument_factories.dart @@ -2,6 +2,8 @@ // 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. +// @dart=2.12 + import 'package:json_annotation/json_annotation.dart'; part 'generic_argument_factories.g.dart'; @@ -22,8 +24,8 @@ class GenericClassWithHelpers { factory GenericClassWithHelpers.fromJson( Map json, - T Function(Object json) fromJsonT, - S Function(Object json) fromJsonS, + T Function(Object? json) fromJsonT, + S Function(Object? json) fromJsonS, ) => _$GenericClassWithHelpersFromJson(json, fromJsonT, fromJsonS); diff --git a/json_serializable/test/generic_files/generic_argument_factories.g.dart b/json_serializable/test/generic_files/generic_argument_factories.g.dart index b88167ada..a41ccc411 100644 --- a/json_serializable/test/generic_files/generic_argument_factories.g.dart +++ b/json_serializable/test/generic_files/generic_argument_factories.g.dart @@ -1,4 +1,5 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// @dart=2.12 part of 'generic_argument_factories.dart'; @@ -8,13 +9,13 @@ part of 'generic_argument_factories.dart'; GenericClassWithHelpers _$GenericClassWithHelpersFromJson( Map json, - T Function(Object json) fromJsonT, - S Function(Object json) fromJsonS, + T Function(Object? json) fromJsonT, + S Function(Object? json) fromJsonS, ) { return GenericClassWithHelpers( fromJsonT(json['value']), - (json['list'] as List)?.map(fromJsonT)?.toList(), - (json['someSet'] as List)?.map(fromJsonS)?.toSet(), + (json['list'] as List).map(fromJsonT).toList(), + (json['someSet'] as List).map(fromJsonS).toSet(), ); } @@ -25,35 +26,29 @@ Map _$GenericClassWithHelpersToJson( ) => { 'value': toJsonT(instance.value), - 'list': instance.list?.map(toJsonT)?.toList(), - 'someSet': instance.someSet?.map(toJsonS)?.toList(), + 'list': instance.list.map(toJsonT).toList(), + 'someSet': instance.someSet.map(toJsonS).toList(), }; ConcreteClass _$ConcreteClassFromJson(Map json) { return ConcreteClass( - json['value'] == null - ? null - : GenericClassWithHelpers.fromJson( - json['value'] as Map, - (value) => value as int, - (value) => value as String), - json['value2'] == null - ? null - : GenericClassWithHelpers.fromJson( - json['value2'] as Map, - (value) => (value as num)?.toDouble(), - (value) => value == null ? null : BigInt.parse(value as String)), + GenericClassWithHelpers.fromJson(json['value'] as Map, + (value) => value as int, (value) => value as String), + GenericClassWithHelpers.fromJson( + json['value2'] as Map, + (value) => (value as num).toDouble(), + (value) => BigInt.parse(value as String)), ); } Map _$ConcreteClassToJson(ConcreteClass instance) => { - 'value': instance.value?.toJson( + 'value': instance.value.toJson( (value) => value, (value) => value, ), - 'value2': instance.value2?.toJson( + 'value2': instance.value2.toJson( (value) => value, - (value) => value?.toString(), + (value) => value.toString(), ), }; diff --git a/json_serializable/test/generic_files/generic_class.dart b/json_serializable/test/generic_files/generic_class.dart index b7cdf649c..4b55add02 100644 --- a/json_serializable/test/generic_files/generic_class.dart +++ b/json_serializable/test/generic_files/generic_class.dart @@ -2,6 +2,8 @@ // 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. +// @dart=2.12 + import 'package:json_annotation/json_annotation.dart'; part 'generic_class.g.dart'; @@ -9,19 +11,19 @@ part 'generic_class.g.dart'; @JsonSerializable() class GenericClass { @JsonKey(fromJson: _dataFromJson, toJson: _dataToJson) - Object fieldObject; + Object? fieldObject; @JsonKey(fromJson: _dataFromJson, toJson: _dataToJson) dynamic fieldDynamic; @JsonKey(fromJson: _dataFromJson, toJson: _dataToJson) - int fieldInt; + int? fieldInt; @JsonKey(fromJson: _dataFromJson, toJson: _dataToJson) - T fieldT; + T? fieldT; @JsonKey(fromJson: _dataFromJson, toJson: _dataToJson) - S fieldS; + S? fieldS; GenericClass(); @@ -31,11 +33,11 @@ class GenericClass { Map toJson() => _$GenericClassToJson(this); static T _dataFromJson(Map input, - [S other1, U other2]) => + [S? other1, U? other2]) => input['value'] as T; static Map _dataToJson(T input, - [S other1, U other2]) => + [S? other1, U? other2]) => {'value': input}; } @@ -44,23 +46,23 @@ class GenericClass { @_DurationListMillisecondConverter() class GenericClassWithConverter { @_SimpleConverter() - Object fieldObject; + Object? fieldObject; @_SimpleConverter() dynamic fieldDynamic; @_SimpleConverter() - int fieldInt; + int? fieldInt; @_SimpleConverter() - T fieldT; + T? fieldT; @_SimpleConverter() - S fieldS; + S? fieldS; - Duration duration; + Duration? duration; - List listDuration; + List? listDuration; GenericClassWithConverter(); @@ -80,25 +82,26 @@ class _SimpleConverter implements JsonConverter> { Map toJson(T object) => {'value': object}; } -class _DurationMillisecondConverter implements JsonConverter { +class _DurationMillisecondConverter implements JsonConverter { const _DurationMillisecondConverter.named(); @override - Duration fromJson(int json) => + Duration? fromJson(int? json) => json == null ? null : Duration(milliseconds: json); @override - int toJson(Duration object) => object?.inMilliseconds; + int? toJson(Duration? object) => object?.inMilliseconds; } class _DurationListMillisecondConverter - implements JsonConverter, int> { + implements JsonConverter?, int?> { const _DurationListMillisecondConverter(); @override - List fromJson(int json) => [Duration(milliseconds: json)]; + List? fromJson(int? json) => + json == null ? null : [Duration(milliseconds: json)]; @override - int toJson(List object) => + int? toJson(List? object) => object?.fold(0, (sum, obj) => sum + obj.inMilliseconds); } diff --git a/json_serializable/test/generic_files/generic_class.g.dart b/json_serializable/test/generic_files/generic_class.g.dart index ae3c03aad..2ef18b32d 100644 --- a/json_serializable/test/generic_files/generic_class.g.dart +++ b/json_serializable/test/generic_files/generic_class.g.dart @@ -1,4 +1,5 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// @dart=2.12 part of 'generic_class.dart'; @@ -37,15 +38,15 @@ GenericClassWithConverter return GenericClassWithConverter() ..fieldObject = json['fieldObject'] ..fieldDynamic = json['fieldDynamic'] - ..fieldInt = json['fieldInt'] as int + ..fieldInt = json['fieldInt'] as int? ..fieldT = - _SimpleConverter().fromJson(json['fieldT'] as Map) + _SimpleConverter().fromJson(json['fieldT'] as Map) ..fieldS = - _SimpleConverter().fromJson(json['fieldS'] as Map) + _SimpleConverter().fromJson(json['fieldS'] as Map) ..duration = const _DurationMillisecondConverter.named() - .fromJson(json['duration'] as int) + .fromJson(json['duration'] as int?) ..listDuration = const _DurationListMillisecondConverter() - .fromJson(json['listDuration'] as int); + .fromJson(json['listDuration'] as int?); } Map _$GenericClassWithConverterToJson( @@ -54,8 +55,8 @@ Map _$GenericClassWithConverterToJson( 'fieldObject': instance.fieldObject, 'fieldDynamic': instance.fieldDynamic, 'fieldInt': instance.fieldInt, - 'fieldT': _SimpleConverter().toJson(instance.fieldT), - 'fieldS': _SimpleConverter().toJson(instance.fieldS), + 'fieldT': _SimpleConverter().toJson(instance.fieldT), + 'fieldS': _SimpleConverter().toJson(instance.fieldS), 'duration': const _DurationMillisecondConverter.named().toJson(instance.duration), 'listDuration': const _DurationListMillisecondConverter() diff --git a/json_serializable/test/generic_files/generic_test.dart b/json_serializable/test/generic_files/generic_test.dart index 19c43758a..dc83e871b 100644 --- a/json_serializable/test/generic_files/generic_test.dart +++ b/json_serializable/test/generic_files/generic_test.dart @@ -2,6 +2,8 @@ // 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. +// @dart=2.12 + import 'dart:convert'; import 'package:test/test.dart'; @@ -63,7 +65,7 @@ void main() { {const Duration(milliseconds: 3), const Duration(milliseconds: 4)}, ); - String encodeDateTime(DateTime value) => value?.toIso8601String(); + String encodeDateTime(DateTime value) => value.toIso8601String(); int encodeDuration(Duration value) => value.inMilliseconds; final encodedJson = loudEncode( diff --git a/json_serializable/test/integration/integration_test.dart b/json_serializable/test/integration/integration_test.dart index fa51cfbe2..b8d6ac115 100644 --- a/json_serializable/test/integration/integration_test.dart +++ b/json_serializable/test/integration/integration_test.dart @@ -2,6 +2,8 @@ // 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. +// @dart=2.12 + import 'package:test/test.dart'; import '../test_utils.dart'; @@ -17,15 +19,6 @@ void main() { roundTripObject(p, (json) => Person.fromJson(json)); } - test('null', () { - roundTripPerson(Person(null, null, null)); - }); - - test('empty', () { - roundTripPerson(Person('', '', null, - middleName: '', dateOfBirth: DateTime.fromMillisecondsSinceEpoch(0))); - }); - test('now', () { roundTripPerson(Person('a', 'b', Category.charmed, middleName: 'c', dateOfBirth: DateTime.now())); @@ -37,13 +30,17 @@ void main() { }); test('empty json', () { - final person = Person.fromJson({}); + final person = Person.fromJson({ + 'firstName': 'a', + 'lastName': 'b', + '\$house': 'top', + }); expect(person.dateOfBirth, isNull); roundTripPerson(person); }); test('enum map', () { - final person = Person(null, null, null) + final person = Person('', '', Category.bottom) ..houseMap = {'bob': Category.strange} ..categoryCounts = {Category.strange: 1}; expect(person.dateOfBirth, isNull); @@ -92,7 +89,10 @@ void main() { test('required, but missing enum value fails', () { expect( - () => Order.fromJson({}), + () => Person.fromJson({ + 'firstName': 'a', + 'lastName': 'b', + }), _throwsArgumentError('A value must be provided. Supported values: ' 'top, bottom, strange, charmed, up, down, not_discovered_yet')); }); @@ -111,7 +111,6 @@ void main() { ..altPlatforms = { 'u': Platform.undefined, 'f': Platform.foo, - 'null': null }; roundTripOrder(order); @@ -124,7 +123,6 @@ void main() { ..altPlatforms = { 'u': Platform.undefined, 'f': Platform.foo, - 'null': null } ..homepage = Uri.parse('https://dart.dev'); @@ -238,7 +236,7 @@ void main() { test('support ints as doubles', () { final value = { - 'doubles': [0, 0.0, null], + 'doubles': [0, 0.0], 'nnDoubles': [0, 0.0] }; diff --git a/json_serializable/test/integration/json_test_common.dart b/json_serializable/test/integration/json_test_common.dart index 295d6df85..931d0ca14 100644 --- a/json_serializable/test/integration/json_test_common.dart +++ b/json_serializable/test/integration/json_test_common.dart @@ -2,6 +2,8 @@ // 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. +// @dart=2.12 + import 'dart:collection'; import 'package:collection/collection.dart'; @@ -32,15 +34,15 @@ enum StatusCode { unknown, } -Duration durationFromInt(int ms) => +Duration? durationFromInt(int? ms) => ms == null ? null : Duration(milliseconds: ms); -int durationToInt(Duration duration) => duration?.inMilliseconds; +int? durationToInt(Duration? duration) => duration?.inMilliseconds; -DateTime dateTimeFromEpochUs(int us) => +DateTime? dateTimeFromEpochUs(int? us) => us == null ? null : DateTime.fromMicrosecondsSinceEpoch(us); -int dateTimeToEpochUs(DateTime dateTime) => dateTime?.microsecondsSinceEpoch; +int? dateTimeToEpochUs(DateTime? dateTime) => dateTime?.microsecondsSinceEpoch; bool deepEquals(a, b) => const DeepCollectionEquality().equals(a, b); @@ -67,7 +69,7 @@ class Platform { } abstract class ItemCore { - final int price; + final int? price; ItemCore(this.price); } @@ -75,7 +77,7 @@ abstract class ItemCore { class MyList extends ListBase { final List _data; - MyList(Iterable source) : _data = source.toList() ?? []; + MyList(Iterable source) : _data = source.toList(); factory MyList.fromJson(List items) => MyList(items); diff --git a/json_serializable/test/integration/json_test_example.dart b/json_serializable/test/integration/json_test_example.dart index f23831961..4a1fcec0f 100644 --- a/json_serializable/test/integration/json_test_example.dart +++ b/json_serializable/test/integration/json_test_example.dart @@ -2,6 +2,8 @@ // 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. +// @dart=2.12 + // ignore_for_file: hash_and_equals import 'dart:collection'; @@ -13,17 +15,18 @@ part 'json_test_example.g.dart'; @JsonSerializable() class Person { - final String firstName, middleName, lastName; - final DateTime dateOfBirth; + final String firstName, lastName; + final String? middleName; + final DateTime? dateOfBirth; @JsonKey(name: '\$house') final Category house; - Order order; + Order? order; - MyList customOrders; + MyList? customOrders; - Map houseMap; - Map categoryCounts; + Map? houseMap; + Map? categoryCounts; Person(this.firstName, this.lastName, this.house, {this.middleName, this.dateOfBirth}); @@ -47,41 +50,39 @@ class Person { class Order { /// Used to test that `disallowNullValues: true` forces `includeIfNull: false` @JsonKey(disallowNullValue: true) - int count; - bool isRushed; + int? count; + bool? isRushed; - Duration duration; + Duration? duration; - @JsonKey(nullable: false) - final Category category; - final UnmodifiableListView items; - Platform platform; - Map altPlatforms; + final Category? category; + final UnmodifiableListView? items; + Platform? platform; + Map? altPlatforms; - Uri homepage; + Uri? homepage; @JsonKey( name: 'status_code', defaultValue: StatusCode.success, - nullable: true, unknownEnumValue: StatusCode.unknown, ) - StatusCode statusCode; + StatusCode? statusCode; @JsonKey(ignore: true) - String get platformValue => platform?.description; + String get platformValue => platform!.description; set platformValue(String value) { throw UnimplementedError('not impld'); } // Ignored getter without value set in ctor - int get price => items.fold(0, (total, item) => item.price + total); + int get price => items!.fold(0, (total, item) => item.price! + total); @JsonKey(ignore: true) - bool shouldBeCached; + bool? shouldBeCached; - Order(this.category, [Iterable items]) + Order(this.category, [Iterable? items]) : items = UnmodifiableListView( List.unmodifiable(items ?? const [])); @@ -101,11 +102,11 @@ class Order { @JsonSerializable() class Item extends ItemCore { @JsonKey(includeIfNull: false, name: 'item-number') - int itemNumber; - List saleDates; - List rates; + int? itemNumber; + List? saleDates; + List? rates; - Item([int price]) : super(price); + Item([int? price]) : super(price); factory Item.fromJson(Map json) => _$ItemFromJson(json); @@ -121,18 +122,17 @@ class Item extends ItemCore { @JsonSerializable() class Numbers { - List ints; - List nums; - List doubles; + List? ints; + List? nums; + List? doubles; - @JsonKey(nullable: false) - List nnDoubles; + List? nnDoubles; @JsonKey(fromJson: durationFromInt, toJson: durationToInt) - Duration duration; + Duration? duration; @JsonKey(fromJson: dateTimeFromEpochUs, toJson: dateTimeToEpochUs) - DateTime date; + DateTime? date; Numbers(); @@ -154,10 +154,10 @@ class Numbers { @JsonSerializable() class MapKeyVariety { - Map intIntMap; - Map uriIntMap; - Map dateTimeIntMap; - Map bigIntMap; + Map? intIntMap; + Map? uriIntMap; + Map? dateTimeIntMap; + Map? bigIntMap; MapKeyVariety(); @@ -178,16 +178,16 @@ class MapKeyVariety { @JsonSerializable(createToJson: false) class UnknownEnumValue { @JsonKey(unknownEnumValue: Category.notDiscoveredYet) - Category enumValue; + late Category enumValue; @JsonKey(unknownEnumValue: Category.notDiscoveredYet) - Iterable enumIterable; + late Iterable enumIterable; @JsonKey(unknownEnumValue: Category.notDiscoveredYet) - List enumList; + late List enumList; @JsonKey(unknownEnumValue: Category.notDiscoveredYet) - Set enumSet; + late Set enumSet; UnknownEnumValue(); diff --git a/json_serializable/test/integration/json_test_example.g.dart b/json_serializable/test/integration/json_test_example.g.dart index 4ec605cc3..a9f5d28e2 100644 --- a/json_serializable/test/integration/json_test_example.g.dart +++ b/json_serializable/test/integration/json_test_example.g.dart @@ -1,4 +1,5 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// @dart=2.12 part of 'json_test_example.dart'; @@ -10,8 +11,8 @@ Person _$PersonFromJson(Map json) { return Person( json['firstName'] as String, json['lastName'] as String, - _$enumDecodeNullable(_$CategoryEnumMap, json[r'$house']), - middleName: json['middleName'] as String, + _$enumDecode(_$CategoryEnumMap, json[r'$house']), + middleName: json['middleName'] as String?, dateOfBirth: json['dateOfBirth'] == null ? null : DateTime.parse(json['dateOfBirth'] as String), @@ -21,22 +22,21 @@ Person _$PersonFromJson(Map json) { : Order.fromJson(json['order'] as Map) ..customOrders = json['customOrders'] == null ? null - : MyList.fromJson((json['customOrders'] as List) - ?.map((e) => - e == null ? null : Order.fromJson(e as Map)) - ?.toList()) - ..houseMap = (json['houseMap'] as Map)?.map( - (k, e) => MapEntry(k, _$enumDecodeNullable(_$CategoryEnumMap, e)), + : MyList.fromJson((json['customOrders'] as List) + .map((e) => Order.fromJson(e as Map)) + .toList()) + ..houseMap = (json['houseMap'] as Map?)?.map( + (k, e) => MapEntry(k, _$enumDecode(_$CategoryEnumMap, e)), ) - ..categoryCounts = (json['categoryCounts'] as Map)?.map( - (k, e) => MapEntry(_$enumDecodeNullable(_$CategoryEnumMap, k), e as int), + ..categoryCounts = (json['categoryCounts'] as Map?)?.map( + (k, e) => MapEntry(_$enumDecode(_$CategoryEnumMap, k), e as int), ); } Map _$PersonToJson(Person instance) => { 'firstName': instance.firstName, - 'middleName': instance.middleName, 'lastName': instance.lastName, + 'middleName': instance.middleName, 'dateOfBirth': instance.dateOfBirth?.toIso8601String(), r'$house': _$CategoryEnumMap[instance.house], 'order': instance.order, @@ -47,36 +47,30 @@ Map _$PersonToJson(Person instance) => { ?.map((k, e) => MapEntry(_$CategoryEnumMap[k], e)), }; -T _$enumDecode( - Map enumValues, - dynamic source, { - T unknownValue, +K _$enumDecode( + Map enumValues, + Object? source, { + K? unknownValue, }) { if (source == null) { - throw ArgumentError('A value must be provided. Supported values: ' - '${enumValues.values.join(', ')}'); - } - - final value = enumValues.entries - .singleWhere((e) => e.value == source, orElse: () => null) - ?.key; - - if (value == null && unknownValue == null) { - throw ArgumentError('`$source` is not one of the supported values: ' - '${enumValues.values.join(', ')}'); + throw ArgumentError( + 'A value must be provided. Supported values: ' + '${enumValues.values.join(', ')}', + ); } - return value ?? unknownValue; -} -T _$enumDecodeNullable( - Map enumValues, - dynamic source, { - T unknownValue, -}) { - if (source == null) { - return null; - } - return _$enumDecode(enumValues, source, unknownValue: unknownValue); + return enumValues.entries.singleWhere( + (e) => e.value == source, + orElse: () { + if (unknownValue == null) { + throw ArgumentError( + '`$source` is not one of the supported values: ' + '${enumValues.values.join(', ')}', + ); + } + return MapEntry(unknownValue, enumValues.values.first); + }, + ).key; } const _$CategoryEnumMap = { @@ -92,20 +86,20 @@ const _$CategoryEnumMap = { Order _$OrderFromJson(Map json) { $checkKeys(json, disallowNullValues: const ['count']); return Order( - _$enumDecode(_$CategoryEnumMap, json['category']), - (json['items'] as List)?.map( - (e) => e == null ? null : Item.fromJson(e as Map)), + _$enumDecodeNullable(_$CategoryEnumMap, json['category']), + (json['items'] as List?) + ?.map((e) => Item.fromJson(e as Map)), ) - ..count = json['count'] as int - ..isRushed = json['isRushed'] as bool + ..count = json['count'] as int? + ..isRushed = json['isRushed'] as bool? ..duration = json['duration'] == null ? null : Duration(microseconds: json['duration'] as int) ..platform = json['platform'] == null ? null : Platform.fromJson(json['platform'] as String) - ..altPlatforms = (json['altPlatforms'] as Map)?.map( - (k, e) => MapEntry(k, e == null ? null : Platform.fromJson(e as String)), + ..altPlatforms = (json['altPlatforms'] as Map?)?.map( + (k, e) => MapEntry(k, Platform.fromJson(e as String)), ) ..homepage = json['homepage'] == null ? null : Uri.parse(json['homepage'] as String) @@ -136,6 +130,17 @@ Map _$OrderToJson(Order instance) { return val; } +K? _$enumDecodeNullable( + Map enumValues, + dynamic source, { + K? unknownValue, +}) { + if (source == null) { + return null; + } + return _$enumDecode(enumValues, source, unknownValue: unknownValue); +} + const _$StatusCodeEnumMap = { StatusCode.success: 200, StatusCode.notFound: 404, @@ -145,13 +150,13 @@ const _$StatusCodeEnumMap = { Item _$ItemFromJson(Map json) { return Item( - json['price'] as int, + json['price'] as int?, ) - ..itemNumber = json['item-number'] as int - ..saleDates = (json['saleDates'] as List) - ?.map((e) => e == null ? null : DateTime.parse(e as String)) - ?.toList() - ..rates = (json['rates'] as List)?.map((e) => e as int)?.toList(); + ..itemNumber = json['item-number'] as int? + ..saleDates = (json['saleDates'] as List?) + ?.map((e) => DateTime.parse(e as String)) + .toList() + ..rates = (json['rates'] as List?)?.map((e) => e as int).toList(); } Map _$ItemToJson(Item instance) { @@ -167,21 +172,23 @@ Map _$ItemToJson(Item instance) { writeNotNull('item-number', instance.itemNumber); val['saleDates'] = - instance.saleDates?.map((e) => e?.toIso8601String())?.toList(); + instance.saleDates?.map((e) => e.toIso8601String()).toList(); val['rates'] = instance.rates; return val; } Numbers _$NumbersFromJson(Map json) { return Numbers() - ..ints = (json['ints'] as List)?.map((e) => e as int)?.toList() - ..nums = (json['nums'] as List)?.map((e) => e as num)?.toList() - ..doubles = - (json['doubles'] as List)?.map((e) => (e as num)?.toDouble())?.toList() - ..nnDoubles = - (json['nnDoubles'] as List).map((e) => (e as num).toDouble()).toList() - ..duration = durationFromInt(json['duration'] as int) - ..date = dateTimeFromEpochUs(json['date'] as int); + ..ints = (json['ints'] as List?)?.map((e) => e as int).toList() + ..nums = (json['nums'] as List?)?.map((e) => e as num).toList() + ..doubles = (json['doubles'] as List?) + ?.map((e) => (e as num).toDouble()) + .toList() + ..nnDoubles = (json['nnDoubles'] as List?) + ?.map((e) => (e as num).toDouble()) + .toList() + ..duration = durationFromInt(json['duration'] as int?) + ..date = dateTimeFromEpochUs(json['date'] as int?); } Map _$NumbersToJson(Numbers instance) => { @@ -195,16 +202,16 @@ Map _$NumbersToJson(Numbers instance) => { MapKeyVariety _$MapKeyVarietyFromJson(Map json) { return MapKeyVariety() - ..intIntMap = (json['intIntMap'] as Map)?.map( + ..intIntMap = (json['intIntMap'] as Map?)?.map( (k, e) => MapEntry(int.parse(k), e as int), ) - ..uriIntMap = (json['uriIntMap'] as Map)?.map( + ..uriIntMap = (json['uriIntMap'] as Map?)?.map( (k, e) => MapEntry(Uri.parse(k), e as int), ) - ..dateTimeIntMap = (json['dateTimeIntMap'] as Map)?.map( + ..dateTimeIntMap = (json['dateTimeIntMap'] as Map?)?.map( (k, e) => MapEntry(DateTime.parse(k), e as int), ) - ..bigIntMap = (json['bigIntMap'] as Map)?.map( + ..bigIntMap = (json['bigIntMap'] as Map?)?.map( (k, e) => MapEntry(BigInt.parse(k), e as int), ); } @@ -220,17 +227,17 @@ Map _$MapKeyVarietyToJson(MapKeyVariety instance) => UnknownEnumValue _$UnknownEnumValueFromJson(Map json) { return UnknownEnumValue() - ..enumValue = _$enumDecodeNullable(_$CategoryEnumMap, json['enumValue'], + ..enumValue = _$enumDecode(_$CategoryEnumMap, json['enumValue'], unknownValue: Category.notDiscoveredYet) - ..enumIterable = (json['enumIterable'] as List)?.map((e) => - _$enumDecodeNullable(_$CategoryEnumMap, e, + ..enumIterable = (json['enumIterable'] as List).map((e) => + _$enumDecode(_$CategoryEnumMap, e, unknownValue: Category.notDiscoveredYet)) - ..enumList = (json['enumList'] as List) - ?.map((e) => _$enumDecodeNullable(_$CategoryEnumMap, e, + ..enumList = (json['enumList'] as List) + .map((e) => _$enumDecode(_$CategoryEnumMap, e, unknownValue: Category.notDiscoveredYet)) - ?.toList() - ..enumSet = (json['enumSet'] as List) - ?.map((e) => _$enumDecodeNullable(_$CategoryEnumMap, e, + .toList() + ..enumSet = (json['enumSet'] as List) + .map((e) => _$enumDecode(_$CategoryEnumMap, e, unknownValue: Category.notDiscoveredYet)) - ?.toSet(); + .toSet(); } diff --git a/json_serializable/test/integration/json_test_example.g_any_map.dart b/json_serializable/test/integration/json_test_example.g_any_map.dart index f781d5b5c..1796bd37f 100644 --- a/json_serializable/test/integration/json_test_example.g_any_map.dart +++ b/json_serializable/test/integration/json_test_example.g_any_map.dart @@ -2,6 +2,8 @@ // 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. +// @dart=2.12 + // ignore_for_file: hash_and_equals import 'dart:collection'; @@ -15,17 +17,18 @@ part 'json_test_example.g_any_map.g.dart'; anyMap: true, ) class Person { - final String firstName, middleName, lastName; - final DateTime dateOfBirth; + final String firstName, lastName; + final String? middleName; + final DateTime? dateOfBirth; @JsonKey(name: '\$house') final Category house; - Order order; + Order? order; - MyList customOrders; + MyList? customOrders; - Map houseMap; - Map categoryCounts; + Map? houseMap; + Map? categoryCounts; Person(this.firstName, this.lastName, this.house, {this.middleName, this.dateOfBirth}); @@ -51,41 +54,39 @@ class Person { class Order { /// Used to test that `disallowNullValues: true` forces `includeIfNull: false` @JsonKey(disallowNullValue: true) - int count; - bool isRushed; + int? count; + bool? isRushed; - Duration duration; + Duration? duration; - @JsonKey(nullable: false) - final Category category; - final UnmodifiableListView items; - Platform platform; - Map altPlatforms; + final Category? category; + final UnmodifiableListView? items; + Platform? platform; + Map? altPlatforms; - Uri homepage; + Uri? homepage; @JsonKey( name: 'status_code', defaultValue: StatusCode.success, - nullable: true, unknownEnumValue: StatusCode.unknown, ) - StatusCode statusCode; + StatusCode? statusCode; @JsonKey(ignore: true) - String get platformValue => platform?.description; + String get platformValue => platform!.description; set platformValue(String value) { throw UnimplementedError('not impld'); } // Ignored getter without value set in ctor - int get price => items.fold(0, (total, item) => item.price + total); + int get price => items!.fold(0, (total, item) => item.price! + total); @JsonKey(ignore: true) - bool shouldBeCached; + bool? shouldBeCached; - Order(this.category, [Iterable items]) + Order(this.category, [Iterable? items]) : items = UnmodifiableListView( List.unmodifiable(items ?? const [])); @@ -107,11 +108,11 @@ class Order { ) class Item extends ItemCore { @JsonKey(includeIfNull: false, name: 'item-number') - int itemNumber; - List saleDates; - List rates; + int? itemNumber; + List? saleDates; + List? rates; - Item([int price]) : super(price); + Item([int? price]) : super(price); factory Item.fromJson(Map json) => _$ItemFromJson(json); @@ -129,18 +130,17 @@ class Item extends ItemCore { anyMap: true, ) class Numbers { - List ints; - List nums; - List doubles; + List? ints; + List? nums; + List? doubles; - @JsonKey(nullable: false) - List nnDoubles; + List? nnDoubles; @JsonKey(fromJson: durationFromInt, toJson: durationToInt) - Duration duration; + Duration? duration; @JsonKey(fromJson: dateTimeFromEpochUs, toJson: dateTimeToEpochUs) - DateTime date; + DateTime? date; Numbers(); @@ -164,10 +164,10 @@ class Numbers { anyMap: true, ) class MapKeyVariety { - Map intIntMap; - Map uriIntMap; - Map dateTimeIntMap; - Map bigIntMap; + Map? intIntMap; + Map? uriIntMap; + Map? dateTimeIntMap; + Map? bigIntMap; MapKeyVariety(); @@ -188,16 +188,16 @@ class MapKeyVariety { @JsonSerializable(anyMap: true, createToJson: false) class UnknownEnumValue { @JsonKey(unknownEnumValue: Category.notDiscoveredYet) - Category enumValue; + late Category enumValue; @JsonKey(unknownEnumValue: Category.notDiscoveredYet) - Iterable enumIterable; + late Iterable enumIterable; @JsonKey(unknownEnumValue: Category.notDiscoveredYet) - List enumList; + late List enumList; @JsonKey(unknownEnumValue: Category.notDiscoveredYet) - Set enumSet; + late Set enumSet; UnknownEnumValue(); diff --git a/json_serializable/test/integration/json_test_example.g_any_map.g.dart b/json_serializable/test/integration/json_test_example.g_any_map.g.dart index e4f24df48..ef4a6566d 100644 --- a/json_serializable/test/integration/json_test_example.g_any_map.g.dart +++ b/json_serializable/test/integration/json_test_example.g_any_map.g.dart @@ -1,4 +1,5 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// @dart=2.12 part of 'json_test_example.g_any_map.dart'; @@ -10,39 +11,32 @@ Person _$PersonFromJson(Map json) { return Person( json['firstName'] as String, json['lastName'] as String, - _$enumDecodeNullable(_$CategoryEnumMap, json[r'$house']), - middleName: json['middleName'] as String, + _$enumDecode(_$CategoryEnumMap, json[r'$house']), + middleName: json['middleName'] as String?, dateOfBirth: json['dateOfBirth'] == null ? null : DateTime.parse(json['dateOfBirth'] as String), ) ..order = json['order'] == null ? null - : Order.fromJson((json['order'] as Map)?.map( - (k, e) => MapEntry(k as String, e), - )) + : Order.fromJson(Map.from(json['order'] as Map)) ..customOrders = json['customOrders'] == null ? null - : MyList.fromJson((json['customOrders'] as List) - ?.map((e) => e == null - ? null - : Order.fromJson((e as Map)?.map( - (k, e) => MapEntry(k as String, e), - ))) - ?.toList()) - ..houseMap = (json['houseMap'] as Map)?.map( - (k, e) => - MapEntry(k as String, _$enumDecodeNullable(_$CategoryEnumMap, e)), + : MyList.fromJson((json['customOrders'] as List) + .map((e) => Order.fromJson(Map.from(e as Map))) + .toList()) + ..houseMap = (json['houseMap'] as Map?)?.map( + (k, e) => MapEntry(k as String, _$enumDecode(_$CategoryEnumMap, e)), ) - ..categoryCounts = (json['categoryCounts'] as Map)?.map( - (k, e) => MapEntry(_$enumDecodeNullable(_$CategoryEnumMap, k), e as int), + ..categoryCounts = (json['categoryCounts'] as Map?)?.map( + (k, e) => MapEntry(_$enumDecode(_$CategoryEnumMap, k), e as int), ); } Map _$PersonToJson(Person instance) => { 'firstName': instance.firstName, - 'middleName': instance.middleName, 'lastName': instance.lastName, + 'middleName': instance.middleName, 'dateOfBirth': instance.dateOfBirth?.toIso8601String(), r'$house': _$CategoryEnumMap[instance.house], 'order': instance.order, @@ -53,36 +47,30 @@ Map _$PersonToJson(Person instance) => { ?.map((k, e) => MapEntry(_$CategoryEnumMap[k], e)), }; -T _$enumDecode( - Map enumValues, - dynamic source, { - T unknownValue, +K _$enumDecode( + Map enumValues, + Object? source, { + K? unknownValue, }) { if (source == null) { - throw ArgumentError('A value must be provided. Supported values: ' - '${enumValues.values.join(', ')}'); + throw ArgumentError( + 'A value must be provided. Supported values: ' + '${enumValues.values.join(', ')}', + ); } - final value = enumValues.entries - .singleWhere((e) => e.value == source, orElse: () => null) - ?.key; - - if (value == null && unknownValue == null) { - throw ArgumentError('`$source` is not one of the supported values: ' - '${enumValues.values.join(', ')}'); - } - return value ?? unknownValue; -} - -T _$enumDecodeNullable( - Map enumValues, - dynamic source, { - T unknownValue, -}) { - if (source == null) { - return null; - } - return _$enumDecode(enumValues, source, unknownValue: unknownValue); + return enumValues.entries.singleWhere( + (e) => e.value == source, + orElse: () { + if (unknownValue == null) { + throw ArgumentError( + '`$source` is not one of the supported values: ' + '${enumValues.values.join(', ')}', + ); + } + return MapEntry(unknownValue, enumValues.values.first); + }, + ).key; } const _$CategoryEnumMap = { @@ -98,24 +86,20 @@ const _$CategoryEnumMap = { Order _$OrderFromJson(Map json) { $checkKeys(json, disallowNullValues: const ['count']); return Order( - _$enumDecode(_$CategoryEnumMap, json['category']), - (json['items'] as List)?.map((e) => e == null - ? null - : Item.fromJson((e as Map)?.map( - (k, e) => MapEntry(k as String, e), - ))), + _$enumDecodeNullable(_$CategoryEnumMap, json['category']), + (json['items'] as List?) + ?.map((e) => Item.fromJson(Map.from(e as Map))), ) - ..count = json['count'] as int - ..isRushed = json['isRushed'] as bool + ..count = json['count'] as int? + ..isRushed = json['isRushed'] as bool? ..duration = json['duration'] == null ? null : Duration(microseconds: json['duration'] as int) ..platform = json['platform'] == null ? null : Platform.fromJson(json['platform'] as String) - ..altPlatforms = (json['altPlatforms'] as Map)?.map( - (k, e) => MapEntry( - k as String, e == null ? null : Platform.fromJson(e as String)), + ..altPlatforms = (json['altPlatforms'] as Map?)?.map( + (k, e) => MapEntry(k as String, Platform.fromJson(e as String)), ) ..homepage = json['homepage'] == null ? null : Uri.parse(json['homepage'] as String) @@ -146,6 +130,17 @@ Map _$OrderToJson(Order instance) { return val; } +K? _$enumDecodeNullable( + Map enumValues, + dynamic source, { + K? unknownValue, +}) { + if (source == null) { + return null; + } + return _$enumDecode(enumValues, source, unknownValue: unknownValue); +} + const _$StatusCodeEnumMap = { StatusCode.success: 200, StatusCode.notFound: 404, @@ -155,13 +150,13 @@ const _$StatusCodeEnumMap = { Item _$ItemFromJson(Map json) { return Item( - json['price'] as int, + json['price'] as int?, ) - ..itemNumber = json['item-number'] as int - ..saleDates = (json['saleDates'] as List) - ?.map((e) => e == null ? null : DateTime.parse(e as String)) - ?.toList() - ..rates = (json['rates'] as List)?.map((e) => e as int)?.toList(); + ..itemNumber = json['item-number'] as int? + ..saleDates = (json['saleDates'] as List?) + ?.map((e) => DateTime.parse(e as String)) + .toList() + ..rates = (json['rates'] as List?)?.map((e) => e as int).toList(); } Map _$ItemToJson(Item instance) { @@ -177,21 +172,23 @@ Map _$ItemToJson(Item instance) { writeNotNull('item-number', instance.itemNumber); val['saleDates'] = - instance.saleDates?.map((e) => e?.toIso8601String())?.toList(); + instance.saleDates?.map((e) => e.toIso8601String()).toList(); val['rates'] = instance.rates; return val; } Numbers _$NumbersFromJson(Map json) { return Numbers() - ..ints = (json['ints'] as List)?.map((e) => e as int)?.toList() - ..nums = (json['nums'] as List)?.map((e) => e as num)?.toList() - ..doubles = - (json['doubles'] as List)?.map((e) => (e as num)?.toDouble())?.toList() - ..nnDoubles = - (json['nnDoubles'] as List).map((e) => (e as num).toDouble()).toList() - ..duration = durationFromInt(json['duration'] as int) - ..date = dateTimeFromEpochUs(json['date'] as int); + ..ints = (json['ints'] as List?)?.map((e) => e as int).toList() + ..nums = (json['nums'] as List?)?.map((e) => e as num).toList() + ..doubles = (json['doubles'] as List?) + ?.map((e) => (e as num).toDouble()) + .toList() + ..nnDoubles = (json['nnDoubles'] as List?) + ?.map((e) => (e as num).toDouble()) + .toList() + ..duration = durationFromInt(json['duration'] as int?) + ..date = dateTimeFromEpochUs(json['date'] as int?); } Map _$NumbersToJson(Numbers instance) => { @@ -205,16 +202,16 @@ Map _$NumbersToJson(Numbers instance) => { MapKeyVariety _$MapKeyVarietyFromJson(Map json) { return MapKeyVariety() - ..intIntMap = (json['intIntMap'] as Map)?.map( + ..intIntMap = (json['intIntMap'] as Map?)?.map( (k, e) => MapEntry(int.parse(k as String), e as int), ) - ..uriIntMap = (json['uriIntMap'] as Map)?.map( + ..uriIntMap = (json['uriIntMap'] as Map?)?.map( (k, e) => MapEntry(Uri.parse(k as String), e as int), ) - ..dateTimeIntMap = (json['dateTimeIntMap'] as Map)?.map( + ..dateTimeIntMap = (json['dateTimeIntMap'] as Map?)?.map( (k, e) => MapEntry(DateTime.parse(k as String), e as int), ) - ..bigIntMap = (json['bigIntMap'] as Map)?.map( + ..bigIntMap = (json['bigIntMap'] as Map?)?.map( (k, e) => MapEntry(BigInt.parse(k as String), e as int), ); } @@ -230,17 +227,17 @@ Map _$MapKeyVarietyToJson(MapKeyVariety instance) => UnknownEnumValue _$UnknownEnumValueFromJson(Map json) { return UnknownEnumValue() - ..enumValue = _$enumDecodeNullable(_$CategoryEnumMap, json['enumValue'], + ..enumValue = _$enumDecode(_$CategoryEnumMap, json['enumValue'], unknownValue: Category.notDiscoveredYet) - ..enumIterable = (json['enumIterable'] as List)?.map((e) => - _$enumDecodeNullable(_$CategoryEnumMap, e, + ..enumIterable = (json['enumIterable'] as List).map((e) => + _$enumDecode(_$CategoryEnumMap, e, unknownValue: Category.notDiscoveredYet)) - ..enumList = (json['enumList'] as List) - ?.map((e) => _$enumDecodeNullable(_$CategoryEnumMap, e, + ..enumList = (json['enumList'] as List) + .map((e) => _$enumDecode(_$CategoryEnumMap, e, unknownValue: Category.notDiscoveredYet)) - ?.toList() - ..enumSet = (json['enumSet'] as List) - ?.map((e) => _$enumDecodeNullable(_$CategoryEnumMap, e, + .toList() + ..enumSet = (json['enumSet'] as List) + .map((e) => _$enumDecode(_$CategoryEnumMap, e, unknownValue: Category.notDiscoveredYet)) - ?.toSet(); + .toSet(); } diff --git a/json_serializable/test/integration/json_test_example.g_non_nullable.dart b/json_serializable/test/integration/json_test_example.g_non_nullable.dart deleted file mode 100644 index cb9928180..000000000 --- a/json_serializable/test/integration/json_test_example.g_non_nullable.dart +++ /dev/null @@ -1,206 +0,0 @@ -// Copyright (c) 2018, 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. - -// ignore_for_file: hash_and_equals -import 'dart:collection'; - -import 'package:json_annotation/json_annotation.dart'; - -import 'json_test_common.dart'; - -part 'json_test_example.g_non_nullable.g.dart'; - -@JsonSerializable( - nullable: false, -) -class Person { - final String firstName, middleName, lastName; - final DateTime dateOfBirth; - @JsonKey(name: '\$house') - final Category house; - - Order order; - - MyList customOrders; - - Map houseMap; - Map categoryCounts; - - Person(this.firstName, this.lastName, this.house, - {this.middleName, this.dateOfBirth}); - - factory Person.fromJson(Map json) => _$PersonFromJson(json); - - Map toJson() => _$PersonToJson(this); - - @override - bool operator ==(Object other) => - other is Person && - firstName == other.firstName && - middleName == other.middleName && - lastName == other.lastName && - dateOfBirth == other.dateOfBirth && - house == other.house && - deepEquals(houseMap, other.houseMap); -} - -@JsonSerializable( - nullable: false, -) -class Order { - /// Used to test that `disallowNullValues: true` forces `includeIfNull: false` - @JsonKey(disallowNullValue: true) - int count; - bool isRushed; - - Duration duration; - - @JsonKey(nullable: false) - final Category category; - final UnmodifiableListView items; - Platform platform; - Map altPlatforms; - - Uri homepage; - - @JsonKey( - name: 'status_code', - defaultValue: StatusCode.success, - nullable: true, - unknownEnumValue: StatusCode.unknown, - ) - StatusCode statusCode; - - @JsonKey(ignore: true) - String get platformValue => platform?.description; - - set platformValue(String value) { - throw UnimplementedError('not impld'); - } - - // Ignored getter without value set in ctor - int get price => items.fold(0, (total, item) => item.price + total); - - @JsonKey(ignore: true) - bool shouldBeCached; - - Order(this.category, [Iterable items]) - : items = UnmodifiableListView( - List.unmodifiable(items ?? const [])); - - factory Order.fromJson(Map json) => _$OrderFromJson(json); - - Map toJson() => _$OrderToJson(this); - - @override - bool operator ==(Object other) => - other is Order && - count == other.count && - isRushed == other.isRushed && - deepEquals(items, other.items) && - deepEquals(altPlatforms, other.altPlatforms); -} - -@JsonSerializable( - nullable: false, -) -class Item extends ItemCore { - @JsonKey(includeIfNull: false, name: 'item-number') - int itemNumber; - List saleDates; - List rates; - - Item([int price]) : super(price); - - factory Item.fromJson(Map json) => _$ItemFromJson(json); - - Map toJson() => _$ItemToJson(this); - - @override - bool operator ==(Object other) => - other is Item && - price == other.price && - itemNumber == other.itemNumber && - deepEquals(saleDates, other.saleDates); -} - -@JsonSerializable( - nullable: false, -) -class Numbers { - List ints; - List nums; - List doubles; - - @JsonKey(nullable: false) - List nnDoubles; - - @JsonKey(fromJson: durationFromInt, toJson: durationToInt) - Duration duration; - - @JsonKey(fromJson: dateTimeFromEpochUs, toJson: dateTimeToEpochUs) - DateTime date; - - Numbers(); - - factory Numbers.fromJson(Map json) => - _$NumbersFromJson(json); - - Map toJson() => _$NumbersToJson(this); - - @override - bool operator ==(Object other) => - other is Numbers && - deepEquals(ints, other.ints) && - deepEquals(nums, other.nums) && - deepEquals(doubles, other.doubles) && - deepEquals(nnDoubles, other.nnDoubles) && - deepEquals(duration, other.duration) && - deepEquals(date, other.date); -} - -@JsonSerializable( - nullable: false, -) -class MapKeyVariety { - Map intIntMap; - Map uriIntMap; - Map dateTimeIntMap; - Map bigIntMap; - - MapKeyVariety(); - - factory MapKeyVariety.fromJson(Map json) => - _$MapKeyVarietyFromJson(json); - - Map toJson() => _$MapKeyVarietyToJson(this); - - @override - bool operator ==(Object other) => - other is MapKeyVariety && - deepEquals(other.intIntMap, intIntMap) && - deepEquals(other.uriIntMap, uriIntMap) && - deepEquals(other.dateTimeIntMap, dateTimeIntMap) && - deepEquals(other.bigIntMap, bigIntMap); -} - -@JsonSerializable(nullable: false, createToJson: false) -class UnknownEnumValue { - @JsonKey(unknownEnumValue: Category.notDiscoveredYet) - Category enumValue; - - @JsonKey(unknownEnumValue: Category.notDiscoveredYet) - Iterable enumIterable; - - @JsonKey(unknownEnumValue: Category.notDiscoveredYet) - List enumList; - - @JsonKey(unknownEnumValue: Category.notDiscoveredYet) - Set enumSet; - - UnknownEnumValue(); - - factory UnknownEnumValue.fromJson(Map json) => - _$UnknownEnumValueFromJson(json); -} diff --git a/json_serializable/test/integration/json_test_example.g_non_nullable.g.dart b/json_serializable/test/integration/json_test_example.g_non_nullable.g.dart deleted file mode 100644 index 6c0e324d6..000000000 --- a/json_serializable/test/integration/json_test_example.g_non_nullable.g.dart +++ /dev/null @@ -1,203 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'json_test_example.g_non_nullable.dart'; - -// ************************************************************************** -// JsonSerializableGenerator -// ************************************************************************** - -Person _$PersonFromJson(Map json) { - return Person( - json['firstName'] as String, - json['lastName'] as String, - _$enumDecode(_$CategoryEnumMap, json[r'$house']), - middleName: json['middleName'] as String, - dateOfBirth: DateTime.parse(json['dateOfBirth'] as String), - ) - ..order = Order.fromJson(json['order'] as Map) - ..customOrders = MyList.fromJson((json['customOrders'] as List) - .map((e) => Order.fromJson(e as Map)) - .toList()) - ..houseMap = (json['houseMap'] as Map).map( - (k, e) => MapEntry(k, _$enumDecode(_$CategoryEnumMap, e)), - ) - ..categoryCounts = (json['categoryCounts'] as Map).map( - (k, e) => MapEntry(_$enumDecode(_$CategoryEnumMap, k), e as int), - ); -} - -Map _$PersonToJson(Person instance) => { - 'firstName': instance.firstName, - 'middleName': instance.middleName, - 'lastName': instance.lastName, - 'dateOfBirth': instance.dateOfBirth.toIso8601String(), - r'$house': _$CategoryEnumMap[instance.house], - 'order': instance.order, - 'customOrders': instance.customOrders, - 'houseMap': - instance.houseMap.map((k, e) => MapEntry(k, _$CategoryEnumMap[e])), - 'categoryCounts': instance.categoryCounts - .map((k, e) => MapEntry(_$CategoryEnumMap[k], e)), - }; - -T _$enumDecode( - Map enumValues, - dynamic source, { - T unknownValue, -}) { - if (source == null) { - throw ArgumentError('A value must be provided. Supported values: ' - '${enumValues.values.join(', ')}'); - } - - final value = enumValues.entries - .singleWhere((e) => e.value == source, orElse: () => null) - ?.key; - - if (value == null && unknownValue == null) { - throw ArgumentError('`$source` is not one of the supported values: ' - '${enumValues.values.join(', ')}'); - } - return value ?? unknownValue; -} - -const _$CategoryEnumMap = { - Category.top: 'top', - Category.bottom: 'bottom', - Category.strange: 'strange', - Category.charmed: 'charmed', - Category.up: 'up', - Category.down: 'down', - Category.notDiscoveredYet: 'not_discovered_yet', -}; - -Order _$OrderFromJson(Map json) { - $checkKeys(json, disallowNullValues: const ['count']); - return Order( - _$enumDecode(_$CategoryEnumMap, json['category']), - (json['items'] as List) - .map((e) => Item.fromJson(e as Map)), - ) - ..count = json['count'] as int - ..isRushed = json['isRushed'] as bool - ..duration = Duration(microseconds: json['duration'] as int) - ..platform = Platform.fromJson(json['platform'] as String) - ..altPlatforms = (json['altPlatforms'] as Map).map( - (k, e) => MapEntry(k, Platform.fromJson(e as String)), - ) - ..homepage = Uri.parse(json['homepage'] as String) - ..statusCode = _$enumDecodeNullable( - _$StatusCodeEnumMap, json['status_code'], - unknownValue: StatusCode.unknown) ?? - StatusCode.success; -} - -Map _$OrderToJson(Order instance) => { - 'count': instance.count, - 'isRushed': instance.isRushed, - 'duration': instance.duration.inMicroseconds, - 'category': _$CategoryEnumMap[instance.category], - 'items': instance.items, - 'platform': instance.platform, - 'altPlatforms': instance.altPlatforms, - 'homepage': instance.homepage.toString(), - 'status_code': _$StatusCodeEnumMap[instance.statusCode], - }; - -T _$enumDecodeNullable( - Map enumValues, - dynamic source, { - T unknownValue, -}) { - if (source == null) { - return null; - } - return _$enumDecode(enumValues, source, unknownValue: unknownValue); -} - -const _$StatusCodeEnumMap = { - StatusCode.success: 200, - StatusCode.notFound: 404, - StatusCode.weird: '500', - StatusCode.unknown: 'unknown', -}; - -Item _$ItemFromJson(Map json) { - return Item( - json['price'] as int, - ) - ..itemNumber = json['item-number'] as int - ..saleDates = (json['saleDates'] as List) - .map((e) => DateTime.parse(e as String)) - .toList() - ..rates = (json['rates'] as List).map((e) => e as int).toList(); -} - -Map _$ItemToJson(Item instance) => { - 'price': instance.price, - 'item-number': instance.itemNumber, - 'saleDates': instance.saleDates.map((e) => e.toIso8601String()).toList(), - 'rates': instance.rates, - }; - -Numbers _$NumbersFromJson(Map json) { - return Numbers() - ..ints = (json['ints'] as List).map((e) => e as int).toList() - ..nums = (json['nums'] as List).map((e) => e as num).toList() - ..doubles = - (json['doubles'] as List).map((e) => (e as num).toDouble()).toList() - ..nnDoubles = - (json['nnDoubles'] as List).map((e) => (e as num).toDouble()).toList() - ..duration = durationFromInt(json['duration'] as int) - ..date = dateTimeFromEpochUs(json['date'] as int); -} - -Map _$NumbersToJson(Numbers instance) => { - 'ints': instance.ints, - 'nums': instance.nums, - 'doubles': instance.doubles, - 'nnDoubles': instance.nnDoubles, - 'duration': durationToInt(instance.duration), - 'date': dateTimeToEpochUs(instance.date), - }; - -MapKeyVariety _$MapKeyVarietyFromJson(Map json) { - return MapKeyVariety() - ..intIntMap = (json['intIntMap'] as Map).map( - (k, e) => MapEntry(int.parse(k), e as int), - ) - ..uriIntMap = (json['uriIntMap'] as Map).map( - (k, e) => MapEntry(Uri.parse(k), e as int), - ) - ..dateTimeIntMap = (json['dateTimeIntMap'] as Map).map( - (k, e) => MapEntry(DateTime.parse(k), e as int), - ) - ..bigIntMap = (json['bigIntMap'] as Map).map( - (k, e) => MapEntry(BigInt.parse(k), e as int), - ); -} - -Map _$MapKeyVarietyToJson(MapKeyVariety instance) => - { - 'intIntMap': instance.intIntMap.map((k, e) => MapEntry(k.toString(), e)), - 'uriIntMap': instance.uriIntMap.map((k, e) => MapEntry(k.toString(), e)), - 'dateTimeIntMap': instance.dateTimeIntMap - .map((k, e) => MapEntry(k.toIso8601String(), e)), - 'bigIntMap': instance.bigIntMap.map((k, e) => MapEntry(k.toString(), e)), - }; - -UnknownEnumValue _$UnknownEnumValueFromJson(Map json) { - return UnknownEnumValue() - ..enumValue = _$enumDecode(_$CategoryEnumMap, json['enumValue'], - unknownValue: Category.notDiscoveredYet) - ..enumIterable = (json['enumIterable'] as List).map((e) => _$enumDecode( - _$CategoryEnumMap, e, unknownValue: Category.notDiscoveredYet)) - ..enumList = (json['enumList'] as List) - .map((e) => _$enumDecode(_$CategoryEnumMap, e, - unknownValue: Category.notDiscoveredYet)) - .toList() - ..enumSet = (json['enumSet'] as List) - .map((e) => _$enumDecode(_$CategoryEnumMap, e, - unknownValue: Category.notDiscoveredYet)) - .toSet(); -} diff --git a/json_serializable/test/json_serializable_test.dart b/json_serializable/test/json_serializable_test.dart index c834eb220..8c3c6351f 100644 --- a/json_serializable/test/json_serializable_test.dart +++ b/json_serializable/test/json_serializable_test.dart @@ -3,6 +3,7 @@ // BSD-style license that can be found in the LICENSE file. @TestOn('vm') +import 'package:build/experiments.dart'; import 'package:json_serializable/json_serializable.dart'; import 'package:path/path.dart' as p; import 'package:source_gen_test/source_gen_test.dart'; @@ -10,9 +11,12 @@ import 'package:test/test.dart'; Future main() async { initializeBuildLogTracking(); - final reader = await initializeLibraryReaderForDirectory( - p.join('test', 'src'), - '_json_serializable_test_input.dart', + final reader = await withEnabledExperiments( + () => initializeLibraryReaderForDirectory( + p.join('test', 'src'), + '_json_serializable_test_input.dart', + ), + ['non-nullable'], ); testAnnotatedElements( @@ -22,7 +26,7 @@ Future main() async { ); } -const _expectedAnnotatedTests = [ +const _expectedAnnotatedTests = { 'annotatedMethod', 'BadFromFuncReturnType', 'BadNoArgs', @@ -34,8 +38,6 @@ const _expectedAnnotatedTests = [ 'DefaultWithDisallowNullRequiredClass', 'DefaultWithFunction', 'DefaultWithNestedEnum', - 'DefaultWithNonNullableClass', - 'DefaultWithNonNullableField', 'DefaultWithSymbol', 'DefaultWithToJsonClass', 'DefaultWithType', @@ -64,18 +66,21 @@ const _expectedAnnotatedTests = [ 'InvalidFromFunc2Args', 'InvalidToFunc2Args', 'Issue713', + 'JsonConvertOnField', 'JsonConverterCtorParams', 'JsonConverterDuplicateAnnotations', 'JsonConverterNamedCtor', 'JsonConverterOnGetter', 'JsonConverterWithBadTypeArg', - 'JsonConvertOnField', 'JsonValueValid', 'JsonValueWithBool', 'JustSetter', 'JustSetterNoFromJson', 'JustSetterNoToJson', 'KeyDupesField', + 'MapKeyNoNullableInt', + 'MapKeyNoNullableObject', + 'MapKeyNoNullableString', 'MapKeyVariety', 'NoCtorClass', 'NoDeserializeBadKey', @@ -114,4 +119,4 @@ const _expectedAnnotatedTests = [ 'ValidToFromFuncClassStatic', 'WithANonCtorGetter', 'WithANonCtorGetterChecked', -]; +}; diff --git a/json_serializable/test/kitchen_sink/json_converters.dart b/json_serializable/test/kitchen_sink/json_converters.dart index f4b24d8b1..c5074416f 100644 --- a/json_serializable/test/kitchen_sink/json_converters.dart +++ b/json_serializable/test/kitchen_sink/json_converters.dart @@ -2,66 +2,68 @@ // 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. +// @dart=2.12 + import 'package:json_annotation/json_annotation.dart'; class GenericConverter implements JsonConverter> { const GenericConverter(); @override - T fromJson(Map json) => null; + T fromJson(Map json) => null as T; @override Map toJson(T object) => {}; } class TrivialNumber { - final int value; + final int? value; TrivialNumber(this.value); } -class TrivialNumberConverter implements JsonConverter { +class TrivialNumberConverter implements JsonConverter { static const instance = TrivialNumberConverter(); const TrivialNumberConverter(); @override - TrivialNumber fromJson(int json) => TrivialNumber(json); + TrivialNumber fromJson(int? json) => TrivialNumber(json); @override - int toJson(TrivialNumber object) => object?.value; + int? toJson(TrivialNumber? object) => object?.value; } class BigIntStringConverter implements JsonConverter { const BigIntStringConverter(); @override - BigInt fromJson(String json) => json == null ? null : BigInt.parse(json); + BigInt fromJson(String json) => BigInt.parse(json); @override - String toJson(BigInt object) => object?.toString(); + String toJson(BigInt object) => object.toString(); } const durationConverter = DurationMillisecondConverter(); -class DurationMillisecondConverter implements JsonConverter { +class DurationMillisecondConverter implements JsonConverter { const DurationMillisecondConverter(); @override - Duration fromJson(int json) => + Duration? fromJson(int? json) => json == null ? null : Duration(milliseconds: json); @override - int toJson(Duration object) => object?.inMilliseconds; + int? toJson(Duration? object) => object?.inMilliseconds; } -class EpochDateTimeConverter implements JsonConverter { +class EpochDateTimeConverter implements JsonConverter { const EpochDateTimeConverter(); @override - DateTime fromJson(int json) => + DateTime? fromJson(int? json) => json == null ? null : DateTime.fromMillisecondsSinceEpoch(json); @override - int toJson(DateTime object) => object?.millisecondsSinceEpoch; + int? toJson(DateTime? object) => object?.millisecondsSinceEpoch; } diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.dart b/json_serializable/test/kitchen_sink/kitchen_sink.dart index aeaa57dde..113fe5e84 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.dart @@ -2,6 +2,8 @@ // 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. +// @dart=2.12 + // ignore_for_file: annotate_overrides, hash_and_equals import 'package:json_annotation/json_annotation.dart'; @@ -14,11 +16,15 @@ part 'kitchen_sink.g.dart'; // NOTE: these methods are replaced in the `non_nullable` cases to return // non-null values. -List _defaultList() => null; -Set _defaultSet() => null; -Map _defaultMap() => null; -SimpleObject _defaultSimpleObject() => null; -StrictKeysObject _defaultStrictKeysObject() => null; +List _defaultList() => []; + +Set _defaultSet() => {}; + +Map _defaultMap() => {}; + +SimpleObject _defaultSimpleObject() => SimpleObject(42); + +StrictKeysObject _defaultStrictKeysObject() => StrictKeysObject(42, 'value'); const k.KitchenSinkFactory factory = _Factory(); @@ -26,19 +32,24 @@ class _Factory implements k.KitchenSinkFactory { const _Factory(); String get description => '--defaults--'; + bool get anyMap => false; + bool get checked => false; + bool get nullable => true; + bool get excludeNull => false; + bool get explicitToJson => false; k.KitchenSink ctor({ - int ctorValidatedNo42, - Iterable iterable, - Iterable dynamicIterable, - Iterable objectIterable, - Iterable intIterable, - Iterable dateTimeIterable, + int? ctorValidatedNo42, + Iterable? iterable, + Iterable? dynamicIterable, + Iterable? objectIterable, + Iterable? intIterable, + Iterable? dateTimeIterable, }) => KitchenSink( ctorValidatedNo42: ctorValidatedNo42, @@ -52,7 +63,15 @@ class _Factory implements k.KitchenSinkFactory { k.KitchenSink fromJson(Map json) => KitchenSink.fromJson(json); - k.JsonConverterTestClass jsonConverterCtor() => JsonConverterTestClass(); + k.JsonConverterTestClass jsonConverterCtor() => JsonConverterTestClass( + const Duration(), + [], + BigInt.zero, + {}, + TrivialNumber(0), + {}, + DateTime.fromMillisecondsSinceEpoch(0), + ); k.JsonConverterTestClass jsonConverterFromJson(Map json) => JsonConverterTestClass.fromJson(json); @@ -62,23 +81,23 @@ class _Factory implements k.KitchenSinkFactory { class KitchenSink implements k.KitchenSink { // NOTE: exposing these as Iterable, but storing the values as List // to make the equality test work trivially. - final Iterable _iterable; + final Iterable? _iterable; final Iterable _dynamicIterable; final Iterable _objectIterable; final Iterable _intIterable; final Iterable _dateTimeIterable; @JsonKey(name: 'no-42') - final int ctorValidatedNo42; + final int? ctorValidatedNo42; KitchenSink({ this.ctorValidatedNo42, - Iterable iterable, - Iterable dynamicIterable, - Iterable objectIterable, - Iterable intIterable, - Iterable dateTimeIterable, - }) : _iterable = iterable?.toList() ?? _defaultList(), + Iterable? iterable, + Iterable? dynamicIterable, + Iterable? objectIterable, + Iterable? intIterable, + Iterable? dateTimeIterable, + }) : _iterable = iterable?.toList(), _dynamicIterable = dynamicIterable?.toList() ?? _defaultList(), _objectIterable = objectIterable?.toList() ?? _defaultList(), _intIterable = intIterable?.toList() ?? _defaultList(), @@ -94,13 +113,16 @@ class KitchenSink implements k.KitchenSink { Map toJson() => _$KitchenSinkToJson(this); - DateTime dateTime; + DateTime? dateTime; - BigInt bigInt; + BigInt? bigInt; + + Iterable? get iterable => _iterable; - Iterable get iterable => _iterable; Iterable get dynamicIterable => _dynamicIterable; + Iterable get objectIterable => _objectIterable; + Iterable get intIterable => _intIterable; Set set = _defaultSet(); @@ -124,23 +146,24 @@ class KitchenSink implements k.KitchenSink { Map dynamicIntMap = _defaultMap(); Map objectDateTimeMap = _defaultMap(); - List>>>> crazyComplex = + List?>?>?>?> crazyComplex = _defaultList(); // Handle fields with names that collide with helper names Map val = _defaultMap(); - bool writeNotNull; + bool? writeNotNull; @JsonKey(name: r'$string') - String string; + String? string; SimpleObject simpleObject = _defaultSimpleObject(); StrictKeysObject strictKeysObject = _defaultStrictKeysObject(); - int _validatedPropertyNo42; - int get validatedPropertyNo42 => _validatedPropertyNo42; + int? _validatedPropertyNo42; + + int? get validatedPropertyNo42 => _validatedPropertyNo42; - set validatedPropertyNo42(int value) { + set validatedPropertyNo42(int? value) { if (value == 42) { throw StateError('Cannot be 42!'); } @@ -158,15 +181,23 @@ class KitchenSink implements k.KitchenSink { @TrivialNumberConverter.instance @EpochDateTimeConverter() class JsonConverterTestClass implements k.JsonConverterTestClass { - JsonConverterTestClass(); + JsonConverterTestClass( + this.duration, + this.durationList, + this.bigInt, + this.bigIntMap, + this.numberSilly, + this.numberSillySet, + this.dateTime, + ); factory JsonConverterTestClass.fromJson(Map json) => _$JsonConverterTestClassFromJson(json); Map toJson() => _$JsonConverterTestClassToJson(this); - Duration duration; - List durationList; + Duration? duration; + List durationList; BigInt bigInt; Map bigIntMap; @@ -174,7 +205,7 @@ class JsonConverterTestClass implements k.JsonConverterTestClass { TrivialNumber numberSilly; Set numberSillySet; - DateTime dateTime; + DateTime? dateTime; } @JsonSerializable() @@ -184,7 +215,11 @@ class JsonConverterGeneric { List itemList; Map itemMap; - JsonConverterGeneric(); + JsonConverterGeneric( + this.item, + this.itemList, + this.itemMap, + ); factory JsonConverterGeneric.fromJson(Map json) => _$JsonConverterGenericFromJson(json); diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.factories.dart b/json_serializable/test/kitchen_sink/kitchen_sink.factories.dart index 8248cdc8a..3c26454da 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.factories.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.factories.dart @@ -1,21 +1,16 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND +// @dart=2.12 + import 'kitchen_sink.dart' as normal; import 'kitchen_sink.g_any_map.dart' as any_map; -import 'kitchen_sink.g_any_map__checked__non_nullable.dart' - as any_map__checked__non_nullable; -import 'kitchen_sink.g_any_map__non_nullable.dart' as any_map__non_nullable; +import 'kitchen_sink.g_any_map__checked.dart' as any_map__checked; import 'kitchen_sink.g_exclude_null.dart' as exclude_null; -import 'kitchen_sink.g_exclude_null__non_nullable.dart' - as exclude_null__non_nullable; import 'kitchen_sink.g_explicit_to_json.dart' as explicit_to_json; -import 'kitchen_sink.g_non_nullable.dart' as non_nullable; const factories = [ normal.factory, any_map.factory, - any_map__checked__non_nullable.factory, - any_map__non_nullable.factory, + any_map__checked.factory, exclude_null.factory, - exclude_null__non_nullable.factory, explicit_to_json.factory, - non_nullable.factory, ]; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g.dart index a6f1555ca..027129a3a 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g.dart @@ -1,4 +1,5 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// @dart=2.12 part of 'kitchen_sink.dart'; @@ -8,74 +9,66 @@ part of 'kitchen_sink.dart'; KitchenSink _$KitchenSinkFromJson(Map json) { return KitchenSink( - ctorValidatedNo42: json['no-42'] as int, - iterable: json['iterable'] as List, - dynamicIterable: json['dynamicIterable'] as List, - objectIterable: json['objectIterable'] as List, - intIterable: (json['intIterable'] as List)?.map((e) => e as int), - dateTimeIterable: (json['datetime-iterable'] as List) - ?.map((e) => e == null ? null : DateTime.parse(e as String)), + ctorValidatedNo42: json['no-42'] as int?, + iterable: json['iterable'] as List?, + dynamicIterable: json['dynamicIterable'] as List?, + objectIterable: + (json['objectIterable'] as List?)?.map((e) => e as Object), + intIterable: (json['intIterable'] as List?)?.map((e) => e as int), + dateTimeIterable: (json['datetime-iterable'] as List?) + ?.map((e) => DateTime.parse(e as String)), ) ..dateTime = json['dateTime'] == null ? null : DateTime.parse(json['dateTime'] as String) ..bigInt = json['bigInt'] == null ? null : BigInt.parse(json['bigInt'] as String) - ..set = (json['set'] as List)?.toSet() - ..dynamicSet = (json['dynamicSet'] as List)?.toSet() - ..objectSet = (json['objectSet'] as List)?.toSet() - ..intSet = (json['intSet'] as List)?.map((e) => e as int)?.toSet() - ..dateTimeSet = (json['dateTimeSet'] as List) - ?.map((e) => e == null ? null : DateTime.parse(e as String)) - ?.toSet() - ..list = json['list'] as List - ..dynamicList = json['dynamicList'] as List - ..objectList = json['objectList'] as List - ..intList = (json['intList'] as List)?.map((e) => e as int)?.toList() - ..dateTimeList = (json['dateTimeList'] as List) - ?.map((e) => e == null ? null : DateTime.parse(e as String)) - ?.toList() + ..set = (json['set'] as List).toSet() + ..dynamicSet = (json['dynamicSet'] as List).toSet() + ..objectSet = + (json['objectSet'] as List).map((e) => e as Object).toSet() + ..intSet = (json['intSet'] as List).map((e) => e as int).toSet() + ..dateTimeSet = (json['dateTimeSet'] as List) + .map((e) => DateTime.parse(e as String)) + .toSet() + ..list = json['list'] as List + ..dynamicList = json['dynamicList'] as List + ..objectList = + (json['objectList'] as List).map((e) => e as Object).toList() + ..intList = (json['intList'] as List).map((e) => e as int).toList() + ..dateTimeList = (json['dateTimeList'] as List) + .map((e) => DateTime.parse(e as String)) + .toList() ..map = json['map'] as Map - ..stringStringMap = (json['stringStringMap'] as Map)?.map( - (k, e) => MapEntry(k, e as String), - ) - ..dynamicIntMap = (json['dynamicIntMap'] as Map)?.map( - (k, e) => MapEntry(k, e as int), - ) + ..stringStringMap = Map.from(json['stringStringMap'] as Map) + ..dynamicIntMap = Map.from(json['dynamicIntMap'] as Map) ..objectDateTimeMap = - (json['objectDateTimeMap'] as Map)?.map( - (k, e) => MapEntry(k, e == null ? null : DateTime.parse(e as String)), + (json['objectDateTimeMap'] as Map).map( + (k, e) => MapEntry(k, DateTime.parse(e as String)), ) - ..crazyComplex = (json['crazyComplex'] as List) - ?.map((e) => (e as Map)?.map( + ..crazyComplex = (json['crazyComplex'] as List) + .map((e) => (e as Map?)?.map( (k, e) => MapEntry( k, - (e as Map)?.map( + (e as Map?)?.map( (k, e) => MapEntry( k, - (e as List) - ?.map((e) => (e as List) - ?.map((e) => e == null - ? null - : DateTime.parse(e as String)) - ?.toList()) - ?.toList()), + (e as List?) + ?.map((e) => (e as List?) + ?.map((e) => DateTime.parse(e as String)) + .toList()) + .toList()), )), )) - ?.toList() - ..val = (json['val'] as Map)?.map( - (k, e) => MapEntry(k, e as bool), - ) - ..writeNotNull = json['writeNotNull'] as bool - ..string = json[r'$string'] as String - ..simpleObject = json['simpleObject'] == null - ? null - : SimpleObject.fromJson(json['simpleObject'] as Map) - ..strictKeysObject = json['strictKeysObject'] == null - ? null - : StrictKeysObject.fromJson( - json['strictKeysObject'] as Map) - ..validatedPropertyNo42 = json['validatedPropertyNo42'] as int; + .toList() + ..val = Map.from(json['val'] as Map) + ..writeNotNull = json['writeNotNull'] as bool? + ..string = json[r'$string'] as String? + ..simpleObject = + SimpleObject.fromJson(json['simpleObject'] as Map) + ..strictKeysObject = StrictKeysObject.fromJson( + json['strictKeysObject'] as Map) + ..validatedPropertyNo42 = json['validatedPropertyNo42'] as int?; } Map _$KitchenSinkToJson(KitchenSink instance) => @@ -84,38 +77,37 @@ Map _$KitchenSinkToJson(KitchenSink instance) => 'dateTime': instance.dateTime?.toIso8601String(), 'bigInt': instance.bigInt?.toString(), 'iterable': instance.iterable?.toList(), - 'dynamicIterable': instance.dynamicIterable?.toList(), - 'objectIterable': instance.objectIterable?.toList(), - 'intIterable': instance.intIterable?.toList(), - 'set': instance.set?.toList(), - 'dynamicSet': instance.dynamicSet?.toList(), - 'objectSet': instance.objectSet?.toList(), - 'intSet': instance.intSet?.toList(), + 'dynamicIterable': instance.dynamicIterable.toList(), + 'objectIterable': instance.objectIterable.toList(), + 'intIterable': instance.intIterable.toList(), + 'set': instance.set.toList(), + 'dynamicSet': instance.dynamicSet.toList(), + 'objectSet': instance.objectSet.toList(), + 'intSet': instance.intSet.toList(), 'dateTimeSet': - instance.dateTimeSet?.map((e) => e?.toIso8601String())?.toList(), + instance.dateTimeSet.map((e) => e.toIso8601String()).toList(), 'datetime-iterable': - instance.dateTimeIterable?.map((e) => e?.toIso8601String())?.toList(), + instance.dateTimeIterable.map((e) => e.toIso8601String()).toList(), 'list': instance.list, 'dynamicList': instance.dynamicList, 'objectList': instance.objectList, 'intList': instance.intList, 'dateTimeList': - instance.dateTimeList?.map((e) => e?.toIso8601String())?.toList(), + instance.dateTimeList.map((e) => e.toIso8601String()).toList(), 'map': instance.map, 'stringStringMap': instance.stringStringMap, 'dynamicIntMap': instance.dynamicIntMap, 'objectDateTimeMap': instance.objectDateTimeMap - ?.map((k, e) => MapEntry(k, e?.toIso8601String())), + .map((k, e) => MapEntry(k, e.toIso8601String())), 'crazyComplex': instance.crazyComplex - ?.map((e) => e?.map((k, e) => MapEntry( + .map((e) => e?.map((k, e) => MapEntry( k, e?.map((k, e) => MapEntry( k, e - ?.map( - (e) => e?.map((e) => e?.toIso8601String())?.toList()) - ?.toList()))))) - ?.toList(), + ?.map((e) => e?.map((e) => e.toIso8601String()).toList()) + .toList()))))) + .toList(), 'val': instance.val, 'writeNotNull': instance.writeNotNull, r'$string': instance.string, @@ -126,23 +118,22 @@ Map _$KitchenSinkToJson(KitchenSink instance) => JsonConverterTestClass _$JsonConverterTestClassFromJson( Map json) { - return JsonConverterTestClass() - ..duration = durationConverter.fromJson(json['duration'] as int) - ..durationList = (json['durationList'] as List) - ?.map((e) => durationConverter.fromJson(e as int)) - ?.toList() - ..bigInt = const BigIntStringConverter().fromJson(json['bigInt'] as String) - ..bigIntMap = (json['bigIntMap'] as Map)?.map( + return JsonConverterTestClass( + durationConverter.fromJson(json['duration'] as int?), + (json['durationList'] as List) + .map((e) => durationConverter.fromJson(e as int?)) + .toList(), + const BigIntStringConverter().fromJson(json['bigInt'] as String), + (json['bigIntMap'] as Map).map( (k, e) => MapEntry(k, const BigIntStringConverter().fromJson(e as String)), - ) - ..numberSilly = - TrivialNumberConverter.instance.fromJson(json['numberSilly'] as int) - ..numberSillySet = (json['numberSillySet'] as List) - ?.map((e) => TrivialNumberConverter.instance.fromJson(e as int)) - ?.toSet() - ..dateTime = - const EpochDateTimeConverter().fromJson(json['dateTime'] as int); + ), + TrivialNumberConverter.instance.fromJson(json['numberSilly'] as int?), + (json['numberSillySet'] as List) + .map((e) => TrivialNumberConverter.instance.fromJson(e as int?)) + .toSet(), + const EpochDateTimeConverter().fromJson(json['dateTime'] as int?), + ); } Map _$JsonConverterTestClassToJson( @@ -150,38 +141,37 @@ Map _$JsonConverterTestClassToJson( { 'duration': durationConverter.toJson(instance.duration), 'durationList': - instance.durationList?.map(durationConverter.toJson)?.toList(), + instance.durationList.map(durationConverter.toJson).toList(), 'bigInt': const BigIntStringConverter().toJson(instance.bigInt), 'bigIntMap': instance.bigIntMap - ?.map((k, e) => MapEntry(k, const BigIntStringConverter().toJson(e))), + .map((k, e) => MapEntry(k, const BigIntStringConverter().toJson(e))), 'numberSilly': TrivialNumberConverter.instance.toJson(instance.numberSilly), 'numberSillySet': instance.numberSillySet - ?.map(TrivialNumberConverter.instance.toJson) - ?.toList(), + .map(TrivialNumberConverter.instance.toJson) + .toList(), 'dateTime': const EpochDateTimeConverter().toJson(instance.dateTime), }; JsonConverterGeneric _$JsonConverterGenericFromJson( Map json) { - return JsonConverterGeneric() - ..item = - GenericConverter().fromJson(json['item'] as Map) - ..itemList = (json['itemList'] as List) - ?.map((e) => GenericConverter().fromJson(e as Map)) - ?.toList() - ..itemMap = (json['itemMap'] as Map)?.map( + return JsonConverterGeneric( + GenericConverter().fromJson(json['item'] as Map), + (json['itemList'] as List) + .map((e) => GenericConverter().fromJson(e as Map)) + .toList(), + (json['itemMap'] as Map).map( (k, e) => MapEntry( k, GenericConverter().fromJson(e as Map)), - ); + ), + ); } Map _$JsonConverterGenericToJson( JsonConverterGeneric instance) => { 'item': GenericConverter().toJson(instance.item), - 'itemList': - instance.itemList?.map(GenericConverter().toJson)?.toList(), + 'itemList': instance.itemList.map(GenericConverter().toJson).toList(), 'itemMap': instance.itemMap - ?.map((k, e) => MapEntry(k, GenericConverter().toJson(e))), + .map((k, e) => MapEntry(k, GenericConverter().toJson(e))), }; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart index b68578374..5d0ce3fbe 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart @@ -2,6 +2,8 @@ // 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. +// @dart=2.12 + // ignore_for_file: annotate_overrides, hash_and_equals import 'package:json_annotation/json_annotation.dart'; @@ -14,11 +16,15 @@ part 'kitchen_sink.g_any_map.g.dart'; // NOTE: these methods are replaced in the `non_nullable` cases to return // non-null values. -List _defaultList() => null; -Set _defaultSet() => null; -Map _defaultMap() => null; -SimpleObject _defaultSimpleObject() => null; -StrictKeysObject _defaultStrictKeysObject() => null; +List _defaultList() => []; + +Set _defaultSet() => {}; + +Map _defaultMap() => {}; + +SimpleObject _defaultSimpleObject() => SimpleObject(42); + +StrictKeysObject _defaultStrictKeysObject() => StrictKeysObject(42, 'value'); const k.KitchenSinkFactory factory = _Factory(); @@ -26,19 +32,24 @@ class _Factory implements k.KitchenSinkFactory { const _Factory(); String get description => 'any_map'; + bool get anyMap => true; + bool get checked => false; + bool get nullable => true; + bool get excludeNull => false; + bool get explicitToJson => false; k.KitchenSink ctor({ - int ctorValidatedNo42, - Iterable iterable, - Iterable dynamicIterable, - Iterable objectIterable, - Iterable intIterable, - Iterable dateTimeIterable, + int? ctorValidatedNo42, + Iterable? iterable, + Iterable? dynamicIterable, + Iterable? objectIterable, + Iterable? intIterable, + Iterable? dateTimeIterable, }) => KitchenSink( ctorValidatedNo42: ctorValidatedNo42, @@ -51,7 +62,15 @@ class _Factory implements k.KitchenSinkFactory { k.KitchenSink fromJson(Map json) => KitchenSink.fromJson(json); - k.JsonConverterTestClass jsonConverterCtor() => JsonConverterTestClass(); + k.JsonConverterTestClass jsonConverterCtor() => JsonConverterTestClass( + const Duration(), + [], + BigInt.zero, + {}, + TrivialNumber(0), + {}, + DateTime.fromMillisecondsSinceEpoch(0), + ); k.JsonConverterTestClass jsonConverterFromJson(Map json) => JsonConverterTestClass.fromJson(json); @@ -63,23 +82,23 @@ class _Factory implements k.KitchenSinkFactory { class KitchenSink implements k.KitchenSink { // NOTE: exposing these as Iterable, but storing the values as List // to make the equality test work trivially. - final Iterable _iterable; + final Iterable? _iterable; final Iterable _dynamicIterable; final Iterable _objectIterable; final Iterable _intIterable; final Iterable _dateTimeIterable; @JsonKey(name: 'no-42') - final int ctorValidatedNo42; + final int? ctorValidatedNo42; KitchenSink({ this.ctorValidatedNo42, - Iterable iterable, - Iterable dynamicIterable, - Iterable objectIterable, - Iterable intIterable, - Iterable dateTimeIterable, - }) : _iterable = iterable?.toList() ?? _defaultList(), + Iterable? iterable, + Iterable? dynamicIterable, + Iterable? objectIterable, + Iterable? intIterable, + Iterable? dateTimeIterable, + }) : _iterable = iterable?.toList(), _dynamicIterable = dynamicIterable?.toList() ?? _defaultList(), _objectIterable = objectIterable?.toList() ?? _defaultList(), _intIterable = intIterable?.toList() ?? _defaultList(), @@ -94,13 +113,16 @@ class KitchenSink implements k.KitchenSink { Map toJson() => _$KitchenSinkToJson(this); - DateTime dateTime; + DateTime? dateTime; - BigInt bigInt; + BigInt? bigInt; + + Iterable? get iterable => _iterable; - Iterable get iterable => _iterable; Iterable get dynamicIterable => _dynamicIterable; + Iterable get objectIterable => _objectIterable; + Iterable get intIterable => _intIterable; Set set = _defaultSet(); @@ -124,23 +146,24 @@ class KitchenSink implements k.KitchenSink { Map dynamicIntMap = _defaultMap(); Map objectDateTimeMap = _defaultMap(); - List>>>> crazyComplex = + List?>?>?>?> crazyComplex = _defaultList(); // Handle fields with names that collide with helper names Map val = _defaultMap(); - bool writeNotNull; + bool? writeNotNull; @JsonKey(name: r'$string') - String string; + String? string; SimpleObject simpleObject = _defaultSimpleObject(); StrictKeysObject strictKeysObject = _defaultStrictKeysObject(); - int _validatedPropertyNo42; - int get validatedPropertyNo42 => _validatedPropertyNo42; + int? _validatedPropertyNo42; + + int? get validatedPropertyNo42 => _validatedPropertyNo42; - set validatedPropertyNo42(int value) { + set validatedPropertyNo42(int? value) { if (value == 42) { throw StateError('Cannot be 42!'); } @@ -160,15 +183,23 @@ class KitchenSink implements k.KitchenSink { @TrivialNumberConverter.instance @EpochDateTimeConverter() class JsonConverterTestClass implements k.JsonConverterTestClass { - JsonConverterTestClass(); + JsonConverterTestClass( + this.duration, + this.durationList, + this.bigInt, + this.bigIntMap, + this.numberSilly, + this.numberSillySet, + this.dateTime, + ); factory JsonConverterTestClass.fromJson(Map json) => _$JsonConverterTestClassFromJson(json); Map toJson() => _$JsonConverterTestClassToJson(this); - Duration duration; - List durationList; + Duration? duration; + List durationList; BigInt bigInt; Map bigIntMap; @@ -176,7 +207,7 @@ class JsonConverterTestClass implements k.JsonConverterTestClass { TrivialNumber numberSilly; Set numberSillySet; - DateTime dateTime; + DateTime? dateTime; } @JsonSerializable( @@ -188,7 +219,11 @@ class JsonConverterGeneric { List itemList; Map itemMap; - JsonConverterGeneric(); + JsonConverterGeneric( + this.item, + this.itemList, + this.itemMap, + ); factory JsonConverterGeneric.fromJson(Map json) => _$JsonConverterGenericFromJson(json); diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart index f57bdf7c6..0c88a1cbd 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart @@ -1,4 +1,5 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// @dart=2.12 part of 'kitchen_sink.g_any_map.dart'; @@ -8,72 +9,64 @@ part of 'kitchen_sink.g_any_map.dart'; KitchenSink _$KitchenSinkFromJson(Map json) { return KitchenSink( - ctorValidatedNo42: json['no-42'] as int, - iterable: json['iterable'] as List, - dynamicIterable: json['dynamicIterable'] as List, - objectIterable: json['objectIterable'] as List, - intIterable: (json['intIterable'] as List)?.map((e) => e as int), - dateTimeIterable: (json['datetime-iterable'] as List) - ?.map((e) => e == null ? null : DateTime.parse(e as String)), + ctorValidatedNo42: json['no-42'] as int?, + iterable: json['iterable'] as List?, + dynamicIterable: json['dynamicIterable'] as List?, + objectIterable: + (json['objectIterable'] as List?)?.map((e) => e as Object), + intIterable: (json['intIterable'] as List?)?.map((e) => e as int), + dateTimeIterable: (json['datetime-iterable'] as List?) + ?.map((e) => DateTime.parse(e as String)), ) ..dateTime = json['dateTime'] == null ? null : DateTime.parse(json['dateTime'] as String) ..bigInt = json['bigInt'] == null ? null : BigInt.parse(json['bigInt'] as String) - ..set = (json['set'] as List)?.toSet() - ..dynamicSet = (json['dynamicSet'] as List)?.toSet() - ..objectSet = (json['objectSet'] as List)?.toSet() - ..intSet = (json['intSet'] as List)?.map((e) => e as int)?.toSet() - ..dateTimeSet = (json['dateTimeSet'] as List) - ?.map((e) => e == null ? null : DateTime.parse(e as String)) - ?.toSet() - ..list = json['list'] as List - ..dynamicList = json['dynamicList'] as List - ..objectList = json['objectList'] as List - ..intList = (json['intList'] as List)?.map((e) => e as int)?.toList() - ..dateTimeList = (json['dateTimeList'] as List) - ?.map((e) => e == null ? null : DateTime.parse(e as String)) - ?.toList() + ..set = (json['set'] as List).toSet() + ..dynamicSet = (json['dynamicSet'] as List).toSet() + ..objectSet = + (json['objectSet'] as List).map((e) => e as Object).toSet() + ..intSet = (json['intSet'] as List).map((e) => e as int).toSet() + ..dateTimeSet = (json['dateTimeSet'] as List) + .map((e) => DateTime.parse(e as String)) + .toSet() + ..list = json['list'] as List + ..dynamicList = json['dynamicList'] as List + ..objectList = + (json['objectList'] as List).map((e) => e as Object).toList() + ..intList = (json['intList'] as List).map((e) => e as int).toList() + ..dateTimeList = (json['dateTimeList'] as List) + .map((e) => DateTime.parse(e as String)) + .toList() ..map = json['map'] as Map - ..stringStringMap = (json['stringStringMap'] as Map)?.map( - (k, e) => MapEntry(k as String, e as String), + ..stringStringMap = Map.from(json['stringStringMap'] as Map) + ..dynamicIntMap = Map.from(json['dynamicIntMap'] as Map) + ..objectDateTimeMap = (json['objectDateTimeMap'] as Map).map( + (k, e) => MapEntry(k as Object, DateTime.parse(e as String)), ) - ..dynamicIntMap = (json['dynamicIntMap'] as Map)?.map( - (k, e) => MapEntry(k, e as int), - ) - ..objectDateTimeMap = (json['objectDateTimeMap'] as Map)?.map( - (k, e) => MapEntry(k, e == null ? null : DateTime.parse(e as String)), - ) - ..crazyComplex = (json['crazyComplex'] as List) - ?.map((e) => (e as Map)?.map( + ..crazyComplex = (json['crazyComplex'] as List) + .map((e) => (e as Map?)?.map( (k, e) => MapEntry( k as String, - (e as Map)?.map( + (e as Map?)?.map( (k, e) => MapEntry( k as String, - (e as List) - ?.map((e) => (e as List) - ?.map((e) => e == null - ? null - : DateTime.parse(e as String)) - ?.toList()) - ?.toList()), + (e as List?) + ?.map((e) => (e as List?) + ?.map((e) => DateTime.parse(e as String)) + .toList()) + .toList()), )), )) - ?.toList() - ..val = (json['val'] as Map)?.map( - (k, e) => MapEntry(k as String, e as bool), - ) - ..writeNotNull = json['writeNotNull'] as bool - ..string = json[r'$string'] as String - ..simpleObject = json['simpleObject'] == null - ? null - : SimpleObject.fromJson(json['simpleObject'] as Map) - ..strictKeysObject = json['strictKeysObject'] == null - ? null - : StrictKeysObject.fromJson(json['strictKeysObject'] as Map) - ..validatedPropertyNo42 = json['validatedPropertyNo42'] as int; + .toList() + ..val = Map.from(json['val'] as Map) + ..writeNotNull = json['writeNotNull'] as bool? + ..string = json[r'$string'] as String? + ..simpleObject = SimpleObject.fromJson(json['simpleObject'] as Map) + ..strictKeysObject = + StrictKeysObject.fromJson(json['strictKeysObject'] as Map) + ..validatedPropertyNo42 = json['validatedPropertyNo42'] as int?; } Map _$KitchenSinkToJson(KitchenSink instance) => @@ -82,38 +75,37 @@ Map _$KitchenSinkToJson(KitchenSink instance) => 'dateTime': instance.dateTime?.toIso8601String(), 'bigInt': instance.bigInt?.toString(), 'iterable': instance.iterable?.toList(), - 'dynamicIterable': instance.dynamicIterable?.toList(), - 'objectIterable': instance.objectIterable?.toList(), - 'intIterable': instance.intIterable?.toList(), - 'set': instance.set?.toList(), - 'dynamicSet': instance.dynamicSet?.toList(), - 'objectSet': instance.objectSet?.toList(), - 'intSet': instance.intSet?.toList(), + 'dynamicIterable': instance.dynamicIterable.toList(), + 'objectIterable': instance.objectIterable.toList(), + 'intIterable': instance.intIterable.toList(), + 'set': instance.set.toList(), + 'dynamicSet': instance.dynamicSet.toList(), + 'objectSet': instance.objectSet.toList(), + 'intSet': instance.intSet.toList(), 'dateTimeSet': - instance.dateTimeSet?.map((e) => e?.toIso8601String())?.toList(), + instance.dateTimeSet.map((e) => e.toIso8601String()).toList(), 'datetime-iterable': - instance.dateTimeIterable?.map((e) => e?.toIso8601String())?.toList(), + instance.dateTimeIterable.map((e) => e.toIso8601String()).toList(), 'list': instance.list, 'dynamicList': instance.dynamicList, 'objectList': instance.objectList, 'intList': instance.intList, 'dateTimeList': - instance.dateTimeList?.map((e) => e?.toIso8601String())?.toList(), + instance.dateTimeList.map((e) => e.toIso8601String()).toList(), 'map': instance.map, 'stringStringMap': instance.stringStringMap, 'dynamicIntMap': instance.dynamicIntMap, 'objectDateTimeMap': instance.objectDateTimeMap - ?.map((k, e) => MapEntry(k, e?.toIso8601String())), + .map((k, e) => MapEntry(k, e.toIso8601String())), 'crazyComplex': instance.crazyComplex - ?.map((e) => e?.map((k, e) => MapEntry( + .map((e) => e?.map((k, e) => MapEntry( k, e?.map((k, e) => MapEntry( k, e - ?.map( - (e) => e?.map((e) => e?.toIso8601String())?.toList()) - ?.toList()))))) - ?.toList(), + ?.map((e) => e?.map((e) => e.toIso8601String()).toList()) + .toList()))))) + .toList(), 'val': instance.val, 'writeNotNull': instance.writeNotNull, r'$string': instance.string, @@ -123,23 +115,22 @@ Map _$KitchenSinkToJson(KitchenSink instance) => }; JsonConverterTestClass _$JsonConverterTestClassFromJson(Map json) { - return JsonConverterTestClass() - ..duration = durationConverter.fromJson(json['duration'] as int) - ..durationList = (json['durationList'] as List) - ?.map((e) => durationConverter.fromJson(e as int)) - ?.toList() - ..bigInt = const BigIntStringConverter().fromJson(json['bigInt'] as String) - ..bigIntMap = (json['bigIntMap'] as Map)?.map( + return JsonConverterTestClass( + durationConverter.fromJson(json['duration'] as int?), + (json['durationList'] as List) + .map((e) => durationConverter.fromJson(e as int?)) + .toList(), + const BigIntStringConverter().fromJson(json['bigInt'] as String), + (json['bigIntMap'] as Map).map( (k, e) => MapEntry( k as String, const BigIntStringConverter().fromJson(e as String)), - ) - ..numberSilly = - TrivialNumberConverter.instance.fromJson(json['numberSilly'] as int) - ..numberSillySet = (json['numberSillySet'] as List) - ?.map((e) => TrivialNumberConverter.instance.fromJson(e as int)) - ?.toSet() - ..dateTime = - const EpochDateTimeConverter().fromJson(json['dateTime'] as int); + ), + TrivialNumberConverter.instance.fromJson(json['numberSilly'] as int?), + (json['numberSillySet'] as List) + .map((e) => TrivialNumberConverter.instance.fromJson(e as int?)) + .toSet(), + const EpochDateTimeConverter().fromJson(json['dateTime'] as int?), + ); } Map _$JsonConverterTestClassToJson( @@ -147,38 +138,37 @@ Map _$JsonConverterTestClassToJson( { 'duration': durationConverter.toJson(instance.duration), 'durationList': - instance.durationList?.map(durationConverter.toJson)?.toList(), + instance.durationList.map(durationConverter.toJson).toList(), 'bigInt': const BigIntStringConverter().toJson(instance.bigInt), 'bigIntMap': instance.bigIntMap - ?.map((k, e) => MapEntry(k, const BigIntStringConverter().toJson(e))), + .map((k, e) => MapEntry(k, const BigIntStringConverter().toJson(e))), 'numberSilly': TrivialNumberConverter.instance.toJson(instance.numberSilly), 'numberSillySet': instance.numberSillySet - ?.map(TrivialNumberConverter.instance.toJson) - ?.toList(), + .map(TrivialNumberConverter.instance.toJson) + .toList(), 'dateTime': const EpochDateTimeConverter().toJson(instance.dateTime), }; JsonConverterGeneric _$JsonConverterGenericFromJson( Map json) { - return JsonConverterGeneric() - ..item = - GenericConverter().fromJson(json['item'] as Map) - ..itemList = (json['itemList'] as List) - ?.map((e) => GenericConverter().fromJson(e as Map)) - ?.toList() - ..itemMap = (json['itemMap'] as Map)?.map( + return JsonConverterGeneric( + GenericConverter().fromJson(json['item'] as Map), + (json['itemList'] as List) + .map((e) => GenericConverter().fromJson(e as Map)) + .toList(), + (json['itemMap'] as Map).map( (k, e) => MapEntry(k as String, GenericConverter().fromJson(e as Map)), - ); + ), + ); } Map _$JsonConverterGenericToJson( JsonConverterGeneric instance) => { 'item': GenericConverter().toJson(instance.item), - 'itemList': - instance.itemList?.map(GenericConverter().toJson)?.toList(), + 'itemList': instance.itemList.map(GenericConverter().toJson).toList(), 'itemMap': instance.itemMap - ?.map((k, e) => MapEntry(k, GenericConverter().toJson(e))), + .map((k, e) => MapEntry(k, GenericConverter().toJson(e))), }; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked__non_nullable.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.dart similarity index 75% rename from json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked__non_nullable.dart rename to json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.dart index dedc28fd4..0c751950d 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked__non_nullable.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.dart @@ -2,6 +2,8 @@ // 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. +// @dart=2.12 + // ignore_for_file: annotate_overrides, hash_and_equals import 'package:json_annotation/json_annotation.dart'; @@ -10,35 +12,44 @@ import 'kitchen_sink_interface.dart' as k; import 'simple_object.dart'; import 'strict_keys_object.dart'; -part 'kitchen_sink.g_any_map__checked__non_nullable.g.dart'; +part 'kitchen_sink.g_any_map__checked.g.dart'; // NOTE: these methods are replaced in the `non_nullable` cases to return // non-null values. -List _defaultList() => []; -Set _defaultSet() => {}; -Map _defaultMap() => {}; +List _defaultList() => []; + +Set _defaultSet() => {}; + +Map _defaultMap() => {}; + SimpleObject _defaultSimpleObject() => SimpleObject(42); -StrictKeysObject _defaultStrictKeysObject() => StrictKeysObject(10, 'cool'); + +StrictKeysObject _defaultStrictKeysObject() => StrictKeysObject(42, 'value'); const k.KitchenSinkFactory factory = _Factory(); class _Factory implements k.KitchenSinkFactory { const _Factory(); - String get description => 'any_map__checked__non_nullable'; + String get description => 'any_map__checked'; + bool get anyMap => true; + bool get checked => true; - bool get nullable => false; + + bool get nullable => true; + bool get excludeNull => false; + bool get explicitToJson => false; k.KitchenSink ctor({ - int ctorValidatedNo42, - Iterable iterable, - Iterable dynamicIterable, - Iterable objectIterable, - Iterable intIterable, - Iterable dateTimeIterable, + int? ctorValidatedNo42, + Iterable? iterable, + Iterable? dynamicIterable, + Iterable? objectIterable, + Iterable? intIterable, + Iterable? dateTimeIterable, }) => KitchenSink( ctorValidatedNo42: ctorValidatedNo42, @@ -51,37 +62,44 @@ class _Factory implements k.KitchenSinkFactory { k.KitchenSink fromJson(Map json) => KitchenSink.fromJson(json); - k.JsonConverterTestClass jsonConverterCtor() => JsonConverterTestClass(); + k.JsonConverterTestClass jsonConverterCtor() => JsonConverterTestClass( + const Duration(), + [], + BigInt.zero, + {}, + TrivialNumber(0), + {}, + DateTime.fromMillisecondsSinceEpoch(0), + ); k.JsonConverterTestClass jsonConverterFromJson(Map json) => JsonConverterTestClass.fromJson(json); } @JsonSerializable( - nullable: false, checked: true, anyMap: true, ) class KitchenSink implements k.KitchenSink { // NOTE: exposing these as Iterable, but storing the values as List // to make the equality test work trivially. - final Iterable _iterable; + final Iterable? _iterable; final Iterable _dynamicIterable; final Iterable _objectIterable; final Iterable _intIterable; final Iterable _dateTimeIterable; @JsonKey(name: 'no-42') - final int ctorValidatedNo42; + final int? ctorValidatedNo42; KitchenSink({ this.ctorValidatedNo42, - Iterable iterable, - Iterable dynamicIterable, - Iterable objectIterable, - Iterable intIterable, - Iterable dateTimeIterable, - }) : _iterable = iterable?.toList() ?? _defaultList(), + Iterable? iterable, + Iterable? dynamicIterable, + Iterable? objectIterable, + Iterable? intIterable, + Iterable? dateTimeIterable, + }) : _iterable = iterable?.toList(), _dynamicIterable = dynamicIterable?.toList() ?? _defaultList(), _objectIterable = objectIterable?.toList() ?? _defaultList(), _intIterable = intIterable?.toList() ?? _defaultList(), @@ -96,13 +114,16 @@ class KitchenSink implements k.KitchenSink { Map toJson() => _$KitchenSinkToJson(this); - DateTime dateTime = DateTime(1981, 6, 5); + DateTime? dateTime; + + BigInt? bigInt; - BigInt bigInt = BigInt.parse('10000000000000000000'); + Iterable? get iterable => _iterable; - Iterable get iterable => _iterable; Iterable get dynamicIterable => _dynamicIterable; + Iterable get objectIterable => _objectIterable; + Iterable get intIterable => _intIterable; Set set = _defaultSet(); @@ -126,23 +147,24 @@ class KitchenSink implements k.KitchenSink { Map dynamicIntMap = _defaultMap(); Map objectDateTimeMap = _defaultMap(); - List>>>> crazyComplex = + List?>?>?>?> crazyComplex = _defaultList(); // Handle fields with names that collide with helper names Map val = _defaultMap(); - bool writeNotNull; + bool? writeNotNull; @JsonKey(name: r'$string') - String string; + String? string; SimpleObject simpleObject = _defaultSimpleObject(); StrictKeysObject strictKeysObject = _defaultStrictKeysObject(); - int _validatedPropertyNo42; - int get validatedPropertyNo42 => _validatedPropertyNo42; + int? _validatedPropertyNo42; + + int? get validatedPropertyNo42 => _validatedPropertyNo42; - set validatedPropertyNo42(int value) { + set validatedPropertyNo42(int? value) { if (value == 42) { throw StateError('Cannot be 42!'); } @@ -153,7 +175,6 @@ class KitchenSink implements k.KitchenSink { } @JsonSerializable( - nullable: false, checked: true, anyMap: true, ) @@ -164,27 +185,34 @@ class KitchenSink implements k.KitchenSink { @TrivialNumberConverter.instance @EpochDateTimeConverter() class JsonConverterTestClass implements k.JsonConverterTestClass { - JsonConverterTestClass(); + JsonConverterTestClass( + this.duration, + this.durationList, + this.bigInt, + this.bigIntMap, + this.numberSilly, + this.numberSillySet, + this.dateTime, + ); factory JsonConverterTestClass.fromJson(Map json) => _$JsonConverterTestClassFromJson(json); Map toJson() => _$JsonConverterTestClassToJson(this); - Duration duration; - List durationList; + Duration? duration; + List durationList; - BigInt bigInt = BigInt.parse('10000000000000000000'); + BigInt bigInt; Map bigIntMap; TrivialNumber numberSilly; Set numberSillySet; - DateTime dateTime = DateTime(1981, 6, 5); + DateTime? dateTime; } @JsonSerializable( - nullable: false, checked: true, anyMap: true, ) @@ -194,7 +222,11 @@ class JsonConverterGeneric { List itemList; Map itemMap; - JsonConverterGeneric(); + JsonConverterGeneric( + this.item, + this.itemList, + this.itemMap, + ); factory JsonConverterGeneric.fromJson(Map json) => _$JsonConverterGenericFromJson(json); diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked__non_nullable.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.g.dart similarity index 56% rename from json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked__non_nullable.g.dart rename to json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.g.dart index ec4f758f2..3ff15a43b 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked__non_nullable.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.g.dart @@ -1,6 +1,7 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// @dart=2.12 -part of 'kitchen_sink.g_any_map__checked__non_nullable.dart'; +part of 'kitchen_sink.g_any_map__checked.dart'; // ************************************************************************** // JsonSerializableGenerator @@ -9,42 +10,59 @@ part of 'kitchen_sink.g_any_map__checked__non_nullable.dart'; KitchenSink _$KitchenSinkFromJson(Map json) { return $checkedNew('KitchenSink', json, () { final val = KitchenSink( - ctorValidatedNo42: $checkedConvert(json, 'no-42', (v) => v as int), - iterable: $checkedConvert(json, 'iterable', (v) => v as List), + ctorValidatedNo42: $checkedConvert(json, 'no-42', (v) => v as int?), + iterable: $checkedConvert(json, 'iterable', (v) => v as List?), dynamicIterable: - $checkedConvert(json, 'dynamicIterable', (v) => v as List), - objectIterable: $checkedConvert(json, 'objectIterable', (v) => v as List), - intIterable: $checkedConvert( - json, 'intIterable', (v) => (v as List).map((e) => e as int)), - dateTimeIterable: $checkedConvert(json, 'datetime-iterable', - (v) => (v as List).map((e) => DateTime.parse(e as String))), + $checkedConvert(json, 'dynamicIterable', (v) => v as List?), + objectIterable: $checkedConvert(json, 'objectIterable', + (v) => (v as List?)?.map((e) => e as Object)), + intIterable: $checkedConvert(json, 'intIterable', + (v) => (v as List?)?.map((e) => e as int)), + dateTimeIterable: $checkedConvert( + json, + 'datetime-iterable', + (v) => + (v as List?)?.map((e) => DateTime.parse(e as String))), ); + $checkedConvert(json, 'dateTime', + (v) => val.dateTime = v == null ? null : DateTime.parse(v as String)); + $checkedConvert(json, 'bigInt', + (v) => val.bigInt = v == null ? null : BigInt.parse(v as String)); + $checkedConvert(json, 'set', (v) => val.set = (v as List).toSet()); + $checkedConvert(json, 'dynamicSet', + (v) => val.dynamicSet = (v as List).toSet()); $checkedConvert( - json, 'dateTime', (v) => val.dateTime = DateTime.parse(v as String)); + json, + 'objectSet', + (v) => val.objectSet = + (v as List).map((e) => e as Object).toSet()); + $checkedConvert(json, 'intSet', + (v) => val.intSet = (v as List).map((e) => e as int).toSet()); $checkedConvert( - json, 'bigInt', (v) => val.bigInt = BigInt.parse(v as String)); - $checkedConvert(json, 'set', (v) => val.set = (v as List).toSet()); + json, + 'dateTimeSet', + (v) => val.dateTimeSet = (v as List) + .map((e) => DateTime.parse(e as String)) + .toSet()); + $checkedConvert(json, 'list', (v) => val.list = v as List); $checkedConvert( - json, 'dynamicSet', (v) => val.dynamicSet = (v as List).toSet()); + json, 'dynamicList', (v) => val.dynamicList = v as List); $checkedConvert( - json, 'objectSet', (v) => val.objectSet = (v as List).toSet()); - $checkedConvert(json, 'intSet', - (v) => val.intSet = (v as List).map((e) => e as int).toSet()); + json, + 'objectList', + (v) => val.objectList = + (v as List).map((e) => e as Object).toList()); $checkedConvert( json, - 'dateTimeSet', - (v) => val.dateTimeSet = - (v as List).map((e) => DateTime.parse(e as String)).toSet()); - $checkedConvert(json, 'list', (v) => val.list = v as List); - $checkedConvert(json, 'dynamicList', (v) => val.dynamicList = v as List); - $checkedConvert(json, 'objectList', (v) => val.objectList = v as List); - $checkedConvert(json, 'intList', - (v) => val.intList = (v as List).map((e) => e as int).toList()); + 'intList', + (v) => + val.intList = (v as List).map((e) => e as int).toList()); $checkedConvert( json, 'dateTimeList', - (v) => val.dateTimeList = - (v as List).map((e) => DateTime.parse(e as String)).toList()); + (v) => val.dateTimeList = (v as List) + .map((e) => DateTime.parse(e as String)) + .toList()); $checkedConvert(json, 'map', (v) => val.map = v as Map); $checkedConvert(json, 'stringStringMap', (v) => val.stringStringMap = Map.from(v as Map)); @@ -54,21 +72,21 @@ KitchenSink _$KitchenSinkFromJson(Map json) { json, 'objectDateTimeMap', (v) => val.objectDateTimeMap = (v as Map).map( - (k, e) => MapEntry(k, DateTime.parse(e as String)), + (k, e) => MapEntry(k as Object, DateTime.parse(e as String)), )); $checkedConvert( json, 'crazyComplex', - (v) => val.crazyComplex = (v as List) - .map((e) => (e as Map).map( + (v) => val.crazyComplex = (v as List) + .map((e) => (e as Map?)?.map( (k, e) => MapEntry( k as String, - (e as Map).map( + (e as Map?)?.map( (k, e) => MapEntry( k as String, - (e as List) - .map((e) => (e as List) - .map((e) => DateTime.parse(e as String)) + (e as List?) + ?.map((e) => (e as List?) + ?.map((e) => DateTime.parse(e as String)) .toList()) .toList()), )), @@ -76,14 +94,14 @@ KitchenSink _$KitchenSinkFromJson(Map json) { .toList()); $checkedConvert( json, 'val', (v) => val.val = Map.from(v as Map)); - $checkedConvert(json, 'writeNotNull', (v) => val.writeNotNull = v as bool); - $checkedConvert(json, r'$string', (v) => val.string = v as String); + $checkedConvert(json, 'writeNotNull', (v) => val.writeNotNull = v as bool?); + $checkedConvert(json, r'$string', (v) => val.string = v as String?); $checkedConvert(json, 'simpleObject', (v) => val.simpleObject = SimpleObject.fromJson(v as Map)); $checkedConvert(json, 'strictKeysObject', (v) => val.strictKeysObject = StrictKeysObject.fromJson(v as Map)); $checkedConvert(json, 'validatedPropertyNo42', - (v) => val.validatedPropertyNo42 = v as int); + (v) => val.validatedPropertyNo42 = v as int?); return val; }, fieldKeyMap: const { 'ctorValidatedNo42': 'no-42', @@ -95,9 +113,9 @@ KitchenSink _$KitchenSinkFromJson(Map json) { Map _$KitchenSinkToJson(KitchenSink instance) => { 'no-42': instance.ctorValidatedNo42, - 'dateTime': instance.dateTime.toIso8601String(), - 'bigInt': instance.bigInt.toString(), - 'iterable': instance.iterable.toList(), + 'dateTime': instance.dateTime?.toIso8601String(), + 'bigInt': instance.bigInt?.toString(), + 'iterable': instance.iterable?.toList(), 'dynamicIterable': instance.dynamicIterable.toList(), 'objectIterable': instance.objectIterable.toList(), 'intIterable': instance.intIterable.toList(), @@ -121,12 +139,12 @@ Map _$KitchenSinkToJson(KitchenSink instance) => 'objectDateTimeMap': instance.objectDateTimeMap .map((k, e) => MapEntry(k, e.toIso8601String())), 'crazyComplex': instance.crazyComplex - .map((e) => e.map((k, e) => MapEntry( + .map((e) => e?.map((k, e) => MapEntry( k, - e.map((k, e) => MapEntry( + e?.map((k, e) => MapEntry( k, e - .map((e) => e.map((e) => e.toIso8601String()).toList()) + ?.map((e) => e?.map((e) => e.toIso8601String()).toList()) .toList()))))) .toList(), 'val': instance.val, @@ -139,43 +157,35 @@ Map _$KitchenSinkToJson(KitchenSink instance) => JsonConverterTestClass _$JsonConverterTestClassFromJson(Map json) { return $checkedNew('JsonConverterTestClass', json, () { - final val = JsonConverterTestClass(); - $checkedConvert(json, 'duration', - (v) => val.duration = durationConverter.fromJson(v as int)); - $checkedConvert( - json, - 'durationList', - (v) => val.durationList = (v as List) - .map((e) => durationConverter.fromJson(e as int)) - .toList()); - $checkedConvert( - json, - 'bigInt', - (v) => - val.bigInt = const BigIntStringConverter().fromJson(v as String)); - $checkedConvert( - json, - 'bigIntMap', - (v) => val.bigIntMap = (v as Map).map( - (k, e) => MapEntry(k as String, - const BigIntStringConverter().fromJson(e as String)), - )); - $checkedConvert( - json, - 'numberSilly', - (v) => val.numberSilly = - TrivialNumberConverter.instance.fromJson(v as int)); - $checkedConvert( - json, - 'numberSillySet', - (v) => val.numberSillySet = (v as List) - .map((e) => TrivialNumberConverter.instance.fromJson(e as int)) - .toSet()); - $checkedConvert( - json, - 'dateTime', - (v) => - val.dateTime = const EpochDateTimeConverter().fromJson(v as int)); + final val = JsonConverterTestClass( + $checkedConvert( + json, 'duration', (v) => durationConverter.fromJson(v as int?)), + $checkedConvert( + json, + 'durationList', + (v) => (v as List) + .map((e) => durationConverter.fromJson(e as int?)) + .toList()), + $checkedConvert(json, 'bigInt', + (v) => const BigIntStringConverter().fromJson(v as String)), + $checkedConvert( + json, + 'bigIntMap', + (v) => (v as Map).map( + (k, e) => MapEntry(k as String, + const BigIntStringConverter().fromJson(e as String)), + )), + $checkedConvert(json, 'numberSilly', + (v) => TrivialNumberConverter.instance.fromJson(v as int?)), + $checkedConvert( + json, + 'numberSillySet', + (v) => (v as List) + .map((e) => TrivialNumberConverter.instance.fromJson(e as int?)) + .toSet()), + $checkedConvert(json, 'dateTime', + (v) => const EpochDateTimeConverter().fromJson(v as int?)), + ); return val; }); } @@ -200,26 +210,24 @@ Map _$JsonConverterTestClassToJson( JsonConverterGeneric _$JsonConverterGenericFromJson( Map json) { return $checkedNew('JsonConverterGeneric', json, () { - final val = JsonConverterGeneric(); - $checkedConvert( - json, - 'item', - (v) => val.item = - GenericConverter().fromJson(v as Map)); - $checkedConvert( - json, - 'itemList', - (v) => val.itemList = (v as List) - .map((e) => - GenericConverter().fromJson(e as Map)) - .toList()); - $checkedConvert( - json, - 'itemMap', - (v) => val.itemMap = (v as Map).map( - (k, e) => MapEntry(k as String, - GenericConverter().fromJson(e as Map)), - )); + final val = JsonConverterGeneric( + $checkedConvert(json, 'item', + (v) => GenericConverter().fromJson(v as Map)), + $checkedConvert( + json, + 'itemList', + (v) => (v as List) + .map((e) => + GenericConverter().fromJson(e as Map)) + .toList()), + $checkedConvert( + json, + 'itemMap', + (v) => (v as Map).map( + (k, e) => MapEntry(k as String, + GenericConverter().fromJson(e as Map)), + )), + ); return val; }); } diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable.dart deleted file mode 100644 index 7185c5243..000000000 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable.dart +++ /dev/null @@ -1,200 +0,0 @@ -// Copyright (c) 2018, 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. - -// ignore_for_file: annotate_overrides, hash_and_equals -import 'package:json_annotation/json_annotation.dart'; - -import 'json_converters.dart'; -import 'kitchen_sink_interface.dart' as k; -import 'simple_object.dart'; -import 'strict_keys_object.dart'; - -part 'kitchen_sink.g_any_map__non_nullable.g.dart'; - -// NOTE: these methods are replaced in the `non_nullable` cases to return -// non-null values. -List _defaultList() => []; -Set _defaultSet() => {}; -Map _defaultMap() => {}; -SimpleObject _defaultSimpleObject() => SimpleObject(42); -StrictKeysObject _defaultStrictKeysObject() => StrictKeysObject(10, 'cool'); - -const k.KitchenSinkFactory factory = _Factory(); - -class _Factory implements k.KitchenSinkFactory { - const _Factory(); - - String get description => 'any_map__non_nullable'; - bool get anyMap => true; - bool get checked => false; - bool get nullable => false; - bool get excludeNull => false; - bool get explicitToJson => false; - - k.KitchenSink ctor({ - int ctorValidatedNo42, - Iterable iterable, - Iterable dynamicIterable, - Iterable objectIterable, - Iterable intIterable, - Iterable dateTimeIterable, - }) => - KitchenSink( - ctorValidatedNo42: ctorValidatedNo42, - iterable: iterable, - dynamicIterable: dynamicIterable, - objectIterable: objectIterable, - intIterable: intIterable, - dateTimeIterable: dateTimeIterable, - ); - - k.KitchenSink fromJson(Map json) => KitchenSink.fromJson(json); - - k.JsonConverterTestClass jsonConverterCtor() => JsonConverterTestClass(); - - k.JsonConverterTestClass jsonConverterFromJson(Map json) => - JsonConverterTestClass.fromJson(json); -} - -@JsonSerializable( - nullable: false, - anyMap: true, -) -class KitchenSink implements k.KitchenSink { - // NOTE: exposing these as Iterable, but storing the values as List - // to make the equality test work trivially. - final Iterable _iterable; - final Iterable _dynamicIterable; - final Iterable _objectIterable; - final Iterable _intIterable; - final Iterable _dateTimeIterable; - - @JsonKey(name: 'no-42') - final int ctorValidatedNo42; - - KitchenSink({ - this.ctorValidatedNo42, - Iterable iterable, - Iterable dynamicIterable, - Iterable objectIterable, - Iterable intIterable, - Iterable dateTimeIterable, - }) : _iterable = iterable?.toList() ?? _defaultList(), - _dynamicIterable = dynamicIterable?.toList() ?? _defaultList(), - _objectIterable = objectIterable?.toList() ?? _defaultList(), - _intIterable = intIterable?.toList() ?? _defaultList(), - _dateTimeIterable = dateTimeIterable?.toList() ?? _defaultList() { - if (ctorValidatedNo42 == 42) { - throw ArgumentError.value( - 42, 'ctorValidatedNo42', 'The value `42` is not allowed.'); - } - } - - factory KitchenSink.fromJson(Map json) => _$KitchenSinkFromJson(json); - - Map toJson() => _$KitchenSinkToJson(this); - - DateTime dateTime = DateTime(1981, 6, 5); - - BigInt bigInt = BigInt.parse('10000000000000000000'); - - Iterable get iterable => _iterable; - Iterable get dynamicIterable => _dynamicIterable; - Iterable get objectIterable => _objectIterable; - Iterable get intIterable => _intIterable; - - Set set = _defaultSet(); - Set dynamicSet = _defaultSet(); - Set objectSet = _defaultSet(); - Set intSet = _defaultSet(); - Set dateTimeSet = _defaultSet(); - - // Added a one-off annotation on a property (not a field) - @JsonKey(name: 'datetime-iterable') - Iterable get dateTimeIterable => _dateTimeIterable; - - List list = _defaultList(); - List dynamicList = _defaultList(); - List objectList = _defaultList(); - List intList = _defaultList(); - List dateTimeList = _defaultList(); - - Map map = _defaultMap(); - Map stringStringMap = _defaultMap(); - Map dynamicIntMap = _defaultMap(); - Map objectDateTimeMap = _defaultMap(); - - List>>>> crazyComplex = - _defaultList(); - - // Handle fields with names that collide with helper names - Map val = _defaultMap(); - bool writeNotNull; - @JsonKey(name: r'$string') - String string; - - SimpleObject simpleObject = _defaultSimpleObject(); - - StrictKeysObject strictKeysObject = _defaultStrictKeysObject(); - - int _validatedPropertyNo42; - int get validatedPropertyNo42 => _validatedPropertyNo42; - - set validatedPropertyNo42(int value) { - if (value == 42) { - throw StateError('Cannot be 42!'); - } - _validatedPropertyNo42 = value; - } - - bool operator ==(Object other) => k.sinkEquals(this, other); -} - -@JsonSerializable( - nullable: false, - anyMap: true, -) -// referencing a top-level field should work -@durationConverter -// referencing via a const constructor should work -@BigIntStringConverter() -@TrivialNumberConverter.instance -@EpochDateTimeConverter() -class JsonConverterTestClass implements k.JsonConverterTestClass { - JsonConverterTestClass(); - - factory JsonConverterTestClass.fromJson(Map json) => - _$JsonConverterTestClassFromJson(json); - - Map toJson() => _$JsonConverterTestClassToJson(this); - - Duration duration; - List durationList; - - BigInt bigInt = BigInt.parse('10000000000000000000'); - Map bigIntMap; - - TrivialNumber numberSilly; - Set numberSillySet; - - DateTime dateTime = DateTime(1981, 6, 5); -} - -@JsonSerializable( - nullable: false, - anyMap: true, -) -@GenericConverter() -class JsonConverterGeneric { - S item; - List itemList; - Map itemMap; - - JsonConverterGeneric(); - - factory JsonConverterGeneric.fromJson(Map json) => - _$JsonConverterGenericFromJson(json); - - Map toJson() => _$JsonConverterGenericToJson(this); -} diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable.g.dart deleted file mode 100644 index e06c0f1be..000000000 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__non_nullable.g.dart +++ /dev/null @@ -1,168 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'kitchen_sink.g_any_map__non_nullable.dart'; - -// ************************************************************************** -// JsonSerializableGenerator -// ************************************************************************** - -KitchenSink _$KitchenSinkFromJson(Map json) { - return KitchenSink( - ctorValidatedNo42: json['no-42'] as int, - iterable: json['iterable'] as List, - dynamicIterable: json['dynamicIterable'] as List, - objectIterable: json['objectIterable'] as List, - intIterable: (json['intIterable'] as List).map((e) => e as int), - dateTimeIterable: (json['datetime-iterable'] as List) - .map((e) => DateTime.parse(e as String)), - ) - ..dateTime = DateTime.parse(json['dateTime'] as String) - ..bigInt = BigInt.parse(json['bigInt'] as String) - ..set = (json['set'] as List).toSet() - ..dynamicSet = (json['dynamicSet'] as List).toSet() - ..objectSet = (json['objectSet'] as List).toSet() - ..intSet = (json['intSet'] as List).map((e) => e as int).toSet() - ..dateTimeSet = (json['dateTimeSet'] as List) - .map((e) => DateTime.parse(e as String)) - .toSet() - ..list = json['list'] as List - ..dynamicList = json['dynamicList'] as List - ..objectList = json['objectList'] as List - ..intList = (json['intList'] as List).map((e) => e as int).toList() - ..dateTimeList = (json['dateTimeList'] as List) - .map((e) => DateTime.parse(e as String)) - .toList() - ..map = json['map'] as Map - ..stringStringMap = Map.from(json['stringStringMap'] as Map) - ..dynamicIntMap = Map.from(json['dynamicIntMap'] as Map) - ..objectDateTimeMap = (json['objectDateTimeMap'] as Map).map( - (k, e) => MapEntry(k, DateTime.parse(e as String)), - ) - ..crazyComplex = (json['crazyComplex'] as List) - .map((e) => (e as Map).map( - (k, e) => MapEntry( - k as String, - (e as Map).map( - (k, e) => MapEntry( - k as String, - (e as List) - .map((e) => (e as List) - .map((e) => DateTime.parse(e as String)) - .toList()) - .toList()), - )), - )) - .toList() - ..val = Map.from(json['val'] as Map) - ..writeNotNull = json['writeNotNull'] as bool - ..string = json[r'$string'] as String - ..simpleObject = SimpleObject.fromJson(json['simpleObject'] as Map) - ..strictKeysObject = - StrictKeysObject.fromJson(json['strictKeysObject'] as Map) - ..validatedPropertyNo42 = json['validatedPropertyNo42'] as int; -} - -Map _$KitchenSinkToJson(KitchenSink instance) => - { - 'no-42': instance.ctorValidatedNo42, - 'dateTime': instance.dateTime.toIso8601String(), - 'bigInt': instance.bigInt.toString(), - 'iterable': instance.iterable.toList(), - 'dynamicIterable': instance.dynamicIterable.toList(), - 'objectIterable': instance.objectIterable.toList(), - 'intIterable': instance.intIterable.toList(), - 'set': instance.set.toList(), - 'dynamicSet': instance.dynamicSet.toList(), - 'objectSet': instance.objectSet.toList(), - 'intSet': instance.intSet.toList(), - 'dateTimeSet': - instance.dateTimeSet.map((e) => e.toIso8601String()).toList(), - 'datetime-iterable': - instance.dateTimeIterable.map((e) => e.toIso8601String()).toList(), - 'list': instance.list, - 'dynamicList': instance.dynamicList, - 'objectList': instance.objectList, - 'intList': instance.intList, - 'dateTimeList': - instance.dateTimeList.map((e) => e.toIso8601String()).toList(), - 'map': instance.map, - 'stringStringMap': instance.stringStringMap, - 'dynamicIntMap': instance.dynamicIntMap, - 'objectDateTimeMap': instance.objectDateTimeMap - .map((k, e) => MapEntry(k, e.toIso8601String())), - 'crazyComplex': instance.crazyComplex - .map((e) => e.map((k, e) => MapEntry( - k, - e.map((k, e) => MapEntry( - k, - e - .map((e) => e.map((e) => e.toIso8601String()).toList()) - .toList()))))) - .toList(), - 'val': instance.val, - 'writeNotNull': instance.writeNotNull, - r'$string': instance.string, - 'simpleObject': instance.simpleObject, - 'strictKeysObject': instance.strictKeysObject, - 'validatedPropertyNo42': instance.validatedPropertyNo42, - }; - -JsonConverterTestClass _$JsonConverterTestClassFromJson(Map json) { - return JsonConverterTestClass() - ..duration = durationConverter.fromJson(json['duration'] as int) - ..durationList = (json['durationList'] as List) - .map((e) => durationConverter.fromJson(e as int)) - .toList() - ..bigInt = const BigIntStringConverter().fromJson(json['bigInt'] as String) - ..bigIntMap = (json['bigIntMap'] as Map).map( - (k, e) => MapEntry( - k as String, const BigIntStringConverter().fromJson(e as String)), - ) - ..numberSilly = - TrivialNumberConverter.instance.fromJson(json['numberSilly'] as int) - ..numberSillySet = (json['numberSillySet'] as List) - .map((e) => TrivialNumberConverter.instance.fromJson(e as int)) - .toSet() - ..dateTime = - const EpochDateTimeConverter().fromJson(json['dateTime'] as int); -} - -Map _$JsonConverterTestClassToJson( - JsonConverterTestClass instance) => - { - 'duration': durationConverter.toJson(instance.duration), - 'durationList': - instance.durationList.map(durationConverter.toJson).toList(), - 'bigInt': const BigIntStringConverter().toJson(instance.bigInt), - 'bigIntMap': instance.bigIntMap - .map((k, e) => MapEntry(k, const BigIntStringConverter().toJson(e))), - 'numberSilly': - TrivialNumberConverter.instance.toJson(instance.numberSilly), - 'numberSillySet': instance.numberSillySet - .map(TrivialNumberConverter.instance.toJson) - .toList(), - 'dateTime': const EpochDateTimeConverter().toJson(instance.dateTime), - }; - -JsonConverterGeneric _$JsonConverterGenericFromJson( - Map json) { - return JsonConverterGeneric() - ..item = - GenericConverter().fromJson(json['item'] as Map) - ..itemList = (json['itemList'] as List) - .map((e) => GenericConverter().fromJson(e as Map)) - .toList() - ..itemMap = (json['itemMap'] as Map).map( - (k, e) => MapEntry(k as String, - GenericConverter().fromJson(e as Map)), - ); -} - -Map _$JsonConverterGenericToJson( - JsonConverterGeneric instance) => - { - 'item': GenericConverter().toJson(instance.item), - 'itemList': instance.itemList.map(GenericConverter().toJson).toList(), - 'itemMap': instance.itemMap - .map((k, e) => MapEntry(k, GenericConverter().toJson(e))), - }; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.dart index 27cedf69b..70c60859b 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.dart @@ -2,6 +2,8 @@ // 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. +// @dart=2.12 + // ignore_for_file: annotate_overrides, hash_and_equals import 'package:json_annotation/json_annotation.dart'; @@ -14,11 +16,15 @@ part 'kitchen_sink.g_exclude_null.g.dart'; // NOTE: these methods are replaced in the `non_nullable` cases to return // non-null values. -List _defaultList() => null; -Set _defaultSet() => null; -Map _defaultMap() => null; -SimpleObject _defaultSimpleObject() => null; -StrictKeysObject _defaultStrictKeysObject() => null; +List _defaultList() => []; + +Set _defaultSet() => {}; + +Map _defaultMap() => {}; + +SimpleObject _defaultSimpleObject() => SimpleObject(42); + +StrictKeysObject _defaultStrictKeysObject() => StrictKeysObject(42, 'value'); const k.KitchenSinkFactory factory = _Factory(); @@ -26,19 +32,24 @@ class _Factory implements k.KitchenSinkFactory { const _Factory(); String get description => 'exclude_null'; + bool get anyMap => false; + bool get checked => false; + bool get nullable => true; + bool get excludeNull => true; + bool get explicitToJson => false; k.KitchenSink ctor({ - int ctorValidatedNo42, - Iterable iterable, - Iterable dynamicIterable, - Iterable objectIterable, - Iterable intIterable, - Iterable dateTimeIterable, + int? ctorValidatedNo42, + Iterable? iterable, + Iterable? dynamicIterable, + Iterable? objectIterable, + Iterable? intIterable, + Iterable? dateTimeIterable, }) => KitchenSink( ctorValidatedNo42: ctorValidatedNo42, @@ -52,7 +63,15 @@ class _Factory implements k.KitchenSinkFactory { k.KitchenSink fromJson(Map json) => KitchenSink.fromJson(json); - k.JsonConverterTestClass jsonConverterCtor() => JsonConverterTestClass(); + k.JsonConverterTestClass jsonConverterCtor() => JsonConverterTestClass( + const Duration(), + [], + BigInt.zero, + {}, + TrivialNumber(0), + {}, + DateTime.fromMillisecondsSinceEpoch(0), + ); k.JsonConverterTestClass jsonConverterFromJson(Map json) => JsonConverterTestClass.fromJson(json); @@ -64,23 +83,23 @@ class _Factory implements k.KitchenSinkFactory { class KitchenSink implements k.KitchenSink { // NOTE: exposing these as Iterable, but storing the values as List // to make the equality test work trivially. - final Iterable _iterable; + final Iterable? _iterable; final Iterable _dynamicIterable; final Iterable _objectIterable; final Iterable _intIterable; final Iterable _dateTimeIterable; @JsonKey(name: 'no-42') - final int ctorValidatedNo42; + final int? ctorValidatedNo42; KitchenSink({ this.ctorValidatedNo42, - Iterable iterable, - Iterable dynamicIterable, - Iterable objectIterable, - Iterable intIterable, - Iterable dateTimeIterable, - }) : _iterable = iterable?.toList() ?? _defaultList(), + Iterable? iterable, + Iterable? dynamicIterable, + Iterable? objectIterable, + Iterable? intIterable, + Iterable? dateTimeIterable, + }) : _iterable = iterable?.toList(), _dynamicIterable = dynamicIterable?.toList() ?? _defaultList(), _objectIterable = objectIterable?.toList() ?? _defaultList(), _intIterable = intIterable?.toList() ?? _defaultList(), @@ -96,13 +115,16 @@ class KitchenSink implements k.KitchenSink { Map toJson() => _$KitchenSinkToJson(this); - DateTime dateTime; + DateTime? dateTime; - BigInt bigInt; + BigInt? bigInt; + + Iterable? get iterable => _iterable; - Iterable get iterable => _iterable; Iterable get dynamicIterable => _dynamicIterable; + Iterable get objectIterable => _objectIterable; + Iterable get intIterable => _intIterable; Set set = _defaultSet(); @@ -126,23 +148,24 @@ class KitchenSink implements k.KitchenSink { Map dynamicIntMap = _defaultMap(); Map objectDateTimeMap = _defaultMap(); - List>>>> crazyComplex = + List?>?>?>?> crazyComplex = _defaultList(); // Handle fields with names that collide with helper names Map val = _defaultMap(); - bool writeNotNull; + bool? writeNotNull; @JsonKey(name: r'$string') - String string; + String? string; SimpleObject simpleObject = _defaultSimpleObject(); StrictKeysObject strictKeysObject = _defaultStrictKeysObject(); - int _validatedPropertyNo42; - int get validatedPropertyNo42 => _validatedPropertyNo42; + int? _validatedPropertyNo42; + + int? get validatedPropertyNo42 => _validatedPropertyNo42; - set validatedPropertyNo42(int value) { + set validatedPropertyNo42(int? value) { if (value == 42) { throw StateError('Cannot be 42!'); } @@ -162,15 +185,23 @@ class KitchenSink implements k.KitchenSink { @TrivialNumberConverter.instance @EpochDateTimeConverter() class JsonConverterTestClass implements k.JsonConverterTestClass { - JsonConverterTestClass(); + JsonConverterTestClass( + this.duration, + this.durationList, + this.bigInt, + this.bigIntMap, + this.numberSilly, + this.numberSillySet, + this.dateTime, + ); factory JsonConverterTestClass.fromJson(Map json) => _$JsonConverterTestClassFromJson(json); Map toJson() => _$JsonConverterTestClassToJson(this); - Duration duration; - List durationList; + Duration? duration; + List durationList; BigInt bigInt; Map bigIntMap; @@ -178,7 +209,7 @@ class JsonConverterTestClass implements k.JsonConverterTestClass { TrivialNumber numberSilly; Set numberSillySet; - DateTime dateTime; + DateTime? dateTime; } @JsonSerializable( @@ -190,7 +221,11 @@ class JsonConverterGeneric { List itemList; Map itemMap; - JsonConverterGeneric(); + JsonConverterGeneric( + this.item, + this.itemList, + this.itemMap, + ); factory JsonConverterGeneric.fromJson(Map json) => _$JsonConverterGenericFromJson(json); diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart index 52c5be511..fdc362702 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart @@ -1,4 +1,5 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// @dart=2.12 part of 'kitchen_sink.g_exclude_null.dart'; @@ -8,74 +9,66 @@ part of 'kitchen_sink.g_exclude_null.dart'; KitchenSink _$KitchenSinkFromJson(Map json) { return KitchenSink( - ctorValidatedNo42: json['no-42'] as int, - iterable: json['iterable'] as List, - dynamicIterable: json['dynamicIterable'] as List, - objectIterable: json['objectIterable'] as List, - intIterable: (json['intIterable'] as List)?.map((e) => e as int), - dateTimeIterable: (json['datetime-iterable'] as List) - ?.map((e) => e == null ? null : DateTime.parse(e as String)), + ctorValidatedNo42: json['no-42'] as int?, + iterable: json['iterable'] as List?, + dynamicIterable: json['dynamicIterable'] as List?, + objectIterable: + (json['objectIterable'] as List?)?.map((e) => e as Object), + intIterable: (json['intIterable'] as List?)?.map((e) => e as int), + dateTimeIterable: (json['datetime-iterable'] as List?) + ?.map((e) => DateTime.parse(e as String)), ) ..dateTime = json['dateTime'] == null ? null : DateTime.parse(json['dateTime'] as String) ..bigInt = json['bigInt'] == null ? null : BigInt.parse(json['bigInt'] as String) - ..set = (json['set'] as List)?.toSet() - ..dynamicSet = (json['dynamicSet'] as List)?.toSet() - ..objectSet = (json['objectSet'] as List)?.toSet() - ..intSet = (json['intSet'] as List)?.map((e) => e as int)?.toSet() - ..dateTimeSet = (json['dateTimeSet'] as List) - ?.map((e) => e == null ? null : DateTime.parse(e as String)) - ?.toSet() - ..list = json['list'] as List - ..dynamicList = json['dynamicList'] as List - ..objectList = json['objectList'] as List - ..intList = (json['intList'] as List)?.map((e) => e as int)?.toList() - ..dateTimeList = (json['dateTimeList'] as List) - ?.map((e) => e == null ? null : DateTime.parse(e as String)) - ?.toList() + ..set = (json['set'] as List).toSet() + ..dynamicSet = (json['dynamicSet'] as List).toSet() + ..objectSet = + (json['objectSet'] as List).map((e) => e as Object).toSet() + ..intSet = (json['intSet'] as List).map((e) => e as int).toSet() + ..dateTimeSet = (json['dateTimeSet'] as List) + .map((e) => DateTime.parse(e as String)) + .toSet() + ..list = json['list'] as List + ..dynamicList = json['dynamicList'] as List + ..objectList = + (json['objectList'] as List).map((e) => e as Object).toList() + ..intList = (json['intList'] as List).map((e) => e as int).toList() + ..dateTimeList = (json['dateTimeList'] as List) + .map((e) => DateTime.parse(e as String)) + .toList() ..map = json['map'] as Map - ..stringStringMap = (json['stringStringMap'] as Map)?.map( - (k, e) => MapEntry(k, e as String), - ) - ..dynamicIntMap = (json['dynamicIntMap'] as Map)?.map( - (k, e) => MapEntry(k, e as int), - ) + ..stringStringMap = Map.from(json['stringStringMap'] as Map) + ..dynamicIntMap = Map.from(json['dynamicIntMap'] as Map) ..objectDateTimeMap = - (json['objectDateTimeMap'] as Map)?.map( - (k, e) => MapEntry(k, e == null ? null : DateTime.parse(e as String)), + (json['objectDateTimeMap'] as Map).map( + (k, e) => MapEntry(k, DateTime.parse(e as String)), ) - ..crazyComplex = (json['crazyComplex'] as List) - ?.map((e) => (e as Map)?.map( + ..crazyComplex = (json['crazyComplex'] as List) + .map((e) => (e as Map?)?.map( (k, e) => MapEntry( k, - (e as Map)?.map( + (e as Map?)?.map( (k, e) => MapEntry( k, - (e as List) - ?.map((e) => (e as List) - ?.map((e) => e == null - ? null - : DateTime.parse(e as String)) - ?.toList()) - ?.toList()), + (e as List?) + ?.map((e) => (e as List?) + ?.map((e) => DateTime.parse(e as String)) + .toList()) + .toList()), )), )) - ?.toList() - ..val = (json['val'] as Map)?.map( - (k, e) => MapEntry(k, e as bool), - ) - ..writeNotNull = json['writeNotNull'] as bool - ..string = json[r'$string'] as String - ..simpleObject = json['simpleObject'] == null - ? null - : SimpleObject.fromJson(json['simpleObject'] as Map) - ..strictKeysObject = json['strictKeysObject'] == null - ? null - : StrictKeysObject.fromJson( - json['strictKeysObject'] as Map) - ..validatedPropertyNo42 = json['validatedPropertyNo42'] as int; + .toList() + ..val = Map.from(json['val'] as Map) + ..writeNotNull = json['writeNotNull'] as bool? + ..string = json[r'$string'] as String? + ..simpleObject = + SimpleObject.fromJson(json['simpleObject'] as Map) + ..strictKeysObject = StrictKeysObject.fromJson( + json['strictKeysObject'] as Map) + ..validatedPropertyNo42 = json['validatedPropertyNo42'] as int?; } Map _$KitchenSinkToJson(KitchenSink instance) { @@ -91,70 +84,64 @@ Map _$KitchenSinkToJson(KitchenSink instance) { writeNotNull('dateTime', instance.dateTime?.toIso8601String()); writeNotNull('bigInt', instance.bigInt?.toString()); writeNotNull('iterable', instance.iterable?.toList()); - writeNotNull('dynamicIterable', instance.dynamicIterable?.toList()); - writeNotNull('objectIterable', instance.objectIterable?.toList()); - writeNotNull('intIterable', instance.intIterable?.toList()); - writeNotNull('set', instance.set?.toList()); - writeNotNull('dynamicSet', instance.dynamicSet?.toList()); - writeNotNull('objectSet', instance.objectSet?.toList()); - writeNotNull('intSet', instance.intSet?.toList()); - writeNotNull('dateTimeSet', - instance.dateTimeSet?.map((e) => e?.toIso8601String())?.toList()); - writeNotNull('datetime-iterable', - instance.dateTimeIterable?.map((e) => e?.toIso8601String())?.toList()); - writeNotNull('list', instance.list); - writeNotNull('dynamicList', instance.dynamicList); - writeNotNull('objectList', instance.objectList); - writeNotNull('intList', instance.intList); - writeNotNull('dateTimeList', - instance.dateTimeList?.map((e) => e?.toIso8601String())?.toList()); - writeNotNull('map', instance.map); - writeNotNull('stringStringMap', instance.stringStringMap); - writeNotNull('dynamicIntMap', instance.dynamicIntMap); - writeNotNull( - 'objectDateTimeMap', - instance.objectDateTimeMap - ?.map((k, e) => MapEntry(k, e?.toIso8601String()))); - writeNotNull( - 'crazyComplex', - instance.crazyComplex - ?.map((e) => e?.map((k, e) => MapEntry( + val['dynamicIterable'] = instance.dynamicIterable.toList(); + val['objectIterable'] = instance.objectIterable.toList(); + val['intIterable'] = instance.intIterable.toList(); + val['set'] = instance.set.toList(); + val['dynamicSet'] = instance.dynamicSet.toList(); + val['objectSet'] = instance.objectSet.toList(); + val['intSet'] = instance.intSet.toList(); + val['dateTimeSet'] = + instance.dateTimeSet.map((e) => e.toIso8601String()).toList(); + val['datetime-iterable'] = + instance.dateTimeIterable.map((e) => e.toIso8601String()).toList(); + val['list'] = instance.list; + val['dynamicList'] = instance.dynamicList; + val['objectList'] = instance.objectList; + val['intList'] = instance.intList; + val['dateTimeList'] = + instance.dateTimeList.map((e) => e.toIso8601String()).toList(); + val['map'] = instance.map; + val['stringStringMap'] = instance.stringStringMap; + val['dynamicIntMap'] = instance.dynamicIntMap; + val['objectDateTimeMap'] = instance.objectDateTimeMap + .map((k, e) => MapEntry(k, e.toIso8601String())); + val['crazyComplex'] = instance.crazyComplex + .map((e) => e?.map((k, e) => MapEntry( + k, + e?.map((k, e) => MapEntry( k, - e?.map((k, e) => MapEntry( - k, - e - ?.map( - (e) => e?.map((e) => e?.toIso8601String())?.toList()) - ?.toList()))))) - ?.toList()); - writeNotNull('val', instance.val); + e + ?.map((e) => e?.map((e) => e.toIso8601String()).toList()) + .toList()))))) + .toList(); + val['val'] = instance.val; writeNotNull('writeNotNull', instance.writeNotNull); writeNotNull(r'$string', instance.string); - writeNotNull('simpleObject', instance.simpleObject); - writeNotNull('strictKeysObject', instance.strictKeysObject); + val['simpleObject'] = instance.simpleObject; + val['strictKeysObject'] = instance.strictKeysObject; writeNotNull('validatedPropertyNo42', instance.validatedPropertyNo42); return val; } JsonConverterTestClass _$JsonConverterTestClassFromJson( Map json) { - return JsonConverterTestClass() - ..duration = durationConverter.fromJson(json['duration'] as int) - ..durationList = (json['durationList'] as List) - ?.map((e) => durationConverter.fromJson(e as int)) - ?.toList() - ..bigInt = const BigIntStringConverter().fromJson(json['bigInt'] as String) - ..bigIntMap = (json['bigIntMap'] as Map)?.map( + return JsonConverterTestClass( + durationConverter.fromJson(json['duration'] as int?), + (json['durationList'] as List) + .map((e) => durationConverter.fromJson(e as int?)) + .toList(), + const BigIntStringConverter().fromJson(json['bigInt'] as String), + (json['bigIntMap'] as Map).map( (k, e) => MapEntry(k, const BigIntStringConverter().fromJson(e as String)), - ) - ..numberSilly = - TrivialNumberConverter.instance.fromJson(json['numberSilly'] as int) - ..numberSillySet = (json['numberSillySet'] as List) - ?.map((e) => TrivialNumberConverter.instance.fromJson(e as int)) - ?.toSet() - ..dateTime = - const EpochDateTimeConverter().fromJson(json['dateTime'] as int); + ), + TrivialNumberConverter.instance.fromJson(json['numberSilly'] as int?), + (json['numberSillySet'] as List) + .map((e) => TrivialNumberConverter.instance.fromJson(e as int?)) + .toSet(), + const EpochDateTimeConverter().fromJson(json['dateTime'] as int?), + ); } Map _$JsonConverterTestClassToJson( @@ -168,20 +155,16 @@ Map _$JsonConverterTestClassToJson( } writeNotNull('duration', durationConverter.toJson(instance.duration)); - writeNotNull('durationList', - instance.durationList?.map(durationConverter.toJson)?.toList()); + val['durationList'] = + instance.durationList.map(durationConverter.toJson).toList(); writeNotNull('bigInt', const BigIntStringConverter().toJson(instance.bigInt)); - writeNotNull( - 'bigIntMap', - instance.bigIntMap?.map( - (k, e) => MapEntry(k, const BigIntStringConverter().toJson(e)))); + val['bigIntMap'] = instance.bigIntMap + .map((k, e) => MapEntry(k, const BigIntStringConverter().toJson(e))); writeNotNull('numberSilly', TrivialNumberConverter.instance.toJson(instance.numberSilly)); - writeNotNull( - 'numberSillySet', - instance.numberSillySet - ?.map(TrivialNumberConverter.instance.toJson) - ?.toList()); + val['numberSillySet'] = instance.numberSillySet + .map(TrivialNumberConverter.instance.toJson) + .toList(); writeNotNull( 'dateTime', const EpochDateTimeConverter().toJson(instance.dateTime)); return val; @@ -189,16 +172,16 @@ Map _$JsonConverterTestClassToJson( JsonConverterGeneric _$JsonConverterGenericFromJson( Map json) { - return JsonConverterGeneric() - ..item = - GenericConverter().fromJson(json['item'] as Map) - ..itemList = (json['itemList'] as List) - ?.map((e) => GenericConverter().fromJson(e as Map)) - ?.toList() - ..itemMap = (json['itemMap'] as Map)?.map( + return JsonConverterGeneric( + GenericConverter().fromJson(json['item'] as Map), + (json['itemList'] as List) + .map((e) => GenericConverter().fromJson(e as Map)) + .toList(), + (json['itemMap'] as Map).map( (k, e) => MapEntry( k, GenericConverter().fromJson(e as Map)), - ); + ), + ); } Map _$JsonConverterGenericToJson( @@ -212,11 +195,9 @@ Map _$JsonConverterGenericToJson( } writeNotNull('item', GenericConverter().toJson(instance.item)); - writeNotNull('itemList', - instance.itemList?.map(GenericConverter().toJson)?.toList()); - writeNotNull( - 'itemMap', - instance.itemMap - ?.map((k, e) => MapEntry(k, GenericConverter().toJson(e)))); + val['itemList'] = + instance.itemList.map(GenericConverter().toJson).toList(); + val['itemMap'] = instance.itemMap + .map((k, e) => MapEntry(k, GenericConverter().toJson(e))); return val; } diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__non_nullable.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__non_nullable.dart deleted file mode 100644 index 194d406a8..000000000 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__non_nullable.dart +++ /dev/null @@ -1,202 +0,0 @@ -// Copyright (c) 2018, 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. - -// ignore_for_file: annotate_overrides, hash_and_equals -import 'package:json_annotation/json_annotation.dart'; - -import 'json_converters.dart'; -import 'kitchen_sink_interface.dart' as k; -import 'simple_object.dart'; -import 'strict_keys_object.dart'; - -part 'kitchen_sink.g_exclude_null__non_nullable.g.dart'; - -// NOTE: these methods are replaced in the `non_nullable` cases to return -// non-null values. -List _defaultList() => []; -Set _defaultSet() => {}; -Map _defaultMap() => {}; -SimpleObject _defaultSimpleObject() => SimpleObject(42); -StrictKeysObject _defaultStrictKeysObject() => StrictKeysObject(10, 'cool'); - -const k.KitchenSinkFactory factory = _Factory(); - -class _Factory implements k.KitchenSinkFactory { - const _Factory(); - - String get description => 'exclude_null__non_nullable'; - bool get anyMap => false; - bool get checked => false; - bool get nullable => false; - bool get excludeNull => true; - bool get explicitToJson => false; - - k.KitchenSink ctor({ - int ctorValidatedNo42, - Iterable iterable, - Iterable dynamicIterable, - Iterable objectIterable, - Iterable intIterable, - Iterable dateTimeIterable, - }) => - KitchenSink( - ctorValidatedNo42: ctorValidatedNo42, - iterable: iterable, - dynamicIterable: dynamicIterable, - objectIterable: objectIterable, - intIterable: intIterable, - dateTimeIterable: dateTimeIterable, - ); - - k.KitchenSink fromJson(Map json) => - KitchenSink.fromJson(json); - - k.JsonConverterTestClass jsonConverterCtor() => JsonConverterTestClass(); - - k.JsonConverterTestClass jsonConverterFromJson(Map json) => - JsonConverterTestClass.fromJson(json); -} - -@JsonSerializable( - nullable: false, - includeIfNull: false, -) -class KitchenSink implements k.KitchenSink { - // NOTE: exposing these as Iterable, but storing the values as List - // to make the equality test work trivially. - final Iterable _iterable; - final Iterable _dynamicIterable; - final Iterable _objectIterable; - final Iterable _intIterable; - final Iterable _dateTimeIterable; - - @JsonKey(name: 'no-42') - final int ctorValidatedNo42; - - KitchenSink({ - this.ctorValidatedNo42, - Iterable iterable, - Iterable dynamicIterable, - Iterable objectIterable, - Iterable intIterable, - Iterable dateTimeIterable, - }) : _iterable = iterable?.toList() ?? _defaultList(), - _dynamicIterable = dynamicIterable?.toList() ?? _defaultList(), - _objectIterable = objectIterable?.toList() ?? _defaultList(), - _intIterable = intIterable?.toList() ?? _defaultList(), - _dateTimeIterable = dateTimeIterable?.toList() ?? _defaultList() { - if (ctorValidatedNo42 == 42) { - throw ArgumentError.value( - 42, 'ctorValidatedNo42', 'The value `42` is not allowed.'); - } - } - - factory KitchenSink.fromJson(Map json) => - _$KitchenSinkFromJson(json); - - Map toJson() => _$KitchenSinkToJson(this); - - DateTime dateTime = DateTime(1981, 6, 5); - - BigInt bigInt = BigInt.parse('10000000000000000000'); - - Iterable get iterable => _iterable; - Iterable get dynamicIterable => _dynamicIterable; - Iterable get objectIterable => _objectIterable; - Iterable get intIterable => _intIterable; - - Set set = _defaultSet(); - Set dynamicSet = _defaultSet(); - Set objectSet = _defaultSet(); - Set intSet = _defaultSet(); - Set dateTimeSet = _defaultSet(); - - // Added a one-off annotation on a property (not a field) - @JsonKey(name: 'datetime-iterable') - Iterable get dateTimeIterable => _dateTimeIterable; - - List list = _defaultList(); - List dynamicList = _defaultList(); - List objectList = _defaultList(); - List intList = _defaultList(); - List dateTimeList = _defaultList(); - - Map map = _defaultMap(); - Map stringStringMap = _defaultMap(); - Map dynamicIntMap = _defaultMap(); - Map objectDateTimeMap = _defaultMap(); - - List>>>> crazyComplex = - _defaultList(); - - // Handle fields with names that collide with helper names - Map val = _defaultMap(); - bool writeNotNull; - @JsonKey(name: r'$string') - String string; - - SimpleObject simpleObject = _defaultSimpleObject(); - - StrictKeysObject strictKeysObject = _defaultStrictKeysObject(); - - int _validatedPropertyNo42; - int get validatedPropertyNo42 => _validatedPropertyNo42; - - set validatedPropertyNo42(int value) { - if (value == 42) { - throw StateError('Cannot be 42!'); - } - _validatedPropertyNo42 = value; - } - - bool operator ==(Object other) => k.sinkEquals(this, other); -} - -@JsonSerializable( - nullable: false, - includeIfNull: false, -) -// referencing a top-level field should work -@durationConverter -// referencing via a const constructor should work -@BigIntStringConverter() -@TrivialNumberConverter.instance -@EpochDateTimeConverter() -class JsonConverterTestClass implements k.JsonConverterTestClass { - JsonConverterTestClass(); - - factory JsonConverterTestClass.fromJson(Map json) => - _$JsonConverterTestClassFromJson(json); - - Map toJson() => _$JsonConverterTestClassToJson(this); - - Duration duration; - List durationList; - - BigInt bigInt = BigInt.parse('10000000000000000000'); - Map bigIntMap; - - TrivialNumber numberSilly; - Set numberSillySet; - - DateTime dateTime = DateTime(1981, 6, 5); -} - -@JsonSerializable( - nullable: false, - includeIfNull: false, -) -@GenericConverter() -class JsonConverterGeneric { - S item; - List itemList; - Map itemMap; - - JsonConverterGeneric(); - - factory JsonConverterGeneric.fromJson(Map json) => - _$JsonConverterGenericFromJson(json); - - Map toJson() => _$JsonConverterGenericToJson(this); -} diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__non_nullable.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__non_nullable.g.dart deleted file mode 100644 index 91ba7b1e9..000000000 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null__non_nullable.g.dart +++ /dev/null @@ -1,189 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'kitchen_sink.g_exclude_null__non_nullable.dart'; - -// ************************************************************************** -// JsonSerializableGenerator -// ************************************************************************** - -KitchenSink _$KitchenSinkFromJson(Map json) { - return KitchenSink( - ctorValidatedNo42: json['no-42'] as int, - iterable: json['iterable'] as List, - dynamicIterable: json['dynamicIterable'] as List, - objectIterable: json['objectIterable'] as List, - intIterable: (json['intIterable'] as List).map((e) => e as int), - dateTimeIterable: (json['datetime-iterable'] as List) - .map((e) => DateTime.parse(e as String)), - ) - ..dateTime = DateTime.parse(json['dateTime'] as String) - ..bigInt = BigInt.parse(json['bigInt'] as String) - ..set = (json['set'] as List).toSet() - ..dynamicSet = (json['dynamicSet'] as List).toSet() - ..objectSet = (json['objectSet'] as List).toSet() - ..intSet = (json['intSet'] as List).map((e) => e as int).toSet() - ..dateTimeSet = (json['dateTimeSet'] as List) - .map((e) => DateTime.parse(e as String)) - .toSet() - ..list = json['list'] as List - ..dynamicList = json['dynamicList'] as List - ..objectList = json['objectList'] as List - ..intList = (json['intList'] as List).map((e) => e as int).toList() - ..dateTimeList = (json['dateTimeList'] as List) - .map((e) => DateTime.parse(e as String)) - .toList() - ..map = json['map'] as Map - ..stringStringMap = Map.from(json['stringStringMap'] as Map) - ..dynamicIntMap = Map.from(json['dynamicIntMap'] as Map) - ..objectDateTimeMap = - (json['objectDateTimeMap'] as Map).map( - (k, e) => MapEntry(k, DateTime.parse(e as String)), - ) - ..crazyComplex = (json['crazyComplex'] as List) - .map((e) => (e as Map).map( - (k, e) => MapEntry( - k, - (e as Map).map( - (k, e) => MapEntry( - k, - (e as List) - .map((e) => (e as List) - .map((e) => DateTime.parse(e as String)) - .toList()) - .toList()), - )), - )) - .toList() - ..val = Map.from(json['val'] as Map) - ..writeNotNull = json['writeNotNull'] as bool - ..string = json[r'$string'] as String - ..simpleObject = - SimpleObject.fromJson(json['simpleObject'] as Map) - ..strictKeysObject = StrictKeysObject.fromJson( - json['strictKeysObject'] as Map) - ..validatedPropertyNo42 = json['validatedPropertyNo42'] as int; -} - -Map _$KitchenSinkToJson(KitchenSink instance) => - { - 'no-42': instance.ctorValidatedNo42, - 'dateTime': instance.dateTime.toIso8601String(), - 'bigInt': instance.bigInt.toString(), - 'iterable': instance.iterable.toList(), - 'dynamicIterable': instance.dynamicIterable.toList(), - 'objectIterable': instance.objectIterable.toList(), - 'intIterable': instance.intIterable.toList(), - 'set': instance.set.toList(), - 'dynamicSet': instance.dynamicSet.toList(), - 'objectSet': instance.objectSet.toList(), - 'intSet': instance.intSet.toList(), - 'dateTimeSet': - instance.dateTimeSet.map((e) => e.toIso8601String()).toList(), - 'datetime-iterable': - instance.dateTimeIterable.map((e) => e.toIso8601String()).toList(), - 'list': instance.list, - 'dynamicList': instance.dynamicList, - 'objectList': instance.objectList, - 'intList': instance.intList, - 'dateTimeList': - instance.dateTimeList.map((e) => e.toIso8601String()).toList(), - 'map': instance.map, - 'stringStringMap': instance.stringStringMap, - 'dynamicIntMap': instance.dynamicIntMap, - 'objectDateTimeMap': instance.objectDateTimeMap - .map((k, e) => MapEntry(k, e.toIso8601String())), - 'crazyComplex': instance.crazyComplex - .map((e) => e.map((k, e) => MapEntry( - k, - e.map((k, e) => MapEntry( - k, - e - .map((e) => e.map((e) => e.toIso8601String()).toList()) - .toList()))))) - .toList(), - 'val': instance.val, - 'writeNotNull': instance.writeNotNull, - r'$string': instance.string, - 'simpleObject': instance.simpleObject, - 'strictKeysObject': instance.strictKeysObject, - 'validatedPropertyNo42': instance.validatedPropertyNo42, - }; - -JsonConverterTestClass _$JsonConverterTestClassFromJson( - Map json) { - return JsonConverterTestClass() - ..duration = durationConverter.fromJson(json['duration'] as int) - ..durationList = (json['durationList'] as List) - .map((e) => durationConverter.fromJson(e as int)) - .toList() - ..bigInt = const BigIntStringConverter().fromJson(json['bigInt'] as String) - ..bigIntMap = (json['bigIntMap'] as Map).map( - (k, e) => - MapEntry(k, const BigIntStringConverter().fromJson(e as String)), - ) - ..numberSilly = - TrivialNumberConverter.instance.fromJson(json['numberSilly'] as int) - ..numberSillySet = (json['numberSillySet'] as List) - .map((e) => TrivialNumberConverter.instance.fromJson(e as int)) - .toSet() - ..dateTime = - const EpochDateTimeConverter().fromJson(json['dateTime'] as int); -} - -Map _$JsonConverterTestClassToJson( - JsonConverterTestClass instance) { - final val = {}; - - void writeNotNull(String key, dynamic value) { - if (value != null) { - val[key] = value; - } - } - - writeNotNull('duration', durationConverter.toJson(instance.duration)); - val['durationList'] = - instance.durationList.map(durationConverter.toJson).toList(); - writeNotNull('bigInt', const BigIntStringConverter().toJson(instance.bigInt)); - val['bigIntMap'] = instance.bigIntMap - .map((k, e) => MapEntry(k, const BigIntStringConverter().toJson(e))); - writeNotNull('numberSilly', - TrivialNumberConverter.instance.toJson(instance.numberSilly)); - val['numberSillySet'] = instance.numberSillySet - .map(TrivialNumberConverter.instance.toJson) - .toList(); - writeNotNull( - 'dateTime', const EpochDateTimeConverter().toJson(instance.dateTime)); - return val; -} - -JsonConverterGeneric _$JsonConverterGenericFromJson( - Map json) { - return JsonConverterGeneric() - ..item = - GenericConverter().fromJson(json['item'] as Map) - ..itemList = (json['itemList'] as List) - .map((e) => GenericConverter().fromJson(e as Map)) - .toList() - ..itemMap = (json['itemMap'] as Map).map( - (k, e) => MapEntry( - k, GenericConverter().fromJson(e as Map)), - ); -} - -Map _$JsonConverterGenericToJson( - JsonConverterGeneric instance) { - final val = {}; - - void writeNotNull(String key, dynamic value) { - if (value != null) { - val[key] = value; - } - } - - writeNotNull('item', GenericConverter().toJson(instance.item)); - val['itemList'] = - instance.itemList.map(GenericConverter().toJson).toList(); - val['itemMap'] = instance.itemMap - .map((k, e) => MapEntry(k, GenericConverter().toJson(e))); - return val; -} diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.dart index 5a4fbeb20..6bc665612 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.dart @@ -2,6 +2,8 @@ // 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. +// @dart=2.12 + // ignore_for_file: annotate_overrides, hash_and_equals import 'package:json_annotation/json_annotation.dart'; @@ -14,11 +16,15 @@ part 'kitchen_sink.g_explicit_to_json.g.dart'; // NOTE: these methods are replaced in the `non_nullable` cases to return // non-null values. -List _defaultList() => null; -Set _defaultSet() => null; -Map _defaultMap() => null; -SimpleObject _defaultSimpleObject() => null; -StrictKeysObject _defaultStrictKeysObject() => null; +List _defaultList() => []; + +Set _defaultSet() => {}; + +Map _defaultMap() => {}; + +SimpleObject _defaultSimpleObject() => SimpleObject(42); + +StrictKeysObject _defaultStrictKeysObject() => StrictKeysObject(42, 'value'); const k.KitchenSinkFactory factory = _Factory(); @@ -26,19 +32,24 @@ class _Factory implements k.KitchenSinkFactory { const _Factory(); String get description => 'explicit_to_json'; + bool get anyMap => false; + bool get checked => false; + bool get nullable => true; + bool get excludeNull => false; + bool get explicitToJson => true; k.KitchenSink ctor({ - int ctorValidatedNo42, - Iterable iterable, - Iterable dynamicIterable, - Iterable objectIterable, - Iterable intIterable, - Iterable dateTimeIterable, + int? ctorValidatedNo42, + Iterable? iterable, + Iterable? dynamicIterable, + Iterable? objectIterable, + Iterable? intIterable, + Iterable? dateTimeIterable, }) => KitchenSink( ctorValidatedNo42: ctorValidatedNo42, @@ -52,7 +63,15 @@ class _Factory implements k.KitchenSinkFactory { k.KitchenSink fromJson(Map json) => KitchenSink.fromJson(json); - k.JsonConverterTestClass jsonConverterCtor() => JsonConverterTestClass(); + k.JsonConverterTestClass jsonConverterCtor() => JsonConverterTestClass( + const Duration(), + [], + BigInt.zero, + {}, + TrivialNumber(0), + {}, + DateTime.fromMillisecondsSinceEpoch(0), + ); k.JsonConverterTestClass jsonConverterFromJson(Map json) => JsonConverterTestClass.fromJson(json); @@ -64,23 +83,23 @@ class _Factory implements k.KitchenSinkFactory { class KitchenSink implements k.KitchenSink { // NOTE: exposing these as Iterable, but storing the values as List // to make the equality test work trivially. - final Iterable _iterable; + final Iterable? _iterable; final Iterable _dynamicIterable; final Iterable _objectIterable; final Iterable _intIterable; final Iterable _dateTimeIterable; @JsonKey(name: 'no-42') - final int ctorValidatedNo42; + final int? ctorValidatedNo42; KitchenSink({ this.ctorValidatedNo42, - Iterable iterable, - Iterable dynamicIterable, - Iterable objectIterable, - Iterable intIterable, - Iterable dateTimeIterable, - }) : _iterable = iterable?.toList() ?? _defaultList(), + Iterable? iterable, + Iterable? dynamicIterable, + Iterable? objectIterable, + Iterable? intIterable, + Iterable? dateTimeIterable, + }) : _iterable = iterable?.toList(), _dynamicIterable = dynamicIterable?.toList() ?? _defaultList(), _objectIterable = objectIterable?.toList() ?? _defaultList(), _intIterable = intIterable?.toList() ?? _defaultList(), @@ -96,13 +115,16 @@ class KitchenSink implements k.KitchenSink { Map toJson() => _$KitchenSinkToJson(this); - DateTime dateTime; + DateTime? dateTime; - BigInt bigInt; + BigInt? bigInt; + + Iterable? get iterable => _iterable; - Iterable get iterable => _iterable; Iterable get dynamicIterable => _dynamicIterable; + Iterable get objectIterable => _objectIterable; + Iterable get intIterable => _intIterable; Set set = _defaultSet(); @@ -126,23 +148,24 @@ class KitchenSink implements k.KitchenSink { Map dynamicIntMap = _defaultMap(); Map objectDateTimeMap = _defaultMap(); - List>>>> crazyComplex = + List?>?>?>?> crazyComplex = _defaultList(); // Handle fields with names that collide with helper names Map val = _defaultMap(); - bool writeNotNull; + bool? writeNotNull; @JsonKey(name: r'$string') - String string; + String? string; SimpleObject simpleObject = _defaultSimpleObject(); StrictKeysObject strictKeysObject = _defaultStrictKeysObject(); - int _validatedPropertyNo42; - int get validatedPropertyNo42 => _validatedPropertyNo42; + int? _validatedPropertyNo42; + + int? get validatedPropertyNo42 => _validatedPropertyNo42; - set validatedPropertyNo42(int value) { + set validatedPropertyNo42(int? value) { if (value == 42) { throw StateError('Cannot be 42!'); } @@ -162,15 +185,23 @@ class KitchenSink implements k.KitchenSink { @TrivialNumberConverter.instance @EpochDateTimeConverter() class JsonConverterTestClass implements k.JsonConverterTestClass { - JsonConverterTestClass(); + JsonConverterTestClass( + this.duration, + this.durationList, + this.bigInt, + this.bigIntMap, + this.numberSilly, + this.numberSillySet, + this.dateTime, + ); factory JsonConverterTestClass.fromJson(Map json) => _$JsonConverterTestClassFromJson(json); Map toJson() => _$JsonConverterTestClassToJson(this); - Duration duration; - List durationList; + Duration? duration; + List durationList; BigInt bigInt; Map bigIntMap; @@ -178,7 +209,7 @@ class JsonConverterTestClass implements k.JsonConverterTestClass { TrivialNumber numberSilly; Set numberSillySet; - DateTime dateTime; + DateTime? dateTime; } @JsonSerializable( @@ -190,7 +221,11 @@ class JsonConverterGeneric { List itemList; Map itemMap; - JsonConverterGeneric(); + JsonConverterGeneric( + this.item, + this.itemList, + this.itemMap, + ); factory JsonConverterGeneric.fromJson(Map json) => _$JsonConverterGenericFromJson(json); diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart index 353b5c35d..9dda090c9 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart @@ -1,4 +1,5 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// @dart=2.12 part of 'kitchen_sink.g_explicit_to_json.dart'; @@ -8,74 +9,66 @@ part of 'kitchen_sink.g_explicit_to_json.dart'; KitchenSink _$KitchenSinkFromJson(Map json) { return KitchenSink( - ctorValidatedNo42: json['no-42'] as int, - iterable: json['iterable'] as List, - dynamicIterable: json['dynamicIterable'] as List, - objectIterable: json['objectIterable'] as List, - intIterable: (json['intIterable'] as List)?.map((e) => e as int), - dateTimeIterable: (json['datetime-iterable'] as List) - ?.map((e) => e == null ? null : DateTime.parse(e as String)), + ctorValidatedNo42: json['no-42'] as int?, + iterable: json['iterable'] as List?, + dynamicIterable: json['dynamicIterable'] as List?, + objectIterable: + (json['objectIterable'] as List?)?.map((e) => e as Object), + intIterable: (json['intIterable'] as List?)?.map((e) => e as int), + dateTimeIterable: (json['datetime-iterable'] as List?) + ?.map((e) => DateTime.parse(e as String)), ) ..dateTime = json['dateTime'] == null ? null : DateTime.parse(json['dateTime'] as String) ..bigInt = json['bigInt'] == null ? null : BigInt.parse(json['bigInt'] as String) - ..set = (json['set'] as List)?.toSet() - ..dynamicSet = (json['dynamicSet'] as List)?.toSet() - ..objectSet = (json['objectSet'] as List)?.toSet() - ..intSet = (json['intSet'] as List)?.map((e) => e as int)?.toSet() - ..dateTimeSet = (json['dateTimeSet'] as List) - ?.map((e) => e == null ? null : DateTime.parse(e as String)) - ?.toSet() - ..list = json['list'] as List - ..dynamicList = json['dynamicList'] as List - ..objectList = json['objectList'] as List - ..intList = (json['intList'] as List)?.map((e) => e as int)?.toList() - ..dateTimeList = (json['dateTimeList'] as List) - ?.map((e) => e == null ? null : DateTime.parse(e as String)) - ?.toList() + ..set = (json['set'] as List).toSet() + ..dynamicSet = (json['dynamicSet'] as List).toSet() + ..objectSet = + (json['objectSet'] as List).map((e) => e as Object).toSet() + ..intSet = (json['intSet'] as List).map((e) => e as int).toSet() + ..dateTimeSet = (json['dateTimeSet'] as List) + .map((e) => DateTime.parse(e as String)) + .toSet() + ..list = json['list'] as List + ..dynamicList = json['dynamicList'] as List + ..objectList = + (json['objectList'] as List).map((e) => e as Object).toList() + ..intList = (json['intList'] as List).map((e) => e as int).toList() + ..dateTimeList = (json['dateTimeList'] as List) + .map((e) => DateTime.parse(e as String)) + .toList() ..map = json['map'] as Map - ..stringStringMap = (json['stringStringMap'] as Map)?.map( - (k, e) => MapEntry(k, e as String), - ) - ..dynamicIntMap = (json['dynamicIntMap'] as Map)?.map( - (k, e) => MapEntry(k, e as int), - ) + ..stringStringMap = Map.from(json['stringStringMap'] as Map) + ..dynamicIntMap = Map.from(json['dynamicIntMap'] as Map) ..objectDateTimeMap = - (json['objectDateTimeMap'] as Map)?.map( - (k, e) => MapEntry(k, e == null ? null : DateTime.parse(e as String)), + (json['objectDateTimeMap'] as Map).map( + (k, e) => MapEntry(k, DateTime.parse(e as String)), ) - ..crazyComplex = (json['crazyComplex'] as List) - ?.map((e) => (e as Map)?.map( + ..crazyComplex = (json['crazyComplex'] as List) + .map((e) => (e as Map?)?.map( (k, e) => MapEntry( k, - (e as Map)?.map( + (e as Map?)?.map( (k, e) => MapEntry( k, - (e as List) - ?.map((e) => (e as List) - ?.map((e) => e == null - ? null - : DateTime.parse(e as String)) - ?.toList()) - ?.toList()), + (e as List?) + ?.map((e) => (e as List?) + ?.map((e) => DateTime.parse(e as String)) + .toList()) + .toList()), )), )) - ?.toList() - ..val = (json['val'] as Map)?.map( - (k, e) => MapEntry(k, e as bool), - ) - ..writeNotNull = json['writeNotNull'] as bool - ..string = json[r'$string'] as String - ..simpleObject = json['simpleObject'] == null - ? null - : SimpleObject.fromJson(json['simpleObject'] as Map) - ..strictKeysObject = json['strictKeysObject'] == null - ? null - : StrictKeysObject.fromJson( - json['strictKeysObject'] as Map) - ..validatedPropertyNo42 = json['validatedPropertyNo42'] as int; + .toList() + ..val = Map.from(json['val'] as Map) + ..writeNotNull = json['writeNotNull'] as bool? + ..string = json[r'$string'] as String? + ..simpleObject = + SimpleObject.fromJson(json['simpleObject'] as Map) + ..strictKeysObject = StrictKeysObject.fromJson( + json['strictKeysObject'] as Map) + ..validatedPropertyNo42 = json['validatedPropertyNo42'] as int?; } Map _$KitchenSinkToJson(KitchenSink instance) => @@ -84,65 +77,63 @@ Map _$KitchenSinkToJson(KitchenSink instance) => 'dateTime': instance.dateTime?.toIso8601String(), 'bigInt': instance.bigInt?.toString(), 'iterable': instance.iterable?.toList(), - 'dynamicIterable': instance.dynamicIterable?.toList(), - 'objectIterable': instance.objectIterable?.toList(), - 'intIterable': instance.intIterable?.toList(), - 'set': instance.set?.toList(), - 'dynamicSet': instance.dynamicSet?.toList(), - 'objectSet': instance.objectSet?.toList(), - 'intSet': instance.intSet?.toList(), + 'dynamicIterable': instance.dynamicIterable.toList(), + 'objectIterable': instance.objectIterable.toList(), + 'intIterable': instance.intIterable.toList(), + 'set': instance.set.toList(), + 'dynamicSet': instance.dynamicSet.toList(), + 'objectSet': instance.objectSet.toList(), + 'intSet': instance.intSet.toList(), 'dateTimeSet': - instance.dateTimeSet?.map((e) => e?.toIso8601String())?.toList(), + instance.dateTimeSet.map((e) => e.toIso8601String()).toList(), 'datetime-iterable': - instance.dateTimeIterable?.map((e) => e?.toIso8601String())?.toList(), + instance.dateTimeIterable.map((e) => e.toIso8601String()).toList(), 'list': instance.list, 'dynamicList': instance.dynamicList, 'objectList': instance.objectList, 'intList': instance.intList, 'dateTimeList': - instance.dateTimeList?.map((e) => e?.toIso8601String())?.toList(), + instance.dateTimeList.map((e) => e.toIso8601String()).toList(), 'map': instance.map, 'stringStringMap': instance.stringStringMap, 'dynamicIntMap': instance.dynamicIntMap, 'objectDateTimeMap': instance.objectDateTimeMap - ?.map((k, e) => MapEntry(k, e?.toIso8601String())), + .map((k, e) => MapEntry(k, e.toIso8601String())), 'crazyComplex': instance.crazyComplex - ?.map((e) => e?.map((k, e) => MapEntry( + .map((e) => e?.map((k, e) => MapEntry( k, e?.map((k, e) => MapEntry( k, e - ?.map( - (e) => e?.map((e) => e?.toIso8601String())?.toList()) - ?.toList()))))) - ?.toList(), + ?.map((e) => e?.map((e) => e.toIso8601String()).toList()) + .toList()))))) + .toList(), 'val': instance.val, 'writeNotNull': instance.writeNotNull, r'$string': instance.string, - 'simpleObject': instance.simpleObject?.toJson(), - 'strictKeysObject': instance.strictKeysObject?.toJson(), + 'simpleObject': instance.simpleObject.toJson(), + 'strictKeysObject': instance.strictKeysObject.toJson(), 'validatedPropertyNo42': instance.validatedPropertyNo42, }; JsonConverterTestClass _$JsonConverterTestClassFromJson( Map json) { - return JsonConverterTestClass() - ..duration = durationConverter.fromJson(json['duration'] as int) - ..durationList = (json['durationList'] as List) - ?.map((e) => durationConverter.fromJson(e as int)) - ?.toList() - ..bigInt = const BigIntStringConverter().fromJson(json['bigInt'] as String) - ..bigIntMap = (json['bigIntMap'] as Map)?.map( + return JsonConverterTestClass( + durationConverter.fromJson(json['duration'] as int?), + (json['durationList'] as List) + .map((e) => durationConverter.fromJson(e as int?)) + .toList(), + const BigIntStringConverter().fromJson(json['bigInt'] as String), + (json['bigIntMap'] as Map).map( (k, e) => MapEntry(k, const BigIntStringConverter().fromJson(e as String)), - ) - ..numberSilly = - TrivialNumberConverter.instance.fromJson(json['numberSilly'] as int) - ..numberSillySet = (json['numberSillySet'] as List) - ?.map((e) => TrivialNumberConverter.instance.fromJson(e as int)) - ?.toSet() - ..dateTime = - const EpochDateTimeConverter().fromJson(json['dateTime'] as int); + ), + TrivialNumberConverter.instance.fromJson(json['numberSilly'] as int?), + (json['numberSillySet'] as List) + .map((e) => TrivialNumberConverter.instance.fromJson(e as int?)) + .toSet(), + const EpochDateTimeConverter().fromJson(json['dateTime'] as int?), + ); } Map _$JsonConverterTestClassToJson( @@ -150,38 +141,37 @@ Map _$JsonConverterTestClassToJson( { 'duration': durationConverter.toJson(instance.duration), 'durationList': - instance.durationList?.map(durationConverter.toJson)?.toList(), + instance.durationList.map(durationConverter.toJson).toList(), 'bigInt': const BigIntStringConverter().toJson(instance.bigInt), 'bigIntMap': instance.bigIntMap - ?.map((k, e) => MapEntry(k, const BigIntStringConverter().toJson(e))), + .map((k, e) => MapEntry(k, const BigIntStringConverter().toJson(e))), 'numberSilly': TrivialNumberConverter.instance.toJson(instance.numberSilly), 'numberSillySet': instance.numberSillySet - ?.map(TrivialNumberConverter.instance.toJson) - ?.toList(), + .map(TrivialNumberConverter.instance.toJson) + .toList(), 'dateTime': const EpochDateTimeConverter().toJson(instance.dateTime), }; JsonConverterGeneric _$JsonConverterGenericFromJson( Map json) { - return JsonConverterGeneric() - ..item = - GenericConverter().fromJson(json['item'] as Map) - ..itemList = (json['itemList'] as List) - ?.map((e) => GenericConverter().fromJson(e as Map)) - ?.toList() - ..itemMap = (json['itemMap'] as Map)?.map( + return JsonConverterGeneric( + GenericConverter().fromJson(json['item'] as Map), + (json['itemList'] as List) + .map((e) => GenericConverter().fromJson(e as Map)) + .toList(), + (json['itemMap'] as Map).map( (k, e) => MapEntry( k, GenericConverter().fromJson(e as Map)), - ); + ), + ); } Map _$JsonConverterGenericToJson( JsonConverterGeneric instance) => { 'item': GenericConverter().toJson(instance.item), - 'itemList': - instance.itemList?.map(GenericConverter().toJson)?.toList(), + 'itemList': instance.itemList.map(GenericConverter().toJson).toList(), 'itemMap': instance.itemMap - ?.map((k, e) => MapEntry(k, GenericConverter().toJson(e))), + .map((k, e) => MapEntry(k, GenericConverter().toJson(e))), }; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_non_nullable.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_non_nullable.dart deleted file mode 100644 index 71d5919c4..000000000 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_non_nullable.dart +++ /dev/null @@ -1,199 +0,0 @@ -// Copyright (c) 2018, 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. - -// ignore_for_file: annotate_overrides, hash_and_equals -import 'package:json_annotation/json_annotation.dart'; - -import 'json_converters.dart'; -import 'kitchen_sink_interface.dart' as k; -import 'simple_object.dart'; -import 'strict_keys_object.dart'; - -part 'kitchen_sink.g_non_nullable.g.dart'; - -// NOTE: these methods are replaced in the `non_nullable` cases to return -// non-null values. -List _defaultList() => []; -Set _defaultSet() => {}; -Map _defaultMap() => {}; -SimpleObject _defaultSimpleObject() => SimpleObject(42); -StrictKeysObject _defaultStrictKeysObject() => StrictKeysObject(10, 'cool'); - -const k.KitchenSinkFactory factory = _Factory(); - -class _Factory implements k.KitchenSinkFactory { - const _Factory(); - - String get description => 'non_nullable'; - bool get anyMap => false; - bool get checked => false; - bool get nullable => false; - bool get excludeNull => false; - bool get explicitToJson => false; - - k.KitchenSink ctor({ - int ctorValidatedNo42, - Iterable iterable, - Iterable dynamicIterable, - Iterable objectIterable, - Iterable intIterable, - Iterable dateTimeIterable, - }) => - KitchenSink( - ctorValidatedNo42: ctorValidatedNo42, - iterable: iterable, - dynamicIterable: dynamicIterable, - objectIterable: objectIterable, - intIterable: intIterable, - dateTimeIterable: dateTimeIterable, - ); - - k.KitchenSink fromJson(Map json) => - KitchenSink.fromJson(json); - - k.JsonConverterTestClass jsonConverterCtor() => JsonConverterTestClass(); - - k.JsonConverterTestClass jsonConverterFromJson(Map json) => - JsonConverterTestClass.fromJson(json); -} - -@JsonSerializable( - nullable: false, -) -class KitchenSink implements k.KitchenSink { - // NOTE: exposing these as Iterable, but storing the values as List - // to make the equality test work trivially. - final Iterable _iterable; - final Iterable _dynamicIterable; - final Iterable _objectIterable; - final Iterable _intIterable; - final Iterable _dateTimeIterable; - - @JsonKey(name: 'no-42') - final int ctorValidatedNo42; - - KitchenSink({ - this.ctorValidatedNo42, - Iterable iterable, - Iterable dynamicIterable, - Iterable objectIterable, - Iterable intIterable, - Iterable dateTimeIterable, - }) : _iterable = iterable?.toList() ?? _defaultList(), - _dynamicIterable = dynamicIterable?.toList() ?? _defaultList(), - _objectIterable = objectIterable?.toList() ?? _defaultList(), - _intIterable = intIterable?.toList() ?? _defaultList(), - _dateTimeIterable = dateTimeIterable?.toList() ?? _defaultList() { - if (ctorValidatedNo42 == 42) { - throw ArgumentError.value( - 42, 'ctorValidatedNo42', 'The value `42` is not allowed.'); - } - } - - factory KitchenSink.fromJson(Map json) => - _$KitchenSinkFromJson(json); - - Map toJson() => _$KitchenSinkToJson(this); - - DateTime dateTime = DateTime(1981, 6, 5); - - BigInt bigInt = BigInt.parse('10000000000000000000'); - - Iterable get iterable => _iterable; - Iterable get dynamicIterable => _dynamicIterable; - Iterable get objectIterable => _objectIterable; - Iterable get intIterable => _intIterable; - - Set set = _defaultSet(); - Set dynamicSet = _defaultSet(); - Set objectSet = _defaultSet(); - Set intSet = _defaultSet(); - Set dateTimeSet = _defaultSet(); - - // Added a one-off annotation on a property (not a field) - @JsonKey(name: 'datetime-iterable') - Iterable get dateTimeIterable => _dateTimeIterable; - - List list = _defaultList(); - List dynamicList = _defaultList(); - List objectList = _defaultList(); - List intList = _defaultList(); - List dateTimeList = _defaultList(); - - Map map = _defaultMap(); - Map stringStringMap = _defaultMap(); - Map dynamicIntMap = _defaultMap(); - Map objectDateTimeMap = _defaultMap(); - - List>>>> crazyComplex = - _defaultList(); - - // Handle fields with names that collide with helper names - Map val = _defaultMap(); - bool writeNotNull; - @JsonKey(name: r'$string') - String string; - - SimpleObject simpleObject = _defaultSimpleObject(); - - StrictKeysObject strictKeysObject = _defaultStrictKeysObject(); - - int _validatedPropertyNo42; - int get validatedPropertyNo42 => _validatedPropertyNo42; - - set validatedPropertyNo42(int value) { - if (value == 42) { - throw StateError('Cannot be 42!'); - } - _validatedPropertyNo42 = value; - } - - bool operator ==(Object other) => k.sinkEquals(this, other); -} - -@JsonSerializable( - nullable: false, -) -// referencing a top-level field should work -@durationConverter -// referencing via a const constructor should work -@BigIntStringConverter() -@TrivialNumberConverter.instance -@EpochDateTimeConverter() -class JsonConverterTestClass implements k.JsonConverterTestClass { - JsonConverterTestClass(); - - factory JsonConverterTestClass.fromJson(Map json) => - _$JsonConverterTestClassFromJson(json); - - Map toJson() => _$JsonConverterTestClassToJson(this); - - Duration duration; - List durationList; - - BigInt bigInt = BigInt.parse('10000000000000000000'); - Map bigIntMap; - - TrivialNumber numberSilly; - Set numberSillySet; - - DateTime dateTime = DateTime(1981, 6, 5); -} - -@JsonSerializable( - nullable: false, -) -@GenericConverter() -class JsonConverterGeneric { - S item; - List itemList; - Map itemMap; - - JsonConverterGeneric(); - - factory JsonConverterGeneric.fromJson(Map json) => - _$JsonConverterGenericFromJson(json); - - Map toJson() => _$JsonConverterGenericToJson(this); -} diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_non_nullable.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_non_nullable.g.dart deleted file mode 100644 index 2c85c5a13..000000000 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_non_nullable.g.dart +++ /dev/null @@ -1,171 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'kitchen_sink.g_non_nullable.dart'; - -// ************************************************************************** -// JsonSerializableGenerator -// ************************************************************************** - -KitchenSink _$KitchenSinkFromJson(Map json) { - return KitchenSink( - ctorValidatedNo42: json['no-42'] as int, - iterable: json['iterable'] as List, - dynamicIterable: json['dynamicIterable'] as List, - objectIterable: json['objectIterable'] as List, - intIterable: (json['intIterable'] as List).map((e) => e as int), - dateTimeIterable: (json['datetime-iterable'] as List) - .map((e) => DateTime.parse(e as String)), - ) - ..dateTime = DateTime.parse(json['dateTime'] as String) - ..bigInt = BigInt.parse(json['bigInt'] as String) - ..set = (json['set'] as List).toSet() - ..dynamicSet = (json['dynamicSet'] as List).toSet() - ..objectSet = (json['objectSet'] as List).toSet() - ..intSet = (json['intSet'] as List).map((e) => e as int).toSet() - ..dateTimeSet = (json['dateTimeSet'] as List) - .map((e) => DateTime.parse(e as String)) - .toSet() - ..list = json['list'] as List - ..dynamicList = json['dynamicList'] as List - ..objectList = json['objectList'] as List - ..intList = (json['intList'] as List).map((e) => e as int).toList() - ..dateTimeList = (json['dateTimeList'] as List) - .map((e) => DateTime.parse(e as String)) - .toList() - ..map = json['map'] as Map - ..stringStringMap = Map.from(json['stringStringMap'] as Map) - ..dynamicIntMap = Map.from(json['dynamicIntMap'] as Map) - ..objectDateTimeMap = - (json['objectDateTimeMap'] as Map).map( - (k, e) => MapEntry(k, DateTime.parse(e as String)), - ) - ..crazyComplex = (json['crazyComplex'] as List) - .map((e) => (e as Map).map( - (k, e) => MapEntry( - k, - (e as Map).map( - (k, e) => MapEntry( - k, - (e as List) - .map((e) => (e as List) - .map((e) => DateTime.parse(e as String)) - .toList()) - .toList()), - )), - )) - .toList() - ..val = Map.from(json['val'] as Map) - ..writeNotNull = json['writeNotNull'] as bool - ..string = json[r'$string'] as String - ..simpleObject = - SimpleObject.fromJson(json['simpleObject'] as Map) - ..strictKeysObject = StrictKeysObject.fromJson( - json['strictKeysObject'] as Map) - ..validatedPropertyNo42 = json['validatedPropertyNo42'] as int; -} - -Map _$KitchenSinkToJson(KitchenSink instance) => - { - 'no-42': instance.ctorValidatedNo42, - 'dateTime': instance.dateTime.toIso8601String(), - 'bigInt': instance.bigInt.toString(), - 'iterable': instance.iterable.toList(), - 'dynamicIterable': instance.dynamicIterable.toList(), - 'objectIterable': instance.objectIterable.toList(), - 'intIterable': instance.intIterable.toList(), - 'set': instance.set.toList(), - 'dynamicSet': instance.dynamicSet.toList(), - 'objectSet': instance.objectSet.toList(), - 'intSet': instance.intSet.toList(), - 'dateTimeSet': - instance.dateTimeSet.map((e) => e.toIso8601String()).toList(), - 'datetime-iterable': - instance.dateTimeIterable.map((e) => e.toIso8601String()).toList(), - 'list': instance.list, - 'dynamicList': instance.dynamicList, - 'objectList': instance.objectList, - 'intList': instance.intList, - 'dateTimeList': - instance.dateTimeList.map((e) => e.toIso8601String()).toList(), - 'map': instance.map, - 'stringStringMap': instance.stringStringMap, - 'dynamicIntMap': instance.dynamicIntMap, - 'objectDateTimeMap': instance.objectDateTimeMap - .map((k, e) => MapEntry(k, e.toIso8601String())), - 'crazyComplex': instance.crazyComplex - .map((e) => e.map((k, e) => MapEntry( - k, - e.map((k, e) => MapEntry( - k, - e - .map((e) => e.map((e) => e.toIso8601String()).toList()) - .toList()))))) - .toList(), - 'val': instance.val, - 'writeNotNull': instance.writeNotNull, - r'$string': instance.string, - 'simpleObject': instance.simpleObject, - 'strictKeysObject': instance.strictKeysObject, - 'validatedPropertyNo42': instance.validatedPropertyNo42, - }; - -JsonConverterTestClass _$JsonConverterTestClassFromJson( - Map json) { - return JsonConverterTestClass() - ..duration = durationConverter.fromJson(json['duration'] as int) - ..durationList = (json['durationList'] as List) - .map((e) => durationConverter.fromJson(e as int)) - .toList() - ..bigInt = const BigIntStringConverter().fromJson(json['bigInt'] as String) - ..bigIntMap = (json['bigIntMap'] as Map).map( - (k, e) => - MapEntry(k, const BigIntStringConverter().fromJson(e as String)), - ) - ..numberSilly = - TrivialNumberConverter.instance.fromJson(json['numberSilly'] as int) - ..numberSillySet = (json['numberSillySet'] as List) - .map((e) => TrivialNumberConverter.instance.fromJson(e as int)) - .toSet() - ..dateTime = - const EpochDateTimeConverter().fromJson(json['dateTime'] as int); -} - -Map _$JsonConverterTestClassToJson( - JsonConverterTestClass instance) => - { - 'duration': durationConverter.toJson(instance.duration), - 'durationList': - instance.durationList.map(durationConverter.toJson).toList(), - 'bigInt': const BigIntStringConverter().toJson(instance.bigInt), - 'bigIntMap': instance.bigIntMap - .map((k, e) => MapEntry(k, const BigIntStringConverter().toJson(e))), - 'numberSilly': - TrivialNumberConverter.instance.toJson(instance.numberSilly), - 'numberSillySet': instance.numberSillySet - .map(TrivialNumberConverter.instance.toJson) - .toList(), - 'dateTime': const EpochDateTimeConverter().toJson(instance.dateTime), - }; - -JsonConverterGeneric _$JsonConverterGenericFromJson( - Map json) { - return JsonConverterGeneric() - ..item = - GenericConverter().fromJson(json['item'] as Map) - ..itemList = (json['itemList'] as List) - .map((e) => GenericConverter().fromJson(e as Map)) - .toList() - ..itemMap = (json['itemMap'] as Map).map( - (k, e) => MapEntry( - k, GenericConverter().fromJson(e as Map)), - ); -} - -Map _$JsonConverterGenericToJson( - JsonConverterGeneric instance) => - { - 'item': GenericConverter().toJson(instance.item), - 'itemList': instance.itemList.map(GenericConverter().toJson).toList(), - 'itemMap': instance.itemMap - .map((k, e) => MapEntry(k, GenericConverter().toJson(e))), - }; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart b/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart index 93916afac..2473ca1df 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart @@ -2,15 +2,23 @@ // 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. +// @dart=2.12 + import 'package:collection/collection.dart'; + import 'simple_object.dart'; abstract class KitchenSinkFactory { String get description; + bool get anyMap; + bool get checked; + bool get nullable; + bool get excludeNull; + bool get explicitToJson; KitchenSink ctor({ @@ -37,43 +45,69 @@ abstract class JsonConverterTestClass { } abstract class KitchenSink { - int get ctorValidatedNo42; - DateTime dateTime; - BigInt bigInt; + int? get ctorValidatedNo42; + + DateTime? dateTime; + BigInt? bigInt; + + Iterable? get iterable; - Iterable get iterable; Iterable get dynamicIterable; + Iterable get objectIterable; + Iterable get intIterable; Iterable get dateTimeIterable; - List list; - List dynamicList; - List objectList; - List intList; - List dateTimeList; + List get list; + + List get dynamicList; + + List get objectList; + + List get intList; + + List get dateTimeList; + + set dateTimeList(List value); + + Set get set; + + Set get dynamicSet; + + Set get objectSet; + + Set get intSet; + + Set get dateTimeSet; + + Map get map; + + set map(Map value); + + Map get stringStringMap; + + Map get dynamicIntMap; + + Map get objectDateTimeMap; + + set objectDateTimeMap(Map value); - Set set; - Set dynamicSet; - Set objectSet; - Set intSet; - Set dateTimeSet; + List?>?>?>?> get crazyComplex; - Map map; - Map stringStringMap; - Map dynamicIntMap; - Map objectDateTimeMap; + set crazyComplex( + List?>?>?>?> value, + ); - List>>>> crazyComplex; + Map get val; - Map val; - bool writeNotNull; - String string; + bool? writeNotNull; + String? string; SimpleObject get simpleObject; - int validatedPropertyNo42; + int? validatedPropertyNo42; Map toJson(); } @@ -102,5 +136,5 @@ bool sinkEquals(KitchenSink a, Object other) => a.writeNotNull == other.writeNotNull && a.string == other.string; -bool _deepEquals(Object a, Object b) => +bool _deepEquals(Object? a, Object? b) => const DeepCollectionEquality().equals(a, b); diff --git a/json_serializable/test/kitchen_sink/kitchen_sink_test.dart b/json_serializable/test/kitchen_sink/kitchen_sink_test.dart index 8a22ce025..40fce7218 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink_test.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink_test.dart @@ -2,39 +2,28 @@ // 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. +// @dart=2.12 + import 'package:json_annotation/json_annotation.dart'; import 'package:test/test.dart'; -import 'package:yaml/yaml.dart'; import '../test_utils.dart'; import 'kitchen_sink.factories.dart'; import 'kitchen_sink_interface.dart'; +import 'kitchen_sink_test_shared.dart'; import 'strict_keys_object.dart'; -// copied and renamed as private from /lib/src/constants.dart -const _generatedLocalVarName = 'val'; -const _toJsonMapHelperName = 'writeNotNull'; - -final _isATypeError = isA(); - -// ignore: deprecated_member_use -final _isACastError = isA(); - -Matcher _isAUnrecognizedKeysException(expectedMessage) => - isA() - .having((e) => e.message, 'message', expectedMessage); - Matcher _isMissingKeyException(expectedMessage) => isA() .having((e) => e.message, 'message', expectedMessage); void main() { test('valid values covers all keys', () { - expect(_invalidValueTypes.keys, orderedEquals(_validValues.keys)); + expect(invalidValueTypes.keys, orderedEquals(validValues.keys)); }); test('tracking Map/Iterable types correctly', () { - for (var entry in _validValues.entries) { + for (var entry in validValues.entries) { if (_iterableMapKeys.contains(entry.key) || _encodedAsMapKeys.contains(entry.key)) { expect(entry.value, anyOf(isMap, isList)); @@ -58,9 +47,6 @@ void main() { } else { _nonNullableTests(factory); } - if (factory.anyMap) { - _anyMapTests(factory); - } _sharedTests(factory); }); } @@ -77,27 +63,18 @@ const _jsonConverterValidValues = { }; void _nonNullableTests(KitchenSinkFactory factory) { - test('with null values fails serialization', () { - expect(() => (factory.ctor()..objectDateTimeMap = null).toJson(), - throwsNoSuchMethodError); - }); - test('with empty json fails deserialization', () { Matcher matcher; if (factory.checked) { - matcher = _checkedMatcher('intIterable'); + matcher = checkedMatcher('set'); } else { - matcher = isNoSuchMethodError; + matcher = isA(); } expect(() => factory.fromJson({}), throwsA(matcher)); }); test('nullable values are not allowed in non-nullable version', () { - var instance = factory.jsonConverterCtor(); - expect(() => instance.toJson(), throwsNoSuchMethodError, - reason: 'Trying to call `map` on a null list'); - - instance = factory.jsonConverterFromJson(_jsonConverterValidValues); + final instance = factory.jsonConverterFromJson(_jsonConverterValidValues); final json = instance.toJson(); expect(json, _jsonConverterValidValues); expect(json.values, everyElement(isNotNull)); @@ -116,15 +93,20 @@ void _nullableTests(KitchenSinkFactory factory) { final instance = factory.jsonConverterCtor(); final json = instance.toJson(); - if (factory.excludeNull) { - expect(json, isEmpty); - } else { - expect(json.values, everyElement(isNull)); - expect(json.keys, unorderedEquals(_jsonConverterValidValues.keys)); + expect(json, const { + 'duration': 0, + 'durationList': [], + 'bigInt': '0', + 'bigIntMap': {}, + 'numberSilly': 0, + 'numberSillySet': [], + 'dateTime': 0 + }); - final instance2 = factory.jsonConverterFromJson(json); - expect(instance2.toJson(), json); - } + expect(json.keys, unorderedEquals(_jsonConverterValidValues.keys)); + + final instance2 = factory.jsonConverterFromJson(json); + expect(instance2.toJson(), json); }); test('Fields with `!includeIfNull` should not be included when null', () { @@ -132,21 +114,26 @@ void _nullableTests(KitchenSinkFactory factory) { final encoded = item.toJson(); if (factory.excludeNull) { - expect(encoded, isEmpty); + expect(encoded.keys, orderedEquals(_nonNullableFields)); } else { - expect(encoded.keys, orderedEquals(_validValues.keys)); - - for (final key in _validValues.keys) { - expect(encoded, containsPair(key, isNull)); + expect(encoded.keys, orderedEquals(validValues.keys)); + + for (final key in validValues.keys) { + expect( + encoded, + containsPair( + key, _nonNullableFields.contains(key) ? isNotNull : isNull), + ); } } }); test('list and map of DateTime', () { final now = DateTime.now(); + final later = now.add(const Duration(days: 1)); final item = factory.ctor(dateTimeIterable: [now]) - ..dateTimeList = [now, null] - ..objectDateTimeMap = {'value': now, 'null': null}; + ..dateTimeList = [now, later] + ..objectDateTimeMap = {'value': now, 'null': later}; roundTripSink(item); }); @@ -174,23 +161,6 @@ void _nullableTests(KitchenSinkFactory factory) { }); } -void _anyMapTests(KitchenSinkFactory factory) { - test('valid values round-trip - yaml', () { - final jsonEncoded = loudEncode(_validValues); - final yaml = loadYaml(jsonEncoded, sourceUrl: 'input.yaml'); - expect(jsonEncoded, loudEncode(factory.fromJson(yaml as YamlMap))); - }); - - group('a bad value for', () { - for (final e in _invalidValueTypes.entries) { - _testBadValue(e.key, e.value, factory, false); - } - for (final e in _invalidCheckedValues.entries) { - _testBadValue(e.key, e.value, factory, true); - } - }); -} - void _sharedTests(KitchenSinkFactory factory) { test('empty', () { final item = factory.ctor(); @@ -225,7 +195,7 @@ void _sharedTests(KitchenSinkFactory factory) { }); test('round trip valid, empty values', () { - final values = Map.fromEntries(_validValues.entries.map((e) { + final values = Map.fromEntries(validValues.entries.map((e) { var value = e.value; if (_iterableMapKeys.contains(e.key)) { if (value is List) { @@ -245,160 +215,43 @@ void _sharedTests(KitchenSinkFactory factory) { test('JSON keys should be defined in field/property order', () { final json = factory.ctor().toJson(); - if (factory.excludeNull && factory.nullable) { - expect(json.keys, isEmpty); + if (factory.excludeNull) { + expect(json.keys, _nonNullableFields); } else { - expect(json.keys, orderedEquals(_validValues.keys)); + expect(json.keys, orderedEquals(validValues.keys)); } }); test('valid values round-trip - json', () { - final validInstance = factory.fromJson(_validValues); + final validInstance = factory.fromJson(validValues); roundTripObject(validInstance, factory.fromJson); }); } -void _testBadValue(String key, Object badValue, KitchenSinkFactory factory, - bool checkedAssignment) { - final matcher = _getMatcher(factory.checked, key, checkedAssignment); - - for (final isJson in [true, false]) { - test('`$key` fails with value `$badValue`- ${isJson ? 'json' : 'yaml'}', - () { - var copy = Map.from(_validValues); - copy[key] = badValue; - - if (!isJson) { - copy = loadYaml(loudEncode(copy)) as YamlMap; - } - - expect(() => factory.fromJson(copy), matcher); - }); - } -} - -Matcher _checkedMatcher(String expectedKey) => isA() - .having((e) => e.className, 'className', 'KitchenSink') - .having((e) => e.key, 'key', expectedKey); - -Matcher _getMatcher(bool checked, String expectedKey, bool checkedAssignment) { - Matcher innerMatcher; - - if (checked) { - if (checkedAssignment && - const ['intIterable', 'datetime-iterable'].contains(expectedKey)) { - expectedKey = null; - } - - innerMatcher = _checkedMatcher(expectedKey); - } else { - innerMatcher = anyOf( - _isACastError, - _isATypeError, - _isAUnrecognizedKeysException( - 'Unrecognized keys: [invalid_key]; supported keys: ' - '[value, custom_field]', - ), - ); - - if (checkedAssignment) { - switch (expectedKey) { - case 'validatedPropertyNo42': - innerMatcher = isStateError; - break; - case 'no-42': - innerMatcher = isArgumentError; - break; - case 'strictKeysObject': - innerMatcher = _isAUnrecognizedKeysException('bob'); - break; - case 'intIterable': - case 'datetime-iterable': - innerMatcher = _isACastError; - break; - default: - throw StateError('Not expected! - $expectedKey'); - } - } - } - - return throwsA(innerMatcher); -} - -const _validValues = { - 'no-42': 0, - 'dateTime': '2018-05-10T14:20:58.927', - 'bigInt': '10000000000000000000', - 'iterable': [true], - 'dynamicIterable': [true], - 'objectIterable': [true], - 'intIterable': [42], - 'set': [true], - 'dynamicSet': [true], - 'objectSet': [true], - 'intSet': [42], - 'dateTimeSet': ['2018-05-10T14:20:58.927'], - 'datetime-iterable': ['2018-05-10T14:20:58.927'], - 'list': [true], - 'dynamicList': [true], - 'objectList': [true], - 'intList': [42], - 'dateTimeList': ['2018-05-10T14:20:58.927'], - 'map': {'key': true}, - 'stringStringMap': {'key': 'vaule'}, - 'dynamicIntMap': {'key': 42}, - 'objectDateTimeMap': {'key': '2018-05-10T14:20:58.927'}, - 'crazyComplex': [{}], - _generatedLocalVarName: {'key': true}, - _toJsonMapHelperName: true, - r'$string': 'string', - 'simpleObject': {'value': 42}, - 'strictKeysObject': {'value': 10, 'custom_field': 'cool'}, - 'validatedPropertyNo42': 0 -}; - -const _invalidValueTypes = { - 'no-42': true, - 'dateTime': true, - 'bigInt': true, - 'iterable': true, - 'dynamicIterable': true, - 'objectIterable': true, - 'intIterable': true, - 'set': true, - 'dynamicSet': true, - 'objectSet': true, - 'intSet': true, - 'dateTimeSet': true, - 'datetime-iterable': true, - 'list': true, - 'dynamicList': true, - 'objectList': true, - 'intList': [true], - 'dateTimeList': [true], - 'map': true, - 'stringStringMap': {'key': 42}, - 'dynamicIntMap': {'key': 'value'}, - 'objectDateTimeMap': {'key': 42}, - 'crazyComplex': [true], - _generatedLocalVarName: {'key': 42}, - _toJsonMapHelperName: 42, - r'$string': true, - 'simpleObject': 42, - 'strictKeysObject': { - 'value': 10, - 'invalid_key': true, - }, - 'validatedPropertyNo42': true -}; - -/// Invalid values that are found after the property set or ctor call -const _invalidCheckedValues = { - 'no-42': 42, - 'validatedPropertyNo42': 42, - 'intIterable': [true], - 'datetime-iterable': [true], -}; +const _nonNullableFields = [ + 'dynamicIterable', + 'objectIterable', + 'intIterable', + 'set', + 'dynamicSet', + 'objectSet', + 'intSet', + 'dateTimeSet', + 'datetime-iterable', + 'list', + 'dynamicList', + 'objectList', + 'intList', + 'dateTimeList', + 'map', + 'stringStringMap', + 'dynamicIntMap', + 'objectDateTimeMap', + 'crazyComplex', + 'val', + 'simpleObject', + 'strictKeysObject' +]; const _encodedAsMapKeys = ['simpleObject', 'strictKeysObject']; @@ -426,5 +279,5 @@ const _iterableMapKeys = [ 'objectSet', 'set', 'stringStringMap', - _generatedLocalVarName, + generatedLocalVarName, ]; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink_test_shared.dart b/json_serializable/test/kitchen_sink/kitchen_sink_test_shared.dart new file mode 100644 index 000000000..bc5456e17 --- /dev/null +++ b/json_serializable/test/kitchen_sink/kitchen_sink_test_shared.dart @@ -0,0 +1,80 @@ +// @dart=2.12 + +import 'package:json_annotation/json_annotation.dart'; +import 'package:test/test.dart'; + +const validValues = { + 'no-42': 0, + 'dateTime': '2018-05-10T14:20:58.927', + 'bigInt': '10000000000000000000', + 'iterable': [true], + 'dynamicIterable': [true], + 'objectIterable': [true], + 'intIterable': [42], + 'set': [true], + 'dynamicSet': [true], + 'objectSet': [true], + 'intSet': [42], + 'dateTimeSet': ['2018-05-10T14:20:58.927'], + 'datetime-iterable': ['2018-05-10T14:20:58.927'], + 'list': [true], + 'dynamicList': [true], + 'objectList': [true], + 'intList': [42], + 'dateTimeList': ['2018-05-10T14:20:58.927'], + 'map': {'key': true}, + 'stringStringMap': {'key': 'vaule'}, + 'dynamicIntMap': {'key': 42}, + 'objectDateTimeMap': {'key': '2018-05-10T14:20:58.927'}, + 'crazyComplex': [{}], + generatedLocalVarName: {'key': true}, + _toJsonMapHelperName: true, + r'$string': 'string', + 'simpleObject': {'value': 42}, + 'strictKeysObject': {'value': 10, 'custom_field': 'cool'}, + 'validatedPropertyNo42': 0 +}; + +const invalidValueTypes = { + 'no-42': true, + 'dateTime': true, + 'bigInt': true, + 'iterable': true, + 'dynamicIterable': true, + 'objectIterable': true, + 'intIterable': true, + 'set': true, + 'dynamicSet': true, + 'objectSet': true, + 'intSet': true, + 'dateTimeSet': true, + 'datetime-iterable': true, + 'list': true, + 'dynamicList': true, + 'objectList': true, + 'intList': [true], + 'dateTimeList': [true], + 'map': true, + 'stringStringMap': {'key': 42}, + 'dynamicIntMap': {'key': 'value'}, + 'objectDateTimeMap': {'key': 42}, + 'crazyComplex': [true], + generatedLocalVarName: {'key': 42}, + _toJsonMapHelperName: 42, + r'$string': true, + 'simpleObject': 42, + 'strictKeysObject': { + 'value': 10, + 'invalid_key': true, + }, + 'validatedPropertyNo42': true +}; + +Matcher checkedMatcher(String? expectedKey) => isA() + .having((e) => e.className, 'className', 'KitchenSink') + .having((e) => e.key, 'key', expectedKey); + +// copied and renamed as private from /lib/src/constants.dart +const generatedLocalVarName = 'val'; + +const _toJsonMapHelperName = 'writeNotNull'; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink_yaml_test.dart b/json_serializable/test/kitchen_sink/kitchen_sink_yaml_test.dart new file mode 100644 index 000000000..d7ca08141 --- /dev/null +++ b/json_serializable/test/kitchen_sink/kitchen_sink_yaml_test.dart @@ -0,0 +1,113 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:test/test.dart'; +import 'package:yaml/yaml.dart'; + +import '../test_utils.dart'; +import 'kitchen_sink.factories.dart'; +import 'kitchen_sink_interface.dart'; +import 'kitchen_sink_test_shared.dart'; + +void main() { + for (var factory in factories.where((element) => element.anyMap)) { + group(factory.description, () { + _anyMapTests(factory); + }); + } +} + +void _anyMapTests(KitchenSinkFactory factory) { + test('valid values round-trip - yaml', () { + final jsonEncoded = loudEncode(validValues); + final yaml = loadYaml(jsonEncoded, sourceUrl: 'input.yaml'); + expect(jsonEncoded, loudEncode(factory.fromJson(yaml as YamlMap))); + }); + + group('a bad value for', () { + for (final e in invalidValueTypes.entries) { + _testBadValue(e.key, e.value, factory, false); + } + for (final e in _invalidCheckedValues.entries) { + _testBadValue(e.key, e.value, factory, true); + } + }); +} + +void _testBadValue(String key, Object badValue, KitchenSinkFactory factory, + bool checkedAssignment) { + final matcher = _getMatcher(factory.checked, key, checkedAssignment); + + for (final isJson in [true, false]) { + test('`$key` fails with value `$badValue`- ${isJson ? 'json' : 'yaml'}', + () { + var copy = Map.from(validValues); + copy[key] = badValue; + + if (!isJson) { + copy = loadYaml(loudEncode(copy)) as YamlMap; + } + + expect(() => factory.fromJson(copy), matcher); + }); + } +} + +Matcher _getMatcher(bool checked, String expectedKey, bool checkedAssignment) { + Matcher innerMatcher; + + if (checked) { + if (checkedAssignment && + const ['intIterable', 'datetime-iterable'].contains(expectedKey)) { + expectedKey = null; + } + + innerMatcher = checkedMatcher(expectedKey); + } else { + innerMatcher = anyOf( + _isACastError, + _isATypeError, + _isAUnrecognizedKeysException( + 'Unrecognized keys: [invalid_key]; supported keys: ' + '[value, custom_field]', + ), + ); + + if (checkedAssignment) { + switch (expectedKey) { + case 'validatedPropertyNo42': + innerMatcher = isStateError; + break; + case 'no-42': + innerMatcher = isArgumentError; + break; + case 'strictKeysObject': + innerMatcher = _isAUnrecognizedKeysException('bob'); + break; + case 'intIterable': + case 'datetime-iterable': + innerMatcher = _isACastError; + break; + default: + throw StateError('Not expected! - $expectedKey'); + } + } + } + + return throwsA(innerMatcher); +} + +final _isATypeError = isA(); + +// ignore: deprecated_member_use +final _isACastError = isA(); + +Matcher _isAUnrecognizedKeysException(expectedMessage) => + isA() + .having((e) => e.message, 'message', expectedMessage); + +/// Invalid values that are found after the property set or ctor call +const _invalidCheckedValues = { + 'no-42': 42, + 'validatedPropertyNo42': 42, + 'intIterable': [true], + 'datetime-iterable': [true], +}; diff --git a/json_serializable/test/kitchen_sink/simple_object.dart b/json_serializable/test/kitchen_sink/simple_object.dart index c02cefc31..b5816fc29 100644 --- a/json_serializable/test/kitchen_sink/simple_object.dart +++ b/json_serializable/test/kitchen_sink/simple_object.dart @@ -2,6 +2,8 @@ // 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. +// @dart=2.12 + import 'package:json_annotation/json_annotation.dart'; part 'simple_object.g.dart'; diff --git a/json_serializable/test/kitchen_sink/simple_object.g.dart b/json_serializable/test/kitchen_sink/simple_object.g.dart index 42d584b69..ad76883f5 100644 --- a/json_serializable/test/kitchen_sink/simple_object.g.dart +++ b/json_serializable/test/kitchen_sink/simple_object.g.dart @@ -1,4 +1,5 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// @dart=2.12 part of 'simple_object.dart'; diff --git a/json_serializable/test/kitchen_sink/strict_keys_object.dart b/json_serializable/test/kitchen_sink/strict_keys_object.dart index 757f3eb5c..bc54f9ba8 100644 --- a/json_serializable/test/kitchen_sink/strict_keys_object.dart +++ b/json_serializable/test/kitchen_sink/strict_keys_object.dart @@ -2,6 +2,8 @@ // 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. +// @dart=2.12 + import 'package:json_annotation/json_annotation.dart'; part 'strict_keys_object.g.dart'; diff --git a/json_serializable/test/kitchen_sink/strict_keys_object.g.dart b/json_serializable/test/kitchen_sink/strict_keys_object.g.dart index dfdda8eaa..50dd9e5d6 100644 --- a/json_serializable/test/kitchen_sink/strict_keys_object.g.dart +++ b/json_serializable/test/kitchen_sink/strict_keys_object.g.dart @@ -1,4 +1,5 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// @dart=2.12 part of 'strict_keys_object.dart'; diff --git a/json_serializable/test/shared_config.dart b/json_serializable/test/shared_config.dart index e8a38d5e0..708c7a7e1 100644 --- a/json_serializable/test/shared_config.dart +++ b/json_serializable/test/shared_config.dart @@ -20,6 +20,5 @@ final generatorConfigNonDefaultJson = fieldRename: FieldRename.kebab, ignoreUnannotated: true, includeIfNull: false, - nullable: false, genericArgumentFactories: true, ).toJson()); diff --git a/json_serializable/test/src/_json_serializable_test_input.dart b/json_serializable/test/src/_json_serializable_test_input.dart index ca5b848c9..e43b91620 100644 --- a/json_serializable/test/src/_json_serializable_test_input.dart +++ b/json_serializable/test/src/_json_serializable_test_input.dart @@ -2,10 +2,14 @@ // 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. +// @dart=2.12 + import 'dart:collection'; import 'package:json_annotation/json_annotation.dart'; -import 'package:json_serializable/src/helper_core.dart'; +import 'package:json_serializable/src/constants.dart'; + +// ignore: import_of_legacy_library_into_null_safe import 'package:source_gen_test/annotations.dart'; part 'checked_test_input.dart'; @@ -36,7 +40,7 @@ const theAnswer = 42; @ShouldThrow('`@JsonSerializable` can only be used on classes.') @JsonSerializable() -Object annotatedMethod() => null; +Object annotatedMethod() => throw UnimplementedError(); @ShouldGenerate( r''' @@ -64,12 +68,11 @@ GeneralTestClass1 _$GeneralTestClass1FromJson(Map json) { ..firstName = json['firstName'] as String ..lastName = json['lastName'] as String ..height = json['h'] as int - ..dateOfBirth = json['dateOfBirth'] == null - ? null - : DateTime.parse(json['dateOfBirth'] as String) + ..dateOfBirth = DateTime.parse(json['dateOfBirth'] as String) ..dynamicType = json['dynamicType'] ..varType = json['varType'] - ..listOfInts = (json['listOfInts'] as List)?.map((e) => e as int)?.toList(); + ..listOfInts = + (json['listOfInts'] as List).map((e) => e as int).toList(); } Map _$GeneralTestClass1ToJson(GeneralTestClass1 instance) => @@ -77,7 +80,7 @@ Map _$GeneralTestClass1ToJson(GeneralTestClass1 instance) => 'firstName': instance.firstName, 'lastName': instance.lastName, 'h': instance.height, - 'dateOfBirth': instance.dateOfBirth?.toIso8601String(), + 'dateOfBirth': instance.dateOfBirth.toIso8601String(), 'dynamicType': instance.dynamicType, 'varType': instance.varType, 'listOfInts': instance.listOfInts, @@ -85,15 +88,15 @@ Map _$GeneralTestClass1ToJson(GeneralTestClass1 instance) => ''') @JsonSerializable() class GeneralTestClass1 { - String firstName, lastName; + late String firstName, lastName; @JsonKey(name: 'h') - int height; - DateTime dateOfBirth; + late int height; + late DateTime dateOfBirth; dynamic dynamicType; //ignore: prefer_typing_uninitialized_variables var varType; - List listOfInts; + late List listOfInts; } @ShouldGenerate(r''' @@ -101,10 +104,8 @@ GeneralTestClass2 _$GeneralTestClass2FromJson(Map json) { return GeneralTestClass2( json['height'] as int, json['firstName'] as String, - json['lastName'] as String, - )..dateOfBirth = json['dateOfBirth'] == null - ? null - : DateTime.parse(json['dateOfBirth'] as String); + json['lastName'] as String?, + )..dateOfBirth = DateTime.parse(json['dateOfBirth'] as String); } Map _$GeneralTestClass2ToJson(GeneralTestClass2 instance) => @@ -112,14 +113,15 @@ Map _$GeneralTestClass2ToJson(GeneralTestClass2 instance) => 'firstName': instance.firstName, 'lastName': instance.lastName, 'height': instance.height, - 'dateOfBirth': instance.dateOfBirth?.toIso8601String(), + 'dateOfBirth': instance.dateOfBirth.toIso8601String(), }; ''') @JsonSerializable() class GeneralTestClass2 { - final String firstName, lastName; - int height; - DateTime dateOfBirth; + final String firstName; + final String? lastName; + late int height; + late DateTime dateOfBirth; GeneralTestClass2(this.height, String firstName, [this.lastName]) : @@ -171,13 +173,13 @@ class FinalFieldsNotSetInCtor { @ShouldGenerate(r''' SetSupport _$SetSupportFromJson(Map json) { return SetSupport( - (json['values'] as List)?.map((e) => e as int)?.toSet(), + (json['values'] as List).map((e) => e as int).toSet(), ); } Map _$SetSupportToJson(SetSupport instance) => { - 'values': instance.values?.toList(), + 'values': instance.values.toList(), }; ''') @JsonSerializable() @@ -196,7 +198,7 @@ $converterOrKeyInstructions''', ) @JsonSerializable(createFactory: false) class NoSerializeFieldType { - Stopwatch watch; + Stopwatch? watch; } @ShouldThrow( @@ -208,7 +210,7 @@ $converterOrKeyInstructions''', ) @JsonSerializable(createToJson: false) class NoDeserializeFieldType { - Stopwatch watch; + Stopwatch? watch; } @ShouldThrow( @@ -219,7 +221,7 @@ Map keys must be one of: Object, dynamic, enum, String, BigInt, DateTime, int, U ) @JsonSerializable(createFactory: false) class NoSerializeBadKey { - Map durationDateTimeMap; + late Map durationDateTimeMap; } @ShouldThrow( @@ -230,7 +232,7 @@ Map keys must be one of: Object, dynamic, enum, String, BigInt, DateTime, int, U ) @JsonSerializable(createToJson: false) class NoDeserializeBadKey { - Map durationDateTimeMap; + late Map durationDateTimeMap; } @ShouldGenerate( @@ -256,8 +258,8 @@ Map _$IncludeIfNullOverrideToJson( @JsonSerializable(createFactory: false, includeIfNull: false) class IncludeIfNullOverride { @JsonKey(includeIfNull: true) - int number; - String str; + int? number; + String? str; } // https://github.com/google/json_serializable.dart/issues/7 regression @@ -267,10 +269,11 @@ class IncludeIfNullOverride { ) @JsonSerializable() class NoCtorClass { - final int member; + late final int member; //ignore: avoid_unused_constructor_parameters - factory NoCtorClass.fromJson(Map json) => null; + factory NoCtorClass.fromJson(Map json) => + throw UnimplementedError(); } @ShouldThrow( @@ -280,9 +283,9 @@ class NoCtorClass { @JsonSerializable(createFactory: false) class KeyDupesField { @JsonKey(name: 'str') - int number; + late int number; - String str; + late String str; } @ShouldThrow( @@ -292,10 +295,10 @@ class KeyDupesField { @JsonSerializable(createFactory: false) class DupeKeys { @JsonKey(name: 'a') - int number; + late int number; @JsonKey(name: 'a') - String str; + late String str; } @ShouldGenerate(r''' @@ -308,12 +311,12 @@ Map _$IgnoredFieldClassToJson(IgnoredFieldClass instance) => @JsonSerializable(createFactory: false) class IgnoredFieldClass { @JsonKey(ignore: true) - int ignoredTrueField; + late int ignoredTrueField; @JsonKey(ignore: false) - int ignoredFalseField; + late int ignoredFalseField; - int ignoredNullField; + late int ignoredNullField; } @ShouldThrow( @@ -351,7 +354,7 @@ class PrivateFieldCtorClass { @JsonSerializable() class IncludeIfNullDisallowNullClass { @JsonKey(includeIfNull: true, disallowNullValue: true) - int field; + late int field; } @ShouldThrow( @@ -361,7 +364,7 @@ class IncludeIfNullDisallowNullClass { ) @JsonSerializable() class JsonValueWithBool { - BadEnum field; + late BadEnum field; } enum BadEnum { @@ -379,7 +382,7 @@ enum BadEnum { ''', contains: true) @JsonSerializable() class JsonValueValid { - GoodEnum field; + late GoodEnum field; } enum GoodEnum { @@ -400,22 +403,20 @@ FieldWithFromJsonCtorAndTypeParams _$FieldWithFromJsonCtorAndTypeParamsFromJson( return FieldWithFromJsonCtorAndTypeParams() ..customOrders = json['customOrders'] == null ? null - : MyList.fromJson((json['customOrders'] as List) - ?.map((e) => e == null - ? null - : GeneralTestClass2.fromJson(e as Map)) - ?.toList()); + : MyList.fromJson((json['customOrders'] as List) + .map((e) => GeneralTestClass2.fromJson(e as Map)) + .toList()); } ''') @JsonSerializable(createToJson: false) class FieldWithFromJsonCtorAndTypeParams { - MyList customOrders; + MyList? customOrders; } class MyList extends ListBase { final List _data; - MyList(Iterable source) : _data = source.toList() ?? []; + MyList(Iterable source) : _data = source.toList(); factory MyList.fromJson(List items) => MyList(items); @@ -437,8 +438,7 @@ class MyList extends ListBase { } mixin _PropInMixinI448RegressionMixin { - @JsonKey(nullable: true) - int nullable; + late int nullable; } @ShouldGenerate(r''' @@ -458,8 +458,8 @@ Map _$PropInMixinI448RegressionToJson( ''') @JsonSerializable() class PropInMixinI448Regression with _PropInMixinI448RegressionMixin { - @JsonKey(nullable: false) - int notNullable; + @JsonKey() + late int notNullable; } @ShouldGenerate( @@ -477,9 +477,9 @@ Map _$IgnoreUnannotatedToJson(IgnoreUnannotated instance) => @JsonSerializable(ignoreUnannotated: true) class IgnoreUnannotated { @JsonKey() - int annotated; + late int annotated; - int unannotated; + late int unannotated; } @ShouldGenerate( @@ -497,7 +497,7 @@ Map _$SubclassedJsonKeyToJson(SubclassedJsonKey instance) => @JsonSerializable(ignoreUnannotated: true) class SubclassedJsonKey { @MyJsonKey() - int annotatedWithSubclass; + late int annotatedWithSubclass; } class MyJsonKey extends JsonKey { @@ -518,7 +518,7 @@ Map _$OverrideGetterExampleI613ToJson( }; ''', ) -@JsonSerializable(nullable: false) +@JsonSerializable() class OverrideGetterExampleI613 extends OverrideGetterExampleI613Super { @override String get id => throw UnimplementedError(); @@ -537,7 +537,7 @@ class OverrideGetterExampleI613Super { ) @JsonSerializable() class InvalidChildClassFromJson { - NoParamFromJsonCtor field; + late NoParamFromJsonCtor field; } class NoParamFromJsonCtor { @@ -547,20 +547,20 @@ class NoParamFromJsonCtor { @ShouldThrow( 'Expecting a `fromJson` constructor with exactly one positional parameter. ' 'The only extra parameters allowed are functions of the form ' - '`T Function(Object) fromJsonT` ' + '`T Function(Object?) fromJsonT` ' 'where `T` is a type parameter of the target type.', element: 'fromJson', ) @JsonSerializable() class InvalidChildClassFromJson2 { - ExtraParamFromJsonCtor field; + late ExtraParamFromJsonCtor field; } class ExtraParamFromJsonCtor { // ignore: avoid_unused_constructor_parameters ExtraParamFromJsonCtor.fromJson(Map json, int oops); - Map toJson() => null; + Map toJson() => throw UnimplementedError(); } @ShouldThrow( @@ -572,12 +572,12 @@ class ExtraParamFromJsonCtor { ) @JsonSerializable() class InvalidChildClassFromJson3 { - ExtraParamToJson field; + late ExtraParamToJson field; } class ExtraParamToJson { // ignore: avoid_unused_constructor_parameters ExtraParamToJson.fromJson(Map json); - Map toJson(int bob) => null; + Map toJson(int bob) => throw UnimplementedError(); } diff --git a/json_serializable/test/src/checked_test_input.dart b/json_serializable/test/src/checked_test_input.dart index a7e6e151a..7d3d17238 100644 --- a/json_serializable/test/src/checked_test_input.dart +++ b/json_serializable/test/src/checked_test_input.dart @@ -1,3 +1,5 @@ +// @dart=2.12 + part of '_json_serializable_test_input.dart'; @ShouldGenerate(r''' @@ -9,8 +11,8 @@ WithANonCtorGetterChecked _$WithANonCtorGetterCheckedFromJson( requiredKeys: const ['items'], disallowNullValues: const ['items']); final val = WithANonCtorGetterChecked( - $checkedConvert( - json, 'items', (v) => (v as List)?.map((e) => e as String)?.toList()), + $checkedConvert(json, 'items', + (v) => (v as List).map((e) => e as String).toList()), ); return val; }); @@ -37,7 +39,7 @@ WithANonCtorGetter _$WithANonCtorGetterFromJson(Map json) { requiredKeys: const ['items'], disallowNullValues: const ['items']); return WithANonCtorGetter( - (json['items'] as List)?.map((e) => e as String)?.toList(), + (json['items'] as List).map((e) => e as String).toList(), ); } ''') diff --git a/json_serializable/test/src/core_subclass_type_input.dart b/json_serializable/test/src/core_subclass_type_input.dart index bad046a8f..8f58465cc 100644 --- a/json_serializable/test/src/core_subclass_type_input.dart +++ b/json_serializable/test/src/core_subclass_type_input.dart @@ -1,3 +1,5 @@ +// @dart=2.12 + part of '_json_serializable_test_input.dart'; @ShouldThrow( @@ -9,7 +11,7 @@ $converterOrKeyInstructions''', ) @JsonSerializable(createToJson: false) class UnsupportedMapField { - MapView mapView; + late MapView mapView; } @ShouldThrow( @@ -21,7 +23,7 @@ $converterOrKeyInstructions''', ) @JsonSerializable(createToJson: false) class UnsupportedListField { - UnmodifiableListView listView; + late UnmodifiableListView listView; } @ShouldThrow( @@ -33,7 +35,7 @@ $converterOrKeyInstructions''', ) @JsonSerializable(createToJson: false) class UnsupportedSetField { - _CustomSet customSet; + late _CustomSet customSet; } abstract class _CustomSet implements Set {} @@ -47,7 +49,7 @@ $converterOrKeyInstructions''', ) @JsonSerializable(createToJson: false) class UnsupportedDurationField { - _CustomDuration customDuration; + late _CustomDuration customDuration; } abstract class _CustomDuration implements Duration {} @@ -61,7 +63,7 @@ $converterOrKeyInstructions''', ) @JsonSerializable(createToJson: false) class UnsupportedUriField { - _CustomUri customUri; + _CustomUri? customUri; } abstract class _CustomUri implements Uri {} @@ -75,7 +77,7 @@ $converterOrKeyInstructions''', ) @JsonSerializable(createToJson: false) class UnsupportedDateTimeField { - _CustomDateTime customDateTime; + late _CustomDateTime customDateTime; } abstract class _CustomDateTime implements DateTime {} diff --git a/json_serializable/test/src/default_value_input.dart b/json_serializable/test/src/default_value_input.dart index 94c14cacb..aca8e90dd 100644 --- a/json_serializable/test/src/default_value_input.dart +++ b/json_serializable/test/src/default_value_input.dart @@ -2,6 +2,8 @@ // 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. +// @dart=2.12 + part of '_json_serializable_test_input.dart'; @ShouldThrow( @@ -12,7 +14,7 @@ part of '_json_serializable_test_input.dart'; @JsonSerializable() class DefaultWithSymbol { @JsonKey(defaultValue: #symbol) - Object field; + late Object field; DefaultWithSymbol(); } @@ -27,7 +29,7 @@ int _function() => 42; @JsonSerializable() class DefaultWithFunction { @JsonKey(defaultValue: _function) - Object field; + Object? field; DefaultWithFunction(); } @@ -40,7 +42,7 @@ class DefaultWithFunction { @JsonSerializable() class DefaultWithType { @JsonKey(defaultValue: Object) - Object field; + late Object field; DefaultWithType(); } @@ -53,7 +55,7 @@ class DefaultWithType { @JsonSerializable() class DefaultWithConstObject { @JsonKey(defaultValue: Duration()) - Object field; + late Object field; DefaultWithConstObject(); } @@ -68,37 +70,11 @@ enum Enum { value } @JsonSerializable() class DefaultWithNestedEnum { @JsonKey(defaultValue: [Enum.value]) - Object field; + late Object field; DefaultWithNestedEnum(); } -@ShouldThrow( - 'Error with `@JsonKey` on `field`. ' - 'Cannot use `defaultValue` on a field with `nullable` false.', - element: 'field', -) -@JsonSerializable() -class DefaultWithNonNullableField { - @JsonKey(defaultValue: 42, nullable: false) - Object field; - - DefaultWithNonNullableField(); -} - -@ShouldThrow( - 'Error with `@JsonKey` on `field`. ' - 'Cannot use `defaultValue` on a field with `nullable` false.', - element: 'field', -) -@JsonSerializable(nullable: false) -class DefaultWithNonNullableClass { - @JsonKey(defaultValue: 42) - Object field; - - DefaultWithNonNullableClass(); -} - @ShouldGenerate( r''' DefaultWithToJsonClass _$DefaultWithToJsonClassFromJson( @@ -118,7 +94,7 @@ Instead of using `defaultValue`, set `nullable: false` and handle `null` in the @JsonSerializable(createToJson: false) class DefaultWithToJsonClass { @JsonKey(defaultValue: 7, fromJson: _fromJson) - int fieldDefaultValueToJson; + late int fieldDefaultValueToJson; DefaultWithToJsonClass(); @@ -132,7 +108,7 @@ DefaultWithDisallowNullRequiredClass $checkKeys(json, requiredKeys: const ['theField'], disallowNullValues: const ['theField']); return DefaultWithDisallowNullRequiredClass() - ..theField = json['theField'] as int ?? 7; + ..theField = json['theField'] as int? ?? 7; } ''', expectedLogItems: [ @@ -143,7 +119,7 @@ DefaultWithDisallowNullRequiredClass @JsonSerializable(createToJson: false) class DefaultWithDisallowNullRequiredClass { @JsonKey(defaultValue: 7, disallowNullValue: true, required: true) - int theField; + int? theField; DefaultWithDisallowNullRequiredClass(); } @@ -152,33 +128,33 @@ class DefaultWithDisallowNullRequiredClass { DefaultDoubleConstants _$DefaultDoubleConstantsFromJson( Map json) { return DefaultDoubleConstants() - ..defaultNan = (json['defaultNan'] as num)?.toDouble() ?? double.nan + ..defaultNan = (json['defaultNan'] as num?)?.toDouble() ?? double.nan ..defaultNegativeInfinity = - (json['defaultNegativeInfinity'] as num)?.toDouble() ?? + (json['defaultNegativeInfinity'] as num?)?.toDouble() ?? double.negativeInfinity ..defaultInfinity = - (json['defaultInfinity'] as num)?.toDouble() ?? double.infinity + (json['defaultInfinity'] as num?)?.toDouble() ?? double.infinity ..defaultMinPositive = - (json['defaultMinPositive'] as num)?.toDouble() ?? 5e-324 - ..defaultMaxFinite = (json['defaultMaxFinite'] as num)?.toDouble() ?? + (json['defaultMinPositive'] as num?)?.toDouble() ?? 5e-324 + ..defaultMaxFinite = (json['defaultMaxFinite'] as num?)?.toDouble() ?? 1.7976931348623157e+308; } ''') @JsonSerializable(createToJson: false) class DefaultDoubleConstants { @JsonKey(defaultValue: double.nan) - double defaultNan; + late double defaultNan; @JsonKey(defaultValue: double.negativeInfinity) - double defaultNegativeInfinity; + late double defaultNegativeInfinity; @JsonKey(defaultValue: double.infinity) - double defaultInfinity; + late double defaultInfinity; // Since these values can be represented as number literals, there is no // special handling. Including them here for completeness, though. @JsonKey(defaultValue: double.minPositive) - double defaultMinPositive; + late double defaultMinPositive; @JsonKey(defaultValue: double.maxFinite) - double defaultMaxFinite; + late double defaultMaxFinite; DefaultDoubleConstants(); } diff --git a/json_serializable/test/src/field_namer_input.dart b/json_serializable/test/src/field_namer_input.dart index f8ec3c66e..1a0cb07ca 100644 --- a/json_serializable/test/src/field_namer_input.dart +++ b/json_serializable/test/src/field_namer_input.dart @@ -1,3 +1,5 @@ +// @dart=2.12 + part of '_json_serializable_test_input.dart'; @ShouldGenerate(r''' @@ -9,10 +11,10 @@ Map _$FieldNamerNoneToJson(FieldNamerNone instance) => ''') @JsonSerializable(fieldRename: FieldRename.none, createFactory: false) class FieldNamerNone { - String theField; + late String theField; @JsonKey(name: 'NAME_OVERRIDE') - String nameOverride; + late String nameOverride; } @ShouldGenerate(r''' @@ -24,10 +26,10 @@ Map _$FieldNamerKebabToJson(FieldNamerKebab instance) => ''') @JsonSerializable(fieldRename: FieldRename.kebab, createFactory: false) class FieldNamerKebab { - String theField; + late String theField; @JsonKey(name: 'NAME_OVERRIDE') - String nameOverride; + late String nameOverride; } @ShouldGenerate(r''' @@ -39,10 +41,10 @@ Map _$FieldNamerPascalToJson(FieldNamerPascal instance) => ''') @JsonSerializable(fieldRename: FieldRename.pascal, createFactory: false) class FieldNamerPascal { - String theField; + late String theField; @JsonKey(name: 'NAME_OVERRIDE') - String nameOverride; + late String nameOverride; } @ShouldGenerate(r''' @@ -54,8 +56,8 @@ Map _$FieldNamerSnakeToJson(FieldNamerSnake instance) => ''') @JsonSerializable(fieldRename: FieldRename.snake, createFactory: false) class FieldNamerSnake { - String theField; + late String theField; @JsonKey(name: 'NAME_OVERRIDE') - String nameOverride; + late String nameOverride; } diff --git a/json_serializable/test/src/generic_test_input.dart b/json_serializable/test/src/generic_test_input.dart index b8642c87c..e60c395e9 100644 --- a/json_serializable/test/src/generic_test_input.dart +++ b/json_serializable/test/src/generic_test_input.dart @@ -2,6 +2,8 @@ // 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. +// @dart=2.12 + part of '_json_serializable_test_input.dart'; @ShouldThrow( @@ -15,7 +17,7 @@ $converterOrKeyInstructions ) @JsonSerializable() class Issue713 { - List result; + List? result; } @ShouldGenerate(r''' @@ -42,26 +44,26 @@ Map _$GenericClassToJson( @JsonSerializable() class GenericClass { @JsonKey(fromJson: _dataFromJson, toJson: _dataToJson) - Object fieldObject; + late Object fieldObject; @JsonKey(fromJson: _dataFromJson, toJson: _dataToJson) dynamic fieldDynamic; @JsonKey(fromJson: _dataFromJson, toJson: _dataToJson) - int fieldInt; + late int fieldInt; @JsonKey(fromJson: _dataFromJson, toJson: _dataToJson) - T fieldT; + late T fieldT; @JsonKey(fromJson: _dataFromJson, toJson: _dataToJson) - S fieldS; + late S fieldS; GenericClass(); } -T _dataFromJson(Object input) => null; +T _dataFromJson(Object? input) => throw UnimplementedError(); -Object _dataToJson(T input) => null; +Object _dataToJson(T input) => throw UnimplementedError(); @ShouldGenerate( r''' diff --git a/json_serializable/test/src/inheritance_test_input.dart b/json_serializable/test/src/inheritance_test_input.dart index 68be3de05..5d0294408 100644 --- a/json_serializable/test/src/inheritance_test_input.dart +++ b/json_serializable/test/src/inheritance_test_input.dart @@ -1,3 +1,5 @@ +// @dart=2.12 + part of '_json_serializable_test_input.dart'; @ShouldGenerate(r''' @@ -6,7 +8,7 @@ SubType _$SubTypeFromJson(Map json) { json['subTypeViaCtor'] as int, json['super-final-field'] as int, ) - ..superReadWriteField = json['superReadWriteField'] as int + ..superReadWriteField = json['superReadWriteField'] as int? ..subTypeReadWrite = json['subTypeReadWrite'] as int; } @@ -29,8 +31,8 @@ Map _$SubTypeToJson(SubType instance) { ''') @JsonSerializable() class SubType extends SuperType { - final int subTypeViaCtor; - int subTypeReadWrite; + late final int subTypeViaCtor; + late int subTypeReadWrite; SubType(this.subTypeViaCtor, int superFinalField) : super(superFinalField); } @@ -38,11 +40,11 @@ class SubType extends SuperType { // NOTE: `SuperType` is intentionally after `SubType` in the source file to // validate field ordering semantics. class SuperType { - @JsonKey(name: 'super-final-field', nullable: false) - final int superFinalField; + @JsonKey(name: 'super-final-field') + final int? superFinalField; @JsonKey(includeIfNull: false) - int superReadWriteField; + int? superReadWriteField; SuperType(this.superFinalField); @@ -51,8 +53,7 @@ class SuperType { int get priceHalf => priceFraction(2); /// Add a method to try to throw-off the generator - int priceFraction(int other) => - superFinalField == null ? null : superFinalField ~/ other; + int priceFraction(int other) => superFinalField! ~/ other; } @ShouldGenerate(r''' @@ -97,17 +98,17 @@ class SubTypeWithAnnotatedFieldOverrideExtendsWithOverrides extends SuperType { /// The annotation applied here overrides the annotation in [SuperType]. @JsonKey(includeIfNull: true) @override - int get superReadWriteField => super.superReadWriteField; + int? get superReadWriteField => super.superReadWriteField; @override - set superReadWriteField(int value) { + set superReadWriteField(int? value) { super.superReadWriteField = value; } /// The order is picked up by this override, but the annotation is still /// applied from [SuperType]. @override - int get superFinalField => super.superFinalField; + int? get superFinalField => super.superFinalField; } @ShouldGenerate(r''' @@ -122,7 +123,7 @@ Map _$SubTypeWithAnnotatedFieldOverrideImplementsToJson( class SubTypeWithAnnotatedFieldOverrideImplements implements SuperType { // Note the order of fields in the output is determined by this class @override - int superReadWriteField; + int? superReadWriteField; @JsonKey(ignore: true) @override diff --git a/json_serializable/test/src/json_converter_test_input.dart b/json_serializable/test/src/json_converter_test_input.dart index 988886941..df58ecd00 100644 --- a/json_serializable/test/src/json_converter_test_input.dart +++ b/json_serializable/test/src/json_converter_test_input.dart @@ -2,6 +2,8 @@ // 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. +// @dart=2.12 + part of '_json_serializable_test_input.dart'; @ShouldGenerate(r''' @@ -31,14 +33,14 @@ Map _$JsonConverterNamedCtorToJson( @_DurationMillisecondConverter.named() @_GenericConverter.named() class JsonConverterNamedCtor { - Duration value; - E genericValue; + late Duration value; + late E genericValue; // Field annotations have precedence over class annotations @JsonKey(fromJson: _fromJson, toJson: _toJson) - Duration keyAnnotationFirst; + late Duration keyAnnotationFirst; - static Duration _fromJson(int value) => null; + static Duration _fromJson(int value) => throw UnimplementedError(); static int _toJson(Duration object) => 42; } @@ -73,15 +75,15 @@ Map _$JsonConvertOnFieldToJson( @_durationConverter class JsonConvertOnField { @_DurationMillisecondConverter() - Duration annotatedField; + late Duration annotatedField; @_DurationMillisecondConverter.named() - Duration annotatedWithNamedCtor; + late Duration annotatedWithNamedCtor; - Duration classAnnotatedWithField; + late Duration classAnnotatedWithField; @_GenericConverter() - E genericValue; + late E genericValue; } class _GenericConverter implements JsonConverter { @@ -90,7 +92,7 @@ class _GenericConverter implements JsonConverter { const _GenericConverter.named(); @override - T fromJson(int json) => null; + T fromJson(int json) => throw UnimplementedError(); @override int toJson(T object) => 0; @@ -104,14 +106,14 @@ class _GenericConverter implements JsonConverter { @JsonSerializable() @_BadConverter() class JsonConverterWithBadTypeArg { - T value; + late T value; } class _BadConverter implements JsonConverter { const _BadConverter(); @override - S fromJson(int json) => null; + S fromJson(int json) => throw UnimplementedError(); @override int toJson(S object) => 0; @@ -125,7 +127,7 @@ class _BadConverter implements JsonConverter { @_durationConverter @_DurationMillisecondConverter() class JsonConverterDuplicateAnnotations { - Duration value; + late Duration value; } const _durationConverter = _DurationMillisecondConverter(); @@ -136,11 +138,10 @@ class _DurationMillisecondConverter implements JsonConverter { const _DurationMillisecondConverter.named(); @override - Duration fromJson(int json) => - json == null ? null : Duration(milliseconds: json); + Duration fromJson(int json) => throw UnimplementedError(); @override - int toJson(Duration object) => object?.inMilliseconds; + int toJson(Duration object) => throw UnimplementedError(); } @ShouldThrow( @@ -150,7 +151,7 @@ class _DurationMillisecondConverter implements JsonConverter { @JsonSerializable() @_ConverterWithCtorParams(42) class JsonConverterCtorParams { - Duration value; + late Duration value; } class _ConverterWithCtorParams implements JsonConverter { @@ -159,7 +160,7 @@ class _ConverterWithCtorParams implements JsonConverter { const _ConverterWithCtorParams(this.param); @override - Duration fromJson(int json) => null; + Duration fromJson(int json) => throw UnimplementedError(); @override int toJson(Duration object) => 0; diff --git a/json_serializable/test/src/map_key_variety_test_input.dart b/json_serializable/test/src/map_key_variety_test_input.dart index 41abe7029..4f022d58a 100644 --- a/json_serializable/test/src/map_key_variety_test_input.dart +++ b/json_serializable/test/src/map_key_variety_test_input.dart @@ -1,19 +1,49 @@ +// @dart=2.12 + part of '_json_serializable_test_input.dart'; @ShouldGenerate(r''' MapKeyVariety _$MapKeyVarietyFromJson(Map json) { return MapKeyVariety() - ..intIntMap = (json['intIntMap'] as Map)?.map( + ..intIntMap = (json['intIntMap'] as Map).map( (k, e) => MapEntry(int.parse(k), e as int), ); } Map _$MapKeyVarietyToJson(MapKeyVariety instance) => { - 'intIntMap': instance.intIntMap?.map((k, e) => MapEntry(k.toString(), e)), + 'intIntMap': instance.intIntMap.map((k, e) => MapEntry(k.toString(), e)), }; ''') @JsonSerializable() class MapKeyVariety { - Map intIntMap; + late Map intIntMap; +} + +@ShouldThrow( + r''' +Could not generate `fromJson` code for `value` because of type `Object?`. +Map keys must be one of: Object, dynamic, enum, String, BigInt, DateTime, int, Uri.''', +) +@JsonSerializable() +class MapKeyNoNullableObject { + late Map value; +} + +@ShouldThrow( + r''' +Could not generate `fromJson` code for `value` because of type `String?`. +Map keys must be one of: Object, dynamic, enum, String, BigInt, DateTime, int, Uri.''', +) +@JsonSerializable() +class MapKeyNoNullableString { + late Map value; +} + +@ShouldThrow(r''' +Could not generate `fromJson` code for `value` because of type `int?`. +Map keys must be one of: Object, dynamic, enum, String, BigInt, DateTime, int, Uri.''') +@JsonSerializable() +class MapKeyNoNullableInt { + late Map value; } diff --git a/json_serializable/test/src/setter_test_input.dart b/json_serializable/test/src/setter_test_input.dart index b951dfeb5..9fe2d890e 100644 --- a/json_serializable/test/src/setter_test_input.dart +++ b/json_serializable/test/src/setter_test_input.dart @@ -1,3 +1,5 @@ +// @dart=2.12 + part of '_json_serializable_test_input.dart'; @ShouldGenerate( diff --git a/json_serializable/test/src/to_from_json_test_input.dart b/json_serializable/test/src/to_from_json_test_input.dart index c98d317bd..497445b8b 100644 --- a/json_serializable/test/src/to_from_json_test_input.dart +++ b/json_serializable/test/src/to_from_json_test_input.dart @@ -2,6 +2,8 @@ // 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. +// @dart=2.12 + part of '_json_serializable_test_input.dart'; int _toInt(bool input) => 42; @@ -10,9 +12,9 @@ int _twoArgFunction(int a, int b) => 42; dynamic _toDynamic(dynamic input) => null; -Object _toObject(Object input) => null; +Object _toObject(Object input) => throw UnimplementedError(); -String _toStringFromObject(Object input) => null; +String _toStringFromObject(Object? input) => throw UnimplementedError(); @ShouldThrow( 'Error with `@JsonKey` on `field`. The `fromJson` function `_toInt` ' @@ -22,7 +24,7 @@ String _toStringFromObject(Object input) => null; @JsonSerializable() class BadFromFuncReturnType { @JsonKey(fromJson: _toInt) - String field; + late String field; } @ShouldThrow( @@ -33,7 +35,7 @@ class BadFromFuncReturnType { @JsonSerializable() class InvalidFromFunc2Args { @JsonKey(fromJson: _twoArgFunction) - String field; + late String field; } @ShouldGenerate( @@ -54,10 +56,10 @@ Map _$ValidToFromFuncClassStaticToJson( ) @JsonSerializable() class ValidToFromFuncClassStatic { - static String _staticFunc(String param) => null; + static String _staticFunc(String param) => throw UnimplementedError(); @JsonKey(fromJson: _staticFunc, toJson: _staticFunc) - String field; + late String field; } @ShouldThrow( @@ -68,7 +70,7 @@ class ValidToFromFuncClassStatic { @JsonSerializable() class BadToFuncReturnType { @JsonKey(toJson: _toInt) - String field; + late String field; } @ShouldThrow( @@ -79,7 +81,7 @@ class BadToFuncReturnType { @JsonSerializable() class InvalidToFunc2Args { @JsonKey(toJson: _twoArgFunction) - String field; + late String field; } @ShouldGenerate( @@ -89,7 +91,7 @@ class InvalidToFunc2Args { @JsonSerializable() class ObjectConvertMethods { @JsonKey(fromJson: _toStringFromObject, toJson: _toObject) - String field; + late String field; } @ShouldGenerate( @@ -100,10 +102,10 @@ class ObjectConvertMethods { @JsonSerializable() class DynamicConvertMethods { @JsonKey(fromJson: _toDynamic, toJson: _toDynamic) - String field; + late String field; } -String _toString(String input) => null; +String _toString(String input) => 'null'; @ShouldGenerate( "_toString(json['field'] as String)", @@ -113,7 +115,7 @@ String _toString(String input) => null; @JsonSerializable() class TypedConvertMethods { @JsonKey(fromJson: _toString, toJson: _toString) - String field; + late String field; } @ShouldGenerate( @@ -132,24 +134,19 @@ Map _$ToJsonNullableFalseIncludeIfNullFalseToJson( return val; } ''', - expectedLogItems: [ - 'The `JsonKey.nullable` value on ' - '`ToJsonNullableFalseIncludeIfNullFalse.field` will be ignored because ' - 'a custom conversion function is being used.', - ], configurations: ['default'], ) @JsonSerializable(createFactory: false) class ToJsonNullableFalseIncludeIfNullFalse { - @JsonKey(toJson: _toString, includeIfNull: false, nullable: false) - String field; + @JsonKey(toJson: _toString, includeIfNull: false) + late String field; } -String _fromDynamicMap(Map input) => null; +String _fromDynamicMap(Map input) => ''; -String _fromDynamicList(List input) => null; +String _fromDynamicList(List input) => 'null'; -String _fromDynamicIterable(Iterable input) => null; +String _fromDynamicIterable(Iterable input) => 'null'; @ShouldGenerate( r''' @@ -166,14 +163,14 @@ FromDynamicCollection _$FromDynamicCollectionFromJson( @JsonSerializable(createToJson: false) class FromDynamicCollection { @JsonKey(fromJson: _fromDynamicMap) - String mapField; + late String mapField; @JsonKey(fromJson: _fromDynamicList) - String listField; + late String listField; @JsonKey(fromJson: _fromDynamicIterable) - String iterableField; + late String iterableField; } -String _noArgs() => null; +String _noArgs() => throw UnimplementedError(); @ShouldThrow( 'Error with `@JsonKey` on `field`. The `fromJson` function ' @@ -183,10 +180,10 @@ String _noArgs() => null; @JsonSerializable(createToJson: false) class BadNoArgs { @JsonKey(fromJson: _noArgs) - String field; + String? field; } -String _twoArgs(a, b) => null; +String? _twoArgs(a, b) => null; @ShouldThrow( 'Error with `@JsonKey` on `field`. The `fromJson` function ' @@ -196,10 +193,10 @@ String _twoArgs(a, b) => null; @JsonSerializable(createToJson: false) class BadTwoRequiredPositional { @JsonKey(fromJson: _twoArgs) - String field; + String? field; } -String _oneNamed({a}) => null; +String? _oneNamed({a}) => null; @ShouldThrow( 'Error with `@JsonKey` on `field`. The `fromJson` function ' @@ -209,32 +206,32 @@ String _oneNamed({a}) => null; @JsonSerializable(createToJson: false) class BadOneNamed { @JsonKey(fromJson: _oneNamed) - String field; + String? field; } -String _oneNormalOnePositional(a, [b]) => null; +String _oneNormalOnePositional(a, [b]) => throw UnimplementedError(); @ShouldGenerate("_oneNormalOnePositional(json['field'])", contains: true) @JsonSerializable(createToJson: false) class OkayOneNormalOptionalPositional { @JsonKey(fromJson: _oneNormalOnePositional) - String field; + String? field; } -String _oneNormalOptionalNamed(a, {b}) => null; +String _oneNormalOptionalNamed(a, {b}) => throw UnimplementedError(); @ShouldGenerate("_oneNormalOptionalNamed(json['field'])", contains: true) @JsonSerializable(createToJson: false) class OkayOneNormalOptionalNamed { @JsonKey(fromJson: _oneNormalOptionalNamed) - String field; + String? field; } -String _onlyOptionalPositional([a, b]) => null; +String _onlyOptionalPositional([a, b]) => throw UnimplementedError(); @ShouldGenerate("_onlyOptionalPositional(json['field'])", contains: true) @JsonSerializable(createToJson: false) class OkayOnlyOptionalPositional { @JsonKey(fromJson: _onlyOptionalPositional) - String field; + String? field; } diff --git a/json_serializable/test/src/unknown_enum_value_test_input.dart b/json_serializable/test/src/unknown_enum_value_test_input.dart index d156fa999..0f6907087 100644 --- a/json_serializable/test/src/unknown_enum_value_test_input.dart +++ b/json_serializable/test/src/unknown_enum_value_test_input.dart @@ -1,3 +1,5 @@ +// @dart=2.12 + part of '_json_serializable_test_input.dart'; @ShouldGenerate( @@ -10,36 +12,41 @@ UnknownEnumValue _$UnknownEnumValueFromJson(Map json) { UnknownEnumValueItems.vNull; } -T _$enumDecode( - Map enumValues, - dynamic source, { - T unknownValue, +K _$enumDecode( + Map enumValues, + Object? source, { + K? unknownValue, }) { if (source == null) { - throw ArgumentError('A value must be provided. Supported values: ' - '${enumValues.values.join(', ')}'); + throw ArgumentError( + 'A value must be provided. Supported values: ' + '${enumValues.values.join(', ')}', + ); } - final value = enumValues.entries - .singleWhere((e) => e.value == source, orElse: () => null) - ?.key; - - if (value == null && unknownValue == null) { - throw ArgumentError('`$source` is not one of the supported values: ' - '${enumValues.values.join(', ')}'); - } - return value ?? unknownValue; + return enumValues.entries.singleWhere( + (e) => e.value == source, + orElse: () { + if (unknownValue == null) { + throw ArgumentError( + '`$source` is not one of the supported values: ' + '${enumValues.values.join(', ')}', + ); + } + return MapEntry(unknownValue, enumValues.values.first); + }, + ).key; } -T _$enumDecodeNullable( - Map enumValues, +K? _$enumDecodeNullable( + Map enumValues, dynamic source, { - T unknownValue, + K? unknownValue, }) { if (source == null) { return null; } - return _$enumDecode(enumValues, source, unknownValue: unknownValue); + return _$enumDecode(enumValues, source, unknownValue: unknownValue); } const _$UnknownEnumValueItemsEnumMap = { @@ -59,7 +66,7 @@ class UnknownEnumValue { defaultValue: UnknownEnumValueItems.vNull, unknownEnumValue: UnknownEnumValueItems.vUnknown, ) - UnknownEnumValueItems value; + UnknownEnumValueItems? value; } enum UnknownEnumValueItems { v0, v1, v2, vUnknown, vNull } @@ -72,7 +79,7 @@ enum UnknownEnumValueItems { v0, v1, v2, vUnknown, vNull } @JsonSerializable() class UnknownEnumValueListWrongType { @JsonKey(unknownEnumValue: WrongEnumType.otherValue) - List value; + late List value; } @ShouldThrow( @@ -83,7 +90,7 @@ class UnknownEnumValueListWrongType { @JsonSerializable() class UnknownEnumValueListWrongEnumType { @JsonKey(unknownEnumValue: WrongEnumType.otherValue) - List value; + late List value; } enum WrongEnumType { otherValue } @@ -96,7 +103,7 @@ enum WrongEnumType { otherValue } @JsonSerializable() class UnknownEnumValueWrongEnumType { @JsonKey(unknownEnumValue: WrongEnumType.otherValue) - UnknownEnumValueItems value; + late UnknownEnumValueItems value; } @ShouldThrow( @@ -106,7 +113,7 @@ class UnknownEnumValueWrongEnumType { @JsonSerializable() class UnknownEnumValueNotEnumValue { @JsonKey(unknownEnumValue: 'not enum value') - UnknownEnumValueItems value; + UnknownEnumValueItems? value; } @ShouldThrow( @@ -116,5 +123,5 @@ class UnknownEnumValueNotEnumValue { @JsonSerializable() class UnknownEnumValueNotEnumField { @JsonKey(unknownEnumValue: UnknownEnumValueItems.vUnknown) - int value; + int? value; } diff --git a/json_serializable/test/supported_types/enum_type.dart b/json_serializable/test/supported_types/enum_type.dart index 360a6bf8e..a0f9c2191 100644 --- a/json_serializable/test/supported_types/enum_type.dart +++ b/json_serializable/test/supported_types/enum_type.dart @@ -2,4 +2,6 @@ // 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. +// @dart=2.12 + enum EnumType { alpha, beta, gamma, delta } diff --git a/json_serializable/test/supported_types/input.dart b/json_serializable/test/supported_types/input.dart index 61f84b8b5..2319b01c0 100644 --- a/json_serializable/test/supported_types/input.dart +++ b/json_serializable/test/supported_types/input.dart @@ -2,6 +2,8 @@ // 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. +// @dart=2.12 + import 'package:json_annotation/json_annotation.dart'; part 'input.g.dart'; @@ -10,19 +12,16 @@ part 'input.g.dart'; class SimpleClass { final dynamic value; - @JsonKey(nullable: false) - final dynamic nullable; - @JsonKey(defaultValue: 42) dynamic withDefault; SimpleClass( this.value, - this.nullable, + this.withDefault, ); - factory SimpleClass.fromJson(Map json) => + factory SimpleClass.fromJson(Map json) => _$SimpleClassFromJson(json); - Map toJson() => _$SimpleClassToJson(this); + Map toJson() => _$SimpleClassToJson(this); } diff --git a/json_serializable/test/supported_types/input.g.dart b/json_serializable/test/supported_types/input.g.dart index 6200f9880..65367bf60 100644 --- a/json_serializable/test/supported_types/input.g.dart +++ b/json_serializable/test/supported_types/input.g.dart @@ -1,4 +1,5 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// @dart=2.12 part of 'input.dart'; @@ -9,13 +10,12 @@ part of 'input.dart'; SimpleClass _$SimpleClassFromJson(Map json) { return SimpleClass( json['value'], - json['nullable'], - )..withDefault = json['withDefault'] ?? 42; + json['withDefault'] ?? 42, + ); } Map _$SimpleClassToJson(SimpleClass instance) => { 'value': instance.value, - 'nullable': instance.nullable, 'withDefault': instance.withDefault, }; diff --git a/json_serializable/test/supported_types/input.type_bigint.dart b/json_serializable/test/supported_types/input.type_bigint.dart index af17f1a45..25005752e 100644 --- a/json_serializable/test/supported_types/input.type_bigint.dart +++ b/json_serializable/test/supported_types/input.type_bigint.dart @@ -2,6 +2,8 @@ // 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. +// @dart=2.12 + import 'package:json_annotation/json_annotation.dart'; part 'input.type_bigint.g.dart'; @@ -10,16 +12,26 @@ part 'input.type_bigint.g.dart'; class SimpleClass { final BigInt value; - @JsonKey(nullable: false) - final BigInt nullable; - SimpleClass( this.value, - this.nullable, ); - factory SimpleClass.fromJson(Map json) => + factory SimpleClass.fromJson(Map json) => _$SimpleClassFromJson(json); - Map toJson() => _$SimpleClassToJson(this); + Map toJson() => _$SimpleClassToJson(this); +} + +@JsonSerializable() +class SimpleClassNullable { + final BigInt? value; + + SimpleClassNullable( + this.value, + ); + + factory SimpleClassNullable.fromJson(Map json) => + _$SimpleClassNullableFromJson(json); + + Map toJson() => _$SimpleClassNullableToJson(this); } diff --git a/json_serializable/test/supported_types/input.type_bigint.g.dart b/json_serializable/test/supported_types/input.type_bigint.g.dart index f558a9326..c03d1ed5f 100644 --- a/json_serializable/test/supported_types/input.type_bigint.g.dart +++ b/json_serializable/test/supported_types/input.type_bigint.g.dart @@ -1,4 +1,5 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// @dart=2.12 part of 'input.type_bigint.dart'; @@ -8,13 +9,23 @@ part of 'input.type_bigint.dart'; SimpleClass _$SimpleClassFromJson(Map json) { return SimpleClass( - json['value'] == null ? null : BigInt.parse(json['value'] as String), - BigInt.parse(json['nullable'] as String), + BigInt.parse(json['value'] as String), ); } Map _$SimpleClassToJson(SimpleClass instance) => + { + 'value': instance.value.toString(), + }; + +SimpleClassNullable _$SimpleClassNullableFromJson(Map json) { + return SimpleClassNullable( + json['value'] == null ? null : BigInt.parse(json['value'] as String), + ); +} + +Map _$SimpleClassNullableToJson( + SimpleClassNullable instance) => { 'value': instance.value?.toString(), - 'nullable': instance.nullable.toString(), }; diff --git a/json_serializable/test/supported_types/input.type_bool.dart b/json_serializable/test/supported_types/input.type_bool.dart index 6d2b100be..9d898ba07 100644 --- a/json_serializable/test/supported_types/input.type_bool.dart +++ b/json_serializable/test/supported_types/input.type_bool.dart @@ -2,6 +2,8 @@ // 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. +// @dart=2.12 + import 'package:json_annotation/json_annotation.dart'; part 'input.type_bool.g.dart'; @@ -10,19 +12,34 @@ part 'input.type_bool.g.dart'; class SimpleClass { final bool value; - @JsonKey(nullable: false) - final bool nullable; - @JsonKey(defaultValue: true) bool withDefault; SimpleClass( this.value, - this.nullable, + this.withDefault, ); - factory SimpleClass.fromJson(Map json) => + factory SimpleClass.fromJson(Map json) => _$SimpleClassFromJson(json); - Map toJson() => _$SimpleClassToJson(this); + Map toJson() => _$SimpleClassToJson(this); +} + +@JsonSerializable() +class SimpleClassNullable { + final bool? value; + + @JsonKey(defaultValue: true) + bool? withDefault; + + SimpleClassNullable( + this.value, + this.withDefault, + ); + + factory SimpleClassNullable.fromJson(Map json) => + _$SimpleClassNullableFromJson(json); + + Map toJson() => _$SimpleClassNullableToJson(this); } diff --git a/json_serializable/test/supported_types/input.type_bool.g.dart b/json_serializable/test/supported_types/input.type_bool.g.dart index 6b0bb40d7..04a942e20 100644 --- a/json_serializable/test/supported_types/input.type_bool.g.dart +++ b/json_serializable/test/supported_types/input.type_bool.g.dart @@ -1,4 +1,5 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// @dart=2.12 part of 'input.type_bool.dart'; @@ -9,13 +10,26 @@ part of 'input.type_bool.dart'; SimpleClass _$SimpleClassFromJson(Map json) { return SimpleClass( json['value'] as bool, - json['nullable'] as bool, - )..withDefault = json['withDefault'] as bool ?? true; + json['withDefault'] as bool? ?? true, + ); } Map _$SimpleClassToJson(SimpleClass instance) => { 'value': instance.value, - 'nullable': instance.nullable, + 'withDefault': instance.withDefault, + }; + +SimpleClassNullable _$SimpleClassNullableFromJson(Map json) { + return SimpleClassNullable( + json['value'] as bool?, + json['withDefault'] as bool? ?? true, + ); +} + +Map _$SimpleClassNullableToJson( + SimpleClassNullable instance) => + { + 'value': instance.value, 'withDefault': instance.withDefault, }; diff --git a/json_serializable/test/supported_types/input.type_datetime.dart b/json_serializable/test/supported_types/input.type_datetime.dart index aae8b83db..cc992713e 100644 --- a/json_serializable/test/supported_types/input.type_datetime.dart +++ b/json_serializable/test/supported_types/input.type_datetime.dart @@ -2,6 +2,8 @@ // 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. +// @dart=2.12 + import 'package:json_annotation/json_annotation.dart'; part 'input.type_datetime.g.dart'; @@ -10,16 +12,26 @@ part 'input.type_datetime.g.dart'; class SimpleClass { final DateTime value; - @JsonKey(nullable: false) - final DateTime nullable; - SimpleClass( this.value, - this.nullable, ); - factory SimpleClass.fromJson(Map json) => + factory SimpleClass.fromJson(Map json) => _$SimpleClassFromJson(json); - Map toJson() => _$SimpleClassToJson(this); + Map toJson() => _$SimpleClassToJson(this); +} + +@JsonSerializable() +class SimpleClassNullable { + final DateTime? value; + + SimpleClassNullable( + this.value, + ); + + factory SimpleClassNullable.fromJson(Map json) => + _$SimpleClassNullableFromJson(json); + + Map toJson() => _$SimpleClassNullableToJson(this); } diff --git a/json_serializable/test/supported_types/input.type_datetime.g.dart b/json_serializable/test/supported_types/input.type_datetime.g.dart index efb459777..b98a2c17d 100644 --- a/json_serializable/test/supported_types/input.type_datetime.g.dart +++ b/json_serializable/test/supported_types/input.type_datetime.g.dart @@ -1,4 +1,5 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// @dart=2.12 part of 'input.type_datetime.dart'; @@ -8,13 +9,23 @@ part of 'input.type_datetime.dart'; SimpleClass _$SimpleClassFromJson(Map json) { return SimpleClass( - json['value'] == null ? null : DateTime.parse(json['value'] as String), - DateTime.parse(json['nullable'] as String), + DateTime.parse(json['value'] as String), ); } Map _$SimpleClassToJson(SimpleClass instance) => + { + 'value': instance.value.toIso8601String(), + }; + +SimpleClassNullable _$SimpleClassNullableFromJson(Map json) { + return SimpleClassNullable( + json['value'] == null ? null : DateTime.parse(json['value'] as String), + ); +} + +Map _$SimpleClassNullableToJson( + SimpleClassNullable instance) => { 'value': instance.value?.toIso8601String(), - 'nullable': instance.nullable.toIso8601String(), }; diff --git a/json_serializable/test/supported_types/input.type_double.dart b/json_serializable/test/supported_types/input.type_double.dart index 14a42481f..e2074ddcd 100644 --- a/json_serializable/test/supported_types/input.type_double.dart +++ b/json_serializable/test/supported_types/input.type_double.dart @@ -2,6 +2,8 @@ // 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. +// @dart=2.12 + import 'package:json_annotation/json_annotation.dart'; part 'input.type_double.g.dart'; @@ -10,19 +12,34 @@ part 'input.type_double.g.dart'; class SimpleClass { final double value; - @JsonKey(nullable: false) - final double nullable; - @JsonKey(defaultValue: 3.14) double withDefault; SimpleClass( this.value, - this.nullable, + this.withDefault, ); - factory SimpleClass.fromJson(Map json) => + factory SimpleClass.fromJson(Map json) => _$SimpleClassFromJson(json); - Map toJson() => _$SimpleClassToJson(this); + Map toJson() => _$SimpleClassToJson(this); +} + +@JsonSerializable() +class SimpleClassNullable { + final double? value; + + @JsonKey(defaultValue: 3.14) + double? withDefault; + + SimpleClassNullable( + this.value, + this.withDefault, + ); + + factory SimpleClassNullable.fromJson(Map json) => + _$SimpleClassNullableFromJson(json); + + Map toJson() => _$SimpleClassNullableToJson(this); } diff --git a/json_serializable/test/supported_types/input.type_double.g.dart b/json_serializable/test/supported_types/input.type_double.g.dart index 36681b7d6..00d0e424b 100644 --- a/json_serializable/test/supported_types/input.type_double.g.dart +++ b/json_serializable/test/supported_types/input.type_double.g.dart @@ -1,4 +1,5 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// @dart=2.12 part of 'input.type_double.dart'; @@ -8,14 +9,27 @@ part of 'input.type_double.dart'; SimpleClass _$SimpleClassFromJson(Map json) { return SimpleClass( - (json['value'] as num)?.toDouble(), - (json['nullable'] as num).toDouble(), - )..withDefault = (json['withDefault'] as num)?.toDouble() ?? 3.14; + (json['value'] as num).toDouble(), + (json['withDefault'] as num?)?.toDouble() ?? 3.14, + ); } Map _$SimpleClassToJson(SimpleClass instance) => { 'value': instance.value, - 'nullable': instance.nullable, + 'withDefault': instance.withDefault, + }; + +SimpleClassNullable _$SimpleClassNullableFromJson(Map json) { + return SimpleClassNullable( + (json['value'] as num?)?.toDouble(), + (json['withDefault'] as num?)?.toDouble() ?? 3.14, + ); +} + +Map _$SimpleClassNullableToJson( + SimpleClassNullable instance) => + { + 'value': instance.value, 'withDefault': instance.withDefault, }; diff --git a/json_serializable/test/supported_types/input.type_duration.dart b/json_serializable/test/supported_types/input.type_duration.dart index a38f9cd68..aa4c716e4 100644 --- a/json_serializable/test/supported_types/input.type_duration.dart +++ b/json_serializable/test/supported_types/input.type_duration.dart @@ -2,6 +2,8 @@ // 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. +// @dart=2.12 + import 'package:json_annotation/json_annotation.dart'; part 'input.type_duration.g.dart'; @@ -10,16 +12,26 @@ part 'input.type_duration.g.dart'; class SimpleClass { final Duration value; - @JsonKey(nullable: false) - final Duration nullable; - SimpleClass( this.value, - this.nullable, ); - factory SimpleClass.fromJson(Map json) => + factory SimpleClass.fromJson(Map json) => _$SimpleClassFromJson(json); - Map toJson() => _$SimpleClassToJson(this); + Map toJson() => _$SimpleClassToJson(this); +} + +@JsonSerializable() +class SimpleClassNullable { + final Duration? value; + + SimpleClassNullable( + this.value, + ); + + factory SimpleClassNullable.fromJson(Map json) => + _$SimpleClassNullableFromJson(json); + + Map toJson() => _$SimpleClassNullableToJson(this); } diff --git a/json_serializable/test/supported_types/input.type_duration.g.dart b/json_serializable/test/supported_types/input.type_duration.g.dart index f7a0bc777..5d7f2f45f 100644 --- a/json_serializable/test/supported_types/input.type_duration.g.dart +++ b/json_serializable/test/supported_types/input.type_duration.g.dart @@ -1,4 +1,5 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// @dart=2.12 part of 'input.type_duration.dart'; @@ -8,13 +9,23 @@ part of 'input.type_duration.dart'; SimpleClass _$SimpleClassFromJson(Map json) { return SimpleClass( - json['value'] == null ? null : Duration(microseconds: json['value'] as int), - Duration(microseconds: json['nullable'] as int), + Duration(microseconds: json['value'] as int), ); } Map _$SimpleClassToJson(SimpleClass instance) => + { + 'value': instance.value.inMicroseconds, + }; + +SimpleClassNullable _$SimpleClassNullableFromJson(Map json) { + return SimpleClassNullable( + json['value'] == null ? null : Duration(microseconds: json['value'] as int), + ); +} + +Map _$SimpleClassNullableToJson( + SimpleClassNullable instance) => { 'value': instance.value?.inMicroseconds, - 'nullable': instance.nullable.inMicroseconds, }; diff --git a/json_serializable/test/supported_types/input.type_enumtype.dart b/json_serializable/test/supported_types/input.type_enumtype.dart index 8c54e81d4..14c28a906 100644 --- a/json_serializable/test/supported_types/input.type_enumtype.dart +++ b/json_serializable/test/supported_types/input.type_enumtype.dart @@ -2,6 +2,8 @@ // 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. +// @dart=2.12 + import 'package:json_annotation/json_annotation.dart'; import 'enum_type.dart'; @@ -11,19 +13,34 @@ part 'input.type_enumtype.g.dart'; class SimpleClass { final EnumType value; - @JsonKey(nullable: false) - final EnumType nullable; - @JsonKey(defaultValue: EnumType.alpha) EnumType withDefault; SimpleClass( this.value, - this.nullable, + this.withDefault, ); - factory SimpleClass.fromJson(Map json) => + factory SimpleClass.fromJson(Map json) => _$SimpleClassFromJson(json); - Map toJson() => _$SimpleClassToJson(this); + Map toJson() => _$SimpleClassToJson(this); +} + +@JsonSerializable() +class SimpleClassNullable { + final EnumType? value; + + @JsonKey(defaultValue: EnumType.alpha) + EnumType? withDefault; + + SimpleClassNullable( + this.value, + this.withDefault, + ); + + factory SimpleClassNullable.fromJson(Map json) => + _$SimpleClassNullableFromJson(json); + + Map toJson() => _$SimpleClassNullableToJson(this); } diff --git a/json_serializable/test/supported_types/input.type_enumtype.g.dart b/json_serializable/test/supported_types/input.type_enumtype.g.dart index d79199ce6..547664f35 100644 --- a/json_serializable/test/supported_types/input.type_enumtype.g.dart +++ b/json_serializable/test/supported_types/input.type_enumtype.g.dart @@ -1,4 +1,5 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// @dart=2.12 part of 'input.type_enumtype.dart'; @@ -8,55 +9,73 @@ part of 'input.type_enumtype.dart'; SimpleClass _$SimpleClassFromJson(Map json) { return SimpleClass( - _$enumDecodeNullable(_$EnumTypeEnumMap, json['value']), - _$enumDecode(_$EnumTypeEnumMap, json['nullable']), - )..withDefault = - _$enumDecodeNullable(_$EnumTypeEnumMap, json['withDefault']) ?? - EnumType.alpha; + _$enumDecode(_$EnumTypeEnumMap, json['value']), + _$enumDecodeNullable(_$EnumTypeEnumMap, json['withDefault']) ?? + EnumType.alpha, + ); } Map _$SimpleClassToJson(SimpleClass instance) => { 'value': _$EnumTypeEnumMap[instance.value], - 'nullable': _$EnumTypeEnumMap[instance.nullable], 'withDefault': _$EnumTypeEnumMap[instance.withDefault], }; -T _$enumDecode( - Map enumValues, - dynamic source, { - T unknownValue, +K _$enumDecode( + Map enumValues, + Object? source, { + K? unknownValue, }) { if (source == null) { - throw ArgumentError('A value must be provided. Supported values: ' - '${enumValues.values.join(', ')}'); + throw ArgumentError( + 'A value must be provided. Supported values: ' + '${enumValues.values.join(', ')}', + ); } - final value = enumValues.entries - .singleWhere((e) => e.value == source, orElse: () => null) - ?.key; - - if (value == null && unknownValue == null) { - throw ArgumentError('`$source` is not one of the supported values: ' - '${enumValues.values.join(', ')}'); - } - return value ?? unknownValue; + return enumValues.entries.singleWhere( + (e) => e.value == source, + orElse: () { + if (unknownValue == null) { + throw ArgumentError( + '`$source` is not one of the supported values: ' + '${enumValues.values.join(', ')}', + ); + } + return MapEntry(unknownValue, enumValues.values.first); + }, + ).key; } -T _$enumDecodeNullable( - Map enumValues, +const _$EnumTypeEnumMap = { + EnumType.alpha: 'alpha', + EnumType.beta: 'beta', + EnumType.gamma: 'gamma', + EnumType.delta: 'delta', +}; + +K? _$enumDecodeNullable( + Map enumValues, dynamic source, { - T unknownValue, + K? unknownValue, }) { if (source == null) { return null; } - return _$enumDecode(enumValues, source, unknownValue: unknownValue); + return _$enumDecode(enumValues, source, unknownValue: unknownValue); } -const _$EnumTypeEnumMap = { - EnumType.alpha: 'alpha', - EnumType.beta: 'beta', - EnumType.gamma: 'gamma', - EnumType.delta: 'delta', -}; +SimpleClassNullable _$SimpleClassNullableFromJson(Map json) { + return SimpleClassNullable( + _$enumDecodeNullable(_$EnumTypeEnumMap, json['value']), + _$enumDecodeNullable(_$EnumTypeEnumMap, json['withDefault']) ?? + EnumType.alpha, + ); +} + +Map _$SimpleClassNullableToJson( + SimpleClassNullable instance) => + { + 'value': _$EnumTypeEnumMap[instance.value], + 'withDefault': _$EnumTypeEnumMap[instance.withDefault], + }; diff --git a/json_serializable/test/supported_types/input.type_int.dart b/json_serializable/test/supported_types/input.type_int.dart index 42eb0e342..0a2614f22 100644 --- a/json_serializable/test/supported_types/input.type_int.dart +++ b/json_serializable/test/supported_types/input.type_int.dart @@ -2,6 +2,8 @@ // 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. +// @dart=2.12 + import 'package:json_annotation/json_annotation.dart'; part 'input.type_int.g.dart'; @@ -10,19 +12,34 @@ part 'input.type_int.g.dart'; class SimpleClass { final int value; - @JsonKey(nullable: false) - final int nullable; - @JsonKey(defaultValue: 42) int withDefault; SimpleClass( this.value, - this.nullable, + this.withDefault, ); - factory SimpleClass.fromJson(Map json) => + factory SimpleClass.fromJson(Map json) => _$SimpleClassFromJson(json); - Map toJson() => _$SimpleClassToJson(this); + Map toJson() => _$SimpleClassToJson(this); +} + +@JsonSerializable() +class SimpleClassNullable { + final int? value; + + @JsonKey(defaultValue: 42) + int? withDefault; + + SimpleClassNullable( + this.value, + this.withDefault, + ); + + factory SimpleClassNullable.fromJson(Map json) => + _$SimpleClassNullableFromJson(json); + + Map toJson() => _$SimpleClassNullableToJson(this); } diff --git a/json_serializable/test/supported_types/input.type_int.g.dart b/json_serializable/test/supported_types/input.type_int.g.dart index 99f4b297a..48295e2b7 100644 --- a/json_serializable/test/supported_types/input.type_int.g.dart +++ b/json_serializable/test/supported_types/input.type_int.g.dart @@ -1,4 +1,5 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// @dart=2.12 part of 'input.type_int.dart'; @@ -9,13 +10,26 @@ part of 'input.type_int.dart'; SimpleClass _$SimpleClassFromJson(Map json) { return SimpleClass( json['value'] as int, - json['nullable'] as int, - )..withDefault = json['withDefault'] as int ?? 42; + json['withDefault'] as int? ?? 42, + ); } Map _$SimpleClassToJson(SimpleClass instance) => { 'value': instance.value, - 'nullable': instance.nullable, + 'withDefault': instance.withDefault, + }; + +SimpleClassNullable _$SimpleClassNullableFromJson(Map json) { + return SimpleClassNullable( + json['value'] as int?, + json['withDefault'] as int? ?? 42, + ); +} + +Map _$SimpleClassNullableToJson( + SimpleClassNullable instance) => + { + 'value': instance.value, 'withDefault': instance.withDefault, }; diff --git a/json_serializable/test/supported_types/input.type_iterable.dart b/json_serializable/test/supported_types/input.type_iterable.dart index 0ba7d5f3c..a90c4d99c 100644 --- a/json_serializable/test/supported_types/input.type_iterable.dart +++ b/json_serializable/test/supported_types/input.type_iterable.dart @@ -2,6 +2,8 @@ // 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. +// @dart=2.12 + import 'package:json_annotation/json_annotation.dart'; import 'enum_type.dart'; @@ -11,235 +13,700 @@ part 'input.type_iterable.g.dart'; class SimpleClass { final Iterable value; - @JsonKey(nullable: false) - final Iterable nullable; - @JsonKey(defaultValue: [42, true, false, null]) Iterable withDefault; SimpleClass( this.value, - this.nullable, + this.withDefault, ); - factory SimpleClass.fromJson(Map json) => + factory SimpleClass.fromJson(Map json) => _$SimpleClassFromJson(json); - Map toJson() => _$SimpleClassToJson(this); + Map toJson() => _$SimpleClassToJson(this); } @JsonSerializable() -class SimpleClassBigInt { +class SimpleClassNullable { + final Iterable? value; + + @JsonKey(defaultValue: [42, true, false, null]) + Iterable? withDefault; + + SimpleClassNullable( + this.value, + this.withDefault, + ); + + factory SimpleClassNullable.fromJson(Map json) => + _$SimpleClassNullableFromJson(json); + + Map toJson() => _$SimpleClassNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfBigInt { final Iterable value; - @JsonKey(nullable: false) - final Iterable nullable; + SimpleClassOfBigInt( + this.value, + ); + + factory SimpleClassOfBigInt.fromJson(Map json) => + _$SimpleClassOfBigIntFromJson(json); + + Map toJson() => _$SimpleClassOfBigIntToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfBigInt { + final Iterable? value; + + SimpleClassNullableOfBigInt( + this.value, + ); + + factory SimpleClassNullableOfBigInt.fromJson(Map json) => + _$SimpleClassNullableOfBigIntFromJson(json); + + Map toJson() => _$SimpleClassNullableOfBigIntToJson(this); +} + +@JsonSerializable() +class SimpleClassOfBigIntNullable { + final Iterable value; + + SimpleClassOfBigIntNullable( + this.value, + ); + + factory SimpleClassOfBigIntNullable.fromJson(Map json) => + _$SimpleClassOfBigIntNullableFromJson(json); + + Map toJson() => _$SimpleClassOfBigIntNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfBigIntNullable { + final Iterable? value; - SimpleClassBigInt( + SimpleClassNullableOfBigIntNullable( this.value, - this.nullable, ); - factory SimpleClassBigInt.fromJson(Map json) => - _$SimpleClassBigIntFromJson(json); + factory SimpleClassNullableOfBigIntNullable.fromJson( + Map json) => + _$SimpleClassNullableOfBigIntNullableFromJson(json); - Map toJson() => _$SimpleClassBigIntToJson(this); + Map toJson() => + _$SimpleClassNullableOfBigIntNullableToJson(this); } @JsonSerializable() -class SimpleClassBool { +class SimpleClassOfBool { final Iterable value; - @JsonKey(nullable: false) - final Iterable nullable; + SimpleClassOfBool( + this.value, + ); + + factory SimpleClassOfBool.fromJson(Map json) => + _$SimpleClassOfBoolFromJson(json); + + Map toJson() => _$SimpleClassOfBoolToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfBool { + final Iterable? value; + + SimpleClassNullableOfBool( + this.value, + ); + + factory SimpleClassNullableOfBool.fromJson(Map json) => + _$SimpleClassNullableOfBoolFromJson(json); + + Map toJson() => _$SimpleClassNullableOfBoolToJson(this); +} + +@JsonSerializable() +class SimpleClassOfBoolNullable { + final Iterable value; + + SimpleClassOfBoolNullable( + this.value, + ); + + factory SimpleClassOfBoolNullable.fromJson(Map json) => + _$SimpleClassOfBoolNullableFromJson(json); + + Map toJson() => _$SimpleClassOfBoolNullableToJson(this); +} - SimpleClassBool( +@JsonSerializable() +class SimpleClassNullableOfBoolNullable { + final Iterable? value; + + SimpleClassNullableOfBoolNullable( this.value, - this.nullable, ); - factory SimpleClassBool.fromJson(Map json) => - _$SimpleClassBoolFromJson(json); + factory SimpleClassNullableOfBoolNullable.fromJson( + Map json) => + _$SimpleClassNullableOfBoolNullableFromJson(json); - Map toJson() => _$SimpleClassBoolToJson(this); + Map toJson() => + _$SimpleClassNullableOfBoolNullableToJson(this); } @JsonSerializable() -class SimpleClassDateTime { +class SimpleClassOfDateTime { final Iterable value; - @JsonKey(nullable: false) - final Iterable nullable; + SimpleClassOfDateTime( + this.value, + ); + + factory SimpleClassOfDateTime.fromJson(Map json) => + _$SimpleClassOfDateTimeFromJson(json); + + Map toJson() => _$SimpleClassOfDateTimeToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfDateTime { + final Iterable? value; + + SimpleClassNullableOfDateTime( + this.value, + ); + + factory SimpleClassNullableOfDateTime.fromJson(Map json) => + _$SimpleClassNullableOfDateTimeFromJson(json); + + Map toJson() => _$SimpleClassNullableOfDateTimeToJson(this); +} + +@JsonSerializable() +class SimpleClassOfDateTimeNullable { + final Iterable value; - SimpleClassDateTime( + SimpleClassOfDateTimeNullable( this.value, - this.nullable, ); - factory SimpleClassDateTime.fromJson(Map json) => - _$SimpleClassDateTimeFromJson(json); + factory SimpleClassOfDateTimeNullable.fromJson(Map json) => + _$SimpleClassOfDateTimeNullableFromJson(json); - Map toJson() => _$SimpleClassDateTimeToJson(this); + Map toJson() => _$SimpleClassOfDateTimeNullableToJson(this); } @JsonSerializable() -class SimpleClassDouble { +class SimpleClassNullableOfDateTimeNullable { + final Iterable? value; + + SimpleClassNullableOfDateTimeNullable( + this.value, + ); + + factory SimpleClassNullableOfDateTimeNullable.fromJson( + Map json) => + _$SimpleClassNullableOfDateTimeNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfDateTimeNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfDouble { final Iterable value; - @JsonKey(nullable: false) - final Iterable nullable; + SimpleClassOfDouble( + this.value, + ); + + factory SimpleClassOfDouble.fromJson(Map json) => + _$SimpleClassOfDoubleFromJson(json); + + Map toJson() => _$SimpleClassOfDoubleToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfDouble { + final Iterable? value; + + SimpleClassNullableOfDouble( + this.value, + ); + + factory SimpleClassNullableOfDouble.fromJson(Map json) => + _$SimpleClassNullableOfDoubleFromJson(json); + + Map toJson() => _$SimpleClassNullableOfDoubleToJson(this); +} + +@JsonSerializable() +class SimpleClassOfDoubleNullable { + final Iterable value; + + SimpleClassOfDoubleNullable( + this.value, + ); + + factory SimpleClassOfDoubleNullable.fromJson(Map json) => + _$SimpleClassOfDoubleNullableFromJson(json); + + Map toJson() => _$SimpleClassOfDoubleNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfDoubleNullable { + final Iterable? value; - SimpleClassDouble( + SimpleClassNullableOfDoubleNullable( this.value, - this.nullable, ); - factory SimpleClassDouble.fromJson(Map json) => - _$SimpleClassDoubleFromJson(json); + factory SimpleClassNullableOfDoubleNullable.fromJson( + Map json) => + _$SimpleClassNullableOfDoubleNullableFromJson(json); - Map toJson() => _$SimpleClassDoubleToJson(this); + Map toJson() => + _$SimpleClassNullableOfDoubleNullableToJson(this); } @JsonSerializable() -class SimpleClassDuration { +class SimpleClassOfDuration { final Iterable value; - @JsonKey(nullable: false) - final Iterable nullable; + SimpleClassOfDuration( + this.value, + ); + + factory SimpleClassOfDuration.fromJson(Map json) => + _$SimpleClassOfDurationFromJson(json); + + Map toJson() => _$SimpleClassOfDurationToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfDuration { + final Iterable? value; + + SimpleClassNullableOfDuration( + this.value, + ); + + factory SimpleClassNullableOfDuration.fromJson(Map json) => + _$SimpleClassNullableOfDurationFromJson(json); + + Map toJson() => _$SimpleClassNullableOfDurationToJson(this); +} + +@JsonSerializable() +class SimpleClassOfDurationNullable { + final Iterable value; + + SimpleClassOfDurationNullable( + this.value, + ); - SimpleClassDuration( + factory SimpleClassOfDurationNullable.fromJson(Map json) => + _$SimpleClassOfDurationNullableFromJson(json); + + Map toJson() => _$SimpleClassOfDurationNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfDurationNullable { + final Iterable? value; + + SimpleClassNullableOfDurationNullable( this.value, - this.nullable, ); - factory SimpleClassDuration.fromJson(Map json) => - _$SimpleClassDurationFromJson(json); + factory SimpleClassNullableOfDurationNullable.fromJson( + Map json) => + _$SimpleClassNullableOfDurationNullableFromJson(json); - Map toJson() => _$SimpleClassDurationToJson(this); + Map toJson() => + _$SimpleClassNullableOfDurationNullableToJson(this); } @JsonSerializable() -class SimpleClassDynamic { +class SimpleClassOfDynamic { final Iterable value; - @JsonKey(nullable: false) - final Iterable nullable; + SimpleClassOfDynamic( + this.value, + ); + + factory SimpleClassOfDynamic.fromJson(Map json) => + _$SimpleClassOfDynamicFromJson(json); + + Map toJson() => _$SimpleClassOfDynamicToJson(this); +} - SimpleClassDynamic( +@JsonSerializable() +class SimpleClassNullableOfDynamic { + final Iterable? value; + + SimpleClassNullableOfDynamic( this.value, - this.nullable, ); - factory SimpleClassDynamic.fromJson(Map json) => - _$SimpleClassDynamicFromJson(json); + factory SimpleClassNullableOfDynamic.fromJson(Map json) => + _$SimpleClassNullableOfDynamicFromJson(json); - Map toJson() => _$SimpleClassDynamicToJson(this); + Map toJson() => _$SimpleClassNullableOfDynamicToJson(this); } @JsonSerializable() -class SimpleClassEnumType { +class SimpleClassOfEnumType { final Iterable value; - @JsonKey(nullable: false) - final Iterable nullable; + SimpleClassOfEnumType( + this.value, + ); + + factory SimpleClassOfEnumType.fromJson(Map json) => + _$SimpleClassOfEnumTypeFromJson(json); + + Map toJson() => _$SimpleClassOfEnumTypeToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfEnumType { + final Iterable? value; + + SimpleClassNullableOfEnumType( + this.value, + ); + + factory SimpleClassNullableOfEnumType.fromJson(Map json) => + _$SimpleClassNullableOfEnumTypeFromJson(json); + + Map toJson() => _$SimpleClassNullableOfEnumTypeToJson(this); +} + +@JsonSerializable() +class SimpleClassOfEnumTypeNullable { + final Iterable value; + + SimpleClassOfEnumTypeNullable( + this.value, + ); + + factory SimpleClassOfEnumTypeNullable.fromJson(Map json) => + _$SimpleClassOfEnumTypeNullableFromJson(json); - SimpleClassEnumType( + Map toJson() => _$SimpleClassOfEnumTypeNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfEnumTypeNullable { + final Iterable? value; + + SimpleClassNullableOfEnumTypeNullable( this.value, - this.nullable, ); - factory SimpleClassEnumType.fromJson(Map json) => - _$SimpleClassEnumTypeFromJson(json); + factory SimpleClassNullableOfEnumTypeNullable.fromJson( + Map json) => + _$SimpleClassNullableOfEnumTypeNullableFromJson(json); - Map toJson() => _$SimpleClassEnumTypeToJson(this); + Map toJson() => + _$SimpleClassNullableOfEnumTypeNullableToJson(this); } @JsonSerializable() -class SimpleClassInt { +class SimpleClassOfInt { final Iterable value; - @JsonKey(nullable: false) - final Iterable nullable; + SimpleClassOfInt( + this.value, + ); + + factory SimpleClassOfInt.fromJson(Map json) => + _$SimpleClassOfIntFromJson(json); + + Map toJson() => _$SimpleClassOfIntToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfInt { + final Iterable? value; + + SimpleClassNullableOfInt( + this.value, + ); + + factory SimpleClassNullableOfInt.fromJson(Map json) => + _$SimpleClassNullableOfIntFromJson(json); + + Map toJson() => _$SimpleClassNullableOfIntToJson(this); +} + +@JsonSerializable() +class SimpleClassOfIntNullable { + final Iterable value; - SimpleClassInt( + SimpleClassOfIntNullable( this.value, - this.nullable, ); - factory SimpleClassInt.fromJson(Map json) => - _$SimpleClassIntFromJson(json); + factory SimpleClassOfIntNullable.fromJson(Map json) => + _$SimpleClassOfIntNullableFromJson(json); - Map toJson() => _$SimpleClassIntToJson(this); + Map toJson() => _$SimpleClassOfIntNullableToJson(this); } @JsonSerializable() -class SimpleClassNum { +class SimpleClassNullableOfIntNullable { + final Iterable? value; + + SimpleClassNullableOfIntNullable( + this.value, + ); + + factory SimpleClassNullableOfIntNullable.fromJson( + Map json) => + _$SimpleClassNullableOfIntNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfIntNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfNum { final Iterable value; - @JsonKey(nullable: false) - final Iterable nullable; + SimpleClassOfNum( + this.value, + ); + + factory SimpleClassOfNum.fromJson(Map json) => + _$SimpleClassOfNumFromJson(json); + + Map toJson() => _$SimpleClassOfNumToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfNum { + final Iterable? value; + + SimpleClassNullableOfNum( + this.value, + ); - SimpleClassNum( + factory SimpleClassNullableOfNum.fromJson(Map json) => + _$SimpleClassNullableOfNumFromJson(json); + + Map toJson() => _$SimpleClassNullableOfNumToJson(this); +} + +@JsonSerializable() +class SimpleClassOfNumNullable { + final Iterable value; + + SimpleClassOfNumNullable( this.value, - this.nullable, ); - factory SimpleClassNum.fromJson(Map json) => - _$SimpleClassNumFromJson(json); + factory SimpleClassOfNumNullable.fromJson(Map json) => + _$SimpleClassOfNumNullableFromJson(json); - Map toJson() => _$SimpleClassNumToJson(this); + Map toJson() => _$SimpleClassOfNumNullableToJson(this); } @JsonSerializable() -class SimpleClassObject { +class SimpleClassNullableOfNumNullable { + final Iterable? value; + + SimpleClassNullableOfNumNullable( + this.value, + ); + + factory SimpleClassNullableOfNumNullable.fromJson( + Map json) => + _$SimpleClassNullableOfNumNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfNumNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfObject { final Iterable value; - @JsonKey(nullable: false) - final Iterable nullable; + SimpleClassOfObject( + this.value, + ); + + factory SimpleClassOfObject.fromJson(Map json) => + _$SimpleClassOfObjectFromJson(json); + + Map toJson() => _$SimpleClassOfObjectToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfObject { + final Iterable? value; + + SimpleClassNullableOfObject( + this.value, + ); + + factory SimpleClassNullableOfObject.fromJson(Map json) => + _$SimpleClassNullableOfObjectFromJson(json); + + Map toJson() => _$SimpleClassNullableOfObjectToJson(this); +} + +@JsonSerializable() +class SimpleClassOfObjectNullable { + final Iterable value; + + SimpleClassOfObjectNullable( + this.value, + ); + + factory SimpleClassOfObjectNullable.fromJson(Map json) => + _$SimpleClassOfObjectNullableFromJson(json); + + Map toJson() => _$SimpleClassOfObjectNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfObjectNullable { + final Iterable? value; - SimpleClassObject( + SimpleClassNullableOfObjectNullable( this.value, - this.nullable, ); - factory SimpleClassObject.fromJson(Map json) => - _$SimpleClassObjectFromJson(json); + factory SimpleClassNullableOfObjectNullable.fromJson( + Map json) => + _$SimpleClassNullableOfObjectNullableFromJson(json); - Map toJson() => _$SimpleClassObjectToJson(this); + Map toJson() => + _$SimpleClassNullableOfObjectNullableToJson(this); } @JsonSerializable() -class SimpleClassString { +class SimpleClassOfString { final Iterable value; - @JsonKey(nullable: false) - final Iterable nullable; + SimpleClassOfString( + this.value, + ); + + factory SimpleClassOfString.fromJson(Map json) => + _$SimpleClassOfStringFromJson(json); + + Map toJson() => _$SimpleClassOfStringToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfString { + final Iterable? value; + + SimpleClassNullableOfString( + this.value, + ); + + factory SimpleClassNullableOfString.fromJson(Map json) => + _$SimpleClassNullableOfStringFromJson(json); + + Map toJson() => _$SimpleClassNullableOfStringToJson(this); +} + +@JsonSerializable() +class SimpleClassOfStringNullable { + final Iterable value; - SimpleClassString( + SimpleClassOfStringNullable( this.value, - this.nullable, ); - factory SimpleClassString.fromJson(Map json) => - _$SimpleClassStringFromJson(json); + factory SimpleClassOfStringNullable.fromJson(Map json) => + _$SimpleClassOfStringNullableFromJson(json); - Map toJson() => _$SimpleClassStringToJson(this); + Map toJson() => _$SimpleClassOfStringNullableToJson(this); } @JsonSerializable() -class SimpleClassUri { +class SimpleClassNullableOfStringNullable { + final Iterable? value; + + SimpleClassNullableOfStringNullable( + this.value, + ); + + factory SimpleClassNullableOfStringNullable.fromJson( + Map json) => + _$SimpleClassNullableOfStringNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfStringNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfUri { final Iterable value; - @JsonKey(nullable: false) - final Iterable nullable; + SimpleClassOfUri( + this.value, + ); + + factory SimpleClassOfUri.fromJson(Map json) => + _$SimpleClassOfUriFromJson(json); + + Map toJson() => _$SimpleClassOfUriToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfUri { + final Iterable? value; + + SimpleClassNullableOfUri( + this.value, + ); + + factory SimpleClassNullableOfUri.fromJson(Map json) => + _$SimpleClassNullableOfUriFromJson(json); + + Map toJson() => _$SimpleClassNullableOfUriToJson(this); +} + +@JsonSerializable() +class SimpleClassOfUriNullable { + final Iterable value; + + SimpleClassOfUriNullable( + this.value, + ); + + factory SimpleClassOfUriNullable.fromJson(Map json) => + _$SimpleClassOfUriNullableFromJson(json); + + Map toJson() => _$SimpleClassOfUriNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfUriNullable { + final Iterable? value; - SimpleClassUri( + SimpleClassNullableOfUriNullable( this.value, - this.nullable, ); - factory SimpleClassUri.fromJson(Map json) => - _$SimpleClassUriFromJson(json); + factory SimpleClassNullableOfUriNullable.fromJson( + Map json) => + _$SimpleClassNullableOfUriNullableFromJson(json); - Map toJson() => _$SimpleClassUriToJson(this); + Map toJson() => + _$SimpleClassNullableOfUriNullableToJson(this); } diff --git a/json_serializable/test/supported_types/input.type_iterable.g.dart b/json_serializable/test/supported_types/input.type_iterable.g.dart index 474f8ce78..e0b5389ad 100644 --- a/json_serializable/test/supported_types/input.type_iterable.g.dart +++ b/json_serializable/test/supported_types/input.type_iterable.g.dart @@ -1,4 +1,5 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// @dart=2.12 part of 'input.type_iterable.dart'; @@ -8,146 +9,358 @@ part of 'input.type_iterable.dart'; SimpleClass _$SimpleClassFromJson(Map json) { return SimpleClass( - json['value'] as List, - json['nullable'] as List, - )..withDefault = json['withDefault'] as List ?? [42, true, false, null]; + json['value'] as List, + json['withDefault'] as List? ?? [42, true, false, null], + ); } Map _$SimpleClassToJson(SimpleClass instance) => + { + 'value': instance.value.toList(), + 'withDefault': instance.withDefault.toList(), + }; + +SimpleClassNullable _$SimpleClassNullableFromJson(Map json) { + return SimpleClassNullable( + json['value'] as List?, + json['withDefault'] as List? ?? [42, true, false, null], + ); +} + +Map _$SimpleClassNullableToJson( + SimpleClassNullable instance) => { 'value': instance.value?.toList(), - 'nullable': instance.nullable.toList(), 'withDefault': instance.withDefault?.toList(), }; -SimpleClassBigInt _$SimpleClassBigIntFromJson(Map json) { - return SimpleClassBigInt( - (json['value'] as List) +SimpleClassOfBigInt _$SimpleClassOfBigIntFromJson(Map json) { + return SimpleClassOfBigInt( + (json['value'] as List).map((e) => BigInt.parse(e as String)), + ); +} + +Map _$SimpleClassOfBigIntToJson( + SimpleClassOfBigInt instance) => + { + 'value': instance.value.map((e) => e.toString()).toList(), + }; + +SimpleClassNullableOfBigInt _$SimpleClassNullableOfBigIntFromJson( + Map json) { + return SimpleClassNullableOfBigInt( + (json['value'] as List?)?.map((e) => BigInt.parse(e as String)), + ); +} + +Map _$SimpleClassNullableOfBigIntToJson( + SimpleClassNullableOfBigInt instance) => + { + 'value': instance.value?.map((e) => e.toString()).toList(), + }; + +SimpleClassOfBigIntNullable _$SimpleClassOfBigIntNullableFromJson( + Map json) { + return SimpleClassOfBigIntNullable( + (json['value'] as List) + .map((e) => e == null ? null : BigInt.parse(e as String)), + ); +} + +Map _$SimpleClassOfBigIntNullableToJson( + SimpleClassOfBigIntNullable instance) => + { + 'value': instance.value.map((e) => e?.toString()).toList(), + }; + +SimpleClassNullableOfBigIntNullable + _$SimpleClassNullableOfBigIntNullableFromJson(Map json) { + return SimpleClassNullableOfBigIntNullable( + (json['value'] as List?) ?.map((e) => e == null ? null : BigInt.parse(e as String)), - (json['nullable'] as List).map((e) => BigInt.parse(e as String)), ); } -Map _$SimpleClassBigIntToJson(SimpleClassBigInt instance) => +Map _$SimpleClassNullableOfBigIntNullableToJson( + SimpleClassNullableOfBigIntNullable instance) => + { + 'value': instance.value?.map((e) => e?.toString()).toList(), + }; + +SimpleClassOfBool _$SimpleClassOfBoolFromJson(Map json) { + return SimpleClassOfBool( + (json['value'] as List).map((e) => e as bool), + ); +} + +Map _$SimpleClassOfBoolToJson(SimpleClassOfBool instance) => + { + 'value': instance.value.toList(), + }; + +SimpleClassNullableOfBool _$SimpleClassNullableOfBoolFromJson( + Map json) { + return SimpleClassNullableOfBool( + (json['value'] as List?)?.map((e) => e as bool), + ); +} + +Map _$SimpleClassNullableOfBoolToJson( + SimpleClassNullableOfBool instance) => + { + 'value': instance.value?.toList(), + }; + +SimpleClassOfBoolNullable _$SimpleClassOfBoolNullableFromJson( + Map json) { + return SimpleClassOfBoolNullable( + (json['value'] as List).map((e) => e as bool?), + ); +} + +Map _$SimpleClassOfBoolNullableToJson( + SimpleClassOfBoolNullable instance) => { - 'value': instance.value?.map((e) => e?.toString())?.toList(), - 'nullable': instance.nullable.map((e) => e.toString()).toList(), + 'value': instance.value.toList(), }; -SimpleClassBool _$SimpleClassBoolFromJson(Map json) { - return SimpleClassBool( - (json['value'] as List)?.map((e) => e as bool), - (json['nullable'] as List).map((e) => e as bool), +SimpleClassNullableOfBoolNullable _$SimpleClassNullableOfBoolNullableFromJson( + Map json) { + return SimpleClassNullableOfBoolNullable( + (json['value'] as List?)?.map((e) => e as bool?), ); } -Map _$SimpleClassBoolToJson(SimpleClassBool instance) => +Map _$SimpleClassNullableOfBoolNullableToJson( + SimpleClassNullableOfBoolNullable instance) => { 'value': instance.value?.toList(), - 'nullable': instance.nullable.toList(), }; -SimpleClassDateTime _$SimpleClassDateTimeFromJson(Map json) { - return SimpleClassDateTime( - (json['value'] as List) +SimpleClassOfDateTime _$SimpleClassOfDateTimeFromJson( + Map json) { + return SimpleClassOfDateTime( + (json['value'] as List).map((e) => DateTime.parse(e as String)), + ); +} + +Map _$SimpleClassOfDateTimeToJson( + SimpleClassOfDateTime instance) => + { + 'value': instance.value.map((e) => e.toIso8601String()).toList(), + }; + +SimpleClassNullableOfDateTime _$SimpleClassNullableOfDateTimeFromJson( + Map json) { + return SimpleClassNullableOfDateTime( + (json['value'] as List?)?.map((e) => DateTime.parse(e as String)), + ); +} + +Map _$SimpleClassNullableOfDateTimeToJson( + SimpleClassNullableOfDateTime instance) => + { + 'value': instance.value?.map((e) => e.toIso8601String()).toList(), + }; + +SimpleClassOfDateTimeNullable _$SimpleClassOfDateTimeNullableFromJson( + Map json) { + return SimpleClassOfDateTimeNullable( + (json['value'] as List) + .map((e) => e == null ? null : DateTime.parse(e as String)), + ); +} + +Map _$SimpleClassOfDateTimeNullableToJson( + SimpleClassOfDateTimeNullable instance) => + { + 'value': instance.value.map((e) => e?.toIso8601String()).toList(), + }; + +SimpleClassNullableOfDateTimeNullable + _$SimpleClassNullableOfDateTimeNullableFromJson(Map json) { + return SimpleClassNullableOfDateTimeNullable( + (json['value'] as List?) ?.map((e) => e == null ? null : DateTime.parse(e as String)), - (json['nullable'] as List).map((e) => DateTime.parse(e as String)), ); } -Map _$SimpleClassDateTimeToJson( - SimpleClassDateTime instance) => +Map _$SimpleClassNullableOfDateTimeNullableToJson( + SimpleClassNullableOfDateTimeNullable instance) => { - 'value': instance.value?.map((e) => e?.toIso8601String())?.toList(), - 'nullable': instance.nullable.map((e) => e.toIso8601String()).toList(), + 'value': instance.value?.map((e) => e?.toIso8601String()).toList(), }; -SimpleClassDouble _$SimpleClassDoubleFromJson(Map json) { - return SimpleClassDouble( - (json['value'] as List)?.map((e) => (e as num)?.toDouble()), - (json['nullable'] as List).map((e) => (e as num).toDouble()), +SimpleClassOfDouble _$SimpleClassOfDoubleFromJson(Map json) { + return SimpleClassOfDouble( + (json['value'] as List).map((e) => (e as num).toDouble()), ); } -Map _$SimpleClassDoubleToJson(SimpleClassDouble instance) => +Map _$SimpleClassOfDoubleToJson( + SimpleClassOfDouble instance) => + { + 'value': instance.value.toList(), + }; + +SimpleClassNullableOfDouble _$SimpleClassNullableOfDoubleFromJson( + Map json) { + return SimpleClassNullableOfDouble( + (json['value'] as List?)?.map((e) => (e as num).toDouble()), + ); +} + +Map _$SimpleClassNullableOfDoubleToJson( + SimpleClassNullableOfDouble instance) => { 'value': instance.value?.toList(), - 'nullable': instance.nullable.toList(), }; -SimpleClassDuration _$SimpleClassDurationFromJson(Map json) { - return SimpleClassDuration( - (json['value'] as List) - ?.map((e) => e == null ? null : Duration(microseconds: e as int)), - (json['nullable'] as List).map((e) => Duration(microseconds: e as int)), +SimpleClassOfDoubleNullable _$SimpleClassOfDoubleNullableFromJson( + Map json) { + return SimpleClassOfDoubleNullable( + (json['value'] as List).map((e) => (e as num?)?.toDouble()), ); } -Map _$SimpleClassDurationToJson( - SimpleClassDuration instance) => +Map _$SimpleClassOfDoubleNullableToJson( + SimpleClassOfDoubleNullable instance) => { - 'value': instance.value?.map((e) => e?.inMicroseconds)?.toList(), - 'nullable': instance.nullable.map((e) => e.inMicroseconds).toList(), + 'value': instance.value.toList(), }; -SimpleClassDynamic _$SimpleClassDynamicFromJson(Map json) { - return SimpleClassDynamic( - json['value'] as List, - json['nullable'] as List, +SimpleClassNullableOfDoubleNullable + _$SimpleClassNullableOfDoubleNullableFromJson(Map json) { + return SimpleClassNullableOfDoubleNullable( + (json['value'] as List?)?.map((e) => (e as num?)?.toDouble()), ); } -Map _$SimpleClassDynamicToJson(SimpleClassDynamic instance) => +Map _$SimpleClassNullableOfDoubleNullableToJson( + SimpleClassNullableOfDoubleNullable instance) => { 'value': instance.value?.toList(), - 'nullable': instance.nullable.toList(), }; -SimpleClassEnumType _$SimpleClassEnumTypeFromJson(Map json) { - return SimpleClassEnumType( - (json['value'] as List) - ?.map((e) => _$enumDecodeNullable(_$EnumTypeEnumMap, e)), - (json['nullable'] as List).map((e) => _$enumDecode(_$EnumTypeEnumMap, e)), +SimpleClassOfDuration _$SimpleClassOfDurationFromJson( + Map json) { + return SimpleClassOfDuration( + (json['value'] as List) + .map((e) => Duration(microseconds: e as int)), ); } -Map _$SimpleClassEnumTypeToJson( - SimpleClassEnumType instance) => +Map _$SimpleClassOfDurationToJson( + SimpleClassOfDuration instance) => { - 'value': instance.value?.map((e) => _$EnumTypeEnumMap[e])?.toList(), - 'nullable': instance.nullable.map((e) => _$EnumTypeEnumMap[e]).toList(), + 'value': instance.value.map((e) => e.inMicroseconds).toList(), }; -T _$enumDecode( - Map enumValues, - dynamic source, { - T unknownValue, -}) { - if (source == null) { - throw ArgumentError('A value must be provided. Supported values: ' - '${enumValues.values.join(', ')}'); - } +SimpleClassNullableOfDuration _$SimpleClassNullableOfDurationFromJson( + Map json) { + return SimpleClassNullableOfDuration( + (json['value'] as List?) + ?.map((e) => Duration(microseconds: e as int)), + ); +} - final value = enumValues.entries - .singleWhere((e) => e.value == source, orElse: () => null) - ?.key; +Map _$SimpleClassNullableOfDurationToJson( + SimpleClassNullableOfDuration instance) => + { + 'value': instance.value?.map((e) => e.inMicroseconds).toList(), + }; - if (value == null && unknownValue == null) { - throw ArgumentError('`$source` is not one of the supported values: ' - '${enumValues.values.join(', ')}'); - } - return value ?? unknownValue; +SimpleClassOfDurationNullable _$SimpleClassOfDurationNullableFromJson( + Map json) { + return SimpleClassOfDurationNullable( + (json['value'] as List) + .map((e) => e == null ? null : Duration(microseconds: e as int)), + ); } -T _$enumDecodeNullable( - Map enumValues, - dynamic source, { - T unknownValue, +Map _$SimpleClassOfDurationNullableToJson( + SimpleClassOfDurationNullable instance) => + { + 'value': instance.value.map((e) => e?.inMicroseconds).toList(), + }; + +SimpleClassNullableOfDurationNullable + _$SimpleClassNullableOfDurationNullableFromJson(Map json) { + return SimpleClassNullableOfDurationNullable( + (json['value'] as List?) + ?.map((e) => e == null ? null : Duration(microseconds: e as int)), + ); +} + +Map _$SimpleClassNullableOfDurationNullableToJson( + SimpleClassNullableOfDurationNullable instance) => + { + 'value': instance.value?.map((e) => e?.inMicroseconds).toList(), + }; + +SimpleClassOfDynamic _$SimpleClassOfDynamicFromJson(Map json) { + return SimpleClassOfDynamic( + json['value'] as List, + ); +} + +Map _$SimpleClassOfDynamicToJson( + SimpleClassOfDynamic instance) => + { + 'value': instance.value.toList(), + }; + +SimpleClassNullableOfDynamic _$SimpleClassNullableOfDynamicFromJson( + Map json) { + return SimpleClassNullableOfDynamic( + json['value'] as List?, + ); +} + +Map _$SimpleClassNullableOfDynamicToJson( + SimpleClassNullableOfDynamic instance) => + { + 'value': instance.value?.toList(), + }; + +SimpleClassOfEnumType _$SimpleClassOfEnumTypeFromJson( + Map json) { + return SimpleClassOfEnumType( + (json['value'] as List) + .map((e) => _$enumDecode(_$EnumTypeEnumMap, e)), + ); +} + +Map _$SimpleClassOfEnumTypeToJson( + SimpleClassOfEnumType instance) => + { + 'value': instance.value.map((e) => _$EnumTypeEnumMap[e]).toList(), + }; + +K _$enumDecode( + Map enumValues, + Object? source, { + K? unknownValue, }) { if (source == null) { - return null; + throw ArgumentError( + 'A value must be provided. Supported values: ' + '${enumValues.values.join(', ')}', + ); } - return _$enumDecode(enumValues, source, unknownValue: unknownValue); + + return enumValues.entries.singleWhere( + (e) => e.value == source, + orElse: () { + if (unknownValue == null) { + throw ArgumentError( + '`$source` is not one of the supported values: ' + '${enumValues.values.join(', ')}', + ); + } + return MapEntry(unknownValue, enumValues.values.first); + }, + ).key; } const _$EnumTypeEnumMap = { @@ -157,68 +370,309 @@ const _$EnumTypeEnumMap = { EnumType.delta: 'delta', }; -SimpleClassInt _$SimpleClassIntFromJson(Map json) { - return SimpleClassInt( - (json['value'] as List)?.map((e) => e as int), - (json['nullable'] as List).map((e) => e as int), +SimpleClassNullableOfEnumType _$SimpleClassNullableOfEnumTypeFromJson( + Map json) { + return SimpleClassNullableOfEnumType( + (json['value'] as List?) + ?.map((e) => _$enumDecode(_$EnumTypeEnumMap, e)), + ); +} + +Map _$SimpleClassNullableOfEnumTypeToJson( + SimpleClassNullableOfEnumType instance) => + { + 'value': instance.value?.map((e) => _$EnumTypeEnumMap[e]).toList(), + }; + +SimpleClassOfEnumTypeNullable _$SimpleClassOfEnumTypeNullableFromJson( + Map json) { + return SimpleClassOfEnumTypeNullable( + (json['value'] as List) + .map((e) => _$enumDecodeNullable(_$EnumTypeEnumMap, e)), + ); +} + +Map _$SimpleClassOfEnumTypeNullableToJson( + SimpleClassOfEnumTypeNullable instance) => + { + 'value': instance.value.map((e) => _$EnumTypeEnumMap[e]).toList(), + }; + +K? _$enumDecodeNullable( + Map enumValues, + dynamic source, { + K? unknownValue, +}) { + if (source == null) { + return null; + } + return _$enumDecode(enumValues, source, unknownValue: unknownValue); +} + +SimpleClassNullableOfEnumTypeNullable + _$SimpleClassNullableOfEnumTypeNullableFromJson(Map json) { + return SimpleClassNullableOfEnumTypeNullable( + (json['value'] as List?) + ?.map((e) => _$enumDecodeNullable(_$EnumTypeEnumMap, e)), + ); +} + +Map _$SimpleClassNullableOfEnumTypeNullableToJson( + SimpleClassNullableOfEnumTypeNullable instance) => + { + 'value': instance.value?.map((e) => _$EnumTypeEnumMap[e]).toList(), + }; + +SimpleClassOfInt _$SimpleClassOfIntFromJson(Map json) { + return SimpleClassOfInt( + (json['value'] as List).map((e) => e as int), + ); +} + +Map _$SimpleClassOfIntToJson(SimpleClassOfInt instance) => + { + 'value': instance.value.toList(), + }; + +SimpleClassNullableOfInt _$SimpleClassNullableOfIntFromJson( + Map json) { + return SimpleClassNullableOfInt( + (json['value'] as List?)?.map((e) => e as int), + ); +} + +Map _$SimpleClassNullableOfIntToJson( + SimpleClassNullableOfInt instance) => + { + 'value': instance.value?.toList(), + }; + +SimpleClassOfIntNullable _$SimpleClassOfIntNullableFromJson( + Map json) { + return SimpleClassOfIntNullable( + (json['value'] as List).map((e) => e as int?), + ); +} + +Map _$SimpleClassOfIntNullableToJson( + SimpleClassOfIntNullable instance) => + { + 'value': instance.value.toList(), + }; + +SimpleClassNullableOfIntNullable _$SimpleClassNullableOfIntNullableFromJson( + Map json) { + return SimpleClassNullableOfIntNullable( + (json['value'] as List?)?.map((e) => e as int?), + ); +} + +Map _$SimpleClassNullableOfIntNullableToJson( + SimpleClassNullableOfIntNullable instance) => + { + 'value': instance.value?.toList(), + }; + +SimpleClassOfNum _$SimpleClassOfNumFromJson(Map json) { + return SimpleClassOfNum( + (json['value'] as List).map((e) => e as num), + ); +} + +Map _$SimpleClassOfNumToJson(SimpleClassOfNum instance) => + { + 'value': instance.value.toList(), + }; + +SimpleClassNullableOfNum _$SimpleClassNullableOfNumFromJson( + Map json) { + return SimpleClassNullableOfNum( + (json['value'] as List?)?.map((e) => e as num), + ); +} + +Map _$SimpleClassNullableOfNumToJson( + SimpleClassNullableOfNum instance) => + { + 'value': instance.value?.toList(), + }; + +SimpleClassOfNumNullable _$SimpleClassOfNumNullableFromJson( + Map json) { + return SimpleClassOfNumNullable( + (json['value'] as List).map((e) => e as num?), ); } -Map _$SimpleClassIntToJson(SimpleClassInt instance) => +Map _$SimpleClassOfNumNullableToJson( + SimpleClassOfNumNullable instance) => + { + 'value': instance.value.toList(), + }; + +SimpleClassNullableOfNumNullable _$SimpleClassNullableOfNumNullableFromJson( + Map json) { + return SimpleClassNullableOfNumNullable( + (json['value'] as List?)?.map((e) => e as num?), + ); +} + +Map _$SimpleClassNullableOfNumNullableToJson( + SimpleClassNullableOfNumNullable instance) => { 'value': instance.value?.toList(), - 'nullable': instance.nullable.toList(), }; -SimpleClassNum _$SimpleClassNumFromJson(Map json) { - return SimpleClassNum( - (json['value'] as List)?.map((e) => e as num), - (json['nullable'] as List).map((e) => e as num), +SimpleClassOfObject _$SimpleClassOfObjectFromJson(Map json) { + return SimpleClassOfObject( + (json['value'] as List).map((e) => e as Object), + ); +} + +Map _$SimpleClassOfObjectToJson( + SimpleClassOfObject instance) => + { + 'value': instance.value.toList(), + }; + +SimpleClassNullableOfObject _$SimpleClassNullableOfObjectFromJson( + Map json) { + return SimpleClassNullableOfObject( + (json['value'] as List?)?.map((e) => e as Object), ); } -Map _$SimpleClassNumToJson(SimpleClassNum instance) => +Map _$SimpleClassNullableOfObjectToJson( + SimpleClassNullableOfObject instance) => { 'value': instance.value?.toList(), - 'nullable': instance.nullable.toList(), }; -SimpleClassObject _$SimpleClassObjectFromJson(Map json) { - return SimpleClassObject( - json['value'] as List, - json['nullable'] as List, +SimpleClassOfObjectNullable _$SimpleClassOfObjectNullableFromJson( + Map json) { + return SimpleClassOfObjectNullable( + json['value'] as List, + ); +} + +Map _$SimpleClassOfObjectNullableToJson( + SimpleClassOfObjectNullable instance) => + { + 'value': instance.value.toList(), + }; + +SimpleClassNullableOfObjectNullable + _$SimpleClassNullableOfObjectNullableFromJson(Map json) { + return SimpleClassNullableOfObjectNullable( + json['value'] as List?, + ); +} + +Map _$SimpleClassNullableOfObjectNullableToJson( + SimpleClassNullableOfObjectNullable instance) => + { + 'value': instance.value?.toList(), + }; + +SimpleClassOfString _$SimpleClassOfStringFromJson(Map json) { + return SimpleClassOfString( + (json['value'] as List).map((e) => e as String), + ); +} + +Map _$SimpleClassOfStringToJson( + SimpleClassOfString instance) => + { + 'value': instance.value.toList(), + }; + +SimpleClassNullableOfString _$SimpleClassNullableOfStringFromJson( + Map json) { + return SimpleClassNullableOfString( + (json['value'] as List?)?.map((e) => e as String), ); } -Map _$SimpleClassObjectToJson(SimpleClassObject instance) => +Map _$SimpleClassNullableOfStringToJson( + SimpleClassNullableOfString instance) => { 'value': instance.value?.toList(), - 'nullable': instance.nullable.toList(), }; -SimpleClassString _$SimpleClassStringFromJson(Map json) { - return SimpleClassString( - (json['value'] as List)?.map((e) => e as String), - (json['nullable'] as List).map((e) => e as String), +SimpleClassOfStringNullable _$SimpleClassOfStringNullableFromJson( + Map json) { + return SimpleClassOfStringNullable( + (json['value'] as List).map((e) => e as String?), ); } -Map _$SimpleClassStringToJson(SimpleClassString instance) => +Map _$SimpleClassOfStringNullableToJson( + SimpleClassOfStringNullable instance) => + { + 'value': instance.value.toList(), + }; + +SimpleClassNullableOfStringNullable + _$SimpleClassNullableOfStringNullableFromJson(Map json) { + return SimpleClassNullableOfStringNullable( + (json['value'] as List?)?.map((e) => e as String?), + ); +} + +Map _$SimpleClassNullableOfStringNullableToJson( + SimpleClassNullableOfStringNullable instance) => { 'value': instance.value?.toList(), - 'nullable': instance.nullable.toList(), }; -SimpleClassUri _$SimpleClassUriFromJson(Map json) { - return SimpleClassUri( - (json['value'] as List) +SimpleClassOfUri _$SimpleClassOfUriFromJson(Map json) { + return SimpleClassOfUri( + (json['value'] as List).map((e) => Uri.parse(e as String)), + ); +} + +Map _$SimpleClassOfUriToJson(SimpleClassOfUri instance) => + { + 'value': instance.value.map((e) => e.toString()).toList(), + }; + +SimpleClassNullableOfUri _$SimpleClassNullableOfUriFromJson( + Map json) { + return SimpleClassNullableOfUri( + (json['value'] as List?)?.map((e) => Uri.parse(e as String)), + ); +} + +Map _$SimpleClassNullableOfUriToJson( + SimpleClassNullableOfUri instance) => + { + 'value': instance.value?.map((e) => e.toString()).toList(), + }; + +SimpleClassOfUriNullable _$SimpleClassOfUriNullableFromJson( + Map json) { + return SimpleClassOfUriNullable( + (json['value'] as List) + .map((e) => e == null ? null : Uri.parse(e as String)), + ); +} + +Map _$SimpleClassOfUriNullableToJson( + SimpleClassOfUriNullable instance) => + { + 'value': instance.value.map((e) => e?.toString()).toList(), + }; + +SimpleClassNullableOfUriNullable _$SimpleClassNullableOfUriNullableFromJson( + Map json) { + return SimpleClassNullableOfUriNullable( + (json['value'] as List?) ?.map((e) => e == null ? null : Uri.parse(e as String)), - (json['nullable'] as List).map((e) => Uri.parse(e as String)), ); } -Map _$SimpleClassUriToJson(SimpleClassUri instance) => +Map _$SimpleClassNullableOfUriNullableToJson( + SimpleClassNullableOfUriNullable instance) => { - 'value': instance.value?.map((e) => e?.toString())?.toList(), - 'nullable': instance.nullable.map((e) => e.toString()).toList(), + 'value': instance.value?.map((e) => e?.toString()).toList(), }; diff --git a/json_serializable/test/supported_types/input.type_list.dart b/json_serializable/test/supported_types/input.type_list.dart index 44219ef49..657d45296 100644 --- a/json_serializable/test/supported_types/input.type_list.dart +++ b/json_serializable/test/supported_types/input.type_list.dart @@ -2,6 +2,8 @@ // 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. +// @dart=2.12 + import 'package:json_annotation/json_annotation.dart'; import 'enum_type.dart'; @@ -11,235 +13,700 @@ part 'input.type_list.g.dart'; class SimpleClass { final List value; - @JsonKey(nullable: false) - final List nullable; - @JsonKey(defaultValue: [42, true, false, null]) List withDefault; SimpleClass( this.value, - this.nullable, + this.withDefault, ); - factory SimpleClass.fromJson(Map json) => + factory SimpleClass.fromJson(Map json) => _$SimpleClassFromJson(json); - Map toJson() => _$SimpleClassToJson(this); + Map toJson() => _$SimpleClassToJson(this); } @JsonSerializable() -class SimpleClassBigInt { +class SimpleClassNullable { + final List? value; + + @JsonKey(defaultValue: [42, true, false, null]) + List? withDefault; + + SimpleClassNullable( + this.value, + this.withDefault, + ); + + factory SimpleClassNullable.fromJson(Map json) => + _$SimpleClassNullableFromJson(json); + + Map toJson() => _$SimpleClassNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfBigInt { final List value; - @JsonKey(nullable: false) - final List nullable; + SimpleClassOfBigInt( + this.value, + ); + + factory SimpleClassOfBigInt.fromJson(Map json) => + _$SimpleClassOfBigIntFromJson(json); + + Map toJson() => _$SimpleClassOfBigIntToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfBigInt { + final List? value; + + SimpleClassNullableOfBigInt( + this.value, + ); + + factory SimpleClassNullableOfBigInt.fromJson(Map json) => + _$SimpleClassNullableOfBigIntFromJson(json); + + Map toJson() => _$SimpleClassNullableOfBigIntToJson(this); +} + +@JsonSerializable() +class SimpleClassOfBigIntNullable { + final List value; + + SimpleClassOfBigIntNullable( + this.value, + ); + + factory SimpleClassOfBigIntNullable.fromJson(Map json) => + _$SimpleClassOfBigIntNullableFromJson(json); + + Map toJson() => _$SimpleClassOfBigIntNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfBigIntNullable { + final List? value; - SimpleClassBigInt( + SimpleClassNullableOfBigIntNullable( this.value, - this.nullable, ); - factory SimpleClassBigInt.fromJson(Map json) => - _$SimpleClassBigIntFromJson(json); + factory SimpleClassNullableOfBigIntNullable.fromJson( + Map json) => + _$SimpleClassNullableOfBigIntNullableFromJson(json); - Map toJson() => _$SimpleClassBigIntToJson(this); + Map toJson() => + _$SimpleClassNullableOfBigIntNullableToJson(this); } @JsonSerializable() -class SimpleClassBool { +class SimpleClassOfBool { final List value; - @JsonKey(nullable: false) - final List nullable; + SimpleClassOfBool( + this.value, + ); + + factory SimpleClassOfBool.fromJson(Map json) => + _$SimpleClassOfBoolFromJson(json); + + Map toJson() => _$SimpleClassOfBoolToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfBool { + final List? value; + + SimpleClassNullableOfBool( + this.value, + ); + + factory SimpleClassNullableOfBool.fromJson(Map json) => + _$SimpleClassNullableOfBoolFromJson(json); + + Map toJson() => _$SimpleClassNullableOfBoolToJson(this); +} + +@JsonSerializable() +class SimpleClassOfBoolNullable { + final List value; + + SimpleClassOfBoolNullable( + this.value, + ); + + factory SimpleClassOfBoolNullable.fromJson(Map json) => + _$SimpleClassOfBoolNullableFromJson(json); + + Map toJson() => _$SimpleClassOfBoolNullableToJson(this); +} - SimpleClassBool( +@JsonSerializable() +class SimpleClassNullableOfBoolNullable { + final List? value; + + SimpleClassNullableOfBoolNullable( this.value, - this.nullable, ); - factory SimpleClassBool.fromJson(Map json) => - _$SimpleClassBoolFromJson(json); + factory SimpleClassNullableOfBoolNullable.fromJson( + Map json) => + _$SimpleClassNullableOfBoolNullableFromJson(json); - Map toJson() => _$SimpleClassBoolToJson(this); + Map toJson() => + _$SimpleClassNullableOfBoolNullableToJson(this); } @JsonSerializable() -class SimpleClassDateTime { +class SimpleClassOfDateTime { final List value; - @JsonKey(nullable: false) - final List nullable; + SimpleClassOfDateTime( + this.value, + ); + + factory SimpleClassOfDateTime.fromJson(Map json) => + _$SimpleClassOfDateTimeFromJson(json); + + Map toJson() => _$SimpleClassOfDateTimeToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfDateTime { + final List? value; + + SimpleClassNullableOfDateTime( + this.value, + ); + + factory SimpleClassNullableOfDateTime.fromJson(Map json) => + _$SimpleClassNullableOfDateTimeFromJson(json); + + Map toJson() => _$SimpleClassNullableOfDateTimeToJson(this); +} + +@JsonSerializable() +class SimpleClassOfDateTimeNullable { + final List value; - SimpleClassDateTime( + SimpleClassOfDateTimeNullable( this.value, - this.nullable, ); - factory SimpleClassDateTime.fromJson(Map json) => - _$SimpleClassDateTimeFromJson(json); + factory SimpleClassOfDateTimeNullable.fromJson(Map json) => + _$SimpleClassOfDateTimeNullableFromJson(json); - Map toJson() => _$SimpleClassDateTimeToJson(this); + Map toJson() => _$SimpleClassOfDateTimeNullableToJson(this); } @JsonSerializable() -class SimpleClassDouble { +class SimpleClassNullableOfDateTimeNullable { + final List? value; + + SimpleClassNullableOfDateTimeNullable( + this.value, + ); + + factory SimpleClassNullableOfDateTimeNullable.fromJson( + Map json) => + _$SimpleClassNullableOfDateTimeNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfDateTimeNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfDouble { final List value; - @JsonKey(nullable: false) - final List nullable; + SimpleClassOfDouble( + this.value, + ); + + factory SimpleClassOfDouble.fromJson(Map json) => + _$SimpleClassOfDoubleFromJson(json); + + Map toJson() => _$SimpleClassOfDoubleToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfDouble { + final List? value; + + SimpleClassNullableOfDouble( + this.value, + ); + + factory SimpleClassNullableOfDouble.fromJson(Map json) => + _$SimpleClassNullableOfDoubleFromJson(json); + + Map toJson() => _$SimpleClassNullableOfDoubleToJson(this); +} + +@JsonSerializable() +class SimpleClassOfDoubleNullable { + final List value; + + SimpleClassOfDoubleNullable( + this.value, + ); + + factory SimpleClassOfDoubleNullable.fromJson(Map json) => + _$SimpleClassOfDoubleNullableFromJson(json); + + Map toJson() => _$SimpleClassOfDoubleNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfDoubleNullable { + final List? value; - SimpleClassDouble( + SimpleClassNullableOfDoubleNullable( this.value, - this.nullable, ); - factory SimpleClassDouble.fromJson(Map json) => - _$SimpleClassDoubleFromJson(json); + factory SimpleClassNullableOfDoubleNullable.fromJson( + Map json) => + _$SimpleClassNullableOfDoubleNullableFromJson(json); - Map toJson() => _$SimpleClassDoubleToJson(this); + Map toJson() => + _$SimpleClassNullableOfDoubleNullableToJson(this); } @JsonSerializable() -class SimpleClassDuration { +class SimpleClassOfDuration { final List value; - @JsonKey(nullable: false) - final List nullable; + SimpleClassOfDuration( + this.value, + ); + + factory SimpleClassOfDuration.fromJson(Map json) => + _$SimpleClassOfDurationFromJson(json); + + Map toJson() => _$SimpleClassOfDurationToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfDuration { + final List? value; + + SimpleClassNullableOfDuration( + this.value, + ); + + factory SimpleClassNullableOfDuration.fromJson(Map json) => + _$SimpleClassNullableOfDurationFromJson(json); + + Map toJson() => _$SimpleClassNullableOfDurationToJson(this); +} + +@JsonSerializable() +class SimpleClassOfDurationNullable { + final List value; + + SimpleClassOfDurationNullable( + this.value, + ); - SimpleClassDuration( + factory SimpleClassOfDurationNullable.fromJson(Map json) => + _$SimpleClassOfDurationNullableFromJson(json); + + Map toJson() => _$SimpleClassOfDurationNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfDurationNullable { + final List? value; + + SimpleClassNullableOfDurationNullable( this.value, - this.nullable, ); - factory SimpleClassDuration.fromJson(Map json) => - _$SimpleClassDurationFromJson(json); + factory SimpleClassNullableOfDurationNullable.fromJson( + Map json) => + _$SimpleClassNullableOfDurationNullableFromJson(json); - Map toJson() => _$SimpleClassDurationToJson(this); + Map toJson() => + _$SimpleClassNullableOfDurationNullableToJson(this); } @JsonSerializable() -class SimpleClassDynamic { +class SimpleClassOfDynamic { final List value; - @JsonKey(nullable: false) - final List nullable; + SimpleClassOfDynamic( + this.value, + ); + + factory SimpleClassOfDynamic.fromJson(Map json) => + _$SimpleClassOfDynamicFromJson(json); + + Map toJson() => _$SimpleClassOfDynamicToJson(this); +} - SimpleClassDynamic( +@JsonSerializable() +class SimpleClassNullableOfDynamic { + final List? value; + + SimpleClassNullableOfDynamic( this.value, - this.nullable, ); - factory SimpleClassDynamic.fromJson(Map json) => - _$SimpleClassDynamicFromJson(json); + factory SimpleClassNullableOfDynamic.fromJson(Map json) => + _$SimpleClassNullableOfDynamicFromJson(json); - Map toJson() => _$SimpleClassDynamicToJson(this); + Map toJson() => _$SimpleClassNullableOfDynamicToJson(this); } @JsonSerializable() -class SimpleClassEnumType { +class SimpleClassOfEnumType { final List value; - @JsonKey(nullable: false) - final List nullable; + SimpleClassOfEnumType( + this.value, + ); + + factory SimpleClassOfEnumType.fromJson(Map json) => + _$SimpleClassOfEnumTypeFromJson(json); + + Map toJson() => _$SimpleClassOfEnumTypeToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfEnumType { + final List? value; + + SimpleClassNullableOfEnumType( + this.value, + ); + + factory SimpleClassNullableOfEnumType.fromJson(Map json) => + _$SimpleClassNullableOfEnumTypeFromJson(json); + + Map toJson() => _$SimpleClassNullableOfEnumTypeToJson(this); +} + +@JsonSerializable() +class SimpleClassOfEnumTypeNullable { + final List value; + + SimpleClassOfEnumTypeNullable( + this.value, + ); + + factory SimpleClassOfEnumTypeNullable.fromJson(Map json) => + _$SimpleClassOfEnumTypeNullableFromJson(json); - SimpleClassEnumType( + Map toJson() => _$SimpleClassOfEnumTypeNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfEnumTypeNullable { + final List? value; + + SimpleClassNullableOfEnumTypeNullable( this.value, - this.nullable, ); - factory SimpleClassEnumType.fromJson(Map json) => - _$SimpleClassEnumTypeFromJson(json); + factory SimpleClassNullableOfEnumTypeNullable.fromJson( + Map json) => + _$SimpleClassNullableOfEnumTypeNullableFromJson(json); - Map toJson() => _$SimpleClassEnumTypeToJson(this); + Map toJson() => + _$SimpleClassNullableOfEnumTypeNullableToJson(this); } @JsonSerializable() -class SimpleClassInt { +class SimpleClassOfInt { final List value; - @JsonKey(nullable: false) - final List nullable; + SimpleClassOfInt( + this.value, + ); + + factory SimpleClassOfInt.fromJson(Map json) => + _$SimpleClassOfIntFromJson(json); + + Map toJson() => _$SimpleClassOfIntToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfInt { + final List? value; + + SimpleClassNullableOfInt( + this.value, + ); + + factory SimpleClassNullableOfInt.fromJson(Map json) => + _$SimpleClassNullableOfIntFromJson(json); + + Map toJson() => _$SimpleClassNullableOfIntToJson(this); +} + +@JsonSerializable() +class SimpleClassOfIntNullable { + final List value; - SimpleClassInt( + SimpleClassOfIntNullable( this.value, - this.nullable, ); - factory SimpleClassInt.fromJson(Map json) => - _$SimpleClassIntFromJson(json); + factory SimpleClassOfIntNullable.fromJson(Map json) => + _$SimpleClassOfIntNullableFromJson(json); - Map toJson() => _$SimpleClassIntToJson(this); + Map toJson() => _$SimpleClassOfIntNullableToJson(this); } @JsonSerializable() -class SimpleClassNum { +class SimpleClassNullableOfIntNullable { + final List? value; + + SimpleClassNullableOfIntNullable( + this.value, + ); + + factory SimpleClassNullableOfIntNullable.fromJson( + Map json) => + _$SimpleClassNullableOfIntNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfIntNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfNum { final List value; - @JsonKey(nullable: false) - final List nullable; + SimpleClassOfNum( + this.value, + ); + + factory SimpleClassOfNum.fromJson(Map json) => + _$SimpleClassOfNumFromJson(json); + + Map toJson() => _$SimpleClassOfNumToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfNum { + final List? value; + + SimpleClassNullableOfNum( + this.value, + ); - SimpleClassNum( + factory SimpleClassNullableOfNum.fromJson(Map json) => + _$SimpleClassNullableOfNumFromJson(json); + + Map toJson() => _$SimpleClassNullableOfNumToJson(this); +} + +@JsonSerializable() +class SimpleClassOfNumNullable { + final List value; + + SimpleClassOfNumNullable( this.value, - this.nullable, ); - factory SimpleClassNum.fromJson(Map json) => - _$SimpleClassNumFromJson(json); + factory SimpleClassOfNumNullable.fromJson(Map json) => + _$SimpleClassOfNumNullableFromJson(json); - Map toJson() => _$SimpleClassNumToJson(this); + Map toJson() => _$SimpleClassOfNumNullableToJson(this); } @JsonSerializable() -class SimpleClassObject { +class SimpleClassNullableOfNumNullable { + final List? value; + + SimpleClassNullableOfNumNullable( + this.value, + ); + + factory SimpleClassNullableOfNumNullable.fromJson( + Map json) => + _$SimpleClassNullableOfNumNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfNumNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfObject { final List value; - @JsonKey(nullable: false) - final List nullable; + SimpleClassOfObject( + this.value, + ); + + factory SimpleClassOfObject.fromJson(Map json) => + _$SimpleClassOfObjectFromJson(json); + + Map toJson() => _$SimpleClassOfObjectToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfObject { + final List? value; + + SimpleClassNullableOfObject( + this.value, + ); + + factory SimpleClassNullableOfObject.fromJson(Map json) => + _$SimpleClassNullableOfObjectFromJson(json); + + Map toJson() => _$SimpleClassNullableOfObjectToJson(this); +} + +@JsonSerializable() +class SimpleClassOfObjectNullable { + final List value; + + SimpleClassOfObjectNullable( + this.value, + ); + + factory SimpleClassOfObjectNullable.fromJson(Map json) => + _$SimpleClassOfObjectNullableFromJson(json); + + Map toJson() => _$SimpleClassOfObjectNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfObjectNullable { + final List? value; - SimpleClassObject( + SimpleClassNullableOfObjectNullable( this.value, - this.nullable, ); - factory SimpleClassObject.fromJson(Map json) => - _$SimpleClassObjectFromJson(json); + factory SimpleClassNullableOfObjectNullable.fromJson( + Map json) => + _$SimpleClassNullableOfObjectNullableFromJson(json); - Map toJson() => _$SimpleClassObjectToJson(this); + Map toJson() => + _$SimpleClassNullableOfObjectNullableToJson(this); } @JsonSerializable() -class SimpleClassString { +class SimpleClassOfString { final List value; - @JsonKey(nullable: false) - final List nullable; + SimpleClassOfString( + this.value, + ); + + factory SimpleClassOfString.fromJson(Map json) => + _$SimpleClassOfStringFromJson(json); + + Map toJson() => _$SimpleClassOfStringToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfString { + final List? value; + + SimpleClassNullableOfString( + this.value, + ); + + factory SimpleClassNullableOfString.fromJson(Map json) => + _$SimpleClassNullableOfStringFromJson(json); + + Map toJson() => _$SimpleClassNullableOfStringToJson(this); +} + +@JsonSerializable() +class SimpleClassOfStringNullable { + final List value; - SimpleClassString( + SimpleClassOfStringNullable( this.value, - this.nullable, ); - factory SimpleClassString.fromJson(Map json) => - _$SimpleClassStringFromJson(json); + factory SimpleClassOfStringNullable.fromJson(Map json) => + _$SimpleClassOfStringNullableFromJson(json); - Map toJson() => _$SimpleClassStringToJson(this); + Map toJson() => _$SimpleClassOfStringNullableToJson(this); } @JsonSerializable() -class SimpleClassUri { +class SimpleClassNullableOfStringNullable { + final List? value; + + SimpleClassNullableOfStringNullable( + this.value, + ); + + factory SimpleClassNullableOfStringNullable.fromJson( + Map json) => + _$SimpleClassNullableOfStringNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfStringNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfUri { final List value; - @JsonKey(nullable: false) - final List nullable; + SimpleClassOfUri( + this.value, + ); + + factory SimpleClassOfUri.fromJson(Map json) => + _$SimpleClassOfUriFromJson(json); + + Map toJson() => _$SimpleClassOfUriToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfUri { + final List? value; + + SimpleClassNullableOfUri( + this.value, + ); + + factory SimpleClassNullableOfUri.fromJson(Map json) => + _$SimpleClassNullableOfUriFromJson(json); + + Map toJson() => _$SimpleClassNullableOfUriToJson(this); +} + +@JsonSerializable() +class SimpleClassOfUriNullable { + final List value; + + SimpleClassOfUriNullable( + this.value, + ); + + factory SimpleClassOfUriNullable.fromJson(Map json) => + _$SimpleClassOfUriNullableFromJson(json); + + Map toJson() => _$SimpleClassOfUriNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfUriNullable { + final List? value; - SimpleClassUri( + SimpleClassNullableOfUriNullable( this.value, - this.nullable, ); - factory SimpleClassUri.fromJson(Map json) => - _$SimpleClassUriFromJson(json); + factory SimpleClassNullableOfUriNullable.fromJson( + Map json) => + _$SimpleClassNullableOfUriNullableFromJson(json); - Map toJson() => _$SimpleClassUriToJson(this); + Map toJson() => + _$SimpleClassNullableOfUriNullableToJson(this); } diff --git a/json_serializable/test/supported_types/input.type_list.g.dart b/json_serializable/test/supported_types/input.type_list.g.dart index bcedf4688..9c1b1a63c 100644 --- a/json_serializable/test/supported_types/input.type_list.g.dart +++ b/json_serializable/test/supported_types/input.type_list.g.dart @@ -1,4 +1,5 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// @dart=2.12 part of 'input.type_list.dart'; @@ -8,226 +9,702 @@ part of 'input.type_list.dart'; SimpleClass _$SimpleClassFromJson(Map json) { return SimpleClass( - json['value'] as List, - json['nullable'] as List, - )..withDefault = json['withDefault'] as List ?? [42, true, false, null]; + json['value'] as List, + json['withDefault'] as List? ?? [42, true, false, null], + ); } Map _$SimpleClassToJson(SimpleClass instance) => { 'value': instance.value, - 'nullable': instance.nullable, 'withDefault': instance.withDefault, }; -SimpleClassBigInt _$SimpleClassBigIntFromJson(Map json) { - return SimpleClassBigInt( - (json['value'] as List) +SimpleClassNullable _$SimpleClassNullableFromJson(Map json) { + return SimpleClassNullable( + json['value'] as List?, + json['withDefault'] as List? ?? [42, true, false, null], + ); +} + +Map _$SimpleClassNullableToJson( + SimpleClassNullable instance) => + { + 'value': instance.value, + 'withDefault': instance.withDefault, + }; + +SimpleClassOfBigInt _$SimpleClassOfBigIntFromJson(Map json) { + return SimpleClassOfBigInt( + (json['value'] as List) + .map((e) => BigInt.parse(e as String)) + .toList(), + ); +} + +Map _$SimpleClassOfBigIntToJson( + SimpleClassOfBigInt instance) => + { + 'value': instance.value.map((e) => e.toString()).toList(), + }; + +SimpleClassNullableOfBigInt _$SimpleClassNullableOfBigIntFromJson( + Map json) { + return SimpleClassNullableOfBigInt( + (json['value'] as List?) + ?.map((e) => BigInt.parse(e as String)) + .toList(), + ); +} + +Map _$SimpleClassNullableOfBigIntToJson( + SimpleClassNullableOfBigInt instance) => + { + 'value': instance.value?.map((e) => e.toString()).toList(), + }; + +SimpleClassOfBigIntNullable _$SimpleClassOfBigIntNullableFromJson( + Map json) { + return SimpleClassOfBigIntNullable( + (json['value'] as List) + .map((e) => e == null ? null : BigInt.parse(e as String)) + .toList(), + ); +} + +Map _$SimpleClassOfBigIntNullableToJson( + SimpleClassOfBigIntNullable instance) => + { + 'value': instance.value.map((e) => e?.toString()).toList(), + }; + +SimpleClassNullableOfBigIntNullable + _$SimpleClassNullableOfBigIntNullableFromJson(Map json) { + return SimpleClassNullableOfBigIntNullable( + (json['value'] as List?) ?.map((e) => e == null ? null : BigInt.parse(e as String)) - ?.toList(), - (json['nullable'] as List).map((e) => BigInt.parse(e as String)).toList(), + .toList(), + ); +} + +Map _$SimpleClassNullableOfBigIntNullableToJson( + SimpleClassNullableOfBigIntNullable instance) => + { + 'value': instance.value?.map((e) => e?.toString()).toList(), + }; + +SimpleClassOfBool _$SimpleClassOfBoolFromJson(Map json) { + return SimpleClassOfBool( + (json['value'] as List).map((e) => e as bool).toList(), + ); +} + +Map _$SimpleClassOfBoolToJson(SimpleClassOfBool instance) => + { + 'value': instance.value, + }; + +SimpleClassNullableOfBool _$SimpleClassNullableOfBoolFromJson( + Map json) { + return SimpleClassNullableOfBool( + (json['value'] as List?)?.map((e) => e as bool).toList(), + ); +} + +Map _$SimpleClassNullableOfBoolToJson( + SimpleClassNullableOfBool instance) => + { + 'value': instance.value, + }; + +SimpleClassOfBoolNullable _$SimpleClassOfBoolNullableFromJson( + Map json) { + return SimpleClassOfBoolNullable( + (json['value'] as List).map((e) => e as bool?).toList(), ); } -Map _$SimpleClassBigIntToJson(SimpleClassBigInt instance) => +Map _$SimpleClassOfBoolNullableToJson( + SimpleClassOfBoolNullable instance) => { - 'value': instance.value?.map((e) => e?.toString())?.toList(), - 'nullable': instance.nullable.map((e) => e.toString()).toList(), + 'value': instance.value, }; -SimpleClassBool _$SimpleClassBoolFromJson(Map json) { - return SimpleClassBool( - (json['value'] as List)?.map((e) => e as bool)?.toList(), - (json['nullable'] as List).map((e) => e as bool).toList(), +SimpleClassNullableOfBoolNullable _$SimpleClassNullableOfBoolNullableFromJson( + Map json) { + return SimpleClassNullableOfBoolNullable( + (json['value'] as List?)?.map((e) => e as bool?).toList(), ); } -Map _$SimpleClassBoolToJson(SimpleClassBool instance) => +Map _$SimpleClassNullableOfBoolNullableToJson( + SimpleClassNullableOfBoolNullable instance) => { 'value': instance.value, - 'nullable': instance.nullable, }; -SimpleClassDateTime _$SimpleClassDateTimeFromJson(Map json) { - return SimpleClassDateTime( - (json['value'] as List) +SimpleClassOfDateTime _$SimpleClassOfDateTimeFromJson( + Map json) { + return SimpleClassOfDateTime( + (json['value'] as List) + .map((e) => DateTime.parse(e as String)) + .toList(), + ); +} + +Map _$SimpleClassOfDateTimeToJson( + SimpleClassOfDateTime instance) => + { + 'value': instance.value.map((e) => e.toIso8601String()).toList(), + }; + +SimpleClassNullableOfDateTime _$SimpleClassNullableOfDateTimeFromJson( + Map json) { + return SimpleClassNullableOfDateTime( + (json['value'] as List?) + ?.map((e) => DateTime.parse(e as String)) + .toList(), + ); +} + +Map _$SimpleClassNullableOfDateTimeToJson( + SimpleClassNullableOfDateTime instance) => + { + 'value': instance.value?.map((e) => e.toIso8601String()).toList(), + }; + +SimpleClassOfDateTimeNullable _$SimpleClassOfDateTimeNullableFromJson( + Map json) { + return SimpleClassOfDateTimeNullable( + (json['value'] as List) + .map((e) => e == null ? null : DateTime.parse(e as String)) + .toList(), + ); +} + +Map _$SimpleClassOfDateTimeNullableToJson( + SimpleClassOfDateTimeNullable instance) => + { + 'value': instance.value.map((e) => e?.toIso8601String()).toList(), + }; + +SimpleClassNullableOfDateTimeNullable + _$SimpleClassNullableOfDateTimeNullableFromJson(Map json) { + return SimpleClassNullableOfDateTimeNullable( + (json['value'] as List?) ?.map((e) => e == null ? null : DateTime.parse(e as String)) - ?.toList(), - (json['nullable'] as List).map((e) => DateTime.parse(e as String)).toList(), + .toList(), ); } -Map _$SimpleClassDateTimeToJson( - SimpleClassDateTime instance) => +Map _$SimpleClassNullableOfDateTimeNullableToJson( + SimpleClassNullableOfDateTimeNullable instance) => { - 'value': instance.value?.map((e) => e?.toIso8601String())?.toList(), - 'nullable': instance.nullable.map((e) => e.toIso8601String()).toList(), + 'value': instance.value?.map((e) => e?.toIso8601String()).toList(), }; -SimpleClassDouble _$SimpleClassDoubleFromJson(Map json) { - return SimpleClassDouble( - (json['value'] as List)?.map((e) => (e as num)?.toDouble())?.toList(), - (json['nullable'] as List).map((e) => (e as num).toDouble()).toList(), +SimpleClassOfDouble _$SimpleClassOfDoubleFromJson(Map json) { + return SimpleClassOfDouble( + (json['value'] as List).map((e) => (e as num).toDouble()).toList(), ); } -Map _$SimpleClassDoubleToJson(SimpleClassDouble instance) => +Map _$SimpleClassOfDoubleToJson( + SimpleClassOfDouble instance) => { 'value': instance.value, - 'nullable': instance.nullable, }; -SimpleClassDuration _$SimpleClassDurationFromJson(Map json) { - return SimpleClassDuration( - (json['value'] as List) - ?.map((e) => e == null ? null : Duration(microseconds: e as int)) - ?.toList(), - (json['nullable'] as List) +SimpleClassNullableOfDouble _$SimpleClassNullableOfDoubleFromJson( + Map json) { + return SimpleClassNullableOfDouble( + (json['value'] as List?) + ?.map((e) => (e as num).toDouble()) + .toList(), + ); +} + +Map _$SimpleClassNullableOfDoubleToJson( + SimpleClassNullableOfDouble instance) => + { + 'value': instance.value, + }; + +SimpleClassOfDoubleNullable _$SimpleClassOfDoubleNullableFromJson( + Map json) { + return SimpleClassOfDoubleNullable( + (json['value'] as List) + .map((e) => (e as num?)?.toDouble()) + .toList(), + ); +} + +Map _$SimpleClassOfDoubleNullableToJson( + SimpleClassOfDoubleNullable instance) => + { + 'value': instance.value, + }; + +SimpleClassNullableOfDoubleNullable + _$SimpleClassNullableOfDoubleNullableFromJson(Map json) { + return SimpleClassNullableOfDoubleNullable( + (json['value'] as List?) + ?.map((e) => (e as num?)?.toDouble()) + .toList(), + ); +} + +Map _$SimpleClassNullableOfDoubleNullableToJson( + SimpleClassNullableOfDoubleNullable instance) => + { + 'value': instance.value, + }; + +SimpleClassOfDuration _$SimpleClassOfDurationFromJson( + Map json) { + return SimpleClassOfDuration( + (json['value'] as List) .map((e) => Duration(microseconds: e as int)) .toList(), ); } -Map _$SimpleClassDurationToJson( - SimpleClassDuration instance) => +Map _$SimpleClassOfDurationToJson( + SimpleClassOfDuration instance) => { - 'value': instance.value?.map((e) => e?.inMicroseconds)?.toList(), - 'nullable': instance.nullable.map((e) => e.inMicroseconds).toList(), + 'value': instance.value.map((e) => e.inMicroseconds).toList(), }; -SimpleClassDynamic _$SimpleClassDynamicFromJson(Map json) { - return SimpleClassDynamic( - json['value'] as List, - json['nullable'] as List, +SimpleClassNullableOfDuration _$SimpleClassNullableOfDurationFromJson( + Map json) { + return SimpleClassNullableOfDuration( + (json['value'] as List?) + ?.map((e) => Duration(microseconds: e as int)) + .toList(), ); } -Map _$SimpleClassDynamicToJson(SimpleClassDynamic instance) => +Map _$SimpleClassNullableOfDurationToJson( + SimpleClassNullableOfDuration instance) => + { + 'value': instance.value?.map((e) => e.inMicroseconds).toList(), + }; + +SimpleClassOfDurationNullable _$SimpleClassOfDurationNullableFromJson( + Map json) { + return SimpleClassOfDurationNullable( + (json['value'] as List) + .map((e) => e == null ? null : Duration(microseconds: e as int)) + .toList(), + ); +} + +Map _$SimpleClassOfDurationNullableToJson( + SimpleClassOfDurationNullable instance) => + { + 'value': instance.value.map((e) => e?.inMicroseconds).toList(), + }; + +SimpleClassNullableOfDurationNullable + _$SimpleClassNullableOfDurationNullableFromJson(Map json) { + return SimpleClassNullableOfDurationNullable( + (json['value'] as List?) + ?.map((e) => e == null ? null : Duration(microseconds: e as int)) + .toList(), + ); +} + +Map _$SimpleClassNullableOfDurationNullableToJson( + SimpleClassNullableOfDurationNullable instance) => + { + 'value': instance.value?.map((e) => e?.inMicroseconds).toList(), + }; + +SimpleClassOfDynamic _$SimpleClassOfDynamicFromJson(Map json) { + return SimpleClassOfDynamic( + json['value'] as List, + ); +} + +Map _$SimpleClassOfDynamicToJson( + SimpleClassOfDynamic instance) => { 'value': instance.value, - 'nullable': instance.nullable, }; -SimpleClassEnumType _$SimpleClassEnumTypeFromJson(Map json) { - return SimpleClassEnumType( - (json['value'] as List) - ?.map((e) => _$enumDecodeNullable(_$EnumTypeEnumMap, e)) - ?.toList(), - (json['nullable'] as List) +SimpleClassNullableOfDynamic _$SimpleClassNullableOfDynamicFromJson( + Map json) { + return SimpleClassNullableOfDynamic( + json['value'] as List?, + ); +} + +Map _$SimpleClassNullableOfDynamicToJson( + SimpleClassNullableOfDynamic instance) => + { + 'value': instance.value, + }; + +SimpleClassOfEnumType _$SimpleClassOfEnumTypeFromJson( + Map json) { + return SimpleClassOfEnumType( + (json['value'] as List) .map((e) => _$enumDecode(_$EnumTypeEnumMap, e)) .toList(), ); } -Map _$SimpleClassEnumTypeToJson( - SimpleClassEnumType instance) => +Map _$SimpleClassOfEnumTypeToJson( + SimpleClassOfEnumType instance) => { - 'value': instance.value?.map((e) => _$EnumTypeEnumMap[e])?.toList(), - 'nullable': instance.nullable.map((e) => _$EnumTypeEnumMap[e]).toList(), + 'value': instance.value.map((e) => _$EnumTypeEnumMap[e]).toList(), }; -T _$enumDecode( - Map enumValues, - dynamic source, { - T unknownValue, +K _$enumDecode( + Map enumValues, + Object? source, { + K? unknownValue, }) { if (source == null) { - throw ArgumentError('A value must be provided. Supported values: ' - '${enumValues.values.join(', ')}'); + throw ArgumentError( + 'A value must be provided. Supported values: ' + '${enumValues.values.join(', ')}', + ); } - final value = enumValues.entries - .singleWhere((e) => e.value == source, orElse: () => null) - ?.key; + return enumValues.entries.singleWhere( + (e) => e.value == source, + orElse: () { + if (unknownValue == null) { + throw ArgumentError( + '`$source` is not one of the supported values: ' + '${enumValues.values.join(', ')}', + ); + } + return MapEntry(unknownValue, enumValues.values.first); + }, + ).key; +} - if (value == null && unknownValue == null) { - throw ArgumentError('`$source` is not one of the supported values: ' - '${enumValues.values.join(', ')}'); - } - return value ?? unknownValue; +const _$EnumTypeEnumMap = { + EnumType.alpha: 'alpha', + EnumType.beta: 'beta', + EnumType.gamma: 'gamma', + EnumType.delta: 'delta', +}; + +SimpleClassNullableOfEnumType _$SimpleClassNullableOfEnumTypeFromJson( + Map json) { + return SimpleClassNullableOfEnumType( + (json['value'] as List?) + ?.map((e) => _$enumDecode(_$EnumTypeEnumMap, e)) + .toList(), + ); } -T _$enumDecodeNullable( - Map enumValues, +Map _$SimpleClassNullableOfEnumTypeToJson( + SimpleClassNullableOfEnumType instance) => + { + 'value': instance.value?.map((e) => _$EnumTypeEnumMap[e]).toList(), + }; + +SimpleClassOfEnumTypeNullable _$SimpleClassOfEnumTypeNullableFromJson( + Map json) { + return SimpleClassOfEnumTypeNullable( + (json['value'] as List) + .map((e) => _$enumDecodeNullable(_$EnumTypeEnumMap, e)) + .toList(), + ); +} + +Map _$SimpleClassOfEnumTypeNullableToJson( + SimpleClassOfEnumTypeNullable instance) => + { + 'value': instance.value.map((e) => _$EnumTypeEnumMap[e]).toList(), + }; + +K? _$enumDecodeNullable( + Map enumValues, dynamic source, { - T unknownValue, + K? unknownValue, }) { if (source == null) { return null; } - return _$enumDecode(enumValues, source, unknownValue: unknownValue); + return _$enumDecode(enumValues, source, unknownValue: unknownValue); } -const _$EnumTypeEnumMap = { - EnumType.alpha: 'alpha', - EnumType.beta: 'beta', - EnumType.gamma: 'gamma', - EnumType.delta: 'delta', -}; +SimpleClassNullableOfEnumTypeNullable + _$SimpleClassNullableOfEnumTypeNullableFromJson(Map json) { + return SimpleClassNullableOfEnumTypeNullable( + (json['value'] as List?) + ?.map((e) => _$enumDecodeNullable(_$EnumTypeEnumMap, e)) + .toList(), + ); +} + +Map _$SimpleClassNullableOfEnumTypeNullableToJson( + SimpleClassNullableOfEnumTypeNullable instance) => + { + 'value': instance.value?.map((e) => _$EnumTypeEnumMap[e]).toList(), + }; + +SimpleClassOfInt _$SimpleClassOfIntFromJson(Map json) { + return SimpleClassOfInt( + (json['value'] as List).map((e) => e as int).toList(), + ); +} + +Map _$SimpleClassOfIntToJson(SimpleClassOfInt instance) => + { + 'value': instance.value, + }; + +SimpleClassNullableOfInt _$SimpleClassNullableOfIntFromJson( + Map json) { + return SimpleClassNullableOfInt( + (json['value'] as List?)?.map((e) => e as int).toList(), + ); +} + +Map _$SimpleClassNullableOfIntToJson( + SimpleClassNullableOfInt instance) => + { + 'value': instance.value, + }; + +SimpleClassOfIntNullable _$SimpleClassOfIntNullableFromJson( + Map json) { + return SimpleClassOfIntNullable( + (json['value'] as List).map((e) => e as int?).toList(), + ); +} + +Map _$SimpleClassOfIntNullableToJson( + SimpleClassOfIntNullable instance) => + { + 'value': instance.value, + }; + +SimpleClassNullableOfIntNullable _$SimpleClassNullableOfIntNullableFromJson( + Map json) { + return SimpleClassNullableOfIntNullable( + (json['value'] as List?)?.map((e) => e as int?).toList(), + ); +} -SimpleClassInt _$SimpleClassIntFromJson(Map json) { - return SimpleClassInt( - (json['value'] as List)?.map((e) => e as int)?.toList(), - (json['nullable'] as List).map((e) => e as int).toList(), +Map _$SimpleClassNullableOfIntNullableToJson( + SimpleClassNullableOfIntNullable instance) => + { + 'value': instance.value, + }; + +SimpleClassOfNum _$SimpleClassOfNumFromJson(Map json) { + return SimpleClassOfNum( + (json['value'] as List).map((e) => e as num).toList(), ); } -Map _$SimpleClassIntToJson(SimpleClassInt instance) => +Map _$SimpleClassOfNumToJson(SimpleClassOfNum instance) => { 'value': instance.value, - 'nullable': instance.nullable, }; -SimpleClassNum _$SimpleClassNumFromJson(Map json) { - return SimpleClassNum( - (json['value'] as List)?.map((e) => e as num)?.toList(), - (json['nullable'] as List).map((e) => e as num).toList(), +SimpleClassNullableOfNum _$SimpleClassNullableOfNumFromJson( + Map json) { + return SimpleClassNullableOfNum( + (json['value'] as List?)?.map((e) => e as num).toList(), ); } -Map _$SimpleClassNumToJson(SimpleClassNum instance) => +Map _$SimpleClassNullableOfNumToJson( + SimpleClassNullableOfNum instance) => { 'value': instance.value, - 'nullable': instance.nullable, }; -SimpleClassObject _$SimpleClassObjectFromJson(Map json) { - return SimpleClassObject( - json['value'] as List, - json['nullable'] as List, +SimpleClassOfNumNullable _$SimpleClassOfNumNullableFromJson( + Map json) { + return SimpleClassOfNumNullable( + (json['value'] as List).map((e) => e as num?).toList(), ); } -Map _$SimpleClassObjectToJson(SimpleClassObject instance) => +Map _$SimpleClassOfNumNullableToJson( + SimpleClassOfNumNullable instance) => { 'value': instance.value, - 'nullable': instance.nullable, }; -SimpleClassString _$SimpleClassStringFromJson(Map json) { - return SimpleClassString( - (json['value'] as List)?.map((e) => e as String)?.toList(), - (json['nullable'] as List).map((e) => e as String).toList(), +SimpleClassNullableOfNumNullable _$SimpleClassNullableOfNumNullableFromJson( + Map json) { + return SimpleClassNullableOfNumNullable( + (json['value'] as List?)?.map((e) => e as num?).toList(), ); } -Map _$SimpleClassStringToJson(SimpleClassString instance) => +Map _$SimpleClassNullableOfNumNullableToJson( + SimpleClassNullableOfNumNullable instance) => { 'value': instance.value, - 'nullable': instance.nullable, }; -SimpleClassUri _$SimpleClassUriFromJson(Map json) { - return SimpleClassUri( - (json['value'] as List) +SimpleClassOfObject _$SimpleClassOfObjectFromJson(Map json) { + return SimpleClassOfObject( + (json['value'] as List).map((e) => e as Object).toList(), + ); +} + +Map _$SimpleClassOfObjectToJson( + SimpleClassOfObject instance) => + { + 'value': instance.value, + }; + +SimpleClassNullableOfObject _$SimpleClassNullableOfObjectFromJson( + Map json) { + return SimpleClassNullableOfObject( + (json['value'] as List?)?.map((e) => e as Object).toList(), + ); +} + +Map _$SimpleClassNullableOfObjectToJson( + SimpleClassNullableOfObject instance) => + { + 'value': instance.value, + }; + +SimpleClassOfObjectNullable _$SimpleClassOfObjectNullableFromJson( + Map json) { + return SimpleClassOfObjectNullable( + json['value'] as List, + ); +} + +Map _$SimpleClassOfObjectNullableToJson( + SimpleClassOfObjectNullable instance) => + { + 'value': instance.value, + }; + +SimpleClassNullableOfObjectNullable + _$SimpleClassNullableOfObjectNullableFromJson(Map json) { + return SimpleClassNullableOfObjectNullable( + json['value'] as List?, + ); +} + +Map _$SimpleClassNullableOfObjectNullableToJson( + SimpleClassNullableOfObjectNullable instance) => + { + 'value': instance.value, + }; + +SimpleClassOfString _$SimpleClassOfStringFromJson(Map json) { + return SimpleClassOfString( + (json['value'] as List).map((e) => e as String).toList(), + ); +} + +Map _$SimpleClassOfStringToJson( + SimpleClassOfString instance) => + { + 'value': instance.value, + }; + +SimpleClassNullableOfString _$SimpleClassNullableOfStringFromJson( + Map json) { + return SimpleClassNullableOfString( + (json['value'] as List?)?.map((e) => e as String).toList(), + ); +} + +Map _$SimpleClassNullableOfStringToJson( + SimpleClassNullableOfString instance) => + { + 'value': instance.value, + }; + +SimpleClassOfStringNullable _$SimpleClassOfStringNullableFromJson( + Map json) { + return SimpleClassOfStringNullable( + (json['value'] as List).map((e) => e as String?).toList(), + ); +} + +Map _$SimpleClassOfStringNullableToJson( + SimpleClassOfStringNullable instance) => + { + 'value': instance.value, + }; + +SimpleClassNullableOfStringNullable + _$SimpleClassNullableOfStringNullableFromJson(Map json) { + return SimpleClassNullableOfStringNullable( + (json['value'] as List?)?.map((e) => e as String?).toList(), + ); +} + +Map _$SimpleClassNullableOfStringNullableToJson( + SimpleClassNullableOfStringNullable instance) => + { + 'value': instance.value, + }; + +SimpleClassOfUri _$SimpleClassOfUriFromJson(Map json) { + return SimpleClassOfUri( + (json['value'] as List) + .map((e) => Uri.parse(e as String)) + .toList(), + ); +} + +Map _$SimpleClassOfUriToJson(SimpleClassOfUri instance) => + { + 'value': instance.value.map((e) => e.toString()).toList(), + }; + +SimpleClassNullableOfUri _$SimpleClassNullableOfUriFromJson( + Map json) { + return SimpleClassNullableOfUri( + (json['value'] as List?) + ?.map((e) => Uri.parse(e as String)) + .toList(), + ); +} + +Map _$SimpleClassNullableOfUriToJson( + SimpleClassNullableOfUri instance) => + { + 'value': instance.value?.map((e) => e.toString()).toList(), + }; + +SimpleClassOfUriNullable _$SimpleClassOfUriNullableFromJson( + Map json) { + return SimpleClassOfUriNullable( + (json['value'] as List) + .map((e) => e == null ? null : Uri.parse(e as String)) + .toList(), + ); +} + +Map _$SimpleClassOfUriNullableToJson( + SimpleClassOfUriNullable instance) => + { + 'value': instance.value.map((e) => e?.toString()).toList(), + }; + +SimpleClassNullableOfUriNullable _$SimpleClassNullableOfUriNullableFromJson( + Map json) { + return SimpleClassNullableOfUriNullable( + (json['value'] as List?) ?.map((e) => e == null ? null : Uri.parse(e as String)) - ?.toList(), - (json['nullable'] as List).map((e) => Uri.parse(e as String)).toList(), + .toList(), ); } -Map _$SimpleClassUriToJson(SimpleClassUri instance) => +Map _$SimpleClassNullableOfUriNullableToJson( + SimpleClassNullableOfUriNullable instance) => { - 'value': instance.value?.map((e) => e?.toString())?.toList(), - 'nullable': instance.nullable.map((e) => e.toString()).toList(), + 'value': instance.value?.map((e) => e?.toString()).toList(), }; diff --git a/json_serializable/test/supported_types/input.type_map.dart b/json_serializable/test/supported_types/input.type_map.dart index 8b351b6fc..74243a4b1 100644 --- a/json_serializable/test/supported_types/input.type_map.dart +++ b/json_serializable/test/supported_types/input.type_map.dart @@ -2,6 +2,8 @@ // 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. +// @dart=2.12 + import 'package:json_annotation/json_annotation.dart'; import 'enum_type.dart'; @@ -11,1747 +13,5704 @@ part 'input.type_map.g.dart'; class SimpleClass { final Map value; - @JsonKey(nullable: false) - final Map nullable; - @JsonKey(defaultValue: {'a': 1}) Map withDefault; SimpleClass( this.value, - this.nullable, + this.withDefault, ); - factory SimpleClass.fromJson(Map json) => + factory SimpleClass.fromJson(Map json) => _$SimpleClassFromJson(json); - Map toJson() => _$SimpleClassToJson(this); + Map toJson() => _$SimpleClassToJson(this); +} + +@JsonSerializable() +class SimpleClassNullable { + final Map? value; + + @JsonKey(defaultValue: {'a': 1}) + Map? withDefault; + + SimpleClassNullable( + this.value, + this.withDefault, + ); + + factory SimpleClassNullable.fromJson(Map json) => + _$SimpleClassNullableFromJson(json); + + Map toJson() => _$SimpleClassNullableToJson(this); } @JsonSerializable() -class SimpleClassBigIntToBigInt { +class SimpleClassOfBigIntToBigInt { final Map value; - @JsonKey(nullable: false) - final Map nullable; + SimpleClassOfBigIntToBigInt( + this.value, + ); + + factory SimpleClassOfBigIntToBigInt.fromJson(Map json) => + _$SimpleClassOfBigIntToBigIntFromJson(json); + + Map toJson() => _$SimpleClassOfBigIntToBigIntToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfBigIntToBigInt { + final Map? value; - SimpleClassBigIntToBigInt( + SimpleClassNullableOfBigIntToBigInt( this.value, - this.nullable, ); - factory SimpleClassBigIntToBigInt.fromJson(Map json) => - _$SimpleClassBigIntToBigIntFromJson(json); + factory SimpleClassNullableOfBigIntToBigInt.fromJson( + Map json) => + _$SimpleClassNullableOfBigIntToBigIntFromJson(json); - Map toJson() => _$SimpleClassBigIntToBigIntToJson(this); + Map toJson() => + _$SimpleClassNullableOfBigIntToBigIntToJson(this); } @JsonSerializable() -class SimpleClassDateTimeToBigInt { +class SimpleClassOfDateTimeToBigInt { final Map value; - @JsonKey(nullable: false) - final Map nullable; + SimpleClassOfDateTimeToBigInt( + this.value, + ); + + factory SimpleClassOfDateTimeToBigInt.fromJson(Map json) => + _$SimpleClassOfDateTimeToBigIntFromJson(json); + + Map toJson() => _$SimpleClassOfDateTimeToBigIntToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfDateTimeToBigInt { + final Map? value; - SimpleClassDateTimeToBigInt( + SimpleClassNullableOfDateTimeToBigInt( this.value, - this.nullable, ); - factory SimpleClassDateTimeToBigInt.fromJson(Map json) => - _$SimpleClassDateTimeToBigIntFromJson(json); + factory SimpleClassNullableOfDateTimeToBigInt.fromJson( + Map json) => + _$SimpleClassNullableOfDateTimeToBigIntFromJson(json); - Map toJson() => _$SimpleClassDateTimeToBigIntToJson(this); + Map toJson() => + _$SimpleClassNullableOfDateTimeToBigIntToJson(this); } @JsonSerializable() -class SimpleClassDynamicToBigInt { +class SimpleClassOfDynamicToBigInt { final Map value; - @JsonKey(nullable: false) - final Map nullable; + SimpleClassOfDynamicToBigInt( + this.value, + ); + + factory SimpleClassOfDynamicToBigInt.fromJson(Map json) => + _$SimpleClassOfDynamicToBigIntFromJson(json); + + Map toJson() => _$SimpleClassOfDynamicToBigIntToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfDynamicToBigInt { + final Map? value; - SimpleClassDynamicToBigInt( + SimpleClassNullableOfDynamicToBigInt( this.value, - this.nullable, ); - factory SimpleClassDynamicToBigInt.fromJson(Map json) => - _$SimpleClassDynamicToBigIntFromJson(json); + factory SimpleClassNullableOfDynamicToBigInt.fromJson( + Map json) => + _$SimpleClassNullableOfDynamicToBigIntFromJson(json); - Map toJson() => _$SimpleClassDynamicToBigIntToJson(this); + Map toJson() => + _$SimpleClassNullableOfDynamicToBigIntToJson(this); } @JsonSerializable() -class SimpleClassEnumTypeToBigInt { +class SimpleClassOfEnumTypeToBigInt { final Map value; - @JsonKey(nullable: false) - final Map nullable; + SimpleClassOfEnumTypeToBigInt( + this.value, + ); + + factory SimpleClassOfEnumTypeToBigInt.fromJson(Map json) => + _$SimpleClassOfEnumTypeToBigIntFromJson(json); + + Map toJson() => _$SimpleClassOfEnumTypeToBigIntToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfEnumTypeToBigInt { + final Map? value; - SimpleClassEnumTypeToBigInt( + SimpleClassNullableOfEnumTypeToBigInt( this.value, - this.nullable, ); - factory SimpleClassEnumTypeToBigInt.fromJson(Map json) => - _$SimpleClassEnumTypeToBigIntFromJson(json); + factory SimpleClassNullableOfEnumTypeToBigInt.fromJson( + Map json) => + _$SimpleClassNullableOfEnumTypeToBigIntFromJson(json); - Map toJson() => _$SimpleClassEnumTypeToBigIntToJson(this); + Map toJson() => + _$SimpleClassNullableOfEnumTypeToBigIntToJson(this); } @JsonSerializable() -class SimpleClassIntToBigInt { +class SimpleClassOfIntToBigInt { final Map value; - @JsonKey(nullable: false) - final Map nullable; + SimpleClassOfIntToBigInt( + this.value, + ); + + factory SimpleClassOfIntToBigInt.fromJson(Map json) => + _$SimpleClassOfIntToBigIntFromJson(json); + + Map toJson() => _$SimpleClassOfIntToBigIntToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfIntToBigInt { + final Map? value; - SimpleClassIntToBigInt( + SimpleClassNullableOfIntToBigInt( this.value, - this.nullable, ); - factory SimpleClassIntToBigInt.fromJson(Map json) => - _$SimpleClassIntToBigIntFromJson(json); + factory SimpleClassNullableOfIntToBigInt.fromJson( + Map json) => + _$SimpleClassNullableOfIntToBigIntFromJson(json); - Map toJson() => _$SimpleClassIntToBigIntToJson(this); + Map toJson() => + _$SimpleClassNullableOfIntToBigIntToJson(this); } @JsonSerializable() -class SimpleClassObjectToBigInt { +class SimpleClassOfObjectToBigInt { final Map value; - @JsonKey(nullable: false) - final Map nullable; + SimpleClassOfObjectToBigInt( + this.value, + ); + + factory SimpleClassOfObjectToBigInt.fromJson(Map json) => + _$SimpleClassOfObjectToBigIntFromJson(json); + + Map toJson() => _$SimpleClassOfObjectToBigIntToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfObjectToBigInt { + final Map? value; - SimpleClassObjectToBigInt( + SimpleClassNullableOfObjectToBigInt( this.value, - this.nullable, ); - factory SimpleClassObjectToBigInt.fromJson(Map json) => - _$SimpleClassObjectToBigIntFromJson(json); + factory SimpleClassNullableOfObjectToBigInt.fromJson( + Map json) => + _$SimpleClassNullableOfObjectToBigIntFromJson(json); - Map toJson() => _$SimpleClassObjectToBigIntToJson(this); + Map toJson() => + _$SimpleClassNullableOfObjectToBigIntToJson(this); } @JsonSerializable() -class SimpleClassStringToBigInt { +class SimpleClassOfStringToBigInt { final Map value; - @JsonKey(nullable: false) - final Map nullable; + SimpleClassOfStringToBigInt( + this.value, + ); + + factory SimpleClassOfStringToBigInt.fromJson(Map json) => + _$SimpleClassOfStringToBigIntFromJson(json); + + Map toJson() => _$SimpleClassOfStringToBigIntToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfStringToBigInt { + final Map? value; - SimpleClassStringToBigInt( + SimpleClassNullableOfStringToBigInt( this.value, - this.nullable, ); - factory SimpleClassStringToBigInt.fromJson(Map json) => - _$SimpleClassStringToBigIntFromJson(json); + factory SimpleClassNullableOfStringToBigInt.fromJson( + Map json) => + _$SimpleClassNullableOfStringToBigIntFromJson(json); - Map toJson() => _$SimpleClassStringToBigIntToJson(this); + Map toJson() => + _$SimpleClassNullableOfStringToBigIntToJson(this); } @JsonSerializable() -class SimpleClassUriToBigInt { +class SimpleClassOfUriToBigInt { final Map value; - @JsonKey(nullable: false) - final Map nullable; - - SimpleClassUriToBigInt( + SimpleClassOfUriToBigInt( this.value, - this.nullable, ); - factory SimpleClassUriToBigInt.fromJson(Map json) => - _$SimpleClassUriToBigIntFromJson(json); + factory SimpleClassOfUriToBigInt.fromJson(Map json) => + _$SimpleClassOfUriToBigIntFromJson(json); - Map toJson() => _$SimpleClassUriToBigIntToJson(this); + Map toJson() => _$SimpleClassOfUriToBigIntToJson(this); } @JsonSerializable() -class SimpleClassBigIntToBool { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassNullableOfUriToBigInt { + final Map? value; - SimpleClassBigIntToBool( + SimpleClassNullableOfUriToBigInt( this.value, - this.nullable, ); - factory SimpleClassBigIntToBool.fromJson(Map json) => - _$SimpleClassBigIntToBoolFromJson(json); + factory SimpleClassNullableOfUriToBigInt.fromJson( + Map json) => + _$SimpleClassNullableOfUriToBigIntFromJson(json); - Map toJson() => _$SimpleClassBigIntToBoolToJson(this); + Map toJson() => + _$SimpleClassNullableOfUriToBigIntToJson(this); } @JsonSerializable() -class SimpleClassDateTimeToBool { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassOfBigIntToBigIntNullable { + final Map value; - SimpleClassDateTimeToBool( + SimpleClassOfBigIntToBigIntNullable( this.value, - this.nullable, ); - factory SimpleClassDateTimeToBool.fromJson(Map json) => - _$SimpleClassDateTimeToBoolFromJson(json); + factory SimpleClassOfBigIntToBigIntNullable.fromJson( + Map json) => + _$SimpleClassOfBigIntToBigIntNullableFromJson(json); - Map toJson() => _$SimpleClassDateTimeToBoolToJson(this); + Map toJson() => + _$SimpleClassOfBigIntToBigIntNullableToJson(this); } @JsonSerializable() -class SimpleClassDynamicToBool { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassNullableOfBigIntToBigIntNullable { + final Map? value; - SimpleClassDynamicToBool( + SimpleClassNullableOfBigIntToBigIntNullable( this.value, - this.nullable, ); - factory SimpleClassDynamicToBool.fromJson(Map json) => - _$SimpleClassDynamicToBoolFromJson(json); + factory SimpleClassNullableOfBigIntToBigIntNullable.fromJson( + Map json) => + _$SimpleClassNullableOfBigIntToBigIntNullableFromJson(json); - Map toJson() => _$SimpleClassDynamicToBoolToJson(this); + Map toJson() => + _$SimpleClassNullableOfBigIntToBigIntNullableToJson(this); } @JsonSerializable() -class SimpleClassEnumTypeToBool { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassOfDateTimeToBigIntNullable { + final Map value; - SimpleClassEnumTypeToBool( + SimpleClassOfDateTimeToBigIntNullable( this.value, - this.nullable, ); - factory SimpleClassEnumTypeToBool.fromJson(Map json) => - _$SimpleClassEnumTypeToBoolFromJson(json); + factory SimpleClassOfDateTimeToBigIntNullable.fromJson( + Map json) => + _$SimpleClassOfDateTimeToBigIntNullableFromJson(json); - Map toJson() => _$SimpleClassEnumTypeToBoolToJson(this); + Map toJson() => + _$SimpleClassOfDateTimeToBigIntNullableToJson(this); } @JsonSerializable() -class SimpleClassIntToBool { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassNullableOfDateTimeToBigIntNullable { + final Map? value; - SimpleClassIntToBool( + SimpleClassNullableOfDateTimeToBigIntNullable( this.value, - this.nullable, ); - factory SimpleClassIntToBool.fromJson(Map json) => - _$SimpleClassIntToBoolFromJson(json); + factory SimpleClassNullableOfDateTimeToBigIntNullable.fromJson( + Map json) => + _$SimpleClassNullableOfDateTimeToBigIntNullableFromJson(json); - Map toJson() => _$SimpleClassIntToBoolToJson(this); + Map toJson() => + _$SimpleClassNullableOfDateTimeToBigIntNullableToJson(this); } @JsonSerializable() -class SimpleClassObjectToBool { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassOfDynamicToBigIntNullable { + final Map value; - SimpleClassObjectToBool( + SimpleClassOfDynamicToBigIntNullable( this.value, - this.nullable, ); - factory SimpleClassObjectToBool.fromJson(Map json) => - _$SimpleClassObjectToBoolFromJson(json); + factory SimpleClassOfDynamicToBigIntNullable.fromJson( + Map json) => + _$SimpleClassOfDynamicToBigIntNullableFromJson(json); - Map toJson() => _$SimpleClassObjectToBoolToJson(this); + Map toJson() => + _$SimpleClassOfDynamicToBigIntNullableToJson(this); } @JsonSerializable() -class SimpleClassStringToBool { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassNullableOfDynamicToBigIntNullable { + final Map? value; - SimpleClassStringToBool( + SimpleClassNullableOfDynamicToBigIntNullable( this.value, - this.nullable, ); - factory SimpleClassStringToBool.fromJson(Map json) => - _$SimpleClassStringToBoolFromJson(json); + factory SimpleClassNullableOfDynamicToBigIntNullable.fromJson( + Map json) => + _$SimpleClassNullableOfDynamicToBigIntNullableFromJson(json); - Map toJson() => _$SimpleClassStringToBoolToJson(this); + Map toJson() => + _$SimpleClassNullableOfDynamicToBigIntNullableToJson(this); } @JsonSerializable() -class SimpleClassUriToBool { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassOfEnumTypeToBigIntNullable { + final Map value; - SimpleClassUriToBool( + SimpleClassOfEnumTypeToBigIntNullable( this.value, - this.nullable, ); - factory SimpleClassUriToBool.fromJson(Map json) => - _$SimpleClassUriToBoolFromJson(json); + factory SimpleClassOfEnumTypeToBigIntNullable.fromJson( + Map json) => + _$SimpleClassOfEnumTypeToBigIntNullableFromJson(json); - Map toJson() => _$SimpleClassUriToBoolToJson(this); + Map toJson() => + _$SimpleClassOfEnumTypeToBigIntNullableToJson(this); } @JsonSerializable() -class SimpleClassBigIntToDateTime { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassNullableOfEnumTypeToBigIntNullable { + final Map? value; - SimpleClassBigIntToDateTime( + SimpleClassNullableOfEnumTypeToBigIntNullable( this.value, - this.nullable, ); - factory SimpleClassBigIntToDateTime.fromJson(Map json) => - _$SimpleClassBigIntToDateTimeFromJson(json); + factory SimpleClassNullableOfEnumTypeToBigIntNullable.fromJson( + Map json) => + _$SimpleClassNullableOfEnumTypeToBigIntNullableFromJson(json); - Map toJson() => _$SimpleClassBigIntToDateTimeToJson(this); + Map toJson() => + _$SimpleClassNullableOfEnumTypeToBigIntNullableToJson(this); } @JsonSerializable() -class SimpleClassDateTimeToDateTime { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassOfIntToBigIntNullable { + final Map value; - SimpleClassDateTimeToDateTime( + SimpleClassOfIntToBigIntNullable( this.value, - this.nullable, ); - factory SimpleClassDateTimeToDateTime.fromJson(Map json) => - _$SimpleClassDateTimeToDateTimeFromJson(json); + factory SimpleClassOfIntToBigIntNullable.fromJson( + Map json) => + _$SimpleClassOfIntToBigIntNullableFromJson(json); - Map toJson() => _$SimpleClassDateTimeToDateTimeToJson(this); + Map toJson() => + _$SimpleClassOfIntToBigIntNullableToJson(this); } @JsonSerializable() -class SimpleClassDynamicToDateTime { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassNullableOfIntToBigIntNullable { + final Map? value; - SimpleClassDynamicToDateTime( + SimpleClassNullableOfIntToBigIntNullable( this.value, - this.nullable, ); - factory SimpleClassDynamicToDateTime.fromJson(Map json) => - _$SimpleClassDynamicToDateTimeFromJson(json); + factory SimpleClassNullableOfIntToBigIntNullable.fromJson( + Map json) => + _$SimpleClassNullableOfIntToBigIntNullableFromJson(json); - Map toJson() => _$SimpleClassDynamicToDateTimeToJson(this); + Map toJson() => + _$SimpleClassNullableOfIntToBigIntNullableToJson(this); } @JsonSerializable() -class SimpleClassEnumTypeToDateTime { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassOfObjectToBigIntNullable { + final Map value; - SimpleClassEnumTypeToDateTime( + SimpleClassOfObjectToBigIntNullable( this.value, - this.nullable, ); - factory SimpleClassEnumTypeToDateTime.fromJson(Map json) => - _$SimpleClassEnumTypeToDateTimeFromJson(json); + factory SimpleClassOfObjectToBigIntNullable.fromJson( + Map json) => + _$SimpleClassOfObjectToBigIntNullableFromJson(json); - Map toJson() => _$SimpleClassEnumTypeToDateTimeToJson(this); + Map toJson() => + _$SimpleClassOfObjectToBigIntNullableToJson(this); } @JsonSerializable() -class SimpleClassIntToDateTime { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassNullableOfObjectToBigIntNullable { + final Map? value; - SimpleClassIntToDateTime( + SimpleClassNullableOfObjectToBigIntNullable( this.value, - this.nullable, ); - factory SimpleClassIntToDateTime.fromJson(Map json) => - _$SimpleClassIntToDateTimeFromJson(json); + factory SimpleClassNullableOfObjectToBigIntNullable.fromJson( + Map json) => + _$SimpleClassNullableOfObjectToBigIntNullableFromJson(json); - Map toJson() => _$SimpleClassIntToDateTimeToJson(this); + Map toJson() => + _$SimpleClassNullableOfObjectToBigIntNullableToJson(this); } @JsonSerializable() -class SimpleClassObjectToDateTime { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassOfStringToBigIntNullable { + final Map value; - SimpleClassObjectToDateTime( + SimpleClassOfStringToBigIntNullable( this.value, - this.nullable, ); - factory SimpleClassObjectToDateTime.fromJson(Map json) => - _$SimpleClassObjectToDateTimeFromJson(json); + factory SimpleClassOfStringToBigIntNullable.fromJson( + Map json) => + _$SimpleClassOfStringToBigIntNullableFromJson(json); - Map toJson() => _$SimpleClassObjectToDateTimeToJson(this); + Map toJson() => + _$SimpleClassOfStringToBigIntNullableToJson(this); } @JsonSerializable() -class SimpleClassStringToDateTime { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassNullableOfStringToBigIntNullable { + final Map? value; - SimpleClassStringToDateTime( + SimpleClassNullableOfStringToBigIntNullable( this.value, - this.nullable, ); - factory SimpleClassStringToDateTime.fromJson(Map json) => - _$SimpleClassStringToDateTimeFromJson(json); + factory SimpleClassNullableOfStringToBigIntNullable.fromJson( + Map json) => + _$SimpleClassNullableOfStringToBigIntNullableFromJson(json); - Map toJson() => _$SimpleClassStringToDateTimeToJson(this); + Map toJson() => + _$SimpleClassNullableOfStringToBigIntNullableToJson(this); } @JsonSerializable() -class SimpleClassUriToDateTime { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassOfUriToBigIntNullable { + final Map value; - SimpleClassUriToDateTime( + SimpleClassOfUriToBigIntNullable( this.value, - this.nullable, ); - factory SimpleClassUriToDateTime.fromJson(Map json) => - _$SimpleClassUriToDateTimeFromJson(json); + factory SimpleClassOfUriToBigIntNullable.fromJson( + Map json) => + _$SimpleClassOfUriToBigIntNullableFromJson(json); - Map toJson() => _$SimpleClassUriToDateTimeToJson(this); + Map toJson() => + _$SimpleClassOfUriToBigIntNullableToJson(this); } @JsonSerializable() -class SimpleClassBigIntToDouble { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassNullableOfUriToBigIntNullable { + final Map? value; - SimpleClassBigIntToDouble( + SimpleClassNullableOfUriToBigIntNullable( this.value, - this.nullable, ); - factory SimpleClassBigIntToDouble.fromJson(Map json) => - _$SimpleClassBigIntToDoubleFromJson(json); + factory SimpleClassNullableOfUriToBigIntNullable.fromJson( + Map json) => + _$SimpleClassNullableOfUriToBigIntNullableFromJson(json); - Map toJson() => _$SimpleClassBigIntToDoubleToJson(this); + Map toJson() => + _$SimpleClassNullableOfUriToBigIntNullableToJson(this); } @JsonSerializable() -class SimpleClassDateTimeToDouble { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassOfBigIntToBool { + final Map value; - SimpleClassDateTimeToDouble( + SimpleClassOfBigIntToBool( this.value, - this.nullable, ); - factory SimpleClassDateTimeToDouble.fromJson(Map json) => - _$SimpleClassDateTimeToDoubleFromJson(json); + factory SimpleClassOfBigIntToBool.fromJson(Map json) => + _$SimpleClassOfBigIntToBoolFromJson(json); - Map toJson() => _$SimpleClassDateTimeToDoubleToJson(this); + Map toJson() => _$SimpleClassOfBigIntToBoolToJson(this); } @JsonSerializable() -class SimpleClassDynamicToDouble { - final Map value; +class SimpleClassNullableOfBigIntToBool { + final Map? value; - @JsonKey(nullable: false) - final Map nullable; - - SimpleClassDynamicToDouble( + SimpleClassNullableOfBigIntToBool( this.value, - this.nullable, ); - factory SimpleClassDynamicToDouble.fromJson(Map json) => - _$SimpleClassDynamicToDoubleFromJson(json); + factory SimpleClassNullableOfBigIntToBool.fromJson( + Map json) => + _$SimpleClassNullableOfBigIntToBoolFromJson(json); - Map toJson() => _$SimpleClassDynamicToDoubleToJson(this); + Map toJson() => + _$SimpleClassNullableOfBigIntToBoolToJson(this); } @JsonSerializable() -class SimpleClassEnumTypeToDouble { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassOfDateTimeToBool { + final Map value; - SimpleClassEnumTypeToDouble( + SimpleClassOfDateTimeToBool( this.value, - this.nullable, ); - factory SimpleClassEnumTypeToDouble.fromJson(Map json) => - _$SimpleClassEnumTypeToDoubleFromJson(json); + factory SimpleClassOfDateTimeToBool.fromJson(Map json) => + _$SimpleClassOfDateTimeToBoolFromJson(json); - Map toJson() => _$SimpleClassEnumTypeToDoubleToJson(this); + Map toJson() => _$SimpleClassOfDateTimeToBoolToJson(this); } @JsonSerializable() -class SimpleClassIntToDouble { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassNullableOfDateTimeToBool { + final Map? value; - SimpleClassIntToDouble( + SimpleClassNullableOfDateTimeToBool( this.value, - this.nullable, ); - factory SimpleClassIntToDouble.fromJson(Map json) => - _$SimpleClassIntToDoubleFromJson(json); + factory SimpleClassNullableOfDateTimeToBool.fromJson( + Map json) => + _$SimpleClassNullableOfDateTimeToBoolFromJson(json); - Map toJson() => _$SimpleClassIntToDoubleToJson(this); + Map toJson() => + _$SimpleClassNullableOfDateTimeToBoolToJson(this); } @JsonSerializable() -class SimpleClassObjectToDouble { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassOfDynamicToBool { + final Map value; - SimpleClassObjectToDouble( + SimpleClassOfDynamicToBool( this.value, - this.nullable, ); - factory SimpleClassObjectToDouble.fromJson(Map json) => - _$SimpleClassObjectToDoubleFromJson(json); + factory SimpleClassOfDynamicToBool.fromJson(Map json) => + _$SimpleClassOfDynamicToBoolFromJson(json); - Map toJson() => _$SimpleClassObjectToDoubleToJson(this); + Map toJson() => _$SimpleClassOfDynamicToBoolToJson(this); } @JsonSerializable() -class SimpleClassStringToDouble { - final Map value; +class SimpleClassNullableOfDynamicToBool { + final Map? value; - @JsonKey(nullable: false) - final Map nullable; - - SimpleClassStringToDouble( + SimpleClassNullableOfDynamicToBool( this.value, - this.nullable, ); - factory SimpleClassStringToDouble.fromJson(Map json) => - _$SimpleClassStringToDoubleFromJson(json); + factory SimpleClassNullableOfDynamicToBool.fromJson( + Map json) => + _$SimpleClassNullableOfDynamicToBoolFromJson(json); - Map toJson() => _$SimpleClassStringToDoubleToJson(this); + Map toJson() => + _$SimpleClassNullableOfDynamicToBoolToJson(this); } @JsonSerializable() -class SimpleClassUriToDouble { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassOfEnumTypeToBool { + final Map value; - SimpleClassUriToDouble( + SimpleClassOfEnumTypeToBool( this.value, - this.nullable, ); - factory SimpleClassUriToDouble.fromJson(Map json) => - _$SimpleClassUriToDoubleFromJson(json); + factory SimpleClassOfEnumTypeToBool.fromJson(Map json) => + _$SimpleClassOfEnumTypeToBoolFromJson(json); - Map toJson() => _$SimpleClassUriToDoubleToJson(this); + Map toJson() => _$SimpleClassOfEnumTypeToBoolToJson(this); } @JsonSerializable() -class SimpleClassBigIntToDuration { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassNullableOfEnumTypeToBool { + final Map? value; - SimpleClassBigIntToDuration( + SimpleClassNullableOfEnumTypeToBool( this.value, - this.nullable, ); - factory SimpleClassBigIntToDuration.fromJson(Map json) => - _$SimpleClassBigIntToDurationFromJson(json); + factory SimpleClassNullableOfEnumTypeToBool.fromJson( + Map json) => + _$SimpleClassNullableOfEnumTypeToBoolFromJson(json); - Map toJson() => _$SimpleClassBigIntToDurationToJson(this); + Map toJson() => + _$SimpleClassNullableOfEnumTypeToBoolToJson(this); } @JsonSerializable() -class SimpleClassDateTimeToDuration { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassOfIntToBool { + final Map value; - SimpleClassDateTimeToDuration( + SimpleClassOfIntToBool( this.value, - this.nullable, ); - factory SimpleClassDateTimeToDuration.fromJson(Map json) => - _$SimpleClassDateTimeToDurationFromJson(json); + factory SimpleClassOfIntToBool.fromJson(Map json) => + _$SimpleClassOfIntToBoolFromJson(json); - Map toJson() => _$SimpleClassDateTimeToDurationToJson(this); + Map toJson() => _$SimpleClassOfIntToBoolToJson(this); } @JsonSerializable() -class SimpleClassDynamicToDuration { - final Map value; +class SimpleClassNullableOfIntToBool { + final Map? value; - @JsonKey(nullable: false) - final Map nullable; - - SimpleClassDynamicToDuration( + SimpleClassNullableOfIntToBool( this.value, - this.nullable, ); - factory SimpleClassDynamicToDuration.fromJson(Map json) => - _$SimpleClassDynamicToDurationFromJson(json); + factory SimpleClassNullableOfIntToBool.fromJson(Map json) => + _$SimpleClassNullableOfIntToBoolFromJson(json); - Map toJson() => _$SimpleClassDynamicToDurationToJson(this); + Map toJson() => _$SimpleClassNullableOfIntToBoolToJson(this); } @JsonSerializable() -class SimpleClassEnumTypeToDuration { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassOfObjectToBool { + final Map value; - SimpleClassEnumTypeToDuration( + SimpleClassOfObjectToBool( this.value, - this.nullable, ); - factory SimpleClassEnumTypeToDuration.fromJson(Map json) => - _$SimpleClassEnumTypeToDurationFromJson(json); + factory SimpleClassOfObjectToBool.fromJson(Map json) => + _$SimpleClassOfObjectToBoolFromJson(json); - Map toJson() => _$SimpleClassEnumTypeToDurationToJson(this); + Map toJson() => _$SimpleClassOfObjectToBoolToJson(this); } @JsonSerializable() -class SimpleClassIntToDuration { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassNullableOfObjectToBool { + final Map? value; - SimpleClassIntToDuration( + SimpleClassNullableOfObjectToBool( this.value, - this.nullable, ); - factory SimpleClassIntToDuration.fromJson(Map json) => - _$SimpleClassIntToDurationFromJson(json); + factory SimpleClassNullableOfObjectToBool.fromJson( + Map json) => + _$SimpleClassNullableOfObjectToBoolFromJson(json); - Map toJson() => _$SimpleClassIntToDurationToJson(this); + Map toJson() => + _$SimpleClassNullableOfObjectToBoolToJson(this); } @JsonSerializable() -class SimpleClassObjectToDuration { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassOfStringToBool { + final Map value; - SimpleClassObjectToDuration( + SimpleClassOfStringToBool( this.value, - this.nullable, ); - factory SimpleClassObjectToDuration.fromJson(Map json) => - _$SimpleClassObjectToDurationFromJson(json); + factory SimpleClassOfStringToBool.fromJson(Map json) => + _$SimpleClassOfStringToBoolFromJson(json); - Map toJson() => _$SimpleClassObjectToDurationToJson(this); + Map toJson() => _$SimpleClassOfStringToBoolToJson(this); } @JsonSerializable() -class SimpleClassStringToDuration { - final Map value; +class SimpleClassNullableOfStringToBool { + final Map? value; - @JsonKey(nullable: false) - final Map nullable; - - SimpleClassStringToDuration( + SimpleClassNullableOfStringToBool( this.value, - this.nullable, ); - factory SimpleClassStringToDuration.fromJson(Map json) => - _$SimpleClassStringToDurationFromJson(json); + factory SimpleClassNullableOfStringToBool.fromJson( + Map json) => + _$SimpleClassNullableOfStringToBoolFromJson(json); - Map toJson() => _$SimpleClassStringToDurationToJson(this); + Map toJson() => + _$SimpleClassNullableOfStringToBoolToJson(this); } @JsonSerializable() -class SimpleClassUriToDuration { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassOfUriToBool { + final Map value; - SimpleClassUriToDuration( + SimpleClassOfUriToBool( this.value, - this.nullable, ); - factory SimpleClassUriToDuration.fromJson(Map json) => - _$SimpleClassUriToDurationFromJson(json); + factory SimpleClassOfUriToBool.fromJson(Map json) => + _$SimpleClassOfUriToBoolFromJson(json); - Map toJson() => _$SimpleClassUriToDurationToJson(this); + Map toJson() => _$SimpleClassOfUriToBoolToJson(this); } @JsonSerializable() -class SimpleClassBigIntToDynamic { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassNullableOfUriToBool { + final Map? value; - SimpleClassBigIntToDynamic( + SimpleClassNullableOfUriToBool( this.value, - this.nullable, ); - factory SimpleClassBigIntToDynamic.fromJson(Map json) => - _$SimpleClassBigIntToDynamicFromJson(json); + factory SimpleClassNullableOfUriToBool.fromJson(Map json) => + _$SimpleClassNullableOfUriToBoolFromJson(json); - Map toJson() => _$SimpleClassBigIntToDynamicToJson(this); + Map toJson() => _$SimpleClassNullableOfUriToBoolToJson(this); } @JsonSerializable() -class SimpleClassDateTimeToDynamic { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassOfBigIntToBoolNullable { + final Map value; - SimpleClassDateTimeToDynamic( + SimpleClassOfBigIntToBoolNullable( this.value, - this.nullable, ); - factory SimpleClassDateTimeToDynamic.fromJson(Map json) => - _$SimpleClassDateTimeToDynamicFromJson(json); + factory SimpleClassOfBigIntToBoolNullable.fromJson( + Map json) => + _$SimpleClassOfBigIntToBoolNullableFromJson(json); - Map toJson() => _$SimpleClassDateTimeToDynamicToJson(this); + Map toJson() => + _$SimpleClassOfBigIntToBoolNullableToJson(this); } @JsonSerializable() -class SimpleClassDynamicToDynamic { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassNullableOfBigIntToBoolNullable { + final Map? value; - SimpleClassDynamicToDynamic( + SimpleClassNullableOfBigIntToBoolNullable( this.value, - this.nullable, ); - factory SimpleClassDynamicToDynamic.fromJson(Map json) => - _$SimpleClassDynamicToDynamicFromJson(json); + factory SimpleClassNullableOfBigIntToBoolNullable.fromJson( + Map json) => + _$SimpleClassNullableOfBigIntToBoolNullableFromJson(json); - Map toJson() => _$SimpleClassDynamicToDynamicToJson(this); + Map toJson() => + _$SimpleClassNullableOfBigIntToBoolNullableToJson(this); } @JsonSerializable() -class SimpleClassEnumTypeToDynamic { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassOfDateTimeToBoolNullable { + final Map value; - SimpleClassEnumTypeToDynamic( + SimpleClassOfDateTimeToBoolNullable( this.value, - this.nullable, ); - factory SimpleClassEnumTypeToDynamic.fromJson(Map json) => - _$SimpleClassEnumTypeToDynamicFromJson(json); + factory SimpleClassOfDateTimeToBoolNullable.fromJson( + Map json) => + _$SimpleClassOfDateTimeToBoolNullableFromJson(json); - Map toJson() => _$SimpleClassEnumTypeToDynamicToJson(this); + Map toJson() => + _$SimpleClassOfDateTimeToBoolNullableToJson(this); } @JsonSerializable() -class SimpleClassIntToDynamic { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassNullableOfDateTimeToBoolNullable { + final Map? value; - SimpleClassIntToDynamic( + SimpleClassNullableOfDateTimeToBoolNullable( this.value, - this.nullable, ); - factory SimpleClassIntToDynamic.fromJson(Map json) => - _$SimpleClassIntToDynamicFromJson(json); + factory SimpleClassNullableOfDateTimeToBoolNullable.fromJson( + Map json) => + _$SimpleClassNullableOfDateTimeToBoolNullableFromJson(json); - Map toJson() => _$SimpleClassIntToDynamicToJson(this); + Map toJson() => + _$SimpleClassNullableOfDateTimeToBoolNullableToJson(this); } @JsonSerializable() -class SimpleClassObjectToDynamic { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassOfDynamicToBoolNullable { + final Map value; - SimpleClassObjectToDynamic( + SimpleClassOfDynamicToBoolNullable( this.value, - this.nullable, ); - factory SimpleClassObjectToDynamic.fromJson(Map json) => - _$SimpleClassObjectToDynamicFromJson(json); + factory SimpleClassOfDynamicToBoolNullable.fromJson( + Map json) => + _$SimpleClassOfDynamicToBoolNullableFromJson(json); - Map toJson() => _$SimpleClassObjectToDynamicToJson(this); + Map toJson() => + _$SimpleClassOfDynamicToBoolNullableToJson(this); } @JsonSerializable() -class SimpleClassStringToDynamic { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassNullableOfDynamicToBoolNullable { + final Map? value; - SimpleClassStringToDynamic( + SimpleClassNullableOfDynamicToBoolNullable( this.value, - this.nullable, ); - factory SimpleClassStringToDynamic.fromJson(Map json) => - _$SimpleClassStringToDynamicFromJson(json); + factory SimpleClassNullableOfDynamicToBoolNullable.fromJson( + Map json) => + _$SimpleClassNullableOfDynamicToBoolNullableFromJson(json); - Map toJson() => _$SimpleClassStringToDynamicToJson(this); + Map toJson() => + _$SimpleClassNullableOfDynamicToBoolNullableToJson(this); } @JsonSerializable() -class SimpleClassUriToDynamic { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassOfEnumTypeToBoolNullable { + final Map value; - SimpleClassUriToDynamic( + SimpleClassOfEnumTypeToBoolNullable( this.value, - this.nullable, ); - factory SimpleClassUriToDynamic.fromJson(Map json) => - _$SimpleClassUriToDynamicFromJson(json); + factory SimpleClassOfEnumTypeToBoolNullable.fromJson( + Map json) => + _$SimpleClassOfEnumTypeToBoolNullableFromJson(json); - Map toJson() => _$SimpleClassUriToDynamicToJson(this); + Map toJson() => + _$SimpleClassOfEnumTypeToBoolNullableToJson(this); } @JsonSerializable() -class SimpleClassBigIntToEnumType { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassNullableOfEnumTypeToBoolNullable { + final Map? value; - SimpleClassBigIntToEnumType( + SimpleClassNullableOfEnumTypeToBoolNullable( this.value, - this.nullable, ); - factory SimpleClassBigIntToEnumType.fromJson(Map json) => - _$SimpleClassBigIntToEnumTypeFromJson(json); + factory SimpleClassNullableOfEnumTypeToBoolNullable.fromJson( + Map json) => + _$SimpleClassNullableOfEnumTypeToBoolNullableFromJson(json); - Map toJson() => _$SimpleClassBigIntToEnumTypeToJson(this); + Map toJson() => + _$SimpleClassNullableOfEnumTypeToBoolNullableToJson(this); } @JsonSerializable() -class SimpleClassDateTimeToEnumType { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassOfIntToBoolNullable { + final Map value; - SimpleClassDateTimeToEnumType( + SimpleClassOfIntToBoolNullable( this.value, - this.nullable, ); - factory SimpleClassDateTimeToEnumType.fromJson(Map json) => - _$SimpleClassDateTimeToEnumTypeFromJson(json); + factory SimpleClassOfIntToBoolNullable.fromJson(Map json) => + _$SimpleClassOfIntToBoolNullableFromJson(json); - Map toJson() => _$SimpleClassDateTimeToEnumTypeToJson(this); + Map toJson() => _$SimpleClassOfIntToBoolNullableToJson(this); } @JsonSerializable() -class SimpleClassDynamicToEnumType { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassNullableOfIntToBoolNullable { + final Map? value; - SimpleClassDynamicToEnumType( + SimpleClassNullableOfIntToBoolNullable( this.value, - this.nullable, ); - factory SimpleClassDynamicToEnumType.fromJson(Map json) => - _$SimpleClassDynamicToEnumTypeFromJson(json); + factory SimpleClassNullableOfIntToBoolNullable.fromJson( + Map json) => + _$SimpleClassNullableOfIntToBoolNullableFromJson(json); - Map toJson() => _$SimpleClassDynamicToEnumTypeToJson(this); + Map toJson() => + _$SimpleClassNullableOfIntToBoolNullableToJson(this); } @JsonSerializable() -class SimpleClassEnumTypeToEnumType { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassOfObjectToBoolNullable { + final Map value; - SimpleClassEnumTypeToEnumType( + SimpleClassOfObjectToBoolNullable( this.value, - this.nullable, ); - factory SimpleClassEnumTypeToEnumType.fromJson(Map json) => - _$SimpleClassEnumTypeToEnumTypeFromJson(json); + factory SimpleClassOfObjectToBoolNullable.fromJson( + Map json) => + _$SimpleClassOfObjectToBoolNullableFromJson(json); - Map toJson() => _$SimpleClassEnumTypeToEnumTypeToJson(this); + Map toJson() => + _$SimpleClassOfObjectToBoolNullableToJson(this); } @JsonSerializable() -class SimpleClassIntToEnumType { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassNullableOfObjectToBoolNullable { + final Map? value; - SimpleClassIntToEnumType( + SimpleClassNullableOfObjectToBoolNullable( this.value, - this.nullable, ); - factory SimpleClassIntToEnumType.fromJson(Map json) => - _$SimpleClassIntToEnumTypeFromJson(json); + factory SimpleClassNullableOfObjectToBoolNullable.fromJson( + Map json) => + _$SimpleClassNullableOfObjectToBoolNullableFromJson(json); - Map toJson() => _$SimpleClassIntToEnumTypeToJson(this); + Map toJson() => + _$SimpleClassNullableOfObjectToBoolNullableToJson(this); } @JsonSerializable() -class SimpleClassObjectToEnumType { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassOfStringToBoolNullable { + final Map value; - SimpleClassObjectToEnumType( + SimpleClassOfStringToBoolNullable( this.value, - this.nullable, ); - factory SimpleClassObjectToEnumType.fromJson(Map json) => - _$SimpleClassObjectToEnumTypeFromJson(json); + factory SimpleClassOfStringToBoolNullable.fromJson( + Map json) => + _$SimpleClassOfStringToBoolNullableFromJson(json); - Map toJson() => _$SimpleClassObjectToEnumTypeToJson(this); + Map toJson() => + _$SimpleClassOfStringToBoolNullableToJson(this); } @JsonSerializable() -class SimpleClassStringToEnumType { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassNullableOfStringToBoolNullable { + final Map? value; - SimpleClassStringToEnumType( + SimpleClassNullableOfStringToBoolNullable( this.value, - this.nullable, ); - factory SimpleClassStringToEnumType.fromJson(Map json) => - _$SimpleClassStringToEnumTypeFromJson(json); + factory SimpleClassNullableOfStringToBoolNullable.fromJson( + Map json) => + _$SimpleClassNullableOfStringToBoolNullableFromJson(json); - Map toJson() => _$SimpleClassStringToEnumTypeToJson(this); + Map toJson() => + _$SimpleClassNullableOfStringToBoolNullableToJson(this); } @JsonSerializable() -class SimpleClassUriToEnumType { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassOfUriToBoolNullable { + final Map value; - SimpleClassUriToEnumType( + SimpleClassOfUriToBoolNullable( this.value, - this.nullable, ); - factory SimpleClassUriToEnumType.fromJson(Map json) => - _$SimpleClassUriToEnumTypeFromJson(json); + factory SimpleClassOfUriToBoolNullable.fromJson(Map json) => + _$SimpleClassOfUriToBoolNullableFromJson(json); - Map toJson() => _$SimpleClassUriToEnumTypeToJson(this); + Map toJson() => _$SimpleClassOfUriToBoolNullableToJson(this); } @JsonSerializable() -class SimpleClassBigIntToInt { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassNullableOfUriToBoolNullable { + final Map? value; - SimpleClassBigIntToInt( + SimpleClassNullableOfUriToBoolNullable( this.value, - this.nullable, ); - factory SimpleClassBigIntToInt.fromJson(Map json) => - _$SimpleClassBigIntToIntFromJson(json); + factory SimpleClassNullableOfUriToBoolNullable.fromJson( + Map json) => + _$SimpleClassNullableOfUriToBoolNullableFromJson(json); - Map toJson() => _$SimpleClassBigIntToIntToJson(this); + Map toJson() => + _$SimpleClassNullableOfUriToBoolNullableToJson(this); } @JsonSerializable() -class SimpleClassDateTimeToInt { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassOfBigIntToDateTime { + final Map value; - SimpleClassDateTimeToInt( + SimpleClassOfBigIntToDateTime( this.value, - this.nullable, ); - factory SimpleClassDateTimeToInt.fromJson(Map json) => - _$SimpleClassDateTimeToIntFromJson(json); + factory SimpleClassOfBigIntToDateTime.fromJson(Map json) => + _$SimpleClassOfBigIntToDateTimeFromJson(json); - Map toJson() => _$SimpleClassDateTimeToIntToJson(this); + Map toJson() => _$SimpleClassOfBigIntToDateTimeToJson(this); } @JsonSerializable() -class SimpleClassDynamicToInt { - final Map value; +class SimpleClassNullableOfBigIntToDateTime { + final Map? value; - @JsonKey(nullable: false) - final Map nullable; - - SimpleClassDynamicToInt( + SimpleClassNullableOfBigIntToDateTime( this.value, - this.nullable, ); - factory SimpleClassDynamicToInt.fromJson(Map json) => - _$SimpleClassDynamicToIntFromJson(json); + factory SimpleClassNullableOfBigIntToDateTime.fromJson( + Map json) => + _$SimpleClassNullableOfBigIntToDateTimeFromJson(json); - Map toJson() => _$SimpleClassDynamicToIntToJson(this); + Map toJson() => + _$SimpleClassNullableOfBigIntToDateTimeToJson(this); } @JsonSerializable() -class SimpleClassEnumTypeToInt { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassOfDateTimeToDateTime { + final Map value; - SimpleClassEnumTypeToInt( + SimpleClassOfDateTimeToDateTime( this.value, - this.nullable, ); - factory SimpleClassEnumTypeToInt.fromJson(Map json) => - _$SimpleClassEnumTypeToIntFromJson(json); + factory SimpleClassOfDateTimeToDateTime.fromJson(Map json) => + _$SimpleClassOfDateTimeToDateTimeFromJson(json); - Map toJson() => _$SimpleClassEnumTypeToIntToJson(this); + Map toJson() => + _$SimpleClassOfDateTimeToDateTimeToJson(this); } @JsonSerializable() -class SimpleClassIntToInt { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassNullableOfDateTimeToDateTime { + final Map? value; - SimpleClassIntToInt( + SimpleClassNullableOfDateTimeToDateTime( this.value, - this.nullable, ); - factory SimpleClassIntToInt.fromJson(Map json) => - _$SimpleClassIntToIntFromJson(json); + factory SimpleClassNullableOfDateTimeToDateTime.fromJson( + Map json) => + _$SimpleClassNullableOfDateTimeToDateTimeFromJson(json); - Map toJson() => _$SimpleClassIntToIntToJson(this); + Map toJson() => + _$SimpleClassNullableOfDateTimeToDateTimeToJson(this); } @JsonSerializable() -class SimpleClassObjectToInt { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassOfDynamicToDateTime { + final Map value; - SimpleClassObjectToInt( + SimpleClassOfDynamicToDateTime( this.value, - this.nullable, ); - factory SimpleClassObjectToInt.fromJson(Map json) => - _$SimpleClassObjectToIntFromJson(json); + factory SimpleClassOfDynamicToDateTime.fromJson(Map json) => + _$SimpleClassOfDynamicToDateTimeFromJson(json); - Map toJson() => _$SimpleClassObjectToIntToJson(this); + Map toJson() => _$SimpleClassOfDynamicToDateTimeToJson(this); } @JsonSerializable() -class SimpleClassStringToInt { - final Map value; +class SimpleClassNullableOfDynamicToDateTime { + final Map? value; - @JsonKey(nullable: false) - final Map nullable; - - SimpleClassStringToInt( + SimpleClassNullableOfDynamicToDateTime( this.value, - this.nullable, ); - factory SimpleClassStringToInt.fromJson(Map json) => - _$SimpleClassStringToIntFromJson(json); + factory SimpleClassNullableOfDynamicToDateTime.fromJson( + Map json) => + _$SimpleClassNullableOfDynamicToDateTimeFromJson(json); - Map toJson() => _$SimpleClassStringToIntToJson(this); + Map toJson() => + _$SimpleClassNullableOfDynamicToDateTimeToJson(this); } @JsonSerializable() -class SimpleClassUriToInt { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassOfEnumTypeToDateTime { + final Map value; - SimpleClassUriToInt( + SimpleClassOfEnumTypeToDateTime( this.value, - this.nullable, ); - factory SimpleClassUriToInt.fromJson(Map json) => - _$SimpleClassUriToIntFromJson(json); + factory SimpleClassOfEnumTypeToDateTime.fromJson(Map json) => + _$SimpleClassOfEnumTypeToDateTimeFromJson(json); - Map toJson() => _$SimpleClassUriToIntToJson(this); + Map toJson() => + _$SimpleClassOfEnumTypeToDateTimeToJson(this); } @JsonSerializable() -class SimpleClassBigIntToNum { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassNullableOfEnumTypeToDateTime { + final Map? value; - SimpleClassBigIntToNum( + SimpleClassNullableOfEnumTypeToDateTime( this.value, - this.nullable, ); - factory SimpleClassBigIntToNum.fromJson(Map json) => - _$SimpleClassBigIntToNumFromJson(json); + factory SimpleClassNullableOfEnumTypeToDateTime.fromJson( + Map json) => + _$SimpleClassNullableOfEnumTypeToDateTimeFromJson(json); - Map toJson() => _$SimpleClassBigIntToNumToJson(this); + Map toJson() => + _$SimpleClassNullableOfEnumTypeToDateTimeToJson(this); } @JsonSerializable() -class SimpleClassDateTimeToNum { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassOfIntToDateTime { + final Map value; - SimpleClassDateTimeToNum( + SimpleClassOfIntToDateTime( this.value, - this.nullable, ); - factory SimpleClassDateTimeToNum.fromJson(Map json) => - _$SimpleClassDateTimeToNumFromJson(json); + factory SimpleClassOfIntToDateTime.fromJson(Map json) => + _$SimpleClassOfIntToDateTimeFromJson(json); - Map toJson() => _$SimpleClassDateTimeToNumToJson(this); + Map toJson() => _$SimpleClassOfIntToDateTimeToJson(this); } @JsonSerializable() -class SimpleClassDynamicToNum { - final Map value; +class SimpleClassNullableOfIntToDateTime { + final Map? value; - @JsonKey(nullable: false) - final Map nullable; - - SimpleClassDynamicToNum( + SimpleClassNullableOfIntToDateTime( this.value, - this.nullable, ); - factory SimpleClassDynamicToNum.fromJson(Map json) => - _$SimpleClassDynamicToNumFromJson(json); + factory SimpleClassNullableOfIntToDateTime.fromJson( + Map json) => + _$SimpleClassNullableOfIntToDateTimeFromJson(json); - Map toJson() => _$SimpleClassDynamicToNumToJson(this); + Map toJson() => + _$SimpleClassNullableOfIntToDateTimeToJson(this); } @JsonSerializable() -class SimpleClassEnumTypeToNum { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassOfObjectToDateTime { + final Map value; - SimpleClassEnumTypeToNum( + SimpleClassOfObjectToDateTime( this.value, - this.nullable, ); - factory SimpleClassEnumTypeToNum.fromJson(Map json) => - _$SimpleClassEnumTypeToNumFromJson(json); + factory SimpleClassOfObjectToDateTime.fromJson(Map json) => + _$SimpleClassOfObjectToDateTimeFromJson(json); - Map toJson() => _$SimpleClassEnumTypeToNumToJson(this); + Map toJson() => _$SimpleClassOfObjectToDateTimeToJson(this); } @JsonSerializable() -class SimpleClassIntToNum { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassNullableOfObjectToDateTime { + final Map? value; - SimpleClassIntToNum( + SimpleClassNullableOfObjectToDateTime( this.value, - this.nullable, ); - factory SimpleClassIntToNum.fromJson(Map json) => - _$SimpleClassIntToNumFromJson(json); + factory SimpleClassNullableOfObjectToDateTime.fromJson( + Map json) => + _$SimpleClassNullableOfObjectToDateTimeFromJson(json); - Map toJson() => _$SimpleClassIntToNumToJson(this); + Map toJson() => + _$SimpleClassNullableOfObjectToDateTimeToJson(this); } @JsonSerializable() -class SimpleClassObjectToNum { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassOfStringToDateTime { + final Map value; - SimpleClassObjectToNum( + SimpleClassOfStringToDateTime( this.value, - this.nullable, ); - factory SimpleClassObjectToNum.fromJson(Map json) => - _$SimpleClassObjectToNumFromJson(json); + factory SimpleClassOfStringToDateTime.fromJson(Map json) => + _$SimpleClassOfStringToDateTimeFromJson(json); - Map toJson() => _$SimpleClassObjectToNumToJson(this); + Map toJson() => _$SimpleClassOfStringToDateTimeToJson(this); } @JsonSerializable() -class SimpleClassStringToNum { - final Map value; +class SimpleClassNullableOfStringToDateTime { + final Map? value; - @JsonKey(nullable: false) - final Map nullable; - - SimpleClassStringToNum( + SimpleClassNullableOfStringToDateTime( this.value, - this.nullable, ); - factory SimpleClassStringToNum.fromJson(Map json) => - _$SimpleClassStringToNumFromJson(json); + factory SimpleClassNullableOfStringToDateTime.fromJson( + Map json) => + _$SimpleClassNullableOfStringToDateTimeFromJson(json); - Map toJson() => _$SimpleClassStringToNumToJson(this); + Map toJson() => + _$SimpleClassNullableOfStringToDateTimeToJson(this); } @JsonSerializable() -class SimpleClassUriToNum { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassOfUriToDateTime { + final Map value; - SimpleClassUriToNum( + SimpleClassOfUriToDateTime( this.value, - this.nullable, ); - factory SimpleClassUriToNum.fromJson(Map json) => - _$SimpleClassUriToNumFromJson(json); + factory SimpleClassOfUriToDateTime.fromJson(Map json) => + _$SimpleClassOfUriToDateTimeFromJson(json); - Map toJson() => _$SimpleClassUriToNumToJson(this); + Map toJson() => _$SimpleClassOfUriToDateTimeToJson(this); } @JsonSerializable() -class SimpleClassBigIntToObject { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassNullableOfUriToDateTime { + final Map? value; - SimpleClassBigIntToObject( + SimpleClassNullableOfUriToDateTime( this.value, - this.nullable, ); - factory SimpleClassBigIntToObject.fromJson(Map json) => - _$SimpleClassBigIntToObjectFromJson(json); + factory SimpleClassNullableOfUriToDateTime.fromJson( + Map json) => + _$SimpleClassNullableOfUriToDateTimeFromJson(json); - Map toJson() => _$SimpleClassBigIntToObjectToJson(this); + Map toJson() => + _$SimpleClassNullableOfUriToDateTimeToJson(this); } @JsonSerializable() -class SimpleClassDateTimeToObject { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassOfBigIntToDateTimeNullable { + final Map value; - SimpleClassDateTimeToObject( + SimpleClassOfBigIntToDateTimeNullable( this.value, - this.nullable, ); - factory SimpleClassDateTimeToObject.fromJson(Map json) => - _$SimpleClassDateTimeToObjectFromJson(json); + factory SimpleClassOfBigIntToDateTimeNullable.fromJson( + Map json) => + _$SimpleClassOfBigIntToDateTimeNullableFromJson(json); - Map toJson() => _$SimpleClassDateTimeToObjectToJson(this); + Map toJson() => + _$SimpleClassOfBigIntToDateTimeNullableToJson(this); } @JsonSerializable() -class SimpleClassDynamicToObject { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassNullableOfBigIntToDateTimeNullable { + final Map? value; - SimpleClassDynamicToObject( + SimpleClassNullableOfBigIntToDateTimeNullable( this.value, - this.nullable, ); - factory SimpleClassDynamicToObject.fromJson(Map json) => - _$SimpleClassDynamicToObjectFromJson(json); + factory SimpleClassNullableOfBigIntToDateTimeNullable.fromJson( + Map json) => + _$SimpleClassNullableOfBigIntToDateTimeNullableFromJson(json); - Map toJson() => _$SimpleClassDynamicToObjectToJson(this); + Map toJson() => + _$SimpleClassNullableOfBigIntToDateTimeNullableToJson(this); } @JsonSerializable() -class SimpleClassEnumTypeToObject { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassOfDateTimeToDateTimeNullable { + final Map value; - SimpleClassEnumTypeToObject( + SimpleClassOfDateTimeToDateTimeNullable( this.value, - this.nullable, ); - factory SimpleClassEnumTypeToObject.fromJson(Map json) => - _$SimpleClassEnumTypeToObjectFromJson(json); + factory SimpleClassOfDateTimeToDateTimeNullable.fromJson( + Map json) => + _$SimpleClassOfDateTimeToDateTimeNullableFromJson(json); - Map toJson() => _$SimpleClassEnumTypeToObjectToJson(this); + Map toJson() => + _$SimpleClassOfDateTimeToDateTimeNullableToJson(this); } @JsonSerializable() -class SimpleClassIntToObject { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassNullableOfDateTimeToDateTimeNullable { + final Map? value; - SimpleClassIntToObject( + SimpleClassNullableOfDateTimeToDateTimeNullable( this.value, - this.nullable, ); - factory SimpleClassIntToObject.fromJson(Map json) => - _$SimpleClassIntToObjectFromJson(json); + factory SimpleClassNullableOfDateTimeToDateTimeNullable.fromJson( + Map json) => + _$SimpleClassNullableOfDateTimeToDateTimeNullableFromJson(json); - Map toJson() => _$SimpleClassIntToObjectToJson(this); + Map toJson() => + _$SimpleClassNullableOfDateTimeToDateTimeNullableToJson(this); } @JsonSerializable() -class SimpleClassObjectToObject { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassOfDynamicToDateTimeNullable { + final Map value; - SimpleClassObjectToObject( + SimpleClassOfDynamicToDateTimeNullable( this.value, - this.nullable, ); - factory SimpleClassObjectToObject.fromJson(Map json) => - _$SimpleClassObjectToObjectFromJson(json); + factory SimpleClassOfDynamicToDateTimeNullable.fromJson( + Map json) => + _$SimpleClassOfDynamicToDateTimeNullableFromJson(json); - Map toJson() => _$SimpleClassObjectToObjectToJson(this); + Map toJson() => + _$SimpleClassOfDynamicToDateTimeNullableToJson(this); } @JsonSerializable() -class SimpleClassStringToObject { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassNullableOfDynamicToDateTimeNullable { + final Map? value; - SimpleClassStringToObject( + SimpleClassNullableOfDynamicToDateTimeNullable( this.value, - this.nullable, ); - factory SimpleClassStringToObject.fromJson(Map json) => - _$SimpleClassStringToObjectFromJson(json); + factory SimpleClassNullableOfDynamicToDateTimeNullable.fromJson( + Map json) => + _$SimpleClassNullableOfDynamicToDateTimeNullableFromJson(json); - Map toJson() => _$SimpleClassStringToObjectToJson(this); + Map toJson() => + _$SimpleClassNullableOfDynamicToDateTimeNullableToJson(this); } @JsonSerializable() -class SimpleClassUriToObject { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassOfEnumTypeToDateTimeNullable { + final Map value; - SimpleClassUriToObject( + SimpleClassOfEnumTypeToDateTimeNullable( this.value, - this.nullable, ); - factory SimpleClassUriToObject.fromJson(Map json) => - _$SimpleClassUriToObjectFromJson(json); + factory SimpleClassOfEnumTypeToDateTimeNullable.fromJson( + Map json) => + _$SimpleClassOfEnumTypeToDateTimeNullableFromJson(json); - Map toJson() => _$SimpleClassUriToObjectToJson(this); + Map toJson() => + _$SimpleClassOfEnumTypeToDateTimeNullableToJson(this); } @JsonSerializable() -class SimpleClassBigIntToString { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassNullableOfEnumTypeToDateTimeNullable { + final Map? value; - SimpleClassBigIntToString( + SimpleClassNullableOfEnumTypeToDateTimeNullable( this.value, - this.nullable, ); - factory SimpleClassBigIntToString.fromJson(Map json) => - _$SimpleClassBigIntToStringFromJson(json); + factory SimpleClassNullableOfEnumTypeToDateTimeNullable.fromJson( + Map json) => + _$SimpleClassNullableOfEnumTypeToDateTimeNullableFromJson(json); - Map toJson() => _$SimpleClassBigIntToStringToJson(this); + Map toJson() => + _$SimpleClassNullableOfEnumTypeToDateTimeNullableToJson(this); } @JsonSerializable() -class SimpleClassDateTimeToString { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassOfIntToDateTimeNullable { + final Map value; - SimpleClassDateTimeToString( + SimpleClassOfIntToDateTimeNullable( this.value, - this.nullable, ); - factory SimpleClassDateTimeToString.fromJson(Map json) => - _$SimpleClassDateTimeToStringFromJson(json); + factory SimpleClassOfIntToDateTimeNullable.fromJson( + Map json) => + _$SimpleClassOfIntToDateTimeNullableFromJson(json); - Map toJson() => _$SimpleClassDateTimeToStringToJson(this); + Map toJson() => + _$SimpleClassOfIntToDateTimeNullableToJson(this); } @JsonSerializable() -class SimpleClassDynamicToString { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassNullableOfIntToDateTimeNullable { + final Map? value; - SimpleClassDynamicToString( + SimpleClassNullableOfIntToDateTimeNullable( this.value, - this.nullable, ); - factory SimpleClassDynamicToString.fromJson(Map json) => - _$SimpleClassDynamicToStringFromJson(json); + factory SimpleClassNullableOfIntToDateTimeNullable.fromJson( + Map json) => + _$SimpleClassNullableOfIntToDateTimeNullableFromJson(json); - Map toJson() => _$SimpleClassDynamicToStringToJson(this); + Map toJson() => + _$SimpleClassNullableOfIntToDateTimeNullableToJson(this); } @JsonSerializable() -class SimpleClassEnumTypeToString { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassOfObjectToDateTimeNullable { + final Map value; - SimpleClassEnumTypeToString( + SimpleClassOfObjectToDateTimeNullable( this.value, - this.nullable, ); - factory SimpleClassEnumTypeToString.fromJson(Map json) => - _$SimpleClassEnumTypeToStringFromJson(json); + factory SimpleClassOfObjectToDateTimeNullable.fromJson( + Map json) => + _$SimpleClassOfObjectToDateTimeNullableFromJson(json); - Map toJson() => _$SimpleClassEnumTypeToStringToJson(this); + Map toJson() => + _$SimpleClassOfObjectToDateTimeNullableToJson(this); } @JsonSerializable() -class SimpleClassIntToString { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassNullableOfObjectToDateTimeNullable { + final Map? value; - SimpleClassIntToString( + SimpleClassNullableOfObjectToDateTimeNullable( this.value, - this.nullable, ); - factory SimpleClassIntToString.fromJson(Map json) => - _$SimpleClassIntToStringFromJson(json); + factory SimpleClassNullableOfObjectToDateTimeNullable.fromJson( + Map json) => + _$SimpleClassNullableOfObjectToDateTimeNullableFromJson(json); - Map toJson() => _$SimpleClassIntToStringToJson(this); + Map toJson() => + _$SimpleClassNullableOfObjectToDateTimeNullableToJson(this); } @JsonSerializable() -class SimpleClassObjectToString { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassOfStringToDateTimeNullable { + final Map value; - SimpleClassObjectToString( + SimpleClassOfStringToDateTimeNullable( this.value, - this.nullable, ); - factory SimpleClassObjectToString.fromJson(Map json) => - _$SimpleClassObjectToStringFromJson(json); + factory SimpleClassOfStringToDateTimeNullable.fromJson( + Map json) => + _$SimpleClassOfStringToDateTimeNullableFromJson(json); - Map toJson() => _$SimpleClassObjectToStringToJson(this); + Map toJson() => + _$SimpleClassOfStringToDateTimeNullableToJson(this); } @JsonSerializable() -class SimpleClassStringToString { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassNullableOfStringToDateTimeNullable { + final Map? value; - SimpleClassStringToString( + SimpleClassNullableOfStringToDateTimeNullable( this.value, - this.nullable, ); - factory SimpleClassStringToString.fromJson(Map json) => - _$SimpleClassStringToStringFromJson(json); + factory SimpleClassNullableOfStringToDateTimeNullable.fromJson( + Map json) => + _$SimpleClassNullableOfStringToDateTimeNullableFromJson(json); - Map toJson() => _$SimpleClassStringToStringToJson(this); + Map toJson() => + _$SimpleClassNullableOfStringToDateTimeNullableToJson(this); } @JsonSerializable() -class SimpleClassUriToString { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassOfUriToDateTimeNullable { + final Map value; - SimpleClassUriToString( + SimpleClassOfUriToDateTimeNullable( this.value, - this.nullable, ); - factory SimpleClassUriToString.fromJson(Map json) => - _$SimpleClassUriToStringFromJson(json); + factory SimpleClassOfUriToDateTimeNullable.fromJson( + Map json) => + _$SimpleClassOfUriToDateTimeNullableFromJson(json); - Map toJson() => _$SimpleClassUriToStringToJson(this); + Map toJson() => + _$SimpleClassOfUriToDateTimeNullableToJson(this); } @JsonSerializable() -class SimpleClassBigIntToUri { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassNullableOfUriToDateTimeNullable { + final Map? value; - SimpleClassBigIntToUri( + SimpleClassNullableOfUriToDateTimeNullable( this.value, - this.nullable, ); - factory SimpleClassBigIntToUri.fromJson(Map json) => - _$SimpleClassBigIntToUriFromJson(json); + factory SimpleClassNullableOfUriToDateTimeNullable.fromJson( + Map json) => + _$SimpleClassNullableOfUriToDateTimeNullableFromJson(json); - Map toJson() => _$SimpleClassBigIntToUriToJson(this); + Map toJson() => + _$SimpleClassNullableOfUriToDateTimeNullableToJson(this); } @JsonSerializable() -class SimpleClassDateTimeToUri { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassOfBigIntToDouble { + final Map value; - SimpleClassDateTimeToUri( + SimpleClassOfBigIntToDouble( this.value, - this.nullable, ); - factory SimpleClassDateTimeToUri.fromJson(Map json) => - _$SimpleClassDateTimeToUriFromJson(json); + factory SimpleClassOfBigIntToDouble.fromJson(Map json) => + _$SimpleClassOfBigIntToDoubleFromJson(json); - Map toJson() => _$SimpleClassDateTimeToUriToJson(this); + Map toJson() => _$SimpleClassOfBigIntToDoubleToJson(this); } @JsonSerializable() -class SimpleClassDynamicToUri { - final Map value; +class SimpleClassNullableOfBigIntToDouble { + final Map? value; - @JsonKey(nullable: false) - final Map nullable; - - SimpleClassDynamicToUri( + SimpleClassNullableOfBigIntToDouble( this.value, - this.nullable, ); - factory SimpleClassDynamicToUri.fromJson(Map json) => - _$SimpleClassDynamicToUriFromJson(json); + factory SimpleClassNullableOfBigIntToDouble.fromJson( + Map json) => + _$SimpleClassNullableOfBigIntToDoubleFromJson(json); - Map toJson() => _$SimpleClassDynamicToUriToJson(this); + Map toJson() => + _$SimpleClassNullableOfBigIntToDoubleToJson(this); } @JsonSerializable() -class SimpleClassEnumTypeToUri { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassOfDateTimeToDouble { + final Map value; - SimpleClassEnumTypeToUri( + SimpleClassOfDateTimeToDouble( this.value, - this.nullable, ); - factory SimpleClassEnumTypeToUri.fromJson(Map json) => - _$SimpleClassEnumTypeToUriFromJson(json); + factory SimpleClassOfDateTimeToDouble.fromJson(Map json) => + _$SimpleClassOfDateTimeToDoubleFromJson(json); - Map toJson() => _$SimpleClassEnumTypeToUriToJson(this); + Map toJson() => _$SimpleClassOfDateTimeToDoubleToJson(this); } @JsonSerializable() -class SimpleClassIntToUri { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassNullableOfDateTimeToDouble { + final Map? value; - SimpleClassIntToUri( + SimpleClassNullableOfDateTimeToDouble( this.value, - this.nullable, ); - factory SimpleClassIntToUri.fromJson(Map json) => - _$SimpleClassIntToUriFromJson(json); + factory SimpleClassNullableOfDateTimeToDouble.fromJson( + Map json) => + _$SimpleClassNullableOfDateTimeToDoubleFromJson(json); - Map toJson() => _$SimpleClassIntToUriToJson(this); + Map toJson() => + _$SimpleClassNullableOfDateTimeToDoubleToJson(this); } @JsonSerializable() -class SimpleClassObjectToUri { - final Map value; - - @JsonKey(nullable: false) - final Map nullable; +class SimpleClassOfDynamicToDouble { + final Map value; - SimpleClassObjectToUri( + SimpleClassOfDynamicToDouble( this.value, - this.nullable, ); - factory SimpleClassObjectToUri.fromJson(Map json) => - _$SimpleClassObjectToUriFromJson(json); + factory SimpleClassOfDynamicToDouble.fromJson(Map json) => + _$SimpleClassOfDynamicToDoubleFromJson(json); - Map toJson() => _$SimpleClassObjectToUriToJson(this); + Map toJson() => _$SimpleClassOfDynamicToDoubleToJson(this); } @JsonSerializable() -class SimpleClassStringToUri { - final Map value; +class SimpleClassNullableOfDynamicToDouble { + final Map? value; - @JsonKey(nullable: false) - final Map nullable; - - SimpleClassStringToUri( + SimpleClassNullableOfDynamicToDouble( this.value, - this.nullable, ); - factory SimpleClassStringToUri.fromJson(Map json) => - _$SimpleClassStringToUriFromJson(json); + factory SimpleClassNullableOfDynamicToDouble.fromJson( + Map json) => + _$SimpleClassNullableOfDynamicToDoubleFromJson(json); - Map toJson() => _$SimpleClassStringToUriToJson(this); + Map toJson() => + _$SimpleClassNullableOfDynamicToDoubleToJson(this); } @JsonSerializable() -class SimpleClassUriToUri { - final Map value; +class SimpleClassOfEnumTypeToDouble { + final Map value; + + SimpleClassOfEnumTypeToDouble( + this.value, + ); + + factory SimpleClassOfEnumTypeToDouble.fromJson(Map json) => + _$SimpleClassOfEnumTypeToDoubleFromJson(json); + + Map toJson() => _$SimpleClassOfEnumTypeToDoubleToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfEnumTypeToDouble { + final Map? value; + + SimpleClassNullableOfEnumTypeToDouble( + this.value, + ); + + factory SimpleClassNullableOfEnumTypeToDouble.fromJson( + Map json) => + _$SimpleClassNullableOfEnumTypeToDoubleFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfEnumTypeToDoubleToJson(this); +} + +@JsonSerializable() +class SimpleClassOfIntToDouble { + final Map value; + + SimpleClassOfIntToDouble( + this.value, + ); + + factory SimpleClassOfIntToDouble.fromJson(Map json) => + _$SimpleClassOfIntToDoubleFromJson(json); + + Map toJson() => _$SimpleClassOfIntToDoubleToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfIntToDouble { + final Map? value; + + SimpleClassNullableOfIntToDouble( + this.value, + ); + + factory SimpleClassNullableOfIntToDouble.fromJson( + Map json) => + _$SimpleClassNullableOfIntToDoubleFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfIntToDoubleToJson(this); +} + +@JsonSerializable() +class SimpleClassOfObjectToDouble { + final Map value; + + SimpleClassOfObjectToDouble( + this.value, + ); + + factory SimpleClassOfObjectToDouble.fromJson(Map json) => + _$SimpleClassOfObjectToDoubleFromJson(json); + + Map toJson() => _$SimpleClassOfObjectToDoubleToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfObjectToDouble { + final Map? value; + + SimpleClassNullableOfObjectToDouble( + this.value, + ); + + factory SimpleClassNullableOfObjectToDouble.fromJson( + Map json) => + _$SimpleClassNullableOfObjectToDoubleFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfObjectToDoubleToJson(this); +} + +@JsonSerializable() +class SimpleClassOfStringToDouble { + final Map value; + + SimpleClassOfStringToDouble( + this.value, + ); + + factory SimpleClassOfStringToDouble.fromJson(Map json) => + _$SimpleClassOfStringToDoubleFromJson(json); + + Map toJson() => _$SimpleClassOfStringToDoubleToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfStringToDouble { + final Map? value; + + SimpleClassNullableOfStringToDouble( + this.value, + ); + + factory SimpleClassNullableOfStringToDouble.fromJson( + Map json) => + _$SimpleClassNullableOfStringToDoubleFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfStringToDoubleToJson(this); +} + +@JsonSerializable() +class SimpleClassOfUriToDouble { + final Map value; + + SimpleClassOfUriToDouble( + this.value, + ); + + factory SimpleClassOfUriToDouble.fromJson(Map json) => + _$SimpleClassOfUriToDoubleFromJson(json); + + Map toJson() => _$SimpleClassOfUriToDoubleToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfUriToDouble { + final Map? value; + + SimpleClassNullableOfUriToDouble( + this.value, + ); + + factory SimpleClassNullableOfUriToDouble.fromJson( + Map json) => + _$SimpleClassNullableOfUriToDoubleFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfUriToDoubleToJson(this); +} + +@JsonSerializable() +class SimpleClassOfBigIntToDoubleNullable { + final Map value; + + SimpleClassOfBigIntToDoubleNullable( + this.value, + ); + + factory SimpleClassOfBigIntToDoubleNullable.fromJson( + Map json) => + _$SimpleClassOfBigIntToDoubleNullableFromJson(json); + + Map toJson() => + _$SimpleClassOfBigIntToDoubleNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfBigIntToDoubleNullable { + final Map? value; + + SimpleClassNullableOfBigIntToDoubleNullable( + this.value, + ); + + factory SimpleClassNullableOfBigIntToDoubleNullable.fromJson( + Map json) => + _$SimpleClassNullableOfBigIntToDoubleNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfBigIntToDoubleNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfDateTimeToDoubleNullable { + final Map value; + + SimpleClassOfDateTimeToDoubleNullable( + this.value, + ); + + factory SimpleClassOfDateTimeToDoubleNullable.fromJson( + Map json) => + _$SimpleClassOfDateTimeToDoubleNullableFromJson(json); + + Map toJson() => + _$SimpleClassOfDateTimeToDoubleNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfDateTimeToDoubleNullable { + final Map? value; + + SimpleClassNullableOfDateTimeToDoubleNullable( + this.value, + ); + + factory SimpleClassNullableOfDateTimeToDoubleNullable.fromJson( + Map json) => + _$SimpleClassNullableOfDateTimeToDoubleNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfDateTimeToDoubleNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfDynamicToDoubleNullable { + final Map value; + + SimpleClassOfDynamicToDoubleNullable( + this.value, + ); + + factory SimpleClassOfDynamicToDoubleNullable.fromJson( + Map json) => + _$SimpleClassOfDynamicToDoubleNullableFromJson(json); + + Map toJson() => + _$SimpleClassOfDynamicToDoubleNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfDynamicToDoubleNullable { + final Map? value; + + SimpleClassNullableOfDynamicToDoubleNullable( + this.value, + ); + + factory SimpleClassNullableOfDynamicToDoubleNullable.fromJson( + Map json) => + _$SimpleClassNullableOfDynamicToDoubleNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfDynamicToDoubleNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfEnumTypeToDoubleNullable { + final Map value; + + SimpleClassOfEnumTypeToDoubleNullable( + this.value, + ); + + factory SimpleClassOfEnumTypeToDoubleNullable.fromJson( + Map json) => + _$SimpleClassOfEnumTypeToDoubleNullableFromJson(json); + + Map toJson() => + _$SimpleClassOfEnumTypeToDoubleNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfEnumTypeToDoubleNullable { + final Map? value; + + SimpleClassNullableOfEnumTypeToDoubleNullable( + this.value, + ); + + factory SimpleClassNullableOfEnumTypeToDoubleNullable.fromJson( + Map json) => + _$SimpleClassNullableOfEnumTypeToDoubleNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfEnumTypeToDoubleNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfIntToDoubleNullable { + final Map value; + + SimpleClassOfIntToDoubleNullable( + this.value, + ); + + factory SimpleClassOfIntToDoubleNullable.fromJson( + Map json) => + _$SimpleClassOfIntToDoubleNullableFromJson(json); + + Map toJson() => + _$SimpleClassOfIntToDoubleNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfIntToDoubleNullable { + final Map? value; + + SimpleClassNullableOfIntToDoubleNullable( + this.value, + ); + + factory SimpleClassNullableOfIntToDoubleNullable.fromJson( + Map json) => + _$SimpleClassNullableOfIntToDoubleNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfIntToDoubleNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfObjectToDoubleNullable { + final Map value; + + SimpleClassOfObjectToDoubleNullable( + this.value, + ); + + factory SimpleClassOfObjectToDoubleNullable.fromJson( + Map json) => + _$SimpleClassOfObjectToDoubleNullableFromJson(json); + + Map toJson() => + _$SimpleClassOfObjectToDoubleNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfObjectToDoubleNullable { + final Map? value; + + SimpleClassNullableOfObjectToDoubleNullable( + this.value, + ); + + factory SimpleClassNullableOfObjectToDoubleNullable.fromJson( + Map json) => + _$SimpleClassNullableOfObjectToDoubleNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfObjectToDoubleNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfStringToDoubleNullable { + final Map value; + + SimpleClassOfStringToDoubleNullable( + this.value, + ); + + factory SimpleClassOfStringToDoubleNullable.fromJson( + Map json) => + _$SimpleClassOfStringToDoubleNullableFromJson(json); + + Map toJson() => + _$SimpleClassOfStringToDoubleNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfStringToDoubleNullable { + final Map? value; + + SimpleClassNullableOfStringToDoubleNullable( + this.value, + ); + + factory SimpleClassNullableOfStringToDoubleNullable.fromJson( + Map json) => + _$SimpleClassNullableOfStringToDoubleNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfStringToDoubleNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfUriToDoubleNullable { + final Map value; + + SimpleClassOfUriToDoubleNullable( + this.value, + ); + + factory SimpleClassOfUriToDoubleNullable.fromJson( + Map json) => + _$SimpleClassOfUriToDoubleNullableFromJson(json); + + Map toJson() => + _$SimpleClassOfUriToDoubleNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfUriToDoubleNullable { + final Map? value; + + SimpleClassNullableOfUriToDoubleNullable( + this.value, + ); + + factory SimpleClassNullableOfUriToDoubleNullable.fromJson( + Map json) => + _$SimpleClassNullableOfUriToDoubleNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfUriToDoubleNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfBigIntToDuration { + final Map value; + + SimpleClassOfBigIntToDuration( + this.value, + ); + + factory SimpleClassOfBigIntToDuration.fromJson(Map json) => + _$SimpleClassOfBigIntToDurationFromJson(json); + + Map toJson() => _$SimpleClassOfBigIntToDurationToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfBigIntToDuration { + final Map? value; + + SimpleClassNullableOfBigIntToDuration( + this.value, + ); + + factory SimpleClassNullableOfBigIntToDuration.fromJson( + Map json) => + _$SimpleClassNullableOfBigIntToDurationFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfBigIntToDurationToJson(this); +} + +@JsonSerializable() +class SimpleClassOfDateTimeToDuration { + final Map value; + + SimpleClassOfDateTimeToDuration( + this.value, + ); + + factory SimpleClassOfDateTimeToDuration.fromJson(Map json) => + _$SimpleClassOfDateTimeToDurationFromJson(json); + + Map toJson() => + _$SimpleClassOfDateTimeToDurationToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfDateTimeToDuration { + final Map? value; + + SimpleClassNullableOfDateTimeToDuration( + this.value, + ); + + factory SimpleClassNullableOfDateTimeToDuration.fromJson( + Map json) => + _$SimpleClassNullableOfDateTimeToDurationFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfDateTimeToDurationToJson(this); +} + +@JsonSerializable() +class SimpleClassOfDynamicToDuration { + final Map value; + + SimpleClassOfDynamicToDuration( + this.value, + ); + + factory SimpleClassOfDynamicToDuration.fromJson(Map json) => + _$SimpleClassOfDynamicToDurationFromJson(json); + + Map toJson() => _$SimpleClassOfDynamicToDurationToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfDynamicToDuration { + final Map? value; + + SimpleClassNullableOfDynamicToDuration( + this.value, + ); + + factory SimpleClassNullableOfDynamicToDuration.fromJson( + Map json) => + _$SimpleClassNullableOfDynamicToDurationFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfDynamicToDurationToJson(this); +} + +@JsonSerializable() +class SimpleClassOfEnumTypeToDuration { + final Map value; + + SimpleClassOfEnumTypeToDuration( + this.value, + ); + + factory SimpleClassOfEnumTypeToDuration.fromJson(Map json) => + _$SimpleClassOfEnumTypeToDurationFromJson(json); + + Map toJson() => + _$SimpleClassOfEnumTypeToDurationToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfEnumTypeToDuration { + final Map? value; + + SimpleClassNullableOfEnumTypeToDuration( + this.value, + ); + + factory SimpleClassNullableOfEnumTypeToDuration.fromJson( + Map json) => + _$SimpleClassNullableOfEnumTypeToDurationFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfEnumTypeToDurationToJson(this); +} + +@JsonSerializable() +class SimpleClassOfIntToDuration { + final Map value; + + SimpleClassOfIntToDuration( + this.value, + ); + + factory SimpleClassOfIntToDuration.fromJson(Map json) => + _$SimpleClassOfIntToDurationFromJson(json); + + Map toJson() => _$SimpleClassOfIntToDurationToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfIntToDuration { + final Map? value; + + SimpleClassNullableOfIntToDuration( + this.value, + ); + + factory SimpleClassNullableOfIntToDuration.fromJson( + Map json) => + _$SimpleClassNullableOfIntToDurationFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfIntToDurationToJson(this); +} + +@JsonSerializable() +class SimpleClassOfObjectToDuration { + final Map value; + + SimpleClassOfObjectToDuration( + this.value, + ); + + factory SimpleClassOfObjectToDuration.fromJson(Map json) => + _$SimpleClassOfObjectToDurationFromJson(json); + + Map toJson() => _$SimpleClassOfObjectToDurationToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfObjectToDuration { + final Map? value; + + SimpleClassNullableOfObjectToDuration( + this.value, + ); + + factory SimpleClassNullableOfObjectToDuration.fromJson( + Map json) => + _$SimpleClassNullableOfObjectToDurationFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfObjectToDurationToJson(this); +} + +@JsonSerializable() +class SimpleClassOfStringToDuration { + final Map value; + + SimpleClassOfStringToDuration( + this.value, + ); + + factory SimpleClassOfStringToDuration.fromJson(Map json) => + _$SimpleClassOfStringToDurationFromJson(json); + + Map toJson() => _$SimpleClassOfStringToDurationToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfStringToDuration { + final Map? value; + + SimpleClassNullableOfStringToDuration( + this.value, + ); + + factory SimpleClassNullableOfStringToDuration.fromJson( + Map json) => + _$SimpleClassNullableOfStringToDurationFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfStringToDurationToJson(this); +} + +@JsonSerializable() +class SimpleClassOfUriToDuration { + final Map value; + + SimpleClassOfUriToDuration( + this.value, + ); + + factory SimpleClassOfUriToDuration.fromJson(Map json) => + _$SimpleClassOfUriToDurationFromJson(json); + + Map toJson() => _$SimpleClassOfUriToDurationToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfUriToDuration { + final Map? value; + + SimpleClassNullableOfUriToDuration( + this.value, + ); + + factory SimpleClassNullableOfUriToDuration.fromJson( + Map json) => + _$SimpleClassNullableOfUriToDurationFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfUriToDurationToJson(this); +} + +@JsonSerializable() +class SimpleClassOfBigIntToDurationNullable { + final Map value; + + SimpleClassOfBigIntToDurationNullable( + this.value, + ); + + factory SimpleClassOfBigIntToDurationNullable.fromJson( + Map json) => + _$SimpleClassOfBigIntToDurationNullableFromJson(json); + + Map toJson() => + _$SimpleClassOfBigIntToDurationNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfBigIntToDurationNullable { + final Map? value; + + SimpleClassNullableOfBigIntToDurationNullable( + this.value, + ); + + factory SimpleClassNullableOfBigIntToDurationNullable.fromJson( + Map json) => + _$SimpleClassNullableOfBigIntToDurationNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfBigIntToDurationNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfDateTimeToDurationNullable { + final Map value; + + SimpleClassOfDateTimeToDurationNullable( + this.value, + ); + + factory SimpleClassOfDateTimeToDurationNullable.fromJson( + Map json) => + _$SimpleClassOfDateTimeToDurationNullableFromJson(json); + + Map toJson() => + _$SimpleClassOfDateTimeToDurationNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfDateTimeToDurationNullable { + final Map? value; + + SimpleClassNullableOfDateTimeToDurationNullable( + this.value, + ); + + factory SimpleClassNullableOfDateTimeToDurationNullable.fromJson( + Map json) => + _$SimpleClassNullableOfDateTimeToDurationNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfDateTimeToDurationNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfDynamicToDurationNullable { + final Map value; + + SimpleClassOfDynamicToDurationNullable( + this.value, + ); + + factory SimpleClassOfDynamicToDurationNullable.fromJson( + Map json) => + _$SimpleClassOfDynamicToDurationNullableFromJson(json); + + Map toJson() => + _$SimpleClassOfDynamicToDurationNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfDynamicToDurationNullable { + final Map? value; + + SimpleClassNullableOfDynamicToDurationNullable( + this.value, + ); + + factory SimpleClassNullableOfDynamicToDurationNullable.fromJson( + Map json) => + _$SimpleClassNullableOfDynamicToDurationNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfDynamicToDurationNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfEnumTypeToDurationNullable { + final Map value; + + SimpleClassOfEnumTypeToDurationNullable( + this.value, + ); + + factory SimpleClassOfEnumTypeToDurationNullable.fromJson( + Map json) => + _$SimpleClassOfEnumTypeToDurationNullableFromJson(json); + + Map toJson() => + _$SimpleClassOfEnumTypeToDurationNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfEnumTypeToDurationNullable { + final Map? value; + + SimpleClassNullableOfEnumTypeToDurationNullable( + this.value, + ); + + factory SimpleClassNullableOfEnumTypeToDurationNullable.fromJson( + Map json) => + _$SimpleClassNullableOfEnumTypeToDurationNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfEnumTypeToDurationNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfIntToDurationNullable { + final Map value; + + SimpleClassOfIntToDurationNullable( + this.value, + ); + + factory SimpleClassOfIntToDurationNullable.fromJson( + Map json) => + _$SimpleClassOfIntToDurationNullableFromJson(json); + + Map toJson() => + _$SimpleClassOfIntToDurationNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfIntToDurationNullable { + final Map? value; + + SimpleClassNullableOfIntToDurationNullable( + this.value, + ); + + factory SimpleClassNullableOfIntToDurationNullable.fromJson( + Map json) => + _$SimpleClassNullableOfIntToDurationNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfIntToDurationNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfObjectToDurationNullable { + final Map value; + + SimpleClassOfObjectToDurationNullable( + this.value, + ); + + factory SimpleClassOfObjectToDurationNullable.fromJson( + Map json) => + _$SimpleClassOfObjectToDurationNullableFromJson(json); + + Map toJson() => + _$SimpleClassOfObjectToDurationNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfObjectToDurationNullable { + final Map? value; + + SimpleClassNullableOfObjectToDurationNullable( + this.value, + ); + + factory SimpleClassNullableOfObjectToDurationNullable.fromJson( + Map json) => + _$SimpleClassNullableOfObjectToDurationNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfObjectToDurationNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfStringToDurationNullable { + final Map value; + + SimpleClassOfStringToDurationNullable( + this.value, + ); + + factory SimpleClassOfStringToDurationNullable.fromJson( + Map json) => + _$SimpleClassOfStringToDurationNullableFromJson(json); + + Map toJson() => + _$SimpleClassOfStringToDurationNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfStringToDurationNullable { + final Map? value; + + SimpleClassNullableOfStringToDurationNullable( + this.value, + ); + + factory SimpleClassNullableOfStringToDurationNullable.fromJson( + Map json) => + _$SimpleClassNullableOfStringToDurationNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfStringToDurationNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfUriToDurationNullable { + final Map value; + + SimpleClassOfUriToDurationNullable( + this.value, + ); + + factory SimpleClassOfUriToDurationNullable.fromJson( + Map json) => + _$SimpleClassOfUriToDurationNullableFromJson(json); + + Map toJson() => + _$SimpleClassOfUriToDurationNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfUriToDurationNullable { + final Map? value; + + SimpleClassNullableOfUriToDurationNullable( + this.value, + ); + + factory SimpleClassNullableOfUriToDurationNullable.fromJson( + Map json) => + _$SimpleClassNullableOfUriToDurationNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfUriToDurationNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfBigIntToDynamic { + final Map value; + + SimpleClassOfBigIntToDynamic( + this.value, + ); + + factory SimpleClassOfBigIntToDynamic.fromJson(Map json) => + _$SimpleClassOfBigIntToDynamicFromJson(json); + + Map toJson() => _$SimpleClassOfBigIntToDynamicToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfBigIntToDynamic { + final Map? value; + + SimpleClassNullableOfBigIntToDynamic( + this.value, + ); + + factory SimpleClassNullableOfBigIntToDynamic.fromJson( + Map json) => + _$SimpleClassNullableOfBigIntToDynamicFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfBigIntToDynamicToJson(this); +} + +@JsonSerializable() +class SimpleClassOfDateTimeToDynamic { + final Map value; + + SimpleClassOfDateTimeToDynamic( + this.value, + ); + + factory SimpleClassOfDateTimeToDynamic.fromJson(Map json) => + _$SimpleClassOfDateTimeToDynamicFromJson(json); + + Map toJson() => _$SimpleClassOfDateTimeToDynamicToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfDateTimeToDynamic { + final Map? value; + + SimpleClassNullableOfDateTimeToDynamic( + this.value, + ); + + factory SimpleClassNullableOfDateTimeToDynamic.fromJson( + Map json) => + _$SimpleClassNullableOfDateTimeToDynamicFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfDateTimeToDynamicToJson(this); +} + +@JsonSerializable() +class SimpleClassOfDynamicToDynamic { + final Map value; + + SimpleClassOfDynamicToDynamic( + this.value, + ); + + factory SimpleClassOfDynamicToDynamic.fromJson(Map json) => + _$SimpleClassOfDynamicToDynamicFromJson(json); + + Map toJson() => _$SimpleClassOfDynamicToDynamicToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfDynamicToDynamic { + final Map? value; + + SimpleClassNullableOfDynamicToDynamic( + this.value, + ); + + factory SimpleClassNullableOfDynamicToDynamic.fromJson( + Map json) => + _$SimpleClassNullableOfDynamicToDynamicFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfDynamicToDynamicToJson(this); +} + +@JsonSerializable() +class SimpleClassOfEnumTypeToDynamic { + final Map value; + + SimpleClassOfEnumTypeToDynamic( + this.value, + ); + + factory SimpleClassOfEnumTypeToDynamic.fromJson(Map json) => + _$SimpleClassOfEnumTypeToDynamicFromJson(json); + + Map toJson() => _$SimpleClassOfEnumTypeToDynamicToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfEnumTypeToDynamic { + final Map? value; + + SimpleClassNullableOfEnumTypeToDynamic( + this.value, + ); + + factory SimpleClassNullableOfEnumTypeToDynamic.fromJson( + Map json) => + _$SimpleClassNullableOfEnumTypeToDynamicFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfEnumTypeToDynamicToJson(this); +} + +@JsonSerializable() +class SimpleClassOfIntToDynamic { + final Map value; + + SimpleClassOfIntToDynamic( + this.value, + ); + + factory SimpleClassOfIntToDynamic.fromJson(Map json) => + _$SimpleClassOfIntToDynamicFromJson(json); + + Map toJson() => _$SimpleClassOfIntToDynamicToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfIntToDynamic { + final Map? value; + + SimpleClassNullableOfIntToDynamic( + this.value, + ); + + factory SimpleClassNullableOfIntToDynamic.fromJson( + Map json) => + _$SimpleClassNullableOfIntToDynamicFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfIntToDynamicToJson(this); +} + +@JsonSerializable() +class SimpleClassOfObjectToDynamic { + final Map value; + + SimpleClassOfObjectToDynamic( + this.value, + ); + + factory SimpleClassOfObjectToDynamic.fromJson(Map json) => + _$SimpleClassOfObjectToDynamicFromJson(json); + + Map toJson() => _$SimpleClassOfObjectToDynamicToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfObjectToDynamic { + final Map? value; + + SimpleClassNullableOfObjectToDynamic( + this.value, + ); + + factory SimpleClassNullableOfObjectToDynamic.fromJson( + Map json) => + _$SimpleClassNullableOfObjectToDynamicFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfObjectToDynamicToJson(this); +} + +@JsonSerializable() +class SimpleClassOfStringToDynamic { + final Map value; + + SimpleClassOfStringToDynamic( + this.value, + ); + + factory SimpleClassOfStringToDynamic.fromJson(Map json) => + _$SimpleClassOfStringToDynamicFromJson(json); + + Map toJson() => _$SimpleClassOfStringToDynamicToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfStringToDynamic { + final Map? value; + + SimpleClassNullableOfStringToDynamic( + this.value, + ); + + factory SimpleClassNullableOfStringToDynamic.fromJson( + Map json) => + _$SimpleClassNullableOfStringToDynamicFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfStringToDynamicToJson(this); +} + +@JsonSerializable() +class SimpleClassOfUriToDynamic { + final Map value; + + SimpleClassOfUriToDynamic( + this.value, + ); + + factory SimpleClassOfUriToDynamic.fromJson(Map json) => + _$SimpleClassOfUriToDynamicFromJson(json); + + Map toJson() => _$SimpleClassOfUriToDynamicToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfUriToDynamic { + final Map? value; + + SimpleClassNullableOfUriToDynamic( + this.value, + ); + + factory SimpleClassNullableOfUriToDynamic.fromJson( + Map json) => + _$SimpleClassNullableOfUriToDynamicFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfUriToDynamicToJson(this); +} + +@JsonSerializable() +class SimpleClassOfBigIntToEnumType { + final Map value; + + SimpleClassOfBigIntToEnumType( + this.value, + ); + + factory SimpleClassOfBigIntToEnumType.fromJson(Map json) => + _$SimpleClassOfBigIntToEnumTypeFromJson(json); + + Map toJson() => _$SimpleClassOfBigIntToEnumTypeToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfBigIntToEnumType { + final Map? value; + + SimpleClassNullableOfBigIntToEnumType( + this.value, + ); + + factory SimpleClassNullableOfBigIntToEnumType.fromJson( + Map json) => + _$SimpleClassNullableOfBigIntToEnumTypeFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfBigIntToEnumTypeToJson(this); +} + +@JsonSerializable() +class SimpleClassOfDateTimeToEnumType { + final Map value; + + SimpleClassOfDateTimeToEnumType( + this.value, + ); + + factory SimpleClassOfDateTimeToEnumType.fromJson(Map json) => + _$SimpleClassOfDateTimeToEnumTypeFromJson(json); + + Map toJson() => + _$SimpleClassOfDateTimeToEnumTypeToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfDateTimeToEnumType { + final Map? value; + + SimpleClassNullableOfDateTimeToEnumType( + this.value, + ); + + factory SimpleClassNullableOfDateTimeToEnumType.fromJson( + Map json) => + _$SimpleClassNullableOfDateTimeToEnumTypeFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfDateTimeToEnumTypeToJson(this); +} + +@JsonSerializable() +class SimpleClassOfDynamicToEnumType { + final Map value; + + SimpleClassOfDynamicToEnumType( + this.value, + ); + + factory SimpleClassOfDynamicToEnumType.fromJson(Map json) => + _$SimpleClassOfDynamicToEnumTypeFromJson(json); + + Map toJson() => _$SimpleClassOfDynamicToEnumTypeToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfDynamicToEnumType { + final Map? value; + + SimpleClassNullableOfDynamicToEnumType( + this.value, + ); + + factory SimpleClassNullableOfDynamicToEnumType.fromJson( + Map json) => + _$SimpleClassNullableOfDynamicToEnumTypeFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfDynamicToEnumTypeToJson(this); +} + +@JsonSerializable() +class SimpleClassOfEnumTypeToEnumType { + final Map value; + + SimpleClassOfEnumTypeToEnumType( + this.value, + ); + + factory SimpleClassOfEnumTypeToEnumType.fromJson(Map json) => + _$SimpleClassOfEnumTypeToEnumTypeFromJson(json); + + Map toJson() => + _$SimpleClassOfEnumTypeToEnumTypeToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfEnumTypeToEnumType { + final Map? value; + + SimpleClassNullableOfEnumTypeToEnumType( + this.value, + ); + + factory SimpleClassNullableOfEnumTypeToEnumType.fromJson( + Map json) => + _$SimpleClassNullableOfEnumTypeToEnumTypeFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfEnumTypeToEnumTypeToJson(this); +} + +@JsonSerializable() +class SimpleClassOfIntToEnumType { + final Map value; + + SimpleClassOfIntToEnumType( + this.value, + ); + + factory SimpleClassOfIntToEnumType.fromJson(Map json) => + _$SimpleClassOfIntToEnumTypeFromJson(json); + + Map toJson() => _$SimpleClassOfIntToEnumTypeToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfIntToEnumType { + final Map? value; + + SimpleClassNullableOfIntToEnumType( + this.value, + ); + + factory SimpleClassNullableOfIntToEnumType.fromJson( + Map json) => + _$SimpleClassNullableOfIntToEnumTypeFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfIntToEnumTypeToJson(this); +} + +@JsonSerializable() +class SimpleClassOfObjectToEnumType { + final Map value; + + SimpleClassOfObjectToEnumType( + this.value, + ); + + factory SimpleClassOfObjectToEnumType.fromJson(Map json) => + _$SimpleClassOfObjectToEnumTypeFromJson(json); + + Map toJson() => _$SimpleClassOfObjectToEnumTypeToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfObjectToEnumType { + final Map? value; + + SimpleClassNullableOfObjectToEnumType( + this.value, + ); + + factory SimpleClassNullableOfObjectToEnumType.fromJson( + Map json) => + _$SimpleClassNullableOfObjectToEnumTypeFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfObjectToEnumTypeToJson(this); +} + +@JsonSerializable() +class SimpleClassOfStringToEnumType { + final Map value; + + SimpleClassOfStringToEnumType( + this.value, + ); + + factory SimpleClassOfStringToEnumType.fromJson(Map json) => + _$SimpleClassOfStringToEnumTypeFromJson(json); + + Map toJson() => _$SimpleClassOfStringToEnumTypeToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfStringToEnumType { + final Map? value; + + SimpleClassNullableOfStringToEnumType( + this.value, + ); + + factory SimpleClassNullableOfStringToEnumType.fromJson( + Map json) => + _$SimpleClassNullableOfStringToEnumTypeFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfStringToEnumTypeToJson(this); +} + +@JsonSerializable() +class SimpleClassOfUriToEnumType { + final Map value; + + SimpleClassOfUriToEnumType( + this.value, + ); + + factory SimpleClassOfUriToEnumType.fromJson(Map json) => + _$SimpleClassOfUriToEnumTypeFromJson(json); + + Map toJson() => _$SimpleClassOfUriToEnumTypeToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfUriToEnumType { + final Map? value; + + SimpleClassNullableOfUriToEnumType( + this.value, + ); + + factory SimpleClassNullableOfUriToEnumType.fromJson( + Map json) => + _$SimpleClassNullableOfUriToEnumTypeFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfUriToEnumTypeToJson(this); +} + +@JsonSerializable() +class SimpleClassOfBigIntToEnumTypeNullable { + final Map value; + + SimpleClassOfBigIntToEnumTypeNullable( + this.value, + ); + + factory SimpleClassOfBigIntToEnumTypeNullable.fromJson( + Map json) => + _$SimpleClassOfBigIntToEnumTypeNullableFromJson(json); + + Map toJson() => + _$SimpleClassOfBigIntToEnumTypeNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfBigIntToEnumTypeNullable { + final Map? value; + + SimpleClassNullableOfBigIntToEnumTypeNullable( + this.value, + ); + + factory SimpleClassNullableOfBigIntToEnumTypeNullable.fromJson( + Map json) => + _$SimpleClassNullableOfBigIntToEnumTypeNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfBigIntToEnumTypeNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfDateTimeToEnumTypeNullable { + final Map value; + + SimpleClassOfDateTimeToEnumTypeNullable( + this.value, + ); + + factory SimpleClassOfDateTimeToEnumTypeNullable.fromJson( + Map json) => + _$SimpleClassOfDateTimeToEnumTypeNullableFromJson(json); + + Map toJson() => + _$SimpleClassOfDateTimeToEnumTypeNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfDateTimeToEnumTypeNullable { + final Map? value; + + SimpleClassNullableOfDateTimeToEnumTypeNullable( + this.value, + ); + + factory SimpleClassNullableOfDateTimeToEnumTypeNullable.fromJson( + Map json) => + _$SimpleClassNullableOfDateTimeToEnumTypeNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfDateTimeToEnumTypeNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfDynamicToEnumTypeNullable { + final Map value; + + SimpleClassOfDynamicToEnumTypeNullable( + this.value, + ); + + factory SimpleClassOfDynamicToEnumTypeNullable.fromJson( + Map json) => + _$SimpleClassOfDynamicToEnumTypeNullableFromJson(json); + + Map toJson() => + _$SimpleClassOfDynamicToEnumTypeNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfDynamicToEnumTypeNullable { + final Map? value; + + SimpleClassNullableOfDynamicToEnumTypeNullable( + this.value, + ); + + factory SimpleClassNullableOfDynamicToEnumTypeNullable.fromJson( + Map json) => + _$SimpleClassNullableOfDynamicToEnumTypeNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfDynamicToEnumTypeNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfEnumTypeToEnumTypeNullable { + final Map value; + + SimpleClassOfEnumTypeToEnumTypeNullable( + this.value, + ); + + factory SimpleClassOfEnumTypeToEnumTypeNullable.fromJson( + Map json) => + _$SimpleClassOfEnumTypeToEnumTypeNullableFromJson(json); + + Map toJson() => + _$SimpleClassOfEnumTypeToEnumTypeNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfEnumTypeToEnumTypeNullable { + final Map? value; + + SimpleClassNullableOfEnumTypeToEnumTypeNullable( + this.value, + ); + + factory SimpleClassNullableOfEnumTypeToEnumTypeNullable.fromJson( + Map json) => + _$SimpleClassNullableOfEnumTypeToEnumTypeNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfEnumTypeToEnumTypeNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfIntToEnumTypeNullable { + final Map value; + + SimpleClassOfIntToEnumTypeNullable( + this.value, + ); + + factory SimpleClassOfIntToEnumTypeNullable.fromJson( + Map json) => + _$SimpleClassOfIntToEnumTypeNullableFromJson(json); + + Map toJson() => + _$SimpleClassOfIntToEnumTypeNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfIntToEnumTypeNullable { + final Map? value; + + SimpleClassNullableOfIntToEnumTypeNullable( + this.value, + ); + + factory SimpleClassNullableOfIntToEnumTypeNullable.fromJson( + Map json) => + _$SimpleClassNullableOfIntToEnumTypeNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfIntToEnumTypeNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfObjectToEnumTypeNullable { + final Map value; + + SimpleClassOfObjectToEnumTypeNullable( + this.value, + ); + + factory SimpleClassOfObjectToEnumTypeNullable.fromJson( + Map json) => + _$SimpleClassOfObjectToEnumTypeNullableFromJson(json); + + Map toJson() => + _$SimpleClassOfObjectToEnumTypeNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfObjectToEnumTypeNullable { + final Map? value; + + SimpleClassNullableOfObjectToEnumTypeNullable( + this.value, + ); + + factory SimpleClassNullableOfObjectToEnumTypeNullable.fromJson( + Map json) => + _$SimpleClassNullableOfObjectToEnumTypeNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfObjectToEnumTypeNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfStringToEnumTypeNullable { + final Map value; + + SimpleClassOfStringToEnumTypeNullable( + this.value, + ); + + factory SimpleClassOfStringToEnumTypeNullable.fromJson( + Map json) => + _$SimpleClassOfStringToEnumTypeNullableFromJson(json); + + Map toJson() => + _$SimpleClassOfStringToEnumTypeNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfStringToEnumTypeNullable { + final Map? value; + + SimpleClassNullableOfStringToEnumTypeNullable( + this.value, + ); + + factory SimpleClassNullableOfStringToEnumTypeNullable.fromJson( + Map json) => + _$SimpleClassNullableOfStringToEnumTypeNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfStringToEnumTypeNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfUriToEnumTypeNullable { + final Map value; + + SimpleClassOfUriToEnumTypeNullable( + this.value, + ); + + factory SimpleClassOfUriToEnumTypeNullable.fromJson( + Map json) => + _$SimpleClassOfUriToEnumTypeNullableFromJson(json); + + Map toJson() => + _$SimpleClassOfUriToEnumTypeNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfUriToEnumTypeNullable { + final Map? value; + + SimpleClassNullableOfUriToEnumTypeNullable( + this.value, + ); + + factory SimpleClassNullableOfUriToEnumTypeNullable.fromJson( + Map json) => + _$SimpleClassNullableOfUriToEnumTypeNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfUriToEnumTypeNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfBigIntToInt { + final Map value; + + SimpleClassOfBigIntToInt( + this.value, + ); + + factory SimpleClassOfBigIntToInt.fromJson(Map json) => + _$SimpleClassOfBigIntToIntFromJson(json); + + Map toJson() => _$SimpleClassOfBigIntToIntToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfBigIntToInt { + final Map? value; + + SimpleClassNullableOfBigIntToInt( + this.value, + ); + + factory SimpleClassNullableOfBigIntToInt.fromJson( + Map json) => + _$SimpleClassNullableOfBigIntToIntFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfBigIntToIntToJson(this); +} + +@JsonSerializable() +class SimpleClassOfDateTimeToInt { + final Map value; + + SimpleClassOfDateTimeToInt( + this.value, + ); + + factory SimpleClassOfDateTimeToInt.fromJson(Map json) => + _$SimpleClassOfDateTimeToIntFromJson(json); + + Map toJson() => _$SimpleClassOfDateTimeToIntToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfDateTimeToInt { + final Map? value; + + SimpleClassNullableOfDateTimeToInt( + this.value, + ); + + factory SimpleClassNullableOfDateTimeToInt.fromJson( + Map json) => + _$SimpleClassNullableOfDateTimeToIntFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfDateTimeToIntToJson(this); +} + +@JsonSerializable() +class SimpleClassOfDynamicToInt { + final Map value; + + SimpleClassOfDynamicToInt( + this.value, + ); + + factory SimpleClassOfDynamicToInt.fromJson(Map json) => + _$SimpleClassOfDynamicToIntFromJson(json); + + Map toJson() => _$SimpleClassOfDynamicToIntToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfDynamicToInt { + final Map? value; + + SimpleClassNullableOfDynamicToInt( + this.value, + ); + + factory SimpleClassNullableOfDynamicToInt.fromJson( + Map json) => + _$SimpleClassNullableOfDynamicToIntFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfDynamicToIntToJson(this); +} + +@JsonSerializable() +class SimpleClassOfEnumTypeToInt { + final Map value; + + SimpleClassOfEnumTypeToInt( + this.value, + ); + + factory SimpleClassOfEnumTypeToInt.fromJson(Map json) => + _$SimpleClassOfEnumTypeToIntFromJson(json); + + Map toJson() => _$SimpleClassOfEnumTypeToIntToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfEnumTypeToInt { + final Map? value; + + SimpleClassNullableOfEnumTypeToInt( + this.value, + ); + + factory SimpleClassNullableOfEnumTypeToInt.fromJson( + Map json) => + _$SimpleClassNullableOfEnumTypeToIntFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfEnumTypeToIntToJson(this); +} + +@JsonSerializable() +class SimpleClassOfIntToInt { + final Map value; + + SimpleClassOfIntToInt( + this.value, + ); + + factory SimpleClassOfIntToInt.fromJson(Map json) => + _$SimpleClassOfIntToIntFromJson(json); + + Map toJson() => _$SimpleClassOfIntToIntToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfIntToInt { + final Map? value; + + SimpleClassNullableOfIntToInt( + this.value, + ); + + factory SimpleClassNullableOfIntToInt.fromJson(Map json) => + _$SimpleClassNullableOfIntToIntFromJson(json); + + Map toJson() => _$SimpleClassNullableOfIntToIntToJson(this); +} + +@JsonSerializable() +class SimpleClassOfObjectToInt { + final Map value; + + SimpleClassOfObjectToInt( + this.value, + ); + + factory SimpleClassOfObjectToInt.fromJson(Map json) => + _$SimpleClassOfObjectToIntFromJson(json); + + Map toJson() => _$SimpleClassOfObjectToIntToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfObjectToInt { + final Map? value; + + SimpleClassNullableOfObjectToInt( + this.value, + ); + + factory SimpleClassNullableOfObjectToInt.fromJson( + Map json) => + _$SimpleClassNullableOfObjectToIntFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfObjectToIntToJson(this); +} + +@JsonSerializable() +class SimpleClassOfStringToInt { + final Map value; + + SimpleClassOfStringToInt( + this.value, + ); + + factory SimpleClassOfStringToInt.fromJson(Map json) => + _$SimpleClassOfStringToIntFromJson(json); + + Map toJson() => _$SimpleClassOfStringToIntToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfStringToInt { + final Map? value; + + SimpleClassNullableOfStringToInt( + this.value, + ); + + factory SimpleClassNullableOfStringToInt.fromJson( + Map json) => + _$SimpleClassNullableOfStringToIntFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfStringToIntToJson(this); +} + +@JsonSerializable() +class SimpleClassOfUriToInt { + final Map value; + + SimpleClassOfUriToInt( + this.value, + ); + + factory SimpleClassOfUriToInt.fromJson(Map json) => + _$SimpleClassOfUriToIntFromJson(json); + + Map toJson() => _$SimpleClassOfUriToIntToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfUriToInt { + final Map? value; + + SimpleClassNullableOfUriToInt( + this.value, + ); + + factory SimpleClassNullableOfUriToInt.fromJson(Map json) => + _$SimpleClassNullableOfUriToIntFromJson(json); + + Map toJson() => _$SimpleClassNullableOfUriToIntToJson(this); +} + +@JsonSerializable() +class SimpleClassOfBigIntToIntNullable { + final Map value; + + SimpleClassOfBigIntToIntNullable( + this.value, + ); + + factory SimpleClassOfBigIntToIntNullable.fromJson( + Map json) => + _$SimpleClassOfBigIntToIntNullableFromJson(json); + + Map toJson() => + _$SimpleClassOfBigIntToIntNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfBigIntToIntNullable { + final Map? value; + + SimpleClassNullableOfBigIntToIntNullable( + this.value, + ); + + factory SimpleClassNullableOfBigIntToIntNullable.fromJson( + Map json) => + _$SimpleClassNullableOfBigIntToIntNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfBigIntToIntNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfDateTimeToIntNullable { + final Map value; + + SimpleClassOfDateTimeToIntNullable( + this.value, + ); + + factory SimpleClassOfDateTimeToIntNullable.fromJson( + Map json) => + _$SimpleClassOfDateTimeToIntNullableFromJson(json); + + Map toJson() => + _$SimpleClassOfDateTimeToIntNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfDateTimeToIntNullable { + final Map? value; + + SimpleClassNullableOfDateTimeToIntNullable( + this.value, + ); + + factory SimpleClassNullableOfDateTimeToIntNullable.fromJson( + Map json) => + _$SimpleClassNullableOfDateTimeToIntNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfDateTimeToIntNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfDynamicToIntNullable { + final Map value; + + SimpleClassOfDynamicToIntNullable( + this.value, + ); + + factory SimpleClassOfDynamicToIntNullable.fromJson( + Map json) => + _$SimpleClassOfDynamicToIntNullableFromJson(json); + + Map toJson() => + _$SimpleClassOfDynamicToIntNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfDynamicToIntNullable { + final Map? value; + + SimpleClassNullableOfDynamicToIntNullable( + this.value, + ); + + factory SimpleClassNullableOfDynamicToIntNullable.fromJson( + Map json) => + _$SimpleClassNullableOfDynamicToIntNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfDynamicToIntNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfEnumTypeToIntNullable { + final Map value; + + SimpleClassOfEnumTypeToIntNullable( + this.value, + ); + + factory SimpleClassOfEnumTypeToIntNullable.fromJson( + Map json) => + _$SimpleClassOfEnumTypeToIntNullableFromJson(json); + + Map toJson() => + _$SimpleClassOfEnumTypeToIntNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfEnumTypeToIntNullable { + final Map? value; + + SimpleClassNullableOfEnumTypeToIntNullable( + this.value, + ); + + factory SimpleClassNullableOfEnumTypeToIntNullable.fromJson( + Map json) => + _$SimpleClassNullableOfEnumTypeToIntNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfEnumTypeToIntNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfIntToIntNullable { + final Map value; + + SimpleClassOfIntToIntNullable( + this.value, + ); + + factory SimpleClassOfIntToIntNullable.fromJson(Map json) => + _$SimpleClassOfIntToIntNullableFromJson(json); + + Map toJson() => _$SimpleClassOfIntToIntNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfIntToIntNullable { + final Map? value; + + SimpleClassNullableOfIntToIntNullable( + this.value, + ); + + factory SimpleClassNullableOfIntToIntNullable.fromJson( + Map json) => + _$SimpleClassNullableOfIntToIntNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfIntToIntNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfObjectToIntNullable { + final Map value; + + SimpleClassOfObjectToIntNullable( + this.value, + ); + + factory SimpleClassOfObjectToIntNullable.fromJson( + Map json) => + _$SimpleClassOfObjectToIntNullableFromJson(json); + + Map toJson() => + _$SimpleClassOfObjectToIntNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfObjectToIntNullable { + final Map? value; + + SimpleClassNullableOfObjectToIntNullable( + this.value, + ); + + factory SimpleClassNullableOfObjectToIntNullable.fromJson( + Map json) => + _$SimpleClassNullableOfObjectToIntNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfObjectToIntNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfStringToIntNullable { + final Map value; + + SimpleClassOfStringToIntNullable( + this.value, + ); + + factory SimpleClassOfStringToIntNullable.fromJson( + Map json) => + _$SimpleClassOfStringToIntNullableFromJson(json); + + Map toJson() => + _$SimpleClassOfStringToIntNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfStringToIntNullable { + final Map? value; + + SimpleClassNullableOfStringToIntNullable( + this.value, + ); + + factory SimpleClassNullableOfStringToIntNullable.fromJson( + Map json) => + _$SimpleClassNullableOfStringToIntNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfStringToIntNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfUriToIntNullable { + final Map value; + + SimpleClassOfUriToIntNullable( + this.value, + ); + + factory SimpleClassOfUriToIntNullable.fromJson(Map json) => + _$SimpleClassOfUriToIntNullableFromJson(json); + + Map toJson() => _$SimpleClassOfUriToIntNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfUriToIntNullable { + final Map? value; + + SimpleClassNullableOfUriToIntNullable( + this.value, + ); + + factory SimpleClassNullableOfUriToIntNullable.fromJson( + Map json) => + _$SimpleClassNullableOfUriToIntNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfUriToIntNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfBigIntToNum { + final Map value; + + SimpleClassOfBigIntToNum( + this.value, + ); + + factory SimpleClassOfBigIntToNum.fromJson(Map json) => + _$SimpleClassOfBigIntToNumFromJson(json); + + Map toJson() => _$SimpleClassOfBigIntToNumToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfBigIntToNum { + final Map? value; + + SimpleClassNullableOfBigIntToNum( + this.value, + ); + + factory SimpleClassNullableOfBigIntToNum.fromJson( + Map json) => + _$SimpleClassNullableOfBigIntToNumFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfBigIntToNumToJson(this); +} + +@JsonSerializable() +class SimpleClassOfDateTimeToNum { + final Map value; + + SimpleClassOfDateTimeToNum( + this.value, + ); + + factory SimpleClassOfDateTimeToNum.fromJson(Map json) => + _$SimpleClassOfDateTimeToNumFromJson(json); + + Map toJson() => _$SimpleClassOfDateTimeToNumToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfDateTimeToNum { + final Map? value; + + SimpleClassNullableOfDateTimeToNum( + this.value, + ); + + factory SimpleClassNullableOfDateTimeToNum.fromJson( + Map json) => + _$SimpleClassNullableOfDateTimeToNumFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfDateTimeToNumToJson(this); +} + +@JsonSerializable() +class SimpleClassOfDynamicToNum { + final Map value; + + SimpleClassOfDynamicToNum( + this.value, + ); + + factory SimpleClassOfDynamicToNum.fromJson(Map json) => + _$SimpleClassOfDynamicToNumFromJson(json); + + Map toJson() => _$SimpleClassOfDynamicToNumToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfDynamicToNum { + final Map? value; + + SimpleClassNullableOfDynamicToNum( + this.value, + ); + + factory SimpleClassNullableOfDynamicToNum.fromJson( + Map json) => + _$SimpleClassNullableOfDynamicToNumFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfDynamicToNumToJson(this); +} + +@JsonSerializable() +class SimpleClassOfEnumTypeToNum { + final Map value; + + SimpleClassOfEnumTypeToNum( + this.value, + ); + + factory SimpleClassOfEnumTypeToNum.fromJson(Map json) => + _$SimpleClassOfEnumTypeToNumFromJson(json); + + Map toJson() => _$SimpleClassOfEnumTypeToNumToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfEnumTypeToNum { + final Map? value; + + SimpleClassNullableOfEnumTypeToNum( + this.value, + ); + + factory SimpleClassNullableOfEnumTypeToNum.fromJson( + Map json) => + _$SimpleClassNullableOfEnumTypeToNumFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfEnumTypeToNumToJson(this); +} + +@JsonSerializable() +class SimpleClassOfIntToNum { + final Map value; + + SimpleClassOfIntToNum( + this.value, + ); + + factory SimpleClassOfIntToNum.fromJson(Map json) => + _$SimpleClassOfIntToNumFromJson(json); + + Map toJson() => _$SimpleClassOfIntToNumToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfIntToNum { + final Map? value; + + SimpleClassNullableOfIntToNum( + this.value, + ); + + factory SimpleClassNullableOfIntToNum.fromJson(Map json) => + _$SimpleClassNullableOfIntToNumFromJson(json); + + Map toJson() => _$SimpleClassNullableOfIntToNumToJson(this); +} + +@JsonSerializable() +class SimpleClassOfObjectToNum { + final Map value; + + SimpleClassOfObjectToNum( + this.value, + ); + + factory SimpleClassOfObjectToNum.fromJson(Map json) => + _$SimpleClassOfObjectToNumFromJson(json); + + Map toJson() => _$SimpleClassOfObjectToNumToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfObjectToNum { + final Map? value; + + SimpleClassNullableOfObjectToNum( + this.value, + ); + + factory SimpleClassNullableOfObjectToNum.fromJson( + Map json) => + _$SimpleClassNullableOfObjectToNumFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfObjectToNumToJson(this); +} + +@JsonSerializable() +class SimpleClassOfStringToNum { + final Map value; + + SimpleClassOfStringToNum( + this.value, + ); + + factory SimpleClassOfStringToNum.fromJson(Map json) => + _$SimpleClassOfStringToNumFromJson(json); + + Map toJson() => _$SimpleClassOfStringToNumToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfStringToNum { + final Map? value; + + SimpleClassNullableOfStringToNum( + this.value, + ); + + factory SimpleClassNullableOfStringToNum.fromJson( + Map json) => + _$SimpleClassNullableOfStringToNumFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfStringToNumToJson(this); +} + +@JsonSerializable() +class SimpleClassOfUriToNum { + final Map value; + + SimpleClassOfUriToNum( + this.value, + ); + + factory SimpleClassOfUriToNum.fromJson(Map json) => + _$SimpleClassOfUriToNumFromJson(json); + + Map toJson() => _$SimpleClassOfUriToNumToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfUriToNum { + final Map? value; + + SimpleClassNullableOfUriToNum( + this.value, + ); + + factory SimpleClassNullableOfUriToNum.fromJson(Map json) => + _$SimpleClassNullableOfUriToNumFromJson(json); + + Map toJson() => _$SimpleClassNullableOfUriToNumToJson(this); +} + +@JsonSerializable() +class SimpleClassOfBigIntToNumNullable { + final Map value; + + SimpleClassOfBigIntToNumNullable( + this.value, + ); + + factory SimpleClassOfBigIntToNumNullable.fromJson( + Map json) => + _$SimpleClassOfBigIntToNumNullableFromJson(json); + + Map toJson() => + _$SimpleClassOfBigIntToNumNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfBigIntToNumNullable { + final Map? value; + + SimpleClassNullableOfBigIntToNumNullable( + this.value, + ); + + factory SimpleClassNullableOfBigIntToNumNullable.fromJson( + Map json) => + _$SimpleClassNullableOfBigIntToNumNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfBigIntToNumNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfDateTimeToNumNullable { + final Map value; + + SimpleClassOfDateTimeToNumNullable( + this.value, + ); + + factory SimpleClassOfDateTimeToNumNullable.fromJson( + Map json) => + _$SimpleClassOfDateTimeToNumNullableFromJson(json); + + Map toJson() => + _$SimpleClassOfDateTimeToNumNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfDateTimeToNumNullable { + final Map? value; + + SimpleClassNullableOfDateTimeToNumNullable( + this.value, + ); + + factory SimpleClassNullableOfDateTimeToNumNullable.fromJson( + Map json) => + _$SimpleClassNullableOfDateTimeToNumNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfDateTimeToNumNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfDynamicToNumNullable { + final Map value; + + SimpleClassOfDynamicToNumNullable( + this.value, + ); + + factory SimpleClassOfDynamicToNumNullable.fromJson( + Map json) => + _$SimpleClassOfDynamicToNumNullableFromJson(json); + + Map toJson() => + _$SimpleClassOfDynamicToNumNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfDynamicToNumNullable { + final Map? value; + + SimpleClassNullableOfDynamicToNumNullable( + this.value, + ); + + factory SimpleClassNullableOfDynamicToNumNullable.fromJson( + Map json) => + _$SimpleClassNullableOfDynamicToNumNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfDynamicToNumNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfEnumTypeToNumNullable { + final Map value; + + SimpleClassOfEnumTypeToNumNullable( + this.value, + ); + + factory SimpleClassOfEnumTypeToNumNullable.fromJson( + Map json) => + _$SimpleClassOfEnumTypeToNumNullableFromJson(json); + + Map toJson() => + _$SimpleClassOfEnumTypeToNumNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfEnumTypeToNumNullable { + final Map? value; + + SimpleClassNullableOfEnumTypeToNumNullable( + this.value, + ); + + factory SimpleClassNullableOfEnumTypeToNumNullable.fromJson( + Map json) => + _$SimpleClassNullableOfEnumTypeToNumNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfEnumTypeToNumNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfIntToNumNullable { + final Map value; + + SimpleClassOfIntToNumNullable( + this.value, + ); + + factory SimpleClassOfIntToNumNullable.fromJson(Map json) => + _$SimpleClassOfIntToNumNullableFromJson(json); + + Map toJson() => _$SimpleClassOfIntToNumNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfIntToNumNullable { + final Map? value; + + SimpleClassNullableOfIntToNumNullable( + this.value, + ); + + factory SimpleClassNullableOfIntToNumNullable.fromJson( + Map json) => + _$SimpleClassNullableOfIntToNumNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfIntToNumNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfObjectToNumNullable { + final Map value; + + SimpleClassOfObjectToNumNullable( + this.value, + ); + + factory SimpleClassOfObjectToNumNullable.fromJson( + Map json) => + _$SimpleClassOfObjectToNumNullableFromJson(json); + + Map toJson() => + _$SimpleClassOfObjectToNumNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfObjectToNumNullable { + final Map? value; + + SimpleClassNullableOfObjectToNumNullable( + this.value, + ); + + factory SimpleClassNullableOfObjectToNumNullable.fromJson( + Map json) => + _$SimpleClassNullableOfObjectToNumNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfObjectToNumNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfStringToNumNullable { + final Map value; + + SimpleClassOfStringToNumNullable( + this.value, + ); + + factory SimpleClassOfStringToNumNullable.fromJson( + Map json) => + _$SimpleClassOfStringToNumNullableFromJson(json); + + Map toJson() => + _$SimpleClassOfStringToNumNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfStringToNumNullable { + final Map? value; + + SimpleClassNullableOfStringToNumNullable( + this.value, + ); + + factory SimpleClassNullableOfStringToNumNullable.fromJson( + Map json) => + _$SimpleClassNullableOfStringToNumNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfStringToNumNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfUriToNumNullable { + final Map value; + + SimpleClassOfUriToNumNullable( + this.value, + ); + + factory SimpleClassOfUriToNumNullable.fromJson(Map json) => + _$SimpleClassOfUriToNumNullableFromJson(json); + + Map toJson() => _$SimpleClassOfUriToNumNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfUriToNumNullable { + final Map? value; + + SimpleClassNullableOfUriToNumNullable( + this.value, + ); + + factory SimpleClassNullableOfUriToNumNullable.fromJson( + Map json) => + _$SimpleClassNullableOfUriToNumNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfUriToNumNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfBigIntToObject { + final Map value; + + SimpleClassOfBigIntToObject( + this.value, + ); + + factory SimpleClassOfBigIntToObject.fromJson(Map json) => + _$SimpleClassOfBigIntToObjectFromJson(json); + + Map toJson() => _$SimpleClassOfBigIntToObjectToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfBigIntToObject { + final Map? value; + + SimpleClassNullableOfBigIntToObject( + this.value, + ); + + factory SimpleClassNullableOfBigIntToObject.fromJson( + Map json) => + _$SimpleClassNullableOfBigIntToObjectFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfBigIntToObjectToJson(this); +} + +@JsonSerializable() +class SimpleClassOfDateTimeToObject { + final Map value; + + SimpleClassOfDateTimeToObject( + this.value, + ); + + factory SimpleClassOfDateTimeToObject.fromJson(Map json) => + _$SimpleClassOfDateTimeToObjectFromJson(json); + + Map toJson() => _$SimpleClassOfDateTimeToObjectToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfDateTimeToObject { + final Map? value; + + SimpleClassNullableOfDateTimeToObject( + this.value, + ); + + factory SimpleClassNullableOfDateTimeToObject.fromJson( + Map json) => + _$SimpleClassNullableOfDateTimeToObjectFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfDateTimeToObjectToJson(this); +} + +@JsonSerializable() +class SimpleClassOfDynamicToObject { + final Map value; + + SimpleClassOfDynamicToObject( + this.value, + ); + + factory SimpleClassOfDynamicToObject.fromJson(Map json) => + _$SimpleClassOfDynamicToObjectFromJson(json); + + Map toJson() => _$SimpleClassOfDynamicToObjectToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfDynamicToObject { + final Map? value; + + SimpleClassNullableOfDynamicToObject( + this.value, + ); + + factory SimpleClassNullableOfDynamicToObject.fromJson( + Map json) => + _$SimpleClassNullableOfDynamicToObjectFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfDynamicToObjectToJson(this); +} + +@JsonSerializable() +class SimpleClassOfEnumTypeToObject { + final Map value; + + SimpleClassOfEnumTypeToObject( + this.value, + ); + + factory SimpleClassOfEnumTypeToObject.fromJson(Map json) => + _$SimpleClassOfEnumTypeToObjectFromJson(json); + + Map toJson() => _$SimpleClassOfEnumTypeToObjectToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfEnumTypeToObject { + final Map? value; + + SimpleClassNullableOfEnumTypeToObject( + this.value, + ); + + factory SimpleClassNullableOfEnumTypeToObject.fromJson( + Map json) => + _$SimpleClassNullableOfEnumTypeToObjectFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfEnumTypeToObjectToJson(this); +} + +@JsonSerializable() +class SimpleClassOfIntToObject { + final Map value; + + SimpleClassOfIntToObject( + this.value, + ); + + factory SimpleClassOfIntToObject.fromJson(Map json) => + _$SimpleClassOfIntToObjectFromJson(json); + + Map toJson() => _$SimpleClassOfIntToObjectToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfIntToObject { + final Map? value; + + SimpleClassNullableOfIntToObject( + this.value, + ); + + factory SimpleClassNullableOfIntToObject.fromJson( + Map json) => + _$SimpleClassNullableOfIntToObjectFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfIntToObjectToJson(this); +} + +@JsonSerializable() +class SimpleClassOfObjectToObject { + final Map value; + + SimpleClassOfObjectToObject( + this.value, + ); + + factory SimpleClassOfObjectToObject.fromJson(Map json) => + _$SimpleClassOfObjectToObjectFromJson(json); + + Map toJson() => _$SimpleClassOfObjectToObjectToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfObjectToObject { + final Map? value; + + SimpleClassNullableOfObjectToObject( + this.value, + ); + + factory SimpleClassNullableOfObjectToObject.fromJson( + Map json) => + _$SimpleClassNullableOfObjectToObjectFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfObjectToObjectToJson(this); +} + +@JsonSerializable() +class SimpleClassOfStringToObject { + final Map value; + + SimpleClassOfStringToObject( + this.value, + ); + + factory SimpleClassOfStringToObject.fromJson(Map json) => + _$SimpleClassOfStringToObjectFromJson(json); + + Map toJson() => _$SimpleClassOfStringToObjectToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfStringToObject { + final Map? value; + + SimpleClassNullableOfStringToObject( + this.value, + ); + + factory SimpleClassNullableOfStringToObject.fromJson( + Map json) => + _$SimpleClassNullableOfStringToObjectFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfStringToObjectToJson(this); +} + +@JsonSerializable() +class SimpleClassOfUriToObject { + final Map value; + + SimpleClassOfUriToObject( + this.value, + ); + + factory SimpleClassOfUriToObject.fromJson(Map json) => + _$SimpleClassOfUriToObjectFromJson(json); + + Map toJson() => _$SimpleClassOfUriToObjectToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfUriToObject { + final Map? value; + + SimpleClassNullableOfUriToObject( + this.value, + ); + + factory SimpleClassNullableOfUriToObject.fromJson( + Map json) => + _$SimpleClassNullableOfUriToObjectFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfUriToObjectToJson(this); +} + +@JsonSerializable() +class SimpleClassOfBigIntToObjectNullable { + final Map value; + + SimpleClassOfBigIntToObjectNullable( + this.value, + ); + + factory SimpleClassOfBigIntToObjectNullable.fromJson( + Map json) => + _$SimpleClassOfBigIntToObjectNullableFromJson(json); + + Map toJson() => + _$SimpleClassOfBigIntToObjectNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfBigIntToObjectNullable { + final Map? value; + + SimpleClassNullableOfBigIntToObjectNullable( + this.value, + ); + + factory SimpleClassNullableOfBigIntToObjectNullable.fromJson( + Map json) => + _$SimpleClassNullableOfBigIntToObjectNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfBigIntToObjectNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfDateTimeToObjectNullable { + final Map value; + + SimpleClassOfDateTimeToObjectNullable( + this.value, + ); + + factory SimpleClassOfDateTimeToObjectNullable.fromJson( + Map json) => + _$SimpleClassOfDateTimeToObjectNullableFromJson(json); + + Map toJson() => + _$SimpleClassOfDateTimeToObjectNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfDateTimeToObjectNullable { + final Map? value; + + SimpleClassNullableOfDateTimeToObjectNullable( + this.value, + ); + + factory SimpleClassNullableOfDateTimeToObjectNullable.fromJson( + Map json) => + _$SimpleClassNullableOfDateTimeToObjectNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfDateTimeToObjectNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfDynamicToObjectNullable { + final Map value; + + SimpleClassOfDynamicToObjectNullable( + this.value, + ); + + factory SimpleClassOfDynamicToObjectNullable.fromJson( + Map json) => + _$SimpleClassOfDynamicToObjectNullableFromJson(json); + + Map toJson() => + _$SimpleClassOfDynamicToObjectNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfDynamicToObjectNullable { + final Map? value; + + SimpleClassNullableOfDynamicToObjectNullable( + this.value, + ); + + factory SimpleClassNullableOfDynamicToObjectNullable.fromJson( + Map json) => + _$SimpleClassNullableOfDynamicToObjectNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfDynamicToObjectNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfEnumTypeToObjectNullable { + final Map value; + + SimpleClassOfEnumTypeToObjectNullable( + this.value, + ); + + factory SimpleClassOfEnumTypeToObjectNullable.fromJson( + Map json) => + _$SimpleClassOfEnumTypeToObjectNullableFromJson(json); + + Map toJson() => + _$SimpleClassOfEnumTypeToObjectNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfEnumTypeToObjectNullable { + final Map? value; + + SimpleClassNullableOfEnumTypeToObjectNullable( + this.value, + ); + + factory SimpleClassNullableOfEnumTypeToObjectNullable.fromJson( + Map json) => + _$SimpleClassNullableOfEnumTypeToObjectNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfEnumTypeToObjectNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfIntToObjectNullable { + final Map value; + + SimpleClassOfIntToObjectNullable( + this.value, + ); + + factory SimpleClassOfIntToObjectNullable.fromJson( + Map json) => + _$SimpleClassOfIntToObjectNullableFromJson(json); + + Map toJson() => + _$SimpleClassOfIntToObjectNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfIntToObjectNullable { + final Map? value; + + SimpleClassNullableOfIntToObjectNullable( + this.value, + ); + + factory SimpleClassNullableOfIntToObjectNullable.fromJson( + Map json) => + _$SimpleClassNullableOfIntToObjectNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfIntToObjectNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfObjectToObjectNullable { + final Map value; + + SimpleClassOfObjectToObjectNullable( + this.value, + ); + + factory SimpleClassOfObjectToObjectNullable.fromJson( + Map json) => + _$SimpleClassOfObjectToObjectNullableFromJson(json); + + Map toJson() => + _$SimpleClassOfObjectToObjectNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfObjectToObjectNullable { + final Map? value; + + SimpleClassNullableOfObjectToObjectNullable( + this.value, + ); + + factory SimpleClassNullableOfObjectToObjectNullable.fromJson( + Map json) => + _$SimpleClassNullableOfObjectToObjectNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfObjectToObjectNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfStringToObjectNullable { + final Map value; + + SimpleClassOfStringToObjectNullable( + this.value, + ); + + factory SimpleClassOfStringToObjectNullable.fromJson( + Map json) => + _$SimpleClassOfStringToObjectNullableFromJson(json); + + Map toJson() => + _$SimpleClassOfStringToObjectNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfStringToObjectNullable { + final Map? value; + + SimpleClassNullableOfStringToObjectNullable( + this.value, + ); + + factory SimpleClassNullableOfStringToObjectNullable.fromJson( + Map json) => + _$SimpleClassNullableOfStringToObjectNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfStringToObjectNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfUriToObjectNullable { + final Map value; + + SimpleClassOfUriToObjectNullable( + this.value, + ); + + factory SimpleClassOfUriToObjectNullable.fromJson( + Map json) => + _$SimpleClassOfUriToObjectNullableFromJson(json); + + Map toJson() => + _$SimpleClassOfUriToObjectNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfUriToObjectNullable { + final Map? value; + + SimpleClassNullableOfUriToObjectNullable( + this.value, + ); + + factory SimpleClassNullableOfUriToObjectNullable.fromJson( + Map json) => + _$SimpleClassNullableOfUriToObjectNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfUriToObjectNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfBigIntToString { + final Map value; + + SimpleClassOfBigIntToString( + this.value, + ); + + factory SimpleClassOfBigIntToString.fromJson(Map json) => + _$SimpleClassOfBigIntToStringFromJson(json); + + Map toJson() => _$SimpleClassOfBigIntToStringToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfBigIntToString { + final Map? value; + + SimpleClassNullableOfBigIntToString( + this.value, + ); + + factory SimpleClassNullableOfBigIntToString.fromJson( + Map json) => + _$SimpleClassNullableOfBigIntToStringFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfBigIntToStringToJson(this); +} + +@JsonSerializable() +class SimpleClassOfDateTimeToString { + final Map value; + + SimpleClassOfDateTimeToString( + this.value, + ); + + factory SimpleClassOfDateTimeToString.fromJson(Map json) => + _$SimpleClassOfDateTimeToStringFromJson(json); + + Map toJson() => _$SimpleClassOfDateTimeToStringToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfDateTimeToString { + final Map? value; + + SimpleClassNullableOfDateTimeToString( + this.value, + ); + + factory SimpleClassNullableOfDateTimeToString.fromJson( + Map json) => + _$SimpleClassNullableOfDateTimeToStringFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfDateTimeToStringToJson(this); +} + +@JsonSerializable() +class SimpleClassOfDynamicToString { + final Map value; + + SimpleClassOfDynamicToString( + this.value, + ); + + factory SimpleClassOfDynamicToString.fromJson(Map json) => + _$SimpleClassOfDynamicToStringFromJson(json); + + Map toJson() => _$SimpleClassOfDynamicToStringToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfDynamicToString { + final Map? value; + + SimpleClassNullableOfDynamicToString( + this.value, + ); + + factory SimpleClassNullableOfDynamicToString.fromJson( + Map json) => + _$SimpleClassNullableOfDynamicToStringFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfDynamicToStringToJson(this); +} + +@JsonSerializable() +class SimpleClassOfEnumTypeToString { + final Map value; + + SimpleClassOfEnumTypeToString( + this.value, + ); + + factory SimpleClassOfEnumTypeToString.fromJson(Map json) => + _$SimpleClassOfEnumTypeToStringFromJson(json); + + Map toJson() => _$SimpleClassOfEnumTypeToStringToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfEnumTypeToString { + final Map? value; + + SimpleClassNullableOfEnumTypeToString( + this.value, + ); + + factory SimpleClassNullableOfEnumTypeToString.fromJson( + Map json) => + _$SimpleClassNullableOfEnumTypeToStringFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfEnumTypeToStringToJson(this); +} + +@JsonSerializable() +class SimpleClassOfIntToString { + final Map value; + + SimpleClassOfIntToString( + this.value, + ); + + factory SimpleClassOfIntToString.fromJson(Map json) => + _$SimpleClassOfIntToStringFromJson(json); + + Map toJson() => _$SimpleClassOfIntToStringToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfIntToString { + final Map? value; + + SimpleClassNullableOfIntToString( + this.value, + ); + + factory SimpleClassNullableOfIntToString.fromJson( + Map json) => + _$SimpleClassNullableOfIntToStringFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfIntToStringToJson(this); +} + +@JsonSerializable() +class SimpleClassOfObjectToString { + final Map value; + + SimpleClassOfObjectToString( + this.value, + ); + + factory SimpleClassOfObjectToString.fromJson(Map json) => + _$SimpleClassOfObjectToStringFromJson(json); + + Map toJson() => _$SimpleClassOfObjectToStringToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfObjectToString { + final Map? value; + + SimpleClassNullableOfObjectToString( + this.value, + ); + + factory SimpleClassNullableOfObjectToString.fromJson( + Map json) => + _$SimpleClassNullableOfObjectToStringFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfObjectToStringToJson(this); +} + +@JsonSerializable() +class SimpleClassOfStringToString { + final Map value; + + SimpleClassOfStringToString( + this.value, + ); + + factory SimpleClassOfStringToString.fromJson(Map json) => + _$SimpleClassOfStringToStringFromJson(json); + + Map toJson() => _$SimpleClassOfStringToStringToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfStringToString { + final Map? value; + + SimpleClassNullableOfStringToString( + this.value, + ); + + factory SimpleClassNullableOfStringToString.fromJson( + Map json) => + _$SimpleClassNullableOfStringToStringFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfStringToStringToJson(this); +} + +@JsonSerializable() +class SimpleClassOfUriToString { + final Map value; + + SimpleClassOfUriToString( + this.value, + ); + + factory SimpleClassOfUriToString.fromJson(Map json) => + _$SimpleClassOfUriToStringFromJson(json); + + Map toJson() => _$SimpleClassOfUriToStringToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfUriToString { + final Map? value; + + SimpleClassNullableOfUriToString( + this.value, + ); + + factory SimpleClassNullableOfUriToString.fromJson( + Map json) => + _$SimpleClassNullableOfUriToStringFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfUriToStringToJson(this); +} + +@JsonSerializable() +class SimpleClassOfBigIntToStringNullable { + final Map value; + + SimpleClassOfBigIntToStringNullable( + this.value, + ); + + factory SimpleClassOfBigIntToStringNullable.fromJson( + Map json) => + _$SimpleClassOfBigIntToStringNullableFromJson(json); + + Map toJson() => + _$SimpleClassOfBigIntToStringNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfBigIntToStringNullable { + final Map? value; + + SimpleClassNullableOfBigIntToStringNullable( + this.value, + ); + + factory SimpleClassNullableOfBigIntToStringNullable.fromJson( + Map json) => + _$SimpleClassNullableOfBigIntToStringNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfBigIntToStringNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfDateTimeToStringNullable { + final Map value; + + SimpleClassOfDateTimeToStringNullable( + this.value, + ); + + factory SimpleClassOfDateTimeToStringNullable.fromJson( + Map json) => + _$SimpleClassOfDateTimeToStringNullableFromJson(json); + + Map toJson() => + _$SimpleClassOfDateTimeToStringNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfDateTimeToStringNullable { + final Map? value; + + SimpleClassNullableOfDateTimeToStringNullable( + this.value, + ); + + factory SimpleClassNullableOfDateTimeToStringNullable.fromJson( + Map json) => + _$SimpleClassNullableOfDateTimeToStringNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfDateTimeToStringNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfDynamicToStringNullable { + final Map value; + + SimpleClassOfDynamicToStringNullable( + this.value, + ); + + factory SimpleClassOfDynamicToStringNullable.fromJson( + Map json) => + _$SimpleClassOfDynamicToStringNullableFromJson(json); + + Map toJson() => + _$SimpleClassOfDynamicToStringNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfDynamicToStringNullable { + final Map? value; + + SimpleClassNullableOfDynamicToStringNullable( + this.value, + ); + + factory SimpleClassNullableOfDynamicToStringNullable.fromJson( + Map json) => + _$SimpleClassNullableOfDynamicToStringNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfDynamicToStringNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfEnumTypeToStringNullable { + final Map value; + + SimpleClassOfEnumTypeToStringNullable( + this.value, + ); + + factory SimpleClassOfEnumTypeToStringNullable.fromJson( + Map json) => + _$SimpleClassOfEnumTypeToStringNullableFromJson(json); + + Map toJson() => + _$SimpleClassOfEnumTypeToStringNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfEnumTypeToStringNullable { + final Map? value; + + SimpleClassNullableOfEnumTypeToStringNullable( + this.value, + ); + + factory SimpleClassNullableOfEnumTypeToStringNullable.fromJson( + Map json) => + _$SimpleClassNullableOfEnumTypeToStringNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfEnumTypeToStringNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfIntToStringNullable { + final Map value; + + SimpleClassOfIntToStringNullable( + this.value, + ); + + factory SimpleClassOfIntToStringNullable.fromJson( + Map json) => + _$SimpleClassOfIntToStringNullableFromJson(json); + + Map toJson() => + _$SimpleClassOfIntToStringNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfIntToStringNullable { + final Map? value; + + SimpleClassNullableOfIntToStringNullable( + this.value, + ); + + factory SimpleClassNullableOfIntToStringNullable.fromJson( + Map json) => + _$SimpleClassNullableOfIntToStringNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfIntToStringNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfObjectToStringNullable { + final Map value; + + SimpleClassOfObjectToStringNullable( + this.value, + ); + + factory SimpleClassOfObjectToStringNullable.fromJson( + Map json) => + _$SimpleClassOfObjectToStringNullableFromJson(json); + + Map toJson() => + _$SimpleClassOfObjectToStringNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfObjectToStringNullable { + final Map? value; + + SimpleClassNullableOfObjectToStringNullable( + this.value, + ); + + factory SimpleClassNullableOfObjectToStringNullable.fromJson( + Map json) => + _$SimpleClassNullableOfObjectToStringNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfObjectToStringNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfStringToStringNullable { + final Map value; + + SimpleClassOfStringToStringNullable( + this.value, + ); + + factory SimpleClassOfStringToStringNullable.fromJson( + Map json) => + _$SimpleClassOfStringToStringNullableFromJson(json); + + Map toJson() => + _$SimpleClassOfStringToStringNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfStringToStringNullable { + final Map? value; + + SimpleClassNullableOfStringToStringNullable( + this.value, + ); + + factory SimpleClassNullableOfStringToStringNullable.fromJson( + Map json) => + _$SimpleClassNullableOfStringToStringNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfStringToStringNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfUriToStringNullable { + final Map value; + + SimpleClassOfUriToStringNullable( + this.value, + ); + + factory SimpleClassOfUriToStringNullable.fromJson( + Map json) => + _$SimpleClassOfUriToStringNullableFromJson(json); + + Map toJson() => + _$SimpleClassOfUriToStringNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfUriToStringNullable { + final Map? value; + + SimpleClassNullableOfUriToStringNullable( + this.value, + ); + + factory SimpleClassNullableOfUriToStringNullable.fromJson( + Map json) => + _$SimpleClassNullableOfUriToStringNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfUriToStringNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfBigIntToUri { + final Map value; + + SimpleClassOfBigIntToUri( + this.value, + ); + + factory SimpleClassOfBigIntToUri.fromJson(Map json) => + _$SimpleClassOfBigIntToUriFromJson(json); + + Map toJson() => _$SimpleClassOfBigIntToUriToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfBigIntToUri { + final Map? value; + + SimpleClassNullableOfBigIntToUri( + this.value, + ); + + factory SimpleClassNullableOfBigIntToUri.fromJson( + Map json) => + _$SimpleClassNullableOfBigIntToUriFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfBigIntToUriToJson(this); +} + +@JsonSerializable() +class SimpleClassOfDateTimeToUri { + final Map value; + + SimpleClassOfDateTimeToUri( + this.value, + ); + + factory SimpleClassOfDateTimeToUri.fromJson(Map json) => + _$SimpleClassOfDateTimeToUriFromJson(json); + + Map toJson() => _$SimpleClassOfDateTimeToUriToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfDateTimeToUri { + final Map? value; + + SimpleClassNullableOfDateTimeToUri( + this.value, + ); + + factory SimpleClassNullableOfDateTimeToUri.fromJson( + Map json) => + _$SimpleClassNullableOfDateTimeToUriFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfDateTimeToUriToJson(this); +} + +@JsonSerializable() +class SimpleClassOfDynamicToUri { + final Map value; + + SimpleClassOfDynamicToUri( + this.value, + ); + + factory SimpleClassOfDynamicToUri.fromJson(Map json) => + _$SimpleClassOfDynamicToUriFromJson(json); + + Map toJson() => _$SimpleClassOfDynamicToUriToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfDynamicToUri { + final Map? value; + + SimpleClassNullableOfDynamicToUri( + this.value, + ); + + factory SimpleClassNullableOfDynamicToUri.fromJson( + Map json) => + _$SimpleClassNullableOfDynamicToUriFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfDynamicToUriToJson(this); +} + +@JsonSerializable() +class SimpleClassOfEnumTypeToUri { + final Map value; + + SimpleClassOfEnumTypeToUri( + this.value, + ); + + factory SimpleClassOfEnumTypeToUri.fromJson(Map json) => + _$SimpleClassOfEnumTypeToUriFromJson(json); + + Map toJson() => _$SimpleClassOfEnumTypeToUriToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfEnumTypeToUri { + final Map? value; + + SimpleClassNullableOfEnumTypeToUri( + this.value, + ); + + factory SimpleClassNullableOfEnumTypeToUri.fromJson( + Map json) => + _$SimpleClassNullableOfEnumTypeToUriFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfEnumTypeToUriToJson(this); +} + +@JsonSerializable() +class SimpleClassOfIntToUri { + final Map value; + + SimpleClassOfIntToUri( + this.value, + ); + + factory SimpleClassOfIntToUri.fromJson(Map json) => + _$SimpleClassOfIntToUriFromJson(json); + + Map toJson() => _$SimpleClassOfIntToUriToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfIntToUri { + final Map? value; + + SimpleClassNullableOfIntToUri( + this.value, + ); + + factory SimpleClassNullableOfIntToUri.fromJson(Map json) => + _$SimpleClassNullableOfIntToUriFromJson(json); + + Map toJson() => _$SimpleClassNullableOfIntToUriToJson(this); +} + +@JsonSerializable() +class SimpleClassOfObjectToUri { + final Map value; + + SimpleClassOfObjectToUri( + this.value, + ); + + factory SimpleClassOfObjectToUri.fromJson(Map json) => + _$SimpleClassOfObjectToUriFromJson(json); + + Map toJson() => _$SimpleClassOfObjectToUriToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfObjectToUri { + final Map? value; + + SimpleClassNullableOfObjectToUri( + this.value, + ); + + factory SimpleClassNullableOfObjectToUri.fromJson( + Map json) => + _$SimpleClassNullableOfObjectToUriFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfObjectToUriToJson(this); +} + +@JsonSerializable() +class SimpleClassOfStringToUri { + final Map value; + + SimpleClassOfStringToUri( + this.value, + ); + + factory SimpleClassOfStringToUri.fromJson(Map json) => + _$SimpleClassOfStringToUriFromJson(json); + + Map toJson() => _$SimpleClassOfStringToUriToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfStringToUri { + final Map? value; + + SimpleClassNullableOfStringToUri( + this.value, + ); + + factory SimpleClassNullableOfStringToUri.fromJson( + Map json) => + _$SimpleClassNullableOfStringToUriFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfStringToUriToJson(this); +} + +@JsonSerializable() +class SimpleClassOfUriToUri { + final Map value; + + SimpleClassOfUriToUri( + this.value, + ); + + factory SimpleClassOfUriToUri.fromJson(Map json) => + _$SimpleClassOfUriToUriFromJson(json); + + Map toJson() => _$SimpleClassOfUriToUriToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfUriToUri { + final Map? value; + + SimpleClassNullableOfUriToUri( + this.value, + ); + + factory SimpleClassNullableOfUriToUri.fromJson(Map json) => + _$SimpleClassNullableOfUriToUriFromJson(json); + + Map toJson() => _$SimpleClassNullableOfUriToUriToJson(this); +} + +@JsonSerializable() +class SimpleClassOfBigIntToUriNullable { + final Map value; + + SimpleClassOfBigIntToUriNullable( + this.value, + ); + + factory SimpleClassOfBigIntToUriNullable.fromJson( + Map json) => + _$SimpleClassOfBigIntToUriNullableFromJson(json); + + Map toJson() => + _$SimpleClassOfBigIntToUriNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfBigIntToUriNullable { + final Map? value; + + SimpleClassNullableOfBigIntToUriNullable( + this.value, + ); + + factory SimpleClassNullableOfBigIntToUriNullable.fromJson( + Map json) => + _$SimpleClassNullableOfBigIntToUriNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfBigIntToUriNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfDateTimeToUriNullable { + final Map value; + + SimpleClassOfDateTimeToUriNullable( + this.value, + ); + + factory SimpleClassOfDateTimeToUriNullable.fromJson( + Map json) => + _$SimpleClassOfDateTimeToUriNullableFromJson(json); + + Map toJson() => + _$SimpleClassOfDateTimeToUriNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfDateTimeToUriNullable { + final Map? value; + + SimpleClassNullableOfDateTimeToUriNullable( + this.value, + ); + + factory SimpleClassNullableOfDateTimeToUriNullable.fromJson( + Map json) => + _$SimpleClassNullableOfDateTimeToUriNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfDateTimeToUriNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfDynamicToUriNullable { + final Map value; + + SimpleClassOfDynamicToUriNullable( + this.value, + ); + + factory SimpleClassOfDynamicToUriNullable.fromJson( + Map json) => + _$SimpleClassOfDynamicToUriNullableFromJson(json); + + Map toJson() => + _$SimpleClassOfDynamicToUriNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfDynamicToUriNullable { + final Map? value; + + SimpleClassNullableOfDynamicToUriNullable( + this.value, + ); + + factory SimpleClassNullableOfDynamicToUriNullable.fromJson( + Map json) => + _$SimpleClassNullableOfDynamicToUriNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfDynamicToUriNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfEnumTypeToUriNullable { + final Map value; + + SimpleClassOfEnumTypeToUriNullable( + this.value, + ); + + factory SimpleClassOfEnumTypeToUriNullable.fromJson( + Map json) => + _$SimpleClassOfEnumTypeToUriNullableFromJson(json); + + Map toJson() => + _$SimpleClassOfEnumTypeToUriNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfEnumTypeToUriNullable { + final Map? value; + + SimpleClassNullableOfEnumTypeToUriNullable( + this.value, + ); + + factory SimpleClassNullableOfEnumTypeToUriNullable.fromJson( + Map json) => + _$SimpleClassNullableOfEnumTypeToUriNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfEnumTypeToUriNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfIntToUriNullable { + final Map value; + + SimpleClassOfIntToUriNullable( + this.value, + ); + + factory SimpleClassOfIntToUriNullable.fromJson(Map json) => + _$SimpleClassOfIntToUriNullableFromJson(json); + + Map toJson() => _$SimpleClassOfIntToUriNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfIntToUriNullable { + final Map? value; + + SimpleClassNullableOfIntToUriNullable( + this.value, + ); + + factory SimpleClassNullableOfIntToUriNullable.fromJson( + Map json) => + _$SimpleClassNullableOfIntToUriNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfIntToUriNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfObjectToUriNullable { + final Map value; + + SimpleClassOfObjectToUriNullable( + this.value, + ); + + factory SimpleClassOfObjectToUriNullable.fromJson( + Map json) => + _$SimpleClassOfObjectToUriNullableFromJson(json); + + Map toJson() => + _$SimpleClassOfObjectToUriNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfObjectToUriNullable { + final Map? value; + + SimpleClassNullableOfObjectToUriNullable( + this.value, + ); + + factory SimpleClassNullableOfObjectToUriNullable.fromJson( + Map json) => + _$SimpleClassNullableOfObjectToUriNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfObjectToUriNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfStringToUriNullable { + final Map value; + + SimpleClassOfStringToUriNullable( + this.value, + ); + + factory SimpleClassOfStringToUriNullable.fromJson( + Map json) => + _$SimpleClassOfStringToUriNullableFromJson(json); + + Map toJson() => + _$SimpleClassOfStringToUriNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfStringToUriNullable { + final Map? value; + + SimpleClassNullableOfStringToUriNullable( + this.value, + ); + + factory SimpleClassNullableOfStringToUriNullable.fromJson( + Map json) => + _$SimpleClassNullableOfStringToUriNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfStringToUriNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfUriToUriNullable { + final Map value; + + SimpleClassOfUriToUriNullable( + this.value, + ); - @JsonKey(nullable: false) - final Map nullable; + factory SimpleClassOfUriToUriNullable.fromJson(Map json) => + _$SimpleClassOfUriToUriNullableFromJson(json); + + Map toJson() => _$SimpleClassOfUriToUriNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfUriToUriNullable { + final Map? value; - SimpleClassUriToUri( + SimpleClassNullableOfUriToUriNullable( this.value, - this.nullable, ); - factory SimpleClassUriToUri.fromJson(Map json) => - _$SimpleClassUriToUriFromJson(json); + factory SimpleClassNullableOfUriToUriNullable.fromJson( + Map json) => + _$SimpleClassNullableOfUriToUriNullableFromJson(json); - Map toJson() => _$SimpleClassUriToUriToJson(this); + Map toJson() => + _$SimpleClassNullableOfUriToUriNullableToJson(this); } diff --git a/json_serializable/test/supported_types/input.type_map.g.dart b/json_serializable/test/supported_types/input.type_map.g.dart index d1817bc25..dfa1c2f7b 100644 --- a/json_serializable/test/supported_types/input.type_map.g.dart +++ b/json_serializable/test/supported_types/input.type_map.g.dart @@ -1,4 +1,5 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// @dart=2.12 part of 'input.type_map.dart'; @@ -9,133 +10,165 @@ part of 'input.type_map.dart'; SimpleClass _$SimpleClassFromJson(Map json) { return SimpleClass( json['value'] as Map, - json['nullable'] as Map, - )..withDefault = json['withDefault'] as Map ?? {'a': 1}; + json['withDefault'] as Map? ?? {'a': 1}, + ); } Map _$SimpleClassToJson(SimpleClass instance) => { 'value': instance.value, - 'nullable': instance.nullable, 'withDefault': instance.withDefault, }; -SimpleClassBigIntToBigInt _$SimpleClassBigIntToBigIntFromJson( +SimpleClassNullable _$SimpleClassNullableFromJson(Map json) { + return SimpleClassNullable( + json['value'] as Map?, + json['withDefault'] as Map? ?? {'a': 1}, + ); +} + +Map _$SimpleClassNullableToJson( + SimpleClassNullable instance) => + { + 'value': instance.value, + 'withDefault': instance.withDefault, + }; + +SimpleClassOfBigIntToBigInt _$SimpleClassOfBigIntToBigIntFromJson( Map json) { - return SimpleClassBigIntToBigInt( - (json['value'] as Map)?.map( - (k, e) => MapEntry( - BigInt.parse(k), e == null ? null : BigInt.parse(e as String)), + return SimpleClassOfBigIntToBigInt( + (json['value'] as Map).map( + (k, e) => MapEntry(BigInt.parse(k), BigInt.parse(e as String)), ), - (json['nullable'] as Map).map( + ); +} + +Map _$SimpleClassOfBigIntToBigIntToJson( + SimpleClassOfBigIntToBigInt instance) => + { + 'value': + instance.value.map((k, e) => MapEntry(k.toString(), e.toString())), + }; + +SimpleClassNullableOfBigIntToBigInt + _$SimpleClassNullableOfBigIntToBigIntFromJson(Map json) { + return SimpleClassNullableOfBigIntToBigInt( + (json['value'] as Map?)?.map( (k, e) => MapEntry(BigInt.parse(k), BigInt.parse(e as String)), ), ); } -Map _$SimpleClassBigIntToBigIntToJson( - SimpleClassBigIntToBigInt instance) => +Map _$SimpleClassNullableOfBigIntToBigIntToJson( + SimpleClassNullableOfBigIntToBigInt instance) => { 'value': - instance.value?.map((k, e) => MapEntry(k.toString(), e?.toString())), - 'nullable': - instance.nullable.map((k, e) => MapEntry(k.toString(), e.toString())), + instance.value?.map((k, e) => MapEntry(k.toString(), e.toString())), }; -SimpleClassDateTimeToBigInt _$SimpleClassDateTimeToBigIntFromJson( +SimpleClassOfDateTimeToBigInt _$SimpleClassOfDateTimeToBigIntFromJson( Map json) { - return SimpleClassDateTimeToBigInt( - (json['value'] as Map)?.map( - (k, e) => MapEntry( - DateTime.parse(k), e == null ? null : BigInt.parse(e as String)), - ), - (json['nullable'] as Map).map( + return SimpleClassOfDateTimeToBigInt( + (json['value'] as Map).map( (k, e) => MapEntry(DateTime.parse(k), BigInt.parse(e as String)), ), ); } -Map _$SimpleClassDateTimeToBigIntToJson( - SimpleClassDateTimeToBigInt instance) => +Map _$SimpleClassOfDateTimeToBigIntToJson( + SimpleClassOfDateTimeToBigInt instance) => { 'value': instance.value - ?.map((k, e) => MapEntry(k.toIso8601String(), e?.toString())), - 'nullable': instance.nullable .map((k, e) => MapEntry(k.toIso8601String(), e.toString())), }; -SimpleClassDynamicToBigInt _$SimpleClassDynamicToBigIntFromJson( +SimpleClassNullableOfDateTimeToBigInt + _$SimpleClassNullableOfDateTimeToBigIntFromJson(Map json) { + return SimpleClassNullableOfDateTimeToBigInt( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(DateTime.parse(k), BigInt.parse(e as String)), + ), + ); +} + +Map _$SimpleClassNullableOfDateTimeToBigIntToJson( + SimpleClassNullableOfDateTimeToBigInt instance) => + { + 'value': instance.value + ?.map((k, e) => MapEntry(k.toIso8601String(), e.toString())), + }; + +SimpleClassOfDynamicToBigInt _$SimpleClassOfDynamicToBigIntFromJson( Map json) { - return SimpleClassDynamicToBigInt( - (json['value'] as Map)?.map( - (k, e) => MapEntry(k, e == null ? null : BigInt.parse(e as String)), + return SimpleClassOfDynamicToBigInt( + (json['value'] as Map).map( + (k, e) => MapEntry(k, BigInt.parse(e as String)), ), - (json['nullable'] as Map).map( + ); +} + +Map _$SimpleClassOfDynamicToBigIntToJson( + SimpleClassOfDynamicToBigInt instance) => + { + 'value': instance.value.map((k, e) => MapEntry(k, e.toString())), + }; + +SimpleClassNullableOfDynamicToBigInt + _$SimpleClassNullableOfDynamicToBigIntFromJson(Map json) { + return SimpleClassNullableOfDynamicToBigInt( + (json['value'] as Map?)?.map( (k, e) => MapEntry(k, BigInt.parse(e as String)), ), ); } -Map _$SimpleClassDynamicToBigIntToJson( - SimpleClassDynamicToBigInt instance) => +Map _$SimpleClassNullableOfDynamicToBigIntToJson( + SimpleClassNullableOfDynamicToBigInt instance) => { - 'value': instance.value?.map((k, e) => MapEntry(k, e?.toString())), - 'nullable': instance.nullable.map((k, e) => MapEntry(k, e.toString())), + 'value': instance.value?.map((k, e) => MapEntry(k, e.toString())), }; -SimpleClassEnumTypeToBigInt _$SimpleClassEnumTypeToBigIntFromJson( +SimpleClassOfEnumTypeToBigInt _$SimpleClassOfEnumTypeToBigIntFromJson( Map json) { - return SimpleClassEnumTypeToBigInt( - (json['value'] as Map)?.map( - (k, e) => MapEntry(_$enumDecodeNullable(_$EnumTypeEnumMap, k), - e == null ? null : BigInt.parse(e as String)), - ), - (json['nullable'] as Map).map( + return SimpleClassOfEnumTypeToBigInt( + (json['value'] as Map).map( (k, e) => MapEntry( _$enumDecode(_$EnumTypeEnumMap, k), BigInt.parse(e as String)), ), ); } -Map _$SimpleClassEnumTypeToBigIntToJson( - SimpleClassEnumTypeToBigInt instance) => +Map _$SimpleClassOfEnumTypeToBigIntToJson( + SimpleClassOfEnumTypeToBigInt instance) => { 'value': instance.value - ?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e?.toString())), - 'nullable': instance.nullable .map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e.toString())), }; -T _$enumDecode( - Map enumValues, - dynamic source, { - T unknownValue, +K _$enumDecode( + Map enumValues, + Object? source, { + K? unknownValue, }) { if (source == null) { - throw ArgumentError('A value must be provided. Supported values: ' - '${enumValues.values.join(', ')}'); - } - - final value = enumValues.entries - .singleWhere((e) => e.value == source, orElse: () => null) - ?.key; - - if (value == null && unknownValue == null) { - throw ArgumentError('`$source` is not one of the supported values: ' - '${enumValues.values.join(', ')}'); + throw ArgumentError( + 'A value must be provided. Supported values: ' + '${enumValues.values.join(', ')}', + ); } - return value ?? unknownValue; -} -T _$enumDecodeNullable( - Map enumValues, - dynamic source, { - T unknownValue, -}) { - if (source == null) { - return null; - } - return _$enumDecode(enumValues, source, unknownValue: unknownValue); + return enumValues.entries.singleWhere( + (e) => e.value == source, + orElse: () { + if (unknownValue == null) { + throw ArgumentError( + '`$source` is not one of the supported values: ' + '${enumValues.values.join(', ')}', + ); + } + return MapEntry(unknownValue, enumValues.values.first); + }, + ).key; } const _$EnumTypeEnumMap = { @@ -145,1787 +178,5610 @@ const _$EnumTypeEnumMap = { EnumType.delta: 'delta', }; -SimpleClassIntToBigInt _$SimpleClassIntToBigIntFromJson( +SimpleClassNullableOfEnumTypeToBigInt + _$SimpleClassNullableOfEnumTypeToBigIntFromJson(Map json) { + return SimpleClassNullableOfEnumTypeToBigInt( + (json['value'] as Map?)?.map( + (k, e) => MapEntry( + _$enumDecode(_$EnumTypeEnumMap, k), BigInt.parse(e as String)), + ), + ); +} + +Map _$SimpleClassNullableOfEnumTypeToBigIntToJson( + SimpleClassNullableOfEnumTypeToBigInt instance) => + { + 'value': instance.value + ?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e.toString())), + }; + +SimpleClassOfIntToBigInt _$SimpleClassOfIntToBigIntFromJson( Map json) { - return SimpleClassIntToBigInt( - (json['value'] as Map)?.map( - (k, e) => - MapEntry(int.parse(k), e == null ? null : BigInt.parse(e as String)), + return SimpleClassOfIntToBigInt( + (json['value'] as Map).map( + (k, e) => MapEntry(int.parse(k), BigInt.parse(e as String)), ), - (json['nullable'] as Map).map( + ); +} + +Map _$SimpleClassOfIntToBigIntToJson( + SimpleClassOfIntToBigInt instance) => + { + 'value': + instance.value.map((k, e) => MapEntry(k.toString(), e.toString())), + }; + +SimpleClassNullableOfIntToBigInt _$SimpleClassNullableOfIntToBigIntFromJson( + Map json) { + return SimpleClassNullableOfIntToBigInt( + (json['value'] as Map?)?.map( (k, e) => MapEntry(int.parse(k), BigInt.parse(e as String)), ), ); } -Map _$SimpleClassIntToBigIntToJson( - SimpleClassIntToBigInt instance) => +Map _$SimpleClassNullableOfIntToBigIntToJson( + SimpleClassNullableOfIntToBigInt instance) => { 'value': - instance.value?.map((k, e) => MapEntry(k.toString(), e?.toString())), - 'nullable': - instance.nullable.map((k, e) => MapEntry(k.toString(), e.toString())), + instance.value?.map((k, e) => MapEntry(k.toString(), e.toString())), }; -SimpleClassObjectToBigInt _$SimpleClassObjectToBigIntFromJson( +SimpleClassOfObjectToBigInt _$SimpleClassOfObjectToBigIntFromJson( Map json) { - return SimpleClassObjectToBigInt( - (json['value'] as Map)?.map( - (k, e) => MapEntry(k, e == null ? null : BigInt.parse(e as String)), + return SimpleClassOfObjectToBigInt( + (json['value'] as Map).map( + (k, e) => MapEntry(k, BigInt.parse(e as String)), ), - (json['nullable'] as Map).map( + ); +} + +Map _$SimpleClassOfObjectToBigIntToJson( + SimpleClassOfObjectToBigInt instance) => + { + 'value': instance.value.map((k, e) => MapEntry(k, e.toString())), + }; + +SimpleClassNullableOfObjectToBigInt + _$SimpleClassNullableOfObjectToBigIntFromJson(Map json) { + return SimpleClassNullableOfObjectToBigInt( + (json['value'] as Map?)?.map( (k, e) => MapEntry(k, BigInt.parse(e as String)), ), ); } -Map _$SimpleClassObjectToBigIntToJson( - SimpleClassObjectToBigInt instance) => +Map _$SimpleClassNullableOfObjectToBigIntToJson( + SimpleClassNullableOfObjectToBigInt instance) => { - 'value': instance.value?.map((k, e) => MapEntry(k, e?.toString())), - 'nullable': instance.nullable.map((k, e) => MapEntry(k, e.toString())), + 'value': instance.value?.map((k, e) => MapEntry(k, e.toString())), }; -SimpleClassStringToBigInt _$SimpleClassStringToBigIntFromJson( +SimpleClassOfStringToBigInt _$SimpleClassOfStringToBigIntFromJson( Map json) { - return SimpleClassStringToBigInt( - (json['value'] as Map)?.map( - (k, e) => MapEntry(k, e == null ? null : BigInt.parse(e as String)), + return SimpleClassOfStringToBigInt( + (json['value'] as Map).map( + (k, e) => MapEntry(k, BigInt.parse(e as String)), ), - (json['nullable'] as Map).map( + ); +} + +Map _$SimpleClassOfStringToBigIntToJson( + SimpleClassOfStringToBigInt instance) => + { + 'value': instance.value.map((k, e) => MapEntry(k, e.toString())), + }; + +SimpleClassNullableOfStringToBigInt + _$SimpleClassNullableOfStringToBigIntFromJson(Map json) { + return SimpleClassNullableOfStringToBigInt( + (json['value'] as Map?)?.map( (k, e) => MapEntry(k, BigInt.parse(e as String)), ), ); } -Map _$SimpleClassStringToBigIntToJson( - SimpleClassStringToBigInt instance) => +Map _$SimpleClassNullableOfStringToBigIntToJson( + SimpleClassNullableOfStringToBigInt instance) => { - 'value': instance.value?.map((k, e) => MapEntry(k, e?.toString())), - 'nullable': instance.nullable.map((k, e) => MapEntry(k, e.toString())), + 'value': instance.value?.map((k, e) => MapEntry(k, e.toString())), }; -SimpleClassUriToBigInt _$SimpleClassUriToBigIntFromJson( +SimpleClassOfUriToBigInt _$SimpleClassOfUriToBigIntFromJson( Map json) { - return SimpleClassUriToBigInt( - (json['value'] as Map)?.map( - (k, e) => - MapEntry(Uri.parse(k), e == null ? null : BigInt.parse(e as String)), + return SimpleClassOfUriToBigInt( + (json['value'] as Map).map( + (k, e) => MapEntry(Uri.parse(k), BigInt.parse(e as String)), ), - (json['nullable'] as Map).map( + ); +} + +Map _$SimpleClassOfUriToBigIntToJson( + SimpleClassOfUriToBigInt instance) => + { + 'value': + instance.value.map((k, e) => MapEntry(k.toString(), e.toString())), + }; + +SimpleClassNullableOfUriToBigInt _$SimpleClassNullableOfUriToBigIntFromJson( + Map json) { + return SimpleClassNullableOfUriToBigInt( + (json['value'] as Map?)?.map( (k, e) => MapEntry(Uri.parse(k), BigInt.parse(e as String)), ), ); } -Map _$SimpleClassUriToBigIntToJson( - SimpleClassUriToBigInt instance) => +Map _$SimpleClassNullableOfUriToBigIntToJson( + SimpleClassNullableOfUriToBigInt instance) => + { + 'value': + instance.value?.map((k, e) => MapEntry(k.toString(), e.toString())), + }; + +SimpleClassOfBigIntToBigIntNullable + _$SimpleClassOfBigIntToBigIntNullableFromJson(Map json) { + return SimpleClassOfBigIntToBigIntNullable( + (json['value'] as Map).map( + (k, e) => MapEntry( + BigInt.parse(k), e == null ? null : BigInt.parse(e as String)), + ), + ); +} + +Map _$SimpleClassOfBigIntToBigIntNullableToJson( + SimpleClassOfBigIntToBigIntNullable instance) => + { + 'value': + instance.value.map((k, e) => MapEntry(k.toString(), e?.toString())), + }; + +SimpleClassNullableOfBigIntToBigIntNullable + _$SimpleClassNullableOfBigIntToBigIntNullableFromJson( + Map json) { + return SimpleClassNullableOfBigIntToBigIntNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry( + BigInt.parse(k), e == null ? null : BigInt.parse(e as String)), + ), + ); +} + +Map _$SimpleClassNullableOfBigIntToBigIntNullableToJson( + SimpleClassNullableOfBigIntToBigIntNullable instance) => { 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e?.toString())), - 'nullable': - instance.nullable.map((k, e) => MapEntry(k.toString(), e.toString())), }; -SimpleClassBigIntToBool _$SimpleClassBigIntToBoolFromJson( - Map json) { - return SimpleClassBigIntToBool( - (json['value'] as Map)?.map( - (k, e) => MapEntry(BigInt.parse(k), e as bool), +SimpleClassOfDateTimeToBigIntNullable + _$SimpleClassOfDateTimeToBigIntNullableFromJson(Map json) { + return SimpleClassOfDateTimeToBigIntNullable( + (json['value'] as Map).map( + (k, e) => MapEntry( + DateTime.parse(k), e == null ? null : BigInt.parse(e as String)), ), - (json['nullable'] as Map).map( - (k, e) => MapEntry(BigInt.parse(k), e as bool), + ); +} + +Map _$SimpleClassOfDateTimeToBigIntNullableToJson( + SimpleClassOfDateTimeToBigIntNullable instance) => + { + 'value': instance.value + .map((k, e) => MapEntry(k.toIso8601String(), e?.toString())), + }; + +SimpleClassNullableOfDateTimeToBigIntNullable + _$SimpleClassNullableOfDateTimeToBigIntNullableFromJson( + Map json) { + return SimpleClassNullableOfDateTimeToBigIntNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry( + DateTime.parse(k), e == null ? null : BigInt.parse(e as String)), ), ); } -Map _$SimpleClassBigIntToBoolToJson( - SimpleClassBigIntToBool instance) => +Map _$SimpleClassNullableOfDateTimeToBigIntNullableToJson( + SimpleClassNullableOfDateTimeToBigIntNullable instance) => { - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - 'nullable': instance.nullable.map((k, e) => MapEntry(k.toString(), e)), + 'value': instance.value + ?.map((k, e) => MapEntry(k.toIso8601String(), e?.toString())), }; -SimpleClassDateTimeToBool _$SimpleClassDateTimeToBoolFromJson( - Map json) { - return SimpleClassDateTimeToBool( - (json['value'] as Map)?.map( - (k, e) => MapEntry(DateTime.parse(k), e as bool), +SimpleClassOfDynamicToBigIntNullable + _$SimpleClassOfDynamicToBigIntNullableFromJson(Map json) { + return SimpleClassOfDynamicToBigIntNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(k, e == null ? null : BigInt.parse(e as String)), ), - (json['nullable'] as Map).map( - (k, e) => MapEntry(DateTime.parse(k), e as bool), + ); +} + +Map _$SimpleClassOfDynamicToBigIntNullableToJson( + SimpleClassOfDynamicToBigIntNullable instance) => + { + 'value': instance.value.map((k, e) => MapEntry(k, e?.toString())), + }; + +SimpleClassNullableOfDynamicToBigIntNullable + _$SimpleClassNullableOfDynamicToBigIntNullableFromJson( + Map json) { + return SimpleClassNullableOfDynamicToBigIntNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e == null ? null : BigInt.parse(e as String)), ), ); } -Map _$SimpleClassDateTimeToBoolToJson( - SimpleClassDateTimeToBool instance) => +Map _$SimpleClassNullableOfDynamicToBigIntNullableToJson( + SimpleClassNullableOfDynamicToBigIntNullable instance) => { - 'value': instance.value?.map((k, e) => MapEntry(k.toIso8601String(), e)), - 'nullable': - instance.nullable.map((k, e) => MapEntry(k.toIso8601String(), e)), + 'value': instance.value?.map((k, e) => MapEntry(k, e?.toString())), + }; + +SimpleClassOfEnumTypeToBigIntNullable + _$SimpleClassOfEnumTypeToBigIntNullableFromJson(Map json) { + return SimpleClassOfEnumTypeToBigIntNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), + e == null ? null : BigInt.parse(e as String)), + ), + ); +} + +Map _$SimpleClassOfEnumTypeToBigIntNullableToJson( + SimpleClassOfEnumTypeToBigIntNullable instance) => + { + 'value': instance.value + .map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e?.toString())), + }; + +SimpleClassNullableOfEnumTypeToBigIntNullable + _$SimpleClassNullableOfEnumTypeToBigIntNullableFromJson( + Map json) { + return SimpleClassNullableOfEnumTypeToBigIntNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), + e == null ? null : BigInt.parse(e as String)), + ), + ); +} + +Map _$SimpleClassNullableOfEnumTypeToBigIntNullableToJson( + SimpleClassNullableOfEnumTypeToBigIntNullable instance) => + { + 'value': instance.value + ?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e?.toString())), }; -SimpleClassDynamicToBool _$SimpleClassDynamicToBoolFromJson( +SimpleClassOfIntToBigIntNullable _$SimpleClassOfIntToBigIntNullableFromJson( Map json) { - return SimpleClassDynamicToBool( - (json['value'] as Map)?.map( - (k, e) => MapEntry(k, e as bool), + return SimpleClassOfIntToBigIntNullable( + (json['value'] as Map).map( + (k, e) => + MapEntry(int.parse(k), e == null ? null : BigInt.parse(e as String)), ), - Map.from(json['nullable'] as Map), ); } -Map _$SimpleClassDynamicToBoolToJson( - SimpleClassDynamicToBool instance) => +Map _$SimpleClassOfIntToBigIntNullableToJson( + SimpleClassOfIntToBigIntNullable instance) => { - 'value': instance.value, - 'nullable': instance.nullable, + 'value': + instance.value.map((k, e) => MapEntry(k.toString(), e?.toString())), + }; + +SimpleClassNullableOfIntToBigIntNullable + _$SimpleClassNullableOfIntToBigIntNullableFromJson( + Map json) { + return SimpleClassNullableOfIntToBigIntNullable( + (json['value'] as Map?)?.map( + (k, e) => + MapEntry(int.parse(k), e == null ? null : BigInt.parse(e as String)), + ), + ); +} + +Map _$SimpleClassNullableOfIntToBigIntNullableToJson( + SimpleClassNullableOfIntToBigIntNullable instance) => + { + 'value': + instance.value?.map((k, e) => MapEntry(k.toString(), e?.toString())), + }; + +SimpleClassOfObjectToBigIntNullable + _$SimpleClassOfObjectToBigIntNullableFromJson(Map json) { + return SimpleClassOfObjectToBigIntNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(k, e == null ? null : BigInt.parse(e as String)), + ), + ); +} + +Map _$SimpleClassOfObjectToBigIntNullableToJson( + SimpleClassOfObjectToBigIntNullable instance) => + { + 'value': instance.value.map((k, e) => MapEntry(k, e?.toString())), + }; + +SimpleClassNullableOfObjectToBigIntNullable + _$SimpleClassNullableOfObjectToBigIntNullableFromJson( + Map json) { + return SimpleClassNullableOfObjectToBigIntNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e == null ? null : BigInt.parse(e as String)), + ), + ); +} + +Map _$SimpleClassNullableOfObjectToBigIntNullableToJson( + SimpleClassNullableOfObjectToBigIntNullable instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k, e?.toString())), + }; + +SimpleClassOfStringToBigIntNullable + _$SimpleClassOfStringToBigIntNullableFromJson(Map json) { + return SimpleClassOfStringToBigIntNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(k, e == null ? null : BigInt.parse(e as String)), + ), + ); +} + +Map _$SimpleClassOfStringToBigIntNullableToJson( + SimpleClassOfStringToBigIntNullable instance) => + { + 'value': instance.value.map((k, e) => MapEntry(k, e?.toString())), + }; + +SimpleClassNullableOfStringToBigIntNullable + _$SimpleClassNullableOfStringToBigIntNullableFromJson( + Map json) { + return SimpleClassNullableOfStringToBigIntNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e == null ? null : BigInt.parse(e as String)), + ), + ); +} + +Map _$SimpleClassNullableOfStringToBigIntNullableToJson( + SimpleClassNullableOfStringToBigIntNullable instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k, e?.toString())), }; -SimpleClassEnumTypeToBool _$SimpleClassEnumTypeToBoolFromJson( +SimpleClassOfUriToBigIntNullable _$SimpleClassOfUriToBigIntNullableFromJson( Map json) { - return SimpleClassEnumTypeToBool( - (json['value'] as Map)?.map( - (k, e) => MapEntry(_$enumDecodeNullable(_$EnumTypeEnumMap, k), e as bool), + return SimpleClassOfUriToBigIntNullable( + (json['value'] as Map).map( + (k, e) => + MapEntry(Uri.parse(k), e == null ? null : BigInt.parse(e as String)), ), - (json['nullable'] as Map).map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as bool), + ); +} + +Map _$SimpleClassOfUriToBigIntNullableToJson( + SimpleClassOfUriToBigIntNullable instance) => + { + 'value': + instance.value.map((k, e) => MapEntry(k.toString(), e?.toString())), + }; + +SimpleClassNullableOfUriToBigIntNullable + _$SimpleClassNullableOfUriToBigIntNullableFromJson( + Map json) { + return SimpleClassNullableOfUriToBigIntNullable( + (json['value'] as Map?)?.map( + (k, e) => + MapEntry(Uri.parse(k), e == null ? null : BigInt.parse(e as String)), ), ); } -Map _$SimpleClassEnumTypeToBoolToJson( - SimpleClassEnumTypeToBool instance) => +Map _$SimpleClassNullableOfUriToBigIntNullableToJson( + SimpleClassNullableOfUriToBigIntNullable instance) => { - 'value': instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), - 'nullable': - instance.nullable.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), + 'value': + instance.value?.map((k, e) => MapEntry(k.toString(), e?.toString())), }; -SimpleClassIntToBool _$SimpleClassIntToBoolFromJson(Map json) { - return SimpleClassIntToBool( - (json['value'] as Map)?.map( - (k, e) => MapEntry(int.parse(k), e as bool), +SimpleClassOfBigIntToBool _$SimpleClassOfBigIntToBoolFromJson( + Map json) { + return SimpleClassOfBigIntToBool( + (json['value'] as Map).map( + (k, e) => MapEntry(BigInt.parse(k), e as bool), ), - (json['nullable'] as Map).map( - (k, e) => MapEntry(int.parse(k), e as bool), + ); +} + +Map _$SimpleClassOfBigIntToBoolToJson( + SimpleClassOfBigIntToBool instance) => + { + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassNullableOfBigIntToBool _$SimpleClassNullableOfBigIntToBoolFromJson( + Map json) { + return SimpleClassNullableOfBigIntToBool( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(BigInt.parse(k), e as bool), + ), + ); +} + +Map _$SimpleClassNullableOfBigIntToBoolToJson( + SimpleClassNullableOfBigIntToBool instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassOfDateTimeToBool _$SimpleClassOfDateTimeToBoolFromJson( + Map json) { + return SimpleClassOfDateTimeToBool( + (json['value'] as Map).map( + (k, e) => MapEntry(DateTime.parse(k), e as bool), + ), + ); +} + +Map _$SimpleClassOfDateTimeToBoolToJson( + SimpleClassOfDateTimeToBool instance) => + { + 'value': instance.value.map((k, e) => MapEntry(k.toIso8601String(), e)), + }; + +SimpleClassNullableOfDateTimeToBool + _$SimpleClassNullableOfDateTimeToBoolFromJson(Map json) { + return SimpleClassNullableOfDateTimeToBool( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(DateTime.parse(k), e as bool), + ), + ); +} + +Map _$SimpleClassNullableOfDateTimeToBoolToJson( + SimpleClassNullableOfDateTimeToBool instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k.toIso8601String(), e)), + }; + +SimpleClassOfDynamicToBool _$SimpleClassOfDynamicToBoolFromJson( + Map json) { + return SimpleClassOfDynamicToBool( + Map.from(json['value'] as Map), + ); +} + +Map _$SimpleClassOfDynamicToBoolToJson( + SimpleClassOfDynamicToBool instance) => + { + 'value': instance.value, + }; + +SimpleClassNullableOfDynamicToBool _$SimpleClassNullableOfDynamicToBoolFromJson( + Map json) { + return SimpleClassNullableOfDynamicToBool( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e as bool), + ), + ); +} + +Map _$SimpleClassNullableOfDynamicToBoolToJson( + SimpleClassNullableOfDynamicToBool instance) => + { + 'value': instance.value, + }; + +SimpleClassOfEnumTypeToBool _$SimpleClassOfEnumTypeToBoolFromJson( + Map json) { + return SimpleClassOfEnumTypeToBool( + (json['value'] as Map).map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as bool), + ), + ); +} + +Map _$SimpleClassOfEnumTypeToBoolToJson( + SimpleClassOfEnumTypeToBool instance) => + { + 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), + }; + +SimpleClassNullableOfEnumTypeToBool + _$SimpleClassNullableOfEnumTypeToBoolFromJson(Map json) { + return SimpleClassNullableOfEnumTypeToBool( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as bool), + ), + ); +} + +Map _$SimpleClassNullableOfEnumTypeToBoolToJson( + SimpleClassNullableOfEnumTypeToBool instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), + }; + +SimpleClassOfIntToBool _$SimpleClassOfIntToBoolFromJson( + Map json) { + return SimpleClassOfIntToBool( + (json['value'] as Map).map( + (k, e) => MapEntry(int.parse(k), e as bool), + ), + ); +} + +Map _$SimpleClassOfIntToBoolToJson( + SimpleClassOfIntToBool instance) => + { + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassNullableOfIntToBool _$SimpleClassNullableOfIntToBoolFromJson( + Map json) { + return SimpleClassNullableOfIntToBool( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(int.parse(k), e as bool), + ), + ); +} + +Map _$SimpleClassNullableOfIntToBoolToJson( + SimpleClassNullableOfIntToBool instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassOfObjectToBool _$SimpleClassOfObjectToBoolFromJson( + Map json) { + return SimpleClassOfObjectToBool( + Map.from(json['value'] as Map), + ); +} + +Map _$SimpleClassOfObjectToBoolToJson( + SimpleClassOfObjectToBool instance) => + { + 'value': instance.value, + }; + +SimpleClassNullableOfObjectToBool _$SimpleClassNullableOfObjectToBoolFromJson( + Map json) { + return SimpleClassNullableOfObjectToBool( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e as bool), + ), + ); +} + +Map _$SimpleClassNullableOfObjectToBoolToJson( + SimpleClassNullableOfObjectToBool instance) => + { + 'value': instance.value, + }; + +SimpleClassOfStringToBool _$SimpleClassOfStringToBoolFromJson( + Map json) { + return SimpleClassOfStringToBool( + Map.from(json['value'] as Map), + ); +} + +Map _$SimpleClassOfStringToBoolToJson( + SimpleClassOfStringToBool instance) => + { + 'value': instance.value, + }; + +SimpleClassNullableOfStringToBool _$SimpleClassNullableOfStringToBoolFromJson( + Map json) { + return SimpleClassNullableOfStringToBool( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e as bool), + ), + ); +} + +Map _$SimpleClassNullableOfStringToBoolToJson( + SimpleClassNullableOfStringToBool instance) => + { + 'value': instance.value, + }; + +SimpleClassOfUriToBool _$SimpleClassOfUriToBoolFromJson( + Map json) { + return SimpleClassOfUriToBool( + (json['value'] as Map).map( + (k, e) => MapEntry(Uri.parse(k), e as bool), + ), + ); +} + +Map _$SimpleClassOfUriToBoolToJson( + SimpleClassOfUriToBool instance) => + { + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassNullableOfUriToBool _$SimpleClassNullableOfUriToBoolFromJson( + Map json) { + return SimpleClassNullableOfUriToBool( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(Uri.parse(k), e as bool), + ), + ); +} + +Map _$SimpleClassNullableOfUriToBoolToJson( + SimpleClassNullableOfUriToBool instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassOfBigIntToBoolNullable _$SimpleClassOfBigIntToBoolNullableFromJson( + Map json) { + return SimpleClassOfBigIntToBoolNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(BigInt.parse(k), e as bool?), + ), + ); +} + +Map _$SimpleClassOfBigIntToBoolNullableToJson( + SimpleClassOfBigIntToBoolNullable instance) => + { + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassNullableOfBigIntToBoolNullable + _$SimpleClassNullableOfBigIntToBoolNullableFromJson( + Map json) { + return SimpleClassNullableOfBigIntToBoolNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(BigInt.parse(k), e as bool?), + ), + ); +} + +Map _$SimpleClassNullableOfBigIntToBoolNullableToJson( + SimpleClassNullableOfBigIntToBoolNullable instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassOfDateTimeToBoolNullable + _$SimpleClassOfDateTimeToBoolNullableFromJson(Map json) { + return SimpleClassOfDateTimeToBoolNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(DateTime.parse(k), e as bool?), + ), + ); +} + +Map _$SimpleClassOfDateTimeToBoolNullableToJson( + SimpleClassOfDateTimeToBoolNullable instance) => + { + 'value': instance.value.map((k, e) => MapEntry(k.toIso8601String(), e)), + }; + +SimpleClassNullableOfDateTimeToBoolNullable + _$SimpleClassNullableOfDateTimeToBoolNullableFromJson( + Map json) { + return SimpleClassNullableOfDateTimeToBoolNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(DateTime.parse(k), e as bool?), + ), + ); +} + +Map _$SimpleClassNullableOfDateTimeToBoolNullableToJson( + SimpleClassNullableOfDateTimeToBoolNullable instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k.toIso8601String(), e)), + }; + +SimpleClassOfDynamicToBoolNullable _$SimpleClassOfDynamicToBoolNullableFromJson( + Map json) { + return SimpleClassOfDynamicToBoolNullable( + Map.from(json['value'] as Map), + ); +} + +Map _$SimpleClassOfDynamicToBoolNullableToJson( + SimpleClassOfDynamicToBoolNullable instance) => + { + 'value': instance.value, + }; + +SimpleClassNullableOfDynamicToBoolNullable + _$SimpleClassNullableOfDynamicToBoolNullableFromJson( + Map json) { + return SimpleClassNullableOfDynamicToBoolNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e as bool?), + ), + ); +} + +Map _$SimpleClassNullableOfDynamicToBoolNullableToJson( + SimpleClassNullableOfDynamicToBoolNullable instance) => + { + 'value': instance.value, + }; + +SimpleClassOfEnumTypeToBoolNullable + _$SimpleClassOfEnumTypeToBoolNullableFromJson(Map json) { + return SimpleClassOfEnumTypeToBoolNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as bool?), + ), + ); +} + +Map _$SimpleClassOfEnumTypeToBoolNullableToJson( + SimpleClassOfEnumTypeToBoolNullable instance) => + { + 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), + }; + +SimpleClassNullableOfEnumTypeToBoolNullable + _$SimpleClassNullableOfEnumTypeToBoolNullableFromJson( + Map json) { + return SimpleClassNullableOfEnumTypeToBoolNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as bool?), + ), + ); +} + +Map _$SimpleClassNullableOfEnumTypeToBoolNullableToJson( + SimpleClassNullableOfEnumTypeToBoolNullable instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), + }; + +SimpleClassOfIntToBoolNullable _$SimpleClassOfIntToBoolNullableFromJson( + Map json) { + return SimpleClassOfIntToBoolNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(int.parse(k), e as bool?), + ), + ); +} + +Map _$SimpleClassOfIntToBoolNullableToJson( + SimpleClassOfIntToBoolNullable instance) => + { + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassNullableOfIntToBoolNullable + _$SimpleClassNullableOfIntToBoolNullableFromJson( + Map json) { + return SimpleClassNullableOfIntToBoolNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(int.parse(k), e as bool?), + ), + ); +} + +Map _$SimpleClassNullableOfIntToBoolNullableToJson( + SimpleClassNullableOfIntToBoolNullable instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassOfObjectToBoolNullable _$SimpleClassOfObjectToBoolNullableFromJson( + Map json) { + return SimpleClassOfObjectToBoolNullable( + Map.from(json['value'] as Map), + ); +} + +Map _$SimpleClassOfObjectToBoolNullableToJson( + SimpleClassOfObjectToBoolNullable instance) => + { + 'value': instance.value, + }; + +SimpleClassNullableOfObjectToBoolNullable + _$SimpleClassNullableOfObjectToBoolNullableFromJson( + Map json) { + return SimpleClassNullableOfObjectToBoolNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e as bool?), + ), + ); +} + +Map _$SimpleClassNullableOfObjectToBoolNullableToJson( + SimpleClassNullableOfObjectToBoolNullable instance) => + { + 'value': instance.value, + }; + +SimpleClassOfStringToBoolNullable _$SimpleClassOfStringToBoolNullableFromJson( + Map json) { + return SimpleClassOfStringToBoolNullable( + Map.from(json['value'] as Map), + ); +} + +Map _$SimpleClassOfStringToBoolNullableToJson( + SimpleClassOfStringToBoolNullable instance) => + { + 'value': instance.value, + }; + +SimpleClassNullableOfStringToBoolNullable + _$SimpleClassNullableOfStringToBoolNullableFromJson( + Map json) { + return SimpleClassNullableOfStringToBoolNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e as bool?), + ), + ); +} + +Map _$SimpleClassNullableOfStringToBoolNullableToJson( + SimpleClassNullableOfStringToBoolNullable instance) => + { + 'value': instance.value, + }; + +SimpleClassOfUriToBoolNullable _$SimpleClassOfUriToBoolNullableFromJson( + Map json) { + return SimpleClassOfUriToBoolNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(Uri.parse(k), e as bool?), + ), + ); +} + +Map _$SimpleClassOfUriToBoolNullableToJson( + SimpleClassOfUriToBoolNullable instance) => + { + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassNullableOfUriToBoolNullable + _$SimpleClassNullableOfUriToBoolNullableFromJson( + Map json) { + return SimpleClassNullableOfUriToBoolNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(Uri.parse(k), e as bool?), + ), + ); +} + +Map _$SimpleClassNullableOfUriToBoolNullableToJson( + SimpleClassNullableOfUriToBoolNullable instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassOfBigIntToDateTime _$SimpleClassOfBigIntToDateTimeFromJson( + Map json) { + return SimpleClassOfBigIntToDateTime( + (json['value'] as Map).map( + (k, e) => MapEntry(BigInt.parse(k), DateTime.parse(e as String)), + ), + ); +} + +Map _$SimpleClassOfBigIntToDateTimeToJson( + SimpleClassOfBigIntToDateTime instance) => + { + 'value': instance.value + .map((k, e) => MapEntry(k.toString(), e.toIso8601String())), + }; + +SimpleClassNullableOfBigIntToDateTime + _$SimpleClassNullableOfBigIntToDateTimeFromJson(Map json) { + return SimpleClassNullableOfBigIntToDateTime( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(BigInt.parse(k), DateTime.parse(e as String)), + ), + ); +} + +Map _$SimpleClassNullableOfBigIntToDateTimeToJson( + SimpleClassNullableOfBigIntToDateTime instance) => + { + 'value': instance.value + ?.map((k, e) => MapEntry(k.toString(), e.toIso8601String())), + }; + +SimpleClassOfDateTimeToDateTime _$SimpleClassOfDateTimeToDateTimeFromJson( + Map json) { + return SimpleClassOfDateTimeToDateTime( + (json['value'] as Map).map( + (k, e) => MapEntry(DateTime.parse(k), DateTime.parse(e as String)), + ), + ); +} + +Map _$SimpleClassOfDateTimeToDateTimeToJson( + SimpleClassOfDateTimeToDateTime instance) => + { + 'value': instance.value + .map((k, e) => MapEntry(k.toIso8601String(), e.toIso8601String())), + }; + +SimpleClassNullableOfDateTimeToDateTime + _$SimpleClassNullableOfDateTimeToDateTimeFromJson( + Map json) { + return SimpleClassNullableOfDateTimeToDateTime( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(DateTime.parse(k), DateTime.parse(e as String)), + ), + ); +} + +Map _$SimpleClassNullableOfDateTimeToDateTimeToJson( + SimpleClassNullableOfDateTimeToDateTime instance) => + { + 'value': instance.value + ?.map((k, e) => MapEntry(k.toIso8601String(), e.toIso8601String())), + }; + +SimpleClassOfDynamicToDateTime _$SimpleClassOfDynamicToDateTimeFromJson( + Map json) { + return SimpleClassOfDynamicToDateTime( + (json['value'] as Map).map( + (k, e) => MapEntry(k, DateTime.parse(e as String)), + ), + ); +} + +Map _$SimpleClassOfDynamicToDateTimeToJson( + SimpleClassOfDynamicToDateTime instance) => + { + 'value': instance.value.map((k, e) => MapEntry(k, e.toIso8601String())), + }; + +SimpleClassNullableOfDynamicToDateTime + _$SimpleClassNullableOfDynamicToDateTimeFromJson( + Map json) { + return SimpleClassNullableOfDynamicToDateTime( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, DateTime.parse(e as String)), + ), + ); +} + +Map _$SimpleClassNullableOfDynamicToDateTimeToJson( + SimpleClassNullableOfDynamicToDateTime instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k, e.toIso8601String())), + }; + +SimpleClassOfEnumTypeToDateTime _$SimpleClassOfEnumTypeToDateTimeFromJson( + Map json) { + return SimpleClassOfEnumTypeToDateTime( + (json['value'] as Map).map( + (k, e) => MapEntry( + _$enumDecode(_$EnumTypeEnumMap, k), DateTime.parse(e as String)), + ), + ); +} + +Map _$SimpleClassOfEnumTypeToDateTimeToJson( + SimpleClassOfEnumTypeToDateTime instance) => + { + 'value': instance.value + .map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e.toIso8601String())), + }; + +SimpleClassNullableOfEnumTypeToDateTime + _$SimpleClassNullableOfEnumTypeToDateTimeFromJson( + Map json) { + return SimpleClassNullableOfEnumTypeToDateTime( + (json['value'] as Map?)?.map( + (k, e) => MapEntry( + _$enumDecode(_$EnumTypeEnumMap, k), DateTime.parse(e as String)), + ), + ); +} + +Map _$SimpleClassNullableOfEnumTypeToDateTimeToJson( + SimpleClassNullableOfEnumTypeToDateTime instance) => + { + 'value': instance.value + ?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e.toIso8601String())), + }; + +SimpleClassOfIntToDateTime _$SimpleClassOfIntToDateTimeFromJson( + Map json) { + return SimpleClassOfIntToDateTime( + (json['value'] as Map).map( + (k, e) => MapEntry(int.parse(k), DateTime.parse(e as String)), + ), + ); +} + +Map _$SimpleClassOfIntToDateTimeToJson( + SimpleClassOfIntToDateTime instance) => + { + 'value': instance.value + .map((k, e) => MapEntry(k.toString(), e.toIso8601String())), + }; + +SimpleClassNullableOfIntToDateTime _$SimpleClassNullableOfIntToDateTimeFromJson( + Map json) { + return SimpleClassNullableOfIntToDateTime( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(int.parse(k), DateTime.parse(e as String)), + ), + ); +} + +Map _$SimpleClassNullableOfIntToDateTimeToJson( + SimpleClassNullableOfIntToDateTime instance) => + { + 'value': instance.value + ?.map((k, e) => MapEntry(k.toString(), e.toIso8601String())), + }; + +SimpleClassOfObjectToDateTime _$SimpleClassOfObjectToDateTimeFromJson( + Map json) { + return SimpleClassOfObjectToDateTime( + (json['value'] as Map).map( + (k, e) => MapEntry(k, DateTime.parse(e as String)), + ), + ); +} + +Map _$SimpleClassOfObjectToDateTimeToJson( + SimpleClassOfObjectToDateTime instance) => + { + 'value': instance.value.map((k, e) => MapEntry(k, e.toIso8601String())), + }; + +SimpleClassNullableOfObjectToDateTime + _$SimpleClassNullableOfObjectToDateTimeFromJson(Map json) { + return SimpleClassNullableOfObjectToDateTime( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, DateTime.parse(e as String)), + ), + ); +} + +Map _$SimpleClassNullableOfObjectToDateTimeToJson( + SimpleClassNullableOfObjectToDateTime instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k, e.toIso8601String())), + }; + +SimpleClassOfStringToDateTime _$SimpleClassOfStringToDateTimeFromJson( + Map json) { + return SimpleClassOfStringToDateTime( + (json['value'] as Map).map( + (k, e) => MapEntry(k, DateTime.parse(e as String)), + ), + ); +} + +Map _$SimpleClassOfStringToDateTimeToJson( + SimpleClassOfStringToDateTime instance) => + { + 'value': instance.value.map((k, e) => MapEntry(k, e.toIso8601String())), + }; + +SimpleClassNullableOfStringToDateTime + _$SimpleClassNullableOfStringToDateTimeFromJson(Map json) { + return SimpleClassNullableOfStringToDateTime( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, DateTime.parse(e as String)), + ), + ); +} + +Map _$SimpleClassNullableOfStringToDateTimeToJson( + SimpleClassNullableOfStringToDateTime instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k, e.toIso8601String())), + }; + +SimpleClassOfUriToDateTime _$SimpleClassOfUriToDateTimeFromJson( + Map json) { + return SimpleClassOfUriToDateTime( + (json['value'] as Map).map( + (k, e) => MapEntry(Uri.parse(k), DateTime.parse(e as String)), + ), + ); +} + +Map _$SimpleClassOfUriToDateTimeToJson( + SimpleClassOfUriToDateTime instance) => + { + 'value': instance.value + .map((k, e) => MapEntry(k.toString(), e.toIso8601String())), + }; + +SimpleClassNullableOfUriToDateTime _$SimpleClassNullableOfUriToDateTimeFromJson( + Map json) { + return SimpleClassNullableOfUriToDateTime( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(Uri.parse(k), DateTime.parse(e as String)), + ), + ); +} + +Map _$SimpleClassNullableOfUriToDateTimeToJson( + SimpleClassNullableOfUriToDateTime instance) => + { + 'value': instance.value + ?.map((k, e) => MapEntry(k.toString(), e.toIso8601String())), + }; + +SimpleClassOfBigIntToDateTimeNullable + _$SimpleClassOfBigIntToDateTimeNullableFromJson(Map json) { + return SimpleClassOfBigIntToDateTimeNullable( + (json['value'] as Map).map( + (k, e) => MapEntry( + BigInt.parse(k), e == null ? null : DateTime.parse(e as String)), + ), + ); +} + +Map _$SimpleClassOfBigIntToDateTimeNullableToJson( + SimpleClassOfBigIntToDateTimeNullable instance) => + { + 'value': instance.value + .map((k, e) => MapEntry(k.toString(), e?.toIso8601String())), + }; + +SimpleClassNullableOfBigIntToDateTimeNullable + _$SimpleClassNullableOfBigIntToDateTimeNullableFromJson( + Map json) { + return SimpleClassNullableOfBigIntToDateTimeNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry( + BigInt.parse(k), e == null ? null : DateTime.parse(e as String)), + ), + ); +} + +Map _$SimpleClassNullableOfBigIntToDateTimeNullableToJson( + SimpleClassNullableOfBigIntToDateTimeNullable instance) => + { + 'value': instance.value + ?.map((k, e) => MapEntry(k.toString(), e?.toIso8601String())), + }; + +SimpleClassOfDateTimeToDateTimeNullable + _$SimpleClassOfDateTimeToDateTimeNullableFromJson( + Map json) { + return SimpleClassOfDateTimeToDateTimeNullable( + (json['value'] as Map).map( + (k, e) => MapEntry( + DateTime.parse(k), e == null ? null : DateTime.parse(e as String)), + ), + ); +} + +Map _$SimpleClassOfDateTimeToDateTimeNullableToJson( + SimpleClassOfDateTimeToDateTimeNullable instance) => + { + 'value': instance.value + .map((k, e) => MapEntry(k.toIso8601String(), e?.toIso8601String())), + }; + +SimpleClassNullableOfDateTimeToDateTimeNullable + _$SimpleClassNullableOfDateTimeToDateTimeNullableFromJson( + Map json) { + return SimpleClassNullableOfDateTimeToDateTimeNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry( + DateTime.parse(k), e == null ? null : DateTime.parse(e as String)), + ), + ); +} + +Map _$SimpleClassNullableOfDateTimeToDateTimeNullableToJson( + SimpleClassNullableOfDateTimeToDateTimeNullable instance) => + { + 'value': instance.value + ?.map((k, e) => MapEntry(k.toIso8601String(), e?.toIso8601String())), + }; + +SimpleClassOfDynamicToDateTimeNullable + _$SimpleClassOfDynamicToDateTimeNullableFromJson( + Map json) { + return SimpleClassOfDynamicToDateTimeNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(k, e == null ? null : DateTime.parse(e as String)), + ), + ); +} + +Map _$SimpleClassOfDynamicToDateTimeNullableToJson( + SimpleClassOfDynamicToDateTimeNullable instance) => + { + 'value': instance.value.map((k, e) => MapEntry(k, e?.toIso8601String())), + }; + +SimpleClassNullableOfDynamicToDateTimeNullable + _$SimpleClassNullableOfDynamicToDateTimeNullableFromJson( + Map json) { + return SimpleClassNullableOfDynamicToDateTimeNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e == null ? null : DateTime.parse(e as String)), + ), + ); +} + +Map _$SimpleClassNullableOfDynamicToDateTimeNullableToJson( + SimpleClassNullableOfDynamicToDateTimeNullable instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k, e?.toIso8601String())), + }; + +SimpleClassOfEnumTypeToDateTimeNullable + _$SimpleClassOfEnumTypeToDateTimeNullableFromJson( + Map json) { + return SimpleClassOfEnumTypeToDateTimeNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), + e == null ? null : DateTime.parse(e as String)), + ), + ); +} + +Map _$SimpleClassOfEnumTypeToDateTimeNullableToJson( + SimpleClassOfEnumTypeToDateTimeNullable instance) => + { + 'value': instance.value + .map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e?.toIso8601String())), + }; + +SimpleClassNullableOfEnumTypeToDateTimeNullable + _$SimpleClassNullableOfEnumTypeToDateTimeNullableFromJson( + Map json) { + return SimpleClassNullableOfEnumTypeToDateTimeNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), + e == null ? null : DateTime.parse(e as String)), + ), + ); +} + +Map _$SimpleClassNullableOfEnumTypeToDateTimeNullableToJson( + SimpleClassNullableOfEnumTypeToDateTimeNullable instance) => + { + 'value': instance.value + ?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e?.toIso8601String())), + }; + +SimpleClassOfIntToDateTimeNullable _$SimpleClassOfIntToDateTimeNullableFromJson( + Map json) { + return SimpleClassOfIntToDateTimeNullable( + (json['value'] as Map).map( + (k, e) => MapEntry( + int.parse(k), e == null ? null : DateTime.parse(e as String)), + ), + ); +} + +Map _$SimpleClassOfIntToDateTimeNullableToJson( + SimpleClassOfIntToDateTimeNullable instance) => + { + 'value': instance.value + .map((k, e) => MapEntry(k.toString(), e?.toIso8601String())), + }; + +SimpleClassNullableOfIntToDateTimeNullable + _$SimpleClassNullableOfIntToDateTimeNullableFromJson( + Map json) { + return SimpleClassNullableOfIntToDateTimeNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry( + int.parse(k), e == null ? null : DateTime.parse(e as String)), + ), + ); +} + +Map _$SimpleClassNullableOfIntToDateTimeNullableToJson( + SimpleClassNullableOfIntToDateTimeNullable instance) => + { + 'value': instance.value + ?.map((k, e) => MapEntry(k.toString(), e?.toIso8601String())), + }; + +SimpleClassOfObjectToDateTimeNullable + _$SimpleClassOfObjectToDateTimeNullableFromJson(Map json) { + return SimpleClassOfObjectToDateTimeNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(k, e == null ? null : DateTime.parse(e as String)), + ), + ); +} + +Map _$SimpleClassOfObjectToDateTimeNullableToJson( + SimpleClassOfObjectToDateTimeNullable instance) => + { + 'value': instance.value.map((k, e) => MapEntry(k, e?.toIso8601String())), + }; + +SimpleClassNullableOfObjectToDateTimeNullable + _$SimpleClassNullableOfObjectToDateTimeNullableFromJson( + Map json) { + return SimpleClassNullableOfObjectToDateTimeNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e == null ? null : DateTime.parse(e as String)), + ), + ); +} + +Map _$SimpleClassNullableOfObjectToDateTimeNullableToJson( + SimpleClassNullableOfObjectToDateTimeNullable instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k, e?.toIso8601String())), + }; + +SimpleClassOfStringToDateTimeNullable + _$SimpleClassOfStringToDateTimeNullableFromJson(Map json) { + return SimpleClassOfStringToDateTimeNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(k, e == null ? null : DateTime.parse(e as String)), + ), + ); +} + +Map _$SimpleClassOfStringToDateTimeNullableToJson( + SimpleClassOfStringToDateTimeNullable instance) => + { + 'value': instance.value.map((k, e) => MapEntry(k, e?.toIso8601String())), + }; + +SimpleClassNullableOfStringToDateTimeNullable + _$SimpleClassNullableOfStringToDateTimeNullableFromJson( + Map json) { + return SimpleClassNullableOfStringToDateTimeNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e == null ? null : DateTime.parse(e as String)), + ), + ); +} + +Map _$SimpleClassNullableOfStringToDateTimeNullableToJson( + SimpleClassNullableOfStringToDateTimeNullable instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k, e?.toIso8601String())), + }; + +SimpleClassOfUriToDateTimeNullable _$SimpleClassOfUriToDateTimeNullableFromJson( + Map json) { + return SimpleClassOfUriToDateTimeNullable( + (json['value'] as Map).map( + (k, e) => MapEntry( + Uri.parse(k), e == null ? null : DateTime.parse(e as String)), + ), + ); +} + +Map _$SimpleClassOfUriToDateTimeNullableToJson( + SimpleClassOfUriToDateTimeNullable instance) => + { + 'value': instance.value + .map((k, e) => MapEntry(k.toString(), e?.toIso8601String())), + }; + +SimpleClassNullableOfUriToDateTimeNullable + _$SimpleClassNullableOfUriToDateTimeNullableFromJson( + Map json) { + return SimpleClassNullableOfUriToDateTimeNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry( + Uri.parse(k), e == null ? null : DateTime.parse(e as String)), + ), + ); +} + +Map _$SimpleClassNullableOfUriToDateTimeNullableToJson( + SimpleClassNullableOfUriToDateTimeNullable instance) => + { + 'value': instance.value + ?.map((k, e) => MapEntry(k.toString(), e?.toIso8601String())), + }; + +SimpleClassOfBigIntToDouble _$SimpleClassOfBigIntToDoubleFromJson( + Map json) { + return SimpleClassOfBigIntToDouble( + (json['value'] as Map).map( + (k, e) => MapEntry(BigInt.parse(k), (e as num).toDouble()), + ), + ); +} + +Map _$SimpleClassOfBigIntToDoubleToJson( + SimpleClassOfBigIntToDouble instance) => + { + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassNullableOfBigIntToDouble + _$SimpleClassNullableOfBigIntToDoubleFromJson(Map json) { + return SimpleClassNullableOfBigIntToDouble( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(BigInt.parse(k), (e as num).toDouble()), + ), + ); +} + +Map _$SimpleClassNullableOfBigIntToDoubleToJson( + SimpleClassNullableOfBigIntToDouble instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassOfDateTimeToDouble _$SimpleClassOfDateTimeToDoubleFromJson( + Map json) { + return SimpleClassOfDateTimeToDouble( + (json['value'] as Map).map( + (k, e) => MapEntry(DateTime.parse(k), (e as num).toDouble()), + ), + ); +} + +Map _$SimpleClassOfDateTimeToDoubleToJson( + SimpleClassOfDateTimeToDouble instance) => + { + 'value': instance.value.map((k, e) => MapEntry(k.toIso8601String(), e)), + }; + +SimpleClassNullableOfDateTimeToDouble + _$SimpleClassNullableOfDateTimeToDoubleFromJson(Map json) { + return SimpleClassNullableOfDateTimeToDouble( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(DateTime.parse(k), (e as num).toDouble()), + ), + ); +} + +Map _$SimpleClassNullableOfDateTimeToDoubleToJson( + SimpleClassNullableOfDateTimeToDouble instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k.toIso8601String(), e)), + }; + +SimpleClassOfDynamicToDouble _$SimpleClassOfDynamicToDoubleFromJson( + Map json) { + return SimpleClassOfDynamicToDouble( + Map.from(json['value'] as Map), + ); +} + +Map _$SimpleClassOfDynamicToDoubleToJson( + SimpleClassOfDynamicToDouble instance) => + { + 'value': instance.value, + }; + +SimpleClassNullableOfDynamicToDouble + _$SimpleClassNullableOfDynamicToDoubleFromJson(Map json) { + return SimpleClassNullableOfDynamicToDouble( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, (e as num).toDouble()), + ), + ); +} + +Map _$SimpleClassNullableOfDynamicToDoubleToJson( + SimpleClassNullableOfDynamicToDouble instance) => + { + 'value': instance.value, + }; + +SimpleClassOfEnumTypeToDouble _$SimpleClassOfEnumTypeToDoubleFromJson( + Map json) { + return SimpleClassOfEnumTypeToDouble( + (json['value'] as Map).map( + (k, e) => + MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), (e as num).toDouble()), + ), + ); +} + +Map _$SimpleClassOfEnumTypeToDoubleToJson( + SimpleClassOfEnumTypeToDouble instance) => + { + 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), + }; + +SimpleClassNullableOfEnumTypeToDouble + _$SimpleClassNullableOfEnumTypeToDoubleFromJson(Map json) { + return SimpleClassNullableOfEnumTypeToDouble( + (json['value'] as Map?)?.map( + (k, e) => + MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), (e as num).toDouble()), + ), + ); +} + +Map _$SimpleClassNullableOfEnumTypeToDoubleToJson( + SimpleClassNullableOfEnumTypeToDouble instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), + }; + +SimpleClassOfIntToDouble _$SimpleClassOfIntToDoubleFromJson( + Map json) { + return SimpleClassOfIntToDouble( + (json['value'] as Map).map( + (k, e) => MapEntry(int.parse(k), (e as num).toDouble()), + ), + ); +} + +Map _$SimpleClassOfIntToDoubleToJson( + SimpleClassOfIntToDouble instance) => + { + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassNullableOfIntToDouble _$SimpleClassNullableOfIntToDoubleFromJson( + Map json) { + return SimpleClassNullableOfIntToDouble( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(int.parse(k), (e as num).toDouble()), + ), + ); +} + +Map _$SimpleClassNullableOfIntToDoubleToJson( + SimpleClassNullableOfIntToDouble instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassOfObjectToDouble _$SimpleClassOfObjectToDoubleFromJson( + Map json) { + return SimpleClassOfObjectToDouble( + Map.from(json['value'] as Map), + ); +} + +Map _$SimpleClassOfObjectToDoubleToJson( + SimpleClassOfObjectToDouble instance) => + { + 'value': instance.value, + }; + +SimpleClassNullableOfObjectToDouble + _$SimpleClassNullableOfObjectToDoubleFromJson(Map json) { + return SimpleClassNullableOfObjectToDouble( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, (e as num).toDouble()), + ), + ); +} + +Map _$SimpleClassNullableOfObjectToDoubleToJson( + SimpleClassNullableOfObjectToDouble instance) => + { + 'value': instance.value, + }; + +SimpleClassOfStringToDouble _$SimpleClassOfStringToDoubleFromJson( + Map json) { + return SimpleClassOfStringToDouble( + Map.from(json['value'] as Map), + ); +} + +Map _$SimpleClassOfStringToDoubleToJson( + SimpleClassOfStringToDouble instance) => + { + 'value': instance.value, + }; + +SimpleClassNullableOfStringToDouble + _$SimpleClassNullableOfStringToDoubleFromJson(Map json) { + return SimpleClassNullableOfStringToDouble( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, (e as num).toDouble()), + ), + ); +} + +Map _$SimpleClassNullableOfStringToDoubleToJson( + SimpleClassNullableOfStringToDouble instance) => + { + 'value': instance.value, + }; + +SimpleClassOfUriToDouble _$SimpleClassOfUriToDoubleFromJson( + Map json) { + return SimpleClassOfUriToDouble( + (json['value'] as Map).map( + (k, e) => MapEntry(Uri.parse(k), (e as num).toDouble()), + ), + ); +} + +Map _$SimpleClassOfUriToDoubleToJson( + SimpleClassOfUriToDouble instance) => + { + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassNullableOfUriToDouble _$SimpleClassNullableOfUriToDoubleFromJson( + Map json) { + return SimpleClassNullableOfUriToDouble( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(Uri.parse(k), (e as num).toDouble()), + ), + ); +} + +Map _$SimpleClassNullableOfUriToDoubleToJson( + SimpleClassNullableOfUriToDouble instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassOfBigIntToDoubleNullable + _$SimpleClassOfBigIntToDoubleNullableFromJson(Map json) { + return SimpleClassOfBigIntToDoubleNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(BigInt.parse(k), (e as num?)?.toDouble()), + ), + ); +} + +Map _$SimpleClassOfBigIntToDoubleNullableToJson( + SimpleClassOfBigIntToDoubleNullable instance) => + { + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassNullableOfBigIntToDoubleNullable + _$SimpleClassNullableOfBigIntToDoubleNullableFromJson( + Map json) { + return SimpleClassNullableOfBigIntToDoubleNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(BigInt.parse(k), (e as num?)?.toDouble()), + ), + ); +} + +Map _$SimpleClassNullableOfBigIntToDoubleNullableToJson( + SimpleClassNullableOfBigIntToDoubleNullable instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassOfDateTimeToDoubleNullable + _$SimpleClassOfDateTimeToDoubleNullableFromJson(Map json) { + return SimpleClassOfDateTimeToDoubleNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(DateTime.parse(k), (e as num?)?.toDouble()), + ), + ); +} + +Map _$SimpleClassOfDateTimeToDoubleNullableToJson( + SimpleClassOfDateTimeToDoubleNullable instance) => + { + 'value': instance.value.map((k, e) => MapEntry(k.toIso8601String(), e)), + }; + +SimpleClassNullableOfDateTimeToDoubleNullable + _$SimpleClassNullableOfDateTimeToDoubleNullableFromJson( + Map json) { + return SimpleClassNullableOfDateTimeToDoubleNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(DateTime.parse(k), (e as num?)?.toDouble()), + ), + ); +} + +Map _$SimpleClassNullableOfDateTimeToDoubleNullableToJson( + SimpleClassNullableOfDateTimeToDoubleNullable instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k.toIso8601String(), e)), + }; + +SimpleClassOfDynamicToDoubleNullable + _$SimpleClassOfDynamicToDoubleNullableFromJson(Map json) { + return SimpleClassOfDynamicToDoubleNullable( + Map.from(json['value'] as Map), + ); +} + +Map _$SimpleClassOfDynamicToDoubleNullableToJson( + SimpleClassOfDynamicToDoubleNullable instance) => + { + 'value': instance.value, + }; + +SimpleClassNullableOfDynamicToDoubleNullable + _$SimpleClassNullableOfDynamicToDoubleNullableFromJson( + Map json) { + return SimpleClassNullableOfDynamicToDoubleNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, (e as num?)?.toDouble()), + ), + ); +} + +Map _$SimpleClassNullableOfDynamicToDoubleNullableToJson( + SimpleClassNullableOfDynamicToDoubleNullable instance) => + { + 'value': instance.value, + }; + +SimpleClassOfEnumTypeToDoubleNullable + _$SimpleClassOfEnumTypeToDoubleNullableFromJson(Map json) { + return SimpleClassOfEnumTypeToDoubleNullable( + (json['value'] as Map).map( + (k, e) => + MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), (e as num?)?.toDouble()), + ), + ); +} + +Map _$SimpleClassOfEnumTypeToDoubleNullableToJson( + SimpleClassOfEnumTypeToDoubleNullable instance) => + { + 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), + }; + +SimpleClassNullableOfEnumTypeToDoubleNullable + _$SimpleClassNullableOfEnumTypeToDoubleNullableFromJson( + Map json) { + return SimpleClassNullableOfEnumTypeToDoubleNullable( + (json['value'] as Map?)?.map( + (k, e) => + MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), (e as num?)?.toDouble()), + ), + ); +} + +Map _$SimpleClassNullableOfEnumTypeToDoubleNullableToJson( + SimpleClassNullableOfEnumTypeToDoubleNullable instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), + }; + +SimpleClassOfIntToDoubleNullable _$SimpleClassOfIntToDoubleNullableFromJson( + Map json) { + return SimpleClassOfIntToDoubleNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(int.parse(k), (e as num?)?.toDouble()), + ), + ); +} + +Map _$SimpleClassOfIntToDoubleNullableToJson( + SimpleClassOfIntToDoubleNullable instance) => + { + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassNullableOfIntToDoubleNullable + _$SimpleClassNullableOfIntToDoubleNullableFromJson( + Map json) { + return SimpleClassNullableOfIntToDoubleNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(int.parse(k), (e as num?)?.toDouble()), + ), + ); +} + +Map _$SimpleClassNullableOfIntToDoubleNullableToJson( + SimpleClassNullableOfIntToDoubleNullable instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassOfObjectToDoubleNullable + _$SimpleClassOfObjectToDoubleNullableFromJson(Map json) { + return SimpleClassOfObjectToDoubleNullable( + Map.from(json['value'] as Map), + ); +} + +Map _$SimpleClassOfObjectToDoubleNullableToJson( + SimpleClassOfObjectToDoubleNullable instance) => + { + 'value': instance.value, + }; + +SimpleClassNullableOfObjectToDoubleNullable + _$SimpleClassNullableOfObjectToDoubleNullableFromJson( + Map json) { + return SimpleClassNullableOfObjectToDoubleNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, (e as num?)?.toDouble()), + ), + ); +} + +Map _$SimpleClassNullableOfObjectToDoubleNullableToJson( + SimpleClassNullableOfObjectToDoubleNullable instance) => + { + 'value': instance.value, + }; + +SimpleClassOfStringToDoubleNullable + _$SimpleClassOfStringToDoubleNullableFromJson(Map json) { + return SimpleClassOfStringToDoubleNullable( + Map.from(json['value'] as Map), + ); +} + +Map _$SimpleClassOfStringToDoubleNullableToJson( + SimpleClassOfStringToDoubleNullable instance) => + { + 'value': instance.value, + }; + +SimpleClassNullableOfStringToDoubleNullable + _$SimpleClassNullableOfStringToDoubleNullableFromJson( + Map json) { + return SimpleClassNullableOfStringToDoubleNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, (e as num?)?.toDouble()), + ), + ); +} + +Map _$SimpleClassNullableOfStringToDoubleNullableToJson( + SimpleClassNullableOfStringToDoubleNullable instance) => + { + 'value': instance.value, + }; + +SimpleClassOfUriToDoubleNullable _$SimpleClassOfUriToDoubleNullableFromJson( + Map json) { + return SimpleClassOfUriToDoubleNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(Uri.parse(k), (e as num?)?.toDouble()), + ), + ); +} + +Map _$SimpleClassOfUriToDoubleNullableToJson( + SimpleClassOfUriToDoubleNullable instance) => + { + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassNullableOfUriToDoubleNullable + _$SimpleClassNullableOfUriToDoubleNullableFromJson( + Map json) { + return SimpleClassNullableOfUriToDoubleNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(Uri.parse(k), (e as num?)?.toDouble()), + ), + ); +} + +Map _$SimpleClassNullableOfUriToDoubleNullableToJson( + SimpleClassNullableOfUriToDoubleNullable instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassOfBigIntToDuration _$SimpleClassOfBigIntToDurationFromJson( + Map json) { + return SimpleClassOfBigIntToDuration( + (json['value'] as Map).map( + (k, e) => MapEntry(BigInt.parse(k), Duration(microseconds: e as int)), + ), + ); +} + +Map _$SimpleClassOfBigIntToDurationToJson( + SimpleClassOfBigIntToDuration instance) => + { + 'value': instance.value + .map((k, e) => MapEntry(k.toString(), e.inMicroseconds)), + }; + +SimpleClassNullableOfBigIntToDuration + _$SimpleClassNullableOfBigIntToDurationFromJson(Map json) { + return SimpleClassNullableOfBigIntToDuration( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(BigInt.parse(k), Duration(microseconds: e as int)), + ), + ); +} + +Map _$SimpleClassNullableOfBigIntToDurationToJson( + SimpleClassNullableOfBigIntToDuration instance) => + { + 'value': instance.value + ?.map((k, e) => MapEntry(k.toString(), e.inMicroseconds)), + }; + +SimpleClassOfDateTimeToDuration _$SimpleClassOfDateTimeToDurationFromJson( + Map json) { + return SimpleClassOfDateTimeToDuration( + (json['value'] as Map).map( + (k, e) => MapEntry(DateTime.parse(k), Duration(microseconds: e as int)), + ), + ); +} + +Map _$SimpleClassOfDateTimeToDurationToJson( + SimpleClassOfDateTimeToDuration instance) => + { + 'value': instance.value + .map((k, e) => MapEntry(k.toIso8601String(), e.inMicroseconds)), + }; + +SimpleClassNullableOfDateTimeToDuration + _$SimpleClassNullableOfDateTimeToDurationFromJson( + Map json) { + return SimpleClassNullableOfDateTimeToDuration( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(DateTime.parse(k), Duration(microseconds: e as int)), + ), + ); +} + +Map _$SimpleClassNullableOfDateTimeToDurationToJson( + SimpleClassNullableOfDateTimeToDuration instance) => + { + 'value': instance.value + ?.map((k, e) => MapEntry(k.toIso8601String(), e.inMicroseconds)), + }; + +SimpleClassOfDynamicToDuration _$SimpleClassOfDynamicToDurationFromJson( + Map json) { + return SimpleClassOfDynamicToDuration( + (json['value'] as Map).map( + (k, e) => MapEntry(k, Duration(microseconds: e as int)), + ), + ); +} + +Map _$SimpleClassOfDynamicToDurationToJson( + SimpleClassOfDynamicToDuration instance) => + { + 'value': instance.value.map((k, e) => MapEntry(k, e.inMicroseconds)), + }; + +SimpleClassNullableOfDynamicToDuration + _$SimpleClassNullableOfDynamicToDurationFromJson( + Map json) { + return SimpleClassNullableOfDynamicToDuration( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, Duration(microseconds: e as int)), + ), + ); +} + +Map _$SimpleClassNullableOfDynamicToDurationToJson( + SimpleClassNullableOfDynamicToDuration instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k, e.inMicroseconds)), + }; + +SimpleClassOfEnumTypeToDuration _$SimpleClassOfEnumTypeToDurationFromJson( + Map json) { + return SimpleClassOfEnumTypeToDuration( + (json['value'] as Map).map( + (k, e) => MapEntry( + _$enumDecode(_$EnumTypeEnumMap, k), Duration(microseconds: e as int)), + ), + ); +} + +Map _$SimpleClassOfEnumTypeToDurationToJson( + SimpleClassOfEnumTypeToDuration instance) => + { + 'value': instance.value + .map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e.inMicroseconds)), + }; + +SimpleClassNullableOfEnumTypeToDuration + _$SimpleClassNullableOfEnumTypeToDurationFromJson( + Map json) { + return SimpleClassNullableOfEnumTypeToDuration( + (json['value'] as Map?)?.map( + (k, e) => MapEntry( + _$enumDecode(_$EnumTypeEnumMap, k), Duration(microseconds: e as int)), + ), + ); +} + +Map _$SimpleClassNullableOfEnumTypeToDurationToJson( + SimpleClassNullableOfEnumTypeToDuration instance) => + { + 'value': instance.value + ?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e.inMicroseconds)), + }; + +SimpleClassOfIntToDuration _$SimpleClassOfIntToDurationFromJson( + Map json) { + return SimpleClassOfIntToDuration( + (json['value'] as Map).map( + (k, e) => MapEntry(int.parse(k), Duration(microseconds: e as int)), + ), + ); +} + +Map _$SimpleClassOfIntToDurationToJson( + SimpleClassOfIntToDuration instance) => + { + 'value': instance.value + .map((k, e) => MapEntry(k.toString(), e.inMicroseconds)), + }; + +SimpleClassNullableOfIntToDuration _$SimpleClassNullableOfIntToDurationFromJson( + Map json) { + return SimpleClassNullableOfIntToDuration( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(int.parse(k), Duration(microseconds: e as int)), + ), + ); +} + +Map _$SimpleClassNullableOfIntToDurationToJson( + SimpleClassNullableOfIntToDuration instance) => + { + 'value': instance.value + ?.map((k, e) => MapEntry(k.toString(), e.inMicroseconds)), + }; + +SimpleClassOfObjectToDuration _$SimpleClassOfObjectToDurationFromJson( + Map json) { + return SimpleClassOfObjectToDuration( + (json['value'] as Map).map( + (k, e) => MapEntry(k, Duration(microseconds: e as int)), + ), + ); +} + +Map _$SimpleClassOfObjectToDurationToJson( + SimpleClassOfObjectToDuration instance) => + { + 'value': instance.value.map((k, e) => MapEntry(k, e.inMicroseconds)), + }; + +SimpleClassNullableOfObjectToDuration + _$SimpleClassNullableOfObjectToDurationFromJson(Map json) { + return SimpleClassNullableOfObjectToDuration( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, Duration(microseconds: e as int)), + ), + ); +} + +Map _$SimpleClassNullableOfObjectToDurationToJson( + SimpleClassNullableOfObjectToDuration instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k, e.inMicroseconds)), + }; + +SimpleClassOfStringToDuration _$SimpleClassOfStringToDurationFromJson( + Map json) { + return SimpleClassOfStringToDuration( + (json['value'] as Map).map( + (k, e) => MapEntry(k, Duration(microseconds: e as int)), + ), + ); +} + +Map _$SimpleClassOfStringToDurationToJson( + SimpleClassOfStringToDuration instance) => + { + 'value': instance.value.map((k, e) => MapEntry(k, e.inMicroseconds)), + }; + +SimpleClassNullableOfStringToDuration + _$SimpleClassNullableOfStringToDurationFromJson(Map json) { + return SimpleClassNullableOfStringToDuration( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, Duration(microseconds: e as int)), + ), + ); +} + +Map _$SimpleClassNullableOfStringToDurationToJson( + SimpleClassNullableOfStringToDuration instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k, e.inMicroseconds)), + }; + +SimpleClassOfUriToDuration _$SimpleClassOfUriToDurationFromJson( + Map json) { + return SimpleClassOfUriToDuration( + (json['value'] as Map).map( + (k, e) => MapEntry(Uri.parse(k), Duration(microseconds: e as int)), + ), + ); +} + +Map _$SimpleClassOfUriToDurationToJson( + SimpleClassOfUriToDuration instance) => + { + 'value': instance.value + .map((k, e) => MapEntry(k.toString(), e.inMicroseconds)), + }; + +SimpleClassNullableOfUriToDuration _$SimpleClassNullableOfUriToDurationFromJson( + Map json) { + return SimpleClassNullableOfUriToDuration( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(Uri.parse(k), Duration(microseconds: e as int)), + ), + ); +} + +Map _$SimpleClassNullableOfUriToDurationToJson( + SimpleClassNullableOfUriToDuration instance) => + { + 'value': instance.value + ?.map((k, e) => MapEntry(k.toString(), e.inMicroseconds)), + }; + +SimpleClassOfBigIntToDurationNullable + _$SimpleClassOfBigIntToDurationNullableFromJson(Map json) { + return SimpleClassOfBigIntToDurationNullable( + (json['value'] as Map).map( + (k, e) => MapEntry( + BigInt.parse(k), e == null ? null : Duration(microseconds: e as int)), + ), + ); +} + +Map _$SimpleClassOfBigIntToDurationNullableToJson( + SimpleClassOfBigIntToDurationNullable instance) => + { + 'value': instance.value + .map((k, e) => MapEntry(k.toString(), e?.inMicroseconds)), + }; + +SimpleClassNullableOfBigIntToDurationNullable + _$SimpleClassNullableOfBigIntToDurationNullableFromJson( + Map json) { + return SimpleClassNullableOfBigIntToDurationNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry( + BigInt.parse(k), e == null ? null : Duration(microseconds: e as int)), + ), + ); +} + +Map _$SimpleClassNullableOfBigIntToDurationNullableToJson( + SimpleClassNullableOfBigIntToDurationNullable instance) => + { + 'value': instance.value + ?.map((k, e) => MapEntry(k.toString(), e?.inMicroseconds)), + }; + +SimpleClassOfDateTimeToDurationNullable + _$SimpleClassOfDateTimeToDurationNullableFromJson( + Map json) { + return SimpleClassOfDateTimeToDurationNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(DateTime.parse(k), + e == null ? null : Duration(microseconds: e as int)), + ), + ); +} + +Map _$SimpleClassOfDateTimeToDurationNullableToJson( + SimpleClassOfDateTimeToDurationNullable instance) => + { + 'value': instance.value + .map((k, e) => MapEntry(k.toIso8601String(), e?.inMicroseconds)), + }; + +SimpleClassNullableOfDateTimeToDurationNullable + _$SimpleClassNullableOfDateTimeToDurationNullableFromJson( + Map json) { + return SimpleClassNullableOfDateTimeToDurationNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(DateTime.parse(k), + e == null ? null : Duration(microseconds: e as int)), + ), + ); +} + +Map _$SimpleClassNullableOfDateTimeToDurationNullableToJson( + SimpleClassNullableOfDateTimeToDurationNullable instance) => + { + 'value': instance.value + ?.map((k, e) => MapEntry(k.toIso8601String(), e?.inMicroseconds)), + }; + +SimpleClassOfDynamicToDurationNullable + _$SimpleClassOfDynamicToDurationNullableFromJson( + Map json) { + return SimpleClassOfDynamicToDurationNullable( + (json['value'] as Map).map( + (k, e) => + MapEntry(k, e == null ? null : Duration(microseconds: e as int)), + ), + ); +} + +Map _$SimpleClassOfDynamicToDurationNullableToJson( + SimpleClassOfDynamicToDurationNullable instance) => + { + 'value': instance.value.map((k, e) => MapEntry(k, e?.inMicroseconds)), + }; + +SimpleClassNullableOfDynamicToDurationNullable + _$SimpleClassNullableOfDynamicToDurationNullableFromJson( + Map json) { + return SimpleClassNullableOfDynamicToDurationNullable( + (json['value'] as Map?)?.map( + (k, e) => + MapEntry(k, e == null ? null : Duration(microseconds: e as int)), + ), + ); +} + +Map _$SimpleClassNullableOfDynamicToDurationNullableToJson( + SimpleClassNullableOfDynamicToDurationNullable instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k, e?.inMicroseconds)), + }; + +SimpleClassOfEnumTypeToDurationNullable + _$SimpleClassOfEnumTypeToDurationNullableFromJson( + Map json) { + return SimpleClassOfEnumTypeToDurationNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), + e == null ? null : Duration(microseconds: e as int)), + ), + ); +} + +Map _$SimpleClassOfEnumTypeToDurationNullableToJson( + SimpleClassOfEnumTypeToDurationNullable instance) => + { + 'value': instance.value + .map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e?.inMicroseconds)), + }; + +SimpleClassNullableOfEnumTypeToDurationNullable + _$SimpleClassNullableOfEnumTypeToDurationNullableFromJson( + Map json) { + return SimpleClassNullableOfEnumTypeToDurationNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), + e == null ? null : Duration(microseconds: e as int)), + ), + ); +} + +Map _$SimpleClassNullableOfEnumTypeToDurationNullableToJson( + SimpleClassNullableOfEnumTypeToDurationNullable instance) => + { + 'value': instance.value + ?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e?.inMicroseconds)), + }; + +SimpleClassOfIntToDurationNullable _$SimpleClassOfIntToDurationNullableFromJson( + Map json) { + return SimpleClassOfIntToDurationNullable( + (json['value'] as Map).map( + (k, e) => MapEntry( + int.parse(k), e == null ? null : Duration(microseconds: e as int)), + ), + ); +} + +Map _$SimpleClassOfIntToDurationNullableToJson( + SimpleClassOfIntToDurationNullable instance) => + { + 'value': instance.value + .map((k, e) => MapEntry(k.toString(), e?.inMicroseconds)), + }; + +SimpleClassNullableOfIntToDurationNullable + _$SimpleClassNullableOfIntToDurationNullableFromJson( + Map json) { + return SimpleClassNullableOfIntToDurationNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry( + int.parse(k), e == null ? null : Duration(microseconds: e as int)), + ), + ); +} + +Map _$SimpleClassNullableOfIntToDurationNullableToJson( + SimpleClassNullableOfIntToDurationNullable instance) => + { + 'value': instance.value + ?.map((k, e) => MapEntry(k.toString(), e?.inMicroseconds)), + }; + +SimpleClassOfObjectToDurationNullable + _$SimpleClassOfObjectToDurationNullableFromJson(Map json) { + return SimpleClassOfObjectToDurationNullable( + (json['value'] as Map).map( + (k, e) => + MapEntry(k, e == null ? null : Duration(microseconds: e as int)), + ), + ); +} + +Map _$SimpleClassOfObjectToDurationNullableToJson( + SimpleClassOfObjectToDurationNullable instance) => + { + 'value': instance.value.map((k, e) => MapEntry(k, e?.inMicroseconds)), + }; + +SimpleClassNullableOfObjectToDurationNullable + _$SimpleClassNullableOfObjectToDurationNullableFromJson( + Map json) { + return SimpleClassNullableOfObjectToDurationNullable( + (json['value'] as Map?)?.map( + (k, e) => + MapEntry(k, e == null ? null : Duration(microseconds: e as int)), + ), + ); +} + +Map _$SimpleClassNullableOfObjectToDurationNullableToJson( + SimpleClassNullableOfObjectToDurationNullable instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k, e?.inMicroseconds)), + }; + +SimpleClassOfStringToDurationNullable + _$SimpleClassOfStringToDurationNullableFromJson(Map json) { + return SimpleClassOfStringToDurationNullable( + (json['value'] as Map).map( + (k, e) => + MapEntry(k, e == null ? null : Duration(microseconds: e as int)), + ), + ); +} + +Map _$SimpleClassOfStringToDurationNullableToJson( + SimpleClassOfStringToDurationNullable instance) => + { + 'value': instance.value.map((k, e) => MapEntry(k, e?.inMicroseconds)), + }; + +SimpleClassNullableOfStringToDurationNullable + _$SimpleClassNullableOfStringToDurationNullableFromJson( + Map json) { + return SimpleClassNullableOfStringToDurationNullable( + (json['value'] as Map?)?.map( + (k, e) => + MapEntry(k, e == null ? null : Duration(microseconds: e as int)), + ), + ); +} + +Map _$SimpleClassNullableOfStringToDurationNullableToJson( + SimpleClassNullableOfStringToDurationNullable instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k, e?.inMicroseconds)), + }; + +SimpleClassOfUriToDurationNullable _$SimpleClassOfUriToDurationNullableFromJson( + Map json) { + return SimpleClassOfUriToDurationNullable( + (json['value'] as Map).map( + (k, e) => MapEntry( + Uri.parse(k), e == null ? null : Duration(microseconds: e as int)), + ), + ); +} + +Map _$SimpleClassOfUriToDurationNullableToJson( + SimpleClassOfUriToDurationNullable instance) => + { + 'value': instance.value + .map((k, e) => MapEntry(k.toString(), e?.inMicroseconds)), + }; + +SimpleClassNullableOfUriToDurationNullable + _$SimpleClassNullableOfUriToDurationNullableFromJson( + Map json) { + return SimpleClassNullableOfUriToDurationNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry( + Uri.parse(k), e == null ? null : Duration(microseconds: e as int)), + ), + ); +} + +Map _$SimpleClassNullableOfUriToDurationNullableToJson( + SimpleClassNullableOfUriToDurationNullable instance) => + { + 'value': instance.value + ?.map((k, e) => MapEntry(k.toString(), e?.inMicroseconds)), + }; + +SimpleClassOfBigIntToDynamic _$SimpleClassOfBigIntToDynamicFromJson( + Map json) { + return SimpleClassOfBigIntToDynamic( + (json['value'] as Map).map( + (k, e) => MapEntry(BigInt.parse(k), e), + ), + ); +} + +Map _$SimpleClassOfBigIntToDynamicToJson( + SimpleClassOfBigIntToDynamic instance) => + { + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassNullableOfBigIntToDynamic + _$SimpleClassNullableOfBigIntToDynamicFromJson(Map json) { + return SimpleClassNullableOfBigIntToDynamic( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(BigInt.parse(k), e), + ), + ); +} + +Map _$SimpleClassNullableOfBigIntToDynamicToJson( + SimpleClassNullableOfBigIntToDynamic instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassOfDateTimeToDynamic _$SimpleClassOfDateTimeToDynamicFromJson( + Map json) { + return SimpleClassOfDateTimeToDynamic( + (json['value'] as Map).map( + (k, e) => MapEntry(DateTime.parse(k), e), + ), + ); +} + +Map _$SimpleClassOfDateTimeToDynamicToJson( + SimpleClassOfDateTimeToDynamic instance) => + { + 'value': instance.value.map((k, e) => MapEntry(k.toIso8601String(), e)), + }; + +SimpleClassNullableOfDateTimeToDynamic + _$SimpleClassNullableOfDateTimeToDynamicFromJson( + Map json) { + return SimpleClassNullableOfDateTimeToDynamic( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(DateTime.parse(k), e), + ), + ); +} + +Map _$SimpleClassNullableOfDateTimeToDynamicToJson( + SimpleClassNullableOfDateTimeToDynamic instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k.toIso8601String(), e)), + }; + +SimpleClassOfDynamicToDynamic _$SimpleClassOfDynamicToDynamicFromJson( + Map json) { + return SimpleClassOfDynamicToDynamic( + json['value'] as Map, + ); +} + +Map _$SimpleClassOfDynamicToDynamicToJson( + SimpleClassOfDynamicToDynamic instance) => + { + 'value': instance.value, + }; + +SimpleClassNullableOfDynamicToDynamic + _$SimpleClassNullableOfDynamicToDynamicFromJson(Map json) { + return SimpleClassNullableOfDynamicToDynamic( + json['value'] as Map?, + ); +} + +Map _$SimpleClassNullableOfDynamicToDynamicToJson( + SimpleClassNullableOfDynamicToDynamic instance) => + { + 'value': instance.value, + }; + +SimpleClassOfEnumTypeToDynamic _$SimpleClassOfEnumTypeToDynamicFromJson( + Map json) { + return SimpleClassOfEnumTypeToDynamic( + (json['value'] as Map).map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e), + ), + ); +} + +Map _$SimpleClassOfEnumTypeToDynamicToJson( + SimpleClassOfEnumTypeToDynamic instance) => + { + 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), + }; + +SimpleClassNullableOfEnumTypeToDynamic + _$SimpleClassNullableOfEnumTypeToDynamicFromJson( + Map json) { + return SimpleClassNullableOfEnumTypeToDynamic( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e), + ), + ); +} + +Map _$SimpleClassNullableOfEnumTypeToDynamicToJson( + SimpleClassNullableOfEnumTypeToDynamic instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), + }; + +SimpleClassOfIntToDynamic _$SimpleClassOfIntToDynamicFromJson( + Map json) { + return SimpleClassOfIntToDynamic( + (json['value'] as Map).map( + (k, e) => MapEntry(int.parse(k), e), + ), + ); +} + +Map _$SimpleClassOfIntToDynamicToJson( + SimpleClassOfIntToDynamic instance) => + { + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassNullableOfIntToDynamic _$SimpleClassNullableOfIntToDynamicFromJson( + Map json) { + return SimpleClassNullableOfIntToDynamic( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(int.parse(k), e), + ), + ); +} + +Map _$SimpleClassNullableOfIntToDynamicToJson( + SimpleClassNullableOfIntToDynamic instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassOfObjectToDynamic _$SimpleClassOfObjectToDynamicFromJson( + Map json) { + return SimpleClassOfObjectToDynamic( + json['value'] as Map, + ); +} + +Map _$SimpleClassOfObjectToDynamicToJson( + SimpleClassOfObjectToDynamic instance) => + { + 'value': instance.value, + }; + +SimpleClassNullableOfObjectToDynamic + _$SimpleClassNullableOfObjectToDynamicFromJson(Map json) { + return SimpleClassNullableOfObjectToDynamic( + json['value'] as Map?, + ); +} + +Map _$SimpleClassNullableOfObjectToDynamicToJson( + SimpleClassNullableOfObjectToDynamic instance) => + { + 'value': instance.value, + }; + +SimpleClassOfStringToDynamic _$SimpleClassOfStringToDynamicFromJson( + Map json) { + return SimpleClassOfStringToDynamic( + json['value'] as Map, + ); +} + +Map _$SimpleClassOfStringToDynamicToJson( + SimpleClassOfStringToDynamic instance) => + { + 'value': instance.value, + }; + +SimpleClassNullableOfStringToDynamic + _$SimpleClassNullableOfStringToDynamicFromJson(Map json) { + return SimpleClassNullableOfStringToDynamic( + json['value'] as Map?, + ); +} + +Map _$SimpleClassNullableOfStringToDynamicToJson( + SimpleClassNullableOfStringToDynamic instance) => + { + 'value': instance.value, + }; + +SimpleClassOfUriToDynamic _$SimpleClassOfUriToDynamicFromJson( + Map json) { + return SimpleClassOfUriToDynamic( + (json['value'] as Map).map( + (k, e) => MapEntry(Uri.parse(k), e), + ), + ); +} + +Map _$SimpleClassOfUriToDynamicToJson( + SimpleClassOfUriToDynamic instance) => + { + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassNullableOfUriToDynamic _$SimpleClassNullableOfUriToDynamicFromJson( + Map json) { + return SimpleClassNullableOfUriToDynamic( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(Uri.parse(k), e), + ), + ); +} + +Map _$SimpleClassNullableOfUriToDynamicToJson( + SimpleClassNullableOfUriToDynamic instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassOfBigIntToEnumType _$SimpleClassOfBigIntToEnumTypeFromJson( + Map json) { + return SimpleClassOfBigIntToEnumType( + (json['value'] as Map).map( + (k, e) => MapEntry(BigInt.parse(k), _$enumDecode(_$EnumTypeEnumMap, e)), + ), + ); +} + +Map _$SimpleClassOfBigIntToEnumTypeToJson( + SimpleClassOfBigIntToEnumType instance) => + { + 'value': instance.value + .map((k, e) => MapEntry(k.toString(), _$EnumTypeEnumMap[e])), + }; + +SimpleClassNullableOfBigIntToEnumType + _$SimpleClassNullableOfBigIntToEnumTypeFromJson(Map json) { + return SimpleClassNullableOfBigIntToEnumType( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(BigInt.parse(k), _$enumDecode(_$EnumTypeEnumMap, e)), + ), + ); +} + +Map _$SimpleClassNullableOfBigIntToEnumTypeToJson( + SimpleClassNullableOfBigIntToEnumType instance) => + { + 'value': instance.value + ?.map((k, e) => MapEntry(k.toString(), _$EnumTypeEnumMap[e])), + }; + +SimpleClassOfDateTimeToEnumType _$SimpleClassOfDateTimeToEnumTypeFromJson( + Map json) { + return SimpleClassOfDateTimeToEnumType( + (json['value'] as Map).map( + (k, e) => MapEntry(DateTime.parse(k), _$enumDecode(_$EnumTypeEnumMap, e)), + ), + ); +} + +Map _$SimpleClassOfDateTimeToEnumTypeToJson( + SimpleClassOfDateTimeToEnumType instance) => + { + 'value': instance.value + .map((k, e) => MapEntry(k.toIso8601String(), _$EnumTypeEnumMap[e])), + }; + +SimpleClassNullableOfDateTimeToEnumType + _$SimpleClassNullableOfDateTimeToEnumTypeFromJson( + Map json) { + return SimpleClassNullableOfDateTimeToEnumType( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(DateTime.parse(k), _$enumDecode(_$EnumTypeEnumMap, e)), + ), + ); +} + +Map _$SimpleClassNullableOfDateTimeToEnumTypeToJson( + SimpleClassNullableOfDateTimeToEnumType instance) => + { + 'value': instance.value + ?.map((k, e) => MapEntry(k.toIso8601String(), _$EnumTypeEnumMap[e])), + }; + +SimpleClassOfDynamicToEnumType _$SimpleClassOfDynamicToEnumTypeFromJson( + Map json) { + return SimpleClassOfDynamicToEnumType( + (json['value'] as Map).map( + (k, e) => MapEntry(k, _$enumDecode(_$EnumTypeEnumMap, e)), + ), + ); +} + +Map _$SimpleClassOfDynamicToEnumTypeToJson( + SimpleClassOfDynamicToEnumType instance) => + { + 'value': instance.value.map((k, e) => MapEntry(k, _$EnumTypeEnumMap[e])), + }; + +SimpleClassNullableOfDynamicToEnumType + _$SimpleClassNullableOfDynamicToEnumTypeFromJson( + Map json) { + return SimpleClassNullableOfDynamicToEnumType( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, _$enumDecode(_$EnumTypeEnumMap, e)), + ), + ); +} + +Map _$SimpleClassNullableOfDynamicToEnumTypeToJson( + SimpleClassNullableOfDynamicToEnumType instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k, _$EnumTypeEnumMap[e])), + }; + +SimpleClassOfEnumTypeToEnumType _$SimpleClassOfEnumTypeToEnumTypeFromJson( + Map json) { + return SimpleClassOfEnumTypeToEnumType( + (json['value'] as Map).map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), + _$enumDecode(_$EnumTypeEnumMap, e)), + ), + ); +} + +Map _$SimpleClassOfEnumTypeToEnumTypeToJson( + SimpleClassOfEnumTypeToEnumType instance) => + { + 'value': instance.value + .map((k, e) => MapEntry(_$EnumTypeEnumMap[k], _$EnumTypeEnumMap[e])), + }; + +SimpleClassNullableOfEnumTypeToEnumType + _$SimpleClassNullableOfEnumTypeToEnumTypeFromJson( + Map json) { + return SimpleClassNullableOfEnumTypeToEnumType( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), + _$enumDecode(_$EnumTypeEnumMap, e)), + ), + ); +} + +Map _$SimpleClassNullableOfEnumTypeToEnumTypeToJson( + SimpleClassNullableOfEnumTypeToEnumType instance) => + { + 'value': instance.value + ?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], _$EnumTypeEnumMap[e])), + }; + +SimpleClassOfIntToEnumType _$SimpleClassOfIntToEnumTypeFromJson( + Map json) { + return SimpleClassOfIntToEnumType( + (json['value'] as Map).map( + (k, e) => MapEntry(int.parse(k), _$enumDecode(_$EnumTypeEnumMap, e)), + ), + ); +} + +Map _$SimpleClassOfIntToEnumTypeToJson( + SimpleClassOfIntToEnumType instance) => + { + 'value': instance.value + .map((k, e) => MapEntry(k.toString(), _$EnumTypeEnumMap[e])), + }; + +SimpleClassNullableOfIntToEnumType _$SimpleClassNullableOfIntToEnumTypeFromJson( + Map json) { + return SimpleClassNullableOfIntToEnumType( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(int.parse(k), _$enumDecode(_$EnumTypeEnumMap, e)), + ), + ); +} + +Map _$SimpleClassNullableOfIntToEnumTypeToJson( + SimpleClassNullableOfIntToEnumType instance) => + { + 'value': instance.value + ?.map((k, e) => MapEntry(k.toString(), _$EnumTypeEnumMap[e])), + }; + +SimpleClassOfObjectToEnumType _$SimpleClassOfObjectToEnumTypeFromJson( + Map json) { + return SimpleClassOfObjectToEnumType( + (json['value'] as Map).map( + (k, e) => MapEntry(k, _$enumDecode(_$EnumTypeEnumMap, e)), + ), + ); +} + +Map _$SimpleClassOfObjectToEnumTypeToJson( + SimpleClassOfObjectToEnumType instance) => + { + 'value': instance.value.map((k, e) => MapEntry(k, _$EnumTypeEnumMap[e])), + }; + +SimpleClassNullableOfObjectToEnumType + _$SimpleClassNullableOfObjectToEnumTypeFromJson(Map json) { + return SimpleClassNullableOfObjectToEnumType( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, _$enumDecode(_$EnumTypeEnumMap, e)), + ), + ); +} + +Map _$SimpleClassNullableOfObjectToEnumTypeToJson( + SimpleClassNullableOfObjectToEnumType instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k, _$EnumTypeEnumMap[e])), + }; + +SimpleClassOfStringToEnumType _$SimpleClassOfStringToEnumTypeFromJson( + Map json) { + return SimpleClassOfStringToEnumType( + (json['value'] as Map).map( + (k, e) => MapEntry(k, _$enumDecode(_$EnumTypeEnumMap, e)), + ), + ); +} + +Map _$SimpleClassOfStringToEnumTypeToJson( + SimpleClassOfStringToEnumType instance) => + { + 'value': instance.value.map((k, e) => MapEntry(k, _$EnumTypeEnumMap[e])), + }; + +SimpleClassNullableOfStringToEnumType + _$SimpleClassNullableOfStringToEnumTypeFromJson(Map json) { + return SimpleClassNullableOfStringToEnumType( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, _$enumDecode(_$EnumTypeEnumMap, e)), + ), + ); +} + +Map _$SimpleClassNullableOfStringToEnumTypeToJson( + SimpleClassNullableOfStringToEnumType instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k, _$EnumTypeEnumMap[e])), + }; + +SimpleClassOfUriToEnumType _$SimpleClassOfUriToEnumTypeFromJson( + Map json) { + return SimpleClassOfUriToEnumType( + (json['value'] as Map).map( + (k, e) => MapEntry(Uri.parse(k), _$enumDecode(_$EnumTypeEnumMap, e)), + ), + ); +} + +Map _$SimpleClassOfUriToEnumTypeToJson( + SimpleClassOfUriToEnumType instance) => + { + 'value': instance.value + .map((k, e) => MapEntry(k.toString(), _$EnumTypeEnumMap[e])), + }; + +SimpleClassNullableOfUriToEnumType _$SimpleClassNullableOfUriToEnumTypeFromJson( + Map json) { + return SimpleClassNullableOfUriToEnumType( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(Uri.parse(k), _$enumDecode(_$EnumTypeEnumMap, e)), + ), + ); +} + +Map _$SimpleClassNullableOfUriToEnumTypeToJson( + SimpleClassNullableOfUriToEnumType instance) => + { + 'value': instance.value + ?.map((k, e) => MapEntry(k.toString(), _$EnumTypeEnumMap[e])), + }; + +SimpleClassOfBigIntToEnumTypeNullable + _$SimpleClassOfBigIntToEnumTypeNullableFromJson(Map json) { + return SimpleClassOfBigIntToEnumTypeNullable( + (json['value'] as Map).map( + (k, e) => + MapEntry(BigInt.parse(k), _$enumDecodeNullable(_$EnumTypeEnumMap, e)), + ), + ); +} + +Map _$SimpleClassOfBigIntToEnumTypeNullableToJson( + SimpleClassOfBigIntToEnumTypeNullable instance) => + { + 'value': instance.value + .map((k, e) => MapEntry(k.toString(), _$EnumTypeEnumMap[e])), + }; + +K? _$enumDecodeNullable( + Map enumValues, + dynamic source, { + K? unknownValue, +}) { + if (source == null) { + return null; + } + return _$enumDecode(enumValues, source, unknownValue: unknownValue); +} + +SimpleClassNullableOfBigIntToEnumTypeNullable + _$SimpleClassNullableOfBigIntToEnumTypeNullableFromJson( + Map json) { + return SimpleClassNullableOfBigIntToEnumTypeNullable( + (json['value'] as Map?)?.map( + (k, e) => + MapEntry(BigInt.parse(k), _$enumDecodeNullable(_$EnumTypeEnumMap, e)), + ), + ); +} + +Map _$SimpleClassNullableOfBigIntToEnumTypeNullableToJson( + SimpleClassNullableOfBigIntToEnumTypeNullable instance) => + { + 'value': instance.value + ?.map((k, e) => MapEntry(k.toString(), _$EnumTypeEnumMap[e])), + }; + +SimpleClassOfDateTimeToEnumTypeNullable + _$SimpleClassOfDateTimeToEnumTypeNullableFromJson( + Map json) { + return SimpleClassOfDateTimeToEnumTypeNullable( + (json['value'] as Map).map( + (k, e) => MapEntry( + DateTime.parse(k), _$enumDecodeNullable(_$EnumTypeEnumMap, e)), + ), + ); +} + +Map _$SimpleClassOfDateTimeToEnumTypeNullableToJson( + SimpleClassOfDateTimeToEnumTypeNullable instance) => + { + 'value': instance.value + .map((k, e) => MapEntry(k.toIso8601String(), _$EnumTypeEnumMap[e])), + }; + +SimpleClassNullableOfDateTimeToEnumTypeNullable + _$SimpleClassNullableOfDateTimeToEnumTypeNullableFromJson( + Map json) { + return SimpleClassNullableOfDateTimeToEnumTypeNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry( + DateTime.parse(k), _$enumDecodeNullable(_$EnumTypeEnumMap, e)), + ), + ); +} + +Map _$SimpleClassNullableOfDateTimeToEnumTypeNullableToJson( + SimpleClassNullableOfDateTimeToEnumTypeNullable instance) => + { + 'value': instance.value + ?.map((k, e) => MapEntry(k.toIso8601String(), _$EnumTypeEnumMap[e])), + }; + +SimpleClassOfDynamicToEnumTypeNullable + _$SimpleClassOfDynamicToEnumTypeNullableFromJson( + Map json) { + return SimpleClassOfDynamicToEnumTypeNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(k, _$enumDecodeNullable(_$EnumTypeEnumMap, e)), + ), + ); +} + +Map _$SimpleClassOfDynamicToEnumTypeNullableToJson( + SimpleClassOfDynamicToEnumTypeNullable instance) => + { + 'value': instance.value.map((k, e) => MapEntry(k, _$EnumTypeEnumMap[e])), + }; + +SimpleClassNullableOfDynamicToEnumTypeNullable + _$SimpleClassNullableOfDynamicToEnumTypeNullableFromJson( + Map json) { + return SimpleClassNullableOfDynamicToEnumTypeNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, _$enumDecodeNullable(_$EnumTypeEnumMap, e)), + ), + ); +} + +Map _$SimpleClassNullableOfDynamicToEnumTypeNullableToJson( + SimpleClassNullableOfDynamicToEnumTypeNullable instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k, _$EnumTypeEnumMap[e])), + }; + +SimpleClassOfEnumTypeToEnumTypeNullable + _$SimpleClassOfEnumTypeToEnumTypeNullableFromJson( + Map json) { + return SimpleClassOfEnumTypeToEnumTypeNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), + _$enumDecodeNullable(_$EnumTypeEnumMap, e)), + ), + ); +} + +Map _$SimpleClassOfEnumTypeToEnumTypeNullableToJson( + SimpleClassOfEnumTypeToEnumTypeNullable instance) => + { + 'value': instance.value + .map((k, e) => MapEntry(_$EnumTypeEnumMap[k], _$EnumTypeEnumMap[e])), + }; + +SimpleClassNullableOfEnumTypeToEnumTypeNullable + _$SimpleClassNullableOfEnumTypeToEnumTypeNullableFromJson( + Map json) { + return SimpleClassNullableOfEnumTypeToEnumTypeNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), + _$enumDecodeNullable(_$EnumTypeEnumMap, e)), + ), + ); +} + +Map _$SimpleClassNullableOfEnumTypeToEnumTypeNullableToJson( + SimpleClassNullableOfEnumTypeToEnumTypeNullable instance) => + { + 'value': instance.value + ?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], _$EnumTypeEnumMap[e])), + }; + +SimpleClassOfIntToEnumTypeNullable _$SimpleClassOfIntToEnumTypeNullableFromJson( + Map json) { + return SimpleClassOfIntToEnumTypeNullable( + (json['value'] as Map).map( + (k, e) => + MapEntry(int.parse(k), _$enumDecodeNullable(_$EnumTypeEnumMap, e)), + ), + ); +} + +Map _$SimpleClassOfIntToEnumTypeNullableToJson( + SimpleClassOfIntToEnumTypeNullable instance) => + { + 'value': instance.value + .map((k, e) => MapEntry(k.toString(), _$EnumTypeEnumMap[e])), + }; + +SimpleClassNullableOfIntToEnumTypeNullable + _$SimpleClassNullableOfIntToEnumTypeNullableFromJson( + Map json) { + return SimpleClassNullableOfIntToEnumTypeNullable( + (json['value'] as Map?)?.map( + (k, e) => + MapEntry(int.parse(k), _$enumDecodeNullable(_$EnumTypeEnumMap, e)), + ), + ); +} + +Map _$SimpleClassNullableOfIntToEnumTypeNullableToJson( + SimpleClassNullableOfIntToEnumTypeNullable instance) => + { + 'value': instance.value + ?.map((k, e) => MapEntry(k.toString(), _$EnumTypeEnumMap[e])), + }; + +SimpleClassOfObjectToEnumTypeNullable + _$SimpleClassOfObjectToEnumTypeNullableFromJson(Map json) { + return SimpleClassOfObjectToEnumTypeNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(k, _$enumDecodeNullable(_$EnumTypeEnumMap, e)), + ), + ); +} + +Map _$SimpleClassOfObjectToEnumTypeNullableToJson( + SimpleClassOfObjectToEnumTypeNullable instance) => + { + 'value': instance.value.map((k, e) => MapEntry(k, _$EnumTypeEnumMap[e])), + }; + +SimpleClassNullableOfObjectToEnumTypeNullable + _$SimpleClassNullableOfObjectToEnumTypeNullableFromJson( + Map json) { + return SimpleClassNullableOfObjectToEnumTypeNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, _$enumDecodeNullable(_$EnumTypeEnumMap, e)), + ), + ); +} + +Map _$SimpleClassNullableOfObjectToEnumTypeNullableToJson( + SimpleClassNullableOfObjectToEnumTypeNullable instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k, _$EnumTypeEnumMap[e])), + }; + +SimpleClassOfStringToEnumTypeNullable + _$SimpleClassOfStringToEnumTypeNullableFromJson(Map json) { + return SimpleClassOfStringToEnumTypeNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(k, _$enumDecodeNullable(_$EnumTypeEnumMap, e)), + ), + ); +} + +Map _$SimpleClassOfStringToEnumTypeNullableToJson( + SimpleClassOfStringToEnumTypeNullable instance) => + { + 'value': instance.value.map((k, e) => MapEntry(k, _$EnumTypeEnumMap[e])), + }; + +SimpleClassNullableOfStringToEnumTypeNullable + _$SimpleClassNullableOfStringToEnumTypeNullableFromJson( + Map json) { + return SimpleClassNullableOfStringToEnumTypeNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, _$enumDecodeNullable(_$EnumTypeEnumMap, e)), + ), + ); +} + +Map _$SimpleClassNullableOfStringToEnumTypeNullableToJson( + SimpleClassNullableOfStringToEnumTypeNullable instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k, _$EnumTypeEnumMap[e])), + }; + +SimpleClassOfUriToEnumTypeNullable _$SimpleClassOfUriToEnumTypeNullableFromJson( + Map json) { + return SimpleClassOfUriToEnumTypeNullable( + (json['value'] as Map).map( + (k, e) => + MapEntry(Uri.parse(k), _$enumDecodeNullable(_$EnumTypeEnumMap, e)), + ), + ); +} + +Map _$SimpleClassOfUriToEnumTypeNullableToJson( + SimpleClassOfUriToEnumTypeNullable instance) => + { + 'value': instance.value + .map((k, e) => MapEntry(k.toString(), _$EnumTypeEnumMap[e])), + }; + +SimpleClassNullableOfUriToEnumTypeNullable + _$SimpleClassNullableOfUriToEnumTypeNullableFromJson( + Map json) { + return SimpleClassNullableOfUriToEnumTypeNullable( + (json['value'] as Map?)?.map( + (k, e) => + MapEntry(Uri.parse(k), _$enumDecodeNullable(_$EnumTypeEnumMap, e)), + ), + ); +} + +Map _$SimpleClassNullableOfUriToEnumTypeNullableToJson( + SimpleClassNullableOfUriToEnumTypeNullable instance) => + { + 'value': instance.value + ?.map((k, e) => MapEntry(k.toString(), _$EnumTypeEnumMap[e])), + }; + +SimpleClassOfBigIntToInt _$SimpleClassOfBigIntToIntFromJson( + Map json) { + return SimpleClassOfBigIntToInt( + (json['value'] as Map).map( + (k, e) => MapEntry(BigInt.parse(k), e as int), + ), + ); +} + +Map _$SimpleClassOfBigIntToIntToJson( + SimpleClassOfBigIntToInt instance) => + { + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassNullableOfBigIntToInt _$SimpleClassNullableOfBigIntToIntFromJson( + Map json) { + return SimpleClassNullableOfBigIntToInt( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(BigInt.parse(k), e as int), + ), + ); +} + +Map _$SimpleClassNullableOfBigIntToIntToJson( + SimpleClassNullableOfBigIntToInt instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassOfDateTimeToInt _$SimpleClassOfDateTimeToIntFromJson( + Map json) { + return SimpleClassOfDateTimeToInt( + (json['value'] as Map).map( + (k, e) => MapEntry(DateTime.parse(k), e as int), + ), + ); +} + +Map _$SimpleClassOfDateTimeToIntToJson( + SimpleClassOfDateTimeToInt instance) => + { + 'value': instance.value.map((k, e) => MapEntry(k.toIso8601String(), e)), + }; + +SimpleClassNullableOfDateTimeToInt _$SimpleClassNullableOfDateTimeToIntFromJson( + Map json) { + return SimpleClassNullableOfDateTimeToInt( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(DateTime.parse(k), e as int), + ), + ); +} + +Map _$SimpleClassNullableOfDateTimeToIntToJson( + SimpleClassNullableOfDateTimeToInt instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k.toIso8601String(), e)), + }; + +SimpleClassOfDynamicToInt _$SimpleClassOfDynamicToIntFromJson( + Map json) { + return SimpleClassOfDynamicToInt( + Map.from(json['value'] as Map), + ); +} + +Map _$SimpleClassOfDynamicToIntToJson( + SimpleClassOfDynamicToInt instance) => + { + 'value': instance.value, + }; + +SimpleClassNullableOfDynamicToInt _$SimpleClassNullableOfDynamicToIntFromJson( + Map json) { + return SimpleClassNullableOfDynamicToInt( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e as int), + ), + ); +} + +Map _$SimpleClassNullableOfDynamicToIntToJson( + SimpleClassNullableOfDynamicToInt instance) => + { + 'value': instance.value, + }; + +SimpleClassOfEnumTypeToInt _$SimpleClassOfEnumTypeToIntFromJson( + Map json) { + return SimpleClassOfEnumTypeToInt( + (json['value'] as Map).map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as int), + ), + ); +} + +Map _$SimpleClassOfEnumTypeToIntToJson( + SimpleClassOfEnumTypeToInt instance) => + { + 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), + }; + +SimpleClassNullableOfEnumTypeToInt _$SimpleClassNullableOfEnumTypeToIntFromJson( + Map json) { + return SimpleClassNullableOfEnumTypeToInt( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as int), + ), + ); +} + +Map _$SimpleClassNullableOfEnumTypeToIntToJson( + SimpleClassNullableOfEnumTypeToInt instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), + }; + +SimpleClassOfIntToInt _$SimpleClassOfIntToIntFromJson( + Map json) { + return SimpleClassOfIntToInt( + (json['value'] as Map).map( + (k, e) => MapEntry(int.parse(k), e as int), + ), + ); +} + +Map _$SimpleClassOfIntToIntToJson( + SimpleClassOfIntToInt instance) => + { + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassNullableOfIntToInt _$SimpleClassNullableOfIntToIntFromJson( + Map json) { + return SimpleClassNullableOfIntToInt( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(int.parse(k), e as int), + ), + ); +} + +Map _$SimpleClassNullableOfIntToIntToJson( + SimpleClassNullableOfIntToInt instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassOfObjectToInt _$SimpleClassOfObjectToIntFromJson( + Map json) { + return SimpleClassOfObjectToInt( + Map.from(json['value'] as Map), + ); +} + +Map _$SimpleClassOfObjectToIntToJson( + SimpleClassOfObjectToInt instance) => + { + 'value': instance.value, + }; + +SimpleClassNullableOfObjectToInt _$SimpleClassNullableOfObjectToIntFromJson( + Map json) { + return SimpleClassNullableOfObjectToInt( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e as int), + ), + ); +} + +Map _$SimpleClassNullableOfObjectToIntToJson( + SimpleClassNullableOfObjectToInt instance) => + { + 'value': instance.value, + }; + +SimpleClassOfStringToInt _$SimpleClassOfStringToIntFromJson( + Map json) { + return SimpleClassOfStringToInt( + Map.from(json['value'] as Map), + ); +} + +Map _$SimpleClassOfStringToIntToJson( + SimpleClassOfStringToInt instance) => + { + 'value': instance.value, + }; + +SimpleClassNullableOfStringToInt _$SimpleClassNullableOfStringToIntFromJson( + Map json) { + return SimpleClassNullableOfStringToInt( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e as int), + ), + ); +} + +Map _$SimpleClassNullableOfStringToIntToJson( + SimpleClassNullableOfStringToInt instance) => + { + 'value': instance.value, + }; + +SimpleClassOfUriToInt _$SimpleClassOfUriToIntFromJson( + Map json) { + return SimpleClassOfUriToInt( + (json['value'] as Map).map( + (k, e) => MapEntry(Uri.parse(k), e as int), + ), + ); +} + +Map _$SimpleClassOfUriToIntToJson( + SimpleClassOfUriToInt instance) => + { + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassNullableOfUriToInt _$SimpleClassNullableOfUriToIntFromJson( + Map json) { + return SimpleClassNullableOfUriToInt( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(Uri.parse(k), e as int), + ), + ); +} + +Map _$SimpleClassNullableOfUriToIntToJson( + SimpleClassNullableOfUriToInt instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassOfBigIntToIntNullable _$SimpleClassOfBigIntToIntNullableFromJson( + Map json) { + return SimpleClassOfBigIntToIntNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(BigInt.parse(k), e as int?), + ), + ); +} + +Map _$SimpleClassOfBigIntToIntNullableToJson( + SimpleClassOfBigIntToIntNullable instance) => + { + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassNullableOfBigIntToIntNullable + _$SimpleClassNullableOfBigIntToIntNullableFromJson( + Map json) { + return SimpleClassNullableOfBigIntToIntNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(BigInt.parse(k), e as int?), + ), + ); +} + +Map _$SimpleClassNullableOfBigIntToIntNullableToJson( + SimpleClassNullableOfBigIntToIntNullable instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassOfDateTimeToIntNullable _$SimpleClassOfDateTimeToIntNullableFromJson( + Map json) { + return SimpleClassOfDateTimeToIntNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(DateTime.parse(k), e as int?), + ), + ); +} + +Map _$SimpleClassOfDateTimeToIntNullableToJson( + SimpleClassOfDateTimeToIntNullable instance) => + { + 'value': instance.value.map((k, e) => MapEntry(k.toIso8601String(), e)), + }; + +SimpleClassNullableOfDateTimeToIntNullable + _$SimpleClassNullableOfDateTimeToIntNullableFromJson( + Map json) { + return SimpleClassNullableOfDateTimeToIntNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(DateTime.parse(k), e as int?), + ), + ); +} + +Map _$SimpleClassNullableOfDateTimeToIntNullableToJson( + SimpleClassNullableOfDateTimeToIntNullable instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k.toIso8601String(), e)), + }; + +SimpleClassOfDynamicToIntNullable _$SimpleClassOfDynamicToIntNullableFromJson( + Map json) { + return SimpleClassOfDynamicToIntNullable( + Map.from(json['value'] as Map), + ); +} + +Map _$SimpleClassOfDynamicToIntNullableToJson( + SimpleClassOfDynamicToIntNullable instance) => + { + 'value': instance.value, + }; + +SimpleClassNullableOfDynamicToIntNullable + _$SimpleClassNullableOfDynamicToIntNullableFromJson( + Map json) { + return SimpleClassNullableOfDynamicToIntNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e as int?), + ), + ); +} + +Map _$SimpleClassNullableOfDynamicToIntNullableToJson( + SimpleClassNullableOfDynamicToIntNullable instance) => + { + 'value': instance.value, + }; + +SimpleClassOfEnumTypeToIntNullable _$SimpleClassOfEnumTypeToIntNullableFromJson( + Map json) { + return SimpleClassOfEnumTypeToIntNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as int?), + ), + ); +} + +Map _$SimpleClassOfEnumTypeToIntNullableToJson( + SimpleClassOfEnumTypeToIntNullable instance) => + { + 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), + }; + +SimpleClassNullableOfEnumTypeToIntNullable + _$SimpleClassNullableOfEnumTypeToIntNullableFromJson( + Map json) { + return SimpleClassNullableOfEnumTypeToIntNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as int?), + ), + ); +} + +Map _$SimpleClassNullableOfEnumTypeToIntNullableToJson( + SimpleClassNullableOfEnumTypeToIntNullable instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), + }; + +SimpleClassOfIntToIntNullable _$SimpleClassOfIntToIntNullableFromJson( + Map json) { + return SimpleClassOfIntToIntNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(int.parse(k), e as int?), + ), + ); +} + +Map _$SimpleClassOfIntToIntNullableToJson( + SimpleClassOfIntToIntNullable instance) => + { + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassNullableOfIntToIntNullable + _$SimpleClassNullableOfIntToIntNullableFromJson(Map json) { + return SimpleClassNullableOfIntToIntNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(int.parse(k), e as int?), + ), + ); +} + +Map _$SimpleClassNullableOfIntToIntNullableToJson( + SimpleClassNullableOfIntToIntNullable instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassOfObjectToIntNullable _$SimpleClassOfObjectToIntNullableFromJson( + Map json) { + return SimpleClassOfObjectToIntNullable( + Map.from(json['value'] as Map), + ); +} + +Map _$SimpleClassOfObjectToIntNullableToJson( + SimpleClassOfObjectToIntNullable instance) => + { + 'value': instance.value, + }; + +SimpleClassNullableOfObjectToIntNullable + _$SimpleClassNullableOfObjectToIntNullableFromJson( + Map json) { + return SimpleClassNullableOfObjectToIntNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e as int?), + ), + ); +} + +Map _$SimpleClassNullableOfObjectToIntNullableToJson( + SimpleClassNullableOfObjectToIntNullable instance) => + { + 'value': instance.value, + }; + +SimpleClassOfStringToIntNullable _$SimpleClassOfStringToIntNullableFromJson( + Map json) { + return SimpleClassOfStringToIntNullable( + Map.from(json['value'] as Map), + ); +} + +Map _$SimpleClassOfStringToIntNullableToJson( + SimpleClassOfStringToIntNullable instance) => + { + 'value': instance.value, + }; + +SimpleClassNullableOfStringToIntNullable + _$SimpleClassNullableOfStringToIntNullableFromJson( + Map json) { + return SimpleClassNullableOfStringToIntNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e as int?), + ), + ); +} + +Map _$SimpleClassNullableOfStringToIntNullableToJson( + SimpleClassNullableOfStringToIntNullable instance) => + { + 'value': instance.value, + }; + +SimpleClassOfUriToIntNullable _$SimpleClassOfUriToIntNullableFromJson( + Map json) { + return SimpleClassOfUriToIntNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(Uri.parse(k), e as int?), + ), + ); +} + +Map _$SimpleClassOfUriToIntNullableToJson( + SimpleClassOfUriToIntNullable instance) => + { + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassNullableOfUriToIntNullable + _$SimpleClassNullableOfUriToIntNullableFromJson(Map json) { + return SimpleClassNullableOfUriToIntNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(Uri.parse(k), e as int?), + ), + ); +} + +Map _$SimpleClassNullableOfUriToIntNullableToJson( + SimpleClassNullableOfUriToIntNullable instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassOfBigIntToNum _$SimpleClassOfBigIntToNumFromJson( + Map json) { + return SimpleClassOfBigIntToNum( + (json['value'] as Map).map( + (k, e) => MapEntry(BigInt.parse(k), e as num), + ), + ); +} + +Map _$SimpleClassOfBigIntToNumToJson( + SimpleClassOfBigIntToNum instance) => + { + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassNullableOfBigIntToNum _$SimpleClassNullableOfBigIntToNumFromJson( + Map json) { + return SimpleClassNullableOfBigIntToNum( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(BigInt.parse(k), e as num), + ), + ); +} + +Map _$SimpleClassNullableOfBigIntToNumToJson( + SimpleClassNullableOfBigIntToNum instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassOfDateTimeToNum _$SimpleClassOfDateTimeToNumFromJson( + Map json) { + return SimpleClassOfDateTimeToNum( + (json['value'] as Map).map( + (k, e) => MapEntry(DateTime.parse(k), e as num), + ), + ); +} + +Map _$SimpleClassOfDateTimeToNumToJson( + SimpleClassOfDateTimeToNum instance) => + { + 'value': instance.value.map((k, e) => MapEntry(k.toIso8601String(), e)), + }; + +SimpleClassNullableOfDateTimeToNum _$SimpleClassNullableOfDateTimeToNumFromJson( + Map json) { + return SimpleClassNullableOfDateTimeToNum( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(DateTime.parse(k), e as num), + ), + ); +} + +Map _$SimpleClassNullableOfDateTimeToNumToJson( + SimpleClassNullableOfDateTimeToNum instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k.toIso8601String(), e)), + }; + +SimpleClassOfDynamicToNum _$SimpleClassOfDynamicToNumFromJson( + Map json) { + return SimpleClassOfDynamicToNum( + Map.from(json['value'] as Map), + ); +} + +Map _$SimpleClassOfDynamicToNumToJson( + SimpleClassOfDynamicToNum instance) => + { + 'value': instance.value, + }; + +SimpleClassNullableOfDynamicToNum _$SimpleClassNullableOfDynamicToNumFromJson( + Map json) { + return SimpleClassNullableOfDynamicToNum( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e as num), + ), + ); +} + +Map _$SimpleClassNullableOfDynamicToNumToJson( + SimpleClassNullableOfDynamicToNum instance) => + { + 'value': instance.value, + }; + +SimpleClassOfEnumTypeToNum _$SimpleClassOfEnumTypeToNumFromJson( + Map json) { + return SimpleClassOfEnumTypeToNum( + (json['value'] as Map).map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as num), + ), + ); +} + +Map _$SimpleClassOfEnumTypeToNumToJson( + SimpleClassOfEnumTypeToNum instance) => + { + 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), + }; + +SimpleClassNullableOfEnumTypeToNum _$SimpleClassNullableOfEnumTypeToNumFromJson( + Map json) { + return SimpleClassNullableOfEnumTypeToNum( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as num), + ), + ); +} + +Map _$SimpleClassNullableOfEnumTypeToNumToJson( + SimpleClassNullableOfEnumTypeToNum instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), + }; + +SimpleClassOfIntToNum _$SimpleClassOfIntToNumFromJson( + Map json) { + return SimpleClassOfIntToNum( + (json['value'] as Map).map( + (k, e) => MapEntry(int.parse(k), e as num), + ), + ); +} + +Map _$SimpleClassOfIntToNumToJson( + SimpleClassOfIntToNum instance) => + { + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassNullableOfIntToNum _$SimpleClassNullableOfIntToNumFromJson( + Map json) { + return SimpleClassNullableOfIntToNum( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(int.parse(k), e as num), + ), + ); +} + +Map _$SimpleClassNullableOfIntToNumToJson( + SimpleClassNullableOfIntToNum instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassOfObjectToNum _$SimpleClassOfObjectToNumFromJson( + Map json) { + return SimpleClassOfObjectToNum( + Map.from(json['value'] as Map), + ); +} + +Map _$SimpleClassOfObjectToNumToJson( + SimpleClassOfObjectToNum instance) => + { + 'value': instance.value, + }; + +SimpleClassNullableOfObjectToNum _$SimpleClassNullableOfObjectToNumFromJson( + Map json) { + return SimpleClassNullableOfObjectToNum( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e as num), + ), + ); +} + +Map _$SimpleClassNullableOfObjectToNumToJson( + SimpleClassNullableOfObjectToNum instance) => + { + 'value': instance.value, + }; + +SimpleClassOfStringToNum _$SimpleClassOfStringToNumFromJson( + Map json) { + return SimpleClassOfStringToNum( + Map.from(json['value'] as Map), + ); +} + +Map _$SimpleClassOfStringToNumToJson( + SimpleClassOfStringToNum instance) => + { + 'value': instance.value, + }; + +SimpleClassNullableOfStringToNum _$SimpleClassNullableOfStringToNumFromJson( + Map json) { + return SimpleClassNullableOfStringToNum( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e as num), + ), + ); +} + +Map _$SimpleClassNullableOfStringToNumToJson( + SimpleClassNullableOfStringToNum instance) => + { + 'value': instance.value, + }; + +SimpleClassOfUriToNum _$SimpleClassOfUriToNumFromJson( + Map json) { + return SimpleClassOfUriToNum( + (json['value'] as Map).map( + (k, e) => MapEntry(Uri.parse(k), e as num), + ), + ); +} + +Map _$SimpleClassOfUriToNumToJson( + SimpleClassOfUriToNum instance) => + { + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassNullableOfUriToNum _$SimpleClassNullableOfUriToNumFromJson( + Map json) { + return SimpleClassNullableOfUriToNum( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(Uri.parse(k), e as num), + ), + ); +} + +Map _$SimpleClassNullableOfUriToNumToJson( + SimpleClassNullableOfUriToNum instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassOfBigIntToNumNullable _$SimpleClassOfBigIntToNumNullableFromJson( + Map json) { + return SimpleClassOfBigIntToNumNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(BigInt.parse(k), e as num?), + ), + ); +} + +Map _$SimpleClassOfBigIntToNumNullableToJson( + SimpleClassOfBigIntToNumNullable instance) => + { + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassNullableOfBigIntToNumNullable + _$SimpleClassNullableOfBigIntToNumNullableFromJson( + Map json) { + return SimpleClassNullableOfBigIntToNumNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(BigInt.parse(k), e as num?), + ), + ); +} + +Map _$SimpleClassNullableOfBigIntToNumNullableToJson( + SimpleClassNullableOfBigIntToNumNullable instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassOfDateTimeToNumNullable _$SimpleClassOfDateTimeToNumNullableFromJson( + Map json) { + return SimpleClassOfDateTimeToNumNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(DateTime.parse(k), e as num?), + ), + ); +} + +Map _$SimpleClassOfDateTimeToNumNullableToJson( + SimpleClassOfDateTimeToNumNullable instance) => + { + 'value': instance.value.map((k, e) => MapEntry(k.toIso8601String(), e)), + }; + +SimpleClassNullableOfDateTimeToNumNullable + _$SimpleClassNullableOfDateTimeToNumNullableFromJson( + Map json) { + return SimpleClassNullableOfDateTimeToNumNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(DateTime.parse(k), e as num?), + ), + ); +} + +Map _$SimpleClassNullableOfDateTimeToNumNullableToJson( + SimpleClassNullableOfDateTimeToNumNullable instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k.toIso8601String(), e)), + }; + +SimpleClassOfDynamicToNumNullable _$SimpleClassOfDynamicToNumNullableFromJson( + Map json) { + return SimpleClassOfDynamicToNumNullable( + Map.from(json['value'] as Map), + ); +} + +Map _$SimpleClassOfDynamicToNumNullableToJson( + SimpleClassOfDynamicToNumNullable instance) => + { + 'value': instance.value, + }; + +SimpleClassNullableOfDynamicToNumNullable + _$SimpleClassNullableOfDynamicToNumNullableFromJson( + Map json) { + return SimpleClassNullableOfDynamicToNumNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e as num?), + ), + ); +} + +Map _$SimpleClassNullableOfDynamicToNumNullableToJson( + SimpleClassNullableOfDynamicToNumNullable instance) => + { + 'value': instance.value, + }; + +SimpleClassOfEnumTypeToNumNullable _$SimpleClassOfEnumTypeToNumNullableFromJson( + Map json) { + return SimpleClassOfEnumTypeToNumNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as num?), + ), + ); +} + +Map _$SimpleClassOfEnumTypeToNumNullableToJson( + SimpleClassOfEnumTypeToNumNullable instance) => + { + 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), + }; + +SimpleClassNullableOfEnumTypeToNumNullable + _$SimpleClassNullableOfEnumTypeToNumNullableFromJson( + Map json) { + return SimpleClassNullableOfEnumTypeToNumNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as num?), + ), + ); +} + +Map _$SimpleClassNullableOfEnumTypeToNumNullableToJson( + SimpleClassNullableOfEnumTypeToNumNullable instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), + }; + +SimpleClassOfIntToNumNullable _$SimpleClassOfIntToNumNullableFromJson( + Map json) { + return SimpleClassOfIntToNumNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(int.parse(k), e as num?), + ), + ); +} + +Map _$SimpleClassOfIntToNumNullableToJson( + SimpleClassOfIntToNumNullable instance) => + { + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassNullableOfIntToNumNullable + _$SimpleClassNullableOfIntToNumNullableFromJson(Map json) { + return SimpleClassNullableOfIntToNumNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(int.parse(k), e as num?), + ), + ); +} + +Map _$SimpleClassNullableOfIntToNumNullableToJson( + SimpleClassNullableOfIntToNumNullable instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassOfObjectToNumNullable _$SimpleClassOfObjectToNumNullableFromJson( + Map json) { + return SimpleClassOfObjectToNumNullable( + Map.from(json['value'] as Map), + ); +} + +Map _$SimpleClassOfObjectToNumNullableToJson( + SimpleClassOfObjectToNumNullable instance) => + { + 'value': instance.value, + }; + +SimpleClassNullableOfObjectToNumNullable + _$SimpleClassNullableOfObjectToNumNullableFromJson( + Map json) { + return SimpleClassNullableOfObjectToNumNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e as num?), + ), + ); +} + +Map _$SimpleClassNullableOfObjectToNumNullableToJson( + SimpleClassNullableOfObjectToNumNullable instance) => + { + 'value': instance.value, + }; + +SimpleClassOfStringToNumNullable _$SimpleClassOfStringToNumNullableFromJson( + Map json) { + return SimpleClassOfStringToNumNullable( + Map.from(json['value'] as Map), + ); +} + +Map _$SimpleClassOfStringToNumNullableToJson( + SimpleClassOfStringToNumNullable instance) => + { + 'value': instance.value, + }; + +SimpleClassNullableOfStringToNumNullable + _$SimpleClassNullableOfStringToNumNullableFromJson( + Map json) { + return SimpleClassNullableOfStringToNumNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e as num?), + ), + ); +} + +Map _$SimpleClassNullableOfStringToNumNullableToJson( + SimpleClassNullableOfStringToNumNullable instance) => + { + 'value': instance.value, + }; + +SimpleClassOfUriToNumNullable _$SimpleClassOfUriToNumNullableFromJson( + Map json) { + return SimpleClassOfUriToNumNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(Uri.parse(k), e as num?), + ), + ); +} + +Map _$SimpleClassOfUriToNumNullableToJson( + SimpleClassOfUriToNumNullable instance) => + { + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassNullableOfUriToNumNullable + _$SimpleClassNullableOfUriToNumNullableFromJson(Map json) { + return SimpleClassNullableOfUriToNumNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(Uri.parse(k), e as num?), + ), + ); +} + +Map _$SimpleClassNullableOfUriToNumNullableToJson( + SimpleClassNullableOfUriToNumNullable instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassOfBigIntToObject _$SimpleClassOfBigIntToObjectFromJson( + Map json) { + return SimpleClassOfBigIntToObject( + (json['value'] as Map).map( + (k, e) => MapEntry(BigInt.parse(k), e as Object), + ), + ); +} + +Map _$SimpleClassOfBigIntToObjectToJson( + SimpleClassOfBigIntToObject instance) => + { + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassNullableOfBigIntToObject + _$SimpleClassNullableOfBigIntToObjectFromJson(Map json) { + return SimpleClassNullableOfBigIntToObject( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(BigInt.parse(k), e as Object), + ), + ); +} + +Map _$SimpleClassNullableOfBigIntToObjectToJson( + SimpleClassNullableOfBigIntToObject instance) => + { + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassOfDateTimeToObject _$SimpleClassOfDateTimeToObjectFromJson( + Map json) { + return SimpleClassOfDateTimeToObject( + (json['value'] as Map).map( + (k, e) => MapEntry(DateTime.parse(k), e as Object), + ), + ); +} + +Map _$SimpleClassOfDateTimeToObjectToJson( + SimpleClassOfDateTimeToObject instance) => + { + 'value': instance.value.map((k, e) => MapEntry(k.toIso8601String(), e)), + }; + +SimpleClassNullableOfDateTimeToObject + _$SimpleClassNullableOfDateTimeToObjectFromJson(Map json) { + return SimpleClassNullableOfDateTimeToObject( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(DateTime.parse(k), e as Object), ), ); } -Map _$SimpleClassIntToBoolToJson( - SimpleClassIntToBool instance) => +Map _$SimpleClassNullableOfDateTimeToObjectToJson( + SimpleClassNullableOfDateTimeToObject instance) => { - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - 'nullable': instance.nullable.map((k, e) => MapEntry(k.toString(), e)), + 'value': instance.value?.map((k, e) => MapEntry(k.toIso8601String(), e)), }; -SimpleClassObjectToBool _$SimpleClassObjectToBoolFromJson( +SimpleClassOfDynamicToObject _$SimpleClassOfDynamicToObjectFromJson( Map json) { - return SimpleClassObjectToBool( - (json['value'] as Map)?.map( - (k, e) => MapEntry(k, e as bool), + return SimpleClassOfDynamicToObject( + (json['value'] as Map).map( + (k, e) => MapEntry(k, e as Object), ), - Map.from(json['nullable'] as Map), ); } -Map _$SimpleClassObjectToBoolToJson( - SimpleClassObjectToBool instance) => +Map _$SimpleClassOfDynamicToObjectToJson( + SimpleClassOfDynamicToObject instance) => { 'value': instance.value, - 'nullable': instance.nullable, }; -SimpleClassStringToBool _$SimpleClassStringToBoolFromJson( - Map json) { - return SimpleClassStringToBool( - (json['value'] as Map)?.map( - (k, e) => MapEntry(k, e as bool), +SimpleClassNullableOfDynamicToObject + _$SimpleClassNullableOfDynamicToObjectFromJson(Map json) { + return SimpleClassNullableOfDynamicToObject( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e as Object), ), - Map.from(json['nullable'] as Map), ); } -Map _$SimpleClassStringToBoolToJson( - SimpleClassStringToBool instance) => +Map _$SimpleClassNullableOfDynamicToObjectToJson( + SimpleClassNullableOfDynamicToObject instance) => { 'value': instance.value, - 'nullable': instance.nullable, }; -SimpleClassUriToBool _$SimpleClassUriToBoolFromJson(Map json) { - return SimpleClassUriToBool( - (json['value'] as Map)?.map( - (k, e) => MapEntry(Uri.parse(k), e as bool), - ), - (json['nullable'] as Map).map( - (k, e) => MapEntry(Uri.parse(k), e as bool), +SimpleClassOfEnumTypeToObject _$SimpleClassOfEnumTypeToObjectFromJson( + Map json) { + return SimpleClassOfEnumTypeToObject( + (json['value'] as Map).map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as Object), ), ); } -Map _$SimpleClassUriToBoolToJson( - SimpleClassUriToBool instance) => +Map _$SimpleClassOfEnumTypeToObjectToJson( + SimpleClassOfEnumTypeToObject instance) => { - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - 'nullable': instance.nullable.map((k, e) => MapEntry(k.toString(), e)), + 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), }; -SimpleClassBigIntToDateTime _$SimpleClassBigIntToDateTimeFromJson( - Map json) { - return SimpleClassBigIntToDateTime( - (json['value'] as Map)?.map( - (k, e) => MapEntry( - BigInt.parse(k), e == null ? null : DateTime.parse(e as String)), - ), - (json['nullable'] as Map).map( - (k, e) => MapEntry(BigInt.parse(k), DateTime.parse(e as String)), +SimpleClassNullableOfEnumTypeToObject + _$SimpleClassNullableOfEnumTypeToObjectFromJson(Map json) { + return SimpleClassNullableOfEnumTypeToObject( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as Object), ), ); } -Map _$SimpleClassBigIntToDateTimeToJson( - SimpleClassBigIntToDateTime instance) => +Map _$SimpleClassNullableOfEnumTypeToObjectToJson( + SimpleClassNullableOfEnumTypeToObject instance) => { - 'value': instance.value - ?.map((k, e) => MapEntry(k.toString(), e?.toIso8601String())), - 'nullable': instance.nullable - .map((k, e) => MapEntry(k.toString(), e.toIso8601String())), + 'value': instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), }; -SimpleClassDateTimeToDateTime _$SimpleClassDateTimeToDateTimeFromJson( +SimpleClassOfIntToObject _$SimpleClassOfIntToObjectFromJson( Map json) { - return SimpleClassDateTimeToDateTime( - (json['value'] as Map)?.map( - (k, e) => MapEntry( - DateTime.parse(k), e == null ? null : DateTime.parse(e as String)), - ), - (json['nullable'] as Map).map( - (k, e) => MapEntry(DateTime.parse(k), DateTime.parse(e as String)), + return SimpleClassOfIntToObject( + (json['value'] as Map).map( + (k, e) => MapEntry(int.parse(k), e as Object), ), ); } -Map _$SimpleClassDateTimeToDateTimeToJson( - SimpleClassDateTimeToDateTime instance) => +Map _$SimpleClassOfIntToObjectToJson( + SimpleClassOfIntToObject instance) => { - 'value': instance.value - ?.map((k, e) => MapEntry(k.toIso8601String(), e?.toIso8601String())), - 'nullable': instance.nullable - .map((k, e) => MapEntry(k.toIso8601String(), e.toIso8601String())), + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), }; -SimpleClassDynamicToDateTime _$SimpleClassDynamicToDateTimeFromJson( +SimpleClassNullableOfIntToObject _$SimpleClassNullableOfIntToObjectFromJson( Map json) { - return SimpleClassDynamicToDateTime( - (json['value'] as Map)?.map( - (k, e) => MapEntry(k, e == null ? null : DateTime.parse(e as String)), - ), - (json['nullable'] as Map).map( - (k, e) => MapEntry(k, DateTime.parse(e as String)), + return SimpleClassNullableOfIntToObject( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(int.parse(k), e as Object), ), ); } -Map _$SimpleClassDynamicToDateTimeToJson( - SimpleClassDynamicToDateTime instance) => +Map _$SimpleClassNullableOfIntToObjectToJson( + SimpleClassNullableOfIntToObject instance) => { - 'value': instance.value?.map((k, e) => MapEntry(k, e?.toIso8601String())), - 'nullable': - instance.nullable.map((k, e) => MapEntry(k, e.toIso8601String())), + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), }; -SimpleClassEnumTypeToDateTime _$SimpleClassEnumTypeToDateTimeFromJson( +SimpleClassOfObjectToObject _$SimpleClassOfObjectToObjectFromJson( Map json) { - return SimpleClassEnumTypeToDateTime( - (json['value'] as Map)?.map( - (k, e) => MapEntry(_$enumDecodeNullable(_$EnumTypeEnumMap, k), - e == null ? null : DateTime.parse(e as String)), - ), - (json['nullable'] as Map).map( - (k, e) => MapEntry( - _$enumDecode(_$EnumTypeEnumMap, k), DateTime.parse(e as String)), + return SimpleClassOfObjectToObject( + (json['value'] as Map).map( + (k, e) => MapEntry(k, e as Object), ), ); } -Map _$SimpleClassEnumTypeToDateTimeToJson( - SimpleClassEnumTypeToDateTime instance) => +Map _$SimpleClassOfObjectToObjectToJson( + SimpleClassOfObjectToObject instance) => { - 'value': instance.value - ?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e?.toIso8601String())), - 'nullable': instance.nullable - .map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e.toIso8601String())), + 'value': instance.value, }; -SimpleClassIntToDateTime _$SimpleClassIntToDateTimeFromJson( - Map json) { - return SimpleClassIntToDateTime( - (json['value'] as Map)?.map( - (k, e) => MapEntry( - int.parse(k), e == null ? null : DateTime.parse(e as String)), - ), - (json['nullable'] as Map).map( - (k, e) => MapEntry(int.parse(k), DateTime.parse(e as String)), +SimpleClassNullableOfObjectToObject + _$SimpleClassNullableOfObjectToObjectFromJson(Map json) { + return SimpleClassNullableOfObjectToObject( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e as Object), ), ); } -Map _$SimpleClassIntToDateTimeToJson( - SimpleClassIntToDateTime instance) => +Map _$SimpleClassNullableOfObjectToObjectToJson( + SimpleClassNullableOfObjectToObject instance) => { - 'value': instance.value - ?.map((k, e) => MapEntry(k.toString(), e?.toIso8601String())), - 'nullable': instance.nullable - .map((k, e) => MapEntry(k.toString(), e.toIso8601String())), + 'value': instance.value, }; -SimpleClassObjectToDateTime _$SimpleClassObjectToDateTimeFromJson( +SimpleClassOfStringToObject _$SimpleClassOfStringToObjectFromJson( Map json) { - return SimpleClassObjectToDateTime( - (json['value'] as Map)?.map( - (k, e) => MapEntry(k, e == null ? null : DateTime.parse(e as String)), - ), - (json['nullable'] as Map).map( - (k, e) => MapEntry(k, DateTime.parse(e as String)), + return SimpleClassOfStringToObject( + (json['value'] as Map).map( + (k, e) => MapEntry(k, e as Object), ), ); } -Map _$SimpleClassObjectToDateTimeToJson( - SimpleClassObjectToDateTime instance) => +Map _$SimpleClassOfStringToObjectToJson( + SimpleClassOfStringToObject instance) => { - 'value': instance.value?.map((k, e) => MapEntry(k, e?.toIso8601String())), - 'nullable': - instance.nullable.map((k, e) => MapEntry(k, e.toIso8601String())), + 'value': instance.value, }; -SimpleClassStringToDateTime _$SimpleClassStringToDateTimeFromJson( - Map json) { - return SimpleClassStringToDateTime( - (json['value'] as Map)?.map( - (k, e) => MapEntry(k, e == null ? null : DateTime.parse(e as String)), - ), - (json['nullable'] as Map).map( - (k, e) => MapEntry(k, DateTime.parse(e as String)), +SimpleClassNullableOfStringToObject + _$SimpleClassNullableOfStringToObjectFromJson(Map json) { + return SimpleClassNullableOfStringToObject( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e as Object), ), ); } -Map _$SimpleClassStringToDateTimeToJson( - SimpleClassStringToDateTime instance) => +Map _$SimpleClassNullableOfStringToObjectToJson( + SimpleClassNullableOfStringToObject instance) => { - 'value': instance.value?.map((k, e) => MapEntry(k, e?.toIso8601String())), - 'nullable': - instance.nullable.map((k, e) => MapEntry(k, e.toIso8601String())), + 'value': instance.value, }; -SimpleClassUriToDateTime _$SimpleClassUriToDateTimeFromJson( +SimpleClassOfUriToObject _$SimpleClassOfUriToObjectFromJson( Map json) { - return SimpleClassUriToDateTime( - (json['value'] as Map)?.map( - (k, e) => MapEntry( - Uri.parse(k), e == null ? null : DateTime.parse(e as String)), - ), - (json['nullable'] as Map).map( - (k, e) => MapEntry(Uri.parse(k), DateTime.parse(e as String)), + return SimpleClassOfUriToObject( + (json['value'] as Map).map( + (k, e) => MapEntry(Uri.parse(k), e as Object), ), ); } -Map _$SimpleClassUriToDateTimeToJson( - SimpleClassUriToDateTime instance) => +Map _$SimpleClassOfUriToObjectToJson( + SimpleClassOfUriToObject instance) => { - 'value': instance.value - ?.map((k, e) => MapEntry(k.toString(), e?.toIso8601String())), - 'nullable': instance.nullable - .map((k, e) => MapEntry(k.toString(), e.toIso8601String())), + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), }; -SimpleClassBigIntToDouble _$SimpleClassBigIntToDoubleFromJson( +SimpleClassNullableOfUriToObject _$SimpleClassNullableOfUriToObjectFromJson( Map json) { - return SimpleClassBigIntToDouble( - (json['value'] as Map)?.map( - (k, e) => MapEntry(BigInt.parse(k), (e as num)?.toDouble()), - ), - (json['nullable'] as Map).map( - (k, e) => MapEntry(BigInt.parse(k), (e as num).toDouble()), + return SimpleClassNullableOfUriToObject( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(Uri.parse(k), e as Object), ), ); } -Map _$SimpleClassBigIntToDoubleToJson( - SimpleClassBigIntToDouble instance) => +Map _$SimpleClassNullableOfUriToObjectToJson( + SimpleClassNullableOfUriToObject instance) => { 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - 'nullable': instance.nullable.map((k, e) => MapEntry(k.toString(), e)), }; -SimpleClassDateTimeToDouble _$SimpleClassDateTimeToDoubleFromJson( - Map json) { - return SimpleClassDateTimeToDouble( - (json['value'] as Map)?.map( - (k, e) => MapEntry(DateTime.parse(k), (e as num)?.toDouble()), - ), - (json['nullable'] as Map).map( - (k, e) => MapEntry(DateTime.parse(k), (e as num).toDouble()), +SimpleClassOfBigIntToObjectNullable + _$SimpleClassOfBigIntToObjectNullableFromJson(Map json) { + return SimpleClassOfBigIntToObjectNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(BigInt.parse(k), e), ), ); } -Map _$SimpleClassDateTimeToDoubleToJson( - SimpleClassDateTimeToDouble instance) => +Map _$SimpleClassOfBigIntToObjectNullableToJson( + SimpleClassOfBigIntToObjectNullable instance) => { - 'value': instance.value?.map((k, e) => MapEntry(k.toIso8601String(), e)), - 'nullable': - instance.nullable.map((k, e) => MapEntry(k.toIso8601String(), e)), + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), }; -SimpleClassDynamicToDouble _$SimpleClassDynamicToDoubleFromJson( - Map json) { - return SimpleClassDynamicToDouble( - (json['value'] as Map)?.map( - (k, e) => MapEntry(k, (e as num)?.toDouble()), +SimpleClassNullableOfBigIntToObjectNullable + _$SimpleClassNullableOfBigIntToObjectNullableFromJson( + Map json) { + return SimpleClassNullableOfBigIntToObjectNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(BigInt.parse(k), e), ), - Map.from(json['nullable'] as Map), ); } -Map _$SimpleClassDynamicToDoubleToJson( - SimpleClassDynamicToDouble instance) => +Map _$SimpleClassNullableOfBigIntToObjectNullableToJson( + SimpleClassNullableOfBigIntToObjectNullable instance) => { - 'value': instance.value, - 'nullable': instance.nullable, + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), }; -SimpleClassEnumTypeToDouble _$SimpleClassEnumTypeToDoubleFromJson( - Map json) { - return SimpleClassEnumTypeToDouble( - (json['value'] as Map)?.map( - (k, e) => MapEntry( - _$enumDecodeNullable(_$EnumTypeEnumMap, k), (e as num)?.toDouble()), - ), - (json['nullable'] as Map).map( - (k, e) => - MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), (e as num).toDouble()), +SimpleClassOfDateTimeToObjectNullable + _$SimpleClassOfDateTimeToObjectNullableFromJson(Map json) { + return SimpleClassOfDateTimeToObjectNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(DateTime.parse(k), e), ), ); } -Map _$SimpleClassEnumTypeToDoubleToJson( - SimpleClassEnumTypeToDouble instance) => +Map _$SimpleClassOfDateTimeToObjectNullableToJson( + SimpleClassOfDateTimeToObjectNullable instance) => { - 'value': instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), - 'nullable': - instance.nullable.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), + 'value': instance.value.map((k, e) => MapEntry(k.toIso8601String(), e)), }; -SimpleClassIntToDouble _$SimpleClassIntToDoubleFromJson( - Map json) { - return SimpleClassIntToDouble( - (json['value'] as Map)?.map( - (k, e) => MapEntry(int.parse(k), (e as num)?.toDouble()), - ), - (json['nullable'] as Map).map( - (k, e) => MapEntry(int.parse(k), (e as num).toDouble()), +SimpleClassNullableOfDateTimeToObjectNullable + _$SimpleClassNullableOfDateTimeToObjectNullableFromJson( + Map json) { + return SimpleClassNullableOfDateTimeToObjectNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(DateTime.parse(k), e), ), ); } -Map _$SimpleClassIntToDoubleToJson( - SimpleClassIntToDouble instance) => +Map _$SimpleClassNullableOfDateTimeToObjectNullableToJson( + SimpleClassNullableOfDateTimeToObjectNullable instance) => { - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - 'nullable': instance.nullable.map((k, e) => MapEntry(k.toString(), e)), + 'value': instance.value?.map((k, e) => MapEntry(k.toIso8601String(), e)), }; -SimpleClassObjectToDouble _$SimpleClassObjectToDoubleFromJson( - Map json) { - return SimpleClassObjectToDouble( - (json['value'] as Map)?.map( - (k, e) => MapEntry(k, (e as num)?.toDouble()), - ), - Map.from(json['nullable'] as Map), +SimpleClassOfDynamicToObjectNullable + _$SimpleClassOfDynamicToObjectNullableFromJson(Map json) { + return SimpleClassOfDynamicToObjectNullable( + json['value'] as Map, ); } -Map _$SimpleClassObjectToDoubleToJson( - SimpleClassObjectToDouble instance) => +Map _$SimpleClassOfDynamicToObjectNullableToJson( + SimpleClassOfDynamicToObjectNullable instance) => { 'value': instance.value, - 'nullable': instance.nullable, }; -SimpleClassStringToDouble _$SimpleClassStringToDoubleFromJson( - Map json) { - return SimpleClassStringToDouble( - (json['value'] as Map)?.map( - (k, e) => MapEntry(k, (e as num)?.toDouble()), - ), - Map.from(json['nullable'] as Map), +SimpleClassNullableOfDynamicToObjectNullable + _$SimpleClassNullableOfDynamicToObjectNullableFromJson( + Map json) { + return SimpleClassNullableOfDynamicToObjectNullable( + json['value'] as Map?, ); } -Map _$SimpleClassStringToDoubleToJson( - SimpleClassStringToDouble instance) => +Map _$SimpleClassNullableOfDynamicToObjectNullableToJson( + SimpleClassNullableOfDynamicToObjectNullable instance) => { 'value': instance.value, - 'nullable': instance.nullable, }; -SimpleClassUriToDouble _$SimpleClassUriToDoubleFromJson( - Map json) { - return SimpleClassUriToDouble( - (json['value'] as Map)?.map( - (k, e) => MapEntry(Uri.parse(k), (e as num)?.toDouble()), - ), - (json['nullable'] as Map).map( - (k, e) => MapEntry(Uri.parse(k), (e as num).toDouble()), +SimpleClassOfEnumTypeToObjectNullable + _$SimpleClassOfEnumTypeToObjectNullableFromJson(Map json) { + return SimpleClassOfEnumTypeToObjectNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e), ), ); } -Map _$SimpleClassUriToDoubleToJson( - SimpleClassUriToDouble instance) => +Map _$SimpleClassOfEnumTypeToObjectNullableToJson( + SimpleClassOfEnumTypeToObjectNullable instance) => { - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - 'nullable': instance.nullable.map((k, e) => MapEntry(k.toString(), e)), + 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), }; -SimpleClassBigIntToDuration _$SimpleClassBigIntToDurationFromJson( - Map json) { - return SimpleClassBigIntToDuration( - (json['value'] as Map)?.map( - (k, e) => MapEntry( - BigInt.parse(k), e == null ? null : Duration(microseconds: e as int)), - ), - (json['nullable'] as Map).map( - (k, e) => MapEntry(BigInt.parse(k), Duration(microseconds: e as int)), +SimpleClassNullableOfEnumTypeToObjectNullable + _$SimpleClassNullableOfEnumTypeToObjectNullableFromJson( + Map json) { + return SimpleClassNullableOfEnumTypeToObjectNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e), ), ); } -Map _$SimpleClassBigIntToDurationToJson( - SimpleClassBigIntToDuration instance) => +Map _$SimpleClassNullableOfEnumTypeToObjectNullableToJson( + SimpleClassNullableOfEnumTypeToObjectNullable instance) => { - 'value': instance.value - ?.map((k, e) => MapEntry(k.toString(), e?.inMicroseconds)), - 'nullable': instance.nullable - .map((k, e) => MapEntry(k.toString(), e.inMicroseconds)), + 'value': instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), }; -SimpleClassDateTimeToDuration _$SimpleClassDateTimeToDurationFromJson( +SimpleClassOfIntToObjectNullable _$SimpleClassOfIntToObjectNullableFromJson( Map json) { - return SimpleClassDateTimeToDuration( - (json['value'] as Map)?.map( - (k, e) => MapEntry(DateTime.parse(k), - e == null ? null : Duration(microseconds: e as int)), - ), - (json['nullable'] as Map).map( - (k, e) => MapEntry(DateTime.parse(k), Duration(microseconds: e as int)), + return SimpleClassOfIntToObjectNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(int.parse(k), e), ), ); } -Map _$SimpleClassDateTimeToDurationToJson( - SimpleClassDateTimeToDuration instance) => +Map _$SimpleClassOfIntToObjectNullableToJson( + SimpleClassOfIntToObjectNullable instance) => { - 'value': instance.value - ?.map((k, e) => MapEntry(k.toIso8601String(), e?.inMicroseconds)), - 'nullable': instance.nullable - .map((k, e) => MapEntry(k.toIso8601String(), e.inMicroseconds)), + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), }; -SimpleClassDynamicToDuration _$SimpleClassDynamicToDurationFromJson( - Map json) { - return SimpleClassDynamicToDuration( - (json['value'] as Map)?.map( - (k, e) => - MapEntry(k, e == null ? null : Duration(microseconds: e as int)), - ), - (json['nullable'] as Map).map( - (k, e) => MapEntry(k, Duration(microseconds: e as int)), +SimpleClassNullableOfIntToObjectNullable + _$SimpleClassNullableOfIntToObjectNullableFromJson( + Map json) { + return SimpleClassNullableOfIntToObjectNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(int.parse(k), e), ), ); } -Map _$SimpleClassDynamicToDurationToJson( - SimpleClassDynamicToDuration instance) => +Map _$SimpleClassNullableOfIntToObjectNullableToJson( + SimpleClassNullableOfIntToObjectNullable instance) => { - 'value': instance.value?.map((k, e) => MapEntry(k, e?.inMicroseconds)), - 'nullable': - instance.nullable.map((k, e) => MapEntry(k, e.inMicroseconds)), + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), }; -SimpleClassEnumTypeToDuration _$SimpleClassEnumTypeToDurationFromJson( - Map json) { - return SimpleClassEnumTypeToDuration( - (json['value'] as Map)?.map( - (k, e) => MapEntry(_$enumDecodeNullable(_$EnumTypeEnumMap, k), - e == null ? null : Duration(microseconds: e as int)), - ), - (json['nullable'] as Map).map( - (k, e) => MapEntry( - _$enumDecode(_$EnumTypeEnumMap, k), Duration(microseconds: e as int)), - ), +SimpleClassOfObjectToObjectNullable + _$SimpleClassOfObjectToObjectNullableFromJson(Map json) { + return SimpleClassOfObjectToObjectNullable( + json['value'] as Map, ); } -Map _$SimpleClassEnumTypeToDurationToJson( - SimpleClassEnumTypeToDuration instance) => +Map _$SimpleClassOfObjectToObjectNullableToJson( + SimpleClassOfObjectToObjectNullable instance) => { - 'value': instance.value - ?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e?.inMicroseconds)), - 'nullable': instance.nullable - .map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e.inMicroseconds)), + 'value': instance.value, }; -SimpleClassIntToDuration _$SimpleClassIntToDurationFromJson( - Map json) { - return SimpleClassIntToDuration( - (json['value'] as Map)?.map( - (k, e) => MapEntry( - int.parse(k), e == null ? null : Duration(microseconds: e as int)), - ), - (json['nullable'] as Map).map( - (k, e) => MapEntry(int.parse(k), Duration(microseconds: e as int)), - ), +SimpleClassNullableOfObjectToObjectNullable + _$SimpleClassNullableOfObjectToObjectNullableFromJson( + Map json) { + return SimpleClassNullableOfObjectToObjectNullable( + json['value'] as Map?, ); } -Map _$SimpleClassIntToDurationToJson( - SimpleClassIntToDuration instance) => +Map _$SimpleClassNullableOfObjectToObjectNullableToJson( + SimpleClassNullableOfObjectToObjectNullable instance) => { - 'value': instance.value - ?.map((k, e) => MapEntry(k.toString(), e?.inMicroseconds)), - 'nullable': instance.nullable - .map((k, e) => MapEntry(k.toString(), e.inMicroseconds)), + 'value': instance.value, }; -SimpleClassObjectToDuration _$SimpleClassObjectToDurationFromJson( - Map json) { - return SimpleClassObjectToDuration( - (json['value'] as Map)?.map( - (k, e) => - MapEntry(k, e == null ? null : Duration(microseconds: e as int)), - ), - (json['nullable'] as Map).map( - (k, e) => MapEntry(k, Duration(microseconds: e as int)), - ), +SimpleClassOfStringToObjectNullable + _$SimpleClassOfStringToObjectNullableFromJson(Map json) { + return SimpleClassOfStringToObjectNullable( + json['value'] as Map, ); } -Map _$SimpleClassObjectToDurationToJson( - SimpleClassObjectToDuration instance) => +Map _$SimpleClassOfStringToObjectNullableToJson( + SimpleClassOfStringToObjectNullable instance) => { - 'value': instance.value?.map((k, e) => MapEntry(k, e?.inMicroseconds)), - 'nullable': - instance.nullable.map((k, e) => MapEntry(k, e.inMicroseconds)), + 'value': instance.value, }; -SimpleClassStringToDuration _$SimpleClassStringToDurationFromJson( - Map json) { - return SimpleClassStringToDuration( - (json['value'] as Map)?.map( - (k, e) => - MapEntry(k, e == null ? null : Duration(microseconds: e as int)), - ), - (json['nullable'] as Map).map( - (k, e) => MapEntry(k, Duration(microseconds: e as int)), - ), +SimpleClassNullableOfStringToObjectNullable + _$SimpleClassNullableOfStringToObjectNullableFromJson( + Map json) { + return SimpleClassNullableOfStringToObjectNullable( + json['value'] as Map?, ); } -Map _$SimpleClassStringToDurationToJson( - SimpleClassStringToDuration instance) => +Map _$SimpleClassNullableOfStringToObjectNullableToJson( + SimpleClassNullableOfStringToObjectNullable instance) => { - 'value': instance.value?.map((k, e) => MapEntry(k, e?.inMicroseconds)), - 'nullable': - instance.nullable.map((k, e) => MapEntry(k, e.inMicroseconds)), + 'value': instance.value, }; -SimpleClassUriToDuration _$SimpleClassUriToDurationFromJson( +SimpleClassOfUriToObjectNullable _$SimpleClassOfUriToObjectNullableFromJson( Map json) { - return SimpleClassUriToDuration( - (json['value'] as Map)?.map( - (k, e) => MapEntry( - Uri.parse(k), e == null ? null : Duration(microseconds: e as int)), - ), - (json['nullable'] as Map).map( - (k, e) => MapEntry(Uri.parse(k), Duration(microseconds: e as int)), + return SimpleClassOfUriToObjectNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(Uri.parse(k), e), ), ); } -Map _$SimpleClassUriToDurationToJson( - SimpleClassUriToDuration instance) => +Map _$SimpleClassOfUriToObjectNullableToJson( + SimpleClassOfUriToObjectNullable instance) => { - 'value': instance.value - ?.map((k, e) => MapEntry(k.toString(), e?.inMicroseconds)), - 'nullable': instance.nullable - .map((k, e) => MapEntry(k.toString(), e.inMicroseconds)), + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), }; -SimpleClassBigIntToDynamic _$SimpleClassBigIntToDynamicFromJson( - Map json) { - return SimpleClassBigIntToDynamic( - (json['value'] as Map)?.map( - (k, e) => MapEntry(BigInt.parse(k), e), - ), - (json['nullable'] as Map).map( - (k, e) => MapEntry(BigInt.parse(k), e), +SimpleClassNullableOfUriToObjectNullable + _$SimpleClassNullableOfUriToObjectNullableFromJson( + Map json) { + return SimpleClassNullableOfUriToObjectNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(Uri.parse(k), e), ), ); } -Map _$SimpleClassBigIntToDynamicToJson( - SimpleClassBigIntToDynamic instance) => +Map _$SimpleClassNullableOfUriToObjectNullableToJson( + SimpleClassNullableOfUriToObjectNullable instance) => { 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - 'nullable': instance.nullable.map((k, e) => MapEntry(k.toString(), e)), }; -SimpleClassDateTimeToDynamic _$SimpleClassDateTimeToDynamicFromJson( +SimpleClassOfBigIntToString _$SimpleClassOfBigIntToStringFromJson( Map json) { - return SimpleClassDateTimeToDynamic( - (json['value'] as Map)?.map( - (k, e) => MapEntry(DateTime.parse(k), e), - ), - (json['nullable'] as Map).map( - (k, e) => MapEntry(DateTime.parse(k), e), + return SimpleClassOfBigIntToString( + (json['value'] as Map).map( + (k, e) => MapEntry(BigInt.parse(k), e as String), ), ); } -Map _$SimpleClassDateTimeToDynamicToJson( - SimpleClassDateTimeToDynamic instance) => +Map _$SimpleClassOfBigIntToStringToJson( + SimpleClassOfBigIntToString instance) => { - 'value': instance.value?.map((k, e) => MapEntry(k.toIso8601String(), e)), - 'nullable': - instance.nullable.map((k, e) => MapEntry(k.toIso8601String(), e)), + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), }; -SimpleClassDynamicToDynamic _$SimpleClassDynamicToDynamicFromJson( - Map json) { - return SimpleClassDynamicToDynamic( - json['value'] as Map, - json['nullable'] as Map, +SimpleClassNullableOfBigIntToString + _$SimpleClassNullableOfBigIntToStringFromJson(Map json) { + return SimpleClassNullableOfBigIntToString( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(BigInt.parse(k), e as String), + ), ); } -Map _$SimpleClassDynamicToDynamicToJson( - SimpleClassDynamicToDynamic instance) => +Map _$SimpleClassNullableOfBigIntToStringToJson( + SimpleClassNullableOfBigIntToString instance) => { - 'value': instance.value, - 'nullable': instance.nullable, + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), }; -SimpleClassEnumTypeToDynamic _$SimpleClassEnumTypeToDynamicFromJson( +SimpleClassOfDateTimeToString _$SimpleClassOfDateTimeToStringFromJson( Map json) { - return SimpleClassEnumTypeToDynamic( - (json['value'] as Map)?.map( - (k, e) => MapEntry(_$enumDecodeNullable(_$EnumTypeEnumMap, k), e), - ), - (json['nullable'] as Map).map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e), + return SimpleClassOfDateTimeToString( + (json['value'] as Map).map( + (k, e) => MapEntry(DateTime.parse(k), e as String), ), ); } -Map _$SimpleClassEnumTypeToDynamicToJson( - SimpleClassEnumTypeToDynamic instance) => +Map _$SimpleClassOfDateTimeToStringToJson( + SimpleClassOfDateTimeToString instance) => { - 'value': instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), - 'nullable': - instance.nullable.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), + 'value': instance.value.map((k, e) => MapEntry(k.toIso8601String(), e)), }; -SimpleClassIntToDynamic _$SimpleClassIntToDynamicFromJson( - Map json) { - return SimpleClassIntToDynamic( - (json['value'] as Map)?.map( - (k, e) => MapEntry(int.parse(k), e), - ), - (json['nullable'] as Map).map( - (k, e) => MapEntry(int.parse(k), e), +SimpleClassNullableOfDateTimeToString + _$SimpleClassNullableOfDateTimeToStringFromJson(Map json) { + return SimpleClassNullableOfDateTimeToString( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(DateTime.parse(k), e as String), ), ); } -Map _$SimpleClassIntToDynamicToJson( - SimpleClassIntToDynamic instance) => +Map _$SimpleClassNullableOfDateTimeToStringToJson( + SimpleClassNullableOfDateTimeToString instance) => { - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - 'nullable': instance.nullable.map((k, e) => MapEntry(k.toString(), e)), + 'value': instance.value?.map((k, e) => MapEntry(k.toIso8601String(), e)), }; -SimpleClassObjectToDynamic _$SimpleClassObjectToDynamicFromJson( +SimpleClassOfDynamicToString _$SimpleClassOfDynamicToStringFromJson( Map json) { - return SimpleClassObjectToDynamic( - json['value'] as Map, - json['nullable'] as Map, + return SimpleClassOfDynamicToString( + Map.from(json['value'] as Map), ); } -Map _$SimpleClassObjectToDynamicToJson( - SimpleClassObjectToDynamic instance) => +Map _$SimpleClassOfDynamicToStringToJson( + SimpleClassOfDynamicToString instance) => { 'value': instance.value, - 'nullable': instance.nullable, }; -SimpleClassStringToDynamic _$SimpleClassStringToDynamicFromJson( - Map json) { - return SimpleClassStringToDynamic( - json['value'] as Map, - json['nullable'] as Map, +SimpleClassNullableOfDynamicToString + _$SimpleClassNullableOfDynamicToStringFromJson(Map json) { + return SimpleClassNullableOfDynamicToString( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e as String), + ), ); } -Map _$SimpleClassStringToDynamicToJson( - SimpleClassStringToDynamic instance) => +Map _$SimpleClassNullableOfDynamicToStringToJson( + SimpleClassNullableOfDynamicToString instance) => { 'value': instance.value, - 'nullable': instance.nullable, }; -SimpleClassUriToDynamic _$SimpleClassUriToDynamicFromJson( +SimpleClassOfEnumTypeToString _$SimpleClassOfEnumTypeToStringFromJson( Map json) { - return SimpleClassUriToDynamic( - (json['value'] as Map)?.map( - (k, e) => MapEntry(Uri.parse(k), e), - ), - (json['nullable'] as Map).map( - (k, e) => MapEntry(Uri.parse(k), e), + return SimpleClassOfEnumTypeToString( + (json['value'] as Map).map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as String), ), ); } -Map _$SimpleClassUriToDynamicToJson( - SimpleClassUriToDynamic instance) => +Map _$SimpleClassOfEnumTypeToStringToJson( + SimpleClassOfEnumTypeToString instance) => { - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - 'nullable': instance.nullable.map((k, e) => MapEntry(k.toString(), e)), + 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), }; -SimpleClassBigIntToEnumType _$SimpleClassBigIntToEnumTypeFromJson( - Map json) { - return SimpleClassBigIntToEnumType( - (json['value'] as Map)?.map( - (k, e) => - MapEntry(BigInt.parse(k), _$enumDecodeNullable(_$EnumTypeEnumMap, e)), - ), - (json['nullable'] as Map).map( - (k, e) => MapEntry(BigInt.parse(k), _$enumDecode(_$EnumTypeEnumMap, e)), +SimpleClassNullableOfEnumTypeToString + _$SimpleClassNullableOfEnumTypeToStringFromJson(Map json) { + return SimpleClassNullableOfEnumTypeToString( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as String), ), ); } -Map _$SimpleClassBigIntToEnumTypeToJson( - SimpleClassBigIntToEnumType instance) => +Map _$SimpleClassNullableOfEnumTypeToStringToJson( + SimpleClassNullableOfEnumTypeToString instance) => { - 'value': instance.value - ?.map((k, e) => MapEntry(k.toString(), _$EnumTypeEnumMap[e])), - 'nullable': instance.nullable - .map((k, e) => MapEntry(k.toString(), _$EnumTypeEnumMap[e])), + 'value': instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), }; -SimpleClassDateTimeToEnumType _$SimpleClassDateTimeToEnumTypeFromJson( +SimpleClassOfIntToString _$SimpleClassOfIntToStringFromJson( Map json) { - return SimpleClassDateTimeToEnumType( - (json['value'] as Map)?.map( - (k, e) => MapEntry( - DateTime.parse(k), _$enumDecodeNullable(_$EnumTypeEnumMap, e)), - ), - (json['nullable'] as Map).map( - (k, e) => MapEntry(DateTime.parse(k), _$enumDecode(_$EnumTypeEnumMap, e)), + return SimpleClassOfIntToString( + (json['value'] as Map).map( + (k, e) => MapEntry(int.parse(k), e as String), ), ); } -Map _$SimpleClassDateTimeToEnumTypeToJson( - SimpleClassDateTimeToEnumType instance) => +Map _$SimpleClassOfIntToStringToJson( + SimpleClassOfIntToString instance) => { - 'value': instance.value - ?.map((k, e) => MapEntry(k.toIso8601String(), _$EnumTypeEnumMap[e])), - 'nullable': instance.nullable - .map((k, e) => MapEntry(k.toIso8601String(), _$EnumTypeEnumMap[e])), + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), }; -SimpleClassDynamicToEnumType _$SimpleClassDynamicToEnumTypeFromJson( +SimpleClassNullableOfIntToString _$SimpleClassNullableOfIntToStringFromJson( Map json) { - return SimpleClassDynamicToEnumType( - (json['value'] as Map)?.map( - (k, e) => MapEntry(k, _$enumDecodeNullable(_$EnumTypeEnumMap, e)), - ), - (json['nullable'] as Map).map( - (k, e) => MapEntry(k, _$enumDecode(_$EnumTypeEnumMap, e)), + return SimpleClassNullableOfIntToString( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(int.parse(k), e as String), ), ); } -Map _$SimpleClassDynamicToEnumTypeToJson( - SimpleClassDynamicToEnumType instance) => +Map _$SimpleClassNullableOfIntToStringToJson( + SimpleClassNullableOfIntToString instance) => { - 'value': instance.value?.map((k, e) => MapEntry(k, _$EnumTypeEnumMap[e])), - 'nullable': - instance.nullable.map((k, e) => MapEntry(k, _$EnumTypeEnumMap[e])), + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), }; -SimpleClassEnumTypeToEnumType _$SimpleClassEnumTypeToEnumTypeFromJson( +SimpleClassOfObjectToString _$SimpleClassOfObjectToStringFromJson( Map json) { - return SimpleClassEnumTypeToEnumType( - (json['value'] as Map)?.map( - (k, e) => MapEntry(_$enumDecodeNullable(_$EnumTypeEnumMap, k), - _$enumDecodeNullable(_$EnumTypeEnumMap, e)), - ), - (json['nullable'] as Map).map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), - _$enumDecode(_$EnumTypeEnumMap, e)), - ), + return SimpleClassOfObjectToString( + Map.from(json['value'] as Map), ); } -Map _$SimpleClassEnumTypeToEnumTypeToJson( - SimpleClassEnumTypeToEnumType instance) => +Map _$SimpleClassOfObjectToStringToJson( + SimpleClassOfObjectToString instance) => { - 'value': instance.value - ?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], _$EnumTypeEnumMap[e])), - 'nullable': instance.nullable - .map((k, e) => MapEntry(_$EnumTypeEnumMap[k], _$EnumTypeEnumMap[e])), + 'value': instance.value, }; -SimpleClassIntToEnumType _$SimpleClassIntToEnumTypeFromJson( - Map json) { - return SimpleClassIntToEnumType( - (json['value'] as Map)?.map( - (k, e) => - MapEntry(int.parse(k), _$enumDecodeNullable(_$EnumTypeEnumMap, e)), - ), - (json['nullable'] as Map).map( - (k, e) => MapEntry(int.parse(k), _$enumDecode(_$EnumTypeEnumMap, e)), +SimpleClassNullableOfObjectToString + _$SimpleClassNullableOfObjectToStringFromJson(Map json) { + return SimpleClassNullableOfObjectToString( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e as String), ), ); } -Map _$SimpleClassIntToEnumTypeToJson( - SimpleClassIntToEnumType instance) => +Map _$SimpleClassNullableOfObjectToStringToJson( + SimpleClassNullableOfObjectToString instance) => + { + 'value': instance.value, + }; + +SimpleClassOfStringToString _$SimpleClassOfStringToStringFromJson( + Map json) { + return SimpleClassOfStringToString( + Map.from(json['value'] as Map), + ); +} + +Map _$SimpleClassOfStringToStringToJson( + SimpleClassOfStringToString instance) => { - 'value': instance.value - ?.map((k, e) => MapEntry(k.toString(), _$EnumTypeEnumMap[e])), - 'nullable': instance.nullable - .map((k, e) => MapEntry(k.toString(), _$EnumTypeEnumMap[e])), + 'value': instance.value, }; -SimpleClassObjectToEnumType _$SimpleClassObjectToEnumTypeFromJson( - Map json) { - return SimpleClassObjectToEnumType( - (json['value'] as Map)?.map( - (k, e) => MapEntry(k, _$enumDecodeNullable(_$EnumTypeEnumMap, e)), - ), - (json['nullable'] as Map).map( - (k, e) => MapEntry(k, _$enumDecode(_$EnumTypeEnumMap, e)), +SimpleClassNullableOfStringToString + _$SimpleClassNullableOfStringToStringFromJson(Map json) { + return SimpleClassNullableOfStringToString( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e as String), ), ); } -Map _$SimpleClassObjectToEnumTypeToJson( - SimpleClassObjectToEnumType instance) => +Map _$SimpleClassNullableOfStringToStringToJson( + SimpleClassNullableOfStringToString instance) => { - 'value': instance.value?.map((k, e) => MapEntry(k, _$EnumTypeEnumMap[e])), - 'nullable': - instance.nullable.map((k, e) => MapEntry(k, _$EnumTypeEnumMap[e])), + 'value': instance.value, }; -SimpleClassStringToEnumType _$SimpleClassStringToEnumTypeFromJson( +SimpleClassOfUriToString _$SimpleClassOfUriToStringFromJson( Map json) { - return SimpleClassStringToEnumType( - (json['value'] as Map)?.map( - (k, e) => MapEntry(k, _$enumDecodeNullable(_$EnumTypeEnumMap, e)), - ), - (json['nullable'] as Map).map( - (k, e) => MapEntry(k, _$enumDecode(_$EnumTypeEnumMap, e)), + return SimpleClassOfUriToString( + (json['value'] as Map).map( + (k, e) => MapEntry(Uri.parse(k), e as String), ), ); } -Map _$SimpleClassStringToEnumTypeToJson( - SimpleClassStringToEnumType instance) => +Map _$SimpleClassOfUriToStringToJson( + SimpleClassOfUriToString instance) => { - 'value': instance.value?.map((k, e) => MapEntry(k, _$EnumTypeEnumMap[e])), - 'nullable': - instance.nullable.map((k, e) => MapEntry(k, _$EnumTypeEnumMap[e])), + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), }; -SimpleClassUriToEnumType _$SimpleClassUriToEnumTypeFromJson( +SimpleClassNullableOfUriToString _$SimpleClassNullableOfUriToStringFromJson( Map json) { - return SimpleClassUriToEnumType( - (json['value'] as Map)?.map( - (k, e) => - MapEntry(Uri.parse(k), _$enumDecodeNullable(_$EnumTypeEnumMap, e)), - ), - (json['nullable'] as Map).map( - (k, e) => MapEntry(Uri.parse(k), _$enumDecode(_$EnumTypeEnumMap, e)), + return SimpleClassNullableOfUriToString( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(Uri.parse(k), e as String), ), ); } -Map _$SimpleClassUriToEnumTypeToJson( - SimpleClassUriToEnumType instance) => +Map _$SimpleClassNullableOfUriToStringToJson( + SimpleClassNullableOfUriToString instance) => { - 'value': instance.value - ?.map((k, e) => MapEntry(k.toString(), _$EnumTypeEnumMap[e])), - 'nullable': instance.nullable - .map((k, e) => MapEntry(k.toString(), _$EnumTypeEnumMap[e])), + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), }; -SimpleClassBigIntToInt _$SimpleClassBigIntToIntFromJson( - Map json) { - return SimpleClassBigIntToInt( - (json['value'] as Map)?.map( - (k, e) => MapEntry(BigInt.parse(k), e as int), - ), - (json['nullable'] as Map).map( - (k, e) => MapEntry(BigInt.parse(k), e as int), +SimpleClassOfBigIntToStringNullable + _$SimpleClassOfBigIntToStringNullableFromJson(Map json) { + return SimpleClassOfBigIntToStringNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(BigInt.parse(k), e as String?), ), ); } -Map _$SimpleClassBigIntToIntToJson( - SimpleClassBigIntToInt instance) => +Map _$SimpleClassOfBigIntToStringNullableToJson( + SimpleClassOfBigIntToStringNullable instance) => { - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - 'nullable': instance.nullable.map((k, e) => MapEntry(k.toString(), e)), + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), }; -SimpleClassDateTimeToInt _$SimpleClassDateTimeToIntFromJson( - Map json) { - return SimpleClassDateTimeToInt( - (json['value'] as Map)?.map( - (k, e) => MapEntry(DateTime.parse(k), e as int), - ), - (json['nullable'] as Map).map( - (k, e) => MapEntry(DateTime.parse(k), e as int), +SimpleClassNullableOfBigIntToStringNullable + _$SimpleClassNullableOfBigIntToStringNullableFromJson( + Map json) { + return SimpleClassNullableOfBigIntToStringNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(BigInt.parse(k), e as String?), ), ); } -Map _$SimpleClassDateTimeToIntToJson( - SimpleClassDateTimeToInt instance) => +Map _$SimpleClassNullableOfBigIntToStringNullableToJson( + SimpleClassNullableOfBigIntToStringNullable instance) => { - 'value': instance.value?.map((k, e) => MapEntry(k.toIso8601String(), e)), - 'nullable': - instance.nullable.map((k, e) => MapEntry(k.toIso8601String(), e)), + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), }; -SimpleClassDynamicToInt _$SimpleClassDynamicToIntFromJson( - Map json) { - return SimpleClassDynamicToInt( - (json['value'] as Map)?.map( - (k, e) => MapEntry(k, e as int), +SimpleClassOfDateTimeToStringNullable + _$SimpleClassOfDateTimeToStringNullableFromJson(Map json) { + return SimpleClassOfDateTimeToStringNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(DateTime.parse(k), e as String?), ), - Map.from(json['nullable'] as Map), ); } -Map _$SimpleClassDynamicToIntToJson( - SimpleClassDynamicToInt instance) => +Map _$SimpleClassOfDateTimeToStringNullableToJson( + SimpleClassOfDateTimeToStringNullable instance) => { - 'value': instance.value, - 'nullable': instance.nullable, + 'value': instance.value.map((k, e) => MapEntry(k.toIso8601String(), e)), }; -SimpleClassEnumTypeToInt _$SimpleClassEnumTypeToIntFromJson( - Map json) { - return SimpleClassEnumTypeToInt( - (json['value'] as Map)?.map( - (k, e) => MapEntry(_$enumDecodeNullable(_$EnumTypeEnumMap, k), e as int), - ), - (json['nullable'] as Map).map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as int), +SimpleClassNullableOfDateTimeToStringNullable + _$SimpleClassNullableOfDateTimeToStringNullableFromJson( + Map json) { + return SimpleClassNullableOfDateTimeToStringNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(DateTime.parse(k), e as String?), ), ); } -Map _$SimpleClassEnumTypeToIntToJson( - SimpleClassEnumTypeToInt instance) => +Map _$SimpleClassNullableOfDateTimeToStringNullableToJson( + SimpleClassNullableOfDateTimeToStringNullable instance) => { - 'value': instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), - 'nullable': - instance.nullable.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), + 'value': instance.value?.map((k, e) => MapEntry(k.toIso8601String(), e)), }; -SimpleClassIntToInt _$SimpleClassIntToIntFromJson(Map json) { - return SimpleClassIntToInt( - (json['value'] as Map)?.map( - (k, e) => MapEntry(int.parse(k), e as int), - ), - (json['nullable'] as Map).map( - (k, e) => MapEntry(int.parse(k), e as int), - ), +SimpleClassOfDynamicToStringNullable + _$SimpleClassOfDynamicToStringNullableFromJson(Map json) { + return SimpleClassOfDynamicToStringNullable( + Map.from(json['value'] as Map), ); } -Map _$SimpleClassIntToIntToJson( - SimpleClassIntToInt instance) => +Map _$SimpleClassOfDynamicToStringNullableToJson( + SimpleClassOfDynamicToStringNullable instance) => { - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - 'nullable': instance.nullable.map((k, e) => MapEntry(k.toString(), e)), + 'value': instance.value, }; -SimpleClassObjectToInt _$SimpleClassObjectToIntFromJson( - Map json) { - return SimpleClassObjectToInt( - (json['value'] as Map)?.map( - (k, e) => MapEntry(k, e as int), +SimpleClassNullableOfDynamicToStringNullable + _$SimpleClassNullableOfDynamicToStringNullableFromJson( + Map json) { + return SimpleClassNullableOfDynamicToStringNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e as String?), ), - Map.from(json['nullable'] as Map), ); } -Map _$SimpleClassObjectToIntToJson( - SimpleClassObjectToInt instance) => +Map _$SimpleClassNullableOfDynamicToStringNullableToJson( + SimpleClassNullableOfDynamicToStringNullable instance) => { 'value': instance.value, - 'nullable': instance.nullable, }; -SimpleClassStringToInt _$SimpleClassStringToIntFromJson( - Map json) { - return SimpleClassStringToInt( - (json['value'] as Map)?.map( - (k, e) => MapEntry(k, e as int), +SimpleClassOfEnumTypeToStringNullable + _$SimpleClassOfEnumTypeToStringNullableFromJson(Map json) { + return SimpleClassOfEnumTypeToStringNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as String?), ), - Map.from(json['nullable'] as Map), ); } -Map _$SimpleClassStringToIntToJson( - SimpleClassStringToInt instance) => +Map _$SimpleClassOfEnumTypeToStringNullableToJson( + SimpleClassOfEnumTypeToStringNullable instance) => { - 'value': instance.value, - 'nullable': instance.nullable, + 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), }; -SimpleClassUriToInt _$SimpleClassUriToIntFromJson(Map json) { - return SimpleClassUriToInt( - (json['value'] as Map)?.map( - (k, e) => MapEntry(Uri.parse(k), e as int), - ), - (json['nullable'] as Map).map( - (k, e) => MapEntry(Uri.parse(k), e as int), +SimpleClassNullableOfEnumTypeToStringNullable + _$SimpleClassNullableOfEnumTypeToStringNullableFromJson( + Map json) { + return SimpleClassNullableOfEnumTypeToStringNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as String?), ), ); } -Map _$SimpleClassUriToIntToJson( - SimpleClassUriToInt instance) => +Map _$SimpleClassNullableOfEnumTypeToStringNullableToJson( + SimpleClassNullableOfEnumTypeToStringNullable instance) => { - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - 'nullable': instance.nullable.map((k, e) => MapEntry(k.toString(), e)), + 'value': instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), }; -SimpleClassBigIntToNum _$SimpleClassBigIntToNumFromJson( +SimpleClassOfIntToStringNullable _$SimpleClassOfIntToStringNullableFromJson( Map json) { - return SimpleClassBigIntToNum( - (json['value'] as Map)?.map( - (k, e) => MapEntry(BigInt.parse(k), e as num), - ), - (json['nullable'] as Map).map( - (k, e) => MapEntry(BigInt.parse(k), e as num), + return SimpleClassOfIntToStringNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(int.parse(k), e as String?), ), ); } -Map _$SimpleClassBigIntToNumToJson( - SimpleClassBigIntToNum instance) => +Map _$SimpleClassOfIntToStringNullableToJson( + SimpleClassOfIntToStringNullable instance) => { - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - 'nullable': instance.nullable.map((k, e) => MapEntry(k.toString(), e)), + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), }; -SimpleClassDateTimeToNum _$SimpleClassDateTimeToNumFromJson( - Map json) { - return SimpleClassDateTimeToNum( - (json['value'] as Map)?.map( - (k, e) => MapEntry(DateTime.parse(k), e as num), - ), - (json['nullable'] as Map).map( - (k, e) => MapEntry(DateTime.parse(k), e as num), +SimpleClassNullableOfIntToStringNullable + _$SimpleClassNullableOfIntToStringNullableFromJson( + Map json) { + return SimpleClassNullableOfIntToStringNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(int.parse(k), e as String?), ), ); } -Map _$SimpleClassDateTimeToNumToJson( - SimpleClassDateTimeToNum instance) => +Map _$SimpleClassNullableOfIntToStringNullableToJson( + SimpleClassNullableOfIntToStringNullable instance) => { - 'value': instance.value?.map((k, e) => MapEntry(k.toIso8601String(), e)), - 'nullable': - instance.nullable.map((k, e) => MapEntry(k.toIso8601String(), e)), + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), }; -SimpleClassDynamicToNum _$SimpleClassDynamicToNumFromJson( - Map json) { - return SimpleClassDynamicToNum( - (json['value'] as Map)?.map( - (k, e) => MapEntry(k, e as num), - ), - Map.from(json['nullable'] as Map), +SimpleClassOfObjectToStringNullable + _$SimpleClassOfObjectToStringNullableFromJson(Map json) { + return SimpleClassOfObjectToStringNullable( + Map.from(json['value'] as Map), ); } -Map _$SimpleClassDynamicToNumToJson( - SimpleClassDynamicToNum instance) => +Map _$SimpleClassOfObjectToStringNullableToJson( + SimpleClassOfObjectToStringNullable instance) => { 'value': instance.value, - 'nullable': instance.nullable, }; -SimpleClassEnumTypeToNum _$SimpleClassEnumTypeToNumFromJson( - Map json) { - return SimpleClassEnumTypeToNum( - (json['value'] as Map)?.map( - (k, e) => MapEntry(_$enumDecodeNullable(_$EnumTypeEnumMap, k), e as num), - ), - (json['nullable'] as Map).map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as num), +SimpleClassNullableOfObjectToStringNullable + _$SimpleClassNullableOfObjectToStringNullableFromJson( + Map json) { + return SimpleClassNullableOfObjectToStringNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e as String?), ), ); } -Map _$SimpleClassEnumTypeToNumToJson( - SimpleClassEnumTypeToNum instance) => +Map _$SimpleClassNullableOfObjectToStringNullableToJson( + SimpleClassNullableOfObjectToStringNullable instance) => { - 'value': instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), - 'nullable': - instance.nullable.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), + 'value': instance.value, }; -SimpleClassIntToNum _$SimpleClassIntToNumFromJson(Map json) { - return SimpleClassIntToNum( - (json['value'] as Map)?.map( - (k, e) => MapEntry(int.parse(k), e as num), - ), - (json['nullable'] as Map).map( - (k, e) => MapEntry(int.parse(k), e as num), - ), +SimpleClassOfStringToStringNullable + _$SimpleClassOfStringToStringNullableFromJson(Map json) { + return SimpleClassOfStringToStringNullable( + Map.from(json['value'] as Map), ); } -Map _$SimpleClassIntToNumToJson( - SimpleClassIntToNum instance) => +Map _$SimpleClassOfStringToStringNullableToJson( + SimpleClassOfStringToStringNullable instance) => { - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - 'nullable': instance.nullable.map((k, e) => MapEntry(k.toString(), e)), + 'value': instance.value, }; -SimpleClassObjectToNum _$SimpleClassObjectToNumFromJson( - Map json) { - return SimpleClassObjectToNum( - (json['value'] as Map)?.map( - (k, e) => MapEntry(k, e as num), +SimpleClassNullableOfStringToStringNullable + _$SimpleClassNullableOfStringToStringNullableFromJson( + Map json) { + return SimpleClassNullableOfStringToStringNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e as String?), ), - Map.from(json['nullable'] as Map), ); } -Map _$SimpleClassObjectToNumToJson( - SimpleClassObjectToNum instance) => +Map _$SimpleClassNullableOfStringToStringNullableToJson( + SimpleClassNullableOfStringToStringNullable instance) => { 'value': instance.value, - 'nullable': instance.nullable, }; -SimpleClassStringToNum _$SimpleClassStringToNumFromJson( +SimpleClassOfUriToStringNullable _$SimpleClassOfUriToStringNullableFromJson( Map json) { - return SimpleClassStringToNum( - (json['value'] as Map)?.map( - (k, e) => MapEntry(k, e as num), + return SimpleClassOfUriToStringNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(Uri.parse(k), e as String?), ), - Map.from(json['nullable'] as Map), ); } -Map _$SimpleClassStringToNumToJson( - SimpleClassStringToNum instance) => +Map _$SimpleClassOfUriToStringNullableToJson( + SimpleClassOfUriToStringNullable instance) => { - 'value': instance.value, - 'nullable': instance.nullable, + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), }; -SimpleClassUriToNum _$SimpleClassUriToNumFromJson(Map json) { - return SimpleClassUriToNum( - (json['value'] as Map)?.map( - (k, e) => MapEntry(Uri.parse(k), e as num), - ), - (json['nullable'] as Map).map( - (k, e) => MapEntry(Uri.parse(k), e as num), +SimpleClassNullableOfUriToStringNullable + _$SimpleClassNullableOfUriToStringNullableFromJson( + Map json) { + return SimpleClassNullableOfUriToStringNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(Uri.parse(k), e as String?), ), ); } -Map _$SimpleClassUriToNumToJson( - SimpleClassUriToNum instance) => +Map _$SimpleClassNullableOfUriToStringNullableToJson( + SimpleClassNullableOfUriToStringNullable instance) => { 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - 'nullable': instance.nullable.map((k, e) => MapEntry(k.toString(), e)), }; -SimpleClassBigIntToObject _$SimpleClassBigIntToObjectFromJson( +SimpleClassOfBigIntToUri _$SimpleClassOfBigIntToUriFromJson( Map json) { - return SimpleClassBigIntToObject( - (json['value'] as Map)?.map( - (k, e) => MapEntry(BigInt.parse(k), e), - ), - (json['nullable'] as Map).map( - (k, e) => MapEntry(BigInt.parse(k), e), + return SimpleClassOfBigIntToUri( + (json['value'] as Map).map( + (k, e) => MapEntry(BigInt.parse(k), Uri.parse(e as String)), ), ); } -Map _$SimpleClassBigIntToObjectToJson( - SimpleClassBigIntToObject instance) => +Map _$SimpleClassOfBigIntToUriToJson( + SimpleClassOfBigIntToUri instance) => { - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - 'nullable': instance.nullable.map((k, e) => MapEntry(k.toString(), e)), + 'value': + instance.value.map((k, e) => MapEntry(k.toString(), e.toString())), }; -SimpleClassDateTimeToObject _$SimpleClassDateTimeToObjectFromJson( +SimpleClassNullableOfBigIntToUri _$SimpleClassNullableOfBigIntToUriFromJson( Map json) { - return SimpleClassDateTimeToObject( - (json['value'] as Map)?.map( - (k, e) => MapEntry(DateTime.parse(k), e), - ), - (json['nullable'] as Map).map( - (k, e) => MapEntry(DateTime.parse(k), e), + return SimpleClassNullableOfBigIntToUri( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(BigInt.parse(k), Uri.parse(e as String)), ), ); } -Map _$SimpleClassDateTimeToObjectToJson( - SimpleClassDateTimeToObject instance) => +Map _$SimpleClassNullableOfBigIntToUriToJson( + SimpleClassNullableOfBigIntToUri instance) => { - 'value': instance.value?.map((k, e) => MapEntry(k.toIso8601String(), e)), - 'nullable': - instance.nullable.map((k, e) => MapEntry(k.toIso8601String(), e)), + 'value': + instance.value?.map((k, e) => MapEntry(k.toString(), e.toString())), }; -SimpleClassDynamicToObject _$SimpleClassDynamicToObjectFromJson( +SimpleClassOfDateTimeToUri _$SimpleClassOfDateTimeToUriFromJson( Map json) { - return SimpleClassDynamicToObject( - json['value'] as Map, - json['nullable'] as Map, + return SimpleClassOfDateTimeToUri( + (json['value'] as Map).map( + (k, e) => MapEntry(DateTime.parse(k), Uri.parse(e as String)), + ), ); } -Map _$SimpleClassDynamicToObjectToJson( - SimpleClassDynamicToObject instance) => +Map _$SimpleClassOfDateTimeToUriToJson( + SimpleClassOfDateTimeToUri instance) => { - 'value': instance.value, - 'nullable': instance.nullable, + 'value': instance.value + .map((k, e) => MapEntry(k.toIso8601String(), e.toString())), }; -SimpleClassEnumTypeToObject _$SimpleClassEnumTypeToObjectFromJson( +SimpleClassNullableOfDateTimeToUri _$SimpleClassNullableOfDateTimeToUriFromJson( Map json) { - return SimpleClassEnumTypeToObject( - (json['value'] as Map)?.map( - (k, e) => MapEntry(_$enumDecodeNullable(_$EnumTypeEnumMap, k), e), - ), - (json['nullable'] as Map).map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e), + return SimpleClassNullableOfDateTimeToUri( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(DateTime.parse(k), Uri.parse(e as String)), ), ); } -Map _$SimpleClassEnumTypeToObjectToJson( - SimpleClassEnumTypeToObject instance) => +Map _$SimpleClassNullableOfDateTimeToUriToJson( + SimpleClassNullableOfDateTimeToUri instance) => { - 'value': instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), - 'nullable': - instance.nullable.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), + 'value': instance.value + ?.map((k, e) => MapEntry(k.toIso8601String(), e.toString())), }; -SimpleClassIntToObject _$SimpleClassIntToObjectFromJson( +SimpleClassOfDynamicToUri _$SimpleClassOfDynamicToUriFromJson( Map json) { - return SimpleClassIntToObject( - (json['value'] as Map)?.map( - (k, e) => MapEntry(int.parse(k), e), - ), - (json['nullable'] as Map).map( - (k, e) => MapEntry(int.parse(k), e), + return SimpleClassOfDynamicToUri( + (json['value'] as Map).map( + (k, e) => MapEntry(k, Uri.parse(e as String)), ), ); } -Map _$SimpleClassIntToObjectToJson( - SimpleClassIntToObject instance) => +Map _$SimpleClassOfDynamicToUriToJson( + SimpleClassOfDynamicToUri instance) => { - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - 'nullable': instance.nullable.map((k, e) => MapEntry(k.toString(), e)), + 'value': instance.value.map((k, e) => MapEntry(k, e.toString())), }; -SimpleClassObjectToObject _$SimpleClassObjectToObjectFromJson( +SimpleClassNullableOfDynamicToUri _$SimpleClassNullableOfDynamicToUriFromJson( Map json) { - return SimpleClassObjectToObject( - json['value'] as Map, - json['nullable'] as Map, + return SimpleClassNullableOfDynamicToUri( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, Uri.parse(e as String)), + ), ); } -Map _$SimpleClassObjectToObjectToJson( - SimpleClassObjectToObject instance) => +Map _$SimpleClassNullableOfDynamicToUriToJson( + SimpleClassNullableOfDynamicToUri instance) => { - 'value': instance.value, - 'nullable': instance.nullable, + 'value': instance.value?.map((k, e) => MapEntry(k, e.toString())), }; -SimpleClassStringToObject _$SimpleClassStringToObjectFromJson( +SimpleClassOfEnumTypeToUri _$SimpleClassOfEnumTypeToUriFromJson( Map json) { - return SimpleClassStringToObject( - json['value'] as Map, - json['nullable'] as Map, + return SimpleClassOfEnumTypeToUri( + (json['value'] as Map).map( + (k, e) => + MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), Uri.parse(e as String)), + ), ); } -Map _$SimpleClassStringToObjectToJson( - SimpleClassStringToObject instance) => +Map _$SimpleClassOfEnumTypeToUriToJson( + SimpleClassOfEnumTypeToUri instance) => { - 'value': instance.value, - 'nullable': instance.nullable, + 'value': instance.value + .map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e.toString())), }; -SimpleClassUriToObject _$SimpleClassUriToObjectFromJson( +SimpleClassNullableOfEnumTypeToUri _$SimpleClassNullableOfEnumTypeToUriFromJson( Map json) { - return SimpleClassUriToObject( - (json['value'] as Map)?.map( - (k, e) => MapEntry(Uri.parse(k), e), - ), - (json['nullable'] as Map).map( - (k, e) => MapEntry(Uri.parse(k), e), + return SimpleClassNullableOfEnumTypeToUri( + (json['value'] as Map?)?.map( + (k, e) => + MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), Uri.parse(e as String)), ), ); } -Map _$SimpleClassUriToObjectToJson( - SimpleClassUriToObject instance) => +Map _$SimpleClassNullableOfEnumTypeToUriToJson( + SimpleClassNullableOfEnumTypeToUri instance) => { - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - 'nullable': instance.nullable.map((k, e) => MapEntry(k.toString(), e)), + 'value': instance.value + ?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e.toString())), }; -SimpleClassBigIntToString _$SimpleClassBigIntToStringFromJson( +SimpleClassOfIntToUri _$SimpleClassOfIntToUriFromJson( Map json) { - return SimpleClassBigIntToString( - (json['value'] as Map)?.map( - (k, e) => MapEntry(BigInt.parse(k), e as String), - ), - (json['nullable'] as Map).map( - (k, e) => MapEntry(BigInt.parse(k), e as String), + return SimpleClassOfIntToUri( + (json['value'] as Map).map( + (k, e) => MapEntry(int.parse(k), Uri.parse(e as String)), ), ); } -Map _$SimpleClassBigIntToStringToJson( - SimpleClassBigIntToString instance) => +Map _$SimpleClassOfIntToUriToJson( + SimpleClassOfIntToUri instance) => { - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - 'nullable': instance.nullable.map((k, e) => MapEntry(k.toString(), e)), + 'value': + instance.value.map((k, e) => MapEntry(k.toString(), e.toString())), }; -SimpleClassDateTimeToString _$SimpleClassDateTimeToStringFromJson( +SimpleClassNullableOfIntToUri _$SimpleClassNullableOfIntToUriFromJson( Map json) { - return SimpleClassDateTimeToString( - (json['value'] as Map)?.map( - (k, e) => MapEntry(DateTime.parse(k), e as String), - ), - (json['nullable'] as Map).map( - (k, e) => MapEntry(DateTime.parse(k), e as String), + return SimpleClassNullableOfIntToUri( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(int.parse(k), Uri.parse(e as String)), ), ); } -Map _$SimpleClassDateTimeToStringToJson( - SimpleClassDateTimeToString instance) => +Map _$SimpleClassNullableOfIntToUriToJson( + SimpleClassNullableOfIntToUri instance) => { - 'value': instance.value?.map((k, e) => MapEntry(k.toIso8601String(), e)), - 'nullable': - instance.nullable.map((k, e) => MapEntry(k.toIso8601String(), e)), + 'value': + instance.value?.map((k, e) => MapEntry(k.toString(), e.toString())), }; -SimpleClassDynamicToString _$SimpleClassDynamicToStringFromJson( +SimpleClassOfObjectToUri _$SimpleClassOfObjectToUriFromJson( Map json) { - return SimpleClassDynamicToString( - (json['value'] as Map)?.map( - (k, e) => MapEntry(k, e as String), + return SimpleClassOfObjectToUri( + (json['value'] as Map).map( + (k, e) => MapEntry(k, Uri.parse(e as String)), ), - Map.from(json['nullable'] as Map), ); } -Map _$SimpleClassDynamicToStringToJson( - SimpleClassDynamicToString instance) => +Map _$SimpleClassOfObjectToUriToJson( + SimpleClassOfObjectToUri instance) => { - 'value': instance.value, - 'nullable': instance.nullable, + 'value': instance.value.map((k, e) => MapEntry(k, e.toString())), }; -SimpleClassEnumTypeToString _$SimpleClassEnumTypeToStringFromJson( +SimpleClassNullableOfObjectToUri _$SimpleClassNullableOfObjectToUriFromJson( Map json) { - return SimpleClassEnumTypeToString( - (json['value'] as Map)?.map( - (k, e) => - MapEntry(_$enumDecodeNullable(_$EnumTypeEnumMap, k), e as String), - ), - (json['nullable'] as Map).map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as String), + return SimpleClassNullableOfObjectToUri( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, Uri.parse(e as String)), ), ); } -Map _$SimpleClassEnumTypeToStringToJson( - SimpleClassEnumTypeToString instance) => +Map _$SimpleClassNullableOfObjectToUriToJson( + SimpleClassNullableOfObjectToUri instance) => { - 'value': instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), - 'nullable': - instance.nullable.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), + 'value': instance.value?.map((k, e) => MapEntry(k, e.toString())), }; -SimpleClassIntToString _$SimpleClassIntToStringFromJson( +SimpleClassOfStringToUri _$SimpleClassOfStringToUriFromJson( Map json) { - return SimpleClassIntToString( - (json['value'] as Map)?.map( - (k, e) => MapEntry(int.parse(k), e as String), - ), - (json['nullable'] as Map).map( - (k, e) => MapEntry(int.parse(k), e as String), + return SimpleClassOfStringToUri( + (json['value'] as Map).map( + (k, e) => MapEntry(k, Uri.parse(e as String)), ), ); } -Map _$SimpleClassIntToStringToJson( - SimpleClassIntToString instance) => +Map _$SimpleClassOfStringToUriToJson( + SimpleClassOfStringToUri instance) => { - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - 'nullable': instance.nullable.map((k, e) => MapEntry(k.toString(), e)), + 'value': instance.value.map((k, e) => MapEntry(k, e.toString())), }; -SimpleClassObjectToString _$SimpleClassObjectToStringFromJson( +SimpleClassNullableOfStringToUri _$SimpleClassNullableOfStringToUriFromJson( Map json) { - return SimpleClassObjectToString( - (json['value'] as Map)?.map( - (k, e) => MapEntry(k, e as String), + return SimpleClassNullableOfStringToUri( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, Uri.parse(e as String)), ), - Map.from(json['nullable'] as Map), ); } -Map _$SimpleClassObjectToStringToJson( - SimpleClassObjectToString instance) => +Map _$SimpleClassNullableOfStringToUriToJson( + SimpleClassNullableOfStringToUri instance) => { - 'value': instance.value, - 'nullable': instance.nullable, + 'value': instance.value?.map((k, e) => MapEntry(k, e.toString())), }; -SimpleClassStringToString _$SimpleClassStringToStringFromJson( +SimpleClassOfUriToUri _$SimpleClassOfUriToUriFromJson( Map json) { - return SimpleClassStringToString( - (json['value'] as Map)?.map( - (k, e) => MapEntry(k, e as String), + return SimpleClassOfUriToUri( + (json['value'] as Map).map( + (k, e) => MapEntry(Uri.parse(k), Uri.parse(e as String)), ), - Map.from(json['nullable'] as Map), ); } -Map _$SimpleClassStringToStringToJson( - SimpleClassStringToString instance) => +Map _$SimpleClassOfUriToUriToJson( + SimpleClassOfUriToUri instance) => { - 'value': instance.value, - 'nullable': instance.nullable, + 'value': + instance.value.map((k, e) => MapEntry(k.toString(), e.toString())), }; -SimpleClassUriToString _$SimpleClassUriToStringFromJson( +SimpleClassNullableOfUriToUri _$SimpleClassNullableOfUriToUriFromJson( Map json) { - return SimpleClassUriToString( - (json['value'] as Map)?.map( - (k, e) => MapEntry(Uri.parse(k), e as String), - ), - (json['nullable'] as Map).map( - (k, e) => MapEntry(Uri.parse(k), e as String), + return SimpleClassNullableOfUriToUri( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(Uri.parse(k), Uri.parse(e as String)), ), ); } -Map _$SimpleClassUriToStringToJson( - SimpleClassUriToString instance) => +Map _$SimpleClassNullableOfUriToUriToJson( + SimpleClassNullableOfUriToUri instance) => { - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - 'nullable': instance.nullable.map((k, e) => MapEntry(k.toString(), e)), + 'value': + instance.value?.map((k, e) => MapEntry(k.toString(), e.toString())), }; -SimpleClassBigIntToUri _$SimpleClassBigIntToUriFromJson( +SimpleClassOfBigIntToUriNullable _$SimpleClassOfBigIntToUriNullableFromJson( Map json) { - return SimpleClassBigIntToUri( - (json['value'] as Map)?.map( + return SimpleClassOfBigIntToUriNullable( + (json['value'] as Map).map( (k, e) => MapEntry(BigInt.parse(k), e == null ? null : Uri.parse(e as String)), ), - (json['nullable'] as Map).map( - (k, e) => MapEntry(BigInt.parse(k), Uri.parse(e as String)), + ); +} + +Map _$SimpleClassOfBigIntToUriNullableToJson( + SimpleClassOfBigIntToUriNullable instance) => + { + 'value': + instance.value.map((k, e) => MapEntry(k.toString(), e?.toString())), + }; + +SimpleClassNullableOfBigIntToUriNullable + _$SimpleClassNullableOfBigIntToUriNullableFromJson( + Map json) { + return SimpleClassNullableOfBigIntToUriNullable( + (json['value'] as Map?)?.map( + (k, e) => + MapEntry(BigInt.parse(k), e == null ? null : Uri.parse(e as String)), ), ); } -Map _$SimpleClassBigIntToUriToJson( - SimpleClassBigIntToUri instance) => +Map _$SimpleClassNullableOfBigIntToUriNullableToJson( + SimpleClassNullableOfBigIntToUriNullable instance) => { 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e?.toString())), - 'nullable': - instance.nullable.map((k, e) => MapEntry(k.toString(), e.toString())), }; -SimpleClassDateTimeToUri _$SimpleClassDateTimeToUriFromJson( +SimpleClassOfDateTimeToUriNullable _$SimpleClassOfDateTimeToUriNullableFromJson( Map json) { - return SimpleClassDateTimeToUri( - (json['value'] as Map)?.map( + return SimpleClassOfDateTimeToUriNullable( + (json['value'] as Map).map( (k, e) => MapEntry( DateTime.parse(k), e == null ? null : Uri.parse(e as String)), ), - (json['nullable'] as Map).map( - (k, e) => MapEntry(DateTime.parse(k), Uri.parse(e as String)), + ); +} + +Map _$SimpleClassOfDateTimeToUriNullableToJson( + SimpleClassOfDateTimeToUriNullable instance) => + { + 'value': instance.value + .map((k, e) => MapEntry(k.toIso8601String(), e?.toString())), + }; + +SimpleClassNullableOfDateTimeToUriNullable + _$SimpleClassNullableOfDateTimeToUriNullableFromJson( + Map json) { + return SimpleClassNullableOfDateTimeToUriNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry( + DateTime.parse(k), e == null ? null : Uri.parse(e as String)), ), ); } -Map _$SimpleClassDateTimeToUriToJson( - SimpleClassDateTimeToUri instance) => +Map _$SimpleClassNullableOfDateTimeToUriNullableToJson( + SimpleClassNullableOfDateTimeToUriNullable instance) => { 'value': instance.value ?.map((k, e) => MapEntry(k.toIso8601String(), e?.toString())), - 'nullable': instance.nullable - .map((k, e) => MapEntry(k.toIso8601String(), e.toString())), }; -SimpleClassDynamicToUri _$SimpleClassDynamicToUriFromJson( +SimpleClassOfDynamicToUriNullable _$SimpleClassOfDynamicToUriNullableFromJson( Map json) { - return SimpleClassDynamicToUri( - (json['value'] as Map)?.map( + return SimpleClassOfDynamicToUriNullable( + (json['value'] as Map).map( (k, e) => MapEntry(k, e == null ? null : Uri.parse(e as String)), ), - (json['nullable'] as Map).map( - (k, e) => MapEntry(k, Uri.parse(e as String)), + ); +} + +Map _$SimpleClassOfDynamicToUriNullableToJson( + SimpleClassOfDynamicToUriNullable instance) => + { + 'value': instance.value.map((k, e) => MapEntry(k, e?.toString())), + }; + +SimpleClassNullableOfDynamicToUriNullable + _$SimpleClassNullableOfDynamicToUriNullableFromJson( + Map json) { + return SimpleClassNullableOfDynamicToUriNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e == null ? null : Uri.parse(e as String)), ), ); } -Map _$SimpleClassDynamicToUriToJson( - SimpleClassDynamicToUri instance) => +Map _$SimpleClassNullableOfDynamicToUriNullableToJson( + SimpleClassNullableOfDynamicToUriNullable instance) => { 'value': instance.value?.map((k, e) => MapEntry(k, e?.toString())), - 'nullable': instance.nullable.map((k, e) => MapEntry(k, e.toString())), }; -SimpleClassEnumTypeToUri _$SimpleClassEnumTypeToUriFromJson( +SimpleClassOfEnumTypeToUriNullable _$SimpleClassOfEnumTypeToUriNullableFromJson( Map json) { - return SimpleClassEnumTypeToUri( - (json['value'] as Map)?.map( - (k, e) => MapEntry(_$enumDecodeNullable(_$EnumTypeEnumMap, k), + return SimpleClassOfEnumTypeToUriNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e == null ? null : Uri.parse(e as String)), ), - (json['nullable'] as Map).map( - (k, e) => - MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), Uri.parse(e as String)), + ); +} + +Map _$SimpleClassOfEnumTypeToUriNullableToJson( + SimpleClassOfEnumTypeToUriNullable instance) => + { + 'value': instance.value + .map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e?.toString())), + }; + +SimpleClassNullableOfEnumTypeToUriNullable + _$SimpleClassNullableOfEnumTypeToUriNullableFromJson( + Map json) { + return SimpleClassNullableOfEnumTypeToUriNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), + e == null ? null : Uri.parse(e as String)), ), ); } -Map _$SimpleClassEnumTypeToUriToJson( - SimpleClassEnumTypeToUri instance) => +Map _$SimpleClassNullableOfEnumTypeToUriNullableToJson( + SimpleClassNullableOfEnumTypeToUriNullable instance) => { 'value': instance.value ?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e?.toString())), - 'nullable': instance.nullable - .map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e.toString())), }; -SimpleClassIntToUri _$SimpleClassIntToUriFromJson(Map json) { - return SimpleClassIntToUri( - (json['value'] as Map)?.map( +SimpleClassOfIntToUriNullable _$SimpleClassOfIntToUriNullableFromJson( + Map json) { + return SimpleClassOfIntToUriNullable( + (json['value'] as Map).map( (k, e) => MapEntry(int.parse(k), e == null ? null : Uri.parse(e as String)), ), - (json['nullable'] as Map).map( - (k, e) => MapEntry(int.parse(k), Uri.parse(e as String)), + ); +} + +Map _$SimpleClassOfIntToUriNullableToJson( + SimpleClassOfIntToUriNullable instance) => + { + 'value': + instance.value.map((k, e) => MapEntry(k.toString(), e?.toString())), + }; + +SimpleClassNullableOfIntToUriNullable + _$SimpleClassNullableOfIntToUriNullableFromJson(Map json) { + return SimpleClassNullableOfIntToUriNullable( + (json['value'] as Map?)?.map( + (k, e) => + MapEntry(int.parse(k), e == null ? null : Uri.parse(e as String)), ), ); } -Map _$SimpleClassIntToUriToJson( - SimpleClassIntToUri instance) => +Map _$SimpleClassNullableOfIntToUriNullableToJson( + SimpleClassNullableOfIntToUriNullable instance) => { 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e?.toString())), - 'nullable': - instance.nullable.map((k, e) => MapEntry(k.toString(), e.toString())), }; -SimpleClassObjectToUri _$SimpleClassObjectToUriFromJson( +SimpleClassOfObjectToUriNullable _$SimpleClassOfObjectToUriNullableFromJson( Map json) { - return SimpleClassObjectToUri( - (json['value'] as Map)?.map( + return SimpleClassOfObjectToUriNullable( + (json['value'] as Map).map( (k, e) => MapEntry(k, e == null ? null : Uri.parse(e as String)), ), - (json['nullable'] as Map).map( - (k, e) => MapEntry(k, Uri.parse(e as String)), + ); +} + +Map _$SimpleClassOfObjectToUriNullableToJson( + SimpleClassOfObjectToUriNullable instance) => + { + 'value': instance.value.map((k, e) => MapEntry(k, e?.toString())), + }; + +SimpleClassNullableOfObjectToUriNullable + _$SimpleClassNullableOfObjectToUriNullableFromJson( + Map json) { + return SimpleClassNullableOfObjectToUriNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e == null ? null : Uri.parse(e as String)), ), ); } -Map _$SimpleClassObjectToUriToJson( - SimpleClassObjectToUri instance) => +Map _$SimpleClassNullableOfObjectToUriNullableToJson( + SimpleClassNullableOfObjectToUriNullable instance) => { 'value': instance.value?.map((k, e) => MapEntry(k, e?.toString())), - 'nullable': instance.nullable.map((k, e) => MapEntry(k, e.toString())), }; -SimpleClassStringToUri _$SimpleClassStringToUriFromJson( +SimpleClassOfStringToUriNullable _$SimpleClassOfStringToUriNullableFromJson( Map json) { - return SimpleClassStringToUri( - (json['value'] as Map)?.map( + return SimpleClassOfStringToUriNullable( + (json['value'] as Map).map( (k, e) => MapEntry(k, e == null ? null : Uri.parse(e as String)), ), - (json['nullable'] as Map).map( - (k, e) => MapEntry(k, Uri.parse(e as String)), + ); +} + +Map _$SimpleClassOfStringToUriNullableToJson( + SimpleClassOfStringToUriNullable instance) => + { + 'value': instance.value.map((k, e) => MapEntry(k, e?.toString())), + }; + +SimpleClassNullableOfStringToUriNullable + _$SimpleClassNullableOfStringToUriNullableFromJson( + Map json) { + return SimpleClassNullableOfStringToUriNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e == null ? null : Uri.parse(e as String)), ), ); } -Map _$SimpleClassStringToUriToJson( - SimpleClassStringToUri instance) => +Map _$SimpleClassNullableOfStringToUriNullableToJson( + SimpleClassNullableOfStringToUriNullable instance) => { 'value': instance.value?.map((k, e) => MapEntry(k, e?.toString())), - 'nullable': instance.nullable.map((k, e) => MapEntry(k, e.toString())), }; -SimpleClassUriToUri _$SimpleClassUriToUriFromJson(Map json) { - return SimpleClassUriToUri( - (json['value'] as Map)?.map( +SimpleClassOfUriToUriNullable _$SimpleClassOfUriToUriNullableFromJson( + Map json) { + return SimpleClassOfUriToUriNullable( + (json['value'] as Map).map( (k, e) => MapEntry(Uri.parse(k), e == null ? null : Uri.parse(e as String)), ), - (json['nullable'] as Map).map( - (k, e) => MapEntry(Uri.parse(k), Uri.parse(e as String)), + ); +} + +Map _$SimpleClassOfUriToUriNullableToJson( + SimpleClassOfUriToUriNullable instance) => + { + 'value': + instance.value.map((k, e) => MapEntry(k.toString(), e?.toString())), + }; + +SimpleClassNullableOfUriToUriNullable + _$SimpleClassNullableOfUriToUriNullableFromJson(Map json) { + return SimpleClassNullableOfUriToUriNullable( + (json['value'] as Map?)?.map( + (k, e) => + MapEntry(Uri.parse(k), e == null ? null : Uri.parse(e as String)), ), ); } -Map _$SimpleClassUriToUriToJson( - SimpleClassUriToUri instance) => +Map _$SimpleClassNullableOfUriToUriNullableToJson( + SimpleClassNullableOfUriToUriNullable instance) => { 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e?.toString())), - 'nullable': - instance.nullable.map((k, e) => MapEntry(k.toString(), e.toString())), }; diff --git a/json_serializable/test/supported_types/input.type_num.dart b/json_serializable/test/supported_types/input.type_num.dart index 587656485..5e9657066 100644 --- a/json_serializable/test/supported_types/input.type_num.dart +++ b/json_serializable/test/supported_types/input.type_num.dart @@ -2,6 +2,8 @@ // 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. +// @dart=2.12 + import 'package:json_annotation/json_annotation.dart'; part 'input.type_num.g.dart'; @@ -10,19 +12,34 @@ part 'input.type_num.g.dart'; class SimpleClass { final num value; - @JsonKey(nullable: false) - final num nullable; - @JsonKey(defaultValue: 88.6) num withDefault; SimpleClass( this.value, - this.nullable, + this.withDefault, ); - factory SimpleClass.fromJson(Map json) => + factory SimpleClass.fromJson(Map json) => _$SimpleClassFromJson(json); - Map toJson() => _$SimpleClassToJson(this); + Map toJson() => _$SimpleClassToJson(this); +} + +@JsonSerializable() +class SimpleClassNullable { + final num? value; + + @JsonKey(defaultValue: 88.6) + num? withDefault; + + SimpleClassNullable( + this.value, + this.withDefault, + ); + + factory SimpleClassNullable.fromJson(Map json) => + _$SimpleClassNullableFromJson(json); + + Map toJson() => _$SimpleClassNullableToJson(this); } diff --git a/json_serializable/test/supported_types/input.type_num.g.dart b/json_serializable/test/supported_types/input.type_num.g.dart index ddca5a84a..d91fb9d68 100644 --- a/json_serializable/test/supported_types/input.type_num.g.dart +++ b/json_serializable/test/supported_types/input.type_num.g.dart @@ -1,4 +1,5 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// @dart=2.12 part of 'input.type_num.dart'; @@ -9,13 +10,26 @@ part of 'input.type_num.dart'; SimpleClass _$SimpleClassFromJson(Map json) { return SimpleClass( json['value'] as num, - json['nullable'] as num, - )..withDefault = json['withDefault'] as num ?? 88.6; + json['withDefault'] as num? ?? 88.6, + ); } Map _$SimpleClassToJson(SimpleClass instance) => { 'value': instance.value, - 'nullable': instance.nullable, + 'withDefault': instance.withDefault, + }; + +SimpleClassNullable _$SimpleClassNullableFromJson(Map json) { + return SimpleClassNullable( + json['value'] as num?, + json['withDefault'] as num? ?? 88.6, + ); +} + +Map _$SimpleClassNullableToJson( + SimpleClassNullable instance) => + { + 'value': instance.value, 'withDefault': instance.withDefault, }; diff --git a/json_serializable/test/supported_types/input.type_object.dart b/json_serializable/test/supported_types/input.type_object.dart index 06bba9e4b..fb0c2e860 100644 --- a/json_serializable/test/supported_types/input.type_object.dart +++ b/json_serializable/test/supported_types/input.type_object.dart @@ -2,6 +2,8 @@ // 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. +// @dart=2.12 + import 'package:json_annotation/json_annotation.dart'; part 'input.type_object.g.dart'; @@ -10,16 +12,34 @@ part 'input.type_object.g.dart'; class SimpleClass { final Object value; - @JsonKey(nullable: false) - final Object nullable; + @JsonKey(defaultValue: 'o1') + Object withDefault; SimpleClass( this.value, - this.nullable, + this.withDefault, ); - factory SimpleClass.fromJson(Map json) => + factory SimpleClass.fromJson(Map json) => _$SimpleClassFromJson(json); - Map toJson() => _$SimpleClassToJson(this); + Map toJson() => _$SimpleClassToJson(this); +} + +@JsonSerializable() +class SimpleClassNullable { + final Object? value; + + @JsonKey(defaultValue: 'o1') + Object? withDefault; + + SimpleClassNullable( + this.value, + this.withDefault, + ); + + factory SimpleClassNullable.fromJson(Map json) => + _$SimpleClassNullableFromJson(json); + + Map toJson() => _$SimpleClassNullableToJson(this); } diff --git a/json_serializable/test/supported_types/input.type_object.g.dart b/json_serializable/test/supported_types/input.type_object.g.dart index e2dafc620..973229f41 100644 --- a/json_serializable/test/supported_types/input.type_object.g.dart +++ b/json_serializable/test/supported_types/input.type_object.g.dart @@ -1,4 +1,5 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// @dart=2.12 part of 'input.type_object.dart'; @@ -8,13 +9,27 @@ part of 'input.type_object.dart'; SimpleClass _$SimpleClassFromJson(Map json) { return SimpleClass( - json['value'], - json['nullable'], + json['value'] as Object, + json['withDefault'] as Object? ?? 'o1', ); } Map _$SimpleClassToJson(SimpleClass instance) => { 'value': instance.value, - 'nullable': instance.nullable, + 'withDefault': instance.withDefault, + }; + +SimpleClassNullable _$SimpleClassNullableFromJson(Map json) { + return SimpleClassNullable( + json['value'], + json['withDefault'] ?? 'o1', + ); +} + +Map _$SimpleClassNullableToJson( + SimpleClassNullable instance) => + { + 'value': instance.value, + 'withDefault': instance.withDefault, }; diff --git a/json_serializable/test/supported_types/input.type_set.dart b/json_serializable/test/supported_types/input.type_set.dart index 395345e2c..ea7eacd67 100644 --- a/json_serializable/test/supported_types/input.type_set.dart +++ b/json_serializable/test/supported_types/input.type_set.dart @@ -2,6 +2,8 @@ // 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. +// @dart=2.12 + import 'package:json_annotation/json_annotation.dart'; import 'enum_type.dart'; @@ -11,235 +13,700 @@ part 'input.type_set.g.dart'; class SimpleClass { final Set value; - @JsonKey(nullable: false) - final Set nullable; - @JsonKey(defaultValue: {42, true, false, null}) Set withDefault; SimpleClass( this.value, - this.nullable, + this.withDefault, ); - factory SimpleClass.fromJson(Map json) => + factory SimpleClass.fromJson(Map json) => _$SimpleClassFromJson(json); - Map toJson() => _$SimpleClassToJson(this); + Map toJson() => _$SimpleClassToJson(this); } @JsonSerializable() -class SimpleClassBigInt { +class SimpleClassNullable { + final Set? value; + + @JsonKey(defaultValue: {42, true, false, null}) + Set? withDefault; + + SimpleClassNullable( + this.value, + this.withDefault, + ); + + factory SimpleClassNullable.fromJson(Map json) => + _$SimpleClassNullableFromJson(json); + + Map toJson() => _$SimpleClassNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfBigInt { final Set value; - @JsonKey(nullable: false) - final Set nullable; + SimpleClassOfBigInt( + this.value, + ); + + factory SimpleClassOfBigInt.fromJson(Map json) => + _$SimpleClassOfBigIntFromJson(json); + + Map toJson() => _$SimpleClassOfBigIntToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfBigInt { + final Set? value; + + SimpleClassNullableOfBigInt( + this.value, + ); + + factory SimpleClassNullableOfBigInt.fromJson(Map json) => + _$SimpleClassNullableOfBigIntFromJson(json); + + Map toJson() => _$SimpleClassNullableOfBigIntToJson(this); +} + +@JsonSerializable() +class SimpleClassOfBigIntNullable { + final Set value; + + SimpleClassOfBigIntNullable( + this.value, + ); + + factory SimpleClassOfBigIntNullable.fromJson(Map json) => + _$SimpleClassOfBigIntNullableFromJson(json); + + Map toJson() => _$SimpleClassOfBigIntNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfBigIntNullable { + final Set? value; - SimpleClassBigInt( + SimpleClassNullableOfBigIntNullable( this.value, - this.nullable, ); - factory SimpleClassBigInt.fromJson(Map json) => - _$SimpleClassBigIntFromJson(json); + factory SimpleClassNullableOfBigIntNullable.fromJson( + Map json) => + _$SimpleClassNullableOfBigIntNullableFromJson(json); - Map toJson() => _$SimpleClassBigIntToJson(this); + Map toJson() => + _$SimpleClassNullableOfBigIntNullableToJson(this); } @JsonSerializable() -class SimpleClassBool { +class SimpleClassOfBool { final Set value; - @JsonKey(nullable: false) - final Set nullable; + SimpleClassOfBool( + this.value, + ); + + factory SimpleClassOfBool.fromJson(Map json) => + _$SimpleClassOfBoolFromJson(json); + + Map toJson() => _$SimpleClassOfBoolToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfBool { + final Set? value; + + SimpleClassNullableOfBool( + this.value, + ); + + factory SimpleClassNullableOfBool.fromJson(Map json) => + _$SimpleClassNullableOfBoolFromJson(json); + + Map toJson() => _$SimpleClassNullableOfBoolToJson(this); +} + +@JsonSerializable() +class SimpleClassOfBoolNullable { + final Set value; + + SimpleClassOfBoolNullable( + this.value, + ); + + factory SimpleClassOfBoolNullable.fromJson(Map json) => + _$SimpleClassOfBoolNullableFromJson(json); + + Map toJson() => _$SimpleClassOfBoolNullableToJson(this); +} - SimpleClassBool( +@JsonSerializable() +class SimpleClassNullableOfBoolNullable { + final Set? value; + + SimpleClassNullableOfBoolNullable( this.value, - this.nullable, ); - factory SimpleClassBool.fromJson(Map json) => - _$SimpleClassBoolFromJson(json); + factory SimpleClassNullableOfBoolNullable.fromJson( + Map json) => + _$SimpleClassNullableOfBoolNullableFromJson(json); - Map toJson() => _$SimpleClassBoolToJson(this); + Map toJson() => + _$SimpleClassNullableOfBoolNullableToJson(this); } @JsonSerializable() -class SimpleClassDateTime { +class SimpleClassOfDateTime { final Set value; - @JsonKey(nullable: false) - final Set nullable; + SimpleClassOfDateTime( + this.value, + ); + + factory SimpleClassOfDateTime.fromJson(Map json) => + _$SimpleClassOfDateTimeFromJson(json); + + Map toJson() => _$SimpleClassOfDateTimeToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfDateTime { + final Set? value; + + SimpleClassNullableOfDateTime( + this.value, + ); + + factory SimpleClassNullableOfDateTime.fromJson(Map json) => + _$SimpleClassNullableOfDateTimeFromJson(json); + + Map toJson() => _$SimpleClassNullableOfDateTimeToJson(this); +} + +@JsonSerializable() +class SimpleClassOfDateTimeNullable { + final Set value; - SimpleClassDateTime( + SimpleClassOfDateTimeNullable( this.value, - this.nullable, ); - factory SimpleClassDateTime.fromJson(Map json) => - _$SimpleClassDateTimeFromJson(json); + factory SimpleClassOfDateTimeNullable.fromJson(Map json) => + _$SimpleClassOfDateTimeNullableFromJson(json); - Map toJson() => _$SimpleClassDateTimeToJson(this); + Map toJson() => _$SimpleClassOfDateTimeNullableToJson(this); } @JsonSerializable() -class SimpleClassDouble { +class SimpleClassNullableOfDateTimeNullable { + final Set? value; + + SimpleClassNullableOfDateTimeNullable( + this.value, + ); + + factory SimpleClassNullableOfDateTimeNullable.fromJson( + Map json) => + _$SimpleClassNullableOfDateTimeNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfDateTimeNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfDouble { final Set value; - @JsonKey(nullable: false) - final Set nullable; + SimpleClassOfDouble( + this.value, + ); + + factory SimpleClassOfDouble.fromJson(Map json) => + _$SimpleClassOfDoubleFromJson(json); + + Map toJson() => _$SimpleClassOfDoubleToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfDouble { + final Set? value; + + SimpleClassNullableOfDouble( + this.value, + ); + + factory SimpleClassNullableOfDouble.fromJson(Map json) => + _$SimpleClassNullableOfDoubleFromJson(json); + + Map toJson() => _$SimpleClassNullableOfDoubleToJson(this); +} + +@JsonSerializable() +class SimpleClassOfDoubleNullable { + final Set value; + + SimpleClassOfDoubleNullable( + this.value, + ); + + factory SimpleClassOfDoubleNullable.fromJson(Map json) => + _$SimpleClassOfDoubleNullableFromJson(json); + + Map toJson() => _$SimpleClassOfDoubleNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfDoubleNullable { + final Set? value; - SimpleClassDouble( + SimpleClassNullableOfDoubleNullable( this.value, - this.nullable, ); - factory SimpleClassDouble.fromJson(Map json) => - _$SimpleClassDoubleFromJson(json); + factory SimpleClassNullableOfDoubleNullable.fromJson( + Map json) => + _$SimpleClassNullableOfDoubleNullableFromJson(json); - Map toJson() => _$SimpleClassDoubleToJson(this); + Map toJson() => + _$SimpleClassNullableOfDoubleNullableToJson(this); } @JsonSerializable() -class SimpleClassDuration { +class SimpleClassOfDuration { final Set value; - @JsonKey(nullable: false) - final Set nullable; + SimpleClassOfDuration( + this.value, + ); + + factory SimpleClassOfDuration.fromJson(Map json) => + _$SimpleClassOfDurationFromJson(json); + + Map toJson() => _$SimpleClassOfDurationToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfDuration { + final Set? value; + + SimpleClassNullableOfDuration( + this.value, + ); + + factory SimpleClassNullableOfDuration.fromJson(Map json) => + _$SimpleClassNullableOfDurationFromJson(json); + + Map toJson() => _$SimpleClassNullableOfDurationToJson(this); +} + +@JsonSerializable() +class SimpleClassOfDurationNullable { + final Set value; + + SimpleClassOfDurationNullable( + this.value, + ); - SimpleClassDuration( + factory SimpleClassOfDurationNullable.fromJson(Map json) => + _$SimpleClassOfDurationNullableFromJson(json); + + Map toJson() => _$SimpleClassOfDurationNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfDurationNullable { + final Set? value; + + SimpleClassNullableOfDurationNullable( this.value, - this.nullable, ); - factory SimpleClassDuration.fromJson(Map json) => - _$SimpleClassDurationFromJson(json); + factory SimpleClassNullableOfDurationNullable.fromJson( + Map json) => + _$SimpleClassNullableOfDurationNullableFromJson(json); - Map toJson() => _$SimpleClassDurationToJson(this); + Map toJson() => + _$SimpleClassNullableOfDurationNullableToJson(this); } @JsonSerializable() -class SimpleClassDynamic { +class SimpleClassOfDynamic { final Set value; - @JsonKey(nullable: false) - final Set nullable; + SimpleClassOfDynamic( + this.value, + ); + + factory SimpleClassOfDynamic.fromJson(Map json) => + _$SimpleClassOfDynamicFromJson(json); + + Map toJson() => _$SimpleClassOfDynamicToJson(this); +} - SimpleClassDynamic( +@JsonSerializable() +class SimpleClassNullableOfDynamic { + final Set? value; + + SimpleClassNullableOfDynamic( this.value, - this.nullable, ); - factory SimpleClassDynamic.fromJson(Map json) => - _$SimpleClassDynamicFromJson(json); + factory SimpleClassNullableOfDynamic.fromJson(Map json) => + _$SimpleClassNullableOfDynamicFromJson(json); - Map toJson() => _$SimpleClassDynamicToJson(this); + Map toJson() => _$SimpleClassNullableOfDynamicToJson(this); } @JsonSerializable() -class SimpleClassEnumType { +class SimpleClassOfEnumType { final Set value; - @JsonKey(nullable: false) - final Set nullable; + SimpleClassOfEnumType( + this.value, + ); + + factory SimpleClassOfEnumType.fromJson(Map json) => + _$SimpleClassOfEnumTypeFromJson(json); + + Map toJson() => _$SimpleClassOfEnumTypeToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfEnumType { + final Set? value; + + SimpleClassNullableOfEnumType( + this.value, + ); + + factory SimpleClassNullableOfEnumType.fromJson(Map json) => + _$SimpleClassNullableOfEnumTypeFromJson(json); + + Map toJson() => _$SimpleClassNullableOfEnumTypeToJson(this); +} + +@JsonSerializable() +class SimpleClassOfEnumTypeNullable { + final Set value; + + SimpleClassOfEnumTypeNullable( + this.value, + ); + + factory SimpleClassOfEnumTypeNullable.fromJson(Map json) => + _$SimpleClassOfEnumTypeNullableFromJson(json); - SimpleClassEnumType( + Map toJson() => _$SimpleClassOfEnumTypeNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfEnumTypeNullable { + final Set? value; + + SimpleClassNullableOfEnumTypeNullable( this.value, - this.nullable, ); - factory SimpleClassEnumType.fromJson(Map json) => - _$SimpleClassEnumTypeFromJson(json); + factory SimpleClassNullableOfEnumTypeNullable.fromJson( + Map json) => + _$SimpleClassNullableOfEnumTypeNullableFromJson(json); - Map toJson() => _$SimpleClassEnumTypeToJson(this); + Map toJson() => + _$SimpleClassNullableOfEnumTypeNullableToJson(this); } @JsonSerializable() -class SimpleClassInt { +class SimpleClassOfInt { final Set value; - @JsonKey(nullable: false) - final Set nullable; + SimpleClassOfInt( + this.value, + ); + + factory SimpleClassOfInt.fromJson(Map json) => + _$SimpleClassOfIntFromJson(json); + + Map toJson() => _$SimpleClassOfIntToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfInt { + final Set? value; + + SimpleClassNullableOfInt( + this.value, + ); + + factory SimpleClassNullableOfInt.fromJson(Map json) => + _$SimpleClassNullableOfIntFromJson(json); + + Map toJson() => _$SimpleClassNullableOfIntToJson(this); +} + +@JsonSerializable() +class SimpleClassOfIntNullable { + final Set value; - SimpleClassInt( + SimpleClassOfIntNullable( this.value, - this.nullable, ); - factory SimpleClassInt.fromJson(Map json) => - _$SimpleClassIntFromJson(json); + factory SimpleClassOfIntNullable.fromJson(Map json) => + _$SimpleClassOfIntNullableFromJson(json); - Map toJson() => _$SimpleClassIntToJson(this); + Map toJson() => _$SimpleClassOfIntNullableToJson(this); } @JsonSerializable() -class SimpleClassNum { +class SimpleClassNullableOfIntNullable { + final Set? value; + + SimpleClassNullableOfIntNullable( + this.value, + ); + + factory SimpleClassNullableOfIntNullable.fromJson( + Map json) => + _$SimpleClassNullableOfIntNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfIntNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfNum { final Set value; - @JsonKey(nullable: false) - final Set nullable; + SimpleClassOfNum( + this.value, + ); + + factory SimpleClassOfNum.fromJson(Map json) => + _$SimpleClassOfNumFromJson(json); + + Map toJson() => _$SimpleClassOfNumToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfNum { + final Set? value; + + SimpleClassNullableOfNum( + this.value, + ); - SimpleClassNum( + factory SimpleClassNullableOfNum.fromJson(Map json) => + _$SimpleClassNullableOfNumFromJson(json); + + Map toJson() => _$SimpleClassNullableOfNumToJson(this); +} + +@JsonSerializable() +class SimpleClassOfNumNullable { + final Set value; + + SimpleClassOfNumNullable( this.value, - this.nullable, ); - factory SimpleClassNum.fromJson(Map json) => - _$SimpleClassNumFromJson(json); + factory SimpleClassOfNumNullable.fromJson(Map json) => + _$SimpleClassOfNumNullableFromJson(json); - Map toJson() => _$SimpleClassNumToJson(this); + Map toJson() => _$SimpleClassOfNumNullableToJson(this); } @JsonSerializable() -class SimpleClassObject { +class SimpleClassNullableOfNumNullable { + final Set? value; + + SimpleClassNullableOfNumNullable( + this.value, + ); + + factory SimpleClassNullableOfNumNullable.fromJson( + Map json) => + _$SimpleClassNullableOfNumNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfNumNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfObject { final Set value; - @JsonKey(nullable: false) - final Set nullable; + SimpleClassOfObject( + this.value, + ); + + factory SimpleClassOfObject.fromJson(Map json) => + _$SimpleClassOfObjectFromJson(json); + + Map toJson() => _$SimpleClassOfObjectToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfObject { + final Set? value; + + SimpleClassNullableOfObject( + this.value, + ); + + factory SimpleClassNullableOfObject.fromJson(Map json) => + _$SimpleClassNullableOfObjectFromJson(json); + + Map toJson() => _$SimpleClassNullableOfObjectToJson(this); +} + +@JsonSerializable() +class SimpleClassOfObjectNullable { + final Set value; + + SimpleClassOfObjectNullable( + this.value, + ); + + factory SimpleClassOfObjectNullable.fromJson(Map json) => + _$SimpleClassOfObjectNullableFromJson(json); + + Map toJson() => _$SimpleClassOfObjectNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfObjectNullable { + final Set? value; - SimpleClassObject( + SimpleClassNullableOfObjectNullable( this.value, - this.nullable, ); - factory SimpleClassObject.fromJson(Map json) => - _$SimpleClassObjectFromJson(json); + factory SimpleClassNullableOfObjectNullable.fromJson( + Map json) => + _$SimpleClassNullableOfObjectNullableFromJson(json); - Map toJson() => _$SimpleClassObjectToJson(this); + Map toJson() => + _$SimpleClassNullableOfObjectNullableToJson(this); } @JsonSerializable() -class SimpleClassString { +class SimpleClassOfString { final Set value; - @JsonKey(nullable: false) - final Set nullable; + SimpleClassOfString( + this.value, + ); + + factory SimpleClassOfString.fromJson(Map json) => + _$SimpleClassOfStringFromJson(json); + + Map toJson() => _$SimpleClassOfStringToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfString { + final Set? value; + + SimpleClassNullableOfString( + this.value, + ); + + factory SimpleClassNullableOfString.fromJson(Map json) => + _$SimpleClassNullableOfStringFromJson(json); + + Map toJson() => _$SimpleClassNullableOfStringToJson(this); +} + +@JsonSerializable() +class SimpleClassOfStringNullable { + final Set value; - SimpleClassString( + SimpleClassOfStringNullable( this.value, - this.nullable, ); - factory SimpleClassString.fromJson(Map json) => - _$SimpleClassStringFromJson(json); + factory SimpleClassOfStringNullable.fromJson(Map json) => + _$SimpleClassOfStringNullableFromJson(json); - Map toJson() => _$SimpleClassStringToJson(this); + Map toJson() => _$SimpleClassOfStringNullableToJson(this); } @JsonSerializable() -class SimpleClassUri { +class SimpleClassNullableOfStringNullable { + final Set? value; + + SimpleClassNullableOfStringNullable( + this.value, + ); + + factory SimpleClassNullableOfStringNullable.fromJson( + Map json) => + _$SimpleClassNullableOfStringNullableFromJson(json); + + Map toJson() => + _$SimpleClassNullableOfStringNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassOfUri { final Set value; - @JsonKey(nullable: false) - final Set nullable; + SimpleClassOfUri( + this.value, + ); + + factory SimpleClassOfUri.fromJson(Map json) => + _$SimpleClassOfUriFromJson(json); + + Map toJson() => _$SimpleClassOfUriToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfUri { + final Set? value; + + SimpleClassNullableOfUri( + this.value, + ); + + factory SimpleClassNullableOfUri.fromJson(Map json) => + _$SimpleClassNullableOfUriFromJson(json); + + Map toJson() => _$SimpleClassNullableOfUriToJson(this); +} + +@JsonSerializable() +class SimpleClassOfUriNullable { + final Set value; + + SimpleClassOfUriNullable( + this.value, + ); + + factory SimpleClassOfUriNullable.fromJson(Map json) => + _$SimpleClassOfUriNullableFromJson(json); + + Map toJson() => _$SimpleClassOfUriNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfUriNullable { + final Set? value; - SimpleClassUri( + SimpleClassNullableOfUriNullable( this.value, - this.nullable, ); - factory SimpleClassUri.fromJson(Map json) => - _$SimpleClassUriFromJson(json); + factory SimpleClassNullableOfUriNullable.fromJson( + Map json) => + _$SimpleClassNullableOfUriNullableFromJson(json); - Map toJson() => _$SimpleClassUriToJson(this); + Map toJson() => + _$SimpleClassNullableOfUriNullableToJson(this); } diff --git a/json_serializable/test/supported_types/input.type_set.g.dart b/json_serializable/test/supported_types/input.type_set.g.dart index 3958ec345..43bf51e4a 100644 --- a/json_serializable/test/supported_types/input.type_set.g.dart +++ b/json_serializable/test/supported_types/input.type_set.g.dart @@ -1,4 +1,5 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// @dart=2.12 part of 'input.type_set.dart'; @@ -8,227 +9,700 @@ part of 'input.type_set.dart'; SimpleClass _$SimpleClassFromJson(Map json) { return SimpleClass( - (json['value'] as List)?.toSet(), - (json['nullable'] as List).toSet(), - )..withDefault = - (json['withDefault'] as List)?.toSet() ?? {42, true, false, null}; + (json['value'] as List).toSet(), + (json['withDefault'] as List?)?.toSet() ?? {42, true, false, null}, + ); } Map _$SimpleClassToJson(SimpleClass instance) => + { + 'value': instance.value.toList(), + 'withDefault': instance.withDefault.toList(), + }; + +SimpleClassNullable _$SimpleClassNullableFromJson(Map json) { + return SimpleClassNullable( + (json['value'] as List?)?.toSet(), + (json['withDefault'] as List?)?.toSet() ?? {42, true, false, null}, + ); +} + +Map _$SimpleClassNullableToJson( + SimpleClassNullable instance) => { 'value': instance.value?.toList(), - 'nullable': instance.nullable.toList(), 'withDefault': instance.withDefault?.toList(), }; -SimpleClassBigInt _$SimpleClassBigIntFromJson(Map json) { - return SimpleClassBigInt( - (json['value'] as List) +SimpleClassOfBigInt _$SimpleClassOfBigIntFromJson(Map json) { + return SimpleClassOfBigInt( + (json['value'] as List) + .map((e) => BigInt.parse(e as String)) + .toSet(), + ); +} + +Map _$SimpleClassOfBigIntToJson( + SimpleClassOfBigInt instance) => + { + 'value': instance.value.map((e) => e.toString()).toList(), + }; + +SimpleClassNullableOfBigInt _$SimpleClassNullableOfBigIntFromJson( + Map json) { + return SimpleClassNullableOfBigInt( + (json['value'] as List?) + ?.map((e) => BigInt.parse(e as String)) + .toSet(), + ); +} + +Map _$SimpleClassNullableOfBigIntToJson( + SimpleClassNullableOfBigInt instance) => + { + 'value': instance.value?.map((e) => e.toString()).toList(), + }; + +SimpleClassOfBigIntNullable _$SimpleClassOfBigIntNullableFromJson( + Map json) { + return SimpleClassOfBigIntNullable( + (json['value'] as List) + .map((e) => e == null ? null : BigInt.parse(e as String)) + .toSet(), + ); +} + +Map _$SimpleClassOfBigIntNullableToJson( + SimpleClassOfBigIntNullable instance) => + { + 'value': instance.value.map((e) => e?.toString()).toList(), + }; + +SimpleClassNullableOfBigIntNullable + _$SimpleClassNullableOfBigIntNullableFromJson(Map json) { + return SimpleClassNullableOfBigIntNullable( + (json['value'] as List?) ?.map((e) => e == null ? null : BigInt.parse(e as String)) - ?.toSet(), - (json['nullable'] as List).map((e) => BigInt.parse(e as String)).toSet(), + .toSet(), + ); +} + +Map _$SimpleClassNullableOfBigIntNullableToJson( + SimpleClassNullableOfBigIntNullable instance) => + { + 'value': instance.value?.map((e) => e?.toString()).toList(), + }; + +SimpleClassOfBool _$SimpleClassOfBoolFromJson(Map json) { + return SimpleClassOfBool( + (json['value'] as List).map((e) => e as bool).toSet(), + ); +} + +Map _$SimpleClassOfBoolToJson(SimpleClassOfBool instance) => + { + 'value': instance.value.toList(), + }; + +SimpleClassNullableOfBool _$SimpleClassNullableOfBoolFromJson( + Map json) { + return SimpleClassNullableOfBool( + (json['value'] as List?)?.map((e) => e as bool).toSet(), + ); +} + +Map _$SimpleClassNullableOfBoolToJson( + SimpleClassNullableOfBool instance) => + { + 'value': instance.value?.toList(), + }; + +SimpleClassOfBoolNullable _$SimpleClassOfBoolNullableFromJson( + Map json) { + return SimpleClassOfBoolNullable( + (json['value'] as List).map((e) => e as bool?).toSet(), ); } -Map _$SimpleClassBigIntToJson(SimpleClassBigInt instance) => +Map _$SimpleClassOfBoolNullableToJson( + SimpleClassOfBoolNullable instance) => { - 'value': instance.value?.map((e) => e?.toString())?.toList(), - 'nullable': instance.nullable.map((e) => e.toString()).toList(), + 'value': instance.value.toList(), }; -SimpleClassBool _$SimpleClassBoolFromJson(Map json) { - return SimpleClassBool( - (json['value'] as List)?.map((e) => e as bool)?.toSet(), - (json['nullable'] as List).map((e) => e as bool).toSet(), +SimpleClassNullableOfBoolNullable _$SimpleClassNullableOfBoolNullableFromJson( + Map json) { + return SimpleClassNullableOfBoolNullable( + (json['value'] as List?)?.map((e) => e as bool?).toSet(), ); } -Map _$SimpleClassBoolToJson(SimpleClassBool instance) => +Map _$SimpleClassNullableOfBoolNullableToJson( + SimpleClassNullableOfBoolNullable instance) => { 'value': instance.value?.toList(), - 'nullable': instance.nullable.toList(), }; -SimpleClassDateTime _$SimpleClassDateTimeFromJson(Map json) { - return SimpleClassDateTime( - (json['value'] as List) +SimpleClassOfDateTime _$SimpleClassOfDateTimeFromJson( + Map json) { + return SimpleClassOfDateTime( + (json['value'] as List) + .map((e) => DateTime.parse(e as String)) + .toSet(), + ); +} + +Map _$SimpleClassOfDateTimeToJson( + SimpleClassOfDateTime instance) => + { + 'value': instance.value.map((e) => e.toIso8601String()).toList(), + }; + +SimpleClassNullableOfDateTime _$SimpleClassNullableOfDateTimeFromJson( + Map json) { + return SimpleClassNullableOfDateTime( + (json['value'] as List?) + ?.map((e) => DateTime.parse(e as String)) + .toSet(), + ); +} + +Map _$SimpleClassNullableOfDateTimeToJson( + SimpleClassNullableOfDateTime instance) => + { + 'value': instance.value?.map((e) => e.toIso8601String()).toList(), + }; + +SimpleClassOfDateTimeNullable _$SimpleClassOfDateTimeNullableFromJson( + Map json) { + return SimpleClassOfDateTimeNullable( + (json['value'] as List) + .map((e) => e == null ? null : DateTime.parse(e as String)) + .toSet(), + ); +} + +Map _$SimpleClassOfDateTimeNullableToJson( + SimpleClassOfDateTimeNullable instance) => + { + 'value': instance.value.map((e) => e?.toIso8601String()).toList(), + }; + +SimpleClassNullableOfDateTimeNullable + _$SimpleClassNullableOfDateTimeNullableFromJson(Map json) { + return SimpleClassNullableOfDateTimeNullable( + (json['value'] as List?) ?.map((e) => e == null ? null : DateTime.parse(e as String)) - ?.toSet(), - (json['nullable'] as List).map((e) => DateTime.parse(e as String)).toSet(), + .toSet(), + ); +} + +Map _$SimpleClassNullableOfDateTimeNullableToJson( + SimpleClassNullableOfDateTimeNullable instance) => + { + 'value': instance.value?.map((e) => e?.toIso8601String()).toList(), + }; + +SimpleClassOfDouble _$SimpleClassOfDoubleFromJson(Map json) { + return SimpleClassOfDouble( + (json['value'] as List).map((e) => (e as num).toDouble()).toSet(), ); } -Map _$SimpleClassDateTimeToJson( - SimpleClassDateTime instance) => +Map _$SimpleClassOfDoubleToJson( + SimpleClassOfDouble instance) => { - 'value': instance.value?.map((e) => e?.toIso8601String())?.toList(), - 'nullable': instance.nullable.map((e) => e.toIso8601String()).toList(), + 'value': instance.value.toList(), }; -SimpleClassDouble _$SimpleClassDoubleFromJson(Map json) { - return SimpleClassDouble( - (json['value'] as List)?.map((e) => (e as num)?.toDouble())?.toSet(), - (json['nullable'] as List).map((e) => (e as num).toDouble()).toSet(), +SimpleClassNullableOfDouble _$SimpleClassNullableOfDoubleFromJson( + Map json) { + return SimpleClassNullableOfDouble( + (json['value'] as List?) + ?.map((e) => (e as num).toDouble()) + .toSet(), ); } -Map _$SimpleClassDoubleToJson(SimpleClassDouble instance) => +Map _$SimpleClassNullableOfDoubleToJson( + SimpleClassNullableOfDouble instance) => { 'value': instance.value?.toList(), - 'nullable': instance.nullable.toList(), }; -SimpleClassDuration _$SimpleClassDurationFromJson(Map json) { - return SimpleClassDuration( - (json['value'] as List) - ?.map((e) => e == null ? null : Duration(microseconds: e as int)) - ?.toSet(), - (json['nullable'] as List) +SimpleClassOfDoubleNullable _$SimpleClassOfDoubleNullableFromJson( + Map json) { + return SimpleClassOfDoubleNullable( + (json['value'] as List) + .map((e) => (e as num?)?.toDouble()) + .toSet(), + ); +} + +Map _$SimpleClassOfDoubleNullableToJson( + SimpleClassOfDoubleNullable instance) => + { + 'value': instance.value.toList(), + }; + +SimpleClassNullableOfDoubleNullable + _$SimpleClassNullableOfDoubleNullableFromJson(Map json) { + return SimpleClassNullableOfDoubleNullable( + (json['value'] as List?) + ?.map((e) => (e as num?)?.toDouble()) + .toSet(), + ); +} + +Map _$SimpleClassNullableOfDoubleNullableToJson( + SimpleClassNullableOfDoubleNullable instance) => + { + 'value': instance.value?.toList(), + }; + +SimpleClassOfDuration _$SimpleClassOfDurationFromJson( + Map json) { + return SimpleClassOfDuration( + (json['value'] as List) .map((e) => Duration(microseconds: e as int)) .toSet(), ); } -Map _$SimpleClassDurationToJson( - SimpleClassDuration instance) => +Map _$SimpleClassOfDurationToJson( + SimpleClassOfDuration instance) => { - 'value': instance.value?.map((e) => e?.inMicroseconds)?.toList(), - 'nullable': instance.nullable.map((e) => e.inMicroseconds).toList(), + 'value': instance.value.map((e) => e.inMicroseconds).toList(), }; -SimpleClassDynamic _$SimpleClassDynamicFromJson(Map json) { - return SimpleClassDynamic( - (json['value'] as List)?.toSet(), - (json['nullable'] as List).toSet(), +SimpleClassNullableOfDuration _$SimpleClassNullableOfDurationFromJson( + Map json) { + return SimpleClassNullableOfDuration( + (json['value'] as List?) + ?.map((e) => Duration(microseconds: e as int)) + .toSet(), ); } -Map _$SimpleClassDynamicToJson(SimpleClassDynamic instance) => +Map _$SimpleClassNullableOfDurationToJson( + SimpleClassNullableOfDuration instance) => + { + 'value': instance.value?.map((e) => e.inMicroseconds).toList(), + }; + +SimpleClassOfDurationNullable _$SimpleClassOfDurationNullableFromJson( + Map json) { + return SimpleClassOfDurationNullable( + (json['value'] as List) + .map((e) => e == null ? null : Duration(microseconds: e as int)) + .toSet(), + ); +} + +Map _$SimpleClassOfDurationNullableToJson( + SimpleClassOfDurationNullable instance) => + { + 'value': instance.value.map((e) => e?.inMicroseconds).toList(), + }; + +SimpleClassNullableOfDurationNullable + _$SimpleClassNullableOfDurationNullableFromJson(Map json) { + return SimpleClassNullableOfDurationNullable( + (json['value'] as List?) + ?.map((e) => e == null ? null : Duration(microseconds: e as int)) + .toSet(), + ); +} + +Map _$SimpleClassNullableOfDurationNullableToJson( + SimpleClassNullableOfDurationNullable instance) => + { + 'value': instance.value?.map((e) => e?.inMicroseconds).toList(), + }; + +SimpleClassOfDynamic _$SimpleClassOfDynamicFromJson(Map json) { + return SimpleClassOfDynamic( + (json['value'] as List).toSet(), + ); +} + +Map _$SimpleClassOfDynamicToJson( + SimpleClassOfDynamic instance) => + { + 'value': instance.value.toList(), + }; + +SimpleClassNullableOfDynamic _$SimpleClassNullableOfDynamicFromJson( + Map json) { + return SimpleClassNullableOfDynamic( + (json['value'] as List?)?.toSet(), + ); +} + +Map _$SimpleClassNullableOfDynamicToJson( + SimpleClassNullableOfDynamic instance) => { 'value': instance.value?.toList(), - 'nullable': instance.nullable.toList(), }; -SimpleClassEnumType _$SimpleClassEnumTypeFromJson(Map json) { - return SimpleClassEnumType( - (json['value'] as List) - ?.map((e) => _$enumDecodeNullable(_$EnumTypeEnumMap, e)) - ?.toSet(), - (json['nullable'] as List) +SimpleClassOfEnumType _$SimpleClassOfEnumTypeFromJson( + Map json) { + return SimpleClassOfEnumType( + (json['value'] as List) .map((e) => _$enumDecode(_$EnumTypeEnumMap, e)) .toSet(), ); } -Map _$SimpleClassEnumTypeToJson( - SimpleClassEnumType instance) => +Map _$SimpleClassOfEnumTypeToJson( + SimpleClassOfEnumType instance) => { - 'value': instance.value?.map((e) => _$EnumTypeEnumMap[e])?.toList(), - 'nullable': instance.nullable.map((e) => _$EnumTypeEnumMap[e]).toList(), + 'value': instance.value.map((e) => _$EnumTypeEnumMap[e]).toList(), }; -T _$enumDecode( - Map enumValues, - dynamic source, { - T unknownValue, +K _$enumDecode( + Map enumValues, + Object? source, { + K? unknownValue, }) { if (source == null) { - throw ArgumentError('A value must be provided. Supported values: ' - '${enumValues.values.join(', ')}'); + throw ArgumentError( + 'A value must be provided. Supported values: ' + '${enumValues.values.join(', ')}', + ); } - final value = enumValues.entries - .singleWhere((e) => e.value == source, orElse: () => null) - ?.key; + return enumValues.entries.singleWhere( + (e) => e.value == source, + orElse: () { + if (unknownValue == null) { + throw ArgumentError( + '`$source` is not one of the supported values: ' + '${enumValues.values.join(', ')}', + ); + } + return MapEntry(unknownValue, enumValues.values.first); + }, + ).key; +} - if (value == null && unknownValue == null) { - throw ArgumentError('`$source` is not one of the supported values: ' - '${enumValues.values.join(', ')}'); - } - return value ?? unknownValue; +const _$EnumTypeEnumMap = { + EnumType.alpha: 'alpha', + EnumType.beta: 'beta', + EnumType.gamma: 'gamma', + EnumType.delta: 'delta', +}; + +SimpleClassNullableOfEnumType _$SimpleClassNullableOfEnumTypeFromJson( + Map json) { + return SimpleClassNullableOfEnumType( + (json['value'] as List?) + ?.map((e) => _$enumDecode(_$EnumTypeEnumMap, e)) + .toSet(), + ); +} + +Map _$SimpleClassNullableOfEnumTypeToJson( + SimpleClassNullableOfEnumType instance) => + { + 'value': instance.value?.map((e) => _$EnumTypeEnumMap[e]).toList(), + }; + +SimpleClassOfEnumTypeNullable _$SimpleClassOfEnumTypeNullableFromJson( + Map json) { + return SimpleClassOfEnumTypeNullable( + (json['value'] as List) + .map((e) => _$enumDecodeNullable(_$EnumTypeEnumMap, e)) + .toSet(), + ); } -T _$enumDecodeNullable( - Map enumValues, +Map _$SimpleClassOfEnumTypeNullableToJson( + SimpleClassOfEnumTypeNullable instance) => + { + 'value': instance.value.map((e) => _$EnumTypeEnumMap[e]).toList(), + }; + +K? _$enumDecodeNullable( + Map enumValues, dynamic source, { - T unknownValue, + K? unknownValue, }) { if (source == null) { return null; } - return _$enumDecode(enumValues, source, unknownValue: unknownValue); + return _$enumDecode(enumValues, source, unknownValue: unknownValue); } -const _$EnumTypeEnumMap = { - EnumType.alpha: 'alpha', - EnumType.beta: 'beta', - EnumType.gamma: 'gamma', - EnumType.delta: 'delta', -}; +SimpleClassNullableOfEnumTypeNullable + _$SimpleClassNullableOfEnumTypeNullableFromJson(Map json) { + return SimpleClassNullableOfEnumTypeNullable( + (json['value'] as List?) + ?.map((e) => _$enumDecodeNullable(_$EnumTypeEnumMap, e)) + .toSet(), + ); +} + +Map _$SimpleClassNullableOfEnumTypeNullableToJson( + SimpleClassNullableOfEnumTypeNullable instance) => + { + 'value': instance.value?.map((e) => _$EnumTypeEnumMap[e]).toList(), + }; + +SimpleClassOfInt _$SimpleClassOfIntFromJson(Map json) { + return SimpleClassOfInt( + (json['value'] as List).map((e) => e as int).toSet(), + ); +} + +Map _$SimpleClassOfIntToJson(SimpleClassOfInt instance) => + { + 'value': instance.value.toList(), + }; -SimpleClassInt _$SimpleClassIntFromJson(Map json) { - return SimpleClassInt( - (json['value'] as List)?.map((e) => e as int)?.toSet(), - (json['nullable'] as List).map((e) => e as int).toSet(), +SimpleClassNullableOfInt _$SimpleClassNullableOfIntFromJson( + Map json) { + return SimpleClassNullableOfInt( + (json['value'] as List?)?.map((e) => e as int).toSet(), ); } -Map _$SimpleClassIntToJson(SimpleClassInt instance) => +Map _$SimpleClassNullableOfIntToJson( + SimpleClassNullableOfInt instance) => { 'value': instance.value?.toList(), - 'nullable': instance.nullable.toList(), }; -SimpleClassNum _$SimpleClassNumFromJson(Map json) { - return SimpleClassNum( - (json['value'] as List)?.map((e) => e as num)?.toSet(), - (json['nullable'] as List).map((e) => e as num).toSet(), +SimpleClassOfIntNullable _$SimpleClassOfIntNullableFromJson( + Map json) { + return SimpleClassOfIntNullable( + (json['value'] as List).map((e) => e as int?).toSet(), + ); +} + +Map _$SimpleClassOfIntNullableToJson( + SimpleClassOfIntNullable instance) => + { + 'value': instance.value.toList(), + }; + +SimpleClassNullableOfIntNullable _$SimpleClassNullableOfIntNullableFromJson( + Map json) { + return SimpleClassNullableOfIntNullable( + (json['value'] as List?)?.map((e) => e as int?).toSet(), ); } -Map _$SimpleClassNumToJson(SimpleClassNum instance) => +Map _$SimpleClassNullableOfIntNullableToJson( + SimpleClassNullableOfIntNullable instance) => { 'value': instance.value?.toList(), - 'nullable': instance.nullable.toList(), }; -SimpleClassObject _$SimpleClassObjectFromJson(Map json) { - return SimpleClassObject( - (json['value'] as List)?.toSet(), - (json['nullable'] as List).toSet(), +SimpleClassOfNum _$SimpleClassOfNumFromJson(Map json) { + return SimpleClassOfNum( + (json['value'] as List).map((e) => e as num).toSet(), + ); +} + +Map _$SimpleClassOfNumToJson(SimpleClassOfNum instance) => + { + 'value': instance.value.toList(), + }; + +SimpleClassNullableOfNum _$SimpleClassNullableOfNumFromJson( + Map json) { + return SimpleClassNullableOfNum( + (json['value'] as List?)?.map((e) => e as num).toSet(), ); } -Map _$SimpleClassObjectToJson(SimpleClassObject instance) => +Map _$SimpleClassNullableOfNumToJson( + SimpleClassNullableOfNum instance) => { 'value': instance.value?.toList(), - 'nullable': instance.nullable.toList(), }; -SimpleClassString _$SimpleClassStringFromJson(Map json) { - return SimpleClassString( - (json['value'] as List)?.map((e) => e as String)?.toSet(), - (json['nullable'] as List).map((e) => e as String).toSet(), +SimpleClassOfNumNullable _$SimpleClassOfNumNullableFromJson( + Map json) { + return SimpleClassOfNumNullable( + (json['value'] as List).map((e) => e as num?).toSet(), ); } -Map _$SimpleClassStringToJson(SimpleClassString instance) => +Map _$SimpleClassOfNumNullableToJson( + SimpleClassOfNumNullable instance) => + { + 'value': instance.value.toList(), + }; + +SimpleClassNullableOfNumNullable _$SimpleClassNullableOfNumNullableFromJson( + Map json) { + return SimpleClassNullableOfNumNullable( + (json['value'] as List?)?.map((e) => e as num?).toSet(), + ); +} + +Map _$SimpleClassNullableOfNumNullableToJson( + SimpleClassNullableOfNumNullable instance) => { 'value': instance.value?.toList(), - 'nullable': instance.nullable.toList(), }; -SimpleClassUri _$SimpleClassUriFromJson(Map json) { - return SimpleClassUri( - (json['value'] as List) +SimpleClassOfObject _$SimpleClassOfObjectFromJson(Map json) { + return SimpleClassOfObject( + (json['value'] as List).map((e) => e as Object).toSet(), + ); +} + +Map _$SimpleClassOfObjectToJson( + SimpleClassOfObject instance) => + { + 'value': instance.value.toList(), + }; + +SimpleClassNullableOfObject _$SimpleClassNullableOfObjectFromJson( + Map json) { + return SimpleClassNullableOfObject( + (json['value'] as List?)?.map((e) => e as Object).toSet(), + ); +} + +Map _$SimpleClassNullableOfObjectToJson( + SimpleClassNullableOfObject instance) => + { + 'value': instance.value?.toList(), + }; + +SimpleClassOfObjectNullable _$SimpleClassOfObjectNullableFromJson( + Map json) { + return SimpleClassOfObjectNullable( + (json['value'] as List).toSet(), + ); +} + +Map _$SimpleClassOfObjectNullableToJson( + SimpleClassOfObjectNullable instance) => + { + 'value': instance.value.toList(), + }; + +SimpleClassNullableOfObjectNullable + _$SimpleClassNullableOfObjectNullableFromJson(Map json) { + return SimpleClassNullableOfObjectNullable( + (json['value'] as List?)?.toSet(), + ); +} + +Map _$SimpleClassNullableOfObjectNullableToJson( + SimpleClassNullableOfObjectNullable instance) => + { + 'value': instance.value?.toList(), + }; + +SimpleClassOfString _$SimpleClassOfStringFromJson(Map json) { + return SimpleClassOfString( + (json['value'] as List).map((e) => e as String).toSet(), + ); +} + +Map _$SimpleClassOfStringToJson( + SimpleClassOfString instance) => + { + 'value': instance.value.toList(), + }; + +SimpleClassNullableOfString _$SimpleClassNullableOfStringFromJson( + Map json) { + return SimpleClassNullableOfString( + (json['value'] as List?)?.map((e) => e as String).toSet(), + ); +} + +Map _$SimpleClassNullableOfStringToJson( + SimpleClassNullableOfString instance) => + { + 'value': instance.value?.toList(), + }; + +SimpleClassOfStringNullable _$SimpleClassOfStringNullableFromJson( + Map json) { + return SimpleClassOfStringNullable( + (json['value'] as List).map((e) => e as String?).toSet(), + ); +} + +Map _$SimpleClassOfStringNullableToJson( + SimpleClassOfStringNullable instance) => + { + 'value': instance.value.toList(), + }; + +SimpleClassNullableOfStringNullable + _$SimpleClassNullableOfStringNullableFromJson(Map json) { + return SimpleClassNullableOfStringNullable( + (json['value'] as List?)?.map((e) => e as String?).toSet(), + ); +} + +Map _$SimpleClassNullableOfStringNullableToJson( + SimpleClassNullableOfStringNullable instance) => + { + 'value': instance.value?.toList(), + }; + +SimpleClassOfUri _$SimpleClassOfUriFromJson(Map json) { + return SimpleClassOfUri( + (json['value'] as List).map((e) => Uri.parse(e as String)).toSet(), + ); +} + +Map _$SimpleClassOfUriToJson(SimpleClassOfUri instance) => + { + 'value': instance.value.map((e) => e.toString()).toList(), + }; + +SimpleClassNullableOfUri _$SimpleClassNullableOfUriFromJson( + Map json) { + return SimpleClassNullableOfUri( + (json['value'] as List?) + ?.map((e) => Uri.parse(e as String)) + .toSet(), + ); +} + +Map _$SimpleClassNullableOfUriToJson( + SimpleClassNullableOfUri instance) => + { + 'value': instance.value?.map((e) => e.toString()).toList(), + }; + +SimpleClassOfUriNullable _$SimpleClassOfUriNullableFromJson( + Map json) { + return SimpleClassOfUriNullable( + (json['value'] as List) + .map((e) => e == null ? null : Uri.parse(e as String)) + .toSet(), + ); +} + +Map _$SimpleClassOfUriNullableToJson( + SimpleClassOfUriNullable instance) => + { + 'value': instance.value.map((e) => e?.toString()).toList(), + }; + +SimpleClassNullableOfUriNullable _$SimpleClassNullableOfUriNullableFromJson( + Map json) { + return SimpleClassNullableOfUriNullable( + (json['value'] as List?) ?.map((e) => e == null ? null : Uri.parse(e as String)) - ?.toSet(), - (json['nullable'] as List).map((e) => Uri.parse(e as String)).toSet(), + .toSet(), ); } -Map _$SimpleClassUriToJson(SimpleClassUri instance) => +Map _$SimpleClassNullableOfUriNullableToJson( + SimpleClassNullableOfUriNullable instance) => { - 'value': instance.value?.map((e) => e?.toString())?.toList(), - 'nullable': instance.nullable.map((e) => e.toString()).toList(), + 'value': instance.value?.map((e) => e?.toString()).toList(), }; diff --git a/json_serializable/test/supported_types/input.type_string.dart b/json_serializable/test/supported_types/input.type_string.dart index 8dc10f032..1131e9556 100644 --- a/json_serializable/test/supported_types/input.type_string.dart +++ b/json_serializable/test/supported_types/input.type_string.dart @@ -2,6 +2,8 @@ // 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. +// @dart=2.12 + import 'package:json_annotation/json_annotation.dart'; part 'input.type_string.g.dart'; @@ -10,19 +12,34 @@ part 'input.type_string.g.dart'; class SimpleClass { final String value; - @JsonKey(nullable: false) - final String nullable; - @JsonKey(defaultValue: 'a string') String withDefault; SimpleClass( this.value, - this.nullable, + this.withDefault, ); - factory SimpleClass.fromJson(Map json) => + factory SimpleClass.fromJson(Map json) => _$SimpleClassFromJson(json); - Map toJson() => _$SimpleClassToJson(this); + Map toJson() => _$SimpleClassToJson(this); +} + +@JsonSerializable() +class SimpleClassNullable { + final String? value; + + @JsonKey(defaultValue: 'a string') + String? withDefault; + + SimpleClassNullable( + this.value, + this.withDefault, + ); + + factory SimpleClassNullable.fromJson(Map json) => + _$SimpleClassNullableFromJson(json); + + Map toJson() => _$SimpleClassNullableToJson(this); } diff --git a/json_serializable/test/supported_types/input.type_string.g.dart b/json_serializable/test/supported_types/input.type_string.g.dart index d3ab769db..55ff7b924 100644 --- a/json_serializable/test/supported_types/input.type_string.g.dart +++ b/json_serializable/test/supported_types/input.type_string.g.dart @@ -1,4 +1,5 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// @dart=2.12 part of 'input.type_string.dart'; @@ -9,13 +10,26 @@ part of 'input.type_string.dart'; SimpleClass _$SimpleClassFromJson(Map json) { return SimpleClass( json['value'] as String, - json['nullable'] as String, - )..withDefault = json['withDefault'] as String ?? 'a string'; + json['withDefault'] as String? ?? 'a string', + ); } Map _$SimpleClassToJson(SimpleClass instance) => { 'value': instance.value, - 'nullable': instance.nullable, + 'withDefault': instance.withDefault, + }; + +SimpleClassNullable _$SimpleClassNullableFromJson(Map json) { + return SimpleClassNullable( + json['value'] as String?, + json['withDefault'] as String? ?? 'a string', + ); +} + +Map _$SimpleClassNullableToJson( + SimpleClassNullable instance) => + { + 'value': instance.value, 'withDefault': instance.withDefault, }; diff --git a/json_serializable/test/supported_types/input.type_uri.dart b/json_serializable/test/supported_types/input.type_uri.dart index ce41b79ca..15b2c39f0 100644 --- a/json_serializable/test/supported_types/input.type_uri.dart +++ b/json_serializable/test/supported_types/input.type_uri.dart @@ -2,6 +2,8 @@ // 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. +// @dart=2.12 + import 'package:json_annotation/json_annotation.dart'; part 'input.type_uri.g.dart'; @@ -10,16 +12,26 @@ part 'input.type_uri.g.dart'; class SimpleClass { final Uri value; - @JsonKey(nullable: false) - final Uri nullable; - SimpleClass( this.value, - this.nullable, ); - factory SimpleClass.fromJson(Map json) => + factory SimpleClass.fromJson(Map json) => _$SimpleClassFromJson(json); - Map toJson() => _$SimpleClassToJson(this); + Map toJson() => _$SimpleClassToJson(this); +} + +@JsonSerializable() +class SimpleClassNullable { + final Uri? value; + + SimpleClassNullable( + this.value, + ); + + factory SimpleClassNullable.fromJson(Map json) => + _$SimpleClassNullableFromJson(json); + + Map toJson() => _$SimpleClassNullableToJson(this); } diff --git a/json_serializable/test/supported_types/input.type_uri.g.dart b/json_serializable/test/supported_types/input.type_uri.g.dart index 665a3b5a3..d0d8e1daf 100644 --- a/json_serializable/test/supported_types/input.type_uri.g.dart +++ b/json_serializable/test/supported_types/input.type_uri.g.dart @@ -1,4 +1,5 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// @dart=2.12 part of 'input.type_uri.dart'; @@ -8,13 +9,23 @@ part of 'input.type_uri.dart'; SimpleClass _$SimpleClassFromJson(Map json) { return SimpleClass( - json['value'] == null ? null : Uri.parse(json['value'] as String), - Uri.parse(json['nullable'] as String), + Uri.parse(json['value'] as String), ); } Map _$SimpleClassToJson(SimpleClass instance) => + { + 'value': instance.value.toString(), + }; + +SimpleClassNullable _$SimpleClassNullableFromJson(Map json) { + return SimpleClassNullable( + json['value'] == null ? null : Uri.parse(json['value'] as String), + ); +} + +Map _$SimpleClassNullableToJson( + SimpleClassNullable instance) => { 'value': instance.value?.toString(), - 'nullable': instance.nullable.toString(), }; diff --git a/json_serializable/test/supported_types/type_test.bigint_test.dart b/json_serializable/test/supported_types/type_test.bigint_test.dart index d185cabd3..cdc2c3718 100644 --- a/json_serializable/test/supported_types/type_test.bigint_test.dart +++ b/json_serializable/test/supported_types/type_test.bigint_test.dart @@ -2,8 +2,12 @@ // 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. +// @dart=2.12 + // ignore_for_file: prefer_const_declarations +import 'dart:convert'; + @TestOn('vm') import 'package:test/test.dart'; @@ -11,31 +15,94 @@ import '../test_utils.dart'; import 'input.type_bigint.dart'; void main() { - test('round trip', () { - final object = SimpleClass.fromJson(_emptyInput); - expect(loudEncode(object), loudEncode(_defaultOutput)); - }); - - test('round trip alternate values', () { - final object = SimpleClass.fromJson(_nonDefaultJson); - expect(loudEncode(object), loudEncode(_nonDefaultJson)); - expect(loudEncode(object), isNot(loudEncode(_defaultOutput))); - }); + group('non-nullable', () { + test('round trip', () { + final object = SimpleClass.fromJson(_defaultInput); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_defaultOutput)); + + final object2 = SimpleClass.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + + test('round trip null', () { + expect( + () => loudEncode(SimpleClass.fromJson({})), + throwsA(isA()), + ); + }); + + test('round trip alternate values', () { + final object = SimpleClass.fromJson(_nonDefaultJson); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_nonDefaultJson)); + expect(encoded, isNot(loudEncode(_defaultOutput))); + + final object2 = SimpleClass.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + }); // end non-nullable group + + group('nullable', () { + test('round trip', () { + final object = SimpleClassNullable.fromJson(_defaultInput); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_defaultOutput)); + + final object2 = SimpleClassNullable.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + + test('round trip null', () { + final object = SimpleClassNullable.fromJson({}); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_nullableDefaultOutput)); + final object2 = SimpleClassNullable.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + + test('round trip alternate values', () { + final object = SimpleClassNullable.fromJson(_nonDefaultJson); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_nonDefaultJson)); + expect(encoded, isNot(loudEncode(_defaultOutput))); + + final object2 = SimpleClassNullable.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + }); // end nullable group } final _defaultValue = '12345'; final _altValue = '67890'; -final _emptyInput = { - 'nullable': _defaultValue, +final _defaultInput = { + 'value': _defaultValue, }; final _defaultOutput = { + 'value': _defaultValue, +}; + +final _nullableDefaultOutput = { 'value': null, - 'nullable': _defaultValue, }; final _nonDefaultJson = { - 'value': null, - 'nullable': _altValue, + 'value': _altValue, }; diff --git a/json_serializable/test/supported_types/type_test.bool_test.dart b/json_serializable/test/supported_types/type_test.bool_test.dart index 52f6764ce..3cf24c38f 100644 --- a/json_serializable/test/supported_types/type_test.bool_test.dart +++ b/json_serializable/test/supported_types/type_test.bool_test.dart @@ -2,8 +2,12 @@ // 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. +// @dart=2.12 + // ignore_for_file: prefer_const_declarations +import 'dart:convert'; + @TestOn('vm') import 'package:test/test.dart'; @@ -11,33 +15,97 @@ import '../test_utils.dart'; import 'input.type_bool.dart'; void main() { - test('round trip', () { - final object = SimpleClass.fromJson(_emptyInput); - expect(loudEncode(object), loudEncode(_defaultOutput)); - }); - - test('round trip alternate values', () { - final object = SimpleClass.fromJson(_nonDefaultJson); - expect(loudEncode(object), loudEncode(_nonDefaultJson)); - expect(loudEncode(object), isNot(loudEncode(_defaultOutput))); - }); + group('non-nullable', () { + test('round trip', () { + final object = SimpleClass.fromJson(_defaultInput); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_defaultOutput)); + + final object2 = SimpleClass.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + + test('round trip null', () { + expect( + () => loudEncode(SimpleClass.fromJson({})), + throwsA(isA()), + ); + }); + + test('round trip alternate values', () { + final object = SimpleClass.fromJson(_nonDefaultJson); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_nonDefaultJson)); + expect(encoded, isNot(loudEncode(_defaultOutput))); + + final object2 = SimpleClass.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + }); // end non-nullable group + + group('nullable', () { + test('round trip', () { + final object = SimpleClassNullable.fromJson(_defaultInput); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_defaultOutput)); + + final object2 = SimpleClassNullable.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + + test('round trip null', () { + final object = SimpleClassNullable.fromJson({}); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_nullableDefaultOutput)); + final object2 = SimpleClassNullable.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + + test('round trip alternate values', () { + final object = SimpleClassNullable.fromJson(_nonDefaultJson); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_nonDefaultJson)); + expect(encoded, isNot(loudEncode(_defaultOutput))); + + final object2 = SimpleClassNullable.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + }); // end nullable group } final _defaultValue = true; final _altValue = false; -final _emptyInput = { - 'nullable': _defaultValue, +final _defaultInput = { + 'value': _defaultValue, }; final _defaultOutput = { + 'value': _defaultValue, + 'withDefault': _defaultValue, +}; + +final _nullableDefaultOutput = { 'value': null, - 'nullable': _defaultValue, 'withDefault': _defaultValue, }; final _nonDefaultJson = { - 'value': null, - 'nullable': _altValue, + 'value': _altValue, 'withDefault': _altValue, }; diff --git a/json_serializable/test/supported_types/type_test.dart b/json_serializable/test/supported_types/type_test.dart index ce7436949..4cafc262b 100644 --- a/json_serializable/test/supported_types/type_test.dart +++ b/json_serializable/test/supported_types/type_test.dart @@ -2,8 +2,12 @@ // 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. +// @dart=2.12 + // ignore_for_file: prefer_const_declarations +import 'dart:convert'; + @TestOn('vm') import 'package:test/test.dart'; @@ -11,33 +15,63 @@ import '../test_utils.dart'; import 'input.dart'; void main() { - test('round trip', () { - final object = SimpleClass.fromJson(_emptyInput); - expect(loudEncode(object), loudEncode(_defaultOutput)); - }); - - test('round trip alternate values', () { - final object = SimpleClass.fromJson(_nonDefaultJson); - expect(loudEncode(object), loudEncode(_nonDefaultJson)); - expect(loudEncode(object), isNot(loudEncode(_defaultOutput))); - }); + group('non-nullable', () { + test('round trip', () { + final object = SimpleClass.fromJson(_defaultInput); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_defaultOutput)); + + final object2 = SimpleClass.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + + test('round trip null', () { + final object = SimpleClass.fromJson({}); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_nullableDefaultOutput)); + final object2 = SimpleClass.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + + test('round trip alternate values', () { + final object = SimpleClass.fromJson(_nonDefaultJson); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_nonDefaultJson)); + expect(encoded, isNot(loudEncode(_defaultOutput))); + + final object2 = SimpleClass.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + }); // end non-nullable group } final _defaultValue = 42; final _altValue = 43; -final _emptyInput = { - 'nullable': _defaultValue, +final _defaultInput = { + 'value': _defaultValue, }; final _defaultOutput = { + 'value': _defaultValue, + 'withDefault': _defaultValue, +}; + +final _nullableDefaultOutput = { 'value': null, - 'nullable': _defaultValue, 'withDefault': _defaultValue, }; final _nonDefaultJson = { - 'value': null, - 'nullable': _altValue, + 'value': _altValue, 'withDefault': _altValue, }; diff --git a/json_serializable/test/supported_types/type_test.datetime_test.dart b/json_serializable/test/supported_types/type_test.datetime_test.dart index ec9f36619..e8dc264dd 100644 --- a/json_serializable/test/supported_types/type_test.datetime_test.dart +++ b/json_serializable/test/supported_types/type_test.datetime_test.dart @@ -2,8 +2,12 @@ // 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. +// @dart=2.12 + // ignore_for_file: prefer_const_declarations +import 'dart:convert'; + @TestOn('vm') import 'package:test/test.dart'; @@ -11,31 +15,94 @@ import '../test_utils.dart'; import 'input.type_datetime.dart'; void main() { - test('round trip', () { - final object = SimpleClass.fromJson(_emptyInput); - expect(loudEncode(object), loudEncode(_defaultOutput)); - }); - - test('round trip alternate values', () { - final object = SimpleClass.fromJson(_nonDefaultJson); - expect(loudEncode(object), loudEncode(_nonDefaultJson)); - expect(loudEncode(object), isNot(loudEncode(_defaultOutput))); - }); + group('non-nullable', () { + test('round trip', () { + final object = SimpleClass.fromJson(_defaultInput); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_defaultOutput)); + + final object2 = SimpleClass.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + + test('round trip null', () { + expect( + () => loudEncode(SimpleClass.fromJson({})), + throwsA(isA()), + ); + }); + + test('round trip alternate values', () { + final object = SimpleClass.fromJson(_nonDefaultJson); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_nonDefaultJson)); + expect(encoded, isNot(loudEncode(_defaultOutput))); + + final object2 = SimpleClass.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + }); // end non-nullable group + + group('nullable', () { + test('round trip', () { + final object = SimpleClassNullable.fromJson(_defaultInput); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_defaultOutput)); + + final object2 = SimpleClassNullable.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + + test('round trip null', () { + final object = SimpleClassNullable.fromJson({}); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_nullableDefaultOutput)); + final object2 = SimpleClassNullable.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + + test('round trip alternate values', () { + final object = SimpleClassNullable.fromJson(_nonDefaultJson); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_nonDefaultJson)); + expect(encoded, isNot(loudEncode(_defaultOutput))); + + final object2 = SimpleClassNullable.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + }); // end nullable group } final _defaultValue = '2020-01-01T00:00:00.000'; final _altValue = '2018-01-01T00:00:00.000'; -final _emptyInput = { - 'nullable': _defaultValue, +final _defaultInput = { + 'value': _defaultValue, }; final _defaultOutput = { + 'value': _defaultValue, +}; + +final _nullableDefaultOutput = { 'value': null, - 'nullable': _defaultValue, }; final _nonDefaultJson = { - 'value': null, - 'nullable': _altValue, + 'value': _altValue, }; diff --git a/json_serializable/test/supported_types/type_test.double_test.dart b/json_serializable/test/supported_types/type_test.double_test.dart index 466abab43..a8b9c07b4 100644 --- a/json_serializable/test/supported_types/type_test.double_test.dart +++ b/json_serializable/test/supported_types/type_test.double_test.dart @@ -2,8 +2,12 @@ // 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. +// @dart=2.12 + // ignore_for_file: prefer_const_declarations +import 'dart:convert'; + @TestOn('vm') import 'package:test/test.dart'; @@ -11,33 +15,97 @@ import '../test_utils.dart'; import 'input.type_double.dart'; void main() { - test('round trip', () { - final object = SimpleClass.fromJson(_emptyInput); - expect(loudEncode(object), loudEncode(_defaultOutput)); - }); - - test('round trip alternate values', () { - final object = SimpleClass.fromJson(_nonDefaultJson); - expect(loudEncode(object), loudEncode(_nonDefaultJson)); - expect(loudEncode(object), isNot(loudEncode(_defaultOutput))); - }); + group('non-nullable', () { + test('round trip', () { + final object = SimpleClass.fromJson(_defaultInput); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_defaultOutput)); + + final object2 = SimpleClass.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + + test('round trip null', () { + expect( + () => loudEncode(SimpleClass.fromJson({})), + throwsA(isA()), + ); + }); + + test('round trip alternate values', () { + final object = SimpleClass.fromJson(_nonDefaultJson); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_nonDefaultJson)); + expect(encoded, isNot(loudEncode(_defaultOutput))); + + final object2 = SimpleClass.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + }); // end non-nullable group + + group('nullable', () { + test('round trip', () { + final object = SimpleClassNullable.fromJson(_defaultInput); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_defaultOutput)); + + final object2 = SimpleClassNullable.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + + test('round trip null', () { + final object = SimpleClassNullable.fromJson({}); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_nullableDefaultOutput)); + final object2 = SimpleClassNullable.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + + test('round trip alternate values', () { + final object = SimpleClassNullable.fromJson(_nonDefaultJson); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_nonDefaultJson)); + expect(encoded, isNot(loudEncode(_defaultOutput))); + + final object2 = SimpleClassNullable.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + }); // end nullable group } final _defaultValue = 3.14; final _altValue = 6.28; -final _emptyInput = { - 'nullable': _defaultValue, +final _defaultInput = { + 'value': _defaultValue, }; final _defaultOutput = { + 'value': _defaultValue, + 'withDefault': _defaultValue, +}; + +final _nullableDefaultOutput = { 'value': null, - 'nullable': _defaultValue, 'withDefault': _defaultValue, }; final _nonDefaultJson = { - 'value': null, - 'nullable': _altValue, + 'value': _altValue, 'withDefault': _altValue, }; diff --git a/json_serializable/test/supported_types/type_test.duration_test.dart b/json_serializable/test/supported_types/type_test.duration_test.dart index 463298ea0..808880f72 100644 --- a/json_serializable/test/supported_types/type_test.duration_test.dart +++ b/json_serializable/test/supported_types/type_test.duration_test.dart @@ -2,8 +2,12 @@ // 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. +// @dart=2.12 + // ignore_for_file: prefer_const_declarations +import 'dart:convert'; + @TestOn('vm') import 'package:test/test.dart'; @@ -11,31 +15,94 @@ import '../test_utils.dart'; import 'input.type_duration.dart'; void main() { - test('round trip', () { - final object = SimpleClass.fromJson(_emptyInput); - expect(loudEncode(object), loudEncode(_defaultOutput)); - }); - - test('round trip alternate values', () { - final object = SimpleClass.fromJson(_nonDefaultJson); - expect(loudEncode(object), loudEncode(_nonDefaultJson)); - expect(loudEncode(object), isNot(loudEncode(_defaultOutput))); - }); + group('non-nullable', () { + test('round trip', () { + final object = SimpleClass.fromJson(_defaultInput); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_defaultOutput)); + + final object2 = SimpleClass.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + + test('round trip null', () { + expect( + () => loudEncode(SimpleClass.fromJson({})), + throwsA(isA()), + ); + }); + + test('round trip alternate values', () { + final object = SimpleClass.fromJson(_nonDefaultJson); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_nonDefaultJson)); + expect(encoded, isNot(loudEncode(_defaultOutput))); + + final object2 = SimpleClass.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + }); // end non-nullable group + + group('nullable', () { + test('round trip', () { + final object = SimpleClassNullable.fromJson(_defaultInput); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_defaultOutput)); + + final object2 = SimpleClassNullable.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + + test('round trip null', () { + final object = SimpleClassNullable.fromJson({}); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_nullableDefaultOutput)); + final object2 = SimpleClassNullable.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + + test('round trip alternate values', () { + final object = SimpleClassNullable.fromJson(_nonDefaultJson); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_nonDefaultJson)); + expect(encoded, isNot(loudEncode(_defaultOutput))); + + final object2 = SimpleClassNullable.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + }); // end nullable group } final _defaultValue = 1234; final _altValue = 2345; -final _emptyInput = { - 'nullable': _defaultValue, +final _defaultInput = { + 'value': _defaultValue, }; final _defaultOutput = { + 'value': _defaultValue, +}; + +final _nullableDefaultOutput = { 'value': null, - 'nullable': _defaultValue, }; final _nonDefaultJson = { - 'value': null, - 'nullable': _altValue, + 'value': _altValue, }; diff --git a/json_serializable/test/supported_types/type_test.enumtype_test.dart b/json_serializable/test/supported_types/type_test.enumtype_test.dart index 321452c71..b76d51a0e 100644 --- a/json_serializable/test/supported_types/type_test.enumtype_test.dart +++ b/json_serializable/test/supported_types/type_test.enumtype_test.dart @@ -2,8 +2,12 @@ // 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. +// @dart=2.12 + // ignore_for_file: prefer_const_declarations +import 'dart:convert'; + @TestOn('vm') import 'package:test/test.dart'; @@ -11,33 +15,97 @@ import '../test_utils.dart'; import 'input.type_enumtype.dart'; void main() { - test('round trip', () { - final object = SimpleClass.fromJson(_emptyInput); - expect(loudEncode(object), loudEncode(_defaultOutput)); - }); - - test('round trip alternate values', () { - final object = SimpleClass.fromJson(_nonDefaultJson); - expect(loudEncode(object), loudEncode(_nonDefaultJson)); - expect(loudEncode(object), isNot(loudEncode(_defaultOutput))); - }); + group('non-nullable', () { + test('round trip', () { + final object = SimpleClass.fromJson(_defaultInput); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_defaultOutput)); + + final object2 = SimpleClass.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + + test('round trip null', () { + expect( + () => loudEncode(SimpleClass.fromJson({})), + throwsA(isA()), + ); + }); + + test('round trip alternate values', () { + final object = SimpleClass.fromJson(_nonDefaultJson); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_nonDefaultJson)); + expect(encoded, isNot(loudEncode(_defaultOutput))); + + final object2 = SimpleClass.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + }); // end non-nullable group + + group('nullable', () { + test('round trip', () { + final object = SimpleClassNullable.fromJson(_defaultInput); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_defaultOutput)); + + final object2 = SimpleClassNullable.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + + test('round trip null', () { + final object = SimpleClassNullable.fromJson({}); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_nullableDefaultOutput)); + final object2 = SimpleClassNullable.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + + test('round trip alternate values', () { + final object = SimpleClassNullable.fromJson(_nonDefaultJson); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_nonDefaultJson)); + expect(encoded, isNot(loudEncode(_defaultOutput))); + + final object2 = SimpleClassNullable.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + }); // end nullable group } final _defaultValue = 'alpha'; final _altValue = 'beta'; -final _emptyInput = { - 'nullable': _defaultValue, +final _defaultInput = { + 'value': _defaultValue, }; final _defaultOutput = { + 'value': _defaultValue, + 'withDefault': _defaultValue, +}; + +final _nullableDefaultOutput = { 'value': null, - 'nullable': _defaultValue, 'withDefault': _defaultValue, }; final _nonDefaultJson = { - 'value': null, - 'nullable': _altValue, + 'value': _altValue, 'withDefault': _altValue, }; diff --git a/json_serializable/test/supported_types/type_test.int_test.dart b/json_serializable/test/supported_types/type_test.int_test.dart index 53d59319c..a40a29a33 100644 --- a/json_serializable/test/supported_types/type_test.int_test.dart +++ b/json_serializable/test/supported_types/type_test.int_test.dart @@ -2,8 +2,12 @@ // 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. +// @dart=2.12 + // ignore_for_file: prefer_const_declarations +import 'dart:convert'; + @TestOn('vm') import 'package:test/test.dart'; @@ -11,33 +15,97 @@ import '../test_utils.dart'; import 'input.type_int.dart'; void main() { - test('round trip', () { - final object = SimpleClass.fromJson(_emptyInput); - expect(loudEncode(object), loudEncode(_defaultOutput)); - }); - - test('round trip alternate values', () { - final object = SimpleClass.fromJson(_nonDefaultJson); - expect(loudEncode(object), loudEncode(_nonDefaultJson)); - expect(loudEncode(object), isNot(loudEncode(_defaultOutput))); - }); + group('non-nullable', () { + test('round trip', () { + final object = SimpleClass.fromJson(_defaultInput); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_defaultOutput)); + + final object2 = SimpleClass.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + + test('round trip null', () { + expect( + () => loudEncode(SimpleClass.fromJson({})), + throwsA(isA()), + ); + }); + + test('round trip alternate values', () { + final object = SimpleClass.fromJson(_nonDefaultJson); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_nonDefaultJson)); + expect(encoded, isNot(loudEncode(_defaultOutput))); + + final object2 = SimpleClass.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + }); // end non-nullable group + + group('nullable', () { + test('round trip', () { + final object = SimpleClassNullable.fromJson(_defaultInput); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_defaultOutput)); + + final object2 = SimpleClassNullable.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + + test('round trip null', () { + final object = SimpleClassNullable.fromJson({}); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_nullableDefaultOutput)); + final object2 = SimpleClassNullable.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + + test('round trip alternate values', () { + final object = SimpleClassNullable.fromJson(_nonDefaultJson); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_nonDefaultJson)); + expect(encoded, isNot(loudEncode(_defaultOutput))); + + final object2 = SimpleClassNullable.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + }); // end nullable group } final _defaultValue = 42; final _altValue = 43; -final _emptyInput = { - 'nullable': _defaultValue, +final _defaultInput = { + 'value': _defaultValue, }; final _defaultOutput = { + 'value': _defaultValue, + 'withDefault': _defaultValue, +}; + +final _nullableDefaultOutput = { 'value': null, - 'nullable': _defaultValue, 'withDefault': _defaultValue, }; final _nonDefaultJson = { - 'value': null, - 'nullable': _altValue, + 'value': _altValue, 'withDefault': _altValue, }; diff --git a/json_serializable/test/supported_types/type_test.iterable_test.dart b/json_serializable/test/supported_types/type_test.iterable_test.dart index 301725643..d24795cd4 100644 --- a/json_serializable/test/supported_types/type_test.iterable_test.dart +++ b/json_serializable/test/supported_types/type_test.iterable_test.dart @@ -2,8 +2,12 @@ // 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. +// @dart=2.12 + // ignore_for_file: prefer_const_declarations +import 'dart:convert'; + @TestOn('vm') import 'package:test/test.dart'; @@ -11,33 +15,97 @@ import '../test_utils.dart'; import 'input.type_iterable.dart'; void main() { - test('round trip', () { - final object = SimpleClass.fromJson(_emptyInput); - expect(loudEncode(object), loudEncode(_defaultOutput)); - }); - - test('round trip alternate values', () { - final object = SimpleClass.fromJson(_nonDefaultJson); - expect(loudEncode(object), loudEncode(_nonDefaultJson)); - expect(loudEncode(object), isNot(loudEncode(_defaultOutput))); - }); + group('non-nullable', () { + test('round trip', () { + final object = SimpleClass.fromJson(_defaultInput); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_defaultOutput)); + + final object2 = SimpleClass.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + + test('round trip null', () { + expect( + () => loudEncode(SimpleClass.fromJson({})), + throwsA(isA()), + ); + }); + + test('round trip alternate values', () { + final object = SimpleClass.fromJson(_nonDefaultJson); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_nonDefaultJson)); + expect(encoded, isNot(loudEncode(_defaultOutput))); + + final object2 = SimpleClass.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + }); // end non-nullable group + + group('nullable', () { + test('round trip', () { + final object = SimpleClassNullable.fromJson(_defaultInput); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_defaultOutput)); + + final object2 = SimpleClassNullable.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + + test('round trip null', () { + final object = SimpleClassNullable.fromJson({}); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_nullableDefaultOutput)); + final object2 = SimpleClassNullable.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + + test('round trip alternate values', () { + final object = SimpleClassNullable.fromJson(_nonDefaultJson); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_nonDefaultJson)); + expect(encoded, isNot(loudEncode(_defaultOutput))); + + final object2 = SimpleClassNullable.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + }); // end nullable group } final _defaultValue = [42, true, false, null]; final _altValue = [43, false]; -final _emptyInput = { - 'nullable': _defaultValue, +final _defaultInput = { + 'value': _defaultValue, }; final _defaultOutput = { + 'value': _defaultValue, + 'withDefault': _defaultValue, +}; + +final _nullableDefaultOutput = { 'value': null, - 'nullable': _defaultValue, 'withDefault': _defaultValue, }; final _nonDefaultJson = { - 'value': null, - 'nullable': _altValue, + 'value': _altValue, 'withDefault': _altValue, }; diff --git a/json_serializable/test/supported_types/type_test.list_test.dart b/json_serializable/test/supported_types/type_test.list_test.dart index 96ccc6751..f68b17243 100644 --- a/json_serializable/test/supported_types/type_test.list_test.dart +++ b/json_serializable/test/supported_types/type_test.list_test.dart @@ -2,8 +2,12 @@ // 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. +// @dart=2.12 + // ignore_for_file: prefer_const_declarations +import 'dart:convert'; + @TestOn('vm') import 'package:test/test.dart'; @@ -11,33 +15,97 @@ import '../test_utils.dart'; import 'input.type_list.dart'; void main() { - test('round trip', () { - final object = SimpleClass.fromJson(_emptyInput); - expect(loudEncode(object), loudEncode(_defaultOutput)); - }); - - test('round trip alternate values', () { - final object = SimpleClass.fromJson(_nonDefaultJson); - expect(loudEncode(object), loudEncode(_nonDefaultJson)); - expect(loudEncode(object), isNot(loudEncode(_defaultOutput))); - }); + group('non-nullable', () { + test('round trip', () { + final object = SimpleClass.fromJson(_defaultInput); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_defaultOutput)); + + final object2 = SimpleClass.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + + test('round trip null', () { + expect( + () => loudEncode(SimpleClass.fromJson({})), + throwsA(isA()), + ); + }); + + test('round trip alternate values', () { + final object = SimpleClass.fromJson(_nonDefaultJson); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_nonDefaultJson)); + expect(encoded, isNot(loudEncode(_defaultOutput))); + + final object2 = SimpleClass.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + }); // end non-nullable group + + group('nullable', () { + test('round trip', () { + final object = SimpleClassNullable.fromJson(_defaultInput); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_defaultOutput)); + + final object2 = SimpleClassNullable.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + + test('round trip null', () { + final object = SimpleClassNullable.fromJson({}); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_nullableDefaultOutput)); + final object2 = SimpleClassNullable.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + + test('round trip alternate values', () { + final object = SimpleClassNullable.fromJson(_nonDefaultJson); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_nonDefaultJson)); + expect(encoded, isNot(loudEncode(_defaultOutput))); + + final object2 = SimpleClassNullable.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + }); // end nullable group } final _defaultValue = [42, true, false, null]; final _altValue = [43, false]; -final _emptyInput = { - 'nullable': _defaultValue, +final _defaultInput = { + 'value': _defaultValue, }; final _defaultOutput = { + 'value': _defaultValue, + 'withDefault': _defaultValue, +}; + +final _nullableDefaultOutput = { 'value': null, - 'nullable': _defaultValue, 'withDefault': _defaultValue, }; final _nonDefaultJson = { - 'value': null, - 'nullable': _altValue, + 'value': _altValue, 'withDefault': _altValue, }; diff --git a/json_serializable/test/supported_types/type_test.map_test.dart b/json_serializable/test/supported_types/type_test.map_test.dart index 62b062586..3dc129caf 100644 --- a/json_serializable/test/supported_types/type_test.map_test.dart +++ b/json_serializable/test/supported_types/type_test.map_test.dart @@ -2,8 +2,12 @@ // 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. +// @dart=2.12 + // ignore_for_file: prefer_const_declarations +import 'dart:convert'; + @TestOn('vm') import 'package:test/test.dart'; @@ -11,33 +15,97 @@ import '../test_utils.dart'; import 'input.type_map.dart'; void main() { - test('round trip', () { - final object = SimpleClass.fromJson(_emptyInput); - expect(loudEncode(object), loudEncode(_defaultOutput)); - }); - - test('round trip alternate values', () { - final object = SimpleClass.fromJson(_nonDefaultJson); - expect(loudEncode(object), loudEncode(_nonDefaultJson)); - expect(loudEncode(object), isNot(loudEncode(_defaultOutput))); - }); + group('non-nullable', () { + test('round trip', () { + final object = SimpleClass.fromJson(_defaultInput); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_defaultOutput)); + + final object2 = SimpleClass.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + + test('round trip null', () { + expect( + () => loudEncode(SimpleClass.fromJson({})), + throwsA(isA()), + ); + }); + + test('round trip alternate values', () { + final object = SimpleClass.fromJson(_nonDefaultJson); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_nonDefaultJson)); + expect(encoded, isNot(loudEncode(_defaultOutput))); + + final object2 = SimpleClass.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + }); // end non-nullable group + + group('nullable', () { + test('round trip', () { + final object = SimpleClassNullable.fromJson(_defaultInput); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_defaultOutput)); + + final object2 = SimpleClassNullable.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + + test('round trip null', () { + final object = SimpleClassNullable.fromJson({}); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_nullableDefaultOutput)); + final object2 = SimpleClassNullable.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + + test('round trip alternate values', () { + final object = SimpleClassNullable.fromJson(_nonDefaultJson); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_nonDefaultJson)); + expect(encoded, isNot(loudEncode(_defaultOutput))); + + final object2 = SimpleClassNullable.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + }); // end nullable group } final _defaultValue = {'a': 1}; final _altValue = {'b': 2}; -final _emptyInput = { - 'nullable': _defaultValue, +final _defaultInput = { + 'value': _defaultValue, }; final _defaultOutput = { + 'value': _defaultValue, + 'withDefault': _defaultValue, +}; + +final _nullableDefaultOutput = { 'value': null, - 'nullable': _defaultValue, 'withDefault': _defaultValue, }; final _nonDefaultJson = { - 'value': null, - 'nullable': _altValue, + 'value': _altValue, 'withDefault': _altValue, }; diff --git a/json_serializable/test/supported_types/type_test.num_test.dart b/json_serializable/test/supported_types/type_test.num_test.dart index 0ab60c852..97366d238 100644 --- a/json_serializable/test/supported_types/type_test.num_test.dart +++ b/json_serializable/test/supported_types/type_test.num_test.dart @@ -2,8 +2,12 @@ // 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. +// @dart=2.12 + // ignore_for_file: prefer_const_declarations +import 'dart:convert'; + @TestOn('vm') import 'package:test/test.dart'; @@ -11,33 +15,97 @@ import '../test_utils.dart'; import 'input.type_num.dart'; void main() { - test('round trip', () { - final object = SimpleClass.fromJson(_emptyInput); - expect(loudEncode(object), loudEncode(_defaultOutput)); - }); - - test('round trip alternate values', () { - final object = SimpleClass.fromJson(_nonDefaultJson); - expect(loudEncode(object), loudEncode(_nonDefaultJson)); - expect(loudEncode(object), isNot(loudEncode(_defaultOutput))); - }); + group('non-nullable', () { + test('round trip', () { + final object = SimpleClass.fromJson(_defaultInput); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_defaultOutput)); + + final object2 = SimpleClass.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + + test('round trip null', () { + expect( + () => loudEncode(SimpleClass.fromJson({})), + throwsA(isA()), + ); + }); + + test('round trip alternate values', () { + final object = SimpleClass.fromJson(_nonDefaultJson); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_nonDefaultJson)); + expect(encoded, isNot(loudEncode(_defaultOutput))); + + final object2 = SimpleClass.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + }); // end non-nullable group + + group('nullable', () { + test('round trip', () { + final object = SimpleClassNullable.fromJson(_defaultInput); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_defaultOutput)); + + final object2 = SimpleClassNullable.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + + test('round trip null', () { + final object = SimpleClassNullable.fromJson({}); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_nullableDefaultOutput)); + final object2 = SimpleClassNullable.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + + test('round trip alternate values', () { + final object = SimpleClassNullable.fromJson(_nonDefaultJson); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_nonDefaultJson)); + expect(encoded, isNot(loudEncode(_defaultOutput))); + + final object2 = SimpleClassNullable.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + }); // end nullable group } final _defaultValue = 88.6; final _altValue = 29; -final _emptyInput = { - 'nullable': _defaultValue, +final _defaultInput = { + 'value': _defaultValue, }; final _defaultOutput = { + 'value': _defaultValue, + 'withDefault': _defaultValue, +}; + +final _nullableDefaultOutput = { 'value': null, - 'nullable': _defaultValue, 'withDefault': _defaultValue, }; final _nonDefaultJson = { - 'value': null, - 'nullable': _altValue, + 'value': _altValue, 'withDefault': _altValue, }; diff --git a/json_serializable/test/supported_types/type_test.object_test.dart b/json_serializable/test/supported_types/type_test.object_test.dart index 30b9c8642..cec28c617 100644 --- a/json_serializable/test/supported_types/type_test.object_test.dart +++ b/json_serializable/test/supported_types/type_test.object_test.dart @@ -2,8 +2,12 @@ // 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. +// @dart=2.12 + // ignore_for_file: prefer_const_declarations +import 'dart:convert'; + @TestOn('vm') import 'package:test/test.dart'; @@ -11,31 +15,97 @@ import '../test_utils.dart'; import 'input.type_object.dart'; void main() { - test('round trip', () { - final object = SimpleClass.fromJson(_emptyInput); - expect(loudEncode(object), loudEncode(_defaultOutput)); - }); - - test('round trip alternate values', () { - final object = SimpleClass.fromJson(_nonDefaultJson); - expect(loudEncode(object), loudEncode(_nonDefaultJson)); - expect(loudEncode(object), isNot(loudEncode(_defaultOutput))); - }); + group('non-nullable', () { + test('round trip', () { + final object = SimpleClass.fromJson(_defaultInput); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_defaultOutput)); + + final object2 = SimpleClass.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + + test('round trip null', () { + expect( + () => loudEncode(SimpleClass.fromJson({})), + throwsA(isA()), + ); + }); + + test('round trip alternate values', () { + final object = SimpleClass.fromJson(_nonDefaultJson); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_nonDefaultJson)); + expect(encoded, isNot(loudEncode(_defaultOutput))); + + final object2 = SimpleClass.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + }); // end non-nullable group + + group('nullable', () { + test('round trip', () { + final object = SimpleClassNullable.fromJson(_defaultInput); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_defaultOutput)); + + final object2 = SimpleClassNullable.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + + test('round trip null', () { + final object = SimpleClassNullable.fromJson({}); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_nullableDefaultOutput)); + final object2 = SimpleClassNullable.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + + test('round trip alternate values', () { + final object = SimpleClassNullable.fromJson(_nonDefaultJson); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_nonDefaultJson)); + expect(encoded, isNot(loudEncode(_defaultOutput))); + + final object2 = SimpleClassNullable.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + }); // end nullable group } -final _defaultValue = null; -final _altValue = 'Object'; +final _defaultValue = 'o1'; +final _altValue = 'o2'; -final _emptyInput = { - 'nullable': _defaultValue, +final _defaultInput = { + 'value': _defaultValue, }; final _defaultOutput = { + 'value': _defaultValue, + 'withDefault': _defaultValue, +}; + +final _nullableDefaultOutput = { 'value': null, - 'nullable': _defaultValue, + 'withDefault': _defaultValue, }; final _nonDefaultJson = { - 'value': null, - 'nullable': _altValue, + 'value': _altValue, + 'withDefault': _altValue, }; diff --git a/json_serializable/test/supported_types/type_test.set_test.dart b/json_serializable/test/supported_types/type_test.set_test.dart index 10db9945f..1e8c63169 100644 --- a/json_serializable/test/supported_types/type_test.set_test.dart +++ b/json_serializable/test/supported_types/type_test.set_test.dart @@ -2,8 +2,12 @@ // 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. +// @dart=2.12 + // ignore_for_file: prefer_const_declarations +import 'dart:convert'; + @TestOn('vm') import 'package:test/test.dart'; @@ -11,33 +15,97 @@ import '../test_utils.dart'; import 'input.type_set.dart'; void main() { - test('round trip', () { - final object = SimpleClass.fromJson(_emptyInput); - expect(loudEncode(object), loudEncode(_defaultOutput)); - }); - - test('round trip alternate values', () { - final object = SimpleClass.fromJson(_nonDefaultJson); - expect(loudEncode(object), loudEncode(_nonDefaultJson)); - expect(loudEncode(object), isNot(loudEncode(_defaultOutput))); - }); + group('non-nullable', () { + test('round trip', () { + final object = SimpleClass.fromJson(_defaultInput); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_defaultOutput)); + + final object2 = SimpleClass.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + + test('round trip null', () { + expect( + () => loudEncode(SimpleClass.fromJson({})), + throwsA(isA()), + ); + }); + + test('round trip alternate values', () { + final object = SimpleClass.fromJson(_nonDefaultJson); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_nonDefaultJson)); + expect(encoded, isNot(loudEncode(_defaultOutput))); + + final object2 = SimpleClass.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + }); // end non-nullable group + + group('nullable', () { + test('round trip', () { + final object = SimpleClassNullable.fromJson(_defaultInput); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_defaultOutput)); + + final object2 = SimpleClassNullable.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + + test('round trip null', () { + final object = SimpleClassNullable.fromJson({}); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_nullableDefaultOutput)); + final object2 = SimpleClassNullable.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + + test('round trip alternate values', () { + final object = SimpleClassNullable.fromJson(_nonDefaultJson); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_nonDefaultJson)); + expect(encoded, isNot(loudEncode(_defaultOutput))); + + final object2 = SimpleClassNullable.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + }); // end nullable group } final _defaultValue = [42, true, false, null]; final _altValue = [43, false]; -final _emptyInput = { - 'nullable': _defaultValue, +final _defaultInput = { + 'value': _defaultValue, }; final _defaultOutput = { + 'value': _defaultValue, + 'withDefault': _defaultValue, +}; + +final _nullableDefaultOutput = { 'value': null, - 'nullable': _defaultValue, 'withDefault': _defaultValue, }; final _nonDefaultJson = { - 'value': null, - 'nullable': _altValue, + 'value': _altValue, 'withDefault': _altValue, }; diff --git a/json_serializable/test/supported_types/type_test.string_test.dart b/json_serializable/test/supported_types/type_test.string_test.dart index 04556ee90..cc12969c8 100644 --- a/json_serializable/test/supported_types/type_test.string_test.dart +++ b/json_serializable/test/supported_types/type_test.string_test.dart @@ -2,8 +2,12 @@ // 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. +// @dart=2.12 + // ignore_for_file: prefer_const_declarations +import 'dart:convert'; + @TestOn('vm') import 'package:test/test.dart'; @@ -11,33 +15,97 @@ import '../test_utils.dart'; import 'input.type_string.dart'; void main() { - test('round trip', () { - final object = SimpleClass.fromJson(_emptyInput); - expect(loudEncode(object), loudEncode(_defaultOutput)); - }); - - test('round trip alternate values', () { - final object = SimpleClass.fromJson(_nonDefaultJson); - expect(loudEncode(object), loudEncode(_nonDefaultJson)); - expect(loudEncode(object), isNot(loudEncode(_defaultOutput))); - }); + group('non-nullable', () { + test('round trip', () { + final object = SimpleClass.fromJson(_defaultInput); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_defaultOutput)); + + final object2 = SimpleClass.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + + test('round trip null', () { + expect( + () => loudEncode(SimpleClass.fromJson({})), + throwsA(isA()), + ); + }); + + test('round trip alternate values', () { + final object = SimpleClass.fromJson(_nonDefaultJson); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_nonDefaultJson)); + expect(encoded, isNot(loudEncode(_defaultOutput))); + + final object2 = SimpleClass.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + }); // end non-nullable group + + group('nullable', () { + test('round trip', () { + final object = SimpleClassNullable.fromJson(_defaultInput); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_defaultOutput)); + + final object2 = SimpleClassNullable.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + + test('round trip null', () { + final object = SimpleClassNullable.fromJson({}); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_nullableDefaultOutput)); + final object2 = SimpleClassNullable.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + + test('round trip alternate values', () { + final object = SimpleClassNullable.fromJson(_nonDefaultJson); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_nonDefaultJson)); + expect(encoded, isNot(loudEncode(_defaultOutput))); + + final object2 = SimpleClassNullable.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + }); // end nullable group } final _defaultValue = 'a string'; final _altValue = 'another string'; -final _emptyInput = { - 'nullable': _defaultValue, +final _defaultInput = { + 'value': _defaultValue, }; final _defaultOutput = { + 'value': _defaultValue, + 'withDefault': _defaultValue, +}; + +final _nullableDefaultOutput = { 'value': null, - 'nullable': _defaultValue, 'withDefault': _defaultValue, }; final _nonDefaultJson = { - 'value': null, - 'nullable': _altValue, + 'value': _altValue, 'withDefault': _altValue, }; diff --git a/json_serializable/test/supported_types/type_test.uri_test.dart b/json_serializable/test/supported_types/type_test.uri_test.dart index 6784d840a..fff3fc43e 100644 --- a/json_serializable/test/supported_types/type_test.uri_test.dart +++ b/json_serializable/test/supported_types/type_test.uri_test.dart @@ -2,8 +2,12 @@ // 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. +// @dart=2.12 + // ignore_for_file: prefer_const_declarations +import 'dart:convert'; + @TestOn('vm') import 'package:test/test.dart'; @@ -11,31 +15,94 @@ import '../test_utils.dart'; import 'input.type_uri.dart'; void main() { - test('round trip', () { - final object = SimpleClass.fromJson(_emptyInput); - expect(loudEncode(object), loudEncode(_defaultOutput)); - }); - - test('round trip alternate values', () { - final object = SimpleClass.fromJson(_nonDefaultJson); - expect(loudEncode(object), loudEncode(_nonDefaultJson)); - expect(loudEncode(object), isNot(loudEncode(_defaultOutput))); - }); + group('non-nullable', () { + test('round trip', () { + final object = SimpleClass.fromJson(_defaultInput); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_defaultOutput)); + + final object2 = SimpleClass.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + + test('round trip null', () { + expect( + () => loudEncode(SimpleClass.fromJson({})), + throwsA(isA()), + ); + }); + + test('round trip alternate values', () { + final object = SimpleClass.fromJson(_nonDefaultJson); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_nonDefaultJson)); + expect(encoded, isNot(loudEncode(_defaultOutput))); + + final object2 = SimpleClass.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + }); // end non-nullable group + + group('nullable', () { + test('round trip', () { + final object = SimpleClassNullable.fromJson(_defaultInput); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_defaultOutput)); + + final object2 = SimpleClassNullable.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + + test('round trip null', () { + final object = SimpleClassNullable.fromJson({}); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_nullableDefaultOutput)); + final object2 = SimpleClassNullable.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + + test('round trip alternate values', () { + final object = SimpleClassNullable.fromJson(_nonDefaultJson); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_nonDefaultJson)); + expect(encoded, isNot(loudEncode(_defaultOutput))); + + final object2 = SimpleClassNullable.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + }); // end nullable group } final _defaultValue = 'https://example.com'; final _altValue = 'https://dart.dev'; -final _emptyInput = { - 'nullable': _defaultValue, +final _defaultInput = { + 'value': _defaultValue, }; final _defaultOutput = { + 'value': _defaultValue, +}; + +final _nullableDefaultOutput = { 'value': null, - 'nullable': _defaultValue, }; final _nonDefaultJson = { - 'value': null, - 'nullable': _altValue, + 'value': _altValue, }; diff --git a/json_serializable/test/test_sources/test_sources.dart b/json_serializable/test/test_sources/test_sources.dart index 198398e53..e14ad6205 100644 --- a/json_serializable/test/test_sources/test_sources.dart +++ b/json_serializable/test/test_sources/test_sources.dart @@ -1,8 +1,10 @@ +// @dart=2.12 + import 'package:json_annotation/json_annotation.dart'; @JsonSerializable() class ConfigurationImplicitDefaults { - int field; + int? field; } @JsonSerializable( @@ -15,18 +17,17 @@ class ConfigurationImplicitDefaults { fieldRename: FieldRename.none, ignoreUnannotated: false, includeIfNull: true, - nullable: true, genericArgumentFactories: false, ) class ConfigurationExplicitDefaults { - int field; + int? field; } @JsonSerializable(createFactory: false) class IncludeIfNullAll { @JsonKey(includeIfNull: true) - int number; - String str; + int? number; + String? str; } @JsonSerializable(createToJson: false) @@ -43,39 +44,39 @@ class ChildWithFromJson { @JsonSerializable() class ParentObject { - int number; - String str; - ChildObject child; + int? number; + String? str; + ChildObject? child; } @JsonSerializable() class ChildObject { - int number; - String str; + int? number; + String? str; } @JsonSerializable() class ParentObjectWithChildren { - int number; - String str; - List children; + int? number; + String? str; + List? children; } @JsonSerializable() class ParentObjectWithDynamicChildren { - int number; - String str; - List children; + int? number; + String? str; + late List children; } @JsonSerializable(createFactory: false, explicitToJson: true) class TrivialNestedNullable { - TrivialNestedNullable child; - int otherField; + TrivialNestedNullable? child; + int? otherField; } -@JsonSerializable(createFactory: false, nullable: false, explicitToJson: true) +@JsonSerializable(createFactory: false, explicitToJson: true) class TrivialNestedNonNullable { - TrivialNestedNonNullable child; - int otherField; + late TrivialNestedNonNullable child; + int? otherField; } diff --git a/json_serializable/test/test_utils.dart b/json_serializable/test/test_utils.dart index 51e6190f4..84bcdf4e7 100644 --- a/json_serializable/test/test_utils.dart +++ b/json_serializable/test/test_utils.dart @@ -2,8 +2,11 @@ // 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. +// @dart=2.12 + import 'dart:convert'; +import 'package:stack_trace/stack_trace.dart'; import 'package:test/test.dart'; // ignore: deprecated_member_use @@ -23,17 +26,30 @@ T roundTripObject(T object, T Function(Map json) factory) { } /// Prints out nested causes before throwing `JsonUnsupportedObjectError`. -String loudEncode(Object object) { +String loudEncode(Object? object) { try { return const JsonEncoder.withIndent(' ').convert(object); - } on JsonUnsupportedObjectError catch (e) // ignore: avoid_catching_errors - { - var error = e; - do { - final cause = error.cause; - print(cause); - error = (cause is JsonUnsupportedObjectError) ? cause : null; - } while (error != null); + } catch (e) { + if (e is JsonUnsupportedObjectError) { + Object? error = e; + + var count = 1; + + while (error is JsonUnsupportedObjectError) { + print( + '(${count++}) $error ${error.unsupportedObject} (${error.unsupportedObject.runtimeType}) !!!', + ); + print(Trace.from(error.stackTrace!).terse); + error = error.cause; + } + + if (error != null) { + print('(${count++}) $error ???'); + if (error is Error) { + print(Trace.from(error.stackTrace!).terse); + } + } + } rethrow; } } diff --git a/json_serializable/tool/test_builder.dart b/json_serializable/tool/test_builder.dart index ea69a84fc..52c4a3b70 100644 --- a/json_serializable/tool/test_builder.dart +++ b/json_serializable/tool/test_builder.dart @@ -63,6 +63,10 @@ class _TestBuilder implements Builder { final newId = buildStep.inputId.changeExtension('.factories.dart'); final lines = [ + r''' +// GENERATED CODE - DO NOT MODIFY BY HAND +// @dart=2.12 +''', ...factories.entries.map((e) => "import '${e.key}' as ${e.value};"), 'const factories = [', ...factories.values.map((e) => '$e.factory,'), @@ -81,7 +85,6 @@ class _TestBuilder implements Builder { const _configReplacements = { 'any_map': Replacement.addJsonSerializableKey('anyMap', true), 'checked': Replacement.addJsonSerializableKey('checked', true), - 'non_nullable': Replacement.addJsonSerializableKey('nullable', false), 'explicit_to_json': Replacement.addJsonSerializableKey('explicitToJson', true), 'exclude_null': Replacement.addJsonSerializableKey('includeIfNull', false), @@ -125,35 +128,6 @@ const _kitchenSinkReplacements = { ), ], 'non_nullable': [ - Replacement( - 'bool get nullable => true;', - 'bool get nullable => false;', - ), - Replacement( - 'List _defaultList() => null;', - 'List _defaultList() => [];', - ), - Replacement( - 'Set _defaultSet() => null;', - 'Set _defaultSet() => {};', - ), - Replacement( - 'Map _defaultMap() => null;', - 'Map _defaultMap() => {};', - ), - Replacement( - 'SimpleObject _defaultSimpleObject() => null;', - 'SimpleObject _defaultSimpleObject() => SimpleObject(42);', - ), - Replacement( - 'StrictKeysObject _defaultStrictKeysObject() => null;', - 'StrictKeysObject _defaultStrictKeysObject() => ' - "StrictKeysObject(10, 'cool');", - ), - Replacement( - 'DateTime dateTime;', - 'DateTime dateTime = DateTime(1981, 6, 5);', - ), Replacement( 'BigInt bigInt;', "BigInt bigInt = BigInt.parse('10000000000000000000');", @@ -163,7 +137,12 @@ const _kitchenSinkReplacements = { Iterable _optionReplacement( String baseName, String optionKey) sync* { - yield _configReplacements[optionKey]; + final value = _configReplacements[optionKey]; + if (value == null) { + log.warning('no replacement thingy for `$optionKey`.'); + } else { + yield value; + } if (baseName == _kitchenSinkBaseName && _kitchenSinkReplacements.containsKey(optionKey)) { @@ -189,12 +168,9 @@ const _kitchenSinkBaseName = 'kitchen_sink'; const _fileConfigurationMap = >>{ _kitchenSinkBaseName: { - {'any_map', 'checked', 'non_nullable'}, - {'any_map', 'non_nullable'}, + {'any_map', 'checked'}, {'any_map'}, {'exclude_null'}, - {'non_nullable'}, - {'exclude_null', 'non_nullable'}, {'explicit_to_json'}, }, 'default_value': { @@ -203,6 +179,8 @@ const _fileConfigurationMap = >>{ 'generic_class': >{}, 'json_test_example': { {'any_map'}, - {'non_nullable'}, - } + }, + 'null_safety': >{ + {'any_map'}, + }, }; diff --git a/json_serializable/tool/test_type_builder.dart b/json_serializable/tool/test_type_builder.dart index a1eb4d18e..773e574fc 100644 --- a/json_serializable/tool/test_type_builder.dart +++ b/json_serializable/tool/test_type_builder.dart @@ -34,21 +34,22 @@ const _trivialTypesToTest = { jsonExpression: '1234', altJsonExpression: '2345', ), - 'int': TestTypeData( - defaultExpression: '42', - altJsonExpression: '43', - ), customEnumType: TestTypeData( defaultExpression: '$customEnumType.alpha', jsonExpression: "'alpha'", altJsonExpression: "'beta'", ), + 'int': TestTypeData( + defaultExpression: '42', + altJsonExpression: '43', + ), 'num': TestTypeData( defaultExpression: '88.6', altJsonExpression: '29', ), 'Object': TestTypeData( - altJsonExpression: "'Object'", + defaultExpression: "'o1'", + altJsonExpression: "'o2'", ), 'String': TestTypeData( defaultExpression: "'a string'", @@ -103,6 +104,7 @@ const _mapKeyTypes = { final _iterableGenericArgs = ([ ..._trivialTypesToTest.keys, + ..._trivialTypesToTest.keys.map((e) => '$e?'), 'dynamic', ]..sort(compareAsciiLowerCase)) .toSet(); diff --git a/json_serializable/tool/test_type_data.dart b/json_serializable/tool/test_type_data.dart index 1036e3231..6417b64c3 100644 --- a/json_serializable/tool/test_type_data.dart +++ b/json_serializable/tool/test_type_data.dart @@ -50,23 +50,47 @@ class TestTypeData { final simpleClassContent = '$classAnnotationSplit${split[1]}'; - buffer.write(Replacement.generate( - simpleClassContent, - _libReplacements(type), - )); + buffer + ..write( + Replacement.generate( + simpleClassContent, + _libReplacements(type), + ), + ) + ..write( + Replacement.generate( + simpleClassContent.replaceAll( + 'SimpleClass', + 'SimpleClassNullable', + ), + _libReplacements('$type?'), + ), + ); for (var genericArg in genericArgs) { final genericArgClassPart = _genericClassPart(genericArg); final genericType = '$type<$genericArg>'; - buffer.write(Replacement.generate( - simpleClassContent.replaceAll( - 'SimpleClass', - 'SimpleClass$genericArgClassPart', - ), - _libReplacements(genericType), - )); + buffer + ..write( + Replacement.generate( + simpleClassContent.replaceAll( + 'SimpleClass', + 'SimpleClassOf$genericArgClassPart', + ), + _libReplacements(genericType), + ), + ) + ..write( + Replacement.generate( + simpleClassContent.replaceAll( + 'SimpleClass', + 'SimpleClassNullableOf$genericArgClassPart', + ), + _libReplacements('$genericType?'), + ), + ); } return buffer.toString(); @@ -77,15 +101,13 @@ class TestTypeData { 'final dynamic value;', 'final $type value;', ); - yield Replacement( - 'final dynamic nullable;', - 'final $type nullable;', - ); - final defaultReplacement = (defaultExpression == null // no default provided + final defaultNotSupported = defaultExpression == null // no default provided || type.contains('<') // no support for default values and generic args - ) + ; + + final defaultReplacement = defaultNotSupported ? '' : _defaultSource .replaceFirst('42', defaultExpression) @@ -95,12 +117,59 @@ class TestTypeData { _defaultSource, defaultReplacement, ); + + if (defaultNotSupported) { + yield const Replacement( + ' this.withDefault,', + '', + ); + } } - String testContent(String sourceContent, String type) => Replacement.generate( - sourceContent, - _testReplacements(type), + String testContent(String sourceContent, String type) { + const groupStart = "\n group('non-nullable', () {"; + const groupEnd = '}); // end non-nullable group\n'; + + final startIndex = sourceContent.indexOf(groupStart); + final endIndex = sourceContent.indexOf(groupEnd) + groupEnd.length; + + final groupContent = sourceContent.substring(startIndex, endIndex); + + final nullableGroupContent = groupContent + .replaceAll('non-nullable', 'nullable') + .replaceAll('SimpleClass', 'SimpleClassNullable'); + + final thrownError = type == customEnumType ? 'ArgumentError' : 'TypeError'; + + final newGroupContent = groupContent.replaceAll( + r''' + final object = SimpleClass.fromJson({}); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(_nullableDefaultOutput)); + final object2 = SimpleClass.fromJson( + jsonDecode(encoded) as Map, ); + expect(loudEncode(object2), encoded);''', + ''' + expect( + () => loudEncode(SimpleClass.fromJson({})), + throwsA(isA<$thrownError>()), + );''', + ); + + final updatedSourceContent = [ + sourceContent.substring(0, startIndex), + newGroupContent, + nullableGroupContent, + sourceContent.substring(endIndex), + ].join(); + + return Replacement.generate( + updatedSourceContent, + _testReplacements(type), + ); + } Iterable _testReplacements(String type) sync* { yield Replacement( @@ -139,6 +208,7 @@ final _altValue = $altJsonExpression; } String _genericClassPart(String genericArg) => genericArg + .replaceAll('?', 'Nullable') .split(',') .map((e) => [ e.substring(0, 1).toUpperCase(), From 3fd508e1fbe01a283ca813dcb90bfbc2d048437f Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 2 Dec 2020 09:38:27 -0800 Subject: [PATCH 253/569] Support the latest pkg:analyzer and prepare to release v3.5.1 (#760) * update github config --- .github/workflows/dart.yml | 2 +- json_serializable/CHANGELOG.md | 3 ++- json_serializable/pubspec.yaml | 6 +++--- mono_repo.yaml | 9 ++++++++- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 7d633f72a..f861ae144 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -3,8 +3,8 @@ name: Dart CI on: push: branches: - - main - master + - "3_x" pull_request: schedule: - cron: "0 0 * * 0" diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index e78e7f946..bc78f0c6d 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,8 +1,9 @@ -## 3.5.1-dev +## 3.5.1 - Improved error messages for unsupported types. - `package:json_serializable/type_helper.dart` - Made the third parameter to `UnsupportedTypeError` positional (optional). +- Require `package:analyzer` `>=0.39.0 <0.42.0`. ## 3.5.0 diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 53bb2223c..a88770c03 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,14 +1,14 @@ name: json_serializable -version: 3.5.0-dev +version: 3.5.1 description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. -homepage: https://github.com/google/json_serializable.dart +repository: https://github.com/google/json_serializable.dart environment: sdk: '>=2.7.0 <3.0.0' dependencies: - analyzer: '>=0.39.0 <0.41.0' + analyzer: '>=0.39.0 <0.42.0' build: '>=0.12.6 <2.0.0' build_config: '>=0.2.6 <0.5.0' diff --git a/mono_repo.yaml b/mono_repo.yaml index e4ceeb944..fa5d6056e 100644 --- a/mono_repo.yaml +++ b/mono_repo.yaml @@ -2,7 +2,14 @@ self_validate: analyzer_and_format github: - cron: '0 0 * * 0' # “At 00:00 (UTC) on Sunday.” + on: + push: + branches: + - master + - 3_x + pull_request: + schedule: + - cron: "0 0 * * 0" merge_stages: - analyzer_and_format From 30e050527367376773a98d477c22f50cd838aed8 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 2 Dec 2020 11:10:39 -0800 Subject: [PATCH 254/569] fix bad merge - analyzer constraint (#761) --- json_serializable/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 82d71cc5d..73e95175a 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -8,7 +8,7 @@ environment: sdk: '>=2.11.0 <3.0.0' dependencies: - analyzer: ^0.40.6 + analyzer: '>=0.40.6 <0.42.0' build: '>=0.12.6 <2.0.0' build_config: '>=0.2.6 <0.5.0' From c1c1d820647368ea04e7b3b460fa57844a602d97 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 2 Dec 2020 17:36:42 -0800 Subject: [PATCH 255/569] Migrate checked_yaml to null safety (#762) Fixes https://github.com/google/json_serializable.dart/issues/758 --- .github/workflows/dart.yml | 123 +----------------- _test_yaml/mono_pkg.yaml | 3 +- _test_yaml/pubspec.yaml | 3 + _test_yaml/test/yaml_test.dart | 7 +- checked_yaml/changelog.md | 5 +- checked_yaml/example/example.dart | 14 +- checked_yaml/lib/checked_yaml.dart | 30 ++--- checked_yaml/mono_pkg.yaml | 7 +- checked_yaml/pubspec.yaml | 19 ++- checked_yaml/readme.md | 14 +- checked_yaml/test/ensure_build_test.dart | 2 + checked_yaml/test/readme_test.dart | 2 + example/mono_pkg.yaml | 2 +- json_annotation/mono_pkg.yaml | 2 +- json_serializable/mono_pkg.yaml | 2 +- json_serializable/pubspec.yaml | 5 +- .../kitchen_sink/kitchen_sink_yaml_test.dart | 6 +- json_serializable/tool/shared.dart | 2 +- tool/ci.sh | 10 +- 19 files changed, 84 insertions(+), 174 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index a74552f5c..2e035bd37 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -36,16 +36,16 @@ jobs: - run: pub global activate mono_repo 3.3.0 - run: pub global run mono_repo generate --validate job_002: - name: "OS: linux; SDK: dev; PKGS: _test_yaml, checked_yaml, json_annotation, json_serializable; TASKS: [`dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-warnings --fatal-infos .`]" + name: "OS: linux; SDK: dev; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; TASKS: [`dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-infos .`]" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@v2 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:_test_yaml-checked_yaml-json_annotation-json_serializable;commands:dartfmt-dartanalyzer_0" + key: "os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:dartfmt-dartanalyzer" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:_test_yaml-checked_yaml-json_annotation-json_serializable + os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable os:ubuntu-latest;pub-cache-hosted;dart:dev os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest @@ -55,56 +55,9 @@ jobs: - run: dart --version - uses: actions/checkout@v2 - env: - PKGS: _test_yaml checked_yaml json_annotation json_serializable + PKGS: _test_yaml checked_yaml example json_annotation json_serializable TRAVIS_OS_NAME: linux - run: tool/ci.sh dartfmt dartanalyzer_0 - job_005: - name: "OS: linux; SDK: 2.7.0; PKG: checked_yaml; TASKS: `dartanalyzer --fatal-warnings .`" - runs-on: ubuntu-latest - steps: - - name: Cache Pub hosted dependencies - uses: actions/cache@v2 - with: - path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;dart:2.7.0;packages:checked_yaml;commands:dartanalyzer_1" - restore-keys: | - os:ubuntu-latest;pub-cache-hosted;dart:2.7.0;packages:checked_yaml - os:ubuntu-latest;pub-cache-hosted;dart:2.7.0 - os:ubuntu-latest;pub-cache-hosted - os:ubuntu-latest - - uses: cedx/setup-dart@v2 - with: - release-channel: stable - version: "2.7.0" - - run: dart --version - - uses: actions/checkout@v2 - - env: - PKGS: checked_yaml - TRAVIS_OS_NAME: linux - run: tool/ci.sh dartanalyzer_1 - job_008: - name: "OS: linux; SDK: dev; PKG: example; TASKS: [`dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-warnings .`]" - runs-on: ubuntu-latest - steps: - - name: Cache Pub hosted dependencies - uses: actions/cache@v2 - with: - path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:example;commands:dartfmt-dartanalyzer_1" - restore-keys: | - os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:example - os:ubuntu-latest;pub-cache-hosted;dart:dev - os:ubuntu-latest;pub-cache-hosted - os:ubuntu-latest - - uses: cedx/setup-dart@v2 - with: - release-channel: dev - - run: dart --version - - uses: actions/checkout@v2 - - env: - PKGS: example - TRAVIS_OS_NAME: linux - run: tool/ci.sh dartfmt dartanalyzer_1 + run: tool/ci.sh dartfmt dartanalyzer job_003: name: "OS: linux; SDK: dev; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test`" runs-on: ubuntu-latest @@ -131,38 +84,7 @@ jobs: needs: - job_001 - job_002 - - job_005 - - job_008 - job_006: - name: "OS: linux; SDK: 2.7.0; PKG: checked_yaml; TASKS: `pub run test`" - runs-on: ubuntu-latest - steps: - - name: Cache Pub hosted dependencies - uses: actions/cache@v2 - with: - path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;dart:2.7.0;packages:checked_yaml;commands:test_0" - restore-keys: | - os:ubuntu-latest;pub-cache-hosted;dart:2.7.0;packages:checked_yaml - os:ubuntu-latest;pub-cache-hosted;dart:2.7.0 - os:ubuntu-latest;pub-cache-hosted - os:ubuntu-latest - - uses: cedx/setup-dart@v2 - with: - release-channel: stable - version: "2.7.0" - - run: dart --version - - uses: actions/checkout@v2 - - env: - PKGS: checked_yaml - TRAVIS_OS_NAME: linux - run: tool/ci.sh test_0 - needs: - - job_001 - - job_002 - - job_005 - - job_008 - job_009: + job_005: name: "OS: linux; SDK: dev; PKG: json_serializable; TASKS: `pub run test -p chrome`" runs-on: ubuntu-latest steps: @@ -188,8 +110,6 @@ jobs: needs: - job_001 - job_002 - - job_005 - - job_008 job_004: name: "OS: linux; SDK: dev; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest @@ -215,33 +135,4 @@ jobs: run: tool/ci.sh test_1 needs: - job_003 - - job_006 - - job_009 - job_007: - name: "OS: linux; SDK: 2.7.0; PKG: checked_yaml; TASKS: `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`" - runs-on: ubuntu-latest - steps: - - name: Cache Pub hosted dependencies - uses: actions/cache@v2 - with: - path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;dart:2.7.0;packages:checked_yaml;commands:test_1" - restore-keys: | - os:ubuntu-latest;pub-cache-hosted;dart:2.7.0;packages:checked_yaml - os:ubuntu-latest;pub-cache-hosted;dart:2.7.0 - os:ubuntu-latest;pub-cache-hosted - os:ubuntu-latest - - uses: cedx/setup-dart@v2 - with: - release-channel: stable - version: "2.7.0" - - run: dart --version - - uses: actions/checkout@v2 - - env: - PKGS: checked_yaml - TRAVIS_OS_NAME: linux - run: tool/ci.sh test_1 - needs: - - job_003 - - job_006 - - job_009 + - job_005 diff --git a/_test_yaml/mono_pkg.yaml b/_test_yaml/mono_pkg.yaml index 5525b49be..fc8565fd2 100644 --- a/_test_yaml/mono_pkg.yaml +++ b/_test_yaml/mono_pkg.yaml @@ -6,8 +6,7 @@ stages: - analyzer_and_format: - group: - dartfmt - - dartanalyzer: --fatal-warnings --fatal-infos . - dart: [dev] + - dartanalyzer: --fatal-infos . - unit_test: - test - ensure_build: diff --git a/_test_yaml/pubspec.yaml b/_test_yaml/pubspec.yaml index 819790eb4..ad32a8485 100644 --- a/_test_yaml/pubspec.yaml +++ b/_test_yaml/pubspec.yaml @@ -19,3 +19,6 @@ dependency_overrides: path: ../json_annotation json_serializable: path: ../json_serializable + + # For yaml! + yaml: 3.0.0-nullsafety.0 diff --git a/_test_yaml/test/yaml_test.dart b/_test_yaml/test/yaml_test.dart index a869a8559..b3fdd7963 100644 --- a/_test_yaml/test/yaml_test.dart +++ b/_test_yaml/test/yaml_test.dart @@ -27,7 +27,10 @@ void main() { for (final filePath in _tests) { test(p.basenameWithoutExtension(filePath), () { final content = File(filePath).readAsStringSync(); - final yamlContent = loadYaml(content, sourceUrl: filePath) as YamlMap; + final yamlContent = loadYaml( + content, + sourceUrl: Uri.file(filePath), + ) as YamlMap; try { final config = Config.fromJson(yamlContent); @@ -47,7 +50,7 @@ void main() { for (final entry in _badConfigs.entries) { test('${index++}', () { final yamlContent = - loadYaml(entry.key, sourceUrl: 'file.yaml') as YamlMap; + loadYaml(entry.key, sourceUrl: Uri.file('file.yaml')) as YamlMap; expect(yamlContent, isNotNull); printOnFailure(entry.key); diff --git a/checked_yaml/changelog.md b/checked_yaml/changelog.md index d436fc9d3..aef7f9af4 100644 --- a/checked_yaml/changelog.md +++ b/checked_yaml/changelog.md @@ -1,6 +1,7 @@ -## 1.0.3-dev +## 2.0.0-nullsafety-dev -- Require at least Dart `2.7.0`. +- *BREAKING* `checkedYamlDecode` `sourceUrl` parameter is now a `Uri`. +- Require at least Dart `2.12.0-0`. ## 1.0.2 diff --git a/checked_yaml/example/example.dart b/checked_yaml/example/example.dart index 7e9b820a0..4cefa2439 100644 --- a/checked_yaml/example/example.dart +++ b/checked_yaml/example/example.dart @@ -13,7 +13,6 @@ part 'example.g.dart'; anyMap: true, checked: true, disallowUnrecognizedKeys: true, - nullable: false, ) class Configuration { @JsonKey(required: true) @@ -21,7 +20,7 @@ class Configuration { @JsonKey(required: true) final int count; - Configuration({this.name, this.count}) { + Configuration({required this.name, required this.count}) { if (name.isEmpty) { throw ArgumentError.value(name, 'name', 'Cannot be empty.'); } @@ -36,18 +35,21 @@ class Configuration { } void main(List arguments) { - var sourcePathOrYaml = arguments.single; + final sourcePathOrYaml = arguments.single; String yamlContent; + Uri? sourceUri; if (FileSystemEntity.isFileSync(sourcePathOrYaml)) { yamlContent = File(sourcePathOrYaml).readAsStringSync(); + sourceUri = Uri.parse(sourcePathOrYaml); } else { yamlContent = sourcePathOrYaml; - sourcePathOrYaml = null; } final config = checkedYamlDecode( - yamlContent, (m) => Configuration.fromJson(m), - sourceUrl: sourcePathOrYaml); + yamlContent, + (m) => Configuration.fromJson(m!), + sourceUrl: sourceUri, + ); print(config); } diff --git a/checked_yaml/lib/checked_yaml.dart b/checked_yaml/lib/checked_yaml.dart index f8d2aff94..3302b34a6 100644 --- a/checked_yaml/lib/checked_yaml.dart +++ b/checked_yaml/lib/checked_yaml.dart @@ -20,11 +20,10 @@ import 'package:yaml/yaml.dart'; /// `null` values. T checkedYamlDecode( String yamlContent, - T Function(Map) constructor, { - sourceUrl, + T Function(Map?) constructor, { + Uri? sourceUrl, bool allowNull = false, }) { - allowNull ??= false; YamlNode yaml; try { @@ -33,7 +32,7 @@ T checkedYamlDecode( throw ParsedYamlException.fromYamlException(e); } - Map map; + Map? map; if (yaml is YamlMap) { map = yaml; } else if (allowNull && yaml is YamlScalar && yaml.value == null) { @@ -56,7 +55,7 @@ T checkedYamlDecode( /// `package:yaml`. If not, you may provide an alternative via [exceptionMap]. ParsedYamlException toParsedYamlException( CheckedFromJsonException exception, { - YamlMap exceptionMap, + YamlMap? exceptionMap, }) { final yamlMap = exceptionMap ?? exception.map as YamlMap; @@ -71,7 +70,7 @@ ParsedYamlException toParsedYamlException( (k) => (k as YamlScalar).value == key, orElse: () => yamlMap) as YamlNode; return ParsedYamlException( - exception.message, + exception.message!, node, innerError: exception, ); @@ -81,7 +80,7 @@ ParsedYamlException toParsedYamlException( if (yamlValue == null) { // TODO: test this case! return ParsedYamlException( - exception.message, + exception.message!, yamlMap, innerError: exception, ); @@ -108,25 +107,26 @@ class ParsedYamlException implements Exception { /// The node associated with this exception. /// /// May be `null` if there was an error decoding. - final YamlNode yamlNode; + final YamlNode? yamlNode; /// If this exception was thrown as a result of another error, /// contains the source error object. - final Object innerError; + final Object? innerError; ParsedYamlException( this.message, - this.yamlNode, { + YamlNode yamlNode, { this.innerError, - }) : assert(message != null), - assert(yamlNode != null); + }) : + // ignore: prefer_initializing_formals + yamlNode = yamlNode; factory ParsedYamlException.fromYamlException(YamlException exception) => _WrappedYamlException(exception); /// Returns [message] formatted with source information provided by /// [yamlNode]. - String get formattedMessage => yamlNode.span.message(message); + String? get formattedMessage => yamlNode?.span.message(message); @override String toString() => 'ParsedYamlException: $formattedMessage'; @@ -136,7 +136,7 @@ class _WrappedYamlException implements ParsedYamlException { _WrappedYamlException(this.innerError); @override - String get formattedMessage => innerError.span.message(innerError.message); + String? get formattedMessage => innerError.span?.message(innerError.message); @override final YamlException innerError; @@ -145,7 +145,7 @@ class _WrappedYamlException implements ParsedYamlException { String get message => innerError.message; @override - YamlNode get yamlNode => null; + YamlNode? get yamlNode => null; @override String toString() => 'ParsedYamlException: $formattedMessage'; diff --git a/checked_yaml/mono_pkg.yaml b/checked_yaml/mono_pkg.yaml index 1d80a7151..18804424f 100644 --- a/checked_yaml/mono_pkg.yaml +++ b/checked_yaml/mono_pkg.yaml @@ -1,17 +1,12 @@ # See https://github.com/google/mono_repo.dart for details on this file dart: -- 2.7.0 - dev stages: - analyzer_and_format: - group: - dartfmt - - dartanalyzer: --fatal-warnings --fatal-infos . - dart: [dev] - - group: - - dartanalyzer: --fatal-warnings . - dart: [2.7.0] + - dartanalyzer: --fatal-infos . - unit_test: - test diff --git a/checked_yaml/pubspec.yaml b/checked_yaml/pubspec.yaml index ef0d6ecb2..7422c6db2 100644 --- a/checked_yaml/pubspec.yaml +++ b/checked_yaml/pubspec.yaml @@ -1,21 +1,30 @@ name: checked_yaml -version: 1.0.3-dev +version: 1.9.0-nullsafety-dev description: >- Generate more helpful exceptions when decoding YAML documents using package:json_serializable and package:yaml. homepage: https://github.com/google/json_serializable.dart environment: - sdk: '>=2.7.0 <3.0.0' + sdk: '>=2.12.0-0 <3.0.0' dependencies: json_annotation: '>=2.2.0 <4.0.0' - source_span: ^1.0.0 - yaml: ^2.1.13 + source_span: ^1.8.0-nullsafety.4 + yaml: ^3.0.0-nullsafety.0 dev_dependencies: build_runner: ^1.0.0 build_verify: ^1.1.0 json_serializable: ^3.0.0 path: ^1.0.0 - test: ^1.6.0 + test: ^1.16.0-nullsafety.7 test_process: ^1.0.1 + +dependency_overrides: + json_annotation: + path: ../json_annotation + json_serializable: + path: ../json_serializable + # Need to force yaml for now due to dev dependencies + # build_runner -> build_config -> pubspec_parse + yaml: 3.0.0-nullsafety.0 diff --git a/checked_yaml/readme.md b/checked_yaml/readme.md index 0e60c0a8d..c1b93bc1d 100644 --- a/checked_yaml/readme.md +++ b/checked_yaml/readme.md @@ -14,7 +14,6 @@ for the class annotation. anyMap: true, checked: true, disallowUnrecognizedKeys: true, - nullable: false, ) class Configuration { @JsonKey(required: true) @@ -22,7 +21,7 @@ class Configuration { @JsonKey(required: true) final int count; - Configuration({this.name, this.count}) { + Configuration({required this.name, required this.count}) { if (name.isEmpty) { throw ArgumentError.value(name, 'name', 'Cannot be empty.'); } @@ -45,19 +44,22 @@ YAML with the error. ```dart void main(List arguments) { - var sourcePathOrYaml = arguments.single; + final sourcePathOrYaml = arguments.single; String yamlContent; + Uri? sourceUri; if (FileSystemEntity.isFileSync(sourcePathOrYaml)) { yamlContent = File(sourcePathOrYaml).readAsStringSync(); + sourceUri = Uri.parse(sourcePathOrYaml); } else { yamlContent = sourcePathOrYaml; - sourcePathOrYaml = null; } final config = checkedYamlDecode( - yamlContent, (m) => Configuration.fromJson(m), - sourceUrl: sourcePathOrYaml); + yamlContent, + (m) => Configuration.fromJson(m!), + sourceUrl: sourceUri, + ); print(config); } ``` diff --git a/checked_yaml/test/ensure_build_test.dart b/checked_yaml/test/ensure_build_test.dart index bcb52649d..e83e0b3b9 100644 --- a/checked_yaml/test/ensure_build_test.dart +++ b/checked_yaml/test/ensure_build_test.dart @@ -2,6 +2,8 @@ // 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. +// @dart=2.9 + @TestOn('vm') @Tags(['presubmit-only']) import 'package:build_verify/build_verify.dart'; diff --git a/checked_yaml/test/readme_test.dart b/checked_yaml/test/readme_test.dart index 2e05f8283..aaf6f6512 100644 --- a/checked_yaml/test/readme_test.dart +++ b/checked_yaml/test/readme_test.dart @@ -2,6 +2,8 @@ // 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. +// @dart=2.9 + import 'dart:convert'; import 'dart:io'; diff --git a/example/mono_pkg.yaml b/example/mono_pkg.yaml index 80aa3fbcb..7ab68ee9f 100644 --- a/example/mono_pkg.yaml +++ b/example/mono_pkg.yaml @@ -6,7 +6,7 @@ stages: - analyzer_and_format: - group: - dartfmt - - dartanalyzer: --fatal-warnings . + - dartanalyzer: --fatal-infos . - unit_test: - test - ensure_build: diff --git a/json_annotation/mono_pkg.yaml b/json_annotation/mono_pkg.yaml index e18bc35a7..e23fee100 100644 --- a/json_annotation/mono_pkg.yaml +++ b/json_annotation/mono_pkg.yaml @@ -3,5 +3,5 @@ stages: - analyzer_and_format: - group: - dartfmt - - dartanalyzer: --fatal-warnings --fatal-infos . + - dartanalyzer: --fatal-infos . dart: [dev] diff --git a/json_serializable/mono_pkg.yaml b/json_serializable/mono_pkg.yaml index 48a0642be..1d552e889 100644 --- a/json_serializable/mono_pkg.yaml +++ b/json_serializable/mono_pkg.yaml @@ -6,7 +6,7 @@ stages: - analyzer_and_format: - group: - dartfmt - - dartanalyzer: --fatal-warnings --fatal-infos . + - dartanalyzer: --fatal-infos . - unit_test: - test: - test: -p chrome diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 73e95175a..bc13a4bc1 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -31,8 +31,11 @@ dev_dependencies: source_gen_test: ^0.1.0 stack_trace: ^1.10.0-nullsafety.5 test: ^1.16.0-nullsafety.7 - yaml: ^2.1.13 + yaml: ^3.0.0-nullsafety.0 dependency_overrides: json_annotation: path: ../json_annotation + + # For yaml! + yaml: 3.0.0-nullsafety.0 diff --git a/json_serializable/test/kitchen_sink/kitchen_sink_yaml_test.dart b/json_serializable/test/kitchen_sink/kitchen_sink_yaml_test.dart index d7ca08141..965117805 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink_yaml_test.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink_yaml_test.dart @@ -1,3 +1,5 @@ +// @dart=2.12 + import 'package:json_annotation/json_annotation.dart'; import 'package:test/test.dart'; import 'package:yaml/yaml.dart'; @@ -18,7 +20,7 @@ void main() { void _anyMapTests(KitchenSinkFactory factory) { test('valid values round-trip - yaml', () { final jsonEncoded = loudEncode(validValues); - final yaml = loadYaml(jsonEncoded, sourceUrl: 'input.yaml'); + final yaml = loadYaml(jsonEncoded); expect(jsonEncoded, loudEncode(factory.fromJson(yaml as YamlMap))); }); @@ -51,7 +53,7 @@ void _testBadValue(String key, Object badValue, KitchenSinkFactory factory, } } -Matcher _getMatcher(bool checked, String expectedKey, bool checkedAssignment) { +Matcher _getMatcher(bool checked, String? expectedKey, bool checkedAssignment) { Matcher innerMatcher; if (checked) { diff --git a/json_serializable/tool/shared.dart b/json_serializable/tool/shared.dart index 58b3a9216..3e12e469e 100644 --- a/json_serializable/tool/shared.dart +++ b/json_serializable/tool/shared.dart @@ -12,7 +12,7 @@ import 'package:yaml/yaml.dart'; Builder validate(String builderName, Builder builder) { var buildYaml = loadYaml( File('build.yaml').readAsStringSync(), - sourceUrl: 'build.yaml', + sourceUrl: Uri.parse('build.yaml'), ) as YamlMap; for (var key in ['builders', builderName, 'build_extensions']) { diff --git a/tool/ci.sh b/tool/ci.sh index 7e4a12bbe..fefe1576b 100755 --- a/tool/ci.sh +++ b/tool/ci.sh @@ -58,13 +58,9 @@ for PKG in ${PKGS}; do echo echo -e "\033[1mPKG: ${PKG}; TASK: ${TASK}\033[22m" case ${TASK} in - dartanalyzer_0) - echo 'dartanalyzer --fatal-warnings --fatal-infos .' - dartanalyzer --fatal-warnings --fatal-infos . || EXIT_CODE=$? - ;; - dartanalyzer_1) - echo 'dartanalyzer --fatal-warnings .' - dartanalyzer --fatal-warnings . || EXIT_CODE=$? + dartanalyzer) + echo 'dartanalyzer --fatal-infos .' + dartanalyzer --fatal-infos . || EXIT_CODE=$? ;; dartfmt) echo 'dartfmt -n --set-exit-if-changed .' From 0e0233c5d8bba6b5dfdb09d83ad559f1b74a995f Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 8 Dec 2020 12:49:44 -0800 Subject: [PATCH 256/569] checked_yaml: allow null-safe json_annotation (#765) Prepare to release 1.0.3 Switch back to proper casing for CHANGELOG and README --- checked_yaml/{changelog.md => CHANGELOG.md} | 3 ++- checked_yaml/{readme.md => README.md} | 0 checked_yaml/pubspec.yaml | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) rename checked_yaml/{changelog.md => CHANGELOG.md} (78%) rename checked_yaml/{readme.md => README.md} (100%) diff --git a/checked_yaml/changelog.md b/checked_yaml/CHANGELOG.md similarity index 78% rename from checked_yaml/changelog.md rename to checked_yaml/CHANGELOG.md index d436fc9d3..ba2ed6844 100644 --- a/checked_yaml/changelog.md +++ b/checked_yaml/CHANGELOG.md @@ -1,6 +1,7 @@ -## 1.0.3-dev +## 1.0.3 - Require at least Dart `2.7.0`. +- Allow `package:json_annotation` `v4.x`. ## 1.0.2 diff --git a/checked_yaml/readme.md b/checked_yaml/README.md similarity index 100% rename from checked_yaml/readme.md rename to checked_yaml/README.md diff --git a/checked_yaml/pubspec.yaml b/checked_yaml/pubspec.yaml index ef0d6ecb2..af956004a 100644 --- a/checked_yaml/pubspec.yaml +++ b/checked_yaml/pubspec.yaml @@ -8,7 +8,7 @@ environment: sdk: '>=2.7.0 <3.0.0' dependencies: - json_annotation: '>=2.2.0 <4.0.0' + json_annotation: '>=2.2.0 <5.0.0' source_span: ^1.0.0 yaml: ^2.1.13 From 5b9c0dd1aec9eb99c353a5a06fb3b958da51e5be Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 8 Dec 2020 12:50:49 -0800 Subject: [PATCH 257/569] fix pubspec --- checked_yaml/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/checked_yaml/pubspec.yaml b/checked_yaml/pubspec.yaml index af956004a..7b8053040 100644 --- a/checked_yaml/pubspec.yaml +++ b/checked_yaml/pubspec.yaml @@ -1,5 +1,5 @@ name: checked_yaml -version: 1.0.3-dev +version: 1.0.3 description: >- Generate more helpful exceptions when decoding YAML documents using package:json_serializable and package:yaml. From 3b68dbb80ff09c859c85bac5dfed2ce723e202b9 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 8 Dec 2020 13:08:18 -0800 Subject: [PATCH 258/569] Update to latest mono_repo (#766) And fixed checked_yaml readme test --- .github/workflows/dart.yml | 317 ++++++++++++++++++++++++----- checked_yaml/test/readme_test.dart | 2 +- tool/ci.sh | 2 +- 3 files changed, 267 insertions(+), 54 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index f861ae144..4da4c0b67 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -1,4 +1,4 @@ -# Created with package:mono_repo v3.3.0 +# Created with package:mono_repo v3.4.1 name: Dart CI on: push: @@ -30,13 +30,14 @@ jobs: - uses: cedx/setup-dart@v2 with: release-channel: stable - version: latest - run: dart --version - uses: actions/checkout@v2 - - run: pub global activate mono_repo 3.3.0 - - run: pub global run mono_repo generate --validate + - name: mono_repo self validate + run: pub global activate mono_repo 3.4.1 + - name: mono_repo self validate + run: pub global run mono_repo generate --validate job_002: - name: "OS: linux; SDK: dev; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; TASKS: [`dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-warnings --fatal-infos .`]" + name: "analyzer_and_format; Dart dev; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; `dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-warnings --fatal-infos .`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies @@ -54,12 +55,68 @@ jobs: release-channel: dev - run: dart --version - uses: actions/checkout@v2 - - env: - PKGS: _test_yaml checked_yaml example json_annotation json_serializable - TRAVIS_OS_NAME: linux - run: tool/ci.sh dartfmt dartanalyzer_0 + - id: _test_yaml_pub_upgrade + name: "_test_yaml; pub upgrade --no-precompile" + working-directory: _test_yaml + run: pub upgrade --no-precompile + - name: "_test_yaml; dartfmt -n --set-exit-if-changed ." + if: "steps._test_yaml_pub_upgrade.conclusion == 'success'" + working-directory: _test_yaml + run: dartfmt -n --set-exit-if-changed . + - name: "_test_yaml; dartanalyzer --fatal-warnings --fatal-infos ." + if: "steps._test_yaml_pub_upgrade.conclusion == 'success'" + working-directory: _test_yaml + run: dartanalyzer --fatal-warnings --fatal-infos . + - id: checked_yaml_pub_upgrade + name: "checked_yaml; pub upgrade --no-precompile" + working-directory: checked_yaml + run: pub upgrade --no-precompile + - name: "checked_yaml; dartfmt -n --set-exit-if-changed ." + if: "steps.checked_yaml_pub_upgrade.conclusion == 'success'" + working-directory: checked_yaml + run: dartfmt -n --set-exit-if-changed . + - name: "checked_yaml; dartanalyzer --fatal-warnings --fatal-infos ." + if: "steps.checked_yaml_pub_upgrade.conclusion == 'success'" + working-directory: checked_yaml + run: dartanalyzer --fatal-warnings --fatal-infos . + - id: example_pub_upgrade + name: "example; pub upgrade --no-precompile" + working-directory: example + run: pub upgrade --no-precompile + - name: "example; dartfmt -n --set-exit-if-changed ." + if: "steps.example_pub_upgrade.conclusion == 'success'" + working-directory: example + run: dartfmt -n --set-exit-if-changed . + - name: "example; dartanalyzer --fatal-warnings --fatal-infos ." + if: "steps.example_pub_upgrade.conclusion == 'success'" + working-directory: example + run: dartanalyzer --fatal-warnings --fatal-infos . + - id: json_annotation_pub_upgrade + name: "json_annotation; pub upgrade --no-precompile" + working-directory: json_annotation + run: pub upgrade --no-precompile + - name: "json_annotation; dartfmt -n --set-exit-if-changed ." + if: "steps.json_annotation_pub_upgrade.conclusion == 'success'" + working-directory: json_annotation + run: dartfmt -n --set-exit-if-changed . + - name: "json_annotation; dartanalyzer --fatal-warnings --fatal-infos ." + if: "steps.json_annotation_pub_upgrade.conclusion == 'success'" + working-directory: json_annotation + run: dartanalyzer --fatal-warnings --fatal-infos . + - id: json_serializable_pub_upgrade + name: "json_serializable; pub upgrade --no-precompile" + working-directory: json_serializable + run: pub upgrade --no-precompile + - name: "json_serializable; dartfmt -n --set-exit-if-changed ." + if: "steps.json_serializable_pub_upgrade.conclusion == 'success'" + working-directory: json_serializable + run: dartfmt -n --set-exit-if-changed . + - name: "json_serializable; dartanalyzer --fatal-warnings --fatal-infos ." + if: "steps.json_serializable_pub_upgrade.conclusion == 'success'" + working-directory: json_serializable + run: dartanalyzer --fatal-warnings --fatal-infos . job_003: - name: "OS: linux; SDK: 2.7.0; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; TASKS: `dartanalyzer --fatal-warnings .`" + name: "analyzer_and_format; Dart 2.7.0; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; `dartanalyzer --fatal-warnings .`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies @@ -78,12 +135,48 @@ jobs: version: "2.7.0" - run: dart --version - uses: actions/checkout@v2 - - env: - PKGS: _test_yaml checked_yaml example json_annotation json_serializable - TRAVIS_OS_NAME: linux - run: tool/ci.sh dartanalyzer_1 + - id: _test_yaml_pub_upgrade + name: "_test_yaml; pub upgrade --no-precompile" + working-directory: _test_yaml + run: pub upgrade --no-precompile + - name: "_test_yaml; dartanalyzer --fatal-warnings ." + if: "steps._test_yaml_pub_upgrade.conclusion == 'success'" + working-directory: _test_yaml + run: dartanalyzer --fatal-warnings . + - id: checked_yaml_pub_upgrade + name: "checked_yaml; pub upgrade --no-precompile" + working-directory: checked_yaml + run: pub upgrade --no-precompile + - name: "checked_yaml; dartanalyzer --fatal-warnings ." + if: "steps.checked_yaml_pub_upgrade.conclusion == 'success'" + working-directory: checked_yaml + run: dartanalyzer --fatal-warnings . + - id: example_pub_upgrade + name: "example; pub upgrade --no-precompile" + working-directory: example + run: pub upgrade --no-precompile + - name: "example; dartanalyzer --fatal-warnings ." + if: "steps.example_pub_upgrade.conclusion == 'success'" + working-directory: example + run: dartanalyzer --fatal-warnings . + - id: json_annotation_pub_upgrade + name: "json_annotation; pub upgrade --no-precompile" + working-directory: json_annotation + run: pub upgrade --no-precompile + - name: "json_annotation; dartanalyzer --fatal-warnings ." + if: "steps.json_annotation_pub_upgrade.conclusion == 'success'" + working-directory: json_annotation + run: dartanalyzer --fatal-warnings . + - id: json_serializable_pub_upgrade + name: "json_serializable; pub upgrade --no-precompile" + working-directory: json_serializable + run: pub upgrade --no-precompile + - name: "json_serializable; dartanalyzer --fatal-warnings ." + if: "steps.json_serializable_pub_upgrade.conclusion == 'success'" + working-directory: json_serializable + run: dartanalyzer --fatal-warnings . job_004: - name: "OS: linux; SDK: 2.7.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test`" + name: "unit_test; Dart 2.7.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; `pub run test`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies @@ -102,16 +195,44 @@ jobs: version: "2.7.0" - run: dart --version - uses: actions/checkout@v2 - - env: - PKGS: _test_yaml checked_yaml example json_serializable - TRAVIS_OS_NAME: linux - run: tool/ci.sh test_0 + - id: _test_yaml_pub_upgrade + name: "_test_yaml; pub upgrade --no-precompile" + working-directory: _test_yaml + run: pub upgrade --no-precompile + - name: _test_yaml; pub run test + if: "steps._test_yaml_pub_upgrade.conclusion == 'success'" + working-directory: _test_yaml + run: pub run test + - id: checked_yaml_pub_upgrade + name: "checked_yaml; pub upgrade --no-precompile" + working-directory: checked_yaml + run: pub upgrade --no-precompile + - name: checked_yaml; pub run test + if: "steps.checked_yaml_pub_upgrade.conclusion == 'success'" + working-directory: checked_yaml + run: pub run test + - id: example_pub_upgrade + name: "example; pub upgrade --no-precompile" + working-directory: example + run: pub upgrade --no-precompile + - name: example; pub run test + if: "steps.example_pub_upgrade.conclusion == 'success'" + working-directory: example + run: pub run test + - id: json_serializable_pub_upgrade + name: "json_serializable; pub upgrade --no-precompile" + working-directory: json_serializable + run: pub upgrade --no-precompile + - name: json_serializable; pub run test + if: "steps.json_serializable_pub_upgrade.conclusion == 'success'" + working-directory: json_serializable + run: pub run test needs: - job_001 - job_002 - job_003 job_005: - name: "OS: linux; SDK: dev; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test`" + name: "unit_test; Dart dev; PKGS: _test_yaml, checked_yaml, example, json_serializable; `pub run test`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies @@ -129,16 +250,44 @@ jobs: release-channel: dev - run: dart --version - uses: actions/checkout@v2 - - env: - PKGS: _test_yaml checked_yaml example json_serializable - TRAVIS_OS_NAME: linux - run: tool/ci.sh test_0 + - id: _test_yaml_pub_upgrade + name: "_test_yaml; pub upgrade --no-precompile" + working-directory: _test_yaml + run: pub upgrade --no-precompile + - name: _test_yaml; pub run test + if: "steps._test_yaml_pub_upgrade.conclusion == 'success'" + working-directory: _test_yaml + run: pub run test + - id: checked_yaml_pub_upgrade + name: "checked_yaml; pub upgrade --no-precompile" + working-directory: checked_yaml + run: pub upgrade --no-precompile + - name: checked_yaml; pub run test + if: "steps.checked_yaml_pub_upgrade.conclusion == 'success'" + working-directory: checked_yaml + run: pub run test + - id: example_pub_upgrade + name: "example; pub upgrade --no-precompile" + working-directory: example + run: pub upgrade --no-precompile + - name: example; pub run test + if: "steps.example_pub_upgrade.conclusion == 'success'" + working-directory: example + run: pub run test + - id: json_serializable_pub_upgrade + name: "json_serializable; pub upgrade --no-precompile" + working-directory: json_serializable + run: pub upgrade --no-precompile + - name: json_serializable; pub run test + if: "steps.json_serializable_pub_upgrade.conclusion == 'success'" + working-directory: json_serializable + run: pub run test needs: - job_001 - job_002 - job_003 - job_008: - name: "OS: linux; SDK: 2.7.0; PKG: json_serializable; TASKS: `pub run test -p chrome`" + job_006: + name: "unit_test; Dart 2.7.0; PKG: json_serializable; `pub run test -p chrome`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies @@ -157,16 +306,20 @@ jobs: version: "2.7.0" - run: dart --version - uses: actions/checkout@v2 - - env: - PKGS: json_serializable - TRAVIS_OS_NAME: linux - run: tool/ci.sh test_2 + - id: json_serializable_pub_upgrade + name: "json_serializable; pub upgrade --no-precompile" + working-directory: json_serializable + run: pub upgrade --no-precompile + - name: "json_serializable; pub run test -p chrome" + if: "steps.json_serializable_pub_upgrade.conclusion == 'success'" + working-directory: json_serializable + run: pub run test -p chrome needs: - job_001 - job_002 - job_003 - job_009: - name: "OS: linux; SDK: dev; PKG: json_serializable; TASKS: `pub run test -p chrome`" + job_007: + name: "unit_test; Dart dev; PKG: json_serializable; `pub run test -p chrome`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies @@ -184,16 +337,20 @@ jobs: release-channel: dev - run: dart --version - uses: actions/checkout@v2 - - env: - PKGS: json_serializable - TRAVIS_OS_NAME: linux - run: tool/ci.sh test_2 + - id: json_serializable_pub_upgrade + name: "json_serializable; pub upgrade --no-precompile" + working-directory: json_serializable + run: pub upgrade --no-precompile + - name: "json_serializable; pub run test -p chrome" + if: "steps.json_serializable_pub_upgrade.conclusion == 'success'" + working-directory: json_serializable + run: pub run test -p chrome needs: - job_001 - job_002 - job_003 - job_006: - name: "OS: linux; SDK: 2.7.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`" + job_008: + name: "ensure_build; Dart 2.7.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies @@ -212,17 +369,45 @@ jobs: version: "2.7.0" - run: dart --version - uses: actions/checkout@v2 - - env: - PKGS: _test_yaml checked_yaml example json_serializable - TRAVIS_OS_NAME: linux - run: tool/ci.sh test_1 + - id: _test_yaml_pub_upgrade + name: "_test_yaml; pub upgrade --no-precompile" + working-directory: _test_yaml + run: pub upgrade --no-precompile + - name: "_test_yaml; pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart" + if: "steps._test_yaml_pub_upgrade.conclusion == 'success'" + working-directory: _test_yaml + run: pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart + - id: checked_yaml_pub_upgrade + name: "checked_yaml; pub upgrade --no-precompile" + working-directory: checked_yaml + run: pub upgrade --no-precompile + - name: "checked_yaml; pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart" + if: "steps.checked_yaml_pub_upgrade.conclusion == 'success'" + working-directory: checked_yaml + run: pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart + - id: example_pub_upgrade + name: "example; pub upgrade --no-precompile" + working-directory: example + run: pub upgrade --no-precompile + - name: "example; pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart" + if: "steps.example_pub_upgrade.conclusion == 'success'" + working-directory: example + run: pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart + - id: json_serializable_pub_upgrade + name: "json_serializable; pub upgrade --no-precompile" + working-directory: json_serializable + run: pub upgrade --no-precompile + - name: "json_serializable; pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart" + if: "steps.json_serializable_pub_upgrade.conclusion == 'success'" + working-directory: json_serializable + run: pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart needs: - job_004 - job_005 - - job_008 - - job_009 - job_007: - name: "OS: linux; SDK: dev; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`" + - job_006 + - job_007 + job_009: + name: "ensure_build; Dart dev; PKGS: _test_yaml, checked_yaml, example, json_serializable; `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies @@ -240,12 +425,40 @@ jobs: release-channel: dev - run: dart --version - uses: actions/checkout@v2 - - env: - PKGS: _test_yaml checked_yaml example json_serializable - TRAVIS_OS_NAME: linux - run: tool/ci.sh test_1 + - id: _test_yaml_pub_upgrade + name: "_test_yaml; pub upgrade --no-precompile" + working-directory: _test_yaml + run: pub upgrade --no-precompile + - name: "_test_yaml; pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart" + if: "steps._test_yaml_pub_upgrade.conclusion == 'success'" + working-directory: _test_yaml + run: pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart + - id: checked_yaml_pub_upgrade + name: "checked_yaml; pub upgrade --no-precompile" + working-directory: checked_yaml + run: pub upgrade --no-precompile + - name: "checked_yaml; pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart" + if: "steps.checked_yaml_pub_upgrade.conclusion == 'success'" + working-directory: checked_yaml + run: pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart + - id: example_pub_upgrade + name: "example; pub upgrade --no-precompile" + working-directory: example + run: pub upgrade --no-precompile + - name: "example; pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart" + if: "steps.example_pub_upgrade.conclusion == 'success'" + working-directory: example + run: pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart + - id: json_serializable_pub_upgrade + name: "json_serializable; pub upgrade --no-precompile" + working-directory: json_serializable + run: pub upgrade --no-precompile + - name: "json_serializable; pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart" + if: "steps.json_serializable_pub_upgrade.conclusion == 'success'" + working-directory: json_serializable + run: pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart needs: - job_004 - job_005 - - job_008 - - job_009 + - job_006 + - job_007 diff --git a/checked_yaml/test/readme_test.dart b/checked_yaml/test/readme_test.dart index 2e05f8283..f2727832c 100644 --- a/checked_yaml/test/readme_test.dart +++ b/checked_yaml/test/readme_test.dart @@ -11,7 +11,7 @@ import 'package:test_process/test_process.dart'; final _examplePath = p.join('example', 'example.dart'); -final _readmeContent = File('readme.md').readAsStringSync(); +final _readmeContent = File('README.md').readAsStringSync(); final _exampleContent = File(_examplePath).readAsStringSync(); const _memberEnd = '\n}'; diff --git a/tool/ci.sh b/tool/ci.sh index 7e4a12bbe..5f425832c 100755 --- a/tool/ci.sh +++ b/tool/ci.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Created with package:mono_repo v3.3.0 +# Created with package:mono_repo v3.4.1 # Support built in commands on windows out of the box. function pub() { From 34f335806f76e6aac7c6bfc04045a325e24d2ce9 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 8 Dec 2020 16:24:53 -0800 Subject: [PATCH 259/569] Allow latest pkg:yaml (#768) Prepare to publish v1.0.4 --- checked_yaml/CHANGELOG.md | 4 ++++ checked_yaml/lib/checked_yaml.dart | 11 ++++++++++- checked_yaml/pubspec.yaml | 6 +++--- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/checked_yaml/CHANGELOG.md b/checked_yaml/CHANGELOG.md index ba2ed6844..8dca08b09 100644 --- a/checked_yaml/CHANGELOG.md +++ b/checked_yaml/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.0.4 + +- Allow `package:yaml` `v3.x`. + ## 1.0.3 - Require at least Dart `2.7.0`. diff --git a/checked_yaml/lib/checked_yaml.dart b/checked_yaml/lib/checked_yaml.dart index f8d2aff94..e7409f467 100644 --- a/checked_yaml/lib/checked_yaml.dart +++ b/checked_yaml/lib/checked_yaml.dart @@ -27,8 +27,17 @@ T checkedYamlDecode( allowNull ??= false; YamlNode yaml; + Uri sourceUri; + if (sourceUrl == null) { + // noop + } else if (sourceUrl is Uri) { + sourceUri = sourceUrl; + } else { + sourceUri = Uri.parse(sourceUrl as String); + } + try { - yaml = loadYamlNode(yamlContent, sourceUrl: sourceUrl); + yaml = loadYamlNode(yamlContent, sourceUrl: sourceUri); } on YamlException catch (e) { throw ParsedYamlException.fromYamlException(e); } diff --git a/checked_yaml/pubspec.yaml b/checked_yaml/pubspec.yaml index 7b8053040..9bcfee429 100644 --- a/checked_yaml/pubspec.yaml +++ b/checked_yaml/pubspec.yaml @@ -1,16 +1,16 @@ name: checked_yaml -version: 1.0.3 +version: 1.0.4 description: >- Generate more helpful exceptions when decoding YAML documents using package:json_serializable and package:yaml. -homepage: https://github.com/google/json_serializable.dart +repository: https://github.com/google/json_serializable.dart environment: sdk: '>=2.7.0 <3.0.0' dependencies: json_annotation: '>=2.2.0 <5.0.0' source_span: ^1.0.0 - yaml: ^2.1.13 + yaml: '>=2.1.13 <4.0.0' dev_dependencies: build_runner: ^1.0.0 From 3567cf9b3978157dba4ca6d2c47099c02a763d27 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 9 Dec 2020 08:30:45 -0800 Subject: [PATCH 260/569] Prepare to release v4.0.0-nullsafety.0 (#770) Closes https://github.com/google/json_serializable.dart/issues/763 --- json_serializable/CHANGELOG.md | 4 ++-- json_serializable/pubspec.yaml | 11 ++--------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 3ee00a080..9129a98da 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,10 +1,10 @@ -## 4.0.0-nullsafety.1 +## 4.0.0-nullsafety.0 - Generates null-safe code. - The `nullable` field on `JsonKey` ignored. The nullability of a field is now determined by the Dart type system. - **BREAKING** `bool defaultProvided` arg added to `TypeHelper.deserialize`. - *Only applies to folks using `TypeHelper` directly.* + *Only applies to code using `TypeHelper` directly.* ## 3.5.1 diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index bc13a4bc1..b8546e85a 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 4.0.0-nullsafety.1 +version: 4.0.0-nullsafety.0 description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. @@ -16,7 +16,7 @@ dependencies: # `json_annotation` properly constrains all features it provides. # For v3 only – allow a wide range since the only change was to REMOVE things # from json_annotation - json_annotation: '>=3.1.0 <3.2.0' + json_annotation: '>=4.0.0-nullsafety.0 <4.1.0' meta: ^1.3.0-nullsafety.5 path: ^1.8.0-nullsafety.2 source_gen: ^0.9.6 @@ -32,10 +32,3 @@ dev_dependencies: stack_trace: ^1.10.0-nullsafety.5 test: ^1.16.0-nullsafety.7 yaml: ^3.0.0-nullsafety.0 - -dependency_overrides: - json_annotation: - path: ../json_annotation - - # For yaml! - yaml: 3.0.0-nullsafety.0 From 4047521eac683886a014bb9ebe3fc19a2158c264 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 10 Dec 2020 12:33:46 -0800 Subject: [PATCH 261/569] Latest mono_repo --- .github/workflows/dart.yml | 6 ++++-- tool/ci.sh | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index e081fd06b..bb04c92d6 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -1,4 +1,4 @@ -# Created with package:mono_repo v3.4.1 +# Created with package:mono_repo v3.4.2 name: Dart CI on: push: @@ -33,7 +33,7 @@ jobs: - run: dart --version - uses: actions/checkout@v2 - name: mono_repo self validate - run: pub global activate mono_repo 3.4.1 + run: pub global activate mono_repo 3.4.2 - name: mono_repo self validate run: pub global run mono_repo generate --validate job_002: @@ -251,5 +251,7 @@ jobs: working-directory: json_serializable run: pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart needs: + - job_001 + - job_002 - job_003 - job_004 diff --git a/tool/ci.sh b/tool/ci.sh index ad9db70ec..733352719 100755 --- a/tool/ci.sh +++ b/tool/ci.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Created with package:mono_repo v3.4.1 +# Created with package:mono_repo v3.4.2 # Support built in commands on windows out of the box. function pub() { From 6c6cc54a3fc4612e0928e0ca63dd183dbe08e60c Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 5 Jan 2021 08:28:34 -0800 Subject: [PATCH 262/569] Lint markdown format and links (#777) --- .github/workflows/markdown_linter.yml | 30 ++ .markdownlint.yaml | 15 + README.md | 14 +- checked_yaml/README.md | 2 +- example/README.md | 9 +- json_annotation/CHANGELOG.md | 96 +++--- json_serializable/CHANGELOG.md | 415 +++++++++++++------------- json_serializable/README.md | 25 +- 8 files changed, 326 insertions(+), 280 deletions(-) create mode 100644 .github/workflows/markdown_linter.yml create mode 100644 .markdownlint.yaml diff --git a/.github/workflows/markdown_linter.yml b/.github/workflows/markdown_linter.yml new file mode 100644 index 000000000..779021a03 --- /dev/null +++ b/.github/workflows/markdown_linter.yml @@ -0,0 +1,30 @@ +name: markdown_linter +on: + push: + branches: + - main + pull_request: + schedule: + - cron: "0 0 * * 0" + +jobs: + markdown-link-check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + - uses: gaurav-nelson/github-action-markdown-link-check@v1 + markdown_lint: + runs-on: ubuntu-latest + strategy: + matrix: + node-version: [ 14.x ] + steps: + - uses: actions/checkout@master + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - name: Install dependencies + run: npm install --global markdownlint-cli2 + - name: Run lint check + run: markdownlint-cli2-fix "**/*.md" diff --git a/.markdownlint.yaml b/.markdownlint.yaml new file mode 100644 index 000000000..a27309850 --- /dev/null +++ b/.markdownlint.yaml @@ -0,0 +1,15 @@ +# Rules for markdownlint-cli2 (https://github.com/DavidAnson/markdownlint-cli2) +# Based on markdownlint library (https://github.com/DavidAnson/markdownlint) +# (same linter as vscode-markdownlint). +# See rules descriptions here: +# https://github.com/DavidAnson/markdownlint/blob/main/doc/Rules.md +# +first-line-heading: false +line_length: # MD013 max line length + tables: false # don't break tables + code_blocks: false # don't break on code blocks + line_length: 80 +html: # MD033 no html + allowed_elements: [br] +images: false # MD045: image alt text +no-blanks-blockquote: false # MD028 diff --git a/README.md b/README.md index 5f995b2c1..6ce98913d 100644 --- a/README.md +++ b/README.md @@ -5,8 +5,8 @@ deserialization. ## json_serializable [![Pub Package](https://img.shields.io/pub/v/json_serializable.svg)](https://pub.dev/packages/json_serializable) -* Package: https://pub.dev/packages/json_serializable -* [Source code](json_serializable) +- Package: +- [Source code](json_serializable) The core package providing Generators for JSON-specific tasks. @@ -14,8 +14,8 @@ Import it into your pubspec `dev_dependencies:` section. ## json_annotation [![Pub Package](https://img.shields.io/pub/v/json_annotation.svg)](https://pub.dev/packages/json_annotation) -* Package: https://pub.dev/packages/json_annotation -* [Source code](json_annotation) +- Package: +- [Source code](json_annotation) The annotation package which has no dependencies. @@ -23,8 +23,8 @@ Import it into your pubspec `dependencies:` section. ## checked_yaml [![Pub Package](https://img.shields.io/pub/v/checked_yaml.svg)](https://pub.dev/packages/checked_yaml) -* Package: https://pub.dev/packages/checked_yaml -* [Source code](checked_yaml) +- Package: +- [Source code](checked_yaml) Generate more helpful exceptions when decoding YAML documents using `package:json_serializable` and `package:yaml`. @@ -33,7 +33,7 @@ Import it into your pubspec `dependencies:` section. ## example -* [Source code](example) +- [Source code](example) An example showing how to setup and use `json_serializable` and `json_annotation`. diff --git a/checked_yaml/README.md b/checked_yaml/README.md index c1b93bc1d..16b132ef0 100644 --- a/checked_yaml/README.md +++ b/checked_yaml/README.md @@ -7,7 +7,7 @@ the target type. [`package:json_serializable`] can generate classes that can parse the [`YamlMap`] type provided by [`package:yaml`] when `anyMap: true` is specified -for the class annotation. +for the class annotation. ```dart @JsonSerializable( diff --git a/example/README.md b/example/README.md index 96ca7440e..89d25aabc 100644 --- a/example/README.md +++ b/example/README.md @@ -1,4 +1,4 @@ -*This example assumes you're using a recent version of the Dart or Flutter SDK.* +_This example assumes you're using a recent version of the Dart or Flutter SDK._ To use [package:json_serializable][json_serializable] in your package, add these dependencies to your `pubspec.yaml`. @@ -15,10 +15,10 @@ dev_dependencies: Annotate your code with classes defined in [package:json_annotation][json_annotation]. -* See [`lib/example.dart`][example] for an example of a file using these +- See [`lib/example.dart`][example] for an example of a file using these annotations. -* See [`lib/example.g.dart`][example_g] for the generated file. +- See [`lib/example.g.dart`][example_g] for the generated file. Run `pub run build_runner build` to generate files into your source directory. @@ -32,7 +32,8 @@ Run `pub run build_runner build` to generate files into your source directory. [INFO] Build: Succeeded after 4687ms with 1 outputs ``` -*NOTE*: If you're using Flutter, replace `pub run` with `flutter packages pub run`. +_NOTE_: If you're using Flutter, replace `pub run` with +`flutter packages pub run`. [example]: lib/example.dart [example_g]: lib/example.g.dart diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index f395247d4..bb76dd097 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -7,14 +7,14 @@ ## 3.1.1 -- Avoid `null` values for `CheckedFromJsonException.message` by using +- Avoid `null` values for `CheckedFromJsonException.message` by using `toString()` with unrecognized error types. - Added a helpful `UnrecognizedKeysException.toString()`. - Fixed doc comments for `JsonSerializable.genericArgumentFactories`. ## 3.1.0 -- Added `JsonSerializable.genericArgumentFactories` field. +- Added `JsonSerializable.genericArgumentFactories` field. - Require at least Dart `2.7.0`. ## 3.0.1 @@ -48,134 +48,134 @@ ## 2.2.0 -* Add an optional (named) `badKey` parameter and field to +- Add an optional (named) `badKey` parameter and field to `CheckedFromJsonException`. ## 2.1.0 -* Require at least Dart `2.1.1`. +- Require at least Dart `2.1.1`. -* Added to `encodeEmptyCollection` to `JsonKey` and `JsonSerializable`. +- Added to `encodeEmptyCollection` to `JsonKey` and `JsonSerializable`. -* `JsonSerializable.fromJson` now throws `CheckedFromJsonException` on errors. - This is potentially a breaking change. +- `JsonSerializable.fromJson` now throws `CheckedFromJsonException` on errors. + This is potentially a breaking change. -* Added a more helpful `toString` to `CheckedFromJsonException`. +- Added a more helpful `toString` to `CheckedFromJsonException`. ## 2.0.0 -* **Potentially Breaking** `JsonSerializable` no longer sets default values for +- **Potentially Breaking** `JsonSerializable` no longer sets default values for fields when constructor arguments are unset or `null`. This is not likely an issue for developers using this class as an annotation with a compatible version of `package:json_serializable`, but it may cause issues if class is used in other contexts. -* Support all `build.yaml` configuration options on classes by adding a number +- Support all `build.yaml` configuration options on classes by adding a number of fields to `JsonSerializable`: `anyMap`, `checked`, `explicitToJson`, `generateToJsonFunction`, and `useWrappers`. ## 1.2.0 -* Added `JsonConverter` class to support custom conversion of types. +- Added `JsonConverter` class to support custom conversion of types. ## 1.1.0 -* Added the `fieldRename` option to `JsonSerializable` and the associated +- Added the `fieldRename` option to `JsonSerializable` and the associated `FieldRename` enum. ## 1.0.0 -* Added `JsonValue` class for annotating `enum` fields with a custom +- Added `JsonValue` class for annotating `enum` fields with a custom serialization value. -* Removed `$checkAllowedKeys`, `$enumDecode` and `$enumDecodeNullable` which are +- Removed `$checkAllowedKeys`, `$enumDecode` and `$enumDecodeNullable` which are no longer needed by the latest release of `package:json_serializable`. ## 0.2.9+1 -* Support the Dart 2.0 stable release. +- Support the Dart 2.0 stable release. ## 0.2.9 -* When `FormatException` is caught in "checked mode", use the `message` - property when creating `CheckedFromJsonException`. +- When `FormatException` is caught in "checked mode", use the `message` property + when creating `CheckedFromJsonException`. ## 0.2.8 -* Added `$checkKeys` helper function and deprecated `$checkAllowedKeys`. +- Added `$checkKeys` helper function and deprecated `$checkAllowedKeys`. Upgrading to the latest `json_serializable` and re-running your build will eliminate any `@deprecated` hints you see. -* Added `BadKeyException` exception which is the abstract super class for +- Added `BadKeyException` exception which is the abstract super class for `MissingRequiredKeysException`, `UnrecognizedKeysException`, and `DisallowedNullValueException`. -* Added `JsonKey.required` field and an associated +- Added `JsonKey.required` field and an associated `MissingRequiredKeysException` that is thrown when `required` fields don't have corresponding keys in a source JSON map. -* Added `JsonKey.disallowNullValue` field and an associated +- Added `JsonKey.disallowNullValue` field and an associated `DisallowedNullValueException` that is thrown when corresponding keys exist in a source JSON map, but their values are `null`. -* Updated documentation of `JsonSerializable.createToJson` to include details - of the new `generate_to_json_function` configuration option. +- Updated documentation of `JsonSerializable.createToJson` to include details of + the new `generate_to_json_function` configuration option. ## 0.2.7+1 -* Small improvement to `UnrecognizedKeysException.message` output and +- Small improvement to `UnrecognizedKeysException.message` output and documentation comments. ## 0.2.7 -* Added `JsonSerializable.disallowUnrecognizedKeys`. - * Added a helper function to support this option. This function starts with a +- 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 `UnrecognizedKeysException` for reporting errors. + - Added `UnrecognizedKeysException` for reporting errors. ## 0.2.6 -* `CheckedFromJsonException` - * Added a public constructor to support hand-written JSON decoding logic. - * The `message` property is now `String` (instead of `Object`). +- `CheckedFromJsonException` -* Added `JsonKey.defaultValue`. + - Added a public constructor to support hand-written JSON decoding logic. + - The `message` property is now `String` (instead of `Object`). -* Added helpers for deserialization of `enum` values. - These functions starting with `$` are referenced by generated code. - They are not meant for direct use. +- Added `JsonKey.defaultValue`. + +- Added helpers for deserialization of `enum` values. These functions starting + with `$` are referenced by generated code. They are not meant for direct use. ## 0.2.5 -* Added `CheckedFromJsonException` which is thrown by code generated when - `checked` is enabled in `json_serializable`. +- Added `CheckedFromJsonException` which is thrown by code generated when + `checked` is enabled in `json_serializable`. -* Added functions to support the `checked` generation option. - These functions starting with `$` are referenced by generated code. - They are not meant for direct use. +- Added functions to support the `checked` generation option. These functions + starting with `$` are referenced by generated code. They are not meant for + direct use. ## 0.2.4 -* Added `fromJson` and `toJson` fields to `JsonKey` class. +- Added `fromJson` and `toJson` fields to `JsonKey` class. ## 0.2.3 -* Added `ignore` field to `JsonKey` class annotation +- Added `ignore` field to `JsonKey` class annotation ## 0.2.2 -* Added a helper class – `$JsonMapWrapper` – and helper functions – `$wrapMap`, - `$wrapMapHandleNull`, `$wrapList`, and `$wrapListHandleNull` – to support - the `useWrappers` option added to `JsonSerializableGenerator` in `v0.3.0` of +- Added a helper class – `$JsonMapWrapper` – and helper functions – `$wrapMap`, + `$wrapMapHandleNull`, `$wrapList`, and `$wrapListHandleNull` – to support the + `useWrappers` option added to `JsonSerializableGenerator` in `v0.3.0` of `package:json_serializable`. ## 0.2.1 -* `JsonSerializable` class annotation - * Added `nullable` field. - * Fixed doc comment. +- `JsonSerializable` class annotation + - Added `nullable` field. + - Fixed doc comment. ## 0.2.0 -* Moved annotation classes for `JsonSerializable` and `JsonLiteral`. +- Moved annotation classes for `JsonSerializable` and `JsonLiteral`. diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 9129a98da..75ad40635 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,10 +1,10 @@ ## 4.0.0-nullsafety.0 - Generates null-safe code. - - The `nullable` field on `JsonKey` ignored. The nullability of a field is now + - The `nullable` field on `JsonKey` ignored. The nullability of a field is now determined by the Dart type system. - **BREAKING** `bool defaultProvided` arg added to `TypeHelper.deserialize`. - *Only applies to code using `TypeHelper` directly.* + _Only applies to code using `TypeHelper` directly._ ## 3.5.1 @@ -17,12 +17,12 @@ - Added support for populating generic helper functions for fields with generic type parameters. -- Added support for `JsonSerializable.genericArgumentFactories`. - This adds extra parameters to generated `fromJson` and/or `toJson` functions - to support encoding and decoding generic types. +- Added support for `JsonSerializable.genericArgumentFactories`. This adds extra + parameters to generated `fromJson` and/or `toJson` functions to support + encoding and decoding generic types. For example, the generated code for - + ```dart @JsonSerializable(genericArgumentFactories: true) class Response { @@ -30,9 +30,9 @@ T value; } ``` - + Looks like - + ```dart Response _$ResponseFromJson( Map json, @@ -42,7 +42,7 @@ ..status = json['status'] as int ..value = fromJsonT(json['value']); } - + Map _$ResponseToJson( Response instance, Object Function(T value) toJsonT, @@ -65,7 +65,7 @@ - `JsonKey.defaultValue` - Added support for `double.infinity`, `double.negativeInfinity`, and - `double.nan`. + `double.nan`. - Added support for `Set` literals. - Require at least Dart `2.7.0`. @@ -83,19 +83,19 @@ ## 3.2.4 -* Require `package:analyzer` `^0.39.0`. +- Require `package:analyzer` `^0.39.0`. ## 3.2.3 -* Bug fix for analyzer 0.38.5. +- Bug fix for analyzer 0.38.5. ## 3.2.2 -* Support `JsonConverter` annotations on property getters +- Support `JsonConverter` annotations on property getters ## 3.2.1 -* Support `package:analyzer` `>=0.33.3 <0.39.0` +- Support `package:analyzer` `>=0.33.3 <0.39.0` ## 3.2.0 @@ -121,16 +121,14 @@ 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.toJson` or a custom `JsonConverter` annotation – don't intercept - `null` values, even if `nullable` is explicitly set to `false`. This allows - these functions to provide alternative values for `null` – such as an empty - collection – which replaces the functionality provided by - `encodeEmptyCollection`. - - **NOTE: this is SILENTLY BREAKING.** There is no corresponding deprecation - for this change. If you use converters, please make sure to test your - code! - +- If a field has a conversion function defined – either `JsonKey.toJson` or a + custom `JsonConverter` annotation – don't intercept `null` values, even if + `nullable` is explicitly set to `false`. This allows these functions to + provide alternative values for `null` – such as an empty collection – which + replaces the functionality provided by `encodeEmptyCollection`. + - **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 `pascal` as an additional `fieldRename` option. @@ -152,162 +150,162 @@ future feature work. ## 2.2.0 - If a field has a conversion function defined – either `JsonKey.toJson` or a - custom `JsonConverter` annotation – handle the case where the function - returns `null` and both `nullable` and `includeIfNull` are `false`. + custom `JsonConverter` annotation – handle the case where the function returns + `null` and both `nullable` and `includeIfNull` are `false`. ## 2.1.2 -* Support `package:json_annotation` `>=2.1.0 <2.3.0`. +- Support `package:json_annotation` `>=2.1.0 <2.3.0`. ## 2.1.1 -* Support `package:analyzer` `>=0.33.3 <0.37.0` +- Support `package:analyzer` `>=0.33.3 <0.37.0` ## 2.1.0 -* Require at least Dart `2.1.1`. +- Require at least Dart `2.1.1`. -* Added support for `encodeEmptyCollection` on `JsonKey` and `JsonSerializable`. +- Added support for `encodeEmptyCollection` on `JsonKey` and `JsonSerializable`. -* Added support for `BigInt`. +- Added support for `BigInt`. -* Added `BigIntTypeHelper` to `type_helper.dart` library. +- Added `BigIntTypeHelper` to `type_helper.dart` library. -* Provide a more helpful error if the builder is improperly configured. +- Provide a more helpful error if the builder is improperly configured. ## 2.0.3 -* When invoking a `fromJson` constructor on a field type, generate a conversion +- When invoking a `fromJson` constructor on a field type, generate a conversion expression derived from the the constructor parameter type. -* Be more strict about the supported `List`, `Set`, or `Map` types. - This may causes errors to be raised in cases where invalid code was generated - before. It also allows implementations of these types to add a `fromJson` - constructor to support custom decoding. +- Be more strict about the supported `List`, `Set`, or `Map` types. This may + causes errors to be raised in cases where invalid code was generated before. + It also allows implementations of these types to add a `fromJson` constructor + to support custom decoding. -* Small change to the whitespace around converted maps to improve a very slow +- 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.defaultValue` is set with other fields. - * With `toJson`: use `nullable: false` instead of `defaultValue`. - * With both `disallowNullValue` and `required` set to `true`. +- Log warnings when `JsonKey.defaultValue` is set with other fields. + + - With `toJson`: use `nullable: false` instead of `defaultValue`. + - With both `disallowNullValue` and `required` set to `true`. -* Avoid no-op call to `map` when decoding a field of type `Set`. +- Avoid no-op call to `map` when decoding a field of type `Set`. -* Support `package:analyzer` `>=0.33.3 <0.36.0` +- Support `package:analyzer` `>=0.33.3 <0.36.0` ## 2.0.1 -* Support `package:analyzer` v0.34.0. +- Support `package:analyzer` v0.34.0. ## 2.0.0 -* Support all `build.yaml` configuration options on classes by adding a number +- Support all `build.yaml` configuration options on classes by adding a number of fields to `JsonSerializable`: `anyMap`, `checked`, `explicitToJson`, `generateToJsonFunction`, and `useWrappers`. -* Support decode/encode of `dart:core` `Duration` +- Support decode/encode of `dart:core` `Duration` -* Code generated for fields and classes annotated with `JsonConverter` instances +- Code generated for fields and classes annotated with `JsonConverter` instances now properly handles nullable fields. -* Build configuration +- Build configuration - * You can now configure all settings exposed by the `JsonSerializable` + - You can now configure all settings exposed by the `JsonSerializable` annotation within `build.yaml`. - * **BREAKING** Unsupported options defined in `build.yaml` will cause + - **BREAKING** Unsupported options defined in `build.yaml` will cause exceptions instead of being logged and ignored. -* `json_serializable.dart` +- `json_serializable.dart` - * **BREAKING** `JsonSerializableGenerator` now exposes a `config` property - of type `JsonSerializable` instead of individual properties for `checked`, + - **BREAKING** `JsonSerializableGenerator` now exposes a `config` property of + type `JsonSerializable` instead of individual properties for `checked`, `anyMay`, etc. This will affect anyone creating or using this class via code. -* `type_helper.dart` +- `type_helper.dart` - * **BREAKING** `SerializeContext` and `DeserializeContext` have been replaced + - **BREAKING** `SerializeContext` and `DeserializeContext` have been replaced with new `TypeHelperContext` class. - * `TypeHelper` now has a type argument allowing implementors to specify a + - `TypeHelper` now has a type argument allowing implementors to specify a specific implementation of `TypeHelperContext` for calls to `serialize` and `deserialize`. Many of the included `TypeHelper` implementations have been updated to indicate they expect more information from the source generator. ## 1.5.1 -* Support the latest `package:analyzer`. +- Support the latest `package:analyzer`. ## 1.5.0 -* Added support for `JsonConvert` annotation on fields. +- Added support for `JsonConvert` annotation on fields. ## 1.4.0 -* `type_helper.dart` +- `type_helper.dart` - * `TypeHelper` `serialize` and `deserialize` have return type `Object` instead + - `TypeHelper` `serialize` and `deserialize` have return type `Object` instead of `String`. This allows coordination between instances to support more advanced features – like using the new `LambdaResult` class to avoid creating unnecessary lambdas. When creating `TypeHelper` implementations, handle non-`String` results by calling `toString()` on unrecognized values. -* Declare support for `package:build` version `1.x.x`. +- Declare support for `package:build` version `1.x.x`. ## 1.3.0 -* Add support for types annotated with classes that extend `JsonConverter` from +- Add support for types annotated with classes that extend `JsonConverter` from `package:json_annotation`. -* Export the following `TypeHelper` implementations in - `package:json_serializable/type_helper.dart`: - `ConvertHelper`, `EnumHelper`, `IterableHelper`, `JsonConverterHelper`, - `MapHelper`, `ValueHelper` +- Export the following `TypeHelper` implementations in + `package:json_serializable/type_helper.dart`: `ConvertHelper`, `EnumHelper`, + `IterableHelper`, `JsonConverterHelper`, `MapHelper`, `ValueHelper` -* Added support for `Set` type as a target. +- Added support for `Set` type as a target. ## 1.2.1 -* Added back `const` for maps generated with `checked: true` configuration. +- Added back `const` for maps generated with `checked: true` configuration. ## 1.2.0 -* Now throws `InvalidGenerationSourceError` instead of `UnsupportedError` for +- Now throws `InvalidGenerationSourceError` instead of `UnsupportedError` for some classes of constructor errors. -* Supports class-static functions for `toJson` and `fromJson` on `JsonKey`. +- Supports class-static functions for `toJson` and `fromJson` on `JsonKey`. -* Provide a warning about ignored setter-only properties instead of crashing. +- Provide a warning about ignored setter-only properties instead of crashing. -* Added back `const` for lists generated with `disallowUnrecognizedKeys`, +- Added back `const` for lists generated with `disallowUnrecognizedKeys`, `required`, and `disallowNullValue`. -* Fixed a bug when `disallowUnrecognizedKeys` is enabled. +- Fixed a bug when `disallowUnrecognizedKeys` is enabled. -* Fixed a number of issues when dealing with inherited properties. +- 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 +- Added support for automatically converting field names to JSON map keys as `kebab-case` or `snake_case` with a new option on the `JsonSerializable` annotation. ## 1.0.1 -* Explicit `new` and `const` are no longer generated. +- Explicit `new` and `const` are no longer generated. ## 1.0.0 -* **BREAKING** By default, code generated to support `toJson` now creates - a top-level function instead of a mixin. The default for the - `generate_to_json_function` is now `true`. To opt-out of this change, - set `generate_to_json_function` to `false`. +- **BREAKING** By default, code generated to support `toJson` now creates a + top-level function instead of a mixin. The default for the + `generate_to_json_function` is now `true`. To opt-out of this change, set + `generate_to_json_function` to `false`. -* Now supports changing the serialized values of enums using `JsonValue`. +- Now supports changing the serialized values of enums using `JsonValue`. ```dart enum AutoApply { @@ -320,312 +318,315 @@ future feature work. } ``` -* `JsonSerializableGenerator.generateForAnnotatedElement` now returns +- `JsonSerializableGenerator.generateForAnnotatedElement` now returns `Iterable` instead of `String`. -* `SerializeContext` and `DeserializeContext` now have an `addMember` function - which allows `TypeHelper` instances to add additional members when handling - a field. This is useful for generating shared helpers, for instance. +- `SerializeContext` and `DeserializeContext` now have an `addMember` function + which allows `TypeHelper` instances to add additional members when handling a + field. This is useful for generating shared helpers, for instance. -* **BREAKING** The `header` option is no longer supported and must be removed +- **BREAKING** The `header` option is no longer supported and must be removed from `build.yaml`. -* If a manual build script is used the `json_serializable` builder must be +- If a manual build script is used the `json_serializable` builder must be switched to `hideOutput: true`, and the `combiningBuilder` from `source_gen` must be included following this builder. When using a generated build script with `pub run build_runner` or `webdev` this is handled automatically. ## 0.5.8+1 -* Support the Dart 2.0 stable release. +- Support the Dart 2.0 stable release. ## 0.5.8 -* Small fixes to support Dart 2 runtime semantics. +- Small fixes to support Dart 2 runtime semantics. -* Support serializing types provided by platform-specific libraries (such as +- 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 a `MissingRequiredKeysException` if - the key does not exist in the JSON map used to populate the annotated field. - * Will be captured and wrapped in a `CheckedFromJsonException` if - `checked` is enabled in `json_serializable`. +- Added support for `JsonKey.required`. + + - When `true`, generated code throws a `MissingRequiredKeysException` if the + key does not exist in the JSON map used to populate the annotated field. + - Will be captured and wrapped in a `CheckedFromJsonException` if `checked` is + enabled in `json_serializable`. + +- Added `JsonKey.disallowNullValue`. -* Added `JsonKey.disallowNullValue`. - * When `true`, generated code throws a `DisallowedNullValueException` if - the corresponding keys exist in in the JSON map, but it's value is null. - * Will be captured and wrapped in a `CheckedFromJsonException` if - `checked` is enabled in `json_serializable`. + - When `true`, generated code throws a `DisallowedNullValueException` if the + corresponding keys exist in in the JSON map, but it's value is null. + - Will be captured and wrapped in a `CheckedFromJsonException` if `checked` is + enabled in `json_serializable`. -* Added support for `Uri` conversion. +- Added support for `Uri` conversion. -* Added missing `checked` parameter to the +- Added missing `checked` parameter to the `JsonSerializableGenerator.withDefaultHelpers` constructor. -* Added `explicit_to_json` configuration option. - * See `JsonSerializableGenerator.explicitToJson` for details. +- Added `explicit_to_json` configuration option. -* Added `generate_to_json_function` configuration option. - * See `JsonSerializableGenerator.generateToJsonFunction` for details. + - See `JsonSerializableGenerator.explicitToJson` for details. + +- Added `generate_to_json_function` configuration option. + - See `JsonSerializableGenerator.generateToJsonFunction` for details. ## 0.5.6 -* Added support for `JsonSerializable.disallowUnrecognizedKeys`. - * Throws an `UnrecognizedKeysException` if it finds unrecognized keys in the +- Added support for `JsonSerializable.disallowUnrecognizedKeys`. + - Throws an `UnrecognizedKeysException` if it finds unrecognized keys in the JSON map used to populate the annotated field. - * Will be captured and wrapped in a `CheckedFromJsonException` if - `checked` is enabled in `json_serializable`. -* All `fromJson` constructors now use block syntax instead of fat arrows. + - Will be captured and wrapped in a `CheckedFromJsonException` if `checked` is + enabled in `json_serializable`. +- All `fromJson` constructors now use block syntax instead of fat arrows. ## 0.5.5 -* Added support for `JsonKey.defaultValue`. +- Added support for `JsonKey.defaultValue`. -* `enum` deserialization now uses helpers provided by `json_annotation`. +- `enum` deserialization now uses helpers provided by `json_annotation`. -* Small change to how nullable `Map` values are deserialized. +- Small change to how nullable `Map` values are deserialized. -* Small whitespace changes to `JsonLiteral` generation to align with `dartfmt`. +- Small whitespace changes to `JsonLiteral` generation to align with `dartfmt`. -* Improve detection of `toJson` and `fromJson` in nested types. +- Improve detection of `toJson` and `fromJson` in nested types. ## 0.5.4+1 -* Fixed a bug introduced in `0.5.4` in some cases where enum values are nested +- Fixed a bug introduced in `0.5.4` in some cases where enum values are nested in collections. ## 0.5.4 -* Add `checked` configuration option. If `true`, generated `fromJson` functions +- Add `checked` configuration option. If `true`, generated `fromJson` functions include extra checks to validate proper deserialization of types. -* Added `any_map` to configuration. Allows `fromJson` code to - support dynamic `Map` instances that are not explicitly - `Map`. +- Added `any_map` to configuration. Allows `fromJson` code to support dynamic + `Map` instances that are not explicitly `Map`. -* Added support for classes with type arguments. +- Added support for classes with type arguments. -* Use `Map.map` for more map conversions. Simplifies generated code and fixes - a subtle issue when the `Map` key type is `dynamic` or `Object`. +- Use `Map.map` for more map conversions. Simplifies generated code and fixes a + subtle issue when the `Map` key type is `dynamic` or `Object`. ## 0.5.3 -* Require the latest version of `package:analyzer` - `v0.32.0`. +- Require the latest version of `package:analyzer` - `v0.32.0`. -* If `JsonKey.fromJson` function parameter is `Iterable` or `Map` with type - arguments of `dynamic` or `Object`, omit the arguments when generating a - cast. - `_myHelper(json['key'] as Map)` instead of - `_myHelper(json['key'] as Map)`. +- If `JsonKey.fromJson` function parameter is `Iterable` or `Map` with type + arguments of `dynamic` or `Object`, omit the arguments when generating a cast. + `_myHelper(json['key'] as Map)` instead of + `_myHelper(json['key'] as Map)`. -* `JsonKey.fromJson`/`.toJson` now support functions with optional arguments. +- `JsonKey.fromJson`/`.toJson` now support functions with optional arguments. ## 0.5.2 -* If `JsonKey.fromJson`/`toJson` are set, apply them before any custom - or default `TypeHelper` instances. This allows custom `DateTime` parsing, - by preempting the existing `DateTime` `TypeHelper`. +- If `JsonKey.fromJson`/`toJson` are set, apply them before any custom or + default `TypeHelper` instances. This allows custom `DateTime` parsing, by + preempting the existing `DateTime` `TypeHelper`. ## 0.5.1 -* Support new `fromJson` and `toJson` fields on `JsonKey`. +- Support new `fromJson` and `toJson` fields on `JsonKey`. -* Use `log` exposed by `package:build`. This requires end-users to have at least +- Use `log` exposed by `package:build`. This requires end-users to have at least `package:build_runner` `^0.8.2`. -* Updated minimum `package:source_gen` dependency to `0.8.1` which includes +- Updated minimum `package:source_gen` dependency to `0.8.1` which includes improved error messages. ## 0.5.0 -* **BREAKING** Removed deprecated support for `require_library_directive` / +- **BREAKING** Removed deprecated support for `require_library_directive` / `requireLibraryDirective` in `build_runner` configuration. -* **BREAKING** Removed the deprecated `generators.dart` library. +- **BREAKING** Removed the deprecated `generators.dart` library. -* **BREAKING** Removed `jsonPartBuilder` function from public API. +- **BREAKING** Removed `jsonPartBuilder` function from public API. -* Support the latest `package:source_gen`. +- Support the latest `package:source_gen`. -* Private and ignored fields are now excluded when generating serialization and +- 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 +- Throw an exception if a private field or an ignored field is referenced by a required constructor argument. -* More comprehensive escaping of string literals. +- More comprehensive escaping of string literals. ### `package:json_serializable/type_helper.dart` -* **Breaking** The `nullable` parameter on `TypeHelper.serialize` and +- **Breaking** The `nullable` parameter on `TypeHelper.serialize` and `.deserialize` has been removed. It is now exposed in `SerializeContext` and - `DeserializeContext` abstract classes as a read-only property. + `DeserializeContext` abstract classes as a read-only property. -* **Potentially Breaking** The `metadata` property on `SerializeContext` and +- **Potentially Breaking** The `metadata` property on `SerializeContext` and `DeserializeContext` is 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 +- **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. +- Avoid unnecessary braces in string escapes. -* Use single quotes when generating code. +- Use single quotes when generating code. ## 0.3.2 -* The `require_library_directive` option now defaults to `false`. - The option will be removed entirely in `0.4.0`. +- The `require_library_directive` option now defaults to `false`. The option + will be removed entirely in `0.4.0`. ## 0.3.1+2 -* Support the latest version of the `analyzer` package. +- Support the latest version of the `analyzer` package. ## 0.3.1+1 -* Expanded `package:build` support to allow version `0.12.0`. +- Expanded `package:build` support to allow version `0.12.0`. ## 0.3.1 -* Add a `build.yaml` so the builder can be consumed by users of `build_runner` +- Add a `build.yaml` so the builder can be consumed by users of `build_runner` version 0.7.0. -* Now requires a Dart `2.0.0-dev` release. +- Now requires a Dart `2.0.0-dev` release. ## 0.3.0 -* **NEW** top-level library `json_serializable.dart`. +- **NEW** top-level library `json_serializable.dart`. - * Replaces now deprecated `generators.dart` to access - `JsonSerializableGenerator` and `JsonLiteralGenerator`. + - Replaces now deprecated `generators.dart` to access + `JsonSerializableGenerator` and `JsonLiteralGenerator`. - * Adds the `jsonPartBuilder` function to make it easy to create a + - Adds the `jsonPartBuilder` function to make it easy to create a `PartBuilder`, without creating an explicit dependency on `source_gen`. -* **BREAKING** `UnsupportedTypeError` added a new required constructor argument: +- **BREAKING** `UnsupportedTypeError` added a new required constructor argument: `reason`. -* **BREAKING** The deprecated `annotations.dart` library has been removed. - Use `package:json_annotation` instead. +- **BREAKING** The deprecated `annotations.dart` library has been removed. Use + `package:json_annotation` instead. -* **BREAKING** The arguments to `TypeHelper` `serialize` and `deserialize` have +- **BREAKING** The arguments to `TypeHelper` `serialize` and `deserialize` have changed. - * `SerializeContext` and `DeserializeContext` (new classes) are now passed + + - `SerializeContext` and `DeserializeContext` (new classes) are now passed instead of the `TypeHelperGenerator` typedef (which has been deleted). -* `JsonSerializableGenerator` now supports an optional `useWrappers` argument +- `JsonSerializableGenerator` now supports an optional `useWrappers` argument when generates and uses wrapper classes to (hopefully) improve the speed and memory usage of serialization – at the cost of more code. **NOTE**: `useWrappers` is not guaranteed to improve the performance of serialization. Benchmarking is recommended. -* Make `null` field handling smarter. If a field is classified as not - `nullable`, then use this knowledge when generating serialization code – even +- Make `null` field handling smarter. If a field is classified as not + `nullable`, then use this knowledge when generating serialization code – even if `includeIfNull` is `false`. ## 0.2.5 -* Throw an exception if a duplicate JSON key is detected. +- Throw an exception if a duplicate JSON key is detected. -* Support the `nullable` field on the `JsonSerializable` class annotation. +- Support the `nullable` field on the `JsonSerializable` class annotation. ## 0.2.4+1 -* Throw a more helpful error when a constructor is missing. +- Throw a more helpful error when a constructor is missing. ## 0.2.4 -* Moved the annotations in `annotations.dart` to `package:json_annotations`. - * Allows package authors to release code that has the corresponding +- Moved the annotations in `annotations.dart` to `package:json_annotations`. + + - Allows package authors to release code that has the corresponding annotations without requiring package users to inherit all of the transitive dependencies. -* Deprecated `annotations.dart`. +- Deprecated `annotations.dart`. ## 0.2.3 -* Write out `toJson` methods more efficiently when the first fields written are +- Write out `toJson` methods more efficiently when the first fields written are not intercepted by the null-checking method. ## 0.2.2+1 -* Simplify the serialization of `Map` instances when no conversion is required +- Simplify the serialization of `Map` instances when no conversion is required for `values`. -* Handle `int` literals in JSON being assigned to `double` fields. +- Handle `int` literals in JSON being assigned to `double` fields. ## 0.2.2 -* Enable support for `enum` values. -* Added `asConst` to `JsonLiteral`. -* Improved the handling of Dart-specific characters in JSON strings. +- Enable support for `enum` values. +- Added `asConst` to `JsonLiteral`. +- Improved the handling of Dart-specific characters in JSON strings. ## 0.2.1 -* Upgrade to `package:source_gen` v0.7.0 +- Upgrade to `package:source_gen` v0.7.0 ## 0.2.0+1 -* When serializing classes that implement their own `fromJson` constructor, +- When serializing classes that implement their own `fromJson` constructor, honor their constructor parameter type. ## 0.2.0 -* **BREAKING** Types are now segmented into their own libraries. +- **BREAKING** Types are now segmented into their own libraries. - * `package:json_serializable/generators.dart` contains `Generator` + - `package:json_serializable/generators.dart` contains `Generator` implementations. - * `package:json_serializable/annotations.dart` contains annotations. - This library should be imported with your target classes. + - `package:json_serializable/annotations.dart` contains annotations. This + library should be imported with your target classes. - * `package:json_serializable/type_helpers.dart` contains `TypeHelper` classes + - `package:json_serializable/type_helpers.dart` contains `TypeHelper` classes and related helpers which allow custom generation for specific types. -* **BREAKING** Generation fails for types that are not a JSON primitive or that +- **BREAKING** Generation fails for types that are not a JSON primitive or that do not explicitly supports JSON serialization. -* **BREAKING** `TypeHelper`: +- **BREAKING** `TypeHelper`: - * Removed `can` methods. Return `null` from `(de)serialize` if the provided + - Removed `can` methods. Return `null` from `(de)serialize` if the provided type is not supported. - * Added `(de)serializeNested` arguments to `(de)serialize` methods allowing - generic types. This is how support for `Iterable`, `List`, and `Map` - is implemented. + - Added `(de)serializeNested` arguments to `(de)serialize` methods allowing + generic types. This is how support for `Iterable`, `List`, and `Map` is + implemented. -* **BREAKING** `JsonKey.jsonName` was renamed to `name` and is now a named +- **BREAKING** `JsonKey.jsonName` was renamed to `name` and is now a named parameter. -* Added support for optional, non-nullable fields. +- Added support for optional, non-nullable fields. -* Added support for excluding `null` values when generating JSON. +- Added support for excluding `null` values when generating JSON. -* Eliminated all implicit casts in generated code. These would end up being +- 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. +- Provide a helpful error when generation fails due to undefined types. ## 0.1.0+1 -* Fix homepage in `pubspec.yaml`. +- Fix homepage in `pubspec.yaml`. ## 0.1.0 -* Split off from [source_gen](https://pub.dev/packages/source_gen). +- Split off from [source_gen](https://pub.dev/packages/source_gen). -* Add `/* unsafe */` comments to generated output likely to be unsafe. +- Add `/* unsafe */` comments to generated output likely to be unsafe. -* Support (de)serializing values in `Map`. +- Support (de)serializing values in `Map`. -* Fix ordering of fields when they are initialized via constructor. +- Fix ordering of fields when they are initialized via constructor. -* Don't use static members when calculating fields to (de)serialize. +- Don't use static members when calculating fields to (de)serialize. diff --git a/json_serializable/README.md b/json_serializable/README.md index d6063dc28..910829c68 100644 --- a/json_serializable/README.md +++ b/json_serializable/README.md @@ -7,10 +7,9 @@ in [package:json_annotation]. - To generate to/from JSON code for a class, annotate it with `@JsonSerializable`. You can provide arguments to `JsonSerializable` to - configure the generated code. You can also customize individual fields - by annotating them with `@JsonKey` and providing custom arguments. - See the table below for details on the - [annotation values](#annotation-values). + configure the generated code. You can also customize individual fields by + annotating them with `@JsonKey` and providing custom arguments. See the table + below for details on the [annotation values](#annotation-values). - To generate a Dart field with the contents of a file containing JSON, use the `JsonLiteral` annotation. @@ -72,7 +71,7 @@ is generated: 1. Set properties on `@JsonSerializable`. 2. Add a `@JsonKey` annotation to a field and set properties there. -3. Add configuration to `build.yaml` – [see below](#build-configuration). +3. Add configuration to `build.yaml` – [see below](#build-configuration). | `build.yaml` key | JsonSerializable | JsonKey | | -------------------------- | ------------------------------------------- | --------------------------- | @@ -116,15 +115,15 @@ is generated: [JsonKey.unknownEnumValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/unknownEnumValue.html > Note: every `JsonSerializable` field is configurable via `build.yaml` – - see the table for the corresponding key. - If you find you want all or most of your classes with the same configuration, - it may be easier to specify values once in the YAML file. Values set - explicitly on `@JsonSerializable` take precedence over settings in - `build.yaml`. +> see the table for the corresponding key. +> If you find you want all or most of your classes with the same configuration, +> it may be easier to specify values once in the YAML file. Values set +> explicitly on `@JsonSerializable` take precedence over settings in +> `build.yaml`. > Note: There is some overlap between fields on `JsonKey` and - `JsonSerializable`. In these cases, if a value is set explicitly via `JsonKey` - it will take precedence over any value set on `JsonSerializable`. +> `JsonSerializable`. In these cases, if a value is set explicitly via `JsonKey` +> it will take precedence over any value set on `JsonSerializable`. # Build configuration @@ -154,5 +153,5 @@ targets: ``` [example]: https://github.com/google/json_serializable.dart/tree/master/example -[Dart Build System]: https://github.com/dart-lang/build +[dart build system]: https://github.com/dart-lang/build [package:json_annotation]: https://pub.dev/packages/json_annotation From c7a7250eacf2968b36bd714874c1aae09ec222f6 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 19 Jan 2021 14:46:56 -0800 Subject: [PATCH 263/569] Regenerate with mono_repo v3.4.5 (#790) --- .github/workflows/dart.yml | 96 ++++++++++++++++++++++---------------- tool/ci.sh | 2 +- 2 files changed, 56 insertions(+), 42 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index bb04c92d6..6f87f7700 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -1,4 +1,4 @@ -# Created with package:mono_repo v3.4.2 +# Created with package:mono_repo v3.4.5 name: Dart CI on: push: @@ -27,13 +27,13 @@ jobs: restore-keys: | os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: cedx/setup-dart@v2 + - uses: dart-lang/setup-dart@v0.3 with: - release-channel: stable - - run: dart --version - - uses: actions/checkout@v2 + sdk: stable + - id: checkout + uses: actions/checkout@v2 - name: mono_repo self validate - run: pub global activate mono_repo 3.4.2 + run: pub global activate mono_repo 3.4.5 - name: mono_repo self validate run: pub global run mono_repo generate --validate job_002: @@ -50,69 +50,74 @@ jobs: os:ubuntu-latest;pub-cache-hosted;dart:dev os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: cedx/setup-dart@v2 + - uses: dart-lang/setup-dart@v0.3 with: - release-channel: dev - - run: dart --version - - uses: actions/checkout@v2 + sdk: dev + - id: checkout + uses: actions/checkout@v2 - id: _test_yaml_pub_upgrade name: "_test_yaml; pub upgrade --no-precompile" + if: "always() && steps.checkout.conclusion == 'success'" working-directory: _test_yaml run: pub upgrade --no-precompile - name: "_test_yaml; dartfmt -n --set-exit-if-changed ." - if: "steps._test_yaml_pub_upgrade.conclusion == 'success'" + if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" working-directory: _test_yaml run: dartfmt -n --set-exit-if-changed . - name: "_test_yaml; dartanalyzer --fatal-infos ." - if: "steps._test_yaml_pub_upgrade.conclusion == 'success'" + if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" working-directory: _test_yaml run: dartanalyzer --fatal-infos . - id: checked_yaml_pub_upgrade name: "checked_yaml; pub upgrade --no-precompile" + if: "always() && steps.checkout.conclusion == 'success'" working-directory: checked_yaml run: pub upgrade --no-precompile - name: "checked_yaml; dartfmt -n --set-exit-if-changed ." - if: "steps.checked_yaml_pub_upgrade.conclusion == 'success'" + if: "always() && steps.checked_yaml_pub_upgrade.conclusion == 'success'" working-directory: checked_yaml run: dartfmt -n --set-exit-if-changed . - name: "checked_yaml; dartanalyzer --fatal-infos ." - if: "steps.checked_yaml_pub_upgrade.conclusion == 'success'" + if: "always() && steps.checked_yaml_pub_upgrade.conclusion == 'success'" working-directory: checked_yaml run: dartanalyzer --fatal-infos . - id: example_pub_upgrade name: "example; pub upgrade --no-precompile" + if: "always() && steps.checkout.conclusion == 'success'" working-directory: example run: pub upgrade --no-precompile - name: "example; dartfmt -n --set-exit-if-changed ." - if: "steps.example_pub_upgrade.conclusion == 'success'" + if: "always() && steps.example_pub_upgrade.conclusion == 'success'" working-directory: example run: dartfmt -n --set-exit-if-changed . - name: "example; dartanalyzer --fatal-infos ." - if: "steps.example_pub_upgrade.conclusion == 'success'" + if: "always() && steps.example_pub_upgrade.conclusion == 'success'" working-directory: example run: dartanalyzer --fatal-infos . - id: json_annotation_pub_upgrade name: "json_annotation; pub upgrade --no-precompile" + if: "always() && steps.checkout.conclusion == 'success'" working-directory: json_annotation run: pub upgrade --no-precompile - name: "json_annotation; dartfmt -n --set-exit-if-changed ." - if: "steps.json_annotation_pub_upgrade.conclusion == 'success'" + if: "always() && steps.json_annotation_pub_upgrade.conclusion == 'success'" working-directory: json_annotation run: dartfmt -n --set-exit-if-changed . - name: "json_annotation; dartanalyzer --fatal-infos ." - if: "steps.json_annotation_pub_upgrade.conclusion == 'success'" + if: "always() && steps.json_annotation_pub_upgrade.conclusion == 'success'" working-directory: json_annotation run: dartanalyzer --fatal-infos . - id: json_serializable_pub_upgrade name: "json_serializable; pub upgrade --no-precompile" + if: "always() && steps.checkout.conclusion == 'success'" working-directory: json_serializable run: pub upgrade --no-precompile - name: "json_serializable; dartfmt -n --set-exit-if-changed ." - if: "steps.json_serializable_pub_upgrade.conclusion == 'success'" + if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" working-directory: json_serializable run: dartfmt -n --set-exit-if-changed . - name: "json_serializable; dartanalyzer --fatal-infos ." - if: "steps.json_serializable_pub_upgrade.conclusion == 'success'" + if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" working-directory: json_serializable run: dartanalyzer --fatal-infos . job_003: @@ -129,41 +134,45 @@ jobs: os:ubuntu-latest;pub-cache-hosted;dart:dev os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: cedx/setup-dart@v2 + - uses: dart-lang/setup-dart@v0.3 with: - release-channel: dev - - run: dart --version - - uses: actions/checkout@v2 + sdk: dev + - id: checkout + uses: actions/checkout@v2 - id: _test_yaml_pub_upgrade name: "_test_yaml; pub upgrade --no-precompile" + if: "always() && steps.checkout.conclusion == 'success'" working-directory: _test_yaml run: pub upgrade --no-precompile - name: _test_yaml; pub run test - if: "steps._test_yaml_pub_upgrade.conclusion == 'success'" + if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" working-directory: _test_yaml run: pub run test - id: checked_yaml_pub_upgrade name: "checked_yaml; pub upgrade --no-precompile" + if: "always() && steps.checkout.conclusion == 'success'" working-directory: checked_yaml run: pub upgrade --no-precompile - name: checked_yaml; pub run test - if: "steps.checked_yaml_pub_upgrade.conclusion == 'success'" + if: "always() && steps.checked_yaml_pub_upgrade.conclusion == 'success'" working-directory: checked_yaml run: pub run test - id: example_pub_upgrade name: "example; pub upgrade --no-precompile" + if: "always() && steps.checkout.conclusion == 'success'" working-directory: example run: pub upgrade --no-precompile - name: example; pub run test - if: "steps.example_pub_upgrade.conclusion == 'success'" + if: "always() && steps.example_pub_upgrade.conclusion == 'success'" working-directory: example run: pub run test - id: json_serializable_pub_upgrade name: "json_serializable; pub upgrade --no-precompile" + if: "always() && steps.checkout.conclusion == 'success'" working-directory: json_serializable run: pub upgrade --no-precompile - name: json_serializable; pub run test - if: "steps.json_serializable_pub_upgrade.conclusion == 'success'" + if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" working-directory: json_serializable run: pub run test needs: @@ -183,17 +192,18 @@ jobs: os:ubuntu-latest;pub-cache-hosted;dart:dev os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: cedx/setup-dart@v2 + - uses: dart-lang/setup-dart@v0.3 with: - release-channel: dev - - run: dart --version - - uses: actions/checkout@v2 + sdk: dev + - id: checkout + uses: actions/checkout@v2 - id: json_serializable_pub_upgrade name: "json_serializable; pub upgrade --no-precompile" + if: "always() && steps.checkout.conclusion == 'success'" working-directory: json_serializable run: pub upgrade --no-precompile - name: "json_serializable; pub run test -p chrome" - if: "steps.json_serializable_pub_upgrade.conclusion == 'success'" + if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" working-directory: json_serializable run: pub run test -p chrome needs: @@ -213,41 +223,45 @@ jobs: os:ubuntu-latest;pub-cache-hosted;dart:dev os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: cedx/setup-dart@v2 + - uses: dart-lang/setup-dart@v0.3 with: - release-channel: dev - - run: dart --version - - uses: actions/checkout@v2 + sdk: dev + - id: checkout + uses: actions/checkout@v2 - id: _test_yaml_pub_upgrade name: "_test_yaml; pub upgrade --no-precompile" + if: "always() && steps.checkout.conclusion == 'success'" working-directory: _test_yaml run: pub upgrade --no-precompile - name: "_test_yaml; pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart" - if: "steps._test_yaml_pub_upgrade.conclusion == 'success'" + if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" working-directory: _test_yaml run: pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart - id: checked_yaml_pub_upgrade name: "checked_yaml; pub upgrade --no-precompile" + if: "always() && steps.checkout.conclusion == 'success'" working-directory: checked_yaml run: pub upgrade --no-precompile - name: "checked_yaml; pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart" - if: "steps.checked_yaml_pub_upgrade.conclusion == 'success'" + if: "always() && steps.checked_yaml_pub_upgrade.conclusion == 'success'" working-directory: checked_yaml run: pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart - id: example_pub_upgrade name: "example; pub upgrade --no-precompile" + if: "always() && steps.checkout.conclusion == 'success'" working-directory: example run: pub upgrade --no-precompile - name: "example; pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart" - if: "steps.example_pub_upgrade.conclusion == 'success'" + if: "always() && steps.example_pub_upgrade.conclusion == 'success'" working-directory: example run: pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart - id: json_serializable_pub_upgrade name: "json_serializable; pub upgrade --no-precompile" + if: "always() && steps.checkout.conclusion == 'success'" working-directory: json_serializable run: pub upgrade --no-precompile - name: "json_serializable; pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart" - if: "steps.json_serializable_pub_upgrade.conclusion == 'success'" + if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" working-directory: json_serializable run: pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart needs: diff --git a/tool/ci.sh b/tool/ci.sh index 733352719..4e0e6e54f 100755 --- a/tool/ci.sh +++ b/tool/ci.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Created with package:mono_repo v3.4.2 +# Created with package:mono_repo v3.4.5 # Support built in commands on windows out of the box. function pub() { From 44e6d555a2fe3f1e1c047930c25e5b6daf312452 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 11 Feb 2021 15:33:42 -0800 Subject: [PATCH 264/569] stable null safe (#798) Bump deps in other packages while we're at it! * Test on beta as well as dev --- .github/workflows/dart.yml | 261 ++++++++++++++++++++++++++++++-- _test_yaml/mono_pkg.yaml | 1 + _test_yaml/pubspec.yaml | 4 +- checked_yaml/CHANGELOG.md | 2 +- checked_yaml/mono_pkg.yaml | 1 + checked_yaml/pubspec.yaml | 11 +- example/mono_pkg.yaml | 1 + example/pubspec.yaml | 4 +- json_annotation/CHANGELOG.md | 4 +- json_annotation/mono_pkg.yaml | 5 +- json_annotation/pubspec.yaml | 2 +- json_serializable/CHANGELOG.md | 2 +- json_serializable/mono_pkg.yaml | 1 + json_serializable/pubspec.yaml | 31 ++-- tool/ci.sh | 2 +- 15 files changed, 292 insertions(+), 40 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 6f87f7700..1176b3094 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -1,4 +1,4 @@ -# Created with package:mono_repo v3.4.5 +# Created with package:mono_repo v3.4.6 name: Dart CI on: push: @@ -33,11 +33,95 @@ jobs: - id: checkout uses: actions/checkout@v2 - name: mono_repo self validate - run: pub global activate mono_repo 3.4.5 + run: pub global activate mono_repo 3.4.6 - name: mono_repo self validate run: pub global run mono_repo generate --validate job_002: - name: "analyzer_and_format; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; `dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-infos .`" + name: "analyzer_and_format; Dart beta; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; `dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-infos .`" + runs-on: ubuntu-latest + steps: + - name: Cache Pub hosted dependencies + uses: actions/cache@v2 + with: + path: "~/.pub-cache/hosted" + key: "os:ubuntu-latest;pub-cache-hosted;dart:beta;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:dartfmt-dartanalyzer" + restore-keys: | + os:ubuntu-latest;pub-cache-hosted;dart:beta;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable + os:ubuntu-latest;pub-cache-hosted;dart:beta + os:ubuntu-latest;pub-cache-hosted + os:ubuntu-latest + - uses: dart-lang/setup-dart@v0.3 + with: + sdk: beta + - id: checkout + uses: actions/checkout@v2 + - id: _test_yaml_pub_upgrade + name: "_test_yaml; pub upgrade --no-precompile" + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: _test_yaml + run: pub upgrade --no-precompile + - name: "_test_yaml; dartfmt -n --set-exit-if-changed ." + if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" + working-directory: _test_yaml + run: dartfmt -n --set-exit-if-changed . + - name: "_test_yaml; dartanalyzer --fatal-infos ." + if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" + working-directory: _test_yaml + run: dartanalyzer --fatal-infos . + - id: checked_yaml_pub_upgrade + name: "checked_yaml; pub upgrade --no-precompile" + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: checked_yaml + run: pub upgrade --no-precompile + - name: "checked_yaml; dartfmt -n --set-exit-if-changed ." + if: "always() && steps.checked_yaml_pub_upgrade.conclusion == 'success'" + working-directory: checked_yaml + run: dartfmt -n --set-exit-if-changed . + - name: "checked_yaml; dartanalyzer --fatal-infos ." + if: "always() && steps.checked_yaml_pub_upgrade.conclusion == 'success'" + working-directory: checked_yaml + run: dartanalyzer --fatal-infos . + - id: example_pub_upgrade + name: "example; pub upgrade --no-precompile" + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: example + run: pub upgrade --no-precompile + - name: "example; dartfmt -n --set-exit-if-changed ." + if: "always() && steps.example_pub_upgrade.conclusion == 'success'" + working-directory: example + run: dartfmt -n --set-exit-if-changed . + - name: "example; dartanalyzer --fatal-infos ." + if: "always() && steps.example_pub_upgrade.conclusion == 'success'" + working-directory: example + run: dartanalyzer --fatal-infos . + - id: json_annotation_pub_upgrade + name: "json_annotation; pub upgrade --no-precompile" + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: json_annotation + run: pub upgrade --no-precompile + - name: "json_annotation; dartfmt -n --set-exit-if-changed ." + if: "always() && steps.json_annotation_pub_upgrade.conclusion == 'success'" + working-directory: json_annotation + run: dartfmt -n --set-exit-if-changed . + - name: "json_annotation; dartanalyzer --fatal-infos ." + if: "always() && steps.json_annotation_pub_upgrade.conclusion == 'success'" + working-directory: json_annotation + run: dartanalyzer --fatal-infos . + - id: json_serializable_pub_upgrade + name: "json_serializable; pub upgrade --no-precompile" + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: json_serializable + run: pub upgrade --no-precompile + - name: "json_serializable; dartfmt -n --set-exit-if-changed ." + if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" + working-directory: json_serializable + run: dartfmt -n --set-exit-if-changed . + - name: "json_serializable; dartanalyzer --fatal-infos ." + if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" + working-directory: json_serializable + run: dartanalyzer --fatal-infos . + job_003: + name: "analyzer_and_format; Dart dev; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; `dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-infos .`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies @@ -120,8 +204,67 @@ jobs: if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" working-directory: json_serializable run: dartanalyzer --fatal-infos . - job_003: - name: "unit_test; PKGS: _test_yaml, checked_yaml, example, json_serializable; `pub run test`" + job_004: + name: "unit_test; Dart beta; PKGS: _test_yaml, checked_yaml, example, json_serializable; `pub run test`" + runs-on: ubuntu-latest + steps: + - name: Cache Pub hosted dependencies + uses: actions/cache@v2 + with: + path: "~/.pub-cache/hosted" + key: "os:ubuntu-latest;pub-cache-hosted;dart:beta;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" + restore-keys: | + os:ubuntu-latest;pub-cache-hosted;dart:beta;packages:_test_yaml-checked_yaml-example-json_serializable + os:ubuntu-latest;pub-cache-hosted;dart:beta + os:ubuntu-latest;pub-cache-hosted + os:ubuntu-latest + - uses: dart-lang/setup-dart@v0.3 + with: + sdk: beta + - id: checkout + uses: actions/checkout@v2 + - id: _test_yaml_pub_upgrade + name: "_test_yaml; pub upgrade --no-precompile" + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: _test_yaml + run: pub upgrade --no-precompile + - name: _test_yaml; pub run test + if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" + working-directory: _test_yaml + run: pub run test + - id: checked_yaml_pub_upgrade + name: "checked_yaml; pub upgrade --no-precompile" + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: checked_yaml + run: pub upgrade --no-precompile + - name: checked_yaml; pub run test + if: "always() && steps.checked_yaml_pub_upgrade.conclusion == 'success'" + working-directory: checked_yaml + run: pub run test + - id: example_pub_upgrade + name: "example; pub upgrade --no-precompile" + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: example + run: pub upgrade --no-precompile + - name: example; pub run test + if: "always() && steps.example_pub_upgrade.conclusion == 'success'" + working-directory: example + run: pub run test + - id: json_serializable_pub_upgrade + name: "json_serializable; pub upgrade --no-precompile" + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: json_serializable + run: pub upgrade --no-precompile + - name: json_serializable; pub run test + if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" + working-directory: json_serializable + run: pub run test + needs: + - job_001 + - job_002 + - job_003 + job_005: + name: "unit_test; Dart dev; PKGS: _test_yaml, checked_yaml, example, json_serializable; `pub run test`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies @@ -178,8 +321,41 @@ jobs: needs: - job_001 - job_002 - job_004: - name: "unit_test; PKG: json_serializable; `pub run test -p chrome`" + - job_003 + job_006: + name: "unit_test; Dart beta; PKG: json_serializable; `pub run test -p chrome`" + runs-on: ubuntu-latest + steps: + - name: Cache Pub hosted dependencies + uses: actions/cache@v2 + with: + path: "~/.pub-cache/hosted" + key: "os:ubuntu-latest;pub-cache-hosted;dart:beta;packages:json_serializable;commands:test_2" + restore-keys: | + os:ubuntu-latest;pub-cache-hosted;dart:beta;packages:json_serializable + os:ubuntu-latest;pub-cache-hosted;dart:beta + os:ubuntu-latest;pub-cache-hosted + os:ubuntu-latest + - uses: dart-lang/setup-dart@v0.3 + with: + sdk: beta + - id: checkout + uses: actions/checkout@v2 + - id: json_serializable_pub_upgrade + name: "json_serializable; pub upgrade --no-precompile" + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: json_serializable + run: pub upgrade --no-precompile + - name: "json_serializable; pub run test -p chrome" + if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" + working-directory: json_serializable + run: pub run test -p chrome + needs: + - job_001 + - job_002 + - job_003 + job_007: + name: "unit_test; Dart dev; PKG: json_serializable; `pub run test -p chrome`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies @@ -209,8 +385,72 @@ jobs: needs: - job_001 - job_002 - job_005: - name: "ensure_build; PKGS: _test_yaml, checked_yaml, example, json_serializable; `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`" + - job_003 + job_008: + name: "ensure_build; Dart beta; PKGS: _test_yaml, checked_yaml, example, json_serializable; `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`" + runs-on: ubuntu-latest + steps: + - name: Cache Pub hosted dependencies + uses: actions/cache@v2 + with: + path: "~/.pub-cache/hosted" + key: "os:ubuntu-latest;pub-cache-hosted;dart:beta;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_1" + restore-keys: | + os:ubuntu-latest;pub-cache-hosted;dart:beta;packages:_test_yaml-checked_yaml-example-json_serializable + os:ubuntu-latest;pub-cache-hosted;dart:beta + os:ubuntu-latest;pub-cache-hosted + os:ubuntu-latest + - uses: dart-lang/setup-dart@v0.3 + with: + sdk: beta + - id: checkout + uses: actions/checkout@v2 + - id: _test_yaml_pub_upgrade + name: "_test_yaml; pub upgrade --no-precompile" + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: _test_yaml + run: pub upgrade --no-precompile + - name: "_test_yaml; pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart" + if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" + working-directory: _test_yaml + run: pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart + - id: checked_yaml_pub_upgrade + name: "checked_yaml; pub upgrade --no-precompile" + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: checked_yaml + run: pub upgrade --no-precompile + - name: "checked_yaml; pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart" + if: "always() && steps.checked_yaml_pub_upgrade.conclusion == 'success'" + working-directory: checked_yaml + run: pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart + - id: example_pub_upgrade + name: "example; pub upgrade --no-precompile" + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: example + run: pub upgrade --no-precompile + - name: "example; pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart" + if: "always() && steps.example_pub_upgrade.conclusion == 'success'" + working-directory: example + run: pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart + - id: json_serializable_pub_upgrade + name: "json_serializable; pub upgrade --no-precompile" + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: json_serializable + run: pub upgrade --no-precompile + - name: "json_serializable; pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart" + if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" + working-directory: json_serializable + run: pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart + needs: + - job_001 + - job_002 + - job_003 + - job_004 + - job_005 + - job_006 + - job_007 + job_009: + name: "ensure_build; Dart dev; PKGS: _test_yaml, checked_yaml, example, json_serializable; `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies @@ -269,3 +509,6 @@ jobs: - job_002 - job_003 - job_004 + - job_005 + - job_006 + - job_007 diff --git a/_test_yaml/mono_pkg.yaml b/_test_yaml/mono_pkg.yaml index fc8565fd2..e99b82ec6 100644 --- a/_test_yaml/mono_pkg.yaml +++ b/_test_yaml/mono_pkg.yaml @@ -1,5 +1,6 @@ # See https://github.com/google/mono_repo.dart for details on this file dart: +- beta # change this to 1.12.0 when it's released! - dev stages: diff --git a/_test_yaml/pubspec.yaml b/_test_yaml/pubspec.yaml index ad32a8485..1343b2698 100644 --- a/_test_yaml/pubspec.yaml +++ b/_test_yaml/pubspec.yaml @@ -11,6 +11,7 @@ dev_dependencies: json_annotation: any json_serializable: any test: ^1.6.0 + yaml: ^3.0.0 dependency_overrides: checked_yaml: @@ -19,6 +20,3 @@ dependency_overrides: path: ../json_annotation json_serializable: path: ../json_serializable - - # For yaml! - yaml: 3.0.0-nullsafety.0 diff --git a/checked_yaml/CHANGELOG.md b/checked_yaml/CHANGELOG.md index b39c887e4..ff1a155c7 100644 --- a/checked_yaml/CHANGELOG.md +++ b/checked_yaml/CHANGELOG.md @@ -1,4 +1,4 @@ -## 2.0.0-nullsafety-dev +## 2.0.0-dev - *BREAKING* `checkedYamlDecode` `sourceUrl` parameter is now a `Uri`. - Require at least Dart `2.12.0-0`. diff --git a/checked_yaml/mono_pkg.yaml b/checked_yaml/mono_pkg.yaml index 18804424f..cf36065b9 100644 --- a/checked_yaml/mono_pkg.yaml +++ b/checked_yaml/mono_pkg.yaml @@ -1,5 +1,6 @@ # See https://github.com/google/mono_repo.dart for details on this file dart: +- beta # change this to 1.12.0 when it's released! - dev stages: diff --git a/checked_yaml/pubspec.yaml b/checked_yaml/pubspec.yaml index 1f3f1867f..8b7674a0d 100644 --- a/checked_yaml/pubspec.yaml +++ b/checked_yaml/pubspec.yaml @@ -1,5 +1,5 @@ name: checked_yaml -version: 1.9.0-nullsafety-dev +version: 1.9.0-dev description: >- Generate more helpful exceptions when decoding YAML documents using @@ -10,15 +10,15 @@ environment: dependencies: json_annotation: '>=2.2.0 <5.0.0' - source_span: ^1.8.0-nullsafety.4 - yaml: ^3.0.0-nullsafety.0 + source_span: ^1.8.0 + yaml: ^3.0.0 dev_dependencies: build_runner: ^1.0.0 build_verify: ^1.1.0 json_serializable: ^3.0.0 path: ^1.0.0 - test: ^1.16.0-nullsafety.7 + test: ^1.16.0 test_process: ^1.0.1 dependency_overrides: @@ -26,6 +26,3 @@ dependency_overrides: path: ../json_annotation json_serializable: path: ../json_serializable - # Need to force yaml for now due to dev dependencies - # build_runner -> build_config -> pubspec_parse - yaml: 3.0.0-nullsafety.0 diff --git a/example/mono_pkg.yaml b/example/mono_pkg.yaml index 7ab68ee9f..cf6269f0f 100644 --- a/example/mono_pkg.yaml +++ b/example/mono_pkg.yaml @@ -1,5 +1,6 @@ # See https://github.com/google/mono_repo.dart for details on this file dart: +- beta # change this to 1.12.0 when it's released! - dev stages: diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 0c90886ed..c898af200 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -15,9 +15,9 @@ dev_dependencies: json_serializable: ^3.2.0 # Used by tests. Not required to use `json_serializable`. - path: ^1.8.0-nullsafety.3 + path: ^1.8.0 # Used by tests. Not required to use `json_serializable`. - test: ^1.16.0-nullsafety.9 + test: ^1.16.0 dependency_overrides: json_annotation: diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index bb76dd097..9beb4d0d6 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -1,5 +1,7 @@ -## 4.0.0-nullsafety.0 +## 4.0.0 +- Support null safety. +- Requires Dart 2.12. - Updated `$checkedConvert` helper to support null-safety. - Removed the `nullable` field on `JsonKey` – the constructor entry still exists, but it's marked `@Deprecated`. The nullability of a field is now diff --git a/json_annotation/mono_pkg.yaml b/json_annotation/mono_pkg.yaml index e23fee100..a1250b87f 100644 --- a/json_annotation/mono_pkg.yaml +++ b/json_annotation/mono_pkg.yaml @@ -1,7 +1,10 @@ # See https://github.com/google/mono_repo.dart for details on this file +dart: +- beta # change this to 1.12.0 when it's released! +- dev + stages: - analyzer_and_format: - group: - dartfmt - dartanalyzer: --fatal-infos . - dart: [dev] diff --git a/json_annotation/pubspec.yaml b/json_annotation/pubspec.yaml index 8e8dc63a4..a273d6b76 100644 --- a/json_annotation/pubspec.yaml +++ b/json_annotation/pubspec.yaml @@ -1,5 +1,5 @@ name: json_annotation -version: 4.0.0-nullsafety.0 +version: 4.0.0 description: >- Classes and helper functions that support JSON code generation via the `json_serializable` package. diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 75ad40635..9e5f73792 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,4 +1,4 @@ -## 4.0.0-nullsafety.0 +## 4.0.0-dev - Generates null-safe code. - The `nullable` field on `JsonKey` ignored. The nullability of a field is now diff --git a/json_serializable/mono_pkg.yaml b/json_serializable/mono_pkg.yaml index 1d552e889..a483c5d6e 100644 --- a/json_serializable/mono_pkg.yaml +++ b/json_serializable/mono_pkg.yaml @@ -1,5 +1,6 @@ # See https://github.com/google/mono_repo.dart for details on this file dart: +- beta # change this to 1.12.0 when it's released! - dev stages: diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index b8546e85a..befcc8d76 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,34 +1,39 @@ name: json_serializable -version: 4.0.0-nullsafety.0 +version: 4.0.0-dev description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. repository: https://github.com/google/json_serializable.dart environment: + # Keeping this <2.12.0 because the code is not null safe – yet! sdk: '>=2.11.0 <3.0.0' dependencies: - analyzer: '>=0.40.6 <0.42.0' - build: '>=0.12.6 <2.0.0' - build_config: '>=0.2.6 <0.5.0' + analyzer: ^0.41.2 + build: ^1.6.1 + build_config: ^0.4.4 # Use a tight version constraint to ensure that a constraint on # `json_annotation` properly constrains all features it provides. # For v3 only – allow a wide range since the only change was to REMOVE things # from json_annotation - json_annotation: '>=4.0.0-nullsafety.0 <4.1.0' - meta: ^1.3.0-nullsafety.5 - path: ^1.8.0-nullsafety.2 - source_gen: ^0.9.6 + json_annotation: '>=4.0.0 <4.1.0' + meta: ^1.3.0 + path: ^1.8.0 + source_gen: ^0.9.9 dev_dependencies: build_runner: ^1.0.0 build_verify: ^1.1.0 collection: ^1.14.0 dart_style: ^1.2.0 - logging: ^0.11.3+1 - pub_semver: ^1.4.0 + logging: ^1.0.0 + pub_semver: ^2.0.0 source_gen_test: ^0.1.0 - stack_trace: ^1.10.0-nullsafety.5 - test: ^1.16.0-nullsafety.7 - yaml: ^3.0.0-nullsafety.0 + stack_trace: ^1.10.0 + test: ^1.16.0 + yaml: ^3.0.0 + +dependency_overrides: + json_annotation: + path: ../json_annotation diff --git a/tool/ci.sh b/tool/ci.sh index 4e0e6e54f..04aa24cfe 100755 --- a/tool/ci.sh +++ b/tool/ci.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Created with package:mono_repo v3.4.5 +# Created with package:mono_repo v3.4.6 # Support built in commands on windows out of the box. function pub() { From 145d8ccb0541404c4ef901a1772c36bee56c2189 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 11 Feb 2021 16:24:21 -0800 Subject: [PATCH 265/569] Prepare to release v4 of json_serializable (#799) --- json_serializable/CHANGELOG.md | 3 ++- json_serializable/pubspec.yaml | 8 ++------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 9e5f73792..1e9d8c1db 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,5 +1,6 @@ -## 4.0.0-dev +## 4.0.0 +- Requires Dart 2.12 or greater. - Generates null-safe code. - The `nullable` field on `JsonKey` ignored. The nullability of a field is now determined by the Dart type system. diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index befcc8d76..64a90bdaf 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,12 +1,12 @@ name: json_serializable -version: 4.0.0-dev +version: 4.0.0 description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. repository: https://github.com/google/json_serializable.dart environment: # Keeping this <2.12.0 because the code is not null safe – yet! - sdk: '>=2.11.0 <3.0.0' + sdk: '>=2.11.99 <3.0.0' dependencies: analyzer: ^0.41.2 @@ -33,7 +33,3 @@ dev_dependencies: stack_trace: ^1.10.0 test: ^1.16.0 yaml: ^3.0.0 - -dependency_overrides: - json_annotation: - path: ../json_annotation From 829b45a4d861052046c6b646fa37c315e5c61253 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 11 Feb 2021 17:18:38 -0800 Subject: [PATCH 266/569] copy constants - cannot publish otherwise (#800) --- json_serializable/lib/src/constants.dart | 2 -- .../src/_json_serializable_test_input.dart | 3 ++- .../test/src/constants_copy.dart | 23 +++++++++++++++++++ 3 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 json_serializable/test/src/constants_copy.dart diff --git a/json_serializable/lib/src/constants.dart b/json_serializable/lib/src/constants.dart index 697cc69ef..9949b77cc 100644 --- a/json_serializable/lib/src/constants.dart +++ b/json_serializable/lib/src/constants.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.12 - /// Name used for closure argument when generating calls to `map`. const closureArg = 'e'; diff --git a/json_serializable/test/src/_json_serializable_test_input.dart b/json_serializable/test/src/_json_serializable_test_input.dart index e43b91620..7ba5c0f3f 100644 --- a/json_serializable/test/src/_json_serializable_test_input.dart +++ b/json_serializable/test/src/_json_serializable_test_input.dart @@ -7,11 +7,12 @@ import 'dart:collection'; import 'package:json_annotation/json_annotation.dart'; -import 'package:json_serializable/src/constants.dart'; // ignore: import_of_legacy_library_into_null_safe import 'package:source_gen_test/annotations.dart'; +part 'constants_copy.dart'; + part 'checked_test_input.dart'; part 'core_subclass_type_input.dart'; diff --git a/json_serializable/test/src/constants_copy.dart b/json_serializable/test/src/constants_copy.dart new file mode 100644 index 000000000..27b33fb51 --- /dev/null +++ b/json_serializable/test/src/constants_copy.dart @@ -0,0 +1,23 @@ +// 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. + +// @dart=2.12 + +part of '_json_serializable_test_input.dart'; + +// TODO: remove this and return link to lib/src/constants.dart once this +// package runs with full null safety + +/// Name used for closure argument when generating calls to `map`. +const closureArg = 'e'; + +const generatedLocalVarName = 'val'; +const toJsonMapHelperName = 'writeNotNull'; + +const converterOrKeyInstructions = r''' +* Use `JsonConverter` + https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonConverter-class.html +* Use `JsonKey` fields `fromJson` and `toJson` + https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/fromJson.html + https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/toJson.html'''; From 81d7abc96f3f3c4154646527bbe851709da137db Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 11 Feb 2021 19:51:27 -0800 Subject: [PATCH 267/569] Update example to latest stable releases (#801) --- example/README.md | 4 ++-- example/pubspec.yaml | 10 ++-------- example/test/readme_test.dart | 4 ++-- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/example/README.md b/example/README.md index 89d25aabc..710bfe171 100644 --- a/example/README.md +++ b/example/README.md @@ -5,11 +5,11 @@ dependencies to your `pubspec.yaml`. ```yaml dependencies: - json_annotation: ^3.0.0 + json_annotation: ^4.0.0 dev_dependencies: build_runner: ^1.0.0 - json_serializable: ^3.2.0 + json_serializable: ^4.0.0 ``` Annotate your code with classes defined in diff --git a/example/pubspec.yaml b/example/pubspec.yaml index c898af200..3bd996e31 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -4,7 +4,7 @@ environment: sdk: '>=2.12.0-0 <3.0.0' dependencies: - json_annotation: ^3.0.0 + json_annotation: ^4.0.0 dev_dependencies: build_runner: ^1.0.0 @@ -12,15 +12,9 @@ dev_dependencies: # Used by tests. Not required to use `json_serializable`. build_verify: ^1.0.0 - json_serializable: ^3.2.0 + json_serializable: ^4.0.0 # Used by tests. Not required to use `json_serializable`. path: ^1.8.0 # Used by tests. Not required to use `json_serializable`. test: ^1.16.0 - -dependency_overrides: - json_annotation: - path: ../json_annotation - json_serializable: - path: ../json_serializable diff --git a/example/test/readme_test.dart b/example/test/readme_test.dart index 342c07df8..2005b5626 100644 --- a/example/test/readme_test.dart +++ b/example/test/readme_test.dart @@ -25,9 +25,9 @@ void _expect(String fileName) { const _pubspecContent = r''' dependencies: - json_annotation: ^3.0.0 + json_annotation: ^4.0.0 dev_dependencies: build_runner: ^1.0.0 - json_serializable: ^3.2.0 + json_serializable: ^4.0.0 '''; From 26b6793bc8821f4dcd7bb42af7626d0e5708aa42 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 18 Feb 2021 10:42:04 -0800 Subject: [PATCH 268/569] allow latest pkg:analyzer (#804) --- json_serializable/CHANGELOG.md | 4 ++++ json_serializable/lib/src/json_key_utils.dart | 10 +++++++++- json_serializable/pubspec.yaml | 4 ++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 1e9d8c1db..014f05c3d 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,7 @@ +## 4.0.1 + +- Allow latest `package:analyzer`. + ## 4.0.0 - Requires Dart 2.12 or greater. diff --git a/json_serializable/lib/src/json_key_utils.dart b/json_serializable/lib/src/json_key_utils.dart index 890479de4..0a51473c4 100644 --- a/json_serializable/lib/src/json_key_utils.dart +++ b/json_serializable/lib/src/json_key_utils.dart @@ -136,7 +136,7 @@ JsonKey _from(FieldElement element, JsonSerializable classAnnotation) { } assert(targetEnumType != null); final annotatedEnumType = annotationValue.objectValue.type; - if (annotatedEnumType != targetEnumType) { + if (!_interfaceTypesEqual(annotatedEnumType, targetEnumType)) { throwUnsupported( element, '`$fieldName` has type ' @@ -254,3 +254,11 @@ bool _includeIfNull( } return keyIncludeIfNull ?? classIncludeIfNull; } + +bool _interfaceTypesEqual(DartType a, DartType b) { + if (a is InterfaceType && b is InterfaceType) { + // Handle nullability case. Pretty sure this is fine for enums. + return a.element == b.element; + } + return a == b; +} diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 64a90bdaf..cc7984066 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 4.0.0 +version: 4.0.1 description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. @@ -9,7 +9,7 @@ environment: sdk: '>=2.11.99 <3.0.0' dependencies: - analyzer: ^0.41.2 + analyzer: '>=0.41.2 <2.0.0' build: ^1.6.1 build_config: ^0.4.4 From 209625fa757cc87f9f3df54add6c304ba09fe67a Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 18 Feb 2021 11:33:57 -0800 Subject: [PATCH 269/569] update generated docs (#805) --- json_serializable/README.md | 38 ++++++++++++++++++------------------ json_serializable/doc/doc.md | 38 ++++++++++++++++++------------------ 2 files changed, 38 insertions(+), 38 deletions(-) diff --git a/json_serializable/README.md b/json_serializable/README.md index 910829c68..be130cab1 100644 --- a/json_serializable/README.md +++ b/json_serializable/README.md @@ -94,25 +94,25 @@ is generated: | | | [JsonKey.toJson] | | | | [JsonKey.unknownEnumValue] | -[JsonSerializable.anyMap]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/anyMap.html -[JsonSerializable.checked]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/checked.html -[JsonSerializable.createFactory]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/createFactory.html -[JsonSerializable.createToJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/createToJson.html -[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html -[JsonSerializable.explicitToJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/explicitToJson.html -[JsonSerializable.fieldRename]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/fieldRename.html -[JsonSerializable.genericArgumentFactories]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/genericArgumentFactories.html -[JsonSerializable.ignoreUnannotated]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/ignoreUnannotated.html -[JsonSerializable.includeIfNull]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/includeIfNull.html -[JsonKey.includeIfNull]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/includeIfNull.html -[JsonKey.defaultValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/defaultValue.html -[JsonKey.disallowNullValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/disallowNullValue.html -[JsonKey.fromJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/fromJson.html -[JsonKey.ignore]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/ignore.html -[JsonKey.name]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/name.html -[JsonKey.required]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/required.html -[JsonKey.toJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/toJson.html -[JsonKey.unknownEnumValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/unknownEnumValue.html +[JsonSerializable.anyMap]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonSerializable/anyMap.html +[JsonSerializable.checked]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonSerializable/checked.html +[JsonSerializable.createFactory]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonSerializable/createFactory.html +[JsonSerializable.createToJson]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonSerializable/createToJson.html +[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html +[JsonSerializable.explicitToJson]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonSerializable/explicitToJson.html +[JsonSerializable.fieldRename]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonSerializable/fieldRename.html +[JsonSerializable.genericArgumentFactories]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonSerializable/genericArgumentFactories.html +[JsonSerializable.ignoreUnannotated]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonSerializable/ignoreUnannotated.html +[JsonSerializable.includeIfNull]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonSerializable/includeIfNull.html +[JsonKey.includeIfNull]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonKey/includeIfNull.html +[JsonKey.defaultValue]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonKey/defaultValue.html +[JsonKey.disallowNullValue]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonKey/disallowNullValue.html +[JsonKey.fromJson]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonKey/fromJson.html +[JsonKey.ignore]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonKey/ignore.html +[JsonKey.name]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonKey/name.html +[JsonKey.required]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonKey/required.html +[JsonKey.toJson]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonKey/toJson.html +[JsonKey.unknownEnumValue]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonKey/unknownEnumValue.html > Note: every `JsonSerializable` field is configurable via `build.yaml` – > see the table for the corresponding key. diff --git a/json_serializable/doc/doc.md b/json_serializable/doc/doc.md index 386068764..52248799d 100644 --- a/json_serializable/doc/doc.md +++ b/json_serializable/doc/doc.md @@ -19,22 +19,22 @@ | | | [JsonKey.toJson] | | | | [JsonKey.unknownEnumValue] | -[JsonSerializable.anyMap]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/anyMap.html -[JsonSerializable.checked]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/checked.html -[JsonSerializable.createFactory]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/createFactory.html -[JsonSerializable.createToJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/createToJson.html -[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html -[JsonSerializable.explicitToJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/explicitToJson.html -[JsonSerializable.fieldRename]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/fieldRename.html -[JsonSerializable.genericArgumentFactories]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/genericArgumentFactories.html -[JsonSerializable.ignoreUnannotated]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/ignoreUnannotated.html -[JsonSerializable.includeIfNull]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/includeIfNull.html -[JsonKey.includeIfNull]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/includeIfNull.html -[JsonKey.defaultValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/defaultValue.html -[JsonKey.disallowNullValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/disallowNullValue.html -[JsonKey.fromJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/fromJson.html -[JsonKey.ignore]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/ignore.html -[JsonKey.name]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/name.html -[JsonKey.required]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/required.html -[JsonKey.toJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/toJson.html -[JsonKey.unknownEnumValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/unknownEnumValue.html +[JsonSerializable.anyMap]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonSerializable/anyMap.html +[JsonSerializable.checked]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonSerializable/checked.html +[JsonSerializable.createFactory]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonSerializable/createFactory.html +[JsonSerializable.createToJson]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonSerializable/createToJson.html +[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html +[JsonSerializable.explicitToJson]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonSerializable/explicitToJson.html +[JsonSerializable.fieldRename]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonSerializable/fieldRename.html +[JsonSerializable.genericArgumentFactories]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonSerializable/genericArgumentFactories.html +[JsonSerializable.ignoreUnannotated]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonSerializable/ignoreUnannotated.html +[JsonSerializable.includeIfNull]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonSerializable/includeIfNull.html +[JsonKey.includeIfNull]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonKey/includeIfNull.html +[JsonKey.defaultValue]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonKey/defaultValue.html +[JsonKey.disallowNullValue]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonKey/disallowNullValue.html +[JsonKey.fromJson]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonKey/fromJson.html +[JsonKey.ignore]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonKey/ignore.html +[JsonKey.name]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonKey/name.html +[JsonKey.required]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonKey/required.html +[JsonKey.toJson]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonKey/toJson.html +[JsonKey.unknownEnumValue]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonKey/unknownEnumValue.html From 17805c1b8bbd65f35e8c04c2f4d2ff9a51521407 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 22 Feb 2021 10:21:38 -0800 Subject: [PATCH 270/569] enable and fix a new lint (#809) --- analysis_options.yaml | 1 + json_serializable/tool/doc_builder.dart | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index 74a2d9a9a..6b1f8d775 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -8,6 +8,7 @@ linter: - always_require_non_null_named_parameters - annotate_overrides - avoid_catching_errors + - avoid_dynamic_calls - avoid_empty_else - avoid_function_literals_in_foreach_calls - avoid_init_to_null diff --git a/json_serializable/tool/doc_builder.dart b/json_serializable/tool/doc_builder.dart index 37e5de5db..1aa0be2c9 100644 --- a/json_serializable/tool/doc_builder.dart +++ b/json_serializable/tool/doc_builder.dart @@ -21,7 +21,7 @@ class _DocBuilder extends Builder { final lockFileAssetId = AssetId(buildStep.inputId.package, 'pubspec.lock'); final lockFileContent = await buildStep.readAsString(lockFileAssetId); final lockFileYaml = - loadYaml(lockFileContent, sourceUrl: lockFileAssetId.uri); + loadYaml(lockFileContent, sourceUrl: lockFileAssetId.uri) as YamlMap; final pkgMap = lockFileYaml['packages'] as YamlMap; final jsonAnnotationMap = pkgMap['json_annotation'] as YamlMap; final jsonAnnotationVersionString = jsonAnnotationMap['version'] as String; From 7af0e17797f35bd7d77b19a09f591b33859124c1 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 24 Feb 2021 21:19:07 -0800 Subject: [PATCH 271/569] Remove experiment bits (#810) --- json_serializable/test/json_serializable_test.dart | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/json_serializable/test/json_serializable_test.dart b/json_serializable/test/json_serializable_test.dart index 8c3c6351f..0da37ec0e 100644 --- a/json_serializable/test/json_serializable_test.dart +++ b/json_serializable/test/json_serializable_test.dart @@ -3,7 +3,6 @@ // BSD-style license that can be found in the LICENSE file. @TestOn('vm') -import 'package:build/experiments.dart'; import 'package:json_serializable/json_serializable.dart'; import 'package:path/path.dart' as p; import 'package:source_gen_test/source_gen_test.dart'; @@ -11,12 +10,9 @@ import 'package:test/test.dart'; Future main() async { initializeBuildLogTracking(); - final reader = await withEnabledExperiments( - () => initializeLibraryReaderForDirectory( - p.join('test', 'src'), - '_json_serializable_test_input.dart', - ), - ['non-nullable'], + final reader = await initializeLibraryReaderForDirectory( + p.join('test', 'src'), + '_json_serializable_test_input.dart', ); testAnnotatedElements( From 2b796be792ac78bcdacfe07686c2e8ab2e980601 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Fri, 26 Feb 2021 11:44:19 -0800 Subject: [PATCH 272/569] Publish checked_yaml v2 null-safe, stable (#812) Fixes https://github.com/google/json_serializable.dart/issues/793 --- checked_yaml/CHANGELOG.md | 2 +- checked_yaml/pubspec.yaml | 15 +++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/checked_yaml/CHANGELOG.md b/checked_yaml/CHANGELOG.md index ff1a155c7..5fd16cb22 100644 --- a/checked_yaml/CHANGELOG.md +++ b/checked_yaml/CHANGELOG.md @@ -1,4 +1,4 @@ -## 2.0.0-dev +## 2.0.0 - *BREAKING* `checkedYamlDecode` `sourceUrl` parameter is now a `Uri`. - Require at least Dart `2.12.0-0`. diff --git a/checked_yaml/pubspec.yaml b/checked_yaml/pubspec.yaml index 8b7674a0d..dfd0972e8 100644 --- a/checked_yaml/pubspec.yaml +++ b/checked_yaml/pubspec.yaml @@ -1,28 +1,27 @@ name: checked_yaml -version: 1.9.0-dev +version: 2.0.0 description: >- Generate more helpful exceptions when decoding YAML documents using package:json_serializable and package:yaml. -repository: https://github.com/google/json_serializable.dart +repository: https://github.com/google/json_serializable.dart/tree/master/checked_yaml environment: sdk: '>=2.12.0-0 <3.0.0' dependencies: - json_annotation: '>=2.2.0 <5.0.0' + json_annotation: ^4.0.0 source_span: ^1.8.0 yaml: ^3.0.0 dev_dependencies: build_runner: ^1.0.0 build_verify: ^1.1.0 - json_serializable: ^3.0.0 + json_serializable: ^4.0.0 path: ^1.0.0 test: ^1.16.0 test_process: ^1.0.1 dependency_overrides: - json_annotation: - path: ../json_annotation - json_serializable: - path: ../json_serializable + # Need to update dependencies on these packages + build_config: ^0.4.4 + pubspec_parse: ^0.1.5 From af82671d12a01a3b9b4fef6e0e6241c42ad53975 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Sun, 28 Feb 2021 21:55:16 -0800 Subject: [PATCH 273/569] Correctly handle nullable `Map` and `Iterable` JSON types... (#813) ..exposed by both class- and function-based converters Release v4.0.2 --- json_serializable/CHANGELOG.md | 5 ++++ .../lib/src/shared_checkers.dart | 6 ++-- json_serializable/pubspec.yaml | 4 +-- .../test/json_serializable_test.dart | 1 + .../test/src/to_from_json_test_input.dart | 29 +++++++++++++++++++ 5 files changed, 41 insertions(+), 4 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 014f05c3d..0f1cd2fb6 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,8 @@ +## 4.0.2 + +- Correctly handle nullable `Map` and `Iterable` JSON types exposed by both + class- and function-based converters. + ## 4.0.1 - Allow latest `package:analyzer`. diff --git a/json_serializable/lib/src/shared_checkers.dart b/json_serializable/lib/src/shared_checkers.dart index 595f8ead4..0f4a6dca3 100644 --- a/json_serializable/lib/src/shared_checkers.dart +++ b/json_serializable/lib/src/shared_checkers.dart @@ -43,10 +43,12 @@ String asStatement(DartType type) { return ''; } + final nullableSuffix = type.isNullableType ? '?' : ''; + if (coreIterableTypeChecker.isAssignableFromType(type)) { final itemType = coreIterableGenericType(type); if (isLikeDynamic(itemType)) { - return ' as List'; + return ' as List$nullableSuffix'; } } @@ -55,7 +57,7 @@ String asStatement(DartType type) { assert(args.length == 2); if (args.every(isLikeDynamic)) { - return ' as Map'; + return ' as Map$nullableSuffix'; } } diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index cc7984066..a59c05b1c 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,9 +1,9 @@ name: json_serializable -version: 4.0.1 +version: 4.0.2 description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. -repository: https://github.com/google/json_serializable.dart +repository: https://github.com/google/json_serializable.dart/tree/master/json_serializable environment: # Keeping this <2.12.0 because the code is not null safe – yet! sdk: '>=2.11.99 <3.0.0' diff --git a/json_serializable/test/json_serializable_test.dart b/json_serializable/test/json_serializable_test.dart index 0da37ec0e..724f13361 100644 --- a/json_serializable/test/json_serializable_test.dart +++ b/json_serializable/test/json_serializable_test.dart @@ -47,6 +47,7 @@ const _expectedAnnotatedTests = { 'FinalFields', 'FinalFieldsNotSetInCtor', 'FromDynamicCollection', + 'FromNullableDynamicCollection', 'GeneralTestClass1', 'GeneralTestClass2', 'GenericArgumentFactoriesFlagWithoutGenericType', diff --git a/json_serializable/test/src/to_from_json_test_input.dart b/json_serializable/test/src/to_from_json_test_input.dart index 497445b8b..321146901 100644 --- a/json_serializable/test/src/to_from_json_test_input.dart +++ b/json_serializable/test/src/to_from_json_test_input.dart @@ -170,6 +170,35 @@ class FromDynamicCollection { late String iterableField; } +String _fromNullableDynamicMap(Map? input) => ''; + +String _fromNullableDynamicList(List? input) => 'null'; + +String _fromNullableDynamicIterable(Iterable? input) => 'null'; + +@ShouldGenerate( + r''' +FromNullableDynamicCollection _$FromNullableDynamicCollectionFromJson( + Map json) { + return FromNullableDynamicCollection() + ..mapField = _fromNullableDynamicMap(json['mapField'] as Map?) + ..listField = _fromNullableDynamicList(json['listField'] as List?) + ..iterableField = + _fromNullableDynamicIterable(json['iterableField'] as List?); +} +''', + configurations: ['default'], +) +@JsonSerializable(createToJson: false) +class FromNullableDynamicCollection { + @JsonKey(fromJson: _fromNullableDynamicMap) + late String mapField; + @JsonKey(fromJson: _fromNullableDynamicList) + late String listField; + @JsonKey(fromJson: _fromNullableDynamicIterable) + late String iterableField; +} + String _noArgs() => throw UnimplementedError(); @ShouldThrow( From 0dd731c764fb256b4f91ce8195cb3f2a62b4a553 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Sun, 28 Feb 2021 21:56:19 -0800 Subject: [PATCH 274/569] General cleanup (#814) --- _test_yaml/test/yaml_test.dart | 3 --- example/test/json_convert_example_test.dart | 24 ++++++++++--------- .../test/generic_files/generic_test.dart | 13 +++++----- .../test/integration/integration_test.dart | 2 +- .../test/kitchen_sink/kitchen_sink_test.dart | 16 +++++++------ .../kitchen_sink_test_shared.dart | 21 ++++++++++++++++ .../kitchen_sink/kitchen_sink_yaml_test.dart | 15 +++++------- .../type_test.bigint_test.dart | 2 +- .../supported_types/type_test.bool_test.dart | 2 +- .../type_test.datetime_test.dart | 2 +- .../type_test.double_test.dart | 2 +- .../type_test.duration_test.dart | 2 +- .../type_test.enumtype_test.dart | 2 +- .../supported_types/type_test.int_test.dart | 2 +- .../type_test.iterable_test.dart | 2 +- .../supported_types/type_test.list_test.dart | 2 +- .../supported_types/type_test.map_test.dart | 2 +- .../supported_types/type_test.num_test.dart | 2 +- .../type_test.object_test.dart | 2 +- .../supported_types/type_test.set_test.dart | 2 +- .../type_test.string_test.dart | 2 +- .../supported_types/type_test.uri_test.dart | 2 +- json_serializable/test/test_utils.dart | 5 ++-- json_serializable/tool/test_type_data.dart | 5 ++-- 24 files changed, 78 insertions(+), 56 deletions(-) diff --git a/_test_yaml/test/yaml_test.dart b/_test_yaml/test/yaml_test.dart index b3fdd7963..d696b6c7e 100644 --- a/_test_yaml/test/yaml_test.dart +++ b/_test_yaml/test/yaml_test.dart @@ -160,9 +160,6 @@ line 4, column 21 of file.yaml: Unsupported value for "configLocation". Illegal ╵''' }; -// ignore: deprecated_member_use -final throwsCastError = throwsA(isA()); - T roundTripObject( T object, T Function(Map json) factory, { diff --git a/example/test/json_convert_example_test.dart b/example/test/json_convert_example_test.dart index e3e09bce6..8345874b4 100644 --- a/example/test/json_convert_example_test.dart +++ b/example/test/json_convert_example_test.dart @@ -67,17 +67,20 @@ void main() { final encoded = _encode(collection); expect( - () => GenericCollection.fromJson( - jsonDecode(encoded) as Map), - _throwsCastError); + () => GenericCollection.fromJson( + jsonDecode(encoded) as Map), + _throwsTypeError, + ); expect( - () => GenericCollection.fromJson( - jsonDecode(encoded) as Map), - _throwsCastError); + () => GenericCollection.fromJson( + jsonDecode(encoded) as Map), + _throwsTypeError, + ); expect( - () => GenericCollection.fromJson( - jsonDecode(encoded) as Map), - _throwsCastError); + () => GenericCollection.fromJson( + jsonDecode(encoded) as Map), + _throwsTypeError, + ); final collection2 = GenericCollection.fromJson(jsonDecode(encoded) as Map); @@ -96,8 +99,7 @@ void main() { }); } -// ignore: deprecated_member_use -final _throwsCastError = throwsA(isA()); +final _throwsTypeError = throwsA(isA()); String _encode(Object object) => const JsonEncoder.withIndent(' ').convert(object); diff --git a/json_serializable/test/generic_files/generic_test.dart b/json_serializable/test/generic_files/generic_test.dart index dc83e871b..be2379158 100644 --- a/json_serializable/test/generic_files/generic_test.dart +++ b/json_serializable/test/generic_files/generic_test.dart @@ -42,15 +42,16 @@ void main() { }); test('with bad arguments', () { expect( - () => GenericClass() - ..fieldT = (true as dynamic) as double, - throwsCastError); + () => GenericClass() + ..fieldT = (true as dynamic) as double, + throwsTypeError, + ); }); test('with bad arguments', () { expect( - () => - GenericClass()..fieldS = (5 as dynamic) as String, - throwsCastError); + () => GenericClass()..fieldS = (5 as dynamic) as String, + throwsTypeError, + ); }); }); diff --git a/json_serializable/test/integration/integration_test.dart b/json_serializable/test/integration/integration_test.dart index b8d6ac115..58379af97 100644 --- a/json_serializable/test/integration/integration_test.dart +++ b/json_serializable/test/integration/integration_test.dart @@ -248,7 +248,7 @@ void main() { 'ints': [3.14, 0], }; - expect(() => Numbers.fromJson(value), throwsCastError); + expect(() => Numbers.fromJson(value), throwsTypeError); }); }); diff --git a/json_serializable/test/kitchen_sink/kitchen_sink_test.dart b/json_serializable/test/kitchen_sink/kitchen_sink_test.dart index 40fce7218..3950b66fa 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink_test.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink_test.dart @@ -68,7 +68,7 @@ void _nonNullableTests(KitchenSinkFactory factory) { if (factory.checked) { matcher = checkedMatcher('set'); } else { - matcher = isA(); + matcher = isTypeError; } expect(() => factory.fromJson({}), throwsA(matcher)); }); @@ -122,7 +122,9 @@ void _nullableTests(KitchenSinkFactory factory) { expect( encoded, containsPair( - key, _nonNullableFields.contains(key) ? isNotNull : isNull), + key, + _nonNullableFields.contains(key) ? isNotNull : isNull, + ), ); } } @@ -228,7 +230,7 @@ void _sharedTests(KitchenSinkFactory factory) { }); } -const _nonNullableFields = [ +const _nonNullableFields = { 'dynamicIterable', 'objectIterable', 'intIterable', @@ -251,11 +253,11 @@ const _nonNullableFields = [ 'val', 'simpleObject', 'strictKeysObject' -]; +}; -const _encodedAsMapKeys = ['simpleObject', 'strictKeysObject']; +const _encodedAsMapKeys = {'simpleObject', 'strictKeysObject'}; -const _iterableMapKeys = [ +const _iterableMapKeys = { 'bigIntMap', 'crazyComplex', 'datetime-iterable', @@ -280,4 +282,4 @@ const _iterableMapKeys = [ 'set', 'stringStringMap', generatedLocalVarName, -]; +}; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink_test_shared.dart b/json_serializable/test/kitchen_sink/kitchen_sink_test_shared.dart index bc5456e17..4b1b60bc0 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink_test_shared.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink_test_shared.dart @@ -70,6 +70,27 @@ const invalidValueTypes = { 'validatedPropertyNo42': true }; +const disallowNullKeys = { + 'set', + 'dynamicSet', + 'objectSet', + 'intSet', + 'dateTimeSet', + 'list', + 'dynamicList', + 'objectList', + 'intList', + 'dateTimeList', + 'map', + 'stringStringMap', + 'dynamicIntMap', + 'objectDateTimeMap', + 'crazyComplex', + generatedLocalVarName, + 'simpleObject', + 'strictKeysObject', +}; + Matcher checkedMatcher(String? expectedKey) => isA() .having((e) => e.className, 'className', 'KitchenSink') .having((e) => e.key, 'key', expectedKey); diff --git a/json_serializable/test/kitchen_sink/kitchen_sink_yaml_test.dart b/json_serializable/test/kitchen_sink/kitchen_sink_yaml_test.dart index 965117805..55846778d 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink_yaml_test.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink_yaml_test.dart @@ -28,13 +28,16 @@ void _anyMapTests(KitchenSinkFactory factory) { for (final e in invalidValueTypes.entries) { _testBadValue(e.key, e.value, factory, false); } + for (final e in disallowNullKeys) { + _testBadValue(e, null, factory, false); + } for (final e in _invalidCheckedValues.entries) { _testBadValue(e.key, e.value, factory, true); } }); } -void _testBadValue(String key, Object badValue, KitchenSinkFactory factory, +void _testBadValue(String key, Object? badValue, KitchenSinkFactory factory, bool checkedAssignment) { final matcher = _getMatcher(factory.checked, key, checkedAssignment); @@ -65,8 +68,7 @@ Matcher _getMatcher(bool checked, String? expectedKey, bool checkedAssignment) { innerMatcher = checkedMatcher(expectedKey); } else { innerMatcher = anyOf( - _isACastError, - _isATypeError, + isTypeError, _isAUnrecognizedKeysException( 'Unrecognized keys: [invalid_key]; supported keys: ' '[value, custom_field]', @@ -86,7 +88,7 @@ Matcher _getMatcher(bool checked, String? expectedKey, bool checkedAssignment) { break; case 'intIterable': case 'datetime-iterable': - innerMatcher = _isACastError; + innerMatcher = isTypeError; break; default: throw StateError('Not expected! - $expectedKey'); @@ -97,11 +99,6 @@ Matcher _getMatcher(bool checked, String? expectedKey, bool checkedAssignment) { return throwsA(innerMatcher); } -final _isATypeError = isA(); - -// ignore: deprecated_member_use -final _isACastError = isA(); - Matcher _isAUnrecognizedKeysException(expectedMessage) => isA() .having((e) => e.message, 'message', expectedMessage); diff --git a/json_serializable/test/supported_types/type_test.bigint_test.dart b/json_serializable/test/supported_types/type_test.bigint_test.dart index cdc2c3718..969cadb27 100644 --- a/json_serializable/test/supported_types/type_test.bigint_test.dart +++ b/json_serializable/test/supported_types/type_test.bigint_test.dart @@ -31,7 +31,7 @@ void main() { test('round trip null', () { expect( () => loudEncode(SimpleClass.fromJson({})), - throwsA(isA()), + throwsTypeError, ); }); diff --git a/json_serializable/test/supported_types/type_test.bool_test.dart b/json_serializable/test/supported_types/type_test.bool_test.dart index 3cf24c38f..31e4f7971 100644 --- a/json_serializable/test/supported_types/type_test.bool_test.dart +++ b/json_serializable/test/supported_types/type_test.bool_test.dart @@ -31,7 +31,7 @@ void main() { test('round trip null', () { expect( () => loudEncode(SimpleClass.fromJson({})), - throwsA(isA()), + throwsTypeError, ); }); diff --git a/json_serializable/test/supported_types/type_test.datetime_test.dart b/json_serializable/test/supported_types/type_test.datetime_test.dart index e8dc264dd..742529c2a 100644 --- a/json_serializable/test/supported_types/type_test.datetime_test.dart +++ b/json_serializable/test/supported_types/type_test.datetime_test.dart @@ -31,7 +31,7 @@ void main() { test('round trip null', () { expect( () => loudEncode(SimpleClass.fromJson({})), - throwsA(isA()), + throwsTypeError, ); }); diff --git a/json_serializable/test/supported_types/type_test.double_test.dart b/json_serializable/test/supported_types/type_test.double_test.dart index a8b9c07b4..c718f6c11 100644 --- a/json_serializable/test/supported_types/type_test.double_test.dart +++ b/json_serializable/test/supported_types/type_test.double_test.dart @@ -31,7 +31,7 @@ void main() { test('round trip null', () { expect( () => loudEncode(SimpleClass.fromJson({})), - throwsA(isA()), + throwsTypeError, ); }); diff --git a/json_serializable/test/supported_types/type_test.duration_test.dart b/json_serializable/test/supported_types/type_test.duration_test.dart index 808880f72..ee91fd475 100644 --- a/json_serializable/test/supported_types/type_test.duration_test.dart +++ b/json_serializable/test/supported_types/type_test.duration_test.dart @@ -31,7 +31,7 @@ void main() { test('round trip null', () { expect( () => loudEncode(SimpleClass.fromJson({})), - throwsA(isA()), + throwsTypeError, ); }); diff --git a/json_serializable/test/supported_types/type_test.enumtype_test.dart b/json_serializable/test/supported_types/type_test.enumtype_test.dart index b76d51a0e..5ead9e9f2 100644 --- a/json_serializable/test/supported_types/type_test.enumtype_test.dart +++ b/json_serializable/test/supported_types/type_test.enumtype_test.dart @@ -31,7 +31,7 @@ void main() { test('round trip null', () { expect( () => loudEncode(SimpleClass.fromJson({})), - throwsA(isA()), + throwsArgumentError, ); }); diff --git a/json_serializable/test/supported_types/type_test.int_test.dart b/json_serializable/test/supported_types/type_test.int_test.dart index a40a29a33..8ec0cd571 100644 --- a/json_serializable/test/supported_types/type_test.int_test.dart +++ b/json_serializable/test/supported_types/type_test.int_test.dart @@ -31,7 +31,7 @@ void main() { test('round trip null', () { expect( () => loudEncode(SimpleClass.fromJson({})), - throwsA(isA()), + throwsTypeError, ); }); diff --git a/json_serializable/test/supported_types/type_test.iterable_test.dart b/json_serializable/test/supported_types/type_test.iterable_test.dart index d24795cd4..cad1cbb99 100644 --- a/json_serializable/test/supported_types/type_test.iterable_test.dart +++ b/json_serializable/test/supported_types/type_test.iterable_test.dart @@ -31,7 +31,7 @@ void main() { test('round trip null', () { expect( () => loudEncode(SimpleClass.fromJson({})), - throwsA(isA()), + throwsTypeError, ); }); diff --git a/json_serializable/test/supported_types/type_test.list_test.dart b/json_serializable/test/supported_types/type_test.list_test.dart index f68b17243..ebfe17126 100644 --- a/json_serializable/test/supported_types/type_test.list_test.dart +++ b/json_serializable/test/supported_types/type_test.list_test.dart @@ -31,7 +31,7 @@ void main() { test('round trip null', () { expect( () => loudEncode(SimpleClass.fromJson({})), - throwsA(isA()), + throwsTypeError, ); }); diff --git a/json_serializable/test/supported_types/type_test.map_test.dart b/json_serializable/test/supported_types/type_test.map_test.dart index 3dc129caf..2691408d1 100644 --- a/json_serializable/test/supported_types/type_test.map_test.dart +++ b/json_serializable/test/supported_types/type_test.map_test.dart @@ -31,7 +31,7 @@ void main() { test('round trip null', () { expect( () => loudEncode(SimpleClass.fromJson({})), - throwsA(isA()), + throwsTypeError, ); }); diff --git a/json_serializable/test/supported_types/type_test.num_test.dart b/json_serializable/test/supported_types/type_test.num_test.dart index 97366d238..a72a873a3 100644 --- a/json_serializable/test/supported_types/type_test.num_test.dart +++ b/json_serializable/test/supported_types/type_test.num_test.dart @@ -31,7 +31,7 @@ void main() { test('round trip null', () { expect( () => loudEncode(SimpleClass.fromJson({})), - throwsA(isA()), + throwsTypeError, ); }); diff --git a/json_serializable/test/supported_types/type_test.object_test.dart b/json_serializable/test/supported_types/type_test.object_test.dart index cec28c617..ef38a0446 100644 --- a/json_serializable/test/supported_types/type_test.object_test.dart +++ b/json_serializable/test/supported_types/type_test.object_test.dart @@ -31,7 +31,7 @@ void main() { test('round trip null', () { expect( () => loudEncode(SimpleClass.fromJson({})), - throwsA(isA()), + throwsTypeError, ); }); diff --git a/json_serializable/test/supported_types/type_test.set_test.dart b/json_serializable/test/supported_types/type_test.set_test.dart index 1e8c63169..99fff3b6b 100644 --- a/json_serializable/test/supported_types/type_test.set_test.dart +++ b/json_serializable/test/supported_types/type_test.set_test.dart @@ -31,7 +31,7 @@ void main() { test('round trip null', () { expect( () => loudEncode(SimpleClass.fromJson({})), - throwsA(isA()), + throwsTypeError, ); }); diff --git a/json_serializable/test/supported_types/type_test.string_test.dart b/json_serializable/test/supported_types/type_test.string_test.dart index cc12969c8..41af3050c 100644 --- a/json_serializable/test/supported_types/type_test.string_test.dart +++ b/json_serializable/test/supported_types/type_test.string_test.dart @@ -31,7 +31,7 @@ void main() { test('round trip null', () { expect( () => loudEncode(SimpleClass.fromJson({})), - throwsA(isA()), + throwsTypeError, ); }); diff --git a/json_serializable/test/supported_types/type_test.uri_test.dart b/json_serializable/test/supported_types/type_test.uri_test.dart index fff3fc43e..b32b892cc 100644 --- a/json_serializable/test/supported_types/type_test.uri_test.dart +++ b/json_serializable/test/supported_types/type_test.uri_test.dart @@ -31,7 +31,7 @@ void main() { test('round trip null', () { expect( () => loudEncode(SimpleClass.fromJson({})), - throwsA(isA()), + throwsTypeError, ); }); diff --git a/json_serializable/test/test_utils.dart b/json_serializable/test/test_utils.dart index 84bcdf4e7..324cdb27a 100644 --- a/json_serializable/test/test_utils.dart +++ b/json_serializable/test/test_utils.dart @@ -9,8 +9,9 @@ import 'dart:convert'; import 'package:stack_trace/stack_trace.dart'; import 'package:test/test.dart'; -// ignore: deprecated_member_use -final throwsCastError = throwsA(isA()); +final throwsTypeError = throwsA(isTypeError); + +final isTypeError = isA(); T roundTripObject(T object, T Function(Map json) factory) { final data = loudEncode(object); diff --git a/json_serializable/tool/test_type_data.dart b/json_serializable/tool/test_type_data.dart index 6417b64c3..fbe201ced 100644 --- a/json_serializable/tool/test_type_data.dart +++ b/json_serializable/tool/test_type_data.dart @@ -139,7 +139,8 @@ class TestTypeData { .replaceAll('non-nullable', 'nullable') .replaceAll('SimpleClass', 'SimpleClassNullable'); - final thrownError = type == customEnumType ? 'ArgumentError' : 'TypeError'; + final thrownError = + type == customEnumType ? 'throwsArgumentError' : 'throwsTypeError'; final newGroupContent = groupContent.replaceAll( r''' @@ -154,7 +155,7 @@ class TestTypeData { ''' expect( () => loudEncode(SimpleClass.fromJson({})), - throwsA(isA<$thrownError>()), + $thrownError, );''', ); From 999c65186ed164f13ca28b874111c7148c2cd262 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 2 Mar 2021 08:20:46 -0800 Subject: [PATCH 275/569] checked_yaml: improve handling of missing keys (#818) If a CheckedFromJsonException exception is caught for a key that is missing in the source map, include that information in the message Also correctly handle the case where CheckedFromJsonException.message is `null` Fixes https://github.com/google/json_serializable.dart/issues/816 --- checked_yaml/CHANGELOG.md | 7 ++++ checked_yaml/README.md | 1 - checked_yaml/example/example.dart | 1 - checked_yaml/example/example.g.dart | 3 +- checked_yaml/lib/checked_yaml.dart | 18 ++++++---- checked_yaml/pubspec.yaml | 4 +-- checked_yaml/test/custom_error_test.dart | 42 ++++++++++++++++++++++++ checked_yaml/test/example_test.dart | 31 +++++++++++++---- checked_yaml/test/readme_test.dart | 10 +++--- 9 files changed, 95 insertions(+), 22 deletions(-) create mode 100644 checked_yaml/test/custom_error_test.dart diff --git a/checked_yaml/CHANGELOG.md b/checked_yaml/CHANGELOG.md index 5fd16cb22..44627a640 100644 --- a/checked_yaml/CHANGELOG.md +++ b/checked_yaml/CHANGELOG.md @@ -1,3 +1,10 @@ +## 2.0.1 + +- If `CheckedFromJsonException` is caught for a key missing in the source map, + include those details in the thrown `ParsedYamlException`. + +- Correctly handle the case where `CheckedFromJsonException.message` is `null`. + ## 2.0.0 - *BREAKING* `checkedYamlDecode` `sourceUrl` parameter is now a `Uri`. diff --git a/checked_yaml/README.md b/checked_yaml/README.md index 16b132ef0..1a56f1e23 100644 --- a/checked_yaml/README.md +++ b/checked_yaml/README.md @@ -18,7 +18,6 @@ for the class annotation. class Configuration { @JsonKey(required: true) final String name; - @JsonKey(required: true) final int count; Configuration({required this.name, required this.count}) { diff --git a/checked_yaml/example/example.dart b/checked_yaml/example/example.dart index 4cefa2439..f89308843 100644 --- a/checked_yaml/example/example.dart +++ b/checked_yaml/example/example.dart @@ -17,7 +17,6 @@ part 'example.g.dart'; class Configuration { @JsonKey(required: true) final String name; - @JsonKey(required: true) final int count; Configuration({required this.name, required this.count}) { diff --git a/checked_yaml/example/example.g.dart b/checked_yaml/example/example.g.dart index 854bcbaf5..0a3b3de52 100644 --- a/checked_yaml/example/example.g.dart +++ b/checked_yaml/example/example.g.dart @@ -9,8 +9,7 @@ part of 'example.dart'; Configuration _$ConfigurationFromJson(Map json) { return $checkedNew('Configuration', json, () { $checkKeys(json, - allowedKeys: const ['name', 'count'], - requiredKeys: const ['name', 'count']); + allowedKeys: const ['name', 'count'], requiredKeys: const ['name']); final val = Configuration( name: $checkedConvert(json, 'name', (v) => v as String), count: $checkedConvert(json, 'count', (v) => v as int), diff --git a/checked_yaml/lib/checked_yaml.dart b/checked_yaml/lib/checked_yaml.dart index 3302b34a6..154c59b02 100644 --- a/checked_yaml/lib/checked_yaml.dart +++ b/checked_yaml/lib/checked_yaml.dart @@ -75,12 +75,18 @@ ParsedYamlException toParsedYamlException( innerError: exception, ); } else { - final yamlValue = yamlMap.nodes[exception.key]; - - if (yamlValue == null) { - // TODO: test this case! + if (exception.key == null) { + return ParsedYamlException( + exception.message ?? 'There was an error parsing the map.', + yamlMap, + innerError: exception, + ); + } else if (!yamlMap.containsKey(exception.key)) { return ParsedYamlException( - exception.message!, + [ + 'Missing key "${exception.key}".', + if (exception.message != null) exception.message!, + ].join(' '), yamlMap, innerError: exception, ); @@ -91,7 +97,7 @@ ParsedYamlException toParsedYamlException( } return ParsedYamlException( message, - yamlValue, + yamlMap.nodes[exception.key] ?? yamlMap, innerError: exception, ); } diff --git a/checked_yaml/pubspec.yaml b/checked_yaml/pubspec.yaml index dfd0972e8..524b160c4 100644 --- a/checked_yaml/pubspec.yaml +++ b/checked_yaml/pubspec.yaml @@ -1,5 +1,5 @@ name: checked_yaml -version: 2.0.0 +version: 2.0.1 description: >- Generate more helpful exceptions when decoding YAML documents using @@ -19,7 +19,7 @@ dev_dependencies: json_serializable: ^4.0.0 path: ^1.0.0 test: ^1.16.0 - test_process: ^1.0.1 + test_process: ^2.0.0 dependency_overrides: # Need to update dependencies on these packages diff --git a/checked_yaml/test/custom_error_test.dart b/checked_yaml/test/custom_error_test.dart new file mode 100644 index 000000000..6ce0e42e1 --- /dev/null +++ b/checked_yaml/test/custom_error_test.dart @@ -0,0 +1,42 @@ +import 'package:checked_yaml/checked_yaml.dart'; +import 'package:json_annotation/json_annotation.dart'; +import 'package:test/test.dart'; +import 'package:yaml/yaml.dart'; + +void main() { + test('bob', () { + expect( + () => checkedYamlDecode( + '{"innerMap": {}}', + (m) { + throw CheckedFromJsonException( + m!['innerMap'] as YamlMap, + null, + 'nothing', + null, + ); + }, + ), + throwsA( + isA() + .having( + (e) => e.message, + 'message', + 'There was an error parsing the map.', + ) + .having((e) => e.yamlNode, 'yamlNode', isA()) + .having( + (e) => e.innerError, + 'innerError', + isA(), + ) + .having((e) => e.formattedMessage, 'formattedMessage', ''' +line 1, column 14: There was an error parsing the map. + ╷ +1 │ {"innerMap": {}} + │ ^^ + ╵'''), + ), + ); + }); +} diff --git a/checked_yaml/test/example_test.dart b/checked_yaml/test/example_test.dart index be5014926..a5d55786d 100644 --- a/checked_yaml/test/example_test.dart +++ b/checked_yaml/test/example_test.dart @@ -21,7 +21,7 @@ Configuration: {name: bob, count: 42} _expectThrows( '{}', r''' -line 1, column 1: Required keys are missing: name, count. +line 1, column 1: Required keys are missing: name. ╷ 1 │ {} │ ^^ @@ -29,6 +29,18 @@ line 1, column 1: Required keys are missing: name, count. ); }); + test('missing count', () { + _expectThrows( + '{"name":"something"}', + r''' +line 1, column 1: Missing key "count". type 'Null' is not a subtype of type 'int' in type cast + ╷ +1 │ {"name":"something"} + │ ^^^^^^^^^^^^^^^^^^^^ + ╵''', + ); + }); + test('not a map', () { _expectThrows( '42', @@ -103,10 +115,17 @@ line 1, column 10: Unsupported value for "name". Cannot be empty. } void _expectThrows(String yamlContent, matcher) => expect( - () => _run(yamlContent), - throwsA(isA().having((e) { - printOnFailure("r'''\n${e.formattedMessage}'''"); - return e.formattedMessage; - }, 'formattedMessage', matcher))); + () => _run(yamlContent), + throwsA( + isA().having( + (e) { + printOnFailure("r'''\n${e.formattedMessage}'''"); + return e.formattedMessage; + }, + 'formattedMessage', + matcher, + ), + ), + ); void _run(String yamlContent) => example.main([yamlContent]); diff --git a/checked_yaml/test/readme_test.dart b/checked_yaml/test/readme_test.dart index 573db78f6..21f530d06 100644 --- a/checked_yaml/test/readme_test.dart +++ b/checked_yaml/test/readme_test.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.9 - import 'dart:convert'; import 'dart:io'; @@ -61,9 +59,13 @@ $errorContent ```''')); final proc = await TestProcess.start( - Platform.resolvedExecutable, [_examplePath, inputContent]); + Platform.resolvedExecutable, + [_examplePath, inputContent], + ); await expectLater( - proc.stderr, emitsInOrder(LineSplitter.split(errorContent))); + proc.stderr, + emitsInOrder(LineSplitter.split(errorContent)), + ); await proc.shouldExit(isNot(0)); }); From 3b6afe92f54a86c08c4663cc57fe1ea2a998e0eb Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 2 Mar 2021 14:45:06 -0800 Subject: [PATCH 276/569] json_annotation: Fix a potential error with `checked: true`... (#819) ...when `ArgumentError.message` is `null` --- json_annotation/CHANGELOG.md | 5 +++++ json_annotation/lib/src/checked_helpers.dart | 9 ++++++--- json_annotation/pubspec.yaml | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index 9beb4d0d6..99086f891 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -1,3 +1,8 @@ +## 4.0.1-dev + +- Fix a potential error with `checked: true` when `ArgumentError.message` is + `null`. + ## 4.0.0 - Support null safety. diff --git a/json_annotation/lib/src/checked_helpers.dart b/json_annotation/lib/src/checked_helpers.dart index c844c80d7..4d5e7e4aa 100644 --- a/json_annotation/lib/src/checked_helpers.dart +++ b/json_annotation/lib/src/checked_helpers.dart @@ -104,7 +104,7 @@ class CheckedFromJsonException implements Exception { innerStack = null; CheckedFromJsonException._( - this.innerError, + Object this.innerError, this.innerStack, this.map, this.key, { @@ -113,9 +113,12 @@ class CheckedFromJsonException implements Exception { badKey = innerError is BadKeyException, message = _getMessage(innerError); - static String? _getMessage(Object? error) { + static String _getMessage(Object error) { if (error is ArgumentError) { - return error.message?.toString(); + final message = error.message; + if (message != null) { + return message.toString(); + } } if (error is BadKeyException) { return error.message; diff --git a/json_annotation/pubspec.yaml b/json_annotation/pubspec.yaml index a273d6b76..a0a0f7f0a 100644 --- a/json_annotation/pubspec.yaml +++ b/json_annotation/pubspec.yaml @@ -1,5 +1,5 @@ name: json_annotation -version: 4.0.0 +version: 4.0.1-dev description: >- Classes and helper functions that support JSON code generation via the `json_serializable` package. From 3bf4564c063014f127db370a7b1d17a958a67fe1 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 4 Mar 2021 16:59:04 -0800 Subject: [PATCH 277/569] Latest mono_repo, Update SDK constraints, added a few more lints (#820) --- .github/workflows/dart.yml | 62 ++++++++++++++++----------------- _test_yaml/mono_pkg.yaml | 2 +- _test_yaml/pubspec.yaml | 2 +- analysis_options.yaml | 5 +++ checked_yaml/mono_pkg.yaml | 2 +- checked_yaml/pubspec.yaml | 2 +- example/mono_pkg.yaml | 2 +- example/pubspec.yaml | 3 +- json_annotation/mono_pkg.yaml | 2 +- json_annotation/pubspec.yaml | 2 +- json_serializable/mono_pkg.yaml | 2 +- tool/ci.sh | 2 +- 12 files changed, 47 insertions(+), 41 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 1176b3094..53243ab98 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -1,4 +1,4 @@ -# Created with package:mono_repo v3.4.6 +# Created with package:mono_repo v3.4.7 name: Dart CI on: push: @@ -27,32 +27,32 @@ jobs: restore-keys: | os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: dart-lang/setup-dart@v0.3 + - uses: dart-lang/setup-dart@v1.0 with: sdk: stable - id: checkout uses: actions/checkout@v2 - name: mono_repo self validate - run: pub global activate mono_repo 3.4.6 + run: pub global activate mono_repo 3.4.7 - name: mono_repo self validate run: pub global run mono_repo generate --validate job_002: - name: "analyzer_and_format; Dart beta; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; `dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-infos .`" + name: "analyzer_and_format; Dart 2.12.0; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; `dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-infos .`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@v2 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;dart:beta;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:dartfmt-dartanalyzer" + key: "os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:dartfmt-dartanalyzer" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;dart:beta;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable - os:ubuntu-latest;pub-cache-hosted;dart:beta + os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable + os:ubuntu-latest;pub-cache-hosted;dart:2.12.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: dart-lang/setup-dart@v0.3 + - uses: dart-lang/setup-dart@v1.0 with: - sdk: beta + sdk: "2.12.0" - id: checkout uses: actions/checkout@v2 - id: _test_yaml_pub_upgrade @@ -134,7 +134,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted;dart:dev os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: dart-lang/setup-dart@v0.3 + - uses: dart-lang/setup-dart@v1.0 with: sdk: dev - id: checkout @@ -205,22 +205,22 @@ jobs: working-directory: json_serializable run: dartanalyzer --fatal-infos . job_004: - name: "unit_test; Dart beta; PKGS: _test_yaml, checked_yaml, example, json_serializable; `pub run test`" + name: "unit_test; Dart 2.12.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; `pub run test`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@v2 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;dart:beta;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" + key: "os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;dart:beta;packages:_test_yaml-checked_yaml-example-json_serializable - os:ubuntu-latest;pub-cache-hosted;dart:beta + os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:_test_yaml-checked_yaml-example-json_serializable + os:ubuntu-latest;pub-cache-hosted;dart:2.12.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: dart-lang/setup-dart@v0.3 + - uses: dart-lang/setup-dart@v1.0 with: - sdk: beta + sdk: "2.12.0" - id: checkout uses: actions/checkout@v2 - id: _test_yaml_pub_upgrade @@ -277,7 +277,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted;dart:dev os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: dart-lang/setup-dart@v0.3 + - uses: dart-lang/setup-dart@v1.0 with: sdk: dev - id: checkout @@ -323,22 +323,22 @@ jobs: - job_002 - job_003 job_006: - name: "unit_test; Dart beta; PKG: json_serializable; `pub run test -p chrome`" + name: "unit_test; Dart 2.12.0; PKG: json_serializable; `pub run test -p chrome`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@v2 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;dart:beta;packages:json_serializable;commands:test_2" + key: "os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:json_serializable;commands:test_2" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;dart:beta;packages:json_serializable - os:ubuntu-latest;pub-cache-hosted;dart:beta + os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:json_serializable + os:ubuntu-latest;pub-cache-hosted;dart:2.12.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: dart-lang/setup-dart@v0.3 + - uses: dart-lang/setup-dart@v1.0 with: - sdk: beta + sdk: "2.12.0" - id: checkout uses: actions/checkout@v2 - id: json_serializable_pub_upgrade @@ -368,7 +368,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted;dart:dev os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: dart-lang/setup-dart@v0.3 + - uses: dart-lang/setup-dart@v1.0 with: sdk: dev - id: checkout @@ -387,22 +387,22 @@ jobs: - job_002 - job_003 job_008: - name: "ensure_build; Dart beta; PKGS: _test_yaml, checked_yaml, example, json_serializable; `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`" + name: "ensure_build; Dart 2.12.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@v2 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;dart:beta;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_1" + key: "os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_1" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;dart:beta;packages:_test_yaml-checked_yaml-example-json_serializable - os:ubuntu-latest;pub-cache-hosted;dart:beta + os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:_test_yaml-checked_yaml-example-json_serializable + os:ubuntu-latest;pub-cache-hosted;dart:2.12.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: dart-lang/setup-dart@v0.3 + - uses: dart-lang/setup-dart@v1.0 with: - sdk: beta + sdk: "2.12.0" - id: checkout uses: actions/checkout@v2 - id: _test_yaml_pub_upgrade @@ -463,7 +463,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted;dart:dev os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: dart-lang/setup-dart@v0.3 + - uses: dart-lang/setup-dart@v1.0 with: sdk: dev - id: checkout diff --git a/_test_yaml/mono_pkg.yaml b/_test_yaml/mono_pkg.yaml index e99b82ec6..50ddd7215 100644 --- a/_test_yaml/mono_pkg.yaml +++ b/_test_yaml/mono_pkg.yaml @@ -1,6 +1,6 @@ # See https://github.com/google/mono_repo.dart for details on this file dart: -- beta # change this to 1.12.0 when it's released! +- 2.12.0 - dev stages: diff --git a/_test_yaml/pubspec.yaml b/_test_yaml/pubspec.yaml index 1343b2698..b04db50c6 100644 --- a/_test_yaml/pubspec.yaml +++ b/_test_yaml/pubspec.yaml @@ -2,7 +2,7 @@ name: _test_yaml publish_to: none environment: - sdk: '>=2.12.0-0 <3.0.0' + sdk: '>=2.12.0 <3.0.0' dev_dependencies: build_runner: ^1.0.0 diff --git a/analysis_options.yaml b/analysis_options.yaml index 6b1f8d775..cd40b8743 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -21,6 +21,7 @@ linter: - avoid_returning_null - avoid_returning_null_for_void - avoid_shadowing_type_parameters + - avoid_single_cascade_in_expression_statements - avoid_types_as_parameter_names - avoid_unused_constructor_parameters - avoid_void_async @@ -88,6 +89,7 @@ linter: - provide_deprecation_message - recursive_getters - slash_for_doc_comments + - sort_child_properties_last - sort_pub_dependencies - test_types_in_equals - throw_in_finally @@ -106,7 +108,10 @@ linter: - unnecessary_string_interpolations - unnecessary_this - unrelated_type_equality_checks + - unsafe_html + - use_full_hex_values_for_flutter_colors - use_function_type_syntax_for_parameters + - use_is_even_rather_than_modulo - use_rethrow_when_possible - use_string_buffers - valid_regexps diff --git a/checked_yaml/mono_pkg.yaml b/checked_yaml/mono_pkg.yaml index cf36065b9..9b068d820 100644 --- a/checked_yaml/mono_pkg.yaml +++ b/checked_yaml/mono_pkg.yaml @@ -1,6 +1,6 @@ # See https://github.com/google/mono_repo.dart for details on this file dart: -- beta # change this to 1.12.0 when it's released! +- 2.12.0 - dev stages: diff --git a/checked_yaml/pubspec.yaml b/checked_yaml/pubspec.yaml index 524b160c4..97b5c1729 100644 --- a/checked_yaml/pubspec.yaml +++ b/checked_yaml/pubspec.yaml @@ -6,7 +6,7 @@ description: >- package:json_serializable and package:yaml. repository: https://github.com/google/json_serializable.dart/tree/master/checked_yaml environment: - sdk: '>=2.12.0-0 <3.0.0' + sdk: '>=2.12.0 <3.0.0' dependencies: json_annotation: ^4.0.0 diff --git a/example/mono_pkg.yaml b/example/mono_pkg.yaml index cf6269f0f..d3815a8d7 100644 --- a/example/mono_pkg.yaml +++ b/example/mono_pkg.yaml @@ -1,6 +1,6 @@ # See https://github.com/google/mono_repo.dart for details on this file dart: -- beta # change this to 1.12.0 when it's released! +- 2.12.0 - dev stages: diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 3bd996e31..ff81bb52c 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -1,7 +1,8 @@ name: example +publish_to: none environment: - sdk: '>=2.12.0-0 <3.0.0' + sdk: '>=2.12.0 <3.0.0' dependencies: json_annotation: ^4.0.0 diff --git a/json_annotation/mono_pkg.yaml b/json_annotation/mono_pkg.yaml index a1250b87f..987f46558 100644 --- a/json_annotation/mono_pkg.yaml +++ b/json_annotation/mono_pkg.yaml @@ -1,6 +1,6 @@ # See https://github.com/google/mono_repo.dart for details on this file dart: -- beta # change this to 1.12.0 when it's released! +- 2.12.0 - dev stages: diff --git a/json_annotation/pubspec.yaml b/json_annotation/pubspec.yaml index a0a0f7f0a..7879496a9 100644 --- a/json_annotation/pubspec.yaml +++ b/json_annotation/pubspec.yaml @@ -5,7 +5,7 @@ description: >- `json_serializable` package. repository: https://github.com/google/json_serializable.dart environment: - sdk: '>=2.12.0-0 <3.0.0' + sdk: '>=2.12.0 <3.0.0' # When changing JsonSerializable class. # dev_dependencies: diff --git a/json_serializable/mono_pkg.yaml b/json_serializable/mono_pkg.yaml index a483c5d6e..d15580f01 100644 --- a/json_serializable/mono_pkg.yaml +++ b/json_serializable/mono_pkg.yaml @@ -1,6 +1,6 @@ # See https://github.com/google/mono_repo.dart for details on this file dart: -- beta # change this to 1.12.0 when it's released! +- 2.12.0 - dev stages: diff --git a/tool/ci.sh b/tool/ci.sh index 04aa24cfe..e82813c21 100755 --- a/tool/ci.sh +++ b/tool/ci.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Created with package:mono_repo v3.4.6 +# Created with package:mono_repo v3.4.7 # Support built in commands on windows out of the box. function pub() { From ae33c4312c6381a42d7dd9c0fed11271357c96c0 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 8 Mar 2021 09:07:02 -0800 Subject: [PATCH 278/569] Handle nullable values with `genericArgumentFactories` (#826) Fixes https://github.com/google/json_serializable.dart/issues/803 --- json_serializable/CHANGELOG.md | 4 ++ json_serializable/lib/src/encoder_helper.dart | 2 +- json_serializable/pubspec.yaml | 3 +- .../generic_argument_factories.dart | 9 ++-- .../generic_argument_factories.g.dart | 12 ++++- .../test/generic_files/generic_test.dart | 50 +++++++++++++++++++ 6 files changed, 73 insertions(+), 7 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 0f1cd2fb6..ae9fe3cbe 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,7 @@ +## 4.0.3-dev + +- Correctly handle nullable values with `genericArgumentFactories`. + ## 4.0.2 - Correctly handle nullable `Map` and `Iterable` JSON types exposed by both diff --git a/json_serializable/lib/src/encoder_helper.dart b/json_serializable/lib/src/encoder_helper.dart index f270c2da6..6ea548781 100644 --- a/json_serializable/lib/src/encoder_helper.dart +++ b/json_serializable/lib/src/encoder_helper.dart @@ -30,7 +30,7 @@ abstract class EncodeHelper implements HelperCore { final helperName = toJsonForType( arg.instantiate(nullabilitySuffix: NullabilitySuffix.none), ); - buffer.write(',Object Function(${arg.name} value) $helperName'); + buffer.write(',Object? Function(${arg.name} value) $helperName'); } if (element.typeParameters.isNotEmpty) { buffer.write(','); diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index a59c05b1c..7cca024a1 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,11 +1,12 @@ name: json_serializable -version: 4.0.2 +version: 4.0.3-dev description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. repository: https://github.com/google/json_serializable.dart/tree/master/json_serializable environment: # Keeping this <2.12.0 because the code is not null safe – yet! + # https://github.com/google/json_serializable.dart/issues/821 sdk: '>=2.11.99 <3.0.0' dependencies: diff --git a/json_serializable/test/generic_files/generic_argument_factories.dart b/json_serializable/test/generic_files/generic_argument_factories.dart index cae60d363..c45ebf081 100644 --- a/json_serializable/test/generic_files/generic_argument_factories.dart +++ b/json_serializable/test/generic_files/generic_argument_factories.dart @@ -30,8 +30,8 @@ class GenericClassWithHelpers { _$GenericClassWithHelpersFromJson(json, fromJsonT, fromJsonS); Map toJson( - Object Function(T value) toJsonT, - Object Function(S value) toJsonS, + Object? Function(T value) toJsonT, + Object? Function(S value) toJsonS, ) => _$GenericClassWithHelpersToJson(this, toJsonT, toJsonS); } @@ -42,7 +42,10 @@ class ConcreteClass { final GenericClassWithHelpers value2; - ConcreteClass(this.value, this.value2); + // Regression scenario for google/json_serializable.dart#803 + final GenericClassWithHelpers value3; + + ConcreteClass(this.value, this.value2, this.value3); factory ConcreteClass.fromJson(Map json) => _$ConcreteClassFromJson(json); diff --git a/json_serializable/test/generic_files/generic_argument_factories.g.dart b/json_serializable/test/generic_files/generic_argument_factories.g.dart index a41ccc411..49ba5d532 100644 --- a/json_serializable/test/generic_files/generic_argument_factories.g.dart +++ b/json_serializable/test/generic_files/generic_argument_factories.g.dart @@ -21,8 +21,8 @@ GenericClassWithHelpers _$GenericClassWithHelpersFromJson( Map _$GenericClassWithHelpersToJson( GenericClassWithHelpers instance, - Object Function(T value) toJsonT, - Object Function(S value) toJsonS, + Object? Function(T value) toJsonT, + Object? Function(S value) toJsonS, ) => { 'value': toJsonT(instance.value), @@ -38,6 +38,10 @@ ConcreteClass _$ConcreteClassFromJson(Map json) { json['value2'] as Map, (value) => (value as num).toDouble(), (value) => BigInt.parse(value as String)), + GenericClassWithHelpers.fromJson( + json['value3'] as Map, + (value) => (value as num?)?.toDouble(), + (value) => value == null ? null : BigInt.parse(value as String)), ); } @@ -51,4 +55,8 @@ Map _$ConcreteClassToJson(ConcreteClass instance) => (value) => value, (value) => value.toString(), ), + 'value3': instance.value3.toJson( + (value) => value, + (value) => value?.toString(), + ), }; diff --git a/json_serializable/test/generic_files/generic_test.dart b/json_serializable/test/generic_files/generic_test.dart index be2379158..b9e62c090 100644 --- a/json_serializable/test/generic_files/generic_test.dart +++ b/json_serializable/test/generic_files/generic_test.dart @@ -108,6 +108,56 @@ void main() { "someSet": [ "2" ] + }, + "value3": { + "value": 3.14, + "list": [ + 3.14 + ], + "someSet": [ + "2" + ] + } +}'''; + + final instance = ConcreteClass.fromJson( + jsonDecode(inputJson) as Map, + ); + + expect(loudEncode(instance), inputJson); + }); + + test('round trip decode/decode with null', () { + const inputJson = r''' +{ + "value": { + "value": 5, + "list": [ + 5 + ], + "someSet": [ + "string" + ] + }, + "value2": { + "value": 3.14, + "list": [ + 3.14 + ], + "someSet": [ + "2" + ] + }, + "value3": { + "value": null, + "list": [ + 3.14, + null + ], + "someSet": [ + "2", + null + ] } }'''; From 4d9d0e3e1fd8a08e6ddd4acc848824d8e316cde3 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 15 Mar 2021 15:20:12 -0700 Subject: [PATCH 279/569] Support the latest pkg:build, prepare to release (#833) --- json_serializable/CHANGELOG.md | 3 ++- json_serializable/pubspec.yaml | 4 ++-- json_serializable/tool/doc_builder.dart | 9 +++++++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index ae9fe3cbe..0a4595685 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,6 +1,7 @@ -## 4.0.3-dev +## 4.0.3 - Correctly handle nullable values with `genericArgumentFactories`. +- Require the latest `package:build`. ## 4.0.2 diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 7cca024a1..42ef700e1 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 4.0.3-dev +version: 4.0.3 description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. @@ -11,7 +11,7 @@ environment: dependencies: analyzer: '>=0.41.2 <2.0.0' - build: ^1.6.1 + build: ^2.0.0 build_config: ^0.4.4 # Use a tight version constraint to ensure that a constraint on diff --git a/json_serializable/tool/doc_builder.dart b/json_serializable/tool/doc_builder.dart index 1aa0be2c9..0dd737305 100644 --- a/json_serializable/tool/doc_builder.dart +++ b/json_serializable/tool/doc_builder.dart @@ -33,8 +33,13 @@ class _DocBuilder extends Builder { ? 'latest' : jsonAnnotationVersion.toString(); - final lib = LibraryReader(await buildStep.resolver.libraryFor( - AssetId.resolve('package:json_annotation/json_annotation.dart'))); + final lib = LibraryReader( + await buildStep.resolver.libraryFor( + AssetId.resolve( + Uri.parse('package:json_annotation/json_annotation.dart'), + ), + ), + ); final descriptionMap = {}; From 07d40b0e8546f9c8a597cac5de8d63efd14f0793 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 15 Mar 2021 15:23:20 -0700 Subject: [PATCH 280/569] checked_yaml: remove dependency_overrides Now we have the latest everything! --- checked_yaml/CHANGELOG.md | 2 ++ checked_yaml/pubspec.yaml | 7 +------ 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/checked_yaml/CHANGELOG.md b/checked_yaml/CHANGELOG.md index 44627a640..9dd60ee08 100644 --- a/checked_yaml/CHANGELOG.md +++ b/checked_yaml/CHANGELOG.md @@ -1,3 +1,5 @@ +## 2.0.2-dev + ## 2.0.1 - If `CheckedFromJsonException` is caught for a key missing in the source map, diff --git a/checked_yaml/pubspec.yaml b/checked_yaml/pubspec.yaml index 97b5c1729..78945b35b 100644 --- a/checked_yaml/pubspec.yaml +++ b/checked_yaml/pubspec.yaml @@ -1,5 +1,5 @@ name: checked_yaml -version: 2.0.1 +version: 2.0.2-dev description: >- Generate more helpful exceptions when decoding YAML documents using @@ -20,8 +20,3 @@ dev_dependencies: path: ^1.0.0 test: ^1.16.0 test_process: ^2.0.0 - -dependency_overrides: - # Need to update dependencies on these packages - build_config: ^0.4.4 - pubspec_parse: ^0.1.5 From c48ebb3357889da2dcd23d3b380d9c9968516326 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 15 Mar 2021 16:13:36 -0700 Subject: [PATCH 281/569] Update example build --- example/lib/tuple_example.g.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/example/lib/tuple_example.g.dart b/example/lib/tuple_example.g.dart index 3032bdfcf..c881fecfc 100644 --- a/example/lib/tuple_example.g.dart +++ b/example/lib/tuple_example.g.dart @@ -19,8 +19,8 @@ Tuple _$TupleFromJson( Map _$TupleToJson( Tuple instance, - Object Function(T value) toJsonT, - Object Function(S value) toJsonS, + Object? Function(T value) toJsonT, + Object? Function(S value) toJsonS, ) => { 'value1': toJsonT(instance.value1), From d33363e7e0e5c10581bdec6dfe71581ba218ffc4 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 16 Mar 2021 10:21:23 -0700 Subject: [PATCH 282/569] Update to latest pkg:build_verify (#836) --- _test_yaml/pubspec.yaml | 2 +- _test_yaml/test/ensure_build_test.dart | 2 -- checked_yaml/pubspec.yaml | 2 +- checked_yaml/test/ensure_build_test.dart | 2 -- example/pubspec.yaml | 2 +- example/test/ensure_build_test.dart | 2 -- json_serializable/pubspec.yaml | 2 +- 7 files changed, 4 insertions(+), 10 deletions(-) diff --git a/_test_yaml/pubspec.yaml b/_test_yaml/pubspec.yaml index b04db50c6..9c536bae2 100644 --- a/_test_yaml/pubspec.yaml +++ b/_test_yaml/pubspec.yaml @@ -6,7 +6,7 @@ environment: dev_dependencies: build_runner: ^1.0.0 - build_verify: ^1.1.0 + build_verify: ^2.0.0 checked_yaml: any json_annotation: any json_serializable: any diff --git a/_test_yaml/test/ensure_build_test.dart b/_test_yaml/test/ensure_build_test.dart index 85f180ff7..acd110e44 100644 --- a/_test_yaml/test/ensure_build_test.dart +++ b/_test_yaml/test/ensure_build_test.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.9 - @TestOn('vm') @Tags(['presubmit-only']) import 'package:build_verify/build_verify.dart'; diff --git a/checked_yaml/pubspec.yaml b/checked_yaml/pubspec.yaml index 78945b35b..552df380d 100644 --- a/checked_yaml/pubspec.yaml +++ b/checked_yaml/pubspec.yaml @@ -15,7 +15,7 @@ dependencies: dev_dependencies: build_runner: ^1.0.0 - build_verify: ^1.1.0 + build_verify: ^2.0.0 json_serializable: ^4.0.0 path: ^1.0.0 test: ^1.16.0 diff --git a/checked_yaml/test/ensure_build_test.dart b/checked_yaml/test/ensure_build_test.dart index e83e0b3b9..bcb52649d 100644 --- a/checked_yaml/test/ensure_build_test.dart +++ b/checked_yaml/test/ensure_build_test.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.9 - @TestOn('vm') @Tags(['presubmit-only']) import 'package:build_verify/build_verify.dart'; diff --git a/example/pubspec.yaml b/example/pubspec.yaml index ff81bb52c..dccf0ab09 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -11,7 +11,7 @@ dev_dependencies: build_runner: ^1.0.0 # Used by tests. Not required to use `json_serializable`. - build_verify: ^1.0.0 + build_verify: ^2.0.0 json_serializable: ^4.0.0 diff --git a/example/test/ensure_build_test.dart b/example/test/ensure_build_test.dart index 9a62c4a83..a927b47a9 100644 --- a/example/test/ensure_build_test.dart +++ b/example/test/ensure_build_test.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.9 - @Tags(['presubmit-only']) import 'package:build_verify/build_verify.dart'; import 'package:test/test.dart'; diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 42ef700e1..c00ac598b 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -25,7 +25,7 @@ dependencies: dev_dependencies: build_runner: ^1.0.0 - build_verify: ^1.1.0 + build_verify: ^2.0.0 collection: ^1.14.0 dart_style: ^1.2.0 logging: ^1.0.0 From 2c6d71786b5e7cf4c5dd1247ac0628289c3754a5 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Fri, 19 Mar 2021 08:34:44 -0700 Subject: [PATCH 283/569] Migrate implementation of json_serializable to null-safety (#841) Fixes https://github.com/google/json_serializable.dart/issues/821 --- json_annotation/CHANGELOG.md | 3 +- .../lib/src/json_serializable.g.dart | 69 +++++++++-------- json_annotation/pubspec.yaml | 4 +- json_serializable/CHANGELOG.md | 4 + json_serializable/example/example.dart | 2 - json_serializable/example/example.g.dart | 1 - json_serializable/lib/builder.dart | 2 +- json_serializable/lib/src/decode_helper.dart | 33 ++++----- json_serializable/lib/src/encoder_helper.dart | 6 +- json_serializable/lib/src/field_helpers.dart | 8 +- .../lib/src/generator_helper.dart | 8 +- json_serializable/lib/src/helper_core.dart | 10 +-- json_serializable/lib/src/json_key_utils.dart | 74 ++++++++++--------- .../lib/src/json_part_builder.dart | 4 +- .../lib/src/json_serializable_generator.dart | 11 ++- json_serializable/lib/src/settings.dart | 6 +- .../lib/src/shared_checkers.dart | 10 +-- json_serializable/lib/src/type_helper.dart | 8 +- .../lib/src/type_helper_ctx.dart | 23 +++--- .../lib/src/type_helpers/big_int_helper.dart | 4 +- .../lib/src/type_helpers/convert_helper.dart | 8 +- .../src/type_helpers/date_time_helper.dart | 4 +- .../lib/src/type_helpers/duration_helper.dart | 4 +- .../lib/src/type_helpers/enum_helper.dart | 10 +-- .../type_helpers/generic_factory_helper.dart | 8 +- .../lib/src/type_helpers/iterable_helper.dart | 8 +- .../type_helpers/json_converter_helper.dart | 32 ++++---- .../lib/src/type_helpers/json_helper.dart | 36 ++++----- .../lib/src/type_helpers/map_helper.dart | 19 ++--- .../lib/src/type_helpers/to_from_string.dart | 4 +- .../lib/src/type_helpers/uri_helper.dart | 4 +- .../lib/src/type_helpers/value_helper.dart | 4 +- .../lib/src/unsupported_type_error.dart | 2 +- json_serializable/lib/src/utils.dart | 44 ++++++----- json_serializable/pubspec.yaml | 18 +++-- json_serializable/test/config_test.dart | 2 +- .../test/custom_configuration_test.dart | 8 +- .../test/default_value/default_value.dart | 2 - .../test/default_value/default_value.g.dart | 1 - .../default_value.g_any_map__checked.dart | 2 - .../default_value.g_any_map__checked.g.dart | 1 - .../default_value_interface.dart | 2 - .../default_value/default_value_test.dart | 2 - .../generic_argument_factories.dart | 2 - .../generic_argument_factories.g.dart | 1 - .../test/generic_files/generic_class.dart | 2 - .../test/generic_files/generic_class.g.dart | 1 - .../test/generic_files/generic_test.dart | 2 - .../test/integration/integration_test.dart | 2 - .../test/integration/json_test_common.dart | 2 - .../test/integration/json_test_example.dart | 2 - .../test/integration/json_test_example.g.dart | 1 - .../json_test_example.g_any_map.dart | 2 - .../json_test_example.g_any_map.g.dart | 1 - .../test/kitchen_sink/json_converters.dart | 2 - .../test/kitchen_sink/kitchen_sink.dart | 2 - .../kitchen_sink/kitchen_sink.factories.dart | 1 - .../test/kitchen_sink/kitchen_sink.g.dart | 1 - .../kitchen_sink/kitchen_sink.g_any_map.dart | 2 - .../kitchen_sink.g_any_map.g.dart | 1 - .../kitchen_sink.g_any_map__checked.dart | 2 - .../kitchen_sink.g_any_map__checked.g.dart | 1 - .../kitchen_sink.g_exclude_null.dart | 2 - .../kitchen_sink.g_exclude_null.g.dart | 1 - .../kitchen_sink.g_explicit_to_json.dart | 2 - .../kitchen_sink.g_explicit_to_json.g.dart | 1 - .../kitchen_sink/kitchen_sink_interface.dart | 2 - .../test/kitchen_sink/kitchen_sink_test.dart | 2 - .../kitchen_sink_test_shared.dart | 2 - .../kitchen_sink/kitchen_sink_yaml_test.dart | 2 - .../test/kitchen_sink/simple_object.dart | 2 - .../test/kitchen_sink/simple_object.g.dart | 1 - .../test/kitchen_sink/strict_keys_object.dart | 2 - .../kitchen_sink/strict_keys_object.g.dart | 1 - json_serializable/test/readme_test.dart | 2 +- .../src/_json_serializable_test_input.dart | 2 - .../test/src/checked_test_input.dart | 2 - .../test/src/constants_copy.dart | 2 - .../test/src/core_subclass_type_input.dart | 2 - .../test/src/default_value_input.dart | 2 - .../test/src/field_namer_input.dart | 2 - .../test/src/generic_test_input.dart | 2 - .../test/src/inheritance_test_input.dart | 2 - .../test/src/json_converter_test_input.dart | 2 - .../test/src/map_key_variety_test_input.dart | 2 - .../test/src/setter_test_input.dart | 2 - .../test/src/to_from_json_test_input.dart | 2 - .../src/unknown_enum_value_test_input.dart | 2 - .../test/supported_types/enum_type.dart | 2 - .../test/supported_types/input.dart | 2 - .../test/supported_types/input.g.dart | 1 - .../supported_types/input.type_bigint.dart | 2 - .../supported_types/input.type_bigint.g.dart | 1 - .../test/supported_types/input.type_bool.dart | 2 - .../supported_types/input.type_bool.g.dart | 1 - .../supported_types/input.type_datetime.dart | 2 - .../input.type_datetime.g.dart | 1 - .../supported_types/input.type_double.dart | 2 - .../supported_types/input.type_double.g.dart | 1 - .../supported_types/input.type_duration.dart | 2 - .../input.type_duration.g.dart | 1 - .../supported_types/input.type_enumtype.dart | 2 - .../input.type_enumtype.g.dart | 1 - .../test/supported_types/input.type_int.dart | 2 - .../supported_types/input.type_int.g.dart | 1 - .../supported_types/input.type_iterable.dart | 2 - .../input.type_iterable.g.dart | 1 - .../test/supported_types/input.type_list.dart | 2 - .../supported_types/input.type_list.g.dart | 1 - .../test/supported_types/input.type_map.dart | 2 - .../supported_types/input.type_map.g.dart | 1 - .../test/supported_types/input.type_num.dart | 2 - .../supported_types/input.type_num.g.dart | 1 - .../supported_types/input.type_object.dart | 2 - .../supported_types/input.type_object.g.dart | 1 - .../test/supported_types/input.type_set.dart | 2 - .../supported_types/input.type_set.g.dart | 1 - .../supported_types/input.type_string.dart | 2 - .../supported_types/input.type_string.g.dart | 1 - .../test/supported_types/input.type_uri.dart | 2 - .../supported_types/input.type_uri.g.dart | 1 - .../type_test.bigint_test.dart | 2 - .../supported_types/type_test.bool_test.dart | 2 - .../test/supported_types/type_test.dart | 2 - .../type_test.datetime_test.dart | 2 - .../type_test.double_test.dart | 2 - .../type_test.duration_test.dart | 2 - .../type_test.enumtype_test.dart | 2 - .../supported_types/type_test.int_test.dart | 2 - .../type_test.iterable_test.dart | 2 - .../supported_types/type_test.list_test.dart | 2 - .../supported_types/type_test.map_test.dart | 2 - .../supported_types/type_test.num_test.dart | 2 - .../type_test.object_test.dart | 2 - .../supported_types/type_test.set_test.dart | 2 - .../type_test.string_test.dart | 2 - .../supported_types/type_test.uri_test.dart | 2 - .../test/test_sources/test_sources.dart | 2 - json_serializable/test/test_utils.dart | 2 - json_serializable/tool/doc_builder.dart | 12 +-- json_serializable/tool/shared.dart | 2 +- json_serializable/tool/test_builder.dart | 6 +- json_serializable/tool/test_type_data.dart | 14 ++-- 143 files changed, 275 insertions(+), 438 deletions(-) diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index 99086f891..14c1969d9 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -1,7 +1,8 @@ -## 4.0.1-dev +## 4.0.1 - Fix a potential error with `checked: true` when `ArgumentError.message` is `null`. +- Updated `JsonSerializable.fromJson` to handle `null` values. ## 4.0.0 diff --git a/json_annotation/lib/src/json_serializable.g.dart b/json_annotation/lib/src/json_serializable.g.dart index 4aa268cb6..7606a71ff 100644 --- a/json_annotation/lib/src/json_serializable.g.dart +++ b/json_annotation/lib/src/json_serializable.g.dart @@ -18,24 +18,25 @@ JsonSerializable _$JsonSerializableFromJson(Map json) { 'field_rename', 'generic_argument_factories', 'ignore_unannotated', - 'include_if_null', + 'include_if_null' ]); final val = JsonSerializable( - anyMap: $checkedConvert(json, 'any_map', (v) => v as bool), - checked: $checkedConvert(json, 'checked', (v) => v as bool), - createFactory: $checkedConvert(json, 'create_factory', (v) => v as bool), - createToJson: $checkedConvert(json, 'create_to_json', (v) => v as bool), - disallowUnrecognizedKeys: - $checkedConvert(json, 'disallow_unrecognized_keys', (v) => v as bool), + anyMap: $checkedConvert(json, 'any_map', (v) => v as bool?), + checked: $checkedConvert(json, 'checked', (v) => v as bool?), + createFactory: $checkedConvert(json, 'create_factory', (v) => v as bool?), + createToJson: $checkedConvert(json, 'create_to_json', (v) => v as bool?), + disallowUnrecognizedKeys: $checkedConvert( + json, 'disallow_unrecognized_keys', (v) => v as bool?), explicitToJson: - $checkedConvert(json, 'explicit_to_json', (v) => v as bool), + $checkedConvert(json, 'explicit_to_json', (v) => v as bool?), fieldRename: $checkedConvert(json, 'field_rename', (v) => _$enumDecodeNullable(_$FieldRenameEnumMap, v)), ignoreUnannotated: - $checkedConvert(json, 'ignore_unannotated', (v) => v as bool), - includeIfNull: $checkedConvert(json, 'include_if_null', (v) => v as bool), - genericArgumentFactories: - $checkedConvert(json, 'generic_argument_factories', (v) => v as bool), + $checkedConvert(json, 'ignore_unannotated', (v) => v as bool?), + includeIfNull: + $checkedConvert(json, 'include_if_null', (v) => v as bool?), + genericArgumentFactories: $checkedConvert( + json, 'generic_argument_factories', (v) => v as bool?), ); return val; }, fieldKeyMap: const { @@ -65,37 +66,41 @@ Map _$JsonSerializableToJson(JsonSerializable instance) => 'include_if_null': instance.includeIfNull, }; -T _$enumDecode( - Map enumValues, - dynamic source, { - T? unknownValue, +K _$enumDecode( + Map enumValues, + Object? source, { + K? unknownValue, }) { if (source == null) { - throw ArgumentError('A value must be provided. Supported values: ' - '${enumValues.values.join(', ')}'); + throw ArgumentError( + 'A value must be provided. Supported values: ' + '${enumValues.values.join(', ')}', + ); } - final value = enumValues.entries - .cast?>() - .singleWhere((e) => e!.value == source, orElse: () => null) - ?.key; - - if (value == null && unknownValue == null) { - throw ArgumentError('`$source` is not one of the supported values: ' - '${enumValues.values.join(', ')}'); - } - return value ?? unknownValue!; + return enumValues.entries.singleWhere( + (e) => e.value == source, + orElse: () { + if (unknownValue == null) { + throw ArgumentError( + '`$source` is not one of the supported values: ' + '${enumValues.values.join(', ')}', + ); + } + return MapEntry(unknownValue, enumValues.values.first); + }, + ).key; } -T? _$enumDecodeNullable( - Map enumValues, +K? _$enumDecodeNullable( + Map enumValues, dynamic source, { - T? unknownValue, + K? unknownValue, }) { if (source == null) { return null; } - return _$enumDecode(enumValues, source, unknownValue: unknownValue); + return _$enumDecode(enumValues, source, unknownValue: unknownValue); } const _$FieldRenameEnumMap = { diff --git a/json_annotation/pubspec.yaml b/json_annotation/pubspec.yaml index 7879496a9..62e04e7ba 100644 --- a/json_annotation/pubspec.yaml +++ b/json_annotation/pubspec.yaml @@ -1,5 +1,5 @@ name: json_annotation -version: 4.0.1-dev +version: 4.0.1 description: >- Classes and helper functions that support JSON code generation via the `json_serializable` package. @@ -10,4 +10,4 @@ environment: # When changing JsonSerializable class. # dev_dependencies: # build_runner: ^1.0.0 -# json_serializable: ^3.1.0 +# json_serializable: ^4.0.0 diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 0a4595685..bcc29a002 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,7 @@ +## 5.0.0-dev + +- Implementation is now null-safe. + ## 4.0.3 - Correctly handle nullable values with `genericArgumentFactories`. diff --git a/json_serializable/example/example.dart b/json_serializable/example/example.dart index 025ae5459..28d252925 100644 --- a/json_serializable/example/example.dart +++ b/json_serializable/example/example.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.12 - import 'package:json_annotation/json_annotation.dart'; part 'example.g.dart'; diff --git a/json_serializable/example/example.g.dart b/json_serializable/example/example.g.dart index b5d4ad39e..a01e08473 100644 --- a/json_serializable/example/example.g.dart +++ b/json_serializable/example/example.g.dart @@ -1,5 +1,4 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// @dart=2.12 part of 'example.dart'; diff --git a/json_serializable/lib/builder.dart b/json_serializable/lib/builder.dart index cd9014e26..c66e3df21 100644 --- a/json_serializable/lib/builder.dart +++ b/json_serializable/lib/builder.dart @@ -34,7 +34,7 @@ Builder jsonSerializable(BuilderOptions options) { lines.add('There is a problem with "${e.key}".'); } if (e.message != null) { - lines.add(e.message); + lines.add(e.message!); } else if (e.innerError != null) { lines.add(e.innerError.toString()); } diff --git a/json_serializable/lib/src/decode_helper.dart b/json_serializable/lib/src/decode_helper.dart index 12002a865..f6bed5954 100644 --- a/json_serializable/lib/src/decode_helper.dart +++ b/json_serializable/lib/src/decode_helper.dart @@ -25,15 +25,15 @@ abstract class DecodeHelper implements HelperCore { Map accessibleFields, Map unavailableReasons, ) { - assert(config.createFactory); + assert(config.createFactory!); final buffer = StringBuffer(); - final mapType = config.anyMap ? 'Map' : 'Map'; + final mapType = config.anyMap! ? 'Map' : 'Map'; buffer.write('$targetClassReference ' '${prefix}FromJson${genericClassArgumentsImpl(true)}' '($mapType json'); - if (config.genericArgumentFactories) { + if (config.genericArgumentFactories!) { for (var arg in element.typeParameters) { final helperName = fromJsonForType( arg.instantiate(nullabilitySuffix: NullabilitySuffix.none), @@ -49,8 +49,8 @@ abstract class DecodeHelper implements HelperCore { buffer.write(') {\n'); String deserializeFun(String paramOrFieldName, - {ParameterElement ctorParam}) => - _deserializeForField(accessibleFields[paramOrFieldName], + {ParameterElement? ctorParam}) => + _deserializeForField(accessibleFields[paramOrFieldName]!, ctorParam: ctorParam); final data = _writeConstructorInvocation( @@ -72,7 +72,7 @@ abstract class DecodeHelper implements HelperCore { final checks = _checkKeys(accessibleFields.values .where((fe) => data.usedCtorParamsAndFields.contains(fe.name))); - if (config.checked) { + if (config.checked!) { final classLiteral = escapeDartString(element.name); buffer..write(''' @@ -84,12 +84,12 @@ abstract class DecodeHelper implements HelperCore { for (final field in data.fieldsToSet) { buffer.writeln(); - final safeName = safeNameAccess(accessibleFields[field]); + final safeName = safeNameAccess(accessibleFields[field]!); buffer ..write(''' \$checkedConvert(json, $safeName, (v) => ''') ..write('val.$field = ') - ..write(_deserializeForField(accessibleFields[field], + ..write(_deserializeForField(accessibleFields[field]!, checkedProperty: true)) ..write(');'); } @@ -98,7 +98,7 @@ abstract class DecodeHelper implements HelperCore { }'''); final fieldKeyMap = Map.fromEntries(data.usedCtorParamsAndFields - .map((k) => MapEntry(k, nameAccess(accessibleFields[k]))) + .map((k) => MapEntry(k, nameAccess(accessibleFields[k]!))) .where((me) => me.key != me.value)); String fieldKeyMapArg; @@ -131,14 +131,14 @@ abstract class DecodeHelper implements HelperCore { String constantList(Iterable things) => 'const ${jsonLiteralAsDart(things.map(nameAccess).toList())}'; - if (config.disallowUnrecognizedKeys) { + if (config.disallowUnrecognizedKeys!) { final allowKeysLiteral = constantList(accessibleFields); args.add('allowedKeys: $allowKeysLiteral'); } final requiredKeys = - accessibleFields.where((fe) => jsonKeyFor(fe).required).toList(); + accessibleFields.where((fe) => jsonKeyFor(fe).required!).toList(); if (requiredKeys.isNotEmpty) { final requiredKeyLiteral = constantList(requiredKeys); @@ -146,7 +146,7 @@ abstract class DecodeHelper implements HelperCore { } final disallowNullKeys = accessibleFields - .where((fe) => jsonKeyFor(fe).disallowNullValue) + .where((fe) => jsonKeyFor(fe).disallowNullValue!) .toList(); if (disallowNullKeys.isNotEmpty) { final disallowNullKeyLiteral = constantList(disallowNullKeys); @@ -163,10 +163,9 @@ abstract class DecodeHelper implements HelperCore { String _deserializeForField( FieldElement field, { - ParameterElement ctorParam, - bool checkedProperty, + ParameterElement? ctorParam, + bool checkedProperty = false, }) { - checkedProperty ??= false; final jsonKeyName = safeNameAccess(field); final targetType = ctorParam?.type ?? field.type; final contextHelper = getHelperContext(field); @@ -174,7 +173,7 @@ abstract class DecodeHelper implements HelperCore { String value; try { - if (config.checked) { + if (config.checked!) { value = contextHelper .deserialize( targetType, @@ -205,7 +204,7 @@ abstract class DecodeHelper implements HelperCore { final jsonKey = jsonKeyFor(field); final defaultValue = jsonKey.defaultValue; if (defaultValue != null) { - if (jsonKey.disallowNullValue && jsonKey.required) { + if (jsonKey.disallowNullValue! && jsonKey.required!) { log.warning('The `defaultValue` on field `${field.name}` will have no ' 'effect because both `disallowNullValue` and `required` are set to ' '`true`.'); diff --git a/json_serializable/lib/src/encoder_helper.dart b/json_serializable/lib/src/encoder_helper.dart index 6ea548781..c11773a3f 100644 --- a/json_serializable/lib/src/encoder_helper.dart +++ b/json_serializable/lib/src/encoder_helper.dart @@ -17,7 +17,7 @@ abstract class EncodeHelper implements HelperCore { String _fieldAccess(FieldElement field) => '$_toJsonParamName.${field.name}'; Iterable createToJson(Set accessibleFields) sync* { - assert(config.createToJson); + assert(config.createToJson!); final buffer = StringBuffer(); @@ -25,7 +25,7 @@ abstract class EncodeHelper implements HelperCore { buffer.write('Map ' '$functionName($targetClassReference $_toJsonParamName'); - if (config.genericArgumentFactories) { + if (config.genericArgumentFactories!) { for (var arg in element.typeParameters) { final helperName = toJsonForType( arg.instantiate(nullabilitySuffix: NullabilitySuffix.none), @@ -140,7 +140,7 @@ abstract class EncodeHelper implements HelperCore { bool _writeJsonValueNaive(FieldElement field) { final jsonKey = jsonKeyFor(field); - return jsonKey.includeIfNull || + return jsonKey.includeIfNull! || (!field.type.isNullableType && !_fieldHasCustomEncoder(field)); } diff --git a/json_serializable/lib/src/field_helpers.dart b/json_serializable/lib/src/field_helpers.dart index 932c43df5..83b293c90 100644 --- a/json_serializable/lib/src/field_helpers.dart +++ b/json_serializable/lib/src/field_helpers.dart @@ -17,9 +17,9 @@ class _FieldSet implements Comparable<_FieldSet> { _FieldSet._(this.field, this.sortField) : assert(field.name == sortField.name); - factory _FieldSet(FieldElement classField, FieldElement superField) { + factory _FieldSet(FieldElement? classField, FieldElement? superField) { // At least one of these will != null, perhaps both. - final fields = [classField, superField].where((fe) => fe != null).toList(); + final fields = [classField, superField].whereType().toList(); // Prefer the class field over the inherited field when sorting. final sortField = fields.first; @@ -58,9 +58,9 @@ class _FieldSet implements Comparable<_FieldSet> { /// Returns the offset of given field/property in its source file – with a /// preference for the getter if it's defined. int _offsetFor(FieldElement e) { - if (e.getter != null && e.getter.nameOffset != e.nameOffset) { + if (e.getter != null && e.getter!.nameOffset != e.nameOffset) { assert(e.nameOffset == -1); - return e.getter.nameOffset; + return e.getter!.nameOffset; } return e.nameOffset; } diff --git a/json_serializable/lib/src/generator_helper.dart b/json_serializable/lib/src/generator_helper.dart index 011fd46d3..95c7d1e36 100644 --- a/json_serializable/lib/src/generator_helper.dart +++ b/json_serializable/lib/src/generator_helper.dart @@ -41,7 +41,7 @@ class GeneratorHelper extends HelperCore with EncodeHelper, DecodeHelper { Iterable generate() sync* { assert(_addedMembers.isEmpty); - if (config.genericArgumentFactories && element.typeParameters.isEmpty) { + if (config.genericArgumentFactories! && element.typeParameters.isEmpty) { log.warning( 'The class `${element.displayName}` is annotated ' 'with `JsonSerializable` field `genericArgumentFactories: true`. ' @@ -68,7 +68,7 @@ class GeneratorHelper extends HelperCore with EncodeHelper, DecodeHelper { unavailableReasons[field.name] = 'Setter-only properties are not supported.'; log.warning('Setters are ignored: ${element.name}.${field.name}'); - } else if (jsonKeyFor(field).ignore) { + } else if (jsonKeyFor(field).ignore!) { unavailableReasons[field.name] = 'It is assigned to an ignored field.'; } else { @@ -81,7 +81,7 @@ class GeneratorHelper extends HelperCore with EncodeHelper, DecodeHelper { ); var accessibleFieldSet = accessibleFields.values.toSet(); - if (config.createFactory) { + if (config.createFactory!) { final createResult = createFactory(accessibleFields, unavailableReasons); yield createResult.output; @@ -108,7 +108,7 @@ class GeneratorHelper extends HelperCore with EncodeHelper, DecodeHelper { }, ); - if (config.createToJson) { + if (config.createToJson!) { yield* createToJson(accessibleFieldSet); } diff --git a/json_serializable/lib/src/helper_core.dart b/json_serializable/lib/src/helper_core.dart index 4e389f58e..20eb2fb7b 100644 --- a/json_serializable/lib/src/helper_core.dart +++ b/json_serializable/lib/src/helper_core.dart @@ -30,7 +30,7 @@ abstract class HelperCore { '${element.name}${genericClassArgumentsImpl(false)}'; @protected - String nameAccess(FieldElement field) => jsonKeyFor(field).name; + String nameAccess(FieldElement field) => jsonKeyFor(field).name!; @protected String safeNameAccess(FieldElement field) => @@ -62,7 +62,7 @@ InvalidGenerationSourceError createInvalidGenerationError( ) { var message = 'Could not generate `$targetMember` code for `${field.name}`'; - String todo; + String? todo; if (error.type is TypeParameterType) { message = '$message because of type ' '`${error.type.getDisplayString(withNullability: false)}` (type parameter)'; @@ -76,7 +76,7 @@ $converterOrKeyInstructions message = '$message because of type `${typeToCode(error.type)}`'; } else { todo = ''' -To support the type `${error.type.element.name}` you can: +To support the type `${error.type.element!.name}` you can: $converterOrKeyInstructions'''; } @@ -112,13 +112,13 @@ $converterOrKeyInstructions'''; /// ``` /// "" /// ``` -String genericClassArguments(ClassElement element, bool withConstraints) { +String genericClassArguments(ClassElement element, bool? withConstraints) { if (withConstraints == null || element.typeParameters.isEmpty) { return ''; } final values = element.typeParameters.map((t) { if (withConstraints && t.bound != null) { - final boundCode = typeToCode(t.bound); + final boundCode = typeToCode(t.bound!); return '${t.name} extends $boundCode'; } else { return t.name; diff --git a/json_serializable/lib/src/json_key_utils.dart b/json_serializable/lib/src/json_key_utils.dart index 0a51473c4..cde0bf487 100644 --- a/json_serializable/lib/src/json_key_utils.dart +++ b/json_serializable/lib/src/json_key_utils.dart @@ -34,7 +34,7 @@ JsonKey _from(FieldElement element, JsonSerializable classAnnotation) { /// Returns a literal value for [dartObject] if possible, otherwise throws /// an [InvalidGenerationSourceError] using [typeInformation] to describe /// the unsupported type. - Object literalForObject( + Object? literalForObject( DartObject dartObject, Iterable typeInformation, ) { @@ -44,7 +44,7 @@ JsonKey _from(FieldElement element, JsonSerializable classAnnotation) { final reader = ConstantReader(dartObject); - String badType; + String? badType; if (reader.isSymbol) { badType = 'Symbol'; } else if (reader.isType) { @@ -53,7 +53,7 @@ JsonKey _from(FieldElement element, JsonSerializable classAnnotation) { // TODO: Support calling function for the default value? badType = 'Function'; } else if (!reader.isLiteral) { - badType = dartObject.type.element.name; + badType = dartObject.type!.element!.name; } if (badType != null) { @@ -93,8 +93,8 @@ JsonKey _from(FieldElement element, JsonSerializable classAnnotation) { ]; return reader.mapValue.map( (k, v) => MapEntry( - literalForObject(k, mapTypeInformation), - literalForObject(v, mapTypeInformation), + literalForObject(k!, mapTypeInformation), + literalForObject(v!, mapTypeInformation), ), ); } @@ -114,15 +114,15 @@ JsonKey _from(FieldElement element, JsonSerializable classAnnotation) { /// If [mustBeEnum] is `true`, throws an [InvalidGenerationSourceError] if /// either the annotated field is not an `enum` or `List` or if the value in /// [fieldName] is not an `enum` value. - Object _annotationValue(String fieldName, {bool mustBeEnum = false}) { + Object? _annotationValue(String fieldName, {bool mustBeEnum = false}) { final annotationValue = obj.read(fieldName); final enumFields = annotationValue.isNull ? null - : iterateEnumFields(annotationValue.objectValue.type); + : iterateEnumFields(annotationValue.objectValue.type!); if (enumFields != null) { if (mustBeEnum) { - DartType targetEnumType; + late DartType targetEnumType; if (isEnum(element.type)) { targetEnumType = element.type; } else if (coreIterableTypeChecker.isAssignableFromType(element.type)) { @@ -134,8 +134,7 @@ JsonKey _from(FieldElement element, JsonSerializable classAnnotation) { 'Iterable, List, or Set instances of an enum type.', ); } - assert(targetEnumType != null); - final annotatedEnumType = annotationValue.objectValue.type; + final annotatedEnumType = annotationValue.objectValue.type!; if (!_interfaceTypesEqual(annotatedEnumType, targetEnumType)) { throwUnsupported( element, @@ -153,7 +152,7 @@ JsonKey _from(FieldElement element, JsonSerializable classAnnotation) { final enumValueName = enumValueForDartObject( annotationValue.objectValue, enumValueNames, (n) => n); - return '${annotationValue.objectValue.type.element.name}.$enumValueName'; + return '${annotationValue.objectValue.type!.element!.name}.$enumValueName'; } else { final defaultValueLiteral = annotationValue.isNull ? null @@ -175,11 +174,11 @@ JsonKey _from(FieldElement element, JsonSerializable classAnnotation) { classAnnotation, element, defaultValue: _annotationValue('defaultValue'), - disallowNullValue: obj.read('disallowNullValue').literalValue as bool, - ignore: obj.read('ignore').literalValue as bool, - includeIfNull: obj.read('includeIfNull').literalValue as bool, - name: obj.read('name').literalValue as String, - required: obj.read('required').literalValue as bool, + disallowNullValue: obj.read('disallowNullValue').literalValue as bool?, + ignore: obj.read('ignore').literalValue as bool?, + includeIfNull: obj.read('includeIfNull').literalValue as bool?, + name: obj.read('name').literalValue as String?, + required: obj.read('required').literalValue as bool?, unknownEnumValue: _annotationValue('unknownEnumValue', mustBeEnum: true), ); } @@ -187,13 +186,13 @@ JsonKey _from(FieldElement element, JsonSerializable classAnnotation) { JsonKey _populateJsonKey( JsonSerializable classAnnotation, FieldElement element, { - Object defaultValue, - bool disallowNullValue, - bool ignore, - bool includeIfNull, - String name, - bool required, - Object unknownEnumValue, + Object? defaultValue, + bool? disallowNullValue, + bool? ignore, + bool? includeIfNull, + String? name, + bool? required, + Object? unknownEnumValue, }) { if (disallowNullValue == true) { if (includeIfNull == true) { @@ -218,8 +217,11 @@ JsonKey _populateJsonKey( return jsonKey; } -String _encodedFieldName(JsonSerializable classAnnotation, - String jsonKeyNameValue, FieldElement fieldElement) { +String _encodedFieldName( + JsonSerializable classAnnotation, + String? jsonKeyNameValue, + FieldElement fieldElement, +) { if (jsonKeyNameValue != null) { return jsonKeyNameValue; } @@ -233,20 +235,20 @@ String _encodedFieldName(JsonSerializable classAnnotation, return kebabCase(fieldElement.name); case FieldRename.pascal: return pascalCase(fieldElement.name); + default: + throw ArgumentError.value( + classAnnotation, + 'classAnnotation', + 'The provided `fieldRename` (${classAnnotation.fieldRename}) is not ' + 'supported.', + ); } - - throw ArgumentError.value( - classAnnotation, - 'classAnnotation', - 'The provided `fieldRename` (${classAnnotation.fieldRename}) is not ' - 'supported.', - ); } -bool _includeIfNull( - bool keyIncludeIfNull, - bool keyDisallowNullValue, - bool classIncludeIfNull, +bool? _includeIfNull( + bool? keyIncludeIfNull, + bool? keyDisallowNullValue, + bool? classIncludeIfNull, ) { if (keyDisallowNullValue == true) { assert(keyIncludeIfNull != true); diff --git a/json_serializable/lib/src/json_part_builder.dart b/json_serializable/lib/src/json_part_builder.dart index 1bf2d38f3..8cc040444 100644 --- a/json_serializable/lib/src/json_part_builder.dart +++ b/json_serializable/lib/src/json_part_builder.dart @@ -16,8 +16,8 @@ import 'settings.dart'; /// [formatOutput] is called to format the generated code. If not provided, /// the default Dart code formatter is used. Builder jsonPartBuilder({ - String Function(String code) formatOutput, - JsonSerializable config, + String Function(String code)? formatOutput, + JsonSerializable? config, }) { final settings = Settings(config: config); diff --git a/json_serializable/lib/src/json_serializable_generator.dart b/json_serializable/lib/src/json_serializable_generator.dart index e0894c58a..0513a7716 100644 --- a/json_serializable/lib/src/json_serializable_generator.dart +++ b/json_serializable/lib/src/json_serializable_generator.dart @@ -30,8 +30,8 @@ class JsonSerializableGenerator /// [BigIntHelper], [DateTimeHelper], [DurationHelper], [JsonHelper], and /// [UriHelper]. factory JsonSerializableGenerator({ - JsonSerializable config, - List typeHelpers, + JsonSerializable? config, + List? typeHelpers, }) => JsonSerializableGenerator.fromSettings(Settings( config: config, @@ -46,7 +46,7 @@ class JsonSerializableGenerator /// [UriHelper]. factory JsonSerializableGenerator.withDefaultHelpers( Iterable typeHelpers, { - JsonSerializable config, + JsonSerializable? config, }) => JsonSerializableGenerator( config: config, @@ -61,7 +61,7 @@ class JsonSerializableGenerator ConstantReader annotation, BuildStep buildStep, ) { - if (!element.library.isNonNullableByDefault) { + if (!element.library!.isNonNullableByDefault) { throw InvalidGenerationSourceError( 'Generator cannot target libraries that have not been migrated to ' 'null-safety.', @@ -76,8 +76,7 @@ class JsonSerializableGenerator ); } - final classElement = element as ClassElement; - final helper = GeneratorHelper(_settings, classElement, annotation); + final helper = GeneratorHelper(_settings, element, annotation); return helper.generate(); } } diff --git a/json_serializable/lib/src/settings.dart b/json_serializable/lib/src/settings.dart index 50b6639de..5d9e3ea40 100644 --- a/json_serializable/lib/src/settings.dart +++ b/json_serializable/lib/src/settings.dart @@ -52,8 +52,8 @@ class Settings { /// [BigIntHelper], [DateTimeHelper], [DurationHelper], [JsonHelper], and /// [UriHelper]. const Settings({ - JsonSerializable config, - List typeHelpers, + JsonSerializable? config, + List? typeHelpers, }) : _config = config ?? JsonSerializable.defaults, _typeHelpers = typeHelpers ?? defaultHelpers; @@ -65,7 +65,7 @@ class Settings { /// [UriHelper]. factory Settings.withDefaultHelpers( Iterable typeHelpers, { - JsonSerializable config, + JsonSerializable? config, }) => Settings( config: config, diff --git a/json_serializable/lib/src/shared_checkers.dart b/json_serializable/lib/src/shared_checkers.dart index 0f4a6dca3..40a78cc1e 100644 --- a/json_serializable/lib/src/shared_checkers.dart +++ b/json_serializable/lib/src/shared_checkers.dart @@ -3,6 +3,7 @@ // BSD-style license that can be found in the LICENSE file. import 'package:analyzer/dart/element/type.dart'; +import 'package:collection/collection.dart'; import 'package:source_gen/source_gen.dart' show TypeChecker; import 'helper_core.dart'; @@ -28,7 +29,7 @@ DartType coreIterableGenericType(DartType type) => List typeArgumentsOf(DartType type, TypeChecker checker) { final implementation = _getImplementationType(type, checker) as InterfaceType; - return implementation?.typeArguments; + return implementation.typeArguments; } /// A [TypeChecker] for [String], [bool] and [num]. @@ -79,11 +80,10 @@ Iterable typeImplementations(DartType type) sync* { yield* type.mixins.expand(typeImplementations); if (type.superclass != null) { - yield* typeImplementations(type.superclass); + yield* typeImplementations(type.superclass!); } } } -DartType _getImplementationType(DartType type, TypeChecker checker) => - typeImplementations(type) - .firstWhere(checker.isExactlyType, orElse: () => null); +DartType? _getImplementationType(DartType type, TypeChecker checker) => + typeImplementations(type).firstWhereOrNull(checker.isExactlyType); diff --git a/json_serializable/lib/src/type_helper.dart b/json_serializable/lib/src/type_helper.dart index af0c1167c..3d7e10f5a 100644 --- a/json_serializable/lib/src/type_helper.dart +++ b/json_serializable/lib/src/type_helper.dart @@ -17,11 +17,11 @@ abstract class TypeHelperContext { /// [expression] may be just the name of the field or it may an expression /// representing the serialization of a value. - Object serialize(DartType fieldType, String expression); + Object? serialize(DartType fieldType, String expression); /// [expression] may be just the name of the field or it may an expression /// representing the serialization of a value. - Object deserialize(DartType fieldType, String expression); + Object? deserialize(DartType fieldType, String expression); /// Adds [memberContent] to the set of generated, top-level members. void addMember(String memberContent); @@ -51,7 +51,7 @@ abstract class TypeHelper { /// String serialize(DartType targetType, String expression) => /// "$expression.id"; /// ```. - Object serialize(DartType targetType, String expression, T context); + Object? serialize(DartType targetType, String expression, T context); /// Returns Dart code that deserializes an [expression] representing a JSON /// literal to into [targetType]. @@ -76,7 +76,7 @@ abstract class TypeHelper { /// String deserialize(DartType targetType, String expression) => /// "new ${targetType.name}.fromInt($expression)"; /// ```. - Object deserialize( + Object? deserialize( DartType targetType, String expression, T context, diff --git a/json_serializable/lib/src/type_helper_ctx.dart b/json_serializable/lib/src/type_helper_ctx.dart index cd1efaff5..ab1fff795 100644 --- a/json_serializable/lib/src/type_helper_ctx.dart +++ b/json_serializable/lib/src/type_helper_ctx.dart @@ -6,7 +6,6 @@ import 'package:analyzer/dart/constant/value.dart'; import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/type.dart'; import 'package:json_annotation/json_annotation.dart'; -import 'package:meta/meta.dart'; import 'helper_core.dart'; import 'type_helper.dart'; @@ -34,10 +33,10 @@ class TypeHelperCtx TypeHelperCtx._(this._helperCore, this.fieldElement); @override - ConvertData get serializeConvertData => _pairFromContext?.toJson; + ConvertData? get serializeConvertData => _pairFromContext.toJson; @override - ConvertData get deserializeConvertData => _pairFromContext?.fromJson; + ConvertData? get deserializeConvertData => _pairFromContext.fromJson; _ConvertPair get _pairFromContext => _ConvertPair(fieldElement); @@ -47,17 +46,17 @@ class TypeHelperCtx } @override - Object serialize(DartType targetType, String expression) => _run( + Object? serialize(DartType targetType, String expression) => _run( targetType, expression, (TypeHelper th) => th.serialize(targetType, expression, this), ); @override - Object deserialize( + Object? deserialize( DartType targetType, String expression, { - @required bool defaultProvided, + bool defaultProvided = false, }) => _run( targetType, @@ -66,25 +65,25 @@ class TypeHelperCtx targetType, expression, this, - defaultProvided ?? false, + defaultProvided, ), ); Object _run( DartType targetType, String expression, - Object Function(TypeHelper) invoke, + Object? Function(TypeHelper) invoke, ) => _helperCore.allTypeHelpers.map(invoke).firstWhere( (r) => r != null, orElse: () => throw UnsupportedTypeError(targetType, expression), - ); + ) as Object; } class _ConvertPair { static final _expando = Expando<_ConvertPair>(); - final ConvertData fromJson, toJson; + final ConvertData? fromJson, toJson; _ConvertPair._(this.fromJson, this.toJson); @@ -106,7 +105,7 @@ class _ConvertPair { } } -ConvertData _convertData(DartObject obj, FieldElement element, bool isFrom) { +ConvertData? _convertData(DartObject obj, FieldElement element, bool isFrom) { final paramName = isFrom ? 'fromJson' : 'toJson'; final objectValue = obj.getField(paramName); @@ -114,7 +113,7 @@ ConvertData _convertData(DartObject obj, FieldElement element, bool isFrom) { return null; } - final executableElement = objectValue.toFunctionValue(); + final executableElement = objectValue.toFunctionValue()!; if (executableElement.parameters.isEmpty || executableElement.parameters.first.isNamed || diff --git a/json_serializable/lib/src/type_helpers/big_int_helper.dart b/json_serializable/lib/src/type_helpers/big_int_helper.dart index 4a4166d91..b2da21a27 100644 --- a/json_serializable/lib/src/type_helpers/big_int_helper.dart +++ b/json_serializable/lib/src/type_helpers/big_int_helper.dart @@ -12,7 +12,7 @@ class BigIntHelper extends TypeHelper { const BigIntHelper(); @override - String serialize( + String? serialize( DartType targetType, String expression, TypeHelperContext context, @@ -24,7 +24,7 @@ class BigIntHelper extends TypeHelper { ); @override - String deserialize( + String? deserialize( DartType targetType, String expression, TypeHelperContext context, diff --git a/json_serializable/lib/src/type_helpers/convert_helper.dart b/json_serializable/lib/src/type_helpers/convert_helper.dart index b605c5c4d..8d31f9863 100644 --- a/json_serializable/lib/src/type_helpers/convert_helper.dart +++ b/json_serializable/lib/src/type_helpers/convert_helper.dart @@ -18,16 +18,16 @@ class ConvertData { } abstract class TypeHelperContextWithConvert extends TypeHelperContext { - ConvertData get serializeConvertData; + ConvertData? get serializeConvertData; - ConvertData get deserializeConvertData; + ConvertData? get deserializeConvertData; } class ConvertHelper extends TypeHelper { const ConvertHelper(); @override - String serialize( + String? serialize( DartType targetType, String expression, TypeHelperContextWithConvert context, @@ -43,7 +43,7 @@ class ConvertHelper extends TypeHelper { } @override - String deserialize( + String? deserialize( DartType targetType, String expression, TypeHelperContextWithConvert context, diff --git a/json_serializable/lib/src/type_helpers/date_time_helper.dart b/json_serializable/lib/src/type_helpers/date_time_helper.dart index beefd0065..d97bc17ac 100644 --- a/json_serializable/lib/src/type_helpers/date_time_helper.dart +++ b/json_serializable/lib/src/type_helpers/date_time_helper.dart @@ -12,7 +12,7 @@ class DateTimeHelper extends TypeHelper { const DateTimeHelper(); @override - String serialize( + String? serialize( DartType targetType, String expression, TypeHelperContext context, @@ -24,7 +24,7 @@ class DateTimeHelper extends TypeHelper { ); @override - String deserialize( + String? deserialize( DartType targetType, String expression, TypeHelperContext context, diff --git a/json_serializable/lib/src/type_helpers/duration_helper.dart b/json_serializable/lib/src/type_helpers/duration_helper.dart index 95acda21a..cf597a6be 100644 --- a/json_serializable/lib/src/type_helpers/duration_helper.dart +++ b/json_serializable/lib/src/type_helpers/duration_helper.dart @@ -12,7 +12,7 @@ class DurationHelper extends TypeHelper { const DurationHelper(); @override - String serialize( + String? serialize( DartType targetType, String expression, TypeHelperContext context, @@ -33,7 +33,7 @@ class DurationHelper extends TypeHelper { } @override - String deserialize( + String? deserialize( DartType targetType, String expression, TypeHelperContext context, diff --git a/json_serializable/lib/src/type_helpers/enum_helper.dart b/json_serializable/lib/src/type_helpers/enum_helper.dart index f12c54740..c3aa4ba31 100644 --- a/json_serializable/lib/src/type_helpers/enum_helper.dart +++ b/json_serializable/lib/src/type_helpers/enum_helper.dart @@ -15,7 +15,7 @@ class EnumHelper extends TypeHelper { const EnumHelper(); @override - String serialize( + String? serialize( DartType targetType, String expression, TypeHelperContextWithConfig context, @@ -32,7 +32,7 @@ class EnumHelper extends TypeHelper { } @override - String deserialize( + String? deserialize( DartType targetType, String expression, TypeHelperContextWithConfig context, @@ -69,9 +69,9 @@ class EnumHelper extends TypeHelper { } String _constMapName(DartType targetType) => - '_\$${targetType.element.name}EnumMap'; + '_\$${targetType.element!.name}EnumMap'; -String _enumValueMapFromType(DartType targetType) { +String? _enumValueMapFromType(DartType targetType) { final enumMap = enumFieldsMap(targetType); if (enumMap == null) { @@ -79,7 +79,7 @@ String _enumValueMapFromType(DartType targetType) { } final items = enumMap.entries - .map((e) => ' ${targetType.element.name}.${e.key.name}: ' + .map((e) => ' ${targetType.element!.name}.${e.key.name}: ' '${jsonLiteralAsDart(e.value)},') .join(); diff --git a/json_serializable/lib/src/type_helpers/generic_factory_helper.dart b/json_serializable/lib/src/type_helpers/generic_factory_helper.dart index a8f8dc88c..8227065f4 100644 --- a/json_serializable/lib/src/type_helpers/generic_factory_helper.dart +++ b/json_serializable/lib/src/type_helpers/generic_factory_helper.dart @@ -11,12 +11,12 @@ class GenericFactoryHelper extends TypeHelper { const GenericFactoryHelper(); @override - Object serialize( + Object? serialize( DartType targetType, String expression, TypeHelperContextWithConfig context, ) { - if (context.config.genericArgumentFactories && + if (context.config.genericArgumentFactories! && targetType is TypeParameterType) { return LambdaResult(expression, toJsonForType(targetType)); } @@ -25,13 +25,13 @@ class GenericFactoryHelper extends TypeHelper { } @override - Object deserialize( + Object? deserialize( DartType targetType, String expression, TypeHelperContextWithConfig context, bool defaultProvided, ) { - if (context.config.genericArgumentFactories && + if (context.config.genericArgumentFactories! && targetType is TypeParameterType) { return LambdaResult(expression, fromJsonForType(targetType)); } diff --git a/json_serializable/lib/src/type_helpers/iterable_helper.dart b/json_serializable/lib/src/type_helpers/iterable_helper.dart index 53f2fcf69..4c26fb42e 100644 --- a/json_serializable/lib/src/type_helpers/iterable_helper.dart +++ b/json_serializable/lib/src/type_helpers/iterable_helper.dart @@ -15,7 +15,7 @@ class IterableHelper extends TypeHelper { const IterableHelper(); @override - String serialize( + String? serialize( DartType targetType, String expression, TypeHelperContextWithConfig context, @@ -30,7 +30,7 @@ class IterableHelper extends TypeHelper { // Although it's possible that child elements may be marked unsafe var isList = _coreListChecker.isAssignableFromType(targetType); - final subField = context.serialize(itemType, closureArg); + final subField = context.serialize(itemType, closureArg)!; var optionalQuestion = targetType.isNullableType ? '?' : ''; @@ -59,7 +59,7 @@ class IterableHelper extends TypeHelper { } @override - String deserialize( + String? deserialize( DartType targetType, String expression, TypeHelperContext context, @@ -73,7 +73,7 @@ class IterableHelper extends TypeHelper { final iterableGenericType = coreIterableGenericType(targetType); - final itemSubVal = context.deserialize(iterableGenericType, closureArg); + final itemSubVal = context.deserialize(iterableGenericType, closureArg)!; var output = '$expression as List'; diff --git a/json_serializable/lib/src/type_helpers/json_converter_helper.dart b/json_serializable/lib/src/type_helpers/json_converter_helper.dart index f1f2bdfd1..9c9044f40 100644 --- a/json_serializable/lib/src/type_helpers/json_converter_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_converter_helper.dart @@ -5,6 +5,7 @@ import 'package:analyzer/dart/constant/value.dart'; import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/type.dart'; +import 'package:collection/collection.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:source_gen/source_gen.dart'; @@ -20,7 +21,7 @@ class JsonConverterHelper extends TypeHelper { const JsonConverterHelper(); @override - Object serialize( + Object? serialize( DartType targetType, String expression, TypeHelperContext context, @@ -35,7 +36,7 @@ class JsonConverterHelper extends TypeHelper { } @override - Object deserialize( + Object? deserialize( DartType targetType, String expression, TypeHelperContext context, @@ -76,10 +77,10 @@ class _JsonConvertData { accessor.isEmpty ? '' : '.$accessor'; } -_JsonConvertData _typeConverter(DartType targetType, TypeHelperContext ctx) { +_JsonConvertData? _typeConverter(DartType targetType, TypeHelperContext ctx) { List<_ConverterMatch> converterMatches(List items) => items .map((annotation) => _compatibleMatch(targetType, annotation)) - .where((dt) => dt != null) + .whereType<_ConverterMatch>() .toList(); var matchingAnnotations = converterMatches(ctx.fieldElement.metadata); @@ -96,7 +97,7 @@ _JsonConvertData _typeConverter(DartType targetType, TypeHelperContext ctx) { return _typeConverterFrom(matchingAnnotations, targetType); } -_JsonConvertData _typeConverterFrom( +_JsonConvertData? _typeConverterFrom( List<_ConverterMatch> matchingAnnotations, DartType targetType, ) { @@ -137,15 +138,15 @@ _JsonConvertData _typeConverterFrom( if (match.genericTypeArg != null) { return _JsonConvertData.genericClass( - match.annotation.type.element.name, - match.genericTypeArg, + match.annotation.type!.element!.name!, + match.genericTypeArg!, reviver.accessor, match.jsonType, ); } return _JsonConvertData.className( - match.annotation.type.element.name, + match.annotation.type!.element!.name!, reviver.accessor, match.jsonType, ); @@ -155,7 +156,7 @@ class _ConverterMatch { final DartObject annotation; final DartType jsonType; final ElementAnnotation elementAnnotation; - final String genericTypeArg; + final String? genericTypeArg; _ConverterMatch( this.elementAnnotation, @@ -165,17 +166,18 @@ class _ConverterMatch { ); } -_ConverterMatch _compatibleMatch( +_ConverterMatch? _compatibleMatch( DartType targetType, ElementAnnotation annotation, ) { - final constantValue = annotation.computeConstantValue(); + final constantValue = annotation.computeConstantValue()!; - final converterClassElement = constantValue.type.element as ClassElement; + final converterClassElement = constantValue.type!.element as ClassElement; - final jsonConverterSuper = converterClassElement.allSupertypes.singleWhere( - (e) => e is InterfaceType && _jsonConverterChecker.isExactly(e.element), - orElse: () => null); + final jsonConverterSuper = + converterClassElement.allSupertypes.singleWhereOrNull( + (e) => e is InterfaceType && _jsonConverterChecker.isExactly(e.element), + ); if (jsonConverterSuper == null) { return null; diff --git a/json_serializable/lib/src/type_helpers/json_helper.dart b/json_serializable/lib/src/type_helpers/json_helper.dart index a678a309e..86de56fc9 100644 --- a/json_serializable/lib/src/type_helpers/json_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_helper.dart @@ -5,6 +5,7 @@ import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/nullability_suffix.dart'; import 'package:analyzer/dart/element/type.dart'; +import 'package:collection/collection.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:source_gen/source_gen.dart'; @@ -23,7 +24,7 @@ class JsonHelper extends TypeHelper { /// By default, JSON encoding in from `dart:convert` calls `toJson()` on /// provided objects. @override - String serialize( + String? serialize( DartType targetType, String expression, TypeHelperContextWithConfig context, @@ -54,7 +55,7 @@ class JsonHelper extends TypeHelper { ); } - if (context.config.explicitToJson || toJsonArgs.isNotEmpty) { + if (context.config.explicitToJson! || toJsonArgs.isNotEmpty) { return '$expression${interfaceType.isNullableType ? '?' : ''}' '.toJson(${toJsonArgs.map((a) => '$a, ').join()} )'; } @@ -62,7 +63,7 @@ class JsonHelper extends TypeHelper { } @override - String deserialize( + String? deserialize( DartType targetType, String expression, TypeHelperContextWithConfig context, @@ -72,11 +73,10 @@ class JsonHelper extends TypeHelper { return null; } - final type = targetType as InterfaceType; - final classElement = type.element; + final classElement = targetType.element; final fromJsonCtor = classElement.constructors - .singleWhere((ce) => ce.name == 'fromJson', orElse: () => null); + .singleWhereOrNull((ce) => ce.name == 'fromJson'); var output = expression; if (fromJsonCtor != null) { @@ -95,7 +95,7 @@ class JsonHelper extends TypeHelper { var asCastType = positionalParams.first.type; if (asCastType is InterfaceType) { - final instantiated = _instantiate(asCastType as InterfaceType, type); + final instantiated = _instantiate(asCastType, targetType); if (instantiated != null) { asCastType = instantiated; } @@ -108,15 +108,15 @@ class JsonHelper extends TypeHelper { ..._helperParams( context.deserialize, _decodeHelper, - targetType as InterfaceType, + targetType, positionalParams.skip(1), fromJsonCtor, ), ]; output = args.join(', '); - } else if (_annotation(context.config, type)?.createFactory == true) { - if (context.config.anyMap) { + } else if (_annotation(context.config, targetType)?.createFactory == true) { + if (context.config.anyMap!) { output += ' as Map'; } else { output += ' as Map'; @@ -135,7 +135,7 @@ class JsonHelper extends TypeHelper { } List _helperParams( - Object Function(DartType, String) execute, + Object? Function(DartType, String) execute, TypeParameterType Function(ParameterElement, Element) paramMapper, InterfaceType type, Iterable positionalParams, @@ -172,7 +172,7 @@ TypeParameterType _decodeHelper( type.normalParameterTypes.length == 1) { final funcReturnType = type.returnType; - if (param.name == fromJsonForName(funcReturnType.element.name)) { + if (param.name == fromJsonForName(funcReturnType.element!.name!)) { final funcParamType = type.normalParameterTypes.single; if ((funcParamType.isDartCoreObject && funcParamType.isNullableType) || @@ -203,7 +203,7 @@ TypeParameterType _encodeHelper( type.normalParameterTypes.length == 1) { final funcParamType = type.normalParameterTypes.single; - if (param.name == toJsonForName(funcParamType.element.name)) { + if (param.name == toJsonForName(funcParamType.element!.name!)) { if (funcParamType is TypeParameterType) { return funcParamType; } @@ -238,7 +238,7 @@ bool _canSerialize(JsonSerializable config, DartType type) { /// Returns an instantiation of [ctorParamType] by providing argument types /// derived by matching corresponding type parameters from [classType]. -InterfaceType _instantiate( +InterfaceType? _instantiate( InterfaceType ctorParamType, InterfaceType classType, ) { @@ -260,13 +260,13 @@ InterfaceType _instantiate( } return ctorParamType.element.instantiate( - typeArguments: argTypes, + typeArguments: argTypes.cast(), // TODO: not 100% sure nullabilitySuffix is right... Works for now nullabilitySuffix: NullabilitySuffix.none, ); } -JsonSerializable _annotation(JsonSerializable config, InterfaceType source) { +JsonSerializable? _annotation(JsonSerializable config, InterfaceType source) { final annotations = const TypeChecker.fromRuntime(JsonSerializable) .annotationsOfExact(source.element, throwOnUnresolved: false) .toList(); @@ -282,6 +282,6 @@ JsonSerializable _annotation(JsonSerializable config, InterfaceType source) { ); } -MethodElement _toJsonMethod(DartType type) => typeImplementations(type) +MethodElement? _toJsonMethod(DartType type) => typeImplementations(type) .map((dt) => dt is InterfaceType ? dt.getMethod('toJson') : null) - .firstWhere((me) => me != null, orElse: () => null); + .firstWhereOrNull((me) => me != null); diff --git a/json_serializable/lib/src/type_helpers/map_helper.dart b/json_serializable/lib/src/type_helpers/map_helper.dart index 5eb83300b..764cd89e9 100644 --- a/json_serializable/lib/src/type_helpers/map_helper.dart +++ b/json_serializable/lib/src/type_helpers/map_helper.dart @@ -3,6 +3,7 @@ // BSD-style license that can be found in the LICENSE file. import 'package:analyzer/dart/element/type.dart'; +import 'package:collection/collection.dart'; import '../constants.dart'; import '../shared_checkers.dart'; @@ -17,7 +18,7 @@ class MapHelper extends TypeHelper { const MapHelper(); @override - String serialize( + String? serialize( DartType targetType, String expression, TypeHelperContextWithConfig context, @@ -50,7 +51,7 @@ class MapHelper extends TypeHelper { } @override - String deserialize( + String? deserialize( DartType targetType, String expression, TypeHelperContextWithConfig context, @@ -76,7 +77,7 @@ class MapHelper extends TypeHelper { if (!isKeyStringable) { if (valueArgIsAny) { - if (context.config.anyMap) { + if (context.config.anyMap!) { if (isLikeDynamic(keyArg)) { return '$expression as Map$optionalQuestion'; } @@ -101,7 +102,7 @@ class MapHelper extends TypeHelper { final itemSubVal = context.deserialize(valueArg, closureArg); - var mapCast = context.config.anyMap ? 'as Map' : 'as Map'; + var mapCast = context.config.anyMap! ? 'as Map' : 'as Map'; if (targetTypeIsNullable) { mapCast += '?'; @@ -110,10 +111,10 @@ class MapHelper extends TypeHelper { String keyUsage; if (isEnum(keyArg)) { keyUsage = context.deserialize(keyArg, _keyParam).toString(); - } else if (context.config.anyMap && + } else if (context.config.anyMap! && !(keyArg.isDartCoreObject || keyArg.isDynamic)) { keyUsage = '$_keyParam as String'; - } else if (context.config.anyMap && + } else if (context.config.anyMap! && keyArg.isDartCoreObject && !keyArg.isNullableType) { keyUsage = '$_keyParam as Object'; @@ -123,7 +124,7 @@ class MapHelper extends TypeHelper { final toFromString = _forType(keyArg); if (toFromString != null) { - keyUsage = toFromString.deserialize(keyArg, keyUsage, false, true); + keyUsage = toFromString.deserialize(keyArg, keyUsage, false, true)!; } return '($expression $mapCast)$optionalQuestion.map( ' @@ -142,8 +143,8 @@ final _instances = [ uriString, ]; -ToFromStringHelper _forType(DartType type) => - _instances.singleWhere((i) => i.matches(type), orElse: () => null); +ToFromStringHelper? _forType(DartType type) => + _instances.singleWhereOrNull((i) => i.matches(type)); /// Returns `true` if [keyType] can be automatically converted to/from String – /// and is therefor usable as a key in a [Map]. diff --git a/json_serializable/lib/src/type_helpers/to_from_string.dart b/json_serializable/lib/src/type_helpers/to_from_string.dart index 7a5d94715..55f8aae7e 100644 --- a/json_serializable/lib/src/type_helpers/to_from_string.dart +++ b/json_serializable/lib/src/type_helpers/to_from_string.dart @@ -48,7 +48,7 @@ class ToFromStringHelper { bool matches(DartType type) => _checker.isExactlyType(type); - String serialize( + String? serialize( DartType type, String expression, bool nullable, @@ -64,7 +64,7 @@ class ToFromStringHelper { return '$expression.$_toString'; } - String deserialize( + String? deserialize( DartType type, String expression, bool nullable, diff --git a/json_serializable/lib/src/type_helpers/uri_helper.dart b/json_serializable/lib/src/type_helpers/uri_helper.dart index 2100812a5..28e40621e 100644 --- a/json_serializable/lib/src/type_helpers/uri_helper.dart +++ b/json_serializable/lib/src/type_helpers/uri_helper.dart @@ -12,7 +12,7 @@ class UriHelper extends TypeHelper { const UriHelper(); @override - String serialize( + String? serialize( DartType targetType, String expression, TypeHelperContext context, @@ -24,7 +24,7 @@ class UriHelper extends TypeHelper { ); @override - String deserialize( + String? deserialize( DartType targetType, String expression, TypeHelperContext context, diff --git a/json_serializable/lib/src/type_helpers/value_helper.dart b/json_serializable/lib/src/type_helpers/value_helper.dart index 0f9c0b43f..16719c656 100644 --- a/json_serializable/lib/src/type_helpers/value_helper.dart +++ b/json_serializable/lib/src/type_helpers/value_helper.dart @@ -13,7 +13,7 @@ class ValueHelper extends TypeHelper { const ValueHelper(); @override - String serialize( + String? serialize( DartType targetType, String expression, TypeHelperContext context, @@ -28,7 +28,7 @@ class ValueHelper extends TypeHelper { } @override - String deserialize( + String? deserialize( DartType targetType, String expression, TypeHelperContext context, diff --git a/json_serializable/lib/src/unsupported_type_error.dart b/json_serializable/lib/src/unsupported_type_error.dart index 3642cc2c4..4d9a00fb3 100644 --- a/json_serializable/lib/src/unsupported_type_error.dart +++ b/json_serializable/lib/src/unsupported_type_error.dart @@ -8,7 +8,7 @@ import 'package:analyzer/dart/element/type.dart'; /// [reason]. class UnsupportedTypeError extends Error { final DartType type; - final String reason; + final String? reason; /// Not currently accesses. Will likely be removed in a future release. final String expression; diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index 3b94f13bd..f397cdbb7 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -7,18 +7,17 @@ import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/nullability_suffix.dart'; import 'package:analyzer/dart/element/type.dart'; import 'package:json_annotation/json_annotation.dart'; -import 'package:meta/meta.dart' show alwaysThrows, required; import 'package:source_gen/source_gen.dart'; import 'helper_core.dart'; const _jsonKeyChecker = TypeChecker.fromRuntime(JsonKey); -DartObject _jsonKeyAnnotation(FieldElement element) => +DartObject? _jsonKeyAnnotation(FieldElement element) => _jsonKeyChecker.firstAnnotationOf(element) ?? (element.getter == null ? null - : _jsonKeyChecker.firstAnnotationOf(element.getter)); + : _jsonKeyChecker.firstAnnotationOf(element.getter!)); ConstantReader jsonKeyAnnotation(FieldElement element) => ConstantReader(_jsonKeyAnnotation(element)); @@ -43,7 +42,7 @@ String pascalCase(String input) { String _fixCase(String input, String separator) => input.replaceAllMapped(_upperCase, (match) { - var lower = match.group(0).toLowerCase(); + var lower = match.group(0)!.toLowerCase(); if (match.start > 0) { lower = '$separator$lower'; @@ -52,13 +51,12 @@ String _fixCase(String input, String separator) => return lower; }); -@alwaysThrows -void throwUnsupported(FieldElement element, String message) => +Never throwUnsupported(FieldElement element, String message) => throw InvalidGenerationSourceError( 'Error with `@JsonKey` on `${element.name}`. $message', element: element); -FieldRename _fromDartObject(ConstantReader reader) => reader.isNull +FieldRename? _fromDartObject(ConstantReader reader) => reader.isNull ? null : enumValueForDartObject( reader.objectValue, @@ -76,18 +74,18 @@ T enumValueForDartObject( /// Return an instance of [JsonSerializable] corresponding to a the provided /// [reader]. JsonSerializable _valueForAnnotation(ConstantReader reader) => JsonSerializable( - anyMap: reader.read('anyMap').literalValue as bool, - checked: reader.read('checked').literalValue as bool, - createFactory: reader.read('createFactory').literalValue as bool, - createToJson: reader.read('createToJson').literalValue as bool, + anyMap: reader.read('anyMap').literalValue as bool?, + checked: reader.read('checked').literalValue as bool?, + createFactory: reader.read('createFactory').literalValue as bool?, + createToJson: reader.read('createToJson').literalValue as bool?, disallowUnrecognizedKeys: - reader.read('disallowUnrecognizedKeys').literalValue as bool, - explicitToJson: reader.read('explicitToJson').literalValue as bool, + reader.read('disallowUnrecognizedKeys').literalValue as bool?, + explicitToJson: reader.read('explicitToJson').literalValue as bool?, fieldRename: _fromDartObject(reader.read('fieldRename')), genericArgumentFactories: - reader.read('genericArgumentFactories').literalValue as bool, - ignoreUnannotated: reader.read('ignoreUnannotated').literalValue as bool, - includeIfNull: reader.read('includeIfNull').literalValue as bool, + reader.read('genericArgumentFactories').literalValue as bool?, + ignoreUnannotated: reader.read('ignoreUnannotated').literalValue as bool?, + includeIfNull: reader.read('includeIfNull').literalValue as bool?, ); /// Returns a [JsonSerializable] with values from the [JsonSerializable] @@ -102,7 +100,7 @@ JsonSerializable _valueForAnnotation(ConstantReader reader) => JsonSerializable( JsonSerializable mergeConfig( JsonSerializable config, ConstantReader reader, { - @required ClassElement classElement, + required ClassElement classElement, }) { final annotation = _valueForAnnotation(reader); @@ -117,7 +115,7 @@ JsonSerializable mergeConfig( fieldRename: annotation.fieldRename ?? config.fieldRename, genericArgumentFactories: annotation.genericArgumentFactories ?? (classElement.typeParameters.isNotEmpty && - config.genericArgumentFactories), + config.genericArgumentFactories!), ignoreUnannotated: annotation.ignoreUnannotated ?? config.ignoreUnannotated, includeIfNull: annotation.includeIfNull ?? config.includeIfNull, ); @@ -137,7 +135,7 @@ final _enumMapExpando = Expando>(); /// used if it's set and not `null`. /// /// If [targetType] is not an enum, `null` is returned. -Map enumFieldsMap(DartType targetType) { +Map? enumFieldsMap(DartType targetType) { MapEntry _generateEntry(FieldElement fe) { final annotation = const TypeChecker.fromRuntime(JsonValue).firstAnnotationOfExact(fe); @@ -179,7 +177,7 @@ Map enumFieldsMap(DartType targetType) { /// with its values. /// /// Otherwise, `null`. -Iterable iterateEnumFields(DartType targetType) => +Iterable? iterateEnumFields(DartType targetType) => enumFieldsMap(targetType)?.keys; /// Returns a quoted String literal for [value] that can be used in generated @@ -191,7 +189,7 @@ String escapeDartString(String value) { var canBeRaw = true; value = value.replaceAllMapped(_escapeRegExp, (match) { - final value = match[0]; + final value = match[0]!; if (value == "'") { hasSingleQuote = true; return value; @@ -267,8 +265,8 @@ String _getHexLiteral(String input) { extension DartTypeExtension on DartType { bool isAssignableTo(DartType other) => // If the library is `null`, treat it like dynamic => `true` - element.library == null || - element.library.typeSystem.isAssignableTo(this, other); + element!.library == null || + element!.library!.typeSystem.isAssignableTo(this, other); } extension TypeExtension on DartType { diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index c00ac598b..d823cca4b 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 4.0.3 +version: 5.0.0-dev description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. @@ -7,30 +7,34 @@ repository: https://github.com/google/json_serializable.dart/tree/master/json_se environment: # Keeping this <2.12.0 because the code is not null safe – yet! # https://github.com/google/json_serializable.dart/issues/821 - sdk: '>=2.11.99 <3.0.0' + sdk: '>=2.12.0 <3.0.0' dependencies: analyzer: '>=0.41.2 <2.0.0' build: ^2.0.0 build_config: ^0.4.4 + collection: ^1.14.0 # Use a tight version constraint to ensure that a constraint on # `json_annotation` properly constrains all features it provides. # For v3 only – allow a wide range since the only change was to REMOVE things # from json_annotation - json_annotation: '>=4.0.0 <4.1.0' + json_annotation: '>=4.0.1 <4.1.0' meta: ^1.3.0 path: ^1.8.0 - source_gen: ^0.9.9 + source_gen: ^1.0.0 dev_dependencies: build_runner: ^1.0.0 build_verify: ^2.0.0 - collection: ^1.14.0 - dart_style: ^1.2.0 + dart_style: ^2.0.0 logging: ^1.0.0 pub_semver: ^2.0.0 - source_gen_test: ^0.1.0 + source_gen_test: ^1.0.0 stack_trace: ^1.10.0 test: ^1.16.0 yaml: ^3.0.0 + +dependency_overrides: + json_annotation: + path: ../json_annotation diff --git a/json_serializable/test/config_test.dart b/json_serializable/test/config_test.dart index 7356a47f6..065aead27 100644 --- a/json_serializable/test/config_test.dart +++ b/json_serializable/test/config_test.dart @@ -114,7 +114,7 @@ void main() { final lastLine = entry.key == 'field_rename' ? '`42` is not one of the supported values: none, kebab, snake, ' 'pascal' - : "type 'int' is not a subtype of type 'bool' in type cast"; + : "type 'int' is not a subtype of type 'bool?' in type cast"; final matcher = isA().having( (v) => v.message, diff --git a/json_serializable/test/custom_configuration_test.dart b/json_serializable/test/custom_configuration_test.dart index 02a04cf1b..e9d9ab19d 100644 --- a/json_serializable/test/custom_configuration_test.dart +++ b/json_serializable/test/custom_configuration_test.dart @@ -18,7 +18,7 @@ import 'package:test/test.dart'; import 'shared_config.dart'; -LibraryReader _libraryReader; +late LibraryReader _libraryReader; Future main() async { initializeBuildLogTracking(); @@ -36,7 +36,7 @@ Future main() async { group('configuration', () { Future runWithConfigAndLogger( - JsonSerializable config, String className) async { + JsonSerializable? config, String className) async { await generateForElement( JsonSerializableGenerator( config: config, typeHelpers: const [_ConfigLogger()]), @@ -214,7 +214,7 @@ class _ConfigLogger implements TypeHelper { const _ConfigLogger(); @override - Object deserialize( + Object? deserialize( DartType targetType, String expression, TypeHelperContextWithConfig context, @@ -225,7 +225,7 @@ class _ConfigLogger implements TypeHelper { } @override - Object serialize(DartType targetType, String expression, + Object? serialize(DartType targetType, String expression, TypeHelperContextWithConfig context) { configurations.add(context.config); return null; diff --git a/json_serializable/test/default_value/default_value.dart b/json_serializable/test/default_value/default_value.dart index 84f1b972e..27eda4ea6 100644 --- a/json_serializable/test/default_value/default_value.dart +++ b/json_serializable/test/default_value/default_value.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.12 - // ignore_for_file: annotate_overrides import 'package:json_annotation/json_annotation.dart'; diff --git a/json_serializable/test/default_value/default_value.g.dart b/json_serializable/test/default_value/default_value.g.dart index 0c29c64b8..fbf121f1d 100644 --- a/json_serializable/test/default_value/default_value.g.dart +++ b/json_serializable/test/default_value/default_value.g.dart @@ -1,5 +1,4 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// @dart=2.12 part of 'default_value.dart'; diff --git a/json_serializable/test/default_value/default_value.g_any_map__checked.dart b/json_serializable/test/default_value/default_value.g_any_map__checked.dart index 615505145..9c345aef1 100644 --- a/json_serializable/test/default_value/default_value.g_any_map__checked.dart +++ b/json_serializable/test/default_value/default_value.g_any_map__checked.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.12 - // ignore_for_file: annotate_overrides import 'package:json_annotation/json_annotation.dart'; diff --git a/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart b/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart index 5aa38d430..678bab817 100644 --- a/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart +++ b/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart @@ -1,5 +1,4 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// @dart=2.12 part of 'default_value.g_any_map__checked.dart'; diff --git a/json_serializable/test/default_value/default_value_interface.dart b/json_serializable/test/default_value/default_value_interface.dart index 65076e6eb..06bc33408 100644 --- a/json_serializable/test/default_value/default_value_interface.dart +++ b/json_serializable/test/default_value/default_value_interface.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.12 - abstract class DefaultValue { bool fieldBool; String fieldString; diff --git a/json_serializable/test/default_value/default_value_test.dart b/json_serializable/test/default_value/default_value_test.dart index 8a0a83ff1..00ef236ad 100644 --- a/json_serializable/test/default_value/default_value_test.dart +++ b/json_serializable/test/default_value/default_value_test.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.12 - import 'package:test/test.dart'; import '../test_utils.dart'; diff --git a/json_serializable/test/generic_files/generic_argument_factories.dart b/json_serializable/test/generic_files/generic_argument_factories.dart index c45ebf081..0ebb09d69 100644 --- a/json_serializable/test/generic_files/generic_argument_factories.dart +++ b/json_serializable/test/generic_files/generic_argument_factories.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.12 - import 'package:json_annotation/json_annotation.dart'; part 'generic_argument_factories.g.dart'; diff --git a/json_serializable/test/generic_files/generic_argument_factories.g.dart b/json_serializable/test/generic_files/generic_argument_factories.g.dart index 49ba5d532..da41c86ff 100644 --- a/json_serializable/test/generic_files/generic_argument_factories.g.dart +++ b/json_serializable/test/generic_files/generic_argument_factories.g.dart @@ -1,5 +1,4 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// @dart=2.12 part of 'generic_argument_factories.dart'; diff --git a/json_serializable/test/generic_files/generic_class.dart b/json_serializable/test/generic_files/generic_class.dart index 4b55add02..bf47a098d 100644 --- a/json_serializable/test/generic_files/generic_class.dart +++ b/json_serializable/test/generic_files/generic_class.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.12 - import 'package:json_annotation/json_annotation.dart'; part 'generic_class.g.dart'; diff --git a/json_serializable/test/generic_files/generic_class.g.dart b/json_serializable/test/generic_files/generic_class.g.dart index 2ef18b32d..d1fb01b0f 100644 --- a/json_serializable/test/generic_files/generic_class.g.dart +++ b/json_serializable/test/generic_files/generic_class.g.dart @@ -1,5 +1,4 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// @dart=2.12 part of 'generic_class.dart'; diff --git a/json_serializable/test/generic_files/generic_test.dart b/json_serializable/test/generic_files/generic_test.dart index b9e62c090..98b7e770b 100644 --- a/json_serializable/test/generic_files/generic_test.dart +++ b/json_serializable/test/generic_files/generic_test.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.12 - import 'dart:convert'; import 'package:test/test.dart'; diff --git a/json_serializable/test/integration/integration_test.dart b/json_serializable/test/integration/integration_test.dart index 58379af97..c86f4ffbf 100644 --- a/json_serializable/test/integration/integration_test.dart +++ b/json_serializable/test/integration/integration_test.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.12 - import 'package:test/test.dart'; import '../test_utils.dart'; diff --git a/json_serializable/test/integration/json_test_common.dart b/json_serializable/test/integration/json_test_common.dart index 931d0ca14..6cd110a4d 100644 --- a/json_serializable/test/integration/json_test_common.dart +++ b/json_serializable/test/integration/json_test_common.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.12 - import 'dart:collection'; import 'package:collection/collection.dart'; diff --git a/json_serializable/test/integration/json_test_example.dart b/json_serializable/test/integration/json_test_example.dart index 4a1fcec0f..6a30846fe 100644 --- a/json_serializable/test/integration/json_test_example.dart +++ b/json_serializable/test/integration/json_test_example.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.12 - // ignore_for_file: hash_and_equals import 'dart:collection'; diff --git a/json_serializable/test/integration/json_test_example.g.dart b/json_serializable/test/integration/json_test_example.g.dart index a9f5d28e2..da899ac94 100644 --- a/json_serializable/test/integration/json_test_example.g.dart +++ b/json_serializable/test/integration/json_test_example.g.dart @@ -1,5 +1,4 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// @dart=2.12 part of 'json_test_example.dart'; diff --git a/json_serializable/test/integration/json_test_example.g_any_map.dart b/json_serializable/test/integration/json_test_example.g_any_map.dart index 1796bd37f..c61b891bc 100644 --- a/json_serializable/test/integration/json_test_example.g_any_map.dart +++ b/json_serializable/test/integration/json_test_example.g_any_map.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.12 - // ignore_for_file: hash_and_equals import 'dart:collection'; diff --git a/json_serializable/test/integration/json_test_example.g_any_map.g.dart b/json_serializable/test/integration/json_test_example.g_any_map.g.dart index ef4a6566d..bfa0c1378 100644 --- a/json_serializable/test/integration/json_test_example.g_any_map.g.dart +++ b/json_serializable/test/integration/json_test_example.g_any_map.g.dart @@ -1,5 +1,4 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// @dart=2.12 part of 'json_test_example.g_any_map.dart'; diff --git a/json_serializable/test/kitchen_sink/json_converters.dart b/json_serializable/test/kitchen_sink/json_converters.dart index c5074416f..aefb246d2 100644 --- a/json_serializable/test/kitchen_sink/json_converters.dart +++ b/json_serializable/test/kitchen_sink/json_converters.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.12 - import 'package:json_annotation/json_annotation.dart'; class GenericConverter implements JsonConverter> { diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.dart b/json_serializable/test/kitchen_sink/kitchen_sink.dart index 113fe5e84..d846eee3d 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.12 - // ignore_for_file: annotate_overrides, hash_and_equals import 'package:json_annotation/json_annotation.dart'; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.factories.dart b/json_serializable/test/kitchen_sink/kitchen_sink.factories.dart index 3c26454da..863afa9bb 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.factories.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.factories.dart @@ -1,5 +1,4 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// @dart=2.12 import 'kitchen_sink.dart' as normal; import 'kitchen_sink.g_any_map.dart' as any_map; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g.dart index 027129a3a..03a894f51 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g.dart @@ -1,5 +1,4 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// @dart=2.12 part of 'kitchen_sink.dart'; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart index 5d0ce3fbe..5db543802 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.12 - // ignore_for_file: annotate_overrides, hash_and_equals import 'package:json_annotation/json_annotation.dart'; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart index 0c88a1cbd..01b13ef4b 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart @@ -1,5 +1,4 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// @dart=2.12 part of 'kitchen_sink.g_any_map.dart'; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.dart index 0c751950d..4782d07a7 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.12 - // ignore_for_file: annotate_overrides, hash_and_equals import 'package:json_annotation/json_annotation.dart'; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.g.dart index 3ff15a43b..42562e25a 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.g.dart @@ -1,5 +1,4 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// @dart=2.12 part of 'kitchen_sink.g_any_map__checked.dart'; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.dart index 70c60859b..7456d12cd 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.12 - // ignore_for_file: annotate_overrides, hash_and_equals import 'package:json_annotation/json_annotation.dart'; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart index fdc362702..095cd3892 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart @@ -1,5 +1,4 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// @dart=2.12 part of 'kitchen_sink.g_exclude_null.dart'; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.dart index 6bc665612..8f2875f59 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.12 - // ignore_for_file: annotate_overrides, hash_and_equals import 'package:json_annotation/json_annotation.dart'; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart index 9dda090c9..24e14ac64 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart @@ -1,5 +1,4 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// @dart=2.12 part of 'kitchen_sink.g_explicit_to_json.dart'; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart b/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart index 2473ca1df..357085e5c 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.12 - import 'package:collection/collection.dart'; import 'simple_object.dart'; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink_test.dart b/json_serializable/test/kitchen_sink/kitchen_sink_test.dart index 3950b66fa..b8566a9e5 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink_test.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink_test.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.12 - import 'package:json_annotation/json_annotation.dart'; import 'package:test/test.dart'; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink_test_shared.dart b/json_serializable/test/kitchen_sink/kitchen_sink_test_shared.dart index 4b1b60bc0..f69535d6a 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink_test_shared.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink_test_shared.dart @@ -1,5 +1,3 @@ -// @dart=2.12 - import 'package:json_annotation/json_annotation.dart'; import 'package:test/test.dart'; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink_yaml_test.dart b/json_serializable/test/kitchen_sink/kitchen_sink_yaml_test.dart index 55846778d..f9a09b521 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink_yaml_test.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink_yaml_test.dart @@ -1,5 +1,3 @@ -// @dart=2.12 - import 'package:json_annotation/json_annotation.dart'; import 'package:test/test.dart'; import 'package:yaml/yaml.dart'; diff --git a/json_serializable/test/kitchen_sink/simple_object.dart b/json_serializable/test/kitchen_sink/simple_object.dart index b5816fc29..c02cefc31 100644 --- a/json_serializable/test/kitchen_sink/simple_object.dart +++ b/json_serializable/test/kitchen_sink/simple_object.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.12 - import 'package:json_annotation/json_annotation.dart'; part 'simple_object.g.dart'; diff --git a/json_serializable/test/kitchen_sink/simple_object.g.dart b/json_serializable/test/kitchen_sink/simple_object.g.dart index ad76883f5..42d584b69 100644 --- a/json_serializable/test/kitchen_sink/simple_object.g.dart +++ b/json_serializable/test/kitchen_sink/simple_object.g.dart @@ -1,5 +1,4 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// @dart=2.12 part of 'simple_object.dart'; diff --git a/json_serializable/test/kitchen_sink/strict_keys_object.dart b/json_serializable/test/kitchen_sink/strict_keys_object.dart index bc54f9ba8..757f3eb5c 100644 --- a/json_serializable/test/kitchen_sink/strict_keys_object.dart +++ b/json_serializable/test/kitchen_sink/strict_keys_object.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.12 - import 'package:json_annotation/json_annotation.dart'; part 'strict_keys_object.g.dart'; diff --git a/json_serializable/test/kitchen_sink/strict_keys_object.g.dart b/json_serializable/test/kitchen_sink/strict_keys_object.g.dart index 50dd9e5d6..dfdda8eaa 100644 --- a/json_serializable/test/kitchen_sink/strict_keys_object.g.dart +++ b/json_serializable/test/kitchen_sink/strict_keys_object.g.dart @@ -1,5 +1,4 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// @dart=2.12 part of 'strict_keys_object.dart'; diff --git a/json_serializable/test/readme_test.dart b/json_serializable/test/readme_test.dart index c11c50a98..24c1be8b9 100644 --- a/json_serializable/test/readme_test.dart +++ b/json_serializable/test/readme_test.dart @@ -9,7 +9,7 @@ import 'package:path/path.dart' as p; import 'package:test/test.dart'; void main() { - String readmeContent; + late String readmeContent; setUpAll(() { readmeContent = File('README.md').readAsStringSync(); diff --git a/json_serializable/test/src/_json_serializable_test_input.dart b/json_serializable/test/src/_json_serializable_test_input.dart index 7ba5c0f3f..81e6b03b7 100644 --- a/json_serializable/test/src/_json_serializable_test_input.dart +++ b/json_serializable/test/src/_json_serializable_test_input.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.12 - import 'dart:collection'; import 'package:json_annotation/json_annotation.dart'; diff --git a/json_serializable/test/src/checked_test_input.dart b/json_serializable/test/src/checked_test_input.dart index 7d3d17238..9a87630c5 100644 --- a/json_serializable/test/src/checked_test_input.dart +++ b/json_serializable/test/src/checked_test_input.dart @@ -1,5 +1,3 @@ -// @dart=2.12 - part of '_json_serializable_test_input.dart'; @ShouldGenerate(r''' diff --git a/json_serializable/test/src/constants_copy.dart b/json_serializable/test/src/constants_copy.dart index 27b33fb51..a4b0f1086 100644 --- a/json_serializable/test/src/constants_copy.dart +++ b/json_serializable/test/src/constants_copy.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.12 - part of '_json_serializable_test_input.dart'; // TODO: remove this and return link to lib/src/constants.dart once this diff --git a/json_serializable/test/src/core_subclass_type_input.dart b/json_serializable/test/src/core_subclass_type_input.dart index 8f58465cc..02b889a2c 100644 --- a/json_serializable/test/src/core_subclass_type_input.dart +++ b/json_serializable/test/src/core_subclass_type_input.dart @@ -1,5 +1,3 @@ -// @dart=2.12 - part of '_json_serializable_test_input.dart'; @ShouldThrow( diff --git a/json_serializable/test/src/default_value_input.dart b/json_serializable/test/src/default_value_input.dart index aca8e90dd..f15739b2f 100644 --- a/json_serializable/test/src/default_value_input.dart +++ b/json_serializable/test/src/default_value_input.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.12 - part of '_json_serializable_test_input.dart'; @ShouldThrow( diff --git a/json_serializable/test/src/field_namer_input.dart b/json_serializable/test/src/field_namer_input.dart index 1a0cb07ca..5f8bc6011 100644 --- a/json_serializable/test/src/field_namer_input.dart +++ b/json_serializable/test/src/field_namer_input.dart @@ -1,5 +1,3 @@ -// @dart=2.12 - part of '_json_serializable_test_input.dart'; @ShouldGenerate(r''' diff --git a/json_serializable/test/src/generic_test_input.dart b/json_serializable/test/src/generic_test_input.dart index e60c395e9..1a3b98466 100644 --- a/json_serializable/test/src/generic_test_input.dart +++ b/json_serializable/test/src/generic_test_input.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.12 - part of '_json_serializable_test_input.dart'; @ShouldThrow( diff --git a/json_serializable/test/src/inheritance_test_input.dart b/json_serializable/test/src/inheritance_test_input.dart index 5d0294408..c853be117 100644 --- a/json_serializable/test/src/inheritance_test_input.dart +++ b/json_serializable/test/src/inheritance_test_input.dart @@ -1,5 +1,3 @@ -// @dart=2.12 - part of '_json_serializable_test_input.dart'; @ShouldGenerate(r''' diff --git a/json_serializable/test/src/json_converter_test_input.dart b/json_serializable/test/src/json_converter_test_input.dart index df58ecd00..9086bccff 100644 --- a/json_serializable/test/src/json_converter_test_input.dart +++ b/json_serializable/test/src/json_converter_test_input.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.12 - part of '_json_serializable_test_input.dart'; @ShouldGenerate(r''' diff --git a/json_serializable/test/src/map_key_variety_test_input.dart b/json_serializable/test/src/map_key_variety_test_input.dart index 4f022d58a..68504cd76 100644 --- a/json_serializable/test/src/map_key_variety_test_input.dart +++ b/json_serializable/test/src/map_key_variety_test_input.dart @@ -1,5 +1,3 @@ -// @dart=2.12 - part of '_json_serializable_test_input.dart'; @ShouldGenerate(r''' diff --git a/json_serializable/test/src/setter_test_input.dart b/json_serializable/test/src/setter_test_input.dart index 9fe2d890e..b951dfeb5 100644 --- a/json_serializable/test/src/setter_test_input.dart +++ b/json_serializable/test/src/setter_test_input.dart @@ -1,5 +1,3 @@ -// @dart=2.12 - part of '_json_serializable_test_input.dart'; @ShouldGenerate( diff --git a/json_serializable/test/src/to_from_json_test_input.dart b/json_serializable/test/src/to_from_json_test_input.dart index 321146901..40c997e3a 100644 --- a/json_serializable/test/src/to_from_json_test_input.dart +++ b/json_serializable/test/src/to_from_json_test_input.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.12 - part of '_json_serializable_test_input.dart'; int _toInt(bool input) => 42; diff --git a/json_serializable/test/src/unknown_enum_value_test_input.dart b/json_serializable/test/src/unknown_enum_value_test_input.dart index 0f6907087..ea238231d 100644 --- a/json_serializable/test/src/unknown_enum_value_test_input.dart +++ b/json_serializable/test/src/unknown_enum_value_test_input.dart @@ -1,5 +1,3 @@ -// @dart=2.12 - part of '_json_serializable_test_input.dart'; @ShouldGenerate( diff --git a/json_serializable/test/supported_types/enum_type.dart b/json_serializable/test/supported_types/enum_type.dart index a0f9c2191..360a6bf8e 100644 --- a/json_serializable/test/supported_types/enum_type.dart +++ b/json_serializable/test/supported_types/enum_type.dart @@ -2,6 +2,4 @@ // 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. -// @dart=2.12 - enum EnumType { alpha, beta, gamma, delta } diff --git a/json_serializable/test/supported_types/input.dart b/json_serializable/test/supported_types/input.dart index 2319b01c0..8a43e9fcc 100644 --- a/json_serializable/test/supported_types/input.dart +++ b/json_serializable/test/supported_types/input.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.12 - import 'package:json_annotation/json_annotation.dart'; part 'input.g.dart'; diff --git a/json_serializable/test/supported_types/input.g.dart b/json_serializable/test/supported_types/input.g.dart index 65367bf60..3effa4548 100644 --- a/json_serializable/test/supported_types/input.g.dart +++ b/json_serializable/test/supported_types/input.g.dart @@ -1,5 +1,4 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// @dart=2.12 part of 'input.dart'; diff --git a/json_serializable/test/supported_types/input.type_bigint.dart b/json_serializable/test/supported_types/input.type_bigint.dart index 25005752e..07ab37ba4 100644 --- a/json_serializable/test/supported_types/input.type_bigint.dart +++ b/json_serializable/test/supported_types/input.type_bigint.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.12 - import 'package:json_annotation/json_annotation.dart'; part 'input.type_bigint.g.dart'; diff --git a/json_serializable/test/supported_types/input.type_bigint.g.dart b/json_serializable/test/supported_types/input.type_bigint.g.dart index c03d1ed5f..c22bc2d85 100644 --- a/json_serializable/test/supported_types/input.type_bigint.g.dart +++ b/json_serializable/test/supported_types/input.type_bigint.g.dart @@ -1,5 +1,4 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// @dart=2.12 part of 'input.type_bigint.dart'; diff --git a/json_serializable/test/supported_types/input.type_bool.dart b/json_serializable/test/supported_types/input.type_bool.dart index 9d898ba07..e3fd6078c 100644 --- a/json_serializable/test/supported_types/input.type_bool.dart +++ b/json_serializable/test/supported_types/input.type_bool.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.12 - import 'package:json_annotation/json_annotation.dart'; part 'input.type_bool.g.dart'; diff --git a/json_serializable/test/supported_types/input.type_bool.g.dart b/json_serializable/test/supported_types/input.type_bool.g.dart index 04a942e20..3a793eccc 100644 --- a/json_serializable/test/supported_types/input.type_bool.g.dart +++ b/json_serializable/test/supported_types/input.type_bool.g.dart @@ -1,5 +1,4 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// @dart=2.12 part of 'input.type_bool.dart'; diff --git a/json_serializable/test/supported_types/input.type_datetime.dart b/json_serializable/test/supported_types/input.type_datetime.dart index cc992713e..880c7ce89 100644 --- a/json_serializable/test/supported_types/input.type_datetime.dart +++ b/json_serializable/test/supported_types/input.type_datetime.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.12 - import 'package:json_annotation/json_annotation.dart'; part 'input.type_datetime.g.dart'; diff --git a/json_serializable/test/supported_types/input.type_datetime.g.dart b/json_serializable/test/supported_types/input.type_datetime.g.dart index b98a2c17d..2f3d8bd9a 100644 --- a/json_serializable/test/supported_types/input.type_datetime.g.dart +++ b/json_serializable/test/supported_types/input.type_datetime.g.dart @@ -1,5 +1,4 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// @dart=2.12 part of 'input.type_datetime.dart'; diff --git a/json_serializable/test/supported_types/input.type_double.dart b/json_serializable/test/supported_types/input.type_double.dart index e2074ddcd..c51a0e35b 100644 --- a/json_serializable/test/supported_types/input.type_double.dart +++ b/json_serializable/test/supported_types/input.type_double.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.12 - import 'package:json_annotation/json_annotation.dart'; part 'input.type_double.g.dart'; diff --git a/json_serializable/test/supported_types/input.type_double.g.dart b/json_serializable/test/supported_types/input.type_double.g.dart index 00d0e424b..1ff5d3cb2 100644 --- a/json_serializable/test/supported_types/input.type_double.g.dart +++ b/json_serializable/test/supported_types/input.type_double.g.dart @@ -1,5 +1,4 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// @dart=2.12 part of 'input.type_double.dart'; diff --git a/json_serializable/test/supported_types/input.type_duration.dart b/json_serializable/test/supported_types/input.type_duration.dart index aa4c716e4..7ecdef825 100644 --- a/json_serializable/test/supported_types/input.type_duration.dart +++ b/json_serializable/test/supported_types/input.type_duration.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.12 - import 'package:json_annotation/json_annotation.dart'; part 'input.type_duration.g.dart'; diff --git a/json_serializable/test/supported_types/input.type_duration.g.dart b/json_serializable/test/supported_types/input.type_duration.g.dart index 5d7f2f45f..d2a77f769 100644 --- a/json_serializable/test/supported_types/input.type_duration.g.dart +++ b/json_serializable/test/supported_types/input.type_duration.g.dart @@ -1,5 +1,4 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// @dart=2.12 part of 'input.type_duration.dart'; diff --git a/json_serializable/test/supported_types/input.type_enumtype.dart b/json_serializable/test/supported_types/input.type_enumtype.dart index 14c28a906..9225db715 100644 --- a/json_serializable/test/supported_types/input.type_enumtype.dart +++ b/json_serializable/test/supported_types/input.type_enumtype.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.12 - import 'package:json_annotation/json_annotation.dart'; import 'enum_type.dart'; diff --git a/json_serializable/test/supported_types/input.type_enumtype.g.dart b/json_serializable/test/supported_types/input.type_enumtype.g.dart index 547664f35..7233add35 100644 --- a/json_serializable/test/supported_types/input.type_enumtype.g.dart +++ b/json_serializable/test/supported_types/input.type_enumtype.g.dart @@ -1,5 +1,4 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// @dart=2.12 part of 'input.type_enumtype.dart'; diff --git a/json_serializable/test/supported_types/input.type_int.dart b/json_serializable/test/supported_types/input.type_int.dart index 0a2614f22..6d80dc79c 100644 --- a/json_serializable/test/supported_types/input.type_int.dart +++ b/json_serializable/test/supported_types/input.type_int.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.12 - import 'package:json_annotation/json_annotation.dart'; part 'input.type_int.g.dart'; diff --git a/json_serializable/test/supported_types/input.type_int.g.dart b/json_serializable/test/supported_types/input.type_int.g.dart index 48295e2b7..c4695d106 100644 --- a/json_serializable/test/supported_types/input.type_int.g.dart +++ b/json_serializable/test/supported_types/input.type_int.g.dart @@ -1,5 +1,4 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// @dart=2.12 part of 'input.type_int.dart'; diff --git a/json_serializable/test/supported_types/input.type_iterable.dart b/json_serializable/test/supported_types/input.type_iterable.dart index a90c4d99c..1471dc935 100644 --- a/json_serializable/test/supported_types/input.type_iterable.dart +++ b/json_serializable/test/supported_types/input.type_iterable.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.12 - import 'package:json_annotation/json_annotation.dart'; import 'enum_type.dart'; diff --git a/json_serializable/test/supported_types/input.type_iterable.g.dart b/json_serializable/test/supported_types/input.type_iterable.g.dart index e0b5389ad..97766b6b8 100644 --- a/json_serializable/test/supported_types/input.type_iterable.g.dart +++ b/json_serializable/test/supported_types/input.type_iterable.g.dart @@ -1,5 +1,4 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// @dart=2.12 part of 'input.type_iterable.dart'; diff --git a/json_serializable/test/supported_types/input.type_list.dart b/json_serializable/test/supported_types/input.type_list.dart index 657d45296..41f35fe72 100644 --- a/json_serializable/test/supported_types/input.type_list.dart +++ b/json_serializable/test/supported_types/input.type_list.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.12 - import 'package:json_annotation/json_annotation.dart'; import 'enum_type.dart'; diff --git a/json_serializable/test/supported_types/input.type_list.g.dart b/json_serializable/test/supported_types/input.type_list.g.dart index 9c1b1a63c..bd7eeb756 100644 --- a/json_serializable/test/supported_types/input.type_list.g.dart +++ b/json_serializable/test/supported_types/input.type_list.g.dart @@ -1,5 +1,4 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// @dart=2.12 part of 'input.type_list.dart'; diff --git a/json_serializable/test/supported_types/input.type_map.dart b/json_serializable/test/supported_types/input.type_map.dart index 74243a4b1..bdf45e336 100644 --- a/json_serializable/test/supported_types/input.type_map.dart +++ b/json_serializable/test/supported_types/input.type_map.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.12 - import 'package:json_annotation/json_annotation.dart'; import 'enum_type.dart'; diff --git a/json_serializable/test/supported_types/input.type_map.g.dart b/json_serializable/test/supported_types/input.type_map.g.dart index dfa1c2f7b..55608e727 100644 --- a/json_serializable/test/supported_types/input.type_map.g.dart +++ b/json_serializable/test/supported_types/input.type_map.g.dart @@ -1,5 +1,4 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// @dart=2.12 part of 'input.type_map.dart'; diff --git a/json_serializable/test/supported_types/input.type_num.dart b/json_serializable/test/supported_types/input.type_num.dart index 5e9657066..57631ce62 100644 --- a/json_serializable/test/supported_types/input.type_num.dart +++ b/json_serializable/test/supported_types/input.type_num.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.12 - import 'package:json_annotation/json_annotation.dart'; part 'input.type_num.g.dart'; diff --git a/json_serializable/test/supported_types/input.type_num.g.dart b/json_serializable/test/supported_types/input.type_num.g.dart index d91fb9d68..0456261f1 100644 --- a/json_serializable/test/supported_types/input.type_num.g.dart +++ b/json_serializable/test/supported_types/input.type_num.g.dart @@ -1,5 +1,4 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// @dart=2.12 part of 'input.type_num.dart'; diff --git a/json_serializable/test/supported_types/input.type_object.dart b/json_serializable/test/supported_types/input.type_object.dart index fb0c2e860..193bd440a 100644 --- a/json_serializable/test/supported_types/input.type_object.dart +++ b/json_serializable/test/supported_types/input.type_object.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.12 - import 'package:json_annotation/json_annotation.dart'; part 'input.type_object.g.dart'; diff --git a/json_serializable/test/supported_types/input.type_object.g.dart b/json_serializable/test/supported_types/input.type_object.g.dart index 973229f41..691a85539 100644 --- a/json_serializable/test/supported_types/input.type_object.g.dart +++ b/json_serializable/test/supported_types/input.type_object.g.dart @@ -1,5 +1,4 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// @dart=2.12 part of 'input.type_object.dart'; diff --git a/json_serializable/test/supported_types/input.type_set.dart b/json_serializable/test/supported_types/input.type_set.dart index ea7eacd67..8e74fb7c2 100644 --- a/json_serializable/test/supported_types/input.type_set.dart +++ b/json_serializable/test/supported_types/input.type_set.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.12 - import 'package:json_annotation/json_annotation.dart'; import 'enum_type.dart'; diff --git a/json_serializable/test/supported_types/input.type_set.g.dart b/json_serializable/test/supported_types/input.type_set.g.dart index 43bf51e4a..32e27b0e6 100644 --- a/json_serializable/test/supported_types/input.type_set.g.dart +++ b/json_serializable/test/supported_types/input.type_set.g.dart @@ -1,5 +1,4 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// @dart=2.12 part of 'input.type_set.dart'; diff --git a/json_serializable/test/supported_types/input.type_string.dart b/json_serializable/test/supported_types/input.type_string.dart index 1131e9556..d199b13c0 100644 --- a/json_serializable/test/supported_types/input.type_string.dart +++ b/json_serializable/test/supported_types/input.type_string.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.12 - import 'package:json_annotation/json_annotation.dart'; part 'input.type_string.g.dart'; diff --git a/json_serializable/test/supported_types/input.type_string.g.dart b/json_serializable/test/supported_types/input.type_string.g.dart index 55ff7b924..54ef11b44 100644 --- a/json_serializable/test/supported_types/input.type_string.g.dart +++ b/json_serializable/test/supported_types/input.type_string.g.dart @@ -1,5 +1,4 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// @dart=2.12 part of 'input.type_string.dart'; diff --git a/json_serializable/test/supported_types/input.type_uri.dart b/json_serializable/test/supported_types/input.type_uri.dart index 15b2c39f0..fe625bbff 100644 --- a/json_serializable/test/supported_types/input.type_uri.dart +++ b/json_serializable/test/supported_types/input.type_uri.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.12 - import 'package:json_annotation/json_annotation.dart'; part 'input.type_uri.g.dart'; diff --git a/json_serializable/test/supported_types/input.type_uri.g.dart b/json_serializable/test/supported_types/input.type_uri.g.dart index d0d8e1daf..8392c64b3 100644 --- a/json_serializable/test/supported_types/input.type_uri.g.dart +++ b/json_serializable/test/supported_types/input.type_uri.g.dart @@ -1,5 +1,4 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// @dart=2.12 part of 'input.type_uri.dart'; diff --git a/json_serializable/test/supported_types/type_test.bigint_test.dart b/json_serializable/test/supported_types/type_test.bigint_test.dart index 969cadb27..c012ea507 100644 --- a/json_serializable/test/supported_types/type_test.bigint_test.dart +++ b/json_serializable/test/supported_types/type_test.bigint_test.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.12 - // ignore_for_file: prefer_const_declarations import 'dart:convert'; diff --git a/json_serializable/test/supported_types/type_test.bool_test.dart b/json_serializable/test/supported_types/type_test.bool_test.dart index 31e4f7971..14e24853b 100644 --- a/json_serializable/test/supported_types/type_test.bool_test.dart +++ b/json_serializable/test/supported_types/type_test.bool_test.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.12 - // ignore_for_file: prefer_const_declarations import 'dart:convert'; diff --git a/json_serializable/test/supported_types/type_test.dart b/json_serializable/test/supported_types/type_test.dart index 4cafc262b..625b8e3c4 100644 --- a/json_serializable/test/supported_types/type_test.dart +++ b/json_serializable/test/supported_types/type_test.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.12 - // ignore_for_file: prefer_const_declarations import 'dart:convert'; diff --git a/json_serializable/test/supported_types/type_test.datetime_test.dart b/json_serializable/test/supported_types/type_test.datetime_test.dart index 742529c2a..597bbf680 100644 --- a/json_serializable/test/supported_types/type_test.datetime_test.dart +++ b/json_serializable/test/supported_types/type_test.datetime_test.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.12 - // ignore_for_file: prefer_const_declarations import 'dart:convert'; diff --git a/json_serializable/test/supported_types/type_test.double_test.dart b/json_serializable/test/supported_types/type_test.double_test.dart index c718f6c11..3e4c05acf 100644 --- a/json_serializable/test/supported_types/type_test.double_test.dart +++ b/json_serializable/test/supported_types/type_test.double_test.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.12 - // ignore_for_file: prefer_const_declarations import 'dart:convert'; diff --git a/json_serializable/test/supported_types/type_test.duration_test.dart b/json_serializable/test/supported_types/type_test.duration_test.dart index ee91fd475..76816e9fc 100644 --- a/json_serializable/test/supported_types/type_test.duration_test.dart +++ b/json_serializable/test/supported_types/type_test.duration_test.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.12 - // ignore_for_file: prefer_const_declarations import 'dart:convert'; diff --git a/json_serializable/test/supported_types/type_test.enumtype_test.dart b/json_serializable/test/supported_types/type_test.enumtype_test.dart index 5ead9e9f2..1652b359b 100644 --- a/json_serializable/test/supported_types/type_test.enumtype_test.dart +++ b/json_serializable/test/supported_types/type_test.enumtype_test.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.12 - // ignore_for_file: prefer_const_declarations import 'dart:convert'; diff --git a/json_serializable/test/supported_types/type_test.int_test.dart b/json_serializable/test/supported_types/type_test.int_test.dart index 8ec0cd571..b4252fa5f 100644 --- a/json_serializable/test/supported_types/type_test.int_test.dart +++ b/json_serializable/test/supported_types/type_test.int_test.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.12 - // ignore_for_file: prefer_const_declarations import 'dart:convert'; diff --git a/json_serializable/test/supported_types/type_test.iterable_test.dart b/json_serializable/test/supported_types/type_test.iterable_test.dart index cad1cbb99..57b9358b0 100644 --- a/json_serializable/test/supported_types/type_test.iterable_test.dart +++ b/json_serializable/test/supported_types/type_test.iterable_test.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.12 - // ignore_for_file: prefer_const_declarations import 'dart:convert'; diff --git a/json_serializable/test/supported_types/type_test.list_test.dart b/json_serializable/test/supported_types/type_test.list_test.dart index ebfe17126..342a89079 100644 --- a/json_serializable/test/supported_types/type_test.list_test.dart +++ b/json_serializable/test/supported_types/type_test.list_test.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.12 - // ignore_for_file: prefer_const_declarations import 'dart:convert'; diff --git a/json_serializable/test/supported_types/type_test.map_test.dart b/json_serializable/test/supported_types/type_test.map_test.dart index 2691408d1..c8cf4ccb9 100644 --- a/json_serializable/test/supported_types/type_test.map_test.dart +++ b/json_serializable/test/supported_types/type_test.map_test.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.12 - // ignore_for_file: prefer_const_declarations import 'dart:convert'; diff --git a/json_serializable/test/supported_types/type_test.num_test.dart b/json_serializable/test/supported_types/type_test.num_test.dart index a72a873a3..52241e719 100644 --- a/json_serializable/test/supported_types/type_test.num_test.dart +++ b/json_serializable/test/supported_types/type_test.num_test.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.12 - // ignore_for_file: prefer_const_declarations import 'dart:convert'; diff --git a/json_serializable/test/supported_types/type_test.object_test.dart b/json_serializable/test/supported_types/type_test.object_test.dart index ef38a0446..a4f9601f6 100644 --- a/json_serializable/test/supported_types/type_test.object_test.dart +++ b/json_serializable/test/supported_types/type_test.object_test.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.12 - // ignore_for_file: prefer_const_declarations import 'dart:convert'; diff --git a/json_serializable/test/supported_types/type_test.set_test.dart b/json_serializable/test/supported_types/type_test.set_test.dart index 99fff3b6b..a3b1ed57b 100644 --- a/json_serializable/test/supported_types/type_test.set_test.dart +++ b/json_serializable/test/supported_types/type_test.set_test.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.12 - // ignore_for_file: prefer_const_declarations import 'dart:convert'; diff --git a/json_serializable/test/supported_types/type_test.string_test.dart b/json_serializable/test/supported_types/type_test.string_test.dart index 41af3050c..845762b19 100644 --- a/json_serializable/test/supported_types/type_test.string_test.dart +++ b/json_serializable/test/supported_types/type_test.string_test.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.12 - // ignore_for_file: prefer_const_declarations import 'dart:convert'; diff --git a/json_serializable/test/supported_types/type_test.uri_test.dart b/json_serializable/test/supported_types/type_test.uri_test.dart index b32b892cc..ff0710b38 100644 --- a/json_serializable/test/supported_types/type_test.uri_test.dart +++ b/json_serializable/test/supported_types/type_test.uri_test.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.12 - // ignore_for_file: prefer_const_declarations import 'dart:convert'; diff --git a/json_serializable/test/test_sources/test_sources.dart b/json_serializable/test/test_sources/test_sources.dart index e14ad6205..b1182cb06 100644 --- a/json_serializable/test/test_sources/test_sources.dart +++ b/json_serializable/test/test_sources/test_sources.dart @@ -1,5 +1,3 @@ -// @dart=2.12 - import 'package:json_annotation/json_annotation.dart'; @JsonSerializable() diff --git a/json_serializable/test/test_utils.dart b/json_serializable/test/test_utils.dart index 324cdb27a..6bb67f98a 100644 --- a/json_serializable/test/test_utils.dart +++ b/json_serializable/test/test_utils.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.12 - import 'dart:convert'; import 'package:stack_trace/stack_trace.dart'; diff --git a/json_serializable/tool/doc_builder.dart b/json_serializable/tool/doc_builder.dart index 0dd737305..267690f7a 100644 --- a/json_serializable/tool/doc_builder.dart +++ b/json_serializable/tool/doc_builder.dart @@ -45,7 +45,7 @@ class _DocBuilder extends Builder { for (var className in _annotationClasses) { for (var fe in lib - .findType(className) + .findType(className)! .fields .where((fe) => !fe.isStatic && !fe.hasDeprecated)) { descriptionMap[fe.name] = @@ -121,9 +121,9 @@ String _link(String version, String owner, String name) => 'json_annotation/$owner/$name.html'; class _FieldInfo implements Comparable<_FieldInfo> { - final FieldElement _keyField, _classField; + final FieldElement? _keyField, _classField; - String get name => _keyField?.name ?? _classField.name; + String get name => _keyField?.name ?? _classField!.name; String get classAnnotationName { if (_classField == null) { @@ -144,15 +144,15 @@ class _FieldInfo implements Comparable<_FieldInfo> { return ''; } - return snakeCase(_classField.name); + return snakeCase(_classField!.name); } _FieldInfo(this._keyField, this._classField); - static _FieldInfo update(FieldElement field, _FieldInfo existing) { + static _FieldInfo update(FieldElement field, _FieldInfo? existing) { final parent = field.enclosingElement.name; - FieldElement keyField, classField; + FieldElement? keyField, classField; switch (parent) { case _jsonSerializable: classField = field; diff --git a/json_serializable/tool/shared.dart b/json_serializable/tool/shared.dart index 3e12e469e..f1e0b9914 100644 --- a/json_serializable/tool/shared.dart +++ b/json_serializable/tool/shared.dart @@ -21,7 +21,7 @@ Builder validate(String builderName, Builder builder) { final extensions = Set.from(buildYaml['.dart'] as YamlList); - final codedExtensions = builder.buildExtensions['.dart'].toSet(); + final codedExtensions = builder.buildExtensions['.dart']!.toSet(); final tooMany = extensions.difference(codedExtensions); if (tooMany.isNotEmpty) { diff --git a/json_serializable/tool/test_builder.dart b/json_serializable/tool/test_builder.dart index 52c4a3b70..4282e43e1 100644 --- a/json_serializable/tool/test_builder.dart +++ b/json_serializable/tool/test_builder.dart @@ -27,7 +27,7 @@ class _TestBuilder implements Builder { final factories = SplayTreeMap.from({'$_kitchenSinkBaseName.dart': 'normal'}); - for (var config in _fileConfigurationMap[baseName]) { + for (var config in _fileConfigurationMap[baseName]!) { final extension = _configToExtension(config); final newId = buildStep.inputId.changeExtension(extension); @@ -65,7 +65,7 @@ class _TestBuilder implements Builder { final lines = [ r''' // GENERATED CODE - DO NOT MODIFY BY HAND -// @dart=2.12 + ''', ...factories.entries.map((e) => "import '${e.key}' as ${e.value};"), 'const factories = [', @@ -146,7 +146,7 @@ Iterable _optionReplacement( if (baseName == _kitchenSinkBaseName && _kitchenSinkReplacements.containsKey(optionKey)) { - yield* _kitchenSinkReplacements[optionKey]; + yield* _kitchenSinkReplacements[optionKey]!; } } diff --git a/json_serializable/tool/test_type_data.dart b/json_serializable/tool/test_type_data.dart index fbe201ced..bd310a751 100644 --- a/json_serializable/tool/test_type_data.dart +++ b/json_serializable/tool/test_type_data.dart @@ -1,5 +1,3 @@ -import 'package:meta/meta.dart'; - import 'shared.dart'; const customEnumType = 'EnumType'; @@ -8,15 +6,15 @@ const _annotationImport = "import 'package:json_annotation/json_annotation.dart';"; class TestTypeData { - final String defaultExpression; - final String jsonExpression; - final String altJsonExpression; + final String? defaultExpression; + final String? jsonExpression; + final String? altJsonExpression; final Set genericArgs; const TestTypeData({ this.defaultExpression, - String jsonExpression, - @required String altJsonExpression, + String? jsonExpression, + required String? altJsonExpression, this.genericArgs = const {}, }) : jsonExpression = jsonExpression ?? defaultExpression, altJsonExpression = @@ -110,7 +108,7 @@ class TestTypeData { final defaultReplacement = defaultNotSupported ? '' : _defaultSource - .replaceFirst('42', defaultExpression) + .replaceFirst('42', defaultExpression!) .replaceFirst('dynamic', type); yield Replacement( From 67b21d2f61b4a6de54f1752a39800a3e250cbb4f Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Fri, 19 Mar 2021 09:39:38 -0700 Subject: [PATCH 284/569] Fix genericArgumentFactories w/ T? in field usage (#840) When a generic type (`T`) is used in a field as nullable (`final T? someField;`) then we cannot call the defined converters which are not expected to return `null` values (in `fromJson`) or handle `null` argument (in `toJson`). So we do the `null` check in a helper and pass it through. Fixes https://github.com/google/json_serializable.dart/issues/803 (for real) Closes https://github.com/google/json_serializable.dart/pull/837 Co-authored-by: Nate Bosch --- json_serializable/CHANGELOG.md | 4 +- json_serializable/README.md | 38 ++-- json_serializable/doc/doc.md | 38 ++-- .../type_helpers/generic_factory_helper.dart | 38 +++- json_serializable/pubspec.yaml | 2 +- .../generic_argument_factories_nullable.dart | 54 ++++++ ...generic_argument_factories_nullable.g.dart | 87 +++++++++ .../test/generic_files/generic_test.dart | 176 ++++++++++++++++-- 8 files changed, 382 insertions(+), 55 deletions(-) create mode 100644 json_serializable/test/generic_files/generic_argument_factories_nullable.dart create mode 100644 json_serializable/test/generic_files/generic_argument_factories_nullable.g.dart diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index bcc29a002..7f3d487a6 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,6 +1,8 @@ -## 5.0.0-dev +## 4.1.0-dev - Implementation is now null-safe. +- Correctly handle nullable generic fields (`T?`) with + `genericArgumentFactories`. ## 4.0.3 diff --git a/json_serializable/README.md b/json_serializable/README.md index be130cab1..09b5f2897 100644 --- a/json_serializable/README.md +++ b/json_serializable/README.md @@ -94,25 +94,25 @@ is generated: | | | [JsonKey.toJson] | | | | [JsonKey.unknownEnumValue] | -[JsonSerializable.anyMap]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonSerializable/anyMap.html -[JsonSerializable.checked]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonSerializable/checked.html -[JsonSerializable.createFactory]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonSerializable/createFactory.html -[JsonSerializable.createToJson]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonSerializable/createToJson.html -[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html -[JsonSerializable.explicitToJson]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonSerializable/explicitToJson.html -[JsonSerializable.fieldRename]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonSerializable/fieldRename.html -[JsonSerializable.genericArgumentFactories]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonSerializable/genericArgumentFactories.html -[JsonSerializable.ignoreUnannotated]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonSerializable/ignoreUnannotated.html -[JsonSerializable.includeIfNull]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonSerializable/includeIfNull.html -[JsonKey.includeIfNull]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonKey/includeIfNull.html -[JsonKey.defaultValue]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonKey/defaultValue.html -[JsonKey.disallowNullValue]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonKey/disallowNullValue.html -[JsonKey.fromJson]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonKey/fromJson.html -[JsonKey.ignore]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonKey/ignore.html -[JsonKey.name]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonKey/name.html -[JsonKey.required]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonKey/required.html -[JsonKey.toJson]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonKey/toJson.html -[JsonKey.unknownEnumValue]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonKey/unknownEnumValue.html +[JsonSerializable.anyMap]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonSerializable/anyMap.html +[JsonSerializable.checked]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonSerializable/checked.html +[JsonSerializable.createFactory]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonSerializable/createFactory.html +[JsonSerializable.createToJson]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonSerializable/createToJson.html +[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html +[JsonSerializable.explicitToJson]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonSerializable/explicitToJson.html +[JsonSerializable.fieldRename]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonSerializable/fieldRename.html +[JsonSerializable.genericArgumentFactories]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonSerializable/genericArgumentFactories.html +[JsonSerializable.ignoreUnannotated]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonSerializable/ignoreUnannotated.html +[JsonSerializable.includeIfNull]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonSerializable/includeIfNull.html +[JsonKey.includeIfNull]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonKey/includeIfNull.html +[JsonKey.defaultValue]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonKey/defaultValue.html +[JsonKey.disallowNullValue]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonKey/disallowNullValue.html +[JsonKey.fromJson]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonKey/fromJson.html +[JsonKey.ignore]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonKey/ignore.html +[JsonKey.name]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonKey/name.html +[JsonKey.required]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonKey/required.html +[JsonKey.toJson]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonKey/toJson.html +[JsonKey.unknownEnumValue]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonKey/unknownEnumValue.html > Note: every `JsonSerializable` field is configurable via `build.yaml` – > see the table for the corresponding key. diff --git a/json_serializable/doc/doc.md b/json_serializable/doc/doc.md index 52248799d..df1894032 100644 --- a/json_serializable/doc/doc.md +++ b/json_serializable/doc/doc.md @@ -19,22 +19,22 @@ | | | [JsonKey.toJson] | | | | [JsonKey.unknownEnumValue] | -[JsonSerializable.anyMap]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonSerializable/anyMap.html -[JsonSerializable.checked]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonSerializable/checked.html -[JsonSerializable.createFactory]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonSerializable/createFactory.html -[JsonSerializable.createToJson]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonSerializable/createToJson.html -[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html -[JsonSerializable.explicitToJson]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonSerializable/explicitToJson.html -[JsonSerializable.fieldRename]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonSerializable/fieldRename.html -[JsonSerializable.genericArgumentFactories]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonSerializable/genericArgumentFactories.html -[JsonSerializable.ignoreUnannotated]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonSerializable/ignoreUnannotated.html -[JsonSerializable.includeIfNull]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonSerializable/includeIfNull.html -[JsonKey.includeIfNull]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonKey/includeIfNull.html -[JsonKey.defaultValue]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonKey/defaultValue.html -[JsonKey.disallowNullValue]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonKey/disallowNullValue.html -[JsonKey.fromJson]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonKey/fromJson.html -[JsonKey.ignore]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonKey/ignore.html -[JsonKey.name]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonKey/name.html -[JsonKey.required]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonKey/required.html -[JsonKey.toJson]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonKey/toJson.html -[JsonKey.unknownEnumValue]: https://pub.dev/documentation/json_annotation/4.0.0/json_annotation/JsonKey/unknownEnumValue.html +[JsonSerializable.anyMap]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonSerializable/anyMap.html +[JsonSerializable.checked]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonSerializable/checked.html +[JsonSerializable.createFactory]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonSerializable/createFactory.html +[JsonSerializable.createToJson]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonSerializable/createToJson.html +[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html +[JsonSerializable.explicitToJson]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonSerializable/explicitToJson.html +[JsonSerializable.fieldRename]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonSerializable/fieldRename.html +[JsonSerializable.genericArgumentFactories]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonSerializable/genericArgumentFactories.html +[JsonSerializable.ignoreUnannotated]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonSerializable/ignoreUnannotated.html +[JsonSerializable.includeIfNull]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonSerializable/includeIfNull.html +[JsonKey.includeIfNull]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonKey/includeIfNull.html +[JsonKey.defaultValue]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonKey/defaultValue.html +[JsonKey.disallowNullValue]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonKey/disallowNullValue.html +[JsonKey.fromJson]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonKey/fromJson.html +[JsonKey.ignore]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonKey/ignore.html +[JsonKey.name]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonKey/name.html +[JsonKey.required]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonKey/required.html +[JsonKey.toJson]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonKey/toJson.html +[JsonKey.unknownEnumValue]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonKey/unknownEnumValue.html diff --git a/json_serializable/lib/src/type_helpers/generic_factory_helper.dart b/json_serializable/lib/src/type_helpers/generic_factory_helper.dart index 8227065f4..1f35d27d6 100644 --- a/json_serializable/lib/src/type_helpers/generic_factory_helper.dart +++ b/json_serializable/lib/src/type_helpers/generic_factory_helper.dart @@ -6,6 +6,7 @@ import 'package:analyzer/dart/element/type.dart'; import '../lambda_result.dart'; import '../type_helper.dart'; +import '../utils.dart'; class GenericFactoryHelper extends TypeHelper { const GenericFactoryHelper(); @@ -18,7 +19,13 @@ class GenericFactoryHelper extends TypeHelper { ) { if (context.config.genericArgumentFactories! && targetType is TypeParameterType) { - return LambdaResult(expression, toJsonForType(targetType)); + final toJsonFunc = toJsonForType(targetType); + if (targetType.isNullableType) { + context.addMember(_toJsonHelper); + return '$_toJsonHelperName($expression, $toJsonFunc)'; + } + + return LambdaResult(expression, toJsonFunc); } return null; @@ -33,13 +40,40 @@ class GenericFactoryHelper extends TypeHelper { ) { if (context.config.genericArgumentFactories! && targetType is TypeParameterType) { - return LambdaResult(expression, fromJsonForType(targetType)); + final fromJsonFunc = fromJsonForType(targetType); + + if (targetType.isNullableType) { + context.addMember(_fromJsonHelper); + return '$_fromJsonHelperName($expression, $fromJsonFunc)'; + } + + return LambdaResult(expression, fromJsonFunc); } return null; } } +const _fromJsonHelperName = r'_$nullableGenericFromJson'; + +const _fromJsonHelper = ''' +T? $_fromJsonHelperName( + Object? input, + T Function(Object? json) fromJson, +) => + input == null ? null : fromJson(input); +'''; + +const _toJsonHelperName = r'_$nullableGenericToJson'; + +const _toJsonHelper = ''' +Object? $_toJsonHelperName( + T? input, + Object? Function(T value) toJson, +) => + input == null ? null : toJson(input); +'''; + String toJsonForType(TypeParameterType type) => toJsonForName(type.getDisplayString(withNullability: false)); diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index d823cca4b..99f9405a3 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 5.0.0-dev +version: 4.1.0-dev description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. diff --git a/json_serializable/test/generic_files/generic_argument_factories_nullable.dart b/json_serializable/test/generic_files/generic_argument_factories_nullable.dart new file mode 100644 index 000000000..355d30a84 --- /dev/null +++ b/json_serializable/test/generic_files/generic_argument_factories_nullable.dart @@ -0,0 +1,54 @@ +// 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. + +// @dart=2.12 + +import 'package:json_annotation/json_annotation.dart'; + +part 'generic_argument_factories_nullable.g.dart'; + +@JsonSerializable(genericArgumentFactories: true) +class GenericClassWithHelpersNullable { + final T? value; + + final List? list; + + final Set? someSet; + + GenericClassWithHelpersNullable({ + this.value, + this.list, + this.someSet, + }); + + factory GenericClassWithHelpersNullable.fromJson( + Map json, + T Function(Object? json) fromJsonT, + S Function(Object? json) fromJsonS, + ) => + _$GenericClassWithHelpersNullableFromJson(json, fromJsonT, fromJsonS); + + Map toJson( + Object? Function(T value) toJsonT, + Object? Function(S value) toJsonS, + ) => + _$GenericClassWithHelpersNullableToJson(this, toJsonT, toJsonS); +} + +@JsonSerializable() +class ConcreteClassNullable { + final GenericClassWithHelpersNullable value; + + final GenericClassWithHelpersNullable value2; + + // Regression scenario for google/json_serializable.dart#803 + final GenericClassWithHelpersNullable value3; + + ConcreteClassNullable(this.value, this.value2, this.value3); + + factory ConcreteClassNullable.fromJson(Map json) => + _$ConcreteClassNullableFromJson(json); + + Map toJson() => _$ConcreteClassNullableToJson(this); +} diff --git a/json_serializable/test/generic_files/generic_argument_factories_nullable.g.dart b/json_serializable/test/generic_files/generic_argument_factories_nullable.g.dart new file mode 100644 index 000000000..e54af7a16 --- /dev/null +++ b/json_serializable/test/generic_files/generic_argument_factories_nullable.g.dart @@ -0,0 +1,87 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND +// @dart=2.12 + +part of 'generic_argument_factories_nullable.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +GenericClassWithHelpersNullable + _$GenericClassWithHelpersNullableFromJson( + Map json, + T Function(Object? json) fromJsonT, + S Function(Object? json) fromJsonS, +) { + return GenericClassWithHelpersNullable( + value: _$nullableGenericFromJson(json['value'], fromJsonT), + list: (json['list'] as List?) + ?.map((e) => _$nullableGenericFromJson(e, fromJsonT)) + .toList(), + someSet: (json['someSet'] as List?) + ?.map((e) => _$nullableGenericFromJson(e, fromJsonS)) + .toSet(), + ); +} + +Map _$GenericClassWithHelpersNullableToJson( + GenericClassWithHelpersNullable instance, + Object? Function(T value) toJsonT, + Object? Function(S value) toJsonS, +) => + { + 'value': _$nullableGenericToJson(instance.value, toJsonT), + 'list': instance.list + ?.map((e) => _$nullableGenericToJson(e, toJsonT)) + .toList(), + 'someSet': instance.someSet + ?.map((e) => _$nullableGenericToJson(e, toJsonS)) + .toList(), + }; + +T? _$nullableGenericFromJson( + Object? input, + T Function(Object? json) fromJson, +) => + input == null ? null : fromJson(input); + +Object? _$nullableGenericToJson( + T? input, + Object? Function(T value) toJson, +) => + input == null ? null : toJson(input); + +ConcreteClassNullable _$ConcreteClassNullableFromJson( + Map json) { + return ConcreteClassNullable( + GenericClassWithHelpersNullable.fromJson( + json['value'] as Map, + (value) => value as int, + (value) => value as String), + GenericClassWithHelpersNullable.fromJson( + json['value2'] as Map, + (value) => (value as num).toDouble(), + (value) => BigInt.parse(value as String)), + GenericClassWithHelpersNullable.fromJson( + json['value3'] as Map, + (value) => (value as num?)?.toDouble(), + (value) => value == null ? null : BigInt.parse(value as String)), + ); +} + +Map _$ConcreteClassNullableToJson( + ConcreteClassNullable instance) => + { + 'value': instance.value.toJson( + (value) => value, + (value) => value, + ), + 'value2': instance.value2.toJson( + (value) => value, + (value) => value.toString(), + ), + 'value3': instance.value3.toJson( + (value) => value, + (value) => value?.toString(), + ), + }; diff --git a/json_serializable/test/generic_files/generic_test.dart b/json_serializable/test/generic_files/generic_test.dart index 98b7e770b..80eb3bf1f 100644 --- a/json_serializable/test/generic_files/generic_test.dart +++ b/json_serializable/test/generic_files/generic_test.dart @@ -8,6 +8,7 @@ import 'package:test/test.dart'; import '../test_utils.dart'; import 'generic_argument_factories.dart'; +import 'generic_argument_factories_nullable.dart'; import 'generic_class.dart'; void main() { @@ -83,11 +84,10 @@ void main() { expect(encodedJson2, encodedJson); }); - }); - group('argument factories', () { - test('round trip decode/decode', () { - const inputJson = r''' + group('argument factories', () { + test('round trip decode/decode', () { + const inputJson = r''' { "value": { "value": 5, @@ -118,15 +118,164 @@ void main() { } }'''; - final instance = ConcreteClass.fromJson( - jsonDecode(inputJson) as Map, + final instance = ConcreteClass.fromJson( + jsonDecode(inputJson) as Map, + ); + + expect(loudEncode(instance), inputJson); + }); + + test('round trip decode/decode with null', () { + const inputJson = r''' +{ + "value": { + "value": 5, + "list": [ + 5 + ], + "someSet": [ + "string" + ] + }, + "value2": { + "value": 3.14, + "list": [ + 3.14 + ], + "someSet": [ + "2" + ] + }, + "value3": { + "value": null, + "list": [ + 3.14, + null + ], + "someSet": [ + "2", + null + ] + } +}'''; + + final instance = ConcreteClass.fromJson( + jsonDecode(inputJson) as Map, + ); + + expect(loudEncode(instance), inputJson); + }); + }); + }); + + group('genericArgumentFactories nullable', () { + test('basic round-trip', () { + final instance = GenericClassWithHelpersNullable( + value: DateTime.fromMillisecondsSinceEpoch(0).toUtc(), + list: [ + DateTime.fromMillisecondsSinceEpoch(1).toUtc(), + DateTime.fromMillisecondsSinceEpoch(2).toUtc(), + ], + someSet: { + const Duration(milliseconds: 3), + const Duration(milliseconds: 4) + }, + ); + + String encodeDateTime(DateTime value) => value.toIso8601String(); + int encodeDuration(Duration value) => value.inMilliseconds; + + final encodedJson = loudEncode( + instance.toJson(encodeDateTime, encodeDuration), + ); + + final decoded = + GenericClassWithHelpersNullable.fromJson( + jsonDecode(encodedJson) as Map, + (value) => DateTime.parse(value as String), + (value) => Duration(milliseconds: value as int), + ); + + final encodedJson2 = loudEncode( + decoded.toJson(encodeDateTime, encodeDuration), + ); + + expect(encodedJson2, encodedJson); + }); + + test('basic round-trip with null values', () { + final instance = GenericClassWithHelpersNullable( + //value: null, // value is null by omission + list: [ + null, + DateTime.fromMillisecondsSinceEpoch(2).toUtc(), + ], + someSet: {null, const Duration(milliseconds: 4)}, + ); + + String encodeDateTime(DateTime value) => value.toIso8601String(); + int encodeDuration(Duration value) => value.inMilliseconds; + + final encodedJson = loudEncode( + instance.toJson(encodeDateTime, encodeDuration), ); - expect(loudEncode(instance), inputJson); + final decoded = + GenericClassWithHelpersNullable.fromJson( + jsonDecode(encodedJson) as Map, + (value) => DateTime.parse(value as String), + (value) => Duration(milliseconds: value as int), + ); + + final encodedJson2 = loudEncode( + decoded.toJson(encodeDateTime, encodeDuration), + ); + + expect(encodedJson2, encodedJson); }); - test('round trip decode/decode with null', () { - const inputJson = r''' + group('argument factories', () { + test('round trip decode/decode', () { + const inputJson = r''' +{ + "value": { + "value": 5, + "list": [ + 5 + ], + "someSet": [ + "string" + ] + }, + "value2": { + "value": 3.14, + "list": [ + 3.14 + ], + "someSet": [ + "2" + ] + }, + "value3": { + "value": 3.14, + "list": [ + 3.14 + ], + "someSet": [ + "2" + ] + } +}'''; + + final instance = ConcreteClass.fromJson( + jsonDecode(inputJson) as Map, + ); + + expect(loudEncode(instance), inputJson); + }); + + test('round trip decode/decode with null', () { + const inputJson = r''' { "value": { "value": 5, @@ -159,11 +308,12 @@ void main() { } }'''; - final instance = ConcreteClass.fromJson( - jsonDecode(inputJson) as Map, - ); + final instance = ConcreteClassNullable.fromJson( + jsonDecode(inputJson) as Map, + ); - expect(loudEncode(instance), inputJson); + expect(loudEncode(instance), inputJson); + }); }); }); } From 7f2784b652da2f6323f5dfa8b73e923c965c3b13 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Fri, 19 Mar 2021 13:34:16 -0700 Subject: [PATCH 285/569] Use classes with non-nullable fields for core generator classes (#843) Eliminates most null checks A breaking change to `type_helper.dart`, but this is only a pseudo-supported library --- json_annotation/CHANGELOG.md | 1 + .../lib/src/json_serializable.dart | 2 + json_serializable/CHANGELOG.md | 5 + json_serializable/lib/src/decode_helper.dart | 18 +-- json_serializable/lib/src/encoder_helper.dart | 6 +- .../lib/src/generator_helper.dart | 8 +- json_serializable/lib/src/helper_core.dart | 8 +- json_serializable/lib/src/json_key_utils.dart | 19 ++- json_serializable/lib/src/settings.dart | 22 +++- json_serializable/lib/src/type_helper.dart | 5 +- .../lib/src/type_helper_ctx.dart | 4 +- .../lib/src/type_helpers/config_types.dart | 123 ++++++++++++++++++ .../type_helpers/generic_factory_helper.dart | 4 +- .../lib/src/type_helpers/json_helper.dart | 9 +- .../lib/src/type_helpers/map_helper.dart | 8 +- json_serializable/lib/src/utils.dart | 9 +- json_serializable/lib/type_helper.dart | 1 + .../test/custom_configuration_test.dart | 3 +- json_serializable/test/shared_config.dart | 3 +- 19 files changed, 206 insertions(+), 52 deletions(-) create mode 100644 json_serializable/lib/src/type_helpers/config_types.dart diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index 14c1969d9..7a4ed529c 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -3,6 +3,7 @@ - Fix a potential error with `checked: true` when `ArgumentError.message` is `null`. - Updated `JsonSerializable.fromJson` to handle `null` values. +- Deprecate `JsonSerializable` `defaults` and `withDefaults()`. ## 4.0.0 diff --git a/json_annotation/lib/src/json_serializable.dart b/json_annotation/lib/src/json_serializable.dart index 019198a78..ca647f024 100644 --- a/json_annotation/lib/src/json_serializable.dart +++ b/json_annotation/lib/src/json_serializable.dart @@ -194,6 +194,7 @@ class JsonSerializable { /// An instance of [JsonSerializable] with all fields set to their default /// values. + @Deprecated('Was only ever included to support builder infrastructure.') static const defaults = JsonSerializable( anyMap: false, checked: false, @@ -212,6 +213,7 @@ class JsonSerializable { /// /// Otherwise, the returned value has the default value as defined in /// [defaults]. + @Deprecated('Was only ever included to support builder infrastructure.') JsonSerializable withDefaults() => JsonSerializable( anyMap: anyMap ?? defaults.anyMap, checked: checked ?? defaults.checked, diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 7f3d487a6..c3f5a6abb 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -4,6 +4,11 @@ - Correctly handle nullable generic fields (`T?`) with `genericArgumentFactories`. +- `type_helper.dart` - **BREAKING changes** + - The API is now null-safe. + - new `KeyConfig` class replaces `JsonKey`. + - new `ClassConfig` class replaces `JsonSerializable`. + ## 4.0.3 - Correctly handle nullable values with `genericArgumentFactories`. diff --git a/json_serializable/lib/src/decode_helper.dart b/json_serializable/lib/src/decode_helper.dart index f6bed5954..d36120fa2 100644 --- a/json_serializable/lib/src/decode_helper.dart +++ b/json_serializable/lib/src/decode_helper.dart @@ -25,15 +25,15 @@ abstract class DecodeHelper implements HelperCore { Map accessibleFields, Map unavailableReasons, ) { - assert(config.createFactory!); + assert(config.createFactory); final buffer = StringBuffer(); - final mapType = config.anyMap! ? 'Map' : 'Map'; + final mapType = config.anyMap ? 'Map' : 'Map'; buffer.write('$targetClassReference ' '${prefix}FromJson${genericClassArgumentsImpl(true)}' '($mapType json'); - if (config.genericArgumentFactories!) { + if (config.genericArgumentFactories) { for (var arg in element.typeParameters) { final helperName = fromJsonForType( arg.instantiate(nullabilitySuffix: NullabilitySuffix.none), @@ -72,7 +72,7 @@ abstract class DecodeHelper implements HelperCore { final checks = _checkKeys(accessibleFields.values .where((fe) => data.usedCtorParamsAndFields.contains(fe.name))); - if (config.checked!) { + if (config.checked) { final classLiteral = escapeDartString(element.name); buffer..write(''' @@ -131,14 +131,14 @@ abstract class DecodeHelper implements HelperCore { String constantList(Iterable things) => 'const ${jsonLiteralAsDart(things.map(nameAccess).toList())}'; - if (config.disallowUnrecognizedKeys!) { + if (config.disallowUnrecognizedKeys) { final allowKeysLiteral = constantList(accessibleFields); args.add('allowedKeys: $allowKeysLiteral'); } final requiredKeys = - accessibleFields.where((fe) => jsonKeyFor(fe).required!).toList(); + accessibleFields.where((fe) => jsonKeyFor(fe).required).toList(); if (requiredKeys.isNotEmpty) { final requiredKeyLiteral = constantList(requiredKeys); @@ -146,7 +146,7 @@ abstract class DecodeHelper implements HelperCore { } final disallowNullKeys = accessibleFields - .where((fe) => jsonKeyFor(fe).disallowNullValue!) + .where((fe) => jsonKeyFor(fe).disallowNullValue) .toList(); if (disallowNullKeys.isNotEmpty) { final disallowNullKeyLiteral = constantList(disallowNullKeys); @@ -173,7 +173,7 @@ abstract class DecodeHelper implements HelperCore { String value; try { - if (config.checked!) { + if (config.checked) { value = contextHelper .deserialize( targetType, @@ -204,7 +204,7 @@ abstract class DecodeHelper implements HelperCore { final jsonKey = jsonKeyFor(field); final defaultValue = jsonKey.defaultValue; if (defaultValue != null) { - if (jsonKey.disallowNullValue! && jsonKey.required!) { + if (jsonKey.disallowNullValue && jsonKey.required) { log.warning('The `defaultValue` on field `${field.name}` will have no ' 'effect because both `disallowNullValue` and `required` are set to ' '`true`.'); diff --git a/json_serializable/lib/src/encoder_helper.dart b/json_serializable/lib/src/encoder_helper.dart index c11773a3f..6ea548781 100644 --- a/json_serializable/lib/src/encoder_helper.dart +++ b/json_serializable/lib/src/encoder_helper.dart @@ -17,7 +17,7 @@ abstract class EncodeHelper implements HelperCore { String _fieldAccess(FieldElement field) => '$_toJsonParamName.${field.name}'; Iterable createToJson(Set accessibleFields) sync* { - assert(config.createToJson!); + assert(config.createToJson); final buffer = StringBuffer(); @@ -25,7 +25,7 @@ abstract class EncodeHelper implements HelperCore { buffer.write('Map ' '$functionName($targetClassReference $_toJsonParamName'); - if (config.genericArgumentFactories!) { + if (config.genericArgumentFactories) { for (var arg in element.typeParameters) { final helperName = toJsonForType( arg.instantiate(nullabilitySuffix: NullabilitySuffix.none), @@ -140,7 +140,7 @@ abstract class EncodeHelper implements HelperCore { bool _writeJsonValueNaive(FieldElement field) { final jsonKey = jsonKeyFor(field); - return jsonKey.includeIfNull! || + return jsonKey.includeIfNull || (!field.type.isNullableType && !_fieldHasCustomEncoder(field)); } diff --git a/json_serializable/lib/src/generator_helper.dart b/json_serializable/lib/src/generator_helper.dart index 95c7d1e36..011fd46d3 100644 --- a/json_serializable/lib/src/generator_helper.dart +++ b/json_serializable/lib/src/generator_helper.dart @@ -41,7 +41,7 @@ class GeneratorHelper extends HelperCore with EncodeHelper, DecodeHelper { Iterable generate() sync* { assert(_addedMembers.isEmpty); - if (config.genericArgumentFactories! && element.typeParameters.isEmpty) { + if (config.genericArgumentFactories && element.typeParameters.isEmpty) { log.warning( 'The class `${element.displayName}` is annotated ' 'with `JsonSerializable` field `genericArgumentFactories: true`. ' @@ -68,7 +68,7 @@ class GeneratorHelper extends HelperCore with EncodeHelper, DecodeHelper { unavailableReasons[field.name] = 'Setter-only properties are not supported.'; log.warning('Setters are ignored: ${element.name}.${field.name}'); - } else if (jsonKeyFor(field).ignore!) { + } else if (jsonKeyFor(field).ignore) { unavailableReasons[field.name] = 'It is assigned to an ignored field.'; } else { @@ -81,7 +81,7 @@ class GeneratorHelper extends HelperCore with EncodeHelper, DecodeHelper { ); var accessibleFieldSet = accessibleFields.values.toSet(); - if (config.createFactory!) { + if (config.createFactory) { final createResult = createFactory(accessibleFields, unavailableReasons); yield createResult.output; @@ -108,7 +108,7 @@ class GeneratorHelper extends HelperCore with EncodeHelper, DecodeHelper { }, ); - if (config.createToJson!) { + if (config.createToJson) { yield* createToJson(accessibleFieldSet); } diff --git a/json_serializable/lib/src/helper_core.dart b/json_serializable/lib/src/helper_core.dart index 20eb2fb7b..ce1670a71 100644 --- a/json_serializable/lib/src/helper_core.dart +++ b/json_serializable/lib/src/helper_core.dart @@ -4,7 +4,6 @@ import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/type.dart'; -import 'package:json_annotation/json_annotation.dart'; import 'package:meta/meta.dart'; import 'package:source_gen/source_gen.dart'; @@ -12,12 +11,13 @@ import 'constants.dart'; import 'json_key_utils.dart'; import 'type_helper.dart'; import 'type_helper_ctx.dart'; +import 'type_helpers/config_types.dart'; import 'unsupported_type_error.dart'; import 'utils.dart'; abstract class HelperCore { final ClassElement element; - final JsonSerializable config; + final ClassConfig config; HelperCore(this.element, this.config); @@ -30,7 +30,7 @@ abstract class HelperCore { '${element.name}${genericClassArgumentsImpl(false)}'; @protected - String nameAccess(FieldElement field) => jsonKeyFor(field).name!; + String nameAccess(FieldElement field) => jsonKeyFor(field).name; @protected String safeNameAccess(FieldElement field) => @@ -48,7 +48,7 @@ abstract class HelperCore { genericClassArguments(element, withConstraints); @protected - JsonKey jsonKeyFor(FieldElement field) => jsonKeyForField(field, config); + KeyConfig jsonKeyFor(FieldElement field) => jsonKeyForField(field, config); @protected TypeHelperCtx getHelperContext(FieldElement field) => diff --git a/json_serializable/lib/src/json_key_utils.dart b/json_serializable/lib/src/json_key_utils.dart index cde0bf487..774dea783 100644 --- a/json_serializable/lib/src/json_key_utils.dart +++ b/json_serializable/lib/src/json_key_utils.dart @@ -10,14 +10,15 @@ import 'package:source_gen/source_gen.dart'; import 'json_literal_generator.dart'; import 'shared_checkers.dart'; +import 'type_helpers/config_types.dart'; import 'utils.dart'; -final _jsonKeyExpando = Expando(); +final _jsonKeyExpando = Expando(); -JsonKey jsonKeyForField(FieldElement field, JsonSerializable classAnnotation) => +KeyConfig jsonKeyForField(FieldElement field, ClassConfig classAnnotation) => _jsonKeyExpando[field] ??= _from(field, classAnnotation); -JsonKey _from(FieldElement element, JsonSerializable classAnnotation) { +KeyConfig _from(FieldElement element, ClassConfig classAnnotation) { // If an annotation exists on `element` the source is a 'real' field. // If the result is `null`, check the getter – it is a property. // TODO: setters: github.com/google/json_serializable.dart/issues/24 @@ -183,8 +184,8 @@ JsonKey _from(FieldElement element, JsonSerializable classAnnotation) { ); } -JsonKey _populateJsonKey( - JsonSerializable classAnnotation, +KeyConfig _populateJsonKey( + ClassConfig classAnnotation, FieldElement element, { Object? defaultValue, bool? disallowNullValue, @@ -203,7 +204,7 @@ JsonKey _populateJsonKey( } } - final jsonKey = JsonKey( + return KeyConfig( defaultValue: defaultValue, disallowNullValue: disallowNullValue ?? false, ignore: ignore ?? false, @@ -213,8 +214,6 @@ JsonKey _populateJsonKey( required: required ?? false, unknownEnumValue: unknownEnumValue, ); - - return jsonKey; } String _encodedFieldName( @@ -245,10 +244,10 @@ String _encodedFieldName( } } -bool? _includeIfNull( +bool _includeIfNull( bool? keyIncludeIfNull, bool? keyDisallowNullValue, - bool? classIncludeIfNull, + bool classIncludeIfNull, ) { if (keyDisallowNullValue == true) { assert(keyIncludeIfNull != true); diff --git a/json_serializable/lib/src/settings.dart b/json_serializable/lib/src/settings.dart index 5d9e3ea40..762289490 100644 --- a/json_serializable/lib/src/settings.dart +++ b/json_serializable/lib/src/settings.dart @@ -6,6 +6,7 @@ import 'package:json_annotation/json_annotation.dart'; import 'type_helper.dart'; import 'type_helpers/big_int_helper.dart'; +import 'type_helpers/config_types.dart'; import 'type_helpers/convert_helper.dart'; import 'type_helpers/date_time_helper.dart'; import 'type_helpers/duration_helper.dart'; @@ -44,7 +45,24 @@ class Settings { final JsonSerializable _config; - JsonSerializable get config => _config.withDefaults(); + ClassConfig get config => ClassConfig( + checked: _config.checked ?? ClassConfig.defaults.checked, + anyMap: _config.anyMap ?? ClassConfig.defaults.anyMap, + createFactory: + _config.createFactory ?? ClassConfig.defaults.createFactory, + createToJson: _config.createToJson ?? ClassConfig.defaults.createToJson, + ignoreUnannotated: + _config.ignoreUnannotated ?? ClassConfig.defaults.ignoreUnannotated, + explicitToJson: + _config.explicitToJson ?? ClassConfig.defaults.explicitToJson, + includeIfNull: + _config.includeIfNull ?? ClassConfig.defaults.includeIfNull, + genericArgumentFactories: _config.genericArgumentFactories ?? + ClassConfig.defaults.genericArgumentFactories, + fieldRename: _config.fieldRename ?? ClassConfig.defaults.fieldRename, + disallowUnrecognizedKeys: _config.disallowUnrecognizedKeys ?? + ClassConfig.defaults.disallowUnrecognizedKeys, + ); /// Creates an instance of [Settings]. /// @@ -54,7 +72,7 @@ class Settings { const Settings({ JsonSerializable? config, List? typeHelpers, - }) : _config = config ?? JsonSerializable.defaults, + }) : _config = config ?? ClassConfig.defaults, _typeHelpers = typeHelpers ?? defaultHelpers; /// Creates an instance of [Settings]. diff --git a/json_serializable/lib/src/type_helper.dart b/json_serializable/lib/src/type_helper.dart index 3d7e10f5a..af6e703c1 100644 --- a/json_serializable/lib/src/type_helper.dart +++ b/json_serializable/lib/src/type_helper.dart @@ -4,7 +4,8 @@ import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/type.dart'; -import 'package:json_annotation/json_annotation.dart'; + +import 'type_helpers/config_types.dart'; /// Context information provided in calls to [TypeHelper.serialize] and /// [TypeHelper.deserialize]. @@ -30,7 +31,7 @@ abstract class TypeHelperContext { /// Extended context information with includes configuration values /// corresponding to `JsonSerializableGenerator` settings. abstract class TypeHelperContextWithConfig extends TypeHelperContext { - JsonSerializable get config; + ClassConfig get config; } abstract class TypeHelper { diff --git a/json_serializable/lib/src/type_helper_ctx.dart b/json_serializable/lib/src/type_helper_ctx.dart index ab1fff795..de0cb7b93 100644 --- a/json_serializable/lib/src/type_helper_ctx.dart +++ b/json_serializable/lib/src/type_helper_ctx.dart @@ -5,10 +5,10 @@ import 'package:analyzer/dart/constant/value.dart'; import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/type.dart'; -import 'package:json_annotation/json_annotation.dart'; import 'helper_core.dart'; import 'type_helper.dart'; +import 'type_helpers/config_types.dart'; import 'type_helpers/convert_helper.dart'; import 'unsupported_type_error.dart'; import 'utils.dart'; @@ -28,7 +28,7 @@ class TypeHelperCtx ClassElement get classElement => _helperCore.element; @override - JsonSerializable get config => _helperCore.config; + ClassConfig get config => _helperCore.config; TypeHelperCtx._(this._helperCore, this.fieldElement); diff --git a/json_serializable/lib/src/type_helpers/config_types.dart b/json_serializable/lib/src/type_helpers/config_types.dart new file mode 100644 index 000000000..813c84c60 --- /dev/null +++ b/json_serializable/lib/src/type_helpers/config_types.dart @@ -0,0 +1,123 @@ +// 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:json_annotation/json_annotation.dart'; + +/// Represents values from [JsonKey] when merged with local configuration. +class KeyConfig { + final Object? defaultValue; + + final bool disallowNullValue; + + final bool ignore; + + final bool includeIfNull; + + final String name; + + final bool required; + + final Object? unknownEnumValue; + + KeyConfig({ + required this.defaultValue, + required this.disallowNullValue, + required this.ignore, + required this.includeIfNull, + required this.name, + required this.required, + required this.unknownEnumValue, + }); +} + +/// Represents values from [JsonSerializable] when merged with local +/// configuration. +/// +/// Values are all known, so types are non-nullable. +class ClassConfig implements JsonSerializable { + @override + final bool anyMap; + + @override + final bool checked; + + @override + final bool createFactory; + + @override + final bool createToJson; + + @override + final bool disallowUnrecognizedKeys; + + @override + final bool explicitToJson; + + @override + final FieldRename fieldRename; + + @override + final bool genericArgumentFactories; + + @override + final bool ignoreUnannotated; + + @override + final bool includeIfNull; + + const ClassConfig({ + required this.anyMap, + required this.checked, + required this.createFactory, + required this.createToJson, + required this.disallowUnrecognizedKeys, + required this.explicitToJson, + required this.fieldRename, + required this.genericArgumentFactories, + required this.ignoreUnannotated, + required this.includeIfNull, + }); + + /// An instance of [JsonSerializable] with all fields set to their default + /// values. + static const defaults = ClassConfig( + anyMap: false, + checked: false, + createFactory: true, + createToJson: true, + disallowUnrecognizedKeys: false, + explicitToJson: false, + fieldRename: FieldRename.none, + genericArgumentFactories: false, + ignoreUnannotated: false, + includeIfNull: true, + ); + + @override + Map toJson() => _$JsonSerializableToJson(this); + + @override + JsonSerializable withDefaults() => this; +} + +const _$FieldRenameEnumMap = { + FieldRename.none: 'none', + FieldRename.kebab: 'kebab', + FieldRename.snake: 'snake', + FieldRename.pascal: 'pascal', +}; + +Map _$JsonSerializableToJson(JsonSerializable instance) => + { + 'any_map': instance.anyMap, + 'checked': instance.checked, + 'create_factory': instance.createFactory, + 'create_to_json': instance.createToJson, + 'disallow_unrecognized_keys': instance.disallowUnrecognizedKeys, + 'explicit_to_json': instance.explicitToJson, + 'field_rename': _$FieldRenameEnumMap[instance.fieldRename], + 'generic_argument_factories': instance.genericArgumentFactories, + 'ignore_unannotated': instance.ignoreUnannotated, + 'include_if_null': instance.includeIfNull, + }; diff --git a/json_serializable/lib/src/type_helpers/generic_factory_helper.dart b/json_serializable/lib/src/type_helpers/generic_factory_helper.dart index 1f35d27d6..9f98cd6aa 100644 --- a/json_serializable/lib/src/type_helpers/generic_factory_helper.dart +++ b/json_serializable/lib/src/type_helpers/generic_factory_helper.dart @@ -17,7 +17,7 @@ class GenericFactoryHelper extends TypeHelper { String expression, TypeHelperContextWithConfig context, ) { - if (context.config.genericArgumentFactories! && + if (context.config.genericArgumentFactories && targetType is TypeParameterType) { final toJsonFunc = toJsonForType(targetType); if (targetType.isNullableType) { @@ -38,7 +38,7 @@ class GenericFactoryHelper extends TypeHelper { TypeHelperContextWithConfig context, bool defaultProvided, ) { - if (context.config.genericArgumentFactories! && + if (context.config.genericArgumentFactories && targetType is TypeParameterType) { final fromJsonFunc = fromJsonForType(targetType); diff --git a/json_serializable/lib/src/type_helpers/json_helper.dart b/json_serializable/lib/src/type_helpers/json_helper.dart index 86de56fc9..2de1398f0 100644 --- a/json_serializable/lib/src/type_helpers/json_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_helper.dart @@ -12,6 +12,7 @@ import 'package:source_gen/source_gen.dart'; import '../shared_checkers.dart'; import '../type_helper.dart'; import '../utils.dart'; +import 'config_types.dart'; import 'generic_factory_helper.dart'; const _helperLambdaParam = 'value'; @@ -55,7 +56,7 @@ class JsonHelper extends TypeHelper { ); } - if (context.config.explicitToJson! || toJsonArgs.isNotEmpty) { + if (context.config.explicitToJson || toJsonArgs.isNotEmpty) { return '$expression${interfaceType.isNullableType ? '?' : ''}' '.toJson(${toJsonArgs.map((a) => '$a, ').join()} )'; } @@ -116,7 +117,7 @@ class JsonHelper extends TypeHelper { output = args.join(', '); } else if (_annotation(context.config, targetType)?.createFactory == true) { - if (context.config.anyMap!) { + if (context.config.anyMap) { output += ' as Map'; } else { output += ' as Map'; @@ -219,7 +220,7 @@ TypeParameterType _encodeHelper( ); } -bool _canSerialize(JsonSerializable config, DartType type) { +bool _canSerialize(ClassConfig config, DartType type) { if (type is InterfaceType) { final toJsonMethod = _toJsonMethod(type); @@ -266,7 +267,7 @@ InterfaceType? _instantiate( ); } -JsonSerializable? _annotation(JsonSerializable config, InterfaceType source) { +ClassConfig? _annotation(ClassConfig config, InterfaceType source) { final annotations = const TypeChecker.fromRuntime(JsonSerializable) .annotationsOfExact(source.element, throwOnUnresolved: false) .toList(); diff --git a/json_serializable/lib/src/type_helpers/map_helper.dart b/json_serializable/lib/src/type_helpers/map_helper.dart index 764cd89e9..d994818a0 100644 --- a/json_serializable/lib/src/type_helpers/map_helper.dart +++ b/json_serializable/lib/src/type_helpers/map_helper.dart @@ -77,7 +77,7 @@ class MapHelper extends TypeHelper { if (!isKeyStringable) { if (valueArgIsAny) { - if (context.config.anyMap!) { + if (context.config.anyMap) { if (isLikeDynamic(keyArg)) { return '$expression as Map$optionalQuestion'; } @@ -102,7 +102,7 @@ class MapHelper extends TypeHelper { final itemSubVal = context.deserialize(valueArg, closureArg); - var mapCast = context.config.anyMap! ? 'as Map' : 'as Map'; + var mapCast = context.config.anyMap ? 'as Map' : 'as Map'; if (targetTypeIsNullable) { mapCast += '?'; @@ -111,10 +111,10 @@ class MapHelper extends TypeHelper { String keyUsage; if (isEnum(keyArg)) { keyUsage = context.deserialize(keyArg, _keyParam).toString(); - } else if (context.config.anyMap! && + } else if (context.config.anyMap && !(keyArg.isDartCoreObject || keyArg.isDynamic)) { keyUsage = '$_keyParam as String'; - } else if (context.config.anyMap! && + } else if (context.config.anyMap && keyArg.isDartCoreObject && !keyArg.isNullableType) { keyUsage = '$_keyParam as Object'; diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index f397cdbb7..ec62c575b 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -10,6 +10,7 @@ import 'package:json_annotation/json_annotation.dart'; import 'package:source_gen/source_gen.dart'; import 'helper_core.dart'; +import 'type_helpers/config_types.dart'; const _jsonKeyChecker = TypeChecker.fromRuntime(JsonKey); @@ -97,14 +98,14 @@ JsonSerializable _valueForAnnotation(ConstantReader reader) => JsonSerializable( /// Note: if [JsonSerializable.genericArgumentFactories] is `false` for [reader] /// and `true` for [config], the corresponding field in the return value will /// only be `true` if [classElement] has type parameters. -JsonSerializable mergeConfig( - JsonSerializable config, +ClassConfig mergeConfig( + ClassConfig config, ConstantReader reader, { required ClassElement classElement, }) { final annotation = _valueForAnnotation(reader); - return JsonSerializable( + return ClassConfig( anyMap: annotation.anyMap ?? config.anyMap, checked: annotation.checked ?? config.checked, createFactory: annotation.createFactory ?? config.createFactory, @@ -115,7 +116,7 @@ JsonSerializable mergeConfig( fieldRename: annotation.fieldRename ?? config.fieldRename, genericArgumentFactories: annotation.genericArgumentFactories ?? (classElement.typeParameters.isNotEmpty && - config.genericArgumentFactories!), + config.genericArgumentFactories), ignoreUnannotated: annotation.ignoreUnannotated ?? config.ignoreUnannotated, includeIfNull: annotation.includeIfNull ?? config.includeIfNull, ); diff --git a/json_serializable/lib/type_helper.dart b/json_serializable/lib/type_helper.dart index 6d574f4b5..cb496d213 100644 --- a/json_serializable/lib/type_helper.dart +++ b/json_serializable/lib/type_helper.dart @@ -6,6 +6,7 @@ export 'src/shared_checkers.dart' show simpleJsonTypeChecker, typeArgumentsOf; export 'src/type_helper.dart' show TypeHelperContext, TypeHelperContextWithConfig, TypeHelper; export 'src/type_helpers/big_int_helper.dart'; +export 'src/type_helpers/config_types.dart'; export 'src/type_helpers/convert_helper.dart'; export 'src/type_helpers/date_time_helper.dart'; export 'src/type_helpers/duration_helper.dart'; diff --git a/json_serializable/test/custom_configuration_test.dart b/json_serializable/test/custom_configuration_test.dart index e9d9ab19d..03c994519 100644 --- a/json_serializable/test/custom_configuration_test.dart +++ b/json_serializable/test/custom_configuration_test.dart @@ -11,6 +11,7 @@ import 'package:json_annotation/json_annotation.dart'; import 'package:json_serializable/json_serializable.dart'; import 'package:json_serializable/src/constants.dart'; import 'package:json_serializable/src/type_helper.dart'; +import 'package:json_serializable/src/type_helpers/config_types.dart'; import 'package:path/path.dart' as p; import 'package:source_gen/source_gen.dart'; import 'package:source_gen_test/source_gen_test.dart'; @@ -31,7 +32,7 @@ Future main() async { ); group('without wrappers', () { - _registerTests(JsonSerializable.defaults); + _registerTests(ClassConfig.defaults); }); group('configuration', () { diff --git a/json_serializable/test/shared_config.dart b/json_serializable/test/shared_config.dart index 708c7a7e1..4e7747475 100644 --- a/json_serializable/test/shared_config.dart +++ b/json_serializable/test/shared_config.dart @@ -3,11 +3,12 @@ // BSD-style license that can be found in the LICENSE file. import 'package:json_annotation/json_annotation.dart'; +import 'package:json_serializable/src/type_helpers/config_types.dart'; final jsonSerializableFields = generatorConfigDefaultJson.keys.toList(); final generatorConfigDefaultJson = Map.unmodifiable( - const JsonSerializable().withDefaults().toJson()); + ClassConfig.defaults.withDefaults().toJson()); final generatorConfigNonDefaultJson = Map.unmodifiable(const JsonSerializable( From d096a39b74344ccca65467cfcdd1dd0621586a4a Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Fri, 19 Mar 2021 14:10:10 -0700 Subject: [PATCH 286/569] Prepare to release v4.1.0 of json_serializable (#844) --- json_serializable/CHANGELOG.md | 2 +- json_serializable/pubspec.yaml | 10 +--------- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index c3f5a6abb..b358bbe67 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,4 +1,4 @@ -## 4.1.0-dev +## 4.1.0 - Implementation is now null-safe. - Correctly handle nullable generic fields (`T?`) with diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 99f9405a3..a83829cdd 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,12 +1,10 @@ name: json_serializable -version: 4.1.0-dev +version: 4.1.0 description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. repository: https://github.com/google/json_serializable.dart/tree/master/json_serializable environment: - # Keeping this <2.12.0 because the code is not null safe – yet! - # https://github.com/google/json_serializable.dart/issues/821 sdk: '>=2.12.0 <3.0.0' dependencies: @@ -17,8 +15,6 @@ dependencies: # Use a tight version constraint to ensure that a constraint on # `json_annotation` properly constrains all features it provides. - # For v3 only – allow a wide range since the only change was to REMOVE things - # from json_annotation json_annotation: '>=4.0.1 <4.1.0' meta: ^1.3.0 path: ^1.8.0 @@ -34,7 +30,3 @@ dev_dependencies: stack_trace: ^1.10.0 test: ^1.16.0 yaml: ^3.0.0 - -dependency_overrides: - json_annotation: - path: ../json_annotation From 2b40a4e655e52426c8282a86a16beff19f7e5605 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 22 Mar 2021 14:08:23 -0700 Subject: [PATCH 287/569] utils: make isEnum an extension (#846) --- json_serializable/lib/src/json_key_utils.dart | 2 +- json_serializable/lib/src/type_helpers/map_helper.dart | 4 ++-- json_serializable/lib/src/utils.dart | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/json_serializable/lib/src/json_key_utils.dart b/json_serializable/lib/src/json_key_utils.dart index 774dea783..596bc7c0d 100644 --- a/json_serializable/lib/src/json_key_utils.dart +++ b/json_serializable/lib/src/json_key_utils.dart @@ -124,7 +124,7 @@ KeyConfig _from(FieldElement element, ClassConfig classAnnotation) { if (enumFields != null) { if (mustBeEnum) { late DartType targetEnumType; - if (isEnum(element.type)) { + if (element.type.isEnum) { targetEnumType = element.type; } else if (coreIterableTypeChecker.isAssignableFromType(element.type)) { targetEnumType = coreIterableGenericType(element.type); diff --git a/json_serializable/lib/src/type_helpers/map_helper.dart b/json_serializable/lib/src/type_helpers/map_helper.dart index d994818a0..f7a3b2494 100644 --- a/json_serializable/lib/src/type_helpers/map_helper.dart +++ b/json_serializable/lib/src/type_helpers/map_helper.dart @@ -109,7 +109,7 @@ class MapHelper extends TypeHelper { } String keyUsage; - if (isEnum(keyArg)) { + if (keyArg.isEnum) { keyUsage = context.deserialize(keyArg, _keyParam).toString(); } else if (context.config.anyMap && !(keyArg.isDartCoreObject || keyArg.isDynamic)) { @@ -149,7 +149,7 @@ ToFromStringHelper? _forType(DartType type) => /// Returns `true` if [keyType] can be automatically converted to/from String – /// and is therefor usable as a key in a [Map]. bool _isKeyStringable(DartType keyType) => - isEnum(keyType) || _instances.any((inst) => inst.matches(keyType)); + keyType.isEnum || _instances.any((inst) => inst.matches(keyType)); void _checkSafeKeyType(String expression, DartType keyArg) { // We're not going to handle converting key types at the moment diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index ec62c575b..2aa651f74 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -122,9 +122,6 @@ ClassConfig mergeConfig( ); } -bool isEnum(DartType targetType) => - targetType is InterfaceType && targetType.element.isEnum; - final _enumMapExpando = Expando>(); /// If [targetType] is an enum, returns a [Map] of the [FieldElement] instances @@ -268,6 +265,9 @@ extension DartTypeExtension on DartType { // If the library is `null`, treat it like dynamic => `true` element!.library == null || element!.library!.typeSystem.isAssignableTo(this, other); + + bool get isEnum => + this is InterfaceType && (this as InterfaceType).element.isEnum; } extension TypeExtension on DartType { From 05733861790d439c652304732fe97bb8fd604355 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 25 Mar 2021 15:56:18 -0700 Subject: [PATCH 288/569] Continue to move utilities to DartType extension (#854) --- .../lib/src/shared_checkers.dart | 27 +++---------------- .../lib/src/type_helpers/json_helper.dart | 3 +-- .../lib/src/type_helpers/map_helper.dart | 2 +- json_serializable/lib/src/utils.dart | 22 +++++++++++++-- 4 files changed, 26 insertions(+), 28 deletions(-) diff --git a/json_serializable/lib/src/shared_checkers.dart b/json_serializable/lib/src/shared_checkers.dart index 40a78cc1e..02decca75 100644 --- a/json_serializable/lib/src/shared_checkers.dart +++ b/json_serializable/lib/src/shared_checkers.dart @@ -40,7 +40,7 @@ const simpleJsonTypeChecker = TypeChecker.any([ ]); String asStatement(DartType type) { - if (isLikeDynamic(type)) { + if (type.isLikeDynamic) { return ''; } @@ -48,7 +48,7 @@ String asStatement(DartType type) { if (coreIterableTypeChecker.isAssignableFromType(type)) { final itemType = coreIterableGenericType(type); - if (isLikeDynamic(itemType)) { + if (itemType.isLikeDynamic) { return ' as List$nullableSuffix'; } } @@ -57,7 +57,7 @@ String asStatement(DartType type) { final args = typeArgumentsOf(type, coreMapTypeChecker); assert(args.length == 2); - if (args.every(isLikeDynamic)) { + if (args.every((e) => e.isLikeDynamic)) { return ' as Map$nullableSuffix'; } } @@ -66,24 +66,5 @@ String asStatement(DartType type) { return ' as $typeCode'; } -/// Returns `true` if [type] is `dynamic` or `Obect?`. -bool isLikeDynamic(DartType type) => - (type.isDartCoreObject && type.isNullableType) || type.isDynamic; - -/// Returns all of the [DartType] types that [type] implements, mixes-in, and -/// extends, starting with [type] itself. -Iterable typeImplementations(DartType type) sync* { - yield type; - - if (type is InterfaceType) { - yield* type.interfaces.expand(typeImplementations); - yield* type.mixins.expand(typeImplementations); - - if (type.superclass != null) { - yield* typeImplementations(type.superclass!); - } - } -} - DartType? _getImplementationType(DartType type, TypeChecker checker) => - typeImplementations(type).firstWhereOrNull(checker.isExactlyType); + type.typeImplementations.firstWhereOrNull(checker.isExactlyType); diff --git a/json_serializable/lib/src/type_helpers/json_helper.dart b/json_serializable/lib/src/type_helpers/json_helper.dart index 2de1398f0..d746b1d6d 100644 --- a/json_serializable/lib/src/type_helpers/json_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_helper.dart @@ -9,7 +9,6 @@ import 'package:collection/collection.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:source_gen/source_gen.dart'; -import '../shared_checkers.dart'; import '../type_helper.dart'; import '../utils.dart'; import 'config_types.dart'; @@ -283,6 +282,6 @@ ClassConfig? _annotation(ClassConfig config, InterfaceType source) { ); } -MethodElement? _toJsonMethod(DartType type) => typeImplementations(type) +MethodElement? _toJsonMethod(DartType type) => type.typeImplementations .map((dt) => dt is InterfaceType ? dt.getMethod('toJson') : null) .firstWhereOrNull((me) => me != null); diff --git a/json_serializable/lib/src/type_helpers/map_helper.dart b/json_serializable/lib/src/type_helpers/map_helper.dart index f7a3b2494..327cb2a02 100644 --- a/json_serializable/lib/src/type_helpers/map_helper.dart +++ b/json_serializable/lib/src/type_helpers/map_helper.dart @@ -78,7 +78,7 @@ class MapHelper extends TypeHelper { if (!isKeyStringable) { if (valueArgIsAny) { if (context.config.anyMap) { - if (isLikeDynamic(keyArg)) { + if (keyArg.isLikeDynamic) { return '$expression as Map$optionalQuestion'; } } else { diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index 2aa651f74..46fb1c20c 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -268,9 +268,27 @@ extension DartTypeExtension on DartType { bool get isEnum => this is InterfaceType && (this as InterfaceType).element.isEnum; -} -extension TypeExtension on DartType { bool get isNullableType => isDynamic || nullabilitySuffix == NullabilitySuffix.question; + + /// Returns `true` if `this` is `dynamic` or `Object?`. + bool get isLikeDynamic => (isDartCoreObject && isNullableType) || isDynamic; + + /// Returns all of the [DartType] types that `this` implements, mixes-in, and + /// extends, starting with `this` itself. + Iterable get typeImplementations sync* { + yield this; + + final myType = this; + + if (myType is InterfaceType) { + yield* myType.interfaces.expand((e) => e.typeImplementations); + yield* myType.mixins.expand((e) => e.typeImplementations); + + if (myType.superclass != null) { + yield* myType.superclass!.typeImplementations; + } + } + } } From 8cda69cc20a582df4957d3292af17024bcc586dd Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Fri, 26 Mar 2021 12:54:11 -0700 Subject: [PATCH 289/569] Small spelling mistake in error message (#855) --- json_serializable/CHANGELOG.md | 2 ++ json_serializable/lib/src/json_key_utils.dart | 2 +- json_serializable/pubspec.yaml | 2 +- json_serializable/test/src/_json_serializable_test_input.dart | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index b358bbe67..8438e0039 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,5 @@ +## 4.1.1-dev + ## 4.1.0 - Implementation is now null-safe. diff --git a/json_serializable/lib/src/json_key_utils.dart b/json_serializable/lib/src/json_key_utils.dart index 596bc7c0d..2fd342466 100644 --- a/json_serializable/lib/src/json_key_utils.dart +++ b/json_serializable/lib/src/json_key_utils.dart @@ -199,7 +199,7 @@ KeyConfig _populateJsonKey( if (includeIfNull == true) { throwUnsupported( element, - 'Cannot set both `disallowNullvalue` and `includeIfNull` to `true`. ' + 'Cannot set both `disallowNullValue` and `includeIfNull` to `true`. ' 'This leads to incompatible `toJson` and `fromJson` behavior.'); } } diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index a83829cdd..9e67da92a 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 4.1.0 +version: 4.1.1-dev description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. diff --git a/json_serializable/test/src/_json_serializable_test_input.dart b/json_serializable/test/src/_json_serializable_test_input.dart index 81e6b03b7..de76cc1f9 100644 --- a/json_serializable/test/src/_json_serializable_test_input.dart +++ b/json_serializable/test/src/_json_serializable_test_input.dart @@ -346,7 +346,7 @@ class PrivateFieldCtorClass { @ShouldThrow( 'Error with `@JsonKey` on `field`. ' - 'Cannot set both `disallowNullvalue` and `includeIfNull` to `true`. ' + 'Cannot set both `disallowNullValue` and `includeIfNull` to `true`. ' 'This leads to incompatible `toJson` and `fromJson` behavior.', element: 'field', ) From 4df0dcb5cf20cbcd3ba31d9cc4ea2fe2e50c026d Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 29 Mar 2021 08:20:32 -0700 Subject: [PATCH 290/569] Use the default value for optional constructor params... (#856) ...if JsonKey.defaultValue is not provided Towards some of the discussion in https://github.com/google/json_serializable.dart/issues/796 --- json_serializable/CHANGELOG.md | 6 +- json_serializable/lib/src/decode_helper.dart | 8 +- json_serializable/lib/src/json_key_utils.dart | 18 ++- .../lib/src/type_helpers/config_types.dart | 3 + json_serializable/lib/src/utils.dart | 24 ++++ json_serializable/pubspec.yaml | 2 +- .../default_value_interface.dart | 50 ++++----- .../default_value/default_value_test.dart | 2 + .../default_value/implicit_default_value.dart | 59 ++++++++++ .../implicit_default_value.g.dart | 103 ++++++++++++++++++ .../test/json_serializable_test.dart | 1 + .../test/src/default_value_input.dart | 24 ++++ 12 files changed, 262 insertions(+), 38 deletions(-) create mode 100644 json_serializable/test/default_value/implicit_default_value.dart create mode 100644 json_serializable/test/default_value/implicit_default_value.g.dart diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 8438e0039..67c40c125 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,4 +1,8 @@ -## 4.1.1-dev +## 5.0.0-dev + +- Use the default value for optional constructor parameters if + `JsonKey.defaultValue` is not provided. This could be a breaking behavior + change in generated code in some cases. ## 4.1.0 diff --git a/json_serializable/lib/src/decode_helper.dart b/json_serializable/lib/src/decode_helper.dart index d36120fa2..024adbb93 100644 --- a/json_serializable/lib/src/decode_helper.dart +++ b/json_serializable/lib/src/decode_helper.dart @@ -241,13 +241,7 @@ _ConstructorData _writeConstructorInvocation( ) { final className = classElement.name; - final ctor = classElement.unnamedConstructor; - if (ctor == null) { - // TODO: support using another ctor - google/json_serializable.dart#50 - throw InvalidGenerationSourceError( - 'The class `$className` has no default constructor.', - element: classElement); - } + final ctor = unnamedConstructorOrError(classElement); final usedCtorParamsAndFields = {}; final constructorArguments = []; diff --git a/json_serializable/lib/src/json_key_utils.dart b/json_serializable/lib/src/json_key_utils.dart index 2fd342466..e300ecd11 100644 --- a/json_serializable/lib/src/json_key_utils.dart +++ b/json_serializable/lib/src/json_key_utils.dart @@ -5,6 +5,7 @@ import 'package:analyzer/dart/constant/value.dart'; import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/type.dart'; +import 'package:build/build.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:source_gen/source_gen.dart'; @@ -24,10 +25,13 @@ KeyConfig _from(FieldElement element, ClassConfig classAnnotation) { // TODO: setters: github.com/google/json_serializable.dart/issues/24 final obj = jsonKeyAnnotation(element); + final ctorParamDefault = classAnnotation.ctorParamDefaults[element.name]; + if (obj.isNull) { return _populateJsonKey( classAnnotation, element, + defaultValue: ctorParamDefault, ignore: classAnnotation.ignoreUnannotated, ); } @@ -171,10 +175,20 @@ KeyConfig _from(FieldElement element, ClassConfig classAnnotation) { } } + final defaultValue = _annotationValue('defaultValue'); + if (defaultValue != null && ctorParamDefault != null) { + log.warning( + 'The constructor parameter for `${element.name}` has a default value ' + '`$ctorParamDefault`, but the `JsonKey.defaultValue` value ' + '`$defaultValue` will be used for missing or `null` values in JSON ' + 'decoding.', + ); + } + return _populateJsonKey( classAnnotation, element, - defaultValue: _annotationValue('defaultValue'), + defaultValue: defaultValue ?? ctorParamDefault, disallowNullValue: obj.read('disallowNullValue').literalValue as bool?, ignore: obj.read('ignore').literalValue as bool?, includeIfNull: obj.read('includeIfNull').literalValue as bool?, @@ -187,7 +201,7 @@ KeyConfig _from(FieldElement element, ClassConfig classAnnotation) { KeyConfig _populateJsonKey( ClassConfig classAnnotation, FieldElement element, { - Object? defaultValue, + required Object? defaultValue, bool? disallowNullValue, bool? ignore, bool? includeIfNull, diff --git a/json_serializable/lib/src/type_helpers/config_types.dart b/json_serializable/lib/src/type_helpers/config_types.dart index 813c84c60..993645e4a 100644 --- a/json_serializable/lib/src/type_helpers/config_types.dart +++ b/json_serializable/lib/src/type_helpers/config_types.dart @@ -66,6 +66,8 @@ class ClassConfig implements JsonSerializable { @override final bool includeIfNull; + final Map ctorParamDefaults; + const ClassConfig({ required this.anyMap, required this.checked, @@ -77,6 +79,7 @@ class ClassConfig implements JsonSerializable { required this.genericArgumentFactories, required this.ignoreUnannotated, required this.includeIfNull, + this.ctorParamDefaults = const {}, }); /// An instance of [JsonSerializable] with all fields set to their default diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index 46fb1c20c..e9e46c2df 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -104,6 +104,14 @@ ClassConfig mergeConfig( required ClassElement classElement, }) { final annotation = _valueForAnnotation(reader); + assert(config.ctorParamDefaults.isEmpty); + + final defaultCtor = unnamedConstructorOrError(classElement); + + final paramDefaultValueMap = Map.fromEntries(defaultCtor + .parameters + .where((element) => element.hasDefaultValue) + .map((e) => MapEntry(e.name, e.defaultValueCode!))); return ClassConfig( anyMap: annotation.anyMap ?? config.anyMap, @@ -119,9 +127,25 @@ ClassConfig mergeConfig( config.genericArgumentFactories), ignoreUnannotated: annotation.ignoreUnannotated ?? config.ignoreUnannotated, includeIfNull: annotation.includeIfNull ?? config.includeIfNull, + ctorParamDefaults: paramDefaultValueMap, ); } +ConstructorElement unnamedConstructorOrError(ClassElement classElement) { + final className = classElement.name; + + final ctor = classElement.unnamedConstructor; + if (ctor == null) { + // TODO: support using another ctor - google/json_serializable.dart#50 + throw InvalidGenerationSourceError( + 'The class `$className` has no default constructor.', + element: classElement, + ); + } + + return ctor; +} + final _enumMapExpando = Expando>(); /// If [targetType] is an enum, returns a [Map] of the [FieldElement] instances diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 9e67da92a..8258839b1 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 4.1.1-dev +version: 5.0.0-dev description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. diff --git a/json_serializable/test/default_value/default_value_interface.dart b/json_serializable/test/default_value/default_value_interface.dart index 06bc33408..6cf4704b6 100644 --- a/json_serializable/test/default_value/default_value_interface.dart +++ b/json_serializable/test/default_value/default_value_interface.dart @@ -3,33 +3,29 @@ // BSD-style license that can be found in the LICENSE file. abstract class DefaultValue { - bool fieldBool; - String fieldString; - int fieldInt; - double fieldDouble; - List fieldListEmpty; - Map fieldMapEmpty; - Set fieldSetEmpty; - List fieldListSimple; - Set fieldSetSimple; - Map fieldMapSimple; - Map> fieldMapListString; - Greek fieldEnum; - - DefaultValue( - this.fieldBool, - this.fieldString, - this.fieldInt, - this.fieldDouble, - this.fieldListEmpty, - this.fieldSetEmpty, - this.fieldMapEmpty, - this.fieldListSimple, - this.fieldSetSimple, - this.fieldMapSimple, - this.fieldMapListString, - this.fieldEnum, - ); + bool get fieldBool; + + String get fieldString; + + int get fieldInt; + + double get fieldDouble; + + List get fieldListEmpty; + + Map get fieldMapEmpty; + + Set get fieldSetEmpty; + + List get fieldListSimple; + + Set get fieldSetSimple; + + Map get fieldMapSimple; + + Map> get fieldMapListString; + + Greek get fieldEnum; } enum Greek { alpha, beta, gamma, delta } diff --git a/json_serializable/test/default_value/default_value_test.dart b/json_serializable/test/default_value/default_value_test.dart index 00ef236ad..740c03a6f 100644 --- a/json_serializable/test/default_value/default_value_test.dart +++ b/json_serializable/test/default_value/default_value_test.dart @@ -8,6 +8,7 @@ import '../test_utils.dart'; import 'default_value.dart' as normal; import 'default_value.g_any_map__checked.dart' as checked; import 'default_value_interface.dart'; +import 'implicit_default_value.dart' as implicit; const _defaultInstance = { 'fieldBool': true, @@ -46,6 +47,7 @@ const _otherValues = { void main() { group('nullable', () => _test(normal.fromJson)); group('non-nullable', () => _test(checked.fromJson)); + group('implicit', () => _test(implicit.fromJson)); } void _test(DefaultValue Function(Map json) fromJson) { diff --git a/json_serializable/test/default_value/implicit_default_value.dart b/json_serializable/test/default_value/implicit_default_value.dart new file mode 100644 index 000000000..e61296bea --- /dev/null +++ b/json_serializable/test/default_value/implicit_default_value.dart @@ -0,0 +1,59 @@ +import 'package:json_annotation/json_annotation.dart'; + +import 'default_value_interface.dart'; +import 'default_value_interface.dart' as dvi hide Greek; + +part 'implicit_default_value.g.dart'; + +dvi.DefaultValue fromJson(Map json) => + _$DefaultValueImplicitFromJson(json); + +@JsonSerializable() +class DefaultValueImplicit implements dvi.DefaultValue { + @override + final bool fieldBool; + @override + final String fieldString; + @override + final int fieldInt; + @override + final double fieldDouble; + @override + final List fieldListEmpty; + @override + final Set fieldSetEmpty; + @override + final Map fieldMapEmpty; + @override + final List fieldListSimple; + @override + final Set fieldSetSimple; + @override + final Map fieldMapSimple; + @override + final Map> fieldMapListString; + @override + final Greek fieldEnum; + + DefaultValueImplicit({ + this.fieldBool = true, + this.fieldString = 'string', + this.fieldInt = 42, + this.fieldDouble = 3.14, + this.fieldListEmpty = const [], + this.fieldSetEmpty = const {}, + this.fieldMapEmpty = const {}, + this.fieldListSimple = const [1, 2, 3], + this.fieldSetSimple = const {'entry1', 'entry2'}, + this.fieldMapSimple = const {'answer': 42}, + this.fieldMapListString = const { + 'root': ['child'] + }, + this.fieldEnum = Greek.beta, + }); + + factory DefaultValueImplicit.fromJson(Map json) => + _$DefaultValueImplicitFromJson(json); + + Map toJson() => _$DefaultValueImplicitToJson(this); +} diff --git a/json_serializable/test/default_value/implicit_default_value.g.dart b/json_serializable/test/default_value/implicit_default_value.g.dart new file mode 100644 index 000000000..d56e93b5c --- /dev/null +++ b/json_serializable/test/default_value/implicit_default_value.g.dart @@ -0,0 +1,103 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'implicit_default_value.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +DefaultValueImplicit _$DefaultValueImplicitFromJson(Map json) { + return DefaultValueImplicit( + fieldBool: json['fieldBool'] as bool? ?? true, + fieldString: json['fieldString'] as String? ?? 'string', + fieldInt: json['fieldInt'] as int? ?? 42, + fieldDouble: (json['fieldDouble'] as num?)?.toDouble() ?? 3.14, + fieldListEmpty: json['fieldListEmpty'] as List? ?? const [], + fieldSetEmpty: + (json['fieldSetEmpty'] as List?)?.toSet() ?? const {}, + fieldMapEmpty: json['fieldMapEmpty'] as Map? ?? const {}, + fieldListSimple: (json['fieldListSimple'] as List?) + ?.map((e) => e as int) + .toList() ?? + const [1, 2, 3], + fieldSetSimple: (json['fieldSetSimple'] as List?) + ?.map((e) => e as String) + .toSet() ?? + const {'entry1', 'entry2'}, + fieldMapSimple: (json['fieldMapSimple'] as Map?)?.map( + (k, e) => MapEntry(k, e as int), + ) ?? + const {'answer': 42}, + fieldMapListString: + (json['fieldMapListString'] as Map?)?.map( + (k, e) => MapEntry( + k, (e as List).map((e) => e as String).toList()), + ) ?? + const { + 'root': ['child'] + }, + fieldEnum: + _$enumDecodeNullable(_$GreekEnumMap, json['fieldEnum']) ?? Greek.beta, + ); +} + +Map _$DefaultValueImplicitToJson( + DefaultValueImplicit instance) => + { + 'fieldBool': instance.fieldBool, + 'fieldString': instance.fieldString, + 'fieldInt': instance.fieldInt, + 'fieldDouble': instance.fieldDouble, + 'fieldListEmpty': instance.fieldListEmpty, + 'fieldSetEmpty': instance.fieldSetEmpty.toList(), + 'fieldMapEmpty': instance.fieldMapEmpty, + 'fieldListSimple': instance.fieldListSimple, + 'fieldSetSimple': instance.fieldSetSimple.toList(), + 'fieldMapSimple': instance.fieldMapSimple, + 'fieldMapListString': instance.fieldMapListString, + 'fieldEnum': _$GreekEnumMap[instance.fieldEnum], + }; + +K _$enumDecode( + Map enumValues, + Object? source, { + K? unknownValue, +}) { + if (source == null) { + throw ArgumentError( + 'A value must be provided. Supported values: ' + '${enumValues.values.join(', ')}', + ); + } + + return enumValues.entries.singleWhere( + (e) => e.value == source, + orElse: () { + if (unknownValue == null) { + throw ArgumentError( + '`$source` is not one of the supported values: ' + '${enumValues.values.join(', ')}', + ); + } + return MapEntry(unknownValue, enumValues.values.first); + }, + ).key; +} + +K? _$enumDecodeNullable( + Map enumValues, + dynamic source, { + K? unknownValue, +}) { + if (source == null) { + return null; + } + return _$enumDecode(enumValues, source, unknownValue: unknownValue); +} + +const _$GreekEnumMap = { + Greek.alpha: 'alpha', + Greek.beta: 'beta', + Greek.gamma: 'gamma', + Greek.delta: 'delta', +}; diff --git a/json_serializable/test/json_serializable_test.dart b/json_serializable/test/json_serializable_test.dart index 724f13361..0f2a893dc 100644 --- a/json_serializable/test/json_serializable_test.dart +++ b/json_serializable/test/json_serializable_test.dart @@ -29,6 +29,7 @@ const _expectedAnnotatedTests = { 'BadOneNamed', 'BadToFuncReturnType', 'BadTwoRequiredPositional', + 'CtorDefaultValueAndJsonKeyDefaultValue', 'DefaultDoubleConstants', 'DefaultWithConstObject', 'DefaultWithDisallowNullRequiredClass', diff --git a/json_serializable/test/src/default_value_input.dart b/json_serializable/test/src/default_value_input.dart index f15739b2f..bc608a156 100644 --- a/json_serializable/test/src/default_value_input.dart +++ b/json_serializable/test/src/default_value_input.dart @@ -122,6 +122,30 @@ class DefaultWithDisallowNullRequiredClass { DefaultWithDisallowNullRequiredClass(); } +@ShouldGenerate( + r''' +CtorDefaultValueAndJsonKeyDefaultValue + _$CtorDefaultValueAndJsonKeyDefaultValueFromJson( + Map json) { + return CtorDefaultValueAndJsonKeyDefaultValue( + json['theField'] as int? ?? 7, + ); +} +''', + expectedLogItems: [ + 'The constructor parameter for `theField` has a default value `6`, but the ' + '`JsonKey.defaultValue` value `7` will be used for missing or `null` ' + 'values in JSON decoding.', + ], +) +@JsonSerializable(createToJson: false) +class CtorDefaultValueAndJsonKeyDefaultValue { + @JsonKey(defaultValue: 7) + final int theField; + + CtorDefaultValueAndJsonKeyDefaultValue([this.theField = 6]); +} + @ShouldGenerate(r''' DefaultDoubleConstants _$DefaultDoubleConstantsFromJson( Map json) { From 410988e92b302014dd41304e32622bec8b57ee0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asc=C3=AAnio?= Date: Thu, 1 Apr 2021 17:10:43 -0300 Subject: [PATCH 291/569] Adds const constructor to JsonConverter (#850) --- json_annotation/lib/src/json_converter.dart | 2 ++ 1 file changed, 2 insertions(+) diff --git a/json_annotation/lib/src/json_converter.dart b/json_annotation/lib/src/json_converter.dart index ef1fddf91..ef98f3f27 100644 --- a/json_annotation/lib/src/json_converter.dart +++ b/json_annotation/lib/src/json_converter.dart @@ -9,6 +9,8 @@ /// [S] is the type of the value stored in JSON. It must be a valid JSON type /// such as [String], [int], or [Map]. abstract class JsonConverter { + const JsonConverter(); + T fromJson(S json); S toJson(T object); } From c72dd11eaafa448272e38c6b3b98d362c21ffc64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asc=C3=AAnio?= Date: Thu, 1 Apr 2021 17:11:15 -0300 Subject: [PATCH 292/569] Improves private names of functions (#851) Changes naming of `toJson` and `fromJson` such that this: ```dart class _Person { // ... } ``` generates this: ```dart _Person _$PersonFromJson(Map json) {} Map _$PersonToJson(Person instance) {} ``` instead of this: ```dart _Person _$_PersonFromJson(Map json) {} Map _$_PersonToJson(Person instance) {} ``` Closes #619. --- json_serializable/CHANGELOG.md | 1 + json_serializable/lib/src/helper_core.dart | 2 +- json_serializable/lib/src/utils.dart | 2 ++ .../test/json_serializable_test.dart | 1 + .../test/src/to_from_json_test_input.dart | 21 +++++++++++++++++++ json_serializable/test/utils_test.dart | 11 ++++++++++ 6 files changed, 37 insertions(+), 1 deletion(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 67c40c125..e518bc615 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -3,6 +3,7 @@ - Use the default value for optional constructor parameters if `JsonKey.defaultValue` is not provided. This could be a breaking behavior change in generated code in some cases. +- Improve names of private classes' `toJson` and `fromJson`. ## 4.1.0 diff --git a/json_serializable/lib/src/helper_core.dart b/json_serializable/lib/src/helper_core.dart index ce1670a71..b79a7a1de 100644 --- a/json_serializable/lib/src/helper_core.dart +++ b/json_serializable/lib/src/helper_core.dart @@ -37,7 +37,7 @@ abstract class HelperCore { escapeDartString(nameAccess(field)); @protected - String get prefix => '_\$${element.name}'; + String get prefix => '_\$${nonPrivateName(element.name)}'; /// Returns a [String] representing the type arguments that exist on /// [element]. diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index e9e46c2df..b01fcd5ff 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -52,6 +52,8 @@ String _fixCase(String input, String separator) => return lower; }); +String nonPrivateName(String input) => input.replaceFirst(RegExp(r'^_*'), ''); + Never throwUnsupported(FieldElement element, String message) => throw InvalidGenerationSourceError( 'Error with `@JsonKey` on `${element.name}`. $message', diff --git a/json_serializable/test/json_serializable_test.dart b/json_serializable/test/json_serializable_test.dart index 0f2a893dc..a61922315 100644 --- a/json_serializable/test/json_serializable_test.dart +++ b/json_serializable/test/json_serializable_test.dart @@ -29,6 +29,7 @@ const _expectedAnnotatedTests = { 'BadOneNamed', 'BadToFuncReturnType', 'BadTwoRequiredPositional', + '_BetterPrivateNames', 'CtorDefaultValueAndJsonKeyDefaultValue', 'DefaultDoubleConstants', 'DefaultWithConstObject', diff --git a/json_serializable/test/src/to_from_json_test_input.dart b/json_serializable/test/src/to_from_json_test_input.dart index 40c997e3a..ef879fa28 100644 --- a/json_serializable/test/src/to_from_json_test_input.dart +++ b/json_serializable/test/src/to_from_json_test_input.dart @@ -262,3 +262,24 @@ class OkayOnlyOptionalPositional { @JsonKey(fromJson: _onlyOptionalPositional) String? field; } + +@ShouldGenerate( + r''' +_BetterPrivateNames _$BetterPrivateNamesFromJson(Map json) { + return _BetterPrivateNames( + name: json['name'] as String, + ); +} + +Map _$BetterPrivateNamesToJson(_BetterPrivateNames instance) => + { + 'name': instance.name, + }; +''', +) +@JsonSerializable(createFactory: true, createToJson: true) +// ignore: unused_element +class _BetterPrivateNames { + final String name; + _BetterPrivateNames({required this.name}); +} diff --git a/json_serializable/test/utils_test.dart b/json_serializable/test/utils_test.dart index aedc7d0a1..4b46b14cd 100644 --- a/json_serializable/test/utils_test.dart +++ b/json_serializable/test/utils_test.dart @@ -50,4 +50,15 @@ void main() { }); } }); + + group('nonPrivateName', () { + test('removes leading underscores', () { + final name = nonPrivateName('__hello__world__'); + expect(name, equals('hello__world__')); + }); + test('does not changes public names', () { + final name = nonPrivateName('HelloWorld'); + expect(name, equals('HelloWorld')); + }); + }); } From 6d7ccf80f92bc63381ef670524e4caf6319f7e88 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 1 Apr 2021 13:54:12 -0700 Subject: [PATCH 293/569] json_annotation: update changelog and pubspec (#858) Follow-up to 410988e92b302014dd41304e32622bec8b57ee0d --- json_annotation/CHANGELOG.md | 4 ++++ json_annotation/pubspec.yaml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index 7a4ed529c..763a2b4c8 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -1,3 +1,7 @@ +## 4.0.2-dev + +- Added a `const` constructor to `JsonConverter`. + ## 4.0.1 - Fix a potential error with `checked: true` when `ArgumentError.message` is diff --git a/json_annotation/pubspec.yaml b/json_annotation/pubspec.yaml index 62e04e7ba..aa40c163d 100644 --- a/json_annotation/pubspec.yaml +++ b/json_annotation/pubspec.yaml @@ -1,5 +1,5 @@ name: json_annotation -version: 4.0.1 +version: 4.0.2-dev description: >- Classes and helper functions that support JSON code generation via the `json_serializable` package. From 47a4db659e1c6de9b5636c11adf7bc3d5f837e9d Mon Sep 17 00:00:00 2001 From: Simon Lightfoot Date: Sun, 4 Apr 2021 01:03:45 +0100 Subject: [PATCH 294/569] Add build_runner and null safety note to README.md. (#848) --- json_serializable/README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/json_serializable/README.md b/json_serializable/README.md index 09b5f2897..0875b8876 100644 --- a/json_serializable/README.md +++ b/json_serializable/README.md @@ -1,5 +1,7 @@ [![Pub Package](https://img.shields.io/pub/v/json_serializable.svg)](https://pub.dev/packages/json_serializable) +> This project now produces null-safe code and itself does not need to be null-safe. + Provides [Dart Build System] builders for handling JSON. The builders generate code when they find members annotated with classes defined @@ -62,6 +64,13 @@ Map _$PersonToJson(Person instance) => { }; ``` +# Running the code generator + +Once you have added the annotations to your code you then need to run the +code generator to generate the missing `.g.dart` generated dart files. + +With Flutter you run `flutter pub run build_runner build` in your project directory. + # Annotation values The only annotation required to use this package is `@JsonSerializable`. When From dd14f777d195ece6c51f1f28cc07321a95767038 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Sat, 3 Apr 2021 17:15:14 -0700 Subject: [PATCH 295/569] more doc tweaks (#860) --- json_serializable/README.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/json_serializable/README.md b/json_serializable/README.md index 0875b8876..9c3f204bb 100644 --- a/json_serializable/README.md +++ b/json_serializable/README.md @@ -1,6 +1,7 @@ [![Pub Package](https://img.shields.io/pub/v/json_serializable.svg)](https://pub.dev/packages/json_serializable) -> This project now produces null-safe code and itself does not need to be null-safe. +> `json_serializable` produces null-safe code. We are waiting for dependencies +> to be migrated before it will appear "null-safe" on `pub.dev`. Provides [Dart Build System] builders for handling JSON. @@ -69,7 +70,11 @@ Map _$PersonToJson(Person instance) => { Once you have added the annotations to your code you then need to run the code generator to generate the missing `.g.dart` generated dart files. -With Flutter you run `flutter pub run build_runner build` in your project directory. + +With a Dart package, run `pub run build_runner build` in the package directory. + +With a Flutter package, run `flutter pub run build_runner build` in your package +directory. # Annotation values From 9863978fa9fe427c846bf714879b5c5bb22e61e0 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Sat, 3 Apr 2021 17:19:05 -0700 Subject: [PATCH 296/569] more readme doc fixes (#861) --- README.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 6ce98913d..71469be89 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ [![Dart CI](https://github.com/google/json_serializable.dart/workflows/Dart%20CI/badge.svg)](https://github.com/google/json_serializable.dart/actions?query=workflow%3A%22Dart+CI%22) -Provides [source_gen] `Generator`s to create code for JSON serialization and -deserialization. +Provides [Dart Build System] builders for handling JSON. ## json_serializable [![Pub Package](https://img.shields.io/pub/v/json_serializable.svg)](https://pub.dev/packages/json_serializable) @@ -35,7 +34,7 @@ Import it into your pubspec `dependencies:` section. - [Source code](example) -An example showing how to setup and use `json_serializable` and +An example showing how to set up and use `json_serializable` and `json_annotation`. -[source_gen]: https://pub.dev/packages/source_gen +[dart build system]: https://github.com/dart-lang/build From df60c2a95c4c0054d6ab785849937d7f5ade39fe Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 5 Apr 2021 08:27:33 -0700 Subject: [PATCH 297/569] Use pkg:source_helper (#859) --- json_serializable/CHANGELOG.md | 3 + json_serializable/lib/src/decode_helper.dart | 1 + json_serializable/lib/src/encoder_helper.dart | 2 +- json_serializable/lib/src/field_helpers.dart | 3 +- json_serializable/lib/src/helper_core.dart | 1 + json_serializable/lib/src/json_key_utils.dart | 1 + .../lib/src/json_literal_generator.dart | 3 +- .../lib/src/shared_checkers.dart | 20 +-- .../lib/src/type_helper_ctx.dart | 1 + .../lib/src/type_helpers/big_int_helper.dart | 2 +- .../lib/src/type_helpers/convert_helper.dart | 2 +- .../src/type_helpers/date_time_helper.dart | 2 +- .../lib/src/type_helpers/duration_helper.dart | 2 +- .../lib/src/type_helpers/enum_helper.dart | 1 + .../type_helpers/generic_factory_helper.dart | 2 +- .../lib/src/type_helpers/iterable_helper.dart | 2 +- .../type_helpers/json_converter_helper.dart | 2 +- .../lib/src/type_helpers/json_helper.dart | 1 + .../lib/src/type_helpers/map_helper.dart | 6 +- .../lib/src/type_helpers/uri_helper.dart | 2 +- .../lib/src/type_helpers/value_helper.dart | 2 +- json_serializable/lib/src/utils.dart | 116 ------------------ json_serializable/lib/type_helper.dart | 2 +- json_serializable/pubspec.yaml | 1 + 24 files changed, 29 insertions(+), 151 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index e518bc615..0ffa47fd5 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -4,6 +4,9 @@ `JsonKey.defaultValue` is not provided. This could be a breaking behavior change in generated code in some cases. - Improve names of private classes' `toJson` and `fromJson`. +- `type_helper.dart`: + - **BREAKING**: removed `typeArgumentsOf`. This is now an extension exposed + by `package:source_helper`. ## 4.1.0 diff --git a/json_serializable/lib/src/decode_helper.dart b/json_serializable/lib/src/decode_helper.dart index 024adbb93..ac587eae3 100644 --- a/json_serializable/lib/src/decode_helper.dart +++ b/json_serializable/lib/src/decode_helper.dart @@ -6,6 +6,7 @@ import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/nullability_suffix.dart'; import 'package:build/build.dart'; import 'package:source_gen/source_gen.dart'; +import 'package:source_helper/source_helper.dart'; import 'helper_core.dart'; import 'json_literal_generator.dart'; diff --git a/json_serializable/lib/src/encoder_helper.dart b/json_serializable/lib/src/encoder_helper.dart index 6ea548781..660ab4938 100644 --- a/json_serializable/lib/src/encoder_helper.dart +++ b/json_serializable/lib/src/encoder_helper.dart @@ -5,13 +5,13 @@ import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/nullability_suffix.dart'; import 'package:json_annotation/json_annotation.dart'; +import 'package:source_helper/source_helper.dart'; import 'constants.dart'; import 'helper_core.dart'; import 'type_helpers/generic_factory_helper.dart'; import 'type_helpers/json_converter_helper.dart'; import 'unsupported_type_error.dart'; -import 'utils.dart'; abstract class EncodeHelper implements HelperCore { String _fieldAccess(FieldElement field) => '$_toJsonParamName.${field.name}'; diff --git a/json_serializable/lib/src/field_helpers.dart b/json_serializable/lib/src/field_helpers.dart index 83b293c90..e479c4d10 100644 --- a/json_serializable/lib/src/field_helpers.dart +++ b/json_serializable/lib/src/field_helpers.dart @@ -81,8 +81,7 @@ Iterable createSortedFieldSet(ClassElement element) { final inheritedFields = {}; final manager = InheritanceManager3(); - // ignore: deprecated_member_use - for (final v in manager.getInheritedConcreteMap(element.thisType).values) { + for (final v in manager.getInheritedConcreteMap2(element).values) { assert(v is! FieldElement); if (_dartCoreObjectChecker.isExactly(v.enclosingElement)) { continue; diff --git a/json_serializable/lib/src/helper_core.dart b/json_serializable/lib/src/helper_core.dart index b79a7a1de..3780df9c7 100644 --- a/json_serializable/lib/src/helper_core.dart +++ b/json_serializable/lib/src/helper_core.dart @@ -6,6 +6,7 @@ import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/type.dart'; import 'package:meta/meta.dart'; import 'package:source_gen/source_gen.dart'; +import 'package:source_helper/source_helper.dart'; import 'constants.dart'; import 'json_key_utils.dart'; diff --git a/json_serializable/lib/src/json_key_utils.dart b/json_serializable/lib/src/json_key_utils.dart index e300ecd11..b0bce2eda 100644 --- a/json_serializable/lib/src/json_key_utils.dart +++ b/json_serializable/lib/src/json_key_utils.dart @@ -8,6 +8,7 @@ import 'package:analyzer/dart/element/type.dart'; import 'package:build/build.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:source_gen/source_gen.dart'; +import 'package:source_helper/source_helper.dart'; import 'json_literal_generator.dart'; import 'shared_checkers.dart'; diff --git a/json_serializable/lib/src/json_literal_generator.dart b/json_serializable/lib/src/json_literal_generator.dart index cf01a6852..f088e5f31 100644 --- a/json_serializable/lib/src/json_literal_generator.dart +++ b/json_serializable/lib/src/json_literal_generator.dart @@ -10,8 +10,7 @@ import 'package:build/build.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:path/path.dart' as p; import 'package:source_gen/source_gen.dart'; - -import 'utils.dart'; +import 'package:source_helper/source_helper.dart'; class JsonLiteralGenerator extends GeneratorForAnnotation { const JsonLiteralGenerator(); diff --git a/json_serializable/lib/src/shared_checkers.dart b/json_serializable/lib/src/shared_checkers.dart index 02decca75..b88635c19 100644 --- a/json_serializable/lib/src/shared_checkers.dart +++ b/json_serializable/lib/src/shared_checkers.dart @@ -3,11 +3,10 @@ // BSD-style license that can be found in the LICENSE file. import 'package:analyzer/dart/element/type.dart'; -import 'package:collection/collection.dart'; import 'package:source_gen/source_gen.dart' show TypeChecker; +import 'package:source_helper/source_helper.dart'; import 'helper_core.dart'; -import 'utils.dart'; /// A [TypeChecker] for [Iterable]. const coreIterableTypeChecker = TypeChecker.fromUrl('dart:core#Iterable'); @@ -20,17 +19,7 @@ const coreMapTypeChecker = TypeChecker.fromUrl('dart:core#Map'); /// /// If [type] does not extend [Iterable], an error is thrown. DartType coreIterableGenericType(DartType type) => - typeArgumentsOf(type, coreIterableTypeChecker).single; - -/// If [type] is the [Type] or implements the [Type] represented by [checker], -/// returns the generic arguments to the [checker] [Type] if there are any. -/// -/// If the [checker] [Type] doesn't have generic arguments, `null` is returned. -List typeArgumentsOf(DartType type, TypeChecker checker) { - final implementation = _getImplementationType(type, checker) as InterfaceType; - - return implementation.typeArguments; -} + type.typeArgumentsOf(coreIterableTypeChecker)!.single; /// A [TypeChecker] for [String], [bool] and [num]. const simpleJsonTypeChecker = TypeChecker.any([ @@ -54,7 +43,7 @@ String asStatement(DartType type) { } if (coreMapTypeChecker.isAssignableFromType(type)) { - final args = typeArgumentsOf(type, coreMapTypeChecker); + final args = type.typeArgumentsOf(coreMapTypeChecker)!; assert(args.length == 2); if (args.every((e) => e.isLikeDynamic)) { @@ -65,6 +54,3 @@ String asStatement(DartType type) { final typeCode = typeToCode(type); return ' as $typeCode'; } - -DartType? _getImplementationType(DartType type, TypeChecker checker) => - type.typeImplementations.firstWhereOrNull(checker.isExactlyType); diff --git a/json_serializable/lib/src/type_helper_ctx.dart b/json_serializable/lib/src/type_helper_ctx.dart index de0cb7b93..429603535 100644 --- a/json_serializable/lib/src/type_helper_ctx.dart +++ b/json_serializable/lib/src/type_helper_ctx.dart @@ -5,6 +5,7 @@ import 'package:analyzer/dart/constant/value.dart'; import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/type.dart'; +import 'package:source_helper/source_helper.dart'; import 'helper_core.dart'; import 'type_helper.dart'; diff --git a/json_serializable/lib/src/type_helpers/big_int_helper.dart b/json_serializable/lib/src/type_helpers/big_int_helper.dart index b2da21a27..935c75b77 100644 --- a/json_serializable/lib/src/type_helpers/big_int_helper.dart +++ b/json_serializable/lib/src/type_helpers/big_int_helper.dart @@ -3,9 +3,9 @@ // BSD-style license that can be found in the LICENSE file. import 'package:analyzer/dart/element/type.dart'; +import 'package:source_helper/source_helper.dart'; import '../type_helper.dart'; -import '../utils.dart'; import 'to_from_string.dart'; class BigIntHelper extends TypeHelper { diff --git a/json_serializable/lib/src/type_helpers/convert_helper.dart b/json_serializable/lib/src/type_helpers/convert_helper.dart index 8d31f9863..406e79f1c 100644 --- a/json_serializable/lib/src/type_helpers/convert_helper.dart +++ b/json_serializable/lib/src/type_helpers/convert_helper.dart @@ -3,10 +3,10 @@ // BSD-style license that can be found in the LICENSE file. import 'package:analyzer/dart/element/type.dart'; +import 'package:source_helper/source_helper.dart'; import '../shared_checkers.dart'; import '../type_helper.dart'; -import '../utils.dart'; /// Information used by [ConvertHelper] when handling `JsonKey`-annotated /// fields with `toJson` or `fromJson` values set. diff --git a/json_serializable/lib/src/type_helpers/date_time_helper.dart b/json_serializable/lib/src/type_helpers/date_time_helper.dart index d97bc17ac..d67b4b2e9 100644 --- a/json_serializable/lib/src/type_helpers/date_time_helper.dart +++ b/json_serializable/lib/src/type_helpers/date_time_helper.dart @@ -3,9 +3,9 @@ // BSD-style license that can be found in the LICENSE file. import 'package:analyzer/dart/element/type.dart'; +import 'package:source_helper/source_helper.dart'; import '../type_helper.dart'; -import '../utils.dart'; import 'to_from_string.dart'; class DateTimeHelper extends TypeHelper { diff --git a/json_serializable/lib/src/type_helpers/duration_helper.dart b/json_serializable/lib/src/type_helpers/duration_helper.dart index cf597a6be..2a1c534fa 100644 --- a/json_serializable/lib/src/type_helpers/duration_helper.dart +++ b/json_serializable/lib/src/type_helpers/duration_helper.dart @@ -4,9 +4,9 @@ import 'package:analyzer/dart/element/type.dart'; import 'package:source_gen/source_gen.dart' show TypeChecker; +import 'package:source_helper/source_helper.dart'; import '../type_helper.dart'; -import '../utils.dart'; class DurationHelper extends TypeHelper { const DurationHelper(); diff --git a/json_serializable/lib/src/type_helpers/enum_helper.dart b/json_serializable/lib/src/type_helpers/enum_helper.dart index c3aa4ba31..60a82699e 100644 --- a/json_serializable/lib/src/type_helpers/enum_helper.dart +++ b/json_serializable/lib/src/type_helpers/enum_helper.dart @@ -3,6 +3,7 @@ // BSD-style license that can be found in the LICENSE file. import 'package:analyzer/dart/element/type.dart'; +import 'package:source_helper/source_helper.dart'; import '../json_key_utils.dart'; import '../json_literal_generator.dart'; diff --git a/json_serializable/lib/src/type_helpers/generic_factory_helper.dart b/json_serializable/lib/src/type_helpers/generic_factory_helper.dart index 9f98cd6aa..3b807550c 100644 --- a/json_serializable/lib/src/type_helpers/generic_factory_helper.dart +++ b/json_serializable/lib/src/type_helpers/generic_factory_helper.dart @@ -3,10 +3,10 @@ // BSD-style license that can be found in the LICENSE file. import 'package:analyzer/dart/element/type.dart'; +import 'package:source_helper/source_helper.dart'; import '../lambda_result.dart'; import '../type_helper.dart'; -import '../utils.dart'; class GenericFactoryHelper extends TypeHelper { const GenericFactoryHelper(); diff --git a/json_serializable/lib/src/type_helpers/iterable_helper.dart b/json_serializable/lib/src/type_helpers/iterable_helper.dart index 4c26fb42e..88be86781 100644 --- a/json_serializable/lib/src/type_helpers/iterable_helper.dart +++ b/json_serializable/lib/src/type_helpers/iterable_helper.dart @@ -4,12 +4,12 @@ import 'package:analyzer/dart/element/type.dart'; import 'package:source_gen/source_gen.dart' show TypeChecker; +import 'package:source_helper/source_helper.dart'; import '../constants.dart'; import '../lambda_result.dart'; import '../shared_checkers.dart'; import '../type_helper.dart'; -import '../utils.dart'; class IterableHelper extends TypeHelper { const IterableHelper(); diff --git a/json_serializable/lib/src/type_helpers/json_converter_helper.dart b/json_serializable/lib/src/type_helpers/json_converter_helper.dart index 9c9044f40..0743dc140 100644 --- a/json_serializable/lib/src/type_helpers/json_converter_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_converter_helper.dart @@ -8,12 +8,12 @@ import 'package:analyzer/dart/element/type.dart'; import 'package:collection/collection.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:source_gen/source_gen.dart'; +import 'package:source_helper/source_helper.dart'; import '../helper_core.dart'; import '../lambda_result.dart'; import '../shared_checkers.dart'; import '../type_helper.dart'; -import '../utils.dart'; /// A [TypeHelper] that supports classes annotated with implementations of /// [JsonConverter]. diff --git a/json_serializable/lib/src/type_helpers/json_helper.dart b/json_serializable/lib/src/type_helpers/json_helper.dart index d746b1d6d..4628f92ce 100644 --- a/json_serializable/lib/src/type_helpers/json_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_helper.dart @@ -8,6 +8,7 @@ import 'package:analyzer/dart/element/type.dart'; import 'package:collection/collection.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:source_gen/source_gen.dart'; +import 'package:source_helper/source_helper.dart'; import '../type_helper.dart'; import '../utils.dart'; diff --git a/json_serializable/lib/src/type_helpers/map_helper.dart b/json_serializable/lib/src/type_helpers/map_helper.dart index 327cb2a02..efe2deddb 100644 --- a/json_serializable/lib/src/type_helpers/map_helper.dart +++ b/json_serializable/lib/src/type_helpers/map_helper.dart @@ -4,12 +4,12 @@ import 'package:analyzer/dart/element/type.dart'; import 'package:collection/collection.dart'; +import 'package:source_helper/source_helper.dart'; import '../constants.dart'; import '../shared_checkers.dart'; import '../type_helper.dart'; import '../unsupported_type_error.dart'; -import '../utils.dart'; import 'to_from_string.dart'; const _keyParam = 'k'; @@ -26,7 +26,7 @@ class MapHelper extends TypeHelper { if (!coreMapTypeChecker.isAssignableFromType(targetType)) { return null; } - final args = typeArgumentsOf(targetType, coreMapTypeChecker); + final args = targetType.typeArgumentsOf(coreMapTypeChecker)!; assert(args.length == 2); final keyType = args[0]; @@ -61,7 +61,7 @@ class MapHelper extends TypeHelper { return null; } - final typeArgs = typeArgumentsOf(targetType, coreMapTypeChecker); + final typeArgs = targetType.typeArgumentsOf(coreMapTypeChecker)!; assert(typeArgs.length == 2); final keyArg = typeArgs.first; final valueArg = typeArgs.last; diff --git a/json_serializable/lib/src/type_helpers/uri_helper.dart b/json_serializable/lib/src/type_helpers/uri_helper.dart index 28e40621e..cea9e285e 100644 --- a/json_serializable/lib/src/type_helpers/uri_helper.dart +++ b/json_serializable/lib/src/type_helpers/uri_helper.dart @@ -3,9 +3,9 @@ // BSD-style license that can be found in the LICENSE file. import 'package:analyzer/dart/element/type.dart'; +import 'package:source_helper/source_helper.dart'; import '../type_helper.dart'; -import '../utils.dart'; import 'to_from_string.dart'; class UriHelper extends TypeHelper { diff --git a/json_serializable/lib/src/type_helpers/value_helper.dart b/json_serializable/lib/src/type_helpers/value_helper.dart index 16719c656..c9c67fae0 100644 --- a/json_serializable/lib/src/type_helpers/value_helper.dart +++ b/json_serializable/lib/src/type_helpers/value_helper.dart @@ -3,11 +3,11 @@ // BSD-style license that can be found in the LICENSE file. import 'package:analyzer/dart/element/type.dart'; +import 'package:source_helper/source_helper.dart'; import '../helper_core.dart'; import '../shared_checkers.dart'; import '../type_helper.dart'; -import '../utils.dart'; class ValueHelper extends TypeHelper { const ValueHelper(); diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index b01fcd5ff..ca8d9555f 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -4,7 +4,6 @@ import 'package:analyzer/dart/constant/value.dart'; import 'package:analyzer/dart/element/element.dart'; -import 'package:analyzer/dart/element/nullability_suffix.dart'; import 'package:analyzer/dart/element/type.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:source_gen/source_gen.dart'; @@ -203,118 +202,3 @@ Map? enumFieldsMap(DartType targetType) { /// Otherwise, `null`. Iterable? iterateEnumFields(DartType targetType) => enumFieldsMap(targetType)?.keys; - -/// Returns a quoted String literal for [value] that can be used in generated -/// Dart code. -String escapeDartString(String value) { - var hasSingleQuote = false; - var hasDoubleQuote = false; - var hasDollar = false; - var canBeRaw = true; - - value = value.replaceAllMapped(_escapeRegExp, (match) { - final value = match[0]!; - if (value == "'") { - hasSingleQuote = true; - return value; - } else if (value == '"') { - hasDoubleQuote = true; - return value; - } else if (value == r'$') { - hasDollar = true; - return value; - } - - canBeRaw = false; - return _escapeMap[value] ?? _getHexLiteral(value); - }); - - if (!hasDollar) { - if (hasSingleQuote) { - if (!hasDoubleQuote) { - return '"$value"'; - } - // something - } else { - // trivial! - return "'$value'"; - } - } - - if (hasDollar && canBeRaw) { - if (hasSingleQuote) { - if (!hasDoubleQuote) { - // quote it with single quotes! - return 'r"$value"'; - } - } else { - // quote it with single quotes! - return "r'$value'"; - } - } - - // The only safe way to wrap the content is to escape all of the - // problematic characters - `$`, `'`, and `"` - final string = value.replaceAll(_dollarQuoteRegexp, r'\'); - return "'$string'"; -} - -final _dollarQuoteRegexp = RegExp(r"""(?=[$'"])"""); - -/// A [Map] between whitespace characters & `\` and their escape sequences. -const _escapeMap = { - '\b': r'\b', // 08 - backspace - '\t': r'\t', // 09 - tab - '\n': r'\n', // 0A - new line - '\v': r'\v', // 0B - vertical tab - '\f': r'\f', // 0C - form feed - '\r': r'\r', // 0D - carriage return - '\x7F': r'\x7F', // delete - r'\': r'\\' // backslash -}; - -final _escapeMapRegexp = _escapeMap.keys.map(_getHexLiteral).join(); - -/// A [RegExp] that matches whitespace characters that should be escaped and -/// single-quote, double-quote, and `$` -final _escapeRegExp = RegExp('[\$\'"\\x00-\\x07\\x0E-\\x1F$_escapeMapRegexp]'); - -/// Given single-character string, return the hex-escaped equivalent. -String _getHexLiteral(String input) { - final rune = input.runes.single; - final value = rune.toRadixString(16).toUpperCase().padLeft(2, '0'); - return '\\x$value'; -} - -extension DartTypeExtension on DartType { - bool isAssignableTo(DartType other) => - // If the library is `null`, treat it like dynamic => `true` - element!.library == null || - element!.library!.typeSystem.isAssignableTo(this, other); - - bool get isEnum => - this is InterfaceType && (this as InterfaceType).element.isEnum; - - bool get isNullableType => - isDynamic || nullabilitySuffix == NullabilitySuffix.question; - - /// Returns `true` if `this` is `dynamic` or `Object?`. - bool get isLikeDynamic => (isDartCoreObject && isNullableType) || isDynamic; - - /// Returns all of the [DartType] types that `this` implements, mixes-in, and - /// extends, starting with `this` itself. - Iterable get typeImplementations sync* { - yield this; - - final myType = this; - - if (myType is InterfaceType) { - yield* myType.interfaces.expand((e) => e.typeImplementations); - yield* myType.mixins.expand((e) => e.typeImplementations); - - if (myType.superclass != null) { - yield* myType.superclass!.typeImplementations; - } - } - } -} diff --git a/json_serializable/lib/type_helper.dart b/json_serializable/lib/type_helper.dart index cb496d213..ab8a4c60a 100644 --- a/json_serializable/lib/type_helper.dart +++ b/json_serializable/lib/type_helper.dart @@ -2,7 +2,7 @@ // 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. -export 'src/shared_checkers.dart' show simpleJsonTypeChecker, typeArgumentsOf; +export 'src/shared_checkers.dart' show simpleJsonTypeChecker; export 'src/type_helper.dart' show TypeHelperContext, TypeHelperContextWithConfig, TypeHelper; export 'src/type_helpers/big_int_helper.dart'; diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 8258839b1..c81c306d6 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -19,6 +19,7 @@ dependencies: meta: ^1.3.0 path: ^1.8.0 source_gen: ^1.0.0 + source_helper: ^1.1.0 dev_dependencies: build_runner: ^1.0.0 From 818c48f82893764c7d6bee7f884a63d301310713 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 5 Apr 2021 12:07:46 -0700 Subject: [PATCH 298/569] Fix `fromJson` for `Map` fields with nullable values (#865) Closes https://github.com/google/json_serializable.dart/issues/864 --- json_serializable/CHANGELOG.md | 1 + .../lib/src/type_helpers/map_helper.dart | 2 +- .../test/supported_types/extra_map_test.dart | 38 +++++++++++++++++++ .../supported_types/input.type_map.g.dart | 30 +++++++-------- 4 files changed, 55 insertions(+), 16 deletions(-) create mode 100644 json_serializable/test/supported_types/extra_map_test.dart diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 0ffa47fd5..9eac16150 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -3,6 +3,7 @@ - Use the default value for optional constructor parameters if `JsonKey.defaultValue` is not provided. This could be a breaking behavior change in generated code in some cases. +- Fixed `fromJson` for `Map` fields with nullable values. - Improve names of private classes' `toJson` and `fromJson`. - `type_helper.dart`: - **BREAKING**: removed `typeArgumentsOf`. This is now an extension exposed diff --git a/json_serializable/lib/src/type_helpers/map_helper.dart b/json_serializable/lib/src/type_helpers/map_helper.dart index efe2deddb..9656e287b 100644 --- a/json_serializable/lib/src/type_helpers/map_helper.dart +++ b/json_serializable/lib/src/type_helpers/map_helper.dart @@ -92,7 +92,7 @@ class MapHelper extends TypeHelper { (valueArgIsAny || simpleJsonTypeChecker.isAssignableFromType(valueArg))) { // No mapping of the values or null check required! - final valueString = valueArg.getDisplayString(withNullability: false); + final valueString = valueArg.getDisplayString(withNullability: true); return 'Map.from($expression as Map)'; } } diff --git a/json_serializable/test/supported_types/extra_map_test.dart b/json_serializable/test/supported_types/extra_map_test.dart new file mode 100644 index 000000000..78a1af821 --- /dev/null +++ b/json_serializable/test/supported_types/extra_map_test.dart @@ -0,0 +1,38 @@ +// 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. + +// ignore_for_file: prefer_const_declarations + +import 'dart:convert'; + +@TestOn('vm') +import 'package:test/test.dart'; + +import '../test_utils.dart'; +import 'input.type_map.dart' show SimpleClassOfStringToStringNullable; + +void main() { + for (var input in const >{ + {'value': {}}, + { + 'value': {'key': 'value'} + }, + { + // Regression case for https://github.com/google/json_serializable.dart/issues/864 + 'value': {'key': null} + }, + }) { + test(input, () { + final object = SimpleClassOfStringToStringNullable.fromJson(input); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(input)); + + final object2 = SimpleClassOfStringToStringNullable.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + } +} diff --git a/json_serializable/test/supported_types/input.type_map.g.dart b/json_serializable/test/supported_types/input.type_map.g.dart index 55608e727..40f73b767 100644 --- a/json_serializable/test/supported_types/input.type_map.g.dart +++ b/json_serializable/test/supported_types/input.type_map.g.dart @@ -885,7 +885,7 @@ Map _$SimpleClassNullableOfDateTimeToBoolNullableToJson( SimpleClassOfDynamicToBoolNullable _$SimpleClassOfDynamicToBoolNullableFromJson( Map json) { return SimpleClassOfDynamicToBoolNullable( - Map.from(json['value'] as Map), + Map.from(json['value'] as Map), ); } @@ -976,7 +976,7 @@ Map _$SimpleClassNullableOfIntToBoolNullableToJson( SimpleClassOfObjectToBoolNullable _$SimpleClassOfObjectToBoolNullableFromJson( Map json) { return SimpleClassOfObjectToBoolNullable( - Map.from(json['value'] as Map), + Map.from(json['value'] as Map), ); } @@ -1005,7 +1005,7 @@ Map _$SimpleClassNullableOfObjectToBoolNullableToJson( SimpleClassOfStringToBoolNullable _$SimpleClassOfStringToBoolNullableFromJson( Map json) { return SimpleClassOfStringToBoolNullable( - Map.from(json['value'] as Map), + Map.from(json['value'] as Map), ); } @@ -1889,7 +1889,7 @@ Map _$SimpleClassNullableOfDateTimeToDoubleNullableToJson( SimpleClassOfDynamicToDoubleNullable _$SimpleClassOfDynamicToDoubleNullableFromJson(Map json) { return SimpleClassOfDynamicToDoubleNullable( - Map.from(json['value'] as Map), + Map.from(json['value'] as Map), ); } @@ -1982,7 +1982,7 @@ Map _$SimpleClassNullableOfIntToDoubleNullableToJson( SimpleClassOfObjectToDoubleNullable _$SimpleClassOfObjectToDoubleNullableFromJson(Map json) { return SimpleClassOfObjectToDoubleNullable( - Map.from(json['value'] as Map), + Map.from(json['value'] as Map), ); } @@ -2011,7 +2011,7 @@ Map _$SimpleClassNullableOfObjectToDoubleNullableToJson( SimpleClassOfStringToDoubleNullable _$SimpleClassOfStringToDoubleNullableFromJson(Map json) { return SimpleClassOfStringToDoubleNullable( - Map.from(json['value'] as Map), + Map.from(json['value'] as Map), ); } @@ -3666,7 +3666,7 @@ Map _$SimpleClassNullableOfDateTimeToIntNullableToJson( SimpleClassOfDynamicToIntNullable _$SimpleClassOfDynamicToIntNullableFromJson( Map json) { return SimpleClassOfDynamicToIntNullable( - Map.from(json['value'] as Map), + Map.from(json['value'] as Map), ); } @@ -3756,7 +3756,7 @@ Map _$SimpleClassNullableOfIntToIntNullableToJson( SimpleClassOfObjectToIntNullable _$SimpleClassOfObjectToIntNullableFromJson( Map json) { return SimpleClassOfObjectToIntNullable( - Map.from(json['value'] as Map), + Map.from(json['value'] as Map), ); } @@ -3785,7 +3785,7 @@ Map _$SimpleClassNullableOfObjectToIntNullableToJson( SimpleClassOfStringToIntNullable _$SimpleClassOfStringToIntNullableFromJson( Map json) { return SimpleClassOfStringToIntNullable( - Map.from(json['value'] as Map), + Map.from(json['value'] as Map), ); } @@ -4140,7 +4140,7 @@ Map _$SimpleClassNullableOfDateTimeToNumNullableToJson( SimpleClassOfDynamicToNumNullable _$SimpleClassOfDynamicToNumNullableFromJson( Map json) { return SimpleClassOfDynamicToNumNullable( - Map.from(json['value'] as Map), + Map.from(json['value'] as Map), ); } @@ -4230,7 +4230,7 @@ Map _$SimpleClassNullableOfIntToNumNullableToJson( SimpleClassOfObjectToNumNullable _$SimpleClassOfObjectToNumNullableFromJson( Map json) { return SimpleClassOfObjectToNumNullable( - Map.from(json['value'] as Map), + Map.from(json['value'] as Map), ); } @@ -4259,7 +4259,7 @@ Map _$SimpleClassNullableOfObjectToNumNullableToJson( SimpleClassOfStringToNumNullable _$SimpleClassOfStringToNumNullableFromJson( Map json) { return SimpleClassOfStringToNumNullable( - Map.from(json['value'] as Map), + Map.from(json['value'] as Map), ); } @@ -5090,7 +5090,7 @@ Map _$SimpleClassNullableOfDateTimeToStringNullableToJson( SimpleClassOfDynamicToStringNullable _$SimpleClassOfDynamicToStringNullableFromJson(Map json) { return SimpleClassOfDynamicToStringNullable( - Map.from(json['value'] as Map), + Map.from(json['value'] as Map), ); } @@ -5181,7 +5181,7 @@ Map _$SimpleClassNullableOfIntToStringNullableToJson( SimpleClassOfObjectToStringNullable _$SimpleClassOfObjectToStringNullableFromJson(Map json) { return SimpleClassOfObjectToStringNullable( - Map.from(json['value'] as Map), + Map.from(json['value'] as Map), ); } @@ -5210,7 +5210,7 @@ Map _$SimpleClassNullableOfObjectToStringNullableToJson( SimpleClassOfStringToStringNullable _$SimpleClassOfStringToStringNullableFromJson(Map json) { return SimpleClassOfStringToStringNullable( - Map.from(json['value'] as Map), + Map.from(json['value'] as Map), ); } From 6205487b0fabbae5e9362f2ff160748f718c4e2c Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 8 Apr 2021 11:03:56 -0700 Subject: [PATCH 299/569] Add and use a new $checkedCreate function in json_annotation (#866) Will allow us to remove $checkedNew and $checkedConvert in the next breaking change of pkg:json_annotation --- _test_yaml/test/src/build_config.g.dart | 31 ++++--- json_annotation/CHANGELOG.md | 4 +- json_annotation/lib/src/checked_helpers.dart | 23 ++++++ json_annotation/pubspec.yaml | 2 +- json_serializable/CHANGELOG.md | 4 +- json_serializable/README.md | 38 ++++----- json_serializable/doc/doc.md | 38 ++++----- json_serializable/lib/src/decode_helper.dart | 8 +- json_serializable/pubspec.yaml | 6 +- .../default_value.g_any_map__checked.g.dart | 28 +++---- .../kitchen_sink.g_any_map__checked.g.dart | 82 ++++++++----------- .../test/src/checked_test_input.dart | 4 +- 12 files changed, 138 insertions(+), 130 deletions(-) diff --git a/_test_yaml/test/src/build_config.g.dart b/_test_yaml/test/src/build_config.g.dart index 813cea427..3500768b8 100644 --- a/_test_yaml/test/src/build_config.g.dart +++ b/_test_yaml/test/src/build_config.g.dart @@ -7,18 +7,16 @@ part of 'build_config.dart'; // ************************************************************************** Config _$ConfigFromJson(Map json) { - return $checkedNew('Config', json, () { + return $checkedCreate('Config', json, ($checkedConvert) { $checkKeys(json, requiredKeys: const ['builders']); final val = Config( builders: $checkedConvert( - json, 'builders', (v) => (v as Map).map( (k, e) => MapEntry(k as String, Builder.fromJson(e as Map)), )), ); $checkedConvert( - json, 'weights', (v) => val.weights = (v as Map?)?.map( (k, e) => MapEntry(_$enumDecode(_$AutoApplyEnumMap, k), e as int), @@ -67,7 +65,7 @@ const _$AutoApplyEnumMap = { }; Builder _$BuilderFromJson(Map json) { - return $checkedNew('Builder', json, () { + return $checkedCreate('Builder', json, ($checkedConvert) { $checkKeys(json, allowedKeys: const [ 'target', 'import', @@ -85,30 +83,29 @@ Builder _$BuilderFromJson(Map json) { 'auto_apply' ]); final val = Builder( - import: $checkedConvert(json, 'import', (v) => v as String), - target: $checkedConvert(json, 'target', (v) => v as String?), - isOptional: $checkedConvert(json, 'is_optional', (v) => v as bool?), - autoApply: $checkedConvert(json, 'auto_apply', - (v) => _$enumDecodeNullable(_$AutoApplyEnumMap, v)), + import: $checkedConvert('import', (v) => v as String), + target: $checkedConvert('target', (v) => v as String?), + isOptional: $checkedConvert('is_optional', (v) => v as bool?), + autoApply: $checkedConvert( + 'auto_apply', (v) => _$enumDecodeNullable(_$AutoApplyEnumMap, v)), buildTo: $checkedConvert( - json, 'build_to', (v) => _$enumDecodeNullable(_$BuildToEnumMap, v)), - defaultEnumTest: $checkedConvert(json, 'defaultEnumTest', + 'build_to', (v) => _$enumDecodeNullable(_$BuildToEnumMap, v)), + defaultEnumTest: $checkedConvert('defaultEnumTest', (v) => _$enumDecodeNullable(_$AutoApplyEnumMap, v)), - builderFactories: $checkedConvert(json, 'builder_factories', + builderFactories: $checkedConvert('builder_factories', (v) => (v as List).map((e) => e as String).toList()), - appliesBuilders: $checkedConvert(json, 'applies_builders', + appliesBuilders: $checkedConvert('applies_builders', (v) => (v as List?)?.map((e) => e as String).toList()), - requiredInputs: $checkedConvert(json, 'required_inputs', + requiredInputs: $checkedConvert('required_inputs', (v) => (v as List?)?.map((e) => e as String).toList()), buildExtensions: $checkedConvert( - json, 'build_extensions', (v) => (v as Map?)?.map( (k, e) => MapEntry(k as String, (e as List).map((e) => e as String).toList()), )), - configLocation: $checkedConvert(json, 'configLocation', - (v) => v == null ? null : Uri.parse(v as String)), + configLocation: $checkedConvert( + 'configLocation', (v) => v == null ? null : Uri.parse(v as String)), ); return val; }, fieldKeyMap: const { diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index 763a2b4c8..dfc70d0b0 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -1,6 +1,8 @@ -## 4.0.2-dev +## 4.1.0-dev - Added a `const` constructor to `JsonConverter`. +- Added `$checkedCreate` helper that will be used by `package:json_serializable` + v5+ and replaces both `$checkedNew` and `$checkedConvert`. ## 4.0.1 diff --git a/json_annotation/lib/src/checked_helpers.dart b/json_annotation/lib/src/checked_helpers.dart index 4d5e7e4aa..7a214f9ad 100644 --- a/json_annotation/lib/src/checked_helpers.dart +++ b/json_annotation/lib/src/checked_helpers.dart @@ -4,6 +4,29 @@ import 'allowed_keys_helpers.dart'; +typedef _CastFunction = R Function(Object?); + +/// Helper function used in generated code when +/// `JsonSerializableGenerator.checked` is `true`. +/// +/// Should not be used directly. +T $checkedCreate( + String className, + Map map, + T Function(S Function(String, _CastFunction) converter) constructor, { + Map fieldKeyMap = const {}, +}) { + Q _checkedConvert(String key, _CastFunction convertFunction) => + $checkedConvert(map, key, convertFunction); + + return $checkedNew( + className, + map, + () => constructor(_checkedConvert), + fieldKeyMap: fieldKeyMap, + ); +} + /// Helper function used in generated code when /// `JsonSerializableGenerator.checked` is `true`. /// diff --git a/json_annotation/pubspec.yaml b/json_annotation/pubspec.yaml index aa40c163d..dfdd789a1 100644 --- a/json_annotation/pubspec.yaml +++ b/json_annotation/pubspec.yaml @@ -1,5 +1,5 @@ name: json_annotation -version: 4.0.2-dev +version: 4.1.0-dev description: >- Classes and helper functions that support JSON code generation via the `json_serializable` package. diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 9eac16150..6f1b28850 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -4,7 +4,9 @@ `JsonKey.defaultValue` is not provided. This could be a breaking behavior change in generated code in some cases. - Fixed `fromJson` for `Map` fields with nullable values. -- Improve names of private classes' `toJson` and `fromJson`. +- Improve names of private classes generated for `toJson` and `fromJson`. +- Use the new `$checkedCreate` helper exposed in `package:json_annotation` + v4.1+. - `type_helper.dart`: - **BREAKING**: removed `typeArgumentsOf`. This is now an extension exposed by `package:source_helper`. diff --git a/json_serializable/README.md b/json_serializable/README.md index 9c3f204bb..24056abb4 100644 --- a/json_serializable/README.md +++ b/json_serializable/README.md @@ -108,25 +108,25 @@ is generated: | | | [JsonKey.toJson] | | | | [JsonKey.unknownEnumValue] | -[JsonSerializable.anyMap]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonSerializable/anyMap.html -[JsonSerializable.checked]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonSerializable/checked.html -[JsonSerializable.createFactory]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonSerializable/createFactory.html -[JsonSerializable.createToJson]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonSerializable/createToJson.html -[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html -[JsonSerializable.explicitToJson]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonSerializable/explicitToJson.html -[JsonSerializable.fieldRename]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonSerializable/fieldRename.html -[JsonSerializable.genericArgumentFactories]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonSerializable/genericArgumentFactories.html -[JsonSerializable.ignoreUnannotated]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonSerializable/ignoreUnannotated.html -[JsonSerializable.includeIfNull]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonSerializable/includeIfNull.html -[JsonKey.includeIfNull]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonKey/includeIfNull.html -[JsonKey.defaultValue]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonKey/defaultValue.html -[JsonKey.disallowNullValue]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonKey/disallowNullValue.html -[JsonKey.fromJson]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonKey/fromJson.html -[JsonKey.ignore]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonKey/ignore.html -[JsonKey.name]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonKey/name.html -[JsonKey.required]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonKey/required.html -[JsonKey.toJson]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonKey/toJson.html -[JsonKey.unknownEnumValue]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonKey/unknownEnumValue.html +[JsonSerializable.anyMap]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/anyMap.html +[JsonSerializable.checked]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/checked.html +[JsonSerializable.createFactory]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/createFactory.html +[JsonSerializable.createToJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/createToJson.html +[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html +[JsonSerializable.explicitToJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/explicitToJson.html +[JsonSerializable.fieldRename]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/fieldRename.html +[JsonSerializable.genericArgumentFactories]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/genericArgumentFactories.html +[JsonSerializable.ignoreUnannotated]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/ignoreUnannotated.html +[JsonSerializable.includeIfNull]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/includeIfNull.html +[JsonKey.includeIfNull]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/includeIfNull.html +[JsonKey.defaultValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/defaultValue.html +[JsonKey.disallowNullValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/disallowNullValue.html +[JsonKey.fromJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/fromJson.html +[JsonKey.ignore]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/ignore.html +[JsonKey.name]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/name.html +[JsonKey.required]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/required.html +[JsonKey.toJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/toJson.html +[JsonKey.unknownEnumValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/unknownEnumValue.html > Note: every `JsonSerializable` field is configurable via `build.yaml` – > see the table for the corresponding key. diff --git a/json_serializable/doc/doc.md b/json_serializable/doc/doc.md index df1894032..386068764 100644 --- a/json_serializable/doc/doc.md +++ b/json_serializable/doc/doc.md @@ -19,22 +19,22 @@ | | | [JsonKey.toJson] | | | | [JsonKey.unknownEnumValue] | -[JsonSerializable.anyMap]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonSerializable/anyMap.html -[JsonSerializable.checked]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonSerializable/checked.html -[JsonSerializable.createFactory]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonSerializable/createFactory.html -[JsonSerializable.createToJson]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonSerializable/createToJson.html -[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html -[JsonSerializable.explicitToJson]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonSerializable/explicitToJson.html -[JsonSerializable.fieldRename]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonSerializable/fieldRename.html -[JsonSerializable.genericArgumentFactories]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonSerializable/genericArgumentFactories.html -[JsonSerializable.ignoreUnannotated]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonSerializable/ignoreUnannotated.html -[JsonSerializable.includeIfNull]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonSerializable/includeIfNull.html -[JsonKey.includeIfNull]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonKey/includeIfNull.html -[JsonKey.defaultValue]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonKey/defaultValue.html -[JsonKey.disallowNullValue]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonKey/disallowNullValue.html -[JsonKey.fromJson]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonKey/fromJson.html -[JsonKey.ignore]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonKey/ignore.html -[JsonKey.name]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonKey/name.html -[JsonKey.required]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonKey/required.html -[JsonKey.toJson]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonKey/toJson.html -[JsonKey.unknownEnumValue]: https://pub.dev/documentation/json_annotation/4.0.1/json_annotation/JsonKey/unknownEnumValue.html +[JsonSerializable.anyMap]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/anyMap.html +[JsonSerializable.checked]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/checked.html +[JsonSerializable.createFactory]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/createFactory.html +[JsonSerializable.createToJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/createToJson.html +[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html +[JsonSerializable.explicitToJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/explicitToJson.html +[JsonSerializable.fieldRename]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/fieldRename.html +[JsonSerializable.genericArgumentFactories]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/genericArgumentFactories.html +[JsonSerializable.ignoreUnannotated]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/ignoreUnannotated.html +[JsonSerializable.includeIfNull]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/includeIfNull.html +[JsonKey.includeIfNull]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/includeIfNull.html +[JsonKey.defaultValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/defaultValue.html +[JsonKey.disallowNullValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/disallowNullValue.html +[JsonKey.fromJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/fromJson.html +[JsonKey.ignore]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/ignore.html +[JsonKey.name]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/name.html +[JsonKey.required]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/required.html +[JsonKey.toJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/toJson.html +[JsonKey.unknownEnumValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/unknownEnumValue.html diff --git a/json_serializable/lib/src/decode_helper.dart b/json_serializable/lib/src/decode_helper.dart index ac587eae3..ed88546ed 100644 --- a/json_serializable/lib/src/decode_helper.dart +++ b/json_serializable/lib/src/decode_helper.dart @@ -77,10 +77,10 @@ abstract class DecodeHelper implements HelperCore { final classLiteral = escapeDartString(element.name); buffer..write(''' - return \$checkedNew( + return \$checkedCreate( $classLiteral, json, - () {\n''')..write(checks)..write(''' + (\$checkedConvert) {\n''')..write(checks)..write(''' final val = ${data.content};'''); for (final field in data.fieldsToSet) { @@ -88,7 +88,7 @@ abstract class DecodeHelper implements HelperCore { final safeName = safeNameAccess(accessibleFields[field]!); buffer ..write(''' - \$checkedConvert(json, $safeName, (v) => ''') + \$checkedConvert($safeName, (v) => ''') ..write('val.$field = ') ..write(_deserializeForField(accessibleFields[field]!, checkedProperty: true)) @@ -183,7 +183,7 @@ abstract class DecodeHelper implements HelperCore { ) .toString(); if (!checkedProperty) { - value = '\$checkedConvert(json, $jsonKeyName, (v) => $value)'; + value = '\$checkedConvert($jsonKeyName, (v) => $value)'; } } else { assert(!checkedProperty, diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index c81c306d6..52eb2069f 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -15,7 +15,7 @@ dependencies: # Use a tight version constraint to ensure that a constraint on # `json_annotation` properly constrains all features it provides. - json_annotation: '>=4.0.1 <4.1.0' + json_annotation: '>=4.1.0 <4.2.0' meta: ^1.3.0 path: ^1.8.0 source_gen: ^1.0.0 @@ -31,3 +31,7 @@ dev_dependencies: stack_trace: ^1.10.0 test: ^1.16.0 yaml: ^3.0.0 + +dependency_overrides: + json_annotation: + path: ../json_annotation diff --git a/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart b/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart index 678bab817..43320b911 100644 --- a/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart +++ b/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart @@ -7,33 +7,29 @@ part of 'default_value.g_any_map__checked.dart'; // ************************************************************************** DefaultValue _$DefaultValueFromJson(Map json) { - return $checkedNew('DefaultValue', json, () { + return $checkedCreate('DefaultValue', json, ($checkedConvert) { final val = DefaultValue( - $checkedConvert(json, 'fieldBool', (v) => v as bool?) ?? true, - $checkedConvert(json, 'fieldString', (v) => v as String?) ?? 'string', - $checkedConvert(json, 'fieldInt', (v) => v as int?) ?? 42, - $checkedConvert(json, 'fieldDouble', (v) => (v as num?)?.toDouble()) ?? - 3.14, - $checkedConvert(json, 'fieldListEmpty', (v) => v as List?) ?? [], - $checkedConvert( - json, 'fieldSetEmpty', (v) => (v as List?)?.toSet()) ?? + $checkedConvert('fieldBool', (v) => v as bool?) ?? true, + $checkedConvert('fieldString', (v) => v as String?) ?? 'string', + $checkedConvert('fieldInt', (v) => v as int?) ?? 42, + $checkedConvert('fieldDouble', (v) => (v as num?)?.toDouble()) ?? 3.14, + $checkedConvert('fieldListEmpty', (v) => v as List?) ?? [], + $checkedConvert('fieldSetEmpty', (v) => (v as List?)?.toSet()) ?? {}, - $checkedConvert(json, 'fieldMapEmpty', (v) => v as Map?) ?? {}, - $checkedConvert(json, 'fieldListSimple', + $checkedConvert('fieldMapEmpty', (v) => v as Map?) ?? {}, + $checkedConvert('fieldListSimple', (v) => (v as List?)?.map((e) => e as int).toList()) ?? [1, 2, 3], - $checkedConvert(json, 'fieldSetSimple', + $checkedConvert('fieldSetSimple', (v) => (v as List?)?.map((e) => e as String).toSet()) ?? {'entry1', 'entry2'}, $checkedConvert( - json, 'fieldMapSimple', (v) => (v as Map?)?.map( (k, e) => MapEntry(k as String, e as int), )) ?? {'answer': 42}, $checkedConvert( - json, 'fieldMapListString', (v) => (v as Map?)?.map( (k, e) => MapEntry(k as String, @@ -42,8 +38,8 @@ DefaultValue _$DefaultValueFromJson(Map json) { { 'root': ['child'] }, - $checkedConvert(json, 'fieldEnum', - (v) => _$enumDecodeNullable(_$GreekEnumMap, v)) ?? + $checkedConvert( + 'fieldEnum', (v) => _$enumDecodeNullable(_$GreekEnumMap, v)) ?? Greek.beta, ); return val; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.g.dart index 42562e25a..7795882c6 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.g.dart @@ -7,74 +7,65 @@ part of 'kitchen_sink.g_any_map__checked.dart'; // ************************************************************************** KitchenSink _$KitchenSinkFromJson(Map json) { - return $checkedNew('KitchenSink', json, () { + return $checkedCreate('KitchenSink', json, ($checkedConvert) { final val = KitchenSink( - ctorValidatedNo42: $checkedConvert(json, 'no-42', (v) => v as int?), - iterable: $checkedConvert(json, 'iterable', (v) => v as List?), + ctorValidatedNo42: $checkedConvert('no-42', (v) => v as int?), + iterable: $checkedConvert('iterable', (v) => v as List?), dynamicIterable: - $checkedConvert(json, 'dynamicIterable', (v) => v as List?), - objectIterable: $checkedConvert(json, 'objectIterable', + $checkedConvert('dynamicIterable', (v) => v as List?), + objectIterable: $checkedConvert('objectIterable', (v) => (v as List?)?.map((e) => e as Object)), - intIterable: $checkedConvert(json, 'intIterable', - (v) => (v as List?)?.map((e) => e as int)), + intIterable: $checkedConvert( + 'intIterable', (v) => (v as List?)?.map((e) => e as int)), dateTimeIterable: $checkedConvert( - json, 'datetime-iterable', (v) => (v as List?)?.map((e) => DateTime.parse(e as String))), ); - $checkedConvert(json, 'dateTime', + $checkedConvert('dateTime', (v) => val.dateTime = v == null ? null : DateTime.parse(v as String)); - $checkedConvert(json, 'bigInt', + $checkedConvert('bigInt', (v) => val.bigInt = v == null ? null : BigInt.parse(v as String)); - $checkedConvert(json, 'set', (v) => val.set = (v as List).toSet()); - $checkedConvert(json, 'dynamicSet', - (v) => val.dynamicSet = (v as List).toSet()); + $checkedConvert('set', (v) => val.set = (v as List).toSet()); + $checkedConvert( + 'dynamicSet', (v) => val.dynamicSet = (v as List).toSet()); $checkedConvert( - json, 'objectSet', (v) => val.objectSet = (v as List).map((e) => e as Object).toSet()); - $checkedConvert(json, 'intSet', + $checkedConvert('intSet', (v) => val.intSet = (v as List).map((e) => e as int).toSet()); $checkedConvert( - json, 'dateTimeSet', (v) => val.dateTimeSet = (v as List) .map((e) => DateTime.parse(e as String)) .toSet()); - $checkedConvert(json, 'list', (v) => val.list = v as List); - $checkedConvert( - json, 'dynamicList', (v) => val.dynamicList = v as List); + $checkedConvert('list', (v) => val.list = v as List); + $checkedConvert('dynamicList', (v) => val.dynamicList = v as List); $checkedConvert( - json, 'objectList', (v) => val.objectList = (v as List).map((e) => e as Object).toList()); $checkedConvert( - json, 'intList', (v) => val.intList = (v as List).map((e) => e as int).toList()); $checkedConvert( - json, 'dateTimeList', (v) => val.dateTimeList = (v as List) .map((e) => DateTime.parse(e as String)) .toList()); - $checkedConvert(json, 'map', (v) => val.map = v as Map); - $checkedConvert(json, 'stringStringMap', + $checkedConvert('map', (v) => val.map = v as Map); + $checkedConvert('stringStringMap', (v) => val.stringStringMap = Map.from(v as Map)); - $checkedConvert(json, 'dynamicIntMap', + $checkedConvert('dynamicIntMap', (v) => val.dynamicIntMap = Map.from(v as Map)); $checkedConvert( - json, 'objectDateTimeMap', (v) => val.objectDateTimeMap = (v as Map).map( (k, e) => MapEntry(k as Object, DateTime.parse(e as String)), )); $checkedConvert( - json, 'crazyComplex', (v) => val.crazyComplex = (v as List) .map((e) => (e as Map?)?.map( @@ -91,16 +82,15 @@ KitchenSink _$KitchenSinkFromJson(Map json) { )), )) .toList()); - $checkedConvert( - json, 'val', (v) => val.val = Map.from(v as Map)); - $checkedConvert(json, 'writeNotNull', (v) => val.writeNotNull = v as bool?); - $checkedConvert(json, r'$string', (v) => val.string = v as String?); - $checkedConvert(json, 'simpleObject', + $checkedConvert('val', (v) => val.val = Map.from(v as Map)); + $checkedConvert('writeNotNull', (v) => val.writeNotNull = v as bool?); + $checkedConvert(r'$string', (v) => val.string = v as String?); + $checkedConvert('simpleObject', (v) => val.simpleObject = SimpleObject.fromJson(v as Map)); - $checkedConvert(json, 'strictKeysObject', + $checkedConvert('strictKeysObject', (v) => val.strictKeysObject = StrictKeysObject.fromJson(v as Map)); - $checkedConvert(json, 'validatedPropertyNo42', - (v) => val.validatedPropertyNo42 = v as int?); + $checkedConvert( + 'validatedPropertyNo42', (v) => val.validatedPropertyNo42 = v as int?); return val; }, fieldKeyMap: const { 'ctorValidatedNo42': 'no-42', @@ -155,34 +145,30 @@ Map _$KitchenSinkToJson(KitchenSink instance) => }; JsonConverterTestClass _$JsonConverterTestClassFromJson(Map json) { - return $checkedNew('JsonConverterTestClass', json, () { + return $checkedCreate('JsonConverterTestClass', json, ($checkedConvert) { final val = JsonConverterTestClass( + $checkedConvert('duration', (v) => durationConverter.fromJson(v as int?)), $checkedConvert( - json, 'duration', (v) => durationConverter.fromJson(v as int?)), - $checkedConvert( - json, 'durationList', (v) => (v as List) .map((e) => durationConverter.fromJson(e as int?)) .toList()), - $checkedConvert(json, 'bigInt', - (v) => const BigIntStringConverter().fromJson(v as String)), $checkedConvert( - json, + 'bigInt', (v) => const BigIntStringConverter().fromJson(v as String)), + $checkedConvert( 'bigIntMap', (v) => (v as Map).map( (k, e) => MapEntry(k as String, const BigIntStringConverter().fromJson(e as String)), )), - $checkedConvert(json, 'numberSilly', + $checkedConvert('numberSilly', (v) => TrivialNumberConverter.instance.fromJson(v as int?)), $checkedConvert( - json, 'numberSillySet', (v) => (v as List) .map((e) => TrivialNumberConverter.instance.fromJson(e as int?)) .toSet()), - $checkedConvert(json, 'dateTime', + $checkedConvert('dateTime', (v) => const EpochDateTimeConverter().fromJson(v as int?)), ); return val; @@ -208,19 +194,17 @@ Map _$JsonConverterTestClassToJson( JsonConverterGeneric _$JsonConverterGenericFromJson( Map json) { - return $checkedNew('JsonConverterGeneric', json, () { + return $checkedCreate('JsonConverterGeneric', json, ($checkedConvert) { final val = JsonConverterGeneric( - $checkedConvert(json, 'item', + $checkedConvert('item', (v) => GenericConverter().fromJson(v as Map)), $checkedConvert( - json, 'itemList', (v) => (v as List) .map((e) => GenericConverter().fromJson(e as Map)) .toList()), $checkedConvert( - json, 'itemMap', (v) => (v as Map).map( (k, e) => MapEntry(k as String, diff --git a/json_serializable/test/src/checked_test_input.dart b/json_serializable/test/src/checked_test_input.dart index 9a87630c5..c15e4a937 100644 --- a/json_serializable/test/src/checked_test_input.dart +++ b/json_serializable/test/src/checked_test_input.dart @@ -3,13 +3,13 @@ part of '_json_serializable_test_input.dart'; @ShouldGenerate(r''' WithANonCtorGetterChecked _$WithANonCtorGetterCheckedFromJson( Map json) { - return $checkedNew('WithANonCtorGetterChecked', json, () { + return $checkedCreate('WithANonCtorGetterChecked', json, ($checkedConvert) { $checkKeys(json, allowedKeys: const ['items'], requiredKeys: const ['items'], disallowNullValues: const ['items']); final val = WithANonCtorGetterChecked( - $checkedConvert(json, 'items', + $checkedConvert('items', (v) => (v as List).map((e) => e as String).toList()), ); return val; From 2fdae9991a22da38f525c382182913f477e0c34a Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 8 Apr 2021 11:28:05 -0700 Subject: [PATCH 300/569] Generated code now complies with prefer_expression_function_bodies lint (#868) --- _test_yaml/test/src/build_config.g.dart | 150 +- analysis_options.yaml | 2 + .../lib/src/json_serializable.g.dart | 91 +- json_serializable/CHANGELOG.md | 1 + json_serializable/README.md | 16 +- json_serializable/example/example.g.dart | 16 +- json_serializable/lib/src/decode_helper.dart | 55 +- .../lib/src/json_literal_generator.dart | 5 +- .../test/default_value/default_value.g.dart | 60 +- .../default_value.g_any_map__checked.g.dart | 87 +- .../implicit_default_value.g.dart | 68 +- .../generic_argument_factories.g.dart | 40 +- ...generic_argument_factories_nullable.g.dart | 52 +- .../test/generic_files/generic_class.g.dart | 52 +- .../test/integration/json_test_example.g.dart | 154 +- .../json_test_example.g_any_map.g.dart | 152 +- .../test/kitchen_sink/kitchen_sink.g.dart | 183 +- .../kitchen_sink.g_any_map.g.dart | 179 +- .../kitchen_sink.g_any_map__checked.g.dart | 300 +- .../kitchen_sink.g_exclude_null.g.dart | 183 +- .../kitchen_sink.g_explicit_to_json.g.dart | 183 +- .../test/kitchen_sink/simple_object.g.dart | 8 +- .../kitchen_sink/strict_keys_object.g.dart | 8 +- .../src/_json_serializable_test_input.dart | 103 +- .../test/src/checked_test_input.dart | 39 +- .../test/src/default_value_input.dart | 52 +- .../test/src/generic_test_input.dart | 20 +- .../test/src/inheritance_test_input.dart | 14 +- .../test/src/json_converter_test_input.dart | 38 +- .../test/src/map_key_variety_test_input.dart | 11 +- .../test/src/setter_test_input.dart | 9 +- .../test/src/to_from_json_test_input.dart | 41 +- .../src/unknown_enum_value_test_input.dart | 13 +- .../test/supported_types/input.g.dart | 10 +- .../supported_types/input.type_bigint.g.dart | 17 +- .../supported_types/input.type_bool.g.dart | 21 +- .../input.type_datetime.g.dart | 17 +- .../supported_types/input.type_double.g.dart | 21 +- .../input.type_duration.g.dart | 19 +- .../input.type_enumtype.g.dart | 25 +- .../supported_types/input.type_int.g.dart | 21 +- .../input.type_iterable.g.dart | 469 +- .../supported_types/input.type_list.g.dart | 533 +- .../supported_types/input.type_map.g.dart | 4831 ++++++++--------- .../supported_types/input.type_num.g.dart | 21 +- .../supported_types/input.type_object.g.dart | 21 +- .../supported_types/input.type_set.g.dart | 533 +- .../supported_types/input.type_string.g.dart | 21 +- .../supported_types/input.type_uri.g.dart | 17 +- 49 files changed, 4262 insertions(+), 4720 deletions(-) diff --git a/_test_yaml/test/src/build_config.g.dart b/_test_yaml/test/src/build_config.g.dart index 3500768b8..e195a5aec 100644 --- a/_test_yaml/test/src/build_config.g.dart +++ b/_test_yaml/test/src/build_config.g.dart @@ -6,24 +6,30 @@ part of 'build_config.dart'; // JsonSerializableGenerator // ************************************************************************** -Config _$ConfigFromJson(Map json) { - return $checkedCreate('Config', json, ($checkedConvert) { - $checkKeys(json, requiredKeys: const ['builders']); - final val = Config( - builders: $checkedConvert( - 'builders', - (v) => (v as Map).map( - (k, e) => MapEntry(k as String, Builder.fromJson(e as Map)), - )), +Config _$ConfigFromJson(Map json) => $checkedCreate( + 'Config', + json, + ($checkedConvert) { + $checkKeys( + json, + requiredKeys: const ['builders'], + ); + final val = Config( + builders: $checkedConvert( + 'builders', + (v) => (v as Map).map( + (k, e) => MapEntry(k as String, Builder.fromJson(e as Map)), + )), + ); + $checkedConvert( + 'weights', + (v) => val.weights = (v as Map?)?.map( + (k, e) => + MapEntry(_$enumDecode(_$AutoApplyEnumMap, k), e as int), + )); + return val; + }, ); - $checkedConvert( - 'weights', - (v) => val.weights = (v as Map?)?.map( - (k, e) => MapEntry(_$enumDecode(_$AutoApplyEnumMap, k), e as int), - )); - return val; - }); -} Map _$ConfigToJson(Config instance) => { 'builders': instance.builders, @@ -64,60 +70,64 @@ const _$AutoApplyEnumMap = { AutoApply.rootPackage: 'root_package', }; -Builder _$BuilderFromJson(Map json) { - return $checkedCreate('Builder', json, ($checkedConvert) { - $checkKeys(json, allowedKeys: const [ - 'target', - 'import', - 'is_optional', - 'configLocation', - 'auto_apply', - 'build_to', - 'defaultEnumTest', - 'builder_factories', - 'applies_builders', - 'required_inputs', - 'build_extensions' - ], disallowNullValues: const [ - 'configLocation', - 'auto_apply' - ]); - final val = Builder( - import: $checkedConvert('import', (v) => v as String), - target: $checkedConvert('target', (v) => v as String?), - isOptional: $checkedConvert('is_optional', (v) => v as bool?), - autoApply: $checkedConvert( - 'auto_apply', (v) => _$enumDecodeNullable(_$AutoApplyEnumMap, v)), - buildTo: $checkedConvert( - 'build_to', (v) => _$enumDecodeNullable(_$BuildToEnumMap, v)), - defaultEnumTest: $checkedConvert('defaultEnumTest', - (v) => _$enumDecodeNullable(_$AutoApplyEnumMap, v)), - builderFactories: $checkedConvert('builder_factories', - (v) => (v as List).map((e) => e as String).toList()), - appliesBuilders: $checkedConvert('applies_builders', - (v) => (v as List?)?.map((e) => e as String).toList()), - requiredInputs: $checkedConvert('required_inputs', - (v) => (v as List?)?.map((e) => e as String).toList()), - buildExtensions: $checkedConvert( - 'build_extensions', - (v) => (v as Map?)?.map( - (k, e) => MapEntry(k as String, - (e as List).map((e) => e as String).toList()), - )), - configLocation: $checkedConvert( - 'configLocation', (v) => v == null ? null : Uri.parse(v as String)), +Builder _$BuilderFromJson(Map json) => $checkedCreate( + 'Builder', + json, + ($checkedConvert) { + $checkKeys( + json, + allowedKeys: const [ + 'target', + 'import', + 'is_optional', + 'configLocation', + 'auto_apply', + 'build_to', + 'defaultEnumTest', + 'builder_factories', + 'applies_builders', + 'required_inputs', + 'build_extensions' + ], + disallowNullValues: const ['configLocation', 'auto_apply'], + ); + final val = Builder( + import: $checkedConvert('import', (v) => v as String), + target: $checkedConvert('target', (v) => v as String?), + isOptional: $checkedConvert('is_optional', (v) => v as bool?), + autoApply: $checkedConvert( + 'auto_apply', (v) => _$enumDecodeNullable(_$AutoApplyEnumMap, v)), + buildTo: $checkedConvert( + 'build_to', (v) => _$enumDecodeNullable(_$BuildToEnumMap, v)), + defaultEnumTest: $checkedConvert('defaultEnumTest', + (v) => _$enumDecodeNullable(_$AutoApplyEnumMap, v)), + builderFactories: $checkedConvert('builder_factories', + (v) => (v as List).map((e) => e as String).toList()), + appliesBuilders: $checkedConvert('applies_builders', + (v) => (v as List?)?.map((e) => e as String).toList()), + requiredInputs: $checkedConvert('required_inputs', + (v) => (v as List?)?.map((e) => e as String).toList()), + buildExtensions: $checkedConvert( + 'build_extensions', + (v) => (v as Map?)?.map( + (k, e) => MapEntry(k as String, + (e as List).map((e) => e as String).toList()), + )), + configLocation: $checkedConvert('configLocation', + (v) => v == null ? null : Uri.parse(v as String)), + ); + return val; + }, + fieldKeyMap: const { + 'isOptional': 'is_optional', + 'autoApply': 'auto_apply', + 'buildTo': 'build_to', + 'builderFactories': 'builder_factories', + 'appliesBuilders': 'applies_builders', + 'requiredInputs': 'required_inputs', + 'buildExtensions': 'build_extensions' + }, ); - return val; - }, fieldKeyMap: const { - 'isOptional': 'is_optional', - 'autoApply': 'auto_apply', - 'buildTo': 'build_to', - 'builderFactories': 'builder_factories', - 'appliesBuilders': 'applies_builders', - 'requiredInputs': 'required_inputs', - 'buildExtensions': 'build_extensions' - }); -} Map _$BuilderToJson(Builder instance) { final val = {}; diff --git a/analysis_options.yaml b/analysis_options.yaml index cd40b8743..8ee7ce592 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -67,6 +67,8 @@ linter: - prefer_const_declarations - prefer_contains - prefer_equal_for_default_values + # Enable once we roll checked_yaml and example + #- prefer_expression_function_bodies - prefer_final_fields - prefer_final_locals - prefer_for_elements_to_map_fromIterable diff --git a/json_annotation/lib/src/json_serializable.g.dart b/json_annotation/lib/src/json_serializable.g.dart index 7606a71ff..e1cceafcc 100644 --- a/json_annotation/lib/src/json_serializable.g.dart +++ b/json_annotation/lib/src/json_serializable.g.dart @@ -6,51 +6,52 @@ part of 'json_serializable.dart'; // JsonSerializableGenerator // ************************************************************************** -JsonSerializable _$JsonSerializableFromJson(Map json) { - return $checkedNew('JsonSerializable', json, () { - $checkKeys(json, allowedKeys: const [ - 'any_map', - 'checked', - 'create_factory', - 'create_to_json', - 'disallow_unrecognized_keys', - 'explicit_to_json', - 'field_rename', - 'generic_argument_factories', - 'ignore_unannotated', - 'include_if_null' - ]); - final val = JsonSerializable( - anyMap: $checkedConvert(json, 'any_map', (v) => v as bool?), - checked: $checkedConvert(json, 'checked', (v) => v as bool?), - createFactory: $checkedConvert(json, 'create_factory', (v) => v as bool?), - createToJson: $checkedConvert(json, 'create_to_json', (v) => v as bool?), - disallowUnrecognizedKeys: $checkedConvert( - json, 'disallow_unrecognized_keys', (v) => v as bool?), - explicitToJson: - $checkedConvert(json, 'explicit_to_json', (v) => v as bool?), - fieldRename: $checkedConvert(json, 'field_rename', - (v) => _$enumDecodeNullable(_$FieldRenameEnumMap, v)), - ignoreUnannotated: - $checkedConvert(json, 'ignore_unannotated', (v) => v as bool?), - includeIfNull: - $checkedConvert(json, 'include_if_null', (v) => v as bool?), - genericArgumentFactories: $checkedConvert( - json, 'generic_argument_factories', (v) => v as bool?), - ); - return val; - }, fieldKeyMap: const { - 'anyMap': 'any_map', - 'createFactory': 'create_factory', - 'createToJson': 'create_to_json', - 'disallowUnrecognizedKeys': 'disallow_unrecognized_keys', - 'explicitToJson': 'explicit_to_json', - 'fieldRename': 'field_rename', - 'ignoreUnannotated': 'ignore_unannotated', - 'includeIfNull': 'include_if_null', - 'genericArgumentFactories': 'generic_argument_factories' - }); -} +JsonSerializable _$JsonSerializableFromJson(Map json) => + $checkedNew('JsonSerializable', json, () { + $checkKeys(json, allowedKeys: const [ + 'any_map', + 'checked', + 'create_factory', + 'create_to_json', + 'disallow_unrecognized_keys', + 'explicit_to_json', + 'field_rename', + 'generic_argument_factories', + 'ignore_unannotated', + 'include_if_null' + ]); + final val = JsonSerializable( + anyMap: $checkedConvert(json, 'any_map', (v) => v as bool?), + checked: $checkedConvert(json, 'checked', (v) => v as bool?), + createFactory: + $checkedConvert(json, 'create_factory', (v) => v as bool?), + createToJson: + $checkedConvert(json, 'create_to_json', (v) => v as bool?), + disallowUnrecognizedKeys: $checkedConvert( + json, 'disallow_unrecognized_keys', (v) => v as bool?), + explicitToJson: + $checkedConvert(json, 'explicit_to_json', (v) => v as bool?), + fieldRename: $checkedConvert(json, 'field_rename', + (v) => _$enumDecodeNullable(_$FieldRenameEnumMap, v)), + ignoreUnannotated: + $checkedConvert(json, 'ignore_unannotated', (v) => v as bool?), + includeIfNull: + $checkedConvert(json, 'include_if_null', (v) => v as bool?), + genericArgumentFactories: $checkedConvert( + json, 'generic_argument_factories', (v) => v as bool?), + ); + return val; + }, fieldKeyMap: const { + 'anyMap': 'any_map', + 'createFactory': 'create_factory', + 'createToJson': 'create_to_json', + 'disallowUnrecognizedKeys': 'disallow_unrecognized_keys', + 'explicitToJson': 'explicit_to_json', + 'fieldRename': 'field_rename', + 'ignoreUnannotated': 'ignore_unannotated', + 'includeIfNull': 'include_if_null', + 'genericArgumentFactories': 'generic_argument_factories' + }); Map _$JsonSerializableToJson(JsonSerializable instance) => { diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 6f1b28850..984923141 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -7,6 +7,7 @@ - Improve names of private classes generated for `toJson` and `fromJson`. - Use the new `$checkedCreate` helper exposed in `package:json_annotation` v4.1+. +- Generated code now conforms to this `prefer_expression_function_bodies` lint. - `type_helper.dart`: - **BREAKING**: removed `typeArgumentsOf`. This is now an extension exposed by `package:source_helper`. diff --git a/json_serializable/README.md b/json_serializable/README.md index 24056abb4..371d7998c 100644 --- a/json_serializable/README.md +++ b/json_serializable/README.md @@ -48,15 +48,13 @@ Building creates the corresponding part `example.g.dart`: ```dart part of 'example.dart'; -Person _$PersonFromJson(Map json) { - return Person( - firstName: json['firstName'] as String, - lastName: json['lastName'] as String, - dateOfBirth: json['dateOfBirth'] == null - ? null - : DateTime.parse(json['dateOfBirth'] as String), - ); -} +Person _$PersonFromJson(Map json) => Person( + firstName: json['firstName'] as String, + lastName: json['lastName'] as String, + dateOfBirth: json['dateOfBirth'] == null + ? null + : DateTime.parse(json['dateOfBirth'] as String), + ); Map _$PersonToJson(Person instance) => { 'firstName': instance.firstName, diff --git a/json_serializable/example/example.g.dart b/json_serializable/example/example.g.dart index a01e08473..7f716df1a 100644 --- a/json_serializable/example/example.g.dart +++ b/json_serializable/example/example.g.dart @@ -6,15 +6,13 @@ part of 'example.dart'; // JsonSerializableGenerator // ************************************************************************** -Person _$PersonFromJson(Map json) { - return Person( - firstName: json['firstName'] as String, - lastName: json['lastName'] as String, - dateOfBirth: json['dateOfBirth'] == null - ? null - : DateTime.parse(json['dateOfBirth'] as String), - ); -} +Person _$PersonFromJson(Map json) => Person( + firstName: json['firstName'] as String, + lastName: json['lastName'] as String, + dateOfBirth: json['dateOfBirth'] == null + ? null + : DateTime.parse(json['dateOfBirth'] as String), + ); Map _$PersonToJson(Person instance) => { 'firstName': instance.firstName, diff --git a/json_serializable/lib/src/decode_helper.dart b/json_serializable/lib/src/decode_helper.dart index ed88546ed..173eb88e4 100644 --- a/json_serializable/lib/src/decode_helper.dart +++ b/json_serializable/lib/src/decode_helper.dart @@ -47,7 +47,9 @@ abstract class DecodeHelper implements HelperCore { } } - buffer.write(') {\n'); + buffer.write(')'); + + final fromJsonLines = []; String deserializeFun(String paramOrFieldName, {ParameterElement? ctorParam}) => @@ -70,23 +72,25 @@ abstract class DecodeHelper implements HelperCore { deserializeFun, ); - final checks = _checkKeys(accessibleFields.values - .where((fe) => data.usedCtorParamsAndFields.contains(fe.name))); + final checks = _checkKeys( + accessibleFields.values + .where((fe) => data.usedCtorParamsAndFields.contains(fe.name)), + ).toList(); if (config.checked) { final classLiteral = escapeDartString(element.name); - buffer..write(''' - return \$checkedCreate( + final sectionBuffer = StringBuffer()..write(''' + \$checkedCreate( $classLiteral, json, - (\$checkedConvert) {\n''')..write(checks)..write(''' + (\$checkedConvert) {\n''')..write(checks.join())..write(''' final val = ${data.content};'''); for (final field in data.fieldsToSet) { - buffer.writeln(); + sectionBuffer.writeln(); final safeName = safeNameAccess(accessibleFields[field]!); - buffer + sectionBuffer ..write(''' \$checkedConvert($safeName, (v) => ''') ..write('val.$field = ') @@ -95,7 +99,7 @@ abstract class DecodeHelper implements HelperCore { ..write(');'); } - buffer.write('''\n return val; + sectionBuffer.write('''\n return val; }'''); final fieldKeyMap = Map.fromEntries(data.usedCtorParamsAndFields @@ -110,23 +114,38 @@ abstract class DecodeHelper implements HelperCore { fieldKeyMapArg = ', fieldKeyMap: const $mapLiteral'; } - buffer..write(fieldKeyMapArg)..write(')'); + sectionBuffer..write(fieldKeyMapArg)..write(',);'); + fromJsonLines.add(sectionBuffer.toString()); } else { - buffer..write(checks)..write(''' - return ${data.content}'''); + fromJsonLines.addAll(checks); + + final sectionBuffer = StringBuffer()..write(''' + ${data.content}'''); for (final field in data.fieldsToSet) { - buffer + sectionBuffer ..writeln() ..write(' ..$field = ') ..write(deserializeFun(field)); } + sectionBuffer.writeln(';'); + fromJsonLines.add(sectionBuffer.toString()); + } + + if (fromJsonLines.length == 1) { + buffer..write('=>')..write(fromJsonLines.single); + } else { + buffer + ..write('{') + ..writeAll(fromJsonLines.take(fromJsonLines.length - 1)) + ..write('return ') + ..write(fromJsonLines.last) + ..write('}'); } - buffer..writeln(';\n}')..writeln(); return CreateFactoryResult(buffer.toString(), data.usedCtorParamsAndFields); } - String _checkKeys(Iterable accessibleFields) { + Iterable _checkKeys(Iterable accessibleFields) sync* { final args = []; String constantList(Iterable things) => @@ -155,10 +174,8 @@ abstract class DecodeHelper implements HelperCore { args.add('disallowNullValues: $disallowNullKeyLiteral'); } - if (args.isEmpty) { - return ''; - } else { - return '\$checkKeys(json, ${args.join(', ')});\n'; + if (args.isNotEmpty) { + yield '\$checkKeys(json, ${args.map((e) => '$e, ').join()});\n'; } } diff --git a/json_serializable/lib/src/json_literal_generator.dart b/json_serializable/lib/src/json_literal_generator.dart index f088e5f31..dd6189fa2 100644 --- a/json_serializable/lib/src/json_literal_generator.dart +++ b/json_serializable/lib/src/json_literal_generator.dart @@ -41,7 +41,7 @@ class JsonLiteralGenerator extends GeneratorForAnnotation { } /// Returns a [String] representing a valid Dart literal for [value]. -String jsonLiteralAsDart(dynamic value) { +String jsonLiteralAsDart(Object? value) { if (value == null) return 'null'; if (value is String) return escapeDartString(value); @@ -74,7 +74,8 @@ String jsonLiteralAsDart(dynamic value) { if (value is Map) return jsonMapAsDart(value); throw StateError( - 'Should never get here – with ${value.runtimeType} - `$value`.'); + 'Should never get here – with ${value.runtimeType} - `$value`.', + ); } String jsonMapAsDart(Map value) { diff --git a/json_serializable/test/default_value/default_value.g.dart b/json_serializable/test/default_value/default_value.g.dart index fbf121f1d..b4c9631db 100644 --- a/json_serializable/test/default_value/default_value.g.dart +++ b/json_serializable/test/default_value/default_value.g.dart @@ -6,37 +6,35 @@ part of 'default_value.dart'; // JsonSerializableGenerator // ************************************************************************** -DefaultValue _$DefaultValueFromJson(Map json) { - return DefaultValue( - json['fieldBool'] as bool? ?? true, - json['fieldString'] as String? ?? 'string', - json['fieldInt'] as int? ?? 42, - (json['fieldDouble'] as num?)?.toDouble() ?? 3.14, - json['fieldListEmpty'] as List? ?? [], - (json['fieldSetEmpty'] as List?)?.toSet() ?? {}, - json['fieldMapEmpty'] as Map? ?? {}, - (json['fieldListSimple'] as List?) - ?.map((e) => e as int) - .toList() ?? - [1, 2, 3], - (json['fieldSetSimple'] as List?) - ?.map((e) => e as String) - .toSet() ?? - {'entry1', 'entry2'}, - (json['fieldMapSimple'] as Map?)?.map( - (k, e) => MapEntry(k, e as int), - ) ?? - {'answer': 42}, - (json['fieldMapListString'] as Map?)?.map( - (k, e) => MapEntry( - k, (e as List).map((e) => e as String).toList()), - ) ?? - { - 'root': ['child'] - }, - _$enumDecodeNullable(_$GreekEnumMap, json['fieldEnum']) ?? Greek.beta, - ); -} +DefaultValue _$DefaultValueFromJson(Map json) => DefaultValue( + json['fieldBool'] as bool? ?? true, + json['fieldString'] as String? ?? 'string', + json['fieldInt'] as int? ?? 42, + (json['fieldDouble'] as num?)?.toDouble() ?? 3.14, + json['fieldListEmpty'] as List? ?? [], + (json['fieldSetEmpty'] as List?)?.toSet() ?? {}, + json['fieldMapEmpty'] as Map? ?? {}, + (json['fieldListSimple'] as List?) + ?.map((e) => e as int) + .toList() ?? + [1, 2, 3], + (json['fieldSetSimple'] as List?) + ?.map((e) => e as String) + .toSet() ?? + {'entry1', 'entry2'}, + (json['fieldMapSimple'] as Map?)?.map( + (k, e) => MapEntry(k, e as int), + ) ?? + {'answer': 42}, + (json['fieldMapListString'] as Map?)?.map( + (k, e) => MapEntry( + k, (e as List).map((e) => e as String).toList()), + ) ?? + { + 'root': ['child'] + }, + _$enumDecodeNullable(_$GreekEnumMap, json['fieldEnum']) ?? Greek.beta, + ); Map _$DefaultValueToJson(DefaultValue instance) => { diff --git a/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart b/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart index 43320b911..8a1bdde7f 100644 --- a/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart +++ b/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart @@ -6,45 +6,56 @@ part of 'default_value.g_any_map__checked.dart'; // JsonSerializableGenerator // ************************************************************************** -DefaultValue _$DefaultValueFromJson(Map json) { - return $checkedCreate('DefaultValue', json, ($checkedConvert) { - final val = DefaultValue( - $checkedConvert('fieldBool', (v) => v as bool?) ?? true, - $checkedConvert('fieldString', (v) => v as String?) ?? 'string', - $checkedConvert('fieldInt', (v) => v as int?) ?? 42, - $checkedConvert('fieldDouble', (v) => (v as num?)?.toDouble()) ?? 3.14, - $checkedConvert('fieldListEmpty', (v) => v as List?) ?? [], - $checkedConvert('fieldSetEmpty', (v) => (v as List?)?.toSet()) ?? - {}, - $checkedConvert('fieldMapEmpty', (v) => v as Map?) ?? {}, - $checkedConvert('fieldListSimple', - (v) => (v as List?)?.map((e) => e as int).toList()) ?? - [1, 2, 3], - $checkedConvert('fieldSetSimple', - (v) => (v as List?)?.map((e) => e as String).toSet()) ?? - {'entry1', 'entry2'}, - $checkedConvert( - 'fieldMapSimple', - (v) => (v as Map?)?.map( - (k, e) => MapEntry(k as String, e as int), - )) ?? - {'answer': 42}, - $checkedConvert( - 'fieldMapListString', - (v) => (v as Map?)?.map( - (k, e) => MapEntry(k as String, - (e as List).map((e) => e as String).toList()), - )) ?? - { - 'root': ['child'] - }, - $checkedConvert( - 'fieldEnum', (v) => _$enumDecodeNullable(_$GreekEnumMap, v)) ?? - Greek.beta, +DefaultValue _$DefaultValueFromJson(Map json) => $checkedCreate( + 'DefaultValue', + json, + ($checkedConvert) { + final val = DefaultValue( + $checkedConvert('fieldBool', (v) => v as bool?) ?? true, + $checkedConvert('fieldString', (v) => v as String?) ?? 'string', + $checkedConvert('fieldInt', (v) => v as int?) ?? 42, + $checkedConvert('fieldDouble', (v) => (v as num?)?.toDouble()) ?? + 3.14, + $checkedConvert('fieldListEmpty', (v) => v as List?) ?? [], + $checkedConvert( + 'fieldSetEmpty', (v) => (v as List?)?.toSet()) ?? + {}, + $checkedConvert('fieldMapEmpty', (v) => v as Map?) ?? {}, + $checkedConvert( + 'fieldListSimple', + (v) => + (v as List?)?.map((e) => e as int).toList()) ?? + [1, 2, 3], + $checkedConvert( + 'fieldSetSimple', + (v) => + (v as List?)?.map((e) => e as String).toSet()) ?? + {'entry1', 'entry2'}, + $checkedConvert( + 'fieldMapSimple', + (v) => (v as Map?)?.map( + (k, e) => MapEntry(k as String, e as int), + )) ?? + {'answer': 42}, + $checkedConvert( + 'fieldMapListString', + (v) => (v as Map?)?.map( + (k, e) => MapEntry( + k as String, + (e as List) + .map((e) => e as String) + .toList()), + )) ?? + { + 'root': ['child'] + }, + $checkedConvert('fieldEnum', + (v) => _$enumDecodeNullable(_$GreekEnumMap, v)) ?? + Greek.beta, + ); + return val; + }, ); - return val; - }); -} Map _$DefaultValueToJson(DefaultValue instance) => { diff --git a/json_serializable/test/default_value/implicit_default_value.g.dart b/json_serializable/test/default_value/implicit_default_value.g.dart index d56e93b5c..71b4449d1 100644 --- a/json_serializable/test/default_value/implicit_default_value.g.dart +++ b/json_serializable/test/default_value/implicit_default_value.g.dart @@ -6,40 +6,40 @@ part of 'implicit_default_value.dart'; // JsonSerializableGenerator // ************************************************************************** -DefaultValueImplicit _$DefaultValueImplicitFromJson(Map json) { - return DefaultValueImplicit( - fieldBool: json['fieldBool'] as bool? ?? true, - fieldString: json['fieldString'] as String? ?? 'string', - fieldInt: json['fieldInt'] as int? ?? 42, - fieldDouble: (json['fieldDouble'] as num?)?.toDouble() ?? 3.14, - fieldListEmpty: json['fieldListEmpty'] as List? ?? const [], - fieldSetEmpty: - (json['fieldSetEmpty'] as List?)?.toSet() ?? const {}, - fieldMapEmpty: json['fieldMapEmpty'] as Map? ?? const {}, - fieldListSimple: (json['fieldListSimple'] as List?) - ?.map((e) => e as int) - .toList() ?? - const [1, 2, 3], - fieldSetSimple: (json['fieldSetSimple'] as List?) - ?.map((e) => e as String) - .toSet() ?? - const {'entry1', 'entry2'}, - fieldMapSimple: (json['fieldMapSimple'] as Map?)?.map( - (k, e) => MapEntry(k, e as int), - ) ?? - const {'answer': 42}, - fieldMapListString: - (json['fieldMapListString'] as Map?)?.map( - (k, e) => MapEntry( - k, (e as List).map((e) => e as String).toList()), - ) ?? - const { - 'root': ['child'] - }, - fieldEnum: - _$enumDecodeNullable(_$GreekEnumMap, json['fieldEnum']) ?? Greek.beta, - ); -} +DefaultValueImplicit _$DefaultValueImplicitFromJson( + Map json) => + DefaultValueImplicit( + fieldBool: json['fieldBool'] as bool? ?? true, + fieldString: json['fieldString'] as String? ?? 'string', + fieldInt: json['fieldInt'] as int? ?? 42, + fieldDouble: (json['fieldDouble'] as num?)?.toDouble() ?? 3.14, + fieldListEmpty: json['fieldListEmpty'] as List? ?? const [], + fieldSetEmpty: + (json['fieldSetEmpty'] as List?)?.toSet() ?? const {}, + fieldMapEmpty: json['fieldMapEmpty'] as Map? ?? const {}, + fieldListSimple: (json['fieldListSimple'] as List?) + ?.map((e) => e as int) + .toList() ?? + const [1, 2, 3], + fieldSetSimple: (json['fieldSetSimple'] as List?) + ?.map((e) => e as String) + .toSet() ?? + const {'entry1', 'entry2'}, + fieldMapSimple: (json['fieldMapSimple'] as Map?)?.map( + (k, e) => MapEntry(k, e as int), + ) ?? + const {'answer': 42}, + fieldMapListString: + (json['fieldMapListString'] as Map?)?.map( + (k, e) => MapEntry( + k, (e as List).map((e) => e as String).toList()), + ) ?? + const { + 'root': ['child'] + }, + fieldEnum: + _$enumDecodeNullable(_$GreekEnumMap, json['fieldEnum']) ?? Greek.beta, + ); Map _$DefaultValueImplicitToJson( DefaultValueImplicit instance) => diff --git a/json_serializable/test/generic_files/generic_argument_factories.g.dart b/json_serializable/test/generic_files/generic_argument_factories.g.dart index da41c86ff..7d3a2fc5d 100644 --- a/json_serializable/test/generic_files/generic_argument_factories.g.dart +++ b/json_serializable/test/generic_files/generic_argument_factories.g.dart @@ -10,13 +10,12 @@ GenericClassWithHelpers _$GenericClassWithHelpersFromJson( Map json, T Function(Object? json) fromJsonT, S Function(Object? json) fromJsonS, -) { - return GenericClassWithHelpers( - fromJsonT(json['value']), - (json['list'] as List).map(fromJsonT).toList(), - (json['someSet'] as List).map(fromJsonS).toSet(), - ); -} +) => + GenericClassWithHelpers( + fromJsonT(json['value']), + (json['list'] as List).map(fromJsonT).toList(), + (json['someSet'] as List).map(fromJsonS).toSet(), + ); Map _$GenericClassWithHelpersToJson( GenericClassWithHelpers instance, @@ -29,20 +28,19 @@ Map _$GenericClassWithHelpersToJson( 'someSet': instance.someSet.map(toJsonS).toList(), }; -ConcreteClass _$ConcreteClassFromJson(Map json) { - return ConcreteClass( - GenericClassWithHelpers.fromJson(json['value'] as Map, - (value) => value as int, (value) => value as String), - GenericClassWithHelpers.fromJson( - json['value2'] as Map, - (value) => (value as num).toDouble(), - (value) => BigInt.parse(value as String)), - GenericClassWithHelpers.fromJson( - json['value3'] as Map, - (value) => (value as num?)?.toDouble(), - (value) => value == null ? null : BigInt.parse(value as String)), - ); -} +ConcreteClass _$ConcreteClassFromJson(Map json) => + ConcreteClass( + GenericClassWithHelpers.fromJson(json['value'] as Map, + (value) => value as int, (value) => value as String), + GenericClassWithHelpers.fromJson( + json['value2'] as Map, + (value) => (value as num).toDouble(), + (value) => BigInt.parse(value as String)), + GenericClassWithHelpers.fromJson( + json['value3'] as Map, + (value) => (value as num?)?.toDouble(), + (value) => value == null ? null : BigInt.parse(value as String)), + ); Map _$ConcreteClassToJson(ConcreteClass instance) => { diff --git a/json_serializable/test/generic_files/generic_argument_factories_nullable.g.dart b/json_serializable/test/generic_files/generic_argument_factories_nullable.g.dart index e54af7a16..2d73473cd 100644 --- a/json_serializable/test/generic_files/generic_argument_factories_nullable.g.dart +++ b/json_serializable/test/generic_files/generic_argument_factories_nullable.g.dart @@ -12,17 +12,16 @@ GenericClassWithHelpersNullable Map json, T Function(Object? json) fromJsonT, S Function(Object? json) fromJsonS, -) { - return GenericClassWithHelpersNullable( - value: _$nullableGenericFromJson(json['value'], fromJsonT), - list: (json['list'] as List?) - ?.map((e) => _$nullableGenericFromJson(e, fromJsonT)) - .toList(), - someSet: (json['someSet'] as List?) - ?.map((e) => _$nullableGenericFromJson(e, fromJsonS)) - .toSet(), - ); -} +) => + GenericClassWithHelpersNullable( + value: _$nullableGenericFromJson(json['value'], fromJsonT), + list: (json['list'] as List?) + ?.map((e) => _$nullableGenericFromJson(e, fromJsonT)) + .toList(), + someSet: (json['someSet'] as List?) + ?.map((e) => _$nullableGenericFromJson(e, fromJsonS)) + .toSet(), + ); Map _$GenericClassWithHelpersNullableToJson( GenericClassWithHelpersNullable instance, @@ -52,22 +51,21 @@ Object? _$nullableGenericToJson( input == null ? null : toJson(input); ConcreteClassNullable _$ConcreteClassNullableFromJson( - Map json) { - return ConcreteClassNullable( - GenericClassWithHelpersNullable.fromJson( - json['value'] as Map, - (value) => value as int, - (value) => value as String), - GenericClassWithHelpersNullable.fromJson( - json['value2'] as Map, - (value) => (value as num).toDouble(), - (value) => BigInt.parse(value as String)), - GenericClassWithHelpersNullable.fromJson( - json['value3'] as Map, - (value) => (value as num?)?.toDouble(), - (value) => value == null ? null : BigInt.parse(value as String)), - ); -} + Map json) => + ConcreteClassNullable( + GenericClassWithHelpersNullable.fromJson( + json['value'] as Map, + (value) => value as int, + (value) => value as String), + GenericClassWithHelpersNullable.fromJson( + json['value2'] as Map, + (value) => (value as num).toDouble(), + (value) => BigInt.parse(value as String)), + GenericClassWithHelpersNullable.fromJson( + json['value3'] as Map, + (value) => (value as num?)?.toDouble(), + (value) => value == null ? null : BigInt.parse(value as String)), + ); Map _$ConcreteClassNullableToJson( ConcreteClassNullable instance) => diff --git a/json_serializable/test/generic_files/generic_class.g.dart b/json_serializable/test/generic_files/generic_class.g.dart index d1fb01b0f..fdec43703 100644 --- a/json_serializable/test/generic_files/generic_class.g.dart +++ b/json_serializable/test/generic_files/generic_class.g.dart @@ -7,19 +7,18 @@ part of 'generic_class.dart'; // ************************************************************************** GenericClass _$GenericClassFromJson( - Map json) { - return GenericClass() - ..fieldObject = - GenericClass._dataFromJson(json['fieldObject'] as Map) - ..fieldDynamic = - GenericClass._dataFromJson(json['fieldDynamic'] as Map) - ..fieldInt = - GenericClass._dataFromJson(json['fieldInt'] as Map) - ..fieldT = - GenericClass._dataFromJson(json['fieldT'] as Map) - ..fieldS = - GenericClass._dataFromJson(json['fieldS'] as Map); -} + Map json) => + GenericClass() + ..fieldObject = GenericClass._dataFromJson( + json['fieldObject'] as Map) + ..fieldDynamic = GenericClass._dataFromJson( + json['fieldDynamic'] as Map) + ..fieldInt = + GenericClass._dataFromJson(json['fieldInt'] as Map) + ..fieldT = + GenericClass._dataFromJson(json['fieldT'] as Map) + ..fieldS = + GenericClass._dataFromJson(json['fieldS'] as Map); Map _$GenericClassToJson( GenericClass instance) => @@ -33,20 +32,19 @@ Map _$GenericClassToJson( GenericClassWithConverter _$GenericClassWithConverterFromJson( - Map json) { - return GenericClassWithConverter() - ..fieldObject = json['fieldObject'] - ..fieldDynamic = json['fieldDynamic'] - ..fieldInt = json['fieldInt'] as int? - ..fieldT = - _SimpleConverter().fromJson(json['fieldT'] as Map) - ..fieldS = - _SimpleConverter().fromJson(json['fieldS'] as Map) - ..duration = const _DurationMillisecondConverter.named() - .fromJson(json['duration'] as int?) - ..listDuration = const _DurationListMillisecondConverter() - .fromJson(json['listDuration'] as int?); -} + Map json) => + GenericClassWithConverter() + ..fieldObject = json['fieldObject'] + ..fieldDynamic = json['fieldDynamic'] + ..fieldInt = json['fieldInt'] as int? + ..fieldT = _SimpleConverter() + .fromJson(json['fieldT'] as Map) + ..fieldS = _SimpleConverter() + .fromJson(json['fieldS'] as Map) + ..duration = const _DurationMillisecondConverter.named() + .fromJson(json['duration'] as int?) + ..listDuration = const _DurationListMillisecondConverter() + .fromJson(json['listDuration'] as int?); Map _$GenericClassWithConverterToJson( GenericClassWithConverter instance) => diff --git a/json_serializable/test/integration/json_test_example.g.dart b/json_serializable/test/integration/json_test_example.g.dart index da899ac94..9632d52a6 100644 --- a/json_serializable/test/integration/json_test_example.g.dart +++ b/json_serializable/test/integration/json_test_example.g.dart @@ -6,31 +6,29 @@ part of 'json_test_example.dart'; // JsonSerializableGenerator // ************************************************************************** -Person _$PersonFromJson(Map json) { - return Person( - json['firstName'] as String, - json['lastName'] as String, - _$enumDecode(_$CategoryEnumMap, json[r'$house']), - middleName: json['middleName'] as String?, - dateOfBirth: json['dateOfBirth'] == null - ? null - : DateTime.parse(json['dateOfBirth'] as String), - ) - ..order = json['order'] == null - ? null - : Order.fromJson(json['order'] as Map) - ..customOrders = json['customOrders'] == null - ? null - : MyList.fromJson((json['customOrders'] as List) - .map((e) => Order.fromJson(e as Map)) - .toList()) - ..houseMap = (json['houseMap'] as Map?)?.map( - (k, e) => MapEntry(k, _$enumDecode(_$CategoryEnumMap, e)), +Person _$PersonFromJson(Map json) => Person( + json['firstName'] as String, + json['lastName'] as String, + _$enumDecode(_$CategoryEnumMap, json[r'$house']), + middleName: json['middleName'] as String?, + dateOfBirth: json['dateOfBirth'] == null + ? null + : DateTime.parse(json['dateOfBirth'] as String), ) - ..categoryCounts = (json['categoryCounts'] as Map?)?.map( - (k, e) => MapEntry(_$enumDecode(_$CategoryEnumMap, k), e as int), - ); -} + ..order = json['order'] == null + ? null + : Order.fromJson(json['order'] as Map) + ..customOrders = json['customOrders'] == null + ? null + : MyList.fromJson((json['customOrders'] as List) + .map((e) => Order.fromJson(e as Map)) + .toList()) + ..houseMap = (json['houseMap'] as Map?)?.map( + (k, e) => MapEntry(k, _$enumDecode(_$CategoryEnumMap, e)), + ) + ..categoryCounts = (json['categoryCounts'] as Map?)?.map( + (k, e) => MapEntry(_$enumDecode(_$CategoryEnumMap, k), e as int), + ); Map _$PersonToJson(Person instance) => { 'firstName': instance.firstName, @@ -83,7 +81,10 @@ const _$CategoryEnumMap = { }; Order _$OrderFromJson(Map json) { - $checkKeys(json, disallowNullValues: const ['count']); + $checkKeys( + json, + disallowNullValues: const ['count'], + ); return Order( _$enumDecodeNullable(_$CategoryEnumMap, json['category']), (json['items'] as List?) @@ -147,16 +148,15 @@ const _$StatusCodeEnumMap = { StatusCode.unknown: 'unknown', }; -Item _$ItemFromJson(Map json) { - return Item( - json['price'] as int?, - ) - ..itemNumber = json['item-number'] as int? - ..saleDates = (json['saleDates'] as List?) - ?.map((e) => DateTime.parse(e as String)) - .toList() - ..rates = (json['rates'] as List?)?.map((e) => e as int).toList(); -} +Item _$ItemFromJson(Map json) => Item( + json['price'] as int?, + ) + ..itemNumber = json['item-number'] as int? + ..saleDates = (json['saleDates'] as List?) + ?.map((e) => DateTime.parse(e as String)) + .toList() + ..rates = + (json['rates'] as List?)?.map((e) => e as int).toList(); Map _$ItemToJson(Item instance) { final val = { @@ -176,19 +176,17 @@ Map _$ItemToJson(Item instance) { return val; } -Numbers _$NumbersFromJson(Map json) { - return Numbers() - ..ints = (json['ints'] as List?)?.map((e) => e as int).toList() - ..nums = (json['nums'] as List?)?.map((e) => e as num).toList() - ..doubles = (json['doubles'] as List?) - ?.map((e) => (e as num).toDouble()) - .toList() - ..nnDoubles = (json['nnDoubles'] as List?) - ?.map((e) => (e as num).toDouble()) - .toList() - ..duration = durationFromInt(json['duration'] as int?) - ..date = dateTimeFromEpochUs(json['date'] as int?); -} +Numbers _$NumbersFromJson(Map json) => Numbers() + ..ints = (json['ints'] as List?)?.map((e) => e as int).toList() + ..nums = (json['nums'] as List?)?.map((e) => e as num).toList() + ..doubles = (json['doubles'] as List?) + ?.map((e) => (e as num).toDouble()) + .toList() + ..nnDoubles = (json['nnDoubles'] as List?) + ?.map((e) => (e as num).toDouble()) + .toList() + ..duration = durationFromInt(json['duration'] as int?) + ..date = dateTimeFromEpochUs(json['date'] as int?); Map _$NumbersToJson(Numbers instance) => { 'ints': instance.ints, @@ -199,21 +197,20 @@ Map _$NumbersToJson(Numbers instance) => { 'date': dateTimeToEpochUs(instance.date), }; -MapKeyVariety _$MapKeyVarietyFromJson(Map json) { - return MapKeyVariety() - ..intIntMap = (json['intIntMap'] as Map?)?.map( - (k, e) => MapEntry(int.parse(k), e as int), - ) - ..uriIntMap = (json['uriIntMap'] as Map?)?.map( - (k, e) => MapEntry(Uri.parse(k), e as int), - ) - ..dateTimeIntMap = (json['dateTimeIntMap'] as Map?)?.map( - (k, e) => MapEntry(DateTime.parse(k), e as int), - ) - ..bigIntMap = (json['bigIntMap'] as Map?)?.map( - (k, e) => MapEntry(BigInt.parse(k), e as int), - ); -} +MapKeyVariety _$MapKeyVarietyFromJson(Map json) => + MapKeyVariety() + ..intIntMap = (json['intIntMap'] as Map?)?.map( + (k, e) => MapEntry(int.parse(k), e as int), + ) + ..uriIntMap = (json['uriIntMap'] as Map?)?.map( + (k, e) => MapEntry(Uri.parse(k), e as int), + ) + ..dateTimeIntMap = (json['dateTimeIntMap'] as Map?)?.map( + (k, e) => MapEntry(DateTime.parse(k), e as int), + ) + ..bigIntMap = (json['bigIntMap'] as Map?)?.map( + (k, e) => MapEntry(BigInt.parse(k), e as int), + ); Map _$MapKeyVarietyToJson(MapKeyVariety instance) => { @@ -224,19 +221,18 @@ Map _$MapKeyVarietyToJson(MapKeyVariety instance) => 'bigIntMap': instance.bigIntMap?.map((k, e) => MapEntry(k.toString(), e)), }; -UnknownEnumValue _$UnknownEnumValueFromJson(Map json) { - return UnknownEnumValue() - ..enumValue = _$enumDecode(_$CategoryEnumMap, json['enumValue'], - unknownValue: Category.notDiscoveredYet) - ..enumIterable = (json['enumIterable'] as List).map((e) => - _$enumDecode(_$CategoryEnumMap, e, - unknownValue: Category.notDiscoveredYet)) - ..enumList = (json['enumList'] as List) - .map((e) => _$enumDecode(_$CategoryEnumMap, e, - unknownValue: Category.notDiscoveredYet)) - .toList() - ..enumSet = (json['enumSet'] as List) - .map((e) => _$enumDecode(_$CategoryEnumMap, e, - unknownValue: Category.notDiscoveredYet)) - .toSet(); -} +UnknownEnumValue _$UnknownEnumValueFromJson(Map json) => + UnknownEnumValue() + ..enumValue = _$enumDecode(_$CategoryEnumMap, json['enumValue'], + unknownValue: Category.notDiscoveredYet) + ..enumIterable = (json['enumIterable'] as List).map((e) => + _$enumDecode(_$CategoryEnumMap, e, + unknownValue: Category.notDiscoveredYet)) + ..enumList = (json['enumList'] as List) + .map((e) => _$enumDecode(_$CategoryEnumMap, e, + unknownValue: Category.notDiscoveredYet)) + .toList() + ..enumSet = (json['enumSet'] as List) + .map((e) => _$enumDecode(_$CategoryEnumMap, e, + unknownValue: Category.notDiscoveredYet)) + .toSet(); diff --git a/json_serializable/test/integration/json_test_example.g_any_map.g.dart b/json_serializable/test/integration/json_test_example.g_any_map.g.dart index bfa0c1378..b18093a56 100644 --- a/json_serializable/test/integration/json_test_example.g_any_map.g.dart +++ b/json_serializable/test/integration/json_test_example.g_any_map.g.dart @@ -6,31 +6,29 @@ part of 'json_test_example.g_any_map.dart'; // JsonSerializableGenerator // ************************************************************************** -Person _$PersonFromJson(Map json) { - return Person( - json['firstName'] as String, - json['lastName'] as String, - _$enumDecode(_$CategoryEnumMap, json[r'$house']), - middleName: json['middleName'] as String?, - dateOfBirth: json['dateOfBirth'] == null - ? null - : DateTime.parse(json['dateOfBirth'] as String), - ) - ..order = json['order'] == null - ? null - : Order.fromJson(Map.from(json['order'] as Map)) - ..customOrders = json['customOrders'] == null - ? null - : MyList.fromJson((json['customOrders'] as List) - .map((e) => Order.fromJson(Map.from(e as Map))) - .toList()) - ..houseMap = (json['houseMap'] as Map?)?.map( - (k, e) => MapEntry(k as String, _$enumDecode(_$CategoryEnumMap, e)), +Person _$PersonFromJson(Map json) => Person( + json['firstName'] as String, + json['lastName'] as String, + _$enumDecode(_$CategoryEnumMap, json[r'$house']), + middleName: json['middleName'] as String?, + dateOfBirth: json['dateOfBirth'] == null + ? null + : DateTime.parse(json['dateOfBirth'] as String), ) - ..categoryCounts = (json['categoryCounts'] as Map?)?.map( - (k, e) => MapEntry(_$enumDecode(_$CategoryEnumMap, k), e as int), - ); -} + ..order = json['order'] == null + ? null + : Order.fromJson(Map.from(json['order'] as Map)) + ..customOrders = json['customOrders'] == null + ? null + : MyList.fromJson((json['customOrders'] as List) + .map((e) => Order.fromJson(Map.from(e as Map))) + .toList()) + ..houseMap = (json['houseMap'] as Map?)?.map( + (k, e) => MapEntry(k as String, _$enumDecode(_$CategoryEnumMap, e)), + ) + ..categoryCounts = (json['categoryCounts'] as Map?)?.map( + (k, e) => MapEntry(_$enumDecode(_$CategoryEnumMap, k), e as int), + ); Map _$PersonToJson(Person instance) => { 'firstName': instance.firstName, @@ -83,7 +81,10 @@ const _$CategoryEnumMap = { }; Order _$OrderFromJson(Map json) { - $checkKeys(json, disallowNullValues: const ['count']); + $checkKeys( + json, + disallowNullValues: const ['count'], + ); return Order( _$enumDecodeNullable(_$CategoryEnumMap, json['category']), (json['items'] as List?) @@ -147,16 +148,15 @@ const _$StatusCodeEnumMap = { StatusCode.unknown: 'unknown', }; -Item _$ItemFromJson(Map json) { - return Item( - json['price'] as int?, - ) - ..itemNumber = json['item-number'] as int? - ..saleDates = (json['saleDates'] as List?) - ?.map((e) => DateTime.parse(e as String)) - .toList() - ..rates = (json['rates'] as List?)?.map((e) => e as int).toList(); -} +Item _$ItemFromJson(Map json) => Item( + json['price'] as int?, + ) + ..itemNumber = json['item-number'] as int? + ..saleDates = (json['saleDates'] as List?) + ?.map((e) => DateTime.parse(e as String)) + .toList() + ..rates = + (json['rates'] as List?)?.map((e) => e as int).toList(); Map _$ItemToJson(Item instance) { final val = { @@ -176,19 +176,17 @@ Map _$ItemToJson(Item instance) { return val; } -Numbers _$NumbersFromJson(Map json) { - return Numbers() - ..ints = (json['ints'] as List?)?.map((e) => e as int).toList() - ..nums = (json['nums'] as List?)?.map((e) => e as num).toList() - ..doubles = (json['doubles'] as List?) - ?.map((e) => (e as num).toDouble()) - .toList() - ..nnDoubles = (json['nnDoubles'] as List?) - ?.map((e) => (e as num).toDouble()) - .toList() - ..duration = durationFromInt(json['duration'] as int?) - ..date = dateTimeFromEpochUs(json['date'] as int?); -} +Numbers _$NumbersFromJson(Map json) => Numbers() + ..ints = (json['ints'] as List?)?.map((e) => e as int).toList() + ..nums = (json['nums'] as List?)?.map((e) => e as num).toList() + ..doubles = (json['doubles'] as List?) + ?.map((e) => (e as num).toDouble()) + .toList() + ..nnDoubles = (json['nnDoubles'] as List?) + ?.map((e) => (e as num).toDouble()) + .toList() + ..duration = durationFromInt(json['duration'] as int?) + ..date = dateTimeFromEpochUs(json['date'] as int?); Map _$NumbersToJson(Numbers instance) => { 'ints': instance.ints, @@ -199,21 +197,19 @@ Map _$NumbersToJson(Numbers instance) => { 'date': dateTimeToEpochUs(instance.date), }; -MapKeyVariety _$MapKeyVarietyFromJson(Map json) { - return MapKeyVariety() - ..intIntMap = (json['intIntMap'] as Map?)?.map( - (k, e) => MapEntry(int.parse(k as String), e as int), - ) - ..uriIntMap = (json['uriIntMap'] as Map?)?.map( - (k, e) => MapEntry(Uri.parse(k as String), e as int), - ) - ..dateTimeIntMap = (json['dateTimeIntMap'] as Map?)?.map( - (k, e) => MapEntry(DateTime.parse(k as String), e as int), - ) - ..bigIntMap = (json['bigIntMap'] as Map?)?.map( - (k, e) => MapEntry(BigInt.parse(k as String), e as int), - ); -} +MapKeyVariety _$MapKeyVarietyFromJson(Map json) => MapKeyVariety() + ..intIntMap = (json['intIntMap'] as Map?)?.map( + (k, e) => MapEntry(int.parse(k as String), e as int), + ) + ..uriIntMap = (json['uriIntMap'] as Map?)?.map( + (k, e) => MapEntry(Uri.parse(k as String), e as int), + ) + ..dateTimeIntMap = (json['dateTimeIntMap'] as Map?)?.map( + (k, e) => MapEntry(DateTime.parse(k as String), e as int), + ) + ..bigIntMap = (json['bigIntMap'] as Map?)?.map( + (k, e) => MapEntry(BigInt.parse(k as String), e as int), + ); Map _$MapKeyVarietyToJson(MapKeyVariety instance) => { @@ -224,19 +220,17 @@ Map _$MapKeyVarietyToJson(MapKeyVariety instance) => 'bigIntMap': instance.bigIntMap?.map((k, e) => MapEntry(k.toString(), e)), }; -UnknownEnumValue _$UnknownEnumValueFromJson(Map json) { - return UnknownEnumValue() - ..enumValue = _$enumDecode(_$CategoryEnumMap, json['enumValue'], - unknownValue: Category.notDiscoveredYet) - ..enumIterable = (json['enumIterable'] as List).map((e) => - _$enumDecode(_$CategoryEnumMap, e, - unknownValue: Category.notDiscoveredYet)) - ..enumList = (json['enumList'] as List) - .map((e) => _$enumDecode(_$CategoryEnumMap, e, - unknownValue: Category.notDiscoveredYet)) - .toList() - ..enumSet = (json['enumSet'] as List) - .map((e) => _$enumDecode(_$CategoryEnumMap, e, - unknownValue: Category.notDiscoveredYet)) - .toSet(); -} +UnknownEnumValue _$UnknownEnumValueFromJson(Map json) => UnknownEnumValue() + ..enumValue = _$enumDecode(_$CategoryEnumMap, json['enumValue'], + unknownValue: Category.notDiscoveredYet) + ..enumIterable = (json['enumIterable'] as List).map((e) => + _$enumDecode(_$CategoryEnumMap, e, + unknownValue: Category.notDiscoveredYet)) + ..enumList = (json['enumList'] as List) + .map((e) => _$enumDecode(_$CategoryEnumMap, e, + unknownValue: Category.notDiscoveredYet)) + .toList() + ..enumSet = (json['enumSet'] as List) + .map((e) => _$enumDecode(_$CategoryEnumMap, e, + unknownValue: Category.notDiscoveredYet)) + .toSet(); diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g.dart index 03a894f51..6806d3a28 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g.dart @@ -6,69 +6,70 @@ part of 'kitchen_sink.dart'; // JsonSerializableGenerator // ************************************************************************** -KitchenSink _$KitchenSinkFromJson(Map json) { - return KitchenSink( - ctorValidatedNo42: json['no-42'] as int?, - iterable: json['iterable'] as List?, - dynamicIterable: json['dynamicIterable'] as List?, - objectIterable: - (json['objectIterable'] as List?)?.map((e) => e as Object), - intIterable: (json['intIterable'] as List?)?.map((e) => e as int), - dateTimeIterable: (json['datetime-iterable'] as List?) - ?.map((e) => DateTime.parse(e as String)), - ) - ..dateTime = json['dateTime'] == null - ? null - : DateTime.parse(json['dateTime'] as String) - ..bigInt = - json['bigInt'] == null ? null : BigInt.parse(json['bigInt'] as String) - ..set = (json['set'] as List).toSet() - ..dynamicSet = (json['dynamicSet'] as List).toSet() - ..objectSet = - (json['objectSet'] as List).map((e) => e as Object).toSet() - ..intSet = (json['intSet'] as List).map((e) => e as int).toSet() - ..dateTimeSet = (json['dateTimeSet'] as List) - .map((e) => DateTime.parse(e as String)) - .toSet() - ..list = json['list'] as List - ..dynamicList = json['dynamicList'] as List - ..objectList = - (json['objectList'] as List).map((e) => e as Object).toList() - ..intList = (json['intList'] as List).map((e) => e as int).toList() - ..dateTimeList = (json['dateTimeList'] as List) - .map((e) => DateTime.parse(e as String)) - .toList() - ..map = json['map'] as Map - ..stringStringMap = Map.from(json['stringStringMap'] as Map) - ..dynamicIntMap = Map.from(json['dynamicIntMap'] as Map) - ..objectDateTimeMap = - (json['objectDateTimeMap'] as Map).map( - (k, e) => MapEntry(k, DateTime.parse(e as String)), +KitchenSink _$KitchenSinkFromJson(Map json) => KitchenSink( + ctorValidatedNo42: json['no-42'] as int?, + iterable: json['iterable'] as List?, + dynamicIterable: json['dynamicIterable'] as List?, + objectIterable: + (json['objectIterable'] as List?)?.map((e) => e as Object), + intIterable: + (json['intIterable'] as List?)?.map((e) => e as int), + dateTimeIterable: (json['datetime-iterable'] as List?) + ?.map((e) => DateTime.parse(e as String)), ) - ..crazyComplex = (json['crazyComplex'] as List) - .map((e) => (e as Map?)?.map( - (k, e) => MapEntry( - k, - (e as Map?)?.map( - (k, e) => MapEntry( - k, - (e as List?) - ?.map((e) => (e as List?) - ?.map((e) => DateTime.parse(e as String)) - .toList()) - .toList()), - )), - )) - .toList() - ..val = Map.from(json['val'] as Map) - ..writeNotNull = json['writeNotNull'] as bool? - ..string = json[r'$string'] as String? - ..simpleObject = - SimpleObject.fromJson(json['simpleObject'] as Map) - ..strictKeysObject = StrictKeysObject.fromJson( - json['strictKeysObject'] as Map) - ..validatedPropertyNo42 = json['validatedPropertyNo42'] as int?; -} + ..dateTime = json['dateTime'] == null + ? null + : DateTime.parse(json['dateTime'] as String) + ..bigInt = + json['bigInt'] == null ? null : BigInt.parse(json['bigInt'] as String) + ..set = (json['set'] as List).toSet() + ..dynamicSet = (json['dynamicSet'] as List).toSet() + ..objectSet = + (json['objectSet'] as List).map((e) => e as Object).toSet() + ..intSet = (json['intSet'] as List).map((e) => e as int).toSet() + ..dateTimeSet = (json['dateTimeSet'] as List) + .map((e) => DateTime.parse(e as String)) + .toSet() + ..list = json['list'] as List + ..dynamicList = json['dynamicList'] as List + ..objectList = + (json['objectList'] as List).map((e) => e as Object).toList() + ..intList = + (json['intList'] as List).map((e) => e as int).toList() + ..dateTimeList = (json['dateTimeList'] as List) + .map((e) => DateTime.parse(e as String)) + .toList() + ..map = json['map'] as Map + ..stringStringMap = + Map.from(json['stringStringMap'] as Map) + ..dynamicIntMap = Map.from(json['dynamicIntMap'] as Map) + ..objectDateTimeMap = + (json['objectDateTimeMap'] as Map).map( + (k, e) => MapEntry(k, DateTime.parse(e as String)), + ) + ..crazyComplex = (json['crazyComplex'] as List) + .map((e) => (e as Map?)?.map( + (k, e) => MapEntry( + k, + (e as Map?)?.map( + (k, e) => MapEntry( + k, + (e as List?) + ?.map((e) => (e as List?) + ?.map((e) => DateTime.parse(e as String)) + .toList()) + .toList()), + )), + )) + .toList() + ..val = Map.from(json['val'] as Map) + ..writeNotNull = json['writeNotNull'] as bool? + ..string = json[r'$string'] as String? + ..simpleObject = + SimpleObject.fromJson(json['simpleObject'] as Map) + ..strictKeysObject = StrictKeysObject.fromJson( + json['strictKeysObject'] as Map) + ..validatedPropertyNo42 = json['validatedPropertyNo42'] as int?; Map _$KitchenSinkToJson(KitchenSink instance) => { @@ -116,24 +117,23 @@ Map _$KitchenSinkToJson(KitchenSink instance) => }; JsonConverterTestClass _$JsonConverterTestClassFromJson( - Map json) { - return JsonConverterTestClass( - durationConverter.fromJson(json['duration'] as int?), - (json['durationList'] as List) - .map((e) => durationConverter.fromJson(e as int?)) - .toList(), - const BigIntStringConverter().fromJson(json['bigInt'] as String), - (json['bigIntMap'] as Map).map( - (k, e) => - MapEntry(k, const BigIntStringConverter().fromJson(e as String)), - ), - TrivialNumberConverter.instance.fromJson(json['numberSilly'] as int?), - (json['numberSillySet'] as List) - .map((e) => TrivialNumberConverter.instance.fromJson(e as int?)) - .toSet(), - const EpochDateTimeConverter().fromJson(json['dateTime'] as int?), - ); -} + Map json) => + JsonConverterTestClass( + durationConverter.fromJson(json['duration'] as int?), + (json['durationList'] as List) + .map((e) => durationConverter.fromJson(e as int?)) + .toList(), + const BigIntStringConverter().fromJson(json['bigInt'] as String), + (json['bigIntMap'] as Map).map( + (k, e) => + MapEntry(k, const BigIntStringConverter().fromJson(e as String)), + ), + TrivialNumberConverter.instance.fromJson(json['numberSilly'] as int?), + (json['numberSillySet'] as List) + .map((e) => TrivialNumberConverter.instance.fromJson(e as int?)) + .toSet(), + const EpochDateTimeConverter().fromJson(json['dateTime'] as int?), + ); Map _$JsonConverterTestClassToJson( JsonConverterTestClass instance) => @@ -153,18 +153,17 @@ Map _$JsonConverterTestClassToJson( }; JsonConverterGeneric _$JsonConverterGenericFromJson( - Map json) { - return JsonConverterGeneric( - GenericConverter().fromJson(json['item'] as Map), - (json['itemList'] as List) - .map((e) => GenericConverter().fromJson(e as Map)) - .toList(), - (json['itemMap'] as Map).map( - (k, e) => MapEntry( - k, GenericConverter().fromJson(e as Map)), - ), - ); -} + Map json) => + JsonConverterGeneric( + GenericConverter().fromJson(json['item'] as Map), + (json['itemList'] as List) + .map((e) => GenericConverter().fromJson(e as Map)) + .toList(), + (json['itemMap'] as Map).map( + (k, e) => MapEntry( + k, GenericConverter().fromJson(e as Map)), + ), + ); Map _$JsonConverterGenericToJson( JsonConverterGeneric instance) => diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart index 01b13ef4b..6e23c1532 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart @@ -6,67 +6,68 @@ part of 'kitchen_sink.g_any_map.dart'; // JsonSerializableGenerator // ************************************************************************** -KitchenSink _$KitchenSinkFromJson(Map json) { - return KitchenSink( - ctorValidatedNo42: json['no-42'] as int?, - iterable: json['iterable'] as List?, - dynamicIterable: json['dynamicIterable'] as List?, - objectIterable: - (json['objectIterable'] as List?)?.map((e) => e as Object), - intIterable: (json['intIterable'] as List?)?.map((e) => e as int), - dateTimeIterable: (json['datetime-iterable'] as List?) - ?.map((e) => DateTime.parse(e as String)), - ) - ..dateTime = json['dateTime'] == null - ? null - : DateTime.parse(json['dateTime'] as String) - ..bigInt = - json['bigInt'] == null ? null : BigInt.parse(json['bigInt'] as String) - ..set = (json['set'] as List).toSet() - ..dynamicSet = (json['dynamicSet'] as List).toSet() - ..objectSet = - (json['objectSet'] as List).map((e) => e as Object).toSet() - ..intSet = (json['intSet'] as List).map((e) => e as int).toSet() - ..dateTimeSet = (json['dateTimeSet'] as List) - .map((e) => DateTime.parse(e as String)) - .toSet() - ..list = json['list'] as List - ..dynamicList = json['dynamicList'] as List - ..objectList = - (json['objectList'] as List).map((e) => e as Object).toList() - ..intList = (json['intList'] as List).map((e) => e as int).toList() - ..dateTimeList = (json['dateTimeList'] as List) - .map((e) => DateTime.parse(e as String)) - .toList() - ..map = json['map'] as Map - ..stringStringMap = Map.from(json['stringStringMap'] as Map) - ..dynamicIntMap = Map.from(json['dynamicIntMap'] as Map) - ..objectDateTimeMap = (json['objectDateTimeMap'] as Map).map( - (k, e) => MapEntry(k as Object, DateTime.parse(e as String)), +KitchenSink _$KitchenSinkFromJson(Map json) => KitchenSink( + ctorValidatedNo42: json['no-42'] as int?, + iterable: json['iterable'] as List?, + dynamicIterable: json['dynamicIterable'] as List?, + objectIterable: + (json['objectIterable'] as List?)?.map((e) => e as Object), + intIterable: + (json['intIterable'] as List?)?.map((e) => e as int), + dateTimeIterable: (json['datetime-iterable'] as List?) + ?.map((e) => DateTime.parse(e as String)), ) - ..crazyComplex = (json['crazyComplex'] as List) - .map((e) => (e as Map?)?.map( - (k, e) => MapEntry( - k as String, - (e as Map?)?.map( - (k, e) => MapEntry( - k as String, - (e as List?) - ?.map((e) => (e as List?) - ?.map((e) => DateTime.parse(e as String)) - .toList()) - .toList()), - )), - )) - .toList() - ..val = Map.from(json['val'] as Map) - ..writeNotNull = json['writeNotNull'] as bool? - ..string = json[r'$string'] as String? - ..simpleObject = SimpleObject.fromJson(json['simpleObject'] as Map) - ..strictKeysObject = - StrictKeysObject.fromJson(json['strictKeysObject'] as Map) - ..validatedPropertyNo42 = json['validatedPropertyNo42'] as int?; -} + ..dateTime = json['dateTime'] == null + ? null + : DateTime.parse(json['dateTime'] as String) + ..bigInt = + json['bigInt'] == null ? null : BigInt.parse(json['bigInt'] as String) + ..set = (json['set'] as List).toSet() + ..dynamicSet = (json['dynamicSet'] as List).toSet() + ..objectSet = + (json['objectSet'] as List).map((e) => e as Object).toSet() + ..intSet = (json['intSet'] as List).map((e) => e as int).toSet() + ..dateTimeSet = (json['dateTimeSet'] as List) + .map((e) => DateTime.parse(e as String)) + .toSet() + ..list = json['list'] as List + ..dynamicList = json['dynamicList'] as List + ..objectList = + (json['objectList'] as List).map((e) => e as Object).toList() + ..intList = + (json['intList'] as List).map((e) => e as int).toList() + ..dateTimeList = (json['dateTimeList'] as List) + .map((e) => DateTime.parse(e as String)) + .toList() + ..map = json['map'] as Map + ..stringStringMap = + Map.from(json['stringStringMap'] as Map) + ..dynamicIntMap = Map.from(json['dynamicIntMap'] as Map) + ..objectDateTimeMap = (json['objectDateTimeMap'] as Map).map( + (k, e) => MapEntry(k as Object, DateTime.parse(e as String)), + ) + ..crazyComplex = (json['crazyComplex'] as List) + .map((e) => (e as Map?)?.map( + (k, e) => MapEntry( + k as String, + (e as Map?)?.map( + (k, e) => MapEntry( + k as String, + (e as List?) + ?.map((e) => (e as List?) + ?.map((e) => DateTime.parse(e as String)) + .toList()) + .toList()), + )), + )) + .toList() + ..val = Map.from(json['val'] as Map) + ..writeNotNull = json['writeNotNull'] as bool? + ..string = json[r'$string'] as String? + ..simpleObject = SimpleObject.fromJson(json['simpleObject'] as Map) + ..strictKeysObject = + StrictKeysObject.fromJson(json['strictKeysObject'] as Map) + ..validatedPropertyNo42 = json['validatedPropertyNo42'] as int?; Map _$KitchenSinkToJson(KitchenSink instance) => { @@ -113,24 +114,23 @@ Map _$KitchenSinkToJson(KitchenSink instance) => 'validatedPropertyNo42': instance.validatedPropertyNo42, }; -JsonConverterTestClass _$JsonConverterTestClassFromJson(Map json) { - return JsonConverterTestClass( - durationConverter.fromJson(json['duration'] as int?), - (json['durationList'] as List) - .map((e) => durationConverter.fromJson(e as int?)) - .toList(), - const BigIntStringConverter().fromJson(json['bigInt'] as String), - (json['bigIntMap'] as Map).map( - (k, e) => MapEntry( - k as String, const BigIntStringConverter().fromJson(e as String)), - ), - TrivialNumberConverter.instance.fromJson(json['numberSilly'] as int?), - (json['numberSillySet'] as List) - .map((e) => TrivialNumberConverter.instance.fromJson(e as int?)) - .toSet(), - const EpochDateTimeConverter().fromJson(json['dateTime'] as int?), - ); -} +JsonConverterTestClass _$JsonConverterTestClassFromJson(Map json) => + JsonConverterTestClass( + durationConverter.fromJson(json['duration'] as int?), + (json['durationList'] as List) + .map((e) => durationConverter.fromJson(e as int?)) + .toList(), + const BigIntStringConverter().fromJson(json['bigInt'] as String), + (json['bigIntMap'] as Map).map( + (k, e) => MapEntry( + k as String, const BigIntStringConverter().fromJson(e as String)), + ), + TrivialNumberConverter.instance.fromJson(json['numberSilly'] as int?), + (json['numberSillySet'] as List) + .map((e) => TrivialNumberConverter.instance.fromJson(e as int?)) + .toSet(), + const EpochDateTimeConverter().fromJson(json['dateTime'] as int?), + ); Map _$JsonConverterTestClassToJson( JsonConverterTestClass instance) => @@ -150,18 +150,17 @@ Map _$JsonConverterTestClassToJson( }; JsonConverterGeneric _$JsonConverterGenericFromJson( - Map json) { - return JsonConverterGeneric( - GenericConverter().fromJson(json['item'] as Map), - (json['itemList'] as List) - .map((e) => GenericConverter().fromJson(e as Map)) - .toList(), - (json['itemMap'] as Map).map( - (k, e) => MapEntry(k as String, - GenericConverter().fromJson(e as Map)), - ), - ); -} + Map json) => + JsonConverterGeneric( + GenericConverter().fromJson(json['item'] as Map), + (json['itemList'] as List) + .map((e) => GenericConverter().fromJson(e as Map)) + .toList(), + (json['itemMap'] as Map).map( + (k, e) => MapEntry(k as String, + GenericConverter().fromJson(e as Map)), + ), + ); Map _$JsonConverterGenericToJson( JsonConverterGeneric instance) => diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.g.dart index 7795882c6..8a8e80f7e 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.g.dart @@ -6,98 +6,108 @@ part of 'kitchen_sink.g_any_map__checked.dart'; // JsonSerializableGenerator // ************************************************************************** -KitchenSink _$KitchenSinkFromJson(Map json) { - return $checkedCreate('KitchenSink', json, ($checkedConvert) { - final val = KitchenSink( - ctorValidatedNo42: $checkedConvert('no-42', (v) => v as int?), - iterable: $checkedConvert('iterable', (v) => v as List?), - dynamicIterable: - $checkedConvert('dynamicIterable', (v) => v as List?), - objectIterable: $checkedConvert('objectIterable', - (v) => (v as List?)?.map((e) => e as Object)), - intIterable: $checkedConvert( - 'intIterable', (v) => (v as List?)?.map((e) => e as int)), - dateTimeIterable: $checkedConvert( - 'datetime-iterable', - (v) => - (v as List?)?.map((e) => DateTime.parse(e as String))), +KitchenSink _$KitchenSinkFromJson(Map json) => $checkedCreate( + 'KitchenSink', + json, + ($checkedConvert) { + final val = KitchenSink( + ctorValidatedNo42: $checkedConvert('no-42', (v) => v as int?), + iterable: $checkedConvert('iterable', (v) => v as List?), + dynamicIterable: + $checkedConvert('dynamicIterable', (v) => v as List?), + objectIterable: $checkedConvert('objectIterable', + (v) => (v as List?)?.map((e) => e as Object)), + intIterable: $checkedConvert('intIterable', + (v) => (v as List?)?.map((e) => e as int)), + dateTimeIterable: $checkedConvert( + 'datetime-iterable', + (v) => (v as List?) + ?.map((e) => DateTime.parse(e as String))), + ); + $checkedConvert( + 'dateTime', + (v) => + val.dateTime = v == null ? null : DateTime.parse(v as String)); + $checkedConvert('bigInt', + (v) => val.bigInt = v == null ? null : BigInt.parse(v as String)); + $checkedConvert('set', (v) => val.set = (v as List).toSet()); + $checkedConvert( + 'dynamicSet', (v) => val.dynamicSet = (v as List).toSet()); + $checkedConvert( + 'objectSet', + (v) => val.objectSet = + (v as List).map((e) => e as Object).toSet()); + $checkedConvert( + 'intSet', + (v) => + val.intSet = (v as List).map((e) => e as int).toSet()); + $checkedConvert( + 'dateTimeSet', + (v) => val.dateTimeSet = (v as List) + .map((e) => DateTime.parse(e as String)) + .toSet()); + $checkedConvert('list', (v) => val.list = v as List); + $checkedConvert( + 'dynamicList', (v) => val.dynamicList = v as List); + $checkedConvert( + 'objectList', + (v) => val.objectList = + (v as List).map((e) => e as Object).toList()); + $checkedConvert( + 'intList', + (v) => val.intList = + (v as List).map((e) => e as int).toList()); + $checkedConvert( + 'dateTimeList', + (v) => val.dateTimeList = (v as List) + .map((e) => DateTime.parse(e as String)) + .toList()); + $checkedConvert('map', (v) => val.map = v as Map); + $checkedConvert('stringStringMap', + (v) => val.stringStringMap = Map.from(v as Map)); + $checkedConvert('dynamicIntMap', + (v) => val.dynamicIntMap = Map.from(v as Map)); + $checkedConvert( + 'objectDateTimeMap', + (v) => val.objectDateTimeMap = (v as Map).map( + (k, e) => MapEntry(k as Object, DateTime.parse(e as String)), + )); + $checkedConvert( + 'crazyComplex', + (v) => val.crazyComplex = (v as List) + .map((e) => (e as Map?)?.map( + (k, e) => MapEntry( + k as String, + (e as Map?)?.map( + (k, e) => MapEntry( + k as String, + (e as List?) + ?.map((e) => (e as List?) + ?.map( + (e) => DateTime.parse(e as String)) + .toList()) + .toList()), + )), + )) + .toList()); + $checkedConvert( + 'val', (v) => val.val = Map.from(v as Map)); + $checkedConvert('writeNotNull', (v) => val.writeNotNull = v as bool?); + $checkedConvert(r'$string', (v) => val.string = v as String?); + $checkedConvert('simpleObject', + (v) => val.simpleObject = SimpleObject.fromJson(v as Map)); + $checkedConvert('strictKeysObject', + (v) => val.strictKeysObject = StrictKeysObject.fromJson(v as Map)); + $checkedConvert('validatedPropertyNo42', + (v) => val.validatedPropertyNo42 = v as int?); + return val; + }, + fieldKeyMap: const { + 'ctorValidatedNo42': 'no-42', + 'dateTimeIterable': 'datetime-iterable', + 'string': r'$string' + }, ); - $checkedConvert('dateTime', - (v) => val.dateTime = v == null ? null : DateTime.parse(v as String)); - $checkedConvert('bigInt', - (v) => val.bigInt = v == null ? null : BigInt.parse(v as String)); - $checkedConvert('set', (v) => val.set = (v as List).toSet()); - $checkedConvert( - 'dynamicSet', (v) => val.dynamicSet = (v as List).toSet()); - $checkedConvert( - 'objectSet', - (v) => val.objectSet = - (v as List).map((e) => e as Object).toSet()); - $checkedConvert('intSet', - (v) => val.intSet = (v as List).map((e) => e as int).toSet()); - $checkedConvert( - 'dateTimeSet', - (v) => val.dateTimeSet = (v as List) - .map((e) => DateTime.parse(e as String)) - .toSet()); - $checkedConvert('list', (v) => val.list = v as List); - $checkedConvert('dynamicList', (v) => val.dynamicList = v as List); - $checkedConvert( - 'objectList', - (v) => val.objectList = - (v as List).map((e) => e as Object).toList()); - $checkedConvert( - 'intList', - (v) => - val.intList = (v as List).map((e) => e as int).toList()); - $checkedConvert( - 'dateTimeList', - (v) => val.dateTimeList = (v as List) - .map((e) => DateTime.parse(e as String)) - .toList()); - $checkedConvert('map', (v) => val.map = v as Map); - $checkedConvert('stringStringMap', - (v) => val.stringStringMap = Map.from(v as Map)); - $checkedConvert('dynamicIntMap', - (v) => val.dynamicIntMap = Map.from(v as Map)); - $checkedConvert( - 'objectDateTimeMap', - (v) => val.objectDateTimeMap = (v as Map).map( - (k, e) => MapEntry(k as Object, DateTime.parse(e as String)), - )); - $checkedConvert( - 'crazyComplex', - (v) => val.crazyComplex = (v as List) - .map((e) => (e as Map?)?.map( - (k, e) => MapEntry( - k as String, - (e as Map?)?.map( - (k, e) => MapEntry( - k as String, - (e as List?) - ?.map((e) => (e as List?) - ?.map((e) => DateTime.parse(e as String)) - .toList()) - .toList()), - )), - )) - .toList()); - $checkedConvert('val', (v) => val.val = Map.from(v as Map)); - $checkedConvert('writeNotNull', (v) => val.writeNotNull = v as bool?); - $checkedConvert(r'$string', (v) => val.string = v as String?); - $checkedConvert('simpleObject', - (v) => val.simpleObject = SimpleObject.fromJson(v as Map)); - $checkedConvert('strictKeysObject', - (v) => val.strictKeysObject = StrictKeysObject.fromJson(v as Map)); - $checkedConvert( - 'validatedPropertyNo42', (v) => val.validatedPropertyNo42 = v as int?); - return val; - }, fieldKeyMap: const { - 'ctorValidatedNo42': 'no-42', - 'dateTimeIterable': 'datetime-iterable', - 'string': r'$string' - }); -} Map _$KitchenSinkToJson(KitchenSink instance) => { @@ -144,36 +154,41 @@ Map _$KitchenSinkToJson(KitchenSink instance) => 'validatedPropertyNo42': instance.validatedPropertyNo42, }; -JsonConverterTestClass _$JsonConverterTestClassFromJson(Map json) { - return $checkedCreate('JsonConverterTestClass', json, ($checkedConvert) { - final val = JsonConverterTestClass( - $checkedConvert('duration', (v) => durationConverter.fromJson(v as int?)), - $checkedConvert( - 'durationList', - (v) => (v as List) - .map((e) => durationConverter.fromJson(e as int?)) - .toList()), - $checkedConvert( - 'bigInt', (v) => const BigIntStringConverter().fromJson(v as String)), - $checkedConvert( - 'bigIntMap', - (v) => (v as Map).map( - (k, e) => MapEntry(k as String, - const BigIntStringConverter().fromJson(e as String)), - )), - $checkedConvert('numberSilly', - (v) => TrivialNumberConverter.instance.fromJson(v as int?)), - $checkedConvert( - 'numberSillySet', - (v) => (v as List) - .map((e) => TrivialNumberConverter.instance.fromJson(e as int?)) - .toSet()), - $checkedConvert('dateTime', - (v) => const EpochDateTimeConverter().fromJson(v as int?)), +JsonConverterTestClass _$JsonConverterTestClassFromJson(Map json) => + $checkedCreate( + 'JsonConverterTestClass', + json, + ($checkedConvert) { + final val = JsonConverterTestClass( + $checkedConvert( + 'duration', (v) => durationConverter.fromJson(v as int?)), + $checkedConvert( + 'durationList', + (v) => (v as List) + .map((e) => durationConverter.fromJson(e as int?)) + .toList()), + $checkedConvert('bigInt', + (v) => const BigIntStringConverter().fromJson(v as String)), + $checkedConvert( + 'bigIntMap', + (v) => (v as Map).map( + (k, e) => MapEntry(k as String, + const BigIntStringConverter().fromJson(e as String)), + )), + $checkedConvert('numberSilly', + (v) => TrivialNumberConverter.instance.fromJson(v as int?)), + $checkedConvert( + 'numberSillySet', + (v) => (v as List) + .map((e) => + TrivialNumberConverter.instance.fromJson(e as int?)) + .toSet()), + $checkedConvert('dateTime', + (v) => const EpochDateTimeConverter().fromJson(v as int?)), + ); + return val; + }, ); - return val; - }); -} Map _$JsonConverterTestClassToJson( JsonConverterTestClass instance) => @@ -193,27 +208,32 @@ Map _$JsonConverterTestClassToJson( }; JsonConverterGeneric _$JsonConverterGenericFromJson( - Map json) { - return $checkedCreate('JsonConverterGeneric', json, ($checkedConvert) { - final val = JsonConverterGeneric( - $checkedConvert('item', - (v) => GenericConverter().fromJson(v as Map)), - $checkedConvert( - 'itemList', - (v) => (v as List) - .map((e) => - GenericConverter().fromJson(e as Map)) - .toList()), - $checkedConvert( - 'itemMap', - (v) => (v as Map).map( - (k, e) => MapEntry(k as String, - GenericConverter().fromJson(e as Map)), - )), + Map json) => + $checkedCreate( + 'JsonConverterGeneric', + json, + ($checkedConvert) { + final val = JsonConverterGeneric( + $checkedConvert('item', + (v) => GenericConverter().fromJson(v as Map)), + $checkedConvert( + 'itemList', + (v) => (v as List) + .map((e) => + GenericConverter().fromJson(e as Map)) + .toList()), + $checkedConvert( + 'itemMap', + (v) => (v as Map).map( + (k, e) => MapEntry( + k as String, + GenericConverter() + .fromJson(e as Map)), + )), + ); + return val; + }, ); - return val; - }); -} Map _$JsonConverterGenericToJson( JsonConverterGeneric instance) => diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart index 095cd3892..b48ce597c 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart @@ -6,69 +6,70 @@ part of 'kitchen_sink.g_exclude_null.dart'; // JsonSerializableGenerator // ************************************************************************** -KitchenSink _$KitchenSinkFromJson(Map json) { - return KitchenSink( - ctorValidatedNo42: json['no-42'] as int?, - iterable: json['iterable'] as List?, - dynamicIterable: json['dynamicIterable'] as List?, - objectIterable: - (json['objectIterable'] as List?)?.map((e) => e as Object), - intIterable: (json['intIterable'] as List?)?.map((e) => e as int), - dateTimeIterable: (json['datetime-iterable'] as List?) - ?.map((e) => DateTime.parse(e as String)), - ) - ..dateTime = json['dateTime'] == null - ? null - : DateTime.parse(json['dateTime'] as String) - ..bigInt = - json['bigInt'] == null ? null : BigInt.parse(json['bigInt'] as String) - ..set = (json['set'] as List).toSet() - ..dynamicSet = (json['dynamicSet'] as List).toSet() - ..objectSet = - (json['objectSet'] as List).map((e) => e as Object).toSet() - ..intSet = (json['intSet'] as List).map((e) => e as int).toSet() - ..dateTimeSet = (json['dateTimeSet'] as List) - .map((e) => DateTime.parse(e as String)) - .toSet() - ..list = json['list'] as List - ..dynamicList = json['dynamicList'] as List - ..objectList = - (json['objectList'] as List).map((e) => e as Object).toList() - ..intList = (json['intList'] as List).map((e) => e as int).toList() - ..dateTimeList = (json['dateTimeList'] as List) - .map((e) => DateTime.parse(e as String)) - .toList() - ..map = json['map'] as Map - ..stringStringMap = Map.from(json['stringStringMap'] as Map) - ..dynamicIntMap = Map.from(json['dynamicIntMap'] as Map) - ..objectDateTimeMap = - (json['objectDateTimeMap'] as Map).map( - (k, e) => MapEntry(k, DateTime.parse(e as String)), +KitchenSink _$KitchenSinkFromJson(Map json) => KitchenSink( + ctorValidatedNo42: json['no-42'] as int?, + iterable: json['iterable'] as List?, + dynamicIterable: json['dynamicIterable'] as List?, + objectIterable: + (json['objectIterable'] as List?)?.map((e) => e as Object), + intIterable: + (json['intIterable'] as List?)?.map((e) => e as int), + dateTimeIterable: (json['datetime-iterable'] as List?) + ?.map((e) => DateTime.parse(e as String)), ) - ..crazyComplex = (json['crazyComplex'] as List) - .map((e) => (e as Map?)?.map( - (k, e) => MapEntry( - k, - (e as Map?)?.map( - (k, e) => MapEntry( - k, - (e as List?) - ?.map((e) => (e as List?) - ?.map((e) => DateTime.parse(e as String)) - .toList()) - .toList()), - )), - )) - .toList() - ..val = Map.from(json['val'] as Map) - ..writeNotNull = json['writeNotNull'] as bool? - ..string = json[r'$string'] as String? - ..simpleObject = - SimpleObject.fromJson(json['simpleObject'] as Map) - ..strictKeysObject = StrictKeysObject.fromJson( - json['strictKeysObject'] as Map) - ..validatedPropertyNo42 = json['validatedPropertyNo42'] as int?; -} + ..dateTime = json['dateTime'] == null + ? null + : DateTime.parse(json['dateTime'] as String) + ..bigInt = + json['bigInt'] == null ? null : BigInt.parse(json['bigInt'] as String) + ..set = (json['set'] as List).toSet() + ..dynamicSet = (json['dynamicSet'] as List).toSet() + ..objectSet = + (json['objectSet'] as List).map((e) => e as Object).toSet() + ..intSet = (json['intSet'] as List).map((e) => e as int).toSet() + ..dateTimeSet = (json['dateTimeSet'] as List) + .map((e) => DateTime.parse(e as String)) + .toSet() + ..list = json['list'] as List + ..dynamicList = json['dynamicList'] as List + ..objectList = + (json['objectList'] as List).map((e) => e as Object).toList() + ..intList = + (json['intList'] as List).map((e) => e as int).toList() + ..dateTimeList = (json['dateTimeList'] as List) + .map((e) => DateTime.parse(e as String)) + .toList() + ..map = json['map'] as Map + ..stringStringMap = + Map.from(json['stringStringMap'] as Map) + ..dynamicIntMap = Map.from(json['dynamicIntMap'] as Map) + ..objectDateTimeMap = + (json['objectDateTimeMap'] as Map).map( + (k, e) => MapEntry(k, DateTime.parse(e as String)), + ) + ..crazyComplex = (json['crazyComplex'] as List) + .map((e) => (e as Map?)?.map( + (k, e) => MapEntry( + k, + (e as Map?)?.map( + (k, e) => MapEntry( + k, + (e as List?) + ?.map((e) => (e as List?) + ?.map((e) => DateTime.parse(e as String)) + .toList()) + .toList()), + )), + )) + .toList() + ..val = Map.from(json['val'] as Map) + ..writeNotNull = json['writeNotNull'] as bool? + ..string = json[r'$string'] as String? + ..simpleObject = + SimpleObject.fromJson(json['simpleObject'] as Map) + ..strictKeysObject = StrictKeysObject.fromJson( + json['strictKeysObject'] as Map) + ..validatedPropertyNo42 = json['validatedPropertyNo42'] as int?; Map _$KitchenSinkToJson(KitchenSink instance) { final val = {}; @@ -124,24 +125,23 @@ Map _$KitchenSinkToJson(KitchenSink instance) { } JsonConverterTestClass _$JsonConverterTestClassFromJson( - Map json) { - return JsonConverterTestClass( - durationConverter.fromJson(json['duration'] as int?), - (json['durationList'] as List) - .map((e) => durationConverter.fromJson(e as int?)) - .toList(), - const BigIntStringConverter().fromJson(json['bigInt'] as String), - (json['bigIntMap'] as Map).map( - (k, e) => - MapEntry(k, const BigIntStringConverter().fromJson(e as String)), - ), - TrivialNumberConverter.instance.fromJson(json['numberSilly'] as int?), - (json['numberSillySet'] as List) - .map((e) => TrivialNumberConverter.instance.fromJson(e as int?)) - .toSet(), - const EpochDateTimeConverter().fromJson(json['dateTime'] as int?), - ); -} + Map json) => + JsonConverterTestClass( + durationConverter.fromJson(json['duration'] as int?), + (json['durationList'] as List) + .map((e) => durationConverter.fromJson(e as int?)) + .toList(), + const BigIntStringConverter().fromJson(json['bigInt'] as String), + (json['bigIntMap'] as Map).map( + (k, e) => + MapEntry(k, const BigIntStringConverter().fromJson(e as String)), + ), + TrivialNumberConverter.instance.fromJson(json['numberSilly'] as int?), + (json['numberSillySet'] as List) + .map((e) => TrivialNumberConverter.instance.fromJson(e as int?)) + .toSet(), + const EpochDateTimeConverter().fromJson(json['dateTime'] as int?), + ); Map _$JsonConverterTestClassToJson( JsonConverterTestClass instance) { @@ -170,18 +170,17 @@ Map _$JsonConverterTestClassToJson( } JsonConverterGeneric _$JsonConverterGenericFromJson( - Map json) { - return JsonConverterGeneric( - GenericConverter().fromJson(json['item'] as Map), - (json['itemList'] as List) - .map((e) => GenericConverter().fromJson(e as Map)) - .toList(), - (json['itemMap'] as Map).map( - (k, e) => MapEntry( - k, GenericConverter().fromJson(e as Map)), - ), - ); -} + Map json) => + JsonConverterGeneric( + GenericConverter().fromJson(json['item'] as Map), + (json['itemList'] as List) + .map((e) => GenericConverter().fromJson(e as Map)) + .toList(), + (json['itemMap'] as Map).map( + (k, e) => MapEntry( + k, GenericConverter().fromJson(e as Map)), + ), + ); Map _$JsonConverterGenericToJson( JsonConverterGeneric instance) { diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart index 24e14ac64..1a01f85d6 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart @@ -6,69 +6,70 @@ part of 'kitchen_sink.g_explicit_to_json.dart'; // JsonSerializableGenerator // ************************************************************************** -KitchenSink _$KitchenSinkFromJson(Map json) { - return KitchenSink( - ctorValidatedNo42: json['no-42'] as int?, - iterable: json['iterable'] as List?, - dynamicIterable: json['dynamicIterable'] as List?, - objectIterable: - (json['objectIterable'] as List?)?.map((e) => e as Object), - intIterable: (json['intIterable'] as List?)?.map((e) => e as int), - dateTimeIterable: (json['datetime-iterable'] as List?) - ?.map((e) => DateTime.parse(e as String)), - ) - ..dateTime = json['dateTime'] == null - ? null - : DateTime.parse(json['dateTime'] as String) - ..bigInt = - json['bigInt'] == null ? null : BigInt.parse(json['bigInt'] as String) - ..set = (json['set'] as List).toSet() - ..dynamicSet = (json['dynamicSet'] as List).toSet() - ..objectSet = - (json['objectSet'] as List).map((e) => e as Object).toSet() - ..intSet = (json['intSet'] as List).map((e) => e as int).toSet() - ..dateTimeSet = (json['dateTimeSet'] as List) - .map((e) => DateTime.parse(e as String)) - .toSet() - ..list = json['list'] as List - ..dynamicList = json['dynamicList'] as List - ..objectList = - (json['objectList'] as List).map((e) => e as Object).toList() - ..intList = (json['intList'] as List).map((e) => e as int).toList() - ..dateTimeList = (json['dateTimeList'] as List) - .map((e) => DateTime.parse(e as String)) - .toList() - ..map = json['map'] as Map - ..stringStringMap = Map.from(json['stringStringMap'] as Map) - ..dynamicIntMap = Map.from(json['dynamicIntMap'] as Map) - ..objectDateTimeMap = - (json['objectDateTimeMap'] as Map).map( - (k, e) => MapEntry(k, DateTime.parse(e as String)), +KitchenSink _$KitchenSinkFromJson(Map json) => KitchenSink( + ctorValidatedNo42: json['no-42'] as int?, + iterable: json['iterable'] as List?, + dynamicIterable: json['dynamicIterable'] as List?, + objectIterable: + (json['objectIterable'] as List?)?.map((e) => e as Object), + intIterable: + (json['intIterable'] as List?)?.map((e) => e as int), + dateTimeIterable: (json['datetime-iterable'] as List?) + ?.map((e) => DateTime.parse(e as String)), ) - ..crazyComplex = (json['crazyComplex'] as List) - .map((e) => (e as Map?)?.map( - (k, e) => MapEntry( - k, - (e as Map?)?.map( - (k, e) => MapEntry( - k, - (e as List?) - ?.map((e) => (e as List?) - ?.map((e) => DateTime.parse(e as String)) - .toList()) - .toList()), - )), - )) - .toList() - ..val = Map.from(json['val'] as Map) - ..writeNotNull = json['writeNotNull'] as bool? - ..string = json[r'$string'] as String? - ..simpleObject = - SimpleObject.fromJson(json['simpleObject'] as Map) - ..strictKeysObject = StrictKeysObject.fromJson( - json['strictKeysObject'] as Map) - ..validatedPropertyNo42 = json['validatedPropertyNo42'] as int?; -} + ..dateTime = json['dateTime'] == null + ? null + : DateTime.parse(json['dateTime'] as String) + ..bigInt = + json['bigInt'] == null ? null : BigInt.parse(json['bigInt'] as String) + ..set = (json['set'] as List).toSet() + ..dynamicSet = (json['dynamicSet'] as List).toSet() + ..objectSet = + (json['objectSet'] as List).map((e) => e as Object).toSet() + ..intSet = (json['intSet'] as List).map((e) => e as int).toSet() + ..dateTimeSet = (json['dateTimeSet'] as List) + .map((e) => DateTime.parse(e as String)) + .toSet() + ..list = json['list'] as List + ..dynamicList = json['dynamicList'] as List + ..objectList = + (json['objectList'] as List).map((e) => e as Object).toList() + ..intList = + (json['intList'] as List).map((e) => e as int).toList() + ..dateTimeList = (json['dateTimeList'] as List) + .map((e) => DateTime.parse(e as String)) + .toList() + ..map = json['map'] as Map + ..stringStringMap = + Map.from(json['stringStringMap'] as Map) + ..dynamicIntMap = Map.from(json['dynamicIntMap'] as Map) + ..objectDateTimeMap = + (json['objectDateTimeMap'] as Map).map( + (k, e) => MapEntry(k, DateTime.parse(e as String)), + ) + ..crazyComplex = (json['crazyComplex'] as List) + .map((e) => (e as Map?)?.map( + (k, e) => MapEntry( + k, + (e as Map?)?.map( + (k, e) => MapEntry( + k, + (e as List?) + ?.map((e) => (e as List?) + ?.map((e) => DateTime.parse(e as String)) + .toList()) + .toList()), + )), + )) + .toList() + ..val = Map.from(json['val'] as Map) + ..writeNotNull = json['writeNotNull'] as bool? + ..string = json[r'$string'] as String? + ..simpleObject = + SimpleObject.fromJson(json['simpleObject'] as Map) + ..strictKeysObject = StrictKeysObject.fromJson( + json['strictKeysObject'] as Map) + ..validatedPropertyNo42 = json['validatedPropertyNo42'] as int?; Map _$KitchenSinkToJson(KitchenSink instance) => { @@ -116,24 +117,23 @@ Map _$KitchenSinkToJson(KitchenSink instance) => }; JsonConverterTestClass _$JsonConverterTestClassFromJson( - Map json) { - return JsonConverterTestClass( - durationConverter.fromJson(json['duration'] as int?), - (json['durationList'] as List) - .map((e) => durationConverter.fromJson(e as int?)) - .toList(), - const BigIntStringConverter().fromJson(json['bigInt'] as String), - (json['bigIntMap'] as Map).map( - (k, e) => - MapEntry(k, const BigIntStringConverter().fromJson(e as String)), - ), - TrivialNumberConverter.instance.fromJson(json['numberSilly'] as int?), - (json['numberSillySet'] as List) - .map((e) => TrivialNumberConverter.instance.fromJson(e as int?)) - .toSet(), - const EpochDateTimeConverter().fromJson(json['dateTime'] as int?), - ); -} + Map json) => + JsonConverterTestClass( + durationConverter.fromJson(json['duration'] as int?), + (json['durationList'] as List) + .map((e) => durationConverter.fromJson(e as int?)) + .toList(), + const BigIntStringConverter().fromJson(json['bigInt'] as String), + (json['bigIntMap'] as Map).map( + (k, e) => + MapEntry(k, const BigIntStringConverter().fromJson(e as String)), + ), + TrivialNumberConverter.instance.fromJson(json['numberSilly'] as int?), + (json['numberSillySet'] as List) + .map((e) => TrivialNumberConverter.instance.fromJson(e as int?)) + .toSet(), + const EpochDateTimeConverter().fromJson(json['dateTime'] as int?), + ); Map _$JsonConverterTestClassToJson( JsonConverterTestClass instance) => @@ -153,18 +153,17 @@ Map _$JsonConverterTestClassToJson( }; JsonConverterGeneric _$JsonConverterGenericFromJson( - Map json) { - return JsonConverterGeneric( - GenericConverter().fromJson(json['item'] as Map), - (json['itemList'] as List) - .map((e) => GenericConverter().fromJson(e as Map)) - .toList(), - (json['itemMap'] as Map).map( - (k, e) => MapEntry( - k, GenericConverter().fromJson(e as Map)), - ), - ); -} + Map json) => + JsonConverterGeneric( + GenericConverter().fromJson(json['item'] as Map), + (json['itemList'] as List) + .map((e) => GenericConverter().fromJson(e as Map)) + .toList(), + (json['itemMap'] as Map).map( + (k, e) => MapEntry( + k, GenericConverter().fromJson(e as Map)), + ), + ); Map _$JsonConverterGenericToJson( JsonConverterGeneric instance) => diff --git a/json_serializable/test/kitchen_sink/simple_object.g.dart b/json_serializable/test/kitchen_sink/simple_object.g.dart index 42d584b69..0102f33ef 100644 --- a/json_serializable/test/kitchen_sink/simple_object.g.dart +++ b/json_serializable/test/kitchen_sink/simple_object.g.dart @@ -6,11 +6,9 @@ part of 'simple_object.dart'; // JsonSerializableGenerator // ************************************************************************** -SimpleObject _$SimpleObjectFromJson(Map json) { - return SimpleObject( - json['value'] as int, - ); -} +SimpleObject _$SimpleObjectFromJson(Map json) => SimpleObject( + json['value'] as int, + ); Map _$SimpleObjectToJson(SimpleObject instance) => { diff --git a/json_serializable/test/kitchen_sink/strict_keys_object.g.dart b/json_serializable/test/kitchen_sink/strict_keys_object.g.dart index dfdda8eaa..081dff4cf 100644 --- a/json_serializable/test/kitchen_sink/strict_keys_object.g.dart +++ b/json_serializable/test/kitchen_sink/strict_keys_object.g.dart @@ -7,9 +7,11 @@ part of 'strict_keys_object.dart'; // ************************************************************************** StrictKeysObject _$StrictKeysObjectFromJson(Map json) { - $checkKeys(json, - allowedKeys: const ['value', 'custom_field'], - requiredKeys: const ['value', 'custom_field']); + $checkKeys( + json, + allowedKeys: const ['value', 'custom_field'], + requiredKeys: const ['value', 'custom_field'], + ); return StrictKeysObject( json['value'] as int, json['custom_field'] as String, diff --git a/json_serializable/test/src/_json_serializable_test_input.dart b/json_serializable/test/src/_json_serializable_test_input.dart index de76cc1f9..f59968aec 100644 --- a/json_serializable/test/src/_json_serializable_test_input.dart +++ b/json_serializable/test/src/_json_serializable_test_input.dart @@ -9,10 +9,10 @@ import 'package:json_annotation/json_annotation.dart'; // ignore: import_of_legacy_library_into_null_safe import 'package:source_gen_test/annotations.dart'; -part 'constants_copy.dart'; - part 'checked_test_input.dart'; +part 'constants_copy.dart'; + part 'core_subclass_type_input.dart'; part 'default_value_input.dart'; @@ -43,9 +43,8 @@ Object annotatedMethod() => throw UnimplementedError(); @ShouldGenerate( r''' -OnlyStaticMembers _$OnlyStaticMembersFromJson(Map json) { - return OnlyStaticMembers(); -} +OnlyStaticMembers _$OnlyStaticMembersFromJson(Map json) => + OnlyStaticMembers(); Map _$OnlyStaticMembersToJson(OnlyStaticMembers instance) => {}; @@ -62,17 +61,16 @@ class OnlyStaticMembers { } @ShouldGenerate(r''' -GeneralTestClass1 _$GeneralTestClass1FromJson(Map json) { - return GeneralTestClass1() - ..firstName = json['firstName'] as String - ..lastName = json['lastName'] as String - ..height = json['h'] as int - ..dateOfBirth = DateTime.parse(json['dateOfBirth'] as String) - ..dynamicType = json['dynamicType'] - ..varType = json['varType'] - ..listOfInts = - (json['listOfInts'] as List).map((e) => e as int).toList(); -} +GeneralTestClass1 _$GeneralTestClass1FromJson(Map json) => + GeneralTestClass1() + ..firstName = json['firstName'] as String + ..lastName = json['lastName'] as String + ..height = json['h'] as int + ..dateOfBirth = DateTime.parse(json['dateOfBirth'] as String) + ..dynamicType = json['dynamicType'] + ..varType = json['varType'] + ..listOfInts = + (json['listOfInts'] as List).map((e) => e as int).toList(); Map _$GeneralTestClass1ToJson(GeneralTestClass1 instance) => { @@ -99,13 +97,12 @@ class GeneralTestClass1 { } @ShouldGenerate(r''' -GeneralTestClass2 _$GeneralTestClass2FromJson(Map json) { - return GeneralTestClass2( - json['height'] as int, - json['firstName'] as String, - json['lastName'] as String?, - )..dateOfBirth = DateTime.parse(json['dateOfBirth'] as String); -} +GeneralTestClass2 _$GeneralTestClass2FromJson(Map json) => + GeneralTestClass2( + json['height'] as int, + json['firstName'] as String, + json['lastName'] as String?, + )..dateOfBirth = DateTime.parse(json['dateOfBirth'] as String); Map _$GeneralTestClass2ToJson(GeneralTestClass2 instance) => { @@ -129,11 +126,9 @@ class GeneralTestClass2 { } @ShouldGenerate(r''' -FinalFields _$FinalFieldsFromJson(Map json) { - return FinalFields( - json['a'] as int, - ); -} +FinalFields _$FinalFieldsFromJson(Map json) => FinalFields( + json['a'] as int, + ); Map _$FinalFieldsToJson(FinalFields instance) => { @@ -152,9 +147,8 @@ class FinalFields { @ShouldGenerate( r''' FinalFieldsNotSetInCtor _$FinalFieldsNotSetInCtorFromJson( - Map json) { - return FinalFieldsNotSetInCtor(); -} + Map json) => + FinalFieldsNotSetInCtor(); Map _$FinalFieldsNotSetInCtorToJson( FinalFieldsNotSetInCtor instance) => @@ -170,11 +164,9 @@ class FinalFieldsNotSetInCtor { } @ShouldGenerate(r''' -SetSupport _$SetSupportFromJson(Map json) { - return SetSupport( - (json['values'] as List).map((e) => e as int).toSet(), - ); -} +SetSupport _$SetSupportFromJson(Map json) => SetSupport( + (json['values'] as List).map((e) => e as int).toSet(), + ); Map _$SetSupportToJson(SetSupport instance) => { @@ -398,14 +390,13 @@ enum GoodEnum { @ShouldGenerate(r''' FieldWithFromJsonCtorAndTypeParams _$FieldWithFromJsonCtorAndTypeParamsFromJson( - Map json) { - return FieldWithFromJsonCtorAndTypeParams() - ..customOrders = json['customOrders'] == null - ? null - : MyList.fromJson((json['customOrders'] as List) - .map((e) => GeneralTestClass2.fromJson(e as Map)) - .toList()); -} + Map json) => + FieldWithFromJsonCtorAndTypeParams() + ..customOrders = json['customOrders'] == null + ? null + : MyList.fromJson((json['customOrders'] as List) + .map((e) => GeneralTestClass2.fromJson(e as Map)) + .toList()); ''') @JsonSerializable(createToJson: false) class FieldWithFromJsonCtorAndTypeParams { @@ -442,11 +433,10 @@ mixin _PropInMixinI448RegressionMixin { @ShouldGenerate(r''' PropInMixinI448Regression _$PropInMixinI448RegressionFromJson( - Map json) { - return PropInMixinI448Regression() - ..nullable = json['nullable'] as int - ..notNullable = json['notNullable'] as int; -} + Map json) => + PropInMixinI448Regression() + ..nullable = json['nullable'] as int + ..notNullable = json['notNullable'] as int; Map _$PropInMixinI448RegressionToJson( PropInMixinI448Regression instance) => @@ -463,9 +453,8 @@ class PropInMixinI448Regression with _PropInMixinI448RegressionMixin { @ShouldGenerate( r''' -IgnoreUnannotated _$IgnoreUnannotatedFromJson(Map json) { - return IgnoreUnannotated()..annotated = json['annotated'] as int; -} +IgnoreUnannotated _$IgnoreUnannotatedFromJson(Map json) => + IgnoreUnannotated()..annotated = json['annotated'] as int; Map _$IgnoreUnannotatedToJson(IgnoreUnannotated instance) => { @@ -483,9 +472,8 @@ class IgnoreUnannotated { @ShouldGenerate( r''' -SubclassedJsonKey _$SubclassedJsonKeyFromJson(Map json) { - return SubclassedJsonKey()..annotatedWithSubclass = json['bob'] as int; -} +SubclassedJsonKey _$SubclassedJsonKeyFromJson(Map json) => + SubclassedJsonKey()..annotatedWithSubclass = json['bob'] as int; Map _$SubclassedJsonKeyToJson(SubclassedJsonKey instance) => { @@ -506,9 +494,8 @@ class MyJsonKey extends JsonKey { @ShouldGenerate( r''' OverrideGetterExampleI613 _$OverrideGetterExampleI613FromJson( - Map json) { - return OverrideGetterExampleI613()..id = json['id'] as String; -} + Map json) => + OverrideGetterExampleI613()..id = json['id'] as String; Map _$OverrideGetterExampleI613ToJson( OverrideGetterExampleI613 instance) => diff --git a/json_serializable/test/src/checked_test_input.dart b/json_serializable/test/src/checked_test_input.dart index c15e4a937..bfbc62457 100644 --- a/json_serializable/test/src/checked_test_input.dart +++ b/json_serializable/test/src/checked_test_input.dart @@ -2,19 +2,24 @@ part of '_json_serializable_test_input.dart'; @ShouldGenerate(r''' WithANonCtorGetterChecked _$WithANonCtorGetterCheckedFromJson( - Map json) { - return $checkedCreate('WithANonCtorGetterChecked', json, ($checkedConvert) { - $checkKeys(json, - allowedKeys: const ['items'], - requiredKeys: const ['items'], - disallowNullValues: const ['items']); - final val = WithANonCtorGetterChecked( - $checkedConvert('items', - (v) => (v as List).map((e) => e as String).toList()), + Map json) => + $checkedCreate( + 'WithANonCtorGetterChecked', + json, + ($checkedConvert) { + $checkKeys( + json, + allowedKeys: const ['items'], + requiredKeys: const ['items'], + disallowNullValues: const ['items'], + ); + final val = WithANonCtorGetterChecked( + $checkedConvert('items', + (v) => (v as List).map((e) => e as String).toList()), + ); + return val; + }, ); - return val; - }); -} ''') @JsonSerializable( disallowUnrecognizedKeys: true, @@ -32,10 +37,12 @@ class WithANonCtorGetterChecked { @ShouldGenerate(r''' WithANonCtorGetter _$WithANonCtorGetterFromJson(Map json) { - $checkKeys(json, - allowedKeys: const ['items'], - requiredKeys: const ['items'], - disallowNullValues: const ['items']); + $checkKeys( + json, + allowedKeys: const ['items'], + requiredKeys: const ['items'], + disallowNullValues: const ['items'], + ); return WithANonCtorGetter( (json['items'] as List).map((e) => e as String).toList(), ); diff --git a/json_serializable/test/src/default_value_input.dart b/json_serializable/test/src/default_value_input.dart index bc608a156..8e6a4e2df 100644 --- a/json_serializable/test/src/default_value_input.dart +++ b/json_serializable/test/src/default_value_input.dart @@ -76,12 +76,11 @@ class DefaultWithNestedEnum { @ShouldGenerate( r''' DefaultWithToJsonClass _$DefaultWithToJsonClassFromJson( - Map json) { - return DefaultWithToJsonClass() - ..fieldDefaultValueToJson = DefaultWithToJsonClass._fromJson( - json['fieldDefaultValueToJson'] as String) ?? - 7; -} + Map json) => + DefaultWithToJsonClass() + ..fieldDefaultValueToJson = DefaultWithToJsonClass._fromJson( + json['fieldDefaultValueToJson'] as String) ?? + 7; ''', expectedLogItems: [ ''' @@ -103,8 +102,11 @@ class DefaultWithToJsonClass { r''' DefaultWithDisallowNullRequiredClass _$DefaultWithDisallowNullRequiredClassFromJson(Map json) { - $checkKeys(json, - requiredKeys: const ['theField'], disallowNullValues: const ['theField']); + $checkKeys( + json, + requiredKeys: const ['theField'], + disallowNullValues: const ['theField'], + ); return DefaultWithDisallowNullRequiredClass() ..theField = json['theField'] as int? ?? 7; } @@ -126,11 +128,10 @@ class DefaultWithDisallowNullRequiredClass { r''' CtorDefaultValueAndJsonKeyDefaultValue _$CtorDefaultValueAndJsonKeyDefaultValueFromJson( - Map json) { - return CtorDefaultValueAndJsonKeyDefaultValue( - json['theField'] as int? ?? 7, - ); -} + Map json) => + CtorDefaultValueAndJsonKeyDefaultValue( + json['theField'] as int? ?? 7, + ); ''', expectedLogItems: [ 'The constructor parameter for `theField` has a default value `6`, but the ' @@ -148,19 +149,18 @@ class CtorDefaultValueAndJsonKeyDefaultValue { @ShouldGenerate(r''' DefaultDoubleConstants _$DefaultDoubleConstantsFromJson( - Map json) { - return DefaultDoubleConstants() - ..defaultNan = (json['defaultNan'] as num?)?.toDouble() ?? double.nan - ..defaultNegativeInfinity = - (json['defaultNegativeInfinity'] as num?)?.toDouble() ?? - double.negativeInfinity - ..defaultInfinity = - (json['defaultInfinity'] as num?)?.toDouble() ?? double.infinity - ..defaultMinPositive = - (json['defaultMinPositive'] as num?)?.toDouble() ?? 5e-324 - ..defaultMaxFinite = (json['defaultMaxFinite'] as num?)?.toDouble() ?? - 1.7976931348623157e+308; -} + Map json) => + DefaultDoubleConstants() + ..defaultNan = (json['defaultNan'] as num?)?.toDouble() ?? double.nan + ..defaultNegativeInfinity = + (json['defaultNegativeInfinity'] as num?)?.toDouble() ?? + double.negativeInfinity + ..defaultInfinity = + (json['defaultInfinity'] as num?)?.toDouble() ?? double.infinity + ..defaultMinPositive = + (json['defaultMinPositive'] as num?)?.toDouble() ?? 5e-324 + ..defaultMaxFinite = (json['defaultMaxFinite'] as num?)?.toDouble() ?? + 1.7976931348623157e+308; ''') @JsonSerializable(createToJson: false) class DefaultDoubleConstants { diff --git a/json_serializable/test/src/generic_test_input.dart b/json_serializable/test/src/generic_test_input.dart index 1a3b98466..8baaa433f 100644 --- a/json_serializable/test/src/generic_test_input.dart +++ b/json_serializable/test/src/generic_test_input.dart @@ -20,14 +20,13 @@ class Issue713 { @ShouldGenerate(r''' GenericClass _$GenericClassFromJson( - Map json) { - return GenericClass() - ..fieldObject = _dataFromJson(json['fieldObject']) - ..fieldDynamic = _dataFromJson(json['fieldDynamic']) - ..fieldInt = _dataFromJson(json['fieldInt']) - ..fieldT = _dataFromJson(json['fieldT']) - ..fieldS = _dataFromJson(json['fieldS']); -} + Map json) => + GenericClass() + ..fieldObject = _dataFromJson(json['fieldObject']) + ..fieldDynamic = _dataFromJson(json['fieldDynamic']) + ..fieldInt = _dataFromJson(json['fieldInt']) + ..fieldT = _dataFromJson(json['fieldT']) + ..fieldS = _dataFromJson(json['fieldS']); Map _$GenericClassToJson( GenericClass instance) => @@ -67,9 +66,8 @@ Object _dataToJson(T input) => throw UnimplementedError(); r''' GenericArgumentFactoriesFlagWithoutGenericType _$GenericArgumentFactoriesFlagWithoutGenericTypeFromJson( - Map json) { - return GenericArgumentFactoriesFlagWithoutGenericType(); -} + Map json) => + GenericArgumentFactoriesFlagWithoutGenericType(); Map _$GenericArgumentFactoriesFlagWithoutGenericTypeToJson( GenericArgumentFactoriesFlagWithoutGenericType instance) => diff --git a/json_serializable/test/src/inheritance_test_input.dart b/json_serializable/test/src/inheritance_test_input.dart index c853be117..b33aaa2c9 100644 --- a/json_serializable/test/src/inheritance_test_input.dart +++ b/json_serializable/test/src/inheritance_test_input.dart @@ -1,14 +1,12 @@ part of '_json_serializable_test_input.dart'; @ShouldGenerate(r''' -SubType _$SubTypeFromJson(Map json) { - return SubType( - json['subTypeViaCtor'] as int, - json['super-final-field'] as int, - ) - ..superReadWriteField = json['superReadWriteField'] as int? - ..subTypeReadWrite = json['subTypeReadWrite'] as int; -} +SubType _$SubTypeFromJson(Map json) => SubType( + json['subTypeViaCtor'] as int, + json['super-final-field'] as int, + ) + ..superReadWriteField = json['superReadWriteField'] as int? + ..subTypeReadWrite = json['subTypeReadWrite'] as int; Map _$SubTypeToJson(SubType instance) { final val = { diff --git a/json_serializable/test/src/json_converter_test_input.dart b/json_serializable/test/src/json_converter_test_input.dart index 9086bccff..10d029b41 100644 --- a/json_serializable/test/src/json_converter_test_input.dart +++ b/json_serializable/test/src/json_converter_test_input.dart @@ -6,15 +6,14 @@ part of '_json_serializable_test_input.dart'; @ShouldGenerate(r''' JsonConverterNamedCtor _$JsonConverterNamedCtorFromJson( - Map json) { - return JsonConverterNamedCtor() - ..value = const _DurationMillisecondConverter.named() - .fromJson(json['value'] as int) - ..genericValue = - _GenericConverter.named().fromJson(json['genericValue'] as int) - ..keyAnnotationFirst = - JsonConverterNamedCtor._fromJson(json['keyAnnotationFirst'] as int); -} + Map json) => + JsonConverterNamedCtor() + ..value = const _DurationMillisecondConverter.named() + .fromJson(json['value'] as int) + ..genericValue = + _GenericConverter.named().fromJson(json['genericValue'] as int) + ..keyAnnotationFirst = + JsonConverterNamedCtor._fromJson(json['keyAnnotationFirst'] as int); Map _$JsonConverterNamedCtorToJson( JsonConverterNamedCtor instance) => @@ -45,17 +44,16 @@ class JsonConverterNamedCtor { @ShouldGenerate(r''' JsonConvertOnField _$JsonConvertOnFieldFromJson( - Map json) { - return JsonConvertOnField() - ..annotatedField = const _DurationMillisecondConverter() - .fromJson(json['annotatedField'] as int) - ..annotatedWithNamedCtor = const _DurationMillisecondConverter.named() - .fromJson(json['annotatedWithNamedCtor'] as int) - ..classAnnotatedWithField = - _durationConverter.fromJson(json['classAnnotatedWithField'] as int) - ..genericValue = - _GenericConverter().fromJson(json['genericValue'] as int); -} + Map json) => + JsonConvertOnField() + ..annotatedField = const _DurationMillisecondConverter() + .fromJson(json['annotatedField'] as int) + ..annotatedWithNamedCtor = const _DurationMillisecondConverter.named() + .fromJson(json['annotatedWithNamedCtor'] as int) + ..classAnnotatedWithField = + _durationConverter.fromJson(json['classAnnotatedWithField'] as int) + ..genericValue = + _GenericConverter().fromJson(json['genericValue'] as int); Map _$JsonConvertOnFieldToJson( JsonConvertOnField instance) => diff --git a/json_serializable/test/src/map_key_variety_test_input.dart b/json_serializable/test/src/map_key_variety_test_input.dart index 68504cd76..861512f18 100644 --- a/json_serializable/test/src/map_key_variety_test_input.dart +++ b/json_serializable/test/src/map_key_variety_test_input.dart @@ -1,12 +1,11 @@ part of '_json_serializable_test_input.dart'; @ShouldGenerate(r''' -MapKeyVariety _$MapKeyVarietyFromJson(Map json) { - return MapKeyVariety() - ..intIntMap = (json['intIntMap'] as Map).map( - (k, e) => MapEntry(int.parse(k), e as int), - ); -} +MapKeyVariety _$MapKeyVarietyFromJson(Map json) => + MapKeyVariety() + ..intIntMap = (json['intIntMap'] as Map).map( + (k, e) => MapEntry(int.parse(k), e as int), + ); Map _$MapKeyVarietyToJson(MapKeyVariety instance) => { diff --git a/json_serializable/test/src/setter_test_input.dart b/json_serializable/test/src/setter_test_input.dart index b951dfeb5..6d7ea9138 100644 --- a/json_serializable/test/src/setter_test_input.dart +++ b/json_serializable/test/src/setter_test_input.dart @@ -2,9 +2,7 @@ part of '_json_serializable_test_input.dart'; @ShouldGenerate( r''' -JustSetter _$JustSetterFromJson(Map json) { - return JustSetter(); -} +JustSetter _$JustSetterFromJson(Map json) => JustSetter(); Map _$JustSetterToJson(JustSetter instance) => {}; @@ -19,9 +17,8 @@ class JustSetter { @ShouldGenerate( r''' -JustSetterNoToJson _$JustSetterNoToJsonFromJson(Map json) { - return JustSetterNoToJson(); -} +JustSetterNoToJson _$JustSetterNoToJsonFromJson(Map json) => + JustSetterNoToJson(); ''', expectedLogItems: ['Setters are ignored: JustSetterNoToJson.someSetter'], configurations: ['default'], diff --git a/json_serializable/test/src/to_from_json_test_input.dart b/json_serializable/test/src/to_from_json_test_input.dart index ef879fa28..211f2acdd 100644 --- a/json_serializable/test/src/to_from_json_test_input.dart +++ b/json_serializable/test/src/to_from_json_test_input.dart @@ -39,10 +39,9 @@ class InvalidFromFunc2Args { @ShouldGenerate( r''' ValidToFromFuncClassStatic _$ValidToFromFuncClassStaticFromJson( - Map json) { - return ValidToFromFuncClassStatic() - ..field = ValidToFromFuncClassStatic._staticFunc(json['field'] as String); -} + Map json) => + ValidToFromFuncClassStatic() + ..field = ValidToFromFuncClassStatic._staticFunc(json['field'] as String); Map _$ValidToFromFuncClassStaticToJson( ValidToFromFuncClassStatic instance) => @@ -149,12 +148,11 @@ String _fromDynamicIterable(Iterable input) => 'null'; @ShouldGenerate( r''' FromDynamicCollection _$FromDynamicCollectionFromJson( - Map json) { - return FromDynamicCollection() - ..mapField = _fromDynamicMap(json['mapField'] as Map) - ..listField = _fromDynamicList(json['listField'] as List) - ..iterableField = _fromDynamicIterable(json['iterableField'] as List); -} + Map json) => + FromDynamicCollection() + ..mapField = _fromDynamicMap(json['mapField'] as Map) + ..listField = _fromDynamicList(json['listField'] as List) + ..iterableField = _fromDynamicIterable(json['iterableField'] as List); ''', configurations: ['default'], ) @@ -177,13 +175,12 @@ String _fromNullableDynamicIterable(Iterable? input) => 'null'; @ShouldGenerate( r''' FromNullableDynamicCollection _$FromNullableDynamicCollectionFromJson( - Map json) { - return FromNullableDynamicCollection() - ..mapField = _fromNullableDynamicMap(json['mapField'] as Map?) - ..listField = _fromNullableDynamicList(json['listField'] as List?) - ..iterableField = - _fromNullableDynamicIterable(json['iterableField'] as List?); -} + Map json) => + FromNullableDynamicCollection() + ..mapField = _fromNullableDynamicMap(json['mapField'] as Map?) + ..listField = _fromNullableDynamicList(json['listField'] as List?) + ..iterableField = + _fromNullableDynamicIterable(json['iterableField'] as List?); ''', configurations: ['default'], ) @@ -265,11 +262,10 @@ class OkayOnlyOptionalPositional { @ShouldGenerate( r''' -_BetterPrivateNames _$BetterPrivateNamesFromJson(Map json) { - return _BetterPrivateNames( - name: json['name'] as String, - ); -} +_BetterPrivateNames _$BetterPrivateNamesFromJson(Map json) => + _BetterPrivateNames( + name: json['name'] as String, + ); Map _$BetterPrivateNamesToJson(_BetterPrivateNames instance) => { @@ -281,5 +277,6 @@ Map _$BetterPrivateNamesToJson(_BetterPrivateNames instance) => // ignore: unused_element class _BetterPrivateNames { final String name; + _BetterPrivateNames({required this.name}); } diff --git a/json_serializable/test/src/unknown_enum_value_test_input.dart b/json_serializable/test/src/unknown_enum_value_test_input.dart index ea238231d..f81d300ef 100644 --- a/json_serializable/test/src/unknown_enum_value_test_input.dart +++ b/json_serializable/test/src/unknown_enum_value_test_input.dart @@ -2,13 +2,12 @@ part of '_json_serializable_test_input.dart'; @ShouldGenerate( r''' -UnknownEnumValue _$UnknownEnumValueFromJson(Map json) { - return UnknownEnumValue() - ..value = _$enumDecodeNullable( - _$UnknownEnumValueItemsEnumMap, json['value'], - unknownValue: UnknownEnumValueItems.vUnknown) ?? - UnknownEnumValueItems.vNull; -} +UnknownEnumValue _$UnknownEnumValueFromJson(Map json) => + UnknownEnumValue() + ..value = _$enumDecodeNullable( + _$UnknownEnumValueItemsEnumMap, json['value'], + unknownValue: UnknownEnumValueItems.vUnknown) ?? + UnknownEnumValueItems.vNull; K _$enumDecode( Map enumValues, diff --git a/json_serializable/test/supported_types/input.g.dart b/json_serializable/test/supported_types/input.g.dart index 3effa4548..e4426eba6 100644 --- a/json_serializable/test/supported_types/input.g.dart +++ b/json_serializable/test/supported_types/input.g.dart @@ -6,12 +6,10 @@ part of 'input.dart'; // JsonSerializableGenerator // ************************************************************************** -SimpleClass _$SimpleClassFromJson(Map json) { - return SimpleClass( - json['value'], - json['withDefault'] ?? 42, - ); -} +SimpleClass _$SimpleClassFromJson(Map json) => SimpleClass( + json['value'], + json['withDefault'] ?? 42, + ); Map _$SimpleClassToJson(SimpleClass instance) => { diff --git a/json_serializable/test/supported_types/input.type_bigint.g.dart b/json_serializable/test/supported_types/input.type_bigint.g.dart index c22bc2d85..82233d66a 100644 --- a/json_serializable/test/supported_types/input.type_bigint.g.dart +++ b/json_serializable/test/supported_types/input.type_bigint.g.dart @@ -6,22 +6,19 @@ part of 'input.type_bigint.dart'; // JsonSerializableGenerator // ************************************************************************** -SimpleClass _$SimpleClassFromJson(Map json) { - return SimpleClass( - BigInt.parse(json['value'] as String), - ); -} +SimpleClass _$SimpleClassFromJson(Map json) => SimpleClass( + BigInt.parse(json['value'] as String), + ); Map _$SimpleClassToJson(SimpleClass instance) => { 'value': instance.value.toString(), }; -SimpleClassNullable _$SimpleClassNullableFromJson(Map json) { - return SimpleClassNullable( - json['value'] == null ? null : BigInt.parse(json['value'] as String), - ); -} +SimpleClassNullable _$SimpleClassNullableFromJson(Map json) => + SimpleClassNullable( + json['value'] == null ? null : BigInt.parse(json['value'] as String), + ); Map _$SimpleClassNullableToJson( SimpleClassNullable instance) => diff --git a/json_serializable/test/supported_types/input.type_bool.g.dart b/json_serializable/test/supported_types/input.type_bool.g.dart index 3a793eccc..99c54e525 100644 --- a/json_serializable/test/supported_types/input.type_bool.g.dart +++ b/json_serializable/test/supported_types/input.type_bool.g.dart @@ -6,12 +6,10 @@ part of 'input.type_bool.dart'; // JsonSerializableGenerator // ************************************************************************** -SimpleClass _$SimpleClassFromJson(Map json) { - return SimpleClass( - json['value'] as bool, - json['withDefault'] as bool? ?? true, - ); -} +SimpleClass _$SimpleClassFromJson(Map json) => SimpleClass( + json['value'] as bool, + json['withDefault'] as bool? ?? true, + ); Map _$SimpleClassToJson(SimpleClass instance) => { @@ -19,12 +17,11 @@ Map _$SimpleClassToJson(SimpleClass instance) => 'withDefault': instance.withDefault, }; -SimpleClassNullable _$SimpleClassNullableFromJson(Map json) { - return SimpleClassNullable( - json['value'] as bool?, - json['withDefault'] as bool? ?? true, - ); -} +SimpleClassNullable _$SimpleClassNullableFromJson(Map json) => + SimpleClassNullable( + json['value'] as bool?, + json['withDefault'] as bool? ?? true, + ); Map _$SimpleClassNullableToJson( SimpleClassNullable instance) => diff --git a/json_serializable/test/supported_types/input.type_datetime.g.dart b/json_serializable/test/supported_types/input.type_datetime.g.dart index 2f3d8bd9a..38ca772ab 100644 --- a/json_serializable/test/supported_types/input.type_datetime.g.dart +++ b/json_serializable/test/supported_types/input.type_datetime.g.dart @@ -6,22 +6,19 @@ part of 'input.type_datetime.dart'; // JsonSerializableGenerator // ************************************************************************** -SimpleClass _$SimpleClassFromJson(Map json) { - return SimpleClass( - DateTime.parse(json['value'] as String), - ); -} +SimpleClass _$SimpleClassFromJson(Map json) => SimpleClass( + DateTime.parse(json['value'] as String), + ); Map _$SimpleClassToJson(SimpleClass instance) => { 'value': instance.value.toIso8601String(), }; -SimpleClassNullable _$SimpleClassNullableFromJson(Map json) { - return SimpleClassNullable( - json['value'] == null ? null : DateTime.parse(json['value'] as String), - ); -} +SimpleClassNullable _$SimpleClassNullableFromJson(Map json) => + SimpleClassNullable( + json['value'] == null ? null : DateTime.parse(json['value'] as String), + ); Map _$SimpleClassNullableToJson( SimpleClassNullable instance) => diff --git a/json_serializable/test/supported_types/input.type_double.g.dart b/json_serializable/test/supported_types/input.type_double.g.dart index 1ff5d3cb2..bc7e07937 100644 --- a/json_serializable/test/supported_types/input.type_double.g.dart +++ b/json_serializable/test/supported_types/input.type_double.g.dart @@ -6,12 +6,10 @@ part of 'input.type_double.dart'; // JsonSerializableGenerator // ************************************************************************** -SimpleClass _$SimpleClassFromJson(Map json) { - return SimpleClass( - (json['value'] as num).toDouble(), - (json['withDefault'] as num?)?.toDouble() ?? 3.14, - ); -} +SimpleClass _$SimpleClassFromJson(Map json) => SimpleClass( + (json['value'] as num).toDouble(), + (json['withDefault'] as num?)?.toDouble() ?? 3.14, + ); Map _$SimpleClassToJson(SimpleClass instance) => { @@ -19,12 +17,11 @@ Map _$SimpleClassToJson(SimpleClass instance) => 'withDefault': instance.withDefault, }; -SimpleClassNullable _$SimpleClassNullableFromJson(Map json) { - return SimpleClassNullable( - (json['value'] as num?)?.toDouble(), - (json['withDefault'] as num?)?.toDouble() ?? 3.14, - ); -} +SimpleClassNullable _$SimpleClassNullableFromJson(Map json) => + SimpleClassNullable( + (json['value'] as num?)?.toDouble(), + (json['withDefault'] as num?)?.toDouble() ?? 3.14, + ); Map _$SimpleClassNullableToJson( SimpleClassNullable instance) => diff --git a/json_serializable/test/supported_types/input.type_duration.g.dart b/json_serializable/test/supported_types/input.type_duration.g.dart index d2a77f769..601925416 100644 --- a/json_serializable/test/supported_types/input.type_duration.g.dart +++ b/json_serializable/test/supported_types/input.type_duration.g.dart @@ -6,22 +6,21 @@ part of 'input.type_duration.dart'; // JsonSerializableGenerator // ************************************************************************** -SimpleClass _$SimpleClassFromJson(Map json) { - return SimpleClass( - Duration(microseconds: json['value'] as int), - ); -} +SimpleClass _$SimpleClassFromJson(Map json) => SimpleClass( + Duration(microseconds: json['value'] as int), + ); Map _$SimpleClassToJson(SimpleClass instance) => { 'value': instance.value.inMicroseconds, }; -SimpleClassNullable _$SimpleClassNullableFromJson(Map json) { - return SimpleClassNullable( - json['value'] == null ? null : Duration(microseconds: json['value'] as int), - ); -} +SimpleClassNullable _$SimpleClassNullableFromJson(Map json) => + SimpleClassNullable( + json['value'] == null + ? null + : Duration(microseconds: json['value'] as int), + ); Map _$SimpleClassNullableToJson( SimpleClassNullable instance) => diff --git a/json_serializable/test/supported_types/input.type_enumtype.g.dart b/json_serializable/test/supported_types/input.type_enumtype.g.dart index 7233add35..1b54f3fd8 100644 --- a/json_serializable/test/supported_types/input.type_enumtype.g.dart +++ b/json_serializable/test/supported_types/input.type_enumtype.g.dart @@ -6,13 +6,11 @@ part of 'input.type_enumtype.dart'; // JsonSerializableGenerator // ************************************************************************** -SimpleClass _$SimpleClassFromJson(Map json) { - return SimpleClass( - _$enumDecode(_$EnumTypeEnumMap, json['value']), - _$enumDecodeNullable(_$EnumTypeEnumMap, json['withDefault']) ?? - EnumType.alpha, - ); -} +SimpleClass _$SimpleClassFromJson(Map json) => SimpleClass( + _$enumDecode(_$EnumTypeEnumMap, json['value']), + _$enumDecodeNullable(_$EnumTypeEnumMap, json['withDefault']) ?? + EnumType.alpha, + ); Map _$SimpleClassToJson(SimpleClass instance) => { @@ -64,13 +62,12 @@ K? _$enumDecodeNullable( return _$enumDecode(enumValues, source, unknownValue: unknownValue); } -SimpleClassNullable _$SimpleClassNullableFromJson(Map json) { - return SimpleClassNullable( - _$enumDecodeNullable(_$EnumTypeEnumMap, json['value']), - _$enumDecodeNullable(_$EnumTypeEnumMap, json['withDefault']) ?? - EnumType.alpha, - ); -} +SimpleClassNullable _$SimpleClassNullableFromJson(Map json) => + SimpleClassNullable( + _$enumDecodeNullable(_$EnumTypeEnumMap, json['value']), + _$enumDecodeNullable(_$EnumTypeEnumMap, json['withDefault']) ?? + EnumType.alpha, + ); Map _$SimpleClassNullableToJson( SimpleClassNullable instance) => diff --git a/json_serializable/test/supported_types/input.type_int.g.dart b/json_serializable/test/supported_types/input.type_int.g.dart index c4695d106..1df77a934 100644 --- a/json_serializable/test/supported_types/input.type_int.g.dart +++ b/json_serializable/test/supported_types/input.type_int.g.dart @@ -6,12 +6,10 @@ part of 'input.type_int.dart'; // JsonSerializableGenerator // ************************************************************************** -SimpleClass _$SimpleClassFromJson(Map json) { - return SimpleClass( - json['value'] as int, - json['withDefault'] as int? ?? 42, - ); -} +SimpleClass _$SimpleClassFromJson(Map json) => SimpleClass( + json['value'] as int, + json['withDefault'] as int? ?? 42, + ); Map _$SimpleClassToJson(SimpleClass instance) => { @@ -19,12 +17,11 @@ Map _$SimpleClassToJson(SimpleClass instance) => 'withDefault': instance.withDefault, }; -SimpleClassNullable _$SimpleClassNullableFromJson(Map json) { - return SimpleClassNullable( - json['value'] as int?, - json['withDefault'] as int? ?? 42, - ); -} +SimpleClassNullable _$SimpleClassNullableFromJson(Map json) => + SimpleClassNullable( + json['value'] as int?, + json['withDefault'] as int? ?? 42, + ); Map _$SimpleClassNullableToJson( SimpleClassNullable instance) => diff --git a/json_serializable/test/supported_types/input.type_iterable.g.dart b/json_serializable/test/supported_types/input.type_iterable.g.dart index 97766b6b8..be6a7a250 100644 --- a/json_serializable/test/supported_types/input.type_iterable.g.dart +++ b/json_serializable/test/supported_types/input.type_iterable.g.dart @@ -6,12 +6,10 @@ part of 'input.type_iterable.dart'; // JsonSerializableGenerator // ************************************************************************** -SimpleClass _$SimpleClassFromJson(Map json) { - return SimpleClass( - json['value'] as List, - json['withDefault'] as List? ?? [42, true, false, null], - ); -} +SimpleClass _$SimpleClassFromJson(Map json) => SimpleClass( + json['value'] as List, + json['withDefault'] as List? ?? [42, true, false, null], + ); Map _$SimpleClassToJson(SimpleClass instance) => { @@ -19,12 +17,11 @@ Map _$SimpleClassToJson(SimpleClass instance) => 'withDefault': instance.withDefault.toList(), }; -SimpleClassNullable _$SimpleClassNullableFromJson(Map json) { - return SimpleClassNullable( - json['value'] as List?, - json['withDefault'] as List? ?? [42, true, false, null], - ); -} +SimpleClassNullable _$SimpleClassNullableFromJson(Map json) => + SimpleClassNullable( + json['value'] as List?, + json['withDefault'] as List? ?? [42, true, false, null], + ); Map _$SimpleClassNullableToJson( SimpleClassNullable instance) => @@ -33,11 +30,10 @@ Map _$SimpleClassNullableToJson( 'withDefault': instance.withDefault?.toList(), }; -SimpleClassOfBigInt _$SimpleClassOfBigIntFromJson(Map json) { - return SimpleClassOfBigInt( - (json['value'] as List).map((e) => BigInt.parse(e as String)), - ); -} +SimpleClassOfBigInt _$SimpleClassOfBigIntFromJson(Map json) => + SimpleClassOfBigInt( + (json['value'] as List).map((e) => BigInt.parse(e as String)), + ); Map _$SimpleClassOfBigIntToJson( SimpleClassOfBigInt instance) => @@ -46,11 +42,10 @@ Map _$SimpleClassOfBigIntToJson( }; SimpleClassNullableOfBigInt _$SimpleClassNullableOfBigIntFromJson( - Map json) { - return SimpleClassNullableOfBigInt( - (json['value'] as List?)?.map((e) => BigInt.parse(e as String)), - ); -} + Map json) => + SimpleClassNullableOfBigInt( + (json['value'] as List?)?.map((e) => BigInt.parse(e as String)), + ); Map _$SimpleClassNullableOfBigIntToJson( SimpleClassNullableOfBigInt instance) => @@ -59,12 +54,11 @@ Map _$SimpleClassNullableOfBigIntToJson( }; SimpleClassOfBigIntNullable _$SimpleClassOfBigIntNullableFromJson( - Map json) { - return SimpleClassOfBigIntNullable( - (json['value'] as List) - .map((e) => e == null ? null : BigInt.parse(e as String)), - ); -} + Map json) => + SimpleClassOfBigIntNullable( + (json['value'] as List) + .map((e) => e == null ? null : BigInt.parse(e as String)), + ); Map _$SimpleClassOfBigIntNullableToJson( SimpleClassOfBigIntNullable instance) => @@ -73,12 +67,11 @@ Map _$SimpleClassOfBigIntNullableToJson( }; SimpleClassNullableOfBigIntNullable - _$SimpleClassNullableOfBigIntNullableFromJson(Map json) { - return SimpleClassNullableOfBigIntNullable( - (json['value'] as List?) - ?.map((e) => e == null ? null : BigInt.parse(e as String)), - ); -} + _$SimpleClassNullableOfBigIntNullableFromJson(Map json) => + SimpleClassNullableOfBigIntNullable( + (json['value'] as List?) + ?.map((e) => e == null ? null : BigInt.parse(e as String)), + ); Map _$SimpleClassNullableOfBigIntNullableToJson( SimpleClassNullableOfBigIntNullable instance) => @@ -86,11 +79,10 @@ Map _$SimpleClassNullableOfBigIntNullableToJson( 'value': instance.value?.map((e) => e?.toString()).toList(), }; -SimpleClassOfBool _$SimpleClassOfBoolFromJson(Map json) { - return SimpleClassOfBool( - (json['value'] as List).map((e) => e as bool), - ); -} +SimpleClassOfBool _$SimpleClassOfBoolFromJson(Map json) => + SimpleClassOfBool( + (json['value'] as List).map((e) => e as bool), + ); Map _$SimpleClassOfBoolToJson(SimpleClassOfBool instance) => { @@ -98,11 +90,10 @@ Map _$SimpleClassOfBoolToJson(SimpleClassOfBool instance) => }; SimpleClassNullableOfBool _$SimpleClassNullableOfBoolFromJson( - Map json) { - return SimpleClassNullableOfBool( - (json['value'] as List?)?.map((e) => e as bool), - ); -} + Map json) => + SimpleClassNullableOfBool( + (json['value'] as List?)?.map((e) => e as bool), + ); Map _$SimpleClassNullableOfBoolToJson( SimpleClassNullableOfBool instance) => @@ -111,11 +102,10 @@ Map _$SimpleClassNullableOfBoolToJson( }; SimpleClassOfBoolNullable _$SimpleClassOfBoolNullableFromJson( - Map json) { - return SimpleClassOfBoolNullable( - (json['value'] as List).map((e) => e as bool?), - ); -} + Map json) => + SimpleClassOfBoolNullable( + (json['value'] as List).map((e) => e as bool?), + ); Map _$SimpleClassOfBoolNullableToJson( SimpleClassOfBoolNullable instance) => @@ -124,11 +114,10 @@ Map _$SimpleClassOfBoolNullableToJson( }; SimpleClassNullableOfBoolNullable _$SimpleClassNullableOfBoolNullableFromJson( - Map json) { - return SimpleClassNullableOfBoolNullable( - (json['value'] as List?)?.map((e) => e as bool?), - ); -} + Map json) => + SimpleClassNullableOfBoolNullable( + (json['value'] as List?)?.map((e) => e as bool?), + ); Map _$SimpleClassNullableOfBoolNullableToJson( SimpleClassNullableOfBoolNullable instance) => @@ -137,11 +126,10 @@ Map _$SimpleClassNullableOfBoolNullableToJson( }; SimpleClassOfDateTime _$SimpleClassOfDateTimeFromJson( - Map json) { - return SimpleClassOfDateTime( - (json['value'] as List).map((e) => DateTime.parse(e as String)), - ); -} + Map json) => + SimpleClassOfDateTime( + (json['value'] as List).map((e) => DateTime.parse(e as String)), + ); Map _$SimpleClassOfDateTimeToJson( SimpleClassOfDateTime instance) => @@ -150,11 +138,11 @@ Map _$SimpleClassOfDateTimeToJson( }; SimpleClassNullableOfDateTime _$SimpleClassNullableOfDateTimeFromJson( - Map json) { - return SimpleClassNullableOfDateTime( - (json['value'] as List?)?.map((e) => DateTime.parse(e as String)), - ); -} + Map json) => + SimpleClassNullableOfDateTime( + (json['value'] as List?) + ?.map((e) => DateTime.parse(e as String)), + ); Map _$SimpleClassNullableOfDateTimeToJson( SimpleClassNullableOfDateTime instance) => @@ -163,12 +151,11 @@ Map _$SimpleClassNullableOfDateTimeToJson( }; SimpleClassOfDateTimeNullable _$SimpleClassOfDateTimeNullableFromJson( - Map json) { - return SimpleClassOfDateTimeNullable( - (json['value'] as List) - .map((e) => e == null ? null : DateTime.parse(e as String)), - ); -} + Map json) => + SimpleClassOfDateTimeNullable( + (json['value'] as List) + .map((e) => e == null ? null : DateTime.parse(e as String)), + ); Map _$SimpleClassOfDateTimeNullableToJson( SimpleClassOfDateTimeNullable instance) => @@ -177,12 +164,12 @@ Map _$SimpleClassOfDateTimeNullableToJson( }; SimpleClassNullableOfDateTimeNullable - _$SimpleClassNullableOfDateTimeNullableFromJson(Map json) { - return SimpleClassNullableOfDateTimeNullable( - (json['value'] as List?) - ?.map((e) => e == null ? null : DateTime.parse(e as String)), - ); -} + _$SimpleClassNullableOfDateTimeNullableFromJson( + Map json) => + SimpleClassNullableOfDateTimeNullable( + (json['value'] as List?) + ?.map((e) => e == null ? null : DateTime.parse(e as String)), + ); Map _$SimpleClassNullableOfDateTimeNullableToJson( SimpleClassNullableOfDateTimeNullable instance) => @@ -190,11 +177,10 @@ Map _$SimpleClassNullableOfDateTimeNullableToJson( 'value': instance.value?.map((e) => e?.toIso8601String()).toList(), }; -SimpleClassOfDouble _$SimpleClassOfDoubleFromJson(Map json) { - return SimpleClassOfDouble( - (json['value'] as List).map((e) => (e as num).toDouble()), - ); -} +SimpleClassOfDouble _$SimpleClassOfDoubleFromJson(Map json) => + SimpleClassOfDouble( + (json['value'] as List).map((e) => (e as num).toDouble()), + ); Map _$SimpleClassOfDoubleToJson( SimpleClassOfDouble instance) => @@ -203,11 +189,10 @@ Map _$SimpleClassOfDoubleToJson( }; SimpleClassNullableOfDouble _$SimpleClassNullableOfDoubleFromJson( - Map json) { - return SimpleClassNullableOfDouble( - (json['value'] as List?)?.map((e) => (e as num).toDouble()), - ); -} + Map json) => + SimpleClassNullableOfDouble( + (json['value'] as List?)?.map((e) => (e as num).toDouble()), + ); Map _$SimpleClassNullableOfDoubleToJson( SimpleClassNullableOfDouble instance) => @@ -216,11 +201,10 @@ Map _$SimpleClassNullableOfDoubleToJson( }; SimpleClassOfDoubleNullable _$SimpleClassOfDoubleNullableFromJson( - Map json) { - return SimpleClassOfDoubleNullable( - (json['value'] as List).map((e) => (e as num?)?.toDouble()), - ); -} + Map json) => + SimpleClassOfDoubleNullable( + (json['value'] as List).map((e) => (e as num?)?.toDouble()), + ); Map _$SimpleClassOfDoubleNullableToJson( SimpleClassOfDoubleNullable instance) => @@ -229,11 +213,11 @@ Map _$SimpleClassOfDoubleNullableToJson( }; SimpleClassNullableOfDoubleNullable - _$SimpleClassNullableOfDoubleNullableFromJson(Map json) { - return SimpleClassNullableOfDoubleNullable( - (json['value'] as List?)?.map((e) => (e as num?)?.toDouble()), - ); -} + _$SimpleClassNullableOfDoubleNullableFromJson(Map json) => + SimpleClassNullableOfDoubleNullable( + (json['value'] as List?) + ?.map((e) => (e as num?)?.toDouble()), + ); Map _$SimpleClassNullableOfDoubleNullableToJson( SimpleClassNullableOfDoubleNullable instance) => @@ -242,12 +226,11 @@ Map _$SimpleClassNullableOfDoubleNullableToJson( }; SimpleClassOfDuration _$SimpleClassOfDurationFromJson( - Map json) { - return SimpleClassOfDuration( - (json['value'] as List) - .map((e) => Duration(microseconds: e as int)), - ); -} + Map json) => + SimpleClassOfDuration( + (json['value'] as List) + .map((e) => Duration(microseconds: e as int)), + ); Map _$SimpleClassOfDurationToJson( SimpleClassOfDuration instance) => @@ -256,12 +239,11 @@ Map _$SimpleClassOfDurationToJson( }; SimpleClassNullableOfDuration _$SimpleClassNullableOfDurationFromJson( - Map json) { - return SimpleClassNullableOfDuration( - (json['value'] as List?) - ?.map((e) => Duration(microseconds: e as int)), - ); -} + Map json) => + SimpleClassNullableOfDuration( + (json['value'] as List?) + ?.map((e) => Duration(microseconds: e as int)), + ); Map _$SimpleClassNullableOfDurationToJson( SimpleClassNullableOfDuration instance) => @@ -270,12 +252,11 @@ Map _$SimpleClassNullableOfDurationToJson( }; SimpleClassOfDurationNullable _$SimpleClassOfDurationNullableFromJson( - Map json) { - return SimpleClassOfDurationNullable( - (json['value'] as List) - .map((e) => e == null ? null : Duration(microseconds: e as int)), - ); -} + Map json) => + SimpleClassOfDurationNullable( + (json['value'] as List) + .map((e) => e == null ? null : Duration(microseconds: e as int)), + ); Map _$SimpleClassOfDurationNullableToJson( SimpleClassOfDurationNullable instance) => @@ -284,12 +265,12 @@ Map _$SimpleClassOfDurationNullableToJson( }; SimpleClassNullableOfDurationNullable - _$SimpleClassNullableOfDurationNullableFromJson(Map json) { - return SimpleClassNullableOfDurationNullable( - (json['value'] as List?) - ?.map((e) => e == null ? null : Duration(microseconds: e as int)), - ); -} + _$SimpleClassNullableOfDurationNullableFromJson( + Map json) => + SimpleClassNullableOfDurationNullable( + (json['value'] as List?) + ?.map((e) => e == null ? null : Duration(microseconds: e as int)), + ); Map _$SimpleClassNullableOfDurationNullableToJson( SimpleClassNullableOfDurationNullable instance) => @@ -297,11 +278,11 @@ Map _$SimpleClassNullableOfDurationNullableToJson( 'value': instance.value?.map((e) => e?.inMicroseconds).toList(), }; -SimpleClassOfDynamic _$SimpleClassOfDynamicFromJson(Map json) { - return SimpleClassOfDynamic( - json['value'] as List, - ); -} +SimpleClassOfDynamic _$SimpleClassOfDynamicFromJson( + Map json) => + SimpleClassOfDynamic( + json['value'] as List, + ); Map _$SimpleClassOfDynamicToJson( SimpleClassOfDynamic instance) => @@ -310,11 +291,10 @@ Map _$SimpleClassOfDynamicToJson( }; SimpleClassNullableOfDynamic _$SimpleClassNullableOfDynamicFromJson( - Map json) { - return SimpleClassNullableOfDynamic( - json['value'] as List?, - ); -} + Map json) => + SimpleClassNullableOfDynamic( + json['value'] as List?, + ); Map _$SimpleClassNullableOfDynamicToJson( SimpleClassNullableOfDynamic instance) => @@ -323,12 +303,11 @@ Map _$SimpleClassNullableOfDynamicToJson( }; SimpleClassOfEnumType _$SimpleClassOfEnumTypeFromJson( - Map json) { - return SimpleClassOfEnumType( - (json['value'] as List) - .map((e) => _$enumDecode(_$EnumTypeEnumMap, e)), - ); -} + Map json) => + SimpleClassOfEnumType( + (json['value'] as List) + .map((e) => _$enumDecode(_$EnumTypeEnumMap, e)), + ); Map _$SimpleClassOfEnumTypeToJson( SimpleClassOfEnumType instance) => @@ -370,12 +349,11 @@ const _$EnumTypeEnumMap = { }; SimpleClassNullableOfEnumType _$SimpleClassNullableOfEnumTypeFromJson( - Map json) { - return SimpleClassNullableOfEnumType( - (json['value'] as List?) - ?.map((e) => _$enumDecode(_$EnumTypeEnumMap, e)), - ); -} + Map json) => + SimpleClassNullableOfEnumType( + (json['value'] as List?) + ?.map((e) => _$enumDecode(_$EnumTypeEnumMap, e)), + ); Map _$SimpleClassNullableOfEnumTypeToJson( SimpleClassNullableOfEnumType instance) => @@ -384,12 +362,11 @@ Map _$SimpleClassNullableOfEnumTypeToJson( }; SimpleClassOfEnumTypeNullable _$SimpleClassOfEnumTypeNullableFromJson( - Map json) { - return SimpleClassOfEnumTypeNullable( - (json['value'] as List) - .map((e) => _$enumDecodeNullable(_$EnumTypeEnumMap, e)), - ); -} + Map json) => + SimpleClassOfEnumTypeNullable( + (json['value'] as List) + .map((e) => _$enumDecodeNullable(_$EnumTypeEnumMap, e)), + ); Map _$SimpleClassOfEnumTypeNullableToJson( SimpleClassOfEnumTypeNullable instance) => @@ -409,12 +386,12 @@ K? _$enumDecodeNullable( } SimpleClassNullableOfEnumTypeNullable - _$SimpleClassNullableOfEnumTypeNullableFromJson(Map json) { - return SimpleClassNullableOfEnumTypeNullable( - (json['value'] as List?) - ?.map((e) => _$enumDecodeNullable(_$EnumTypeEnumMap, e)), - ); -} + _$SimpleClassNullableOfEnumTypeNullableFromJson( + Map json) => + SimpleClassNullableOfEnumTypeNullable( + (json['value'] as List?) + ?.map((e) => _$enumDecodeNullable(_$EnumTypeEnumMap, e)), + ); Map _$SimpleClassNullableOfEnumTypeNullableToJson( SimpleClassNullableOfEnumTypeNullable instance) => @@ -422,11 +399,10 @@ Map _$SimpleClassNullableOfEnumTypeNullableToJson( 'value': instance.value?.map((e) => _$EnumTypeEnumMap[e]).toList(), }; -SimpleClassOfInt _$SimpleClassOfIntFromJson(Map json) { - return SimpleClassOfInt( - (json['value'] as List).map((e) => e as int), - ); -} +SimpleClassOfInt _$SimpleClassOfIntFromJson(Map json) => + SimpleClassOfInt( + (json['value'] as List).map((e) => e as int), + ); Map _$SimpleClassOfIntToJson(SimpleClassOfInt instance) => { @@ -434,11 +410,10 @@ Map _$SimpleClassOfIntToJson(SimpleClassOfInt instance) => }; SimpleClassNullableOfInt _$SimpleClassNullableOfIntFromJson( - Map json) { - return SimpleClassNullableOfInt( - (json['value'] as List?)?.map((e) => e as int), - ); -} + Map json) => + SimpleClassNullableOfInt( + (json['value'] as List?)?.map((e) => e as int), + ); Map _$SimpleClassNullableOfIntToJson( SimpleClassNullableOfInt instance) => @@ -447,11 +422,10 @@ Map _$SimpleClassNullableOfIntToJson( }; SimpleClassOfIntNullable _$SimpleClassOfIntNullableFromJson( - Map json) { - return SimpleClassOfIntNullable( - (json['value'] as List).map((e) => e as int?), - ); -} + Map json) => + SimpleClassOfIntNullable( + (json['value'] as List).map((e) => e as int?), + ); Map _$SimpleClassOfIntNullableToJson( SimpleClassOfIntNullable instance) => @@ -460,11 +434,10 @@ Map _$SimpleClassOfIntNullableToJson( }; SimpleClassNullableOfIntNullable _$SimpleClassNullableOfIntNullableFromJson( - Map json) { - return SimpleClassNullableOfIntNullable( - (json['value'] as List?)?.map((e) => e as int?), - ); -} + Map json) => + SimpleClassNullableOfIntNullable( + (json['value'] as List?)?.map((e) => e as int?), + ); Map _$SimpleClassNullableOfIntNullableToJson( SimpleClassNullableOfIntNullable instance) => @@ -472,11 +445,10 @@ Map _$SimpleClassNullableOfIntNullableToJson( 'value': instance.value?.toList(), }; -SimpleClassOfNum _$SimpleClassOfNumFromJson(Map json) { - return SimpleClassOfNum( - (json['value'] as List).map((e) => e as num), - ); -} +SimpleClassOfNum _$SimpleClassOfNumFromJson(Map json) => + SimpleClassOfNum( + (json['value'] as List).map((e) => e as num), + ); Map _$SimpleClassOfNumToJson(SimpleClassOfNum instance) => { @@ -484,11 +456,10 @@ Map _$SimpleClassOfNumToJson(SimpleClassOfNum instance) => }; SimpleClassNullableOfNum _$SimpleClassNullableOfNumFromJson( - Map json) { - return SimpleClassNullableOfNum( - (json['value'] as List?)?.map((e) => e as num), - ); -} + Map json) => + SimpleClassNullableOfNum( + (json['value'] as List?)?.map((e) => e as num), + ); Map _$SimpleClassNullableOfNumToJson( SimpleClassNullableOfNum instance) => @@ -497,11 +468,10 @@ Map _$SimpleClassNullableOfNumToJson( }; SimpleClassOfNumNullable _$SimpleClassOfNumNullableFromJson( - Map json) { - return SimpleClassOfNumNullable( - (json['value'] as List).map((e) => e as num?), - ); -} + Map json) => + SimpleClassOfNumNullable( + (json['value'] as List).map((e) => e as num?), + ); Map _$SimpleClassOfNumNullableToJson( SimpleClassOfNumNullable instance) => @@ -510,11 +480,10 @@ Map _$SimpleClassOfNumNullableToJson( }; SimpleClassNullableOfNumNullable _$SimpleClassNullableOfNumNullableFromJson( - Map json) { - return SimpleClassNullableOfNumNullable( - (json['value'] as List?)?.map((e) => e as num?), - ); -} + Map json) => + SimpleClassNullableOfNumNullable( + (json['value'] as List?)?.map((e) => e as num?), + ); Map _$SimpleClassNullableOfNumNullableToJson( SimpleClassNullableOfNumNullable instance) => @@ -522,11 +491,10 @@ Map _$SimpleClassNullableOfNumNullableToJson( 'value': instance.value?.toList(), }; -SimpleClassOfObject _$SimpleClassOfObjectFromJson(Map json) { - return SimpleClassOfObject( - (json['value'] as List).map((e) => e as Object), - ); -} +SimpleClassOfObject _$SimpleClassOfObjectFromJson(Map json) => + SimpleClassOfObject( + (json['value'] as List).map((e) => e as Object), + ); Map _$SimpleClassOfObjectToJson( SimpleClassOfObject instance) => @@ -535,11 +503,10 @@ Map _$SimpleClassOfObjectToJson( }; SimpleClassNullableOfObject _$SimpleClassNullableOfObjectFromJson( - Map json) { - return SimpleClassNullableOfObject( - (json['value'] as List?)?.map((e) => e as Object), - ); -} + Map json) => + SimpleClassNullableOfObject( + (json['value'] as List?)?.map((e) => e as Object), + ); Map _$SimpleClassNullableOfObjectToJson( SimpleClassNullableOfObject instance) => @@ -548,11 +515,10 @@ Map _$SimpleClassNullableOfObjectToJson( }; SimpleClassOfObjectNullable _$SimpleClassOfObjectNullableFromJson( - Map json) { - return SimpleClassOfObjectNullable( - json['value'] as List, - ); -} + Map json) => + SimpleClassOfObjectNullable( + json['value'] as List, + ); Map _$SimpleClassOfObjectNullableToJson( SimpleClassOfObjectNullable instance) => @@ -561,11 +527,10 @@ Map _$SimpleClassOfObjectNullableToJson( }; SimpleClassNullableOfObjectNullable - _$SimpleClassNullableOfObjectNullableFromJson(Map json) { - return SimpleClassNullableOfObjectNullable( - json['value'] as List?, - ); -} + _$SimpleClassNullableOfObjectNullableFromJson(Map json) => + SimpleClassNullableOfObjectNullable( + json['value'] as List?, + ); Map _$SimpleClassNullableOfObjectNullableToJson( SimpleClassNullableOfObjectNullable instance) => @@ -573,11 +538,10 @@ Map _$SimpleClassNullableOfObjectNullableToJson( 'value': instance.value?.toList(), }; -SimpleClassOfString _$SimpleClassOfStringFromJson(Map json) { - return SimpleClassOfString( - (json['value'] as List).map((e) => e as String), - ); -} +SimpleClassOfString _$SimpleClassOfStringFromJson(Map json) => + SimpleClassOfString( + (json['value'] as List).map((e) => e as String), + ); Map _$SimpleClassOfStringToJson( SimpleClassOfString instance) => @@ -586,11 +550,10 @@ Map _$SimpleClassOfStringToJson( }; SimpleClassNullableOfString _$SimpleClassNullableOfStringFromJson( - Map json) { - return SimpleClassNullableOfString( - (json['value'] as List?)?.map((e) => e as String), - ); -} + Map json) => + SimpleClassNullableOfString( + (json['value'] as List?)?.map((e) => e as String), + ); Map _$SimpleClassNullableOfStringToJson( SimpleClassNullableOfString instance) => @@ -599,11 +562,10 @@ Map _$SimpleClassNullableOfStringToJson( }; SimpleClassOfStringNullable _$SimpleClassOfStringNullableFromJson( - Map json) { - return SimpleClassOfStringNullable( - (json['value'] as List).map((e) => e as String?), - ); -} + Map json) => + SimpleClassOfStringNullable( + (json['value'] as List).map((e) => e as String?), + ); Map _$SimpleClassOfStringNullableToJson( SimpleClassOfStringNullable instance) => @@ -612,11 +574,10 @@ Map _$SimpleClassOfStringNullableToJson( }; SimpleClassNullableOfStringNullable - _$SimpleClassNullableOfStringNullableFromJson(Map json) { - return SimpleClassNullableOfStringNullable( - (json['value'] as List?)?.map((e) => e as String?), - ); -} + _$SimpleClassNullableOfStringNullableFromJson(Map json) => + SimpleClassNullableOfStringNullable( + (json['value'] as List?)?.map((e) => e as String?), + ); Map _$SimpleClassNullableOfStringNullableToJson( SimpleClassNullableOfStringNullable instance) => @@ -624,11 +585,10 @@ Map _$SimpleClassNullableOfStringNullableToJson( 'value': instance.value?.toList(), }; -SimpleClassOfUri _$SimpleClassOfUriFromJson(Map json) { - return SimpleClassOfUri( - (json['value'] as List).map((e) => Uri.parse(e as String)), - ); -} +SimpleClassOfUri _$SimpleClassOfUriFromJson(Map json) => + SimpleClassOfUri( + (json['value'] as List).map((e) => Uri.parse(e as String)), + ); Map _$SimpleClassOfUriToJson(SimpleClassOfUri instance) => { @@ -636,11 +596,10 @@ Map _$SimpleClassOfUriToJson(SimpleClassOfUri instance) => }; SimpleClassNullableOfUri _$SimpleClassNullableOfUriFromJson( - Map json) { - return SimpleClassNullableOfUri( - (json['value'] as List?)?.map((e) => Uri.parse(e as String)), - ); -} + Map json) => + SimpleClassNullableOfUri( + (json['value'] as List?)?.map((e) => Uri.parse(e as String)), + ); Map _$SimpleClassNullableOfUriToJson( SimpleClassNullableOfUri instance) => @@ -649,12 +608,11 @@ Map _$SimpleClassNullableOfUriToJson( }; SimpleClassOfUriNullable _$SimpleClassOfUriNullableFromJson( - Map json) { - return SimpleClassOfUriNullable( - (json['value'] as List) - .map((e) => e == null ? null : Uri.parse(e as String)), - ); -} + Map json) => + SimpleClassOfUriNullable( + (json['value'] as List) + .map((e) => e == null ? null : Uri.parse(e as String)), + ); Map _$SimpleClassOfUriNullableToJson( SimpleClassOfUriNullable instance) => @@ -663,12 +621,11 @@ Map _$SimpleClassOfUriNullableToJson( }; SimpleClassNullableOfUriNullable _$SimpleClassNullableOfUriNullableFromJson( - Map json) { - return SimpleClassNullableOfUriNullable( - (json['value'] as List?) - ?.map((e) => e == null ? null : Uri.parse(e as String)), - ); -} + Map json) => + SimpleClassNullableOfUriNullable( + (json['value'] as List?) + ?.map((e) => e == null ? null : Uri.parse(e as String)), + ); Map _$SimpleClassNullableOfUriNullableToJson( SimpleClassNullableOfUriNullable instance) => diff --git a/json_serializable/test/supported_types/input.type_list.g.dart b/json_serializable/test/supported_types/input.type_list.g.dart index bd7eeb756..a52bc9cbf 100644 --- a/json_serializable/test/supported_types/input.type_list.g.dart +++ b/json_serializable/test/supported_types/input.type_list.g.dart @@ -6,12 +6,10 @@ part of 'input.type_list.dart'; // JsonSerializableGenerator // ************************************************************************** -SimpleClass _$SimpleClassFromJson(Map json) { - return SimpleClass( - json['value'] as List, - json['withDefault'] as List? ?? [42, true, false, null], - ); -} +SimpleClass _$SimpleClassFromJson(Map json) => SimpleClass( + json['value'] as List, + json['withDefault'] as List? ?? [42, true, false, null], + ); Map _$SimpleClassToJson(SimpleClass instance) => { @@ -19,12 +17,11 @@ Map _$SimpleClassToJson(SimpleClass instance) => 'withDefault': instance.withDefault, }; -SimpleClassNullable _$SimpleClassNullableFromJson(Map json) { - return SimpleClassNullable( - json['value'] as List?, - json['withDefault'] as List? ?? [42, true, false, null], - ); -} +SimpleClassNullable _$SimpleClassNullableFromJson(Map json) => + SimpleClassNullable( + json['value'] as List?, + json['withDefault'] as List? ?? [42, true, false, null], + ); Map _$SimpleClassNullableToJson( SimpleClassNullable instance) => @@ -33,13 +30,12 @@ Map _$SimpleClassNullableToJson( 'withDefault': instance.withDefault, }; -SimpleClassOfBigInt _$SimpleClassOfBigIntFromJson(Map json) { - return SimpleClassOfBigInt( - (json['value'] as List) - .map((e) => BigInt.parse(e as String)) - .toList(), - ); -} +SimpleClassOfBigInt _$SimpleClassOfBigIntFromJson(Map json) => + SimpleClassOfBigInt( + (json['value'] as List) + .map((e) => BigInt.parse(e as String)) + .toList(), + ); Map _$SimpleClassOfBigIntToJson( SimpleClassOfBigInt instance) => @@ -48,13 +44,12 @@ Map _$SimpleClassOfBigIntToJson( }; SimpleClassNullableOfBigInt _$SimpleClassNullableOfBigIntFromJson( - Map json) { - return SimpleClassNullableOfBigInt( - (json['value'] as List?) - ?.map((e) => BigInt.parse(e as String)) - .toList(), - ); -} + Map json) => + SimpleClassNullableOfBigInt( + (json['value'] as List?) + ?.map((e) => BigInt.parse(e as String)) + .toList(), + ); Map _$SimpleClassNullableOfBigIntToJson( SimpleClassNullableOfBigInt instance) => @@ -63,13 +58,12 @@ Map _$SimpleClassNullableOfBigIntToJson( }; SimpleClassOfBigIntNullable _$SimpleClassOfBigIntNullableFromJson( - Map json) { - return SimpleClassOfBigIntNullable( - (json['value'] as List) - .map((e) => e == null ? null : BigInt.parse(e as String)) - .toList(), - ); -} + Map json) => + SimpleClassOfBigIntNullable( + (json['value'] as List) + .map((e) => e == null ? null : BigInt.parse(e as String)) + .toList(), + ); Map _$SimpleClassOfBigIntNullableToJson( SimpleClassOfBigIntNullable instance) => @@ -78,13 +72,12 @@ Map _$SimpleClassOfBigIntNullableToJson( }; SimpleClassNullableOfBigIntNullable - _$SimpleClassNullableOfBigIntNullableFromJson(Map json) { - return SimpleClassNullableOfBigIntNullable( - (json['value'] as List?) - ?.map((e) => e == null ? null : BigInt.parse(e as String)) - .toList(), - ); -} + _$SimpleClassNullableOfBigIntNullableFromJson(Map json) => + SimpleClassNullableOfBigIntNullable( + (json['value'] as List?) + ?.map((e) => e == null ? null : BigInt.parse(e as String)) + .toList(), + ); Map _$SimpleClassNullableOfBigIntNullableToJson( SimpleClassNullableOfBigIntNullable instance) => @@ -92,11 +85,10 @@ Map _$SimpleClassNullableOfBigIntNullableToJson( 'value': instance.value?.map((e) => e?.toString()).toList(), }; -SimpleClassOfBool _$SimpleClassOfBoolFromJson(Map json) { - return SimpleClassOfBool( - (json['value'] as List).map((e) => e as bool).toList(), - ); -} +SimpleClassOfBool _$SimpleClassOfBoolFromJson(Map json) => + SimpleClassOfBool( + (json['value'] as List).map((e) => e as bool).toList(), + ); Map _$SimpleClassOfBoolToJson(SimpleClassOfBool instance) => { @@ -104,11 +96,10 @@ Map _$SimpleClassOfBoolToJson(SimpleClassOfBool instance) => }; SimpleClassNullableOfBool _$SimpleClassNullableOfBoolFromJson( - Map json) { - return SimpleClassNullableOfBool( - (json['value'] as List?)?.map((e) => e as bool).toList(), - ); -} + Map json) => + SimpleClassNullableOfBool( + (json['value'] as List?)?.map((e) => e as bool).toList(), + ); Map _$SimpleClassNullableOfBoolToJson( SimpleClassNullableOfBool instance) => @@ -117,11 +108,10 @@ Map _$SimpleClassNullableOfBoolToJson( }; SimpleClassOfBoolNullable _$SimpleClassOfBoolNullableFromJson( - Map json) { - return SimpleClassOfBoolNullable( - (json['value'] as List).map((e) => e as bool?).toList(), - ); -} + Map json) => + SimpleClassOfBoolNullable( + (json['value'] as List).map((e) => e as bool?).toList(), + ); Map _$SimpleClassOfBoolNullableToJson( SimpleClassOfBoolNullable instance) => @@ -130,11 +120,10 @@ Map _$SimpleClassOfBoolNullableToJson( }; SimpleClassNullableOfBoolNullable _$SimpleClassNullableOfBoolNullableFromJson( - Map json) { - return SimpleClassNullableOfBoolNullable( - (json['value'] as List?)?.map((e) => e as bool?).toList(), - ); -} + Map json) => + SimpleClassNullableOfBoolNullable( + (json['value'] as List?)?.map((e) => e as bool?).toList(), + ); Map _$SimpleClassNullableOfBoolNullableToJson( SimpleClassNullableOfBoolNullable instance) => @@ -143,13 +132,12 @@ Map _$SimpleClassNullableOfBoolNullableToJson( }; SimpleClassOfDateTime _$SimpleClassOfDateTimeFromJson( - Map json) { - return SimpleClassOfDateTime( - (json['value'] as List) - .map((e) => DateTime.parse(e as String)) - .toList(), - ); -} + Map json) => + SimpleClassOfDateTime( + (json['value'] as List) + .map((e) => DateTime.parse(e as String)) + .toList(), + ); Map _$SimpleClassOfDateTimeToJson( SimpleClassOfDateTime instance) => @@ -158,13 +146,12 @@ Map _$SimpleClassOfDateTimeToJson( }; SimpleClassNullableOfDateTime _$SimpleClassNullableOfDateTimeFromJson( - Map json) { - return SimpleClassNullableOfDateTime( - (json['value'] as List?) - ?.map((e) => DateTime.parse(e as String)) - .toList(), - ); -} + Map json) => + SimpleClassNullableOfDateTime( + (json['value'] as List?) + ?.map((e) => DateTime.parse(e as String)) + .toList(), + ); Map _$SimpleClassNullableOfDateTimeToJson( SimpleClassNullableOfDateTime instance) => @@ -173,13 +160,12 @@ Map _$SimpleClassNullableOfDateTimeToJson( }; SimpleClassOfDateTimeNullable _$SimpleClassOfDateTimeNullableFromJson( - Map json) { - return SimpleClassOfDateTimeNullable( - (json['value'] as List) - .map((e) => e == null ? null : DateTime.parse(e as String)) - .toList(), - ); -} + Map json) => + SimpleClassOfDateTimeNullable( + (json['value'] as List) + .map((e) => e == null ? null : DateTime.parse(e as String)) + .toList(), + ); Map _$SimpleClassOfDateTimeNullableToJson( SimpleClassOfDateTimeNullable instance) => @@ -188,13 +174,13 @@ Map _$SimpleClassOfDateTimeNullableToJson( }; SimpleClassNullableOfDateTimeNullable - _$SimpleClassNullableOfDateTimeNullableFromJson(Map json) { - return SimpleClassNullableOfDateTimeNullable( - (json['value'] as List?) - ?.map((e) => e == null ? null : DateTime.parse(e as String)) - .toList(), - ); -} + _$SimpleClassNullableOfDateTimeNullableFromJson( + Map json) => + SimpleClassNullableOfDateTimeNullable( + (json['value'] as List?) + ?.map((e) => e == null ? null : DateTime.parse(e as String)) + .toList(), + ); Map _$SimpleClassNullableOfDateTimeNullableToJson( SimpleClassNullableOfDateTimeNullable instance) => @@ -202,11 +188,12 @@ Map _$SimpleClassNullableOfDateTimeNullableToJson( 'value': instance.value?.map((e) => e?.toIso8601String()).toList(), }; -SimpleClassOfDouble _$SimpleClassOfDoubleFromJson(Map json) { - return SimpleClassOfDouble( - (json['value'] as List).map((e) => (e as num).toDouble()).toList(), - ); -} +SimpleClassOfDouble _$SimpleClassOfDoubleFromJson(Map json) => + SimpleClassOfDouble( + (json['value'] as List) + .map((e) => (e as num).toDouble()) + .toList(), + ); Map _$SimpleClassOfDoubleToJson( SimpleClassOfDouble instance) => @@ -215,13 +202,12 @@ Map _$SimpleClassOfDoubleToJson( }; SimpleClassNullableOfDouble _$SimpleClassNullableOfDoubleFromJson( - Map json) { - return SimpleClassNullableOfDouble( - (json['value'] as List?) - ?.map((e) => (e as num).toDouble()) - .toList(), - ); -} + Map json) => + SimpleClassNullableOfDouble( + (json['value'] as List?) + ?.map((e) => (e as num).toDouble()) + .toList(), + ); Map _$SimpleClassNullableOfDoubleToJson( SimpleClassNullableOfDouble instance) => @@ -230,13 +216,12 @@ Map _$SimpleClassNullableOfDoubleToJson( }; SimpleClassOfDoubleNullable _$SimpleClassOfDoubleNullableFromJson( - Map json) { - return SimpleClassOfDoubleNullable( - (json['value'] as List) - .map((e) => (e as num?)?.toDouble()) - .toList(), - ); -} + Map json) => + SimpleClassOfDoubleNullable( + (json['value'] as List) + .map((e) => (e as num?)?.toDouble()) + .toList(), + ); Map _$SimpleClassOfDoubleNullableToJson( SimpleClassOfDoubleNullable instance) => @@ -245,13 +230,12 @@ Map _$SimpleClassOfDoubleNullableToJson( }; SimpleClassNullableOfDoubleNullable - _$SimpleClassNullableOfDoubleNullableFromJson(Map json) { - return SimpleClassNullableOfDoubleNullable( - (json['value'] as List?) - ?.map((e) => (e as num?)?.toDouble()) - .toList(), - ); -} + _$SimpleClassNullableOfDoubleNullableFromJson(Map json) => + SimpleClassNullableOfDoubleNullable( + (json['value'] as List?) + ?.map((e) => (e as num?)?.toDouble()) + .toList(), + ); Map _$SimpleClassNullableOfDoubleNullableToJson( SimpleClassNullableOfDoubleNullable instance) => @@ -260,13 +244,12 @@ Map _$SimpleClassNullableOfDoubleNullableToJson( }; SimpleClassOfDuration _$SimpleClassOfDurationFromJson( - Map json) { - return SimpleClassOfDuration( - (json['value'] as List) - .map((e) => Duration(microseconds: e as int)) - .toList(), - ); -} + Map json) => + SimpleClassOfDuration( + (json['value'] as List) + .map((e) => Duration(microseconds: e as int)) + .toList(), + ); Map _$SimpleClassOfDurationToJson( SimpleClassOfDuration instance) => @@ -275,13 +258,12 @@ Map _$SimpleClassOfDurationToJson( }; SimpleClassNullableOfDuration _$SimpleClassNullableOfDurationFromJson( - Map json) { - return SimpleClassNullableOfDuration( - (json['value'] as List?) - ?.map((e) => Duration(microseconds: e as int)) - .toList(), - ); -} + Map json) => + SimpleClassNullableOfDuration( + (json['value'] as List?) + ?.map((e) => Duration(microseconds: e as int)) + .toList(), + ); Map _$SimpleClassNullableOfDurationToJson( SimpleClassNullableOfDuration instance) => @@ -290,13 +272,12 @@ Map _$SimpleClassNullableOfDurationToJson( }; SimpleClassOfDurationNullable _$SimpleClassOfDurationNullableFromJson( - Map json) { - return SimpleClassOfDurationNullable( - (json['value'] as List) - .map((e) => e == null ? null : Duration(microseconds: e as int)) - .toList(), - ); -} + Map json) => + SimpleClassOfDurationNullable( + (json['value'] as List) + .map((e) => e == null ? null : Duration(microseconds: e as int)) + .toList(), + ); Map _$SimpleClassOfDurationNullableToJson( SimpleClassOfDurationNullable instance) => @@ -305,13 +286,13 @@ Map _$SimpleClassOfDurationNullableToJson( }; SimpleClassNullableOfDurationNullable - _$SimpleClassNullableOfDurationNullableFromJson(Map json) { - return SimpleClassNullableOfDurationNullable( - (json['value'] as List?) - ?.map((e) => e == null ? null : Duration(microseconds: e as int)) - .toList(), - ); -} + _$SimpleClassNullableOfDurationNullableFromJson( + Map json) => + SimpleClassNullableOfDurationNullable( + (json['value'] as List?) + ?.map((e) => e == null ? null : Duration(microseconds: e as int)) + .toList(), + ); Map _$SimpleClassNullableOfDurationNullableToJson( SimpleClassNullableOfDurationNullable instance) => @@ -319,11 +300,11 @@ Map _$SimpleClassNullableOfDurationNullableToJson( 'value': instance.value?.map((e) => e?.inMicroseconds).toList(), }; -SimpleClassOfDynamic _$SimpleClassOfDynamicFromJson(Map json) { - return SimpleClassOfDynamic( - json['value'] as List, - ); -} +SimpleClassOfDynamic _$SimpleClassOfDynamicFromJson( + Map json) => + SimpleClassOfDynamic( + json['value'] as List, + ); Map _$SimpleClassOfDynamicToJson( SimpleClassOfDynamic instance) => @@ -332,11 +313,10 @@ Map _$SimpleClassOfDynamicToJson( }; SimpleClassNullableOfDynamic _$SimpleClassNullableOfDynamicFromJson( - Map json) { - return SimpleClassNullableOfDynamic( - json['value'] as List?, - ); -} + Map json) => + SimpleClassNullableOfDynamic( + json['value'] as List?, + ); Map _$SimpleClassNullableOfDynamicToJson( SimpleClassNullableOfDynamic instance) => @@ -345,13 +325,12 @@ Map _$SimpleClassNullableOfDynamicToJson( }; SimpleClassOfEnumType _$SimpleClassOfEnumTypeFromJson( - Map json) { - return SimpleClassOfEnumType( - (json['value'] as List) - .map((e) => _$enumDecode(_$EnumTypeEnumMap, e)) - .toList(), - ); -} + Map json) => + SimpleClassOfEnumType( + (json['value'] as List) + .map((e) => _$enumDecode(_$EnumTypeEnumMap, e)) + .toList(), + ); Map _$SimpleClassOfEnumTypeToJson( SimpleClassOfEnumType instance) => @@ -393,13 +372,12 @@ const _$EnumTypeEnumMap = { }; SimpleClassNullableOfEnumType _$SimpleClassNullableOfEnumTypeFromJson( - Map json) { - return SimpleClassNullableOfEnumType( - (json['value'] as List?) - ?.map((e) => _$enumDecode(_$EnumTypeEnumMap, e)) - .toList(), - ); -} + Map json) => + SimpleClassNullableOfEnumType( + (json['value'] as List?) + ?.map((e) => _$enumDecode(_$EnumTypeEnumMap, e)) + .toList(), + ); Map _$SimpleClassNullableOfEnumTypeToJson( SimpleClassNullableOfEnumType instance) => @@ -408,13 +386,12 @@ Map _$SimpleClassNullableOfEnumTypeToJson( }; SimpleClassOfEnumTypeNullable _$SimpleClassOfEnumTypeNullableFromJson( - Map json) { - return SimpleClassOfEnumTypeNullable( - (json['value'] as List) - .map((e) => _$enumDecodeNullable(_$EnumTypeEnumMap, e)) - .toList(), - ); -} + Map json) => + SimpleClassOfEnumTypeNullable( + (json['value'] as List) + .map((e) => _$enumDecodeNullable(_$EnumTypeEnumMap, e)) + .toList(), + ); Map _$SimpleClassOfEnumTypeNullableToJson( SimpleClassOfEnumTypeNullable instance) => @@ -434,13 +411,13 @@ K? _$enumDecodeNullable( } SimpleClassNullableOfEnumTypeNullable - _$SimpleClassNullableOfEnumTypeNullableFromJson(Map json) { - return SimpleClassNullableOfEnumTypeNullable( - (json['value'] as List?) - ?.map((e) => _$enumDecodeNullable(_$EnumTypeEnumMap, e)) - .toList(), - ); -} + _$SimpleClassNullableOfEnumTypeNullableFromJson( + Map json) => + SimpleClassNullableOfEnumTypeNullable( + (json['value'] as List?) + ?.map((e) => _$enumDecodeNullable(_$EnumTypeEnumMap, e)) + .toList(), + ); Map _$SimpleClassNullableOfEnumTypeNullableToJson( SimpleClassNullableOfEnumTypeNullable instance) => @@ -448,11 +425,10 @@ Map _$SimpleClassNullableOfEnumTypeNullableToJson( 'value': instance.value?.map((e) => _$EnumTypeEnumMap[e]).toList(), }; -SimpleClassOfInt _$SimpleClassOfIntFromJson(Map json) { - return SimpleClassOfInt( - (json['value'] as List).map((e) => e as int).toList(), - ); -} +SimpleClassOfInt _$SimpleClassOfIntFromJson(Map json) => + SimpleClassOfInt( + (json['value'] as List).map((e) => e as int).toList(), + ); Map _$SimpleClassOfIntToJson(SimpleClassOfInt instance) => { @@ -460,11 +436,10 @@ Map _$SimpleClassOfIntToJson(SimpleClassOfInt instance) => }; SimpleClassNullableOfInt _$SimpleClassNullableOfIntFromJson( - Map json) { - return SimpleClassNullableOfInt( - (json['value'] as List?)?.map((e) => e as int).toList(), - ); -} + Map json) => + SimpleClassNullableOfInt( + (json['value'] as List?)?.map((e) => e as int).toList(), + ); Map _$SimpleClassNullableOfIntToJson( SimpleClassNullableOfInt instance) => @@ -473,11 +448,10 @@ Map _$SimpleClassNullableOfIntToJson( }; SimpleClassOfIntNullable _$SimpleClassOfIntNullableFromJson( - Map json) { - return SimpleClassOfIntNullable( - (json['value'] as List).map((e) => e as int?).toList(), - ); -} + Map json) => + SimpleClassOfIntNullable( + (json['value'] as List).map((e) => e as int?).toList(), + ); Map _$SimpleClassOfIntNullableToJson( SimpleClassOfIntNullable instance) => @@ -486,11 +460,10 @@ Map _$SimpleClassOfIntNullableToJson( }; SimpleClassNullableOfIntNullable _$SimpleClassNullableOfIntNullableFromJson( - Map json) { - return SimpleClassNullableOfIntNullable( - (json['value'] as List?)?.map((e) => e as int?).toList(), - ); -} + Map json) => + SimpleClassNullableOfIntNullable( + (json['value'] as List?)?.map((e) => e as int?).toList(), + ); Map _$SimpleClassNullableOfIntNullableToJson( SimpleClassNullableOfIntNullable instance) => @@ -498,11 +471,10 @@ Map _$SimpleClassNullableOfIntNullableToJson( 'value': instance.value, }; -SimpleClassOfNum _$SimpleClassOfNumFromJson(Map json) { - return SimpleClassOfNum( - (json['value'] as List).map((e) => e as num).toList(), - ); -} +SimpleClassOfNum _$SimpleClassOfNumFromJson(Map json) => + SimpleClassOfNum( + (json['value'] as List).map((e) => e as num).toList(), + ); Map _$SimpleClassOfNumToJson(SimpleClassOfNum instance) => { @@ -510,11 +482,10 @@ Map _$SimpleClassOfNumToJson(SimpleClassOfNum instance) => }; SimpleClassNullableOfNum _$SimpleClassNullableOfNumFromJson( - Map json) { - return SimpleClassNullableOfNum( - (json['value'] as List?)?.map((e) => e as num).toList(), - ); -} + Map json) => + SimpleClassNullableOfNum( + (json['value'] as List?)?.map((e) => e as num).toList(), + ); Map _$SimpleClassNullableOfNumToJson( SimpleClassNullableOfNum instance) => @@ -523,11 +494,10 @@ Map _$SimpleClassNullableOfNumToJson( }; SimpleClassOfNumNullable _$SimpleClassOfNumNullableFromJson( - Map json) { - return SimpleClassOfNumNullable( - (json['value'] as List).map((e) => e as num?).toList(), - ); -} + Map json) => + SimpleClassOfNumNullable( + (json['value'] as List).map((e) => e as num?).toList(), + ); Map _$SimpleClassOfNumNullableToJson( SimpleClassOfNumNullable instance) => @@ -536,11 +506,10 @@ Map _$SimpleClassOfNumNullableToJson( }; SimpleClassNullableOfNumNullable _$SimpleClassNullableOfNumNullableFromJson( - Map json) { - return SimpleClassNullableOfNumNullable( - (json['value'] as List?)?.map((e) => e as num?).toList(), - ); -} + Map json) => + SimpleClassNullableOfNumNullable( + (json['value'] as List?)?.map((e) => e as num?).toList(), + ); Map _$SimpleClassNullableOfNumNullableToJson( SimpleClassNullableOfNumNullable instance) => @@ -548,11 +517,10 @@ Map _$SimpleClassNullableOfNumNullableToJson( 'value': instance.value, }; -SimpleClassOfObject _$SimpleClassOfObjectFromJson(Map json) { - return SimpleClassOfObject( - (json['value'] as List).map((e) => e as Object).toList(), - ); -} +SimpleClassOfObject _$SimpleClassOfObjectFromJson(Map json) => + SimpleClassOfObject( + (json['value'] as List).map((e) => e as Object).toList(), + ); Map _$SimpleClassOfObjectToJson( SimpleClassOfObject instance) => @@ -561,11 +529,10 @@ Map _$SimpleClassOfObjectToJson( }; SimpleClassNullableOfObject _$SimpleClassNullableOfObjectFromJson( - Map json) { - return SimpleClassNullableOfObject( - (json['value'] as List?)?.map((e) => e as Object).toList(), - ); -} + Map json) => + SimpleClassNullableOfObject( + (json['value'] as List?)?.map((e) => e as Object).toList(), + ); Map _$SimpleClassNullableOfObjectToJson( SimpleClassNullableOfObject instance) => @@ -574,11 +541,10 @@ Map _$SimpleClassNullableOfObjectToJson( }; SimpleClassOfObjectNullable _$SimpleClassOfObjectNullableFromJson( - Map json) { - return SimpleClassOfObjectNullable( - json['value'] as List, - ); -} + Map json) => + SimpleClassOfObjectNullable( + json['value'] as List, + ); Map _$SimpleClassOfObjectNullableToJson( SimpleClassOfObjectNullable instance) => @@ -587,11 +553,10 @@ Map _$SimpleClassOfObjectNullableToJson( }; SimpleClassNullableOfObjectNullable - _$SimpleClassNullableOfObjectNullableFromJson(Map json) { - return SimpleClassNullableOfObjectNullable( - json['value'] as List?, - ); -} + _$SimpleClassNullableOfObjectNullableFromJson(Map json) => + SimpleClassNullableOfObjectNullable( + json['value'] as List?, + ); Map _$SimpleClassNullableOfObjectNullableToJson( SimpleClassNullableOfObjectNullable instance) => @@ -599,11 +564,10 @@ Map _$SimpleClassNullableOfObjectNullableToJson( 'value': instance.value, }; -SimpleClassOfString _$SimpleClassOfStringFromJson(Map json) { - return SimpleClassOfString( - (json['value'] as List).map((e) => e as String).toList(), - ); -} +SimpleClassOfString _$SimpleClassOfStringFromJson(Map json) => + SimpleClassOfString( + (json['value'] as List).map((e) => e as String).toList(), + ); Map _$SimpleClassOfStringToJson( SimpleClassOfString instance) => @@ -612,11 +576,10 @@ Map _$SimpleClassOfStringToJson( }; SimpleClassNullableOfString _$SimpleClassNullableOfStringFromJson( - Map json) { - return SimpleClassNullableOfString( - (json['value'] as List?)?.map((e) => e as String).toList(), - ); -} + Map json) => + SimpleClassNullableOfString( + (json['value'] as List?)?.map((e) => e as String).toList(), + ); Map _$SimpleClassNullableOfStringToJson( SimpleClassNullableOfString instance) => @@ -625,11 +588,10 @@ Map _$SimpleClassNullableOfStringToJson( }; SimpleClassOfStringNullable _$SimpleClassOfStringNullableFromJson( - Map json) { - return SimpleClassOfStringNullable( - (json['value'] as List).map((e) => e as String?).toList(), - ); -} + Map json) => + SimpleClassOfStringNullable( + (json['value'] as List).map((e) => e as String?).toList(), + ); Map _$SimpleClassOfStringNullableToJson( SimpleClassOfStringNullable instance) => @@ -638,11 +600,10 @@ Map _$SimpleClassOfStringNullableToJson( }; SimpleClassNullableOfStringNullable - _$SimpleClassNullableOfStringNullableFromJson(Map json) { - return SimpleClassNullableOfStringNullable( - (json['value'] as List?)?.map((e) => e as String?).toList(), - ); -} + _$SimpleClassNullableOfStringNullableFromJson(Map json) => + SimpleClassNullableOfStringNullable( + (json['value'] as List?)?.map((e) => e as String?).toList(), + ); Map _$SimpleClassNullableOfStringNullableToJson( SimpleClassNullableOfStringNullable instance) => @@ -650,13 +611,12 @@ Map _$SimpleClassNullableOfStringNullableToJson( 'value': instance.value, }; -SimpleClassOfUri _$SimpleClassOfUriFromJson(Map json) { - return SimpleClassOfUri( - (json['value'] as List) - .map((e) => Uri.parse(e as String)) - .toList(), - ); -} +SimpleClassOfUri _$SimpleClassOfUriFromJson(Map json) => + SimpleClassOfUri( + (json['value'] as List) + .map((e) => Uri.parse(e as String)) + .toList(), + ); Map _$SimpleClassOfUriToJson(SimpleClassOfUri instance) => { @@ -664,13 +624,12 @@ Map _$SimpleClassOfUriToJson(SimpleClassOfUri instance) => }; SimpleClassNullableOfUri _$SimpleClassNullableOfUriFromJson( - Map json) { - return SimpleClassNullableOfUri( - (json['value'] as List?) - ?.map((e) => Uri.parse(e as String)) - .toList(), - ); -} + Map json) => + SimpleClassNullableOfUri( + (json['value'] as List?) + ?.map((e) => Uri.parse(e as String)) + .toList(), + ); Map _$SimpleClassNullableOfUriToJson( SimpleClassNullableOfUri instance) => @@ -679,13 +638,12 @@ Map _$SimpleClassNullableOfUriToJson( }; SimpleClassOfUriNullable _$SimpleClassOfUriNullableFromJson( - Map json) { - return SimpleClassOfUriNullable( - (json['value'] as List) - .map((e) => e == null ? null : Uri.parse(e as String)) - .toList(), - ); -} + Map json) => + SimpleClassOfUriNullable( + (json['value'] as List) + .map((e) => e == null ? null : Uri.parse(e as String)) + .toList(), + ); Map _$SimpleClassOfUriNullableToJson( SimpleClassOfUriNullable instance) => @@ -694,13 +652,12 @@ Map _$SimpleClassOfUriNullableToJson( }; SimpleClassNullableOfUriNullable _$SimpleClassNullableOfUriNullableFromJson( - Map json) { - return SimpleClassNullableOfUriNullable( - (json['value'] as List?) - ?.map((e) => e == null ? null : Uri.parse(e as String)) - .toList(), - ); -} + Map json) => + SimpleClassNullableOfUriNullable( + (json['value'] as List?) + ?.map((e) => e == null ? null : Uri.parse(e as String)) + .toList(), + ); Map _$SimpleClassNullableOfUriNullableToJson( SimpleClassNullableOfUriNullable instance) => diff --git a/json_serializable/test/supported_types/input.type_map.g.dart b/json_serializable/test/supported_types/input.type_map.g.dart index 40f73b767..5a5f4f352 100644 --- a/json_serializable/test/supported_types/input.type_map.g.dart +++ b/json_serializable/test/supported_types/input.type_map.g.dart @@ -6,12 +6,10 @@ part of 'input.type_map.dart'; // JsonSerializableGenerator // ************************************************************************** -SimpleClass _$SimpleClassFromJson(Map json) { - return SimpleClass( - json['value'] as Map, - json['withDefault'] as Map? ?? {'a': 1}, - ); -} +SimpleClass _$SimpleClassFromJson(Map json) => SimpleClass( + json['value'] as Map, + json['withDefault'] as Map? ?? {'a': 1}, + ); Map _$SimpleClassToJson(SimpleClass instance) => { @@ -19,12 +17,11 @@ Map _$SimpleClassToJson(SimpleClass instance) => 'withDefault': instance.withDefault, }; -SimpleClassNullable _$SimpleClassNullableFromJson(Map json) { - return SimpleClassNullable( - json['value'] as Map?, - json['withDefault'] as Map? ?? {'a': 1}, - ); -} +SimpleClassNullable _$SimpleClassNullableFromJson(Map json) => + SimpleClassNullable( + json['value'] as Map?, + json['withDefault'] as Map? ?? {'a': 1}, + ); Map _$SimpleClassNullableToJson( SimpleClassNullable instance) => @@ -34,13 +31,12 @@ Map _$SimpleClassNullableToJson( }; SimpleClassOfBigIntToBigInt _$SimpleClassOfBigIntToBigIntFromJson( - Map json) { - return SimpleClassOfBigIntToBigInt( - (json['value'] as Map).map( - (k, e) => MapEntry(BigInt.parse(k), BigInt.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassOfBigIntToBigInt( + (json['value'] as Map).map( + (k, e) => MapEntry(BigInt.parse(k), BigInt.parse(e as String)), + ), + ); Map _$SimpleClassOfBigIntToBigIntToJson( SimpleClassOfBigIntToBigInt instance) => @@ -50,13 +46,12 @@ Map _$SimpleClassOfBigIntToBigIntToJson( }; SimpleClassNullableOfBigIntToBigInt - _$SimpleClassNullableOfBigIntToBigIntFromJson(Map json) { - return SimpleClassNullableOfBigIntToBigInt( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(BigInt.parse(k), BigInt.parse(e as String)), - ), - ); -} + _$SimpleClassNullableOfBigIntToBigIntFromJson(Map json) => + SimpleClassNullableOfBigIntToBigInt( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(BigInt.parse(k), BigInt.parse(e as String)), + ), + ); Map _$SimpleClassNullableOfBigIntToBigIntToJson( SimpleClassNullableOfBigIntToBigInt instance) => @@ -66,13 +61,12 @@ Map _$SimpleClassNullableOfBigIntToBigIntToJson( }; SimpleClassOfDateTimeToBigInt _$SimpleClassOfDateTimeToBigIntFromJson( - Map json) { - return SimpleClassOfDateTimeToBigInt( - (json['value'] as Map).map( - (k, e) => MapEntry(DateTime.parse(k), BigInt.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassOfDateTimeToBigInt( + (json['value'] as Map).map( + (k, e) => MapEntry(DateTime.parse(k), BigInt.parse(e as String)), + ), + ); Map _$SimpleClassOfDateTimeToBigIntToJson( SimpleClassOfDateTimeToBigInt instance) => @@ -82,13 +76,13 @@ Map _$SimpleClassOfDateTimeToBigIntToJson( }; SimpleClassNullableOfDateTimeToBigInt - _$SimpleClassNullableOfDateTimeToBigIntFromJson(Map json) { - return SimpleClassNullableOfDateTimeToBigInt( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(DateTime.parse(k), BigInt.parse(e as String)), - ), - ); -} + _$SimpleClassNullableOfDateTimeToBigIntFromJson( + Map json) => + SimpleClassNullableOfDateTimeToBigInt( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(DateTime.parse(k), BigInt.parse(e as String)), + ), + ); Map _$SimpleClassNullableOfDateTimeToBigIntToJson( SimpleClassNullableOfDateTimeToBigInt instance) => @@ -98,13 +92,12 @@ Map _$SimpleClassNullableOfDateTimeToBigIntToJson( }; SimpleClassOfDynamicToBigInt _$SimpleClassOfDynamicToBigIntFromJson( - Map json) { - return SimpleClassOfDynamicToBigInt( - (json['value'] as Map).map( - (k, e) => MapEntry(k, BigInt.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassOfDynamicToBigInt( + (json['value'] as Map).map( + (k, e) => MapEntry(k, BigInt.parse(e as String)), + ), + ); Map _$SimpleClassOfDynamicToBigIntToJson( SimpleClassOfDynamicToBigInt instance) => @@ -113,13 +106,12 @@ Map _$SimpleClassOfDynamicToBigIntToJson( }; SimpleClassNullableOfDynamicToBigInt - _$SimpleClassNullableOfDynamicToBigIntFromJson(Map json) { - return SimpleClassNullableOfDynamicToBigInt( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(k, BigInt.parse(e as String)), - ), - ); -} + _$SimpleClassNullableOfDynamicToBigIntFromJson(Map json) => + SimpleClassNullableOfDynamicToBigInt( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, BigInt.parse(e as String)), + ), + ); Map _$SimpleClassNullableOfDynamicToBigIntToJson( SimpleClassNullableOfDynamicToBigInt instance) => @@ -128,14 +120,13 @@ Map _$SimpleClassNullableOfDynamicToBigIntToJson( }; SimpleClassOfEnumTypeToBigInt _$SimpleClassOfEnumTypeToBigIntFromJson( - Map json) { - return SimpleClassOfEnumTypeToBigInt( - (json['value'] as Map).map( - (k, e) => MapEntry( - _$enumDecode(_$EnumTypeEnumMap, k), BigInt.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassOfEnumTypeToBigInt( + (json['value'] as Map).map( + (k, e) => MapEntry( + _$enumDecode(_$EnumTypeEnumMap, k), BigInt.parse(e as String)), + ), + ); Map _$SimpleClassOfEnumTypeToBigIntToJson( SimpleClassOfEnumTypeToBigInt instance) => @@ -178,14 +169,14 @@ const _$EnumTypeEnumMap = { }; SimpleClassNullableOfEnumTypeToBigInt - _$SimpleClassNullableOfEnumTypeToBigIntFromJson(Map json) { - return SimpleClassNullableOfEnumTypeToBigInt( - (json['value'] as Map?)?.map( - (k, e) => MapEntry( - _$enumDecode(_$EnumTypeEnumMap, k), BigInt.parse(e as String)), - ), - ); -} + _$SimpleClassNullableOfEnumTypeToBigIntFromJson( + Map json) => + SimpleClassNullableOfEnumTypeToBigInt( + (json['value'] as Map?)?.map( + (k, e) => MapEntry( + _$enumDecode(_$EnumTypeEnumMap, k), BigInt.parse(e as String)), + ), + ); Map _$SimpleClassNullableOfEnumTypeToBigIntToJson( SimpleClassNullableOfEnumTypeToBigInt instance) => @@ -195,13 +186,12 @@ Map _$SimpleClassNullableOfEnumTypeToBigIntToJson( }; SimpleClassOfIntToBigInt _$SimpleClassOfIntToBigIntFromJson( - Map json) { - return SimpleClassOfIntToBigInt( - (json['value'] as Map).map( - (k, e) => MapEntry(int.parse(k), BigInt.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassOfIntToBigInt( + (json['value'] as Map).map( + (k, e) => MapEntry(int.parse(k), BigInt.parse(e as String)), + ), + ); Map _$SimpleClassOfIntToBigIntToJson( SimpleClassOfIntToBigInt instance) => @@ -211,13 +201,12 @@ Map _$SimpleClassOfIntToBigIntToJson( }; SimpleClassNullableOfIntToBigInt _$SimpleClassNullableOfIntToBigIntFromJson( - Map json) { - return SimpleClassNullableOfIntToBigInt( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(int.parse(k), BigInt.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassNullableOfIntToBigInt( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(int.parse(k), BigInt.parse(e as String)), + ), + ); Map _$SimpleClassNullableOfIntToBigIntToJson( SimpleClassNullableOfIntToBigInt instance) => @@ -227,13 +216,12 @@ Map _$SimpleClassNullableOfIntToBigIntToJson( }; SimpleClassOfObjectToBigInt _$SimpleClassOfObjectToBigIntFromJson( - Map json) { - return SimpleClassOfObjectToBigInt( - (json['value'] as Map).map( - (k, e) => MapEntry(k, BigInt.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassOfObjectToBigInt( + (json['value'] as Map).map( + (k, e) => MapEntry(k, BigInt.parse(e as String)), + ), + ); Map _$SimpleClassOfObjectToBigIntToJson( SimpleClassOfObjectToBigInt instance) => @@ -242,13 +230,12 @@ Map _$SimpleClassOfObjectToBigIntToJson( }; SimpleClassNullableOfObjectToBigInt - _$SimpleClassNullableOfObjectToBigIntFromJson(Map json) { - return SimpleClassNullableOfObjectToBigInt( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(k, BigInt.parse(e as String)), - ), - ); -} + _$SimpleClassNullableOfObjectToBigIntFromJson(Map json) => + SimpleClassNullableOfObjectToBigInt( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, BigInt.parse(e as String)), + ), + ); Map _$SimpleClassNullableOfObjectToBigIntToJson( SimpleClassNullableOfObjectToBigInt instance) => @@ -257,13 +244,12 @@ Map _$SimpleClassNullableOfObjectToBigIntToJson( }; SimpleClassOfStringToBigInt _$SimpleClassOfStringToBigIntFromJson( - Map json) { - return SimpleClassOfStringToBigInt( - (json['value'] as Map).map( - (k, e) => MapEntry(k, BigInt.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassOfStringToBigInt( + (json['value'] as Map).map( + (k, e) => MapEntry(k, BigInt.parse(e as String)), + ), + ); Map _$SimpleClassOfStringToBigIntToJson( SimpleClassOfStringToBigInt instance) => @@ -272,13 +258,12 @@ Map _$SimpleClassOfStringToBigIntToJson( }; SimpleClassNullableOfStringToBigInt - _$SimpleClassNullableOfStringToBigIntFromJson(Map json) { - return SimpleClassNullableOfStringToBigInt( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(k, BigInt.parse(e as String)), - ), - ); -} + _$SimpleClassNullableOfStringToBigIntFromJson(Map json) => + SimpleClassNullableOfStringToBigInt( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, BigInt.parse(e as String)), + ), + ); Map _$SimpleClassNullableOfStringToBigIntToJson( SimpleClassNullableOfStringToBigInt instance) => @@ -287,13 +272,12 @@ Map _$SimpleClassNullableOfStringToBigIntToJson( }; SimpleClassOfUriToBigInt _$SimpleClassOfUriToBigIntFromJson( - Map json) { - return SimpleClassOfUriToBigInt( - (json['value'] as Map).map( - (k, e) => MapEntry(Uri.parse(k), BigInt.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassOfUriToBigInt( + (json['value'] as Map).map( + (k, e) => MapEntry(Uri.parse(k), BigInt.parse(e as String)), + ), + ); Map _$SimpleClassOfUriToBigIntToJson( SimpleClassOfUriToBigInt instance) => @@ -303,13 +287,12 @@ Map _$SimpleClassOfUriToBigIntToJson( }; SimpleClassNullableOfUriToBigInt _$SimpleClassNullableOfUriToBigIntFromJson( - Map json) { - return SimpleClassNullableOfUriToBigInt( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(Uri.parse(k), BigInt.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassNullableOfUriToBigInt( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(Uri.parse(k), BigInt.parse(e as String)), + ), + ); Map _$SimpleClassNullableOfUriToBigIntToJson( SimpleClassNullableOfUriToBigInt instance) => @@ -319,14 +302,13 @@ Map _$SimpleClassNullableOfUriToBigIntToJson( }; SimpleClassOfBigIntToBigIntNullable - _$SimpleClassOfBigIntToBigIntNullableFromJson(Map json) { - return SimpleClassOfBigIntToBigIntNullable( - (json['value'] as Map).map( - (k, e) => MapEntry( - BigInt.parse(k), e == null ? null : BigInt.parse(e as String)), - ), - ); -} + _$SimpleClassOfBigIntToBigIntNullableFromJson(Map json) => + SimpleClassOfBigIntToBigIntNullable( + (json['value'] as Map).map( + (k, e) => MapEntry( + BigInt.parse(k), e == null ? null : BigInt.parse(e as String)), + ), + ); Map _$SimpleClassOfBigIntToBigIntNullableToJson( SimpleClassOfBigIntToBigIntNullable instance) => @@ -337,14 +319,13 @@ Map _$SimpleClassOfBigIntToBigIntNullableToJson( SimpleClassNullableOfBigIntToBigIntNullable _$SimpleClassNullableOfBigIntToBigIntNullableFromJson( - Map json) { - return SimpleClassNullableOfBigIntToBigIntNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry( - BigInt.parse(k), e == null ? null : BigInt.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassNullableOfBigIntToBigIntNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry( + BigInt.parse(k), e == null ? null : BigInt.parse(e as String)), + ), + ); Map _$SimpleClassNullableOfBigIntToBigIntNullableToJson( SimpleClassNullableOfBigIntToBigIntNullable instance) => @@ -354,14 +335,14 @@ Map _$SimpleClassNullableOfBigIntToBigIntNullableToJson( }; SimpleClassOfDateTimeToBigIntNullable - _$SimpleClassOfDateTimeToBigIntNullableFromJson(Map json) { - return SimpleClassOfDateTimeToBigIntNullable( - (json['value'] as Map).map( - (k, e) => MapEntry( - DateTime.parse(k), e == null ? null : BigInt.parse(e as String)), - ), - ); -} + _$SimpleClassOfDateTimeToBigIntNullableFromJson( + Map json) => + SimpleClassOfDateTimeToBigIntNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(DateTime.parse(k), + e == null ? null : BigInt.parse(e as String)), + ), + ); Map _$SimpleClassOfDateTimeToBigIntNullableToJson( SimpleClassOfDateTimeToBigIntNullable instance) => @@ -372,14 +353,13 @@ Map _$SimpleClassOfDateTimeToBigIntNullableToJson( SimpleClassNullableOfDateTimeToBigIntNullable _$SimpleClassNullableOfDateTimeToBigIntNullableFromJson( - Map json) { - return SimpleClassNullableOfDateTimeToBigIntNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry( - DateTime.parse(k), e == null ? null : BigInt.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassNullableOfDateTimeToBigIntNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(DateTime.parse(k), + e == null ? null : BigInt.parse(e as String)), + ), + ); Map _$SimpleClassNullableOfDateTimeToBigIntNullableToJson( SimpleClassNullableOfDateTimeToBigIntNullable instance) => @@ -389,13 +369,12 @@ Map _$SimpleClassNullableOfDateTimeToBigIntNullableToJson( }; SimpleClassOfDynamicToBigIntNullable - _$SimpleClassOfDynamicToBigIntNullableFromJson(Map json) { - return SimpleClassOfDynamicToBigIntNullable( - (json['value'] as Map).map( - (k, e) => MapEntry(k, e == null ? null : BigInt.parse(e as String)), - ), - ); -} + _$SimpleClassOfDynamicToBigIntNullableFromJson(Map json) => + SimpleClassOfDynamicToBigIntNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(k, e == null ? null : BigInt.parse(e as String)), + ), + ); Map _$SimpleClassOfDynamicToBigIntNullableToJson( SimpleClassOfDynamicToBigIntNullable instance) => @@ -405,13 +384,12 @@ Map _$SimpleClassOfDynamicToBigIntNullableToJson( SimpleClassNullableOfDynamicToBigIntNullable _$SimpleClassNullableOfDynamicToBigIntNullableFromJson( - Map json) { - return SimpleClassNullableOfDynamicToBigIntNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(k, e == null ? null : BigInt.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassNullableOfDynamicToBigIntNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e == null ? null : BigInt.parse(e as String)), + ), + ); Map _$SimpleClassNullableOfDynamicToBigIntNullableToJson( SimpleClassNullableOfDynamicToBigIntNullable instance) => @@ -420,14 +398,14 @@ Map _$SimpleClassNullableOfDynamicToBigIntNullableToJson( }; SimpleClassOfEnumTypeToBigIntNullable - _$SimpleClassOfEnumTypeToBigIntNullableFromJson(Map json) { - return SimpleClassOfEnumTypeToBigIntNullable( - (json['value'] as Map).map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), - e == null ? null : BigInt.parse(e as String)), - ), - ); -} + _$SimpleClassOfEnumTypeToBigIntNullableFromJson( + Map json) => + SimpleClassOfEnumTypeToBigIntNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), + e == null ? null : BigInt.parse(e as String)), + ), + ); Map _$SimpleClassOfEnumTypeToBigIntNullableToJson( SimpleClassOfEnumTypeToBigIntNullable instance) => @@ -438,14 +416,13 @@ Map _$SimpleClassOfEnumTypeToBigIntNullableToJson( SimpleClassNullableOfEnumTypeToBigIntNullable _$SimpleClassNullableOfEnumTypeToBigIntNullableFromJson( - Map json) { - return SimpleClassNullableOfEnumTypeToBigIntNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), - e == null ? null : BigInt.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassNullableOfEnumTypeToBigIntNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), + e == null ? null : BigInt.parse(e as String)), + ), + ); Map _$SimpleClassNullableOfEnumTypeToBigIntNullableToJson( SimpleClassNullableOfEnumTypeToBigIntNullable instance) => @@ -455,14 +432,13 @@ Map _$SimpleClassNullableOfEnumTypeToBigIntNullableToJson( }; SimpleClassOfIntToBigIntNullable _$SimpleClassOfIntToBigIntNullableFromJson( - Map json) { - return SimpleClassOfIntToBigIntNullable( - (json['value'] as Map).map( - (k, e) => - MapEntry(int.parse(k), e == null ? null : BigInt.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassOfIntToBigIntNullable( + (json['value'] as Map).map( + (k, e) => MapEntry( + int.parse(k), e == null ? null : BigInt.parse(e as String)), + ), + ); Map _$SimpleClassOfIntToBigIntNullableToJson( SimpleClassOfIntToBigIntNullable instance) => @@ -473,14 +449,13 @@ Map _$SimpleClassOfIntToBigIntNullableToJson( SimpleClassNullableOfIntToBigIntNullable _$SimpleClassNullableOfIntToBigIntNullableFromJson( - Map json) { - return SimpleClassNullableOfIntToBigIntNullable( - (json['value'] as Map?)?.map( - (k, e) => - MapEntry(int.parse(k), e == null ? null : BigInt.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassNullableOfIntToBigIntNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry( + int.parse(k), e == null ? null : BigInt.parse(e as String)), + ), + ); Map _$SimpleClassNullableOfIntToBigIntNullableToJson( SimpleClassNullableOfIntToBigIntNullable instance) => @@ -490,13 +465,12 @@ Map _$SimpleClassNullableOfIntToBigIntNullableToJson( }; SimpleClassOfObjectToBigIntNullable - _$SimpleClassOfObjectToBigIntNullableFromJson(Map json) { - return SimpleClassOfObjectToBigIntNullable( - (json['value'] as Map).map( - (k, e) => MapEntry(k, e == null ? null : BigInt.parse(e as String)), - ), - ); -} + _$SimpleClassOfObjectToBigIntNullableFromJson(Map json) => + SimpleClassOfObjectToBigIntNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(k, e == null ? null : BigInt.parse(e as String)), + ), + ); Map _$SimpleClassOfObjectToBigIntNullableToJson( SimpleClassOfObjectToBigIntNullable instance) => @@ -506,13 +480,12 @@ Map _$SimpleClassOfObjectToBigIntNullableToJson( SimpleClassNullableOfObjectToBigIntNullable _$SimpleClassNullableOfObjectToBigIntNullableFromJson( - Map json) { - return SimpleClassNullableOfObjectToBigIntNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(k, e == null ? null : BigInt.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassNullableOfObjectToBigIntNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e == null ? null : BigInt.parse(e as String)), + ), + ); Map _$SimpleClassNullableOfObjectToBigIntNullableToJson( SimpleClassNullableOfObjectToBigIntNullable instance) => @@ -521,13 +494,12 @@ Map _$SimpleClassNullableOfObjectToBigIntNullableToJson( }; SimpleClassOfStringToBigIntNullable - _$SimpleClassOfStringToBigIntNullableFromJson(Map json) { - return SimpleClassOfStringToBigIntNullable( - (json['value'] as Map).map( - (k, e) => MapEntry(k, e == null ? null : BigInt.parse(e as String)), - ), - ); -} + _$SimpleClassOfStringToBigIntNullableFromJson(Map json) => + SimpleClassOfStringToBigIntNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(k, e == null ? null : BigInt.parse(e as String)), + ), + ); Map _$SimpleClassOfStringToBigIntNullableToJson( SimpleClassOfStringToBigIntNullable instance) => @@ -537,13 +509,12 @@ Map _$SimpleClassOfStringToBigIntNullableToJson( SimpleClassNullableOfStringToBigIntNullable _$SimpleClassNullableOfStringToBigIntNullableFromJson( - Map json) { - return SimpleClassNullableOfStringToBigIntNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(k, e == null ? null : BigInt.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassNullableOfStringToBigIntNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e == null ? null : BigInt.parse(e as String)), + ), + ); Map _$SimpleClassNullableOfStringToBigIntNullableToJson( SimpleClassNullableOfStringToBigIntNullable instance) => @@ -552,14 +523,13 @@ Map _$SimpleClassNullableOfStringToBigIntNullableToJson( }; SimpleClassOfUriToBigIntNullable _$SimpleClassOfUriToBigIntNullableFromJson( - Map json) { - return SimpleClassOfUriToBigIntNullable( - (json['value'] as Map).map( - (k, e) => - MapEntry(Uri.parse(k), e == null ? null : BigInt.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassOfUriToBigIntNullable( + (json['value'] as Map).map( + (k, e) => MapEntry( + Uri.parse(k), e == null ? null : BigInt.parse(e as String)), + ), + ); Map _$SimpleClassOfUriToBigIntNullableToJson( SimpleClassOfUriToBigIntNullable instance) => @@ -570,14 +540,13 @@ Map _$SimpleClassOfUriToBigIntNullableToJson( SimpleClassNullableOfUriToBigIntNullable _$SimpleClassNullableOfUriToBigIntNullableFromJson( - Map json) { - return SimpleClassNullableOfUriToBigIntNullable( - (json['value'] as Map?)?.map( - (k, e) => - MapEntry(Uri.parse(k), e == null ? null : BigInt.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassNullableOfUriToBigIntNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry( + Uri.parse(k), e == null ? null : BigInt.parse(e as String)), + ), + ); Map _$SimpleClassNullableOfUriToBigIntNullableToJson( SimpleClassNullableOfUriToBigIntNullable instance) => @@ -587,13 +556,12 @@ Map _$SimpleClassNullableOfUriToBigIntNullableToJson( }; SimpleClassOfBigIntToBool _$SimpleClassOfBigIntToBoolFromJson( - Map json) { - return SimpleClassOfBigIntToBool( - (json['value'] as Map).map( - (k, e) => MapEntry(BigInt.parse(k), e as bool), - ), - ); -} + Map json) => + SimpleClassOfBigIntToBool( + (json['value'] as Map).map( + (k, e) => MapEntry(BigInt.parse(k), e as bool), + ), + ); Map _$SimpleClassOfBigIntToBoolToJson( SimpleClassOfBigIntToBool instance) => @@ -602,13 +570,12 @@ Map _$SimpleClassOfBigIntToBoolToJson( }; SimpleClassNullableOfBigIntToBool _$SimpleClassNullableOfBigIntToBoolFromJson( - Map json) { - return SimpleClassNullableOfBigIntToBool( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(BigInt.parse(k), e as bool), - ), - ); -} + Map json) => + SimpleClassNullableOfBigIntToBool( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(BigInt.parse(k), e as bool), + ), + ); Map _$SimpleClassNullableOfBigIntToBoolToJson( SimpleClassNullableOfBigIntToBool instance) => @@ -617,13 +584,12 @@ Map _$SimpleClassNullableOfBigIntToBoolToJson( }; SimpleClassOfDateTimeToBool _$SimpleClassOfDateTimeToBoolFromJson( - Map json) { - return SimpleClassOfDateTimeToBool( - (json['value'] as Map).map( - (k, e) => MapEntry(DateTime.parse(k), e as bool), - ), - ); -} + Map json) => + SimpleClassOfDateTimeToBool( + (json['value'] as Map).map( + (k, e) => MapEntry(DateTime.parse(k), e as bool), + ), + ); Map _$SimpleClassOfDateTimeToBoolToJson( SimpleClassOfDateTimeToBool instance) => @@ -632,13 +598,12 @@ Map _$SimpleClassOfDateTimeToBoolToJson( }; SimpleClassNullableOfDateTimeToBool - _$SimpleClassNullableOfDateTimeToBoolFromJson(Map json) { - return SimpleClassNullableOfDateTimeToBool( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(DateTime.parse(k), e as bool), - ), - ); -} + _$SimpleClassNullableOfDateTimeToBoolFromJson(Map json) => + SimpleClassNullableOfDateTimeToBool( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(DateTime.parse(k), e as bool), + ), + ); Map _$SimpleClassNullableOfDateTimeToBoolToJson( SimpleClassNullableOfDateTimeToBool instance) => @@ -647,11 +612,10 @@ Map _$SimpleClassNullableOfDateTimeToBoolToJson( }; SimpleClassOfDynamicToBool _$SimpleClassOfDynamicToBoolFromJson( - Map json) { - return SimpleClassOfDynamicToBool( - Map.from(json['value'] as Map), - ); -} + Map json) => + SimpleClassOfDynamicToBool( + Map.from(json['value'] as Map), + ); Map _$SimpleClassOfDynamicToBoolToJson( SimpleClassOfDynamicToBool instance) => @@ -660,13 +624,12 @@ Map _$SimpleClassOfDynamicToBoolToJson( }; SimpleClassNullableOfDynamicToBool _$SimpleClassNullableOfDynamicToBoolFromJson( - Map json) { - return SimpleClassNullableOfDynamicToBool( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(k, e as bool), - ), - ); -} + Map json) => + SimpleClassNullableOfDynamicToBool( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e as bool), + ), + ); Map _$SimpleClassNullableOfDynamicToBoolToJson( SimpleClassNullableOfDynamicToBool instance) => @@ -675,13 +638,12 @@ Map _$SimpleClassNullableOfDynamicToBoolToJson( }; SimpleClassOfEnumTypeToBool _$SimpleClassOfEnumTypeToBoolFromJson( - Map json) { - return SimpleClassOfEnumTypeToBool( - (json['value'] as Map).map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as bool), - ), - ); -} + Map json) => + SimpleClassOfEnumTypeToBool( + (json['value'] as Map).map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as bool), + ), + ); Map _$SimpleClassOfEnumTypeToBoolToJson( SimpleClassOfEnumTypeToBool instance) => @@ -690,13 +652,12 @@ Map _$SimpleClassOfEnumTypeToBoolToJson( }; SimpleClassNullableOfEnumTypeToBool - _$SimpleClassNullableOfEnumTypeToBoolFromJson(Map json) { - return SimpleClassNullableOfEnumTypeToBool( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as bool), - ), - ); -} + _$SimpleClassNullableOfEnumTypeToBoolFromJson(Map json) => + SimpleClassNullableOfEnumTypeToBool( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as bool), + ), + ); Map _$SimpleClassNullableOfEnumTypeToBoolToJson( SimpleClassNullableOfEnumTypeToBool instance) => @@ -705,13 +666,12 @@ Map _$SimpleClassNullableOfEnumTypeToBoolToJson( }; SimpleClassOfIntToBool _$SimpleClassOfIntToBoolFromJson( - Map json) { - return SimpleClassOfIntToBool( - (json['value'] as Map).map( - (k, e) => MapEntry(int.parse(k), e as bool), - ), - ); -} + Map json) => + SimpleClassOfIntToBool( + (json['value'] as Map).map( + (k, e) => MapEntry(int.parse(k), e as bool), + ), + ); Map _$SimpleClassOfIntToBoolToJson( SimpleClassOfIntToBool instance) => @@ -720,13 +680,12 @@ Map _$SimpleClassOfIntToBoolToJson( }; SimpleClassNullableOfIntToBool _$SimpleClassNullableOfIntToBoolFromJson( - Map json) { - return SimpleClassNullableOfIntToBool( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(int.parse(k), e as bool), - ), - ); -} + Map json) => + SimpleClassNullableOfIntToBool( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(int.parse(k), e as bool), + ), + ); Map _$SimpleClassNullableOfIntToBoolToJson( SimpleClassNullableOfIntToBool instance) => @@ -735,11 +694,10 @@ Map _$SimpleClassNullableOfIntToBoolToJson( }; SimpleClassOfObjectToBool _$SimpleClassOfObjectToBoolFromJson( - Map json) { - return SimpleClassOfObjectToBool( - Map.from(json['value'] as Map), - ); -} + Map json) => + SimpleClassOfObjectToBool( + Map.from(json['value'] as Map), + ); Map _$SimpleClassOfObjectToBoolToJson( SimpleClassOfObjectToBool instance) => @@ -748,13 +706,12 @@ Map _$SimpleClassOfObjectToBoolToJson( }; SimpleClassNullableOfObjectToBool _$SimpleClassNullableOfObjectToBoolFromJson( - Map json) { - return SimpleClassNullableOfObjectToBool( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(k, e as bool), - ), - ); -} + Map json) => + SimpleClassNullableOfObjectToBool( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e as bool), + ), + ); Map _$SimpleClassNullableOfObjectToBoolToJson( SimpleClassNullableOfObjectToBool instance) => @@ -763,11 +720,10 @@ Map _$SimpleClassNullableOfObjectToBoolToJson( }; SimpleClassOfStringToBool _$SimpleClassOfStringToBoolFromJson( - Map json) { - return SimpleClassOfStringToBool( - Map.from(json['value'] as Map), - ); -} + Map json) => + SimpleClassOfStringToBool( + Map.from(json['value'] as Map), + ); Map _$SimpleClassOfStringToBoolToJson( SimpleClassOfStringToBool instance) => @@ -776,13 +732,12 @@ Map _$SimpleClassOfStringToBoolToJson( }; SimpleClassNullableOfStringToBool _$SimpleClassNullableOfStringToBoolFromJson( - Map json) { - return SimpleClassNullableOfStringToBool( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(k, e as bool), - ), - ); -} + Map json) => + SimpleClassNullableOfStringToBool( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e as bool), + ), + ); Map _$SimpleClassNullableOfStringToBoolToJson( SimpleClassNullableOfStringToBool instance) => @@ -791,13 +746,12 @@ Map _$SimpleClassNullableOfStringToBoolToJson( }; SimpleClassOfUriToBool _$SimpleClassOfUriToBoolFromJson( - Map json) { - return SimpleClassOfUriToBool( - (json['value'] as Map).map( - (k, e) => MapEntry(Uri.parse(k), e as bool), - ), - ); -} + Map json) => + SimpleClassOfUriToBool( + (json['value'] as Map).map( + (k, e) => MapEntry(Uri.parse(k), e as bool), + ), + ); Map _$SimpleClassOfUriToBoolToJson( SimpleClassOfUriToBool instance) => @@ -806,13 +760,12 @@ Map _$SimpleClassOfUriToBoolToJson( }; SimpleClassNullableOfUriToBool _$SimpleClassNullableOfUriToBoolFromJson( - Map json) { - return SimpleClassNullableOfUriToBool( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(Uri.parse(k), e as bool), - ), - ); -} + Map json) => + SimpleClassNullableOfUriToBool( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(Uri.parse(k), e as bool), + ), + ); Map _$SimpleClassNullableOfUriToBoolToJson( SimpleClassNullableOfUriToBool instance) => @@ -821,13 +774,12 @@ Map _$SimpleClassNullableOfUriToBoolToJson( }; SimpleClassOfBigIntToBoolNullable _$SimpleClassOfBigIntToBoolNullableFromJson( - Map json) { - return SimpleClassOfBigIntToBoolNullable( - (json['value'] as Map).map( - (k, e) => MapEntry(BigInt.parse(k), e as bool?), - ), - ); -} + Map json) => + SimpleClassOfBigIntToBoolNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(BigInt.parse(k), e as bool?), + ), + ); Map _$SimpleClassOfBigIntToBoolNullableToJson( SimpleClassOfBigIntToBoolNullable instance) => @@ -837,13 +789,12 @@ Map _$SimpleClassOfBigIntToBoolNullableToJson( SimpleClassNullableOfBigIntToBoolNullable _$SimpleClassNullableOfBigIntToBoolNullableFromJson( - Map json) { - return SimpleClassNullableOfBigIntToBoolNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(BigInt.parse(k), e as bool?), - ), - ); -} + Map json) => + SimpleClassNullableOfBigIntToBoolNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(BigInt.parse(k), e as bool?), + ), + ); Map _$SimpleClassNullableOfBigIntToBoolNullableToJson( SimpleClassNullableOfBigIntToBoolNullable instance) => @@ -852,13 +803,12 @@ Map _$SimpleClassNullableOfBigIntToBoolNullableToJson( }; SimpleClassOfDateTimeToBoolNullable - _$SimpleClassOfDateTimeToBoolNullableFromJson(Map json) { - return SimpleClassOfDateTimeToBoolNullable( - (json['value'] as Map).map( - (k, e) => MapEntry(DateTime.parse(k), e as bool?), - ), - ); -} + _$SimpleClassOfDateTimeToBoolNullableFromJson(Map json) => + SimpleClassOfDateTimeToBoolNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(DateTime.parse(k), e as bool?), + ), + ); Map _$SimpleClassOfDateTimeToBoolNullableToJson( SimpleClassOfDateTimeToBoolNullable instance) => @@ -868,13 +818,12 @@ Map _$SimpleClassOfDateTimeToBoolNullableToJson( SimpleClassNullableOfDateTimeToBoolNullable _$SimpleClassNullableOfDateTimeToBoolNullableFromJson( - Map json) { - return SimpleClassNullableOfDateTimeToBoolNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(DateTime.parse(k), e as bool?), - ), - ); -} + Map json) => + SimpleClassNullableOfDateTimeToBoolNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(DateTime.parse(k), e as bool?), + ), + ); Map _$SimpleClassNullableOfDateTimeToBoolNullableToJson( SimpleClassNullableOfDateTimeToBoolNullable instance) => @@ -883,11 +832,10 @@ Map _$SimpleClassNullableOfDateTimeToBoolNullableToJson( }; SimpleClassOfDynamicToBoolNullable _$SimpleClassOfDynamicToBoolNullableFromJson( - Map json) { - return SimpleClassOfDynamicToBoolNullable( - Map.from(json['value'] as Map), - ); -} + Map json) => + SimpleClassOfDynamicToBoolNullable( + Map.from(json['value'] as Map), + ); Map _$SimpleClassOfDynamicToBoolNullableToJson( SimpleClassOfDynamicToBoolNullable instance) => @@ -897,13 +845,12 @@ Map _$SimpleClassOfDynamicToBoolNullableToJson( SimpleClassNullableOfDynamicToBoolNullable _$SimpleClassNullableOfDynamicToBoolNullableFromJson( - Map json) { - return SimpleClassNullableOfDynamicToBoolNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(k, e as bool?), - ), - ); -} + Map json) => + SimpleClassNullableOfDynamicToBoolNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e as bool?), + ), + ); Map _$SimpleClassNullableOfDynamicToBoolNullableToJson( SimpleClassNullableOfDynamicToBoolNullable instance) => @@ -912,13 +859,12 @@ Map _$SimpleClassNullableOfDynamicToBoolNullableToJson( }; SimpleClassOfEnumTypeToBoolNullable - _$SimpleClassOfEnumTypeToBoolNullableFromJson(Map json) { - return SimpleClassOfEnumTypeToBoolNullable( - (json['value'] as Map).map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as bool?), - ), - ); -} + _$SimpleClassOfEnumTypeToBoolNullableFromJson(Map json) => + SimpleClassOfEnumTypeToBoolNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as bool?), + ), + ); Map _$SimpleClassOfEnumTypeToBoolNullableToJson( SimpleClassOfEnumTypeToBoolNullable instance) => @@ -928,13 +874,12 @@ Map _$SimpleClassOfEnumTypeToBoolNullableToJson( SimpleClassNullableOfEnumTypeToBoolNullable _$SimpleClassNullableOfEnumTypeToBoolNullableFromJson( - Map json) { - return SimpleClassNullableOfEnumTypeToBoolNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as bool?), - ), - ); -} + Map json) => + SimpleClassNullableOfEnumTypeToBoolNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as bool?), + ), + ); Map _$SimpleClassNullableOfEnumTypeToBoolNullableToJson( SimpleClassNullableOfEnumTypeToBoolNullable instance) => @@ -943,13 +888,12 @@ Map _$SimpleClassNullableOfEnumTypeToBoolNullableToJson( }; SimpleClassOfIntToBoolNullable _$SimpleClassOfIntToBoolNullableFromJson( - Map json) { - return SimpleClassOfIntToBoolNullable( - (json['value'] as Map).map( - (k, e) => MapEntry(int.parse(k), e as bool?), - ), - ); -} + Map json) => + SimpleClassOfIntToBoolNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(int.parse(k), e as bool?), + ), + ); Map _$SimpleClassOfIntToBoolNullableToJson( SimpleClassOfIntToBoolNullable instance) => @@ -959,13 +903,12 @@ Map _$SimpleClassOfIntToBoolNullableToJson( SimpleClassNullableOfIntToBoolNullable _$SimpleClassNullableOfIntToBoolNullableFromJson( - Map json) { - return SimpleClassNullableOfIntToBoolNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(int.parse(k), e as bool?), - ), - ); -} + Map json) => + SimpleClassNullableOfIntToBoolNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(int.parse(k), e as bool?), + ), + ); Map _$SimpleClassNullableOfIntToBoolNullableToJson( SimpleClassNullableOfIntToBoolNullable instance) => @@ -974,11 +917,10 @@ Map _$SimpleClassNullableOfIntToBoolNullableToJson( }; SimpleClassOfObjectToBoolNullable _$SimpleClassOfObjectToBoolNullableFromJson( - Map json) { - return SimpleClassOfObjectToBoolNullable( - Map.from(json['value'] as Map), - ); -} + Map json) => + SimpleClassOfObjectToBoolNullable( + Map.from(json['value'] as Map), + ); Map _$SimpleClassOfObjectToBoolNullableToJson( SimpleClassOfObjectToBoolNullable instance) => @@ -988,13 +930,12 @@ Map _$SimpleClassOfObjectToBoolNullableToJson( SimpleClassNullableOfObjectToBoolNullable _$SimpleClassNullableOfObjectToBoolNullableFromJson( - Map json) { - return SimpleClassNullableOfObjectToBoolNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(k, e as bool?), - ), - ); -} + Map json) => + SimpleClassNullableOfObjectToBoolNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e as bool?), + ), + ); Map _$SimpleClassNullableOfObjectToBoolNullableToJson( SimpleClassNullableOfObjectToBoolNullable instance) => @@ -1003,11 +944,10 @@ Map _$SimpleClassNullableOfObjectToBoolNullableToJson( }; SimpleClassOfStringToBoolNullable _$SimpleClassOfStringToBoolNullableFromJson( - Map json) { - return SimpleClassOfStringToBoolNullable( - Map.from(json['value'] as Map), - ); -} + Map json) => + SimpleClassOfStringToBoolNullable( + Map.from(json['value'] as Map), + ); Map _$SimpleClassOfStringToBoolNullableToJson( SimpleClassOfStringToBoolNullable instance) => @@ -1017,13 +957,12 @@ Map _$SimpleClassOfStringToBoolNullableToJson( SimpleClassNullableOfStringToBoolNullable _$SimpleClassNullableOfStringToBoolNullableFromJson( - Map json) { - return SimpleClassNullableOfStringToBoolNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(k, e as bool?), - ), - ); -} + Map json) => + SimpleClassNullableOfStringToBoolNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e as bool?), + ), + ); Map _$SimpleClassNullableOfStringToBoolNullableToJson( SimpleClassNullableOfStringToBoolNullable instance) => @@ -1032,13 +971,12 @@ Map _$SimpleClassNullableOfStringToBoolNullableToJson( }; SimpleClassOfUriToBoolNullable _$SimpleClassOfUriToBoolNullableFromJson( - Map json) { - return SimpleClassOfUriToBoolNullable( - (json['value'] as Map).map( - (k, e) => MapEntry(Uri.parse(k), e as bool?), - ), - ); -} + Map json) => + SimpleClassOfUriToBoolNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(Uri.parse(k), e as bool?), + ), + ); Map _$SimpleClassOfUriToBoolNullableToJson( SimpleClassOfUriToBoolNullable instance) => @@ -1048,13 +986,12 @@ Map _$SimpleClassOfUriToBoolNullableToJson( SimpleClassNullableOfUriToBoolNullable _$SimpleClassNullableOfUriToBoolNullableFromJson( - Map json) { - return SimpleClassNullableOfUriToBoolNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(Uri.parse(k), e as bool?), - ), - ); -} + Map json) => + SimpleClassNullableOfUriToBoolNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(Uri.parse(k), e as bool?), + ), + ); Map _$SimpleClassNullableOfUriToBoolNullableToJson( SimpleClassNullableOfUriToBoolNullable instance) => @@ -1063,13 +1000,12 @@ Map _$SimpleClassNullableOfUriToBoolNullableToJson( }; SimpleClassOfBigIntToDateTime _$SimpleClassOfBigIntToDateTimeFromJson( - Map json) { - return SimpleClassOfBigIntToDateTime( - (json['value'] as Map).map( - (k, e) => MapEntry(BigInt.parse(k), DateTime.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassOfBigIntToDateTime( + (json['value'] as Map).map( + (k, e) => MapEntry(BigInt.parse(k), DateTime.parse(e as String)), + ), + ); Map _$SimpleClassOfBigIntToDateTimeToJson( SimpleClassOfBigIntToDateTime instance) => @@ -1079,13 +1015,13 @@ Map _$SimpleClassOfBigIntToDateTimeToJson( }; SimpleClassNullableOfBigIntToDateTime - _$SimpleClassNullableOfBigIntToDateTimeFromJson(Map json) { - return SimpleClassNullableOfBigIntToDateTime( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(BigInt.parse(k), DateTime.parse(e as String)), - ), - ); -} + _$SimpleClassNullableOfBigIntToDateTimeFromJson( + Map json) => + SimpleClassNullableOfBigIntToDateTime( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(BigInt.parse(k), DateTime.parse(e as String)), + ), + ); Map _$SimpleClassNullableOfBigIntToDateTimeToJson( SimpleClassNullableOfBigIntToDateTime instance) => @@ -1095,13 +1031,12 @@ Map _$SimpleClassNullableOfBigIntToDateTimeToJson( }; SimpleClassOfDateTimeToDateTime _$SimpleClassOfDateTimeToDateTimeFromJson( - Map json) { - return SimpleClassOfDateTimeToDateTime( - (json['value'] as Map).map( - (k, e) => MapEntry(DateTime.parse(k), DateTime.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassOfDateTimeToDateTime( + (json['value'] as Map).map( + (k, e) => MapEntry(DateTime.parse(k), DateTime.parse(e as String)), + ), + ); Map _$SimpleClassOfDateTimeToDateTimeToJson( SimpleClassOfDateTimeToDateTime instance) => @@ -1112,13 +1047,12 @@ Map _$SimpleClassOfDateTimeToDateTimeToJson( SimpleClassNullableOfDateTimeToDateTime _$SimpleClassNullableOfDateTimeToDateTimeFromJson( - Map json) { - return SimpleClassNullableOfDateTimeToDateTime( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(DateTime.parse(k), DateTime.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassNullableOfDateTimeToDateTime( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(DateTime.parse(k), DateTime.parse(e as String)), + ), + ); Map _$SimpleClassNullableOfDateTimeToDateTimeToJson( SimpleClassNullableOfDateTimeToDateTime instance) => @@ -1128,13 +1062,12 @@ Map _$SimpleClassNullableOfDateTimeToDateTimeToJson( }; SimpleClassOfDynamicToDateTime _$SimpleClassOfDynamicToDateTimeFromJson( - Map json) { - return SimpleClassOfDynamicToDateTime( - (json['value'] as Map).map( - (k, e) => MapEntry(k, DateTime.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassOfDynamicToDateTime( + (json['value'] as Map).map( + (k, e) => MapEntry(k, DateTime.parse(e as String)), + ), + ); Map _$SimpleClassOfDynamicToDateTimeToJson( SimpleClassOfDynamicToDateTime instance) => @@ -1144,13 +1077,12 @@ Map _$SimpleClassOfDynamicToDateTimeToJson( SimpleClassNullableOfDynamicToDateTime _$SimpleClassNullableOfDynamicToDateTimeFromJson( - Map json) { - return SimpleClassNullableOfDynamicToDateTime( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(k, DateTime.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassNullableOfDynamicToDateTime( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, DateTime.parse(e as String)), + ), + ); Map _$SimpleClassNullableOfDynamicToDateTimeToJson( SimpleClassNullableOfDynamicToDateTime instance) => @@ -1159,14 +1091,13 @@ Map _$SimpleClassNullableOfDynamicToDateTimeToJson( }; SimpleClassOfEnumTypeToDateTime _$SimpleClassOfEnumTypeToDateTimeFromJson( - Map json) { - return SimpleClassOfEnumTypeToDateTime( - (json['value'] as Map).map( - (k, e) => MapEntry( - _$enumDecode(_$EnumTypeEnumMap, k), DateTime.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassOfEnumTypeToDateTime( + (json['value'] as Map).map( + (k, e) => MapEntry( + _$enumDecode(_$EnumTypeEnumMap, k), DateTime.parse(e as String)), + ), + ); Map _$SimpleClassOfEnumTypeToDateTimeToJson( SimpleClassOfEnumTypeToDateTime instance) => @@ -1177,14 +1108,13 @@ Map _$SimpleClassOfEnumTypeToDateTimeToJson( SimpleClassNullableOfEnumTypeToDateTime _$SimpleClassNullableOfEnumTypeToDateTimeFromJson( - Map json) { - return SimpleClassNullableOfEnumTypeToDateTime( - (json['value'] as Map?)?.map( - (k, e) => MapEntry( - _$enumDecode(_$EnumTypeEnumMap, k), DateTime.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassNullableOfEnumTypeToDateTime( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), + DateTime.parse(e as String)), + ), + ); Map _$SimpleClassNullableOfEnumTypeToDateTimeToJson( SimpleClassNullableOfEnumTypeToDateTime instance) => @@ -1194,13 +1124,12 @@ Map _$SimpleClassNullableOfEnumTypeToDateTimeToJson( }; SimpleClassOfIntToDateTime _$SimpleClassOfIntToDateTimeFromJson( - Map json) { - return SimpleClassOfIntToDateTime( - (json['value'] as Map).map( - (k, e) => MapEntry(int.parse(k), DateTime.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassOfIntToDateTime( + (json['value'] as Map).map( + (k, e) => MapEntry(int.parse(k), DateTime.parse(e as String)), + ), + ); Map _$SimpleClassOfIntToDateTimeToJson( SimpleClassOfIntToDateTime instance) => @@ -1210,13 +1139,12 @@ Map _$SimpleClassOfIntToDateTimeToJson( }; SimpleClassNullableOfIntToDateTime _$SimpleClassNullableOfIntToDateTimeFromJson( - Map json) { - return SimpleClassNullableOfIntToDateTime( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(int.parse(k), DateTime.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassNullableOfIntToDateTime( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(int.parse(k), DateTime.parse(e as String)), + ), + ); Map _$SimpleClassNullableOfIntToDateTimeToJson( SimpleClassNullableOfIntToDateTime instance) => @@ -1226,13 +1154,12 @@ Map _$SimpleClassNullableOfIntToDateTimeToJson( }; SimpleClassOfObjectToDateTime _$SimpleClassOfObjectToDateTimeFromJson( - Map json) { - return SimpleClassOfObjectToDateTime( - (json['value'] as Map).map( - (k, e) => MapEntry(k, DateTime.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassOfObjectToDateTime( + (json['value'] as Map).map( + (k, e) => MapEntry(k, DateTime.parse(e as String)), + ), + ); Map _$SimpleClassOfObjectToDateTimeToJson( SimpleClassOfObjectToDateTime instance) => @@ -1241,13 +1168,13 @@ Map _$SimpleClassOfObjectToDateTimeToJson( }; SimpleClassNullableOfObjectToDateTime - _$SimpleClassNullableOfObjectToDateTimeFromJson(Map json) { - return SimpleClassNullableOfObjectToDateTime( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(k, DateTime.parse(e as String)), - ), - ); -} + _$SimpleClassNullableOfObjectToDateTimeFromJson( + Map json) => + SimpleClassNullableOfObjectToDateTime( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, DateTime.parse(e as String)), + ), + ); Map _$SimpleClassNullableOfObjectToDateTimeToJson( SimpleClassNullableOfObjectToDateTime instance) => @@ -1256,13 +1183,12 @@ Map _$SimpleClassNullableOfObjectToDateTimeToJson( }; SimpleClassOfStringToDateTime _$SimpleClassOfStringToDateTimeFromJson( - Map json) { - return SimpleClassOfStringToDateTime( - (json['value'] as Map).map( - (k, e) => MapEntry(k, DateTime.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassOfStringToDateTime( + (json['value'] as Map).map( + (k, e) => MapEntry(k, DateTime.parse(e as String)), + ), + ); Map _$SimpleClassOfStringToDateTimeToJson( SimpleClassOfStringToDateTime instance) => @@ -1271,13 +1197,13 @@ Map _$SimpleClassOfStringToDateTimeToJson( }; SimpleClassNullableOfStringToDateTime - _$SimpleClassNullableOfStringToDateTimeFromJson(Map json) { - return SimpleClassNullableOfStringToDateTime( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(k, DateTime.parse(e as String)), - ), - ); -} + _$SimpleClassNullableOfStringToDateTimeFromJson( + Map json) => + SimpleClassNullableOfStringToDateTime( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, DateTime.parse(e as String)), + ), + ); Map _$SimpleClassNullableOfStringToDateTimeToJson( SimpleClassNullableOfStringToDateTime instance) => @@ -1286,13 +1212,12 @@ Map _$SimpleClassNullableOfStringToDateTimeToJson( }; SimpleClassOfUriToDateTime _$SimpleClassOfUriToDateTimeFromJson( - Map json) { - return SimpleClassOfUriToDateTime( - (json['value'] as Map).map( - (k, e) => MapEntry(Uri.parse(k), DateTime.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassOfUriToDateTime( + (json['value'] as Map).map( + (k, e) => MapEntry(Uri.parse(k), DateTime.parse(e as String)), + ), + ); Map _$SimpleClassOfUriToDateTimeToJson( SimpleClassOfUriToDateTime instance) => @@ -1302,13 +1227,12 @@ Map _$SimpleClassOfUriToDateTimeToJson( }; SimpleClassNullableOfUriToDateTime _$SimpleClassNullableOfUriToDateTimeFromJson( - Map json) { - return SimpleClassNullableOfUriToDateTime( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(Uri.parse(k), DateTime.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassNullableOfUriToDateTime( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(Uri.parse(k), DateTime.parse(e as String)), + ), + ); Map _$SimpleClassNullableOfUriToDateTimeToJson( SimpleClassNullableOfUriToDateTime instance) => @@ -1318,14 +1242,14 @@ Map _$SimpleClassNullableOfUriToDateTimeToJson( }; SimpleClassOfBigIntToDateTimeNullable - _$SimpleClassOfBigIntToDateTimeNullableFromJson(Map json) { - return SimpleClassOfBigIntToDateTimeNullable( - (json['value'] as Map).map( - (k, e) => MapEntry( - BigInt.parse(k), e == null ? null : DateTime.parse(e as String)), - ), - ); -} + _$SimpleClassOfBigIntToDateTimeNullableFromJson( + Map json) => + SimpleClassOfBigIntToDateTimeNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(BigInt.parse(k), + e == null ? null : DateTime.parse(e as String)), + ), + ); Map _$SimpleClassOfBigIntToDateTimeNullableToJson( SimpleClassOfBigIntToDateTimeNullable instance) => @@ -1336,14 +1260,13 @@ Map _$SimpleClassOfBigIntToDateTimeNullableToJson( SimpleClassNullableOfBigIntToDateTimeNullable _$SimpleClassNullableOfBigIntToDateTimeNullableFromJson( - Map json) { - return SimpleClassNullableOfBigIntToDateTimeNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry( - BigInt.parse(k), e == null ? null : DateTime.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassNullableOfBigIntToDateTimeNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(BigInt.parse(k), + e == null ? null : DateTime.parse(e as String)), + ), + ); Map _$SimpleClassNullableOfBigIntToDateTimeNullableToJson( SimpleClassNullableOfBigIntToDateTimeNullable instance) => @@ -1354,14 +1277,13 @@ Map _$SimpleClassNullableOfBigIntToDateTimeNullableToJson( SimpleClassOfDateTimeToDateTimeNullable _$SimpleClassOfDateTimeToDateTimeNullableFromJson( - Map json) { - return SimpleClassOfDateTimeToDateTimeNullable( - (json['value'] as Map).map( - (k, e) => MapEntry( - DateTime.parse(k), e == null ? null : DateTime.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassOfDateTimeToDateTimeNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(DateTime.parse(k), + e == null ? null : DateTime.parse(e as String)), + ), + ); Map _$SimpleClassOfDateTimeToDateTimeNullableToJson( SimpleClassOfDateTimeToDateTimeNullable instance) => @@ -1372,14 +1294,13 @@ Map _$SimpleClassOfDateTimeToDateTimeNullableToJson( SimpleClassNullableOfDateTimeToDateTimeNullable _$SimpleClassNullableOfDateTimeToDateTimeNullableFromJson( - Map json) { - return SimpleClassNullableOfDateTimeToDateTimeNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry( - DateTime.parse(k), e == null ? null : DateTime.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassNullableOfDateTimeToDateTimeNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(DateTime.parse(k), + e == null ? null : DateTime.parse(e as String)), + ), + ); Map _$SimpleClassNullableOfDateTimeToDateTimeNullableToJson( SimpleClassNullableOfDateTimeToDateTimeNullable instance) => @@ -1390,13 +1311,13 @@ Map _$SimpleClassNullableOfDateTimeToDateTimeNullableToJson( SimpleClassOfDynamicToDateTimeNullable _$SimpleClassOfDynamicToDateTimeNullableFromJson( - Map json) { - return SimpleClassOfDynamicToDateTimeNullable( - (json['value'] as Map).map( - (k, e) => MapEntry(k, e == null ? null : DateTime.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassOfDynamicToDateTimeNullable( + (json['value'] as Map).map( + (k, e) => + MapEntry(k, e == null ? null : DateTime.parse(e as String)), + ), + ); Map _$SimpleClassOfDynamicToDateTimeNullableToJson( SimpleClassOfDynamicToDateTimeNullable instance) => @@ -1406,13 +1327,13 @@ Map _$SimpleClassOfDynamicToDateTimeNullableToJson( SimpleClassNullableOfDynamicToDateTimeNullable _$SimpleClassNullableOfDynamicToDateTimeNullableFromJson( - Map json) { - return SimpleClassNullableOfDynamicToDateTimeNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(k, e == null ? null : DateTime.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassNullableOfDynamicToDateTimeNullable( + (json['value'] as Map?)?.map( + (k, e) => + MapEntry(k, e == null ? null : DateTime.parse(e as String)), + ), + ); Map _$SimpleClassNullableOfDynamicToDateTimeNullableToJson( SimpleClassNullableOfDynamicToDateTimeNullable instance) => @@ -1422,14 +1343,13 @@ Map _$SimpleClassNullableOfDynamicToDateTimeNullableToJson( SimpleClassOfEnumTypeToDateTimeNullable _$SimpleClassOfEnumTypeToDateTimeNullableFromJson( - Map json) { - return SimpleClassOfEnumTypeToDateTimeNullable( - (json['value'] as Map).map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), - e == null ? null : DateTime.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassOfEnumTypeToDateTimeNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), + e == null ? null : DateTime.parse(e as String)), + ), + ); Map _$SimpleClassOfEnumTypeToDateTimeNullableToJson( SimpleClassOfEnumTypeToDateTimeNullable instance) => @@ -1440,14 +1360,13 @@ Map _$SimpleClassOfEnumTypeToDateTimeNullableToJson( SimpleClassNullableOfEnumTypeToDateTimeNullable _$SimpleClassNullableOfEnumTypeToDateTimeNullableFromJson( - Map json) { - return SimpleClassNullableOfEnumTypeToDateTimeNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), - e == null ? null : DateTime.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassNullableOfEnumTypeToDateTimeNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), + e == null ? null : DateTime.parse(e as String)), + ), + ); Map _$SimpleClassNullableOfEnumTypeToDateTimeNullableToJson( SimpleClassNullableOfEnumTypeToDateTimeNullable instance) => @@ -1457,14 +1376,13 @@ Map _$SimpleClassNullableOfEnumTypeToDateTimeNullableToJson( }; SimpleClassOfIntToDateTimeNullable _$SimpleClassOfIntToDateTimeNullableFromJson( - Map json) { - return SimpleClassOfIntToDateTimeNullable( - (json['value'] as Map).map( - (k, e) => MapEntry( - int.parse(k), e == null ? null : DateTime.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassOfIntToDateTimeNullable( + (json['value'] as Map).map( + (k, e) => MapEntry( + int.parse(k), e == null ? null : DateTime.parse(e as String)), + ), + ); Map _$SimpleClassOfIntToDateTimeNullableToJson( SimpleClassOfIntToDateTimeNullable instance) => @@ -1475,14 +1393,13 @@ Map _$SimpleClassOfIntToDateTimeNullableToJson( SimpleClassNullableOfIntToDateTimeNullable _$SimpleClassNullableOfIntToDateTimeNullableFromJson( - Map json) { - return SimpleClassNullableOfIntToDateTimeNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry( - int.parse(k), e == null ? null : DateTime.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassNullableOfIntToDateTimeNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry( + int.parse(k), e == null ? null : DateTime.parse(e as String)), + ), + ); Map _$SimpleClassNullableOfIntToDateTimeNullableToJson( SimpleClassNullableOfIntToDateTimeNullable instance) => @@ -1492,13 +1409,14 @@ Map _$SimpleClassNullableOfIntToDateTimeNullableToJson( }; SimpleClassOfObjectToDateTimeNullable - _$SimpleClassOfObjectToDateTimeNullableFromJson(Map json) { - return SimpleClassOfObjectToDateTimeNullable( - (json['value'] as Map).map( - (k, e) => MapEntry(k, e == null ? null : DateTime.parse(e as String)), - ), - ); -} + _$SimpleClassOfObjectToDateTimeNullableFromJson( + Map json) => + SimpleClassOfObjectToDateTimeNullable( + (json['value'] as Map).map( + (k, e) => + MapEntry(k, e == null ? null : DateTime.parse(e as String)), + ), + ); Map _$SimpleClassOfObjectToDateTimeNullableToJson( SimpleClassOfObjectToDateTimeNullable instance) => @@ -1508,13 +1426,13 @@ Map _$SimpleClassOfObjectToDateTimeNullableToJson( SimpleClassNullableOfObjectToDateTimeNullable _$SimpleClassNullableOfObjectToDateTimeNullableFromJson( - Map json) { - return SimpleClassNullableOfObjectToDateTimeNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(k, e == null ? null : DateTime.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassNullableOfObjectToDateTimeNullable( + (json['value'] as Map?)?.map( + (k, e) => + MapEntry(k, e == null ? null : DateTime.parse(e as String)), + ), + ); Map _$SimpleClassNullableOfObjectToDateTimeNullableToJson( SimpleClassNullableOfObjectToDateTimeNullable instance) => @@ -1523,13 +1441,14 @@ Map _$SimpleClassNullableOfObjectToDateTimeNullableToJson( }; SimpleClassOfStringToDateTimeNullable - _$SimpleClassOfStringToDateTimeNullableFromJson(Map json) { - return SimpleClassOfStringToDateTimeNullable( - (json['value'] as Map).map( - (k, e) => MapEntry(k, e == null ? null : DateTime.parse(e as String)), - ), - ); -} + _$SimpleClassOfStringToDateTimeNullableFromJson( + Map json) => + SimpleClassOfStringToDateTimeNullable( + (json['value'] as Map).map( + (k, e) => + MapEntry(k, e == null ? null : DateTime.parse(e as String)), + ), + ); Map _$SimpleClassOfStringToDateTimeNullableToJson( SimpleClassOfStringToDateTimeNullable instance) => @@ -1539,13 +1458,13 @@ Map _$SimpleClassOfStringToDateTimeNullableToJson( SimpleClassNullableOfStringToDateTimeNullable _$SimpleClassNullableOfStringToDateTimeNullableFromJson( - Map json) { - return SimpleClassNullableOfStringToDateTimeNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(k, e == null ? null : DateTime.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassNullableOfStringToDateTimeNullable( + (json['value'] as Map?)?.map( + (k, e) => + MapEntry(k, e == null ? null : DateTime.parse(e as String)), + ), + ); Map _$SimpleClassNullableOfStringToDateTimeNullableToJson( SimpleClassNullableOfStringToDateTimeNullable instance) => @@ -1554,14 +1473,13 @@ Map _$SimpleClassNullableOfStringToDateTimeNullableToJson( }; SimpleClassOfUriToDateTimeNullable _$SimpleClassOfUriToDateTimeNullableFromJson( - Map json) { - return SimpleClassOfUriToDateTimeNullable( - (json['value'] as Map).map( - (k, e) => MapEntry( - Uri.parse(k), e == null ? null : DateTime.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassOfUriToDateTimeNullable( + (json['value'] as Map).map( + (k, e) => MapEntry( + Uri.parse(k), e == null ? null : DateTime.parse(e as String)), + ), + ); Map _$SimpleClassOfUriToDateTimeNullableToJson( SimpleClassOfUriToDateTimeNullable instance) => @@ -1572,14 +1490,13 @@ Map _$SimpleClassOfUriToDateTimeNullableToJson( SimpleClassNullableOfUriToDateTimeNullable _$SimpleClassNullableOfUriToDateTimeNullableFromJson( - Map json) { - return SimpleClassNullableOfUriToDateTimeNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry( - Uri.parse(k), e == null ? null : DateTime.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassNullableOfUriToDateTimeNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry( + Uri.parse(k), e == null ? null : DateTime.parse(e as String)), + ), + ); Map _$SimpleClassNullableOfUriToDateTimeNullableToJson( SimpleClassNullableOfUriToDateTimeNullable instance) => @@ -1589,13 +1506,12 @@ Map _$SimpleClassNullableOfUriToDateTimeNullableToJson( }; SimpleClassOfBigIntToDouble _$SimpleClassOfBigIntToDoubleFromJson( - Map json) { - return SimpleClassOfBigIntToDouble( - (json['value'] as Map).map( - (k, e) => MapEntry(BigInt.parse(k), (e as num).toDouble()), - ), - ); -} + Map json) => + SimpleClassOfBigIntToDouble( + (json['value'] as Map).map( + (k, e) => MapEntry(BigInt.parse(k), (e as num).toDouble()), + ), + ); Map _$SimpleClassOfBigIntToDoubleToJson( SimpleClassOfBigIntToDouble instance) => @@ -1604,13 +1520,12 @@ Map _$SimpleClassOfBigIntToDoubleToJson( }; SimpleClassNullableOfBigIntToDouble - _$SimpleClassNullableOfBigIntToDoubleFromJson(Map json) { - return SimpleClassNullableOfBigIntToDouble( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(BigInt.parse(k), (e as num).toDouble()), - ), - ); -} + _$SimpleClassNullableOfBigIntToDoubleFromJson(Map json) => + SimpleClassNullableOfBigIntToDouble( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(BigInt.parse(k), (e as num).toDouble()), + ), + ); Map _$SimpleClassNullableOfBigIntToDoubleToJson( SimpleClassNullableOfBigIntToDouble instance) => @@ -1619,13 +1534,12 @@ Map _$SimpleClassNullableOfBigIntToDoubleToJson( }; SimpleClassOfDateTimeToDouble _$SimpleClassOfDateTimeToDoubleFromJson( - Map json) { - return SimpleClassOfDateTimeToDouble( - (json['value'] as Map).map( - (k, e) => MapEntry(DateTime.parse(k), (e as num).toDouble()), - ), - ); -} + Map json) => + SimpleClassOfDateTimeToDouble( + (json['value'] as Map).map( + (k, e) => MapEntry(DateTime.parse(k), (e as num).toDouble()), + ), + ); Map _$SimpleClassOfDateTimeToDoubleToJson( SimpleClassOfDateTimeToDouble instance) => @@ -1634,13 +1548,13 @@ Map _$SimpleClassOfDateTimeToDoubleToJson( }; SimpleClassNullableOfDateTimeToDouble - _$SimpleClassNullableOfDateTimeToDoubleFromJson(Map json) { - return SimpleClassNullableOfDateTimeToDouble( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(DateTime.parse(k), (e as num).toDouble()), - ), - ); -} + _$SimpleClassNullableOfDateTimeToDoubleFromJson( + Map json) => + SimpleClassNullableOfDateTimeToDouble( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(DateTime.parse(k), (e as num).toDouble()), + ), + ); Map _$SimpleClassNullableOfDateTimeToDoubleToJson( SimpleClassNullableOfDateTimeToDouble instance) => @@ -1649,11 +1563,10 @@ Map _$SimpleClassNullableOfDateTimeToDoubleToJson( }; SimpleClassOfDynamicToDouble _$SimpleClassOfDynamicToDoubleFromJson( - Map json) { - return SimpleClassOfDynamicToDouble( - Map.from(json['value'] as Map), - ); -} + Map json) => + SimpleClassOfDynamicToDouble( + Map.from(json['value'] as Map), + ); Map _$SimpleClassOfDynamicToDoubleToJson( SimpleClassOfDynamicToDouble instance) => @@ -1662,13 +1575,12 @@ Map _$SimpleClassOfDynamicToDoubleToJson( }; SimpleClassNullableOfDynamicToDouble - _$SimpleClassNullableOfDynamicToDoubleFromJson(Map json) { - return SimpleClassNullableOfDynamicToDouble( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(k, (e as num).toDouble()), - ), - ); -} + _$SimpleClassNullableOfDynamicToDoubleFromJson(Map json) => + SimpleClassNullableOfDynamicToDouble( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, (e as num).toDouble()), + ), + ); Map _$SimpleClassNullableOfDynamicToDoubleToJson( SimpleClassNullableOfDynamicToDouble instance) => @@ -1677,14 +1589,13 @@ Map _$SimpleClassNullableOfDynamicToDoubleToJson( }; SimpleClassOfEnumTypeToDouble _$SimpleClassOfEnumTypeToDoubleFromJson( - Map json) { - return SimpleClassOfEnumTypeToDouble( - (json['value'] as Map).map( - (k, e) => - MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), (e as num).toDouble()), - ), - ); -} + Map json) => + SimpleClassOfEnumTypeToDouble( + (json['value'] as Map).map( + (k, e) => + MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), (e as num).toDouble()), + ), + ); Map _$SimpleClassOfEnumTypeToDoubleToJson( SimpleClassOfEnumTypeToDouble instance) => @@ -1693,14 +1604,14 @@ Map _$SimpleClassOfEnumTypeToDoubleToJson( }; SimpleClassNullableOfEnumTypeToDouble - _$SimpleClassNullableOfEnumTypeToDoubleFromJson(Map json) { - return SimpleClassNullableOfEnumTypeToDouble( - (json['value'] as Map?)?.map( - (k, e) => - MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), (e as num).toDouble()), - ), - ); -} + _$SimpleClassNullableOfEnumTypeToDoubleFromJson( + Map json) => + SimpleClassNullableOfEnumTypeToDouble( + (json['value'] as Map?)?.map( + (k, e) => MapEntry( + _$enumDecode(_$EnumTypeEnumMap, k), (e as num).toDouble()), + ), + ); Map _$SimpleClassNullableOfEnumTypeToDoubleToJson( SimpleClassNullableOfEnumTypeToDouble instance) => @@ -1709,13 +1620,12 @@ Map _$SimpleClassNullableOfEnumTypeToDoubleToJson( }; SimpleClassOfIntToDouble _$SimpleClassOfIntToDoubleFromJson( - Map json) { - return SimpleClassOfIntToDouble( - (json['value'] as Map).map( - (k, e) => MapEntry(int.parse(k), (e as num).toDouble()), - ), - ); -} + Map json) => + SimpleClassOfIntToDouble( + (json['value'] as Map).map( + (k, e) => MapEntry(int.parse(k), (e as num).toDouble()), + ), + ); Map _$SimpleClassOfIntToDoubleToJson( SimpleClassOfIntToDouble instance) => @@ -1724,13 +1634,12 @@ Map _$SimpleClassOfIntToDoubleToJson( }; SimpleClassNullableOfIntToDouble _$SimpleClassNullableOfIntToDoubleFromJson( - Map json) { - return SimpleClassNullableOfIntToDouble( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(int.parse(k), (e as num).toDouble()), - ), - ); -} + Map json) => + SimpleClassNullableOfIntToDouble( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(int.parse(k), (e as num).toDouble()), + ), + ); Map _$SimpleClassNullableOfIntToDoubleToJson( SimpleClassNullableOfIntToDouble instance) => @@ -1739,11 +1648,10 @@ Map _$SimpleClassNullableOfIntToDoubleToJson( }; SimpleClassOfObjectToDouble _$SimpleClassOfObjectToDoubleFromJson( - Map json) { - return SimpleClassOfObjectToDouble( - Map.from(json['value'] as Map), - ); -} + Map json) => + SimpleClassOfObjectToDouble( + Map.from(json['value'] as Map), + ); Map _$SimpleClassOfObjectToDoubleToJson( SimpleClassOfObjectToDouble instance) => @@ -1752,13 +1660,12 @@ Map _$SimpleClassOfObjectToDoubleToJson( }; SimpleClassNullableOfObjectToDouble - _$SimpleClassNullableOfObjectToDoubleFromJson(Map json) { - return SimpleClassNullableOfObjectToDouble( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(k, (e as num).toDouble()), - ), - ); -} + _$SimpleClassNullableOfObjectToDoubleFromJson(Map json) => + SimpleClassNullableOfObjectToDouble( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, (e as num).toDouble()), + ), + ); Map _$SimpleClassNullableOfObjectToDoubleToJson( SimpleClassNullableOfObjectToDouble instance) => @@ -1767,11 +1674,10 @@ Map _$SimpleClassNullableOfObjectToDoubleToJson( }; SimpleClassOfStringToDouble _$SimpleClassOfStringToDoubleFromJson( - Map json) { - return SimpleClassOfStringToDouble( - Map.from(json['value'] as Map), - ); -} + Map json) => + SimpleClassOfStringToDouble( + Map.from(json['value'] as Map), + ); Map _$SimpleClassOfStringToDoubleToJson( SimpleClassOfStringToDouble instance) => @@ -1780,13 +1686,12 @@ Map _$SimpleClassOfStringToDoubleToJson( }; SimpleClassNullableOfStringToDouble - _$SimpleClassNullableOfStringToDoubleFromJson(Map json) { - return SimpleClassNullableOfStringToDouble( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(k, (e as num).toDouble()), - ), - ); -} + _$SimpleClassNullableOfStringToDoubleFromJson(Map json) => + SimpleClassNullableOfStringToDouble( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, (e as num).toDouble()), + ), + ); Map _$SimpleClassNullableOfStringToDoubleToJson( SimpleClassNullableOfStringToDouble instance) => @@ -1795,13 +1700,12 @@ Map _$SimpleClassNullableOfStringToDoubleToJson( }; SimpleClassOfUriToDouble _$SimpleClassOfUriToDoubleFromJson( - Map json) { - return SimpleClassOfUriToDouble( - (json['value'] as Map).map( - (k, e) => MapEntry(Uri.parse(k), (e as num).toDouble()), - ), - ); -} + Map json) => + SimpleClassOfUriToDouble( + (json['value'] as Map).map( + (k, e) => MapEntry(Uri.parse(k), (e as num).toDouble()), + ), + ); Map _$SimpleClassOfUriToDoubleToJson( SimpleClassOfUriToDouble instance) => @@ -1810,13 +1714,12 @@ Map _$SimpleClassOfUriToDoubleToJson( }; SimpleClassNullableOfUriToDouble _$SimpleClassNullableOfUriToDoubleFromJson( - Map json) { - return SimpleClassNullableOfUriToDouble( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(Uri.parse(k), (e as num).toDouble()), - ), - ); -} + Map json) => + SimpleClassNullableOfUriToDouble( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(Uri.parse(k), (e as num).toDouble()), + ), + ); Map _$SimpleClassNullableOfUriToDoubleToJson( SimpleClassNullableOfUriToDouble instance) => @@ -1825,13 +1728,12 @@ Map _$SimpleClassNullableOfUriToDoubleToJson( }; SimpleClassOfBigIntToDoubleNullable - _$SimpleClassOfBigIntToDoubleNullableFromJson(Map json) { - return SimpleClassOfBigIntToDoubleNullable( - (json['value'] as Map).map( - (k, e) => MapEntry(BigInt.parse(k), (e as num?)?.toDouble()), - ), - ); -} + _$SimpleClassOfBigIntToDoubleNullableFromJson(Map json) => + SimpleClassOfBigIntToDoubleNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(BigInt.parse(k), (e as num?)?.toDouble()), + ), + ); Map _$SimpleClassOfBigIntToDoubleNullableToJson( SimpleClassOfBigIntToDoubleNullable instance) => @@ -1841,13 +1743,12 @@ Map _$SimpleClassOfBigIntToDoubleNullableToJson( SimpleClassNullableOfBigIntToDoubleNullable _$SimpleClassNullableOfBigIntToDoubleNullableFromJson( - Map json) { - return SimpleClassNullableOfBigIntToDoubleNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(BigInt.parse(k), (e as num?)?.toDouble()), - ), - ); -} + Map json) => + SimpleClassNullableOfBigIntToDoubleNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(BigInt.parse(k), (e as num?)?.toDouble()), + ), + ); Map _$SimpleClassNullableOfBigIntToDoubleNullableToJson( SimpleClassNullableOfBigIntToDoubleNullable instance) => @@ -1856,13 +1757,13 @@ Map _$SimpleClassNullableOfBigIntToDoubleNullableToJson( }; SimpleClassOfDateTimeToDoubleNullable - _$SimpleClassOfDateTimeToDoubleNullableFromJson(Map json) { - return SimpleClassOfDateTimeToDoubleNullable( - (json['value'] as Map).map( - (k, e) => MapEntry(DateTime.parse(k), (e as num?)?.toDouble()), - ), - ); -} + _$SimpleClassOfDateTimeToDoubleNullableFromJson( + Map json) => + SimpleClassOfDateTimeToDoubleNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(DateTime.parse(k), (e as num?)?.toDouble()), + ), + ); Map _$SimpleClassOfDateTimeToDoubleNullableToJson( SimpleClassOfDateTimeToDoubleNullable instance) => @@ -1872,13 +1773,12 @@ Map _$SimpleClassOfDateTimeToDoubleNullableToJson( SimpleClassNullableOfDateTimeToDoubleNullable _$SimpleClassNullableOfDateTimeToDoubleNullableFromJson( - Map json) { - return SimpleClassNullableOfDateTimeToDoubleNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(DateTime.parse(k), (e as num?)?.toDouble()), - ), - ); -} + Map json) => + SimpleClassNullableOfDateTimeToDoubleNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(DateTime.parse(k), (e as num?)?.toDouble()), + ), + ); Map _$SimpleClassNullableOfDateTimeToDoubleNullableToJson( SimpleClassNullableOfDateTimeToDoubleNullable instance) => @@ -1887,11 +1787,10 @@ Map _$SimpleClassNullableOfDateTimeToDoubleNullableToJson( }; SimpleClassOfDynamicToDoubleNullable - _$SimpleClassOfDynamicToDoubleNullableFromJson(Map json) { - return SimpleClassOfDynamicToDoubleNullable( - Map.from(json['value'] as Map), - ); -} + _$SimpleClassOfDynamicToDoubleNullableFromJson(Map json) => + SimpleClassOfDynamicToDoubleNullable( + Map.from(json['value'] as Map), + ); Map _$SimpleClassOfDynamicToDoubleNullableToJson( SimpleClassOfDynamicToDoubleNullable instance) => @@ -1901,13 +1800,12 @@ Map _$SimpleClassOfDynamicToDoubleNullableToJson( SimpleClassNullableOfDynamicToDoubleNullable _$SimpleClassNullableOfDynamicToDoubleNullableFromJson( - Map json) { - return SimpleClassNullableOfDynamicToDoubleNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(k, (e as num?)?.toDouble()), - ), - ); -} + Map json) => + SimpleClassNullableOfDynamicToDoubleNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, (e as num?)?.toDouble()), + ), + ); Map _$SimpleClassNullableOfDynamicToDoubleNullableToJson( SimpleClassNullableOfDynamicToDoubleNullable instance) => @@ -1916,14 +1814,14 @@ Map _$SimpleClassNullableOfDynamicToDoubleNullableToJson( }; SimpleClassOfEnumTypeToDoubleNullable - _$SimpleClassOfEnumTypeToDoubleNullableFromJson(Map json) { - return SimpleClassOfEnumTypeToDoubleNullable( - (json['value'] as Map).map( - (k, e) => - MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), (e as num?)?.toDouble()), - ), - ); -} + _$SimpleClassOfEnumTypeToDoubleNullableFromJson( + Map json) => + SimpleClassOfEnumTypeToDoubleNullable( + (json['value'] as Map).map( + (k, e) => MapEntry( + _$enumDecode(_$EnumTypeEnumMap, k), (e as num?)?.toDouble()), + ), + ); Map _$SimpleClassOfEnumTypeToDoubleNullableToJson( SimpleClassOfEnumTypeToDoubleNullable instance) => @@ -1933,14 +1831,13 @@ Map _$SimpleClassOfEnumTypeToDoubleNullableToJson( SimpleClassNullableOfEnumTypeToDoubleNullable _$SimpleClassNullableOfEnumTypeToDoubleNullableFromJson( - Map json) { - return SimpleClassNullableOfEnumTypeToDoubleNullable( - (json['value'] as Map?)?.map( - (k, e) => - MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), (e as num?)?.toDouble()), - ), - ); -} + Map json) => + SimpleClassNullableOfEnumTypeToDoubleNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry( + _$enumDecode(_$EnumTypeEnumMap, k), (e as num?)?.toDouble()), + ), + ); Map _$SimpleClassNullableOfEnumTypeToDoubleNullableToJson( SimpleClassNullableOfEnumTypeToDoubleNullable instance) => @@ -1949,13 +1846,12 @@ Map _$SimpleClassNullableOfEnumTypeToDoubleNullableToJson( }; SimpleClassOfIntToDoubleNullable _$SimpleClassOfIntToDoubleNullableFromJson( - Map json) { - return SimpleClassOfIntToDoubleNullable( - (json['value'] as Map).map( - (k, e) => MapEntry(int.parse(k), (e as num?)?.toDouble()), - ), - ); -} + Map json) => + SimpleClassOfIntToDoubleNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(int.parse(k), (e as num?)?.toDouble()), + ), + ); Map _$SimpleClassOfIntToDoubleNullableToJson( SimpleClassOfIntToDoubleNullable instance) => @@ -1965,13 +1861,12 @@ Map _$SimpleClassOfIntToDoubleNullableToJson( SimpleClassNullableOfIntToDoubleNullable _$SimpleClassNullableOfIntToDoubleNullableFromJson( - Map json) { - return SimpleClassNullableOfIntToDoubleNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(int.parse(k), (e as num?)?.toDouble()), - ), - ); -} + Map json) => + SimpleClassNullableOfIntToDoubleNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(int.parse(k), (e as num?)?.toDouble()), + ), + ); Map _$SimpleClassNullableOfIntToDoubleNullableToJson( SimpleClassNullableOfIntToDoubleNullable instance) => @@ -1980,11 +1875,10 @@ Map _$SimpleClassNullableOfIntToDoubleNullableToJson( }; SimpleClassOfObjectToDoubleNullable - _$SimpleClassOfObjectToDoubleNullableFromJson(Map json) { - return SimpleClassOfObjectToDoubleNullable( - Map.from(json['value'] as Map), - ); -} + _$SimpleClassOfObjectToDoubleNullableFromJson(Map json) => + SimpleClassOfObjectToDoubleNullable( + Map.from(json['value'] as Map), + ); Map _$SimpleClassOfObjectToDoubleNullableToJson( SimpleClassOfObjectToDoubleNullable instance) => @@ -1994,13 +1888,12 @@ Map _$SimpleClassOfObjectToDoubleNullableToJson( SimpleClassNullableOfObjectToDoubleNullable _$SimpleClassNullableOfObjectToDoubleNullableFromJson( - Map json) { - return SimpleClassNullableOfObjectToDoubleNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(k, (e as num?)?.toDouble()), - ), - ); -} + Map json) => + SimpleClassNullableOfObjectToDoubleNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, (e as num?)?.toDouble()), + ), + ); Map _$SimpleClassNullableOfObjectToDoubleNullableToJson( SimpleClassNullableOfObjectToDoubleNullable instance) => @@ -2009,11 +1902,10 @@ Map _$SimpleClassNullableOfObjectToDoubleNullableToJson( }; SimpleClassOfStringToDoubleNullable - _$SimpleClassOfStringToDoubleNullableFromJson(Map json) { - return SimpleClassOfStringToDoubleNullable( - Map.from(json['value'] as Map), - ); -} + _$SimpleClassOfStringToDoubleNullableFromJson(Map json) => + SimpleClassOfStringToDoubleNullable( + Map.from(json['value'] as Map), + ); Map _$SimpleClassOfStringToDoubleNullableToJson( SimpleClassOfStringToDoubleNullable instance) => @@ -2023,13 +1915,12 @@ Map _$SimpleClassOfStringToDoubleNullableToJson( SimpleClassNullableOfStringToDoubleNullable _$SimpleClassNullableOfStringToDoubleNullableFromJson( - Map json) { - return SimpleClassNullableOfStringToDoubleNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(k, (e as num?)?.toDouble()), - ), - ); -} + Map json) => + SimpleClassNullableOfStringToDoubleNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, (e as num?)?.toDouble()), + ), + ); Map _$SimpleClassNullableOfStringToDoubleNullableToJson( SimpleClassNullableOfStringToDoubleNullable instance) => @@ -2038,13 +1929,12 @@ Map _$SimpleClassNullableOfStringToDoubleNullableToJson( }; SimpleClassOfUriToDoubleNullable _$SimpleClassOfUriToDoubleNullableFromJson( - Map json) { - return SimpleClassOfUriToDoubleNullable( - (json['value'] as Map).map( - (k, e) => MapEntry(Uri.parse(k), (e as num?)?.toDouble()), - ), - ); -} + Map json) => + SimpleClassOfUriToDoubleNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(Uri.parse(k), (e as num?)?.toDouble()), + ), + ); Map _$SimpleClassOfUriToDoubleNullableToJson( SimpleClassOfUriToDoubleNullable instance) => @@ -2054,13 +1944,12 @@ Map _$SimpleClassOfUriToDoubleNullableToJson( SimpleClassNullableOfUriToDoubleNullable _$SimpleClassNullableOfUriToDoubleNullableFromJson( - Map json) { - return SimpleClassNullableOfUriToDoubleNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(Uri.parse(k), (e as num?)?.toDouble()), - ), - ); -} + Map json) => + SimpleClassNullableOfUriToDoubleNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(Uri.parse(k), (e as num?)?.toDouble()), + ), + ); Map _$SimpleClassNullableOfUriToDoubleNullableToJson( SimpleClassNullableOfUriToDoubleNullable instance) => @@ -2069,13 +1958,12 @@ Map _$SimpleClassNullableOfUriToDoubleNullableToJson( }; SimpleClassOfBigIntToDuration _$SimpleClassOfBigIntToDurationFromJson( - Map json) { - return SimpleClassOfBigIntToDuration( - (json['value'] as Map).map( - (k, e) => MapEntry(BigInt.parse(k), Duration(microseconds: e as int)), - ), - ); -} + Map json) => + SimpleClassOfBigIntToDuration( + (json['value'] as Map).map( + (k, e) => MapEntry(BigInt.parse(k), Duration(microseconds: e as int)), + ), + ); Map _$SimpleClassOfBigIntToDurationToJson( SimpleClassOfBigIntToDuration instance) => @@ -2085,13 +1973,14 @@ Map _$SimpleClassOfBigIntToDurationToJson( }; SimpleClassNullableOfBigIntToDuration - _$SimpleClassNullableOfBigIntToDurationFromJson(Map json) { - return SimpleClassNullableOfBigIntToDuration( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(BigInt.parse(k), Duration(microseconds: e as int)), - ), - ); -} + _$SimpleClassNullableOfBigIntToDurationFromJson( + Map json) => + SimpleClassNullableOfBigIntToDuration( + (json['value'] as Map?)?.map( + (k, e) => + MapEntry(BigInt.parse(k), Duration(microseconds: e as int)), + ), + ); Map _$SimpleClassNullableOfBigIntToDurationToJson( SimpleClassNullableOfBigIntToDuration instance) => @@ -2101,13 +1990,12 @@ Map _$SimpleClassNullableOfBigIntToDurationToJson( }; SimpleClassOfDateTimeToDuration _$SimpleClassOfDateTimeToDurationFromJson( - Map json) { - return SimpleClassOfDateTimeToDuration( - (json['value'] as Map).map( - (k, e) => MapEntry(DateTime.parse(k), Duration(microseconds: e as int)), - ), - ); -} + Map json) => + SimpleClassOfDateTimeToDuration( + (json['value'] as Map).map( + (k, e) => MapEntry(DateTime.parse(k), Duration(microseconds: e as int)), + ), + ); Map _$SimpleClassOfDateTimeToDurationToJson( SimpleClassOfDateTimeToDuration instance) => @@ -2118,13 +2006,13 @@ Map _$SimpleClassOfDateTimeToDurationToJson( SimpleClassNullableOfDateTimeToDuration _$SimpleClassNullableOfDateTimeToDurationFromJson( - Map json) { - return SimpleClassNullableOfDateTimeToDuration( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(DateTime.parse(k), Duration(microseconds: e as int)), - ), - ); -} + Map json) => + SimpleClassNullableOfDateTimeToDuration( + (json['value'] as Map?)?.map( + (k, e) => + MapEntry(DateTime.parse(k), Duration(microseconds: e as int)), + ), + ); Map _$SimpleClassNullableOfDateTimeToDurationToJson( SimpleClassNullableOfDateTimeToDuration instance) => @@ -2134,13 +2022,12 @@ Map _$SimpleClassNullableOfDateTimeToDurationToJson( }; SimpleClassOfDynamicToDuration _$SimpleClassOfDynamicToDurationFromJson( - Map json) { - return SimpleClassOfDynamicToDuration( - (json['value'] as Map).map( - (k, e) => MapEntry(k, Duration(microseconds: e as int)), - ), - ); -} + Map json) => + SimpleClassOfDynamicToDuration( + (json['value'] as Map).map( + (k, e) => MapEntry(k, Duration(microseconds: e as int)), + ), + ); Map _$SimpleClassOfDynamicToDurationToJson( SimpleClassOfDynamicToDuration instance) => @@ -2150,13 +2037,12 @@ Map _$SimpleClassOfDynamicToDurationToJson( SimpleClassNullableOfDynamicToDuration _$SimpleClassNullableOfDynamicToDurationFromJson( - Map json) { - return SimpleClassNullableOfDynamicToDuration( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(k, Duration(microseconds: e as int)), - ), - ); -} + Map json) => + SimpleClassNullableOfDynamicToDuration( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, Duration(microseconds: e as int)), + ), + ); Map _$SimpleClassNullableOfDynamicToDurationToJson( SimpleClassNullableOfDynamicToDuration instance) => @@ -2165,14 +2051,13 @@ Map _$SimpleClassNullableOfDynamicToDurationToJson( }; SimpleClassOfEnumTypeToDuration _$SimpleClassOfEnumTypeToDurationFromJson( - Map json) { - return SimpleClassOfEnumTypeToDuration( - (json['value'] as Map).map( - (k, e) => MapEntry( - _$enumDecode(_$EnumTypeEnumMap, k), Duration(microseconds: e as int)), - ), - ); -} + Map json) => + SimpleClassOfEnumTypeToDuration( + (json['value'] as Map).map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), + Duration(microseconds: e as int)), + ), + ); Map _$SimpleClassOfEnumTypeToDurationToJson( SimpleClassOfEnumTypeToDuration instance) => @@ -2183,14 +2068,13 @@ Map _$SimpleClassOfEnumTypeToDurationToJson( SimpleClassNullableOfEnumTypeToDuration _$SimpleClassNullableOfEnumTypeToDurationFromJson( - Map json) { - return SimpleClassNullableOfEnumTypeToDuration( - (json['value'] as Map?)?.map( - (k, e) => MapEntry( - _$enumDecode(_$EnumTypeEnumMap, k), Duration(microseconds: e as int)), - ), - ); -} + Map json) => + SimpleClassNullableOfEnumTypeToDuration( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), + Duration(microseconds: e as int)), + ), + ); Map _$SimpleClassNullableOfEnumTypeToDurationToJson( SimpleClassNullableOfEnumTypeToDuration instance) => @@ -2200,13 +2084,12 @@ Map _$SimpleClassNullableOfEnumTypeToDurationToJson( }; SimpleClassOfIntToDuration _$SimpleClassOfIntToDurationFromJson( - Map json) { - return SimpleClassOfIntToDuration( - (json['value'] as Map).map( - (k, e) => MapEntry(int.parse(k), Duration(microseconds: e as int)), - ), - ); -} + Map json) => + SimpleClassOfIntToDuration( + (json['value'] as Map).map( + (k, e) => MapEntry(int.parse(k), Duration(microseconds: e as int)), + ), + ); Map _$SimpleClassOfIntToDurationToJson( SimpleClassOfIntToDuration instance) => @@ -2216,13 +2099,12 @@ Map _$SimpleClassOfIntToDurationToJson( }; SimpleClassNullableOfIntToDuration _$SimpleClassNullableOfIntToDurationFromJson( - Map json) { - return SimpleClassNullableOfIntToDuration( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(int.parse(k), Duration(microseconds: e as int)), - ), - ); -} + Map json) => + SimpleClassNullableOfIntToDuration( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(int.parse(k), Duration(microseconds: e as int)), + ), + ); Map _$SimpleClassNullableOfIntToDurationToJson( SimpleClassNullableOfIntToDuration instance) => @@ -2232,13 +2114,12 @@ Map _$SimpleClassNullableOfIntToDurationToJson( }; SimpleClassOfObjectToDuration _$SimpleClassOfObjectToDurationFromJson( - Map json) { - return SimpleClassOfObjectToDuration( - (json['value'] as Map).map( - (k, e) => MapEntry(k, Duration(microseconds: e as int)), - ), - ); -} + Map json) => + SimpleClassOfObjectToDuration( + (json['value'] as Map).map( + (k, e) => MapEntry(k, Duration(microseconds: e as int)), + ), + ); Map _$SimpleClassOfObjectToDurationToJson( SimpleClassOfObjectToDuration instance) => @@ -2247,13 +2128,13 @@ Map _$SimpleClassOfObjectToDurationToJson( }; SimpleClassNullableOfObjectToDuration - _$SimpleClassNullableOfObjectToDurationFromJson(Map json) { - return SimpleClassNullableOfObjectToDuration( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(k, Duration(microseconds: e as int)), - ), - ); -} + _$SimpleClassNullableOfObjectToDurationFromJson( + Map json) => + SimpleClassNullableOfObjectToDuration( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, Duration(microseconds: e as int)), + ), + ); Map _$SimpleClassNullableOfObjectToDurationToJson( SimpleClassNullableOfObjectToDuration instance) => @@ -2262,13 +2143,12 @@ Map _$SimpleClassNullableOfObjectToDurationToJson( }; SimpleClassOfStringToDuration _$SimpleClassOfStringToDurationFromJson( - Map json) { - return SimpleClassOfStringToDuration( - (json['value'] as Map).map( - (k, e) => MapEntry(k, Duration(microseconds: e as int)), - ), - ); -} + Map json) => + SimpleClassOfStringToDuration( + (json['value'] as Map).map( + (k, e) => MapEntry(k, Duration(microseconds: e as int)), + ), + ); Map _$SimpleClassOfStringToDurationToJson( SimpleClassOfStringToDuration instance) => @@ -2277,13 +2157,13 @@ Map _$SimpleClassOfStringToDurationToJson( }; SimpleClassNullableOfStringToDuration - _$SimpleClassNullableOfStringToDurationFromJson(Map json) { - return SimpleClassNullableOfStringToDuration( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(k, Duration(microseconds: e as int)), - ), - ); -} + _$SimpleClassNullableOfStringToDurationFromJson( + Map json) => + SimpleClassNullableOfStringToDuration( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, Duration(microseconds: e as int)), + ), + ); Map _$SimpleClassNullableOfStringToDurationToJson( SimpleClassNullableOfStringToDuration instance) => @@ -2292,13 +2172,12 @@ Map _$SimpleClassNullableOfStringToDurationToJson( }; SimpleClassOfUriToDuration _$SimpleClassOfUriToDurationFromJson( - Map json) { - return SimpleClassOfUriToDuration( - (json['value'] as Map).map( - (k, e) => MapEntry(Uri.parse(k), Duration(microseconds: e as int)), - ), - ); -} + Map json) => + SimpleClassOfUriToDuration( + (json['value'] as Map).map( + (k, e) => MapEntry(Uri.parse(k), Duration(microseconds: e as int)), + ), + ); Map _$SimpleClassOfUriToDurationToJson( SimpleClassOfUriToDuration instance) => @@ -2308,13 +2187,12 @@ Map _$SimpleClassOfUriToDurationToJson( }; SimpleClassNullableOfUriToDuration _$SimpleClassNullableOfUriToDurationFromJson( - Map json) { - return SimpleClassNullableOfUriToDuration( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(Uri.parse(k), Duration(microseconds: e as int)), - ), - ); -} + Map json) => + SimpleClassNullableOfUriToDuration( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(Uri.parse(k), Duration(microseconds: e as int)), + ), + ); Map _$SimpleClassNullableOfUriToDurationToJson( SimpleClassNullableOfUriToDuration instance) => @@ -2324,14 +2202,14 @@ Map _$SimpleClassNullableOfUriToDurationToJson( }; SimpleClassOfBigIntToDurationNullable - _$SimpleClassOfBigIntToDurationNullableFromJson(Map json) { - return SimpleClassOfBigIntToDurationNullable( - (json['value'] as Map).map( - (k, e) => MapEntry( - BigInt.parse(k), e == null ? null : Duration(microseconds: e as int)), - ), - ); -} + _$SimpleClassOfBigIntToDurationNullableFromJson( + Map json) => + SimpleClassOfBigIntToDurationNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(BigInt.parse(k), + e == null ? null : Duration(microseconds: e as int)), + ), + ); Map _$SimpleClassOfBigIntToDurationNullableToJson( SimpleClassOfBigIntToDurationNullable instance) => @@ -2342,14 +2220,13 @@ Map _$SimpleClassOfBigIntToDurationNullableToJson( SimpleClassNullableOfBigIntToDurationNullable _$SimpleClassNullableOfBigIntToDurationNullableFromJson( - Map json) { - return SimpleClassNullableOfBigIntToDurationNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry( - BigInt.parse(k), e == null ? null : Duration(microseconds: e as int)), - ), - ); -} + Map json) => + SimpleClassNullableOfBigIntToDurationNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(BigInt.parse(k), + e == null ? null : Duration(microseconds: e as int)), + ), + ); Map _$SimpleClassNullableOfBigIntToDurationNullableToJson( SimpleClassNullableOfBigIntToDurationNullable instance) => @@ -2360,14 +2237,13 @@ Map _$SimpleClassNullableOfBigIntToDurationNullableToJson( SimpleClassOfDateTimeToDurationNullable _$SimpleClassOfDateTimeToDurationNullableFromJson( - Map json) { - return SimpleClassOfDateTimeToDurationNullable( - (json['value'] as Map).map( - (k, e) => MapEntry(DateTime.parse(k), - e == null ? null : Duration(microseconds: e as int)), - ), - ); -} + Map json) => + SimpleClassOfDateTimeToDurationNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(DateTime.parse(k), + e == null ? null : Duration(microseconds: e as int)), + ), + ); Map _$SimpleClassOfDateTimeToDurationNullableToJson( SimpleClassOfDateTimeToDurationNullable instance) => @@ -2378,14 +2254,13 @@ Map _$SimpleClassOfDateTimeToDurationNullableToJson( SimpleClassNullableOfDateTimeToDurationNullable _$SimpleClassNullableOfDateTimeToDurationNullableFromJson( - Map json) { - return SimpleClassNullableOfDateTimeToDurationNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(DateTime.parse(k), - e == null ? null : Duration(microseconds: e as int)), - ), - ); -} + Map json) => + SimpleClassNullableOfDateTimeToDurationNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(DateTime.parse(k), + e == null ? null : Duration(microseconds: e as int)), + ), + ); Map _$SimpleClassNullableOfDateTimeToDurationNullableToJson( SimpleClassNullableOfDateTimeToDurationNullable instance) => @@ -2396,14 +2271,13 @@ Map _$SimpleClassNullableOfDateTimeToDurationNullableToJson( SimpleClassOfDynamicToDurationNullable _$SimpleClassOfDynamicToDurationNullableFromJson( - Map json) { - return SimpleClassOfDynamicToDurationNullable( - (json['value'] as Map).map( - (k, e) => - MapEntry(k, e == null ? null : Duration(microseconds: e as int)), - ), - ); -} + Map json) => + SimpleClassOfDynamicToDurationNullable( + (json['value'] as Map).map( + (k, e) => MapEntry( + k, e == null ? null : Duration(microseconds: e as int)), + ), + ); Map _$SimpleClassOfDynamicToDurationNullableToJson( SimpleClassOfDynamicToDurationNullable instance) => @@ -2413,14 +2287,13 @@ Map _$SimpleClassOfDynamicToDurationNullableToJson( SimpleClassNullableOfDynamicToDurationNullable _$SimpleClassNullableOfDynamicToDurationNullableFromJson( - Map json) { - return SimpleClassNullableOfDynamicToDurationNullable( - (json['value'] as Map?)?.map( - (k, e) => - MapEntry(k, e == null ? null : Duration(microseconds: e as int)), - ), - ); -} + Map json) => + SimpleClassNullableOfDynamicToDurationNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry( + k, e == null ? null : Duration(microseconds: e as int)), + ), + ); Map _$SimpleClassNullableOfDynamicToDurationNullableToJson( SimpleClassNullableOfDynamicToDurationNullable instance) => @@ -2430,14 +2303,13 @@ Map _$SimpleClassNullableOfDynamicToDurationNullableToJson( SimpleClassOfEnumTypeToDurationNullable _$SimpleClassOfEnumTypeToDurationNullableFromJson( - Map json) { - return SimpleClassOfEnumTypeToDurationNullable( - (json['value'] as Map).map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), - e == null ? null : Duration(microseconds: e as int)), - ), - ); -} + Map json) => + SimpleClassOfEnumTypeToDurationNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), + e == null ? null : Duration(microseconds: e as int)), + ), + ); Map _$SimpleClassOfEnumTypeToDurationNullableToJson( SimpleClassOfEnumTypeToDurationNullable instance) => @@ -2448,14 +2320,13 @@ Map _$SimpleClassOfEnumTypeToDurationNullableToJson( SimpleClassNullableOfEnumTypeToDurationNullable _$SimpleClassNullableOfEnumTypeToDurationNullableFromJson( - Map json) { - return SimpleClassNullableOfEnumTypeToDurationNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), - e == null ? null : Duration(microseconds: e as int)), - ), - ); -} + Map json) => + SimpleClassNullableOfEnumTypeToDurationNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), + e == null ? null : Duration(microseconds: e as int)), + ), + ); Map _$SimpleClassNullableOfEnumTypeToDurationNullableToJson( SimpleClassNullableOfEnumTypeToDurationNullable instance) => @@ -2465,14 +2336,13 @@ Map _$SimpleClassNullableOfEnumTypeToDurationNullableToJson( }; SimpleClassOfIntToDurationNullable _$SimpleClassOfIntToDurationNullableFromJson( - Map json) { - return SimpleClassOfIntToDurationNullable( - (json['value'] as Map).map( - (k, e) => MapEntry( - int.parse(k), e == null ? null : Duration(microseconds: e as int)), - ), - ); -} + Map json) => + SimpleClassOfIntToDurationNullable( + (json['value'] as Map).map( + (k, e) => MapEntry( + int.parse(k), e == null ? null : Duration(microseconds: e as int)), + ), + ); Map _$SimpleClassOfIntToDurationNullableToJson( SimpleClassOfIntToDurationNullable instance) => @@ -2483,14 +2353,13 @@ Map _$SimpleClassOfIntToDurationNullableToJson( SimpleClassNullableOfIntToDurationNullable _$SimpleClassNullableOfIntToDurationNullableFromJson( - Map json) { - return SimpleClassNullableOfIntToDurationNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry( - int.parse(k), e == null ? null : Duration(microseconds: e as int)), - ), - ); -} + Map json) => + SimpleClassNullableOfIntToDurationNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(int.parse(k), + e == null ? null : Duration(microseconds: e as int)), + ), + ); Map _$SimpleClassNullableOfIntToDurationNullableToJson( SimpleClassNullableOfIntToDurationNullable instance) => @@ -2500,14 +2369,14 @@ Map _$SimpleClassNullableOfIntToDurationNullableToJson( }; SimpleClassOfObjectToDurationNullable - _$SimpleClassOfObjectToDurationNullableFromJson(Map json) { - return SimpleClassOfObjectToDurationNullable( - (json['value'] as Map).map( - (k, e) => - MapEntry(k, e == null ? null : Duration(microseconds: e as int)), - ), - ); -} + _$SimpleClassOfObjectToDurationNullableFromJson( + Map json) => + SimpleClassOfObjectToDurationNullable( + (json['value'] as Map).map( + (k, e) => MapEntry( + k, e == null ? null : Duration(microseconds: e as int)), + ), + ); Map _$SimpleClassOfObjectToDurationNullableToJson( SimpleClassOfObjectToDurationNullable instance) => @@ -2517,14 +2386,13 @@ Map _$SimpleClassOfObjectToDurationNullableToJson( SimpleClassNullableOfObjectToDurationNullable _$SimpleClassNullableOfObjectToDurationNullableFromJson( - Map json) { - return SimpleClassNullableOfObjectToDurationNullable( - (json['value'] as Map?)?.map( - (k, e) => - MapEntry(k, e == null ? null : Duration(microseconds: e as int)), - ), - ); -} + Map json) => + SimpleClassNullableOfObjectToDurationNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry( + k, e == null ? null : Duration(microseconds: e as int)), + ), + ); Map _$SimpleClassNullableOfObjectToDurationNullableToJson( SimpleClassNullableOfObjectToDurationNullable instance) => @@ -2533,14 +2401,14 @@ Map _$SimpleClassNullableOfObjectToDurationNullableToJson( }; SimpleClassOfStringToDurationNullable - _$SimpleClassOfStringToDurationNullableFromJson(Map json) { - return SimpleClassOfStringToDurationNullable( - (json['value'] as Map).map( - (k, e) => - MapEntry(k, e == null ? null : Duration(microseconds: e as int)), - ), - ); -} + _$SimpleClassOfStringToDurationNullableFromJson( + Map json) => + SimpleClassOfStringToDurationNullable( + (json['value'] as Map).map( + (k, e) => MapEntry( + k, e == null ? null : Duration(microseconds: e as int)), + ), + ); Map _$SimpleClassOfStringToDurationNullableToJson( SimpleClassOfStringToDurationNullable instance) => @@ -2550,14 +2418,13 @@ Map _$SimpleClassOfStringToDurationNullableToJson( SimpleClassNullableOfStringToDurationNullable _$SimpleClassNullableOfStringToDurationNullableFromJson( - Map json) { - return SimpleClassNullableOfStringToDurationNullable( - (json['value'] as Map?)?.map( - (k, e) => - MapEntry(k, e == null ? null : Duration(microseconds: e as int)), - ), - ); -} + Map json) => + SimpleClassNullableOfStringToDurationNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry( + k, e == null ? null : Duration(microseconds: e as int)), + ), + ); Map _$SimpleClassNullableOfStringToDurationNullableToJson( SimpleClassNullableOfStringToDurationNullable instance) => @@ -2566,14 +2433,13 @@ Map _$SimpleClassNullableOfStringToDurationNullableToJson( }; SimpleClassOfUriToDurationNullable _$SimpleClassOfUriToDurationNullableFromJson( - Map json) { - return SimpleClassOfUriToDurationNullable( - (json['value'] as Map).map( - (k, e) => MapEntry( - Uri.parse(k), e == null ? null : Duration(microseconds: e as int)), - ), - ); -} + Map json) => + SimpleClassOfUriToDurationNullable( + (json['value'] as Map).map( + (k, e) => MapEntry( + Uri.parse(k), e == null ? null : Duration(microseconds: e as int)), + ), + ); Map _$SimpleClassOfUriToDurationNullableToJson( SimpleClassOfUriToDurationNullable instance) => @@ -2584,14 +2450,13 @@ Map _$SimpleClassOfUriToDurationNullableToJson( SimpleClassNullableOfUriToDurationNullable _$SimpleClassNullableOfUriToDurationNullableFromJson( - Map json) { - return SimpleClassNullableOfUriToDurationNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry( - Uri.parse(k), e == null ? null : Duration(microseconds: e as int)), - ), - ); -} + Map json) => + SimpleClassNullableOfUriToDurationNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(Uri.parse(k), + e == null ? null : Duration(microseconds: e as int)), + ), + ); Map _$SimpleClassNullableOfUriToDurationNullableToJson( SimpleClassNullableOfUriToDurationNullable instance) => @@ -2601,13 +2466,12 @@ Map _$SimpleClassNullableOfUriToDurationNullableToJson( }; SimpleClassOfBigIntToDynamic _$SimpleClassOfBigIntToDynamicFromJson( - Map json) { - return SimpleClassOfBigIntToDynamic( - (json['value'] as Map).map( - (k, e) => MapEntry(BigInt.parse(k), e), - ), - ); -} + Map json) => + SimpleClassOfBigIntToDynamic( + (json['value'] as Map).map( + (k, e) => MapEntry(BigInt.parse(k), e), + ), + ); Map _$SimpleClassOfBigIntToDynamicToJson( SimpleClassOfBigIntToDynamic instance) => @@ -2616,13 +2480,12 @@ Map _$SimpleClassOfBigIntToDynamicToJson( }; SimpleClassNullableOfBigIntToDynamic - _$SimpleClassNullableOfBigIntToDynamicFromJson(Map json) { - return SimpleClassNullableOfBigIntToDynamic( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(BigInt.parse(k), e), - ), - ); -} + _$SimpleClassNullableOfBigIntToDynamicFromJson(Map json) => + SimpleClassNullableOfBigIntToDynamic( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(BigInt.parse(k), e), + ), + ); Map _$SimpleClassNullableOfBigIntToDynamicToJson( SimpleClassNullableOfBigIntToDynamic instance) => @@ -2631,13 +2494,12 @@ Map _$SimpleClassNullableOfBigIntToDynamicToJson( }; SimpleClassOfDateTimeToDynamic _$SimpleClassOfDateTimeToDynamicFromJson( - Map json) { - return SimpleClassOfDateTimeToDynamic( - (json['value'] as Map).map( - (k, e) => MapEntry(DateTime.parse(k), e), - ), - ); -} + Map json) => + SimpleClassOfDateTimeToDynamic( + (json['value'] as Map).map( + (k, e) => MapEntry(DateTime.parse(k), e), + ), + ); Map _$SimpleClassOfDateTimeToDynamicToJson( SimpleClassOfDateTimeToDynamic instance) => @@ -2647,13 +2509,12 @@ Map _$SimpleClassOfDateTimeToDynamicToJson( SimpleClassNullableOfDateTimeToDynamic _$SimpleClassNullableOfDateTimeToDynamicFromJson( - Map json) { - return SimpleClassNullableOfDateTimeToDynamic( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(DateTime.parse(k), e), - ), - ); -} + Map json) => + SimpleClassNullableOfDateTimeToDynamic( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(DateTime.parse(k), e), + ), + ); Map _$SimpleClassNullableOfDateTimeToDynamicToJson( SimpleClassNullableOfDateTimeToDynamic instance) => @@ -2662,11 +2523,10 @@ Map _$SimpleClassNullableOfDateTimeToDynamicToJson( }; SimpleClassOfDynamicToDynamic _$SimpleClassOfDynamicToDynamicFromJson( - Map json) { - return SimpleClassOfDynamicToDynamic( - json['value'] as Map, - ); -} + Map json) => + SimpleClassOfDynamicToDynamic( + json['value'] as Map, + ); Map _$SimpleClassOfDynamicToDynamicToJson( SimpleClassOfDynamicToDynamic instance) => @@ -2675,11 +2535,11 @@ Map _$SimpleClassOfDynamicToDynamicToJson( }; SimpleClassNullableOfDynamicToDynamic - _$SimpleClassNullableOfDynamicToDynamicFromJson(Map json) { - return SimpleClassNullableOfDynamicToDynamic( - json['value'] as Map?, - ); -} + _$SimpleClassNullableOfDynamicToDynamicFromJson( + Map json) => + SimpleClassNullableOfDynamicToDynamic( + json['value'] as Map?, + ); Map _$SimpleClassNullableOfDynamicToDynamicToJson( SimpleClassNullableOfDynamicToDynamic instance) => @@ -2688,13 +2548,12 @@ Map _$SimpleClassNullableOfDynamicToDynamicToJson( }; SimpleClassOfEnumTypeToDynamic _$SimpleClassOfEnumTypeToDynamicFromJson( - Map json) { - return SimpleClassOfEnumTypeToDynamic( - (json['value'] as Map).map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e), - ), - ); -} + Map json) => + SimpleClassOfEnumTypeToDynamic( + (json['value'] as Map).map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e), + ), + ); Map _$SimpleClassOfEnumTypeToDynamicToJson( SimpleClassOfEnumTypeToDynamic instance) => @@ -2704,13 +2563,12 @@ Map _$SimpleClassOfEnumTypeToDynamicToJson( SimpleClassNullableOfEnumTypeToDynamic _$SimpleClassNullableOfEnumTypeToDynamicFromJson( - Map json) { - return SimpleClassNullableOfEnumTypeToDynamic( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e), - ), - ); -} + Map json) => + SimpleClassNullableOfEnumTypeToDynamic( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e), + ), + ); Map _$SimpleClassNullableOfEnumTypeToDynamicToJson( SimpleClassNullableOfEnumTypeToDynamic instance) => @@ -2719,13 +2577,12 @@ Map _$SimpleClassNullableOfEnumTypeToDynamicToJson( }; SimpleClassOfIntToDynamic _$SimpleClassOfIntToDynamicFromJson( - Map json) { - return SimpleClassOfIntToDynamic( - (json['value'] as Map).map( - (k, e) => MapEntry(int.parse(k), e), - ), - ); -} + Map json) => + SimpleClassOfIntToDynamic( + (json['value'] as Map).map( + (k, e) => MapEntry(int.parse(k), e), + ), + ); Map _$SimpleClassOfIntToDynamicToJson( SimpleClassOfIntToDynamic instance) => @@ -2734,13 +2591,12 @@ Map _$SimpleClassOfIntToDynamicToJson( }; SimpleClassNullableOfIntToDynamic _$SimpleClassNullableOfIntToDynamicFromJson( - Map json) { - return SimpleClassNullableOfIntToDynamic( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(int.parse(k), e), - ), - ); -} + Map json) => + SimpleClassNullableOfIntToDynamic( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(int.parse(k), e), + ), + ); Map _$SimpleClassNullableOfIntToDynamicToJson( SimpleClassNullableOfIntToDynamic instance) => @@ -2749,11 +2605,10 @@ Map _$SimpleClassNullableOfIntToDynamicToJson( }; SimpleClassOfObjectToDynamic _$SimpleClassOfObjectToDynamicFromJson( - Map json) { - return SimpleClassOfObjectToDynamic( - json['value'] as Map, - ); -} + Map json) => + SimpleClassOfObjectToDynamic( + json['value'] as Map, + ); Map _$SimpleClassOfObjectToDynamicToJson( SimpleClassOfObjectToDynamic instance) => @@ -2762,11 +2617,10 @@ Map _$SimpleClassOfObjectToDynamicToJson( }; SimpleClassNullableOfObjectToDynamic - _$SimpleClassNullableOfObjectToDynamicFromJson(Map json) { - return SimpleClassNullableOfObjectToDynamic( - json['value'] as Map?, - ); -} + _$SimpleClassNullableOfObjectToDynamicFromJson(Map json) => + SimpleClassNullableOfObjectToDynamic( + json['value'] as Map?, + ); Map _$SimpleClassNullableOfObjectToDynamicToJson( SimpleClassNullableOfObjectToDynamic instance) => @@ -2775,11 +2629,10 @@ Map _$SimpleClassNullableOfObjectToDynamicToJson( }; SimpleClassOfStringToDynamic _$SimpleClassOfStringToDynamicFromJson( - Map json) { - return SimpleClassOfStringToDynamic( - json['value'] as Map, - ); -} + Map json) => + SimpleClassOfStringToDynamic( + json['value'] as Map, + ); Map _$SimpleClassOfStringToDynamicToJson( SimpleClassOfStringToDynamic instance) => @@ -2788,11 +2641,10 @@ Map _$SimpleClassOfStringToDynamicToJson( }; SimpleClassNullableOfStringToDynamic - _$SimpleClassNullableOfStringToDynamicFromJson(Map json) { - return SimpleClassNullableOfStringToDynamic( - json['value'] as Map?, - ); -} + _$SimpleClassNullableOfStringToDynamicFromJson(Map json) => + SimpleClassNullableOfStringToDynamic( + json['value'] as Map?, + ); Map _$SimpleClassNullableOfStringToDynamicToJson( SimpleClassNullableOfStringToDynamic instance) => @@ -2801,13 +2653,12 @@ Map _$SimpleClassNullableOfStringToDynamicToJson( }; SimpleClassOfUriToDynamic _$SimpleClassOfUriToDynamicFromJson( - Map json) { - return SimpleClassOfUriToDynamic( - (json['value'] as Map).map( - (k, e) => MapEntry(Uri.parse(k), e), - ), - ); -} + Map json) => + SimpleClassOfUriToDynamic( + (json['value'] as Map).map( + (k, e) => MapEntry(Uri.parse(k), e), + ), + ); Map _$SimpleClassOfUriToDynamicToJson( SimpleClassOfUriToDynamic instance) => @@ -2816,13 +2667,12 @@ Map _$SimpleClassOfUriToDynamicToJson( }; SimpleClassNullableOfUriToDynamic _$SimpleClassNullableOfUriToDynamicFromJson( - Map json) { - return SimpleClassNullableOfUriToDynamic( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(Uri.parse(k), e), - ), - ); -} + Map json) => + SimpleClassNullableOfUriToDynamic( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(Uri.parse(k), e), + ), + ); Map _$SimpleClassNullableOfUriToDynamicToJson( SimpleClassNullableOfUriToDynamic instance) => @@ -2831,13 +2681,12 @@ Map _$SimpleClassNullableOfUriToDynamicToJson( }; SimpleClassOfBigIntToEnumType _$SimpleClassOfBigIntToEnumTypeFromJson( - Map json) { - return SimpleClassOfBigIntToEnumType( - (json['value'] as Map).map( - (k, e) => MapEntry(BigInt.parse(k), _$enumDecode(_$EnumTypeEnumMap, e)), - ), - ); -} + Map json) => + SimpleClassOfBigIntToEnumType( + (json['value'] as Map).map( + (k, e) => MapEntry(BigInt.parse(k), _$enumDecode(_$EnumTypeEnumMap, e)), + ), + ); Map _$SimpleClassOfBigIntToEnumTypeToJson( SimpleClassOfBigIntToEnumType instance) => @@ -2847,13 +2696,14 @@ Map _$SimpleClassOfBigIntToEnumTypeToJson( }; SimpleClassNullableOfBigIntToEnumType - _$SimpleClassNullableOfBigIntToEnumTypeFromJson(Map json) { - return SimpleClassNullableOfBigIntToEnumType( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(BigInt.parse(k), _$enumDecode(_$EnumTypeEnumMap, e)), - ), - ); -} + _$SimpleClassNullableOfBigIntToEnumTypeFromJson( + Map json) => + SimpleClassNullableOfBigIntToEnumType( + (json['value'] as Map?)?.map( + (k, e) => + MapEntry(BigInt.parse(k), _$enumDecode(_$EnumTypeEnumMap, e)), + ), + ); Map _$SimpleClassNullableOfBigIntToEnumTypeToJson( SimpleClassNullableOfBigIntToEnumType instance) => @@ -2863,13 +2713,13 @@ Map _$SimpleClassNullableOfBigIntToEnumTypeToJson( }; SimpleClassOfDateTimeToEnumType _$SimpleClassOfDateTimeToEnumTypeFromJson( - Map json) { - return SimpleClassOfDateTimeToEnumType( - (json['value'] as Map).map( - (k, e) => MapEntry(DateTime.parse(k), _$enumDecode(_$EnumTypeEnumMap, e)), - ), - ); -} + Map json) => + SimpleClassOfDateTimeToEnumType( + (json['value'] as Map).map( + (k, e) => + MapEntry(DateTime.parse(k), _$enumDecode(_$EnumTypeEnumMap, e)), + ), + ); Map _$SimpleClassOfDateTimeToEnumTypeToJson( SimpleClassOfDateTimeToEnumType instance) => @@ -2880,13 +2730,13 @@ Map _$SimpleClassOfDateTimeToEnumTypeToJson( SimpleClassNullableOfDateTimeToEnumType _$SimpleClassNullableOfDateTimeToEnumTypeFromJson( - Map json) { - return SimpleClassNullableOfDateTimeToEnumType( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(DateTime.parse(k), _$enumDecode(_$EnumTypeEnumMap, e)), - ), - ); -} + Map json) => + SimpleClassNullableOfDateTimeToEnumType( + (json['value'] as Map?)?.map( + (k, e) => + MapEntry(DateTime.parse(k), _$enumDecode(_$EnumTypeEnumMap, e)), + ), + ); Map _$SimpleClassNullableOfDateTimeToEnumTypeToJson( SimpleClassNullableOfDateTimeToEnumType instance) => @@ -2896,13 +2746,12 @@ Map _$SimpleClassNullableOfDateTimeToEnumTypeToJson( }; SimpleClassOfDynamicToEnumType _$SimpleClassOfDynamicToEnumTypeFromJson( - Map json) { - return SimpleClassOfDynamicToEnumType( - (json['value'] as Map).map( - (k, e) => MapEntry(k, _$enumDecode(_$EnumTypeEnumMap, e)), - ), - ); -} + Map json) => + SimpleClassOfDynamicToEnumType( + (json['value'] as Map).map( + (k, e) => MapEntry(k, _$enumDecode(_$EnumTypeEnumMap, e)), + ), + ); Map _$SimpleClassOfDynamicToEnumTypeToJson( SimpleClassOfDynamicToEnumType instance) => @@ -2912,13 +2761,12 @@ Map _$SimpleClassOfDynamicToEnumTypeToJson( SimpleClassNullableOfDynamicToEnumType _$SimpleClassNullableOfDynamicToEnumTypeFromJson( - Map json) { - return SimpleClassNullableOfDynamicToEnumType( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(k, _$enumDecode(_$EnumTypeEnumMap, e)), - ), - ); -} + Map json) => + SimpleClassNullableOfDynamicToEnumType( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, _$enumDecode(_$EnumTypeEnumMap, e)), + ), + ); Map _$SimpleClassNullableOfDynamicToEnumTypeToJson( SimpleClassNullableOfDynamicToEnumType instance) => @@ -2927,14 +2775,13 @@ Map _$SimpleClassNullableOfDynamicToEnumTypeToJson( }; SimpleClassOfEnumTypeToEnumType _$SimpleClassOfEnumTypeToEnumTypeFromJson( - Map json) { - return SimpleClassOfEnumTypeToEnumType( - (json['value'] as Map).map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), - _$enumDecode(_$EnumTypeEnumMap, e)), - ), - ); -} + Map json) => + SimpleClassOfEnumTypeToEnumType( + (json['value'] as Map).map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), + _$enumDecode(_$EnumTypeEnumMap, e)), + ), + ); Map _$SimpleClassOfEnumTypeToEnumTypeToJson( SimpleClassOfEnumTypeToEnumType instance) => @@ -2945,14 +2792,13 @@ Map _$SimpleClassOfEnumTypeToEnumTypeToJson( SimpleClassNullableOfEnumTypeToEnumType _$SimpleClassNullableOfEnumTypeToEnumTypeFromJson( - Map json) { - return SimpleClassNullableOfEnumTypeToEnumType( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), - _$enumDecode(_$EnumTypeEnumMap, e)), - ), - ); -} + Map json) => + SimpleClassNullableOfEnumTypeToEnumType( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), + _$enumDecode(_$EnumTypeEnumMap, e)), + ), + ); Map _$SimpleClassNullableOfEnumTypeToEnumTypeToJson( SimpleClassNullableOfEnumTypeToEnumType instance) => @@ -2962,13 +2808,12 @@ Map _$SimpleClassNullableOfEnumTypeToEnumTypeToJson( }; SimpleClassOfIntToEnumType _$SimpleClassOfIntToEnumTypeFromJson( - Map json) { - return SimpleClassOfIntToEnumType( - (json['value'] as Map).map( - (k, e) => MapEntry(int.parse(k), _$enumDecode(_$EnumTypeEnumMap, e)), - ), - ); -} + Map json) => + SimpleClassOfIntToEnumType( + (json['value'] as Map).map( + (k, e) => MapEntry(int.parse(k), _$enumDecode(_$EnumTypeEnumMap, e)), + ), + ); Map _$SimpleClassOfIntToEnumTypeToJson( SimpleClassOfIntToEnumType instance) => @@ -2978,13 +2823,12 @@ Map _$SimpleClassOfIntToEnumTypeToJson( }; SimpleClassNullableOfIntToEnumType _$SimpleClassNullableOfIntToEnumTypeFromJson( - Map json) { - return SimpleClassNullableOfIntToEnumType( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(int.parse(k), _$enumDecode(_$EnumTypeEnumMap, e)), - ), - ); -} + Map json) => + SimpleClassNullableOfIntToEnumType( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(int.parse(k), _$enumDecode(_$EnumTypeEnumMap, e)), + ), + ); Map _$SimpleClassNullableOfIntToEnumTypeToJson( SimpleClassNullableOfIntToEnumType instance) => @@ -2994,13 +2838,12 @@ Map _$SimpleClassNullableOfIntToEnumTypeToJson( }; SimpleClassOfObjectToEnumType _$SimpleClassOfObjectToEnumTypeFromJson( - Map json) { - return SimpleClassOfObjectToEnumType( - (json['value'] as Map).map( - (k, e) => MapEntry(k, _$enumDecode(_$EnumTypeEnumMap, e)), - ), - ); -} + Map json) => + SimpleClassOfObjectToEnumType( + (json['value'] as Map).map( + (k, e) => MapEntry(k, _$enumDecode(_$EnumTypeEnumMap, e)), + ), + ); Map _$SimpleClassOfObjectToEnumTypeToJson( SimpleClassOfObjectToEnumType instance) => @@ -3009,13 +2852,13 @@ Map _$SimpleClassOfObjectToEnumTypeToJson( }; SimpleClassNullableOfObjectToEnumType - _$SimpleClassNullableOfObjectToEnumTypeFromJson(Map json) { - return SimpleClassNullableOfObjectToEnumType( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(k, _$enumDecode(_$EnumTypeEnumMap, e)), - ), - ); -} + _$SimpleClassNullableOfObjectToEnumTypeFromJson( + Map json) => + SimpleClassNullableOfObjectToEnumType( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, _$enumDecode(_$EnumTypeEnumMap, e)), + ), + ); Map _$SimpleClassNullableOfObjectToEnumTypeToJson( SimpleClassNullableOfObjectToEnumType instance) => @@ -3024,13 +2867,12 @@ Map _$SimpleClassNullableOfObjectToEnumTypeToJson( }; SimpleClassOfStringToEnumType _$SimpleClassOfStringToEnumTypeFromJson( - Map json) { - return SimpleClassOfStringToEnumType( - (json['value'] as Map).map( - (k, e) => MapEntry(k, _$enumDecode(_$EnumTypeEnumMap, e)), - ), - ); -} + Map json) => + SimpleClassOfStringToEnumType( + (json['value'] as Map).map( + (k, e) => MapEntry(k, _$enumDecode(_$EnumTypeEnumMap, e)), + ), + ); Map _$SimpleClassOfStringToEnumTypeToJson( SimpleClassOfStringToEnumType instance) => @@ -3039,13 +2881,13 @@ Map _$SimpleClassOfStringToEnumTypeToJson( }; SimpleClassNullableOfStringToEnumType - _$SimpleClassNullableOfStringToEnumTypeFromJson(Map json) { - return SimpleClassNullableOfStringToEnumType( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(k, _$enumDecode(_$EnumTypeEnumMap, e)), - ), - ); -} + _$SimpleClassNullableOfStringToEnumTypeFromJson( + Map json) => + SimpleClassNullableOfStringToEnumType( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, _$enumDecode(_$EnumTypeEnumMap, e)), + ), + ); Map _$SimpleClassNullableOfStringToEnumTypeToJson( SimpleClassNullableOfStringToEnumType instance) => @@ -3054,13 +2896,12 @@ Map _$SimpleClassNullableOfStringToEnumTypeToJson( }; SimpleClassOfUriToEnumType _$SimpleClassOfUriToEnumTypeFromJson( - Map json) { - return SimpleClassOfUriToEnumType( - (json['value'] as Map).map( - (k, e) => MapEntry(Uri.parse(k), _$enumDecode(_$EnumTypeEnumMap, e)), - ), - ); -} + Map json) => + SimpleClassOfUriToEnumType( + (json['value'] as Map).map( + (k, e) => MapEntry(Uri.parse(k), _$enumDecode(_$EnumTypeEnumMap, e)), + ), + ); Map _$SimpleClassOfUriToEnumTypeToJson( SimpleClassOfUriToEnumType instance) => @@ -3070,13 +2911,12 @@ Map _$SimpleClassOfUriToEnumTypeToJson( }; SimpleClassNullableOfUriToEnumType _$SimpleClassNullableOfUriToEnumTypeFromJson( - Map json) { - return SimpleClassNullableOfUriToEnumType( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(Uri.parse(k), _$enumDecode(_$EnumTypeEnumMap, e)), - ), - ); -} + Map json) => + SimpleClassNullableOfUriToEnumType( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(Uri.parse(k), _$enumDecode(_$EnumTypeEnumMap, e)), + ), + ); Map _$SimpleClassNullableOfUriToEnumTypeToJson( SimpleClassNullableOfUriToEnumType instance) => @@ -3086,14 +2926,14 @@ Map _$SimpleClassNullableOfUriToEnumTypeToJson( }; SimpleClassOfBigIntToEnumTypeNullable - _$SimpleClassOfBigIntToEnumTypeNullableFromJson(Map json) { - return SimpleClassOfBigIntToEnumTypeNullable( - (json['value'] as Map).map( - (k, e) => - MapEntry(BigInt.parse(k), _$enumDecodeNullable(_$EnumTypeEnumMap, e)), - ), - ); -} + _$SimpleClassOfBigIntToEnumTypeNullableFromJson( + Map json) => + SimpleClassOfBigIntToEnumTypeNullable( + (json['value'] as Map).map( + (k, e) => MapEntry( + BigInt.parse(k), _$enumDecodeNullable(_$EnumTypeEnumMap, e)), + ), + ); Map _$SimpleClassOfBigIntToEnumTypeNullableToJson( SimpleClassOfBigIntToEnumTypeNullable instance) => @@ -3115,14 +2955,13 @@ K? _$enumDecodeNullable( SimpleClassNullableOfBigIntToEnumTypeNullable _$SimpleClassNullableOfBigIntToEnumTypeNullableFromJson( - Map json) { - return SimpleClassNullableOfBigIntToEnumTypeNullable( - (json['value'] as Map?)?.map( - (k, e) => - MapEntry(BigInt.parse(k), _$enumDecodeNullable(_$EnumTypeEnumMap, e)), - ), - ); -} + Map json) => + SimpleClassNullableOfBigIntToEnumTypeNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry( + BigInt.parse(k), _$enumDecodeNullable(_$EnumTypeEnumMap, e)), + ), + ); Map _$SimpleClassNullableOfBigIntToEnumTypeNullableToJson( SimpleClassNullableOfBigIntToEnumTypeNullable instance) => @@ -3133,14 +2972,13 @@ Map _$SimpleClassNullableOfBigIntToEnumTypeNullableToJson( SimpleClassOfDateTimeToEnumTypeNullable _$SimpleClassOfDateTimeToEnumTypeNullableFromJson( - Map json) { - return SimpleClassOfDateTimeToEnumTypeNullable( - (json['value'] as Map).map( - (k, e) => MapEntry( - DateTime.parse(k), _$enumDecodeNullable(_$EnumTypeEnumMap, e)), - ), - ); -} + Map json) => + SimpleClassOfDateTimeToEnumTypeNullable( + (json['value'] as Map).map( + (k, e) => MapEntry( + DateTime.parse(k), _$enumDecodeNullable(_$EnumTypeEnumMap, e)), + ), + ); Map _$SimpleClassOfDateTimeToEnumTypeNullableToJson( SimpleClassOfDateTimeToEnumTypeNullable instance) => @@ -3151,14 +2989,13 @@ Map _$SimpleClassOfDateTimeToEnumTypeNullableToJson( SimpleClassNullableOfDateTimeToEnumTypeNullable _$SimpleClassNullableOfDateTimeToEnumTypeNullableFromJson( - Map json) { - return SimpleClassNullableOfDateTimeToEnumTypeNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry( - DateTime.parse(k), _$enumDecodeNullable(_$EnumTypeEnumMap, e)), - ), - ); -} + Map json) => + SimpleClassNullableOfDateTimeToEnumTypeNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry( + DateTime.parse(k), _$enumDecodeNullable(_$EnumTypeEnumMap, e)), + ), + ); Map _$SimpleClassNullableOfDateTimeToEnumTypeNullableToJson( SimpleClassNullableOfDateTimeToEnumTypeNullable instance) => @@ -3169,13 +3006,12 @@ Map _$SimpleClassNullableOfDateTimeToEnumTypeNullableToJson( SimpleClassOfDynamicToEnumTypeNullable _$SimpleClassOfDynamicToEnumTypeNullableFromJson( - Map json) { - return SimpleClassOfDynamicToEnumTypeNullable( - (json['value'] as Map).map( - (k, e) => MapEntry(k, _$enumDecodeNullable(_$EnumTypeEnumMap, e)), - ), - ); -} + Map json) => + SimpleClassOfDynamicToEnumTypeNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(k, _$enumDecodeNullable(_$EnumTypeEnumMap, e)), + ), + ); Map _$SimpleClassOfDynamicToEnumTypeNullableToJson( SimpleClassOfDynamicToEnumTypeNullable instance) => @@ -3185,13 +3021,12 @@ Map _$SimpleClassOfDynamicToEnumTypeNullableToJson( SimpleClassNullableOfDynamicToEnumTypeNullable _$SimpleClassNullableOfDynamicToEnumTypeNullableFromJson( - Map json) { - return SimpleClassNullableOfDynamicToEnumTypeNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(k, _$enumDecodeNullable(_$EnumTypeEnumMap, e)), - ), - ); -} + Map json) => + SimpleClassNullableOfDynamicToEnumTypeNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, _$enumDecodeNullable(_$EnumTypeEnumMap, e)), + ), + ); Map _$SimpleClassNullableOfDynamicToEnumTypeNullableToJson( SimpleClassNullableOfDynamicToEnumTypeNullable instance) => @@ -3201,14 +3036,13 @@ Map _$SimpleClassNullableOfDynamicToEnumTypeNullableToJson( SimpleClassOfEnumTypeToEnumTypeNullable _$SimpleClassOfEnumTypeToEnumTypeNullableFromJson( - Map json) { - return SimpleClassOfEnumTypeToEnumTypeNullable( - (json['value'] as Map).map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), - _$enumDecodeNullable(_$EnumTypeEnumMap, e)), - ), - ); -} + Map json) => + SimpleClassOfEnumTypeToEnumTypeNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), + _$enumDecodeNullable(_$EnumTypeEnumMap, e)), + ), + ); Map _$SimpleClassOfEnumTypeToEnumTypeNullableToJson( SimpleClassOfEnumTypeToEnumTypeNullable instance) => @@ -3219,14 +3053,13 @@ Map _$SimpleClassOfEnumTypeToEnumTypeNullableToJson( SimpleClassNullableOfEnumTypeToEnumTypeNullable _$SimpleClassNullableOfEnumTypeToEnumTypeNullableFromJson( - Map json) { - return SimpleClassNullableOfEnumTypeToEnumTypeNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), - _$enumDecodeNullable(_$EnumTypeEnumMap, e)), - ), - ); -} + Map json) => + SimpleClassNullableOfEnumTypeToEnumTypeNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), + _$enumDecodeNullable(_$EnumTypeEnumMap, e)), + ), + ); Map _$SimpleClassNullableOfEnumTypeToEnumTypeNullableToJson( SimpleClassNullableOfEnumTypeToEnumTypeNullable instance) => @@ -3236,14 +3069,13 @@ Map _$SimpleClassNullableOfEnumTypeToEnumTypeNullableToJson( }; SimpleClassOfIntToEnumTypeNullable _$SimpleClassOfIntToEnumTypeNullableFromJson( - Map json) { - return SimpleClassOfIntToEnumTypeNullable( - (json['value'] as Map).map( - (k, e) => - MapEntry(int.parse(k), _$enumDecodeNullable(_$EnumTypeEnumMap, e)), - ), - ); -} + Map json) => + SimpleClassOfIntToEnumTypeNullable( + (json['value'] as Map).map( + (k, e) => + MapEntry(int.parse(k), _$enumDecodeNullable(_$EnumTypeEnumMap, e)), + ), + ); Map _$SimpleClassOfIntToEnumTypeNullableToJson( SimpleClassOfIntToEnumTypeNullable instance) => @@ -3254,14 +3086,13 @@ Map _$SimpleClassOfIntToEnumTypeNullableToJson( SimpleClassNullableOfIntToEnumTypeNullable _$SimpleClassNullableOfIntToEnumTypeNullableFromJson( - Map json) { - return SimpleClassNullableOfIntToEnumTypeNullable( - (json['value'] as Map?)?.map( - (k, e) => - MapEntry(int.parse(k), _$enumDecodeNullable(_$EnumTypeEnumMap, e)), - ), - ); -} + Map json) => + SimpleClassNullableOfIntToEnumTypeNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry( + int.parse(k), _$enumDecodeNullable(_$EnumTypeEnumMap, e)), + ), + ); Map _$SimpleClassNullableOfIntToEnumTypeNullableToJson( SimpleClassNullableOfIntToEnumTypeNullable instance) => @@ -3271,13 +3102,13 @@ Map _$SimpleClassNullableOfIntToEnumTypeNullableToJson( }; SimpleClassOfObjectToEnumTypeNullable - _$SimpleClassOfObjectToEnumTypeNullableFromJson(Map json) { - return SimpleClassOfObjectToEnumTypeNullable( - (json['value'] as Map).map( - (k, e) => MapEntry(k, _$enumDecodeNullable(_$EnumTypeEnumMap, e)), - ), - ); -} + _$SimpleClassOfObjectToEnumTypeNullableFromJson( + Map json) => + SimpleClassOfObjectToEnumTypeNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(k, _$enumDecodeNullable(_$EnumTypeEnumMap, e)), + ), + ); Map _$SimpleClassOfObjectToEnumTypeNullableToJson( SimpleClassOfObjectToEnumTypeNullable instance) => @@ -3287,13 +3118,12 @@ Map _$SimpleClassOfObjectToEnumTypeNullableToJson( SimpleClassNullableOfObjectToEnumTypeNullable _$SimpleClassNullableOfObjectToEnumTypeNullableFromJson( - Map json) { - return SimpleClassNullableOfObjectToEnumTypeNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(k, _$enumDecodeNullable(_$EnumTypeEnumMap, e)), - ), - ); -} + Map json) => + SimpleClassNullableOfObjectToEnumTypeNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, _$enumDecodeNullable(_$EnumTypeEnumMap, e)), + ), + ); Map _$SimpleClassNullableOfObjectToEnumTypeNullableToJson( SimpleClassNullableOfObjectToEnumTypeNullable instance) => @@ -3302,13 +3132,13 @@ Map _$SimpleClassNullableOfObjectToEnumTypeNullableToJson( }; SimpleClassOfStringToEnumTypeNullable - _$SimpleClassOfStringToEnumTypeNullableFromJson(Map json) { - return SimpleClassOfStringToEnumTypeNullable( - (json['value'] as Map).map( - (k, e) => MapEntry(k, _$enumDecodeNullable(_$EnumTypeEnumMap, e)), - ), - ); -} + _$SimpleClassOfStringToEnumTypeNullableFromJson( + Map json) => + SimpleClassOfStringToEnumTypeNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(k, _$enumDecodeNullable(_$EnumTypeEnumMap, e)), + ), + ); Map _$SimpleClassOfStringToEnumTypeNullableToJson( SimpleClassOfStringToEnumTypeNullable instance) => @@ -3318,13 +3148,12 @@ Map _$SimpleClassOfStringToEnumTypeNullableToJson( SimpleClassNullableOfStringToEnumTypeNullable _$SimpleClassNullableOfStringToEnumTypeNullableFromJson( - Map json) { - return SimpleClassNullableOfStringToEnumTypeNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(k, _$enumDecodeNullable(_$EnumTypeEnumMap, e)), - ), - ); -} + Map json) => + SimpleClassNullableOfStringToEnumTypeNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, _$enumDecodeNullable(_$EnumTypeEnumMap, e)), + ), + ); Map _$SimpleClassNullableOfStringToEnumTypeNullableToJson( SimpleClassNullableOfStringToEnumTypeNullable instance) => @@ -3333,14 +3162,13 @@ Map _$SimpleClassNullableOfStringToEnumTypeNullableToJson( }; SimpleClassOfUriToEnumTypeNullable _$SimpleClassOfUriToEnumTypeNullableFromJson( - Map json) { - return SimpleClassOfUriToEnumTypeNullable( - (json['value'] as Map).map( - (k, e) => - MapEntry(Uri.parse(k), _$enumDecodeNullable(_$EnumTypeEnumMap, e)), - ), - ); -} + Map json) => + SimpleClassOfUriToEnumTypeNullable( + (json['value'] as Map).map( + (k, e) => + MapEntry(Uri.parse(k), _$enumDecodeNullable(_$EnumTypeEnumMap, e)), + ), + ); Map _$SimpleClassOfUriToEnumTypeNullableToJson( SimpleClassOfUriToEnumTypeNullable instance) => @@ -3351,14 +3179,13 @@ Map _$SimpleClassOfUriToEnumTypeNullableToJson( SimpleClassNullableOfUriToEnumTypeNullable _$SimpleClassNullableOfUriToEnumTypeNullableFromJson( - Map json) { - return SimpleClassNullableOfUriToEnumTypeNullable( - (json['value'] as Map?)?.map( - (k, e) => - MapEntry(Uri.parse(k), _$enumDecodeNullable(_$EnumTypeEnumMap, e)), - ), - ); -} + Map json) => + SimpleClassNullableOfUriToEnumTypeNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry( + Uri.parse(k), _$enumDecodeNullable(_$EnumTypeEnumMap, e)), + ), + ); Map _$SimpleClassNullableOfUriToEnumTypeNullableToJson( SimpleClassNullableOfUriToEnumTypeNullable instance) => @@ -3368,13 +3195,12 @@ Map _$SimpleClassNullableOfUriToEnumTypeNullableToJson( }; SimpleClassOfBigIntToInt _$SimpleClassOfBigIntToIntFromJson( - Map json) { - return SimpleClassOfBigIntToInt( - (json['value'] as Map).map( - (k, e) => MapEntry(BigInt.parse(k), e as int), - ), - ); -} + Map json) => + SimpleClassOfBigIntToInt( + (json['value'] as Map).map( + (k, e) => MapEntry(BigInt.parse(k), e as int), + ), + ); Map _$SimpleClassOfBigIntToIntToJson( SimpleClassOfBigIntToInt instance) => @@ -3383,13 +3209,12 @@ Map _$SimpleClassOfBigIntToIntToJson( }; SimpleClassNullableOfBigIntToInt _$SimpleClassNullableOfBigIntToIntFromJson( - Map json) { - return SimpleClassNullableOfBigIntToInt( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(BigInt.parse(k), e as int), - ), - ); -} + Map json) => + SimpleClassNullableOfBigIntToInt( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(BigInt.parse(k), e as int), + ), + ); Map _$SimpleClassNullableOfBigIntToIntToJson( SimpleClassNullableOfBigIntToInt instance) => @@ -3398,13 +3223,12 @@ Map _$SimpleClassNullableOfBigIntToIntToJson( }; SimpleClassOfDateTimeToInt _$SimpleClassOfDateTimeToIntFromJson( - Map json) { - return SimpleClassOfDateTimeToInt( - (json['value'] as Map).map( - (k, e) => MapEntry(DateTime.parse(k), e as int), - ), - ); -} + Map json) => + SimpleClassOfDateTimeToInt( + (json['value'] as Map).map( + (k, e) => MapEntry(DateTime.parse(k), e as int), + ), + ); Map _$SimpleClassOfDateTimeToIntToJson( SimpleClassOfDateTimeToInt instance) => @@ -3413,13 +3237,12 @@ Map _$SimpleClassOfDateTimeToIntToJson( }; SimpleClassNullableOfDateTimeToInt _$SimpleClassNullableOfDateTimeToIntFromJson( - Map json) { - return SimpleClassNullableOfDateTimeToInt( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(DateTime.parse(k), e as int), - ), - ); -} + Map json) => + SimpleClassNullableOfDateTimeToInt( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(DateTime.parse(k), e as int), + ), + ); Map _$SimpleClassNullableOfDateTimeToIntToJson( SimpleClassNullableOfDateTimeToInt instance) => @@ -3428,11 +3251,10 @@ Map _$SimpleClassNullableOfDateTimeToIntToJson( }; SimpleClassOfDynamicToInt _$SimpleClassOfDynamicToIntFromJson( - Map json) { - return SimpleClassOfDynamicToInt( - Map.from(json['value'] as Map), - ); -} + Map json) => + SimpleClassOfDynamicToInt( + Map.from(json['value'] as Map), + ); Map _$SimpleClassOfDynamicToIntToJson( SimpleClassOfDynamicToInt instance) => @@ -3441,13 +3263,12 @@ Map _$SimpleClassOfDynamicToIntToJson( }; SimpleClassNullableOfDynamicToInt _$SimpleClassNullableOfDynamicToIntFromJson( - Map json) { - return SimpleClassNullableOfDynamicToInt( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(k, e as int), - ), - ); -} + Map json) => + SimpleClassNullableOfDynamicToInt( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e as int), + ), + ); Map _$SimpleClassNullableOfDynamicToIntToJson( SimpleClassNullableOfDynamicToInt instance) => @@ -3456,13 +3277,12 @@ Map _$SimpleClassNullableOfDynamicToIntToJson( }; SimpleClassOfEnumTypeToInt _$SimpleClassOfEnumTypeToIntFromJson( - Map json) { - return SimpleClassOfEnumTypeToInt( - (json['value'] as Map).map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as int), - ), - ); -} + Map json) => + SimpleClassOfEnumTypeToInt( + (json['value'] as Map).map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as int), + ), + ); Map _$SimpleClassOfEnumTypeToIntToJson( SimpleClassOfEnumTypeToInt instance) => @@ -3471,13 +3291,12 @@ Map _$SimpleClassOfEnumTypeToIntToJson( }; SimpleClassNullableOfEnumTypeToInt _$SimpleClassNullableOfEnumTypeToIntFromJson( - Map json) { - return SimpleClassNullableOfEnumTypeToInt( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as int), - ), - ); -} + Map json) => + SimpleClassNullableOfEnumTypeToInt( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as int), + ), + ); Map _$SimpleClassNullableOfEnumTypeToIntToJson( SimpleClassNullableOfEnumTypeToInt instance) => @@ -3486,13 +3305,12 @@ Map _$SimpleClassNullableOfEnumTypeToIntToJson( }; SimpleClassOfIntToInt _$SimpleClassOfIntToIntFromJson( - Map json) { - return SimpleClassOfIntToInt( - (json['value'] as Map).map( - (k, e) => MapEntry(int.parse(k), e as int), - ), - ); -} + Map json) => + SimpleClassOfIntToInt( + (json['value'] as Map).map( + (k, e) => MapEntry(int.parse(k), e as int), + ), + ); Map _$SimpleClassOfIntToIntToJson( SimpleClassOfIntToInt instance) => @@ -3501,13 +3319,12 @@ Map _$SimpleClassOfIntToIntToJson( }; SimpleClassNullableOfIntToInt _$SimpleClassNullableOfIntToIntFromJson( - Map json) { - return SimpleClassNullableOfIntToInt( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(int.parse(k), e as int), - ), - ); -} + Map json) => + SimpleClassNullableOfIntToInt( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(int.parse(k), e as int), + ), + ); Map _$SimpleClassNullableOfIntToIntToJson( SimpleClassNullableOfIntToInt instance) => @@ -3516,11 +3333,10 @@ Map _$SimpleClassNullableOfIntToIntToJson( }; SimpleClassOfObjectToInt _$SimpleClassOfObjectToIntFromJson( - Map json) { - return SimpleClassOfObjectToInt( - Map.from(json['value'] as Map), - ); -} + Map json) => + SimpleClassOfObjectToInt( + Map.from(json['value'] as Map), + ); Map _$SimpleClassOfObjectToIntToJson( SimpleClassOfObjectToInt instance) => @@ -3529,13 +3345,12 @@ Map _$SimpleClassOfObjectToIntToJson( }; SimpleClassNullableOfObjectToInt _$SimpleClassNullableOfObjectToIntFromJson( - Map json) { - return SimpleClassNullableOfObjectToInt( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(k, e as int), - ), - ); -} + Map json) => + SimpleClassNullableOfObjectToInt( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e as int), + ), + ); Map _$SimpleClassNullableOfObjectToIntToJson( SimpleClassNullableOfObjectToInt instance) => @@ -3544,11 +3359,10 @@ Map _$SimpleClassNullableOfObjectToIntToJson( }; SimpleClassOfStringToInt _$SimpleClassOfStringToIntFromJson( - Map json) { - return SimpleClassOfStringToInt( - Map.from(json['value'] as Map), - ); -} + Map json) => + SimpleClassOfStringToInt( + Map.from(json['value'] as Map), + ); Map _$SimpleClassOfStringToIntToJson( SimpleClassOfStringToInt instance) => @@ -3557,13 +3371,12 @@ Map _$SimpleClassOfStringToIntToJson( }; SimpleClassNullableOfStringToInt _$SimpleClassNullableOfStringToIntFromJson( - Map json) { - return SimpleClassNullableOfStringToInt( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(k, e as int), - ), - ); -} + Map json) => + SimpleClassNullableOfStringToInt( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e as int), + ), + ); Map _$SimpleClassNullableOfStringToIntToJson( SimpleClassNullableOfStringToInt instance) => @@ -3572,13 +3385,12 @@ Map _$SimpleClassNullableOfStringToIntToJson( }; SimpleClassOfUriToInt _$SimpleClassOfUriToIntFromJson( - Map json) { - return SimpleClassOfUriToInt( - (json['value'] as Map).map( - (k, e) => MapEntry(Uri.parse(k), e as int), - ), - ); -} + Map json) => + SimpleClassOfUriToInt( + (json['value'] as Map).map( + (k, e) => MapEntry(Uri.parse(k), e as int), + ), + ); Map _$SimpleClassOfUriToIntToJson( SimpleClassOfUriToInt instance) => @@ -3587,13 +3399,12 @@ Map _$SimpleClassOfUriToIntToJson( }; SimpleClassNullableOfUriToInt _$SimpleClassNullableOfUriToIntFromJson( - Map json) { - return SimpleClassNullableOfUriToInt( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(Uri.parse(k), e as int), - ), - ); -} + Map json) => + SimpleClassNullableOfUriToInt( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(Uri.parse(k), e as int), + ), + ); Map _$SimpleClassNullableOfUriToIntToJson( SimpleClassNullableOfUriToInt instance) => @@ -3602,13 +3413,12 @@ Map _$SimpleClassNullableOfUriToIntToJson( }; SimpleClassOfBigIntToIntNullable _$SimpleClassOfBigIntToIntNullableFromJson( - Map json) { - return SimpleClassOfBigIntToIntNullable( - (json['value'] as Map).map( - (k, e) => MapEntry(BigInt.parse(k), e as int?), - ), - ); -} + Map json) => + SimpleClassOfBigIntToIntNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(BigInt.parse(k), e as int?), + ), + ); Map _$SimpleClassOfBigIntToIntNullableToJson( SimpleClassOfBigIntToIntNullable instance) => @@ -3618,13 +3428,12 @@ Map _$SimpleClassOfBigIntToIntNullableToJson( SimpleClassNullableOfBigIntToIntNullable _$SimpleClassNullableOfBigIntToIntNullableFromJson( - Map json) { - return SimpleClassNullableOfBigIntToIntNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(BigInt.parse(k), e as int?), - ), - ); -} + Map json) => + SimpleClassNullableOfBigIntToIntNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(BigInt.parse(k), e as int?), + ), + ); Map _$SimpleClassNullableOfBigIntToIntNullableToJson( SimpleClassNullableOfBigIntToIntNullable instance) => @@ -3633,13 +3442,12 @@ Map _$SimpleClassNullableOfBigIntToIntNullableToJson( }; SimpleClassOfDateTimeToIntNullable _$SimpleClassOfDateTimeToIntNullableFromJson( - Map json) { - return SimpleClassOfDateTimeToIntNullable( - (json['value'] as Map).map( - (k, e) => MapEntry(DateTime.parse(k), e as int?), - ), - ); -} + Map json) => + SimpleClassOfDateTimeToIntNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(DateTime.parse(k), e as int?), + ), + ); Map _$SimpleClassOfDateTimeToIntNullableToJson( SimpleClassOfDateTimeToIntNullable instance) => @@ -3649,13 +3457,12 @@ Map _$SimpleClassOfDateTimeToIntNullableToJson( SimpleClassNullableOfDateTimeToIntNullable _$SimpleClassNullableOfDateTimeToIntNullableFromJson( - Map json) { - return SimpleClassNullableOfDateTimeToIntNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(DateTime.parse(k), e as int?), - ), - ); -} + Map json) => + SimpleClassNullableOfDateTimeToIntNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(DateTime.parse(k), e as int?), + ), + ); Map _$SimpleClassNullableOfDateTimeToIntNullableToJson( SimpleClassNullableOfDateTimeToIntNullable instance) => @@ -3664,11 +3471,10 @@ Map _$SimpleClassNullableOfDateTimeToIntNullableToJson( }; SimpleClassOfDynamicToIntNullable _$SimpleClassOfDynamicToIntNullableFromJson( - Map json) { - return SimpleClassOfDynamicToIntNullable( - Map.from(json['value'] as Map), - ); -} + Map json) => + SimpleClassOfDynamicToIntNullable( + Map.from(json['value'] as Map), + ); Map _$SimpleClassOfDynamicToIntNullableToJson( SimpleClassOfDynamicToIntNullable instance) => @@ -3678,13 +3484,12 @@ Map _$SimpleClassOfDynamicToIntNullableToJson( SimpleClassNullableOfDynamicToIntNullable _$SimpleClassNullableOfDynamicToIntNullableFromJson( - Map json) { - return SimpleClassNullableOfDynamicToIntNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(k, e as int?), - ), - ); -} + Map json) => + SimpleClassNullableOfDynamicToIntNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e as int?), + ), + ); Map _$SimpleClassNullableOfDynamicToIntNullableToJson( SimpleClassNullableOfDynamicToIntNullable instance) => @@ -3693,13 +3498,12 @@ Map _$SimpleClassNullableOfDynamicToIntNullableToJson( }; SimpleClassOfEnumTypeToIntNullable _$SimpleClassOfEnumTypeToIntNullableFromJson( - Map json) { - return SimpleClassOfEnumTypeToIntNullable( - (json['value'] as Map).map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as int?), - ), - ); -} + Map json) => + SimpleClassOfEnumTypeToIntNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as int?), + ), + ); Map _$SimpleClassOfEnumTypeToIntNullableToJson( SimpleClassOfEnumTypeToIntNullable instance) => @@ -3709,13 +3513,12 @@ Map _$SimpleClassOfEnumTypeToIntNullableToJson( SimpleClassNullableOfEnumTypeToIntNullable _$SimpleClassNullableOfEnumTypeToIntNullableFromJson( - Map json) { - return SimpleClassNullableOfEnumTypeToIntNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as int?), - ), - ); -} + Map json) => + SimpleClassNullableOfEnumTypeToIntNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as int?), + ), + ); Map _$SimpleClassNullableOfEnumTypeToIntNullableToJson( SimpleClassNullableOfEnumTypeToIntNullable instance) => @@ -3724,13 +3527,12 @@ Map _$SimpleClassNullableOfEnumTypeToIntNullableToJson( }; SimpleClassOfIntToIntNullable _$SimpleClassOfIntToIntNullableFromJson( - Map json) { - return SimpleClassOfIntToIntNullable( - (json['value'] as Map).map( - (k, e) => MapEntry(int.parse(k), e as int?), - ), - ); -} + Map json) => + SimpleClassOfIntToIntNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(int.parse(k), e as int?), + ), + ); Map _$SimpleClassOfIntToIntNullableToJson( SimpleClassOfIntToIntNullable instance) => @@ -3739,13 +3541,13 @@ Map _$SimpleClassOfIntToIntNullableToJson( }; SimpleClassNullableOfIntToIntNullable - _$SimpleClassNullableOfIntToIntNullableFromJson(Map json) { - return SimpleClassNullableOfIntToIntNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(int.parse(k), e as int?), - ), - ); -} + _$SimpleClassNullableOfIntToIntNullableFromJson( + Map json) => + SimpleClassNullableOfIntToIntNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(int.parse(k), e as int?), + ), + ); Map _$SimpleClassNullableOfIntToIntNullableToJson( SimpleClassNullableOfIntToIntNullable instance) => @@ -3754,11 +3556,10 @@ Map _$SimpleClassNullableOfIntToIntNullableToJson( }; SimpleClassOfObjectToIntNullable _$SimpleClassOfObjectToIntNullableFromJson( - Map json) { - return SimpleClassOfObjectToIntNullable( - Map.from(json['value'] as Map), - ); -} + Map json) => + SimpleClassOfObjectToIntNullable( + Map.from(json['value'] as Map), + ); Map _$SimpleClassOfObjectToIntNullableToJson( SimpleClassOfObjectToIntNullable instance) => @@ -3768,13 +3569,12 @@ Map _$SimpleClassOfObjectToIntNullableToJson( SimpleClassNullableOfObjectToIntNullable _$SimpleClassNullableOfObjectToIntNullableFromJson( - Map json) { - return SimpleClassNullableOfObjectToIntNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(k, e as int?), - ), - ); -} + Map json) => + SimpleClassNullableOfObjectToIntNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e as int?), + ), + ); Map _$SimpleClassNullableOfObjectToIntNullableToJson( SimpleClassNullableOfObjectToIntNullable instance) => @@ -3783,11 +3583,10 @@ Map _$SimpleClassNullableOfObjectToIntNullableToJson( }; SimpleClassOfStringToIntNullable _$SimpleClassOfStringToIntNullableFromJson( - Map json) { - return SimpleClassOfStringToIntNullable( - Map.from(json['value'] as Map), - ); -} + Map json) => + SimpleClassOfStringToIntNullable( + Map.from(json['value'] as Map), + ); Map _$SimpleClassOfStringToIntNullableToJson( SimpleClassOfStringToIntNullable instance) => @@ -3797,13 +3596,12 @@ Map _$SimpleClassOfStringToIntNullableToJson( SimpleClassNullableOfStringToIntNullable _$SimpleClassNullableOfStringToIntNullableFromJson( - Map json) { - return SimpleClassNullableOfStringToIntNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(k, e as int?), - ), - ); -} + Map json) => + SimpleClassNullableOfStringToIntNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e as int?), + ), + ); Map _$SimpleClassNullableOfStringToIntNullableToJson( SimpleClassNullableOfStringToIntNullable instance) => @@ -3812,13 +3610,12 @@ Map _$SimpleClassNullableOfStringToIntNullableToJson( }; SimpleClassOfUriToIntNullable _$SimpleClassOfUriToIntNullableFromJson( - Map json) { - return SimpleClassOfUriToIntNullable( - (json['value'] as Map).map( - (k, e) => MapEntry(Uri.parse(k), e as int?), - ), - ); -} + Map json) => + SimpleClassOfUriToIntNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(Uri.parse(k), e as int?), + ), + ); Map _$SimpleClassOfUriToIntNullableToJson( SimpleClassOfUriToIntNullable instance) => @@ -3827,13 +3624,13 @@ Map _$SimpleClassOfUriToIntNullableToJson( }; SimpleClassNullableOfUriToIntNullable - _$SimpleClassNullableOfUriToIntNullableFromJson(Map json) { - return SimpleClassNullableOfUriToIntNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(Uri.parse(k), e as int?), - ), - ); -} + _$SimpleClassNullableOfUriToIntNullableFromJson( + Map json) => + SimpleClassNullableOfUriToIntNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(Uri.parse(k), e as int?), + ), + ); Map _$SimpleClassNullableOfUriToIntNullableToJson( SimpleClassNullableOfUriToIntNullable instance) => @@ -3842,13 +3639,12 @@ Map _$SimpleClassNullableOfUriToIntNullableToJson( }; SimpleClassOfBigIntToNum _$SimpleClassOfBigIntToNumFromJson( - Map json) { - return SimpleClassOfBigIntToNum( - (json['value'] as Map).map( - (k, e) => MapEntry(BigInt.parse(k), e as num), - ), - ); -} + Map json) => + SimpleClassOfBigIntToNum( + (json['value'] as Map).map( + (k, e) => MapEntry(BigInt.parse(k), e as num), + ), + ); Map _$SimpleClassOfBigIntToNumToJson( SimpleClassOfBigIntToNum instance) => @@ -3857,13 +3653,12 @@ Map _$SimpleClassOfBigIntToNumToJson( }; SimpleClassNullableOfBigIntToNum _$SimpleClassNullableOfBigIntToNumFromJson( - Map json) { - return SimpleClassNullableOfBigIntToNum( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(BigInt.parse(k), e as num), - ), - ); -} + Map json) => + SimpleClassNullableOfBigIntToNum( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(BigInt.parse(k), e as num), + ), + ); Map _$SimpleClassNullableOfBigIntToNumToJson( SimpleClassNullableOfBigIntToNum instance) => @@ -3872,13 +3667,12 @@ Map _$SimpleClassNullableOfBigIntToNumToJson( }; SimpleClassOfDateTimeToNum _$SimpleClassOfDateTimeToNumFromJson( - Map json) { - return SimpleClassOfDateTimeToNum( - (json['value'] as Map).map( - (k, e) => MapEntry(DateTime.parse(k), e as num), - ), - ); -} + Map json) => + SimpleClassOfDateTimeToNum( + (json['value'] as Map).map( + (k, e) => MapEntry(DateTime.parse(k), e as num), + ), + ); Map _$SimpleClassOfDateTimeToNumToJson( SimpleClassOfDateTimeToNum instance) => @@ -3887,13 +3681,12 @@ Map _$SimpleClassOfDateTimeToNumToJson( }; SimpleClassNullableOfDateTimeToNum _$SimpleClassNullableOfDateTimeToNumFromJson( - Map json) { - return SimpleClassNullableOfDateTimeToNum( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(DateTime.parse(k), e as num), - ), - ); -} + Map json) => + SimpleClassNullableOfDateTimeToNum( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(DateTime.parse(k), e as num), + ), + ); Map _$SimpleClassNullableOfDateTimeToNumToJson( SimpleClassNullableOfDateTimeToNum instance) => @@ -3902,11 +3695,10 @@ Map _$SimpleClassNullableOfDateTimeToNumToJson( }; SimpleClassOfDynamicToNum _$SimpleClassOfDynamicToNumFromJson( - Map json) { - return SimpleClassOfDynamicToNum( - Map.from(json['value'] as Map), - ); -} + Map json) => + SimpleClassOfDynamicToNum( + Map.from(json['value'] as Map), + ); Map _$SimpleClassOfDynamicToNumToJson( SimpleClassOfDynamicToNum instance) => @@ -3915,13 +3707,12 @@ Map _$SimpleClassOfDynamicToNumToJson( }; SimpleClassNullableOfDynamicToNum _$SimpleClassNullableOfDynamicToNumFromJson( - Map json) { - return SimpleClassNullableOfDynamicToNum( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(k, e as num), - ), - ); -} + Map json) => + SimpleClassNullableOfDynamicToNum( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e as num), + ), + ); Map _$SimpleClassNullableOfDynamicToNumToJson( SimpleClassNullableOfDynamicToNum instance) => @@ -3930,13 +3721,12 @@ Map _$SimpleClassNullableOfDynamicToNumToJson( }; SimpleClassOfEnumTypeToNum _$SimpleClassOfEnumTypeToNumFromJson( - Map json) { - return SimpleClassOfEnumTypeToNum( - (json['value'] as Map).map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as num), - ), - ); -} + Map json) => + SimpleClassOfEnumTypeToNum( + (json['value'] as Map).map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as num), + ), + ); Map _$SimpleClassOfEnumTypeToNumToJson( SimpleClassOfEnumTypeToNum instance) => @@ -3945,13 +3735,12 @@ Map _$SimpleClassOfEnumTypeToNumToJson( }; SimpleClassNullableOfEnumTypeToNum _$SimpleClassNullableOfEnumTypeToNumFromJson( - Map json) { - return SimpleClassNullableOfEnumTypeToNum( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as num), - ), - ); -} + Map json) => + SimpleClassNullableOfEnumTypeToNum( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as num), + ), + ); Map _$SimpleClassNullableOfEnumTypeToNumToJson( SimpleClassNullableOfEnumTypeToNum instance) => @@ -3960,13 +3749,12 @@ Map _$SimpleClassNullableOfEnumTypeToNumToJson( }; SimpleClassOfIntToNum _$SimpleClassOfIntToNumFromJson( - Map json) { - return SimpleClassOfIntToNum( - (json['value'] as Map).map( - (k, e) => MapEntry(int.parse(k), e as num), - ), - ); -} + Map json) => + SimpleClassOfIntToNum( + (json['value'] as Map).map( + (k, e) => MapEntry(int.parse(k), e as num), + ), + ); Map _$SimpleClassOfIntToNumToJson( SimpleClassOfIntToNum instance) => @@ -3975,13 +3763,12 @@ Map _$SimpleClassOfIntToNumToJson( }; SimpleClassNullableOfIntToNum _$SimpleClassNullableOfIntToNumFromJson( - Map json) { - return SimpleClassNullableOfIntToNum( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(int.parse(k), e as num), - ), - ); -} + Map json) => + SimpleClassNullableOfIntToNum( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(int.parse(k), e as num), + ), + ); Map _$SimpleClassNullableOfIntToNumToJson( SimpleClassNullableOfIntToNum instance) => @@ -3990,11 +3777,10 @@ Map _$SimpleClassNullableOfIntToNumToJson( }; SimpleClassOfObjectToNum _$SimpleClassOfObjectToNumFromJson( - Map json) { - return SimpleClassOfObjectToNum( - Map.from(json['value'] as Map), - ); -} + Map json) => + SimpleClassOfObjectToNum( + Map.from(json['value'] as Map), + ); Map _$SimpleClassOfObjectToNumToJson( SimpleClassOfObjectToNum instance) => @@ -4003,13 +3789,12 @@ Map _$SimpleClassOfObjectToNumToJson( }; SimpleClassNullableOfObjectToNum _$SimpleClassNullableOfObjectToNumFromJson( - Map json) { - return SimpleClassNullableOfObjectToNum( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(k, e as num), - ), - ); -} + Map json) => + SimpleClassNullableOfObjectToNum( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e as num), + ), + ); Map _$SimpleClassNullableOfObjectToNumToJson( SimpleClassNullableOfObjectToNum instance) => @@ -4018,11 +3803,10 @@ Map _$SimpleClassNullableOfObjectToNumToJson( }; SimpleClassOfStringToNum _$SimpleClassOfStringToNumFromJson( - Map json) { - return SimpleClassOfStringToNum( - Map.from(json['value'] as Map), - ); -} + Map json) => + SimpleClassOfStringToNum( + Map.from(json['value'] as Map), + ); Map _$SimpleClassOfStringToNumToJson( SimpleClassOfStringToNum instance) => @@ -4031,13 +3815,12 @@ Map _$SimpleClassOfStringToNumToJson( }; SimpleClassNullableOfStringToNum _$SimpleClassNullableOfStringToNumFromJson( - Map json) { - return SimpleClassNullableOfStringToNum( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(k, e as num), - ), - ); -} + Map json) => + SimpleClassNullableOfStringToNum( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e as num), + ), + ); Map _$SimpleClassNullableOfStringToNumToJson( SimpleClassNullableOfStringToNum instance) => @@ -4046,13 +3829,12 @@ Map _$SimpleClassNullableOfStringToNumToJson( }; SimpleClassOfUriToNum _$SimpleClassOfUriToNumFromJson( - Map json) { - return SimpleClassOfUriToNum( - (json['value'] as Map).map( - (k, e) => MapEntry(Uri.parse(k), e as num), - ), - ); -} + Map json) => + SimpleClassOfUriToNum( + (json['value'] as Map).map( + (k, e) => MapEntry(Uri.parse(k), e as num), + ), + ); Map _$SimpleClassOfUriToNumToJson( SimpleClassOfUriToNum instance) => @@ -4061,13 +3843,12 @@ Map _$SimpleClassOfUriToNumToJson( }; SimpleClassNullableOfUriToNum _$SimpleClassNullableOfUriToNumFromJson( - Map json) { - return SimpleClassNullableOfUriToNum( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(Uri.parse(k), e as num), - ), - ); -} + Map json) => + SimpleClassNullableOfUriToNum( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(Uri.parse(k), e as num), + ), + ); Map _$SimpleClassNullableOfUriToNumToJson( SimpleClassNullableOfUriToNum instance) => @@ -4076,13 +3857,12 @@ Map _$SimpleClassNullableOfUriToNumToJson( }; SimpleClassOfBigIntToNumNullable _$SimpleClassOfBigIntToNumNullableFromJson( - Map json) { - return SimpleClassOfBigIntToNumNullable( - (json['value'] as Map).map( - (k, e) => MapEntry(BigInt.parse(k), e as num?), - ), - ); -} + Map json) => + SimpleClassOfBigIntToNumNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(BigInt.parse(k), e as num?), + ), + ); Map _$SimpleClassOfBigIntToNumNullableToJson( SimpleClassOfBigIntToNumNullable instance) => @@ -4092,13 +3872,12 @@ Map _$SimpleClassOfBigIntToNumNullableToJson( SimpleClassNullableOfBigIntToNumNullable _$SimpleClassNullableOfBigIntToNumNullableFromJson( - Map json) { - return SimpleClassNullableOfBigIntToNumNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(BigInt.parse(k), e as num?), - ), - ); -} + Map json) => + SimpleClassNullableOfBigIntToNumNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(BigInt.parse(k), e as num?), + ), + ); Map _$SimpleClassNullableOfBigIntToNumNullableToJson( SimpleClassNullableOfBigIntToNumNullable instance) => @@ -4107,13 +3886,12 @@ Map _$SimpleClassNullableOfBigIntToNumNullableToJson( }; SimpleClassOfDateTimeToNumNullable _$SimpleClassOfDateTimeToNumNullableFromJson( - Map json) { - return SimpleClassOfDateTimeToNumNullable( - (json['value'] as Map).map( - (k, e) => MapEntry(DateTime.parse(k), e as num?), - ), - ); -} + Map json) => + SimpleClassOfDateTimeToNumNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(DateTime.parse(k), e as num?), + ), + ); Map _$SimpleClassOfDateTimeToNumNullableToJson( SimpleClassOfDateTimeToNumNullable instance) => @@ -4123,13 +3901,12 @@ Map _$SimpleClassOfDateTimeToNumNullableToJson( SimpleClassNullableOfDateTimeToNumNullable _$SimpleClassNullableOfDateTimeToNumNullableFromJson( - Map json) { - return SimpleClassNullableOfDateTimeToNumNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(DateTime.parse(k), e as num?), - ), - ); -} + Map json) => + SimpleClassNullableOfDateTimeToNumNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(DateTime.parse(k), e as num?), + ), + ); Map _$SimpleClassNullableOfDateTimeToNumNullableToJson( SimpleClassNullableOfDateTimeToNumNullable instance) => @@ -4138,11 +3915,10 @@ Map _$SimpleClassNullableOfDateTimeToNumNullableToJson( }; SimpleClassOfDynamicToNumNullable _$SimpleClassOfDynamicToNumNullableFromJson( - Map json) { - return SimpleClassOfDynamicToNumNullable( - Map.from(json['value'] as Map), - ); -} + Map json) => + SimpleClassOfDynamicToNumNullable( + Map.from(json['value'] as Map), + ); Map _$SimpleClassOfDynamicToNumNullableToJson( SimpleClassOfDynamicToNumNullable instance) => @@ -4152,13 +3928,12 @@ Map _$SimpleClassOfDynamicToNumNullableToJson( SimpleClassNullableOfDynamicToNumNullable _$SimpleClassNullableOfDynamicToNumNullableFromJson( - Map json) { - return SimpleClassNullableOfDynamicToNumNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(k, e as num?), - ), - ); -} + Map json) => + SimpleClassNullableOfDynamicToNumNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e as num?), + ), + ); Map _$SimpleClassNullableOfDynamicToNumNullableToJson( SimpleClassNullableOfDynamicToNumNullable instance) => @@ -4167,13 +3942,12 @@ Map _$SimpleClassNullableOfDynamicToNumNullableToJson( }; SimpleClassOfEnumTypeToNumNullable _$SimpleClassOfEnumTypeToNumNullableFromJson( - Map json) { - return SimpleClassOfEnumTypeToNumNullable( - (json['value'] as Map).map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as num?), - ), - ); -} + Map json) => + SimpleClassOfEnumTypeToNumNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as num?), + ), + ); Map _$SimpleClassOfEnumTypeToNumNullableToJson( SimpleClassOfEnumTypeToNumNullable instance) => @@ -4183,13 +3957,12 @@ Map _$SimpleClassOfEnumTypeToNumNullableToJson( SimpleClassNullableOfEnumTypeToNumNullable _$SimpleClassNullableOfEnumTypeToNumNullableFromJson( - Map json) { - return SimpleClassNullableOfEnumTypeToNumNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as num?), - ), - ); -} + Map json) => + SimpleClassNullableOfEnumTypeToNumNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as num?), + ), + ); Map _$SimpleClassNullableOfEnumTypeToNumNullableToJson( SimpleClassNullableOfEnumTypeToNumNullable instance) => @@ -4198,13 +3971,12 @@ Map _$SimpleClassNullableOfEnumTypeToNumNullableToJson( }; SimpleClassOfIntToNumNullable _$SimpleClassOfIntToNumNullableFromJson( - Map json) { - return SimpleClassOfIntToNumNullable( - (json['value'] as Map).map( - (k, e) => MapEntry(int.parse(k), e as num?), - ), - ); -} + Map json) => + SimpleClassOfIntToNumNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(int.parse(k), e as num?), + ), + ); Map _$SimpleClassOfIntToNumNullableToJson( SimpleClassOfIntToNumNullable instance) => @@ -4213,13 +3985,13 @@ Map _$SimpleClassOfIntToNumNullableToJson( }; SimpleClassNullableOfIntToNumNullable - _$SimpleClassNullableOfIntToNumNullableFromJson(Map json) { - return SimpleClassNullableOfIntToNumNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(int.parse(k), e as num?), - ), - ); -} + _$SimpleClassNullableOfIntToNumNullableFromJson( + Map json) => + SimpleClassNullableOfIntToNumNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(int.parse(k), e as num?), + ), + ); Map _$SimpleClassNullableOfIntToNumNullableToJson( SimpleClassNullableOfIntToNumNullable instance) => @@ -4228,11 +4000,10 @@ Map _$SimpleClassNullableOfIntToNumNullableToJson( }; SimpleClassOfObjectToNumNullable _$SimpleClassOfObjectToNumNullableFromJson( - Map json) { - return SimpleClassOfObjectToNumNullable( - Map.from(json['value'] as Map), - ); -} + Map json) => + SimpleClassOfObjectToNumNullable( + Map.from(json['value'] as Map), + ); Map _$SimpleClassOfObjectToNumNullableToJson( SimpleClassOfObjectToNumNullable instance) => @@ -4242,13 +4013,12 @@ Map _$SimpleClassOfObjectToNumNullableToJson( SimpleClassNullableOfObjectToNumNullable _$SimpleClassNullableOfObjectToNumNullableFromJson( - Map json) { - return SimpleClassNullableOfObjectToNumNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(k, e as num?), - ), - ); -} + Map json) => + SimpleClassNullableOfObjectToNumNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e as num?), + ), + ); Map _$SimpleClassNullableOfObjectToNumNullableToJson( SimpleClassNullableOfObjectToNumNullable instance) => @@ -4257,11 +4027,10 @@ Map _$SimpleClassNullableOfObjectToNumNullableToJson( }; SimpleClassOfStringToNumNullable _$SimpleClassOfStringToNumNullableFromJson( - Map json) { - return SimpleClassOfStringToNumNullable( - Map.from(json['value'] as Map), - ); -} + Map json) => + SimpleClassOfStringToNumNullable( + Map.from(json['value'] as Map), + ); Map _$SimpleClassOfStringToNumNullableToJson( SimpleClassOfStringToNumNullable instance) => @@ -4271,13 +4040,12 @@ Map _$SimpleClassOfStringToNumNullableToJson( SimpleClassNullableOfStringToNumNullable _$SimpleClassNullableOfStringToNumNullableFromJson( - Map json) { - return SimpleClassNullableOfStringToNumNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(k, e as num?), - ), - ); -} + Map json) => + SimpleClassNullableOfStringToNumNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e as num?), + ), + ); Map _$SimpleClassNullableOfStringToNumNullableToJson( SimpleClassNullableOfStringToNumNullable instance) => @@ -4286,13 +4054,12 @@ Map _$SimpleClassNullableOfStringToNumNullableToJson( }; SimpleClassOfUriToNumNullable _$SimpleClassOfUriToNumNullableFromJson( - Map json) { - return SimpleClassOfUriToNumNullable( - (json['value'] as Map).map( - (k, e) => MapEntry(Uri.parse(k), e as num?), - ), - ); -} + Map json) => + SimpleClassOfUriToNumNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(Uri.parse(k), e as num?), + ), + ); Map _$SimpleClassOfUriToNumNullableToJson( SimpleClassOfUriToNumNullable instance) => @@ -4301,13 +4068,13 @@ Map _$SimpleClassOfUriToNumNullableToJson( }; SimpleClassNullableOfUriToNumNullable - _$SimpleClassNullableOfUriToNumNullableFromJson(Map json) { - return SimpleClassNullableOfUriToNumNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(Uri.parse(k), e as num?), - ), - ); -} + _$SimpleClassNullableOfUriToNumNullableFromJson( + Map json) => + SimpleClassNullableOfUriToNumNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(Uri.parse(k), e as num?), + ), + ); Map _$SimpleClassNullableOfUriToNumNullableToJson( SimpleClassNullableOfUriToNumNullable instance) => @@ -4316,13 +4083,12 @@ Map _$SimpleClassNullableOfUriToNumNullableToJson( }; SimpleClassOfBigIntToObject _$SimpleClassOfBigIntToObjectFromJson( - Map json) { - return SimpleClassOfBigIntToObject( - (json['value'] as Map).map( - (k, e) => MapEntry(BigInt.parse(k), e as Object), - ), - ); -} + Map json) => + SimpleClassOfBigIntToObject( + (json['value'] as Map).map( + (k, e) => MapEntry(BigInt.parse(k), e as Object), + ), + ); Map _$SimpleClassOfBigIntToObjectToJson( SimpleClassOfBigIntToObject instance) => @@ -4331,13 +4097,12 @@ Map _$SimpleClassOfBigIntToObjectToJson( }; SimpleClassNullableOfBigIntToObject - _$SimpleClassNullableOfBigIntToObjectFromJson(Map json) { - return SimpleClassNullableOfBigIntToObject( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(BigInt.parse(k), e as Object), - ), - ); -} + _$SimpleClassNullableOfBigIntToObjectFromJson(Map json) => + SimpleClassNullableOfBigIntToObject( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(BigInt.parse(k), e as Object), + ), + ); Map _$SimpleClassNullableOfBigIntToObjectToJson( SimpleClassNullableOfBigIntToObject instance) => @@ -4346,13 +4111,12 @@ Map _$SimpleClassNullableOfBigIntToObjectToJson( }; SimpleClassOfDateTimeToObject _$SimpleClassOfDateTimeToObjectFromJson( - Map json) { - return SimpleClassOfDateTimeToObject( - (json['value'] as Map).map( - (k, e) => MapEntry(DateTime.parse(k), e as Object), - ), - ); -} + Map json) => + SimpleClassOfDateTimeToObject( + (json['value'] as Map).map( + (k, e) => MapEntry(DateTime.parse(k), e as Object), + ), + ); Map _$SimpleClassOfDateTimeToObjectToJson( SimpleClassOfDateTimeToObject instance) => @@ -4361,13 +4125,13 @@ Map _$SimpleClassOfDateTimeToObjectToJson( }; SimpleClassNullableOfDateTimeToObject - _$SimpleClassNullableOfDateTimeToObjectFromJson(Map json) { - return SimpleClassNullableOfDateTimeToObject( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(DateTime.parse(k), e as Object), - ), - ); -} + _$SimpleClassNullableOfDateTimeToObjectFromJson( + Map json) => + SimpleClassNullableOfDateTimeToObject( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(DateTime.parse(k), e as Object), + ), + ); Map _$SimpleClassNullableOfDateTimeToObjectToJson( SimpleClassNullableOfDateTimeToObject instance) => @@ -4376,13 +4140,12 @@ Map _$SimpleClassNullableOfDateTimeToObjectToJson( }; SimpleClassOfDynamicToObject _$SimpleClassOfDynamicToObjectFromJson( - Map json) { - return SimpleClassOfDynamicToObject( - (json['value'] as Map).map( - (k, e) => MapEntry(k, e as Object), - ), - ); -} + Map json) => + SimpleClassOfDynamicToObject( + (json['value'] as Map).map( + (k, e) => MapEntry(k, e as Object), + ), + ); Map _$SimpleClassOfDynamicToObjectToJson( SimpleClassOfDynamicToObject instance) => @@ -4391,13 +4154,12 @@ Map _$SimpleClassOfDynamicToObjectToJson( }; SimpleClassNullableOfDynamicToObject - _$SimpleClassNullableOfDynamicToObjectFromJson(Map json) { - return SimpleClassNullableOfDynamicToObject( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(k, e as Object), - ), - ); -} + _$SimpleClassNullableOfDynamicToObjectFromJson(Map json) => + SimpleClassNullableOfDynamicToObject( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e as Object), + ), + ); Map _$SimpleClassNullableOfDynamicToObjectToJson( SimpleClassNullableOfDynamicToObject instance) => @@ -4406,13 +4168,12 @@ Map _$SimpleClassNullableOfDynamicToObjectToJson( }; SimpleClassOfEnumTypeToObject _$SimpleClassOfEnumTypeToObjectFromJson( - Map json) { - return SimpleClassOfEnumTypeToObject( - (json['value'] as Map).map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as Object), - ), - ); -} + Map json) => + SimpleClassOfEnumTypeToObject( + (json['value'] as Map).map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as Object), + ), + ); Map _$SimpleClassOfEnumTypeToObjectToJson( SimpleClassOfEnumTypeToObject instance) => @@ -4421,13 +4182,13 @@ Map _$SimpleClassOfEnumTypeToObjectToJson( }; SimpleClassNullableOfEnumTypeToObject - _$SimpleClassNullableOfEnumTypeToObjectFromJson(Map json) { - return SimpleClassNullableOfEnumTypeToObject( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as Object), - ), - ); -} + _$SimpleClassNullableOfEnumTypeToObjectFromJson( + Map json) => + SimpleClassNullableOfEnumTypeToObject( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as Object), + ), + ); Map _$SimpleClassNullableOfEnumTypeToObjectToJson( SimpleClassNullableOfEnumTypeToObject instance) => @@ -4436,13 +4197,12 @@ Map _$SimpleClassNullableOfEnumTypeToObjectToJson( }; SimpleClassOfIntToObject _$SimpleClassOfIntToObjectFromJson( - Map json) { - return SimpleClassOfIntToObject( - (json['value'] as Map).map( - (k, e) => MapEntry(int.parse(k), e as Object), - ), - ); -} + Map json) => + SimpleClassOfIntToObject( + (json['value'] as Map).map( + (k, e) => MapEntry(int.parse(k), e as Object), + ), + ); Map _$SimpleClassOfIntToObjectToJson( SimpleClassOfIntToObject instance) => @@ -4451,13 +4211,12 @@ Map _$SimpleClassOfIntToObjectToJson( }; SimpleClassNullableOfIntToObject _$SimpleClassNullableOfIntToObjectFromJson( - Map json) { - return SimpleClassNullableOfIntToObject( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(int.parse(k), e as Object), - ), - ); -} + Map json) => + SimpleClassNullableOfIntToObject( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(int.parse(k), e as Object), + ), + ); Map _$SimpleClassNullableOfIntToObjectToJson( SimpleClassNullableOfIntToObject instance) => @@ -4466,13 +4225,12 @@ Map _$SimpleClassNullableOfIntToObjectToJson( }; SimpleClassOfObjectToObject _$SimpleClassOfObjectToObjectFromJson( - Map json) { - return SimpleClassOfObjectToObject( - (json['value'] as Map).map( - (k, e) => MapEntry(k, e as Object), - ), - ); -} + Map json) => + SimpleClassOfObjectToObject( + (json['value'] as Map).map( + (k, e) => MapEntry(k, e as Object), + ), + ); Map _$SimpleClassOfObjectToObjectToJson( SimpleClassOfObjectToObject instance) => @@ -4481,13 +4239,12 @@ Map _$SimpleClassOfObjectToObjectToJson( }; SimpleClassNullableOfObjectToObject - _$SimpleClassNullableOfObjectToObjectFromJson(Map json) { - return SimpleClassNullableOfObjectToObject( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(k, e as Object), - ), - ); -} + _$SimpleClassNullableOfObjectToObjectFromJson(Map json) => + SimpleClassNullableOfObjectToObject( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e as Object), + ), + ); Map _$SimpleClassNullableOfObjectToObjectToJson( SimpleClassNullableOfObjectToObject instance) => @@ -4496,13 +4253,12 @@ Map _$SimpleClassNullableOfObjectToObjectToJson( }; SimpleClassOfStringToObject _$SimpleClassOfStringToObjectFromJson( - Map json) { - return SimpleClassOfStringToObject( - (json['value'] as Map).map( - (k, e) => MapEntry(k, e as Object), - ), - ); -} + Map json) => + SimpleClassOfStringToObject( + (json['value'] as Map).map( + (k, e) => MapEntry(k, e as Object), + ), + ); Map _$SimpleClassOfStringToObjectToJson( SimpleClassOfStringToObject instance) => @@ -4511,13 +4267,12 @@ Map _$SimpleClassOfStringToObjectToJson( }; SimpleClassNullableOfStringToObject - _$SimpleClassNullableOfStringToObjectFromJson(Map json) { - return SimpleClassNullableOfStringToObject( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(k, e as Object), - ), - ); -} + _$SimpleClassNullableOfStringToObjectFromJson(Map json) => + SimpleClassNullableOfStringToObject( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e as Object), + ), + ); Map _$SimpleClassNullableOfStringToObjectToJson( SimpleClassNullableOfStringToObject instance) => @@ -4526,13 +4281,12 @@ Map _$SimpleClassNullableOfStringToObjectToJson( }; SimpleClassOfUriToObject _$SimpleClassOfUriToObjectFromJson( - Map json) { - return SimpleClassOfUriToObject( - (json['value'] as Map).map( - (k, e) => MapEntry(Uri.parse(k), e as Object), - ), - ); -} + Map json) => + SimpleClassOfUriToObject( + (json['value'] as Map).map( + (k, e) => MapEntry(Uri.parse(k), e as Object), + ), + ); Map _$SimpleClassOfUriToObjectToJson( SimpleClassOfUriToObject instance) => @@ -4541,13 +4295,12 @@ Map _$SimpleClassOfUriToObjectToJson( }; SimpleClassNullableOfUriToObject _$SimpleClassNullableOfUriToObjectFromJson( - Map json) { - return SimpleClassNullableOfUriToObject( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(Uri.parse(k), e as Object), - ), - ); -} + Map json) => + SimpleClassNullableOfUriToObject( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(Uri.parse(k), e as Object), + ), + ); Map _$SimpleClassNullableOfUriToObjectToJson( SimpleClassNullableOfUriToObject instance) => @@ -4556,13 +4309,12 @@ Map _$SimpleClassNullableOfUriToObjectToJson( }; SimpleClassOfBigIntToObjectNullable - _$SimpleClassOfBigIntToObjectNullableFromJson(Map json) { - return SimpleClassOfBigIntToObjectNullable( - (json['value'] as Map).map( - (k, e) => MapEntry(BigInt.parse(k), e), - ), - ); -} + _$SimpleClassOfBigIntToObjectNullableFromJson(Map json) => + SimpleClassOfBigIntToObjectNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(BigInt.parse(k), e), + ), + ); Map _$SimpleClassOfBigIntToObjectNullableToJson( SimpleClassOfBigIntToObjectNullable instance) => @@ -4572,13 +4324,12 @@ Map _$SimpleClassOfBigIntToObjectNullableToJson( SimpleClassNullableOfBigIntToObjectNullable _$SimpleClassNullableOfBigIntToObjectNullableFromJson( - Map json) { - return SimpleClassNullableOfBigIntToObjectNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(BigInt.parse(k), e), - ), - ); -} + Map json) => + SimpleClassNullableOfBigIntToObjectNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(BigInt.parse(k), e), + ), + ); Map _$SimpleClassNullableOfBigIntToObjectNullableToJson( SimpleClassNullableOfBigIntToObjectNullable instance) => @@ -4587,13 +4338,13 @@ Map _$SimpleClassNullableOfBigIntToObjectNullableToJson( }; SimpleClassOfDateTimeToObjectNullable - _$SimpleClassOfDateTimeToObjectNullableFromJson(Map json) { - return SimpleClassOfDateTimeToObjectNullable( - (json['value'] as Map).map( - (k, e) => MapEntry(DateTime.parse(k), e), - ), - ); -} + _$SimpleClassOfDateTimeToObjectNullableFromJson( + Map json) => + SimpleClassOfDateTimeToObjectNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(DateTime.parse(k), e), + ), + ); Map _$SimpleClassOfDateTimeToObjectNullableToJson( SimpleClassOfDateTimeToObjectNullable instance) => @@ -4603,13 +4354,12 @@ Map _$SimpleClassOfDateTimeToObjectNullableToJson( SimpleClassNullableOfDateTimeToObjectNullable _$SimpleClassNullableOfDateTimeToObjectNullableFromJson( - Map json) { - return SimpleClassNullableOfDateTimeToObjectNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(DateTime.parse(k), e), - ), - ); -} + Map json) => + SimpleClassNullableOfDateTimeToObjectNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(DateTime.parse(k), e), + ), + ); Map _$SimpleClassNullableOfDateTimeToObjectNullableToJson( SimpleClassNullableOfDateTimeToObjectNullable instance) => @@ -4618,11 +4368,10 @@ Map _$SimpleClassNullableOfDateTimeToObjectNullableToJson( }; SimpleClassOfDynamicToObjectNullable - _$SimpleClassOfDynamicToObjectNullableFromJson(Map json) { - return SimpleClassOfDynamicToObjectNullable( - json['value'] as Map, - ); -} + _$SimpleClassOfDynamicToObjectNullableFromJson(Map json) => + SimpleClassOfDynamicToObjectNullable( + json['value'] as Map, + ); Map _$SimpleClassOfDynamicToObjectNullableToJson( SimpleClassOfDynamicToObjectNullable instance) => @@ -4632,11 +4381,10 @@ Map _$SimpleClassOfDynamicToObjectNullableToJson( SimpleClassNullableOfDynamicToObjectNullable _$SimpleClassNullableOfDynamicToObjectNullableFromJson( - Map json) { - return SimpleClassNullableOfDynamicToObjectNullable( - json['value'] as Map?, - ); -} + Map json) => + SimpleClassNullableOfDynamicToObjectNullable( + json['value'] as Map?, + ); Map _$SimpleClassNullableOfDynamicToObjectNullableToJson( SimpleClassNullableOfDynamicToObjectNullable instance) => @@ -4645,13 +4393,13 @@ Map _$SimpleClassNullableOfDynamicToObjectNullableToJson( }; SimpleClassOfEnumTypeToObjectNullable - _$SimpleClassOfEnumTypeToObjectNullableFromJson(Map json) { - return SimpleClassOfEnumTypeToObjectNullable( - (json['value'] as Map).map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e), - ), - ); -} + _$SimpleClassOfEnumTypeToObjectNullableFromJson( + Map json) => + SimpleClassOfEnumTypeToObjectNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e), + ), + ); Map _$SimpleClassOfEnumTypeToObjectNullableToJson( SimpleClassOfEnumTypeToObjectNullable instance) => @@ -4661,13 +4409,12 @@ Map _$SimpleClassOfEnumTypeToObjectNullableToJson( SimpleClassNullableOfEnumTypeToObjectNullable _$SimpleClassNullableOfEnumTypeToObjectNullableFromJson( - Map json) { - return SimpleClassNullableOfEnumTypeToObjectNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e), - ), - ); -} + Map json) => + SimpleClassNullableOfEnumTypeToObjectNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e), + ), + ); Map _$SimpleClassNullableOfEnumTypeToObjectNullableToJson( SimpleClassNullableOfEnumTypeToObjectNullable instance) => @@ -4676,13 +4423,12 @@ Map _$SimpleClassNullableOfEnumTypeToObjectNullableToJson( }; SimpleClassOfIntToObjectNullable _$SimpleClassOfIntToObjectNullableFromJson( - Map json) { - return SimpleClassOfIntToObjectNullable( - (json['value'] as Map).map( - (k, e) => MapEntry(int.parse(k), e), - ), - ); -} + Map json) => + SimpleClassOfIntToObjectNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(int.parse(k), e), + ), + ); Map _$SimpleClassOfIntToObjectNullableToJson( SimpleClassOfIntToObjectNullable instance) => @@ -4692,13 +4438,12 @@ Map _$SimpleClassOfIntToObjectNullableToJson( SimpleClassNullableOfIntToObjectNullable _$SimpleClassNullableOfIntToObjectNullableFromJson( - Map json) { - return SimpleClassNullableOfIntToObjectNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(int.parse(k), e), - ), - ); -} + Map json) => + SimpleClassNullableOfIntToObjectNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(int.parse(k), e), + ), + ); Map _$SimpleClassNullableOfIntToObjectNullableToJson( SimpleClassNullableOfIntToObjectNullable instance) => @@ -4707,11 +4452,10 @@ Map _$SimpleClassNullableOfIntToObjectNullableToJson( }; SimpleClassOfObjectToObjectNullable - _$SimpleClassOfObjectToObjectNullableFromJson(Map json) { - return SimpleClassOfObjectToObjectNullable( - json['value'] as Map, - ); -} + _$SimpleClassOfObjectToObjectNullableFromJson(Map json) => + SimpleClassOfObjectToObjectNullable( + json['value'] as Map, + ); Map _$SimpleClassOfObjectToObjectNullableToJson( SimpleClassOfObjectToObjectNullable instance) => @@ -4721,11 +4465,10 @@ Map _$SimpleClassOfObjectToObjectNullableToJson( SimpleClassNullableOfObjectToObjectNullable _$SimpleClassNullableOfObjectToObjectNullableFromJson( - Map json) { - return SimpleClassNullableOfObjectToObjectNullable( - json['value'] as Map?, - ); -} + Map json) => + SimpleClassNullableOfObjectToObjectNullable( + json['value'] as Map?, + ); Map _$SimpleClassNullableOfObjectToObjectNullableToJson( SimpleClassNullableOfObjectToObjectNullable instance) => @@ -4734,11 +4477,10 @@ Map _$SimpleClassNullableOfObjectToObjectNullableToJson( }; SimpleClassOfStringToObjectNullable - _$SimpleClassOfStringToObjectNullableFromJson(Map json) { - return SimpleClassOfStringToObjectNullable( - json['value'] as Map, - ); -} + _$SimpleClassOfStringToObjectNullableFromJson(Map json) => + SimpleClassOfStringToObjectNullable( + json['value'] as Map, + ); Map _$SimpleClassOfStringToObjectNullableToJson( SimpleClassOfStringToObjectNullable instance) => @@ -4748,11 +4490,10 @@ Map _$SimpleClassOfStringToObjectNullableToJson( SimpleClassNullableOfStringToObjectNullable _$SimpleClassNullableOfStringToObjectNullableFromJson( - Map json) { - return SimpleClassNullableOfStringToObjectNullable( - json['value'] as Map?, - ); -} + Map json) => + SimpleClassNullableOfStringToObjectNullable( + json['value'] as Map?, + ); Map _$SimpleClassNullableOfStringToObjectNullableToJson( SimpleClassNullableOfStringToObjectNullable instance) => @@ -4761,13 +4502,12 @@ Map _$SimpleClassNullableOfStringToObjectNullableToJson( }; SimpleClassOfUriToObjectNullable _$SimpleClassOfUriToObjectNullableFromJson( - Map json) { - return SimpleClassOfUriToObjectNullable( - (json['value'] as Map).map( - (k, e) => MapEntry(Uri.parse(k), e), - ), - ); -} + Map json) => + SimpleClassOfUriToObjectNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(Uri.parse(k), e), + ), + ); Map _$SimpleClassOfUriToObjectNullableToJson( SimpleClassOfUriToObjectNullable instance) => @@ -4777,13 +4517,12 @@ Map _$SimpleClassOfUriToObjectNullableToJson( SimpleClassNullableOfUriToObjectNullable _$SimpleClassNullableOfUriToObjectNullableFromJson( - Map json) { - return SimpleClassNullableOfUriToObjectNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(Uri.parse(k), e), - ), - ); -} + Map json) => + SimpleClassNullableOfUriToObjectNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(Uri.parse(k), e), + ), + ); Map _$SimpleClassNullableOfUriToObjectNullableToJson( SimpleClassNullableOfUriToObjectNullable instance) => @@ -4792,13 +4531,12 @@ Map _$SimpleClassNullableOfUriToObjectNullableToJson( }; SimpleClassOfBigIntToString _$SimpleClassOfBigIntToStringFromJson( - Map json) { - return SimpleClassOfBigIntToString( - (json['value'] as Map).map( - (k, e) => MapEntry(BigInt.parse(k), e as String), - ), - ); -} + Map json) => + SimpleClassOfBigIntToString( + (json['value'] as Map).map( + (k, e) => MapEntry(BigInt.parse(k), e as String), + ), + ); Map _$SimpleClassOfBigIntToStringToJson( SimpleClassOfBigIntToString instance) => @@ -4807,13 +4545,12 @@ Map _$SimpleClassOfBigIntToStringToJson( }; SimpleClassNullableOfBigIntToString - _$SimpleClassNullableOfBigIntToStringFromJson(Map json) { - return SimpleClassNullableOfBigIntToString( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(BigInt.parse(k), e as String), - ), - ); -} + _$SimpleClassNullableOfBigIntToStringFromJson(Map json) => + SimpleClassNullableOfBigIntToString( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(BigInt.parse(k), e as String), + ), + ); Map _$SimpleClassNullableOfBigIntToStringToJson( SimpleClassNullableOfBigIntToString instance) => @@ -4822,13 +4559,12 @@ Map _$SimpleClassNullableOfBigIntToStringToJson( }; SimpleClassOfDateTimeToString _$SimpleClassOfDateTimeToStringFromJson( - Map json) { - return SimpleClassOfDateTimeToString( - (json['value'] as Map).map( - (k, e) => MapEntry(DateTime.parse(k), e as String), - ), - ); -} + Map json) => + SimpleClassOfDateTimeToString( + (json['value'] as Map).map( + (k, e) => MapEntry(DateTime.parse(k), e as String), + ), + ); Map _$SimpleClassOfDateTimeToStringToJson( SimpleClassOfDateTimeToString instance) => @@ -4837,13 +4573,13 @@ Map _$SimpleClassOfDateTimeToStringToJson( }; SimpleClassNullableOfDateTimeToString - _$SimpleClassNullableOfDateTimeToStringFromJson(Map json) { - return SimpleClassNullableOfDateTimeToString( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(DateTime.parse(k), e as String), - ), - ); -} + _$SimpleClassNullableOfDateTimeToStringFromJson( + Map json) => + SimpleClassNullableOfDateTimeToString( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(DateTime.parse(k), e as String), + ), + ); Map _$SimpleClassNullableOfDateTimeToStringToJson( SimpleClassNullableOfDateTimeToString instance) => @@ -4852,11 +4588,10 @@ Map _$SimpleClassNullableOfDateTimeToStringToJson( }; SimpleClassOfDynamicToString _$SimpleClassOfDynamicToStringFromJson( - Map json) { - return SimpleClassOfDynamicToString( - Map.from(json['value'] as Map), - ); -} + Map json) => + SimpleClassOfDynamicToString( + Map.from(json['value'] as Map), + ); Map _$SimpleClassOfDynamicToStringToJson( SimpleClassOfDynamicToString instance) => @@ -4865,13 +4600,12 @@ Map _$SimpleClassOfDynamicToStringToJson( }; SimpleClassNullableOfDynamicToString - _$SimpleClassNullableOfDynamicToStringFromJson(Map json) { - return SimpleClassNullableOfDynamicToString( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(k, e as String), - ), - ); -} + _$SimpleClassNullableOfDynamicToStringFromJson(Map json) => + SimpleClassNullableOfDynamicToString( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e as String), + ), + ); Map _$SimpleClassNullableOfDynamicToStringToJson( SimpleClassNullableOfDynamicToString instance) => @@ -4880,13 +4614,12 @@ Map _$SimpleClassNullableOfDynamicToStringToJson( }; SimpleClassOfEnumTypeToString _$SimpleClassOfEnumTypeToStringFromJson( - Map json) { - return SimpleClassOfEnumTypeToString( - (json['value'] as Map).map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as String), - ), - ); -} + Map json) => + SimpleClassOfEnumTypeToString( + (json['value'] as Map).map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as String), + ), + ); Map _$SimpleClassOfEnumTypeToStringToJson( SimpleClassOfEnumTypeToString instance) => @@ -4895,13 +4628,13 @@ Map _$SimpleClassOfEnumTypeToStringToJson( }; SimpleClassNullableOfEnumTypeToString - _$SimpleClassNullableOfEnumTypeToStringFromJson(Map json) { - return SimpleClassNullableOfEnumTypeToString( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as String), - ), - ); -} + _$SimpleClassNullableOfEnumTypeToStringFromJson( + Map json) => + SimpleClassNullableOfEnumTypeToString( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as String), + ), + ); Map _$SimpleClassNullableOfEnumTypeToStringToJson( SimpleClassNullableOfEnumTypeToString instance) => @@ -4910,13 +4643,12 @@ Map _$SimpleClassNullableOfEnumTypeToStringToJson( }; SimpleClassOfIntToString _$SimpleClassOfIntToStringFromJson( - Map json) { - return SimpleClassOfIntToString( - (json['value'] as Map).map( - (k, e) => MapEntry(int.parse(k), e as String), - ), - ); -} + Map json) => + SimpleClassOfIntToString( + (json['value'] as Map).map( + (k, e) => MapEntry(int.parse(k), e as String), + ), + ); Map _$SimpleClassOfIntToStringToJson( SimpleClassOfIntToString instance) => @@ -4925,13 +4657,12 @@ Map _$SimpleClassOfIntToStringToJson( }; SimpleClassNullableOfIntToString _$SimpleClassNullableOfIntToStringFromJson( - Map json) { - return SimpleClassNullableOfIntToString( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(int.parse(k), e as String), - ), - ); -} + Map json) => + SimpleClassNullableOfIntToString( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(int.parse(k), e as String), + ), + ); Map _$SimpleClassNullableOfIntToStringToJson( SimpleClassNullableOfIntToString instance) => @@ -4940,11 +4671,10 @@ Map _$SimpleClassNullableOfIntToStringToJson( }; SimpleClassOfObjectToString _$SimpleClassOfObjectToStringFromJson( - Map json) { - return SimpleClassOfObjectToString( - Map.from(json['value'] as Map), - ); -} + Map json) => + SimpleClassOfObjectToString( + Map.from(json['value'] as Map), + ); Map _$SimpleClassOfObjectToStringToJson( SimpleClassOfObjectToString instance) => @@ -4953,13 +4683,12 @@ Map _$SimpleClassOfObjectToStringToJson( }; SimpleClassNullableOfObjectToString - _$SimpleClassNullableOfObjectToStringFromJson(Map json) { - return SimpleClassNullableOfObjectToString( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(k, e as String), - ), - ); -} + _$SimpleClassNullableOfObjectToStringFromJson(Map json) => + SimpleClassNullableOfObjectToString( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e as String), + ), + ); Map _$SimpleClassNullableOfObjectToStringToJson( SimpleClassNullableOfObjectToString instance) => @@ -4968,11 +4697,10 @@ Map _$SimpleClassNullableOfObjectToStringToJson( }; SimpleClassOfStringToString _$SimpleClassOfStringToStringFromJson( - Map json) { - return SimpleClassOfStringToString( - Map.from(json['value'] as Map), - ); -} + Map json) => + SimpleClassOfStringToString( + Map.from(json['value'] as Map), + ); Map _$SimpleClassOfStringToStringToJson( SimpleClassOfStringToString instance) => @@ -4981,13 +4709,12 @@ Map _$SimpleClassOfStringToStringToJson( }; SimpleClassNullableOfStringToString - _$SimpleClassNullableOfStringToStringFromJson(Map json) { - return SimpleClassNullableOfStringToString( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(k, e as String), - ), - ); -} + _$SimpleClassNullableOfStringToStringFromJson(Map json) => + SimpleClassNullableOfStringToString( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e as String), + ), + ); Map _$SimpleClassNullableOfStringToStringToJson( SimpleClassNullableOfStringToString instance) => @@ -4996,13 +4723,12 @@ Map _$SimpleClassNullableOfStringToStringToJson( }; SimpleClassOfUriToString _$SimpleClassOfUriToStringFromJson( - Map json) { - return SimpleClassOfUriToString( - (json['value'] as Map).map( - (k, e) => MapEntry(Uri.parse(k), e as String), - ), - ); -} + Map json) => + SimpleClassOfUriToString( + (json['value'] as Map).map( + (k, e) => MapEntry(Uri.parse(k), e as String), + ), + ); Map _$SimpleClassOfUriToStringToJson( SimpleClassOfUriToString instance) => @@ -5011,13 +4737,12 @@ Map _$SimpleClassOfUriToStringToJson( }; SimpleClassNullableOfUriToString _$SimpleClassNullableOfUriToStringFromJson( - Map json) { - return SimpleClassNullableOfUriToString( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(Uri.parse(k), e as String), - ), - ); -} + Map json) => + SimpleClassNullableOfUriToString( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(Uri.parse(k), e as String), + ), + ); Map _$SimpleClassNullableOfUriToStringToJson( SimpleClassNullableOfUriToString instance) => @@ -5026,13 +4751,12 @@ Map _$SimpleClassNullableOfUriToStringToJson( }; SimpleClassOfBigIntToStringNullable - _$SimpleClassOfBigIntToStringNullableFromJson(Map json) { - return SimpleClassOfBigIntToStringNullable( - (json['value'] as Map).map( - (k, e) => MapEntry(BigInt.parse(k), e as String?), - ), - ); -} + _$SimpleClassOfBigIntToStringNullableFromJson(Map json) => + SimpleClassOfBigIntToStringNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(BigInt.parse(k), e as String?), + ), + ); Map _$SimpleClassOfBigIntToStringNullableToJson( SimpleClassOfBigIntToStringNullable instance) => @@ -5042,13 +4766,12 @@ Map _$SimpleClassOfBigIntToStringNullableToJson( SimpleClassNullableOfBigIntToStringNullable _$SimpleClassNullableOfBigIntToStringNullableFromJson( - Map json) { - return SimpleClassNullableOfBigIntToStringNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(BigInt.parse(k), e as String?), - ), - ); -} + Map json) => + SimpleClassNullableOfBigIntToStringNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(BigInt.parse(k), e as String?), + ), + ); Map _$SimpleClassNullableOfBigIntToStringNullableToJson( SimpleClassNullableOfBigIntToStringNullable instance) => @@ -5057,13 +4780,13 @@ Map _$SimpleClassNullableOfBigIntToStringNullableToJson( }; SimpleClassOfDateTimeToStringNullable - _$SimpleClassOfDateTimeToStringNullableFromJson(Map json) { - return SimpleClassOfDateTimeToStringNullable( - (json['value'] as Map).map( - (k, e) => MapEntry(DateTime.parse(k), e as String?), - ), - ); -} + _$SimpleClassOfDateTimeToStringNullableFromJson( + Map json) => + SimpleClassOfDateTimeToStringNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(DateTime.parse(k), e as String?), + ), + ); Map _$SimpleClassOfDateTimeToStringNullableToJson( SimpleClassOfDateTimeToStringNullable instance) => @@ -5073,13 +4796,12 @@ Map _$SimpleClassOfDateTimeToStringNullableToJson( SimpleClassNullableOfDateTimeToStringNullable _$SimpleClassNullableOfDateTimeToStringNullableFromJson( - Map json) { - return SimpleClassNullableOfDateTimeToStringNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(DateTime.parse(k), e as String?), - ), - ); -} + Map json) => + SimpleClassNullableOfDateTimeToStringNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(DateTime.parse(k), e as String?), + ), + ); Map _$SimpleClassNullableOfDateTimeToStringNullableToJson( SimpleClassNullableOfDateTimeToStringNullable instance) => @@ -5088,11 +4810,10 @@ Map _$SimpleClassNullableOfDateTimeToStringNullableToJson( }; SimpleClassOfDynamicToStringNullable - _$SimpleClassOfDynamicToStringNullableFromJson(Map json) { - return SimpleClassOfDynamicToStringNullable( - Map.from(json['value'] as Map), - ); -} + _$SimpleClassOfDynamicToStringNullableFromJson(Map json) => + SimpleClassOfDynamicToStringNullable( + Map.from(json['value'] as Map), + ); Map _$SimpleClassOfDynamicToStringNullableToJson( SimpleClassOfDynamicToStringNullable instance) => @@ -5102,13 +4823,12 @@ Map _$SimpleClassOfDynamicToStringNullableToJson( SimpleClassNullableOfDynamicToStringNullable _$SimpleClassNullableOfDynamicToStringNullableFromJson( - Map json) { - return SimpleClassNullableOfDynamicToStringNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(k, e as String?), - ), - ); -} + Map json) => + SimpleClassNullableOfDynamicToStringNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e as String?), + ), + ); Map _$SimpleClassNullableOfDynamicToStringNullableToJson( SimpleClassNullableOfDynamicToStringNullable instance) => @@ -5117,13 +4837,14 @@ Map _$SimpleClassNullableOfDynamicToStringNullableToJson( }; SimpleClassOfEnumTypeToStringNullable - _$SimpleClassOfEnumTypeToStringNullableFromJson(Map json) { - return SimpleClassOfEnumTypeToStringNullable( - (json['value'] as Map).map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as String?), - ), - ); -} + _$SimpleClassOfEnumTypeToStringNullableFromJson( + Map json) => + SimpleClassOfEnumTypeToStringNullable( + (json['value'] as Map).map( + (k, e) => + MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as String?), + ), + ); Map _$SimpleClassOfEnumTypeToStringNullableToJson( SimpleClassOfEnumTypeToStringNullable instance) => @@ -5133,13 +4854,13 @@ Map _$SimpleClassOfEnumTypeToStringNullableToJson( SimpleClassNullableOfEnumTypeToStringNullable _$SimpleClassNullableOfEnumTypeToStringNullableFromJson( - Map json) { - return SimpleClassNullableOfEnumTypeToStringNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as String?), - ), - ); -} + Map json) => + SimpleClassNullableOfEnumTypeToStringNullable( + (json['value'] as Map?)?.map( + (k, e) => + MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as String?), + ), + ); Map _$SimpleClassNullableOfEnumTypeToStringNullableToJson( SimpleClassNullableOfEnumTypeToStringNullable instance) => @@ -5148,13 +4869,12 @@ Map _$SimpleClassNullableOfEnumTypeToStringNullableToJson( }; SimpleClassOfIntToStringNullable _$SimpleClassOfIntToStringNullableFromJson( - Map json) { - return SimpleClassOfIntToStringNullable( - (json['value'] as Map).map( - (k, e) => MapEntry(int.parse(k), e as String?), - ), - ); -} + Map json) => + SimpleClassOfIntToStringNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(int.parse(k), e as String?), + ), + ); Map _$SimpleClassOfIntToStringNullableToJson( SimpleClassOfIntToStringNullable instance) => @@ -5164,13 +4884,12 @@ Map _$SimpleClassOfIntToStringNullableToJson( SimpleClassNullableOfIntToStringNullable _$SimpleClassNullableOfIntToStringNullableFromJson( - Map json) { - return SimpleClassNullableOfIntToStringNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(int.parse(k), e as String?), - ), - ); -} + Map json) => + SimpleClassNullableOfIntToStringNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(int.parse(k), e as String?), + ), + ); Map _$SimpleClassNullableOfIntToStringNullableToJson( SimpleClassNullableOfIntToStringNullable instance) => @@ -5179,11 +4898,10 @@ Map _$SimpleClassNullableOfIntToStringNullableToJson( }; SimpleClassOfObjectToStringNullable - _$SimpleClassOfObjectToStringNullableFromJson(Map json) { - return SimpleClassOfObjectToStringNullable( - Map.from(json['value'] as Map), - ); -} + _$SimpleClassOfObjectToStringNullableFromJson(Map json) => + SimpleClassOfObjectToStringNullable( + Map.from(json['value'] as Map), + ); Map _$SimpleClassOfObjectToStringNullableToJson( SimpleClassOfObjectToStringNullable instance) => @@ -5193,13 +4911,12 @@ Map _$SimpleClassOfObjectToStringNullableToJson( SimpleClassNullableOfObjectToStringNullable _$SimpleClassNullableOfObjectToStringNullableFromJson( - Map json) { - return SimpleClassNullableOfObjectToStringNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(k, e as String?), - ), - ); -} + Map json) => + SimpleClassNullableOfObjectToStringNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e as String?), + ), + ); Map _$SimpleClassNullableOfObjectToStringNullableToJson( SimpleClassNullableOfObjectToStringNullable instance) => @@ -5208,11 +4925,10 @@ Map _$SimpleClassNullableOfObjectToStringNullableToJson( }; SimpleClassOfStringToStringNullable - _$SimpleClassOfStringToStringNullableFromJson(Map json) { - return SimpleClassOfStringToStringNullable( - Map.from(json['value'] as Map), - ); -} + _$SimpleClassOfStringToStringNullableFromJson(Map json) => + SimpleClassOfStringToStringNullable( + Map.from(json['value'] as Map), + ); Map _$SimpleClassOfStringToStringNullableToJson( SimpleClassOfStringToStringNullable instance) => @@ -5222,13 +4938,12 @@ Map _$SimpleClassOfStringToStringNullableToJson( SimpleClassNullableOfStringToStringNullable _$SimpleClassNullableOfStringToStringNullableFromJson( - Map json) { - return SimpleClassNullableOfStringToStringNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(k, e as String?), - ), - ); -} + Map json) => + SimpleClassNullableOfStringToStringNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e as String?), + ), + ); Map _$SimpleClassNullableOfStringToStringNullableToJson( SimpleClassNullableOfStringToStringNullable instance) => @@ -5237,13 +4952,12 @@ Map _$SimpleClassNullableOfStringToStringNullableToJson( }; SimpleClassOfUriToStringNullable _$SimpleClassOfUriToStringNullableFromJson( - Map json) { - return SimpleClassOfUriToStringNullable( - (json['value'] as Map).map( - (k, e) => MapEntry(Uri.parse(k), e as String?), - ), - ); -} + Map json) => + SimpleClassOfUriToStringNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(Uri.parse(k), e as String?), + ), + ); Map _$SimpleClassOfUriToStringNullableToJson( SimpleClassOfUriToStringNullable instance) => @@ -5253,13 +4967,12 @@ Map _$SimpleClassOfUriToStringNullableToJson( SimpleClassNullableOfUriToStringNullable _$SimpleClassNullableOfUriToStringNullableFromJson( - Map json) { - return SimpleClassNullableOfUriToStringNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(Uri.parse(k), e as String?), - ), - ); -} + Map json) => + SimpleClassNullableOfUriToStringNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(Uri.parse(k), e as String?), + ), + ); Map _$SimpleClassNullableOfUriToStringNullableToJson( SimpleClassNullableOfUriToStringNullable instance) => @@ -5268,13 +4981,12 @@ Map _$SimpleClassNullableOfUriToStringNullableToJson( }; SimpleClassOfBigIntToUri _$SimpleClassOfBigIntToUriFromJson( - Map json) { - return SimpleClassOfBigIntToUri( - (json['value'] as Map).map( - (k, e) => MapEntry(BigInt.parse(k), Uri.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassOfBigIntToUri( + (json['value'] as Map).map( + (k, e) => MapEntry(BigInt.parse(k), Uri.parse(e as String)), + ), + ); Map _$SimpleClassOfBigIntToUriToJson( SimpleClassOfBigIntToUri instance) => @@ -5284,13 +4996,12 @@ Map _$SimpleClassOfBigIntToUriToJson( }; SimpleClassNullableOfBigIntToUri _$SimpleClassNullableOfBigIntToUriFromJson( - Map json) { - return SimpleClassNullableOfBigIntToUri( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(BigInt.parse(k), Uri.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassNullableOfBigIntToUri( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(BigInt.parse(k), Uri.parse(e as String)), + ), + ); Map _$SimpleClassNullableOfBigIntToUriToJson( SimpleClassNullableOfBigIntToUri instance) => @@ -5300,13 +5011,12 @@ Map _$SimpleClassNullableOfBigIntToUriToJson( }; SimpleClassOfDateTimeToUri _$SimpleClassOfDateTimeToUriFromJson( - Map json) { - return SimpleClassOfDateTimeToUri( - (json['value'] as Map).map( - (k, e) => MapEntry(DateTime.parse(k), Uri.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassOfDateTimeToUri( + (json['value'] as Map).map( + (k, e) => MapEntry(DateTime.parse(k), Uri.parse(e as String)), + ), + ); Map _$SimpleClassOfDateTimeToUriToJson( SimpleClassOfDateTimeToUri instance) => @@ -5316,13 +5026,12 @@ Map _$SimpleClassOfDateTimeToUriToJson( }; SimpleClassNullableOfDateTimeToUri _$SimpleClassNullableOfDateTimeToUriFromJson( - Map json) { - return SimpleClassNullableOfDateTimeToUri( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(DateTime.parse(k), Uri.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassNullableOfDateTimeToUri( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(DateTime.parse(k), Uri.parse(e as String)), + ), + ); Map _$SimpleClassNullableOfDateTimeToUriToJson( SimpleClassNullableOfDateTimeToUri instance) => @@ -5332,13 +5041,12 @@ Map _$SimpleClassNullableOfDateTimeToUriToJson( }; SimpleClassOfDynamicToUri _$SimpleClassOfDynamicToUriFromJson( - Map json) { - return SimpleClassOfDynamicToUri( - (json['value'] as Map).map( - (k, e) => MapEntry(k, Uri.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassOfDynamicToUri( + (json['value'] as Map).map( + (k, e) => MapEntry(k, Uri.parse(e as String)), + ), + ); Map _$SimpleClassOfDynamicToUriToJson( SimpleClassOfDynamicToUri instance) => @@ -5347,13 +5055,12 @@ Map _$SimpleClassOfDynamicToUriToJson( }; SimpleClassNullableOfDynamicToUri _$SimpleClassNullableOfDynamicToUriFromJson( - Map json) { - return SimpleClassNullableOfDynamicToUri( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(k, Uri.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassNullableOfDynamicToUri( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, Uri.parse(e as String)), + ), + ); Map _$SimpleClassNullableOfDynamicToUriToJson( SimpleClassNullableOfDynamicToUri instance) => @@ -5362,14 +5069,13 @@ Map _$SimpleClassNullableOfDynamicToUriToJson( }; SimpleClassOfEnumTypeToUri _$SimpleClassOfEnumTypeToUriFromJson( - Map json) { - return SimpleClassOfEnumTypeToUri( - (json['value'] as Map).map( - (k, e) => - MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), Uri.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassOfEnumTypeToUri( + (json['value'] as Map).map( + (k, e) => MapEntry( + _$enumDecode(_$EnumTypeEnumMap, k), Uri.parse(e as String)), + ), + ); Map _$SimpleClassOfEnumTypeToUriToJson( SimpleClassOfEnumTypeToUri instance) => @@ -5379,14 +5085,13 @@ Map _$SimpleClassOfEnumTypeToUriToJson( }; SimpleClassNullableOfEnumTypeToUri _$SimpleClassNullableOfEnumTypeToUriFromJson( - Map json) { - return SimpleClassNullableOfEnumTypeToUri( - (json['value'] as Map?)?.map( - (k, e) => - MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), Uri.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassNullableOfEnumTypeToUri( + (json['value'] as Map?)?.map( + (k, e) => MapEntry( + _$enumDecode(_$EnumTypeEnumMap, k), Uri.parse(e as String)), + ), + ); Map _$SimpleClassNullableOfEnumTypeToUriToJson( SimpleClassNullableOfEnumTypeToUri instance) => @@ -5396,13 +5101,12 @@ Map _$SimpleClassNullableOfEnumTypeToUriToJson( }; SimpleClassOfIntToUri _$SimpleClassOfIntToUriFromJson( - Map json) { - return SimpleClassOfIntToUri( - (json['value'] as Map).map( - (k, e) => MapEntry(int.parse(k), Uri.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassOfIntToUri( + (json['value'] as Map).map( + (k, e) => MapEntry(int.parse(k), Uri.parse(e as String)), + ), + ); Map _$SimpleClassOfIntToUriToJson( SimpleClassOfIntToUri instance) => @@ -5412,13 +5116,12 @@ Map _$SimpleClassOfIntToUriToJson( }; SimpleClassNullableOfIntToUri _$SimpleClassNullableOfIntToUriFromJson( - Map json) { - return SimpleClassNullableOfIntToUri( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(int.parse(k), Uri.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassNullableOfIntToUri( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(int.parse(k), Uri.parse(e as String)), + ), + ); Map _$SimpleClassNullableOfIntToUriToJson( SimpleClassNullableOfIntToUri instance) => @@ -5428,13 +5131,12 @@ Map _$SimpleClassNullableOfIntToUriToJson( }; SimpleClassOfObjectToUri _$SimpleClassOfObjectToUriFromJson( - Map json) { - return SimpleClassOfObjectToUri( - (json['value'] as Map).map( - (k, e) => MapEntry(k, Uri.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassOfObjectToUri( + (json['value'] as Map).map( + (k, e) => MapEntry(k, Uri.parse(e as String)), + ), + ); Map _$SimpleClassOfObjectToUriToJson( SimpleClassOfObjectToUri instance) => @@ -5443,13 +5145,12 @@ Map _$SimpleClassOfObjectToUriToJson( }; SimpleClassNullableOfObjectToUri _$SimpleClassNullableOfObjectToUriFromJson( - Map json) { - return SimpleClassNullableOfObjectToUri( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(k, Uri.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassNullableOfObjectToUri( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, Uri.parse(e as String)), + ), + ); Map _$SimpleClassNullableOfObjectToUriToJson( SimpleClassNullableOfObjectToUri instance) => @@ -5458,13 +5159,12 @@ Map _$SimpleClassNullableOfObjectToUriToJson( }; SimpleClassOfStringToUri _$SimpleClassOfStringToUriFromJson( - Map json) { - return SimpleClassOfStringToUri( - (json['value'] as Map).map( - (k, e) => MapEntry(k, Uri.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassOfStringToUri( + (json['value'] as Map).map( + (k, e) => MapEntry(k, Uri.parse(e as String)), + ), + ); Map _$SimpleClassOfStringToUriToJson( SimpleClassOfStringToUri instance) => @@ -5473,13 +5173,12 @@ Map _$SimpleClassOfStringToUriToJson( }; SimpleClassNullableOfStringToUri _$SimpleClassNullableOfStringToUriFromJson( - Map json) { - return SimpleClassNullableOfStringToUri( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(k, Uri.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassNullableOfStringToUri( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, Uri.parse(e as String)), + ), + ); Map _$SimpleClassNullableOfStringToUriToJson( SimpleClassNullableOfStringToUri instance) => @@ -5488,13 +5187,12 @@ Map _$SimpleClassNullableOfStringToUriToJson( }; SimpleClassOfUriToUri _$SimpleClassOfUriToUriFromJson( - Map json) { - return SimpleClassOfUriToUri( - (json['value'] as Map).map( - (k, e) => MapEntry(Uri.parse(k), Uri.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassOfUriToUri( + (json['value'] as Map).map( + (k, e) => MapEntry(Uri.parse(k), Uri.parse(e as String)), + ), + ); Map _$SimpleClassOfUriToUriToJson( SimpleClassOfUriToUri instance) => @@ -5504,13 +5202,12 @@ Map _$SimpleClassOfUriToUriToJson( }; SimpleClassNullableOfUriToUri _$SimpleClassNullableOfUriToUriFromJson( - Map json) { - return SimpleClassNullableOfUriToUri( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(Uri.parse(k), Uri.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassNullableOfUriToUri( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(Uri.parse(k), Uri.parse(e as String)), + ), + ); Map _$SimpleClassNullableOfUriToUriToJson( SimpleClassNullableOfUriToUri instance) => @@ -5520,14 +5217,13 @@ Map _$SimpleClassNullableOfUriToUriToJson( }; SimpleClassOfBigIntToUriNullable _$SimpleClassOfBigIntToUriNullableFromJson( - Map json) { - return SimpleClassOfBigIntToUriNullable( - (json['value'] as Map).map( - (k, e) => - MapEntry(BigInt.parse(k), e == null ? null : Uri.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassOfBigIntToUriNullable( + (json['value'] as Map).map( + (k, e) => MapEntry( + BigInt.parse(k), e == null ? null : Uri.parse(e as String)), + ), + ); Map _$SimpleClassOfBigIntToUriNullableToJson( SimpleClassOfBigIntToUriNullable instance) => @@ -5538,14 +5234,13 @@ Map _$SimpleClassOfBigIntToUriNullableToJson( SimpleClassNullableOfBigIntToUriNullable _$SimpleClassNullableOfBigIntToUriNullableFromJson( - Map json) { - return SimpleClassNullableOfBigIntToUriNullable( - (json['value'] as Map?)?.map( - (k, e) => - MapEntry(BigInt.parse(k), e == null ? null : Uri.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassNullableOfBigIntToUriNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry( + BigInt.parse(k), e == null ? null : Uri.parse(e as String)), + ), + ); Map _$SimpleClassNullableOfBigIntToUriNullableToJson( SimpleClassNullableOfBigIntToUriNullable instance) => @@ -5555,14 +5250,13 @@ Map _$SimpleClassNullableOfBigIntToUriNullableToJson( }; SimpleClassOfDateTimeToUriNullable _$SimpleClassOfDateTimeToUriNullableFromJson( - Map json) { - return SimpleClassOfDateTimeToUriNullable( - (json['value'] as Map).map( - (k, e) => MapEntry( - DateTime.parse(k), e == null ? null : Uri.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassOfDateTimeToUriNullable( + (json['value'] as Map).map( + (k, e) => MapEntry( + DateTime.parse(k), e == null ? null : Uri.parse(e as String)), + ), + ); Map _$SimpleClassOfDateTimeToUriNullableToJson( SimpleClassOfDateTimeToUriNullable instance) => @@ -5573,14 +5267,13 @@ Map _$SimpleClassOfDateTimeToUriNullableToJson( SimpleClassNullableOfDateTimeToUriNullable _$SimpleClassNullableOfDateTimeToUriNullableFromJson( - Map json) { - return SimpleClassNullableOfDateTimeToUriNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry( - DateTime.parse(k), e == null ? null : Uri.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassNullableOfDateTimeToUriNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry( + DateTime.parse(k), e == null ? null : Uri.parse(e as String)), + ), + ); Map _$SimpleClassNullableOfDateTimeToUriNullableToJson( SimpleClassNullableOfDateTimeToUriNullable instance) => @@ -5590,13 +5283,12 @@ Map _$SimpleClassNullableOfDateTimeToUriNullableToJson( }; SimpleClassOfDynamicToUriNullable _$SimpleClassOfDynamicToUriNullableFromJson( - Map json) { - return SimpleClassOfDynamicToUriNullable( - (json['value'] as Map).map( - (k, e) => MapEntry(k, e == null ? null : Uri.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassOfDynamicToUriNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(k, e == null ? null : Uri.parse(e as String)), + ), + ); Map _$SimpleClassOfDynamicToUriNullableToJson( SimpleClassOfDynamicToUriNullable instance) => @@ -5606,13 +5298,12 @@ Map _$SimpleClassOfDynamicToUriNullableToJson( SimpleClassNullableOfDynamicToUriNullable _$SimpleClassNullableOfDynamicToUriNullableFromJson( - Map json) { - return SimpleClassNullableOfDynamicToUriNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(k, e == null ? null : Uri.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassNullableOfDynamicToUriNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e == null ? null : Uri.parse(e as String)), + ), + ); Map _$SimpleClassNullableOfDynamicToUriNullableToJson( SimpleClassNullableOfDynamicToUriNullable instance) => @@ -5621,14 +5312,13 @@ Map _$SimpleClassNullableOfDynamicToUriNullableToJson( }; SimpleClassOfEnumTypeToUriNullable _$SimpleClassOfEnumTypeToUriNullableFromJson( - Map json) { - return SimpleClassOfEnumTypeToUriNullable( - (json['value'] as Map).map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), - e == null ? null : Uri.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassOfEnumTypeToUriNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), + e == null ? null : Uri.parse(e as String)), + ), + ); Map _$SimpleClassOfEnumTypeToUriNullableToJson( SimpleClassOfEnumTypeToUriNullable instance) => @@ -5639,14 +5329,13 @@ Map _$SimpleClassOfEnumTypeToUriNullableToJson( SimpleClassNullableOfEnumTypeToUriNullable _$SimpleClassNullableOfEnumTypeToUriNullableFromJson( - Map json) { - return SimpleClassNullableOfEnumTypeToUriNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), - e == null ? null : Uri.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassNullableOfEnumTypeToUriNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), + e == null ? null : Uri.parse(e as String)), + ), + ); Map _$SimpleClassNullableOfEnumTypeToUriNullableToJson( SimpleClassNullableOfEnumTypeToUriNullable instance) => @@ -5656,14 +5345,13 @@ Map _$SimpleClassNullableOfEnumTypeToUriNullableToJson( }; SimpleClassOfIntToUriNullable _$SimpleClassOfIntToUriNullableFromJson( - Map json) { - return SimpleClassOfIntToUriNullable( - (json['value'] as Map).map( - (k, e) => - MapEntry(int.parse(k), e == null ? null : Uri.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassOfIntToUriNullable( + (json['value'] as Map).map( + (k, e) => + MapEntry(int.parse(k), e == null ? null : Uri.parse(e as String)), + ), + ); Map _$SimpleClassOfIntToUriNullableToJson( SimpleClassOfIntToUriNullable instance) => @@ -5673,14 +5361,14 @@ Map _$SimpleClassOfIntToUriNullableToJson( }; SimpleClassNullableOfIntToUriNullable - _$SimpleClassNullableOfIntToUriNullableFromJson(Map json) { - return SimpleClassNullableOfIntToUriNullable( - (json['value'] as Map?)?.map( - (k, e) => - MapEntry(int.parse(k), e == null ? null : Uri.parse(e as String)), - ), - ); -} + _$SimpleClassNullableOfIntToUriNullableFromJson( + Map json) => + SimpleClassNullableOfIntToUriNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry( + int.parse(k), e == null ? null : Uri.parse(e as String)), + ), + ); Map _$SimpleClassNullableOfIntToUriNullableToJson( SimpleClassNullableOfIntToUriNullable instance) => @@ -5690,13 +5378,12 @@ Map _$SimpleClassNullableOfIntToUriNullableToJson( }; SimpleClassOfObjectToUriNullable _$SimpleClassOfObjectToUriNullableFromJson( - Map json) { - return SimpleClassOfObjectToUriNullable( - (json['value'] as Map).map( - (k, e) => MapEntry(k, e == null ? null : Uri.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassOfObjectToUriNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(k, e == null ? null : Uri.parse(e as String)), + ), + ); Map _$SimpleClassOfObjectToUriNullableToJson( SimpleClassOfObjectToUriNullable instance) => @@ -5706,13 +5393,12 @@ Map _$SimpleClassOfObjectToUriNullableToJson( SimpleClassNullableOfObjectToUriNullable _$SimpleClassNullableOfObjectToUriNullableFromJson( - Map json) { - return SimpleClassNullableOfObjectToUriNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(k, e == null ? null : Uri.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassNullableOfObjectToUriNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e == null ? null : Uri.parse(e as String)), + ), + ); Map _$SimpleClassNullableOfObjectToUriNullableToJson( SimpleClassNullableOfObjectToUriNullable instance) => @@ -5721,13 +5407,12 @@ Map _$SimpleClassNullableOfObjectToUriNullableToJson( }; SimpleClassOfStringToUriNullable _$SimpleClassOfStringToUriNullableFromJson( - Map json) { - return SimpleClassOfStringToUriNullable( - (json['value'] as Map).map( - (k, e) => MapEntry(k, e == null ? null : Uri.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassOfStringToUriNullable( + (json['value'] as Map).map( + (k, e) => MapEntry(k, e == null ? null : Uri.parse(e as String)), + ), + ); Map _$SimpleClassOfStringToUriNullableToJson( SimpleClassOfStringToUriNullable instance) => @@ -5737,13 +5422,12 @@ Map _$SimpleClassOfStringToUriNullableToJson( SimpleClassNullableOfStringToUriNullable _$SimpleClassNullableOfStringToUriNullableFromJson( - Map json) { - return SimpleClassNullableOfStringToUriNullable( - (json['value'] as Map?)?.map( - (k, e) => MapEntry(k, e == null ? null : Uri.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassNullableOfStringToUriNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry(k, e == null ? null : Uri.parse(e as String)), + ), + ); Map _$SimpleClassNullableOfStringToUriNullableToJson( SimpleClassNullableOfStringToUriNullable instance) => @@ -5752,14 +5436,13 @@ Map _$SimpleClassNullableOfStringToUriNullableToJson( }; SimpleClassOfUriToUriNullable _$SimpleClassOfUriToUriNullableFromJson( - Map json) { - return SimpleClassOfUriToUriNullable( - (json['value'] as Map).map( - (k, e) => - MapEntry(Uri.parse(k), e == null ? null : Uri.parse(e as String)), - ), - ); -} + Map json) => + SimpleClassOfUriToUriNullable( + (json['value'] as Map).map( + (k, e) => + MapEntry(Uri.parse(k), e == null ? null : Uri.parse(e as String)), + ), + ); Map _$SimpleClassOfUriToUriNullableToJson( SimpleClassOfUriToUriNullable instance) => @@ -5769,14 +5452,14 @@ Map _$SimpleClassOfUriToUriNullableToJson( }; SimpleClassNullableOfUriToUriNullable - _$SimpleClassNullableOfUriToUriNullableFromJson(Map json) { - return SimpleClassNullableOfUriToUriNullable( - (json['value'] as Map?)?.map( - (k, e) => - MapEntry(Uri.parse(k), e == null ? null : Uri.parse(e as String)), - ), - ); -} + _$SimpleClassNullableOfUriToUriNullableFromJson( + Map json) => + SimpleClassNullableOfUriToUriNullable( + (json['value'] as Map?)?.map( + (k, e) => MapEntry( + Uri.parse(k), e == null ? null : Uri.parse(e as String)), + ), + ); Map _$SimpleClassNullableOfUriToUriNullableToJson( SimpleClassNullableOfUriToUriNullable instance) => diff --git a/json_serializable/test/supported_types/input.type_num.g.dart b/json_serializable/test/supported_types/input.type_num.g.dart index 0456261f1..c42af8030 100644 --- a/json_serializable/test/supported_types/input.type_num.g.dart +++ b/json_serializable/test/supported_types/input.type_num.g.dart @@ -6,12 +6,10 @@ part of 'input.type_num.dart'; // JsonSerializableGenerator // ************************************************************************** -SimpleClass _$SimpleClassFromJson(Map json) { - return SimpleClass( - json['value'] as num, - json['withDefault'] as num? ?? 88.6, - ); -} +SimpleClass _$SimpleClassFromJson(Map json) => SimpleClass( + json['value'] as num, + json['withDefault'] as num? ?? 88.6, + ); Map _$SimpleClassToJson(SimpleClass instance) => { @@ -19,12 +17,11 @@ Map _$SimpleClassToJson(SimpleClass instance) => 'withDefault': instance.withDefault, }; -SimpleClassNullable _$SimpleClassNullableFromJson(Map json) { - return SimpleClassNullable( - json['value'] as num?, - json['withDefault'] as num? ?? 88.6, - ); -} +SimpleClassNullable _$SimpleClassNullableFromJson(Map json) => + SimpleClassNullable( + json['value'] as num?, + json['withDefault'] as num? ?? 88.6, + ); Map _$SimpleClassNullableToJson( SimpleClassNullable instance) => diff --git a/json_serializable/test/supported_types/input.type_object.g.dart b/json_serializable/test/supported_types/input.type_object.g.dart index 691a85539..0254c5908 100644 --- a/json_serializable/test/supported_types/input.type_object.g.dart +++ b/json_serializable/test/supported_types/input.type_object.g.dart @@ -6,12 +6,10 @@ part of 'input.type_object.dart'; // JsonSerializableGenerator // ************************************************************************** -SimpleClass _$SimpleClassFromJson(Map json) { - return SimpleClass( - json['value'] as Object, - json['withDefault'] as Object? ?? 'o1', - ); -} +SimpleClass _$SimpleClassFromJson(Map json) => SimpleClass( + json['value'] as Object, + json['withDefault'] as Object? ?? 'o1', + ); Map _$SimpleClassToJson(SimpleClass instance) => { @@ -19,12 +17,11 @@ Map _$SimpleClassToJson(SimpleClass instance) => 'withDefault': instance.withDefault, }; -SimpleClassNullable _$SimpleClassNullableFromJson(Map json) { - return SimpleClassNullable( - json['value'], - json['withDefault'] ?? 'o1', - ); -} +SimpleClassNullable _$SimpleClassNullableFromJson(Map json) => + SimpleClassNullable( + json['value'], + json['withDefault'] ?? 'o1', + ); Map _$SimpleClassNullableToJson( SimpleClassNullable instance) => diff --git a/json_serializable/test/supported_types/input.type_set.g.dart b/json_serializable/test/supported_types/input.type_set.g.dart index 32e27b0e6..966b8f7db 100644 --- a/json_serializable/test/supported_types/input.type_set.g.dart +++ b/json_serializable/test/supported_types/input.type_set.g.dart @@ -6,12 +6,11 @@ part of 'input.type_set.dart'; // JsonSerializableGenerator // ************************************************************************** -SimpleClass _$SimpleClassFromJson(Map json) { - return SimpleClass( - (json['value'] as List).toSet(), - (json['withDefault'] as List?)?.toSet() ?? {42, true, false, null}, - ); -} +SimpleClass _$SimpleClassFromJson(Map json) => SimpleClass( + (json['value'] as List).toSet(), + (json['withDefault'] as List?)?.toSet() ?? + {42, true, false, null}, + ); Map _$SimpleClassToJson(SimpleClass instance) => { @@ -19,12 +18,12 @@ Map _$SimpleClassToJson(SimpleClass instance) => 'withDefault': instance.withDefault.toList(), }; -SimpleClassNullable _$SimpleClassNullableFromJson(Map json) { - return SimpleClassNullable( - (json['value'] as List?)?.toSet(), - (json['withDefault'] as List?)?.toSet() ?? {42, true, false, null}, - ); -} +SimpleClassNullable _$SimpleClassNullableFromJson(Map json) => + SimpleClassNullable( + (json['value'] as List?)?.toSet(), + (json['withDefault'] as List?)?.toSet() ?? + {42, true, false, null}, + ); Map _$SimpleClassNullableToJson( SimpleClassNullable instance) => @@ -33,13 +32,12 @@ Map _$SimpleClassNullableToJson( 'withDefault': instance.withDefault?.toList(), }; -SimpleClassOfBigInt _$SimpleClassOfBigIntFromJson(Map json) { - return SimpleClassOfBigInt( - (json['value'] as List) - .map((e) => BigInt.parse(e as String)) - .toSet(), - ); -} +SimpleClassOfBigInt _$SimpleClassOfBigIntFromJson(Map json) => + SimpleClassOfBigInt( + (json['value'] as List) + .map((e) => BigInt.parse(e as String)) + .toSet(), + ); Map _$SimpleClassOfBigIntToJson( SimpleClassOfBigInt instance) => @@ -48,13 +46,12 @@ Map _$SimpleClassOfBigIntToJson( }; SimpleClassNullableOfBigInt _$SimpleClassNullableOfBigIntFromJson( - Map json) { - return SimpleClassNullableOfBigInt( - (json['value'] as List?) - ?.map((e) => BigInt.parse(e as String)) - .toSet(), - ); -} + Map json) => + SimpleClassNullableOfBigInt( + (json['value'] as List?) + ?.map((e) => BigInt.parse(e as String)) + .toSet(), + ); Map _$SimpleClassNullableOfBigIntToJson( SimpleClassNullableOfBigInt instance) => @@ -63,13 +60,12 @@ Map _$SimpleClassNullableOfBigIntToJson( }; SimpleClassOfBigIntNullable _$SimpleClassOfBigIntNullableFromJson( - Map json) { - return SimpleClassOfBigIntNullable( - (json['value'] as List) - .map((e) => e == null ? null : BigInt.parse(e as String)) - .toSet(), - ); -} + Map json) => + SimpleClassOfBigIntNullable( + (json['value'] as List) + .map((e) => e == null ? null : BigInt.parse(e as String)) + .toSet(), + ); Map _$SimpleClassOfBigIntNullableToJson( SimpleClassOfBigIntNullable instance) => @@ -78,13 +74,12 @@ Map _$SimpleClassOfBigIntNullableToJson( }; SimpleClassNullableOfBigIntNullable - _$SimpleClassNullableOfBigIntNullableFromJson(Map json) { - return SimpleClassNullableOfBigIntNullable( - (json['value'] as List?) - ?.map((e) => e == null ? null : BigInt.parse(e as String)) - .toSet(), - ); -} + _$SimpleClassNullableOfBigIntNullableFromJson(Map json) => + SimpleClassNullableOfBigIntNullable( + (json['value'] as List?) + ?.map((e) => e == null ? null : BigInt.parse(e as String)) + .toSet(), + ); Map _$SimpleClassNullableOfBigIntNullableToJson( SimpleClassNullableOfBigIntNullable instance) => @@ -92,11 +87,10 @@ Map _$SimpleClassNullableOfBigIntNullableToJson( 'value': instance.value?.map((e) => e?.toString()).toList(), }; -SimpleClassOfBool _$SimpleClassOfBoolFromJson(Map json) { - return SimpleClassOfBool( - (json['value'] as List).map((e) => e as bool).toSet(), - ); -} +SimpleClassOfBool _$SimpleClassOfBoolFromJson(Map json) => + SimpleClassOfBool( + (json['value'] as List).map((e) => e as bool).toSet(), + ); Map _$SimpleClassOfBoolToJson(SimpleClassOfBool instance) => { @@ -104,11 +98,10 @@ Map _$SimpleClassOfBoolToJson(SimpleClassOfBool instance) => }; SimpleClassNullableOfBool _$SimpleClassNullableOfBoolFromJson( - Map json) { - return SimpleClassNullableOfBool( - (json['value'] as List?)?.map((e) => e as bool).toSet(), - ); -} + Map json) => + SimpleClassNullableOfBool( + (json['value'] as List?)?.map((e) => e as bool).toSet(), + ); Map _$SimpleClassNullableOfBoolToJson( SimpleClassNullableOfBool instance) => @@ -117,11 +110,10 @@ Map _$SimpleClassNullableOfBoolToJson( }; SimpleClassOfBoolNullable _$SimpleClassOfBoolNullableFromJson( - Map json) { - return SimpleClassOfBoolNullable( - (json['value'] as List).map((e) => e as bool?).toSet(), - ); -} + Map json) => + SimpleClassOfBoolNullable( + (json['value'] as List).map((e) => e as bool?).toSet(), + ); Map _$SimpleClassOfBoolNullableToJson( SimpleClassOfBoolNullable instance) => @@ -130,11 +122,10 @@ Map _$SimpleClassOfBoolNullableToJson( }; SimpleClassNullableOfBoolNullable _$SimpleClassNullableOfBoolNullableFromJson( - Map json) { - return SimpleClassNullableOfBoolNullable( - (json['value'] as List?)?.map((e) => e as bool?).toSet(), - ); -} + Map json) => + SimpleClassNullableOfBoolNullable( + (json['value'] as List?)?.map((e) => e as bool?).toSet(), + ); Map _$SimpleClassNullableOfBoolNullableToJson( SimpleClassNullableOfBoolNullable instance) => @@ -143,13 +134,12 @@ Map _$SimpleClassNullableOfBoolNullableToJson( }; SimpleClassOfDateTime _$SimpleClassOfDateTimeFromJson( - Map json) { - return SimpleClassOfDateTime( - (json['value'] as List) - .map((e) => DateTime.parse(e as String)) - .toSet(), - ); -} + Map json) => + SimpleClassOfDateTime( + (json['value'] as List) + .map((e) => DateTime.parse(e as String)) + .toSet(), + ); Map _$SimpleClassOfDateTimeToJson( SimpleClassOfDateTime instance) => @@ -158,13 +148,12 @@ Map _$SimpleClassOfDateTimeToJson( }; SimpleClassNullableOfDateTime _$SimpleClassNullableOfDateTimeFromJson( - Map json) { - return SimpleClassNullableOfDateTime( - (json['value'] as List?) - ?.map((e) => DateTime.parse(e as String)) - .toSet(), - ); -} + Map json) => + SimpleClassNullableOfDateTime( + (json['value'] as List?) + ?.map((e) => DateTime.parse(e as String)) + .toSet(), + ); Map _$SimpleClassNullableOfDateTimeToJson( SimpleClassNullableOfDateTime instance) => @@ -173,13 +162,12 @@ Map _$SimpleClassNullableOfDateTimeToJson( }; SimpleClassOfDateTimeNullable _$SimpleClassOfDateTimeNullableFromJson( - Map json) { - return SimpleClassOfDateTimeNullable( - (json['value'] as List) - .map((e) => e == null ? null : DateTime.parse(e as String)) - .toSet(), - ); -} + Map json) => + SimpleClassOfDateTimeNullable( + (json['value'] as List) + .map((e) => e == null ? null : DateTime.parse(e as String)) + .toSet(), + ); Map _$SimpleClassOfDateTimeNullableToJson( SimpleClassOfDateTimeNullable instance) => @@ -188,13 +176,13 @@ Map _$SimpleClassOfDateTimeNullableToJson( }; SimpleClassNullableOfDateTimeNullable - _$SimpleClassNullableOfDateTimeNullableFromJson(Map json) { - return SimpleClassNullableOfDateTimeNullable( - (json['value'] as List?) - ?.map((e) => e == null ? null : DateTime.parse(e as String)) - .toSet(), - ); -} + _$SimpleClassNullableOfDateTimeNullableFromJson( + Map json) => + SimpleClassNullableOfDateTimeNullable( + (json['value'] as List?) + ?.map((e) => e == null ? null : DateTime.parse(e as String)) + .toSet(), + ); Map _$SimpleClassNullableOfDateTimeNullableToJson( SimpleClassNullableOfDateTimeNullable instance) => @@ -202,11 +190,12 @@ Map _$SimpleClassNullableOfDateTimeNullableToJson( 'value': instance.value?.map((e) => e?.toIso8601String()).toList(), }; -SimpleClassOfDouble _$SimpleClassOfDoubleFromJson(Map json) { - return SimpleClassOfDouble( - (json['value'] as List).map((e) => (e as num).toDouble()).toSet(), - ); -} +SimpleClassOfDouble _$SimpleClassOfDoubleFromJson(Map json) => + SimpleClassOfDouble( + (json['value'] as List) + .map((e) => (e as num).toDouble()) + .toSet(), + ); Map _$SimpleClassOfDoubleToJson( SimpleClassOfDouble instance) => @@ -215,13 +204,12 @@ Map _$SimpleClassOfDoubleToJson( }; SimpleClassNullableOfDouble _$SimpleClassNullableOfDoubleFromJson( - Map json) { - return SimpleClassNullableOfDouble( - (json['value'] as List?) - ?.map((e) => (e as num).toDouble()) - .toSet(), - ); -} + Map json) => + SimpleClassNullableOfDouble( + (json['value'] as List?) + ?.map((e) => (e as num).toDouble()) + .toSet(), + ); Map _$SimpleClassNullableOfDoubleToJson( SimpleClassNullableOfDouble instance) => @@ -230,13 +218,12 @@ Map _$SimpleClassNullableOfDoubleToJson( }; SimpleClassOfDoubleNullable _$SimpleClassOfDoubleNullableFromJson( - Map json) { - return SimpleClassOfDoubleNullable( - (json['value'] as List) - .map((e) => (e as num?)?.toDouble()) - .toSet(), - ); -} + Map json) => + SimpleClassOfDoubleNullable( + (json['value'] as List) + .map((e) => (e as num?)?.toDouble()) + .toSet(), + ); Map _$SimpleClassOfDoubleNullableToJson( SimpleClassOfDoubleNullable instance) => @@ -245,13 +232,12 @@ Map _$SimpleClassOfDoubleNullableToJson( }; SimpleClassNullableOfDoubleNullable - _$SimpleClassNullableOfDoubleNullableFromJson(Map json) { - return SimpleClassNullableOfDoubleNullable( - (json['value'] as List?) - ?.map((e) => (e as num?)?.toDouble()) - .toSet(), - ); -} + _$SimpleClassNullableOfDoubleNullableFromJson(Map json) => + SimpleClassNullableOfDoubleNullable( + (json['value'] as List?) + ?.map((e) => (e as num?)?.toDouble()) + .toSet(), + ); Map _$SimpleClassNullableOfDoubleNullableToJson( SimpleClassNullableOfDoubleNullable instance) => @@ -260,13 +246,12 @@ Map _$SimpleClassNullableOfDoubleNullableToJson( }; SimpleClassOfDuration _$SimpleClassOfDurationFromJson( - Map json) { - return SimpleClassOfDuration( - (json['value'] as List) - .map((e) => Duration(microseconds: e as int)) - .toSet(), - ); -} + Map json) => + SimpleClassOfDuration( + (json['value'] as List) + .map((e) => Duration(microseconds: e as int)) + .toSet(), + ); Map _$SimpleClassOfDurationToJson( SimpleClassOfDuration instance) => @@ -275,13 +260,12 @@ Map _$SimpleClassOfDurationToJson( }; SimpleClassNullableOfDuration _$SimpleClassNullableOfDurationFromJson( - Map json) { - return SimpleClassNullableOfDuration( - (json['value'] as List?) - ?.map((e) => Duration(microseconds: e as int)) - .toSet(), - ); -} + Map json) => + SimpleClassNullableOfDuration( + (json['value'] as List?) + ?.map((e) => Duration(microseconds: e as int)) + .toSet(), + ); Map _$SimpleClassNullableOfDurationToJson( SimpleClassNullableOfDuration instance) => @@ -290,13 +274,12 @@ Map _$SimpleClassNullableOfDurationToJson( }; SimpleClassOfDurationNullable _$SimpleClassOfDurationNullableFromJson( - Map json) { - return SimpleClassOfDurationNullable( - (json['value'] as List) - .map((e) => e == null ? null : Duration(microseconds: e as int)) - .toSet(), - ); -} + Map json) => + SimpleClassOfDurationNullable( + (json['value'] as List) + .map((e) => e == null ? null : Duration(microseconds: e as int)) + .toSet(), + ); Map _$SimpleClassOfDurationNullableToJson( SimpleClassOfDurationNullable instance) => @@ -305,13 +288,13 @@ Map _$SimpleClassOfDurationNullableToJson( }; SimpleClassNullableOfDurationNullable - _$SimpleClassNullableOfDurationNullableFromJson(Map json) { - return SimpleClassNullableOfDurationNullable( - (json['value'] as List?) - ?.map((e) => e == null ? null : Duration(microseconds: e as int)) - .toSet(), - ); -} + _$SimpleClassNullableOfDurationNullableFromJson( + Map json) => + SimpleClassNullableOfDurationNullable( + (json['value'] as List?) + ?.map((e) => e == null ? null : Duration(microseconds: e as int)) + .toSet(), + ); Map _$SimpleClassNullableOfDurationNullableToJson( SimpleClassNullableOfDurationNullable instance) => @@ -319,11 +302,11 @@ Map _$SimpleClassNullableOfDurationNullableToJson( 'value': instance.value?.map((e) => e?.inMicroseconds).toList(), }; -SimpleClassOfDynamic _$SimpleClassOfDynamicFromJson(Map json) { - return SimpleClassOfDynamic( - (json['value'] as List).toSet(), - ); -} +SimpleClassOfDynamic _$SimpleClassOfDynamicFromJson( + Map json) => + SimpleClassOfDynamic( + (json['value'] as List).toSet(), + ); Map _$SimpleClassOfDynamicToJson( SimpleClassOfDynamic instance) => @@ -332,11 +315,10 @@ Map _$SimpleClassOfDynamicToJson( }; SimpleClassNullableOfDynamic _$SimpleClassNullableOfDynamicFromJson( - Map json) { - return SimpleClassNullableOfDynamic( - (json['value'] as List?)?.toSet(), - ); -} + Map json) => + SimpleClassNullableOfDynamic( + (json['value'] as List?)?.toSet(), + ); Map _$SimpleClassNullableOfDynamicToJson( SimpleClassNullableOfDynamic instance) => @@ -345,13 +327,12 @@ Map _$SimpleClassNullableOfDynamicToJson( }; SimpleClassOfEnumType _$SimpleClassOfEnumTypeFromJson( - Map json) { - return SimpleClassOfEnumType( - (json['value'] as List) - .map((e) => _$enumDecode(_$EnumTypeEnumMap, e)) - .toSet(), - ); -} + Map json) => + SimpleClassOfEnumType( + (json['value'] as List) + .map((e) => _$enumDecode(_$EnumTypeEnumMap, e)) + .toSet(), + ); Map _$SimpleClassOfEnumTypeToJson( SimpleClassOfEnumType instance) => @@ -393,13 +374,12 @@ const _$EnumTypeEnumMap = { }; SimpleClassNullableOfEnumType _$SimpleClassNullableOfEnumTypeFromJson( - Map json) { - return SimpleClassNullableOfEnumType( - (json['value'] as List?) - ?.map((e) => _$enumDecode(_$EnumTypeEnumMap, e)) - .toSet(), - ); -} + Map json) => + SimpleClassNullableOfEnumType( + (json['value'] as List?) + ?.map((e) => _$enumDecode(_$EnumTypeEnumMap, e)) + .toSet(), + ); Map _$SimpleClassNullableOfEnumTypeToJson( SimpleClassNullableOfEnumType instance) => @@ -408,13 +388,12 @@ Map _$SimpleClassNullableOfEnumTypeToJson( }; SimpleClassOfEnumTypeNullable _$SimpleClassOfEnumTypeNullableFromJson( - Map json) { - return SimpleClassOfEnumTypeNullable( - (json['value'] as List) - .map((e) => _$enumDecodeNullable(_$EnumTypeEnumMap, e)) - .toSet(), - ); -} + Map json) => + SimpleClassOfEnumTypeNullable( + (json['value'] as List) + .map((e) => _$enumDecodeNullable(_$EnumTypeEnumMap, e)) + .toSet(), + ); Map _$SimpleClassOfEnumTypeNullableToJson( SimpleClassOfEnumTypeNullable instance) => @@ -434,13 +413,13 @@ K? _$enumDecodeNullable( } SimpleClassNullableOfEnumTypeNullable - _$SimpleClassNullableOfEnumTypeNullableFromJson(Map json) { - return SimpleClassNullableOfEnumTypeNullable( - (json['value'] as List?) - ?.map((e) => _$enumDecodeNullable(_$EnumTypeEnumMap, e)) - .toSet(), - ); -} + _$SimpleClassNullableOfEnumTypeNullableFromJson( + Map json) => + SimpleClassNullableOfEnumTypeNullable( + (json['value'] as List?) + ?.map((e) => _$enumDecodeNullable(_$EnumTypeEnumMap, e)) + .toSet(), + ); Map _$SimpleClassNullableOfEnumTypeNullableToJson( SimpleClassNullableOfEnumTypeNullable instance) => @@ -448,11 +427,10 @@ Map _$SimpleClassNullableOfEnumTypeNullableToJson( 'value': instance.value?.map((e) => _$EnumTypeEnumMap[e]).toList(), }; -SimpleClassOfInt _$SimpleClassOfIntFromJson(Map json) { - return SimpleClassOfInt( - (json['value'] as List).map((e) => e as int).toSet(), - ); -} +SimpleClassOfInt _$SimpleClassOfIntFromJson(Map json) => + SimpleClassOfInt( + (json['value'] as List).map((e) => e as int).toSet(), + ); Map _$SimpleClassOfIntToJson(SimpleClassOfInt instance) => { @@ -460,11 +438,10 @@ Map _$SimpleClassOfIntToJson(SimpleClassOfInt instance) => }; SimpleClassNullableOfInt _$SimpleClassNullableOfIntFromJson( - Map json) { - return SimpleClassNullableOfInt( - (json['value'] as List?)?.map((e) => e as int).toSet(), - ); -} + Map json) => + SimpleClassNullableOfInt( + (json['value'] as List?)?.map((e) => e as int).toSet(), + ); Map _$SimpleClassNullableOfIntToJson( SimpleClassNullableOfInt instance) => @@ -473,11 +450,10 @@ Map _$SimpleClassNullableOfIntToJson( }; SimpleClassOfIntNullable _$SimpleClassOfIntNullableFromJson( - Map json) { - return SimpleClassOfIntNullable( - (json['value'] as List).map((e) => e as int?).toSet(), - ); -} + Map json) => + SimpleClassOfIntNullable( + (json['value'] as List).map((e) => e as int?).toSet(), + ); Map _$SimpleClassOfIntNullableToJson( SimpleClassOfIntNullable instance) => @@ -486,11 +462,10 @@ Map _$SimpleClassOfIntNullableToJson( }; SimpleClassNullableOfIntNullable _$SimpleClassNullableOfIntNullableFromJson( - Map json) { - return SimpleClassNullableOfIntNullable( - (json['value'] as List?)?.map((e) => e as int?).toSet(), - ); -} + Map json) => + SimpleClassNullableOfIntNullable( + (json['value'] as List?)?.map((e) => e as int?).toSet(), + ); Map _$SimpleClassNullableOfIntNullableToJson( SimpleClassNullableOfIntNullable instance) => @@ -498,11 +473,10 @@ Map _$SimpleClassNullableOfIntNullableToJson( 'value': instance.value?.toList(), }; -SimpleClassOfNum _$SimpleClassOfNumFromJson(Map json) { - return SimpleClassOfNum( - (json['value'] as List).map((e) => e as num).toSet(), - ); -} +SimpleClassOfNum _$SimpleClassOfNumFromJson(Map json) => + SimpleClassOfNum( + (json['value'] as List).map((e) => e as num).toSet(), + ); Map _$SimpleClassOfNumToJson(SimpleClassOfNum instance) => { @@ -510,11 +484,10 @@ Map _$SimpleClassOfNumToJson(SimpleClassOfNum instance) => }; SimpleClassNullableOfNum _$SimpleClassNullableOfNumFromJson( - Map json) { - return SimpleClassNullableOfNum( - (json['value'] as List?)?.map((e) => e as num).toSet(), - ); -} + Map json) => + SimpleClassNullableOfNum( + (json['value'] as List?)?.map((e) => e as num).toSet(), + ); Map _$SimpleClassNullableOfNumToJson( SimpleClassNullableOfNum instance) => @@ -523,11 +496,10 @@ Map _$SimpleClassNullableOfNumToJson( }; SimpleClassOfNumNullable _$SimpleClassOfNumNullableFromJson( - Map json) { - return SimpleClassOfNumNullable( - (json['value'] as List).map((e) => e as num?).toSet(), - ); -} + Map json) => + SimpleClassOfNumNullable( + (json['value'] as List).map((e) => e as num?).toSet(), + ); Map _$SimpleClassOfNumNullableToJson( SimpleClassOfNumNullable instance) => @@ -536,11 +508,10 @@ Map _$SimpleClassOfNumNullableToJson( }; SimpleClassNullableOfNumNullable _$SimpleClassNullableOfNumNullableFromJson( - Map json) { - return SimpleClassNullableOfNumNullable( - (json['value'] as List?)?.map((e) => e as num?).toSet(), - ); -} + Map json) => + SimpleClassNullableOfNumNullable( + (json['value'] as List?)?.map((e) => e as num?).toSet(), + ); Map _$SimpleClassNullableOfNumNullableToJson( SimpleClassNullableOfNumNullable instance) => @@ -548,11 +519,10 @@ Map _$SimpleClassNullableOfNumNullableToJson( 'value': instance.value?.toList(), }; -SimpleClassOfObject _$SimpleClassOfObjectFromJson(Map json) { - return SimpleClassOfObject( - (json['value'] as List).map((e) => e as Object).toSet(), - ); -} +SimpleClassOfObject _$SimpleClassOfObjectFromJson(Map json) => + SimpleClassOfObject( + (json['value'] as List).map((e) => e as Object).toSet(), + ); Map _$SimpleClassOfObjectToJson( SimpleClassOfObject instance) => @@ -561,11 +531,10 @@ Map _$SimpleClassOfObjectToJson( }; SimpleClassNullableOfObject _$SimpleClassNullableOfObjectFromJson( - Map json) { - return SimpleClassNullableOfObject( - (json['value'] as List?)?.map((e) => e as Object).toSet(), - ); -} + Map json) => + SimpleClassNullableOfObject( + (json['value'] as List?)?.map((e) => e as Object).toSet(), + ); Map _$SimpleClassNullableOfObjectToJson( SimpleClassNullableOfObject instance) => @@ -574,11 +543,10 @@ Map _$SimpleClassNullableOfObjectToJson( }; SimpleClassOfObjectNullable _$SimpleClassOfObjectNullableFromJson( - Map json) { - return SimpleClassOfObjectNullable( - (json['value'] as List).toSet(), - ); -} + Map json) => + SimpleClassOfObjectNullable( + (json['value'] as List).toSet(), + ); Map _$SimpleClassOfObjectNullableToJson( SimpleClassOfObjectNullable instance) => @@ -587,11 +555,10 @@ Map _$SimpleClassOfObjectNullableToJson( }; SimpleClassNullableOfObjectNullable - _$SimpleClassNullableOfObjectNullableFromJson(Map json) { - return SimpleClassNullableOfObjectNullable( - (json['value'] as List?)?.toSet(), - ); -} + _$SimpleClassNullableOfObjectNullableFromJson(Map json) => + SimpleClassNullableOfObjectNullable( + (json['value'] as List?)?.toSet(), + ); Map _$SimpleClassNullableOfObjectNullableToJson( SimpleClassNullableOfObjectNullable instance) => @@ -599,11 +566,10 @@ Map _$SimpleClassNullableOfObjectNullableToJson( 'value': instance.value?.toList(), }; -SimpleClassOfString _$SimpleClassOfStringFromJson(Map json) { - return SimpleClassOfString( - (json['value'] as List).map((e) => e as String).toSet(), - ); -} +SimpleClassOfString _$SimpleClassOfStringFromJson(Map json) => + SimpleClassOfString( + (json['value'] as List).map((e) => e as String).toSet(), + ); Map _$SimpleClassOfStringToJson( SimpleClassOfString instance) => @@ -612,11 +578,10 @@ Map _$SimpleClassOfStringToJson( }; SimpleClassNullableOfString _$SimpleClassNullableOfStringFromJson( - Map json) { - return SimpleClassNullableOfString( - (json['value'] as List?)?.map((e) => e as String).toSet(), - ); -} + Map json) => + SimpleClassNullableOfString( + (json['value'] as List?)?.map((e) => e as String).toSet(), + ); Map _$SimpleClassNullableOfStringToJson( SimpleClassNullableOfString instance) => @@ -625,11 +590,10 @@ Map _$SimpleClassNullableOfStringToJson( }; SimpleClassOfStringNullable _$SimpleClassOfStringNullableFromJson( - Map json) { - return SimpleClassOfStringNullable( - (json['value'] as List).map((e) => e as String?).toSet(), - ); -} + Map json) => + SimpleClassOfStringNullable( + (json['value'] as List).map((e) => e as String?).toSet(), + ); Map _$SimpleClassOfStringNullableToJson( SimpleClassOfStringNullable instance) => @@ -638,11 +602,10 @@ Map _$SimpleClassOfStringNullableToJson( }; SimpleClassNullableOfStringNullable - _$SimpleClassNullableOfStringNullableFromJson(Map json) { - return SimpleClassNullableOfStringNullable( - (json['value'] as List?)?.map((e) => e as String?).toSet(), - ); -} + _$SimpleClassNullableOfStringNullableFromJson(Map json) => + SimpleClassNullableOfStringNullable( + (json['value'] as List?)?.map((e) => e as String?).toSet(), + ); Map _$SimpleClassNullableOfStringNullableToJson( SimpleClassNullableOfStringNullable instance) => @@ -650,11 +613,12 @@ Map _$SimpleClassNullableOfStringNullableToJson( 'value': instance.value?.toList(), }; -SimpleClassOfUri _$SimpleClassOfUriFromJson(Map json) { - return SimpleClassOfUri( - (json['value'] as List).map((e) => Uri.parse(e as String)).toSet(), - ); -} +SimpleClassOfUri _$SimpleClassOfUriFromJson(Map json) => + SimpleClassOfUri( + (json['value'] as List) + .map((e) => Uri.parse(e as String)) + .toSet(), + ); Map _$SimpleClassOfUriToJson(SimpleClassOfUri instance) => { @@ -662,13 +626,12 @@ Map _$SimpleClassOfUriToJson(SimpleClassOfUri instance) => }; SimpleClassNullableOfUri _$SimpleClassNullableOfUriFromJson( - Map json) { - return SimpleClassNullableOfUri( - (json['value'] as List?) - ?.map((e) => Uri.parse(e as String)) - .toSet(), - ); -} + Map json) => + SimpleClassNullableOfUri( + (json['value'] as List?) + ?.map((e) => Uri.parse(e as String)) + .toSet(), + ); Map _$SimpleClassNullableOfUriToJson( SimpleClassNullableOfUri instance) => @@ -677,13 +640,12 @@ Map _$SimpleClassNullableOfUriToJson( }; SimpleClassOfUriNullable _$SimpleClassOfUriNullableFromJson( - Map json) { - return SimpleClassOfUriNullable( - (json['value'] as List) - .map((e) => e == null ? null : Uri.parse(e as String)) - .toSet(), - ); -} + Map json) => + SimpleClassOfUriNullable( + (json['value'] as List) + .map((e) => e == null ? null : Uri.parse(e as String)) + .toSet(), + ); Map _$SimpleClassOfUriNullableToJson( SimpleClassOfUriNullable instance) => @@ -692,13 +654,12 @@ Map _$SimpleClassOfUriNullableToJson( }; SimpleClassNullableOfUriNullable _$SimpleClassNullableOfUriNullableFromJson( - Map json) { - return SimpleClassNullableOfUriNullable( - (json['value'] as List?) - ?.map((e) => e == null ? null : Uri.parse(e as String)) - .toSet(), - ); -} + Map json) => + SimpleClassNullableOfUriNullable( + (json['value'] as List?) + ?.map((e) => e == null ? null : Uri.parse(e as String)) + .toSet(), + ); Map _$SimpleClassNullableOfUriNullableToJson( SimpleClassNullableOfUriNullable instance) => diff --git a/json_serializable/test/supported_types/input.type_string.g.dart b/json_serializable/test/supported_types/input.type_string.g.dart index 54ef11b44..291ec405a 100644 --- a/json_serializable/test/supported_types/input.type_string.g.dart +++ b/json_serializable/test/supported_types/input.type_string.g.dart @@ -6,12 +6,10 @@ part of 'input.type_string.dart'; // JsonSerializableGenerator // ************************************************************************** -SimpleClass _$SimpleClassFromJson(Map json) { - return SimpleClass( - json['value'] as String, - json['withDefault'] as String? ?? 'a string', - ); -} +SimpleClass _$SimpleClassFromJson(Map json) => SimpleClass( + json['value'] as String, + json['withDefault'] as String? ?? 'a string', + ); Map _$SimpleClassToJson(SimpleClass instance) => { @@ -19,12 +17,11 @@ Map _$SimpleClassToJson(SimpleClass instance) => 'withDefault': instance.withDefault, }; -SimpleClassNullable _$SimpleClassNullableFromJson(Map json) { - return SimpleClassNullable( - json['value'] as String?, - json['withDefault'] as String? ?? 'a string', - ); -} +SimpleClassNullable _$SimpleClassNullableFromJson(Map json) => + SimpleClassNullable( + json['value'] as String?, + json['withDefault'] as String? ?? 'a string', + ); Map _$SimpleClassNullableToJson( SimpleClassNullable instance) => diff --git a/json_serializable/test/supported_types/input.type_uri.g.dart b/json_serializable/test/supported_types/input.type_uri.g.dart index 8392c64b3..82452c83b 100644 --- a/json_serializable/test/supported_types/input.type_uri.g.dart +++ b/json_serializable/test/supported_types/input.type_uri.g.dart @@ -6,22 +6,19 @@ part of 'input.type_uri.dart'; // JsonSerializableGenerator // ************************************************************************** -SimpleClass _$SimpleClassFromJson(Map json) { - return SimpleClass( - Uri.parse(json['value'] as String), - ); -} +SimpleClass _$SimpleClassFromJson(Map json) => SimpleClass( + Uri.parse(json['value'] as String), + ); Map _$SimpleClassToJson(SimpleClass instance) => { 'value': instance.value.toString(), }; -SimpleClassNullable _$SimpleClassNullableFromJson(Map json) { - return SimpleClassNullable( - json['value'] == null ? null : Uri.parse(json['value'] as String), - ); -} +SimpleClassNullable _$SimpleClassNullableFromJson(Map json) => + SimpleClassNullable( + json['value'] == null ? null : Uri.parse(json['value'] as String), + ); Map _$SimpleClassNullableToJson( SimpleClassNullable instance) => From 824950daf076600a7666bc5d451e9997dfd94462 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 13 Apr 2021 15:53:15 -0700 Subject: [PATCH 301/569] Include nullability information for generic class (#873) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also allow nullable return values with fromJson if there is a default value Fixes two issues. 1. Correctly includes a trailing `?` in the error message when a type was generic. 2. Wires up the `defaultValue` in the case where a `fromJson` function returns a nullable value – and omits the associated warning. Fixes https://github.com/google/json_serializable.dart/issues/869 --- json_serializable/lib/src/decode_helper.dart | 6 +- json_serializable/lib/src/helper_core.dart | 14 ++--- .../lib/src/type_helper_ctx.dart | 31 +++++++--- .../lib/src/type_helpers/convert_helper.dart | 10 +++- json_serializable/lib/src/utils.dart | 5 ++ .../test/json_serializable_test.dart | 2 + .../test/src/to_from_json_test_input.dart | 58 +++++++++++++++++++ 7 files changed, 108 insertions(+), 18 deletions(-) diff --git a/json_serializable/lib/src/decode_helper.dart b/json_serializable/lib/src/decode_helper.dart index 173eb88e4..79aacd68e 100644 --- a/json_serializable/lib/src/decode_helper.dart +++ b/json_serializable/lib/src/decode_helper.dart @@ -227,7 +227,11 @@ abstract class DecodeHelper implements HelperCore { 'effect because both `disallowNullValue` and `required` are set to ' '`true`.'); } - if (contextHelper.deserializeConvertData != null) { + + final deserializeConvertData = contextHelper.deserializeConvertData; + + if (deserializeConvertData != null && + !deserializeConvertData.nullableToAllowDefault) { log.warning('The field `${field.name}` has both `defaultValue` and ' '`fromJson` defined which likely won\'t work for your scenario.\n' 'Instead of using `defaultValue`, set `nullable: false` and handle ' diff --git a/json_serializable/lib/src/helper_core.dart b/json_serializable/lib/src/helper_core.dart index 3780df9c7..14694cee8 100644 --- a/json_serializable/lib/src/helper_core.dart +++ b/json_serializable/lib/src/helper_core.dart @@ -141,14 +141,12 @@ String typeToCode( if (type.isDynamic) { return 'dynamic'; } else if (type is InterfaceType) { - final typeArguments = type.typeArguments; - if (typeArguments.isEmpty) { - final nullablePostfix = (type.isNullableType || forceNullable) ? '?' : ''; - return '${type.element.name}$nullablePostfix'; - } else { - final typeArgumentsCode = typeArguments.map(typeToCode).join(', '); - return '${type.element.name}<$typeArgumentsCode>'; - } + return [ + type.element.name, + if (type.typeArguments.isNotEmpty) + '<${type.typeArguments.map(typeToCode).join(', ')}>', + (type.isNullableType || forceNullable) ? '?' : '', + ].join(); } throw UnimplementedError('(${type.runtimeType}) $type'); } diff --git a/json_serializable/lib/src/type_helper_ctx.dart b/json_serializable/lib/src/type_helper_ctx.dart index 429603535..4ba3dcd38 100644 --- a/json_serializable/lib/src/type_helper_ctx.dart +++ b/json_serializable/lib/src/type_helper_ctx.dart @@ -125,8 +125,13 @@ ConvertData? _convertData(DartObject obj, FieldElement element, bool isFrom) { 'positional parameter.'); } + var nullableToAllowDefault = false; + final argType = executableElement.parameters.first.type; if (isFrom) { + final hasDefaultValue = + !jsonKeyAnnotation(element).read('defaultValue').isNull; + final returnType = executableElement.returnType; if (returnType is TypeParameterType) { @@ -134,14 +139,20 @@ ConvertData? _convertData(DartObject obj, FieldElement element, bool isFrom) { // to the `fromJson` function. // TODO: consider adding error checking here if there is confusion. } else if (!returnType.isAssignableTo(element.type)) { - final returnTypeCode = typeToCode(returnType); - final elementTypeCode = typeToCode(element.type); - throwUnsupported( - element, - 'The `$paramName` function `${executableElement.name}` return type ' - '`$returnTypeCode` is not compatible with field type ' - '`$elementTypeCode`.'); + if (returnType.promoteNonNullable().isAssignableTo(element.type) && + hasDefaultValue) { + // noop + } else { + final returnTypeCode = typeToCode(returnType); + final elementTypeCode = typeToCode(element.type); + throwUnsupported( + element, + 'The `$paramName` function `${executableElement.name}` return type ' + '`$returnTypeCode` is not compatible with field type ' + '`$elementTypeCode`.'); + } } + nullableToAllowDefault = hasDefaultValue && returnType.isNullableType; } else { if (argType is TypeParameterType) { // We keep things simple in this case. We rely on inferred type arguments @@ -164,5 +175,9 @@ ConvertData? _convertData(DartObject obj, FieldElement element, bool isFrom) { name = '${executableElement.enclosingElement.name}.$name'; } - return ConvertData(name, argType); + return ConvertData( + name, + argType, + nullableToAllowDefault: nullableToAllowDefault, + ); } diff --git a/json_serializable/lib/src/type_helpers/convert_helper.dart b/json_serializable/lib/src/type_helpers/convert_helper.dart index 406e79f1c..f2ce98e02 100644 --- a/json_serializable/lib/src/type_helpers/convert_helper.dart +++ b/json_serializable/lib/src/type_helpers/convert_helper.dart @@ -14,7 +14,15 @@ class ConvertData { final String name; final DartType paramType; - ConvertData(this.name, this.paramType); + /// `true` if the function returns a nullable value AND there is a default + /// value assigned. + final bool nullableToAllowDefault; + + ConvertData( + this.name, + this.paramType, { + required this.nullableToAllowDefault, + }); } abstract class TypeHelperContextWithConvert extends TypeHelperContext { diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index ca8d9555f..d8d74fcdb 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -202,3 +202,8 @@ Map? enumFieldsMap(DartType targetType) { /// Otherwise, `null`. Iterable? iterateEnumFields(DartType targetType) => enumFieldsMap(targetType)?.keys; + +extension DartTypeExtension on DartType { + DartType promoteNonNullable() => + element?.library?.typeSystem.promoteToNonNull(this) ?? this; +} diff --git a/json_serializable/test/json_serializable_test.dart b/json_serializable/test/json_serializable_test.dart index a61922315..3f67990d2 100644 --- a/json_serializable/test/json_serializable_test.dart +++ b/json_serializable/test/json_serializable_test.dart @@ -94,6 +94,8 @@ const _expectedAnnotatedTests = { 'OverrideGetterExampleI613', 'PrivateFieldCtorClass', 'PropInMixinI448Regression', + 'Reproduce869NullableGenericType', + 'Reproduce869NullableGenericTypeWithDefault', 'SetSupport', 'SubclassedJsonKey', 'SubType', diff --git a/json_serializable/test/src/to_from_json_test_input.dart b/json_serializable/test/src/to_from_json_test_input.dart index 211f2acdd..ee8ba7fff 100644 --- a/json_serializable/test/src/to_from_json_test_input.dart +++ b/json_serializable/test/src/to_from_json_test_input.dart @@ -70,6 +70,64 @@ class BadToFuncReturnType { late String field; } +@ShouldThrow( + 'Error with `@JsonKey` on `values`. The `fromJson` function `_fromList` ' + 'return type `List?` is not compatible with field type `List`.', + element: 'values', +) +@JsonSerializable() +class Reproduce869NullableGenericType { + @JsonKey( + toJson: _toList, // nullable + fromJson: _fromList, // nullable + ) + late final List values; +} + +@ShouldGenerate( + r''' +Reproduce869NullableGenericTypeWithDefault + _$Reproduce869NullableGenericTypeWithDefaultFromJson( + Map json) => + Reproduce869NullableGenericTypeWithDefault() + ..values = _fromList(json['values'] as List?) ?? [] + ..valuesNullable = _fromList(json['valuesNullable'] as List?) ?? []; + +Map _$Reproduce869NullableGenericTypeWithDefaultToJson( + Reproduce869NullableGenericTypeWithDefault instance) => + { + 'values': _toList(instance.values), + 'valuesNullable': _toList(instance.valuesNullable), + }; +''', +) +@JsonSerializable() +class Reproduce869NullableGenericTypeWithDefault { + @JsonKey( + toJson: _toList, // nullable + fromJson: _fromList, // nullable + defaultValue: [], + ) + late List values; + + @JsonKey( + toJson: _toList, // nullable + fromJson: _fromList, // nullable + defaultValue: [], + ) + List? valuesNullable; +} + +List? _fromList(List? pairs) { + return pairs?.map((it) { + return it as int; + }).toList(growable: false); +} + +List? _toList(List? pairs) { + return pairs?.map((it) => [it]).toList(growable: false); +} + @ShouldThrow( 'Error with `@JsonKey` on `field`. The `toJson` function ' '`_twoArgFunction` must have one positional parameter.', From 7d9c6a76938b460061abd51246ead2cc7f87aade Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 20 Apr 2021 13:54:16 -0700 Subject: [PATCH 302/569] Allow the latest pkg:build_config (#875) --- json_serializable/CHANGELOG.md | 4 ++++ json_serializable/pubspec.yaml | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index b358bbe67..b4391dffa 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,7 @@ +## 4.1.1 + +- Allow the latest `package:build_config`. + ## 4.1.0 - Implementation is now null-safe. diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index a83829cdd..c9eceb1af 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 4.1.0 +version: 4.1.1 description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. @@ -10,7 +10,7 @@ environment: dependencies: analyzer: '>=0.41.2 <2.0.0' build: ^2.0.0 - build_config: ^0.4.4 + build_config: '>=0.4.4 <2.0.0' collection: ^1.14.0 # Use a tight version constraint to ensure that a constraint on @@ -21,7 +21,7 @@ dependencies: source_gen: ^1.0.0 dev_dependencies: - build_runner: ^1.0.0 + build_runner: ^2.0.0 build_verify: ^2.0.0 dart_style: ^2.0.0 logging: ^1.0.0 From 1443303c9313905396f1258d9563d6b0c2720075 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 20 Apr 2021 18:30:16 -0700 Subject: [PATCH 303/569] Update build_runner deps (#877) --- _test_yaml/pubspec.yaml | 2 +- checked_yaml/pubspec.yaml | 2 +- example/README.md | 2 +- example/pubspec.yaml | 2 +- example/test/readme_test.dart | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/_test_yaml/pubspec.yaml b/_test_yaml/pubspec.yaml index 9c536bae2..2af71ec61 100644 --- a/_test_yaml/pubspec.yaml +++ b/_test_yaml/pubspec.yaml @@ -5,7 +5,7 @@ environment: sdk: '>=2.12.0 <3.0.0' dev_dependencies: - build_runner: ^1.0.0 + build_runner: ^2.0.0 build_verify: ^2.0.0 checked_yaml: any json_annotation: any diff --git a/checked_yaml/pubspec.yaml b/checked_yaml/pubspec.yaml index 552df380d..becff7234 100644 --- a/checked_yaml/pubspec.yaml +++ b/checked_yaml/pubspec.yaml @@ -14,7 +14,7 @@ dependencies: yaml: ^3.0.0 dev_dependencies: - build_runner: ^1.0.0 + build_runner: ^2.0.0 build_verify: ^2.0.0 json_serializable: ^4.0.0 path: ^1.0.0 diff --git a/example/README.md b/example/README.md index 710bfe171..e5d0c0707 100644 --- a/example/README.md +++ b/example/README.md @@ -8,7 +8,7 @@ dependencies: json_annotation: ^4.0.0 dev_dependencies: - build_runner: ^1.0.0 + build_runner: ^2.0.0 json_serializable: ^4.0.0 ``` diff --git a/example/pubspec.yaml b/example/pubspec.yaml index dccf0ab09..53668ed78 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -8,7 +8,7 @@ dependencies: json_annotation: ^4.0.0 dev_dependencies: - build_runner: ^1.0.0 + build_runner: ^2.0.0 # Used by tests. Not required to use `json_serializable`. build_verify: ^2.0.0 diff --git a/example/test/readme_test.dart b/example/test/readme_test.dart index 2005b5626..a49379af5 100644 --- a/example/test/readme_test.dart +++ b/example/test/readme_test.dart @@ -28,6 +28,6 @@ dependencies: json_annotation: ^4.0.0 dev_dependencies: - build_runner: ^1.0.0 + build_runner: ^2.0.0 json_serializable: ^4.0.0 '''; From 922c24f6e73e7eb2489593fd1de8e173fafc3eb1 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Sun, 25 Apr 2021 13:52:27 -0700 Subject: [PATCH 304/569] fix lint (#880) --- json_serializable/test/enum_helper_test.dart | 3 +-- json_serializable/test/utils_test.dart | 4 +--- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/json_serializable/test/enum_helper_test.dart b/json_serializable/test/enum_helper_test.dart index 8043543b7..4399dc843 100644 --- a/json_serializable/test/enum_helper_test.dart +++ b/json_serializable/test/enum_helper_test.dart @@ -3,9 +3,8 @@ // BSD-style license that can be found in the LICENSE file. @TestOn('vm') - -import 'package:test/test.dart'; import 'package:json_serializable/src/type_helpers/enum_helper.dart'; +import 'package:test/test.dart'; void main() { group('expression test', () { diff --git a/json_serializable/test/utils_test.dart b/json_serializable/test/utils_test.dart index 4b46b14cd..23fbaaa5b 100644 --- a/json_serializable/test/utils_test.dart +++ b/json_serializable/test/utils_test.dart @@ -3,10 +3,8 @@ // BSD-style license that can be found in the LICENSE file. @TestOn('vm') - -import 'package:test/test.dart'; - import 'package:json_serializable/src/utils.dart'; +import 'package:test/test.dart'; const _kebabItems = { 'simple': 'simple', From 5d299e0387398d0c80af5625da88398cbc4c71ac Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Fri, 14 May 2021 12:59:40 -0700 Subject: [PATCH 305/569] Correctly decode Map when the input has int literals (#894) Prepare to release v4.1.2 Also fix directive ordering, which is now enforced Also add stable branch (v4_x) to test on CI Also update generated CI code with latest mono_repo --- .github/workflows/dart.yml | 42 +++++----- json_serializable/CHANGELOG.md | 4 + .../lib/src/type_helpers/map_helper.dart | 9 ++- json_serializable/pubspec.yaml | 2 +- json_serializable/test/enum_helper_test.dart | 3 +- .../supported_types/input.type_map.g.dart | 24 ++++-- .../support_types_extra_tests.dart | 77 +++++++++++++++++++ json_serializable/test/utils_test.dart | 4 +- mono_repo.yaml | 2 +- tool/ci.sh | 19 ++++- 10 files changed, 147 insertions(+), 39 deletions(-) create mode 100644 json_serializable/test/supported_types/support_types_extra_tests.dart diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 53243ab98..7f5b10c30 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -1,10 +1,10 @@ -# Created with package:mono_repo v3.4.7 +# Created with package:mono_repo v4.0.0 name: Dart CI on: push: branches: - master - - "3_x" + - "4_x" pull_request: schedule: - cron: "0 0 * * 0" @@ -20,7 +20,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v2 + uses: actions/cache@v2.1.5 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;dart:stable" @@ -31,9 +31,9 @@ jobs: with: sdk: stable - id: checkout - uses: actions/checkout@v2 + uses: actions/checkout@v2.3.4 - name: mono_repo self validate - run: pub global activate mono_repo 3.4.7 + run: pub global activate mono_repo 4.0.0 - name: mono_repo self validate run: pub global run mono_repo generate --validate job_002: @@ -41,7 +41,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v2 + uses: actions/cache@v2.1.5 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:dartfmt-dartanalyzer" @@ -54,7 +54,7 @@ jobs: with: sdk: "2.12.0" - id: checkout - uses: actions/checkout@v2 + uses: actions/checkout@v2.3.4 - id: _test_yaml_pub_upgrade name: "_test_yaml; pub upgrade --no-precompile" if: "always() && steps.checkout.conclusion == 'success'" @@ -125,7 +125,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v2 + uses: actions/cache@v2.1.5 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:dartfmt-dartanalyzer" @@ -138,7 +138,7 @@ jobs: with: sdk: dev - id: checkout - uses: actions/checkout@v2 + uses: actions/checkout@v2.3.4 - id: _test_yaml_pub_upgrade name: "_test_yaml; pub upgrade --no-precompile" if: "always() && steps.checkout.conclusion == 'success'" @@ -209,7 +209,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v2 + uses: actions/cache@v2.1.5 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" @@ -222,7 +222,7 @@ jobs: with: sdk: "2.12.0" - id: checkout - uses: actions/checkout@v2 + uses: actions/checkout@v2.3.4 - id: _test_yaml_pub_upgrade name: "_test_yaml; pub upgrade --no-precompile" if: "always() && steps.checkout.conclusion == 'success'" @@ -268,7 +268,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v2 + uses: actions/cache@v2.1.5 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" @@ -281,7 +281,7 @@ jobs: with: sdk: dev - id: checkout - uses: actions/checkout@v2 + uses: actions/checkout@v2.3.4 - id: _test_yaml_pub_upgrade name: "_test_yaml; pub upgrade --no-precompile" if: "always() && steps.checkout.conclusion == 'success'" @@ -327,7 +327,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v2 + uses: actions/cache@v2.1.5 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:json_serializable;commands:test_2" @@ -340,7 +340,7 @@ jobs: with: sdk: "2.12.0" - id: checkout - uses: actions/checkout@v2 + uses: actions/checkout@v2.3.4 - id: json_serializable_pub_upgrade name: "json_serializable; pub upgrade --no-precompile" if: "always() && steps.checkout.conclusion == 'success'" @@ -359,7 +359,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v2 + uses: actions/cache@v2.1.5 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:json_serializable;commands:test_2" @@ -372,7 +372,7 @@ jobs: with: sdk: dev - id: checkout - uses: actions/checkout@v2 + uses: actions/checkout@v2.3.4 - id: json_serializable_pub_upgrade name: "json_serializable; pub upgrade --no-precompile" if: "always() && steps.checkout.conclusion == 'success'" @@ -391,7 +391,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v2 + uses: actions/cache@v2.1.5 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_1" @@ -404,7 +404,7 @@ jobs: with: sdk: "2.12.0" - id: checkout - uses: actions/checkout@v2 + uses: actions/checkout@v2.3.4 - id: _test_yaml_pub_upgrade name: "_test_yaml; pub upgrade --no-precompile" if: "always() && steps.checkout.conclusion == 'success'" @@ -454,7 +454,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v2 + uses: actions/cache@v2.1.5 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_1" @@ -467,7 +467,7 @@ jobs: with: sdk: dev - id: checkout - uses: actions/checkout@v2 + uses: actions/checkout@v2.3.4 - id: _test_yaml_pub_upgrade name: "_test_yaml; pub upgrade --no-precompile" if: "always() && steps.checkout.conclusion == 'success'" diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index b4391dffa..50481bbaa 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,7 @@ +## 4.1.2 + +- Correctly decode `Map` when the input has `int` literals. + ## 4.1.1 - Allow the latest `package:build_config`. diff --git a/json_serializable/lib/src/type_helpers/map_helper.dart b/json_serializable/lib/src/type_helpers/map_helper.dart index d994818a0..8e74fc888 100644 --- a/json_serializable/lib/src/type_helpers/map_helper.dart +++ b/json_serializable/lib/src/type_helpers/map_helper.dart @@ -90,7 +90,9 @@ class MapHelper extends TypeHelper { if (!targetTypeIsNullable && (valueArgIsAny || - simpleJsonTypeChecker.isAssignableFromType(valueArg))) { + // explicitly exclude double since we need to do an explicit + // `toDouble` on input values + valueArg.isSimpleJsonTypeNotDouble)) { // No mapping of the values or null check required! final valueString = valueArg.getDisplayString(withNullability: false); return 'Map.from($expression as Map)'; @@ -179,3 +181,8 @@ Iterable get _allowedTypeNames => const [ 'enum', 'String', ].followedBy(_instances.map((i) => i.coreTypeName)); + +extension on DartType { + bool get isSimpleJsonTypeNotDouble => + !isDartCoreDouble && simpleJsonTypeChecker.isAssignableFromType(this); +} diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index c9eceb1af..a65e576f0 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 4.1.1 +version: 4.1.2 description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. diff --git a/json_serializable/test/enum_helper_test.dart b/json_serializable/test/enum_helper_test.dart index 8043543b7..4399dc843 100644 --- a/json_serializable/test/enum_helper_test.dart +++ b/json_serializable/test/enum_helper_test.dart @@ -3,9 +3,8 @@ // BSD-style license that can be found in the LICENSE file. @TestOn('vm') - -import 'package:test/test.dart'; import 'package:json_serializable/src/type_helpers/enum_helper.dart'; +import 'package:test/test.dart'; void main() { group('expression test', () { diff --git a/json_serializable/test/supported_types/input.type_map.g.dart b/json_serializable/test/supported_types/input.type_map.g.dart index 55608e727..4780cc504 100644 --- a/json_serializable/test/supported_types/input.type_map.g.dart +++ b/json_serializable/test/supported_types/input.type_map.g.dart @@ -1651,7 +1651,9 @@ Map _$SimpleClassNullableOfDateTimeToDoubleToJson( SimpleClassOfDynamicToDouble _$SimpleClassOfDynamicToDoubleFromJson( Map json) { return SimpleClassOfDynamicToDouble( - Map.from(json['value'] as Map), + (json['value'] as Map).map( + (k, e) => MapEntry(k, (e as num).toDouble()), + ), ); } @@ -1741,7 +1743,9 @@ Map _$SimpleClassNullableOfIntToDoubleToJson( SimpleClassOfObjectToDouble _$SimpleClassOfObjectToDoubleFromJson( Map json) { return SimpleClassOfObjectToDouble( - Map.from(json['value'] as Map), + (json['value'] as Map).map( + (k, e) => MapEntry(k, (e as num).toDouble()), + ), ); } @@ -1769,7 +1773,9 @@ Map _$SimpleClassNullableOfObjectToDoubleToJson( SimpleClassOfStringToDouble _$SimpleClassOfStringToDoubleFromJson( Map json) { return SimpleClassOfStringToDouble( - Map.from(json['value'] as Map), + (json['value'] as Map).map( + (k, e) => MapEntry(k, (e as num).toDouble()), + ), ); } @@ -1889,7 +1895,9 @@ Map _$SimpleClassNullableOfDateTimeToDoubleNullableToJson( SimpleClassOfDynamicToDoubleNullable _$SimpleClassOfDynamicToDoubleNullableFromJson(Map json) { return SimpleClassOfDynamicToDoubleNullable( - Map.from(json['value'] as Map), + (json['value'] as Map).map( + (k, e) => MapEntry(k, (e as num?)?.toDouble()), + ), ); } @@ -1982,7 +1990,9 @@ Map _$SimpleClassNullableOfIntToDoubleNullableToJson( SimpleClassOfObjectToDoubleNullable _$SimpleClassOfObjectToDoubleNullableFromJson(Map json) { return SimpleClassOfObjectToDoubleNullable( - Map.from(json['value'] as Map), + (json['value'] as Map).map( + (k, e) => MapEntry(k, (e as num?)?.toDouble()), + ), ); } @@ -2011,7 +2021,9 @@ Map _$SimpleClassNullableOfObjectToDoubleNullableToJson( SimpleClassOfStringToDoubleNullable _$SimpleClassOfStringToDoubleNullableFromJson(Map json) { return SimpleClassOfStringToDoubleNullable( - Map.from(json['value'] as Map), + (json['value'] as Map).map( + (k, e) => MapEntry(k, (e as num?)?.toDouble()), + ), ); } diff --git a/json_serializable/test/supported_types/support_types_extra_tests.dart b/json_serializable/test/supported_types/support_types_extra_tests.dart new file mode 100644 index 000000000..8ce83f390 --- /dev/null +++ b/json_serializable/test/supported_types/support_types_extra_tests.dart @@ -0,0 +1,77 @@ +// Copyright (c) 2020, 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 'dart:convert'; + +import 'package:test/test.dart'; + +import '../test_utils.dart'; +import 'input.type_map.dart'; + +void main() { + test('SimpleClassOfStringToDouble', () { + const value = { + 'value': { + 'double': 1.0, + 'int': 1, + } + }; + + final object = SimpleClassOfStringToDouble.fromJson(value); + final encoded = loudEncode(object); + + expect( + encoded, + loudEncode({ + 'value': { + 'double': 1.0, + // Note! Encoded as a double on output! + 'int': 1.0, + } + }), + ); + + final object2 = SimpleClassOfStringToDouble.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + + test('SimpleClassOfStringToInt', () { + const value = { + 'value': { + 'int': 1, + } + }; + + final object = SimpleClassOfStringToInt.fromJson(value); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(value)); + + final object2 = SimpleClassOfStringToInt.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); + + test('SimpleClassOfStringToNum', () { + const value = { + 'value': { + 'double': 1.0, + 'int': 1, + } + }; + + final object = SimpleClassOfStringToNum.fromJson(value); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(value)); + + final object2 = SimpleClassOfStringToNum.fromJson( + jsonDecode(encoded) as Map, + ); + expect(loudEncode(object2), encoded); + }); +} diff --git a/json_serializable/test/utils_test.dart b/json_serializable/test/utils_test.dart index aedc7d0a1..7aaec8a44 100644 --- a/json_serializable/test/utils_test.dart +++ b/json_serializable/test/utils_test.dart @@ -3,10 +3,8 @@ // BSD-style license that can be found in the LICENSE file. @TestOn('vm') - -import 'package:test/test.dart'; - import 'package:json_serializable/src/utils.dart'; +import 'package:test/test.dart'; const _kebabItems = { 'simple': 'simple', diff --git a/mono_repo.yaml b/mono_repo.yaml index fa5d6056e..84f7b7d50 100644 --- a/mono_repo.yaml +++ b/mono_repo.yaml @@ -6,7 +6,7 @@ github: push: branches: - master - - 3_x + - 4_x pull_request: schedule: - cron: "0 0 * * 0" diff --git a/tool/ci.sh b/tool/ci.sh index e82813c21..e5d867207 100755 --- a/tool/ci.sh +++ b/tool/ci.sh @@ -1,12 +1,23 @@ #!/bin/bash -# Created with package:mono_repo v3.4.7 +# Created with package:mono_repo v4.0.0 # Support built in commands on windows out of the box. +# When it is a flutter repo (check the pubspec.yaml for "sdk: flutter") +# then "flutter" is called instead of "pub". +# This assumes that the Flutter SDK has been installed in a previous step. function pub() { - if [[ $TRAVIS_OS_NAME == "windows" ]]; then - command pub.bat "$@" + if grep -Fq "sdk: flutter" "${PWD}/pubspec.yaml"; then + if [[ $TRAVIS_OS_NAME == "windows" ]]; then + command flutter.bat pub "$@" + else + command flutter pub "$@" + fi else - command pub "$@" + if [[ $TRAVIS_OS_NAME == "windows" ]]; then + command pub.bat "$@" + else + command pub "$@" + fi fi } function dartfmt() { From 1666cdcac0bbcb62259c6929d29be1381e6fc876 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 19 May 2021 20:33:37 -0700 Subject: [PATCH 306/569] Add dependabot --- .github/dependabot.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 000000000..655f40367 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,11 @@ +# Set update schedule for GitHub Actions +# See https://docs.github.com/en/code-security/supply-chain-security/keeping-your-dependencies-updated-automatically + +version: 2 +updates: + +- package-ecosystem: "github-actions" + directory: "/" + schedule: + # Check for updates to GitHub Actions weekly + interval: "weekly" From 7d582b7bcdc94e46e4d215570719c87a67e01755 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 19 May 2021 20:37:03 -0700 Subject: [PATCH 307/569] Bump actions/setup-node from 1 to 2.1.5 (#897) Bumps [actions/setup-node](https://github.com/actions/setup-node) from 1 to 2.1.5. - [Release notes](https://github.com/actions/setup-node/releases) - [Commits](https://github.com/actions/setup-node/compare/v1...v2.1.5) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/markdown_linter.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/markdown_linter.yml b/.github/workflows/markdown_linter.yml index 779021a03..53509b0bd 100644 --- a/.github/workflows/markdown_linter.yml +++ b/.github/workflows/markdown_linter.yml @@ -21,7 +21,7 @@ jobs: steps: - uses: actions/checkout@master - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v1 + uses: actions/setup-node@v2.1.5 with: node-version: ${{ matrix.node-version }} - name: Install dependencies From 25f7a1f2c57d263b56f5338fa2c8c8d82e10ca6e Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 26 May 2021 10:24:32 -0700 Subject: [PATCH 308/569] Correctly handle nullable types with type arguments in generated code (#901) Missed a code path where `?` should be included when a type has arguments Fixes https://github.com/google/json_serializable.dart/issues/896 Prepare to release 4.1.3 --- json_serializable/CHANGELOG.md | 4 +++ json_serializable/lib/src/helper_core.dart | 12 ++++----- json_serializable/pubspec.yaml | 2 +- .../test/integration/integration_test.dart | 26 +++++++++++++++---- .../test/integration/json_test_example.dart | 25 ++++++++++++++++++ .../test/integration/json_test_example.g.dart | 4 ++- .../json_test_example.g_any_map.dart | 25 ++++++++++++++++++ .../json_test_example.g_any_map.g.dart | 4 ++- 8 files changed, 87 insertions(+), 15 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 50481bbaa..4077a22f2 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,7 @@ +## 4.1.3 + +- Correctly handle nullable types with type arguments in generated code. + ## 4.1.2 - Correctly decode `Map` when the input has `int` literals. diff --git a/json_serializable/lib/src/helper_core.dart b/json_serializable/lib/src/helper_core.dart index ce1670a71..1f25b7ef3 100644 --- a/json_serializable/lib/src/helper_core.dart +++ b/json_serializable/lib/src/helper_core.dart @@ -141,13 +141,11 @@ String typeToCode( return 'dynamic'; } else if (type is InterfaceType) { final typeArguments = type.typeArguments; - if (typeArguments.isEmpty) { - final nullablePostfix = (type.isNullableType || forceNullable) ? '?' : ''; - return '${type.element.name}$nullablePostfix'; - } else { - final typeArgumentsCode = typeArguments.map(typeToCode).join(', '); - return '${type.element.name}<$typeArgumentsCode>'; - } + final typeArgumentsCode = typeArguments.isEmpty + ? '' + : '<${typeArguments.map(typeToCode).join(', ')}>'; + final nullablePostfix = (type.isNullableType || forceNullable) ? '?' : ''; + return '${type.element.name}$typeArgumentsCode$nullablePostfix'; } throw UnimplementedError('(${type.runtimeType}) $type'); } diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index a65e576f0..0ba073c14 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 4.1.2 +version: 4.1.3 description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. diff --git a/json_serializable/test/integration/integration_test.dart b/json_serializable/test/integration/integration_test.dart index c86f4ffbf..c25327ebb 100644 --- a/json_serializable/test/integration/integration_test.dart +++ b/json_serializable/test/integration/integration_test.dart @@ -195,8 +195,16 @@ void main() { expect(item.saleDates, isNull); roundTripItem(item); - expect(item.toJson().keys, orderedEquals(['price', 'saleDates', 'rates']), - reason: 'Omits null `itemNumber`'); + expect( + item.toJson().keys, + orderedEquals([ + 'price', + 'saleDates', + 'rates', + 'geoPoint', + ]), + reason: 'Omits null `itemNumber`', + ); }); test('set itemNumber - with custom JSON key', () { @@ -204,9 +212,17 @@ void main() { expect(item.itemNumber, 42); roundTripItem(item); - expect(item.toJson().keys, - orderedEquals(['price', 'item-number', 'saleDates', 'rates']), - reason: 'Includes non-null `itemNumber` - with custom key'); + expect( + item.toJson().keys, + orderedEquals([ + 'price', + 'item-number', + 'saleDates', + 'rates', + 'geoPoint', + ]), + reason: 'Includes non-null `itemNumber` - with custom key', + ); }); }); diff --git a/json_serializable/test/integration/json_test_example.dart b/json_serializable/test/integration/json_test_example.dart index 6a30846fe..ba344482d 100644 --- a/json_serializable/test/integration/json_test_example.dart +++ b/json_serializable/test/integration/json_test_example.dart @@ -104,6 +104,10 @@ class Item extends ItemCore { List? saleDates; List? rates; + // Regression test for https://github.com/google/json_serializable.dart/issues/896 + @JsonKey(fromJson: _fromJsonGeoPoint, toJson: _toJsonGeoPoint) + GeoPoint? geoPoint; + Item([int? price]) : super(price); factory Item.fromJson(Map json) => _$ItemFromJson(json); @@ -118,6 +122,27 @@ class Item extends ItemCore { deepEquals(saleDates, other.saleDates); } +GeoPoint? _fromJsonGeoPoint(Map? json) { + if (json != null) { + return GeoPoint(json['latitude'], json['longitude']); + } else { + return null; + } +} + +Map? _toJsonGeoPoint(GeoPoint? geoPoint) { + if (geoPoint == null) { + return null; + } + return {'latitude': geoPoint.latitude, 'longitude': geoPoint.longitude}; +} + +class GeoPoint { + final Object? latitude, longitude; + + GeoPoint(this.latitude, this.longitude); +} + @JsonSerializable() class Numbers { List? ints; diff --git a/json_serializable/test/integration/json_test_example.g.dart b/json_serializable/test/integration/json_test_example.g.dart index da899ac94..d7acc541f 100644 --- a/json_serializable/test/integration/json_test_example.g.dart +++ b/json_serializable/test/integration/json_test_example.g.dart @@ -155,7 +155,8 @@ Item _$ItemFromJson(Map json) { ..saleDates = (json['saleDates'] as List?) ?.map((e) => DateTime.parse(e as String)) .toList() - ..rates = (json['rates'] as List?)?.map((e) => e as int).toList(); + ..rates = (json['rates'] as List?)?.map((e) => e as int).toList() + ..geoPoint = _fromJsonGeoPoint(json['geoPoint'] as Map?); } Map _$ItemToJson(Item instance) { @@ -173,6 +174,7 @@ Map _$ItemToJson(Item instance) { val['saleDates'] = instance.saleDates?.map((e) => e.toIso8601String()).toList(); val['rates'] = instance.rates; + val['geoPoint'] = _toJsonGeoPoint(instance.geoPoint); return val; } diff --git a/json_serializable/test/integration/json_test_example.g_any_map.dart b/json_serializable/test/integration/json_test_example.g_any_map.dart index c61b891bc..d4ee3c60e 100644 --- a/json_serializable/test/integration/json_test_example.g_any_map.dart +++ b/json_serializable/test/integration/json_test_example.g_any_map.dart @@ -110,6 +110,10 @@ class Item extends ItemCore { List? saleDates; List? rates; + // Regression test for https://github.com/google/json_serializable.dart/issues/896 + @JsonKey(fromJson: _fromJsonGeoPoint, toJson: _toJsonGeoPoint) + GeoPoint? geoPoint; + Item([int? price]) : super(price); factory Item.fromJson(Map json) => _$ItemFromJson(json); @@ -124,6 +128,27 @@ class Item extends ItemCore { deepEquals(saleDates, other.saleDates); } +GeoPoint? _fromJsonGeoPoint(Map? json) { + if (json != null) { + return GeoPoint(json['latitude'], json['longitude']); + } else { + return null; + } +} + +Map? _toJsonGeoPoint(GeoPoint? geoPoint) { + if (geoPoint == null) { + return null; + } + return {'latitude': geoPoint.latitude, 'longitude': geoPoint.longitude}; +} + +class GeoPoint { + final Object? latitude, longitude; + + GeoPoint(this.latitude, this.longitude); +} + @JsonSerializable( anyMap: true, ) diff --git a/json_serializable/test/integration/json_test_example.g_any_map.g.dart b/json_serializable/test/integration/json_test_example.g_any_map.g.dart index bfa0c1378..6f64f7238 100644 --- a/json_serializable/test/integration/json_test_example.g_any_map.g.dart +++ b/json_serializable/test/integration/json_test_example.g_any_map.g.dart @@ -155,7 +155,8 @@ Item _$ItemFromJson(Map json) { ..saleDates = (json['saleDates'] as List?) ?.map((e) => DateTime.parse(e as String)) .toList() - ..rates = (json['rates'] as List?)?.map((e) => e as int).toList(); + ..rates = (json['rates'] as List?)?.map((e) => e as int).toList() + ..geoPoint = _fromJsonGeoPoint(json['geoPoint'] as Map?); } Map _$ItemToJson(Item instance) { @@ -173,6 +174,7 @@ Map _$ItemToJson(Item instance) { val['saleDates'] = instance.saleDates?.map((e) => e.toIso8601String()).toList(); val['rates'] = instance.rates; + val['geoPoint'] = _toJsonGeoPoint(instance.geoPoint); return val; } From 39cc674cb71316c0a1411ed9e59bd192e926a41e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 4 Jun 2021 10:34:33 -0700 Subject: [PATCH 309/569] Bump actions/cache from 2.1.5 to 2.1.6 (#907) Bumps [actions/cache](https://github.com/actions/cache) from 2.1.5 to 2.1.6. - [Release notes](https://github.com/actions/cache/releases) - [Commits](https://github.com/actions/cache/compare/v2.1.5...v2.1.6) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Kevin Moore --- .github/workflows/dart.yml | 350 ++++++++++++++++++------------------- tool/ci.sh | 30 ++-- 2 files changed, 190 insertions(+), 190 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 7f5b10c30..703ace866 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -1,4 +1,4 @@ -# Created with package:mono_repo v4.0.0 +# Created with package:mono_repo v4.1.0 name: Dart CI on: push: @@ -20,7 +20,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v2.1.5 + uses: actions/cache@v2.1.6 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;dart:stable" @@ -33,15 +33,15 @@ jobs: - id: checkout uses: actions/checkout@v2.3.4 - name: mono_repo self validate - run: pub global activate mono_repo 4.0.0 + run: dart pub global activate mono_repo 4.1.0 - name: mono_repo self validate - run: pub global run mono_repo generate --validate + run: dart pub global run mono_repo generate --validate job_002: - name: "analyzer_and_format; Dart 2.12.0; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; `dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-infos .`" + name: "analyzer_and_format; Dart 2.12.0; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; `dart format --output=none --set-exit-if-changed .`, `dart analyze --fatal-infos .`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v2.1.5 + uses: actions/cache@v2.1.6 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:dartfmt-dartanalyzer" @@ -56,76 +56,76 @@ jobs: - id: checkout uses: actions/checkout@v2.3.4 - id: _test_yaml_pub_upgrade - name: "_test_yaml; pub upgrade --no-precompile" + name: _test_yaml; pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: _test_yaml - run: pub upgrade --no-precompile - - name: "_test_yaml; dartfmt -n --set-exit-if-changed ." + run: pub upgrade + - name: "_test_yaml; dart format --output=none --set-exit-if-changed ." if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" working-directory: _test_yaml - run: dartfmt -n --set-exit-if-changed . - - name: "_test_yaml; dartanalyzer --fatal-infos ." + run: "dart format --output=none --set-exit-if-changed ." + - name: "_test_yaml; dart analyze --fatal-infos ." if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" working-directory: _test_yaml - run: dartanalyzer --fatal-infos . + run: dart analyze --fatal-infos . - id: checked_yaml_pub_upgrade - name: "checked_yaml; pub upgrade --no-precompile" + name: checked_yaml; pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: checked_yaml - run: pub upgrade --no-precompile - - name: "checked_yaml; dartfmt -n --set-exit-if-changed ." + run: pub upgrade + - name: "checked_yaml; dart format --output=none --set-exit-if-changed ." if: "always() && steps.checked_yaml_pub_upgrade.conclusion == 'success'" working-directory: checked_yaml - run: dartfmt -n --set-exit-if-changed . - - name: "checked_yaml; dartanalyzer --fatal-infos ." + run: "dart format --output=none --set-exit-if-changed ." + - name: "checked_yaml; dart analyze --fatal-infos ." if: "always() && steps.checked_yaml_pub_upgrade.conclusion == 'success'" working-directory: checked_yaml - run: dartanalyzer --fatal-infos . + run: dart analyze --fatal-infos . - id: example_pub_upgrade - name: "example; pub upgrade --no-precompile" + name: example; pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: example - run: pub upgrade --no-precompile - - name: "example; dartfmt -n --set-exit-if-changed ." + run: pub upgrade + - name: "example; dart format --output=none --set-exit-if-changed ." if: "always() && steps.example_pub_upgrade.conclusion == 'success'" working-directory: example - run: dartfmt -n --set-exit-if-changed . - - name: "example; dartanalyzer --fatal-infos ." + run: "dart format --output=none --set-exit-if-changed ." + - name: "example; dart analyze --fatal-infos ." if: "always() && steps.example_pub_upgrade.conclusion == 'success'" working-directory: example - run: dartanalyzer --fatal-infos . + run: dart analyze --fatal-infos . - id: json_annotation_pub_upgrade - name: "json_annotation; pub upgrade --no-precompile" + name: json_annotation; pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: json_annotation - run: pub upgrade --no-precompile - - name: "json_annotation; dartfmt -n --set-exit-if-changed ." + run: pub upgrade + - name: "json_annotation; dart format --output=none --set-exit-if-changed ." if: "always() && steps.json_annotation_pub_upgrade.conclusion == 'success'" working-directory: json_annotation - run: dartfmt -n --set-exit-if-changed . - - name: "json_annotation; dartanalyzer --fatal-infos ." + run: "dart format --output=none --set-exit-if-changed ." + - name: "json_annotation; dart analyze --fatal-infos ." if: "always() && steps.json_annotation_pub_upgrade.conclusion == 'success'" working-directory: json_annotation - run: dartanalyzer --fatal-infos . + run: dart analyze --fatal-infos . - id: json_serializable_pub_upgrade - name: "json_serializable; pub upgrade --no-precompile" + name: json_serializable; pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: json_serializable - run: pub upgrade --no-precompile - - name: "json_serializable; dartfmt -n --set-exit-if-changed ." + run: pub upgrade + - name: "json_serializable; dart format --output=none --set-exit-if-changed ." if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" working-directory: json_serializable - run: dartfmt -n --set-exit-if-changed . - - name: "json_serializable; dartanalyzer --fatal-infos ." + run: "dart format --output=none --set-exit-if-changed ." + - name: "json_serializable; dart analyze --fatal-infos ." if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" working-directory: json_serializable - run: dartanalyzer --fatal-infos . + run: dart analyze --fatal-infos . job_003: - name: "analyzer_and_format; Dart dev; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; `dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-infos .`" + name: "analyzer_and_format; Dart dev; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; `dart format --output=none --set-exit-if-changed .`, `dart analyze --fatal-infos .`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v2.1.5 + uses: actions/cache@v2.1.6 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:dartfmt-dartanalyzer" @@ -140,76 +140,76 @@ jobs: - id: checkout uses: actions/checkout@v2.3.4 - id: _test_yaml_pub_upgrade - name: "_test_yaml; pub upgrade --no-precompile" + name: _test_yaml; pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: _test_yaml - run: pub upgrade --no-precompile - - name: "_test_yaml; dartfmt -n --set-exit-if-changed ." + run: pub upgrade + - name: "_test_yaml; dart format --output=none --set-exit-if-changed ." if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" working-directory: _test_yaml - run: dartfmt -n --set-exit-if-changed . - - name: "_test_yaml; dartanalyzer --fatal-infos ." + run: "dart format --output=none --set-exit-if-changed ." + - name: "_test_yaml; dart analyze --fatal-infos ." if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" working-directory: _test_yaml - run: dartanalyzer --fatal-infos . + run: dart analyze --fatal-infos . - id: checked_yaml_pub_upgrade - name: "checked_yaml; pub upgrade --no-precompile" + name: checked_yaml; pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: checked_yaml - run: pub upgrade --no-precompile - - name: "checked_yaml; dartfmt -n --set-exit-if-changed ." + run: pub upgrade + - name: "checked_yaml; dart format --output=none --set-exit-if-changed ." if: "always() && steps.checked_yaml_pub_upgrade.conclusion == 'success'" working-directory: checked_yaml - run: dartfmt -n --set-exit-if-changed . - - name: "checked_yaml; dartanalyzer --fatal-infos ." + run: "dart format --output=none --set-exit-if-changed ." + - name: "checked_yaml; dart analyze --fatal-infos ." if: "always() && steps.checked_yaml_pub_upgrade.conclusion == 'success'" working-directory: checked_yaml - run: dartanalyzer --fatal-infos . + run: dart analyze --fatal-infos . - id: example_pub_upgrade - name: "example; pub upgrade --no-precompile" + name: example; pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: example - run: pub upgrade --no-precompile - - name: "example; dartfmt -n --set-exit-if-changed ." + run: pub upgrade + - name: "example; dart format --output=none --set-exit-if-changed ." if: "always() && steps.example_pub_upgrade.conclusion == 'success'" working-directory: example - run: dartfmt -n --set-exit-if-changed . - - name: "example; dartanalyzer --fatal-infos ." + run: "dart format --output=none --set-exit-if-changed ." + - name: "example; dart analyze --fatal-infos ." if: "always() && steps.example_pub_upgrade.conclusion == 'success'" working-directory: example - run: dartanalyzer --fatal-infos . + run: dart analyze --fatal-infos . - id: json_annotation_pub_upgrade - name: "json_annotation; pub upgrade --no-precompile" + name: json_annotation; pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: json_annotation - run: pub upgrade --no-precompile - - name: "json_annotation; dartfmt -n --set-exit-if-changed ." + run: pub upgrade + - name: "json_annotation; dart format --output=none --set-exit-if-changed ." if: "always() && steps.json_annotation_pub_upgrade.conclusion == 'success'" working-directory: json_annotation - run: dartfmt -n --set-exit-if-changed . - - name: "json_annotation; dartanalyzer --fatal-infos ." + run: "dart format --output=none --set-exit-if-changed ." + - name: "json_annotation; dart analyze --fatal-infos ." if: "always() && steps.json_annotation_pub_upgrade.conclusion == 'success'" working-directory: json_annotation - run: dartanalyzer --fatal-infos . + run: dart analyze --fatal-infos . - id: json_serializable_pub_upgrade - name: "json_serializable; pub upgrade --no-precompile" + name: json_serializable; pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: json_serializable - run: pub upgrade --no-precompile - - name: "json_serializable; dartfmt -n --set-exit-if-changed ." + run: pub upgrade + - name: "json_serializable; dart format --output=none --set-exit-if-changed ." if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" working-directory: json_serializable - run: dartfmt -n --set-exit-if-changed . - - name: "json_serializable; dartanalyzer --fatal-infos ." + run: "dart format --output=none --set-exit-if-changed ." + - name: "json_serializable; dart analyze --fatal-infos ." if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" working-directory: json_serializable - run: dartanalyzer --fatal-infos . + run: dart analyze --fatal-infos . job_004: - name: "unit_test; Dart 2.12.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; `pub run test`" + name: "unit_test; Dart 2.12.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; `dart test`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v2.1.5 + uses: actions/cache@v2.1.6 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" @@ -224,142 +224,142 @@ jobs: - id: checkout uses: actions/checkout@v2.3.4 - id: _test_yaml_pub_upgrade - name: "_test_yaml; pub upgrade --no-precompile" + name: _test_yaml; pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: _test_yaml - run: pub upgrade --no-precompile - - name: _test_yaml; pub run test + run: pub upgrade + - name: _test_yaml; dart test if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" working-directory: _test_yaml - run: pub run test + run: dart test - id: checked_yaml_pub_upgrade - name: "checked_yaml; pub upgrade --no-precompile" + name: checked_yaml; pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: checked_yaml - run: pub upgrade --no-precompile - - name: checked_yaml; pub run test + run: pub upgrade + - name: checked_yaml; dart test if: "always() && steps.checked_yaml_pub_upgrade.conclusion == 'success'" working-directory: checked_yaml - run: pub run test + run: dart test - id: example_pub_upgrade - name: "example; pub upgrade --no-precompile" + name: example; pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: example - run: pub upgrade --no-precompile - - name: example; pub run test + run: pub upgrade + - name: example; dart test if: "always() && steps.example_pub_upgrade.conclusion == 'success'" working-directory: example - run: pub run test + run: dart test - id: json_serializable_pub_upgrade - name: "json_serializable; pub upgrade --no-precompile" + name: json_serializable; pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: json_serializable - run: pub upgrade --no-precompile - - name: json_serializable; pub run test + run: pub upgrade + - name: json_serializable; dart test if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" working-directory: json_serializable - run: pub run test + run: dart test needs: - job_001 - job_002 - job_003 job_005: - name: "unit_test; Dart dev; PKGS: _test_yaml, checked_yaml, example, json_serializable; `pub run test`" + name: "unit_test; Dart 2.12.0; PKG: json_serializable; `dart test -p chrome`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v2.1.5 + uses: actions/cache@v2.1.6 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" + key: "os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:json_serializable;commands:test_2" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:_test_yaml-checked_yaml-example-json_serializable - os:ubuntu-latest;pub-cache-hosted;dart:dev + os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:json_serializable + os:ubuntu-latest;pub-cache-hosted;dart:2.12.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - uses: dart-lang/setup-dart@v1.0 with: - sdk: dev + sdk: "2.12.0" - id: checkout uses: actions/checkout@v2.3.4 - - id: _test_yaml_pub_upgrade - name: "_test_yaml; pub upgrade --no-precompile" - if: "always() && steps.checkout.conclusion == 'success'" - working-directory: _test_yaml - run: pub upgrade --no-precompile - - name: _test_yaml; pub run test - if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" - working-directory: _test_yaml - run: pub run test - - id: checked_yaml_pub_upgrade - name: "checked_yaml; pub upgrade --no-precompile" - if: "always() && steps.checkout.conclusion == 'success'" - working-directory: checked_yaml - run: pub upgrade --no-precompile - - name: checked_yaml; pub run test - if: "always() && steps.checked_yaml_pub_upgrade.conclusion == 'success'" - working-directory: checked_yaml - run: pub run test - - id: example_pub_upgrade - name: "example; pub upgrade --no-precompile" - if: "always() && steps.checkout.conclusion == 'success'" - working-directory: example - run: pub upgrade --no-precompile - - name: example; pub run test - if: "always() && steps.example_pub_upgrade.conclusion == 'success'" - working-directory: example - run: pub run test - id: json_serializable_pub_upgrade - name: "json_serializable; pub upgrade --no-precompile" + name: json_serializable; pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: json_serializable - run: pub upgrade --no-precompile - - name: json_serializable; pub run test + run: pub upgrade + - name: "json_serializable; dart test -p chrome" if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" working-directory: json_serializable - run: pub run test + run: dart test -p chrome needs: - job_001 - job_002 - job_003 job_006: - name: "unit_test; Dart 2.12.0; PKG: json_serializable; `pub run test -p chrome`" + name: "unit_test; Dart dev; PKGS: _test_yaml, checked_yaml, example, json_serializable; `dart test`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v2.1.5 + uses: actions/cache@v2.1.6 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:json_serializable;commands:test_2" + key: "os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:json_serializable - os:ubuntu-latest;pub-cache-hosted;dart:2.12.0 + os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:_test_yaml-checked_yaml-example-json_serializable + os:ubuntu-latest;pub-cache-hosted;dart:dev os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - uses: dart-lang/setup-dart@v1.0 with: - sdk: "2.12.0" + sdk: dev - id: checkout uses: actions/checkout@v2.3.4 + - id: _test_yaml_pub_upgrade + name: _test_yaml; pub upgrade + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: _test_yaml + run: pub upgrade + - name: _test_yaml; dart test + if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" + working-directory: _test_yaml + run: dart test + - id: checked_yaml_pub_upgrade + name: checked_yaml; pub upgrade + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: checked_yaml + run: pub upgrade + - name: checked_yaml; dart test + if: "always() && steps.checked_yaml_pub_upgrade.conclusion == 'success'" + working-directory: checked_yaml + run: dart test + - id: example_pub_upgrade + name: example; pub upgrade + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: example + run: pub upgrade + - name: example; dart test + if: "always() && steps.example_pub_upgrade.conclusion == 'success'" + working-directory: example + run: dart test - id: json_serializable_pub_upgrade - name: "json_serializable; pub upgrade --no-precompile" + name: json_serializable; pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: json_serializable - run: pub upgrade --no-precompile - - name: "json_serializable; pub run test -p chrome" + run: pub upgrade + - name: json_serializable; dart test if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" working-directory: json_serializable - run: pub run test -p chrome + run: dart test needs: - job_001 - job_002 - job_003 job_007: - name: "unit_test; Dart dev; PKG: json_serializable; `pub run test -p chrome`" + name: "unit_test; Dart dev; PKG: json_serializable; `dart test -p chrome`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v2.1.5 + uses: actions/cache@v2.1.6 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:json_serializable;commands:test_2" @@ -374,24 +374,24 @@ jobs: - id: checkout uses: actions/checkout@v2.3.4 - id: json_serializable_pub_upgrade - name: "json_serializable; pub upgrade --no-precompile" + name: json_serializable; pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: json_serializable - run: pub upgrade --no-precompile - - name: "json_serializable; pub run test -p chrome" + run: pub upgrade + - name: "json_serializable; dart test -p chrome" if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" working-directory: json_serializable - run: pub run test -p chrome + run: dart test -p chrome needs: - job_001 - job_002 - job_003 job_008: - name: "ensure_build; Dart 2.12.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`" + name: "ensure_build; Dart 2.12.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v2.1.5 + uses: actions/cache@v2.1.6 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_1" @@ -406,41 +406,41 @@ jobs: - id: checkout uses: actions/checkout@v2.3.4 - id: _test_yaml_pub_upgrade - name: "_test_yaml; pub upgrade --no-precompile" + name: _test_yaml; pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: _test_yaml - run: pub upgrade --no-precompile - - name: "_test_yaml; pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart" + run: pub upgrade + - name: "_test_yaml; dart test --run-skipped -t presubmit-only test/ensure_build_test.dart" if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" working-directory: _test_yaml - run: pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart + run: dart test --run-skipped -t presubmit-only test/ensure_build_test.dart - id: checked_yaml_pub_upgrade - name: "checked_yaml; pub upgrade --no-precompile" + name: checked_yaml; pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: checked_yaml - run: pub upgrade --no-precompile - - name: "checked_yaml; pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart" + run: pub upgrade + - name: "checked_yaml; dart test --run-skipped -t presubmit-only test/ensure_build_test.dart" if: "always() && steps.checked_yaml_pub_upgrade.conclusion == 'success'" working-directory: checked_yaml - run: pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart + run: dart test --run-skipped -t presubmit-only test/ensure_build_test.dart - id: example_pub_upgrade - name: "example; pub upgrade --no-precompile" + name: example; pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: example - run: pub upgrade --no-precompile - - name: "example; pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart" + run: pub upgrade + - name: "example; dart test --run-skipped -t presubmit-only test/ensure_build_test.dart" if: "always() && steps.example_pub_upgrade.conclusion == 'success'" working-directory: example - run: pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart + run: dart test --run-skipped -t presubmit-only test/ensure_build_test.dart - id: json_serializable_pub_upgrade - name: "json_serializable; pub upgrade --no-precompile" + name: json_serializable; pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: json_serializable - run: pub upgrade --no-precompile - - name: "json_serializable; pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart" + run: pub upgrade + - name: "json_serializable; dart test --run-skipped -t presubmit-only test/ensure_build_test.dart" if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" working-directory: json_serializable - run: pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart + run: dart test --run-skipped -t presubmit-only test/ensure_build_test.dart needs: - job_001 - job_002 @@ -450,11 +450,11 @@ jobs: - job_006 - job_007 job_009: - name: "ensure_build; Dart dev; PKGS: _test_yaml, checked_yaml, example, json_serializable; `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`" + name: "ensure_build; Dart dev; PKGS: _test_yaml, checked_yaml, example, json_serializable; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v2.1.5 + uses: actions/cache@v2.1.6 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_1" @@ -469,41 +469,41 @@ jobs: - id: checkout uses: actions/checkout@v2.3.4 - id: _test_yaml_pub_upgrade - name: "_test_yaml; pub upgrade --no-precompile" + name: _test_yaml; pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: _test_yaml - run: pub upgrade --no-precompile - - name: "_test_yaml; pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart" + run: pub upgrade + - name: "_test_yaml; dart test --run-skipped -t presubmit-only test/ensure_build_test.dart" if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" working-directory: _test_yaml - run: pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart + run: dart test --run-skipped -t presubmit-only test/ensure_build_test.dart - id: checked_yaml_pub_upgrade - name: "checked_yaml; pub upgrade --no-precompile" + name: checked_yaml; pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: checked_yaml - run: pub upgrade --no-precompile - - name: "checked_yaml; pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart" + run: pub upgrade + - name: "checked_yaml; dart test --run-skipped -t presubmit-only test/ensure_build_test.dart" if: "always() && steps.checked_yaml_pub_upgrade.conclusion == 'success'" working-directory: checked_yaml - run: pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart + run: dart test --run-skipped -t presubmit-only test/ensure_build_test.dart - id: example_pub_upgrade - name: "example; pub upgrade --no-precompile" + name: example; pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: example - run: pub upgrade --no-precompile - - name: "example; pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart" + run: pub upgrade + - name: "example; dart test --run-skipped -t presubmit-only test/ensure_build_test.dart" if: "always() && steps.example_pub_upgrade.conclusion == 'success'" working-directory: example - run: pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart + run: dart test --run-skipped -t presubmit-only test/ensure_build_test.dart - id: json_serializable_pub_upgrade - name: "json_serializable; pub upgrade --no-precompile" + name: json_serializable; pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: json_serializable - run: pub upgrade --no-precompile - - name: "json_serializable; pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart" + run: pub upgrade + - name: "json_serializable; dart test --run-skipped -t presubmit-only test/ensure_build_test.dart" if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" working-directory: json_serializable - run: pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart + run: dart test --run-skipped -t presubmit-only test/ensure_build_test.dart needs: - job_001 - job_002 diff --git a/tool/ci.sh b/tool/ci.sh index e5d867207..c3a24113b 100755 --- a/tool/ci.sh +++ b/tool/ci.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Created with package:mono_repo v4.0.0 +# Created with package:mono_repo v4.1.0 # Support built in commands on windows out of the box. # When it is a flutter repo (check the pubspec.yaml for "sdk: flutter") @@ -16,7 +16,7 @@ function pub() { if [[ $TRAVIS_OS_NAME == "windows" ]]; then command pub.bat "$@" else - command pub "$@" + command dart pub "$@" fi fi } @@ -58,11 +58,11 @@ for PKG in ${PKGS}; do exit 64 fi - pub upgrade --no-precompile || EXIT_CODE=$? + dart pub upgrade || EXIT_CODE=$? if [[ ${EXIT_CODE} -ne 0 ]]; then - echo -e "\033[31mPKG: ${PKG}; 'pub upgrade' - FAILED (${EXIT_CODE})\033[0m" - FAILURES+=("${PKG}; 'pub upgrade'") + echo -e "\033[31mPKG: ${PKG}; 'dart pub upgrade' - FAILED (${EXIT_CODE})\033[0m" + FAILURES+=("${PKG}; 'dart pub upgrade'") else for TASK in "$@"; do EXIT_CODE=0 @@ -70,24 +70,24 @@ for PKG in ${PKGS}; do echo -e "\033[1mPKG: ${PKG}; TASK: ${TASK}\033[22m" case ${TASK} in dartanalyzer) - echo 'dartanalyzer --fatal-infos .' - dartanalyzer --fatal-infos . || EXIT_CODE=$? + echo 'dart analyze --fatal-infos .' + dart analyze --fatal-infos . || EXIT_CODE=$? ;; dartfmt) - echo 'dartfmt -n --set-exit-if-changed .' - dartfmt -n --set-exit-if-changed . || EXIT_CODE=$? + echo 'dart format --output=none --set-exit-if-changed .' + dart format --output=none --set-exit-if-changed . || EXIT_CODE=$? ;; test_0) - echo 'pub run test' - pub run test || EXIT_CODE=$? + echo 'dart test' + dart test || EXIT_CODE=$? ;; test_1) - echo 'pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart' - pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart || EXIT_CODE=$? + echo 'dart test --run-skipped -t presubmit-only test/ensure_build_test.dart' + dart test --run-skipped -t presubmit-only test/ensure_build_test.dart || EXIT_CODE=$? ;; test_2) - echo 'pub run test -p chrome' - pub run test -p chrome || EXIT_CODE=$? + echo 'dart test -p chrome' + dart test -p chrome || EXIT_CODE=$? ;; *) echo -e "\033[31mUnknown TASK '${TASK}' - TERMINATING JOB\033[0m" From b0a0e519c7f1103c05b31a9e5302a5da73cddd2f Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 7 Jun 2021 07:43:24 -0700 Subject: [PATCH 310/569] json_annotation: annotate annotations with the supported targets (#912) Hopefully minimizes incorrect usage. Closes https://github.com/google/json_serializable.dart/issues/910 --- json_annotation/CHANGELOG.md | 2 ++ json_annotation/lib/src/json_key.dart | 3 +++ json_annotation/lib/src/json_literal.dart | 3 +++ json_annotation/lib/src/json_serializable.dart | 3 +++ json_annotation/pubspec.yaml | 3 +++ .../test/src/_json_serializable_test_input.dart | 16 ++-------------- 6 files changed, 16 insertions(+), 14 deletions(-) diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index dfc70d0b0..3b1d43495 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -3,6 +3,8 @@ - Added a `const` constructor to `JsonConverter`. - Added `$checkedCreate` helper that will be used by `package:json_serializable` v5+ and replaces both `$checkedNew` and `$checkedConvert`. +- Annotate annotations with the supported target types, to minimize incorrect + usage. ## 4.0.1 diff --git a/json_annotation/lib/src/json_key.dart b/json_annotation/lib/src/json_key.dart index ddf68330f..4481b3cd4 100644 --- a/json_annotation/lib/src/json_key.dart +++ b/json_annotation/lib/src/json_key.dart @@ -2,10 +2,13 @@ // 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 'allowed_keys_helpers.dart'; import 'json_serializable.dart'; /// An annotation used to specify how a field is serialized. +@Target({TargetKind.field, TargetKind.getter}) class JsonKey { /// The value to use if the source JSON does not contain this key or if the /// value is `null`. diff --git a/json_annotation/lib/src/json_literal.dart b/json_annotation/lib/src/json_literal.dart index 9840e24ae..7a1159238 100644 --- a/json_annotation/lib/src/json_literal.dart +++ b/json_annotation/lib/src/json_literal.dart @@ -2,6 +2,8 @@ // 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 generate a private field containing the contents of a /// JSON file. /// @@ -15,6 +17,7 @@ /// @JsonLiteral('data.json') /// Map get glossaryData => _$glossaryDataJsonLiteral; /// ``` +@Target({TargetKind.getter}) class JsonLiteral { /// The relative path from the Dart file with the annotation to the file /// containing the source JSON. diff --git a/json_annotation/lib/src/json_serializable.dart b/json_annotation/lib/src/json_serializable.dart index ca647f024..6db0ae101 100644 --- a/json_annotation/lib/src/json_serializable.dart +++ b/json_annotation/lib/src/json_serializable.dart @@ -2,6 +2,8 @@ // 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 'allowed_keys_helpers.dart'; import 'checked_helpers.dart'; import 'json_key.dart'; @@ -29,6 +31,7 @@ enum FieldRename { disallowUnrecognizedKeys: true, fieldRename: FieldRename.snake, ) +@Target({TargetKind.classType}) class JsonSerializable { /// If `true`, [Map] types are *not* assumed to be [Map] /// – which is the default type of [Map] instances return by JSON decode in diff --git a/json_annotation/pubspec.yaml b/json_annotation/pubspec.yaml index dfdd789a1..20bc1c198 100644 --- a/json_annotation/pubspec.yaml +++ b/json_annotation/pubspec.yaml @@ -7,6 +7,9 @@ repository: https://github.com/google/json_serializable.dart environment: sdk: '>=2.12.0 <3.0.0' +dependencies: + meta: ^1.4.0 + # When changing JsonSerializable class. # dev_dependencies: # build_runner: ^1.0.0 diff --git a/json_serializable/test/src/_json_serializable_test_input.dart b/json_serializable/test/src/_json_serializable_test_input.dart index f59968aec..816f20561 100644 --- a/json_serializable/test/src/_json_serializable_test_input.dart +++ b/json_serializable/test/src/_json_serializable_test_input.dart @@ -5,40 +5,28 @@ import 'dart:collection'; import 'package:json_annotation/json_annotation.dart'; - // ignore: import_of_legacy_library_into_null_safe import 'package:source_gen_test/annotations.dart'; part 'checked_test_input.dart'; - part 'constants_copy.dart'; - part 'core_subclass_type_input.dart'; - part 'default_value_input.dart'; - part 'field_namer_input.dart'; - part 'generic_test_input.dart'; - part 'inheritance_test_input.dart'; - part 'json_converter_test_input.dart'; - part 'map_key_variety_test_input.dart'; - part 'setter_test_input.dart'; - part 'to_from_json_test_input.dart'; - part 'unknown_enum_value_test_input.dart'; @ShouldThrow('`@JsonSerializable` can only be used on classes.') -@JsonSerializable() +@JsonSerializable() // ignore: invalid_annotation_target const theAnswer = 42; @ShouldThrow('`@JsonSerializable` can only be used on classes.') -@JsonSerializable() +@JsonSerializable() // ignore: invalid_annotation_target Object annotatedMethod() => throw UnimplementedError(); @ShouldGenerate( From 4ce3ac51d4619cf237c1bc9694f6192fd1d862a1 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 10 Jun 2021 13:27:19 -0700 Subject: [PATCH 311/569] Support default values in constructors for types with a fromJson ctor (#915) Fixes https://github.com/google/json_serializable.dart/issues/903 --- json_serializable/CHANGELOG.md | 6 +- json_serializable/lib/src/decode_helper.dart | 43 ++++++----- .../lib/src/default_container.dart | 40 ++++++++++ .../lib/src/type_helpers/json_helper.dart | 6 +- .../test/default_value/default_value.dart | 8 +- .../test/default_value/default_value.g.dart | 4 + .../default_value.g_any_map__checked.dart | 8 +- .../default_value.g_any_map__checked.g.dart | 73 ++++++++++--------- .../default_value_interface.dart | 4 + .../default_value/default_value_test.dart | 6 +- .../default_value/implicit_default_value.dart | 16 ++++ .../implicit_default_value.g.dart | 13 ++++ 12 files changed, 159 insertions(+), 68 deletions(-) create mode 100644 json_serializable/lib/src/default_container.dart diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index aa851323b..80106e437 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -8,9 +8,11 @@ - Use the new `$checkedCreate` helper exposed in `package:json_annotation` v4.1+. - Generated code now conforms to this `prefer_expression_function_bodies` lint. +- Support default values in constructors for types with a `fromJson` + constructor. - `type_helper.dart`: - - **BREAKING**: removed `typeArgumentsOf`. This is now an extension exposed - by `package:source_helper`. + - **BREAKING**: removed `typeArgumentsOf`. This is now an extension exposed by + `package:source_helper`. ## 4.1.3 diff --git a/json_serializable/lib/src/decode_helper.dart b/json_serializable/lib/src/decode_helper.dart index 79aacd68e..bbce1c78d 100644 --- a/json_serializable/lib/src/decode_helper.dart +++ b/json_serializable/lib/src/decode_helper.dart @@ -8,6 +8,7 @@ import 'package:build/build.dart'; import 'package:source_gen/source_gen.dart'; import 'package:source_helper/source_helper.dart'; +import 'default_container.dart'; import 'helper_core.dart'; import 'json_literal_generator.dart'; import 'type_helpers/generic_factory_helper.dart'; @@ -187,41 +188,40 @@ abstract class DecodeHelper implements HelperCore { final jsonKeyName = safeNameAccess(field); final targetType = ctorParam?.type ?? field.type; final contextHelper = getHelperContext(field); - final defaultProvided = jsonKeyFor(field).defaultValue != null; + final jsonKey = jsonKeyFor(field); + final defaultValue = jsonKey.defaultValue; + final defaultProvided = defaultValue != null; + + String deserialize(String expression) { + final value = contextHelper.deserialize( + targetType, + expression, + defaultProvided: defaultProvided, + )!; + + return DefaultContainer.encode(value, defaultValue: defaultValue); + } String value; try { if (config.checked) { - value = contextHelper - .deserialize( - targetType, - 'v', - defaultProvided: defaultProvided, - ) - .toString(); + value = deserialize('v'); if (!checkedProperty) { value = '\$checkedConvert($jsonKeyName, (v) => $value)'; } } else { - assert(!checkedProperty, - 'should only be true if `_generator.checked` is true.'); - - value = contextHelper - .deserialize( - targetType, - 'json[$jsonKeyName]', - defaultProvided: defaultProvided, - ) - .toString(); + assert( + !checkedProperty, + 'should only be true if `_generator.checked` is true.', + ); + value = deserialize('json[$jsonKeyName]'); } } on UnsupportedTypeError catch (e) // ignore: avoid_catching_errors { throw createInvalidGenerationError('fromJson', field, e); } - final jsonKey = jsonKeyFor(field); - final defaultValue = jsonKey.defaultValue; - if (defaultValue != null) { + if (defaultProvided) { if (jsonKey.disallowNullValue && jsonKey.required) { log.warning('The `defaultValue` on field `${field.name}` will have no ' 'effect because both `disallowNullValue` and `required` are set to ' @@ -237,7 +237,6 @@ abstract class DecodeHelper implements HelperCore { 'Instead of using `defaultValue`, set `nullable: false` and handle ' '`null` in the `fromJson` function.'); } - value = '$value ?? $defaultValue'; } return value; } diff --git a/json_serializable/lib/src/default_container.dart b/json_serializable/lib/src/default_container.dart new file mode 100644 index 000000000..621dfd9f1 --- /dev/null +++ b/json_serializable/lib/src/default_container.dart @@ -0,0 +1,40 @@ +// 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. + +/// Represents an expression that may be represented differently if there is +/// a default value available to replace it if `null`. +class DefaultContainer { + final bool nullable; + final String expression; + final String output; + + DefaultContainer(this.nullable, this.expression, this.output); + + String _result([Object? defaultValue]) { + if (defaultValue != null || nullable) { + return '$expression == null ? $defaultValue : $output'; + } + + if (defaultValue == null) { + return output; + } + return '$output ?? $defaultValue'; + } + + static String encode(Object input, {Object? defaultValue}) { + if (input is DefaultContainer) { + return input._result(defaultValue); + } + + var result = input.toString(); + + if (defaultValue != null) { + result = '$result ?? $defaultValue'; + } + return result; + } + + @override + String toString() => _result(); +} diff --git a/json_serializable/lib/src/type_helpers/json_helper.dart b/json_serializable/lib/src/type_helpers/json_helper.dart index 4628f92ce..703c88abc 100644 --- a/json_serializable/lib/src/type_helpers/json_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_helper.dart @@ -10,6 +10,7 @@ import 'package:json_annotation/json_annotation.dart'; import 'package:source_gen/source_gen.dart'; import 'package:source_helper/source_helper.dart'; +import '../default_container.dart'; import '../type_helper.dart'; import '../utils.dart'; import 'config_types.dart'; @@ -64,7 +65,7 @@ class JsonHelper extends TypeHelper { } @override - String? deserialize( + Object? deserialize( DartType targetType, String expression, TypeHelperContextWithConfig context, @@ -130,8 +131,7 @@ class JsonHelper extends TypeHelper { // https://github.com/google/json_serializable.dart/issues/19 output = '${targetType.element.name}.fromJson($output)'; - return commonNullPrefix(targetType.isNullableType, expression, output) - .toString(); + return DefaultContainer(targetType.isNullableType, expression, output); } } diff --git a/json_serializable/test/default_value/default_value.dart b/json_serializable/test/default_value/default_value.dart index 27eda4ea6..fd954656b 100644 --- a/json_serializable/test/default_value/default_value.dart +++ b/json_serializable/test/default_value/default_value.dart @@ -8,6 +8,7 @@ import 'package:json_annotation/json_annotation.dart'; import 'default_value_interface.dart' as dvi hide Greek; import 'default_value_interface.dart' show Greek; +import 'implicit_default_value.dart'; part 'default_value.g.dart'; @@ -56,6 +57,8 @@ class DefaultValue implements dvi.DefaultValue { @JsonKey(defaultValue: Greek.beta) Greek fieldEnum; + ConstClass constClass; + DefaultValue( this.fieldBool, this.fieldString, @@ -68,8 +71,9 @@ class DefaultValue implements dvi.DefaultValue { this.fieldSetSimple, this.fieldMapSimple, this.fieldMapListString, - this.fieldEnum, - ); + this.fieldEnum, { + this.constClass = const ConstClass('value'), + }); factory DefaultValue.fromJson(Map json) => _$DefaultValueFromJson(json); diff --git a/json_serializable/test/default_value/default_value.g.dart b/json_serializable/test/default_value/default_value.g.dart index b4c9631db..afff6bcc7 100644 --- a/json_serializable/test/default_value/default_value.g.dart +++ b/json_serializable/test/default_value/default_value.g.dart @@ -34,6 +34,9 @@ DefaultValue _$DefaultValueFromJson(Map json) => DefaultValue( 'root': ['child'] }, _$enumDecodeNullable(_$GreekEnumMap, json['fieldEnum']) ?? Greek.beta, + constClass: json['constClass'] == null + ? const ConstClass('value') + : ConstClass.fromJson(json['constClass'] as Map), ); Map _$DefaultValueToJson(DefaultValue instance) => @@ -50,6 +53,7 @@ Map _$DefaultValueToJson(DefaultValue instance) => 'fieldMapSimple': instance.fieldMapSimple, 'fieldMapListString': instance.fieldMapListString, 'fieldEnum': _$GreekEnumMap[instance.fieldEnum], + 'constClass': instance.constClass, }; K _$enumDecode( diff --git a/json_serializable/test/default_value/default_value.g_any_map__checked.dart b/json_serializable/test/default_value/default_value.g_any_map__checked.dart index 9c345aef1..7e2fed007 100644 --- a/json_serializable/test/default_value/default_value.g_any_map__checked.dart +++ b/json_serializable/test/default_value/default_value.g_any_map__checked.dart @@ -8,6 +8,7 @@ import 'package:json_annotation/json_annotation.dart'; import 'default_value_interface.dart' as dvi hide Greek; import 'default_value_interface.dart' show Greek; +import 'implicit_default_value.dart'; part 'default_value.g_any_map__checked.g.dart'; @@ -59,6 +60,8 @@ class DefaultValue implements dvi.DefaultValue { @JsonKey(defaultValue: Greek.beta) Greek fieldEnum; + ConstClass constClass; + DefaultValue( this.fieldBool, this.fieldString, @@ -71,8 +74,9 @@ class DefaultValue implements dvi.DefaultValue { this.fieldSetSimple, this.fieldMapSimple, this.fieldMapListString, - this.fieldEnum, - ); + this.fieldEnum, { + this.constClass = const ConstClass('value'), + }); factory DefaultValue.fromJson(Map json) => _$DefaultValueFromJson(json); diff --git a/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart b/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart index 8a1bdde7f..eb1096c58 100644 --- a/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart +++ b/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart @@ -11,47 +11,49 @@ DefaultValue _$DefaultValueFromJson(Map json) => $checkedCreate( json, ($checkedConvert) { final val = DefaultValue( - $checkedConvert('fieldBool', (v) => v as bool?) ?? true, - $checkedConvert('fieldString', (v) => v as String?) ?? 'string', - $checkedConvert('fieldInt', (v) => v as int?) ?? 42, - $checkedConvert('fieldDouble', (v) => (v as num?)?.toDouble()) ?? - 3.14, - $checkedConvert('fieldListEmpty', (v) => v as List?) ?? [], + $checkedConvert('fieldBool', (v) => v as bool? ?? true), + $checkedConvert('fieldString', (v) => v as String? ?? 'string'), + $checkedConvert('fieldInt', (v) => v as int? ?? 42), $checkedConvert( - 'fieldSetEmpty', (v) => (v as List?)?.toSet()) ?? - {}, - $checkedConvert('fieldMapEmpty', (v) => v as Map?) ?? {}, + 'fieldDouble', (v) => (v as num?)?.toDouble() ?? 3.14), + $checkedConvert('fieldListEmpty', (v) => v as List? ?? []), $checkedConvert( - 'fieldListSimple', - (v) => - (v as List?)?.map((e) => e as int).toList()) ?? - [1, 2, 3], + 'fieldSetEmpty', (v) => (v as List?)?.toSet() ?? {}), + $checkedConvert('fieldMapEmpty', (v) => v as Map? ?? {}), $checkedConvert( - 'fieldSetSimple', - (v) => - (v as List?)?.map((e) => e as String).toSet()) ?? - {'entry1', 'entry2'}, + 'fieldListSimple', + (v) => + (v as List?)?.map((e) => e as int).toList() ?? + [1, 2, 3]), $checkedConvert( - 'fieldMapSimple', - (v) => (v as Map?)?.map( - (k, e) => MapEntry(k as String, e as int), - )) ?? - {'answer': 42}, + 'fieldSetSimple', + (v) => + (v as List?)?.map((e) => e as String).toSet() ?? + {'entry1', 'entry2'}), $checkedConvert( - 'fieldMapListString', - (v) => (v as Map?)?.map( - (k, e) => MapEntry( - k as String, - (e as List) - .map((e) => e as String) - .toList()), - )) ?? - { - 'root': ['child'] - }, + 'fieldMapSimple', + (v) => + (v as Map?)?.map( + (k, e) => MapEntry(k as String, e as int), + ) ?? + {'answer': 42}), + $checkedConvert( + 'fieldMapListString', + (v) => + (v as Map?)?.map( + (k, e) => MapEntry(k as String, + (e as List).map((e) => e as String).toList()), + ) ?? + { + 'root': ['child'] + }), $checkedConvert('fieldEnum', - (v) => _$enumDecodeNullable(_$GreekEnumMap, v)) ?? - Greek.beta, + (v) => _$enumDecodeNullable(_$GreekEnumMap, v) ?? Greek.beta), + constClass: $checkedConvert( + 'constClass', + (v) => v == null + ? const ConstClass('value') + : ConstClass.fromJson(Map.from(v as Map))), ); return val; }, @@ -71,6 +73,7 @@ Map _$DefaultValueToJson(DefaultValue instance) => 'fieldMapSimple': instance.fieldMapSimple, 'fieldMapListString': instance.fieldMapListString, 'fieldEnum': _$GreekEnumMap[instance.fieldEnum], + 'constClass': instance.constClass, }; K _$enumDecode( diff --git a/json_serializable/test/default_value/default_value_interface.dart b/json_serializable/test/default_value/default_value_interface.dart index 6cf4704b6..a9a743a58 100644 --- a/json_serializable/test/default_value/default_value_interface.dart +++ b/json_serializable/test/default_value/default_value_interface.dart @@ -2,6 +2,8 @@ // 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 'implicit_default_value.dart'; + abstract class DefaultValue { bool get fieldBool; @@ -26,6 +28,8 @@ abstract class DefaultValue { Map> get fieldMapListString; Greek get fieldEnum; + + ConstClass get constClass; } enum Greek { alpha, beta, gamma, delta } diff --git a/json_serializable/test/default_value/default_value_test.dart b/json_serializable/test/default_value/default_value_test.dart index 740c03a6f..bfac560ff 100644 --- a/json_serializable/test/default_value/default_value_test.dart +++ b/json_serializable/test/default_value/default_value_test.dart @@ -24,7 +24,8 @@ const _defaultInstance = { 'fieldMapListString': { 'root': ['child'] }, - 'fieldEnum': 'beta' + 'fieldEnum': 'beta', + 'constClass': {'field': 'value'} }; const _otherValues = { @@ -41,7 +42,8 @@ const _otherValues = { 'fieldMapListString': { 'root2': ['alpha'] }, - 'fieldEnum': 'delta' + 'fieldEnum': 'delta', + 'constClass': {'field': 'otherValue'} }; void main() { diff --git a/json_serializable/test/default_value/implicit_default_value.dart b/json_serializable/test/default_value/implicit_default_value.dart index e61296bea..8d4cac423 100644 --- a/json_serializable/test/default_value/implicit_default_value.dart +++ b/json_serializable/test/default_value/implicit_default_value.dart @@ -34,6 +34,8 @@ class DefaultValueImplicit implements dvi.DefaultValue { final Map> fieldMapListString; @override final Greek fieldEnum; + @override + final ConstClass constClass; DefaultValueImplicit({ this.fieldBool = true, @@ -50,6 +52,7 @@ class DefaultValueImplicit implements dvi.DefaultValue { 'root': ['child'] }, this.fieldEnum = Greek.beta, + this.constClass = const ConstClass('value'), }); factory DefaultValueImplicit.fromJson(Map json) => @@ -57,3 +60,16 @@ class DefaultValueImplicit implements dvi.DefaultValue { Map toJson() => _$DefaultValueImplicitToJson(this); } + +// Regression for https://github.com/google/json_serializable.dart/issues/903 +@JsonSerializable() +class ConstClass { + final String field; + + const ConstClass(this.field); + + factory ConstClass.fromJson(Map json) => + _$ConstClassFromJson(json); + + Map toJson() => _$ConstClassToJson(this); +} diff --git a/json_serializable/test/default_value/implicit_default_value.g.dart b/json_serializable/test/default_value/implicit_default_value.g.dart index 71b4449d1..392c419e6 100644 --- a/json_serializable/test/default_value/implicit_default_value.g.dart +++ b/json_serializable/test/default_value/implicit_default_value.g.dart @@ -39,6 +39,9 @@ DefaultValueImplicit _$DefaultValueImplicitFromJson( }, fieldEnum: _$enumDecodeNullable(_$GreekEnumMap, json['fieldEnum']) ?? Greek.beta, + constClass: json['constClass'] == null + ? const ConstClass('value') + : ConstClass.fromJson(json['constClass'] as Map), ); Map _$DefaultValueImplicitToJson( @@ -56,6 +59,7 @@ Map _$DefaultValueImplicitToJson( 'fieldMapSimple': instance.fieldMapSimple, 'fieldMapListString': instance.fieldMapListString, 'fieldEnum': _$GreekEnumMap[instance.fieldEnum], + 'constClass': instance.constClass, }; K _$enumDecode( @@ -101,3 +105,12 @@ const _$GreekEnumMap = { Greek.gamma: 'gamma', Greek.delta: 'delta', }; + +ConstClass _$ConstClassFromJson(Map json) => ConstClass( + json['field'] as String, + ); + +Map _$ConstClassToJson(ConstClass instance) => + { + 'field': instance.field, + }; From 28f782962a0d769721c8db9549970a183cfe487a Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 10 Jun 2021 17:49:05 -0700 Subject: [PATCH 312/569] Correctly handle converters and default values (#916) * Doc comments * test: refactor default_value test interface code * Correctly handle converters and default values A consistent model for handling converter-like things and default values * cleanup * use lambda more * cleanup --- json_serializable/CHANGELOG.md | 4 +- json_serializable/lib/src/decode_helper.dart | 16 ++----- .../lib/src/default_container.dart | 40 +++++++++------- json_serializable/lib/src/json_key_utils.dart | 4 +- json_serializable/lib/src/lambda_result.dart | 19 ++++++-- json_serializable/lib/src/type_helper.dart | 3 +- .../lib/src/type_helper_ctx.dart | 9 +--- .../lib/src/type_helpers/config_types.dart | 2 +- .../lib/src/type_helpers/convert_helper.dart | 20 +++----- .../lib/src/type_helpers/iterable_helper.dart | 4 +- .../type_helpers/json_converter_helper.dart | 5 +- .../lib/src/type_helpers/json_helper.dart | 3 +- json_serializable/lib/src/utils.dart | 3 ++ .../test/default_value/default_value.dart | 17 ++++++- .../test/default_value/default_value.g.dart | 10 ++++ .../default_value.g_any_map__checked.dart | 17 ++++++- .../default_value.g_any_map__checked.g.dart | 13 +++++ .../default_value_interface.dart | 35 +++++++++++++- .../default_value/default_value_test.dart | 8 +++- .../default_value/implicit_default_value.dart | 48 +++++++++---------- .../implicit_default_value.g.dart | 19 ++++---- .../test/src/default_value_input.dart | 12 ++--- .../test/src/to_from_json_test_input.dart | 19 ++++---- 23 files changed, 207 insertions(+), 123 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 80106e437..9134863eb 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -8,8 +8,8 @@ - Use the new `$checkedCreate` helper exposed in `package:json_annotation` v4.1+. - Generated code now conforms to this `prefer_expression_function_bodies` lint. -- Support default values in constructors for types with a `fromJson` - constructor. +- Support default values and types with a `fromJson` constructor. +- Support default values with class- and function-based converters. - `type_helper.dart`: - **BREAKING**: removed `typeArgumentsOf`. This is now an extension exposed by `package:source_helper`. diff --git a/json_serializable/lib/src/decode_helper.dart b/json_serializable/lib/src/decode_helper.dart index bbce1c78d..955c224aa 100644 --- a/json_serializable/lib/src/decode_helper.dart +++ b/json_serializable/lib/src/decode_helper.dart @@ -199,7 +199,11 @@ abstract class DecodeHelper implements HelperCore { defaultProvided: defaultProvided, )!; - return DefaultContainer.encode(value, defaultValue: defaultValue); + return DefaultContainer.encode( + value, + nullable: targetType.isNullableType, + defaultValue: defaultValue, + ); } String value; @@ -227,16 +231,6 @@ abstract class DecodeHelper implements HelperCore { 'effect because both `disallowNullValue` and `required` are set to ' '`true`.'); } - - final deserializeConvertData = contextHelper.deserializeConvertData; - - if (deserializeConvertData != null && - !deserializeConvertData.nullableToAllowDefault) { - log.warning('The field `${field.name}` has both `defaultValue` and ' - '`fromJson` defined which likely won\'t work for your scenario.\n' - 'Instead of using `defaultValue`, set `nullable: false` and handle ' - '`null` in the `fromJson` function.'); - } } return value; } diff --git a/json_serializable/lib/src/default_container.dart b/json_serializable/lib/src/default_container.dart index 621dfd9f1..23f90cab9 100644 --- a/json_serializable/lib/src/default_container.dart +++ b/json_serializable/lib/src/default_container.dart @@ -2,32 +2,38 @@ // 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 'lambda_result.dart'; +import 'utils.dart'; + /// Represents an expression that may be represented differently if there is /// a default value available to replace it if `null`. class DefaultContainer { - final bool nullable; final String expression; final String output; - DefaultContainer(this.nullable, this.expression, this.output); - - String _result([Object? defaultValue]) { - if (defaultValue != null || nullable) { - return '$expression == null ? $defaultValue : $output'; + DefaultContainer(this.expression, this.output); + + static String encode( + Object value, { + bool nullable = false, + String? defaultValue, + }) { + if (value is DefaultContainer) { + if (defaultValue != null || nullable) { + return ifNullOrElse( + value.expression, + defaultValue ?? 'null', + value.output, + ); + } + value = value.output; } - if (defaultValue == null) { - return output; - } - return '$output ?? $defaultValue'; - } - - static String encode(Object input, {Object? defaultValue}) { - if (input is DefaultContainer) { - return input._result(defaultValue); + if (value is LambdaResult && defaultValue != null) { + return ifNullOrElse(value.expression, defaultValue, value.toString()); } - var result = input.toString(); + var result = value.toString(); if (defaultValue != null) { result = '$result ?? $defaultValue'; @@ -36,5 +42,5 @@ class DefaultContainer { } @override - String toString() => _result(); + String toString() => encode(this); } diff --git a/json_serializable/lib/src/json_key_utils.dart b/json_serializable/lib/src/json_key_utils.dart index b0bce2eda..3ad264b2e 100644 --- a/json_serializable/lib/src/json_key_utils.dart +++ b/json_serializable/lib/src/json_key_utils.dart @@ -120,7 +120,7 @@ KeyConfig _from(FieldElement element, ClassConfig classAnnotation) { /// If [mustBeEnum] is `true`, throws an [InvalidGenerationSourceError] if /// either the annotated field is not an `enum` or `List` or if the value in /// [fieldName] is not an `enum` value. - Object? _annotationValue(String fieldName, {bool mustBeEnum = false}) { + String? _annotationValue(String fieldName, {bool mustBeEnum = false}) { final annotationValue = obj.read(fieldName); final enumFields = annotationValue.isNull @@ -202,7 +202,7 @@ KeyConfig _from(FieldElement element, ClassConfig classAnnotation) { KeyConfig _populateJsonKey( ClassConfig classAnnotation, FieldElement element, { - required Object? defaultValue, + required String? defaultValue, bool? disallowNullValue, bool? ignore, bool? includeIfNull, diff --git a/json_serializable/lib/src/lambda_result.dart b/json_serializable/lib/src/lambda_result.dart index b87f433de..05f07d7f3 100644 --- a/json_serializable/lib/src/lambda_result.dart +++ b/json_serializable/lib/src/lambda_result.dart @@ -2,17 +2,28 @@ // 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 'constants.dart' show closureArg; + +/// Represents a lambda that can be used as a tear-off depending on the context +/// in which it is used. +/// +/// Allows generated code to support the +/// https://dart-lang.github.io/linter/lints/unnecessary_lambdas.html +/// lint. class LambdaResult { final String expression; final String lambda; + final String? asContent; + + String get _fullExpression => '$expression${asContent ?? ''}'; - LambdaResult(this.expression, this.lambda); + LambdaResult(this.expression, this.lambda, {this.asContent}); @override - String toString() => '$lambda($expression)'; + String toString() => '$lambda($_fullExpression)'; - static String process(Object subField, String closureArg) => - (subField is LambdaResult && closureArg == subField.expression) + static String process(Object subField) => + (subField is LambdaResult && closureArg == subField._fullExpression) ? subField.lambda : '($closureArg) => $subField'; } diff --git a/json_serializable/lib/src/type_helper.dart b/json_serializable/lib/src/type_helper.dart index af6e703c1..b01249334 100644 --- a/json_serializable/lib/src/type_helper.dart +++ b/json_serializable/lib/src/type_helper.dart @@ -6,6 +6,7 @@ import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/type.dart'; import 'type_helpers/config_types.dart'; +import 'utils.dart'; /// Context information provided in calls to [TypeHelper.serialize] and /// [TypeHelper.deserialize]. @@ -91,5 +92,5 @@ Object commonNullPrefix( Object unsafeExpression, ) => nullable - ? '$expression == null ? null : $unsafeExpression' + ? ifNullOrElse(expression, 'null', '$unsafeExpression') : unsafeExpression; diff --git a/json_serializable/lib/src/type_helper_ctx.dart b/json_serializable/lib/src/type_helper_ctx.dart index 4ba3dcd38..be324c4d0 100644 --- a/json_serializable/lib/src/type_helper_ctx.dart +++ b/json_serializable/lib/src/type_helper_ctx.dart @@ -125,8 +125,6 @@ ConvertData? _convertData(DartObject obj, FieldElement element, bool isFrom) { 'positional parameter.'); } - var nullableToAllowDefault = false; - final argType = executableElement.parameters.first.type; if (isFrom) { final hasDefaultValue = @@ -152,7 +150,6 @@ ConvertData? _convertData(DartObject obj, FieldElement element, bool isFrom) { '`$elementTypeCode`.'); } } - nullableToAllowDefault = hasDefaultValue && returnType.isNullableType; } else { if (argType is TypeParameterType) { // We keep things simple in this case. We rely on inferred type arguments @@ -175,9 +172,5 @@ ConvertData? _convertData(DartObject obj, FieldElement element, bool isFrom) { name = '${executableElement.enclosingElement.name}.$name'; } - return ConvertData( - name, - argType, - nullableToAllowDefault: nullableToAllowDefault, - ); + return ConvertData(name, argType); } diff --git a/json_serializable/lib/src/type_helpers/config_types.dart b/json_serializable/lib/src/type_helpers/config_types.dart index 993645e4a..7b3c26637 100644 --- a/json_serializable/lib/src/type_helpers/config_types.dart +++ b/json_serializable/lib/src/type_helpers/config_types.dart @@ -6,7 +6,7 @@ import 'package:json_annotation/json_annotation.dart'; /// Represents values from [JsonKey] when merged with local configuration. class KeyConfig { - final Object? defaultValue; + final String? defaultValue; final bool disallowNullValue; diff --git a/json_serializable/lib/src/type_helpers/convert_helper.dart b/json_serializable/lib/src/type_helpers/convert_helper.dart index f2ce98e02..051f2cb9b 100644 --- a/json_serializable/lib/src/type_helpers/convert_helper.dart +++ b/json_serializable/lib/src/type_helpers/convert_helper.dart @@ -5,6 +5,7 @@ import 'package:analyzer/dart/element/type.dart'; import 'package:source_helper/source_helper.dart'; +import '../lambda_result.dart'; import '../shared_checkers.dart'; import '../type_helper.dart'; @@ -14,15 +15,7 @@ class ConvertData { final String name; final DartType paramType; - /// `true` if the function returns a nullable value AND there is a default - /// value assigned. - final bool nullableToAllowDefault; - - ConvertData( - this.name, - this.paramType, { - required this.nullableToAllowDefault, - }); + ConvertData(this.name, this.paramType); } abstract class TypeHelperContextWithConvert extends TypeHelperContext { @@ -31,11 +24,12 @@ abstract class TypeHelperContextWithConvert extends TypeHelperContext { ConvertData? get deserializeConvertData; } +/// Handles `JsonKey`-annotated fields with `toJson` or `fromJson` values set. class ConvertHelper extends TypeHelper { const ConvertHelper(); @override - String? serialize( + Object? serialize( DartType targetType, String expression, TypeHelperContextWithConvert context, @@ -47,11 +41,11 @@ class ConvertHelper extends TypeHelper { assert(toJsonData.paramType is TypeParameterType || targetType.isAssignableTo(toJsonData.paramType)); - return '${toJsonData.name}($expression)'; + return LambdaResult(expression, toJsonData.name); } @override - String? deserialize( + Object? deserialize( DartType targetType, String expression, TypeHelperContextWithConvert context, @@ -63,6 +57,6 @@ class ConvertHelper extends TypeHelper { } final asContent = asStatement(fromJsonData.paramType); - return '${fromJsonData.name}($expression$asContent)'; + return LambdaResult(expression, fromJsonData.name, asContent: asContent); } } diff --git a/json_serializable/lib/src/type_helpers/iterable_helper.dart b/json_serializable/lib/src/type_helpers/iterable_helper.dart index 88be86781..3ac2355a1 100644 --- a/json_serializable/lib/src/type_helpers/iterable_helper.dart +++ b/json_serializable/lib/src/type_helpers/iterable_helper.dart @@ -38,7 +38,7 @@ class IterableHelper extends TypeHelper { // will be identical to `substitute` – so no explicit mapping is needed. // If they are not equal, then we to write out the substitution. if (subField != closureArg) { - final lambda = LambdaResult.process(subField, closureArg); + final lambda = LambdaResult.process(subField); expression = '$expression$optionalQuestion.map($lambda)'; @@ -95,7 +95,7 @@ class IterableHelper extends TypeHelper { var optionalQuestion = targetTypeIsNullable ? '?' : ''; if (closureArg != itemSubVal) { - final lambda = LambdaResult.process(itemSubVal, closureArg); + final lambda = LambdaResult.process(itemSubVal); output += '$optionalQuestion.map($lambda)'; // No need to include the optional question below – it was used here! optionalQuestion = ''; diff --git a/json_serializable/lib/src/type_helpers/json_converter_helper.dart b/json_serializable/lib/src/type_helpers/json_converter_helper.dart index 0743dc140..d6969049d 100644 --- a/json_serializable/lib/src/type_helpers/json_converter_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_converter_helper.dart @@ -50,7 +50,10 @@ class JsonConverterHelper extends TypeHelper { final asContent = asStatement(converter.jsonType); return LambdaResult( - '$expression$asContent', '${converter.accessString}.fromJson'); + expression, + '${converter.accessString}.fromJson', + asContent: asContent, + ); } } diff --git a/json_serializable/lib/src/type_helpers/json_helper.dart b/json_serializable/lib/src/type_helpers/json_helper.dart index 703c88abc..521985fa5 100644 --- a/json_serializable/lib/src/type_helpers/json_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_helper.dart @@ -18,6 +18,7 @@ import 'generic_factory_helper.dart'; const _helperLambdaParam = 'value'; +/// Supports types that have `fromJson` constructors and/or `toJson` functions. class JsonHelper extends TypeHelper { const JsonHelper(); @@ -131,7 +132,7 @@ class JsonHelper extends TypeHelper { // https://github.com/google/json_serializable.dart/issues/19 output = '${targetType.element.name}.fromJson($output)'; - return DefaultContainer(targetType.isNullableType, expression, output); + return DefaultContainer(expression, output); } } diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index d8d74fcdb..0b374eedb 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -207,3 +207,6 @@ extension DartTypeExtension on DartType { DartType promoteNonNullable() => element?.library?.typeSystem.promoteToNonNull(this) ?? this; } + +String ifNullOrElse(String test, String ifNull, String ifNotNull) => + '$test == null ? $ifNull : $ifNotNull'; diff --git a/json_serializable/test/default_value/default_value.dart b/json_serializable/test/default_value/default_value.dart index fd954656b..a62894d2c 100644 --- a/json_serializable/test/default_value/default_value.dart +++ b/json_serializable/test/default_value/default_value.dart @@ -7,8 +7,13 @@ import 'package:json_annotation/json_annotation.dart'; import 'default_value_interface.dart' as dvi hide Greek; -import 'default_value_interface.dart' show Greek; -import 'implicit_default_value.dart'; +import 'default_value_interface.dart' + show + Greek, + ConstClass, + ConstClassConverter, + constClassFromJson, + constClassToJson; part 'default_value.g.dart'; @@ -59,6 +64,12 @@ class DefaultValue implements dvi.DefaultValue { ConstClass constClass; + @ConstClassConverter() + ConstClass valueFromConverter; + + @JsonKey(fromJson: constClassFromJson, toJson: constClassToJson) + ConstClass valueFromFunction; + DefaultValue( this.fieldBool, this.fieldString, @@ -73,6 +84,8 @@ class DefaultValue implements dvi.DefaultValue { this.fieldMapListString, this.fieldEnum, { this.constClass = const ConstClass('value'), + this.valueFromConverter = const ConstClass('value'), + this.valueFromFunction = const ConstClass('value'), }); factory DefaultValue.fromJson(Map json) => diff --git a/json_serializable/test/default_value/default_value.g.dart b/json_serializable/test/default_value/default_value.g.dart index afff6bcc7..bd5997a00 100644 --- a/json_serializable/test/default_value/default_value.g.dart +++ b/json_serializable/test/default_value/default_value.g.dart @@ -37,6 +37,13 @@ DefaultValue _$DefaultValueFromJson(Map json) => DefaultValue( constClass: json['constClass'] == null ? const ConstClass('value') : ConstClass.fromJson(json['constClass'] as Map), + valueFromConverter: json['valueFromConverter'] == null + ? const ConstClass('value') + : const ConstClassConverter() + .fromJson(json['valueFromConverter'] as String), + valueFromFunction: json['valueFromFunction'] == null + ? const ConstClass('value') + : constClassFromJson(json['valueFromFunction'] as String), ); Map _$DefaultValueToJson(DefaultValue instance) => @@ -54,6 +61,9 @@ Map _$DefaultValueToJson(DefaultValue instance) => 'fieldMapListString': instance.fieldMapListString, 'fieldEnum': _$GreekEnumMap[instance.fieldEnum], 'constClass': instance.constClass, + 'valueFromConverter': + const ConstClassConverter().toJson(instance.valueFromConverter), + 'valueFromFunction': constClassToJson(instance.valueFromFunction), }; K _$enumDecode( diff --git a/json_serializable/test/default_value/default_value.g_any_map__checked.dart b/json_serializable/test/default_value/default_value.g_any_map__checked.dart index 7e2fed007..39eeb129a 100644 --- a/json_serializable/test/default_value/default_value.g_any_map__checked.dart +++ b/json_serializable/test/default_value/default_value.g_any_map__checked.dart @@ -7,8 +7,13 @@ import 'package:json_annotation/json_annotation.dart'; import 'default_value_interface.dart' as dvi hide Greek; -import 'default_value_interface.dart' show Greek; -import 'implicit_default_value.dart'; +import 'default_value_interface.dart' + show + Greek, + ConstClass, + ConstClassConverter, + constClassFromJson, + constClassToJson; part 'default_value.g_any_map__checked.g.dart'; @@ -62,6 +67,12 @@ class DefaultValue implements dvi.DefaultValue { ConstClass constClass; + @ConstClassConverter() + ConstClass valueFromConverter; + + @JsonKey(fromJson: constClassFromJson, toJson: constClassToJson) + ConstClass valueFromFunction; + DefaultValue( this.fieldBool, this.fieldString, @@ -76,6 +87,8 @@ class DefaultValue implements dvi.DefaultValue { this.fieldMapListString, this.fieldEnum, { this.constClass = const ConstClass('value'), + this.valueFromConverter = const ConstClass('value'), + this.valueFromFunction = const ConstClass('value'), }); factory DefaultValue.fromJson(Map json) => diff --git a/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart b/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart index eb1096c58..9030a7354 100644 --- a/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart +++ b/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart @@ -54,6 +54,16 @@ DefaultValue _$DefaultValueFromJson(Map json) => $checkedCreate( (v) => v == null ? const ConstClass('value') : ConstClass.fromJson(Map.from(v as Map))), + valueFromConverter: $checkedConvert( + 'valueFromConverter', + (v) => v == null + ? const ConstClass('value') + : const ConstClassConverter().fromJson(v as String)), + valueFromFunction: $checkedConvert( + 'valueFromFunction', + (v) => v == null + ? const ConstClass('value') + : constClassFromJson(v as String)), ); return val; }, @@ -74,6 +84,9 @@ Map _$DefaultValueToJson(DefaultValue instance) => 'fieldMapListString': instance.fieldMapListString, 'fieldEnum': _$GreekEnumMap[instance.fieldEnum], 'constClass': instance.constClass, + 'valueFromConverter': + const ConstClassConverter().toJson(instance.valueFromConverter), + 'valueFromFunction': constClassToJson(instance.valueFromFunction), }; K _$enumDecode( diff --git a/json_serializable/test/default_value/default_value_interface.dart b/json_serializable/test/default_value/default_value_interface.dart index a9a743a58..9becc6e6f 100644 --- a/json_serializable/test/default_value/default_value_interface.dart +++ b/json_serializable/test/default_value/default_value_interface.dart @@ -2,7 +2,7 @@ // 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 'implicit_default_value.dart'; +import 'package:json_annotation/json_annotation.dart'; abstract class DefaultValue { bool get fieldBool; @@ -30,6 +30,39 @@ abstract class DefaultValue { Greek get fieldEnum; ConstClass get constClass; + + ConstClass get valueFromConverter; + + ConstClass get valueFromFunction; } enum Greek { alpha, beta, gamma, delta } + +// Regression for https://github.com/google/json_serializable.dart/issues/903 +class ConstClass { + final String field; + + const ConstClass(this.field); + + factory ConstClass.fromJson(Map json) => ConstClass( + json['field'] as String, + ); + + Map toJson() => { + 'field': field, + }; +} + +ConstClass constClassFromJson(String json) => ConstClass(json); + +String constClassToJson(ConstClass object) => object.field; + +class ConstClassConverter extends JsonConverter { + const ConstClassConverter(); + + @override + ConstClass fromJson(String json) => ConstClass(json); + + @override + String toJson(ConstClass object) => object.field; +} diff --git a/json_serializable/test/default_value/default_value_test.dart b/json_serializable/test/default_value/default_value_test.dart index bfac560ff..baee4b811 100644 --- a/json_serializable/test/default_value/default_value_test.dart +++ b/json_serializable/test/default_value/default_value_test.dart @@ -25,7 +25,9 @@ const _defaultInstance = { 'root': ['child'] }, 'fieldEnum': 'beta', - 'constClass': {'field': 'value'} + 'constClass': {'field': 'value'}, + 'valueFromConverter': 'value', + 'valueFromFunction': 'value', }; const _otherValues = { @@ -43,7 +45,9 @@ const _otherValues = { 'root2': ['alpha'] }, 'fieldEnum': 'delta', - 'constClass': {'field': 'otherValue'} + 'constClass': {'field': 'otherValue'}, + 'valueFromConverter': 'otherValue', + 'valueFromFunction': 'otherValue', }; void main() { diff --git a/json_serializable/test/default_value/implicit_default_value.dart b/json_serializable/test/default_value/implicit_default_value.dart index 8d4cac423..ad6c6c52b 100644 --- a/json_serializable/test/default_value/implicit_default_value.dart +++ b/json_serializable/test/default_value/implicit_default_value.dart @@ -1,3 +1,5 @@ +// ignore_for_file: annotate_overrides + import 'package:json_annotation/json_annotation.dart'; import 'default_value_interface.dart'; @@ -10,33 +12,38 @@ dvi.DefaultValue fromJson(Map json) => @JsonSerializable() class DefaultValueImplicit implements dvi.DefaultValue { - @override final bool fieldBool; - @override + final String fieldString; - @override + final int fieldInt; - @override + final double fieldDouble; - @override + final List fieldListEmpty; - @override + final Set fieldSetEmpty; - @override + final Map fieldMapEmpty; - @override + final List fieldListSimple; - @override + final Set fieldSetSimple; - @override + final Map fieldMapSimple; - @override + final Map> fieldMapListString; - @override + final Greek fieldEnum; - @override + final ConstClass constClass; + @ConstClassConverter() + ConstClass valueFromConverter; + + @JsonKey(fromJson: constClassFromJson, toJson: constClassToJson) + ConstClass valueFromFunction; + DefaultValueImplicit({ this.fieldBool = true, this.fieldString = 'string', @@ -53,6 +60,8 @@ class DefaultValueImplicit implements dvi.DefaultValue { }, this.fieldEnum = Greek.beta, this.constClass = const ConstClass('value'), + this.valueFromConverter = const ConstClass('value'), + this.valueFromFunction = const ConstClass('value'), }); factory DefaultValueImplicit.fromJson(Map json) => @@ -60,16 +69,3 @@ class DefaultValueImplicit implements dvi.DefaultValue { Map toJson() => _$DefaultValueImplicitToJson(this); } - -// Regression for https://github.com/google/json_serializable.dart/issues/903 -@JsonSerializable() -class ConstClass { - final String field; - - const ConstClass(this.field); - - factory ConstClass.fromJson(Map json) => - _$ConstClassFromJson(json); - - Map toJson() => _$ConstClassToJson(this); -} diff --git a/json_serializable/test/default_value/implicit_default_value.g.dart b/json_serializable/test/default_value/implicit_default_value.g.dart index 392c419e6..75a26d064 100644 --- a/json_serializable/test/default_value/implicit_default_value.g.dart +++ b/json_serializable/test/default_value/implicit_default_value.g.dart @@ -42,6 +42,13 @@ DefaultValueImplicit _$DefaultValueImplicitFromJson( constClass: json['constClass'] == null ? const ConstClass('value') : ConstClass.fromJson(json['constClass'] as Map), + valueFromConverter: json['valueFromConverter'] == null + ? const ConstClass('value') + : const ConstClassConverter() + .fromJson(json['valueFromConverter'] as String), + valueFromFunction: json['valueFromFunction'] == null + ? const ConstClass('value') + : constClassFromJson(json['valueFromFunction'] as String), ); Map _$DefaultValueImplicitToJson( @@ -60,6 +67,9 @@ Map _$DefaultValueImplicitToJson( 'fieldMapListString': instance.fieldMapListString, 'fieldEnum': _$GreekEnumMap[instance.fieldEnum], 'constClass': instance.constClass, + 'valueFromConverter': + const ConstClassConverter().toJson(instance.valueFromConverter), + 'valueFromFunction': constClassToJson(instance.valueFromFunction), }; K _$enumDecode( @@ -105,12 +115,3 @@ const _$GreekEnumMap = { Greek.gamma: 'gamma', Greek.delta: 'delta', }; - -ConstClass _$ConstClassFromJson(Map json) => ConstClass( - json['field'] as String, - ); - -Map _$ConstClassToJson(ConstClass instance) => - { - 'field': instance.field, - }; diff --git a/json_serializable/test/src/default_value_input.dart b/json_serializable/test/src/default_value_input.dart index 8e6a4e2df..cde52251a 100644 --- a/json_serializable/test/src/default_value_input.dart +++ b/json_serializable/test/src/default_value_input.dart @@ -78,15 +78,11 @@ class DefaultWithNestedEnum { DefaultWithToJsonClass _$DefaultWithToJsonClassFromJson( Map json) => DefaultWithToJsonClass() - ..fieldDefaultValueToJson = DefaultWithToJsonClass._fromJson( - json['fieldDefaultValueToJson'] as String) ?? - 7; + ..fieldDefaultValueToJson = json['fieldDefaultValueToJson'] == null + ? 7 + : DefaultWithToJsonClass._fromJson( + json['fieldDefaultValueToJson'] as String); ''', - expectedLogItems: [ - ''' -The field `fieldDefaultValueToJson` has both `defaultValue` and `fromJson` defined which likely won't work for your scenario. -Instead of using `defaultValue`, set `nullable: false` and handle `null` in the `fromJson` function.''' - ], ) @JsonSerializable(createToJson: false) class DefaultWithToJsonClass { diff --git a/json_serializable/test/src/to_from_json_test_input.dart b/json_serializable/test/src/to_from_json_test_input.dart index ee8ba7fff..1f6a6245f 100644 --- a/json_serializable/test/src/to_from_json_test_input.dart +++ b/json_serializable/test/src/to_from_json_test_input.dart @@ -90,8 +90,11 @@ Reproduce869NullableGenericTypeWithDefault _$Reproduce869NullableGenericTypeWithDefaultFromJson( Map json) => Reproduce869NullableGenericTypeWithDefault() - ..values = _fromList(json['values'] as List?) ?? [] - ..valuesNullable = _fromList(json['valuesNullable'] as List?) ?? []; + ..values = + json['values'] == null ? [] : _fromList(json['values'] as List?) + ..valuesNullable = json['valuesNullable'] == null + ? [] + : _fromList(json['valuesNullable'] as List?); Map _$Reproduce869NullableGenericTypeWithDefaultToJson( Reproduce869NullableGenericTypeWithDefault instance) => @@ -118,15 +121,11 @@ class Reproduce869NullableGenericTypeWithDefault { List? valuesNullable; } -List? _fromList(List? pairs) { - return pairs?.map((it) { - return it as int; - }).toList(growable: false); -} +List? _fromList(List? pairs) => + pairs?.map((it) => it as int).toList(growable: false); -List? _toList(List? pairs) { - return pairs?.map((it) => [it]).toList(growable: false); -} +List? _toList(List? pairs) => + pairs?.map((it) => [it]).toList(growable: false); @ShouldThrow( 'Error with `@JsonKey` on `field`. The `toJson` function ' From f803b7509295d790f5d6580e879265b5444d7ce3 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 10 Jun 2021 19:32:28 -0700 Subject: [PATCH 313/569] more arrow functions --- example/lib/json_converter_example.dart | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/example/lib/json_converter_example.dart b/example/lib/json_converter_example.dart index 47789bd92..d408223c3 100644 --- a/example/lib/json_converter_example.dart +++ b/example/lib/json_converter_example.dart @@ -75,13 +75,11 @@ class _Converter implements JsonConverter { return json as T; } + // This will only work if `object` is a native JSON type: + // num, String, bool, null, etc + // Or if it has a `toJson()` function`. @override - Object? toJson(T object) { - // This will only work if `object` is a native JSON type: - // num, String, bool, null, etc - // Or if it has a `toJson()` function`. - return object; - } + Object? toJson(T object) => object; } @JsonSerializable() From faf2138c5446285b3e70d7ccbdd9af83f8897b72 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 16 Jun 2021 16:23:46 -0700 Subject: [PATCH 314/569] update to the latest mono_repo (#919) --- .github/workflows/dart.yml | 120 ++++++++++++++++---------------- _test_yaml/mono_pkg.yaml | 4 +- checked_yaml/mono_pkg.yaml | 4 +- example/mono_pkg.yaml | 4 +- json_annotation/mono_pkg.yaml | 4 +- json_serializable/mono_pkg.yaml | 4 +- tool/ci.sh | 40 +++++------ 7 files changed, 89 insertions(+), 91 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 703ace866..9b2f7a62a 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -1,4 +1,4 @@ -# Created with package:mono_repo v4.1.0 +# Created with package:mono_repo v5.0.0 name: Dart CI on: push: @@ -33,7 +33,7 @@ jobs: - id: checkout uses: actions/checkout@v2.3.4 - name: mono_repo self validate - run: dart pub global activate mono_repo 4.1.0 + run: dart pub global activate mono_repo 5.0.0 - name: mono_repo self validate run: dart pub global run mono_repo generate --validate job_002: @@ -44,7 +44,7 @@ jobs: uses: actions/cache@v2.1.6 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:dartfmt-dartanalyzer" + key: "os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:format-analyze" restore-keys: | os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable os:ubuntu-latest;pub-cache-hosted;dart:2.12.0 @@ -56,10 +56,10 @@ jobs: - id: checkout uses: actions/checkout@v2.3.4 - id: _test_yaml_pub_upgrade - name: _test_yaml; pub upgrade + name: _test_yaml; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: _test_yaml - run: pub upgrade + run: dart pub upgrade - name: "_test_yaml; dart format --output=none --set-exit-if-changed ." if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" working-directory: _test_yaml @@ -69,10 +69,10 @@ jobs: working-directory: _test_yaml run: dart analyze --fatal-infos . - id: checked_yaml_pub_upgrade - name: checked_yaml; pub upgrade + name: checked_yaml; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: checked_yaml - run: pub upgrade + run: dart pub upgrade - name: "checked_yaml; dart format --output=none --set-exit-if-changed ." if: "always() && steps.checked_yaml_pub_upgrade.conclusion == 'success'" working-directory: checked_yaml @@ -82,10 +82,10 @@ jobs: working-directory: checked_yaml run: dart analyze --fatal-infos . - id: example_pub_upgrade - name: example; pub upgrade + name: example; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: example - run: pub upgrade + run: dart pub upgrade - name: "example; dart format --output=none --set-exit-if-changed ." if: "always() && steps.example_pub_upgrade.conclusion == 'success'" working-directory: example @@ -95,10 +95,10 @@ jobs: working-directory: example run: dart analyze --fatal-infos . - id: json_annotation_pub_upgrade - name: json_annotation; pub upgrade + name: json_annotation; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: json_annotation - run: pub upgrade + run: dart pub upgrade - name: "json_annotation; dart format --output=none --set-exit-if-changed ." if: "always() && steps.json_annotation_pub_upgrade.conclusion == 'success'" working-directory: json_annotation @@ -108,10 +108,10 @@ jobs: working-directory: json_annotation run: dart analyze --fatal-infos . - id: json_serializable_pub_upgrade - name: json_serializable; pub upgrade + name: json_serializable; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: json_serializable - run: pub upgrade + run: dart pub upgrade - name: "json_serializable; dart format --output=none --set-exit-if-changed ." if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" working-directory: json_serializable @@ -128,7 +128,7 @@ jobs: uses: actions/cache@v2.1.6 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:dartfmt-dartanalyzer" + key: "os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:format-analyze" restore-keys: | os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable os:ubuntu-latest;pub-cache-hosted;dart:dev @@ -140,10 +140,10 @@ jobs: - id: checkout uses: actions/checkout@v2.3.4 - id: _test_yaml_pub_upgrade - name: _test_yaml; pub upgrade + name: _test_yaml; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: _test_yaml - run: pub upgrade + run: dart pub upgrade - name: "_test_yaml; dart format --output=none --set-exit-if-changed ." if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" working-directory: _test_yaml @@ -153,10 +153,10 @@ jobs: working-directory: _test_yaml run: dart analyze --fatal-infos . - id: checked_yaml_pub_upgrade - name: checked_yaml; pub upgrade + name: checked_yaml; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: checked_yaml - run: pub upgrade + run: dart pub upgrade - name: "checked_yaml; dart format --output=none --set-exit-if-changed ." if: "always() && steps.checked_yaml_pub_upgrade.conclusion == 'success'" working-directory: checked_yaml @@ -166,10 +166,10 @@ jobs: working-directory: checked_yaml run: dart analyze --fatal-infos . - id: example_pub_upgrade - name: example; pub upgrade + name: example; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: example - run: pub upgrade + run: dart pub upgrade - name: "example; dart format --output=none --set-exit-if-changed ." if: "always() && steps.example_pub_upgrade.conclusion == 'success'" working-directory: example @@ -179,10 +179,10 @@ jobs: working-directory: example run: dart analyze --fatal-infos . - id: json_annotation_pub_upgrade - name: json_annotation; pub upgrade + name: json_annotation; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: json_annotation - run: pub upgrade + run: dart pub upgrade - name: "json_annotation; dart format --output=none --set-exit-if-changed ." if: "always() && steps.json_annotation_pub_upgrade.conclusion == 'success'" working-directory: json_annotation @@ -192,10 +192,10 @@ jobs: working-directory: json_annotation run: dart analyze --fatal-infos . - id: json_serializable_pub_upgrade - name: json_serializable; pub upgrade + name: json_serializable; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: json_serializable - run: pub upgrade + run: dart pub upgrade - name: "json_serializable; dart format --output=none --set-exit-if-changed ." if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" working-directory: json_serializable @@ -224,37 +224,37 @@ jobs: - id: checkout uses: actions/checkout@v2.3.4 - id: _test_yaml_pub_upgrade - name: _test_yaml; pub upgrade + name: _test_yaml; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: _test_yaml - run: pub upgrade + run: dart pub upgrade - name: _test_yaml; dart test if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" working-directory: _test_yaml run: dart test - id: checked_yaml_pub_upgrade - name: checked_yaml; pub upgrade + name: checked_yaml; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: checked_yaml - run: pub upgrade + run: dart pub upgrade - name: checked_yaml; dart test if: "always() && steps.checked_yaml_pub_upgrade.conclusion == 'success'" working-directory: checked_yaml run: dart test - id: example_pub_upgrade - name: example; pub upgrade + name: example; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: example - run: pub upgrade + run: dart pub upgrade - name: example; dart test if: "always() && steps.example_pub_upgrade.conclusion == 'success'" working-directory: example run: dart test - id: json_serializable_pub_upgrade - name: json_serializable; pub upgrade + name: json_serializable; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: json_serializable - run: pub upgrade + run: dart pub upgrade - name: json_serializable; dart test if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" working-directory: json_serializable @@ -283,10 +283,10 @@ jobs: - id: checkout uses: actions/checkout@v2.3.4 - id: json_serializable_pub_upgrade - name: json_serializable; pub upgrade + name: json_serializable; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: json_serializable - run: pub upgrade + run: dart pub upgrade - name: "json_serializable; dart test -p chrome" if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" working-directory: json_serializable @@ -315,37 +315,37 @@ jobs: - id: checkout uses: actions/checkout@v2.3.4 - id: _test_yaml_pub_upgrade - name: _test_yaml; pub upgrade + name: _test_yaml; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: _test_yaml - run: pub upgrade + run: dart pub upgrade - name: _test_yaml; dart test if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" working-directory: _test_yaml run: dart test - id: checked_yaml_pub_upgrade - name: checked_yaml; pub upgrade + name: checked_yaml; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: checked_yaml - run: pub upgrade + run: dart pub upgrade - name: checked_yaml; dart test if: "always() && steps.checked_yaml_pub_upgrade.conclusion == 'success'" working-directory: checked_yaml run: dart test - id: example_pub_upgrade - name: example; pub upgrade + name: example; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: example - run: pub upgrade + run: dart pub upgrade - name: example; dart test if: "always() && steps.example_pub_upgrade.conclusion == 'success'" working-directory: example run: dart test - id: json_serializable_pub_upgrade - name: json_serializable; pub upgrade + name: json_serializable; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: json_serializable - run: pub upgrade + run: dart pub upgrade - name: json_serializable; dart test if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" working-directory: json_serializable @@ -374,10 +374,10 @@ jobs: - id: checkout uses: actions/checkout@v2.3.4 - id: json_serializable_pub_upgrade - name: json_serializable; pub upgrade + name: json_serializable; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: json_serializable - run: pub upgrade + run: dart pub upgrade - name: "json_serializable; dart test -p chrome" if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" working-directory: json_serializable @@ -406,37 +406,37 @@ jobs: - id: checkout uses: actions/checkout@v2.3.4 - id: _test_yaml_pub_upgrade - name: _test_yaml; pub upgrade + name: _test_yaml; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: _test_yaml - run: pub upgrade + run: dart pub upgrade - name: "_test_yaml; dart test --run-skipped -t presubmit-only test/ensure_build_test.dart" if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" working-directory: _test_yaml run: dart test --run-skipped -t presubmit-only test/ensure_build_test.dart - id: checked_yaml_pub_upgrade - name: checked_yaml; pub upgrade + name: checked_yaml; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: checked_yaml - run: pub upgrade + run: dart pub upgrade - name: "checked_yaml; dart test --run-skipped -t presubmit-only test/ensure_build_test.dart" if: "always() && steps.checked_yaml_pub_upgrade.conclusion == 'success'" working-directory: checked_yaml run: dart test --run-skipped -t presubmit-only test/ensure_build_test.dart - id: example_pub_upgrade - name: example; pub upgrade + name: example; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: example - run: pub upgrade + run: dart pub upgrade - name: "example; dart test --run-skipped -t presubmit-only test/ensure_build_test.dart" if: "always() && steps.example_pub_upgrade.conclusion == 'success'" working-directory: example run: dart test --run-skipped -t presubmit-only test/ensure_build_test.dart - id: json_serializable_pub_upgrade - name: json_serializable; pub upgrade + name: json_serializable; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: json_serializable - run: pub upgrade + run: dart pub upgrade - name: "json_serializable; dart test --run-skipped -t presubmit-only test/ensure_build_test.dart" if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" working-directory: json_serializable @@ -469,37 +469,37 @@ jobs: - id: checkout uses: actions/checkout@v2.3.4 - id: _test_yaml_pub_upgrade - name: _test_yaml; pub upgrade + name: _test_yaml; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: _test_yaml - run: pub upgrade + run: dart pub upgrade - name: "_test_yaml; dart test --run-skipped -t presubmit-only test/ensure_build_test.dart" if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" working-directory: _test_yaml run: dart test --run-skipped -t presubmit-only test/ensure_build_test.dart - id: checked_yaml_pub_upgrade - name: checked_yaml; pub upgrade + name: checked_yaml; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: checked_yaml - run: pub upgrade + run: dart pub upgrade - name: "checked_yaml; dart test --run-skipped -t presubmit-only test/ensure_build_test.dart" if: "always() && steps.checked_yaml_pub_upgrade.conclusion == 'success'" working-directory: checked_yaml run: dart test --run-skipped -t presubmit-only test/ensure_build_test.dart - id: example_pub_upgrade - name: example; pub upgrade + name: example; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: example - run: pub upgrade + run: dart pub upgrade - name: "example; dart test --run-skipped -t presubmit-only test/ensure_build_test.dart" if: "always() && steps.example_pub_upgrade.conclusion == 'success'" working-directory: example run: dart test --run-skipped -t presubmit-only test/ensure_build_test.dart - id: json_serializable_pub_upgrade - name: json_serializable; pub upgrade + name: json_serializable; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: json_serializable - run: pub upgrade + run: dart pub upgrade - name: "json_serializable; dart test --run-skipped -t presubmit-only test/ensure_build_test.dart" if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" working-directory: json_serializable diff --git a/_test_yaml/mono_pkg.yaml b/_test_yaml/mono_pkg.yaml index 50ddd7215..c731c29e5 100644 --- a/_test_yaml/mono_pkg.yaml +++ b/_test_yaml/mono_pkg.yaml @@ -6,8 +6,8 @@ dart: stages: - analyzer_and_format: - group: - - dartfmt - - dartanalyzer: --fatal-infos . + - format + - analyze: --fatal-infos . - unit_test: - test - ensure_build: diff --git a/checked_yaml/mono_pkg.yaml b/checked_yaml/mono_pkg.yaml index 9b068d820..e83d7d1dc 100644 --- a/checked_yaml/mono_pkg.yaml +++ b/checked_yaml/mono_pkg.yaml @@ -6,8 +6,8 @@ dart: stages: - analyzer_and_format: - group: - - dartfmt - - dartanalyzer: --fatal-infos . + - format + - analyze: --fatal-infos . - unit_test: - test diff --git a/example/mono_pkg.yaml b/example/mono_pkg.yaml index d3815a8d7..f3afd8417 100644 --- a/example/mono_pkg.yaml +++ b/example/mono_pkg.yaml @@ -6,8 +6,8 @@ dart: stages: - analyzer_and_format: - group: - - dartfmt - - dartanalyzer: --fatal-infos . + - format + - analyze: --fatal-infos . - unit_test: - test - ensure_build: diff --git a/json_annotation/mono_pkg.yaml b/json_annotation/mono_pkg.yaml index 987f46558..2413a305f 100644 --- a/json_annotation/mono_pkg.yaml +++ b/json_annotation/mono_pkg.yaml @@ -6,5 +6,5 @@ dart: stages: - analyzer_and_format: - group: - - dartfmt - - dartanalyzer: --fatal-infos . + - format + - analyze: --fatal-infos . diff --git a/json_serializable/mono_pkg.yaml b/json_serializable/mono_pkg.yaml index d15580f01..e9145b0ae 100644 --- a/json_serializable/mono_pkg.yaml +++ b/json_serializable/mono_pkg.yaml @@ -6,8 +6,8 @@ dart: stages: - analyzer_and_format: - group: - - dartfmt - - dartanalyzer: --fatal-infos . + - format + - analyze: --fatal-infos . - unit_test: - test: - test: -p chrome diff --git a/tool/ci.sh b/tool/ci.sh index c3a24113b..3c31a5f16 100755 --- a/tool/ci.sh +++ b/tool/ci.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Created with package:mono_repo v4.1.0 +# Created with package:mono_repo v5.0.0 # Support built in commands on windows out of the box. # When it is a flutter repo (check the pubspec.yaml for "sdk: flutter") @@ -7,31 +7,29 @@ # This assumes that the Flutter SDK has been installed in a previous step. function pub() { if grep -Fq "sdk: flutter" "${PWD}/pubspec.yaml"; then - if [[ $TRAVIS_OS_NAME == "windows" ]]; then - command flutter.bat pub "$@" - else - command flutter pub "$@" - fi + command flutter pub "$@" else - if [[ $TRAVIS_OS_NAME == "windows" ]]; then - command pub.bat "$@" - else - command dart pub "$@" - fi + command dart pub "$@" fi } -function dartfmt() { - if [[ $TRAVIS_OS_NAME == "windows" ]]; then - command dartfmt.bat "$@" +# When it is a flutter repo (check the pubspec.yaml for "sdk: flutter") +# then "flutter" is called instead of "pub". +# This assumes that the Flutter SDK has been installed in a previous step. +function format() { + if grep -Fq "sdk: flutter" "${PWD}/pubspec.yaml"; then + command flutter format "$@" else - command dartfmt "$@" + command dart format "$@" fi } -function dartanalyzer() { - if [[ $TRAVIS_OS_NAME == "windows" ]]; then - command dartanalyzer.bat "$@" +# When it is a flutter repo (check the pubspec.yaml for "sdk: flutter") +# then "flutter" is called instead of "pub". +# This assumes that the Flutter SDK has been installed in a previous step. +function analyze() { + if grep -Fq "sdk: flutter" "${PWD}/pubspec.yaml"; then + command flutter analyze "$@" else - command dartanalyzer "$@" + command dart analyze "$@" fi } @@ -69,11 +67,11 @@ for PKG in ${PKGS}; do echo echo -e "\033[1mPKG: ${PKG}; TASK: ${TASK}\033[22m" case ${TASK} in - dartanalyzer) + analyze) echo 'dart analyze --fatal-infos .' dart analyze --fatal-infos . || EXIT_CODE=$? ;; - dartfmt) + format) echo 'dart format --output=none --set-exit-if-changed .' dart format --output=none --set-exit-if-changed . || EXIT_CODE=$? ;; From 3eabe514539c9175052c4d6b2ce93f855656fdb5 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 22 Jun 2021 13:27:07 -0700 Subject: [PATCH 315/569] Update API usage from pkg:analyzer (#922) --- json_serializable/CHANGELOG.md | 1 + json_serializable/lib/src/decode_helper.dart | 7 +------ json_serializable/lib/src/field_helpers.dart | 5 ++--- json_serializable/pubspec.yaml | 2 +- 4 files changed, 5 insertions(+), 10 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 9134863eb..d0fc1ff36 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -13,6 +13,7 @@ - `type_helper.dart`: - **BREAKING**: removed `typeArgumentsOf`. This is now an extension exposed by `package:source_helper`. +- Require `package:analyzer` `^1.7.0`. ## 4.1.3 diff --git a/json_serializable/lib/src/decode_helper.dart b/json_serializable/lib/src/decode_helper.dart index 955c224aa..b332a071f 100644 --- a/json_serializable/lib/src/decode_helper.dart +++ b/json_serializable/lib/src/decode_helper.dart @@ -61,12 +61,7 @@ abstract class DecodeHelper implements HelperCore { element, accessibleFields.keys, accessibleFields.values - .where((fe) => - !fe.isFinal || - // Handle the case where `fe` defines a getter in `element` - // and there is a setter in a super class - // See google/json_serializable.dart#613 - element.lookUpSetter(fe.name, element.library) != null) + .where((fe) => element.lookUpSetter(fe.name, element.library) != null) .map((fe) => fe.name) .toList(), unavailableReasons, diff --git a/json_serializable/lib/src/field_helpers.dart b/json_serializable/lib/src/field_helpers.dart index e479c4d10..d2bc5c6a3 100644 --- a/json_serializable/lib/src/field_helpers.dart +++ b/json_serializable/lib/src/field_helpers.dart @@ -58,9 +58,8 @@ class _FieldSet implements Comparable<_FieldSet> { /// Returns the offset of given field/property in its source file – with a /// preference for the getter if it's defined. int _offsetFor(FieldElement e) { - if (e.getter != null && e.getter!.nameOffset != e.nameOffset) { - assert(e.nameOffset == -1); - return e.getter!.nameOffset; + if (e.isSynthetic) { + return (e.getter ?? e.setter)!.nameOffset; } return e.nameOffset; } diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index e1c4e0fc4..8094f8b4f 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -8,7 +8,7 @@ environment: sdk: '>=2.12.0 <3.0.0' dependencies: - analyzer: '>=0.41.2 <2.0.0' + analyzer: ^1.7.0 build: ^2.0.0 build_config: '>=0.4.4 <2.0.0' collection: ^1.14.0 From 7df02a347858621a31d916d0468337f05d12d31c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 5 Jul 2021 10:33:59 -0700 Subject: [PATCH 316/569] Bump actions/setup-node from 2.1.5 to 2.2.0 (#928) Bumps [actions/setup-node](https://github.com/actions/setup-node) from 2.1.5 to 2.2.0. - [Release notes](https://github.com/actions/setup-node/releases) - [Commits](https://github.com/actions/setup-node/compare/v2.1.5...v2.2.0) --- updated-dependencies: - dependency-name: actions/setup-node dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/markdown_linter.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/markdown_linter.yml b/.github/workflows/markdown_linter.yml index 53509b0bd..eb17ad559 100644 --- a/.github/workflows/markdown_linter.yml +++ b/.github/workflows/markdown_linter.yml @@ -21,7 +21,7 @@ jobs: steps: - uses: actions/checkout@master - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v2.1.5 + uses: actions/setup-node@v2.2.0 with: node-version: ${{ matrix.node-version }} - name: Install dependencies From 26ae25e2801b9be344f5f9d989ffb241cc34badc Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 13 Jul 2021 12:00:52 -0700 Subject: [PATCH 317/569] json_serializable: require latest analyzer (#936) checked_yaml: add dependency overrides to validate latest --- checked_yaml/example/example.g.dart | 25 +++++++++++-------- checked_yaml/pubspec.yaml | 6 +++++ json_serializable/CHANGELOG.md | 2 +- json_serializable/lib/src/decode_helper.dart | 15 ++++++++--- json_serializable/lib/src/encoder_helper.dart | 4 ++- json_serializable/lib/src/field_helpers.dart | 2 +- json_serializable/pubspec.yaml | 2 +- json_serializable/tool/test_builder.dart | 2 +- 8 files changed, 39 insertions(+), 19 deletions(-) diff --git a/checked_yaml/example/example.g.dart b/checked_yaml/example/example.g.dart index 0a3b3de52..c4d01aefb 100644 --- a/checked_yaml/example/example.g.dart +++ b/checked_yaml/example/example.g.dart @@ -6,17 +6,22 @@ part of 'example.dart'; // JsonSerializableGenerator // ************************************************************************** -Configuration _$ConfigurationFromJson(Map json) { - return $checkedNew('Configuration', json, () { - $checkKeys(json, - allowedKeys: const ['name', 'count'], requiredKeys: const ['name']); - final val = Configuration( - name: $checkedConvert(json, 'name', (v) => v as String), - count: $checkedConvert(json, 'count', (v) => v as int), +Configuration _$ConfigurationFromJson(Map json) => $checkedCreate( + 'Configuration', + json, + ($checkedConvert) { + $checkKeys( + json, + allowedKeys: const ['name', 'count'], + requiredKeys: const ['name'], + ); + final val = Configuration( + name: $checkedConvert('name', (v) => v as String), + count: $checkedConvert('count', (v) => v as int), + ); + return val; + }, ); - return val; - }); -} Map _$ConfigurationToJson(Configuration instance) => { diff --git a/checked_yaml/pubspec.yaml b/checked_yaml/pubspec.yaml index becff7234..36a28250e 100644 --- a/checked_yaml/pubspec.yaml +++ b/checked_yaml/pubspec.yaml @@ -20,3 +20,9 @@ dev_dependencies: path: ^1.0.0 test: ^1.16.0 test_process: ^2.0.0 + +dependency_overrides: + json_annotation: + path: ../json_annotation + json_serializable: + path: ../json_serializable diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index d0fc1ff36..b24a6adc2 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -13,7 +13,7 @@ - `type_helper.dart`: - **BREAKING**: removed `typeArgumentsOf`. This is now an extension exposed by `package:source_helper`. -- Require `package:analyzer` `^1.7.0`. +- Require `package:analyzer` `^2.0.0`. ## 4.1.3 diff --git a/json_serializable/lib/src/decode_helper.dart b/json_serializable/lib/src/decode_helper.dart index b332a071f..9bcc0acb2 100644 --- a/json_serializable/lib/src/decode_helper.dart +++ b/json_serializable/lib/src/decode_helper.dart @@ -76,11 +76,14 @@ abstract class DecodeHelper implements HelperCore { if (config.checked) { final classLiteral = escapeDartString(element.name); - final sectionBuffer = StringBuffer()..write(''' + final sectionBuffer = StringBuffer() + ..write(''' \$checkedCreate( $classLiteral, json, - (\$checkedConvert) {\n''')..write(checks.join())..write(''' + (\$checkedConvert) {\n''') + ..write(checks.join()) + ..write(''' final val = ${data.content};'''); for (final field in data.fieldsToSet) { @@ -110,7 +113,9 @@ abstract class DecodeHelper implements HelperCore { fieldKeyMapArg = ', fieldKeyMap: const $mapLiteral'; } - sectionBuffer..write(fieldKeyMapArg)..write(',);'); + sectionBuffer + ..write(fieldKeyMapArg) + ..write(',);'); fromJsonLines.add(sectionBuffer.toString()); } else { fromJsonLines.addAll(checks); @@ -128,7 +133,9 @@ abstract class DecodeHelper implements HelperCore { } if (fromJsonLines.length == 1) { - buffer..write('=>')..write(fromJsonLines.single); + buffer + ..write('=>') + ..write(fromJsonLines.single); } else { buffer ..write('{') diff --git a/json_serializable/lib/src/encoder_helper.dart b/json_serializable/lib/src/encoder_helper.dart index 660ab4938..fd963329d 100644 --- a/json_serializable/lib/src/encoder_helper.dart +++ b/json_serializable/lib/src/encoder_helper.dart @@ -121,7 +121,9 @@ abstract class EncodeHelper implements HelperCore { } } - buffer..writeln(' return $generatedLocalVarName;')..writeln(' }'); + buffer + ..writeln(' return $generatedLocalVarName;') + ..writeln(' }'); } String _serializeField(FieldElement field, String accessExpression) { diff --git a/json_serializable/lib/src/field_helpers.dart b/json_serializable/lib/src/field_helpers.dart index d2bc5c6a3..bfeff2e93 100644 --- a/json_serializable/lib/src/field_helpers.dart +++ b/json_serializable/lib/src/field_helpers.dart @@ -101,7 +101,7 @@ Iterable createSortedFieldSet(ClassElement element) { final fields = allFields .map((e) => _FieldSet(elementInstanceFields[e], inheritedFields[e])) .toList() - ..sort(); + ..sort(); return fields.map((fs) => fs.field).toList(); } diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 8094f8b4f..409dc0b6a 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -8,7 +8,7 @@ environment: sdk: '>=2.12.0 <3.0.0' dependencies: - analyzer: ^1.7.0 + analyzer: ^2.0.0 build: ^2.0.0 build_config: '>=0.4.4 <2.0.0' collection: ^1.14.0 diff --git a/json_serializable/tool/test_builder.dart b/json_serializable/tool/test_builder.dart index 4282e43e1..6e6389c4c 100644 --- a/json_serializable/tool/test_builder.dart +++ b/json_serializable/tool/test_builder.dart @@ -162,7 +162,7 @@ List get _fileConfigurations => _fileConfigurationMap.values .followedBy(['.factories.dart']) .toSet() .toList() - ..sort(); + ..sort(); const _kitchenSinkBaseName = 'kitchen_sink'; From 6cb51dbacfbebe4a570b8a891732de9109fbce40 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 13 Jul 2021 12:52:13 -0700 Subject: [PATCH 318/569] json_annotation: prepare for release (#937) Regenerate json_annotation code Update example to use overrides Enable expression body lint --- analysis_options.yaml | 3 +- example/lib/example.g.dart | 58 +++++------ .../lib/generic_response_class_example.g.dart | 55 +++++------ example/lib/json_converter_example.g.dart | 39 ++++---- example/lib/tuple_example.g.dart | 30 +++--- example/pubspec.yaml | 6 ++ json_annotation/CHANGELOG.md | 2 +- .../lib/src/json_serializable.g.dart | 95 ++++++++++--------- json_annotation/pubspec.yaml | 6 +- 9 files changed, 143 insertions(+), 151 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index 8ee7ce592..3c9c88a16 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -67,8 +67,7 @@ linter: - prefer_const_declarations - prefer_contains - prefer_equal_for_default_values - # Enable once we roll checked_yaml and example - #- prefer_expression_function_bodies + - prefer_expression_function_bodies - prefer_final_fields - prefer_final_locals - prefer_for_elements_to_map_fromIterable diff --git a/example/lib/example.g.dart b/example/lib/example.g.dart index 29f93504e..04ce2ac6a 100644 --- a/example/lib/example.g.dart +++ b/example/lib/example.g.dart @@ -6,20 +6,18 @@ part of 'example.dart'; // JsonSerializableGenerator // ************************************************************************** -Person _$PersonFromJson(Map json) { - return Person( - json['firstName'] as String, - json['lastName'] as String, - DateTime.parse(json['date-of-birth'] as String), - middleName: json['middleName'] as String?, - lastOrder: json['last-order'] == null - ? null - : DateTime.parse(json['last-order'] as String), - orders: (json['orders'] as List?) - ?.map((e) => Order.fromJson(e as Map)) - .toList(), - ); -} +Person _$PersonFromJson(Map json) => Person( + json['firstName'] as String, + json['lastName'] as String, + DateTime.parse(json['date-of-birth'] as String), + middleName: json['middleName'] as String?, + lastOrder: json['last-order'] == null + ? null + : DateTime.parse(json['last-order'] as String), + orders: (json['orders'] as List?) + ?.map((e) => Order.fromJson(e as Map)) + .toList(), + ); Map _$PersonToJson(Person instance) { final val = { @@ -40,18 +38,16 @@ Map _$PersonToJson(Person instance) { return val; } -Order _$OrderFromJson(Map json) { - return Order( - Order._dateTimeFromEpochUs(json['date'] as int), - ) - ..count = json['count'] as int? - ..itemNumber = json['itemNumber'] as int? - ..isRushed = json['isRushed'] as bool? - ..item = json['item'] == null - ? null - : Item.fromJson(json['item'] as Map) - ..prepTime = Order._durationFromMilliseconds(json['prep-time'] as int?); -} +Order _$OrderFromJson(Map json) => Order( + Order._dateTimeFromEpochUs(json['date'] as int), + ) + ..count = json['count'] as int? + ..itemNumber = json['itemNumber'] as int? + ..isRushed = json['isRushed'] as bool? + ..item = json['item'] == null + ? null + : Item.fromJson(json['item'] as Map) + ..prepTime = Order._durationFromMilliseconds(json['prep-time'] as int?); Map _$OrderToJson(Order instance) { final val = {}; @@ -71,12 +67,10 @@ Map _$OrderToJson(Order instance) { return val; } -Item _$ItemFromJson(Map json) { - return Item() - ..count = json['count'] as int? - ..itemNumber = json['itemNumber'] as int? - ..isRushed = json['isRushed'] as bool?; -} +Item _$ItemFromJson(Map json) => Item() + ..count = json['count'] as int? + ..itemNumber = json['itemNumber'] as int? + ..isRushed = json['isRushed'] as bool?; Map _$ItemToJson(Item instance) => { 'count': instance.count, diff --git a/example/lib/generic_response_class_example.g.dart b/example/lib/generic_response_class_example.g.dart index ffd875507..6b2e9325a 100644 --- a/example/lib/generic_response_class_example.g.dart +++ b/example/lib/generic_response_class_example.g.dart @@ -6,37 +6,30 @@ part of 'generic_response_class_example.dart'; // JsonSerializableGenerator // ************************************************************************** -BaseResponse _$BaseResponseFromJson(Map json) { - return BaseResponse( - status: json['status'] as int?, - msg: json['msg'] as String?, - data: BaseResponse._dataFromJson(json['data'] as Object), - ); -} +BaseResponse _$BaseResponseFromJson(Map json) => + BaseResponse( + status: json['status'] as int?, + msg: json['msg'] as String?, + data: BaseResponse._dataFromJson(json['data'] as Object), + ); -Article _$ArticleFromJson(Map json) { - return Article( - id: json['id'] as int, - title: json['title'] as String, - author: json['author'] == null - ? null - : User.fromJson(json['author'] as Map), - comments: (json['comments'] as List?) - ?.map((e) => Comment.fromJson(e as Map)) - .toList(), - ); -} +Article _$ArticleFromJson(Map json) => Article( + id: json['id'] as int, + title: json['title'] as String, + author: json['author'] == null + ? null + : User.fromJson(json['author'] as Map), + comments: (json['comments'] as List?) + ?.map((e) => Comment.fromJson(e as Map)) + .toList(), + ); -User _$UserFromJson(Map json) { - return User( - id: json['id'] as int?, - email: json['email'] as String?, - ); -} +User _$UserFromJson(Map json) => User( + id: json['id'] as int?, + email: json['email'] as String?, + ); -Comment _$CommentFromJson(Map json) { - return Comment( - id: json['id'] as int?, - content: json['content'] as String?, - ); -} +Comment _$CommentFromJson(Map json) => Comment( + id: json['id'] as int?, + content: json['content'] as String?, + ); diff --git a/example/lib/json_converter_example.g.dart b/example/lib/json_converter_example.g.dart index 62b29746a..526177be7 100644 --- a/example/lib/json_converter_example.g.dart +++ b/example/lib/json_converter_example.g.dart @@ -6,27 +6,26 @@ part of 'json_converter_example.dart'; // JsonSerializableGenerator // ************************************************************************** -DateTimeExample _$DateTimeExampleFromJson(Map json) { - return DateTimeExample( - const _DateTimeEpochConverter().fromJson(json['when'] as int), - ); -} +DateTimeExample _$DateTimeExampleFromJson(Map json) => + DateTimeExample( + const _DateTimeEpochConverter().fromJson(json['when'] as int), + ); Map _$DateTimeExampleToJson(DateTimeExample instance) => { 'when': const _DateTimeEpochConverter().toJson(instance.when), }; -GenericCollection _$GenericCollectionFromJson(Map json) { - return GenericCollection( - page: json['page'] as int?, - totalResults: json['total_results'] as int?, - totalPages: json['total_pages'] as int?, - results: (json['results'] as List?) - ?.map(_Converter().fromJson) - .toList(), - ); -} +GenericCollection _$GenericCollectionFromJson( + Map json) => + GenericCollection( + page: json['page'] as int?, + totalResults: json['total_results'] as int?, + totalPages: json['total_pages'] as int?, + results: (json['results'] as List?) + ?.map(_Converter().fromJson) + .toList(), + ); Map _$GenericCollectionToJson( GenericCollection instance) => @@ -37,12 +36,10 @@ Map _$GenericCollectionToJson( 'results': instance.results?.map(_Converter().toJson).toList(), }; -CustomResult _$CustomResultFromJson(Map json) { - return CustomResult( - json['name'] as String, - json['size'] as int, - ); -} +CustomResult _$CustomResultFromJson(Map json) => CustomResult( + json['name'] as String, + json['size'] as int, + ); Map _$CustomResultToJson(CustomResult instance) => { diff --git a/example/lib/tuple_example.g.dart b/example/lib/tuple_example.g.dart index c881fecfc..e6a4690c2 100644 --- a/example/lib/tuple_example.g.dart +++ b/example/lib/tuple_example.g.dart @@ -10,12 +10,11 @@ Tuple _$TupleFromJson( Map json, T Function(Object? json) fromJsonT, S Function(Object? json) fromJsonS, -) { - return Tuple( - fromJsonT(json['value1']), - fromJsonS(json['value2']), - ); -} +) => + Tuple( + fromJsonT(json['value1']), + fromJsonS(json['value2']), + ); Map _$TupleToJson( Tuple instance, @@ -27,16 +26,15 @@ Map _$TupleToJson( 'value2': toJsonS(instance.value2), }; -ConcreteClass _$ConcreteClassFromJson(Map json) { - return ConcreteClass( - Tuple.fromJson(json['tuple1'] as Map, - (value) => value as int, (value) => DateTime.parse(value as String)), - Tuple.fromJson( - json['tuple2'] as Map, - (value) => Duration(microseconds: value as int), - (value) => BigInt.parse(value as String)), - ); -} +ConcreteClass _$ConcreteClassFromJson(Map json) => + ConcreteClass( + Tuple.fromJson(json['tuple1'] as Map, + (value) => value as int, (value) => DateTime.parse(value as String)), + Tuple.fromJson( + json['tuple2'] as Map, + (value) => Duration(microseconds: value as int), + (value) => BigInt.parse(value as String)), + ); Map _$ConcreteClassToJson(ConcreteClass instance) => { diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 53668ed78..aa013d193 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -19,3 +19,9 @@ dev_dependencies: path: ^1.8.0 # Used by tests. Not required to use `json_serializable`. test: ^1.16.0 + +dependency_overrides: + json_annotation: + path: ../json_annotation + json_serializable: + path: ../json_serializable diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index 3b1d43495..b10746b46 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -1,4 +1,4 @@ -## 4.1.0-dev +## 4.1.0 - Added a `const` constructor to `JsonConverter`. - Added `$checkedCreate` helper that will be used by `package:json_serializable` diff --git a/json_annotation/lib/src/json_serializable.g.dart b/json_annotation/lib/src/json_serializable.g.dart index e1cceafcc..d0b8a896c 100644 --- a/json_annotation/lib/src/json_serializable.g.dart +++ b/json_annotation/lib/src/json_serializable.g.dart @@ -7,51 +7,56 @@ part of 'json_serializable.dart'; // ************************************************************************** JsonSerializable _$JsonSerializableFromJson(Map json) => - $checkedNew('JsonSerializable', json, () { - $checkKeys(json, allowedKeys: const [ - 'any_map', - 'checked', - 'create_factory', - 'create_to_json', - 'disallow_unrecognized_keys', - 'explicit_to_json', - 'field_rename', - 'generic_argument_factories', - 'ignore_unannotated', - 'include_if_null' - ]); - final val = JsonSerializable( - anyMap: $checkedConvert(json, 'any_map', (v) => v as bool?), - checked: $checkedConvert(json, 'checked', (v) => v as bool?), - createFactory: - $checkedConvert(json, 'create_factory', (v) => v as bool?), - createToJson: - $checkedConvert(json, 'create_to_json', (v) => v as bool?), - disallowUnrecognizedKeys: $checkedConvert( - json, 'disallow_unrecognized_keys', (v) => v as bool?), - explicitToJson: - $checkedConvert(json, 'explicit_to_json', (v) => v as bool?), - fieldRename: $checkedConvert(json, 'field_rename', - (v) => _$enumDecodeNullable(_$FieldRenameEnumMap, v)), - ignoreUnannotated: - $checkedConvert(json, 'ignore_unannotated', (v) => v as bool?), - includeIfNull: - $checkedConvert(json, 'include_if_null', (v) => v as bool?), - genericArgumentFactories: $checkedConvert( - json, 'generic_argument_factories', (v) => v as bool?), - ); - return val; - }, fieldKeyMap: const { - 'anyMap': 'any_map', - 'createFactory': 'create_factory', - 'createToJson': 'create_to_json', - 'disallowUnrecognizedKeys': 'disallow_unrecognized_keys', - 'explicitToJson': 'explicit_to_json', - 'fieldRename': 'field_rename', - 'ignoreUnannotated': 'ignore_unannotated', - 'includeIfNull': 'include_if_null', - 'genericArgumentFactories': 'generic_argument_factories' - }); + $checkedCreate( + 'JsonSerializable', + json, + ($checkedConvert) { + $checkKeys( + json, + allowedKeys: const [ + 'any_map', + 'checked', + 'create_factory', + 'create_to_json', + 'disallow_unrecognized_keys', + 'explicit_to_json', + 'field_rename', + 'generic_argument_factories', + 'ignore_unannotated', + 'include_if_null' + ], + ); + final val = JsonSerializable( + anyMap: $checkedConvert('any_map', (v) => v as bool?), + checked: $checkedConvert('checked', (v) => v as bool?), + createFactory: $checkedConvert('create_factory', (v) => v as bool?), + createToJson: $checkedConvert('create_to_json', (v) => v as bool?), + disallowUnrecognizedKeys: + $checkedConvert('disallow_unrecognized_keys', (v) => v as bool?), + explicitToJson: + $checkedConvert('explicit_to_json', (v) => v as bool?), + fieldRename: $checkedConvert('field_rename', + (v) => _$enumDecodeNullable(_$FieldRenameEnumMap, v)), + ignoreUnannotated: + $checkedConvert('ignore_unannotated', (v) => v as bool?), + includeIfNull: $checkedConvert('include_if_null', (v) => v as bool?), + genericArgumentFactories: + $checkedConvert('generic_argument_factories', (v) => v as bool?), + ); + return val; + }, + fieldKeyMap: const { + 'anyMap': 'any_map', + 'createFactory': 'create_factory', + 'createToJson': 'create_to_json', + 'disallowUnrecognizedKeys': 'disallow_unrecognized_keys', + 'explicitToJson': 'explicit_to_json', + 'fieldRename': 'field_rename', + 'ignoreUnannotated': 'ignore_unannotated', + 'includeIfNull': 'include_if_null', + 'genericArgumentFactories': 'generic_argument_factories' + }, + ); Map _$JsonSerializableToJson(JsonSerializable instance) => { diff --git a/json_annotation/pubspec.yaml b/json_annotation/pubspec.yaml index 20bc1c198..3c55da570 100644 --- a/json_annotation/pubspec.yaml +++ b/json_annotation/pubspec.yaml @@ -1,5 +1,5 @@ name: json_annotation -version: 4.1.0-dev +version: 4.1.0 description: >- Classes and helper functions that support JSON code generation via the `json_serializable` package. @@ -12,5 +12,5 @@ dependencies: # When changing JsonSerializable class. # dev_dependencies: -# build_runner: ^1.0.0 -# json_serializable: ^4.0.0 +# build_runner: ^2.0.0 +# json_serializable: any From 9303ccc8da3bd3ba7780a170c8c964b5342a5e2c Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 13 Jul 2021 13:16:55 -0700 Subject: [PATCH 319/569] json_serializable: prepare to release v5.0.0 (#938) Bump checked_yaml and example to use published pkg:json_annotation --- checked_yaml/pubspec.yaml | 4 +--- example/README.md | 2 +- example/pubspec.yaml | 4 +--- example/test/readme_test.dart | 2 +- json_serializable/CHANGELOG.md | 2 +- json_serializable/pubspec.yaml | 6 +----- 6 files changed, 6 insertions(+), 14 deletions(-) diff --git a/checked_yaml/pubspec.yaml b/checked_yaml/pubspec.yaml index 36a28250e..0195ae7a5 100644 --- a/checked_yaml/pubspec.yaml +++ b/checked_yaml/pubspec.yaml @@ -9,7 +9,7 @@ environment: sdk: '>=2.12.0 <3.0.0' dependencies: - json_annotation: ^4.0.0 + json_annotation: ^4.1.0 source_span: ^1.8.0 yaml: ^3.0.0 @@ -22,7 +22,5 @@ dev_dependencies: test_process: ^2.0.0 dependency_overrides: - json_annotation: - path: ../json_annotation json_serializable: path: ../json_serializable diff --git a/example/README.md b/example/README.md index e5d0c0707..0ae3de505 100644 --- a/example/README.md +++ b/example/README.md @@ -5,7 +5,7 @@ dependencies to your `pubspec.yaml`. ```yaml dependencies: - json_annotation: ^4.0.0 + json_annotation: ^4.1.0 dev_dependencies: build_runner: ^2.0.0 diff --git a/example/pubspec.yaml b/example/pubspec.yaml index aa013d193..a1edcac2f 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -5,7 +5,7 @@ environment: sdk: '>=2.12.0 <3.0.0' dependencies: - json_annotation: ^4.0.0 + json_annotation: ^4.1.0 dev_dependencies: build_runner: ^2.0.0 @@ -21,7 +21,5 @@ dev_dependencies: test: ^1.16.0 dependency_overrides: - json_annotation: - path: ../json_annotation json_serializable: path: ../json_serializable diff --git a/example/test/readme_test.dart b/example/test/readme_test.dart index a49379af5..03677f540 100644 --- a/example/test/readme_test.dart +++ b/example/test/readme_test.dart @@ -25,7 +25,7 @@ void _expect(String fileName) { const _pubspecContent = r''' dependencies: - json_annotation: ^4.0.0 + json_annotation: ^4.1.0 dev_dependencies: build_runner: ^2.0.0 diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index b24a6adc2..c2ae8a867 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,4 +1,4 @@ -## 5.0.0-dev +## 5.0.0 - Use the default value for optional constructor parameters if `JsonKey.defaultValue` is not provided. This could be a breaking behavior diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 409dc0b6a..08892d461 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 5.0.0-dev +version: 5.0.0 description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. @@ -31,7 +31,3 @@ dev_dependencies: stack_trace: ^1.10.0 test: ^1.16.0 yaml: ^3.0.0 - -dependency_overrides: - json_annotation: - path: ../json_annotation From 6e7b1eb2b7319a8897f30d18838e6cd199e342b3 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 13 Jul 2021 13:34:13 -0700 Subject: [PATCH 320/569] update checked_yaml and examples to use latest (#939) --- checked_yaml/pubspec.yaml | 6 +----- example/README.md | 2 +- example/pubspec.yaml | 6 +----- example/test/readme_test.dart | 2 +- 4 files changed, 4 insertions(+), 12 deletions(-) diff --git a/checked_yaml/pubspec.yaml b/checked_yaml/pubspec.yaml index 0195ae7a5..f5495c10f 100644 --- a/checked_yaml/pubspec.yaml +++ b/checked_yaml/pubspec.yaml @@ -16,11 +16,7 @@ dependencies: dev_dependencies: build_runner: ^2.0.0 build_verify: ^2.0.0 - json_serializable: ^4.0.0 + json_serializable: ^5.0.0 path: ^1.0.0 test: ^1.16.0 test_process: ^2.0.0 - -dependency_overrides: - json_serializable: - path: ../json_serializable diff --git a/example/README.md b/example/README.md index 0ae3de505..658af7ac8 100644 --- a/example/README.md +++ b/example/README.md @@ -9,7 +9,7 @@ dependencies: dev_dependencies: build_runner: ^2.0.0 - json_serializable: ^4.0.0 + json_serializable: ^5.0.0 ``` Annotate your code with classes defined in diff --git a/example/pubspec.yaml b/example/pubspec.yaml index a1edcac2f..c9ac80f88 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -13,13 +13,9 @@ dev_dependencies: # Used by tests. Not required to use `json_serializable`. build_verify: ^2.0.0 - json_serializable: ^4.0.0 + json_serializable: ^5.0.0 # Used by tests. Not required to use `json_serializable`. path: ^1.8.0 # Used by tests. Not required to use `json_serializable`. test: ^1.16.0 - -dependency_overrides: - json_serializable: - path: ../json_serializable diff --git a/example/test/readme_test.dart b/example/test/readme_test.dart index 03677f540..ab92b477d 100644 --- a/example/test/readme_test.dart +++ b/example/test/readme_test.dart @@ -29,5 +29,5 @@ dependencies: dev_dependencies: build_runner: ^2.0.0 - json_serializable: ^4.0.0 + json_serializable: ^5.0.0 '''; From 975f88fe9af39a5bad6b8930440161e0b91f73ae Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 13 Jul 2021 15:27:07 -0700 Subject: [PATCH 321/569] v4: Allow the latest json_annotation (#940) --- .github/workflows/dart.yml | 354 +++++++++--------- json_serializable/CHANGELOG.md | 4 + json_serializable/lib/src/decode_helper.dart | 19 +- json_serializable/lib/src/encoder_helper.dart | 4 +- json_serializable/lib/src/field_helpers.dart | 2 +- json_serializable/pubspec.yaml | 4 +- .../src/_json_serializable_test_input.dart | 16 +- json_serializable/tool/test_builder.dart | 2 +- tool/ci.sh | 66 ++-- 9 files changed, 237 insertions(+), 234 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 7f5b10c30..9b2f7a62a 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -1,4 +1,4 @@ -# Created with package:mono_repo v4.0.0 +# Created with package:mono_repo v5.0.0 name: Dart CI on: push: @@ -20,7 +20,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v2.1.5 + uses: actions/cache@v2.1.6 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;dart:stable" @@ -33,18 +33,18 @@ jobs: - id: checkout uses: actions/checkout@v2.3.4 - name: mono_repo self validate - run: pub global activate mono_repo 4.0.0 + run: dart pub global activate mono_repo 5.0.0 - name: mono_repo self validate - run: pub global run mono_repo generate --validate + run: dart pub global run mono_repo generate --validate job_002: - name: "analyzer_and_format; Dart 2.12.0; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; `dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-infos .`" + name: "analyzer_and_format; Dart 2.12.0; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; `dart format --output=none --set-exit-if-changed .`, `dart analyze --fatal-infos .`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v2.1.5 + uses: actions/cache@v2.1.6 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:dartfmt-dartanalyzer" + key: "os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:format-analyze" restore-keys: | os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable os:ubuntu-latest;pub-cache-hosted;dart:2.12.0 @@ -56,79 +56,79 @@ jobs: - id: checkout uses: actions/checkout@v2.3.4 - id: _test_yaml_pub_upgrade - name: "_test_yaml; pub upgrade --no-precompile" + name: _test_yaml; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: _test_yaml - run: pub upgrade --no-precompile - - name: "_test_yaml; dartfmt -n --set-exit-if-changed ." + run: dart pub upgrade + - name: "_test_yaml; dart format --output=none --set-exit-if-changed ." if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" working-directory: _test_yaml - run: dartfmt -n --set-exit-if-changed . - - name: "_test_yaml; dartanalyzer --fatal-infos ." + run: "dart format --output=none --set-exit-if-changed ." + - name: "_test_yaml; dart analyze --fatal-infos ." if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" working-directory: _test_yaml - run: dartanalyzer --fatal-infos . + run: dart analyze --fatal-infos . - id: checked_yaml_pub_upgrade - name: "checked_yaml; pub upgrade --no-precompile" + name: checked_yaml; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: checked_yaml - run: pub upgrade --no-precompile - - name: "checked_yaml; dartfmt -n --set-exit-if-changed ." + run: dart pub upgrade + - name: "checked_yaml; dart format --output=none --set-exit-if-changed ." if: "always() && steps.checked_yaml_pub_upgrade.conclusion == 'success'" working-directory: checked_yaml - run: dartfmt -n --set-exit-if-changed . - - name: "checked_yaml; dartanalyzer --fatal-infos ." + run: "dart format --output=none --set-exit-if-changed ." + - name: "checked_yaml; dart analyze --fatal-infos ." if: "always() && steps.checked_yaml_pub_upgrade.conclusion == 'success'" working-directory: checked_yaml - run: dartanalyzer --fatal-infos . + run: dart analyze --fatal-infos . - id: example_pub_upgrade - name: "example; pub upgrade --no-precompile" + name: example; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: example - run: pub upgrade --no-precompile - - name: "example; dartfmt -n --set-exit-if-changed ." + run: dart pub upgrade + - name: "example; dart format --output=none --set-exit-if-changed ." if: "always() && steps.example_pub_upgrade.conclusion == 'success'" working-directory: example - run: dartfmt -n --set-exit-if-changed . - - name: "example; dartanalyzer --fatal-infos ." + run: "dart format --output=none --set-exit-if-changed ." + - name: "example; dart analyze --fatal-infos ." if: "always() && steps.example_pub_upgrade.conclusion == 'success'" working-directory: example - run: dartanalyzer --fatal-infos . + run: dart analyze --fatal-infos . - id: json_annotation_pub_upgrade - name: "json_annotation; pub upgrade --no-precompile" + name: json_annotation; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: json_annotation - run: pub upgrade --no-precompile - - name: "json_annotation; dartfmt -n --set-exit-if-changed ." + run: dart pub upgrade + - name: "json_annotation; dart format --output=none --set-exit-if-changed ." if: "always() && steps.json_annotation_pub_upgrade.conclusion == 'success'" working-directory: json_annotation - run: dartfmt -n --set-exit-if-changed . - - name: "json_annotation; dartanalyzer --fatal-infos ." + run: "dart format --output=none --set-exit-if-changed ." + - name: "json_annotation; dart analyze --fatal-infos ." if: "always() && steps.json_annotation_pub_upgrade.conclusion == 'success'" working-directory: json_annotation - run: dartanalyzer --fatal-infos . + run: dart analyze --fatal-infos . - id: json_serializable_pub_upgrade - name: "json_serializable; pub upgrade --no-precompile" + name: json_serializable; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: json_serializable - run: pub upgrade --no-precompile - - name: "json_serializable; dartfmt -n --set-exit-if-changed ." + run: dart pub upgrade + - name: "json_serializable; dart format --output=none --set-exit-if-changed ." if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" working-directory: json_serializable - run: dartfmt -n --set-exit-if-changed . - - name: "json_serializable; dartanalyzer --fatal-infos ." + run: "dart format --output=none --set-exit-if-changed ." + - name: "json_serializable; dart analyze --fatal-infos ." if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" working-directory: json_serializable - run: dartanalyzer --fatal-infos . + run: dart analyze --fatal-infos . job_003: - name: "analyzer_and_format; Dart dev; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; `dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-infos .`" + name: "analyzer_and_format; Dart dev; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; `dart format --output=none --set-exit-if-changed .`, `dart analyze --fatal-infos .`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v2.1.5 + uses: actions/cache@v2.1.6 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:dartfmt-dartanalyzer" + key: "os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:format-analyze" restore-keys: | os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable os:ubuntu-latest;pub-cache-hosted;dart:dev @@ -140,76 +140,76 @@ jobs: - id: checkout uses: actions/checkout@v2.3.4 - id: _test_yaml_pub_upgrade - name: "_test_yaml; pub upgrade --no-precompile" + name: _test_yaml; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: _test_yaml - run: pub upgrade --no-precompile - - name: "_test_yaml; dartfmt -n --set-exit-if-changed ." + run: dart pub upgrade + - name: "_test_yaml; dart format --output=none --set-exit-if-changed ." if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" working-directory: _test_yaml - run: dartfmt -n --set-exit-if-changed . - - name: "_test_yaml; dartanalyzer --fatal-infos ." + run: "dart format --output=none --set-exit-if-changed ." + - name: "_test_yaml; dart analyze --fatal-infos ." if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" working-directory: _test_yaml - run: dartanalyzer --fatal-infos . + run: dart analyze --fatal-infos . - id: checked_yaml_pub_upgrade - name: "checked_yaml; pub upgrade --no-precompile" + name: checked_yaml; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: checked_yaml - run: pub upgrade --no-precompile - - name: "checked_yaml; dartfmt -n --set-exit-if-changed ." + run: dart pub upgrade + - name: "checked_yaml; dart format --output=none --set-exit-if-changed ." if: "always() && steps.checked_yaml_pub_upgrade.conclusion == 'success'" working-directory: checked_yaml - run: dartfmt -n --set-exit-if-changed . - - name: "checked_yaml; dartanalyzer --fatal-infos ." + run: "dart format --output=none --set-exit-if-changed ." + - name: "checked_yaml; dart analyze --fatal-infos ." if: "always() && steps.checked_yaml_pub_upgrade.conclusion == 'success'" working-directory: checked_yaml - run: dartanalyzer --fatal-infos . + run: dart analyze --fatal-infos . - id: example_pub_upgrade - name: "example; pub upgrade --no-precompile" + name: example; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: example - run: pub upgrade --no-precompile - - name: "example; dartfmt -n --set-exit-if-changed ." + run: dart pub upgrade + - name: "example; dart format --output=none --set-exit-if-changed ." if: "always() && steps.example_pub_upgrade.conclusion == 'success'" working-directory: example - run: dartfmt -n --set-exit-if-changed . - - name: "example; dartanalyzer --fatal-infos ." + run: "dart format --output=none --set-exit-if-changed ." + - name: "example; dart analyze --fatal-infos ." if: "always() && steps.example_pub_upgrade.conclusion == 'success'" working-directory: example - run: dartanalyzer --fatal-infos . + run: dart analyze --fatal-infos . - id: json_annotation_pub_upgrade - name: "json_annotation; pub upgrade --no-precompile" + name: json_annotation; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: json_annotation - run: pub upgrade --no-precompile - - name: "json_annotation; dartfmt -n --set-exit-if-changed ." + run: dart pub upgrade + - name: "json_annotation; dart format --output=none --set-exit-if-changed ." if: "always() && steps.json_annotation_pub_upgrade.conclusion == 'success'" working-directory: json_annotation - run: dartfmt -n --set-exit-if-changed . - - name: "json_annotation; dartanalyzer --fatal-infos ." + run: "dart format --output=none --set-exit-if-changed ." + - name: "json_annotation; dart analyze --fatal-infos ." if: "always() && steps.json_annotation_pub_upgrade.conclusion == 'success'" working-directory: json_annotation - run: dartanalyzer --fatal-infos . + run: dart analyze --fatal-infos . - id: json_serializable_pub_upgrade - name: "json_serializable; pub upgrade --no-precompile" + name: json_serializable; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: json_serializable - run: pub upgrade --no-precompile - - name: "json_serializable; dartfmt -n --set-exit-if-changed ." + run: dart pub upgrade + - name: "json_serializable; dart format --output=none --set-exit-if-changed ." if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" working-directory: json_serializable - run: dartfmt -n --set-exit-if-changed . - - name: "json_serializable; dartanalyzer --fatal-infos ." + run: "dart format --output=none --set-exit-if-changed ." + - name: "json_serializable; dart analyze --fatal-infos ." if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" working-directory: json_serializable - run: dartanalyzer --fatal-infos . + run: dart analyze --fatal-infos . job_004: - name: "unit_test; Dart 2.12.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; `pub run test`" + name: "unit_test; Dart 2.12.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; `dart test`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v2.1.5 + uses: actions/cache@v2.1.6 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" @@ -224,142 +224,142 @@ jobs: - id: checkout uses: actions/checkout@v2.3.4 - id: _test_yaml_pub_upgrade - name: "_test_yaml; pub upgrade --no-precompile" + name: _test_yaml; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: _test_yaml - run: pub upgrade --no-precompile - - name: _test_yaml; pub run test + run: dart pub upgrade + - name: _test_yaml; dart test if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" working-directory: _test_yaml - run: pub run test + run: dart test - id: checked_yaml_pub_upgrade - name: "checked_yaml; pub upgrade --no-precompile" + name: checked_yaml; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: checked_yaml - run: pub upgrade --no-precompile - - name: checked_yaml; pub run test + run: dart pub upgrade + - name: checked_yaml; dart test if: "always() && steps.checked_yaml_pub_upgrade.conclusion == 'success'" working-directory: checked_yaml - run: pub run test + run: dart test - id: example_pub_upgrade - name: "example; pub upgrade --no-precompile" + name: example; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: example - run: pub upgrade --no-precompile - - name: example; pub run test + run: dart pub upgrade + - name: example; dart test if: "always() && steps.example_pub_upgrade.conclusion == 'success'" working-directory: example - run: pub run test + run: dart test - id: json_serializable_pub_upgrade - name: "json_serializable; pub upgrade --no-precompile" + name: json_serializable; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: json_serializable - run: pub upgrade --no-precompile - - name: json_serializable; pub run test + run: dart pub upgrade + - name: json_serializable; dart test if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" working-directory: json_serializable - run: pub run test + run: dart test needs: - job_001 - job_002 - job_003 job_005: - name: "unit_test; Dart dev; PKGS: _test_yaml, checked_yaml, example, json_serializable; `pub run test`" + name: "unit_test; Dart 2.12.0; PKG: json_serializable; `dart test -p chrome`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v2.1.5 + uses: actions/cache@v2.1.6 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" + key: "os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:json_serializable;commands:test_2" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:_test_yaml-checked_yaml-example-json_serializable - os:ubuntu-latest;pub-cache-hosted;dart:dev + os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:json_serializable + os:ubuntu-latest;pub-cache-hosted;dart:2.12.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - uses: dart-lang/setup-dart@v1.0 with: - sdk: dev + sdk: "2.12.0" - id: checkout uses: actions/checkout@v2.3.4 - - id: _test_yaml_pub_upgrade - name: "_test_yaml; pub upgrade --no-precompile" - if: "always() && steps.checkout.conclusion == 'success'" - working-directory: _test_yaml - run: pub upgrade --no-precompile - - name: _test_yaml; pub run test - if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" - working-directory: _test_yaml - run: pub run test - - id: checked_yaml_pub_upgrade - name: "checked_yaml; pub upgrade --no-precompile" - if: "always() && steps.checkout.conclusion == 'success'" - working-directory: checked_yaml - run: pub upgrade --no-precompile - - name: checked_yaml; pub run test - if: "always() && steps.checked_yaml_pub_upgrade.conclusion == 'success'" - working-directory: checked_yaml - run: pub run test - - id: example_pub_upgrade - name: "example; pub upgrade --no-precompile" - if: "always() && steps.checkout.conclusion == 'success'" - working-directory: example - run: pub upgrade --no-precompile - - name: example; pub run test - if: "always() && steps.example_pub_upgrade.conclusion == 'success'" - working-directory: example - run: pub run test - id: json_serializable_pub_upgrade - name: "json_serializable; pub upgrade --no-precompile" + name: json_serializable; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: json_serializable - run: pub upgrade --no-precompile - - name: json_serializable; pub run test + run: dart pub upgrade + - name: "json_serializable; dart test -p chrome" if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" working-directory: json_serializable - run: pub run test + run: dart test -p chrome needs: - job_001 - job_002 - job_003 job_006: - name: "unit_test; Dart 2.12.0; PKG: json_serializable; `pub run test -p chrome`" + name: "unit_test; Dart dev; PKGS: _test_yaml, checked_yaml, example, json_serializable; `dart test`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v2.1.5 + uses: actions/cache@v2.1.6 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:json_serializable;commands:test_2" + key: "os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:json_serializable - os:ubuntu-latest;pub-cache-hosted;dart:2.12.0 + os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:_test_yaml-checked_yaml-example-json_serializable + os:ubuntu-latest;pub-cache-hosted;dart:dev os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - uses: dart-lang/setup-dart@v1.0 with: - sdk: "2.12.0" + sdk: dev - id: checkout uses: actions/checkout@v2.3.4 + - id: _test_yaml_pub_upgrade + name: _test_yaml; dart pub upgrade + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: _test_yaml + run: dart pub upgrade + - name: _test_yaml; dart test + if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" + working-directory: _test_yaml + run: dart test + - id: checked_yaml_pub_upgrade + name: checked_yaml; dart pub upgrade + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: checked_yaml + run: dart pub upgrade + - name: checked_yaml; dart test + if: "always() && steps.checked_yaml_pub_upgrade.conclusion == 'success'" + working-directory: checked_yaml + run: dart test + - id: example_pub_upgrade + name: example; dart pub upgrade + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: example + run: dart pub upgrade + - name: example; dart test + if: "always() && steps.example_pub_upgrade.conclusion == 'success'" + working-directory: example + run: dart test - id: json_serializable_pub_upgrade - name: "json_serializable; pub upgrade --no-precompile" + name: json_serializable; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: json_serializable - run: pub upgrade --no-precompile - - name: "json_serializable; pub run test -p chrome" + run: dart pub upgrade + - name: json_serializable; dart test if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" working-directory: json_serializable - run: pub run test -p chrome + run: dart test needs: - job_001 - job_002 - job_003 job_007: - name: "unit_test; Dart dev; PKG: json_serializable; `pub run test -p chrome`" + name: "unit_test; Dart dev; PKG: json_serializable; `dart test -p chrome`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v2.1.5 + uses: actions/cache@v2.1.6 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:json_serializable;commands:test_2" @@ -374,24 +374,24 @@ jobs: - id: checkout uses: actions/checkout@v2.3.4 - id: json_serializable_pub_upgrade - name: "json_serializable; pub upgrade --no-precompile" + name: json_serializable; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: json_serializable - run: pub upgrade --no-precompile - - name: "json_serializable; pub run test -p chrome" + run: dart pub upgrade + - name: "json_serializable; dart test -p chrome" if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" working-directory: json_serializable - run: pub run test -p chrome + run: dart test -p chrome needs: - job_001 - job_002 - job_003 job_008: - name: "ensure_build; Dart 2.12.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`" + name: "ensure_build; Dart 2.12.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v2.1.5 + uses: actions/cache@v2.1.6 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_1" @@ -406,41 +406,41 @@ jobs: - id: checkout uses: actions/checkout@v2.3.4 - id: _test_yaml_pub_upgrade - name: "_test_yaml; pub upgrade --no-precompile" + name: _test_yaml; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: _test_yaml - run: pub upgrade --no-precompile - - name: "_test_yaml; pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart" + run: dart pub upgrade + - name: "_test_yaml; dart test --run-skipped -t presubmit-only test/ensure_build_test.dart" if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" working-directory: _test_yaml - run: pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart + run: dart test --run-skipped -t presubmit-only test/ensure_build_test.dart - id: checked_yaml_pub_upgrade - name: "checked_yaml; pub upgrade --no-precompile" + name: checked_yaml; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: checked_yaml - run: pub upgrade --no-precompile - - name: "checked_yaml; pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart" + run: dart pub upgrade + - name: "checked_yaml; dart test --run-skipped -t presubmit-only test/ensure_build_test.dart" if: "always() && steps.checked_yaml_pub_upgrade.conclusion == 'success'" working-directory: checked_yaml - run: pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart + run: dart test --run-skipped -t presubmit-only test/ensure_build_test.dart - id: example_pub_upgrade - name: "example; pub upgrade --no-precompile" + name: example; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: example - run: pub upgrade --no-precompile - - name: "example; pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart" + run: dart pub upgrade + - name: "example; dart test --run-skipped -t presubmit-only test/ensure_build_test.dart" if: "always() && steps.example_pub_upgrade.conclusion == 'success'" working-directory: example - run: pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart + run: dart test --run-skipped -t presubmit-only test/ensure_build_test.dart - id: json_serializable_pub_upgrade - name: "json_serializable; pub upgrade --no-precompile" + name: json_serializable; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: json_serializable - run: pub upgrade --no-precompile - - name: "json_serializable; pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart" + run: dart pub upgrade + - name: "json_serializable; dart test --run-skipped -t presubmit-only test/ensure_build_test.dart" if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" working-directory: json_serializable - run: pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart + run: dart test --run-skipped -t presubmit-only test/ensure_build_test.dart needs: - job_001 - job_002 @@ -450,11 +450,11 @@ jobs: - job_006 - job_007 job_009: - name: "ensure_build; Dart dev; PKGS: _test_yaml, checked_yaml, example, json_serializable; `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`" + name: "ensure_build; Dart dev; PKGS: _test_yaml, checked_yaml, example, json_serializable; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v2.1.5 + uses: actions/cache@v2.1.6 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_1" @@ -469,41 +469,41 @@ jobs: - id: checkout uses: actions/checkout@v2.3.4 - id: _test_yaml_pub_upgrade - name: "_test_yaml; pub upgrade --no-precompile" + name: _test_yaml; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: _test_yaml - run: pub upgrade --no-precompile - - name: "_test_yaml; pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart" + run: dart pub upgrade + - name: "_test_yaml; dart test --run-skipped -t presubmit-only test/ensure_build_test.dart" if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" working-directory: _test_yaml - run: pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart + run: dart test --run-skipped -t presubmit-only test/ensure_build_test.dart - id: checked_yaml_pub_upgrade - name: "checked_yaml; pub upgrade --no-precompile" + name: checked_yaml; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: checked_yaml - run: pub upgrade --no-precompile - - name: "checked_yaml; pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart" + run: dart pub upgrade + - name: "checked_yaml; dart test --run-skipped -t presubmit-only test/ensure_build_test.dart" if: "always() && steps.checked_yaml_pub_upgrade.conclusion == 'success'" working-directory: checked_yaml - run: pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart + run: dart test --run-skipped -t presubmit-only test/ensure_build_test.dart - id: example_pub_upgrade - name: "example; pub upgrade --no-precompile" + name: example; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: example - run: pub upgrade --no-precompile - - name: "example; pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart" + run: dart pub upgrade + - name: "example; dart test --run-skipped -t presubmit-only test/ensure_build_test.dart" if: "always() && steps.example_pub_upgrade.conclusion == 'success'" working-directory: example - run: pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart + run: dart test --run-skipped -t presubmit-only test/ensure_build_test.dart - id: json_serializable_pub_upgrade - name: "json_serializable; pub upgrade --no-precompile" + name: json_serializable; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: json_serializable - run: pub upgrade --no-precompile - - name: "json_serializable; pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart" + run: dart pub upgrade + - name: "json_serializable; dart test --run-skipped -t presubmit-only test/ensure_build_test.dart" if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" working-directory: json_serializable - run: pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart + run: dart test --run-skipped -t presubmit-only test/ensure_build_test.dart needs: - job_001 - job_002 diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 4077a22f2..bf7c1c484 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,7 @@ +## 4.1.4 + +- Allow the latest `package:json_annotation`. + ## 4.1.3 - Correctly handle nullable types with type arguments in generated code. diff --git a/json_serializable/lib/src/decode_helper.dart b/json_serializable/lib/src/decode_helper.dart index d36120fa2..e44eae78a 100644 --- a/json_serializable/lib/src/decode_helper.dart +++ b/json_serializable/lib/src/decode_helper.dart @@ -75,11 +75,14 @@ abstract class DecodeHelper implements HelperCore { if (config.checked) { final classLiteral = escapeDartString(element.name); - buffer..write(''' + buffer + ..write(''' return \$checkedNew( $classLiteral, json, - () {\n''')..write(checks)..write(''' + () {\n''') + ..write(checks) + ..write(''' final val = ${data.content};'''); for (final field in data.fieldsToSet) { @@ -109,9 +112,13 @@ abstract class DecodeHelper implements HelperCore { fieldKeyMapArg = ', fieldKeyMap: const $mapLiteral'; } - buffer..write(fieldKeyMapArg)..write(')'); + buffer + ..write(fieldKeyMapArg) + ..write(')'); } else { - buffer..write(checks)..write(''' + buffer + ..write(checks) + ..write(''' return ${data.content}'''); for (final field in data.fieldsToSet) { buffer @@ -120,7 +127,9 @@ abstract class DecodeHelper implements HelperCore { ..write(deserializeFun(field)); } } - buffer..writeln(';\n}')..writeln(); + buffer + ..writeln(';\n}') + ..writeln(); return CreateFactoryResult(buffer.toString(), data.usedCtorParamsAndFields); } diff --git a/json_serializable/lib/src/encoder_helper.dart b/json_serializable/lib/src/encoder_helper.dart index 6ea548781..446ff4fbb 100644 --- a/json_serializable/lib/src/encoder_helper.dart +++ b/json_serializable/lib/src/encoder_helper.dart @@ -121,7 +121,9 @@ abstract class EncodeHelper implements HelperCore { } } - buffer..writeln(' return $generatedLocalVarName;')..writeln(' }'); + buffer + ..writeln(' return $generatedLocalVarName;') + ..writeln(' }'); } String _serializeField(FieldElement field, String accessExpression) { diff --git a/json_serializable/lib/src/field_helpers.dart b/json_serializable/lib/src/field_helpers.dart index 83b293c90..01d4f2a3a 100644 --- a/json_serializable/lib/src/field_helpers.dart +++ b/json_serializable/lib/src/field_helpers.dart @@ -103,7 +103,7 @@ Iterable createSortedFieldSet(ClassElement element) { final fields = allFields .map((e) => _FieldSet(elementInstanceFields[e], inheritedFields[e])) .toList() - ..sort(); + ..sort(); return fields.map((fs) => fs.field).toList(); } diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 0ba073c14..c3c3ed68e 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 4.1.3 +version: 4.1.4 description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. @@ -15,7 +15,7 @@ dependencies: # Use a tight version constraint to ensure that a constraint on # `json_annotation` properly constrains all features it provides. - json_annotation: '>=4.0.1 <4.1.0' + json_annotation: '>=4.0.1 <4.2.0' meta: ^1.3.0 path: ^1.8.0 source_gen: ^1.0.0 diff --git a/json_serializable/test/src/_json_serializable_test_input.dart b/json_serializable/test/src/_json_serializable_test_input.dart index 81e6b03b7..f3e8d4841 100644 --- a/json_serializable/test/src/_json_serializable_test_input.dart +++ b/json_serializable/test/src/_json_serializable_test_input.dart @@ -5,39 +5,29 @@ import 'dart:collection'; import 'package:json_annotation/json_annotation.dart'; - // ignore: import_of_legacy_library_into_null_safe import 'package:source_gen_test/annotations.dart'; -part 'constants_copy.dart'; - part 'checked_test_input.dart'; - +part 'constants_copy.dart'; part 'core_subclass_type_input.dart'; - part 'default_value_input.dart'; - part 'field_namer_input.dart'; - part 'generic_test_input.dart'; - part 'inheritance_test_input.dart'; - part 'json_converter_test_input.dart'; - part 'map_key_variety_test_input.dart'; - part 'setter_test_input.dart'; - part 'to_from_json_test_input.dart'; - part 'unknown_enum_value_test_input.dart'; @ShouldThrow('`@JsonSerializable` can only be used on classes.') +// ignore: invalid_annotation_target @JsonSerializable() const theAnswer = 42; @ShouldThrow('`@JsonSerializable` can only be used on classes.') +// ignore: invalid_annotation_target @JsonSerializable() Object annotatedMethod() => throw UnimplementedError(); diff --git a/json_serializable/tool/test_builder.dart b/json_serializable/tool/test_builder.dart index 4282e43e1..6e6389c4c 100644 --- a/json_serializable/tool/test_builder.dart +++ b/json_serializable/tool/test_builder.dart @@ -162,7 +162,7 @@ List get _fileConfigurations => _fileConfigurationMap.values .followedBy(['.factories.dart']) .toSet() .toList() - ..sort(); + ..sort(); const _kitchenSinkBaseName = 'kitchen_sink'; diff --git a/tool/ci.sh b/tool/ci.sh index e5d867207..3c31a5f16 100755 --- a/tool/ci.sh +++ b/tool/ci.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Created with package:mono_repo v4.0.0 +# Created with package:mono_repo v5.0.0 # Support built in commands on windows out of the box. # When it is a flutter repo (check the pubspec.yaml for "sdk: flutter") @@ -7,31 +7,29 @@ # This assumes that the Flutter SDK has been installed in a previous step. function pub() { if grep -Fq "sdk: flutter" "${PWD}/pubspec.yaml"; then - if [[ $TRAVIS_OS_NAME == "windows" ]]; then - command flutter.bat pub "$@" - else - command flutter pub "$@" - fi + command flutter pub "$@" else - if [[ $TRAVIS_OS_NAME == "windows" ]]; then - command pub.bat "$@" - else - command pub "$@" - fi + command dart pub "$@" fi } -function dartfmt() { - if [[ $TRAVIS_OS_NAME == "windows" ]]; then - command dartfmt.bat "$@" +# When it is a flutter repo (check the pubspec.yaml for "sdk: flutter") +# then "flutter" is called instead of "pub". +# This assumes that the Flutter SDK has been installed in a previous step. +function format() { + if grep -Fq "sdk: flutter" "${PWD}/pubspec.yaml"; then + command flutter format "$@" else - command dartfmt "$@" + command dart format "$@" fi } -function dartanalyzer() { - if [[ $TRAVIS_OS_NAME == "windows" ]]; then - command dartanalyzer.bat "$@" +# When it is a flutter repo (check the pubspec.yaml for "sdk: flutter") +# then "flutter" is called instead of "pub". +# This assumes that the Flutter SDK has been installed in a previous step. +function analyze() { + if grep -Fq "sdk: flutter" "${PWD}/pubspec.yaml"; then + command flutter analyze "$@" else - command dartanalyzer "$@" + command dart analyze "$@" fi } @@ -58,36 +56,36 @@ for PKG in ${PKGS}; do exit 64 fi - pub upgrade --no-precompile || EXIT_CODE=$? + dart pub upgrade || EXIT_CODE=$? if [[ ${EXIT_CODE} -ne 0 ]]; then - echo -e "\033[31mPKG: ${PKG}; 'pub upgrade' - FAILED (${EXIT_CODE})\033[0m" - FAILURES+=("${PKG}; 'pub upgrade'") + echo -e "\033[31mPKG: ${PKG}; 'dart pub upgrade' - FAILED (${EXIT_CODE})\033[0m" + FAILURES+=("${PKG}; 'dart pub upgrade'") else for TASK in "$@"; do EXIT_CODE=0 echo echo -e "\033[1mPKG: ${PKG}; TASK: ${TASK}\033[22m" case ${TASK} in - dartanalyzer) - echo 'dartanalyzer --fatal-infos .' - dartanalyzer --fatal-infos . || EXIT_CODE=$? + analyze) + echo 'dart analyze --fatal-infos .' + dart analyze --fatal-infos . || EXIT_CODE=$? ;; - dartfmt) - echo 'dartfmt -n --set-exit-if-changed .' - dartfmt -n --set-exit-if-changed . || EXIT_CODE=$? + format) + echo 'dart format --output=none --set-exit-if-changed .' + dart format --output=none --set-exit-if-changed . || EXIT_CODE=$? ;; test_0) - echo 'pub run test' - pub run test || EXIT_CODE=$? + echo 'dart test' + dart test || EXIT_CODE=$? ;; test_1) - echo 'pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart' - pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart || EXIT_CODE=$? + echo 'dart test --run-skipped -t presubmit-only test/ensure_build_test.dart' + dart test --run-skipped -t presubmit-only test/ensure_build_test.dart || EXIT_CODE=$? ;; test_2) - echo 'pub run test -p chrome' - pub run test -p chrome || EXIT_CODE=$? + echo 'dart test -p chrome' + dart test -p chrome || EXIT_CODE=$? ;; *) echo -e "\033[31mUnknown TASK '${TASK}' - TERMINATING JOB\033[0m" From 71e0ffcf428ef88aa4b8e351de9949ae235a2d27 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 21 Jul 2021 12:24:15 -0700 Subject: [PATCH 322/569] update docs in readme (#947) --- json_serializable/README.md | 38 ++++++++++++++++++------------------ json_serializable/doc/doc.md | 38 ++++++++++++++++++------------------ 2 files changed, 38 insertions(+), 38 deletions(-) diff --git a/json_serializable/README.md b/json_serializable/README.md index 371d7998c..a80cc24a0 100644 --- a/json_serializable/README.md +++ b/json_serializable/README.md @@ -106,25 +106,25 @@ is generated: | | | [JsonKey.toJson] | | | | [JsonKey.unknownEnumValue] | -[JsonSerializable.anyMap]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/anyMap.html -[JsonSerializable.checked]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/checked.html -[JsonSerializable.createFactory]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/createFactory.html -[JsonSerializable.createToJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/createToJson.html -[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html -[JsonSerializable.explicitToJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/explicitToJson.html -[JsonSerializable.fieldRename]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/fieldRename.html -[JsonSerializable.genericArgumentFactories]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/genericArgumentFactories.html -[JsonSerializable.ignoreUnannotated]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/ignoreUnannotated.html -[JsonSerializable.includeIfNull]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/includeIfNull.html -[JsonKey.includeIfNull]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/includeIfNull.html -[JsonKey.defaultValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/defaultValue.html -[JsonKey.disallowNullValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/disallowNullValue.html -[JsonKey.fromJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/fromJson.html -[JsonKey.ignore]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/ignore.html -[JsonKey.name]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/name.html -[JsonKey.required]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/required.html -[JsonKey.toJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/toJson.html -[JsonKey.unknownEnumValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/unknownEnumValue.html +[JsonSerializable.anyMap]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonSerializable/anyMap.html +[JsonSerializable.checked]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonSerializable/checked.html +[JsonSerializable.createFactory]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonSerializable/createFactory.html +[JsonSerializable.createToJson]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonSerializable/createToJson.html +[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html +[JsonSerializable.explicitToJson]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonSerializable/explicitToJson.html +[JsonSerializable.fieldRename]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonSerializable/fieldRename.html +[JsonSerializable.genericArgumentFactories]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonSerializable/genericArgumentFactories.html +[JsonSerializable.ignoreUnannotated]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonSerializable/ignoreUnannotated.html +[JsonSerializable.includeIfNull]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonSerializable/includeIfNull.html +[JsonKey.includeIfNull]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonKey/includeIfNull.html +[JsonKey.defaultValue]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonKey/defaultValue.html +[JsonKey.disallowNullValue]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonKey/disallowNullValue.html +[JsonKey.fromJson]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonKey/fromJson.html +[JsonKey.ignore]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonKey/ignore.html +[JsonKey.name]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonKey/name.html +[JsonKey.required]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonKey/required.html +[JsonKey.toJson]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonKey/toJson.html +[JsonKey.unknownEnumValue]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonKey/unknownEnumValue.html > Note: every `JsonSerializable` field is configurable via `build.yaml` – > see the table for the corresponding key. diff --git a/json_serializable/doc/doc.md b/json_serializable/doc/doc.md index 386068764..2e46bf966 100644 --- a/json_serializable/doc/doc.md +++ b/json_serializable/doc/doc.md @@ -19,22 +19,22 @@ | | | [JsonKey.toJson] | | | | [JsonKey.unknownEnumValue] | -[JsonSerializable.anyMap]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/anyMap.html -[JsonSerializable.checked]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/checked.html -[JsonSerializable.createFactory]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/createFactory.html -[JsonSerializable.createToJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/createToJson.html -[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html -[JsonSerializable.explicitToJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/explicitToJson.html -[JsonSerializable.fieldRename]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/fieldRename.html -[JsonSerializable.genericArgumentFactories]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/genericArgumentFactories.html -[JsonSerializable.ignoreUnannotated]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/ignoreUnannotated.html -[JsonSerializable.includeIfNull]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/includeIfNull.html -[JsonKey.includeIfNull]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/includeIfNull.html -[JsonKey.defaultValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/defaultValue.html -[JsonKey.disallowNullValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/disallowNullValue.html -[JsonKey.fromJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/fromJson.html -[JsonKey.ignore]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/ignore.html -[JsonKey.name]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/name.html -[JsonKey.required]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/required.html -[JsonKey.toJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/toJson.html -[JsonKey.unknownEnumValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/unknownEnumValue.html +[JsonSerializable.anyMap]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonSerializable/anyMap.html +[JsonSerializable.checked]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonSerializable/checked.html +[JsonSerializable.createFactory]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonSerializable/createFactory.html +[JsonSerializable.createToJson]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonSerializable/createToJson.html +[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html +[JsonSerializable.explicitToJson]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonSerializable/explicitToJson.html +[JsonSerializable.fieldRename]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonSerializable/fieldRename.html +[JsonSerializable.genericArgumentFactories]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonSerializable/genericArgumentFactories.html +[JsonSerializable.ignoreUnannotated]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonSerializable/ignoreUnannotated.html +[JsonSerializable.includeIfNull]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonSerializable/includeIfNull.html +[JsonKey.includeIfNull]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonKey/includeIfNull.html +[JsonKey.defaultValue]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonKey/defaultValue.html +[JsonKey.disallowNullValue]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonKey/disallowNullValue.html +[JsonKey.fromJson]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonKey/fromJson.html +[JsonKey.ignore]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonKey/ignore.html +[JsonKey.name]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonKey/name.html +[JsonKey.required]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonKey/required.html +[JsonKey.toJson]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonKey/toJson.html +[JsonKey.unknownEnumValue]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonKey/unknownEnumValue.html From 1069c2aed82011da12e0626b2fdeaff031209dc9 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Sun, 25 Jul 2021 21:24:17 -0700 Subject: [PATCH 323/569] update mono_repo Closes #950 --- .github/workflows/dart.yml | 22 +++++++++++----------- tool/ci.sh | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 9b2f7a62a..9e7ba0e3c 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -1,4 +1,4 @@ -# Created with package:mono_repo v5.0.0 +# Created with package:mono_repo v5.0.1 name: Dart CI on: push: @@ -27,13 +27,13 @@ jobs: restore-keys: | os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: dart-lang/setup-dart@v1.0 + - uses: dart-lang/setup-dart@v1.1 with: sdk: stable - id: checkout uses: actions/checkout@v2.3.4 - name: mono_repo self validate - run: dart pub global activate mono_repo 5.0.0 + run: dart pub global activate mono_repo 5.0.1 - name: mono_repo self validate run: dart pub global run mono_repo generate --validate job_002: @@ -50,7 +50,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted;dart:2.12.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: dart-lang/setup-dart@v1.0 + - uses: dart-lang/setup-dart@v1.1 with: sdk: "2.12.0" - id: checkout @@ -134,7 +134,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted;dart:dev os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: dart-lang/setup-dart@v1.0 + - uses: dart-lang/setup-dart@v1.1 with: sdk: dev - id: checkout @@ -218,7 +218,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted;dart:2.12.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: dart-lang/setup-dart@v1.0 + - uses: dart-lang/setup-dart@v1.1 with: sdk: "2.12.0" - id: checkout @@ -277,7 +277,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted;dart:2.12.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: dart-lang/setup-dart@v1.0 + - uses: dart-lang/setup-dart@v1.1 with: sdk: "2.12.0" - id: checkout @@ -309,7 +309,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted;dart:dev os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: dart-lang/setup-dart@v1.0 + - uses: dart-lang/setup-dart@v1.1 with: sdk: dev - id: checkout @@ -368,7 +368,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted;dart:dev os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: dart-lang/setup-dart@v1.0 + - uses: dart-lang/setup-dart@v1.1 with: sdk: dev - id: checkout @@ -400,7 +400,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted;dart:2.12.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: dart-lang/setup-dart@v1.0 + - uses: dart-lang/setup-dart@v1.1 with: sdk: "2.12.0" - id: checkout @@ -463,7 +463,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted;dart:dev os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: dart-lang/setup-dart@v1.0 + - uses: dart-lang/setup-dart@v1.1 with: sdk: dev - id: checkout diff --git a/tool/ci.sh b/tool/ci.sh index 3c31a5f16..d7fc69429 100755 --- a/tool/ci.sh +++ b/tool/ci.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Created with package:mono_repo v5.0.0 +# Created with package:mono_repo v5.0.1 # Support built in commands on windows out of the box. # When it is a flutter repo (check the pubspec.yaml for "sdk: flutter") From 0b3893216ec09a82f23c7e479184dd79c3c9e441 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 25 Jul 2021 21:25:02 -0700 Subject: [PATCH 324/569] Bump actions/setup-node from 2.2.0 to 2.3.0 (#951) Bumps [actions/setup-node](https://github.com/actions/setup-node) from 2.2.0 to 2.3.0. - [Release notes](https://github.com/actions/setup-node/releases) - [Commits](https://github.com/actions/setup-node/compare/v2.2.0...v2.3.0) --- updated-dependencies: - dependency-name: actions/setup-node dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/markdown_linter.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/markdown_linter.yml b/.github/workflows/markdown_linter.yml index eb17ad559..c1a025851 100644 --- a/.github/workflows/markdown_linter.yml +++ b/.github/workflows/markdown_linter.yml @@ -21,7 +21,7 @@ jobs: steps: - uses: actions/checkout@master - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v2.2.0 + uses: actions/setup-node@v2.3.0 with: node-version: ${{ matrix.node-version }} - name: Install dependencies From f1c04e26ce2323fd52d4be13014225e673eda46e Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Fri, 30 Jul 2021 13:31:33 -0700 Subject: [PATCH 325/569] Enable and fix a few more lints (#954) --- analysis_options.yaml | 5 ++++ example/lib/data.json | 26 ++++++++++++++++++- example/lib/example.g.dart | 3 +-- json_serializable/build.yaml | 5 ++++ json_serializable/example/example.g.dart | 2 ++ json_serializable/lib/src/helper_core.dart | 3 ++- json_serializable/lib/src/json_key_utils.dart | 3 ++- .../test/default_value/default_value.g.dart | 2 ++ .../default_value.g_any_map__checked.g.dart | 2 ++ .../implicit_default_value.g.dart | 2 ++ .../generic_argument_factories.g.dart | 2 ++ ...generic_argument_factories_nullable.g.dart | 2 ++ .../test/generic_files/generic_class.g.dart | 2 ++ .../test/integration/json_test_common.dart | 3 ++- .../test/integration/json_test_example.g.dart | 2 ++ .../json_test_example.g_any_map.g.dart | 2 ++ .../test/kitchen_sink/kitchen_sink.g.dart | 2 ++ .../kitchen_sink.g_any_map.g.dart | 2 ++ .../kitchen_sink.g_any_map__checked.g.dart | 2 ++ .../kitchen_sink.g_exclude_null.g.dart | 2 ++ .../kitchen_sink.g_explicit_to_json.g.dart | 2 ++ .../test/kitchen_sink/simple_object.g.dart | 2 ++ .../kitchen_sink/strict_keys_object.g.dart | 2 ++ .../test/literal/json_literal.g.dart | 2 ++ .../src/_json_serializable_test_input.dart | 2 +- .../test/supported_types/input.g.dart | 2 ++ .../supported_types/input.type_bigint.g.dart | 2 ++ .../supported_types/input.type_bool.g.dart | 2 ++ .../input.type_datetime.g.dart | 2 ++ .../supported_types/input.type_double.g.dart | 2 ++ .../input.type_duration.g.dart | 2 ++ .../input.type_enumtype.g.dart | 2 ++ .../supported_types/input.type_int.g.dart | 2 ++ .../input.type_iterable.g.dart | 2 ++ .../supported_types/input.type_list.g.dart | 2 ++ .../supported_types/input.type_map.g.dart | 2 ++ .../supported_types/input.type_num.g.dart | 2 ++ .../supported_types/input.type_object.g.dart | 2 ++ .../supported_types/input.type_set.g.dart | 2 ++ .../supported_types/input.type_string.g.dart | 2 ++ .../supported_types/input.type_uri.g.dart | 2 ++ json_serializable/test/test_utils.dart | 3 ++- 42 files changed, 111 insertions(+), 8 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index 3c9c88a16..e13ccf9ad 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -38,6 +38,7 @@ linter: - empty_catches - empty_constructor_bodies - empty_statements + - exhaustive_cases - file_names - hash_and_equals - implementation_imports @@ -46,6 +47,7 @@ linter: - join_return_with_assignment - library_names - library_prefixes + - lines_longer_than_80_chars - list_remove_unrelated_type - literal_only_boolean_expressions - missing_whitespace_between_adjacent_strings @@ -94,6 +96,7 @@ linter: - sort_pub_dependencies - test_types_in_equals - throw_in_finally + - type_annotate_public_apis - type_init_formals - unawaited_futures - unnecessary_brace_in_string_interps @@ -106,6 +109,8 @@ linter: - unnecessary_overrides - unnecessary_parenthesis - unnecessary_statements + # TODO: fix pkg:source_helper + #- unnecessary_string_escapes - unnecessary_string_interpolations - unnecessary_this - unrelated_type_equality_checks diff --git a/example/lib/data.json b/example/lib/data.json index 4e75e9dd0..5e85eb5ce 100644 --- a/example/lib/data.json +++ b/example/lib/data.json @@ -1 +1,25 @@ -{"glossary":{"title":"example glossary","GlossDiv":{"title":"S","GlossList":{"GlossEntry":{"ID":"SGML","SortAs":"SGML","GlossTerm":"Standard Generalized Markup Language","Acronym":"SGML","Abbrev":"ISO 8879:1986","GlossDef":{"para":"A meta-markup language, used to create markup languages such as DocBook.","GlossSeeAlso":["GML","XML"]},"GlossSee":"markup"}}}}} +{ + "glossary": { + "title": "example glossary", + "GlossDiv": { + "title": "S", + "GlossList": { + "GlossEntry": { + "ID": "SGML", + "SortAs": "SGML", + "GlossTerm": "Standard Generalized Markup Language", + "Acronym": "SGML", + "Abbrev": "ISO 8879:1986", + "GlossDef": { + "para": "A meta-markup language, used to create markup languages.", + "GlossSeeAlso": [ + "GML", + "XML" + ] + }, + "GlossSee": "markup" + } + } + } + } +} diff --git a/example/lib/example.g.dart b/example/lib/example.g.dart index 04ce2ac6a..40e7e4e9c 100644 --- a/example/lib/example.g.dart +++ b/example/lib/example.g.dart @@ -95,8 +95,7 @@ final _$glossaryDataJsonLiteral = { 'Acronym': 'SGML', 'Abbrev': 'ISO 8879:1986', 'GlossDef': { - 'para': - 'A meta-markup language, used to create markup languages such as DocBook.', + 'para': 'A meta-markup language, used to create markup languages.', 'GlossSeeAlso': ['GML', 'XML'] }, 'GlossSee': 'markup' diff --git a/json_serializable/build.yaml b/json_serializable/build.yaml index e1c82f75f..809fc74e8 100644 --- a/json_serializable/build.yaml +++ b/json_serializable/build.yaml @@ -2,6 +2,11 @@ targets: $default: builders: + source_gen|combining_builder: + options: + ignore_for_file: + - lines_longer_than_80_chars + json_serializable: generate_for: - example/* diff --git a/json_serializable/example/example.g.dart b/json_serializable/example/example.g.dart index 7f716df1a..0db7c1d08 100644 --- a/json_serializable/example/example.g.dart +++ b/json_serializable/example/example.g.dart @@ -1,5 +1,7 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: lines_longer_than_80_chars + part of 'example.dart'; // ************************************************************************** diff --git a/json_serializable/lib/src/helper_core.dart b/json_serializable/lib/src/helper_core.dart index 14694cee8..af29bb25c 100644 --- a/json_serializable/lib/src/helper_core.dart +++ b/json_serializable/lib/src/helper_core.dart @@ -66,7 +66,8 @@ InvalidGenerationSourceError createInvalidGenerationError( String? todo; if (error.type is TypeParameterType) { message = '$message because of type ' - '`${error.type.getDisplayString(withNullability: false)}` (type parameter)'; + '`${error.type.getDisplayString(withNullability: false)}` ' + '(type parameter)'; todo = ''' To support type parameters (generic types) you can: diff --git a/json_serializable/lib/src/json_key_utils.dart b/json_serializable/lib/src/json_key_utils.dart index 3ad264b2e..11ef9a037 100644 --- a/json_serializable/lib/src/json_key_utils.dart +++ b/json_serializable/lib/src/json_key_utils.dart @@ -158,7 +158,8 @@ KeyConfig _from(FieldElement element, ClassConfig classAnnotation) { final enumValueName = enumValueForDartObject( annotationValue.objectValue, enumValueNames, (n) => n); - return '${annotationValue.objectValue.type!.element!.name}.$enumValueName'; + return '${annotationValue.objectValue.type!.element!.name}' + '.$enumValueName'; } else { final defaultValueLiteral = annotationValue.isNull ? null diff --git a/json_serializable/test/default_value/default_value.g.dart b/json_serializable/test/default_value/default_value.g.dart index bd5997a00..a7388eb8a 100644 --- a/json_serializable/test/default_value/default_value.g.dart +++ b/json_serializable/test/default_value/default_value.g.dart @@ -1,5 +1,7 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: lines_longer_than_80_chars + part of 'default_value.dart'; // ************************************************************************** diff --git a/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart b/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart index 9030a7354..5181c11b3 100644 --- a/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart +++ b/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart @@ -1,5 +1,7 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: lines_longer_than_80_chars + part of 'default_value.g_any_map__checked.dart'; // ************************************************************************** diff --git a/json_serializable/test/default_value/implicit_default_value.g.dart b/json_serializable/test/default_value/implicit_default_value.g.dart index 75a26d064..fc355e089 100644 --- a/json_serializable/test/default_value/implicit_default_value.g.dart +++ b/json_serializable/test/default_value/implicit_default_value.g.dart @@ -1,5 +1,7 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: lines_longer_than_80_chars + part of 'implicit_default_value.dart'; // ************************************************************************** diff --git a/json_serializable/test/generic_files/generic_argument_factories.g.dart b/json_serializable/test/generic_files/generic_argument_factories.g.dart index 7d3a2fc5d..cc8c0428a 100644 --- a/json_serializable/test/generic_files/generic_argument_factories.g.dart +++ b/json_serializable/test/generic_files/generic_argument_factories.g.dart @@ -1,5 +1,7 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: lines_longer_than_80_chars + part of 'generic_argument_factories.dart'; // ************************************************************************** diff --git a/json_serializable/test/generic_files/generic_argument_factories_nullable.g.dart b/json_serializable/test/generic_files/generic_argument_factories_nullable.g.dart index 2d73473cd..115d1ee32 100644 --- a/json_serializable/test/generic_files/generic_argument_factories_nullable.g.dart +++ b/json_serializable/test/generic_files/generic_argument_factories_nullable.g.dart @@ -1,6 +1,8 @@ // GENERATED CODE - DO NOT MODIFY BY HAND // @dart=2.12 +// ignore_for_file: lines_longer_than_80_chars + part of 'generic_argument_factories_nullable.dart'; // ************************************************************************** diff --git a/json_serializable/test/generic_files/generic_class.g.dart b/json_serializable/test/generic_files/generic_class.g.dart index fdec43703..a3810757f 100644 --- a/json_serializable/test/generic_files/generic_class.g.dart +++ b/json_serializable/test/generic_files/generic_class.g.dart @@ -1,5 +1,7 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: lines_longer_than_80_chars + part of 'generic_class.dart'; // ************************************************************************** diff --git a/json_serializable/test/integration/json_test_common.dart b/json_serializable/test/integration/json_test_common.dart index 6cd110a4d..d878e9f1b 100644 --- a/json_serializable/test/integration/json_test_common.dart +++ b/json_serializable/test/integration/json_test_common.dart @@ -42,7 +42,8 @@ DateTime? dateTimeFromEpochUs(int? us) => int? dateTimeToEpochUs(DateTime? dateTime) => dateTime?.microsecondsSinceEpoch; -bool deepEquals(a, b) => const DeepCollectionEquality().equals(a, b); +bool deepEquals(dynamic a, dynamic b) => + const DeepCollectionEquality().equals(a, b); class Platform { final String description; diff --git a/json_serializable/test/integration/json_test_example.g.dart b/json_serializable/test/integration/json_test_example.g.dart index 9565dc4ec..25edb0d43 100644 --- a/json_serializable/test/integration/json_test_example.g.dart +++ b/json_serializable/test/integration/json_test_example.g.dart @@ -1,5 +1,7 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: lines_longer_than_80_chars + part of 'json_test_example.dart'; // ************************************************************************** diff --git a/json_serializable/test/integration/json_test_example.g_any_map.g.dart b/json_serializable/test/integration/json_test_example.g_any_map.g.dart index 464d6b04a..c79a9752d 100644 --- a/json_serializable/test/integration/json_test_example.g_any_map.g.dart +++ b/json_serializable/test/integration/json_test_example.g_any_map.g.dart @@ -1,5 +1,7 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: lines_longer_than_80_chars + part of 'json_test_example.g_any_map.dart'; // ************************************************************************** diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g.dart index 6806d3a28..a469e8842 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g.dart @@ -1,5 +1,7 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: lines_longer_than_80_chars + part of 'kitchen_sink.dart'; // ************************************************************************** diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart index 6e23c1532..f2e8da4c3 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart @@ -1,5 +1,7 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: lines_longer_than_80_chars + part of 'kitchen_sink.g_any_map.dart'; // ************************************************************************** diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.g.dart index 8a8e80f7e..056a8cd61 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.g.dart @@ -1,5 +1,7 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: lines_longer_than_80_chars + part of 'kitchen_sink.g_any_map__checked.dart'; // ************************************************************************** diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart index b48ce597c..b0866ea2c 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart @@ -1,5 +1,7 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: lines_longer_than_80_chars + part of 'kitchen_sink.g_exclude_null.dart'; // ************************************************************************** diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart index 1a01f85d6..18ad9cb04 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart @@ -1,5 +1,7 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: lines_longer_than_80_chars + part of 'kitchen_sink.g_explicit_to_json.dart'; // ************************************************************************** diff --git a/json_serializable/test/kitchen_sink/simple_object.g.dart b/json_serializable/test/kitchen_sink/simple_object.g.dart index 0102f33ef..30c82ebfe 100644 --- a/json_serializable/test/kitchen_sink/simple_object.g.dart +++ b/json_serializable/test/kitchen_sink/simple_object.g.dart @@ -1,5 +1,7 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: lines_longer_than_80_chars + part of 'simple_object.dart'; // ************************************************************************** diff --git a/json_serializable/test/kitchen_sink/strict_keys_object.g.dart b/json_serializable/test/kitchen_sink/strict_keys_object.g.dart index 081dff4cf..e112c1444 100644 --- a/json_serializable/test/kitchen_sink/strict_keys_object.g.dart +++ b/json_serializable/test/kitchen_sink/strict_keys_object.g.dart @@ -1,5 +1,7 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: lines_longer_than_80_chars + part of 'strict_keys_object.dart'; // ************************************************************************** diff --git a/json_serializable/test/literal/json_literal.g.dart b/json_serializable/test/literal/json_literal.g.dart index 5ffcbe848..30c865127 100644 --- a/json_serializable/test/literal/json_literal.g.dart +++ b/json_serializable/test/literal/json_literal.g.dart @@ -1,5 +1,7 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: lines_longer_than_80_chars + part of 'json_literal.dart'; // ************************************************************************** diff --git a/json_serializable/test/src/_json_serializable_test_input.dart b/json_serializable/test/src/_json_serializable_test_input.dart index 816f20561..4899478c2 100644 --- a/json_serializable/test/src/_json_serializable_test_input.dart +++ b/json_serializable/test/src/_json_serializable_test_input.dart @@ -79,7 +79,7 @@ class GeneralTestClass1 { late DateTime dateOfBirth; dynamic dynamicType; - //ignore: prefer_typing_uninitialized_variables + //ignore: prefer_typing_uninitialized_variables,type_annotate_public_apis var varType; late List listOfInts; } diff --git a/json_serializable/test/supported_types/input.g.dart b/json_serializable/test/supported_types/input.g.dart index e4426eba6..619612027 100644 --- a/json_serializable/test/supported_types/input.g.dart +++ b/json_serializable/test/supported_types/input.g.dart @@ -1,5 +1,7 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: lines_longer_than_80_chars + part of 'input.dart'; // ************************************************************************** diff --git a/json_serializable/test/supported_types/input.type_bigint.g.dart b/json_serializable/test/supported_types/input.type_bigint.g.dart index 82233d66a..16bb34ed8 100644 --- a/json_serializable/test/supported_types/input.type_bigint.g.dart +++ b/json_serializable/test/supported_types/input.type_bigint.g.dart @@ -1,5 +1,7 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: lines_longer_than_80_chars + part of 'input.type_bigint.dart'; // ************************************************************************** diff --git a/json_serializable/test/supported_types/input.type_bool.g.dart b/json_serializable/test/supported_types/input.type_bool.g.dart index 99c54e525..9138ae273 100644 --- a/json_serializable/test/supported_types/input.type_bool.g.dart +++ b/json_serializable/test/supported_types/input.type_bool.g.dart @@ -1,5 +1,7 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: lines_longer_than_80_chars + part of 'input.type_bool.dart'; // ************************************************************************** diff --git a/json_serializable/test/supported_types/input.type_datetime.g.dart b/json_serializable/test/supported_types/input.type_datetime.g.dart index 38ca772ab..2e2b0b6a0 100644 --- a/json_serializable/test/supported_types/input.type_datetime.g.dart +++ b/json_serializable/test/supported_types/input.type_datetime.g.dart @@ -1,5 +1,7 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: lines_longer_than_80_chars + part of 'input.type_datetime.dart'; // ************************************************************************** diff --git a/json_serializable/test/supported_types/input.type_double.g.dart b/json_serializable/test/supported_types/input.type_double.g.dart index bc7e07937..0f7e12fdc 100644 --- a/json_serializable/test/supported_types/input.type_double.g.dart +++ b/json_serializable/test/supported_types/input.type_double.g.dart @@ -1,5 +1,7 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: lines_longer_than_80_chars + part of 'input.type_double.dart'; // ************************************************************************** diff --git a/json_serializable/test/supported_types/input.type_duration.g.dart b/json_serializable/test/supported_types/input.type_duration.g.dart index 601925416..b33f0e19f 100644 --- a/json_serializable/test/supported_types/input.type_duration.g.dart +++ b/json_serializable/test/supported_types/input.type_duration.g.dart @@ -1,5 +1,7 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: lines_longer_than_80_chars + part of 'input.type_duration.dart'; // ************************************************************************** diff --git a/json_serializable/test/supported_types/input.type_enumtype.g.dart b/json_serializable/test/supported_types/input.type_enumtype.g.dart index 1b54f3fd8..a896a8fc7 100644 --- a/json_serializable/test/supported_types/input.type_enumtype.g.dart +++ b/json_serializable/test/supported_types/input.type_enumtype.g.dart @@ -1,5 +1,7 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: lines_longer_than_80_chars + part of 'input.type_enumtype.dart'; // ************************************************************************** diff --git a/json_serializable/test/supported_types/input.type_int.g.dart b/json_serializable/test/supported_types/input.type_int.g.dart index 1df77a934..3e6b3aa75 100644 --- a/json_serializable/test/supported_types/input.type_int.g.dart +++ b/json_serializable/test/supported_types/input.type_int.g.dart @@ -1,5 +1,7 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: lines_longer_than_80_chars + part of 'input.type_int.dart'; // ************************************************************************** diff --git a/json_serializable/test/supported_types/input.type_iterable.g.dart b/json_serializable/test/supported_types/input.type_iterable.g.dart index be6a7a250..3d150a3d9 100644 --- a/json_serializable/test/supported_types/input.type_iterable.g.dart +++ b/json_serializable/test/supported_types/input.type_iterable.g.dart @@ -1,5 +1,7 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: lines_longer_than_80_chars + part of 'input.type_iterable.dart'; // ************************************************************************** diff --git a/json_serializable/test/supported_types/input.type_list.g.dart b/json_serializable/test/supported_types/input.type_list.g.dart index a52bc9cbf..960780acc 100644 --- a/json_serializable/test/supported_types/input.type_list.g.dart +++ b/json_serializable/test/supported_types/input.type_list.g.dart @@ -1,5 +1,7 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: lines_longer_than_80_chars + part of 'input.type_list.dart'; // ************************************************************************** diff --git a/json_serializable/test/supported_types/input.type_map.g.dart b/json_serializable/test/supported_types/input.type_map.g.dart index 93508cc50..6bc7c3e0f 100644 --- a/json_serializable/test/supported_types/input.type_map.g.dart +++ b/json_serializable/test/supported_types/input.type_map.g.dart @@ -1,5 +1,7 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: lines_longer_than_80_chars + part of 'input.type_map.dart'; // ************************************************************************** diff --git a/json_serializable/test/supported_types/input.type_num.g.dart b/json_serializable/test/supported_types/input.type_num.g.dart index c42af8030..e996e5744 100644 --- a/json_serializable/test/supported_types/input.type_num.g.dart +++ b/json_serializable/test/supported_types/input.type_num.g.dart @@ -1,5 +1,7 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: lines_longer_than_80_chars + part of 'input.type_num.dart'; // ************************************************************************** diff --git a/json_serializable/test/supported_types/input.type_object.g.dart b/json_serializable/test/supported_types/input.type_object.g.dart index 0254c5908..4ac5cff7b 100644 --- a/json_serializable/test/supported_types/input.type_object.g.dart +++ b/json_serializable/test/supported_types/input.type_object.g.dart @@ -1,5 +1,7 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: lines_longer_than_80_chars + part of 'input.type_object.dart'; // ************************************************************************** diff --git a/json_serializable/test/supported_types/input.type_set.g.dart b/json_serializable/test/supported_types/input.type_set.g.dart index 966b8f7db..7cb3f7976 100644 --- a/json_serializable/test/supported_types/input.type_set.g.dart +++ b/json_serializable/test/supported_types/input.type_set.g.dart @@ -1,5 +1,7 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: lines_longer_than_80_chars + part of 'input.type_set.dart'; // ************************************************************************** diff --git a/json_serializable/test/supported_types/input.type_string.g.dart b/json_serializable/test/supported_types/input.type_string.g.dart index 291ec405a..648df335a 100644 --- a/json_serializable/test/supported_types/input.type_string.g.dart +++ b/json_serializable/test/supported_types/input.type_string.g.dart @@ -1,5 +1,7 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: lines_longer_than_80_chars + part of 'input.type_string.dart'; // ************************************************************************** diff --git a/json_serializable/test/supported_types/input.type_uri.g.dart b/json_serializable/test/supported_types/input.type_uri.g.dart index 82452c83b..9634819b7 100644 --- a/json_serializable/test/supported_types/input.type_uri.g.dart +++ b/json_serializable/test/supported_types/input.type_uri.g.dart @@ -1,5 +1,7 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: lines_longer_than_80_chars + part of 'input.type_uri.dart'; // ************************************************************************** diff --git a/json_serializable/test/test_utils.dart b/json_serializable/test/test_utils.dart index 6bb67f98a..c47a46d7b 100644 --- a/json_serializable/test/test_utils.dart +++ b/json_serializable/test/test_utils.dart @@ -36,7 +36,8 @@ String loudEncode(Object? object) { while (error is JsonUnsupportedObjectError) { print( - '(${count++}) $error ${error.unsupportedObject} (${error.unsupportedObject.runtimeType}) !!!', + '(${count++}) $error ${error.unsupportedObject} ' + '(${error.unsupportedObject.runtimeType}) !!!', ); print(Trace.from(error.stackTrace!).terse); error = error.cause; From cb1e5b5c8d82afcffdd3306cd6a2a369c836cc33 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Fri, 30 Jul 2021 13:51:52 -0700 Subject: [PATCH 326/569] Require the latest pkg:source_helper (#955) Enable fixed lint Regenerate test code --- analysis_options.yaml | 3 +- json_serializable/CHANGELOG.md | 4 + json_serializable/pubspec.yaml | 4 +- .../test/literal/json_literal.g.dart | 144 +++++++++--------- 4 files changed, 79 insertions(+), 76 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index e13ccf9ad..611323ece 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -109,8 +109,7 @@ linter: - unnecessary_overrides - unnecessary_parenthesis - unnecessary_statements - # TODO: fix pkg:source_helper - #- unnecessary_string_escapes + - unnecessary_string_escapes - unnecessary_string_interpolations - unnecessary_this - unrelated_type_equality_checks diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 37851c134..944ebc7a9 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,7 @@ +## 5.0.1-dev + +- Require the latest `package:source_helper`. + ## 5.0.0 - Use the default value for optional constructor parameters if diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 08892d461..892a48c13 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 5.0.0 +version: 5.0.1-dev description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. @@ -19,7 +19,7 @@ dependencies: meta: ^1.3.0 path: ^1.8.0 source_gen: ^1.0.0 - source_helper: ^1.1.0 + source_helper: ^1.2.1 dev_dependencies: build_runner: ^2.0.0 diff --git a/json_serializable/test/literal/json_literal.g.dart b/json_serializable/test/literal/json_literal.g.dart index 30c865127..87f89f479 100644 --- a/json_serializable/test/literal/json_literal.g.dart +++ b/json_serializable/test/literal/json_literal.g.dart @@ -21,19 +21,19 @@ final _$dataJsonLiteral = [ 'simple string', "'string with single quotes'", '"string with double quotes"', - '\'With singles and \"doubles\"\'', + '\'With singles and "doubles"\'', r'dollar $igns', r"'single quotes and dollor $ig$'", r"${'nice!'}", '""hello""', r'""$double quotes and dollar signs""', - '\$scary with \'single quotes\' and triple-doubles \"\"\"oh no!', + '\$scary with \'single quotes\' and triple-doubles """oh no!', 'Dollar signs: \$ vs \\\$ vs \\\\\$', 'Slashes \\nice slash\\', 'slashes \\ and dollars \$ with white \n space', "'''triple quoted strings should be\nfine!'''", '"""as with triple-double-quotes"""', - '\"\"\"as with triple-double-quotes even when \'mixed\'\"\"\"', + '"""as with triple-double-quotes even when \'mixed\'"""', null, true, false, @@ -64,19 +64,19 @@ const _$asConstJsonLiteral = [ 'simple string', "'string with single quotes'", '"string with double quotes"', - '\'With singles and \"doubles\"\'', + '\'With singles and "doubles"\'', r'dollar $igns', r"'single quotes and dollor $ig$'", r"${'nice!'}", '""hello""', r'""$double quotes and dollar signs""', - '\$scary with \'single quotes\' and triple-doubles \"\"\"oh no!', + '\$scary with \'single quotes\' and triple-doubles """oh no!', 'Dollar signs: \$ vs \\\$ vs \\\\\$', 'Slashes \\nice slash\\', 'slashes \\ and dollars \$ with white \n space', "'''triple quoted strings should be\nfine!'''", '"""as with triple-double-quotes"""', - '\"\"\"as with triple-double-quotes even when \'mixed\'\"\"\"', + '"""as with triple-double-quotes even when \'mixed\'"""', null, true, false, @@ -212,9 +212,9 @@ const _$naughtyStringsJsonLiteral = [ '"', "''", '""', - '\'\"\'', - '\"\'\'\'\'\"\'\"', - '\"\'\"\'\"\'\'\'\'\"', + '\'"\'', + '"\'\'\'\'"\'"', + '"\'"\'"\'\'\'\'"', '', '', '', @@ -320,8 +320,8 @@ const _$naughtyStringsJsonLiteral = [ 'javascript:alert(1);', 'javascript:alert(1);', 'javascript:alert(1);', - '\'`\"><\\x3Cscript>javascript:alert(1)', - '\'`\"><\\x00script>javascript:alert(1)', + '\'`"><\\x3Cscript>javascript:alert(1)', + '\'`"><\\x00script>javascript:alert(1)', 'ABC
DEF', 'ABC
DEF', 'ABC
DEF', @@ -406,53 +406,53 @@ const _$naughtyStringsJsonLiteral = [ 'test', 'test', 'test', - '`\"\'>', - '`\"\'>', - '`\"\'>', - '`\"\'>', - '`\"\'>', - '`\"\'>', - '`\"\'>', - '`\"\'>', - '`\"\'>', - '`\"\'>', - '\"`\'>', - '\"`\'>', - '\"`\'>', - '\"`\'>', - '\"`\'>', - '\"`\'>', - '\"`\'>', - '\"`\'>', - '\"`\'>', - '\"`\'>', - '\"`\'>', - '\"`\'>', - '\"`\'>', - '\"`\'>', - '\"`\'>', - '\"`\'>', - '\"`\'>', - '\"`\'>', - '\"`\'>', - '\"`\'>', - '\"`\'>', - '\"`\'>', - '\"`\'>', - '\"`\'>', - '\"`\'>', - '\"`\'>', - '\"`\'>', - '\"`\'>', - '\"`\'>', - '\"`\'>', - '\"`\'>', - '\"`\'>', - '\"`\'>', - '\"`\'>', - '\"`\'>', - '\"`\'>', - '\"`\'>', + '`"\'>', + '`"\'>', + '`"\'>', + '`"\'>', + '`"\'>', + '`"\'>', + '`"\'>', + '`"\'>', + '`"\'>', + '`"\'>', + '"`\'>', + '"`\'>', + '"`\'>', + '"`\'>', + '"`\'>', + '"`\'>', + '"`\'>', + '"`\'>', + '"`\'>', + '"`\'>', + '"`\'>', + '"`\'>', + '"`\'>', + '"`\'>', + '"`\'>', + '"`\'>', + '"`\'>', + '"`\'>', + '"`\'>', + '"`\'>', + '"`\'>', + '"`\'>', + '"`\'>', + '"`\'>', + '"`\'>', + '"`\'>', + '"`\'>', + '"`\'>', + '"`\'>', + '"`\'>', + '"`\'>', + '"`\'>', + '"`\'>', + '"`\'>', + '"`\'>', + '"`\'>', + '"`\'>', '', '', '', @@ -489,7 +489,7 @@ const _$naughtyStringsJsonLiteral = [ '', 'XXX', '', - '', + '', '', '<a href=http://foo.bar/#x=`y></a><img alt="`><img src=x:x onerror=javascript:alert(1)></a>">', '<!--[if]><script>javascript:alert(1)</script -->', @@ -498,27 +498,27 @@ const _$naughtyStringsJsonLiteral = [ '<script src="\\\\%(jscript)s"></script>', '<IMG """><SCRIPT>alert("XSS")</SCRIPT>">', '<IMG SRC=javascript:alert(String.fromCharCode(88,83,83))>', - '<IMG SRC=# onmouseover=\"alert(\'xxs\')\">', - '<IMG SRC= onmouseover=\"alert(\'xxs\')\">', - '<IMG onmouseover=\"alert(\'xxs\')\">', + '<IMG SRC=# onmouseover="alert(\'xxs\')">', + '<IMG SRC= onmouseover="alert(\'xxs\')">', + '<IMG onmouseover="alert(\'xxs\')">', '<IMG SRC=javascript:alert('XSS')>', '<IMG SRC=javascript:alert('XSS')>', '<IMG SRC=javascript:alert('XSS')>', - '<IMG SRC=\"jav ascript:alert(\'XSS\');\">', - '<IMG SRC=\"jav ascript:alert(\'XSS\');\">', - '<IMG SRC=\"jav ascript:alert(\'XSS\');\">', - '<IMG SRC=\"jav ascript:alert(\'XSS\');\">', - 'perl -e \'print \"<IMG SRC=java\\0script:alert(\\\"XSS\\\")>\";\' > out', - '<IMG SRC=\"  javascript:alert(\'XSS\');\">', + '<IMG SRC="jav ascript:alert(\'XSS\');">', + '<IMG SRC="jav ascript:alert(\'XSS\');">', + '<IMG SRC="jav ascript:alert(\'XSS\');">', + '<IMG SRC="jav ascript:alert(\'XSS\');">', + 'perl -e \'print "<IMG SRC=java\\0script:alert(\\"XSS\\")>";\' > out', + '<IMG SRC="  javascript:alert(\'XSS\');">', '<SCRIPT/XSS SRC="http://ha.ckers.org/xss.js"></SCRIPT>', - '<BODY onload!#\$%&()*~+-_.,:;?@[/|\\]^`=alert(\"XSS\")>', + '<BODY onload!#\$%&()*~+-_.,:;?@[/|\\]^`=alert("XSS")>', '<SCRIPT/SRC="http://ha.ckers.org/xss.js"></SCRIPT>', '<<SCRIPT>alert("XSS");//<</SCRIPT>', '<SCRIPT SRC=http://ha.ckers.org/xss.js?< B >', '<SCRIPT SRC=//ha.ckers.org/.j>', - '<IMG SRC=\"javascript:alert(\'XSS\')\"', + '<IMG SRC="javascript:alert(\'XSS\')"', '<iframe src=http://ha.ckers.org/scriptlet.html <', - '\\\";alert(\'XSS\');//', + '\\";alert(\'XSS\');//', '<u oncopy=alert()> Copy me</u>', '<i onwheel=alert(1)> Scroll over me </i>', '<plaintext>', @@ -540,7 +540,7 @@ const _$naughtyStringsJsonLiteral = [ '`touch /tmp/blns.fail`', r'$(touch /tmp/blns.fail)', '@{[system "touch /tmp/blns.fail"]}', - 'eval(\"puts \'hello world\'\")', + 'eval("puts \'hello world\'")', 'System("ls -al /")', '`ls -al /`', 'Kernel.exec("ls -al /")', From 8cd9836a9d594142b719cadfd3b125a2c4ea3be1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 9 Aug 2021 07:49:01 -0700 Subject: [PATCH 327/569] Bump actions/setup-node from 2.3.0 to 2.4.0 (#961) Bumps [actions/setup-node](https://github.com/actions/setup-node) from 2.3.0 to 2.4.0. - [Release notes](https://github.com/actions/setup-node/releases) - [Commits](https://github.com/actions/setup-node/compare/v2.3.0...v2.4.0) --- updated-dependencies: - dependency-name: actions/setup-node dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/markdown_linter.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/markdown_linter.yml b/.github/workflows/markdown_linter.yml index c1a025851..50a277651 100644 --- a/.github/workflows/markdown_linter.yml +++ b/.github/workflows/markdown_linter.yml @@ -21,7 +21,7 @@ jobs: steps: - uses: actions/checkout@master - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v2.3.0 + uses: actions/setup-node@v2.4.0 with: node-version: ${{ matrix.node-version }} - name: Install dependencies From 162f935f6442e06ed0ff88b4f95970e631732696 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 2 Sep 2021 14:49:01 -0700 Subject: [PATCH 328/569] Bump dart-lang/setup-dart from 1.1 to 1.2 (#958) Bumps [dart-lang/setup-dart](https://github.com/dart-lang/setup-dart) from 1.1 to 1.2. - [Release notes](https://github.com/dart-lang/setup-dart/releases) - [Changelog](https://github.com/dart-lang/setup-dart/blob/main/CHANGELOG.md) - [Commits](https://github.com/dart-lang/setup-dart/compare/v1.1...v1.2) --- updated-dependencies: - dependency-name: dart-lang/setup-dart dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/dart.yml | 22 +++++++++++----------- tool/ci.sh | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 9e7ba0e3c..c41cd1f22 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -1,4 +1,4 @@ -# Created with package:mono_repo v5.0.1 +# Created with package:mono_repo v5.0.2 name: Dart CI on: push: @@ -27,13 +27,13 @@ jobs: restore-keys: | os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: dart-lang/setup-dart@v1.1 + - uses: dart-lang/setup-dart@v1.2 with: sdk: stable - id: checkout uses: actions/checkout@v2.3.4 - name: mono_repo self validate - run: dart pub global activate mono_repo 5.0.1 + run: dart pub global activate mono_repo 5.0.2 - name: mono_repo self validate run: dart pub global run mono_repo generate --validate job_002: @@ -50,7 +50,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted;dart:2.12.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: dart-lang/setup-dart@v1.1 + - uses: dart-lang/setup-dart@v1.2 with: sdk: "2.12.0" - id: checkout @@ -134,7 +134,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted;dart:dev os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: dart-lang/setup-dart@v1.1 + - uses: dart-lang/setup-dart@v1.2 with: sdk: dev - id: checkout @@ -218,7 +218,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted;dart:2.12.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: dart-lang/setup-dart@v1.1 + - uses: dart-lang/setup-dart@v1.2 with: sdk: "2.12.0" - id: checkout @@ -277,7 +277,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted;dart:2.12.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: dart-lang/setup-dart@v1.1 + - uses: dart-lang/setup-dart@v1.2 with: sdk: "2.12.0" - id: checkout @@ -309,7 +309,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted;dart:dev os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: dart-lang/setup-dart@v1.1 + - uses: dart-lang/setup-dart@v1.2 with: sdk: dev - id: checkout @@ -368,7 +368,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted;dart:dev os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: dart-lang/setup-dart@v1.1 + - uses: dart-lang/setup-dart@v1.2 with: sdk: dev - id: checkout @@ -400,7 +400,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted;dart:2.12.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: dart-lang/setup-dart@v1.1 + - uses: dart-lang/setup-dart@v1.2 with: sdk: "2.12.0" - id: checkout @@ -463,7 +463,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted;dart:dev os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: dart-lang/setup-dart@v1.1 + - uses: dart-lang/setup-dart@v1.2 with: sdk: dev - id: checkout diff --git a/tool/ci.sh b/tool/ci.sh index d7fc69429..47e488070 100755 --- a/tool/ci.sh +++ b/tool/ci.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Created with package:mono_repo v5.0.1 +# Created with package:mono_repo v5.0.2 # Support built in commands on windows out of the box. # When it is a flutter repo (check the pubspec.yaml for "sdk: flutter") From cccbf7251045c8cdc1370e03c4a6fb8e3426df13 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Fri, 3 Sep 2021 08:54:30 -0700 Subject: [PATCH 329/569] Correctly handle nullable custom objects within Iterable and Map (#971) Fixes https://github.com/google/json_serializable.dart/issues/956 --- json_serializable/CHANGELOG.md | 3 +- json_serializable/lib/src/decode_helper.dart | 26 ++++++---------- .../lib/src/default_container.dart | 10 +++---- .../lib/src/type_helper_ctx.dart | 30 ++++++++++++------- json_serializable/pubspec.yaml | 2 +- .../test/kitchen_sink/kitchen_sink.dart | 2 ++ .../test/kitchen_sink/kitchen_sink.g.dart | 16 ++++++++++ .../kitchen_sink/kitchen_sink.g_any_map.dart | 2 ++ .../kitchen_sink.g_any_map.g.dart | 10 +++++++ .../kitchen_sink.g_any_map__checked.dart | 2 ++ .../kitchen_sink.g_any_map__checked.g.dart | 13 ++++++++ .../kitchen_sink.g_exclude_null.dart | 2 ++ .../kitchen_sink.g_exclude_null.g.dart | 16 ++++++++++ .../kitchen_sink.g_explicit_to_json.dart | 2 ++ .../kitchen_sink.g_explicit_to_json.g.dart | 18 +++++++++++ .../kitchen_sink/kitchen_sink_interface.dart | 8 +++++ .../test/kitchen_sink/kitchen_sink_test.dart | 4 +++ .../kitchen_sink_test_shared.dart | 12 ++++++++ 18 files changed, 142 insertions(+), 36 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 944ebc7a9..e790d65e0 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,5 +1,6 @@ -## 5.0.1-dev +## 5.1.0-dev +- Correctly handle nullable custom objects within `Iterable` and `Map`. - Require the latest `package:source_helper`. ## 5.0.0 diff --git a/json_serializable/lib/src/decode_helper.dart b/json_serializable/lib/src/decode_helper.dart index 9bcc0acb2..d5c6439d5 100644 --- a/json_serializable/lib/src/decode_helper.dart +++ b/json_serializable/lib/src/decode_helper.dart @@ -8,7 +8,6 @@ import 'package:build/build.dart'; import 'package:source_gen/source_gen.dart'; import 'package:source_helper/source_helper.dart'; -import 'default_container.dart'; import 'helper_core.dart'; import 'json_literal_generator.dart'; import 'type_helpers/generic_factory_helper.dart'; @@ -192,21 +191,14 @@ abstract class DecodeHelper implements HelperCore { final contextHelper = getHelperContext(field); final jsonKey = jsonKeyFor(field); final defaultValue = jsonKey.defaultValue; - final defaultProvided = defaultValue != null; - - String deserialize(String expression) { - final value = contextHelper.deserialize( - targetType, - expression, - defaultProvided: defaultProvided, - )!; - - return DefaultContainer.encode( - value, - nullable: targetType.isNullableType, - defaultValue: defaultValue, - ); - } + + String deserialize(String expression) => contextHelper + .deserialize( + targetType, + expression, + defaultValue: defaultValue, + ) + .toString(); String value; try { @@ -227,7 +219,7 @@ abstract class DecodeHelper implements HelperCore { throw createInvalidGenerationError('fromJson', field, e); } - if (defaultProvided) { + if (defaultValue != null) { if (jsonKey.disallowNullValue && jsonKey.required) { log.warning('The `defaultValue` on field `${field.name}` will have no ' 'effect because both `disallowNullValue` and `required` are set to ' diff --git a/json_serializable/lib/src/default_container.dart b/json_serializable/lib/src/default_container.dart index 23f90cab9..752aa2bb5 100644 --- a/json_serializable/lib/src/default_container.dart +++ b/json_serializable/lib/src/default_container.dart @@ -13,7 +13,7 @@ class DefaultContainer { DefaultContainer(this.expression, this.output); - static String encode( + static Object deserialize( Object value, { bool nullable = false, String? defaultValue, @@ -33,14 +33,12 @@ class DefaultContainer { return ifNullOrElse(value.expression, defaultValue, value.toString()); } - var result = value.toString(); - if (defaultValue != null) { - result = '$result ?? $defaultValue'; + value = '$value ?? $defaultValue'; } - return result; + return value; } @override - String toString() => encode(this); + String toString() => deserialize(this).toString(); } diff --git a/json_serializable/lib/src/type_helper_ctx.dart b/json_serializable/lib/src/type_helper_ctx.dart index be324c4d0..c8016ba2b 100644 --- a/json_serializable/lib/src/type_helper_ctx.dart +++ b/json_serializable/lib/src/type_helper_ctx.dart @@ -7,6 +7,7 @@ import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/type.dart'; import 'package:source_helper/source_helper.dart'; +import 'default_container.dart'; import 'helper_core.dart'; import 'type_helper.dart'; import 'type_helpers/config_types.dart'; @@ -54,21 +55,28 @@ class TypeHelperCtx ); @override - Object? deserialize( + Object deserialize( DartType targetType, String expression, { - bool defaultProvided = false, - }) => - _run( + String? defaultValue, + }) { + final value = _run( + targetType, + expression, + (TypeHelper th) => th.deserialize( targetType, expression, - (TypeHelper th) => th.deserialize( - targetType, - expression, - this, - defaultProvided, - ), - ); + this, + defaultValue != null, + ), + ); + + return DefaultContainer.deserialize( + value, + nullable: targetType.isNullableType, + defaultValue: defaultValue, + ); + } Object _run( DartType targetType, diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 892a48c13..e8bcd232e 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 5.0.1-dev +version: 5.1.0-dev description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.dart b/json_serializable/test/kitchen_sink/kitchen_sink.dart index d846eee3d..7456234f7 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.dart @@ -138,11 +138,13 @@ class KitchenSink implements k.KitchenSink { List<Object> objectList = _defaultList(); List<int> intList = _defaultList(); List<DateTime> dateTimeList = _defaultList(); + List<SimpleObject?> nullableSimpleObjectList = _defaultList(); Map map = _defaultMap(); Map<String, String> stringStringMap = _defaultMap(); Map<dynamic, int> dynamicIntMap = _defaultMap(); Map<Object, DateTime> objectDateTimeMap = _defaultMap(); + Map<String, SimpleObject?> nullableSimpleObjectMap = _defaultMap(); List<Map<String, Map<String, List<List<DateTime>?>?>?>?> crazyComplex = _defaultList(); diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g.dart index a469e8842..0b51b3fc7 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g.dart @@ -41,6 +41,12 @@ KitchenSink _$KitchenSinkFromJson(Map<String, dynamic> json) => KitchenSink( ..dateTimeList = (json['dateTimeList'] as List<dynamic>) .map((e) => DateTime.parse(e as String)) .toList() + ..nullableSimpleObjectList = + (json['nullableSimpleObjectList'] as List<dynamic>) + .map((e) => e == null + ? null + : SimpleObject.fromJson(e as Map<String, dynamic>)) + .toList() ..map = json['map'] as Map<String, dynamic> ..stringStringMap = Map<String, String>.from(json['stringStringMap'] as Map) @@ -49,6 +55,14 @@ KitchenSink _$KitchenSinkFromJson(Map<String, dynamic> json) => KitchenSink( (json['objectDateTimeMap'] as Map<String, dynamic>).map( (k, e) => MapEntry(k, DateTime.parse(e as String)), ) + ..nullableSimpleObjectMap = + (json['nullableSimpleObjectMap'] as Map<String, dynamic>).map( + (k, e) => MapEntry( + k, + e == null + ? null + : SimpleObject.fromJson(e as Map<String, dynamic>)), + ) ..crazyComplex = (json['crazyComplex'] as List<dynamic>) .map((e) => (e as Map<String, dynamic>?)?.map( (k, e) => MapEntry( @@ -96,11 +110,13 @@ Map<String, dynamic> _$KitchenSinkToJson(KitchenSink instance) => 'intList': instance.intList, 'dateTimeList': instance.dateTimeList.map((e) => e.toIso8601String()).toList(), + 'nullableSimpleObjectList': instance.nullableSimpleObjectList, 'map': instance.map, 'stringStringMap': instance.stringStringMap, 'dynamicIntMap': instance.dynamicIntMap, 'objectDateTimeMap': instance.objectDateTimeMap .map((k, e) => MapEntry(k, e.toIso8601String())), + 'nullableSimpleObjectMap': instance.nullableSimpleObjectMap, 'crazyComplex': instance.crazyComplex .map((e) => e?.map((k, e) => MapEntry( k, diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart index 5db543802..56cdb9a1e 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart @@ -138,11 +138,13 @@ class KitchenSink implements k.KitchenSink { List<Object> objectList = _defaultList(); List<int> intList = _defaultList(); List<DateTime> dateTimeList = _defaultList(); + List<SimpleObject?> nullableSimpleObjectList = _defaultList(); Map map = _defaultMap(); Map<String, String> stringStringMap = _defaultMap(); Map<dynamic, int> dynamicIntMap = _defaultMap(); Map<Object, DateTime> objectDateTimeMap = _defaultMap(); + Map<String, SimpleObject?> nullableSimpleObjectMap = _defaultMap(); List<Map<String, Map<String, List<List<DateTime>?>?>?>?> crazyComplex = _defaultList(); diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart index f2e8da4c3..b2c48bf02 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart @@ -41,6 +41,10 @@ KitchenSink _$KitchenSinkFromJson(Map json) => KitchenSink( ..dateTimeList = (json['dateTimeList'] as List<dynamic>) .map((e) => DateTime.parse(e as String)) .toList() + ..nullableSimpleObjectList = + (json['nullableSimpleObjectList'] as List<dynamic>) + .map((e) => e == null ? null : SimpleObject.fromJson(e as Map)) + .toList() ..map = json['map'] as Map ..stringStringMap = Map<String, String>.from(json['stringStringMap'] as Map) @@ -48,6 +52,10 @@ KitchenSink _$KitchenSinkFromJson(Map json) => KitchenSink( ..objectDateTimeMap = (json['objectDateTimeMap'] as Map).map( (k, e) => MapEntry(k as Object, DateTime.parse(e as String)), ) + ..nullableSimpleObjectMap = (json['nullableSimpleObjectMap'] as Map).map( + (k, e) => MapEntry( + k as String, e == null ? null : SimpleObject.fromJson(e as Map)), + ) ..crazyComplex = (json['crazyComplex'] as List<dynamic>) .map((e) => (e as Map?)?.map( (k, e) => MapEntry( @@ -94,11 +102,13 @@ Map<String, dynamic> _$KitchenSinkToJson(KitchenSink instance) => 'intList': instance.intList, 'dateTimeList': instance.dateTimeList.map((e) => e.toIso8601String()).toList(), + 'nullableSimpleObjectList': instance.nullableSimpleObjectList, 'map': instance.map, 'stringStringMap': instance.stringStringMap, 'dynamicIntMap': instance.dynamicIntMap, 'objectDateTimeMap': instance.objectDateTimeMap .map((k, e) => MapEntry(k, e.toIso8601String())), + 'nullableSimpleObjectMap': instance.nullableSimpleObjectMap, 'crazyComplex': instance.crazyComplex .map((e) => e?.map((k, e) => MapEntry( k, diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.dart index 4782d07a7..d997a4422 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.dart @@ -139,11 +139,13 @@ class KitchenSink implements k.KitchenSink { List<Object> objectList = _defaultList(); List<int> intList = _defaultList(); List<DateTime> dateTimeList = _defaultList(); + List<SimpleObject?> nullableSimpleObjectList = _defaultList(); Map map = _defaultMap(); Map<String, String> stringStringMap = _defaultMap(); Map<dynamic, int> dynamicIntMap = _defaultMap(); Map<Object, DateTime> objectDateTimeMap = _defaultMap(); + Map<String, SimpleObject?> nullableSimpleObjectMap = _defaultMap(); List<Map<String, Map<String, List<List<DateTime>?>?>?>?> crazyComplex = _defaultList(); diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.g.dart index 056a8cd61..20066ff54 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.g.dart @@ -64,6 +64,11 @@ KitchenSink _$KitchenSinkFromJson(Map json) => $checkedCreate( (v) => val.dateTimeList = (v as List<dynamic>) .map((e) => DateTime.parse(e as String)) .toList()); + $checkedConvert( + 'nullableSimpleObjectList', + (v) => val.nullableSimpleObjectList = (v as List<dynamic>) + .map((e) => e == null ? null : SimpleObject.fromJson(e as Map)) + .toList()); $checkedConvert('map', (v) => val.map = v as Map); $checkedConvert('stringStringMap', (v) => val.stringStringMap = Map<String, String>.from(v as Map)); @@ -74,6 +79,12 @@ KitchenSink _$KitchenSinkFromJson(Map json) => $checkedCreate( (v) => val.objectDateTimeMap = (v as Map).map( (k, e) => MapEntry(k as Object, DateTime.parse(e as String)), )); + $checkedConvert( + 'nullableSimpleObjectMap', + (v) => val.nullableSimpleObjectMap = (v as Map).map( + (k, e) => MapEntry(k as String, + e == null ? null : SimpleObject.fromJson(e as Map)), + )); $checkedConvert( 'crazyComplex', (v) => val.crazyComplex = (v as List<dynamic>) @@ -134,11 +145,13 @@ Map<String, dynamic> _$KitchenSinkToJson(KitchenSink instance) => 'intList': instance.intList, 'dateTimeList': instance.dateTimeList.map((e) => e.toIso8601String()).toList(), + 'nullableSimpleObjectList': instance.nullableSimpleObjectList, 'map': instance.map, 'stringStringMap': instance.stringStringMap, 'dynamicIntMap': instance.dynamicIntMap, 'objectDateTimeMap': instance.objectDateTimeMap .map((k, e) => MapEntry(k, e.toIso8601String())), + 'nullableSimpleObjectMap': instance.nullableSimpleObjectMap, 'crazyComplex': instance.crazyComplex .map((e) => e?.map((k, e) => MapEntry( k, diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.dart index 7456d12cd..44750ac8e 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.dart @@ -140,11 +140,13 @@ class KitchenSink implements k.KitchenSink { List<Object> objectList = _defaultList(); List<int> intList = _defaultList(); List<DateTime> dateTimeList = _defaultList(); + List<SimpleObject?> nullableSimpleObjectList = _defaultList(); Map map = _defaultMap(); Map<String, String> stringStringMap = _defaultMap(); Map<dynamic, int> dynamicIntMap = _defaultMap(); Map<Object, DateTime> objectDateTimeMap = _defaultMap(); + Map<String, SimpleObject?> nullableSimpleObjectMap = _defaultMap(); List<Map<String, Map<String, List<List<DateTime>?>?>?>?> crazyComplex = _defaultList(); diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart index b0866ea2c..c7ef240b6 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart @@ -41,6 +41,12 @@ KitchenSink _$KitchenSinkFromJson(Map<String, dynamic> json) => KitchenSink( ..dateTimeList = (json['dateTimeList'] as List<dynamic>) .map((e) => DateTime.parse(e as String)) .toList() + ..nullableSimpleObjectList = + (json['nullableSimpleObjectList'] as List<dynamic>) + .map((e) => e == null + ? null + : SimpleObject.fromJson(e as Map<String, dynamic>)) + .toList() ..map = json['map'] as Map<String, dynamic> ..stringStringMap = Map<String, String>.from(json['stringStringMap'] as Map) @@ -49,6 +55,14 @@ KitchenSink _$KitchenSinkFromJson(Map<String, dynamic> json) => KitchenSink( (json['objectDateTimeMap'] as Map<String, dynamic>).map( (k, e) => MapEntry(k, DateTime.parse(e as String)), ) + ..nullableSimpleObjectMap = + (json['nullableSimpleObjectMap'] as Map<String, dynamic>).map( + (k, e) => MapEntry( + k, + e == null + ? null + : SimpleObject.fromJson(e as Map<String, dynamic>)), + ) ..crazyComplex = (json['crazyComplex'] as List<dynamic>) .map((e) => (e as Map<String, dynamic>?)?.map( (k, e) => MapEntry( @@ -103,11 +117,13 @@ Map<String, dynamic> _$KitchenSinkToJson(KitchenSink instance) { val['intList'] = instance.intList; val['dateTimeList'] = instance.dateTimeList.map((e) => e.toIso8601String()).toList(); + val['nullableSimpleObjectList'] = instance.nullableSimpleObjectList; val['map'] = instance.map; val['stringStringMap'] = instance.stringStringMap; val['dynamicIntMap'] = instance.dynamicIntMap; val['objectDateTimeMap'] = instance.objectDateTimeMap .map((k, e) => MapEntry(k, e.toIso8601String())); + val['nullableSimpleObjectMap'] = instance.nullableSimpleObjectMap; val['crazyComplex'] = instance.crazyComplex .map((e) => e?.map((k, e) => MapEntry( k, diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.dart index 8f2875f59..4568b1cd0 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.dart @@ -140,11 +140,13 @@ class KitchenSink implements k.KitchenSink { List<Object> objectList = _defaultList(); List<int> intList = _defaultList(); List<DateTime> dateTimeList = _defaultList(); + List<SimpleObject?> nullableSimpleObjectList = _defaultList(); Map map = _defaultMap(); Map<String, String> stringStringMap = _defaultMap(); Map<dynamic, int> dynamicIntMap = _defaultMap(); Map<Object, DateTime> objectDateTimeMap = _defaultMap(); + Map<String, SimpleObject?> nullableSimpleObjectMap = _defaultMap(); List<Map<String, Map<String, List<List<DateTime>?>?>?>?> crazyComplex = _defaultList(); diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart index 18ad9cb04..36f94cadd 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart @@ -41,6 +41,12 @@ KitchenSink _$KitchenSinkFromJson(Map<String, dynamic> json) => KitchenSink( ..dateTimeList = (json['dateTimeList'] as List<dynamic>) .map((e) => DateTime.parse(e as String)) .toList() + ..nullableSimpleObjectList = + (json['nullableSimpleObjectList'] as List<dynamic>) + .map((e) => e == null + ? null + : SimpleObject.fromJson(e as Map<String, dynamic>)) + .toList() ..map = json['map'] as Map<String, dynamic> ..stringStringMap = Map<String, String>.from(json['stringStringMap'] as Map) @@ -49,6 +55,14 @@ KitchenSink _$KitchenSinkFromJson(Map<String, dynamic> json) => KitchenSink( (json['objectDateTimeMap'] as Map<String, dynamic>).map( (k, e) => MapEntry(k, DateTime.parse(e as String)), ) + ..nullableSimpleObjectMap = + (json['nullableSimpleObjectMap'] as Map<String, dynamic>).map( + (k, e) => MapEntry( + k, + e == null + ? null + : SimpleObject.fromJson(e as Map<String, dynamic>)), + ) ..crazyComplex = (json['crazyComplex'] as List<dynamic>) .map((e) => (e as Map<String, dynamic>?)?.map( (k, e) => MapEntry( @@ -96,11 +110,15 @@ Map<String, dynamic> _$KitchenSinkToJson(KitchenSink instance) => 'intList': instance.intList, 'dateTimeList': instance.dateTimeList.map((e) => e.toIso8601String()).toList(), + 'nullableSimpleObjectList': + instance.nullableSimpleObjectList.map((e) => e?.toJson()).toList(), 'map': instance.map, 'stringStringMap': instance.stringStringMap, 'dynamicIntMap': instance.dynamicIntMap, 'objectDateTimeMap': instance.objectDateTimeMap .map((k, e) => MapEntry(k, e.toIso8601String())), + 'nullableSimpleObjectMap': instance.nullableSimpleObjectMap + .map((k, e) => MapEntry(k, e?.toJson())), 'crazyComplex': instance.crazyComplex .map((e) => e?.map((k, e) => MapEntry( k, diff --git a/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart b/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart index 357085e5c..d1442e27a 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart @@ -70,6 +70,10 @@ abstract class KitchenSink { set dateTimeList(List<DateTime> value); + List<SimpleObject?> get nullableSimpleObjectList; + + set nullableSimpleObjectList(List<SimpleObject?> value); + Set get set; Set<dynamic> get dynamicSet; @@ -92,6 +96,10 @@ abstract class KitchenSink { set objectDateTimeMap(Map<Object, DateTime> value); + Map<String, SimpleObject?> get nullableSimpleObjectMap; + + set nullableSimpleObjectMap(Map<String, SimpleObject?> value); + List<Map<String, Map<String, List<List<DateTime>?>?>?>?> get crazyComplex; set crazyComplex( diff --git a/json_serializable/test/kitchen_sink/kitchen_sink_test.dart b/json_serializable/test/kitchen_sink/kitchen_sink_test.dart index b8566a9e5..13fde4f75 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink_test.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink_test.dart @@ -243,10 +243,12 @@ const _nonNullableFields = { 'objectList', 'intList', 'dateTimeList', + 'nullableSimpleObjectList', 'map', 'stringStringMap', 'dynamicIntMap', 'objectDateTimeMap', + 'nullableSimpleObjectMap', 'crazyComplex', 'val', 'simpleObject', @@ -270,8 +272,10 @@ const _iterableMapKeys = { 'intList', 'intSet', 'iterable', + 'nullableSimpleObjectList', 'list', 'map', + 'nullableSimpleObjectMap', 'numberSillySet', 'objectDateTimeMap', 'objectIterable', diff --git a/json_serializable/test/kitchen_sink/kitchen_sink_test_shared.dart b/json_serializable/test/kitchen_sink/kitchen_sink_test_shared.dart index f69535d6a..f39dcaed1 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink_test_shared.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink_test_shared.dart @@ -20,10 +20,18 @@ const validValues = <String, dynamic>{ 'objectList': [true], 'intList': [42], 'dateTimeList': ['2018-05-10T14:20:58.927'], + 'nullableSimpleObjectList': [ + {'value': 42}, + null + ], 'map': <String, dynamic>{'key': true}, 'stringStringMap': <String, dynamic>{'key': 'vaule'}, 'dynamicIntMap': <String, dynamic>{'key': 42}, 'objectDateTimeMap': <String, dynamic>{'key': '2018-05-10T14:20:58.927'}, + 'nullableSimpleObjectMap': <String, dynamic>{ + 'key': {'value': 42}, + 'null-key': null, + }, 'crazyComplex': [<String, dynamic>{}], generatedLocalVarName: <String, dynamic>{'key': true}, _toJsonMapHelperName: true, @@ -52,10 +60,12 @@ const invalidValueTypes = { 'objectList': true, 'intList': [true], 'dateTimeList': [true], + 'nullableSimpleObjectList': 42, 'map': true, 'stringStringMap': {'key': 42}, 'dynamicIntMap': {'key': 'value'}, 'objectDateTimeMap': {'key': 42}, + 'nullableSimpleObjectMap': <String, dynamic>{'key': 42}, 'crazyComplex': [true], generatedLocalVarName: {'key': 42}, _toJsonMapHelperName: 42, @@ -79,10 +89,12 @@ const disallowNullKeys = { 'objectList', 'intList', 'dateTimeList', + 'nullableSimpleObjectList', 'map', 'stringStringMap', 'dynamicIntMap', 'objectDateTimeMap', + 'nullableSimpleObjectMap', 'crazyComplex', generatedLocalVarName, 'simpleObject', From 6f7d8ad0338d8899711854aa6813523dfba88ea0 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@google.com> Date: Wed, 21 Jul 2021 11:36:26 -0700 Subject: [PATCH 330/569] Cleanup build.yaml --- json_serializable/build.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/json_serializable/build.yaml b/json_serializable/build.yaml index 809fc74e8..990cbdb1c 100644 --- a/json_serializable/build.yaml +++ b/json_serializable/build.yaml @@ -22,7 +22,6 @@ targets: - test/default_value/default_value.dart - test/generic_files/generic_class.dart - test/integration/json_test_example.dart - - test/integration/json_test_example.dart - test/kitchen_sink/kitchen_sink.dart json_serializable|_type_builder: From b92d12d5c8d93c99c36637fc258db7612dfd2cbf Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@google.com> Date: Sat, 4 Sep 2021 14:42:15 -0700 Subject: [PATCH 331/569] readme cleanup RE null-safety --- json_serializable/README.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/json_serializable/README.md b/json_serializable/README.md index a80cc24a0..77980e499 100644 --- a/json_serializable/README.md +++ b/json_serializable/README.md @@ -1,8 +1,5 @@ [![Pub Package](https://img.shields.io/pub/v/json_serializable.svg)](https://pub.dev/packages/json_serializable) -> `json_serializable` produces null-safe code. We are waiting for dependencies -> to be migrated before it will appear "null-safe" on `pub.dev`. - Provides [Dart Build System] builders for handling JSON. The builders generate code when they find members annotated with classes defined From 12fe7a150a9b41c0f856c6886d72ee2a3ec4fd1d Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@google.com> Date: Wed, 15 Sep 2021 07:42:00 -0700 Subject: [PATCH 332/569] release json_serializable v5.0.1 --- json_serializable/CHANGELOG.md | 2 +- json_serializable/pubspec.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index e790d65e0..f6888a0eb 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,4 +1,4 @@ -## 5.1.0-dev +## 5.0.1 - Correctly handle nullable custom objects within `Iterable` and `Map`. - Require the latest `package:source_helper`. diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index e8bcd232e..4066201e1 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 5.1.0-dev +version: 5.0.1 description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. From b509a7fc6779ff2485fe7b1d472b570191106887 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Mon, 20 Sep 2021 11:23:13 -0700 Subject: [PATCH 333/569] Include type arguments when invoking `fromJson` on custom types. (#984) This fixes an edge case where the generic arguments could not be inferred. Also DRY'd up some test helpers Fixes https://github.com/google/json_serializable.dart/pull/980 Closes https://github.com/google/json_serializable.dart/pull/981 --- json_serializable/CHANGELOG.md | 5 +++ .../lib/src/type_helpers/json_helper.dart | 3 +- json_serializable/pubspec.yaml | 2 +- .../generic_argument_factories.g.dart | 10 +++-- ...generic_argument_factories_nullable.g.dart | 6 +-- .../test/generic_files/generic_class.dart | 40 +++++++++++++++++++ .../test/generic_files/generic_class.g.dart | 14 +++++++ .../test/generic_files/generic_test.dart | 10 +++++ .../test/integration/json_test_common.dart | 4 -- .../test/integration/json_test_example.dart | 1 + .../test/integration/json_test_example.g.dart | 2 +- .../json_test_example.g_any_map.dart | 1 + .../json_test_example.g_any_map.g.dart | 2 +- .../kitchen_sink/kitchen_sink_interface.dart | 18 ++++----- .../src/_json_serializable_test_input.dart | 3 +- json_serializable/test/test_utils.dart | 4 ++ 16 files changed, 98 insertions(+), 27 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index f6888a0eb..059d33b5f 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,8 @@ +## 5.0.2 + +- Include type arguments when invoking `fromJson` on custom types. + This fixes an edge case where the generic arguments could not be inferred. + ## 5.0.1 - Correctly handle nullable custom objects within `Iterable` and `Map`. diff --git a/json_serializable/lib/src/type_helpers/json_helper.dart b/json_serializable/lib/src/type_helpers/json_helper.dart index 521985fa5..305017fef 100644 --- a/json_serializable/lib/src/type_helpers/json_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_helper.dart @@ -11,6 +11,7 @@ import 'package:source_gen/source_gen.dart'; import 'package:source_helper/source_helper.dart'; import '../default_container.dart'; +import '../helper_core.dart'; import '../type_helper.dart'; import '../utils.dart'; import 'config_types.dart'; @@ -130,7 +131,7 @@ class JsonHelper extends TypeHelper<TypeHelperContextWithConfig> { // TODO: the type could be imported from a library with a prefix! // https://github.com/google/json_serializable.dart/issues/19 - output = '${targetType.element.name}.fromJson($output)'; + output = '${typeToCode(targetType.promoteNonNullable())}.fromJson($output)'; return DefaultContainer(expression, output); } diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 4066201e1..f2fb529e2 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 5.0.1 +version: 5.0.2 description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. diff --git a/json_serializable/test/generic_files/generic_argument_factories.g.dart b/json_serializable/test/generic_files/generic_argument_factories.g.dart index cc8c0428a..965996240 100644 --- a/json_serializable/test/generic_files/generic_argument_factories.g.dart +++ b/json_serializable/test/generic_files/generic_argument_factories.g.dart @@ -32,13 +32,15 @@ Map<String, dynamic> _$GenericClassWithHelpersToJson<T, S>( ConcreteClass _$ConcreteClassFromJson(Map<String, dynamic> json) => ConcreteClass( - GenericClassWithHelpers.fromJson(json['value'] as Map<String, dynamic>, - (value) => value as int, (value) => value as String), - GenericClassWithHelpers.fromJson( + GenericClassWithHelpers<int, String>.fromJson( + json['value'] as Map<String, dynamic>, + (value) => value as int, + (value) => value as String), + GenericClassWithHelpers<double, BigInt>.fromJson( json['value2'] as Map<String, dynamic>, (value) => (value as num).toDouble(), (value) => BigInt.parse(value as String)), - GenericClassWithHelpers.fromJson( + GenericClassWithHelpers<double?, BigInt?>.fromJson( json['value3'] as Map<String, dynamic>, (value) => (value as num?)?.toDouble(), (value) => value == null ? null : BigInt.parse(value as String)), diff --git a/json_serializable/test/generic_files/generic_argument_factories_nullable.g.dart b/json_serializable/test/generic_files/generic_argument_factories_nullable.g.dart index 115d1ee32..93bde3ca0 100644 --- a/json_serializable/test/generic_files/generic_argument_factories_nullable.g.dart +++ b/json_serializable/test/generic_files/generic_argument_factories_nullable.g.dart @@ -55,15 +55,15 @@ Object? _$nullableGenericToJson<T>( ConcreteClassNullable _$ConcreteClassNullableFromJson( Map<String, dynamic> json) => ConcreteClassNullable( - GenericClassWithHelpersNullable.fromJson( + GenericClassWithHelpersNullable<int, String>.fromJson( json['value'] as Map<String, dynamic>, (value) => value as int, (value) => value as String), - GenericClassWithHelpersNullable.fromJson( + GenericClassWithHelpersNullable<double, BigInt>.fromJson( json['value2'] as Map<String, dynamic>, (value) => (value as num).toDouble(), (value) => BigInt.parse(value as String)), - GenericClassWithHelpersNullable.fromJson( + GenericClassWithHelpersNullable<double?, BigInt?>.fromJson( json['value3'] as Map<String, dynamic>, (value) => (value as num?)?.toDouble(), (value) => value == null ? null : BigInt.parse(value as String)), diff --git a/json_serializable/test/generic_files/generic_class.dart b/json_serializable/test/generic_files/generic_class.dart index bf47a098d..d0fbd6e0b 100644 --- a/json_serializable/test/generic_files/generic_class.dart +++ b/json_serializable/test/generic_files/generic_class.dart @@ -2,8 +2,11 @@ // 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:collection/collection.dart'; import 'package:json_annotation/json_annotation.dart'; +import '../test_utils.dart'; + part 'generic_class.g.dart'; @JsonSerializable() @@ -103,3 +106,40 @@ class _DurationListMillisecondConverter int? toJson(List<Duration>? object) => object?.fold<int>(0, (sum, obj) => sum + obj.inMilliseconds); } + +class Issue980GenericClass<T> { + final T value; + + Issue980GenericClass(this.value); + + factory Issue980GenericClass.fromJson(Map<String, dynamic> json) => + Issue980GenericClass(json['value'] as T); + + Map<String, dynamic> toJson() => {'value': value}; + + @override + bool operator ==(Object other) => + other is Issue980GenericClass && value == other.value; + + @override + int get hashCode => value.hashCode; +} + +@JsonSerializable() +class Issue980ParentClass { + final List<Issue980GenericClass<int>> list; + + Issue980ParentClass(this.list); + + factory Issue980ParentClass.fromJson(Map<String, dynamic> json) => + _$Issue980ParentClassFromJson(json); + + Map<String, dynamic> toJson() => _$Issue980ParentClassToJson(this); + + @override + bool operator ==(Object other) => + other is Issue980ParentClass && deepEquals(list, other.list); + + @override + int get hashCode => const DeepCollectionEquality().hash(list); +} diff --git a/json_serializable/test/generic_files/generic_class.g.dart b/json_serializable/test/generic_files/generic_class.g.dart index a3810757f..aa5f32e79 100644 --- a/json_serializable/test/generic_files/generic_class.g.dart +++ b/json_serializable/test/generic_files/generic_class.g.dart @@ -61,3 +61,17 @@ Map<String, dynamic> _$GenericClassWithConverterToJson<T extends num, S>( 'listDuration': const _DurationListMillisecondConverter() .toJson(instance.listDuration), }; + +Issue980ParentClass _$Issue980ParentClassFromJson(Map<String, dynamic> json) => + Issue980ParentClass( + (json['list'] as List<dynamic>) + .map((e) => + Issue980GenericClass<int>.fromJson(e as Map<String, dynamic>)) + .toList(), + ); + +Map<String, dynamic> _$Issue980ParentClassToJson( + Issue980ParentClass instance) => + <String, dynamic>{ + 'list': instance.list, + }; diff --git a/json_serializable/test/generic_files/generic_test.dart b/json_serializable/test/generic_files/generic_test.dart index 80eb3bf1f..70de6cd9c 100644 --- a/json_serializable/test/generic_files/generic_test.dart +++ b/json_serializable/test/generic_files/generic_test.dart @@ -316,4 +316,14 @@ void main() { }); }); }); + + test('issue 980 regression test', () { + roundTripObject( + Issue980ParentClass([ + Issue980GenericClass(45), + Issue980GenericClass(42), + ]), + (json) => Issue980ParentClass.fromJson(json), + ); + }); } diff --git a/json_serializable/test/integration/json_test_common.dart b/json_serializable/test/integration/json_test_common.dart index d878e9f1b..81f671172 100644 --- a/json_serializable/test/integration/json_test_common.dart +++ b/json_serializable/test/integration/json_test_common.dart @@ -4,7 +4,6 @@ import 'dart:collection'; -import 'package:collection/collection.dart'; import 'package:json_annotation/json_annotation.dart'; enum Category { @@ -42,9 +41,6 @@ DateTime? dateTimeFromEpochUs(int? us) => int? dateTimeToEpochUs(DateTime? dateTime) => dateTime?.microsecondsSinceEpoch; -bool deepEquals(dynamic a, dynamic b) => - const DeepCollectionEquality().equals(a, b); - class Platform { final String description; diff --git a/json_serializable/test/integration/json_test_example.dart b/json_serializable/test/integration/json_test_example.dart index ba344482d..d9f43e66b 100644 --- a/json_serializable/test/integration/json_test_example.dart +++ b/json_serializable/test/integration/json_test_example.dart @@ -7,6 +7,7 @@ import 'dart:collection'; import 'package:json_annotation/json_annotation.dart'; +import '../test_utils.dart'; import 'json_test_common.dart'; part 'json_test_example.g.dart'; diff --git a/json_serializable/test/integration/json_test_example.g.dart b/json_serializable/test/integration/json_test_example.g.dart index 25edb0d43..b6149a068 100644 --- a/json_serializable/test/integration/json_test_example.g.dart +++ b/json_serializable/test/integration/json_test_example.g.dart @@ -22,7 +22,7 @@ Person _$PersonFromJson(Map<String, dynamic> json) => Person( : Order.fromJson(json['order'] as Map<String, dynamic>) ..customOrders = json['customOrders'] == null ? null - : MyList.fromJson((json['customOrders'] as List<dynamic>) + : MyList<Order>.fromJson((json['customOrders'] as List<dynamic>) .map((e) => Order.fromJson(e as Map<String, dynamic>)) .toList()) ..houseMap = (json['houseMap'] as Map<String, dynamic>?)?.map( diff --git a/json_serializable/test/integration/json_test_example.g_any_map.dart b/json_serializable/test/integration/json_test_example.g_any_map.dart index d4ee3c60e..5cff5c35d 100644 --- a/json_serializable/test/integration/json_test_example.g_any_map.dart +++ b/json_serializable/test/integration/json_test_example.g_any_map.dart @@ -7,6 +7,7 @@ import 'dart:collection'; import 'package:json_annotation/json_annotation.dart'; +import '../test_utils.dart'; import 'json_test_common.dart'; part 'json_test_example.g_any_map.g.dart'; diff --git a/json_serializable/test/integration/json_test_example.g_any_map.g.dart b/json_serializable/test/integration/json_test_example.g_any_map.g.dart index c79a9752d..9abeb7ed8 100644 --- a/json_serializable/test/integration/json_test_example.g_any_map.g.dart +++ b/json_serializable/test/integration/json_test_example.g_any_map.g.dart @@ -22,7 +22,7 @@ Person _$PersonFromJson(Map json) => Person( : Order.fromJson(Map<String, dynamic>.from(json['order'] as Map)) ..customOrders = json['customOrders'] == null ? null - : MyList.fromJson((json['customOrders'] as List<dynamic>) + : MyList<Order>.fromJson((json['customOrders'] as List<dynamic>) .map((e) => Order.fromJson(Map<String, dynamic>.from(e as Map))) .toList()) ..houseMap = (json['houseMap'] as Map?)?.map( diff --git a/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart b/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart index d1442e27a..ca4ad5b8f 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart @@ -2,8 +2,7 @@ // 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:collection/collection.dart'; - +import '../test_utils.dart'; import 'simple_object.dart'; abstract class KitchenSinkFactory<K, V> { @@ -123,24 +122,21 @@ bool sinkEquals(KitchenSink a, Object other) => other is KitchenSink && a.ctorValidatedNo42 == other.ctorValidatedNo42 && a.dateTime == other.dateTime && - _deepEquals(a.iterable, other.iterable) && - _deepEquals(a.dynamicIterable, other.dynamicIterable) && + deepEquals(a.iterable, other.iterable) && + deepEquals(a.dynamicIterable, other.dynamicIterable) && // objectIterable // intIterable - _deepEquals(a.dateTimeIterable, other.dateTimeIterable) && + deepEquals(a.dateTimeIterable, other.dateTimeIterable) && // list // dynamicList // objectList // intList - _deepEquals(a.dateTimeList, other.dateTimeList) && + deepEquals(a.dateTimeList, other.dateTimeList) && // map // stringStringMap // stringIntMap - _deepEquals(a.objectDateTimeMap, other.objectDateTimeMap) && - _deepEquals(a.crazyComplex, other.crazyComplex) && + deepEquals(a.objectDateTimeMap, other.objectDateTimeMap) && + deepEquals(a.crazyComplex, other.crazyComplex) && // val a.writeNotNull == other.writeNotNull && a.string == other.string; - -bool _deepEquals(Object? a, Object? b) => - const DeepCollectionEquality().equals(a, b); diff --git a/json_serializable/test/src/_json_serializable_test_input.dart b/json_serializable/test/src/_json_serializable_test_input.dart index 4899478c2..09c972b93 100644 --- a/json_serializable/test/src/_json_serializable_test_input.dart +++ b/json_serializable/test/src/_json_serializable_test_input.dart @@ -382,7 +382,8 @@ FieldWithFromJsonCtorAndTypeParams _$FieldWithFromJsonCtorAndTypeParamsFromJson( FieldWithFromJsonCtorAndTypeParams() ..customOrders = json['customOrders'] == null ? null - : MyList.fromJson((json['customOrders'] as List<dynamic>) + : MyList<GeneralTestClass2, int>.fromJson((json['customOrders'] + as List<dynamic>) .map((e) => GeneralTestClass2.fromJson(e as Map<String, dynamic>)) .toList()); ''') diff --git a/json_serializable/test/test_utils.dart b/json_serializable/test/test_utils.dart index c47a46d7b..e54c43eee 100644 --- a/json_serializable/test/test_utils.dart +++ b/json_serializable/test/test_utils.dart @@ -4,6 +4,7 @@ import 'dart:convert'; +import 'package:collection/collection.dart'; import 'package:stack_trace/stack_trace.dart'; import 'package:test/test.dart'; @@ -11,6 +12,9 @@ final throwsTypeError = throwsA(isTypeError); final isTypeError = isA<TypeError>(); +bool deepEquals(dynamic a, dynamic b) => + const DeepCollectionEquality().equals(a, b); + T roundTripObject<T>(T object, T Function(Map<String, dynamic> json) factory) { final data = loudEncode(object); From bfe2ca4f186226f39dabaf50fba0d3ee9ee55dd9 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@google.com> Date: Mon, 20 Sep 2021 11:35:05 -0700 Subject: [PATCH 334/569] fix example --- example/lib/tuple_example.g.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/example/lib/tuple_example.g.dart b/example/lib/tuple_example.g.dart index e6a4690c2..e90d91a1d 100644 --- a/example/lib/tuple_example.g.dart +++ b/example/lib/tuple_example.g.dart @@ -28,9 +28,9 @@ Map<String, dynamic> _$TupleToJson<T, S>( ConcreteClass _$ConcreteClassFromJson(Map<String, dynamic> json) => ConcreteClass( - Tuple.fromJson(json['tuple1'] as Map<String, dynamic>, + Tuple<int, DateTime>.fromJson(json['tuple1'] as Map<String, dynamic>, (value) => value as int, (value) => DateTime.parse(value as String)), - Tuple.fromJson( + Tuple<Duration, BigInt>.fromJson( json['tuple2'] as Map<String, dynamic>, (value) => Duration(microseconds: value as int), (value) => BigInt.parse(value as String)), From 2d0fe3a50bea740d665439484839e00c48adf1ee Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Tue, 21 Sep 2021 11:20:34 -0700 Subject: [PATCH 335/569] fix for latest analysis (#985) --- .../lib/src/type_helpers/json_converter_helper.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/json_serializable/lib/src/type_helpers/json_converter_helper.dart b/json_serializable/lib/src/type_helpers/json_converter_helper.dart index d6969049d..66182a8ba 100644 --- a/json_serializable/lib/src/type_helpers/json_converter_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_converter_helper.dart @@ -179,7 +179,7 @@ _ConverterMatch? _compatibleMatch( final jsonConverterSuper = converterClassElement.allSupertypes.singleWhereOrNull( - (e) => e is InterfaceType && _jsonConverterChecker.isExactly(e.element), + (e) => _jsonConverterChecker.isExactly(e.element), ); if (jsonConverterSuper == null) { From 5cd539321a3d7843d3c03a58e500ce7069f9e47d Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@google.com> Date: Thu, 23 Sep 2021 18:16:38 -0700 Subject: [PATCH 336/569] Add some breadcrumbs to make updating json_annotation easier...later --- json_serializable/lib/src/settings.dart | 1 + json_serializable/lib/src/type_helpers/config_types.dart | 1 + json_serializable/lib/src/utils.dart | 1 + json_serializable/test/config_test.dart | 9 +++++++-- json_serializable/test/custom_configuration_test.dart | 6 +++++- json_serializable/test/shared_config.dart | 5 +++-- json_serializable/test/test_sources/test_sources.dart | 1 + 7 files changed, 19 insertions(+), 5 deletions(-) diff --git a/json_serializable/lib/src/settings.dart b/json_serializable/lib/src/settings.dart index 762289490..f2c93535e 100644 --- a/json_serializable/lib/src/settings.dart +++ b/json_serializable/lib/src/settings.dart @@ -45,6 +45,7 @@ class Settings { final JsonSerializable _config; + // #CHANGE WHEN UPDATING json_annotation ClassConfig get config => ClassConfig( checked: _config.checked ?? ClassConfig.defaults.checked, anyMap: _config.anyMap ?? ClassConfig.defaults.anyMap, diff --git a/json_serializable/lib/src/type_helpers/config_types.dart b/json_serializable/lib/src/type_helpers/config_types.dart index 7b3c26637..3a8d82adb 100644 --- a/json_serializable/lib/src/type_helpers/config_types.dart +++ b/json_serializable/lib/src/type_helpers/config_types.dart @@ -111,6 +111,7 @@ const _$FieldRenameEnumMap = { FieldRename.pascal: 'pascal', }; +// #CHANGE WHEN UPDATING json_annotation Map<String, dynamic> _$JsonSerializableToJson(JsonSerializable instance) => <String, dynamic>{ 'any_map': instance.anyMap, diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index 0b374eedb..2e558f6c3 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -75,6 +75,7 @@ T enumValueForDartObject<T>( /// Return an instance of [JsonSerializable] corresponding to a the provided /// [reader]. +// #CHANGE WHEN UPDATING json_annotation JsonSerializable _valueForAnnotation(ConstantReader reader) => JsonSerializable( anyMap: reader.read('anyMap').literalValue as bool?, checked: reader.read('checked').literalValue as bool?, diff --git a/json_serializable/test/config_test.dart b/json_serializable/test/config_test.dart index 065aead27..ccd28c837 100644 --- a/json_serializable/test/config_test.dart +++ b/json_serializable/test/config_test.dart @@ -76,8 +76,12 @@ void main() { final configMap = Map<String, dynamic>.from(yaml); - expect(configMap.keys, unorderedEquals(generatorConfigDefaultJson.keys), - reason: 'All supported keys are documented.'); + expect( + configMap.keys, + unorderedEquals(generatorConfigDefaultJson.keys), + reason: 'All supported keys are documented. ' + 'Did you forget to change README.md?', + ); expect( JsonSerializable.fromJson(configMap).toJson(), @@ -131,6 +135,7 @@ $lastLine''', }); } +// #CHANGE WHEN UPDATING json_annotation const _invalidConfig = { 'any_map': 42, 'checked': 42, diff --git a/json_serializable/test/custom_configuration_test.dart b/json_serializable/test/custom_configuration_test.dart index 03c994519..beb592648 100644 --- a/json_serializable/test/custom_configuration_test.dart +++ b/json_serializable/test/custom_configuration_test.dart @@ -110,7 +110,11 @@ Future<void> main() async { expected[jsonSerialKey] = generatorConfigDefaultJson[jsonSerialKey]; } - expect(_ConfigLogger.configurations.first.toJson(), expected); + expect( + _ConfigLogger.configurations.first.toJson(), + expected, + reason: 'Did you forget to change README.md?', + ); }, ); }); diff --git a/json_serializable/test/shared_config.dart b/json_serializable/test/shared_config.dart index 4e7747475..c4876e99b 100644 --- a/json_serializable/test/shared_config.dart +++ b/json_serializable/test/shared_config.dart @@ -7,9 +7,10 @@ import 'package:json_serializable/src/type_helpers/config_types.dart'; final jsonSerializableFields = generatorConfigDefaultJson.keys.toList(); -final generatorConfigDefaultJson = Map<String, dynamic>.unmodifiable( - ClassConfig.defaults.withDefaults().toJson()); +final generatorConfigDefaultJson = + Map<String, dynamic>.unmodifiable(ClassConfig.defaults.toJson()); +// #CHANGE WHEN UPDATING json_annotation final generatorConfigNonDefaultJson = Map<String, dynamic>.unmodifiable(const JsonSerializable( anyMap: true, diff --git a/json_serializable/test/test_sources/test_sources.dart b/json_serializable/test/test_sources/test_sources.dart index b1182cb06..8911ddfd8 100644 --- a/json_serializable/test/test_sources/test_sources.dart +++ b/json_serializable/test/test_sources/test_sources.dart @@ -5,6 +5,7 @@ class ConfigurationImplicitDefaults { int? field; } +// #CHANGE WHEN UPDATING json_annotation @JsonSerializable( anyMap: false, checked: false, From f1cd0a8882f45546cfe776413d3598ef03b45b97 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@google.com> Date: Thu, 23 Sep 2021 20:30:32 -0700 Subject: [PATCH 337/569] test cleanup --- .../test/generic_files/generic_test.dart | 2 +- .../test/integration/integration_test.dart | 13 +++++-------- .../test/kitchen_sink/kitchen_sink_test.dart | 12 ++++++------ json_serializable/test/test_utils.dart | 6 ++++-- 4 files changed, 16 insertions(+), 17 deletions(-) diff --git a/json_serializable/test/generic_files/generic_test.dart b/json_serializable/test/generic_files/generic_test.dart index 70de6cd9c..f3de54bd7 100644 --- a/json_serializable/test/generic_files/generic_test.dart +++ b/json_serializable/test/generic_files/generic_test.dart @@ -318,7 +318,7 @@ void main() { }); test('issue 980 regression test', () { - roundTripObject( + validateRoundTrip( Issue980ParentClass([ Issue980GenericClass(45), Issue980GenericClass(42), diff --git a/json_serializable/test/integration/integration_test.dart b/json_serializable/test/integration/integration_test.dart index c25327ebb..71786ea4b 100644 --- a/json_serializable/test/integration/integration_test.dart +++ b/json_serializable/test/integration/integration_test.dart @@ -14,7 +14,7 @@ Matcher _throwsArgumentError(matcher) => void main() { group('Person', () { void roundTripPerson(Person p) { - roundTripObject(p, (json) => Person.fromJson(json)); + validateRoundTrip(p, (json) => Person.fromJson(json)); } test('now', () { @@ -48,7 +48,7 @@ void main() { group('Order', () { void roundTripOrder(Order p) { - roundTripObject(p, (json) => Order.fromJson(json)); + validateRoundTrip(p, (json) => Order.fromJson(json)); } test('null', () { @@ -187,7 +187,7 @@ void main() { group('Item', () { void roundTripItem(Item p) { - roundTripObject(p, (json) => Item.fromJson(json)); + validateRoundTrip(p, (json) => Item.fromJson(json)); } test('empty json', () { @@ -228,7 +228,7 @@ void main() { group('Numbers', () { void roundTripNumber(Numbers p) { - roundTripObject(p, (json) => Numbers.fromJson(json)); + validateRoundTrip(p, (json) => Numbers.fromJson(json)); } test('simple', () { @@ -273,10 +273,7 @@ void main() { ..intIntMap = {3: 3} ..uriIntMap = {Uri.parse('https://example.com'): 4}; - final roundTrip = - roundTripObject(instance, (j) => MapKeyVariety.fromJson(j)); - - expect(roundTrip, instance); + validateRoundTrip(instance, (j) => MapKeyVariety.fromJson(j)); }); test('UnknownEnumValue', () { diff --git a/json_serializable/test/kitchen_sink/kitchen_sink_test.dart b/json_serializable/test/kitchen_sink/kitchen_sink_test.dart index 13fde4f75..c60d9bd08 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink_test.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink_test.dart @@ -84,7 +84,7 @@ void _nonNullableTests(KitchenSinkFactory factory) { void _nullableTests(KitchenSinkFactory factory) { void roundTripSink(KitchenSink p) { - roundTripObject(p, factory.fromJson); + validateRoundTrip(p, factory.fromJson); } test('nullable values are allowed in the nullable version', () { @@ -164,7 +164,7 @@ void _nullableTests(KitchenSinkFactory factory) { void _sharedTests(KitchenSinkFactory factory) { test('empty', () { final item = factory.ctor(); - roundTripObject(item, factory.fromJson); + validateRoundTrip(item, factory.fromJson); }); test('list and map of DateTime - not null', () { @@ -173,7 +173,7 @@ void _sharedTests(KitchenSinkFactory factory) { ..dateTimeList = <DateTime>[now, now] ..objectDateTimeMap = <Object, DateTime>{'value': now}; - roundTripObject(item, factory.fromJson); + validateRoundTrip(item, factory.fromJson); }); test('complex nested type - not null', () { @@ -191,7 +191,7 @@ void _sharedTests(KitchenSinkFactory factory) { } } ]; - roundTripObject(item, factory.fromJson); + validateRoundTrip(item, factory.fromJson); }); test('round trip valid, empty values', () { @@ -210,7 +210,7 @@ void _sharedTests(KitchenSinkFactory factory) { final validInstance = factory.fromJson(values); - roundTripObject(validInstance, factory.fromJson); + validateRoundTrip(validInstance, factory.fromJson); }); test('JSON keys should be defined in field/property order', () { @@ -224,7 +224,7 @@ void _sharedTests(KitchenSinkFactory factory) { test('valid values round-trip - json', () { final validInstance = factory.fromJson(validValues); - roundTripObject(validInstance, factory.fromJson); + validateRoundTrip(validInstance, factory.fromJson); }); } diff --git a/json_serializable/test/test_utils.dart b/json_serializable/test/test_utils.dart index e54c43eee..b82e1b780 100644 --- a/json_serializable/test/test_utils.dart +++ b/json_serializable/test/test_utils.dart @@ -15,7 +15,10 @@ final isTypeError = isA<TypeError>(); bool deepEquals(dynamic a, dynamic b) => const DeepCollectionEquality().equals(a, b); -T roundTripObject<T>(T object, T Function(Map<String, dynamic> json) factory) { +void validateRoundTrip<T>( + T object, + T Function(Map<String, dynamic> json) factory, +) { final data = loudEncode(object); final object2 = factory(json.decode(data) as Map<String, dynamic>); @@ -25,7 +28,6 @@ T roundTripObject<T>(T object, T Function(Map<String, dynamic> json) factory) { final json2 = loudEncode(object2); expect(json2, equals(data)); - return object2; } /// Prints out nested causes before throwing `JsonUnsupportedObjectError`. From 368a8c704b3caf0c57bc32af26666a92b37545e6 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@google.com> Date: Thu, 23 Sep 2021 14:54:17 -0700 Subject: [PATCH 338/569] Add JsonSerializabel.constructor Allows specifying an alternative constructor to invoke when creating a `fromJson` helper. Closes https://github.com/google/json_serializable.dart/issues/490 --- json_annotation/CHANGELOG.md | 5 +++ .../lib/src/json_serializable.dart | 12 ++++++ .../lib/src/json_serializable.g.dart | 3 ++ json_annotation/pubspec.yaml | 2 +- json_serializable/CHANGELOG.md | 6 +++ json_serializable/README.md | 42 ++++++++++--------- json_serializable/doc/doc.md | 40 +++++++++--------- json_serializable/lib/src/decode_helper.dart | 12 +++++- json_serializable/lib/src/settings.dart | 1 + .../lib/src/type_helpers/config_types.dart | 6 +++ json_serializable/lib/src/utils.dart | 40 ++++++++++++------ json_serializable/pubspec.yaml | 8 +++- json_serializable/test/config_test.dart | 20 +++++++-- .../test/integration/integration_test.dart | 19 ++++++--- .../test/integration/json_test_example.dart | 25 ++++++++++- .../test/integration/json_test_example.g.dart | 14 ++++++- .../json_test_example.g_any_map.dart | 27 ++++++++++-- .../json_test_example.g_any_map.g.dart | 14 ++++++- .../test/json_serializable_test.dart | 1 + json_serializable/test/shared_config.dart | 1 + .../src/_json_serializable_test_input.dart | 18 ++++---- .../test/src/setter_test_input.dart | 3 -- .../test/src/to_from_json_test_input.dart | 6 --- .../test/test_sources/test_sources.dart | 4 ++ 24 files changed, 238 insertions(+), 91 deletions(-) diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index b10746b46..47ef110b6 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -1,3 +1,8 @@ +## 4.2.0-dev + +- Added `JsonSerializabel.constructor` field to allow specifying an alternative + constructor to invoke when creating a `fromJson` helper. + ## 4.1.0 - Added a `const` constructor to `JsonConverter`. diff --git a/json_annotation/lib/src/json_serializable.dart b/json_annotation/lib/src/json_serializable.dart index 6db0ae101..5267277bb 100644 --- a/json_annotation/lib/src/json_serializable.dart +++ b/json_annotation/lib/src/json_serializable.dart @@ -50,6 +50,15 @@ class JsonSerializable { /// [CheckedFromJsonException] is thrown. final bool? checked; + /// Specifies a named constructor to target when creating the `fromJson` + /// function. + /// + /// If the value is not set or an empty [String], the default constructor + /// is used. + /// + /// This setting has no effect if [createFactory] is `false`. + final String? constructor; + /// If `true` (the default), a private, static `_$ExampleFromJson` method /// is created in the generated part file. /// @@ -182,6 +191,7 @@ class JsonSerializable { @Deprecated('Has no effect') bool? nullable, this.anyMap, this.checked, + this.constructor, this.createFactory, this.createToJson, this.disallowUnrecognizedKeys, @@ -201,6 +211,7 @@ class JsonSerializable { static const defaults = JsonSerializable( anyMap: false, checked: false, + constructor: '', createFactory: true, createToJson: true, disallowUnrecognizedKeys: false, @@ -220,6 +231,7 @@ class JsonSerializable { JsonSerializable withDefaults() => JsonSerializable( anyMap: anyMap ?? defaults.anyMap, checked: checked ?? defaults.checked, + constructor: constructor ?? defaults.constructor, createFactory: createFactory ?? defaults.createFactory, createToJson: createToJson ?? defaults.createToJson, disallowUnrecognizedKeys: diff --git a/json_annotation/lib/src/json_serializable.g.dart b/json_annotation/lib/src/json_serializable.g.dart index d0b8a896c..bab0898c6 100644 --- a/json_annotation/lib/src/json_serializable.g.dart +++ b/json_annotation/lib/src/json_serializable.g.dart @@ -16,6 +16,7 @@ JsonSerializable _$JsonSerializableFromJson(Map<String, dynamic> json) => allowedKeys: const [ 'any_map', 'checked', + 'constructor', 'create_factory', 'create_to_json', 'disallow_unrecognized_keys', @@ -29,6 +30,7 @@ JsonSerializable _$JsonSerializableFromJson(Map<String, dynamic> json) => final val = JsonSerializable( anyMap: $checkedConvert('any_map', (v) => v as bool?), checked: $checkedConvert('checked', (v) => v as bool?), + constructor: $checkedConvert('constructor', (v) => v as String?), createFactory: $checkedConvert('create_factory', (v) => v as bool?), createToJson: $checkedConvert('create_to_json', (v) => v as bool?), disallowUnrecognizedKeys: @@ -62,6 +64,7 @@ Map<String, dynamic> _$JsonSerializableToJson(JsonSerializable instance) => <String, dynamic>{ 'any_map': instance.anyMap, 'checked': instance.checked, + 'constructor': instance.constructor, 'create_factory': instance.createFactory, 'create_to_json': instance.createToJson, 'disallow_unrecognized_keys': instance.disallowUnrecognizedKeys, diff --git a/json_annotation/pubspec.yaml b/json_annotation/pubspec.yaml index 3c55da570..2c3dd4daa 100644 --- a/json_annotation/pubspec.yaml +++ b/json_annotation/pubspec.yaml @@ -1,5 +1,5 @@ name: json_annotation -version: 4.1.0 +version: 4.2.0-dev description: >- Classes and helper functions that support JSON code generation via the `json_serializable` package. diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 059d33b5f..57b3bd69e 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,9 @@ +## 5.1.0-dev + +- Added support for `JsonSerializabel.constructor` to allow specifying an + alternative constructor to invoke when creating a `fromJson` helper. +- Require `json_annotation` `'>=4.2.0 <4.3.0'`. + ## 5.0.2 - Include type arguments when invoking `fromJson` on custom types. diff --git a/json_serializable/README.md b/json_serializable/README.md index 77980e499..193b66147 100644 --- a/json_serializable/README.md +++ b/json_serializable/README.md @@ -86,6 +86,7 @@ is generated: | -------------------------- | ------------------------------------------- | --------------------------- | | any_map | [JsonSerializable.anyMap] | | | checked | [JsonSerializable.checked] | | +| constructor | [JsonSerializable.constructor] | | | create_factory | [JsonSerializable.createFactory] | | | create_to_json | [JsonSerializable.createToJson] | | | disallow_unrecognized_keys | [JsonSerializable.disallowUnrecognizedKeys] | | @@ -103,25 +104,27 @@ is generated: | | | [JsonKey.toJson] | | | | [JsonKey.unknownEnumValue] | -[JsonSerializable.anyMap]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonSerializable/anyMap.html -[JsonSerializable.checked]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonSerializable/checked.html -[JsonSerializable.createFactory]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonSerializable/createFactory.html -[JsonSerializable.createToJson]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonSerializable/createToJson.html -[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html -[JsonSerializable.explicitToJson]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonSerializable/explicitToJson.html -[JsonSerializable.fieldRename]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonSerializable/fieldRename.html -[JsonSerializable.genericArgumentFactories]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonSerializable/genericArgumentFactories.html -[JsonSerializable.ignoreUnannotated]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonSerializable/ignoreUnannotated.html -[JsonSerializable.includeIfNull]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonSerializable/includeIfNull.html -[JsonKey.includeIfNull]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonKey/includeIfNull.html -[JsonKey.defaultValue]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonKey/defaultValue.html -[JsonKey.disallowNullValue]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonKey/disallowNullValue.html -[JsonKey.fromJson]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonKey/fromJson.html -[JsonKey.ignore]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonKey/ignore.html -[JsonKey.name]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonKey/name.html -[JsonKey.required]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonKey/required.html -[JsonKey.toJson]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonKey/toJson.html -[JsonKey.unknownEnumValue]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonKey/unknownEnumValue.html +[JsonSerializable.anyMap]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/anyMap.html +[JsonSerializable.checked]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/checked.html +[JsonSerializable.constructor]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/constructor.html +[JsonSerializable.createFactory]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/createFactory.html +[JsonSerializable.createToJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/createToJson.html +[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html +[JsonSerializable.explicitToJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/explicitToJson.html +[JsonSerializable.fieldRename]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/fieldRename.html +[JsonSerializable.genericArgumentFactories]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/genericArgumentFactories.html +[JsonSerializable.ignoreUnannotated]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/ignoreUnannotated.html +[JsonSerializable.includeIfNull]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/includeIfNull.html +[JsonKey.includeIfNull]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/includeIfNull.html +[JsonKey.defaultValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/defaultValue.html +[JsonKey.disallowNullValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/disallowNullValue.html +[JsonKey.fromJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/fromJson.html +[JsonKey.ignore]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/ignore.html +[JsonKey.name]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/name.html +[JsonKey.required]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/required.html +[JsonKey.toJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/toJson.html +[JsonKey.unknownEnumValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/unknownEnumValue.html + > Note: every `JsonSerializable` field is configurable via `build.yaml` – > see the table for the corresponding key. @@ -151,6 +154,7 @@ targets: # The default value for each is listed. any_map: false checked: false + constructor: '' create_factory: true create_to_json: true disallow_unrecognized_keys: false diff --git a/json_serializable/doc/doc.md b/json_serializable/doc/doc.md index 2e46bf966..c64b22723 100644 --- a/json_serializable/doc/doc.md +++ b/json_serializable/doc/doc.md @@ -2,6 +2,7 @@ | -------------------------- | ------------------------------------------- | --------------------------- | | any_map | [JsonSerializable.anyMap] | | | checked | [JsonSerializable.checked] | | +| constructor | [JsonSerializable.constructor] | | | create_factory | [JsonSerializable.createFactory] | | | create_to_json | [JsonSerializable.createToJson] | | | disallow_unrecognized_keys | [JsonSerializable.disallowUnrecognizedKeys] | | @@ -19,22 +20,23 @@ | | | [JsonKey.toJson] | | | | [JsonKey.unknownEnumValue] | -[JsonSerializable.anyMap]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonSerializable/anyMap.html -[JsonSerializable.checked]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonSerializable/checked.html -[JsonSerializable.createFactory]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonSerializable/createFactory.html -[JsonSerializable.createToJson]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonSerializable/createToJson.html -[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html -[JsonSerializable.explicitToJson]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonSerializable/explicitToJson.html -[JsonSerializable.fieldRename]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonSerializable/fieldRename.html -[JsonSerializable.genericArgumentFactories]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonSerializable/genericArgumentFactories.html -[JsonSerializable.ignoreUnannotated]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonSerializable/ignoreUnannotated.html -[JsonSerializable.includeIfNull]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonSerializable/includeIfNull.html -[JsonKey.includeIfNull]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonKey/includeIfNull.html -[JsonKey.defaultValue]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonKey/defaultValue.html -[JsonKey.disallowNullValue]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonKey/disallowNullValue.html -[JsonKey.fromJson]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonKey/fromJson.html -[JsonKey.ignore]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonKey/ignore.html -[JsonKey.name]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonKey/name.html -[JsonKey.required]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonKey/required.html -[JsonKey.toJson]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonKey/toJson.html -[JsonKey.unknownEnumValue]: https://pub.dev/documentation/json_annotation/4.1.0/json_annotation/JsonKey/unknownEnumValue.html +[JsonSerializable.anyMap]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/anyMap.html +[JsonSerializable.checked]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/checked.html +[JsonSerializable.constructor]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/constructor.html +[JsonSerializable.createFactory]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/createFactory.html +[JsonSerializable.createToJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/createToJson.html +[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html +[JsonSerializable.explicitToJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/explicitToJson.html +[JsonSerializable.fieldRename]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/fieldRename.html +[JsonSerializable.genericArgumentFactories]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/genericArgumentFactories.html +[JsonSerializable.ignoreUnannotated]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/ignoreUnannotated.html +[JsonSerializable.includeIfNull]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/includeIfNull.html +[JsonKey.includeIfNull]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/includeIfNull.html +[JsonKey.defaultValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/defaultValue.html +[JsonKey.disallowNullValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/disallowNullValue.html +[JsonKey.fromJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/fromJson.html +[JsonKey.ignore]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/ignore.html +[JsonKey.name]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/name.html +[JsonKey.required]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/required.html +[JsonKey.toJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/toJson.html +[JsonKey.unknownEnumValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/unknownEnumValue.html diff --git a/json_serializable/lib/src/decode_helper.dart b/json_serializable/lib/src/decode_helper.dart index d5c6439d5..dc8e934be 100644 --- a/json_serializable/lib/src/decode_helper.dart +++ b/json_serializable/lib/src/decode_helper.dart @@ -58,6 +58,7 @@ abstract class DecodeHelper implements HelperCore { final data = _writeConstructorInvocation( element, + config.constructor, accessibleFields.keys, accessibleFields.values .where((fe) => element.lookUpSetter(fe.name, element.library) != null) @@ -242,6 +243,7 @@ abstract class DecodeHelper implements HelperCore { /// been defined by a constructor parameter with the same name. _ConstructorData _writeConstructorInvocation( ClassElement classElement, + String constructorName, Iterable<String> availableConstructorParameters, Iterable<String> writableFields, Map<String, String> unavailableReasons, @@ -250,7 +252,7 @@ _ConstructorData _writeConstructorInvocation( ) { final className = classElement.name; - final ctor = unnamedConstructorOrError(classElement); + final ctor = constructorByName(classElement, constructorName); final usedCtorParamsAndFields = <String>{}; final constructorArguments = <ParameterElement>[]; @@ -287,8 +289,14 @@ _ConstructorData _writeConstructorInvocation( final remainingFieldsForInvocationBody = writableFields.toSet().difference(usedCtorParamsAndFields); + final constructorExtra = constructorName.isEmpty ? '' : '.$constructorName'; + final buffer = StringBuffer() - ..write('$className${genericClassArguments(classElement, false)}('); + ..write( + '$className' + '${genericClassArguments(classElement, false)}' + '$constructorExtra(', + ); if (constructorArguments.isNotEmpty) { buffer ..writeln() diff --git a/json_serializable/lib/src/settings.dart b/json_serializable/lib/src/settings.dart index f2c93535e..f9561ce65 100644 --- a/json_serializable/lib/src/settings.dart +++ b/json_serializable/lib/src/settings.dart @@ -49,6 +49,7 @@ class Settings { ClassConfig get config => ClassConfig( checked: _config.checked ?? ClassConfig.defaults.checked, anyMap: _config.anyMap ?? ClassConfig.defaults.anyMap, + constructor: _config.constructor ?? ClassConfig.defaults.constructor, createFactory: _config.createFactory ?? ClassConfig.defaults.createFactory, createToJson: _config.createToJson ?? ClassConfig.defaults.createToJson, diff --git a/json_serializable/lib/src/type_helpers/config_types.dart b/json_serializable/lib/src/type_helpers/config_types.dart index 3a8d82adb..3d65dc5a0 100644 --- a/json_serializable/lib/src/type_helpers/config_types.dart +++ b/json_serializable/lib/src/type_helpers/config_types.dart @@ -42,6 +42,9 @@ class ClassConfig implements JsonSerializable { @override final bool checked; + @override + final String constructor; + @override final bool createFactory; @@ -71,6 +74,7 @@ class ClassConfig implements JsonSerializable { const ClassConfig({ required this.anyMap, required this.checked, + required this.constructor, required this.createFactory, required this.createToJson, required this.disallowUnrecognizedKeys, @@ -87,6 +91,7 @@ class ClassConfig implements JsonSerializable { static const defaults = ClassConfig( anyMap: false, checked: false, + constructor: '', createFactory: true, createToJson: true, disallowUnrecognizedKeys: false, @@ -116,6 +121,7 @@ Map<String, dynamic> _$JsonSerializableToJson(JsonSerializable instance) => <String, dynamic>{ 'any_map': instance.anyMap, 'checked': instance.checked, + 'constructor': instance.constructor, 'create_factory': instance.createFactory, 'create_to_json': instance.createToJson, 'disallow_unrecognized_keys': instance.disallowUnrecognizedKeys, diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index 2e558f6c3..270a09e54 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -79,6 +79,7 @@ T enumValueForDartObject<T>( JsonSerializable _valueForAnnotation(ConstantReader reader) => JsonSerializable( anyMap: reader.read('anyMap').literalValue as bool?, checked: reader.read('checked').literalValue as bool?, + constructor: reader.read('constructor').literalValue as String?, createFactory: reader.read('createFactory').literalValue as bool?, createToJson: reader.read('createToJson').literalValue as bool?, disallowUnrecognizedKeys: @@ -108,16 +109,18 @@ ClassConfig mergeConfig( final annotation = _valueForAnnotation(reader); assert(config.ctorParamDefaults.isEmpty); - final defaultCtor = unnamedConstructorOrError(classElement); + final constructor = annotation.constructor ?? config.constructor; + final constructorInstance = constructorByName(classElement, constructor); - final paramDefaultValueMap = Map<String, String>.fromEntries(defaultCtor - .parameters - .where((element) => element.hasDefaultValue) - .map((e) => MapEntry(e.name, e.defaultValueCode!))); + final paramDefaultValueMap = Map<String, String>.fromEntries( + constructorInstance.parameters + .where((element) => element.hasDefaultValue) + .map((e) => MapEntry(e.name, e.defaultValueCode!))); return ClassConfig( anyMap: annotation.anyMap ?? config.anyMap, checked: annotation.checked ?? config.checked, + constructor: constructor, createFactory: annotation.createFactory ?? config.createFactory, createToJson: annotation.createToJson ?? config.createToJson, disallowUnrecognizedKeys: @@ -133,16 +136,27 @@ ClassConfig mergeConfig( ); } -ConstructorElement unnamedConstructorOrError(ClassElement classElement) { +ConstructorElement constructorByName(ClassElement classElement, String name) { final className = classElement.name; - final ctor = classElement.unnamedConstructor; - if (ctor == null) { - // TODO: support using another ctor - google/json_serializable.dart#50 - throw InvalidGenerationSourceError( - 'The class `$className` has no default constructor.', - element: classElement, - ); + ConstructorElement? ctor; + if (name.isEmpty) { + ctor = classElement.unnamedConstructor; + if (ctor == null) { + throw InvalidGenerationSourceError( + 'The class `$className` has no default constructor.', + element: classElement, + ); + } + } else { + ctor = classElement.getNamedConstructor(name); + if (ctor == null) { + throw InvalidGenerationSourceError( + 'The class `$className` does not have a constructor with the name ' + '`$name`.', + element: classElement, + ); + } } return ctor; diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index f2fb529e2..21948bbb5 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 5.0.2 +version: 5.1.0-dev description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. @@ -15,7 +15,7 @@ dependencies: # Use a tight version constraint to ensure that a constraint on # `json_annotation` properly constrains all features it provides. - json_annotation: '>=4.1.0 <4.2.0' + json_annotation: '>=4.2.0 <4.3.0' meta: ^1.3.0 path: ^1.8.0 source_gen: ^1.0.0 @@ -31,3 +31,7 @@ dev_dependencies: stack_trace: ^1.10.0 test: ^1.16.0 yaml: ^3.0.0 + +dependency_overrides: + json_annotation: + path: ../json_annotation diff --git a/json_serializable/test/config_test.dart b/json_serializable/test/config_test.dart index ccd28c837..e137b0bbc 100644 --- a/json_serializable/test/config_test.dart +++ b/json_serializable/test/config_test.dart @@ -115,10 +115,21 @@ void main() { final config = Map<String, dynamic>.from(generatorConfigDefaultJson); config[entry.key] = entry.value; - final lastLine = entry.key == 'field_rename' - ? '`42` is not one of the supported values: none, kebab, snake, ' - 'pascal' - : "type 'int' is not a subtype of type 'bool?' in type cast"; + String lastLine; + switch (entry.key) { + case 'field_rename': + lastLine = + '`42` is not one of the supported values: none, kebab, snake, ' + 'pascal'; + break; + case 'constructor': + lastLine = "type 'int' is not a subtype of type 'String?' in type " + 'cast'; + break; + default: + lastLine = + "type 'int' is not a subtype of type 'bool?' in type cast"; + } final matcher = isA<StateError>().having( (v) => v.message, @@ -139,6 +150,7 @@ $lastLine''', const _invalidConfig = { 'any_map': 42, 'checked': 42, + 'constructor': 42, 'create_factory': 42, 'create_to_json': 42, 'disallow_unrecognized_keys': 42, diff --git a/json_serializable/test/integration/integration_test.dart b/json_serializable/test/integration/integration_test.dart index 71786ea4b..42d5b13f7 100644 --- a/json_serializable/test/integration/integration_test.dart +++ b/json_serializable/test/integration/integration_test.dart @@ -52,18 +52,19 @@ void main() { } test('null', () { - roundTripOrder(Order(Category.charmed)..statusCode = StatusCode.success); + roundTripOrder( + Order.custom(Category.charmed)..statusCode = StatusCode.success); }); test('empty', () { - roundTripOrder(Order(Category.strange, const []) + roundTripOrder(Order.custom(Category.strange, const []) ..statusCode = StatusCode.success ..count = 0 ..isRushed = false); }); test('simple', () { - roundTripOrder(Order(Category.top, <Item>[ + roundTripOrder(Order.custom(Category.top, <Item>[ Item(24) ..itemNumber = 42 ..saleDates = [DateTime.now()] @@ -103,7 +104,7 @@ void main() { }); test('platform', () { - final order = Order(Category.charmed) + final order = Order.custom(Category.charmed) ..statusCode = StatusCode.success ..platform = Platform.undefined ..altPlatforms = { @@ -115,7 +116,7 @@ void main() { }); test('homepage', () { - final order = Order(Category.charmed) + final order = Order.custom(Category.charmed) ..platform = Platform.undefined ..statusCode = StatusCode.success ..altPlatforms = { @@ -152,7 +153,7 @@ void main() { }); test('duration toJson', () { - final order = Order(Category.notDiscoveredYet) + final order = Order.custom(Category.notDiscoveredYet) ..statusCode = StatusCode.success ..duration = const Duration( days: 2, @@ -289,4 +290,10 @@ void main() { expect(instance.enumList, [Category.notDiscoveredYet]); expect(instance.enumSet, [Category.notDiscoveredYet]); }); + + test('PrivateConstructor', () { + final value = PrivateConstructor('test'); + + validateRoundTrip(value, (json) => PrivateConstructor.fromJson(json)); + }); } diff --git a/json_serializable/test/integration/json_test_example.dart b/json_serializable/test/integration/json_test_example.dart index d9f43e66b..b4c0ab86c 100644 --- a/json_serializable/test/integration/json_test_example.dart +++ b/json_serializable/test/integration/json_test_example.dart @@ -45,7 +45,7 @@ class Person { deepEquals(houseMap, other.houseMap); } -@JsonSerializable() +@JsonSerializable(constructor: 'custom') class Order { /// Used to test that `disallowNullValues: true` forces `includeIfNull: false` @JsonKey(disallowNullValue: true) @@ -81,7 +81,7 @@ class Order { @JsonKey(ignore: true) bool? shouldBeCached; - Order(this.category, [Iterable<Item>? items]) + Order.custom(this.category, [Iterable<Item>? items]) : items = UnmodifiableListView<Item>( List<Item>.unmodifiable(items ?? const <Item>[])); @@ -218,3 +218,24 @@ class UnknownEnumValue { factory UnknownEnumValue.fromJson(Map<String, dynamic> json) => _$UnknownEnumValueFromJson(json); } + +@JsonSerializable(constructor: '_') +class PrivateConstructor { + static int _id = 0; + + final int id; + final String value; + + PrivateConstructor._(this.id, this.value); + + PrivateConstructor(this.value) : id = _id++; + + factory PrivateConstructor.fromJson(Map<String, dynamic> json) => + _$PrivateConstructorFromJson(json); + + Map<String, dynamic> toJson() => _$PrivateConstructorToJson(this); + + @override + bool operator ==(Object other) => + other is PrivateConstructor && id == other.id && value == other.value; +} diff --git a/json_serializable/test/integration/json_test_example.g.dart b/json_serializable/test/integration/json_test_example.g.dart index b6149a068..a7514fad5 100644 --- a/json_serializable/test/integration/json_test_example.g.dart +++ b/json_serializable/test/integration/json_test_example.g.dart @@ -87,7 +87,7 @@ Order _$OrderFromJson(Map<String, dynamic> json) { json, disallowNullValues: const ['count'], ); - return Order( + return Order.custom( _$enumDecodeNullable(_$CategoryEnumMap, json['category']), (json['items'] as List<dynamic>?) ?.map((e) => Item.fromJson(e as Map<String, dynamic>)), @@ -239,3 +239,15 @@ UnknownEnumValue _$UnknownEnumValueFromJson(Map<String, dynamic> json) => .map((e) => _$enumDecode(_$CategoryEnumMap, e, unknownValue: Category.notDiscoveredYet)) .toSet(); + +PrivateConstructor _$PrivateConstructorFromJson(Map<String, dynamic> json) => + PrivateConstructor._( + json['id'] as int, + json['value'] as String, + ); + +Map<String, dynamic> _$PrivateConstructorToJson(PrivateConstructor instance) => + <String, dynamic>{ + 'id': instance.id, + 'value': instance.value, + }; diff --git a/json_serializable/test/integration/json_test_example.g_any_map.dart b/json_serializable/test/integration/json_test_example.g_any_map.dart index 5cff5c35d..a6ce3663b 100644 --- a/json_serializable/test/integration/json_test_example.g_any_map.dart +++ b/json_serializable/test/integration/json_test_example.g_any_map.dart @@ -47,9 +47,7 @@ class Person { deepEquals(houseMap, other.houseMap); } -@JsonSerializable( - anyMap: true, -) +@JsonSerializable(anyMap: true, constructor: 'custom') class Order { /// Used to test that `disallowNullValues: true` forces `includeIfNull: false` @JsonKey(disallowNullValue: true) @@ -85,7 +83,7 @@ class Order { @JsonKey(ignore: true) bool? shouldBeCached; - Order(this.category, [Iterable<Item>? items]) + Order.custom(this.category, [Iterable<Item>? items]) : items = UnmodifiableListView<Item>( List<Item>.unmodifiable(items ?? const <Item>[])); @@ -228,3 +226,24 @@ class UnknownEnumValue { factory UnknownEnumValue.fromJson(Map<String, dynamic> json) => _$UnknownEnumValueFromJson(json); } + +@JsonSerializable(anyMap: true, constructor: '_') +class PrivateConstructor { + static int _id = 0; + + final int id; + final String value; + + PrivateConstructor._(this.id, this.value); + + PrivateConstructor(this.value) : id = _id++; + + factory PrivateConstructor.fromJson(Map<String, dynamic> json) => + _$PrivateConstructorFromJson(json); + + Map<String, dynamic> toJson() => _$PrivateConstructorToJson(this); + + @override + bool operator ==(Object other) => + other is PrivateConstructor && id == other.id && value == other.value; +} diff --git a/json_serializable/test/integration/json_test_example.g_any_map.g.dart b/json_serializable/test/integration/json_test_example.g_any_map.g.dart index 9abeb7ed8..a3b3d7760 100644 --- a/json_serializable/test/integration/json_test_example.g_any_map.g.dart +++ b/json_serializable/test/integration/json_test_example.g_any_map.g.dart @@ -87,7 +87,7 @@ Order _$OrderFromJson(Map json) { json, disallowNullValues: const ['count'], ); - return Order( + return Order.custom( _$enumDecodeNullable(_$CategoryEnumMap, json['category']), (json['items'] as List<dynamic>?) ?.map((e) => Item.fromJson(Map<String, dynamic>.from(e as Map))), @@ -237,3 +237,15 @@ UnknownEnumValue _$UnknownEnumValueFromJson(Map json) => UnknownEnumValue() .map((e) => _$enumDecode(_$CategoryEnumMap, e, unknownValue: Category.notDiscoveredYet)) .toSet(); + +PrivateConstructor _$PrivateConstructorFromJson(Map json) => + PrivateConstructor._( + json['id'] as int, + json['value'] as String, + ); + +Map<String, dynamic> _$PrivateConstructorToJson(PrivateConstructor instance) => + <String, dynamic>{ + 'id': instance.id, + 'value': instance.value, + }; diff --git a/json_serializable/test/json_serializable_test.dart b/json_serializable/test/json_serializable_test.dart index 3f67990d2..d4f0f68b5 100644 --- a/json_serializable/test/json_serializable_test.dart +++ b/json_serializable/test/json_serializable_test.dart @@ -120,4 +120,5 @@ const _expectedAnnotatedTests = { 'ValidToFromFuncClassStatic', 'WithANonCtorGetter', 'WithANonCtorGetterChecked', + 'WrongConstructorNameClass', }; diff --git a/json_serializable/test/shared_config.dart b/json_serializable/test/shared_config.dart index c4876e99b..09311ad10 100644 --- a/json_serializable/test/shared_config.dart +++ b/json_serializable/test/shared_config.dart @@ -15,6 +15,7 @@ final generatorConfigNonDefaultJson = Map<String, dynamic>.unmodifiable(const JsonSerializable( anyMap: true, checked: true, + constructor: 'something', createFactory: false, createToJson: false, disallowUnrecognizedKeys: true, diff --git a/json_serializable/test/src/_json_serializable_test_input.dart b/json_serializable/test/src/_json_serializable_test_input.dart index 09c972b93..d7e5ceced 100644 --- a/json_serializable/test/src/_json_serializable_test_input.dart +++ b/json_serializable/test/src/_json_serializable_test_input.dart @@ -37,7 +37,6 @@ OnlyStaticMembers _$OnlyStaticMembersFromJson(Map<String, dynamic> json) => Map<String, dynamic> _$OnlyStaticMembersToJson(OnlyStaticMembers instance) => <String, dynamic>{}; ''', - configurations: ['default'], ) @JsonSerializable() class OnlyStaticMembers { @@ -142,7 +141,6 @@ Map<String, dynamic> _$FinalFieldsNotSetInCtorToJson( FinalFieldsNotSetInCtor instance) => <String, dynamic>{}; ''', - configurations: ['default'], ) @JsonSerializable() class FinalFieldsNotSetInCtor { @@ -173,7 +171,6 @@ class SetSupport { Could not generate `toJson` code for `watch`. To support the type `Stopwatch` you can: $converterOrKeyInstructions''', - configurations: ['default'], ) @JsonSerializable(createFactory: false) class NoSerializeFieldType { @@ -185,7 +182,6 @@ class NoSerializeFieldType { Could not generate `fromJson` code for `watch`. To support the type `Stopwatch` you can: $converterOrKeyInstructions''', - configurations: ['default'], ) @JsonSerializable(createToJson: false) class NoDeserializeFieldType { @@ -196,7 +192,6 @@ class NoDeserializeFieldType { ''' Could not generate `toJson` code for `durationDateTimeMap` because of type `Duration`. Map keys must be one of: Object, dynamic, enum, String, BigInt, DateTime, int, Uri.''', - configurations: ['default'], ) @JsonSerializable(createFactory: false) class NoSerializeBadKey { @@ -207,7 +202,6 @@ class NoSerializeBadKey { ''' Could not generate `fromJson` code for `durationDateTimeMap` because of type `Duration`. Map keys must be one of: Object, dynamic, enum, String, BigInt, DateTime, int, Uri.''', - configurations: ['default'], ) @JsonSerializable(createToJson: false) class NoDeserializeBadKey { @@ -232,7 +226,6 @@ Map<String, dynamic> _$IncludeIfNullOverrideToJson( return val; } ''', - configurations: ['default'], ) @JsonSerializable(createFactory: false, includeIfNull: false) class IncludeIfNullOverride { @@ -244,7 +237,6 @@ class IncludeIfNullOverride { // https://github.com/google/json_serializable.dart/issues/7 regression @ShouldThrow( 'The class `NoCtorClass` has no default constructor.', - configurations: ['default'], ) @JsonSerializable() class NoCtorClass { @@ -255,6 +247,16 @@ class NoCtorClass { throw UnimplementedError(); } +// https://github.com/google/json_serializable.dart/issues/7 regression +@ShouldThrow( + 'The class `WrongConstructorNameClass` does not have a constructor with the ' + 'name `bob`.', +) +@JsonSerializable(constructor: 'bob') +class WrongConstructorNameClass { + late final int member; +} + @ShouldThrow( 'More than one field has the JSON key for name "str".', element: 'str', diff --git a/json_serializable/test/src/setter_test_input.dart b/json_serializable/test/src/setter_test_input.dart index 6d7ea9138..f9dddf4bd 100644 --- a/json_serializable/test/src/setter_test_input.dart +++ b/json_serializable/test/src/setter_test_input.dart @@ -8,7 +8,6 @@ Map<String, dynamic> _$JustSetterToJson(JustSetter instance) => <String, dynamic>{}; ''', expectedLogItems: ['Setters are ignored: JustSetter.someSetter'], - configurations: ['default'], ) @JsonSerializable() class JustSetter { @@ -21,7 +20,6 @@ JustSetterNoToJson _$JustSetterNoToJsonFromJson(Map<String, dynamic> json) => JustSetterNoToJson(); ''', expectedLogItems: ['Setters are ignored: JustSetterNoToJson.someSetter'], - configurations: ['default'], ) @JsonSerializable(createToJson: false) class JustSetterNoToJson { @@ -35,7 +33,6 @@ Map<String, dynamic> _$JustSetterNoFromJsonToJson( <String, dynamic>{}; ''', expectedLogItems: ['Setters are ignored: JustSetterNoFromJson.someSetter'], - configurations: ['default'], ) @JsonSerializable(createFactory: false) class JustSetterNoFromJson { diff --git a/json_serializable/test/src/to_from_json_test_input.dart b/json_serializable/test/src/to_from_json_test_input.dart index 1f6a6245f..6658ce039 100644 --- a/json_serializable/test/src/to_from_json_test_input.dart +++ b/json_serializable/test/src/to_from_json_test_input.dart @@ -49,7 +49,6 @@ Map<String, dynamic> _$ValidToFromFuncClassStaticToJson( 'field': ValidToFromFuncClassStatic._staticFunc(instance.field), }; ''', - configurations: ['default'], ) @JsonSerializable() class ValidToFromFuncClassStatic { @@ -151,7 +150,6 @@ class ObjectConvertMethods { @ShouldGenerate( "_toDynamic(json['field'])", contains: true, - configurations: ['default'], ) @JsonSerializable() class DynamicConvertMethods { @@ -164,7 +162,6 @@ String _toString(String input) => 'null'; @ShouldGenerate( "_toString(json['field'] as String)", contains: true, - configurations: ['default'], ) @JsonSerializable() class TypedConvertMethods { @@ -188,7 +185,6 @@ Map<String, dynamic> _$ToJsonNullableFalseIncludeIfNullFalseToJson( return val; } ''', - configurations: ['default'], ) @JsonSerializable(createFactory: false) class ToJsonNullableFalseIncludeIfNullFalse { @@ -211,7 +207,6 @@ FromDynamicCollection _$FromDynamicCollectionFromJson( ..listField = _fromDynamicList(json['listField'] as List) ..iterableField = _fromDynamicIterable(json['iterableField'] as List); ''', - configurations: ['default'], ) @JsonSerializable(createToJson: false) class FromDynamicCollection { @@ -239,7 +234,6 @@ FromNullableDynamicCollection _$FromNullableDynamicCollectionFromJson( ..iterableField = _fromNullableDynamicIterable(json['iterableField'] as List?); ''', - configurations: ['default'], ) @JsonSerializable(createToJson: false) class FromNullableDynamicCollection { diff --git a/json_serializable/test/test_sources/test_sources.dart b/json_serializable/test/test_sources/test_sources.dart index 8911ddfd8..c0d93c839 100644 --- a/json_serializable/test/test_sources/test_sources.dart +++ b/json_serializable/test/test_sources/test_sources.dart @@ -2,6 +2,9 @@ import 'package:json_annotation/json_annotation.dart'; @JsonSerializable() class ConfigurationImplicitDefaults { + ConfigurationImplicitDefaults(); + ConfigurationImplicitDefaults.something(); + int? field; } @@ -9,6 +12,7 @@ class ConfigurationImplicitDefaults { @JsonSerializable( anyMap: false, checked: false, + constructor: '', createFactory: true, createToJson: true, disallowUnrecognizedKeys: false, From e06e380711b40f5651724ae53bb3a7d07a917442 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@google.com> Date: Fri, 24 Sep 2021 08:21:25 -0700 Subject: [PATCH 339/569] Use new casing-utils from source_helper Drop internal implementations and tests --- json_serializable/lib/src/helper_core.dart | 3 +- json_serializable/lib/src/json_key_utils.dart | 6 +- json_serializable/lib/src/utils.dart | 27 -------- json_serializable/pubspec.yaml | 2 +- json_serializable/test/utils_test.dart | 62 ------------------- json_serializable/tool/doc_builder.dart | 4 +- 6 files changed, 7 insertions(+), 97 deletions(-) delete mode 100644 json_serializable/test/utils_test.dart diff --git a/json_serializable/lib/src/helper_core.dart b/json_serializable/lib/src/helper_core.dart index af29bb25c..df50f0455 100644 --- a/json_serializable/lib/src/helper_core.dart +++ b/json_serializable/lib/src/helper_core.dart @@ -14,7 +14,6 @@ import 'type_helper.dart'; import 'type_helper_ctx.dart'; import 'type_helpers/config_types.dart'; import 'unsupported_type_error.dart'; -import 'utils.dart'; abstract class HelperCore { final ClassElement element; @@ -38,7 +37,7 @@ abstract class HelperCore { escapeDartString(nameAccess(field)); @protected - String get prefix => '_\$${nonPrivateName(element.name)}'; + String get prefix => '_\$${element.name.nonPrivate}'; /// Returns a [String] representing the type arguments that exist on /// [element]. diff --git a/json_serializable/lib/src/json_key_utils.dart b/json_serializable/lib/src/json_key_utils.dart index 11ef9a037..26a74b33f 100644 --- a/json_serializable/lib/src/json_key_utils.dart +++ b/json_serializable/lib/src/json_key_utils.dart @@ -245,11 +245,11 @@ String _encodedFieldName( case FieldRename.none: return fieldElement.name; case FieldRename.snake: - return snakeCase(fieldElement.name); + return fieldElement.name.snake; case FieldRename.kebab: - return kebabCase(fieldElement.name); + return fieldElement.name.kebab; case FieldRename.pascal: - return pascalCase(fieldElement.name); + return fieldElement.name.pascal; default: throw ArgumentError.value( classAnnotation, diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index 270a09e54..1f41232e8 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -26,33 +26,6 @@ ConstantReader jsonKeyAnnotation(FieldElement element) => bool hasJsonKeyAnnotation(FieldElement element) => _jsonKeyAnnotation(element) != null; -final _upperCase = RegExp('[A-Z]'); - -String kebabCase(String input) => _fixCase(input, '-'); - -String snakeCase(String input) => _fixCase(input, '_'); - -String pascalCase(String input) { - if (input.isEmpty) { - return ''; - } - - return input[0].toUpperCase() + input.substring(1); -} - -String _fixCase(String input, String separator) => - input.replaceAllMapped(_upperCase, (match) { - var lower = match.group(0)!.toLowerCase(); - - if (match.start > 0) { - lower = '$separator$lower'; - } - - return lower; - }); - -String nonPrivateName(String input) => input.replaceFirst(RegExp(r'^_*'), ''); - Never throwUnsupported(FieldElement element, String message) => throw InvalidGenerationSourceError( 'Error with `@JsonKey` on `${element.name}`. $message', diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 21948bbb5..658734d9d 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -19,7 +19,7 @@ dependencies: meta: ^1.3.0 path: ^1.8.0 source_gen: ^1.0.0 - source_helper: ^1.2.1 + source_helper: ^1.3.0 dev_dependencies: build_runner: ^2.0.0 diff --git a/json_serializable/test/utils_test.dart b/json_serializable/test/utils_test.dart deleted file mode 100644 index 23fbaaa5b..000000000 --- a/json_serializable/test/utils_test.dart +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright (c) 2018, 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. - -@TestOn('vm') -import 'package:json_serializable/src/utils.dart'; -import 'package:test/test.dart'; - -const _kebabItems = { - 'simple': 'simple', - 'twoWords': 'two-words', - 'FirstBig': 'first-big' -}; - -const _pascalItems = { - 'simple': 'Simple', - 'twoWords': 'TwoWords', - 'FirstBig': 'FirstBig' -}; - -const _snakeItems = { - 'simple': 'simple', - 'twoWords': 'two_words', - 'FirstBig': 'first_big' -}; - -void main() { - group('kebab', () { - for (final entry in _kebabItems.entries) { - test('"${entry.key}"', () { - expect(kebabCase(entry.key), entry.value); - }); - } - }); - - group('pascal', () { - for (final entry in _pascalItems.entries) { - test('"${entry.key}"', () { - expect(pascalCase(entry.key), entry.value); - }); - } - }); - - group('snake', () { - for (final entry in _snakeItems.entries) { - test('"${entry.key}"', () { - expect(snakeCase(entry.key), entry.value); - }); - } - }); - - group('nonPrivateName', () { - test('removes leading underscores', () { - final name = nonPrivateName('__hello__world__'); - expect(name, equals('hello__world__')); - }); - test('does not changes public names', () { - final name = nonPrivateName('HelloWorld'); - expect(name, equals('HelloWorld')); - }); - }); -} diff --git a/json_serializable/tool/doc_builder.dart b/json_serializable/tool/doc_builder.dart index 267690f7a..69241ae0b 100644 --- a/json_serializable/tool/doc_builder.dart +++ b/json_serializable/tool/doc_builder.dart @@ -5,9 +5,9 @@ import 'dart:async'; import 'package:analyzer/dart/element/element.dart'; import 'package:build/build.dart'; -import 'package:json_serializable/src/utils.dart'; import 'package:pub_semver/pub_semver.dart'; import 'package:source_gen/source_gen.dart'; +import 'package:source_helper/source_helper.dart'; import 'package:yaml/yaml.dart'; Builder docBuilder([_]) => _DocBuilder(); @@ -144,7 +144,7 @@ class _FieldInfo implements Comparable<_FieldInfo> { return ''; } - return snakeCase(_classField!.name); + return _classField!.name.snake; } _FieldInfo(this._keyField, this._classField); From 83b71d2573faa0f76f816dc3fea0c6186ec7d148 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@google.com> Date: Fri, 24 Sep 2021 09:41:24 -0700 Subject: [PATCH 340/569] TypeHelperCtx: convert property to late final field --- json_serializable/lib/src/type_helper_ctx.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/json_serializable/lib/src/type_helper_ctx.dart b/json_serializable/lib/src/type_helper_ctx.dart index c8016ba2b..1d7f9d7a1 100644 --- a/json_serializable/lib/src/type_helper_ctx.dart +++ b/json_serializable/lib/src/type_helper_ctx.dart @@ -40,7 +40,7 @@ class TypeHelperCtx @override ConvertData? get deserializeConvertData => _pairFromContext.fromJson; - _ConvertPair get _pairFromContext => _ConvertPair(fieldElement); + late final _pairFromContext = _ConvertPair(fieldElement); @override void addMember(String memberContent) { From a61658de33d7d77f4207d0cd7398a02805bebd15 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Mon, 27 Sep 2021 20:38:38 -0700 Subject: [PATCH 341/569] Add @JsonEnum annotation (#989) Allows generating the associated helpers without requiring usage as a field in a @JsonSerializable class Fixes https://github.com/google/json_serializable.dart/issues/778 --- json_annotation/CHANGELOG.md | 1 + json_annotation/lib/json_annotation.dart | 1 + json_annotation/lib/src/json_enum.dart | 13 ++++ json_serializable/CHANGELOG.md | 3 + json_serializable/lib/json_serializable.dart | 1 + .../lib/src/json_enum_generator.dart | 33 ++++++++++ .../lib/src/json_part_builder.dart | 63 ++++++++++++++++++- .../lib/src/json_serializable_generator.dart | 2 +- .../lib/src/type_helpers/enum_helper.dart | 10 +-- .../lib/src/type_helpers/json_helper.dart | 3 + .../test/integration/integration_test.dart | 4 ++ .../test/integration/json_test_example.dart | 14 +++++ .../test/integration/json_test_example.g.dart | 7 +++ .../json_test_example.g_any_map.dart | 14 +++++ .../json_test_example.g_any_map.g.dart | 7 +++ .../test/json_serializable_test.dart | 1 + .../src/_json_serializable_test_input.dart | 5 +- 17 files changed, 174 insertions(+), 8 deletions(-) create mode 100644 json_annotation/lib/src/json_enum.dart create mode 100644 json_serializable/lib/src/json_enum_generator.dart diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index 47ef110b6..0740c1578 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -2,6 +2,7 @@ - Added `JsonSerializabel.constructor` field to allow specifying an alternative constructor to invoke when creating a `fromJson` helper. +- Added `JsonEnum` for annotating `enum` types. ## 4.1.0 diff --git a/json_annotation/lib/json_annotation.dart b/json_annotation/lib/json_annotation.dart index 9d1c39706..d0e3bb017 100644 --- a/json_annotation/lib/json_annotation.dart +++ b/json_annotation/lib/json_annotation.dart @@ -13,6 +13,7 @@ library json_annotation; export 'src/allowed_keys_helpers.dart'; export 'src/checked_helpers.dart'; export 'src/json_converter.dart'; +export 'src/json_enum.dart'; export 'src/json_key.dart'; export 'src/json_literal.dart'; export 'src/json_serializable.dart'; diff --git a/json_annotation/lib/src/json_enum.dart b/json_annotation/lib/src/json_enum.dart new file mode 100644 index 000000000..1afb1c134 --- /dev/null +++ b/json_annotation/lib/src/json_enum.dart @@ -0,0 +1,13 @@ +// 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'; + +/// When applied to `enum` definitions, causes the corresponding private +// `_$EnumNameEnumMap` and `_$enumDecode` helpers to be generated, even if the +// `enum` is not referenced elsewhere in generated code. +@Target({TargetKind.enumType}) +class JsonEnum { + const JsonEnum(); +} diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 57b3bd69e..0df47cc7f 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -2,6 +2,9 @@ - Added support for `JsonSerializabel.constructor` to allow specifying an alternative constructor to invoke when creating a `fromJson` helper. +- Support the new `@JsonEnum` annotation by generating the corresponding private + `_$EnumNameEnumMap` and `_$enumDecode` helpers, even if the `enum` is not + referenced elsewhere in generated code. - Require `json_annotation` `'>=4.2.0 <4.3.0'`. ## 5.0.2 diff --git a/json_serializable/lib/json_serializable.dart b/json_serializable/lib/json_serializable.dart index 094597df6..ec938a371 100644 --- a/json_serializable/lib/json_serializable.dart +++ b/json_serializable/lib/json_serializable.dart @@ -2,5 +2,6 @@ // 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. +export 'src/json_enum_generator.dart' show JsonEnumGenerator; export 'src/json_literal_generator.dart' show JsonLiteralGenerator; export 'src/json_serializable_generator.dart' show JsonSerializableGenerator; diff --git a/json_serializable/lib/src/json_enum_generator.dart b/json_serializable/lib/src/json_enum_generator.dart new file mode 100644 index 000000000..65e7979bb --- /dev/null +++ b/json_serializable/lib/src/json_enum_generator.dart @@ -0,0 +1,33 @@ +// Copyright (c) 2017, 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:analyzer/dart/element/element.dart'; +import 'package:build/build.dart'; +import 'package:json_annotation/json_annotation.dart'; +import 'package:source_gen/source_gen.dart'; + +import 'type_helpers/enum_helper.dart'; + +class JsonEnumGenerator extends GeneratorForAnnotation<JsonEnum> { + const JsonEnumGenerator(); + + @override + List<String> generateForAnnotatedElement( + Element element, + ConstantReader annotation, + BuildStep buildStep, + ) { + if (element is! ClassElement || !element.isEnum) { + throw InvalidGenerationSourceError( + '`@JsonEnum` can only be used on enum elements.', + element: element, + ); + } + + return [ + enumDecodeHelper, + enumValueMapFromType(element.thisType)!, + ]; + } +} diff --git a/json_serializable/lib/src/json_part_builder.dart b/json_serializable/lib/src/json_part_builder.dart index 8cc040444..bcd7a5994 100644 --- a/json_serializable/lib/src/json_part_builder.dart +++ b/json_serializable/lib/src/json_part_builder.dart @@ -6,6 +6,7 @@ import 'package:build/build.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:source_gen/source_gen.dart'; +import 'json_enum_generator.dart'; import 'json_literal_generator.dart'; import 'json_serializable_generator.dart'; import 'settings.dart'; @@ -23,10 +24,70 @@ Builder jsonPartBuilder({ return SharedPartBuilder( [ - JsonSerializableGenerator.fromSettings(settings), + _UnifiedGenerator([ + JsonSerializableGenerator.fromSettings(settings), + const JsonEnumGenerator(), + ]), const JsonLiteralGenerator(), ], 'json_serializable', formatOutput: formatOutput, ); } + +/// Allows exposing separate [GeneratorForAnnotation] instances as one +/// generator. +/// +/// Output can be merged while keeping implementations separate. +class _UnifiedGenerator extends Generator { + final List<GeneratorForAnnotation> _generators; + + _UnifiedGenerator(this._generators); + + @override + Future<String?> generate(LibraryReader library, BuildStep buildStep) async { + final values = <String>{}; + + for (var generator in _generators) { + for (var annotatedElement + in library.annotatedWith(generator.typeChecker)) { + final generatedValue = generator.generateForAnnotatedElement( + annotatedElement.element, annotatedElement.annotation, buildStep); + for (var value in _normalizeGeneratorOutput(generatedValue)) { + assert(value.length == value.trim().length); + values.add(value); + } + } + } + + return values.join('\n\n'); + } + + @override + String toString() => 'JsonSerializableGenerator'; +} + +// Borrowed from `package:source_gen` +Iterable<String> _normalizeGeneratorOutput(Object? value) { + if (value == null) { + return const []; + } else if (value is String) { + value = [value]; + } + + if (value is Iterable) { + return value.where((e) => e != null).map((e) { + if (e is String) { + return e.trim(); + } + + throw _argError(e as Object); + }).where((e) => e.isNotEmpty); + } + throw _argError(value); +} + +// Borrowed from `package:source_gen` +ArgumentError _argError(Object value) => ArgumentError( + 'Must be a String or be an Iterable containing String values. ' + 'Found `${Error.safeToString(value)}` (${value.runtimeType}).'); diff --git a/json_serializable/lib/src/json_serializable_generator.dart b/json_serializable/lib/src/json_serializable_generator.dart index 0513a7716..13a4b16e4 100644 --- a/json_serializable/lib/src/json_serializable_generator.dart +++ b/json_serializable/lib/src/json_serializable_generator.dart @@ -69,7 +69,7 @@ class JsonSerializableGenerator ); } - if (element is! ClassElement) { + if (element is! ClassElement || element.isEnum) { throw InvalidGenerationSourceError( '`@JsonSerializable` can only be used on classes.', element: element, diff --git a/json_serializable/lib/src/type_helpers/enum_helper.dart b/json_serializable/lib/src/type_helpers/enum_helper.dart index 60a82699e..23723436f 100644 --- a/json_serializable/lib/src/type_helpers/enum_helper.dart +++ b/json_serializable/lib/src/type_helpers/enum_helper.dart @@ -21,7 +21,7 @@ class EnumHelper extends TypeHelper<TypeHelperContextWithConfig> { String expression, TypeHelperContextWithConfig context, ) { - final memberContent = _enumValueMapFromType(targetType); + final memberContent = enumValueMapFromType(targetType); if (memberContent == null) { return null; @@ -39,13 +39,13 @@ class EnumHelper extends TypeHelper<TypeHelperContextWithConfig> { TypeHelperContextWithConfig context, bool defaultProvided, ) { - final memberContent = _enumValueMapFromType(targetType); + final memberContent = enumValueMapFromType(targetType); if (memberContent == null) { return null; } - context.addMember(_enumDecodeHelper); + context.addMember(enumDecodeHelper); String functionName; if (targetType.isNullableType || defaultProvided) { @@ -72,7 +72,7 @@ class EnumHelper extends TypeHelper<TypeHelperContextWithConfig> { String _constMapName(DartType targetType) => '_\$${targetType.element!.name}EnumMap'; -String? _enumValueMapFromType(DartType targetType) { +String? enumValueMapFromType(DartType targetType) { final enumMap = enumFieldsMap(targetType); if (enumMap == null) { @@ -87,7 +87,7 @@ String? _enumValueMapFromType(DartType targetType) { return 'const ${_constMapName(targetType)} = {\n$items\n};'; } -const _enumDecodeHelper = r''' +const enumDecodeHelper = r''' K _$enumDecode<K, V>( Map<K, V> enumValues, Object? source, { diff --git a/json_serializable/lib/src/type_helpers/json_helper.dart b/json_serializable/lib/src/type_helpers/json_helper.dart index 305017fef..48b5243af 100644 --- a/json_serializable/lib/src/type_helpers/json_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_helper.dart @@ -270,6 +270,9 @@ InterfaceType? _instantiate( } ClassConfig? _annotation(ClassConfig config, InterfaceType source) { + if (source.isEnum) { + return null; + } final annotations = const TypeChecker.fromRuntime(JsonSerializable) .annotationsOfExact(source.element, throwOnUnresolved: false) .toList(); diff --git a/json_serializable/test/integration/integration_test.dart b/json_serializable/test/integration/integration_test.dart index 42d5b13f7..ab480132f 100644 --- a/json_serializable/test/integration/integration_test.dart +++ b/json_serializable/test/integration/integration_test.dart @@ -296,4 +296,8 @@ void main() { validateRoundTrip(value, (json) => PrivateConstructor.fromJson(json)); }); + + test('enum helpers', () { + expect(standAloneEnumKeys, ['a', 'b', 'g', 'd']); + }); } diff --git a/json_serializable/test/integration/json_test_example.dart b/json_serializable/test/integration/json_test_example.dart index b4c0ab86c..87fe97129 100644 --- a/json_serializable/test/integration/json_test_example.dart +++ b/json_serializable/test/integration/json_test_example.dart @@ -239,3 +239,17 @@ class PrivateConstructor { bool operator ==(Object other) => other is PrivateConstructor && id == other.id && value == other.value; } + +@JsonEnum() +enum StandAloneEnum { + @JsonValue('a') + alpha, + @JsonValue('b') + beta, + @JsonValue('g') + gamma, + @JsonValue('d') + delta, +} + +Iterable<String> get standAloneEnumKeys => _$StandAloneEnumEnumMap.values; diff --git a/json_serializable/test/integration/json_test_example.g.dart b/json_serializable/test/integration/json_test_example.g.dart index a7514fad5..77f9662ef 100644 --- a/json_serializable/test/integration/json_test_example.g.dart +++ b/json_serializable/test/integration/json_test_example.g.dart @@ -251,3 +251,10 @@ Map<String, dynamic> _$PrivateConstructorToJson(PrivateConstructor instance) => 'id': instance.id, 'value': instance.value, }; + +const _$StandAloneEnumEnumMap = { + StandAloneEnum.alpha: 'a', + StandAloneEnum.beta: 'b', + StandAloneEnum.gamma: 'g', + StandAloneEnum.delta: 'd', +}; diff --git a/json_serializable/test/integration/json_test_example.g_any_map.dart b/json_serializable/test/integration/json_test_example.g_any_map.dart index a6ce3663b..ea83e1222 100644 --- a/json_serializable/test/integration/json_test_example.g_any_map.dart +++ b/json_serializable/test/integration/json_test_example.g_any_map.dart @@ -247,3 +247,17 @@ class PrivateConstructor { bool operator ==(Object other) => other is PrivateConstructor && id == other.id && value == other.value; } + +@JsonEnum() +enum StandAloneEnum { + @JsonValue('a') + alpha, + @JsonValue('b') + beta, + @JsonValue('g') + gamma, + @JsonValue('d') + delta, +} + +Iterable<String> get standAloneEnumKeys => _$StandAloneEnumEnumMap.values; diff --git a/json_serializable/test/integration/json_test_example.g_any_map.g.dart b/json_serializable/test/integration/json_test_example.g_any_map.g.dart index a3b3d7760..4b43ef614 100644 --- a/json_serializable/test/integration/json_test_example.g_any_map.g.dart +++ b/json_serializable/test/integration/json_test_example.g_any_map.g.dart @@ -249,3 +249,10 @@ Map<String, dynamic> _$PrivateConstructorToJson(PrivateConstructor instance) => 'id': instance.id, 'value': instance.value, }; + +const _$StandAloneEnumEnumMap = { + StandAloneEnum.alpha: 'a', + StandAloneEnum.beta: 'b', + StandAloneEnum.gamma: 'g', + StandAloneEnum.delta: 'd', +}; diff --git a/json_serializable/test/json_serializable_test.dart b/json_serializable/test/json_serializable_test.dart index d4f0f68b5..5deed8c97 100644 --- a/json_serializable/test/json_serializable_test.dart +++ b/json_serializable/test/json_serializable_test.dart @@ -24,6 +24,7 @@ Future<void> main() async { const _expectedAnnotatedTests = { 'annotatedMethod', + 'unsupportedEnum', 'BadFromFuncReturnType', 'BadNoArgs', 'BadOneNamed', diff --git a/json_serializable/test/src/_json_serializable_test_input.dart b/json_serializable/test/src/_json_serializable_test_input.dart index d7e5ceced..2e37b4770 100644 --- a/json_serializable/test/src/_json_serializable_test_input.dart +++ b/json_serializable/test/src/_json_serializable_test_input.dart @@ -5,7 +5,6 @@ import 'dart:collection'; import 'package:json_annotation/json_annotation.dart'; -// ignore: import_of_legacy_library_into_null_safe import 'package:source_gen_test/annotations.dart'; part 'checked_test_input.dart'; @@ -25,6 +24,10 @@ part 'unknown_enum_value_test_input.dart'; @JsonSerializable() // ignore: invalid_annotation_target const theAnswer = 42; +@ShouldThrow('`@JsonSerializable` can only be used on classes.') +@JsonSerializable() // ignore: invalid_annotation_target +enum unsupportedEnum { not, valid } + @ShouldThrow('`@JsonSerializable` can only be used on classes.') @JsonSerializable() // ignore: invalid_annotation_target Object annotatedMethod() => throw UnimplementedError(); From 532c7d8aee888b7591273e957c27ddbeb22104ff Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Tue, 28 Sep 2021 11:59:15 -0700 Subject: [PATCH 342/569] Improve doc comment on _UnifiedGenerator (#990) --- json_serializable/lib/src/json_part_builder.dart | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/json_serializable/lib/src/json_part_builder.dart b/json_serializable/lib/src/json_part_builder.dart index bcd7a5994..d4c5d3cfe 100644 --- a/json_serializable/lib/src/json_part_builder.dart +++ b/json_serializable/lib/src/json_part_builder.dart @@ -38,7 +38,12 @@ Builder jsonPartBuilder({ /// Allows exposing separate [GeneratorForAnnotation] instances as one /// generator. /// -/// Output can be merged while keeping implementations separate. +/// We want duplicate items to be merged if folks use both `@JsonEnum` and +/// `@JsonSerializable` so we don't get duplicate enum helper functions. +/// +/// This can only be done if the output is merged into one generator. +/// +/// This class allows us to keep the implementations separate. class _UnifiedGenerator extends Generator { final List<GeneratorForAnnotation> _generators; From d44d99361d1c2eda52145f4b9f31a6e30a83962c Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@google.com> Date: Tue, 28 Sep 2021 13:51:35 -0700 Subject: [PATCH 343/569] Add tests for improper @JsonEnum usage --- .../test/json_serializable_test.dart | 15 +++++++++++++-- .../test/src/_json_enum_test_input.dart | 10 ++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 json_serializable/test/src/_json_enum_test_input.dart diff --git a/json_serializable/test/json_serializable_test.dart b/json_serializable/test/json_serializable_test.dart index 5deed8c97..b7dd734ff 100644 --- a/json_serializable/test/json_serializable_test.dart +++ b/json_serializable/test/json_serializable_test.dart @@ -10,16 +10,27 @@ import 'package:test/test.dart'; Future<void> main() async { initializeBuildLogTracking(); - final reader = await initializeLibraryReaderForDirectory( + final jsonSerializableTestReader = await initializeLibraryReaderForDirectory( p.join('test', 'src'), '_json_serializable_test_input.dart', ); testAnnotatedElements( - reader, + jsonSerializableTestReader, JsonSerializableGenerator(), expectedAnnotatedTests: _expectedAnnotatedTests, ); + + final jsonEnumTestReader = await initializeLibraryReaderForDirectory( + p.join('test', 'src'), + '_json_enum_test_input.dart', + ); + + testAnnotatedElements( + jsonEnumTestReader, + const JsonEnumGenerator(), + expectedAnnotatedTests: {'UnsupportedClass'}, + ); } const _expectedAnnotatedTests = { diff --git a/json_serializable/test/src/_json_enum_test_input.dart b/json_serializable/test/src/_json_enum_test_input.dart new file mode 100644 index 000000000..bf3f96050 --- /dev/null +++ b/json_serializable/test/src/_json_enum_test_input.dart @@ -0,0 +1,10 @@ +// Copyright (c) 2018, 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:json_annotation/json_annotation.dart'; +import 'package:source_gen_test/annotations.dart'; + +@ShouldThrow('`@JsonEnum` can only be used on enum elements.') +@JsonEnum() // ignore: invalid_annotation_target +class UnsupportedClass {} From c3e979434ce82c5f507285b60e7f248009060703 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@google.com> Date: Tue, 28 Sep 2021 14:14:22 -0700 Subject: [PATCH 344/569] Make generating enum helpers opt-in for @JsonEnum Allows configuring other aspects of enum generation without also creating the helpers --- json_annotation/lib/src/json_enum.dart | 18 ++++++++++++++---- json_serializable/CHANGELOG.md | 4 +--- .../lib/src/json_enum_generator.dart | 10 ++++++++++ .../test/integration/json_test_example.dart | 2 +- .../json_test_example.g_any_map.dart | 2 +- 5 files changed, 27 insertions(+), 9 deletions(-) diff --git a/json_annotation/lib/src/json_enum.dart b/json_annotation/lib/src/json_enum.dart index 1afb1c134..c35a84b1b 100644 --- a/json_annotation/lib/src/json_enum.dart +++ b/json_annotation/lib/src/json_enum.dart @@ -4,10 +4,20 @@ import 'package:meta/meta_meta.dart'; -/// When applied to `enum` definitions, causes the corresponding private -// `_$EnumNameEnumMap` and `_$enumDecode` helpers to be generated, even if the -// `enum` is not referenced elsewhere in generated code. +import 'json_serializable.dart'; + +/// Allows configuration of how `enum` elements are treated as JSON. @Target({TargetKind.enumType}) class JsonEnum { - const JsonEnum(); + const JsonEnum({ + this.alwaysCreate = false, + }); + + /// If `true`, `_$EnumNameEnumMap` and `_$enumDecode` are generated for the + /// 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; } diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 0df47cc7f..644ac8945 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -2,9 +2,7 @@ - Added support for `JsonSerializabel.constructor` to allow specifying an alternative constructor to invoke when creating a `fromJson` helper. -- Support the new `@JsonEnum` annotation by generating the corresponding private - `_$EnumNameEnumMap` and `_$enumDecode` helpers, even if the `enum` is not - referenced elsewhere in generated code. +- Support the new `@JsonEnum` annotation in `package:json_annotation`. - Require `json_annotation` `'>=4.2.0 <4.3.0'`. ## 5.0.2 diff --git a/json_serializable/lib/src/json_enum_generator.dart b/json_serializable/lib/src/json_enum_generator.dart index 65e7979bb..c3931c44b 100644 --- a/json_serializable/lib/src/json_enum_generator.dart +++ b/json_serializable/lib/src/json_enum_generator.dart @@ -25,9 +25,19 @@ class JsonEnumGenerator extends GeneratorForAnnotation<JsonEnum> { ); } + final jsonEnum = _fromAnnotation(annotation); + + if (!jsonEnum.alwaysCreate) { + return const []; + } + return [ enumDecodeHelper, enumValueMapFromType(element.thisType)!, ]; } } + +JsonEnum _fromAnnotation(ConstantReader reader) => JsonEnum( + alwaysCreate: reader.read('alwaysCreate').literalValue as bool, + ); diff --git a/json_serializable/test/integration/json_test_example.dart b/json_serializable/test/integration/json_test_example.dart index 87fe97129..3266aad3c 100644 --- a/json_serializable/test/integration/json_test_example.dart +++ b/json_serializable/test/integration/json_test_example.dart @@ -240,7 +240,7 @@ class PrivateConstructor { other is PrivateConstructor && id == other.id && value == other.value; } -@JsonEnum() +@JsonEnum(alwaysCreate: true) enum StandAloneEnum { @JsonValue('a') alpha, diff --git a/json_serializable/test/integration/json_test_example.g_any_map.dart b/json_serializable/test/integration/json_test_example.g_any_map.dart index ea83e1222..c105189a2 100644 --- a/json_serializable/test/integration/json_test_example.g_any_map.dart +++ b/json_serializable/test/integration/json_test_example.g_any_map.dart @@ -248,7 +248,7 @@ class PrivateConstructor { other is PrivateConstructor && id == other.id && value == other.value; } -@JsonEnum() +@JsonEnum(alwaysCreate: true) enum StandAloneEnum { @JsonValue('a') alpha, From 7ab5d99a9df2efa2c84624b56e5fa026b444cfda Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@google.com> Date: Tue, 28 Sep 2021 14:31:58 -0700 Subject: [PATCH 345/569] Bump min SDK for json_annotation|serializable to 2.14.0 Going to make changes required the Enum class later --- .github/workflows/dart.yml | 184 +++++++++++++++++++++++--------- _test_yaml/mono_pkg.yaml | 2 +- _test_yaml/pubspec.yaml | 2 +- json_annotation/CHANGELOG.md | 1 + json_annotation/mono_pkg.yaml | 2 +- json_annotation/pubspec.yaml | 2 +- json_serializable/CHANGELOG.md | 1 + json_serializable/mono_pkg.yaml | 2 +- json_serializable/pubspec.yaml | 2 +- 9 files changed, 140 insertions(+), 58 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index c41cd1f22..5555c30f6 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -37,16 +37,16 @@ jobs: - name: mono_repo self validate run: dart pub global run mono_repo generate --validate job_002: - name: "analyzer_and_format; Dart 2.12.0; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; `dart format --output=none --set-exit-if-changed .`, `dart analyze --fatal-infos .`" + name: "analyzer_and_format; Dart 2.12.0; PKGS: checked_yaml, example; `dart format --output=none --set-exit-if-changed .`, `dart analyze --fatal-infos .`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@v2.1.6 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:format-analyze" + key: "os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:checked_yaml-example;commands:format-analyze" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable + os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:checked_yaml-example os:ubuntu-latest;pub-cache-hosted;dart:2.12.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest @@ -55,19 +55,6 @@ jobs: sdk: "2.12.0" - id: checkout uses: actions/checkout@v2.3.4 - - id: _test_yaml_pub_upgrade - name: _test_yaml; dart pub upgrade - if: "always() && steps.checkout.conclusion == 'success'" - working-directory: _test_yaml - run: dart pub upgrade - - name: "_test_yaml; dart format --output=none --set-exit-if-changed ." - if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" - working-directory: _test_yaml - run: "dart format --output=none --set-exit-if-changed ." - - name: "_test_yaml; dart analyze --fatal-infos ." - if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" - working-directory: _test_yaml - run: dart analyze --fatal-infos . - id: checked_yaml_pub_upgrade name: checked_yaml; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -94,6 +81,38 @@ jobs: if: "always() && steps.example_pub_upgrade.conclusion == 'success'" working-directory: example run: dart analyze --fatal-infos . + job_003: + name: "analyzer_and_format; Dart 2.14.0; PKGS: _test_yaml, json_annotation, json_serializable; `dart format --output=none --set-exit-if-changed .`, `dart analyze --fatal-infos .`" + runs-on: ubuntu-latest + steps: + - name: Cache Pub hosted dependencies + uses: actions/cache@v2.1.6 + with: + path: "~/.pub-cache/hosted" + key: "os:ubuntu-latest;pub-cache-hosted;dart:2.14.0;packages:_test_yaml-json_annotation-json_serializable;commands:format-analyze" + restore-keys: | + os:ubuntu-latest;pub-cache-hosted;dart:2.14.0;packages:_test_yaml-json_annotation-json_serializable + os:ubuntu-latest;pub-cache-hosted;dart:2.14.0 + os:ubuntu-latest;pub-cache-hosted + os:ubuntu-latest + - uses: dart-lang/setup-dart@v1.2 + with: + sdk: "2.14.0" + - id: checkout + uses: actions/checkout@v2.3.4 + - id: _test_yaml_pub_upgrade + name: _test_yaml; dart pub upgrade + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: _test_yaml + run: dart pub upgrade + - name: "_test_yaml; dart format --output=none --set-exit-if-changed ." + if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" + working-directory: _test_yaml + run: "dart format --output=none --set-exit-if-changed ." + - name: "_test_yaml; dart analyze --fatal-infos ." + if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" + working-directory: _test_yaml + run: dart analyze --fatal-infos . - id: json_annotation_pub_upgrade name: json_annotation; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -120,7 +139,7 @@ jobs: if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" working-directory: json_serializable run: dart analyze --fatal-infos . - job_003: + job_004: name: "analyzer_and_format; Dart dev; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; `dart format --output=none --set-exit-if-changed .`, `dart analyze --fatal-infos .`" runs-on: ubuntu-latest steps: @@ -204,17 +223,17 @@ jobs: if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" working-directory: json_serializable run: dart analyze --fatal-infos . - job_004: - name: "unit_test; Dart 2.12.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; `dart test`" + job_005: + name: "unit_test; Dart 2.12.0; PKGS: checked_yaml, example; `dart test`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@v2.1.6 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" + key: "os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:checked_yaml-example;commands:test_0" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:_test_yaml-checked_yaml-example-json_serializable + os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:checked_yaml-example os:ubuntu-latest;pub-cache-hosted;dart:2.12.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest @@ -223,15 +242,6 @@ jobs: sdk: "2.12.0" - id: checkout uses: actions/checkout@v2.3.4 - - id: _test_yaml_pub_upgrade - name: _test_yaml; dart pub upgrade - if: "always() && steps.checkout.conclusion == 'success'" - working-directory: _test_yaml - run: dart pub upgrade - - name: _test_yaml; dart test - if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" - working-directory: _test_yaml - run: dart test - id: checked_yaml_pub_upgrade name: checked_yaml; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -250,6 +260,39 @@ jobs: if: "always() && steps.example_pub_upgrade.conclusion == 'success'" working-directory: example run: dart test + needs: + - job_001 + - job_002 + - job_003 + - job_004 + job_006: + name: "unit_test; Dart 2.14.0; PKGS: _test_yaml, json_serializable; `dart test`" + runs-on: ubuntu-latest + steps: + - name: Cache Pub hosted dependencies + uses: actions/cache@v2.1.6 + with: + path: "~/.pub-cache/hosted" + key: "os:ubuntu-latest;pub-cache-hosted;dart:2.14.0;packages:_test_yaml-json_serializable;commands:test_0" + restore-keys: | + os:ubuntu-latest;pub-cache-hosted;dart:2.14.0;packages:_test_yaml-json_serializable + os:ubuntu-latest;pub-cache-hosted;dart:2.14.0 + os:ubuntu-latest;pub-cache-hosted + os:ubuntu-latest + - uses: dart-lang/setup-dart@v1.2 + with: + sdk: "2.14.0" + - id: checkout + uses: actions/checkout@v2.3.4 + - id: _test_yaml_pub_upgrade + name: _test_yaml; dart pub upgrade + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: _test_yaml + run: dart pub upgrade + - name: _test_yaml; dart test + if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" + working-directory: _test_yaml + run: dart test - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -263,23 +306,24 @@ jobs: - job_001 - job_002 - job_003 - job_005: - name: "unit_test; Dart 2.12.0; PKG: json_serializable; `dart test -p chrome`" + - job_004 + job_007: + name: "unit_test; Dart 2.14.0; PKG: json_serializable; `dart test -p chrome`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@v2.1.6 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:json_serializable;commands:test_2" + key: "os:ubuntu-latest;pub-cache-hosted;dart:2.14.0;packages:json_serializable;commands:test_2" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:json_serializable - os:ubuntu-latest;pub-cache-hosted;dart:2.12.0 + os:ubuntu-latest;pub-cache-hosted;dart:2.14.0;packages:json_serializable + os:ubuntu-latest;pub-cache-hosted;dart:2.14.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - uses: dart-lang/setup-dart@v1.2 with: - sdk: "2.12.0" + sdk: "2.14.0" - id: checkout uses: actions/checkout@v2.3.4 - id: json_serializable_pub_upgrade @@ -295,7 +339,8 @@ jobs: - job_001 - job_002 - job_003 - job_006: + - job_004 + job_008: name: "unit_test; Dart dev; PKGS: _test_yaml, checked_yaml, example, json_serializable; `dart test`" runs-on: ubuntu-latest steps: @@ -354,7 +399,8 @@ jobs: - job_001 - job_002 - job_003 - job_007: + - job_004 + job_009: name: "unit_test; Dart dev; PKG: json_serializable; `dart test -p chrome`" runs-on: ubuntu-latest steps: @@ -386,17 +432,18 @@ jobs: - job_001 - job_002 - job_003 - job_008: - name: "ensure_build; Dart 2.12.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" + - job_004 + job_010: + name: "ensure_build; Dart 2.12.0; PKGS: checked_yaml, example; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@v2.1.6 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_1" + key: "os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:checked_yaml-example;commands:test_1" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:_test_yaml-checked_yaml-example-json_serializable + os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:checked_yaml-example os:ubuntu-latest;pub-cache-hosted;dart:2.12.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest @@ -405,15 +452,6 @@ jobs: sdk: "2.12.0" - id: checkout uses: actions/checkout@v2.3.4 - - id: _test_yaml_pub_upgrade - name: _test_yaml; dart pub upgrade - if: "always() && steps.checkout.conclusion == 'success'" - working-directory: _test_yaml - run: dart pub upgrade - - name: "_test_yaml; dart test --run-skipped -t presubmit-only test/ensure_build_test.dart" - if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" - working-directory: _test_yaml - run: dart test --run-skipped -t presubmit-only test/ensure_build_test.dart - id: checked_yaml_pub_upgrade name: checked_yaml; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -432,6 +470,44 @@ jobs: if: "always() && steps.example_pub_upgrade.conclusion == 'success'" working-directory: example run: dart test --run-skipped -t presubmit-only test/ensure_build_test.dart + needs: + - job_001 + - job_002 + - job_003 + - job_004 + - job_005 + - job_006 + - job_007 + - job_008 + - job_009 + job_011: + name: "ensure_build; Dart 2.14.0; PKGS: _test_yaml, json_serializable; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" + runs-on: ubuntu-latest + steps: + - name: Cache Pub hosted dependencies + uses: actions/cache@v2.1.6 + with: + path: "~/.pub-cache/hosted" + key: "os:ubuntu-latest;pub-cache-hosted;dart:2.14.0;packages:_test_yaml-json_serializable;commands:test_1" + restore-keys: | + os:ubuntu-latest;pub-cache-hosted;dart:2.14.0;packages:_test_yaml-json_serializable + os:ubuntu-latest;pub-cache-hosted;dart:2.14.0 + os:ubuntu-latest;pub-cache-hosted + os:ubuntu-latest + - uses: dart-lang/setup-dart@v1.2 + with: + sdk: "2.14.0" + - id: checkout + uses: actions/checkout@v2.3.4 + - id: _test_yaml_pub_upgrade + name: _test_yaml; dart pub upgrade + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: _test_yaml + run: dart pub upgrade + - name: "_test_yaml; dart test --run-skipped -t presubmit-only test/ensure_build_test.dart" + if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" + working-directory: _test_yaml + run: dart test --run-skipped -t presubmit-only test/ensure_build_test.dart - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -449,7 +525,9 @@ jobs: - job_005 - job_006 - job_007 - job_009: + - job_008 + - job_009 + job_012: name: "ensure_build; Dart dev; PKGS: _test_yaml, checked_yaml, example, json_serializable; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest steps: @@ -512,3 +590,5 @@ jobs: - job_005 - job_006 - job_007 + - job_008 + - job_009 diff --git a/_test_yaml/mono_pkg.yaml b/_test_yaml/mono_pkg.yaml index c731c29e5..f508952d2 100644 --- a/_test_yaml/mono_pkg.yaml +++ b/_test_yaml/mono_pkg.yaml @@ -1,6 +1,6 @@ # See https://github.com/google/mono_repo.dart for details on this file dart: -- 2.12.0 +- 2.14.0 - dev stages: diff --git a/_test_yaml/pubspec.yaml b/_test_yaml/pubspec.yaml index 2af71ec61..74a9b271b 100644 --- a/_test_yaml/pubspec.yaml +++ b/_test_yaml/pubspec.yaml @@ -2,7 +2,7 @@ name: _test_yaml publish_to: none environment: - sdk: '>=2.12.0 <3.0.0' + sdk: '>=2.14.0 <3.0.0' dev_dependencies: build_runner: ^2.0.0 diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index 0740c1578..38a375a0a 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -3,6 +3,7 @@ - Added `JsonSerializabel.constructor` field to allow specifying an alternative constructor to invoke when creating a `fromJson` helper. - Added `JsonEnum` for annotating `enum` types. +- Require Dart SDK `>=2.14.0`. ## 4.1.0 diff --git a/json_annotation/mono_pkg.yaml b/json_annotation/mono_pkg.yaml index 2413a305f..aa7c47dab 100644 --- a/json_annotation/mono_pkg.yaml +++ b/json_annotation/mono_pkg.yaml @@ -1,6 +1,6 @@ # See https://github.com/google/mono_repo.dart for details on this file dart: -- 2.12.0 +- 2.14.0 - dev stages: diff --git a/json_annotation/pubspec.yaml b/json_annotation/pubspec.yaml index 2c3dd4daa..a3b427500 100644 --- a/json_annotation/pubspec.yaml +++ b/json_annotation/pubspec.yaml @@ -5,7 +5,7 @@ description: >- `json_serializable` package. repository: https://github.com/google/json_serializable.dart environment: - sdk: '>=2.12.0 <3.0.0' + sdk: '>=2.14.0 <3.0.0' dependencies: meta: ^1.4.0 diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 644ac8945..f9ec9fbfd 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -3,6 +3,7 @@ - Added support for `JsonSerializabel.constructor` to allow specifying an alternative constructor to invoke when creating a `fromJson` helper. - Support the new `@JsonEnum` annotation in `package:json_annotation`. +- Require Dart SDK `>=2.14.0`. - Require `json_annotation` `'>=4.2.0 <4.3.0'`. ## 5.0.2 diff --git a/json_serializable/mono_pkg.yaml b/json_serializable/mono_pkg.yaml index e9145b0ae..6b1b63b89 100644 --- a/json_serializable/mono_pkg.yaml +++ b/json_serializable/mono_pkg.yaml @@ -1,6 +1,6 @@ # See https://github.com/google/mono_repo.dart for details on this file dart: -- 2.12.0 +- 2.14.0 - dev stages: diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 658734d9d..f016976f1 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -5,7 +5,7 @@ description: >- Dart classes. repository: https://github.com/google/json_serializable.dart/tree/master/json_serializable environment: - sdk: '>=2.12.0 <3.0.0' + sdk: '>=2.14.0 <3.0.0' dependencies: analyzer: ^2.0.0 From bf5ef6b98f7a4738498aa1281ef4e2229e5077d7 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@google.com> Date: Tue, 28 Sep 2021 14:53:35 -0700 Subject: [PATCH 346/569] Ship the enum helpers in json_annotation... Update json_serializable to use those, instead of generating them --- _test_yaml/test/src/build_config.g.dart | 45 +--- json_annotation/CHANGELOG.md | 4 +- json_annotation/lib/json_annotation.dart | 1 + json_annotation/lib/src/enum_helpers.dart | 60 ++++++ json_annotation/lib/src/json_enum.dart | 6 +- json_serializable/CHANGELOG.md | 4 + .../lib/src/json_enum_generator.dart | 5 +- .../lib/src/type_helpers/enum_helper.dart | 46 +--- .../test/default_value/default_value.g.dart | 39 +--- .../default_value.g_any_map__checked.g.dart | 39 +--- .../implicit_default_value.g.dart | 39 +--- .../test/integration/json_test_example.g.dart | 56 +---- .../json_test_example.g_any_map.g.dart | 56 +---- .../src/unknown_enum_value_test_input.dart | 39 +--- .../input.type_enumtype.g.dart | 45 +--- .../input.type_iterable.g.dart | 45 +--- .../supported_types/input.type_list.g.dart | 45 +--- .../supported_types/input.type_map.g.dart | 201 +++++++----------- .../supported_types/input.type_set.g.dart | 45 +--- 19 files changed, 197 insertions(+), 623 deletions(-) create mode 100644 json_annotation/lib/src/enum_helpers.dart diff --git a/_test_yaml/test/src/build_config.g.dart b/_test_yaml/test/src/build_config.g.dart index e195a5aec..f509e2eb6 100644 --- a/_test_yaml/test/src/build_config.g.dart +++ b/_test_yaml/test/src/build_config.g.dart @@ -25,7 +25,7 @@ Config _$ConfigFromJson(Map json) => $checkedCreate( 'weights', (v) => val.weights = (v as Map?)?.map( (k, e) => - MapEntry(_$enumDecode(_$AutoApplyEnumMap, k), e as int), + MapEntry($enumDecode(_$AutoApplyEnumMap, k), e as int), )); return val; }, @@ -37,32 +37,6 @@ Map<String, dynamic> _$ConfigToJson(Config instance) => <String, dynamic>{ instance.weights?.map((k, e) => MapEntry(_$AutoApplyEnumMap[k], e)), }; -K _$enumDecode<K, V>( - Map<K, V> enumValues, - Object? source, { - K? unknownValue, -}) { - if (source == null) { - throw ArgumentError( - 'A value must be provided. Supported values: ' - '${enumValues.values.join(', ')}', - ); - } - - return enumValues.entries.singleWhere( - (e) => e.value == source, - orElse: () { - if (unknownValue == null) { - throw ArgumentError( - '`$source` is not one of the supported values: ' - '${enumValues.values.join(', ')}', - ); - } - return MapEntry(unknownValue, enumValues.values.first); - }, - ).key; -} - const _$AutoApplyEnumMap = { AutoApply.none: 'none', AutoApply.dependents: 'dependents', @@ -96,11 +70,11 @@ Builder _$BuilderFromJson(Map json) => $checkedCreate( target: $checkedConvert('target', (v) => v as String?), isOptional: $checkedConvert('is_optional', (v) => v as bool?), autoApply: $checkedConvert( - 'auto_apply', (v) => _$enumDecodeNullable(_$AutoApplyEnumMap, v)), + 'auto_apply', (v) => $enumDecodeNullable(_$AutoApplyEnumMap, v)), buildTo: $checkedConvert( - 'build_to', (v) => _$enumDecodeNullable(_$BuildToEnumMap, v)), + 'build_to', (v) => $enumDecodeNullable(_$BuildToEnumMap, v)), defaultEnumTest: $checkedConvert('defaultEnumTest', - (v) => _$enumDecodeNullable(_$AutoApplyEnumMap, v)), + (v) => $enumDecodeNullable(_$AutoApplyEnumMap, v)), builderFactories: $checkedConvert('builder_factories', (v) => (v as List<dynamic>).map((e) => e as String).toList()), appliesBuilders: $checkedConvert('applies_builders', @@ -152,17 +126,6 @@ Map<String, dynamic> _$BuilderToJson(Builder instance) { return val; } -K? _$enumDecodeNullable<K, V>( - Map<K, V> enumValues, - dynamic source, { - K? unknownValue, -}) { - if (source == null) { - return null; - } - return _$enumDecode<K, V>(enumValues, source, unknownValue: unknownValue); -} - const _$BuildToEnumMap = { BuildTo.cache: 'cache', BuildTo.source: 'source', diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index 38a375a0a..ba4985757 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -2,7 +2,9 @@ - Added `JsonSerializabel.constructor` field to allow specifying an alternative constructor to invoke when creating a `fromJson` helper. -- Added `JsonEnum` for annotating `enum` types. +- Added `JsonEnum` for annotating `enum` types. +- Added `$enumDecodeNullable` and `$enumDecode` helpers to minimize generated + code. - Require Dart SDK `>=2.14.0`. ## 4.1.0 diff --git a/json_annotation/lib/json_annotation.dart b/json_annotation/lib/json_annotation.dart index d0e3bb017..2dc5d00b1 100644 --- a/json_annotation/lib/json_annotation.dart +++ b/json_annotation/lib/json_annotation.dart @@ -12,6 +12,7 @@ library json_annotation; export 'src/allowed_keys_helpers.dart'; export 'src/checked_helpers.dart'; +export 'src/enum_helpers.dart'; export 'src/json_converter.dart'; export 'src/json_enum.dart'; export 'src/json_key.dart'; diff --git a/json_annotation/lib/src/enum_helpers.dart b/json_annotation/lib/src/enum_helpers.dart new file mode 100644 index 000000000..db1d45a8b --- /dev/null +++ b/json_annotation/lib/src/enum_helpers.dart @@ -0,0 +1,60 @@ +// 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. + +/// Returns the key associated with value [source] from [enumValues], if one +/// exists. +/// +/// If [unknownValue] is not `null` and [source] is not a value in [enumValues], +/// [unknownValue] is returned. Otherwise, an [ArgumentError] is thrown. +/// +/// If [source] is `null`, `null` is returned. +/// +/// Exposed only for code generated by `package:json_serializable`. +/// Not meant to be used directly by user code. +K? $enumDecodeNullable<K extends Enum, V>( + Map<K, V> enumValues, + dynamic source, { + K? unknownValue, +}) { + if (source == null) { + return null; + } + return $enumDecode<K, V>(enumValues, source, unknownValue: unknownValue); +} + +/// Returns the key associated with value [source] from [enumValues], if one +/// exists. +/// +/// If [unknownValue] is not `null` and [source] is not a value in [enumValues], +/// [unknownValue] is returned. Otherwise, an [ArgumentError] is thrown. +/// +/// If [source] is `null`, an [ArgumentError] is thrown. +/// +/// Exposed only for code generated by `package:json_serializable`. +/// Not meant to be used directly by user code. +K $enumDecode<K extends Enum, V>( + Map<K, V> enumValues, + Object? source, { + K? unknownValue, +}) { + if (source == null) { + throw ArgumentError( + 'A value must be provided. Supported values: ' + '${enumValues.values.join(', ')}', + ); + } + + return enumValues.entries.singleWhere( + (e) => e.value == source, + orElse: () { + if (unknownValue == null) { + throw ArgumentError( + '`$source` is not one of the supported values: ' + '${enumValues.values.join(', ')}', + ); + } + return MapEntry(unknownValue, enumValues.values.first); + }, + ).key; +} diff --git a/json_annotation/lib/src/json_enum.dart b/json_annotation/lib/src/json_enum.dart index c35a84b1b..c5ba66541 100644 --- a/json_annotation/lib/src/json_enum.dart +++ b/json_annotation/lib/src/json_enum.dart @@ -13,9 +13,9 @@ class JsonEnum { this.alwaysCreate = false, }); - /// If `true`, `_$EnumNameEnumMap` and `_$enumDecode` are generated for the - /// library containing the `enum`, even if the `enum` is not used as a field - /// in a class annotated with [JsonSerializable]. + /// 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]. diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index f9ec9fbfd..734e93109 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -3,6 +3,10 @@ - Added support for `JsonSerializabel.constructor` to allow specifying an alternative constructor to invoke when creating a `fromJson` helper. - Support the new `@JsonEnum` annotation in `package:json_annotation`. +- Use the new `$enumDecodeNullable` and `$enumDecode` in `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. - Require Dart SDK `>=2.14.0`. - Require `json_annotation` `'>=4.2.0 <4.3.0'`. diff --git a/json_serializable/lib/src/json_enum_generator.dart b/json_serializable/lib/src/json_enum_generator.dart index c3931c44b..5f3dbd13c 100644 --- a/json_serializable/lib/src/json_enum_generator.dart +++ b/json_serializable/lib/src/json_enum_generator.dart @@ -31,10 +31,7 @@ class JsonEnumGenerator extends GeneratorForAnnotation<JsonEnum> { return const []; } - return [ - enumDecodeHelper, - enumValueMapFromType(element.thisType)!, - ]; + return [enumValueMapFromType(element.thisType)!]; } } diff --git a/json_serializable/lib/src/type_helpers/enum_helper.dart b/json_serializable/lib/src/type_helpers/enum_helper.dart index 23723436f..c8926e624 100644 --- a/json_serializable/lib/src/type_helpers/enum_helper.dart +++ b/json_serializable/lib/src/type_helpers/enum_helper.dart @@ -45,14 +45,11 @@ class EnumHelper extends TypeHelper<TypeHelperContextWithConfig> { return null; } - context.addMember(enumDecodeHelper); - String functionName; if (targetType.isNullableType || defaultProvided) { - functionName = r'_$enumDecodeNullable'; - context.addMember(_enumDecodeHelperNullable); + functionName = r'$enumDecodeNullable'; } else { - functionName = r'_$enumDecode'; + functionName = r'$enumDecode'; } context.addMember(memberContent); @@ -86,42 +83,3 @@ String? enumValueMapFromType(DartType targetType) { return 'const ${_constMapName(targetType)} = {\n$items\n};'; } - -const enumDecodeHelper = r''' -K _$enumDecode<K, V>( - Map<K, V> enumValues, - Object? source, { - K? unknownValue, -}) { - if (source == null) { - throw ArgumentError( - 'A value must be provided. Supported values: ' - '${enumValues.values.join(', ')}', - ); - } - - return enumValues.entries.singleWhere( - (e) => e.value == source, - orElse: () { - if (unknownValue == null) { - throw ArgumentError( - '`$source` is not one of the supported values: ' - '${enumValues.values.join(', ')}', - ); - } - return MapEntry(unknownValue, enumValues.values.first); - }, - ).key; -}'''; - -const _enumDecodeHelperNullable = r''' -K? _$enumDecodeNullable<K, V>( - Map<K, V> enumValues, - dynamic source, { - K? unknownValue, -}) { - if (source == null) { - return null; - } - return _$enumDecode<K, V>(enumValues, source, unknownValue: unknownValue); -}'''; diff --git a/json_serializable/test/default_value/default_value.g.dart b/json_serializable/test/default_value/default_value.g.dart index a7388eb8a..8dc932408 100644 --- a/json_serializable/test/default_value/default_value.g.dart +++ b/json_serializable/test/default_value/default_value.g.dart @@ -35,7 +35,7 @@ DefaultValue _$DefaultValueFromJson(Map<String, dynamic> json) => DefaultValue( { 'root': ['child'] }, - _$enumDecodeNullable(_$GreekEnumMap, json['fieldEnum']) ?? Greek.beta, + $enumDecodeNullable(_$GreekEnumMap, json['fieldEnum']) ?? Greek.beta, constClass: json['constClass'] == null ? const ConstClass('value') : ConstClass.fromJson(json['constClass'] as Map<String, dynamic>), @@ -68,43 +68,6 @@ Map<String, dynamic> _$DefaultValueToJson(DefaultValue instance) => 'valueFromFunction': constClassToJson(instance.valueFromFunction), }; -K _$enumDecode<K, V>( - Map<K, V> enumValues, - Object? source, { - K? unknownValue, -}) { - if (source == null) { - throw ArgumentError( - 'A value must be provided. Supported values: ' - '${enumValues.values.join(', ')}', - ); - } - - return enumValues.entries.singleWhere( - (e) => e.value == source, - orElse: () { - if (unknownValue == null) { - throw ArgumentError( - '`$source` is not one of the supported values: ' - '${enumValues.values.join(', ')}', - ); - } - return MapEntry(unknownValue, enumValues.values.first); - }, - ).key; -} - -K? _$enumDecodeNullable<K, V>( - Map<K, V> enumValues, - dynamic source, { - K? unknownValue, -}) { - if (source == null) { - return null; - } - return _$enumDecode<K, V>(enumValues, source, unknownValue: unknownValue); -} - const _$GreekEnumMap = { Greek.alpha: 'alpha', Greek.beta: 'beta', diff --git a/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart b/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart index 5181c11b3..d1608ef2d 100644 --- a/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart +++ b/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart @@ -50,7 +50,7 @@ DefaultValue _$DefaultValueFromJson(Map json) => $checkedCreate( 'root': ['child'] }), $checkedConvert('fieldEnum', - (v) => _$enumDecodeNullable(_$GreekEnumMap, v) ?? Greek.beta), + (v) => $enumDecodeNullable(_$GreekEnumMap, v) ?? Greek.beta), constClass: $checkedConvert( 'constClass', (v) => v == null @@ -91,43 +91,6 @@ Map<String, dynamic> _$DefaultValueToJson(DefaultValue instance) => 'valueFromFunction': constClassToJson(instance.valueFromFunction), }; -K _$enumDecode<K, V>( - Map<K, V> enumValues, - Object? source, { - K? unknownValue, -}) { - if (source == null) { - throw ArgumentError( - 'A value must be provided. Supported values: ' - '${enumValues.values.join(', ')}', - ); - } - - return enumValues.entries.singleWhere( - (e) => e.value == source, - orElse: () { - if (unknownValue == null) { - throw ArgumentError( - '`$source` is not one of the supported values: ' - '${enumValues.values.join(', ')}', - ); - } - return MapEntry(unknownValue, enumValues.values.first); - }, - ).key; -} - -K? _$enumDecodeNullable<K, V>( - Map<K, V> enumValues, - dynamic source, { - K? unknownValue, -}) { - if (source == null) { - return null; - } - return _$enumDecode<K, V>(enumValues, source, unknownValue: unknownValue); -} - const _$GreekEnumMap = { Greek.alpha: 'alpha', Greek.beta: 'beta', diff --git a/json_serializable/test/default_value/implicit_default_value.g.dart b/json_serializable/test/default_value/implicit_default_value.g.dart index fc355e089..fe5d17283 100644 --- a/json_serializable/test/default_value/implicit_default_value.g.dart +++ b/json_serializable/test/default_value/implicit_default_value.g.dart @@ -40,7 +40,7 @@ DefaultValueImplicit _$DefaultValueImplicitFromJson( 'root': ['child'] }, fieldEnum: - _$enumDecodeNullable(_$GreekEnumMap, json['fieldEnum']) ?? Greek.beta, + $enumDecodeNullable(_$GreekEnumMap, json['fieldEnum']) ?? Greek.beta, constClass: json['constClass'] == null ? const ConstClass('value') : ConstClass.fromJson(json['constClass'] as Map<String, dynamic>), @@ -74,43 +74,6 @@ Map<String, dynamic> _$DefaultValueImplicitToJson( 'valueFromFunction': constClassToJson(instance.valueFromFunction), }; -K _$enumDecode<K, V>( - Map<K, V> enumValues, - Object? source, { - K? unknownValue, -}) { - if (source == null) { - throw ArgumentError( - 'A value must be provided. Supported values: ' - '${enumValues.values.join(', ')}', - ); - } - - return enumValues.entries.singleWhere( - (e) => e.value == source, - orElse: () { - if (unknownValue == null) { - throw ArgumentError( - '`$source` is not one of the supported values: ' - '${enumValues.values.join(', ')}', - ); - } - return MapEntry(unknownValue, enumValues.values.first); - }, - ).key; -} - -K? _$enumDecodeNullable<K, V>( - Map<K, V> enumValues, - dynamic source, { - K? unknownValue, -}) { - if (source == null) { - return null; - } - return _$enumDecode<K, V>(enumValues, source, unknownValue: unknownValue); -} - const _$GreekEnumMap = { Greek.alpha: 'alpha', Greek.beta: 'beta', diff --git a/json_serializable/test/integration/json_test_example.g.dart b/json_serializable/test/integration/json_test_example.g.dart index 77f9662ef..b665e1048 100644 --- a/json_serializable/test/integration/json_test_example.g.dart +++ b/json_serializable/test/integration/json_test_example.g.dart @@ -11,7 +11,7 @@ part of 'json_test_example.dart'; Person _$PersonFromJson(Map<String, dynamic> json) => Person( json['firstName'] as String, json['lastName'] as String, - _$enumDecode(_$CategoryEnumMap, json[r'$house']), + $enumDecode(_$CategoryEnumMap, json[r'$house']), middleName: json['middleName'] as String?, dateOfBirth: json['dateOfBirth'] == null ? null @@ -26,10 +26,10 @@ Person _$PersonFromJson(Map<String, dynamic> json) => Person( .map((e) => Order.fromJson(e as Map<String, dynamic>)) .toList()) ..houseMap = (json['houseMap'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, _$enumDecode(_$CategoryEnumMap, e)), + (k, e) => MapEntry(k, $enumDecode(_$CategoryEnumMap, e)), ) ..categoryCounts = (json['categoryCounts'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(_$enumDecode(_$CategoryEnumMap, k), e as int), + (k, e) => MapEntry($enumDecode(_$CategoryEnumMap, k), e as int), ); Map<String, dynamic> _$PersonToJson(Person instance) => <String, dynamic>{ @@ -46,32 +46,6 @@ Map<String, dynamic> _$PersonToJson(Person instance) => <String, dynamic>{ ?.map((k, e) => MapEntry(_$CategoryEnumMap[k], e)), }; -K _$enumDecode<K, V>( - Map<K, V> enumValues, - Object? source, { - K? unknownValue, -}) { - if (source == null) { - throw ArgumentError( - 'A value must be provided. Supported values: ' - '${enumValues.values.join(', ')}', - ); - } - - return enumValues.entries.singleWhere( - (e) => e.value == source, - orElse: () { - if (unknownValue == null) { - throw ArgumentError( - '`$source` is not one of the supported values: ' - '${enumValues.values.join(', ')}', - ); - } - return MapEntry(unknownValue, enumValues.values.first); - }, - ).key; -} - const _$CategoryEnumMap = { Category.top: 'top', Category.bottom: 'bottom', @@ -88,7 +62,7 @@ Order _$OrderFromJson(Map<String, dynamic> json) { disallowNullValues: const ['count'], ); return Order.custom( - _$enumDecodeNullable(_$CategoryEnumMap, json['category']), + $enumDecodeNullable(_$CategoryEnumMap, json['category']), (json['items'] as List<dynamic>?) ?.map((e) => Item.fromJson(e as Map<String, dynamic>)), ) @@ -105,8 +79,7 @@ Order _$OrderFromJson(Map<String, dynamic> json) { ) ..homepage = json['homepage'] == null ? null : Uri.parse(json['homepage'] as String) - ..statusCode = _$enumDecodeNullable( - _$StatusCodeEnumMap, json['status_code'], + ..statusCode = $enumDecodeNullable(_$StatusCodeEnumMap, json['status_code'], unknownValue: StatusCode.unknown) ?? StatusCode.success; } @@ -132,17 +105,6 @@ Map<String, dynamic> _$OrderToJson(Order instance) { return val; } -K? _$enumDecodeNullable<K, V>( - Map<K, V> enumValues, - dynamic source, { - K? unknownValue, -}) { - if (source == null) { - return null; - } - return _$enumDecode<K, V>(enumValues, source, unknownValue: unknownValue); -} - const _$StatusCodeEnumMap = { StatusCode.success: 200, StatusCode.notFound: 404, @@ -226,17 +188,17 @@ Map<String, dynamic> _$MapKeyVarietyToJson(MapKeyVariety instance) => UnknownEnumValue _$UnknownEnumValueFromJson(Map<String, dynamic> json) => UnknownEnumValue() - ..enumValue = _$enumDecode(_$CategoryEnumMap, json['enumValue'], + ..enumValue = $enumDecode(_$CategoryEnumMap, json['enumValue'], unknownValue: Category.notDiscoveredYet) ..enumIterable = (json['enumIterable'] as List<dynamic>).map((e) => - _$enumDecode(_$CategoryEnumMap, e, + $enumDecode(_$CategoryEnumMap, e, unknownValue: Category.notDiscoveredYet)) ..enumList = (json['enumList'] as List<dynamic>) - .map((e) => _$enumDecode(_$CategoryEnumMap, e, + .map((e) => $enumDecode(_$CategoryEnumMap, e, unknownValue: Category.notDiscoveredYet)) .toList() ..enumSet = (json['enumSet'] as List<dynamic>) - .map((e) => _$enumDecode(_$CategoryEnumMap, e, + .map((e) => $enumDecode(_$CategoryEnumMap, e, unknownValue: Category.notDiscoveredYet)) .toSet(); diff --git a/json_serializable/test/integration/json_test_example.g_any_map.g.dart b/json_serializable/test/integration/json_test_example.g_any_map.g.dart index 4b43ef614..cdedd8cae 100644 --- a/json_serializable/test/integration/json_test_example.g_any_map.g.dart +++ b/json_serializable/test/integration/json_test_example.g_any_map.g.dart @@ -11,7 +11,7 @@ part of 'json_test_example.g_any_map.dart'; Person _$PersonFromJson(Map json) => Person( json['firstName'] as String, json['lastName'] as String, - _$enumDecode(_$CategoryEnumMap, json[r'$house']), + $enumDecode(_$CategoryEnumMap, json[r'$house']), middleName: json['middleName'] as String?, dateOfBirth: json['dateOfBirth'] == null ? null @@ -26,10 +26,10 @@ Person _$PersonFromJson(Map json) => Person( .map((e) => Order.fromJson(Map<String, dynamic>.from(e as Map))) .toList()) ..houseMap = (json['houseMap'] as Map?)?.map( - (k, e) => MapEntry(k as String, _$enumDecode(_$CategoryEnumMap, e)), + (k, e) => MapEntry(k as String, $enumDecode(_$CategoryEnumMap, e)), ) ..categoryCounts = (json['categoryCounts'] as Map?)?.map( - (k, e) => MapEntry(_$enumDecode(_$CategoryEnumMap, k), e as int), + (k, e) => MapEntry($enumDecode(_$CategoryEnumMap, k), e as int), ); Map<String, dynamic> _$PersonToJson(Person instance) => <String, dynamic>{ @@ -46,32 +46,6 @@ Map<String, dynamic> _$PersonToJson(Person instance) => <String, dynamic>{ ?.map((k, e) => MapEntry(_$CategoryEnumMap[k], e)), }; -K _$enumDecode<K, V>( - Map<K, V> enumValues, - Object? source, { - K? unknownValue, -}) { - if (source == null) { - throw ArgumentError( - 'A value must be provided. Supported values: ' - '${enumValues.values.join(', ')}', - ); - } - - return enumValues.entries.singleWhere( - (e) => e.value == source, - orElse: () { - if (unknownValue == null) { - throw ArgumentError( - '`$source` is not one of the supported values: ' - '${enumValues.values.join(', ')}', - ); - } - return MapEntry(unknownValue, enumValues.values.first); - }, - ).key; -} - const _$CategoryEnumMap = { Category.top: 'top', Category.bottom: 'bottom', @@ -88,7 +62,7 @@ Order _$OrderFromJson(Map json) { disallowNullValues: const ['count'], ); return Order.custom( - _$enumDecodeNullable(_$CategoryEnumMap, json['category']), + $enumDecodeNullable(_$CategoryEnumMap, json['category']), (json['items'] as List<dynamic>?) ?.map((e) => Item.fromJson(Map<String, dynamic>.from(e as Map))), ) @@ -105,8 +79,7 @@ Order _$OrderFromJson(Map json) { ) ..homepage = json['homepage'] == null ? null : Uri.parse(json['homepage'] as String) - ..statusCode = _$enumDecodeNullable( - _$StatusCodeEnumMap, json['status_code'], + ..statusCode = $enumDecodeNullable(_$StatusCodeEnumMap, json['status_code'], unknownValue: StatusCode.unknown) ?? StatusCode.success; } @@ -132,17 +105,6 @@ Map<String, dynamic> _$OrderToJson(Order instance) { return val; } -K? _$enumDecodeNullable<K, V>( - Map<K, V> enumValues, - dynamic source, { - K? unknownValue, -}) { - if (source == null) { - return null; - } - return _$enumDecode<K, V>(enumValues, source, unknownValue: unknownValue); -} - const _$StatusCodeEnumMap = { StatusCode.success: 200, StatusCode.notFound: 404, @@ -224,17 +186,17 @@ Map<String, dynamic> _$MapKeyVarietyToJson(MapKeyVariety instance) => }; UnknownEnumValue _$UnknownEnumValueFromJson(Map json) => UnknownEnumValue() - ..enumValue = _$enumDecode(_$CategoryEnumMap, json['enumValue'], + ..enumValue = $enumDecode(_$CategoryEnumMap, json['enumValue'], unknownValue: Category.notDiscoveredYet) ..enumIterable = (json['enumIterable'] as List<dynamic>).map((e) => - _$enumDecode(_$CategoryEnumMap, e, + $enumDecode(_$CategoryEnumMap, e, unknownValue: Category.notDiscoveredYet)) ..enumList = (json['enumList'] as List<dynamic>) - .map((e) => _$enumDecode(_$CategoryEnumMap, e, + .map((e) => $enumDecode(_$CategoryEnumMap, e, unknownValue: Category.notDiscoveredYet)) .toList() ..enumSet = (json['enumSet'] as List<dynamic>) - .map((e) => _$enumDecode(_$CategoryEnumMap, e, + .map((e) => $enumDecode(_$CategoryEnumMap, e, unknownValue: Category.notDiscoveredYet)) .toSet(); diff --git a/json_serializable/test/src/unknown_enum_value_test_input.dart b/json_serializable/test/src/unknown_enum_value_test_input.dart index f81d300ef..a7b6ff0fb 100644 --- a/json_serializable/test/src/unknown_enum_value_test_input.dart +++ b/json_serializable/test/src/unknown_enum_value_test_input.dart @@ -4,48 +4,11 @@ part of '_json_serializable_test_input.dart'; r''' UnknownEnumValue _$UnknownEnumValueFromJson(Map<String, dynamic> json) => UnknownEnumValue() - ..value = _$enumDecodeNullable( + ..value = $enumDecodeNullable( _$UnknownEnumValueItemsEnumMap, json['value'], unknownValue: UnknownEnumValueItems.vUnknown) ?? UnknownEnumValueItems.vNull; -K _$enumDecode<K, V>( - Map<K, V> enumValues, - Object? source, { - K? unknownValue, -}) { - if (source == null) { - throw ArgumentError( - 'A value must be provided. Supported values: ' - '${enumValues.values.join(', ')}', - ); - } - - return enumValues.entries.singleWhere( - (e) => e.value == source, - orElse: () { - if (unknownValue == null) { - throw ArgumentError( - '`$source` is not one of the supported values: ' - '${enumValues.values.join(', ')}', - ); - } - return MapEntry(unknownValue, enumValues.values.first); - }, - ).key; -} - -K? _$enumDecodeNullable<K, V>( - Map<K, V> enumValues, - dynamic source, { - K? unknownValue, -}) { - if (source == null) { - return null; - } - return _$enumDecode<K, V>(enumValues, source, unknownValue: unknownValue); -} - const _$UnknownEnumValueItemsEnumMap = { UnknownEnumValueItems.v0: 'v0', UnknownEnumValueItems.v1: 'v1', diff --git a/json_serializable/test/supported_types/input.type_enumtype.g.dart b/json_serializable/test/supported_types/input.type_enumtype.g.dart index a896a8fc7..931ddfc3e 100644 --- a/json_serializable/test/supported_types/input.type_enumtype.g.dart +++ b/json_serializable/test/supported_types/input.type_enumtype.g.dart @@ -9,8 +9,8 @@ part of 'input.type_enumtype.dart'; // ************************************************************************** SimpleClass _$SimpleClassFromJson(Map<String, dynamic> json) => SimpleClass( - _$enumDecode(_$EnumTypeEnumMap, json['value']), - _$enumDecodeNullable(_$EnumTypeEnumMap, json['withDefault']) ?? + $enumDecode(_$EnumTypeEnumMap, json['value']), + $enumDecodeNullable(_$EnumTypeEnumMap, json['withDefault']) ?? EnumType.alpha, ); @@ -20,32 +20,6 @@ Map<String, dynamic> _$SimpleClassToJson(SimpleClass instance) => 'withDefault': _$EnumTypeEnumMap[instance.withDefault], }; -K _$enumDecode<K, V>( - Map<K, V> enumValues, - Object? source, { - K? unknownValue, -}) { - if (source == null) { - throw ArgumentError( - 'A value must be provided. Supported values: ' - '${enumValues.values.join(', ')}', - ); - } - - return enumValues.entries.singleWhere( - (e) => e.value == source, - orElse: () { - if (unknownValue == null) { - throw ArgumentError( - '`$source` is not one of the supported values: ' - '${enumValues.values.join(', ')}', - ); - } - return MapEntry(unknownValue, enumValues.values.first); - }, - ).key; -} - const _$EnumTypeEnumMap = { EnumType.alpha: 'alpha', EnumType.beta: 'beta', @@ -53,21 +27,10 @@ const _$EnumTypeEnumMap = { EnumType.delta: 'delta', }; -K? _$enumDecodeNullable<K, V>( - Map<K, V> enumValues, - dynamic source, { - K? unknownValue, -}) { - if (source == null) { - return null; - } - return _$enumDecode<K, V>(enumValues, source, unknownValue: unknownValue); -} - SimpleClassNullable _$SimpleClassNullableFromJson(Map<String, dynamic> json) => SimpleClassNullable( - _$enumDecodeNullable(_$EnumTypeEnumMap, json['value']), - _$enumDecodeNullable(_$EnumTypeEnumMap, json['withDefault']) ?? + $enumDecodeNullable(_$EnumTypeEnumMap, json['value']), + $enumDecodeNullable(_$EnumTypeEnumMap, json['withDefault']) ?? EnumType.alpha, ); diff --git a/json_serializable/test/supported_types/input.type_iterable.g.dart b/json_serializable/test/supported_types/input.type_iterable.g.dart index 3d150a3d9..f312e76ba 100644 --- a/json_serializable/test/supported_types/input.type_iterable.g.dart +++ b/json_serializable/test/supported_types/input.type_iterable.g.dart @@ -308,7 +308,7 @@ SimpleClassOfEnumType _$SimpleClassOfEnumTypeFromJson( Map<String, dynamic> json) => SimpleClassOfEnumType( (json['value'] as List<dynamic>) - .map((e) => _$enumDecode(_$EnumTypeEnumMap, e)), + .map((e) => $enumDecode(_$EnumTypeEnumMap, e)), ); Map<String, dynamic> _$SimpleClassOfEnumTypeToJson( @@ -317,32 +317,6 @@ Map<String, dynamic> _$SimpleClassOfEnumTypeToJson( 'value': instance.value.map((e) => _$EnumTypeEnumMap[e]).toList(), }; -K _$enumDecode<K, V>( - Map<K, V> enumValues, - Object? source, { - K? unknownValue, -}) { - if (source == null) { - throw ArgumentError( - 'A value must be provided. Supported values: ' - '${enumValues.values.join(', ')}', - ); - } - - return enumValues.entries.singleWhere( - (e) => e.value == source, - orElse: () { - if (unknownValue == null) { - throw ArgumentError( - '`$source` is not one of the supported values: ' - '${enumValues.values.join(', ')}', - ); - } - return MapEntry(unknownValue, enumValues.values.first); - }, - ).key; -} - const _$EnumTypeEnumMap = { EnumType.alpha: 'alpha', EnumType.beta: 'beta', @@ -354,7 +328,7 @@ SimpleClassNullableOfEnumType _$SimpleClassNullableOfEnumTypeFromJson( Map<String, dynamic> json) => SimpleClassNullableOfEnumType( (json['value'] as List<dynamic>?) - ?.map((e) => _$enumDecode(_$EnumTypeEnumMap, e)), + ?.map((e) => $enumDecode(_$EnumTypeEnumMap, e)), ); Map<String, dynamic> _$SimpleClassNullableOfEnumTypeToJson( @@ -367,7 +341,7 @@ SimpleClassOfEnumTypeNullable _$SimpleClassOfEnumTypeNullableFromJson( Map<String, dynamic> json) => SimpleClassOfEnumTypeNullable( (json['value'] as List<dynamic>) - .map((e) => _$enumDecodeNullable(_$EnumTypeEnumMap, e)), + .map((e) => $enumDecodeNullable(_$EnumTypeEnumMap, e)), ); Map<String, dynamic> _$SimpleClassOfEnumTypeNullableToJson( @@ -376,23 +350,12 @@ Map<String, dynamic> _$SimpleClassOfEnumTypeNullableToJson( 'value': instance.value.map((e) => _$EnumTypeEnumMap[e]).toList(), }; -K? _$enumDecodeNullable<K, V>( - Map<K, V> enumValues, - dynamic source, { - K? unknownValue, -}) { - if (source == null) { - return null; - } - return _$enumDecode<K, V>(enumValues, source, unknownValue: unknownValue); -} - SimpleClassNullableOfEnumTypeNullable _$SimpleClassNullableOfEnumTypeNullableFromJson( Map<String, dynamic> json) => SimpleClassNullableOfEnumTypeNullable( (json['value'] as List<dynamic>?) - ?.map((e) => _$enumDecodeNullable(_$EnumTypeEnumMap, e)), + ?.map((e) => $enumDecodeNullable(_$EnumTypeEnumMap, e)), ); Map<String, dynamic> _$SimpleClassNullableOfEnumTypeNullableToJson( diff --git a/json_serializable/test/supported_types/input.type_list.g.dart b/json_serializable/test/supported_types/input.type_list.g.dart index 960780acc..36b9ad467 100644 --- a/json_serializable/test/supported_types/input.type_list.g.dart +++ b/json_serializable/test/supported_types/input.type_list.g.dart @@ -330,7 +330,7 @@ SimpleClassOfEnumType _$SimpleClassOfEnumTypeFromJson( Map<String, dynamic> json) => SimpleClassOfEnumType( (json['value'] as List<dynamic>) - .map((e) => _$enumDecode(_$EnumTypeEnumMap, e)) + .map((e) => $enumDecode(_$EnumTypeEnumMap, e)) .toList(), ); @@ -340,32 +340,6 @@ Map<String, dynamic> _$SimpleClassOfEnumTypeToJson( 'value': instance.value.map((e) => _$EnumTypeEnumMap[e]).toList(), }; -K _$enumDecode<K, V>( - Map<K, V> enumValues, - Object? source, { - K? unknownValue, -}) { - if (source == null) { - throw ArgumentError( - 'A value must be provided. Supported values: ' - '${enumValues.values.join(', ')}', - ); - } - - return enumValues.entries.singleWhere( - (e) => e.value == source, - orElse: () { - if (unknownValue == null) { - throw ArgumentError( - '`$source` is not one of the supported values: ' - '${enumValues.values.join(', ')}', - ); - } - return MapEntry(unknownValue, enumValues.values.first); - }, - ).key; -} - const _$EnumTypeEnumMap = { EnumType.alpha: 'alpha', EnumType.beta: 'beta', @@ -377,7 +351,7 @@ SimpleClassNullableOfEnumType _$SimpleClassNullableOfEnumTypeFromJson( Map<String, dynamic> json) => SimpleClassNullableOfEnumType( (json['value'] as List<dynamic>?) - ?.map((e) => _$enumDecode(_$EnumTypeEnumMap, e)) + ?.map((e) => $enumDecode(_$EnumTypeEnumMap, e)) .toList(), ); @@ -391,7 +365,7 @@ SimpleClassOfEnumTypeNullable _$SimpleClassOfEnumTypeNullableFromJson( Map<String, dynamic> json) => SimpleClassOfEnumTypeNullable( (json['value'] as List<dynamic>) - .map((e) => _$enumDecodeNullable(_$EnumTypeEnumMap, e)) + .map((e) => $enumDecodeNullable(_$EnumTypeEnumMap, e)) .toList(), ); @@ -401,23 +375,12 @@ Map<String, dynamic> _$SimpleClassOfEnumTypeNullableToJson( 'value': instance.value.map((e) => _$EnumTypeEnumMap[e]).toList(), }; -K? _$enumDecodeNullable<K, V>( - Map<K, V> enumValues, - dynamic source, { - K? unknownValue, -}) { - if (source == null) { - return null; - } - return _$enumDecode<K, V>(enumValues, source, unknownValue: unknownValue); -} - SimpleClassNullableOfEnumTypeNullable _$SimpleClassNullableOfEnumTypeNullableFromJson( Map<String, dynamic> json) => SimpleClassNullableOfEnumTypeNullable( (json['value'] as List<dynamic>?) - ?.map((e) => _$enumDecodeNullable(_$EnumTypeEnumMap, e)) + ?.map((e) => $enumDecodeNullable(_$EnumTypeEnumMap, e)) .toList(), ); diff --git a/json_serializable/test/supported_types/input.type_map.g.dart b/json_serializable/test/supported_types/input.type_map.g.dart index 6bc7c3e0f..0886e800a 100644 --- a/json_serializable/test/supported_types/input.type_map.g.dart +++ b/json_serializable/test/supported_types/input.type_map.g.dart @@ -126,7 +126,7 @@ SimpleClassOfEnumTypeToBigInt _$SimpleClassOfEnumTypeToBigIntFromJson( SimpleClassOfEnumTypeToBigInt( (json['value'] as Map<String, dynamic>).map( (k, e) => MapEntry( - _$enumDecode(_$EnumTypeEnumMap, k), BigInt.parse(e as String)), + $enumDecode(_$EnumTypeEnumMap, k), BigInt.parse(e as String)), ), ); @@ -137,32 +137,6 @@ Map<String, dynamic> _$SimpleClassOfEnumTypeToBigIntToJson( .map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e.toString())), }; -K _$enumDecode<K, V>( - Map<K, V> enumValues, - Object? source, { - K? unknownValue, -}) { - if (source == null) { - throw ArgumentError( - 'A value must be provided. Supported values: ' - '${enumValues.values.join(', ')}', - ); - } - - return enumValues.entries.singleWhere( - (e) => e.value == source, - orElse: () { - if (unknownValue == null) { - throw ArgumentError( - '`$source` is not one of the supported values: ' - '${enumValues.values.join(', ')}', - ); - } - return MapEntry(unknownValue, enumValues.values.first); - }, - ).key; -} - const _$EnumTypeEnumMap = { EnumType.alpha: 'alpha', EnumType.beta: 'beta', @@ -176,7 +150,7 @@ SimpleClassNullableOfEnumTypeToBigInt SimpleClassNullableOfEnumTypeToBigInt( (json['value'] as Map<String, dynamic>?)?.map( (k, e) => MapEntry( - _$enumDecode(_$EnumTypeEnumMap, k), BigInt.parse(e as String)), + $enumDecode(_$EnumTypeEnumMap, k), BigInt.parse(e as String)), ), ); @@ -404,7 +378,7 @@ SimpleClassOfEnumTypeToBigIntNullable Map<String, dynamic> json) => SimpleClassOfEnumTypeToBigIntNullable( (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), + (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e == null ? null : BigInt.parse(e as String)), ), ); @@ -421,7 +395,7 @@ SimpleClassNullableOfEnumTypeToBigIntNullable Map<String, dynamic> json) => SimpleClassNullableOfEnumTypeToBigIntNullable( (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), + (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e == null ? null : BigInt.parse(e as String)), ), ); @@ -643,7 +617,7 @@ SimpleClassOfEnumTypeToBool _$SimpleClassOfEnumTypeToBoolFromJson( Map<String, dynamic> json) => SimpleClassOfEnumTypeToBool( (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as bool), + (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e as bool), ), ); @@ -657,7 +631,7 @@ SimpleClassNullableOfEnumTypeToBool _$SimpleClassNullableOfEnumTypeToBoolFromJson(Map<String, dynamic> json) => SimpleClassNullableOfEnumTypeToBool( (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as bool), + (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e as bool), ), ); @@ -864,7 +838,7 @@ SimpleClassOfEnumTypeToBoolNullable _$SimpleClassOfEnumTypeToBoolNullableFromJson(Map<String, dynamic> json) => SimpleClassOfEnumTypeToBoolNullable( (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as bool?), + (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e as bool?), ), ); @@ -879,7 +853,7 @@ SimpleClassNullableOfEnumTypeToBoolNullable Map<String, dynamic> json) => SimpleClassNullableOfEnumTypeToBoolNullable( (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as bool?), + (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e as bool?), ), ); @@ -1097,7 +1071,7 @@ SimpleClassOfEnumTypeToDateTime _$SimpleClassOfEnumTypeToDateTimeFromJson( SimpleClassOfEnumTypeToDateTime( (json['value'] as Map<String, dynamic>).map( (k, e) => MapEntry( - _$enumDecode(_$EnumTypeEnumMap, k), DateTime.parse(e as String)), + $enumDecode(_$EnumTypeEnumMap, k), DateTime.parse(e as String)), ), ); @@ -1113,8 +1087,8 @@ SimpleClassNullableOfEnumTypeToDateTime Map<String, dynamic> json) => SimpleClassNullableOfEnumTypeToDateTime( (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), - DateTime.parse(e as String)), + (k, e) => MapEntry( + $enumDecode(_$EnumTypeEnumMap, k), DateTime.parse(e as String)), ), ); @@ -1348,7 +1322,7 @@ SimpleClassOfEnumTypeToDateTimeNullable Map<String, dynamic> json) => SimpleClassOfEnumTypeToDateTimeNullable( (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), + (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e == null ? null : DateTime.parse(e as String)), ), ); @@ -1365,7 +1339,7 @@ SimpleClassNullableOfEnumTypeToDateTimeNullable Map<String, dynamic> json) => SimpleClassNullableOfEnumTypeToDateTimeNullable( (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), + (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e == null ? null : DateTime.parse(e as String)), ), ); @@ -1597,7 +1571,7 @@ SimpleClassOfEnumTypeToDouble _$SimpleClassOfEnumTypeToDoubleFromJson( SimpleClassOfEnumTypeToDouble( (json['value'] as Map<String, dynamic>).map( (k, e) => - MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), (e as num).toDouble()), + MapEntry($enumDecode(_$EnumTypeEnumMap, k), (e as num).toDouble()), ), ); @@ -1613,7 +1587,7 @@ SimpleClassNullableOfEnumTypeToDouble SimpleClassNullableOfEnumTypeToDouble( (json['value'] as Map<String, dynamic>?)?.map( (k, e) => MapEntry( - _$enumDecode(_$EnumTypeEnumMap, k), (e as num).toDouble()), + $enumDecode(_$EnumTypeEnumMap, k), (e as num).toDouble()), ), ); @@ -1829,7 +1803,7 @@ SimpleClassOfEnumTypeToDoubleNullable SimpleClassOfEnumTypeToDoubleNullable( (json['value'] as Map<String, dynamic>).map( (k, e) => MapEntry( - _$enumDecode(_$EnumTypeEnumMap, k), (e as num?)?.toDouble()), + $enumDecode(_$EnumTypeEnumMap, k), (e as num?)?.toDouble()), ), ); @@ -1845,7 +1819,7 @@ SimpleClassNullableOfEnumTypeToDoubleNullable SimpleClassNullableOfEnumTypeToDoubleNullable( (json['value'] as Map<String, dynamic>?)?.map( (k, e) => MapEntry( - _$enumDecode(_$EnumTypeEnumMap, k), (e as num?)?.toDouble()), + $enumDecode(_$EnumTypeEnumMap, k), (e as num?)?.toDouble()), ), ); @@ -2068,7 +2042,7 @@ SimpleClassOfEnumTypeToDuration _$SimpleClassOfEnumTypeToDurationFromJson( Map<String, dynamic> json) => SimpleClassOfEnumTypeToDuration( (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), + (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), Duration(microseconds: e as int)), ), ); @@ -2085,7 +2059,7 @@ SimpleClassNullableOfEnumTypeToDuration Map<String, dynamic> json) => SimpleClassNullableOfEnumTypeToDuration( (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), + (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), Duration(microseconds: e as int)), ), ); @@ -2320,7 +2294,7 @@ SimpleClassOfEnumTypeToDurationNullable Map<String, dynamic> json) => SimpleClassOfEnumTypeToDurationNullable( (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), + (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e == null ? null : Duration(microseconds: e as int)), ), ); @@ -2337,7 +2311,7 @@ SimpleClassNullableOfEnumTypeToDurationNullable Map<String, dynamic> json) => SimpleClassNullableOfEnumTypeToDurationNullable( (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), + (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e == null ? null : Duration(microseconds: e as int)), ), ); @@ -2565,7 +2539,7 @@ SimpleClassOfEnumTypeToDynamic _$SimpleClassOfEnumTypeToDynamicFromJson( Map<String, dynamic> json) => SimpleClassOfEnumTypeToDynamic( (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e), + (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e), ), ); @@ -2580,7 +2554,7 @@ SimpleClassNullableOfEnumTypeToDynamic Map<String, dynamic> json) => SimpleClassNullableOfEnumTypeToDynamic( (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e), + (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e), ), ); @@ -2698,7 +2672,7 @@ SimpleClassOfBigIntToEnumType _$SimpleClassOfBigIntToEnumTypeFromJson( Map<String, dynamic> json) => SimpleClassOfBigIntToEnumType( (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(BigInt.parse(k), _$enumDecode(_$EnumTypeEnumMap, e)), + (k, e) => MapEntry(BigInt.parse(k), $enumDecode(_$EnumTypeEnumMap, e)), ), ); @@ -2715,7 +2689,7 @@ SimpleClassNullableOfBigIntToEnumType SimpleClassNullableOfBigIntToEnumType( (json['value'] as Map<String, dynamic>?)?.map( (k, e) => - MapEntry(BigInt.parse(k), _$enumDecode(_$EnumTypeEnumMap, e)), + MapEntry(BigInt.parse(k), $enumDecode(_$EnumTypeEnumMap, e)), ), ); @@ -2731,7 +2705,7 @@ SimpleClassOfDateTimeToEnumType _$SimpleClassOfDateTimeToEnumTypeFromJson( SimpleClassOfDateTimeToEnumType( (json['value'] as Map<String, dynamic>).map( (k, e) => - MapEntry(DateTime.parse(k), _$enumDecode(_$EnumTypeEnumMap, e)), + MapEntry(DateTime.parse(k), $enumDecode(_$EnumTypeEnumMap, e)), ), ); @@ -2748,7 +2722,7 @@ SimpleClassNullableOfDateTimeToEnumType SimpleClassNullableOfDateTimeToEnumType( (json['value'] as Map<String, dynamic>?)?.map( (k, e) => - MapEntry(DateTime.parse(k), _$enumDecode(_$EnumTypeEnumMap, e)), + MapEntry(DateTime.parse(k), $enumDecode(_$EnumTypeEnumMap, e)), ), ); @@ -2763,7 +2737,7 @@ SimpleClassOfDynamicToEnumType _$SimpleClassOfDynamicToEnumTypeFromJson( Map<String, dynamic> json) => SimpleClassOfDynamicToEnumType( (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(k, _$enumDecode(_$EnumTypeEnumMap, e)), + (k, e) => MapEntry(k, $enumDecode(_$EnumTypeEnumMap, e)), ), ); @@ -2778,7 +2752,7 @@ SimpleClassNullableOfDynamicToEnumType Map<String, dynamic> json) => SimpleClassNullableOfDynamicToEnumType( (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, _$enumDecode(_$EnumTypeEnumMap, e)), + (k, e) => MapEntry(k, $enumDecode(_$EnumTypeEnumMap, e)), ), ); @@ -2792,8 +2766,8 @@ SimpleClassOfEnumTypeToEnumType _$SimpleClassOfEnumTypeToEnumTypeFromJson( Map<String, dynamic> json) => SimpleClassOfEnumTypeToEnumType( (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), - _$enumDecode(_$EnumTypeEnumMap, e)), + (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), + $enumDecode(_$EnumTypeEnumMap, e)), ), ); @@ -2809,8 +2783,8 @@ SimpleClassNullableOfEnumTypeToEnumType Map<String, dynamic> json) => SimpleClassNullableOfEnumTypeToEnumType( (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), - _$enumDecode(_$EnumTypeEnumMap, e)), + (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), + $enumDecode(_$EnumTypeEnumMap, e)), ), ); @@ -2825,7 +2799,7 @@ SimpleClassOfIntToEnumType _$SimpleClassOfIntToEnumTypeFromJson( Map<String, dynamic> json) => SimpleClassOfIntToEnumType( (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(int.parse(k), _$enumDecode(_$EnumTypeEnumMap, e)), + (k, e) => MapEntry(int.parse(k), $enumDecode(_$EnumTypeEnumMap, e)), ), ); @@ -2840,7 +2814,7 @@ SimpleClassNullableOfIntToEnumType _$SimpleClassNullableOfIntToEnumTypeFromJson( Map<String, dynamic> json) => SimpleClassNullableOfIntToEnumType( (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(int.parse(k), _$enumDecode(_$EnumTypeEnumMap, e)), + (k, e) => MapEntry(int.parse(k), $enumDecode(_$EnumTypeEnumMap, e)), ), ); @@ -2855,7 +2829,7 @@ SimpleClassOfObjectToEnumType _$SimpleClassOfObjectToEnumTypeFromJson( Map<String, dynamic> json) => SimpleClassOfObjectToEnumType( (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(k, _$enumDecode(_$EnumTypeEnumMap, e)), + (k, e) => MapEntry(k, $enumDecode(_$EnumTypeEnumMap, e)), ), ); @@ -2870,7 +2844,7 @@ SimpleClassNullableOfObjectToEnumType Map<String, dynamic> json) => SimpleClassNullableOfObjectToEnumType( (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, _$enumDecode(_$EnumTypeEnumMap, e)), + (k, e) => MapEntry(k, $enumDecode(_$EnumTypeEnumMap, e)), ), ); @@ -2884,7 +2858,7 @@ SimpleClassOfStringToEnumType _$SimpleClassOfStringToEnumTypeFromJson( Map<String, dynamic> json) => SimpleClassOfStringToEnumType( (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(k, _$enumDecode(_$EnumTypeEnumMap, e)), + (k, e) => MapEntry(k, $enumDecode(_$EnumTypeEnumMap, e)), ), ); @@ -2899,7 +2873,7 @@ SimpleClassNullableOfStringToEnumType Map<String, dynamic> json) => SimpleClassNullableOfStringToEnumType( (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, _$enumDecode(_$EnumTypeEnumMap, e)), + (k, e) => MapEntry(k, $enumDecode(_$EnumTypeEnumMap, e)), ), ); @@ -2913,7 +2887,7 @@ SimpleClassOfUriToEnumType _$SimpleClassOfUriToEnumTypeFromJson( Map<String, dynamic> json) => SimpleClassOfUriToEnumType( (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(Uri.parse(k), _$enumDecode(_$EnumTypeEnumMap, e)), + (k, e) => MapEntry(Uri.parse(k), $enumDecode(_$EnumTypeEnumMap, e)), ), ); @@ -2928,7 +2902,7 @@ SimpleClassNullableOfUriToEnumType _$SimpleClassNullableOfUriToEnumTypeFromJson( Map<String, dynamic> json) => SimpleClassNullableOfUriToEnumType( (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(Uri.parse(k), _$enumDecode(_$EnumTypeEnumMap, e)), + (k, e) => MapEntry(Uri.parse(k), $enumDecode(_$EnumTypeEnumMap, e)), ), ); @@ -2945,7 +2919,7 @@ SimpleClassOfBigIntToEnumTypeNullable SimpleClassOfBigIntToEnumTypeNullable( (json['value'] as Map<String, dynamic>).map( (k, e) => MapEntry( - BigInt.parse(k), _$enumDecodeNullable(_$EnumTypeEnumMap, e)), + BigInt.parse(k), $enumDecodeNullable(_$EnumTypeEnumMap, e)), ), ); @@ -2956,24 +2930,13 @@ Map<String, dynamic> _$SimpleClassOfBigIntToEnumTypeNullableToJson( .map((k, e) => MapEntry(k.toString(), _$EnumTypeEnumMap[e])), }; -K? _$enumDecodeNullable<K, V>( - Map<K, V> enumValues, - dynamic source, { - K? unknownValue, -}) { - if (source == null) { - return null; - } - return _$enumDecode<K, V>(enumValues, source, unknownValue: unknownValue); -} - SimpleClassNullableOfBigIntToEnumTypeNullable _$SimpleClassNullableOfBigIntToEnumTypeNullableFromJson( Map<String, dynamic> json) => SimpleClassNullableOfBigIntToEnumTypeNullable( (json['value'] as Map<String, dynamic>?)?.map( (k, e) => MapEntry( - BigInt.parse(k), _$enumDecodeNullable(_$EnumTypeEnumMap, e)), + BigInt.parse(k), $enumDecodeNullable(_$EnumTypeEnumMap, e)), ), ); @@ -2990,7 +2953,7 @@ SimpleClassOfDateTimeToEnumTypeNullable SimpleClassOfDateTimeToEnumTypeNullable( (json['value'] as Map<String, dynamic>).map( (k, e) => MapEntry( - DateTime.parse(k), _$enumDecodeNullable(_$EnumTypeEnumMap, e)), + DateTime.parse(k), $enumDecodeNullable(_$EnumTypeEnumMap, e)), ), ); @@ -3007,7 +2970,7 @@ SimpleClassNullableOfDateTimeToEnumTypeNullable SimpleClassNullableOfDateTimeToEnumTypeNullable( (json['value'] as Map<String, dynamic>?)?.map( (k, e) => MapEntry( - DateTime.parse(k), _$enumDecodeNullable(_$EnumTypeEnumMap, e)), + DateTime.parse(k), $enumDecodeNullable(_$EnumTypeEnumMap, e)), ), ); @@ -3023,7 +2986,7 @@ SimpleClassOfDynamicToEnumTypeNullable Map<String, dynamic> json) => SimpleClassOfDynamicToEnumTypeNullable( (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(k, _$enumDecodeNullable(_$EnumTypeEnumMap, e)), + (k, e) => MapEntry(k, $enumDecodeNullable(_$EnumTypeEnumMap, e)), ), ); @@ -3038,7 +3001,7 @@ SimpleClassNullableOfDynamicToEnumTypeNullable Map<String, dynamic> json) => SimpleClassNullableOfDynamicToEnumTypeNullable( (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, _$enumDecodeNullable(_$EnumTypeEnumMap, e)), + (k, e) => MapEntry(k, $enumDecodeNullable(_$EnumTypeEnumMap, e)), ), ); @@ -3053,8 +3016,8 @@ SimpleClassOfEnumTypeToEnumTypeNullable Map<String, dynamic> json) => SimpleClassOfEnumTypeToEnumTypeNullable( (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), - _$enumDecodeNullable(_$EnumTypeEnumMap, e)), + (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), + $enumDecodeNullable(_$EnumTypeEnumMap, e)), ), ); @@ -3070,8 +3033,8 @@ SimpleClassNullableOfEnumTypeToEnumTypeNullable Map<String, dynamic> json) => SimpleClassNullableOfEnumTypeToEnumTypeNullable( (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), - _$enumDecodeNullable(_$EnumTypeEnumMap, e)), + (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), + $enumDecodeNullable(_$EnumTypeEnumMap, e)), ), ); @@ -3087,7 +3050,7 @@ SimpleClassOfIntToEnumTypeNullable _$SimpleClassOfIntToEnumTypeNullableFromJson( SimpleClassOfIntToEnumTypeNullable( (json['value'] as Map<String, dynamic>).map( (k, e) => - MapEntry(int.parse(k), _$enumDecodeNullable(_$EnumTypeEnumMap, e)), + MapEntry(int.parse(k), $enumDecodeNullable(_$EnumTypeEnumMap, e)), ), ); @@ -3104,7 +3067,7 @@ SimpleClassNullableOfIntToEnumTypeNullable SimpleClassNullableOfIntToEnumTypeNullable( (json['value'] as Map<String, dynamic>?)?.map( (k, e) => MapEntry( - int.parse(k), _$enumDecodeNullable(_$EnumTypeEnumMap, e)), + int.parse(k), $enumDecodeNullable(_$EnumTypeEnumMap, e)), ), ); @@ -3120,7 +3083,7 @@ SimpleClassOfObjectToEnumTypeNullable Map<String, dynamic> json) => SimpleClassOfObjectToEnumTypeNullable( (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(k, _$enumDecodeNullable(_$EnumTypeEnumMap, e)), + (k, e) => MapEntry(k, $enumDecodeNullable(_$EnumTypeEnumMap, e)), ), ); @@ -3135,7 +3098,7 @@ SimpleClassNullableOfObjectToEnumTypeNullable Map<String, dynamic> json) => SimpleClassNullableOfObjectToEnumTypeNullable( (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, _$enumDecodeNullable(_$EnumTypeEnumMap, e)), + (k, e) => MapEntry(k, $enumDecodeNullable(_$EnumTypeEnumMap, e)), ), ); @@ -3150,7 +3113,7 @@ SimpleClassOfStringToEnumTypeNullable Map<String, dynamic> json) => SimpleClassOfStringToEnumTypeNullable( (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(k, _$enumDecodeNullable(_$EnumTypeEnumMap, e)), + (k, e) => MapEntry(k, $enumDecodeNullable(_$EnumTypeEnumMap, e)), ), ); @@ -3165,7 +3128,7 @@ SimpleClassNullableOfStringToEnumTypeNullable Map<String, dynamic> json) => SimpleClassNullableOfStringToEnumTypeNullable( (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, _$enumDecodeNullable(_$EnumTypeEnumMap, e)), + (k, e) => MapEntry(k, $enumDecodeNullable(_$EnumTypeEnumMap, e)), ), ); @@ -3180,7 +3143,7 @@ SimpleClassOfUriToEnumTypeNullable _$SimpleClassOfUriToEnumTypeNullableFromJson( SimpleClassOfUriToEnumTypeNullable( (json['value'] as Map<String, dynamic>).map( (k, e) => - MapEntry(Uri.parse(k), _$enumDecodeNullable(_$EnumTypeEnumMap, e)), + MapEntry(Uri.parse(k), $enumDecodeNullable(_$EnumTypeEnumMap, e)), ), ); @@ -3197,7 +3160,7 @@ SimpleClassNullableOfUriToEnumTypeNullable SimpleClassNullableOfUriToEnumTypeNullable( (json['value'] as Map<String, dynamic>?)?.map( (k, e) => MapEntry( - Uri.parse(k), _$enumDecodeNullable(_$EnumTypeEnumMap, e)), + Uri.parse(k), $enumDecodeNullable(_$EnumTypeEnumMap, e)), ), ); @@ -3294,7 +3257,7 @@ SimpleClassOfEnumTypeToInt _$SimpleClassOfEnumTypeToIntFromJson( Map<String, dynamic> json) => SimpleClassOfEnumTypeToInt( (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as int), + (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e as int), ), ); @@ -3308,7 +3271,7 @@ SimpleClassNullableOfEnumTypeToInt _$SimpleClassNullableOfEnumTypeToIntFromJson( Map<String, dynamic> json) => SimpleClassNullableOfEnumTypeToInt( (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as int), + (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e as int), ), ); @@ -3515,7 +3478,7 @@ SimpleClassOfEnumTypeToIntNullable _$SimpleClassOfEnumTypeToIntNullableFromJson( Map<String, dynamic> json) => SimpleClassOfEnumTypeToIntNullable( (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as int?), + (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e as int?), ), ); @@ -3530,7 +3493,7 @@ SimpleClassNullableOfEnumTypeToIntNullable Map<String, dynamic> json) => SimpleClassNullableOfEnumTypeToIntNullable( (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as int?), + (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e as int?), ), ); @@ -3738,7 +3701,7 @@ SimpleClassOfEnumTypeToNum _$SimpleClassOfEnumTypeToNumFromJson( Map<String, dynamic> json) => SimpleClassOfEnumTypeToNum( (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as num), + (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e as num), ), ); @@ -3752,7 +3715,7 @@ SimpleClassNullableOfEnumTypeToNum _$SimpleClassNullableOfEnumTypeToNumFromJson( Map<String, dynamic> json) => SimpleClassNullableOfEnumTypeToNum( (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as num), + (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e as num), ), ); @@ -3959,7 +3922,7 @@ SimpleClassOfEnumTypeToNumNullable _$SimpleClassOfEnumTypeToNumNullableFromJson( Map<String, dynamic> json) => SimpleClassOfEnumTypeToNumNullable( (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as num?), + (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e as num?), ), ); @@ -3974,7 +3937,7 @@ SimpleClassNullableOfEnumTypeToNumNullable Map<String, dynamic> json) => SimpleClassNullableOfEnumTypeToNumNullable( (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as num?), + (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e as num?), ), ); @@ -4185,7 +4148,7 @@ SimpleClassOfEnumTypeToObject _$SimpleClassOfEnumTypeToObjectFromJson( Map<String, dynamic> json) => SimpleClassOfEnumTypeToObject( (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as Object), + (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e as Object), ), ); @@ -4200,7 +4163,7 @@ SimpleClassNullableOfEnumTypeToObject Map<String, dynamic> json) => SimpleClassNullableOfEnumTypeToObject( (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as Object), + (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e as Object), ), ); @@ -4411,7 +4374,7 @@ SimpleClassOfEnumTypeToObjectNullable Map<String, dynamic> json) => SimpleClassOfEnumTypeToObjectNullable( (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e), + (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e), ), ); @@ -4426,7 +4389,7 @@ SimpleClassNullableOfEnumTypeToObjectNullable Map<String, dynamic> json) => SimpleClassNullableOfEnumTypeToObjectNullable( (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e), + (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e), ), ); @@ -4631,7 +4594,7 @@ SimpleClassOfEnumTypeToString _$SimpleClassOfEnumTypeToStringFromJson( Map<String, dynamic> json) => SimpleClassOfEnumTypeToString( (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as String), + (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e as String), ), ); @@ -4646,7 +4609,7 @@ SimpleClassNullableOfEnumTypeToString Map<String, dynamic> json) => SimpleClassNullableOfEnumTypeToString( (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as String), + (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e as String), ), ); @@ -4855,8 +4818,7 @@ SimpleClassOfEnumTypeToStringNullable Map<String, dynamic> json) => SimpleClassOfEnumTypeToStringNullable( (json['value'] as Map<String, dynamic>).map( - (k, e) => - MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as String?), + (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e as String?), ), ); @@ -4871,8 +4833,7 @@ SimpleClassNullableOfEnumTypeToStringNullable Map<String, dynamic> json) => SimpleClassNullableOfEnumTypeToStringNullable( (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => - MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), e as String?), + (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e as String?), ), ); @@ -5086,8 +5047,8 @@ SimpleClassOfEnumTypeToUri _$SimpleClassOfEnumTypeToUriFromJson( Map<String, dynamic> json) => SimpleClassOfEnumTypeToUri( (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry( - _$enumDecode(_$EnumTypeEnumMap, k), Uri.parse(e as String)), + (k, e) => + MapEntry($enumDecode(_$EnumTypeEnumMap, k), Uri.parse(e as String)), ), ); @@ -5102,8 +5063,8 @@ SimpleClassNullableOfEnumTypeToUri _$SimpleClassNullableOfEnumTypeToUriFromJson( Map<String, dynamic> json) => SimpleClassNullableOfEnumTypeToUri( (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry( - _$enumDecode(_$EnumTypeEnumMap, k), Uri.parse(e as String)), + (k, e) => + MapEntry($enumDecode(_$EnumTypeEnumMap, k), Uri.parse(e as String)), ), ); @@ -5329,7 +5290,7 @@ SimpleClassOfEnumTypeToUriNullable _$SimpleClassOfEnumTypeToUriNullableFromJson( Map<String, dynamic> json) => SimpleClassOfEnumTypeToUriNullable( (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), + (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e == null ? null : Uri.parse(e as String)), ), ); @@ -5346,7 +5307,7 @@ SimpleClassNullableOfEnumTypeToUriNullable Map<String, dynamic> json) => SimpleClassNullableOfEnumTypeToUriNullable( (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(_$enumDecode(_$EnumTypeEnumMap, k), + (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e == null ? null : Uri.parse(e as String)), ), ); diff --git a/json_serializable/test/supported_types/input.type_set.g.dart b/json_serializable/test/supported_types/input.type_set.g.dart index 7cb3f7976..a028e2791 100644 --- a/json_serializable/test/supported_types/input.type_set.g.dart +++ b/json_serializable/test/supported_types/input.type_set.g.dart @@ -332,7 +332,7 @@ SimpleClassOfEnumType _$SimpleClassOfEnumTypeFromJson( Map<String, dynamic> json) => SimpleClassOfEnumType( (json['value'] as List<dynamic>) - .map((e) => _$enumDecode(_$EnumTypeEnumMap, e)) + .map((e) => $enumDecode(_$EnumTypeEnumMap, e)) .toSet(), ); @@ -342,32 +342,6 @@ Map<String, dynamic> _$SimpleClassOfEnumTypeToJson( 'value': instance.value.map((e) => _$EnumTypeEnumMap[e]).toList(), }; -K _$enumDecode<K, V>( - Map<K, V> enumValues, - Object? source, { - K? unknownValue, -}) { - if (source == null) { - throw ArgumentError( - 'A value must be provided. Supported values: ' - '${enumValues.values.join(', ')}', - ); - } - - return enumValues.entries.singleWhere( - (e) => e.value == source, - orElse: () { - if (unknownValue == null) { - throw ArgumentError( - '`$source` is not one of the supported values: ' - '${enumValues.values.join(', ')}', - ); - } - return MapEntry(unknownValue, enumValues.values.first); - }, - ).key; -} - const _$EnumTypeEnumMap = { EnumType.alpha: 'alpha', EnumType.beta: 'beta', @@ -379,7 +353,7 @@ SimpleClassNullableOfEnumType _$SimpleClassNullableOfEnumTypeFromJson( Map<String, dynamic> json) => SimpleClassNullableOfEnumType( (json['value'] as List<dynamic>?) - ?.map((e) => _$enumDecode(_$EnumTypeEnumMap, e)) + ?.map((e) => $enumDecode(_$EnumTypeEnumMap, e)) .toSet(), ); @@ -393,7 +367,7 @@ SimpleClassOfEnumTypeNullable _$SimpleClassOfEnumTypeNullableFromJson( Map<String, dynamic> json) => SimpleClassOfEnumTypeNullable( (json['value'] as List<dynamic>) - .map((e) => _$enumDecodeNullable(_$EnumTypeEnumMap, e)) + .map((e) => $enumDecodeNullable(_$EnumTypeEnumMap, e)) .toSet(), ); @@ -403,23 +377,12 @@ Map<String, dynamic> _$SimpleClassOfEnumTypeNullableToJson( 'value': instance.value.map((e) => _$EnumTypeEnumMap[e]).toList(), }; -K? _$enumDecodeNullable<K, V>( - Map<K, V> enumValues, - dynamic source, { - K? unknownValue, -}) { - if (source == null) { - return null; - } - return _$enumDecode<K, V>(enumValues, source, unknownValue: unknownValue); -} - SimpleClassNullableOfEnumTypeNullable _$SimpleClassNullableOfEnumTypeNullableFromJson( Map<String, dynamic> json) => SimpleClassNullableOfEnumTypeNullable( (json['value'] as List<dynamic>?) - ?.map((e) => _$enumDecodeNullable(_$EnumTypeEnumMap, e)) + ?.map((e) => $enumDecodeNullable(_$EnumTypeEnumMap, e)) .toSet(), ); From b411952982e8a07e84ea8da88443c526408a4b98 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@google.com> Date: Tue, 28 Sep 2021 14:19:48 -0700 Subject: [PATCH 347/569] test: move enum bits to their own library --- .../test/integration/integration_test.dart | 1 + .../test/integration/json_enum_example.dart | 17 +++++++++++++++++ .../test/integration/json_enum_example.g.dart | 16 ++++++++++++++++ .../test/integration/json_test_example.dart | 14 -------------- .../test/integration/json_test_example.g.dart | 7 ------- .../json_test_example.g_any_map.dart | 14 -------------- .../json_test_example.g_any_map.g.dart | 7 ------- 7 files changed, 34 insertions(+), 42 deletions(-) create mode 100644 json_serializable/test/integration/json_enum_example.dart create mode 100644 json_serializable/test/integration/json_enum_example.g.dart diff --git a/json_serializable/test/integration/integration_test.dart b/json_serializable/test/integration/integration_test.dart index ab480132f..7f06ea01b 100644 --- a/json_serializable/test/integration/integration_test.dart +++ b/json_serializable/test/integration/integration_test.dart @@ -5,6 +5,7 @@ import 'package:test/test.dart'; import '../test_utils.dart'; +import 'json_enum_example.dart'; import 'json_test_common.dart' show Category, Platform, StatusCode; import 'json_test_example.dart'; diff --git a/json_serializable/test/integration/json_enum_example.dart b/json_serializable/test/integration/json_enum_example.dart new file mode 100644 index 000000000..5f9b80f85 --- /dev/null +++ b/json_serializable/test/integration/json_enum_example.dart @@ -0,0 +1,17 @@ +import 'package:json_annotation/json_annotation.dart'; + +part 'json_enum_example.g.dart'; + +@JsonEnum(alwaysCreate: true) +enum StandAloneEnum { + @JsonValue('a') + alpha, + @JsonValue('b') + beta, + @JsonValue('g') + gamma, + @JsonValue('d') + delta, +} + +Iterable<String> get standAloneEnumKeys => _$StandAloneEnumEnumMap.values; diff --git a/json_serializable/test/integration/json_enum_example.g.dart b/json_serializable/test/integration/json_enum_example.g.dart new file mode 100644 index 000000000..ba355b2fa --- /dev/null +++ b/json_serializable/test/integration/json_enum_example.g.dart @@ -0,0 +1,16 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +// ignore_for_file: lines_longer_than_80_chars + +part of 'json_enum_example.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +const _$StandAloneEnumEnumMap = { + StandAloneEnum.alpha: 'a', + StandAloneEnum.beta: 'b', + StandAloneEnum.gamma: 'g', + StandAloneEnum.delta: 'd', +}; diff --git a/json_serializable/test/integration/json_test_example.dart b/json_serializable/test/integration/json_test_example.dart index 3266aad3c..b4c0ab86c 100644 --- a/json_serializable/test/integration/json_test_example.dart +++ b/json_serializable/test/integration/json_test_example.dart @@ -239,17 +239,3 @@ class PrivateConstructor { bool operator ==(Object other) => other is PrivateConstructor && id == other.id && value == other.value; } - -@JsonEnum(alwaysCreate: true) -enum StandAloneEnum { - @JsonValue('a') - alpha, - @JsonValue('b') - beta, - @JsonValue('g') - gamma, - @JsonValue('d') - delta, -} - -Iterable<String> get standAloneEnumKeys => _$StandAloneEnumEnumMap.values; diff --git a/json_serializable/test/integration/json_test_example.g.dart b/json_serializable/test/integration/json_test_example.g.dart index b665e1048..a4a8172a1 100644 --- a/json_serializable/test/integration/json_test_example.g.dart +++ b/json_serializable/test/integration/json_test_example.g.dart @@ -213,10 +213,3 @@ Map<String, dynamic> _$PrivateConstructorToJson(PrivateConstructor instance) => 'id': instance.id, 'value': instance.value, }; - -const _$StandAloneEnumEnumMap = { - StandAloneEnum.alpha: 'a', - StandAloneEnum.beta: 'b', - StandAloneEnum.gamma: 'g', - StandAloneEnum.delta: 'd', -}; diff --git a/json_serializable/test/integration/json_test_example.g_any_map.dart b/json_serializable/test/integration/json_test_example.g_any_map.dart index c105189a2..a6ce3663b 100644 --- a/json_serializable/test/integration/json_test_example.g_any_map.dart +++ b/json_serializable/test/integration/json_test_example.g_any_map.dart @@ -247,17 +247,3 @@ class PrivateConstructor { bool operator ==(Object other) => other is PrivateConstructor && id == other.id && value == other.value; } - -@JsonEnum(alwaysCreate: true) -enum StandAloneEnum { - @JsonValue('a') - alpha, - @JsonValue('b') - beta, - @JsonValue('g') - gamma, - @JsonValue('d') - delta, -} - -Iterable<String> get standAloneEnumKeys => _$StandAloneEnumEnumMap.values; diff --git a/json_serializable/test/integration/json_test_example.g_any_map.g.dart b/json_serializable/test/integration/json_test_example.g_any_map.g.dart index cdedd8cae..b25d890bb 100644 --- a/json_serializable/test/integration/json_test_example.g_any_map.g.dart +++ b/json_serializable/test/integration/json_test_example.g_any_map.g.dart @@ -211,10 +211,3 @@ Map<String, dynamic> _$PrivateConstructorToJson(PrivateConstructor instance) => 'id': instance.id, 'value': instance.value, }; - -const _$StandAloneEnumEnumMap = { - StandAloneEnum.alpha: 'a', - StandAloneEnum.beta: 'b', - StandAloneEnum.gamma: 'g', - StandAloneEnum.delta: 'd', -}; From d83b3f6977e8a2b08150e0a676df7a09990a08eb Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@google.com> Date: Tue, 28 Sep 2021 15:35:33 -0700 Subject: [PATCH 348/569] utils: refactor logic around getting enum fields --- json_serializable/lib/src/utils.dart | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index 1f41232e8..9d25b5fff 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -175,21 +175,26 @@ Map<FieldElement, dynamic>? enumFieldsMap(DartType targetType) { return entry; } - if (targetType is InterfaceType && targetType.element.isEnum) { - return _enumMapExpando[targetType] ??= - Map<FieldElement, dynamic>.fromEntries(targetType.element.fields - .where((p) => !p.isSynthetic) - .map(_generateEntry)); + final enumFields = iterateEnumFields(targetType); + + if (enumFields == null) { + return null; } - return null; + + return _enumMapExpando[targetType] ??= + Map<FieldElement, dynamic>.fromEntries(enumFields.map(_generateEntry)); } /// If [targetType] is an enum, returns the [FieldElement] instances associated /// with its values. /// /// Otherwise, `null`. -Iterable<FieldElement>? iterateEnumFields(DartType targetType) => - enumFieldsMap(targetType)?.keys; +Iterable<FieldElement>? iterateEnumFields(DartType targetType) { + if (targetType is InterfaceType && targetType.element.isEnum) { + return targetType.element.fields.where((element) => !element.isSynthetic); + } + return null; +} extension DartTypeExtension on DartType { DartType promoteNonNullable() => From fcbd439fc073fd5e1b1ab319eceaa9cc86a542d6 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@google.com> Date: Tue, 28 Sep 2021 16:02:10 -0700 Subject: [PATCH 349/569] json_key_util: cleanup field rename logic --- json_serializable/lib/src/json_key_utils.dart | 28 ++++++------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/json_serializable/lib/src/json_key_utils.dart b/json_serializable/lib/src/json_key_utils.dart index 26a74b33f..5e6f5b85c 100644 --- a/json_serializable/lib/src/json_key_utils.dart +++ b/json_serializable/lib/src/json_key_utils.dart @@ -226,37 +226,25 @@ KeyConfig _populateJsonKey( ignore: ignore ?? false, includeIfNull: _includeIfNull( includeIfNull, disallowNullValue, classAnnotation.includeIfNull), - name: _encodedFieldName(classAnnotation, name, element), + name: name ?? _encodedFieldName(classAnnotation.fieldRename, element.name), required: required ?? false, unknownEnumValue: unknownEnumValue, ); } String _encodedFieldName( - JsonSerializable classAnnotation, - String? jsonKeyNameValue, - FieldElement fieldElement, + FieldRename fieldRename, + String declaredName, ) { - if (jsonKeyNameValue != null) { - return jsonKeyNameValue; - } - - switch (classAnnotation.fieldRename) { + switch (fieldRename) { case FieldRename.none: - return fieldElement.name; + return declaredName; case FieldRename.snake: - return fieldElement.name.snake; + return declaredName.snake; case FieldRename.kebab: - return fieldElement.name.kebab; + return declaredName.kebab; case FieldRename.pascal: - return fieldElement.name.pascal; - default: - throw ArgumentError.value( - classAnnotation, - 'classAnnotation', - 'The provided `fieldRename` (${classAnnotation.fieldRename}) is not ' - 'supported.', - ); + return declaredName.pascal; } } From 3a0cc4317883b2c45b87e8630d20ffb626cab5d0 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@google.com> Date: Tue, 28 Sep 2021 14:02:34 -0700 Subject: [PATCH 350/569] Allow specifying rename logic for enum entries using @JsonEnum Fixes https://github.com/google/json_serializable.dart/issues/297 --- _test_yaml/test/src/build_config.dart | 5 +- json_annotation/lib/src/json_enum.dart | 14 ++++ json_serializable/lib/src/enum_utils.dart | 84 +++++++++++++++++++ .../lib/src/json_enum_generator.dart | 17 ++-- json_serializable/lib/src/json_key_utils.dart | 19 +---- .../lib/src/type_helpers/enum_helper.dart | 25 +----- json_serializable/lib/src/utils.dart | 68 ++++----------- .../test/integration/integration_test.dart | 3 +- .../test/integration/json_enum_example.dart | 11 ++- .../test/integration/json_enum_example.g.dart | 6 ++ .../test/integration/json_test_common.dart | 2 + 11 files changed, 147 insertions(+), 107 deletions(-) create mode 100644 json_serializable/lib/src/enum_utils.dart diff --git a/_test_yaml/test/src/build_config.dart b/_test_yaml/test/src/build_config.dart index 91e0383e8..a749d442a 100644 --- a/_test_yaml/test/src/build_config.dart +++ b/_test_yaml/test/src/build_config.dart @@ -81,13 +81,12 @@ class Builder { Map<String, dynamic> toJson() => _$BuilderToJson(this); } +@JsonEnum(fieldRename: FieldRename.snake) enum AutoApply { none, dependents, - @JsonValue('all_packages') allPackages, - @JsonValue('root_package') - rootPackage + rootPackage, } enum BuildTo { cache, source } diff --git a/json_annotation/lib/src/json_enum.dart b/json_annotation/lib/src/json_enum.dart index c5ba66541..0d186a184 100644 --- a/json_annotation/lib/src/json_enum.dart +++ b/json_annotation/lib/src/json_enum.dart @@ -5,12 +5,14 @@ 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, }); /// If `true`, `_$[enum name]EnumMap` is generated for in library containing @@ -20,4 +22,16 @@ class JsonEnum { /// 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; } diff --git a/json_serializable/lib/src/enum_utils.dart b/json_serializable/lib/src/enum_utils.dart new file mode 100644 index 000000000..bda9ae037 --- /dev/null +++ b/json_serializable/lib/src/enum_utils.dart @@ -0,0 +1,84 @@ +// 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:analyzer/dart/constant/value.dart'; +import 'package:analyzer/dart/element/element.dart'; +import 'package:analyzer/dart/element/type.dart'; +import 'package:json_annotation/json_annotation.dart'; +import 'package:source_gen/source_gen.dart'; + +import 'helper_core.dart'; +import 'json_literal_generator.dart'; +import 'utils.dart'; + +String constMapName(DartType targetType) => + '_\$${targetType.element!.name}EnumMap'; + +String? enumValueMapFromType( + DartType targetType, { + bool nullWithNoAnnotation = false, +}) { + final annotation = _jsonEnumChecker.firstAnnotationOf(targetType.element!); + final jsonEnum = _fromAnnotation(annotation); + + final enumFields = iterateEnumFields(targetType); + + if (enumFields == null || (nullWithNoAnnotation && !jsonEnum.alwaysCreate)) { + return null; + } + + MapEntry<FieldElement, dynamic> _generateEntry(FieldElement fe) { + final annotation = + const TypeChecker.fromRuntime(JsonValue).firstAnnotationOfExact(fe); + + dynamic fieldValue; + if (annotation == null) { + fieldValue = encodedFieldName(jsonEnum.fieldRename, fe.name); + } else { + final reader = ConstantReader(annotation); + + final valueReader = reader.read('value'); + + if (valueReader.isString || valueReader.isNull || valueReader.isInt) { + fieldValue = valueReader.literalValue; + } else { + final targetTypeCode = typeToCode(targetType); + throw InvalidGenerationSourceError( + 'The `JsonValue` annotation on `$targetTypeCode.${fe.name}` does ' + 'not have a value of type String, int, or null.', + element: fe); + } + } + + final entry = MapEntry(fe, fieldValue); + + return entry; + } + + final enumMap = + Map<FieldElement, dynamic>.fromEntries(enumFields.map(_generateEntry)); + + final items = enumMap.entries + .map((e) => ' ${targetType.element!.name}.${e.key.name}: ' + '${jsonLiteralAsDart(e.value)},') + .join(); + + return 'const ${constMapName(targetType)} = {\n$items\n};'; +} + +const _jsonEnumChecker = TypeChecker.fromRuntime(JsonEnum); + +JsonEnum _fromAnnotation(DartObject? dartObject) { + if (dartObject == null) { + return const JsonEnum(); + } + final reader = ConstantReader(dartObject); + return JsonEnum( + alwaysCreate: reader.read('alwaysCreate').literalValue as bool, + fieldRename: enumValueForDartObject( + reader.read('fieldRename').objectValue, + FieldRename.values, + (f) => f.toString().split('.')[1], + )); +} diff --git a/json_serializable/lib/src/json_enum_generator.dart b/json_serializable/lib/src/json_enum_generator.dart index 5f3dbd13c..171df15b1 100644 --- a/json_serializable/lib/src/json_enum_generator.dart +++ b/json_serializable/lib/src/json_enum_generator.dart @@ -7,7 +7,7 @@ import 'package:build/build.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:source_gen/source_gen.dart'; -import 'type_helpers/enum_helper.dart'; +import 'enum_utils.dart'; class JsonEnumGenerator extends GeneratorForAnnotation<JsonEnum> { const JsonEnumGenerator(); @@ -25,16 +25,11 @@ class JsonEnumGenerator extends GeneratorForAnnotation<JsonEnum> { ); } - final jsonEnum = _fromAnnotation(annotation); + final value = + enumValueMapFromType(element.thisType, nullWithNoAnnotation: true); - if (!jsonEnum.alwaysCreate) { - return const []; - } - - return [enumValueMapFromType(element.thisType)!]; + return [ + if (value != null) value, + ]; } } - -JsonEnum _fromAnnotation(ConstantReader reader) => JsonEnum( - alwaysCreate: reader.read('alwaysCreate').literalValue as bool, - ); diff --git a/json_serializable/lib/src/json_key_utils.dart b/json_serializable/lib/src/json_key_utils.dart index 5e6f5b85c..932741901 100644 --- a/json_serializable/lib/src/json_key_utils.dart +++ b/json_serializable/lib/src/json_key_utils.dart @@ -6,7 +6,6 @@ import 'package:analyzer/dart/constant/value.dart'; import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/type.dart'; import 'package:build/build.dart'; -import 'package:json_annotation/json_annotation.dart'; import 'package:source_gen/source_gen.dart'; import 'package:source_helper/source_helper.dart'; @@ -226,28 +225,12 @@ KeyConfig _populateJsonKey( ignore: ignore ?? false, includeIfNull: _includeIfNull( includeIfNull, disallowNullValue, classAnnotation.includeIfNull), - name: name ?? _encodedFieldName(classAnnotation.fieldRename, element.name), + name: name ?? encodedFieldName(classAnnotation.fieldRename, element.name), required: required ?? false, unknownEnumValue: unknownEnumValue, ); } -String _encodedFieldName( - FieldRename fieldRename, - String declaredName, -) { - switch (fieldRename) { - case FieldRename.none: - return declaredName; - case FieldRename.snake: - return declaredName.snake; - case FieldRename.kebab: - return declaredName.kebab; - case FieldRename.pascal: - return declaredName.pascal; - } -} - bool _includeIfNull( bool? keyIncludeIfNull, bool? keyDisallowNullValue, diff --git a/json_serializable/lib/src/type_helpers/enum_helper.dart b/json_serializable/lib/src/type_helpers/enum_helper.dart index c8926e624..68609da65 100644 --- a/json_serializable/lib/src/type_helpers/enum_helper.dart +++ b/json_serializable/lib/src/type_helpers/enum_helper.dart @@ -5,10 +5,9 @@ import 'package:analyzer/dart/element/type.dart'; import 'package:source_helper/source_helper.dart'; +import '../enum_utils.dart'; import '../json_key_utils.dart'; -import '../json_literal_generator.dart'; import '../type_helper.dart'; -import '../utils.dart'; final simpleExpression = RegExp('^[a-zA-Z_]+\$'); @@ -29,7 +28,7 @@ class EnumHelper extends TypeHelper<TypeHelperContextWithConfig> { context.addMember(memberContent); - return '${_constMapName(targetType)}[$expression]'; + return '${constMapName(targetType)}[$expression]'; } @override @@ -56,7 +55,7 @@ class EnumHelper extends TypeHelper<TypeHelperContextWithConfig> { final jsonKey = jsonKeyForField(context.fieldElement, context.config); final args = [ - _constMapName(targetType), + constMapName(targetType), expression, if (jsonKey.unknownEnumValue != null) 'unknownValue: ${jsonKey.unknownEnumValue}', @@ -65,21 +64,3 @@ class EnumHelper extends TypeHelper<TypeHelperContextWithConfig> { return '$functionName(${args.join(', ')})'; } } - -String _constMapName(DartType targetType) => - '_\$${targetType.element!.name}EnumMap'; - -String? enumValueMapFromType(DartType targetType) { - final enumMap = enumFieldsMap(targetType); - - if (enumMap == null) { - return null; - } - - final items = enumMap.entries - .map((e) => ' ${targetType.element!.name}.${e.key.name}: ' - '${jsonLiteralAsDart(e.value)},') - .join(); - - return 'const ${_constMapName(targetType)} = {\n$items\n};'; -} diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index 9d25b5fff..df12ffccc 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -7,8 +7,8 @@ import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/type.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:source_gen/source_gen.dart'; +import 'package:source_helper/source_helper.dart'; -import 'helper_core.dart'; import 'type_helpers/config_types.dart'; const _jsonKeyChecker = TypeChecker.fromRuntime(JsonKey); @@ -135,56 +135,6 @@ ConstructorElement constructorByName(ClassElement classElement, String name) { return ctor; } -final _enumMapExpando = Expando<Map<FieldElement, dynamic>>(); - -/// If [targetType] is an enum, returns a [Map] of the [FieldElement] instances -/// associated with the enum values mapped to the [String] values that represent -/// the serialized output. -/// -/// By default, the [String] value is just the name of the enum value. -/// If the enum value is annotated with [JsonKey], then the `name` property is -/// used if it's set and not `null`. -/// -/// If [targetType] is not an enum, `null` is returned. -Map<FieldElement, dynamic>? enumFieldsMap(DartType targetType) { - MapEntry<FieldElement, dynamic> _generateEntry(FieldElement fe) { - final annotation = - const TypeChecker.fromRuntime(JsonValue).firstAnnotationOfExact(fe); - - dynamic fieldValue; - if (annotation == null) { - fieldValue = fe.name; - } else { - final reader = ConstantReader(annotation); - - final valueReader = reader.read('value'); - - if (valueReader.isString || valueReader.isNull || valueReader.isInt) { - fieldValue = valueReader.literalValue; - } else { - final targetTypeCode = typeToCode(targetType); - throw InvalidGenerationSourceError( - 'The `JsonValue` annotation on `$targetTypeCode.${fe.name}` does ' - 'not have a value of type String, int, or null.', - element: fe); - } - } - - final entry = MapEntry(fe, fieldValue); - - return entry; - } - - final enumFields = iterateEnumFields(targetType); - - if (enumFields == null) { - return null; - } - - return _enumMapExpando[targetType] ??= - Map<FieldElement, dynamic>.fromEntries(enumFields.map(_generateEntry)); -} - /// If [targetType] is an enum, returns the [FieldElement] instances associated /// with its values. /// @@ -203,3 +153,19 @@ extension DartTypeExtension on DartType { String ifNullOrElse(String test, String ifNull, String ifNotNull) => '$test == null ? $ifNull : $ifNotNull'; + +String encodedFieldName( + FieldRename fieldRename, + String declaredName, +) { + switch (fieldRename) { + case FieldRename.none: + return declaredName; + case FieldRename.snake: + return declaredName.snake; + case FieldRename.kebab: + return declaredName.kebab; + case FieldRename.pascal: + return declaredName.pascal; + } +} diff --git a/json_serializable/test/integration/integration_test.dart b/json_serializable/test/integration/integration_test.dart index 7f06ea01b..ab20d28e2 100644 --- a/json_serializable/test/integration/integration_test.dart +++ b/json_serializable/test/integration/integration_test.dart @@ -299,6 +299,7 @@ void main() { }); test('enum helpers', () { - expect(standAloneEnumKeys, ['a', 'b', 'g', 'd']); + expect(standAloneEnumValues, ['a', 'b', 'g', 'd']); + expect(dayTypeEnumValues, ['no-good', 'rotten', 'very-bad']); }); } diff --git a/json_serializable/test/integration/json_enum_example.dart b/json_serializable/test/integration/json_enum_example.dart index 5f9b80f85..fe7cfa279 100644 --- a/json_serializable/test/integration/json_enum_example.dart +++ b/json_serializable/test/integration/json_enum_example.dart @@ -14,4 +14,13 @@ enum StandAloneEnum { delta, } -Iterable<String> get standAloneEnumKeys => _$StandAloneEnumEnumMap.values; +Iterable<String> get standAloneEnumValues => _$StandAloneEnumEnumMap.values; + +@JsonEnum(alwaysCreate: true, fieldRename: FieldRename.kebab) +enum DayType { + noGood, + rotten, + veryBad, +} + +Iterable<String> get dayTypeEnumValues => _$DayTypeEnumMap.values; diff --git a/json_serializable/test/integration/json_enum_example.g.dart b/json_serializable/test/integration/json_enum_example.g.dart index ba355b2fa..c99f8d56a 100644 --- a/json_serializable/test/integration/json_enum_example.g.dart +++ b/json_serializable/test/integration/json_enum_example.g.dart @@ -14,3 +14,9 @@ const _$StandAloneEnumEnumMap = { StandAloneEnum.gamma: 'g', StandAloneEnum.delta: 'd', }; + +const _$DayTypeEnumMap = { + DayType.noGood: 'no-good', + DayType.rotten: 'rotten', + DayType.veryBad: 'very-bad', +}; diff --git a/json_serializable/test/integration/json_test_common.dart b/json_serializable/test/integration/json_test_common.dart index 81f671172..fb7c4d212 100644 --- a/json_serializable/test/integration/json_test_common.dart +++ b/json_serializable/test/integration/json_test_common.dart @@ -6,6 +6,7 @@ import 'dart:collection'; import 'package:json_annotation/json_annotation.dart'; +@JsonEnum(fieldRename: FieldRename.kebab) enum Category { top, bottom, @@ -13,6 +14,7 @@ enum Category { charmed, up, down, + // NOTE: this should override the kebab bits below! @JsonValue('not_discovered_yet') notDiscoveredYet } From b4d09edeb66e71723763ac7b6f4e103cf092be5a Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@google.com> Date: Tue, 28 Sep 2021 16:31:17 -0700 Subject: [PATCH 351/569] Refactoring: move typeToCode to a better spot --- json_serializable/lib/src/enum_utils.dart | 1 - json_serializable/lib/src/helper_core.dart | 24 +------------------ .../lib/src/shared_checkers.dart | 2 +- .../type_helpers/json_converter_helper.dart | 2 +- .../lib/src/type_helpers/json_helper.dart | 1 - .../lib/src/type_helpers/value_helper.dart | 2 +- json_serializable/lib/src/utils.dart | 23 ++++++++++++++++++ 7 files changed, 27 insertions(+), 28 deletions(-) diff --git a/json_serializable/lib/src/enum_utils.dart b/json_serializable/lib/src/enum_utils.dart index bda9ae037..fe379d36a 100644 --- a/json_serializable/lib/src/enum_utils.dart +++ b/json_serializable/lib/src/enum_utils.dart @@ -8,7 +8,6 @@ import 'package:analyzer/dart/element/type.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:source_gen/source_gen.dart'; -import 'helper_core.dart'; import 'json_literal_generator.dart'; import 'utils.dart'; diff --git a/json_serializable/lib/src/helper_core.dart b/json_serializable/lib/src/helper_core.dart index df50f0455..700cab2b3 100644 --- a/json_serializable/lib/src/helper_core.dart +++ b/json_serializable/lib/src/helper_core.dart @@ -14,6 +14,7 @@ import 'type_helper.dart'; import 'type_helper_ctx.dart'; import 'type_helpers/config_types.dart'; import 'unsupported_type_error.dart'; +import 'utils.dart'; abstract class HelperCore { final ClassElement element; @@ -127,26 +128,3 @@ String genericClassArguments(ClassElement element, bool? withConstraints) { }).join(', '); return '<$values>'; } - -/// Return the Dart code presentation for the given [type]. -/// -/// This function is intentionally limited, and does not support all possible -/// types and locations of these files in code. Specifically, it supports -/// only [InterfaceType]s, with optional type arguments that are also should -/// be [InterfaceType]s. -String typeToCode( - DartType type, { - bool forceNullable = false, -}) { - if (type.isDynamic) { - return 'dynamic'; - } else if (type is InterfaceType) { - return [ - type.element.name, - if (type.typeArguments.isNotEmpty) - '<${type.typeArguments.map(typeToCode).join(', ')}>', - (type.isNullableType || forceNullable) ? '?' : '', - ].join(); - } - throw UnimplementedError('(${type.runtimeType}) $type'); -} diff --git a/json_serializable/lib/src/shared_checkers.dart b/json_serializable/lib/src/shared_checkers.dart index b88635c19..a8e0abcc6 100644 --- a/json_serializable/lib/src/shared_checkers.dart +++ b/json_serializable/lib/src/shared_checkers.dart @@ -6,7 +6,7 @@ import 'package:analyzer/dart/element/type.dart'; import 'package:source_gen/source_gen.dart' show TypeChecker; import 'package:source_helper/source_helper.dart'; -import 'helper_core.dart'; +import 'utils.dart'; /// A [TypeChecker] for [Iterable]. const coreIterableTypeChecker = TypeChecker.fromUrl('dart:core#Iterable'); diff --git a/json_serializable/lib/src/type_helpers/json_converter_helper.dart b/json_serializable/lib/src/type_helpers/json_converter_helper.dart index 66182a8ba..8c0df9f3a 100644 --- a/json_serializable/lib/src/type_helpers/json_converter_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_converter_helper.dart @@ -10,10 +10,10 @@ import 'package:json_annotation/json_annotation.dart'; import 'package:source_gen/source_gen.dart'; import 'package:source_helper/source_helper.dart'; -import '../helper_core.dart'; import '../lambda_result.dart'; import '../shared_checkers.dart'; import '../type_helper.dart'; +import '../utils.dart'; /// A [TypeHelper] that supports classes annotated with implementations of /// [JsonConverter]. diff --git a/json_serializable/lib/src/type_helpers/json_helper.dart b/json_serializable/lib/src/type_helpers/json_helper.dart index 48b5243af..e61ed9f90 100644 --- a/json_serializable/lib/src/type_helpers/json_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_helper.dart @@ -11,7 +11,6 @@ import 'package:source_gen/source_gen.dart'; import 'package:source_helper/source_helper.dart'; import '../default_container.dart'; -import '../helper_core.dart'; import '../type_helper.dart'; import '../utils.dart'; import 'config_types.dart'; diff --git a/json_serializable/lib/src/type_helpers/value_helper.dart b/json_serializable/lib/src/type_helpers/value_helper.dart index c9c67fae0..f87e6cd03 100644 --- a/json_serializable/lib/src/type_helpers/value_helper.dart +++ b/json_serializable/lib/src/type_helpers/value_helper.dart @@ -5,9 +5,9 @@ import 'package:analyzer/dart/element/type.dart'; import 'package:source_helper/source_helper.dart'; -import '../helper_core.dart'; import '../shared_checkers.dart'; import '../type_helper.dart'; +import '../utils.dart'; class ValueHelper extends TypeHelper { const ValueHelper(); diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index df12ffccc..7d4a79b1e 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -169,3 +169,26 @@ String encodedFieldName( return declaredName.pascal; } } + +/// Return the Dart code presentation for the given [type]. +/// +/// This function is intentionally limited, and does not support all possible +/// types and locations of these files in code. Specifically, it supports +/// only [InterfaceType]s, with optional type arguments that are also should +/// be [InterfaceType]s. +String typeToCode( + DartType type, { + bool forceNullable = false, +}) { + if (type.isDynamic) { + return 'dynamic'; + } else if (type is InterfaceType) { + return [ + type.element.name, + if (type.typeArguments.isNotEmpty) + '<${type.typeArguments.map(typeToCode).join(', ')}>', + (type.isNullableType || forceNullable) ? '?' : '', + ].join(); + } + throw UnimplementedError('(${type.runtimeType}) $type'); +} From c90d488417054f000ef57d5323f9542774dc0365 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 4 Oct 2021 07:28:36 -0700 Subject: [PATCH 352/569] Bump actions/setup-node from 2.4.0 to 2.4.1 (#996) Bumps [actions/setup-node](https://github.com/actions/setup-node) from 2.4.0 to 2.4.1. - [Release notes](https://github.com/actions/setup-node/releases) - [Commits](https://github.com/actions/setup-node/compare/v2.4.0...v2.4.1) --- updated-dependencies: - dependency-name: actions/setup-node dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/markdown_linter.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/markdown_linter.yml b/.github/workflows/markdown_linter.yml index 50a277651..2526d4c7c 100644 --- a/.github/workflows/markdown_linter.yml +++ b/.github/workflows/markdown_linter.yml @@ -21,7 +21,7 @@ jobs: steps: - uses: actions/checkout@master - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v2.4.0 + uses: actions/setup-node@v2.4.1 with: node-version: ${{ matrix.node-version }} - name: Install dependencies From ab3a48830ef02fe99c3968eeefe90294204439ce Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Tue, 5 Oct 2021 19:32:47 -0700 Subject: [PATCH 353/569] impl: Fix caching of KeyConfig - take into account all data (#999) Fixes https://github.com/google/json_serializable.dart/issues/979 --- json_serializable/lib/src/json_key_utils.dart | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/json_serializable/lib/src/json_key_utils.dart b/json_serializable/lib/src/json_key_utils.dart index 932741901..b5310f939 100644 --- a/json_serializable/lib/src/json_key_utils.dart +++ b/json_serializable/lib/src/json_key_utils.dart @@ -14,10 +14,11 @@ import 'shared_checkers.dart'; import 'type_helpers/config_types.dart'; import 'utils.dart'; -final _jsonKeyExpando = Expando<KeyConfig>(); +final _jsonKeyExpando = Expando<Map<ClassConfig, KeyConfig>>(); KeyConfig jsonKeyForField(FieldElement field, ClassConfig classAnnotation) => - _jsonKeyExpando[field] ??= _from(field, classAnnotation); + (_jsonKeyExpando[field] ??= Map.identity())[classAnnotation] ??= + _from(field, classAnnotation); KeyConfig _from(FieldElement element, ClassConfig classAnnotation) { // If an annotation exists on `element` the source is a 'real' field. From 06f5f5f69221321c7621ccaef6ed8a34126a5f69 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Wed, 6 Oct 2021 14:09:46 -0700 Subject: [PATCH 354/569] TypeHelperCtx: tiny code reorg (#1000) --- json_serializable/lib/src/type_helper_ctx.dart | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/json_serializable/lib/src/type_helper_ctx.dart b/json_serializable/lib/src/type_helper_ctx.dart index 1d7f9d7a1..a601f7bc3 100644 --- a/json_serializable/lib/src/type_helper_ctx.dart +++ b/json_serializable/lib/src/type_helper_ctx.dart @@ -16,7 +16,9 @@ import 'unsupported_type_error.dart'; import 'utils.dart'; TypeHelperCtx typeHelperContext( - HelperCore helperCore, FieldElement fieldElement) => + HelperCore helperCore, + FieldElement fieldElement, +) => TypeHelperCtx._(helperCore, fieldElement); class TypeHelperCtx @@ -32,8 +34,6 @@ class TypeHelperCtx @override ClassConfig get config => _helperCore.config; - TypeHelperCtx._(this._helperCore, this.fieldElement); - @override ConvertData? get serializeConvertData => _pairFromContext.toJson; @@ -42,6 +42,8 @@ class TypeHelperCtx late final _pairFromContext = _ConvertPair(fieldElement); + TypeHelperCtx._(this._helperCore, this.fieldElement); + @override void addMember(String memberContent) { _helperCore.addMember(memberContent); From 4d7a7b0234935b1ae62882bb0167a93870ef74a0 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Wed, 6 Oct 2021 14:28:45 -0700 Subject: [PATCH 355/569] Use a generator to create README.md (#1001) Easier to keep things in sync! --- json_serializable/README.md | 24 +++-- json_serializable/build.yaml | 19 ++-- json_serializable/test/readme_test.dart | 63 ------------ ...oc_builder.dart => api_table_builder.dart} | 10 +- .../{doc/doc.md => tool/readme/api.md} | 0 .../tool/readme/readme_template.md | 96 +++++++++++++++++++ json_serializable/tool/readme_builder.dart | 87 +++++++++++++++++ json_serializable/tool/shared.dart | 2 + 8 files changed, 215 insertions(+), 86 deletions(-) delete mode 100644 json_serializable/test/readme_test.dart rename json_serializable/tool/{doc_builder.dart => api_table_builder.dart} (95%) rename json_serializable/{doc/doc.md => tool/readme/api.md} (100%) create mode 100644 json_serializable/tool/readme/readme_template.md create mode 100644 json_serializable/tool/readme_builder.dart diff --git a/json_serializable/README.md b/json_serializable/README.md index 193b66147..c13451e76 100644 --- a/json_serializable/README.md +++ b/json_serializable/README.md @@ -1,3 +1,4 @@ +<!-- This content is generated. See tool/readme/readme_template.md --> [![Pub Package](https://img.shields.io/pub/v/json_serializable.svg)](https://pub.dev/packages/json_serializable) Provides [Dart Build System] builders for handling JSON. @@ -62,9 +63,8 @@ Map<String, dynamic> _$PersonToJson(Person instance) => <String, dynamic>{ # Running the code generator -Once you have added the annotations to your code you then need to run the -code generator to generate the missing `.g.dart` generated dart files. - +Once you have added the annotations to your code you then need to run the code +generator to generate the missing `.g.dart` generated dart files. With a Dart package, run `pub run build_runner build` in the package directory. @@ -125,21 +125,19 @@ is generated: [JsonKey.toJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/toJson.html [JsonKey.unknownEnumValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/unknownEnumValue.html - -> Note: every `JsonSerializable` field is configurable via `build.yaml` – -> see the table for the corresponding key. -> If you find you want all or most of your classes with the same configuration, -> it may be easier to specify values once in the YAML file. Values set -> explicitly on `@JsonSerializable` take precedence over settings in -> `build.yaml`. +> Note: every `JsonSerializable` field is configurable via `build.yaml` – see +> the table for the corresponding key. If you find you want all or most of your +> classes with the same configuration, it may be easier to specify values once +> in the YAML file. Values set explicitly on `@JsonSerializable` take precedence +> over settings in `build.yaml`. > Note: There is some overlap between fields on `JsonKey` and > `JsonSerializable`. In these cases, if a value is set explicitly via `JsonKey` -> it will take precedence over any value set on `JsonSerializable`. +> it will take precedence over any value set on `JsonSerializable`. # Build configuration -Besides setting arguments on the associated annotation classes, you can also +Aside from setting arguments on the associated annotation classes, you can also configure code generation by setting values in `build.yaml`. ```yaml @@ -154,7 +152,7 @@ targets: # The default value for each is listed. any_map: false checked: false - constructor: '' + constructor: "" create_factory: true create_to_json: true disallow_unrecognized_keys: false diff --git a/json_serializable/build.yaml b/json_serializable/build.yaml index 990cbdb1c..da4d555ec 100644 --- a/json_serializable/build.yaml +++ b/json_serializable/build.yaml @@ -92,14 +92,21 @@ builders: build_to: source runs_before: ["json_serializable"] - _doc_builder: - import: "tool/doc_builder.dart" - builder_factories: ["docBuilder"] - build_extensions: {"lib/json_serializable.dart": ["doc/doc.md"]} + _api_table_builder: + import: "tool/api_table_builder.dart" + builder_factories: ["apiTableBuilder"] + build_extensions: {"lib/json_serializable.dart": ["tool/readme/api.md"]} build_to: source auto_apply: root_package - runs_before: ["json_serializable"] - required_inputs: ["doc/json_annotation_version.txt"] + runs_before: ["_readme_builder"] + + _readme_builder: + import: "tool/readme_builder.dart" + builder_factories: ["readmeBuilder"] + build_extensions: {"tool/readme/api.md": ["README.md"]} + build_to: source + auto_apply: root_package + required_inputs: ['.dart'] json_serializable: import: "package:json_serializable/builder.dart" diff --git a/json_serializable/test/readme_test.dart b/json_serializable/test/readme_test.dart deleted file mode 100644 index 24c1be8b9..000000000 --- a/json_serializable/test/readme_test.dart +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright (c) 2018, 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. - -@TestOn('vm') -import 'dart:io'; - -import 'package:path/path.dart' as p; -import 'package:test/test.dart'; - -void main() { - late String readmeContent; - - setUpAll(() { - readmeContent = File('README.md').readAsStringSync(); - }); - - test('example.dart', () { - final exampleContent = _getExampleContent('example.dart'); - expect(readmeContent, contains(exampleContent)); - }); - - test('example.g.dart', () { - final exampleGeneratedContent = _getExampleContent('example.g.dart'); - expect(readmeContent, contains(exampleGeneratedContent)); - }); - - test('doc/doc.md', () { - final docContent = File(p.join('doc', 'doc.md')).readAsStringSync(); - expect(readmeContent, contains(docContent)); - }); -} - -String _getExampleContent(String fileName) { - final lines = File(p.join('example', fileName)).readAsLinesSync(); - - var lastHadContent = false; - - // All lines with content, except those starting with `/`. - // Also exclude blank lines that follow other blank lines - final cleanedSource = lines.where((l) { - if (l.startsWith(r'/')) { - return false; - } - - if (l.trim().isNotEmpty) { - lastHadContent = true; - return true; - } - - if (lastHadContent) { - lastHadContent = false; - return true; - } - - return false; - }).join('\n'); - - return ''' -```dart -$cleanedSource -```'''; -} diff --git a/json_serializable/tool/doc_builder.dart b/json_serializable/tool/api_table_builder.dart similarity index 95% rename from json_serializable/tool/doc_builder.dart rename to json_serializable/tool/api_table_builder.dart index 69241ae0b..bef52a719 100644 --- a/json_serializable/tool/doc_builder.dart +++ b/json_serializable/tool/api_table_builder.dart @@ -10,12 +10,14 @@ import 'package:source_gen/source_gen.dart'; import 'package:source_helper/source_helper.dart'; import 'package:yaml/yaml.dart'; -Builder docBuilder([_]) => _DocBuilder(); +import 'shared.dart'; + +Builder apiTableBuilder([_]) => _ApiTableBuilder(); const _jsonKey = 'JsonKey'; const _jsonSerializable = 'JsonSerializable'; -class _DocBuilder extends Builder { +class _ApiTableBuilder extends Builder { @override FutureOr<void> build(BuildStep buildStep) async { final lockFileAssetId = AssetId(buildStep.inputId.package, 'pubspec.lock'); @@ -102,12 +104,12 @@ class _DocBuilder extends Builder { } await buildStep.writeAsString( - AssetId(buildStep.inputId.package, 'doc/doc.md'), buffer.toString()); + AssetId(buildStep.inputId.package, readmeApiPath), buffer.toString()); } @override final buildExtensions = const { - r'lib/json_serializable.dart': ['doc/doc.md'] + r'lib/json_serializable.dart': [readmeApiPath] }; } diff --git a/json_serializable/doc/doc.md b/json_serializable/tool/readme/api.md similarity index 100% rename from json_serializable/doc/doc.md rename to json_serializable/tool/readme/api.md diff --git a/json_serializable/tool/readme/readme_template.md b/json_serializable/tool/readme/readme_template.md new file mode 100644 index 000000000..0ac4dbf3d --- /dev/null +++ b/json_serializable/tool/readme/readme_template.md @@ -0,0 +1,96 @@ +[![Pub Package](https://img.shields.io/pub/v/json_serializable.svg)](https://pub.dev/packages/json_serializable) + +Provides [Dart Build System] builders for handling JSON. + +The builders generate code when they find members annotated with classes defined +in [package:json_annotation]. + +- To generate to/from JSON code for a class, annotate it with + `@JsonSerializable`. You can provide arguments to `JsonSerializable` to + configure the generated code. You can also customize individual fields by + annotating them with `@JsonKey` and providing custom arguments. See the table + below for details on the [annotation values](#annotation-values). + +- To generate a Dart field with the contents of a file containing JSON, use the + `JsonLiteral` annotation. + +## Setup + +To configure your project for the latest released version of, +`json_serializable` see the [example]. + +## Example + +Given a library `example.dart` with an `Person` class annotated with +`@JsonSerializable()`: + +<!-- REPLACE example.dart --> + +Building creates the corresponding part `example.g.dart`: + +<!-- REPLACE example.g.dart --> + +# Running the code generator + +Once you have added the annotations to your code you then need to run the code +generator to generate the missing `.g.dart` generated dart files. + +With a Dart package, run `pub run build_runner build` in the package directory. + +With a Flutter package, run `flutter pub run build_runner build` in your package +directory. + +# Annotation values + +The only annotation required to use this package is `@JsonSerializable`. When +applied to a class (in a correctly configured package), `toJson` and `fromJson` +code will be generated when you build. There are three ways to control how code +is generated: + +1. Set properties on `@JsonSerializable`. +2. Add a `@JsonKey` annotation to a field and set properties there. +3. Add configuration to `build.yaml` – [see below](#build-configuration). + +<!-- REPLACE api.md --> + +> Note: every `JsonSerializable` field is configurable via `build.yaml` – see +> the table for the corresponding key. If you find you want all or most of your +> classes with the same configuration, it may be easier to specify values once +> in the YAML file. Values set explicitly on `@JsonSerializable` take precedence +> over settings in `build.yaml`. + +> Note: There is some overlap between fields on `JsonKey` and +> `JsonSerializable`. In these cases, if a value is set explicitly via `JsonKey` +> it will take precedence over any value set on `JsonSerializable`. + +# Build configuration + +Aside from setting arguments on the associated annotation classes, you can also +configure code generation by setting values in `build.yaml`. + +```yaml +targets: + $default: + builders: + json_serializable: + options: + # Options configure how source code is generated for every + # `@JsonSerializable`-annotated class in the package. + # + # The default value for each is listed. + any_map: false + checked: false + constructor: "" + create_factory: true + create_to_json: true + disallow_unrecognized_keys: false + explicit_to_json: false + field_rename: none + generic_argument_factories: false + ignore_unannotated: false + include_if_null: true +``` + +[example]: https://github.com/google/json_serializable.dart/tree/master/example +[dart build system]: https://github.com/dart-lang/build +[package:json_annotation]: https://pub.dev/packages/json_annotation diff --git a/json_serializable/tool/readme_builder.dart b/json_serializable/tool/readme_builder.dart new file mode 100644 index 000000000..48ee391e5 --- /dev/null +++ b/json_serializable/tool/readme_builder.dart @@ -0,0 +1,87 @@ +// Copyright (c) 2019, 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 'dart:async'; +import 'dart:convert'; + +import 'package:build/build.dart'; +import 'package:path/path.dart' as p; + +import 'shared.dart'; + +Builder readmeBuilder([_]) => _ReadmeBuilder(); + +class _ReadmeBuilder extends Builder { + @override + FutureOr<void> build(BuildStep buildStep) async { + final templateAssetId = + AssetId(buildStep.inputId.package, 'tool/readme/readme_template.md'); + final templateAssetContent = await buildStep.readAsString(templateAssetId); + + Future<String> getExampleContent(String fileName) async { + final content = await buildStep.readAsString( + AssetId(buildStep.inputId.package, p.join('example', fileName)), + ); + + final lines = LineSplitter.split(content); + + var lastHadContent = false; + + // All lines with content, except those starting with `/`. + // Also exclude blank lines that follow other blank lines + final cleanedSource = lines.where((l) { + if (l.startsWith(r'/')) { + return false; + } + + if (l.trim().isNotEmpty) { + lastHadContent = true; + return true; + } + + if (lastHadContent) { + lastHadContent = false; + return true; + } + + return false; + }).join('\n'); + + return ''' +```dart +$cleanedSource +```'''; + } + + final replacements = { + 'api.md': await buildStep + .readAsString(AssetId(buildStep.inputId.package, readmeApiPath)), + 'example.dart': await getExampleContent('example.dart'), + 'example.g.dart': await getExampleContent('example.g.dart'), + }; + + final expandedContent = + templateAssetContent.replaceAllMapped(_replaceRegexp, (match) { + final replacementKey = match.group(1)!; + return replacements[replacementKey]!.trim(); + }).trim(); + + await buildStep.writeAsString( + AssetId(buildStep.inputId.package, _readmePath), + ''' +<!-- This content is generated. See $_templatePath --> +$expandedContent +''', + ); + } + + @override + final buildExtensions = const { + readmeApiPath: [_readmePath] + }; +} + +const _templatePath = 'tool/readme/readme_template.md'; +const _readmePath = 'README.md'; + +final _replaceRegexp = RegExp(r'<!-- REPLACE ([\w\d\.]+) -->'); diff --git a/json_serializable/tool/shared.dart b/json_serializable/tool/shared.dart index f1e0b9914..ba3e5ee99 100644 --- a/json_serializable/tool/shared.dart +++ b/json_serializable/tool/shared.dart @@ -7,6 +7,8 @@ import 'dart:io'; import 'package:build/build.dart'; import 'package:yaml/yaml.dart'; +const readmeApiPath = 'tool/readme/api.md'; + // Until we have verification in pkg:build and friends // https://github.com/dart-lang/build/issues/590 Builder validate(String builderName, Builder builder) { From 4db27a8d0e3b48fd4a9a872f008adde77eb9ae30 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Thu, 7 Oct 2021 11:14:09 -0700 Subject: [PATCH 356/569] Big documentation updates/improvements (#1003) --- json_serializable/README.md | 180 +++++++++----- json_serializable/build.yaml | 10 +- json_serializable/example/example.dart | 13 +- json_serializable/tool/api_table_builder.dart | 198 ---------------- json_serializable/tool/readme/api.md | 42 ---- .../tool/readme/readme_template.md | 93 ++++++-- json_serializable/tool/readme_builder.dart | 222 ++++++++++++++---- json_serializable/tool/shared.dart | 2 - json_serializable/tool/test_type_builder.dart | 21 +- 9 files changed, 386 insertions(+), 395 deletions(-) delete mode 100644 json_serializable/tool/api_table_builder.dart delete mode 100644 json_serializable/tool/readme/api.md diff --git a/json_serializable/README.md b/json_serializable/README.md index c13451e76..7b3e53906 100644 --- a/json_serializable/README.md +++ b/json_serializable/README.md @@ -7,13 +7,13 @@ The builders generate code when they find members annotated with classes defined in [package:json_annotation]. - To generate to/from JSON code for a class, annotate it with - `@JsonSerializable`. You can provide arguments to `JsonSerializable` to + [`JsonSerializable`]. You can provide arguments to [`JsonSerializable`] to configure the generated code. You can also customize individual fields by - annotating them with `@JsonKey` and providing custom arguments. See the table - below for details on the [annotation values](#annotation-values). + annotating them with [`JsonKey`] and providing custom arguments. See the + table below for details on the [annotation values](#annotation-values). - To generate a Dart field with the contents of a file containing JSON, use the - `JsonLiteral` annotation. + [`JsonLiteral`] annotation. ## Setup @@ -23,7 +23,7 @@ To configure your project for the latest released version of, ## Example Given a library `example.dart` with an `Person` class annotated with -`@JsonSerializable()`: +[`JsonSerializable`]: ```dart import 'package:json_annotation/json_annotation.dart'; @@ -32,11 +32,20 @@ part 'example.g.dart'; @JsonSerializable() class Person { - final String firstName; - final String lastName; + /// The generated code assumes these values exist in JSON. + final String firstName, lastName; + + /// The generated code below handles if the corresponding JSON value doesn't + /// exist or is empty. final DateTime? dateOfBirth; + Person({required this.firstName, required this.lastName, this.dateOfBirth}); + + /// Connect the generated [_$PersonFromJson] function to the `fromJson` + /// factory. factory Person.fromJson(Map<String, dynamic> json) => _$PersonFromJson(json); + + /// Connect the generated [_$PersonToJson] function to the `toJson` method. Map<String, dynamic> toJson() => _$PersonToJson(this); } ``` @@ -66,74 +75,91 @@ Map<String, dynamic> _$PersonToJson(Person instance) => <String, dynamic>{ Once you have added the annotations to your code you then need to run the code generator to generate the missing `.g.dart` generated dart files. -With a Dart package, run `pub run build_runner build` in the package directory. +With a Dart package, run `dart run build_runner build` in the package directory. With a Flutter package, run `flutter pub run build_runner build` in your package directory. # Annotation values -The only annotation required to use this package is `@JsonSerializable`. When +The only annotation required to use this package is [`JsonSerializable`]. When applied to a class (in a correctly configured package), `toJson` and `fromJson` code will be generated when you build. There are three ways to control how code is generated: -1. Set properties on `@JsonSerializable`. -2. Add a `@JsonKey` annotation to a field and set properties there. -3. Add configuration to `build.yaml` – [see below](#build-configuration). - -| `build.yaml` key | JsonSerializable | JsonKey | -| -------------------------- | ------------------------------------------- | --------------------------- | -| any_map | [JsonSerializable.anyMap] | | -| checked | [JsonSerializable.checked] | | -| constructor | [JsonSerializable.constructor] | | -| create_factory | [JsonSerializable.createFactory] | | -| create_to_json | [JsonSerializable.createToJson] | | -| disallow_unrecognized_keys | [JsonSerializable.disallowUnrecognizedKeys] | | -| explicit_to_json | [JsonSerializable.explicitToJson] | | -| field_rename | [JsonSerializable.fieldRename] | | -| generic_argument_factories | [JsonSerializable.genericArgumentFactories] | | -| ignore_unannotated | [JsonSerializable.ignoreUnannotated] | | -| include_if_null | [JsonSerializable.includeIfNull] | [JsonKey.includeIfNull] | -| | | [JsonKey.defaultValue] | -| | | [JsonKey.disallowNullValue] | -| | | [JsonKey.fromJson] | -| | | [JsonKey.ignore] | -| | | [JsonKey.name] | -| | | [JsonKey.required] | -| | | [JsonKey.toJson] | -| | | [JsonKey.unknownEnumValue] | - -[JsonSerializable.anyMap]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/anyMap.html -[JsonSerializable.checked]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/checked.html -[JsonSerializable.constructor]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/constructor.html -[JsonSerializable.createFactory]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/createFactory.html -[JsonSerializable.createToJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/createToJson.html -[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html -[JsonSerializable.explicitToJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/explicitToJson.html -[JsonSerializable.fieldRename]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/fieldRename.html -[JsonSerializable.genericArgumentFactories]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/genericArgumentFactories.html -[JsonSerializable.ignoreUnannotated]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/ignoreUnannotated.html -[JsonSerializable.includeIfNull]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/includeIfNull.html -[JsonKey.includeIfNull]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/includeIfNull.html -[JsonKey.defaultValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/defaultValue.html -[JsonKey.disallowNullValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/disallowNullValue.html -[JsonKey.fromJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/fromJson.html -[JsonKey.ignore]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/ignore.html -[JsonKey.name]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/name.html -[JsonKey.required]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/required.html -[JsonKey.toJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/toJson.html -[JsonKey.unknownEnumValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/unknownEnumValue.html - -> Note: every `JsonSerializable` field is configurable via `build.yaml` – see -> the table for the corresponding key. If you find you want all or most of your -> classes with the same configuration, it may be easier to specify values once -> in the YAML file. Values set explicitly on `@JsonSerializable` take precedence -> over settings in `build.yaml`. - -> Note: There is some overlap between fields on `JsonKey` and -> `JsonSerializable`. In these cases, if a value is set explicitly via `JsonKey` -> it will take precedence over any value set on `JsonSerializable`. +1. Setting properties on [`JsonKey`] annotating the target field. +1. Set properties on [`JsonSerializable`] annotating the target type. +1. Add configuration to `build.yaml` – [see below](#build-configuration). + +Every [`JsonSerializable`] field is configurable via `build.yaml`. If you find +you want all or most of your classes with the same configuration, it may be +easier to specify values once in the YAML file. Values set explicitly on +[`JsonSerializable`] take precedence over settings in `build.yaml`. + +There is some overlap between settings on [`JsonKey`] and +[`JsonSerializable`]. In these cases, the property on [`JsonKey`] takes +precedence over any value set on [`JsonSerializable`]. + +<!-- TODO: add an example! --> + +## Enums + +Annotate `enum` types with [`JsonEnum`] (new in `json_annotation` 4.2.0) to: + +1. Specify the default rename logic for each enum value using `fieldRename`. For + instance, use `fieldRename: FieldRename.kebab` to encode `enum` value + `noGood` as `"no-good"`. +1. Force the generation of the `enum` helpers, even if the `enum` is not + referenced in code. This is an edge scenario, but useful for some. + +Annotate `enum` values with [`JsonValue`] to specify the encoded value to map +to target `enum` entries. Values can be of type [`String`] or [`int`]. + +<!-- TODO: hoist out to source code! --> + +```dart +enum StatusCode { + @JsonValue(200) + success, + @JsonValue('500') + weird, +} +``` + +# Supported types + +Out of the box, `json_serializable` supports many common types in the +[dart:core](https://api.dart.dev/stable/dart-core/dart-core-library.html) +library: +[`BigInt`], [`bool`], [`DateTime`], [`double`], [`Duration`], [`Enum`], [`int`], +[`Iterable`], [`List`], [`Map`], [`num`], [`Object`], [`Set`], [`String`], +[`Uri`] + +The collection types – +[`Iterable`], [`List`], [`Map`], [`Set`] +– can contain values of all the above types. + +For [`Map`], the key value must be one of +[`BigInt`], [`DateTime`], [`dynamic`], [`Enum`], [`int`], [`Object`], +[`String`], [`Uri`] + +# Custom types and custom encoding + +If you want to use types that are not supported out-of-the-box or if you want to +customize the encoding/decoding of any type, you have a few options. + +1. If you own/cotrol the desired type, add a `fromJson` constructor and/or a + `toJson()` function to the type. Note: while you can use `json_serializable` + for these types, you don't have to! The generator code only looks for these + methods. It doesn't care how they were created. +1. Use the [`JsonKey.toJson`] and [`JsonKey.fromJson`] properties to specify + custom conversions on the annotated field. The functions specified must be + top-level or static. See the documentation of these properties for details. +1. Create an implementation of [`JsonConverter`] and annotate either the + corresponding field or the containing class. [`JsonConverter`] is convenient + if you want to use the same conversion logic on many fields. It also allows + you to support a type within collections. Check out + [these examples](https://github.com/google/json_serializable.dart/blob/master/example/lib/json_converter_example.dart). # Build configuration @@ -166,3 +192,27 @@ targets: [example]: https://github.com/google/json_serializable.dart/tree/master/example [dart build system]: https://github.com/dart-lang/build [package:json_annotation]: https://pub.dev/packages/json_annotation +[`BigInt`]: https://api.dart.dev/stable/dart-core/BigInt-class.html +[`bool`]: https://api.dart.dev/stable/dart-core/bool-class.html +[`DateTime`]: https://api.dart.dev/stable/dart-core/DateTime-class.html +[`double`]: https://api.dart.dev/stable/dart-core/double-class.html +[`Duration`]: https://api.dart.dev/stable/dart-core/Duration-class.html +[`dynamic`]: https://api.dart.dev/stable/dart-core/dynamic-class.html +[`Enum`]: https://api.dart.dev/stable/dart-core/Enum-class.html +[`int`]: https://api.dart.dev/stable/dart-core/int-class.html +[`Iterable`]: https://api.dart.dev/stable/dart-core/Iterable-class.html +[`JsonConverter`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonConverter-class.html +[`JsonEnum`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonEnum-class.html +[`JsonKey.fromJson`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/fromJson.html +[`JsonKey.toJson`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/toJson.html +[`JsonKey`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey-class.html +[`JsonLiteral`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonLiteral-class.html +[`JsonSerializable`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable-class.html +[`JsonValue`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonValue-class.html +[`List`]: https://api.dart.dev/stable/dart-core/List-class.html +[`Map`]: https://api.dart.dev/stable/dart-core/Map-class.html +[`num`]: https://api.dart.dev/stable/dart-core/num-class.html +[`Object`]: https://api.dart.dev/stable/dart-core/Object-class.html +[`Set`]: https://api.dart.dev/stable/dart-core/Set-class.html +[`String`]: https://api.dart.dev/stable/dart-core/String-class.html +[`Uri`]: https://api.dart.dev/stable/dart-core/Uri-class.html diff --git a/json_serializable/build.yaml b/json_serializable/build.yaml index da4d555ec..bc69e96d9 100644 --- a/json_serializable/build.yaml +++ b/json_serializable/build.yaml @@ -92,18 +92,10 @@ builders: build_to: source runs_before: ["json_serializable"] - _api_table_builder: - import: "tool/api_table_builder.dart" - builder_factories: ["apiTableBuilder"] - build_extensions: {"lib/json_serializable.dart": ["tool/readme/api.md"]} - build_to: source - auto_apply: root_package - runs_before: ["_readme_builder"] - _readme_builder: import: "tool/readme_builder.dart" builder_factories: ["readmeBuilder"] - build_extensions: {"tool/readme/api.md": ["README.md"]} + build_extensions: {"tool/readme/readme_template.md": ["README.md"]} build_to: source auto_apply: root_package required_inputs: ['.dart'] diff --git a/json_serializable/example/example.dart b/json_serializable/example/example.dart index 28d252925..39cc11597 100644 --- a/json_serializable/example/example.dart +++ b/json_serializable/example/example.dart @@ -8,10 +8,19 @@ part 'example.g.dart'; @JsonSerializable() class Person { - final String firstName; - final String lastName; + /// The generated code assumes these values exist in JSON. + final String firstName, lastName; + + /// The generated code below handles if the corresponding JSON value doesn't + /// exist or is empty. final DateTime? dateOfBirth; + Person({required this.firstName, required this.lastName, this.dateOfBirth}); + + /// Connect the generated [_$PersonFromJson] function to the `fromJson` + /// factory. factory Person.fromJson(Map<String, dynamic> json) => _$PersonFromJson(json); + + /// Connect the generated [_$PersonToJson] function to the `toJson` method. Map<String, dynamic> toJson() => _$PersonToJson(this); } diff --git a/json_serializable/tool/api_table_builder.dart b/json_serializable/tool/api_table_builder.dart deleted file mode 100644 index bef52a719..000000000 --- a/json_serializable/tool/api_table_builder.dart +++ /dev/null @@ -1,198 +0,0 @@ -// Copyright (c) 2019, 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 'dart:async'; - -import 'package:analyzer/dart/element/element.dart'; -import 'package:build/build.dart'; -import 'package:pub_semver/pub_semver.dart'; -import 'package:source_gen/source_gen.dart'; -import 'package:source_helper/source_helper.dart'; -import 'package:yaml/yaml.dart'; - -import 'shared.dart'; - -Builder apiTableBuilder([_]) => _ApiTableBuilder(); - -const _jsonKey = 'JsonKey'; -const _jsonSerializable = 'JsonSerializable'; - -class _ApiTableBuilder extends Builder { - @override - FutureOr<void> build(BuildStep buildStep) async { - final lockFileAssetId = AssetId(buildStep.inputId.package, 'pubspec.lock'); - final lockFileContent = await buildStep.readAsString(lockFileAssetId); - final lockFileYaml = - loadYaml(lockFileContent, sourceUrl: lockFileAssetId.uri) as YamlMap; - final pkgMap = lockFileYaml['packages'] as YamlMap; - final jsonAnnotationMap = pkgMap['json_annotation'] as YamlMap; - final jsonAnnotationVersionString = jsonAnnotationMap['version'] as String; - - final jsonAnnotationVersion = - Version.parse(jsonAnnotationVersionString.trim()); - - final targetVersion = jsonAnnotationVersion.isPreRelease - ? 'latest' - : jsonAnnotationVersion.toString(); - - final lib = LibraryReader( - await buildStep.resolver.libraryFor( - AssetId.resolve( - Uri.parse('package:json_annotation/json_annotation.dart'), - ), - ), - ); - - final descriptionMap = <String, _FieldInfo>{}; - - for (var className in _annotationClasses) { - for (var fe in lib - .findType(className)! - .fields - .where((fe) => !fe.isStatic && !fe.hasDeprecated)) { - descriptionMap[fe.name] = - _FieldInfo.update(fe, descriptionMap[fe.name]); - } - } - - final buffer = StringBuffer(); - - final sortedValues = descriptionMap.values.toList()..sort(); - - final rows = <List<String>>[ - ['`build.yaml` key', _jsonSerializable, _jsonKey], - ['-', '-', '-'], - for (var info in sortedValues) - [ - info.buildKey, - info.classAnnotationName, - info.fieldAnnotationName, - ], - ]; - - final longest = List<int>.generate(rows.first.length, (_) => 0); - for (var row in rows) { - for (var column = 0; column < longest.length; column++) { - if (row[column].length > longest[column]) { - longest[column] = row[column].length; - } - } - } - - for (var row in rows) { - for (var column = 0; column < longest.length; column++) { - var content = row[column]; - if (content == '-') { - content *= longest[column]; - } else { - content = content.padRight(longest[column]); - } - buffer.write('| $content '); - } - buffer.writeln('|'); - } - - buffer.writeln(); - - for (var info in sortedValues) { - if (info._classField != null) { - buffer.writeln(_link(targetVersion, _jsonSerializable, info.name)); - } - if (info._keyField != null) { - buffer.writeln(_link(targetVersion, _jsonKey, info.name)); - } - } - - await buildStep.writeAsString( - AssetId(buildStep.inputId.package, readmeApiPath), buffer.toString()); - } - - @override - final buildExtensions = const { - r'lib/json_serializable.dart': [readmeApiPath] - }; -} - -const _annotationClasses = [_jsonSerializable, _jsonKey]; - -String _anchorUriForName(String owner, String name) => '[$owner.$name]'; - -String _link(String version, String owner, String name) => - '${_anchorUriForName(owner, name)}: ' - 'https://pub.dev/documentation/json_annotation/$version/' - 'json_annotation/$owner/$name.html'; - -class _FieldInfo implements Comparable<_FieldInfo> { - final FieldElement? _keyField, _classField; - - String get name => _keyField?.name ?? _classField!.name; - - String get classAnnotationName { - if (_classField == null) { - return ''; - } - return _anchorUriForName(_jsonSerializable, name); - } - - String get fieldAnnotationName { - if (_keyField == null) { - return ''; - } - return _anchorUriForName(_jsonKey, name); - } - - String get buildKey { - if (_classField == null) { - return ''; - } - - return _classField!.name.snake; - } - - _FieldInfo(this._keyField, this._classField); - - static _FieldInfo update(FieldElement field, _FieldInfo? existing) { - final parent = field.enclosingElement.name; - - FieldElement? keyField, classField; - switch (parent) { - case _jsonSerializable: - classField = field; - keyField = existing?._keyField; - break; - case _jsonKey: - keyField = field; - classField = existing?._classField; - break; - default: - throw FallThroughError(); - } - - return _FieldInfo(keyField, classField); - } - - @override - int compareTo(_FieldInfo other) { - var value = _sortValue.compareTo(other._sortValue); - - if (value == 0) { - value = name.compareTo(other.name); - } - return value; - } - - int get _sortValue { - if (_classField == null) { - return 0; - } - - if (_keyField == null) { - return -2; - } - - return -1; - } - - @override - String toString() => '_FieldThing($_keyField)'; -} diff --git a/json_serializable/tool/readme/api.md b/json_serializable/tool/readme/api.md deleted file mode 100644 index c64b22723..000000000 --- a/json_serializable/tool/readme/api.md +++ /dev/null @@ -1,42 +0,0 @@ -| `build.yaml` key | JsonSerializable | JsonKey | -| -------------------------- | ------------------------------------------- | --------------------------- | -| any_map | [JsonSerializable.anyMap] | | -| checked | [JsonSerializable.checked] | | -| constructor | [JsonSerializable.constructor] | | -| create_factory | [JsonSerializable.createFactory] | | -| create_to_json | [JsonSerializable.createToJson] | | -| disallow_unrecognized_keys | [JsonSerializable.disallowUnrecognizedKeys] | | -| explicit_to_json | [JsonSerializable.explicitToJson] | | -| field_rename | [JsonSerializable.fieldRename] | | -| generic_argument_factories | [JsonSerializable.genericArgumentFactories] | | -| ignore_unannotated | [JsonSerializable.ignoreUnannotated] | | -| include_if_null | [JsonSerializable.includeIfNull] | [JsonKey.includeIfNull] | -| | | [JsonKey.defaultValue] | -| | | [JsonKey.disallowNullValue] | -| | | [JsonKey.fromJson] | -| | | [JsonKey.ignore] | -| | | [JsonKey.name] | -| | | [JsonKey.required] | -| | | [JsonKey.toJson] | -| | | [JsonKey.unknownEnumValue] | - -[JsonSerializable.anyMap]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/anyMap.html -[JsonSerializable.checked]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/checked.html -[JsonSerializable.constructor]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/constructor.html -[JsonSerializable.createFactory]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/createFactory.html -[JsonSerializable.createToJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/createToJson.html -[JsonSerializable.disallowUnrecognizedKeys]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/disallowUnrecognizedKeys.html -[JsonSerializable.explicitToJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/explicitToJson.html -[JsonSerializable.fieldRename]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/fieldRename.html -[JsonSerializable.genericArgumentFactories]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/genericArgumentFactories.html -[JsonSerializable.ignoreUnannotated]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/ignoreUnannotated.html -[JsonSerializable.includeIfNull]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/includeIfNull.html -[JsonKey.includeIfNull]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/includeIfNull.html -[JsonKey.defaultValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/defaultValue.html -[JsonKey.disallowNullValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/disallowNullValue.html -[JsonKey.fromJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/fromJson.html -[JsonKey.ignore]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/ignore.html -[JsonKey.name]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/name.html -[JsonKey.required]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/required.html -[JsonKey.toJson]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/toJson.html -[JsonKey.unknownEnumValue]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/unknownEnumValue.html diff --git a/json_serializable/tool/readme/readme_template.md b/json_serializable/tool/readme/readme_template.md index 0ac4dbf3d..fa8c3956a 100644 --- a/json_serializable/tool/readme/readme_template.md +++ b/json_serializable/tool/readme/readme_template.md @@ -6,13 +6,13 @@ The builders generate code when they find members annotated with classes defined in [package:json_annotation]. - To generate to/from JSON code for a class, annotate it with - `@JsonSerializable`. You can provide arguments to `JsonSerializable` to + `ja:JsonSerializable`. You can provide arguments to `ja:JsonSerializable` to configure the generated code. You can also customize individual fields by - annotating them with `@JsonKey` and providing custom arguments. See the table - below for details on the [annotation values](#annotation-values). + annotating them with `ja:JsonKey` and providing custom arguments. See the + table below for details on the [annotation values](#annotation-values). - To generate a Dart field with the contents of a file containing JSON, use the - `JsonLiteral` annotation. + `ja:JsonLiteral` annotation. ## Setup @@ -22,7 +22,7 @@ To configure your project for the latest released version of, ## Example Given a library `example.dart` with an `Person` class annotated with -`@JsonSerializable()`: +`ja:JsonSerializable`: <!-- REPLACE example.dart --> @@ -35,33 +35,88 @@ Building creates the corresponding part `example.g.dart`: Once you have added the annotations to your code you then need to run the code generator to generate the missing `.g.dart` generated dart files. -With a Dart package, run `pub run build_runner build` in the package directory. +With a Dart package, run `dart run build_runner build` in the package directory. With a Flutter package, run `flutter pub run build_runner build` in your package directory. # Annotation values -The only annotation required to use this package is `@JsonSerializable`. When +The only annotation required to use this package is `ja:JsonSerializable`. When applied to a class (in a correctly configured package), `toJson` and `fromJson` code will be generated when you build. There are three ways to control how code is generated: -1. Set properties on `@JsonSerializable`. -2. Add a `@JsonKey` annotation to a field and set properties there. -3. Add configuration to `build.yaml` – [see below](#build-configuration). +1. Setting properties on `ja:JsonKey` annotating the target field. +1. Set properties on `ja:JsonSerializable` annotating the target type. +1. Add configuration to `build.yaml` – [see below](#build-configuration). -<!-- REPLACE api.md --> +Every `ja:JsonSerializable` field is configurable via `build.yaml`. If you find +you want all or most of your classes with the same configuration, it may be +easier to specify values once in the YAML file. Values set explicitly on +`ja:JsonSerializable` take precedence over settings in `build.yaml`. -> Note: every `JsonSerializable` field is configurable via `build.yaml` – see -> the table for the corresponding key. If you find you want all or most of your -> classes with the same configuration, it may be easier to specify values once -> in the YAML file. Values set explicitly on `@JsonSerializable` take precedence -> over settings in `build.yaml`. +There is some overlap between settings on `ja:JsonKey` and +`ja:JsonSerializable`. In these cases, the property on `ja:JsonKey` takes +precedence over any value set on `ja:JsonSerializable`. -> Note: There is some overlap between fields on `JsonKey` and -> `JsonSerializable`. In these cases, if a value is set explicitly via `JsonKey` -> it will take precedence over any value set on `JsonSerializable`. +<!-- TODO: add an example! --> + +## Enums + +Annotate `enum` types with `ja:JsonEnum` (new in `json_annotation` 4.2.0) to: + +1. Specify the default rename logic for each enum value using `fieldRename`. For + instance, use `fieldRename: FieldRename.kebab` to encode `enum` value + `noGood` as `"no-good"`. +1. Force the generation of the `enum` helpers, even if the `enum` is not + referenced in code. This is an edge scenario, but useful for some. + +Annotate `enum` values with `ja:JsonValue` to specify the encoded value to map +to target `enum` entries. Values can be of type `core:String` or `core:int`. + +<!-- TODO: hoist out to source code! --> + +```dart +enum StatusCode { + @JsonValue(200) + success, + @JsonValue('500') + weird, +} +``` + +# Supported types + +Out of the box, `json_serializable` supports many common types in the +[dart:core](https://api.dart.dev/stable/dart-core/dart-core-library.html) +library: +<!-- REPLACE supported_types --> + +The collection types – +<!-- REPLACE collection_types --> +– can contain values of all the above types. + +For `core:Map`, the key value must be one of +<!-- REPLACE map_key_types --> + +# Custom types and custom encoding + +If you want to use types that are not supported out-of-the-box or if you want to +customize the encoding/decoding of any type, you have a few options. + +1. If you own/cotrol the desired type, add a `fromJson` constructor and/or a + `toJson()` function to the type. Note: while you can use `json_serializable` + for these types, you don't have to! The generator code only looks for these + methods. It doesn't care how they were created. +1. Use the `ja:JsonKey.toJson` and `ja:JsonKey.fromJson` properties to specify + custom conversions on the annotated field. The functions specified must be + top-level or static. See the documentation of these properties for details. +1. Create an implementation of `ja:JsonConverter` and annotate either the + corresponding field or the containing class. `ja:JsonConverter` is convenient + if you want to use the same conversion logic on many fields. It also allows + you to support a type within collections. Check out + [these examples](https://github.com/google/json_serializable.dart/blob/master/example/lib/json_converter_example.dart). # Build configuration diff --git a/json_serializable/tool/readme_builder.dart b/json_serializable/tool/readme_builder.dart index 48ee391e5..2bad39344 100644 --- a/json_serializable/tool/readme_builder.dart +++ b/json_serializable/tool/readme_builder.dart @@ -2,12 +2,17 @@ // 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 'dart:async'; +import 'dart:collection'; import 'dart:convert'; import 'package:build/build.dart'; +import 'package:collection/collection.dart'; import 'package:path/path.dart' as p; +import 'package:pub_semver/pub_semver.dart'; +import 'package:yaml/yaml.dart'; -import 'shared.dart'; +import 'test_type_builder.dart'; +import 'test_type_data.dart'; Builder readmeBuilder([_]) => _ReadmeBuilder(); @@ -15,73 +20,190 @@ class _ReadmeBuilder extends Builder { @override FutureOr<void> build(BuildStep buildStep) async { final templateAssetId = - AssetId(buildStep.inputId.package, 'tool/readme/readme_template.md'); - final templateAssetContent = await buildStep.readAsString(templateAssetId); + buildStep.assetIdForInputPackage('tool/readme/readme_template.md'); - Future<String> getExampleContent(String fileName) async { - final content = await buildStep.readAsString( - AssetId(buildStep.inputId.package, p.join('example', fileName)), - ); - - final lines = LineSplitter.split(content); - - var lastHadContent = false; - - // All lines with content, except those starting with `/`. - // Also exclude blank lines that follow other blank lines - final cleanedSource = lines.where((l) { - if (l.startsWith(r'/')) { - return false; - } - - if (l.trim().isNotEmpty) { - lastHadContent = true; - return true; - } + final replacements = { + 'example.dart': await buildStep.getExampleContent('example.dart'), + 'example.g.dart': await buildStep.getExampleContent('example.g.dart'), + 'supported_types': _classCleanAndSort(supportedTypes()), + 'collection_types': _classCleanAndSort(collectionTypes()), + 'map_key_types': _classCleanAndSort(mapKeyTypes), + }; - if (lastHadContent) { - lastHadContent = false; - return true; + final availableKeys = replacements.keys.toSet(); + + final jsonAnnotationVersion = await buildStep.jsonAnnotationVersion(); + final jsonAnnotationBaseUri = + 'https://pub.dev/documentation/json_annotation/$jsonAnnotationVersion/json_annotation'; + + String jsonAnnotationUri(String className, [String? member]) => + member == null + ? '$jsonAnnotationBaseUri/$className-class.html' + : '$jsonAnnotationBaseUri/$className/$member.html'; + + final foundClasses = SplayTreeMap<String, String>(compareAsciiLowerCase); + + final theMap = <Pattern, String Function(Match)>{ + RegExp(r'<!-- REPLACE ([\w\d\.]+) -->'): (match) { + final replacementKey = match.group(1)!; + availableKeys.remove(replacementKey); + return (replacements[replacementKey] ?? '*MISSING! `$replacementKey`*') + .trim(); + }, + RegExp(r'`(\w+):(\w+)(\.\w+)?`'): (match) { + final context = match.group(1)!; + final className = match.group(2)!; + final memberName = match.group(3); + final linkContent = '[`$className${memberName ?? ''}`]'; + String linkValue; + switch (context) { + case 'core': + linkValue = _coreTypeUri(className); + break; + case 'ja': + linkValue = jsonAnnotationUri(className, memberName?.substring(1)); + break; + default: + linkValue = 'https://unknown.com/$context/$className'; } + foundClasses[linkContent] = linkValue; + return linkContent; + } + }; - return false; - }).join('\n'); + var content = (await buildStep.readAsString(templateAssetId)).trim(); - return ''' -```dart -$cleanedSource -```'''; + for (var entry in theMap.entries) { + content = content.replaceAllMapped(entry.key, entry.value); } - final replacements = { - 'api.md': await buildStep - .readAsString(AssetId(buildStep.inputId.package, readmeApiPath)), - 'example.dart': await getExampleContent('example.dart'), - 'example.g.dart': await getExampleContent('example.g.dart'), - }; + if (availableKeys.isNotEmpty) { + log.warning( + 'Some parsed replacements where not used: ${availableKeys.join(', ')}', + ); + } - final expandedContent = - templateAssetContent.replaceAllMapped(_replaceRegexp, (match) { - final replacementKey = match.group(1)!; - return replacements[replacementKey]!.trim(); - }).trim(); + content = ''' +<!-- This content is generated. See $_templatePath --> +$content +${foundClasses.entries.map((e) => '${e.key}: ${e.value}').join('\n')} +'''; await buildStep.writeAsString( - AssetId(buildStep.inputId.package, _readmePath), - ''' -<!-- This content is generated. See $_templatePath --> -$expandedContent -''', + buildStep.assetIdForInputPackage(_readmePath), + content, ); } @override final buildExtensions = const { - readmeApiPath: [_readmePath] + _templatePath: [_readmePath] }; } const _templatePath = 'tool/readme/readme_template.md'; const _readmePath = 'README.md'; -final _replaceRegexp = RegExp(r'<!-- REPLACE ([\w\d\.]+) -->'); +String _coreTypeUri(String type) => + 'https://api.dart.dev/stable/dart-core/$type-class.html'; + +String _classCleanAndSort(Iterable<String> classes) { + final initial = (classes.map((e) => e == customEnumType ? 'Enum' : e).toList() + ..sort(compareAsciiLowerCase)) + // Start by mapping to the output format – so we wrap correctly + .map((e) => '[`$e`]') + .join(', '); + + if (initial.length <= 80) { + return initial; + } + + final splits = initial.split(' '); + final lines = <String>[]; + String? currentLine; + for (var split in splits) { + if (currentLine == null) { + currentLine = split; + } else { + final option = '$currentLine $split'; + if (option.length > 80) { + lines.add(currentLine); + currentLine = split; + } else { + currentLine = option; + } + } + if (currentLine.length > 80) { + lines.add(currentLine); + currentLine = null; + } + } + + if (currentLine != null) { + lines.add(currentLine); + } + + return lines.join('\n').replaceAllMapped( + // Now put in the core: logic so we autolink correctly + RegExp(r'\[`(\w+)`\]'), + (match) => '`core:${match[1]}`', + ); +} + +extension on BuildStep { + AssetId assetIdForInputPackage(String path) => AssetId(inputId.package, path); + + Future<String> jsonAnnotationVersion() async { + final lockFileAssetId = assetIdForInputPackage('pubspec.lock'); + final lockFileContent = await readAsString(lockFileAssetId); + final lockFileYaml = + loadYaml(lockFileContent, sourceUrl: lockFileAssetId.uri) as YamlMap; + final pkgMap = lockFileYaml['packages'] as YamlMap; + final jsonAnnotationMap = pkgMap['json_annotation'] as YamlMap; + final jsonAnnotationVersionString = jsonAnnotationMap['version'] as String; + + final jsonAnnotationVersion = + Version.parse(jsonAnnotationVersionString.trim()); + + final targetVersion = jsonAnnotationVersion.isPreRelease + ? 'latest' + : jsonAnnotationVersion.toString(); + + return targetVersion; + } + + Future<String> getExampleContent(String fileName) async { + final content = await readAsString( + assetIdForInputPackage(p.join('example', fileName)), + ); + + final lines = LineSplitter.split(content); + + var lastHadContent = false; + + // All lines with content, except those starting with `/`. + // Also exclude blank lines that follow other blank lines + final cleanedSource = lines.where((l) { + if (l.startsWith(r'/')) { + return false; + } + + if (l.trim().isNotEmpty) { + lastHadContent = true; + return true; + } + + if (lastHadContent) { + lastHadContent = false; + return true; + } + + return false; + }).join('\n'); + + return ''' +```dart +$cleanedSource +```'''; + } +} diff --git a/json_serializable/tool/shared.dart b/json_serializable/tool/shared.dart index ba3e5ee99..f1e0b9914 100644 --- a/json_serializable/tool/shared.dart +++ b/json_serializable/tool/shared.dart @@ -7,8 +7,6 @@ import 'dart:io'; import 'package:build/build.dart'; import 'package:yaml/yaml.dart'; -const readmeApiPath = 'tool/readme/api.md'; - // Until we have verification in pkg:build and friends // https://github.com/dart-lang/build/issues/590 Builder validate(String builderName, Builder builder) { diff --git a/json_serializable/tool/test_type_builder.dart b/json_serializable/tool/test_type_builder.dart index 773e574fc..bfadc7091 100644 --- a/json_serializable/tool/test_type_builder.dart +++ b/json_serializable/tool/test_type_builder.dart @@ -61,16 +61,16 @@ const _trivialTypesToTest = { ), }; -final _typesToTest = { - ..._trivialTypesToTest, - // - // Collection types - // +Iterable<String> supportedTypes() => _typesToTest.keys; + +Iterable<String> collectionTypes() => _collectionTypes.keys; + +final _collectionTypes = { 'Map': TestTypeData( defaultExpression: "{'a': 1}", altJsonExpression: "{'b': 2}", genericArgs: _iterableGenericArgs - .expand((v) => _mapKeyTypes.map((k) => '$k,$v')) + .expand((v) => mapKeyTypes.map((k) => '$k,$v')) .toSet(), ), 'List': TestTypeData( @@ -91,11 +91,16 @@ final _typesToTest = { ), }; -const _mapKeyTypes = { +final _typesToTest = { + ..._trivialTypesToTest, + ..._collectionTypes, +}; + +const mapKeyTypes = { 'BigInt', 'DateTime', 'dynamic', - 'EnumType', + customEnumType, 'int', 'Object', 'String', From dabcecb042e3e5e0c5fc7770fe959062c004d809 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@google.com> Date: Fri, 8 Oct 2021 16:49:26 -0700 Subject: [PATCH 357/569] Better error output with incorrect annotations --- json_serializable/lib/src/json_key_utils.dart | 15 +++++++------ json_serializable/lib/src/utils.dart | 5 +++-- .../src/_json_serializable_test_input.dart | 2 +- .../test/src/default_value_input.dart | 10 ++++----- .../test/src/to_from_json_test_input.dart | 21 ++++++++++--------- .../src/unknown_enum_value_test_input.dart | 13 ++++++------ 6 files changed, 36 insertions(+), 30 deletions(-) diff --git a/json_serializable/lib/src/json_key_utils.dart b/json_serializable/lib/src/json_key_utils.dart index b5310f939..d3f0b9c4a 100644 --- a/json_serializable/lib/src/json_key_utils.dart +++ b/json_serializable/lib/src/json_key_utils.dart @@ -41,6 +41,7 @@ KeyConfig _from(FieldElement element, ClassConfig classAnnotation) { /// an [InvalidGenerationSourceError] using [typeInformation] to describe /// the unsupported type. Object? literalForObject( + String fieldName, DartObject dartObject, Iterable<String> typeInformation, ) { @@ -65,7 +66,9 @@ KeyConfig _from(FieldElement element, ClassConfig classAnnotation) { if (badType != null) { badType = typeInformation.followedBy([badType]).join(' > '); throwUnsupported( - element, '`defaultValue` is `$badType`, it must be a literal.'); + element, + '`$fieldName` is `$badType`, it must be a literal.', + ); } if (reader.isDouble || reader.isInt || reader.isString || reader.isBool) { @@ -75,7 +78,7 @@ KeyConfig _from(FieldElement element, ClassConfig classAnnotation) { if (reader.isList) { return [ for (var e in reader.listValue) - literalForObject(e, [ + literalForObject(fieldName, e, [ ...typeInformation, 'List', ]) @@ -85,7 +88,7 @@ KeyConfig _from(FieldElement element, ClassConfig classAnnotation) { if (reader.isSet) { return { for (var e in reader.setValue) - literalForObject(e, [ + literalForObject(fieldName, e, [ ...typeInformation, 'Set', ]) @@ -99,8 +102,8 @@ KeyConfig _from(FieldElement element, ClassConfig classAnnotation) { ]; return reader.mapValue.map( (k, v) => MapEntry( - literalForObject(k!, mapTypeInformation), - literalForObject(v!, mapTypeInformation), + literalForObject(fieldName, k!, mapTypeInformation), + literalForObject(fieldName, v!, mapTypeInformation), ), ); } @@ -163,7 +166,7 @@ KeyConfig _from(FieldElement element, ClassConfig classAnnotation) { } else { final defaultValueLiteral = annotationValue.isNull ? null - : literalForObject(annotationValue.objectValue, []); + : literalForObject(fieldName, annotationValue.objectValue, []); if (defaultValueLiteral == null) { return null; } diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index 7d4a79b1e..5614709ec 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -28,8 +28,9 @@ bool hasJsonKeyAnnotation(FieldElement element) => Never throwUnsupported(FieldElement element, String message) => throw InvalidGenerationSourceError( - 'Error with `@JsonKey` on `${element.name}`. $message', - element: element); + 'Error with `@JsonKey` on the `${element.name}` field. $message', + element: element, + ); FieldRename? _fromDartObject(ConstantReader reader) => reader.isNull ? null diff --git a/json_serializable/test/src/_json_serializable_test_input.dart b/json_serializable/test/src/_json_serializable_test_input.dart index 2e37b4770..72ab3c447 100644 --- a/json_serializable/test/src/_json_serializable_test_input.dart +++ b/json_serializable/test/src/_json_serializable_test_input.dart @@ -330,7 +330,7 @@ class PrivateFieldCtorClass { } @ShouldThrow( - 'Error with `@JsonKey` on `field`. ' + 'Error with `@JsonKey` on the `field` field. ' 'Cannot set both `disallowNullValue` and `includeIfNull` to `true`. ' 'This leads to incompatible `toJson` and `fromJson` behavior.', element: 'field', diff --git a/json_serializable/test/src/default_value_input.dart b/json_serializable/test/src/default_value_input.dart index cde52251a..b3801b760 100644 --- a/json_serializable/test/src/default_value_input.dart +++ b/json_serializable/test/src/default_value_input.dart @@ -5,7 +5,7 @@ part of '_json_serializable_test_input.dart'; @ShouldThrow( - 'Error with `@JsonKey` on `field`. ' + 'Error with `@JsonKey` on the `field` field. ' '`defaultValue` is `Symbol`, it must be a literal.', element: 'field', ) @@ -20,7 +20,7 @@ class DefaultWithSymbol { int _function() => 42; @ShouldThrow( - 'Error with `@JsonKey` on `field`. ' + 'Error with `@JsonKey` on the `field` field. ' '`defaultValue` is `Function`, it must be a literal.', element: 'field', ) @@ -33,7 +33,7 @@ class DefaultWithFunction { } @ShouldThrow( - 'Error with `@JsonKey` on `field`. ' + 'Error with `@JsonKey` on the `field` field. ' '`defaultValue` is `Type`, it must be a literal.', element: 'field', ) @@ -46,7 +46,7 @@ class DefaultWithType { } @ShouldThrow( - 'Error with `@JsonKey` on `field`. ' + 'Error with `@JsonKey` on the `field` field. ' '`defaultValue` is `Duration`, it must be a literal.', element: 'field', ) @@ -61,7 +61,7 @@ class DefaultWithConstObject { enum Enum { value } @ShouldThrow( - 'Error with `@JsonKey` on `field`. ' + 'Error with `@JsonKey` on the `field` field. ' '`defaultValue` is `List > Enum`, it must be a literal.', element: 'field', ) diff --git a/json_serializable/test/src/to_from_json_test_input.dart b/json_serializable/test/src/to_from_json_test_input.dart index 6658ce039..dafd680ea 100644 --- a/json_serializable/test/src/to_from_json_test_input.dart +++ b/json_serializable/test/src/to_from_json_test_input.dart @@ -15,8 +15,8 @@ Object _toObject(Object input) => throw UnimplementedError(); String _toStringFromObject(Object? input) => throw UnimplementedError(); @ShouldThrow( - 'Error with `@JsonKey` on `field`. The `fromJson` function `_toInt` ' - 'return type `int` is not compatible with field type `String`.', + 'Error with `@JsonKey` on the `field` field. The `fromJson` function ' + '`_toInt` return type `int` is not compatible with field type `String`.', element: 'field', ) @JsonSerializable() @@ -26,7 +26,7 @@ class BadFromFuncReturnType { } @ShouldThrow( - 'Error with `@JsonKey` on `field`. The `fromJson` function ' + 'Error with `@JsonKey` on the `field` field. The `fromJson` function ' '`_twoArgFunction` must have one positional parameter.', element: 'field', ) @@ -59,7 +59,7 @@ class ValidToFromFuncClassStatic { } @ShouldThrow( - 'Error with `@JsonKey` on `field`. The `toJson` function `_toInt` ' + 'Error with `@JsonKey` on the `field` field. The `toJson` function `_toInt` ' 'argument type `bool` is not compatible with field type `String`.', element: 'field', ) @@ -70,8 +70,9 @@ class BadToFuncReturnType { } @ShouldThrow( - 'Error with `@JsonKey` on `values`. The `fromJson` function `_fromList` ' - 'return type `List<int>?` is not compatible with field type `List<int>`.', + 'Error with `@JsonKey` on the `values` field. The `fromJson` function ' + '`_fromList` return type `List<int>?` is not compatible with field type ' + '`List<int>`.', element: 'values', ) @JsonSerializable() @@ -127,7 +128,7 @@ List<List>? _toList(List<int>? pairs) => pairs?.map((it) => [it]).toList(growable: false); @ShouldThrow( - 'Error with `@JsonKey` on `field`. The `toJson` function ' + 'Error with `@JsonKey` on the `field` field. The `toJson` function ' '`_twoArgFunction` must have one positional parameter.', element: 'field', ) @@ -248,7 +249,7 @@ class FromNullableDynamicCollection { String _noArgs() => throw UnimplementedError(); @ShouldThrow( - 'Error with `@JsonKey` on `field`. The `fromJson` function ' + 'Error with `@JsonKey` on the `field` field. The `fromJson` function ' '`_noArgs` must have one positional parameter.', element: 'field', ) @@ -261,7 +262,7 @@ class BadNoArgs { String? _twoArgs(a, b) => null; @ShouldThrow( - 'Error with `@JsonKey` on `field`. The `fromJson` function ' + 'Error with `@JsonKey` on the `field` field. The `fromJson` function ' '`_twoArgs` must have one positional parameter.', element: 'field', ) @@ -274,7 +275,7 @@ class BadTwoRequiredPositional { String? _oneNamed({a}) => null; @ShouldThrow( - 'Error with `@JsonKey` on `field`. The `fromJson` function ' + 'Error with `@JsonKey` on the `field` field. The `fromJson` function ' '`_oneNamed` must have one positional parameter.', element: 'field', ) diff --git a/json_serializable/test/src/unknown_enum_value_test_input.dart b/json_serializable/test/src/unknown_enum_value_test_input.dart index a7b6ff0fb..e69204deb 100644 --- a/json_serializable/test/src/unknown_enum_value_test_input.dart +++ b/json_serializable/test/src/unknown_enum_value_test_input.dart @@ -32,7 +32,7 @@ class UnknownEnumValue { enum UnknownEnumValueItems { v0, v1, v2, vUnknown, vNull } @ShouldThrow( - 'Error with `@JsonKey` on `value`. `unknownEnumValue` has type ' + 'Error with `@JsonKey` on the `value` field. `unknownEnumValue` has type ' '`int`, but the provided unknownEnumValue is of type ' '`WrongEnumType`.', ) @@ -43,7 +43,7 @@ class UnknownEnumValueListWrongType { } @ShouldThrow( - 'Error with `@JsonKey` on `value`. `unknownEnumValue` has type ' + 'Error with `@JsonKey` on the `value` field. `unknownEnumValue` has type ' '`UnknownEnumValueItems`, but the provided unknownEnumValue is of type ' '`WrongEnumType`.', ) @@ -56,7 +56,7 @@ class UnknownEnumValueListWrongEnumType { enum WrongEnumType { otherValue } @ShouldThrow( - 'Error with `@JsonKey` on `value`. `unknownEnumValue` has type ' + 'Error with `@JsonKey` on the `value` field. `unknownEnumValue` has type ' '`UnknownEnumValueItems`, but the provided unknownEnumValue is of type ' '`WrongEnumType`.', ) @@ -67,7 +67,7 @@ class UnknownEnumValueWrongEnumType { } @ShouldThrow( - 'Error with `@JsonKey` on `value`. The value provided ' + 'Error with `@JsonKey` on the `value` field. The value provided ' 'for `unknownEnumValue` must be a matching enum.', ) @JsonSerializable() @@ -77,8 +77,9 @@ class UnknownEnumValueNotEnumValue { } @ShouldThrow( - 'Error with `@JsonKey` on `value`. `unknownEnumValue` can only be set on ' - 'fields of type enum or on Iterable, List, or Set instances of an enum type.', + 'Error with `@JsonKey` on the `value` field. `unknownEnumValue` can only be ' + 'set on fields of type enum or on Iterable, List, or Set instances of an ' + 'enum type.', ) @JsonSerializable() class UnknownEnumValueNotEnumField { From b15f0d0828a8772a15dd6526d3b7b32071ce4e4b Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@google.com> Date: Fri, 8 Oct 2021 17:29:59 -0700 Subject: [PATCH 358/569] Add sentinel value for `null` as the fallback for an unknown enum value Fixes https://github.com/google/json_serializable.dart/issues/559 --- json_annotation/CHANGELOG.md | 2 + json_annotation/lib/src/enum_helpers.dart | 52 +++++++++++++------ json_annotation/lib/src/json_key.dart | 10 ++++ json_serializable/CHANGELOG.md | 2 + json_serializable/lib/src/json_key_utils.dart | 6 ++- .../lib/src/type_helpers/config_types.dart | 2 +- .../lib/src/type_helpers/enum_helper.dart | 23 +++++++- .../test/integration/integration_test.dart | 20 +++++++ .../test/integration/json_enum_example.dart | 25 +++++++++ .../test/integration/json_enum_example.g.dart | 18 +++++++ .../test/json_serializable_test.dart | 3 ++ .../test/src/default_value_input.dart | 13 +++++ .../src/unknown_enum_value_test_input.dart | 20 +++++++ 13 files changed, 178 insertions(+), 18 deletions(-) diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index ba4985757..9e4c6cd5b 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -5,6 +5,8 @@ - Added `JsonEnum` for annotating `enum` types. - Added `$enumDecodeNullable` and `$enumDecode` helpers to minimize generated code. +- Added `const` `JsonKey.nullForUndefinedEnumValue` for use in + `JsonKey.unknownEnumValue` when you want to use `null` for an unknown value. - Require Dart SDK `>=2.14.0`. ## 4.1.0 diff --git a/json_annotation/lib/src/enum_helpers.dart b/json_annotation/lib/src/enum_helpers.dart index db1d45a8b..93b25cb31 100644 --- a/json_annotation/lib/src/enum_helpers.dart +++ b/json_annotation/lib/src/enum_helpers.dart @@ -2,6 +2,8 @@ // 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 'json_key.dart'; + /// Returns the key associated with value [source] from [enumValues], if one /// exists. /// @@ -14,13 +16,31 @@ /// Not meant to be used directly by user code. K? $enumDecodeNullable<K extends Enum, V>( Map<K, V> enumValues, - dynamic source, { - K? unknownValue, + Object? source, { + Object? unknownValue, }) { if (source == null) { return null; } - return $enumDecode<K, V>(enumValues, source, unknownValue: unknownValue); + + for (var entry in enumValues.entries) { + if (entry.value == source) { + return entry.key; + } + } + + if (unknownValue == JsonKey.nullForUndefinedEnumValue) { + return null; + } + + if (unknownValue == null) { + throw ArgumentError( + '`$source` is not one of the supported values: ' + '${enumValues.values.join(', ')}', + ); + } + + return unknownValue as K; } /// Returns the key associated with value [source] from [enumValues], if one @@ -45,16 +65,18 @@ K $enumDecode<K extends Enum, V>( ); } - return enumValues.entries.singleWhere( - (e) => e.value == source, - orElse: () { - if (unknownValue == null) { - throw ArgumentError( - '`$source` is not one of the supported values: ' - '${enumValues.values.join(', ')}', - ); - } - return MapEntry(unknownValue, enumValues.values.first); - }, - ).key; + for (var entry in enumValues.entries) { + if (entry.value == source) { + return entry.key; + } + } + + if (unknownValue == null) { + throw ArgumentError( + '`$source` is not one of the supported values: ' + '${enumValues.values.join(', ')}', + ); + } + + return unknownValue; } diff --git a/json_annotation/lib/src/json_key.dart b/json_annotation/lib/src/json_key.dart index 4481b3cd4..44d7ab149 100644 --- a/json_annotation/lib/src/json_key.dart +++ b/json_annotation/lib/src/json_key.dart @@ -91,6 +91,10 @@ class JsonKey { /// source enum. /// /// Valid only on enum fields with a compatible enum value. + /// + /// If you want to use the value `null` when encountering an unknown value, + /// use the value of [JsonKey.nullForUndefinedEnumValue] instead. This is only + /// valid on an nullable enum field. final Object? unknownEnumValue; /// Creates a new [JsonKey] instance. @@ -108,4 +112,10 @@ class JsonKey { this.toJson, this.unknownEnumValue, }); + + /// Sentinel value for use with [unknownEnumValue]. + /// + /// Read the documentation on [unknownEnumValue] for more details. + static const Object nullForUndefinedEnumValue = + r'JsonKey.nullForUndefinedEnumValue'; } diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 734e93109..fcc786f89 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -3,6 +3,8 @@ - Added support for `JsonSerializabel.constructor` to allow specifying an alternative constructor to invoke when creating a `fromJson` helper. - Support the new `@JsonEnum` annotation in `package:json_annotation`. +- Support `JsonKey.nullForUndefinedEnumValue` as a value for + `JsonKey.unknownEnumValue` when you want to use `null` as the unknown value. - Use the new `$enumDecodeNullable` and `$enumDecode` in `json_annotation' instead of generating these for each library. **NOTE**: This is a potential breaking change if any user code relies on diff --git a/json_serializable/lib/src/json_key_utils.dart b/json_serializable/lib/src/json_key_utils.dart index d3f0b9c4a..5192d2835 100644 --- a/json_serializable/lib/src/json_key_utils.dart +++ b/json_serializable/lib/src/json_key_utils.dart @@ -6,6 +6,7 @@ import 'package:analyzer/dart/constant/value.dart'; import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/type.dart'; import 'package:build/build.dart'; +import 'package:json_annotation/json_annotation.dart'; import 'package:source_gen/source_gen.dart'; import 'package:source_helper/source_helper.dart'; @@ -171,6 +172,9 @@ KeyConfig _from(FieldElement element, ClassConfig classAnnotation) { return null; } if (mustBeEnum) { + if (defaultValueLiteral == JsonKey.nullForUndefinedEnumValue) { + return defaultValueLiteral as String; + } throwUnsupported( element, 'The value provided for `$fieldName` must be a matching enum.', @@ -212,7 +216,7 @@ KeyConfig _populateJsonKey( bool? includeIfNull, String? name, bool? required, - Object? unknownEnumValue, + String? unknownEnumValue, }) { if (disallowNullValue == true) { if (includeIfNull == true) { diff --git a/json_serializable/lib/src/type_helpers/config_types.dart b/json_serializable/lib/src/type_helpers/config_types.dart index 3d65dc5a0..916894f91 100644 --- a/json_serializable/lib/src/type_helpers/config_types.dart +++ b/json_serializable/lib/src/type_helpers/config_types.dart @@ -18,7 +18,7 @@ class KeyConfig { final bool required; - final Object? unknownEnumValue; + final String? unknownEnumValue; KeyConfig({ required this.defaultValue, diff --git a/json_serializable/lib/src/type_helpers/enum_helper.dart b/json_serializable/lib/src/type_helpers/enum_helper.dart index 68609da65..b133733dd 100644 --- a/json_serializable/lib/src/type_helpers/enum_helper.dart +++ b/json_serializable/lib/src/type_helpers/enum_helper.dart @@ -3,6 +3,8 @@ // BSD-style license that can be found in the LICENSE file. import 'package:analyzer/dart/element/type.dart'; +import 'package:json_annotation/json_annotation.dart'; +import 'package:source_gen/source_gen.dart'; import 'package:source_helper/source_helper.dart'; import '../enum_utils.dart'; @@ -44,6 +46,26 @@ class EnumHelper extends TypeHelper<TypeHelperContextWithConfig> { return null; } + final jsonKey = jsonKeyForField(context.fieldElement, context.config); + + if (jsonKey.defaultValue == "'${JsonKey.nullForUndefinedEnumValue}'") { + throw InvalidGenerationSourceError( + '`${JsonKey.nullForUndefinedEnumValue}` cannot be used with ' + '`JsonKey.defaultValue`.', + element: context.fieldElement, + ); + } + + if (!targetType.isNullableType && + jsonKey.unknownEnumValue == JsonKey.nullForUndefinedEnumValue) { + // If the target is not nullable, + throw InvalidGenerationSourceError( + '`${JsonKey.nullForUndefinedEnumValue}` cannot be used with ' + '`JsonKey.unknownEnumValue` unless the field is nullable.', + element: context.fieldElement, + ); + } + String functionName; if (targetType.isNullableType || defaultProvided) { functionName = r'$enumDecodeNullable'; @@ -53,7 +75,6 @@ class EnumHelper extends TypeHelper<TypeHelperContextWithConfig> { context.addMember(memberContent); - final jsonKey = jsonKeyForField(context.fieldElement, context.config); final args = [ constMapName(targetType), expression, diff --git a/json_serializable/test/integration/integration_test.dart b/json_serializable/test/integration/integration_test.dart index ab20d28e2..13e06f2b6 100644 --- a/json_serializable/test/integration/integration_test.dart +++ b/json_serializable/test/integration/integration_test.dart @@ -2,6 +2,7 @@ // 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:json_annotation/json_annotation.dart'; import 'package:test/test.dart'; import '../test_utils.dart'; @@ -302,4 +303,23 @@ void main() { expect(standAloneEnumValues, ['a', 'b', 'g', 'd']); expect(dayTypeEnumValues, ['no-good', 'rotten', 'very-bad']); }); + + test('unknown as null for enum', () { + expect( + () => Issue559Regression.fromJson({}).status, + throwsA(isA<MissingRequiredKeysException>()), + ); + expect( + () => Issue559Regression.fromJson({'status': null}).status, + throwsA(isA<DisallowedNullValueException>()), + ); + expect( + Issue559Regression.fromJson({'status': 'gamma'}).status, + Issue559RegressionEnum.gamma, + ); + expect( + Issue559Regression.fromJson({'status': 'bob'}).status, + isNull, + ); + }); } diff --git a/json_serializable/test/integration/json_enum_example.dart b/json_serializable/test/integration/json_enum_example.dart index fe7cfa279..5b25001f8 100644 --- a/json_serializable/test/integration/json_enum_example.dart +++ b/json_serializable/test/integration/json_enum_example.dart @@ -24,3 +24,28 @@ enum DayType { } Iterable<String> get dayTypeEnumValues => _$DayTypeEnumMap.values; + +@JsonSerializable( + createToJson: false, +) +class Issue559Regression { + Issue559Regression({ + required this.status, + }); + + factory Issue559Regression.fromJson(Map<String, dynamic> json) => + _$Issue559RegressionFromJson(json); + + @JsonKey( + disallowNullValue: true, + required: true, + unknownEnumValue: JsonKey.nullForUndefinedEnumValue, + ) + final Issue559RegressionEnum? status; +} + +enum Issue559RegressionEnum { + alpha, + beta, + gamma, +} diff --git a/json_serializable/test/integration/json_enum_example.g.dart b/json_serializable/test/integration/json_enum_example.g.dart index c99f8d56a..c416d5540 100644 --- a/json_serializable/test/integration/json_enum_example.g.dart +++ b/json_serializable/test/integration/json_enum_example.g.dart @@ -8,6 +8,24 @@ part of 'json_enum_example.dart'; // JsonSerializableGenerator // ************************************************************************** +Issue559Regression _$Issue559RegressionFromJson(Map<String, dynamic> json) { + $checkKeys( + json, + requiredKeys: const ['status'], + disallowNullValues: const ['status'], + ); + return Issue559Regression( + status: $enumDecodeNullable(_$Issue559RegressionEnumEnumMap, json['status'], + unknownValue: JsonKey.nullForUndefinedEnumValue), + ); +} + +const _$Issue559RegressionEnumEnumMap = { + Issue559RegressionEnum.alpha: 'alpha', + Issue559RegressionEnum.beta: 'beta', + Issue559RegressionEnum.gamma: 'gamma', +}; + const _$StandAloneEnumEnumMap = { StandAloneEnum.alpha: 'a', StandAloneEnum.beta: 'b', diff --git a/json_serializable/test/json_serializable_test.dart b/json_serializable/test/json_serializable_test.dart index b7dd734ff..2c3a6cece 100644 --- a/json_serializable/test/json_serializable_test.dart +++ b/json_serializable/test/json_serializable_test.dart @@ -41,6 +41,7 @@ const _expectedAnnotatedTests = { 'BadOneNamed', 'BadToFuncReturnType', 'BadTwoRequiredPositional', + 'BadEnumDefaultValue', '_BetterPrivateNames', 'CtorDefaultValueAndJsonKeyDefaultValue', 'DefaultDoubleConstants', @@ -98,6 +99,7 @@ const _expectedAnnotatedTests = { 'NoDeserializeFieldType', 'NoSerializeBadKey', 'NoSerializeFieldType', + 'NullForUndefinedEnumValueOnNonNullableField', 'ObjectConvertMethods', 'OkayOneNormalOptionalNamed', 'OkayOneNormalOptionalPositional', @@ -130,6 +132,7 @@ const _expectedAnnotatedTests = { 'UnsupportedSetField', 'UnsupportedUriField', 'ValidToFromFuncClassStatic', + 'WeirdValueForUnknownEnumValue', 'WithANonCtorGetter', 'WithANonCtorGetterChecked', 'WrongConstructorNameClass', diff --git a/json_serializable/test/src/default_value_input.dart b/json_serializable/test/src/default_value_input.dart index b3801b760..7eb0ff7da 100644 --- a/json_serializable/test/src/default_value_input.dart +++ b/json_serializable/test/src/default_value_input.dart @@ -73,6 +73,19 @@ class DefaultWithNestedEnum { DefaultWithNestedEnum(); } +@ShouldThrow( + '`JsonKey.nullForUndefinedEnumValue` cannot be used with ' + '`JsonKey.defaultValue`.', + element: 'enumValue', +) +@JsonSerializable() +class BadEnumDefaultValue { + @JsonKey(defaultValue: JsonKey.nullForUndefinedEnumValue) + Enum? enumValue; + + BadEnumDefaultValue(); +} + @ShouldGenerate( r''' DefaultWithToJsonClass _$DefaultWithToJsonClassFromJson( diff --git a/json_serializable/test/src/unknown_enum_value_test_input.dart b/json_serializable/test/src/unknown_enum_value_test_input.dart index e69204deb..53232aa88 100644 --- a/json_serializable/test/src/unknown_enum_value_test_input.dart +++ b/json_serializable/test/src/unknown_enum_value_test_input.dart @@ -86,3 +86,23 @@ class UnknownEnumValueNotEnumField { @JsonKey(unknownEnumValue: UnknownEnumValueItems.vUnknown) int? value; } + +@ShouldThrow( + '`JsonKey.nullForUndefinedEnumValue` cannot be used with ' + '`JsonKey.unknownEnumValue` unless the field is nullable.', +) +@JsonSerializable() +class NullForUndefinedEnumValueOnNonNullableField { + @JsonKey(unknownEnumValue: JsonKey.nullForUndefinedEnumValue) + late UnknownEnumValueItems value; +} + +@ShouldThrow( + 'Error with `@JsonKey` on the `value` field. `unknownEnumValue` is ' + '`JsonSerializable`, it must be a literal.', +) +@JsonSerializable() +class WeirdValueForUnknownEnumValue { + @JsonKey(unknownEnumValue: JsonSerializable()) + late UnknownEnumValueItems value; +} From 5456a62582db4fd723846694e82e1b7496cafdae Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Mon, 11 Oct 2021 13:39:07 -0700 Subject: [PATCH 359/569] Latest mono_repo (#1005) --- .github/workflows/dart.yml | 28 ++++++++++++++-------------- tool/ci.sh | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 5555c30f6..871c0fac4 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -1,4 +1,4 @@ -# Created with package:mono_repo v5.0.2 +# Created with package:mono_repo v5.0.3 name: Dart CI on: push: @@ -27,13 +27,13 @@ jobs: restore-keys: | os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: dart-lang/setup-dart@v1.2 + - uses: dart-lang/setup-dart@v1.3 with: sdk: stable - id: checkout uses: actions/checkout@v2.3.4 - name: mono_repo self validate - run: dart pub global activate mono_repo 5.0.2 + run: dart pub global activate mono_repo 5.0.3 - name: mono_repo self validate run: dart pub global run mono_repo generate --validate job_002: @@ -50,7 +50,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted;dart:2.12.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: dart-lang/setup-dart@v1.2 + - uses: dart-lang/setup-dart@v1.3 with: sdk: "2.12.0" - id: checkout @@ -95,7 +95,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted;dart:2.14.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: dart-lang/setup-dart@v1.2 + - uses: dart-lang/setup-dart@v1.3 with: sdk: "2.14.0" - id: checkout @@ -153,7 +153,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted;dart:dev os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: dart-lang/setup-dart@v1.2 + - uses: dart-lang/setup-dart@v1.3 with: sdk: dev - id: checkout @@ -237,7 +237,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted;dart:2.12.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: dart-lang/setup-dart@v1.2 + - uses: dart-lang/setup-dart@v1.3 with: sdk: "2.12.0" - id: checkout @@ -279,7 +279,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted;dart:2.14.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: dart-lang/setup-dart@v1.2 + - uses: dart-lang/setup-dart@v1.3 with: sdk: "2.14.0" - id: checkout @@ -321,7 +321,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted;dart:2.14.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: dart-lang/setup-dart@v1.2 + - uses: dart-lang/setup-dart@v1.3 with: sdk: "2.14.0" - id: checkout @@ -354,7 +354,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted;dart:dev os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: dart-lang/setup-dart@v1.2 + - uses: dart-lang/setup-dart@v1.3 with: sdk: dev - id: checkout @@ -414,7 +414,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted;dart:dev os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: dart-lang/setup-dart@v1.2 + - uses: dart-lang/setup-dart@v1.3 with: sdk: dev - id: checkout @@ -447,7 +447,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted;dart:2.12.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: dart-lang/setup-dart@v1.2 + - uses: dart-lang/setup-dart@v1.3 with: sdk: "2.12.0" - id: checkout @@ -494,7 +494,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted;dart:2.14.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: dart-lang/setup-dart@v1.2 + - uses: dart-lang/setup-dart@v1.3 with: sdk: "2.14.0" - id: checkout @@ -541,7 +541,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted;dart:dev os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: dart-lang/setup-dart@v1.2 + - uses: dart-lang/setup-dart@v1.3 with: sdk: dev - id: checkout diff --git a/tool/ci.sh b/tool/ci.sh index 47e488070..85179cd28 100755 --- a/tool/ci.sh +++ b/tool/ci.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Created with package:mono_repo v5.0.2 +# Created with package:mono_repo v5.0.3 # Support built in commands on windows out of the box. # When it is a flutter repo (check the pubspec.yaml for "sdk: flutter") From ed22f382bfb7bfb0f2f7cf87eba28be059bf15d2 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Tue, 12 Oct 2021 17:49:02 -0700 Subject: [PATCH 360/569] Prepare to release v4.2.0 of json_annotation (#1006) --- json_annotation/CHANGELOG.md | 4 ++-- json_annotation/pubspec.yaml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index 9e4c6cd5b..b7b3d8fce 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -1,6 +1,6 @@ -## 4.2.0-dev +## 4.2.0 -- Added `JsonSerializabel.constructor` field to allow specifying an alternative +- Added `JsonSerializable.constructor` field to allow specifying an alternative constructor to invoke when creating a `fromJson` helper. - Added `JsonEnum` for annotating `enum` types. - Added `$enumDecodeNullable` and `$enumDecode` helpers to minimize generated diff --git a/json_annotation/pubspec.yaml b/json_annotation/pubspec.yaml index a3b427500..466b4633d 100644 --- a/json_annotation/pubspec.yaml +++ b/json_annotation/pubspec.yaml @@ -1,5 +1,5 @@ name: json_annotation -version: 4.2.0-dev +version: 4.2.0 description: >- Classes and helper functions that support JSON code generation via the `json_serializable` package. From 26ce0caca591fd3930a0738c46afc4a13d31e4b7 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@google.com> Date: Tue, 12 Oct 2021 17:51:43 -0700 Subject: [PATCH 361/569] Use published json_annotation, update generated docs --- json_serializable/README.md | 16 ++++++++-------- json_serializable/pubspec.yaml | 4 ---- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/json_serializable/README.md b/json_serializable/README.md index 7b3e53906..ae8fd4643 100644 --- a/json_serializable/README.md +++ b/json_serializable/README.md @@ -201,14 +201,14 @@ targets: [`Enum`]: https://api.dart.dev/stable/dart-core/Enum-class.html [`int`]: https://api.dart.dev/stable/dart-core/int-class.html [`Iterable`]: https://api.dart.dev/stable/dart-core/Iterable-class.html -[`JsonConverter`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonConverter-class.html -[`JsonEnum`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonEnum-class.html -[`JsonKey.fromJson`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/fromJson.html -[`JsonKey.toJson`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/toJson.html -[`JsonKey`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey-class.html -[`JsonLiteral`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonLiteral-class.html -[`JsonSerializable`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable-class.html -[`JsonValue`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonValue-class.html +[`JsonConverter`]: https://pub.dev/documentation/json_annotation/4.2.0/json_annotation/JsonConverter-class.html +[`JsonEnum`]: https://pub.dev/documentation/json_annotation/4.2.0/json_annotation/JsonEnum-class.html +[`JsonKey.fromJson`]: https://pub.dev/documentation/json_annotation/4.2.0/json_annotation/JsonKey/fromJson.html +[`JsonKey.toJson`]: https://pub.dev/documentation/json_annotation/4.2.0/json_annotation/JsonKey/toJson.html +[`JsonKey`]: https://pub.dev/documentation/json_annotation/4.2.0/json_annotation/JsonKey-class.html +[`JsonLiteral`]: https://pub.dev/documentation/json_annotation/4.2.0/json_annotation/JsonLiteral-class.html +[`JsonSerializable`]: https://pub.dev/documentation/json_annotation/4.2.0/json_annotation/JsonSerializable-class.html +[`JsonValue`]: https://pub.dev/documentation/json_annotation/4.2.0/json_annotation/JsonValue-class.html [`List`]: https://api.dart.dev/stable/dart-core/List-class.html [`Map`]: https://api.dart.dev/stable/dart-core/Map-class.html [`num`]: https://api.dart.dev/stable/dart-core/num-class.html diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index f016976f1..b67ebb048 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -31,7 +31,3 @@ dev_dependencies: stack_trace: ^1.10.0 test: ^1.16.0 yaml: ^3.0.0 - -dependency_overrides: - json_annotation: - path: ../json_annotation From 8d150b63eab8c6acc75fc0c52bce5b1721f95ba8 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@google.com> Date: Tue, 12 Oct 2021 18:23:30 -0700 Subject: [PATCH 362/569] Drop `dynamic` from generated doc links --- json_serializable/README.md | 4 +--- json_serializable/tool/readme_builder.dart | 2 ++ 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/json_serializable/README.md b/json_serializable/README.md index ae8fd4643..91022ba17 100644 --- a/json_serializable/README.md +++ b/json_serializable/README.md @@ -140,8 +140,7 @@ The collection types – – can contain values of all the above types. For [`Map`], the key value must be one of -[`BigInt`], [`DateTime`], [`dynamic`], [`Enum`], [`int`], [`Object`], -[`String`], [`Uri`] +[`BigInt`], [`DateTime`], [`Enum`], [`int`], [`Object`], [`String`], [`Uri`] # Custom types and custom encoding @@ -197,7 +196,6 @@ targets: [`DateTime`]: https://api.dart.dev/stable/dart-core/DateTime-class.html [`double`]: https://api.dart.dev/stable/dart-core/double-class.html [`Duration`]: https://api.dart.dev/stable/dart-core/Duration-class.html -[`dynamic`]: https://api.dart.dev/stable/dart-core/dynamic-class.html [`Enum`]: https://api.dart.dev/stable/dart-core/Enum-class.html [`int`]: https://api.dart.dev/stable/dart-core/int-class.html [`Iterable`]: https://api.dart.dev/stable/dart-core/Iterable-class.html diff --git a/json_serializable/tool/readme_builder.dart b/json_serializable/tool/readme_builder.dart index 2bad39344..cfb255496 100644 --- a/json_serializable/tool/readme_builder.dart +++ b/json_serializable/tool/readme_builder.dart @@ -110,6 +110,8 @@ String _coreTypeUri(String type) => String _classCleanAndSort(Iterable<String> classes) { final initial = (classes.map((e) => e == customEnumType ? 'Enum' : e).toList() ..sort(compareAsciiLowerCase)) + // Dropping `dynamic` – it's not linkable! + .where((element) => element != 'dynamic') // Start by mapping to the output format – so we wrap correctly .map((e) => '[`$e`]') .join(', '); From 20c97a80091e9a5992e2008ef6cec6645186e4c6 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Thu, 14 Oct 2021 07:26:08 -0700 Subject: [PATCH 363/569] Add checks to ensure the dependency on json_annotation is correct (#1008) --- .github/workflows/dart.yml | 184 +++++++++++++++--- _test_yaml/pubspec.yaml | 2 +- json_serializable/CHANGELOG.md | 4 +- .../lib/src/check_dependencies.dart | 151 ++++++++++++++ .../lib/src/json_part_builder.dart | 3 + json_serializable/mono_pkg.yaml | 2 +- json_serializable/pubspec.yaml | 8 +- .../test/annotation_version_test.dart | 161 +++++++++++++++ tool/ci.sh | 4 + 9 files changed, 485 insertions(+), 34 deletions(-) create mode 100644 json_serializable/lib/src/check_dependencies.dart create mode 100644 json_serializable/test/annotation_version_test.dart diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 871c0fac4..2618b4fd0 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -308,6 +308,72 @@ jobs: - job_003 - job_004 job_007: + name: "unit_test; Dart 2.14.0; PKG: json_serializable; `dart test --run-skipped -t presubmit-only test/annotation_version_test.dart`" + runs-on: ubuntu-latest + steps: + - name: Cache Pub hosted dependencies + uses: actions/cache@v2.1.6 + with: + path: "~/.pub-cache/hosted" + key: "os:ubuntu-latest;pub-cache-hosted;dart:2.14.0;packages:json_serializable;commands:test_3" + restore-keys: | + os:ubuntu-latest;pub-cache-hosted;dart:2.14.0;packages:json_serializable + os:ubuntu-latest;pub-cache-hosted;dart:2.14.0 + os:ubuntu-latest;pub-cache-hosted + os:ubuntu-latest + - uses: dart-lang/setup-dart@v1.3 + with: + sdk: "2.14.0" + - id: checkout + uses: actions/checkout@v2.3.4 + - id: json_serializable_pub_upgrade + name: json_serializable; dart pub upgrade + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: json_serializable + run: dart pub upgrade + - name: "json_serializable; dart test --run-skipped -t presubmit-only test/annotation_version_test.dart" + if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" + working-directory: json_serializable + run: dart test --run-skipped -t presubmit-only test/annotation_version_test.dart + needs: + - job_001 + - job_002 + - job_003 + - job_004 + job_008: + name: "unit_test; Dart 2.14.0; PKG: json_serializable; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" + runs-on: ubuntu-latest + steps: + - name: Cache Pub hosted dependencies + uses: actions/cache@v2.1.6 + with: + path: "~/.pub-cache/hosted" + key: "os:ubuntu-latest;pub-cache-hosted;dart:2.14.0;packages:json_serializable;commands:test_1" + restore-keys: | + os:ubuntu-latest;pub-cache-hosted;dart:2.14.0;packages:json_serializable + os:ubuntu-latest;pub-cache-hosted;dart:2.14.0 + os:ubuntu-latest;pub-cache-hosted + os:ubuntu-latest + - uses: dart-lang/setup-dart@v1.3 + with: + sdk: "2.14.0" + - id: checkout + uses: actions/checkout@v2.3.4 + - id: json_serializable_pub_upgrade + name: json_serializable; dart pub upgrade + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: json_serializable + run: dart pub upgrade + - name: "json_serializable; dart test --run-skipped -t presubmit-only test/ensure_build_test.dart" + if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" + working-directory: json_serializable + run: dart test --run-skipped -t presubmit-only test/ensure_build_test.dart + needs: + - job_001 + - job_002 + - job_003 + - job_004 + job_009: name: "unit_test; Dart 2.14.0; PKG: json_serializable; `dart test -p chrome`" runs-on: ubuntu-latest steps: @@ -340,7 +406,7 @@ jobs: - job_002 - job_003 - job_004 - job_008: + job_010: name: "unit_test; Dart dev; PKGS: _test_yaml, checked_yaml, example, json_serializable; `dart test`" runs-on: ubuntu-latest steps: @@ -400,7 +466,73 @@ jobs: - job_002 - job_003 - job_004 - job_009: + job_011: + name: "unit_test; Dart dev; PKG: json_serializable; `dart test --run-skipped -t presubmit-only test/annotation_version_test.dart`" + runs-on: ubuntu-latest + steps: + - name: Cache Pub hosted dependencies + uses: actions/cache@v2.1.6 + with: + path: "~/.pub-cache/hosted" + key: "os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:json_serializable;commands:test_3" + restore-keys: | + os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:json_serializable + os:ubuntu-latest;pub-cache-hosted;dart:dev + os:ubuntu-latest;pub-cache-hosted + os:ubuntu-latest + - uses: dart-lang/setup-dart@v1.3 + with: + sdk: dev + - id: checkout + uses: actions/checkout@v2.3.4 + - id: json_serializable_pub_upgrade + name: json_serializable; dart pub upgrade + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: json_serializable + run: dart pub upgrade + - name: "json_serializable; dart test --run-skipped -t presubmit-only test/annotation_version_test.dart" + if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" + working-directory: json_serializable + run: dart test --run-skipped -t presubmit-only test/annotation_version_test.dart + needs: + - job_001 + - job_002 + - job_003 + - job_004 + job_012: + name: "unit_test; Dart dev; PKG: json_serializable; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" + runs-on: ubuntu-latest + steps: + - name: Cache Pub hosted dependencies + uses: actions/cache@v2.1.6 + with: + path: "~/.pub-cache/hosted" + key: "os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:json_serializable;commands:test_1" + restore-keys: | + os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:json_serializable + os:ubuntu-latest;pub-cache-hosted;dart:dev + os:ubuntu-latest;pub-cache-hosted + os:ubuntu-latest + - uses: dart-lang/setup-dart@v1.3 + with: + sdk: dev + - id: checkout + uses: actions/checkout@v2.3.4 + - id: json_serializable_pub_upgrade + name: json_serializable; dart pub upgrade + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: json_serializable + run: dart pub upgrade + - name: "json_serializable; dart test --run-skipped -t presubmit-only test/ensure_build_test.dart" + if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" + working-directory: json_serializable + run: dart test --run-skipped -t presubmit-only test/ensure_build_test.dart + needs: + - job_001 + - job_002 + - job_003 + - job_004 + job_013: name: "unit_test; Dart dev; PKG: json_serializable; `dart test -p chrome`" runs-on: ubuntu-latest steps: @@ -433,7 +565,7 @@ jobs: - job_002 - job_003 - job_004 - job_010: + job_014: name: "ensure_build; Dart 2.12.0; PKGS: checked_yaml, example; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest steps: @@ -480,17 +612,21 @@ jobs: - job_007 - job_008 - job_009 - job_011: - name: "ensure_build; Dart 2.14.0; PKGS: _test_yaml, json_serializable; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" + - job_010 + - job_011 + - job_012 + - job_013 + job_015: + name: "ensure_build; Dart 2.14.0; PKG: _test_yaml; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@v2.1.6 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;dart:2.14.0;packages:_test_yaml-json_serializable;commands:test_1" + key: "os:ubuntu-latest;pub-cache-hosted;dart:2.14.0;packages:_test_yaml;commands:test_1" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;dart:2.14.0;packages:_test_yaml-json_serializable + os:ubuntu-latest;pub-cache-hosted;dart:2.14.0;packages:_test_yaml os:ubuntu-latest;pub-cache-hosted;dart:2.14.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest @@ -508,15 +644,6 @@ jobs: if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" working-directory: _test_yaml run: dart test --run-skipped -t presubmit-only test/ensure_build_test.dart - - id: json_serializable_pub_upgrade - name: json_serializable; dart pub upgrade - if: "always() && steps.checkout.conclusion == 'success'" - working-directory: json_serializable - run: dart pub upgrade - - name: "json_serializable; dart test --run-skipped -t presubmit-only test/ensure_build_test.dart" - if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" - working-directory: json_serializable - run: dart test --run-skipped -t presubmit-only test/ensure_build_test.dart needs: - job_001 - job_002 @@ -527,17 +654,21 @@ jobs: - job_007 - job_008 - job_009 - job_012: - name: "ensure_build; Dart dev; PKGS: _test_yaml, checked_yaml, example, json_serializable; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" + - job_010 + - job_011 + - job_012 + - job_013 + job_016: + name: "ensure_build; Dart dev; PKGS: _test_yaml, checked_yaml, example; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@v2.1.6 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_1" + key: "os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:_test_yaml-checked_yaml-example;commands:test_1" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:_test_yaml-checked_yaml-example-json_serializable + os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:_test_yaml-checked_yaml-example os:ubuntu-latest;pub-cache-hosted;dart:dev os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest @@ -573,15 +704,6 @@ jobs: if: "always() && steps.example_pub_upgrade.conclusion == 'success'" working-directory: example run: dart test --run-skipped -t presubmit-only test/ensure_build_test.dart - - id: json_serializable_pub_upgrade - name: json_serializable; dart pub upgrade - if: "always() && steps.checkout.conclusion == 'success'" - working-directory: json_serializable - run: dart pub upgrade - - name: "json_serializable; dart test --run-skipped -t presubmit-only test/ensure_build_test.dart" - if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" - working-directory: json_serializable - run: dart test --run-skipped -t presubmit-only test/ensure_build_test.dart needs: - job_001 - job_002 @@ -592,3 +714,7 @@ jobs: - job_007 - job_008 - job_009 + - job_010 + - job_011 + - job_012 + - job_013 diff --git a/_test_yaml/pubspec.yaml b/_test_yaml/pubspec.yaml index 74a9b271b..e6ec97674 100644 --- a/_test_yaml/pubspec.yaml +++ b/_test_yaml/pubspec.yaml @@ -8,7 +8,7 @@ dev_dependencies: build_runner: ^2.0.0 build_verify: ^2.0.0 checked_yaml: any - json_annotation: any + json_annotation: ^4.2.0 json_serializable: any test: ^1.6.0 yaml: ^3.0.0 diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index fcc786f89..446c07fdd 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,4 +1,4 @@ -## 5.1.0-dev +## 6.0.0-dev - Added support for `JsonSerializabel.constructor` to allow specifying an alternative constructor to invoke when creating a `fromJson` helper. @@ -9,6 +9,8 @@ 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.2.0 <4.3.0'`. diff --git a/json_serializable/lib/src/check_dependencies.dart b/json_serializable/lib/src/check_dependencies.dart new file mode 100644 index 000000000..df82a1f61 --- /dev/null +++ b/json_serializable/lib/src/check_dependencies.dart @@ -0,0 +1,151 @@ +// 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 'dart:async'; + +import 'package:async/async.dart'; +import 'package:build/build.dart'; +import 'package:pub_semver/pub_semver.dart'; +import 'package:pubspec_parse/pubspec_parse.dart'; + +const _productionDirectories = {'lib', 'bin'}; +const _annotationPkgName = 'json_annotation'; +final requiredJsonAnnotationMinVersion = Version.parse('4.2.0'); + +Future<void> pubspecHasRightVersion(BuildStep buildStep) async { + final segments = buildStep.inputId.pathSegments; + final productionDependency = + segments.length > 1 && _productionDirectories.contains(segments.first); + final resource = await buildStep.fetchResource( + productionDependency + ? _productionDependencyCheckResource + : _developmentDependencyCheckResource, + ); + + final errorMessage = await resource.run(buildStep); + + if (errorMessage == null) return; + + throw BadPackageDependencyError(errorMessage); +} + +final _productionDependencyCheckResource = + _OncePerBuild.resource<bool, String?>(true, _validatePubspec); + +final _developmentDependencyCheckResource = + _OncePerBuild.resource<bool, String?>(false, _validatePubspec); + +Future<String?> _validatePubspec(bool production, BuildStep buildStep) async { + final pubspecAssetId = AssetId(buildStep.inputId.package, 'pubspec.yaml'); + + if (!await buildStep.canRead(pubspecAssetId)) { + log.warning( + 'Could not read the "pubspec.yaml` file associated with this package. ' + 'Usage of package:$_annotationPkgName could not be verified.', + ); + return null; + } + + Future<Pubspec> readPubspec(AssetId asset) async { + final string = await buildStep.readAsString(asset); + return Pubspec.parse(string, sourceUrl: asset.uri); + } + + final pubspec = await readPubspec(pubspecAssetId); + + return _checkAnnotationConstraint( + pubspec, + !production, + ); +} + +String? _checkAnnotationConstraint( + Pubspec pubspec, + bool includeDevDependencies, +) { + var dependency = pubspec.dependencies[_annotationPkgName]; + + if (dependency == null && includeDevDependencies) { + dependency = pubspec.devDependencies[_annotationPkgName]; + } + + if (dependency == null) { + if (includeDevDependencies) { + dependency = pubspec.devDependencies[_annotationPkgName]; + + if (dependency == null) { + return 'You are missing a required dependency on $_annotationPkgName ' + 'with a lower bound of at least ' + '"$requiredJsonAnnotationMinVersion".'; + } + } else { + return 'You are missing a required dependency on $_annotationPkgName in ' + 'the "dependencies" section of your pubspec with a lower bound of at ' + 'least "$requiredJsonAnnotationMinVersion".'; + } + } + + if (dependency is! HostedDependency) { + log.warning( + 'Your dependency on `$_annotationPkgName` is not a ' + '`$HostedDependency`, as expected. Version checking is being skipped.', + ); + return null; + } + + // We know it's a HostedDependency at this point! + final constraint = dependency.version; + + final constraintTooLowMessage = + 'The version constraint "$constraint" on $_annotationPkgName allows ' + 'versions before $requiredJsonAnnotationMinVersion which is not ' + 'allowed.'; + + if (constraint is Version && constraint < requiredJsonAnnotationMinVersion) { + return constraintTooLowMessage; + } + + final range = constraint as VersionRange; + final rangeMin = range.min; + + if (rangeMin == null || rangeMin < requiredJsonAnnotationMinVersion) { + return constraintTooLowMessage; + } + + return null; +} + +class _OncePerBuild<S, T> { + final S state; + final FutureOr<T> Function(S, BuildStep) _callback; + AsyncMemoizer<T>? _memo; + + static Resource<_OncePerBuild<State, T>> resource<State, T>( + State state, + FutureOr<T> Function(State, BuildStep) callback, + ) => + Resource<_OncePerBuild<State, T>>( + () => _OncePerBuild._(state, callback), + dispose: (c) => c._dispose(), + ); + + _OncePerBuild._(this.state, this._callback); + + Future<T> run(BuildStep buildStep) => + (_memo ??= AsyncMemoizer()).runOnce(() => _callback(state, buildStep)); + + void _dispose() { + _memo = null; + } +} + +/// Thrown when a pubspec dependency is missing or incorrectly specified. +class BadPackageDependencyError extends Error { + final String message; + + BadPackageDependencyError(this.message); + + @override + String toString() => message; +} diff --git a/json_serializable/lib/src/json_part_builder.dart b/json_serializable/lib/src/json_part_builder.dart index d4c5d3cfe..832c2fbd5 100644 --- a/json_serializable/lib/src/json_part_builder.dart +++ b/json_serializable/lib/src/json_part_builder.dart @@ -6,6 +6,7 @@ import 'package:build/build.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:source_gen/source_gen.dart'; +import 'check_dependencies.dart'; import 'json_enum_generator.dart'; import 'json_literal_generator.dart'; import 'json_serializable_generator.dart'; @@ -51,6 +52,8 @@ class _UnifiedGenerator extends Generator { @override Future<String?> generate(LibraryReader library, BuildStep buildStep) async { + await pubspecHasRightVersion(buildStep); + final values = <String>{}; for (var generator in _generators) { diff --git a/json_serializable/mono_pkg.yaml b/json_serializable/mono_pkg.yaml index 6b1b63b89..fbc055781 100644 --- a/json_serializable/mono_pkg.yaml +++ b/json_serializable/mono_pkg.yaml @@ -11,7 +11,7 @@ stages: - unit_test: - test: - test: -p chrome -- ensure_build: + - test: --run-skipped -t presubmit-only test/annotation_version_test.dart - test: --run-skipped -t presubmit-only test/ensure_build_test.dart cache: diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index b67ebb048..d0fe34626 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 5.1.0-dev +version: 6.0.0-dev description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. @@ -9,6 +9,7 @@ environment: dependencies: analyzer: ^2.0.0 + async: ^2.8.0 build: ^2.0.0 build_config: '>=0.4.4 <2.0.0' collection: ^1.14.0 @@ -18,6 +19,8 @@ dependencies: json_annotation: '>=4.2.0 <4.3.0' meta: ^1.3.0 path: ^1.8.0 + pub_semver: ^2.0.0 + pubspec_parse: ^1.0.0 source_gen: ^1.0.0 source_helper: ^1.3.0 @@ -26,8 +29,9 @@ dev_dependencies: build_verify: ^2.0.0 dart_style: ^2.0.0 logging: ^1.0.0 - pub_semver: ^2.0.0 source_gen_test: ^1.0.0 stack_trace: ^1.10.0 test: ^1.16.0 + test_descriptor: ^2.0.0 + test_process: ^2.0.0 yaml: ^3.0.0 diff --git a/json_serializable/test/annotation_version_test.dart b/json_serializable/test/annotation_version_test.dart new file mode 100644 index 000000000..8c4ff829f --- /dev/null +++ b/json_serializable/test/annotation_version_test.dart @@ -0,0 +1,161 @@ +// 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. + +@TestOn('vm') +@Tags(['presubmit-only']) +import 'dart:convert'; +import 'dart:io'; + +import 'package:json_serializable/src/check_dependencies.dart'; +import 'package:path/path.dart' as p; +import 'package:pub_semver/pub_semver.dart'; +import 'package:pubspec_parse/pubspec_parse.dart'; +import 'package:test/test.dart'; +import 'package:test_descriptor/test_descriptor.dart' as d; +import 'package:test_process/test_process.dart'; + +void main() { + test('validate pubspec constraint', () { + final pubspec = Pubspec.parse( + File('pubspec.yaml').readAsStringSync(), + sourceUrl: Uri.file('pubspec.yaml'), + ); + + final annotationConstraint = + pubspec.dependencies['json_annotation'] as HostedDependency; + final versionRange = annotationConstraint.version as VersionRange; + + expect(versionRange.includeMin, isTrue); + expect(versionRange.min, requiredJsonAnnotationMinVersion); + }); + + test( + 'missing dependency in production code', + () => _structurePackage( + sourceDirectory: 'lib', + message: _missingProductionDep, + ), + ); + + test( + 'missing dependency in example code', + () => _structurePackage( + sourceDirectory: 'example', + message: + 'You are missing a required dependency on json_annotation with a ' + 'lower bound of at least "$_annotationLowerBound".', + ), + ); + + test( + 'dev dependency with a production usage', + () => _structurePackage( + sourceDirectory: 'lib', + devDependencies: {'json_annotation': _annotationLowerBound}, + message: _missingProductionDep, + ), + ); + + test( + 'dependency with `null` constraint', + () => _structurePackage( + sourceDirectory: 'lib', + dependencies: {'json_annotation': null}, + message: + 'The version constraint "any" on json_annotation allows versions ' + 'before $_annotationLowerBound which is not allowed.', + ), + ); + + test( + 'dependency with "any" constraint', + () => _structurePackage( + sourceDirectory: 'lib', + dependencies: {'json_annotation': 'any'}, + message: + 'The version constraint "any" on json_annotation allows versions ' + 'before $_annotationLowerBound which is not allowed.', + ), + ); + + test( + 'dependency with too low version range', + () => _structurePackage( + sourceDirectory: 'lib', + dependencies: {'json_annotation': '^4.0.0'}, + message: + 'The version constraint "^4.0.0" on json_annotation allows versions ' + 'before $_annotationLowerBound which is not allowed.', + ), + ); +} + +final _annotationLowerBound = requiredJsonAnnotationMinVersion.toString(); + +final _missingProductionDep = + 'You are missing a required dependency on json_annotation in the ' + '"dependencies" section of your pubspec with a lower bound of at least ' + '"$_annotationLowerBound".'; + +Future<void> _structurePackage({ + required String sourceDirectory, + required String message, + Map<String, dynamic> dependencies = const {}, + Map<String, dynamic> devDependencies = const {}, +}) async { + final pubspec = const JsonEncoder.withIndent(' ').convert( + { + 'name': '_test_pkg', + 'environment': {'sdk': '>=2.14.0 <3.0.0'}, + 'dependencies': dependencies, + 'dev_dependencies': { + ...devDependencies, + 'build_runner': 'any', + 'json_serializable': {'path': p.current}, + } + }, + ); + + await d.file('pubspec.yaml', pubspec).create(); + + await d.dir( + sourceDirectory, + [ + d.file( + 'sample.dart', + ''' +import 'package:json_annotation/json_annotation.dart'; + +part 'sample.g.dart'; + +@JsonSerializable() +class SomeClass{} +''', + ) + ], + ).create(); + + final proc = await TestProcess.start( + 'dart', + ['run', 'build_runner', 'build'], + workingDirectory: d.sandbox, + ); + + await proc.stdoutStream().forEach(print); + + await expectLater( + proc.stdout, + emitsThrough( + emitsInOrder([ + '[SEVERE] json_serializable:json_serializable on $sourceDirectory/sample.dart:', + '', + message, + ]), + ), + ); + + await expectLater(proc.stderr, emitsDone); + + await proc.shouldExit(1); +} diff --git a/tool/ci.sh b/tool/ci.sh index 85179cd28..edd653f85 100755 --- a/tool/ci.sh +++ b/tool/ci.sh @@ -87,6 +87,10 @@ for PKG in ${PKGS}; do echo 'dart test -p chrome' dart test -p chrome || EXIT_CODE=$? ;; + test_3) + echo 'dart test --run-skipped -t presubmit-only test/annotation_version_test.dart' + dart test --run-skipped -t presubmit-only test/annotation_version_test.dart || EXIT_CODE=$? + ;; *) echo -e "\033[31mUnknown TASK '${TASK}' - TERMINATING JOB\033[0m" exit 64 From a5fa29a7492cb2a4eb7ade528daf2677ed08ffaa Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@google.com> Date: Thu, 14 Oct 2021 14:00:31 -0700 Subject: [PATCH 364/569] Changes to cleanup support for null-as-default value for enums Prepare to release json_annotation v4.3.0 - Changed the type of `JsonKey.unknownEnumValue` from `Object?` to `Enum?`. - Changed the type of the `$enumDecodeNullable` parameter `unknownValue` from `Object?` to `Enum?`. --- _test_yaml/pubspec.yaml | 2 +- json_annotation/CHANGELOG.md | 8 +++++ json_annotation/lib/src/enum_helpers.dart | 12 ++++++-- json_annotation/lib/src/json_key.dart | 9 +++--- json_annotation/pubspec.yaml | 2 +- json_serializable/README.md | 16 +++++----- .../lib/src/check_dependencies.dart | 2 +- json_serializable/lib/src/json_key_utils.dart | 30 ++++++++++++++----- .../lib/src/type_helpers/enum_helper.dart | 13 ++------ json_serializable/pubspec.yaml | 6 +++- .../test/annotation_version_test.dart | 29 ++++++++++++------ .../test/json_serializable_test.dart | 3 -- .../src/unknown_enum_value_test_input.dart | 30 ------------------- 13 files changed, 83 insertions(+), 79 deletions(-) diff --git a/_test_yaml/pubspec.yaml b/_test_yaml/pubspec.yaml index e6ec97674..39171e628 100644 --- a/_test_yaml/pubspec.yaml +++ b/_test_yaml/pubspec.yaml @@ -8,7 +8,7 @@ dev_dependencies: build_runner: ^2.0.0 build_verify: ^2.0.0 checked_yaml: any - json_annotation: ^4.2.0 + json_annotation: ^4.3.0 json_serializable: any test: ^1.6.0 yaml: ^3.0.0 diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index b7b3d8fce..ee44417a1 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -1,3 +1,11 @@ +## 4.3.0 + +- Changed the type of `JsonKey.unknownEnumValue` from `Object?` to `Enum?`. + Assuming this feature has been used correctly, it shouldn't be a breaking + change. +- Changed the type of the `$enumDecodeNullable` parameter `unknownValue` from + `Object?` to `Enum?`. + ## 4.2.0 - Added `JsonSerializable.constructor` field to allow specifying an alternative diff --git a/json_annotation/lib/src/enum_helpers.dart b/json_annotation/lib/src/enum_helpers.dart index 93b25cb31..c0c5cb3ed 100644 --- a/json_annotation/lib/src/enum_helpers.dart +++ b/json_annotation/lib/src/enum_helpers.dart @@ -17,7 +17,7 @@ import 'json_key.dart'; K? $enumDecodeNullable<K extends Enum, V>( Map<K, V> enumValues, Object? source, { - Object? unknownValue, + Enum? unknownValue, }) { if (source == null) { return null; @@ -40,7 +40,15 @@ K? $enumDecodeNullable<K extends Enum, V>( ); } - return unknownValue as K; + if (unknownValue is! K) { + throw ArgumentError.value( + unknownValue, + 'unknownValue', + 'Must by of type `$K` or `JsonKey.nullForUndefinedEnumValue`.', + ); + } + + return unknownValue; } /// Returns the key associated with value [source] from [enumValues], if one diff --git a/json_annotation/lib/src/json_key.dart b/json_annotation/lib/src/json_key.dart index 44d7ab149..7a1c44b6f 100644 --- a/json_annotation/lib/src/json_key.dart +++ b/json_annotation/lib/src/json_key.dart @@ -94,8 +94,8 @@ class JsonKey { /// /// If you want to use the value `null` when encountering an unknown value, /// use the value of [JsonKey.nullForUndefinedEnumValue] instead. This is only - /// valid on an nullable enum field. - final Object? unknownEnumValue; + /// valid on a nullable enum field. + final Enum? unknownEnumValue; /// Creates a new [JsonKey] instance. /// @@ -116,6 +116,7 @@ class JsonKey { /// Sentinel value for use with [unknownEnumValue]. /// /// Read the documentation on [unknownEnumValue] for more details. - static const Object nullForUndefinedEnumValue = - r'JsonKey.nullForUndefinedEnumValue'; + static const Enum nullForUndefinedEnumValue = _NullAsDefault.value; } + +enum _NullAsDefault { value } diff --git a/json_annotation/pubspec.yaml b/json_annotation/pubspec.yaml index 466b4633d..9eddca416 100644 --- a/json_annotation/pubspec.yaml +++ b/json_annotation/pubspec.yaml @@ -1,5 +1,5 @@ name: json_annotation -version: 4.2.0 +version: 4.3.0 description: >- Classes and helper functions that support JSON code generation via the `json_serializable` package. diff --git a/json_serializable/README.md b/json_serializable/README.md index 91022ba17..4756a0760 100644 --- a/json_serializable/README.md +++ b/json_serializable/README.md @@ -199,14 +199,14 @@ targets: [`Enum`]: https://api.dart.dev/stable/dart-core/Enum-class.html [`int`]: https://api.dart.dev/stable/dart-core/int-class.html [`Iterable`]: https://api.dart.dev/stable/dart-core/Iterable-class.html -[`JsonConverter`]: https://pub.dev/documentation/json_annotation/4.2.0/json_annotation/JsonConverter-class.html -[`JsonEnum`]: https://pub.dev/documentation/json_annotation/4.2.0/json_annotation/JsonEnum-class.html -[`JsonKey.fromJson`]: https://pub.dev/documentation/json_annotation/4.2.0/json_annotation/JsonKey/fromJson.html -[`JsonKey.toJson`]: https://pub.dev/documentation/json_annotation/4.2.0/json_annotation/JsonKey/toJson.html -[`JsonKey`]: https://pub.dev/documentation/json_annotation/4.2.0/json_annotation/JsonKey-class.html -[`JsonLiteral`]: https://pub.dev/documentation/json_annotation/4.2.0/json_annotation/JsonLiteral-class.html -[`JsonSerializable`]: https://pub.dev/documentation/json_annotation/4.2.0/json_annotation/JsonSerializable-class.html -[`JsonValue`]: https://pub.dev/documentation/json_annotation/4.2.0/json_annotation/JsonValue-class.html +[`JsonConverter`]: https://pub.dev/documentation/json_annotation/4.3.0/json_annotation/JsonConverter-class.html +[`JsonEnum`]: https://pub.dev/documentation/json_annotation/4.3.0/json_annotation/JsonEnum-class.html +[`JsonKey.fromJson`]: https://pub.dev/documentation/json_annotation/4.3.0/json_annotation/JsonKey/fromJson.html +[`JsonKey.toJson`]: https://pub.dev/documentation/json_annotation/4.3.0/json_annotation/JsonKey/toJson.html +[`JsonKey`]: https://pub.dev/documentation/json_annotation/4.3.0/json_annotation/JsonKey-class.html +[`JsonLiteral`]: https://pub.dev/documentation/json_annotation/4.3.0/json_annotation/JsonLiteral-class.html +[`JsonSerializable`]: https://pub.dev/documentation/json_annotation/4.3.0/json_annotation/JsonSerializable-class.html +[`JsonValue`]: https://pub.dev/documentation/json_annotation/4.3.0/json_annotation/JsonValue-class.html [`List`]: https://api.dart.dev/stable/dart-core/List-class.html [`Map`]: https://api.dart.dev/stable/dart-core/Map-class.html [`num`]: https://api.dart.dev/stable/dart-core/num-class.html diff --git a/json_serializable/lib/src/check_dependencies.dart b/json_serializable/lib/src/check_dependencies.dart index df82a1f61..9d7e06de9 100644 --- a/json_serializable/lib/src/check_dependencies.dart +++ b/json_serializable/lib/src/check_dependencies.dart @@ -11,7 +11,7 @@ import 'package:pubspec_parse/pubspec_parse.dart'; const _productionDirectories = {'lib', 'bin'}; const _annotationPkgName = 'json_annotation'; -final requiredJsonAnnotationMinVersion = Version.parse('4.2.0'); +final requiredJsonAnnotationMinVersion = Version.parse('4.3.0'); Future<void> pubspecHasRightVersion(BuildStep buildStep) async { final segments = buildStep.inputId.pathSegments; diff --git a/json_serializable/lib/src/json_key_utils.dart b/json_serializable/lib/src/json_key_utils.dart index 5192d2835..65ea585db 100644 --- a/json_serializable/lib/src/json_key_utils.dart +++ b/json_serializable/lib/src/json_key_utils.dart @@ -126,10 +126,11 @@ KeyConfig _from(FieldElement element, ClassConfig classAnnotation) { /// [fieldName] is not an `enum` value. String? _annotationValue(String fieldName, {bool mustBeEnum = false}) { final annotationValue = obj.read(fieldName); + late final DartType annotationType; final enumFields = annotationValue.isNull ? null - : iterateEnumFields(annotationValue.objectValue.type!); + : iterateEnumFields(annotationType = annotationValue.objectValue.type!); if (enumFields != null) { if (mustBeEnum) { late DartType targetEnumType; @@ -144,25 +145,35 @@ KeyConfig _from(FieldElement element, ClassConfig classAnnotation) { 'Iterable, List, or Set instances of an enum type.', ); } - final annotatedEnumType = annotationValue.objectValue.type!; - if (!_interfaceTypesEqual(annotatedEnumType, targetEnumType)) { + + if (_nullAsUnknownChecker.isExactlyType(annotationType)) { + return jsonKeyNullForUndefinedEnumValueFieldName; + } else if (!_interfaceTypesEqual(annotationType, targetEnumType)) { throwUnsupported( element, '`$fieldName` has type ' '`${targetEnumType.getDisplayString(withNullability: false)}`, but ' 'the provided unknownEnumValue is of type ' - '`${annotatedEnumType.getDisplayString(withNullability: false)}`.', + '`${annotationType.getDisplayString(withNullability: false)}`.', ); } } + if (_nullAsUnknownChecker.isExactlyType(annotationType)) { + throw InvalidGenerationSourceError( + '`$jsonKeyNullForUndefinedEnumValueFieldName` cannot be used with ' + '`JsonKey.defaultValue`.', + element: element, + ); + } + final enumValueNames = enumFields.map((p) => p.name).toList(growable: false); final enumValueName = enumValueForDartObject<String>( annotationValue.objectValue, enumValueNames, (n) => n); - return '${annotationValue.objectValue.type!.element!.name}' + return '${annotationType.element!.name}' '.$enumValueName'; } else { final defaultValueLiteral = annotationValue.isNull @@ -172,9 +183,6 @@ KeyConfig _from(FieldElement element, ClassConfig classAnnotation) { return null; } if (mustBeEnum) { - if (defaultValueLiteral == JsonKey.nullForUndefinedEnumValue) { - return defaultValueLiteral as String; - } throwUnsupported( element, 'The value provided for `$fieldName` must be a matching enum.', @@ -258,3 +266,9 @@ bool _interfaceTypesEqual(DartType a, DartType b) { } return a == b; } + +const jsonKeyNullForUndefinedEnumValueFieldName = + 'JsonKey.nullForUndefinedEnumValue'; + +final _nullAsUnknownChecker = + TypeChecker.fromRuntime(JsonKey.nullForUndefinedEnumValue.runtimeType); diff --git a/json_serializable/lib/src/type_helpers/enum_helper.dart b/json_serializable/lib/src/type_helpers/enum_helper.dart index b133733dd..40fb6997c 100644 --- a/json_serializable/lib/src/type_helpers/enum_helper.dart +++ b/json_serializable/lib/src/type_helpers/enum_helper.dart @@ -3,7 +3,6 @@ // BSD-style license that can be found in the LICENSE file. import 'package:analyzer/dart/element/type.dart'; -import 'package:json_annotation/json_annotation.dart'; import 'package:source_gen/source_gen.dart'; import 'package:source_helper/source_helper.dart'; @@ -48,19 +47,11 @@ class EnumHelper extends TypeHelper<TypeHelperContextWithConfig> { final jsonKey = jsonKeyForField(context.fieldElement, context.config); - if (jsonKey.defaultValue == "'${JsonKey.nullForUndefinedEnumValue}'") { - throw InvalidGenerationSourceError( - '`${JsonKey.nullForUndefinedEnumValue}` cannot be used with ' - '`JsonKey.defaultValue`.', - element: context.fieldElement, - ); - } - if (!targetType.isNullableType && - jsonKey.unknownEnumValue == JsonKey.nullForUndefinedEnumValue) { + jsonKey.unknownEnumValue == jsonKeyNullForUndefinedEnumValueFieldName) { // If the target is not nullable, throw InvalidGenerationSourceError( - '`${JsonKey.nullForUndefinedEnumValue}` cannot be used with ' + '`$jsonKeyNullForUndefinedEnumValueFieldName` cannot be used with ' '`JsonKey.unknownEnumValue` unless the field is nullable.', element: context.fieldElement, ); diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index d0fe34626..b99391d97 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -16,7 +16,7 @@ dependencies: # Use a tight version constraint to ensure that a constraint on # `json_annotation` properly constrains all features it provides. - json_annotation: '>=4.2.0 <4.3.0' + json_annotation: '>=4.3.0 <4.4.0' meta: ^1.3.0 path: ^1.8.0 pub_semver: ^2.0.0 @@ -35,3 +35,7 @@ dev_dependencies: test_descriptor: ^2.0.0 test_process: ^2.0.0 yaml: ^3.0.0 + +dependency_overrides: + json_annotation: + path: ../json_annotation diff --git a/json_serializable/test/annotation_version_test.dart b/json_serializable/test/annotation_version_test.dart index 8c4ff829f..efbc70fdc 100644 --- a/json_serializable/test/annotation_version_test.dart +++ b/json_serializable/test/annotation_version_test.dart @@ -17,13 +17,8 @@ import 'package:test_process/test_process.dart'; void main() { test('validate pubspec constraint', () { - final pubspec = Pubspec.parse( - File('pubspec.yaml').readAsStringSync(), - sourceUrl: Uri.file('pubspec.yaml'), - ); - final annotationConstraint = - pubspec.dependencies['json_annotation'] as HostedDependency; + _jsonSerialPubspec.dependencies['json_annotation'] as HostedDependency; final versionRange = annotationConstraint.version as VersionRange; expect(versionRange.includeMin, isTrue); @@ -91,6 +86,23 @@ void main() { ); } +final _jsonSerialPubspec = Pubspec.parse( + File('pubspec.yaml').readAsStringSync(), + sourceUrl: Uri.file('pubspec.yaml'), +); + +String _fixPath(String path) { + if (p.isAbsolute(path)) return path; + + return p.canonicalize(p.join(p.current, path)); +} + +final _jsonSerialPathDependencyOverrides = { + for (var entry in _jsonSerialPubspec.dependencyOverrides.entries) + if (entry.value is PathDependency) + entry.key: {'path': _fixPath((entry.value as PathDependency).path)} +}; + final _annotationLowerBound = requiredJsonAnnotationMinVersion.toString(); final _missingProductionDep = @@ -113,7 +125,8 @@ Future<void> _structurePackage({ ...devDependencies, 'build_runner': 'any', 'json_serializable': {'path': p.current}, - } + }, + 'dependency_overrides': _jsonSerialPathDependencyOverrides, }, ); @@ -155,7 +168,5 @@ class SomeClass{} ), ); - await expectLater(proc.stderr, emitsDone); - await proc.shouldExit(1); } diff --git a/json_serializable/test/json_serializable_test.dart b/json_serializable/test/json_serializable_test.dart index 2c3a6cece..9c8b2d46a 100644 --- a/json_serializable/test/json_serializable_test.dart +++ b/json_serializable/test/json_serializable_test.dart @@ -99,7 +99,6 @@ const _expectedAnnotatedTests = { 'NoDeserializeFieldType', 'NoSerializeBadKey', 'NoSerializeFieldType', - 'NullForUndefinedEnumValueOnNonNullableField', 'ObjectConvertMethods', 'OkayOneNormalOptionalNamed', 'OkayOneNormalOptionalPositional', @@ -120,7 +119,6 @@ const _expectedAnnotatedTests = { 'ToJsonNullableFalseIncludeIfNullFalse', 'TypedConvertMethods', 'UnknownEnumValue', - 'UnknownEnumValueNotEnumValue', 'UnknownEnumValueListWrongEnumType', 'UnknownEnumValueListWrongType', 'UnknownEnumValueWrongEnumType', @@ -132,7 +130,6 @@ const _expectedAnnotatedTests = { 'UnsupportedSetField', 'UnsupportedUriField', 'ValidToFromFuncClassStatic', - 'WeirdValueForUnknownEnumValue', 'WithANonCtorGetter', 'WithANonCtorGetterChecked', 'WrongConstructorNameClass', diff --git a/json_serializable/test/src/unknown_enum_value_test_input.dart b/json_serializable/test/src/unknown_enum_value_test_input.dart index 53232aa88..c2f745899 100644 --- a/json_serializable/test/src/unknown_enum_value_test_input.dart +++ b/json_serializable/test/src/unknown_enum_value_test_input.dart @@ -66,16 +66,6 @@ class UnknownEnumValueWrongEnumType { late UnknownEnumValueItems value; } -@ShouldThrow( - 'Error with `@JsonKey` on the `value` field. The value provided ' - 'for `unknownEnumValue` must be a matching enum.', -) -@JsonSerializable() -class UnknownEnumValueNotEnumValue { - @JsonKey(unknownEnumValue: 'not enum value') - UnknownEnumValueItems? value; -} - @ShouldThrow( 'Error with `@JsonKey` on the `value` field. `unknownEnumValue` can only be ' 'set on fields of type enum or on Iterable, List, or Set instances of an ' @@ -86,23 +76,3 @@ class UnknownEnumValueNotEnumField { @JsonKey(unknownEnumValue: UnknownEnumValueItems.vUnknown) int? value; } - -@ShouldThrow( - '`JsonKey.nullForUndefinedEnumValue` cannot be used with ' - '`JsonKey.unknownEnumValue` unless the field is nullable.', -) -@JsonSerializable() -class NullForUndefinedEnumValueOnNonNullableField { - @JsonKey(unknownEnumValue: JsonKey.nullForUndefinedEnumValue) - late UnknownEnumValueItems value; -} - -@ShouldThrow( - 'Error with `@JsonKey` on the `value` field. `unknownEnumValue` is ' - '`JsonSerializable`, it must be a literal.', -) -@JsonSerializable() -class WeirdValueForUnknownEnumValue { - @JsonKey(unknownEnumValue: JsonSerializable()) - late UnknownEnumValueItems value; -} From 9e24cb23be396f4acad18da25d8e097194906d45 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@google.com> Date: Thu, 14 Oct 2021 16:07:09 -0700 Subject: [PATCH 365/569] simplify dependency check --- .../lib/src/check_dependencies.dart | 59 +++++++------------ 1 file changed, 22 insertions(+), 37 deletions(-) diff --git a/json_serializable/lib/src/check_dependencies.dart b/json_serializable/lib/src/check_dependencies.dart index 9d7e06de9..f5b389ddc 100644 --- a/json_serializable/lib/src/check_dependencies.dart +++ b/json_serializable/lib/src/check_dependencies.dart @@ -4,7 +4,6 @@ import 'dart:async'; -import 'package:async/async.dart'; import 'package:build/build.dart'; import 'package:pub_semver/pub_semver.dart'; import 'package:pubspec_parse/pubspec_parse.dart'; @@ -17,26 +16,17 @@ Future<void> pubspecHasRightVersion(BuildStep buildStep) async { final segments = buildStep.inputId.pathSegments; final productionDependency = segments.length > 1 && _productionDirectories.contains(segments.first); - final resource = await buildStep.fetchResource( - productionDependency - ? _productionDependencyCheckResource - : _developmentDependencyCheckResource, - ); - - final errorMessage = await resource.run(buildStep); - - if (errorMessage == null) return; + final resource = + productionDependency ? _productionDependency : _developmentDependency; - throw BadPackageDependencyError(errorMessage); + await resource.run(buildStep); } -final _productionDependencyCheckResource = - _OncePerBuild.resource<bool, String?>(true, _validatePubspec); +final _productionDependency = _OncePerBuild(true, _validatePubspec); -final _developmentDependencyCheckResource = - _OncePerBuild.resource<bool, String?>(false, _validatePubspec); +final _developmentDependency = _OncePerBuild(false, _validatePubspec); -Future<String?> _validatePubspec(bool production, BuildStep buildStep) async { +Future<void> _validatePubspec(bool production, BuildStep buildStep) async { final pubspecAssetId = AssetId(buildStep.inputId.package, 'pubspec.yaml'); if (!await buildStep.canRead(pubspecAssetId)) { @@ -44,7 +34,7 @@ Future<String?> _validatePubspec(bool production, BuildStep buildStep) async { 'Could not read the "pubspec.yaml` file associated with this package. ' 'Usage of package:$_annotationPkgName could not be verified.', ); - return null; + return; } Future<Pubspec> readPubspec(AssetId asset) async { @@ -54,10 +44,14 @@ Future<String?> _validatePubspec(bool production, BuildStep buildStep) async { final pubspec = await readPubspec(pubspecAssetId); - return _checkAnnotationConstraint( + final errorMessage = _checkAnnotationConstraint( pubspec, !production, ); + + if (errorMessage == null) return; + + throw BadPackageDependencyError(errorMessage); } String? _checkAnnotationConstraint( @@ -116,27 +110,18 @@ String? _checkAnnotationConstraint( return null; } -class _OncePerBuild<S, T> { - final S state; - final FutureOr<T> Function(S, BuildStep) _callback; - AsyncMemoizer<T>? _memo; +class _OncePerBuild { + final bool state; + final FutureOr<void> Function(bool, BuildStep) _callback; + bool _ran = false; - static Resource<_OncePerBuild<State, T>> resource<State, T>( - State state, - FutureOr<T> Function(State, BuildStep) callback, - ) => - Resource<_OncePerBuild<State, T>>( - () => _OncePerBuild._(state, callback), - dispose: (c) => c._dispose(), - ); + _OncePerBuild(this.state, this._callback); - _OncePerBuild._(this.state, this._callback); - - Future<T> run(BuildStep buildStep) => - (_memo ??= AsyncMemoizer()).runOnce(() => _callback(state, buildStep)); - - void _dispose() { - _memo = null; + Future<void> run(BuildStep buildStep) async { + if (!_ran) { + _ran = true; + await _callback(state, buildStep); + } } } From dab72b99073fe3c7eb84ad9c11f93d311129171d Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Thu, 14 Oct 2021 17:23:51 -0700 Subject: [PATCH 366/569] json_serializable: prepare for v6 release (#1010) --- json_serializable/CHANGELOG.md | 6 +++--- json_serializable/pubspec.yaml | 6 +----- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 446c07fdd..54ffda7c9 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,6 +1,6 @@ -## 6.0.0-dev +## 6.0.0 -- Added support for `JsonSerializabel.constructor` to allow specifying an +- Added support for `JsonSerializable.constructor` to allow specifying an alternative constructor to invoke when creating a `fromJson` helper. - Support the new `@JsonEnum` annotation in `package:json_annotation`. - Support `JsonKey.nullForUndefinedEnumValue` as a value for @@ -12,7 +12,7 @@ - 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.2.0 <4.3.0'`. +- Require `json_annotation` `'>=4.3.0 <4.4.0'`. ## 5.0.2 diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index b99391d97..6a345b4a6 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 6.0.0-dev +version: 6.0.0 description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. @@ -35,7 +35,3 @@ dev_dependencies: test_descriptor: ^2.0.0 test_process: ^2.0.0 yaml: ^3.0.0 - -dependency_overrides: - json_annotation: - path: ../json_annotation From 6c50dee067b4716a9e28be4ad54bb1f639a30ce5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 22 Oct 2021 12:22:54 -0700 Subject: [PATCH 367/569] Bump actions/checkout from 2.3.4 to 2.3.5 (#1013) Bumps [actions/checkout](https://github.com/actions/checkout) from 2.3.4 to 2.3.5. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v2.3.4...v2.3.5) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/dart.yml | 36 +++++++++++++-------------- .github/workflows/markdown_linter.yml | 4 +-- tool/ci.sh | 2 +- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 2618b4fd0..862f0916e 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -1,4 +1,4 @@ -# Created with package:mono_repo v5.0.3 +# Created with package:mono_repo v5.0.4 name: Dart CI on: push: @@ -31,9 +31,9 @@ jobs: with: sdk: stable - id: checkout - uses: actions/checkout@v2.3.4 + uses: actions/checkout@v2.3.5 - name: mono_repo self validate - run: dart pub global activate mono_repo 5.0.3 + run: dart pub global activate mono_repo 5.0.4 - name: mono_repo self validate run: dart pub global run mono_repo generate --validate job_002: @@ -54,7 +54,7 @@ jobs: with: sdk: "2.12.0" - id: checkout - uses: actions/checkout@v2.3.4 + uses: actions/checkout@v2.3.5 - id: checked_yaml_pub_upgrade name: checked_yaml; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -99,7 +99,7 @@ jobs: with: sdk: "2.14.0" - id: checkout - uses: actions/checkout@v2.3.4 + uses: actions/checkout@v2.3.5 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -157,7 +157,7 @@ jobs: with: sdk: dev - id: checkout - uses: actions/checkout@v2.3.4 + uses: actions/checkout@v2.3.5 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -241,7 +241,7 @@ jobs: with: sdk: "2.12.0" - id: checkout - uses: actions/checkout@v2.3.4 + uses: actions/checkout@v2.3.5 - id: checked_yaml_pub_upgrade name: checked_yaml; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -283,7 +283,7 @@ jobs: with: sdk: "2.14.0" - id: checkout - uses: actions/checkout@v2.3.4 + uses: actions/checkout@v2.3.5 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -325,7 +325,7 @@ jobs: with: sdk: "2.14.0" - id: checkout - uses: actions/checkout@v2.3.4 + uses: actions/checkout@v2.3.5 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -358,7 +358,7 @@ jobs: with: sdk: "2.14.0" - id: checkout - uses: actions/checkout@v2.3.4 + uses: actions/checkout@v2.3.5 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -391,7 +391,7 @@ jobs: with: sdk: "2.14.0" - id: checkout - uses: actions/checkout@v2.3.4 + uses: actions/checkout@v2.3.5 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -424,7 +424,7 @@ jobs: with: sdk: dev - id: checkout - uses: actions/checkout@v2.3.4 + uses: actions/checkout@v2.3.5 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -484,7 +484,7 @@ jobs: with: sdk: dev - id: checkout - uses: actions/checkout@v2.3.4 + uses: actions/checkout@v2.3.5 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -517,7 +517,7 @@ jobs: with: sdk: dev - id: checkout - uses: actions/checkout@v2.3.4 + uses: actions/checkout@v2.3.5 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -550,7 +550,7 @@ jobs: with: sdk: dev - id: checkout - uses: actions/checkout@v2.3.4 + uses: actions/checkout@v2.3.5 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -583,7 +583,7 @@ jobs: with: sdk: "2.12.0" - id: checkout - uses: actions/checkout@v2.3.4 + uses: actions/checkout@v2.3.5 - id: checked_yaml_pub_upgrade name: checked_yaml; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -634,7 +634,7 @@ jobs: with: sdk: "2.14.0" - id: checkout - uses: actions/checkout@v2.3.4 + uses: actions/checkout@v2.3.5 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -676,7 +676,7 @@ jobs: with: sdk: dev - id: checkout - uses: actions/checkout@v2.3.4 + uses: actions/checkout@v2.3.5 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" diff --git a/.github/workflows/markdown_linter.yml b/.github/workflows/markdown_linter.yml index 2526d4c7c..f5ac406d6 100644 --- a/.github/workflows/markdown_linter.yml +++ b/.github/workflows/markdown_linter.yml @@ -11,7 +11,7 @@ jobs: markdown-link-check: runs-on: ubuntu-latest steps: - - uses: actions/checkout@master + - uses: actions/checkout@v2.3.5 - uses: gaurav-nelson/github-action-markdown-link-check@v1 markdown_lint: runs-on: ubuntu-latest @@ -19,7 +19,7 @@ jobs: matrix: node-version: [ 14.x ] steps: - - uses: actions/checkout@master + - uses: actions/checkout@v2.3.5 - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v2.4.1 with: diff --git a/tool/ci.sh b/tool/ci.sh index edd653f85..747f00558 100755 --- a/tool/ci.sh +++ b/tool/ci.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Created with package:mono_repo v5.0.3 +# Created with package:mono_repo v5.0.4 # Support built in commands on windows out of the box. # When it is a flutter repo (check the pubspec.yaml for "sdk: flutter") From b119ac76af77defb5a483f5c89a12a739e4d82bc Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@google.com> Date: Fri, 22 Oct 2021 13:13:33 -0700 Subject: [PATCH 368/569] skip browser tests --- .github/workflows/dart.yml | 86 +++------------------------------ json_serializable/mono_pkg.yaml | 3 +- tool/ci.sh | 4 -- 3 files changed, 9 insertions(+), 84 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 862f0916e..b1f6f71ad 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -315,7 +315,7 @@ jobs: uses: actions/cache@v2.1.6 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;dart:2.14.0;packages:json_serializable;commands:test_3" + key: "os:ubuntu-latest;pub-cache-hosted;dart:2.14.0;packages:json_serializable;commands:test_2" restore-keys: | os:ubuntu-latest;pub-cache-hosted;dart:2.14.0;packages:json_serializable os:ubuntu-latest;pub-cache-hosted;dart:2.14.0 @@ -374,39 +374,6 @@ jobs: - job_003 - job_004 job_009: - name: "unit_test; Dart 2.14.0; PKG: json_serializable; `dart test -p chrome`" - runs-on: ubuntu-latest - steps: - - name: Cache Pub hosted dependencies - uses: actions/cache@v2.1.6 - with: - path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;dart:2.14.0;packages:json_serializable;commands:test_2" - restore-keys: | - os:ubuntu-latest;pub-cache-hosted;dart:2.14.0;packages:json_serializable - os:ubuntu-latest;pub-cache-hosted;dart:2.14.0 - os:ubuntu-latest;pub-cache-hosted - os:ubuntu-latest - - uses: dart-lang/setup-dart@v1.3 - with: - sdk: "2.14.0" - - id: checkout - uses: actions/checkout@v2.3.5 - - id: json_serializable_pub_upgrade - name: json_serializable; dart pub upgrade - if: "always() && steps.checkout.conclusion == 'success'" - working-directory: json_serializable - run: dart pub upgrade - - name: "json_serializable; dart test -p chrome" - if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" - working-directory: json_serializable - run: dart test -p chrome - needs: - - job_001 - - job_002 - - job_003 - - job_004 - job_010: name: "unit_test; Dart dev; PKGS: _test_yaml, checked_yaml, example, json_serializable; `dart test`" runs-on: ubuntu-latest steps: @@ -466,7 +433,7 @@ jobs: - job_002 - job_003 - job_004 - job_011: + job_010: name: "unit_test; Dart dev; PKG: json_serializable; `dart test --run-skipped -t presubmit-only test/annotation_version_test.dart`" runs-on: ubuntu-latest steps: @@ -474,7 +441,7 @@ jobs: uses: actions/cache@v2.1.6 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:json_serializable;commands:test_3" + key: "os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:json_serializable;commands:test_2" restore-keys: | os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:json_serializable os:ubuntu-latest;pub-cache-hosted;dart:dev @@ -499,7 +466,7 @@ jobs: - job_002 - job_003 - job_004 - job_012: + job_011: name: "unit_test; Dart dev; PKG: json_serializable; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest steps: @@ -532,40 +499,7 @@ jobs: - job_002 - job_003 - job_004 - job_013: - name: "unit_test; Dart dev; PKG: json_serializable; `dart test -p chrome`" - runs-on: ubuntu-latest - steps: - - name: Cache Pub hosted dependencies - uses: actions/cache@v2.1.6 - with: - path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:json_serializable;commands:test_2" - restore-keys: | - os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:json_serializable - os:ubuntu-latest;pub-cache-hosted;dart:dev - os:ubuntu-latest;pub-cache-hosted - os:ubuntu-latest - - uses: dart-lang/setup-dart@v1.3 - with: - sdk: dev - - id: checkout - uses: actions/checkout@v2.3.5 - - id: json_serializable_pub_upgrade - name: json_serializable; dart pub upgrade - if: "always() && steps.checkout.conclusion == 'success'" - working-directory: json_serializable - run: dart pub upgrade - - name: "json_serializable; dart test -p chrome" - if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" - working-directory: json_serializable - run: dart test -p chrome - needs: - - job_001 - - job_002 - - job_003 - - job_004 - job_014: + job_012: name: "ensure_build; Dart 2.12.0; PKGS: checked_yaml, example; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest steps: @@ -614,9 +548,7 @@ jobs: - job_009 - job_010 - job_011 - - job_012 - - job_013 - job_015: + job_013: name: "ensure_build; Dart 2.14.0; PKG: _test_yaml; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest steps: @@ -656,9 +588,7 @@ jobs: - job_009 - job_010 - job_011 - - job_012 - - job_013 - job_016: + job_014: name: "ensure_build; Dart dev; PKGS: _test_yaml, checked_yaml, example; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest steps: @@ -716,5 +646,3 @@ jobs: - job_009 - job_010 - job_011 - - job_012 - - job_013 diff --git a/json_serializable/mono_pkg.yaml b/json_serializable/mono_pkg.yaml index fbc055781..4a0f72d92 100644 --- a/json_serializable/mono_pkg.yaml +++ b/json_serializable/mono_pkg.yaml @@ -10,7 +10,8 @@ stages: - analyze: --fatal-infos . - unit_test: - test: - - test: -p chrome + # Skip browser tests - hitting https://github.com/dart-lang/test/issues/1610 + #- test: -p chrome - test: --run-skipped -t presubmit-only test/annotation_version_test.dart - test: --run-skipped -t presubmit-only test/ensure_build_test.dart diff --git a/tool/ci.sh b/tool/ci.sh index 747f00558..91c7ba137 100755 --- a/tool/ci.sh +++ b/tool/ci.sh @@ -84,10 +84,6 @@ for PKG in ${PKGS}; do dart test --run-skipped -t presubmit-only test/ensure_build_test.dart || EXIT_CODE=$? ;; test_2) - echo 'dart test -p chrome' - dart test -p chrome || EXIT_CODE=$? - ;; - test_3) echo 'dart test --run-skipped -t presubmit-only test/annotation_version_test.dart' dart test --run-skipped -t presubmit-only test/annotation_version_test.dart || EXIT_CODE=$? ;; From 94d419c72cfdc94f6c10fe8d0d5454471091eb2a Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@google.com> Date: Fri, 22 Oct 2021 12:25:38 -0700 Subject: [PATCH 369/569] Update example and checked_yaml to latest json_serializable --- .github/workflows/dart.yml | 194 ++++++++++------------------------ checked_yaml/CHANGELOG.md | 3 + checked_yaml/mono_pkg.yaml | 2 +- checked_yaml/pubspec.yaml | 6 +- example/README.md | 4 +- example/mono_pkg.yaml | 2 +- example/pubspec.yaml | 6 +- example/test/readme_test.dart | 4 +- 8 files changed, 70 insertions(+), 151 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index b1f6f71ad..453971bd8 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -37,24 +37,37 @@ jobs: - name: mono_repo self validate run: dart pub global run mono_repo generate --validate job_002: - name: "analyzer_and_format; Dart 2.12.0; PKGS: checked_yaml, example; `dart format --output=none --set-exit-if-changed .`, `dart analyze --fatal-infos .`" + name: "analyzer_and_format; Dart 2.14.0; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; `dart format --output=none --set-exit-if-changed .`, `dart analyze --fatal-infos .`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@v2.1.6 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:checked_yaml-example;commands:format-analyze" + key: "os:ubuntu-latest;pub-cache-hosted;dart:2.14.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:format-analyze" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:checked_yaml-example - os:ubuntu-latest;pub-cache-hosted;dart:2.12.0 + os:ubuntu-latest;pub-cache-hosted;dart:2.14.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable + os:ubuntu-latest;pub-cache-hosted;dart:2.14.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - uses: dart-lang/setup-dart@v1.3 with: - sdk: "2.12.0" + sdk: "2.14.0" - id: checkout uses: actions/checkout@v2.3.5 + - id: _test_yaml_pub_upgrade + name: _test_yaml; dart pub upgrade + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: _test_yaml + run: dart pub upgrade + - name: "_test_yaml; dart format --output=none --set-exit-if-changed ." + if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" + working-directory: _test_yaml + run: "dart format --output=none --set-exit-if-changed ." + - name: "_test_yaml; dart analyze --fatal-infos ." + if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" + working-directory: _test_yaml + run: dart analyze --fatal-infos . - id: checked_yaml_pub_upgrade name: checked_yaml; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -81,38 +94,6 @@ jobs: if: "always() && steps.example_pub_upgrade.conclusion == 'success'" working-directory: example run: dart analyze --fatal-infos . - job_003: - name: "analyzer_and_format; Dart 2.14.0; PKGS: _test_yaml, json_annotation, json_serializable; `dart format --output=none --set-exit-if-changed .`, `dart analyze --fatal-infos .`" - runs-on: ubuntu-latest - steps: - - name: Cache Pub hosted dependencies - uses: actions/cache@v2.1.6 - with: - path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;dart:2.14.0;packages:_test_yaml-json_annotation-json_serializable;commands:format-analyze" - restore-keys: | - os:ubuntu-latest;pub-cache-hosted;dart:2.14.0;packages:_test_yaml-json_annotation-json_serializable - os:ubuntu-latest;pub-cache-hosted;dart:2.14.0 - os:ubuntu-latest;pub-cache-hosted - os:ubuntu-latest - - uses: dart-lang/setup-dart@v1.3 - with: - sdk: "2.14.0" - - id: checkout - uses: actions/checkout@v2.3.5 - - id: _test_yaml_pub_upgrade - name: _test_yaml; dart pub upgrade - if: "always() && steps.checkout.conclusion == 'success'" - working-directory: _test_yaml - run: dart pub upgrade - - name: "_test_yaml; dart format --output=none --set-exit-if-changed ." - if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" - working-directory: _test_yaml - run: "dart format --output=none --set-exit-if-changed ." - - name: "_test_yaml; dart analyze --fatal-infos ." - if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" - working-directory: _test_yaml - run: dart analyze --fatal-infos . - id: json_annotation_pub_upgrade name: json_annotation; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -139,7 +120,7 @@ jobs: if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" working-directory: json_serializable run: dart analyze --fatal-infos . - job_004: + job_003: name: "analyzer_and_format; Dart dev; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; `dart format --output=none --set-exit-if-changed .`, `dart analyze --fatal-infos .`" runs-on: ubuntu-latest steps: @@ -223,25 +204,34 @@ jobs: if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" working-directory: json_serializable run: dart analyze --fatal-infos . - job_005: - name: "unit_test; Dart 2.12.0; PKGS: checked_yaml, example; `dart test`" + job_004: + name: "unit_test; Dart 2.14.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; `dart test`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@v2.1.6 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:checked_yaml-example;commands:test_0" + key: "os:ubuntu-latest;pub-cache-hosted;dart:2.14.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:checked_yaml-example - os:ubuntu-latest;pub-cache-hosted;dart:2.12.0 + os:ubuntu-latest;pub-cache-hosted;dart:2.14.0;packages:_test_yaml-checked_yaml-example-json_serializable + os:ubuntu-latest;pub-cache-hosted;dart:2.14.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - uses: dart-lang/setup-dart@v1.3 with: - sdk: "2.12.0" + sdk: "2.14.0" - id: checkout uses: actions/checkout@v2.3.5 + - id: _test_yaml_pub_upgrade + name: _test_yaml; dart pub upgrade + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: _test_yaml + run: dart pub upgrade + - name: _test_yaml; dart test + if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" + working-directory: _test_yaml + run: dart test - id: checked_yaml_pub_upgrade name: checked_yaml; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -260,39 +250,6 @@ jobs: if: "always() && steps.example_pub_upgrade.conclusion == 'success'" working-directory: example run: dart test - needs: - - job_001 - - job_002 - - job_003 - - job_004 - job_006: - name: "unit_test; Dart 2.14.0; PKGS: _test_yaml, json_serializable; `dart test`" - runs-on: ubuntu-latest - steps: - - name: Cache Pub hosted dependencies - uses: actions/cache@v2.1.6 - with: - path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;dart:2.14.0;packages:_test_yaml-json_serializable;commands:test_0" - restore-keys: | - os:ubuntu-latest;pub-cache-hosted;dart:2.14.0;packages:_test_yaml-json_serializable - os:ubuntu-latest;pub-cache-hosted;dart:2.14.0 - os:ubuntu-latest;pub-cache-hosted - os:ubuntu-latest - - uses: dart-lang/setup-dart@v1.3 - with: - sdk: "2.14.0" - - id: checkout - uses: actions/checkout@v2.3.5 - - id: _test_yaml_pub_upgrade - name: _test_yaml; dart pub upgrade - if: "always() && steps.checkout.conclusion == 'success'" - working-directory: _test_yaml - run: dart pub upgrade - - name: _test_yaml; dart test - if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" - working-directory: _test_yaml - run: dart test - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -306,8 +263,7 @@ jobs: - job_001 - job_002 - job_003 - - job_004 - job_007: + job_005: name: "unit_test; Dart 2.14.0; PKG: json_serializable; `dart test --run-skipped -t presubmit-only test/annotation_version_test.dart`" runs-on: ubuntu-latest steps: @@ -339,8 +295,7 @@ jobs: - job_001 - job_002 - job_003 - - job_004 - job_008: + job_006: name: "unit_test; Dart 2.14.0; PKG: json_serializable; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest steps: @@ -372,8 +327,7 @@ jobs: - job_001 - job_002 - job_003 - - job_004 - job_009: + job_007: name: "unit_test; Dart dev; PKGS: _test_yaml, checked_yaml, example, json_serializable; `dart test`" runs-on: ubuntu-latest steps: @@ -432,8 +386,7 @@ jobs: - job_001 - job_002 - job_003 - - job_004 - job_010: + job_008: name: "unit_test; Dart dev; PKG: json_serializable; `dart test --run-skipped -t presubmit-only test/annotation_version_test.dart`" runs-on: ubuntu-latest steps: @@ -465,8 +418,7 @@ jobs: - job_001 - job_002 - job_003 - - job_004 - job_011: + job_009: name: "unit_test; Dart dev; PKG: json_serializable; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest steps: @@ -498,26 +450,34 @@ jobs: - job_001 - job_002 - job_003 - - job_004 - job_012: - name: "ensure_build; Dart 2.12.0; PKGS: checked_yaml, example; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" + job_010: + name: "ensure_build; Dart 2.14.0; PKGS: _test_yaml, checked_yaml, example; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@v2.1.6 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:checked_yaml-example;commands:test_1" + key: "os:ubuntu-latest;pub-cache-hosted;dart:2.14.0;packages:_test_yaml-checked_yaml-example;commands:test_1" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:checked_yaml-example - os:ubuntu-latest;pub-cache-hosted;dart:2.12.0 + os:ubuntu-latest;pub-cache-hosted;dart:2.14.0;packages:_test_yaml-checked_yaml-example + os:ubuntu-latest;pub-cache-hosted;dart:2.14.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - uses: dart-lang/setup-dart@v1.3 with: - sdk: "2.12.0" + sdk: "2.14.0" - id: checkout uses: actions/checkout@v2.3.5 + - id: _test_yaml_pub_upgrade + name: _test_yaml; dart pub upgrade + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: _test_yaml + run: dart pub upgrade + - name: "_test_yaml; dart test --run-skipped -t presubmit-only test/ensure_build_test.dart" + if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" + working-directory: _test_yaml + run: dart test --run-skipped -t presubmit-only test/ensure_build_test.dart - id: checked_yaml_pub_upgrade name: checked_yaml; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -546,49 +506,7 @@ jobs: - job_007 - job_008 - job_009 - - job_010 - - job_011 - job_013: - name: "ensure_build; Dart 2.14.0; PKG: _test_yaml; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" - runs-on: ubuntu-latest - steps: - - name: Cache Pub hosted dependencies - uses: actions/cache@v2.1.6 - with: - path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;dart:2.14.0;packages:_test_yaml;commands:test_1" - restore-keys: | - os:ubuntu-latest;pub-cache-hosted;dart:2.14.0;packages:_test_yaml - os:ubuntu-latest;pub-cache-hosted;dart:2.14.0 - os:ubuntu-latest;pub-cache-hosted - os:ubuntu-latest - - uses: dart-lang/setup-dart@v1.3 - with: - sdk: "2.14.0" - - id: checkout - uses: actions/checkout@v2.3.5 - - id: _test_yaml_pub_upgrade - name: _test_yaml; dart pub upgrade - if: "always() && steps.checkout.conclusion == 'success'" - working-directory: _test_yaml - run: dart pub upgrade - - name: "_test_yaml; dart test --run-skipped -t presubmit-only test/ensure_build_test.dart" - if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" - working-directory: _test_yaml - run: dart test --run-skipped -t presubmit-only test/ensure_build_test.dart - needs: - - job_001 - - job_002 - - job_003 - - job_004 - - job_005 - - job_006 - - job_007 - - job_008 - - job_009 - - job_010 - - job_011 - job_014: + job_011: name: "ensure_build; Dart dev; PKGS: _test_yaml, checked_yaml, example; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest steps: @@ -644,5 +562,3 @@ jobs: - job_007 - job_008 - job_009 - - job_010 - - job_011 diff --git a/checked_yaml/CHANGELOG.md b/checked_yaml/CHANGELOG.md index 9dd60ee08..019af44b4 100644 --- a/checked_yaml/CHANGELOG.md +++ b/checked_yaml/CHANGELOG.md @@ -1,5 +1,8 @@ ## 2.0.2-dev +- Require `json_annotation` `^4.3.0` +- Require Dart SDK `>=2.14` + ## 2.0.1 - If `CheckedFromJsonException` is caught for a key missing in the source map, diff --git a/checked_yaml/mono_pkg.yaml b/checked_yaml/mono_pkg.yaml index e83d7d1dc..133bdf513 100644 --- a/checked_yaml/mono_pkg.yaml +++ b/checked_yaml/mono_pkg.yaml @@ -1,6 +1,6 @@ # See https://github.com/google/mono_repo.dart for details on this file dart: -- 2.12.0 +- 2.14.0 - dev stages: diff --git a/checked_yaml/pubspec.yaml b/checked_yaml/pubspec.yaml index f5495c10f..f41bdc1d0 100644 --- a/checked_yaml/pubspec.yaml +++ b/checked_yaml/pubspec.yaml @@ -6,17 +6,17 @@ description: >- package:json_serializable and package:yaml. repository: https://github.com/google/json_serializable.dart/tree/master/checked_yaml environment: - sdk: '>=2.12.0 <3.0.0' + sdk: '>=2.14.0 <3.0.0' dependencies: - json_annotation: ^4.1.0 + json_annotation: ^4.3.0 source_span: ^1.8.0 yaml: ^3.0.0 dev_dependencies: build_runner: ^2.0.0 build_verify: ^2.0.0 - json_serializable: ^5.0.0 + json_serializable: ^6.0.0 path: ^1.0.0 test: ^1.16.0 test_process: ^2.0.0 diff --git a/example/README.md b/example/README.md index 658af7ac8..b3228f743 100644 --- a/example/README.md +++ b/example/README.md @@ -5,11 +5,11 @@ dependencies to your `pubspec.yaml`. ```yaml dependencies: - json_annotation: ^4.1.0 + json_annotation: ^4.3.0 dev_dependencies: build_runner: ^2.0.0 - json_serializable: ^5.0.0 + json_serializable: ^6.0.0 ``` Annotate your code with classes defined in diff --git a/example/mono_pkg.yaml b/example/mono_pkg.yaml index f3afd8417..06efa807f 100644 --- a/example/mono_pkg.yaml +++ b/example/mono_pkg.yaml @@ -1,6 +1,6 @@ # See https://github.com/google/mono_repo.dart for details on this file dart: -- 2.12.0 +- 2.14.0 - dev stages: diff --git a/example/pubspec.yaml b/example/pubspec.yaml index c9ac80f88..fd2b789bf 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -2,10 +2,10 @@ name: example publish_to: none environment: - sdk: '>=2.12.0 <3.0.0' + sdk: '>=2.14.0 <3.0.0' dependencies: - json_annotation: ^4.1.0 + json_annotation: ^4.3.0 dev_dependencies: build_runner: ^2.0.0 @@ -13,7 +13,7 @@ dev_dependencies: # Used by tests. Not required to use `json_serializable`. build_verify: ^2.0.0 - json_serializable: ^5.0.0 + json_serializable: ^6.0.0 # Used by tests. Not required to use `json_serializable`. path: ^1.8.0 diff --git a/example/test/readme_test.dart b/example/test/readme_test.dart index ab92b477d..f17ceaad2 100644 --- a/example/test/readme_test.dart +++ b/example/test/readme_test.dart @@ -25,9 +25,9 @@ void _expect(String fileName) { const _pubspecContent = r''' dependencies: - json_annotation: ^4.1.0 + json_annotation: ^4.3.0 dev_dependencies: build_runner: ^2.0.0 - json_serializable: ^5.0.0 + json_serializable: ^6.0.0 '''; From db1d692483ee0e82c828741f4c44946a51393673 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@google.com> Date: Fri, 22 Oct 2021 13:10:47 -0700 Subject: [PATCH 370/569] Don't require json_annotation in dependencies if it's just used in tests Fixes https://github.com/google/json_serializable.dart/issues/1014 Prepare to release v6.0.1 --- json_serializable/CHANGELOG.md | 4 +++ .../lib/src/json_part_builder.dart | 4 +-- json_serializable/pubspec.yaml | 2 +- .../test/annotation_version_test.dart | 31 ++++++++++++------- 4 files changed, 27 insertions(+), 14 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 54ffda7c9..45200e39a 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,7 @@ +## 6.0.1 + +- Don't require `json_annotation` in `dependencies` if it's just used in tests. + ## 6.0.0 - Added support for `JsonSerializable.constructor` to allow specifying an diff --git a/json_serializable/lib/src/json_part_builder.dart b/json_serializable/lib/src/json_part_builder.dart index 832c2fbd5..17e2c7fb6 100644 --- a/json_serializable/lib/src/json_part_builder.dart +++ b/json_serializable/lib/src/json_part_builder.dart @@ -52,13 +52,13 @@ class _UnifiedGenerator extends Generator { @override Future<String?> generate(LibraryReader library, BuildStep buildStep) async { - await pubspecHasRightVersion(buildStep); - final values = <String>{}; for (var generator in _generators) { for (var annotatedElement in library.annotatedWith(generator.typeChecker)) { + await pubspecHasRightVersion(buildStep); + final generatedValue = generator.generateForAnnotatedElement( annotatedElement.element, annotatedElement.annotation, buildStep); for (var value in _normalizeGeneratorOutput(generatedValue)) { diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 6a345b4a6..2e31342cb 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 6.0.0 +version: 6.0.1 description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. diff --git a/json_serializable/test/annotation_version_test.dart b/json_serializable/test/annotation_version_test.dart index efbc70fdc..1ba895866 100644 --- a/json_serializable/test/annotation_version_test.dart +++ b/json_serializable/test/annotation_version_test.dart @@ -132,6 +132,16 @@ Future<void> _structurePackage({ await d.file('pubspec.yaml', pubspec).create(); + /// A file in the lib directory without JsonSerializable should do nothing! + await d.dir( + 'lib', + [ + d.file('no_op.dart', ''' +class NoOp {} +''') + ], + ).create(); + await d.dir( sourceDirectory, [ @@ -155,18 +165,17 @@ class SomeClass{} workingDirectory: d.sandbox, ); - await proc.stdoutStream().forEach(print); + final lines = StringBuffer(); + await for (var line in proc.stdoutStream()) { + lines.writeln(line); + print(line); + } - await expectLater( - proc.stdout, - emitsThrough( - emitsInOrder([ - '[SEVERE] json_serializable:json_serializable on $sourceDirectory/sample.dart:', - '', - message, - ]), - ), - ); + expect(lines.toString(), contains(''' +[SEVERE] json_serializable:json_serializable on $sourceDirectory/sample.dart: + +$message +''')); await proc.shouldExit(1); } From a81ddd1f2d74150cf2e4ef3ba0af5ebf39de975f Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Mon, 25 Oct 2021 09:56:04 -0700 Subject: [PATCH 371/569] Reenable browser tests (#1016) --- .github/workflows/dart.yml | 80 ++++++++++++++++++++++++++++++--- json_serializable/mono_pkg.yaml | 3 +- tool/ci.sh | 4 ++ 3 files changed, 79 insertions(+), 8 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 453971bd8..e1fbc4f68 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -271,7 +271,7 @@ jobs: uses: actions/cache@v2.1.6 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;dart:2.14.0;packages:json_serializable;commands:test_2" + key: "os:ubuntu-latest;pub-cache-hosted;dart:2.14.0;packages:json_serializable;commands:test_3" restore-keys: | os:ubuntu-latest;pub-cache-hosted;dart:2.14.0;packages:json_serializable os:ubuntu-latest;pub-cache-hosted;dart:2.14.0 @@ -328,6 +328,38 @@ jobs: - job_002 - job_003 job_007: + name: "unit_test; Dart 2.14.0; PKG: json_serializable; `dart test -p chrome`" + runs-on: ubuntu-latest + steps: + - name: Cache Pub hosted dependencies + uses: actions/cache@v2.1.6 + with: + path: "~/.pub-cache/hosted" + key: "os:ubuntu-latest;pub-cache-hosted;dart:2.14.0;packages:json_serializable;commands:test_2" + restore-keys: | + os:ubuntu-latest;pub-cache-hosted;dart:2.14.0;packages:json_serializable + os:ubuntu-latest;pub-cache-hosted;dart:2.14.0 + os:ubuntu-latest;pub-cache-hosted + os:ubuntu-latest + - uses: dart-lang/setup-dart@v1.3 + with: + sdk: "2.14.0" + - id: checkout + uses: actions/checkout@v2.3.5 + - id: json_serializable_pub_upgrade + name: json_serializable; dart pub upgrade + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: json_serializable + run: dart pub upgrade + - name: "json_serializable; dart test -p chrome" + if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" + working-directory: json_serializable + run: dart test -p chrome + needs: + - job_001 + - job_002 + - job_003 + job_008: name: "unit_test; Dart dev; PKGS: _test_yaml, checked_yaml, example, json_serializable; `dart test`" runs-on: ubuntu-latest steps: @@ -386,7 +418,7 @@ jobs: - job_001 - job_002 - job_003 - job_008: + job_009: name: "unit_test; Dart dev; PKG: json_serializable; `dart test --run-skipped -t presubmit-only test/annotation_version_test.dart`" runs-on: ubuntu-latest steps: @@ -394,7 +426,7 @@ jobs: uses: actions/cache@v2.1.6 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:json_serializable;commands:test_2" + key: "os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:json_serializable;commands:test_3" restore-keys: | os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:json_serializable os:ubuntu-latest;pub-cache-hosted;dart:dev @@ -418,7 +450,7 @@ jobs: - job_001 - job_002 - job_003 - job_009: + job_010: name: "unit_test; Dart dev; PKG: json_serializable; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest steps: @@ -450,7 +482,39 @@ jobs: - job_001 - job_002 - job_003 - job_010: + job_011: + name: "unit_test; Dart dev; PKG: json_serializable; `dart test -p chrome`" + runs-on: ubuntu-latest + steps: + - name: Cache Pub hosted dependencies + uses: actions/cache@v2.1.6 + with: + path: "~/.pub-cache/hosted" + key: "os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:json_serializable;commands:test_2" + restore-keys: | + os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:json_serializable + os:ubuntu-latest;pub-cache-hosted;dart:dev + os:ubuntu-latest;pub-cache-hosted + os:ubuntu-latest + - uses: dart-lang/setup-dart@v1.3 + with: + sdk: dev + - id: checkout + uses: actions/checkout@v2.3.5 + - id: json_serializable_pub_upgrade + name: json_serializable; dart pub upgrade + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: json_serializable + run: dart pub upgrade + - name: "json_serializable; dart test -p chrome" + if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" + working-directory: json_serializable + run: dart test -p chrome + needs: + - job_001 + - job_002 + - job_003 + job_012: name: "ensure_build; Dart 2.14.0; PKGS: _test_yaml, checked_yaml, example; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest steps: @@ -506,7 +570,9 @@ jobs: - job_007 - job_008 - job_009 - job_011: + - job_010 + - job_011 + job_013: name: "ensure_build; Dart dev; PKGS: _test_yaml, checked_yaml, example; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest steps: @@ -562,3 +628,5 @@ jobs: - job_007 - job_008 - job_009 + - job_010 + - job_011 diff --git a/json_serializable/mono_pkg.yaml b/json_serializable/mono_pkg.yaml index 4a0f72d92..fbc055781 100644 --- a/json_serializable/mono_pkg.yaml +++ b/json_serializable/mono_pkg.yaml @@ -10,8 +10,7 @@ stages: - analyze: --fatal-infos . - unit_test: - test: - # Skip browser tests - hitting https://github.com/dart-lang/test/issues/1610 - #- test: -p chrome + - test: -p chrome - test: --run-skipped -t presubmit-only test/annotation_version_test.dart - test: --run-skipped -t presubmit-only test/ensure_build_test.dart diff --git a/tool/ci.sh b/tool/ci.sh index 91c7ba137..747f00558 100755 --- a/tool/ci.sh +++ b/tool/ci.sh @@ -84,6 +84,10 @@ for PKG in ${PKGS}; do dart test --run-skipped -t presubmit-only test/ensure_build_test.dart || EXIT_CODE=$? ;; test_2) + echo 'dart test -p chrome' + dart test -p chrome || EXIT_CODE=$? + ;; + test_3) echo 'dart test --run-skipped -t presubmit-only test/annotation_version_test.dart' dart test --run-skipped -t presubmit-only test/annotation_version_test.dart || EXIT_CODE=$? ;; From 8f73952059d9e0caaccfd418f71b4bb560d725e9 Mon Sep 17 00:00:00 2001 From: David Wimmer <david.wimmer@ffuf.de> Date: Fri, 12 Nov 2021 00:16:12 +0100 Subject: [PATCH 372/569] Update json_key_utils.dart (#1027) Only log a hint if defaultValue and ctorParamDefault are the same --- json_serializable/lib/src/json_key_utils.dart | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/json_serializable/lib/src/json_key_utils.dart b/json_serializable/lib/src/json_key_utils.dart index 65ea585db..4153e14be 100644 --- a/json_serializable/lib/src/json_key_utils.dart +++ b/json_serializable/lib/src/json_key_utils.dart @@ -194,12 +194,19 @@ KeyConfig _from(FieldElement element, ClassConfig classAnnotation) { final defaultValue = _annotationValue('defaultValue'); if (defaultValue != null && ctorParamDefault != null) { - log.warning( - 'The constructor parameter for `${element.name}` has a default value ' - '`$ctorParamDefault`, but the `JsonKey.defaultValue` value ' - '`$defaultValue` will be used for missing or `null` values in JSON ' - 'decoding.', - ); + if (defaultValue == ctorParamDefault) { + log.info( + 'The default value `$defaultValue` for `${element.name}` is defined ' + 'twice in the constructor and in the `JsonKey.defaultValue`.', + ); + } else { + log.warning( + 'The constructor parameter for `${element.name}` has a default value ' + '`$ctorParamDefault`, but the `JsonKey.defaultValue` value ' + '`$defaultValue` will be used for missing or `null` values in JSON ' + 'decoding.', + ); + } } return _populateJsonKey( From 1aab1ec1292ac2434e4f3edda0def8357b18c346 Mon Sep 17 00:00:00 2001 From: David Wimmer <david.wimmer@ffuf.de> Date: Sat, 13 Nov 2021 00:03:24 +0100 Subject: [PATCH 373/569] added test for SameCtorAndJsonKeyDefaultValue (#1028) --- .../test/json_serializable_test.dart | 1 + .../test/src/default_value_input.dart | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/json_serializable/test/json_serializable_test.dart b/json_serializable/test/json_serializable_test.dart index 9c8b2d46a..b95f6183b 100644 --- a/json_serializable/test/json_serializable_test.dart +++ b/json_serializable/test/json_serializable_test.dart @@ -44,6 +44,7 @@ const _expectedAnnotatedTests = { 'BadEnumDefaultValue', '_BetterPrivateNames', 'CtorDefaultValueAndJsonKeyDefaultValue', + 'SameCtorAndJsonKeyDefaultValue', 'DefaultDoubleConstants', 'DefaultWithConstObject', 'DefaultWithDisallowNullRequiredClass', diff --git a/json_serializable/test/src/default_value_input.dart b/json_serializable/test/src/default_value_input.dart index 7eb0ff7da..81540aa4a 100644 --- a/json_serializable/test/src/default_value_input.dart +++ b/json_serializable/test/src/default_value_input.dart @@ -156,6 +156,27 @@ class CtorDefaultValueAndJsonKeyDefaultValue { CtorDefaultValueAndJsonKeyDefaultValue([this.theField = 6]); } +@ShouldGenerate( + r''' +SameCtorAndJsonKeyDefaultValue _$SameCtorAndJsonKeyDefaultValueFromJson( + Map<String, dynamic> json) => + SameCtorAndJsonKeyDefaultValue( + json['theField'] as int? ?? 3, + ); +''', + expectedLogItems: [ + 'The default value `3` for `theField` is defined twice ' + 'in the constructor and in the `JsonKey.defaultValue`.', + ], +) +@JsonSerializable(createToJson: false) +class SameCtorAndJsonKeyDefaultValue { + @JsonKey(defaultValue: 3) + final int theField; + + SameCtorAndJsonKeyDefaultValue([this.theField = 3]); +} + @ShouldGenerate(r''' DefaultDoubleConstants _$DefaultDoubleConstantsFromJson( Map<String, dynamic> json) => From b7302caf49e922de2029e60b1376a32de51d34de Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Fri, 12 Nov 2021 15:25:08 -0800 Subject: [PATCH 374/569] Ignore text_direction_code_point_in_literal in generated code (#1030) --- json_serializable/build.yaml | 2 ++ json_serializable/example/example.g.dart | 2 +- json_serializable/test/default_value/default_value.g.dart | 2 +- .../test/default_value/default_value.g_any_map__checked.g.dart | 2 +- .../test/default_value/implicit_default_value.g.dart | 2 +- .../test/generic_files/generic_argument_factories.g.dart | 2 +- .../generic_files/generic_argument_factories_nullable.g.dart | 2 +- json_serializable/test/generic_files/generic_class.g.dart | 2 +- json_serializable/test/integration/json_enum_example.g.dart | 2 +- json_serializable/test/integration/json_test_example.g.dart | 2 +- .../test/integration/json_test_example.g_any_map.g.dart | 2 +- json_serializable/test/kitchen_sink/kitchen_sink.g.dart | 2 +- .../test/kitchen_sink/kitchen_sink.g_any_map.g.dart | 2 +- .../test/kitchen_sink/kitchen_sink.g_any_map__checked.g.dart | 2 +- .../test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart | 2 +- .../test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart | 2 +- json_serializable/test/kitchen_sink/simple_object.g.dart | 2 +- json_serializable/test/kitchen_sink/strict_keys_object.g.dart | 2 +- json_serializable/test/literal/json_literal.g.dart | 2 +- json_serializable/test/supported_types/input.g.dart | 2 +- json_serializable/test/supported_types/input.type_bigint.g.dart | 2 +- json_serializable/test/supported_types/input.type_bool.g.dart | 2 +- .../test/supported_types/input.type_datetime.g.dart | 2 +- json_serializable/test/supported_types/input.type_double.g.dart | 2 +- .../test/supported_types/input.type_duration.g.dart | 2 +- .../test/supported_types/input.type_enumtype.g.dart | 2 +- json_serializable/test/supported_types/input.type_int.g.dart | 2 +- .../test/supported_types/input.type_iterable.g.dart | 2 +- json_serializable/test/supported_types/input.type_list.g.dart | 2 +- json_serializable/test/supported_types/input.type_map.g.dart | 2 +- json_serializable/test/supported_types/input.type_num.g.dart | 2 +- json_serializable/test/supported_types/input.type_object.g.dart | 2 +- json_serializable/test/supported_types/input.type_set.g.dart | 2 +- json_serializable/test/supported_types/input.type_string.g.dart | 2 +- json_serializable/test/supported_types/input.type_uri.g.dart | 2 +- 35 files changed, 36 insertions(+), 34 deletions(-) diff --git a/json_serializable/build.yaml b/json_serializable/build.yaml index bc69e96d9..03933fb6e 100644 --- a/json_serializable/build.yaml +++ b/json_serializable/build.yaml @@ -6,6 +6,8 @@ targets: options: ignore_for_file: - lines_longer_than_80_chars + # Only for the JSON literal output file + - text_direction_code_point_in_literal json_serializable: generate_for: diff --git a/json_serializable/example/example.g.dart b/json_serializable/example/example.g.dart index 0db7c1d08..21820874c 100644 --- a/json_serializable/example/example.g.dart +++ b/json_serializable/example/example.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal part of 'example.dart'; diff --git a/json_serializable/test/default_value/default_value.g.dart b/json_serializable/test/default_value/default_value.g.dart index 8dc932408..a923dc624 100644 --- a/json_serializable/test/default_value/default_value.g.dart +++ b/json_serializable/test/default_value/default_value.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal part of 'default_value.dart'; diff --git a/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart b/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart index d1608ef2d..0004ac0bc 100644 --- a/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart +++ b/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal part of 'default_value.g_any_map__checked.dart'; diff --git a/json_serializable/test/default_value/implicit_default_value.g.dart b/json_serializable/test/default_value/implicit_default_value.g.dart index fe5d17283..5b92c2607 100644 --- a/json_serializable/test/default_value/implicit_default_value.g.dart +++ b/json_serializable/test/default_value/implicit_default_value.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal part of 'implicit_default_value.dart'; diff --git a/json_serializable/test/generic_files/generic_argument_factories.g.dart b/json_serializable/test/generic_files/generic_argument_factories.g.dart index 965996240..87755ac37 100644 --- a/json_serializable/test/generic_files/generic_argument_factories.g.dart +++ b/json_serializable/test/generic_files/generic_argument_factories.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal part of 'generic_argument_factories.dart'; diff --git a/json_serializable/test/generic_files/generic_argument_factories_nullable.g.dart b/json_serializable/test/generic_files/generic_argument_factories_nullable.g.dart index 93bde3ca0..3bf21b18c 100644 --- a/json_serializable/test/generic_files/generic_argument_factories_nullable.g.dart +++ b/json_serializable/test/generic_files/generic_argument_factories_nullable.g.dart @@ -1,7 +1,7 @@ // GENERATED CODE - DO NOT MODIFY BY HAND // @dart=2.12 -// ignore_for_file: lines_longer_than_80_chars +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal part of 'generic_argument_factories_nullable.dart'; diff --git a/json_serializable/test/generic_files/generic_class.g.dart b/json_serializable/test/generic_files/generic_class.g.dart index aa5f32e79..dd2bb6db8 100644 --- a/json_serializable/test/generic_files/generic_class.g.dart +++ b/json_serializable/test/generic_files/generic_class.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal part of 'generic_class.dart'; diff --git a/json_serializable/test/integration/json_enum_example.g.dart b/json_serializable/test/integration/json_enum_example.g.dart index c416d5540..a41a825af 100644 --- a/json_serializable/test/integration/json_enum_example.g.dart +++ b/json_serializable/test/integration/json_enum_example.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal part of 'json_enum_example.dart'; diff --git a/json_serializable/test/integration/json_test_example.g.dart b/json_serializable/test/integration/json_test_example.g.dart index a4a8172a1..b4ac755e8 100644 --- a/json_serializable/test/integration/json_test_example.g.dart +++ b/json_serializable/test/integration/json_test_example.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal part of 'json_test_example.dart'; diff --git a/json_serializable/test/integration/json_test_example.g_any_map.g.dart b/json_serializable/test/integration/json_test_example.g_any_map.g.dart index b25d890bb..cf1e068dd 100644 --- a/json_serializable/test/integration/json_test_example.g_any_map.g.dart +++ b/json_serializable/test/integration/json_test_example.g_any_map.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal part of 'json_test_example.g_any_map.dart'; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g.dart index 0b51b3fc7..393ccfedb 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal part of 'kitchen_sink.dart'; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart index b2c48bf02..6e80def06 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal part of 'kitchen_sink.g_any_map.dart'; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.g.dart index 20066ff54..61434b375 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal part of 'kitchen_sink.g_any_map__checked.dart'; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart index c7ef240b6..21e25bc02 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal part of 'kitchen_sink.g_exclude_null.dart'; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart index 36f94cadd..e6d447061 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal part of 'kitchen_sink.g_explicit_to_json.dart'; diff --git a/json_serializable/test/kitchen_sink/simple_object.g.dart b/json_serializable/test/kitchen_sink/simple_object.g.dart index 30c82ebfe..c18d4558c 100644 --- a/json_serializable/test/kitchen_sink/simple_object.g.dart +++ b/json_serializable/test/kitchen_sink/simple_object.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal part of 'simple_object.dart'; diff --git a/json_serializable/test/kitchen_sink/strict_keys_object.g.dart b/json_serializable/test/kitchen_sink/strict_keys_object.g.dart index e112c1444..b8dc65ec6 100644 --- a/json_serializable/test/kitchen_sink/strict_keys_object.g.dart +++ b/json_serializable/test/kitchen_sink/strict_keys_object.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal part of 'strict_keys_object.dart'; diff --git a/json_serializable/test/literal/json_literal.g.dart b/json_serializable/test/literal/json_literal.g.dart index 87f89f479..02294b603 100644 --- a/json_serializable/test/literal/json_literal.g.dart +++ b/json_serializable/test/literal/json_literal.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal part of 'json_literal.dart'; diff --git a/json_serializable/test/supported_types/input.g.dart b/json_serializable/test/supported_types/input.g.dart index 619612027..a07530cb6 100644 --- a/json_serializable/test/supported_types/input.g.dart +++ b/json_serializable/test/supported_types/input.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal part of 'input.dart'; diff --git a/json_serializable/test/supported_types/input.type_bigint.g.dart b/json_serializable/test/supported_types/input.type_bigint.g.dart index 16bb34ed8..9fe750fc1 100644 --- a/json_serializable/test/supported_types/input.type_bigint.g.dart +++ b/json_serializable/test/supported_types/input.type_bigint.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal part of 'input.type_bigint.dart'; diff --git a/json_serializable/test/supported_types/input.type_bool.g.dart b/json_serializable/test/supported_types/input.type_bool.g.dart index 9138ae273..7964a3a21 100644 --- a/json_serializable/test/supported_types/input.type_bool.g.dart +++ b/json_serializable/test/supported_types/input.type_bool.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal part of 'input.type_bool.dart'; diff --git a/json_serializable/test/supported_types/input.type_datetime.g.dart b/json_serializable/test/supported_types/input.type_datetime.g.dart index 2e2b0b6a0..f4873e041 100644 --- a/json_serializable/test/supported_types/input.type_datetime.g.dart +++ b/json_serializable/test/supported_types/input.type_datetime.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal part of 'input.type_datetime.dart'; diff --git a/json_serializable/test/supported_types/input.type_double.g.dart b/json_serializable/test/supported_types/input.type_double.g.dart index 0f7e12fdc..921716796 100644 --- a/json_serializable/test/supported_types/input.type_double.g.dart +++ b/json_serializable/test/supported_types/input.type_double.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal part of 'input.type_double.dart'; diff --git a/json_serializable/test/supported_types/input.type_duration.g.dart b/json_serializable/test/supported_types/input.type_duration.g.dart index b33f0e19f..cee2811f2 100644 --- a/json_serializable/test/supported_types/input.type_duration.g.dart +++ b/json_serializable/test/supported_types/input.type_duration.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal part of 'input.type_duration.dart'; diff --git a/json_serializable/test/supported_types/input.type_enumtype.g.dart b/json_serializable/test/supported_types/input.type_enumtype.g.dart index 931ddfc3e..6f8fa4a70 100644 --- a/json_serializable/test/supported_types/input.type_enumtype.g.dart +++ b/json_serializable/test/supported_types/input.type_enumtype.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal part of 'input.type_enumtype.dart'; diff --git a/json_serializable/test/supported_types/input.type_int.g.dart b/json_serializable/test/supported_types/input.type_int.g.dart index 3e6b3aa75..848d81cf1 100644 --- a/json_serializable/test/supported_types/input.type_int.g.dart +++ b/json_serializable/test/supported_types/input.type_int.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal part of 'input.type_int.dart'; diff --git a/json_serializable/test/supported_types/input.type_iterable.g.dart b/json_serializable/test/supported_types/input.type_iterable.g.dart index f312e76ba..388702120 100644 --- a/json_serializable/test/supported_types/input.type_iterable.g.dart +++ b/json_serializable/test/supported_types/input.type_iterable.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal part of 'input.type_iterable.dart'; diff --git a/json_serializable/test/supported_types/input.type_list.g.dart b/json_serializable/test/supported_types/input.type_list.g.dart index 36b9ad467..b20b902e4 100644 --- a/json_serializable/test/supported_types/input.type_list.g.dart +++ b/json_serializable/test/supported_types/input.type_list.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal part of 'input.type_list.dart'; diff --git a/json_serializable/test/supported_types/input.type_map.g.dart b/json_serializable/test/supported_types/input.type_map.g.dart index 0886e800a..3e78f5f8b 100644 --- a/json_serializable/test/supported_types/input.type_map.g.dart +++ b/json_serializable/test/supported_types/input.type_map.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal part of 'input.type_map.dart'; diff --git a/json_serializable/test/supported_types/input.type_num.g.dart b/json_serializable/test/supported_types/input.type_num.g.dart index e996e5744..fbd27bbba 100644 --- a/json_serializable/test/supported_types/input.type_num.g.dart +++ b/json_serializable/test/supported_types/input.type_num.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal part of 'input.type_num.dart'; diff --git a/json_serializable/test/supported_types/input.type_object.g.dart b/json_serializable/test/supported_types/input.type_object.g.dart index 4ac5cff7b..7959daa78 100644 --- a/json_serializable/test/supported_types/input.type_object.g.dart +++ b/json_serializable/test/supported_types/input.type_object.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal part of 'input.type_object.dart'; diff --git a/json_serializable/test/supported_types/input.type_set.g.dart b/json_serializable/test/supported_types/input.type_set.g.dart index a028e2791..f46938826 100644 --- a/json_serializable/test/supported_types/input.type_set.g.dart +++ b/json_serializable/test/supported_types/input.type_set.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal part of 'input.type_set.dart'; diff --git a/json_serializable/test/supported_types/input.type_string.g.dart b/json_serializable/test/supported_types/input.type_string.g.dart index 648df335a..4b1c64a20 100644 --- a/json_serializable/test/supported_types/input.type_string.g.dart +++ b/json_serializable/test/supported_types/input.type_string.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal part of 'input.type_string.dart'; diff --git a/json_serializable/test/supported_types/input.type_uri.g.dart b/json_serializable/test/supported_types/input.type_uri.g.dart index 9634819b7..b4c7354df 100644 --- a/json_serializable/test/supported_types/input.type_uri.g.dart +++ b/json_serializable/test/supported_types/input.type_uri.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal part of 'input.type_uri.dart'; From d8b0594efb30c4b4986a31ef451bbf1849544e9d Mon Sep 17 00:00:00 2001 From: Koen Van Looveren <vanlooverenkoen.dev@gmail.com> Date: Fri, 26 Nov 2021 01:08:55 +0100 Subject: [PATCH 375/569] Updated the tostring for UnrecognizedKeysException & DisallowedNullValueException & updated the UnrecognizedKeyException (#1040) --- json_annotation/lib/src/allowed_keys_helpers.dart | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/json_annotation/lib/src/allowed_keys_helpers.dart b/json_annotation/lib/src/allowed_keys_helpers.dart index 42d3e4ca9..aab8f7562 100644 --- a/json_annotation/lib/src/allowed_keys_helpers.dart +++ b/json_annotation/lib/src/allowed_keys_helpers.dart @@ -73,7 +73,7 @@ class UnrecognizedKeysException extends BadKeyException { : super._(map); @override - String toString() => message; + String toString() => 'UnrecognizedKeysException: $message'; } /// Exception thrown if there are missing required keys in a JSON map that was @@ -88,6 +88,9 @@ class MissingRequiredKeysException extends BadKeyException { MissingRequiredKeysException(this.missingKeys, Map map) : assert(missingKeys.isNotEmpty), super._(map); + + @override + String toString() => 'MissingRequiredKeyException: $message'; } /// Exception thrown if there are keys with disallowed `null` values in a JSON @@ -100,4 +103,7 @@ class DisallowedNullValueException extends BadKeyException { @override String get message => 'These keys had `null` values, ' 'which is not allowed: $keysWithNullValues'; + + @override + String toString() => 'DisallowedNullValueException: $message'; } From 11b256175f7793ae108f9e6388057962d333f1f5 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Fri, 26 Nov 2021 15:11:48 -0800 Subject: [PATCH 376/569] annotation: follow-up to exception toString fixes (#1042) RE https://github.com/google/json_serializable.dart/commit/d8b0594efb30c4b4986a31ef451bbf1849544e9d --- checked_yaml/pubspec.yaml | 4 ++++ json_annotation/CHANGELOG.md | 4 ++++ json_annotation/lib/src/allowed_keys_helpers.dart | 12 +++--------- json_annotation/pubspec.yaml | 2 +- json_serializable/pubspec.yaml | 6 +++++- 5 files changed, 17 insertions(+), 11 deletions(-) diff --git a/checked_yaml/pubspec.yaml b/checked_yaml/pubspec.yaml index f41bdc1d0..ee79d69ec 100644 --- a/checked_yaml/pubspec.yaml +++ b/checked_yaml/pubspec.yaml @@ -20,3 +20,7 @@ dev_dependencies: path: ^1.0.0 test: ^1.16.0 test_process: ^2.0.0 + +dependency_overrides: + json_annotation: + path: ../json_annotation diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index ee44417a1..0eb6f8a5c 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -1,3 +1,7 @@ +## 4.3.1-dev + +- Improved `toString` in included exceptions. + ## 4.3.0 - Changed the type of `JsonKey.unknownEnumValue` from `Object?` to `Enum?`. diff --git a/json_annotation/lib/src/allowed_keys_helpers.dart b/json_annotation/lib/src/allowed_keys_helpers.dart index aab8f7562..48c3689b7 100644 --- a/json_annotation/lib/src/allowed_keys_helpers.dart +++ b/json_annotation/lib/src/allowed_keys_helpers.dart @@ -53,6 +53,9 @@ abstract class BadKeyException implements Exception { /// A human-readable message corresponding to the error. String get message; + + @override + String toString() => '$runtimeType: $message'; } /// Exception thrown if there are unrecognized keys in a JSON map that was @@ -71,9 +74,6 @@ class UnrecognizedKeysException extends BadKeyException { UnrecognizedKeysException(this.unrecognizedKeys, Map map, this.allowedKeys) : super._(map); - - @override - String toString() => 'UnrecognizedKeysException: $message'; } /// Exception thrown if there are missing required keys in a JSON map that was @@ -88,9 +88,6 @@ class MissingRequiredKeysException extends BadKeyException { MissingRequiredKeysException(this.missingKeys, Map map) : assert(missingKeys.isNotEmpty), super._(map); - - @override - String toString() => 'MissingRequiredKeyException: $message'; } /// Exception thrown if there are keys with disallowed `null` values in a JSON @@ -103,7 +100,4 @@ class DisallowedNullValueException extends BadKeyException { @override String get message => 'These keys had `null` values, ' 'which is not allowed: $keysWithNullValues'; - - @override - String toString() => 'DisallowedNullValueException: $message'; } diff --git a/json_annotation/pubspec.yaml b/json_annotation/pubspec.yaml index 9eddca416..93fa3460e 100644 --- a/json_annotation/pubspec.yaml +++ b/json_annotation/pubspec.yaml @@ -1,5 +1,5 @@ name: json_annotation -version: 4.3.0 +version: 4.3.1-dev description: >- Classes and helper functions that support JSON code generation via the `json_serializable` package. diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 2e31342cb..dd5adcd5d 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 6.0.1 +version: 6.1.0-dev description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. @@ -35,3 +35,7 @@ dev_dependencies: test_descriptor: ^2.0.0 test_process: ^2.0.0 yaml: ^3.0.0 + +dependency_overrides: + json_annotation: + path: ../json_annotation From 76f88936d3ac723c3922b26992577ff5431bffbc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 29 Nov 2021 08:51:46 -0800 Subject: [PATCH 377/569] Bump actions/cache from 2.1.6 to 2.1.7 (#1043) * Bump actions/cache from 2.1.6 to 2.1.7 Bumps [actions/cache](https://github.com/actions/cache) from 2.1.6 to 2.1.7. - [Release notes](https://github.com/actions/cache/releases) - [Commits](https://github.com/actions/cache/compare/v2.1.6...v2.1.7) --- updated-dependencies: - dependency-name: actions/cache dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Kevin Moore <kevmoo@google.com> --- .github/workflows/dart.yml | 56 +++++++++++++++++++------------------- tool/ci.sh | 2 +- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index e1fbc4f68..dcf06c94f 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -1,4 +1,4 @@ -# Created with package:mono_repo v5.0.4 +# Created with package:mono_repo v5.0.5 name: Dart CI on: push: @@ -20,7 +20,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v2.1.6 + uses: actions/cache@v2.1.7 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;dart:stable" @@ -31,9 +31,9 @@ jobs: with: sdk: stable - id: checkout - uses: actions/checkout@v2.3.5 + uses: actions/checkout@v2.4.0 - name: mono_repo self validate - run: dart pub global activate mono_repo 5.0.4 + run: dart pub global activate mono_repo 5.0.5 - name: mono_repo self validate run: dart pub global run mono_repo generate --validate job_002: @@ -41,7 +41,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v2.1.6 + uses: actions/cache@v2.1.7 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;dart:2.14.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:format-analyze" @@ -54,7 +54,7 @@ jobs: with: sdk: "2.14.0" - id: checkout - uses: actions/checkout@v2.3.5 + uses: actions/checkout@v2.4.0 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -125,7 +125,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v2.1.6 + uses: actions/cache@v2.1.7 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:format-analyze" @@ -138,7 +138,7 @@ jobs: with: sdk: dev - id: checkout - uses: actions/checkout@v2.3.5 + uses: actions/checkout@v2.4.0 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -209,7 +209,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v2.1.6 + uses: actions/cache@v2.1.7 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;dart:2.14.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" @@ -222,7 +222,7 @@ jobs: with: sdk: "2.14.0" - id: checkout - uses: actions/checkout@v2.3.5 + uses: actions/checkout@v2.4.0 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -268,7 +268,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v2.1.6 + uses: actions/cache@v2.1.7 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;dart:2.14.0;packages:json_serializable;commands:test_3" @@ -281,7 +281,7 @@ jobs: with: sdk: "2.14.0" - id: checkout - uses: actions/checkout@v2.3.5 + uses: actions/checkout@v2.4.0 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -300,7 +300,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v2.1.6 + uses: actions/cache@v2.1.7 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;dart:2.14.0;packages:json_serializable;commands:test_1" @@ -313,7 +313,7 @@ jobs: with: sdk: "2.14.0" - id: checkout - uses: actions/checkout@v2.3.5 + uses: actions/checkout@v2.4.0 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -332,7 +332,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v2.1.6 + uses: actions/cache@v2.1.7 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;dart:2.14.0;packages:json_serializable;commands:test_2" @@ -345,7 +345,7 @@ jobs: with: sdk: "2.14.0" - id: checkout - uses: actions/checkout@v2.3.5 + uses: actions/checkout@v2.4.0 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -364,7 +364,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v2.1.6 + uses: actions/cache@v2.1.7 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" @@ -377,7 +377,7 @@ jobs: with: sdk: dev - id: checkout - uses: actions/checkout@v2.3.5 + uses: actions/checkout@v2.4.0 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -423,7 +423,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v2.1.6 + uses: actions/cache@v2.1.7 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:json_serializable;commands:test_3" @@ -436,7 +436,7 @@ jobs: with: sdk: dev - id: checkout - uses: actions/checkout@v2.3.5 + uses: actions/checkout@v2.4.0 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -455,7 +455,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v2.1.6 + uses: actions/cache@v2.1.7 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:json_serializable;commands:test_1" @@ -468,7 +468,7 @@ jobs: with: sdk: dev - id: checkout - uses: actions/checkout@v2.3.5 + uses: actions/checkout@v2.4.0 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -487,7 +487,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v2.1.6 + uses: actions/cache@v2.1.7 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:json_serializable;commands:test_2" @@ -500,7 +500,7 @@ jobs: with: sdk: dev - id: checkout - uses: actions/checkout@v2.3.5 + uses: actions/checkout@v2.4.0 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -519,7 +519,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v2.1.6 + uses: actions/cache@v2.1.7 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;dart:2.14.0;packages:_test_yaml-checked_yaml-example;commands:test_1" @@ -532,7 +532,7 @@ jobs: with: sdk: "2.14.0" - id: checkout - uses: actions/checkout@v2.3.5 + uses: actions/checkout@v2.4.0 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -577,7 +577,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v2.1.6 + uses: actions/cache@v2.1.7 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:_test_yaml-checked_yaml-example;commands:test_1" @@ -590,7 +590,7 @@ jobs: with: sdk: dev - id: checkout - uses: actions/checkout@v2.3.5 + uses: actions/checkout@v2.4.0 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" diff --git a/tool/ci.sh b/tool/ci.sh index 747f00558..0125be6d4 100755 --- a/tool/ci.sh +++ b/tool/ci.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Created with package:mono_repo v5.0.4 +# Created with package:mono_repo v5.0.5 # Support built in commands on windows out of the box. # When it is a flutter repo (check the pubspec.yaml for "sdk: flutter") From a36f26668fa3614c22e5e670e1400e1b3c373ffa Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@google.com> Date: Fri, 26 Nov 2021 15:30:46 -0800 Subject: [PATCH 378/569] doc comments are nice! --- json_serializable/lib/src/type_helpers/value_helper.dart | 2 ++ 1 file changed, 2 insertions(+) diff --git a/json_serializable/lib/src/type_helpers/value_helper.dart b/json_serializable/lib/src/type_helpers/value_helper.dart index f87e6cd03..a06b61069 100644 --- a/json_serializable/lib/src/type_helpers/value_helper.dart +++ b/json_serializable/lib/src/type_helpers/value_helper.dart @@ -9,6 +9,8 @@ import '../shared_checkers.dart'; import '../type_helper.dart'; import '../utils.dart'; +/// Handles the types corresponding to [simpleJsonTypeChecker], namely +/// [String], [bool], [num], [int], [double]. class ValueHelper extends TypeHelper { const ValueHelper(); From d2fe5141a333e2109fd1511e1520bc13374a63e9 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Mon, 29 Nov 2021 14:57:04 -0800 Subject: [PATCH 379/569] Allow customizable "reading" of JSON maps (#1045) Allows aliasing values to different names or computing a single field value from any aspect of the source JSON map Fixes https://github.com/google/json_serializable.dart/issues/144 Fixes https://github.com/google/json_serializable.dart/issues/888 --- _test_yaml/pubspec.yaml | 2 +- json_annotation/CHANGELOG.md | 5 ++- json_annotation/lib/src/checked_helpers.dart | 26 +++++++++++--- json_annotation/lib/src/json_key.dart | 16 +++++++++ json_serializable/CHANGELOG.md | 6 ++++ json_serializable/README.md | 16 ++++----- .../lib/src/check_dependencies.dart | 2 +- json_serializable/lib/src/decode_helper.dart | 34 ++++++++++++++----- json_serializable/lib/src/json_key_utils.dart | 10 ++++++ .../lib/src/type_helpers/config_types.dart | 3 ++ json_serializable/pubspec.yaml | 2 +- .../test/kitchen_sink/kitchen_sink.dart | 15 +++++++- .../test/kitchen_sink/kitchen_sink.g.dart | 4 +-- .../kitchen_sink/kitchen_sink.g_any_map.dart | 15 +++++++- .../kitchen_sink.g_any_map.g.dart | 4 +-- .../kitchen_sink.g_any_map__checked.dart | 15 +++++++- .../kitchen_sink.g_any_map__checked.g.dart | 12 +++++-- .../kitchen_sink.g_exclude_null.dart | 15 +++++++- .../kitchen_sink.g_exclude_null.g.dart | 4 +-- .../kitchen_sink.g_explicit_to_json.dart | 15 +++++++- .../kitchen_sink.g_explicit_to_json.g.dart | 4 +-- .../kitchen_sink/kitchen_sink_interface.dart | 3 ++ .../test/kitchen_sink/kitchen_sink_test.dart | 16 +++++++++ .../kitchen_sink_test_shared.dart | 6 ++-- 24 files changed, 208 insertions(+), 42 deletions(-) diff --git a/_test_yaml/pubspec.yaml b/_test_yaml/pubspec.yaml index 39171e628..24c036c12 100644 --- a/_test_yaml/pubspec.yaml +++ b/_test_yaml/pubspec.yaml @@ -8,7 +8,7 @@ dev_dependencies: build_runner: ^2.0.0 build_verify: ^2.0.0 checked_yaml: any - json_annotation: ^4.3.0 + json_annotation: ^4.4.0 json_serializable: any test: ^1.6.0 yaml: ^3.0.0 diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index 0eb6f8a5c..3ccaa294d 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -1,5 +1,8 @@ -## 4.3.1-dev +## 4.4.0-dev +- Added `JsonKey.readValue`. +- Non-breaking updates to `checkedCreate` and `checkedConvert` to support + `JsonKey.readValue`. - Improved `toString` in included exceptions. ## 4.3.0 diff --git a/json_annotation/lib/src/checked_helpers.dart b/json_annotation/lib/src/checked_helpers.dart index 7a214f9ad..f26d55385 100644 --- a/json_annotation/lib/src/checked_helpers.dart +++ b/json_annotation/lib/src/checked_helpers.dart @@ -13,11 +13,22 @@ typedef _CastFunction<R> = R Function(Object?); T $checkedCreate<T>( String className, Map map, - T Function(S Function<S>(String, _CastFunction<S>) converter) constructor, { + T Function( + S Function<S>( + String, + _CastFunction<S>, { + Object? Function(Map, String)? readValue, + }), + ) + constructor, { Map<String, String> fieldKeyMap = const {}, }) { - Q _checkedConvert<Q>(String key, _CastFunction<Q> convertFunction) => - $checkedConvert<Q>(map, key, convertFunction); + Q _checkedConvert<Q>( + String key, + _CastFunction<Q> convertFunction, { + Object? Function(Map, String)? readValue, + }) => + $checkedConvert<Q>(map, key, convertFunction, readValue: readValue); return $checkedNew( className, @@ -69,9 +80,14 @@ T $checkedNew<T>( /// `JsonSerializableGenerator.checked` is `true`. /// /// Should not be used directly. -T $checkedConvert<T>(Map map, String key, T Function(dynamic) castFunc) { +T $checkedConvert<T>( + Map map, + String key, + T Function(dynamic) castFunc, { + Object? Function(Map, String)? readValue, +}) { try { - return castFunc(map[key]); + return castFunc(readValue == null ? map[key] : readValue(map, key)); } on CheckedFromJsonException { rethrow; } catch (error, stack) { diff --git a/json_annotation/lib/src/json_key.dart b/json_annotation/lib/src/json_key.dart index 7a1c44b6f..96967c2a9 100644 --- a/json_annotation/lib/src/json_key.dart +++ b/json_annotation/lib/src/json_key.dart @@ -67,6 +67,21 @@ class JsonKey { /// If `null`, the field name is used. final String? name; + /// Specialize how a value is read from the source JSON map. + /// + /// Typically, the value corresponding to a given key is read directly from + /// the JSON map using `map[key]`. At times it's convenient to customize this + /// behavior to support alternative names or to support logic that requires + /// accessing multiple values at once. + /// + /// The provided, the [Function] must be a top-level or static within the + /// using class. + /// + /// Note: using this feature does not change any of the subsequent decoding + /// logic for the field. For instance, if the field is of type [DateTime] we + /// expect the function provided here to return a [String]. + final Object? Function(Map, String)? readValue; + /// When `true`, generated code for `fromJson` will verify that the source /// JSON map contains the associated key. /// @@ -108,6 +123,7 @@ class JsonKey { this.ignore, this.includeIfNull, this.name, + this.readValue, this.required, this.toJson, this.unknownEnumValue, diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 45200e39a..b8573499b 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,9 @@ +## 6.1.0-dev + +- Support `JsonKey.readValue` to allow customized reading of values from source + JSON map objects. +- Require `json_annotation` `'>=4.4.0 <4.5.0'`. + ## 6.0.1 - Don't require `json_annotation` in `dependencies` if it's just used in tests. diff --git a/json_serializable/README.md b/json_serializable/README.md index 4756a0760..ae17884c7 100644 --- a/json_serializable/README.md +++ b/json_serializable/README.md @@ -199,14 +199,14 @@ targets: [`Enum`]: https://api.dart.dev/stable/dart-core/Enum-class.html [`int`]: https://api.dart.dev/stable/dart-core/int-class.html [`Iterable`]: https://api.dart.dev/stable/dart-core/Iterable-class.html -[`JsonConverter`]: https://pub.dev/documentation/json_annotation/4.3.0/json_annotation/JsonConverter-class.html -[`JsonEnum`]: https://pub.dev/documentation/json_annotation/4.3.0/json_annotation/JsonEnum-class.html -[`JsonKey.fromJson`]: https://pub.dev/documentation/json_annotation/4.3.0/json_annotation/JsonKey/fromJson.html -[`JsonKey.toJson`]: https://pub.dev/documentation/json_annotation/4.3.0/json_annotation/JsonKey/toJson.html -[`JsonKey`]: https://pub.dev/documentation/json_annotation/4.3.0/json_annotation/JsonKey-class.html -[`JsonLiteral`]: https://pub.dev/documentation/json_annotation/4.3.0/json_annotation/JsonLiteral-class.html -[`JsonSerializable`]: https://pub.dev/documentation/json_annotation/4.3.0/json_annotation/JsonSerializable-class.html -[`JsonValue`]: https://pub.dev/documentation/json_annotation/4.3.0/json_annotation/JsonValue-class.html +[`JsonConverter`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonConverter-class.html +[`JsonEnum`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonEnum-class.html +[`JsonKey.fromJson`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/fromJson.html +[`JsonKey.toJson`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/toJson.html +[`JsonKey`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey-class.html +[`JsonLiteral`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonLiteral-class.html +[`JsonSerializable`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable-class.html +[`JsonValue`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonValue-class.html [`List`]: https://api.dart.dev/stable/dart-core/List-class.html [`Map`]: https://api.dart.dev/stable/dart-core/Map-class.html [`num`]: https://api.dart.dev/stable/dart-core/num-class.html diff --git a/json_serializable/lib/src/check_dependencies.dart b/json_serializable/lib/src/check_dependencies.dart index f5b389ddc..edeb2340c 100644 --- a/json_serializable/lib/src/check_dependencies.dart +++ b/json_serializable/lib/src/check_dependencies.dart @@ -10,7 +10,7 @@ import 'package:pubspec_parse/pubspec_parse.dart'; const _productionDirectories = {'lib', 'bin'}; const _annotationPkgName = 'json_annotation'; -final requiredJsonAnnotationMinVersion = Version.parse('4.3.0'); +final requiredJsonAnnotationMinVersion = Version.parse('4.4.0'); Future<void> pubspecHasRightVersion(BuildStep buildStep) async { final segments = buildStep.inputId.pathSegments; diff --git a/json_serializable/lib/src/decode_helper.dart b/json_serializable/lib/src/decode_helper.dart index dc8e934be..adf774764 100644 --- a/json_serializable/lib/src/decode_helper.dart +++ b/json_serializable/lib/src/decode_helper.dart @@ -86,16 +86,24 @@ abstract class DecodeHelper implements HelperCore { ..write(''' final val = ${data.content};'''); - for (final field in data.fieldsToSet) { + for (final fieldName in data.fieldsToSet) { sectionBuffer.writeln(); - final safeName = safeNameAccess(accessibleFields[field]!); + final fieldValue = accessibleFields[fieldName]!; + final safeName = safeNameAccess(fieldValue); sectionBuffer ..write(''' \$checkedConvert($safeName, (v) => ''') - ..write('val.$field = ') - ..write(_deserializeForField(accessibleFields[field]!, - checkedProperty: true)) - ..write(');'); + ..write('val.$fieldName = ') + ..write( + _deserializeForField(fieldValue, checkedProperty: true), + ); + + final readValueFunc = jsonKeyFor(fieldValue).readValueFunctionName; + if (readValueFunc != null) { + sectionBuffer.writeln(',readValue: $readValueFunc,'); + } + + sectionBuffer.write(');'); } sectionBuffer.write('''\n return val; @@ -182,6 +190,8 @@ abstract class DecodeHelper implements HelperCore { } } + /// If [checkedProperty] is `true`, we're using this function to write to a + /// setter. String _deserializeForField( FieldElement field, { ParameterElement? ctorParam, @@ -192,6 +202,7 @@ abstract class DecodeHelper implements HelperCore { final contextHelper = getHelperContext(field); final jsonKey = jsonKeyFor(field); final defaultValue = jsonKey.defaultValue; + final readValueFunc = jsonKey.readValueFunctionName; String deserialize(String expression) => contextHelper .deserialize( @@ -206,14 +217,21 @@ abstract class DecodeHelper implements HelperCore { if (config.checked) { value = deserialize('v'); if (!checkedProperty) { - value = '\$checkedConvert($jsonKeyName, (v) => $value)'; + final readValueBit = + readValueFunc == null ? '' : ',readValue: $readValueFunc,'; + value = '\$checkedConvert($jsonKeyName, (v) => $value$readValueBit)'; } } else { assert( !checkedProperty, 'should only be true if `_generator.checked` is true.', ); - value = deserialize('json[$jsonKeyName]'); + + value = deserialize( + readValueFunc == null + ? 'json[$jsonKeyName]' + : '$readValueFunc(json, $jsonKeyName)', + ); } } on UnsupportedTypeError catch (e) // ignore: avoid_catching_errors { diff --git a/json_serializable/lib/src/json_key_utils.dart b/json_serializable/lib/src/json_key_utils.dart index 4153e14be..c565282ad 100644 --- a/json_serializable/lib/src/json_key_utils.dart +++ b/json_serializable/lib/src/json_key_utils.dart @@ -209,6 +209,13 @@ KeyConfig _from(FieldElement element, ClassConfig classAnnotation) { } } + String? readValueFunctionName; + final readValue = obj.read('readValue'); + if (!readValue.isNull) { + final objValue = readValue.objectValue.toFunctionValue()!; + readValueFunctionName = objValue.name; + } + return _populateJsonKey( classAnnotation, element, @@ -217,6 +224,7 @@ KeyConfig _from(FieldElement element, ClassConfig classAnnotation) { ignore: obj.read('ignore').literalValue as bool?, includeIfNull: obj.read('includeIfNull').literalValue as bool?, name: obj.read('name').literalValue as String?, + readValueFunctionName: readValueFunctionName, required: obj.read('required').literalValue as bool?, unknownEnumValue: _annotationValue('unknownEnumValue', mustBeEnum: true), ); @@ -230,6 +238,7 @@ KeyConfig _populateJsonKey( bool? ignore, bool? includeIfNull, String? name, + String? readValueFunctionName, bool? required, String? unknownEnumValue, }) { @@ -249,6 +258,7 @@ KeyConfig _populateJsonKey( includeIfNull: _includeIfNull( includeIfNull, disallowNullValue, classAnnotation.includeIfNull), name: name ?? encodedFieldName(classAnnotation.fieldRename, element.name), + readValueFunctionName: readValueFunctionName, required: required ?? false, unknownEnumValue: unknownEnumValue, ); diff --git a/json_serializable/lib/src/type_helpers/config_types.dart b/json_serializable/lib/src/type_helpers/config_types.dart index 916894f91..a90a1220d 100644 --- a/json_serializable/lib/src/type_helpers/config_types.dart +++ b/json_serializable/lib/src/type_helpers/config_types.dart @@ -20,12 +20,15 @@ class KeyConfig { final String? unknownEnumValue; + final String? readValueFunctionName; + KeyConfig({ required this.defaultValue, required this.disallowNullValue, required this.ignore, required this.includeIfNull, required this.name, + required this.readValueFunctionName, required this.required, required this.unknownEnumValue, }); diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index dd5adcd5d..348e3b711 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -16,7 +16,7 @@ dependencies: # Use a tight version constraint to ensure that a constraint on # `json_annotation` properly constrains all features it provides. - json_annotation: '>=4.3.0 <4.4.0' + json_annotation: '>=4.4.0 <4.5.0' meta: ^1.3.0 path: ^1.8.0 pub_semver: ^2.0.0 diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.dart b/json_serializable/test/kitchen_sink/kitchen_sink.dart index 7456234f7..bdde73b01 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.dart @@ -75,6 +75,18 @@ class _Factory implements k.KitchenSinkFactory<String, dynamic> { JsonConverterTestClass.fromJson(json); } +Object? _valueAccessor(Map json, String key) { + if (key == k.trickyKeyName) { + return json[k.trickyKeyName] ?? json['STRING']; + } + + if (key == 'iterable') { + return json['iterable'] ?? json['theIterable']; + } + + return json[key]; +} + @JsonSerializable() class KitchenSink implements k.KitchenSink { // NOTE: exposing these as Iterable, but storing the values as List @@ -115,6 +127,7 @@ class KitchenSink implements k.KitchenSink { BigInt? bigInt; + @JsonKey(readValue: _valueAccessor) Iterable? get iterable => _iterable; Iterable<dynamic> get dynamicIterable => _dynamicIterable; @@ -152,7 +165,7 @@ class KitchenSink implements k.KitchenSink { // Handle fields with names that collide with helper names Map<String, bool> val = _defaultMap(); bool? writeNotNull; - @JsonKey(name: r'$string') + @JsonKey(name: k.trickyKeyName, readValue: _valueAccessor) String? string; SimpleObject simpleObject = _defaultSimpleObject(); diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g.dart index 393ccfedb..d4feec78a 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g.dart @@ -10,7 +10,7 @@ part of 'kitchen_sink.dart'; KitchenSink _$KitchenSinkFromJson(Map<String, dynamic> json) => KitchenSink( ctorValidatedNo42: json['no-42'] as int?, - iterable: json['iterable'] as List<dynamic>?, + iterable: _valueAccessor(json, 'iterable') as List<dynamic>?, dynamicIterable: json['dynamicIterable'] as List<dynamic>?, objectIterable: (json['objectIterable'] as List<dynamic>?)?.map((e) => e as Object), @@ -80,7 +80,7 @@ KitchenSink _$KitchenSinkFromJson(Map<String, dynamic> json) => KitchenSink( .toList() ..val = Map<String, bool>.from(json['val'] as Map) ..writeNotNull = json['writeNotNull'] as bool? - ..string = json[r'$string'] as String? + ..string = _valueAccessor(json, r'$string') as String? ..simpleObject = SimpleObject.fromJson(json['simpleObject'] as Map<String, dynamic>) ..strictKeysObject = StrictKeysObject.fromJson( diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart index 56cdb9a1e..d0d8f49ad 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart @@ -74,6 +74,18 @@ class _Factory implements k.KitchenSinkFactory<dynamic, dynamic> { JsonConverterTestClass.fromJson(json); } +Object? _valueAccessor(Map json, String key) { + if (key == k.trickyKeyName) { + return json[k.trickyKeyName] ?? json['STRING']; + } + + if (key == 'iterable') { + return json['iterable'] ?? json['theIterable']; + } + + return json[key]; +} + @JsonSerializable( anyMap: true, ) @@ -115,6 +127,7 @@ class KitchenSink implements k.KitchenSink { BigInt? bigInt; + @JsonKey(readValue: _valueAccessor) Iterable? get iterable => _iterable; Iterable<dynamic> get dynamicIterable => _dynamicIterable; @@ -152,7 +165,7 @@ class KitchenSink implements k.KitchenSink { // Handle fields with names that collide with helper names Map<String, bool> val = _defaultMap(); bool? writeNotNull; - @JsonKey(name: r'$string') + @JsonKey(name: k.trickyKeyName, readValue: _valueAccessor) String? string; SimpleObject simpleObject = _defaultSimpleObject(); diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart index 6e80def06..e05b1f53d 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart @@ -10,7 +10,7 @@ part of 'kitchen_sink.g_any_map.dart'; KitchenSink _$KitchenSinkFromJson(Map json) => KitchenSink( ctorValidatedNo42: json['no-42'] as int?, - iterable: json['iterable'] as List<dynamic>?, + iterable: _valueAccessor(json, 'iterable') as List<dynamic>?, dynamicIterable: json['dynamicIterable'] as List<dynamic>?, objectIterable: (json['objectIterable'] as List<dynamic>?)?.map((e) => e as Object), @@ -73,7 +73,7 @@ KitchenSink _$KitchenSinkFromJson(Map json) => KitchenSink( .toList() ..val = Map<String, bool>.from(json['val'] as Map) ..writeNotNull = json['writeNotNull'] as bool? - ..string = json[r'$string'] as String? + ..string = _valueAccessor(json, r'$string') as String? ..simpleObject = SimpleObject.fromJson(json['simpleObject'] as Map) ..strictKeysObject = StrictKeysObject.fromJson(json['strictKeysObject'] as Map) diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.dart index d997a4422..c6d326c54 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.dart @@ -74,6 +74,18 @@ class _Factory implements k.KitchenSinkFactory<dynamic, dynamic> { JsonConverterTestClass.fromJson(json); } +Object? _valueAccessor(Map json, String key) { + if (key == k.trickyKeyName) { + return json[k.trickyKeyName] ?? json['STRING']; + } + + if (key == 'iterable') { + return json['iterable'] ?? json['theIterable']; + } + + return json[key]; +} + @JsonSerializable( checked: true, anyMap: true, @@ -116,6 +128,7 @@ class KitchenSink implements k.KitchenSink { BigInt? bigInt; + @JsonKey(readValue: _valueAccessor) Iterable? get iterable => _iterable; Iterable<dynamic> get dynamicIterable => _dynamicIterable; @@ -153,7 +166,7 @@ class KitchenSink implements k.KitchenSink { // Handle fields with names that collide with helper names Map<String, bool> val = _defaultMap(); bool? writeNotNull; - @JsonKey(name: r'$string') + @JsonKey(name: k.trickyKeyName, readValue: _valueAccessor) String? string; SimpleObject simpleObject = _defaultSimpleObject(); diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.g.dart index 61434b375..38c2b8109 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.g.dart @@ -14,7 +14,11 @@ KitchenSink _$KitchenSinkFromJson(Map json) => $checkedCreate( ($checkedConvert) { final val = KitchenSink( ctorValidatedNo42: $checkedConvert('no-42', (v) => v as int?), - iterable: $checkedConvert('iterable', (v) => v as List<dynamic>?), + iterable: $checkedConvert( + 'iterable', + (v) => v as List<dynamic>?, + readValue: _valueAccessor, + ), dynamicIterable: $checkedConvert('dynamicIterable', (v) => v as List<dynamic>?), objectIterable: $checkedConvert('objectIterable', @@ -106,7 +110,11 @@ KitchenSink _$KitchenSinkFromJson(Map json) => $checkedCreate( $checkedConvert( 'val', (v) => val.val = Map<String, bool>.from(v as Map)); $checkedConvert('writeNotNull', (v) => val.writeNotNull = v as bool?); - $checkedConvert(r'$string', (v) => val.string = v as String?); + $checkedConvert( + r'$string', + (v) => val.string = v as String?, + readValue: _valueAccessor, + ); $checkedConvert('simpleObject', (v) => val.simpleObject = SimpleObject.fromJson(v as Map)); $checkedConvert('strictKeysObject', diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.dart index 44750ac8e..11d68878b 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.dart @@ -75,6 +75,18 @@ class _Factory implements k.KitchenSinkFactory<String, dynamic> { JsonConverterTestClass.fromJson(json); } +Object? _valueAccessor(Map json, String key) { + if (key == k.trickyKeyName) { + return json[k.trickyKeyName] ?? json['STRING']; + } + + if (key == 'iterable') { + return json['iterable'] ?? json['theIterable']; + } + + return json[key]; +} + @JsonSerializable( includeIfNull: false, ) @@ -117,6 +129,7 @@ class KitchenSink implements k.KitchenSink { BigInt? bigInt; + @JsonKey(readValue: _valueAccessor) Iterable? get iterable => _iterable; Iterable<dynamic> get dynamicIterable => _dynamicIterable; @@ -154,7 +167,7 @@ class KitchenSink implements k.KitchenSink { // Handle fields with names that collide with helper names Map<String, bool> val = _defaultMap(); bool? writeNotNull; - @JsonKey(name: r'$string') + @JsonKey(name: k.trickyKeyName, readValue: _valueAccessor) String? string; SimpleObject simpleObject = _defaultSimpleObject(); diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart index 21e25bc02..fd7d40925 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart @@ -10,7 +10,7 @@ part of 'kitchen_sink.g_exclude_null.dart'; KitchenSink _$KitchenSinkFromJson(Map<String, dynamic> json) => KitchenSink( ctorValidatedNo42: json['no-42'] as int?, - iterable: json['iterable'] as List<dynamic>?, + iterable: _valueAccessor(json, 'iterable') as List<dynamic>?, dynamicIterable: json['dynamicIterable'] as List<dynamic>?, objectIterable: (json['objectIterable'] as List<dynamic>?)?.map((e) => e as Object), @@ -80,7 +80,7 @@ KitchenSink _$KitchenSinkFromJson(Map<String, dynamic> json) => KitchenSink( .toList() ..val = Map<String, bool>.from(json['val'] as Map) ..writeNotNull = json['writeNotNull'] as bool? - ..string = json[r'$string'] as String? + ..string = _valueAccessor(json, r'$string') as String? ..simpleObject = SimpleObject.fromJson(json['simpleObject'] as Map<String, dynamic>) ..strictKeysObject = StrictKeysObject.fromJson( diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.dart index 4568b1cd0..f5707afa4 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.dart @@ -75,6 +75,18 @@ class _Factory implements k.KitchenSinkFactory<String, dynamic> { JsonConverterTestClass.fromJson(json); } +Object? _valueAccessor(Map json, String key) { + if (key == k.trickyKeyName) { + return json[k.trickyKeyName] ?? json['STRING']; + } + + if (key == 'iterable') { + return json['iterable'] ?? json['theIterable']; + } + + return json[key]; +} + @JsonSerializable( explicitToJson: true, ) @@ -117,6 +129,7 @@ class KitchenSink implements k.KitchenSink { BigInt? bigInt; + @JsonKey(readValue: _valueAccessor) Iterable? get iterable => _iterable; Iterable<dynamic> get dynamicIterable => _dynamicIterable; @@ -154,7 +167,7 @@ class KitchenSink implements k.KitchenSink { // Handle fields with names that collide with helper names Map<String, bool> val = _defaultMap(); bool? writeNotNull; - @JsonKey(name: r'$string') + @JsonKey(name: k.trickyKeyName, readValue: _valueAccessor) String? string; SimpleObject simpleObject = _defaultSimpleObject(); diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart index e6d447061..301c75b29 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart @@ -10,7 +10,7 @@ part of 'kitchen_sink.g_explicit_to_json.dart'; KitchenSink _$KitchenSinkFromJson(Map<String, dynamic> json) => KitchenSink( ctorValidatedNo42: json['no-42'] as int?, - iterable: json['iterable'] as List<dynamic>?, + iterable: _valueAccessor(json, 'iterable') as List<dynamic>?, dynamicIterable: json['dynamicIterable'] as List<dynamic>?, objectIterable: (json['objectIterable'] as List<dynamic>?)?.map((e) => e as Object), @@ -80,7 +80,7 @@ KitchenSink _$KitchenSinkFromJson(Map<String, dynamic> json) => KitchenSink( .toList() ..val = Map<String, bool>.from(json['val'] as Map) ..writeNotNull = json['writeNotNull'] as bool? - ..string = json[r'$string'] as String? + ..string = _valueAccessor(json, r'$string') as String? ..simpleObject = SimpleObject.fromJson(json['simpleObject'] as Map<String, dynamic>) ..strictKeysObject = StrictKeysObject.fromJson( diff --git a/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart b/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart index ca4ad5b8f..f69ade258 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart @@ -5,6 +5,9 @@ import '../test_utils.dart'; import 'simple_object.dart'; +/// A key name that requires special encoding +const trickyKeyName = r'$string'; + abstract class KitchenSinkFactory<K, V> { String get description; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink_test.dart b/json_serializable/test/kitchen_sink/kitchen_sink_test.dart index c60d9bd08..0b5a1f8b8 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink_test.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink_test.dart @@ -162,6 +162,22 @@ void _nullableTests(KitchenSinkFactory factory) { } void _sharedTests(KitchenSinkFactory factory) { + test('other names', () { + final originalName = factory.fromJson(validValues); + + final aliasName = factory.fromJson( + <String, dynamic>{ + ...validValues, + 'theIterable': validValues['iterable'], + 'STRING': validValues[trickyKeyName] + } + ..remove('iterable') + ..remove(trickyKeyName), + ); + + expect(loudEncode(aliasName), loudEncode(originalName)); + }); + test('empty', () { final item = factory.ctor(); validateRoundTrip(item, factory.fromJson); diff --git a/json_serializable/test/kitchen_sink/kitchen_sink_test_shared.dart b/json_serializable/test/kitchen_sink/kitchen_sink_test_shared.dart index f39dcaed1..7bf34f035 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink_test_shared.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink_test_shared.dart @@ -1,6 +1,8 @@ import 'package:json_annotation/json_annotation.dart'; import 'package:test/test.dart'; +import 'kitchen_sink_interface.dart' show trickyKeyName; + const validValues = <String, dynamic>{ 'no-42': 0, 'dateTime': '2018-05-10T14:20:58.927', @@ -35,7 +37,7 @@ const validValues = <String, dynamic>{ 'crazyComplex': [<String, dynamic>{}], generatedLocalVarName: <String, dynamic>{'key': true}, _toJsonMapHelperName: true, - r'$string': 'string', + trickyKeyName: 'string', 'simpleObject': {'value': 42}, 'strictKeysObject': {'value': 10, 'custom_field': 'cool'}, 'validatedPropertyNo42': 0 @@ -69,7 +71,7 @@ const invalidValueTypes = { 'crazyComplex': [true], generatedLocalVarName: {'key': 42}, _toJsonMapHelperName: 42, - r'$string': true, + trickyKeyName: true, 'simpleObject': 42, 'strictKeysObject': { 'value': 10, From efda15821de7556cd135a24e43ddf81b92f17f37 Mon Sep 17 00:00:00 2001 From: fzyzcjy <5236035+fzyzcjy@users.noreply.github.com> Date: Tue, 30 Nov 2021 12:26:43 +0800 Subject: [PATCH 380/569] Fix typo that changes meaning of sentence (peak != peek) (#1046) --- example/lib/generic_response_class_example.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/lib/generic_response_class_example.dart b/example/lib/generic_response_class_example.dart index cde1e60eb..5565aed8d 100644 --- a/example/lib/generic_response_class_example.dart +++ b/example/lib/generic_response_class_example.dart @@ -40,7 +40,7 @@ class BaseResponse<T> { } else if (json is List) { // NOTE: this logic assumes the ONLY valid value for a `List` in this case // is a List<Author>. If that assumption changes, then it will be - // necessary to "peak" into non-empty lists to determine the type! + // necessary to "peek" into non-empty lists to determine the type! return json .map((e) => Article.fromJson(e as Map<String, dynamic>)) From c6d34908c7066d84ada03c4310b7ab9843f17b04 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@google.com> Date: Tue, 30 Nov 2021 16:11:26 -0800 Subject: [PATCH 381/569] Cleanup changelog --- json_serializable/CHANGELOG.md | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index b8573499b..603ad4526 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -10,15 +10,15 @@ ## 6.0.0 -- Added support for `JsonSerializable.constructor` to allow specifying an +- Added support for `JsonSerializable.constructor` to allow specifying an alternative constructor to invoke when creating a `fromJson` helper. - Support the new `@JsonEnum` annotation in `package:json_annotation`. - Support `JsonKey.nullForUndefinedEnumValue` as a value for `JsonKey.unknownEnumValue` when you want to use `null` as the unknown value. - Use the new `$enumDecodeNullable` and `$enumDecode` in `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. + 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`. @@ -26,8 +26,8 @@ ## 5.0.2 -- Include type arguments when invoking `fromJson` on custom types. - This fixes an edge case where the generic arguments could not be inferred. +- Include type arguments when invoking `fromJson` on custom types. This fixes an + edge case where the generic arguments could not be inferred. ## 5.0.1 @@ -182,7 +182,7 @@ ## 3.2.3 -- Bug fix for analyzer 0.38.5. +- Fixed bug related to `package:analyzer` 0.38.5. ## 3.2.2 @@ -271,12 +271,12 @@ future feature work. ## 2.0.3 - When invoking a `fromJson` constructor on a field type, generate a conversion - expression derived from the the constructor parameter type. + expression derived from the constructor parameter type. - Be more strict about the supported `List`, `Set`, or `Map` types. This may - causes errors to be raised in cases where invalid code was generated before. - It also allows implementations of these types to add a `fromJson` constructor - to support custom decoding. + cause errors to be raised in cases where invalid code was generated before. It + also allows implementations of these types to add a `fromJson` constructor to + support custom decoding. - Small change to the whitespace around converted maps to improve a very slow path when formatting generated code. @@ -319,8 +319,7 @@ future feature work. - **BREAKING** `JsonSerializableGenerator` now exposes a `config` property of type `JsonSerializable` instead of individual properties for `checked`, - `anyMay`, etc. This will affect anyone creating or using this class via - code. + `anyMay`, etc. This will affect creating or using this class via code. - `type_helper.dart` @@ -451,7 +450,7 @@ future feature work. - Added `JsonKey.disallowNullValue`. - When `true`, generated code throws a `DisallowedNullValueException` if the - corresponding keys exist in in the JSON map, but it's value is null. + corresponding keys exist in the JSON map, but its value is `null`. - Will be captured and wrapped in a `CheckedFromJsonException` if `checked` is enabled in `json_serializable`. @@ -641,7 +640,7 @@ future feature work. - Moved the annotations in `annotations.dart` to `package:json_annotations`. - Allows package authors to release code that has the corresponding - annotations without requiring package users to inherit all of the transitive + annotations without requiring package users to inherit all the transitive dependencies. - Deprecated `annotations.dart`. @@ -687,7 +686,7 @@ future feature work. 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 supports JSON serialization. + do not explicitly support JSON serialization. - **BREAKING** `TypeHelper`: From 85ac59f361cdaf99e345bf32744f26d2c2130fc2 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@google.com> Date: Tue, 30 Nov 2021 16:43:40 -0800 Subject: [PATCH 382/569] Just warn (don't fail) when the json_annotation constraint looks wrong Fixes https://github.com/google/json_serializable.dart/issues/1011 Fixes https://github.com/google/json_serializable.dart/issues/1014 Fixes https://github.com/google/json_serializable.dart/issues/1020 Fixes https://github.com/google/json_serializable.dart/issues/1025 --- json_serializable/CHANGELOG.md | 2 ++ json_serializable/lib/src/check_dependencies.dart | 12 +----------- json_serializable/test/annotation_version_test.dart | 8 +++----- 3 files changed, 6 insertions(+), 16 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 603ad4526..f74887b6b 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -2,6 +2,8 @@ - Support `JsonKey.readValue` to allow customized reading of values from source JSON map objects. +- The check to make sure there is a correctly constrained dependency on + `package:json_annotation` is now a warning and doesn't fail the build. - Require `json_annotation` `'>=4.4.0 <4.5.0'`. ## 6.0.1 diff --git a/json_serializable/lib/src/check_dependencies.dart b/json_serializable/lib/src/check_dependencies.dart index edeb2340c..e6cf92a85 100644 --- a/json_serializable/lib/src/check_dependencies.dart +++ b/json_serializable/lib/src/check_dependencies.dart @@ -51,7 +51,7 @@ Future<void> _validatePubspec(bool production, BuildStep buildStep) async { if (errorMessage == null) return; - throw BadPackageDependencyError(errorMessage); + log.warning(errorMessage); } String? _checkAnnotationConstraint( @@ -124,13 +124,3 @@ class _OncePerBuild { } } } - -/// Thrown when a pubspec dependency is missing or incorrectly specified. -class BadPackageDependencyError extends Error { - final String message; - - BadPackageDependencyError(this.message); - - @override - String toString() => message; -} diff --git a/json_serializable/test/annotation_version_test.dart b/json_serializable/test/annotation_version_test.dart index 1ba895866..e5431ec70 100644 --- a/json_serializable/test/annotation_version_test.dart +++ b/json_serializable/test/annotation_version_test.dart @@ -172,10 +172,8 @@ class SomeClass{} } expect(lines.toString(), contains(''' -[SEVERE] json_serializable:json_serializable on $sourceDirectory/sample.dart: +[WARNING] json_serializable:json_serializable on $sourceDirectory/sample.dart: +$message''')); -$message -''')); - - await proc.shouldExit(1); + await proc.shouldExit(0); } From cd77f7a3cf0fba34613c9f5ca15685b154f5327c Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Tue, 30 Nov 2021 17:07:22 -0800 Subject: [PATCH 383/569] Don't assume we need a constructor too early in build process (#1049) Fixes https://github.com/google/json_serializable.dart/issues/1038 --- json_serializable/lib/src/utils.dart | 20 ++++++++++++++++--- .../test/json_serializable_test.dart | 1 + .../src/_json_serializable_test_input.dart | 18 +++++++++++++++++ 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index 5614709ec..17130cddb 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -84,10 +84,12 @@ ClassConfig mergeConfig( assert(config.ctorParamDefaults.isEmpty); final constructor = annotation.constructor ?? config.constructor; - final constructorInstance = constructorByName(classElement, constructor); + final constructorInstance = + constructorByNameOrNull(classElement, constructor); - final paramDefaultValueMap = Map<String, String>.fromEntries( - constructorInstance.parameters + final paramDefaultValueMap = constructorInstance == null + ? <String, String>{} + : Map<String, String>.fromEntries(constructorInstance.parameters .where((element) => element.hasDefaultValue) .map((e) => MapEntry(e.name, e.defaultValueCode!))); @@ -110,6 +112,18 @@ ClassConfig mergeConfig( ); } +ConstructorElement? constructorByNameOrNull( + ClassElement classElement, + String name, +) { + try { + return constructorByName(classElement, name); + // ignore: avoid_catching_errors + } on InvalidGenerationSourceError { + return null; + } +} + ConstructorElement constructorByName(ClassElement classElement, String name) { final className = classElement.name; diff --git a/json_serializable/test/json_serializable_test.dart b/json_serializable/test/json_serializable_test.dart index b95f6183b..a8bd577e3 100644 --- a/json_serializable/test/json_serializable_test.dart +++ b/json_serializable/test/json_serializable_test.dart @@ -79,6 +79,7 @@ const _expectedAnnotatedTests = { 'InvalidFromFunc2Args', 'InvalidToFunc2Args', 'Issue713', + 'Issue1038RegressionTest', 'JsonConvertOnField', 'JsonConverterCtorParams', 'JsonConverterDuplicateAnnotations', diff --git a/json_serializable/test/src/_json_serializable_test_input.dart b/json_serializable/test/src/_json_serializable_test_input.dart index 72ab3c447..ac3cbda8b 100644 --- a/json_serializable/test/src/_json_serializable_test_input.dart +++ b/json_serializable/test/src/_json_serializable_test_input.dart @@ -561,3 +561,21 @@ class ExtraParamToJson { Map<String, dynamic> toJson(int bob) => throw UnimplementedError(); } + +@ShouldGenerate(r''' +Map<String, dynamic> _$Issue1038RegressionTestToJson( + Issue1038RegressionTest instance) => + <String, dynamic>{ + 'id': instance.id, + 'ean': instance.ean, + }; +''') +@JsonSerializable(createFactory: false) +class Issue1038RegressionTest { + final String? id; + final String? ean; + + Issue1038RegressionTest.id(this.id) : ean = null; + + Issue1038RegressionTest.ean(this.ean) : id = null; +} From 04af01c922930610af8328457eafd0927c1760b7 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Tue, 30 Nov 2021 17:07:35 -0800 Subject: [PATCH 384/569] beta release of pkg:json_annotation (#1050) To ensure it's backwards compatible --- json_annotation/CHANGELOG.md | 2 +- json_annotation/pubspec.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index 3ccaa294d..d75d325cb 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -1,4 +1,4 @@ -## 4.4.0-dev +## 4.4.0-beta.0 - Added `JsonKey.readValue`. - Non-breaking updates to `checkedCreate` and `checkedConvert` to support diff --git a/json_annotation/pubspec.yaml b/json_annotation/pubspec.yaml index 93fa3460e..aff03f861 100644 --- a/json_annotation/pubspec.yaml +++ b/json_annotation/pubspec.yaml @@ -1,5 +1,5 @@ name: json_annotation -version: 4.3.1-dev +version: 4.4.0-beta.0 description: >- Classes and helper functions that support JSON code generation via the `json_serializable` package. From 3cd08a811ae95876da3490323462f7113dd0c205 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Tue, 30 Nov 2021 17:28:31 -0800 Subject: [PATCH 385/569] json_annotation: prepare release (#1051) --- json_annotation/CHANGELOG.md | 2 +- json_annotation/pubspec.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index d75d325cb..3fd593498 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -1,4 +1,4 @@ -## 4.4.0-beta.0 +## 4.4.0 - Added `JsonKey.readValue`. - Non-breaking updates to `checkedCreate` and `checkedConvert` to support diff --git a/json_annotation/pubspec.yaml b/json_annotation/pubspec.yaml index aff03f861..d7601b2ff 100644 --- a/json_annotation/pubspec.yaml +++ b/json_annotation/pubspec.yaml @@ -1,5 +1,5 @@ name: json_annotation -version: 4.4.0-beta.0 +version: 4.4.0 description: >- Classes and helper functions that support JSON code generation via the `json_serializable` package. From 3c1a734aea14b98e970d8136bd4f1e822ad94929 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Tue, 30 Nov 2021 17:37:50 -0800 Subject: [PATCH 386/569] json_serializable: make things private that can be private (#1052) --- json_serializable/lib/src/utils.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index 17130cddb..b3d527ea3 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -85,7 +85,7 @@ ClassConfig mergeConfig( final constructor = annotation.constructor ?? config.constructor; final constructorInstance = - constructorByNameOrNull(classElement, constructor); + _constructorByNameOrNull(classElement, constructor); final paramDefaultValueMap = constructorInstance == null ? <String, String>{} @@ -112,7 +112,7 @@ ClassConfig mergeConfig( ); } -ConstructorElement? constructorByNameOrNull( +ConstructorElement? _constructorByNameOrNull( ClassElement classElement, String name, ) { From 1a8c00b068dae0aefe1e8764c0ba3c3f8d64cf86 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Tue, 30 Nov 2021 17:46:17 -0800 Subject: [PATCH 387/569] json_serializable: prepare to release v6.1.0 (#1053) --- json_serializable/CHANGELOG.md | 2 +- json_serializable/README.md | 16 ++++++++-------- json_serializable/pubspec.yaml | 6 +----- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index f74887b6b..478e68d8a 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,4 +1,4 @@ -## 6.1.0-dev +## 6.1.0 - Support `JsonKey.readValue` to allow customized reading of values from source JSON map objects. diff --git a/json_serializable/README.md b/json_serializable/README.md index ae17884c7..050319619 100644 --- a/json_serializable/README.md +++ b/json_serializable/README.md @@ -199,14 +199,14 @@ targets: [`Enum`]: https://api.dart.dev/stable/dart-core/Enum-class.html [`int`]: https://api.dart.dev/stable/dart-core/int-class.html [`Iterable`]: https://api.dart.dev/stable/dart-core/Iterable-class.html -[`JsonConverter`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonConverter-class.html -[`JsonEnum`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonEnum-class.html -[`JsonKey.fromJson`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/fromJson.html -[`JsonKey.toJson`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/toJson.html -[`JsonKey`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey-class.html -[`JsonLiteral`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonLiteral-class.html -[`JsonSerializable`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable-class.html -[`JsonValue`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonValue-class.html +[`JsonConverter`]: https://pub.dev/documentation/json_annotation/4.4.0/json_annotation/JsonConverter-class.html +[`JsonEnum`]: https://pub.dev/documentation/json_annotation/4.4.0/json_annotation/JsonEnum-class.html +[`JsonKey.fromJson`]: https://pub.dev/documentation/json_annotation/4.4.0/json_annotation/JsonKey/fromJson.html +[`JsonKey.toJson`]: https://pub.dev/documentation/json_annotation/4.4.0/json_annotation/JsonKey/toJson.html +[`JsonKey`]: https://pub.dev/documentation/json_annotation/4.4.0/json_annotation/JsonKey-class.html +[`JsonLiteral`]: https://pub.dev/documentation/json_annotation/4.4.0/json_annotation/JsonLiteral-class.html +[`JsonSerializable`]: https://pub.dev/documentation/json_annotation/4.4.0/json_annotation/JsonSerializable-class.html +[`JsonValue`]: https://pub.dev/documentation/json_annotation/4.4.0/json_annotation/JsonValue-class.html [`List`]: https://api.dart.dev/stable/dart-core/List-class.html [`Map`]: https://api.dart.dev/stable/dart-core/Map-class.html [`num`]: https://api.dart.dev/stable/dart-core/num-class.html diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 348e3b711..39120bf09 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 6.1.0-dev +version: 6.1.0 description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. @@ -35,7 +35,3 @@ dev_dependencies: test_descriptor: ^2.0.0 test_process: ^2.0.0 yaml: ^3.0.0 - -dependency_overrides: - json_annotation: - path: ../json_annotation From 39467a3753f5986a1c47d919888e7d4ea20d7c86 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Thu, 2 Dec 2021 11:00:21 -0800 Subject: [PATCH 388/569] Fix support for static functions with JsonKey.readValue (#1058) and prepare to release v6.1.1 Fixes https://github.com/google/json_serializable.dart/issues/1055 --- json_serializable/CHANGELOG.md | 4 ++++ json_serializable/lib/src/json_key_utils.dart | 4 ++-- json_serializable/lib/src/type_helper_ctx.dart | 8 +------- json_serializable/lib/src/utils.dart | 18 ++++++++++++++++++ json_serializable/pubspec.yaml | 2 +- .../test/kitchen_sink/kitchen_sink.dart | 14 +++++++++----- .../test/kitchen_sink/kitchen_sink.g.dart | 2 +- .../kitchen_sink/kitchen_sink.g_any_map.dart | 14 +++++++++----- .../kitchen_sink/kitchen_sink.g_any_map.g.dart | 2 +- .../kitchen_sink.g_any_map__checked.dart | 14 +++++++++----- .../kitchen_sink.g_any_map__checked.g.dart | 2 +- .../kitchen_sink.g_exclude_null.dart | 14 +++++++++----- .../kitchen_sink.g_exclude_null.g.dart | 2 +- .../kitchen_sink.g_explicit_to_json.dart | 14 +++++++++----- .../kitchen_sink.g_explicit_to_json.g.dart | 2 +- 15 files changed, 76 insertions(+), 40 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 478e68d8a..24b8bbd51 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,7 @@ +## 6.1.1 + +- Fix `JsonKey.readValue` support to allow static functions. + ## 6.1.0 - Support `JsonKey.readValue` to allow customized reading of values from source diff --git a/json_serializable/lib/src/json_key_utils.dart b/json_serializable/lib/src/json_key_utils.dart index c565282ad..3d2543163 100644 --- a/json_serializable/lib/src/json_key_utils.dart +++ b/json_serializable/lib/src/json_key_utils.dart @@ -212,8 +212,8 @@ KeyConfig _from(FieldElement element, ClassConfig classAnnotation) { String? readValueFunctionName; final readValue = obj.read('readValue'); if (!readValue.isNull) { - final objValue = readValue.objectValue.toFunctionValue()!; - readValueFunctionName = objValue.name; + readValueFunctionName = + readValue.objectValue.toFunctionValue()!.qualifiedName; } return _populateJsonKey( diff --git a/json_serializable/lib/src/type_helper_ctx.dart b/json_serializable/lib/src/type_helper_ctx.dart index a601f7bc3..9928e459b 100644 --- a/json_serializable/lib/src/type_helper_ctx.dart +++ b/json_serializable/lib/src/type_helper_ctx.dart @@ -176,11 +176,5 @@ ConvertData? _convertData(DartObject obj, FieldElement element, bool isFrom) { } } - var name = executableElement.name; - - if (executableElement is MethodElement) { - name = '${executableElement.enclosingElement.name}.$name'; - } - - return ConvertData(name, argType); + return ConvertData(executableElement.qualifiedName, argType); } diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index b3d527ea3..5eda053e0 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -207,3 +207,21 @@ String typeToCode( } throw UnimplementedError('(${type.runtimeType}) $type'); } + +extension ExecutableElementExtension on ExecutableElement { + /// Returns the name of `this` qualified with the class name if it's a + /// [MethodElement]. + String get qualifiedName { + if (this is FunctionElement) { + return name; + } + + if (this is MethodElement) { + return '${enclosingElement.name}.$name'; + } + + throw UnsupportedError( + 'Not sure how to support typeof $runtimeType', + ); + } +} diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 39120bf09..8e9cf5578 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 6.1.0 +version: 6.1.1 description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.dart b/json_serializable/test/kitchen_sink/kitchen_sink.dart index bdde73b01..92bd1c94d 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.dart @@ -76,10 +76,6 @@ class _Factory implements k.KitchenSinkFactory<String, dynamic> { } Object? _valueAccessor(Map json, String key) { - if (key == k.trickyKeyName) { - return json[k.trickyKeyName] ?? json['STRING']; - } - if (key == 'iterable') { return json['iterable'] ?? json['theIterable']; } @@ -165,7 +161,7 @@ class KitchenSink implements k.KitchenSink { // Handle fields with names that collide with helper names Map<String, bool> val = _defaultMap(); bool? writeNotNull; - @JsonKey(name: k.trickyKeyName, readValue: _valueAccessor) + @JsonKey(name: k.trickyKeyName, readValue: _trickyValueAccessor) String? string; SimpleObject simpleObject = _defaultSimpleObject(); @@ -184,6 +180,14 @@ class KitchenSink implements k.KitchenSink { } bool operator ==(Object other) => k.sinkEquals(this, other); + + static Object? _trickyValueAccessor(Map json, String key) { + if (key == k.trickyKeyName) { + return json[k.trickyKeyName] ?? json['STRING']; + } + + return json[key]; + } } @JsonSerializable() diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g.dart index d4feec78a..ec7fa097c 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g.dart @@ -80,7 +80,7 @@ KitchenSink _$KitchenSinkFromJson(Map<String, dynamic> json) => KitchenSink( .toList() ..val = Map<String, bool>.from(json['val'] as Map) ..writeNotNull = json['writeNotNull'] as bool? - ..string = _valueAccessor(json, r'$string') as String? + ..string = KitchenSink._trickyValueAccessor(json, r'$string') as String? ..simpleObject = SimpleObject.fromJson(json['simpleObject'] as Map<String, dynamic>) ..strictKeysObject = StrictKeysObject.fromJson( diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart index d0d8f49ad..bf82df50d 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart @@ -75,10 +75,6 @@ class _Factory implements k.KitchenSinkFactory<dynamic, dynamic> { } Object? _valueAccessor(Map json, String key) { - if (key == k.trickyKeyName) { - return json[k.trickyKeyName] ?? json['STRING']; - } - if (key == 'iterable') { return json['iterable'] ?? json['theIterable']; } @@ -165,7 +161,7 @@ class KitchenSink implements k.KitchenSink { // Handle fields with names that collide with helper names Map<String, bool> val = _defaultMap(); bool? writeNotNull; - @JsonKey(name: k.trickyKeyName, readValue: _valueAccessor) + @JsonKey(name: k.trickyKeyName, readValue: _trickyValueAccessor) String? string; SimpleObject simpleObject = _defaultSimpleObject(); @@ -184,6 +180,14 @@ class KitchenSink implements k.KitchenSink { } bool operator ==(Object other) => k.sinkEquals(this, other); + + static Object? _trickyValueAccessor(Map json, String key) { + if (key == k.trickyKeyName) { + return json[k.trickyKeyName] ?? json['STRING']; + } + + return json[key]; + } } @JsonSerializable( diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart index e05b1f53d..16d995c98 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart @@ -73,7 +73,7 @@ KitchenSink _$KitchenSinkFromJson(Map json) => KitchenSink( .toList() ..val = Map<String, bool>.from(json['val'] as Map) ..writeNotNull = json['writeNotNull'] as bool? - ..string = _valueAccessor(json, r'$string') as String? + ..string = KitchenSink._trickyValueAccessor(json, r'$string') as String? ..simpleObject = SimpleObject.fromJson(json['simpleObject'] as Map) ..strictKeysObject = StrictKeysObject.fromJson(json['strictKeysObject'] as Map) diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.dart index c6d326c54..0a5119aa5 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.dart @@ -75,10 +75,6 @@ class _Factory implements k.KitchenSinkFactory<dynamic, dynamic> { } Object? _valueAccessor(Map json, String key) { - if (key == k.trickyKeyName) { - return json[k.trickyKeyName] ?? json['STRING']; - } - if (key == 'iterable') { return json['iterable'] ?? json['theIterable']; } @@ -166,7 +162,7 @@ class KitchenSink implements k.KitchenSink { // Handle fields with names that collide with helper names Map<String, bool> val = _defaultMap(); bool? writeNotNull; - @JsonKey(name: k.trickyKeyName, readValue: _valueAccessor) + @JsonKey(name: k.trickyKeyName, readValue: _trickyValueAccessor) String? string; SimpleObject simpleObject = _defaultSimpleObject(); @@ -185,6 +181,14 @@ class KitchenSink implements k.KitchenSink { } bool operator ==(Object other) => k.sinkEquals(this, other); + + static Object? _trickyValueAccessor(Map json, String key) { + if (key == k.trickyKeyName) { + return json[k.trickyKeyName] ?? json['STRING']; + } + + return json[key]; + } } @JsonSerializable( diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.g.dart index 38c2b8109..8be98d6cb 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.g.dart @@ -113,7 +113,7 @@ KitchenSink _$KitchenSinkFromJson(Map json) => $checkedCreate( $checkedConvert( r'$string', (v) => val.string = v as String?, - readValue: _valueAccessor, + readValue: KitchenSink._trickyValueAccessor, ); $checkedConvert('simpleObject', (v) => val.simpleObject = SimpleObject.fromJson(v as Map)); diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.dart index 11d68878b..5927b1aaa 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.dart @@ -76,10 +76,6 @@ class _Factory implements k.KitchenSinkFactory<String, dynamic> { } Object? _valueAccessor(Map json, String key) { - if (key == k.trickyKeyName) { - return json[k.trickyKeyName] ?? json['STRING']; - } - if (key == 'iterable') { return json['iterable'] ?? json['theIterable']; } @@ -167,7 +163,7 @@ class KitchenSink implements k.KitchenSink { // Handle fields with names that collide with helper names Map<String, bool> val = _defaultMap(); bool? writeNotNull; - @JsonKey(name: k.trickyKeyName, readValue: _valueAccessor) + @JsonKey(name: k.trickyKeyName, readValue: _trickyValueAccessor) String? string; SimpleObject simpleObject = _defaultSimpleObject(); @@ -186,6 +182,14 @@ class KitchenSink implements k.KitchenSink { } bool operator ==(Object other) => k.sinkEquals(this, other); + + static Object? _trickyValueAccessor(Map json, String key) { + if (key == k.trickyKeyName) { + return json[k.trickyKeyName] ?? json['STRING']; + } + + return json[key]; + } } @JsonSerializable( diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart index fd7d40925..6afeb29a2 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart @@ -80,7 +80,7 @@ KitchenSink _$KitchenSinkFromJson(Map<String, dynamic> json) => KitchenSink( .toList() ..val = Map<String, bool>.from(json['val'] as Map) ..writeNotNull = json['writeNotNull'] as bool? - ..string = _valueAccessor(json, r'$string') as String? + ..string = KitchenSink._trickyValueAccessor(json, r'$string') as String? ..simpleObject = SimpleObject.fromJson(json['simpleObject'] as Map<String, dynamic>) ..strictKeysObject = StrictKeysObject.fromJson( diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.dart index f5707afa4..bce55d5f0 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.dart @@ -76,10 +76,6 @@ class _Factory implements k.KitchenSinkFactory<String, dynamic> { } Object? _valueAccessor(Map json, String key) { - if (key == k.trickyKeyName) { - return json[k.trickyKeyName] ?? json['STRING']; - } - if (key == 'iterable') { return json['iterable'] ?? json['theIterable']; } @@ -167,7 +163,7 @@ class KitchenSink implements k.KitchenSink { // Handle fields with names that collide with helper names Map<String, bool> val = _defaultMap(); bool? writeNotNull; - @JsonKey(name: k.trickyKeyName, readValue: _valueAccessor) + @JsonKey(name: k.trickyKeyName, readValue: _trickyValueAccessor) String? string; SimpleObject simpleObject = _defaultSimpleObject(); @@ -186,6 +182,14 @@ class KitchenSink implements k.KitchenSink { } bool operator ==(Object other) => k.sinkEquals(this, other); + + static Object? _trickyValueAccessor(Map json, String key) { + if (key == k.trickyKeyName) { + return json[k.trickyKeyName] ?? json['STRING']; + } + + return json[key]; + } } @JsonSerializable( diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart index 301c75b29..cb0415623 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart @@ -80,7 +80,7 @@ KitchenSink _$KitchenSinkFromJson(Map<String, dynamic> json) => KitchenSink( .toList() ..val = Map<String, bool>.from(json['val'] as Map) ..writeNotNull = json['writeNotNull'] as bool? - ..string = _valueAccessor(json, r'$string') as String? + ..string = KitchenSink._trickyValueAccessor(json, r'$string') as String? ..simpleObject = SimpleObject.fromJson(json['simpleObject'] as Map<String, dynamic>) ..strictKeysObject = StrictKeysObject.fromJson( From c8474bf67348e6a0944f35f9def7a608774aa3c1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 5 Dec 2021 20:44:47 -0800 Subject: [PATCH 389/569] Bump actions/setup-node from 2.4.1 to 2.5.0 (#1059) Bumps [actions/setup-node](https://github.com/actions/setup-node) from 2.4.1 to 2.5.0. - [Release notes](https://github.com/actions/setup-node/releases) - [Commits](https://github.com/actions/setup-node/compare/v2.4.1...v2.5.0) --- updated-dependencies: - dependency-name: actions/setup-node dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/markdown_linter.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/markdown_linter.yml b/.github/workflows/markdown_linter.yml index f5ac406d6..89ffdaeb3 100644 --- a/.github/workflows/markdown_linter.yml +++ b/.github/workflows/markdown_linter.yml @@ -21,7 +21,7 @@ jobs: steps: - uses: actions/checkout@v2.3.5 - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v2.4.1 + uses: actions/setup-node@v2.5.0 with: node-version: ${{ matrix.node-version }} - name: Install dependencies From 1b46dce943876e8a01aa7e48a4f662a4775aee96 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@google.com> Date: Fri, 10 Dec 2021 13:26:35 -0800 Subject: [PATCH 390/569] latest mono_repo --- .github/workflows/dart.yml | 78 ++++++++++++++++----------------- _test_yaml/mono_pkg.yaml | 2 +- checked_yaml/mono_pkg.yaml | 2 +- example/mono_pkg.yaml | 2 +- json_annotation/mono_pkg.yaml | 2 +- json_serializable/mono_pkg.yaml | 2 +- tool/ci.sh | 2 +- 7 files changed, 45 insertions(+), 45 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index dcf06c94f..bfb04f032 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -1,4 +1,4 @@ -# Created with package:mono_repo v5.0.5 +# Created with package:mono_repo v6.0.0 name: Dart CI on: push: @@ -23,7 +23,7 @@ jobs: uses: actions/cache@v2.1.7 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;dart:stable" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:stable" restore-keys: | os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest @@ -33,7 +33,7 @@ jobs: - id: checkout uses: actions/checkout@v2.4.0 - name: mono_repo self validate - run: dart pub global activate mono_repo 5.0.5 + run: dart pub global activate mono_repo 6.0.0 - name: mono_repo self validate run: dart pub global run mono_repo generate --validate job_002: @@ -44,10 +44,10 @@ jobs: uses: actions/cache@v2.1.7 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;dart:2.14.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:format-analyze" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.14.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:format-analyze" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;dart:2.14.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable - os:ubuntu-latest;pub-cache-hosted;dart:2.14.0 + os:ubuntu-latest;pub-cache-hosted;sdk:2.14.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable + os:ubuntu-latest;pub-cache-hosted;sdk:2.14.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - uses: dart-lang/setup-dart@v1.3 @@ -128,10 +128,10 @@ jobs: uses: actions/cache@v2.1.7 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:format-analyze" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:format-analyze" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable - os:ubuntu-latest;pub-cache-hosted;dart:dev + os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable + os:ubuntu-latest;pub-cache-hosted;sdk:dev os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - uses: dart-lang/setup-dart@v1.3 @@ -212,10 +212,10 @@ jobs: uses: actions/cache@v2.1.7 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;dart:2.14.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.14.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;dart:2.14.0;packages:_test_yaml-checked_yaml-example-json_serializable - os:ubuntu-latest;pub-cache-hosted;dart:2.14.0 + os:ubuntu-latest;pub-cache-hosted;sdk:2.14.0;packages:_test_yaml-checked_yaml-example-json_serializable + os:ubuntu-latest;pub-cache-hosted;sdk:2.14.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - uses: dart-lang/setup-dart@v1.3 @@ -271,10 +271,10 @@ jobs: uses: actions/cache@v2.1.7 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;dart:2.14.0;packages:json_serializable;commands:test_3" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.14.0;packages:json_serializable;commands:test_3" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;dart:2.14.0;packages:json_serializable - os:ubuntu-latest;pub-cache-hosted;dart:2.14.0 + os:ubuntu-latest;pub-cache-hosted;sdk:2.14.0;packages:json_serializable + os:ubuntu-latest;pub-cache-hosted;sdk:2.14.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - uses: dart-lang/setup-dart@v1.3 @@ -303,10 +303,10 @@ jobs: uses: actions/cache@v2.1.7 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;dart:2.14.0;packages:json_serializable;commands:test_1" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.14.0;packages:json_serializable;commands:test_1" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;dart:2.14.0;packages:json_serializable - os:ubuntu-latest;pub-cache-hosted;dart:2.14.0 + os:ubuntu-latest;pub-cache-hosted;sdk:2.14.0;packages:json_serializable + os:ubuntu-latest;pub-cache-hosted;sdk:2.14.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - uses: dart-lang/setup-dart@v1.3 @@ -335,10 +335,10 @@ jobs: uses: actions/cache@v2.1.7 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;dart:2.14.0;packages:json_serializable;commands:test_2" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.14.0;packages:json_serializable;commands:test_2" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;dart:2.14.0;packages:json_serializable - os:ubuntu-latest;pub-cache-hosted;dart:2.14.0 + os:ubuntu-latest;pub-cache-hosted;sdk:2.14.0;packages:json_serializable + os:ubuntu-latest;pub-cache-hosted;sdk:2.14.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - uses: dart-lang/setup-dart@v1.3 @@ -367,10 +367,10 @@ jobs: uses: actions/cache@v2.1.7 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:_test_yaml-checked_yaml-example-json_serializable - os:ubuntu-latest;pub-cache-hosted;dart:dev + os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:_test_yaml-checked_yaml-example-json_serializable + os:ubuntu-latest;pub-cache-hosted;sdk:dev os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - uses: dart-lang/setup-dart@v1.3 @@ -426,10 +426,10 @@ jobs: uses: actions/cache@v2.1.7 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:json_serializable;commands:test_3" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:json_serializable;commands:test_3" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:json_serializable - os:ubuntu-latest;pub-cache-hosted;dart:dev + os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:json_serializable + os:ubuntu-latest;pub-cache-hosted;sdk:dev os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - uses: dart-lang/setup-dart@v1.3 @@ -458,10 +458,10 @@ jobs: uses: actions/cache@v2.1.7 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:json_serializable;commands:test_1" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:json_serializable;commands:test_1" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:json_serializable - os:ubuntu-latest;pub-cache-hosted;dart:dev + os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:json_serializable + os:ubuntu-latest;pub-cache-hosted;sdk:dev os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - uses: dart-lang/setup-dart@v1.3 @@ -490,10 +490,10 @@ jobs: uses: actions/cache@v2.1.7 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:json_serializable;commands:test_2" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:json_serializable;commands:test_2" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:json_serializable - os:ubuntu-latest;pub-cache-hosted;dart:dev + os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:json_serializable + os:ubuntu-latest;pub-cache-hosted;sdk:dev os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - uses: dart-lang/setup-dart@v1.3 @@ -522,10 +522,10 @@ jobs: uses: actions/cache@v2.1.7 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;dart:2.14.0;packages:_test_yaml-checked_yaml-example;commands:test_1" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.14.0;packages:_test_yaml-checked_yaml-example;commands:test_1" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;dart:2.14.0;packages:_test_yaml-checked_yaml-example - os:ubuntu-latest;pub-cache-hosted;dart:2.14.0 + os:ubuntu-latest;pub-cache-hosted;sdk:2.14.0;packages:_test_yaml-checked_yaml-example + os:ubuntu-latest;pub-cache-hosted;sdk:2.14.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - uses: dart-lang/setup-dart@v1.3 @@ -580,10 +580,10 @@ jobs: uses: actions/cache@v2.1.7 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:_test_yaml-checked_yaml-example;commands:test_1" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:_test_yaml-checked_yaml-example;commands:test_1" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:_test_yaml-checked_yaml-example - os:ubuntu-latest;pub-cache-hosted;dart:dev + os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:_test_yaml-checked_yaml-example + os:ubuntu-latest;pub-cache-hosted;sdk:dev os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - uses: dart-lang/setup-dart@v1.3 diff --git a/_test_yaml/mono_pkg.yaml b/_test_yaml/mono_pkg.yaml index f508952d2..f2999e505 100644 --- a/_test_yaml/mono_pkg.yaml +++ b/_test_yaml/mono_pkg.yaml @@ -1,5 +1,5 @@ # See https://github.com/google/mono_repo.dart for details on this file -dart: +sdk: - 2.14.0 - dev diff --git a/checked_yaml/mono_pkg.yaml b/checked_yaml/mono_pkg.yaml index 133bdf513..11ce57bf7 100644 --- a/checked_yaml/mono_pkg.yaml +++ b/checked_yaml/mono_pkg.yaml @@ -1,5 +1,5 @@ # See https://github.com/google/mono_repo.dart for details on this file -dart: +sdk: - 2.14.0 - dev diff --git a/example/mono_pkg.yaml b/example/mono_pkg.yaml index 06efa807f..1cbcbed1d 100644 --- a/example/mono_pkg.yaml +++ b/example/mono_pkg.yaml @@ -1,5 +1,5 @@ # See https://github.com/google/mono_repo.dart for details on this file -dart: +sdk: - 2.14.0 - dev diff --git a/json_annotation/mono_pkg.yaml b/json_annotation/mono_pkg.yaml index aa7c47dab..24925dbb7 100644 --- a/json_annotation/mono_pkg.yaml +++ b/json_annotation/mono_pkg.yaml @@ -1,5 +1,5 @@ # See https://github.com/google/mono_repo.dart for details on this file -dart: +sdk: - 2.14.0 - dev diff --git a/json_serializable/mono_pkg.yaml b/json_serializable/mono_pkg.yaml index fbc055781..46c30da01 100644 --- a/json_serializable/mono_pkg.yaml +++ b/json_serializable/mono_pkg.yaml @@ -1,5 +1,5 @@ # See https://github.com/google/mono_repo.dart for details on this file -dart: +sdk: - 2.14.0 - dev diff --git a/tool/ci.sh b/tool/ci.sh index 0125be6d4..14253e00a 100755 --- a/tool/ci.sh +++ b/tool/ci.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Created with package:mono_repo v5.0.5 +# Created with package:mono_repo v6.0.0 # Support built in commands on windows out of the box. # When it is a flutter repo (check the pubspec.yaml for "sdk: flutter") From 2d660a482971607b6b768680d1b48ed56ad04203 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@google.com> Date: Fri, 10 Dec 2021 13:28:19 -0800 Subject: [PATCH 391/569] latest build_verify --- _test_yaml/pubspec.yaml | 2 +- checked_yaml/pubspec.yaml | 2 +- example/pubspec.yaml | 2 +- json_serializable/pubspec.yaml | 2 +- json_serializable/test/ensure_build_test.dart | 7 +++++-- 5 files changed, 9 insertions(+), 6 deletions(-) diff --git a/_test_yaml/pubspec.yaml b/_test_yaml/pubspec.yaml index 24c036c12..a07c3df6a 100644 --- a/_test_yaml/pubspec.yaml +++ b/_test_yaml/pubspec.yaml @@ -6,7 +6,7 @@ environment: dev_dependencies: build_runner: ^2.0.0 - build_verify: ^2.0.0 + build_verify: ^3.0.0 checked_yaml: any json_annotation: ^4.4.0 json_serializable: any diff --git a/checked_yaml/pubspec.yaml b/checked_yaml/pubspec.yaml index ee79d69ec..1d8f36ae6 100644 --- a/checked_yaml/pubspec.yaml +++ b/checked_yaml/pubspec.yaml @@ -15,7 +15,7 @@ dependencies: dev_dependencies: build_runner: ^2.0.0 - build_verify: ^2.0.0 + build_verify: ^3.0.0 json_serializable: ^6.0.0 path: ^1.0.0 test: ^1.16.0 diff --git a/example/pubspec.yaml b/example/pubspec.yaml index fd2b789bf..243756f68 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -11,7 +11,7 @@ dev_dependencies: build_runner: ^2.0.0 # Used by tests. Not required to use `json_serializable`. - build_verify: ^2.0.0 + build_verify: ^3.0.0 json_serializable: ^6.0.0 diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 8e9cf5578..a77ddeae1 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -26,7 +26,7 @@ dependencies: dev_dependencies: build_runner: ^2.0.0 - build_verify: ^2.0.0 + build_verify: ^3.0.0 dart_style: ^2.0.0 logging: ^1.0.0 source_gen_test: ^1.0.0 diff --git a/json_serializable/test/ensure_build_test.dart b/json_serializable/test/ensure_build_test.dart index 487646cb3..de538c834 100644 --- a/json_serializable/test/ensure_build_test.dart +++ b/json_serializable/test/ensure_build_test.dart @@ -8,6 +8,9 @@ import 'package:build_verify/build_verify.dart'; import 'package:test/test.dart'; void main() { - test('ensure_build', - () => expectBuildClean(packageRelativeDirectory: 'json_serializable')); + test( + 'ensure_build', + () => expectBuildClean(packageRelativeDirectory: 'json_serializable'), + timeout: const Timeout.factor(2), + ); } From c03e84b94dc43c3e4f498a540d282bb3c5154137 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@google.com> Date: Thu, 16 Dec 2021 11:30:17 -0800 Subject: [PATCH 392/569] Add 2x timeout factor to all "ensure_build" tests --- _test_yaml/test/ensure_build_test.dart | 7 +++++-- checked_yaml/test/ensure_build_test.dart | 7 +++++-- example/test/ensure_build_test.dart | 7 +++++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/_test_yaml/test/ensure_build_test.dart b/_test_yaml/test/ensure_build_test.dart index acd110e44..4de07e5ee 100644 --- a/_test_yaml/test/ensure_build_test.dart +++ b/_test_yaml/test/ensure_build_test.dart @@ -8,6 +8,9 @@ import 'package:build_verify/build_verify.dart'; import 'package:test/test.dart'; void main() { - test('ensure_build', - () => expectBuildClean(packageRelativeDirectory: '_test_yaml')); + test( + 'ensure_build', + () => expectBuildClean(packageRelativeDirectory: '_test_yaml'), + timeout: const Timeout.factor(2), + ); } diff --git a/checked_yaml/test/ensure_build_test.dart b/checked_yaml/test/ensure_build_test.dart index bcb52649d..088218dcf 100644 --- a/checked_yaml/test/ensure_build_test.dart +++ b/checked_yaml/test/ensure_build_test.dart @@ -8,6 +8,9 @@ import 'package:build_verify/build_verify.dart'; import 'package:test/test.dart'; void main() { - test('ensure_build', - () => expectBuildClean(packageRelativeDirectory: 'checked_yaml')); + test( + 'ensure_build', + () => expectBuildClean(packageRelativeDirectory: 'checked_yaml'), + timeout: const Timeout.factor(2), + ); } diff --git a/example/test/ensure_build_test.dart b/example/test/ensure_build_test.dart index a927b47a9..7fd35a448 100644 --- a/example/test/ensure_build_test.dart +++ b/example/test/ensure_build_test.dart @@ -7,6 +7,9 @@ import 'package:build_verify/build_verify.dart'; import 'package:test/test.dart'; void main() { - test('ensure_build', - () => expectBuildClean(packageRelativeDirectory: 'example')); + test( + 'ensure_build', + () => expectBuildClean(packageRelativeDirectory: 'example'), + timeout: const Timeout.factor(2), + ); } From 13fe0c8e58f24363e3b80c7584c06195aadda005 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@google.com> Date: Thu, 16 Dec 2021 11:17:01 -0800 Subject: [PATCH 393/569] Fix issue with nested generics and `genericArgumentFactories: true` Fixes https://github.com/google/json_serializable.dart/issues/1047 --- json_serializable/CHANGELOG.md | 5 +++ json_serializable/lib/src/utils.dart | 4 ++ json_serializable/pubspec.yaml | 2 +- .../test/generic_files/generic_class.dart | 32 +++++++++++++++ .../test/generic_files/generic_class.g.dart | 39 +++++++++++++++++++ .../test/generic_files/generic_test.dart | 29 ++++++++++++++ 6 files changed, 110 insertions(+), 1 deletion(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 24b8bbd51..db911b7e1 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,8 @@ +## 6.1.2 + +- Fix issue with nested generics and `genericArgumentFactories: true`. + ([#1047](https://github.com/google/json_serializable.dart/issues/1047)) + ## 6.1.1 - Fix `JsonKey.readValue` support to allow static functions. diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index 5eda053e0..50362abe9 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -205,6 +205,10 @@ String typeToCode( (type.isNullableType || forceNullable) ? '?' : '', ].join(); } + + if (type is TypeParameterType) { + return type.getDisplayString(withNullability: false); + } throw UnimplementedError('(${type.runtimeType}) $type'); } diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index a77ddeae1..38fcbbd1c 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 6.1.1 +version: 6.1.2 description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. diff --git a/json_serializable/test/generic_files/generic_class.dart b/json_serializable/test/generic_files/generic_class.dart index d0fbd6e0b..6149d8dba 100644 --- a/json_serializable/test/generic_files/generic_class.dart +++ b/json_serializable/test/generic_files/generic_class.dart @@ -143,3 +143,35 @@ class Issue980ParentClass { @override int get hashCode => const DeepCollectionEquality().hash(list); } + +@JsonSerializable(genericArgumentFactories: true) +class Issue1047ParentClass<T> { + Issue1047ParentClass({required this.edges}); + + factory Issue1047ParentClass.fromJson( + Map<String, dynamic> json, T Function(Object? json) fromJsonT) => + _$Issue1047ParentClassFromJson<T>(json, fromJsonT); + + final List<Issue1047Class<T>> edges; + + Map<String, dynamic> toJson(Object? Function(T value) toJsonT) => + _$Issue1047ParentClassToJson(this, toJsonT); +} + +@JsonSerializable(genericArgumentFactories: true) +class Issue1047Class<T> { + Issue1047Class({ + required this.node, + }); + + factory Issue1047Class.fromJson( + Map<String, dynamic> json, + T Function(Object? json) fromJsonT, + ) => + _$Issue1047ClassFromJson<T>(json, fromJsonT); + + final T node; + + Map<String, dynamic> toJson(Object? Function(T value) toJsonT) => + _$Issue1047ClassToJson(this, toJsonT); +} diff --git a/json_serializable/test/generic_files/generic_class.g.dart b/json_serializable/test/generic_files/generic_class.g.dart index dd2bb6db8..e45e840d4 100644 --- a/json_serializable/test/generic_files/generic_class.g.dart +++ b/json_serializable/test/generic_files/generic_class.g.dart @@ -75,3 +75,42 @@ Map<String, dynamic> _$Issue980ParentClassToJson( <String, dynamic>{ 'list': instance.list, }; + +Issue1047ParentClass<T> _$Issue1047ParentClassFromJson<T>( + Map<String, dynamic> json, + T Function(Object? json) fromJsonT, +) => + Issue1047ParentClass<T>( + edges: (json['edges'] as List<dynamic>) + .map((e) => Issue1047Class<T>.fromJson( + e as Map<String, dynamic>, (value) => fromJsonT(value))) + .toList(), + ); + +Map<String, dynamic> _$Issue1047ParentClassToJson<T>( + Issue1047ParentClass<T> instance, + Object? Function(T value) toJsonT, +) => + <String, dynamic>{ + 'edges': instance.edges + .map((e) => e.toJson( + (value) => toJsonT(value), + )) + .toList(), + }; + +Issue1047Class<T> _$Issue1047ClassFromJson<T>( + Map<String, dynamic> json, + T Function(Object? json) fromJsonT, +) => + Issue1047Class<T>( + node: fromJsonT(json['node']), + ); + +Map<String, dynamic> _$Issue1047ClassToJson<T>( + Issue1047Class<T> instance, + Object? Function(T value) toJsonT, +) => + <String, dynamic>{ + 'node': toJsonT(instance.node), + }; diff --git a/json_serializable/test/generic_files/generic_test.dart b/json_serializable/test/generic_files/generic_test.dart index f3de54bd7..7b38c1c65 100644 --- a/json_serializable/test/generic_files/generic_test.dart +++ b/json_serializable/test/generic_files/generic_test.dart @@ -326,4 +326,33 @@ void main() { (json) => Issue980ParentClass.fromJson(json), ); }); + + test('issue 1047 regression', () { + _roundTrip( + sourceJson: { + 'edges': [ + {'node': '42'} + ] + }, + genericEncode: (o) => o.toString(), + genericDecode: (o) => int.parse(o as String), + ); + }); +} + +void _roundTrip<T>({ + required Map<String, dynamic> sourceJson, + required Object? Function(T) genericEncode, + required T Function(Object?) genericDecode, +}) { + final json = jsonEncode(sourceJson); + + final instance2 = Issue1047ParentClass<T>.fromJson( + jsonDecode(json) as Map<String, dynamic>, + genericDecode, + ); + + final json2 = jsonEncode(instance2.toJson(genericEncode)); + + expect(json2, json); } From d2e6a414abb74dadb587542b43017136962d4e6a Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Thu, 16 Dec 2021 19:03:13 -0800 Subject: [PATCH 394/569] Allow latest pkg:analyzer, prepare pkg:json_serializable v6.1.3 (#1069) --- json_serializable/CHANGELOG.md | 4 ++++ json_serializable/pubspec.yaml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index db911b7e1..890d9bbfa 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,7 @@ +## 6.1.3 + +- Allow latest `package:analyzer`. + ## 6.1.2 - Fix issue with nested generics and `genericArgumentFactories: true`. diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 38fcbbd1c..e8985525c 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -8,7 +8,7 @@ environment: sdk: '>=2.14.0 <3.0.0' dependencies: - analyzer: ^2.0.0 + analyzer: '>=2.0.0 <4.0.0' async: ^2.8.0 build: ^2.0.0 build_config: '>=0.4.4 <2.0.0' From b8c6f5af479e181474bfd2facda400e5c844f28b Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@google.com> Date: Thu, 16 Dec 2021 19:04:16 -0800 Subject: [PATCH 395/569] fix version --- json_serializable/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index e8985525c..58b75337c 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 6.1.2 +version: 6.1.3 description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. From ad413769b3d7b2c2f1bcf223a9e845fbeeeb70d3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 3 Jan 2022 12:00:25 -0800 Subject: [PATCH 396/569] Bump actions/setup-node from 2.5.0 to 2.5.1 (#1079) Bumps [actions/setup-node](https://github.com/actions/setup-node) from 2.5.0 to 2.5.1. - [Release notes](https://github.com/actions/setup-node/releases) - [Commits](https://github.com/actions/setup-node/compare/v2.5.0...v2.5.1) --- updated-dependencies: - dependency-name: actions/setup-node dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/markdown_linter.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/markdown_linter.yml b/.github/workflows/markdown_linter.yml index 89ffdaeb3..6ef9afa89 100644 --- a/.github/workflows/markdown_linter.yml +++ b/.github/workflows/markdown_linter.yml @@ -21,7 +21,7 @@ jobs: steps: - uses: actions/checkout@v2.3.5 - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v2.5.0 + uses: actions/setup-node@v2.5.1 with: node-version: ${{ matrix.node-version }} - name: Install dependencies From 6cef1eb6cd5fb263be836f3c8c620f19f8e34f1e Mon Sep 17 00:00:00 2001 From: Evan Weible <evan.weible@workiva.com> Date: Wed, 5 Jan 2022 17:41:01 -0700 Subject: [PATCH 397/569] [Backpatch to v3] Widen analyzer range to allow v1 (#1082) --- .github/workflows/dart.yml | 497 +++++++++++++----- _test_yaml/mono_pkg.yaml | 12 +- _test_yaml/pubspec.yaml | 1 + checked_yaml/mono_pkg.yaml | 12 +- checked_yaml/pubspec.yaml | 1 + example/mono_pkg.yaml | 14 +- example/pubspec.yaml | 8 + json_annotation/mono_pkg.yaml | 10 +- json_serializable/CHANGELOG.md | 4 + json_serializable/mono_pkg.yaml | 14 +- json_serializable/pubspec.yaml | 20 +- .../test/kitchen_sink/kitchen_sink_test.dart | 2 +- json_serializable/tool/shared.dart | 2 +- tool/ci.sh | 69 +-- 14 files changed, 460 insertions(+), 206 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index f861ae144..e5af09b4c 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -1,4 +1,4 @@ -# Created with package:mono_repo v3.3.0 +# Created with package:mono_repo v5.0.0 name: Dart CI on: push: @@ -20,232 +20,471 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v2 + uses: actions/cache@v2.1.6 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;dart:stable" restore-keys: | os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: cedx/setup-dart@v2 - with: - release-channel: stable - version: latest - - run: dart --version - - uses: actions/checkout@v2 - - run: pub global activate mono_repo 3.3.0 - - run: pub global run mono_repo generate --validate + - uses: dart-lang/setup-dart@v1.0 + with: + sdk: stable + - id: checkout + uses: actions/checkout@v2.3.4 + - name: mono_repo self validate + run: dart pub global activate mono_repo 5.0.0 + - name: mono_repo self validate + run: dart pub global run mono_repo generate --validate job_002: - name: "OS: linux; SDK: dev; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; TASKS: [`dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-warnings --fatal-infos .`]" + name: "analyzer_and_format; Dart 2.13.4; PKGS: _test_yaml, checked_yaml; `dart format --output=none --set-exit-if-changed .`, `dart analyze --fatal-warnings --fatal-infos .`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v2 + uses: actions/cache@v2.1.6 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:dartfmt-dartanalyzer_0" + key: "os:ubuntu-latest;pub-cache-hosted;dart:2.13.4;packages:_test_yaml-checked_yaml;commands:format-analyze_0" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable - os:ubuntu-latest;pub-cache-hosted;dart:dev + os:ubuntu-latest;pub-cache-hosted;dart:2.13.4;packages:_test_yaml-checked_yaml + os:ubuntu-latest;pub-cache-hosted;dart:2.13.4 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: cedx/setup-dart@v2 - with: - release-channel: dev - - run: dart --version - - uses: actions/checkout@v2 - - env: - PKGS: _test_yaml checked_yaml example json_annotation json_serializable - TRAVIS_OS_NAME: linux - run: tool/ci.sh dartfmt dartanalyzer_0 + - uses: dart-lang/setup-dart@v1.0 + with: + sdk: "2.13.4" + - id: checkout + uses: actions/checkout@v2.3.4 + - id: _test_yaml_pub_upgrade + name: _test_yaml; dart pub upgrade + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: _test_yaml + run: dart pub upgrade + - name: "_test_yaml; dart format --output=none --set-exit-if-changed ." + if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" + working-directory: _test_yaml + run: "dart format --output=none --set-exit-if-changed ." + - name: "_test_yaml; dart analyze --fatal-warnings --fatal-infos ." + if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" + working-directory: _test_yaml + run: dart analyze --fatal-warnings --fatal-infos . + - id: checked_yaml_pub_upgrade + name: checked_yaml; dart pub upgrade + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: checked_yaml + run: dart pub upgrade + - name: "checked_yaml; dart format --output=none --set-exit-if-changed ." + if: "always() && steps.checked_yaml_pub_upgrade.conclusion == 'success'" + working-directory: checked_yaml + run: "dart format --output=none --set-exit-if-changed ." + - name: "checked_yaml; dart analyze --fatal-warnings --fatal-infos ." + if: "always() && steps.checked_yaml_pub_upgrade.conclusion == 'success'" + working-directory: checked_yaml + run: dart analyze --fatal-warnings --fatal-infos . job_003: - name: "OS: linux; SDK: 2.7.0; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; TASKS: `dartanalyzer --fatal-warnings .`" + name: "analyzer_and_format; Dart 2.13.4; PKGS: example, json_annotation, json_serializable; `dart format --output=none --set-exit-if-changed .`, `dart analyze --fatal-warnings .`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v2 + uses: actions/cache@v2.1.6 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;dart:2.7.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:dartanalyzer_1" + key: "os:ubuntu-latest;pub-cache-hosted;dart:2.13.4;packages:example-json_annotation-json_serializable;commands:format-analyze_1" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;dart:2.7.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable - os:ubuntu-latest;pub-cache-hosted;dart:2.7.0 + os:ubuntu-latest;pub-cache-hosted;dart:2.13.4;packages:example-json_annotation-json_serializable + os:ubuntu-latest;pub-cache-hosted;dart:2.13.4 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: cedx/setup-dart@v2 - with: - release-channel: stable - version: "2.7.0" - - run: dart --version - - uses: actions/checkout@v2 - - env: - PKGS: _test_yaml checked_yaml example json_annotation json_serializable - TRAVIS_OS_NAME: linux - run: tool/ci.sh dartanalyzer_1 + - uses: dart-lang/setup-dart@v1.0 + with: + sdk: "2.13.4" + - id: checkout + uses: actions/checkout@v2.3.4 + - id: example_pub_upgrade + name: example; dart pub upgrade + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: example + run: dart pub upgrade + - name: "example; dart format --output=none --set-exit-if-changed ." + if: "always() && steps.example_pub_upgrade.conclusion == 'success'" + working-directory: example + run: "dart format --output=none --set-exit-if-changed ." + - name: "example; dart analyze --fatal-warnings ." + if: "always() && steps.example_pub_upgrade.conclusion == 'success'" + working-directory: example + run: dart analyze --fatal-warnings . + - id: json_annotation_pub_upgrade + name: json_annotation; dart pub upgrade + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: json_annotation + run: dart pub upgrade + - name: "json_annotation; dart format --output=none --set-exit-if-changed ." + if: "always() && steps.json_annotation_pub_upgrade.conclusion == 'success'" + working-directory: json_annotation + run: "dart format --output=none --set-exit-if-changed ." + - name: "json_annotation; dart analyze --fatal-warnings ." + if: "always() && steps.json_annotation_pub_upgrade.conclusion == 'success'" + working-directory: json_annotation + run: dart analyze --fatal-warnings . + - id: json_serializable_pub_upgrade + name: json_serializable; dart pub upgrade + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: json_serializable + run: dart pub upgrade + - name: "json_serializable; dart format --output=none --set-exit-if-changed ." + if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" + working-directory: json_serializable + run: "dart format --output=none --set-exit-if-changed ." + - name: "json_serializable; dart analyze --fatal-warnings ." + if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" + working-directory: json_serializable + run: dart analyze --fatal-warnings . job_004: - name: "OS: linux; SDK: 2.7.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test`" + name: "analyzer_and_format; Dart stable; PKGS: example, json_annotation; `dart analyze --fatal-warnings --fatal-infos .`" + runs-on: ubuntu-latest + steps: + - name: Cache Pub hosted dependencies + uses: actions/cache@v2.1.6 + with: + path: "~/.pub-cache/hosted" + key: "os:ubuntu-latest;pub-cache-hosted;dart:stable;packages:example-json_annotation;commands:analyze_0" + restore-keys: | + os:ubuntu-latest;pub-cache-hosted;dart:stable;packages:example-json_annotation + os:ubuntu-latest;pub-cache-hosted;dart:stable + os:ubuntu-latest;pub-cache-hosted + os:ubuntu-latest + - uses: dart-lang/setup-dart@v1.0 + with: + sdk: stable + - id: checkout + uses: actions/checkout@v2.3.4 + - id: example_pub_upgrade + name: example; dart pub upgrade + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: example + run: dart pub upgrade + - name: "example; dart analyze --fatal-warnings --fatal-infos ." + if: "always() && steps.example_pub_upgrade.conclusion == 'success'" + working-directory: example + run: dart analyze --fatal-warnings --fatal-infos . + - id: json_annotation_pub_upgrade + name: json_annotation; dart pub upgrade + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: json_annotation + run: dart pub upgrade + - name: "json_annotation; dart analyze --fatal-warnings --fatal-infos ." + if: "always() && steps.json_annotation_pub_upgrade.conclusion == 'success'" + working-directory: json_annotation + run: dart analyze --fatal-warnings --fatal-infos . + job_005: + name: "analyzer_and_format; Dart stable; PKG: json_serializable; `dart analyze --fatal-warnings .`" + runs-on: ubuntu-latest + steps: + - name: Cache Pub hosted dependencies + uses: actions/cache@v2.1.6 + with: + path: "~/.pub-cache/hosted" + key: "os:ubuntu-latest;pub-cache-hosted;dart:stable;packages:json_serializable;commands:analyze_1" + restore-keys: | + os:ubuntu-latest;pub-cache-hosted;dart:stable;packages:json_serializable + os:ubuntu-latest;pub-cache-hosted;dart:stable + os:ubuntu-latest;pub-cache-hosted + os:ubuntu-latest + - uses: dart-lang/setup-dart@v1.0 + with: + sdk: stable + - id: checkout + uses: actions/checkout@v2.3.4 + - id: json_serializable_pub_upgrade + name: json_serializable; dart pub upgrade + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: json_serializable + run: dart pub upgrade + - name: "json_serializable; dart analyze --fatal-warnings ." + if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" + working-directory: json_serializable + run: dart analyze --fatal-warnings . + job_006: + name: "unit_test; Dart 2.13.4; PKGS: _test_yaml, checked_yaml, example, json_serializable; `dart test`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v2 + uses: actions/cache@v2.1.6 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;dart:2.7.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" + key: "os:ubuntu-latest;pub-cache-hosted;dart:2.13.4;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;dart:2.7.0;packages:_test_yaml-checked_yaml-example-json_serializable - os:ubuntu-latest;pub-cache-hosted;dart:2.7.0 + os:ubuntu-latest;pub-cache-hosted;dart:2.13.4;packages:_test_yaml-checked_yaml-example-json_serializable + os:ubuntu-latest;pub-cache-hosted;dart:2.13.4 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: cedx/setup-dart@v2 - with: - release-channel: stable - version: "2.7.0" - - run: dart --version - - uses: actions/checkout@v2 - - env: - PKGS: _test_yaml checked_yaml example json_serializable - TRAVIS_OS_NAME: linux - run: tool/ci.sh test_0 + - uses: dart-lang/setup-dart@v1.0 + with: + sdk: "2.13.4" + - id: checkout + uses: actions/checkout@v2.3.4 + - id: _test_yaml_pub_upgrade + name: _test_yaml; dart pub upgrade + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: _test_yaml + run: dart pub upgrade + - name: _test_yaml; dart test + if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" + working-directory: _test_yaml + run: dart test + - id: checked_yaml_pub_upgrade + name: checked_yaml; dart pub upgrade + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: checked_yaml + run: dart pub upgrade + - name: checked_yaml; dart test + if: "always() && steps.checked_yaml_pub_upgrade.conclusion == 'success'" + working-directory: checked_yaml + run: dart test + - id: example_pub_upgrade + name: example; dart pub upgrade + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: example + run: dart pub upgrade + - name: example; dart test + if: "always() && steps.example_pub_upgrade.conclusion == 'success'" + working-directory: example + run: dart test + - id: json_serializable_pub_upgrade + name: json_serializable; dart pub upgrade + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: json_serializable + run: dart pub upgrade + - name: json_serializable; dart test + if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" + working-directory: json_serializable + run: dart test needs: - job_001 - job_002 - job_003 - job_005: - name: "OS: linux; SDK: dev; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test`" + - job_004 + - job_005 + job_007: + name: "unit_test; Dart 2.13.4; PKG: json_serializable; `dart test -p chrome`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v2 + uses: actions/cache@v2.1.6 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" + key: "os:ubuntu-latest;pub-cache-hosted;dart:2.13.4;packages:json_serializable;commands:test_2" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:_test_yaml-checked_yaml-example-json_serializable - os:ubuntu-latest;pub-cache-hosted;dart:dev + os:ubuntu-latest;pub-cache-hosted;dart:2.13.4;packages:json_serializable + os:ubuntu-latest;pub-cache-hosted;dart:2.13.4 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: cedx/setup-dart@v2 - with: - release-channel: dev - - run: dart --version - - uses: actions/checkout@v2 - - env: - PKGS: _test_yaml checked_yaml example json_serializable - TRAVIS_OS_NAME: linux - run: tool/ci.sh test_0 + - uses: dart-lang/setup-dart@v1.0 + with: + sdk: "2.13.4" + - id: checkout + uses: actions/checkout@v2.3.4 + - id: json_serializable_pub_upgrade + name: json_serializable; dart pub upgrade + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: json_serializable + run: dart pub upgrade + - name: "json_serializable; dart test -p chrome" + if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" + working-directory: json_serializable + run: dart test -p chrome needs: - job_001 - job_002 - job_003 + - job_004 + - job_005 job_008: - name: "OS: linux; SDK: 2.7.0; PKG: json_serializable; TASKS: `pub run test -p chrome`" + name: "unit_test; Dart stable; PKGS: example, json_serializable; `dart test`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v2 + uses: actions/cache@v2.1.6 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;dart:2.7.0;packages:json_serializable;commands:test_2" + key: "os:ubuntu-latest;pub-cache-hosted;dart:stable;packages:example-json_serializable;commands:test_0" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;dart:2.7.0;packages:json_serializable - os:ubuntu-latest;pub-cache-hosted;dart:2.7.0 + os:ubuntu-latest;pub-cache-hosted;dart:stable;packages:example-json_serializable + os:ubuntu-latest;pub-cache-hosted;dart:stable os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: cedx/setup-dart@v2 - with: - release-channel: stable - version: "2.7.0" - - run: dart --version - - uses: actions/checkout@v2 - - env: - PKGS: json_serializable - TRAVIS_OS_NAME: linux - run: tool/ci.sh test_2 + - uses: dart-lang/setup-dart@v1.0 + with: + sdk: stable + - id: checkout + uses: actions/checkout@v2.3.4 + - id: example_pub_upgrade + name: example; dart pub upgrade + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: example + run: dart pub upgrade + - name: example; dart test + if: "always() && steps.example_pub_upgrade.conclusion == 'success'" + working-directory: example + run: dart test + - id: json_serializable_pub_upgrade + name: json_serializable; dart pub upgrade + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: json_serializable + run: dart pub upgrade + - name: json_serializable; dart test + if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" + working-directory: json_serializable + run: dart test needs: - job_001 - job_002 - job_003 + - job_004 + - job_005 job_009: - name: "OS: linux; SDK: dev; PKG: json_serializable; TASKS: `pub run test -p chrome`" + name: "unit_test; Dart stable; PKG: json_serializable; `dart test -p chrome`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v2 + uses: actions/cache@v2.1.6 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:json_serializable;commands:test_2" + key: "os:ubuntu-latest;pub-cache-hosted;dart:stable;packages:json_serializable;commands:test_2" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:json_serializable - os:ubuntu-latest;pub-cache-hosted;dart:dev + os:ubuntu-latest;pub-cache-hosted;dart:stable;packages:json_serializable + os:ubuntu-latest;pub-cache-hosted;dart:stable os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: cedx/setup-dart@v2 - with: - release-channel: dev - - run: dart --version - - uses: actions/checkout@v2 - - env: - PKGS: json_serializable - TRAVIS_OS_NAME: linux - run: tool/ci.sh test_2 + - uses: dart-lang/setup-dart@v1.0 + with: + sdk: stable + - id: checkout + uses: actions/checkout@v2.3.4 + - id: json_serializable_pub_upgrade + name: json_serializable; dart pub upgrade + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: json_serializable + run: dart pub upgrade + - name: "json_serializable; dart test -p chrome" + if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" + working-directory: json_serializable + run: dart test -p chrome needs: - job_001 - job_002 - job_003 - job_006: - name: "OS: linux; SDK: 2.7.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`" + - job_004 + - job_005 + job_010: + name: "ensure_build; Dart 2.13.4; PKGS: _test_yaml, checked_yaml, example, json_serializable; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v2 + uses: actions/cache@v2.1.6 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;dart:2.7.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_1" + key: "os:ubuntu-latest;pub-cache-hosted;dart:2.13.4;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_1" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;dart:2.7.0;packages:_test_yaml-checked_yaml-example-json_serializable - os:ubuntu-latest;pub-cache-hosted;dart:2.7.0 + os:ubuntu-latest;pub-cache-hosted;dart:2.13.4;packages:_test_yaml-checked_yaml-example-json_serializable + os:ubuntu-latest;pub-cache-hosted;dart:2.13.4 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: cedx/setup-dart@v2 - with: - release-channel: stable - version: "2.7.0" - - run: dart --version - - uses: actions/checkout@v2 - - env: - PKGS: _test_yaml checked_yaml example json_serializable - TRAVIS_OS_NAME: linux - run: tool/ci.sh test_1 + - uses: dart-lang/setup-dart@v1.0 + with: + sdk: "2.13.4" + - id: checkout + uses: actions/checkout@v2.3.4 + - id: _test_yaml_pub_upgrade + name: _test_yaml; dart pub upgrade + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: _test_yaml + run: dart pub upgrade + - name: "_test_yaml; dart test --run-skipped -t presubmit-only test/ensure_build_test.dart" + if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" + working-directory: _test_yaml + run: dart test --run-skipped -t presubmit-only test/ensure_build_test.dart + - id: checked_yaml_pub_upgrade + name: checked_yaml; dart pub upgrade + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: checked_yaml + run: dart pub upgrade + - name: "checked_yaml; dart test --run-skipped -t presubmit-only test/ensure_build_test.dart" + if: "always() && steps.checked_yaml_pub_upgrade.conclusion == 'success'" + working-directory: checked_yaml + run: dart test --run-skipped -t presubmit-only test/ensure_build_test.dart + - id: example_pub_upgrade + name: example; dart pub upgrade + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: example + run: dart pub upgrade + - name: "example; dart test --run-skipped -t presubmit-only test/ensure_build_test.dart" + if: "always() && steps.example_pub_upgrade.conclusion == 'success'" + working-directory: example + run: dart test --run-skipped -t presubmit-only test/ensure_build_test.dart + - id: json_serializable_pub_upgrade + name: json_serializable; dart pub upgrade + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: json_serializable + run: dart pub upgrade + - name: "json_serializable; dart test --run-skipped -t presubmit-only test/ensure_build_test.dart" + if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" + working-directory: json_serializable + run: dart test --run-skipped -t presubmit-only test/ensure_build_test.dart needs: + - job_001 + - job_002 + - job_003 - job_004 - job_005 + - job_006 + - job_007 - job_008 - job_009 - job_007: - name: "OS: linux; SDK: dev; PKGS: _test_yaml, checked_yaml, example, json_serializable; TASKS: `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`" + job_011: + name: "ensure_build; Dart stable; PKGS: example, json_serializable; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v2 + uses: actions/cache@v2.1.6 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_1" + key: "os:ubuntu-latest;pub-cache-hosted;dart:stable;packages:example-json_serializable;commands:test_1" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:_test_yaml-checked_yaml-example-json_serializable - os:ubuntu-latest;pub-cache-hosted;dart:dev + os:ubuntu-latest;pub-cache-hosted;dart:stable;packages:example-json_serializable + os:ubuntu-latest;pub-cache-hosted;dart:stable os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: cedx/setup-dart@v2 - with: - release-channel: dev - - run: dart --version - - uses: actions/checkout@v2 - - env: - PKGS: _test_yaml checked_yaml example json_serializable - TRAVIS_OS_NAME: linux - run: tool/ci.sh test_1 + - uses: dart-lang/setup-dart@v1.0 + with: + sdk: stable + - id: checkout + uses: actions/checkout@v2.3.4 + - id: example_pub_upgrade + name: example; dart pub upgrade + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: example + run: dart pub upgrade + - name: "example; dart test --run-skipped -t presubmit-only test/ensure_build_test.dart" + if: "always() && steps.example_pub_upgrade.conclusion == 'success'" + working-directory: example + run: dart test --run-skipped -t presubmit-only test/ensure_build_test.dart + - id: json_serializable_pub_upgrade + name: json_serializable; dart pub upgrade + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: json_serializable + run: dart pub upgrade + - name: "json_serializable; dart test --run-skipped -t presubmit-only test/ensure_build_test.dart" + if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" + working-directory: json_serializable + run: dart test --run-skipped -t presubmit-only test/ensure_build_test.dart needs: + - job_001 + - job_002 + - job_003 - job_004 - job_005 + - job_006 + - job_007 - job_008 - job_009 diff --git a/_test_yaml/mono_pkg.yaml b/_test_yaml/mono_pkg.yaml index 676aaa38d..eab4a975e 100644 --- a/_test_yaml/mono_pkg.yaml +++ b/_test_yaml/mono_pkg.yaml @@ -1,17 +1,13 @@ # See https://github.com/google/mono_repo.dart for details on this file dart: -- 2.7.0 -- dev +- 2.13.4 stages: - analyzer_and_format: - group: - - dartfmt - - dartanalyzer: --fatal-warnings --fatal-infos . - dart: [dev] - - group: - - dartanalyzer: --fatal-warnings . - dart: [2.7.0] + - format + - analyze: --fatal-warnings --fatal-infos . + dart: [2.13.4] - unit_test: - test - ensure_build: diff --git a/_test_yaml/pubspec.yaml b/_test_yaml/pubspec.yaml index 4339901fe..e34987e19 100644 --- a/_test_yaml/pubspec.yaml +++ b/_test_yaml/pubspec.yaml @@ -10,6 +10,7 @@ dev_dependencies: checked_yaml: any json_annotation: any json_serializable: any + meta: ">=1.2.2 <1.7.0" # Workaround to avoid https://github.com/dart-lang/sdk/issues/46142 test: ^1.6.0 dependency_overrides: diff --git a/checked_yaml/mono_pkg.yaml b/checked_yaml/mono_pkg.yaml index 1d80a7151..1b7901e92 100644 --- a/checked_yaml/mono_pkg.yaml +++ b/checked_yaml/mono_pkg.yaml @@ -1,17 +1,13 @@ # See https://github.com/google/mono_repo.dart for details on this file dart: -- 2.7.0 -- dev +- 2.13.4 stages: - analyzer_and_format: - group: - - dartfmt - - dartanalyzer: --fatal-warnings --fatal-infos . - dart: [dev] - - group: - - dartanalyzer: --fatal-warnings . - dart: [2.7.0] + - format + - analyze: --fatal-warnings --fatal-infos . + dart: [2.13.4] - unit_test: - test diff --git a/checked_yaml/pubspec.yaml b/checked_yaml/pubspec.yaml index ef0d6ecb2..d6f660e11 100644 --- a/checked_yaml/pubspec.yaml +++ b/checked_yaml/pubspec.yaml @@ -16,6 +16,7 @@ dev_dependencies: build_runner: ^1.0.0 build_verify: ^1.1.0 json_serializable: ^3.0.0 + meta: ">=1.2.2 <1.7.0" # Workaround to avoid https://github.com/dart-lang/sdk/issues/46142 path: ^1.0.0 test: ^1.6.0 test_process: ^1.0.1 diff --git a/example/mono_pkg.yaml b/example/mono_pkg.yaml index 23b5859b6..2ca52a8dc 100644 --- a/example/mono_pkg.yaml +++ b/example/mono_pkg.yaml @@ -1,17 +1,17 @@ # See https://github.com/google/mono_repo.dart for details on this file dart: -- 2.7.0 -- dev +- 2.13.4 +- stable stages: - analyzer_and_format: - group: - - dartfmt - - dartanalyzer: --fatal-warnings --fatal-infos . - dart: [dev] + - analyze: --fatal-warnings --fatal-infos . + dart: [stable] - group: - - dartanalyzer: --fatal-warnings . - dart: [2.7.0] + - format + - analyze: --fatal-warnings . + dart: [2.13.4] - unit_test: - test - ensure_build: diff --git a/example/pubspec.yaml b/example/pubspec.yaml index fe8692d14..0dc06f390 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -24,3 +24,11 @@ dependency_overrides: path: ../json_annotation json_serializable: path: ../json_serializable + # Normally pubspec_parse would be constrained to <1.0.0 because of this + # package's constraint on json_annotation ^3.0.0, but because json_annotation + # is also overridden here, that does not happen, and pubspec_parse would + # otherwise resolve to v1 which will fail. To avoid that issue, we override + # pubspec_parse here, but note that this is not representative of a consumer + # would actually need to do – depending on json_annotation ^3.0.0 is + # sufficient for consumers. + pubspec_parse: <1.0.0 diff --git a/json_annotation/mono_pkg.yaml b/json_annotation/mono_pkg.yaml index 1da53eb18..fabc4c937 100644 --- a/json_annotation/mono_pkg.yaml +++ b/json_annotation/mono_pkg.yaml @@ -2,9 +2,9 @@ stages: - analyzer_and_format: - group: - - dartfmt - - dartanalyzer: --fatal-warnings --fatal-infos . - dart: [dev] + - analyze: --fatal-warnings --fatal-infos . + dart: [stable] - group: - - dartanalyzer: --fatal-warnings . - dart: [2.7.0] + - format + - analyze: --fatal-warnings . + dart: [2.13.4] diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index bc78f0c6d..bc968298e 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,7 @@ +## 3.5.2 + +- Widen `package:analyzer` range to allow v1.x. + ## 3.5.1 - Improved error messages for unsupported types. diff --git a/json_serializable/mono_pkg.yaml b/json_serializable/mono_pkg.yaml index 485700e0e..bb460725b 100644 --- a/json_serializable/mono_pkg.yaml +++ b/json_serializable/mono_pkg.yaml @@ -1,17 +1,17 @@ # See https://github.com/google/mono_repo.dart for details on this file dart: -- 2.7.0 -- dev +- 2.13.4 +- stable stages: - analyzer_and_format: - group: - - dartfmt - - dartanalyzer: --fatal-warnings --fatal-infos . - dart: [dev] + - analyze: --fatal-warnings . + dart: [stable] - group: - - dartanalyzer: --fatal-warnings . - dart: [2.7.0] + - format + - analyze: --fatal-warnings . + dart: [2.13.4] - unit_test: - test - test: -p chrome diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index a88770c03..1afca57b2 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,16 +1,16 @@ name: json_serializable -version: 3.5.1 +version: 3.5.2 description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. repository: https://github.com/google/json_serializable.dart environment: - sdk: '>=2.7.0 <3.0.0' + sdk: '>=2.11.99 <3.0.0' dependencies: - analyzer: '>=0.39.0 <0.42.0' - build: '>=0.12.6 <2.0.0' - build_config: '>=0.2.6 <0.5.0' + analyzer: '>=0.39.0 <2.0.0' + build: '>=0.12.6 <3.0.0' + build_config: '>=0.2.6 <2.0.0' # Use a tight version constraint to ensure that a constraint on # `json_annotation` properly constrains all features it provides. @@ -23,11 +23,11 @@ dependencies: dev_dependencies: build_runner: ^1.0.0 - build_verify: ^1.1.0 + build_verify: ^2.0.0 collection: ^1.14.0 - dart_style: ^1.2.0 - logging: ^0.11.3+1 - pub_semver: ^1.4.0 + dart_style: ^1.0.0 + logging: ^1.0.0 + pub_semver: ^2.0.0 source_gen_test: ^0.1.0 test: ^1.6.0 - yaml: ^2.1.13 + yaml: ^3.0.0 diff --git a/json_serializable/test/kitchen_sink/kitchen_sink_test.dart b/json_serializable/test/kitchen_sink/kitchen_sink_test.dart index 8a22ce025..86a0330a6 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink_test.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink_test.dart @@ -177,7 +177,7 @@ void _nullableTests(KitchenSinkFactory factory) { void _anyMapTests(KitchenSinkFactory factory) { test('valid values round-trip - yaml', () { final jsonEncoded = loudEncode(_validValues); - final yaml = loadYaml(jsonEncoded, sourceUrl: 'input.yaml'); + final yaml = loadYaml(jsonEncoded, sourceUrl: Uri.parse('input.yaml')); expect(jsonEncoded, loudEncode(factory.fromJson(yaml as YamlMap))); }); diff --git a/json_serializable/tool/shared.dart b/json_serializable/tool/shared.dart index 58b3a9216..3e12e469e 100644 --- a/json_serializable/tool/shared.dart +++ b/json_serializable/tool/shared.dart @@ -12,7 +12,7 @@ import 'package:yaml/yaml.dart'; Builder validate(String builderName, Builder builder) { var buildYaml = loadYaml( File('build.yaml').readAsStringSync(), - sourceUrl: 'build.yaml', + sourceUrl: Uri.parse('build.yaml'), ) as YamlMap; for (var key in ['builders', builderName, 'build_extensions']) { diff --git a/tool/ci.sh b/tool/ci.sh index 7e4a12bbe..85df7f879 100755 --- a/tool/ci.sh +++ b/tool/ci.sh @@ -1,26 +1,35 @@ #!/bin/bash -# Created with package:mono_repo v3.3.0 +# Created with package:mono_repo v5.0.0 # Support built in commands on windows out of the box. +# When it is a flutter repo (check the pubspec.yaml for "sdk: flutter") +# then "flutter" is called instead of "pub". +# This assumes that the Flutter SDK has been installed in a previous step. function pub() { - if [[ $TRAVIS_OS_NAME == "windows" ]]; then - command pub.bat "$@" + if grep -Fq "sdk: flutter" "${PWD}/pubspec.yaml"; then + command flutter pub "$@" else - command pub "$@" + command dart pub "$@" fi } -function dartfmt() { - if [[ $TRAVIS_OS_NAME == "windows" ]]; then - command dartfmt.bat "$@" +# When it is a flutter repo (check the pubspec.yaml for "sdk: flutter") +# then "flutter" is called instead of "pub". +# This assumes that the Flutter SDK has been installed in a previous step. +function format() { + if grep -Fq "sdk: flutter" "${PWD}/pubspec.yaml"; then + command flutter format "$@" else - command dartfmt "$@" + command dart format "$@" fi } -function dartanalyzer() { - if [[ $TRAVIS_OS_NAME == "windows" ]]; then - command dartanalyzer.bat "$@" +# When it is a flutter repo (check the pubspec.yaml for "sdk: flutter") +# then "flutter" is called instead of "pub". +# This assumes that the Flutter SDK has been installed in a previous step. +function analyze() { + if grep -Fq "sdk: flutter" "${PWD}/pubspec.yaml"; then + command flutter analyze "$@" else - command dartanalyzer "$@" + command dart analyze "$@" fi } @@ -47,40 +56,40 @@ for PKG in ${PKGS}; do exit 64 fi - pub upgrade --no-precompile || EXIT_CODE=$? + dart pub upgrade || EXIT_CODE=$? if [[ ${EXIT_CODE} -ne 0 ]]; then - echo -e "\033[31mPKG: ${PKG}; 'pub upgrade' - FAILED (${EXIT_CODE})\033[0m" - FAILURES+=("${PKG}; 'pub upgrade'") + echo -e "\033[31mPKG: ${PKG}; 'dart pub upgrade' - FAILED (${EXIT_CODE})\033[0m" + FAILURES+=("${PKG}; 'dart pub upgrade'") else for TASK in "$@"; do EXIT_CODE=0 echo echo -e "\033[1mPKG: ${PKG}; TASK: ${TASK}\033[22m" case ${TASK} in - dartanalyzer_0) - echo 'dartanalyzer --fatal-warnings --fatal-infos .' - dartanalyzer --fatal-warnings --fatal-infos . || EXIT_CODE=$? + analyze_0) + echo 'dart analyze --fatal-warnings --fatal-infos .' + dart analyze --fatal-warnings --fatal-infos . || EXIT_CODE=$? ;; - dartanalyzer_1) - echo 'dartanalyzer --fatal-warnings .' - dartanalyzer --fatal-warnings . || EXIT_CODE=$? + analyze_1) + echo 'dart analyze --fatal-warnings .' + dart analyze --fatal-warnings . || EXIT_CODE=$? ;; - dartfmt) - echo 'dartfmt -n --set-exit-if-changed .' - dartfmt -n --set-exit-if-changed . || EXIT_CODE=$? + format) + echo 'dart format --output=none --set-exit-if-changed .' + dart format --output=none --set-exit-if-changed . || EXIT_CODE=$? ;; test_0) - echo 'pub run test' - pub run test || EXIT_CODE=$? + echo 'dart test' + dart test || EXIT_CODE=$? ;; test_1) - echo 'pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart' - pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart || EXIT_CODE=$? + echo 'dart test --run-skipped -t presubmit-only test/ensure_build_test.dart' + dart test --run-skipped -t presubmit-only test/ensure_build_test.dart || EXIT_CODE=$? ;; test_2) - echo 'pub run test -p chrome' - pub run test -p chrome || EXIT_CODE=$? + echo 'dart test -p chrome' + dart test -p chrome || EXIT_CODE=$? ;; *) echo -e "\033[31mUnknown TASK '${TASK}' - TERMINATING JOB\033[0m" From ae20162db10811514e5a53ebc4c9bab70e81a3f9 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@google.com> Date: Thu, 13 Jan 2022 10:41:47 -0800 Subject: [PATCH 398/569] Resolve issue with latest analyzer, enums and annotations Fixes https://github.com/google/json_serializable.dart/issues/1083 --- json_serializable/CHANGELOG.md | 4 ++++ json_serializable/lib/src/utils.dart | 2 +- json_serializable/pubspec.yaml | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 7b258ccc1..0fb283958 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,7 @@ +## 6.1.4 + +- Fix issues with latest `package:analyzer` related to enums and annotations. + ## 6.1.3 - Allow latest `package:analyzer`. diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index 50362abe9..3d33eddad 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -45,7 +45,7 @@ T enumValueForDartObject<T>( List<T> items, String Function(T) name, ) => - items.singleWhere((v) => source.getField(name(v)) != null); + items[source.getField('index')!.toIntValue()!]; /// Return an instance of [JsonSerializable] corresponding to a the provided /// [reader]. diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 58b75337c..bb4ef6908 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 6.1.3 +version: 6.1.4 description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. From 61d0893c6bf1802b2a8b935866ef714ca0cf938d Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@google.com> Date: Thu, 13 Jan 2022 10:45:15 -0800 Subject: [PATCH 399/569] fix an updated lint --- json_serializable/test/json_serializable_test.dart | 2 +- json_serializable/test/src/_json_serializable_test_input.dart | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/json_serializable/test/json_serializable_test.dart b/json_serializable/test/json_serializable_test.dart index a8bd577e3..9c9d8d834 100644 --- a/json_serializable/test/json_serializable_test.dart +++ b/json_serializable/test/json_serializable_test.dart @@ -35,7 +35,7 @@ Future<void> main() async { const _expectedAnnotatedTests = { 'annotatedMethod', - 'unsupportedEnum', + 'UnsupportedEnum', 'BadFromFuncReturnType', 'BadNoArgs', 'BadOneNamed', diff --git a/json_serializable/test/src/_json_serializable_test_input.dart b/json_serializable/test/src/_json_serializable_test_input.dart index ac3cbda8b..7a116a094 100644 --- a/json_serializable/test/src/_json_serializable_test_input.dart +++ b/json_serializable/test/src/_json_serializable_test_input.dart @@ -26,7 +26,7 @@ const theAnswer = 42; @ShouldThrow('`@JsonSerializable` can only be used on classes.') @JsonSerializable() // ignore: invalid_annotation_target -enum unsupportedEnum { not, valid } +enum UnsupportedEnum { not, valid } @ShouldThrow('`@JsonSerializable` can only be used on classes.') @JsonSerializable() // ignore: invalid_annotation_target From df37429ea2be479ce59a14635ec059edec43e4a4 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Tue, 25 Jan 2022 18:39:04 -0800 Subject: [PATCH 400/569] Move to strict casts (#1086) --- analysis_options.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index 611323ece..fd9a9a815 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1,6 +1,6 @@ analyzer: - strong-mode: - implicit-casts: false + language: + strict-casts: true linter: rules: From 4de8c1f36f773df19b708ad3d5795a67311d560d Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@google.com> Date: Thu, 3 Feb 2022 13:54:34 -0800 Subject: [PATCH 401/569] example: Bump json_annotation version constraint --- example/README.md | 2 +- example/pubspec.yaml | 2 +- example/test/readme_test.dart | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/example/README.md b/example/README.md index b3228f743..3be08ba78 100644 --- a/example/README.md +++ b/example/README.md @@ -5,7 +5,7 @@ dependencies to your `pubspec.yaml`. ```yaml dependencies: - json_annotation: ^4.3.0 + json_annotation: ^4.4.0 dev_dependencies: build_runner: ^2.0.0 diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 243756f68..a5feb1175 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -5,7 +5,7 @@ environment: sdk: '>=2.14.0 <3.0.0' dependencies: - json_annotation: ^4.3.0 + json_annotation: ^4.4.0 dev_dependencies: build_runner: ^2.0.0 diff --git a/example/test/readme_test.dart b/example/test/readme_test.dart index f17ceaad2..9a98c4b63 100644 --- a/example/test/readme_test.dart +++ b/example/test/readme_test.dart @@ -25,7 +25,7 @@ void _expect(String fileName) { const _pubspecContent = r''' dependencies: - json_annotation: ^4.3.0 + json_annotation: ^4.4.0 dev_dependencies: build_runner: ^2.0.0 From 41b5a279ac8feec8d293ae29a5131c11637751cd Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@google.com> Date: Thu, 3 Feb 2022 14:13:47 -0800 Subject: [PATCH 402/569] New infra package to share code across the mono repo And migrate last test in _test_yaml to null-safety --- _test_yaml/pubspec.yaml | 2 + _test_yaml/test/src/build_config.dart | 6 +-- _test_yaml/test/src/build_config.g.dart | 6 +-- _test_yaml/test/yaml_test.dart | 39 +------------- json_serializable/pubspec.yaml | 3 +- .../generic_argument_factories_nullable.dart | 2 - ...generic_argument_factories_nullable.g.dart | 1 - .../test/generic_files/generic_test.dart | 2 +- .../test/integration/integration_test.dart | 12 ++--- .../test/kitchen_sink/kitchen_sink_test.dart | 12 ++--- json_serializable/test/test_utils.dart | 50 +---------------- shared_test/lib/shared_test.dart | 53 +++++++++++++++++++ shared_test/pubspec.yaml | 8 +++ 13 files changed, 87 insertions(+), 109 deletions(-) create mode 100644 shared_test/lib/shared_test.dart create mode 100644 shared_test/pubspec.yaml diff --git a/_test_yaml/pubspec.yaml b/_test_yaml/pubspec.yaml index a07c3df6a..63c0b00cd 100644 --- a/_test_yaml/pubspec.yaml +++ b/_test_yaml/pubspec.yaml @@ -5,6 +5,8 @@ environment: sdk: '>=2.14.0 <3.0.0' dev_dependencies: + _json_serial_shared_test: + path: ../shared_test build_runner: ^2.0.0 build_verify: ^3.0.0 checked_yaml: any diff --git a/_test_yaml/test/src/build_config.dart b/_test_yaml/test/src/build_config.dart index a749d442a..a31c1c5b6 100644 --- a/_test_yaml/test/src/build_config.dart +++ b/_test_yaml/test/src/build_config.dart @@ -12,7 +12,7 @@ class Config { final Map<String, Builder> builders; // Verifying enum keys in map - Map<AutoApply, int>? weights; + Map<AutoApply, int?>? weights; Config({required this.builders}); @@ -29,7 +29,7 @@ class Config { class Builder { final String? target; - final String import; + final String? import; @JsonKey(name: 'is_optional') final bool? isOptional; @@ -58,7 +58,7 @@ class Builder { final Map<String, List<String>>? buildExtensions; Builder({ - required this.import, + this.import, this.target, this.isOptional, this.autoApply, diff --git a/_test_yaml/test/src/build_config.g.dart b/_test_yaml/test/src/build_config.g.dart index f509e2eb6..72cbe0034 100644 --- a/_test_yaml/test/src/build_config.g.dart +++ b/_test_yaml/test/src/build_config.g.dart @@ -25,7 +25,7 @@ Config _$ConfigFromJson(Map json) => $checkedCreate( 'weights', (v) => val.weights = (v as Map?)?.map( (k, e) => - MapEntry($enumDecode(_$AutoApplyEnumMap, k), e as int), + MapEntry($enumDecode(_$AutoApplyEnumMap, k), e as int?), )); return val; }, @@ -66,7 +66,7 @@ Builder _$BuilderFromJson(Map json) => $checkedCreate( disallowNullValues: const ['configLocation', 'auto_apply'], ); final val = Builder( - import: $checkedConvert('import', (v) => v as String), + import: $checkedConvert('import', (v) => v as String?), target: $checkedConvert('target', (v) => v as String?), isOptional: $checkedConvert('is_optional', (v) => v as bool?), autoApply: $checkedConvert( @@ -113,7 +113,7 @@ Map<String, dynamic> _$BuilderToJson(Builder instance) { } writeNotNull('target', instance.target); - val['import'] = instance.import; + writeNotNull('import', instance.import); writeNotNull('is_optional', instance.isOptional); writeNotNull('configLocation', instance.configLocation?.toString()); writeNotNull('auto_apply', _$AutoApplyEnumMap[instance.autoApply]); diff --git a/_test_yaml/test/yaml_test.dart b/_test_yaml/test/yaml_test.dart index d696b6c7e..428587d78 100644 --- a/_test_yaml/test/yaml_test.dart +++ b/_test_yaml/test/yaml_test.dart @@ -2,12 +2,10 @@ // 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. -// @dart=2.9 - @TestOn('vm') -import 'dart:convert'; import 'dart:io'; +import 'package:_json_serial_shared_test/shared_test.dart'; import 'package:checked_yaml/checked_yaml.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:path/path.dart' as p; @@ -159,38 +157,3 @@ line 4, column 21 of file.yaml: Unsupported value for "configLocation". Illegal │ ^^^^^^^^^^^^^^^^^^^^^^^ ╵''' }; - -T roundTripObject<T>( - T object, - T Function(Map<String, dynamic> json) factory, { - bool skipObjectEquals = false, -}) { - final data = loudEncode(object); - - final object2 = factory(json.decode(data) as Map<String, dynamic>); - - if (!skipObjectEquals) { - expect(object2, equals(object)); - } - - final json2 = loudEncode(object2); - - expect(json2, equals(data)); - return object2; -} - -/// Prints out nested causes before throwing `JsonUnsupportedObjectError`. -String loudEncode(Object object) { - try { - return const JsonEncoder.withIndent(' ').convert(object); - } on JsonUnsupportedObjectError catch (e) // ignore: avoid_catching_errors - { - var error = e; - do { - final cause = error.cause; - print(cause); - error = (cause is JsonUnsupportedObjectError) ? cause : null; - } while (error != null); - rethrow; - } -} diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index bb4ef6908..48430e9ab 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -25,12 +25,13 @@ dependencies: source_helper: ^1.3.0 dev_dependencies: + _json_serial_shared_test: + path: ../shared_test build_runner: ^2.0.0 build_verify: ^3.0.0 dart_style: ^2.0.0 logging: ^1.0.0 source_gen_test: ^1.0.0 - stack_trace: ^1.10.0 test: ^1.16.0 test_descriptor: ^2.0.0 test_process: ^2.0.0 diff --git a/json_serializable/test/generic_files/generic_argument_factories_nullable.dart b/json_serializable/test/generic_files/generic_argument_factories_nullable.dart index 355d30a84..882ad4de5 100644 --- a/json_serializable/test/generic_files/generic_argument_factories_nullable.dart +++ b/json_serializable/test/generic_files/generic_argument_factories_nullable.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.12 - import 'package:json_annotation/json_annotation.dart'; part 'generic_argument_factories_nullable.g.dart'; diff --git a/json_serializable/test/generic_files/generic_argument_factories_nullable.g.dart b/json_serializable/test/generic_files/generic_argument_factories_nullable.g.dart index 3bf21b18c..5527d2fed 100644 --- a/json_serializable/test/generic_files/generic_argument_factories_nullable.g.dart +++ b/json_serializable/test/generic_files/generic_argument_factories_nullable.g.dart @@ -1,5 +1,4 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// @dart=2.12 // ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal diff --git a/json_serializable/test/generic_files/generic_test.dart b/json_serializable/test/generic_files/generic_test.dart index 7b38c1c65..4593dac95 100644 --- a/json_serializable/test/generic_files/generic_test.dart +++ b/json_serializable/test/generic_files/generic_test.dart @@ -318,7 +318,7 @@ void main() { }); test('issue 980 regression test', () { - validateRoundTrip( + roundTripObject( Issue980ParentClass([ Issue980GenericClass(45), Issue980GenericClass(42), diff --git a/json_serializable/test/integration/integration_test.dart b/json_serializable/test/integration/integration_test.dart index 13e06f2b6..22dc186aa 100644 --- a/json_serializable/test/integration/integration_test.dart +++ b/json_serializable/test/integration/integration_test.dart @@ -16,7 +16,7 @@ Matcher _throwsArgumentError(matcher) => void main() { group('Person', () { void roundTripPerson(Person p) { - validateRoundTrip(p, (json) => Person.fromJson(json)); + roundTripObject(p, (json) => Person.fromJson(json)); } test('now', () { @@ -50,7 +50,7 @@ void main() { group('Order', () { void roundTripOrder(Order p) { - validateRoundTrip(p, (json) => Order.fromJson(json)); + roundTripObject(p, (json) => Order.fromJson(json)); } test('null', () { @@ -190,7 +190,7 @@ void main() { group('Item', () { void roundTripItem(Item p) { - validateRoundTrip(p, (json) => Item.fromJson(json)); + roundTripObject(p, (json) => Item.fromJson(json)); } test('empty json', () { @@ -231,7 +231,7 @@ void main() { group('Numbers', () { void roundTripNumber(Numbers p) { - validateRoundTrip(p, (json) => Numbers.fromJson(json)); + roundTripObject(p, (json) => Numbers.fromJson(json)); } test('simple', () { @@ -276,7 +276,7 @@ void main() { ..intIntMap = {3: 3} ..uriIntMap = {Uri.parse('https://example.com'): 4}; - validateRoundTrip(instance, (j) => MapKeyVariety.fromJson(j)); + roundTripObject(instance, (j) => MapKeyVariety.fromJson(j)); }); test('UnknownEnumValue', () { @@ -296,7 +296,7 @@ void main() { test('PrivateConstructor', () { final value = PrivateConstructor('test'); - validateRoundTrip(value, (json) => PrivateConstructor.fromJson(json)); + roundTripObject(value, (json) => PrivateConstructor.fromJson(json)); }); test('enum helpers', () { diff --git a/json_serializable/test/kitchen_sink/kitchen_sink_test.dart b/json_serializable/test/kitchen_sink/kitchen_sink_test.dart index 0b5a1f8b8..8044c29d7 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink_test.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink_test.dart @@ -84,7 +84,7 @@ void _nonNullableTests(KitchenSinkFactory factory) { void _nullableTests(KitchenSinkFactory factory) { void roundTripSink(KitchenSink p) { - validateRoundTrip(p, factory.fromJson); + roundTripObject(p, factory.fromJson); } test('nullable values are allowed in the nullable version', () { @@ -180,7 +180,7 @@ void _sharedTests(KitchenSinkFactory factory) { test('empty', () { final item = factory.ctor(); - validateRoundTrip(item, factory.fromJson); + roundTripObject(item, factory.fromJson); }); test('list and map of DateTime - not null', () { @@ -189,7 +189,7 @@ void _sharedTests(KitchenSinkFactory factory) { ..dateTimeList = <DateTime>[now, now] ..objectDateTimeMap = <Object, DateTime>{'value': now}; - validateRoundTrip(item, factory.fromJson); + roundTripObject(item, factory.fromJson); }); test('complex nested type - not null', () { @@ -207,7 +207,7 @@ void _sharedTests(KitchenSinkFactory factory) { } } ]; - validateRoundTrip(item, factory.fromJson); + roundTripObject(item, factory.fromJson); }); test('round trip valid, empty values', () { @@ -226,7 +226,7 @@ void _sharedTests(KitchenSinkFactory factory) { final validInstance = factory.fromJson(values); - validateRoundTrip(validInstance, factory.fromJson); + roundTripObject(validInstance, factory.fromJson); }); test('JSON keys should be defined in field/property order', () { @@ -240,7 +240,7 @@ void _sharedTests(KitchenSinkFactory factory) { test('valid values round-trip - json', () { final validInstance = factory.fromJson(validValues); - validateRoundTrip(validInstance, factory.fromJson); + roundTripObject(validInstance, factory.fromJson); }); } diff --git a/json_serializable/test/test_utils.dart b/json_serializable/test/test_utils.dart index b82e1b780..ea943342d 100644 --- a/json_serializable/test/test_utils.dart +++ b/json_serializable/test/test_utils.dart @@ -2,60 +2,14 @@ // 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 'dart:convert'; - import 'package:collection/collection.dart'; -import 'package:stack_trace/stack_trace.dart'; import 'package:test/test.dart'; +export 'package:_json_serial_shared_test/shared_test.dart'; + final throwsTypeError = throwsA(isTypeError); final isTypeError = isA<TypeError>(); bool deepEquals(dynamic a, dynamic b) => const DeepCollectionEquality().equals(a, b); - -void validateRoundTrip<T>( - T object, - T Function(Map<String, dynamic> json) factory, -) { - final data = loudEncode(object); - - final object2 = factory(json.decode(data) as Map<String, dynamic>); - - expect(object2, equals(object)); - - final json2 = loudEncode(object2); - - expect(json2, equals(data)); -} - -/// Prints out nested causes before throwing `JsonUnsupportedObjectError`. -String loudEncode(Object? object) { - try { - return const JsonEncoder.withIndent(' ').convert(object); - } catch (e) { - if (e is JsonUnsupportedObjectError) { - Object? error = e; - - var count = 1; - - while (error is JsonUnsupportedObjectError) { - print( - '(${count++}) $error ${error.unsupportedObject} ' - '(${error.unsupportedObject.runtimeType}) !!!', - ); - print(Trace.from(error.stackTrace!).terse); - error = error.cause; - } - - if (error != null) { - print('(${count++}) $error ???'); - if (error is Error) { - print(Trace.from(error.stackTrace!).terse); - } - } - } - rethrow; - } -} diff --git a/shared_test/lib/shared_test.dart b/shared_test/lib/shared_test.dart new file mode 100644 index 000000000..4cf9dd96c --- /dev/null +++ b/shared_test/lib/shared_test.dart @@ -0,0 +1,53 @@ +import 'dart:convert'; + +import 'package:stack_trace/stack_trace.dart'; +import 'package:test/test.dart'; + +/// Prints out nested causes before throwing `JsonUnsupportedObjectError`. +String loudEncode(Object? object) { + try { + return const JsonEncoder.withIndent(' ').convert(object); + } catch (e) { + if (e is JsonUnsupportedObjectError) { + Object? error = e; + + var count = 1; + + while (error is JsonUnsupportedObjectError) { + print( + '(${count++}) $error ${error.unsupportedObject} ' + '(${error.unsupportedObject.runtimeType}) !!!', + ); + print(Trace.from(error.stackTrace!).terse); + error = error.cause; + } + + if (error != null) { + print('(${count++}) $error ???'); + if (error is Error) { + print(Trace.from(error.stackTrace!).terse); + } + } + } + rethrow; + } +} + +T roundTripObject<T>( + T object, + T Function(Map<String, dynamic> json) factory, { + bool skipObjectEquals = false, +}) { + final data = loudEncode(object); + + final object2 = factory(json.decode(data) as Map<String, dynamic>); + + if (!skipObjectEquals) { + expect(object2, equals(object)); + } + + final json2 = loudEncode(object2); + + expect(json2, equals(data)); + return object2; +} diff --git a/shared_test/pubspec.yaml b/shared_test/pubspec.yaml new file mode 100644 index 000000000..ec6a4e961 --- /dev/null +++ b/shared_test/pubspec.yaml @@ -0,0 +1,8 @@ +name: _json_serial_shared_test +publish_to: none +environment: + sdk: '>=2.14.0 <3.0.0' + +dependencies: + stack_trace: ^1.10.0 + test: ^1.6.0 From 2dfffd0df2abc4592b37e75de2ee75932711c503 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@google.com> Date: Thu, 3 Feb 2022 13:53:05 -0800 Subject: [PATCH 403/569] example: Add an example demonstrating how to do nested fields Closes https://github.com/google/json_serializable.dart/issues/490 --- example/lib/nested_values_example.dart | 37 ++++++++++++++++++++++++ example/lib/nested_values_example.g.dart | 18 ++++++++++++ example/pubspec.yaml | 3 ++ example/test/nested_values_test.dart | 35 ++++++++++++++++++++++ 4 files changed, 93 insertions(+) create mode 100644 example/lib/nested_values_example.dart create mode 100644 example/lib/nested_values_example.g.dart create mode 100644 example/test/nested_values_test.dart diff --git a/example/lib/nested_values_example.dart b/example/lib/nested_values_example.dart new file mode 100644 index 000000000..3bd1e47f6 --- /dev/null +++ b/example/lib/nested_values_example.dart @@ -0,0 +1,37 @@ +import 'package:json_annotation/json_annotation.dart'; + +part 'nested_values_example.g.dart'; + +/// An example work-around for +/// https://github.com/google/json_serializable.dart/issues/490 +@JsonSerializable() +class NestedValueExample { + NestedValueExample(this.nestedValues); + + factory NestedValueExample.fromJson(Map<String, dynamic> json) => + _$NestedValueExampleFromJson(json); + + @_NestedListConverter() + @JsonKey(name: 'root_items') + final List<String> nestedValues; + + Map<String, dynamic> toJson() => _$NestedValueExampleToJson(this); +} + +class _NestedListConverter + extends JsonConverter<List<String>, Map<String, dynamic>> { + const _NestedListConverter(); + + @override + List<String> fromJson(Map<String, dynamic> json) => [ + for (var e in json['items'] as List) + (e as Map<String, dynamic>)['name'] as String + ]; + + @override + Map<String, dynamic> toJson(List<String> object) => { + 'items': [ + for (var item in object) {'name': item} + ] + }; +} diff --git a/example/lib/nested_values_example.g.dart b/example/lib/nested_values_example.g.dart new file mode 100644 index 000000000..39dc2b8c2 --- /dev/null +++ b/example/lib/nested_values_example.g.dart @@ -0,0 +1,18 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'nested_values_example.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +NestedValueExample _$NestedValueExampleFromJson(Map<String, dynamic> json) => + NestedValueExample( + const _NestedListConverter() + .fromJson(json['root_items'] as Map<String, dynamic>), + ); + +Map<String, dynamic> _$NestedValueExampleToJson(NestedValueExample instance) => + <String, dynamic>{ + 'root_items': const _NestedListConverter().toJson(instance.nestedValues), + }; diff --git a/example/pubspec.yaml b/example/pubspec.yaml index a5feb1175..eb124b468 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -8,6 +8,9 @@ dependencies: json_annotation: ^4.4.0 dev_dependencies: + # Used by tests. Not required to use `json_serializable`. + _json_serial_shared_test: + path: ../shared_test build_runner: ^2.0.0 # Used by tests. Not required to use `json_serializable`. diff --git a/example/test/nested_values_test.dart b/example/test/nested_values_test.dart new file mode 100644 index 000000000..d244b71d2 --- /dev/null +++ b/example/test/nested_values_test.dart @@ -0,0 +1,35 @@ +// Copyright (c) 2020, 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 'dart:convert'; + +import 'package:_json_serial_shared_test/shared_test.dart'; +import 'package:example/nested_values_example.dart'; +import 'package:test/test.dart'; + +void main() { + test('NestedValueExample', () { + final input = jsonDecode(_input) as Map<String, dynamic>; + final normalizedOutput = loudEncode(input); + + final instance = NestedValueExample.fromJson(input); + + expect(loudEncode(instance), normalizedOutput); + }); +} + +const _input = r''' +{ + "root_items": { + "items": [ + { + "name": "first nested item" + }, + { + "name": "second nested item" + } + ] + } +} +'''; From 58f46ade0d2da55ec7274760c58d90e0b91f107a Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@google.com> Date: Thu, 3 Feb 2022 14:50:05 -0800 Subject: [PATCH 404/569] More sharing of test logic --- example/test/example_test.dart | 8 +++--- example/test/json_convert_example_test.dart | 26 ++++++++----------- example/test/tuple_example_test.dart | 8 +++--- .../test/annotation_version_test.dart | 5 ++-- json_serializable/test/test_utils.dart | 5 ---- shared_test/lib/shared_test.dart | 4 +++ 6 files changed, 24 insertions(+), 32 deletions(-) diff --git a/example/test/example_test.dart b/example/test/example_test.dart index 55020c06b..e2abf3424 100644 --- a/example/test/example_test.dart +++ b/example/test/example_test.dart @@ -4,6 +4,7 @@ import 'dart:convert'; +import 'package:_json_serial_shared_test/shared_test.dart'; import 'package:example/example.dart'; import 'package:test/test.dart'; @@ -12,7 +13,7 @@ void main() { final person = Person('Inigo', 'Montoya', DateTime(1560, 5, 5)) ..orders = [Order(DateTime.now())..item = (Item()..count = 42)]; - final personJson = _encode(person); + final personJson = loudEncode(person); final person2 = Person.fromJson(json.decode(personJson) as Map<String, dynamic>); @@ -23,13 +24,10 @@ void main() { expect(person.orders.single.date, person2.orders.single.date); expect(person.orders.single.item!.count, 42); - expect(_encode(person2), equals(personJson)); + expect(loudEncode(person2), equals(personJson)); }); test('JsonLiteral', () { expect(glossaryData, hasLength(1)); }); } - -String _encode(Object object) => - const JsonEncoder.withIndent(' ').convert(object); diff --git a/example/test/json_convert_example_test.dart b/example/test/json_convert_example_test.dart index 8345874b4..1801b21cc 100644 --- a/example/test/json_convert_example_test.dart +++ b/example/test/json_convert_example_test.dart @@ -4,6 +4,7 @@ import 'dart:convert'; +import 'package:_json_serial_shared_test/shared_test.dart'; import 'package:example/json_converter_example.dart'; import 'package:test/test.dart'; @@ -13,7 +14,7 @@ void main() { final epochDateTime = DateTime.fromMillisecondsSinceEpoch(value); final instance = DateTimeExample(epochDateTime); - final json = _encode(instance); + final json = loudEncode(instance); expect(json, '''{ "when": $value }'''); @@ -27,13 +28,13 @@ void main() { final collection = GenericCollection<int>( page: 0, totalPages: 3, totalResults: 10, results: [1, 2, 3]); - final encoded = _encode(collection); + final encoded = loudEncode(collection); final collection2 = GenericCollection<int>.fromJson( jsonDecode(encoded) as Map<String, dynamic>); expect(collection2.results, [1, 2, 3]); - expect(_encode(collection2), encoded); + expect(loudEncode(collection2), encoded); }); test('custom result', () { @@ -43,13 +44,13 @@ void main() { totalResults: 10, results: [CustomResult('bob', 42)]); - final encoded = _encode(collection); + final encoded = loudEncode(collection); final collection2 = GenericCollection<CustomResult>.fromJson( jsonDecode(encoded) as Map<String, dynamic>); expect(collection2.results, [CustomResult('bob', 42)]); - expect(_encode(collection2), encoded); + expect(loudEncode(collection2), encoded); }); test('mixed values in generic collection', () { @@ -64,22 +65,22 @@ void main() { CustomResult('bob', 42) ]); - final encoded = _encode(collection); + final encoded = loudEncode(collection); expect( () => GenericCollection<CustomResult>.fromJson( jsonDecode(encoded) as Map<String, dynamic>), - _throwsTypeError, + throwsTypeError, ); expect( () => GenericCollection<int>.fromJson( jsonDecode(encoded) as Map<String, dynamic>), - _throwsTypeError, + throwsTypeError, ); expect( () => GenericCollection<String>.fromJson( jsonDecode(encoded) as Map<String, dynamic>), - _throwsTypeError, + throwsTypeError, ); final collection2 = @@ -95,11 +96,6 @@ void main() { CustomResult('bob', 42) ]); - expect(_encode(collection2), encoded); + expect(loudEncode(collection2), encoded); }); } - -final _throwsTypeError = throwsA(isA<TypeError>()); - -String _encode(Object object) => - const JsonEncoder.withIndent(' ').convert(object); diff --git a/example/test/tuple_example_test.dart b/example/test/tuple_example_test.dart index 67dc4fb43..b5d03ab71 100644 --- a/example/test/tuple_example_test.dart +++ b/example/test/tuple_example_test.dart @@ -4,6 +4,7 @@ import 'dart:convert'; +import 'package:_json_serial_shared_test/shared_test.dart'; import 'package:example/tuple_example.dart'; import 'package:test/test.dart'; @@ -14,7 +15,7 @@ void main() { Tuple(const Duration(seconds: 42), BigInt.two), ); - final encoded = _encode(instance); + final encoded = loudEncode(instance); const expected = r''' { @@ -32,10 +33,7 @@ void main() { final decoded = ConcreteClass.fromJson( jsonDecode(encoded) as Map<String, dynamic>, ); - final encoded2 = _encode(decoded); + final encoded2 = loudEncode(decoded); expect(encoded2, encoded); }); } - -String _encode(Object object) => - const JsonEncoder.withIndent(' ').convert(object); diff --git a/json_serializable/test/annotation_version_test.dart b/json_serializable/test/annotation_version_test.dart index e5431ec70..99af55588 100644 --- a/json_serializable/test/annotation_version_test.dart +++ b/json_serializable/test/annotation_version_test.dart @@ -4,7 +4,6 @@ @TestOn('vm') @Tags(['presubmit-only']) -import 'dart:convert'; import 'dart:io'; import 'package:json_serializable/src/check_dependencies.dart'; @@ -15,6 +14,8 @@ import 'package:test/test.dart'; import 'package:test_descriptor/test_descriptor.dart' as d; import 'package:test_process/test_process.dart'; +import 'test_utils.dart'; + void main() { test('validate pubspec constraint', () { final annotationConstraint = @@ -116,7 +117,7 @@ Future<void> _structurePackage({ Map<String, dynamic> dependencies = const {}, Map<String, dynamic> devDependencies = const {}, }) async { - final pubspec = const JsonEncoder.withIndent(' ').convert( + final pubspec = loudEncode( { 'name': '_test_pkg', 'environment': {'sdk': '>=2.14.0 <3.0.0'}, diff --git a/json_serializable/test/test_utils.dart b/json_serializable/test/test_utils.dart index ea943342d..7d09c427c 100644 --- a/json_serializable/test/test_utils.dart +++ b/json_serializable/test/test_utils.dart @@ -3,13 +3,8 @@ // BSD-style license that can be found in the LICENSE file. import 'package:collection/collection.dart'; -import 'package:test/test.dart'; export 'package:_json_serial_shared_test/shared_test.dart'; -final throwsTypeError = throwsA(isTypeError); - -final isTypeError = isA<TypeError>(); - bool deepEquals(dynamic a, dynamic b) => const DeepCollectionEquality().equals(a, b); diff --git a/shared_test/lib/shared_test.dart b/shared_test/lib/shared_test.dart index 4cf9dd96c..3085effbf 100644 --- a/shared_test/lib/shared_test.dart +++ b/shared_test/lib/shared_test.dart @@ -3,6 +3,10 @@ import 'dart:convert'; import 'package:stack_trace/stack_trace.dart'; import 'package:test/test.dart'; +final throwsTypeError = throwsA(isTypeError); + +final isTypeError = isA<TypeError>(); + /// Prints out nested causes before throwing `JsonUnsupportedObjectError`. String loudEncode(Object? object) { try { From b975aaca80f9e3d964138b62d4d63710ddebcf43 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Mon, 7 Feb 2022 09:29:43 -0800 Subject: [PATCH 405/569] Fix readme typo (#1091) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Péter Ferenc Gyarmati <40776291+peter-gy@users.noreply.github.com> --- json_serializable/README.md | 4 ++-- json_serializable/tool/readme/readme_template.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/json_serializable/README.md b/json_serializable/README.md index 050319619..3ed9023f5 100644 --- a/json_serializable/README.md +++ b/json_serializable/README.md @@ -17,8 +17,8 @@ in [package:json_annotation]. ## Setup -To configure your project for the latest released version of, -`json_serializable` see the [example]. +To configure your project for the latest released version of +`json_serializable`, see the [example]. ## Example diff --git a/json_serializable/tool/readme/readme_template.md b/json_serializable/tool/readme/readme_template.md index fa8c3956a..ab6fe9f6c 100644 --- a/json_serializable/tool/readme/readme_template.md +++ b/json_serializable/tool/readme/readme_template.md @@ -16,8 +16,8 @@ in [package:json_annotation]. ## Setup -To configure your project for the latest released version of, -`json_serializable` see the [example]. +To configure your project for the latest released version of +`json_serializable`, see the [example]. ## Example From 949494afc189c04ee341bd4db7c792e4e950b120 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 27 Feb 2022 20:20:22 -0800 Subject: [PATCH 406/569] Bump actions/setup-node from 2.5.1 to 3 (#1103) Bumps [actions/setup-node](https://github.com/actions/setup-node) from 2.5.1 to 3. - [Release notes](https://github.com/actions/setup-node/releases) - [Commits](https://github.com/actions/setup-node/compare/v2.5.1...v3) --- updated-dependencies: - dependency-name: actions/setup-node dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/markdown_linter.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/markdown_linter.yml b/.github/workflows/markdown_linter.yml index 6ef9afa89..db3a2e92e 100644 --- a/.github/workflows/markdown_linter.yml +++ b/.github/workflows/markdown_linter.yml @@ -21,7 +21,7 @@ jobs: steps: - uses: actions/checkout@v2.3.5 - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v2.5.1 + uses: actions/setup-node@v3 with: node-version: ${{ matrix.node-version }} - name: Install dependencies From ff32528de08c9ae4aac7ba194c5a6aba323e977f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 7 Mar 2022 09:45:40 -0800 Subject: [PATCH 407/569] Bump actions/checkout from 2.4.0 to 3 (#1109) Bumps [actions/checkout](https://github.com/actions/checkout) from 2.4.0 to 3. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v2.4.0...v3) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/dart.yml | 30 +++++++++++++-------------- .github/workflows/markdown_linter.yml | 4 ++-- tool/ci.sh | 2 +- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index bfb04f032..08f74cffb 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -1,4 +1,4 @@ -# Created with package:mono_repo v6.0.0 +# Created with package:mono_repo v6.1.0 name: Dart CI on: push: @@ -31,9 +31,9 @@ jobs: with: sdk: stable - id: checkout - uses: actions/checkout@v2.4.0 + uses: actions/checkout@v3.0.0 - name: mono_repo self validate - run: dart pub global activate mono_repo 6.0.0 + run: dart pub global activate mono_repo 6.1.0 - name: mono_repo self validate run: dart pub global run mono_repo generate --validate job_002: @@ -54,7 +54,7 @@ jobs: with: sdk: "2.14.0" - id: checkout - uses: actions/checkout@v2.4.0 + uses: actions/checkout@v3.0.0 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -138,7 +138,7 @@ jobs: with: sdk: dev - id: checkout - uses: actions/checkout@v2.4.0 + uses: actions/checkout@v3.0.0 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -222,7 +222,7 @@ jobs: with: sdk: "2.14.0" - id: checkout - uses: actions/checkout@v2.4.0 + uses: actions/checkout@v3.0.0 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -281,7 +281,7 @@ jobs: with: sdk: "2.14.0" - id: checkout - uses: actions/checkout@v2.4.0 + uses: actions/checkout@v3.0.0 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -313,7 +313,7 @@ jobs: with: sdk: "2.14.0" - id: checkout - uses: actions/checkout@v2.4.0 + uses: actions/checkout@v3.0.0 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -345,7 +345,7 @@ jobs: with: sdk: "2.14.0" - id: checkout - uses: actions/checkout@v2.4.0 + uses: actions/checkout@v3.0.0 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -377,7 +377,7 @@ jobs: with: sdk: dev - id: checkout - uses: actions/checkout@v2.4.0 + uses: actions/checkout@v3.0.0 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -436,7 +436,7 @@ jobs: with: sdk: dev - id: checkout - uses: actions/checkout@v2.4.0 + uses: actions/checkout@v3.0.0 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -468,7 +468,7 @@ jobs: with: sdk: dev - id: checkout - uses: actions/checkout@v2.4.0 + uses: actions/checkout@v3.0.0 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -500,7 +500,7 @@ jobs: with: sdk: dev - id: checkout - uses: actions/checkout@v2.4.0 + uses: actions/checkout@v3.0.0 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -532,7 +532,7 @@ jobs: with: sdk: "2.14.0" - id: checkout - uses: actions/checkout@v2.4.0 + uses: actions/checkout@v3.0.0 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -590,7 +590,7 @@ jobs: with: sdk: dev - id: checkout - uses: actions/checkout@v2.4.0 + uses: actions/checkout@v3.0.0 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" diff --git a/.github/workflows/markdown_linter.yml b/.github/workflows/markdown_linter.yml index db3a2e92e..61c156315 100644 --- a/.github/workflows/markdown_linter.yml +++ b/.github/workflows/markdown_linter.yml @@ -11,7 +11,7 @@ jobs: markdown-link-check: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2.3.5 + - uses: actions/checkout@v3 - uses: gaurav-nelson/github-action-markdown-link-check@v1 markdown_lint: runs-on: ubuntu-latest @@ -19,7 +19,7 @@ jobs: matrix: node-version: [ 14.x ] steps: - - uses: actions/checkout@v2.3.5 + - uses: actions/checkout@v3 - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v3 with: diff --git a/tool/ci.sh b/tool/ci.sh index 14253e00a..531d6eaad 100755 --- a/tool/ci.sh +++ b/tool/ci.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Created with package:mono_repo v6.0.0 +# Created with package:mono_repo v6.1.0 # Support built in commands on windows out of the box. # When it is a flutter repo (check the pubspec.yaml for "sdk: flutter") From 74e6d0162bedf187c62716812817d15952c9f6ec Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Mon, 7 Mar 2022 11:12:56 -0800 Subject: [PATCH 408/569] Fix enum support for upcoming enhanced enums in Dart 2.17 (#1111) Fixes https://github.com/google/json_serializable.dart/issues/1110 Prepare v6.1.5 release --- json_serializable/CHANGELOG.md | 4 ++++ json_serializable/lib/src/utils.dart | 2 +- json_serializable/pubspec.yaml | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 0fb283958..889df6676 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,7 @@ +## 6.1.5 + +- Fix enum support for upcoming enhanced enums in Dart 2.17. + ## 6.1.4 - Fix issues with latest `package:analyzer` related to enums and annotations. diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index 3d33eddad..27dd2597a 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -156,7 +156,7 @@ ConstructorElement constructorByName(ClassElement classElement, String name) { /// Otherwise, `null`. Iterable<FieldElement>? iterateEnumFields(DartType targetType) { if (targetType is InterfaceType && targetType.element.isEnum) { - return targetType.element.fields.where((element) => !element.isSynthetic); + return targetType.element.fields.where((element) => element.isEnumConstant); } return null; } diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 48430e9ab..bfa5bd4fe 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 6.1.4 +version: 6.1.5 description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. From e47633d38ada4ac8e10484363e5715d09f2865c3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 1 Apr 2022 12:38:10 -0700 Subject: [PATCH 409/569] Bump actions/cache from 2.1.7 to 3 (#1122) Bumps [actions/cache](https://github.com/actions/cache) from 2.1.7 to 3. - [Release notes](https://github.com/actions/cache/releases) - [Commits](https://github.com/actions/cache/compare/v2.1.7...v3) --- updated-dependencies: - dependency-name: actions/cache dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/dart.yml | 30 +++++++++++++++--------------- tool/ci.sh | 2 +- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 08f74cffb..ffd85e33b 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -1,4 +1,4 @@ -# Created with package:mono_repo v6.1.0 +# Created with package:mono_repo v6.2.0 name: Dart CI on: push: @@ -20,7 +20,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v2.1.7 + uses: actions/cache@v3 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:stable" @@ -33,7 +33,7 @@ jobs: - id: checkout uses: actions/checkout@v3.0.0 - name: mono_repo self validate - run: dart pub global activate mono_repo 6.1.0 + run: dart pub global activate mono_repo 6.2.0 - name: mono_repo self validate run: dart pub global run mono_repo generate --validate job_002: @@ -41,7 +41,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v2.1.7 + uses: actions/cache@v3 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.14.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:format-analyze" @@ -125,7 +125,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v2.1.7 + uses: actions/cache@v3 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:format-analyze" @@ -209,7 +209,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v2.1.7 + uses: actions/cache@v3 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.14.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" @@ -268,7 +268,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v2.1.7 + uses: actions/cache@v3 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.14.0;packages:json_serializable;commands:test_3" @@ -300,7 +300,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v2.1.7 + uses: actions/cache@v3 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.14.0;packages:json_serializable;commands:test_1" @@ -332,7 +332,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v2.1.7 + uses: actions/cache@v3 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.14.0;packages:json_serializable;commands:test_2" @@ -364,7 +364,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v2.1.7 + uses: actions/cache@v3 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" @@ -423,7 +423,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v2.1.7 + uses: actions/cache@v3 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:json_serializable;commands:test_3" @@ -455,7 +455,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v2.1.7 + uses: actions/cache@v3 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:json_serializable;commands:test_1" @@ -487,7 +487,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v2.1.7 + uses: actions/cache@v3 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:json_serializable;commands:test_2" @@ -519,7 +519,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v2.1.7 + uses: actions/cache@v3 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.14.0;packages:_test_yaml-checked_yaml-example;commands:test_1" @@ -577,7 +577,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v2.1.7 + uses: actions/cache@v3 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:_test_yaml-checked_yaml-example;commands:test_1" diff --git a/tool/ci.sh b/tool/ci.sh index 531d6eaad..35a511af7 100755 --- a/tool/ci.sh +++ b/tool/ci.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Created with package:mono_repo v6.1.0 +# Created with package:mono_repo v6.2.0 # Support built in commands on windows out of the box. # When it is a flutter repo (check the pubspec.yaml for "sdk: flutter") From f484a8dc7bdfc49a6e9e4b640002d1c5034fd6cc Mon Sep 17 00:00:00 2001 From: Jacob MacDonald <jakemac@google.com> Date: Tue, 5 Apr 2022 10:56:36 -0700 Subject: [PATCH 410/569] add mono_pkg.yaml file to shared_test package (#1127) --- shared_test/mono_pkg.yaml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 shared_test/mono_pkg.yaml diff --git a/shared_test/mono_pkg.yaml b/shared_test/mono_pkg.yaml new file mode 100644 index 000000000..090f30901 --- /dev/null +++ b/shared_test/mono_pkg.yaml @@ -0,0 +1,2 @@ +# No tests to run, this only registers this package with mono_repo for +# commands like `mono_repo pub get`. From 89602c5953a8a32b80dcc3609e07f653ffc4c051 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Thu, 14 Apr 2022 14:32:41 -0700 Subject: [PATCH 411/569] latest pkg:analyzer (#1130) --- json_serializable/CHANGELOG.md | 4 ++++ json_serializable/pubspec.yaml | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 889df6676..7be8bd13e 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,7 @@ +## 6.1.6 + +- Allow latest `package:analyzer`. + ## 6.1.5 - Fix enum support for upcoming enhanced enums in Dart 2.17. diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index bfa5bd4fe..524f9ad08 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 6.1.5 +version: 6.1.6 description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. @@ -8,7 +8,7 @@ environment: sdk: '>=2.14.0 <3.0.0' dependencies: - analyzer: '>=2.0.0 <4.0.0' + analyzer: '>=2.0.0 <5.0.0' async: ^2.8.0 build: ^2.0.0 build_config: '>=0.4.4 <2.0.0' From 51c45e8b17b0fc647f1bb540ce72cfdc8d4e11a1 Mon Sep 17 00:00:00 2001 From: Devon Carew <devoncarew@google.com> Date: Tue, 19 Apr 2022 17:06:57 -0700 Subject: [PATCH 412/569] Update pubspec.yaml (#1134) --- json_annotation/pubspec.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/json_annotation/pubspec.yaml b/json_annotation/pubspec.yaml index d7601b2ff..d40a82a1a 100644 --- a/json_annotation/pubspec.yaml +++ b/json_annotation/pubspec.yaml @@ -3,7 +3,8 @@ version: 4.4.0 description: >- Classes and helper functions that support JSON code generation via the `json_serializable` package. -repository: https://github.com/google/json_serializable.dart +repository: https://github.com/google/json_serializable.dart/tree/master/json_annotation + environment: sdk: '>=2.14.0 <3.0.0' From 66871781495743f4cbe8fee7b7aa05bd346a0f4e Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Thu, 21 Apr 2022 08:10:56 -0700 Subject: [PATCH 413/569] Update dependabot.yml --- .github/dependabot.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 655f40367..3be9dfa64 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -8,4 +8,4 @@ updates: directory: "/" schedule: # Check for updates to GitHub Actions weekly - interval: "weekly" + interval: "monthly" From ab218c7087fe8fb2002f4072cbfca6dc283210af Mon Sep 17 00:00:00 2001 From: zbarbuto <zbarbuto@nextfaze.com> Date: Wed, 27 Apr 2022 07:54:07 +0930 Subject: [PATCH 414/569] Add support for screaming snake case (#1118) Fixes #1032 --- checked_yaml/pubspec.yaml | 2 ++ json_annotation/lib/src/json_serializable.dart | 6 +++++- json_annotation/lib/src/json_serializable.g.dart | 1 + .../lib/src/type_helpers/config_types.dart | 1 + json_serializable/lib/src/utils.dart | 2 ++ json_serializable/pubspec.yaml | 4 ++++ json_serializable/test/config_test.dart | 2 +- .../test/json_serializable_test.dart | 1 + .../test/src/field_namer_input.dart | 16 ++++++++++++++++ 9 files changed, 33 insertions(+), 2 deletions(-) diff --git a/checked_yaml/pubspec.yaml b/checked_yaml/pubspec.yaml index 1d8f36ae6..f02b54271 100644 --- a/checked_yaml/pubspec.yaml +++ b/checked_yaml/pubspec.yaml @@ -24,3 +24,5 @@ dev_dependencies: dependency_overrides: json_annotation: path: ../json_annotation + json_serializable: + path: ../json_serializable diff --git a/json_annotation/lib/src/json_serializable.dart b/json_annotation/lib/src/json_serializable.dart index 5267277bb..6a2278c8c 100644 --- a/json_annotation/lib/src/json_serializable.dart +++ b/json_annotation/lib/src/json_serializable.dart @@ -22,7 +22,11 @@ enum FieldRename { snake, /// Encodes a field named `pascalCase` with a JSON key `PascalCase`. - pascal + pascal, + + /// Encodes a field named `screamingSnakeCase` with a JSON key + /// `SCREAMING_SNAKE_CASE` + screamingSnake, } /// An annotation used to specify a class to generate code for. diff --git a/json_annotation/lib/src/json_serializable.g.dart b/json_annotation/lib/src/json_serializable.g.dart index bab0898c6..65d452093 100644 --- a/json_annotation/lib/src/json_serializable.g.dart +++ b/json_annotation/lib/src/json_serializable.g.dart @@ -117,4 +117,5 @@ const _$FieldRenameEnumMap = { FieldRename.kebab: 'kebab', FieldRename.snake: 'snake', FieldRename.pascal: 'pascal', + FieldRename.screamingSnake: 'screamingSnake', }; diff --git a/json_serializable/lib/src/type_helpers/config_types.dart b/json_serializable/lib/src/type_helpers/config_types.dart index a90a1220d..0918b2138 100644 --- a/json_serializable/lib/src/type_helpers/config_types.dart +++ b/json_serializable/lib/src/type_helpers/config_types.dart @@ -117,6 +117,7 @@ const _$FieldRenameEnumMap = { FieldRename.kebab: 'kebab', FieldRename.snake: 'snake', FieldRename.pascal: 'pascal', + FieldRename.screamingSnake: 'screamingSnake', }; // #CHANGE WHEN UPDATING json_annotation diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index 27dd2597a..8edebaa5a 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -178,6 +178,8 @@ String encodedFieldName( return declaredName; case FieldRename.snake: return declaredName.snake; + case FieldRename.screamingSnake: + return declaredName.snake.toUpperCase(); case FieldRename.kebab: return declaredName.kebab; case FieldRename.pascal: diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 524f9ad08..93e874c8a 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -36,3 +36,7 @@ dev_dependencies: test_descriptor: ^2.0.0 test_process: ^2.0.0 yaml: ^3.0.0 + +dependency_overrides: + json_annotation: + path: ../json_annotation \ No newline at end of file diff --git a/json_serializable/test/config_test.dart b/json_serializable/test/config_test.dart index e137b0bbc..811567b81 100644 --- a/json_serializable/test/config_test.dart +++ b/json_serializable/test/config_test.dart @@ -120,7 +120,7 @@ void main() { case 'field_rename': lastLine = '`42` is not one of the supported values: none, kebab, snake, ' - 'pascal'; + 'pascal, screamingSnake'; break; case 'constructor': lastLine = "type 'int' is not a subtype of type 'String?' in type " diff --git a/json_serializable/test/json_serializable_test.dart b/json_serializable/test/json_serializable_test.dart index 9c9d8d834..9d29fce0b 100644 --- a/json_serializable/test/json_serializable_test.dart +++ b/json_serializable/test/json_serializable_test.dart @@ -58,6 +58,7 @@ const _expectedAnnotatedTests = { 'FieldNamerKebab', 'FieldNamerNone', 'FieldNamerPascal', + 'FieldNamerScreamingSnake', 'FieldNamerSnake', 'FieldWithFromJsonCtorAndTypeParams', 'FinalFields', diff --git a/json_serializable/test/src/field_namer_input.dart b/json_serializable/test/src/field_namer_input.dart index 5f8bc6011..98cbadd8c 100644 --- a/json_serializable/test/src/field_namer_input.dart +++ b/json_serializable/test/src/field_namer_input.dart @@ -59,3 +59,19 @@ class FieldNamerSnake { @JsonKey(name: 'NAME_OVERRIDE') late String nameOverride; } + +@ShouldGenerate(r''' +Map<String, dynamic> _$FieldNamerScreamingSnakeToJson( + FieldNamerScreamingSnake instance) => + <String, dynamic>{ + 'THE_FIELD': instance.theField, + 'nameOverride': instance.nameOverride, + }; +''') +@JsonSerializable(fieldRename: FieldRename.screamingSnake, createFactory: false) +class FieldNamerScreamingSnake { + late String theField; + + @JsonKey(name: 'nameOverride') + late String nameOverride; +} From 0d836a4db0be672488029252e6be366d90b12d89 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Tue, 26 Apr 2022 16:50:07 -0700 Subject: [PATCH 415/569] changelog and pubspec tweaks (#1141) Follow-up to #1118 --- json_annotation/CHANGELOG.md | 4 ++++ json_annotation/pubspec.yaml | 2 +- json_serializable/CHANGELOG.md | 5 +++++ json_serializable/README.md | 16 ++++++++-------- .../lib/src/check_dependencies.dart | 2 +- json_serializable/pubspec.yaml | 4 ++-- 6 files changed, 21 insertions(+), 12 deletions(-) diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index 3fd593498..1bc03904c 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -1,3 +1,7 @@ +## 4.5.0 + +- Added `FieldRename.screamingSnake`. + ## 4.4.0 - Added `JsonKey.readValue`. diff --git a/json_annotation/pubspec.yaml b/json_annotation/pubspec.yaml index d40a82a1a..a192cafa5 100644 --- a/json_annotation/pubspec.yaml +++ b/json_annotation/pubspec.yaml @@ -1,5 +1,5 @@ name: json_annotation -version: 4.4.0 +version: 4.5.0 description: >- Classes and helper functions that support JSON code generation via the `json_serializable` package. diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 7be8bd13e..fc5676b04 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,8 @@ +## 6.2.0 + +- Added support for the new `FieldRename.screamingSnake` field in + `package:json_annotation`. + ## 6.1.6 - Allow latest `package:analyzer`. diff --git a/json_serializable/README.md b/json_serializable/README.md index 3ed9023f5..3694c32dd 100644 --- a/json_serializable/README.md +++ b/json_serializable/README.md @@ -199,14 +199,14 @@ targets: [`Enum`]: https://api.dart.dev/stable/dart-core/Enum-class.html [`int`]: https://api.dart.dev/stable/dart-core/int-class.html [`Iterable`]: https://api.dart.dev/stable/dart-core/Iterable-class.html -[`JsonConverter`]: https://pub.dev/documentation/json_annotation/4.4.0/json_annotation/JsonConverter-class.html -[`JsonEnum`]: https://pub.dev/documentation/json_annotation/4.4.0/json_annotation/JsonEnum-class.html -[`JsonKey.fromJson`]: https://pub.dev/documentation/json_annotation/4.4.0/json_annotation/JsonKey/fromJson.html -[`JsonKey.toJson`]: https://pub.dev/documentation/json_annotation/4.4.0/json_annotation/JsonKey/toJson.html -[`JsonKey`]: https://pub.dev/documentation/json_annotation/4.4.0/json_annotation/JsonKey-class.html -[`JsonLiteral`]: https://pub.dev/documentation/json_annotation/4.4.0/json_annotation/JsonLiteral-class.html -[`JsonSerializable`]: https://pub.dev/documentation/json_annotation/4.4.0/json_annotation/JsonSerializable-class.html -[`JsonValue`]: https://pub.dev/documentation/json_annotation/4.4.0/json_annotation/JsonValue-class.html +[`JsonConverter`]: https://pub.dev/documentation/json_annotation/4.5.0/json_annotation/JsonConverter-class.html +[`JsonEnum`]: https://pub.dev/documentation/json_annotation/4.5.0/json_annotation/JsonEnum-class.html +[`JsonKey.fromJson`]: https://pub.dev/documentation/json_annotation/4.5.0/json_annotation/JsonKey/fromJson.html +[`JsonKey.toJson`]: https://pub.dev/documentation/json_annotation/4.5.0/json_annotation/JsonKey/toJson.html +[`JsonKey`]: https://pub.dev/documentation/json_annotation/4.5.0/json_annotation/JsonKey-class.html +[`JsonLiteral`]: https://pub.dev/documentation/json_annotation/4.5.0/json_annotation/JsonLiteral-class.html +[`JsonSerializable`]: https://pub.dev/documentation/json_annotation/4.5.0/json_annotation/JsonSerializable-class.html +[`JsonValue`]: https://pub.dev/documentation/json_annotation/4.5.0/json_annotation/JsonValue-class.html [`List`]: https://api.dart.dev/stable/dart-core/List-class.html [`Map`]: https://api.dart.dev/stable/dart-core/Map-class.html [`num`]: https://api.dart.dev/stable/dart-core/num-class.html diff --git a/json_serializable/lib/src/check_dependencies.dart b/json_serializable/lib/src/check_dependencies.dart index e6cf92a85..ec72bdb0f 100644 --- a/json_serializable/lib/src/check_dependencies.dart +++ b/json_serializable/lib/src/check_dependencies.dart @@ -10,7 +10,7 @@ import 'package:pubspec_parse/pubspec_parse.dart'; const _productionDirectories = {'lib', 'bin'}; const _annotationPkgName = 'json_annotation'; -final requiredJsonAnnotationMinVersion = Version.parse('4.4.0'); +final requiredJsonAnnotationMinVersion = Version.parse('4.5.0'); Future<void> pubspecHasRightVersion(BuildStep buildStep) async { final segments = buildStep.inputId.pathSegments; diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 93e874c8a..007f80985 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 6.1.6 +version: 6.2.0 description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. @@ -16,7 +16,7 @@ dependencies: # Use a tight version constraint to ensure that a constraint on # `json_annotation` properly constrains all features it provides. - json_annotation: '>=4.4.0 <4.5.0' + json_annotation: '>=4.5.0 <4.6.0' meta: ^1.3.0 path: ^1.8.0 pub_semver: ^2.0.0 From 5dbb1b2fcd648611fe77b5a6d313f750f3a6dd0f Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Wed, 27 Apr 2022 11:20:42 -0700 Subject: [PATCH 416/569] Prepare to release json_serializable v6.2.0 (#1142) --- checked_yaml/pubspec.yaml | 2 -- json_serializable/pubspec.yaml | 4 ---- 2 files changed, 6 deletions(-) diff --git a/checked_yaml/pubspec.yaml b/checked_yaml/pubspec.yaml index f02b54271..44b447747 100644 --- a/checked_yaml/pubspec.yaml +++ b/checked_yaml/pubspec.yaml @@ -22,7 +22,5 @@ dev_dependencies: test_process: ^2.0.0 dependency_overrides: - json_annotation: - path: ../json_annotation json_serializable: path: ../json_serializable diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 007f80985..081f91ac1 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -36,7 +36,3 @@ dev_dependencies: test_descriptor: ^2.0.0 test_process: ^2.0.0 yaml: ^3.0.0 - -dependency_overrides: - json_annotation: - path: ../json_annotation \ No newline at end of file From 09cca32f7548fe8a31b5db0941ca142a13f0ed6e Mon Sep 17 00:00:00 2001 From: Remi Rousselet <darky12s@gmail.com> Date: Thu, 28 Apr 2022 19:46:47 +0200 Subject: [PATCH 417/569] Support using non-nullable JsonConverter on nullable properties (#1136) fixes #822 --- json_serializable/CHANGELOG.md | 5 ++ .../type_helpers/json_converter_helper.dart | 90 +++++++++++++++++-- json_serializable/pubspec.yaml | 2 +- .../test/generic_files/generic_class.g.dart | 26 ++++-- .../test/json_serializable_test.dart | 1 + .../test/kitchen_sink/kitchen_sink.dart | 14 +++ .../test/kitchen_sink/kitchen_sink.g.dart | 37 ++++++++ .../kitchen_sink/kitchen_sink.g_any_map.dart | 14 +++ .../kitchen_sink.g_any_map.g.dart | 37 ++++++++ .../kitchen_sink.g_any_map__checked.dart | 14 +++ .../kitchen_sink.g_any_map__checked.g.dart | 44 +++++++++ .../kitchen_sink.g_exclude_null.dart | 14 +++ .../kitchen_sink.g_exclude_null.g.dart | 41 +++++++++ .../kitchen_sink.g_explicit_to_json.dart | 14 +++ .../kitchen_sink.g_explicit_to_json.g.dart | 37 ++++++++ .../kitchen_sink/kitchen_sink_interface.dart | 3 + .../test/kitchen_sink/kitchen_sink_test.dart | 27 +++++- .../test/src/json_converter_test_input.dart | 22 +++++ 18 files changed, 426 insertions(+), 16 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index fc5676b04..7e79368d3 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,8 @@ +## 6.3.0-dev + +- Added support for using a `JsonConverter<MyClass, Object>` on properties + of type `MyClass?`. ([#822](https://github.com/google/json_serializable.dart/issues/822)) + ## 6.2.0 - Added support for the new `FieldRename.screamingSnake` field in diff --git a/json_serializable/lib/src/type_helpers/json_converter_helper.dart b/json_serializable/lib/src/type_helpers/json_converter_helper.dart index 8c0df9f3a..10fa483b4 100644 --- a/json_serializable/lib/src/type_helpers/json_converter_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_converter_helper.dart @@ -32,6 +32,24 @@ class JsonConverterHelper extends TypeHelper { return null; } + if (!converter.fieldType.isNullableType && targetType.isNullableType) { + const converterToJsonName = r'_$JsonConverterToJson'; + context.addMember(''' +Json? $converterToJsonName<Json, Value>( + Value? value, + Json? Function(Value value) toJson, +) => ${ifNullOrElse('value', 'null', 'toJson(value)')}; +'''); + + return _nullableJsonConverterLambdaResult( + converter, + name: converterToJsonName, + targetType: targetType, + expression: expression, + callback: '${converter.accessString}.toJson', + ); + } + return LambdaResult(expression, '${converter.accessString}.toJson'); } @@ -49,6 +67,24 @@ class JsonConverterHelper extends TypeHelper { final asContent = asStatement(converter.jsonType); + if (!converter.jsonType.isNullableType && targetType.isNullableType) { + const converterFromJsonName = r'_$JsonConverterFromJson'; + context.addMember(''' +Value? $converterFromJsonName<Json, Value>( + Object? json, + Value? Function(Json json) fromJson, +) => ${ifNullOrElse('json', 'null', 'fromJson(json as Json)')}; +'''); + + return _nullableJsonConverterLambdaResult( + converter, + name: converterFromJsonName, + targetType: targetType, + expression: expression, + callback: '${converter.accessString}.fromJson', + ); + } + return LambdaResult( expression, '${converter.accessString}.fromJson', @@ -57,24 +93,51 @@ class JsonConverterHelper extends TypeHelper { } } +String _nullableJsonConverterLambdaResult( + _JsonConvertData converter, { + required String name, + required DartType targetType, + required String expression, + required String callback, +}) { + final jsonDisplayString = typeToCode(converter.jsonType); + final fieldTypeDisplayString = converter.isGeneric + ? typeToCode(targetType) + : typeToCode(converter.fieldType); + + return '$name<$jsonDisplayString, $fieldTypeDisplayString>(' + '$expression, $callback)'; +} + class _JsonConvertData { final String accessString; final DartType jsonType; + final DartType fieldType; + final bool isGeneric; _JsonConvertData.className( String className, String accessor, this.jsonType, - ) : accessString = 'const $className${_withAccessor(accessor)}()'; + this.fieldType, + ) : accessString = 'const $className${_withAccessor(accessor)}()', + isGeneric = false; _JsonConvertData.genericClass( String className, String genericTypeArg, String accessor, this.jsonType, - ) : accessString = '$className<$genericTypeArg>${_withAccessor(accessor)}()'; + this.fieldType, + ) : accessString = + '$className<$genericTypeArg>${_withAccessor(accessor)}()', + isGeneric = true; - _JsonConvertData.propertyAccess(this.accessString, this.jsonType); + _JsonConvertData.propertyAccess( + this.accessString, + this.jsonType, + this.fieldType, + ) : isGeneric = false; static String _withAccessor(String accessor) => accessor.isEmpty ? '' : '.$accessor'; @@ -127,7 +190,11 @@ _JsonConvertData? _typeConverterFrom( accessString = '${enclosing.name}.$accessString'; } - return _JsonConvertData.propertyAccess(accessString, match.jsonType); + return _JsonConvertData.propertyAccess( + accessString, + match.jsonType, + match.fieldType, + ); } final reviver = ConstantReader(match.annotation).revive(); @@ -145,6 +212,7 @@ _JsonConvertData? _typeConverterFrom( match.genericTypeArg!, reviver.accessor, match.jsonType, + match.fieldType, ); } @@ -152,11 +220,13 @@ _JsonConvertData? _typeConverterFrom( match.annotation.type!.element!.name!, reviver.accessor, match.jsonType, + match.fieldType, ); } class _ConverterMatch { final DartObject annotation; + final DartType fieldType; final DartType jsonType; final ElementAnnotation elementAnnotation; final String? genericTypeArg; @@ -166,6 +236,7 @@ class _ConverterMatch { this.annotation, this.jsonType, this.genericTypeArg, + this.fieldType, ); } @@ -191,9 +262,15 @@ _ConverterMatch? _compatibleMatch( final fieldType = jsonConverterSuper.typeArguments[0]; - if (fieldType == targetType) { + // Allow assigning T to T? + if (fieldType == targetType || fieldType == targetType.promoteNonNullable()) { return _ConverterMatch( - annotation, constantValue, jsonConverterSuper.typeArguments[1], null); + annotation, + constantValue, + jsonConverterSuper.typeArguments[1], + null, + fieldType, + ); } if (fieldType is TypeParameterType && targetType is TypeParameterType) { @@ -212,6 +289,7 @@ _ConverterMatch? _compatibleMatch( constantValue, jsonConverterSuper.typeArguments[1], '${targetType.element.name}${targetType.isNullableType ? '?' : ''}', + fieldType, ); } diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 081f91ac1..00db66b4f 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 6.2.0 +version: 6.3.0-dev description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. diff --git a/json_serializable/test/generic_files/generic_class.g.dart b/json_serializable/test/generic_files/generic_class.g.dart index e45e840d4..c2f216483 100644 --- a/json_serializable/test/generic_files/generic_class.g.dart +++ b/json_serializable/test/generic_files/generic_class.g.dart @@ -39,10 +39,10 @@ GenericClassWithConverter<T, S> ..fieldObject = json['fieldObject'] ..fieldDynamic = json['fieldDynamic'] ..fieldInt = json['fieldInt'] as int? - ..fieldT = _SimpleConverter<T?>() - .fromJson(json['fieldT'] as Map<String, dynamic>) - ..fieldS = _SimpleConverter<S?>() - .fromJson(json['fieldS'] as Map<String, dynamic>) + ..fieldT = _$JsonConverterFromJson<Map<String, dynamic>, T>( + json['fieldT'], _SimpleConverter<T?>().fromJson) + ..fieldS = _$JsonConverterFromJson<Map<String, dynamic>, S>( + json['fieldS'], _SimpleConverter<S?>().fromJson) ..duration = const _DurationMillisecondConverter.named() .fromJson(json['duration'] as int?) ..listDuration = const _DurationListMillisecondConverter() @@ -54,14 +54,28 @@ Map<String, dynamic> _$GenericClassWithConverterToJson<T extends num, S>( 'fieldObject': instance.fieldObject, 'fieldDynamic': instance.fieldDynamic, 'fieldInt': instance.fieldInt, - 'fieldT': _SimpleConverter<T?>().toJson(instance.fieldT), - 'fieldS': _SimpleConverter<S?>().toJson(instance.fieldS), + 'fieldT': _$JsonConverterToJson<Map<String, dynamic>, T>( + instance.fieldT, _SimpleConverter<T?>().toJson), + 'fieldS': _$JsonConverterToJson<Map<String, dynamic>, S>( + instance.fieldS, _SimpleConverter<S?>().toJson), 'duration': const _DurationMillisecondConverter.named().toJson(instance.duration), 'listDuration': const _DurationListMillisecondConverter() .toJson(instance.listDuration), }; +Value? _$JsonConverterFromJson<Json, Value>( + Object? json, + Value? Function(Json json) fromJson, +) => + json == null ? null : fromJson(json as Json); + +Json? _$JsonConverterToJson<Json, Value>( + Value? value, + Json? Function(Value value) toJson, +) => + value == null ? null : toJson(value); + Issue980ParentClass _$Issue980ParentClassFromJson(Map<String, dynamic> json) => Issue980ParentClass( (json['list'] as List<dynamic>) diff --git a/json_serializable/test/json_serializable_test.dart b/json_serializable/test/json_serializable_test.dart index 9d29fce0b..ef5e38e01 100644 --- a/json_serializable/test/json_serializable_test.dart +++ b/json_serializable/test/json_serializable_test.dart @@ -85,6 +85,7 @@ const _expectedAnnotatedTests = { 'JsonConverterCtorParams', 'JsonConverterDuplicateAnnotations', 'JsonConverterNamedCtor', + 'JsonConverterNullableToNonNullable', 'JsonConverterOnGetter', 'JsonConverterWithBadTypeArg', 'JsonValueValid', diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.dart b/json_serializable/test/kitchen_sink/kitchen_sink.dart index 92bd1c94d..4eabab0e2 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.dart @@ -66,9 +66,13 @@ class _Factory implements k.KitchenSinkFactory<String, dynamic> { [], BigInt.zero, {}, + BigInt.zero, + {}, TrivialNumber(0), {}, DateTime.fromMillisecondsSinceEpoch(0), + TrivialNumber(0), + {}, ); k.JsonConverterTestClass jsonConverterFromJson(Map<String, dynamic> json) => @@ -203,9 +207,13 @@ class JsonConverterTestClass implements k.JsonConverterTestClass { this.durationList, this.bigInt, this.bigIntMap, + this.nullableBigInt, + this.nullableBigIntMap, this.numberSilly, this.numberSillySet, this.dateTime, + this.nullableNumberSilly, + this.nullableNumberSillySet, ); factory JsonConverterTestClass.fromJson(Map<String, dynamic> json) => @@ -219,10 +227,16 @@ class JsonConverterTestClass implements k.JsonConverterTestClass { BigInt bigInt; Map<String, BigInt> bigIntMap; + BigInt? nullableBigInt; + Map<String, BigInt?> nullableBigIntMap; + TrivialNumber numberSilly; Set<TrivialNumber> numberSillySet; DateTime? dateTime; + + TrivialNumber? nullableNumberSilly; + Set<TrivialNumber?> nullableNumberSillySet; } @JsonSerializable() diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g.dart index ec7fa097c..c74f6aee0 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g.dart @@ -146,11 +146,24 @@ JsonConverterTestClass _$JsonConverterTestClassFromJson( (k, e) => MapEntry(k, const BigIntStringConverter().fromJson(e as String)), ), + _$JsonConverterFromJson<String, BigInt>( + json['nullableBigInt'], const BigIntStringConverter().fromJson), + (json['nullableBigIntMap'] as Map<String, dynamic>).map( + (k, e) => MapEntry( + k, + _$JsonConverterFromJson<String, BigInt>( + e, const BigIntStringConverter().fromJson)), + ), TrivialNumberConverter.instance.fromJson(json['numberSilly'] as int?), (json['numberSillySet'] as List<dynamic>) .map((e) => TrivialNumberConverter.instance.fromJson(e as int?)) .toSet(), const EpochDateTimeConverter().fromJson(json['dateTime'] as int?), + TrivialNumberConverter.instance + .fromJson(json['nullableNumberSilly'] as int?), + (json['nullableNumberSillySet'] as List<dynamic>) + .map((e) => TrivialNumberConverter.instance.fromJson(e as int?)) + .toSet(), ); Map<String, dynamic> _$JsonConverterTestClassToJson( @@ -162,14 +175,38 @@ Map<String, dynamic> _$JsonConverterTestClassToJson( 'bigInt': const BigIntStringConverter().toJson(instance.bigInt), 'bigIntMap': instance.bigIntMap .map((k, e) => MapEntry(k, const BigIntStringConverter().toJson(e))), + 'nullableBigInt': _$JsonConverterToJson<String, BigInt>( + instance.nullableBigInt, const BigIntStringConverter().toJson), + 'nullableBigIntMap': instance.nullableBigIntMap.map((k, e) => MapEntry( + k, + _$JsonConverterToJson<String, BigInt>( + e, const BigIntStringConverter().toJson))), 'numberSilly': TrivialNumberConverter.instance.toJson(instance.numberSilly), 'numberSillySet': instance.numberSillySet .map(TrivialNumberConverter.instance.toJson) .toList(), 'dateTime': const EpochDateTimeConverter().toJson(instance.dateTime), + 'nullableNumberSilly': _$JsonConverterToJson<int?, TrivialNumber>( + instance.nullableNumberSilly, TrivialNumberConverter.instance.toJson), + 'nullableNumberSillySet': instance.nullableNumberSillySet + .map((e) => _$JsonConverterToJson<int?, TrivialNumber>( + e, TrivialNumberConverter.instance.toJson)) + .toList(), }; +Value? _$JsonConverterFromJson<Json, Value>( + Object? json, + Value? Function(Json json) fromJson, +) => + json == null ? null : fromJson(json as Json); + +Json? _$JsonConverterToJson<Json, Value>( + Value? value, + Json? Function(Value value) toJson, +) => + value == null ? null : toJson(value); + JsonConverterGeneric<S, T, U> _$JsonConverterGenericFromJson<S, T, U>( Map<String, dynamic> json) => JsonConverterGeneric<S, T, U>( diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart index bf82df50d..9da91757a 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart @@ -65,9 +65,13 @@ class _Factory implements k.KitchenSinkFactory<dynamic, dynamic> { [], BigInt.zero, {}, + BigInt.zero, + {}, TrivialNumber(0), {}, DateTime.fromMillisecondsSinceEpoch(0), + TrivialNumber(0), + {}, ); k.JsonConverterTestClass jsonConverterFromJson(Map<String, dynamic> json) => @@ -205,9 +209,13 @@ class JsonConverterTestClass implements k.JsonConverterTestClass { this.durationList, this.bigInt, this.bigIntMap, + this.nullableBigInt, + this.nullableBigIntMap, this.numberSilly, this.numberSillySet, this.dateTime, + this.nullableNumberSilly, + this.nullableNumberSillySet, ); factory JsonConverterTestClass.fromJson(Map<String, dynamic> json) => @@ -221,10 +229,16 @@ class JsonConverterTestClass implements k.JsonConverterTestClass { BigInt bigInt; Map<String, BigInt> bigIntMap; + BigInt? nullableBigInt; + Map<String, BigInt?> nullableBigIntMap; + TrivialNumber numberSilly; Set<TrivialNumber> numberSillySet; DateTime? dateTime; + + TrivialNumber? nullableNumberSilly; + Set<TrivialNumber?> nullableNumberSillySet; } @JsonSerializable( diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart index 16d995c98..638091dcc 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart @@ -137,11 +137,24 @@ JsonConverterTestClass _$JsonConverterTestClassFromJson(Map json) => (k, e) => MapEntry( k as String, const BigIntStringConverter().fromJson(e as String)), ), + _$JsonConverterFromJson<String, BigInt>( + json['nullableBigInt'], const BigIntStringConverter().fromJson), + (json['nullableBigIntMap'] as Map).map( + (k, e) => MapEntry( + k as String, + _$JsonConverterFromJson<String, BigInt>( + e, const BigIntStringConverter().fromJson)), + ), TrivialNumberConverter.instance.fromJson(json['numberSilly'] as int?), (json['numberSillySet'] as List<dynamic>) .map((e) => TrivialNumberConverter.instance.fromJson(e as int?)) .toSet(), const EpochDateTimeConverter().fromJson(json['dateTime'] as int?), + TrivialNumberConverter.instance + .fromJson(json['nullableNumberSilly'] as int?), + (json['nullableNumberSillySet'] as List<dynamic>) + .map((e) => TrivialNumberConverter.instance.fromJson(e as int?)) + .toSet(), ); Map<String, dynamic> _$JsonConverterTestClassToJson( @@ -153,14 +166,38 @@ Map<String, dynamic> _$JsonConverterTestClassToJson( 'bigInt': const BigIntStringConverter().toJson(instance.bigInt), 'bigIntMap': instance.bigIntMap .map((k, e) => MapEntry(k, const BigIntStringConverter().toJson(e))), + 'nullableBigInt': _$JsonConverterToJson<String, BigInt>( + instance.nullableBigInt, const BigIntStringConverter().toJson), + 'nullableBigIntMap': instance.nullableBigIntMap.map((k, e) => MapEntry( + k, + _$JsonConverterToJson<String, BigInt>( + e, const BigIntStringConverter().toJson))), 'numberSilly': TrivialNumberConverter.instance.toJson(instance.numberSilly), 'numberSillySet': instance.numberSillySet .map(TrivialNumberConverter.instance.toJson) .toList(), 'dateTime': const EpochDateTimeConverter().toJson(instance.dateTime), + 'nullableNumberSilly': _$JsonConverterToJson<int?, TrivialNumber>( + instance.nullableNumberSilly, TrivialNumberConverter.instance.toJson), + 'nullableNumberSillySet': instance.nullableNumberSillySet + .map((e) => _$JsonConverterToJson<int?, TrivialNumber>( + e, TrivialNumberConverter.instance.toJson)) + .toList(), }; +Value? _$JsonConverterFromJson<Json, Value>( + Object? json, + Value? Function(Json json) fromJson, +) => + json == null ? null : fromJson(json as Json); + +Json? _$JsonConverterToJson<Json, Value>( + Value? value, + Json? Function(Value value) toJson, +) => + value == null ? null : toJson(value); + JsonConverterGeneric<S, T, U> _$JsonConverterGenericFromJson<S, T, U>( Map json) => JsonConverterGeneric<S, T, U>( diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.dart index 0a5119aa5..71812ba2e 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.dart @@ -65,9 +65,13 @@ class _Factory implements k.KitchenSinkFactory<dynamic, dynamic> { [], BigInt.zero, {}, + BigInt.zero, + {}, TrivialNumber(0), {}, DateTime.fromMillisecondsSinceEpoch(0), + TrivialNumber(0), + {}, ); k.JsonConverterTestClass jsonConverterFromJson(Map<String, dynamic> json) => @@ -207,9 +211,13 @@ class JsonConverterTestClass implements k.JsonConverterTestClass { this.durationList, this.bigInt, this.bigIntMap, + this.nullableBigInt, + this.nullableBigIntMap, this.numberSilly, this.numberSillySet, this.dateTime, + this.nullableNumberSilly, + this.nullableNumberSillySet, ); factory JsonConverterTestClass.fromJson(Map<String, dynamic> json) => @@ -223,10 +231,16 @@ class JsonConverterTestClass implements k.JsonConverterTestClass { BigInt bigInt; Map<String, BigInt> bigIntMap; + BigInt? nullableBigInt; + Map<String, BigInt?> nullableBigIntMap; + TrivialNumber numberSilly; Set<TrivialNumber> numberSillySet; DateTime? dateTime; + + TrivialNumber? nullableNumberSilly; + Set<TrivialNumber?> nullableNumberSillySet; } @JsonSerializable( diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.g.dart index 8be98d6cb..1d8c4c26b 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.g.dart @@ -198,6 +198,18 @@ JsonConverterTestClass _$JsonConverterTestClassFromJson(Map json) => (k, e) => MapEntry(k as String, const BigIntStringConverter().fromJson(e as String)), )), + $checkedConvert( + 'nullableBigInt', + (v) => _$JsonConverterFromJson<String, BigInt>( + v, const BigIntStringConverter().fromJson)), + $checkedConvert( + 'nullableBigIntMap', + (v) => (v as Map).map( + (k, e) => MapEntry( + k as String, + _$JsonConverterFromJson<String, BigInt>( + e, const BigIntStringConverter().fromJson)), + )), $checkedConvert('numberSilly', (v) => TrivialNumberConverter.instance.fromJson(v as int?)), $checkedConvert( @@ -208,6 +220,14 @@ JsonConverterTestClass _$JsonConverterTestClassFromJson(Map json) => .toSet()), $checkedConvert('dateTime', (v) => const EpochDateTimeConverter().fromJson(v as int?)), + $checkedConvert('nullableNumberSilly', + (v) => TrivialNumberConverter.instance.fromJson(v as int?)), + $checkedConvert( + 'nullableNumberSillySet', + (v) => (v as List<dynamic>) + .map((e) => + TrivialNumberConverter.instance.fromJson(e as int?)) + .toSet()), ); return val; }, @@ -222,14 +242,38 @@ Map<String, dynamic> _$JsonConverterTestClassToJson( 'bigInt': const BigIntStringConverter().toJson(instance.bigInt), 'bigIntMap': instance.bigIntMap .map((k, e) => MapEntry(k, const BigIntStringConverter().toJson(e))), + 'nullableBigInt': _$JsonConverterToJson<String, BigInt>( + instance.nullableBigInt, const BigIntStringConverter().toJson), + 'nullableBigIntMap': instance.nullableBigIntMap.map((k, e) => MapEntry( + k, + _$JsonConverterToJson<String, BigInt>( + e, const BigIntStringConverter().toJson))), 'numberSilly': TrivialNumberConverter.instance.toJson(instance.numberSilly), 'numberSillySet': instance.numberSillySet .map(TrivialNumberConverter.instance.toJson) .toList(), 'dateTime': const EpochDateTimeConverter().toJson(instance.dateTime), + 'nullableNumberSilly': _$JsonConverterToJson<int?, TrivialNumber>( + instance.nullableNumberSilly, TrivialNumberConverter.instance.toJson), + 'nullableNumberSillySet': instance.nullableNumberSillySet + .map((e) => _$JsonConverterToJson<int?, TrivialNumber>( + e, TrivialNumberConverter.instance.toJson)) + .toList(), }; +Value? _$JsonConverterFromJson<Json, Value>( + Object? json, + Value? Function(Json json) fromJson, +) => + json == null ? null : fromJson(json as Json); + +Json? _$JsonConverterToJson<Json, Value>( + Value? value, + Json? Function(Value value) toJson, +) => + value == null ? null : toJson(value); + JsonConverterGeneric<S, T, U> _$JsonConverterGenericFromJson<S, T, U>( Map json) => $checkedCreate( diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.dart index 5927b1aaa..a8fd5e1d8 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.dart @@ -66,9 +66,13 @@ class _Factory implements k.KitchenSinkFactory<String, dynamic> { [], BigInt.zero, {}, + BigInt.zero, + {}, TrivialNumber(0), {}, DateTime.fromMillisecondsSinceEpoch(0), + TrivialNumber(0), + {}, ); k.JsonConverterTestClass jsonConverterFromJson(Map<String, dynamic> json) => @@ -207,9 +211,13 @@ class JsonConverterTestClass implements k.JsonConverterTestClass { this.durationList, this.bigInt, this.bigIntMap, + this.nullableBigInt, + this.nullableBigIntMap, this.numberSilly, this.numberSillySet, this.dateTime, + this.nullableNumberSilly, + this.nullableNumberSillySet, ); factory JsonConverterTestClass.fromJson(Map<String, dynamic> json) => @@ -223,10 +231,16 @@ class JsonConverterTestClass implements k.JsonConverterTestClass { BigInt bigInt; Map<String, BigInt> bigIntMap; + BigInt? nullableBigInt; + Map<String, BigInt?> nullableBigIntMap; + TrivialNumber numberSilly; Set<TrivialNumber> numberSillySet; DateTime? dateTime; + + TrivialNumber? nullableNumberSilly; + Set<TrivialNumber?> nullableNumberSillySet; } @JsonSerializable( diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart index 6afeb29a2..a0246e8bc 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart @@ -154,11 +154,24 @@ JsonConverterTestClass _$JsonConverterTestClassFromJson( (k, e) => MapEntry(k, const BigIntStringConverter().fromJson(e as String)), ), + _$JsonConverterFromJson<String, BigInt>( + json['nullableBigInt'], const BigIntStringConverter().fromJson), + (json['nullableBigIntMap'] as Map<String, dynamic>).map( + (k, e) => MapEntry( + k, + _$JsonConverterFromJson<String, BigInt>( + e, const BigIntStringConverter().fromJson)), + ), TrivialNumberConverter.instance.fromJson(json['numberSilly'] as int?), (json['numberSillySet'] as List<dynamic>) .map((e) => TrivialNumberConverter.instance.fromJson(e as int?)) .toSet(), const EpochDateTimeConverter().fromJson(json['dateTime'] as int?), + TrivialNumberConverter.instance + .fromJson(json['nullableNumberSilly'] as int?), + (json['nullableNumberSillySet'] as List<dynamic>) + .map((e) => TrivialNumberConverter.instance.fromJson(e as int?)) + .toSet(), ); Map<String, dynamic> _$JsonConverterTestClassToJson( @@ -177,6 +190,14 @@ Map<String, dynamic> _$JsonConverterTestClassToJson( writeNotNull('bigInt', const BigIntStringConverter().toJson(instance.bigInt)); val['bigIntMap'] = instance.bigIntMap .map((k, e) => MapEntry(k, const BigIntStringConverter().toJson(e))); + writeNotNull( + 'nullableBigInt', + _$JsonConverterToJson<String, BigInt>( + instance.nullableBigInt, const BigIntStringConverter().toJson)); + val['nullableBigIntMap'] = instance.nullableBigIntMap.map((k, e) => MapEntry( + k, + _$JsonConverterToJson<String, BigInt>( + e, const BigIntStringConverter().toJson))); writeNotNull('numberSilly', TrivialNumberConverter.instance.toJson(instance.numberSilly)); val['numberSillySet'] = instance.numberSillySet @@ -184,9 +205,29 @@ Map<String, dynamic> _$JsonConverterTestClassToJson( .toList(); writeNotNull( 'dateTime', const EpochDateTimeConverter().toJson(instance.dateTime)); + writeNotNull( + 'nullableNumberSilly', + _$JsonConverterToJson<int?, TrivialNumber>(instance.nullableNumberSilly, + TrivialNumberConverter.instance.toJson)); + val['nullableNumberSillySet'] = instance.nullableNumberSillySet + .map((e) => _$JsonConverterToJson<int?, TrivialNumber>( + e, TrivialNumberConverter.instance.toJson)) + .toList(); return val; } +Value? _$JsonConverterFromJson<Json, Value>( + Object? json, + Value? Function(Json json) fromJson, +) => + json == null ? null : fromJson(json as Json); + +Json? _$JsonConverterToJson<Json, Value>( + Value? value, + Json? Function(Value value) toJson, +) => + value == null ? null : toJson(value); + JsonConverterGeneric<S, T, U> _$JsonConverterGenericFromJson<S, T, U>( Map<String, dynamic> json) => JsonConverterGeneric<S, T, U>( diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.dart index bce55d5f0..f5f13fc7d 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.dart @@ -66,9 +66,13 @@ class _Factory implements k.KitchenSinkFactory<String, dynamic> { [], BigInt.zero, {}, + BigInt.zero, + {}, TrivialNumber(0), {}, DateTime.fromMillisecondsSinceEpoch(0), + TrivialNumber(0), + {}, ); k.JsonConverterTestClass jsonConverterFromJson(Map<String, dynamic> json) => @@ -207,9 +211,13 @@ class JsonConverterTestClass implements k.JsonConverterTestClass { this.durationList, this.bigInt, this.bigIntMap, + this.nullableBigInt, + this.nullableBigIntMap, this.numberSilly, this.numberSillySet, this.dateTime, + this.nullableNumberSilly, + this.nullableNumberSillySet, ); factory JsonConverterTestClass.fromJson(Map<String, dynamic> json) => @@ -223,10 +231,16 @@ class JsonConverterTestClass implements k.JsonConverterTestClass { BigInt bigInt; Map<String, BigInt> bigIntMap; + BigInt? nullableBigInt; + Map<String, BigInt?> nullableBigIntMap; + TrivialNumber numberSilly; Set<TrivialNumber> numberSillySet; DateTime? dateTime; + + TrivialNumber? nullableNumberSilly; + Set<TrivialNumber?> nullableNumberSillySet; } @JsonSerializable( diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart index cb0415623..e6f218fa6 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart @@ -148,11 +148,24 @@ JsonConverterTestClass _$JsonConverterTestClassFromJson( (k, e) => MapEntry(k, const BigIntStringConverter().fromJson(e as String)), ), + _$JsonConverterFromJson<String, BigInt>( + json['nullableBigInt'], const BigIntStringConverter().fromJson), + (json['nullableBigIntMap'] as Map<String, dynamic>).map( + (k, e) => MapEntry( + k, + _$JsonConverterFromJson<String, BigInt>( + e, const BigIntStringConverter().fromJson)), + ), TrivialNumberConverter.instance.fromJson(json['numberSilly'] as int?), (json['numberSillySet'] as List<dynamic>) .map((e) => TrivialNumberConverter.instance.fromJson(e as int?)) .toSet(), const EpochDateTimeConverter().fromJson(json['dateTime'] as int?), + TrivialNumberConverter.instance + .fromJson(json['nullableNumberSilly'] as int?), + (json['nullableNumberSillySet'] as List<dynamic>) + .map((e) => TrivialNumberConverter.instance.fromJson(e as int?)) + .toSet(), ); Map<String, dynamic> _$JsonConverterTestClassToJson( @@ -164,14 +177,38 @@ Map<String, dynamic> _$JsonConverterTestClassToJson( 'bigInt': const BigIntStringConverter().toJson(instance.bigInt), 'bigIntMap': instance.bigIntMap .map((k, e) => MapEntry(k, const BigIntStringConverter().toJson(e))), + 'nullableBigInt': _$JsonConverterToJson<String, BigInt>( + instance.nullableBigInt, const BigIntStringConverter().toJson), + 'nullableBigIntMap': instance.nullableBigIntMap.map((k, e) => MapEntry( + k, + _$JsonConverterToJson<String, BigInt>( + e, const BigIntStringConverter().toJson))), 'numberSilly': TrivialNumberConverter.instance.toJson(instance.numberSilly), 'numberSillySet': instance.numberSillySet .map(TrivialNumberConverter.instance.toJson) .toList(), 'dateTime': const EpochDateTimeConverter().toJson(instance.dateTime), + 'nullableNumberSilly': _$JsonConverterToJson<int?, TrivialNumber>( + instance.nullableNumberSilly, TrivialNumberConverter.instance.toJson), + 'nullableNumberSillySet': instance.nullableNumberSillySet + .map((e) => _$JsonConverterToJson<int?, TrivialNumber>( + e, TrivialNumberConverter.instance.toJson)) + .toList(), }; +Value? _$JsonConverterFromJson<Json, Value>( + Object? json, + Value? Function(Json json) fromJson, +) => + json == null ? null : fromJson(json as Json); + +Json? _$JsonConverterToJson<Json, Value>( + Value? value, + Json? Function(Value value) toJson, +) => + value == null ? null : toJson(value); + JsonConverterGeneric<S, T, U> _$JsonConverterGenericFromJson<S, T, U>( Map<String, dynamic> json) => JsonConverterGeneric<S, T, U>( diff --git a/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart b/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart index f69ade258..9f8740943 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart @@ -3,6 +3,7 @@ // BSD-style license that can be found in the LICENSE file. import '../test_utils.dart'; +import 'json_converters.dart'; import 'simple_object.dart'; /// A key name that requires special encoding @@ -41,6 +42,8 @@ abstract class KitchenSinkFactory<K, V> { } abstract class JsonConverterTestClass { + TrivialNumber? nullableNumberSilly; + Map<String, dynamic> toJson(); } diff --git a/json_serializable/test/kitchen_sink/kitchen_sink_test.dart b/json_serializable/test/kitchen_sink/kitchen_sink_test.dart index 8044c29d7..99e45bf40 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink_test.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink_test.dart @@ -6,6 +6,7 @@ import 'package:json_annotation/json_annotation.dart'; import 'package:test/test.dart'; import '../test_utils.dart'; +import 'json_converters.dart'; import 'kitchen_sink.factories.dart'; import 'kitchen_sink_interface.dart'; import 'kitchen_sink_test_shared.dart'; @@ -54,10 +55,14 @@ const _jsonConverterValidValues = { 'duration': 5, 'durationList': [5], 'bigInt': '5', - 'bigIntMap': {'vaule': '5'}, + 'bigIntMap': {'value': '5'}, 'numberSilly': 5, 'numberSillySet': [5], - 'dateTime': 5 + 'dateTime': 5, + 'nullableNumberSilly': 5, + 'nullableBigInt': '42', + 'nullableBigIntMap': {'value': '42'}, + 'nullableNumberSillySet': [42], }; void _nonNullableTests(KitchenSinkFactory factory) { @@ -96,9 +101,13 @@ void _nullableTests(KitchenSinkFactory factory) { 'durationList': [], 'bigInt': '0', 'bigIntMap': {}, + 'nullableBigInt': '0', + 'nullableBigIntMap': {}, 'numberSilly': 0, 'numberSillySet': [], - 'dateTime': 0 + 'dateTime': 0, + 'nullableNumberSilly': 0, + 'nullableNumberSillySet': [], }); expect(json.keys, unorderedEquals(_jsonConverterValidValues.keys)); @@ -183,6 +192,18 @@ void _sharedTests(KitchenSinkFactory factory) { roundTripObject(item, factory.fromJson); }); + test('JsonConverters with nullable JSON keys handle `null` JSON values', () { + final item = factory.jsonConverterFromJson({ + ..._jsonConverterValidValues, + 'nullableNumberSilly': null, + }); + + expect( + item.nullableNumberSilly, + isA<TrivialNumber>().having((e) => e.value, 'value', isNull), + ); + }); + test('list and map of DateTime - not null', () { final now = DateTime.now(); final item = factory.ctor(dateTimeIterable: <DateTime>[now]) diff --git a/json_serializable/test/src/json_converter_test_input.dart b/json_serializable/test/src/json_converter_test_input.dart index 10d029b41..fbe7da28c 100644 --- a/json_serializable/test/src/json_converter_test_input.dart +++ b/json_serializable/test/src/json_converter_test_input.dart @@ -189,3 +189,25 @@ class _NeedsConversionConverter @override int toJson(_NeedsConversion object) => 0; } + +@ShouldThrow( + ''' +Could not generate `fromJson` code for `value`. +To support the type `_NeedsConversion` you can: +$converterOrKeyInstructions''', +) +@_NullableConverter() +@JsonSerializable() +class JsonConverterNullableToNonNullable { + late _NeedsConversion value; +} + +class _NullableConverter implements JsonConverter<_NeedsConversion?, Object?> { + const _NullableConverter(); + + @override + _NeedsConversion? fromJson(Object? json) => null; + + @override + Object? toJson(_NeedsConversion? object) => null; +} From d5d73b85a83cab20938ba4cbdb32811e0f0413ed Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 28 Apr 2022 10:47:15 -0700 Subject: [PATCH 418/569] Bump actions/checkout from 3.0.0 to 3.0.2 (#1137) Bumps [actions/checkout](https://github.com/actions/checkout) from 3.0.0 to 3.0.2. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v3...v3.0.2) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * update Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Kevin Moore <kevmoo@google.com> --- .github/workflows/dart.yml | 30 +++++++++++++-------------- .github/workflows/markdown_linter.yml | 4 ++-- tool/ci.sh | 2 +- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index ffd85e33b..fcb1c1e86 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -1,4 +1,4 @@ -# Created with package:mono_repo v6.2.0 +# Created with package:mono_repo v6.2.2 name: Dart CI on: push: @@ -31,9 +31,9 @@ jobs: with: sdk: stable - id: checkout - uses: actions/checkout@v3.0.0 + uses: actions/checkout@v3 - name: mono_repo self validate - run: dart pub global activate mono_repo 6.2.0 + run: dart pub global activate mono_repo 6.2.2 - name: mono_repo self validate run: dart pub global run mono_repo generate --validate job_002: @@ -54,7 +54,7 @@ jobs: with: sdk: "2.14.0" - id: checkout - uses: actions/checkout@v3.0.0 + uses: actions/checkout@v3 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -138,7 +138,7 @@ jobs: with: sdk: dev - id: checkout - uses: actions/checkout@v3.0.0 + uses: actions/checkout@v3 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -222,7 +222,7 @@ jobs: with: sdk: "2.14.0" - id: checkout - uses: actions/checkout@v3.0.0 + uses: actions/checkout@v3 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -281,7 +281,7 @@ jobs: with: sdk: "2.14.0" - id: checkout - uses: actions/checkout@v3.0.0 + uses: actions/checkout@v3 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -313,7 +313,7 @@ jobs: with: sdk: "2.14.0" - id: checkout - uses: actions/checkout@v3.0.0 + uses: actions/checkout@v3 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -345,7 +345,7 @@ jobs: with: sdk: "2.14.0" - id: checkout - uses: actions/checkout@v3.0.0 + uses: actions/checkout@v3 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -377,7 +377,7 @@ jobs: with: sdk: dev - id: checkout - uses: actions/checkout@v3.0.0 + uses: actions/checkout@v3 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -436,7 +436,7 @@ jobs: with: sdk: dev - id: checkout - uses: actions/checkout@v3.0.0 + uses: actions/checkout@v3 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -468,7 +468,7 @@ jobs: with: sdk: dev - id: checkout - uses: actions/checkout@v3.0.0 + uses: actions/checkout@v3 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -500,7 +500,7 @@ jobs: with: sdk: dev - id: checkout - uses: actions/checkout@v3.0.0 + uses: actions/checkout@v3 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -532,7 +532,7 @@ jobs: with: sdk: "2.14.0" - id: checkout - uses: actions/checkout@v3.0.0 + uses: actions/checkout@v3 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -590,7 +590,7 @@ jobs: with: sdk: dev - id: checkout - uses: actions/checkout@v3.0.0 + uses: actions/checkout@v3 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" diff --git a/.github/workflows/markdown_linter.yml b/.github/workflows/markdown_linter.yml index 61c156315..4cb0e7e6f 100644 --- a/.github/workflows/markdown_linter.yml +++ b/.github/workflows/markdown_linter.yml @@ -11,7 +11,7 @@ jobs: markdown-link-check: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v3.0.2 - uses: gaurav-nelson/github-action-markdown-link-check@v1 markdown_lint: runs-on: ubuntu-latest @@ -19,7 +19,7 @@ jobs: matrix: node-version: [ 14.x ] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v3.0.2 - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v3 with: diff --git a/tool/ci.sh b/tool/ci.sh index 35a511af7..b601dbadc 100755 --- a/tool/ci.sh +++ b/tool/ci.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Created with package:mono_repo v6.2.0 +# Created with package:mono_repo v6.2.2 # Support built in commands on windows out of the box. # When it is a flutter repo (check the pubspec.yaml for "sdk: flutter") From 51224edb859f73d0caf5fc3f697e8de9d504a627 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Sun, 22 May 2022 14:40:42 -0700 Subject: [PATCH 419/569] Ignore deprecated API usage (#1150) --- json_serializable/lib/src/decode_helper.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/json_serializable/lib/src/decode_helper.dart b/json_serializable/lib/src/decode_helper.dart index adf774764..341446b92 100644 --- a/json_serializable/lib/src/decode_helper.dart +++ b/json_serializable/lib/src/decode_helper.dart @@ -278,6 +278,7 @@ _ConstructorData _writeConstructorInvocation( for (final arg in ctor.parameters) { if (!availableConstructorParameters.contains(arg.name)) { + // ignore: deprecated_member_use if (arg.isNotOptional) { var msg = 'Cannot populate the required constructor ' 'argument: ${arg.name}.'; From 8aadb45042179964eeb9f86f77fcec3b9104ed8b Mon Sep 17 00:00:00 2001 From: Remi Rousselet <darky12s@gmail.com> Date: Tue, 24 May 2022 04:55:04 +0200 Subject: [PATCH 420/569] Add JsonConverter(converters) option (#1135) Co-authored-by: Kevin Moore <kevmoo@users.noreply.github.com> --- checked_yaml/pubspec.yaml | 2 + json_annotation/CHANGELOG.md | 7 +- json_annotation/lib/src/json_converter.dart | 31 +++++++ .../lib/src/json_serializable.dart | 36 +++++++ json_annotation/pubspec.yaml | 2 +- json_serializable/CHANGELOG.md | 2 + json_serializable/README.md | 16 ++-- .../lib/src/check_dependencies.dart | 2 +- .../lib/src/json_serializable_generator.dart | 2 +- json_serializable/lib/src/settings.dart | 29 +----- .../lib/src/type_helpers/config_types.dart | 93 ++++++++----------- .../type_helpers/json_converter_helper.dart | 47 +++++++--- json_serializable/lib/src/utils.dart | 5 +- json_serializable/pubspec.yaml | 6 +- .../test/custom_configuration_test.dart | 18 ++-- .../test/kitchen_sink/json_converters.dart | 19 ++++ .../test/kitchen_sink/kitchen_sink.dart | 15 ++- .../test/kitchen_sink/kitchen_sink.g.dart | 14 ++- .../kitchen_sink/kitchen_sink.g_any_map.dart | 17 ++-- .../kitchen_sink.g_any_map.g.dart | 14 ++- .../kitchen_sink.g_any_map__checked.dart | 18 ++-- .../kitchen_sink.g_any_map__checked.g.dart | 18 ++-- .../kitchen_sink.g_exclude_null.dart | 17 ++-- .../kitchen_sink.g_exclude_null.g.dart | 15 ++- .../kitchen_sink.g_explicit_to_json.dart | 17 ++-- .../kitchen_sink.g_explicit_to_json.g.dart | 14 ++- .../test/kitchen_sink/kitchen_sink_test.dart | 2 + json_serializable/test/shared_config.dart | 5 +- 28 files changed, 314 insertions(+), 169 deletions(-) diff --git a/checked_yaml/pubspec.yaml b/checked_yaml/pubspec.yaml index 44b447747..f02b54271 100644 --- a/checked_yaml/pubspec.yaml +++ b/checked_yaml/pubspec.yaml @@ -22,5 +22,7 @@ dev_dependencies: test_process: ^2.0.0 dependency_overrides: + json_annotation: + path: ../json_annotation json_serializable: path: ../json_serializable diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index 1bc03904c..753827f52 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -1,3 +1,8 @@ +## 4.6.0 + +- Added `JsonSerializable(converters: <JsonConverter>[])` + ([#1072](https://github.com/google/json_serializable.dart/issues/1072)) + ## 4.5.0 - Added `FieldRename.screamingSnake`. @@ -38,7 +43,7 @@ ## 4.0.1 -- Fix a potential error with `checked: true` when `ArgumentError.message` is +- Fix a potential error with `checked: true` when `ArgumentError.message` is `null`. - Updated `JsonSerializable.fromJson` to handle `null` values. - Deprecate `JsonSerializable` `defaults` and `withDefaults()`. diff --git a/json_annotation/lib/src/json_converter.dart b/json_annotation/lib/src/json_converter.dart index ef98f3f27..73506e3ed 100644 --- a/json_annotation/lib/src/json_converter.dart +++ b/json_annotation/lib/src/json_converter.dart @@ -8,6 +8,37 @@ /// /// [S] is the type of the value stored in JSON. It must be a valid JSON type /// such as [String], [int], or [Map<String, dynamic>]. +/// +/// +/// [JsonConverter]s can be placed either on the class: +/// +/// ```dart +/// class MyConverter extends JsonConverter<Value, JSON> { +/// // TODO +/// } +/// +/// @JsonSerializable() +/// @MyJsonConverter() +/// class Example {} +/// ``` +/// +/// or on a property: +/// +/// ```dart +/// @JsonSerializable() +/// @MyJsonConverter() +/// class Example { +/// @MyJsonConverter() +/// final Value property; +/// } +/// ``` +/// +/// Or finally, passed to the annotation: +/// +///```dart +/// @JsonSerializable(converters: [MyConverter()]) +/// class Example {} +/// ``` abstract class JsonConverter<T, S> { const JsonConverter(); diff --git a/json_annotation/lib/src/json_serializable.dart b/json_annotation/lib/src/json_serializable.dart index 6a2278c8c..34fe2abb6 100644 --- a/json_annotation/lib/src/json_serializable.dart +++ b/json_annotation/lib/src/json_serializable.dart @@ -6,6 +6,7 @@ import 'package:meta/meta_meta.dart'; import 'allowed_keys_helpers.dart'; import 'checked_helpers.dart'; +import 'json_converter.dart'; import 'json_key.dart'; part 'json_serializable.g.dart'; @@ -190,6 +191,40 @@ class JsonSerializable { /// `includeIfNull`, that value takes precedent. final bool? includeIfNull; + /// A list of [JsonConverter] to apply to this class. + /// + /// Writing: + /// + /// ```dart + /// @JsonSerializable(converters: [MyJsonConverter()]) + /// class Example {...} + /// ``` + /// + /// is equivalent to writing: + /// + /// ```dart + /// @JsonSerializable() + /// @MyJsonConverter() + /// class Example {...} + /// ``` + /// + /// The main difference is that this allows reusing a custom + /// [JsonSerializable] over multiple classes: + /// + /// ```dart + /// const myCustomAnnotation = JsonSerializable( + /// converters: [MyJsonConverter()], + /// ); + /// + /// @myCustomAnnotation + /// class Example {...} + /// + /// @myCustomAnnotation + /// class Another {...} + /// ``` + @JsonKey(ignore: true) + final List<JsonConverter>? converters; + /// Creates a new [JsonSerializable] instance. const JsonSerializable({ @Deprecated('Has no effect') bool? nullable, @@ -203,6 +238,7 @@ class JsonSerializable { this.fieldRename, this.ignoreUnannotated, this.includeIfNull, + this.converters, this.genericArgumentFactories, }); diff --git a/json_annotation/pubspec.yaml b/json_annotation/pubspec.yaml index a192cafa5..7b875c142 100644 --- a/json_annotation/pubspec.yaml +++ b/json_annotation/pubspec.yaml @@ -1,5 +1,5 @@ name: json_annotation -version: 4.5.0 +version: 4.6.0 description: >- Classes and helper functions that support JSON code generation via the `json_serializable` package. diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 7e79368d3..ba3e21bc9 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -2,6 +2,8 @@ - Added support for using a `JsonConverter<MyClass, Object>` on properties of type `MyClass?`. ([#822](https://github.com/google/json_serializable.dart/issues/822)) +- Added support for `JsonSerializable(converters: <JsonConverter>[])` + ([#1072](https://github.com/google/json_serializable.dart/issues/1072)) ## 6.2.0 diff --git a/json_serializable/README.md b/json_serializable/README.md index 3694c32dd..ffdb481f7 100644 --- a/json_serializable/README.md +++ b/json_serializable/README.md @@ -199,14 +199,14 @@ targets: [`Enum`]: https://api.dart.dev/stable/dart-core/Enum-class.html [`int`]: https://api.dart.dev/stable/dart-core/int-class.html [`Iterable`]: https://api.dart.dev/stable/dart-core/Iterable-class.html -[`JsonConverter`]: https://pub.dev/documentation/json_annotation/4.5.0/json_annotation/JsonConverter-class.html -[`JsonEnum`]: https://pub.dev/documentation/json_annotation/4.5.0/json_annotation/JsonEnum-class.html -[`JsonKey.fromJson`]: https://pub.dev/documentation/json_annotation/4.5.0/json_annotation/JsonKey/fromJson.html -[`JsonKey.toJson`]: https://pub.dev/documentation/json_annotation/4.5.0/json_annotation/JsonKey/toJson.html -[`JsonKey`]: https://pub.dev/documentation/json_annotation/4.5.0/json_annotation/JsonKey-class.html -[`JsonLiteral`]: https://pub.dev/documentation/json_annotation/4.5.0/json_annotation/JsonLiteral-class.html -[`JsonSerializable`]: https://pub.dev/documentation/json_annotation/4.5.0/json_annotation/JsonSerializable-class.html -[`JsonValue`]: https://pub.dev/documentation/json_annotation/4.5.0/json_annotation/JsonValue-class.html +[`JsonConverter`]: https://pub.dev/documentation/json_annotation/4.6.0/json_annotation/JsonConverter-class.html +[`JsonEnum`]: https://pub.dev/documentation/json_annotation/4.6.0/json_annotation/JsonEnum-class.html +[`JsonKey.fromJson`]: https://pub.dev/documentation/json_annotation/4.6.0/json_annotation/JsonKey/fromJson.html +[`JsonKey.toJson`]: https://pub.dev/documentation/json_annotation/4.6.0/json_annotation/JsonKey/toJson.html +[`JsonKey`]: https://pub.dev/documentation/json_annotation/4.6.0/json_annotation/JsonKey-class.html +[`JsonLiteral`]: https://pub.dev/documentation/json_annotation/4.6.0/json_annotation/JsonLiteral-class.html +[`JsonSerializable`]: https://pub.dev/documentation/json_annotation/4.6.0/json_annotation/JsonSerializable-class.html +[`JsonValue`]: https://pub.dev/documentation/json_annotation/4.6.0/json_annotation/JsonValue-class.html [`List`]: https://api.dart.dev/stable/dart-core/List-class.html [`Map`]: https://api.dart.dev/stable/dart-core/Map-class.html [`num`]: https://api.dart.dev/stable/dart-core/num-class.html diff --git a/json_serializable/lib/src/check_dependencies.dart b/json_serializable/lib/src/check_dependencies.dart index ec72bdb0f..873be904a 100644 --- a/json_serializable/lib/src/check_dependencies.dart +++ b/json_serializable/lib/src/check_dependencies.dart @@ -10,7 +10,7 @@ import 'package:pubspec_parse/pubspec_parse.dart'; const _productionDirectories = {'lib', 'bin'}; const _annotationPkgName = 'json_annotation'; -final requiredJsonAnnotationMinVersion = Version.parse('4.5.0'); +final requiredJsonAnnotationMinVersion = Version.parse('4.6.0'); Future<void> pubspecHasRightVersion(BuildStep buildStep) async { final segments = buildStep.inputId.pathSegments; diff --git a/json_serializable/lib/src/json_serializable_generator.dart b/json_serializable/lib/src/json_serializable_generator.dart index 13a4b16e4..69ead4939 100644 --- a/json_serializable/lib/src/json_serializable_generator.dart +++ b/json_serializable/lib/src/json_serializable_generator.dart @@ -20,7 +20,7 @@ class JsonSerializableGenerator extends GeneratorForAnnotation<JsonSerializable> { final Settings _settings; - JsonSerializable get config => _settings.config; + JsonSerializable get config => _settings.config.toJsonSerializable(); JsonSerializableGenerator.fromSettings(this._settings); diff --git a/json_serializable/lib/src/settings.dart b/json_serializable/lib/src/settings.dart index f9561ce65..c73df1b7b 100644 --- a/json_serializable/lib/src/settings.dart +++ b/json_serializable/lib/src/settings.dart @@ -43,38 +43,19 @@ class Settings { GenericFactoryHelper(), ].followedBy(_typeHelpers).followedBy(_coreHelpers); - final JsonSerializable _config; - - // #CHANGE WHEN UPDATING json_annotation - ClassConfig get config => ClassConfig( - checked: _config.checked ?? ClassConfig.defaults.checked, - anyMap: _config.anyMap ?? ClassConfig.defaults.anyMap, - constructor: _config.constructor ?? ClassConfig.defaults.constructor, - createFactory: - _config.createFactory ?? ClassConfig.defaults.createFactory, - createToJson: _config.createToJson ?? ClassConfig.defaults.createToJson, - ignoreUnannotated: - _config.ignoreUnannotated ?? ClassConfig.defaults.ignoreUnannotated, - explicitToJson: - _config.explicitToJson ?? ClassConfig.defaults.explicitToJson, - includeIfNull: - _config.includeIfNull ?? ClassConfig.defaults.includeIfNull, - genericArgumentFactories: _config.genericArgumentFactories ?? - ClassConfig.defaults.genericArgumentFactories, - fieldRename: _config.fieldRename ?? ClassConfig.defaults.fieldRename, - disallowUnrecognizedKeys: _config.disallowUnrecognizedKeys ?? - ClassConfig.defaults.disallowUnrecognizedKeys, - ); + final ClassConfig config; /// Creates an instance of [Settings]. /// /// If [typeHelpers] is not provided, the built-in helpers are used: /// [BigIntHelper], [DateTimeHelper], [DurationHelper], [JsonHelper], and /// [UriHelper]. - const Settings({ + Settings({ JsonSerializable? config, List<TypeHelper>? typeHelpers, - }) : _config = config ?? ClassConfig.defaults, + }) : config = config != null + ? ClassConfig.fromJsonSerializable(config) + : ClassConfig.defaults, _typeHelpers = typeHelpers ?? defaultHelpers; /// Creates an instance of [Settings]. diff --git a/json_serializable/lib/src/type_helpers/config_types.dart b/json_serializable/lib/src/type_helpers/config_types.dart index 0918b2138..6d51ac475 100644 --- a/json_serializable/lib/src/type_helpers/config_types.dart +++ b/json_serializable/lib/src/type_helpers/config_types.dart @@ -2,6 +2,7 @@ // 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:analyzer/dart/constant/value.dart'; import 'package:json_annotation/json_annotation.dart'; /// Represents values from [JsonKey] when merged with local configuration. @@ -38,41 +39,20 @@ class KeyConfig { /// configuration. /// /// Values are all known, so types are non-nullable. -class ClassConfig implements JsonSerializable { - @override +class ClassConfig { final bool anyMap; - - @override final bool checked; - - @override final String constructor; - - @override final bool createFactory; - - @override final bool createToJson; - - @override final bool disallowUnrecognizedKeys; - - @override final bool explicitToJson; - - @override final FieldRename fieldRename; - - @override final bool genericArgumentFactories; - - @override final bool ignoreUnannotated; - - @override final bool includeIfNull; - final Map<String, String> ctorParamDefaults; + final List<DartObject> converters; const ClassConfig({ required this.anyMap, @@ -86,9 +66,33 @@ class ClassConfig implements JsonSerializable { required this.genericArgumentFactories, required this.ignoreUnannotated, required this.includeIfNull, + this.converters = const [], this.ctorParamDefaults = const {}, }); + factory ClassConfig.fromJsonSerializable(JsonSerializable config) => + // #CHANGE WHEN UPDATING json_annotation + ClassConfig( + checked: config.checked ?? ClassConfig.defaults.checked, + anyMap: config.anyMap ?? ClassConfig.defaults.anyMap, + constructor: config.constructor ?? ClassConfig.defaults.constructor, + createFactory: + config.createFactory ?? ClassConfig.defaults.createFactory, + createToJson: config.createToJson ?? ClassConfig.defaults.createToJson, + ignoreUnannotated: + config.ignoreUnannotated ?? ClassConfig.defaults.ignoreUnannotated, + explicitToJson: + config.explicitToJson ?? ClassConfig.defaults.explicitToJson, + includeIfNull: + config.includeIfNull ?? ClassConfig.defaults.includeIfNull, + genericArgumentFactories: config.genericArgumentFactories ?? + ClassConfig.defaults.genericArgumentFactories, + fieldRename: config.fieldRename ?? ClassConfig.defaults.fieldRename, + disallowUnrecognizedKeys: config.disallowUnrecognizedKeys ?? + ClassConfig.defaults.disallowUnrecognizedKeys, + // TODO typeConverters = [] + ); + /// An instance of [JsonSerializable] with all fields set to their default /// values. static const defaults = ClassConfig( @@ -105,33 +109,18 @@ class ClassConfig implements JsonSerializable { includeIfNull: true, ); - @override - Map<String, dynamic> toJson() => _$JsonSerializableToJson(this); - - @override - JsonSerializable withDefaults() => this; + JsonSerializable toJsonSerializable() => JsonSerializable( + checked: checked, + anyMap: anyMap, + constructor: constructor, + createFactory: createFactory, + createToJson: createToJson, + ignoreUnannotated: ignoreUnannotated, + explicitToJson: explicitToJson, + includeIfNull: includeIfNull, + genericArgumentFactories: genericArgumentFactories, + fieldRename: fieldRename, + disallowUnrecognizedKeys: disallowUnrecognizedKeys, + // TODO typeConverters = [] + ); } - -const _$FieldRenameEnumMap = { - FieldRename.none: 'none', - FieldRename.kebab: 'kebab', - FieldRename.snake: 'snake', - FieldRename.pascal: 'pascal', - FieldRename.screamingSnake: 'screamingSnake', -}; - -// #CHANGE WHEN UPDATING json_annotation -Map<String, dynamic> _$JsonSerializableToJson(JsonSerializable instance) => - <String, dynamic>{ - 'any_map': instance.anyMap, - 'checked': instance.checked, - 'constructor': instance.constructor, - 'create_factory': instance.createFactory, - 'create_to_json': instance.createToJson, - 'disallow_unrecognized_keys': instance.disallowUnrecognizedKeys, - 'explicit_to_json': instance.explicitToJson, - 'field_rename': _$FieldRenameEnumMap[instance.fieldRename], - 'generic_argument_factories': instance.genericArgumentFactories, - 'ignore_unannotated': instance.ignoreUnannotated, - 'include_if_null': instance.includeIfNull, - }; diff --git a/json_serializable/lib/src/type_helpers/json_converter_helper.dart b/json_serializable/lib/src/type_helpers/json_converter_helper.dart index 10fa483b4..ffe1627f1 100644 --- a/json_serializable/lib/src/type_helpers/json_converter_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_converter_helper.dart @@ -17,14 +17,14 @@ import '../utils.dart'; /// A [TypeHelper] that supports classes annotated with implementations of /// [JsonConverter]. -class JsonConverterHelper extends TypeHelper { +class JsonConverterHelper extends TypeHelper<TypeHelperContextWithConfig> { const JsonConverterHelper(); @override Object? serialize( DartType targetType, String expression, - TypeHelperContext context, + TypeHelperContextWithConfig context, ) { final converter = _typeConverter(targetType, context); @@ -57,7 +57,7 @@ Json? $converterToJsonName<Json, Value>( Object? deserialize( DartType targetType, String expression, - TypeHelperContext context, + TypeHelperContextWithConfig context, bool defaultProvided, ) { final converter = _typeConverter(targetType, context); @@ -143,9 +143,18 @@ class _JsonConvertData { accessor.isEmpty ? '' : '.$accessor'; } -_JsonConvertData? _typeConverter(DartType targetType, TypeHelperContext ctx) { +_JsonConvertData? _typeConverter( + DartType targetType, + TypeHelperContextWithConfig ctx, +) { List<_ConverterMatch> converterMatches(List<ElementAnnotation> items) => items - .map((annotation) => _compatibleMatch(targetType, annotation)) + .map( + (annotation) => _compatibleMatch( + targetType, + annotation, + annotation.computeConstantValue()!, + ), + ) .whereType<_ConverterMatch>() .toList(); @@ -157,6 +166,13 @@ _JsonConvertData? _typeConverter(DartType targetType, TypeHelperContext ctx) { if (matchingAnnotations.isEmpty) { matchingAnnotations = converterMatches(ctx.classElement.metadata); + + if (matchingAnnotations.isEmpty) { + matchingAnnotations = ctx.config.converters + .map((e) => _compatibleMatch(targetType, null, e)) + .whereType<_ConverterMatch>() + .toList(); + } } } @@ -174,13 +190,14 @@ _JsonConvertData? _typeConverterFrom( if (matchingAnnotations.length > 1) { final targetTypeCode = typeToCode(targetType); throw InvalidGenerationSourceError( - 'Found more than one matching converter for `$targetTypeCode`.', - element: matchingAnnotations[1].elementAnnotation.element); + 'Found more than one matching converter for `$targetTypeCode`.', + element: matchingAnnotations[1].elementAnnotation?.element, + ); } final match = matchingAnnotations.single; - final annotationElement = match.elementAnnotation.element; + final annotationElement = match.elementAnnotation?.element; if (annotationElement is PropertyAccessorElement) { final enclosing = annotationElement.enclosingElement; @@ -202,8 +219,9 @@ _JsonConvertData? _typeConverterFrom( if (reviver.namedArguments.isNotEmpty || reviver.positionalArguments.isNotEmpty) { throw InvalidGenerationSourceError( - 'Generators with constructor arguments are not supported.', - element: match.elementAnnotation.element); + 'Generators with constructor arguments are not supported.', + element: match.elementAnnotation?.element, + ); } if (match.genericTypeArg != null) { @@ -228,7 +246,7 @@ class _ConverterMatch { final DartObject annotation; final DartType fieldType; final DartType jsonType; - final ElementAnnotation elementAnnotation; + final ElementAnnotation? elementAnnotation; final String? genericTypeArg; _ConverterMatch( @@ -242,10 +260,9 @@ class _ConverterMatch { _ConverterMatch? _compatibleMatch( DartType targetType, - ElementAnnotation annotation, + ElementAnnotation? annotation, + DartObject constantValue, ) { - final constantValue = annotation.computeConstantValue()!; - final converterClassElement = constantValue.type!.element as ClassElement; final jsonConverterSuper = @@ -274,7 +291,7 @@ _ConverterMatch? _compatibleMatch( } if (fieldType is TypeParameterType && targetType is TypeParameterType) { - assert(annotation.element is! PropertyAccessorElement); + assert(annotation?.element is! PropertyAccessorElement); assert(converterClassElement.typeParameters.isNotEmpty); if (converterClassElement.typeParameters.length > 1) { throw InvalidGenerationSourceError( diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index 8edebaa5a..470627491 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -66,7 +66,7 @@ JsonSerializable _valueForAnnotation(ConstantReader reader) => JsonSerializable( includeIfNull: reader.read('includeIfNull').literalValue as bool?, ); -/// Returns a [JsonSerializable] with values from the [JsonSerializable] +/// Returns a [ClassConfig] with values from the [JsonSerializable] /// instance represented by [reader]. /// /// For fields that are not defined in [JsonSerializable] or `null` in [reader], @@ -93,6 +93,8 @@ ClassConfig mergeConfig( .where((element) => element.hasDefaultValue) .map((e) => MapEntry(e.name, e.defaultValueCode!))); + final converters = reader.read('converters'); + return ClassConfig( anyMap: annotation.anyMap ?? config.anyMap, checked: annotation.checked ?? config.checked, @@ -109,6 +111,7 @@ ClassConfig mergeConfig( ignoreUnannotated: annotation.ignoreUnannotated ?? config.ignoreUnannotated, includeIfNull: annotation.includeIfNull ?? config.includeIfNull, ctorParamDefaults: paramDefaultValueMap, + converters: converters.isNull ? const [] : converters.listValue, ); } diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 00db66b4f..b2b5caa5d 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -16,7 +16,7 @@ dependencies: # Use a tight version constraint to ensure that a constraint on # `json_annotation` properly constrains all features it provides. - json_annotation: '>=4.5.0 <4.6.0' + json_annotation: '>=4.6.0 <4.7.0' meta: ^1.3.0 path: ^1.8.0 pub_semver: ^2.0.0 @@ -36,3 +36,7 @@ dev_dependencies: test_descriptor: ^2.0.0 test_process: ^2.0.0 yaml: ^3.0.0 + +dependency_overrides: + json_annotation: + path: ../json_annotation diff --git a/json_serializable/test/custom_configuration_test.dart b/json_serializable/test/custom_configuration_test.dart index beb592648..649815905 100644 --- a/json_serializable/test/custom_configuration_test.dart +++ b/json_serializable/test/custom_configuration_test.dart @@ -32,7 +32,7 @@ Future<void> main() async { ); group('without wrappers', () { - _registerTests(ClassConfig.defaults); + _registerTests(ClassConfig.defaults.toJsonSerializable()); }); group('configuration', () { @@ -61,8 +61,10 @@ Future<void> main() async { nullConfig ? null : const JsonSerializable(), className); expect(_ConfigLogger.configurations, hasLength(2)); - expect(_ConfigLogger.configurations.first, - same(_ConfigLogger.configurations.last)); + expect( + _ConfigLogger.configurations.first.toJson(), + _ConfigLogger.configurations.last.toJson(), + ); expect(_ConfigLogger.configurations.first.toJson(), generatorConfigDefaultJson); }); @@ -98,8 +100,10 @@ Future<void> main() async { 'ConfigurationExplicitDefaults'); expect(_ConfigLogger.configurations, hasLength(2)); - expect(_ConfigLogger.configurations.first, - same(_ConfigLogger.configurations.last)); + expect( + _ConfigLogger.configurations.first.toJson(), + _ConfigLogger.configurations.last.toJson(), + ); // The effective configuration should be non-Default configuration, but // with all fields set from JsonSerializable as the defaults @@ -225,14 +229,14 @@ class _ConfigLogger implements TypeHelper<TypeHelperContextWithConfig> { TypeHelperContextWithConfig context, bool defaultProvided, ) { - configurations.add(context.config); + configurations.add(context.config.toJsonSerializable()); return null; } @override Object? serialize(DartType targetType, String expression, TypeHelperContextWithConfig context) { - configurations.add(context.config); + configurations.add(context.config.toJsonSerializable()); return null; } } diff --git a/json_serializable/test/kitchen_sink/json_converters.dart b/json_serializable/test/kitchen_sink/json_converters.dart index aefb246d2..4f31a5b4e 100644 --- a/json_serializable/test/kitchen_sink/json_converters.dart +++ b/json_serializable/test/kitchen_sink/json_converters.dart @@ -55,6 +55,25 @@ class DurationMillisecondConverter implements JsonConverter<Duration?, int?> { int? toJson(Duration? object) => object?.inMilliseconds; } +class TrivialString { + TrivialString(this.value); + + final String? value; +} + +const trivialStringConverter = TrivialStringConverter(); + +class TrivialStringConverter implements JsonConverter<TrivialString?, String?> { + const TrivialStringConverter(); + + @override + TrivialString? fromJson(String? json) => + json == null ? null : TrivialString(json); + + @override + String? toJson(TrivialString? object) => object?.value; +} + class EpochDateTimeConverter implements JsonConverter<DateTime?, int?> { const EpochDateTimeConverter(); diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.dart b/json_serializable/test/kitchen_sink/kitchen_sink.dart index 4eabab0e2..e194dbfbc 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.dart @@ -71,6 +71,7 @@ class _Factory implements k.KitchenSinkFactory<String, dynamic> { TrivialNumber(0), {}, DateTime.fromMillisecondsSinceEpoch(0), + TrivialString(''), TrivialNumber(0), {}, ); @@ -194,11 +195,14 @@ class KitchenSink implements k.KitchenSink { } } -@JsonSerializable() +@JsonSerializable(converters: [ + // referencing a top-level field should work + durationConverter, + // referencing via a const constructor should work + BigIntStringConverter(), +]) // referencing a top-level field should work -@durationConverter -// referencing via a const constructor should work -@BigIntStringConverter() +@trivialStringConverter @TrivialNumberConverter.instance @EpochDateTimeConverter() class JsonConverterTestClass implements k.JsonConverterTestClass { @@ -212,6 +216,7 @@ class JsonConverterTestClass implements k.JsonConverterTestClass { this.numberSilly, this.numberSillySet, this.dateTime, + this.trivialString, this.nullableNumberSilly, this.nullableNumberSillySet, ); @@ -235,6 +240,8 @@ class JsonConverterTestClass implements k.JsonConverterTestClass { DateTime? dateTime; + TrivialString? trivialString; + TrivialNumber? nullableNumberSilly; Set<TrivialNumber?> nullableNumberSillySet; } diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g.dart index c74f6aee0..c795c6c13 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g.dart @@ -137,9 +137,9 @@ Map<String, dynamic> _$KitchenSinkToJson(KitchenSink instance) => JsonConverterTestClass _$JsonConverterTestClassFromJson( Map<String, dynamic> json) => JsonConverterTestClass( - durationConverter.fromJson(json['duration'] as int?), + const DurationMillisecondConverter().fromJson(json['duration'] as int?), (json['durationList'] as List<dynamic>) - .map((e) => durationConverter.fromJson(e as int?)) + .map((e) => const DurationMillisecondConverter().fromJson(e as int?)) .toList(), const BigIntStringConverter().fromJson(json['bigInt'] as String), (json['bigIntMap'] as Map<String, dynamic>).map( @@ -159,6 +159,7 @@ JsonConverterTestClass _$JsonConverterTestClassFromJson( .map((e) => TrivialNumberConverter.instance.fromJson(e as int?)) .toSet(), const EpochDateTimeConverter().fromJson(json['dateTime'] as int?), + trivialStringConverter.fromJson(json['trivialString'] as String?), TrivialNumberConverter.instance .fromJson(json['nullableNumberSilly'] as int?), (json['nullableNumberSillySet'] as List<dynamic>) @@ -169,9 +170,11 @@ JsonConverterTestClass _$JsonConverterTestClassFromJson( Map<String, dynamic> _$JsonConverterTestClassToJson( JsonConverterTestClass instance) => <String, dynamic>{ - 'duration': durationConverter.toJson(instance.duration), - 'durationList': - instance.durationList.map(durationConverter.toJson).toList(), + 'duration': + const DurationMillisecondConverter().toJson(instance.duration), + 'durationList': instance.durationList + .map(const DurationMillisecondConverter().toJson) + .toList(), 'bigInt': const BigIntStringConverter().toJson(instance.bigInt), 'bigIntMap': instance.bigIntMap .map((k, e) => MapEntry(k, const BigIntStringConverter().toJson(e))), @@ -187,6 +190,7 @@ Map<String, dynamic> _$JsonConverterTestClassToJson( .map(TrivialNumberConverter.instance.toJson) .toList(), 'dateTime': const EpochDateTimeConverter().toJson(instance.dateTime), + 'trivialString': trivialStringConverter.toJson(instance.trivialString), 'nullableNumberSilly': _$JsonConverterToJson<int?, TrivialNumber>( instance.nullableNumberSilly, TrivialNumberConverter.instance.toJson), 'nullableNumberSillySet': instance.nullableNumberSillySet diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart index 9da91757a..cd0abae63 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart @@ -70,6 +70,7 @@ class _Factory implements k.KitchenSinkFactory<dynamic, dynamic> { TrivialNumber(0), {}, DateTime.fromMillisecondsSinceEpoch(0), + TrivialString(''), TrivialNumber(0), {}, ); @@ -194,13 +195,14 @@ class KitchenSink implements k.KitchenSink { } } -@JsonSerializable( - anyMap: true, -) +@JsonSerializable(anyMap: true, converters: [ + // referencing a top-level field should work + durationConverter, + // referencing via a const constructor should work + BigIntStringConverter(), +]) // referencing a top-level field should work -@durationConverter -// referencing via a const constructor should work -@BigIntStringConverter() +@trivialStringConverter @TrivialNumberConverter.instance @EpochDateTimeConverter() class JsonConverterTestClass implements k.JsonConverterTestClass { @@ -214,6 +216,7 @@ class JsonConverterTestClass implements k.JsonConverterTestClass { this.numberSilly, this.numberSillySet, this.dateTime, + this.trivialString, this.nullableNumberSilly, this.nullableNumberSillySet, ); @@ -237,6 +240,8 @@ class JsonConverterTestClass implements k.JsonConverterTestClass { DateTime? dateTime; + TrivialString? trivialString; + TrivialNumber? nullableNumberSilly; Set<TrivialNumber?> nullableNumberSillySet; } diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart index 638091dcc..ce7520a1e 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart @@ -128,9 +128,9 @@ Map<String, dynamic> _$KitchenSinkToJson(KitchenSink instance) => JsonConverterTestClass _$JsonConverterTestClassFromJson(Map json) => JsonConverterTestClass( - durationConverter.fromJson(json['duration'] as int?), + const DurationMillisecondConverter().fromJson(json['duration'] as int?), (json['durationList'] as List<dynamic>) - .map((e) => durationConverter.fromJson(e as int?)) + .map((e) => const DurationMillisecondConverter().fromJson(e as int?)) .toList(), const BigIntStringConverter().fromJson(json['bigInt'] as String), (json['bigIntMap'] as Map).map( @@ -150,6 +150,7 @@ JsonConverterTestClass _$JsonConverterTestClassFromJson(Map json) => .map((e) => TrivialNumberConverter.instance.fromJson(e as int?)) .toSet(), const EpochDateTimeConverter().fromJson(json['dateTime'] as int?), + trivialStringConverter.fromJson(json['trivialString'] as String?), TrivialNumberConverter.instance .fromJson(json['nullableNumberSilly'] as int?), (json['nullableNumberSillySet'] as List<dynamic>) @@ -160,9 +161,11 @@ JsonConverterTestClass _$JsonConverterTestClassFromJson(Map json) => Map<String, dynamic> _$JsonConverterTestClassToJson( JsonConverterTestClass instance) => <String, dynamic>{ - 'duration': durationConverter.toJson(instance.duration), - 'durationList': - instance.durationList.map(durationConverter.toJson).toList(), + 'duration': + const DurationMillisecondConverter().toJson(instance.duration), + 'durationList': instance.durationList + .map(const DurationMillisecondConverter().toJson) + .toList(), 'bigInt': const BigIntStringConverter().toJson(instance.bigInt), 'bigIntMap': instance.bigIntMap .map((k, e) => MapEntry(k, const BigIntStringConverter().toJson(e))), @@ -178,6 +181,7 @@ Map<String, dynamic> _$JsonConverterTestClassToJson( .map(TrivialNumberConverter.instance.toJson) .toList(), 'dateTime': const EpochDateTimeConverter().toJson(instance.dateTime), + 'trivialString': trivialStringConverter.toJson(instance.trivialString), 'nullableNumberSilly': _$JsonConverterToJson<int?, TrivialNumber>( instance.nullableNumberSilly, TrivialNumberConverter.instance.toJson), 'nullableNumberSillySet': instance.nullableNumberSillySet diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.dart index 71812ba2e..b01ef3341 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.dart @@ -70,6 +70,7 @@ class _Factory implements k.KitchenSinkFactory<dynamic, dynamic> { TrivialNumber(0), {}, DateTime.fromMillisecondsSinceEpoch(0), + TrivialString(''), TrivialNumber(0), {}, ); @@ -195,14 +196,14 @@ class KitchenSink implements k.KitchenSink { } } -@JsonSerializable( - checked: true, - anyMap: true, -) +@JsonSerializable(checked: true, anyMap: true, converters: [ + // referencing a top-level field should work + durationConverter, + // referencing via a const constructor should work + BigIntStringConverter(), +]) // referencing a top-level field should work -@durationConverter -// referencing via a const constructor should work -@BigIntStringConverter() +@trivialStringConverter @TrivialNumberConverter.instance @EpochDateTimeConverter() class JsonConverterTestClass implements k.JsonConverterTestClass { @@ -216,6 +217,7 @@ class JsonConverterTestClass implements k.JsonConverterTestClass { this.numberSilly, this.numberSillySet, this.dateTime, + this.trivialString, this.nullableNumberSilly, this.nullableNumberSillySet, ); @@ -239,6 +241,8 @@ class JsonConverterTestClass implements k.JsonConverterTestClass { DateTime? dateTime; + TrivialString? trivialString; + TrivialNumber? nullableNumberSilly; Set<TrivialNumber?> nullableNumberSillySet; } diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.g.dart index 1d8c4c26b..a9e48d1a6 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.g.dart @@ -183,12 +183,13 @@ JsonConverterTestClass _$JsonConverterTestClassFromJson(Map json) => json, ($checkedConvert) { final val = JsonConverterTestClass( - $checkedConvert( - 'duration', (v) => durationConverter.fromJson(v as int?)), + $checkedConvert('duration', + (v) => const DurationMillisecondConverter().fromJson(v as int?)), $checkedConvert( 'durationList', (v) => (v as List<dynamic>) - .map((e) => durationConverter.fromJson(e as int?)) + .map((e) => + const DurationMillisecondConverter().fromJson(e as int?)) .toList()), $checkedConvert('bigInt', (v) => const BigIntStringConverter().fromJson(v as String)), @@ -220,6 +221,8 @@ JsonConverterTestClass _$JsonConverterTestClassFromJson(Map json) => .toSet()), $checkedConvert('dateTime', (v) => const EpochDateTimeConverter().fromJson(v as int?)), + $checkedConvert('trivialString', + (v) => trivialStringConverter.fromJson(v as String?)), $checkedConvert('nullableNumberSilly', (v) => TrivialNumberConverter.instance.fromJson(v as int?)), $checkedConvert( @@ -236,9 +239,11 @@ JsonConverterTestClass _$JsonConverterTestClassFromJson(Map json) => Map<String, dynamic> _$JsonConverterTestClassToJson( JsonConverterTestClass instance) => <String, dynamic>{ - 'duration': durationConverter.toJson(instance.duration), - 'durationList': - instance.durationList.map(durationConverter.toJson).toList(), + 'duration': + const DurationMillisecondConverter().toJson(instance.duration), + 'durationList': instance.durationList + .map(const DurationMillisecondConverter().toJson) + .toList(), 'bigInt': const BigIntStringConverter().toJson(instance.bigInt), 'bigIntMap': instance.bigIntMap .map((k, e) => MapEntry(k, const BigIntStringConverter().toJson(e))), @@ -254,6 +259,7 @@ Map<String, dynamic> _$JsonConverterTestClassToJson( .map(TrivialNumberConverter.instance.toJson) .toList(), 'dateTime': const EpochDateTimeConverter().toJson(instance.dateTime), + 'trivialString': trivialStringConverter.toJson(instance.trivialString), 'nullableNumberSilly': _$JsonConverterToJson<int?, TrivialNumber>( instance.nullableNumberSilly, TrivialNumberConverter.instance.toJson), 'nullableNumberSillySet': instance.nullableNumberSillySet diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.dart index a8fd5e1d8..46b2ea3b7 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.dart @@ -71,6 +71,7 @@ class _Factory implements k.KitchenSinkFactory<String, dynamic> { TrivialNumber(0), {}, DateTime.fromMillisecondsSinceEpoch(0), + TrivialString(''), TrivialNumber(0), {}, ); @@ -196,13 +197,14 @@ class KitchenSink implements k.KitchenSink { } } -@JsonSerializable( - includeIfNull: false, -) +@JsonSerializable(includeIfNull: false, converters: [ + // referencing a top-level field should work + durationConverter, + // referencing via a const constructor should work + BigIntStringConverter(), +]) // referencing a top-level field should work -@durationConverter -// referencing via a const constructor should work -@BigIntStringConverter() +@trivialStringConverter @TrivialNumberConverter.instance @EpochDateTimeConverter() class JsonConverterTestClass implements k.JsonConverterTestClass { @@ -216,6 +218,7 @@ class JsonConverterTestClass implements k.JsonConverterTestClass { this.numberSilly, this.numberSillySet, this.dateTime, + this.trivialString, this.nullableNumberSilly, this.nullableNumberSillySet, ); @@ -239,6 +242,8 @@ class JsonConverterTestClass implements k.JsonConverterTestClass { DateTime? dateTime; + TrivialString? trivialString; + TrivialNumber? nullableNumberSilly; Set<TrivialNumber?> nullableNumberSillySet; } diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart index a0246e8bc..017e40a6a 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart @@ -145,9 +145,9 @@ Map<String, dynamic> _$KitchenSinkToJson(KitchenSink instance) { JsonConverterTestClass _$JsonConverterTestClassFromJson( Map<String, dynamic> json) => JsonConverterTestClass( - durationConverter.fromJson(json['duration'] as int?), + const DurationMillisecondConverter().fromJson(json['duration'] as int?), (json['durationList'] as List<dynamic>) - .map((e) => durationConverter.fromJson(e as int?)) + .map((e) => const DurationMillisecondConverter().fromJson(e as int?)) .toList(), const BigIntStringConverter().fromJson(json['bigInt'] as String), (json['bigIntMap'] as Map<String, dynamic>).map( @@ -167,6 +167,7 @@ JsonConverterTestClass _$JsonConverterTestClassFromJson( .map((e) => TrivialNumberConverter.instance.fromJson(e as int?)) .toSet(), const EpochDateTimeConverter().fromJson(json['dateTime'] as int?), + trivialStringConverter.fromJson(json['trivialString'] as String?), TrivialNumberConverter.instance .fromJson(json['nullableNumberSilly'] as int?), (json['nullableNumberSillySet'] as List<dynamic>) @@ -184,9 +185,11 @@ Map<String, dynamic> _$JsonConverterTestClassToJson( } } - writeNotNull('duration', durationConverter.toJson(instance.duration)); - val['durationList'] = - instance.durationList.map(durationConverter.toJson).toList(); + writeNotNull('duration', + const DurationMillisecondConverter().toJson(instance.duration)); + val['durationList'] = instance.durationList + .map(const DurationMillisecondConverter().toJson) + .toList(); writeNotNull('bigInt', const BigIntStringConverter().toJson(instance.bigInt)); val['bigIntMap'] = instance.bigIntMap .map((k, e) => MapEntry(k, const BigIntStringConverter().toJson(e))); @@ -205,6 +208,8 @@ Map<String, dynamic> _$JsonConverterTestClassToJson( .toList(); writeNotNull( 'dateTime', const EpochDateTimeConverter().toJson(instance.dateTime)); + writeNotNull( + 'trivialString', trivialStringConverter.toJson(instance.trivialString)); writeNotNull( 'nullableNumberSilly', _$JsonConverterToJson<int?, TrivialNumber>(instance.nullableNumberSilly, diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.dart index f5f13fc7d..02bd2a683 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.dart @@ -71,6 +71,7 @@ class _Factory implements k.KitchenSinkFactory<String, dynamic> { TrivialNumber(0), {}, DateTime.fromMillisecondsSinceEpoch(0), + TrivialString(''), TrivialNumber(0), {}, ); @@ -196,13 +197,14 @@ class KitchenSink implements k.KitchenSink { } } -@JsonSerializable( - explicitToJson: true, -) +@JsonSerializable(explicitToJson: true, converters: [ + // referencing a top-level field should work + durationConverter, + // referencing via a const constructor should work + BigIntStringConverter(), +]) // referencing a top-level field should work -@durationConverter -// referencing via a const constructor should work -@BigIntStringConverter() +@trivialStringConverter @TrivialNumberConverter.instance @EpochDateTimeConverter() class JsonConverterTestClass implements k.JsonConverterTestClass { @@ -216,6 +218,7 @@ class JsonConverterTestClass implements k.JsonConverterTestClass { this.numberSilly, this.numberSillySet, this.dateTime, + this.trivialString, this.nullableNumberSilly, this.nullableNumberSillySet, ); @@ -239,6 +242,8 @@ class JsonConverterTestClass implements k.JsonConverterTestClass { DateTime? dateTime; + TrivialString? trivialString; + TrivialNumber? nullableNumberSilly; Set<TrivialNumber?> nullableNumberSillySet; } diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart index e6f218fa6..a38b42bf0 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart @@ -139,9 +139,9 @@ Map<String, dynamic> _$KitchenSinkToJson(KitchenSink instance) => JsonConverterTestClass _$JsonConverterTestClassFromJson( Map<String, dynamic> json) => JsonConverterTestClass( - durationConverter.fromJson(json['duration'] as int?), + const DurationMillisecondConverter().fromJson(json['duration'] as int?), (json['durationList'] as List<dynamic>) - .map((e) => durationConverter.fromJson(e as int?)) + .map((e) => const DurationMillisecondConverter().fromJson(e as int?)) .toList(), const BigIntStringConverter().fromJson(json['bigInt'] as String), (json['bigIntMap'] as Map<String, dynamic>).map( @@ -161,6 +161,7 @@ JsonConverterTestClass _$JsonConverterTestClassFromJson( .map((e) => TrivialNumberConverter.instance.fromJson(e as int?)) .toSet(), const EpochDateTimeConverter().fromJson(json['dateTime'] as int?), + trivialStringConverter.fromJson(json['trivialString'] as String?), TrivialNumberConverter.instance .fromJson(json['nullableNumberSilly'] as int?), (json['nullableNumberSillySet'] as List<dynamic>) @@ -171,9 +172,11 @@ JsonConverterTestClass _$JsonConverterTestClassFromJson( Map<String, dynamic> _$JsonConverterTestClassToJson( JsonConverterTestClass instance) => <String, dynamic>{ - 'duration': durationConverter.toJson(instance.duration), - 'durationList': - instance.durationList.map(durationConverter.toJson).toList(), + 'duration': + const DurationMillisecondConverter().toJson(instance.duration), + 'durationList': instance.durationList + .map(const DurationMillisecondConverter().toJson) + .toList(), 'bigInt': const BigIntStringConverter().toJson(instance.bigInt), 'bigIntMap': instance.bigIntMap .map((k, e) => MapEntry(k, const BigIntStringConverter().toJson(e))), @@ -189,6 +192,7 @@ Map<String, dynamic> _$JsonConverterTestClassToJson( .map(TrivialNumberConverter.instance.toJson) .toList(), 'dateTime': const EpochDateTimeConverter().toJson(instance.dateTime), + 'trivialString': trivialStringConverter.toJson(instance.trivialString), 'nullableNumberSilly': _$JsonConverterToJson<int?, TrivialNumber>( instance.nullableNumberSilly, TrivialNumberConverter.instance.toJson), 'nullableNumberSillySet': instance.nullableNumberSillySet diff --git a/json_serializable/test/kitchen_sink/kitchen_sink_test.dart b/json_serializable/test/kitchen_sink/kitchen_sink_test.dart index 99e45bf40..67e68400a 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink_test.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink_test.dart @@ -59,6 +59,7 @@ const _jsonConverterValidValues = { 'numberSilly': 5, 'numberSillySet': [5], 'dateTime': 5, + 'trivialString': '', 'nullableNumberSilly': 5, 'nullableBigInt': '42', 'nullableBigIntMap': {'value': '42'}, @@ -106,6 +107,7 @@ void _nullableTests(KitchenSinkFactory factory) { 'numberSilly': 0, 'numberSillySet': [], 'dateTime': 0, + 'trivialString': '', 'nullableNumberSilly': 0, 'nullableNumberSillySet': [], }); diff --git a/json_serializable/test/shared_config.dart b/json_serializable/test/shared_config.dart index 09311ad10..8ee8ca585 100644 --- a/json_serializable/test/shared_config.dart +++ b/json_serializable/test/shared_config.dart @@ -7,8 +7,9 @@ import 'package:json_serializable/src/type_helpers/config_types.dart'; final jsonSerializableFields = generatorConfigDefaultJson.keys.toList(); -final generatorConfigDefaultJson = - Map<String, dynamic>.unmodifiable(ClassConfig.defaults.toJson()); +final generatorConfigDefaultJson = Map<String, dynamic>.unmodifiable( + ClassConfig.defaults.toJsonSerializable().toJson(), +); // #CHANGE WHEN UPDATING json_annotation final generatorConfigNonDefaultJson = From dee0e5a7889aa0331cf1952b95e5f59ef391f0f5 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Sat, 18 Jun 2022 17:34:32 -0700 Subject: [PATCH 421/569] Fix test annotations (#1160) --- json_serializable/test/supported_types/extra_map_test.dart | 2 +- .../test/supported_types/type_test.bigint_test.dart | 2 +- json_serializable/test/supported_types/type_test.bool_test.dart | 2 +- json_serializable/test/supported_types/type_test.dart | 2 +- .../test/supported_types/type_test.datetime_test.dart | 2 +- .../test/supported_types/type_test.double_test.dart | 2 +- .../test/supported_types/type_test.duration_test.dart | 2 +- .../test/supported_types/type_test.enumtype_test.dart | 2 +- json_serializable/test/supported_types/type_test.int_test.dart | 2 +- .../test/supported_types/type_test.iterable_test.dart | 2 +- json_serializable/test/supported_types/type_test.list_test.dart | 2 +- json_serializable/test/supported_types/type_test.map_test.dart | 2 +- json_serializable/test/supported_types/type_test.num_test.dart | 2 +- .../test/supported_types/type_test.object_test.dart | 2 +- json_serializable/test/supported_types/type_test.set_test.dart | 2 +- .../test/supported_types/type_test.string_test.dart | 2 +- json_serializable/test/supported_types/type_test.uri_test.dart | 2 +- 17 files changed, 17 insertions(+), 17 deletions(-) diff --git a/json_serializable/test/supported_types/extra_map_test.dart b/json_serializable/test/supported_types/extra_map_test.dart index 78a1af821..0bdea277c 100644 --- a/json_serializable/test/supported_types/extra_map_test.dart +++ b/json_serializable/test/supported_types/extra_map_test.dart @@ -3,10 +3,10 @@ // BSD-style license that can be found in the LICENSE file. // ignore_for_file: prefer_const_declarations +@TestOn('vm') import 'dart:convert'; -@TestOn('vm') import 'package:test/test.dart'; import '../test_utils.dart'; diff --git a/json_serializable/test/supported_types/type_test.bigint_test.dart b/json_serializable/test/supported_types/type_test.bigint_test.dart index c012ea507..aa35a7d68 100644 --- a/json_serializable/test/supported_types/type_test.bigint_test.dart +++ b/json_serializable/test/supported_types/type_test.bigint_test.dart @@ -3,10 +3,10 @@ // BSD-style license that can be found in the LICENSE file. // ignore_for_file: prefer_const_declarations +@TestOn('vm') import 'dart:convert'; -@TestOn('vm') import 'package:test/test.dart'; import '../test_utils.dart'; diff --git a/json_serializable/test/supported_types/type_test.bool_test.dart b/json_serializable/test/supported_types/type_test.bool_test.dart index 14e24853b..1d66ca8ce 100644 --- a/json_serializable/test/supported_types/type_test.bool_test.dart +++ b/json_serializable/test/supported_types/type_test.bool_test.dart @@ -3,10 +3,10 @@ // BSD-style license that can be found in the LICENSE file. // ignore_for_file: prefer_const_declarations +@TestOn('vm') import 'dart:convert'; -@TestOn('vm') import 'package:test/test.dart'; import '../test_utils.dart'; diff --git a/json_serializable/test/supported_types/type_test.dart b/json_serializable/test/supported_types/type_test.dart index 625b8e3c4..1a94d75ed 100644 --- a/json_serializable/test/supported_types/type_test.dart +++ b/json_serializable/test/supported_types/type_test.dart @@ -3,10 +3,10 @@ // BSD-style license that can be found in the LICENSE file. // ignore_for_file: prefer_const_declarations +@TestOn('vm') import 'dart:convert'; -@TestOn('vm') import 'package:test/test.dart'; import '../test_utils.dart'; diff --git a/json_serializable/test/supported_types/type_test.datetime_test.dart b/json_serializable/test/supported_types/type_test.datetime_test.dart index 597bbf680..2be225554 100644 --- a/json_serializable/test/supported_types/type_test.datetime_test.dart +++ b/json_serializable/test/supported_types/type_test.datetime_test.dart @@ -3,10 +3,10 @@ // BSD-style license that can be found in the LICENSE file. // ignore_for_file: prefer_const_declarations +@TestOn('vm') import 'dart:convert'; -@TestOn('vm') import 'package:test/test.dart'; import '../test_utils.dart'; diff --git a/json_serializable/test/supported_types/type_test.double_test.dart b/json_serializable/test/supported_types/type_test.double_test.dart index 3e4c05acf..c9db8891a 100644 --- a/json_serializable/test/supported_types/type_test.double_test.dart +++ b/json_serializable/test/supported_types/type_test.double_test.dart @@ -3,10 +3,10 @@ // BSD-style license that can be found in the LICENSE file. // ignore_for_file: prefer_const_declarations +@TestOn('vm') import 'dart:convert'; -@TestOn('vm') import 'package:test/test.dart'; import '../test_utils.dart'; diff --git a/json_serializable/test/supported_types/type_test.duration_test.dart b/json_serializable/test/supported_types/type_test.duration_test.dart index 76816e9fc..c19af16cd 100644 --- a/json_serializable/test/supported_types/type_test.duration_test.dart +++ b/json_serializable/test/supported_types/type_test.duration_test.dart @@ -3,10 +3,10 @@ // BSD-style license that can be found in the LICENSE file. // ignore_for_file: prefer_const_declarations +@TestOn('vm') import 'dart:convert'; -@TestOn('vm') import 'package:test/test.dart'; import '../test_utils.dart'; diff --git a/json_serializable/test/supported_types/type_test.enumtype_test.dart b/json_serializable/test/supported_types/type_test.enumtype_test.dart index 1652b359b..568ddb615 100644 --- a/json_serializable/test/supported_types/type_test.enumtype_test.dart +++ b/json_serializable/test/supported_types/type_test.enumtype_test.dart @@ -3,10 +3,10 @@ // BSD-style license that can be found in the LICENSE file. // ignore_for_file: prefer_const_declarations +@TestOn('vm') import 'dart:convert'; -@TestOn('vm') import 'package:test/test.dart'; import '../test_utils.dart'; diff --git a/json_serializable/test/supported_types/type_test.int_test.dart b/json_serializable/test/supported_types/type_test.int_test.dart index b4252fa5f..9f5a81b1f 100644 --- a/json_serializable/test/supported_types/type_test.int_test.dart +++ b/json_serializable/test/supported_types/type_test.int_test.dart @@ -3,10 +3,10 @@ // BSD-style license that can be found in the LICENSE file. // ignore_for_file: prefer_const_declarations +@TestOn('vm') import 'dart:convert'; -@TestOn('vm') import 'package:test/test.dart'; import '../test_utils.dart'; diff --git a/json_serializable/test/supported_types/type_test.iterable_test.dart b/json_serializable/test/supported_types/type_test.iterable_test.dart index 57b9358b0..658ed97e1 100644 --- a/json_serializable/test/supported_types/type_test.iterable_test.dart +++ b/json_serializable/test/supported_types/type_test.iterable_test.dart @@ -3,10 +3,10 @@ // BSD-style license that can be found in the LICENSE file. // ignore_for_file: prefer_const_declarations +@TestOn('vm') import 'dart:convert'; -@TestOn('vm') import 'package:test/test.dart'; import '../test_utils.dart'; diff --git a/json_serializable/test/supported_types/type_test.list_test.dart b/json_serializable/test/supported_types/type_test.list_test.dart index 342a89079..adbd2ed4a 100644 --- a/json_serializable/test/supported_types/type_test.list_test.dart +++ b/json_serializable/test/supported_types/type_test.list_test.dart @@ -3,10 +3,10 @@ // BSD-style license that can be found in the LICENSE file. // ignore_for_file: prefer_const_declarations +@TestOn('vm') import 'dart:convert'; -@TestOn('vm') import 'package:test/test.dart'; import '../test_utils.dart'; diff --git a/json_serializable/test/supported_types/type_test.map_test.dart b/json_serializable/test/supported_types/type_test.map_test.dart index c8cf4ccb9..e814f7bd2 100644 --- a/json_serializable/test/supported_types/type_test.map_test.dart +++ b/json_serializable/test/supported_types/type_test.map_test.dart @@ -3,10 +3,10 @@ // BSD-style license that can be found in the LICENSE file. // ignore_for_file: prefer_const_declarations +@TestOn('vm') import 'dart:convert'; -@TestOn('vm') import 'package:test/test.dart'; import '../test_utils.dart'; diff --git a/json_serializable/test/supported_types/type_test.num_test.dart b/json_serializable/test/supported_types/type_test.num_test.dart index 52241e719..1ebf28dbe 100644 --- a/json_serializable/test/supported_types/type_test.num_test.dart +++ b/json_serializable/test/supported_types/type_test.num_test.dart @@ -3,10 +3,10 @@ // BSD-style license that can be found in the LICENSE file. // ignore_for_file: prefer_const_declarations +@TestOn('vm') import 'dart:convert'; -@TestOn('vm') import 'package:test/test.dart'; import '../test_utils.dart'; diff --git a/json_serializable/test/supported_types/type_test.object_test.dart b/json_serializable/test/supported_types/type_test.object_test.dart index a4f9601f6..7f8e7f4b6 100644 --- a/json_serializable/test/supported_types/type_test.object_test.dart +++ b/json_serializable/test/supported_types/type_test.object_test.dart @@ -3,10 +3,10 @@ // BSD-style license that can be found in the LICENSE file. // ignore_for_file: prefer_const_declarations +@TestOn('vm') import 'dart:convert'; -@TestOn('vm') import 'package:test/test.dart'; import '../test_utils.dart'; diff --git a/json_serializable/test/supported_types/type_test.set_test.dart b/json_serializable/test/supported_types/type_test.set_test.dart index a3b1ed57b..1a0c0133d 100644 --- a/json_serializable/test/supported_types/type_test.set_test.dart +++ b/json_serializable/test/supported_types/type_test.set_test.dart @@ -3,10 +3,10 @@ // BSD-style license that can be found in the LICENSE file. // ignore_for_file: prefer_const_declarations +@TestOn('vm') import 'dart:convert'; -@TestOn('vm') import 'package:test/test.dart'; import '../test_utils.dart'; diff --git a/json_serializable/test/supported_types/type_test.string_test.dart b/json_serializable/test/supported_types/type_test.string_test.dart index 845762b19..c239eab85 100644 --- a/json_serializable/test/supported_types/type_test.string_test.dart +++ b/json_serializable/test/supported_types/type_test.string_test.dart @@ -3,10 +3,10 @@ // BSD-style license that can be found in the LICENSE file. // ignore_for_file: prefer_const_declarations +@TestOn('vm') import 'dart:convert'; -@TestOn('vm') import 'package:test/test.dart'; import '../test_utils.dart'; diff --git a/json_serializable/test/supported_types/type_test.uri_test.dart b/json_serializable/test/supported_types/type_test.uri_test.dart index ff0710b38..28903704b 100644 --- a/json_serializable/test/supported_types/type_test.uri_test.dart +++ b/json_serializable/test/supported_types/type_test.uri_test.dart @@ -3,10 +3,10 @@ // BSD-style license that can be found in the LICENSE file. // ignore_for_file: prefer_const_declarations +@TestOn('vm') import 'dart:convert'; -@TestOn('vm') import 'package:test/test.dart'; import '../test_utils.dart'; From 49828483bc861e46adee15c1fb152c9774c13ac2 Mon Sep 17 00:00:00 2001 From: Erlang Parasu <erlangparasu@gmail.com> Date: Sat, 25 Jun 2022 10:45:12 +0800 Subject: [PATCH 422/569] Update README.md (#1161) --- example/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/README.md b/example/README.md index 3be08ba78..a0fe48ac6 100644 --- a/example/README.md +++ b/example/README.md @@ -33,7 +33,7 @@ Run `pub run build_runner build` to generate files into your source directory. ``` _NOTE_: If you're using Flutter, replace `pub run` with -`flutter packages pub run`. +`flutter pub run`. [example]: lib/example.dart [example_g]: lib/example.g.dart From 0f383e71e4600d80d6da5d78c14f2e43c91bf6cb Mon Sep 17 00:00:00 2001 From: Matthew Shipton <ssabdb@users.noreply.github.com> Date: Sat, 25 Jun 2022 03:46:18 +0100 Subject: [PATCH 423/569] =?UTF-8?q?Serializing=20enums=20explicitly=20refe?= =?UTF-8?q?rences=20types=20unless=20nullable=20(issue=20=E2=80=A6=20(#114?= =?UTF-8?q?6)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this change, serializing non-nullable enums in a subtype was incorrectly producing nullable string types. For example, serializing a class member of type Map<enum, String> produced a type Map<String?, dynamic> where Map<String, dynamic> should have been produced. Nullable enums should still produce nullable types, eg. serializing List<enum?> should produce List<String?> fixes #1145 --- _test_yaml/test/src/build_config.g.dart | 2 +- json_serializable/CHANGELOG.md | 2 + .../lib/src/type_helpers/enum_helper.dart | 6 +- .../test/default_value/default_value.g.dart | 2 +- .../default_value.g_any_map__checked.g.dart | 2 +- .../implicit_default_value.g.dart | 2 +- .../test/integration/integration_test.dart | 17 +++ .../test/integration/json_enum_example.dart | 32 ++++ .../test/integration/json_enum_example.g.dart | 21 +++ .../test/integration/json_test_example.g.dart | 6 +- .../json_test_example.g_any_map.g.dart | 6 +- .../input.type_enumtype.g.dart | 4 +- .../input.type_iterable.g.dart | 4 +- .../supported_types/input.type_list.g.dart | 4 +- .../supported_types/input.type_map.g.dart | 144 ++++++++++-------- .../supported_types/input.type_set.g.dart | 4 +- 16 files changed, 175 insertions(+), 83 deletions(-) diff --git a/_test_yaml/test/src/build_config.g.dart b/_test_yaml/test/src/build_config.g.dart index 72cbe0034..332000dd1 100644 --- a/_test_yaml/test/src/build_config.g.dart +++ b/_test_yaml/test/src/build_config.g.dart @@ -34,7 +34,7 @@ Config _$ConfigFromJson(Map json) => $checkedCreate( Map<String, dynamic> _$ConfigToJson(Config instance) => <String, dynamic>{ 'builders': instance.builders, 'weights': - instance.weights?.map((k, e) => MapEntry(_$AutoApplyEnumMap[k], e)), + instance.weights?.map((k, e) => MapEntry(_$AutoApplyEnumMap[k]!, e)), }; const _$AutoApplyEnumMap = { diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index ba3e21bc9..32ef550ed 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -4,6 +4,8 @@ of type `MyClass?`. ([#822](https://github.com/google/json_serializable.dart/issues/822)) - Added support for `JsonSerializable(converters: <JsonConverter>[])` ([#1072](https://github.com/google/json_serializable.dart/issues/1072)) +- Fix issue with serialization of non-nullable enumerations emitting a nullable + type ([#1146](https://github.com/google/json_serializable.dart/pull/1146)) ## 6.2.0 diff --git a/json_serializable/lib/src/type_helpers/enum_helper.dart b/json_serializable/lib/src/type_helpers/enum_helper.dart index 40fb6997c..2d8e91765 100644 --- a/json_serializable/lib/src/type_helpers/enum_helper.dart +++ b/json_serializable/lib/src/type_helpers/enum_helper.dart @@ -29,7 +29,11 @@ class EnumHelper extends TypeHelper<TypeHelperContextWithConfig> { context.addMember(memberContent); - return '${constMapName(targetType)}[$expression]'; + if (targetType.isNullableType) { + return '${constMapName(targetType)}[$expression]'; + } else { + return '${constMapName(targetType)}[$expression]!'; + } } @override diff --git a/json_serializable/test/default_value/default_value.g.dart b/json_serializable/test/default_value/default_value.g.dart index a923dc624..36088a33f 100644 --- a/json_serializable/test/default_value/default_value.g.dart +++ b/json_serializable/test/default_value/default_value.g.dart @@ -61,7 +61,7 @@ Map<String, dynamic> _$DefaultValueToJson(DefaultValue instance) => 'fieldSetSimple': instance.fieldSetSimple.toList(), 'fieldMapSimple': instance.fieldMapSimple, 'fieldMapListString': instance.fieldMapListString, - 'fieldEnum': _$GreekEnumMap[instance.fieldEnum], + 'fieldEnum': _$GreekEnumMap[instance.fieldEnum]!, 'constClass': instance.constClass, 'valueFromConverter': const ConstClassConverter().toJson(instance.valueFromConverter), diff --git a/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart b/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart index 0004ac0bc..f2ab42ae8 100644 --- a/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart +++ b/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart @@ -84,7 +84,7 @@ Map<String, dynamic> _$DefaultValueToJson(DefaultValue instance) => 'fieldSetSimple': instance.fieldSetSimple.toList(), 'fieldMapSimple': instance.fieldMapSimple, 'fieldMapListString': instance.fieldMapListString, - 'fieldEnum': _$GreekEnumMap[instance.fieldEnum], + 'fieldEnum': _$GreekEnumMap[instance.fieldEnum]!, 'constClass': instance.constClass, 'valueFromConverter': const ConstClassConverter().toJson(instance.valueFromConverter), diff --git a/json_serializable/test/default_value/implicit_default_value.g.dart b/json_serializable/test/default_value/implicit_default_value.g.dart index 5b92c2607..ab9ec52bb 100644 --- a/json_serializable/test/default_value/implicit_default_value.g.dart +++ b/json_serializable/test/default_value/implicit_default_value.g.dart @@ -67,7 +67,7 @@ Map<String, dynamic> _$DefaultValueImplicitToJson( 'fieldSetSimple': instance.fieldSetSimple.toList(), 'fieldMapSimple': instance.fieldMapSimple, 'fieldMapListString': instance.fieldMapListString, - 'fieldEnum': _$GreekEnumMap[instance.fieldEnum], + 'fieldEnum': _$GreekEnumMap[instance.fieldEnum]!, 'constClass': instance.constClass, 'valueFromConverter': const ConstClassConverter().toJson(instance.valueFromConverter), diff --git a/json_serializable/test/integration/integration_test.dart b/json_serializable/test/integration/integration_test.dart index 22dc186aa..327c20519 100644 --- a/json_serializable/test/integration/integration_test.dart +++ b/json_serializable/test/integration/integration_test.dart @@ -304,6 +304,23 @@ void main() { expect(dayTypeEnumValues, ['no-good', 'rotten', 'very-bad']); }); + test( + 'serializing a non-nullable enum as a key in a map should produce a ' + 'non-nullable string key', () { + final cls = + Issue1145RegressionA(status: {Issue1145RegressionEnum.gamma: true}); + // Due to issue 1145 this resulted in Map<String?, dynamic> + expect(cls.toJson()['status'], const TypeMatcher<Map<String, dynamic>>()); + }); + + test( + 'serializing a nullable enum in a list should produce a list with' + ' nullable entries', () { + final cls = Issue1145RegressionB(status: [Issue1145RegressionEnum.gamma]); + // Issue 1145 should not have affected nullable enums + expect(cls.toJson()['status'], const TypeMatcher<List<String?>>()); + }); + test('unknown as null for enum', () { expect( () => Issue559Regression.fromJson({}).status, diff --git a/json_serializable/test/integration/json_enum_example.dart b/json_serializable/test/integration/json_enum_example.dart index 5b25001f8..90f6e2006 100644 --- a/json_serializable/test/integration/json_enum_example.dart +++ b/json_serializable/test/integration/json_enum_example.dart @@ -49,3 +49,35 @@ enum Issue559RegressionEnum { beta, gamma, } + +enum Issue1145RegressionEnum { + alpha, + beta, + gamma, +} + +@JsonSerializable( + createFactory: false, +) +class Issue1145RegressionA { + Issue1145RegressionA({ + required this.status, + }); + + Map<String, dynamic> toJson() => _$Issue1145RegressionAToJson(this); + + final Map<Issue1145RegressionEnum, bool> status; +} + +@JsonSerializable( + createFactory: false, +) +class Issue1145RegressionB { + Issue1145RegressionB({ + required this.status, + }); + + Map<String, dynamic> toJson() => _$Issue1145RegressionBToJson(this); + + final List<Issue1145RegressionEnum?> status; +} diff --git a/json_serializable/test/integration/json_enum_example.g.dart b/json_serializable/test/integration/json_enum_example.g.dart index a41a825af..609cdd9c9 100644 --- a/json_serializable/test/integration/json_enum_example.g.dart +++ b/json_serializable/test/integration/json_enum_example.g.dart @@ -26,6 +26,27 @@ const _$Issue559RegressionEnumEnumMap = { Issue559RegressionEnum.gamma: 'gamma', }; +Map<String, dynamic> _$Issue1145RegressionAToJson( + Issue1145RegressionA instance) => + <String, dynamic>{ + 'status': instance.status + .map((k, e) => MapEntry(_$Issue1145RegressionEnumEnumMap[k]!, e)), + }; + +const _$Issue1145RegressionEnumEnumMap = { + Issue1145RegressionEnum.alpha: 'alpha', + Issue1145RegressionEnum.beta: 'beta', + Issue1145RegressionEnum.gamma: 'gamma', +}; + +Map<String, dynamic> _$Issue1145RegressionBToJson( + Issue1145RegressionB instance) => + <String, dynamic>{ + 'status': instance.status + .map((e) => _$Issue1145RegressionEnumEnumMap[e]) + .toList(), + }; + const _$StandAloneEnumEnumMap = { StandAloneEnum.alpha: 'a', StandAloneEnum.beta: 'b', diff --git a/json_serializable/test/integration/json_test_example.g.dart b/json_serializable/test/integration/json_test_example.g.dart index b4ac755e8..432455f76 100644 --- a/json_serializable/test/integration/json_test_example.g.dart +++ b/json_serializable/test/integration/json_test_example.g.dart @@ -37,13 +37,13 @@ Map<String, dynamic> _$PersonToJson(Person instance) => <String, dynamic>{ 'lastName': instance.lastName, 'middleName': instance.middleName, 'dateOfBirth': instance.dateOfBirth?.toIso8601String(), - r'$house': _$CategoryEnumMap[instance.house], + r'$house': _$CategoryEnumMap[instance.house]!, 'order': instance.order, 'customOrders': instance.customOrders, 'houseMap': - instance.houseMap?.map((k, e) => MapEntry(k, _$CategoryEnumMap[e])), + instance.houseMap?.map((k, e) => MapEntry(k, _$CategoryEnumMap[e]!)), 'categoryCounts': instance.categoryCounts - ?.map((k, e) => MapEntry(_$CategoryEnumMap[k], e)), + ?.map((k, e) => MapEntry(_$CategoryEnumMap[k]!, e)), }; const _$CategoryEnumMap = { diff --git a/json_serializable/test/integration/json_test_example.g_any_map.g.dart b/json_serializable/test/integration/json_test_example.g_any_map.g.dart index cf1e068dd..13390d797 100644 --- a/json_serializable/test/integration/json_test_example.g_any_map.g.dart +++ b/json_serializable/test/integration/json_test_example.g_any_map.g.dart @@ -37,13 +37,13 @@ Map<String, dynamic> _$PersonToJson(Person instance) => <String, dynamic>{ 'lastName': instance.lastName, 'middleName': instance.middleName, 'dateOfBirth': instance.dateOfBirth?.toIso8601String(), - r'$house': _$CategoryEnumMap[instance.house], + r'$house': _$CategoryEnumMap[instance.house]!, 'order': instance.order, 'customOrders': instance.customOrders, 'houseMap': - instance.houseMap?.map((k, e) => MapEntry(k, _$CategoryEnumMap[e])), + instance.houseMap?.map((k, e) => MapEntry(k, _$CategoryEnumMap[e]!)), 'categoryCounts': instance.categoryCounts - ?.map((k, e) => MapEntry(_$CategoryEnumMap[k], e)), + ?.map((k, e) => MapEntry(_$CategoryEnumMap[k]!, e)), }; const _$CategoryEnumMap = { diff --git a/json_serializable/test/supported_types/input.type_enumtype.g.dart b/json_serializable/test/supported_types/input.type_enumtype.g.dart index 6f8fa4a70..b8f1901fc 100644 --- a/json_serializable/test/supported_types/input.type_enumtype.g.dart +++ b/json_serializable/test/supported_types/input.type_enumtype.g.dart @@ -16,8 +16,8 @@ SimpleClass _$SimpleClassFromJson(Map<String, dynamic> json) => SimpleClass( Map<String, dynamic> _$SimpleClassToJson(SimpleClass instance) => <String, dynamic>{ - 'value': _$EnumTypeEnumMap[instance.value], - 'withDefault': _$EnumTypeEnumMap[instance.withDefault], + 'value': _$EnumTypeEnumMap[instance.value]!, + 'withDefault': _$EnumTypeEnumMap[instance.withDefault]!, }; const _$EnumTypeEnumMap = { diff --git a/json_serializable/test/supported_types/input.type_iterable.g.dart b/json_serializable/test/supported_types/input.type_iterable.g.dart index 388702120..1433484ec 100644 --- a/json_serializable/test/supported_types/input.type_iterable.g.dart +++ b/json_serializable/test/supported_types/input.type_iterable.g.dart @@ -314,7 +314,7 @@ SimpleClassOfEnumType _$SimpleClassOfEnumTypeFromJson( Map<String, dynamic> _$SimpleClassOfEnumTypeToJson( SimpleClassOfEnumType instance) => <String, dynamic>{ - 'value': instance.value.map((e) => _$EnumTypeEnumMap[e]).toList(), + 'value': instance.value.map((e) => _$EnumTypeEnumMap[e]!).toList(), }; const _$EnumTypeEnumMap = { @@ -334,7 +334,7 @@ SimpleClassNullableOfEnumType _$SimpleClassNullableOfEnumTypeFromJson( Map<String, dynamic> _$SimpleClassNullableOfEnumTypeToJson( SimpleClassNullableOfEnumType instance) => <String, dynamic>{ - 'value': instance.value?.map((e) => _$EnumTypeEnumMap[e]).toList(), + 'value': instance.value?.map((e) => _$EnumTypeEnumMap[e]!).toList(), }; SimpleClassOfEnumTypeNullable _$SimpleClassOfEnumTypeNullableFromJson( diff --git a/json_serializable/test/supported_types/input.type_list.g.dart b/json_serializable/test/supported_types/input.type_list.g.dart index b20b902e4..9c6a1fe88 100644 --- a/json_serializable/test/supported_types/input.type_list.g.dart +++ b/json_serializable/test/supported_types/input.type_list.g.dart @@ -337,7 +337,7 @@ SimpleClassOfEnumType _$SimpleClassOfEnumTypeFromJson( Map<String, dynamic> _$SimpleClassOfEnumTypeToJson( SimpleClassOfEnumType instance) => <String, dynamic>{ - 'value': instance.value.map((e) => _$EnumTypeEnumMap[e]).toList(), + 'value': instance.value.map((e) => _$EnumTypeEnumMap[e]!).toList(), }; const _$EnumTypeEnumMap = { @@ -358,7 +358,7 @@ SimpleClassNullableOfEnumType _$SimpleClassNullableOfEnumTypeFromJson( Map<String, dynamic> _$SimpleClassNullableOfEnumTypeToJson( SimpleClassNullableOfEnumType instance) => <String, dynamic>{ - 'value': instance.value?.map((e) => _$EnumTypeEnumMap[e]).toList(), + 'value': instance.value?.map((e) => _$EnumTypeEnumMap[e]!).toList(), }; SimpleClassOfEnumTypeNullable _$SimpleClassOfEnumTypeNullableFromJson( diff --git a/json_serializable/test/supported_types/input.type_map.g.dart b/json_serializable/test/supported_types/input.type_map.g.dart index 3e78f5f8b..82b579e23 100644 --- a/json_serializable/test/supported_types/input.type_map.g.dart +++ b/json_serializable/test/supported_types/input.type_map.g.dart @@ -134,7 +134,7 @@ Map<String, dynamic> _$SimpleClassOfEnumTypeToBigIntToJson( SimpleClassOfEnumTypeToBigInt instance) => <String, dynamic>{ 'value': instance.value - .map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e.toString())), + .map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e.toString())), }; const _$EnumTypeEnumMap = { @@ -158,7 +158,7 @@ Map<String, dynamic> _$SimpleClassNullableOfEnumTypeToBigIntToJson( SimpleClassNullableOfEnumTypeToBigInt instance) => <String, dynamic>{ 'value': instance.value - ?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e.toString())), + ?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e.toString())), }; SimpleClassOfIntToBigInt _$SimpleClassOfIntToBigIntFromJson( @@ -387,7 +387,7 @@ Map<String, dynamic> _$SimpleClassOfEnumTypeToBigIntNullableToJson( SimpleClassOfEnumTypeToBigIntNullable instance) => <String, dynamic>{ 'value': instance.value - .map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e?.toString())), + .map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e?.toString())), }; SimpleClassNullableOfEnumTypeToBigIntNullable @@ -404,7 +404,7 @@ Map<String, dynamic> _$SimpleClassNullableOfEnumTypeToBigIntNullableToJson( SimpleClassNullableOfEnumTypeToBigIntNullable instance) => <String, dynamic>{ 'value': instance.value - ?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e?.toString())), + ?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e?.toString())), }; SimpleClassOfIntToBigIntNullable _$SimpleClassOfIntToBigIntNullableFromJson( @@ -624,7 +624,7 @@ SimpleClassOfEnumTypeToBool _$SimpleClassOfEnumTypeToBoolFromJson( Map<String, dynamic> _$SimpleClassOfEnumTypeToBoolToJson( SimpleClassOfEnumTypeToBool instance) => <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), + 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), }; SimpleClassNullableOfEnumTypeToBool @@ -638,7 +638,8 @@ SimpleClassNullableOfEnumTypeToBool Map<String, dynamic> _$SimpleClassNullableOfEnumTypeToBoolToJson( SimpleClassNullableOfEnumTypeToBool instance) => <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), + 'value': + instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), }; SimpleClassOfIntToBool _$SimpleClassOfIntToBoolFromJson( @@ -845,7 +846,7 @@ SimpleClassOfEnumTypeToBoolNullable Map<String, dynamic> _$SimpleClassOfEnumTypeToBoolNullableToJson( SimpleClassOfEnumTypeToBoolNullable instance) => <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), + 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), }; SimpleClassNullableOfEnumTypeToBoolNullable @@ -860,7 +861,8 @@ SimpleClassNullableOfEnumTypeToBoolNullable Map<String, dynamic> _$SimpleClassNullableOfEnumTypeToBoolNullableToJson( SimpleClassNullableOfEnumTypeToBoolNullable instance) => <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), + 'value': + instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), }; SimpleClassOfIntToBoolNullable _$SimpleClassOfIntToBoolNullableFromJson( @@ -1079,7 +1081,7 @@ Map<String, dynamic> _$SimpleClassOfEnumTypeToDateTimeToJson( SimpleClassOfEnumTypeToDateTime instance) => <String, dynamic>{ 'value': instance.value - .map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e.toIso8601String())), + .map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e.toIso8601String())), }; SimpleClassNullableOfEnumTypeToDateTime @@ -1096,7 +1098,7 @@ Map<String, dynamic> _$SimpleClassNullableOfEnumTypeToDateTimeToJson( SimpleClassNullableOfEnumTypeToDateTime instance) => <String, dynamic>{ 'value': instance.value - ?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e.toIso8601String())), + ?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e.toIso8601String())), }; SimpleClassOfIntToDateTime _$SimpleClassOfIntToDateTimeFromJson( @@ -1331,7 +1333,7 @@ Map<String, dynamic> _$SimpleClassOfEnumTypeToDateTimeNullableToJson( SimpleClassOfEnumTypeToDateTimeNullable instance) => <String, dynamic>{ 'value': instance.value - .map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e?.toIso8601String())), + .map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e?.toIso8601String())), }; SimpleClassNullableOfEnumTypeToDateTimeNullable @@ -1347,8 +1349,8 @@ SimpleClassNullableOfEnumTypeToDateTimeNullable Map<String, dynamic> _$SimpleClassNullableOfEnumTypeToDateTimeNullableToJson( SimpleClassNullableOfEnumTypeToDateTimeNullable instance) => <String, dynamic>{ - 'value': instance.value - ?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e?.toIso8601String())), + 'value': instance.value?.map( + (k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e?.toIso8601String())), }; SimpleClassOfIntToDateTimeNullable _$SimpleClassOfIntToDateTimeNullableFromJson( @@ -1578,7 +1580,7 @@ SimpleClassOfEnumTypeToDouble _$SimpleClassOfEnumTypeToDoubleFromJson( Map<String, dynamic> _$SimpleClassOfEnumTypeToDoubleToJson( SimpleClassOfEnumTypeToDouble instance) => <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), + 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), }; SimpleClassNullableOfEnumTypeToDouble @@ -1594,7 +1596,8 @@ SimpleClassNullableOfEnumTypeToDouble Map<String, dynamic> _$SimpleClassNullableOfEnumTypeToDoubleToJson( SimpleClassNullableOfEnumTypeToDouble instance) => <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), + 'value': + instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), }; SimpleClassOfIntToDouble _$SimpleClassOfIntToDoubleFromJson( @@ -1810,7 +1813,7 @@ SimpleClassOfEnumTypeToDoubleNullable Map<String, dynamic> _$SimpleClassOfEnumTypeToDoubleNullableToJson( SimpleClassOfEnumTypeToDoubleNullable instance) => <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), + 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), }; SimpleClassNullableOfEnumTypeToDoubleNullable @@ -1826,7 +1829,8 @@ SimpleClassNullableOfEnumTypeToDoubleNullable Map<String, dynamic> _$SimpleClassNullableOfEnumTypeToDoubleNullableToJson( SimpleClassNullableOfEnumTypeToDoubleNullable instance) => <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), + 'value': + instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), }; SimpleClassOfIntToDoubleNullable _$SimpleClassOfIntToDoubleNullableFromJson( @@ -2051,7 +2055,7 @@ Map<String, dynamic> _$SimpleClassOfEnumTypeToDurationToJson( SimpleClassOfEnumTypeToDuration instance) => <String, dynamic>{ 'value': instance.value - .map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e.inMicroseconds)), + .map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e.inMicroseconds)), }; SimpleClassNullableOfEnumTypeToDuration @@ -2068,7 +2072,7 @@ Map<String, dynamic> _$SimpleClassNullableOfEnumTypeToDurationToJson( SimpleClassNullableOfEnumTypeToDuration instance) => <String, dynamic>{ 'value': instance.value - ?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e.inMicroseconds)), + ?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e.inMicroseconds)), }; SimpleClassOfIntToDuration _$SimpleClassOfIntToDurationFromJson( @@ -2303,7 +2307,7 @@ Map<String, dynamic> _$SimpleClassOfEnumTypeToDurationNullableToJson( SimpleClassOfEnumTypeToDurationNullable instance) => <String, dynamic>{ 'value': instance.value - .map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e?.inMicroseconds)), + .map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e?.inMicroseconds)), }; SimpleClassNullableOfEnumTypeToDurationNullable @@ -2320,7 +2324,7 @@ Map<String, dynamic> _$SimpleClassNullableOfEnumTypeToDurationNullableToJson( SimpleClassNullableOfEnumTypeToDurationNullable instance) => <String, dynamic>{ 'value': instance.value - ?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e?.inMicroseconds)), + ?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e?.inMicroseconds)), }; SimpleClassOfIntToDurationNullable _$SimpleClassOfIntToDurationNullableFromJson( @@ -2546,7 +2550,7 @@ SimpleClassOfEnumTypeToDynamic _$SimpleClassOfEnumTypeToDynamicFromJson( Map<String, dynamic> _$SimpleClassOfEnumTypeToDynamicToJson( SimpleClassOfEnumTypeToDynamic instance) => <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), + 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), }; SimpleClassNullableOfEnumTypeToDynamic @@ -2561,7 +2565,8 @@ SimpleClassNullableOfEnumTypeToDynamic Map<String, dynamic> _$SimpleClassNullableOfEnumTypeToDynamicToJson( SimpleClassNullableOfEnumTypeToDynamic instance) => <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), + 'value': + instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), }; SimpleClassOfIntToDynamic _$SimpleClassOfIntToDynamicFromJson( @@ -2680,7 +2685,7 @@ Map<String, dynamic> _$SimpleClassOfBigIntToEnumTypeToJson( SimpleClassOfBigIntToEnumType instance) => <String, dynamic>{ 'value': instance.value - .map((k, e) => MapEntry(k.toString(), _$EnumTypeEnumMap[e])), + .map((k, e) => MapEntry(k.toString(), _$EnumTypeEnumMap[e]!)), }; SimpleClassNullableOfBigIntToEnumType @@ -2697,7 +2702,7 @@ Map<String, dynamic> _$SimpleClassNullableOfBigIntToEnumTypeToJson( SimpleClassNullableOfBigIntToEnumType instance) => <String, dynamic>{ 'value': instance.value - ?.map((k, e) => MapEntry(k.toString(), _$EnumTypeEnumMap[e])), + ?.map((k, e) => MapEntry(k.toString(), _$EnumTypeEnumMap[e]!)), }; SimpleClassOfDateTimeToEnumType _$SimpleClassOfDateTimeToEnumTypeFromJson( @@ -2713,7 +2718,7 @@ Map<String, dynamic> _$SimpleClassOfDateTimeToEnumTypeToJson( SimpleClassOfDateTimeToEnumType instance) => <String, dynamic>{ 'value': instance.value - .map((k, e) => MapEntry(k.toIso8601String(), _$EnumTypeEnumMap[e])), + .map((k, e) => MapEntry(k.toIso8601String(), _$EnumTypeEnumMap[e]!)), }; SimpleClassNullableOfDateTimeToEnumType @@ -2730,7 +2735,7 @@ Map<String, dynamic> _$SimpleClassNullableOfDateTimeToEnumTypeToJson( SimpleClassNullableOfDateTimeToEnumType instance) => <String, dynamic>{ 'value': instance.value - ?.map((k, e) => MapEntry(k.toIso8601String(), _$EnumTypeEnumMap[e])), + ?.map((k, e) => MapEntry(k.toIso8601String(), _$EnumTypeEnumMap[e]!)), }; SimpleClassOfDynamicToEnumType _$SimpleClassOfDynamicToEnumTypeFromJson( @@ -2744,7 +2749,7 @@ SimpleClassOfDynamicToEnumType _$SimpleClassOfDynamicToEnumTypeFromJson( Map<String, dynamic> _$SimpleClassOfDynamicToEnumTypeToJson( SimpleClassOfDynamicToEnumType instance) => <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k, _$EnumTypeEnumMap[e])), + 'value': instance.value.map((k, e) => MapEntry(k, _$EnumTypeEnumMap[e]!)), }; SimpleClassNullableOfDynamicToEnumType @@ -2759,7 +2764,8 @@ SimpleClassNullableOfDynamicToEnumType Map<String, dynamic> _$SimpleClassNullableOfDynamicToEnumTypeToJson( SimpleClassNullableOfDynamicToEnumType instance) => <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k, _$EnumTypeEnumMap[e])), + 'value': + instance.value?.map((k, e) => MapEntry(k, _$EnumTypeEnumMap[e]!)), }; SimpleClassOfEnumTypeToEnumType _$SimpleClassOfEnumTypeToEnumTypeFromJson( @@ -2774,8 +2780,8 @@ SimpleClassOfEnumTypeToEnumType _$SimpleClassOfEnumTypeToEnumTypeFromJson( Map<String, dynamic> _$SimpleClassOfEnumTypeToEnumTypeToJson( SimpleClassOfEnumTypeToEnumType instance) => <String, dynamic>{ - 'value': instance.value - .map((k, e) => MapEntry(_$EnumTypeEnumMap[k], _$EnumTypeEnumMap[e])), + 'value': instance.value.map( + (k, e) => MapEntry(_$EnumTypeEnumMap[k]!, _$EnumTypeEnumMap[e]!)), }; SimpleClassNullableOfEnumTypeToEnumType @@ -2791,8 +2797,8 @@ SimpleClassNullableOfEnumTypeToEnumType Map<String, dynamic> _$SimpleClassNullableOfEnumTypeToEnumTypeToJson( SimpleClassNullableOfEnumTypeToEnumType instance) => <String, dynamic>{ - 'value': instance.value - ?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], _$EnumTypeEnumMap[e])), + 'value': instance.value?.map( + (k, e) => MapEntry(_$EnumTypeEnumMap[k]!, _$EnumTypeEnumMap[e]!)), }; SimpleClassOfIntToEnumType _$SimpleClassOfIntToEnumTypeFromJson( @@ -2807,7 +2813,7 @@ Map<String, dynamic> _$SimpleClassOfIntToEnumTypeToJson( SimpleClassOfIntToEnumType instance) => <String, dynamic>{ 'value': instance.value - .map((k, e) => MapEntry(k.toString(), _$EnumTypeEnumMap[e])), + .map((k, e) => MapEntry(k.toString(), _$EnumTypeEnumMap[e]!)), }; SimpleClassNullableOfIntToEnumType _$SimpleClassNullableOfIntToEnumTypeFromJson( @@ -2822,7 +2828,7 @@ Map<String, dynamic> _$SimpleClassNullableOfIntToEnumTypeToJson( SimpleClassNullableOfIntToEnumType instance) => <String, dynamic>{ 'value': instance.value - ?.map((k, e) => MapEntry(k.toString(), _$EnumTypeEnumMap[e])), + ?.map((k, e) => MapEntry(k.toString(), _$EnumTypeEnumMap[e]!)), }; SimpleClassOfObjectToEnumType _$SimpleClassOfObjectToEnumTypeFromJson( @@ -2836,7 +2842,7 @@ SimpleClassOfObjectToEnumType _$SimpleClassOfObjectToEnumTypeFromJson( Map<String, dynamic> _$SimpleClassOfObjectToEnumTypeToJson( SimpleClassOfObjectToEnumType instance) => <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k, _$EnumTypeEnumMap[e])), + 'value': instance.value.map((k, e) => MapEntry(k, _$EnumTypeEnumMap[e]!)), }; SimpleClassNullableOfObjectToEnumType @@ -2851,7 +2857,8 @@ SimpleClassNullableOfObjectToEnumType Map<String, dynamic> _$SimpleClassNullableOfObjectToEnumTypeToJson( SimpleClassNullableOfObjectToEnumType instance) => <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k, _$EnumTypeEnumMap[e])), + 'value': + instance.value?.map((k, e) => MapEntry(k, _$EnumTypeEnumMap[e]!)), }; SimpleClassOfStringToEnumType _$SimpleClassOfStringToEnumTypeFromJson( @@ -2865,7 +2872,7 @@ SimpleClassOfStringToEnumType _$SimpleClassOfStringToEnumTypeFromJson( Map<String, dynamic> _$SimpleClassOfStringToEnumTypeToJson( SimpleClassOfStringToEnumType instance) => <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k, _$EnumTypeEnumMap[e])), + 'value': instance.value.map((k, e) => MapEntry(k, _$EnumTypeEnumMap[e]!)), }; SimpleClassNullableOfStringToEnumType @@ -2880,7 +2887,8 @@ SimpleClassNullableOfStringToEnumType Map<String, dynamic> _$SimpleClassNullableOfStringToEnumTypeToJson( SimpleClassNullableOfStringToEnumType instance) => <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k, _$EnumTypeEnumMap[e])), + 'value': + instance.value?.map((k, e) => MapEntry(k, _$EnumTypeEnumMap[e]!)), }; SimpleClassOfUriToEnumType _$SimpleClassOfUriToEnumTypeFromJson( @@ -2895,7 +2903,7 @@ Map<String, dynamic> _$SimpleClassOfUriToEnumTypeToJson( SimpleClassOfUriToEnumType instance) => <String, dynamic>{ 'value': instance.value - .map((k, e) => MapEntry(k.toString(), _$EnumTypeEnumMap[e])), + .map((k, e) => MapEntry(k.toString(), _$EnumTypeEnumMap[e]!)), }; SimpleClassNullableOfUriToEnumType _$SimpleClassNullableOfUriToEnumTypeFromJson( @@ -2910,7 +2918,7 @@ Map<String, dynamic> _$SimpleClassNullableOfUriToEnumTypeToJson( SimpleClassNullableOfUriToEnumType instance) => <String, dynamic>{ 'value': instance.value - ?.map((k, e) => MapEntry(k.toString(), _$EnumTypeEnumMap[e])), + ?.map((k, e) => MapEntry(k.toString(), _$EnumTypeEnumMap[e]!)), }; SimpleClassOfBigIntToEnumTypeNullable @@ -3025,7 +3033,7 @@ Map<String, dynamic> _$SimpleClassOfEnumTypeToEnumTypeNullableToJson( SimpleClassOfEnumTypeToEnumTypeNullable instance) => <String, dynamic>{ 'value': instance.value - .map((k, e) => MapEntry(_$EnumTypeEnumMap[k], _$EnumTypeEnumMap[e])), + .map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, _$EnumTypeEnumMap[e])), }; SimpleClassNullableOfEnumTypeToEnumTypeNullable @@ -3041,8 +3049,8 @@ SimpleClassNullableOfEnumTypeToEnumTypeNullable Map<String, dynamic> _$SimpleClassNullableOfEnumTypeToEnumTypeNullableToJson( SimpleClassNullableOfEnumTypeToEnumTypeNullable instance) => <String, dynamic>{ - 'value': instance.value - ?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], _$EnumTypeEnumMap[e])), + 'value': instance.value?.map( + (k, e) => MapEntry(_$EnumTypeEnumMap[k]!, _$EnumTypeEnumMap[e])), }; SimpleClassOfIntToEnumTypeNullable _$SimpleClassOfIntToEnumTypeNullableFromJson( @@ -3264,7 +3272,7 @@ SimpleClassOfEnumTypeToInt _$SimpleClassOfEnumTypeToIntFromJson( Map<String, dynamic> _$SimpleClassOfEnumTypeToIntToJson( SimpleClassOfEnumTypeToInt instance) => <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), + 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), }; SimpleClassNullableOfEnumTypeToInt _$SimpleClassNullableOfEnumTypeToIntFromJson( @@ -3278,7 +3286,8 @@ SimpleClassNullableOfEnumTypeToInt _$SimpleClassNullableOfEnumTypeToIntFromJson( Map<String, dynamic> _$SimpleClassNullableOfEnumTypeToIntToJson( SimpleClassNullableOfEnumTypeToInt instance) => <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), + 'value': + instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), }; SimpleClassOfIntToInt _$SimpleClassOfIntToIntFromJson( @@ -3485,7 +3494,7 @@ SimpleClassOfEnumTypeToIntNullable _$SimpleClassOfEnumTypeToIntNullableFromJson( Map<String, dynamic> _$SimpleClassOfEnumTypeToIntNullableToJson( SimpleClassOfEnumTypeToIntNullable instance) => <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), + 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), }; SimpleClassNullableOfEnumTypeToIntNullable @@ -3500,7 +3509,8 @@ SimpleClassNullableOfEnumTypeToIntNullable Map<String, dynamic> _$SimpleClassNullableOfEnumTypeToIntNullableToJson( SimpleClassNullableOfEnumTypeToIntNullable instance) => <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), + 'value': + instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), }; SimpleClassOfIntToIntNullable _$SimpleClassOfIntToIntNullableFromJson( @@ -3708,7 +3718,7 @@ SimpleClassOfEnumTypeToNum _$SimpleClassOfEnumTypeToNumFromJson( Map<String, dynamic> _$SimpleClassOfEnumTypeToNumToJson( SimpleClassOfEnumTypeToNum instance) => <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), + 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), }; SimpleClassNullableOfEnumTypeToNum _$SimpleClassNullableOfEnumTypeToNumFromJson( @@ -3722,7 +3732,8 @@ SimpleClassNullableOfEnumTypeToNum _$SimpleClassNullableOfEnumTypeToNumFromJson( Map<String, dynamic> _$SimpleClassNullableOfEnumTypeToNumToJson( SimpleClassNullableOfEnumTypeToNum instance) => <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), + 'value': + instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), }; SimpleClassOfIntToNum _$SimpleClassOfIntToNumFromJson( @@ -3929,7 +3940,7 @@ SimpleClassOfEnumTypeToNumNullable _$SimpleClassOfEnumTypeToNumNullableFromJson( Map<String, dynamic> _$SimpleClassOfEnumTypeToNumNullableToJson( SimpleClassOfEnumTypeToNumNullable instance) => <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), + 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), }; SimpleClassNullableOfEnumTypeToNumNullable @@ -3944,7 +3955,8 @@ SimpleClassNullableOfEnumTypeToNumNullable Map<String, dynamic> _$SimpleClassNullableOfEnumTypeToNumNullableToJson( SimpleClassNullableOfEnumTypeToNumNullable instance) => <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), + 'value': + instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), }; SimpleClassOfIntToNumNullable _$SimpleClassOfIntToNumNullableFromJson( @@ -4155,7 +4167,7 @@ SimpleClassOfEnumTypeToObject _$SimpleClassOfEnumTypeToObjectFromJson( Map<String, dynamic> _$SimpleClassOfEnumTypeToObjectToJson( SimpleClassOfEnumTypeToObject instance) => <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), + 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), }; SimpleClassNullableOfEnumTypeToObject @@ -4170,7 +4182,8 @@ SimpleClassNullableOfEnumTypeToObject Map<String, dynamic> _$SimpleClassNullableOfEnumTypeToObjectToJson( SimpleClassNullableOfEnumTypeToObject instance) => <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), + 'value': + instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), }; SimpleClassOfIntToObject _$SimpleClassOfIntToObjectFromJson( @@ -4381,7 +4394,7 @@ SimpleClassOfEnumTypeToObjectNullable Map<String, dynamic> _$SimpleClassOfEnumTypeToObjectNullableToJson( SimpleClassOfEnumTypeToObjectNullable instance) => <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), + 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), }; SimpleClassNullableOfEnumTypeToObjectNullable @@ -4396,7 +4409,8 @@ SimpleClassNullableOfEnumTypeToObjectNullable Map<String, dynamic> _$SimpleClassNullableOfEnumTypeToObjectNullableToJson( SimpleClassNullableOfEnumTypeToObjectNullable instance) => <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), + 'value': + instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), }; SimpleClassOfIntToObjectNullable _$SimpleClassOfIntToObjectNullableFromJson( @@ -4601,7 +4615,7 @@ SimpleClassOfEnumTypeToString _$SimpleClassOfEnumTypeToStringFromJson( Map<String, dynamic> _$SimpleClassOfEnumTypeToStringToJson( SimpleClassOfEnumTypeToString instance) => <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), + 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), }; SimpleClassNullableOfEnumTypeToString @@ -4616,7 +4630,8 @@ SimpleClassNullableOfEnumTypeToString Map<String, dynamic> _$SimpleClassNullableOfEnumTypeToStringToJson( SimpleClassNullableOfEnumTypeToString instance) => <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), + 'value': + instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), }; SimpleClassOfIntToString _$SimpleClassOfIntToStringFromJson( @@ -4825,7 +4840,7 @@ SimpleClassOfEnumTypeToStringNullable Map<String, dynamic> _$SimpleClassOfEnumTypeToStringNullableToJson( SimpleClassOfEnumTypeToStringNullable instance) => <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), + 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), }; SimpleClassNullableOfEnumTypeToStringNullable @@ -4840,7 +4855,8 @@ SimpleClassNullableOfEnumTypeToStringNullable Map<String, dynamic> _$SimpleClassNullableOfEnumTypeToStringNullableToJson( SimpleClassNullableOfEnumTypeToStringNullable instance) => <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e)), + 'value': + instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), }; SimpleClassOfIntToStringNullable _$SimpleClassOfIntToStringNullableFromJson( @@ -5056,7 +5072,7 @@ Map<String, dynamic> _$SimpleClassOfEnumTypeToUriToJson( SimpleClassOfEnumTypeToUri instance) => <String, dynamic>{ 'value': instance.value - .map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e.toString())), + .map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e.toString())), }; SimpleClassNullableOfEnumTypeToUri _$SimpleClassNullableOfEnumTypeToUriFromJson( @@ -5072,7 +5088,7 @@ Map<String, dynamic> _$SimpleClassNullableOfEnumTypeToUriToJson( SimpleClassNullableOfEnumTypeToUri instance) => <String, dynamic>{ 'value': instance.value - ?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e.toString())), + ?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e.toString())), }; SimpleClassOfIntToUri _$SimpleClassOfIntToUriFromJson( @@ -5299,7 +5315,7 @@ Map<String, dynamic> _$SimpleClassOfEnumTypeToUriNullableToJson( SimpleClassOfEnumTypeToUriNullable instance) => <String, dynamic>{ 'value': instance.value - .map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e?.toString())), + .map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e?.toString())), }; SimpleClassNullableOfEnumTypeToUriNullable @@ -5316,7 +5332,7 @@ Map<String, dynamic> _$SimpleClassNullableOfEnumTypeToUriNullableToJson( SimpleClassNullableOfEnumTypeToUriNullable instance) => <String, dynamic>{ 'value': instance.value - ?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k], e?.toString())), + ?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e?.toString())), }; SimpleClassOfIntToUriNullable _$SimpleClassOfIntToUriNullableFromJson( diff --git a/json_serializable/test/supported_types/input.type_set.g.dart b/json_serializable/test/supported_types/input.type_set.g.dart index f46938826..38f681536 100644 --- a/json_serializable/test/supported_types/input.type_set.g.dart +++ b/json_serializable/test/supported_types/input.type_set.g.dart @@ -339,7 +339,7 @@ SimpleClassOfEnumType _$SimpleClassOfEnumTypeFromJson( Map<String, dynamic> _$SimpleClassOfEnumTypeToJson( SimpleClassOfEnumType instance) => <String, dynamic>{ - 'value': instance.value.map((e) => _$EnumTypeEnumMap[e]).toList(), + 'value': instance.value.map((e) => _$EnumTypeEnumMap[e]!).toList(), }; const _$EnumTypeEnumMap = { @@ -360,7 +360,7 @@ SimpleClassNullableOfEnumType _$SimpleClassNullableOfEnumTypeFromJson( Map<String, dynamic> _$SimpleClassNullableOfEnumTypeToJson( SimpleClassNullableOfEnumType instance) => <String, dynamic>{ - 'value': instance.value?.map((e) => _$EnumTypeEnumMap[e]).toList(), + 'value': instance.value?.map((e) => _$EnumTypeEnumMap[e]!).toList(), }; SimpleClassOfEnumTypeNullable _$SimpleClassOfEnumTypeNullableFromJson( From 25c6138009736869109a63d88d00c64f6384421f Mon Sep 17 00:00:00 2001 From: Remi Rousselet <darky12s@gmail.com> Date: Tue, 28 Jun 2022 18:15:45 +0200 Subject: [PATCH 424/569] feat: Add JsonSerializable(createJsonMeta) (#1164) As discussed before, this adds an option for generating a constant Map of property name: json name fixes #972 --- json_annotation/CHANGELOG.md | 2 + .../lib/src/json_serializable.dart | 9 ++++ .../lib/src/json_serializable.g.dart | 44 +++---------------- json_serializable/CHANGELOG.md | 6 +++ json_serializable/README.md | 1 + json_serializable/lib/src/encoder_helper.dart | 21 +++++++++ .../lib/src/generator_helper.dart | 4 ++ .../lib/src/type_helpers/config_types.dart | 6 +++ json_serializable/lib/src/utils.dart | 2 + json_serializable/pubspec.yaml | 2 +- json_serializable/test/config_test.dart | 5 +++ .../test/integration/field_map_example.dart | 43 ++++++++++++++++++ .../test/integration/field_map_example.g.dart | 33 ++++++++++++++ .../test/integration/integration_test.dart | 19 ++++++++ json_serializable/test/shared_config.dart | 1 + .../test/test_sources/test_sources.dart | 1 + .../tool/readme/readme_template.md | 1 + 17 files changed, 161 insertions(+), 39 deletions(-) create mode 100644 json_serializable/test/integration/field_map_example.dart create mode 100644 json_serializable/test/integration/field_map_example.g.dart diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index 753827f52..277480e1f 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -1,5 +1,7 @@ ## 4.6.0 +- Added `JsonSerializable(createFieldMap: true)`. + ([#1164](https://github.com/google/json_serializable.dart/pull/1164)) - Added `JsonSerializable(converters: <JsonConverter>[])` ([#1072](https://github.com/google/json_serializable.dart/issues/1072)) diff --git a/json_annotation/lib/src/json_serializable.dart b/json_annotation/lib/src/json_serializable.dart index 34fe2abb6..17437f349 100644 --- a/json_annotation/lib/src/json_serializable.dart +++ b/json_annotation/lib/src/json_serializable.dart @@ -6,6 +6,7 @@ import 'package:meta/meta_meta.dart'; import 'allowed_keys_helpers.dart'; import 'checked_helpers.dart'; +import 'enum_helpers.dart'; import 'json_converter.dart'; import 'json_key.dart'; @@ -79,6 +80,13 @@ class JsonSerializable { /// ``` final bool? createFactory; + /// If `true` (defaults to false), a private, static `_$ExampleJsonMeta` + /// constant is created in the generated part file. + /// + /// This constant can be used by other code-generators to support features + /// such as [fieldRename]. + final bool? createFieldMap; + /// If `true` (the default), A top-level function is created that you can /// reference from your class. /// @@ -231,6 +239,7 @@ class JsonSerializable { this.anyMap, this.checked, this.constructor, + this.createFieldMap, this.createFactory, this.createToJson, this.disallowUnrecognizedKeys, diff --git a/json_annotation/lib/src/json_serializable.g.dart b/json_annotation/lib/src/json_serializable.g.dart index 65d452093..34ecbe5b0 100644 --- a/json_annotation/lib/src/json_serializable.g.dart +++ b/json_annotation/lib/src/json_serializable.g.dart @@ -18,6 +18,7 @@ JsonSerializable _$JsonSerializableFromJson(Map<String, dynamic> json) => 'checked', 'constructor', 'create_factory', + 'create_field_map', 'create_to_json', 'disallow_unrecognized_keys', 'explicit_to_json', @@ -31,6 +32,8 @@ JsonSerializable _$JsonSerializableFromJson(Map<String, dynamic> json) => anyMap: $checkedConvert('any_map', (v) => v as bool?), checked: $checkedConvert('checked', (v) => v as bool?), constructor: $checkedConvert('constructor', (v) => v as String?), + createFieldMap: + $checkedConvert('create_field_map', (v) => v as bool?), createFactory: $checkedConvert('create_factory', (v) => v as bool?), createToJson: $checkedConvert('create_to_json', (v) => v as bool?), disallowUnrecognizedKeys: @@ -38,7 +41,7 @@ JsonSerializable _$JsonSerializableFromJson(Map<String, dynamic> json) => explicitToJson: $checkedConvert('explicit_to_json', (v) => v as bool?), fieldRename: $checkedConvert('field_rename', - (v) => _$enumDecodeNullable(_$FieldRenameEnumMap, v)), + (v) => $enumDecodeNullable(_$FieldRenameEnumMap, v)), ignoreUnannotated: $checkedConvert('ignore_unannotated', (v) => v as bool?), includeIfNull: $checkedConvert('include_if_null', (v) => v as bool?), @@ -49,6 +52,7 @@ JsonSerializable _$JsonSerializableFromJson(Map<String, dynamic> json) => }, fieldKeyMap: const { 'anyMap': 'any_map', + 'createFieldMap': 'create_field_map', 'createFactory': 'create_factory', 'createToJson': 'create_to_json', 'disallowUnrecognizedKeys': 'disallow_unrecognized_keys', @@ -66,6 +70,7 @@ Map<String, dynamic> _$JsonSerializableToJson(JsonSerializable instance) => 'checked': instance.checked, 'constructor': instance.constructor, 'create_factory': instance.createFactory, + 'create_field_map': instance.createFieldMap, 'create_to_json': instance.createToJson, 'disallow_unrecognized_keys': instance.disallowUnrecognizedKeys, 'explicit_to_json': instance.explicitToJson, @@ -75,43 +80,6 @@ Map<String, dynamic> _$JsonSerializableToJson(JsonSerializable instance) => 'include_if_null': instance.includeIfNull, }; -K _$enumDecode<K, V>( - Map<K, V> enumValues, - Object? source, { - K? unknownValue, -}) { - if (source == null) { - throw ArgumentError( - 'A value must be provided. Supported values: ' - '${enumValues.values.join(', ')}', - ); - } - - return enumValues.entries.singleWhere( - (e) => e.value == source, - orElse: () { - if (unknownValue == null) { - throw ArgumentError( - '`$source` is not one of the supported values: ' - '${enumValues.values.join(', ')}', - ); - } - return MapEntry(unknownValue, enumValues.values.first); - }, - ).key; -} - -K? _$enumDecodeNullable<K, V>( - Map<K, V> enumValues, - dynamic source, { - K? unknownValue, -}) { - if (source == null) { - return null; - } - return _$enumDecode<K, V>(enumValues, source, unknownValue: unknownValue); -} - const _$FieldRenameEnumMap = { FieldRename.none: 'none', FieldRename.kebab: 'kebab', diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 32ef550ed..9f2e66674 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,9 @@ +## 6.3.1-dev + +- Added support for generating `_$ExampleFieldMeta`, which can be used by other + code-generators that needs to interact with the JSON serialization. + ([#1164](https://github.com/google/json_serializable.dart/pull/1164)) + ## 6.3.0-dev - Added support for using a `JsonConverter<MyClass, Object>` on properties diff --git a/json_serializable/README.md b/json_serializable/README.md index ffdb481f7..fd568cae1 100644 --- a/json_serializable/README.md +++ b/json_serializable/README.md @@ -179,6 +179,7 @@ targets: checked: false constructor: "" create_factory: true + create_field_map: false create_to_json: true disallow_unrecognized_keys: false explicit_to_json: false diff --git a/json_serializable/lib/src/encoder_helper.dart b/json_serializable/lib/src/encoder_helper.dart index fd963329d..9bb045852 100644 --- a/json_serializable/lib/src/encoder_helper.dart +++ b/json_serializable/lib/src/encoder_helper.dart @@ -16,6 +16,27 @@ import 'unsupported_type_error.dart'; abstract class EncodeHelper implements HelperCore { String _fieldAccess(FieldElement field) => '$_toJsonParamName.${field.name}'; + /// Generates an object containing metadatas related to the encoding, + /// destined to be used by other code-generators. + String createFieldMap(Set<FieldElement> accessibleFieldSet) { + assert(config.createFieldMap); + + final buffer = StringBuffer( + 'const _\$${element.name.nonPrivate}FieldMap = <String, String> {', + ); + + for (final field in accessibleFieldSet) { + buffer.writeln( + '${escapeDartString(field.name)}: ' + '${escapeDartString(nameAccess(field))},', + ); + } + + buffer.write('};'); + + return buffer.toString(); + } + Iterable<String> createToJson(Set<FieldElement> accessibleFields) sync* { assert(config.createToJson); diff --git a/json_serializable/lib/src/generator_helper.dart b/json_serializable/lib/src/generator_helper.dart index 011fd46d3..f4016292a 100644 --- a/json_serializable/lib/src/generator_helper.dart +++ b/json_serializable/lib/src/generator_helper.dart @@ -108,6 +108,10 @@ class GeneratorHelper extends HelperCore with EncodeHelper, DecodeHelper { }, ); + if (config.createFieldMap) { + yield createFieldMap(accessibleFieldSet); + } + if (config.createToJson) { yield* createToJson(accessibleFieldSet); } diff --git a/json_serializable/lib/src/type_helpers/config_types.dart b/json_serializable/lib/src/type_helpers/config_types.dart index 6d51ac475..d352d16af 100644 --- a/json_serializable/lib/src/type_helpers/config_types.dart +++ b/json_serializable/lib/src/type_helpers/config_types.dart @@ -45,6 +45,7 @@ class ClassConfig { final String constructor; final bool createFactory; final bool createToJson; + final bool createFieldMap; final bool disallowUnrecognizedKeys; final bool explicitToJson; final FieldRename fieldRename; @@ -60,6 +61,7 @@ class ClassConfig { required this.constructor, required this.createFactory, required this.createToJson, + required this.createFieldMap, required this.disallowUnrecognizedKeys, required this.explicitToJson, required this.fieldRename, @@ -76,6 +78,8 @@ class ClassConfig { checked: config.checked ?? ClassConfig.defaults.checked, anyMap: config.anyMap ?? ClassConfig.defaults.anyMap, constructor: config.constructor ?? ClassConfig.defaults.constructor, + createFieldMap: + config.createFieldMap ?? ClassConfig.defaults.createFieldMap, createFactory: config.createFactory ?? ClassConfig.defaults.createFactory, createToJson: config.createToJson ?? ClassConfig.defaults.createToJson, @@ -101,6 +105,7 @@ class ClassConfig { constructor: '', createFactory: true, createToJson: true, + createFieldMap: false, disallowUnrecognizedKeys: false, explicitToJson: false, fieldRename: FieldRename.none, @@ -115,6 +120,7 @@ class ClassConfig { constructor: constructor, createFactory: createFactory, createToJson: createToJson, + createFieldMap: createFieldMap, ignoreUnannotated: ignoreUnannotated, explicitToJson: explicitToJson, includeIfNull: includeIfNull, diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index 470627491..38dbba64b 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -56,6 +56,7 @@ JsonSerializable _valueForAnnotation(ConstantReader reader) => JsonSerializable( constructor: reader.read('constructor').literalValue as String?, createFactory: reader.read('createFactory').literalValue as bool?, createToJson: reader.read('createToJson').literalValue as bool?, + createFieldMap: reader.read('createFieldMap').literalValue as bool?, disallowUnrecognizedKeys: reader.read('disallowUnrecognizedKeys').literalValue as bool?, explicitToJson: reader.read('explicitToJson').literalValue as bool?, @@ -101,6 +102,7 @@ ClassConfig mergeConfig( constructor: constructor, createFactory: annotation.createFactory ?? config.createFactory, createToJson: annotation.createToJson ?? config.createToJson, + createFieldMap: annotation.createFieldMap ?? config.createFieldMap, disallowUnrecognizedKeys: annotation.disallowUnrecognizedKeys ?? config.disallowUnrecognizedKeys, explicitToJson: annotation.explicitToJson ?? config.explicitToJson, diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index b2b5caa5d..ef2647c92 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 6.3.0-dev +version: 6.3.1-dev description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. diff --git a/json_serializable/test/config_test.dart b/json_serializable/test/config_test.dart index 811567b81..d98942607 100644 --- a/json_serializable/test/config_test.dart +++ b/json_serializable/test/config_test.dart @@ -126,6 +126,10 @@ void main() { lastLine = "type 'int' is not a subtype of type 'String?' in type " 'cast'; break; + case 'create_to_json': + lastLine = "type 'int' is not a subtype of type 'bool?' in type " + 'cast'; + break; default: lastLine = "type 'int' is not a subtype of type 'bool?' in type cast"; @@ -152,6 +156,7 @@ const _invalidConfig = { 'checked': 42, 'constructor': 42, 'create_factory': 42, + 'create_field_map': 42, 'create_to_json': 42, 'disallow_unrecognized_keys': 42, 'explicit_to_json': 42, diff --git a/json_serializable/test/integration/field_map_example.dart b/json_serializable/test/integration/field_map_example.dart new file mode 100644 index 000000000..9d06a15ef --- /dev/null +++ b/json_serializable/test/integration/field_map_example.dart @@ -0,0 +1,43 @@ +import 'package:json_annotation/json_annotation.dart'; + +part 'field_map_example.g.dart'; + +@JsonSerializable(createFieldMap: true, fieldRename: FieldRename.kebab) +class Model { + Model({ + required this.firstName, + required this.lastName, + this.ignoredName, + }); + + factory Model.fromJson(Map<String, Object?> json) => _$ModelFromJson(json); + + final String firstName; + + @JsonKey(name: 'LAST_NAME') + final String lastName; + + @JsonKey(ignore: true) + final String? ignoredName; + + String get fullName => '$firstName $lastName'; + + Map<String, Object?> toJson() => _$ModelToJson(this); +} + +const modelFieldMap = _$ModelFieldMap; + +@JsonSerializable( + createFieldMap: true, + fieldRename: FieldRename.kebab, + createFactory: false, +) +class _PrivateModel { + _PrivateModel(this.fullName); + + final String fullName; + + Map<String, Object?> toJson() => _$PrivateModelToJson(this); +} + +const privateModelFieldMap = _$PrivateModelFieldMap; diff --git a/json_serializable/test/integration/field_map_example.g.dart b/json_serializable/test/integration/field_map_example.g.dart new file mode 100644 index 000000000..5c50eadc3 --- /dev/null +++ b/json_serializable/test/integration/field_map_example.g.dart @@ -0,0 +1,33 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal + +part of 'field_map_example.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +Model _$ModelFromJson(Map<String, dynamic> json) => Model( + firstName: json['first-name'] as String, + lastName: json['LAST_NAME'] as String, + ); + +const _$ModelFieldMap = <String, String>{ + 'firstName': 'first-name', + 'lastName': 'LAST_NAME', +}; + +Map<String, dynamic> _$ModelToJson(Model instance) => <String, dynamic>{ + 'first-name': instance.firstName, + 'LAST_NAME': instance.lastName, + }; + +const _$PrivateModelFieldMap = <String, String>{ + 'fullName': 'full-name', +}; + +Map<String, dynamic> _$PrivateModelToJson(_PrivateModel instance) => + <String, dynamic>{ + 'full-name': instance.fullName, + }; diff --git a/json_serializable/test/integration/integration_test.dart b/json_serializable/test/integration/integration_test.dart index 327c20519..731aea828 100644 --- a/json_serializable/test/integration/integration_test.dart +++ b/json_serializable/test/integration/integration_test.dart @@ -6,6 +6,7 @@ import 'package:json_annotation/json_annotation.dart'; import 'package:test/test.dart'; import '../test_utils.dart'; +import 'field_map_example.dart'; import 'json_enum_example.dart'; import 'json_test_common.dart' show Category, Platform, StatusCode; import 'json_test_example.dart'; @@ -339,4 +340,22 @@ void main() { isNull, ); }); + + test(r'_$ModelFieldMap', () { + expect( + modelFieldMap, + { + 'firstName': 'first-name', + 'lastName': 'LAST_NAME', + }, + ); + }); + + test(r'Generates _$PrivateModelFieldMap instead of __$PrivateModelFieldMap', + () { + expect( + privateModelFieldMap, + {'fullName': 'full-name'}, + ); + }); } diff --git a/json_serializable/test/shared_config.dart b/json_serializable/test/shared_config.dart index 8ee8ca585..e387488e9 100644 --- a/json_serializable/test/shared_config.dart +++ b/json_serializable/test/shared_config.dart @@ -19,6 +19,7 @@ final generatorConfigNonDefaultJson = constructor: 'something', createFactory: false, createToJson: false, + createFieldMap: true, disallowUnrecognizedKeys: true, explicitToJson: true, fieldRename: FieldRename.kebab, diff --git a/json_serializable/test/test_sources/test_sources.dart b/json_serializable/test/test_sources/test_sources.dart index c0d93c839..3d3c3b368 100644 --- a/json_serializable/test/test_sources/test_sources.dart +++ b/json_serializable/test/test_sources/test_sources.dart @@ -15,6 +15,7 @@ class ConfigurationImplicitDefaults { constructor: '', createFactory: true, createToJson: true, + createFieldMap: false, disallowUnrecognizedKeys: false, explicitToJson: false, fieldRename: FieldRename.none, diff --git a/json_serializable/tool/readme/readme_template.md b/json_serializable/tool/readme/readme_template.md index ab6fe9f6c..45d9adc18 100644 --- a/json_serializable/tool/readme/readme_template.md +++ b/json_serializable/tool/readme/readme_template.md @@ -137,6 +137,7 @@ targets: checked: false constructor: "" create_factory: true + create_field_map: false create_to_json: true disallow_unrecognized_keys: false explicit_to_json: false From 8a0e71ee64860d3f88d5480c7446ed23599998aa Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Thu, 30 Jun 2022 13:36:47 -0700 Subject: [PATCH 425/569] Latest mono_repo (#1165) --- .github/workflows/dart.yml | 83 +++++++++++++++++++------------------- tool/ci.sh | 2 +- 2 files changed, 43 insertions(+), 42 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index fcb1c1e86..02e70c120 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -1,4 +1,4 @@ -# Created with package:mono_repo v6.2.2 +# Created with package:mono_repo v6.3.0 name: Dart CI on: push: @@ -13,6 +13,7 @@ defaults: shell: bash env: PUB_ENVIRONMENT: bot.github +permissions: read-all jobs: job_001: @@ -20,20 +21,20 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v3 + uses: actions/cache@4504faf7e9bcf8f3ed0bc863c4e1d21499ab8ef8 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:stable" restore-keys: | os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: dart-lang/setup-dart@v1.3 + - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: stable - id: checkout - uses: actions/checkout@v3 + uses: actions/checkout@d0651293c4a5a52e711f25b41b05b2212f385d28 - name: mono_repo self validate - run: dart pub global activate mono_repo 6.2.2 + run: dart pub global activate mono_repo 6.3.0 - name: mono_repo self validate run: dart pub global run mono_repo generate --validate job_002: @@ -41,7 +42,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v3 + uses: actions/cache@4504faf7e9bcf8f3ed0bc863c4e1d21499ab8ef8 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.14.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:format-analyze" @@ -50,11 +51,11 @@ jobs: os:ubuntu-latest;pub-cache-hosted;sdk:2.14.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: dart-lang/setup-dart@v1.3 + - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: "2.14.0" - id: checkout - uses: actions/checkout@v3 + uses: actions/checkout@d0651293c4a5a52e711f25b41b05b2212f385d28 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -125,7 +126,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v3 + uses: actions/cache@4504faf7e9bcf8f3ed0bc863c4e1d21499ab8ef8 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:format-analyze" @@ -134,11 +135,11 @@ jobs: os:ubuntu-latest;pub-cache-hosted;sdk:dev os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: dart-lang/setup-dart@v1.3 + - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: dev - id: checkout - uses: actions/checkout@v3 + uses: actions/checkout@d0651293c4a5a52e711f25b41b05b2212f385d28 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -209,7 +210,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v3 + uses: actions/cache@4504faf7e9bcf8f3ed0bc863c4e1d21499ab8ef8 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.14.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" @@ -218,11 +219,11 @@ jobs: os:ubuntu-latest;pub-cache-hosted;sdk:2.14.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: dart-lang/setup-dart@v1.3 + - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: "2.14.0" - id: checkout - uses: actions/checkout@v3 + uses: actions/checkout@d0651293c4a5a52e711f25b41b05b2212f385d28 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -268,7 +269,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v3 + uses: actions/cache@4504faf7e9bcf8f3ed0bc863c4e1d21499ab8ef8 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.14.0;packages:json_serializable;commands:test_3" @@ -277,11 +278,11 @@ jobs: os:ubuntu-latest;pub-cache-hosted;sdk:2.14.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: dart-lang/setup-dart@v1.3 + - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: "2.14.0" - id: checkout - uses: actions/checkout@v3 + uses: actions/checkout@d0651293c4a5a52e711f25b41b05b2212f385d28 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -300,7 +301,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v3 + uses: actions/cache@4504faf7e9bcf8f3ed0bc863c4e1d21499ab8ef8 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.14.0;packages:json_serializable;commands:test_1" @@ -309,11 +310,11 @@ jobs: os:ubuntu-latest;pub-cache-hosted;sdk:2.14.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: dart-lang/setup-dart@v1.3 + - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: "2.14.0" - id: checkout - uses: actions/checkout@v3 + uses: actions/checkout@d0651293c4a5a52e711f25b41b05b2212f385d28 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -332,7 +333,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v3 + uses: actions/cache@4504faf7e9bcf8f3ed0bc863c4e1d21499ab8ef8 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.14.0;packages:json_serializable;commands:test_2" @@ -341,11 +342,11 @@ jobs: os:ubuntu-latest;pub-cache-hosted;sdk:2.14.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: dart-lang/setup-dart@v1.3 + - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: "2.14.0" - id: checkout - uses: actions/checkout@v3 + uses: actions/checkout@d0651293c4a5a52e711f25b41b05b2212f385d28 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -364,7 +365,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v3 + uses: actions/cache@4504faf7e9bcf8f3ed0bc863c4e1d21499ab8ef8 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" @@ -373,11 +374,11 @@ jobs: os:ubuntu-latest;pub-cache-hosted;sdk:dev os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: dart-lang/setup-dart@v1.3 + - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: dev - id: checkout - uses: actions/checkout@v3 + uses: actions/checkout@d0651293c4a5a52e711f25b41b05b2212f385d28 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -423,7 +424,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v3 + uses: actions/cache@4504faf7e9bcf8f3ed0bc863c4e1d21499ab8ef8 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:json_serializable;commands:test_3" @@ -432,11 +433,11 @@ jobs: os:ubuntu-latest;pub-cache-hosted;sdk:dev os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: dart-lang/setup-dart@v1.3 + - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: dev - id: checkout - uses: actions/checkout@v3 + uses: actions/checkout@d0651293c4a5a52e711f25b41b05b2212f385d28 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -455,7 +456,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v3 + uses: actions/cache@4504faf7e9bcf8f3ed0bc863c4e1d21499ab8ef8 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:json_serializable;commands:test_1" @@ -464,11 +465,11 @@ jobs: os:ubuntu-latest;pub-cache-hosted;sdk:dev os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: dart-lang/setup-dart@v1.3 + - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: dev - id: checkout - uses: actions/checkout@v3 + uses: actions/checkout@d0651293c4a5a52e711f25b41b05b2212f385d28 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -487,7 +488,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v3 + uses: actions/cache@4504faf7e9bcf8f3ed0bc863c4e1d21499ab8ef8 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:json_serializable;commands:test_2" @@ -496,11 +497,11 @@ jobs: os:ubuntu-latest;pub-cache-hosted;sdk:dev os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: dart-lang/setup-dart@v1.3 + - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: dev - id: checkout - uses: actions/checkout@v3 + uses: actions/checkout@d0651293c4a5a52e711f25b41b05b2212f385d28 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -519,7 +520,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v3 + uses: actions/cache@4504faf7e9bcf8f3ed0bc863c4e1d21499ab8ef8 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.14.0;packages:_test_yaml-checked_yaml-example;commands:test_1" @@ -528,11 +529,11 @@ jobs: os:ubuntu-latest;pub-cache-hosted;sdk:2.14.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: dart-lang/setup-dart@v1.3 + - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: "2.14.0" - id: checkout - uses: actions/checkout@v3 + uses: actions/checkout@d0651293c4a5a52e711f25b41b05b2212f385d28 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" @@ -577,7 +578,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@v3 + uses: actions/cache@4504faf7e9bcf8f3ed0bc863c4e1d21499ab8ef8 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:_test_yaml-checked_yaml-example;commands:test_1" @@ -586,11 +587,11 @@ jobs: os:ubuntu-latest;pub-cache-hosted;sdk:dev os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: dart-lang/setup-dart@v1.3 + - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: dev - id: checkout - uses: actions/checkout@v3 + uses: actions/checkout@d0651293c4a5a52e711f25b41b05b2212f385d28 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" diff --git a/tool/ci.sh b/tool/ci.sh index b601dbadc..2beaee4d7 100755 --- a/tool/ci.sh +++ b/tool/ci.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Created with package:mono_repo v6.2.2 +# Created with package:mono_repo v6.3.0 # Support built in commands on windows out of the box. # When it is a flutter repo (check the pubspec.yaml for "sdk: flutter") From decbda14dd654ee0645a69f2c5f6686cd4a66c1f Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Thu, 7 Jul 2022 12:37:31 -0700 Subject: [PATCH 426/569] Prepare to release json_serializable v6.3.0 (#1169) --- json_serializable/CHANGELOG.md | 14 ++++++-------- json_serializable/pubspec.yaml | 6 +----- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 9f2e66674..4f6564098 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,13 +1,11 @@ -## 6.3.1-dev +## 6.3.0 -- Added support for generating `_$ExampleFieldMeta`, which can be used by other - code-generators that needs to interact with the JSON serialization. +- Added support for generating `_$ExampleFieldMap`, which can be used by other + code-generators that needs to interact with JSON serialization. ([#1164](https://github.com/google/json_serializable.dart/pull/1164)) - -## 6.3.0-dev - -- Added support for using a `JsonConverter<MyClass, Object>` on properties - of type `MyClass?`. ([#822](https://github.com/google/json_serializable.dart/issues/822)) +- Added support for using a `JsonConverter<MyClass, Object>` on properties of + type `MyClass?`. + ([#822](https://github.com/google/json_serializable.dart/issues/822)) - Added support for `JsonSerializable(converters: <JsonConverter>[])` ([#1072](https://github.com/google/json_serializable.dart/issues/1072)) - Fix issue with serialization of non-nullable enumerations emitting a nullable diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index ef2647c92..a973db9ef 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 6.3.1-dev +version: 6.3.0 description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. @@ -36,7 +36,3 @@ dev_dependencies: test_descriptor: ^2.0.0 test_process: ^2.0.0 yaml: ^3.0.0 - -dependency_overrides: - json_annotation: - path: ../json_annotation From f50eb99b7c68e4cd74d83ec68a7ad708f8d44dd7 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Fri, 8 Jul 2022 14:44:23 -0700 Subject: [PATCH 427/569] Fix support for Duration fields with default values (#1172) Fixes https://github.com/google/json_serializable.dart/issues/1170 `Duration` was overlooked when supporting default values in constructors. That's now fixed! --- json_serializable/CHANGELOG.md | 5 +++++ json_serializable/lib/src/type_helper.dart | 10 ---------- .../lib/src/type_helpers/duration_helper.dart | 8 ++++---- .../lib/src/type_helpers/to_from_string.dart | 7 ++++--- json_serializable/pubspec.yaml | 2 +- .../test/default_value/default_value.dart | 3 +++ .../test/default_value/default_value.g.dart | 4 ++++ .../default_value.g_any_map__checked.dart | 3 +++ .../default_value.g_any_map__checked.g.dart | 5 +++++ .../test/default_value/default_value_interface.dart | 2 ++ .../test/default_value/default_value_test.dart | 2 ++ .../test/default_value/implicit_default_value.dart | 3 +++ .../test/default_value/implicit_default_value.g.dart | 4 ++++ 13 files changed, 40 insertions(+), 18 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 4f6564098..73f8dba20 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,8 @@ +## 6.3.1 + +- Fixed support for `Duration` fields with default values. + ([#1170](https://github.com/google/json_serializable.dart/issues/1170)) + ## 6.3.0 - Added support for generating `_$ExampleFieldMap`, which can be used by other diff --git a/json_serializable/lib/src/type_helper.dart b/json_serializable/lib/src/type_helper.dart index b01249334..01add6bcf 100644 --- a/json_serializable/lib/src/type_helper.dart +++ b/json_serializable/lib/src/type_helper.dart @@ -6,7 +6,6 @@ import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/type.dart'; import 'type_helpers/config_types.dart'; -import 'utils.dart'; /// Context information provided in calls to [TypeHelper.serialize] and /// [TypeHelper.deserialize]. @@ -85,12 +84,3 @@ abstract class TypeHelper<T extends TypeHelperContext> { bool defaultProvided, ); } - -Object commonNullPrefix( - bool nullable, - String expression, - Object unsafeExpression, -) => - nullable - ? ifNullOrElse(expression, 'null', '$unsafeExpression') - : unsafeExpression; diff --git a/json_serializable/lib/src/type_helpers/duration_helper.dart b/json_serializable/lib/src/type_helpers/duration_helper.dart index 2a1c534fa..d45cb4222 100644 --- a/json_serializable/lib/src/type_helpers/duration_helper.dart +++ b/json_serializable/lib/src/type_helpers/duration_helper.dart @@ -6,6 +6,7 @@ import 'package:analyzer/dart/element/type.dart'; import 'package:source_gen/source_gen.dart' show TypeChecker; import 'package:source_helper/source_helper.dart'; +import '../default_container.dart'; import '../type_helper.dart'; class DurationHelper extends TypeHelper { @@ -33,7 +34,7 @@ class DurationHelper extends TypeHelper { } @override - String? deserialize( + Object? deserialize( DartType targetType, String expression, TypeHelperContext context, @@ -43,11 +44,10 @@ class DurationHelper extends TypeHelper { return null; } - return commonNullPrefix( - targetType.isNullableType, + return DefaultContainer( expression, 'Duration(microseconds: $expression as int)', - ).toString(); + ); } } diff --git a/json_serializable/lib/src/type_helpers/to_from_string.dart b/json_serializable/lib/src/type_helpers/to_from_string.dart index 55f8aae7e..68ea04a0a 100644 --- a/json_serializable/lib/src/type_helpers/to_from_string.dart +++ b/json_serializable/lib/src/type_helpers/to_from_string.dart @@ -5,7 +5,7 @@ import 'package:analyzer/dart/element/type.dart'; import 'package:source_gen/source_gen.dart'; -import '../type_helper.dart'; +import '../utils.dart'; final bigIntString = ToFromStringHelper( 'BigInt.parse', @@ -76,7 +76,8 @@ class ToFromStringHelper { final parseParam = isString ? expression : '$expression as String'; - return commonNullPrefix(nullable, expression, '$_parse($parseParam)') - .toString(); + final output = '$_parse($parseParam)'; + + return nullable ? ifNullOrElse(expression, 'null', output) : output; } } diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index a973db9ef..d3cc89601 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 6.3.0 +version: 6.3.1 description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. diff --git a/json_serializable/test/default_value/default_value.dart b/json_serializable/test/default_value/default_value.dart index a62894d2c..6b7624b35 100644 --- a/json_serializable/test/default_value/default_value.dart +++ b/json_serializable/test/default_value/default_value.dart @@ -59,6 +59,8 @@ class DefaultValue implements dvi.DefaultValue { }) Map<String, List<String>> fieldMapListString; + Duration durationField; + @JsonKey(defaultValue: Greek.beta) Greek fieldEnum; @@ -83,6 +85,7 @@ class DefaultValue implements dvi.DefaultValue { this.fieldMapSimple, this.fieldMapListString, this.fieldEnum, { + this.durationField = Duration.zero, this.constClass = const ConstClass('value'), this.valueFromConverter = const ConstClass('value'), this.valueFromFunction = const ConstClass('value'), diff --git a/json_serializable/test/default_value/default_value.g.dart b/json_serializable/test/default_value/default_value.g.dart index 36088a33f..fef6a04c9 100644 --- a/json_serializable/test/default_value/default_value.g.dart +++ b/json_serializable/test/default_value/default_value.g.dart @@ -36,6 +36,9 @@ DefaultValue _$DefaultValueFromJson(Map<String, dynamic> json) => DefaultValue( 'root': ['child'] }, $enumDecodeNullable(_$GreekEnumMap, json['fieldEnum']) ?? Greek.beta, + durationField: json['durationField'] == null + ? Duration.zero + : Duration(microseconds: json['durationField'] as int), constClass: json['constClass'] == null ? const ConstClass('value') : ConstClass.fromJson(json['constClass'] as Map<String, dynamic>), @@ -61,6 +64,7 @@ Map<String, dynamic> _$DefaultValueToJson(DefaultValue instance) => 'fieldSetSimple': instance.fieldSetSimple.toList(), 'fieldMapSimple': instance.fieldMapSimple, 'fieldMapListString': instance.fieldMapListString, + 'durationField': instance.durationField.inMicroseconds, 'fieldEnum': _$GreekEnumMap[instance.fieldEnum]!, 'constClass': instance.constClass, 'valueFromConverter': diff --git a/json_serializable/test/default_value/default_value.g_any_map__checked.dart b/json_serializable/test/default_value/default_value.g_any_map__checked.dart index 39eeb129a..f56aa1818 100644 --- a/json_serializable/test/default_value/default_value.g_any_map__checked.dart +++ b/json_serializable/test/default_value/default_value.g_any_map__checked.dart @@ -62,6 +62,8 @@ class DefaultValue implements dvi.DefaultValue { }) Map<String, List<String>> fieldMapListString; + Duration durationField; + @JsonKey(defaultValue: Greek.beta) Greek fieldEnum; @@ -86,6 +88,7 @@ class DefaultValue implements dvi.DefaultValue { this.fieldMapSimple, this.fieldMapListString, this.fieldEnum, { + this.durationField = Duration.zero, this.constClass = const ConstClass('value'), this.valueFromConverter = const ConstClass('value'), this.valueFromFunction = const ConstClass('value'), diff --git a/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart b/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart index f2ab42ae8..b06e40e86 100644 --- a/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart +++ b/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart @@ -51,6 +51,10 @@ DefaultValue _$DefaultValueFromJson(Map json) => $checkedCreate( }), $checkedConvert('fieldEnum', (v) => $enumDecodeNullable(_$GreekEnumMap, v) ?? Greek.beta), + durationField: $checkedConvert( + 'durationField', + (v) => + v == null ? Duration.zero : Duration(microseconds: v as int)), constClass: $checkedConvert( 'constClass', (v) => v == null @@ -84,6 +88,7 @@ Map<String, dynamic> _$DefaultValueToJson(DefaultValue instance) => 'fieldSetSimple': instance.fieldSetSimple.toList(), 'fieldMapSimple': instance.fieldMapSimple, 'fieldMapListString': instance.fieldMapListString, + 'durationField': instance.durationField.inMicroseconds, 'fieldEnum': _$GreekEnumMap[instance.fieldEnum]!, 'constClass': instance.constClass, 'valueFromConverter': diff --git a/json_serializable/test/default_value/default_value_interface.dart b/json_serializable/test/default_value/default_value_interface.dart index 9becc6e6f..7c7a4c5ba 100644 --- a/json_serializable/test/default_value/default_value_interface.dart +++ b/json_serializable/test/default_value/default_value_interface.dart @@ -27,6 +27,8 @@ abstract class DefaultValue { Map<String, List<String>> get fieldMapListString; + Duration get durationField; + Greek get fieldEnum; ConstClass get constClass; diff --git a/json_serializable/test/default_value/default_value_test.dart b/json_serializable/test/default_value/default_value_test.dart index baee4b811..c345400fe 100644 --- a/json_serializable/test/default_value/default_value_test.dart +++ b/json_serializable/test/default_value/default_value_test.dart @@ -24,6 +24,7 @@ const _defaultInstance = { 'fieldMapListString': { 'root': ['child'] }, + 'durationField': 0, 'fieldEnum': 'beta', 'constClass': {'field': 'value'}, 'valueFromConverter': 'value', @@ -44,6 +45,7 @@ const _otherValues = { 'fieldMapListString': { 'root2': ['alpha'] }, + 'durationField': 1, 'fieldEnum': 'delta', 'constClass': {'field': 'otherValue'}, 'valueFromConverter': 'otherValue', diff --git a/json_serializable/test/default_value/implicit_default_value.dart b/json_serializable/test/default_value/implicit_default_value.dart index ad6c6c52b..4159ee9fe 100644 --- a/json_serializable/test/default_value/implicit_default_value.dart +++ b/json_serializable/test/default_value/implicit_default_value.dart @@ -34,6 +34,8 @@ class DefaultValueImplicit implements dvi.DefaultValue { final Map<String, List<String>> fieldMapListString; + final Duration durationField; + final Greek fieldEnum; final ConstClass constClass; @@ -59,6 +61,7 @@ class DefaultValueImplicit implements dvi.DefaultValue { 'root': ['child'] }, this.fieldEnum = Greek.beta, + this.durationField = const Duration(), this.constClass = const ConstClass('value'), this.valueFromConverter = const ConstClass('value'), this.valueFromFunction = const ConstClass('value'), diff --git a/json_serializable/test/default_value/implicit_default_value.g.dart b/json_serializable/test/default_value/implicit_default_value.g.dart index ab9ec52bb..98f1de477 100644 --- a/json_serializable/test/default_value/implicit_default_value.g.dart +++ b/json_serializable/test/default_value/implicit_default_value.g.dart @@ -41,6 +41,9 @@ DefaultValueImplicit _$DefaultValueImplicitFromJson( }, fieldEnum: $enumDecodeNullable(_$GreekEnumMap, json['fieldEnum']) ?? Greek.beta, + durationField: json['durationField'] == null + ? const Duration() + : Duration(microseconds: json['durationField'] as int), constClass: json['constClass'] == null ? const ConstClass('value') : ConstClass.fromJson(json['constClass'] as Map<String, dynamic>), @@ -67,6 +70,7 @@ Map<String, dynamic> _$DefaultValueImplicitToJson( 'fieldSetSimple': instance.fieldSetSimple.toList(), 'fieldMapSimple': instance.fieldMapSimple, 'fieldMapListString': instance.fieldMapListString, + 'durationField': instance.durationField.inMicroseconds, 'fieldEnum': _$GreekEnumMap[instance.fieldEnum]!, 'constClass': instance.constClass, 'valueFromConverter': From 5c26a0a843604a49c7fcf7726e5f056269099fb2 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Mon, 1 Aug 2022 10:25:53 -0700 Subject: [PATCH 428/569] Update to latest pkg:analyzer, bump SDK constraint (#1180) Use pkg:lints v2 and remove redundant entries in analysis_options --- .github/workflows/dart.yml | 60 +++++++------- _test_yaml/mono_pkg.yaml | 2 +- _test_yaml/pubspec.yaml | 4 +- analysis_options.yaml | 80 +------------------ checked_yaml/CHANGELOG.md | 2 +- checked_yaml/mono_pkg.yaml | 2 +- checked_yaml/pubspec.yaml | 3 +- example/mono_pkg.yaml | 2 +- example/pubspec.yaml | 6 +- json_annotation/CHANGELOG.md | 4 + json_annotation/lib/src/checked_helpers.dart | 10 +-- json_annotation/mono_pkg.yaml | 2 +- json_annotation/pubspec.yaml | 7 +- json_serializable/CHANGELOG.md | 5 ++ json_serializable/lib/src/enum_utils.dart | 4 +- json_serializable/lib/src/field_helpers.dart | 18 ++--- json_serializable/lib/src/json_key_utils.dart | 7 +- .../type_helpers/json_converter_helper.dart | 2 +- json_serializable/lib/src/utils.dart | 2 +- json_serializable/mono_pkg.yaml | 2 +- json_serializable/pubspec.yaml | 7 +- .../test/generic_files/generic_test.dart | 2 +- .../test/integration/integration_test.dart | 12 +-- .../test/integration/json_test_example.dart | 2 +- .../json_test_example.g_any_map.dart | 2 +- .../test/src/core_subclass_type_input.dart | 24 +++--- .../test/src/inheritance_test_input.dart | 7 +- .../test/src/json_converter_test_input.dart | 21 +++-- shared_test/pubspec.yaml | 5 +- 29 files changed, 123 insertions(+), 183 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 02e70c120..4b6a5d613 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -38,22 +38,22 @@ jobs: - name: mono_repo self validate run: dart pub global run mono_repo generate --validate job_002: - name: "analyzer_and_format; Dart 2.14.0; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; `dart format --output=none --set-exit-if-changed .`, `dart analyze --fatal-infos .`" + name: "analyzer_and_format; Dart 2.17.0; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; `dart format --output=none --set-exit-if-changed .`, `dart analyze --fatal-infos .`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@4504faf7e9bcf8f3ed0bc863c4e1d21499ab8ef8 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.14.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:format-analyze" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.17.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:format-analyze" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:2.14.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable - os:ubuntu-latest;pub-cache-hosted;sdk:2.14.0 + os:ubuntu-latest;pub-cache-hosted;sdk:2.17.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable + os:ubuntu-latest;pub-cache-hosted;sdk:2.17.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: - sdk: "2.14.0" + sdk: "2.17.0" - id: checkout uses: actions/checkout@d0651293c4a5a52e711f25b41b05b2212f385d28 - id: _test_yaml_pub_upgrade @@ -206,22 +206,22 @@ jobs: working-directory: json_serializable run: dart analyze --fatal-infos . job_004: - name: "unit_test; Dart 2.14.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; `dart test`" + name: "unit_test; Dart 2.17.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; `dart test`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@4504faf7e9bcf8f3ed0bc863c4e1d21499ab8ef8 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.14.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.17.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:2.14.0;packages:_test_yaml-checked_yaml-example-json_serializable - os:ubuntu-latest;pub-cache-hosted;sdk:2.14.0 + os:ubuntu-latest;pub-cache-hosted;sdk:2.17.0;packages:_test_yaml-checked_yaml-example-json_serializable + os:ubuntu-latest;pub-cache-hosted;sdk:2.17.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: - sdk: "2.14.0" + sdk: "2.17.0" - id: checkout uses: actions/checkout@d0651293c4a5a52e711f25b41b05b2212f385d28 - id: _test_yaml_pub_upgrade @@ -265,22 +265,22 @@ jobs: - job_002 - job_003 job_005: - name: "unit_test; Dart 2.14.0; PKG: json_serializable; `dart test --run-skipped -t presubmit-only test/annotation_version_test.dart`" + name: "unit_test; Dart 2.17.0; PKG: json_serializable; `dart test --run-skipped -t presubmit-only test/annotation_version_test.dart`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@4504faf7e9bcf8f3ed0bc863c4e1d21499ab8ef8 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.14.0;packages:json_serializable;commands:test_3" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.17.0;packages:json_serializable;commands:test_3" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:2.14.0;packages:json_serializable - os:ubuntu-latest;pub-cache-hosted;sdk:2.14.0 + os:ubuntu-latest;pub-cache-hosted;sdk:2.17.0;packages:json_serializable + os:ubuntu-latest;pub-cache-hosted;sdk:2.17.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: - sdk: "2.14.0" + sdk: "2.17.0" - id: checkout uses: actions/checkout@d0651293c4a5a52e711f25b41b05b2212f385d28 - id: json_serializable_pub_upgrade @@ -297,22 +297,22 @@ jobs: - job_002 - job_003 job_006: - name: "unit_test; Dart 2.14.0; PKG: json_serializable; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" + name: "unit_test; Dart 2.17.0; PKG: json_serializable; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@4504faf7e9bcf8f3ed0bc863c4e1d21499ab8ef8 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.14.0;packages:json_serializable;commands:test_1" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.17.0;packages:json_serializable;commands:test_1" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:2.14.0;packages:json_serializable - os:ubuntu-latest;pub-cache-hosted;sdk:2.14.0 + os:ubuntu-latest;pub-cache-hosted;sdk:2.17.0;packages:json_serializable + os:ubuntu-latest;pub-cache-hosted;sdk:2.17.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: - sdk: "2.14.0" + sdk: "2.17.0" - id: checkout uses: actions/checkout@d0651293c4a5a52e711f25b41b05b2212f385d28 - id: json_serializable_pub_upgrade @@ -329,22 +329,22 @@ jobs: - job_002 - job_003 job_007: - name: "unit_test; Dart 2.14.0; PKG: json_serializable; `dart test -p chrome`" + name: "unit_test; Dart 2.17.0; PKG: json_serializable; `dart test -p chrome`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@4504faf7e9bcf8f3ed0bc863c4e1d21499ab8ef8 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.14.0;packages:json_serializable;commands:test_2" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.17.0;packages:json_serializable;commands:test_2" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:2.14.0;packages:json_serializable - os:ubuntu-latest;pub-cache-hosted;sdk:2.14.0 + os:ubuntu-latest;pub-cache-hosted;sdk:2.17.0;packages:json_serializable + os:ubuntu-latest;pub-cache-hosted;sdk:2.17.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: - sdk: "2.14.0" + sdk: "2.17.0" - id: checkout uses: actions/checkout@d0651293c4a5a52e711f25b41b05b2212f385d28 - id: json_serializable_pub_upgrade @@ -516,22 +516,22 @@ jobs: - job_002 - job_003 job_012: - name: "ensure_build; Dart 2.14.0; PKGS: _test_yaml, checked_yaml, example; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" + name: "ensure_build; Dart 2.17.0; PKGS: _test_yaml, checked_yaml, example; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@4504faf7e9bcf8f3ed0bc863c4e1d21499ab8ef8 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.14.0;packages:_test_yaml-checked_yaml-example;commands:test_1" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.17.0;packages:_test_yaml-checked_yaml-example;commands:test_1" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:2.14.0;packages:_test_yaml-checked_yaml-example - os:ubuntu-latest;pub-cache-hosted;sdk:2.14.0 + os:ubuntu-latest;pub-cache-hosted;sdk:2.17.0;packages:_test_yaml-checked_yaml-example + os:ubuntu-latest;pub-cache-hosted;sdk:2.17.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: - sdk: "2.14.0" + sdk: "2.17.0" - id: checkout uses: actions/checkout@d0651293c4a5a52e711f25b41b05b2212f385d28 - id: _test_yaml_pub_upgrade diff --git a/_test_yaml/mono_pkg.yaml b/_test_yaml/mono_pkg.yaml index f2999e505..fb3857ae3 100644 --- a/_test_yaml/mono_pkg.yaml +++ b/_test_yaml/mono_pkg.yaml @@ -1,6 +1,6 @@ # See https://github.com/google/mono_repo.dart for details on this file sdk: -- 2.14.0 +- 2.17.0 - dev stages: diff --git a/_test_yaml/pubspec.yaml b/_test_yaml/pubspec.yaml index 63c0b00cd..7989c3cb5 100644 --- a/_test_yaml/pubspec.yaml +++ b/_test_yaml/pubspec.yaml @@ -2,7 +2,7 @@ name: _test_yaml publish_to: none environment: - sdk: '>=2.14.0 <3.0.0' + sdk: '>=2.17.0 <3.0.0' dev_dependencies: _json_serial_shared_test: @@ -12,6 +12,8 @@ dev_dependencies: checked_yaml: any json_annotation: ^4.4.0 json_serializable: any + lints: ^2.0.0 + path: ^1.8.2 test: ^1.6.0 yaml: ^3.0.0 diff --git a/analysis_options.yaml b/analysis_options.yaml index fd9a9a815..eb8ce5989 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1,3 +1,5 @@ +include: package:lints/recommended.yaml + analyzer: language: strict-casts: true @@ -5,119 +7,43 @@ analyzer: linter: rules: - always_declare_return_types - - always_require_non_null_named_parameters - - annotate_overrides - avoid_catching_errors - avoid_dynamic_calls - - avoid_empty_else - - avoid_function_literals_in_foreach_calls - - avoid_init_to_null - - avoid_null_checks_in_equality_operators - avoid_private_typedef_functions - avoid_redundant_argument_values - - avoid_relative_lib_imports - - avoid_renaming_method_parameters - - avoid_return_types_on_setters - avoid_returning_null - - avoid_returning_null_for_void - - avoid_shadowing_type_parameters - - avoid_single_cascade_in_expression_statements - - avoid_types_as_parameter_names - avoid_unused_constructor_parameters - avoid_void_async - - await_only_futures - - camel_case_extensions - - camel_case_types - cancel_subscriptions - cascade_invocations - comment_references - - constant_identifier_names - - control_flow_in_finally - - curly_braces_in_flow_control_structures - directives_ordering - - empty_catches - - empty_constructor_bodies - - empty_statements - - exhaustive_cases - - file_names - - hash_and_equals - - implementation_imports - - invariant_booleans - - iterable_contains_unrelated_type - join_return_with_assignment - - library_names - - library_prefixes - lines_longer_than_80_chars - - list_remove_unrelated_type - literal_only_boolean_expressions - missing_whitespace_between_adjacent_strings - - no_duplicate_case_values - no_runtimeType_toString - - non_constant_identifier_names - - null_closures - omit_local_variable_types - only_throw_errors - - overridden_fields - package_api_docs - - package_names - - package_prefixed_library_names - - prefer_adjacent_string_concatenation - prefer_asserts_in_initializer_lists - - prefer_collection_literals - - prefer_conditional_assignment - prefer_const_constructors - prefer_const_declarations - - prefer_contains - - prefer_equal_for_default_values - prefer_expression_function_bodies - - prefer_final_fields - prefer_final_locals - - prefer_for_elements_to_map_fromIterable - - prefer_function_declarations_over_variables - - prefer_generic_function_type_aliases - - prefer_if_null_operators - - prefer_initializing_formals - - prefer_inlined_adds - - prefer_interpolation_to_compose_strings - - prefer_is_empty - - prefer_is_not_empty - - prefer_is_not_operator - - prefer_iterable_whereType - - prefer_null_aware_operators - prefer_relative_imports - prefer_single_quotes - - prefer_spread_collections - - prefer_typing_uninitialized_variables - - prefer_void_to_null - - provide_deprecation_message - - recursive_getters - - slash_for_doc_comments - sort_child_properties_last - sort_pub_dependencies - test_types_in_equals - throw_in_finally - type_annotate_public_apis - - type_init_formals - unawaited_futures - - unnecessary_brace_in_string_interps - - unnecessary_const - - unnecessary_getters_setters - unnecessary_lambdas - - unnecessary_new - - unnecessary_null_aware_assignments - - unnecessary_null_in_if_null_operators - - unnecessary_overrides - unnecessary_parenthesis - unnecessary_statements - - unnecessary_string_escapes - - unnecessary_string_interpolations - - unnecessary_this - - unrelated_type_equality_checks - unsafe_html - use_full_hex_values_for_flutter_colors - - use_function_type_syntax_for_parameters - use_is_even_rather_than_modulo - - use_rethrow_when_possible - use_string_buffers - - valid_regexps - - void_checks + - use_super_parameters diff --git a/checked_yaml/CHANGELOG.md b/checked_yaml/CHANGELOG.md index 019af44b4..f244360ac 100644 --- a/checked_yaml/CHANGELOG.md +++ b/checked_yaml/CHANGELOG.md @@ -1,7 +1,7 @@ ## 2.0.2-dev - Require `json_annotation` `^4.3.0` -- Require Dart SDK `>=2.14` +- Require Dart SDK `>=2.17` ## 2.0.1 diff --git a/checked_yaml/mono_pkg.yaml b/checked_yaml/mono_pkg.yaml index 11ce57bf7..a6d895871 100644 --- a/checked_yaml/mono_pkg.yaml +++ b/checked_yaml/mono_pkg.yaml @@ -1,6 +1,6 @@ # See https://github.com/google/mono_repo.dart for details on this file sdk: -- 2.14.0 +- 2.17.0 - dev stages: diff --git a/checked_yaml/pubspec.yaml b/checked_yaml/pubspec.yaml index f02b54271..d81ac0fe3 100644 --- a/checked_yaml/pubspec.yaml +++ b/checked_yaml/pubspec.yaml @@ -6,7 +6,7 @@ description: >- package:json_serializable and package:yaml. repository: https://github.com/google/json_serializable.dart/tree/master/checked_yaml environment: - sdk: '>=2.14.0 <3.0.0' + sdk: '>=2.17.0 <3.0.0' dependencies: json_annotation: ^4.3.0 @@ -17,6 +17,7 @@ dev_dependencies: build_runner: ^2.0.0 build_verify: ^3.0.0 json_serializable: ^6.0.0 + lints: ^2.0.0 path: ^1.0.0 test: ^1.16.0 test_process: ^2.0.0 diff --git a/example/mono_pkg.yaml b/example/mono_pkg.yaml index 1cbcbed1d..dfe0338ee 100644 --- a/example/mono_pkg.yaml +++ b/example/mono_pkg.yaml @@ -1,6 +1,6 @@ # See https://github.com/google/mono_repo.dart for details on this file sdk: -- 2.14.0 +- 2.17.0 - dev stages: diff --git a/example/pubspec.yaml b/example/pubspec.yaml index eb124b468..2bf5ecaba 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -2,7 +2,7 @@ name: example publish_to: none environment: - sdk: '>=2.14.0 <3.0.0' + sdk: '>=2.17.0 <3.0.0' dependencies: json_annotation: ^4.4.0 @@ -18,7 +18,7 @@ dev_dependencies: json_serializable: ^6.0.0 - # Used by tests. Not required to use `json_serializable`. + # Not required to use `json_serializable`. + lints: ^2.0.0 path: ^1.8.0 - # Used by tests. Not required to use `json_serializable`. test: ^1.16.0 diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index 277480e1f..0fdf4e642 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -1,3 +1,7 @@ +## 4.6.1-dev + +- Require Dart SDK 2.17 + ## 4.6.0 - Added `JsonSerializable(createFieldMap: true)`. diff --git a/json_annotation/lib/src/checked_helpers.dart b/json_annotation/lib/src/checked_helpers.dart index f26d55385..e3da209b2 100644 --- a/json_annotation/lib/src/checked_helpers.dart +++ b/json_annotation/lib/src/checked_helpers.dart @@ -4,8 +4,6 @@ import 'allowed_keys_helpers.dart'; -typedef _CastFunction<R> = R Function(Object?); - /// Helper function used in generated code when /// `JsonSerializableGenerator.checked` is `true`. /// @@ -16,16 +14,16 @@ T $checkedCreate<T>( T Function( S Function<S>( String, - _CastFunction<S>, { + S Function(Object?), { Object? Function(Map, String)? readValue, }), ) constructor, { Map<String, String> fieldKeyMap = const {}, }) { - Q _checkedConvert<Q>( + Q checkedConvert<Q>( String key, - _CastFunction<Q> convertFunction, { + Q Function(Object?) convertFunction, { Object? Function(Map, String)? readValue, }) => $checkedConvert<Q>(map, key, convertFunction, readValue: readValue); @@ -33,7 +31,7 @@ T $checkedCreate<T>( return $checkedNew( className, map, - () => constructor(_checkedConvert), + () => constructor(checkedConvert), fieldKeyMap: fieldKeyMap, ); } diff --git a/json_annotation/mono_pkg.yaml b/json_annotation/mono_pkg.yaml index 24925dbb7..95a6aa9a4 100644 --- a/json_annotation/mono_pkg.yaml +++ b/json_annotation/mono_pkg.yaml @@ -1,6 +1,6 @@ # See https://github.com/google/mono_repo.dart for details on this file sdk: -- 2.14.0 +- 2.17.0 - dev stages: diff --git a/json_annotation/pubspec.yaml b/json_annotation/pubspec.yaml index 7b875c142..6b019fcb4 100644 --- a/json_annotation/pubspec.yaml +++ b/json_annotation/pubspec.yaml @@ -1,17 +1,18 @@ name: json_annotation -version: 4.6.0 +version: 4.6.1-dev description: >- Classes and helper functions that support JSON code generation via the `json_serializable` package. repository: https://github.com/google/json_serializable.dart/tree/master/json_annotation environment: - sdk: '>=2.14.0 <3.0.0' + sdk: '>=2.17.0 <3.0.0' dependencies: meta: ^1.4.0 +dev_dependencies: + lints: ^2.0.0 # When changing JsonSerializable class. -# dev_dependencies: # build_runner: ^2.0.0 # json_serializable: any diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 73f8dba20..38eed7b16 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,8 @@ +## 6.3.2-dev + +- Require Dart SDK 2.17 +- Require package:analyzer >=4.3.1 + ## 6.3.1 - Fixed support for `Duration` fields with default values. diff --git a/json_serializable/lib/src/enum_utils.dart b/json_serializable/lib/src/enum_utils.dart index fe379d36a..769db154c 100644 --- a/json_serializable/lib/src/enum_utils.dart +++ b/json_serializable/lib/src/enum_utils.dart @@ -27,7 +27,7 @@ String? enumValueMapFromType( return null; } - MapEntry<FieldElement, dynamic> _generateEntry(FieldElement fe) { + MapEntry<FieldElement, dynamic> generateEntry(FieldElement fe) { final annotation = const TypeChecker.fromRuntime(JsonValue).firstAnnotationOfExact(fe); @@ -56,7 +56,7 @@ String? enumValueMapFromType( } final enumMap = - Map<FieldElement, dynamic>.fromEntries(enumFields.map(_generateEntry)); + Map<FieldElement, dynamic>.fromEntries(enumFields.map(generateEntry)); final items = enumMap.entries .map((e) => ' ${targetType.element!.name}.${e.key.name}: ' diff --git a/json_serializable/lib/src/field_helpers.dart b/json_serializable/lib/src/field_helpers.dart index bfeff2e93..9ae68c8c2 100644 --- a/json_serializable/lib/src/field_helpers.dart +++ b/json_serializable/lib/src/field_helpers.dart @@ -37,34 +37,34 @@ class _FieldSet implements Comparable<_FieldSet> { static int _sortByLocation(FieldElement a, FieldElement b) { final checkerA = - TypeChecker.fromStatic((a.enclosingElement as ClassElement).thisType); + TypeChecker.fromStatic((a.enclosingElement2 as ClassElement).thisType); - if (!checkerA.isExactly(b.enclosingElement)) { + if (!checkerA.isExactly(b.enclosingElement2)) { // in this case, you want to prioritize the enclosingElement that is more // "super". - if (checkerA.isAssignableFrom(b.enclosingElement)) { + if (checkerA.isAssignableFrom(b.enclosingElement2)) { return -1; } - final checkerB = - TypeChecker.fromStatic((b.enclosingElement as ClassElement).thisType); + final checkerB = TypeChecker.fromStatic( + (b.enclosingElement2 as ClassElement).thisType); - if (checkerB.isAssignableFrom(a.enclosingElement)) { + if (checkerB.isAssignableFrom(a.enclosingElement2)) { return 1; } } /// Returns the offset of given field/property in its source file – with a /// preference for the getter if it's defined. - int _offsetFor(FieldElement e) { + int offsetFor(FieldElement e) { if (e.isSynthetic) { return (e.getter ?? e.setter)!.nameOffset; } return e.nameOffset; } - return _offsetFor(a).compareTo(_offsetFor(b)); + return offsetFor(a).compareTo(offsetFor(b)); } } @@ -82,7 +82,7 @@ Iterable<FieldElement> createSortedFieldSet(ClassElement element) { for (final v in manager.getInheritedConcreteMap2(element).values) { assert(v is! FieldElement); - if (_dartCoreObjectChecker.isExactly(v.enclosingElement)) { + if (_dartCoreObjectChecker.isExactly(v.enclosingElement2)) { continue; } diff --git a/json_serializable/lib/src/json_key_utils.dart b/json_serializable/lib/src/json_key_utils.dart index 3d2543163..b309be16d 100644 --- a/json_serializable/lib/src/json_key_utils.dart +++ b/json_serializable/lib/src/json_key_utils.dart @@ -124,7 +124,7 @@ KeyConfig _from(FieldElement element, ClassConfig classAnnotation) { /// If [mustBeEnum] is `true`, throws an [InvalidGenerationSourceError] if /// either the annotated field is not an `enum` or `List` or if the value in /// [fieldName] is not an `enum` value. - String? _annotationValue(String fieldName, {bool mustBeEnum = false}) { + String? createAnnotationValue(String fieldName, {bool mustBeEnum = false}) { final annotationValue = obj.read(fieldName); late final DartType annotationType; @@ -192,7 +192,7 @@ KeyConfig _from(FieldElement element, ClassConfig classAnnotation) { } } - final defaultValue = _annotationValue('defaultValue'); + final defaultValue = createAnnotationValue('defaultValue'); if (defaultValue != null && ctorParamDefault != null) { if (defaultValue == ctorParamDefault) { log.info( @@ -226,7 +226,8 @@ KeyConfig _from(FieldElement element, ClassConfig classAnnotation) { name: obj.read('name').literalValue as String?, readValueFunctionName: readValueFunctionName, required: obj.read('required').literalValue as bool?, - unknownEnumValue: _annotationValue('unknownEnumValue', mustBeEnum: true), + unknownEnumValue: + createAnnotationValue('unknownEnumValue', mustBeEnum: true), ); } diff --git a/json_serializable/lib/src/type_helpers/json_converter_helper.dart b/json_serializable/lib/src/type_helpers/json_converter_helper.dart index ffe1627f1..d0f19750a 100644 --- a/json_serializable/lib/src/type_helpers/json_converter_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_converter_helper.dart @@ -199,7 +199,7 @@ _JsonConvertData? _typeConverterFrom( final annotationElement = match.elementAnnotation?.element; if (annotationElement is PropertyAccessorElement) { - final enclosing = annotationElement.enclosingElement; + final enclosing = annotationElement.enclosingElement2; var accessString = annotationElement.name; diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index 38dbba64b..d4c2afcb5 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -228,7 +228,7 @@ extension ExecutableElementExtension on ExecutableElement { } if (this is MethodElement) { - return '${enclosingElement.name}.$name'; + return '${enclosingElement2.name}.$name'; } throw UnsupportedError( diff --git a/json_serializable/mono_pkg.yaml b/json_serializable/mono_pkg.yaml index 46c30da01..2743bbb7c 100644 --- a/json_serializable/mono_pkg.yaml +++ b/json_serializable/mono_pkg.yaml @@ -1,6 +1,6 @@ # See https://github.com/google/mono_repo.dart for details on this file sdk: -- 2.14.0 +- 2.17.0 - dev stages: diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index d3cc89601..61f557eae 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,14 +1,14 @@ name: json_serializable -version: 6.3.1 +version: 6.3.2-dev description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. repository: https://github.com/google/json_serializable.dart/tree/master/json_serializable environment: - sdk: '>=2.14.0 <3.0.0' + sdk: '>=2.17.0 <3.0.0' dependencies: - analyzer: '>=2.0.0 <5.0.0' + analyzer: '>=4.3.1 <5.0.0' async: ^2.8.0 build: ^2.0.0 build_config: '>=0.4.4 <2.0.0' @@ -30,6 +30,7 @@ dev_dependencies: build_runner: ^2.0.0 build_verify: ^3.0.0 dart_style: ^2.0.0 + lints: ^2.0.0 logging: ^1.0.0 source_gen_test: ^1.0.0 test: ^1.16.0 diff --git a/json_serializable/test/generic_files/generic_test.dart b/json_serializable/test/generic_files/generic_test.dart index 4593dac95..7de5f80d5 100644 --- a/json_serializable/test/generic_files/generic_test.dart +++ b/json_serializable/test/generic_files/generic_test.dart @@ -323,7 +323,7 @@ void main() { Issue980GenericClass(45), Issue980GenericClass(42), ]), - (json) => Issue980ParentClass.fromJson(json), + Issue980ParentClass.fromJson, ); }); diff --git a/json_serializable/test/integration/integration_test.dart b/json_serializable/test/integration/integration_test.dart index 731aea828..ca6266dab 100644 --- a/json_serializable/test/integration/integration_test.dart +++ b/json_serializable/test/integration/integration_test.dart @@ -17,7 +17,7 @@ Matcher _throwsArgumentError(matcher) => void main() { group('Person', () { void roundTripPerson(Person p) { - roundTripObject(p, (json) => Person.fromJson(json)); + roundTripObject(p, Person.fromJson); } test('now', () { @@ -51,7 +51,7 @@ void main() { group('Order', () { void roundTripOrder(Order p) { - roundTripObject(p, (json) => Order.fromJson(json)); + roundTripObject(p, Order.fromJson); } test('null', () { @@ -191,7 +191,7 @@ void main() { group('Item', () { void roundTripItem(Item p) { - roundTripObject(p, (json) => Item.fromJson(json)); + roundTripObject(p, Item.fromJson); } test('empty json', () { @@ -232,7 +232,7 @@ void main() { group('Numbers', () { void roundTripNumber(Numbers p) { - roundTripObject(p, (json) => Numbers.fromJson(json)); + roundTripObject(p, Numbers.fromJson); } test('simple', () { @@ -277,7 +277,7 @@ void main() { ..intIntMap = {3: 3} ..uriIntMap = {Uri.parse('https://example.com'): 4}; - roundTripObject(instance, (j) => MapKeyVariety.fromJson(j)); + roundTripObject(instance, MapKeyVariety.fromJson); }); test('UnknownEnumValue', () { @@ -297,7 +297,7 @@ void main() { test('PrivateConstructor', () { final value = PrivateConstructor('test'); - roundTripObject(value, (json) => PrivateConstructor.fromJson(json)); + roundTripObject(value, PrivateConstructor.fromJson); }); test('enum helpers', () { diff --git a/json_serializable/test/integration/json_test_example.dart b/json_serializable/test/integration/json_test_example.dart index b4c0ab86c..8d29a26f3 100644 --- a/json_serializable/test/integration/json_test_example.dart +++ b/json_serializable/test/integration/json_test_example.dart @@ -109,7 +109,7 @@ class Item extends ItemCore { @JsonKey(fromJson: _fromJsonGeoPoint, toJson: _toJsonGeoPoint) GeoPoint? geoPoint; - Item([int? price]) : super(price); + Item([super.price]); factory Item.fromJson(Map<String, dynamic> json) => _$ItemFromJson(json); diff --git a/json_serializable/test/integration/json_test_example.g_any_map.dart b/json_serializable/test/integration/json_test_example.g_any_map.dart index a6ce3663b..38c5d3687 100644 --- a/json_serializable/test/integration/json_test_example.g_any_map.dart +++ b/json_serializable/test/integration/json_test_example.g_any_map.dart @@ -113,7 +113,7 @@ class Item extends ItemCore { @JsonKey(fromJson: _fromJsonGeoPoint, toJson: _toJsonGeoPoint) GeoPoint? geoPoint; - Item([int? price]) : super(price); + Item([super.price]); factory Item.fromJson(Map<String, dynamic> json) => _$ItemFromJson(json); diff --git a/json_serializable/test/src/core_subclass_type_input.dart b/json_serializable/test/src/core_subclass_type_input.dart index 02b889a2c..4165a4525 100644 --- a/json_serializable/test/src/core_subclass_type_input.dart +++ b/json_serializable/test/src/core_subclass_type_input.dart @@ -27,55 +27,55 @@ class UnsupportedListField { @ShouldThrow( ''' Could not generate `fromJson` code for `customSet`. -To support the type `_CustomSet` you can: +To support the type `CustomSet` you can: $converterOrKeyInstructions''', element: 'customSet', ) @JsonSerializable(createToJson: false) class UnsupportedSetField { - late _CustomSet customSet; + late CustomSet customSet; } -abstract class _CustomSet implements Set {} +abstract class CustomSet implements Set {} @ShouldThrow( ''' Could not generate `fromJson` code for `customDuration`. -To support the type `_CustomDuration` you can: +To support the type `CustomDuration` you can: $converterOrKeyInstructions''', element: 'customDuration', ) @JsonSerializable(createToJson: false) class UnsupportedDurationField { - late _CustomDuration customDuration; + late CustomDuration customDuration; } -abstract class _CustomDuration implements Duration {} +abstract class CustomDuration implements Duration {} @ShouldThrow( ''' Could not generate `fromJson` code for `customUri`. -To support the type `_CustomUri` you can: +To support the type `CustomUri` you can: $converterOrKeyInstructions''', element: 'customUri', ) @JsonSerializable(createToJson: false) class UnsupportedUriField { - _CustomUri? customUri; + CustomUri? customUri; } -abstract class _CustomUri implements Uri {} +abstract class CustomUri implements Uri {} @ShouldThrow( ''' Could not generate `fromJson` code for `customDateTime`. -To support the type `_CustomDateTime` you can: +To support the type `CustomDateTime` you can: $converterOrKeyInstructions''', element: 'customDateTime', ) @JsonSerializable(createToJson: false) class UnsupportedDateTimeField { - late _CustomDateTime customDateTime; + late CustomDateTime customDateTime; } -abstract class _CustomDateTime implements DateTime {} +abstract class CustomDateTime implements DateTime {} diff --git a/json_serializable/test/src/inheritance_test_input.dart b/json_serializable/test/src/inheritance_test_input.dart index b33aaa2c9..7ea3ffc2b 100644 --- a/json_serializable/test/src/inheritance_test_input.dart +++ b/json_serializable/test/src/inheritance_test_input.dart @@ -72,8 +72,7 @@ Map<String, dynamic> _$SubTypeWithAnnotatedFieldOverrideExtendsToJson( ''') @JsonSerializable(createFactory: false) class SubTypeWithAnnotatedFieldOverrideExtends extends SuperType { - SubTypeWithAnnotatedFieldOverrideExtends(int superTypeViaCtor) - : super(superTypeViaCtor); + SubTypeWithAnnotatedFieldOverrideExtends(int super.superTypeViaCtor); } @ShouldGenerate(r''' @@ -88,8 +87,8 @@ Map<String, dynamic> ''') @JsonSerializable(createFactory: false) class SubTypeWithAnnotatedFieldOverrideExtendsWithOverrides extends SuperType { - SubTypeWithAnnotatedFieldOverrideExtendsWithOverrides(int superTypeViaCtor) - : super(superTypeViaCtor); + SubTypeWithAnnotatedFieldOverrideExtendsWithOverrides( + int super.superTypeViaCtor); /// The annotation applied here overrides the annotation in [SuperType]. @JsonKey(includeIfNull: true) diff --git a/json_serializable/test/src/json_converter_test_input.dart b/json_serializable/test/src/json_converter_test_input.dart index fbe7da28c..ac7852f61 100644 --- a/json_serializable/test/src/json_converter_test_input.dart +++ b/json_serializable/test/src/json_converter_test_input.dart @@ -174,40 +174,39 @@ Map<String, dynamic> _$JsonConverterOnGetterToJson( class JsonConverterOnGetter { @JsonKey() @_NeedsConversionConverter() - _NeedsConversion get annotatedGetter => _NeedsConversion(); + NeedsConversion get annotatedGetter => NeedsConversion(); } -class _NeedsConversion {} +class NeedsConversion {} -class _NeedsConversionConverter - implements JsonConverter<_NeedsConversion, int> { +class _NeedsConversionConverter implements JsonConverter<NeedsConversion, int> { const _NeedsConversionConverter(); @override - _NeedsConversion fromJson(int json) => _NeedsConversion(); + NeedsConversion fromJson(int json) => NeedsConversion(); @override - int toJson(_NeedsConversion object) => 0; + int toJson(NeedsConversion object) => 0; } @ShouldThrow( ''' Could not generate `fromJson` code for `value`. -To support the type `_NeedsConversion` you can: +To support the type `NeedsConversion` you can: $converterOrKeyInstructions''', ) @_NullableConverter() @JsonSerializable() class JsonConverterNullableToNonNullable { - late _NeedsConversion value; + late NeedsConversion value; } -class _NullableConverter implements JsonConverter<_NeedsConversion?, Object?> { +class _NullableConverter implements JsonConverter<NeedsConversion?, Object?> { const _NullableConverter(); @override - _NeedsConversion? fromJson(Object? json) => null; + NeedsConversion? fromJson(Object? json) => null; @override - Object? toJson(_NeedsConversion? object) => null; + Object? toJson(NeedsConversion? object) => null; } diff --git a/shared_test/pubspec.yaml b/shared_test/pubspec.yaml index ec6a4e961..42467dbcf 100644 --- a/shared_test/pubspec.yaml +++ b/shared_test/pubspec.yaml @@ -1,8 +1,11 @@ name: _json_serial_shared_test publish_to: none environment: - sdk: '>=2.14.0 <3.0.0' + sdk: '>=2.17.0 <3.0.0' dependencies: stack_trace: ^1.10.0 test: ^1.6.0 + +dev_dependencies: + lints: ^2.0.0 From 10dd2ee26b559b13be3644d7de1cbf19b75a6b29 Mon Sep 17 00:00:00 2001 From: Michel Feinstein <feinstein@users.noreply.github.com> Date: Sun, 28 Aug 2022 16:22:41 -0300 Subject: [PATCH 429/569] Fix JsonConverter docs example (#1193) Closes #1194 --- json_annotation/lib/src/json_converter.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/json_annotation/lib/src/json_converter.dart b/json_annotation/lib/src/json_converter.dart index 73506e3ed..8736d2c42 100644 --- a/json_annotation/lib/src/json_converter.dart +++ b/json_annotation/lib/src/json_converter.dart @@ -13,7 +13,7 @@ /// [JsonConverter]s can be placed either on the class: /// /// ```dart -/// class MyConverter extends JsonConverter<Value, JSON> { +/// class MyJsonConverter extends JsonConverter<Value, JSON> { /// // TODO /// } /// @@ -36,7 +36,7 @@ /// Or finally, passed to the annotation: /// ///```dart -/// @JsonSerializable(converters: [MyConverter()]) +/// @JsonSerializable(converters: [MyJsonConverter()]) /// class Example {} /// ``` abstract class JsonConverter<T, S> { From b1cd6be32c83fac4732c086518e39c0a15633f5e Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Wed, 7 Sep 2022 09:13:07 -0700 Subject: [PATCH 430/569] latest mono_repo, ignore hints for now, use pubspec feature (#1197) Closes https://github.com/google/json_serializable.dart/pull/1196 --- .github/workflows/dart.yml | 248 ++++++++++++++++++-------------- _test_yaml/mono_pkg.yaml | 2 +- analysis_options.yaml | 3 + checked_yaml/mono_pkg.yaml | 2 +- example/mono_pkg.yaml | 2 +- json_annotation/mono_pkg.yaml | 2 +- json_serializable/mono_pkg.yaml | 2 +- tool/ci.sh | 2 +- 8 files changed, 146 insertions(+), 117 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 4b6a5d613..691f85089 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -1,4 +1,4 @@ -# Created with package:mono_repo v6.3.0 +# Created with package:mono_repo v6.4.0 name: Dart CI on: push: @@ -21,20 +21,22 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@4504faf7e9bcf8f3ed0bc863c4e1d21499ab8ef8 + uses: actions/cache@fd5de65bc895cf536527842281bea11763fefd77 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:stable" restore-keys: | os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d + - name: Setup Dart SDK + uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: stable - id: checkout - uses: actions/checkout@d0651293c4a5a52e711f25b41b05b2212f385d28 + name: Checkout repository + uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b - name: mono_repo self validate - run: dart pub global activate mono_repo 6.3.0 + run: dart pub global activate mono_repo 6.4.0 - name: mono_repo self validate run: dart pub global run mono_repo generate --validate job_002: @@ -42,7 +44,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@4504faf7e9bcf8f3ed0bc863c4e1d21499ab8ef8 + uses: actions/cache@fd5de65bc895cf536527842281bea11763fefd77 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.17.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:format-analyze" @@ -51,82 +53,84 @@ jobs: os:ubuntu-latest;pub-cache-hosted;sdk:2.17.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d + - name: Setup Dart SDK + uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: "2.17.0" - id: checkout - uses: actions/checkout@d0651293c4a5a52e711f25b41b05b2212f385d28 + name: Checkout repository + uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade + run: dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: _test_yaml - run: dart pub upgrade - name: "_test_yaml; dart format --output=none --set-exit-if-changed ." + run: "dart format --output=none --set-exit-if-changed ." if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" working-directory: _test_yaml - run: "dart format --output=none --set-exit-if-changed ." - name: "_test_yaml; dart analyze --fatal-infos ." + run: dart analyze --fatal-infos . if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" working-directory: _test_yaml - run: dart analyze --fatal-infos . - id: checked_yaml_pub_upgrade name: checked_yaml; dart pub upgrade + run: dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: checked_yaml - run: dart pub upgrade - name: "checked_yaml; dart format --output=none --set-exit-if-changed ." + run: "dart format --output=none --set-exit-if-changed ." if: "always() && steps.checked_yaml_pub_upgrade.conclusion == 'success'" working-directory: checked_yaml - run: "dart format --output=none --set-exit-if-changed ." - name: "checked_yaml; dart analyze --fatal-infos ." + run: dart analyze --fatal-infos . if: "always() && steps.checked_yaml_pub_upgrade.conclusion == 'success'" working-directory: checked_yaml - run: dart analyze --fatal-infos . - id: example_pub_upgrade name: example; dart pub upgrade + run: dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: example - run: dart pub upgrade - name: "example; dart format --output=none --set-exit-if-changed ." + run: "dart format --output=none --set-exit-if-changed ." if: "always() && steps.example_pub_upgrade.conclusion == 'success'" working-directory: example - run: "dart format --output=none --set-exit-if-changed ." - name: "example; dart analyze --fatal-infos ." + run: dart analyze --fatal-infos . if: "always() && steps.example_pub_upgrade.conclusion == 'success'" working-directory: example - run: dart analyze --fatal-infos . - id: json_annotation_pub_upgrade name: json_annotation; dart pub upgrade + run: dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: json_annotation - run: dart pub upgrade - name: "json_annotation; dart format --output=none --set-exit-if-changed ." + run: "dart format --output=none --set-exit-if-changed ." if: "always() && steps.json_annotation_pub_upgrade.conclusion == 'success'" working-directory: json_annotation - run: "dart format --output=none --set-exit-if-changed ." - name: "json_annotation; dart analyze --fatal-infos ." + run: dart analyze --fatal-infos . if: "always() && steps.json_annotation_pub_upgrade.conclusion == 'success'" working-directory: json_annotation - run: dart analyze --fatal-infos . - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade + run: dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: json_serializable - run: dart pub upgrade - name: "json_serializable; dart format --output=none --set-exit-if-changed ." + run: "dart format --output=none --set-exit-if-changed ." if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" working-directory: json_serializable - run: "dart format --output=none --set-exit-if-changed ." - name: "json_serializable; dart analyze --fatal-infos ." + run: dart analyze --fatal-infos . if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" working-directory: json_serializable - run: dart analyze --fatal-infos . job_003: name: "analyzer_and_format; Dart dev; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; `dart format --output=none --set-exit-if-changed .`, `dart analyze --fatal-infos .`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@4504faf7e9bcf8f3ed0bc863c4e1d21499ab8ef8 + uses: actions/cache@fd5de65bc895cf536527842281bea11763fefd77 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:format-analyze" @@ -135,82 +139,84 @@ jobs: os:ubuntu-latest;pub-cache-hosted;sdk:dev os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d + - name: Setup Dart SDK + uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: dev - id: checkout - uses: actions/checkout@d0651293c4a5a52e711f25b41b05b2212f385d28 + name: Checkout repository + uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade + run: dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: _test_yaml - run: dart pub upgrade - name: "_test_yaml; dart format --output=none --set-exit-if-changed ." + run: "dart format --output=none --set-exit-if-changed ." if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" working-directory: _test_yaml - run: "dart format --output=none --set-exit-if-changed ." - name: "_test_yaml; dart analyze --fatal-infos ." + run: dart analyze --fatal-infos . if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" working-directory: _test_yaml - run: dart analyze --fatal-infos . - id: checked_yaml_pub_upgrade name: checked_yaml; dart pub upgrade + run: dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: checked_yaml - run: dart pub upgrade - name: "checked_yaml; dart format --output=none --set-exit-if-changed ." + run: "dart format --output=none --set-exit-if-changed ." if: "always() && steps.checked_yaml_pub_upgrade.conclusion == 'success'" working-directory: checked_yaml - run: "dart format --output=none --set-exit-if-changed ." - name: "checked_yaml; dart analyze --fatal-infos ." + run: dart analyze --fatal-infos . if: "always() && steps.checked_yaml_pub_upgrade.conclusion == 'success'" working-directory: checked_yaml - run: dart analyze --fatal-infos . - id: example_pub_upgrade name: example; dart pub upgrade + run: dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: example - run: dart pub upgrade - name: "example; dart format --output=none --set-exit-if-changed ." + run: "dart format --output=none --set-exit-if-changed ." if: "always() && steps.example_pub_upgrade.conclusion == 'success'" working-directory: example - run: "dart format --output=none --set-exit-if-changed ." - name: "example; dart analyze --fatal-infos ." + run: dart analyze --fatal-infos . if: "always() && steps.example_pub_upgrade.conclusion == 'success'" working-directory: example - run: dart analyze --fatal-infos . - id: json_annotation_pub_upgrade name: json_annotation; dart pub upgrade + run: dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: json_annotation - run: dart pub upgrade - name: "json_annotation; dart format --output=none --set-exit-if-changed ." + run: "dart format --output=none --set-exit-if-changed ." if: "always() && steps.json_annotation_pub_upgrade.conclusion == 'success'" working-directory: json_annotation - run: "dart format --output=none --set-exit-if-changed ." - name: "json_annotation; dart analyze --fatal-infos ." + run: dart analyze --fatal-infos . if: "always() && steps.json_annotation_pub_upgrade.conclusion == 'success'" working-directory: json_annotation - run: dart analyze --fatal-infos . - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade + run: dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: json_serializable - run: dart pub upgrade - name: "json_serializable; dart format --output=none --set-exit-if-changed ." + run: "dart format --output=none --set-exit-if-changed ." if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" working-directory: json_serializable - run: "dart format --output=none --set-exit-if-changed ." - name: "json_serializable; dart analyze --fatal-infos ." + run: dart analyze --fatal-infos . if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" working-directory: json_serializable - run: dart analyze --fatal-infos . job_004: name: "unit_test; Dart 2.17.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; `dart test`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@4504faf7e9bcf8f3ed0bc863c4e1d21499ab8ef8 + uses: actions/cache@fd5de65bc895cf536527842281bea11763fefd77 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.17.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" @@ -219,47 +225,49 @@ jobs: os:ubuntu-latest;pub-cache-hosted;sdk:2.17.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d + - name: Setup Dart SDK + uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: "2.17.0" - id: checkout - uses: actions/checkout@d0651293c4a5a52e711f25b41b05b2212f385d28 + name: Checkout repository + uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade + run: dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: _test_yaml - run: dart pub upgrade - name: _test_yaml; dart test + run: dart test if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" working-directory: _test_yaml - run: dart test - id: checked_yaml_pub_upgrade name: checked_yaml; dart pub upgrade + run: dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: checked_yaml - run: dart pub upgrade - name: checked_yaml; dart test + run: dart test if: "always() && steps.checked_yaml_pub_upgrade.conclusion == 'success'" working-directory: checked_yaml - run: dart test - id: example_pub_upgrade name: example; dart pub upgrade + run: dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: example - run: dart pub upgrade - name: example; dart test + run: dart test if: "always() && steps.example_pub_upgrade.conclusion == 'success'" working-directory: example - run: dart test - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade + run: dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: json_serializable - run: dart pub upgrade - name: json_serializable; dart test + run: dart test if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" working-directory: json_serializable - run: dart test needs: - job_001 - job_002 @@ -269,7 +277,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@4504faf7e9bcf8f3ed0bc863c4e1d21499ab8ef8 + uses: actions/cache@fd5de65bc895cf536527842281bea11763fefd77 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.17.0;packages:json_serializable;commands:test_3" @@ -278,20 +286,22 @@ jobs: os:ubuntu-latest;pub-cache-hosted;sdk:2.17.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d + - name: Setup Dart SDK + uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: "2.17.0" - id: checkout - uses: actions/checkout@d0651293c4a5a52e711f25b41b05b2212f385d28 + name: Checkout repository + uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade + run: dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: json_serializable - run: dart pub upgrade - name: "json_serializable; dart test --run-skipped -t presubmit-only test/annotation_version_test.dart" + run: dart test --run-skipped -t presubmit-only test/annotation_version_test.dart if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" working-directory: json_serializable - run: dart test --run-skipped -t presubmit-only test/annotation_version_test.dart needs: - job_001 - job_002 @@ -301,7 +311,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@4504faf7e9bcf8f3ed0bc863c4e1d21499ab8ef8 + uses: actions/cache@fd5de65bc895cf536527842281bea11763fefd77 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.17.0;packages:json_serializable;commands:test_1" @@ -310,20 +320,22 @@ jobs: os:ubuntu-latest;pub-cache-hosted;sdk:2.17.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d + - name: Setup Dart SDK + uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: "2.17.0" - id: checkout - uses: actions/checkout@d0651293c4a5a52e711f25b41b05b2212f385d28 + name: Checkout repository + uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade + run: dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: json_serializable - run: dart pub upgrade - name: "json_serializable; dart test --run-skipped -t presubmit-only test/ensure_build_test.dart" + run: dart test --run-skipped -t presubmit-only test/ensure_build_test.dart if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" working-directory: json_serializable - run: dart test --run-skipped -t presubmit-only test/ensure_build_test.dart needs: - job_001 - job_002 @@ -333,7 +345,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@4504faf7e9bcf8f3ed0bc863c4e1d21499ab8ef8 + uses: actions/cache@fd5de65bc895cf536527842281bea11763fefd77 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.17.0;packages:json_serializable;commands:test_2" @@ -342,20 +354,22 @@ jobs: os:ubuntu-latest;pub-cache-hosted;sdk:2.17.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d + - name: Setup Dart SDK + uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: "2.17.0" - id: checkout - uses: actions/checkout@d0651293c4a5a52e711f25b41b05b2212f385d28 + name: Checkout repository + uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade + run: dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: json_serializable - run: dart pub upgrade - name: "json_serializable; dart test -p chrome" + run: dart test -p chrome if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" working-directory: json_serializable - run: dart test -p chrome needs: - job_001 - job_002 @@ -365,7 +379,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@4504faf7e9bcf8f3ed0bc863c4e1d21499ab8ef8 + uses: actions/cache@fd5de65bc895cf536527842281bea11763fefd77 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" @@ -374,47 +388,49 @@ jobs: os:ubuntu-latest;pub-cache-hosted;sdk:dev os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d + - name: Setup Dart SDK + uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: dev - id: checkout - uses: actions/checkout@d0651293c4a5a52e711f25b41b05b2212f385d28 + name: Checkout repository + uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade + run: dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: _test_yaml - run: dart pub upgrade - name: _test_yaml; dart test + run: dart test if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" working-directory: _test_yaml - run: dart test - id: checked_yaml_pub_upgrade name: checked_yaml; dart pub upgrade + run: dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: checked_yaml - run: dart pub upgrade - name: checked_yaml; dart test + run: dart test if: "always() && steps.checked_yaml_pub_upgrade.conclusion == 'success'" working-directory: checked_yaml - run: dart test - id: example_pub_upgrade name: example; dart pub upgrade + run: dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: example - run: dart pub upgrade - name: example; dart test + run: dart test if: "always() && steps.example_pub_upgrade.conclusion == 'success'" working-directory: example - run: dart test - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade + run: dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: json_serializable - run: dart pub upgrade - name: json_serializable; dart test + run: dart test if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" working-directory: json_serializable - run: dart test needs: - job_001 - job_002 @@ -424,7 +440,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@4504faf7e9bcf8f3ed0bc863c4e1d21499ab8ef8 + uses: actions/cache@fd5de65bc895cf536527842281bea11763fefd77 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:json_serializable;commands:test_3" @@ -433,20 +449,22 @@ jobs: os:ubuntu-latest;pub-cache-hosted;sdk:dev os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d + - name: Setup Dart SDK + uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: dev - id: checkout - uses: actions/checkout@d0651293c4a5a52e711f25b41b05b2212f385d28 + name: Checkout repository + uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade + run: dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: json_serializable - run: dart pub upgrade - name: "json_serializable; dart test --run-skipped -t presubmit-only test/annotation_version_test.dart" + run: dart test --run-skipped -t presubmit-only test/annotation_version_test.dart if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" working-directory: json_serializable - run: dart test --run-skipped -t presubmit-only test/annotation_version_test.dart needs: - job_001 - job_002 @@ -456,7 +474,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@4504faf7e9bcf8f3ed0bc863c4e1d21499ab8ef8 + uses: actions/cache@fd5de65bc895cf536527842281bea11763fefd77 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:json_serializable;commands:test_1" @@ -465,20 +483,22 @@ jobs: os:ubuntu-latest;pub-cache-hosted;sdk:dev os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d + - name: Setup Dart SDK + uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: dev - id: checkout - uses: actions/checkout@d0651293c4a5a52e711f25b41b05b2212f385d28 + name: Checkout repository + uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade + run: dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: json_serializable - run: dart pub upgrade - name: "json_serializable; dart test --run-skipped -t presubmit-only test/ensure_build_test.dart" + run: dart test --run-skipped -t presubmit-only test/ensure_build_test.dart if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" working-directory: json_serializable - run: dart test --run-skipped -t presubmit-only test/ensure_build_test.dart needs: - job_001 - job_002 @@ -488,7 +508,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@4504faf7e9bcf8f3ed0bc863c4e1d21499ab8ef8 + uses: actions/cache@fd5de65bc895cf536527842281bea11763fefd77 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:json_serializable;commands:test_2" @@ -497,20 +517,22 @@ jobs: os:ubuntu-latest;pub-cache-hosted;sdk:dev os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d + - name: Setup Dart SDK + uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: dev - id: checkout - uses: actions/checkout@d0651293c4a5a52e711f25b41b05b2212f385d28 + name: Checkout repository + uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade + run: dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: json_serializable - run: dart pub upgrade - name: "json_serializable; dart test -p chrome" + run: dart test -p chrome if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" working-directory: json_serializable - run: dart test -p chrome needs: - job_001 - job_002 @@ -520,7 +542,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@4504faf7e9bcf8f3ed0bc863c4e1d21499ab8ef8 + uses: actions/cache@fd5de65bc895cf536527842281bea11763fefd77 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.17.0;packages:_test_yaml-checked_yaml-example;commands:test_1" @@ -529,38 +551,40 @@ jobs: os:ubuntu-latest;pub-cache-hosted;sdk:2.17.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d + - name: Setup Dart SDK + uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: "2.17.0" - id: checkout - uses: actions/checkout@d0651293c4a5a52e711f25b41b05b2212f385d28 + name: Checkout repository + uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade + run: dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: _test_yaml - run: dart pub upgrade - name: "_test_yaml; dart test --run-skipped -t presubmit-only test/ensure_build_test.dart" + run: dart test --run-skipped -t presubmit-only test/ensure_build_test.dart if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" working-directory: _test_yaml - run: dart test --run-skipped -t presubmit-only test/ensure_build_test.dart - id: checked_yaml_pub_upgrade name: checked_yaml; dart pub upgrade + run: dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: checked_yaml - run: dart pub upgrade - name: "checked_yaml; dart test --run-skipped -t presubmit-only test/ensure_build_test.dart" + run: dart test --run-skipped -t presubmit-only test/ensure_build_test.dart if: "always() && steps.checked_yaml_pub_upgrade.conclusion == 'success'" working-directory: checked_yaml - run: dart test --run-skipped -t presubmit-only test/ensure_build_test.dart - id: example_pub_upgrade name: example; dart pub upgrade + run: dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: example - run: dart pub upgrade - name: "example; dart test --run-skipped -t presubmit-only test/ensure_build_test.dart" + run: dart test --run-skipped -t presubmit-only test/ensure_build_test.dart if: "always() && steps.example_pub_upgrade.conclusion == 'success'" working-directory: example - run: dart test --run-skipped -t presubmit-only test/ensure_build_test.dart needs: - job_001 - job_002 @@ -578,7 +602,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@4504faf7e9bcf8f3ed0bc863c4e1d21499ab8ef8 + uses: actions/cache@fd5de65bc895cf536527842281bea11763fefd77 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:_test_yaml-checked_yaml-example;commands:test_1" @@ -587,38 +611,40 @@ jobs: os:ubuntu-latest;pub-cache-hosted;sdk:dev os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d + - name: Setup Dart SDK + uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: dev - id: checkout - uses: actions/checkout@d0651293c4a5a52e711f25b41b05b2212f385d28 + name: Checkout repository + uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade + run: dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: _test_yaml - run: dart pub upgrade - name: "_test_yaml; dart test --run-skipped -t presubmit-only test/ensure_build_test.dart" + run: dart test --run-skipped -t presubmit-only test/ensure_build_test.dart if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" working-directory: _test_yaml - run: dart test --run-skipped -t presubmit-only test/ensure_build_test.dart - id: checked_yaml_pub_upgrade name: checked_yaml; dart pub upgrade + run: dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: checked_yaml - run: dart pub upgrade - name: "checked_yaml; dart test --run-skipped -t presubmit-only test/ensure_build_test.dart" + run: dart test --run-skipped -t presubmit-only test/ensure_build_test.dart if: "always() && steps.checked_yaml_pub_upgrade.conclusion == 'success'" working-directory: checked_yaml - run: dart test --run-skipped -t presubmit-only test/ensure_build_test.dart - id: example_pub_upgrade name: example; dart pub upgrade + run: dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: example - run: dart pub upgrade - name: "example; dart test --run-skipped -t presubmit-only test/ensure_build_test.dart" + run: dart test --run-skipped -t presubmit-only test/ensure_build_test.dart if: "always() && steps.example_pub_upgrade.conclusion == 'success'" working-directory: example - run: dart test --run-skipped -t presubmit-only test/ensure_build_test.dart needs: - job_001 - job_002 diff --git a/_test_yaml/mono_pkg.yaml b/_test_yaml/mono_pkg.yaml index fb3857ae3..497ed5d8c 100644 --- a/_test_yaml/mono_pkg.yaml +++ b/_test_yaml/mono_pkg.yaml @@ -1,6 +1,6 @@ # See https://github.com/google/mono_repo.dart for details on this file sdk: -- 2.17.0 +- pubspec - dev stages: diff --git a/analysis_options.yaml b/analysis_options.yaml index eb8ce5989..3c65dfaba 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1,6 +1,9 @@ include: package:lints/recommended.yaml analyzer: + errors: + # TODO: remove when pkg:analyzer v5 is out + deprecated_member_use: ignore language: strict-casts: true diff --git a/checked_yaml/mono_pkg.yaml b/checked_yaml/mono_pkg.yaml index a6d895871..667b27cd5 100644 --- a/checked_yaml/mono_pkg.yaml +++ b/checked_yaml/mono_pkg.yaml @@ -1,6 +1,6 @@ # See https://github.com/google/mono_repo.dart for details on this file sdk: -- 2.17.0 +- pubspec - dev stages: diff --git a/example/mono_pkg.yaml b/example/mono_pkg.yaml index dfe0338ee..158b67b19 100644 --- a/example/mono_pkg.yaml +++ b/example/mono_pkg.yaml @@ -1,6 +1,6 @@ # See https://github.com/google/mono_repo.dart for details on this file sdk: -- 2.17.0 +- pubspec - dev stages: diff --git a/json_annotation/mono_pkg.yaml b/json_annotation/mono_pkg.yaml index 95a6aa9a4..971262031 100644 --- a/json_annotation/mono_pkg.yaml +++ b/json_annotation/mono_pkg.yaml @@ -1,6 +1,6 @@ # See https://github.com/google/mono_repo.dart for details on this file sdk: -- 2.17.0 +- pubspec - dev stages: diff --git a/json_serializable/mono_pkg.yaml b/json_serializable/mono_pkg.yaml index 2743bbb7c..6da59e995 100644 --- a/json_serializable/mono_pkg.yaml +++ b/json_serializable/mono_pkg.yaml @@ -1,6 +1,6 @@ # See https://github.com/google/mono_repo.dart for details on this file sdk: -- 2.17.0 +- pubspec - dev stages: diff --git a/tool/ci.sh b/tool/ci.sh index 2beaee4d7..228f5ad34 100755 --- a/tool/ci.sh +++ b/tool/ci.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Created with package:mono_repo v6.3.0 +# Created with package:mono_repo v6.4.0 # Support built in commands on windows out of the box. # When it is a flutter repo (check the pubspec.yaml for "sdk: flutter") From e30a519bce81d11b57d4e713888eccaef0accf60 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Tue, 13 Sep 2022 12:17:20 -0700 Subject: [PATCH 431/569] latest pkg:analyzer, prepare to publish (#1200) --- analysis_options.yaml | 3 --- example/pubspec.yaml | 4 ++++ json_serializable/CHANGELOG.md | 6 +++--- json_serializable/lib/src/decode_helper.dart | 3 +-- json_serializable/lib/src/enum_utils.dart | 6 +++--- json_serializable/lib/src/field_helpers.dart | 12 ++++++------ json_serializable/lib/src/helper_core.dart | 2 +- .../lib/src/json_enum_generator.dart | 2 +- json_serializable/lib/src/json_key_utils.dart | 6 +++--- .../lib/src/json_serializable_generator.dart | 2 +- .../src/type_helpers/json_converter_helper.dart | 14 +++++++------- .../lib/src/type_helpers/json_helper.dart | 16 ++++++++-------- json_serializable/lib/src/utils.dart | 11 ++++++----- json_serializable/pubspec.yaml | 4 ++-- 14 files changed, 46 insertions(+), 45 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index 3c65dfaba..eb8ce5989 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1,9 +1,6 @@ include: package:lints/recommended.yaml analyzer: - errors: - # TODO: remove when pkg:analyzer v5 is out - deprecated_member_use: ignore language: strict-casts: true diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 2bf5ecaba..cce74537f 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -22,3 +22,7 @@ dev_dependencies: lints: ^2.0.0 path: ^1.8.0 test: ^1.16.0 + +dependency_overrides: + json_serializable: + path: ../json_serializable diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 38eed7b16..e342b6da9 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,7 +1,7 @@ -## 6.3.2-dev +## 6.3.2 -- Require Dart SDK 2.17 -- Require package:analyzer >=4.3.1 +- Require `analyzer: '>=4.6.0 <6.0.0'` +- Require `sdk: '>=2.17.0 <3.0.0'` ## 6.3.1 diff --git a/json_serializable/lib/src/decode_helper.dart b/json_serializable/lib/src/decode_helper.dart index 341446b92..e446e0047 100644 --- a/json_serializable/lib/src/decode_helper.dart +++ b/json_serializable/lib/src/decode_helper.dart @@ -278,8 +278,7 @@ _ConstructorData _writeConstructorInvocation( for (final arg in ctor.parameters) { if (!availableConstructorParameters.contains(arg.name)) { - // ignore: deprecated_member_use - if (arg.isNotOptional) { + if (arg.isRequired) { var msg = 'Cannot populate the required constructor ' 'argument: ${arg.name}.'; diff --git a/json_serializable/lib/src/enum_utils.dart b/json_serializable/lib/src/enum_utils.dart index 769db154c..f302814f5 100644 --- a/json_serializable/lib/src/enum_utils.dart +++ b/json_serializable/lib/src/enum_utils.dart @@ -12,13 +12,13 @@ import 'json_literal_generator.dart'; import 'utils.dart'; String constMapName(DartType targetType) => - '_\$${targetType.element!.name}EnumMap'; + '_\$${targetType.element2!.name}EnumMap'; String? enumValueMapFromType( DartType targetType, { bool nullWithNoAnnotation = false, }) { - final annotation = _jsonEnumChecker.firstAnnotationOf(targetType.element!); + final annotation = _jsonEnumChecker.firstAnnotationOf(targetType.element2!); final jsonEnum = _fromAnnotation(annotation); final enumFields = iterateEnumFields(targetType); @@ -59,7 +59,7 @@ String? enumValueMapFromType( Map<FieldElement, dynamic>.fromEntries(enumFields.map(generateEntry)); final items = enumMap.entries - .map((e) => ' ${targetType.element!.name}.${e.key.name}: ' + .map((e) => ' ${targetType.element2!.name}.${e.key.name}: ' '${jsonLiteralAsDart(e.value)},') .join(); diff --git a/json_serializable/lib/src/field_helpers.dart b/json_serializable/lib/src/field_helpers.dart index 9ae68c8c2..d07f45d2e 100644 --- a/json_serializable/lib/src/field_helpers.dart +++ b/json_serializable/lib/src/field_helpers.dart @@ -37,20 +37,20 @@ class _FieldSet implements Comparable<_FieldSet> { static int _sortByLocation(FieldElement a, FieldElement b) { final checkerA = - TypeChecker.fromStatic((a.enclosingElement2 as ClassElement).thisType); + TypeChecker.fromStatic((a.enclosingElement3 as ClassElement).thisType); - if (!checkerA.isExactly(b.enclosingElement2)) { + if (!checkerA.isExactly(b.enclosingElement3)) { // in this case, you want to prioritize the enclosingElement that is more // "super". - if (checkerA.isAssignableFrom(b.enclosingElement2)) { + if (checkerA.isAssignableFrom(b.enclosingElement3)) { return -1; } final checkerB = TypeChecker.fromStatic( - (b.enclosingElement2 as ClassElement).thisType); + (b.enclosingElement3 as InterfaceElement).thisType); - if (checkerB.isAssignableFrom(a.enclosingElement2)) { + if (checkerB.isAssignableFrom(a.enclosingElement3)) { return 1; } } @@ -82,7 +82,7 @@ Iterable<FieldElement> createSortedFieldSet(ClassElement element) { for (final v in manager.getInheritedConcreteMap2(element).values) { assert(v is! FieldElement); - if (_dartCoreObjectChecker.isExactly(v.enclosingElement2)) { + if (_dartCoreObjectChecker.isExactly(v.enclosingElement3)) { continue; } diff --git a/json_serializable/lib/src/helper_core.dart b/json_serializable/lib/src/helper_core.dart index 700cab2b3..d7540668b 100644 --- a/json_serializable/lib/src/helper_core.dart +++ b/json_serializable/lib/src/helper_core.dart @@ -78,7 +78,7 @@ $converterOrKeyInstructions message = '$message because of type `${typeToCode(error.type)}`'; } else { todo = ''' -To support the type `${error.type.element!.name}` you can: +To support the type `${error.type.element2!.name}` you can: $converterOrKeyInstructions'''; } diff --git a/json_serializable/lib/src/json_enum_generator.dart b/json_serializable/lib/src/json_enum_generator.dart index 171df15b1..e72657add 100644 --- a/json_serializable/lib/src/json_enum_generator.dart +++ b/json_serializable/lib/src/json_enum_generator.dart @@ -18,7 +18,7 @@ class JsonEnumGenerator extends GeneratorForAnnotation<JsonEnum> { ConstantReader annotation, BuildStep buildStep, ) { - if (element is! ClassElement || !element.isEnum) { + if (element is! EnumElement) { throw InvalidGenerationSourceError( '`@JsonEnum` can only be used on enum elements.', element: element, diff --git a/json_serializable/lib/src/json_key_utils.dart b/json_serializable/lib/src/json_key_utils.dart index b309be16d..aaed19799 100644 --- a/json_serializable/lib/src/json_key_utils.dart +++ b/json_serializable/lib/src/json_key_utils.dart @@ -61,7 +61,7 @@ KeyConfig _from(FieldElement element, ClassConfig classAnnotation) { // TODO: Support calling function for the default value? badType = 'Function'; } else if (!reader.isLiteral) { - badType = dartObject.type!.element!.name; + badType = dartObject.type!.element2!.name; } if (badType != null) { @@ -173,7 +173,7 @@ KeyConfig _from(FieldElement element, ClassConfig classAnnotation) { final enumValueName = enumValueForDartObject<String>( annotationValue.objectValue, enumValueNames, (n) => n); - return '${annotationType.element!.name}' + return '${annotationType.element2!.name}' '.$enumValueName'; } else { final defaultValueLiteral = annotationValue.isNull @@ -280,7 +280,7 @@ bool _includeIfNull( bool _interfaceTypesEqual(DartType a, DartType b) { if (a is InterfaceType && b is InterfaceType) { // Handle nullability case. Pretty sure this is fine for enums. - return a.element == b.element; + return a.element2 == b.element2; } return a == b; } diff --git a/json_serializable/lib/src/json_serializable_generator.dart b/json_serializable/lib/src/json_serializable_generator.dart index 69ead4939..611056131 100644 --- a/json_serializable/lib/src/json_serializable_generator.dart +++ b/json_serializable/lib/src/json_serializable_generator.dart @@ -69,7 +69,7 @@ class JsonSerializableGenerator ); } - if (element is! ClassElement || element.isEnum) { + if (element is! ClassElement || element is EnumElement) { throw InvalidGenerationSourceError( '`@JsonSerializable` can only be used on classes.', element: element, diff --git a/json_serializable/lib/src/type_helpers/json_converter_helper.dart b/json_serializable/lib/src/type_helpers/json_converter_helper.dart index d0f19750a..37523f42a 100644 --- a/json_serializable/lib/src/type_helpers/json_converter_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_converter_helper.dart @@ -199,7 +199,7 @@ _JsonConvertData? _typeConverterFrom( final annotationElement = match.elementAnnotation?.element; if (annotationElement is PropertyAccessorElement) { - final enclosing = annotationElement.enclosingElement2; + final enclosing = annotationElement.enclosingElement3; var accessString = annotationElement.name; @@ -226,7 +226,7 @@ _JsonConvertData? _typeConverterFrom( if (match.genericTypeArg != null) { return _JsonConvertData.genericClass( - match.annotation.type!.element!.name!, + match.annotation.type!.element2!.name!, match.genericTypeArg!, reviver.accessor, match.jsonType, @@ -235,7 +235,7 @@ _JsonConvertData? _typeConverterFrom( } return _JsonConvertData.className( - match.annotation.type!.element!.name!, + match.annotation.type!.element2!.name!, reviver.accessor, match.jsonType, match.fieldType, @@ -263,18 +263,18 @@ _ConverterMatch? _compatibleMatch( ElementAnnotation? annotation, DartObject constantValue, ) { - final converterClassElement = constantValue.type!.element as ClassElement; + final converterClassElement = constantValue.type!.element2 as ClassElement; final jsonConverterSuper = converterClassElement.allSupertypes.singleWhereOrNull( - (e) => _jsonConverterChecker.isExactly(e.element), + (e) => _jsonConverterChecker.isExactly(e.element2), ); if (jsonConverterSuper == null) { return null; } - assert(jsonConverterSuper.element.typeParameters.length == 2); + assert(jsonConverterSuper.element2.typeParameters.length == 2); assert(jsonConverterSuper.typeArguments.length == 2); final fieldType = jsonConverterSuper.typeArguments[0]; @@ -305,7 +305,7 @@ _ConverterMatch? _compatibleMatch( annotation, constantValue, jsonConverterSuper.typeArguments[1], - '${targetType.element.name}${targetType.isNullableType ? '?' : ''}', + '${targetType.element2.name}${targetType.isNullableType ? '?' : ''}', fieldType, ); } diff --git a/json_serializable/lib/src/type_helpers/json_helper.dart b/json_serializable/lib/src/type_helpers/json_helper.dart index e61ed9f90..426c77d14 100644 --- a/json_serializable/lib/src/type_helpers/json_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_helper.dart @@ -76,7 +76,7 @@ class JsonHelper extends TypeHelper<TypeHelperContextWithConfig> { return null; } - final classElement = targetType.element; + final classElement = targetType.element2; final fromJsonCtor = classElement.constructors .singleWhereOrNull((ce) => ce.name == 'fromJson'); @@ -152,7 +152,7 @@ List<String> _helperParams( for (var helperArg in rest) { final typeParamIndex = - type.element.typeParameters.indexOf(helperArg.element); + type.element2.typeParameters.indexOf(helperArg.element2); // TODO: throw here if `typeParamIndex` is -1 ? final typeArg = type.typeArguments[typeParamIndex]; @@ -174,7 +174,7 @@ TypeParameterType _decodeHelper( type.normalParameterTypes.length == 1) { final funcReturnType = type.returnType; - if (param.name == fromJsonForName(funcReturnType.element!.name!)) { + if (param.name == fromJsonForName(funcReturnType.element2!.name!)) { final funcParamType = type.normalParameterTypes.single; if ((funcParamType.isDartCoreObject && funcParamType.isNullableType) || @@ -205,7 +205,7 @@ TypeParameterType _encodeHelper( type.normalParameterTypes.length == 1) { final funcParamType = type.normalParameterTypes.single; - if (param.name == toJsonForName(funcParamType.element!.name!)) { + if (param.name == toJsonForName(funcParamType.element2!.name!)) { if (funcParamType is TypeParameterType) { return funcParamType; } @@ -245,7 +245,7 @@ InterfaceType? _instantiate( InterfaceType classType, ) { final argTypes = ctorParamType.typeArguments.map((arg) { - final typeParamIndex = classType.element.typeParameters.indexWhere( + final typeParamIndex = classType.element2.typeParameters.indexWhere( // TODO: not 100% sure `nullabilitySuffix` is right (e) => e.instantiate(nullabilitySuffix: arg.nullabilitySuffix) == arg); if (typeParamIndex >= 0) { @@ -261,7 +261,7 @@ InterfaceType? _instantiate( return null; } - return ctorParamType.element.instantiate( + return ctorParamType.element2.instantiate( typeArguments: argTypes.cast<DartType>(), // TODO: not 100% sure nullabilitySuffix is right... Works for now nullabilitySuffix: NullabilitySuffix.none, @@ -273,7 +273,7 @@ ClassConfig? _annotation(ClassConfig config, InterfaceType source) { return null; } final annotations = const TypeChecker.fromRuntime(JsonSerializable) - .annotationsOfExact(source.element, throwOnUnresolved: false) + .annotationsOfExact(source.element2, throwOnUnresolved: false) .toList(); if (annotations.isEmpty) { @@ -283,7 +283,7 @@ ClassConfig? _annotation(ClassConfig config, InterfaceType source) { return mergeConfig( config, ConstantReader(annotations.single), - classElement: source.element, + classElement: source.element2 as ClassElement, ); } diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index d4c2afcb5..727b6f0d0 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -160,15 +160,16 @@ ConstructorElement constructorByName(ClassElement classElement, String name) { /// /// Otherwise, `null`. Iterable<FieldElement>? iterateEnumFields(DartType targetType) { - if (targetType is InterfaceType && targetType.element.isEnum) { - return targetType.element.fields.where((element) => element.isEnumConstant); + if (targetType is InterfaceType && targetType.element2 is EnumElement) { + return targetType.element2.fields + .where((element) => element.isEnumConstant); } return null; } extension DartTypeExtension on DartType { DartType promoteNonNullable() => - element?.library?.typeSystem.promoteToNonNull(this) ?? this; + element2?.library?.typeSystem.promoteToNonNull(this) ?? this; } String ifNullOrElse(String test, String ifNull, String ifNotNull) => @@ -206,7 +207,7 @@ String typeToCode( return 'dynamic'; } else if (type is InterfaceType) { return [ - type.element.name, + type.element2.name, if (type.typeArguments.isNotEmpty) '<${type.typeArguments.map(typeToCode).join(', ')}>', (type.isNullableType || forceNullable) ? '?' : '', @@ -228,7 +229,7 @@ extension ExecutableElementExtension on ExecutableElement { } if (this is MethodElement) { - return '${enclosingElement2.name}.$name'; + return '${enclosingElement3.name}.$name'; } throw UnsupportedError( diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 61f557eae..f3bfc1b0e 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 6.3.2-dev +version: 6.3.2 description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. @@ -8,7 +8,7 @@ environment: sdk: '>=2.17.0 <3.0.0' dependencies: - analyzer: '>=4.3.1 <5.0.0' + analyzer: '>=4.6.0 <6.0.0' async: ^2.8.0 build: ^2.0.0 build_config: '>=0.4.4 <2.0.0' From 572e8133ab5a8cfc17f5855899cf2a3e9cd74548 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Mon, 19 Sep 2022 14:13:21 -0700 Subject: [PATCH 432/569] json_serialiable: fix bug with pkg:build output in test (#1201) --- json_serializable/test/annotation_version_test.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/json_serializable/test/annotation_version_test.dart b/json_serializable/test/annotation_version_test.dart index 99af55588..1ff0b4d62 100644 --- a/json_serializable/test/annotation_version_test.dart +++ b/json_serializable/test/annotation_version_test.dart @@ -173,7 +173,7 @@ class SomeClass{} } expect(lines.toString(), contains(''' -[WARNING] json_serializable:json_serializable on $sourceDirectory/sample.dart: +[WARNING] json_serializable on $sourceDirectory/sample.dart: $message''')); await proc.shouldExit(0); From 9143b83918e4af5c5e60e35ac16ee106991196e2 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Tue, 20 Sep 2022 14:55:55 -0700 Subject: [PATCH 433/569] Add JsonEnum.valueField for encoding enhanced enum values (#1203) Fixes https://github.com/google/json_serializable.dart/issues/1147 Prepare to release json_annotation v4.7.0 --- example/pubspec.yaml | 2 + json_annotation/CHANGELOG.md | 5 +- json_annotation/lib/src/json_enum.dart | 8 +++ json_annotation/pubspec.yaml | 2 +- json_serializable/CHANGELOG.md | 7 +++ json_serializable/README.md | 16 ++--- .../lib/src/check_dependencies.dart | 2 +- json_serializable/lib/src/enum_utils.dart | 58 ++++++++++++++---- json_serializable/pubspec.yaml | 8 ++- .../test/integration/json_enum_example.dart | 13 ++++ .../test/integration/json_enum_example.g.dart | 5 ++ .../test/json_serializable_test.dart | 8 ++- .../test/src/_json_enum_test_input.dart | 61 +++++++++++++++++++ 13 files changed, 170 insertions(+), 25 deletions(-) diff --git a/example/pubspec.yaml b/example/pubspec.yaml index cce74537f..eb251f41f 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -24,5 +24,7 @@ dev_dependencies: test: ^1.16.0 dependency_overrides: + json_annotation: + path: ../json_annotation json_serializable: path: ../json_serializable diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index 0fdf4e642..e571f85f5 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -1,5 +1,8 @@ -## 4.6.1-dev +## 4.7.0 +- Added `JsonEnum.valueField` which allows specifying a field in an + "enhanced enum" to use for serialization instead of specifying each value + individually with `JsonValue`. - Require Dart SDK 2.17 ## 4.6.0 diff --git a/json_annotation/lib/src/json_enum.dart b/json_annotation/lib/src/json_enum.dart index 0d186a184..27d1fb5bc 100644 --- a/json_annotation/lib/src/json_enum.dart +++ b/json_annotation/lib/src/json_enum.dart @@ -13,6 +13,7 @@ class JsonEnum { const JsonEnum({ this.alwaysCreate = false, this.fieldRename = FieldRename.none, + this.valueField, }); /// If `true`, `_$[enum name]EnumMap` is generated for in library containing @@ -34,4 +35,11 @@ class JsonEnum { /// Note: the value for [JsonValue.value] takes precedence over this option /// for entries annotated with [JsonValue]. final FieldRename fieldRename; + + /// 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; } diff --git a/json_annotation/pubspec.yaml b/json_annotation/pubspec.yaml index 6b019fcb4..e80442751 100644 --- a/json_annotation/pubspec.yaml +++ b/json_annotation/pubspec.yaml @@ -1,5 +1,5 @@ name: json_annotation -version: 4.6.1-dev +version: 4.7.0 description: >- Classes and helper functions that support JSON code generation via the `json_serializable` package. diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index e342b6da9..865886e4d 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,10 @@ +## 6.4.0 + +- Add support for `JsonEnum.valueField` which 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'` diff --git a/json_serializable/README.md b/json_serializable/README.md index fd568cae1..34e874147 100644 --- a/json_serializable/README.md +++ b/json_serializable/README.md @@ -200,14 +200,14 @@ targets: [`Enum`]: https://api.dart.dev/stable/dart-core/Enum-class.html [`int`]: https://api.dart.dev/stable/dart-core/int-class.html [`Iterable`]: https://api.dart.dev/stable/dart-core/Iterable-class.html -[`JsonConverter`]: https://pub.dev/documentation/json_annotation/4.6.0/json_annotation/JsonConverter-class.html -[`JsonEnum`]: https://pub.dev/documentation/json_annotation/4.6.0/json_annotation/JsonEnum-class.html -[`JsonKey.fromJson`]: https://pub.dev/documentation/json_annotation/4.6.0/json_annotation/JsonKey/fromJson.html -[`JsonKey.toJson`]: https://pub.dev/documentation/json_annotation/4.6.0/json_annotation/JsonKey/toJson.html -[`JsonKey`]: https://pub.dev/documentation/json_annotation/4.6.0/json_annotation/JsonKey-class.html -[`JsonLiteral`]: https://pub.dev/documentation/json_annotation/4.6.0/json_annotation/JsonLiteral-class.html -[`JsonSerializable`]: https://pub.dev/documentation/json_annotation/4.6.0/json_annotation/JsonSerializable-class.html -[`JsonValue`]: https://pub.dev/documentation/json_annotation/4.6.0/json_annotation/JsonValue-class.html +[`JsonConverter`]: https://pub.dev/documentation/json_annotation/4.7.0/json_annotation/JsonConverter-class.html +[`JsonEnum`]: https://pub.dev/documentation/json_annotation/4.7.0/json_annotation/JsonEnum-class.html +[`JsonKey.fromJson`]: https://pub.dev/documentation/json_annotation/4.7.0/json_annotation/JsonKey/fromJson.html +[`JsonKey.toJson`]: https://pub.dev/documentation/json_annotation/4.7.0/json_annotation/JsonKey/toJson.html +[`JsonKey`]: https://pub.dev/documentation/json_annotation/4.7.0/json_annotation/JsonKey-class.html +[`JsonLiteral`]: https://pub.dev/documentation/json_annotation/4.7.0/json_annotation/JsonLiteral-class.html +[`JsonSerializable`]: https://pub.dev/documentation/json_annotation/4.7.0/json_annotation/JsonSerializable-class.html +[`JsonValue`]: https://pub.dev/documentation/json_annotation/4.7.0/json_annotation/JsonValue-class.html [`List`]: https://api.dart.dev/stable/dart-core/List-class.html [`Map`]: https://api.dart.dev/stable/dart-core/Map-class.html [`num`]: https://api.dart.dev/stable/dart-core/num-class.html diff --git a/json_serializable/lib/src/check_dependencies.dart b/json_serializable/lib/src/check_dependencies.dart index 873be904a..835be668a 100644 --- a/json_serializable/lib/src/check_dependencies.dart +++ b/json_serializable/lib/src/check_dependencies.dart @@ -10,7 +10,7 @@ import 'package:pubspec_parse/pubspec_parse.dart'; const _productionDirectories = {'lib', 'bin'}; const _annotationPkgName = 'json_annotation'; -final requiredJsonAnnotationMinVersion = Version.parse('4.6.0'); +final requiredJsonAnnotationMinVersion = Version.parse('4.7.0'); Future<void> pubspecHasRightVersion(BuildStep buildStep) async { final segments = buildStep.inputId.pathSegments; diff --git a/json_serializable/lib/src/enum_utils.dart b/json_serializable/lib/src/enum_utils.dart index f302814f5..4128993b5 100644 --- a/json_serializable/lib/src/enum_utils.dart +++ b/json_serializable/lib/src/enum_utils.dart @@ -33,20 +33,50 @@ String? enumValueMapFromType( dynamic fieldValue; if (annotation == null) { - fieldValue = encodedFieldName(jsonEnum.fieldRename, fe.name); + if (jsonEnum.valueField != null) { + // TODO: fieldRename is pointless here!!! At least log a warning! + + final fieldElementType = fe.type.element2 as EnumElement; + + final e = fieldElementType.getField(jsonEnum.valueField!); + + if (e == null || e.isStatic) { + throw InvalidGenerationSourceError( + '`JsonEnum.valueField` was set to "${jsonEnum.valueField}", but ' + 'that is not a valid, instance field on ' + '`${typeToCode(targetType)}`.', + element: targetType.element2, + ); + } + + final reader = ConstantReader(fe.computeConstantValue()); + final valueReader = reader.read(jsonEnum.valueField!); + if (valueReader.validValueType) { + fieldValue = valueReader.literalValue; + } else { + throw InvalidGenerationSourceError( + '`JsonEnum.valueField` was set to "${jsonEnum.valueField}", but ' + 'that field does not have a type of String, int, or null.', + element: targetType.element2, + ); + } + } else { + fieldValue = encodedFieldName(jsonEnum.fieldRename, fe.name); + } } else { final reader = ConstantReader(annotation); final valueReader = reader.read('value'); - if (valueReader.isString || valueReader.isNull || valueReader.isInt) { + if (valueReader.validValueType) { fieldValue = valueReader.literalValue; } else { final targetTypeCode = typeToCode(targetType); throw InvalidGenerationSourceError( - 'The `JsonValue` annotation on `$targetTypeCode.${fe.name}` does ' - 'not have a value of type String, int, or null.', - element: fe); + 'The `JsonValue` annotation on `$targetTypeCode.${fe.name}` does ' + 'not have a value of type String, int, or null.', + element: fe, + ); } } @@ -74,10 +104,16 @@ JsonEnum _fromAnnotation(DartObject? dartObject) { } final reader = ConstantReader(dartObject); return JsonEnum( - alwaysCreate: reader.read('alwaysCreate').literalValue as bool, - fieldRename: enumValueForDartObject( - reader.read('fieldRename').objectValue, - FieldRename.values, - (f) => f.toString().split('.')[1], - )); + alwaysCreate: reader.read('alwaysCreate').literalValue as bool, + fieldRename: enumValueForDartObject( + reader.read('fieldRename').objectValue, + FieldRename.values, + (f) => f.toString().split('.')[1], + ), + valueField: reader.read('valueField').literalValue as String?, + ); +} + +extension on ConstantReader { + bool get validValueType => isString || isNull || isInt; } diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index f3bfc1b0e..2c51c6fb1 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 6.3.2 +version: 6.4.0-dev description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. @@ -16,7 +16,7 @@ dependencies: # Use a tight version constraint to ensure that a constraint on # `json_annotation` properly constrains all features it provides. - json_annotation: '>=4.6.0 <4.7.0' + json_annotation: '>=4.7.0 <4.8.0' meta: ^1.3.0 path: ^1.8.0 pub_semver: ^2.0.0 @@ -37,3 +37,7 @@ dev_dependencies: test_descriptor: ^2.0.0 test_process: ^2.0.0 yaml: ^3.0.0 + +dependency_overrides: + json_annotation: + path: ../json_annotation diff --git a/json_serializable/test/integration/json_enum_example.dart b/json_serializable/test/integration/json_enum_example.dart index 90f6e2006..a2a29bde9 100644 --- a/json_serializable/test/integration/json_enum_example.dart +++ b/json_serializable/test/integration/json_enum_example.dart @@ -25,6 +25,19 @@ enum DayType { Iterable<String> get dayTypeEnumValues => _$DayTypeEnumMap.values; +@JsonEnum(alwaysCreate: true, valueField: 'value') +enum MyStatusCode { + success(200), + @JsonValue(701) // explicit value always takes precedence + weird(601); + + const MyStatusCode(this.value); + + final int value; +} + +Iterable<int> get myStatusCodeEnumValues => _$MyStatusCodeEnumMap.values; + @JsonSerializable( createToJson: false, ) diff --git a/json_serializable/test/integration/json_enum_example.g.dart b/json_serializable/test/integration/json_enum_example.g.dart index 609cdd9c9..946fe263f 100644 --- a/json_serializable/test/integration/json_enum_example.g.dart +++ b/json_serializable/test/integration/json_enum_example.g.dart @@ -59,3 +59,8 @@ const _$DayTypeEnumMap = { DayType.rotten: 'rotten', DayType.veryBad: 'very-bad', }; + +const _$MyStatusCodeEnumMap = { + MyStatusCode.success: 200, + MyStatusCode.weird: 701, +}; diff --git a/json_serializable/test/json_serializable_test.dart b/json_serializable/test/json_serializable_test.dart index ef5e38e01..cf4962e43 100644 --- a/json_serializable/test/json_serializable_test.dart +++ b/json_serializable/test/json_serializable_test.dart @@ -29,7 +29,13 @@ Future<void> main() async { testAnnotatedElements( jsonEnumTestReader, const JsonEnumGenerator(), - expectedAnnotatedTests: {'UnsupportedClass'}, + expectedAnnotatedTests: { + 'EnumValueIssue1147', + 'EnumValueNotAField', + 'EnumValueNotSupportType', + 'EnumValueWeirdField', + 'UnsupportedClass', + }, ); } diff --git a/json_serializable/test/src/_json_enum_test_input.dart b/json_serializable/test/src/_json_enum_test_input.dart index bf3f96050..594229f7b 100644 --- a/json_serializable/test/src/_json_enum_test_input.dart +++ b/json_serializable/test/src/_json_enum_test_input.dart @@ -5,6 +5,67 @@ import 'package:json_annotation/json_annotation.dart'; import 'package:source_gen_test/annotations.dart'; +@ShouldGenerate(r''' +const _$EnumValueIssue1147EnumMap = { + EnumValueIssue1147.success: 200, + EnumValueIssue1147.weird: 601, +}; +''') +@JsonEnum(alwaysCreate: true, valueField: 'statusCodeNumber') +enum EnumValueIssue1147 { + success(200), + @JsonValue(601) + weird(701); + + const EnumValueIssue1147(this.statusCodeNumber); + + final int statusCodeNumber; +} + +@ShouldThrow( + '`JsonEnum.valueField` was set to "notAField", but that is not a valid, ' + 'instance field on `EnumValueNotAField`.', +) +@JsonEnum(alwaysCreate: true, valueField: 'notAField') +enum EnumValueNotAField { + success(200), + @JsonValue(601) + weird(701); + + const EnumValueNotAField(this.statusCodeNumber); + + final int statusCodeNumber; +} + +@ShouldThrow( + '`JsonEnum.valueField` was set to "symbolWeird", but that field does not ' + 'have a type of String, int, or null.', +) +@JsonEnum(alwaysCreate: true, valueField: 'symbolWeird') +enum EnumValueNotSupportType { + success(#success), + @JsonValue(601) + weird(#weird); + + const EnumValueNotSupportType(this.symbolWeird); + + final Symbol symbolWeird; +} + +@ShouldThrow( + '`JsonEnum.valueField` was set to "values", but that is not a valid, ' + 'instance field on `EnumValueWeirdField`.', +) +@JsonEnum(alwaysCreate: true, valueField: 'values') +enum EnumValueWeirdField { + success(200), + weird(701); + + const EnumValueWeirdField(this.something); + + final int something; +} + @ShouldThrow('`@JsonEnum` can only be used on enum elements.') @JsonEnum() // ignore: invalid_annotation_target class UnsupportedClass {} From 52236b0b021a85ba654a1b3216ebbe03ce7d713b Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Tue, 20 Sep 2022 16:35:09 -0700 Subject: [PATCH 434/569] json_serializable: refactor enum logic (#1204) Refactor a function into to functions Simplify the return value --- json_serializable/lib/src/enum_utils.dart | 117 +++++++++++----------- 1 file changed, 61 insertions(+), 56 deletions(-) diff --git a/json_serializable/lib/src/enum_utils.dart b/json_serializable/lib/src/enum_utils.dart index 4128993b5..98a3fef30 100644 --- a/json_serializable/lib/src/enum_utils.dart +++ b/json_serializable/lib/src/enum_utils.dart @@ -27,73 +27,78 @@ String? enumValueMapFromType( return null; } - MapEntry<FieldElement, dynamic> generateEntry(FieldElement fe) { - final annotation = - const TypeChecker.fromRuntime(JsonValue).firstAnnotationOfExact(fe); - - dynamic fieldValue; - if (annotation == null) { - if (jsonEnum.valueField != null) { - // TODO: fieldRename is pointless here!!! At least log a warning! - - final fieldElementType = fe.type.element2 as EnumElement; - - final e = fieldElementType.getField(jsonEnum.valueField!); - - if (e == null || e.isStatic) { - throw InvalidGenerationSourceError( - '`JsonEnum.valueField` was set to "${jsonEnum.valueField}", but ' - 'that is not a valid, instance field on ' - '`${typeToCode(targetType)}`.', - element: targetType.element2, - ); - } - - final reader = ConstantReader(fe.computeConstantValue()); - final valueReader = reader.read(jsonEnum.valueField!); - if (valueReader.validValueType) { - fieldValue = valueReader.literalValue; - } else { - throw InvalidGenerationSourceError( - '`JsonEnum.valueField` was set to "${jsonEnum.valueField}", but ' - 'that field does not have a type of String, int, or null.', - element: targetType.element2, - ); - } - } else { - fieldValue = encodedFieldName(jsonEnum.fieldRename, fe.name); - } - } else { - final reader = ConstantReader(annotation); + final enumMap = { + for (var field in enumFields) + field: generateEntry( + field: field, + jsonEnum: jsonEnum, + targetType: targetType, + ), + }; + + final items = enumMap.entries + .map((e) => ' ${targetType.element2!.name}.${e.key.name}: ' + '${jsonLiteralAsDart(e.value)},') + .join(); + + return 'const ${constMapName(targetType)} = {\n$items\n};'; +} + +Object? generateEntry({ + required FieldElement field, + required JsonEnum jsonEnum, + required DartType targetType, +}) { + final annotation = + const TypeChecker.fromRuntime(JsonValue).firstAnnotationOfExact(field); + + if (annotation == null) { + if (jsonEnum.valueField != null) { + // TODO: fieldRename is pointless here!!! At least log a warning! + + final fieldElementType = field.type.element2 as EnumElement; - final valueReader = reader.read('value'); + final e = fieldElementType.getField(jsonEnum.valueField!); + if (e == null || e.isStatic) { + throw InvalidGenerationSourceError( + '`JsonEnum.valueField` was set to "${jsonEnum.valueField}", but ' + 'that is not a valid, instance field on ' + '`${typeToCode(targetType)}`.', + element: targetType.element2, + ); + } + + final reader = ConstantReader(field.computeConstantValue()); + final valueReader = reader.read(jsonEnum.valueField!); if (valueReader.validValueType) { - fieldValue = valueReader.literalValue; + return valueReader.literalValue; } else { - final targetTypeCode = typeToCode(targetType); throw InvalidGenerationSourceError( - 'The `JsonValue` annotation on `$targetTypeCode.${fe.name}` does ' - 'not have a value of type String, int, or null.', - element: fe, + '`JsonEnum.valueField` was set to "${jsonEnum.valueField}", but ' + 'that field does not have a type of String, int, or null.', + element: targetType.element2, ); } + } else { + return encodedFieldName(jsonEnum.fieldRename, field.name); } + } else { + final reader = ConstantReader(annotation); - final entry = MapEntry(fe, fieldValue); + final valueReader = reader.read('value'); - return entry; + if (valueReader.validValueType) { + return valueReader.literalValue; + } else { + final targetTypeCode = typeToCode(targetType); + throw InvalidGenerationSourceError( + 'The `JsonValue` annotation on `$targetTypeCode.${field.name}` does ' + 'not have a value of type String, int, or null.', + element: field, + ); + } } - - final enumMap = - Map<FieldElement, dynamic>.fromEntries(enumFields.map(generateEntry)); - - final items = enumMap.entries - .map((e) => ' ${targetType.element2!.name}.${e.key.name}: ' - '${jsonLiteralAsDart(e.value)},') - .join(); - - return 'const ${constMapName(targetType)} = {\n$items\n};'; } const _jsonEnumChecker = TypeChecker.fromRuntime(JsonEnum); From 12414e0567f9c482bdef1b62384bc40a41500911 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@google.com> Date: Tue, 20 Sep 2022 16:43:46 -0700 Subject: [PATCH 435/569] json_serialiable: make utility function private --- json_serializable/lib/src/enum_utils.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/json_serializable/lib/src/enum_utils.dart b/json_serializable/lib/src/enum_utils.dart index 98a3fef30..9e6dfc480 100644 --- a/json_serializable/lib/src/enum_utils.dart +++ b/json_serializable/lib/src/enum_utils.dart @@ -29,7 +29,7 @@ String? enumValueMapFromType( final enumMap = { for (var field in enumFields) - field: generateEntry( + field: _generateEntry( field: field, jsonEnum: jsonEnum, targetType: targetType, @@ -44,7 +44,7 @@ String? enumValueMapFromType( return 'const ${constMapName(targetType)} = {\n$items\n};'; } -Object? generateEntry({ +Object? _generateEntry({ required FieldElement field, required JsonEnum jsonEnum, required DartType targetType, From feadf4ce4107427c82d830ac535c607fef266921 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Tue, 20 Sep 2022 17:06:33 -0700 Subject: [PATCH 436/569] json_serializable: more enum util cleanup (#1205) Use a field to avoid extra null checks and {} is String interpolation --- json_serializable/lib/src/enum_utils.dart | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/json_serializable/lib/src/enum_utils.dart b/json_serializable/lib/src/enum_utils.dart index 9e6dfc480..61ed15721 100644 --- a/json_serializable/lib/src/enum_utils.dart +++ b/json_serializable/lib/src/enum_utils.dart @@ -53,16 +53,17 @@ Object? _generateEntry({ const TypeChecker.fromRuntime(JsonValue).firstAnnotationOfExact(field); if (annotation == null) { - if (jsonEnum.valueField != null) { + final valueField = jsonEnum.valueField; + if (valueField != null) { // TODO: fieldRename is pointless here!!! At least log a warning! final fieldElementType = field.type.element2 as EnumElement; - final e = fieldElementType.getField(jsonEnum.valueField!); + final e = fieldElementType.getField(valueField); if (e == null || e.isStatic) { throw InvalidGenerationSourceError( - '`JsonEnum.valueField` was set to "${jsonEnum.valueField}", but ' + '`JsonEnum.valueField` was set to "$valueField", but ' 'that is not a valid, instance field on ' '`${typeToCode(targetType)}`.', element: targetType.element2, @@ -70,12 +71,12 @@ Object? _generateEntry({ } final reader = ConstantReader(field.computeConstantValue()); - final valueReader = reader.read(jsonEnum.valueField!); + final valueReader = reader.read(valueField); if (valueReader.validValueType) { return valueReader.literalValue; } else { throw InvalidGenerationSourceError( - '`JsonEnum.valueField` was set to "${jsonEnum.valueField}", but ' + '`JsonEnum.valueField` was set to "$valueField", but ' 'that field does not have a type of String, int, or null.', element: targetType.element2, ); From c844625eb217dab112145903a5ed00e6f3490dac Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Tue, 20 Sep 2022 17:16:38 -0700 Subject: [PATCH 437/569] json_serializable: prepare to release v6.4.0 (#1206) --- example/pubspec.yaml | 2 -- json_serializable/pubspec.yaml | 6 +----- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/example/pubspec.yaml b/example/pubspec.yaml index eb251f41f..cce74537f 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -24,7 +24,5 @@ dev_dependencies: test: ^1.16.0 dependency_overrides: - json_annotation: - path: ../json_annotation json_serializable: path: ../json_serializable diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 2c51c6fb1..508f1b8c2 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 6.4.0-dev +version: 6.4.0 description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. @@ -37,7 +37,3 @@ dev_dependencies: test_descriptor: ^2.0.0 test_process: ^2.0.0 yaml: ^3.0.0 - -dependency_overrides: - json_annotation: - path: ../json_annotation From 89d75b990a397e10b0611c4694d23a917a466702 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Tue, 27 Sep 2022 12:51:22 -0700 Subject: [PATCH 438/569] Add more documentation about JsonEnum (#1209) Also added some features to the readme builder, which will be useful later --- json_serializable/CHANGELOG.md | 4 + json_serializable/README.md | 29 +++++- json_serializable/pubspec.yaml | 2 +- .../tool/readme/enum_example.dart | 25 +++++ .../tool/readme/readme_template.md | 20 ++-- json_serializable/tool/readme_builder.dart | 92 ++++++++++++++++--- 6 files changed, 145 insertions(+), 27 deletions(-) create mode 100644 json_serializable/tool/readme/enum_example.dart diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 865886e4d..8d13284ee 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,7 @@ +## 6.4.1-dev + +- Added more documentation `@JsonEnum`. + ## 6.4.0 - Add support for `JsonEnum.valueField` which allows specifying a field in an diff --git a/json_serializable/README.md b/json_serializable/README.md index 34e874147..44648c6dc 100644 --- a/json_serializable/README.md +++ b/json_serializable/README.md @@ -115,14 +115,34 @@ Annotate `enum` types with [`JsonEnum`] (new in `json_annotation` 4.2.0) to: Annotate `enum` values with [`JsonValue`] to specify the encoded value to map to target `enum` entries. Values can be of type [`String`] or [`int`]. -<!-- TODO: hoist out to source code! --> - ```dart enum StatusCode { @JsonValue(200) success, - @JsonValue('500') - weird, + @JsonValue(301) + movedPermanently, + @JsonValue(302) + found, + @JsonValue(500) + internalServerError, +} +``` + +If you are annotating an +[enhanced enum](https://dart.dev/guides/language/language-tour#declaring-enhanced-enums), +you can use [`JsonEnum.valueField`] to specify the field to use for the +serialized value. + +```dart +@JsonEnum(valueField: 'code') +enum StatusCodeEnhanced { + success(200), + movedPermanently(301), + found(302), + internalServerError(500); + + const StatusCodeEnhanced(this.code); + final int code; } ``` @@ -201,6 +221,7 @@ targets: [`int`]: https://api.dart.dev/stable/dart-core/int-class.html [`Iterable`]: https://api.dart.dev/stable/dart-core/Iterable-class.html [`JsonConverter`]: https://pub.dev/documentation/json_annotation/4.7.0/json_annotation/JsonConverter-class.html +[`JsonEnum.valueField`]: https://pub.dev/documentation/json_annotation/4.7.0/json_annotation/JsonEnum/valueField.html [`JsonEnum`]: https://pub.dev/documentation/json_annotation/4.7.0/json_annotation/JsonEnum-class.html [`JsonKey.fromJson`]: https://pub.dev/documentation/json_annotation/4.7.0/json_annotation/JsonKey/fromJson.html [`JsonKey.toJson`]: https://pub.dev/documentation/json_annotation/4.7.0/json_annotation/JsonKey/toJson.html diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 508f1b8c2..0a373aada 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 6.4.0 +version: 6.4.1-dev description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. diff --git a/json_serializable/tool/readme/enum_example.dart b/json_serializable/tool/readme/enum_example.dart new file mode 100644 index 000000000..f3f48b017 --- /dev/null +++ b/json_serializable/tool/readme/enum_example.dart @@ -0,0 +1,25 @@ +import 'package:json_annotation/json_annotation.dart'; + +// # simple_example +enum StatusCode { + @JsonValue(200) + success, + @JsonValue(301) + movedPermanently, + @JsonValue(302) + found, + @JsonValue(500) + internalServerError, +} + +// # enhanced_example +@JsonEnum(valueField: 'code') +enum StatusCodeEnhanced { + success(200), + movedPermanently(301), + found(302), + internalServerError(500); + + const StatusCodeEnhanced(this.code); + final int code; +} diff --git a/json_serializable/tool/readme/readme_template.md b/json_serializable/tool/readme/readme_template.md index 45d9adc18..6009b06de 100644 --- a/json_serializable/tool/readme/readme_template.md +++ b/json_serializable/tool/readme/readme_template.md @@ -24,11 +24,11 @@ To configure your project for the latest released version of Given a library `example.dart` with an `Person` class annotated with `ja:JsonSerializable`: -<!-- REPLACE example.dart --> +<!-- REPLACE example/example.dart --> Building creates the corresponding part `example.g.dart`: -<!-- REPLACE example.g.dart --> +<!-- REPLACE example/example.g.dart --> # Running the code generator @@ -75,16 +75,14 @@ Annotate `enum` types with `ja:JsonEnum` (new in `json_annotation` 4.2.0) to: Annotate `enum` values with `ja:JsonValue` to specify the encoded value to map to target `enum` entries. Values can be of type `core:String` or `core:int`. -<!-- TODO: hoist out to source code! --> +<!-- REPLACE tool/readme/enum_example.dart-simple_example --> -```dart -enum StatusCode { - @JsonValue(200) - success, - @JsonValue('500') - weird, -} -``` +If you are annotating an +[enhanced enum](https://dart.dev/guides/language/language-tour#declaring-enhanced-enums), +you can use `ja:JsonEnum.valueField` to specify the field to use for the +serialized value. + +<!-- REPLACE tool/readme/enum_example.dart-enhanced_example --> # Supported types diff --git a/json_serializable/tool/readme_builder.dart b/json_serializable/tool/readme_builder.dart index cfb255496..be97e7832 100644 --- a/json_serializable/tool/readme_builder.dart +++ b/json_serializable/tool/readme_builder.dart @@ -7,7 +7,6 @@ import 'dart:convert'; import 'package:build/build.dart'; import 'package:collection/collection.dart'; -import 'package:path/path.dart' as p; import 'package:pub_semver/pub_semver.dart'; import 'package:yaml/yaml.dart'; @@ -23,8 +22,9 @@ class _ReadmeBuilder extends Builder { buildStep.assetIdForInputPackage('tool/readme/readme_template.md'); final replacements = { - 'example.dart': await buildStep.getExampleContent('example.dart'), - 'example.g.dart': await buildStep.getExampleContent('example.g.dart'), + ...await buildStep.getExampleContent('example/example.dart'), + ...await buildStep.getExampleContent('example/example.g.dart'), + ...await buildStep.getExampleContent('tool/readme/enum_example.dart'), 'supported_types': _classCleanAndSort(supportedTypes()), 'collection_types': _classCleanAndSort(collectionTypes()), 'map_key_types': _classCleanAndSort(mapKeyTypes), @@ -44,7 +44,7 @@ class _ReadmeBuilder extends Builder { final foundClasses = SplayTreeMap<String, String>(compareAsciiLowerCase); final theMap = <Pattern, String Function(Match)>{ - RegExp(r'<!-- REPLACE ([\w\d\.]+) -->'): (match) { + RegExp(r'<!-- REPLACE ([\/\w\d\._-]+) -->'): (match) { final replacementKey = match.group(1)!; availableKeys.remove(replacementKey); return (replacements[replacementKey] ?? '*MISSING! `$replacementKey`*') @@ -174,9 +174,9 @@ extension on BuildStep { return targetVersion; } - Future<String> getExampleContent(String fileName) async { + Future<Map<String, String>> getExampleContent(String fileName) async { final content = await readAsString( - assetIdForInputPackage(p.join('example', fileName)), + assetIdForInputPackage(fileName), ); final lines = LineSplitter.split(content); @@ -185,7 +185,12 @@ extension on BuildStep { // All lines with content, except those starting with `/`. // Also exclude blank lines that follow other blank lines - final cleanedSource = lines.where((l) { + final cleanedSourceLines = lines.where((l) { + if (l.isBlockLine) { + // This is a block! + return true; + } + if (l.startsWith(r'/')) { return false; } @@ -201,11 +206,76 @@ extension on BuildStep { } return false; - }).join('\n'); + }); + + if (cleanedSourceLines.any((element) => element.isBlockLine)) { + final result = <String, String>{}; + + String? currentBlock; + final builder = <String>[]; + + void finishBlock() { + result[currentBlock!] = builder.join('\n').trim(); + builder.clear(); + currentBlock = null; + } + + for (var line in cleanedSourceLines) { + if (currentBlock == null) { + if (!line.isBlockLine) { + // have not got to a block yet – skip! + } else { + // this is our first block! + currentBlock = line.blockName; + if (result.containsKey(currentBlock)) { + throw StateError('Duplicate block "$currentBlock"'); + } + } + continue; + } + + if (line.isBlockLine) { + if (builder.isEmpty) { + log.warning('`$currentBlock` is empty'); + } else { + finishBlock(); + currentBlock = line.blockName; + if (result.containsKey(currentBlock)) { + throw StateError('Duplicate block "$currentBlock"'); + } + } + } else { + builder.add(line); + } + } - return ''' + if (currentBlock != null) finishBlock(); + + return result + .map((key, value) => MapEntry('$fileName-$key', value.dartBlock)); + } else { + return { + fileName: cleanedSourceLines.join('\n').dartBlock, + }; + } + } +} + +extension on String { + bool get isBlockLine => trim().startsWith(_blockComment); + + String get blockName { + assert(isBlockLine); + final index = indexOf(_blockComment); + assert(index >= 0); + final start = index + _blockComment.length; + return substring(start).trim(); + } + + String get dartBlock => ''' ```dart -$cleanedSource +${trim()} ```'''; - } + + static const _blockComment = r'// # '; } From f94edb272e7fd45b757e7e3320a440c4793d5691 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Wed, 28 Sep 2022 12:43:20 -0700 Subject: [PATCH 439/569] Fix a bug when annotated classes also use mixins (#1211) Swapped a cast to ClassElement to less specific InterfaceElement Fixes https://github.com/google/json_serializable.dart/issues/1210 Prepare to release v6.4.1 --- json_serializable/CHANGELOG.md | 3 ++- json_serializable/lib/src/field_helpers.dart | 5 +++-- json_serializable/pubspec.yaml | 2 +- .../test/integration/json_test_example.dart | 18 +++++++++++++++++ .../test/integration/json_test_example.g.dart | 12 +++++++++++ .../json_test_example.g_any_map.dart | 20 +++++++++++++++++++ .../json_test_example.g_any_map.g.dart | 11 ++++++++++ 7 files changed, 67 insertions(+), 4 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 8d13284ee..849110984 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,5 +1,6 @@ -## 6.4.1-dev +## 6.4.1 +- Fixed a bug when an `@JsonSerializable` class uses a mixin with fields. - Added more documentation `@JsonEnum`. ## 6.4.0 diff --git a/json_serializable/lib/src/field_helpers.dart b/json_serializable/lib/src/field_helpers.dart index d07f45d2e..3e3643915 100644 --- a/json_serializable/lib/src/field_helpers.dart +++ b/json_serializable/lib/src/field_helpers.dart @@ -36,8 +36,9 @@ class _FieldSet implements Comparable<_FieldSet> { int compareTo(_FieldSet other) => _sortByLocation(sortField, other.sortField); static int _sortByLocation(FieldElement a, FieldElement b) { - final checkerA = - TypeChecker.fromStatic((a.enclosingElement3 as ClassElement).thisType); + final checkerA = TypeChecker.fromStatic( + (a.enclosingElement3 as InterfaceElement).thisType, + ); if (!checkerA.isExactly(b.enclosingElement3)) { // in this case, you want to prioritize the enclosingElement that is more diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 0a373aada..c4eef479b 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 6.4.1-dev +version: 6.4.1 description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. diff --git a/json_serializable/test/integration/json_test_example.dart b/json_serializable/test/integration/json_test_example.dart index 8d29a26f3..09c4aa6d0 100644 --- a/json_serializable/test/integration/json_test_example.dart +++ b/json_serializable/test/integration/json_test_example.dart @@ -239,3 +239,21 @@ class PrivateConstructor { bool operator ==(Object other) => other is PrivateConstructor && id == other.id && value == other.value; } + +mixin RegressionTestIssue1210Mixin { + bool? get someProperty => null; + + @override + int get hashCode => identityHashCode(this); +} + +@JsonSerializable() +class RegressionTestIssue1210 with RegressionTestIssue1210Mixin { + const RegressionTestIssue1210(this.field); + + factory RegressionTestIssue1210.fromJson(Map<String, dynamic> json) => + _$RegressionTestIssue1210FromJson(json); + final String field; + + Map<String, dynamic> toJson() => _$RegressionTestIssue1210ToJson(this); +} diff --git a/json_serializable/test/integration/json_test_example.g.dart b/json_serializable/test/integration/json_test_example.g.dart index 432455f76..4681280b8 100644 --- a/json_serializable/test/integration/json_test_example.g.dart +++ b/json_serializable/test/integration/json_test_example.g.dart @@ -213,3 +213,15 @@ Map<String, dynamic> _$PrivateConstructorToJson(PrivateConstructor instance) => 'id': instance.id, 'value': instance.value, }; + +RegressionTestIssue1210 _$RegressionTestIssue1210FromJson( + Map<String, dynamic> json) => + RegressionTestIssue1210( + json['field'] as String, + ); + +Map<String, dynamic> _$RegressionTestIssue1210ToJson( + RegressionTestIssue1210 instance) => + <String, dynamic>{ + 'field': instance.field, + }; diff --git a/json_serializable/test/integration/json_test_example.g_any_map.dart b/json_serializable/test/integration/json_test_example.g_any_map.dart index 38c5d3687..9c449727d 100644 --- a/json_serializable/test/integration/json_test_example.g_any_map.dart +++ b/json_serializable/test/integration/json_test_example.g_any_map.dart @@ -247,3 +247,23 @@ class PrivateConstructor { bool operator ==(Object other) => other is PrivateConstructor && id == other.id && value == other.value; } + +mixin RegressionTestIssue1210Mixin { + bool? get someProperty => null; + + @override + int get hashCode => identityHashCode(this); +} + +@JsonSerializable( + anyMap: true, +) +class RegressionTestIssue1210 with RegressionTestIssue1210Mixin { + const RegressionTestIssue1210(this.field); + + factory RegressionTestIssue1210.fromJson(Map<String, dynamic> json) => + _$RegressionTestIssue1210FromJson(json); + final String field; + + Map<String, dynamic> toJson() => _$RegressionTestIssue1210ToJson(this); +} diff --git a/json_serializable/test/integration/json_test_example.g_any_map.g.dart b/json_serializable/test/integration/json_test_example.g_any_map.g.dart index 13390d797..1e86e1fbc 100644 --- a/json_serializable/test/integration/json_test_example.g_any_map.g.dart +++ b/json_serializable/test/integration/json_test_example.g_any_map.g.dart @@ -211,3 +211,14 @@ Map<String, dynamic> _$PrivateConstructorToJson(PrivateConstructor instance) => 'id': instance.id, 'value': instance.value, }; + +RegressionTestIssue1210 _$RegressionTestIssue1210FromJson(Map json) => + RegressionTestIssue1210( + json['field'] as String, + ); + +Map<String, dynamic> _$RegressionTestIssue1210ToJson( + RegressionTestIssue1210 instance) => + <String, dynamic>{ + 'field': instance.field, + }; From 9b8050c07238b81b92330a54fb1dc445e96ebb96 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Wed, 28 Sep 2022 14:26:35 -0700 Subject: [PATCH 440/569] json_serializable: fix readme spelling, DRY up some type logic (#1212) --- json_serializable/CHANGELOG.md | 2 ++ json_serializable/README.md | 2 +- .../lib/src/type_helpers/map_helper.dart | 7 ++++--- json_serializable/lib/type_helper.dart | 2 +- json_serializable/pubspec.yaml | 2 +- json_serializable/tool/readme/readme_template.md | 2 +- json_serializable/tool/test_type_builder.dart | 14 ++++---------- 7 files changed, 14 insertions(+), 17 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 849110984..7d89d80d9 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,5 @@ +## 6.4.2-dev + ## 6.4.1 - Fixed a bug when an `@JsonSerializable` class uses a mixin with fields. diff --git a/json_serializable/README.md b/json_serializable/README.md index 44648c6dc..2d7b4c66d 100644 --- a/json_serializable/README.md +++ b/json_serializable/README.md @@ -167,7 +167,7 @@ For [`Map`], the key value must be one of If you want to use types that are not supported out-of-the-box or if you want to customize the encoding/decoding of any type, you have a few options. -1. If you own/cotrol the desired type, add a `fromJson` constructor and/or a +1. If you own/control the desired type, add a `fromJson` constructor and/or a `toJson()` function to the type. Note: while you can use `json_serializable` for these types, you don't have to! The generator code only looks for these methods. It doesn't care how they were created. diff --git a/json_serializable/lib/src/type_helpers/map_helper.dart b/json_serializable/lib/src/type_helpers/map_helper.dart index 8bff25263..7c99fcf5a 100644 --- a/json_serializable/lib/src/type_helpers/map_helper.dart +++ b/json_serializable/lib/src/type_helpers/map_helper.dart @@ -167,7 +167,7 @@ void _checkSafeKeyType(String expression, DartType keyArg) { throw UnsupportedTypeError( keyArg, expression, - 'Map keys must be one of: ${_allowedTypeNames.join(', ')}.', + 'Map keys must be one of: ${allowedMapKeyTypes.join(', ')}.', ); } @@ -175,12 +175,13 @@ void _checkSafeKeyType(String expression, DartType keyArg) { /// /// Used in [_checkSafeKeyType] to provide a helpful error with unsupported /// types. -Iterable<String> get _allowedTypeNames => const [ +List<String> get allowedMapKeyTypes => [ 'Object', 'dynamic', 'enum', 'String', - ].followedBy(_instances.map((i) => i.coreTypeName)); + ..._instances.map((i) => i.coreTypeName) + ]; extension on DartType { bool get isSimpleJsonTypeNotDouble => diff --git a/json_serializable/lib/type_helper.dart b/json_serializable/lib/type_helper.dart index ab8a4c60a..d79a2ada7 100644 --- a/json_serializable/lib/type_helper.dart +++ b/json_serializable/lib/type_helper.dart @@ -14,7 +14,7 @@ export 'src/type_helpers/enum_helper.dart'; export 'src/type_helpers/iterable_helper.dart'; export 'src/type_helpers/json_converter_helper.dart'; export 'src/type_helpers/json_helper.dart'; -export 'src/type_helpers/map_helper.dart'; +export 'src/type_helpers/map_helper.dart' show MapHelper; export 'src/type_helpers/uri_helper.dart'; export 'src/type_helpers/value_helper.dart'; export 'src/unsupported_type_error.dart'; diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index c4eef479b..b8739a41d 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 6.4.1 +version: 6.4.2-dev description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. diff --git a/json_serializable/tool/readme/readme_template.md b/json_serializable/tool/readme/readme_template.md index 6009b06de..2f3c39551 100644 --- a/json_serializable/tool/readme/readme_template.md +++ b/json_serializable/tool/readme/readme_template.md @@ -103,7 +103,7 @@ For `core:Map`, the key value must be one of If you want to use types that are not supported out-of-the-box or if you want to customize the encoding/decoding of any type, you have a few options. -1. If you own/cotrol the desired type, add a `fromJson` constructor and/or a +1. If you own/control the desired type, add a `fromJson` constructor and/or a `toJson()` function to the type. Note: while you can use `json_serializable` for these types, you don't have to! The generator code only looks for these methods. It doesn't care how they were created. diff --git a/json_serializable/tool/test_type_builder.dart b/json_serializable/tool/test_type_builder.dart index bfadc7091..de9df8b2c 100644 --- a/json_serializable/tool/test_type_builder.dart +++ b/json_serializable/tool/test_type_builder.dart @@ -7,6 +7,7 @@ import 'dart:async'; import 'package:build/build.dart'; import 'package:collection/collection.dart'; import 'package:dart_style/dart_style.dart'; +import 'package:json_serializable/src/type_helpers/map_helper.dart'; import 'shared.dart'; import 'test_type_data.dart'; @@ -96,16 +97,9 @@ final _typesToTest = { ..._collectionTypes, }; -const mapKeyTypes = { - 'BigInt', - 'DateTime', - 'dynamic', - customEnumType, - 'int', - 'Object', - 'String', - 'Uri', -}; +Iterable<String> get mapKeyTypes => + allowedMapKeyTypes.map((e) => e == 'enum' ? customEnumType : e).toList() + ..sort(compareAsciiLowerCase); final _iterableGenericArgs = ([ ..._trivialTypesToTest.keys, From aee8507305811c0f6478b90b2dc36ac1f3b704d9 Mon Sep 17 00:00:00 2001 From: Alex Li <github@alexv525.com> Date: Thu, 29 Sep 2022 06:22:50 +0800 Subject: [PATCH 441/569] Support `ConstructorElement` (#1183) --- json_serializable/CHANGELOG.md | 2 ++ json_serializable/lib/src/utils.dart | 8 ++++++ .../test/json_serializable_test.dart | 1 + .../src/_json_serializable_test_input.dart | 28 +++++++++++++++++++ 4 files changed, 39 insertions(+) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 7d89d80d9..d6366ae68 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,5 +1,7 @@ ## 6.4.2-dev +- Support `ConstructorElement` which allows using tear-off constructors. + ## 6.4.1 - Fixed a bug when an `@JsonSerializable` class uses a mixin with fields. diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index 727b6f0d0..7a5c479ce 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -232,6 +232,14 @@ extension ExecutableElementExtension on ExecutableElement { return '${enclosingElement3.name}.$name'; } + if (this is ConstructorElement) { + // Ignore the default constructor. + if (name.isEmpty) { + return '${enclosingElement3.name}'; + } + return '${enclosingElement3.name}.$name'; + } + throw UnsupportedError( 'Not sure how to support typeof $runtimeType', ); diff --git a/json_serializable/test/json_serializable_test.dart b/json_serializable/test/json_serializable_test.dart index cf4962e43..992142553 100644 --- a/json_serializable/test/json_serializable_test.dart +++ b/json_serializable/test/json_serializable_test.dart @@ -126,6 +126,7 @@ const _expectedAnnotatedTests = { 'SubTypeWithAnnotatedFieldOverrideExtendsWithOverrides', 'SubTypeWithAnnotatedFieldOverrideImplements', 'theAnswer', + 'TearOffFromJsonClass', 'ToJsonNullableFalseIncludeIfNullFalse', 'TypedConvertMethods', 'UnknownEnumValue', diff --git a/json_serializable/test/src/_json_serializable_test_input.dart b/json_serializable/test/src/_json_serializable_test_input.dart index 7a116a094..945bf5571 100644 --- a/json_serializable/test/src/_json_serializable_test_input.dart +++ b/json_serializable/test/src/_json_serializable_test_input.dart @@ -579,3 +579,31 @@ class Issue1038RegressionTest { Issue1038RegressionTest.ean(this.ean) : id = null; } + +@ShouldGenerate( + r''' +TearOffFromJsonClass _$TearOffFromJsonClassFromJson( + Map<String, dynamic> json) => + TearOffFromJsonClass( + TearOffValueClass(json['value'] as String), + TearOffValueClass.fromJson(json['factoryValue'] as String), + ); +''', +) +@JsonSerializable(createToJson: false) +class TearOffFromJsonClass { + TearOffFromJsonClass(this.value, this.factoryValue); + + @JsonKey(fromJson: TearOffValueClass.new) + final TearOffValueClass value; + @JsonKey(fromJson: TearOffValueClass.fromJson) + final TearOffValueClass factoryValue; +} + +class TearOffValueClass { + const TearOffValueClass(this.value); + + factory TearOffValueClass.fromJson(String value) => TearOffValueClass(value); + + final String value; +} From f8dc218290b8c46a02c43ed20685002274d0765f Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Thu, 29 Sep 2022 12:06:19 -0700 Subject: [PATCH 442/569] changelog cleanup, add more examples to readme (#1213) --- json_annotation/lib/src/json_converter.dart | 5 +- json_serializable/CHANGELOG.md | 3 +- json_serializable/README.md | 79 ++++++++++++++ json_serializable/build.yaml | 1 + .../tool/readme/enum_example.dart | 25 ----- .../tool/readme/readme_examples.dart | 101 ++++++++++++++++++ .../tool/readme/readme_examples.g.dart | 33 ++++++ .../tool/readme/readme_template.md | 12 ++- json_serializable/tool/readme_builder.dart | 16 ++- 9 files changed, 239 insertions(+), 36 deletions(-) delete mode 100644 json_serializable/tool/readme/enum_example.dart create mode 100644 json_serializable/tool/readme/readme_examples.dart create mode 100644 json_serializable/tool/readme/readme_examples.g.dart diff --git a/json_annotation/lib/src/json_converter.dart b/json_annotation/lib/src/json_converter.dart index 8736d2c42..fefe88ece 100644 --- a/json_annotation/lib/src/json_converter.dart +++ b/json_annotation/lib/src/json_converter.dart @@ -26,16 +26,15 @@ /// /// ```dart /// @JsonSerializable() -/// @MyJsonConverter() /// class Example { /// @MyJsonConverter() /// final Value property; /// } /// ``` /// -/// Or finally, passed to the annotation: +/// Or finally, passed to the `@JsonSerializable` annotation: /// -///```dart +/// ```dart /// @JsonSerializable(converters: [MyJsonConverter()]) /// class Example {} /// ``` diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index d6366ae68..7270ca696 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,6 +1,7 @@ ## 6.4.2-dev -- Support `ConstructorElement` which allows using tear-off constructors. +- Allow constructors to be passed to `JsonKey` parameters that support + `Function` types. ## 6.4.1 diff --git a/json_serializable/README.md b/json_serializable/README.md index 2d7b4c66d..ac0eebdf7 100644 --- a/json_serializable/README.md +++ b/json_serializable/README.md @@ -171,15 +171,94 @@ customize the encoding/decoding of any type, you have a few options. `toJson()` function to the type. Note: while you can use `json_serializable` for these types, you don't have to! The generator code only looks for these methods. It doesn't care how they were created. + + ```dart + @JsonSerializable() + class Sample1 { + Sample1(this.value); + + factory Sample1.fromJson(Map<String, dynamic> json) => + _$Sample1FromJson(json); + + // Sample2 is NOT annotated with @JsonSerializable(), but that's okay + // The class has a `fromJson` constructor and a `toJson` method, which is + // all that is required. + final Sample2 value; + + Map<String, dynamic> toJson() => _$Sample1ToJson(this); + } + + class Sample2 { + Sample2(this.value); + + // The convention is for `fromJson` to take a single parameter of type + // `Map<String, dynamic>` but any JSON-compatible type is allowed. + factory Sample2.fromJson(int value) => Sample2(value); + final int value; + + // The convention is for `toJson` to take return a type of + // `Map<String, dynamic>` but any JSON-compatible type is allowed. + int toJson() => value; + } + ``` + 1. Use the [`JsonKey.toJson`] and [`JsonKey.fromJson`] properties to specify custom conversions on the annotated field. The functions specified must be top-level or static. See the documentation of these properties for details. + + ```dart + @JsonSerializable() + class Sample3 { + Sample3(this.value); + + factory Sample3.fromJson(Map<String, dynamic> json) => + _$Sample3FromJson(json); + + @JsonKey( + toJson: _toJson, + fromJson: _fromJson, + ) + final DateTime value; + + Map<String, dynamic> toJson() => _$Sample3ToJson(this); + + static int _toJson(DateTime value) => value.millisecondsSinceEpoch; + static DateTime _fromJson(int value) => + DateTime.fromMillisecondsSinceEpoch(value); + } + ``` + 1. Create an implementation of [`JsonConverter`] and annotate either the corresponding field or the containing class. [`JsonConverter`] is convenient if you want to use the same conversion logic on many fields. It also allows you to support a type within collections. Check out [these examples](https://github.com/google/json_serializable.dart/blob/master/example/lib/json_converter_example.dart). + ```dart + @JsonSerializable() + class Sample4 { + Sample4(this.value); + + factory Sample4.fromJson(Map<String, dynamic> json) => + _$Sample4FromJson(json); + + @EpochDateTimeConverter() + final DateTime value; + + Map<String, dynamic> toJson() => _$Sample4ToJson(this); + } + + class EpochDateTimeConverter implements JsonConverter<DateTime, int> { + const EpochDateTimeConverter(); + + @override + DateTime fromJson(int json) => DateTime.fromMillisecondsSinceEpoch(json); + + @override + int toJson(DateTime object) => object.millisecondsSinceEpoch; + } + ``` + # Build configuration Aside from setting arguments on the associated annotation classes, you can also diff --git a/json_serializable/build.yaml b/json_serializable/build.yaml index 03933fb6e..1b5d731c9 100644 --- a/json_serializable/build.yaml +++ b/json_serializable/build.yaml @@ -18,6 +18,7 @@ targets: - test/kitchen_sink/* - test/literal/* - test/supported_types/* + - tool/readme/* json_serializable|_test_builder: generate_for: diff --git a/json_serializable/tool/readme/enum_example.dart b/json_serializable/tool/readme/enum_example.dart deleted file mode 100644 index f3f48b017..000000000 --- a/json_serializable/tool/readme/enum_example.dart +++ /dev/null @@ -1,25 +0,0 @@ -import 'package:json_annotation/json_annotation.dart'; - -// # simple_example -enum StatusCode { - @JsonValue(200) - success, - @JsonValue(301) - movedPermanently, - @JsonValue(302) - found, - @JsonValue(500) - internalServerError, -} - -// # enhanced_example -@JsonEnum(valueField: 'code') -enum StatusCodeEnhanced { - success(200), - movedPermanently(301), - found(302), - internalServerError(500); - - const StatusCodeEnhanced(this.code); - final int code; -} diff --git a/json_serializable/tool/readme/readme_examples.dart b/json_serializable/tool/readme/readme_examples.dart new file mode 100644 index 000000000..0abc70fc5 --- /dev/null +++ b/json_serializable/tool/readme/readme_examples.dart @@ -0,0 +1,101 @@ +import 'package:json_annotation/json_annotation.dart'; + +part 'readme_examples.g.dart'; + +// # simple_example +enum StatusCode { + @JsonValue(200) + success, + @JsonValue(301) + movedPermanently, + @JsonValue(302) + found, + @JsonValue(500) + internalServerError, +} + +// # enhanced_example +@JsonEnum(valueField: 'code') +enum StatusCodeEnhanced { + success(200), + movedPermanently(301), + found(302), + internalServerError(500); + + const StatusCodeEnhanced(this.code); + final int code; +} + +// # to_from +@JsonSerializable() +class Sample1 { + Sample1(this.value); + + factory Sample1.fromJson(Map<String, dynamic> json) => + _$Sample1FromJson(json); + + // Sample2 is NOT annotated with @JsonSerializable(), but that's okay + // The class has a `fromJson` constructor and a `toJson` method, which is + // all that is required. + final Sample2 value; + + Map<String, dynamic> toJson() => _$Sample1ToJson(this); +} + +class Sample2 { + Sample2(this.value); + + // The convention is for `fromJson` to take a single parameter of type + // `Map<String, dynamic>` but any JSON-compatible type is allowed. + factory Sample2.fromJson(int value) => Sample2(value); + final int value; + + // The convention is for `toJson` to take return a type of + // `Map<String, dynamic>` but any JSON-compatible type is allowed. + int toJson() => value; +} + +// # json_key +@JsonSerializable() +class Sample3 { + Sample3(this.value); + + factory Sample3.fromJson(Map<String, dynamic> json) => + _$Sample3FromJson(json); + + @JsonKey( + toJson: _toJson, + fromJson: _fromJson, + ) + final DateTime value; + + Map<String, dynamic> toJson() => _$Sample3ToJson(this); + + static int _toJson(DateTime value) => value.millisecondsSinceEpoch; + static DateTime _fromJson(int value) => + DateTime.fromMillisecondsSinceEpoch(value); +} + +// # json_converter +@JsonSerializable() +class Sample4 { + Sample4(this.value); + + factory Sample4.fromJson(Map<String, dynamic> json) => + _$Sample4FromJson(json); + + @EpochDateTimeConverter() + final DateTime value; + + Map<String, dynamic> toJson() => _$Sample4ToJson(this); +} + +class EpochDateTimeConverter implements JsonConverter<DateTime, int> { + const EpochDateTimeConverter(); + + @override + DateTime fromJson(int json) => DateTime.fromMillisecondsSinceEpoch(json); + + @override + int toJson(DateTime object) => object.millisecondsSinceEpoch; +} diff --git a/json_serializable/tool/readme/readme_examples.g.dart b/json_serializable/tool/readme/readme_examples.g.dart new file mode 100644 index 000000000..be265dd6d --- /dev/null +++ b/json_serializable/tool/readme/readme_examples.g.dart @@ -0,0 +1,33 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal + +part of 'readme_examples.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +Sample1 _$Sample1FromJson(Map<String, dynamic> json) => Sample1( + Sample2.fromJson(json['value'] as int), + ); + +Map<String, dynamic> _$Sample1ToJson(Sample1 instance) => <String, dynamic>{ + 'value': instance.value, + }; + +Sample3 _$Sample3FromJson(Map<String, dynamic> json) => Sample3( + Sample3._fromJson(json['value'] as int), + ); + +Map<String, dynamic> _$Sample3ToJson(Sample3 instance) => <String, dynamic>{ + 'value': Sample3._toJson(instance.value), + }; + +Sample4 _$Sample4FromJson(Map<String, dynamic> json) => Sample4( + const EpochDateTimeConverter().fromJson(json['value'] as int), + ); + +Map<String, dynamic> _$Sample4ToJson(Sample4 instance) => <String, dynamic>{ + 'value': const EpochDateTimeConverter().toJson(instance.value), + }; diff --git a/json_serializable/tool/readme/readme_template.md b/json_serializable/tool/readme/readme_template.md index 2f3c39551..8af2bac78 100644 --- a/json_serializable/tool/readme/readme_template.md +++ b/json_serializable/tool/readme/readme_template.md @@ -75,14 +75,14 @@ Annotate `enum` types with `ja:JsonEnum` (new in `json_annotation` 4.2.0) to: Annotate `enum` values with `ja:JsonValue` to specify the encoded value to map to target `enum` entries. Values can be of type `core:String` or `core:int`. -<!-- REPLACE tool/readme/enum_example.dart-simple_example --> +<!-- REPLACE tool/readme/readme_examples.dart-simple_example --> If you are annotating an [enhanced enum](https://dart.dev/guides/language/language-tour#declaring-enhanced-enums), you can use `ja:JsonEnum.valueField` to specify the field to use for the serialized value. -<!-- REPLACE tool/readme/enum_example.dart-enhanced_example --> +<!-- REPLACE tool/readme/readme_examples.dart-enhanced_example --> # Supported types @@ -107,15 +107,23 @@ customize the encoding/decoding of any type, you have a few options. `toJson()` function to the type. Note: while you can use `json_serializable` for these types, you don't have to! The generator code only looks for these methods. It doesn't care how they were created. + + <!-- REPLACE tool/readme/readme_examples.dart-to_from --> + 1. Use the `ja:JsonKey.toJson` and `ja:JsonKey.fromJson` properties to specify custom conversions on the annotated field. The functions specified must be top-level or static. See the documentation of these properties for details. + + <!-- REPLACE tool/readme/readme_examples.dart-json_key --> + 1. Create an implementation of `ja:JsonConverter` and annotate either the corresponding field or the containing class. `ja:JsonConverter` is convenient if you want to use the same conversion logic on many fields. It also allows you to support a type within collections. Check out [these examples](https://github.com/google/json_serializable.dart/blob/master/example/lib/json_converter_example.dart). + <!-- REPLACE tool/readme/readme_examples.dart-json_converter --> + # Build configuration Aside from setting arguments on the associated annotation classes, you can also diff --git a/json_serializable/tool/readme_builder.dart b/json_serializable/tool/readme_builder.dart index be97e7832..76156a219 100644 --- a/json_serializable/tool/readme_builder.dart +++ b/json_serializable/tool/readme_builder.dart @@ -24,7 +24,7 @@ class _ReadmeBuilder extends Builder { final replacements = { ...await buildStep.getExampleContent('example/example.dart'), ...await buildStep.getExampleContent('example/example.g.dart'), - ...await buildStep.getExampleContent('tool/readme/enum_example.dart'), + ...await buildStep.getExampleContent('tool/readme/readme_examples.dart'), 'supported_types': _classCleanAndSort(supportedTypes()), 'collection_types': _classCleanAndSort(collectionTypes()), 'map_key_types': _classCleanAndSort(mapKeyTypes), @@ -44,11 +44,14 @@ class _ReadmeBuilder extends Builder { final foundClasses = SplayTreeMap<String, String>(compareAsciiLowerCase); final theMap = <Pattern, String Function(Match)>{ - RegExp(r'<!-- REPLACE ([\/\w\d\._-]+) -->'): (match) { - final replacementKey = match.group(1)!; + RegExp(r'( *)<!-- REPLACE ([\/\w\d\._-]+) -->'): (match) { + final replacementKey = match.group(2)!; availableKeys.remove(replacementKey); - return (replacements[replacementKey] ?? '*MISSING! `$replacementKey`*') - .trim(); + final replacement = + (replacements[replacementKey] ?? '*MISSING! `$replacementKey`*') + .trim(); + + return replacement.indent(match.group(1)!); }, RegExp(r'`(\w+):(\w+)(\.\w+)?`'): (match) { final context = match.group(1)!; @@ -278,4 +281,7 @@ ${trim()} ```'''; static const _blockComment = r'// # '; + + String indent(String indent) => + LineSplitter.split(this).map((e) => '$indent$e'.trimRight()).join('\n'); } From 7d3bf2044ffa161ac67e75a67a51ebd8690a3487 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Mon, 3 Oct 2022 11:50:36 -0700 Subject: [PATCH 443/569] Latest mono_repo (#1215) Closes #1214 --- .github/workflows/dart.yml | 30 +++++++++++++++--------------- tool/ci.sh | 2 +- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 691f85089..a1692ef8f 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -1,4 +1,4 @@ -# Created with package:mono_repo v6.4.0 +# Created with package:mono_repo v6.4.1 name: Dart CI on: push: @@ -21,7 +21,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@fd5de65bc895cf536527842281bea11763fefd77 + uses: actions/cache@ac8075791e805656e71b4ba23325ace9e3421120 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:stable" @@ -36,7 +36,7 @@ jobs: name: Checkout repository uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b - name: mono_repo self validate - run: dart pub global activate mono_repo 6.4.0 + run: dart pub global activate mono_repo 6.4.1 - name: mono_repo self validate run: dart pub global run mono_repo generate --validate job_002: @@ -44,7 +44,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@fd5de65bc895cf536527842281bea11763fefd77 + uses: actions/cache@ac8075791e805656e71b4ba23325ace9e3421120 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.17.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:format-analyze" @@ -130,7 +130,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@fd5de65bc895cf536527842281bea11763fefd77 + uses: actions/cache@ac8075791e805656e71b4ba23325ace9e3421120 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:format-analyze" @@ -216,7 +216,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@fd5de65bc895cf536527842281bea11763fefd77 + uses: actions/cache@ac8075791e805656e71b4ba23325ace9e3421120 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.17.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" @@ -277,7 +277,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@fd5de65bc895cf536527842281bea11763fefd77 + uses: actions/cache@ac8075791e805656e71b4ba23325ace9e3421120 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.17.0;packages:json_serializable;commands:test_3" @@ -311,7 +311,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@fd5de65bc895cf536527842281bea11763fefd77 + uses: actions/cache@ac8075791e805656e71b4ba23325ace9e3421120 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.17.0;packages:json_serializable;commands:test_1" @@ -345,7 +345,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@fd5de65bc895cf536527842281bea11763fefd77 + uses: actions/cache@ac8075791e805656e71b4ba23325ace9e3421120 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.17.0;packages:json_serializable;commands:test_2" @@ -379,7 +379,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@fd5de65bc895cf536527842281bea11763fefd77 + uses: actions/cache@ac8075791e805656e71b4ba23325ace9e3421120 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" @@ -440,7 +440,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@fd5de65bc895cf536527842281bea11763fefd77 + uses: actions/cache@ac8075791e805656e71b4ba23325ace9e3421120 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:json_serializable;commands:test_3" @@ -474,7 +474,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@fd5de65bc895cf536527842281bea11763fefd77 + uses: actions/cache@ac8075791e805656e71b4ba23325ace9e3421120 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:json_serializable;commands:test_1" @@ -508,7 +508,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@fd5de65bc895cf536527842281bea11763fefd77 + uses: actions/cache@ac8075791e805656e71b4ba23325ace9e3421120 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:json_serializable;commands:test_2" @@ -542,7 +542,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@fd5de65bc895cf536527842281bea11763fefd77 + uses: actions/cache@ac8075791e805656e71b4ba23325ace9e3421120 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.17.0;packages:_test_yaml-checked_yaml-example;commands:test_1" @@ -602,7 +602,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@fd5de65bc895cf536527842281bea11763fefd77 + uses: actions/cache@ac8075791e805656e71b4ba23325ace9e3421120 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:_test_yaml-checked_yaml-example;commands:test_1" diff --git a/tool/ci.sh b/tool/ci.sh index 228f5ad34..79afcec7d 100755 --- a/tool/ci.sh +++ b/tool/ci.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Created with package:mono_repo v6.4.0 +# Created with package:mono_repo v6.4.1 # Support built in commands on windows out of the box. # When it is a flutter repo (check the pubspec.yaml for "sdk: flutter") From 0e89d966b6daf951e8ed51f3c0de032b2c7bfa70 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Wed, 5 Oct 2022 10:54:02 -0700 Subject: [PATCH 444/569] Support Function values for JsonKey.default value (#1216) Update docs in json_annotation Prepare to release json_serializable v6.5.0 Closes https://github.com/google/json_serializable.dart/issues/1185 --- json_annotation/CHANGELOG.md | 5 +++ json_annotation/lib/src/json_key.dart | 14 ++++-- json_annotation/pubspec.yaml | 2 +- json_serializable/CHANGELOG.md | 5 ++- json_serializable/lib/src/json_key_utils.dart | 44 ++++++++++++++----- json_serializable/pubspec.yaml | 2 +- .../test/default_value/default_value.dart | 15 ++++++- .../test/default_value/default_value.g.dart | 20 +++++++++ .../default_value.g_any_map__checked.dart | 15 ++++++- .../default_value.g_any_map__checked.g.dart | 18 ++++++++ .../default_value_interface.dart | 12 ++++- .../default_value/default_value_test.dart | 6 +++ .../default_value/implicit_default_value.dart | 9 ++++ .../implicit_default_value.g.dart | 19 ++++++++ .../test/json_serializable_test.dart | 1 + .../test/src/default_value_input.dart | 28 ++++++++++-- 16 files changed, 189 insertions(+), 26 deletions(-) diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index e571f85f5..f5167ebc1 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -1,3 +1,8 @@ +## 4.7.1-dev + +- Update `JsonKey` documentation to align with new features in + `package:json_serializable`. + ## 4.7.0 - Added `JsonEnum.valueField` which allows specifying a field in an diff --git a/json_annotation/lib/src/json_key.dart b/json_annotation/lib/src/json_key.dart index 96967c2a9..bda621039 100644 --- a/json_annotation/lib/src/json_key.dart +++ b/json_annotation/lib/src/json_key.dart @@ -12,6 +12,10 @@ import 'json_serializable.dart'; class JsonKey { /// The value to use if the source JSON does not contain this key or if the /// value is `null`. + /// + /// Also supported: a top-level or static [Function] or a constructor with no + /// required parameters and a return type compatible with the field being + /// assigned. final Object? defaultValue; /// If `true`, generated code will throw a [DisallowedNullValueException] if @@ -30,8 +34,9 @@ class JsonKey { /// A [Function] to use when decoding the associated JSON value to the /// annotated field. /// - /// Must be a top-level or static [Function] that takes one argument mapping - /// a JSON literal to a value compatible with the type of the annotated field. + /// Must be a top-level or static [Function] or a constructor that accepts one + /// positional argument mapping a JSON literal to a value compatible with the + /// type of the annotated field. /// /// When creating a class that supports both `toJson` and `fromJson` /// (the default), you should also set [toJson] if you set [fromJson]. @@ -94,8 +99,9 @@ class JsonKey { /// A [Function] to use when encoding the annotated field to JSON. /// - /// Must be a top-level or static [Function] with one parameter compatible - /// with the field being serialized that returns a JSON-compatible value. + /// Must be a top-level or static [Function] or a constructor that accepts one + /// positional argument compatible with the field being serialized that + /// returns a JSON-compatible value. /// /// When creating a class that supports both `toJson` and `fromJson` /// (the default), you should also set [fromJson] if you set [toJson]. diff --git a/json_annotation/pubspec.yaml b/json_annotation/pubspec.yaml index e80442751..4daf681c0 100644 --- a/json_annotation/pubspec.yaml +++ b/json_annotation/pubspec.yaml @@ -1,5 +1,5 @@ name: json_annotation -version: 4.7.0 +version: 4.7.1-dev description: >- Classes and helper functions that support JSON code generation via the `json_serializable` package. diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 7270ca696..37a261442 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,7 +1,10 @@ -## 6.4.2-dev +## 6.5.0 - Allow constructors to be passed to `JsonKey` parameters that support `Function` types. +- Accept `Function` values for `JsonKey.defaultValue`. The provided + `Function` will be invoked for the default value if the target JSON element is + missing or `null`. ## 6.4.1 diff --git a/json_serializable/lib/src/json_key_utils.dart b/json_serializable/lib/src/json_key_utils.dart index aaed19799..b994fa097 100644 --- a/json_serializable/lib/src/json_key_utils.dart +++ b/json_serializable/lib/src/json_key_utils.dart @@ -58,7 +58,9 @@ KeyConfig _from(FieldElement element, ClassConfig classAnnotation) { } else if (reader.isType) { badType = 'Type'; } else if (dartObject.type is FunctionType) { - // TODO: Support calling function for the default value? + // Function types at the "root" are already handled. If they occur + // here, it's because the function is nested instead of a collection + // literal, which is NOT supported! badType = 'Function'; } else if (!reader.isLiteral) { badType = dartObject.type!.element2!.name; @@ -126,11 +128,32 @@ KeyConfig _from(FieldElement element, ClassConfig classAnnotation) { /// [fieldName] is not an `enum` value. String? createAnnotationValue(String fieldName, {bool mustBeEnum = false}) { final annotationValue = obj.read(fieldName); - late final DartType annotationType; - final enumFields = annotationValue.isNull - ? null - : iterateEnumFields(annotationType = annotationValue.objectValue.type!); + if (annotationValue.isNull) { + return null; + } + + final objectValue = annotationValue.objectValue; + final annotationType = objectValue.type!; + + if (annotationType is FunctionType) { + // TODO: we could be a LOT more careful here, checking the return type + // and the number of parameters. BUT! If any of those things are wrong + // the generated code will be invalid, so skipping until we're bored + // later + + final functionValue = objectValue.toFunctionValue()!; + + final invokeConst = + functionValue is ConstructorElement && functionValue.isConst + ? 'const ' + : ''; + + return '$invokeConst${functionValue.qualifiedName}()'; + } + + final enumFields = iterateEnumFields(annotationType); + if (enumFields != null) { if (mustBeEnum) { late DartType targetEnumType; @@ -170,15 +193,12 @@ KeyConfig _from(FieldElement element, ClassConfig classAnnotation) { final enumValueNames = enumFields.map((p) => p.name).toList(growable: false); - final enumValueName = enumValueForDartObject<String>( - annotationValue.objectValue, enumValueNames, (n) => n); + final enumValueName = + enumValueForDartObject<String>(objectValue, enumValueNames, (n) => n); - return '${annotationType.element2!.name}' - '.$enumValueName'; + return '${annotationType.element2!.name}.$enumValueName'; } else { - final defaultValueLiteral = annotationValue.isNull - ? null - : literalForObject(fieldName, annotationValue.objectValue, []); + final defaultValueLiteral = literalForObject(fieldName, objectValue, []); if (defaultValueLiteral == null) { return null; } diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index b8739a41d..926eb4b7d 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 6.4.2-dev +version: 6.5.0 description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. diff --git a/json_serializable/test/default_value/default_value.dart b/json_serializable/test/default_value/default_value.dart index 6b7624b35..65a8fe9ad 100644 --- a/json_serializable/test/default_value/default_value.dart +++ b/json_serializable/test/default_value/default_value.dart @@ -13,7 +13,8 @@ import 'default_value_interface.dart' ConstClass, ConstClassConverter, constClassFromJson, - constClassToJson; + constClassToJson, + intDefaultValueFunction; part 'default_value.g.dart'; @@ -72,6 +73,15 @@ class DefaultValue implements dvi.DefaultValue { @JsonKey(fromJson: constClassFromJson, toJson: constClassToJson) ConstClass valueFromFunction; + @JsonKey(defaultValue: intDefaultValueFunction) + int intDefaultValueFromFunction; + + @JsonKey(defaultValue: ConstClass.new) + ConstClass valueFromDefaultValueDefaultConstructor; + + @JsonKey(defaultValue: ConstClass.easy) + ConstClass valueFromDefaultValueNamedConstructor; + DefaultValue( this.fieldBool, this.fieldString, @@ -89,6 +99,9 @@ class DefaultValue implements dvi.DefaultValue { this.constClass = const ConstClass('value'), this.valueFromConverter = const ConstClass('value'), this.valueFromFunction = const ConstClass('value'), + required this.intDefaultValueFromFunction, + required this.valueFromDefaultValueDefaultConstructor, + required this.valueFromDefaultValueNamedConstructor, }); factory DefaultValue.fromJson(Map<String, dynamic> json) => diff --git a/json_serializable/test/default_value/default_value.g.dart b/json_serializable/test/default_value/default_value.g.dart index fef6a04c9..4cf5cda7d 100644 --- a/json_serializable/test/default_value/default_value.g.dart +++ b/json_serializable/test/default_value/default_value.g.dart @@ -49,6 +49,21 @@ DefaultValue _$DefaultValueFromJson(Map<String, dynamic> json) => DefaultValue( valueFromFunction: json['valueFromFunction'] == null ? const ConstClass('value') : constClassFromJson(json['valueFromFunction'] as String), + intDefaultValueFromFunction: + json['intDefaultValueFromFunction'] as int? ?? + intDefaultValueFunction(), + valueFromDefaultValueDefaultConstructor: + json['valueFromDefaultValueDefaultConstructor'] == null + ? const ConstClass() + : ConstClass.fromJson( + json['valueFromDefaultValueDefaultConstructor'] + as Map<String, dynamic>), + valueFromDefaultValueNamedConstructor: + json['valueFromDefaultValueNamedConstructor'] == null + ? ConstClass.easy() + : ConstClass.fromJson( + json['valueFromDefaultValueNamedConstructor'] + as Map<String, dynamic>), ); Map<String, dynamic> _$DefaultValueToJson(DefaultValue instance) => @@ -70,6 +85,11 @@ Map<String, dynamic> _$DefaultValueToJson(DefaultValue instance) => 'valueFromConverter': const ConstClassConverter().toJson(instance.valueFromConverter), 'valueFromFunction': constClassToJson(instance.valueFromFunction), + 'intDefaultValueFromFunction': instance.intDefaultValueFromFunction, + 'valueFromDefaultValueDefaultConstructor': + instance.valueFromDefaultValueDefaultConstructor, + 'valueFromDefaultValueNamedConstructor': + instance.valueFromDefaultValueNamedConstructor, }; const _$GreekEnumMap = { diff --git a/json_serializable/test/default_value/default_value.g_any_map__checked.dart b/json_serializable/test/default_value/default_value.g_any_map__checked.dart index f56aa1818..07e12fb29 100644 --- a/json_serializable/test/default_value/default_value.g_any_map__checked.dart +++ b/json_serializable/test/default_value/default_value.g_any_map__checked.dart @@ -13,7 +13,8 @@ import 'default_value_interface.dart' ConstClass, ConstClassConverter, constClassFromJson, - constClassToJson; + constClassToJson, + intDefaultValueFunction; part 'default_value.g_any_map__checked.g.dart'; @@ -75,6 +76,15 @@ class DefaultValue implements dvi.DefaultValue { @JsonKey(fromJson: constClassFromJson, toJson: constClassToJson) ConstClass valueFromFunction; + @JsonKey(defaultValue: intDefaultValueFunction) + int intDefaultValueFromFunction; + + @JsonKey(defaultValue: ConstClass.new) + ConstClass valueFromDefaultValueDefaultConstructor; + + @JsonKey(defaultValue: ConstClass.easy) + ConstClass valueFromDefaultValueNamedConstructor; + DefaultValue( this.fieldBool, this.fieldString, @@ -92,6 +102,9 @@ class DefaultValue implements dvi.DefaultValue { this.constClass = const ConstClass('value'), this.valueFromConverter = const ConstClass('value'), this.valueFromFunction = const ConstClass('value'), + required this.intDefaultValueFromFunction, + required this.valueFromDefaultValueDefaultConstructor, + required this.valueFromDefaultValueNamedConstructor, }); factory DefaultValue.fromJson(Map<String, dynamic> json) => diff --git a/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart b/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart index b06e40e86..b3a0669c9 100644 --- a/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart +++ b/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart @@ -70,6 +70,19 @@ DefaultValue _$DefaultValueFromJson(Map json) => $checkedCreate( (v) => v == null ? const ConstClass('value') : constClassFromJson(v as String)), + intDefaultValueFromFunction: $checkedConvert( + 'intDefaultValueFromFunction', + (v) => v as int? ?? intDefaultValueFunction()), + valueFromDefaultValueDefaultConstructor: $checkedConvert( + 'valueFromDefaultValueDefaultConstructor', + (v) => v == null + ? const ConstClass() + : ConstClass.fromJson(Map<String, dynamic>.from(v as Map))), + valueFromDefaultValueNamedConstructor: $checkedConvert( + 'valueFromDefaultValueNamedConstructor', + (v) => v == null + ? ConstClass.easy() + : ConstClass.fromJson(Map<String, dynamic>.from(v as Map))), ); return val; }, @@ -94,6 +107,11 @@ Map<String, dynamic> _$DefaultValueToJson(DefaultValue instance) => 'valueFromConverter': const ConstClassConverter().toJson(instance.valueFromConverter), 'valueFromFunction': constClassToJson(instance.valueFromFunction), + 'intDefaultValueFromFunction': instance.intDefaultValueFromFunction, + 'valueFromDefaultValueDefaultConstructor': + instance.valueFromDefaultValueDefaultConstructor, + 'valueFromDefaultValueNamedConstructor': + instance.valueFromDefaultValueNamedConstructor, }; const _$GreekEnumMap = { diff --git a/json_serializable/test/default_value/default_value_interface.dart b/json_serializable/test/default_value/default_value_interface.dart index 7c7a4c5ba..2a2cb1cbc 100644 --- a/json_serializable/test/default_value/default_value_interface.dart +++ b/json_serializable/test/default_value/default_value_interface.dart @@ -36,6 +36,12 @@ abstract class DefaultValue { ConstClass get valueFromConverter; ConstClass get valueFromFunction; + + int get intDefaultValueFromFunction; + + ConstClass get valueFromDefaultValueDefaultConstructor; + + ConstClass get valueFromDefaultValueNamedConstructor; } enum Greek { alpha, beta, gamma, delta } @@ -44,7 +50,9 @@ enum Greek { alpha, beta, gamma, delta } class ConstClass { final String field; - const ConstClass(this.field); + const ConstClass([this.field = 'default']); + + ConstClass.easy() : field = 'easy'; factory ConstClass.fromJson(Map<String, dynamic> json) => ConstClass( json['field'] as String, @@ -68,3 +76,5 @@ class ConstClassConverter extends JsonConverter<ConstClass, String> { @override String toJson(ConstClass object) => object.field; } + +int intDefaultValueFunction() => 43; diff --git a/json_serializable/test/default_value/default_value_test.dart b/json_serializable/test/default_value/default_value_test.dart index c345400fe..59b82fc3c 100644 --- a/json_serializable/test/default_value/default_value_test.dart +++ b/json_serializable/test/default_value/default_value_test.dart @@ -29,6 +29,9 @@ const _defaultInstance = { 'constClass': {'field': 'value'}, 'valueFromConverter': 'value', 'valueFromFunction': 'value', + 'intDefaultValueFromFunction': 43, + 'valueFromDefaultValueDefaultConstructor': {'field': 'default'}, + 'valueFromDefaultValueNamedConstructor': {'field': 'easy'}, }; const _otherValues = { @@ -50,6 +53,9 @@ const _otherValues = { 'constClass': {'field': 'otherValue'}, 'valueFromConverter': 'otherValue', 'valueFromFunction': 'otherValue', + 'intDefaultValueFromFunction': 44, + 'valueFromDefaultValueDefaultConstructor': {'field': 'other'}, + 'valueFromDefaultValueNamedConstructor': {'field': 'other'}, }; void main() { diff --git a/json_serializable/test/default_value/implicit_default_value.dart b/json_serializable/test/default_value/implicit_default_value.dart index 4159ee9fe..49bf57999 100644 --- a/json_serializable/test/default_value/implicit_default_value.dart +++ b/json_serializable/test/default_value/implicit_default_value.dart @@ -46,6 +46,12 @@ class DefaultValueImplicit implements dvi.DefaultValue { @JsonKey(fromJson: constClassFromJson, toJson: constClassToJson) ConstClass valueFromFunction; + int intDefaultValueFromFunction; + + ConstClass valueFromDefaultValueDefaultConstructor; + + ConstClass valueFromDefaultValueNamedConstructor; + DefaultValueImplicit({ this.fieldBool = true, this.fieldString = 'string', @@ -65,6 +71,9 @@ class DefaultValueImplicit implements dvi.DefaultValue { this.constClass = const ConstClass('value'), this.valueFromConverter = const ConstClass('value'), this.valueFromFunction = const ConstClass('value'), + this.intDefaultValueFromFunction = 43, + this.valueFromDefaultValueDefaultConstructor = const ConstClass(), + this.valueFromDefaultValueNamedConstructor = const ConstClass('easy'), }); factory DefaultValueImplicit.fromJson(Map<String, dynamic> json) => diff --git a/json_serializable/test/default_value/implicit_default_value.g.dart b/json_serializable/test/default_value/implicit_default_value.g.dart index 98f1de477..1a3973134 100644 --- a/json_serializable/test/default_value/implicit_default_value.g.dart +++ b/json_serializable/test/default_value/implicit_default_value.g.dart @@ -54,6 +54,20 @@ DefaultValueImplicit _$DefaultValueImplicitFromJson( valueFromFunction: json['valueFromFunction'] == null ? const ConstClass('value') : constClassFromJson(json['valueFromFunction'] as String), + intDefaultValueFromFunction: + json['intDefaultValueFromFunction'] as int? ?? 43, + valueFromDefaultValueDefaultConstructor: + json['valueFromDefaultValueDefaultConstructor'] == null + ? const ConstClass() + : ConstClass.fromJson( + json['valueFromDefaultValueDefaultConstructor'] + as Map<String, dynamic>), + valueFromDefaultValueNamedConstructor: + json['valueFromDefaultValueNamedConstructor'] == null + ? const ConstClass('easy') + : ConstClass.fromJson( + json['valueFromDefaultValueNamedConstructor'] + as Map<String, dynamic>), ); Map<String, dynamic> _$DefaultValueImplicitToJson( @@ -76,6 +90,11 @@ Map<String, dynamic> _$DefaultValueImplicitToJson( 'valueFromConverter': const ConstClassConverter().toJson(instance.valueFromConverter), 'valueFromFunction': constClassToJson(instance.valueFromFunction), + 'intDefaultValueFromFunction': instance.intDefaultValueFromFunction, + 'valueFromDefaultValueDefaultConstructor': + instance.valueFromDefaultValueDefaultConstructor, + 'valueFromDefaultValueNamedConstructor': + instance.valueFromDefaultValueNamedConstructor, }; const _$GreekEnumMap = { diff --git a/json_serializable/test/json_serializable_test.dart b/json_serializable/test/json_serializable_test.dart index 992142553..646ab4724 100644 --- a/json_serializable/test/json_serializable_test.dart +++ b/json_serializable/test/json_serializable_test.dart @@ -55,6 +55,7 @@ const _expectedAnnotatedTests = { 'DefaultWithConstObject', 'DefaultWithDisallowNullRequiredClass', 'DefaultWithFunction', + 'DefaultWithFunctionInList', 'DefaultWithNestedEnum', 'DefaultWithSymbol', 'DefaultWithToJsonClass', diff --git a/json_serializable/test/src/default_value_input.dart b/json_serializable/test/src/default_value_input.dart index 81540aa4a..a594aa761 100644 --- a/json_serializable/test/src/default_value_input.dart +++ b/json_serializable/test/src/default_value_input.dart @@ -19,10 +19,17 @@ class DefaultWithSymbol { int _function() => 42; -@ShouldThrow( - 'Error with `@JsonKey` on the `field` field. ' - '`defaultValue` is `Function`, it must be a literal.', - element: 'field', +@ShouldGenerate( + r''' +DefaultWithFunction _$DefaultWithFunctionFromJson(Map<String, dynamic> json) => + DefaultWithFunction()..field = json['field'] ?? _function(); + +Map<String, dynamic> _$DefaultWithFunctionToJson( + DefaultWithFunction instance) => + <String, dynamic>{ + 'field': instance.field, + }; +''', ) @JsonSerializable() class DefaultWithFunction { @@ -32,6 +39,19 @@ class DefaultWithFunction { DefaultWithFunction(); } +@ShouldThrow( + 'Error with `@JsonKey` on the `field` field. ' + '`defaultValue` is `List > Function`, it must be a literal.', + element: 'field', +) +@JsonSerializable() +class DefaultWithFunctionInList { + @JsonKey(defaultValue: [_function]) + Object? field; + + DefaultWithFunctionInList(); +} + @ShouldThrow( 'Error with `@JsonKey` on the `field` field. ' '`defaultValue` is `Type`, it must be a literal.', From a79c6b7ca56601aa452b37983e0d451f618edf2e Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Mon, 10 Oct 2022 10:10:37 -0700 Subject: [PATCH 445/569] Fix BigInt, DateTime, Uri JsonKey.defaultValue w/ a function (#1220) Fixes https://github.com/google/json_serializable.dart/issues/1219 Prepare to release v6.5.1 --- json_serializable/CHANGELOG.md | 5 +++ .../lib/src/type_helpers/big_int_helper.dart | 3 +- .../src/type_helpers/date_time_helper.dart | 3 +- .../lib/src/type_helpers/map_helper.dart | 3 +- .../lib/src/type_helpers/to_from_string.dart | 9 ++-- .../lib/src/type_helpers/uri_helper.dart | 3 +- json_serializable/pubspec.yaml | 2 +- .../supported_types/input.type_bigint.dart | 10 +++++ .../supported_types/input.type_bigint.g.dart | 8 ++++ .../supported_types/input.type_datetime.dart | 10 +++++ .../input.type_datetime.g.dart | 8 ++++ .../test/supported_types/input.type_uri.dart | 10 +++++ .../supported_types/input.type_uri.g.dart | 8 ++++ .../type_test.bigint_test.dart | 3 ++ .../type_test.datetime_test.dart | 3 ++ .../supported_types/type_test.uri_test.dart | 3 ++ json_serializable/tool/test_type_builder.dart | 6 +-- json_serializable/tool/test_type_data.dart | 41 +++++++++++++++++-- 18 files changed, 123 insertions(+), 15 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 37a261442..9cda69759 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,8 @@ +## 6.5.1 + +- Fixed `BigInt`, `DateTime`, and `Uri` support for `JsonKey.defaultValue` with + a function value. + ## 6.5.0 - Allow constructors to be passed to `JsonKey` parameters that support diff --git a/json_serializable/lib/src/type_helpers/big_int_helper.dart b/json_serializable/lib/src/type_helpers/big_int_helper.dart index 935c75b77..3c5c4316d 100644 --- a/json_serializable/lib/src/type_helpers/big_int_helper.dart +++ b/json_serializable/lib/src/type_helpers/big_int_helper.dart @@ -5,6 +5,7 @@ import 'package:analyzer/dart/element/type.dart'; import 'package:source_helper/source_helper.dart'; +import '../default_container.dart'; import '../type_helper.dart'; import 'to_from_string.dart'; @@ -24,7 +25,7 @@ class BigIntHelper extends TypeHelper { ); @override - String? deserialize( + DefaultContainer? deserialize( DartType targetType, String expression, TypeHelperContext context, diff --git a/json_serializable/lib/src/type_helpers/date_time_helper.dart b/json_serializable/lib/src/type_helpers/date_time_helper.dart index d67b4b2e9..89a526013 100644 --- a/json_serializable/lib/src/type_helpers/date_time_helper.dart +++ b/json_serializable/lib/src/type_helpers/date_time_helper.dart @@ -5,6 +5,7 @@ import 'package:analyzer/dart/element/type.dart'; import 'package:source_helper/source_helper.dart'; +import '../default_container.dart'; import '../type_helper.dart'; import 'to_from_string.dart'; @@ -24,7 +25,7 @@ class DateTimeHelper extends TypeHelper { ); @override - String? deserialize( + DefaultContainer? deserialize( DartType targetType, String expression, TypeHelperContext context, diff --git a/json_serializable/lib/src/type_helpers/map_helper.dart b/json_serializable/lib/src/type_helpers/map_helper.dart index 7c99fcf5a..e84bc5193 100644 --- a/json_serializable/lib/src/type_helpers/map_helper.dart +++ b/json_serializable/lib/src/type_helpers/map_helper.dart @@ -126,7 +126,8 @@ class MapHelper extends TypeHelper<TypeHelperContextWithConfig> { final toFromString = _forType(keyArg); if (toFromString != null) { - keyUsage = toFromString.deserialize(keyArg, keyUsage, false, true)!; + keyUsage = + toFromString.deserialize(keyArg, keyUsage, false, true).toString(); } return '($expression $mapCast)$optionalQuestion.map( ' diff --git a/json_serializable/lib/src/type_helpers/to_from_string.dart b/json_serializable/lib/src/type_helpers/to_from_string.dart index 68ea04a0a..5c6174ad0 100644 --- a/json_serializable/lib/src/type_helpers/to_from_string.dart +++ b/json_serializable/lib/src/type_helpers/to_from_string.dart @@ -5,7 +5,7 @@ import 'package:analyzer/dart/element/type.dart'; import 'package:source_gen/source_gen.dart'; -import '../utils.dart'; +import '../default_container.dart'; final bigIntString = ToFromStringHelper( 'BigInt.parse', @@ -64,7 +64,7 @@ class ToFromStringHelper { return '$expression.$_toString'; } - String? deserialize( + DefaultContainer? deserialize( DartType type, String expression, bool nullable, @@ -78,6 +78,9 @@ class ToFromStringHelper { final output = '$_parse($parseParam)'; - return nullable ? ifNullOrElse(expression, 'null', output) : output; + return DefaultContainer( + expression, + output, + ); } } diff --git a/json_serializable/lib/src/type_helpers/uri_helper.dart b/json_serializable/lib/src/type_helpers/uri_helper.dart index cea9e285e..49dea856a 100644 --- a/json_serializable/lib/src/type_helpers/uri_helper.dart +++ b/json_serializable/lib/src/type_helpers/uri_helper.dart @@ -5,6 +5,7 @@ import 'package:analyzer/dart/element/type.dart'; import 'package:source_helper/source_helper.dart'; +import '../default_container.dart'; import '../type_helper.dart'; import 'to_from_string.dart'; @@ -24,7 +25,7 @@ class UriHelper extends TypeHelper { ); @override - String? deserialize( + DefaultContainer? deserialize( DartType targetType, String expression, TypeHelperContext context, diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 926eb4b7d..24c3204d3 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 6.5.0 +version: 6.5.1 description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. diff --git a/json_serializable/test/supported_types/input.type_bigint.dart b/json_serializable/test/supported_types/input.type_bigint.dart index 07ab37ba4..f376da7a1 100644 --- a/json_serializable/test/supported_types/input.type_bigint.dart +++ b/json_serializable/test/supported_types/input.type_bigint.dart @@ -10,8 +10,12 @@ part 'input.type_bigint.g.dart'; class SimpleClass { final BigInt value; + @JsonKey(defaultValue: _defaultValueFunc) + BigInt withDefault; + SimpleClass( this.value, + this.withDefault, ); factory SimpleClass.fromJson(Map<String, Object?> json) => @@ -24,8 +28,12 @@ class SimpleClass { class SimpleClassNullable { final BigInt? value; + @JsonKey(defaultValue: _defaultValueFunc) + BigInt? withDefault; + SimpleClassNullable( this.value, + this.withDefault, ); factory SimpleClassNullable.fromJson(Map<String, Object?> json) => @@ -33,3 +41,5 @@ class SimpleClassNullable { Map<String, Object?> toJson() => _$SimpleClassNullableToJson(this); } + +BigInt _defaultValueFunc() => BigInt.parse('12345'); diff --git a/json_serializable/test/supported_types/input.type_bigint.g.dart b/json_serializable/test/supported_types/input.type_bigint.g.dart index 9fe750fc1..39f10c238 100644 --- a/json_serializable/test/supported_types/input.type_bigint.g.dart +++ b/json_serializable/test/supported_types/input.type_bigint.g.dart @@ -10,20 +10,28 @@ part of 'input.type_bigint.dart'; SimpleClass _$SimpleClassFromJson(Map<String, dynamic> json) => SimpleClass( BigInt.parse(json['value'] as String), + json['withDefault'] == null + ? _defaultValueFunc() + : BigInt.parse(json['withDefault'] as String), ); Map<String, dynamic> _$SimpleClassToJson(SimpleClass instance) => <String, dynamic>{ 'value': instance.value.toString(), + 'withDefault': instance.withDefault.toString(), }; SimpleClassNullable _$SimpleClassNullableFromJson(Map<String, dynamic> json) => SimpleClassNullable( json['value'] == null ? null : BigInt.parse(json['value'] as String), + json['withDefault'] == null + ? _defaultValueFunc() + : BigInt.parse(json['withDefault'] as String), ); Map<String, dynamic> _$SimpleClassNullableToJson( SimpleClassNullable instance) => <String, dynamic>{ 'value': instance.value?.toString(), + 'withDefault': instance.withDefault?.toString(), }; diff --git a/json_serializable/test/supported_types/input.type_datetime.dart b/json_serializable/test/supported_types/input.type_datetime.dart index 880c7ce89..08d2dd797 100644 --- a/json_serializable/test/supported_types/input.type_datetime.dart +++ b/json_serializable/test/supported_types/input.type_datetime.dart @@ -10,8 +10,12 @@ part 'input.type_datetime.g.dart'; class SimpleClass { final DateTime value; + @JsonKey(defaultValue: _defaultValueFunc) + DateTime withDefault; + SimpleClass( this.value, + this.withDefault, ); factory SimpleClass.fromJson(Map<String, Object?> json) => @@ -24,8 +28,12 @@ class SimpleClass { class SimpleClassNullable { final DateTime? value; + @JsonKey(defaultValue: _defaultValueFunc) + DateTime? withDefault; + SimpleClassNullable( this.value, + this.withDefault, ); factory SimpleClassNullable.fromJson(Map<String, Object?> json) => @@ -33,3 +41,5 @@ class SimpleClassNullable { Map<String, Object?> toJson() => _$SimpleClassNullableToJson(this); } + +DateTime _defaultValueFunc() => DateTime.parse('2020-01-01T00:00:00.000'); diff --git a/json_serializable/test/supported_types/input.type_datetime.g.dart b/json_serializable/test/supported_types/input.type_datetime.g.dart index f4873e041..043bce089 100644 --- a/json_serializable/test/supported_types/input.type_datetime.g.dart +++ b/json_serializable/test/supported_types/input.type_datetime.g.dart @@ -10,20 +10,28 @@ part of 'input.type_datetime.dart'; SimpleClass _$SimpleClassFromJson(Map<String, dynamic> json) => SimpleClass( DateTime.parse(json['value'] as String), + json['withDefault'] == null + ? _defaultValueFunc() + : DateTime.parse(json['withDefault'] as String), ); Map<String, dynamic> _$SimpleClassToJson(SimpleClass instance) => <String, dynamic>{ 'value': instance.value.toIso8601String(), + 'withDefault': instance.withDefault.toIso8601String(), }; SimpleClassNullable _$SimpleClassNullableFromJson(Map<String, dynamic> json) => SimpleClassNullable( json['value'] == null ? null : DateTime.parse(json['value'] as String), + json['withDefault'] == null + ? _defaultValueFunc() + : DateTime.parse(json['withDefault'] as String), ); Map<String, dynamic> _$SimpleClassNullableToJson( SimpleClassNullable instance) => <String, dynamic>{ 'value': instance.value?.toIso8601String(), + 'withDefault': instance.withDefault?.toIso8601String(), }; diff --git a/json_serializable/test/supported_types/input.type_uri.dart b/json_serializable/test/supported_types/input.type_uri.dart index fe625bbff..1be4d40f9 100644 --- a/json_serializable/test/supported_types/input.type_uri.dart +++ b/json_serializable/test/supported_types/input.type_uri.dart @@ -10,8 +10,12 @@ part 'input.type_uri.g.dart'; class SimpleClass { final Uri value; + @JsonKey(defaultValue: _defaultValueFunc) + Uri withDefault; + SimpleClass( this.value, + this.withDefault, ); factory SimpleClass.fromJson(Map<String, Object?> json) => @@ -24,8 +28,12 @@ class SimpleClass { class SimpleClassNullable { final Uri? value; + @JsonKey(defaultValue: _defaultValueFunc) + Uri? withDefault; + SimpleClassNullable( this.value, + this.withDefault, ); factory SimpleClassNullable.fromJson(Map<String, Object?> json) => @@ -33,3 +41,5 @@ class SimpleClassNullable { Map<String, Object?> toJson() => _$SimpleClassNullableToJson(this); } + +Uri _defaultValueFunc() => Uri.parse('https://example.com'); diff --git a/json_serializable/test/supported_types/input.type_uri.g.dart b/json_serializable/test/supported_types/input.type_uri.g.dart index b4c7354df..e224f7036 100644 --- a/json_serializable/test/supported_types/input.type_uri.g.dart +++ b/json_serializable/test/supported_types/input.type_uri.g.dart @@ -10,20 +10,28 @@ part of 'input.type_uri.dart'; SimpleClass _$SimpleClassFromJson(Map<String, dynamic> json) => SimpleClass( Uri.parse(json['value'] as String), + json['withDefault'] == null + ? _defaultValueFunc() + : Uri.parse(json['withDefault'] as String), ); Map<String, dynamic> _$SimpleClassToJson(SimpleClass instance) => <String, dynamic>{ 'value': instance.value.toString(), + 'withDefault': instance.withDefault.toString(), }; SimpleClassNullable _$SimpleClassNullableFromJson(Map<String, dynamic> json) => SimpleClassNullable( json['value'] == null ? null : Uri.parse(json['value'] as String), + json['withDefault'] == null + ? _defaultValueFunc() + : Uri.parse(json['withDefault'] as String), ); Map<String, dynamic> _$SimpleClassNullableToJson( SimpleClassNullable instance) => <String, dynamic>{ 'value': instance.value?.toString(), + 'withDefault': instance.withDefault?.toString(), }; diff --git a/json_serializable/test/supported_types/type_test.bigint_test.dart b/json_serializable/test/supported_types/type_test.bigint_test.dart index aa35a7d68..579298f0e 100644 --- a/json_serializable/test/supported_types/type_test.bigint_test.dart +++ b/json_serializable/test/supported_types/type_test.bigint_test.dart @@ -95,12 +95,15 @@ final _defaultInput = <String, Object?>{ final _defaultOutput = { 'value': _defaultValue, + 'withDefault': _defaultValue, }; final _nullableDefaultOutput = { 'value': null, + 'withDefault': _defaultValue, }; final _nonDefaultJson = { 'value': _altValue, + 'withDefault': _altValue, }; diff --git a/json_serializable/test/supported_types/type_test.datetime_test.dart b/json_serializable/test/supported_types/type_test.datetime_test.dart index 2be225554..5e16b81e5 100644 --- a/json_serializable/test/supported_types/type_test.datetime_test.dart +++ b/json_serializable/test/supported_types/type_test.datetime_test.dart @@ -95,12 +95,15 @@ final _defaultInput = <String, Object?>{ final _defaultOutput = { 'value': _defaultValue, + 'withDefault': _defaultValue, }; final _nullableDefaultOutput = { 'value': null, + 'withDefault': _defaultValue, }; final _nonDefaultJson = { 'value': _altValue, + 'withDefault': _altValue, }; diff --git a/json_serializable/test/supported_types/type_test.uri_test.dart b/json_serializable/test/supported_types/type_test.uri_test.dart index 28903704b..b60773780 100644 --- a/json_serializable/test/supported_types/type_test.uri_test.dart +++ b/json_serializable/test/supported_types/type_test.uri_test.dart @@ -95,12 +95,15 @@ final _defaultInput = <String, Object?>{ final _defaultOutput = { 'value': _defaultValue, + 'withDefault': _defaultValue, }; final _nullableDefaultOutput = { 'value': null, + 'withDefault': _defaultValue, }; final _nonDefaultJson = { 'value': _altValue, + 'withDefault': _altValue, }; diff --git a/json_serializable/tool/test_type_builder.dart b/json_serializable/tool/test_type_builder.dart index de9df8b2c..9ebd4a440 100644 --- a/json_serializable/tool/test_type_builder.dart +++ b/json_serializable/tool/test_type_builder.dart @@ -15,7 +15,7 @@ import 'test_type_data.dart'; final _formatter = DartFormatter(); const _trivialTypesToTest = { - 'BigInt': TestTypeData( + 'BigInt': TestTypeData.defaultFunc( jsonExpression: "'12345'", altJsonExpression: "'67890'", ), @@ -23,7 +23,7 @@ const _trivialTypesToTest = { defaultExpression: 'true', altJsonExpression: 'false', ), - 'DateTime': TestTypeData( + 'DateTime': TestTypeData.defaultFunc( jsonExpression: "'2020-01-01T00:00:00.000'", altJsonExpression: "'2018-01-01T00:00:00.000'", ), @@ -56,7 +56,7 @@ const _trivialTypesToTest = { defaultExpression: "'a string'", altJsonExpression: "'another string'", ), - 'Uri': TestTypeData( + 'Uri': TestTypeData.defaultFunc( jsonExpression: "'https://example.com'", altJsonExpression: "'https://dart.dev'", ), diff --git a/json_serializable/tool/test_type_data.dart b/json_serializable/tool/test_type_data.dart index bd310a751..f6042fe9c 100644 --- a/json_serializable/tool/test_type_data.dart +++ b/json_serializable/tool/test_type_data.dart @@ -6,6 +6,7 @@ const _annotationImport = "import 'package:json_annotation/json_annotation.dart';"; class TestTypeData { + final bool stringParseType; final String? defaultExpression; final String? jsonExpression; final String? altJsonExpression; @@ -18,7 +19,16 @@ class TestTypeData { this.genericArgs = const {}, }) : jsonExpression = jsonExpression ?? defaultExpression, altJsonExpression = - altJsonExpression ?? jsonExpression ?? defaultExpression; + altJsonExpression ?? jsonExpression ?? defaultExpression, + stringParseType = false; + + const TestTypeData.defaultFunc({ + this.jsonExpression, + required String? altJsonExpression, + }) : altJsonExpression = altJsonExpression ?? jsonExpression, + genericArgs = const {}, + defaultExpression = null, + stringParseType = true; String libContent(String source, String type) { const classAnnotationSplit = '@JsonSerializable()'; @@ -91,16 +101,39 @@ class TestTypeData { ); } + final defaultValueFuncBody = _defaultValueFuncBody(type); + + if (defaultValueFuncBody != null) { + buffer.write(defaultValueFuncBody); + } + return buffer.toString(); } + String? _defaultValueFuncBody(String type) { + if (stringParseType) { + return '$type _defaultValueFunc() => $type.parse($jsonExpression);'; + } + + return null; + } + + String? get _annotationDefaultValue { + if (stringParseType) { + return '_defaultValueFunc'; + } + + return defaultExpression; + } + Iterable<Replacement> _libReplacements(String type) sync* { yield Replacement( 'final dynamic value;', 'final $type value;', ); - final defaultNotSupported = defaultExpression == null // no default provided + final defaultNotSupported = + _annotationDefaultValue == null // no default provided || type.contains('<') // no support for default values and generic args ; @@ -108,7 +141,7 @@ class TestTypeData { final defaultReplacement = defaultNotSupported ? '' : _defaultSource - .replaceFirst('42', defaultExpression!) + .replaceFirst('42', _annotationDefaultValue!) .replaceFirst('dynamic', type); yield Replacement( @@ -187,7 +220,7 @@ final _altValue = $altJsonExpression; ''', ); - if (defaultExpression == null) { + if (defaultExpression == null && !stringParseType) { yield const Replacement( " 'withDefault': _defaultValue,\n", '', From 5107ac1df814527853ab65686dced776335bf498 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Mon, 17 Oct 2022 11:13:43 -0700 Subject: [PATCH 446/569] Improve encoding of values to handle null cases (#1223) Specifically with enums and converter functions when `includeIfNull` is `false`. Enum values with `null` as an output where not properly wrapped. This is now fixed. Fixes https://github.com/google/json_serializable.dart/issues/1202 Also 'unwrap' the cases where conversion functions never return `null`. --- json_serializable/CHANGELOG.md | 5 + json_serializable/lib/src/encoder_helper.dart | 39 +++++--- json_serializable/lib/src/enum_utils.dart | 38 ++++++-- .../lib/src/type_helper_ctx.dart | 5 +- .../lib/src/type_helpers/convert_helper.dart | 3 +- .../lib/src/type_helpers/enum_helper.dart | 3 +- .../type_helpers/json_converter_helper.dart | 18 ++++ json_serializable/pubspec.yaml | 2 +- .../test/integration/converter_examples.dart | 97 +++++++++++++++++++ .../integration/converter_examples.g.dart | 60 ++++++++++++ .../test/integration/integration_test.dart | 56 +++++++++++ .../kitchen_sink.g_exclude_null.g.dart | 31 ++---- .../test/src/to_from_json_test_input.dart | 6 +- 13 files changed, 313 insertions(+), 50 deletions(-) create mode 100644 json_serializable/test/integration/converter_examples.dart create mode 100644 json_serializable/test/integration/converter_examples.g.dart diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 9cda69759..0bf05ed6d 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,8 @@ +## 6.5.2 + +- Better handling of `null` when encoding `enum` values or values with + conversions. + ## 6.5.1 - Fixed `BigInt`, `DateTime`, and `Uri` support for `JsonKey.defaultValue` with diff --git a/json_serializable/lib/src/encoder_helper.dart b/json_serializable/lib/src/encoder_helper.dart index 9bb045852..c21c0380a 100644 --- a/json_serializable/lib/src/encoder_helper.dart +++ b/json_serializable/lib/src/encoder_helper.dart @@ -4,10 +4,10 @@ import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/nullability_suffix.dart'; -import 'package:json_annotation/json_annotation.dart'; import 'package:source_helper/source_helper.dart'; import 'constants.dart'; +import 'enum_utils.dart'; import 'helper_core.dart'; import 'type_helpers/generic_factory_helper.dart'; import 'type_helpers/json_converter_helper.dart'; @@ -163,19 +163,32 @@ abstract class EncodeHelper implements HelperCore { bool _writeJsonValueNaive(FieldElement field) { final jsonKey = jsonKeyFor(field); - return jsonKey.includeIfNull || - (!field.type.isNullableType && !_fieldHasCustomEncoder(field)); - } + if (jsonKey.includeIfNull) { + return true; + } - /// Returns `true` if [field] has a user-defined encoder. - /// - /// This can be either a `toJson` function in [JsonKey] or a [JsonConverter] - /// annotation. - bool _fieldHasCustomEncoder(FieldElement field) { final helperContext = getHelperContext(field); - return helperContext.serializeConvertData != null || - const JsonConverterHelper() - .serialize(field.type, 'test', helperContext) != - null; + + final serializeConvertData = helperContext.serializeConvertData; + if (serializeConvertData != null) { + return !serializeConvertData.returnType.isNullableType; + } + + final nullableEncodeConverter = + hasConverterNullEncode(field.type, helperContext); + + if (nullableEncodeConverter != null) { + return !nullableEncodeConverter; + } + + // We can consider enums as kinda like having custom converters + // same rules apply. If `null` is in the set of encoded values, we + // should not write naive + final enumWithNullValue = enumFieldWithNullInEncodeMap(field.type); + if (enumWithNullValue != null) { + return !enumWithNullValue; + } + + return !field.type.isNullableType; } } diff --git a/json_serializable/lib/src/enum_utils.dart b/json_serializable/lib/src/enum_utils.dart index 61ed15721..b293aba4c 100644 --- a/json_serializable/lib/src/enum_utils.dart +++ b/json_serializable/lib/src/enum_utils.dart @@ -14,9 +14,38 @@ import 'utils.dart'; String constMapName(DartType targetType) => '_\$${targetType.element2!.name}EnumMap'; +/// If [targetType] is not an enum, return `null`. +/// +/// Otherwise, returns `true` if one of the encoded values of the enum is +/// `null`. +bool? enumFieldWithNullInEncodeMap(DartType targetType) { + final enumMap = _enumMap(targetType); + + if (enumMap == null) return null; + + return enumMap.values.contains(null); +} + String? enumValueMapFromType( DartType targetType, { bool nullWithNoAnnotation = false, +}) { + final enumMap = + _enumMap(targetType, nullWithNoAnnotation: nullWithNoAnnotation); + + if (enumMap == null) return null; + + final items = enumMap.entries + .map((e) => ' ${targetType.element2!.name}.${e.key.name}: ' + '${jsonLiteralAsDart(e.value)},') + .join(); + + return 'const ${constMapName(targetType)} = {\n$items\n};'; +} + +Map<FieldElement, Object?>? _enumMap( + DartType targetType, { + bool nullWithNoAnnotation = false, }) { final annotation = _jsonEnumChecker.firstAnnotationOf(targetType.element2!); final jsonEnum = _fromAnnotation(annotation); @@ -27,7 +56,7 @@ String? enumValueMapFromType( return null; } - final enumMap = { + return { for (var field in enumFields) field: _generateEntry( field: field, @@ -35,13 +64,6 @@ String? enumValueMapFromType( targetType: targetType, ), }; - - final items = enumMap.entries - .map((e) => ' ${targetType.element2!.name}.${e.key.name}: ' - '${jsonLiteralAsDart(e.value)},') - .join(); - - return 'const ${constMapName(targetType)} = {\n$items\n};'; } Object? _generateEntry({ diff --git a/json_serializable/lib/src/type_helper_ctx.dart b/json_serializable/lib/src/type_helper_ctx.dart index 9928e459b..b49008504 100644 --- a/json_serializable/lib/src/type_helper_ctx.dart +++ b/json_serializable/lib/src/type_helper_ctx.dart @@ -135,13 +135,12 @@ ConvertData? _convertData(DartObject obj, FieldElement element, bool isFrom) { 'positional parameter.'); } + final returnType = executableElement.returnType; final argType = executableElement.parameters.first.type; if (isFrom) { final hasDefaultValue = !jsonKeyAnnotation(element).read('defaultValue').isNull; - final returnType = executableElement.returnType; - if (returnType is TypeParameterType) { // We keep things simple in this case. We rely on inferred type arguments // to the `fromJson` function. @@ -176,5 +175,5 @@ ConvertData? _convertData(DartObject obj, FieldElement element, bool isFrom) { } } - return ConvertData(executableElement.qualifiedName, argType); + return ConvertData(executableElement.qualifiedName, argType, returnType); } diff --git a/json_serializable/lib/src/type_helpers/convert_helper.dart b/json_serializable/lib/src/type_helpers/convert_helper.dart index 051f2cb9b..1918fd42a 100644 --- a/json_serializable/lib/src/type_helpers/convert_helper.dart +++ b/json_serializable/lib/src/type_helpers/convert_helper.dart @@ -14,8 +14,9 @@ import '../type_helper.dart'; class ConvertData { final String name; final DartType paramType; + final DartType returnType; - ConvertData(this.name, this.paramType); + ConvertData(this.name, this.paramType, this.returnType); } abstract class TypeHelperContextWithConvert extends TypeHelperContext { diff --git a/json_serializable/lib/src/type_helpers/enum_helper.dart b/json_serializable/lib/src/type_helpers/enum_helper.dart index 2d8e91765..ce7641fdf 100644 --- a/json_serializable/lib/src/type_helpers/enum_helper.dart +++ b/json_serializable/lib/src/type_helpers/enum_helper.dart @@ -29,7 +29,8 @@ class EnumHelper extends TypeHelper<TypeHelperContextWithConfig> { context.addMember(memberContent); - if (targetType.isNullableType) { + if (targetType.isNullableType || + enumFieldWithNullInEncodeMap(targetType) == true) { return '${constMapName(targetType)}[$expression]'; } else { return '${constMapName(targetType)}[$expression]!'; diff --git a/json_serializable/lib/src/type_helpers/json_converter_helper.dart b/json_serializable/lib/src/type_helpers/json_converter_helper.dart index 37523f42a..2b57e1e1d 100644 --- a/json_serializable/lib/src/type_helpers/json_converter_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_converter_helper.dart @@ -143,6 +143,24 @@ class _JsonConvertData { accessor.isEmpty ? '' : '.$accessor'; } +/// If there is no converter for the params, return `null`. +/// +/// Otherwise, returns `true` if the converter has a null return value. +/// +/// Used to make sure we create a smart encoding function. +bool? hasConverterNullEncode( + DartType targetType, + TypeHelperContextWithConfig ctx, +) { + final data = _typeConverter(targetType, ctx); + + if (data == null) { + return null; + } + + return data.jsonType.isNullableType; +} + _JsonConvertData? _typeConverter( DartType targetType, TypeHelperContextWithConfig ctx, diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 24c3204d3..7112acfa1 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 6.5.1 +version: 6.5.2 description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. diff --git a/json_serializable/test/integration/converter_examples.dart b/json_serializable/test/integration/converter_examples.dart new file mode 100644 index 000000000..736907cd3 --- /dev/null +++ b/json_serializable/test/integration/converter_examples.dart @@ -0,0 +1,97 @@ +import 'dart:convert'; + +import 'package:json_annotation/json_annotation.dart'; + +part 'converter_examples.g.dart'; + +@JsonEnum(valueField: 'value') +enum Issue1202RegressionEnum { + normalValue(42), + nullValue(null); + + const Issue1202RegressionEnum(this.value); + + final int? value; +} + +@JsonSerializable(includeIfNull: false) +class Issue1202RegressionClass { + @JsonKey(fromJson: _fromJson, toJson: _toJson) + final int valueWithFunctions; + + @_Issue1202RegressionNotNullConverter() + final int notNullableValueWithConverter; + + final Issue1202RegressionEnum value; + final int? normalNullableValue; + + @_Issue1202RegressionConverter() + final int notNullableValueWithNullableConverter; + + @JsonKey(fromJson: _fromJsonNullable, toJson: _toJsonNullable) + final int valueWithNullableFunctions; + + Issue1202RegressionClass({ + required this.value, + required this.normalNullableValue, + required this.notNullableValueWithNullableConverter, + required this.notNullableValueWithConverter, + required this.valueWithFunctions, + required this.valueWithNullableFunctions, + }); + + factory Issue1202RegressionClass.fromJson(Map<String, dynamic> json) => + _$Issue1202RegressionClassFromJson(json); + + Map<String, dynamic> toJson() => _$Issue1202RegressionClassToJson(this); + + @override + bool operator ==(Object other) => + other is Issue1202RegressionClass && + jsonEncode(other) == jsonEncode(this); + + @override + int get hashCode => jsonEncode(this).hashCode; + + static int _fromJsonNullable(String? json) { + if (json == null) return _default; + return int.parse(json); + } + + static String? _toJsonNullable(int object) { + if (object == _default) return null; + return object.toString(); + } + + static int _fromJson(String json) => int.parse(json); + + static String _toJson(int object) => object.toString(); +} + +const _default = 42; + +class _Issue1202RegressionConverter extends JsonConverter<int, String?> { + const _Issue1202RegressionConverter(); + + @override + int fromJson(String? json) { + if (json == null) return _default; + return int.parse(json); + } + + @override + String? toJson(int object) { + if (object == _default) return null; + return object.toString(); + } +} + +class _Issue1202RegressionNotNullConverter extends JsonConverter<int, String> { + const _Issue1202RegressionNotNullConverter(); + + @override + int fromJson(String json) => int.parse(json); + + @override + String toJson(int object) => object.toString(); +} diff --git a/json_serializable/test/integration/converter_examples.g.dart b/json_serializable/test/integration/converter_examples.g.dart new file mode 100644 index 000000000..098bc8506 --- /dev/null +++ b/json_serializable/test/integration/converter_examples.g.dart @@ -0,0 +1,60 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal + +part of 'converter_examples.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +Issue1202RegressionClass _$Issue1202RegressionClassFromJson( + Map<String, dynamic> json) => + Issue1202RegressionClass( + value: $enumDecode(_$Issue1202RegressionEnumEnumMap, json['value']), + normalNullableValue: json['normalNullableValue'] as int?, + notNullableValueWithNullableConverter: + const _Issue1202RegressionConverter().fromJson( + json['notNullableValueWithNullableConverter'] as String?), + notNullableValueWithConverter: + const _Issue1202RegressionNotNullConverter() + .fromJson(json['notNullableValueWithConverter'] as String), + valueWithFunctions: Issue1202RegressionClass._fromJson( + json['valueWithFunctions'] as String), + valueWithNullableFunctions: Issue1202RegressionClass._fromJsonNullable( + json['valueWithNullableFunctions'] as String?), + ); + +Map<String, dynamic> _$Issue1202RegressionClassToJson( + Issue1202RegressionClass instance) { + final val = <String, dynamic>{ + 'valueWithFunctions': + Issue1202RegressionClass._toJson(instance.valueWithFunctions), + 'notNullableValueWithConverter': + const _Issue1202RegressionNotNullConverter() + .toJson(instance.notNullableValueWithConverter), + }; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('value', _$Issue1202RegressionEnumEnumMap[instance.value]); + writeNotNull('normalNullableValue', instance.normalNullableValue); + writeNotNull( + 'notNullableValueWithNullableConverter', + const _Issue1202RegressionConverter() + .toJson(instance.notNullableValueWithNullableConverter)); + writeNotNull( + 'valueWithNullableFunctions', + Issue1202RegressionClass._toJsonNullable( + instance.valueWithNullableFunctions)); + return val; +} + +const _$Issue1202RegressionEnumEnumMap = { + Issue1202RegressionEnum.normalValue: 42, + Issue1202RegressionEnum.nullValue: null, +}; diff --git a/json_serializable/test/integration/integration_test.dart b/json_serializable/test/integration/integration_test.dart index ca6266dab..27fdf99ef 100644 --- a/json_serializable/test/integration/integration_test.dart +++ b/json_serializable/test/integration/integration_test.dart @@ -6,6 +6,7 @@ import 'package:json_annotation/json_annotation.dart'; import 'package:test/test.dart'; import '../test_utils.dart'; +import 'converter_examples.dart'; import 'field_map_example.dart'; import 'json_enum_example.dart'; import 'json_test_common.dart' show Category, Platform, StatusCode; @@ -358,4 +359,59 @@ void main() { {'fullName': 'full-name'}, ); }); + + group('classes with converters', () { + Issue1202RegressionClass roundTripIssue1202RegressionClass(int value) { + final instance = Issue1202RegressionClass( + normalNullableValue: value, + notNullableValueWithConverter: value, + notNullableValueWithNullableConverter: value, + value: Issue1202RegressionEnum.normalValue, + valueWithFunctions: value, + valueWithNullableFunctions: value, + ); + return roundTripObject(instance, Issue1202RegressionClass.fromJson); + } + + test('With default values', () { + final thing = roundTripIssue1202RegressionClass(42); + + expect(thing.toJson(), { + 'valueWithFunctions': '42', + 'notNullableValueWithConverter': '42', + 'value': 42, + 'normalNullableValue': 42, + }); + }); + + test('With non-default values', () { + final thing = roundTripIssue1202RegressionClass(43); + + expect(thing.toJson(), { + 'valueWithFunctions': '43', + 'notNullableValueWithConverter': '43', + 'value': 42, + 'normalNullableValue': 43, + 'notNullableValueWithNullableConverter': '43', + 'valueWithNullableFunctions': '43', + }); + }); + + test('enum with null value', () { + final instance = Issue1202RegressionClass( + normalNullableValue: 42, + notNullableValueWithConverter: 42, + notNullableValueWithNullableConverter: 42, + value: Issue1202RegressionEnum.nullValue, + valueWithFunctions: 42, + valueWithNullableFunctions: 42, + ); + + expect(instance.toJson(), { + 'valueWithFunctions': '42', + 'notNullableValueWithConverter': '42', + 'normalNullableValue': 42, + }); + }); + }); } diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart index 017e40a6a..110817593 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart @@ -190,13 +190,11 @@ Map<String, dynamic> _$JsonConverterTestClassToJson( val['durationList'] = instance.durationList .map(const DurationMillisecondConverter().toJson) .toList(); - writeNotNull('bigInt', const BigIntStringConverter().toJson(instance.bigInt)); + val['bigInt'] = const BigIntStringConverter().toJson(instance.bigInt); val['bigIntMap'] = instance.bigIntMap .map((k, e) => MapEntry(k, const BigIntStringConverter().toJson(e))); - writeNotNull( - 'nullableBigInt', - _$JsonConverterToJson<String, BigInt>( - instance.nullableBigInt, const BigIntStringConverter().toJson)); + val['nullableBigInt'] = _$JsonConverterToJson<String, BigInt>( + instance.nullableBigInt, const BigIntStringConverter().toJson); val['nullableBigIntMap'] = instance.nullableBigIntMap.map((k, e) => MapEntry( k, _$JsonConverterToJson<String, BigInt>( @@ -247,19 +245,10 @@ JsonConverterGeneric<S, T, U> _$JsonConverterGenericFromJson<S, T, U>( ); Map<String, dynamic> _$JsonConverterGenericToJson<S, T, U>( - JsonConverterGeneric<S, T, U> instance) { - final val = <String, dynamic>{}; - - void writeNotNull(String key, dynamic value) { - if (value != null) { - val[key] = value; - } - } - - writeNotNull('item', GenericConverter<S>().toJson(instance.item)); - val['itemList'] = - instance.itemList.map(GenericConverter<T>().toJson).toList(); - val['itemMap'] = instance.itemMap - .map((k, e) => MapEntry(k, GenericConverter<U>().toJson(e))); - return val; -} + JsonConverterGeneric<S, T, U> instance) => + <String, dynamic>{ + 'item': GenericConverter<S>().toJson(instance.item), + 'itemList': instance.itemList.map(GenericConverter<T>().toJson).toList(), + 'itemMap': instance.itemMap + .map((k, e) => MapEntry(k, GenericConverter<U>().toJson(e))), + }; diff --git a/json_serializable/test/src/to_from_json_test_input.dart b/json_serializable/test/src/to_from_json_test_input.dart index dafd680ea..11ce9f447 100644 --- a/json_serializable/test/src/to_from_json_test_input.dart +++ b/json_serializable/test/src/to_from_json_test_input.dart @@ -170,6 +170,8 @@ class TypedConvertMethods { late String field; } +String? _toStringNullOnEmpty(String input) => input.isEmpty ? null : input; + @ShouldGenerate( r''' Map<String, dynamic> _$ToJsonNullableFalseIncludeIfNullFalseToJson( @@ -182,14 +184,14 @@ Map<String, dynamic> _$ToJsonNullableFalseIncludeIfNullFalseToJson( } } - writeNotNull('field', _toString(instance.field)); + writeNotNull('field', _toStringNullOnEmpty(instance.field)); return val; } ''', ) @JsonSerializable(createFactory: false) class ToJsonNullableFalseIncludeIfNullFalse { - @JsonKey(toJson: _toString, includeIfNull: false) + @JsonKey(toJson: _toStringNullOnEmpty, includeIfNull: false) late String field; } From cc084e5dbd4fccbb01915d11bcfe1f95f98a6783 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Mon, 17 Oct 2022 11:26:13 -0700 Subject: [PATCH 447/569] CI: use latest mono_repo (#1224) --- .github/workflows/dart.yml | 56 +++++++++++++++++++------------------- tool/ci.sh | 2 +- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index a1692ef8f..c7b261fec 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -1,4 +1,4 @@ -# Created with package:mono_repo v6.4.1 +# Created with package:mono_repo v6.4.2 name: Dart CI on: push: @@ -21,7 +21,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@ac8075791e805656e71b4ba23325ace9e3421120 + uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:stable" @@ -34,9 +34,9 @@ jobs: sdk: stable - id: checkout name: Checkout repository - uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b + uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 - name: mono_repo self validate - run: dart pub global activate mono_repo 6.4.1 + run: dart pub global activate mono_repo 6.4.2 - name: mono_repo self validate run: dart pub global run mono_repo generate --validate job_002: @@ -44,7 +44,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@ac8075791e805656e71b4ba23325ace9e3421120 + uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.17.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:format-analyze" @@ -59,7 +59,7 @@ jobs: sdk: "2.17.0" - id: checkout name: Checkout repository - uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b + uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -130,7 +130,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@ac8075791e805656e71b4ba23325ace9e3421120 + uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:format-analyze" @@ -145,7 +145,7 @@ jobs: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b + uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -216,7 +216,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@ac8075791e805656e71b4ba23325ace9e3421120 + uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.17.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" @@ -231,7 +231,7 @@ jobs: sdk: "2.17.0" - id: checkout name: Checkout repository - uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b + uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -277,7 +277,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@ac8075791e805656e71b4ba23325ace9e3421120 + uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.17.0;packages:json_serializable;commands:test_3" @@ -292,7 +292,7 @@ jobs: sdk: "2.17.0" - id: checkout name: Checkout repository - uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b + uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -311,7 +311,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@ac8075791e805656e71b4ba23325ace9e3421120 + uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.17.0;packages:json_serializable;commands:test_1" @@ -326,7 +326,7 @@ jobs: sdk: "2.17.0" - id: checkout name: Checkout repository - uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b + uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -345,7 +345,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@ac8075791e805656e71b4ba23325ace9e3421120 + uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.17.0;packages:json_serializable;commands:test_2" @@ -360,7 +360,7 @@ jobs: sdk: "2.17.0" - id: checkout name: Checkout repository - uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b + uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -379,7 +379,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@ac8075791e805656e71b4ba23325ace9e3421120 + uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" @@ -394,7 +394,7 @@ jobs: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b + uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -440,7 +440,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@ac8075791e805656e71b4ba23325ace9e3421120 + uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:json_serializable;commands:test_3" @@ -455,7 +455,7 @@ jobs: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b + uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -474,7 +474,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@ac8075791e805656e71b4ba23325ace9e3421120 + uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:json_serializable;commands:test_1" @@ -489,7 +489,7 @@ jobs: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b + uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -508,7 +508,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@ac8075791e805656e71b4ba23325ace9e3421120 + uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:json_serializable;commands:test_2" @@ -523,7 +523,7 @@ jobs: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b + uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -542,7 +542,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@ac8075791e805656e71b4ba23325ace9e3421120 + uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.17.0;packages:_test_yaml-checked_yaml-example;commands:test_1" @@ -557,7 +557,7 @@ jobs: sdk: "2.17.0" - id: checkout name: Checkout repository - uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b + uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -602,7 +602,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@ac8075791e805656e71b4ba23325ace9e3421120 + uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:_test_yaml-checked_yaml-example;commands:test_1" @@ -617,7 +617,7 @@ jobs: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b + uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade diff --git a/tool/ci.sh b/tool/ci.sh index 79afcec7d..3b8269ea3 100755 --- a/tool/ci.sh +++ b/tool/ci.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Created with package:mono_repo v6.4.1 +# Created with package:mono_repo v6.4.2 # Support built in commands on windows out of the box. # When it is a flutter repo (check the pubspec.yaml for "sdk: flutter") From fed0f2e408263025b0133f51908cb2d5b511f161 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Mon, 17 Oct 2022 11:43:50 -0700 Subject: [PATCH 448/569] Fix build (#1225) --- _test_yaml/pubspec.yaml | 2 +- _test_yaml/test/src/build_config.g.dart | 6 +++--- example/README.md | 2 +- example/pubspec.yaml | 2 +- example/test/readme_test.dart | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/_test_yaml/pubspec.yaml b/_test_yaml/pubspec.yaml index 7989c3cb5..662de43b2 100644 --- a/_test_yaml/pubspec.yaml +++ b/_test_yaml/pubspec.yaml @@ -10,7 +10,7 @@ dev_dependencies: build_runner: ^2.0.0 build_verify: ^3.0.0 checked_yaml: any - json_annotation: ^4.4.0 + json_annotation: ^4.7.0 json_serializable: any lints: ^2.0.0 path: ^1.8.2 diff --git a/_test_yaml/test/src/build_config.g.dart b/_test_yaml/test/src/build_config.g.dart index 332000dd1..b41d7fae7 100644 --- a/_test_yaml/test/src/build_config.g.dart +++ b/_test_yaml/test/src/build_config.g.dart @@ -116,9 +116,9 @@ Map<String, dynamic> _$BuilderToJson(Builder instance) { writeNotNull('import', instance.import); writeNotNull('is_optional', instance.isOptional); writeNotNull('configLocation', instance.configLocation?.toString()); - writeNotNull('auto_apply', _$AutoApplyEnumMap[instance.autoApply]); - writeNotNull('build_to', _$BuildToEnumMap[instance.buildTo]); - writeNotNull('defaultEnumTest', _$AutoApplyEnumMap[instance.defaultEnumTest]); + val['auto_apply'] = _$AutoApplyEnumMap[instance.autoApply]; + val['build_to'] = _$BuildToEnumMap[instance.buildTo]; + val['defaultEnumTest'] = _$AutoApplyEnumMap[instance.defaultEnumTest]; val['builder_factories'] = instance.builderFactories; writeNotNull('applies_builders', instance.appliesBuilders); writeNotNull('required_inputs', instance.requiredInputs); diff --git a/example/README.md b/example/README.md index a0fe48ac6..f515f2544 100644 --- a/example/README.md +++ b/example/README.md @@ -5,7 +5,7 @@ dependencies to your `pubspec.yaml`. ```yaml dependencies: - json_annotation: ^4.4.0 + json_annotation: ^4.7.0 dev_dependencies: build_runner: ^2.0.0 diff --git a/example/pubspec.yaml b/example/pubspec.yaml index cce74537f..b3738de4b 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -5,7 +5,7 @@ environment: sdk: '>=2.17.0 <3.0.0' dependencies: - json_annotation: ^4.4.0 + json_annotation: ^4.7.0 dev_dependencies: # Used by tests. Not required to use `json_serializable`. diff --git a/example/test/readme_test.dart b/example/test/readme_test.dart index 9a98c4b63..dd4892155 100644 --- a/example/test/readme_test.dart +++ b/example/test/readme_test.dart @@ -25,7 +25,7 @@ void _expect(String fileName) { const _pubspecContent = r''' dependencies: - json_annotation: ^4.4.0 + json_annotation: ^4.7.0 dev_dependencies: build_runner: ^2.0.0 From 227da7abba3516a92a37a1e55f20b04383a0351b Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Tue, 18 Oct 2022 17:56:16 -0700 Subject: [PATCH 449/569] Fix handling of nullable `enum` fields with `includeIfNull: false` (#1227) Fixes https://github.com/google/json_serializable.dart/issues/1226 --- _test_yaml/test/src/build_config.g.dart | 6 +++--- json_serializable/CHANGELOG.md | 4 ++++ json_serializable/lib/src/enum_utils.dart | 9 +++++++-- json_serializable/pubspec.yaml | 2 +- .../test/integration/integration_test.dart | 5 +++++ .../test/integration/json_enum_example.dart | 16 ++++++++++++--- .../test/integration/json_enum_example.g.dart | 20 +++++++++++++++++++ 7 files changed, 53 insertions(+), 9 deletions(-) diff --git a/_test_yaml/test/src/build_config.g.dart b/_test_yaml/test/src/build_config.g.dart index b41d7fae7..332000dd1 100644 --- a/_test_yaml/test/src/build_config.g.dart +++ b/_test_yaml/test/src/build_config.g.dart @@ -116,9 +116,9 @@ Map<String, dynamic> _$BuilderToJson(Builder instance) { writeNotNull('import', instance.import); writeNotNull('is_optional', instance.isOptional); writeNotNull('configLocation', instance.configLocation?.toString()); - val['auto_apply'] = _$AutoApplyEnumMap[instance.autoApply]; - val['build_to'] = _$BuildToEnumMap[instance.buildTo]; - val['defaultEnumTest'] = _$AutoApplyEnumMap[instance.defaultEnumTest]; + writeNotNull('auto_apply', _$AutoApplyEnumMap[instance.autoApply]); + writeNotNull('build_to', _$BuildToEnumMap[instance.buildTo]); + writeNotNull('defaultEnumTest', _$AutoApplyEnumMap[instance.defaultEnumTest]); val['builder_factories'] = instance.builderFactories; writeNotNull('applies_builders', instance.appliesBuilders); writeNotNull('required_inputs', instance.requiredInputs); diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 0bf05ed6d..7e6aa60e6 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,7 @@ +## 6.5.3 + +- Fixed handling of nullable `enum` fields with `includeIfNull: false`. + ## 6.5.2 - Better handling of `null` when encoding `enum` values or values with diff --git a/json_serializable/lib/src/enum_utils.dart b/json_serializable/lib/src/enum_utils.dart index b293aba4c..676c8cdc0 100644 --- a/json_serializable/lib/src/enum_utils.dart +++ b/json_serializable/lib/src/enum_utils.dart @@ -7,6 +7,7 @@ import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/type.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:source_gen/source_gen.dart'; +import 'package:source_helper/source_helper.dart'; import 'json_literal_generator.dart'; import 'utils.dart'; @@ -16,13 +17,17 @@ String constMapName(DartType targetType) => /// If [targetType] is not an enum, return `null`. /// -/// Otherwise, returns `true` if one of the encoded values of the enum is -/// `null`. +/// Otherwise, returns `true` if [targetType] is nullable OR if one of the +/// encoded values of the enum is `null`. bool? enumFieldWithNullInEncodeMap(DartType targetType) { final enumMap = _enumMap(targetType); if (enumMap == null) return null; + if (targetType.isNullableType) { + return true; + } + return enumMap.values.contains(null); } diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 7112acfa1..09dda4417 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 6.5.2 +version: 6.5.3 description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. diff --git a/json_serializable/test/integration/integration_test.dart b/json_serializable/test/integration/integration_test.dart index 27fdf99ef..8aeefbfdb 100644 --- a/json_serializable/test/integration/integration_test.dart +++ b/json_serializable/test/integration/integration_test.dart @@ -414,4 +414,9 @@ void main() { }); }); }); + + test('Issue1226Regression', () { + final instance = Issue1226Regression(durationType: null); + expect(instance.toJson(), isEmpty); + }); } diff --git a/json_serializable/test/integration/json_enum_example.dart b/json_serializable/test/integration/json_enum_example.dart index a2a29bde9..7f1158f59 100644 --- a/json_serializable/test/integration/json_enum_example.dart +++ b/json_serializable/test/integration/json_enum_example.dart @@ -86,11 +86,21 @@ class Issue1145RegressionA { createFactory: false, ) class Issue1145RegressionB { - Issue1145RegressionB({ - required this.status, - }); + Issue1145RegressionB({required this.status}); Map<String, dynamic> toJson() => _$Issue1145RegressionBToJson(this); final List<Issue1145RegressionEnum?> status; } + +@JsonSerializable(includeIfNull: false) +class Issue1226Regression { + Issue1226Regression({required this.durationType}); + + factory Issue1226Regression.fromJson(Map<String, dynamic> json) => + _$Issue1226RegressionFromJson(json); + + final Issue1145RegressionEnum? durationType; + + Map<String, dynamic> toJson() => _$Issue1226RegressionToJson(this); +} diff --git a/json_serializable/test/integration/json_enum_example.g.dart b/json_serializable/test/integration/json_enum_example.g.dart index 946fe263f..932550b9b 100644 --- a/json_serializable/test/integration/json_enum_example.g.dart +++ b/json_serializable/test/integration/json_enum_example.g.dart @@ -47,6 +47,26 @@ Map<String, dynamic> _$Issue1145RegressionBToJson( .toList(), }; +Issue1226Regression _$Issue1226RegressionFromJson(Map<String, dynamic> json) => + Issue1226Regression( + durationType: $enumDecodeNullable( + _$Issue1145RegressionEnumEnumMap, json['durationType']), + ); + +Map<String, dynamic> _$Issue1226RegressionToJson(Issue1226Regression instance) { + final val = <String, dynamic>{}; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull( + 'durationType', _$Issue1145RegressionEnumEnumMap[instance.durationType]); + return val; +} + const _$StandAloneEnumEnumMap = { StandAloneEnum.alpha: 'a', StandAloneEnum.beta: 'b', From 2cfe92aff6ace73a20cd54750df036b3105f2a46 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Tue, 25 Oct 2022 11:48:28 -0700 Subject: [PATCH 450/569] Fix encoding nullable values with converters, prepare for release (#1231) Fixes https://github.com/google/json_serializable.dart/issues/1229 --- json_serializable/CHANGELOG.md | 5 +++ json_serializable/lib/src/encoder_helper.dart | 2 +- json_serializable/pubspec.yaml | 2 +- .../test/integration/converter_examples.dart | 24 +++++++++++++ .../integration/converter_examples.g.dart | 34 +++++++++++++++++++ .../test/integration/integration_test.dart | 5 +++ .../kitchen_sink.g_exclude_null.g.dart | 6 ++-- 7 files changed, 74 insertions(+), 4 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 7e6aa60e6..61f058df5 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,8 @@ +## 6.5.4 + +- Fixed handling of nullable fields with converters which return non-nullable + values. + ## 6.5.3 - Fixed handling of nullable `enum` fields with `includeIfNull: false`. diff --git a/json_serializable/lib/src/encoder_helper.dart b/json_serializable/lib/src/encoder_helper.dart index c21c0380a..581c0d48d 100644 --- a/json_serializable/lib/src/encoder_helper.dart +++ b/json_serializable/lib/src/encoder_helper.dart @@ -178,7 +178,7 @@ abstract class EncodeHelper implements HelperCore { hasConverterNullEncode(field.type, helperContext); if (nullableEncodeConverter != null) { - return !nullableEncodeConverter; + return !nullableEncodeConverter && !field.type.isNullableType; } // We can consider enums as kinda like having custom converters diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 09dda4417..04e786ec7 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 6.5.3 +version: 6.5.4 description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. diff --git a/json_serializable/test/integration/converter_examples.dart b/json_serializable/test/integration/converter_examples.dart index 736907cd3..9641b966b 100644 --- a/json_serializable/test/integration/converter_examples.dart +++ b/json_serializable/test/integration/converter_examples.dart @@ -95,3 +95,27 @@ class _Issue1202RegressionNotNullConverter extends JsonConverter<int, String> { @override String toJson(int object) => object.toString(); } + +class DateTimeConverter extends JsonConverter<DateTime, String> { + const DateTimeConverter(); + @override + DateTime fromJson(String json) => DateTime.parse(json).toLocal(); + @override + String toJson(DateTime object) => object.toUtc().toIso8601String(); +} + +@JsonSerializable() +@DateTimeConverter() +class Regression1229 { + @JsonKey(includeIfNull: false) + final DateTime? date; + + Regression1229({ + this.date, + }); + + factory Regression1229.fromJson(Map<String, dynamic> json) => + _$Regression1229FromJson(json); + + Map<String, dynamic> toJson() => _$Regression1229ToJson(this); +} diff --git a/json_serializable/test/integration/converter_examples.g.dart b/json_serializable/test/integration/converter_examples.g.dart index 098bc8506..de339009e 100644 --- a/json_serializable/test/integration/converter_examples.g.dart +++ b/json_serializable/test/integration/converter_examples.g.dart @@ -58,3 +58,37 @@ const _$Issue1202RegressionEnumEnumMap = { Issue1202RegressionEnum.normalValue: 42, Issue1202RegressionEnum.nullValue: null, }; + +Regression1229 _$Regression1229FromJson(Map<String, dynamic> json) => + Regression1229( + date: _$JsonConverterFromJson<String, DateTime>( + json['date'], const DateTimeConverter().fromJson), + ); + +Map<String, dynamic> _$Regression1229ToJson(Regression1229 instance) { + final val = <String, dynamic>{}; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull( + 'date', + _$JsonConverterToJson<String, DateTime>( + instance.date, const DateTimeConverter().toJson)); + return val; +} + +Value? _$JsonConverterFromJson<Json, Value>( + Object? json, + Value? Function(Json json) fromJson, +) => + json == null ? null : fromJson(json as Json); + +Json? _$JsonConverterToJson<Json, Value>( + Value? value, + Json? Function(Value value) toJson, +) => + value == null ? null : toJson(value); diff --git a/json_serializable/test/integration/integration_test.dart b/json_serializable/test/integration/integration_test.dart index 8aeefbfdb..0f17fe7e7 100644 --- a/json_serializable/test/integration/integration_test.dart +++ b/json_serializable/test/integration/integration_test.dart @@ -419,4 +419,9 @@ void main() { final instance = Issue1226Regression(durationType: null); expect(instance.toJson(), isEmpty); }); + + test('Regression1229', () { + final instance = Regression1229(); + expect(instance.toJson(), isEmpty); + }); } diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart index 110817593..d69950e1b 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart @@ -193,8 +193,10 @@ Map<String, dynamic> _$JsonConverterTestClassToJson( val['bigInt'] = const BigIntStringConverter().toJson(instance.bigInt); val['bigIntMap'] = instance.bigIntMap .map((k, e) => MapEntry(k, const BigIntStringConverter().toJson(e))); - val['nullableBigInt'] = _$JsonConverterToJson<String, BigInt>( - instance.nullableBigInt, const BigIntStringConverter().toJson); + writeNotNull( + 'nullableBigInt', + _$JsonConverterToJson<String, BigInt>( + instance.nullableBigInt, const BigIntStringConverter().toJson)); val['nullableBigIntMap'] = instance.nullableBigIntMap.map((k, e) => MapEntry( k, _$JsonConverterToJson<String, BigInt>( From def4b1e7f163c6fc73dd09ba375d17cbf0385734 Mon Sep 17 00:00:00 2001 From: Remi Rousselet <darky12s@gmail.com> Date: Thu, 27 Oct 2022 18:19:34 +0200 Subject: [PATCH 451/569] Upgrade analyzer to 5.2.0 and fix deprecated warnings (#1232) --- .github/workflows/dart.yml | 60 +++++++++---------- _test_yaml/pubspec.yaml | 2 +- checked_yaml/CHANGELOG.md | 2 +- checked_yaml/pubspec.yaml | 2 +- example/pubspec.yaml | 2 +- json_annotation/CHANGELOG.md | 1 + json_annotation/pubspec.yaml | 2 +- json_serializable/CHANGELOG.md | 7 ++- json_serializable/lib/src/enum_utils.dart | 12 ++-- json_serializable/lib/src/field_helpers.dart | 12 ++-- json_serializable/lib/src/helper_core.dart | 2 +- json_serializable/lib/src/json_key_utils.dart | 6 +- .../type_helpers/json_converter_helper.dart | 14 ++--- .../lib/src/type_helpers/json_helper.dart | 16 ++--- json_serializable/lib/src/utils.dart | 15 +++-- json_serializable/pubspec.yaml | 6 +- shared_test/pubspec.yaml | 2 +- 17 files changed, 84 insertions(+), 79 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index c7b261fec..2f74798c7 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -40,23 +40,23 @@ jobs: - name: mono_repo self validate run: dart pub global run mono_repo generate --validate job_002: - name: "analyzer_and_format; Dart 2.17.0; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; `dart format --output=none --set-exit-if-changed .`, `dart analyze --fatal-infos .`" + name: "analyzer_and_format; Dart 2.18.0; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; `dart format --output=none --set-exit-if-changed .`, `dart analyze --fatal-infos .`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.17.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:format-analyze" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.18.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:format-analyze" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:2.17.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable - os:ubuntu-latest;pub-cache-hosted;sdk:2.17.0 + os:ubuntu-latest;pub-cache-hosted;sdk:2.18.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable + os:ubuntu-latest;pub-cache-hosted;sdk:2.18.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: - sdk: "2.17.0" + sdk: "2.18.0" - id: checkout name: Checkout repository uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 @@ -212,23 +212,23 @@ jobs: if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" working-directory: json_serializable job_004: - name: "unit_test; Dart 2.17.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; `dart test`" + name: "unit_test; Dart 2.18.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; `dart test`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.17.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.18.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:2.17.0;packages:_test_yaml-checked_yaml-example-json_serializable - os:ubuntu-latest;pub-cache-hosted;sdk:2.17.0 + os:ubuntu-latest;pub-cache-hosted;sdk:2.18.0;packages:_test_yaml-checked_yaml-example-json_serializable + os:ubuntu-latest;pub-cache-hosted;sdk:2.18.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: - sdk: "2.17.0" + sdk: "2.18.0" - id: checkout name: Checkout repository uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 @@ -273,23 +273,23 @@ jobs: - job_002 - job_003 job_005: - name: "unit_test; Dart 2.17.0; PKG: json_serializable; `dart test --run-skipped -t presubmit-only test/annotation_version_test.dart`" + name: "unit_test; Dart 2.18.0; PKG: json_serializable; `dart test --run-skipped -t presubmit-only test/annotation_version_test.dart`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.17.0;packages:json_serializable;commands:test_3" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.18.0;packages:json_serializable;commands:test_3" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:2.17.0;packages:json_serializable - os:ubuntu-latest;pub-cache-hosted;sdk:2.17.0 + os:ubuntu-latest;pub-cache-hosted;sdk:2.18.0;packages:json_serializable + os:ubuntu-latest;pub-cache-hosted;sdk:2.18.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: - sdk: "2.17.0" + sdk: "2.18.0" - id: checkout name: Checkout repository uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 @@ -307,23 +307,23 @@ jobs: - job_002 - job_003 job_006: - name: "unit_test; Dart 2.17.0; PKG: json_serializable; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" + name: "unit_test; Dart 2.18.0; PKG: json_serializable; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.17.0;packages:json_serializable;commands:test_1" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.18.0;packages:json_serializable;commands:test_1" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:2.17.0;packages:json_serializable - os:ubuntu-latest;pub-cache-hosted;sdk:2.17.0 + os:ubuntu-latest;pub-cache-hosted;sdk:2.18.0;packages:json_serializable + os:ubuntu-latest;pub-cache-hosted;sdk:2.18.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: - sdk: "2.17.0" + sdk: "2.18.0" - id: checkout name: Checkout repository uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 @@ -341,23 +341,23 @@ jobs: - job_002 - job_003 job_007: - name: "unit_test; Dart 2.17.0; PKG: json_serializable; `dart test -p chrome`" + name: "unit_test; Dart 2.18.0; PKG: json_serializable; `dart test -p chrome`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.17.0;packages:json_serializable;commands:test_2" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.18.0;packages:json_serializable;commands:test_2" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:2.17.0;packages:json_serializable - os:ubuntu-latest;pub-cache-hosted;sdk:2.17.0 + os:ubuntu-latest;pub-cache-hosted;sdk:2.18.0;packages:json_serializable + os:ubuntu-latest;pub-cache-hosted;sdk:2.18.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: - sdk: "2.17.0" + sdk: "2.18.0" - id: checkout name: Checkout repository uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 @@ -538,23 +538,23 @@ jobs: - job_002 - job_003 job_012: - name: "ensure_build; Dart 2.17.0; PKGS: _test_yaml, checked_yaml, example; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" + name: "ensure_build; Dart 2.18.0; PKGS: _test_yaml, checked_yaml, example; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.17.0;packages:_test_yaml-checked_yaml-example;commands:test_1" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.18.0;packages:_test_yaml-checked_yaml-example;commands:test_1" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:2.17.0;packages:_test_yaml-checked_yaml-example - os:ubuntu-latest;pub-cache-hosted;sdk:2.17.0 + os:ubuntu-latest;pub-cache-hosted;sdk:2.18.0;packages:_test_yaml-checked_yaml-example + os:ubuntu-latest;pub-cache-hosted;sdk:2.18.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: - sdk: "2.17.0" + sdk: "2.18.0" - id: checkout name: Checkout repository uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 diff --git a/_test_yaml/pubspec.yaml b/_test_yaml/pubspec.yaml index 662de43b2..5e7bd31d9 100644 --- a/_test_yaml/pubspec.yaml +++ b/_test_yaml/pubspec.yaml @@ -2,7 +2,7 @@ name: _test_yaml publish_to: none environment: - sdk: '>=2.17.0 <3.0.0' + sdk: '>=2.18.0 <3.0.0' dev_dependencies: _json_serial_shared_test: diff --git a/checked_yaml/CHANGELOG.md b/checked_yaml/CHANGELOG.md index f244360ac..1b3736a4d 100644 --- a/checked_yaml/CHANGELOG.md +++ b/checked_yaml/CHANGELOG.md @@ -1,7 +1,7 @@ ## 2.0.2-dev - Require `json_annotation` `^4.3.0` -- Require Dart SDK `>=2.17` +- Require Dart SDK `>=2.18` ## 2.0.1 diff --git a/checked_yaml/pubspec.yaml b/checked_yaml/pubspec.yaml index d81ac0fe3..e9b29cb7e 100644 --- a/checked_yaml/pubspec.yaml +++ b/checked_yaml/pubspec.yaml @@ -6,7 +6,7 @@ description: >- package:json_serializable and package:yaml. repository: https://github.com/google/json_serializable.dart/tree/master/checked_yaml environment: - sdk: '>=2.17.0 <3.0.0' + sdk: '>=2.18.0 <3.0.0' dependencies: json_annotation: ^4.3.0 diff --git a/example/pubspec.yaml b/example/pubspec.yaml index b3738de4b..0c936013e 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -2,7 +2,7 @@ name: example publish_to: none environment: - sdk: '>=2.17.0 <3.0.0' + sdk: '>=2.18.0 <3.0.0' dependencies: json_annotation: ^4.7.0 diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index f5167ebc1..ce031a7d4 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -2,6 +2,7 @@ - Update `JsonKey` documentation to align with new features in `package:json_serializable`. +- Require Dart SDK `>=2.18.0`. ## 4.7.0 diff --git a/json_annotation/pubspec.yaml b/json_annotation/pubspec.yaml index 4daf681c0..5e570c130 100644 --- a/json_annotation/pubspec.yaml +++ b/json_annotation/pubspec.yaml @@ -6,7 +6,7 @@ description: >- repository: https://github.com/google/json_serializable.dart/tree/master/json_annotation environment: - sdk: '>=2.17.0 <3.0.0' + sdk: '>=2.18.0 <3.0.0' dependencies: meta: ^1.4.0 diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 61f058df5..75b2664d2 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,8 @@ +## 6.6.0-dev + +- Require Dart SDK `>=2.18.0`. +- Require `analyzer: ^5.2.0` + ## 6.5.4 - Fixed handling of nullable fields with converters which return non-nullable @@ -20,7 +25,7 @@ ## 6.5.0 - Allow constructors to be passed to `JsonKey` parameters that support - `Function` types. + `Function` types. - Accept `Function` values for `JsonKey.defaultValue`. The provided `Function` will be invoked for the default value if the target JSON element is missing or `null`. diff --git a/json_serializable/lib/src/enum_utils.dart b/json_serializable/lib/src/enum_utils.dart index 676c8cdc0..a5bc539f2 100644 --- a/json_serializable/lib/src/enum_utils.dart +++ b/json_serializable/lib/src/enum_utils.dart @@ -13,7 +13,7 @@ import 'json_literal_generator.dart'; import 'utils.dart'; String constMapName(DartType targetType) => - '_\$${targetType.element2!.name}EnumMap'; + '_\$${targetType.element!.name}EnumMap'; /// If [targetType] is not an enum, return `null`. /// @@ -41,7 +41,7 @@ String? enumValueMapFromType( if (enumMap == null) return null; final items = enumMap.entries - .map((e) => ' ${targetType.element2!.name}.${e.key.name}: ' + .map((e) => ' ${targetType.element!.name}.${e.key.name}: ' '${jsonLiteralAsDart(e.value)},') .join(); @@ -52,7 +52,7 @@ Map<FieldElement, Object?>? _enumMap( DartType targetType, { bool nullWithNoAnnotation = false, }) { - final annotation = _jsonEnumChecker.firstAnnotationOf(targetType.element2!); + final annotation = _jsonEnumChecker.firstAnnotationOf(targetType.element!); final jsonEnum = _fromAnnotation(annotation); final enumFields = iterateEnumFields(targetType); @@ -84,7 +84,7 @@ Object? _generateEntry({ if (valueField != null) { // TODO: fieldRename is pointless here!!! At least log a warning! - final fieldElementType = field.type.element2 as EnumElement; + final fieldElementType = field.type.element as EnumElement; final e = fieldElementType.getField(valueField); @@ -93,7 +93,7 @@ Object? _generateEntry({ '`JsonEnum.valueField` was set to "$valueField", but ' 'that is not a valid, instance field on ' '`${typeToCode(targetType)}`.', - element: targetType.element2, + element: targetType.element, ); } @@ -105,7 +105,7 @@ Object? _generateEntry({ throw InvalidGenerationSourceError( '`JsonEnum.valueField` was set to "$valueField", but ' 'that field does not have a type of String, int, or null.', - element: targetType.element2, + element: targetType.element, ); } } else { diff --git a/json_serializable/lib/src/field_helpers.dart b/json_serializable/lib/src/field_helpers.dart index 3e3643915..e20a8c5db 100644 --- a/json_serializable/lib/src/field_helpers.dart +++ b/json_serializable/lib/src/field_helpers.dart @@ -37,21 +37,21 @@ class _FieldSet implements Comparable<_FieldSet> { static int _sortByLocation(FieldElement a, FieldElement b) { final checkerA = TypeChecker.fromStatic( - (a.enclosingElement3 as InterfaceElement).thisType, + (a.enclosingElement as InterfaceElement).thisType, ); - if (!checkerA.isExactly(b.enclosingElement3)) { + if (!checkerA.isExactly(b.enclosingElement)) { // in this case, you want to prioritize the enclosingElement that is more // "super". - if (checkerA.isAssignableFrom(b.enclosingElement3)) { + if (checkerA.isAssignableFrom(b.enclosingElement)) { return -1; } final checkerB = TypeChecker.fromStatic( - (b.enclosingElement3 as InterfaceElement).thisType); + (b.enclosingElement as InterfaceElement).thisType); - if (checkerB.isAssignableFrom(a.enclosingElement3)) { + if (checkerB.isAssignableFrom(a.enclosingElement)) { return 1; } } @@ -83,7 +83,7 @@ Iterable<FieldElement> createSortedFieldSet(ClassElement element) { for (final v in manager.getInheritedConcreteMap2(element).values) { assert(v is! FieldElement); - if (_dartCoreObjectChecker.isExactly(v.enclosingElement3)) { + if (_dartCoreObjectChecker.isExactly(v.enclosingElement)) { continue; } diff --git a/json_serializable/lib/src/helper_core.dart b/json_serializable/lib/src/helper_core.dart index d7540668b..700cab2b3 100644 --- a/json_serializable/lib/src/helper_core.dart +++ b/json_serializable/lib/src/helper_core.dart @@ -78,7 +78,7 @@ $converterOrKeyInstructions message = '$message because of type `${typeToCode(error.type)}`'; } else { todo = ''' -To support the type `${error.type.element2!.name}` you can: +To support the type `${error.type.element!.name}` you can: $converterOrKeyInstructions'''; } diff --git a/json_serializable/lib/src/json_key_utils.dart b/json_serializable/lib/src/json_key_utils.dart index b994fa097..0df264822 100644 --- a/json_serializable/lib/src/json_key_utils.dart +++ b/json_serializable/lib/src/json_key_utils.dart @@ -63,7 +63,7 @@ KeyConfig _from(FieldElement element, ClassConfig classAnnotation) { // literal, which is NOT supported! badType = 'Function'; } else if (!reader.isLiteral) { - badType = dartObject.type!.element2!.name; + badType = dartObject.type!.element!.name; } if (badType != null) { @@ -196,7 +196,7 @@ KeyConfig _from(FieldElement element, ClassConfig classAnnotation) { final enumValueName = enumValueForDartObject<String>(objectValue, enumValueNames, (n) => n); - return '${annotationType.element2!.name}.$enumValueName'; + return '${annotationType.element!.name}.$enumValueName'; } else { final defaultValueLiteral = literalForObject(fieldName, objectValue, []); if (defaultValueLiteral == null) { @@ -300,7 +300,7 @@ bool _includeIfNull( bool _interfaceTypesEqual(DartType a, DartType b) { if (a is InterfaceType && b is InterfaceType) { // Handle nullability case. Pretty sure this is fine for enums. - return a.element2 == b.element2; + return a.element == b.element; } return a == b; } diff --git a/json_serializable/lib/src/type_helpers/json_converter_helper.dart b/json_serializable/lib/src/type_helpers/json_converter_helper.dart index 2b57e1e1d..65b06a12f 100644 --- a/json_serializable/lib/src/type_helpers/json_converter_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_converter_helper.dart @@ -217,7 +217,7 @@ _JsonConvertData? _typeConverterFrom( final annotationElement = match.elementAnnotation?.element; if (annotationElement is PropertyAccessorElement) { - final enclosing = annotationElement.enclosingElement3; + final enclosing = annotationElement.enclosingElement; var accessString = annotationElement.name; @@ -244,7 +244,7 @@ _JsonConvertData? _typeConverterFrom( if (match.genericTypeArg != null) { return _JsonConvertData.genericClass( - match.annotation.type!.element2!.name!, + match.annotation.type!.element!.name!, match.genericTypeArg!, reviver.accessor, match.jsonType, @@ -253,7 +253,7 @@ _JsonConvertData? _typeConverterFrom( } return _JsonConvertData.className( - match.annotation.type!.element2!.name!, + match.annotation.type!.element!.name!, reviver.accessor, match.jsonType, match.fieldType, @@ -281,18 +281,18 @@ _ConverterMatch? _compatibleMatch( ElementAnnotation? annotation, DartObject constantValue, ) { - final converterClassElement = constantValue.type!.element2 as ClassElement; + final converterClassElement = constantValue.type!.element as ClassElement; final jsonConverterSuper = converterClassElement.allSupertypes.singleWhereOrNull( - (e) => _jsonConverterChecker.isExactly(e.element2), + (e) => _jsonConverterChecker.isExactly(e.element), ); if (jsonConverterSuper == null) { return null; } - assert(jsonConverterSuper.element2.typeParameters.length == 2); + assert(jsonConverterSuper.element.typeParameters.length == 2); assert(jsonConverterSuper.typeArguments.length == 2); final fieldType = jsonConverterSuper.typeArguments[0]; @@ -323,7 +323,7 @@ _ConverterMatch? _compatibleMatch( annotation, constantValue, jsonConverterSuper.typeArguments[1], - '${targetType.element2.name}${targetType.isNullableType ? '?' : ''}', + '${targetType.element.name}${targetType.isNullableType ? '?' : ''}', fieldType, ); } diff --git a/json_serializable/lib/src/type_helpers/json_helper.dart b/json_serializable/lib/src/type_helpers/json_helper.dart index 426c77d14..a5d8acd13 100644 --- a/json_serializable/lib/src/type_helpers/json_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_helper.dart @@ -76,7 +76,7 @@ class JsonHelper extends TypeHelper<TypeHelperContextWithConfig> { return null; } - final classElement = targetType.element2; + final classElement = targetType.element; final fromJsonCtor = classElement.constructors .singleWhereOrNull((ce) => ce.name == 'fromJson'); @@ -152,7 +152,7 @@ List<String> _helperParams( for (var helperArg in rest) { final typeParamIndex = - type.element2.typeParameters.indexOf(helperArg.element2); + type.element.typeParameters.indexOf(helperArg.element); // TODO: throw here if `typeParamIndex` is -1 ? final typeArg = type.typeArguments[typeParamIndex]; @@ -174,7 +174,7 @@ TypeParameterType _decodeHelper( type.normalParameterTypes.length == 1) { final funcReturnType = type.returnType; - if (param.name == fromJsonForName(funcReturnType.element2!.name!)) { + if (param.name == fromJsonForName(funcReturnType.element!.name!)) { final funcParamType = type.normalParameterTypes.single; if ((funcParamType.isDartCoreObject && funcParamType.isNullableType) || @@ -205,7 +205,7 @@ TypeParameterType _encodeHelper( type.normalParameterTypes.length == 1) { final funcParamType = type.normalParameterTypes.single; - if (param.name == toJsonForName(funcParamType.element2!.name!)) { + if (param.name == toJsonForName(funcParamType.element!.name!)) { if (funcParamType is TypeParameterType) { return funcParamType; } @@ -245,7 +245,7 @@ InterfaceType? _instantiate( InterfaceType classType, ) { final argTypes = ctorParamType.typeArguments.map((arg) { - final typeParamIndex = classType.element2.typeParameters.indexWhere( + final typeParamIndex = classType.element.typeParameters.indexWhere( // TODO: not 100% sure `nullabilitySuffix` is right (e) => e.instantiate(nullabilitySuffix: arg.nullabilitySuffix) == arg); if (typeParamIndex >= 0) { @@ -261,7 +261,7 @@ InterfaceType? _instantiate( return null; } - return ctorParamType.element2.instantiate( + return ctorParamType.element.instantiate( typeArguments: argTypes.cast<DartType>(), // TODO: not 100% sure nullabilitySuffix is right... Works for now nullabilitySuffix: NullabilitySuffix.none, @@ -273,7 +273,7 @@ ClassConfig? _annotation(ClassConfig config, InterfaceType source) { return null; } final annotations = const TypeChecker.fromRuntime(JsonSerializable) - .annotationsOfExact(source.element2, throwOnUnresolved: false) + .annotationsOfExact(source.element, throwOnUnresolved: false) .toList(); if (annotations.isEmpty) { @@ -283,7 +283,7 @@ ClassConfig? _annotation(ClassConfig config, InterfaceType source) { return mergeConfig( config, ConstantReader(annotations.single), - classElement: source.element2 as ClassElement, + classElement: source.element as ClassElement, ); } diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index 7a5c479ce..f243a8c03 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -160,16 +160,15 @@ ConstructorElement constructorByName(ClassElement classElement, String name) { /// /// Otherwise, `null`. Iterable<FieldElement>? iterateEnumFields(DartType targetType) { - if (targetType is InterfaceType && targetType.element2 is EnumElement) { - return targetType.element2.fields - .where((element) => element.isEnumConstant); + if (targetType is InterfaceType && targetType.element is EnumElement) { + return targetType.element.fields.where((element) => element.isEnumConstant); } return null; } extension DartTypeExtension on DartType { DartType promoteNonNullable() => - element2?.library?.typeSystem.promoteToNonNull(this) ?? this; + element?.library?.typeSystem.promoteToNonNull(this) ?? this; } String ifNullOrElse(String test, String ifNull, String ifNotNull) => @@ -207,7 +206,7 @@ String typeToCode( return 'dynamic'; } else if (type is InterfaceType) { return [ - type.element2.name, + type.element.name, if (type.typeArguments.isNotEmpty) '<${type.typeArguments.map(typeToCode).join(', ')}>', (type.isNullableType || forceNullable) ? '?' : '', @@ -229,15 +228,15 @@ extension ExecutableElementExtension on ExecutableElement { } if (this is MethodElement) { - return '${enclosingElement3.name}.$name'; + return '${enclosingElement.name}.$name'; } if (this is ConstructorElement) { // Ignore the default constructor. if (name.isEmpty) { - return '${enclosingElement3.name}'; + return '${enclosingElement.name}'; } - return '${enclosingElement3.name}.$name'; + return '${enclosingElement.name}.$name'; } throw UnsupportedError( diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 04e786ec7..5a4097a6c 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,14 +1,14 @@ name: json_serializable -version: 6.5.4 +version: 6.5.5-dev description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. repository: https://github.com/google/json_serializable.dart/tree/master/json_serializable environment: - sdk: '>=2.17.0 <3.0.0' + sdk: '>=2.18.0 <3.0.0' dependencies: - analyzer: '>=4.6.0 <6.0.0' + analyzer: ^5.2.0 async: ^2.8.0 build: ^2.0.0 build_config: '>=0.4.4 <2.0.0' diff --git a/shared_test/pubspec.yaml b/shared_test/pubspec.yaml index 42467dbcf..92d063bd3 100644 --- a/shared_test/pubspec.yaml +++ b/shared_test/pubspec.yaml @@ -1,7 +1,7 @@ name: _json_serial_shared_test publish_to: none environment: - sdk: '>=2.17.0 <3.0.0' + sdk: '>=2.18.0 <3.0.0' dependencies: stack_trace: ^1.10.0 From f37664af948d836a10b46d55eacfa68821e06c96 Mon Sep 17 00:00:00 2001 From: Remi Rousselet <darky12s@gmail.com> Date: Thu, 3 Nov 2022 15:19:34 +0100 Subject: [PATCH 452/569] Add JsonSerializable.createPerFieldToJson (#1230) --- example/pubspec.yaml | 2 + json_annotation/CHANGELOG.md | 6 + .../lib/src/json_serializable.dart | 8 ++ .../lib/src/json_serializable.g.dart | 7 +- json_annotation/pubspec.yaml | 2 +- json_serializable/CHANGELOG.md | 1 + json_serializable/README.md | 19 +-- .../lib/src/check_dependencies.dart | 2 +- json_serializable/lib/src/decode_helper.dart | 2 +- json_serializable/lib/src/encoder_helper.dart | 63 ++++++--- .../lib/src/generator_helper.dart | 4 + json_serializable/lib/src/helper_core.dart | 4 +- .../lib/src/type_helpers/config_types.dart | 6 + json_serializable/lib/src/utils.dart | 4 + json_serializable/pubspec.yaml | 8 +- json_serializable/test/config_test.dart | 1 + .../create_per_field_to_json_example.dart | 97 +++++++++++++ .../create_per_field_to_json_example.g.dart | 127 ++++++++++++++++++ .../test/integration/integration_test.dart | 43 ++++++ json_serializable/test/shared_config.dart | 1 + .../test/test_sources/test_sources.dart | 1 + .../tool/readme/readme_template.md | 1 + 22 files changed, 376 insertions(+), 33 deletions(-) create mode 100644 json_serializable/test/integration/create_per_field_to_json_example.dart create mode 100644 json_serializable/test/integration/create_per_field_to_json_example.g.dart diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 0c936013e..758ca0b33 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -24,5 +24,7 @@ dev_dependencies: test: ^1.16.0 dependency_overrides: + json_annotation: + path: ../json_annotation json_serializable: path: ../json_serializable diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index ce031a7d4..ecd989c2b 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -1,3 +1,9 @@ +## 4.8.0-dev + +- Require Dart SDK `>=2.18.0`. +- Added `JsonSerializable.createPerFieldToJson` which allows generating + a `_$ModelPerFieldToJson`, enabling partial encoding of a model. + ## 4.7.1-dev - Update `JsonKey` documentation to align with new features in diff --git a/json_annotation/lib/src/json_serializable.dart b/json_annotation/lib/src/json_serializable.dart index 17437f349..22b8d4f93 100644 --- a/json_annotation/lib/src/json_serializable.dart +++ b/json_annotation/lib/src/json_serializable.dart @@ -87,6 +87,13 @@ class JsonSerializable { /// such as [fieldRename]. final bool? createFieldMap; + /// If `true` (defaults to false), a private, static `_$ExamplePerFieldToJson` + /// abstract class will be geenrated in the part file. + /// + /// This abstract class will contain one static function per property, + /// exposing a way to encode only this property instead of the entire object. + final bool? createPerFieldToJson; + /// If `true` (the default), A top-level function is created that you can /// reference from your class. /// @@ -249,6 +256,7 @@ class JsonSerializable { this.includeIfNull, this.converters, this.genericArgumentFactories, + this.createPerFieldToJson, }); factory JsonSerializable.fromJson(Map<String, dynamic> json) => diff --git a/json_annotation/lib/src/json_serializable.g.dart b/json_annotation/lib/src/json_serializable.g.dart index 34ecbe5b0..9d02a187c 100644 --- a/json_annotation/lib/src/json_serializable.g.dart +++ b/json_annotation/lib/src/json_serializable.g.dart @@ -19,6 +19,7 @@ JsonSerializable _$JsonSerializableFromJson(Map<String, dynamic> json) => 'constructor', 'create_factory', 'create_field_map', + 'create_per_field_to_json', 'create_to_json', 'disallow_unrecognized_keys', 'explicit_to_json', @@ -47,6 +48,8 @@ JsonSerializable _$JsonSerializableFromJson(Map<String, dynamic> json) => includeIfNull: $checkedConvert('include_if_null', (v) => v as bool?), genericArgumentFactories: $checkedConvert('generic_argument_factories', (v) => v as bool?), + createPerFieldToJson: + $checkedConvert('create_per_field_to_json', (v) => v as bool?), ); return val; }, @@ -60,7 +63,8 @@ JsonSerializable _$JsonSerializableFromJson(Map<String, dynamic> json) => 'fieldRename': 'field_rename', 'ignoreUnannotated': 'ignore_unannotated', 'includeIfNull': 'include_if_null', - 'genericArgumentFactories': 'generic_argument_factories' + 'genericArgumentFactories': 'generic_argument_factories', + 'createPerFieldToJson': 'create_per_field_to_json' }, ); @@ -71,6 +75,7 @@ Map<String, dynamic> _$JsonSerializableToJson(JsonSerializable instance) => 'constructor': instance.constructor, 'create_factory': instance.createFactory, 'create_field_map': instance.createFieldMap, + 'create_per_field_to_json': instance.createPerFieldToJson, 'create_to_json': instance.createToJson, 'disallow_unrecognized_keys': instance.disallowUnrecognizedKeys, 'explicit_to_json': instance.explicitToJson, diff --git a/json_annotation/pubspec.yaml b/json_annotation/pubspec.yaml index 5e570c130..f80c93b77 100644 --- a/json_annotation/pubspec.yaml +++ b/json_annotation/pubspec.yaml @@ -1,5 +1,5 @@ name: json_annotation -version: 4.7.1-dev +version: 4.8.0-dev description: >- Classes and helper functions that support JSON code generation via the `json_serializable` package. diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 75b2664d2..011a998c4 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -2,6 +2,7 @@ - Require Dart SDK `>=2.18.0`. - Require `analyzer: ^5.2.0` +- Require `json_annotation: '>=4.8.0 <4.9.0'` ## 6.5.4 diff --git a/json_serializable/README.md b/json_serializable/README.md index ac0eebdf7..deb8a86a7 100644 --- a/json_serializable/README.md +++ b/json_serializable/README.md @@ -279,6 +279,7 @@ targets: constructor: "" create_factory: true create_field_map: false + create_per_field_to_json: false create_to_json: true disallow_unrecognized_keys: false explicit_to_json: false @@ -299,15 +300,15 @@ targets: [`Enum`]: https://api.dart.dev/stable/dart-core/Enum-class.html [`int`]: https://api.dart.dev/stable/dart-core/int-class.html [`Iterable`]: https://api.dart.dev/stable/dart-core/Iterable-class.html -[`JsonConverter`]: https://pub.dev/documentation/json_annotation/4.7.0/json_annotation/JsonConverter-class.html -[`JsonEnum.valueField`]: https://pub.dev/documentation/json_annotation/4.7.0/json_annotation/JsonEnum/valueField.html -[`JsonEnum`]: https://pub.dev/documentation/json_annotation/4.7.0/json_annotation/JsonEnum-class.html -[`JsonKey.fromJson`]: https://pub.dev/documentation/json_annotation/4.7.0/json_annotation/JsonKey/fromJson.html -[`JsonKey.toJson`]: https://pub.dev/documentation/json_annotation/4.7.0/json_annotation/JsonKey/toJson.html -[`JsonKey`]: https://pub.dev/documentation/json_annotation/4.7.0/json_annotation/JsonKey-class.html -[`JsonLiteral`]: https://pub.dev/documentation/json_annotation/4.7.0/json_annotation/JsonLiteral-class.html -[`JsonSerializable`]: https://pub.dev/documentation/json_annotation/4.7.0/json_annotation/JsonSerializable-class.html -[`JsonValue`]: https://pub.dev/documentation/json_annotation/4.7.0/json_annotation/JsonValue-class.html +[`JsonConverter`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonConverter-class.html +[`JsonEnum.valueField`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonEnum/valueField.html +[`JsonEnum`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonEnum-class.html +[`JsonKey.fromJson`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/fromJson.html +[`JsonKey.toJson`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/toJson.html +[`JsonKey`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey-class.html +[`JsonLiteral`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonLiteral-class.html +[`JsonSerializable`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable-class.html +[`JsonValue`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonValue-class.html [`List`]: https://api.dart.dev/stable/dart-core/List-class.html [`Map`]: https://api.dart.dev/stable/dart-core/Map-class.html [`num`]: https://api.dart.dev/stable/dart-core/num-class.html diff --git a/json_serializable/lib/src/check_dependencies.dart b/json_serializable/lib/src/check_dependencies.dart index 835be668a..f69cadc8c 100644 --- a/json_serializable/lib/src/check_dependencies.dart +++ b/json_serializable/lib/src/check_dependencies.dart @@ -10,7 +10,7 @@ import 'package:pubspec_parse/pubspec_parse.dart'; const _productionDirectories = {'lib', 'bin'}; const _annotationPkgName = 'json_annotation'; -final requiredJsonAnnotationMinVersion = Version.parse('4.7.0'); +final requiredJsonAnnotationMinVersion = Version.parse('4.8.0-dev'); Future<void> pubspecHasRightVersion(BuildStep buildStep) async { final segments = buildStep.inputId.pathSegments; diff --git a/json_serializable/lib/src/decode_helper.dart b/json_serializable/lib/src/decode_helper.dart index e446e0047..daa1967cd 100644 --- a/json_serializable/lib/src/decode_helper.dart +++ b/json_serializable/lib/src/decode_helper.dart @@ -31,7 +31,7 @@ abstract class DecodeHelper implements HelperCore { final mapType = config.anyMap ? 'Map' : 'Map<String, dynamic>'; buffer.write('$targetClassReference ' - '${prefix}FromJson${genericClassArgumentsImpl(true)}' + '${prefix}FromJson${genericClassArgumentsImpl(withConstraints: true)}' '($mapType json'); if (config.genericArgumentFactories) { diff --git a/json_serializable/lib/src/encoder_helper.dart b/json_serializable/lib/src/encoder_helper.dart index 581c0d48d..289411d2e 100644 --- a/json_serializable/lib/src/encoder_helper.dart +++ b/json_serializable/lib/src/encoder_helper.dart @@ -16,6 +16,32 @@ import 'unsupported_type_error.dart'; abstract class EncodeHelper implements HelperCore { String _fieldAccess(FieldElement field) => '$_toJsonParamName.${field.name}'; + String createPerFieldToJson(Set<FieldElement> accessibleFieldSet) { + final buffer = StringBuffer() + ..writeln('// ignore: unused_element') + ..writeln('abstract class _\$${element.name.nonPrivate}PerFieldToJson {'); + + for (final field in accessibleFieldSet) { + buffer + ..writeln(' // ignore: unused_element') + ..write( + 'static Object? ${field.name}' + '${genericClassArgumentsImpl(withConstraints: true)}' + '(${field.type} $_toJsonParamName', + ); + + if (config.genericArgumentFactories) { + _writeGenericArgumentFactories(buffer); + } + + buffer.writeln(') => ${_serializeField(field, _toJsonParamName)};'); + } + + buffer.writeln('}'); + + return buffer.toString(); + } + /// Generates an object containing metadatas related to the encoding, /// destined to be used by other code-generators. String createFieldMap(Set<FieldElement> accessibleFieldSet) { @@ -42,26 +68,19 @@ abstract class EncodeHelper implements HelperCore { final buffer = StringBuffer(); - final functionName = '${prefix}ToJson${genericClassArgumentsImpl(true)}'; + final functionName = + '${prefix}ToJson${genericClassArgumentsImpl(withConstraints: true)}'; buffer.write('Map<String, dynamic> ' '$functionName($targetClassReference $_toJsonParamName'); - if (config.genericArgumentFactories) { - for (var arg in element.typeParameters) { - final helperName = toJsonForType( - arg.instantiate(nullabilitySuffix: NullabilitySuffix.none), - ); - buffer.write(',Object? Function(${arg.name} value) $helperName'); - } - if (element.typeParameters.isNotEmpty) { - buffer.write(','); - } - } + if (config.genericArgumentFactories) _writeGenericArgumentFactories(buffer); + buffer.write(') '); - final writeNaive = accessibleFields.every(_writeJsonValueNaive); + final canWriteAllJsonValuesWithoutNullCheck = + accessibleFields.every(_canWriteJsonWithoutNullCheck); - if (writeNaive) { + if (canWriteAllJsonValuesWithoutNullCheck) { // write simple `toJson` method that includes all keys... _writeToJsonSimple(buffer, accessibleFields); } else { @@ -72,6 +91,18 @@ abstract class EncodeHelper implements HelperCore { yield buffer.toString(); } + void _writeGenericArgumentFactories(StringBuffer buffer) { + for (var arg in element.typeParameters) { + final helperName = toJsonForType( + arg.instantiate(nullabilitySuffix: NullabilitySuffix.none), + ); + buffer.write(',Object? Function(${arg.name} value) $helperName'); + } + if (element.typeParameters.isNotEmpty) { + buffer.write(','); + } + } + void _writeToJsonSimple(StringBuffer buffer, Iterable<FieldElement> fields) { buffer ..writeln('=> <String, dynamic>{') @@ -112,7 +143,7 @@ abstract class EncodeHelper implements HelperCore { } final expression = _serializeField(field, safeFieldAccess); - if (_writeJsonValueNaive(field)) { + if (_canWriteJsonWithoutNullCheck(field)) { if (directWrite) { buffer.writeln(' $safeJsonKeyString: $expression,'); } else { @@ -160,7 +191,7 @@ abstract class EncodeHelper implements HelperCore { /// Returns `true` if the field can be written to JSON 'naively' – meaning /// we can avoid checking for `null`. - bool _writeJsonValueNaive(FieldElement field) { + bool _canWriteJsonWithoutNullCheck(FieldElement field) { final jsonKey = jsonKeyFor(field); if (jsonKey.includeIfNull) { diff --git a/json_serializable/lib/src/generator_helper.dart b/json_serializable/lib/src/generator_helper.dart index f4016292a..c02921a70 100644 --- a/json_serializable/lib/src/generator_helper.dart +++ b/json_serializable/lib/src/generator_helper.dart @@ -112,6 +112,10 @@ class GeneratorHelper extends HelperCore with EncodeHelper, DecodeHelper { yield createFieldMap(accessibleFieldSet); } + if (config.createPerFieldToJson) { + yield createPerFieldToJson(accessibleFieldSet); + } + if (config.createToJson) { yield* createToJson(accessibleFieldSet); } diff --git a/json_serializable/lib/src/helper_core.dart b/json_serializable/lib/src/helper_core.dart index 700cab2b3..3e6d6b88d 100644 --- a/json_serializable/lib/src/helper_core.dart +++ b/json_serializable/lib/src/helper_core.dart @@ -28,7 +28,7 @@ abstract class HelperCore { @protected String get targetClassReference => - '${element.name}${genericClassArgumentsImpl(false)}'; + '${element.name}${genericClassArgumentsImpl(withConstraints: false)}'; @protected String nameAccess(FieldElement field) => jsonKeyFor(field).name; @@ -45,7 +45,7 @@ abstract class HelperCore { /// /// Returns the output of calling [genericClassArguments] with [element]. @protected - String genericClassArgumentsImpl(bool withConstraints) => + String genericClassArgumentsImpl({required bool withConstraints}) => genericClassArguments(element, withConstraints); @protected diff --git a/json_serializable/lib/src/type_helpers/config_types.dart b/json_serializable/lib/src/type_helpers/config_types.dart index d352d16af..442a20e3c 100644 --- a/json_serializable/lib/src/type_helpers/config_types.dart +++ b/json_serializable/lib/src/type_helpers/config_types.dart @@ -46,6 +46,7 @@ class ClassConfig { final bool createFactory; final bool createToJson; final bool createFieldMap; + final bool createPerFieldToJson; final bool disallowUnrecognizedKeys; final bool explicitToJson; final FieldRename fieldRename; @@ -62,6 +63,7 @@ class ClassConfig { required this.createFactory, required this.createToJson, required this.createFieldMap, + required this.createPerFieldToJson, required this.disallowUnrecognizedKeys, required this.explicitToJson, required this.fieldRename, @@ -80,6 +82,8 @@ class ClassConfig { constructor: config.constructor ?? ClassConfig.defaults.constructor, createFieldMap: config.createFieldMap ?? ClassConfig.defaults.createFieldMap, + createPerFieldToJson: config.createPerFieldToJson ?? + ClassConfig.defaults.createPerFieldToJson, createFactory: config.createFactory ?? ClassConfig.defaults.createFactory, createToJson: config.createToJson ?? ClassConfig.defaults.createToJson, @@ -106,6 +110,7 @@ class ClassConfig { createFactory: true, createToJson: true, createFieldMap: false, + createPerFieldToJson: false, disallowUnrecognizedKeys: false, explicitToJson: false, fieldRename: FieldRename.none, @@ -121,6 +126,7 @@ class ClassConfig { createFactory: createFactory, createToJson: createToJson, createFieldMap: createFieldMap, + createPerFieldToJson: createPerFieldToJson, ignoreUnannotated: ignoreUnannotated, explicitToJson: explicitToJson, includeIfNull: includeIfNull, diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index f243a8c03..56ec6a45a 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -57,6 +57,8 @@ JsonSerializable _valueForAnnotation(ConstantReader reader) => JsonSerializable( createFactory: reader.read('createFactory').literalValue as bool?, createToJson: reader.read('createToJson').literalValue as bool?, createFieldMap: reader.read('createFieldMap').literalValue as bool?, + createPerFieldToJson: + reader.read('createPerFieldToJson').literalValue as bool?, disallowUnrecognizedKeys: reader.read('disallowUnrecognizedKeys').literalValue as bool?, explicitToJson: reader.read('explicitToJson').literalValue as bool?, @@ -103,6 +105,8 @@ ClassConfig mergeConfig( createFactory: annotation.createFactory ?? config.createFactory, createToJson: annotation.createToJson ?? config.createToJson, createFieldMap: annotation.createFieldMap ?? config.createFieldMap, + createPerFieldToJson: + annotation.createPerFieldToJson ?? config.createPerFieldToJson, disallowUnrecognizedKeys: annotation.disallowUnrecognizedKeys ?? config.disallowUnrecognizedKeys, explicitToJson: annotation.explicitToJson ?? config.explicitToJson, diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 5a4097a6c..2c491cbd1 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 6.5.5-dev +version: 6.6.0-dev description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. @@ -16,7 +16,7 @@ dependencies: # Use a tight version constraint to ensure that a constraint on # `json_annotation` properly constrains all features it provides. - json_annotation: '>=4.7.0 <4.8.0' + json_annotation: '>=4.8.0-dev <4.9.0' meta: ^1.3.0 path: ^1.8.0 pub_semver: ^2.0.0 @@ -37,3 +37,7 @@ dev_dependencies: test_descriptor: ^2.0.0 test_process: ^2.0.0 yaml: ^3.0.0 + +dependency_overrides: + json_annotation: + path: ../json_annotation \ No newline at end of file diff --git a/json_serializable/test/config_test.dart b/json_serializable/test/config_test.dart index d98942607..5c8dcef0e 100644 --- a/json_serializable/test/config_test.dart +++ b/json_serializable/test/config_test.dart @@ -157,6 +157,7 @@ const _invalidConfig = { 'constructor': 42, 'create_factory': 42, 'create_field_map': 42, + 'create_per_field_to_json': 42, 'create_to_json': 42, 'disallow_unrecognized_keys': 42, 'explicit_to_json': 42, diff --git a/json_serializable/test/integration/create_per_field_to_json_example.dart b/json_serializable/test/integration/create_per_field_to_json_example.dart new file mode 100644 index 000000000..80a306124 --- /dev/null +++ b/json_serializable/test/integration/create_per_field_to_json_example.dart @@ -0,0 +1,97 @@ +import 'package:json_annotation/json_annotation.dart'; + +part 'create_per_field_to_json_example.g.dart'; + +@JsonSerializable( + createPerFieldToJson: true, + explicitToJson: true, +) +class Model { + Model({ + required this.firstName, + required this.lastName, + this.ignoredName, + this.enumValue, + this.nested, + this.nestedExcludeIfNull, + this.nestedGeneric, + }); + + factory Model.fromJson(Map<String, Object?> json) => _$ModelFromJson(json); + + final String firstName; + final String lastName; + final EnumValue? enumValue; + final Nested? nested; + final GenericFactory<int>? nestedGeneric; + + @JsonKey(includeIfNull: false) + final Nested? nestedExcludeIfNull; + + @JsonKey(ignore: true) + final String? ignoredName; + + String get fullName => '$firstName $lastName'; + + Map<String, Object?> toJson() => _$ModelToJson(this); +} + +typedef ModelPerFieldToJson = _$ModelPerFieldToJson; + +@JsonEnum() +enum EnumValue { + @JsonValue('1') + first, + second, +} + +@JsonSerializable() +class Nested { + Nested(this.value); + + factory Nested.fromJson(Map<String, Object?> json) => _$NestedFromJson(json); + + final String value; + + Map<String, Object?> toJson() => _$NestedToJson(this); +} + +@JsonSerializable( + createPerFieldToJson: true, + genericArgumentFactories: true, +) +class GenericFactory<T> { + GenericFactory( + this.value, + this.map, + ); + + factory GenericFactory.fromJson( + Map<String, Object?> json, + T Function(Object? json) fromJsonT, + ) => + _$GenericFactoryFromJson(json, fromJsonT); + + final T value; + final Map<String, T> map; + + Map<String, Object?> toJson(Object? Function(T value) toJsonT) => + _$GenericFactoryToJson(this, toJsonT); +} + +typedef GenericFactoryPerFieldToJson = _$GenericFactoryPerFieldToJson; + +@JsonSerializable( + createPerFieldToJson: true, + fieldRename: FieldRename.kebab, + createFactory: false, +) +class _PrivateModel { + _PrivateModel(this.fullName); + + final String fullName; + + Map<String, Object?> toJson() => _$PrivateModelToJson(this); +} + +typedef PrivatePerFieldToJson = _$PrivateModelPerFieldToJson; diff --git a/json_serializable/test/integration/create_per_field_to_json_example.g.dart b/json_serializable/test/integration/create_per_field_to_json_example.g.dart new file mode 100644 index 000000000..29c4baa7b --- /dev/null +++ b/json_serializable/test/integration/create_per_field_to_json_example.g.dart @@ -0,0 +1,127 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal + +part of 'create_per_field_to_json_example.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +Model _$ModelFromJson(Map<String, dynamic> json) => Model( + firstName: json['firstName'] as String, + lastName: json['lastName'] as String, + enumValue: $enumDecodeNullable(_$EnumValueEnumMap, json['enumValue']), + nested: json['nested'] == null + ? null + : Nested.fromJson(json['nested'] as Map<String, dynamic>), + nestedExcludeIfNull: json['nestedExcludeIfNull'] == null + ? null + : Nested.fromJson( + json['nestedExcludeIfNull'] as Map<String, dynamic>), + nestedGeneric: json['nestedGeneric'] == null + ? null + : GenericFactory<int>.fromJson( + json['nestedGeneric'] as Map<String, dynamic>, + (value) => value as int), + ); + +// ignore: unused_element +abstract class _$ModelPerFieldToJson { + // ignore: unused_element + static Object? firstName(String instance) => instance; + // ignore: unused_element + static Object? lastName(String instance) => instance; + // ignore: unused_element + static Object? enumValue(EnumValue? instance) => _$EnumValueEnumMap[instance]; + // ignore: unused_element + static Object? nested(Nested? instance) => instance?.toJson(); + // ignore: unused_element + static Object? nestedGeneric(GenericFactory<int>? instance) => + instance?.toJson( + (value) => value, + ); + // ignore: unused_element + static Object? nestedExcludeIfNull(Nested? instance) => instance?.toJson(); +} + +Map<String, dynamic> _$ModelToJson(Model instance) { + final val = <String, dynamic>{ + 'firstName': instance.firstName, + 'lastName': instance.lastName, + 'enumValue': _$EnumValueEnumMap[instance.enumValue], + 'nested': instance.nested?.toJson(), + 'nestedGeneric': instance.nestedGeneric?.toJson( + (value) => value, + ), + }; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('nestedExcludeIfNull', instance.nestedExcludeIfNull?.toJson()); + return val; +} + +const _$EnumValueEnumMap = { + EnumValue.first: '1', + EnumValue.second: 'second', +}; + +Nested _$NestedFromJson(Map<String, dynamic> json) => Nested( + json['value'] as String, + ); + +Map<String, dynamic> _$NestedToJson(Nested instance) => <String, dynamic>{ + 'value': instance.value, + }; + +GenericFactory<T> _$GenericFactoryFromJson<T>( + Map<String, dynamic> json, + T Function(Object? json) fromJsonT, +) => + GenericFactory<T>( + fromJsonT(json['value']), + (json['map'] as Map<String, dynamic>).map( + (k, e) => MapEntry(k, fromJsonT(e)), + ), + ); + +// ignore: unused_element +abstract class _$GenericFactoryPerFieldToJson { + // ignore: unused_element + static Object? value<T>( + T instance, + Object? Function(T value) toJsonT, + ) => + toJsonT(instance); + // ignore: unused_element + static Object? map<T>( + Map<String, T> instance, + Object? Function(T value) toJsonT, + ) => + instance.map((k, e) => MapEntry(k, toJsonT(e))); +} + +Map<String, dynamic> _$GenericFactoryToJson<T>( + GenericFactory<T> instance, + Object? Function(T value) toJsonT, +) => + <String, dynamic>{ + 'value': toJsonT(instance.value), + 'map': instance.map.map((k, e) => MapEntry(k, toJsonT(e))), + }; + +// ignore: unused_element +abstract class _$PrivateModelPerFieldToJson { + // ignore: unused_element + static Object? fullName(String instance) => instance; +} + +Map<String, dynamic> _$PrivateModelToJson(_PrivateModel instance) => + <String, dynamic>{ + 'full-name': instance.fullName, + }; diff --git a/json_serializable/test/integration/integration_test.dart b/json_serializable/test/integration/integration_test.dart index 0f17fe7e7..596822024 100644 --- a/json_serializable/test/integration/integration_test.dart +++ b/json_serializable/test/integration/integration_test.dart @@ -7,6 +7,7 @@ import 'package:test/test.dart'; import '../test_utils.dart'; import 'converter_examples.dart'; +import 'create_per_field_to_json_example.dart'; import 'field_map_example.dart'; import 'json_enum_example.dart'; import 'json_test_common.dart' show Category, Platform, StatusCode; @@ -360,6 +361,48 @@ void main() { ); }); + test(r'_$ModelPerFieldToJson', () { + expect(ModelPerFieldToJson.firstName('foo'), 'foo'); + + expect(ModelPerFieldToJson.enumValue(EnumValue.first), '1'); + expect(ModelPerFieldToJson.enumValue(EnumValue.second), 'second'); + + expect(ModelPerFieldToJson.nested(Nested('foo')), {'value': 'foo'}); + expect(ModelPerFieldToJson.nested(null), null); + expect( + ModelPerFieldToJson.nestedExcludeIfNull(Nested('foo')), + {'value': 'foo'}, + ); + expect(ModelPerFieldToJson.nestedExcludeIfNull(null), null); + expect( + ModelPerFieldToJson.nestedGeneric(GenericFactory(42, {'key': 21})), + { + 'value': 42, + 'map': {'key': 21}, + }, + ); + }); + + test(r'_$GenericFactoryPerFieldToJson', () { + expect( + GenericFactoryPerFieldToJson.value<int>(42, (value) => '$value'), + '42', + ); + expect( + GenericFactoryPerFieldToJson.value<String>('42', int.tryParse), + 42, + ); + + expect( + GenericFactoryPerFieldToJson.map<int>({'foo': 21}, (value) => '$value'), + {'foo': '21'}, + ); + expect( + GenericFactoryPerFieldToJson.map<String>({'key': '42'}, int.tryParse), + {'key': 42}, + ); + }); + group('classes with converters', () { Issue1202RegressionClass roundTripIssue1202RegressionClass(int value) { final instance = Issue1202RegressionClass( diff --git a/json_serializable/test/shared_config.dart b/json_serializable/test/shared_config.dart index e387488e9..957728da3 100644 --- a/json_serializable/test/shared_config.dart +++ b/json_serializable/test/shared_config.dart @@ -20,6 +20,7 @@ final generatorConfigNonDefaultJson = createFactory: false, createToJson: false, createFieldMap: true, + createPerFieldToJson: true, disallowUnrecognizedKeys: true, explicitToJson: true, fieldRename: FieldRename.kebab, diff --git a/json_serializable/test/test_sources/test_sources.dart b/json_serializable/test/test_sources/test_sources.dart index 3d3c3b368..06cc495f3 100644 --- a/json_serializable/test/test_sources/test_sources.dart +++ b/json_serializable/test/test_sources/test_sources.dart @@ -16,6 +16,7 @@ class ConfigurationImplicitDefaults { createFactory: true, createToJson: true, createFieldMap: false, + createPerFieldToJson: false, disallowUnrecognizedKeys: false, explicitToJson: false, fieldRename: FieldRename.none, diff --git a/json_serializable/tool/readme/readme_template.md b/json_serializable/tool/readme/readme_template.md index 8af2bac78..d8de00352 100644 --- a/json_serializable/tool/readme/readme_template.md +++ b/json_serializable/tool/readme/readme_template.md @@ -144,6 +144,7 @@ targets: constructor: "" create_factory: true create_field_map: false + create_per_field_to_json: false create_to_json: true disallow_unrecognized_keys: false explicit_to_json: false From 916a9bf60120ed15c16afb4296ac8d02c7696e8b Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Thu, 3 Nov 2022 07:25:03 -0700 Subject: [PATCH 453/569] Update dependabot.yml (#1237) --- .github/dependabot.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 3be9dfa64..2a0f49229 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -7,5 +7,4 @@ updates: - package-ecosystem: "github-actions" directory: "/" schedule: - # Check for updates to GitHub Actions weekly interval: "monthly" From ce62f8690043f340cd3c457ea70010d9031540f8 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Thu, 10 Nov 2022 19:14:16 -0800 Subject: [PATCH 454/569] Fix actions in markdown_linter (#1240) Closes https://github.com/google/json_serializable.dart/pull/1235 --- .github/workflows/markdown_linter.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/markdown_linter.yml b/.github/workflows/markdown_linter.yml index 4cb0e7e6f..3ec98ad09 100644 --- a/.github/workflows/markdown_linter.yml +++ b/.github/workflows/markdown_linter.yml @@ -11,7 +11,7 @@ jobs: markdown-link-check: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3.0.2 + - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 - uses: gaurav-nelson/github-action-markdown-link-check@v1 markdown_lint: runs-on: ubuntu-latest @@ -19,9 +19,9 @@ jobs: matrix: node-version: [ 14.x ] steps: - - uses: actions/checkout@v3.0.2 + - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v3 + uses: actions/setup-node@8c91899e586c5b171469028077307d293428b516 with: node-version: ${{ matrix.node-version }} - name: Install dependencies From ae72ad64bbe8578ee00528df667025afea0b1e28 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Tue, 15 Nov 2022 10:12:14 -0800 Subject: [PATCH 455/569] Cleanup .gitignore (#1247) --- .gitignore | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 43dbe764a..c5a0d2502 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,3 @@ +# https://dart.dev/guides/libraries/private-files .dart_tool -.packages -.pub -packages pubspec.lock From f35aceb04174e58cd7ae8c0c77709e54af54dd2f Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Tue, 15 Nov 2022 10:14:47 -0800 Subject: [PATCH 456/569] annotation: fix changelog (#1246) --- json_annotation/CHANGELOG.md | 4 ---- json_serializable/lib/src/check_dependencies.dart | 2 +- json_serializable/pubspec.yaml | 2 +- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index ecd989c2b..da3bf8ce4 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -1,11 +1,7 @@ ## 4.8.0-dev -- Require Dart SDK `>=2.18.0`. - Added `JsonSerializable.createPerFieldToJson` which allows generating a `_$ModelPerFieldToJson`, enabling partial encoding of a model. - -## 4.7.1-dev - - Update `JsonKey` documentation to align with new features in `package:json_serializable`. - Require Dart SDK `>=2.18.0`. diff --git a/json_serializable/lib/src/check_dependencies.dart b/json_serializable/lib/src/check_dependencies.dart index f69cadc8c..86e580bea 100644 --- a/json_serializable/lib/src/check_dependencies.dart +++ b/json_serializable/lib/src/check_dependencies.dart @@ -10,7 +10,7 @@ import 'package:pubspec_parse/pubspec_parse.dart'; const _productionDirectories = {'lib', 'bin'}; const _annotationPkgName = 'json_annotation'; -final requiredJsonAnnotationMinVersion = Version.parse('4.8.0-dev'); +final requiredJsonAnnotationMinVersion = Version.parse('4.8.0'); Future<void> pubspecHasRightVersion(BuildStep buildStep) async { final segments = buildStep.inputId.pathSegments; diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 2c491cbd1..85ab370d5 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -16,7 +16,7 @@ dependencies: # Use a tight version constraint to ensure that a constraint on # `json_annotation` properly constrains all features it provides. - json_annotation: '>=4.8.0-dev <4.9.0' + json_annotation: '>=4.8.0 <4.9.0' meta: ^1.3.0 path: ^1.8.0 pub_semver: ^2.0.0 From caf3a15e708845687915751172873f5709e2d3d9 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Thu, 17 Nov 2022 12:26:22 -0800 Subject: [PATCH 457/569] Support `JsonEnum.valueField` being set with `'index'` (#1250) Fixes https://github.com/google/json_serializable.dart/issues/1249 --- json_serializable/CHANGELOG.md | 1 + json_serializable/lib/src/enum_utils.dart | 7 +++++++ .../test/integration/integration_test.dart | 4 ++++ .../test/integration/json_enum_example.dart | 17 +++++++++++++++++ .../test/integration/json_enum_example.g.dart | 6 ++++++ 5 files changed, 35 insertions(+) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 011a998c4..6a18f57c4 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,5 +1,6 @@ ## 6.6.0-dev +- Support `JsonEnum.valueField` being set with `'index'`. - Require Dart SDK `>=2.18.0`. - Require `analyzer: ^5.2.0` - Require `json_annotation: '>=4.8.0 <4.9.0'` diff --git a/json_serializable/lib/src/enum_utils.dart b/json_serializable/lib/src/enum_utils.dart index a5bc539f2..9b27334b0 100644 --- a/json_serializable/lib/src/enum_utils.dart +++ b/json_serializable/lib/src/enum_utils.dart @@ -88,6 +88,13 @@ Object? _generateEntry({ final e = fieldElementType.getField(valueField); + if (e == null && valueField == 'index') { + return fieldElementType.fields + .where((element) => element.isEnumConstant) + .toList(growable: false) + .indexOf(field); + } + if (e == null || e.isStatic) { throw InvalidGenerationSourceError( '`JsonEnum.valueField` was set to "$valueField", but ' diff --git a/json_serializable/test/integration/integration_test.dart b/json_serializable/test/integration/integration_test.dart index 596822024..76b01f8fa 100644 --- a/json_serializable/test/integration/integration_test.dart +++ b/json_serializable/test/integration/integration_test.dart @@ -467,4 +467,8 @@ void main() { final instance = Regression1229(); expect(instance.toJson(), isEmpty); }); + + test('value field index fun', () { + expect(enumValueFieldIndexValues, [0, 701, 2]); + }); } diff --git a/json_serializable/test/integration/json_enum_example.dart b/json_serializable/test/integration/json_enum_example.dart index 7f1158f59..9f8cee0a8 100644 --- a/json_serializable/test/integration/json_enum_example.dart +++ b/json_serializable/test/integration/json_enum_example.dart @@ -38,6 +38,23 @@ enum MyStatusCode { Iterable<int> get myStatusCodeEnumValues => _$MyStatusCodeEnumMap.values; +@JsonEnum(alwaysCreate: true, valueField: 'index') +enum EnumValueFieldIndex { + success(200), + @JsonValue(701) // explicit value always takes precedence + weird(601), + oneMore(777); + + static const tryingToBeConfusing = weird; + + const EnumValueFieldIndex(this.value); + + final int value; +} + +Iterable<int> get enumValueFieldIndexValues => + _$EnumValueFieldIndexEnumMap.values; + @JsonSerializable( createToJson: false, ) diff --git a/json_serializable/test/integration/json_enum_example.g.dart b/json_serializable/test/integration/json_enum_example.g.dart index 932550b9b..818e057ae 100644 --- a/json_serializable/test/integration/json_enum_example.g.dart +++ b/json_serializable/test/integration/json_enum_example.g.dart @@ -84,3 +84,9 @@ const _$MyStatusCodeEnumMap = { MyStatusCode.success: 200, MyStatusCode.weird: 701, }; + +const _$EnumValueFieldIndexEnumMap = { + EnumValueFieldIndex.success: 0, + EnumValueFieldIndex.weird: 701, + EnumValueFieldIndex.oneMore: 2, +}; From 16284aa541a835c8b368091d793b2956ebfd8741 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Thu, 17 Nov 2022 15:27:15 -0800 Subject: [PATCH 458/569] Update re-response logic (#1253) --- .github/no-response.yml | 16 --------------- .github/workflows/no-response.yml | 33 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 16 deletions(-) delete mode 100644 .github/no-response.yml create mode 100644 .github/workflows/no-response.yml diff --git a/.github/no-response.yml b/.github/no-response.yml deleted file mode 100644 index b5567e94c..000000000 --- a/.github/no-response.yml +++ /dev/null @@ -1,16 +0,0 @@ -# Configuration for probot-no-response - https://github.com/probot/no-response - -# Number of days of inactivity before an issue is closed for lack of response. -daysUntilClose: 21 - -# Label requiring a response. -responseRequiredLabel: "State: needs info" - -# Comment to post when closing an Issue for lack of response. -closeComment: >- - Without additional information, we are unfortunately not sure how to - resolve this issue. We are therefore reluctantly going to close this - bug for now. Please don't hesitate to comment on the bug if you have - any more information for us; we will reopen it right away! - - Thanks for your contribution. diff --git a/.github/workflows/no-response.yml b/.github/workflows/no-response.yml new file mode 100644 index 000000000..23b3a75ef --- /dev/null +++ b/.github/workflows/no-response.yml @@ -0,0 +1,33 @@ +# A workflow to close issues where the author hasn't responded to a request for +# more information; see https://github.com/godofredoc/no-response for docs. + +name: No Response + +# Both `issue_comment` and `scheduled` event types are required. +on: + issue_comment: + types: [created] + schedule: + # Schedule for five minutes after the hour, every hour + - cron: '5 * * * *' + +# All permissions not specified are set to 'none'. +permissions: + issues: write + +jobs: + noResponse: + runs-on: ubuntu-latest + if: ${{ github.repository_owner == 'google' }} + steps: + - uses: godofredoc/no-response@0ce2dc0e63e1c7d2b87752ceed091f6d32c9df09 + with: + responseRequiredLabel: "State: needs info" + daysUntilClose: 14 + # Comment to post when closing an Issue for lack of response. + closeComment: > + Without additional information we're not able to resolve this + issue, so it will be closed at this time. You're still free to add + more info and respond to any questions above, though. We'll reopen + the case if you do. Thanks for your contribution! + token: ${{ github.token }} From f6614d3962560546ad45c00fa6c1ae75f9f6add8 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@google.com> Date: Mon, 21 Nov 2022 14:11:50 -0800 Subject: [PATCH 459/569] Refactor some enum helpers --- json_serializable/lib/src/enum_utils.dart | 6 +----- json_serializable/lib/src/utils.dart | 17 +++++++++-------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/json_serializable/lib/src/enum_utils.dart b/json_serializable/lib/src/enum_utils.dart index 9b27334b0..467d47161 100644 --- a/json_serializable/lib/src/enum_utils.dart +++ b/json_serializable/lib/src/enum_utils.dart @@ -145,11 +145,7 @@ JsonEnum _fromAnnotation(DartObject? dartObject) { final reader = ConstantReader(dartObject); return JsonEnum( alwaysCreate: reader.read('alwaysCreate').literalValue as bool, - fieldRename: enumValueForDartObject( - reader.read('fieldRename').objectValue, - FieldRename.values, - (f) => f.toString().split('.')[1], - ), + fieldRename: readEnum(reader.read('fieldRename'), FieldRename.values)!, valueField: reader.read('valueField').literalValue as String?, ); } diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index 56ec6a45a..b81359fc4 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -32,13 +32,14 @@ Never throwUnsupported(FieldElement element, String message) => element: element, ); -FieldRename? _fromDartObject(ConstantReader reader) => reader.isNull - ? null - : enumValueForDartObject( - reader.objectValue, - FieldRename.values, - (f) => f.toString().split('.')[1], - ); +T? readEnum<T extends Enum>(ConstantReader reader, List<T> values) => + reader.isNull + ? null + : enumValueForDartObject<T>( + reader.objectValue, + values, + (f) => f.name, + ); T enumValueForDartObject<T>( DartObject source, @@ -62,7 +63,7 @@ JsonSerializable _valueForAnnotation(ConstantReader reader) => JsonSerializable( disallowUnrecognizedKeys: reader.read('disallowUnrecognizedKeys').literalValue as bool?, explicitToJson: reader.read('explicitToJson').literalValue as bool?, - fieldRename: _fromDartObject(reader.read('fieldRename')), + fieldRename: readEnum(reader.read('fieldRename'), FieldRename.values), genericArgumentFactories: reader.read('genericArgumentFactories').literalValue as bool?, ignoreUnannotated: reader.read('ignoreUnannotated').literalValue as bool?, From 7638402cec7e4e6c732ffa9efcc24db3386dd999 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@google.com> Date: Mon, 21 Nov 2022 16:21:10 -0800 Subject: [PATCH 460/569] tool: share formatter --- json_serializable/tool/shared.dart | 3 +++ json_serializable/tool/test_builder.dart | 7 ++----- json_serializable/tool/test_type_builder.dart | 5 +---- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/json_serializable/tool/shared.dart b/json_serializable/tool/shared.dart index f1e0b9914..6565baf9d 100644 --- a/json_serializable/tool/shared.dart +++ b/json_serializable/tool/shared.dart @@ -5,8 +5,11 @@ import 'dart:io'; import 'package:build/build.dart'; +import 'package:dart_style/dart_style.dart'; import 'package:yaml/yaml.dart'; +final formatter = DartFormatter(); + // Until we have verification in pkg:build and friends // https://github.com/dart-lang/build/issues/590 Builder validate(String builderName, Builder builder) { diff --git a/json_serializable/tool/test_builder.dart b/json_serializable/tool/test_builder.dart index 6e6389c4c..a0926b098 100644 --- a/json_serializable/tool/test_builder.dart +++ b/json_serializable/tool/test_builder.dart @@ -6,13 +6,10 @@ import 'dart:async'; import 'dart:collection'; import 'package:build/build.dart'; -import 'package:dart_style/dart_style.dart'; import 'package:path/path.dart' as p; import 'shared.dart'; -final _formatter = DartFormatter(); - Builder testBuilder([_]) => validate('_test_builder', const _TestBuilder()); class _TestBuilder implements Builder { @@ -56,7 +53,7 @@ class _TestBuilder implements Builder { final content = Replacement.generate(sourceContent, replacements); - await buildStep.writeAsString(newId, _formatter.format(content)); + await buildStep.writeAsString(newId, formatter.format(content)); } if (baseName == _kitchenSinkBaseName) { @@ -73,7 +70,7 @@ class _TestBuilder implements Builder { '];', ]; - await buildStep.writeAsString(newId, _formatter.format(lines.join('\n'))); + await buildStep.writeAsString(newId, formatter.format(lines.join('\n'))); } } diff --git a/json_serializable/tool/test_type_builder.dart b/json_serializable/tool/test_type_builder.dart index 9ebd4a440..af6dd2dd4 100644 --- a/json_serializable/tool/test_type_builder.dart +++ b/json_serializable/tool/test_type_builder.dart @@ -6,14 +6,11 @@ import 'dart:async'; import 'package:build/build.dart'; import 'package:collection/collection.dart'; -import 'package:dart_style/dart_style.dart'; import 'package:json_serializable/src/type_helpers/map_helper.dart'; import 'shared.dart'; import 'test_type_data.dart'; -final _formatter = DartFormatter(); - const _trivialTypesToTest = { 'BigInt': TestTypeData.defaultFunc( jsonExpression: "'12345'", @@ -128,7 +125,7 @@ class _TypeBuilder implements Builder { await buildStep.writeAsString( newId, - _formatter.format(entry.value.libContent(sourceContent, type)), + formatter.format(entry.value.libContent(sourceContent, type)), ); } } From 776df7cbb67ce368262612b34758bb780459ac46 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Wed, 30 Nov 2022 09:24:31 -0800 Subject: [PATCH 461/569] Add JsonKey.includeFromJson/includeToJson - allow explicit control of serialization (#1256) Deprecate `JsonKey.ignore` Fixes https://github.com/google/json_serializable.dart/issues/24 Fixes https://github.com/google/json_serializable.dart/issues/274 Fixes https://github.com/google/json_serializable.dart/issues/537 Fixes https://github.com/google/json_serializable.dart/issues/569 Fixes https://github.com/google/json_serializable.dart/issues/797 Fixes https://github.com/google/json_serializable.dart/issues/1100 Fixes https://github.com/google/json_serializable.dart/issues/1244 --- json_annotation/CHANGELOG.md | 3 + json_annotation/lib/src/json_key.dart | 42 +- .../lib/src/json_serializable.dart | 4 +- json_serializable/CHANGELOG.md | 1 + json_serializable/build.yaml | 13 + json_serializable/lib/src/field_helpers.dart | 6 +- .../lib/src/generator_helper.dart | 74 +++- json_serializable/lib/src/json_key_utils.dart | 35 +- .../lib/src/type_helpers/config_types.dart | 7 +- json_serializable/test/field_matrix_test.dart | 94 ++++ .../test/field_matrix_test.field_matrix.dart | 404 ++++++++++++++++++ .../field_matrix_test.field_matrix.g.dart | 262 ++++++++++++ .../create_per_field_to_json_example.dart | 2 +- .../test/integration/field_map_example.dart | 2 +- .../test/integration/json_test_example.dart | 4 +- .../json_test_example.g_any_map.dart | 4 +- .../test/json_serializable_test.dart | 22 +- .../src/_json_serializable_test_input.dart | 32 +- .../test/src/inheritance_test_input.dart | 2 +- .../tool/field_matrix_builder.dart | 88 ++++ 20 files changed, 1046 insertions(+), 55 deletions(-) create mode 100644 json_serializable/test/field_matrix_test.dart create mode 100644 json_serializable/test/field_matrix_test.field_matrix.dart create mode 100644 json_serializable/test/field_matrix_test.field_matrix.g.dart create mode 100644 json_serializable/tool/field_matrix_builder.dart diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index da3bf8ce4..5697f95a2 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -1,5 +1,8 @@ ## 4.8.0-dev +- DEPRECATED `JsonKey.ignore`. Replaced by... +- Added `JsonKey.includeFromJson` and `JsonKey.includeToJson` to allow + fine-grained control of if a field is encoded/decoded. - Added `JsonSerializable.createPerFieldToJson` which allows generating a `_$ModelPerFieldToJson`, enabling partial encoding of a model. - Update `JsonKey` documentation to align with new features in diff --git a/json_annotation/lib/src/json_key.dart b/json_annotation/lib/src/json_key.dart index bda621039..d87d52068 100644 --- a/json_annotation/lib/src/json_key.dart +++ b/json_annotation/lib/src/json_key.dart @@ -47,8 +47,27 @@ class JsonKey { /// /// If `null` (the default) or `false`, the field will be considered for /// serialization. + /// + /// This field is DEPRECATED use [includeFromJson] and [includeToJson] + /// instead. + @Deprecated( + 'Use `includeFromJson` and `includeToJson` with a value of `false` ' + 'instead.', + ) final bool? ignore; + /// Used to force a field to be included (or excluded) when decoding a object + /// from JSON. + /// + /// `null` (the default) means the field will be handled with the default + /// semantics that take into account if it's private or if it can be cleanly + /// round-tripped to-from JSON. + /// + /// `true` means the field should always be decoded, even if it's private. + /// + /// `false` means the field should never be decoded. + final bool? includeFromJson; + /// Whether the generator should include fields with `null` values in the /// serialized output. /// @@ -66,6 +85,18 @@ class JsonKey { /// same field, an exception will be thrown during code generation. final bool? includeIfNull; + /// Used to force a field to be included (or excluded) when encoding a object + /// to JSON. + /// + /// `null` (the default) means the field will be handled with the default + /// semantics that take into account if it's private or if it can be cleanly + /// round-tripped to-from JSON. + /// + /// `true` means the field should always be encoded, even if it's private. + /// + /// `false` means the field should never be encoded. + final bool? includeToJson; + /// The key in a JSON map to use when reading and writing values corresponding /// to the annotated fields. /// @@ -122,12 +153,19 @@ class JsonKey { /// /// Only required when the default behavior is not desired. const JsonKey({ - @Deprecated('Has no effect') bool? nullable, + @Deprecated('Has no effect') + bool? nullable, this.defaultValue, this.disallowNullValue, this.fromJson, - this.ignore, + @Deprecated( + 'Use `includeFromJson` and `includeToJson` with a value of `false` ' + 'instead.', + ) + this.ignore, + this.includeFromJson, this.includeIfNull, + this.includeToJson, this.name, this.readValue, this.required, diff --git a/json_annotation/lib/src/json_serializable.dart b/json_annotation/lib/src/json_serializable.dart index 22b8d4f93..41fa0c136 100644 --- a/json_annotation/lib/src/json_serializable.dart +++ b/json_annotation/lib/src/json_serializable.dart @@ -193,7 +193,7 @@ class JsonSerializable { /// generated. /// /// It will have the same effect as if those fields had been annotated with - /// `@JsonKey(ignore: true)`. + /// [JsonKey.includeToJson] and [JsonKey.includeFromJson] set to `false` final bool? ignoreUnannotated; /// Whether the generator should include fields with `null` values in the @@ -237,7 +237,7 @@ class JsonSerializable { /// @myCustomAnnotation /// class Another {...} /// ``` - @JsonKey(ignore: true) + @JsonKey(includeFromJson: false, includeToJson: false) final List<JsonConverter>? converters; /// Creates a new [JsonSerializable] instance. diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 6a18f57c4..d42ed892f 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,5 +1,6 @@ ## 6.6.0-dev +- Support for `JsonKey.includeFromJson` and `JsonKey.includeToJson`. - Support `JsonEnum.valueField` being set with `'index'`. - Require Dart SDK `>=2.18.0`. - Require `analyzer: ^5.2.0` diff --git a/json_serializable/build.yaml b/json_serializable/build.yaml index 1b5d731c9..66f56a880 100644 --- a/json_serializable/build.yaml +++ b/json_serializable/build.yaml @@ -13,6 +13,7 @@ targets: generate_for: - example/* - test/default_value/* + - test/field_matrix_test.field_matrix.dart - test/generic_files/* - test/integration/* - test/kitchen_sink/* @@ -20,6 +21,10 @@ targets: - test/supported_types/* - tool/readme/* + json_serializable|_field_matrix_builder: + generate_for: + - test/field_matrix_test.dart + json_serializable|_test_builder: generate_for: - test/default_value/default_value.dart @@ -95,6 +100,14 @@ builders: build_to: source runs_before: ["json_serializable"] + _field_matrix_builder: + import: 'tool/field_matrix_builder.dart' + builder_factories: ['builder'] + build_extensions: + .dart: [.field_matrix.dart] + build_to: source + runs_before: ["json_serializable"] + _readme_builder: import: "tool/readme_builder.dart" builder_factories: ["readmeBuilder"] diff --git a/json_serializable/lib/src/field_helpers.dart b/json_serializable/lib/src/field_helpers.dart index e20a8c5db..4b6608f3f 100644 --- a/json_serializable/lib/src/field_helpers.dart +++ b/json_serializable/lib/src/field_helpers.dart @@ -69,10 +69,10 @@ class _FieldSet implements Comparable<_FieldSet> { } } -/// Returns a [Set] of all instance [FieldElement] items for [element] and +/// Returns a [List] of all instance [FieldElement] items for [element] and /// super classes, sorted first by their location in the inheritance hierarchy /// (super first) and then by their location in the source file. -Iterable<FieldElement> createSortedFieldSet(ClassElement element) { +List<FieldElement> createSortedFieldSet(ClassElement element) { // Get all of the fields that need to be assigned // TODO: support overriding the field set with an annotation option final elementInstanceFields = Map.fromEntries( @@ -104,7 +104,7 @@ Iterable<FieldElement> createSortedFieldSet(ClassElement element) { .toList() ..sort(); - return fields.map((fs) => fs.field).toList(); + return fields.map((fs) => fs.field).toList(growable: false); } const _dartCoreObjectChecker = TypeChecker.fromRuntime(Object); diff --git a/json_serializable/lib/src/generator_helper.dart b/json_serializable/lib/src/generator_helper.dart index c02921a70..1b8621156 100644 --- a/json_serializable/lib/src/generator_helper.dart +++ b/json_serializable/lib/src/generator_helper.dart @@ -6,12 +6,12 @@ import 'package:analyzer/dart/element/element.dart'; import 'package:build/build.dart'; import 'package:source_gen/source_gen.dart'; +import '../type_helper.dart'; import 'decode_helper.dart'; import 'encoder_helper.dart'; import 'field_helpers.dart'; import 'helper_core.dart'; import 'settings.dart'; -import 'type_helper.dart'; import 'utils.dart'; class GeneratorHelper extends HelperCore with EncodeHelper, DecodeHelper { @@ -61,16 +61,17 @@ class GeneratorHelper extends HelperCore with EncodeHelper, DecodeHelper { final accessibleFields = sortedFields.fold<Map<String, FieldElement>>( <String, FieldElement>{}, (map, field) { - if (!field.isPublic) { + final jsonKey = jsonKeyFor(field); + if (!field.isPublic && !jsonKey.explicitYesFromJson) { unavailableReasons[field.name] = 'It is assigned to a private field.'; } else if (field.getter == null) { assert(field.setter != null); unavailableReasons[field.name] = 'Setter-only properties are not supported.'; log.warning('Setters are ignored: ${element.name}.${field.name}'); - } else if (jsonKeyFor(field).ignore) { + } else if (jsonKey.explicitNoFromJson) { unavailableReasons[field.name] = - 'It is assigned to an ignored field.'; + 'It is assigned to a field not meant to be used in fromJson.'; } else { assert(!map.containsKey(field.name)); map[field.name] = field; @@ -85,28 +86,47 @@ class GeneratorHelper extends HelperCore with EncodeHelper, DecodeHelper { final createResult = createFactory(accessibleFields, unavailableReasons); yield createResult.output; - accessibleFieldSet = accessibleFields.entries + final fieldsToUse = accessibleFields.entries .where((e) => createResult.usedFields.contains(e.key)) .map((e) => e.value) - .toSet(); + .toList(); + + // Need to add candidates BACK even if they are not used in the factory if + // they are forced to be used for toJSON + for (var candidate in sortedFields.where((element) => + jsonKeyFor(element).explicitYesToJson && + !fieldsToUse.contains(element))) { + fieldsToUse.add(candidate); + } + + // Need the fields to maintain the original source ordering + fieldsToUse.sort( + (a, b) => sortedFields.indexOf(a).compareTo(sortedFields.indexOf(b))); + + accessibleFieldSet = fieldsToUse.toSet(); } - // Check for duplicate JSON keys due to colliding annotations. - // We do this now, since we have a final field list after any pruning done - // by `_writeCtor`. - accessibleFieldSet.fold( - <String>{}, - (Set<String> set, fe) { - final jsonKey = nameAccess(fe); - if (!set.add(jsonKey)) { - throw InvalidGenerationSourceError( - 'More than one field has the JSON key for name "$jsonKey".', - element: fe, - ); - } - return set; - }, - ); + accessibleFieldSet + ..removeWhere( + (element) => jsonKeyFor(element).explicitNoToJson, + ) + + // Check for duplicate JSON keys due to colliding annotations. + // We do this now, since we have a final field list after any pruning done + // by `_writeCtor`. + ..fold( + <String>{}, + (Set<String> set, fe) { + final jsonKey = nameAccess(fe); + if (!set.add(jsonKey)) { + throw InvalidGenerationSourceError( + 'More than one field has the JSON key for name "$jsonKey".', + element: fe, + ); + } + return set; + }, + ); if (config.createFieldMap) { yield createFieldMap(accessibleFieldSet); @@ -123,3 +143,13 @@ class GeneratorHelper extends HelperCore with EncodeHelper, DecodeHelper { yield* _addedMembers; } } + +extension on KeyConfig { + bool get explicitYesFromJson => includeFromJson == true; + + bool get explicitNoFromJson => includeFromJson == false; + + bool get explicitYesToJson => includeToJson == true; + + bool get explicitNoToJson => includeFromJson == false; +} diff --git a/json_serializable/lib/src/json_key_utils.dart b/json_serializable/lib/src/json_key_utils.dart index 0df264822..8ba78229d 100644 --- a/json_serializable/lib/src/json_key_utils.dart +++ b/json_serializable/lib/src/json_key_utils.dart @@ -34,7 +34,8 @@ KeyConfig _from(FieldElement element, ClassConfig classAnnotation) { classAnnotation, element, defaultValue: ctorParamDefault, - ignore: classAnnotation.ignoreUnannotated, + includeFromJson: classAnnotation.ignoreUnannotated ? false : null, + includeToJson: classAnnotation.ignoreUnannotated ? false : null, ); } @@ -236,18 +237,42 @@ KeyConfig _from(FieldElement element, ClassConfig classAnnotation) { readValue.objectValue.toFunctionValue()!.qualifiedName; } + final ignore = obj.read('ignore').literalValue as bool?; + var includeFromJson = obj.read('includeFromJson').literalValue as bool?; + var includeToJson = obj.read('includeToJson').literalValue as bool?; + + if (ignore != null) { + if (includeFromJson != null) { + throwUnsupported( + element, + 'Cannot use both `ignore` and `includeFromJson` on the same field. ' + 'Since `ignore` is deprecated, you should only use `includeFromJson`.', + ); + } + if (includeToJson != null) { + throwUnsupported( + element, + 'Cannot use both `ignore` and `includeToJson` on the same field. ' + 'Since `ignore` is deprecated, you should only use `includeToJson`.', + ); + } + assert(includeFromJson == null && includeToJson == null); + includeToJson = includeFromJson = !ignore; + } + return _populateJsonKey( classAnnotation, element, defaultValue: defaultValue ?? ctorParamDefault, disallowNullValue: obj.read('disallowNullValue').literalValue as bool?, - ignore: obj.read('ignore').literalValue as bool?, includeIfNull: obj.read('includeIfNull').literalValue as bool?, name: obj.read('name').literalValue as String?, readValueFunctionName: readValueFunctionName, required: obj.read('required').literalValue as bool?, unknownEnumValue: createAnnotationValue('unknownEnumValue', mustBeEnum: true), + includeToJson: includeToJson, + includeFromJson: includeFromJson, ); } @@ -256,12 +281,13 @@ KeyConfig _populateJsonKey( FieldElement element, { required String? defaultValue, bool? disallowNullValue, - bool? ignore, bool? includeIfNull, String? name, String? readValueFunctionName, bool? required, String? unknownEnumValue, + bool? includeToJson, + bool? includeFromJson, }) { if (disallowNullValue == true) { if (includeIfNull == true) { @@ -275,13 +301,14 @@ KeyConfig _populateJsonKey( return KeyConfig( defaultValue: defaultValue, disallowNullValue: disallowNullValue ?? false, - ignore: ignore ?? false, includeIfNull: _includeIfNull( includeIfNull, disallowNullValue, classAnnotation.includeIfNull), name: name ?? encodedFieldName(classAnnotation.fieldRename, element.name), readValueFunctionName: readValueFunctionName, required: required ?? false, unknownEnumValue: unknownEnumValue, + includeFromJson: includeFromJson, + includeToJson: includeToJson, ); } diff --git a/json_serializable/lib/src/type_helpers/config_types.dart b/json_serializable/lib/src/type_helpers/config_types.dart index 442a20e3c..c4bdc260a 100644 --- a/json_serializable/lib/src/type_helpers/config_types.dart +++ b/json_serializable/lib/src/type_helpers/config_types.dart @@ -11,10 +11,12 @@ class KeyConfig { final bool disallowNullValue; - final bool ignore; + final bool? includeFromJson; final bool includeIfNull; + final bool? includeToJson; + final String name; final bool required; @@ -26,8 +28,9 @@ class KeyConfig { KeyConfig({ required this.defaultValue, required this.disallowNullValue, - required this.ignore, + required this.includeFromJson, required this.includeIfNull, + required this.includeToJson, required this.name, required this.readValueFunctionName, required this.required, diff --git a/json_serializable/test/field_matrix_test.dart b/json_serializable/test/field_matrix_test.dart new file mode 100644 index 000000000..0e18091f9 --- /dev/null +++ b/json_serializable/test/field_matrix_test.dart @@ -0,0 +1,94 @@ +import 'dart:convert'; + +import 'package:test/test.dart'; + +import 'field_matrix_test.field_matrix.dart'; + +void main() { + test('test', () { + final result = Map.fromEntries(fromJsonFactories.map((e) { + final instance = e({'field': 42}); + return MapEntry(instance.toString(), { + 'with': instance, + 'without': e({}), + }); + })); + + expect(jsonDecode(jsonEncode(result)), _expectedResult); + }); +} + +const _expectedResult = { + 'ToJsonNullFromJsonNullPublic: field: 42': { + 'with': {'aField': null, 'field': 42, 'zField': null}, + 'without': {'aField': null, 'field': null, 'zField': null} + }, + 'ToJsonNullFromJsonTruePublic: field: 42': { + 'with': {'aField': null, 'field': 42, 'zField': null}, + 'without': {'aField': null, 'field': null, 'zField': null} + }, + 'ToJsonNullFromJsonFalsePublic: field: null': { + 'with': {'aField': null, 'zField': null}, + 'without': {'aField': null, 'zField': null} + }, + 'ToJsonTrueFromJsonNullPublic: field: 42': { + 'with': {'aField': null, 'field': 42, 'zField': null}, + 'without': {'aField': null, 'field': null, 'zField': null} + }, + 'ToJsonTrueFromJsonTruePublic: field: 42': { + 'with': {'aField': null, 'field': 42, 'zField': null}, + 'without': {'aField': null, 'field': null, 'zField': null} + }, + 'ToJsonTrueFromJsonFalsePublic: field: null': { + 'with': {'aField': null, 'zField': null}, + 'without': {'aField': null, 'zField': null} + }, + 'ToJsonFalseFromJsonNullPublic: field: 42': { + 'with': {'aField': null, 'field': 42, 'zField': null}, + 'without': {'aField': null, 'field': null, 'zField': null} + }, + 'ToJsonFalseFromJsonTruePublic: field: 42': { + 'with': {'aField': null, 'field': 42, 'zField': null}, + 'without': {'aField': null, 'field': null, 'zField': null} + }, + 'ToJsonFalseFromJsonFalsePublic: field: null': { + 'with': {'aField': null, 'zField': null}, + 'without': {'aField': null, 'zField': null} + }, + 'ToJsonNullFromJsonNullPrivate: _field: null': { + 'with': {'aField': null, 'zField': null}, + 'without': {'aField': null, 'zField': null} + }, + 'ToJsonNullFromJsonTruePrivate: _field: 42': { + 'with': {'aField': null, 'field': 42, 'zField': null}, + 'without': {'aField': null, 'field': null, 'zField': null} + }, + 'ToJsonNullFromJsonFalsePrivate: _field: null': { + 'with': {'aField': null, 'zField': null}, + 'without': {'aField': null, 'zField': null} + }, + 'ToJsonTrueFromJsonNullPrivate: _field: null': { + 'with': {'aField': null, 'field': null, 'zField': null}, + 'without': {'aField': null, 'field': null, 'zField': null} + }, + 'ToJsonTrueFromJsonTruePrivate: _field: 42': { + 'with': {'aField': null, 'field': 42, 'zField': null}, + 'without': {'aField': null, 'field': null, 'zField': null} + }, + 'ToJsonTrueFromJsonFalsePrivate: _field: null': { + 'with': {'aField': null, 'zField': null}, + 'without': {'aField': null, 'zField': null} + }, + 'ToJsonFalseFromJsonNullPrivate: _field: null': { + 'with': {'aField': null, 'zField': null}, + 'without': {'aField': null, 'zField': null} + }, + 'ToJsonFalseFromJsonTruePrivate: _field: 42': { + 'with': {'aField': null, 'field': 42, 'zField': null}, + 'without': {'aField': null, 'field': null, 'zField': null} + }, + 'ToJsonFalseFromJsonFalsePrivate: _field: null': { + 'with': {'aField': null, 'zField': null}, + 'without': {'aField': null, 'zField': null} + } +}; diff --git a/json_serializable/test/field_matrix_test.field_matrix.dart b/json_serializable/test/field_matrix_test.field_matrix.dart new file mode 100644 index 000000000..fd1c52b5f --- /dev/null +++ b/json_serializable/test/field_matrix_test.field_matrix.dart @@ -0,0 +1,404 @@ +import 'package:json_annotation/json_annotation.dart'; + +part 'field_matrix_test.field_matrix.g.dart'; + +@JsonSerializable() +class ToJsonNullFromJsonNullPublic { + ToJsonNullFromJsonNullPublic(); + + int? aField; + + int? field; + + int? zField; + + factory ToJsonNullFromJsonNullPublic.fromJson(Map<String, dynamic> json) => + _$ToJsonNullFromJsonNullPublicFromJson(json); + + Map<String, dynamic> toJson() => _$ToJsonNullFromJsonNullPublicToJson(this); + + @override + String toString() => 'ToJsonNullFromJsonNullPublic: field: $field'; +} + +@JsonSerializable() +class ToJsonNullFromJsonTruePublic { + ToJsonNullFromJsonTruePublic(); + + int? aField; + + @JsonKey( + includeFromJson: true, + ) + int? field; + + int? zField; + + factory ToJsonNullFromJsonTruePublic.fromJson(Map<String, dynamic> json) => + _$ToJsonNullFromJsonTruePublicFromJson(json); + + Map<String, dynamic> toJson() => _$ToJsonNullFromJsonTruePublicToJson(this); + + @override + String toString() => 'ToJsonNullFromJsonTruePublic: field: $field'; +} + +@JsonSerializable() +class ToJsonNullFromJsonFalsePublic { + ToJsonNullFromJsonFalsePublic(); + + int? aField; + + @JsonKey( + includeFromJson: false, + ) + int? field; + + int? zField; + + factory ToJsonNullFromJsonFalsePublic.fromJson(Map<String, dynamic> json) => + _$ToJsonNullFromJsonFalsePublicFromJson(json); + + Map<String, dynamic> toJson() => _$ToJsonNullFromJsonFalsePublicToJson(this); + + @override + String toString() => 'ToJsonNullFromJsonFalsePublic: field: $field'; +} + +@JsonSerializable() +class ToJsonTrueFromJsonNullPublic { + ToJsonTrueFromJsonNullPublic(); + + int? aField; + + @JsonKey( + includeToJson: true, + ) + int? field; + + int? zField; + + factory ToJsonTrueFromJsonNullPublic.fromJson(Map<String, dynamic> json) => + _$ToJsonTrueFromJsonNullPublicFromJson(json); + + Map<String, dynamic> toJson() => _$ToJsonTrueFromJsonNullPublicToJson(this); + + @override + String toString() => 'ToJsonTrueFromJsonNullPublic: field: $field'; +} + +@JsonSerializable() +class ToJsonTrueFromJsonTruePublic { + ToJsonTrueFromJsonTruePublic(); + + int? aField; + + @JsonKey( + includeFromJson: true, + includeToJson: true, + ) + int? field; + + int? zField; + + factory ToJsonTrueFromJsonTruePublic.fromJson(Map<String, dynamic> json) => + _$ToJsonTrueFromJsonTruePublicFromJson(json); + + Map<String, dynamic> toJson() => _$ToJsonTrueFromJsonTruePublicToJson(this); + + @override + String toString() => 'ToJsonTrueFromJsonTruePublic: field: $field'; +} + +@JsonSerializable() +class ToJsonTrueFromJsonFalsePublic { + ToJsonTrueFromJsonFalsePublic(); + + int? aField; + + @JsonKey( + includeFromJson: false, + includeToJson: true, + ) + int? field; + + int? zField; + + factory ToJsonTrueFromJsonFalsePublic.fromJson(Map<String, dynamic> json) => + _$ToJsonTrueFromJsonFalsePublicFromJson(json); + + Map<String, dynamic> toJson() => _$ToJsonTrueFromJsonFalsePublicToJson(this); + + @override + String toString() => 'ToJsonTrueFromJsonFalsePublic: field: $field'; +} + +@JsonSerializable() +class ToJsonFalseFromJsonNullPublic { + ToJsonFalseFromJsonNullPublic(); + + int? aField; + + @JsonKey( + includeToJson: false, + ) + int? field; + + int? zField; + + factory ToJsonFalseFromJsonNullPublic.fromJson(Map<String, dynamic> json) => + _$ToJsonFalseFromJsonNullPublicFromJson(json); + + Map<String, dynamic> toJson() => _$ToJsonFalseFromJsonNullPublicToJson(this); + + @override + String toString() => 'ToJsonFalseFromJsonNullPublic: field: $field'; +} + +@JsonSerializable() +class ToJsonFalseFromJsonTruePublic { + ToJsonFalseFromJsonTruePublic(); + + int? aField; + + @JsonKey( + includeFromJson: true, + includeToJson: false, + ) + int? field; + + int? zField; + + factory ToJsonFalseFromJsonTruePublic.fromJson(Map<String, dynamic> json) => + _$ToJsonFalseFromJsonTruePublicFromJson(json); + + Map<String, dynamic> toJson() => _$ToJsonFalseFromJsonTruePublicToJson(this); + + @override + String toString() => 'ToJsonFalseFromJsonTruePublic: field: $field'; +} + +@JsonSerializable() +class ToJsonFalseFromJsonFalsePublic { + ToJsonFalseFromJsonFalsePublic(); + + int? aField; + + @JsonKey( + includeFromJson: false, + includeToJson: false, + ) + int? field; + + int? zField; + + factory ToJsonFalseFromJsonFalsePublic.fromJson(Map<String, dynamic> json) => + _$ToJsonFalseFromJsonFalsePublicFromJson(json); + + Map<String, dynamic> toJson() => _$ToJsonFalseFromJsonFalsePublicToJson(this); + + @override + String toString() => 'ToJsonFalseFromJsonFalsePublic: field: $field'; +} + +@JsonSerializable() +class ToJsonNullFromJsonNullPrivate { + ToJsonNullFromJsonNullPrivate(); + + int? aField; + + @JsonKey(name: 'field') + int? _field; + + int? zField; + + factory ToJsonNullFromJsonNullPrivate.fromJson(Map<String, dynamic> json) => + _$ToJsonNullFromJsonNullPrivateFromJson(json); + + Map<String, dynamic> toJson() => _$ToJsonNullFromJsonNullPrivateToJson(this); + + @override + String toString() => 'ToJsonNullFromJsonNullPrivate: _field: $_field'; +} + +@JsonSerializable() +class ToJsonNullFromJsonTruePrivate { + ToJsonNullFromJsonTruePrivate(); + + int? aField; + + @JsonKey(includeFromJson: true, name: 'field') + int? _field; + + int? zField; + + factory ToJsonNullFromJsonTruePrivate.fromJson(Map<String, dynamic> json) => + _$ToJsonNullFromJsonTruePrivateFromJson(json); + + Map<String, dynamic> toJson() => _$ToJsonNullFromJsonTruePrivateToJson(this); + + @override + String toString() => 'ToJsonNullFromJsonTruePrivate: _field: $_field'; +} + +@JsonSerializable() +class ToJsonNullFromJsonFalsePrivate { + ToJsonNullFromJsonFalsePrivate(); + + int? aField; + + @JsonKey(includeFromJson: false, name: 'field') + int? _field; + + int? zField; + + factory ToJsonNullFromJsonFalsePrivate.fromJson(Map<String, dynamic> json) => + _$ToJsonNullFromJsonFalsePrivateFromJson(json); + + Map<String, dynamic> toJson() => _$ToJsonNullFromJsonFalsePrivateToJson(this); + + @override + String toString() => 'ToJsonNullFromJsonFalsePrivate: _field: $_field'; +} + +@JsonSerializable() +class ToJsonTrueFromJsonNullPrivate { + ToJsonTrueFromJsonNullPrivate(); + + int? aField; + + @JsonKey(includeToJson: true, name: 'field') + int? _field; + + int? zField; + + factory ToJsonTrueFromJsonNullPrivate.fromJson(Map<String, dynamic> json) => + _$ToJsonTrueFromJsonNullPrivateFromJson(json); + + Map<String, dynamic> toJson() => _$ToJsonTrueFromJsonNullPrivateToJson(this); + + @override + String toString() => 'ToJsonTrueFromJsonNullPrivate: _field: $_field'; +} + +@JsonSerializable() +class ToJsonTrueFromJsonTruePrivate { + ToJsonTrueFromJsonTruePrivate(); + + int? aField; + + @JsonKey(includeFromJson: true, includeToJson: true, name: 'field') + int? _field; + + int? zField; + + factory ToJsonTrueFromJsonTruePrivate.fromJson(Map<String, dynamic> json) => + _$ToJsonTrueFromJsonTruePrivateFromJson(json); + + Map<String, dynamic> toJson() => _$ToJsonTrueFromJsonTruePrivateToJson(this); + + @override + String toString() => 'ToJsonTrueFromJsonTruePrivate: _field: $_field'; +} + +@JsonSerializable() +class ToJsonTrueFromJsonFalsePrivate { + ToJsonTrueFromJsonFalsePrivate(); + + int? aField; + + @JsonKey(includeFromJson: false, includeToJson: true, name: 'field') + int? _field; + + int? zField; + + factory ToJsonTrueFromJsonFalsePrivate.fromJson(Map<String, dynamic> json) => + _$ToJsonTrueFromJsonFalsePrivateFromJson(json); + + Map<String, dynamic> toJson() => _$ToJsonTrueFromJsonFalsePrivateToJson(this); + + @override + String toString() => 'ToJsonTrueFromJsonFalsePrivate: _field: $_field'; +} + +@JsonSerializable() +class ToJsonFalseFromJsonNullPrivate { + ToJsonFalseFromJsonNullPrivate(); + + int? aField; + + @JsonKey(includeToJson: false, name: 'field') + int? _field; + + int? zField; + + factory ToJsonFalseFromJsonNullPrivate.fromJson(Map<String, dynamic> json) => + _$ToJsonFalseFromJsonNullPrivateFromJson(json); + + Map<String, dynamic> toJson() => _$ToJsonFalseFromJsonNullPrivateToJson(this); + + @override + String toString() => 'ToJsonFalseFromJsonNullPrivate: _field: $_field'; +} + +@JsonSerializable() +class ToJsonFalseFromJsonTruePrivate { + ToJsonFalseFromJsonTruePrivate(); + + int? aField; + + @JsonKey(includeFromJson: true, includeToJson: false, name: 'field') + int? _field; + + int? zField; + + factory ToJsonFalseFromJsonTruePrivate.fromJson(Map<String, dynamic> json) => + _$ToJsonFalseFromJsonTruePrivateFromJson(json); + + Map<String, dynamic> toJson() => _$ToJsonFalseFromJsonTruePrivateToJson(this); + + @override + String toString() => 'ToJsonFalseFromJsonTruePrivate: _field: $_field'; +} + +@JsonSerializable() +class ToJsonFalseFromJsonFalsePrivate { + ToJsonFalseFromJsonFalsePrivate(); + + int? aField; + + @JsonKey(includeFromJson: false, includeToJson: false, name: 'field') + int? _field; + + int? zField; + + factory ToJsonFalseFromJsonFalsePrivate.fromJson(Map<String, dynamic> json) => + _$ToJsonFalseFromJsonFalsePrivateFromJson(json); + + Map<String, dynamic> toJson() => + _$ToJsonFalseFromJsonFalsePrivateToJson(this); + + @override + String toString() => 'ToJsonFalseFromJsonFalsePrivate: _field: $_field'; +} + +const fromJsonFactories = <Object Function(Map<String, dynamic>)>{ + ToJsonNullFromJsonNullPublic.fromJson, + ToJsonNullFromJsonTruePublic.fromJson, + ToJsonNullFromJsonFalsePublic.fromJson, + ToJsonTrueFromJsonNullPublic.fromJson, + ToJsonTrueFromJsonTruePublic.fromJson, + ToJsonTrueFromJsonFalsePublic.fromJson, + ToJsonFalseFromJsonNullPublic.fromJson, + ToJsonFalseFromJsonTruePublic.fromJson, + ToJsonFalseFromJsonFalsePublic.fromJson, + ToJsonNullFromJsonNullPrivate.fromJson, + ToJsonNullFromJsonTruePrivate.fromJson, + ToJsonNullFromJsonFalsePrivate.fromJson, + ToJsonTrueFromJsonNullPrivate.fromJson, + ToJsonTrueFromJsonTruePrivate.fromJson, + ToJsonTrueFromJsonFalsePrivate.fromJson, + ToJsonFalseFromJsonNullPrivate.fromJson, + ToJsonFalseFromJsonTruePrivate.fromJson, + ToJsonFalseFromJsonFalsePrivate.fromJson, +}; diff --git a/json_serializable/test/field_matrix_test.field_matrix.g.dart b/json_serializable/test/field_matrix_test.field_matrix.g.dart new file mode 100644 index 000000000..dd948315f --- /dev/null +++ b/json_serializable/test/field_matrix_test.field_matrix.g.dart @@ -0,0 +1,262 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal + +part of 'field_matrix_test.field_matrix.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +ToJsonNullFromJsonNullPublic _$ToJsonNullFromJsonNullPublicFromJson( + Map<String, dynamic> json) => + ToJsonNullFromJsonNullPublic() + ..aField = json['aField'] as int? + ..field = json['field'] as int? + ..zField = json['zField'] as int?; + +Map<String, dynamic> _$ToJsonNullFromJsonNullPublicToJson( + ToJsonNullFromJsonNullPublic instance) => + <String, dynamic>{ + 'aField': instance.aField, + 'field': instance.field, + 'zField': instance.zField, + }; + +ToJsonNullFromJsonTruePublic _$ToJsonNullFromJsonTruePublicFromJson( + Map<String, dynamic> json) => + ToJsonNullFromJsonTruePublic() + ..aField = json['aField'] as int? + ..field = json['field'] as int? + ..zField = json['zField'] as int?; + +Map<String, dynamic> _$ToJsonNullFromJsonTruePublicToJson( + ToJsonNullFromJsonTruePublic instance) => + <String, dynamic>{ + 'aField': instance.aField, + 'field': instance.field, + 'zField': instance.zField, + }; + +ToJsonNullFromJsonFalsePublic _$ToJsonNullFromJsonFalsePublicFromJson( + Map<String, dynamic> json) => + ToJsonNullFromJsonFalsePublic() + ..aField = json['aField'] as int? + ..zField = json['zField'] as int?; + +Map<String, dynamic> _$ToJsonNullFromJsonFalsePublicToJson( + ToJsonNullFromJsonFalsePublic instance) => + <String, dynamic>{ + 'aField': instance.aField, + 'zField': instance.zField, + }; + +ToJsonTrueFromJsonNullPublic _$ToJsonTrueFromJsonNullPublicFromJson( + Map<String, dynamic> json) => + ToJsonTrueFromJsonNullPublic() + ..aField = json['aField'] as int? + ..field = json['field'] as int? + ..zField = json['zField'] as int?; + +Map<String, dynamic> _$ToJsonTrueFromJsonNullPublicToJson( + ToJsonTrueFromJsonNullPublic instance) => + <String, dynamic>{ + 'aField': instance.aField, + 'field': instance.field, + 'zField': instance.zField, + }; + +ToJsonTrueFromJsonTruePublic _$ToJsonTrueFromJsonTruePublicFromJson( + Map<String, dynamic> json) => + ToJsonTrueFromJsonTruePublic() + ..aField = json['aField'] as int? + ..field = json['field'] as int? + ..zField = json['zField'] as int?; + +Map<String, dynamic> _$ToJsonTrueFromJsonTruePublicToJson( + ToJsonTrueFromJsonTruePublic instance) => + <String, dynamic>{ + 'aField': instance.aField, + 'field': instance.field, + 'zField': instance.zField, + }; + +ToJsonTrueFromJsonFalsePublic _$ToJsonTrueFromJsonFalsePublicFromJson( + Map<String, dynamic> json) => + ToJsonTrueFromJsonFalsePublic() + ..aField = json['aField'] as int? + ..zField = json['zField'] as int?; + +Map<String, dynamic> _$ToJsonTrueFromJsonFalsePublicToJson( + ToJsonTrueFromJsonFalsePublic instance) => + <String, dynamic>{ + 'aField': instance.aField, + 'zField': instance.zField, + }; + +ToJsonFalseFromJsonNullPublic _$ToJsonFalseFromJsonNullPublicFromJson( + Map<String, dynamic> json) => + ToJsonFalseFromJsonNullPublic() + ..aField = json['aField'] as int? + ..field = json['field'] as int? + ..zField = json['zField'] as int?; + +Map<String, dynamic> _$ToJsonFalseFromJsonNullPublicToJson( + ToJsonFalseFromJsonNullPublic instance) => + <String, dynamic>{ + 'aField': instance.aField, + 'field': instance.field, + 'zField': instance.zField, + }; + +ToJsonFalseFromJsonTruePublic _$ToJsonFalseFromJsonTruePublicFromJson( + Map<String, dynamic> json) => + ToJsonFalseFromJsonTruePublic() + ..aField = json['aField'] as int? + ..field = json['field'] as int? + ..zField = json['zField'] as int?; + +Map<String, dynamic> _$ToJsonFalseFromJsonTruePublicToJson( + ToJsonFalseFromJsonTruePublic instance) => + <String, dynamic>{ + 'aField': instance.aField, + 'field': instance.field, + 'zField': instance.zField, + }; + +ToJsonFalseFromJsonFalsePublic _$ToJsonFalseFromJsonFalsePublicFromJson( + Map<String, dynamic> json) => + ToJsonFalseFromJsonFalsePublic() + ..aField = json['aField'] as int? + ..zField = json['zField'] as int?; + +Map<String, dynamic> _$ToJsonFalseFromJsonFalsePublicToJson( + ToJsonFalseFromJsonFalsePublic instance) => + <String, dynamic>{ + 'aField': instance.aField, + 'zField': instance.zField, + }; + +ToJsonNullFromJsonNullPrivate _$ToJsonNullFromJsonNullPrivateFromJson( + Map<String, dynamic> json) => + ToJsonNullFromJsonNullPrivate() + ..aField = json['aField'] as int? + ..zField = json['zField'] as int?; + +Map<String, dynamic> _$ToJsonNullFromJsonNullPrivateToJson( + ToJsonNullFromJsonNullPrivate instance) => + <String, dynamic>{ + 'aField': instance.aField, + 'zField': instance.zField, + }; + +ToJsonNullFromJsonTruePrivate _$ToJsonNullFromJsonTruePrivateFromJson( + Map<String, dynamic> json) => + ToJsonNullFromJsonTruePrivate() + ..aField = json['aField'] as int? + .._field = json['field'] as int? + ..zField = json['zField'] as int?; + +Map<String, dynamic> _$ToJsonNullFromJsonTruePrivateToJson( + ToJsonNullFromJsonTruePrivate instance) => + <String, dynamic>{ + 'aField': instance.aField, + 'field': instance._field, + 'zField': instance.zField, + }; + +ToJsonNullFromJsonFalsePrivate _$ToJsonNullFromJsonFalsePrivateFromJson( + Map<String, dynamic> json) => + ToJsonNullFromJsonFalsePrivate() + ..aField = json['aField'] as int? + ..zField = json['zField'] as int?; + +Map<String, dynamic> _$ToJsonNullFromJsonFalsePrivateToJson( + ToJsonNullFromJsonFalsePrivate instance) => + <String, dynamic>{ + 'aField': instance.aField, + 'zField': instance.zField, + }; + +ToJsonTrueFromJsonNullPrivate _$ToJsonTrueFromJsonNullPrivateFromJson( + Map<String, dynamic> json) => + ToJsonTrueFromJsonNullPrivate() + ..aField = json['aField'] as int? + ..zField = json['zField'] as int?; + +Map<String, dynamic> _$ToJsonTrueFromJsonNullPrivateToJson( + ToJsonTrueFromJsonNullPrivate instance) => + <String, dynamic>{ + 'aField': instance.aField, + 'field': instance._field, + 'zField': instance.zField, + }; + +ToJsonTrueFromJsonTruePrivate _$ToJsonTrueFromJsonTruePrivateFromJson( + Map<String, dynamic> json) => + ToJsonTrueFromJsonTruePrivate() + ..aField = json['aField'] as int? + .._field = json['field'] as int? + ..zField = json['zField'] as int?; + +Map<String, dynamic> _$ToJsonTrueFromJsonTruePrivateToJson( + ToJsonTrueFromJsonTruePrivate instance) => + <String, dynamic>{ + 'aField': instance.aField, + 'field': instance._field, + 'zField': instance.zField, + }; + +ToJsonTrueFromJsonFalsePrivate _$ToJsonTrueFromJsonFalsePrivateFromJson( + Map<String, dynamic> json) => + ToJsonTrueFromJsonFalsePrivate() + ..aField = json['aField'] as int? + ..zField = json['zField'] as int?; + +Map<String, dynamic> _$ToJsonTrueFromJsonFalsePrivateToJson( + ToJsonTrueFromJsonFalsePrivate instance) => + <String, dynamic>{ + 'aField': instance.aField, + 'zField': instance.zField, + }; + +ToJsonFalseFromJsonNullPrivate _$ToJsonFalseFromJsonNullPrivateFromJson( + Map<String, dynamic> json) => + ToJsonFalseFromJsonNullPrivate() + ..aField = json['aField'] as int? + ..zField = json['zField'] as int?; + +Map<String, dynamic> _$ToJsonFalseFromJsonNullPrivateToJson( + ToJsonFalseFromJsonNullPrivate instance) => + <String, dynamic>{ + 'aField': instance.aField, + 'zField': instance.zField, + }; + +ToJsonFalseFromJsonTruePrivate _$ToJsonFalseFromJsonTruePrivateFromJson( + Map<String, dynamic> json) => + ToJsonFalseFromJsonTruePrivate() + ..aField = json['aField'] as int? + .._field = json['field'] as int? + ..zField = json['zField'] as int?; + +Map<String, dynamic> _$ToJsonFalseFromJsonTruePrivateToJson( + ToJsonFalseFromJsonTruePrivate instance) => + <String, dynamic>{ + 'aField': instance.aField, + 'field': instance._field, + 'zField': instance.zField, + }; + +ToJsonFalseFromJsonFalsePrivate _$ToJsonFalseFromJsonFalsePrivateFromJson( + Map<String, dynamic> json) => + ToJsonFalseFromJsonFalsePrivate() + ..aField = json['aField'] as int? + ..zField = json['zField'] as int?; + +Map<String, dynamic> _$ToJsonFalseFromJsonFalsePrivateToJson( + ToJsonFalseFromJsonFalsePrivate instance) => + <String, dynamic>{ + 'aField': instance.aField, + 'zField': instance.zField, + }; diff --git a/json_serializable/test/integration/create_per_field_to_json_example.dart b/json_serializable/test/integration/create_per_field_to_json_example.dart index 80a306124..8eb3f5e9e 100644 --- a/json_serializable/test/integration/create_per_field_to_json_example.dart +++ b/json_serializable/test/integration/create_per_field_to_json_example.dart @@ -28,7 +28,7 @@ class Model { @JsonKey(includeIfNull: false) final Nested? nestedExcludeIfNull; - @JsonKey(ignore: true) + @JsonKey(includeFromJson: false, includeToJson: false) final String? ignoredName; String get fullName => '$firstName $lastName'; diff --git a/json_serializable/test/integration/field_map_example.dart b/json_serializable/test/integration/field_map_example.dart index 9d06a15ef..a9dba2475 100644 --- a/json_serializable/test/integration/field_map_example.dart +++ b/json_serializable/test/integration/field_map_example.dart @@ -17,7 +17,7 @@ class Model { @JsonKey(name: 'LAST_NAME') final String lastName; - @JsonKey(ignore: true) + @JsonKey(includeFromJson: false, includeToJson: false) final String? ignoredName; String get fullName => '$firstName $lastName'; diff --git a/json_serializable/test/integration/json_test_example.dart b/json_serializable/test/integration/json_test_example.dart index 09c4aa6d0..d69be6022 100644 --- a/json_serializable/test/integration/json_test_example.dart +++ b/json_serializable/test/integration/json_test_example.dart @@ -68,7 +68,7 @@ class Order { ) StatusCode? statusCode; - @JsonKey(ignore: true) + @JsonKey(includeFromJson: false, includeToJson: false) String get platformValue => platform!.description; set platformValue(String value) { @@ -78,7 +78,7 @@ class Order { // Ignored getter without value set in ctor int get price => items!.fold(0, (total, item) => item.price! + total); - @JsonKey(ignore: true) + @JsonKey(includeFromJson: false, includeToJson: false) bool? shouldBeCached; Order.custom(this.category, [Iterable<Item>? items]) diff --git a/json_serializable/test/integration/json_test_example.g_any_map.dart b/json_serializable/test/integration/json_test_example.g_any_map.dart index 9c449727d..2c6b51bda 100644 --- a/json_serializable/test/integration/json_test_example.g_any_map.dart +++ b/json_serializable/test/integration/json_test_example.g_any_map.dart @@ -70,7 +70,7 @@ class Order { ) StatusCode? statusCode; - @JsonKey(ignore: true) + @JsonKey(includeFromJson: false, includeToJson: false) String get platformValue => platform!.description; set platformValue(String value) { @@ -80,7 +80,7 @@ class Order { // Ignored getter without value set in ctor int get price => items!.fold(0, (total, item) => item.price! + total); - @JsonKey(ignore: true) + @JsonKey(includeFromJson: false, includeToJson: false) bool? shouldBeCached; Order.custom(this.category, [Iterable<Item>? items]) diff --git a/json_serializable/test/json_serializable_test.dart b/json_serializable/test/json_serializable_test.dart index 646ab4724..8affde81c 100644 --- a/json_serializable/test/json_serializable_test.dart +++ b/json_serializable/test/json_serializable_test.dart @@ -40,17 +40,13 @@ Future<void> main() async { } const _expectedAnnotatedTests = { - 'annotatedMethod', - 'UnsupportedEnum', + 'BadEnumDefaultValue', 'BadFromFuncReturnType', 'BadNoArgs', 'BadOneNamed', 'BadToFuncReturnType', 'BadTwoRequiredPositional', - 'BadEnumDefaultValue', - '_BetterPrivateNames', 'CtorDefaultValueAndJsonKeyDefaultValue', - 'SameCtorAndJsonKeyDefaultValue', 'DefaultDoubleConstants', 'DefaultWithConstObject', 'DefaultWithDisallowNullRequiredClass', @@ -76,9 +72,11 @@ const _expectedAnnotatedTests = { 'GeneralTestClass2', 'GenericArgumentFactoriesFlagWithoutGenericType', 'GenericClass', + 'IgnoreAndIncludeFromJsonFieldCtorClass', + 'IgnoreAndIncludeToJsonFieldCtorClass', + 'IgnoreUnannotated', 'IgnoredFieldClass', 'IgnoredFieldCtorClass', - 'IgnoreUnannotated', 'IncludeIfNullDisallowNullClass', 'IncludeIfNullOverride', 'InvalidChildClassFromJson', @@ -86,8 +84,8 @@ const _expectedAnnotatedTests = { 'InvalidChildClassFromJson3', 'InvalidFromFunc2Args', 'InvalidToFunc2Args', - 'Issue713', 'Issue1038RegressionTest', + 'Issue713', 'JsonConvertOnField', 'JsonConverterCtorParams', 'JsonConverterDuplicateAnnotations', @@ -120,23 +118,24 @@ const _expectedAnnotatedTests = { 'PropInMixinI448Regression', 'Reproduce869NullableGenericType', 'Reproduce869NullableGenericTypeWithDefault', + 'SameCtorAndJsonKeyDefaultValue', 'SetSupport', - 'SubclassedJsonKey', 'SubType', 'SubTypeWithAnnotatedFieldOverrideExtends', 'SubTypeWithAnnotatedFieldOverrideExtendsWithOverrides', 'SubTypeWithAnnotatedFieldOverrideImplements', - 'theAnswer', + 'SubclassedJsonKey', 'TearOffFromJsonClass', 'ToJsonNullableFalseIncludeIfNullFalse', 'TypedConvertMethods', 'UnknownEnumValue', 'UnknownEnumValueListWrongEnumType', 'UnknownEnumValueListWrongType', - 'UnknownEnumValueWrongEnumType', 'UnknownEnumValueNotEnumField', + 'UnknownEnumValueWrongEnumType', 'UnsupportedDateTimeField', 'UnsupportedDurationField', + 'UnsupportedEnum', 'UnsupportedListField', 'UnsupportedMapField', 'UnsupportedSetField', @@ -145,4 +144,7 @@ const _expectedAnnotatedTests = { 'WithANonCtorGetter', 'WithANonCtorGetterChecked', 'WrongConstructorNameClass', + '_BetterPrivateNames', + 'annotatedMethod', + 'theAnswer', }; diff --git a/json_serializable/test/src/_json_serializable_test_input.dart b/json_serializable/test/src/_json_serializable_test_input.dart index 945bf5571..f77864668 100644 --- a/json_serializable/test/src/_json_serializable_test_input.dart +++ b/json_serializable/test/src/_json_serializable_test_input.dart @@ -294,9 +294,11 @@ Map<String, dynamic> _$IgnoredFieldClassToJson(IgnoredFieldClass instance) => ''') @JsonSerializable(createFactory: false) class IgnoredFieldClass { + // ignore: deprecated_member_use @JsonKey(ignore: true) late int ignoredTrueField; + // ignore: deprecated_member_use @JsonKey(ignore: false) late int ignoredFalseField; @@ -304,18 +306,42 @@ class IgnoredFieldClass { } @ShouldThrow( - 'Cannot populate the required constructor argument: ' - 'ignoredTrueField. It is assigned to an ignored field.', + 'Cannot populate the required constructor argument: ignoredTrueField. It is ' + 'assigned to a field not meant to be used in fromJson.', element: '', ) @JsonSerializable() class IgnoredFieldCtorClass { - @JsonKey(ignore: true) + @JsonKey(includeFromJson: false, includeToJson: false) int ignoredTrueField; IgnoredFieldCtorClass(this.ignoredTrueField); } +@ShouldThrow( + 'Error with `@JsonKey` on the `ignoredTrueField` field. ' + 'Cannot use both `ignore` and `includeToJson` on the same field. ' + 'Since `ignore` is deprecated, you should only use `includeToJson`.', +) +@JsonSerializable() +class IgnoreAndIncludeToJsonFieldCtorClass { + // ignore: deprecated_member_use + @JsonKey(ignore: true, includeToJson: true) + int? ignoredTrueField; +} + +@ShouldThrow( + 'Error with `@JsonKey` on the `ignoredTrueField` field. ' + 'Cannot use both `ignore` and `includeFromJson` on the same field. ' + 'Since `ignore` is deprecated, you should only use `includeFromJson`.', +) +@JsonSerializable() +class IgnoreAndIncludeFromJsonFieldCtorClass { + // ignore: deprecated_member_use + @JsonKey(ignore: true, includeFromJson: true) + int? ignoredTrueField; +} + @ShouldThrow( 'Cannot populate the required constructor argument: ' '_privateField. It is assigned to a private field.', diff --git a/json_serializable/test/src/inheritance_test_input.dart b/json_serializable/test/src/inheritance_test_input.dart index 7ea3ffc2b..afd6a6552 100644 --- a/json_serializable/test/src/inheritance_test_input.dart +++ b/json_serializable/test/src/inheritance_test_input.dart @@ -120,7 +120,7 @@ class SubTypeWithAnnotatedFieldOverrideImplements implements SuperType { @override int? superReadWriteField; - @JsonKey(ignore: true) + @JsonKey(includeToJson: false, includeFromJson: false) @override int get priceHalf => 42; diff --git a/json_serializable/tool/field_matrix_builder.dart b/json_serializable/tool/field_matrix_builder.dart new file mode 100644 index 000000000..4288bd782 --- /dev/null +++ b/json_serializable/tool/field_matrix_builder.dart @@ -0,0 +1,88 @@ +// Copyright (c) 2019, 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 'dart:async'; + +import 'package:build/build.dart'; +import 'package:path/path.dart' as p; +import 'package:source_helper/source_helper.dart'; + +import 'shared.dart'; + +Builder builder([_]) => _FieldMatrixBuilder(); + +class _FieldMatrixBuilder extends Builder { + @override + FutureOr<void> build(BuildStep buildStep) async { + final inputBaseName = p.basenameWithoutExtension(buildStep.inputId.path); + + final output = buildStep.allowedOutputs.single; + + final content = StringBuffer(''' +import 'package:json_annotation/json_annotation.dart'; + +part '$inputBaseName.field_matrix.g.dart'; +'''); + + final classes = <String>{}; + + for (var isPublic in [true, false]) { + for (var includeToJson in [null, true, false]) { + for (var includeFromJson in [null, true, false]) { + final className = 'ToJson${includeToJson.toString().pascal}' + 'FromJson${includeFromJson.toString().pascal}' + '${isPublic ? 'Public' : 'Private'}'; + + classes.add(className); + + final fieldName = isPublic ? 'field' : '_field'; + + final bits = [ + if (includeFromJson != null) 'includeFromJson: $includeFromJson,', + if (includeToJson != null) 'includeToJson: $includeToJson,', + if (!isPublic) "name: 'field'", + ]; + + final fieldAnnotation = + bits.isEmpty ? '' : '@JsonKey(${bits.join()})'; + + content.writeln(''' +@JsonSerializable() +class $className { + $className(); + + int? aField; + + $fieldAnnotation + int? $fieldName; + + int? zField; + + factory $className.fromJson(Map<String, dynamic> json) => + _\$${className}FromJson(json); + + Map<String, dynamic> toJson() => _\$${className}ToJson(this); + + @override + String toString() => '$className: $fieldName: \$$fieldName'; +} +'''); + } + } + } + + content.writeln(''' +const fromJsonFactories = <Object Function(Map<String, dynamic>)>{ + ${classes.map((e) => '$e.fromJson,').join()} +}; +'''); + + await buildStep.writeAsString(output, formatter.format(content.toString())); + } + + @override + Map<String, List<String>> get buildExtensions => const { + '.dart': ['.field_matrix.dart'], + }; +} From c6836ae94b99b721083fd904288f844f933187b4 Mon Sep 17 00:00:00 2001 From: Jason Rai <me@jasonrai.ca> Date: Mon, 5 Dec 2022 12:46:38 -0500 Subject: [PATCH 462/569] update example readme to use "dart run" over "pub run" (#1258) `pub run` no longer works on the current Dart SDK, `dart` is the top level command to use. --- example/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/example/README.md b/example/README.md index f515f2544..408878257 100644 --- a/example/README.md +++ b/example/README.md @@ -20,7 +20,7 @@ Annotate your code with classes defined in - See [`lib/example.g.dart`][example_g] for the generated file. -Run `pub run build_runner build` to generate files into your source directory. +Run `dart run build_runner build` to generate files into your source directory. ```console > pub run build_runner build @@ -32,7 +32,7 @@ Run `pub run build_runner build` to generate files into your source directory. [INFO] Build: Succeeded after 4687ms with 1 outputs ``` -_NOTE_: If you're using Flutter, replace `pub run` with +_NOTE_: If you're using Flutter, replace `dart run` with `flutter pub run`. [example]: lib/example.dart From b5c7af1c06b97e8ca134da1ceeba84c99a5d7d15 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Mon, 19 Dec 2022 15:41:13 -0800 Subject: [PATCH 463/569] Work around SDK issue in v3.0-dev (#1262) See https://github.com/dart-lang/sdk/issues/50756 --- checked_yaml/lib/checked_yaml.dart | 8 ++++---- json_serializable/lib/builder.dart | 7 ++++++- json_serializable/pubspec.yaml | 4 +++- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/checked_yaml/lib/checked_yaml.dart b/checked_yaml/lib/checked_yaml.dart index 154c59b02..c9a75ee56 100644 --- a/checked_yaml/lib/checked_yaml.dart +++ b/checked_yaml/lib/checked_yaml.dart @@ -120,12 +120,12 @@ class ParsedYamlException implements Exception { final Object? innerError; ParsedYamlException( - this.message, - YamlNode yamlNode, { + String message, + YamlNode this.yamlNode, { this.innerError, }) : - // ignore: prefer_initializing_formals - yamlNode = yamlNode; + // TODO(kevmoo) remove when dart-lang/sdk#50756 is fixed! + message = message.replaceAll(" of ' in type cast'", ' in type cast'); factory ParsedYamlException.fromYamlException(YamlException exception) => _WrappedYamlException(exception); diff --git a/json_serializable/lib/builder.dart b/json_serializable/lib/builder.dart index c66e3df21..93a3aa2f5 100644 --- a/json_serializable/lib/builder.dart +++ b/json_serializable/lib/builder.dart @@ -39,6 +39,11 @@ Builder jsonSerializable(BuilderOptions options) { lines.add(e.innerError.toString()); } - throw StateError(lines.join('\n')); + throw StateError( + lines + .join('\n') + // TODO(kevmoo) remove when dart-lang/sdk#50756 is fixed! + .replaceAll(" of ' in type cast'", ' in type cast'), + ); } } diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 85ab370d5..c0eece955 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -39,5 +39,7 @@ dev_dependencies: yaml: ^3.0.0 dependency_overrides: + checked_yaml: + path: ../checked_yaml json_annotation: - path: ../json_annotation \ No newline at end of file + path: ../json_annotation From e8f2b32d94c17c009d8b00eca846b860e740a784 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Mon, 2 Jan 2023 15:14:28 -0800 Subject: [PATCH 464/569] Prepare checked_yaml v2.0.2 release (#1265) --- checked_yaml/CHANGELOG.md | 3 ++- checked_yaml/pubspec.yaml | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/checked_yaml/CHANGELOG.md b/checked_yaml/CHANGELOG.md index 1b3736a4d..1b5ac8736 100644 --- a/checked_yaml/CHANGELOG.md +++ b/checked_yaml/CHANGELOG.md @@ -1,7 +1,8 @@ -## 2.0.2-dev +## 2.0.2 - Require `json_annotation` `^4.3.0` - Require Dart SDK `>=2.18` +- Work-around for [dart-lang/sdk#50756](https://github.com/dart-lang/sdk/issues/50756). ## 2.0.1 diff --git a/checked_yaml/pubspec.yaml b/checked_yaml/pubspec.yaml index e9b29cb7e..eb8f98a33 100644 --- a/checked_yaml/pubspec.yaml +++ b/checked_yaml/pubspec.yaml @@ -1,5 +1,5 @@ name: checked_yaml -version: 2.0.2-dev +version: 2.0.2 description: >- Generate more helpful exceptions when decoding YAML documents using From 388010ea13310c66e75f7204d01ecbbca0e9bf32 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Mon, 2 Jan 2023 15:26:39 -0800 Subject: [PATCH 465/569] checked_yaml: drop dep overrides (#1266) --- checked_yaml/pubspec.yaml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/checked_yaml/pubspec.yaml b/checked_yaml/pubspec.yaml index eb8f98a33..945382541 100644 --- a/checked_yaml/pubspec.yaml +++ b/checked_yaml/pubspec.yaml @@ -22,8 +22,8 @@ dev_dependencies: test: ^1.16.0 test_process: ^2.0.0 -dependency_overrides: - json_annotation: - path: ../json_annotation - json_serializable: - path: ../json_serializable +#dependency_overrides: +# json_annotation: +# path: ../json_annotation +# json_serializable: +# path: ../json_serializable From 58db73b4c2c3a0c393e4e7a68f499d28051908ac Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Fri, 13 Jan 2023 16:39:55 -0800 Subject: [PATCH 466/569] Latest mono_repo (#1267) Closes https://github.com/google/json_serializable.dart/pull/1263 Closes https://github.com/google/json_serializable.dart/pull/1264 --- .github/workflows/dart.yml | 56 +++++++++++++++++++------------------- tool/ci.sh | 2 +- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 2f74798c7..0a638cd93 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -1,4 +1,4 @@ -# Created with package:mono_repo v6.4.2 +# Created with package:mono_repo v6.4.3 name: Dart CI on: push: @@ -21,7 +21,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7 + uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:stable" @@ -34,9 +34,9 @@ jobs: sdk: stable - id: checkout name: Checkout repository - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 + uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b - name: mono_repo self validate - run: dart pub global activate mono_repo 6.4.2 + run: dart pub global activate mono_repo 6.4.3 - name: mono_repo self validate run: dart pub global run mono_repo generate --validate job_002: @@ -44,7 +44,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7 + uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.18.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:format-analyze" @@ -59,7 +59,7 @@ jobs: sdk: "2.18.0" - id: checkout name: Checkout repository - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 + uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -130,7 +130,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7 + uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:format-analyze" @@ -145,7 +145,7 @@ jobs: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 + uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -216,7 +216,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7 + uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.18.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" @@ -231,7 +231,7 @@ jobs: sdk: "2.18.0" - id: checkout name: Checkout repository - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 + uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -277,7 +277,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7 + uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.18.0;packages:json_serializable;commands:test_3" @@ -292,7 +292,7 @@ jobs: sdk: "2.18.0" - id: checkout name: Checkout repository - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 + uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -311,7 +311,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7 + uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.18.0;packages:json_serializable;commands:test_1" @@ -326,7 +326,7 @@ jobs: sdk: "2.18.0" - id: checkout name: Checkout repository - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 + uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -345,7 +345,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7 + uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.18.0;packages:json_serializable;commands:test_2" @@ -360,7 +360,7 @@ jobs: sdk: "2.18.0" - id: checkout name: Checkout repository - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 + uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -379,7 +379,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7 + uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" @@ -394,7 +394,7 @@ jobs: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 + uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -440,7 +440,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7 + uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:json_serializable;commands:test_3" @@ -455,7 +455,7 @@ jobs: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 + uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -474,7 +474,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7 + uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:json_serializable;commands:test_1" @@ -489,7 +489,7 @@ jobs: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 + uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -508,7 +508,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7 + uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:json_serializable;commands:test_2" @@ -523,7 +523,7 @@ jobs: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 + uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -542,7 +542,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7 + uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.18.0;packages:_test_yaml-checked_yaml-example;commands:test_1" @@ -557,7 +557,7 @@ jobs: sdk: "2.18.0" - id: checkout name: Checkout repository - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 + uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -602,7 +602,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7 + uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:_test_yaml-checked_yaml-example;commands:test_1" @@ -617,7 +617,7 @@ jobs: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 + uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade diff --git a/tool/ci.sh b/tool/ci.sh index 3b8269ea3..45e617f64 100755 --- a/tool/ci.sh +++ b/tool/ci.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Created with package:mono_repo v6.4.2 +# Created with package:mono_repo v6.4.3 # Support built in commands on windows out of the box. # When it is a flutter repo (check the pubspec.yaml for "sdk: flutter") From 44d0080ac8dc5e116af2bd00d5ee5e07f630b7dc Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Thu, 19 Jan 2023 11:58:25 -0800 Subject: [PATCH 467/569] Prepare to release pkg:json_annotation v4.8.0 (#1268) --- json_annotation/CHANGELOG.md | 2 +- json_annotation/pubspec.yaml | 2 +- json_serializable/CHANGELOG.md | 3 ++- json_serializable/README.md | 18 +++++++++--------- json_serializable/pubspec.yaml | 2 +- 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index 5697f95a2..d784ddeed 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -1,4 +1,4 @@ -## 4.8.0-dev +## 4.8.0 - DEPRECATED `JsonKey.ignore`. Replaced by... - Added `JsonKey.includeFromJson` and `JsonKey.includeToJson` to allow diff --git a/json_annotation/pubspec.yaml b/json_annotation/pubspec.yaml index f80c93b77..68397aea3 100644 --- a/json_annotation/pubspec.yaml +++ b/json_annotation/pubspec.yaml @@ -1,5 +1,5 @@ name: json_annotation -version: 4.8.0-dev +version: 4.8.0 description: >- Classes and helper functions that support JSON code generation via the `json_serializable` package. diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index d42ed892f..0fd1ed5e5 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,7 +1,8 @@ -## 6.6.0-dev +## 6.6.0 - Support for `JsonKey.includeFromJson` and `JsonKey.includeToJson`. - Support `JsonEnum.valueField` being 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'` diff --git a/json_serializable/README.md b/json_serializable/README.md index deb8a86a7..d11f294b3 100644 --- a/json_serializable/README.md +++ b/json_serializable/README.md @@ -300,15 +300,15 @@ targets: [`Enum`]: https://api.dart.dev/stable/dart-core/Enum-class.html [`int`]: https://api.dart.dev/stable/dart-core/int-class.html [`Iterable`]: https://api.dart.dev/stable/dart-core/Iterable-class.html -[`JsonConverter`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonConverter-class.html -[`JsonEnum.valueField`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonEnum/valueField.html -[`JsonEnum`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonEnum-class.html -[`JsonKey.fromJson`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/fromJson.html -[`JsonKey.toJson`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/toJson.html -[`JsonKey`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey-class.html -[`JsonLiteral`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonLiteral-class.html -[`JsonSerializable`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable-class.html -[`JsonValue`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonValue-class.html +[`JsonConverter`]: https://pub.dev/documentation/json_annotation/4.8.0/json_annotation/JsonConverter-class.html +[`JsonEnum.valueField`]: https://pub.dev/documentation/json_annotation/4.8.0/json_annotation/JsonEnum/valueField.html +[`JsonEnum`]: https://pub.dev/documentation/json_annotation/4.8.0/json_annotation/JsonEnum-class.html +[`JsonKey.fromJson`]: https://pub.dev/documentation/json_annotation/4.8.0/json_annotation/JsonKey/fromJson.html +[`JsonKey.toJson`]: https://pub.dev/documentation/json_annotation/4.8.0/json_annotation/JsonKey/toJson.html +[`JsonKey`]: https://pub.dev/documentation/json_annotation/4.8.0/json_annotation/JsonKey-class.html +[`JsonLiteral`]: https://pub.dev/documentation/json_annotation/4.8.0/json_annotation/JsonLiteral-class.html +[`JsonSerializable`]: https://pub.dev/documentation/json_annotation/4.8.0/json_annotation/JsonSerializable-class.html +[`JsonValue`]: https://pub.dev/documentation/json_annotation/4.8.0/json_annotation/JsonValue-class.html [`List`]: https://api.dart.dev/stable/dart-core/List-class.html [`Map`]: https://api.dart.dev/stable/dart-core/Map-class.html [`num`]: https://api.dart.dev/stable/dart-core/num-class.html diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index c0eece955..a41b8b2cc 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 6.6.0-dev +version: 6.6.0 description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. From 832fc7b54a036823c013a98e8f24918c2dc7860a Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Thu, 19 Jan 2023 12:35:31 -0800 Subject: [PATCH 468/569] Prepare to release json_serializable v6.6.0 (#1269) --- json_serializable/pubspec.yaml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index a41b8b2cc..0807ca23f 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -37,9 +37,3 @@ dev_dependencies: test_descriptor: ^2.0.0 test_process: ^2.0.0 yaml: ^3.0.0 - -dependency_overrides: - checked_yaml: - path: ../checked_yaml - json_annotation: - path: ../json_annotation From bccf4b39ed845e8026e7828c82423c972075b114 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Thu, 19 Jan 2023 13:34:17 -0800 Subject: [PATCH 469/569] example: cleanup readme and pubspec (#1270) --- example/README.md | 8 ++++---- example/pubspec.yaml | 11 ++++++++--- example/test/readme_test.dart | 6 +++--- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/example/README.md b/example/README.md index 408878257..20b58a5c7 100644 --- a/example/README.md +++ b/example/README.md @@ -5,11 +5,11 @@ dependencies to your `pubspec.yaml`. ```yaml dependencies: - json_annotation: ^4.7.0 + json_annotation: ^4.8.0 dev_dependencies: - build_runner: ^2.0.0 - json_serializable: ^6.0.0 + build_runner: ^2.3.3 + json_serializable: ^6.6.0 ``` Annotate your code with classes defined in @@ -23,7 +23,7 @@ Annotate your code with classes defined in Run `dart run build_runner build` to generate files into your source directory. ```console -> pub run build_runner build +> dart pub run build_runner build [INFO] ensureBuildScript: Generating build script completed, took 368ms [INFO] BuildDefinition: Reading cached asset graph completed, took 54ms [INFO] BuildDefinition: Checking for updates since last build completed, took 663ms diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 758ca0b33..4e4cb64f4 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -5,24 +5,29 @@ environment: sdk: '>=2.18.0 <3.0.0' dependencies: - json_annotation: ^4.7.0 + json_annotation: ^4.8.0 dev_dependencies: # Used by tests. Not required to use `json_serializable`. _json_serial_shared_test: path: ../shared_test - build_runner: ^2.0.0 + + # REQUIRED! + build_runner: ^2.3.3 # Used by tests. Not required to use `json_serializable`. build_verify: ^3.0.0 - json_serializable: ^6.0.0 + # REQUIRED! + json_serializable: ^6.6.0 # Not required to use `json_serializable`. lints: ^2.0.0 path: ^1.8.0 test: ^1.16.0 +# This section is used to verify changes to these packages. Do not include in +# your code! dependency_overrides: json_annotation: path: ../json_annotation diff --git a/example/test/readme_test.dart b/example/test/readme_test.dart index dd4892155..ab3267f8b 100644 --- a/example/test/readme_test.dart +++ b/example/test/readme_test.dart @@ -25,9 +25,9 @@ void _expect(String fileName) { const _pubspecContent = r''' dependencies: - json_annotation: ^4.7.0 + json_annotation: ^4.8.0 dev_dependencies: - build_runner: ^2.0.0 - json_serializable: ^6.0.0 + build_runner: ^2.3.3 + json_serializable: ^6.6.0 '''; From 217f21e6762a6f7b765b4338c7b7f7e35412726e Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Tue, 31 Jan 2023 12:47:10 -0800 Subject: [PATCH 470/569] Enable and fix new lints (#1274) --- _test_yaml/test/ensure_build_test.dart | 2 ++ _test_yaml/test/yaml_test.dart | 2 ++ analysis_options.yaml | 8 ++++++++ checked_yaml/test/ensure_build_test.dart | 2 ++ example/test/ensure_build_test.dart | 2 ++ json_serializable/lib/type_helper.dart | 2 +- json_serializable/test/annotation_version_test.dart | 2 ++ json_serializable/test/config_test.dart | 2 ++ json_serializable/test/custom_configuration_test.dart | 2 ++ json_serializable/test/default_value/default_value.dart | 2 +- .../default_value/default_value.g_any_map__checked.dart | 2 +- json_serializable/test/ensure_build_test.dart | 2 ++ json_serializable/test/enum_helper_test.dart | 2 ++ json_serializable/test/json_serializable_test.dart | 2 ++ json_serializable/test/literal/json_literal_test.dart | 2 ++ .../test/supported_types/extra_map_test.dart | 1 + .../test/supported_types/type_test.bigint_test.dart | 1 + .../test/supported_types/type_test.bool_test.dart | 1 + json_serializable/test/supported_types/type_test.dart | 1 + .../test/supported_types/type_test.datetime_test.dart | 1 + .../test/supported_types/type_test.double_test.dart | 1 + .../test/supported_types/type_test.duration_test.dart | 1 + .../test/supported_types/type_test.enumtype_test.dart | 1 + .../test/supported_types/type_test.int_test.dart | 1 + .../test/supported_types/type_test.iterable_test.dart | 1 + .../test/supported_types/type_test.list_test.dart | 1 + .../test/supported_types/type_test.map_test.dart | 1 + .../test/supported_types/type_test.num_test.dart | 1 + .../test/supported_types/type_test.object_test.dart | 1 + .../test/supported_types/type_test.set_test.dart | 1 + .../test/supported_types/type_test.string_test.dart | 1 + .../test/supported_types/type_test.uri_test.dart | 1 + 32 files changed, 50 insertions(+), 3 deletions(-) diff --git a/_test_yaml/test/ensure_build_test.dart b/_test_yaml/test/ensure_build_test.dart index 4de07e5ee..868332ed6 100644 --- a/_test_yaml/test/ensure_build_test.dart +++ b/_test_yaml/test/ensure_build_test.dart @@ -4,6 +4,8 @@ @TestOn('vm') @Tags(['presubmit-only']) +library test; + import 'package:build_verify/build_verify.dart'; import 'package:test/test.dart'; diff --git a/_test_yaml/test/yaml_test.dart b/_test_yaml/test/yaml_test.dart index 428587d78..96f698b05 100644 --- a/_test_yaml/test/yaml_test.dart +++ b/_test_yaml/test/yaml_test.dart @@ -3,6 +3,8 @@ // BSD-style license that can be found in the LICENSE file. @TestOn('vm') +library test; + import 'dart:io'; import 'package:_json_serial_shared_test/shared_test.dart'; diff --git a/analysis_options.yaml b/analysis_options.yaml index eb8ce5989..8a6ede19c 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -16,9 +16,14 @@ linter: - avoid_void_async - cancel_subscriptions - cascade_invocations + - collection_methods_unrelated_type + - combinators_ordering - comment_references + - dangling_library_doc_comments - directives_ordering + - implicit_call_tearoffs - join_return_with_assignment + - library_annotations - lines_longer_than_80_chars - literal_only_boolean_expressions - missing_whitespace_between_adjacent_strings @@ -40,10 +45,13 @@ linter: - type_annotate_public_apis - unawaited_futures - unnecessary_lambdas + - unnecessary_library_directive - unnecessary_parenthesis - unnecessary_statements + - unreachable_from_main - unsafe_html - use_full_hex_values_for_flutter_colors - use_is_even_rather_than_modulo - use_string_buffers + - use_string_in_part_of_directives - use_super_parameters diff --git a/checked_yaml/test/ensure_build_test.dart b/checked_yaml/test/ensure_build_test.dart index 088218dcf..0a5935d7b 100644 --- a/checked_yaml/test/ensure_build_test.dart +++ b/checked_yaml/test/ensure_build_test.dart @@ -4,6 +4,8 @@ @TestOn('vm') @Tags(['presubmit-only']) +library test; + import 'package:build_verify/build_verify.dart'; import 'package:test/test.dart'; diff --git a/example/test/ensure_build_test.dart b/example/test/ensure_build_test.dart index 7fd35a448..5d06a2fd1 100644 --- a/example/test/ensure_build_test.dart +++ b/example/test/ensure_build_test.dart @@ -3,6 +3,8 @@ // BSD-style license that can be found in the LICENSE file. @Tags(['presubmit-only']) +library test; + import 'package:build_verify/build_verify.dart'; import 'package:test/test.dart'; diff --git a/json_serializable/lib/type_helper.dart b/json_serializable/lib/type_helper.dart index d79a2ada7..4caa64137 100644 --- a/json_serializable/lib/type_helper.dart +++ b/json_serializable/lib/type_helper.dart @@ -4,7 +4,7 @@ export 'src/shared_checkers.dart' show simpleJsonTypeChecker; export 'src/type_helper.dart' - show TypeHelperContext, TypeHelperContextWithConfig, TypeHelper; + show TypeHelper, TypeHelperContext, TypeHelperContextWithConfig; export 'src/type_helpers/big_int_helper.dart'; export 'src/type_helpers/config_types.dart'; export 'src/type_helpers/convert_helper.dart'; diff --git a/json_serializable/test/annotation_version_test.dart b/json_serializable/test/annotation_version_test.dart index 1ff0b4d62..349ca8b6d 100644 --- a/json_serializable/test/annotation_version_test.dart +++ b/json_serializable/test/annotation_version_test.dart @@ -4,6 +4,8 @@ @TestOn('vm') @Tags(['presubmit-only']) +library test; + import 'dart:io'; import 'package:json_serializable/src/check_dependencies.dart'; diff --git a/json_serializable/test/config_test.dart b/json_serializable/test/config_test.dart index 5c8dcef0e..a8355f117 100644 --- a/json_serializable/test/config_test.dart +++ b/json_serializable/test/config_test.dart @@ -3,6 +3,8 @@ // BSD-style license that can be found in the LICENSE file. @TestOn('vm') +library test; + import 'dart:io'; import 'package:build/build.dart'; diff --git a/json_serializable/test/custom_configuration_test.dart b/json_serializable/test/custom_configuration_test.dart index 649815905..8fc7ce097 100644 --- a/json_serializable/test/custom_configuration_test.dart +++ b/json_serializable/test/custom_configuration_test.dart @@ -3,6 +3,8 @@ // BSD-style license that can be found in the LICENSE file. @TestOn('vm') +library test; + import 'dart:async'; import 'package:analyzer/dart/element/type.dart'; diff --git a/json_serializable/test/default_value/default_value.dart b/json_serializable/test/default_value/default_value.dart index 65a8fe9ad..0894af857 100644 --- a/json_serializable/test/default_value/default_value.dart +++ b/json_serializable/test/default_value/default_value.dart @@ -9,9 +9,9 @@ import 'package:json_annotation/json_annotation.dart'; import 'default_value_interface.dart' as dvi hide Greek; import 'default_value_interface.dart' show - Greek, ConstClass, ConstClassConverter, + Greek, constClassFromJson, constClassToJson, intDefaultValueFunction; diff --git a/json_serializable/test/default_value/default_value.g_any_map__checked.dart b/json_serializable/test/default_value/default_value.g_any_map__checked.dart index 07e12fb29..be46b0133 100644 --- a/json_serializable/test/default_value/default_value.g_any_map__checked.dart +++ b/json_serializable/test/default_value/default_value.g_any_map__checked.dart @@ -9,9 +9,9 @@ import 'package:json_annotation/json_annotation.dart'; import 'default_value_interface.dart' as dvi hide Greek; import 'default_value_interface.dart' show - Greek, ConstClass, ConstClassConverter, + Greek, constClassFromJson, constClassToJson, intDefaultValueFunction; diff --git a/json_serializable/test/ensure_build_test.dart b/json_serializable/test/ensure_build_test.dart index de538c834..a8c75e638 100644 --- a/json_serializable/test/ensure_build_test.dart +++ b/json_serializable/test/ensure_build_test.dart @@ -4,6 +4,8 @@ @TestOn('vm') @Tags(['presubmit-only']) +library test; + import 'package:build_verify/build_verify.dart'; import 'package:test/test.dart'; diff --git a/json_serializable/test/enum_helper_test.dart b/json_serializable/test/enum_helper_test.dart index 4399dc843..cfc18ad9b 100644 --- a/json_serializable/test/enum_helper_test.dart +++ b/json_serializable/test/enum_helper_test.dart @@ -3,6 +3,8 @@ // BSD-style license that can be found in the LICENSE file. @TestOn('vm') +library test; + import 'package:json_serializable/src/type_helpers/enum_helper.dart'; import 'package:test/test.dart'; diff --git a/json_serializable/test/json_serializable_test.dart b/json_serializable/test/json_serializable_test.dart index 8affde81c..5644b51cb 100644 --- a/json_serializable/test/json_serializable_test.dart +++ b/json_serializable/test/json_serializable_test.dart @@ -3,6 +3,8 @@ // BSD-style license that can be found in the LICENSE file. @TestOn('vm') +library test; + import 'package:json_serializable/json_serializable.dart'; import 'package:path/path.dart' as p; import 'package:source_gen_test/source_gen_test.dart'; diff --git a/json_serializable/test/literal/json_literal_test.dart b/json_serializable/test/literal/json_literal_test.dart index d8d6c2643..edcb7855f 100644 --- a/json_serializable/test/literal/json_literal_test.dart +++ b/json_serializable/test/literal/json_literal_test.dart @@ -3,6 +3,8 @@ // BSD-style license that can be found in the LICENSE file. @TestOn('vm') +library test; + import 'dart:convert'; import 'dart:io'; diff --git a/json_serializable/test/supported_types/extra_map_test.dart b/json_serializable/test/supported_types/extra_map_test.dart index 0bdea277c..449a8d9ba 100644 --- a/json_serializable/test/supported_types/extra_map_test.dart +++ b/json_serializable/test/supported_types/extra_map_test.dart @@ -4,6 +4,7 @@ // ignore_for_file: prefer_const_declarations @TestOn('vm') +library test; import 'dart:convert'; diff --git a/json_serializable/test/supported_types/type_test.bigint_test.dart b/json_serializable/test/supported_types/type_test.bigint_test.dart index 579298f0e..26e7a001b 100644 --- a/json_serializable/test/supported_types/type_test.bigint_test.dart +++ b/json_serializable/test/supported_types/type_test.bigint_test.dart @@ -4,6 +4,7 @@ // ignore_for_file: prefer_const_declarations @TestOn('vm') +library test; import 'dart:convert'; diff --git a/json_serializable/test/supported_types/type_test.bool_test.dart b/json_serializable/test/supported_types/type_test.bool_test.dart index 1d66ca8ce..19247a81c 100644 --- a/json_serializable/test/supported_types/type_test.bool_test.dart +++ b/json_serializable/test/supported_types/type_test.bool_test.dart @@ -4,6 +4,7 @@ // ignore_for_file: prefer_const_declarations @TestOn('vm') +library test; import 'dart:convert'; diff --git a/json_serializable/test/supported_types/type_test.dart b/json_serializable/test/supported_types/type_test.dart index 1a94d75ed..1d5d72ded 100644 --- a/json_serializable/test/supported_types/type_test.dart +++ b/json_serializable/test/supported_types/type_test.dart @@ -4,6 +4,7 @@ // ignore_for_file: prefer_const_declarations @TestOn('vm') +library test; import 'dart:convert'; diff --git a/json_serializable/test/supported_types/type_test.datetime_test.dart b/json_serializable/test/supported_types/type_test.datetime_test.dart index 5e16b81e5..dee0b5cf5 100644 --- a/json_serializable/test/supported_types/type_test.datetime_test.dart +++ b/json_serializable/test/supported_types/type_test.datetime_test.dart @@ -4,6 +4,7 @@ // ignore_for_file: prefer_const_declarations @TestOn('vm') +library test; import 'dart:convert'; diff --git a/json_serializable/test/supported_types/type_test.double_test.dart b/json_serializable/test/supported_types/type_test.double_test.dart index c9db8891a..4704157ff 100644 --- a/json_serializable/test/supported_types/type_test.double_test.dart +++ b/json_serializable/test/supported_types/type_test.double_test.dart @@ -4,6 +4,7 @@ // ignore_for_file: prefer_const_declarations @TestOn('vm') +library test; import 'dart:convert'; diff --git a/json_serializable/test/supported_types/type_test.duration_test.dart b/json_serializable/test/supported_types/type_test.duration_test.dart index c19af16cd..f7651278c 100644 --- a/json_serializable/test/supported_types/type_test.duration_test.dart +++ b/json_serializable/test/supported_types/type_test.duration_test.dart @@ -4,6 +4,7 @@ // ignore_for_file: prefer_const_declarations @TestOn('vm') +library test; import 'dart:convert'; diff --git a/json_serializable/test/supported_types/type_test.enumtype_test.dart b/json_serializable/test/supported_types/type_test.enumtype_test.dart index 568ddb615..cd2b527e4 100644 --- a/json_serializable/test/supported_types/type_test.enumtype_test.dart +++ b/json_serializable/test/supported_types/type_test.enumtype_test.dart @@ -4,6 +4,7 @@ // ignore_for_file: prefer_const_declarations @TestOn('vm') +library test; import 'dart:convert'; diff --git a/json_serializable/test/supported_types/type_test.int_test.dart b/json_serializable/test/supported_types/type_test.int_test.dart index 9f5a81b1f..9f36677dd 100644 --- a/json_serializable/test/supported_types/type_test.int_test.dart +++ b/json_serializable/test/supported_types/type_test.int_test.dart @@ -4,6 +4,7 @@ // ignore_for_file: prefer_const_declarations @TestOn('vm') +library test; import 'dart:convert'; diff --git a/json_serializable/test/supported_types/type_test.iterable_test.dart b/json_serializable/test/supported_types/type_test.iterable_test.dart index 658ed97e1..a9c34fee7 100644 --- a/json_serializable/test/supported_types/type_test.iterable_test.dart +++ b/json_serializable/test/supported_types/type_test.iterable_test.dart @@ -4,6 +4,7 @@ // ignore_for_file: prefer_const_declarations @TestOn('vm') +library test; import 'dart:convert'; diff --git a/json_serializable/test/supported_types/type_test.list_test.dart b/json_serializable/test/supported_types/type_test.list_test.dart index adbd2ed4a..007a386a3 100644 --- a/json_serializable/test/supported_types/type_test.list_test.dart +++ b/json_serializable/test/supported_types/type_test.list_test.dart @@ -4,6 +4,7 @@ // ignore_for_file: prefer_const_declarations @TestOn('vm') +library test; import 'dart:convert'; diff --git a/json_serializable/test/supported_types/type_test.map_test.dart b/json_serializable/test/supported_types/type_test.map_test.dart index e814f7bd2..54a37fa9c 100644 --- a/json_serializable/test/supported_types/type_test.map_test.dart +++ b/json_serializable/test/supported_types/type_test.map_test.dart @@ -4,6 +4,7 @@ // ignore_for_file: prefer_const_declarations @TestOn('vm') +library test; import 'dart:convert'; diff --git a/json_serializable/test/supported_types/type_test.num_test.dart b/json_serializable/test/supported_types/type_test.num_test.dart index 1ebf28dbe..8bc9e72b5 100644 --- a/json_serializable/test/supported_types/type_test.num_test.dart +++ b/json_serializable/test/supported_types/type_test.num_test.dart @@ -4,6 +4,7 @@ // ignore_for_file: prefer_const_declarations @TestOn('vm') +library test; import 'dart:convert'; diff --git a/json_serializable/test/supported_types/type_test.object_test.dart b/json_serializable/test/supported_types/type_test.object_test.dart index 7f8e7f4b6..c7f28dd71 100644 --- a/json_serializable/test/supported_types/type_test.object_test.dart +++ b/json_serializable/test/supported_types/type_test.object_test.dart @@ -4,6 +4,7 @@ // ignore_for_file: prefer_const_declarations @TestOn('vm') +library test; import 'dart:convert'; diff --git a/json_serializable/test/supported_types/type_test.set_test.dart b/json_serializable/test/supported_types/type_test.set_test.dart index 1a0c0133d..4dfc0b82f 100644 --- a/json_serializable/test/supported_types/type_test.set_test.dart +++ b/json_serializable/test/supported_types/type_test.set_test.dart @@ -4,6 +4,7 @@ // ignore_for_file: prefer_const_declarations @TestOn('vm') +library test; import 'dart:convert'; diff --git a/json_serializable/test/supported_types/type_test.string_test.dart b/json_serializable/test/supported_types/type_test.string_test.dart index c239eab85..f7ed73127 100644 --- a/json_serializable/test/supported_types/type_test.string_test.dart +++ b/json_serializable/test/supported_types/type_test.string_test.dart @@ -4,6 +4,7 @@ // ignore_for_file: prefer_const_declarations @TestOn('vm') +library test; import 'dart:convert'; diff --git a/json_serializable/test/supported_types/type_test.uri_test.dart b/json_serializable/test/supported_types/type_test.uri_test.dart index b60773780..4b8493ca4 100644 --- a/json_serializable/test/supported_types/type_test.uri_test.dart +++ b/json_serializable/test/supported_types/type_test.uri_test.dart @@ -4,6 +4,7 @@ // ignore_for_file: prefer_const_declarations @TestOn('vm') +library test; import 'dart:convert'; From 5ab50723ab4e7630f5d119899b03f289bf1e491a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 31 Jan 2023 23:40:04 -0800 Subject: [PATCH 471/569] Bump actions/setup-node from 3.5.1 to 3.6.0 (#1278) Bumps [actions/setup-node](https://github.com/actions/setup-node) from 3.5.1 to 3.6.0. - [Release notes](https://github.com/actions/setup-node/releases) - [Commits](https://github.com/actions/setup-node/compare/8c91899e586c5b171469028077307d293428b516...64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c) --- updated-dependencies: - dependency-name: actions/setup-node dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/markdown_linter.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/markdown_linter.yml b/.github/workflows/markdown_linter.yml index 3ec98ad09..ea9a0099b 100644 --- a/.github/workflows/markdown_linter.yml +++ b/.github/workflows/markdown_linter.yml @@ -21,7 +21,7 @@ jobs: steps: - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@8c91899e586c5b171469028077307d293428b516 + uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c with: node-version: ${{ matrix.node-version }} - name: Install dependencies From 8f31d52928eb70031077453b849a803e89d270c4 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Wed, 1 Feb 2023 09:23:20 -0800 Subject: [PATCH 472/569] Latest CI actions (#1279) Double timeout for annotation_version_test --- .github/workflows/dart.yml | 82 +++++++++---------- .../test/annotation_version_test.dart | 1 + tool/ci.sh | 2 +- 3 files changed, 43 insertions(+), 42 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 0a638cd93..983df2316 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -1,4 +1,4 @@ -# Created with package:mono_repo v6.4.3 +# Created with package:mono_repo v6.5.0 name: Dart CI on: push: @@ -21,7 +21,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d + uses: actions/cache@627f0f41f6904a5b1efbaed9f96d9eb58e92e920 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:stable" @@ -29,14 +29,14 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d + uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 with: sdk: stable - id: checkout name: Checkout repository - uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b + uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c - name: mono_repo self validate - run: dart pub global activate mono_repo 6.4.3 + run: dart pub global activate mono_repo 6.5.0 - name: mono_repo self validate run: dart pub global run mono_repo generate --validate job_002: @@ -44,7 +44,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d + uses: actions/cache@627f0f41f6904a5b1efbaed9f96d9eb58e92e920 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.18.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:format-analyze" @@ -54,12 +54,12 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d + uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 with: sdk: "2.18.0" - id: checkout name: Checkout repository - uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b + uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -130,7 +130,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d + uses: actions/cache@627f0f41f6904a5b1efbaed9f96d9eb58e92e920 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:format-analyze" @@ -140,12 +140,12 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d + uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 with: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b + uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -216,7 +216,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d + uses: actions/cache@627f0f41f6904a5b1efbaed9f96d9eb58e92e920 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.18.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" @@ -226,12 +226,12 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d + uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 with: sdk: "2.18.0" - id: checkout name: Checkout repository - uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b + uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -277,7 +277,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d + uses: actions/cache@627f0f41f6904a5b1efbaed9f96d9eb58e92e920 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.18.0;packages:json_serializable;commands:test_3" @@ -287,12 +287,12 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d + uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 with: sdk: "2.18.0" - id: checkout name: Checkout repository - uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b + uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -311,7 +311,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d + uses: actions/cache@627f0f41f6904a5b1efbaed9f96d9eb58e92e920 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.18.0;packages:json_serializable;commands:test_1" @@ -321,12 +321,12 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d + uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 with: sdk: "2.18.0" - id: checkout name: Checkout repository - uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b + uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -345,7 +345,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d + uses: actions/cache@627f0f41f6904a5b1efbaed9f96d9eb58e92e920 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.18.0;packages:json_serializable;commands:test_2" @@ -355,12 +355,12 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d + uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 with: sdk: "2.18.0" - id: checkout name: Checkout repository - uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b + uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -379,7 +379,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d + uses: actions/cache@627f0f41f6904a5b1efbaed9f96d9eb58e92e920 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" @@ -389,12 +389,12 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d + uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 with: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b + uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -440,7 +440,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d + uses: actions/cache@627f0f41f6904a5b1efbaed9f96d9eb58e92e920 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:json_serializable;commands:test_3" @@ -450,12 +450,12 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d + uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 with: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b + uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -474,7 +474,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d + uses: actions/cache@627f0f41f6904a5b1efbaed9f96d9eb58e92e920 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:json_serializable;commands:test_1" @@ -484,12 +484,12 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d + uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 with: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b + uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -508,7 +508,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d + uses: actions/cache@627f0f41f6904a5b1efbaed9f96d9eb58e92e920 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:json_serializable;commands:test_2" @@ -518,12 +518,12 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d + uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 with: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b + uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -542,7 +542,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d + uses: actions/cache@627f0f41f6904a5b1efbaed9f96d9eb58e92e920 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.18.0;packages:_test_yaml-checked_yaml-example;commands:test_1" @@ -552,12 +552,12 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d + uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 with: sdk: "2.18.0" - id: checkout name: Checkout repository - uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b + uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -602,7 +602,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d + uses: actions/cache@627f0f41f6904a5b1efbaed9f96d9eb58e92e920 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:_test_yaml-checked_yaml-example;commands:test_1" @@ -612,12 +612,12 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d + uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 with: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b + uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade diff --git a/json_serializable/test/annotation_version_test.dart b/json_serializable/test/annotation_version_test.dart index 349ca8b6d..a12d3398b 100644 --- a/json_serializable/test/annotation_version_test.dart +++ b/json_serializable/test/annotation_version_test.dart @@ -4,6 +4,7 @@ @TestOn('vm') @Tags(['presubmit-only']) +@Timeout.factor(2) library test; import 'dart:io'; diff --git a/tool/ci.sh b/tool/ci.sh index 45e617f64..d0d8faa8f 100755 --- a/tool/ci.sh +++ b/tool/ci.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Created with package:mono_repo v6.4.3 +# Created with package:mono_repo v6.5.0 # Support built in commands on windows out of the box. # When it is a flutter repo (check the pubspec.yaml for "sdk: flutter") From d49a5f25af9ba02a013502475f324df3f54a4686 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Wed, 1 Feb 2023 13:12:11 -0800 Subject: [PATCH 473/569] Fix bug when `JsonKey.includeToJson` is `false` (#1281) Fixes https://github.com/google/json_serializable.dart/issues/1280 --- json_serializable/CHANGELOG.md | 4 ++++ .../lib/src/generator_helper.dart | 2 +- json_serializable/pubspec.yaml | 2 +- json_serializable/test/field_matrix_test.dart | 20 +++++++++---------- .../field_matrix_test.field_matrix.g.dart | 5 ++--- 5 files changed, 18 insertions(+), 15 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 0fd1ed5e5..d4e683d06 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,7 @@ +## 6.6.1 + +- Fix bug when `JsonKey.includeToJson` is `false`. + ## 6.6.0 - Support for `JsonKey.includeFromJson` and `JsonKey.includeToJson`. diff --git a/json_serializable/lib/src/generator_helper.dart b/json_serializable/lib/src/generator_helper.dart index 1b8621156..501df9469 100644 --- a/json_serializable/lib/src/generator_helper.dart +++ b/json_serializable/lib/src/generator_helper.dart @@ -151,5 +151,5 @@ extension on KeyConfig { bool get explicitYesToJson => includeToJson == true; - bool get explicitNoToJson => includeFromJson == false; + bool get explicitNoToJson => includeToJson == false; } diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 0807ca23f..678000181 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 6.6.0 +version: 6.6.1 description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. diff --git a/json_serializable/test/field_matrix_test.dart b/json_serializable/test/field_matrix_test.dart index 0e18091f9..8f1abff1a 100644 --- a/json_serializable/test/field_matrix_test.dart +++ b/json_serializable/test/field_matrix_test.dart @@ -40,16 +40,16 @@ const _expectedResult = { 'without': {'aField': null, 'field': null, 'zField': null} }, 'ToJsonTrueFromJsonFalsePublic: field: null': { - 'with': {'aField': null, 'zField': null}, - 'without': {'aField': null, 'zField': null} + 'with': {'aField': null, 'field': null, 'zField': null}, + 'without': {'aField': null, 'field': null, 'zField': null} }, 'ToJsonFalseFromJsonNullPublic: field: 42': { - 'with': {'aField': null, 'field': 42, 'zField': null}, - 'without': {'aField': null, 'field': null, 'zField': null} + 'with': {'aField': null, 'zField': null}, + 'without': {'aField': null, 'zField': null} }, 'ToJsonFalseFromJsonTruePublic: field: 42': { - 'with': {'aField': null, 'field': 42, 'zField': null}, - 'without': {'aField': null, 'field': null, 'zField': null} + 'with': {'aField': null, 'zField': null}, + 'without': {'aField': null, 'zField': null} }, 'ToJsonFalseFromJsonFalsePublic: field: null': { 'with': {'aField': null, 'zField': null}, @@ -76,16 +76,16 @@ const _expectedResult = { 'without': {'aField': null, 'field': null, 'zField': null} }, 'ToJsonTrueFromJsonFalsePrivate: _field: null': { - 'with': {'aField': null, 'zField': null}, - 'without': {'aField': null, 'zField': null} + 'with': {'aField': null, 'field': null, 'zField': null}, + 'without': {'aField': null, 'field': null, 'zField': null} }, 'ToJsonFalseFromJsonNullPrivate: _field: null': { 'with': {'aField': null, 'zField': null}, 'without': {'aField': null, 'zField': null} }, 'ToJsonFalseFromJsonTruePrivate: _field: 42': { - 'with': {'aField': null, 'field': 42, 'zField': null}, - 'without': {'aField': null, 'field': null, 'zField': null} + 'with': {'aField': null, 'zField': null}, + 'without': {'aField': null, 'zField': null} }, 'ToJsonFalseFromJsonFalsePrivate: _field: null': { 'with': {'aField': null, 'zField': null}, diff --git a/json_serializable/test/field_matrix_test.field_matrix.g.dart b/json_serializable/test/field_matrix_test.field_matrix.g.dart index dd948315f..cdb054b03 100644 --- a/json_serializable/test/field_matrix_test.field_matrix.g.dart +++ b/json_serializable/test/field_matrix_test.field_matrix.g.dart @@ -91,6 +91,7 @@ Map<String, dynamic> _$ToJsonTrueFromJsonFalsePublicToJson( ToJsonTrueFromJsonFalsePublic instance) => <String, dynamic>{ 'aField': instance.aField, + 'field': instance.field, 'zField': instance.zField, }; @@ -105,7 +106,6 @@ Map<String, dynamic> _$ToJsonFalseFromJsonNullPublicToJson( ToJsonFalseFromJsonNullPublic instance) => <String, dynamic>{ 'aField': instance.aField, - 'field': instance.field, 'zField': instance.zField, }; @@ -120,7 +120,6 @@ Map<String, dynamic> _$ToJsonFalseFromJsonTruePublicToJson( ToJsonFalseFromJsonTruePublic instance) => <String, dynamic>{ 'aField': instance.aField, - 'field': instance.field, 'zField': instance.zField, }; @@ -217,6 +216,7 @@ Map<String, dynamic> _$ToJsonTrueFromJsonFalsePrivateToJson( ToJsonTrueFromJsonFalsePrivate instance) => <String, dynamic>{ 'aField': instance.aField, + 'field': instance._field, 'zField': instance.zField, }; @@ -244,7 +244,6 @@ Map<String, dynamic> _$ToJsonFalseFromJsonTruePrivateToJson( ToJsonFalseFromJsonTruePrivate instance) => <String, dynamic>{ 'aField': instance.aField, - 'field': instance._field, 'zField': instance.zField, }; From 707e4a0ec653a9fccb11fb8a4eff1d35efb4766c Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Tue, 7 Feb 2023 16:00:40 -0800 Subject: [PATCH 474/569] Move to dart_flutter_team_lints with associated cleanup (#1282) --- _test_yaml/pubspec.yaml | 2 +- analysis_options.yaml | 20 ++------------------ checked_yaml/pubspec.yaml | 2 +- example/pubspec.yaml | 4 +++- json_annotation/pubspec.yaml | 2 +- json_serializable/pubspec.yaml | 2 +- shared_test/pubspec.yaml | 2 +- 7 files changed, 10 insertions(+), 24 deletions(-) diff --git a/_test_yaml/pubspec.yaml b/_test_yaml/pubspec.yaml index 5e7bd31d9..659b4593f 100644 --- a/_test_yaml/pubspec.yaml +++ b/_test_yaml/pubspec.yaml @@ -10,9 +10,9 @@ dev_dependencies: build_runner: ^2.0.0 build_verify: ^3.0.0 checked_yaml: any + dart_flutter_team_lints: ^0.1.0 json_annotation: ^4.7.0 json_serializable: any - lints: ^2.0.0 path: ^1.8.2 test: ^1.6.0 yaml: ^3.0.0 diff --git a/analysis_options.yaml b/analysis_options.yaml index 8a6ede19c..2fe41329a 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1,4 +1,5 @@ -include: package:lints/recommended.yaml +# See https://dart.dev/guides/language/analysis-options +include: package:dart_flutter_team_lints/analysis_options.yaml analyzer: language: @@ -6,9 +7,6 @@ analyzer: linter: rules: - - always_declare_return_types - - avoid_catching_errors - - avoid_dynamic_calls - avoid_private_typedef_functions - avoid_redundant_argument_values - avoid_returning_null @@ -20,38 +18,24 @@ linter: - combinators_ordering - comment_references - dangling_library_doc_comments - - directives_ordering - implicit_call_tearoffs - join_return_with_assignment - library_annotations - - lines_longer_than_80_chars - literal_only_boolean_expressions - missing_whitespace_between_adjacent_strings - no_runtimeType_toString - - omit_local_variable_types - - only_throw_errors - package_api_docs - - prefer_asserts_in_initializer_lists - prefer_const_constructors - prefer_const_declarations - prefer_expression_function_bodies - prefer_final_locals - prefer_relative_imports - - prefer_single_quotes - sort_child_properties_last - - sort_pub_dependencies - test_types_in_equals - - throw_in_finally - - type_annotate_public_apis - - unawaited_futures - - unnecessary_lambdas - unnecessary_library_directive - - unnecessary_parenthesis - - unnecessary_statements - unreachable_from_main - unsafe_html - use_full_hex_values_for_flutter_colors - - use_is_even_rather_than_modulo - use_string_buffers - use_string_in_part_of_directives - use_super_parameters diff --git a/checked_yaml/pubspec.yaml b/checked_yaml/pubspec.yaml index 945382541..b88a36fca 100644 --- a/checked_yaml/pubspec.yaml +++ b/checked_yaml/pubspec.yaml @@ -16,8 +16,8 @@ dependencies: dev_dependencies: build_runner: ^2.0.0 build_verify: ^3.0.0 + dart_flutter_team_lints: ^0.1.0 json_serializable: ^6.0.0 - lints: ^2.0.0 path: ^1.0.0 test: ^1.16.0 test_process: ^2.0.0 diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 4e4cb64f4..d97e1d81c 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -18,11 +18,13 @@ dev_dependencies: # Used by tests. Not required to use `json_serializable`. build_verify: ^3.0.0 + # Not required to use `json_serializable`. + dart_flutter_team_lints: ^0.1.0 + # REQUIRED! json_serializable: ^6.6.0 # Not required to use `json_serializable`. - lints: ^2.0.0 path: ^1.8.0 test: ^1.16.0 diff --git a/json_annotation/pubspec.yaml b/json_annotation/pubspec.yaml index 68397aea3..b3210155f 100644 --- a/json_annotation/pubspec.yaml +++ b/json_annotation/pubspec.yaml @@ -12,7 +12,7 @@ dependencies: meta: ^1.4.0 dev_dependencies: - lints: ^2.0.0 + dart_flutter_team_lints: ^0.1.0 # When changing JsonSerializable class. # build_runner: ^2.0.0 # json_serializable: any diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 678000181..eb6825e65 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -29,8 +29,8 @@ dev_dependencies: path: ../shared_test build_runner: ^2.0.0 build_verify: ^3.0.0 + dart_flutter_team_lints: ^0.1.0 dart_style: ^2.0.0 - lints: ^2.0.0 logging: ^1.0.0 source_gen_test: ^1.0.0 test: ^1.16.0 diff --git a/shared_test/pubspec.yaml b/shared_test/pubspec.yaml index 92d063bd3..896b4e049 100644 --- a/shared_test/pubspec.yaml +++ b/shared_test/pubspec.yaml @@ -8,4 +8,4 @@ dependencies: test: ^1.6.0 dev_dependencies: - lints: ^2.0.0 + dart_flutter_team_lints: ^0.1.0 From 38ca2bbe896c6017809ffebf01d98b150e942088 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Thu, 23 Feb 2023 16:34:21 -0800 Subject: [PATCH 475/569] blast_repo fixes (#1288) auto-publish --- .github/workflows/publish.yaml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 .github/workflows/publish.yaml diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml new file mode 100644 index 000000000..8c8f07d14 --- /dev/null +++ b/.github/workflows/publish.yaml @@ -0,0 +1,14 @@ +# A CI configuration to auto-publish pub packages. + +name: Publish + +on: + pull_request: + branches: [ master ] + push: + tags: [ '[A-z]+-v[0-9]+.[0-9]+.[0-9]+' ] + +jobs: + publish: + if: ${{ github.repository_owner == 'google' }} + uses: dart-lang/ecosystem/.github/workflows/publish.yaml@main From 5aa5a5fbc98abf56e28d137bb57a352f039253b2 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Thu, 23 Feb 2023 16:45:21 -0800 Subject: [PATCH 476/569] chore: use latest dart_flutter_team_lints, bump min SDK (#1289) --- .github/workflows/dart.yml | 60 +++++++++++++++++----------------- _test_yaml/pubspec.yaml | 4 +-- analysis_options.yaml | 8 ----- checked_yaml/CHANGELOG.md | 4 +++ checked_yaml/pubspec.yaml | 6 ++-- example/pubspec.yaml | 4 +-- json_annotation/CHANGELOG.md | 4 +++ json_annotation/pubspec.yaml | 6 ++-- json_serializable/CHANGELOG.md | 4 +++ json_serializable/pubspec.yaml | 6 ++-- shared_test/pubspec.yaml | 4 +-- 11 files changed, 57 insertions(+), 53 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 983df2316..f2967f5b3 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -40,23 +40,23 @@ jobs: - name: mono_repo self validate run: dart pub global run mono_repo generate --validate job_002: - name: "analyzer_and_format; Dart 2.18.0; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; `dart format --output=none --set-exit-if-changed .`, `dart analyze --fatal-infos .`" + name: "analyzer_and_format; Dart 2.19.0; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; `dart format --output=none --set-exit-if-changed .`, `dart analyze --fatal-infos .`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@627f0f41f6904a5b1efbaed9f96d9eb58e92e920 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.18.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:format-analyze" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:format-analyze" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:2.18.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable - os:ubuntu-latest;pub-cache-hosted;sdk:2.18.0 + os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable + os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 with: - sdk: "2.18.0" + sdk: "2.19.0" - id: checkout name: Checkout repository uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c @@ -212,23 +212,23 @@ jobs: if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" working-directory: json_serializable job_004: - name: "unit_test; Dart 2.18.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; `dart test`" + name: "unit_test; Dart 2.19.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; `dart test`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@627f0f41f6904a5b1efbaed9f96d9eb58e92e920 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.18.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:2.18.0;packages:_test_yaml-checked_yaml-example-json_serializable - os:ubuntu-latest;pub-cache-hosted;sdk:2.18.0 + os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0;packages:_test_yaml-checked_yaml-example-json_serializable + os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 with: - sdk: "2.18.0" + sdk: "2.19.0" - id: checkout name: Checkout repository uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c @@ -273,23 +273,23 @@ jobs: - job_002 - job_003 job_005: - name: "unit_test; Dart 2.18.0; PKG: json_serializable; `dart test --run-skipped -t presubmit-only test/annotation_version_test.dart`" + name: "unit_test; Dart 2.19.0; PKG: json_serializable; `dart test --run-skipped -t presubmit-only test/annotation_version_test.dart`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@627f0f41f6904a5b1efbaed9f96d9eb58e92e920 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.18.0;packages:json_serializable;commands:test_3" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0;packages:json_serializable;commands:test_3" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:2.18.0;packages:json_serializable - os:ubuntu-latest;pub-cache-hosted;sdk:2.18.0 + os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0;packages:json_serializable + os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 with: - sdk: "2.18.0" + sdk: "2.19.0" - id: checkout name: Checkout repository uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c @@ -307,23 +307,23 @@ jobs: - job_002 - job_003 job_006: - name: "unit_test; Dart 2.18.0; PKG: json_serializable; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" + name: "unit_test; Dart 2.19.0; PKG: json_serializable; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@627f0f41f6904a5b1efbaed9f96d9eb58e92e920 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.18.0;packages:json_serializable;commands:test_1" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0;packages:json_serializable;commands:test_1" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:2.18.0;packages:json_serializable - os:ubuntu-latest;pub-cache-hosted;sdk:2.18.0 + os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0;packages:json_serializable + os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 with: - sdk: "2.18.0" + sdk: "2.19.0" - id: checkout name: Checkout repository uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c @@ -341,23 +341,23 @@ jobs: - job_002 - job_003 job_007: - name: "unit_test; Dart 2.18.0; PKG: json_serializable; `dart test -p chrome`" + name: "unit_test; Dart 2.19.0; PKG: json_serializable; `dart test -p chrome`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@627f0f41f6904a5b1efbaed9f96d9eb58e92e920 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.18.0;packages:json_serializable;commands:test_2" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0;packages:json_serializable;commands:test_2" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:2.18.0;packages:json_serializable - os:ubuntu-latest;pub-cache-hosted;sdk:2.18.0 + os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0;packages:json_serializable + os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 with: - sdk: "2.18.0" + sdk: "2.19.0" - id: checkout name: Checkout repository uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c @@ -538,23 +538,23 @@ jobs: - job_002 - job_003 job_012: - name: "ensure_build; Dart 2.18.0; PKGS: _test_yaml, checked_yaml, example; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" + name: "ensure_build; Dart 2.19.0; PKGS: _test_yaml, checked_yaml, example; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@627f0f41f6904a5b1efbaed9f96d9eb58e92e920 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.18.0;packages:_test_yaml-checked_yaml-example;commands:test_1" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0;packages:_test_yaml-checked_yaml-example;commands:test_1" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:2.18.0;packages:_test_yaml-checked_yaml-example - os:ubuntu-latest;pub-cache-hosted;sdk:2.18.0 + os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0;packages:_test_yaml-checked_yaml-example + os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 with: - sdk: "2.18.0" + sdk: "2.19.0" - id: checkout name: Checkout repository uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c diff --git a/_test_yaml/pubspec.yaml b/_test_yaml/pubspec.yaml index 659b4593f..a35dbeef2 100644 --- a/_test_yaml/pubspec.yaml +++ b/_test_yaml/pubspec.yaml @@ -2,7 +2,7 @@ name: _test_yaml publish_to: none environment: - sdk: '>=2.18.0 <3.0.0' + sdk: '>=2.19.0 <3.0.0' dev_dependencies: _json_serial_shared_test: @@ -10,7 +10,7 @@ dev_dependencies: build_runner: ^2.0.0 build_verify: ^3.0.0 checked_yaml: any - dart_flutter_team_lints: ^0.1.0 + dart_flutter_team_lints: ^1.0.0 json_annotation: ^4.7.0 json_serializable: any path: ^1.8.2 diff --git a/analysis_options.yaml b/analysis_options.yaml index 2fe41329a..124d1e711 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -14,13 +14,8 @@ linter: - avoid_void_async - cancel_subscriptions - cascade_invocations - - collection_methods_unrelated_type - - combinators_ordering - comment_references - - dangling_library_doc_comments - - implicit_call_tearoffs - join_return_with_assignment - - library_annotations - literal_only_boolean_expressions - missing_whitespace_between_adjacent_strings - no_runtimeType_toString @@ -32,10 +27,7 @@ linter: - prefer_relative_imports - sort_child_properties_last - test_types_in_equals - - unnecessary_library_directive - - unreachable_from_main - unsafe_html - use_full_hex_values_for_flutter_colors - use_string_buffers - - use_string_in_part_of_directives - use_super_parameters diff --git a/checked_yaml/CHANGELOG.md b/checked_yaml/CHANGELOG.md index 1b5ac8736..3d8404566 100644 --- a/checked_yaml/CHANGELOG.md +++ b/checked_yaml/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.0.3-dev + +- Require Dart 2.19 + ## 2.0.2 - Require `json_annotation` `^4.3.0` diff --git a/checked_yaml/pubspec.yaml b/checked_yaml/pubspec.yaml index b88a36fca..c93abad14 100644 --- a/checked_yaml/pubspec.yaml +++ b/checked_yaml/pubspec.yaml @@ -1,12 +1,12 @@ name: checked_yaml -version: 2.0.2 +version: 2.0.3-dev description: >- Generate more helpful exceptions when decoding YAML documents using package:json_serializable and package:yaml. repository: https://github.com/google/json_serializable.dart/tree/master/checked_yaml environment: - sdk: '>=2.18.0 <3.0.0' + sdk: '>=2.19.0 <3.0.0' dependencies: json_annotation: ^4.3.0 @@ -16,7 +16,7 @@ dependencies: dev_dependencies: build_runner: ^2.0.0 build_verify: ^3.0.0 - dart_flutter_team_lints: ^0.1.0 + dart_flutter_team_lints: ^1.0.0 json_serializable: ^6.0.0 path: ^1.0.0 test: ^1.16.0 diff --git a/example/pubspec.yaml b/example/pubspec.yaml index d97e1d81c..069facd40 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -2,7 +2,7 @@ name: example publish_to: none environment: - sdk: '>=2.18.0 <3.0.0' + sdk: '>=2.19.0 <3.0.0' dependencies: json_annotation: ^4.8.0 @@ -19,7 +19,7 @@ dev_dependencies: build_verify: ^3.0.0 # Not required to use `json_serializable`. - dart_flutter_team_lints: ^0.1.0 + dart_flutter_team_lints: ^1.0.0 # REQUIRED! json_serializable: ^6.6.0 diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index d784ddeed..5a23b4817 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -1,3 +1,7 @@ +## 4.8.1-dev + +- Require Dart 2.19 + ## 4.8.0 - DEPRECATED `JsonKey.ignore`. Replaced by... diff --git a/json_annotation/pubspec.yaml b/json_annotation/pubspec.yaml index b3210155f..fc43ca68d 100644 --- a/json_annotation/pubspec.yaml +++ b/json_annotation/pubspec.yaml @@ -1,18 +1,18 @@ name: json_annotation -version: 4.8.0 +version: 4.8.1-dev description: >- Classes and helper functions that support JSON code generation via the `json_serializable` package. repository: https://github.com/google/json_serializable.dart/tree/master/json_annotation environment: - sdk: '>=2.18.0 <3.0.0' + sdk: '>=2.19.0 <3.0.0' dependencies: meta: ^1.4.0 dev_dependencies: - dart_flutter_team_lints: ^0.1.0 + dart_flutter_team_lints: ^1.0.0 # When changing JsonSerializable class. # build_runner: ^2.0.0 # json_serializable: any diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index d4e683d06..2e90f4ace 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,7 @@ +## 6.6.2-dev + +- Require Dart 2.19 + ## 6.6.1 - Fix bug when `JsonKey.includeToJson` is `false`. diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index eb6825e65..f3a4d3ac1 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,11 +1,11 @@ name: json_serializable -version: 6.6.1 +version: 6.6.2-dev description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. repository: https://github.com/google/json_serializable.dart/tree/master/json_serializable environment: - sdk: '>=2.18.0 <3.0.0' + sdk: '>=2.19.0 <3.0.0' dependencies: analyzer: ^5.2.0 @@ -29,7 +29,7 @@ dev_dependencies: path: ../shared_test build_runner: ^2.0.0 build_verify: ^3.0.0 - dart_flutter_team_lints: ^0.1.0 + dart_flutter_team_lints: ^1.0.0 dart_style: ^2.0.0 logging: ^1.0.0 source_gen_test: ^1.0.0 diff --git a/shared_test/pubspec.yaml b/shared_test/pubspec.yaml index 896b4e049..ab560ef00 100644 --- a/shared_test/pubspec.yaml +++ b/shared_test/pubspec.yaml @@ -1,11 +1,11 @@ name: _json_serial_shared_test publish_to: none environment: - sdk: '>=2.18.0 <3.0.0' + sdk: '>=2.19.0 <3.0.0' dependencies: stack_trace: ^1.10.0 test: ^1.6.0 dev_dependencies: - dart_flutter_team_lints: ^0.1.0 + dart_flutter_team_lints: ^1.0.0 From ff9d1387dd489e0c031ae9de1889d355d19a7eb2 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Wed, 1 Mar 2023 11:59:25 -0800 Subject: [PATCH 477/569] Latest cache actions (#1292) Closes https://github.com/google/json_serializable.dart/pull/1291 --- .github/workflows/dart.yml | 30 +++++++++++++++--------------- tool/ci.sh | 2 +- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index f2967f5b3..51d859fd9 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -1,4 +1,4 @@ -# Created with package:mono_repo v6.5.0 +# Created with package:mono_repo v6.5.1 name: Dart CI on: push: @@ -21,7 +21,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@627f0f41f6904a5b1efbaed9f96d9eb58e92e920 + uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:stable" @@ -36,7 +36,7 @@ jobs: name: Checkout repository uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c - name: mono_repo self validate - run: dart pub global activate mono_repo 6.5.0 + run: dart pub global activate mono_repo 6.5.1 - name: mono_repo self validate run: dart pub global run mono_repo generate --validate job_002: @@ -44,7 +44,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@627f0f41f6904a5b1efbaed9f96d9eb58e92e920 + uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:format-analyze" @@ -130,7 +130,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@627f0f41f6904a5b1efbaed9f96d9eb58e92e920 + uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:format-analyze" @@ -216,7 +216,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@627f0f41f6904a5b1efbaed9f96d9eb58e92e920 + uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" @@ -277,7 +277,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@627f0f41f6904a5b1efbaed9f96d9eb58e92e920 + uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0;packages:json_serializable;commands:test_3" @@ -311,7 +311,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@627f0f41f6904a5b1efbaed9f96d9eb58e92e920 + uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0;packages:json_serializable;commands:test_1" @@ -345,7 +345,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@627f0f41f6904a5b1efbaed9f96d9eb58e92e920 + uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0;packages:json_serializable;commands:test_2" @@ -379,7 +379,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@627f0f41f6904a5b1efbaed9f96d9eb58e92e920 + uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" @@ -440,7 +440,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@627f0f41f6904a5b1efbaed9f96d9eb58e92e920 + uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:json_serializable;commands:test_3" @@ -474,7 +474,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@627f0f41f6904a5b1efbaed9f96d9eb58e92e920 + uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:json_serializable;commands:test_1" @@ -508,7 +508,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@627f0f41f6904a5b1efbaed9f96d9eb58e92e920 + uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:json_serializable;commands:test_2" @@ -542,7 +542,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@627f0f41f6904a5b1efbaed9f96d9eb58e92e920 + uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0;packages:_test_yaml-checked_yaml-example;commands:test_1" @@ -602,7 +602,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@627f0f41f6904a5b1efbaed9f96d9eb58e92e920 + uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:_test_yaml-checked_yaml-example;commands:test_1" diff --git a/tool/ci.sh b/tool/ci.sh index d0d8faa8f..d7fc35f6e 100755 --- a/tool/ci.sh +++ b/tool/ci.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Created with package:mono_repo v6.5.0 +# Created with package:mono_repo v6.5.1 # Support built in commands on windows out of the box. # When it is a flutter repo (check the pubspec.yaml for "sdk: flutter") From 393cb43cffa9fcde784a7bc264595b39c1b144e2 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Sun, 12 Mar 2023 20:19:14 -0700 Subject: [PATCH 478/569] Fix formatting with the latest SDK (#1295) --- .github/workflows/dart.yml | 81 +++++++++++++------- json_annotation/lib/src/checked_helpers.dart | 3 +- json_annotation/mono_pkg.yaml | 8 +- tool/ci.sh | 6 +- 4 files changed, 64 insertions(+), 34 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 51d859fd9..554641623 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -40,16 +40,16 @@ jobs: - name: mono_repo self validate run: dart pub global run mono_repo generate --validate job_002: - name: "analyzer_and_format; Dart 2.19.0; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; `dart format --output=none --set-exit-if-changed .`, `dart analyze --fatal-infos .`" + name: "analyzer_and_format; Dart 2.19.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; `dart format --output=none --set-exit-if-changed .`, `dart analyze --fatal-infos .`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:format-analyze" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:format-analyze_0" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable + os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0;packages:_test_yaml-checked_yaml-example-json_serializable os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest @@ -99,19 +99,6 @@ jobs: run: dart analyze --fatal-infos . if: "always() && steps.example_pub_upgrade.conclusion == 'success'" working-directory: example - - id: json_annotation_pub_upgrade - name: json_annotation; dart pub upgrade - run: dart pub upgrade - if: "always() && steps.checkout.conclusion == 'success'" - working-directory: json_annotation - - name: "json_annotation; dart format --output=none --set-exit-if-changed ." - run: "dart format --output=none --set-exit-if-changed ." - if: "always() && steps.json_annotation_pub_upgrade.conclusion == 'success'" - working-directory: json_annotation - - name: "json_annotation; dart analyze --fatal-infos ." - run: dart analyze --fatal-infos . - if: "always() && steps.json_annotation_pub_upgrade.conclusion == 'success'" - working-directory: json_annotation - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -126,6 +113,36 @@ jobs: if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" working-directory: json_serializable job_003: + name: "analyzer_and_format; Dart 2.19.0; PKG: json_annotation; `dart analyze`" + runs-on: ubuntu-latest + steps: + - name: Cache Pub hosted dependencies + uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 + with: + path: "~/.pub-cache/hosted" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0;packages:json_annotation;commands:analyze_1" + restore-keys: | + os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0;packages:json_annotation + os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0 + os:ubuntu-latest;pub-cache-hosted + os:ubuntu-latest + - name: Setup Dart SDK + uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 + with: + sdk: "2.19.0" + - id: checkout + name: Checkout repository + uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c + - id: json_annotation_pub_upgrade + name: json_annotation; dart pub upgrade + run: dart pub upgrade + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: json_annotation + - name: json_annotation; dart analyze + run: dart analyze + if: "always() && steps.json_annotation_pub_upgrade.conclusion == 'success'" + working-directory: json_annotation + job_004: name: "analyzer_and_format; Dart dev; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; `dart format --output=none --set-exit-if-changed .`, `dart analyze --fatal-infos .`" runs-on: ubuntu-latest steps: @@ -133,7 +150,7 @@ jobs: uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:format-analyze" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:format-analyze_0" restore-keys: | os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable os:ubuntu-latest;pub-cache-hosted;sdk:dev @@ -211,7 +228,7 @@ jobs: run: dart analyze --fatal-infos . if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" working-directory: json_serializable - job_004: + job_005: name: "unit_test; Dart 2.19.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; `dart test`" runs-on: ubuntu-latest steps: @@ -272,7 +289,8 @@ jobs: - job_001 - job_002 - job_003 - job_005: + - job_004 + job_006: name: "unit_test; Dart 2.19.0; PKG: json_serializable; `dart test --run-skipped -t presubmit-only test/annotation_version_test.dart`" runs-on: ubuntu-latest steps: @@ -306,7 +324,8 @@ jobs: - job_001 - job_002 - job_003 - job_006: + - job_004 + job_007: name: "unit_test; Dart 2.19.0; PKG: json_serializable; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest steps: @@ -340,7 +359,8 @@ jobs: - job_001 - job_002 - job_003 - job_007: + - job_004 + job_008: name: "unit_test; Dart 2.19.0; PKG: json_serializable; `dart test -p chrome`" runs-on: ubuntu-latest steps: @@ -374,7 +394,8 @@ jobs: - job_001 - job_002 - job_003 - job_008: + - job_004 + job_009: name: "unit_test; Dart dev; PKGS: _test_yaml, checked_yaml, example, json_serializable; `dart test`" runs-on: ubuntu-latest steps: @@ -435,7 +456,8 @@ jobs: - job_001 - job_002 - job_003 - job_009: + - job_004 + job_010: name: "unit_test; Dart dev; PKG: json_serializable; `dart test --run-skipped -t presubmit-only test/annotation_version_test.dart`" runs-on: ubuntu-latest steps: @@ -469,7 +491,8 @@ jobs: - job_001 - job_002 - job_003 - job_010: + - job_004 + job_011: name: "unit_test; Dart dev; PKG: json_serializable; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest steps: @@ -503,7 +526,8 @@ jobs: - job_001 - job_002 - job_003 - job_011: + - job_004 + job_012: name: "unit_test; Dart dev; PKG: json_serializable; `dart test -p chrome`" runs-on: ubuntu-latest steps: @@ -537,7 +561,8 @@ jobs: - job_001 - job_002 - job_003 - job_012: + - job_004 + job_013: name: "ensure_build; Dart 2.19.0; PKGS: _test_yaml, checked_yaml, example; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest steps: @@ -597,7 +622,8 @@ jobs: - job_009 - job_010 - job_011 - job_013: + - job_012 + job_014: name: "ensure_build; Dart dev; PKGS: _test_yaml, checked_yaml, example; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest steps: @@ -657,3 +683,4 @@ jobs: - job_009 - job_010 - job_011 + - job_012 diff --git a/json_annotation/lib/src/checked_helpers.dart b/json_annotation/lib/src/checked_helpers.dart index e3da209b2..04c54d871 100644 --- a/json_annotation/lib/src/checked_helpers.dart +++ b/json_annotation/lib/src/checked_helpers.dart @@ -17,8 +17,7 @@ T $checkedCreate<T>( S Function(Object?), { Object? Function(Map, String)? readValue, }), - ) - constructor, { + ) constructor, { Map<String, String> fieldKeyMap = const {}, }) { Q checkedConvert<Q>( diff --git a/json_annotation/mono_pkg.yaml b/json_annotation/mono_pkg.yaml index 971262031..305682a97 100644 --- a/json_annotation/mono_pkg.yaml +++ b/json_annotation/mono_pkg.yaml @@ -1,10 +1,10 @@ # See https://github.com/google/mono_repo.dart for details on this file -sdk: -- pubspec -- dev - stages: - analyzer_and_format: - group: - format - analyze: --fatal-infos . + sdk: dev + - group: + - analyze + sdk: pubspec diff --git a/tool/ci.sh b/tool/ci.sh index d7fc35f6e..cc6cd1a81 100755 --- a/tool/ci.sh +++ b/tool/ci.sh @@ -67,10 +67,14 @@ for PKG in ${PKGS}; do echo echo -e "\033[1mPKG: ${PKG}; TASK: ${TASK}\033[22m" case ${TASK} in - analyze) + analyze_0) echo 'dart analyze --fatal-infos .' dart analyze --fatal-infos . || EXIT_CODE=$? ;; + analyze_1) + echo 'dart analyze' + dart analyze || EXIT_CODE=$? + ;; format) echo 'dart format --output=none --set-exit-if-changed .' dart format --output=none --set-exit-if-changed . || EXIT_CODE=$? From 06e14e95269b2c75ddb0edcf7200dc0b36acf79c Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Mon, 13 Mar 2023 11:08:22 -0700 Subject: [PATCH 479/569] Update no-response.yml - once a day --- .github/workflows/no-response.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/no-response.yml b/.github/workflows/no-response.yml index 23b3a75ef..599c7c209 100644 --- a/.github/workflows/no-response.yml +++ b/.github/workflows/no-response.yml @@ -8,8 +8,8 @@ on: issue_comment: types: [created] schedule: - # Schedule for five minutes after the hour, every hour - - cron: '5 * * * *' + # Every day at 8am + - cron: '0 8 * * *' # All permissions not specified are set to 'none'. permissions: From 2798034820c5f30c1537933eb6ad7a2e6550cf8e Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Wed, 22 Mar 2023 02:16:30 -0700 Subject: [PATCH 480/569] latest mono_repo and actions (#1296) --- .github/workflows/dart.yml | 88 +++++++++++++++++++------------------- tool/ci.sh | 2 +- 2 files changed, 45 insertions(+), 45 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 554641623..0e1a4bd8c 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -1,4 +1,4 @@ -# Created with package:mono_repo v6.5.1 +# Created with package:mono_repo v6.5.2 name: Dart CI on: push: @@ -21,7 +21,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 + uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:stable" @@ -29,14 +29,14 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 + uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f with: sdk: stable - id: checkout name: Checkout repository - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c + uses: actions/checkout@24cb9080177205b6e8c946b17badbe402adc938f - name: mono_repo self validate - run: dart pub global activate mono_repo 6.5.1 + run: dart pub global activate mono_repo 6.5.2 - name: mono_repo self validate run: dart pub global run mono_repo generate --validate job_002: @@ -44,7 +44,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 + uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:format-analyze_0" @@ -54,12 +54,12 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 + uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f with: sdk: "2.19.0" - id: checkout name: Checkout repository - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c + uses: actions/checkout@24cb9080177205b6e8c946b17badbe402adc938f - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -117,7 +117,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 + uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0;packages:json_annotation;commands:analyze_1" @@ -127,12 +127,12 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 + uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f with: sdk: "2.19.0" - id: checkout name: Checkout repository - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c + uses: actions/checkout@24cb9080177205b6e8c946b17badbe402adc938f - id: json_annotation_pub_upgrade name: json_annotation; dart pub upgrade run: dart pub upgrade @@ -147,7 +147,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 + uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:format-analyze_0" @@ -157,12 +157,12 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 + uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f with: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c + uses: actions/checkout@24cb9080177205b6e8c946b17badbe402adc938f - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -233,7 +233,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 + uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" @@ -243,12 +243,12 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 + uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f with: sdk: "2.19.0" - id: checkout name: Checkout repository - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c + uses: actions/checkout@24cb9080177205b6e8c946b17badbe402adc938f - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -295,7 +295,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 + uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0;packages:json_serializable;commands:test_3" @@ -305,12 +305,12 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 + uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f with: sdk: "2.19.0" - id: checkout name: Checkout repository - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c + uses: actions/checkout@24cb9080177205b6e8c946b17badbe402adc938f - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -330,7 +330,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 + uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0;packages:json_serializable;commands:test_1" @@ -340,12 +340,12 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 + uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f with: sdk: "2.19.0" - id: checkout name: Checkout repository - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c + uses: actions/checkout@24cb9080177205b6e8c946b17badbe402adc938f - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -365,7 +365,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 + uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0;packages:json_serializable;commands:test_2" @@ -375,12 +375,12 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 + uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f with: sdk: "2.19.0" - id: checkout name: Checkout repository - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c + uses: actions/checkout@24cb9080177205b6e8c946b17badbe402adc938f - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -400,7 +400,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 + uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" @@ -410,12 +410,12 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 + uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f with: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c + uses: actions/checkout@24cb9080177205b6e8c946b17badbe402adc938f - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -462,7 +462,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 + uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:json_serializable;commands:test_3" @@ -472,12 +472,12 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 + uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f with: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c + uses: actions/checkout@24cb9080177205b6e8c946b17badbe402adc938f - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -497,7 +497,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 + uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:json_serializable;commands:test_1" @@ -507,12 +507,12 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 + uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f with: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c + uses: actions/checkout@24cb9080177205b6e8c946b17badbe402adc938f - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -532,7 +532,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 + uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:json_serializable;commands:test_2" @@ -542,12 +542,12 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 + uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f with: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c + uses: actions/checkout@24cb9080177205b6e8c946b17badbe402adc938f - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -567,7 +567,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 + uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0;packages:_test_yaml-checked_yaml-example;commands:test_1" @@ -577,12 +577,12 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 + uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f with: sdk: "2.19.0" - id: checkout name: Checkout repository - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c + uses: actions/checkout@24cb9080177205b6e8c946b17badbe402adc938f - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -628,7 +628,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 + uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:_test_yaml-checked_yaml-example;commands:test_1" @@ -638,12 +638,12 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 + uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f with: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c + uses: actions/checkout@24cb9080177205b6e8c946b17badbe402adc938f - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade diff --git a/tool/ci.sh b/tool/ci.sh index cc6cd1a81..0d1a0f690 100755 --- a/tool/ci.sh +++ b/tool/ci.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Created with package:mono_repo v6.5.1 +# Created with package:mono_repo v6.5.2 # Support built in commands on windows out of the box. # When it is a flutter repo (check the pubspec.yaml for "sdk: flutter") From b2ea4bfe55941f566075d5dd84b01e12505afb0d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 2 Apr 2023 11:41:09 -0700 Subject: [PATCH 481/569] Bump actions/checkout from 3.4.0 to 3.5.0 (#1301) Bumps [actions/checkout](https://github.com/actions/checkout) from 3.4.0 to 3.5.0. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v3.4.0...8f4b7f84864484a7bf31766abe9204da3cbe65b3) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> --- .github/workflows/dart.yml | 32 +++++++++++++-------------- .github/workflows/markdown_linter.yml | 4 ++-- tool/ci.sh | 2 +- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 0e1a4bd8c..c8f0e1760 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -1,4 +1,4 @@ -# Created with package:mono_repo v6.5.2 +# Created with package:mono_repo v6.5.3 name: Dart CI on: push: @@ -34,9 +34,9 @@ jobs: sdk: stable - id: checkout name: Checkout repository - uses: actions/checkout@24cb9080177205b6e8c946b17badbe402adc938f + uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 - name: mono_repo self validate - run: dart pub global activate mono_repo 6.5.2 + run: dart pub global activate mono_repo 6.5.3 - name: mono_repo self validate run: dart pub global run mono_repo generate --validate job_002: @@ -59,7 +59,7 @@ jobs: sdk: "2.19.0" - id: checkout name: Checkout repository - uses: actions/checkout@24cb9080177205b6e8c946b17badbe402adc938f + uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -132,7 +132,7 @@ jobs: sdk: "2.19.0" - id: checkout name: Checkout repository - uses: actions/checkout@24cb9080177205b6e8c946b17badbe402adc938f + uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 - id: json_annotation_pub_upgrade name: json_annotation; dart pub upgrade run: dart pub upgrade @@ -162,7 +162,7 @@ jobs: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@24cb9080177205b6e8c946b17badbe402adc938f + uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -248,7 +248,7 @@ jobs: sdk: "2.19.0" - id: checkout name: Checkout repository - uses: actions/checkout@24cb9080177205b6e8c946b17badbe402adc938f + uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -310,7 +310,7 @@ jobs: sdk: "2.19.0" - id: checkout name: Checkout repository - uses: actions/checkout@24cb9080177205b6e8c946b17badbe402adc938f + uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -345,7 +345,7 @@ jobs: sdk: "2.19.0" - id: checkout name: Checkout repository - uses: actions/checkout@24cb9080177205b6e8c946b17badbe402adc938f + uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -380,7 +380,7 @@ jobs: sdk: "2.19.0" - id: checkout name: Checkout repository - uses: actions/checkout@24cb9080177205b6e8c946b17badbe402adc938f + uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -415,7 +415,7 @@ jobs: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@24cb9080177205b6e8c946b17badbe402adc938f + uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -477,7 +477,7 @@ jobs: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@24cb9080177205b6e8c946b17badbe402adc938f + uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -512,7 +512,7 @@ jobs: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@24cb9080177205b6e8c946b17badbe402adc938f + uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -547,7 +547,7 @@ jobs: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@24cb9080177205b6e8c946b17badbe402adc938f + uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -582,7 +582,7 @@ jobs: sdk: "2.19.0" - id: checkout name: Checkout repository - uses: actions/checkout@24cb9080177205b6e8c946b17badbe402adc938f + uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -643,7 +643,7 @@ jobs: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@24cb9080177205b6e8c946b17badbe402adc938f + uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade diff --git a/.github/workflows/markdown_linter.yml b/.github/workflows/markdown_linter.yml index ea9a0099b..ce7162673 100644 --- a/.github/workflows/markdown_linter.yml +++ b/.github/workflows/markdown_linter.yml @@ -11,7 +11,7 @@ jobs: markdown-link-check: runs-on: ubuntu-latest steps: - - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 + - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 - uses: gaurav-nelson/github-action-markdown-link-check@v1 markdown_lint: runs-on: ubuntu-latest @@ -19,7 +19,7 @@ jobs: matrix: node-version: [ 14.x ] steps: - - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 + - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c with: diff --git a/tool/ci.sh b/tool/ci.sh index 0d1a0f690..18e741b2c 100755 --- a/tool/ci.sh +++ b/tool/ci.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Created with package:mono_repo v6.5.2 +# Created with package:mono_repo v6.5.3 # Support built in commands on windows out of the box. # When it is a flutter repo (check the pubspec.yaml for "sdk: flutter") From 190f8b1ea1fdd87943ba230f1deddcc31393a348 Mon Sep 17 00:00:00 2001 From: Alex Bukin <bukin.alexey.a@gmail.com> Date: Tue, 18 Apr 2023 05:02:18 +0400 Subject: [PATCH 482/569] typo fix (#1305) typo fix --- json_annotation/lib/src/json_serializable.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/json_annotation/lib/src/json_serializable.dart b/json_annotation/lib/src/json_serializable.dart index 41fa0c136..71a6e4550 100644 --- a/json_annotation/lib/src/json_serializable.dart +++ b/json_annotation/lib/src/json_serializable.dart @@ -88,7 +88,7 @@ class JsonSerializable { final bool? createFieldMap; /// If `true` (defaults to false), a private, static `_$ExamplePerFieldToJson` - /// abstract class will be geenrated in the part file. + /// abstract class will be generated in the part file. /// /// This abstract class will contain one static function per property, /// exposing a way to encode only this property instead of the entire object. From 5422fd47d0aec9fc7e9f0adbaa0ac368b067cde2 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Wed, 26 Apr 2023 15:26:54 -0700 Subject: [PATCH 483/569] Correctly handle Object?/dynamic as to/from json param type (#1307) --- json_serializable/CHANGELOG.md | 1 + .../lib/src/default_container.dart | 4 +- json_serializable/lib/src/lambda_result.dart | 38 +- .../lib/src/shared_checkers.dart | 29 - .../lib/src/type_helpers/convert_helper.dart | 8 +- .../type_helpers/json_converter_helper.dart | 5 +- .../lib/src/type_helpers/json_helper.dart | 12 +- .../test/supported_types/enum_type.dart | 33 + .../supported_types/input.type_iterable.dart | 96 +++ .../input.type_iterable.g.dart | 80 ++ .../test/supported_types/input.type_list.dart | 96 +++ .../supported_types/input.type_list.g.dart | 88 ++ .../test/supported_types/input.type_map.dart | 770 ++++++++++++++++++ .../supported_types/input.type_map.g.dart | 760 +++++++++++++++++ .../test/supported_types/input.type_set.dart | 96 +++ .../supported_types/input.type_set.g.dart | 88 ++ json_serializable/tool/test_type_builder.dart | 3 + 17 files changed, 2162 insertions(+), 45 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 2e90f4ace..1814d3154 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,5 +1,6 @@ ## 6.6.2-dev +- Better handling of `Object?` or `dynamic` as `fromJson` constructor param. - Require Dart 2.19 ## 6.6.1 diff --git a/json_serializable/lib/src/default_container.dart b/json_serializable/lib/src/default_container.dart index 752aa2bb5..ee2087947 100644 --- a/json_serializable/lib/src/default_container.dart +++ b/json_serializable/lib/src/default_container.dart @@ -9,7 +9,7 @@ import 'utils.dart'; /// a default value available to replace it if `null`. class DefaultContainer { final String expression; - final String output; + final Object output; DefaultContainer(this.expression, this.output); @@ -23,7 +23,7 @@ class DefaultContainer { return ifNullOrElse( value.expression, defaultValue ?? 'null', - value.output, + value.output.toString(), ); } value = value.output; diff --git a/json_serializable/lib/src/lambda_result.dart b/json_serializable/lib/src/lambda_result.dart index 05f07d7f3..0531cc20f 100644 --- a/json_serializable/lib/src/lambda_result.dart +++ b/json_serializable/lib/src/lambda_result.dart @@ -2,7 +2,12 @@ // 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:analyzer/dart/element/type.dart'; +import 'package:source_helper/source_helper.dart'; + import 'constants.dart' show closureArg; +import 'shared_checkers.dart'; +import 'utils.dart'; /// Represents a lambda that can be used as a tear-off depending on the context /// in which it is used. @@ -13,9 +18,11 @@ import 'constants.dart' show closureArg; class LambdaResult { final String expression; final String lambda; - final String? asContent; + final DartType? asContent; + + String get _asContent => asContent == null ? '' : _asStatement(asContent!); - String get _fullExpression => '$expression${asContent ?? ''}'; + String get _fullExpression => '$expression$_asContent'; LambdaResult(this.expression, this.lambda, {this.asContent}); @@ -27,3 +34,30 @@ class LambdaResult { ? subField.lambda : '($closureArg) => $subField'; } + +String _asStatement(DartType type) { + if (type.isLikeDynamic) { + return ''; + } + + final nullableSuffix = type.isNullableType ? '?' : ''; + + if (coreIterableTypeChecker.isAssignableFromType(type)) { + final itemType = coreIterableGenericType(type); + if (itemType.isLikeDynamic) { + return ' as List$nullableSuffix'; + } + } + + if (coreMapTypeChecker.isAssignableFromType(type)) { + final args = type.typeArgumentsOf(coreMapTypeChecker)!; + assert(args.length == 2); + + if (args.every((e) => e.isLikeDynamic)) { + return ' as Map$nullableSuffix'; + } + } + + final typeCode = typeToCode(type); + return ' as $typeCode'; +} diff --git a/json_serializable/lib/src/shared_checkers.dart b/json_serializable/lib/src/shared_checkers.dart index a8e0abcc6..d2da8dbe8 100644 --- a/json_serializable/lib/src/shared_checkers.dart +++ b/json_serializable/lib/src/shared_checkers.dart @@ -6,8 +6,6 @@ import 'package:analyzer/dart/element/type.dart'; import 'package:source_gen/source_gen.dart' show TypeChecker; import 'package:source_helper/source_helper.dart'; -import 'utils.dart'; - /// A [TypeChecker] for [Iterable]. const coreIterableTypeChecker = TypeChecker.fromUrl('dart:core#Iterable'); @@ -27,30 +25,3 @@ const simpleJsonTypeChecker = TypeChecker.any([ TypeChecker.fromUrl('dart:core#bool'), TypeChecker.fromUrl('dart:core#num') ]); - -String asStatement(DartType type) { - if (type.isLikeDynamic) { - return ''; - } - - final nullableSuffix = type.isNullableType ? '?' : ''; - - if (coreIterableTypeChecker.isAssignableFromType(type)) { - final itemType = coreIterableGenericType(type); - if (itemType.isLikeDynamic) { - return ' as List$nullableSuffix'; - } - } - - if (coreMapTypeChecker.isAssignableFromType(type)) { - final args = type.typeArgumentsOf(coreMapTypeChecker)!; - assert(args.length == 2); - - if (args.every((e) => e.isLikeDynamic)) { - return ' as Map$nullableSuffix'; - } - } - - final typeCode = typeToCode(type); - return ' as $typeCode'; -} diff --git a/json_serializable/lib/src/type_helpers/convert_helper.dart b/json_serializable/lib/src/type_helpers/convert_helper.dart index 1918fd42a..6657a9e60 100644 --- a/json_serializable/lib/src/type_helpers/convert_helper.dart +++ b/json_serializable/lib/src/type_helpers/convert_helper.dart @@ -6,7 +6,6 @@ import 'package:analyzer/dart/element/type.dart'; import 'package:source_helper/source_helper.dart'; import '../lambda_result.dart'; -import '../shared_checkers.dart'; import '../type_helper.dart'; /// Information used by [ConvertHelper] when handling `JsonKey`-annotated @@ -57,7 +56,10 @@ class ConvertHelper extends TypeHelper<TypeHelperContextWithConvert> { return null; } - final asContent = asStatement(fromJsonData.paramType); - return LambdaResult(expression, fromJsonData.name, asContent: asContent); + return LambdaResult( + expression, + fromJsonData.name, + asContent: fromJsonData.paramType, + ); } } diff --git a/json_serializable/lib/src/type_helpers/json_converter_helper.dart b/json_serializable/lib/src/type_helpers/json_converter_helper.dart index 65b06a12f..ce78f19d1 100644 --- a/json_serializable/lib/src/type_helpers/json_converter_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_converter_helper.dart @@ -11,7 +11,6 @@ import 'package:source_gen/source_gen.dart'; import 'package:source_helper/source_helper.dart'; import '../lambda_result.dart'; -import '../shared_checkers.dart'; import '../type_helper.dart'; import '../utils.dart'; @@ -65,8 +64,6 @@ Json? $converterToJsonName<Json, Value>( return null; } - final asContent = asStatement(converter.jsonType); - if (!converter.jsonType.isNullableType && targetType.isNullableType) { const converterFromJsonName = r'_$JsonConverterFromJson'; context.addMember(''' @@ -88,7 +85,7 @@ Value? $converterFromJsonName<Json, Value>( return LambdaResult( expression, '${converter.accessString}.fromJson', - asContent: asContent, + asContent: converter.jsonType, ); } } diff --git a/json_serializable/lib/src/type_helpers/json_helper.dart b/json_serializable/lib/src/type_helpers/json_helper.dart index a5d8acd13..79430e42d 100644 --- a/json_serializable/lib/src/type_helpers/json_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_helper.dart @@ -3,7 +3,6 @@ // BSD-style license that can be found in the LICENSE file. import 'package:analyzer/dart/element/element.dart'; -import 'package:analyzer/dart/element/nullability_suffix.dart'; import 'package:analyzer/dart/element/type.dart'; import 'package:collection/collection.dart'; import 'package:json_annotation/json_annotation.dart'; @@ -11,6 +10,7 @@ import 'package:source_gen/source_gen.dart'; import 'package:source_helper/source_helper.dart'; import '../default_container.dart'; +import '../lambda_result.dart'; import '../type_helper.dart'; import '../utils.dart'; import 'config_types.dart'; @@ -130,9 +130,12 @@ class JsonHelper extends TypeHelper<TypeHelperContextWithConfig> { // TODO: the type could be imported from a library with a prefix! // https://github.com/google/json_serializable.dart/issues/19 - output = '${typeToCode(targetType.promoteNonNullable())}.fromJson($output)'; + final lambda = LambdaResult( + output, + '${typeToCode(targetType.promoteNonNullable())}.fromJson', + ); - return DefaultContainer(expression, output); + return DefaultContainer(expression, lambda); } } @@ -263,8 +266,7 @@ InterfaceType? _instantiate( return ctorParamType.element.instantiate( typeArguments: argTypes.cast<DartType>(), - // TODO: not 100% sure nullabilitySuffix is right... Works for now - nullabilitySuffix: NullabilitySuffix.none, + nullabilitySuffix: ctorParamType.nullabilitySuffix, ); } diff --git a/json_serializable/test/supported_types/enum_type.dart b/json_serializable/test/supported_types/enum_type.dart index 360a6bf8e..6e31deaf2 100644 --- a/json_serializable/test/supported_types/enum_type.dart +++ b/json_serializable/test/supported_types/enum_type.dart @@ -3,3 +3,36 @@ // BSD-style license that can be found in the LICENSE file. enum EnumType { alpha, beta, gamma, delta } + +class FromJsonDynamicParam { + FromJsonDynamicParam({required this.value}); + + final int value; + + factory FromJsonDynamicParam.fromJson(dynamic json) => + FromJsonDynamicParam(value: json as int); + + dynamic toJson() => null; +} + +class FromJsonNullableObjectParam { + FromJsonNullableObjectParam({required this.value}); + + final int value; + + factory FromJsonNullableObjectParam.fromJson(Object? json) => + FromJsonNullableObjectParam(value: json as int); + + Object? toJson() => null; +} + +class FromJsonObjectParam { + FromJsonObjectParam({required this.value}); + + final int value; + + factory FromJsonObjectParam.fromJson(Object json) => + FromJsonObjectParam(value: json as int); + + dynamic toJson() => null; +} diff --git a/json_serializable/test/supported_types/input.type_iterable.dart b/json_serializable/test/supported_types/input.type_iterable.dart index 1471dc935..79c080a7b 100644 --- a/json_serializable/test/supported_types/input.type_iterable.dart +++ b/json_serializable/test/supported_types/input.type_iterable.dart @@ -419,6 +419,102 @@ class SimpleClassNullableOfEnumTypeNullable { _$SimpleClassNullableOfEnumTypeNullableToJson(this); } +@JsonSerializable() +class SimpleClassOfFromJsonDynamicParam { + final Iterable<FromJsonDynamicParam> value; + + SimpleClassOfFromJsonDynamicParam( + this.value, + ); + + factory SimpleClassOfFromJsonDynamicParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassOfFromJsonDynamicParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassOfFromJsonDynamicParamToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfFromJsonDynamicParam { + final Iterable<FromJsonDynamicParam>? value; + + SimpleClassNullableOfFromJsonDynamicParam( + this.value, + ); + + factory SimpleClassNullableOfFromJsonDynamicParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassNullableOfFromJsonDynamicParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassNullableOfFromJsonDynamicParamToJson(this); +} + +@JsonSerializable() +class SimpleClassOfFromJsonNullableObjectParam { + final Iterable<FromJsonNullableObjectParam> value; + + SimpleClassOfFromJsonNullableObjectParam( + this.value, + ); + + factory SimpleClassOfFromJsonNullableObjectParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassOfFromJsonNullableObjectParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassOfFromJsonNullableObjectParamToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfFromJsonNullableObjectParam { + final Iterable<FromJsonNullableObjectParam>? value; + + SimpleClassNullableOfFromJsonNullableObjectParam( + this.value, + ); + + factory SimpleClassNullableOfFromJsonNullableObjectParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassNullableOfFromJsonNullableObjectParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassNullableOfFromJsonNullableObjectParamToJson(this); +} + +@JsonSerializable() +class SimpleClassOfFromJsonObjectParam { + final Iterable<FromJsonObjectParam> value; + + SimpleClassOfFromJsonObjectParam( + this.value, + ); + + factory SimpleClassOfFromJsonObjectParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassOfFromJsonObjectParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassOfFromJsonObjectParamToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfFromJsonObjectParam { + final Iterable<FromJsonObjectParam>? value; + + SimpleClassNullableOfFromJsonObjectParam( + this.value, + ); + + factory SimpleClassNullableOfFromJsonObjectParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassNullableOfFromJsonObjectParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassNullableOfFromJsonObjectParamToJson(this); +} + @JsonSerializable() class SimpleClassOfInt { final Iterable<int> value; diff --git a/json_serializable/test/supported_types/input.type_iterable.g.dart b/json_serializable/test/supported_types/input.type_iterable.g.dart index 1433484ec..9222c22d2 100644 --- a/json_serializable/test/supported_types/input.type_iterable.g.dart +++ b/json_serializable/test/supported_types/input.type_iterable.g.dart @@ -364,6 +364,86 @@ Map<String, dynamic> _$SimpleClassNullableOfEnumTypeNullableToJson( 'value': instance.value?.map((e) => _$EnumTypeEnumMap[e]).toList(), }; +SimpleClassOfFromJsonDynamicParam _$SimpleClassOfFromJsonDynamicParamFromJson( + Map<String, dynamic> json) => + SimpleClassOfFromJsonDynamicParam( + (json['value'] as List<dynamic>).map(FromJsonDynamicParam.fromJson), + ); + +Map<String, dynamic> _$SimpleClassOfFromJsonDynamicParamToJson( + SimpleClassOfFromJsonDynamicParam instance) => + <String, dynamic>{ + 'value': instance.value.toList(), + }; + +SimpleClassNullableOfFromJsonDynamicParam + _$SimpleClassNullableOfFromJsonDynamicParamFromJson( + Map<String, dynamic> json) => + SimpleClassNullableOfFromJsonDynamicParam( + (json['value'] as List<dynamic>?)?.map(FromJsonDynamicParam.fromJson), + ); + +Map<String, dynamic> _$SimpleClassNullableOfFromJsonDynamicParamToJson( + SimpleClassNullableOfFromJsonDynamicParam instance) => + <String, dynamic>{ + 'value': instance.value?.toList(), + }; + +SimpleClassOfFromJsonNullableObjectParam + _$SimpleClassOfFromJsonNullableObjectParamFromJson( + Map<String, dynamic> json) => + SimpleClassOfFromJsonNullableObjectParam( + (json['value'] as List<dynamic>) + .map(FromJsonNullableObjectParam.fromJson), + ); + +Map<String, dynamic> _$SimpleClassOfFromJsonNullableObjectParamToJson( + SimpleClassOfFromJsonNullableObjectParam instance) => + <String, dynamic>{ + 'value': instance.value.toList(), + }; + +SimpleClassNullableOfFromJsonNullableObjectParam + _$SimpleClassNullableOfFromJsonNullableObjectParamFromJson( + Map<String, dynamic> json) => + SimpleClassNullableOfFromJsonNullableObjectParam( + (json['value'] as List<dynamic>?) + ?.map(FromJsonNullableObjectParam.fromJson), + ); + +Map<String, dynamic> _$SimpleClassNullableOfFromJsonNullableObjectParamToJson( + SimpleClassNullableOfFromJsonNullableObjectParam instance) => + <String, dynamic>{ + 'value': instance.value?.toList(), + }; + +SimpleClassOfFromJsonObjectParam _$SimpleClassOfFromJsonObjectParamFromJson( + Map<String, dynamic> json) => + SimpleClassOfFromJsonObjectParam( + (json['value'] as List<dynamic>) + .map((e) => FromJsonObjectParam.fromJson(e as Object)), + ); + +Map<String, dynamic> _$SimpleClassOfFromJsonObjectParamToJson( + SimpleClassOfFromJsonObjectParam instance) => + <String, dynamic>{ + 'value': instance.value.toList(), + }; + +SimpleClassNullableOfFromJsonObjectParam + _$SimpleClassNullableOfFromJsonObjectParamFromJson( + Map<String, dynamic> json) => + SimpleClassNullableOfFromJsonObjectParam( + (json['value'] as List<dynamic>?) + ?.map((e) => FromJsonObjectParam.fromJson(e as Object)), + ); + +Map<String, dynamic> _$SimpleClassNullableOfFromJsonObjectParamToJson( + SimpleClassNullableOfFromJsonObjectParam instance) => + <String, dynamic>{ + 'value': instance.value?.toList(), + }; + SimpleClassOfInt _$SimpleClassOfIntFromJson(Map<String, dynamic> json) => SimpleClassOfInt( (json['value'] as List<dynamic>).map((e) => e as int), diff --git a/json_serializable/test/supported_types/input.type_list.dart b/json_serializable/test/supported_types/input.type_list.dart index 41f35fe72..12119ec40 100644 --- a/json_serializable/test/supported_types/input.type_list.dart +++ b/json_serializable/test/supported_types/input.type_list.dart @@ -419,6 +419,102 @@ class SimpleClassNullableOfEnumTypeNullable { _$SimpleClassNullableOfEnumTypeNullableToJson(this); } +@JsonSerializable() +class SimpleClassOfFromJsonDynamicParam { + final List<FromJsonDynamicParam> value; + + SimpleClassOfFromJsonDynamicParam( + this.value, + ); + + factory SimpleClassOfFromJsonDynamicParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassOfFromJsonDynamicParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassOfFromJsonDynamicParamToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfFromJsonDynamicParam { + final List<FromJsonDynamicParam>? value; + + SimpleClassNullableOfFromJsonDynamicParam( + this.value, + ); + + factory SimpleClassNullableOfFromJsonDynamicParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassNullableOfFromJsonDynamicParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassNullableOfFromJsonDynamicParamToJson(this); +} + +@JsonSerializable() +class SimpleClassOfFromJsonNullableObjectParam { + final List<FromJsonNullableObjectParam> value; + + SimpleClassOfFromJsonNullableObjectParam( + this.value, + ); + + factory SimpleClassOfFromJsonNullableObjectParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassOfFromJsonNullableObjectParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassOfFromJsonNullableObjectParamToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfFromJsonNullableObjectParam { + final List<FromJsonNullableObjectParam>? value; + + SimpleClassNullableOfFromJsonNullableObjectParam( + this.value, + ); + + factory SimpleClassNullableOfFromJsonNullableObjectParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassNullableOfFromJsonNullableObjectParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassNullableOfFromJsonNullableObjectParamToJson(this); +} + +@JsonSerializable() +class SimpleClassOfFromJsonObjectParam { + final List<FromJsonObjectParam> value; + + SimpleClassOfFromJsonObjectParam( + this.value, + ); + + factory SimpleClassOfFromJsonObjectParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassOfFromJsonObjectParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassOfFromJsonObjectParamToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfFromJsonObjectParam { + final List<FromJsonObjectParam>? value; + + SimpleClassNullableOfFromJsonObjectParam( + this.value, + ); + + factory SimpleClassNullableOfFromJsonObjectParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassNullableOfFromJsonObjectParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassNullableOfFromJsonObjectParamToJson(this); +} + @JsonSerializable() class SimpleClassOfInt { final List<int> value; diff --git a/json_serializable/test/supported_types/input.type_list.g.dart b/json_serializable/test/supported_types/input.type_list.g.dart index 9c6a1fe88..11d7dd234 100644 --- a/json_serializable/test/supported_types/input.type_list.g.dart +++ b/json_serializable/test/supported_types/input.type_list.g.dart @@ -390,6 +390,94 @@ Map<String, dynamic> _$SimpleClassNullableOfEnumTypeNullableToJson( 'value': instance.value?.map((e) => _$EnumTypeEnumMap[e]).toList(), }; +SimpleClassOfFromJsonDynamicParam _$SimpleClassOfFromJsonDynamicParamFromJson( + Map<String, dynamic> json) => + SimpleClassOfFromJsonDynamicParam( + (json['value'] as List<dynamic>) + .map(FromJsonDynamicParam.fromJson) + .toList(), + ); + +Map<String, dynamic> _$SimpleClassOfFromJsonDynamicParamToJson( + SimpleClassOfFromJsonDynamicParam instance) => + <String, dynamic>{ + 'value': instance.value, + }; + +SimpleClassNullableOfFromJsonDynamicParam + _$SimpleClassNullableOfFromJsonDynamicParamFromJson( + Map<String, dynamic> json) => + SimpleClassNullableOfFromJsonDynamicParam( + (json['value'] as List<dynamic>?) + ?.map(FromJsonDynamicParam.fromJson) + .toList(), + ); + +Map<String, dynamic> _$SimpleClassNullableOfFromJsonDynamicParamToJson( + SimpleClassNullableOfFromJsonDynamicParam instance) => + <String, dynamic>{ + 'value': instance.value, + }; + +SimpleClassOfFromJsonNullableObjectParam + _$SimpleClassOfFromJsonNullableObjectParamFromJson( + Map<String, dynamic> json) => + SimpleClassOfFromJsonNullableObjectParam( + (json['value'] as List<dynamic>) + .map(FromJsonNullableObjectParam.fromJson) + .toList(), + ); + +Map<String, dynamic> _$SimpleClassOfFromJsonNullableObjectParamToJson( + SimpleClassOfFromJsonNullableObjectParam instance) => + <String, dynamic>{ + 'value': instance.value, + }; + +SimpleClassNullableOfFromJsonNullableObjectParam + _$SimpleClassNullableOfFromJsonNullableObjectParamFromJson( + Map<String, dynamic> json) => + SimpleClassNullableOfFromJsonNullableObjectParam( + (json['value'] as List<dynamic>?) + ?.map(FromJsonNullableObjectParam.fromJson) + .toList(), + ); + +Map<String, dynamic> _$SimpleClassNullableOfFromJsonNullableObjectParamToJson( + SimpleClassNullableOfFromJsonNullableObjectParam instance) => + <String, dynamic>{ + 'value': instance.value, + }; + +SimpleClassOfFromJsonObjectParam _$SimpleClassOfFromJsonObjectParamFromJson( + Map<String, dynamic> json) => + SimpleClassOfFromJsonObjectParam( + (json['value'] as List<dynamic>) + .map((e) => FromJsonObjectParam.fromJson(e as Object)) + .toList(), + ); + +Map<String, dynamic> _$SimpleClassOfFromJsonObjectParamToJson( + SimpleClassOfFromJsonObjectParam instance) => + <String, dynamic>{ + 'value': instance.value, + }; + +SimpleClassNullableOfFromJsonObjectParam + _$SimpleClassNullableOfFromJsonObjectParamFromJson( + Map<String, dynamic> json) => + SimpleClassNullableOfFromJsonObjectParam( + (json['value'] as List<dynamic>?) + ?.map((e) => FromJsonObjectParam.fromJson(e as Object)) + .toList(), + ); + +Map<String, dynamic> _$SimpleClassNullableOfFromJsonObjectParamToJson( + SimpleClassNullableOfFromJsonObjectParam instance) => + <String, dynamic>{ + 'value': instance.value, + }; + SimpleClassOfInt _$SimpleClassOfIntFromJson(Map<String, dynamic> json) => SimpleClassOfInt( (json['value'] as List<dynamic>).map((e) => e as int).toList(), diff --git a/json_serializable/test/supported_types/input.type_map.dart b/json_serializable/test/supported_types/input.type_map.dart index bdf45e336..ab87400eb 100644 --- a/json_serializable/test/supported_types/input.type_map.dart +++ b/json_serializable/test/supported_types/input.type_map.dart @@ -3257,6 +3257,776 @@ class SimpleClassNullableOfUriToEnumTypeNullable { _$SimpleClassNullableOfUriToEnumTypeNullableToJson(this); } +@JsonSerializable() +class SimpleClassOfBigIntToFromJsonDynamicParam { + final Map<BigInt, FromJsonDynamicParam> value; + + SimpleClassOfBigIntToFromJsonDynamicParam( + this.value, + ); + + factory SimpleClassOfBigIntToFromJsonDynamicParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassOfBigIntToFromJsonDynamicParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassOfBigIntToFromJsonDynamicParamToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfBigIntToFromJsonDynamicParam { + final Map<BigInt, FromJsonDynamicParam>? value; + + SimpleClassNullableOfBigIntToFromJsonDynamicParam( + this.value, + ); + + factory SimpleClassNullableOfBigIntToFromJsonDynamicParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassNullableOfBigIntToFromJsonDynamicParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassNullableOfBigIntToFromJsonDynamicParamToJson(this); +} + +@JsonSerializable() +class SimpleClassOfDateTimeToFromJsonDynamicParam { + final Map<DateTime, FromJsonDynamicParam> value; + + SimpleClassOfDateTimeToFromJsonDynamicParam( + this.value, + ); + + factory SimpleClassOfDateTimeToFromJsonDynamicParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassOfDateTimeToFromJsonDynamicParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassOfDateTimeToFromJsonDynamicParamToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfDateTimeToFromJsonDynamicParam { + final Map<DateTime, FromJsonDynamicParam>? value; + + SimpleClassNullableOfDateTimeToFromJsonDynamicParam( + this.value, + ); + + factory SimpleClassNullableOfDateTimeToFromJsonDynamicParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassNullableOfDateTimeToFromJsonDynamicParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassNullableOfDateTimeToFromJsonDynamicParamToJson(this); +} + +@JsonSerializable() +class SimpleClassOfDynamicToFromJsonDynamicParam { + final Map<dynamic, FromJsonDynamicParam> value; + + SimpleClassOfDynamicToFromJsonDynamicParam( + this.value, + ); + + factory SimpleClassOfDynamicToFromJsonDynamicParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassOfDynamicToFromJsonDynamicParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassOfDynamicToFromJsonDynamicParamToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfDynamicToFromJsonDynamicParam { + final Map<dynamic, FromJsonDynamicParam>? value; + + SimpleClassNullableOfDynamicToFromJsonDynamicParam( + this.value, + ); + + factory SimpleClassNullableOfDynamicToFromJsonDynamicParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassNullableOfDynamicToFromJsonDynamicParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassNullableOfDynamicToFromJsonDynamicParamToJson(this); +} + +@JsonSerializable() +class SimpleClassOfEnumTypeToFromJsonDynamicParam { + final Map<EnumType, FromJsonDynamicParam> value; + + SimpleClassOfEnumTypeToFromJsonDynamicParam( + this.value, + ); + + factory SimpleClassOfEnumTypeToFromJsonDynamicParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassOfEnumTypeToFromJsonDynamicParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassOfEnumTypeToFromJsonDynamicParamToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfEnumTypeToFromJsonDynamicParam { + final Map<EnumType, FromJsonDynamicParam>? value; + + SimpleClassNullableOfEnumTypeToFromJsonDynamicParam( + this.value, + ); + + factory SimpleClassNullableOfEnumTypeToFromJsonDynamicParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassNullableOfEnumTypeToFromJsonDynamicParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassNullableOfEnumTypeToFromJsonDynamicParamToJson(this); +} + +@JsonSerializable() +class SimpleClassOfIntToFromJsonDynamicParam { + final Map<int, FromJsonDynamicParam> value; + + SimpleClassOfIntToFromJsonDynamicParam( + this.value, + ); + + factory SimpleClassOfIntToFromJsonDynamicParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassOfIntToFromJsonDynamicParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassOfIntToFromJsonDynamicParamToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfIntToFromJsonDynamicParam { + final Map<int, FromJsonDynamicParam>? value; + + SimpleClassNullableOfIntToFromJsonDynamicParam( + this.value, + ); + + factory SimpleClassNullableOfIntToFromJsonDynamicParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassNullableOfIntToFromJsonDynamicParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassNullableOfIntToFromJsonDynamicParamToJson(this); +} + +@JsonSerializable() +class SimpleClassOfObjectToFromJsonDynamicParam { + final Map<Object, FromJsonDynamicParam> value; + + SimpleClassOfObjectToFromJsonDynamicParam( + this.value, + ); + + factory SimpleClassOfObjectToFromJsonDynamicParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassOfObjectToFromJsonDynamicParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassOfObjectToFromJsonDynamicParamToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfObjectToFromJsonDynamicParam { + final Map<Object, FromJsonDynamicParam>? value; + + SimpleClassNullableOfObjectToFromJsonDynamicParam( + this.value, + ); + + factory SimpleClassNullableOfObjectToFromJsonDynamicParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassNullableOfObjectToFromJsonDynamicParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassNullableOfObjectToFromJsonDynamicParamToJson(this); +} + +@JsonSerializable() +class SimpleClassOfStringToFromJsonDynamicParam { + final Map<String, FromJsonDynamicParam> value; + + SimpleClassOfStringToFromJsonDynamicParam( + this.value, + ); + + factory SimpleClassOfStringToFromJsonDynamicParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassOfStringToFromJsonDynamicParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassOfStringToFromJsonDynamicParamToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfStringToFromJsonDynamicParam { + final Map<String, FromJsonDynamicParam>? value; + + SimpleClassNullableOfStringToFromJsonDynamicParam( + this.value, + ); + + factory SimpleClassNullableOfStringToFromJsonDynamicParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassNullableOfStringToFromJsonDynamicParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassNullableOfStringToFromJsonDynamicParamToJson(this); +} + +@JsonSerializable() +class SimpleClassOfUriToFromJsonDynamicParam { + final Map<Uri, FromJsonDynamicParam> value; + + SimpleClassOfUriToFromJsonDynamicParam( + this.value, + ); + + factory SimpleClassOfUriToFromJsonDynamicParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassOfUriToFromJsonDynamicParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassOfUriToFromJsonDynamicParamToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfUriToFromJsonDynamicParam { + final Map<Uri, FromJsonDynamicParam>? value; + + SimpleClassNullableOfUriToFromJsonDynamicParam( + this.value, + ); + + factory SimpleClassNullableOfUriToFromJsonDynamicParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassNullableOfUriToFromJsonDynamicParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassNullableOfUriToFromJsonDynamicParamToJson(this); +} + +@JsonSerializable() +class SimpleClassOfBigIntToFromJsonNullableObjectParam { + final Map<BigInt, FromJsonNullableObjectParam> value; + + SimpleClassOfBigIntToFromJsonNullableObjectParam( + this.value, + ); + + factory SimpleClassOfBigIntToFromJsonNullableObjectParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassOfBigIntToFromJsonNullableObjectParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassOfBigIntToFromJsonNullableObjectParamToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfBigIntToFromJsonNullableObjectParam { + final Map<BigInt, FromJsonNullableObjectParam>? value; + + SimpleClassNullableOfBigIntToFromJsonNullableObjectParam( + this.value, + ); + + factory SimpleClassNullableOfBigIntToFromJsonNullableObjectParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassNullableOfBigIntToFromJsonNullableObjectParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassNullableOfBigIntToFromJsonNullableObjectParamToJson(this); +} + +@JsonSerializable() +class SimpleClassOfDateTimeToFromJsonNullableObjectParam { + final Map<DateTime, FromJsonNullableObjectParam> value; + + SimpleClassOfDateTimeToFromJsonNullableObjectParam( + this.value, + ); + + factory SimpleClassOfDateTimeToFromJsonNullableObjectParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassOfDateTimeToFromJsonNullableObjectParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassOfDateTimeToFromJsonNullableObjectParamToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfDateTimeToFromJsonNullableObjectParam { + final Map<DateTime, FromJsonNullableObjectParam>? value; + + SimpleClassNullableOfDateTimeToFromJsonNullableObjectParam( + this.value, + ); + + factory SimpleClassNullableOfDateTimeToFromJsonNullableObjectParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassNullableOfDateTimeToFromJsonNullableObjectParamFromJson( + json); + + Map<String, Object?> toJson() => + _$SimpleClassNullableOfDateTimeToFromJsonNullableObjectParamToJson(this); +} + +@JsonSerializable() +class SimpleClassOfDynamicToFromJsonNullableObjectParam { + final Map<dynamic, FromJsonNullableObjectParam> value; + + SimpleClassOfDynamicToFromJsonNullableObjectParam( + this.value, + ); + + factory SimpleClassOfDynamicToFromJsonNullableObjectParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassOfDynamicToFromJsonNullableObjectParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassOfDynamicToFromJsonNullableObjectParamToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfDynamicToFromJsonNullableObjectParam { + final Map<dynamic, FromJsonNullableObjectParam>? value; + + SimpleClassNullableOfDynamicToFromJsonNullableObjectParam( + this.value, + ); + + factory SimpleClassNullableOfDynamicToFromJsonNullableObjectParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassNullableOfDynamicToFromJsonNullableObjectParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassNullableOfDynamicToFromJsonNullableObjectParamToJson(this); +} + +@JsonSerializable() +class SimpleClassOfEnumTypeToFromJsonNullableObjectParam { + final Map<EnumType, FromJsonNullableObjectParam> value; + + SimpleClassOfEnumTypeToFromJsonNullableObjectParam( + this.value, + ); + + factory SimpleClassOfEnumTypeToFromJsonNullableObjectParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassOfEnumTypeToFromJsonNullableObjectParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassOfEnumTypeToFromJsonNullableObjectParamToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfEnumTypeToFromJsonNullableObjectParam { + final Map<EnumType, FromJsonNullableObjectParam>? value; + + SimpleClassNullableOfEnumTypeToFromJsonNullableObjectParam( + this.value, + ); + + factory SimpleClassNullableOfEnumTypeToFromJsonNullableObjectParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassNullableOfEnumTypeToFromJsonNullableObjectParamFromJson( + json); + + Map<String, Object?> toJson() => + _$SimpleClassNullableOfEnumTypeToFromJsonNullableObjectParamToJson(this); +} + +@JsonSerializable() +class SimpleClassOfIntToFromJsonNullableObjectParam { + final Map<int, FromJsonNullableObjectParam> value; + + SimpleClassOfIntToFromJsonNullableObjectParam( + this.value, + ); + + factory SimpleClassOfIntToFromJsonNullableObjectParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassOfIntToFromJsonNullableObjectParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassOfIntToFromJsonNullableObjectParamToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfIntToFromJsonNullableObjectParam { + final Map<int, FromJsonNullableObjectParam>? value; + + SimpleClassNullableOfIntToFromJsonNullableObjectParam( + this.value, + ); + + factory SimpleClassNullableOfIntToFromJsonNullableObjectParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassNullableOfIntToFromJsonNullableObjectParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassNullableOfIntToFromJsonNullableObjectParamToJson(this); +} + +@JsonSerializable() +class SimpleClassOfObjectToFromJsonNullableObjectParam { + final Map<Object, FromJsonNullableObjectParam> value; + + SimpleClassOfObjectToFromJsonNullableObjectParam( + this.value, + ); + + factory SimpleClassOfObjectToFromJsonNullableObjectParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassOfObjectToFromJsonNullableObjectParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassOfObjectToFromJsonNullableObjectParamToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfObjectToFromJsonNullableObjectParam { + final Map<Object, FromJsonNullableObjectParam>? value; + + SimpleClassNullableOfObjectToFromJsonNullableObjectParam( + this.value, + ); + + factory SimpleClassNullableOfObjectToFromJsonNullableObjectParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassNullableOfObjectToFromJsonNullableObjectParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassNullableOfObjectToFromJsonNullableObjectParamToJson(this); +} + +@JsonSerializable() +class SimpleClassOfStringToFromJsonNullableObjectParam { + final Map<String, FromJsonNullableObjectParam> value; + + SimpleClassOfStringToFromJsonNullableObjectParam( + this.value, + ); + + factory SimpleClassOfStringToFromJsonNullableObjectParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassOfStringToFromJsonNullableObjectParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassOfStringToFromJsonNullableObjectParamToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfStringToFromJsonNullableObjectParam { + final Map<String, FromJsonNullableObjectParam>? value; + + SimpleClassNullableOfStringToFromJsonNullableObjectParam( + this.value, + ); + + factory SimpleClassNullableOfStringToFromJsonNullableObjectParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassNullableOfStringToFromJsonNullableObjectParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassNullableOfStringToFromJsonNullableObjectParamToJson(this); +} + +@JsonSerializable() +class SimpleClassOfUriToFromJsonNullableObjectParam { + final Map<Uri, FromJsonNullableObjectParam> value; + + SimpleClassOfUriToFromJsonNullableObjectParam( + this.value, + ); + + factory SimpleClassOfUriToFromJsonNullableObjectParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassOfUriToFromJsonNullableObjectParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassOfUriToFromJsonNullableObjectParamToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfUriToFromJsonNullableObjectParam { + final Map<Uri, FromJsonNullableObjectParam>? value; + + SimpleClassNullableOfUriToFromJsonNullableObjectParam( + this.value, + ); + + factory SimpleClassNullableOfUriToFromJsonNullableObjectParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassNullableOfUriToFromJsonNullableObjectParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassNullableOfUriToFromJsonNullableObjectParamToJson(this); +} + +@JsonSerializable() +class SimpleClassOfBigIntToFromJsonObjectParam { + final Map<BigInt, FromJsonObjectParam> value; + + SimpleClassOfBigIntToFromJsonObjectParam( + this.value, + ); + + factory SimpleClassOfBigIntToFromJsonObjectParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassOfBigIntToFromJsonObjectParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassOfBigIntToFromJsonObjectParamToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfBigIntToFromJsonObjectParam { + final Map<BigInt, FromJsonObjectParam>? value; + + SimpleClassNullableOfBigIntToFromJsonObjectParam( + this.value, + ); + + factory SimpleClassNullableOfBigIntToFromJsonObjectParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassNullableOfBigIntToFromJsonObjectParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassNullableOfBigIntToFromJsonObjectParamToJson(this); +} + +@JsonSerializable() +class SimpleClassOfDateTimeToFromJsonObjectParam { + final Map<DateTime, FromJsonObjectParam> value; + + SimpleClassOfDateTimeToFromJsonObjectParam( + this.value, + ); + + factory SimpleClassOfDateTimeToFromJsonObjectParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassOfDateTimeToFromJsonObjectParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassOfDateTimeToFromJsonObjectParamToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfDateTimeToFromJsonObjectParam { + final Map<DateTime, FromJsonObjectParam>? value; + + SimpleClassNullableOfDateTimeToFromJsonObjectParam( + this.value, + ); + + factory SimpleClassNullableOfDateTimeToFromJsonObjectParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassNullableOfDateTimeToFromJsonObjectParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassNullableOfDateTimeToFromJsonObjectParamToJson(this); +} + +@JsonSerializable() +class SimpleClassOfDynamicToFromJsonObjectParam { + final Map<dynamic, FromJsonObjectParam> value; + + SimpleClassOfDynamicToFromJsonObjectParam( + this.value, + ); + + factory SimpleClassOfDynamicToFromJsonObjectParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassOfDynamicToFromJsonObjectParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassOfDynamicToFromJsonObjectParamToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfDynamicToFromJsonObjectParam { + final Map<dynamic, FromJsonObjectParam>? value; + + SimpleClassNullableOfDynamicToFromJsonObjectParam( + this.value, + ); + + factory SimpleClassNullableOfDynamicToFromJsonObjectParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassNullableOfDynamicToFromJsonObjectParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassNullableOfDynamicToFromJsonObjectParamToJson(this); +} + +@JsonSerializable() +class SimpleClassOfEnumTypeToFromJsonObjectParam { + final Map<EnumType, FromJsonObjectParam> value; + + SimpleClassOfEnumTypeToFromJsonObjectParam( + this.value, + ); + + factory SimpleClassOfEnumTypeToFromJsonObjectParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassOfEnumTypeToFromJsonObjectParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassOfEnumTypeToFromJsonObjectParamToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfEnumTypeToFromJsonObjectParam { + final Map<EnumType, FromJsonObjectParam>? value; + + SimpleClassNullableOfEnumTypeToFromJsonObjectParam( + this.value, + ); + + factory SimpleClassNullableOfEnumTypeToFromJsonObjectParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassNullableOfEnumTypeToFromJsonObjectParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassNullableOfEnumTypeToFromJsonObjectParamToJson(this); +} + +@JsonSerializable() +class SimpleClassOfIntToFromJsonObjectParam { + final Map<int, FromJsonObjectParam> value; + + SimpleClassOfIntToFromJsonObjectParam( + this.value, + ); + + factory SimpleClassOfIntToFromJsonObjectParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassOfIntToFromJsonObjectParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassOfIntToFromJsonObjectParamToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfIntToFromJsonObjectParam { + final Map<int, FromJsonObjectParam>? value; + + SimpleClassNullableOfIntToFromJsonObjectParam( + this.value, + ); + + factory SimpleClassNullableOfIntToFromJsonObjectParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassNullableOfIntToFromJsonObjectParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassNullableOfIntToFromJsonObjectParamToJson(this); +} + +@JsonSerializable() +class SimpleClassOfObjectToFromJsonObjectParam { + final Map<Object, FromJsonObjectParam> value; + + SimpleClassOfObjectToFromJsonObjectParam( + this.value, + ); + + factory SimpleClassOfObjectToFromJsonObjectParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassOfObjectToFromJsonObjectParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassOfObjectToFromJsonObjectParamToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfObjectToFromJsonObjectParam { + final Map<Object, FromJsonObjectParam>? value; + + SimpleClassNullableOfObjectToFromJsonObjectParam( + this.value, + ); + + factory SimpleClassNullableOfObjectToFromJsonObjectParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassNullableOfObjectToFromJsonObjectParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassNullableOfObjectToFromJsonObjectParamToJson(this); +} + +@JsonSerializable() +class SimpleClassOfStringToFromJsonObjectParam { + final Map<String, FromJsonObjectParam> value; + + SimpleClassOfStringToFromJsonObjectParam( + this.value, + ); + + factory SimpleClassOfStringToFromJsonObjectParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassOfStringToFromJsonObjectParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassOfStringToFromJsonObjectParamToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfStringToFromJsonObjectParam { + final Map<String, FromJsonObjectParam>? value; + + SimpleClassNullableOfStringToFromJsonObjectParam( + this.value, + ); + + factory SimpleClassNullableOfStringToFromJsonObjectParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassNullableOfStringToFromJsonObjectParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassNullableOfStringToFromJsonObjectParamToJson(this); +} + +@JsonSerializable() +class SimpleClassOfUriToFromJsonObjectParam { + final Map<Uri, FromJsonObjectParam> value; + + SimpleClassOfUriToFromJsonObjectParam( + this.value, + ); + + factory SimpleClassOfUriToFromJsonObjectParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassOfUriToFromJsonObjectParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassOfUriToFromJsonObjectParamToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfUriToFromJsonObjectParam { + final Map<Uri, FromJsonObjectParam>? value; + + SimpleClassNullableOfUriToFromJsonObjectParam( + this.value, + ); + + factory SimpleClassNullableOfUriToFromJsonObjectParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassNullableOfUriToFromJsonObjectParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassNullableOfUriToFromJsonObjectParamToJson(this); +} + @JsonSerializable() class SimpleClassOfBigIntToInt { final Map<BigInt, int> value; diff --git a/json_serializable/test/supported_types/input.type_map.g.dart b/json_serializable/test/supported_types/input.type_map.g.dart index 82b579e23..dbda9199a 100644 --- a/json_serializable/test/supported_types/input.type_map.g.dart +++ b/json_serializable/test/supported_types/input.type_map.g.dart @@ -3179,6 +3179,766 @@ Map<String, dynamic> _$SimpleClassNullableOfUriToEnumTypeNullableToJson( ?.map((k, e) => MapEntry(k.toString(), _$EnumTypeEnumMap[e])), }; +SimpleClassOfBigIntToFromJsonDynamicParam + _$SimpleClassOfBigIntToFromJsonDynamicParamFromJson( + Map<String, dynamic> json) => + SimpleClassOfBigIntToFromJsonDynamicParam( + (json['value'] as Map<String, dynamic>).map( + (k, e) => + MapEntry(BigInt.parse(k), FromJsonDynamicParam.fromJson(e)), + ), + ); + +Map<String, dynamic> _$SimpleClassOfBigIntToFromJsonDynamicParamToJson( + SimpleClassOfBigIntToFromJsonDynamicParam instance) => + <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassNullableOfBigIntToFromJsonDynamicParam + _$SimpleClassNullableOfBigIntToFromJsonDynamicParamFromJson( + Map<String, dynamic> json) => + SimpleClassNullableOfBigIntToFromJsonDynamicParam( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => + MapEntry(BigInt.parse(k), FromJsonDynamicParam.fromJson(e)), + ), + ); + +Map<String, dynamic> _$SimpleClassNullableOfBigIntToFromJsonDynamicParamToJson( + SimpleClassNullableOfBigIntToFromJsonDynamicParam instance) => + <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassOfDateTimeToFromJsonDynamicParam + _$SimpleClassOfDateTimeToFromJsonDynamicParamFromJson( + Map<String, dynamic> json) => + SimpleClassOfDateTimeToFromJsonDynamicParam( + (json['value'] as Map<String, dynamic>).map( + (k, e) => + MapEntry(DateTime.parse(k), FromJsonDynamicParam.fromJson(e)), + ), + ); + +Map<String, dynamic> _$SimpleClassOfDateTimeToFromJsonDynamicParamToJson( + SimpleClassOfDateTimeToFromJsonDynamicParam instance) => + <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toIso8601String(), e)), + }; + +SimpleClassNullableOfDateTimeToFromJsonDynamicParam + _$SimpleClassNullableOfDateTimeToFromJsonDynamicParamFromJson( + Map<String, dynamic> json) => + SimpleClassNullableOfDateTimeToFromJsonDynamicParam( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => + MapEntry(DateTime.parse(k), FromJsonDynamicParam.fromJson(e)), + ), + ); + +Map<String, dynamic> + _$SimpleClassNullableOfDateTimeToFromJsonDynamicParamToJson( + SimpleClassNullableOfDateTimeToFromJsonDynamicParam instance) => + <String, dynamic>{ + 'value': + instance.value?.map((k, e) => MapEntry(k.toIso8601String(), e)), + }; + +SimpleClassOfDynamicToFromJsonDynamicParam + _$SimpleClassOfDynamicToFromJsonDynamicParamFromJson( + Map<String, dynamic> json) => + SimpleClassOfDynamicToFromJsonDynamicParam( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(k, FromJsonDynamicParam.fromJson(e)), + ), + ); + +Map<String, dynamic> _$SimpleClassOfDynamicToFromJsonDynamicParamToJson( + SimpleClassOfDynamicToFromJsonDynamicParam instance) => + <String, dynamic>{ + 'value': instance.value, + }; + +SimpleClassNullableOfDynamicToFromJsonDynamicParam + _$SimpleClassNullableOfDynamicToFromJsonDynamicParamFromJson( + Map<String, dynamic> json) => + SimpleClassNullableOfDynamicToFromJsonDynamicParam( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, FromJsonDynamicParam.fromJson(e)), + ), + ); + +Map<String, dynamic> _$SimpleClassNullableOfDynamicToFromJsonDynamicParamToJson( + SimpleClassNullableOfDynamicToFromJsonDynamicParam instance) => + <String, dynamic>{ + 'value': instance.value, + }; + +SimpleClassOfEnumTypeToFromJsonDynamicParam + _$SimpleClassOfEnumTypeToFromJsonDynamicParamFromJson( + Map<String, dynamic> json) => + SimpleClassOfEnumTypeToFromJsonDynamicParam( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), + FromJsonDynamicParam.fromJson(e)), + ), + ); + +Map<String, dynamic> _$SimpleClassOfEnumTypeToFromJsonDynamicParamToJson( + SimpleClassOfEnumTypeToFromJsonDynamicParam instance) => + <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), + }; + +SimpleClassNullableOfEnumTypeToFromJsonDynamicParam + _$SimpleClassNullableOfEnumTypeToFromJsonDynamicParamFromJson( + Map<String, dynamic> json) => + SimpleClassNullableOfEnumTypeToFromJsonDynamicParam( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), + FromJsonDynamicParam.fromJson(e)), + ), + ); + +Map<String, dynamic> + _$SimpleClassNullableOfEnumTypeToFromJsonDynamicParamToJson( + SimpleClassNullableOfEnumTypeToFromJsonDynamicParam instance) => + <String, dynamic>{ + 'value': + instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), + }; + +SimpleClassOfIntToFromJsonDynamicParam + _$SimpleClassOfIntToFromJsonDynamicParamFromJson( + Map<String, dynamic> json) => + SimpleClassOfIntToFromJsonDynamicParam( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(int.parse(k), FromJsonDynamicParam.fromJson(e)), + ), + ); + +Map<String, dynamic> _$SimpleClassOfIntToFromJsonDynamicParamToJson( + SimpleClassOfIntToFromJsonDynamicParam instance) => + <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassNullableOfIntToFromJsonDynamicParam + _$SimpleClassNullableOfIntToFromJsonDynamicParamFromJson( + Map<String, dynamic> json) => + SimpleClassNullableOfIntToFromJsonDynamicParam( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(int.parse(k), FromJsonDynamicParam.fromJson(e)), + ), + ); + +Map<String, dynamic> _$SimpleClassNullableOfIntToFromJsonDynamicParamToJson( + SimpleClassNullableOfIntToFromJsonDynamicParam instance) => + <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassOfObjectToFromJsonDynamicParam + _$SimpleClassOfObjectToFromJsonDynamicParamFromJson( + Map<String, dynamic> json) => + SimpleClassOfObjectToFromJsonDynamicParam( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(k, FromJsonDynamicParam.fromJson(e)), + ), + ); + +Map<String, dynamic> _$SimpleClassOfObjectToFromJsonDynamicParamToJson( + SimpleClassOfObjectToFromJsonDynamicParam instance) => + <String, dynamic>{ + 'value': instance.value, + }; + +SimpleClassNullableOfObjectToFromJsonDynamicParam + _$SimpleClassNullableOfObjectToFromJsonDynamicParamFromJson( + Map<String, dynamic> json) => + SimpleClassNullableOfObjectToFromJsonDynamicParam( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, FromJsonDynamicParam.fromJson(e)), + ), + ); + +Map<String, dynamic> _$SimpleClassNullableOfObjectToFromJsonDynamicParamToJson( + SimpleClassNullableOfObjectToFromJsonDynamicParam instance) => + <String, dynamic>{ + 'value': instance.value, + }; + +SimpleClassOfStringToFromJsonDynamicParam + _$SimpleClassOfStringToFromJsonDynamicParamFromJson( + Map<String, dynamic> json) => + SimpleClassOfStringToFromJsonDynamicParam( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(k, FromJsonDynamicParam.fromJson(e)), + ), + ); + +Map<String, dynamic> _$SimpleClassOfStringToFromJsonDynamicParamToJson( + SimpleClassOfStringToFromJsonDynamicParam instance) => + <String, dynamic>{ + 'value': instance.value, + }; + +SimpleClassNullableOfStringToFromJsonDynamicParam + _$SimpleClassNullableOfStringToFromJsonDynamicParamFromJson( + Map<String, dynamic> json) => + SimpleClassNullableOfStringToFromJsonDynamicParam( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, FromJsonDynamicParam.fromJson(e)), + ), + ); + +Map<String, dynamic> _$SimpleClassNullableOfStringToFromJsonDynamicParamToJson( + SimpleClassNullableOfStringToFromJsonDynamicParam instance) => + <String, dynamic>{ + 'value': instance.value, + }; + +SimpleClassOfUriToFromJsonDynamicParam + _$SimpleClassOfUriToFromJsonDynamicParamFromJson( + Map<String, dynamic> json) => + SimpleClassOfUriToFromJsonDynamicParam( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(Uri.parse(k), FromJsonDynamicParam.fromJson(e)), + ), + ); + +Map<String, dynamic> _$SimpleClassOfUriToFromJsonDynamicParamToJson( + SimpleClassOfUriToFromJsonDynamicParam instance) => + <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassNullableOfUriToFromJsonDynamicParam + _$SimpleClassNullableOfUriToFromJsonDynamicParamFromJson( + Map<String, dynamic> json) => + SimpleClassNullableOfUriToFromJsonDynamicParam( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(Uri.parse(k), FromJsonDynamicParam.fromJson(e)), + ), + ); + +Map<String, dynamic> _$SimpleClassNullableOfUriToFromJsonDynamicParamToJson( + SimpleClassNullableOfUriToFromJsonDynamicParam instance) => + <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassOfBigIntToFromJsonNullableObjectParam + _$SimpleClassOfBigIntToFromJsonNullableObjectParamFromJson( + Map<String, dynamic> json) => + SimpleClassOfBigIntToFromJsonNullableObjectParam( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry( + BigInt.parse(k), FromJsonNullableObjectParam.fromJson(e)), + ), + ); + +Map<String, dynamic> _$SimpleClassOfBigIntToFromJsonNullableObjectParamToJson( + SimpleClassOfBigIntToFromJsonNullableObjectParam instance) => + <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassNullableOfBigIntToFromJsonNullableObjectParam + _$SimpleClassNullableOfBigIntToFromJsonNullableObjectParamFromJson( + Map<String, dynamic> json) => + SimpleClassNullableOfBigIntToFromJsonNullableObjectParam( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry( + BigInt.parse(k), FromJsonNullableObjectParam.fromJson(e)), + ), + ); + +Map<String, + dynamic> _$SimpleClassNullableOfBigIntToFromJsonNullableObjectParamToJson( + SimpleClassNullableOfBigIntToFromJsonNullableObjectParam instance) => + <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassOfDateTimeToFromJsonNullableObjectParam + _$SimpleClassOfDateTimeToFromJsonNullableObjectParamFromJson( + Map<String, dynamic> json) => + SimpleClassOfDateTimeToFromJsonNullableObjectParam( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry( + DateTime.parse(k), FromJsonNullableObjectParam.fromJson(e)), + ), + ); + +Map<String, dynamic> _$SimpleClassOfDateTimeToFromJsonNullableObjectParamToJson( + SimpleClassOfDateTimeToFromJsonNullableObjectParam instance) => + <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toIso8601String(), e)), + }; + +SimpleClassNullableOfDateTimeToFromJsonNullableObjectParam + _$SimpleClassNullableOfDateTimeToFromJsonNullableObjectParamFromJson( + Map<String, dynamic> json) => + SimpleClassNullableOfDateTimeToFromJsonNullableObjectParam( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry( + DateTime.parse(k), FromJsonNullableObjectParam.fromJson(e)), + ), + ); + +Map<String, + dynamic> _$SimpleClassNullableOfDateTimeToFromJsonNullableObjectParamToJson( + SimpleClassNullableOfDateTimeToFromJsonNullableObjectParam instance) => + <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toIso8601String(), e)), + }; + +SimpleClassOfDynamicToFromJsonNullableObjectParam + _$SimpleClassOfDynamicToFromJsonNullableObjectParamFromJson( + Map<String, dynamic> json) => + SimpleClassOfDynamicToFromJsonNullableObjectParam( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(k, FromJsonNullableObjectParam.fromJson(e)), + ), + ); + +Map<String, dynamic> _$SimpleClassOfDynamicToFromJsonNullableObjectParamToJson( + SimpleClassOfDynamicToFromJsonNullableObjectParam instance) => + <String, dynamic>{ + 'value': instance.value, + }; + +SimpleClassNullableOfDynamicToFromJsonNullableObjectParam + _$SimpleClassNullableOfDynamicToFromJsonNullableObjectParamFromJson( + Map<String, dynamic> json) => + SimpleClassNullableOfDynamicToFromJsonNullableObjectParam( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, FromJsonNullableObjectParam.fromJson(e)), + ), + ); + +Map<String, + dynamic> _$SimpleClassNullableOfDynamicToFromJsonNullableObjectParamToJson( + SimpleClassNullableOfDynamicToFromJsonNullableObjectParam instance) => + <String, dynamic>{ + 'value': instance.value, + }; + +SimpleClassOfEnumTypeToFromJsonNullableObjectParam + _$SimpleClassOfEnumTypeToFromJsonNullableObjectParamFromJson( + Map<String, dynamic> json) => + SimpleClassOfEnumTypeToFromJsonNullableObjectParam( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), + FromJsonNullableObjectParam.fromJson(e)), + ), + ); + +Map<String, dynamic> _$SimpleClassOfEnumTypeToFromJsonNullableObjectParamToJson( + SimpleClassOfEnumTypeToFromJsonNullableObjectParam instance) => + <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), + }; + +SimpleClassNullableOfEnumTypeToFromJsonNullableObjectParam + _$SimpleClassNullableOfEnumTypeToFromJsonNullableObjectParamFromJson( + Map<String, dynamic> json) => + SimpleClassNullableOfEnumTypeToFromJsonNullableObjectParam( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), + FromJsonNullableObjectParam.fromJson(e)), + ), + ); + +Map<String, + dynamic> _$SimpleClassNullableOfEnumTypeToFromJsonNullableObjectParamToJson( + SimpleClassNullableOfEnumTypeToFromJsonNullableObjectParam instance) => + <String, dynamic>{ + 'value': + instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), + }; + +SimpleClassOfIntToFromJsonNullableObjectParam + _$SimpleClassOfIntToFromJsonNullableObjectParamFromJson( + Map<String, dynamic> json) => + SimpleClassOfIntToFromJsonNullableObjectParam( + (json['value'] as Map<String, dynamic>).map( + (k, e) => + MapEntry(int.parse(k), FromJsonNullableObjectParam.fromJson(e)), + ), + ); + +Map<String, dynamic> _$SimpleClassOfIntToFromJsonNullableObjectParamToJson( + SimpleClassOfIntToFromJsonNullableObjectParam instance) => + <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassNullableOfIntToFromJsonNullableObjectParam + _$SimpleClassNullableOfIntToFromJsonNullableObjectParamFromJson( + Map<String, dynamic> json) => + SimpleClassNullableOfIntToFromJsonNullableObjectParam( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => + MapEntry(int.parse(k), FromJsonNullableObjectParam.fromJson(e)), + ), + ); + +Map<String, dynamic> + _$SimpleClassNullableOfIntToFromJsonNullableObjectParamToJson( + SimpleClassNullableOfIntToFromJsonNullableObjectParam instance) => + <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassOfObjectToFromJsonNullableObjectParam + _$SimpleClassOfObjectToFromJsonNullableObjectParamFromJson( + Map<String, dynamic> json) => + SimpleClassOfObjectToFromJsonNullableObjectParam( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(k, FromJsonNullableObjectParam.fromJson(e)), + ), + ); + +Map<String, dynamic> _$SimpleClassOfObjectToFromJsonNullableObjectParamToJson( + SimpleClassOfObjectToFromJsonNullableObjectParam instance) => + <String, dynamic>{ + 'value': instance.value, + }; + +SimpleClassNullableOfObjectToFromJsonNullableObjectParam + _$SimpleClassNullableOfObjectToFromJsonNullableObjectParamFromJson( + Map<String, dynamic> json) => + SimpleClassNullableOfObjectToFromJsonNullableObjectParam( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, FromJsonNullableObjectParam.fromJson(e)), + ), + ); + +Map<String, + dynamic> _$SimpleClassNullableOfObjectToFromJsonNullableObjectParamToJson( + SimpleClassNullableOfObjectToFromJsonNullableObjectParam instance) => + <String, dynamic>{ + 'value': instance.value, + }; + +SimpleClassOfStringToFromJsonNullableObjectParam + _$SimpleClassOfStringToFromJsonNullableObjectParamFromJson( + Map<String, dynamic> json) => + SimpleClassOfStringToFromJsonNullableObjectParam( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(k, FromJsonNullableObjectParam.fromJson(e)), + ), + ); + +Map<String, dynamic> _$SimpleClassOfStringToFromJsonNullableObjectParamToJson( + SimpleClassOfStringToFromJsonNullableObjectParam instance) => + <String, dynamic>{ + 'value': instance.value, + }; + +SimpleClassNullableOfStringToFromJsonNullableObjectParam + _$SimpleClassNullableOfStringToFromJsonNullableObjectParamFromJson( + Map<String, dynamic> json) => + SimpleClassNullableOfStringToFromJsonNullableObjectParam( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, FromJsonNullableObjectParam.fromJson(e)), + ), + ); + +Map<String, + dynamic> _$SimpleClassNullableOfStringToFromJsonNullableObjectParamToJson( + SimpleClassNullableOfStringToFromJsonNullableObjectParam instance) => + <String, dynamic>{ + 'value': instance.value, + }; + +SimpleClassOfUriToFromJsonNullableObjectParam + _$SimpleClassOfUriToFromJsonNullableObjectParamFromJson( + Map<String, dynamic> json) => + SimpleClassOfUriToFromJsonNullableObjectParam( + (json['value'] as Map<String, dynamic>).map( + (k, e) => + MapEntry(Uri.parse(k), FromJsonNullableObjectParam.fromJson(e)), + ), + ); + +Map<String, dynamic> _$SimpleClassOfUriToFromJsonNullableObjectParamToJson( + SimpleClassOfUriToFromJsonNullableObjectParam instance) => + <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassNullableOfUriToFromJsonNullableObjectParam + _$SimpleClassNullableOfUriToFromJsonNullableObjectParamFromJson( + Map<String, dynamic> json) => + SimpleClassNullableOfUriToFromJsonNullableObjectParam( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => + MapEntry(Uri.parse(k), FromJsonNullableObjectParam.fromJson(e)), + ), + ); + +Map<String, dynamic> + _$SimpleClassNullableOfUriToFromJsonNullableObjectParamToJson( + SimpleClassNullableOfUriToFromJsonNullableObjectParam instance) => + <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassOfBigIntToFromJsonObjectParam + _$SimpleClassOfBigIntToFromJsonObjectParamFromJson( + Map<String, dynamic> json) => + SimpleClassOfBigIntToFromJsonObjectParam( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry( + BigInt.parse(k), FromJsonObjectParam.fromJson(e as Object)), + ), + ); + +Map<String, dynamic> _$SimpleClassOfBigIntToFromJsonObjectParamToJson( + SimpleClassOfBigIntToFromJsonObjectParam instance) => + <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassNullableOfBigIntToFromJsonObjectParam + _$SimpleClassNullableOfBigIntToFromJsonObjectParamFromJson( + Map<String, dynamic> json) => + SimpleClassNullableOfBigIntToFromJsonObjectParam( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry( + BigInt.parse(k), FromJsonObjectParam.fromJson(e as Object)), + ), + ); + +Map<String, dynamic> _$SimpleClassNullableOfBigIntToFromJsonObjectParamToJson( + SimpleClassNullableOfBigIntToFromJsonObjectParam instance) => + <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassOfDateTimeToFromJsonObjectParam + _$SimpleClassOfDateTimeToFromJsonObjectParamFromJson( + Map<String, dynamic> json) => + SimpleClassOfDateTimeToFromJsonObjectParam( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry( + DateTime.parse(k), FromJsonObjectParam.fromJson(e as Object)), + ), + ); + +Map<String, dynamic> _$SimpleClassOfDateTimeToFromJsonObjectParamToJson( + SimpleClassOfDateTimeToFromJsonObjectParam instance) => + <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toIso8601String(), e)), + }; + +SimpleClassNullableOfDateTimeToFromJsonObjectParam + _$SimpleClassNullableOfDateTimeToFromJsonObjectParamFromJson( + Map<String, dynamic> json) => + SimpleClassNullableOfDateTimeToFromJsonObjectParam( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry( + DateTime.parse(k), FromJsonObjectParam.fromJson(e as Object)), + ), + ); + +Map<String, dynamic> _$SimpleClassNullableOfDateTimeToFromJsonObjectParamToJson( + SimpleClassNullableOfDateTimeToFromJsonObjectParam instance) => + <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toIso8601String(), e)), + }; + +SimpleClassOfDynamicToFromJsonObjectParam + _$SimpleClassOfDynamicToFromJsonObjectParamFromJson( + Map<String, dynamic> json) => + SimpleClassOfDynamicToFromJsonObjectParam( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(k, FromJsonObjectParam.fromJson(e as Object)), + ), + ); + +Map<String, dynamic> _$SimpleClassOfDynamicToFromJsonObjectParamToJson( + SimpleClassOfDynamicToFromJsonObjectParam instance) => + <String, dynamic>{ + 'value': instance.value, + }; + +SimpleClassNullableOfDynamicToFromJsonObjectParam + _$SimpleClassNullableOfDynamicToFromJsonObjectParamFromJson( + Map<String, dynamic> json) => + SimpleClassNullableOfDynamicToFromJsonObjectParam( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, FromJsonObjectParam.fromJson(e as Object)), + ), + ); + +Map<String, dynamic> _$SimpleClassNullableOfDynamicToFromJsonObjectParamToJson( + SimpleClassNullableOfDynamicToFromJsonObjectParam instance) => + <String, dynamic>{ + 'value': instance.value, + }; + +SimpleClassOfEnumTypeToFromJsonObjectParam + _$SimpleClassOfEnumTypeToFromJsonObjectParamFromJson( + Map<String, dynamic> json) => + SimpleClassOfEnumTypeToFromJsonObjectParam( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), + FromJsonObjectParam.fromJson(e as Object)), + ), + ); + +Map<String, dynamic> _$SimpleClassOfEnumTypeToFromJsonObjectParamToJson( + SimpleClassOfEnumTypeToFromJsonObjectParam instance) => + <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), + }; + +SimpleClassNullableOfEnumTypeToFromJsonObjectParam + _$SimpleClassNullableOfEnumTypeToFromJsonObjectParamFromJson( + Map<String, dynamic> json) => + SimpleClassNullableOfEnumTypeToFromJsonObjectParam( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), + FromJsonObjectParam.fromJson(e as Object)), + ), + ); + +Map<String, dynamic> _$SimpleClassNullableOfEnumTypeToFromJsonObjectParamToJson( + SimpleClassNullableOfEnumTypeToFromJsonObjectParam instance) => + <String, dynamic>{ + 'value': + instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), + }; + +SimpleClassOfIntToFromJsonObjectParam + _$SimpleClassOfIntToFromJsonObjectParamFromJson( + Map<String, dynamic> json) => + SimpleClassOfIntToFromJsonObjectParam( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry( + int.parse(k), FromJsonObjectParam.fromJson(e as Object)), + ), + ); + +Map<String, dynamic> _$SimpleClassOfIntToFromJsonObjectParamToJson( + SimpleClassOfIntToFromJsonObjectParam instance) => + <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassNullableOfIntToFromJsonObjectParam + _$SimpleClassNullableOfIntToFromJsonObjectParamFromJson( + Map<String, dynamic> json) => + SimpleClassNullableOfIntToFromJsonObjectParam( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry( + int.parse(k), FromJsonObjectParam.fromJson(e as Object)), + ), + ); + +Map<String, dynamic> _$SimpleClassNullableOfIntToFromJsonObjectParamToJson( + SimpleClassNullableOfIntToFromJsonObjectParam instance) => + <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassOfObjectToFromJsonObjectParam + _$SimpleClassOfObjectToFromJsonObjectParamFromJson( + Map<String, dynamic> json) => + SimpleClassOfObjectToFromJsonObjectParam( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(k, FromJsonObjectParam.fromJson(e as Object)), + ), + ); + +Map<String, dynamic> _$SimpleClassOfObjectToFromJsonObjectParamToJson( + SimpleClassOfObjectToFromJsonObjectParam instance) => + <String, dynamic>{ + 'value': instance.value, + }; + +SimpleClassNullableOfObjectToFromJsonObjectParam + _$SimpleClassNullableOfObjectToFromJsonObjectParamFromJson( + Map<String, dynamic> json) => + SimpleClassNullableOfObjectToFromJsonObjectParam( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, FromJsonObjectParam.fromJson(e as Object)), + ), + ); + +Map<String, dynamic> _$SimpleClassNullableOfObjectToFromJsonObjectParamToJson( + SimpleClassNullableOfObjectToFromJsonObjectParam instance) => + <String, dynamic>{ + 'value': instance.value, + }; + +SimpleClassOfStringToFromJsonObjectParam + _$SimpleClassOfStringToFromJsonObjectParamFromJson( + Map<String, dynamic> json) => + SimpleClassOfStringToFromJsonObjectParam( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(k, FromJsonObjectParam.fromJson(e as Object)), + ), + ); + +Map<String, dynamic> _$SimpleClassOfStringToFromJsonObjectParamToJson( + SimpleClassOfStringToFromJsonObjectParam instance) => + <String, dynamic>{ + 'value': instance.value, + }; + +SimpleClassNullableOfStringToFromJsonObjectParam + _$SimpleClassNullableOfStringToFromJsonObjectParamFromJson( + Map<String, dynamic> json) => + SimpleClassNullableOfStringToFromJsonObjectParam( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, FromJsonObjectParam.fromJson(e as Object)), + ), + ); + +Map<String, dynamic> _$SimpleClassNullableOfStringToFromJsonObjectParamToJson( + SimpleClassNullableOfStringToFromJsonObjectParam instance) => + <String, dynamic>{ + 'value': instance.value, + }; + +SimpleClassOfUriToFromJsonObjectParam + _$SimpleClassOfUriToFromJsonObjectParamFromJson( + Map<String, dynamic> json) => + SimpleClassOfUriToFromJsonObjectParam( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry( + Uri.parse(k), FromJsonObjectParam.fromJson(e as Object)), + ), + ); + +Map<String, dynamic> _$SimpleClassOfUriToFromJsonObjectParamToJson( + SimpleClassOfUriToFromJsonObjectParam instance) => + <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), + }; + +SimpleClassNullableOfUriToFromJsonObjectParam + _$SimpleClassNullableOfUriToFromJsonObjectParamFromJson( + Map<String, dynamic> json) => + SimpleClassNullableOfUriToFromJsonObjectParam( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry( + Uri.parse(k), FromJsonObjectParam.fromJson(e as Object)), + ), + ); + +Map<String, dynamic> _$SimpleClassNullableOfUriToFromJsonObjectParamToJson( + SimpleClassNullableOfUriToFromJsonObjectParam instance) => + <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), + }; + SimpleClassOfBigIntToInt _$SimpleClassOfBigIntToIntFromJson( Map<String, dynamic> json) => SimpleClassOfBigIntToInt( diff --git a/json_serializable/test/supported_types/input.type_set.dart b/json_serializable/test/supported_types/input.type_set.dart index 8e74fb7c2..cfc46748c 100644 --- a/json_serializable/test/supported_types/input.type_set.dart +++ b/json_serializable/test/supported_types/input.type_set.dart @@ -419,6 +419,102 @@ class SimpleClassNullableOfEnumTypeNullable { _$SimpleClassNullableOfEnumTypeNullableToJson(this); } +@JsonSerializable() +class SimpleClassOfFromJsonDynamicParam { + final Set<FromJsonDynamicParam> value; + + SimpleClassOfFromJsonDynamicParam( + this.value, + ); + + factory SimpleClassOfFromJsonDynamicParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassOfFromJsonDynamicParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassOfFromJsonDynamicParamToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfFromJsonDynamicParam { + final Set<FromJsonDynamicParam>? value; + + SimpleClassNullableOfFromJsonDynamicParam( + this.value, + ); + + factory SimpleClassNullableOfFromJsonDynamicParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassNullableOfFromJsonDynamicParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassNullableOfFromJsonDynamicParamToJson(this); +} + +@JsonSerializable() +class SimpleClassOfFromJsonNullableObjectParam { + final Set<FromJsonNullableObjectParam> value; + + SimpleClassOfFromJsonNullableObjectParam( + this.value, + ); + + factory SimpleClassOfFromJsonNullableObjectParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassOfFromJsonNullableObjectParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassOfFromJsonNullableObjectParamToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfFromJsonNullableObjectParam { + final Set<FromJsonNullableObjectParam>? value; + + SimpleClassNullableOfFromJsonNullableObjectParam( + this.value, + ); + + factory SimpleClassNullableOfFromJsonNullableObjectParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassNullableOfFromJsonNullableObjectParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassNullableOfFromJsonNullableObjectParamToJson(this); +} + +@JsonSerializable() +class SimpleClassOfFromJsonObjectParam { + final Set<FromJsonObjectParam> value; + + SimpleClassOfFromJsonObjectParam( + this.value, + ); + + factory SimpleClassOfFromJsonObjectParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassOfFromJsonObjectParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassOfFromJsonObjectParamToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfFromJsonObjectParam { + final Set<FromJsonObjectParam>? value; + + SimpleClassNullableOfFromJsonObjectParam( + this.value, + ); + + factory SimpleClassNullableOfFromJsonObjectParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassNullableOfFromJsonObjectParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassNullableOfFromJsonObjectParamToJson(this); +} + @JsonSerializable() class SimpleClassOfInt { final Set<int> value; diff --git a/json_serializable/test/supported_types/input.type_set.g.dart b/json_serializable/test/supported_types/input.type_set.g.dart index 38f681536..dc8ed047f 100644 --- a/json_serializable/test/supported_types/input.type_set.g.dart +++ b/json_serializable/test/supported_types/input.type_set.g.dart @@ -392,6 +392,94 @@ Map<String, dynamic> _$SimpleClassNullableOfEnumTypeNullableToJson( 'value': instance.value?.map((e) => _$EnumTypeEnumMap[e]).toList(), }; +SimpleClassOfFromJsonDynamicParam _$SimpleClassOfFromJsonDynamicParamFromJson( + Map<String, dynamic> json) => + SimpleClassOfFromJsonDynamicParam( + (json['value'] as List<dynamic>) + .map(FromJsonDynamicParam.fromJson) + .toSet(), + ); + +Map<String, dynamic> _$SimpleClassOfFromJsonDynamicParamToJson( + SimpleClassOfFromJsonDynamicParam instance) => + <String, dynamic>{ + 'value': instance.value.toList(), + }; + +SimpleClassNullableOfFromJsonDynamicParam + _$SimpleClassNullableOfFromJsonDynamicParamFromJson( + Map<String, dynamic> json) => + SimpleClassNullableOfFromJsonDynamicParam( + (json['value'] as List<dynamic>?) + ?.map(FromJsonDynamicParam.fromJson) + .toSet(), + ); + +Map<String, dynamic> _$SimpleClassNullableOfFromJsonDynamicParamToJson( + SimpleClassNullableOfFromJsonDynamicParam instance) => + <String, dynamic>{ + 'value': instance.value?.toList(), + }; + +SimpleClassOfFromJsonNullableObjectParam + _$SimpleClassOfFromJsonNullableObjectParamFromJson( + Map<String, dynamic> json) => + SimpleClassOfFromJsonNullableObjectParam( + (json['value'] as List<dynamic>) + .map(FromJsonNullableObjectParam.fromJson) + .toSet(), + ); + +Map<String, dynamic> _$SimpleClassOfFromJsonNullableObjectParamToJson( + SimpleClassOfFromJsonNullableObjectParam instance) => + <String, dynamic>{ + 'value': instance.value.toList(), + }; + +SimpleClassNullableOfFromJsonNullableObjectParam + _$SimpleClassNullableOfFromJsonNullableObjectParamFromJson( + Map<String, dynamic> json) => + SimpleClassNullableOfFromJsonNullableObjectParam( + (json['value'] as List<dynamic>?) + ?.map(FromJsonNullableObjectParam.fromJson) + .toSet(), + ); + +Map<String, dynamic> _$SimpleClassNullableOfFromJsonNullableObjectParamToJson( + SimpleClassNullableOfFromJsonNullableObjectParam instance) => + <String, dynamic>{ + 'value': instance.value?.toList(), + }; + +SimpleClassOfFromJsonObjectParam _$SimpleClassOfFromJsonObjectParamFromJson( + Map<String, dynamic> json) => + SimpleClassOfFromJsonObjectParam( + (json['value'] as List<dynamic>) + .map((e) => FromJsonObjectParam.fromJson(e as Object)) + .toSet(), + ); + +Map<String, dynamic> _$SimpleClassOfFromJsonObjectParamToJson( + SimpleClassOfFromJsonObjectParam instance) => + <String, dynamic>{ + 'value': instance.value.toList(), + }; + +SimpleClassNullableOfFromJsonObjectParam + _$SimpleClassNullableOfFromJsonObjectParamFromJson( + Map<String, dynamic> json) => + SimpleClassNullableOfFromJsonObjectParam( + (json['value'] as List<dynamic>?) + ?.map((e) => FromJsonObjectParam.fromJson(e as Object)) + .toSet(), + ); + +Map<String, dynamic> _$SimpleClassNullableOfFromJsonObjectParamToJson( + SimpleClassNullableOfFromJsonObjectParam instance) => + <String, dynamic>{ + 'value': instance.value?.toList(), + }; + SimpleClassOfInt _$SimpleClassOfIntFromJson(Map<String, dynamic> json) => SimpleClassOfInt( (json['value'] as List<dynamic>).map((e) => e as int).toSet(), diff --git a/json_serializable/tool/test_type_builder.dart b/json_serializable/tool/test_type_builder.dart index af6dd2dd4..e35dfd766 100644 --- a/json_serializable/tool/test_type_builder.dart +++ b/json_serializable/tool/test_type_builder.dart @@ -101,6 +101,9 @@ Iterable<String> get mapKeyTypes => final _iterableGenericArgs = ([ ..._trivialTypesToTest.keys, ..._trivialTypesToTest.keys.map((e) => '$e?'), + 'FromJsonDynamicParam', + 'FromJsonNullableObjectParam', + 'FromJsonObjectParam', 'dynamic', ]..sort(compareAsciiLowerCase)) .toSet(); From 2685abf885d77e1e975a5980bcb3c6d3a59ca95d Mon Sep 17 00:00:00 2001 From: Jonas Finnemann Jensen <jonasfj@google.com> Date: Tue, 2 May 2023 15:38:01 +0200 Subject: [PATCH 484/569] A few proposed topics (#1309) --- checked_yaml/pubspec.yaml | 7 +++++++ json_annotation/pubspec.yaml | 5 +++++ json_serializable/pubspec.yaml | 5 +++++ 3 files changed, 17 insertions(+) diff --git a/checked_yaml/pubspec.yaml b/checked_yaml/pubspec.yaml index c93abad14..b346ecda3 100644 --- a/checked_yaml/pubspec.yaml +++ b/checked_yaml/pubspec.yaml @@ -5,6 +5,13 @@ description: >- Generate more helpful exceptions when decoding YAML documents using package:json_serializable and package:yaml. repository: https://github.com/google/json_serializable.dart/tree/master/checked_yaml +topics: + - yaml + - json + - build-runner + - json-serializable + - codegen + environment: sdk: '>=2.19.0 <3.0.0' diff --git a/json_annotation/pubspec.yaml b/json_annotation/pubspec.yaml index fc43ca68d..2dde7af2f 100644 --- a/json_annotation/pubspec.yaml +++ b/json_annotation/pubspec.yaml @@ -4,6 +4,11 @@ description: >- Classes and helper functions that support JSON code generation via the `json_serializable` package. repository: https://github.com/google/json_serializable.dart/tree/master/json_annotation +topics: + - json + - build-runner + - json-serializable + - codegen environment: sdk: '>=2.19.0 <3.0.0' diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index f3a4d3ac1..a4f7b1cb9 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -6,6 +6,11 @@ description: >- repository: https://github.com/google/json_serializable.dart/tree/master/json_serializable environment: sdk: '>=2.19.0 <3.0.0' +topics: + - json + - build-runner + - json-serializable + - codegen dependencies: analyzer: ^5.2.0 From 2e79481c57d1a18eab6ed41393c0da50872aa08d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 3 May 2023 09:32:51 -0700 Subject: [PATCH 485/569] Bump actions/checkout from 3.5.0 to 3.5.2 (#1308) Bumps [actions/checkout](https://github.com/actions/checkout) from 3.5.0 to 3.5.2. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/8f4b7f84864484a7bf31766abe9204da3cbe65b3...8e5e7e5ab8b370d6c329ec480221332ada57f0ab) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/dart.yml | 32 +++++++++++++-------------- .github/workflows/markdown_linter.yml | 4 ++-- tool/ci.sh | 2 +- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index c8f0e1760..04116ee28 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -1,4 +1,4 @@ -# Created with package:mono_repo v6.5.3 +# Created with package:mono_repo v6.5.4 name: Dart CI on: push: @@ -34,9 +34,9 @@ jobs: sdk: stable - id: checkout name: Checkout repository - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 + uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab - name: mono_repo self validate - run: dart pub global activate mono_repo 6.5.3 + run: dart pub global activate mono_repo 6.5.4 - name: mono_repo self validate run: dart pub global run mono_repo generate --validate job_002: @@ -59,7 +59,7 @@ jobs: sdk: "2.19.0" - id: checkout name: Checkout repository - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 + uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -132,7 +132,7 @@ jobs: sdk: "2.19.0" - id: checkout name: Checkout repository - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 + uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab - id: json_annotation_pub_upgrade name: json_annotation; dart pub upgrade run: dart pub upgrade @@ -162,7 +162,7 @@ jobs: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 + uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -248,7 +248,7 @@ jobs: sdk: "2.19.0" - id: checkout name: Checkout repository - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 + uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -310,7 +310,7 @@ jobs: sdk: "2.19.0" - id: checkout name: Checkout repository - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 + uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -345,7 +345,7 @@ jobs: sdk: "2.19.0" - id: checkout name: Checkout repository - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 + uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -380,7 +380,7 @@ jobs: sdk: "2.19.0" - id: checkout name: Checkout repository - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 + uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -415,7 +415,7 @@ jobs: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 + uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -477,7 +477,7 @@ jobs: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 + uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -512,7 +512,7 @@ jobs: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 + uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -547,7 +547,7 @@ jobs: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 + uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -582,7 +582,7 @@ jobs: sdk: "2.19.0" - id: checkout name: Checkout repository - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 + uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -643,7 +643,7 @@ jobs: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 + uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade diff --git a/.github/workflows/markdown_linter.yml b/.github/workflows/markdown_linter.yml index ce7162673..5186f95cb 100644 --- a/.github/workflows/markdown_linter.yml +++ b/.github/workflows/markdown_linter.yml @@ -11,7 +11,7 @@ jobs: markdown-link-check: runs-on: ubuntu-latest steps: - - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 + - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab - uses: gaurav-nelson/github-action-markdown-link-check@v1 markdown_lint: runs-on: ubuntu-latest @@ -19,7 +19,7 @@ jobs: matrix: node-version: [ 14.x ] steps: - - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 + - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c with: diff --git a/tool/ci.sh b/tool/ci.sh index 18e741b2c..a70cf4343 100755 --- a/tool/ci.sh +++ b/tool/ci.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Created with package:mono_repo v6.5.3 +# Created with package:mono_repo v6.5.4 # Support built in commands on windows out of the box. # When it is a flutter repo (check the pubspec.yaml for "sdk: flutter") From 4c7609d92ad857129dbe3ffd3c7b6314581d6a45 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Wed, 3 May 2023 09:49:07 -0700 Subject: [PATCH 486/569] annotation: Prepare to release v4.8.1 (#1310) --- json_annotation/CHANGELOG.md | 3 ++- json_annotation/pubspec.yaml | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index 5a23b4817..ee6b48c33 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -1,6 +1,7 @@ -## 4.8.1-dev +## 4.8.1 - Require Dart 2.19 +- Add topics. ## 4.8.0 diff --git a/json_annotation/pubspec.yaml b/json_annotation/pubspec.yaml index 2dde7af2f..64bc29b2a 100644 --- a/json_annotation/pubspec.yaml +++ b/json_annotation/pubspec.yaml @@ -1,5 +1,5 @@ name: json_annotation -version: 4.8.1-dev +version: 4.8.1 description: >- Classes and helper functions that support JSON code generation via the `json_serializable` package. From 979c4554caad367424ffa6b0f057ac7e2aa9a9b5 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Wed, 3 May 2023 10:21:20 -0700 Subject: [PATCH 487/569] json_serializable: prepare to release v6.6.2 (#1311) --- json_serializable/CHANGELOG.md | 2 +- json_serializable/README.md | 18 +++++++++--------- .../lib/src/check_dependencies.dart | 2 +- json_serializable/pubspec.yaml | 4 ++-- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 1814d3154..b29d1ba81 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,4 +1,4 @@ -## 6.6.2-dev +## 6.6.2 - Better handling of `Object?` or `dynamic` as `fromJson` constructor param. - Require Dart 2.19 diff --git a/json_serializable/README.md b/json_serializable/README.md index d11f294b3..4f1d53fe5 100644 --- a/json_serializable/README.md +++ b/json_serializable/README.md @@ -300,15 +300,15 @@ targets: [`Enum`]: https://api.dart.dev/stable/dart-core/Enum-class.html [`int`]: https://api.dart.dev/stable/dart-core/int-class.html [`Iterable`]: https://api.dart.dev/stable/dart-core/Iterable-class.html -[`JsonConverter`]: https://pub.dev/documentation/json_annotation/4.8.0/json_annotation/JsonConverter-class.html -[`JsonEnum.valueField`]: https://pub.dev/documentation/json_annotation/4.8.0/json_annotation/JsonEnum/valueField.html -[`JsonEnum`]: https://pub.dev/documentation/json_annotation/4.8.0/json_annotation/JsonEnum-class.html -[`JsonKey.fromJson`]: https://pub.dev/documentation/json_annotation/4.8.0/json_annotation/JsonKey/fromJson.html -[`JsonKey.toJson`]: https://pub.dev/documentation/json_annotation/4.8.0/json_annotation/JsonKey/toJson.html -[`JsonKey`]: https://pub.dev/documentation/json_annotation/4.8.0/json_annotation/JsonKey-class.html -[`JsonLiteral`]: https://pub.dev/documentation/json_annotation/4.8.0/json_annotation/JsonLiteral-class.html -[`JsonSerializable`]: https://pub.dev/documentation/json_annotation/4.8.0/json_annotation/JsonSerializable-class.html -[`JsonValue`]: https://pub.dev/documentation/json_annotation/4.8.0/json_annotation/JsonValue-class.html +[`JsonConverter`]: https://pub.dev/documentation/json_annotation/4.8.1/json_annotation/JsonConverter-class.html +[`JsonEnum.valueField`]: https://pub.dev/documentation/json_annotation/4.8.1/json_annotation/JsonEnum/valueField.html +[`JsonEnum`]: https://pub.dev/documentation/json_annotation/4.8.1/json_annotation/JsonEnum-class.html +[`JsonKey.fromJson`]: https://pub.dev/documentation/json_annotation/4.8.1/json_annotation/JsonKey/fromJson.html +[`JsonKey.toJson`]: https://pub.dev/documentation/json_annotation/4.8.1/json_annotation/JsonKey/toJson.html +[`JsonKey`]: https://pub.dev/documentation/json_annotation/4.8.1/json_annotation/JsonKey-class.html +[`JsonLiteral`]: https://pub.dev/documentation/json_annotation/4.8.1/json_annotation/JsonLiteral-class.html +[`JsonSerializable`]: https://pub.dev/documentation/json_annotation/4.8.1/json_annotation/JsonSerializable-class.html +[`JsonValue`]: https://pub.dev/documentation/json_annotation/4.8.1/json_annotation/JsonValue-class.html [`List`]: https://api.dart.dev/stable/dart-core/List-class.html [`Map`]: https://api.dart.dev/stable/dart-core/Map-class.html [`num`]: https://api.dart.dev/stable/dart-core/num-class.html diff --git a/json_serializable/lib/src/check_dependencies.dart b/json_serializable/lib/src/check_dependencies.dart index 86e580bea..63512589d 100644 --- a/json_serializable/lib/src/check_dependencies.dart +++ b/json_serializable/lib/src/check_dependencies.dart @@ -10,7 +10,7 @@ import 'package:pubspec_parse/pubspec_parse.dart'; const _productionDirectories = {'lib', 'bin'}; const _annotationPkgName = 'json_annotation'; -final requiredJsonAnnotationMinVersion = Version.parse('4.8.0'); +final requiredJsonAnnotationMinVersion = Version.parse('4.8.1'); Future<void> pubspecHasRightVersion(BuildStep buildStep) async { final segments = buildStep.inputId.pathSegments; diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index a4f7b1cb9..a80e4bc24 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 6.6.2-dev +version: 6.6.2 description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. @@ -21,7 +21,7 @@ dependencies: # Use a tight version constraint to ensure that a constraint on # `json_annotation` properly constrains all features it provides. - json_annotation: '>=4.8.0 <4.9.0' + json_annotation: '>=4.8.1 <4.9.0' meta: ^1.3.0 path: ^1.8.0 pub_semver: ^2.0.0 From d8d41afe00321f936dcc44261c7c6ae2806f72af Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Wed, 3 May 2023 10:36:51 -0700 Subject: [PATCH 488/569] checked_yaml: prepare to publish 2.0.3 (#1312) --- checked_yaml/CHANGELOG.md | 3 ++- checked_yaml/pubspec.yaml | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/checked_yaml/CHANGELOG.md b/checked_yaml/CHANGELOG.md index 3d8404566..bcecf04d6 100644 --- a/checked_yaml/CHANGELOG.md +++ b/checked_yaml/CHANGELOG.md @@ -1,6 +1,7 @@ -## 2.0.3-dev +## 2.0.3 - Require Dart 2.19 +- Add topics ## 2.0.2 diff --git a/checked_yaml/pubspec.yaml b/checked_yaml/pubspec.yaml index b346ecda3..1b2e74eec 100644 --- a/checked_yaml/pubspec.yaml +++ b/checked_yaml/pubspec.yaml @@ -1,5 +1,5 @@ name: checked_yaml -version: 2.0.3-dev +version: 2.0.3 description: >- Generate more helpful exceptions when decoding YAML documents using From 8c39dd2584513b9dc927dfe108b54a5da413a49f Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Mon, 15 May 2023 18:36:34 -0700 Subject: [PATCH 489/569] Require Dart 3 and latest analyzer (#1319) --- .github/workflows/dart.yml | 278 ++++++++++++------ _test_yaml/pubspec.yaml | 2 +- analysis_options.yaml | 3 + example/pubspec.yaml | 2 +- json_serializable/CHANGELOG.md | 5 + json_serializable/lib/src/decode_helper.dart | 2 +- json_serializable/lib/src/encoder_helper.dart | 2 +- .../lib/src/type_helpers/json_helper.dart | 4 +- .../lib/src/type_helpers/map_helper.dart | 6 +- .../lib/src/type_helpers/value_helper.dart | 4 +- json_serializable/lib/src/utils.dart | 2 +- json_serializable/pubspec.yaml | 8 +- json_serializable/test/config_test.dart | 30 +- .../kitchen_sink/kitchen_sink_yaml_test.dart | 25 +- json_serializable/tool/readme_builder.dart | 15 +- 15 files changed, 236 insertions(+), 152 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 04116ee28..43bc120f6 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -40,16 +40,16 @@ jobs: - name: mono_repo self validate run: dart pub global run mono_repo generate --validate job_002: - name: "analyzer_and_format; Dart 2.19.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; `dart format --output=none --set-exit-if-changed .`, `dart analyze --fatal-infos .`" + name: "analyzer_and_format; Dart 2.19.0; PKG: checked_yaml; `dart format --output=none --set-exit-if-changed .`, `dart analyze --fatal-infos .`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:format-analyze_0" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0;packages:checked_yaml;commands:format-analyze_0" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0;packages:_test_yaml-checked_yaml-example-json_serializable + os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0;packages:checked_yaml os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest @@ -60,19 +60,6 @@ jobs: - id: checkout name: Checkout repository uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab - - id: _test_yaml_pub_upgrade - name: _test_yaml; dart pub upgrade - run: dart pub upgrade - if: "always() && steps.checkout.conclusion == 'success'" - working-directory: _test_yaml - - name: "_test_yaml; dart format --output=none --set-exit-if-changed ." - run: "dart format --output=none --set-exit-if-changed ." - if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" - working-directory: _test_yaml - - name: "_test_yaml; dart analyze --fatal-infos ." - run: dart analyze --fatal-infos . - if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" - working-directory: _test_yaml - id: checked_yaml_pub_upgrade name: checked_yaml; dart pub upgrade run: dart pub upgrade @@ -86,32 +73,6 @@ jobs: run: dart analyze --fatal-infos . if: "always() && steps.checked_yaml_pub_upgrade.conclusion == 'success'" working-directory: checked_yaml - - id: example_pub_upgrade - name: example; dart pub upgrade - run: dart pub upgrade - if: "always() && steps.checkout.conclusion == 'success'" - working-directory: example - - name: "example; dart format --output=none --set-exit-if-changed ." - run: "dart format --output=none --set-exit-if-changed ." - if: "always() && steps.example_pub_upgrade.conclusion == 'success'" - working-directory: example - - name: "example; dart analyze --fatal-infos ." - run: dart analyze --fatal-infos . - if: "always() && steps.example_pub_upgrade.conclusion == 'success'" - working-directory: example - - id: json_serializable_pub_upgrade - name: json_serializable; dart pub upgrade - run: dart pub upgrade - if: "always() && steps.checkout.conclusion == 'success'" - working-directory: json_serializable - - name: "json_serializable; dart format --output=none --set-exit-if-changed ." - run: "dart format --output=none --set-exit-if-changed ." - if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" - working-directory: json_serializable - - name: "json_serializable; dart analyze --fatal-infos ." - run: dart analyze --fatal-infos . - if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" - working-directory: json_serializable job_003: name: "analyzer_and_format; Dart 2.19.0; PKG: json_annotation; `dart analyze`" runs-on: ubuntu-latest @@ -143,6 +104,66 @@ jobs: if: "always() && steps.json_annotation_pub_upgrade.conclusion == 'success'" working-directory: json_annotation job_004: + name: "analyzer_and_format; Dart 3.0.0; PKGS: _test_yaml, example, json_serializable; `dart format --output=none --set-exit-if-changed .`, `dart analyze --fatal-infos .`" + runs-on: ubuntu-latest + steps: + - name: Cache Pub hosted dependencies + uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 + with: + path: "~/.pub-cache/hosted" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:_test_yaml-example-json_serializable;commands:format-analyze_0" + restore-keys: | + os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:_test_yaml-example-json_serializable + os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0 + os:ubuntu-latest;pub-cache-hosted + os:ubuntu-latest + - name: Setup Dart SDK + uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f + with: + sdk: "3.0.0" + - id: checkout + name: Checkout repository + uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab + - id: _test_yaml_pub_upgrade + name: _test_yaml; dart pub upgrade + run: dart pub upgrade + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: _test_yaml + - name: "_test_yaml; dart format --output=none --set-exit-if-changed ." + run: "dart format --output=none --set-exit-if-changed ." + if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" + working-directory: _test_yaml + - name: "_test_yaml; dart analyze --fatal-infos ." + run: dart analyze --fatal-infos . + if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" + working-directory: _test_yaml + - id: example_pub_upgrade + name: example; dart pub upgrade + run: dart pub upgrade + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: example + - name: "example; dart format --output=none --set-exit-if-changed ." + run: "dart format --output=none --set-exit-if-changed ." + if: "always() && steps.example_pub_upgrade.conclusion == 'success'" + working-directory: example + - name: "example; dart analyze --fatal-infos ." + run: dart analyze --fatal-infos . + if: "always() && steps.example_pub_upgrade.conclusion == 'success'" + working-directory: example + - id: json_serializable_pub_upgrade + name: json_serializable; dart pub upgrade + run: dart pub upgrade + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: json_serializable + - name: "json_serializable; dart format --output=none --set-exit-if-changed ." + run: "dart format --output=none --set-exit-if-changed ." + if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" + working-directory: json_serializable + - name: "json_serializable; dart analyze --fatal-infos ." + run: dart analyze --fatal-infos . + if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" + working-directory: json_serializable + job_005: name: "analyzer_and_format; Dart dev; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; `dart format --output=none --set-exit-if-changed .`, `dart analyze --fatal-infos .`" runs-on: ubuntu-latest steps: @@ -228,17 +249,17 @@ jobs: run: dart analyze --fatal-infos . if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" working-directory: json_serializable - job_005: - name: "unit_test; Dart 2.19.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; `dart test`" + job_006: + name: "unit_test; Dart 2.19.0; PKG: checked_yaml; `dart test`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0;packages:checked_yaml;commands:test_0" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0;packages:_test_yaml-checked_yaml-example-json_serializable + os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0;packages:checked_yaml os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest @@ -249,15 +270,6 @@ jobs: - id: checkout name: Checkout repository uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab - - id: _test_yaml_pub_upgrade - name: _test_yaml; dart pub upgrade - run: dart pub upgrade - if: "always() && steps.checkout.conclusion == 'success'" - working-directory: _test_yaml - - name: _test_yaml; dart test - run: dart test - if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" - working-directory: _test_yaml - id: checked_yaml_pub_upgrade name: checked_yaml; dart pub upgrade run: dart pub upgrade @@ -267,6 +279,42 @@ jobs: run: dart test if: "always() && steps.checked_yaml_pub_upgrade.conclusion == 'success'" working-directory: checked_yaml + needs: + - job_001 + - job_002 + - job_003 + - job_004 + - job_005 + job_007: + name: "unit_test; Dart 3.0.0; PKGS: _test_yaml, example, json_serializable; `dart test`" + runs-on: ubuntu-latest + steps: + - name: Cache Pub hosted dependencies + uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 + with: + path: "~/.pub-cache/hosted" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:_test_yaml-example-json_serializable;commands:test_0" + restore-keys: | + os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:_test_yaml-example-json_serializable + os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0 + os:ubuntu-latest;pub-cache-hosted + os:ubuntu-latest + - name: Setup Dart SDK + uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f + with: + sdk: "3.0.0" + - id: checkout + name: Checkout repository + uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab + - id: _test_yaml_pub_upgrade + name: _test_yaml; dart pub upgrade + run: dart pub upgrade + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: _test_yaml + - name: _test_yaml; dart test + run: dart test + if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" + working-directory: _test_yaml - id: example_pub_upgrade name: example; dart pub upgrade run: dart pub upgrade @@ -290,24 +338,25 @@ jobs: - job_002 - job_003 - job_004 - job_006: - name: "unit_test; Dart 2.19.0; PKG: json_serializable; `dart test --run-skipped -t presubmit-only test/annotation_version_test.dart`" + - job_005 + job_008: + name: "unit_test; Dart 3.0.0; PKG: json_serializable; `dart test --run-skipped -t presubmit-only test/annotation_version_test.dart`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0;packages:json_serializable;commands:test_3" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:json_serializable;commands:test_3" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0;packages:json_serializable - os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0 + os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:json_serializable + os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f with: - sdk: "2.19.0" + sdk: "3.0.0" - id: checkout name: Checkout repository uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab @@ -325,24 +374,25 @@ jobs: - job_002 - job_003 - job_004 - job_007: - name: "unit_test; Dart 2.19.0; PKG: json_serializable; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" + - job_005 + job_009: + name: "unit_test; Dart 3.0.0; PKG: json_serializable; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0;packages:json_serializable;commands:test_1" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:json_serializable;commands:test_1" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0;packages:json_serializable - os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0 + os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:json_serializable + os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f with: - sdk: "2.19.0" + sdk: "3.0.0" - id: checkout name: Checkout repository uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab @@ -360,24 +410,25 @@ jobs: - job_002 - job_003 - job_004 - job_008: - name: "unit_test; Dart 2.19.0; PKG: json_serializable; `dart test -p chrome`" + - job_005 + job_010: + name: "unit_test; Dart 3.0.0; PKG: json_serializable; `dart test -p chrome`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0;packages:json_serializable;commands:test_2" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:json_serializable;commands:test_2" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0;packages:json_serializable - os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0 + os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:json_serializable + os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f with: - sdk: "2.19.0" + sdk: "3.0.0" - id: checkout name: Checkout repository uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab @@ -395,7 +446,8 @@ jobs: - job_002 - job_003 - job_004 - job_009: + - job_005 + job_011: name: "unit_test; Dart dev; PKGS: _test_yaml, checked_yaml, example, json_serializable; `dart test`" runs-on: ubuntu-latest steps: @@ -457,7 +509,8 @@ jobs: - job_002 - job_003 - job_004 - job_010: + - job_005 + job_012: name: "unit_test; Dart dev; PKG: json_serializable; `dart test --run-skipped -t presubmit-only test/annotation_version_test.dart`" runs-on: ubuntu-latest steps: @@ -492,7 +545,8 @@ jobs: - job_002 - job_003 - job_004 - job_011: + - job_005 + job_013: name: "unit_test; Dart dev; PKG: json_serializable; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest steps: @@ -527,7 +581,8 @@ jobs: - job_002 - job_003 - job_004 - job_012: + - job_005 + job_014: name: "unit_test; Dart dev; PKG: json_serializable; `dart test -p chrome`" runs-on: ubuntu-latest steps: @@ -562,17 +617,18 @@ jobs: - job_002 - job_003 - job_004 - job_013: - name: "ensure_build; Dart 2.19.0; PKGS: _test_yaml, checked_yaml, example; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" + - job_005 + job_015: + name: "ensure_build; Dart 2.19.0; PKG: checked_yaml; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0;packages:_test_yaml-checked_yaml-example;commands:test_1" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0;packages:checked_yaml;commands:test_1" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0;packages:_test_yaml-checked_yaml-example + os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0;packages:checked_yaml os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest @@ -583,15 +639,6 @@ jobs: - id: checkout name: Checkout repository uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab - - id: _test_yaml_pub_upgrade - name: _test_yaml; dart pub upgrade - run: dart pub upgrade - if: "always() && steps.checkout.conclusion == 'success'" - working-directory: _test_yaml - - name: "_test_yaml; dart test --run-skipped -t presubmit-only test/ensure_build_test.dart" - run: dart test --run-skipped -t presubmit-only test/ensure_build_test.dart - if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" - working-directory: _test_yaml - id: checked_yaml_pub_upgrade name: checked_yaml; dart pub upgrade run: dart pub upgrade @@ -601,6 +648,51 @@ jobs: run: dart test --run-skipped -t presubmit-only test/ensure_build_test.dart if: "always() && steps.checked_yaml_pub_upgrade.conclusion == 'success'" working-directory: checked_yaml + needs: + - job_001 + - job_002 + - job_003 + - job_004 + - job_005 + - job_006 + - job_007 + - job_008 + - job_009 + - job_010 + - job_011 + - job_012 + - job_013 + - job_014 + job_016: + name: "ensure_build; Dart 3.0.0; PKGS: _test_yaml, example; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" + runs-on: ubuntu-latest + steps: + - name: Cache Pub hosted dependencies + uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 + with: + path: "~/.pub-cache/hosted" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:_test_yaml-example;commands:test_1" + restore-keys: | + os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:_test_yaml-example + os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0 + os:ubuntu-latest;pub-cache-hosted + os:ubuntu-latest + - name: Setup Dart SDK + uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f + with: + sdk: "3.0.0" + - id: checkout + name: Checkout repository + uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab + - id: _test_yaml_pub_upgrade + name: _test_yaml; dart pub upgrade + run: dart pub upgrade + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: _test_yaml + - name: "_test_yaml; dart test --run-skipped -t presubmit-only test/ensure_build_test.dart" + run: dart test --run-skipped -t presubmit-only test/ensure_build_test.dart + if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" + working-directory: _test_yaml - id: example_pub_upgrade name: example; dart pub upgrade run: dart pub upgrade @@ -623,7 +715,9 @@ jobs: - job_010 - job_011 - job_012 - job_014: + - job_013 + - job_014 + job_017: name: "ensure_build; Dart dev; PKGS: _test_yaml, checked_yaml, example; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest steps: @@ -684,3 +778,5 @@ jobs: - job_010 - job_011 - job_012 + - job_013 + - job_014 diff --git a/_test_yaml/pubspec.yaml b/_test_yaml/pubspec.yaml index a35dbeef2..4bcc26f14 100644 --- a/_test_yaml/pubspec.yaml +++ b/_test_yaml/pubspec.yaml @@ -2,7 +2,7 @@ name: _test_yaml publish_to: none environment: - sdk: '>=2.19.0 <3.0.0' + sdk: ^3.0.0 dev_dependencies: _json_serial_shared_test: diff --git a/analysis_options.yaml b/analysis_options.yaml index 124d1e711..375e7720b 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -15,6 +15,7 @@ linter: - cancel_subscriptions - cascade_invocations - comment_references + - invalid_case_patterns - join_return_with_assignment - literal_only_boolean_expressions - missing_whitespace_between_adjacent_strings @@ -27,6 +28,8 @@ linter: - prefer_relative_imports - sort_child_properties_last - test_types_in_equals + - type_literal_in_constant_pattern + - unnecessary_breaks - unsafe_html - use_full_hex_values_for_flutter_colors - use_string_buffers diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 069facd40..9eeb261d5 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -2,7 +2,7 @@ name: example publish_to: none environment: - sdk: '>=2.19.0 <3.0.0' + sdk: ^3.0.0 dependencies: json_annotation: ^4.8.0 diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index b29d1ba81..93ca8f831 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,8 @@ +## 6.7.0-dev + +- Require Dart 3.0 +- Require `analyzer: ^5.12.0` + ## 6.6.2 - Better handling of `Object?` or `dynamic` as `fromJson` constructor param. diff --git a/json_serializable/lib/src/decode_helper.dart b/json_serializable/lib/src/decode_helper.dart index daa1967cd..a4a76d1ff 100644 --- a/json_serializable/lib/src/decode_helper.dart +++ b/json_serializable/lib/src/decode_helper.dart @@ -21,7 +21,7 @@ class CreateFactoryResult { CreateFactoryResult(this.output, this.usedFields); } -abstract class DecodeHelper implements HelperCore { +mixin DecodeHelper implements HelperCore { CreateFactoryResult createFactory( Map<String, FieldElement> accessibleFields, Map<String, String> unavailableReasons, diff --git a/json_serializable/lib/src/encoder_helper.dart b/json_serializable/lib/src/encoder_helper.dart index 289411d2e..cfc70b3af 100644 --- a/json_serializable/lib/src/encoder_helper.dart +++ b/json_serializable/lib/src/encoder_helper.dart @@ -13,7 +13,7 @@ import 'type_helpers/generic_factory_helper.dart'; import 'type_helpers/json_converter_helper.dart'; import 'unsupported_type_error.dart'; -abstract class EncodeHelper implements HelperCore { +mixin EncodeHelper implements HelperCore { String _fieldAccess(FieldElement field) => '$_toJsonParamName.${field.name}'; String createPerFieldToJson(Set<FieldElement> accessibleFieldSet) { diff --git a/json_serializable/lib/src/type_helpers/json_helper.dart b/json_serializable/lib/src/type_helpers/json_helper.dart index 79430e42d..fe10a3fea 100644 --- a/json_serializable/lib/src/type_helpers/json_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_helper.dart @@ -181,7 +181,7 @@ TypeParameterType _decodeHelper( final funcParamType = type.normalParameterTypes.single; if ((funcParamType.isDartCoreObject && funcParamType.isNullableType) || - funcParamType.isDynamic) { + funcParamType is DynamicType) { return funcReturnType as TypeParameterType; } } @@ -204,7 +204,7 @@ TypeParameterType _encodeHelper( final type = param.type; if (type is FunctionType && - (type.returnType.isDartCoreObject || type.returnType.isDynamic) && + (type.returnType.isDartCoreObject || type.returnType is DynamicType) && type.normalParameterTypes.length == 1) { final funcParamType = type.normalParameterTypes.single; diff --git a/json_serializable/lib/src/type_helpers/map_helper.dart b/json_serializable/lib/src/type_helpers/map_helper.dart index e84bc5193..806c7074e 100644 --- a/json_serializable/lib/src/type_helpers/map_helper.dart +++ b/json_serializable/lib/src/type_helpers/map_helper.dart @@ -68,7 +68,7 @@ class MapHelper extends TypeHelper<TypeHelperContextWithConfig> { _checkSafeKeyType(expression, keyArg); - final valueArgIsAny = valueArg.isDynamic || + final valueArgIsAny = valueArg is DynamicType || (valueArg.isDartCoreObject && valueArg.isNullableType); final isKeyStringable = _isKeyStringable(keyArg); @@ -114,7 +114,7 @@ class MapHelper extends TypeHelper<TypeHelperContextWithConfig> { if (keyArg.isEnum) { keyUsage = context.deserialize(keyArg, _keyParam).toString(); } else if (context.config.anyMap && - !(keyArg.isDartCoreObject || keyArg.isDynamic)) { + !(keyArg.isDartCoreObject || keyArg is DynamicType)) { keyUsage = '$_keyParam as String'; } else if (context.config.anyMap && keyArg.isDartCoreObject && @@ -157,7 +157,7 @@ bool _isKeyStringable(DartType keyType) => void _checkSafeKeyType(String expression, DartType keyArg) { // We're not going to handle converting key types at the moment // So the only safe types for key are dynamic/Object/String/enum - if (keyArg.isDynamic || + if (keyArg is DynamicType || (!keyArg.isNullableType && (keyArg.isDartCoreObject || coreStringTypeChecker.isExactlyType(keyArg) || diff --git a/json_serializable/lib/src/type_helpers/value_helper.dart b/json_serializable/lib/src/type_helpers/value_helper.dart index a06b61069..49f7372f4 100644 --- a/json_serializable/lib/src/type_helpers/value_helper.dart +++ b/json_serializable/lib/src/type_helpers/value_helper.dart @@ -21,7 +21,7 @@ class ValueHelper extends TypeHelper { TypeHelperContext context, ) { if (targetType.isDartCoreObject || - targetType.isDynamic || + targetType is DynamicType || simpleJsonTypeChecker.isAssignableFromType(targetType)) { return expression; } @@ -39,7 +39,7 @@ class ValueHelper extends TypeHelper { if (targetType.isDartCoreObject && !targetType.isNullableType) { final question = defaultProvided ? '?' : ''; return '$expression as Object$question'; - } else if (targetType.isDartCoreObject || targetType.isDynamic) { + } else if (targetType.isDartCoreObject || targetType is DynamicType) { // just return it as-is. We'll hope it's safe. return expression; } else if (targetType.isDartCoreDouble) { diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index b81359fc4..8163247c1 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -207,7 +207,7 @@ String typeToCode( DartType type, { bool forceNullable = false, }) { - if (type.isDynamic) { + if (type is DynamicType) { return 'dynamic'; } else if (type is InterfaceType) { return [ diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index a80e4bc24..ac4be2a86 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,11 +1,11 @@ name: json_serializable -version: 6.6.2 +version: 6.7.0-dev description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. repository: https://github.com/google/json_serializable.dart/tree/master/json_serializable environment: - sdk: '>=2.19.0 <3.0.0' + sdk: ^3.0.0 topics: - json - build-runner @@ -13,7 +13,7 @@ topics: - codegen dependencies: - analyzer: ^5.2.0 + analyzer: ^5.12.0 async: ^2.8.0 build: ^2.0.0 build_config: '>=0.4.4 <2.0.0' @@ -26,7 +26,7 @@ dependencies: path: ^1.8.0 pub_semver: ^2.0.0 pubspec_parse: ^1.0.0 - source_gen: ^1.0.0 + source_gen: ^1.3.2 source_helper: ^1.3.0 dev_dependencies: diff --git a/json_serializable/test/config_test.dart b/json_serializable/test/config_test.dart index a8355f117..15767a319 100644 --- a/json_serializable/test/config_test.dart +++ b/json_serializable/test/config_test.dart @@ -118,24 +118,18 @@ void main() { config[entry.key] = entry.value; String lastLine; - switch (entry.key) { - case 'field_rename': - lastLine = - '`42` is not one of the supported values: none, kebab, snake, ' - 'pascal, screamingSnake'; - break; - case 'constructor': - lastLine = "type 'int' is not a subtype of type 'String?' in type " - 'cast'; - break; - case 'create_to_json': - lastLine = "type 'int' is not a subtype of type 'bool?' in type " - 'cast'; - break; - default: - lastLine = - "type 'int' is not a subtype of type 'bool?' in type cast"; - } + lastLine = switch (entry.key) { + 'field_rename' => + '`42` is not one of the supported values: none, kebab, snake, ' + 'pascal, screamingSnake', + 'constructor' => + "type 'int' is not a subtype of type 'String?' in type " + 'cast', + 'create_to_json' => + "type 'int' is not a subtype of type 'bool?' in type " + 'cast', + _ => "type 'int' is not a subtype of type 'bool?' in type cast" + }; final matcher = isA<StateError>().having( (v) => v.message, diff --git a/json_serializable/test/kitchen_sink/kitchen_sink_yaml_test.dart b/json_serializable/test/kitchen_sink/kitchen_sink_yaml_test.dart index f9a09b521..e1fcb1039 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink_yaml_test.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink_yaml_test.dart @@ -74,23 +74,14 @@ Matcher _getMatcher(bool checked, String? expectedKey, bool checkedAssignment) { ); if (checkedAssignment) { - switch (expectedKey) { - case 'validatedPropertyNo42': - innerMatcher = isStateError; - break; - case 'no-42': - innerMatcher = isArgumentError; - break; - case 'strictKeysObject': - innerMatcher = _isAUnrecognizedKeysException('bob'); - break; - case 'intIterable': - case 'datetime-iterable': - innerMatcher = isTypeError; - break; - default: - throw StateError('Not expected! - $expectedKey'); - } + innerMatcher = switch (expectedKey) { + 'validatedPropertyNo42' => isStateError, + 'no-42' => isArgumentError, + 'strictKeysObject' => _isAUnrecognizedKeysException('bob'), + 'intIterable' => isTypeError, + 'datetime-iterable' => isTypeError, + _ => throw StateError('Not expected! - $expectedKey') + }; } } diff --git a/json_serializable/tool/readme_builder.dart b/json_serializable/tool/readme_builder.dart index 76156a219..5de07dfe3 100644 --- a/json_serializable/tool/readme_builder.dart +++ b/json_serializable/tool/readme_builder.dart @@ -59,16 +59,11 @@ class _ReadmeBuilder extends Builder { final memberName = match.group(3); final linkContent = '[`$className${memberName ?? ''}`]'; String linkValue; - switch (context) { - case 'core': - linkValue = _coreTypeUri(className); - break; - case 'ja': - linkValue = jsonAnnotationUri(className, memberName?.substring(1)); - break; - default: - linkValue = 'https://unknown.com/$context/$className'; - } + linkValue = switch (context) { + 'core' => _coreTypeUri(className), + 'ja' => jsonAnnotationUri(className, memberName?.substring(1)), + _ => 'https://unknown.com/$context/$className' + }; foundClasses[linkContent] = linkValue; return linkContent; } From be8e9a34ecbcf696c3acbe8b4ce0fad7ef5a45d8 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Tue, 16 May 2023 11:23:53 -0700 Subject: [PATCH 490/569] Support Dart 3 Record types (#1314) Closes https://github.com/google/json_serializable.dart/issues/1222 --- json_serializable/CHANGELOG.md | 3 +- json_serializable/README.md | 7 +- json_serializable/build.yaml | 1 + json_serializable/lib/src/enum_utils.dart | 4 +- json_serializable/lib/src/helper_core.dart | 3 +- json_serializable/lib/src/json_key_utils.dart | 2 +- json_serializable/lib/src/settings.dart | 2 + .../lib/src/type_helpers/record_helper.dart | 124 ++ json_serializable/pubspec.yaml | 2 +- .../test/kitchen_sink/kitchen_sink.dart | 2 + .../test/kitchen_sink/kitchen_sink.g.dart | 23 +- .../kitchen_sink/kitchen_sink.g_any_map.dart | 2 + .../kitchen_sink.g_any_map.g.dart | 23 +- .../kitchen_sink.g_any_map__checked.dart | 2 + .../kitchen_sink.g_any_map__checked.g.dart | 23 + .../kitchen_sink.g_exclude_null.dart | 2 + .../kitchen_sink.g_exclude_null.g.dart | 25 +- .../kitchen_sink.g_explicit_to_json.dart | 2 + .../kitchen_sink.g_explicit_to_json.g.dart | 23 +- .../kitchen_sink/kitchen_sink_interface.dart | 11 +- .../test/kitchen_sink/kitchen_sink_test.dart | 6 +- .../kitchen_sink_test_shared.dart | 10 +- .../supported_types/input.type_record.dart | 861 ++++++++++++ .../supported_types/input.type_record.g.dart | 1221 +++++++++++++++++ json_serializable/tool/test_type_builder.dart | 17 +- json_serializable/tool/test_type_data.dart | 25 +- 26 files changed, 2400 insertions(+), 26 deletions(-) create mode 100644 json_serializable/lib/src/type_helpers/record_helper.dart create mode 100644 json_serializable/test/supported_types/input.type_record.dart create mode 100644 json_serializable/test/supported_types/input.type_record.g.dart diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 93ca8f831..0effefc60 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,5 +1,6 @@ -## 6.7.0-dev +## 6.7.0 +- Support `Record` types. - Require Dart 3.0 - Require `analyzer: ^5.12.0` diff --git a/json_serializable/README.md b/json_serializable/README.md index 4f1d53fe5..5e7498540 100644 --- a/json_serializable/README.md +++ b/json_serializable/README.md @@ -152,11 +152,11 @@ Out of the box, `json_serializable` supports many common types in the [dart:core](https://api.dart.dev/stable/dart-core/dart-core-library.html) library: [`BigInt`], [`bool`], [`DateTime`], [`double`], [`Duration`], [`Enum`], [`int`], -[`Iterable`], [`List`], [`Map`], [`num`], [`Object`], [`Set`], [`String`], -[`Uri`] +[`Iterable`], [`List`], [`Map`], [`num`], [`Object`], [`Record`], [`Set`], +[`String`], [`Uri`] The collection types – -[`Iterable`], [`List`], [`Map`], [`Set`] +[`Iterable`], [`List`], [`Map`], [`Record`], [`Set`] – can contain values of all the above types. For [`Map`], the key value must be one of @@ -313,6 +313,7 @@ targets: [`Map`]: https://api.dart.dev/stable/dart-core/Map-class.html [`num`]: https://api.dart.dev/stable/dart-core/num-class.html [`Object`]: https://api.dart.dev/stable/dart-core/Object-class.html +[`Record`]: https://api.dart.dev/stable/dart-core/Record-class.html [`Set`]: https://api.dart.dev/stable/dart-core/Set-class.html [`String`]: https://api.dart.dev/stable/dart-core/String-class.html [`Uri`]: https://api.dart.dev/stable/dart-core/Uri-class.html diff --git a/json_serializable/build.yaml b/json_serializable/build.yaml index 66f56a880..fb0052e74 100644 --- a/json_serializable/build.yaml +++ b/json_serializable/build.yaml @@ -71,6 +71,7 @@ builders: - .type_map.dart - .type_num.dart - .type_object.dart + - .type_record.dart - .type_set.dart - .type_string.dart - .type_uri.dart diff --git a/json_serializable/lib/src/enum_utils.dart b/json_serializable/lib/src/enum_utils.dart index 467d47161..d5aa4d2d2 100644 --- a/json_serializable/lib/src/enum_utils.dart +++ b/json_serializable/lib/src/enum_utils.dart @@ -52,7 +52,9 @@ Map<FieldElement, Object?>? _enumMap( DartType targetType, { bool nullWithNoAnnotation = false, }) { - final annotation = _jsonEnumChecker.firstAnnotationOf(targetType.element!); + final targetTypeElement = targetType.element; + if (targetTypeElement == null) return null; + final annotation = _jsonEnumChecker.firstAnnotationOf(targetTypeElement); final jsonEnum = _fromAnnotation(annotation); final enumFields = iterateEnumFields(targetType); diff --git a/json_serializable/lib/src/helper_core.dart b/json_serializable/lib/src/helper_core.dart index 3e6d6b88d..5a8248c66 100644 --- a/json_serializable/lib/src/helper_core.dart +++ b/json_serializable/lib/src/helper_core.dart @@ -77,8 +77,9 @@ $converterOrKeyInstructions } else if (field.type != error.type) { message = '$message because of type `${typeToCode(error.type)}`'; } else { + final element = error.type.element?.name; todo = ''' -To support the type `${error.type.element!.name}` you can: +To support the type `${element ?? error.type}` you can: $converterOrKeyInstructions'''; } diff --git a/json_serializable/lib/src/json_key_utils.dart b/json_serializable/lib/src/json_key_utils.dart index 8ba78229d..42eb0cfce 100644 --- a/json_serializable/lib/src/json_key_utils.dart +++ b/json_serializable/lib/src/json_key_utils.dart @@ -64,7 +64,7 @@ KeyConfig _from(FieldElement element, ClassConfig classAnnotation) { // literal, which is NOT supported! badType = 'Function'; } else if (!reader.isLiteral) { - badType = dartObject.type!.element!.name; + badType = dartObject.type!.element?.name; } if (badType != null) { diff --git a/json_serializable/lib/src/settings.dart b/json_serializable/lib/src/settings.dart index c73df1b7b..62d35a93c 100644 --- a/json_serializable/lib/src/settings.dart +++ b/json_serializable/lib/src/settings.dart @@ -16,6 +16,7 @@ import 'type_helpers/iterable_helper.dart'; import 'type_helpers/json_converter_helper.dart'; import 'type_helpers/json_helper.dart'; import 'type_helpers/map_helper.dart'; +import 'type_helpers/record_helper.dart'; import 'type_helpers/uri_helper.dart'; import 'type_helpers/value_helper.dart'; @@ -24,6 +25,7 @@ class Settings { IterableHelper(), MapHelper(), EnumHelper(), + RecordHelper(), ValueHelper(), ]; diff --git a/json_serializable/lib/src/type_helpers/record_helper.dart b/json_serializable/lib/src/type_helpers/record_helper.dart new file mode 100644 index 000000000..f086948bf --- /dev/null +++ b/json_serializable/lib/src/type_helpers/record_helper.dart @@ -0,0 +1,124 @@ +import 'package:analyzer/dart/element/type.dart'; +import 'package:source_helper/source_helper.dart'; + +import '../type_helper.dart'; +import '../utils.dart'; + +class RecordHelper extends TypeHelper<TypeHelperContextWithConfig> { + const RecordHelper(); + + @override + Object? deserialize( + DartType targetType, + String expression, + TypeHelperContextWithConfig context, + bool defaultProvided, + ) { + if (targetType is! RecordType) return null; + + final items = <Object>[]; + + const paramName = r'$jsonValue'; + + var index = 1; + for (var field in targetType.positionalFields) { + final indexer = escapeDartString('\$$index'); + items.add( + context.deserialize(field.type, '$paramName[$indexer]')!, + ); + index++; + } + for (var field in targetType.namedFields) { + final indexer = escapeDartString(field.name); + items.add( + '${field.name}:' + '${context.deserialize(field.type, '$paramName[$indexer]')!}', + ); + } + + if (items.isEmpty) { + return '()'; + } + + context.addMember( + _recordConvertImpl( + nullable: targetType.isNullableType, anyMap: context.config.anyMap), + ); + + final recordLiteral = '(${items.map((e) => '$e,').join()})'; + + final helperName = _recordConvertName( + nullable: targetType.isNullableType, + anyMap: context.config.anyMap, + ); + + return ''' +$helperName( + $expression, + ($paramName) => $recordLiteral, +)'''; + } + + @override + Object? serialize( + DartType targetType, + String expression, + TypeHelperContextWithConfig context, + ) { + if (targetType is! RecordType) return null; + + final maybeBang = targetType.isNullableType ? '!' : ''; + + final items = <Object>[]; + + var index = 1; + for (var field in targetType.positionalFields) { + final indexer = escapeDartString('\$$index'); + items.add( + '$indexer:' + '${context.serialize(field.type, '$expression$maybeBang.\$$index')!}', + ); + index++; + } + for (var field in targetType.namedFields) { + final indexer = escapeDartString(field.name); + items.add( + '$indexer:${context.serialize( + field.type, + '$expression$maybeBang.${field.name}', + )!}', + ); + } + + final mapValue = '{${items.map((e) => '$e,').join()}}'; + + return targetType.isNullableType + ? ifNullOrElse( + expression, + 'null', + mapValue, + ) + : mapValue; + } +} + +String _recordConvertName({required bool nullable, required bool anyMap}) => + '_\$recordConvert${anyMap ? 'Any' : ''}${nullable ? 'Nullable' : ''}'; + +String _recordConvertImpl({required bool nullable, required bool anyMap}) { + final name = _recordConvertName(nullable: nullable, anyMap: anyMap); + + var expression = + 'convert(value as ${anyMap ? 'Map' : 'Map<String, dynamic>'})'; + if (nullable) { + expression = ifNullOrElse('value', 'null', expression); + } + + return ''' +\$Rec${nullable ? '?' : ''} $name<\$Rec>( + Object? value, + \$Rec Function(Map) convert, +) => + $expression; +'''; +} diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index ac4be2a86..d64039063 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 6.7.0-dev +version: 6.7.0 description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.dart b/json_serializable/test/kitchen_sink/kitchen_sink.dart index e194dbfbc..b0ff20f00 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.dart @@ -184,6 +184,8 @@ class KitchenSink implements k.KitchenSink { _validatedPropertyNo42 = value; } + k.RecordSample? recordField; + bool operator ==(Object other) => k.sinkEquals(this, other); static Object? _trickyValueAccessor(Map json, String key) { diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g.dart index c795c6c13..1396ff044 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g.dart @@ -85,7 +85,15 @@ KitchenSink _$KitchenSinkFromJson(Map<String, dynamic> json) => KitchenSink( SimpleObject.fromJson(json['simpleObject'] as Map<String, dynamic>) ..strictKeysObject = StrictKeysObject.fromJson( json['strictKeysObject'] as Map<String, dynamic>) - ..validatedPropertyNo42 = json['validatedPropertyNo42'] as int?; + ..validatedPropertyNo42 = json['validatedPropertyNo42'] as int? + ..recordField = _$recordConvertNullable( + json['recordField'], + ($jsonValue) => ( + $jsonValue[r'$1'] as int, + $jsonValue[r'$2'] as String, + truth: $jsonValue['truth'] as bool, + ), + ); Map<String, dynamic> _$KitchenSinkToJson(KitchenSink instance) => <String, dynamic>{ @@ -132,8 +140,21 @@ Map<String, dynamic> _$KitchenSinkToJson(KitchenSink instance) => 'simpleObject': instance.simpleObject, 'strictKeysObject': instance.strictKeysObject, 'validatedPropertyNo42': instance.validatedPropertyNo42, + 'recordField': instance.recordField == null + ? null + : { + r'$1': instance.recordField!.$1, + r'$2': instance.recordField!.$2, + 'truth': instance.recordField!.truth, + }, }; +$Rec? _$recordConvertNullable<$Rec>( + Object? value, + $Rec Function(Map) convert, +) => + value == null ? null : convert(value as Map<String, dynamic>); + JsonConverterTestClass _$JsonConverterTestClassFromJson( Map<String, dynamic> json) => JsonConverterTestClass( diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart index cd0abae63..6f8b5c69f 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart @@ -184,6 +184,8 @@ class KitchenSink implements k.KitchenSink { _validatedPropertyNo42 = value; } + k.RecordSample? recordField; + bool operator ==(Object other) => k.sinkEquals(this, other); static Object? _trickyValueAccessor(Map json, String key) { diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart index ce7520a1e..6cfb749ea 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart @@ -77,7 +77,15 @@ KitchenSink _$KitchenSinkFromJson(Map json) => KitchenSink( ..simpleObject = SimpleObject.fromJson(json['simpleObject'] as Map) ..strictKeysObject = StrictKeysObject.fromJson(json['strictKeysObject'] as Map) - ..validatedPropertyNo42 = json['validatedPropertyNo42'] as int?; + ..validatedPropertyNo42 = json['validatedPropertyNo42'] as int? + ..recordField = _$recordConvertAnyNullable( + json['recordField'], + ($jsonValue) => ( + $jsonValue[r'$1'] as int, + $jsonValue[r'$2'] as String, + truth: $jsonValue['truth'] as bool, + ), + ); Map<String, dynamic> _$KitchenSinkToJson(KitchenSink instance) => <String, dynamic>{ @@ -124,8 +132,21 @@ Map<String, dynamic> _$KitchenSinkToJson(KitchenSink instance) => 'simpleObject': instance.simpleObject, 'strictKeysObject': instance.strictKeysObject, 'validatedPropertyNo42': instance.validatedPropertyNo42, + 'recordField': instance.recordField == null + ? null + : { + r'$1': instance.recordField!.$1, + r'$2': instance.recordField!.$2, + 'truth': instance.recordField!.truth, + }, }; +$Rec? _$recordConvertAnyNullable<$Rec>( + Object? value, + $Rec Function(Map) convert, +) => + value == null ? null : convert(value as Map); + JsonConverterTestClass _$JsonConverterTestClassFromJson(Map json) => JsonConverterTestClass( const DurationMillisecondConverter().fromJson(json['duration'] as int?), diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.dart index b01ef3341..fe5bcbba7 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.dart @@ -185,6 +185,8 @@ class KitchenSink implements k.KitchenSink { _validatedPropertyNo42 = value; } + k.RecordSample? recordField; + bool operator ==(Object other) => k.sinkEquals(this, other); static Object? _trickyValueAccessor(Map json, String key) { diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.g.dart index a9e48d1a6..02fc36586 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.g.dart @@ -121,6 +121,16 @@ KitchenSink _$KitchenSinkFromJson(Map json) => $checkedCreate( (v) => val.strictKeysObject = StrictKeysObject.fromJson(v as Map)); $checkedConvert('validatedPropertyNo42', (v) => val.validatedPropertyNo42 = v as int?); + $checkedConvert( + 'recordField', + (v) => val.recordField = _$recordConvertAnyNullable( + v, + ($jsonValue) => ( + $jsonValue[r'$1'] as int, + $jsonValue[r'$2'] as String, + truth: $jsonValue['truth'] as bool, + ), + )); return val; }, fieldKeyMap: const { @@ -175,8 +185,21 @@ Map<String, dynamic> _$KitchenSinkToJson(KitchenSink instance) => 'simpleObject': instance.simpleObject, 'strictKeysObject': instance.strictKeysObject, 'validatedPropertyNo42': instance.validatedPropertyNo42, + 'recordField': instance.recordField == null + ? null + : { + r'$1': instance.recordField!.$1, + r'$2': instance.recordField!.$2, + 'truth': instance.recordField!.truth, + }, }; +$Rec? _$recordConvertAnyNullable<$Rec>( + Object? value, + $Rec Function(Map) convert, +) => + value == null ? null : convert(value as Map); + JsonConverterTestClass _$JsonConverterTestClassFromJson(Map json) => $checkedCreate( 'JsonConverterTestClass', diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.dart index 46b2ea3b7..9476908a6 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.dart @@ -186,6 +186,8 @@ class KitchenSink implements k.KitchenSink { _validatedPropertyNo42 = value; } + k.RecordSample? recordField; + bool operator ==(Object other) => k.sinkEquals(this, other); static Object? _trickyValueAccessor(Map json, String key) { diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart index d69950e1b..e9f8662ad 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart @@ -85,7 +85,15 @@ KitchenSink _$KitchenSinkFromJson(Map<String, dynamic> json) => KitchenSink( SimpleObject.fromJson(json['simpleObject'] as Map<String, dynamic>) ..strictKeysObject = StrictKeysObject.fromJson( json['strictKeysObject'] as Map<String, dynamic>) - ..validatedPropertyNo42 = json['validatedPropertyNo42'] as int?; + ..validatedPropertyNo42 = json['validatedPropertyNo42'] as int? + ..recordField = _$recordConvertNullable( + json['recordField'], + ($jsonValue) => ( + $jsonValue[r'$1'] as int, + $jsonValue[r'$2'] as String, + truth: $jsonValue['truth'] as bool, + ), + ); Map<String, dynamic> _$KitchenSinkToJson(KitchenSink instance) { final val = <String, dynamic>{}; @@ -139,9 +147,24 @@ Map<String, dynamic> _$KitchenSinkToJson(KitchenSink instance) { val['simpleObject'] = instance.simpleObject; val['strictKeysObject'] = instance.strictKeysObject; writeNotNull('validatedPropertyNo42', instance.validatedPropertyNo42); + writeNotNull( + 'recordField', + instance.recordField == null + ? null + : { + r'$1': instance.recordField!.$1, + r'$2': instance.recordField!.$2, + 'truth': instance.recordField!.truth, + }); return val; } +$Rec? _$recordConvertNullable<$Rec>( + Object? value, + $Rec Function(Map) convert, +) => + value == null ? null : convert(value as Map<String, dynamic>); + JsonConverterTestClass _$JsonConverterTestClassFromJson( Map<String, dynamic> json) => JsonConverterTestClass( diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.dart index 02bd2a683..48afb79fc 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.dart @@ -186,6 +186,8 @@ class KitchenSink implements k.KitchenSink { _validatedPropertyNo42 = value; } + k.RecordSample? recordField; + bool operator ==(Object other) => k.sinkEquals(this, other); static Object? _trickyValueAccessor(Map json, String key) { diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart index a38b42bf0..24101a1b6 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart @@ -85,7 +85,15 @@ KitchenSink _$KitchenSinkFromJson(Map<String, dynamic> json) => KitchenSink( SimpleObject.fromJson(json['simpleObject'] as Map<String, dynamic>) ..strictKeysObject = StrictKeysObject.fromJson( json['strictKeysObject'] as Map<String, dynamic>) - ..validatedPropertyNo42 = json['validatedPropertyNo42'] as int?; + ..validatedPropertyNo42 = json['validatedPropertyNo42'] as int? + ..recordField = _$recordConvertNullable( + json['recordField'], + ($jsonValue) => ( + $jsonValue[r'$1'] as int, + $jsonValue[r'$2'] as String, + truth: $jsonValue['truth'] as bool, + ), + ); Map<String, dynamic> _$KitchenSinkToJson(KitchenSink instance) => <String, dynamic>{ @@ -134,8 +142,21 @@ Map<String, dynamic> _$KitchenSinkToJson(KitchenSink instance) => 'simpleObject': instance.simpleObject.toJson(), 'strictKeysObject': instance.strictKeysObject.toJson(), 'validatedPropertyNo42': instance.validatedPropertyNo42, + 'recordField': instance.recordField == null + ? null + : { + r'$1': instance.recordField!.$1, + r'$2': instance.recordField!.$2, + 'truth': instance.recordField!.truth, + }, }; +$Rec? _$recordConvertNullable<$Rec>( + Object? value, + $Rec Function(Map) convert, +) => + value == null ? null : convert(value as Map<String, dynamic>); + JsonConverterTestClass _$JsonConverterTestClassFromJson( Map<String, dynamic> json) => JsonConverterTestClass( diff --git a/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart b/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart index 9f8740943..57673b70f 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart @@ -120,9 +120,17 @@ abstract class KitchenSink { int? validatedPropertyNo42; + RecordSample? recordField; + Map<String, dynamic> toJson(); } +typedef RecordSample = ( + int, + String, { + bool truth, +}); + // TODO: finish this... bool sinkEquals(KitchenSink a, Object other) => other is KitchenSink && @@ -145,4 +153,5 @@ bool sinkEquals(KitchenSink a, Object other) => deepEquals(a.crazyComplex, other.crazyComplex) && // val a.writeNotNull == other.writeNotNull && - a.string == other.string; + a.string == other.string && + a.recordField == other.recordField; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink_test.dart b/json_serializable/test/kitchen_sink/kitchen_sink_test.dart index 67e68400a..f3519050b 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink_test.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink_test.dart @@ -294,7 +294,11 @@ const _nonNullableFields = { 'strictKeysObject' }; -const _encodedAsMapKeys = {'simpleObject', 'strictKeysObject'}; +const _encodedAsMapKeys = { + 'simpleObject', + 'strictKeysObject', + 'recordField', +}; const _iterableMapKeys = { 'bigIntMap', diff --git a/json_serializable/test/kitchen_sink/kitchen_sink_test_shared.dart b/json_serializable/test/kitchen_sink/kitchen_sink_test_shared.dart index 7bf34f035..fc235bc05 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink_test_shared.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink_test_shared.dart @@ -40,7 +40,12 @@ const validValues = <String, dynamic>{ trickyKeyName: 'string', 'simpleObject': {'value': 42}, 'strictKeysObject': {'value': 10, 'custom_field': 'cool'}, - 'validatedPropertyNo42': 0 + 'validatedPropertyNo42': 0, + 'recordField': { + '\$1': 0, + '\$2': 'string', + 'truth': true, + }, }; const invalidValueTypes = { @@ -77,7 +82,8 @@ const invalidValueTypes = { 'value': 10, 'invalid_key': true, }, - 'validatedPropertyNo42': true + 'validatedPropertyNo42': true, + 'recordField': true, }; const disallowNullKeys = { diff --git a/json_serializable/test/supported_types/input.type_record.dart b/json_serializable/test/supported_types/input.type_record.dart new file mode 100644 index 000000000..0f226fed3 --- /dev/null +++ b/json_serializable/test/supported_types/input.type_record.dart @@ -0,0 +1,861 @@ +// Copyright (c) 2020, 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:json_annotation/json_annotation.dart'; +import 'enum_type.dart'; + +part 'input.type_record.g.dart'; + +typedef RecordTypeDef = (); + +@JsonSerializable() +class SimpleClass { + final RecordTypeDef value; + + SimpleClass( + this.value, + ); + + factory SimpleClass.fromJson(Map<String, Object?> json) => + _$SimpleClassFromJson(json); + + Map<String, Object?> toJson() => _$SimpleClassToJson(this); +} + +@JsonSerializable() +class SimpleClassNullable { + final RecordTypeDef? value; + + SimpleClassNullable( + this.value, + ); + + factory SimpleClassNullable.fromJson(Map<String, Object?> json) => + _$SimpleClassNullableFromJson(json); + + Map<String, Object?> toJson() => _$SimpleClassNullableToJson(this); +} + +typedef SimpleClassOfBigIntTypeDef = (BigInt, {BigInt named}); + +@JsonSerializable() +class SimpleClassOfBigInt { + final SimpleClassOfBigIntTypeDef value; + + SimpleClassOfBigInt( + this.value, + ); + + factory SimpleClassOfBigInt.fromJson(Map<String, Object?> json) => + _$SimpleClassOfBigIntFromJson(json); + + Map<String, Object?> toJson() => _$SimpleClassOfBigIntToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfBigInt { + final SimpleClassOfBigIntTypeDef? value; + + SimpleClassNullableOfBigInt( + this.value, + ); + + factory SimpleClassNullableOfBigInt.fromJson(Map<String, Object?> json) => + _$SimpleClassNullableOfBigIntFromJson(json); + + Map<String, Object?> toJson() => _$SimpleClassNullableOfBigIntToJson(this); +} + +typedef SimpleClassOfBigIntNullableTypeDef = (BigInt?, {BigInt? named}); + +@JsonSerializable() +class SimpleClassOfBigIntNullable { + final SimpleClassOfBigIntNullableTypeDef value; + + SimpleClassOfBigIntNullable( + this.value, + ); + + factory SimpleClassOfBigIntNullable.fromJson(Map<String, Object?> json) => + _$SimpleClassOfBigIntNullableFromJson(json); + + Map<String, Object?> toJson() => _$SimpleClassOfBigIntNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfBigIntNullable { + final SimpleClassOfBigIntNullableTypeDef? value; + + SimpleClassNullableOfBigIntNullable( + this.value, + ); + + factory SimpleClassNullableOfBigIntNullable.fromJson( + Map<String, Object?> json) => + _$SimpleClassNullableOfBigIntNullableFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassNullableOfBigIntNullableToJson(this); +} + +typedef SimpleClassOfBoolTypeDef = (bool, {bool named}); + +@JsonSerializable() +class SimpleClassOfBool { + final SimpleClassOfBoolTypeDef value; + + SimpleClassOfBool( + this.value, + ); + + factory SimpleClassOfBool.fromJson(Map<String, Object?> json) => + _$SimpleClassOfBoolFromJson(json); + + Map<String, Object?> toJson() => _$SimpleClassOfBoolToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfBool { + final SimpleClassOfBoolTypeDef? value; + + SimpleClassNullableOfBool( + this.value, + ); + + factory SimpleClassNullableOfBool.fromJson(Map<String, Object?> json) => + _$SimpleClassNullableOfBoolFromJson(json); + + Map<String, Object?> toJson() => _$SimpleClassNullableOfBoolToJson(this); +} + +typedef SimpleClassOfBoolNullableTypeDef = (bool?, {bool? named}); + +@JsonSerializable() +class SimpleClassOfBoolNullable { + final SimpleClassOfBoolNullableTypeDef value; + + SimpleClassOfBoolNullable( + this.value, + ); + + factory SimpleClassOfBoolNullable.fromJson(Map<String, Object?> json) => + _$SimpleClassOfBoolNullableFromJson(json); + + Map<String, Object?> toJson() => _$SimpleClassOfBoolNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfBoolNullable { + final SimpleClassOfBoolNullableTypeDef? value; + + SimpleClassNullableOfBoolNullable( + this.value, + ); + + factory SimpleClassNullableOfBoolNullable.fromJson( + Map<String, Object?> json) => + _$SimpleClassNullableOfBoolNullableFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassNullableOfBoolNullableToJson(this); +} + +typedef SimpleClassOfDateTimeTypeDef = (DateTime, {DateTime named}); + +@JsonSerializable() +class SimpleClassOfDateTime { + final SimpleClassOfDateTimeTypeDef value; + + SimpleClassOfDateTime( + this.value, + ); + + factory SimpleClassOfDateTime.fromJson(Map<String, Object?> json) => + _$SimpleClassOfDateTimeFromJson(json); + + Map<String, Object?> toJson() => _$SimpleClassOfDateTimeToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfDateTime { + final SimpleClassOfDateTimeTypeDef? value; + + SimpleClassNullableOfDateTime( + this.value, + ); + + factory SimpleClassNullableOfDateTime.fromJson(Map<String, Object?> json) => + _$SimpleClassNullableOfDateTimeFromJson(json); + + Map<String, Object?> toJson() => _$SimpleClassNullableOfDateTimeToJson(this); +} + +typedef SimpleClassOfDateTimeNullableTypeDef = (DateTime?, {DateTime? named}); + +@JsonSerializable() +class SimpleClassOfDateTimeNullable { + final SimpleClassOfDateTimeNullableTypeDef value; + + SimpleClassOfDateTimeNullable( + this.value, + ); + + factory SimpleClassOfDateTimeNullable.fromJson(Map<String, Object?> json) => + _$SimpleClassOfDateTimeNullableFromJson(json); + + Map<String, Object?> toJson() => _$SimpleClassOfDateTimeNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfDateTimeNullable { + final SimpleClassOfDateTimeNullableTypeDef? value; + + SimpleClassNullableOfDateTimeNullable( + this.value, + ); + + factory SimpleClassNullableOfDateTimeNullable.fromJson( + Map<String, Object?> json) => + _$SimpleClassNullableOfDateTimeNullableFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassNullableOfDateTimeNullableToJson(this); +} + +typedef SimpleClassOfDoubleTypeDef = (double, {double named}); + +@JsonSerializable() +class SimpleClassOfDouble { + final SimpleClassOfDoubleTypeDef value; + + SimpleClassOfDouble( + this.value, + ); + + factory SimpleClassOfDouble.fromJson(Map<String, Object?> json) => + _$SimpleClassOfDoubleFromJson(json); + + Map<String, Object?> toJson() => _$SimpleClassOfDoubleToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfDouble { + final SimpleClassOfDoubleTypeDef? value; + + SimpleClassNullableOfDouble( + this.value, + ); + + factory SimpleClassNullableOfDouble.fromJson(Map<String, Object?> json) => + _$SimpleClassNullableOfDoubleFromJson(json); + + Map<String, Object?> toJson() => _$SimpleClassNullableOfDoubleToJson(this); +} + +typedef SimpleClassOfDoubleNullableTypeDef = (double?, {double? named}); + +@JsonSerializable() +class SimpleClassOfDoubleNullable { + final SimpleClassOfDoubleNullableTypeDef value; + + SimpleClassOfDoubleNullable( + this.value, + ); + + factory SimpleClassOfDoubleNullable.fromJson(Map<String, Object?> json) => + _$SimpleClassOfDoubleNullableFromJson(json); + + Map<String, Object?> toJson() => _$SimpleClassOfDoubleNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfDoubleNullable { + final SimpleClassOfDoubleNullableTypeDef? value; + + SimpleClassNullableOfDoubleNullable( + this.value, + ); + + factory SimpleClassNullableOfDoubleNullable.fromJson( + Map<String, Object?> json) => + _$SimpleClassNullableOfDoubleNullableFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassNullableOfDoubleNullableToJson(this); +} + +typedef SimpleClassOfDurationTypeDef = (Duration, {Duration named}); + +@JsonSerializable() +class SimpleClassOfDuration { + final SimpleClassOfDurationTypeDef value; + + SimpleClassOfDuration( + this.value, + ); + + factory SimpleClassOfDuration.fromJson(Map<String, Object?> json) => + _$SimpleClassOfDurationFromJson(json); + + Map<String, Object?> toJson() => _$SimpleClassOfDurationToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfDuration { + final SimpleClassOfDurationTypeDef? value; + + SimpleClassNullableOfDuration( + this.value, + ); + + factory SimpleClassNullableOfDuration.fromJson(Map<String, Object?> json) => + _$SimpleClassNullableOfDurationFromJson(json); + + Map<String, Object?> toJson() => _$SimpleClassNullableOfDurationToJson(this); +} + +typedef SimpleClassOfDurationNullableTypeDef = (Duration?, {Duration? named}); + +@JsonSerializable() +class SimpleClassOfDurationNullable { + final SimpleClassOfDurationNullableTypeDef value; + + SimpleClassOfDurationNullable( + this.value, + ); + + factory SimpleClassOfDurationNullable.fromJson(Map<String, Object?> json) => + _$SimpleClassOfDurationNullableFromJson(json); + + Map<String, Object?> toJson() => _$SimpleClassOfDurationNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfDurationNullable { + final SimpleClassOfDurationNullableTypeDef? value; + + SimpleClassNullableOfDurationNullable( + this.value, + ); + + factory SimpleClassNullableOfDurationNullable.fromJson( + Map<String, Object?> json) => + _$SimpleClassNullableOfDurationNullableFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassNullableOfDurationNullableToJson(this); +} + +typedef SimpleClassOfDynamicTypeDef = (dynamic, {dynamic named}); + +@JsonSerializable() +class SimpleClassOfDynamic { + final SimpleClassOfDynamicTypeDef value; + + SimpleClassOfDynamic( + this.value, + ); + + factory SimpleClassOfDynamic.fromJson(Map<String, Object?> json) => + _$SimpleClassOfDynamicFromJson(json); + + Map<String, Object?> toJson() => _$SimpleClassOfDynamicToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfDynamic { + final SimpleClassOfDynamicTypeDef? value; + + SimpleClassNullableOfDynamic( + this.value, + ); + + factory SimpleClassNullableOfDynamic.fromJson(Map<String, Object?> json) => + _$SimpleClassNullableOfDynamicFromJson(json); + + Map<String, Object?> toJson() => _$SimpleClassNullableOfDynamicToJson(this); +} + +typedef SimpleClassOfEnumTypeTypeDef = (EnumType, {EnumType named}); + +@JsonSerializable() +class SimpleClassOfEnumType { + final SimpleClassOfEnumTypeTypeDef value; + + SimpleClassOfEnumType( + this.value, + ); + + factory SimpleClassOfEnumType.fromJson(Map<String, Object?> json) => + _$SimpleClassOfEnumTypeFromJson(json); + + Map<String, Object?> toJson() => _$SimpleClassOfEnumTypeToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfEnumType { + final SimpleClassOfEnumTypeTypeDef? value; + + SimpleClassNullableOfEnumType( + this.value, + ); + + factory SimpleClassNullableOfEnumType.fromJson(Map<String, Object?> json) => + _$SimpleClassNullableOfEnumTypeFromJson(json); + + Map<String, Object?> toJson() => _$SimpleClassNullableOfEnumTypeToJson(this); +} + +typedef SimpleClassOfEnumTypeNullableTypeDef = (EnumType?, {EnumType? named}); + +@JsonSerializable() +class SimpleClassOfEnumTypeNullable { + final SimpleClassOfEnumTypeNullableTypeDef value; + + SimpleClassOfEnumTypeNullable( + this.value, + ); + + factory SimpleClassOfEnumTypeNullable.fromJson(Map<String, Object?> json) => + _$SimpleClassOfEnumTypeNullableFromJson(json); + + Map<String, Object?> toJson() => _$SimpleClassOfEnumTypeNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfEnumTypeNullable { + final SimpleClassOfEnumTypeNullableTypeDef? value; + + SimpleClassNullableOfEnumTypeNullable( + this.value, + ); + + factory SimpleClassNullableOfEnumTypeNullable.fromJson( + Map<String, Object?> json) => + _$SimpleClassNullableOfEnumTypeNullableFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassNullableOfEnumTypeNullableToJson(this); +} + +typedef SimpleClassOfFromJsonDynamicParamTypeDef = ( + FromJsonDynamicParam, { + FromJsonDynamicParam named +}); + +@JsonSerializable() +class SimpleClassOfFromJsonDynamicParam { + final SimpleClassOfFromJsonDynamicParamTypeDef value; + + SimpleClassOfFromJsonDynamicParam( + this.value, + ); + + factory SimpleClassOfFromJsonDynamicParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassOfFromJsonDynamicParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassOfFromJsonDynamicParamToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfFromJsonDynamicParam { + final SimpleClassOfFromJsonDynamicParamTypeDef? value; + + SimpleClassNullableOfFromJsonDynamicParam( + this.value, + ); + + factory SimpleClassNullableOfFromJsonDynamicParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassNullableOfFromJsonDynamicParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassNullableOfFromJsonDynamicParamToJson(this); +} + +typedef SimpleClassOfFromJsonNullableObjectParamTypeDef = ( + FromJsonNullableObjectParam, { + FromJsonNullableObjectParam named +}); + +@JsonSerializable() +class SimpleClassOfFromJsonNullableObjectParam { + final SimpleClassOfFromJsonNullableObjectParamTypeDef value; + + SimpleClassOfFromJsonNullableObjectParam( + this.value, + ); + + factory SimpleClassOfFromJsonNullableObjectParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassOfFromJsonNullableObjectParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassOfFromJsonNullableObjectParamToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfFromJsonNullableObjectParam { + final SimpleClassOfFromJsonNullableObjectParamTypeDef? value; + + SimpleClassNullableOfFromJsonNullableObjectParam( + this.value, + ); + + factory SimpleClassNullableOfFromJsonNullableObjectParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassNullableOfFromJsonNullableObjectParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassNullableOfFromJsonNullableObjectParamToJson(this); +} + +typedef SimpleClassOfFromJsonObjectParamTypeDef = ( + FromJsonObjectParam, { + FromJsonObjectParam named +}); + +@JsonSerializable() +class SimpleClassOfFromJsonObjectParam { + final SimpleClassOfFromJsonObjectParamTypeDef value; + + SimpleClassOfFromJsonObjectParam( + this.value, + ); + + factory SimpleClassOfFromJsonObjectParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassOfFromJsonObjectParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassOfFromJsonObjectParamToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfFromJsonObjectParam { + final SimpleClassOfFromJsonObjectParamTypeDef? value; + + SimpleClassNullableOfFromJsonObjectParam( + this.value, + ); + + factory SimpleClassNullableOfFromJsonObjectParam.fromJson( + Map<String, Object?> json) => + _$SimpleClassNullableOfFromJsonObjectParamFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassNullableOfFromJsonObjectParamToJson(this); +} + +typedef SimpleClassOfIntTypeDef = (int, {int named}); + +@JsonSerializable() +class SimpleClassOfInt { + final SimpleClassOfIntTypeDef value; + + SimpleClassOfInt( + this.value, + ); + + factory SimpleClassOfInt.fromJson(Map<String, Object?> json) => + _$SimpleClassOfIntFromJson(json); + + Map<String, Object?> toJson() => _$SimpleClassOfIntToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfInt { + final SimpleClassOfIntTypeDef? value; + + SimpleClassNullableOfInt( + this.value, + ); + + factory SimpleClassNullableOfInt.fromJson(Map<String, Object?> json) => + _$SimpleClassNullableOfIntFromJson(json); + + Map<String, Object?> toJson() => _$SimpleClassNullableOfIntToJson(this); +} + +typedef SimpleClassOfIntNullableTypeDef = (int?, {int? named}); + +@JsonSerializable() +class SimpleClassOfIntNullable { + final SimpleClassOfIntNullableTypeDef value; + + SimpleClassOfIntNullable( + this.value, + ); + + factory SimpleClassOfIntNullable.fromJson(Map<String, Object?> json) => + _$SimpleClassOfIntNullableFromJson(json); + + Map<String, Object?> toJson() => _$SimpleClassOfIntNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfIntNullable { + final SimpleClassOfIntNullableTypeDef? value; + + SimpleClassNullableOfIntNullable( + this.value, + ); + + factory SimpleClassNullableOfIntNullable.fromJson( + Map<String, Object?> json) => + _$SimpleClassNullableOfIntNullableFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassNullableOfIntNullableToJson(this); +} + +typedef SimpleClassOfNumTypeDef = (num, {num named}); + +@JsonSerializable() +class SimpleClassOfNum { + final SimpleClassOfNumTypeDef value; + + SimpleClassOfNum( + this.value, + ); + + factory SimpleClassOfNum.fromJson(Map<String, Object?> json) => + _$SimpleClassOfNumFromJson(json); + + Map<String, Object?> toJson() => _$SimpleClassOfNumToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfNum { + final SimpleClassOfNumTypeDef? value; + + SimpleClassNullableOfNum( + this.value, + ); + + factory SimpleClassNullableOfNum.fromJson(Map<String, Object?> json) => + _$SimpleClassNullableOfNumFromJson(json); + + Map<String, Object?> toJson() => _$SimpleClassNullableOfNumToJson(this); +} + +typedef SimpleClassOfNumNullableTypeDef = (num?, {num? named}); + +@JsonSerializable() +class SimpleClassOfNumNullable { + final SimpleClassOfNumNullableTypeDef value; + + SimpleClassOfNumNullable( + this.value, + ); + + factory SimpleClassOfNumNullable.fromJson(Map<String, Object?> json) => + _$SimpleClassOfNumNullableFromJson(json); + + Map<String, Object?> toJson() => _$SimpleClassOfNumNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfNumNullable { + final SimpleClassOfNumNullableTypeDef? value; + + SimpleClassNullableOfNumNullable( + this.value, + ); + + factory SimpleClassNullableOfNumNullable.fromJson( + Map<String, Object?> json) => + _$SimpleClassNullableOfNumNullableFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassNullableOfNumNullableToJson(this); +} + +typedef SimpleClassOfObjectTypeDef = (Object, {Object named}); + +@JsonSerializable() +class SimpleClassOfObject { + final SimpleClassOfObjectTypeDef value; + + SimpleClassOfObject( + this.value, + ); + + factory SimpleClassOfObject.fromJson(Map<String, Object?> json) => + _$SimpleClassOfObjectFromJson(json); + + Map<String, Object?> toJson() => _$SimpleClassOfObjectToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfObject { + final SimpleClassOfObjectTypeDef? value; + + SimpleClassNullableOfObject( + this.value, + ); + + factory SimpleClassNullableOfObject.fromJson(Map<String, Object?> json) => + _$SimpleClassNullableOfObjectFromJson(json); + + Map<String, Object?> toJson() => _$SimpleClassNullableOfObjectToJson(this); +} + +typedef SimpleClassOfObjectNullableTypeDef = (Object?, {Object? named}); + +@JsonSerializable() +class SimpleClassOfObjectNullable { + final SimpleClassOfObjectNullableTypeDef value; + + SimpleClassOfObjectNullable( + this.value, + ); + + factory SimpleClassOfObjectNullable.fromJson(Map<String, Object?> json) => + _$SimpleClassOfObjectNullableFromJson(json); + + Map<String, Object?> toJson() => _$SimpleClassOfObjectNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfObjectNullable { + final SimpleClassOfObjectNullableTypeDef? value; + + SimpleClassNullableOfObjectNullable( + this.value, + ); + + factory SimpleClassNullableOfObjectNullable.fromJson( + Map<String, Object?> json) => + _$SimpleClassNullableOfObjectNullableFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassNullableOfObjectNullableToJson(this); +} + +typedef SimpleClassOfStringTypeDef = (String, {String named}); + +@JsonSerializable() +class SimpleClassOfString { + final SimpleClassOfStringTypeDef value; + + SimpleClassOfString( + this.value, + ); + + factory SimpleClassOfString.fromJson(Map<String, Object?> json) => + _$SimpleClassOfStringFromJson(json); + + Map<String, Object?> toJson() => _$SimpleClassOfStringToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfString { + final SimpleClassOfStringTypeDef? value; + + SimpleClassNullableOfString( + this.value, + ); + + factory SimpleClassNullableOfString.fromJson(Map<String, Object?> json) => + _$SimpleClassNullableOfStringFromJson(json); + + Map<String, Object?> toJson() => _$SimpleClassNullableOfStringToJson(this); +} + +typedef SimpleClassOfStringNullableTypeDef = (String?, {String? named}); + +@JsonSerializable() +class SimpleClassOfStringNullable { + final SimpleClassOfStringNullableTypeDef value; + + SimpleClassOfStringNullable( + this.value, + ); + + factory SimpleClassOfStringNullable.fromJson(Map<String, Object?> json) => + _$SimpleClassOfStringNullableFromJson(json); + + Map<String, Object?> toJson() => _$SimpleClassOfStringNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfStringNullable { + final SimpleClassOfStringNullableTypeDef? value; + + SimpleClassNullableOfStringNullable( + this.value, + ); + + factory SimpleClassNullableOfStringNullable.fromJson( + Map<String, Object?> json) => + _$SimpleClassNullableOfStringNullableFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassNullableOfStringNullableToJson(this); +} + +typedef SimpleClassOfUriTypeDef = (Uri, {Uri named}); + +@JsonSerializable() +class SimpleClassOfUri { + final SimpleClassOfUriTypeDef value; + + SimpleClassOfUri( + this.value, + ); + + factory SimpleClassOfUri.fromJson(Map<String, Object?> json) => + _$SimpleClassOfUriFromJson(json); + + Map<String, Object?> toJson() => _$SimpleClassOfUriToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfUri { + final SimpleClassOfUriTypeDef? value; + + SimpleClassNullableOfUri( + this.value, + ); + + factory SimpleClassNullableOfUri.fromJson(Map<String, Object?> json) => + _$SimpleClassNullableOfUriFromJson(json); + + Map<String, Object?> toJson() => _$SimpleClassNullableOfUriToJson(this); +} + +typedef SimpleClassOfUriNullableTypeDef = (Uri?, {Uri? named}); + +@JsonSerializable() +class SimpleClassOfUriNullable { + final SimpleClassOfUriNullableTypeDef value; + + SimpleClassOfUriNullable( + this.value, + ); + + factory SimpleClassOfUriNullable.fromJson(Map<String, Object?> json) => + _$SimpleClassOfUriNullableFromJson(json); + + Map<String, Object?> toJson() => _$SimpleClassOfUriNullableToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfUriNullable { + final SimpleClassOfUriNullableTypeDef? value; + + SimpleClassNullableOfUriNullable( + this.value, + ); + + factory SimpleClassNullableOfUriNullable.fromJson( + Map<String, Object?> json) => + _$SimpleClassNullableOfUriNullableFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassNullableOfUriNullableToJson(this); +} diff --git a/json_serializable/test/supported_types/input.type_record.g.dart b/json_serializable/test/supported_types/input.type_record.g.dart new file mode 100644 index 000000000..445701050 --- /dev/null +++ b/json_serializable/test/supported_types/input.type_record.g.dart @@ -0,0 +1,1221 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal + +part of 'input.type_record.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +SimpleClass _$SimpleClassFromJson(Map<String, dynamic> json) => SimpleClass( + (), + ); + +Map<String, dynamic> _$SimpleClassToJson(SimpleClass instance) => + <String, dynamic>{ + 'value': {}, + }; + +SimpleClassNullable _$SimpleClassNullableFromJson(Map<String, dynamic> json) => + SimpleClassNullable( + (), + ); + +Map<String, dynamic> _$SimpleClassNullableToJson( + SimpleClassNullable instance) => + <String, dynamic>{ + 'value': instance.value == null ? null : {}, + }; + +SimpleClassOfBigInt _$SimpleClassOfBigIntFromJson(Map<String, dynamic> json) => + SimpleClassOfBigInt( + _$recordConvert( + json['value'], + ($jsonValue) => ( + BigInt.parse($jsonValue[r'$1'] as String), + named: BigInt.parse($jsonValue['named'] as String), + ), + ), + ); + +Map<String, dynamic> _$SimpleClassOfBigIntToJson( + SimpleClassOfBigInt instance) => + <String, dynamic>{ + 'value': { + r'$1': instance.value.$1.toString(), + 'named': instance.value.named.toString(), + }, + }; + +$Rec _$recordConvert<$Rec>( + Object? value, + $Rec Function(Map) convert, +) => + convert(value as Map<String, dynamic>); + +SimpleClassNullableOfBigInt _$SimpleClassNullableOfBigIntFromJson( + Map<String, dynamic> json) => + SimpleClassNullableOfBigInt( + _$recordConvertNullable( + json['value'], + ($jsonValue) => ( + BigInt.parse($jsonValue[r'$1'] as String), + named: BigInt.parse($jsonValue['named'] as String), + ), + ), + ); + +Map<String, dynamic> _$SimpleClassNullableOfBigIntToJson( + SimpleClassNullableOfBigInt instance) => + <String, dynamic>{ + 'value': instance.value == null + ? null + : { + r'$1': instance.value!.$1.toString(), + 'named': instance.value!.named.toString(), + }, + }; + +$Rec? _$recordConvertNullable<$Rec>( + Object? value, + $Rec Function(Map) convert, +) => + value == null ? null : convert(value as Map<String, dynamic>); + +SimpleClassOfBigIntNullable _$SimpleClassOfBigIntNullableFromJson( + Map<String, dynamic> json) => + SimpleClassOfBigIntNullable( + _$recordConvert( + json['value'], + ($jsonValue) => ( + $jsonValue[r'$1'] == null + ? null + : BigInt.parse($jsonValue[r'$1'] as String), + named: $jsonValue['named'] == null + ? null + : BigInt.parse($jsonValue['named'] as String), + ), + ), + ); + +Map<String, dynamic> _$SimpleClassOfBigIntNullableToJson( + SimpleClassOfBigIntNullable instance) => + <String, dynamic>{ + 'value': { + r'$1': instance.value.$1?.toString(), + 'named': instance.value.named?.toString(), + }, + }; + +SimpleClassNullableOfBigIntNullable + _$SimpleClassNullableOfBigIntNullableFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfBigIntNullable( + _$recordConvertNullable( + json['value'], + ($jsonValue) => ( + $jsonValue[r'$1'] == null + ? null + : BigInt.parse($jsonValue[r'$1'] as String), + named: $jsonValue['named'] == null + ? null + : BigInt.parse($jsonValue['named'] as String), + ), + ), + ); + +Map<String, dynamic> _$SimpleClassNullableOfBigIntNullableToJson( + SimpleClassNullableOfBigIntNullable instance) => + <String, dynamic>{ + 'value': instance.value == null + ? null + : { + r'$1': instance.value!.$1?.toString(), + 'named': instance.value!.named?.toString(), + }, + }; + +SimpleClassOfBool _$SimpleClassOfBoolFromJson(Map<String, dynamic> json) => + SimpleClassOfBool( + _$recordConvert( + json['value'], + ($jsonValue) => ( + $jsonValue[r'$1'] as bool, + named: $jsonValue['named'] as bool, + ), + ), + ); + +Map<String, dynamic> _$SimpleClassOfBoolToJson(SimpleClassOfBool instance) => + <String, dynamic>{ + 'value': { + r'$1': instance.value.$1, + 'named': instance.value.named, + }, + }; + +SimpleClassNullableOfBool _$SimpleClassNullableOfBoolFromJson( + Map<String, dynamic> json) => + SimpleClassNullableOfBool( + _$recordConvertNullable( + json['value'], + ($jsonValue) => ( + $jsonValue[r'$1'] as bool, + named: $jsonValue['named'] as bool, + ), + ), + ); + +Map<String, dynamic> _$SimpleClassNullableOfBoolToJson( + SimpleClassNullableOfBool instance) => + <String, dynamic>{ + 'value': instance.value == null + ? null + : { + r'$1': instance.value!.$1, + 'named': instance.value!.named, + }, + }; + +SimpleClassOfBoolNullable _$SimpleClassOfBoolNullableFromJson( + Map<String, dynamic> json) => + SimpleClassOfBoolNullable( + _$recordConvert( + json['value'], + ($jsonValue) => ( + $jsonValue[r'$1'] as bool?, + named: $jsonValue['named'] as bool?, + ), + ), + ); + +Map<String, dynamic> _$SimpleClassOfBoolNullableToJson( + SimpleClassOfBoolNullable instance) => + <String, dynamic>{ + 'value': { + r'$1': instance.value.$1, + 'named': instance.value.named, + }, + }; + +SimpleClassNullableOfBoolNullable _$SimpleClassNullableOfBoolNullableFromJson( + Map<String, dynamic> json) => + SimpleClassNullableOfBoolNullable( + _$recordConvertNullable( + json['value'], + ($jsonValue) => ( + $jsonValue[r'$1'] as bool?, + named: $jsonValue['named'] as bool?, + ), + ), + ); + +Map<String, dynamic> _$SimpleClassNullableOfBoolNullableToJson( + SimpleClassNullableOfBoolNullable instance) => + <String, dynamic>{ + 'value': instance.value == null + ? null + : { + r'$1': instance.value!.$1, + 'named': instance.value!.named, + }, + }; + +SimpleClassOfDateTime _$SimpleClassOfDateTimeFromJson( + Map<String, dynamic> json) => + SimpleClassOfDateTime( + _$recordConvert( + json['value'], + ($jsonValue) => ( + DateTime.parse($jsonValue[r'$1'] as String), + named: DateTime.parse($jsonValue['named'] as String), + ), + ), + ); + +Map<String, dynamic> _$SimpleClassOfDateTimeToJson( + SimpleClassOfDateTime instance) => + <String, dynamic>{ + 'value': { + r'$1': instance.value.$1.toIso8601String(), + 'named': instance.value.named.toIso8601String(), + }, + }; + +SimpleClassNullableOfDateTime _$SimpleClassNullableOfDateTimeFromJson( + Map<String, dynamic> json) => + SimpleClassNullableOfDateTime( + _$recordConvertNullable( + json['value'], + ($jsonValue) => ( + DateTime.parse($jsonValue[r'$1'] as String), + named: DateTime.parse($jsonValue['named'] as String), + ), + ), + ); + +Map<String, dynamic> _$SimpleClassNullableOfDateTimeToJson( + SimpleClassNullableOfDateTime instance) => + <String, dynamic>{ + 'value': instance.value == null + ? null + : { + r'$1': instance.value!.$1.toIso8601String(), + 'named': instance.value!.named.toIso8601String(), + }, + }; + +SimpleClassOfDateTimeNullable _$SimpleClassOfDateTimeNullableFromJson( + Map<String, dynamic> json) => + SimpleClassOfDateTimeNullable( + _$recordConvert( + json['value'], + ($jsonValue) => ( + $jsonValue[r'$1'] == null + ? null + : DateTime.parse($jsonValue[r'$1'] as String), + named: $jsonValue['named'] == null + ? null + : DateTime.parse($jsonValue['named'] as String), + ), + ), + ); + +Map<String, dynamic> _$SimpleClassOfDateTimeNullableToJson( + SimpleClassOfDateTimeNullable instance) => + <String, dynamic>{ + 'value': { + r'$1': instance.value.$1?.toIso8601String(), + 'named': instance.value.named?.toIso8601String(), + }, + }; + +SimpleClassNullableOfDateTimeNullable + _$SimpleClassNullableOfDateTimeNullableFromJson( + Map<String, dynamic> json) => + SimpleClassNullableOfDateTimeNullable( + _$recordConvertNullable( + json['value'], + ($jsonValue) => ( + $jsonValue[r'$1'] == null + ? null + : DateTime.parse($jsonValue[r'$1'] as String), + named: $jsonValue['named'] == null + ? null + : DateTime.parse($jsonValue['named'] as String), + ), + ), + ); + +Map<String, dynamic> _$SimpleClassNullableOfDateTimeNullableToJson( + SimpleClassNullableOfDateTimeNullable instance) => + <String, dynamic>{ + 'value': instance.value == null + ? null + : { + r'$1': instance.value!.$1?.toIso8601String(), + 'named': instance.value!.named?.toIso8601String(), + }, + }; + +SimpleClassOfDouble _$SimpleClassOfDoubleFromJson(Map<String, dynamic> json) => + SimpleClassOfDouble( + _$recordConvert( + json['value'], + ($jsonValue) => ( + ($jsonValue[r'$1'] as num).toDouble(), + named: ($jsonValue['named'] as num).toDouble(), + ), + ), + ); + +Map<String, dynamic> _$SimpleClassOfDoubleToJson( + SimpleClassOfDouble instance) => + <String, dynamic>{ + 'value': { + r'$1': instance.value.$1, + 'named': instance.value.named, + }, + }; + +SimpleClassNullableOfDouble _$SimpleClassNullableOfDoubleFromJson( + Map<String, dynamic> json) => + SimpleClassNullableOfDouble( + _$recordConvertNullable( + json['value'], + ($jsonValue) => ( + ($jsonValue[r'$1'] as num).toDouble(), + named: ($jsonValue['named'] as num).toDouble(), + ), + ), + ); + +Map<String, dynamic> _$SimpleClassNullableOfDoubleToJson( + SimpleClassNullableOfDouble instance) => + <String, dynamic>{ + 'value': instance.value == null + ? null + : { + r'$1': instance.value!.$1, + 'named': instance.value!.named, + }, + }; + +SimpleClassOfDoubleNullable _$SimpleClassOfDoubleNullableFromJson( + Map<String, dynamic> json) => + SimpleClassOfDoubleNullable( + _$recordConvert( + json['value'], + ($jsonValue) => ( + ($jsonValue[r'$1'] as num?)?.toDouble(), + named: ($jsonValue['named'] as num?)?.toDouble(), + ), + ), + ); + +Map<String, dynamic> _$SimpleClassOfDoubleNullableToJson( + SimpleClassOfDoubleNullable instance) => + <String, dynamic>{ + 'value': { + r'$1': instance.value.$1, + 'named': instance.value.named, + }, + }; + +SimpleClassNullableOfDoubleNullable + _$SimpleClassNullableOfDoubleNullableFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfDoubleNullable( + _$recordConvertNullable( + json['value'], + ($jsonValue) => ( + ($jsonValue[r'$1'] as num?)?.toDouble(), + named: ($jsonValue['named'] as num?)?.toDouble(), + ), + ), + ); + +Map<String, dynamic> _$SimpleClassNullableOfDoubleNullableToJson( + SimpleClassNullableOfDoubleNullable instance) => + <String, dynamic>{ + 'value': instance.value == null + ? null + : { + r'$1': instance.value!.$1, + 'named': instance.value!.named, + }, + }; + +SimpleClassOfDuration _$SimpleClassOfDurationFromJson( + Map<String, dynamic> json) => + SimpleClassOfDuration( + _$recordConvert( + json['value'], + ($jsonValue) => ( + Duration(microseconds: $jsonValue[r'$1'] as int), + named: Duration(microseconds: $jsonValue['named'] as int), + ), + ), + ); + +Map<String, dynamic> _$SimpleClassOfDurationToJson( + SimpleClassOfDuration instance) => + <String, dynamic>{ + 'value': { + r'$1': instance.value.$1.inMicroseconds, + 'named': instance.value.named.inMicroseconds, + }, + }; + +SimpleClassNullableOfDuration _$SimpleClassNullableOfDurationFromJson( + Map<String, dynamic> json) => + SimpleClassNullableOfDuration( + _$recordConvertNullable( + json['value'], + ($jsonValue) => ( + Duration(microseconds: $jsonValue[r'$1'] as int), + named: Duration(microseconds: $jsonValue['named'] as int), + ), + ), + ); + +Map<String, dynamic> _$SimpleClassNullableOfDurationToJson( + SimpleClassNullableOfDuration instance) => + <String, dynamic>{ + 'value': instance.value == null + ? null + : { + r'$1': instance.value!.$1.inMicroseconds, + 'named': instance.value!.named.inMicroseconds, + }, + }; + +SimpleClassOfDurationNullable _$SimpleClassOfDurationNullableFromJson( + Map<String, dynamic> json) => + SimpleClassOfDurationNullable( + _$recordConvert( + json['value'], + ($jsonValue) => ( + $jsonValue[r'$1'] == null + ? null + : Duration(microseconds: $jsonValue[r'$1'] as int), + named: $jsonValue['named'] == null + ? null + : Duration(microseconds: $jsonValue['named'] as int), + ), + ), + ); + +Map<String, dynamic> _$SimpleClassOfDurationNullableToJson( + SimpleClassOfDurationNullable instance) => + <String, dynamic>{ + 'value': { + r'$1': instance.value.$1?.inMicroseconds, + 'named': instance.value.named?.inMicroseconds, + }, + }; + +SimpleClassNullableOfDurationNullable + _$SimpleClassNullableOfDurationNullableFromJson( + Map<String, dynamic> json) => + SimpleClassNullableOfDurationNullable( + _$recordConvertNullable( + json['value'], + ($jsonValue) => ( + $jsonValue[r'$1'] == null + ? null + : Duration(microseconds: $jsonValue[r'$1'] as int), + named: $jsonValue['named'] == null + ? null + : Duration(microseconds: $jsonValue['named'] as int), + ), + ), + ); + +Map<String, dynamic> _$SimpleClassNullableOfDurationNullableToJson( + SimpleClassNullableOfDurationNullable instance) => + <String, dynamic>{ + 'value': instance.value == null + ? null + : { + r'$1': instance.value!.$1?.inMicroseconds, + 'named': instance.value!.named?.inMicroseconds, + }, + }; + +SimpleClassOfDynamic _$SimpleClassOfDynamicFromJson( + Map<String, dynamic> json) => + SimpleClassOfDynamic( + _$recordConvert( + json['value'], + ($jsonValue) => ( + $jsonValue[r'$1'], + named: $jsonValue['named'], + ), + ), + ); + +Map<String, dynamic> _$SimpleClassOfDynamicToJson( + SimpleClassOfDynamic instance) => + <String, dynamic>{ + 'value': { + r'$1': instance.value.$1, + 'named': instance.value.named, + }, + }; + +SimpleClassNullableOfDynamic _$SimpleClassNullableOfDynamicFromJson( + Map<String, dynamic> json) => + SimpleClassNullableOfDynamic( + _$recordConvertNullable( + json['value'], + ($jsonValue) => ( + $jsonValue[r'$1'], + named: $jsonValue['named'], + ), + ), + ); + +Map<String, dynamic> _$SimpleClassNullableOfDynamicToJson( + SimpleClassNullableOfDynamic instance) => + <String, dynamic>{ + 'value': instance.value == null + ? null + : { + r'$1': instance.value!.$1, + 'named': instance.value!.named, + }, + }; + +SimpleClassOfEnumType _$SimpleClassOfEnumTypeFromJson( + Map<String, dynamic> json) => + SimpleClassOfEnumType( + _$recordConvert( + json['value'], + ($jsonValue) => ( + $enumDecode(_$EnumTypeEnumMap, $jsonValue[r'$1']), + named: $enumDecode(_$EnumTypeEnumMap, $jsonValue['named']), + ), + ), + ); + +Map<String, dynamic> _$SimpleClassOfEnumTypeToJson( + SimpleClassOfEnumType instance) => + <String, dynamic>{ + 'value': { + r'$1': _$EnumTypeEnumMap[instance.value.$1]!, + 'named': _$EnumTypeEnumMap[instance.value.named]!, + }, + }; + +const _$EnumTypeEnumMap = { + EnumType.alpha: 'alpha', + EnumType.beta: 'beta', + EnumType.gamma: 'gamma', + EnumType.delta: 'delta', +}; + +SimpleClassNullableOfEnumType _$SimpleClassNullableOfEnumTypeFromJson( + Map<String, dynamic> json) => + SimpleClassNullableOfEnumType( + _$recordConvertNullable( + json['value'], + ($jsonValue) => ( + $enumDecode(_$EnumTypeEnumMap, $jsonValue[r'$1']), + named: $enumDecode(_$EnumTypeEnumMap, $jsonValue['named']), + ), + ), + ); + +Map<String, dynamic> _$SimpleClassNullableOfEnumTypeToJson( + SimpleClassNullableOfEnumType instance) => + <String, dynamic>{ + 'value': instance.value == null + ? null + : { + r'$1': _$EnumTypeEnumMap[instance.value!.$1]!, + 'named': _$EnumTypeEnumMap[instance.value!.named]!, + }, + }; + +SimpleClassOfEnumTypeNullable _$SimpleClassOfEnumTypeNullableFromJson( + Map<String, dynamic> json) => + SimpleClassOfEnumTypeNullable( + _$recordConvert( + json['value'], + ($jsonValue) => ( + $enumDecodeNullable(_$EnumTypeEnumMap, $jsonValue[r'$1']), + named: $enumDecodeNullable(_$EnumTypeEnumMap, $jsonValue['named']), + ), + ), + ); + +Map<String, dynamic> _$SimpleClassOfEnumTypeNullableToJson( + SimpleClassOfEnumTypeNullable instance) => + <String, dynamic>{ + 'value': { + r'$1': _$EnumTypeEnumMap[instance.value.$1], + 'named': _$EnumTypeEnumMap[instance.value.named], + }, + }; + +SimpleClassNullableOfEnumTypeNullable + _$SimpleClassNullableOfEnumTypeNullableFromJson( + Map<String, dynamic> json) => + SimpleClassNullableOfEnumTypeNullable( + _$recordConvertNullable( + json['value'], + ($jsonValue) => ( + $enumDecodeNullable(_$EnumTypeEnumMap, $jsonValue[r'$1']), + named: + $enumDecodeNullable(_$EnumTypeEnumMap, $jsonValue['named']), + ), + ), + ); + +Map<String, dynamic> _$SimpleClassNullableOfEnumTypeNullableToJson( + SimpleClassNullableOfEnumTypeNullable instance) => + <String, dynamic>{ + 'value': instance.value == null + ? null + : { + r'$1': _$EnumTypeEnumMap[instance.value!.$1], + 'named': _$EnumTypeEnumMap[instance.value!.named], + }, + }; + +SimpleClassOfFromJsonDynamicParam _$SimpleClassOfFromJsonDynamicParamFromJson( + Map<String, dynamic> json) => + SimpleClassOfFromJsonDynamicParam( + _$recordConvert( + json['value'], + ($jsonValue) => ( + FromJsonDynamicParam.fromJson($jsonValue[r'$1']), + named: FromJsonDynamicParam.fromJson($jsonValue['named']), + ), + ), + ); + +Map<String, dynamic> _$SimpleClassOfFromJsonDynamicParamToJson( + SimpleClassOfFromJsonDynamicParam instance) => + <String, dynamic>{ + 'value': { + r'$1': instance.value.$1, + 'named': instance.value.named, + }, + }; + +SimpleClassNullableOfFromJsonDynamicParam + _$SimpleClassNullableOfFromJsonDynamicParamFromJson( + Map<String, dynamic> json) => + SimpleClassNullableOfFromJsonDynamicParam( + _$recordConvertNullable( + json['value'], + ($jsonValue) => ( + FromJsonDynamicParam.fromJson($jsonValue[r'$1']), + named: FromJsonDynamicParam.fromJson($jsonValue['named']), + ), + ), + ); + +Map<String, dynamic> _$SimpleClassNullableOfFromJsonDynamicParamToJson( + SimpleClassNullableOfFromJsonDynamicParam instance) => + <String, dynamic>{ + 'value': instance.value == null + ? null + : { + r'$1': instance.value!.$1, + 'named': instance.value!.named, + }, + }; + +SimpleClassOfFromJsonNullableObjectParam + _$SimpleClassOfFromJsonNullableObjectParamFromJson( + Map<String, dynamic> json) => + SimpleClassOfFromJsonNullableObjectParam( + _$recordConvert( + json['value'], + ($jsonValue) => ( + FromJsonNullableObjectParam.fromJson($jsonValue[r'$1']), + named: FromJsonNullableObjectParam.fromJson($jsonValue['named']), + ), + ), + ); + +Map<String, dynamic> _$SimpleClassOfFromJsonNullableObjectParamToJson( + SimpleClassOfFromJsonNullableObjectParam instance) => + <String, dynamic>{ + 'value': { + r'$1': instance.value.$1, + 'named': instance.value.named, + }, + }; + +SimpleClassNullableOfFromJsonNullableObjectParam + _$SimpleClassNullableOfFromJsonNullableObjectParamFromJson( + Map<String, dynamic> json) => + SimpleClassNullableOfFromJsonNullableObjectParam( + _$recordConvertNullable( + json['value'], + ($jsonValue) => ( + FromJsonNullableObjectParam.fromJson($jsonValue[r'$1']), + named: FromJsonNullableObjectParam.fromJson($jsonValue['named']), + ), + ), + ); + +Map<String, dynamic> _$SimpleClassNullableOfFromJsonNullableObjectParamToJson( + SimpleClassNullableOfFromJsonNullableObjectParam instance) => + <String, dynamic>{ + 'value': instance.value == null + ? null + : { + r'$1': instance.value!.$1, + 'named': instance.value!.named, + }, + }; + +SimpleClassOfFromJsonObjectParam _$SimpleClassOfFromJsonObjectParamFromJson( + Map<String, dynamic> json) => + SimpleClassOfFromJsonObjectParam( + _$recordConvert( + json['value'], + ($jsonValue) => ( + FromJsonObjectParam.fromJson($jsonValue[r'$1'] as Object), + named: FromJsonObjectParam.fromJson($jsonValue['named'] as Object), + ), + ), + ); + +Map<String, dynamic> _$SimpleClassOfFromJsonObjectParamToJson( + SimpleClassOfFromJsonObjectParam instance) => + <String, dynamic>{ + 'value': { + r'$1': instance.value.$1, + 'named': instance.value.named, + }, + }; + +SimpleClassNullableOfFromJsonObjectParam + _$SimpleClassNullableOfFromJsonObjectParamFromJson( + Map<String, dynamic> json) => + SimpleClassNullableOfFromJsonObjectParam( + _$recordConvertNullable( + json['value'], + ($jsonValue) => ( + FromJsonObjectParam.fromJson($jsonValue[r'$1'] as Object), + named: + FromJsonObjectParam.fromJson($jsonValue['named'] as Object), + ), + ), + ); + +Map<String, dynamic> _$SimpleClassNullableOfFromJsonObjectParamToJson( + SimpleClassNullableOfFromJsonObjectParam instance) => + <String, dynamic>{ + 'value': instance.value == null + ? null + : { + r'$1': instance.value!.$1, + 'named': instance.value!.named, + }, + }; + +SimpleClassOfInt _$SimpleClassOfIntFromJson(Map<String, dynamic> json) => + SimpleClassOfInt( + _$recordConvert( + json['value'], + ($jsonValue) => ( + $jsonValue[r'$1'] as int, + named: $jsonValue['named'] as int, + ), + ), + ); + +Map<String, dynamic> _$SimpleClassOfIntToJson(SimpleClassOfInt instance) => + <String, dynamic>{ + 'value': { + r'$1': instance.value.$1, + 'named': instance.value.named, + }, + }; + +SimpleClassNullableOfInt _$SimpleClassNullableOfIntFromJson( + Map<String, dynamic> json) => + SimpleClassNullableOfInt( + _$recordConvertNullable( + json['value'], + ($jsonValue) => ( + $jsonValue[r'$1'] as int, + named: $jsonValue['named'] as int, + ), + ), + ); + +Map<String, dynamic> _$SimpleClassNullableOfIntToJson( + SimpleClassNullableOfInt instance) => + <String, dynamic>{ + 'value': instance.value == null + ? null + : { + r'$1': instance.value!.$1, + 'named': instance.value!.named, + }, + }; + +SimpleClassOfIntNullable _$SimpleClassOfIntNullableFromJson( + Map<String, dynamic> json) => + SimpleClassOfIntNullable( + _$recordConvert( + json['value'], + ($jsonValue) => ( + $jsonValue[r'$1'] as int?, + named: $jsonValue['named'] as int?, + ), + ), + ); + +Map<String, dynamic> _$SimpleClassOfIntNullableToJson( + SimpleClassOfIntNullable instance) => + <String, dynamic>{ + 'value': { + r'$1': instance.value.$1, + 'named': instance.value.named, + }, + }; + +SimpleClassNullableOfIntNullable _$SimpleClassNullableOfIntNullableFromJson( + Map<String, dynamic> json) => + SimpleClassNullableOfIntNullable( + _$recordConvertNullable( + json['value'], + ($jsonValue) => ( + $jsonValue[r'$1'] as int?, + named: $jsonValue['named'] as int?, + ), + ), + ); + +Map<String, dynamic> _$SimpleClassNullableOfIntNullableToJson( + SimpleClassNullableOfIntNullable instance) => + <String, dynamic>{ + 'value': instance.value == null + ? null + : { + r'$1': instance.value!.$1, + 'named': instance.value!.named, + }, + }; + +SimpleClassOfNum _$SimpleClassOfNumFromJson(Map<String, dynamic> json) => + SimpleClassOfNum( + _$recordConvert( + json['value'], + ($jsonValue) => ( + $jsonValue[r'$1'] as num, + named: $jsonValue['named'] as num, + ), + ), + ); + +Map<String, dynamic> _$SimpleClassOfNumToJson(SimpleClassOfNum instance) => + <String, dynamic>{ + 'value': { + r'$1': instance.value.$1, + 'named': instance.value.named, + }, + }; + +SimpleClassNullableOfNum _$SimpleClassNullableOfNumFromJson( + Map<String, dynamic> json) => + SimpleClassNullableOfNum( + _$recordConvertNullable( + json['value'], + ($jsonValue) => ( + $jsonValue[r'$1'] as num, + named: $jsonValue['named'] as num, + ), + ), + ); + +Map<String, dynamic> _$SimpleClassNullableOfNumToJson( + SimpleClassNullableOfNum instance) => + <String, dynamic>{ + 'value': instance.value == null + ? null + : { + r'$1': instance.value!.$1, + 'named': instance.value!.named, + }, + }; + +SimpleClassOfNumNullable _$SimpleClassOfNumNullableFromJson( + Map<String, dynamic> json) => + SimpleClassOfNumNullable( + _$recordConvert( + json['value'], + ($jsonValue) => ( + $jsonValue[r'$1'] as num?, + named: $jsonValue['named'] as num?, + ), + ), + ); + +Map<String, dynamic> _$SimpleClassOfNumNullableToJson( + SimpleClassOfNumNullable instance) => + <String, dynamic>{ + 'value': { + r'$1': instance.value.$1, + 'named': instance.value.named, + }, + }; + +SimpleClassNullableOfNumNullable _$SimpleClassNullableOfNumNullableFromJson( + Map<String, dynamic> json) => + SimpleClassNullableOfNumNullable( + _$recordConvertNullable( + json['value'], + ($jsonValue) => ( + $jsonValue[r'$1'] as num?, + named: $jsonValue['named'] as num?, + ), + ), + ); + +Map<String, dynamic> _$SimpleClassNullableOfNumNullableToJson( + SimpleClassNullableOfNumNullable instance) => + <String, dynamic>{ + 'value': instance.value == null + ? null + : { + r'$1': instance.value!.$1, + 'named': instance.value!.named, + }, + }; + +SimpleClassOfObject _$SimpleClassOfObjectFromJson(Map<String, dynamic> json) => + SimpleClassOfObject( + _$recordConvert( + json['value'], + ($jsonValue) => ( + $jsonValue[r'$1'] as Object, + named: $jsonValue['named'] as Object, + ), + ), + ); + +Map<String, dynamic> _$SimpleClassOfObjectToJson( + SimpleClassOfObject instance) => + <String, dynamic>{ + 'value': { + r'$1': instance.value.$1, + 'named': instance.value.named, + }, + }; + +SimpleClassNullableOfObject _$SimpleClassNullableOfObjectFromJson( + Map<String, dynamic> json) => + SimpleClassNullableOfObject( + _$recordConvertNullable( + json['value'], + ($jsonValue) => ( + $jsonValue[r'$1'] as Object, + named: $jsonValue['named'] as Object, + ), + ), + ); + +Map<String, dynamic> _$SimpleClassNullableOfObjectToJson( + SimpleClassNullableOfObject instance) => + <String, dynamic>{ + 'value': instance.value == null + ? null + : { + r'$1': instance.value!.$1, + 'named': instance.value!.named, + }, + }; + +SimpleClassOfObjectNullable _$SimpleClassOfObjectNullableFromJson( + Map<String, dynamic> json) => + SimpleClassOfObjectNullable( + _$recordConvert( + json['value'], + ($jsonValue) => ( + $jsonValue[r'$1'], + named: $jsonValue['named'], + ), + ), + ); + +Map<String, dynamic> _$SimpleClassOfObjectNullableToJson( + SimpleClassOfObjectNullable instance) => + <String, dynamic>{ + 'value': { + r'$1': instance.value.$1, + 'named': instance.value.named, + }, + }; + +SimpleClassNullableOfObjectNullable + _$SimpleClassNullableOfObjectNullableFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfObjectNullable( + _$recordConvertNullable( + json['value'], + ($jsonValue) => ( + $jsonValue[r'$1'], + named: $jsonValue['named'], + ), + ), + ); + +Map<String, dynamic> _$SimpleClassNullableOfObjectNullableToJson( + SimpleClassNullableOfObjectNullable instance) => + <String, dynamic>{ + 'value': instance.value == null + ? null + : { + r'$1': instance.value!.$1, + 'named': instance.value!.named, + }, + }; + +SimpleClassOfString _$SimpleClassOfStringFromJson(Map<String, dynamic> json) => + SimpleClassOfString( + _$recordConvert( + json['value'], + ($jsonValue) => ( + $jsonValue[r'$1'] as String, + named: $jsonValue['named'] as String, + ), + ), + ); + +Map<String, dynamic> _$SimpleClassOfStringToJson( + SimpleClassOfString instance) => + <String, dynamic>{ + 'value': { + r'$1': instance.value.$1, + 'named': instance.value.named, + }, + }; + +SimpleClassNullableOfString _$SimpleClassNullableOfStringFromJson( + Map<String, dynamic> json) => + SimpleClassNullableOfString( + _$recordConvertNullable( + json['value'], + ($jsonValue) => ( + $jsonValue[r'$1'] as String, + named: $jsonValue['named'] as String, + ), + ), + ); + +Map<String, dynamic> _$SimpleClassNullableOfStringToJson( + SimpleClassNullableOfString instance) => + <String, dynamic>{ + 'value': instance.value == null + ? null + : { + r'$1': instance.value!.$1, + 'named': instance.value!.named, + }, + }; + +SimpleClassOfStringNullable _$SimpleClassOfStringNullableFromJson( + Map<String, dynamic> json) => + SimpleClassOfStringNullable( + _$recordConvert( + json['value'], + ($jsonValue) => ( + $jsonValue[r'$1'] as String?, + named: $jsonValue['named'] as String?, + ), + ), + ); + +Map<String, dynamic> _$SimpleClassOfStringNullableToJson( + SimpleClassOfStringNullable instance) => + <String, dynamic>{ + 'value': { + r'$1': instance.value.$1, + 'named': instance.value.named, + }, + }; + +SimpleClassNullableOfStringNullable + _$SimpleClassNullableOfStringNullableFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfStringNullable( + _$recordConvertNullable( + json['value'], + ($jsonValue) => ( + $jsonValue[r'$1'] as String?, + named: $jsonValue['named'] as String?, + ), + ), + ); + +Map<String, dynamic> _$SimpleClassNullableOfStringNullableToJson( + SimpleClassNullableOfStringNullable instance) => + <String, dynamic>{ + 'value': instance.value == null + ? null + : { + r'$1': instance.value!.$1, + 'named': instance.value!.named, + }, + }; + +SimpleClassOfUri _$SimpleClassOfUriFromJson(Map<String, dynamic> json) => + SimpleClassOfUri( + _$recordConvert( + json['value'], + ($jsonValue) => ( + Uri.parse($jsonValue[r'$1'] as String), + named: Uri.parse($jsonValue['named'] as String), + ), + ), + ); + +Map<String, dynamic> _$SimpleClassOfUriToJson(SimpleClassOfUri instance) => + <String, dynamic>{ + 'value': { + r'$1': instance.value.$1.toString(), + 'named': instance.value.named.toString(), + }, + }; + +SimpleClassNullableOfUri _$SimpleClassNullableOfUriFromJson( + Map<String, dynamic> json) => + SimpleClassNullableOfUri( + _$recordConvertNullable( + json['value'], + ($jsonValue) => ( + Uri.parse($jsonValue[r'$1'] as String), + named: Uri.parse($jsonValue['named'] as String), + ), + ), + ); + +Map<String, dynamic> _$SimpleClassNullableOfUriToJson( + SimpleClassNullableOfUri instance) => + <String, dynamic>{ + 'value': instance.value == null + ? null + : { + r'$1': instance.value!.$1.toString(), + 'named': instance.value!.named.toString(), + }, + }; + +SimpleClassOfUriNullable _$SimpleClassOfUriNullableFromJson( + Map<String, dynamic> json) => + SimpleClassOfUriNullable( + _$recordConvert( + json['value'], + ($jsonValue) => ( + $jsonValue[r'$1'] == null + ? null + : Uri.parse($jsonValue[r'$1'] as String), + named: $jsonValue['named'] == null + ? null + : Uri.parse($jsonValue['named'] as String), + ), + ), + ); + +Map<String, dynamic> _$SimpleClassOfUriNullableToJson( + SimpleClassOfUriNullable instance) => + <String, dynamic>{ + 'value': { + r'$1': instance.value.$1?.toString(), + 'named': instance.value.named?.toString(), + }, + }; + +SimpleClassNullableOfUriNullable _$SimpleClassNullableOfUriNullableFromJson( + Map<String, dynamic> json) => + SimpleClassNullableOfUriNullable( + _$recordConvertNullable( + json['value'], + ($jsonValue) => ( + $jsonValue[r'$1'] == null + ? null + : Uri.parse($jsonValue[r'$1'] as String), + named: $jsonValue['named'] == null + ? null + : Uri.parse($jsonValue['named'] as String), + ), + ), + ); + +Map<String, dynamic> _$SimpleClassNullableOfUriNullableToJson( + SimpleClassNullableOfUriNullable instance) => + <String, dynamic>{ + 'value': instance.value == null + ? null + : { + r'$1': instance.value!.$1?.toString(), + 'named': instance.value!.named?.toString(), + }, + }; diff --git a/json_serializable/tool/test_type_builder.dart b/json_serializable/tool/test_type_builder.dart index e35dfd766..31f96c3ba 100644 --- a/json_serializable/tool/test_type_builder.dart +++ b/json_serializable/tool/test_type_builder.dart @@ -59,7 +59,7 @@ const _trivialTypesToTest = { ), }; -Iterable<String> supportedTypes() => _typesToTest.keys; +Iterable<String> supportedTypes() => _allTypes.keys; Iterable<String> collectionTypes() => _collectionTypes.keys; @@ -87,13 +87,19 @@ final _collectionTypes = { altJsonExpression: '[$_altCollectionExpressions]', genericArgs: _iterableGenericArgs, ), + recordType: TestTypeData( + altJsonExpression: '{}', + genericArgs: _iterableGenericArgs, + ) }; -final _typesToTest = { +final _allTypes = { ..._trivialTypesToTest, ..._collectionTypes, }; +final _typesToTest = Map.of(_allTypes)..remove(recordType); + Iterable<String> get mapKeyTypes => allowedMapKeyTypes.map((e) => e == 'enum' ? customEnumType : e).toList() ..sort(compareAsciiLowerCase); @@ -122,7 +128,7 @@ class _TypeBuilder implements Builder { final sourceContent = await buildStep.readAsString(inputId); - for (var entry in _typesToTest.entries) { + for (var entry in _allTypes.entries) { final type = entry.key; final newId = buildStep.inputId.changeExtension(toTypeExtension(type)); @@ -134,9 +140,8 @@ class _TypeBuilder implements Builder { } @override - Map<String, List<String>> get buildExtensions => { - '.dart': _typesToTest.keys.map(toTypeExtension).toSet().toList()..sort() - }; + Map<String, List<String>> get buildExtensions => + {'.dart': _allTypes.keys.map(toTypeExtension).toSet().toList()..sort()}; } Builder typeTestBuilder([_]) => diff --git a/json_serializable/tool/test_type_data.dart b/json_serializable/tool/test_type_data.dart index f6042fe9c..3b6366d00 100644 --- a/json_serializable/tool/test_type_data.dart +++ b/json_serializable/tool/test_type_data.dart @@ -2,6 +2,8 @@ import 'shared.dart'; const customEnumType = 'EnumType'; +const recordType = 'Record'; + const _annotationImport = "import 'package:json_annotation/json_annotation.dart';"; @@ -56,13 +58,19 @@ class TestTypeData { final buffer = StringBuffer(Replacement.generate(split[0], headerReplacements)); + if (type == recordType) { + buffer.writeln('typedef RecordTypeDef = ();'); + } + final simpleClassContent = '$classAnnotationSplit${split[1]}'; + final simpleLiteral = type == recordType ? 'RecordTypeDef' : type; + buffer ..write( Replacement.generate( simpleClassContent, - _libReplacements(type), + _libReplacements(simpleLiteral), ), ) ..write( @@ -71,21 +79,30 @@ class TestTypeData { 'SimpleClass', 'SimpleClassNullable', ), - _libReplacements('$type?'), + _libReplacements('$simpleLiteral?'), ), ); for (var genericArg in genericArgs) { final genericArgClassPart = _genericClassPart(genericArg); - final genericType = '$type<$genericArg>'; + final theName = 'SimpleClassOf$genericArgClassPart'; + + final genericType = + type == recordType ? '${theName}TypeDef' : '$type<$genericArg>'; + + if (type == recordType) { + buffer.writeln( + 'typedef $genericType = ($genericArg, {$genericArg named});', + ); + } buffer ..write( Replacement.generate( simpleClassContent.replaceAll( 'SimpleClass', - 'SimpleClassOf$genericArgClassPart', + theName, ), _libReplacements(genericType), ), From 755d5d39e0e13678e0478a65c087709e2bff09f9 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Tue, 16 May 2023 11:44:35 -0700 Subject: [PATCH 491/569] Records: more testing (#1320) --- json_annotation/lib/src/json_key.dart | 5 +- .../supported_types/input.type_iterable.dart | 28 ++ .../input.type_iterable.g.dart | 55 +++ .../test/supported_types/input.type_list.dart | 28 ++ .../supported_types/input.type_list.g.dart | 59 +++ .../test/supported_types/input.type_map.dart | 240 ++++++++++ .../supported_types/input.type_map.g.dart | 440 ++++++++++++++++++ .../supported_types/input.type_record.dart | 33 ++ .../supported_types/input.type_record.g.dart | 87 ++++ .../test/supported_types/input.type_set.dart | 28 ++ .../supported_types/input.type_set.g.dart | 59 +++ ...sts.dart => support_types_extra_test.dart} | 22 + json_serializable/tool/test_type_builder.dart | 1 + json_serializable/tool/test_type_data.dart | 18 +- 14 files changed, 1098 insertions(+), 5 deletions(-) rename json_serializable/test/supported_types/{support_types_extra_tests.dart => support_types_extra_test.dart} (78%) diff --git a/json_annotation/lib/src/json_key.dart b/json_annotation/lib/src/json_key.dart index d87d52068..d7c97b65b 100644 --- a/json_annotation/lib/src/json_key.dart +++ b/json_annotation/lib/src/json_key.dart @@ -153,8 +153,7 @@ class JsonKey { /// /// Only required when the default behavior is not desired. const JsonKey({ - @Deprecated('Has no effect') - bool? nullable, + @Deprecated('Has no effect') bool? nullable, this.defaultValue, this.disallowNullValue, this.fromJson, @@ -162,7 +161,7 @@ class JsonKey { 'Use `includeFromJson` and `includeToJson` with a value of `false` ' 'instead.', ) - this.ignore, + this.ignore, this.includeFromJson, this.includeIfNull, this.includeToJson, diff --git a/json_serializable/test/supported_types/input.type_iterable.dart b/json_serializable/test/supported_types/input.type_iterable.dart index 79c080a7b..d01b49a20 100644 --- a/json_serializable/test/supported_types/input.type_iterable.dart +++ b/json_serializable/test/supported_types/input.type_iterable.dart @@ -689,6 +689,34 @@ class SimpleClassNullableOfObjectNullable { _$SimpleClassNullableOfObjectNullableToJson(this); } +@JsonSerializable() +class SimpleClassOfRecord { + final Iterable<(int, String, {bool truth})> value; + + SimpleClassOfRecord( + this.value, + ); + + factory SimpleClassOfRecord.fromJson(Map<String, Object?> json) => + _$SimpleClassOfRecordFromJson(json); + + Map<String, Object?> toJson() => _$SimpleClassOfRecordToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfRecord { + final Iterable<(int, String, {bool truth})>? value; + + SimpleClassNullableOfRecord( + this.value, + ); + + factory SimpleClassNullableOfRecord.fromJson(Map<String, Object?> json) => + _$SimpleClassNullableOfRecordFromJson(json); + + Map<String, Object?> toJson() => _$SimpleClassNullableOfRecordToJson(this); +} + @JsonSerializable() class SimpleClassOfString { final Iterable<String> value; diff --git a/json_serializable/test/supported_types/input.type_iterable.g.dart b/json_serializable/test/supported_types/input.type_iterable.g.dart index 9222c22d2..885d166a8 100644 --- a/json_serializable/test/supported_types/input.type_iterable.g.dart +++ b/json_serializable/test/supported_types/input.type_iterable.g.dart @@ -583,6 +583,61 @@ Map<String, dynamic> _$SimpleClassNullableOfObjectNullableToJson( 'value': instance.value?.toList(), }; +SimpleClassOfRecord _$SimpleClassOfRecordFromJson(Map<String, dynamic> json) => + SimpleClassOfRecord( + (json['value'] as List<dynamic>).map((e) => _$recordConvert( + e, + ($jsonValue) => ( + $jsonValue[r'$1'] as int, + $jsonValue[r'$2'] as String, + truth: $jsonValue['truth'] as bool, + ), + )), + ); + +Map<String, dynamic> _$SimpleClassOfRecordToJson( + SimpleClassOfRecord instance) => + <String, dynamic>{ + 'value': instance.value + .map((e) => { + r'$1': e.$1, + r'$2': e.$2, + 'truth': e.truth, + }) + .toList(), + }; + +$Rec _$recordConvert<$Rec>( + Object? value, + $Rec Function(Map) convert, +) => + convert(value as Map<String, dynamic>); + +SimpleClassNullableOfRecord _$SimpleClassNullableOfRecordFromJson( + Map<String, dynamic> json) => + SimpleClassNullableOfRecord( + (json['value'] as List<dynamic>?)?.map((e) => _$recordConvert( + e, + ($jsonValue) => ( + $jsonValue[r'$1'] as int, + $jsonValue[r'$2'] as String, + truth: $jsonValue['truth'] as bool, + ), + )), + ); + +Map<String, dynamic> _$SimpleClassNullableOfRecordToJson( + SimpleClassNullableOfRecord instance) => + <String, dynamic>{ + 'value': instance.value + ?.map((e) => { + r'$1': e.$1, + r'$2': e.$2, + 'truth': e.truth, + }) + .toList(), + }; + SimpleClassOfString _$SimpleClassOfStringFromJson(Map<String, dynamic> json) => SimpleClassOfString( (json['value'] as List<dynamic>).map((e) => e as String), diff --git a/json_serializable/test/supported_types/input.type_list.dart b/json_serializable/test/supported_types/input.type_list.dart index 12119ec40..205e97195 100644 --- a/json_serializable/test/supported_types/input.type_list.dart +++ b/json_serializable/test/supported_types/input.type_list.dart @@ -689,6 +689,34 @@ class SimpleClassNullableOfObjectNullable { _$SimpleClassNullableOfObjectNullableToJson(this); } +@JsonSerializable() +class SimpleClassOfRecord { + final List<(int, String, {bool truth})> value; + + SimpleClassOfRecord( + this.value, + ); + + factory SimpleClassOfRecord.fromJson(Map<String, Object?> json) => + _$SimpleClassOfRecordFromJson(json); + + Map<String, Object?> toJson() => _$SimpleClassOfRecordToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfRecord { + final List<(int, String, {bool truth})>? value; + + SimpleClassNullableOfRecord( + this.value, + ); + + factory SimpleClassNullableOfRecord.fromJson(Map<String, Object?> json) => + _$SimpleClassNullableOfRecordFromJson(json); + + Map<String, Object?> toJson() => _$SimpleClassNullableOfRecordToJson(this); +} + @JsonSerializable() class SimpleClassOfString { final List<String> value; diff --git a/json_serializable/test/supported_types/input.type_list.g.dart b/json_serializable/test/supported_types/input.type_list.g.dart index 11d7dd234..b21a959b6 100644 --- a/json_serializable/test/supported_types/input.type_list.g.dart +++ b/json_serializable/test/supported_types/input.type_list.g.dart @@ -617,6 +617,65 @@ Map<String, dynamic> _$SimpleClassNullableOfObjectNullableToJson( 'value': instance.value, }; +SimpleClassOfRecord _$SimpleClassOfRecordFromJson(Map<String, dynamic> json) => + SimpleClassOfRecord( + (json['value'] as List<dynamic>) + .map((e) => _$recordConvert( + e, + ($jsonValue) => ( + $jsonValue[r'$1'] as int, + $jsonValue[r'$2'] as String, + truth: $jsonValue['truth'] as bool, + ), + )) + .toList(), + ); + +Map<String, dynamic> _$SimpleClassOfRecordToJson( + SimpleClassOfRecord instance) => + <String, dynamic>{ + 'value': instance.value + .map((e) => { + r'$1': e.$1, + r'$2': e.$2, + 'truth': e.truth, + }) + .toList(), + }; + +$Rec _$recordConvert<$Rec>( + Object? value, + $Rec Function(Map) convert, +) => + convert(value as Map<String, dynamic>); + +SimpleClassNullableOfRecord _$SimpleClassNullableOfRecordFromJson( + Map<String, dynamic> json) => + SimpleClassNullableOfRecord( + (json['value'] as List<dynamic>?) + ?.map((e) => _$recordConvert( + e, + ($jsonValue) => ( + $jsonValue[r'$1'] as int, + $jsonValue[r'$2'] as String, + truth: $jsonValue['truth'] as bool, + ), + )) + .toList(), + ); + +Map<String, dynamic> _$SimpleClassNullableOfRecordToJson( + SimpleClassNullableOfRecord instance) => + <String, dynamic>{ + 'value': instance.value + ?.map((e) => { + r'$1': e.$1, + r'$2': e.$2, + 'truth': e.truth, + }) + .toList(), + }; + SimpleClassOfString _$SimpleClassOfStringFromJson(Map<String, dynamic> json) => SimpleClassOfString( (json['value'] as List<dynamic>).map((e) => e as String).toList(), diff --git a/json_serializable/test/supported_types/input.type_map.dart b/json_serializable/test/supported_types/input.type_map.dart index ab87400eb..985dbe125 100644 --- a/json_serializable/test/supported_types/input.type_map.dart +++ b/json_serializable/test/supported_types/input.type_map.dart @@ -5499,6 +5499,246 @@ class SimpleClassNullableOfUriToObjectNullable { _$SimpleClassNullableOfUriToObjectNullableToJson(this); } +@JsonSerializable() +class SimpleClassOfBigIntToRecord { + final Map<BigInt, (int, String, {bool truth})> value; + + SimpleClassOfBigIntToRecord( + this.value, + ); + + factory SimpleClassOfBigIntToRecord.fromJson(Map<String, Object?> json) => + _$SimpleClassOfBigIntToRecordFromJson(json); + + Map<String, Object?> toJson() => _$SimpleClassOfBigIntToRecordToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfBigIntToRecord { + final Map<BigInt, (int, String, {bool truth})>? value; + + SimpleClassNullableOfBigIntToRecord( + this.value, + ); + + factory SimpleClassNullableOfBigIntToRecord.fromJson( + Map<String, Object?> json) => + _$SimpleClassNullableOfBigIntToRecordFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassNullableOfBigIntToRecordToJson(this); +} + +@JsonSerializable() +class SimpleClassOfDateTimeToRecord { + final Map<DateTime, (int, String, {bool truth})> value; + + SimpleClassOfDateTimeToRecord( + this.value, + ); + + factory SimpleClassOfDateTimeToRecord.fromJson(Map<String, Object?> json) => + _$SimpleClassOfDateTimeToRecordFromJson(json); + + Map<String, Object?> toJson() => _$SimpleClassOfDateTimeToRecordToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfDateTimeToRecord { + final Map<DateTime, (int, String, {bool truth})>? value; + + SimpleClassNullableOfDateTimeToRecord( + this.value, + ); + + factory SimpleClassNullableOfDateTimeToRecord.fromJson( + Map<String, Object?> json) => + _$SimpleClassNullableOfDateTimeToRecordFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassNullableOfDateTimeToRecordToJson(this); +} + +@JsonSerializable() +class SimpleClassOfDynamicToRecord { + final Map<dynamic, (int, String, {bool truth})> value; + + SimpleClassOfDynamicToRecord( + this.value, + ); + + factory SimpleClassOfDynamicToRecord.fromJson(Map<String, Object?> json) => + _$SimpleClassOfDynamicToRecordFromJson(json); + + Map<String, Object?> toJson() => _$SimpleClassOfDynamicToRecordToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfDynamicToRecord { + final Map<dynamic, (int, String, {bool truth})>? value; + + SimpleClassNullableOfDynamicToRecord( + this.value, + ); + + factory SimpleClassNullableOfDynamicToRecord.fromJson( + Map<String, Object?> json) => + _$SimpleClassNullableOfDynamicToRecordFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassNullableOfDynamicToRecordToJson(this); +} + +@JsonSerializable() +class SimpleClassOfEnumTypeToRecord { + final Map<EnumType, (int, String, {bool truth})> value; + + SimpleClassOfEnumTypeToRecord( + this.value, + ); + + factory SimpleClassOfEnumTypeToRecord.fromJson(Map<String, Object?> json) => + _$SimpleClassOfEnumTypeToRecordFromJson(json); + + Map<String, Object?> toJson() => _$SimpleClassOfEnumTypeToRecordToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfEnumTypeToRecord { + final Map<EnumType, (int, String, {bool truth})>? value; + + SimpleClassNullableOfEnumTypeToRecord( + this.value, + ); + + factory SimpleClassNullableOfEnumTypeToRecord.fromJson( + Map<String, Object?> json) => + _$SimpleClassNullableOfEnumTypeToRecordFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassNullableOfEnumTypeToRecordToJson(this); +} + +@JsonSerializable() +class SimpleClassOfIntToRecord { + final Map<int, (int, String, {bool truth})> value; + + SimpleClassOfIntToRecord( + this.value, + ); + + factory SimpleClassOfIntToRecord.fromJson(Map<String, Object?> json) => + _$SimpleClassOfIntToRecordFromJson(json); + + Map<String, Object?> toJson() => _$SimpleClassOfIntToRecordToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfIntToRecord { + final Map<int, (int, String, {bool truth})>? value; + + SimpleClassNullableOfIntToRecord( + this.value, + ); + + factory SimpleClassNullableOfIntToRecord.fromJson( + Map<String, Object?> json) => + _$SimpleClassNullableOfIntToRecordFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassNullableOfIntToRecordToJson(this); +} + +@JsonSerializable() +class SimpleClassOfObjectToRecord { + final Map<Object, (int, String, {bool truth})> value; + + SimpleClassOfObjectToRecord( + this.value, + ); + + factory SimpleClassOfObjectToRecord.fromJson(Map<String, Object?> json) => + _$SimpleClassOfObjectToRecordFromJson(json); + + Map<String, Object?> toJson() => _$SimpleClassOfObjectToRecordToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfObjectToRecord { + final Map<Object, (int, String, {bool truth})>? value; + + SimpleClassNullableOfObjectToRecord( + this.value, + ); + + factory SimpleClassNullableOfObjectToRecord.fromJson( + Map<String, Object?> json) => + _$SimpleClassNullableOfObjectToRecordFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassNullableOfObjectToRecordToJson(this); +} + +@JsonSerializable() +class SimpleClassOfStringToRecord { + final Map<String, (int, String, {bool truth})> value; + + SimpleClassOfStringToRecord( + this.value, + ); + + factory SimpleClassOfStringToRecord.fromJson(Map<String, Object?> json) => + _$SimpleClassOfStringToRecordFromJson(json); + + Map<String, Object?> toJson() => _$SimpleClassOfStringToRecordToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfStringToRecord { + final Map<String, (int, String, {bool truth})>? value; + + SimpleClassNullableOfStringToRecord( + this.value, + ); + + factory SimpleClassNullableOfStringToRecord.fromJson( + Map<String, Object?> json) => + _$SimpleClassNullableOfStringToRecordFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassNullableOfStringToRecordToJson(this); +} + +@JsonSerializable() +class SimpleClassOfUriToRecord { + final Map<Uri, (int, String, {bool truth})> value; + + SimpleClassOfUriToRecord( + this.value, + ); + + factory SimpleClassOfUriToRecord.fromJson(Map<String, Object?> json) => + _$SimpleClassOfUriToRecordFromJson(json); + + Map<String, Object?> toJson() => _$SimpleClassOfUriToRecordToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfUriToRecord { + final Map<Uri, (int, String, {bool truth})>? value; + + SimpleClassNullableOfUriToRecord( + this.value, + ); + + factory SimpleClassNullableOfUriToRecord.fromJson( + Map<String, Object?> json) => + _$SimpleClassNullableOfUriToRecordFromJson(json); + + Map<String, Object?> toJson() => + _$SimpleClassNullableOfUriToRecordToJson(this); +} + @JsonSerializable() class SimpleClassOfBigIntToString { final Map<BigInt, String> value; diff --git a/json_serializable/test/supported_types/input.type_map.g.dart b/json_serializable/test/supported_types/input.type_map.g.dart index dbda9199a..dc17f2907 100644 --- a/json_serializable/test/supported_types/input.type_map.g.dart +++ b/json_serializable/test/supported_types/input.type_map.g.dart @@ -5281,6 +5281,446 @@ Map<String, dynamic> _$SimpleClassNullableOfUriToObjectNullableToJson( 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), }; +SimpleClassOfBigIntToRecord _$SimpleClassOfBigIntToRecordFromJson( + Map<String, dynamic> json) => + SimpleClassOfBigIntToRecord( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry( + BigInt.parse(k), + _$recordConvert( + e, + ($jsonValue) => ( + $jsonValue[r'$1'] as int, + $jsonValue[r'$2'] as String, + truth: $jsonValue['truth'] as bool, + ), + )), + ), + ); + +Map<String, dynamic> _$SimpleClassOfBigIntToRecordToJson( + SimpleClassOfBigIntToRecord instance) => + <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), { + r'$1': e.$1, + r'$2': e.$2, + 'truth': e.truth, + })), + }; + +$Rec _$recordConvert<$Rec>( + Object? value, + $Rec Function(Map) convert, +) => + convert(value as Map<String, dynamic>); + +SimpleClassNullableOfBigIntToRecord + _$SimpleClassNullableOfBigIntToRecordFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfBigIntToRecord( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry( + BigInt.parse(k), + _$recordConvert( + e, + ($jsonValue) => ( + $jsonValue[r'$1'] as int, + $jsonValue[r'$2'] as String, + truth: $jsonValue['truth'] as bool, + ), + )), + ), + ); + +Map<String, dynamic> _$SimpleClassNullableOfBigIntToRecordToJson( + SimpleClassNullableOfBigIntToRecord instance) => + <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), { + r'$1': e.$1, + r'$2': e.$2, + 'truth': e.truth, + })), + }; + +SimpleClassOfDateTimeToRecord _$SimpleClassOfDateTimeToRecordFromJson( + Map<String, dynamic> json) => + SimpleClassOfDateTimeToRecord( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry( + DateTime.parse(k), + _$recordConvert( + e, + ($jsonValue) => ( + $jsonValue[r'$1'] as int, + $jsonValue[r'$2'] as String, + truth: $jsonValue['truth'] as bool, + ), + )), + ), + ); + +Map<String, dynamic> _$SimpleClassOfDateTimeToRecordToJson( + SimpleClassOfDateTimeToRecord instance) => + <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toIso8601String(), { + r'$1': e.$1, + r'$2': e.$2, + 'truth': e.truth, + })), + }; + +SimpleClassNullableOfDateTimeToRecord + _$SimpleClassNullableOfDateTimeToRecordFromJson( + Map<String, dynamic> json) => + SimpleClassNullableOfDateTimeToRecord( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry( + DateTime.parse(k), + _$recordConvert( + e, + ($jsonValue) => ( + $jsonValue[r'$1'] as int, + $jsonValue[r'$2'] as String, + truth: $jsonValue['truth'] as bool, + ), + )), + ), + ); + +Map<String, dynamic> _$SimpleClassNullableOfDateTimeToRecordToJson( + SimpleClassNullableOfDateTimeToRecord instance) => + <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toIso8601String(), { + r'$1': e.$1, + r'$2': e.$2, + 'truth': e.truth, + })), + }; + +SimpleClassOfDynamicToRecord _$SimpleClassOfDynamicToRecordFromJson( + Map<String, dynamic> json) => + SimpleClassOfDynamicToRecord( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry( + k, + _$recordConvert( + e, + ($jsonValue) => ( + $jsonValue[r'$1'] as int, + $jsonValue[r'$2'] as String, + truth: $jsonValue['truth'] as bool, + ), + )), + ), + ); + +Map<String, dynamic> _$SimpleClassOfDynamicToRecordToJson( + SimpleClassOfDynamicToRecord instance) => + <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k, { + r'$1': e.$1, + r'$2': e.$2, + 'truth': e.truth, + })), + }; + +SimpleClassNullableOfDynamicToRecord + _$SimpleClassNullableOfDynamicToRecordFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfDynamicToRecord( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry( + k, + _$recordConvert( + e, + ($jsonValue) => ( + $jsonValue[r'$1'] as int, + $jsonValue[r'$2'] as String, + truth: $jsonValue['truth'] as bool, + ), + )), + ), + ); + +Map<String, dynamic> _$SimpleClassNullableOfDynamicToRecordToJson( + SimpleClassNullableOfDynamicToRecord instance) => + <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k, { + r'$1': e.$1, + r'$2': e.$2, + 'truth': e.truth, + })), + }; + +SimpleClassOfEnumTypeToRecord _$SimpleClassOfEnumTypeToRecordFromJson( + Map<String, dynamic> json) => + SimpleClassOfEnumTypeToRecord( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry( + $enumDecode(_$EnumTypeEnumMap, k), + _$recordConvert( + e, + ($jsonValue) => ( + $jsonValue[r'$1'] as int, + $jsonValue[r'$2'] as String, + truth: $jsonValue['truth'] as bool, + ), + )), + ), + ); + +Map<String, dynamic> _$SimpleClassOfEnumTypeToRecordToJson( + SimpleClassOfEnumTypeToRecord instance) => + <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, { + r'$1': e.$1, + r'$2': e.$2, + 'truth': e.truth, + })), + }; + +SimpleClassNullableOfEnumTypeToRecord + _$SimpleClassNullableOfEnumTypeToRecordFromJson( + Map<String, dynamic> json) => + SimpleClassNullableOfEnumTypeToRecord( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry( + $enumDecode(_$EnumTypeEnumMap, k), + _$recordConvert( + e, + ($jsonValue) => ( + $jsonValue[r'$1'] as int, + $jsonValue[r'$2'] as String, + truth: $jsonValue['truth'] as bool, + ), + )), + ), + ); + +Map<String, dynamic> _$SimpleClassNullableOfEnumTypeToRecordToJson( + SimpleClassNullableOfEnumTypeToRecord instance) => + <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, { + r'$1': e.$1, + r'$2': e.$2, + 'truth': e.truth, + })), + }; + +SimpleClassOfIntToRecord _$SimpleClassOfIntToRecordFromJson( + Map<String, dynamic> json) => + SimpleClassOfIntToRecord( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry( + int.parse(k), + _$recordConvert( + e, + ($jsonValue) => ( + $jsonValue[r'$1'] as int, + $jsonValue[r'$2'] as String, + truth: $jsonValue['truth'] as bool, + ), + )), + ), + ); + +Map<String, dynamic> _$SimpleClassOfIntToRecordToJson( + SimpleClassOfIntToRecord instance) => + <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), { + r'$1': e.$1, + r'$2': e.$2, + 'truth': e.truth, + })), + }; + +SimpleClassNullableOfIntToRecord _$SimpleClassNullableOfIntToRecordFromJson( + Map<String, dynamic> json) => + SimpleClassNullableOfIntToRecord( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry( + int.parse(k), + _$recordConvert( + e, + ($jsonValue) => ( + $jsonValue[r'$1'] as int, + $jsonValue[r'$2'] as String, + truth: $jsonValue['truth'] as bool, + ), + )), + ), + ); + +Map<String, dynamic> _$SimpleClassNullableOfIntToRecordToJson( + SimpleClassNullableOfIntToRecord instance) => + <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), { + r'$1': e.$1, + r'$2': e.$2, + 'truth': e.truth, + })), + }; + +SimpleClassOfObjectToRecord _$SimpleClassOfObjectToRecordFromJson( + Map<String, dynamic> json) => + SimpleClassOfObjectToRecord( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry( + k, + _$recordConvert( + e, + ($jsonValue) => ( + $jsonValue[r'$1'] as int, + $jsonValue[r'$2'] as String, + truth: $jsonValue['truth'] as bool, + ), + )), + ), + ); + +Map<String, dynamic> _$SimpleClassOfObjectToRecordToJson( + SimpleClassOfObjectToRecord instance) => + <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k, { + r'$1': e.$1, + r'$2': e.$2, + 'truth': e.truth, + })), + }; + +SimpleClassNullableOfObjectToRecord + _$SimpleClassNullableOfObjectToRecordFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfObjectToRecord( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry( + k, + _$recordConvert( + e, + ($jsonValue) => ( + $jsonValue[r'$1'] as int, + $jsonValue[r'$2'] as String, + truth: $jsonValue['truth'] as bool, + ), + )), + ), + ); + +Map<String, dynamic> _$SimpleClassNullableOfObjectToRecordToJson( + SimpleClassNullableOfObjectToRecord instance) => + <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k, { + r'$1': e.$1, + r'$2': e.$2, + 'truth': e.truth, + })), + }; + +SimpleClassOfStringToRecord _$SimpleClassOfStringToRecordFromJson( + Map<String, dynamic> json) => + SimpleClassOfStringToRecord( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry( + k, + _$recordConvert( + e, + ($jsonValue) => ( + $jsonValue[r'$1'] as int, + $jsonValue[r'$2'] as String, + truth: $jsonValue['truth'] as bool, + ), + )), + ), + ); + +Map<String, dynamic> _$SimpleClassOfStringToRecordToJson( + SimpleClassOfStringToRecord instance) => + <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k, { + r'$1': e.$1, + r'$2': e.$2, + 'truth': e.truth, + })), + }; + +SimpleClassNullableOfStringToRecord + _$SimpleClassNullableOfStringToRecordFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfStringToRecord( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry( + k, + _$recordConvert( + e, + ($jsonValue) => ( + $jsonValue[r'$1'] as int, + $jsonValue[r'$2'] as String, + truth: $jsonValue['truth'] as bool, + ), + )), + ), + ); + +Map<String, dynamic> _$SimpleClassNullableOfStringToRecordToJson( + SimpleClassNullableOfStringToRecord instance) => + <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k, { + r'$1': e.$1, + r'$2': e.$2, + 'truth': e.truth, + })), + }; + +SimpleClassOfUriToRecord _$SimpleClassOfUriToRecordFromJson( + Map<String, dynamic> json) => + SimpleClassOfUriToRecord( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry( + Uri.parse(k), + _$recordConvert( + e, + ($jsonValue) => ( + $jsonValue[r'$1'] as int, + $jsonValue[r'$2'] as String, + truth: $jsonValue['truth'] as bool, + ), + )), + ), + ); + +Map<String, dynamic> _$SimpleClassOfUriToRecordToJson( + SimpleClassOfUriToRecord instance) => + <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), { + r'$1': e.$1, + r'$2': e.$2, + 'truth': e.truth, + })), + }; + +SimpleClassNullableOfUriToRecord _$SimpleClassNullableOfUriToRecordFromJson( + Map<String, dynamic> json) => + SimpleClassNullableOfUriToRecord( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry( + Uri.parse(k), + _$recordConvert( + e, + ($jsonValue) => ( + $jsonValue[r'$1'] as int, + $jsonValue[r'$2'] as String, + truth: $jsonValue['truth'] as bool, + ), + )), + ), + ); + +Map<String, dynamic> _$SimpleClassNullableOfUriToRecordToJson( + SimpleClassNullableOfUriToRecord instance) => + <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), { + r'$1': e.$1, + r'$2': e.$2, + 'truth': e.truth, + })), + }; + SimpleClassOfBigIntToString _$SimpleClassOfBigIntToStringFromJson( Map<String, dynamic> json) => SimpleClassOfBigIntToString( diff --git a/json_serializable/test/supported_types/input.type_record.dart b/json_serializable/test/supported_types/input.type_record.dart index 0f226fed3..4f26ab82e 100644 --- a/json_serializable/test/supported_types/input.type_record.dart +++ b/json_serializable/test/supported_types/input.type_record.dart @@ -736,6 +736,39 @@ class SimpleClassNullableOfObjectNullable { _$SimpleClassNullableOfObjectNullableToJson(this); } +typedef SimpleClassOfRecordTypeDef = ( + (int, String, {bool truth}), { + (int, String, {bool truth}) named +}); + +@JsonSerializable() +class SimpleClassOfRecord { + final SimpleClassOfRecordTypeDef value; + + SimpleClassOfRecord( + this.value, + ); + + factory SimpleClassOfRecord.fromJson(Map<String, Object?> json) => + _$SimpleClassOfRecordFromJson(json); + + Map<String, Object?> toJson() => _$SimpleClassOfRecordToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfRecord { + final SimpleClassOfRecordTypeDef? value; + + SimpleClassNullableOfRecord( + this.value, + ); + + factory SimpleClassNullableOfRecord.fromJson(Map<String, Object?> json) => + _$SimpleClassNullableOfRecordFromJson(json); + + Map<String, Object?> toJson() => _$SimpleClassNullableOfRecordToJson(this); +} + typedef SimpleClassOfStringTypeDef = (String, {String named}); @JsonSerializable() diff --git a/json_serializable/test/supported_types/input.type_record.g.dart b/json_serializable/test/supported_types/input.type_record.g.dart index 445701050..19f2da859 100644 --- a/json_serializable/test/supported_types/input.type_record.g.dart +++ b/json_serializable/test/supported_types/input.type_record.g.dart @@ -1039,6 +1039,93 @@ Map<String, dynamic> _$SimpleClassNullableOfObjectNullableToJson( }, }; +SimpleClassOfRecord _$SimpleClassOfRecordFromJson(Map<String, dynamic> json) => + SimpleClassOfRecord( + _$recordConvert( + json['value'], + ($jsonValue) => ( + _$recordConvert( + $jsonValue[r'$1'], + ($jsonValue) => ( + $jsonValue[r'$1'] as int, + $jsonValue[r'$2'] as String, + truth: $jsonValue['truth'] as bool, + ), + ), + named: _$recordConvert( + $jsonValue['named'], + ($jsonValue) => ( + $jsonValue[r'$1'] as int, + $jsonValue[r'$2'] as String, + truth: $jsonValue['truth'] as bool, + ), + ), + ), + ), + ); + +Map<String, dynamic> _$SimpleClassOfRecordToJson( + SimpleClassOfRecord instance) => + <String, dynamic>{ + 'value': { + r'$1': { + r'$1': instance.value.$1.$1, + r'$2': instance.value.$1.$2, + 'truth': instance.value.$1.truth, + }, + 'named': { + r'$1': instance.value.named.$1, + r'$2': instance.value.named.$2, + 'truth': instance.value.named.truth, + }, + }, + }; + +SimpleClassNullableOfRecord _$SimpleClassNullableOfRecordFromJson( + Map<String, dynamic> json) => + SimpleClassNullableOfRecord( + _$recordConvertNullable( + json['value'], + ($jsonValue) => ( + _$recordConvert( + $jsonValue[r'$1'], + ($jsonValue) => ( + $jsonValue[r'$1'] as int, + $jsonValue[r'$2'] as String, + truth: $jsonValue['truth'] as bool, + ), + ), + named: _$recordConvert( + $jsonValue['named'], + ($jsonValue) => ( + $jsonValue[r'$1'] as int, + $jsonValue[r'$2'] as String, + truth: $jsonValue['truth'] as bool, + ), + ), + ), + ), + ); + +Map<String, dynamic> _$SimpleClassNullableOfRecordToJson( + SimpleClassNullableOfRecord instance) => + <String, dynamic>{ + 'value': instance.value == null + ? null + : { + r'$1': { + r'$1': instance.value!.$1.$1, + r'$2': instance.value!.$1.$2, + 'truth': instance.value!.$1.truth, + }, + 'named': { + r'$1': instance.value!.named.$1, + r'$2': instance.value!.named.$2, + 'truth': instance.value!.named.truth, + }, + }, + }; + SimpleClassOfString _$SimpleClassOfStringFromJson(Map<String, dynamic> json) => SimpleClassOfString( _$recordConvert( diff --git a/json_serializable/test/supported_types/input.type_set.dart b/json_serializable/test/supported_types/input.type_set.dart index cfc46748c..398e3f7aa 100644 --- a/json_serializable/test/supported_types/input.type_set.dart +++ b/json_serializable/test/supported_types/input.type_set.dart @@ -689,6 +689,34 @@ class SimpleClassNullableOfObjectNullable { _$SimpleClassNullableOfObjectNullableToJson(this); } +@JsonSerializable() +class SimpleClassOfRecord { + final Set<(int, String, {bool truth})> value; + + SimpleClassOfRecord( + this.value, + ); + + factory SimpleClassOfRecord.fromJson(Map<String, Object?> json) => + _$SimpleClassOfRecordFromJson(json); + + Map<String, Object?> toJson() => _$SimpleClassOfRecordToJson(this); +} + +@JsonSerializable() +class SimpleClassNullableOfRecord { + final Set<(int, String, {bool truth})>? value; + + SimpleClassNullableOfRecord( + this.value, + ); + + factory SimpleClassNullableOfRecord.fromJson(Map<String, Object?> json) => + _$SimpleClassNullableOfRecordFromJson(json); + + Map<String, Object?> toJson() => _$SimpleClassNullableOfRecordToJson(this); +} + @JsonSerializable() class SimpleClassOfString { final Set<String> value; diff --git a/json_serializable/test/supported_types/input.type_set.g.dart b/json_serializable/test/supported_types/input.type_set.g.dart index dc8ed047f..861b0c4fe 100644 --- a/json_serializable/test/supported_types/input.type_set.g.dart +++ b/json_serializable/test/supported_types/input.type_set.g.dart @@ -619,6 +619,65 @@ Map<String, dynamic> _$SimpleClassNullableOfObjectNullableToJson( 'value': instance.value?.toList(), }; +SimpleClassOfRecord _$SimpleClassOfRecordFromJson(Map<String, dynamic> json) => + SimpleClassOfRecord( + (json['value'] as List<dynamic>) + .map((e) => _$recordConvert( + e, + ($jsonValue) => ( + $jsonValue[r'$1'] as int, + $jsonValue[r'$2'] as String, + truth: $jsonValue['truth'] as bool, + ), + )) + .toSet(), + ); + +Map<String, dynamic> _$SimpleClassOfRecordToJson( + SimpleClassOfRecord instance) => + <String, dynamic>{ + 'value': instance.value + .map((e) => { + r'$1': e.$1, + r'$2': e.$2, + 'truth': e.truth, + }) + .toList(), + }; + +$Rec _$recordConvert<$Rec>( + Object? value, + $Rec Function(Map) convert, +) => + convert(value as Map<String, dynamic>); + +SimpleClassNullableOfRecord _$SimpleClassNullableOfRecordFromJson( + Map<String, dynamic> json) => + SimpleClassNullableOfRecord( + (json['value'] as List<dynamic>?) + ?.map((e) => _$recordConvert( + e, + ($jsonValue) => ( + $jsonValue[r'$1'] as int, + $jsonValue[r'$2'] as String, + truth: $jsonValue['truth'] as bool, + ), + )) + .toSet(), + ); + +Map<String, dynamic> _$SimpleClassNullableOfRecordToJson( + SimpleClassNullableOfRecord instance) => + <String, dynamic>{ + 'value': instance.value + ?.map((e) => { + r'$1': e.$1, + r'$2': e.$2, + 'truth': e.truth, + }) + .toList(), + }; + SimpleClassOfString _$SimpleClassOfStringFromJson(Map<String, dynamic> json) => SimpleClassOfString( (json['value'] as List<dynamic>).map((e) => e as String).toSet(), diff --git a/json_serializable/test/supported_types/support_types_extra_tests.dart b/json_serializable/test/supported_types/support_types_extra_test.dart similarity index 78% rename from json_serializable/test/supported_types/support_types_extra_tests.dart rename to json_serializable/test/supported_types/support_types_extra_test.dart index 8ce83f390..4a02b2ade 100644 --- a/json_serializable/test/supported_types/support_types_extra_tests.dart +++ b/json_serializable/test/supported_types/support_types_extra_test.dart @@ -74,4 +74,26 @@ void main() { ); expect(loudEncode(object2), encoded); }); + + test('SimpleClassOfStringToRecord', () { + const value = { + 'value': { + 'key': { + r'$1': 1, + r'$2': 'string', + 'truth': false, + } + } + }; + + final object = SimpleClassOfStringToRecord.fromJson(value); + final encoded = loudEncode(object); + + expect(encoded, loudEncode(value)); + + final object2 = SimpleClassOfStringToRecord.fromJson( + jsonDecode(encoded) as Map<String, Object?>, + ); + expect(loudEncode(object2), encoded); + }); } diff --git a/json_serializable/tool/test_type_builder.dart b/json_serializable/tool/test_type_builder.dart index 31f96c3ba..050231041 100644 --- a/json_serializable/tool/test_type_builder.dart +++ b/json_serializable/tool/test_type_builder.dart @@ -111,6 +111,7 @@ final _iterableGenericArgs = ([ 'FromJsonNullableObjectParam', 'FromJsonObjectParam', 'dynamic', + recordType, ]..sort(compareAsciiLowerCase)) .toSet(); diff --git a/json_serializable/tool/test_type_data.dart b/json_serializable/tool/test_type_data.dart index 3b6366d00..53ffb5b1c 100644 --- a/json_serializable/tool/test_type_data.dart +++ b/json_serializable/tool/test_type_data.dart @@ -83,17 +83,31 @@ class TestTypeData { ), ); + const sampleRecordDefinition = '(int, String, {bool truth})'; + for (var genericArg in genericArgs) { final genericArgClassPart = _genericClassPart(genericArg); final theName = 'SimpleClassOf$genericArgClassPart'; + var genericArgFixed = genericArg; + + if (genericArgFixed == recordType) { + genericArgFixed = sampleRecordDefinition; + } + + genericArgFixed = genericArgFixed.replaceFirst( + ',$recordType', + ',$sampleRecordDefinition', + ); + final genericType = - type == recordType ? '${theName}TypeDef' : '$type<$genericArg>'; + type == recordType ? '${theName}TypeDef' : '$type<$genericArgFixed>'; if (type == recordType) { buffer.writeln( - 'typedef $genericType = ($genericArg, {$genericArg named});', + 'typedef $genericType = ' + '($genericArgFixed, {$genericArgFixed named});', ); } From 1632d28a405ffadc91f951c2afa796f65bc16c99 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@google.com> Date: Fri, 26 May 2023 07:54:03 -0700 Subject: [PATCH 492/569] latest mono_repo --- .github/workflows/dart.yml | 4 ++-- tool/ci.sh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 43bc120f6..c43b128da 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -1,4 +1,4 @@ -# Created with package:mono_repo v6.5.4 +# Created with package:mono_repo v6.5.7 name: Dart CI on: push: @@ -36,7 +36,7 @@ jobs: name: Checkout repository uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab - name: mono_repo self validate - run: dart pub global activate mono_repo 6.5.4 + run: dart pub global activate mono_repo 6.5.7 - name: mono_repo self validate run: dart pub global run mono_repo generate --validate job_002: diff --git a/tool/ci.sh b/tool/ci.sh index a70cf4343..436465312 100755 --- a/tool/ci.sh +++ b/tool/ci.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Created with package:mono_repo v6.5.4 +# Created with package:mono_repo v6.5.7 # Support built in commands on windows out of the box. # When it is a flutter repo (check the pubspec.yaml for "sdk: flutter") From 288dbdb915481555c8dc7a73d3820d992a5b8ab8 Mon Sep 17 00:00:00 2001 From: Jaap Aarts <JAicewizard@users.noreply.github.com> Date: Wed, 14 Jun 2023 22:45:23 +0200 Subject: [PATCH 493/569] Unify dart and flutter generation instructions (#1329) Unify dart and flutter generation instructions --- json_serializable/README.md | 5 +---- json_serializable/tool/readme/readme_template.md | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/json_serializable/README.md b/json_serializable/README.md index 5e7498540..cb1eec619 100644 --- a/json_serializable/README.md +++ b/json_serializable/README.md @@ -75,10 +75,7 @@ Map<String, dynamic> _$PersonToJson(Person instance) => <String, dynamic>{ Once you have added the annotations to your code you then need to run the code generator to generate the missing `.g.dart` generated dart files. -With a Dart package, run `dart run build_runner build` in the package directory. - -With a Flutter package, run `flutter pub run build_runner build` in your package -directory. +Run `dart run build_runner build` in the package directory. # Annotation values diff --git a/json_serializable/tool/readme/readme_template.md b/json_serializable/tool/readme/readme_template.md index d8de00352..79ac1c7dd 100644 --- a/json_serializable/tool/readme/readme_template.md +++ b/json_serializable/tool/readme/readme_template.md @@ -35,10 +35,7 @@ Building creates the corresponding part `example.g.dart`: Once you have added the annotations to your code you then need to run the code generator to generate the missing `.g.dart` generated dart files. -With a Dart package, run `dart run build_runner build` in the package directory. - -With a Flutter package, run `flutter pub run build_runner build` in your package -directory. +Run `dart run build_runner build` in the package directory. # Annotation values From facdb5e5bd26e92d516017092cee49a213d05ecc Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Fri, 30 Jun 2023 15:07:27 -0700 Subject: [PATCH 494/569] Support latest pkg:analyzer, release v6.7.1 (#1333) --- json_serializable/CHANGELOG.md | 4 ++++ json_serializable/pubspec.yaml | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 0effefc60..49a067ba7 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,7 @@ +## 6.7.1 + +- Support the latest `package:analyzer`. + ## 6.7.0 - Support `Record` types. diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index d64039063..cfb3dd8a8 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 6.7.0 +version: 6.7.1 description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. @@ -13,7 +13,7 @@ topics: - codegen dependencies: - analyzer: ^5.12.0 + analyzer: '>=5.12.0 <7.0.0' async: ^2.8.0 build: ^2.0.0 build_config: '>=0.4.4 <2.0.0' From 2185e8b80d8d0c12e2adbf897d920b6f5725cded Mon Sep 17 00:00:00 2001 From: CicadaCinema <52425971+CicadaCinema@users.noreply.github.com> Date: Tue, 11 Jul 2023 03:28:03 +0100 Subject: [PATCH 495/569] add Example.property field to docstring in example (#1337) --- json_annotation/lib/src/json_converter.dart | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/json_annotation/lib/src/json_converter.dart b/json_annotation/lib/src/json_converter.dart index fefe88ece..bd0738e80 100644 --- a/json_annotation/lib/src/json_converter.dart +++ b/json_annotation/lib/src/json_converter.dart @@ -19,7 +19,9 @@ /// /// @JsonSerializable() /// @MyJsonConverter() -/// class Example {} +/// class Example { +/// final Value property; +/// } /// ``` /// /// or on a property: @@ -36,7 +38,9 @@ /// /// ```dart /// @JsonSerializable(converters: [MyJsonConverter()]) -/// class Example {} +/// class Example { +/// final Value property; +/// } /// ``` abstract class JsonConverter<T, S> { const JsonConverter(); From 4e8e9ac2b14824787f08cfab94c44d9671e10ab0 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Tue, 8 Aug 2023 09:10:23 -0700 Subject: [PATCH 496/569] Require Dart 3 across the board, use switch expressions (#1344) --- .github/workflows/dart.yml | 258 ++++++------------ checked_yaml/CHANGELOG.md | 4 + checked_yaml/pubspec.yaml | 4 +- json_annotation/CHANGELOG.md | 4 + json_annotation/pubspec.yaml | 4 +- json_serializable/lib/src/utils.dart | 22 +- .../test/integration/json_test_common.dart | 15 +- shared_test/pubspec.yaml | 2 +- 8 files changed, 107 insertions(+), 206 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index c43b128da..6c8269f52 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -40,80 +40,16 @@ jobs: - name: mono_repo self validate run: dart pub global run mono_repo generate --validate job_002: - name: "analyzer_and_format; Dart 2.19.0; PKG: checked_yaml; `dart format --output=none --set-exit-if-changed .`, `dart analyze --fatal-infos .`" + name: "analyzer_and_format; Dart 3.0.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; `dart format --output=none --set-exit-if-changed .`, `dart analyze --fatal-infos .`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0;packages:checked_yaml;commands:format-analyze_0" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:format-analyze_0" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0;packages:checked_yaml - os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0 - os:ubuntu-latest;pub-cache-hosted - os:ubuntu-latest - - name: Setup Dart SDK - uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f - with: - sdk: "2.19.0" - - id: checkout - name: Checkout repository - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab - - id: checked_yaml_pub_upgrade - name: checked_yaml; dart pub upgrade - run: dart pub upgrade - if: "always() && steps.checkout.conclusion == 'success'" - working-directory: checked_yaml - - name: "checked_yaml; dart format --output=none --set-exit-if-changed ." - run: "dart format --output=none --set-exit-if-changed ." - if: "always() && steps.checked_yaml_pub_upgrade.conclusion == 'success'" - working-directory: checked_yaml - - name: "checked_yaml; dart analyze --fatal-infos ." - run: dart analyze --fatal-infos . - if: "always() && steps.checked_yaml_pub_upgrade.conclusion == 'success'" - working-directory: checked_yaml - job_003: - name: "analyzer_and_format; Dart 2.19.0; PKG: json_annotation; `dart analyze`" - runs-on: ubuntu-latest - steps: - - name: Cache Pub hosted dependencies - uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 - with: - path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0;packages:json_annotation;commands:analyze_1" - restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0;packages:json_annotation - os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0 - os:ubuntu-latest;pub-cache-hosted - os:ubuntu-latest - - name: Setup Dart SDK - uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f - with: - sdk: "2.19.0" - - id: checkout - name: Checkout repository - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab - - id: json_annotation_pub_upgrade - name: json_annotation; dart pub upgrade - run: dart pub upgrade - if: "always() && steps.checkout.conclusion == 'success'" - working-directory: json_annotation - - name: json_annotation; dart analyze - run: dart analyze - if: "always() && steps.json_annotation_pub_upgrade.conclusion == 'success'" - working-directory: json_annotation - job_004: - name: "analyzer_and_format; Dart 3.0.0; PKGS: _test_yaml, example, json_serializable; `dart format --output=none --set-exit-if-changed .`, `dart analyze --fatal-infos .`" - runs-on: ubuntu-latest - steps: - - name: Cache Pub hosted dependencies - uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 - with: - path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:_test_yaml-example-json_serializable;commands:format-analyze_0" - restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:_test_yaml-example-json_serializable + os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:_test_yaml-checked_yaml-example-json_serializable os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest @@ -137,6 +73,19 @@ jobs: run: dart analyze --fatal-infos . if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" working-directory: _test_yaml + - id: checked_yaml_pub_upgrade + name: checked_yaml; dart pub upgrade + run: dart pub upgrade + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: checked_yaml + - name: "checked_yaml; dart format --output=none --set-exit-if-changed ." + run: "dart format --output=none --set-exit-if-changed ." + if: "always() && steps.checked_yaml_pub_upgrade.conclusion == 'success'" + working-directory: checked_yaml + - name: "checked_yaml; dart analyze --fatal-infos ." + run: dart analyze --fatal-infos . + if: "always() && steps.checked_yaml_pub_upgrade.conclusion == 'success'" + working-directory: checked_yaml - id: example_pub_upgrade name: example; dart pub upgrade run: dart pub upgrade @@ -163,7 +112,37 @@ jobs: run: dart analyze --fatal-infos . if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" working-directory: json_serializable - job_005: + job_003: + name: "analyzer_and_format; Dart 3.0.0; PKG: json_annotation; `dart analyze`" + runs-on: ubuntu-latest + steps: + - name: Cache Pub hosted dependencies + uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 + with: + path: "~/.pub-cache/hosted" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:json_annotation;commands:analyze_1" + restore-keys: | + os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:json_annotation + os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0 + os:ubuntu-latest;pub-cache-hosted + os:ubuntu-latest + - name: Setup Dart SDK + uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f + with: + sdk: "3.0.0" + - id: checkout + name: Checkout repository + uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab + - id: json_annotation_pub_upgrade + name: json_annotation; dart pub upgrade + run: dart pub upgrade + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: json_annotation + - name: json_annotation; dart analyze + run: dart analyze + if: "always() && steps.json_annotation_pub_upgrade.conclusion == 'success'" + working-directory: json_annotation + job_004: name: "analyzer_and_format; Dart dev; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; `dart format --output=none --set-exit-if-changed .`, `dart analyze --fatal-infos .`" runs-on: ubuntu-latest steps: @@ -249,53 +228,17 @@ jobs: run: dart analyze --fatal-infos . if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" working-directory: json_serializable - job_006: - name: "unit_test; Dart 2.19.0; PKG: checked_yaml; `dart test`" - runs-on: ubuntu-latest - steps: - - name: Cache Pub hosted dependencies - uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 - with: - path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0;packages:checked_yaml;commands:test_0" - restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0;packages:checked_yaml - os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0 - os:ubuntu-latest;pub-cache-hosted - os:ubuntu-latest - - name: Setup Dart SDK - uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f - with: - sdk: "2.19.0" - - id: checkout - name: Checkout repository - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab - - id: checked_yaml_pub_upgrade - name: checked_yaml; dart pub upgrade - run: dart pub upgrade - if: "always() && steps.checkout.conclusion == 'success'" - working-directory: checked_yaml - - name: checked_yaml; dart test - run: dart test - if: "always() && steps.checked_yaml_pub_upgrade.conclusion == 'success'" - working-directory: checked_yaml - needs: - - job_001 - - job_002 - - job_003 - - job_004 - - job_005 - job_007: - name: "unit_test; Dart 3.0.0; PKGS: _test_yaml, example, json_serializable; `dart test`" + job_005: + name: "unit_test; Dart 3.0.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; `dart test`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:_test_yaml-example-json_serializable;commands:test_0" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:_test_yaml-example-json_serializable + os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:_test_yaml-checked_yaml-example-json_serializable os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest @@ -315,6 +258,15 @@ jobs: run: dart test if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" working-directory: _test_yaml + - id: checked_yaml_pub_upgrade + name: checked_yaml; dart pub upgrade + run: dart pub upgrade + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: checked_yaml + - name: checked_yaml; dart test + run: dart test + if: "always() && steps.checked_yaml_pub_upgrade.conclusion == 'success'" + working-directory: checked_yaml - id: example_pub_upgrade name: example; dart pub upgrade run: dart pub upgrade @@ -338,8 +290,7 @@ jobs: - job_002 - job_003 - job_004 - - job_005 - job_008: + job_006: name: "unit_test; Dart 3.0.0; PKG: json_serializable; `dart test --run-skipped -t presubmit-only test/annotation_version_test.dart`" runs-on: ubuntu-latest steps: @@ -374,8 +325,7 @@ jobs: - job_002 - job_003 - job_004 - - job_005 - job_009: + job_007: name: "unit_test; Dart 3.0.0; PKG: json_serializable; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest steps: @@ -410,8 +360,7 @@ jobs: - job_002 - job_003 - job_004 - - job_005 - job_010: + job_008: name: "unit_test; Dart 3.0.0; PKG: json_serializable; `dart test -p chrome`" runs-on: ubuntu-latest steps: @@ -446,8 +395,7 @@ jobs: - job_002 - job_003 - job_004 - - job_005 - job_011: + job_009: name: "unit_test; Dart dev; PKGS: _test_yaml, checked_yaml, example, json_serializable; `dart test`" runs-on: ubuntu-latest steps: @@ -509,8 +457,7 @@ jobs: - job_002 - job_003 - job_004 - - job_005 - job_012: + job_010: name: "unit_test; Dart dev; PKG: json_serializable; `dart test --run-skipped -t presubmit-only test/annotation_version_test.dart`" runs-on: ubuntu-latest steps: @@ -545,8 +492,7 @@ jobs: - job_002 - job_003 - job_004 - - job_005 - job_013: + job_011: name: "unit_test; Dart dev; PKG: json_serializable; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest steps: @@ -581,8 +527,7 @@ jobs: - job_002 - job_003 - job_004 - - job_005 - job_014: + job_012: name: "unit_test; Dart dev; PKG: json_serializable; `dart test -p chrome`" runs-on: ubuntu-latest steps: @@ -617,63 +562,17 @@ jobs: - job_002 - job_003 - job_004 - - job_005 - job_015: - name: "ensure_build; Dart 2.19.0; PKG: checked_yaml; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" - runs-on: ubuntu-latest - steps: - - name: Cache Pub hosted dependencies - uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 - with: - path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0;packages:checked_yaml;commands:test_1" - restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0;packages:checked_yaml - os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0 - os:ubuntu-latest;pub-cache-hosted - os:ubuntu-latest - - name: Setup Dart SDK - uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f - with: - sdk: "2.19.0" - - id: checkout - name: Checkout repository - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab - - id: checked_yaml_pub_upgrade - name: checked_yaml; dart pub upgrade - run: dart pub upgrade - if: "always() && steps.checkout.conclusion == 'success'" - working-directory: checked_yaml - - name: "checked_yaml; dart test --run-skipped -t presubmit-only test/ensure_build_test.dart" - run: dart test --run-skipped -t presubmit-only test/ensure_build_test.dart - if: "always() && steps.checked_yaml_pub_upgrade.conclusion == 'success'" - working-directory: checked_yaml - needs: - - job_001 - - job_002 - - job_003 - - job_004 - - job_005 - - job_006 - - job_007 - - job_008 - - job_009 - - job_010 - - job_011 - - job_012 - - job_013 - - job_014 - job_016: - name: "ensure_build; Dart 3.0.0; PKGS: _test_yaml, example; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" + job_013: + name: "ensure_build; Dart 3.0.0; PKGS: _test_yaml, checked_yaml, example; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:_test_yaml-example;commands:test_1" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:_test_yaml-checked_yaml-example;commands:test_1" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:_test_yaml-example + os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:_test_yaml-checked_yaml-example os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest @@ -693,6 +592,15 @@ jobs: run: dart test --run-skipped -t presubmit-only test/ensure_build_test.dart if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" working-directory: _test_yaml + - id: checked_yaml_pub_upgrade + name: checked_yaml; dart pub upgrade + run: dart pub upgrade + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: checked_yaml + - name: "checked_yaml; dart test --run-skipped -t presubmit-only test/ensure_build_test.dart" + run: dart test --run-skipped -t presubmit-only test/ensure_build_test.dart + if: "always() && steps.checked_yaml_pub_upgrade.conclusion == 'success'" + working-directory: checked_yaml - id: example_pub_upgrade name: example; dart pub upgrade run: dart pub upgrade @@ -715,9 +623,7 @@ jobs: - job_010 - job_011 - job_012 - - job_013 - - job_014 - job_017: + job_014: name: "ensure_build; Dart dev; PKGS: _test_yaml, checked_yaml, example; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest steps: @@ -778,5 +684,3 @@ jobs: - job_010 - job_011 - job_012 - - job_013 - - job_014 diff --git a/checked_yaml/CHANGELOG.md b/checked_yaml/CHANGELOG.md index bcecf04d6..18603be88 100644 --- a/checked_yaml/CHANGELOG.md +++ b/checked_yaml/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.0.4-wip + +- Require Dart 3.0 + ## 2.0.3 - Require Dart 2.19 diff --git a/checked_yaml/pubspec.yaml b/checked_yaml/pubspec.yaml index 1b2e74eec..c164cab1a 100644 --- a/checked_yaml/pubspec.yaml +++ b/checked_yaml/pubspec.yaml @@ -1,5 +1,5 @@ name: checked_yaml -version: 2.0.3 +version: 2.0.4-wip description: >- Generate more helpful exceptions when decoding YAML documents using @@ -13,7 +13,7 @@ topics: - codegen environment: - sdk: '>=2.19.0 <3.0.0' + sdk: ^3.0.0 dependencies: json_annotation: ^4.3.0 diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index ee6b48c33..5929a6840 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -1,3 +1,7 @@ +## 4.8.2-wip + +- Require Dart 3.0 + ## 4.8.1 - Require Dart 2.19 diff --git a/json_annotation/pubspec.yaml b/json_annotation/pubspec.yaml index 64bc29b2a..ce60661f9 100644 --- a/json_annotation/pubspec.yaml +++ b/json_annotation/pubspec.yaml @@ -1,5 +1,5 @@ name: json_annotation -version: 4.8.1 +version: 4.8.2-wip description: >- Classes and helper functions that support JSON code generation via the `json_serializable` package. @@ -11,7 +11,7 @@ topics: - codegen environment: - sdk: '>=2.19.0 <3.0.0' + sdk: ^3.0.0 dependencies: meta: ^1.4.0 diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index 8163247c1..941b7492a 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -182,20 +182,14 @@ String ifNullOrElse(String test, String ifNull, String ifNotNull) => String encodedFieldName( FieldRename fieldRename, String declaredName, -) { - switch (fieldRename) { - case FieldRename.none: - return declaredName; - case FieldRename.snake: - return declaredName.snake; - case FieldRename.screamingSnake: - return declaredName.snake.toUpperCase(); - case FieldRename.kebab: - return declaredName.kebab; - case FieldRename.pascal: - return declaredName.pascal; - } -} +) => + switch (fieldRename) { + FieldRename.none => declaredName, + FieldRename.snake => declaredName.snake, + FieldRename.screamingSnake => declaredName.snake.toUpperCase(), + FieldRename.kebab => declaredName.kebab, + FieldRename.pascal => declaredName.pascal + }; /// Return the Dart code presentation for the given [type]. /// diff --git a/json_serializable/test/integration/json_test_common.dart b/json_serializable/test/integration/json_test_common.dart index fb7c4d212..d16c3b954 100644 --- a/json_serializable/test/integration/json_test_common.dart +++ b/json_serializable/test/integration/json_test_common.dart @@ -51,16 +51,11 @@ class Platform { const Platform._(this.description); - factory Platform.fromJson(String value) { - switch (value) { - case 'foo': - return foo; - case 'undefined': - return undefined; - default: - throw ArgumentError.value(value, 'value', 'Not a supported value.'); - } - } + factory Platform.fromJson(String value) => switch (value) { + 'foo' => foo, + 'undefined' => undefined, + _ => throw ArgumentError.value(value, 'value', 'Not a supported value.') + }; String toJson() => description; } diff --git a/shared_test/pubspec.yaml b/shared_test/pubspec.yaml index ab560ef00..c52b9527e 100644 --- a/shared_test/pubspec.yaml +++ b/shared_test/pubspec.yaml @@ -1,7 +1,7 @@ name: _json_serial_shared_test publish_to: none environment: - sdk: '>=2.19.0 <3.0.0' + sdk: ^3.0.0 dependencies: stack_trace: ^1.10.0 From ff0e0fd84a955a7ccd41d0478268f5764794a93c Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Wed, 9 Aug 2023 08:49:56 -0700 Subject: [PATCH 497/569] Standardize analyze across packages (#1345) - analyze fatal infos + format on dev - just analyze on "pubspec" --- .github/workflows/dart.yml | 105 +++++++++----------------------- _test_yaml/mono_pkg.yaml | 4 ++ checked_yaml/mono_pkg.yaml | 5 +- example/mono_pkg.yaml | 4 ++ json_serializable/mono_pkg.yaml | 4 ++ 5 files changed, 45 insertions(+), 77 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 6c8269f52..65680329f 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -40,16 +40,16 @@ jobs: - name: mono_repo self validate run: dart pub global run mono_repo generate --validate job_002: - name: "analyzer_and_format; Dart 3.0.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; `dart format --output=none --set-exit-if-changed .`, `dart analyze --fatal-infos .`" + name: "analyzer_and_format; Dart 3.0.0; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; `dart analyze`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:format-analyze_0" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:analyze_1" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:_test_yaml-checked_yaml-example-json_serializable + os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest @@ -65,12 +65,8 @@ jobs: run: dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: _test_yaml - - name: "_test_yaml; dart format --output=none --set-exit-if-changed ." - run: "dart format --output=none --set-exit-if-changed ." - if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" - working-directory: _test_yaml - - name: "_test_yaml; dart analyze --fatal-infos ." - run: dart analyze --fatal-infos . + - name: _test_yaml; dart analyze + run: dart analyze if: "always() && steps._test_yaml_pub_upgrade.conclusion == 'success'" working-directory: _test_yaml - id: checked_yaml_pub_upgrade @@ -78,12 +74,8 @@ jobs: run: dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: checked_yaml - - name: "checked_yaml; dart format --output=none --set-exit-if-changed ." - run: "dart format --output=none --set-exit-if-changed ." - if: "always() && steps.checked_yaml_pub_upgrade.conclusion == 'success'" - working-directory: checked_yaml - - name: "checked_yaml; dart analyze --fatal-infos ." - run: dart analyze --fatal-infos . + - name: checked_yaml; dart analyze + run: dart analyze if: "always() && steps.checked_yaml_pub_upgrade.conclusion == 'success'" working-directory: checked_yaml - id: example_pub_upgrade @@ -91,48 +83,10 @@ jobs: run: dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: example - - name: "example; dart format --output=none --set-exit-if-changed ." - run: "dart format --output=none --set-exit-if-changed ." - if: "always() && steps.example_pub_upgrade.conclusion == 'success'" - working-directory: example - - name: "example; dart analyze --fatal-infos ." - run: dart analyze --fatal-infos . + - name: example; dart analyze + run: dart analyze if: "always() && steps.example_pub_upgrade.conclusion == 'success'" working-directory: example - - id: json_serializable_pub_upgrade - name: json_serializable; dart pub upgrade - run: dart pub upgrade - if: "always() && steps.checkout.conclusion == 'success'" - working-directory: json_serializable - - name: "json_serializable; dart format --output=none --set-exit-if-changed ." - run: "dart format --output=none --set-exit-if-changed ." - if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" - working-directory: json_serializable - - name: "json_serializable; dart analyze --fatal-infos ." - run: dart analyze --fatal-infos . - if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" - working-directory: json_serializable - job_003: - name: "analyzer_and_format; Dart 3.0.0; PKG: json_annotation; `dart analyze`" - runs-on: ubuntu-latest - steps: - - name: Cache Pub hosted dependencies - uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 - with: - path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:json_annotation;commands:analyze_1" - restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:json_annotation - os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0 - os:ubuntu-latest;pub-cache-hosted - os:ubuntu-latest - - name: Setup Dart SDK - uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f - with: - sdk: "3.0.0" - - id: checkout - name: Checkout repository - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab - id: json_annotation_pub_upgrade name: json_annotation; dart pub upgrade run: dart pub upgrade @@ -142,7 +96,16 @@ jobs: run: dart analyze if: "always() && steps.json_annotation_pub_upgrade.conclusion == 'success'" working-directory: json_annotation - job_004: + - id: json_serializable_pub_upgrade + name: json_serializable; dart pub upgrade + run: dart pub upgrade + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: json_serializable + - name: json_serializable; dart analyze + run: dart analyze + if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" + working-directory: json_serializable + job_003: name: "analyzer_and_format; Dart dev; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; `dart format --output=none --set-exit-if-changed .`, `dart analyze --fatal-infos .`" runs-on: ubuntu-latest steps: @@ -228,7 +191,7 @@ jobs: run: dart analyze --fatal-infos . if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" working-directory: json_serializable - job_005: + job_004: name: "unit_test; Dart 3.0.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; `dart test`" runs-on: ubuntu-latest steps: @@ -289,8 +252,7 @@ jobs: - job_001 - job_002 - job_003 - - job_004 - job_006: + job_005: name: "unit_test; Dart 3.0.0; PKG: json_serializable; `dart test --run-skipped -t presubmit-only test/annotation_version_test.dart`" runs-on: ubuntu-latest steps: @@ -324,8 +286,7 @@ jobs: - job_001 - job_002 - job_003 - - job_004 - job_007: + job_006: name: "unit_test; Dart 3.0.0; PKG: json_serializable; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest steps: @@ -359,8 +320,7 @@ jobs: - job_001 - job_002 - job_003 - - job_004 - job_008: + job_007: name: "unit_test; Dart 3.0.0; PKG: json_serializable; `dart test -p chrome`" runs-on: ubuntu-latest steps: @@ -394,8 +354,7 @@ jobs: - job_001 - job_002 - job_003 - - job_004 - job_009: + job_008: name: "unit_test; Dart dev; PKGS: _test_yaml, checked_yaml, example, json_serializable; `dart test`" runs-on: ubuntu-latest steps: @@ -456,8 +415,7 @@ jobs: - job_001 - job_002 - job_003 - - job_004 - job_010: + job_009: name: "unit_test; Dart dev; PKG: json_serializable; `dart test --run-skipped -t presubmit-only test/annotation_version_test.dart`" runs-on: ubuntu-latest steps: @@ -491,8 +449,7 @@ jobs: - job_001 - job_002 - job_003 - - job_004 - job_011: + job_010: name: "unit_test; Dart dev; PKG: json_serializable; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest steps: @@ -526,8 +483,7 @@ jobs: - job_001 - job_002 - job_003 - - job_004 - job_012: + job_011: name: "unit_test; Dart dev; PKG: json_serializable; `dart test -p chrome`" runs-on: ubuntu-latest steps: @@ -561,8 +517,7 @@ jobs: - job_001 - job_002 - job_003 - - job_004 - job_013: + job_012: name: "ensure_build; Dart 3.0.0; PKGS: _test_yaml, checked_yaml, example; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest steps: @@ -622,8 +577,7 @@ jobs: - job_009 - job_010 - job_011 - - job_012 - job_014: + job_013: name: "ensure_build; Dart dev; PKGS: _test_yaml, checked_yaml, example; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest steps: @@ -683,4 +637,3 @@ jobs: - job_009 - job_010 - job_011 - - job_012 diff --git a/_test_yaml/mono_pkg.yaml b/_test_yaml/mono_pkg.yaml index 497ed5d8c..840b0b117 100644 --- a/_test_yaml/mono_pkg.yaml +++ b/_test_yaml/mono_pkg.yaml @@ -8,6 +8,10 @@ stages: - group: - format - analyze: --fatal-infos . + sdk: dev + - group: + - analyze + sdk: pubspec - unit_test: - test - ensure_build: diff --git a/checked_yaml/mono_pkg.yaml b/checked_yaml/mono_pkg.yaml index 667b27cd5..e31657400 100644 --- a/checked_yaml/mono_pkg.yaml +++ b/checked_yaml/mono_pkg.yaml @@ -8,7 +8,10 @@ stages: - group: - format - analyze: --fatal-infos . - + sdk: dev + - group: + - analyze + sdk: pubspec - unit_test: - test - ensure_build: diff --git a/example/mono_pkg.yaml b/example/mono_pkg.yaml index 158b67b19..8ab9954ed 100644 --- a/example/mono_pkg.yaml +++ b/example/mono_pkg.yaml @@ -8,6 +8,10 @@ stages: - group: - format - analyze: --fatal-infos . + sdk: dev + - group: + - analyze + sdk: pubspec - unit_test: - test - ensure_build: diff --git a/json_serializable/mono_pkg.yaml b/json_serializable/mono_pkg.yaml index 6da59e995..aed7819e8 100644 --- a/json_serializable/mono_pkg.yaml +++ b/json_serializable/mono_pkg.yaml @@ -8,6 +8,10 @@ stages: - group: - format - analyze: --fatal-infos . + sdk: dev + - group: + - analyze + sdk: pubspec - unit_test: - test: - test: -p chrome From aee214d96c68447d4c9fff9ab455e0014e20fca3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 1 Sep 2023 12:07:05 -0700 Subject: [PATCH 498/569] Bump actions/setup-node from 3.6.0 to 3.8.1 (#1352) Bumps [actions/setup-node](https://github.com/actions/setup-node) from 3.6.0 to 3.8.1. - [Release notes](https://github.com/actions/setup-node/releases) - [Commits](https://github.com/actions/setup-node/compare/64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c...5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d) --- updated-dependencies: - dependency-name: actions/setup-node dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/markdown_linter.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/markdown_linter.yml b/.github/workflows/markdown_linter.yml index 5186f95cb..1658a0086 100644 --- a/.github/workflows/markdown_linter.yml +++ b/.github/workflows/markdown_linter.yml @@ -21,7 +21,7 @@ jobs: steps: - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c + uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d with: node-version: ${{ matrix.node-version }} - name: Install dependencies From b1b0998cf003f03d588397532bfedf595a5687f7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 1 Sep 2023 12:07:26 -0700 Subject: [PATCH 499/569] Bump actions/checkout from 3.5.2 to 3.6.0 (#1351) Bumps [actions/checkout](https://github.com/actions/checkout) from 3.5.2 to 3.6.0. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/8e5e7e5ab8b370d6c329ec480221332ada57f0ab...f43a0e5ff2bd294095638e18286ca9a3d1956744) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/dart.yml | 26 +++++++++++++------------- .github/workflows/markdown_linter.yml | 4 ++-- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 65680329f..83b7651e9 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -34,7 +34,7 @@ jobs: sdk: stable - id: checkout name: Checkout repository - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab + uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 - name: mono_repo self validate run: dart pub global activate mono_repo 6.5.7 - name: mono_repo self validate @@ -59,7 +59,7 @@ jobs: sdk: "3.0.0" - id: checkout name: Checkout repository - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab + uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -125,7 +125,7 @@ jobs: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab + uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -211,7 +211,7 @@ jobs: sdk: "3.0.0" - id: checkout name: Checkout repository - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab + uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -272,7 +272,7 @@ jobs: sdk: "3.0.0" - id: checkout name: Checkout repository - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab + uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -306,7 +306,7 @@ jobs: sdk: "3.0.0" - id: checkout name: Checkout repository - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab + uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -340,7 +340,7 @@ jobs: sdk: "3.0.0" - id: checkout name: Checkout repository - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab + uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -374,7 +374,7 @@ jobs: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab + uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -435,7 +435,7 @@ jobs: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab + uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -469,7 +469,7 @@ jobs: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab + uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -503,7 +503,7 @@ jobs: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab + uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -537,7 +537,7 @@ jobs: sdk: "3.0.0" - id: checkout name: Checkout repository - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab + uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -597,7 +597,7 @@ jobs: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab + uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade diff --git a/.github/workflows/markdown_linter.yml b/.github/workflows/markdown_linter.yml index 1658a0086..f4261362c 100644 --- a/.github/workflows/markdown_linter.yml +++ b/.github/workflows/markdown_linter.yml @@ -11,7 +11,7 @@ jobs: markdown-link-check: runs-on: ubuntu-latest steps: - - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab + - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 - uses: gaurav-nelson/github-action-markdown-link-check@v1 markdown_lint: runs-on: ubuntu-latest @@ -19,7 +19,7 @@ jobs: matrix: node-version: [ 14.x ] steps: - - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab + - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d with: From 85e83641befab6a30526c24950ecfd3fe3f9ce62 Mon Sep 17 00:00:00 2001 From: Tatsuya Fujisaki <1838962+tatsuyafujisaki@users.noreply.github.com> Date: Thu, 14 Sep 2023 00:34:37 +0900 Subject: [PATCH 500/569] Replace deprecated "dart pub run" with "dart run" (#1353) --- example/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/README.md b/example/README.md index 20b58a5c7..65fc28f59 100644 --- a/example/README.md +++ b/example/README.md @@ -23,7 +23,7 @@ Annotate your code with classes defined in Run `dart run build_runner build` to generate files into your source directory. ```console -> dart pub run build_runner build +> dart run build_runner build [INFO] ensureBuildScript: Generating build script completed, took 368ms [INFO] BuildDefinition: Reading cached asset graph completed, took 54ms [INFO] BuildDefinition: Checking for updates since last build completed, took 663ms From d055d4951e5e7755776413d3eda435113103801e Mon Sep 17 00:00:00 2001 From: Serena867 <104524200+Serena867@users.noreply.github.com> Date: Mon, 23 Oct 2023 14:25:00 -0700 Subject: [PATCH 501/569] Typo fix in utils.dart (#1363) Found and fixed a minor typo in utils.dart --- json_serializable/lib/src/utils.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index 941b7492a..c8c727f7d 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -48,7 +48,7 @@ T enumValueForDartObject<T>( ) => items[source.getField('index')!.toIntValue()!]; -/// Return an instance of [JsonSerializable] corresponding to a the provided +/// Return an instance of [JsonSerializable] corresponding to the provided /// [reader]. // #CHANGE WHEN UPDATING json_annotation JsonSerializable _valueForAnnotation(ConstantReader reader) => JsonSerializable( From df42558da71dbe31f88b3435b4cfc04937e3327a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 24 Oct 2023 18:23:57 -0700 Subject: [PATCH 502/569] Bump actions/cache from 3.3.1 to 3.3.2 (#1359) Bumps [actions/cache](https://github.com/actions/cache) from 3.3.1 to 3.3.2. - [Release notes](https://github.com/actions/cache/releases) - [Changelog](https://github.com/actions/cache/blob/main/RELEASES.md) - [Commits](https://github.com/actions/cache/compare/88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8...704facf57e6136b1bc63b828d79edcd491f0ee84) --- updated-dependencies: - dependency-name: actions/cache dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/dart.yml | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 83b7651e9..f1031f039 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -21,7 +21,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 + uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:stable" @@ -44,7 +44,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 + uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:analyze_1" @@ -110,7 +110,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 + uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:format-analyze_0" @@ -196,7 +196,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 + uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" @@ -257,7 +257,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 + uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:json_serializable;commands:test_3" @@ -291,7 +291,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 + uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:json_serializable;commands:test_1" @@ -325,7 +325,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 + uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:json_serializable;commands:test_2" @@ -359,7 +359,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 + uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" @@ -420,7 +420,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 + uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:json_serializable;commands:test_3" @@ -454,7 +454,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 + uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:json_serializable;commands:test_1" @@ -488,7 +488,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 + uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:json_serializable;commands:test_2" @@ -522,7 +522,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 + uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:_test_yaml-checked_yaml-example;commands:test_1" @@ -582,7 +582,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 + uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:_test_yaml-checked_yaml-example;commands:test_1" From fe636b10a55819859b1d807a24579df9481c84ae Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 24 Oct 2023 18:24:22 -0700 Subject: [PATCH 503/569] Bump dart-lang/setup-dart from 1.5.0 to 1.5.1 (#1358) Bumps [dart-lang/setup-dart](https://github.com/dart-lang/setup-dart) from 1.5.0 to 1.5.1. - [Release notes](https://github.com/dart-lang/setup-dart/releases) - [Changelog](https://github.com/dart-lang/setup-dart/blob/main/CHANGELOG.md) - [Commits](https://github.com/dart-lang/setup-dart/compare/d6a63dab3335f427404425de0fbfed4686d93c4f...8a4b97ea2017cc079571daec46542f76189836b1) --- updated-dependencies: - dependency-name: dart-lang/setup-dart dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/dart.yml | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index f1031f039..f7b0140eb 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -29,7 +29,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f + uses: dart-lang/setup-dart@8a4b97ea2017cc079571daec46542f76189836b1 with: sdk: stable - id: checkout @@ -54,7 +54,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f + uses: dart-lang/setup-dart@8a4b97ea2017cc079571daec46542f76189836b1 with: sdk: "3.0.0" - id: checkout @@ -120,7 +120,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f + uses: dart-lang/setup-dart@8a4b97ea2017cc079571daec46542f76189836b1 with: sdk: dev - id: checkout @@ -206,7 +206,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f + uses: dart-lang/setup-dart@8a4b97ea2017cc079571daec46542f76189836b1 with: sdk: "3.0.0" - id: checkout @@ -267,7 +267,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f + uses: dart-lang/setup-dart@8a4b97ea2017cc079571daec46542f76189836b1 with: sdk: "3.0.0" - id: checkout @@ -301,7 +301,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f + uses: dart-lang/setup-dart@8a4b97ea2017cc079571daec46542f76189836b1 with: sdk: "3.0.0" - id: checkout @@ -335,7 +335,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f + uses: dart-lang/setup-dart@8a4b97ea2017cc079571daec46542f76189836b1 with: sdk: "3.0.0" - id: checkout @@ -369,7 +369,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f + uses: dart-lang/setup-dart@8a4b97ea2017cc079571daec46542f76189836b1 with: sdk: dev - id: checkout @@ -430,7 +430,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f + uses: dart-lang/setup-dart@8a4b97ea2017cc079571daec46542f76189836b1 with: sdk: dev - id: checkout @@ -464,7 +464,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f + uses: dart-lang/setup-dart@8a4b97ea2017cc079571daec46542f76189836b1 with: sdk: dev - id: checkout @@ -498,7 +498,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f + uses: dart-lang/setup-dart@8a4b97ea2017cc079571daec46542f76189836b1 with: sdk: dev - id: checkout @@ -532,7 +532,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f + uses: dart-lang/setup-dart@8a4b97ea2017cc079571daec46542f76189836b1 with: sdk: "3.0.0" - id: checkout @@ -592,7 +592,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f + uses: dart-lang/setup-dart@8a4b97ea2017cc079571daec46542f76189836b1 with: sdk: dev - id: checkout From e2c8badaee4e36893e13c4073375a8ea035f2403 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 24 Oct 2023 18:24:32 -0700 Subject: [PATCH 504/569] Bump actions/checkout from 3.6.0 to 4.1.0 (#1357) Bumps [actions/checkout](https://github.com/actions/checkout) from 3.6.0 to 4.1.0. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/f43a0e5ff2bd294095638e18286ca9a3d1956744...8ade135a41bc03ea155e62e844d188df1ea18608) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/dart.yml | 26 +++++++++++++------------- .github/workflows/markdown_linter.yml | 4 ++-- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index f7b0140eb..8311a9857 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -34,7 +34,7 @@ jobs: sdk: stable - id: checkout name: Checkout repository - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 + uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - name: mono_repo self validate run: dart pub global activate mono_repo 6.5.7 - name: mono_repo self validate @@ -59,7 +59,7 @@ jobs: sdk: "3.0.0" - id: checkout name: Checkout repository - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 + uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -125,7 +125,7 @@ jobs: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 + uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -211,7 +211,7 @@ jobs: sdk: "3.0.0" - id: checkout name: Checkout repository - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 + uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -272,7 +272,7 @@ jobs: sdk: "3.0.0" - id: checkout name: Checkout repository - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 + uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -306,7 +306,7 @@ jobs: sdk: "3.0.0" - id: checkout name: Checkout repository - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 + uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -340,7 +340,7 @@ jobs: sdk: "3.0.0" - id: checkout name: Checkout repository - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 + uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -374,7 +374,7 @@ jobs: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 + uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -435,7 +435,7 @@ jobs: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 + uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -469,7 +469,7 @@ jobs: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 + uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -503,7 +503,7 @@ jobs: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 + uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -537,7 +537,7 @@ jobs: sdk: "3.0.0" - id: checkout name: Checkout repository - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 + uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -597,7 +597,7 @@ jobs: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 + uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade diff --git a/.github/workflows/markdown_linter.yml b/.github/workflows/markdown_linter.yml index f4261362c..b6243be61 100644 --- a/.github/workflows/markdown_linter.yml +++ b/.github/workflows/markdown_linter.yml @@ -11,7 +11,7 @@ jobs: markdown-link-check: runs-on: ubuntu-latest steps: - - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 + - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - uses: gaurav-nelson/github-action-markdown-link-check@v1 markdown_lint: runs-on: ubuntu-latest @@ -19,7 +19,7 @@ jobs: matrix: node-version: [ 14.x ] steps: - - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 + - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d with: From f8e57b52d9db0b66bab9f8cee86396f49d0a44e3 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Thu, 26 Oct 2023 10:50:43 -0700 Subject: [PATCH 505/569] Update to latest lints (#1361) --- _test_yaml/pubspec.yaml | 2 +- analysis_options.yaml | 6 - checked_yaml/pubspec.yaml | 2 +- checked_yaml/test/example_test.dart | 2 +- example/lib/json_converter_example.dart | 2 + example/pubspec.yaml | 2 +- example/test/json_convert_example_test.dart | 4 +- json_annotation/pubspec.yaml | 2 +- json_serializable/CHANGELOG.md | 4 + json_serializable/build.yaml | 4 + json_serializable/example/example.g.dart | 2 +- .../lib/src/type_helpers/record_helper.dart | 2 +- json_serializable/pubspec.yaml | 4 +- .../test/default_value/default_value.g.dart | 2 +- .../default_value.g_any_map__checked.g.dart | 2 +- .../default_value/default_value_test.dart | 4 +- .../implicit_default_value.g.dart | 2 +- .../field_matrix_test.field_matrix.g.dart | 2 +- .../generic_argument_factories.g.dart | 2 +- ...generic_argument_factories_nullable.g.dart | 2 +- .../test/generic_files/generic_class.dart | 2 + .../test/generic_files/generic_class.g.dart | 2 +- .../test/generic_files/generic_test.dart | 1 + .../integration/converter_examples.g.dart | 2 +- .../create_per_field_to_json_example.g.dart | 2 +- .../test/integration/field_map_example.g.dart | 2 +- .../test/integration/integration_test.dart | 2 +- .../test/integration/json_enum_example.g.dart | 2 +- .../test/integration/json_test_example.g.dart | 2 +- .../json_test_example.g_any_map.g.dart | 2 +- .../test/kitchen_sink/kitchen_sink.dart | 1 + .../test/kitchen_sink/kitchen_sink.g.dart | 4 +- .../kitchen_sink/kitchen_sink.g_any_map.dart | 1 + .../kitchen_sink.g_any_map.g.dart | 4 +- .../kitchen_sink.g_any_map__checked.dart | 1 + .../kitchen_sink.g_any_map__checked.g.dart | 4 +- .../kitchen_sink.g_exclude_null.dart | 1 + .../kitchen_sink.g_exclude_null.g.dart | 4 +- .../kitchen_sink.g_explicit_to_json.dart | 1 + .../kitchen_sink.g_explicit_to_json.g.dart | 4 +- .../test/kitchen_sink/kitchen_sink_test.dart | 12 +- .../kitchen_sink/kitchen_sink_yaml_test.dart | 4 +- .../test/kitchen_sink/simple_object.g.dart | 2 +- .../kitchen_sink/strict_keys_object.g.dart | 2 +- .../test/literal/json_literal.g.dart | 2 +- .../src/_json_serializable_test_input.dart | 2 +- .../test/src/json_converter_test_input.dart | 2 + .../test/supported_types/input.g.dart | 2 +- .../supported_types/input.type_bigint.g.dart | 2 +- .../supported_types/input.type_bool.g.dart | 2 +- .../input.type_datetime.g.dart | 2 +- .../supported_types/input.type_double.g.dart | 2 +- .../input.type_duration.g.dart | 2 +- .../input.type_enumtype.g.dart | 2 +- .../supported_types/input.type_int.g.dart | 2 +- .../input.type_iterable.g.dart | 6 +- .../supported_types/input.type_list.g.dart | 6 +- .../supported_types/input.type_map.g.dart | 124 ++++++++++-------- .../supported_types/input.type_num.g.dart | 2 +- .../supported_types/input.type_object.g.dart | 2 +- .../supported_types/input.type_record.g.dart | 122 ++++++++--------- .../supported_types/input.type_set.g.dart | 6 +- .../supported_types/input.type_string.g.dart | 2 +- .../supported_types/input.type_uri.g.dart | 2 +- .../tool/readme/readme_examples.g.dart | 2 +- json_serializable/tool/test_builder.dart | 3 +- shared_test/pubspec.yaml | 2 +- 67 files changed, 221 insertions(+), 198 deletions(-) diff --git a/_test_yaml/pubspec.yaml b/_test_yaml/pubspec.yaml index 4bcc26f14..f682e6e88 100644 --- a/_test_yaml/pubspec.yaml +++ b/_test_yaml/pubspec.yaml @@ -10,7 +10,7 @@ dev_dependencies: build_runner: ^2.0.0 build_verify: ^3.0.0 checked_yaml: any - dart_flutter_team_lints: ^1.0.0 + dart_flutter_team_lints: ^2.0.0 json_annotation: ^4.7.0 json_serializable: any path: ^1.8.2 diff --git a/analysis_options.yaml b/analysis_options.yaml index 375e7720b..4786eef5b 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -14,23 +14,17 @@ linter: - avoid_void_async - cancel_subscriptions - cascade_invocations - - comment_references - invalid_case_patterns - join_return_with_assignment - literal_only_boolean_expressions - missing_whitespace_between_adjacent_strings - no_runtimeType_toString - package_api_docs - - prefer_const_constructors - prefer_const_declarations - prefer_expression_function_bodies - prefer_final_locals - - prefer_relative_imports - sort_child_properties_last - - test_types_in_equals - - type_literal_in_constant_pattern - unnecessary_breaks - unsafe_html - use_full_hex_values_for_flutter_colors - use_string_buffers - - use_super_parameters diff --git a/checked_yaml/pubspec.yaml b/checked_yaml/pubspec.yaml index c164cab1a..821c9de5e 100644 --- a/checked_yaml/pubspec.yaml +++ b/checked_yaml/pubspec.yaml @@ -23,7 +23,7 @@ dependencies: dev_dependencies: build_runner: ^2.0.0 build_verify: ^3.0.0 - dart_flutter_team_lints: ^1.0.0 + dart_flutter_team_lints: ^2.0.0 json_serializable: ^6.0.0 path: ^1.0.0 test: ^1.16.0 diff --git a/checked_yaml/test/example_test.dart b/checked_yaml/test/example_test.dart index a5d55786d..08ff6f358 100644 --- a/checked_yaml/test/example_test.dart +++ b/checked_yaml/test/example_test.dart @@ -114,7 +114,7 @@ line 1, column 10: Unsupported value for "name". Cannot be empty. }); } -void _expectThrows(String yamlContent, matcher) => expect( +void _expectThrows(String yamlContent, String matcher) => expect( () => _run(yamlContent), throwsA( isA<ParsedYamlException>().having( diff --git a/example/lib/json_converter_example.dart b/example/lib/json_converter_example.dart index d408223c3..3ca92c6f1 100644 --- a/example/lib/json_converter_example.dart +++ b/example/lib/json_converter_example.dart @@ -2,6 +2,8 @@ // 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. +// ignore_for_file: inference_failure_on_instance_creation + import 'package:json_annotation/json_annotation.dart'; part 'json_converter_example.g.dart'; diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 9eeb261d5..6191089bd 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -19,7 +19,7 @@ dev_dependencies: build_verify: ^3.0.0 # Not required to use `json_serializable`. - dart_flutter_team_lints: ^1.0.0 + dart_flutter_team_lints: ^2.0.0 # REQUIRED! json_serializable: ^6.6.0 diff --git a/example/test/json_convert_example_test.dart b/example/test/json_convert_example_test.dart index 1801b21cc..5751b72de 100644 --- a/example/test/json_convert_example_test.dart +++ b/example/test/json_convert_example_test.dart @@ -83,8 +83,8 @@ void main() { throwsTypeError, ); - final collection2 = - GenericCollection.fromJson(jsonDecode(encoded) as Map<String, dynamic>); + final collection2 = GenericCollection<dynamic>.fromJson( + jsonDecode(encoded) as Map<String, dynamic>); expect(collection2.results, [ 1, diff --git a/json_annotation/pubspec.yaml b/json_annotation/pubspec.yaml index ce60661f9..a6b97a231 100644 --- a/json_annotation/pubspec.yaml +++ b/json_annotation/pubspec.yaml @@ -17,7 +17,7 @@ dependencies: meta: ^1.4.0 dev_dependencies: - dart_flutter_team_lints: ^1.0.0 + dart_flutter_team_lints: ^2.0.0 # When changing JsonSerializable class. # build_runner: ^2.0.0 # json_serializable: any diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 49a067ba7..0d36ca8af 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,7 @@ +## 6.7.2-wip + +- Add type arguments to `Map` literals used for `Record` serialization. + ## 6.7.1 - Support the latest `package:analyzer`. diff --git a/json_serializable/build.yaml b/json_serializable/build.yaml index fb0052e74..e52d7d814 100644 --- a/json_serializable/build.yaml +++ b/json_serializable/build.yaml @@ -8,6 +8,10 @@ targets: - lines_longer_than_80_chars # Only for the JSON literal output file - text_direction_code_point_in_literal + # Too much work in generated code + - inference_failure_on_function_invocation + # Need to update sourcegen_helper to generate List/Map with the right type params + - inference_failure_on_collection_literal json_serializable: generate_for: diff --git a/json_serializable/example/example.g.dart b/json_serializable/example/example.g.dart index 21820874c..0ed069cae 100644 --- a/json_serializable/example/example.g.dart +++ b/json_serializable/example/example.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal, inference_failure_on_function_invocation, inference_failure_on_collection_literal part of 'example.dart'; diff --git a/json_serializable/lib/src/type_helpers/record_helper.dart b/json_serializable/lib/src/type_helpers/record_helper.dart index f086948bf..42b13025e 100644 --- a/json_serializable/lib/src/type_helpers/record_helper.dart +++ b/json_serializable/lib/src/type_helpers/record_helper.dart @@ -90,7 +90,7 @@ $helperName( ); } - final mapValue = '{${items.map((e) => '$e,').join()}}'; + final mapValue = '<String, dynamic>{${items.map((e) => '$e,').join()}}'; return targetType.isNullableType ? ifNullOrElse( diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index cfb3dd8a8..8f55a01f0 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 6.7.1 +version: 6.7.2-wip description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. @@ -34,7 +34,7 @@ dev_dependencies: path: ../shared_test build_runner: ^2.0.0 build_verify: ^3.0.0 - dart_flutter_team_lints: ^1.0.0 + dart_flutter_team_lints: ^2.0.0 dart_style: ^2.0.0 logging: ^1.0.0 source_gen_test: ^1.0.0 diff --git a/json_serializable/test/default_value/default_value.g.dart b/json_serializable/test/default_value/default_value.g.dart index 4cf5cda7d..0614284e6 100644 --- a/json_serializable/test/default_value/default_value.g.dart +++ b/json_serializable/test/default_value/default_value.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal, inference_failure_on_function_invocation, inference_failure_on_collection_literal part of 'default_value.dart'; diff --git a/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart b/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart index b3a0669c9..24be86d8a 100644 --- a/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart +++ b/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal, inference_failure_on_function_invocation, inference_failure_on_collection_literal part of 'default_value.g_any_map__checked.dart'; diff --git a/json_serializable/test/default_value/default_value_test.dart b/json_serializable/test/default_value/default_value_test.dart index 59b82fc3c..d2d057c28 100644 --- a/json_serializable/test/default_value/default_value_test.dart +++ b/json_serializable/test/default_value/default_value_test.dart @@ -15,8 +15,8 @@ const _defaultInstance = { 'fieldString': 'string', 'fieldInt': 42, 'fieldDouble': 3.14, - 'fieldListEmpty': [], - 'fieldSetEmpty': [], + 'fieldListEmpty': <dynamic>[], + 'fieldSetEmpty': <dynamic>[], 'fieldMapEmpty': <String, dynamic>{}, 'fieldListSimple': [1, 2, 3], 'fieldSetSimple': ['entry1', 'entry2'], diff --git a/json_serializable/test/default_value/implicit_default_value.g.dart b/json_serializable/test/default_value/implicit_default_value.g.dart index 1a3973134..9bd1f19e0 100644 --- a/json_serializable/test/default_value/implicit_default_value.g.dart +++ b/json_serializable/test/default_value/implicit_default_value.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal, inference_failure_on_function_invocation, inference_failure_on_collection_literal part of 'implicit_default_value.dart'; diff --git a/json_serializable/test/field_matrix_test.field_matrix.g.dart b/json_serializable/test/field_matrix_test.field_matrix.g.dart index cdb054b03..84891ef9a 100644 --- a/json_serializable/test/field_matrix_test.field_matrix.g.dart +++ b/json_serializable/test/field_matrix_test.field_matrix.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal, inference_failure_on_function_invocation, inference_failure_on_collection_literal part of 'field_matrix_test.field_matrix.dart'; diff --git a/json_serializable/test/generic_files/generic_argument_factories.g.dart b/json_serializable/test/generic_files/generic_argument_factories.g.dart index 87755ac37..188ac7116 100644 --- a/json_serializable/test/generic_files/generic_argument_factories.g.dart +++ b/json_serializable/test/generic_files/generic_argument_factories.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal, inference_failure_on_function_invocation, inference_failure_on_collection_literal part of 'generic_argument_factories.dart'; diff --git a/json_serializable/test/generic_files/generic_argument_factories_nullable.g.dart b/json_serializable/test/generic_files/generic_argument_factories_nullable.g.dart index 5527d2fed..17b278eed 100644 --- a/json_serializable/test/generic_files/generic_argument_factories_nullable.g.dart +++ b/json_serializable/test/generic_files/generic_argument_factories_nullable.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal, inference_failure_on_function_invocation, inference_failure_on_collection_literal part of 'generic_argument_factories_nullable.dart'; diff --git a/json_serializable/test/generic_files/generic_class.dart b/json_serializable/test/generic_files/generic_class.dart index 6149d8dba..0870c956f 100644 --- a/json_serializable/test/generic_files/generic_class.dart +++ b/json_serializable/test/generic_files/generic_class.dart @@ -2,6 +2,8 @@ // 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. +// ignore_for_file: inference_failure_on_instance_creation + import 'package:collection/collection.dart'; import 'package:json_annotation/json_annotation.dart'; diff --git a/json_serializable/test/generic_files/generic_class.g.dart b/json_serializable/test/generic_files/generic_class.g.dart index c2f216483..c5809241c 100644 --- a/json_serializable/test/generic_files/generic_class.g.dart +++ b/json_serializable/test/generic_files/generic_class.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal, inference_failure_on_function_invocation, inference_failure_on_collection_literal part of 'generic_class.dart'; diff --git a/json_serializable/test/generic_files/generic_test.dart b/json_serializable/test/generic_files/generic_test.dart index 7de5f80d5..e4f82d6f3 100644 --- a/json_serializable/test/generic_files/generic_test.dart +++ b/json_serializable/test/generic_files/generic_test.dart @@ -24,6 +24,7 @@ void main() { } test('no type args', () { + // ignore: inference_failure_on_instance_creation roundTripGenericClass(GenericClass() ..fieldDynamic = 1 ..fieldInt = 2 diff --git a/json_serializable/test/integration/converter_examples.g.dart b/json_serializable/test/integration/converter_examples.g.dart index de339009e..26da277f0 100644 --- a/json_serializable/test/integration/converter_examples.g.dart +++ b/json_serializable/test/integration/converter_examples.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal, inference_failure_on_function_invocation, inference_failure_on_collection_literal part of 'converter_examples.dart'; diff --git a/json_serializable/test/integration/create_per_field_to_json_example.g.dart b/json_serializable/test/integration/create_per_field_to_json_example.g.dart index 29c4baa7b..0587c26ba 100644 --- a/json_serializable/test/integration/create_per_field_to_json_example.g.dart +++ b/json_serializable/test/integration/create_per_field_to_json_example.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal, inference_failure_on_function_invocation, inference_failure_on_collection_literal part of 'create_per_field_to_json_example.dart'; diff --git a/json_serializable/test/integration/field_map_example.g.dart b/json_serializable/test/integration/field_map_example.g.dart index 5c50eadc3..d47e01793 100644 --- a/json_serializable/test/integration/field_map_example.g.dart +++ b/json_serializable/test/integration/field_map_example.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal, inference_failure_on_function_invocation, inference_failure_on_collection_literal part of 'field_map_example.dart'; diff --git a/json_serializable/test/integration/integration_test.dart b/json_serializable/test/integration/integration_test.dart index 76b01f8fa..9305b4f9b 100644 --- a/json_serializable/test/integration/integration_test.dart +++ b/json_serializable/test/integration/integration_test.dart @@ -13,7 +13,7 @@ import 'json_enum_example.dart'; import 'json_test_common.dart' show Category, Platform, StatusCode; import 'json_test_example.dart'; -Matcher _throwsArgumentError(matcher) => +Matcher _throwsArgumentError(Object matcher) => throwsA(isArgumentError.having((e) => e.message, 'message', matcher)); void main() { diff --git a/json_serializable/test/integration/json_enum_example.g.dart b/json_serializable/test/integration/json_enum_example.g.dart index 818e057ae..6408e9e1d 100644 --- a/json_serializable/test/integration/json_enum_example.g.dart +++ b/json_serializable/test/integration/json_enum_example.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal, inference_failure_on_function_invocation, inference_failure_on_collection_literal part of 'json_enum_example.dart'; diff --git a/json_serializable/test/integration/json_test_example.g.dart b/json_serializable/test/integration/json_test_example.g.dart index 4681280b8..b6a5330d4 100644 --- a/json_serializable/test/integration/json_test_example.g.dart +++ b/json_serializable/test/integration/json_test_example.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal, inference_failure_on_function_invocation, inference_failure_on_collection_literal part of 'json_test_example.dart'; diff --git a/json_serializable/test/integration/json_test_example.g_any_map.g.dart b/json_serializable/test/integration/json_test_example.g_any_map.g.dart index 1e86e1fbc..b8ba1f9f4 100644 --- a/json_serializable/test/integration/json_test_example.g_any_map.g.dart +++ b/json_serializable/test/integration/json_test_example.g_any_map.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal, inference_failure_on_function_invocation, inference_failure_on_collection_literal part of 'json_test_example.g_any_map.dart'; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.dart b/json_serializable/test/kitchen_sink/kitchen_sink.dart index b0ff20f00..86525d9c8 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.dart @@ -249,6 +249,7 @@ class JsonConverterTestClass implements k.JsonConverterTestClass { } @JsonSerializable() +// ignore: inference_failure_on_instance_creation @GenericConverter() class JsonConverterGeneric<S, T, U> { S item; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g.dart index 1396ff044..d9230fbc5 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal, inference_failure_on_function_invocation, inference_failure_on_collection_literal part of 'kitchen_sink.dart'; @@ -142,7 +142,7 @@ Map<String, dynamic> _$KitchenSinkToJson(KitchenSink instance) => 'validatedPropertyNo42': instance.validatedPropertyNo42, 'recordField': instance.recordField == null ? null - : { + : <String, dynamic>{ r'$1': instance.recordField!.$1, r'$2': instance.recordField!.$2, 'truth': instance.recordField!.truth, diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart index 6f8b5c69f..f00f38ebc 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart @@ -251,6 +251,7 @@ class JsonConverterTestClass implements k.JsonConverterTestClass { @JsonSerializable( anyMap: true, ) +// ignore: inference_failure_on_instance_creation @GenericConverter() class JsonConverterGeneric<S, T, U> { S item; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart index 6cfb749ea..74a348f5e 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal, inference_failure_on_function_invocation, inference_failure_on_collection_literal part of 'kitchen_sink.g_any_map.dart'; @@ -134,7 +134,7 @@ Map<String, dynamic> _$KitchenSinkToJson(KitchenSink instance) => 'validatedPropertyNo42': instance.validatedPropertyNo42, 'recordField': instance.recordField == null ? null - : { + : <String, dynamic>{ r'$1': instance.recordField!.$1, r'$2': instance.recordField!.$2, 'truth': instance.recordField!.truth, diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.dart index fe5bcbba7..0d9dc1144 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.dart @@ -253,6 +253,7 @@ class JsonConverterTestClass implements k.JsonConverterTestClass { checked: true, anyMap: true, ) +// ignore: inference_failure_on_instance_creation @GenericConverter() class JsonConverterGeneric<S, T, U> { S item; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.g.dart index 02fc36586..d08da32c5 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal, inference_failure_on_function_invocation, inference_failure_on_collection_literal part of 'kitchen_sink.g_any_map__checked.dart'; @@ -187,7 +187,7 @@ Map<String, dynamic> _$KitchenSinkToJson(KitchenSink instance) => 'validatedPropertyNo42': instance.validatedPropertyNo42, 'recordField': instance.recordField == null ? null - : { + : <String, dynamic>{ r'$1': instance.recordField!.$1, r'$2': instance.recordField!.$2, 'truth': instance.recordField!.truth, diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.dart index 9476908a6..5dda14726 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.dart @@ -253,6 +253,7 @@ class JsonConverterTestClass implements k.JsonConverterTestClass { @JsonSerializable( includeIfNull: false, ) +// ignore: inference_failure_on_instance_creation @GenericConverter() class JsonConverterGeneric<S, T, U> { S item; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart index e9f8662ad..76504317c 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal, inference_failure_on_function_invocation, inference_failure_on_collection_literal part of 'kitchen_sink.g_exclude_null.dart'; @@ -151,7 +151,7 @@ Map<String, dynamic> _$KitchenSinkToJson(KitchenSink instance) { 'recordField', instance.recordField == null ? null - : { + : <String, dynamic>{ r'$1': instance.recordField!.$1, r'$2': instance.recordField!.$2, 'truth': instance.recordField!.truth, diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.dart index 48afb79fc..efccc8f08 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.dart @@ -253,6 +253,7 @@ class JsonConverterTestClass implements k.JsonConverterTestClass { @JsonSerializable( explicitToJson: true, ) +// ignore: inference_failure_on_instance_creation @GenericConverter() class JsonConverterGeneric<S, T, U> { S item; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart index 24101a1b6..ff092269c 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal, inference_failure_on_function_invocation, inference_failure_on_collection_literal part of 'kitchen_sink.g_explicit_to_json.dart'; @@ -144,7 +144,7 @@ Map<String, dynamic> _$KitchenSinkToJson(KitchenSink instance) => 'validatedPropertyNo42': instance.validatedPropertyNo42, 'recordField': instance.recordField == null ? null - : { + : <String, dynamic>{ r'$1': instance.recordField!.$1, r'$2': instance.recordField!.$2, 'truth': instance.recordField!.truth, diff --git a/json_serializable/test/kitchen_sink/kitchen_sink_test.dart b/json_serializable/test/kitchen_sink/kitchen_sink_test.dart index f3519050b..3cd0c399f 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink_test.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink_test.dart @@ -12,7 +12,7 @@ import 'kitchen_sink_interface.dart'; import 'kitchen_sink_test_shared.dart'; import 'strict_keys_object.dart'; -Matcher _isMissingKeyException(expectedMessage) => +Matcher _isMissingKeyException(String expectedMessage) => isA<MissingRequiredKeysException>() .having((e) => e.message, 'message', expectedMessage); @@ -99,17 +99,17 @@ void _nullableTests(KitchenSinkFactory factory) { expect(json, const { 'duration': 0, - 'durationList': [], + 'durationList': <dynamic>[], 'bigInt': '0', - 'bigIntMap': {}, + 'bigIntMap': <String, dynamic>{}, 'nullableBigInt': '0', - 'nullableBigIntMap': {}, + 'nullableBigIntMap': <String, dynamic>{}, 'numberSilly': 0, - 'numberSillySet': [], + 'numberSillySet': <dynamic>[], 'dateTime': 0, 'trivialString': '', 'nullableNumberSilly': 0, - 'nullableNumberSillySet': [], + 'nullableNumberSillySet': <dynamic>[], }); expect(json.keys, unorderedEquals(_jsonConverterValidValues.keys)); diff --git a/json_serializable/test/kitchen_sink/kitchen_sink_yaml_test.dart b/json_serializable/test/kitchen_sink/kitchen_sink_yaml_test.dart index e1fcb1039..951a90df7 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink_yaml_test.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink_yaml_test.dart @@ -42,7 +42,7 @@ void _testBadValue(String key, Object? badValue, KitchenSinkFactory factory, for (final isJson in [true, false]) { test('`$key` fails with value `$badValue`- ${isJson ? 'json' : 'yaml'}', () { - var copy = Map.from(validValues); + var copy = Map<dynamic, dynamic>.of(validValues); copy[key] = badValue; if (!isJson) { @@ -88,7 +88,7 @@ Matcher _getMatcher(bool checked, String? expectedKey, bool checkedAssignment) { return throwsA(innerMatcher); } -Matcher _isAUnrecognizedKeysException(expectedMessage) => +Matcher _isAUnrecognizedKeysException(String expectedMessage) => isA<UnrecognizedKeysException>() .having((e) => e.message, 'message', expectedMessage); diff --git a/json_serializable/test/kitchen_sink/simple_object.g.dart b/json_serializable/test/kitchen_sink/simple_object.g.dart index c18d4558c..b0bbfbef0 100644 --- a/json_serializable/test/kitchen_sink/simple_object.g.dart +++ b/json_serializable/test/kitchen_sink/simple_object.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal, inference_failure_on_function_invocation, inference_failure_on_collection_literal part of 'simple_object.dart'; diff --git a/json_serializable/test/kitchen_sink/strict_keys_object.g.dart b/json_serializable/test/kitchen_sink/strict_keys_object.g.dart index b8dc65ec6..b6b00cce3 100644 --- a/json_serializable/test/kitchen_sink/strict_keys_object.g.dart +++ b/json_serializable/test/kitchen_sink/strict_keys_object.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal, inference_failure_on_function_invocation, inference_failure_on_collection_literal part of 'strict_keys_object.dart'; diff --git a/json_serializable/test/literal/json_literal.g.dart b/json_serializable/test/literal/json_literal.g.dart index 02294b603..9e0993dde 100644 --- a/json_serializable/test/literal/json_literal.g.dart +++ b/json_serializable/test/literal/json_literal.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal, inference_failure_on_function_invocation, inference_failure_on_collection_literal part of 'json_literal.dart'; diff --git a/json_serializable/test/src/_json_serializable_test_input.dart b/json_serializable/test/src/_json_serializable_test_input.dart index f77864668..af82c8440 100644 --- a/json_serializable/test/src/_json_serializable_test_input.dart +++ b/json_serializable/test/src/_json_serializable_test_input.dart @@ -81,7 +81,7 @@ class GeneralTestClass1 { late DateTime dateOfBirth; dynamic dynamicType; - //ignore: prefer_typing_uninitialized_variables,type_annotate_public_apis + //ignore: prefer_typing_uninitialized_variables,type_annotate_public_apis,inference_failure_on_uninitialized_variable var varType; late List<int> listOfInts; } diff --git a/json_serializable/test/src/json_converter_test_input.dart b/json_serializable/test/src/json_converter_test_input.dart index ac7852f61..865ee06a6 100644 --- a/json_serializable/test/src/json_converter_test_input.dart +++ b/json_serializable/test/src/json_converter_test_input.dart @@ -2,6 +2,8 @@ // 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. +// ignore_for_file: inference_failure_on_instance_creation + part of '_json_serializable_test_input.dart'; @ShouldGenerate(r''' diff --git a/json_serializable/test/supported_types/input.g.dart b/json_serializable/test/supported_types/input.g.dart index a07530cb6..4c7e8053d 100644 --- a/json_serializable/test/supported_types/input.g.dart +++ b/json_serializable/test/supported_types/input.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal, inference_failure_on_function_invocation, inference_failure_on_collection_literal part of 'input.dart'; diff --git a/json_serializable/test/supported_types/input.type_bigint.g.dart b/json_serializable/test/supported_types/input.type_bigint.g.dart index 39f10c238..379bdbd50 100644 --- a/json_serializable/test/supported_types/input.type_bigint.g.dart +++ b/json_serializable/test/supported_types/input.type_bigint.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal, inference_failure_on_function_invocation, inference_failure_on_collection_literal part of 'input.type_bigint.dart'; diff --git a/json_serializable/test/supported_types/input.type_bool.g.dart b/json_serializable/test/supported_types/input.type_bool.g.dart index 7964a3a21..4077ce108 100644 --- a/json_serializable/test/supported_types/input.type_bool.g.dart +++ b/json_serializable/test/supported_types/input.type_bool.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal, inference_failure_on_function_invocation, inference_failure_on_collection_literal part of 'input.type_bool.dart'; diff --git a/json_serializable/test/supported_types/input.type_datetime.g.dart b/json_serializable/test/supported_types/input.type_datetime.g.dart index 043bce089..461e30ebb 100644 --- a/json_serializable/test/supported_types/input.type_datetime.g.dart +++ b/json_serializable/test/supported_types/input.type_datetime.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal, inference_failure_on_function_invocation, inference_failure_on_collection_literal part of 'input.type_datetime.dart'; diff --git a/json_serializable/test/supported_types/input.type_double.g.dart b/json_serializable/test/supported_types/input.type_double.g.dart index 921716796..163485d5a 100644 --- a/json_serializable/test/supported_types/input.type_double.g.dart +++ b/json_serializable/test/supported_types/input.type_double.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal, inference_failure_on_function_invocation, inference_failure_on_collection_literal part of 'input.type_double.dart'; diff --git a/json_serializable/test/supported_types/input.type_duration.g.dart b/json_serializable/test/supported_types/input.type_duration.g.dart index cee2811f2..7ea4c7da6 100644 --- a/json_serializable/test/supported_types/input.type_duration.g.dart +++ b/json_serializable/test/supported_types/input.type_duration.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal, inference_failure_on_function_invocation, inference_failure_on_collection_literal part of 'input.type_duration.dart'; diff --git a/json_serializable/test/supported_types/input.type_enumtype.g.dart b/json_serializable/test/supported_types/input.type_enumtype.g.dart index b8f1901fc..77d67e064 100644 --- a/json_serializable/test/supported_types/input.type_enumtype.g.dart +++ b/json_serializable/test/supported_types/input.type_enumtype.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal, inference_failure_on_function_invocation, inference_failure_on_collection_literal part of 'input.type_enumtype.dart'; diff --git a/json_serializable/test/supported_types/input.type_int.g.dart b/json_serializable/test/supported_types/input.type_int.g.dart index 848d81cf1..ddb06ed57 100644 --- a/json_serializable/test/supported_types/input.type_int.g.dart +++ b/json_serializable/test/supported_types/input.type_int.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal, inference_failure_on_function_invocation, inference_failure_on_collection_literal part of 'input.type_int.dart'; diff --git a/json_serializable/test/supported_types/input.type_iterable.g.dart b/json_serializable/test/supported_types/input.type_iterable.g.dart index 885d166a8..95c3e0557 100644 --- a/json_serializable/test/supported_types/input.type_iterable.g.dart +++ b/json_serializable/test/supported_types/input.type_iterable.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal, inference_failure_on_function_invocation, inference_failure_on_collection_literal part of 'input.type_iterable.dart'; @@ -599,7 +599,7 @@ Map<String, dynamic> _$SimpleClassOfRecordToJson( SimpleClassOfRecord instance) => <String, dynamic>{ 'value': instance.value - .map((e) => { + .map((e) => <String, dynamic>{ r'$1': e.$1, r'$2': e.$2, 'truth': e.truth, @@ -630,7 +630,7 @@ Map<String, dynamic> _$SimpleClassNullableOfRecordToJson( SimpleClassNullableOfRecord instance) => <String, dynamic>{ 'value': instance.value - ?.map((e) => { + ?.map((e) => <String, dynamic>{ r'$1': e.$1, r'$2': e.$2, 'truth': e.truth, diff --git a/json_serializable/test/supported_types/input.type_list.g.dart b/json_serializable/test/supported_types/input.type_list.g.dart index b21a959b6..2f4497581 100644 --- a/json_serializable/test/supported_types/input.type_list.g.dart +++ b/json_serializable/test/supported_types/input.type_list.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal, inference_failure_on_function_invocation, inference_failure_on_collection_literal part of 'input.type_list.dart'; @@ -635,7 +635,7 @@ Map<String, dynamic> _$SimpleClassOfRecordToJson( SimpleClassOfRecord instance) => <String, dynamic>{ 'value': instance.value - .map((e) => { + .map((e) => <String, dynamic>{ r'$1': e.$1, r'$2': e.$2, 'truth': e.truth, @@ -668,7 +668,7 @@ Map<String, dynamic> _$SimpleClassNullableOfRecordToJson( SimpleClassNullableOfRecord instance) => <String, dynamic>{ 'value': instance.value - ?.map((e) => { + ?.map((e) => <String, dynamic>{ r'$1': e.$1, r'$2': e.$2, 'truth': e.truth, diff --git a/json_serializable/test/supported_types/input.type_map.g.dart b/json_serializable/test/supported_types/input.type_map.g.dart index dc17f2907..5f29d60ab 100644 --- a/json_serializable/test/supported_types/input.type_map.g.dart +++ b/json_serializable/test/supported_types/input.type_map.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal, inference_failure_on_function_invocation, inference_failure_on_collection_literal part of 'input.type_map.dart'; @@ -5301,11 +5301,12 @@ SimpleClassOfBigIntToRecord _$SimpleClassOfBigIntToRecordFromJson( Map<String, dynamic> _$SimpleClassOfBigIntToRecordToJson( SimpleClassOfBigIntToRecord instance) => <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toString(), { - r'$1': e.$1, - r'$2': e.$2, - 'truth': e.truth, - })), + 'value': + instance.value.map((k, e) => MapEntry(k.toString(), <String, dynamic>{ + r'$1': e.$1, + r'$2': e.$2, + 'truth': e.truth, + })), }; $Rec _$recordConvert<$Rec>( @@ -5334,11 +5335,12 @@ SimpleClassNullableOfBigIntToRecord Map<String, dynamic> _$SimpleClassNullableOfBigIntToRecordToJson( SimpleClassNullableOfBigIntToRecord instance) => <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), { - r'$1': e.$1, - r'$2': e.$2, - 'truth': e.truth, - })), + 'value': instance.value + ?.map((k, e) => MapEntry(k.toString(), <String, dynamic>{ + r'$1': e.$1, + r'$2': e.$2, + 'truth': e.truth, + })), }; SimpleClassOfDateTimeToRecord _$SimpleClassOfDateTimeToRecordFromJson( @@ -5361,11 +5363,12 @@ SimpleClassOfDateTimeToRecord _$SimpleClassOfDateTimeToRecordFromJson( Map<String, dynamic> _$SimpleClassOfDateTimeToRecordToJson( SimpleClassOfDateTimeToRecord instance) => <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toIso8601String(), { - r'$1': e.$1, - r'$2': e.$2, - 'truth': e.truth, - })), + 'value': instance.value + .map((k, e) => MapEntry(k.toIso8601String(), <String, dynamic>{ + r'$1': e.$1, + r'$2': e.$2, + 'truth': e.truth, + })), }; SimpleClassNullableOfDateTimeToRecord @@ -5389,11 +5392,12 @@ SimpleClassNullableOfDateTimeToRecord Map<String, dynamic> _$SimpleClassNullableOfDateTimeToRecordToJson( SimpleClassNullableOfDateTimeToRecord instance) => <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toIso8601String(), { - r'$1': e.$1, - r'$2': e.$2, - 'truth': e.truth, - })), + 'value': instance.value + ?.map((k, e) => MapEntry(k.toIso8601String(), <String, dynamic>{ + r'$1': e.$1, + r'$2': e.$2, + 'truth': e.truth, + })), }; SimpleClassOfDynamicToRecord _$SimpleClassOfDynamicToRecordFromJson( @@ -5416,7 +5420,7 @@ SimpleClassOfDynamicToRecord _$SimpleClassOfDynamicToRecordFromJson( Map<String, dynamic> _$SimpleClassOfDynamicToRecordToJson( SimpleClassOfDynamicToRecord instance) => <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k, { + 'value': instance.value.map((k, e) => MapEntry(k, <String, dynamic>{ r'$1': e.$1, r'$2': e.$2, 'truth': e.truth, @@ -5443,7 +5447,7 @@ SimpleClassNullableOfDynamicToRecord Map<String, dynamic> _$SimpleClassNullableOfDynamicToRecordToJson( SimpleClassNullableOfDynamicToRecord instance) => <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k, { + 'value': instance.value?.map((k, e) => MapEntry(k, <String, dynamic>{ r'$1': e.$1, r'$2': e.$2, 'truth': e.truth, @@ -5470,11 +5474,12 @@ SimpleClassOfEnumTypeToRecord _$SimpleClassOfEnumTypeToRecordFromJson( Map<String, dynamic> _$SimpleClassOfEnumTypeToRecordToJson( SimpleClassOfEnumTypeToRecord instance) => <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, { - r'$1': e.$1, - r'$2': e.$2, - 'truth': e.truth, - })), + 'value': instance.value + .map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, <String, dynamic>{ + r'$1': e.$1, + r'$2': e.$2, + 'truth': e.truth, + })), }; SimpleClassNullableOfEnumTypeToRecord @@ -5498,11 +5503,12 @@ SimpleClassNullableOfEnumTypeToRecord Map<String, dynamic> _$SimpleClassNullableOfEnumTypeToRecordToJson( SimpleClassNullableOfEnumTypeToRecord instance) => <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, { - r'$1': e.$1, - r'$2': e.$2, - 'truth': e.truth, - })), + 'value': instance.value + ?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, <String, dynamic>{ + r'$1': e.$1, + r'$2': e.$2, + 'truth': e.truth, + })), }; SimpleClassOfIntToRecord _$SimpleClassOfIntToRecordFromJson( @@ -5525,11 +5531,12 @@ SimpleClassOfIntToRecord _$SimpleClassOfIntToRecordFromJson( Map<String, dynamic> _$SimpleClassOfIntToRecordToJson( SimpleClassOfIntToRecord instance) => <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toString(), { - r'$1': e.$1, - r'$2': e.$2, - 'truth': e.truth, - })), + 'value': + instance.value.map((k, e) => MapEntry(k.toString(), <String, dynamic>{ + r'$1': e.$1, + r'$2': e.$2, + 'truth': e.truth, + })), }; SimpleClassNullableOfIntToRecord _$SimpleClassNullableOfIntToRecordFromJson( @@ -5552,11 +5559,12 @@ SimpleClassNullableOfIntToRecord _$SimpleClassNullableOfIntToRecordFromJson( Map<String, dynamic> _$SimpleClassNullableOfIntToRecordToJson( SimpleClassNullableOfIntToRecord instance) => <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), { - r'$1': e.$1, - r'$2': e.$2, - 'truth': e.truth, - })), + 'value': instance.value + ?.map((k, e) => MapEntry(k.toString(), <String, dynamic>{ + r'$1': e.$1, + r'$2': e.$2, + 'truth': e.truth, + })), }; SimpleClassOfObjectToRecord _$SimpleClassOfObjectToRecordFromJson( @@ -5579,7 +5587,7 @@ SimpleClassOfObjectToRecord _$SimpleClassOfObjectToRecordFromJson( Map<String, dynamic> _$SimpleClassOfObjectToRecordToJson( SimpleClassOfObjectToRecord instance) => <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k, { + 'value': instance.value.map((k, e) => MapEntry(k, <String, dynamic>{ r'$1': e.$1, r'$2': e.$2, 'truth': e.truth, @@ -5606,7 +5614,7 @@ SimpleClassNullableOfObjectToRecord Map<String, dynamic> _$SimpleClassNullableOfObjectToRecordToJson( SimpleClassNullableOfObjectToRecord instance) => <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k, { + 'value': instance.value?.map((k, e) => MapEntry(k, <String, dynamic>{ r'$1': e.$1, r'$2': e.$2, 'truth': e.truth, @@ -5633,7 +5641,7 @@ SimpleClassOfStringToRecord _$SimpleClassOfStringToRecordFromJson( Map<String, dynamic> _$SimpleClassOfStringToRecordToJson( SimpleClassOfStringToRecord instance) => <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k, { + 'value': instance.value.map((k, e) => MapEntry(k, <String, dynamic>{ r'$1': e.$1, r'$2': e.$2, 'truth': e.truth, @@ -5660,7 +5668,7 @@ SimpleClassNullableOfStringToRecord Map<String, dynamic> _$SimpleClassNullableOfStringToRecordToJson( SimpleClassNullableOfStringToRecord instance) => <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k, { + 'value': instance.value?.map((k, e) => MapEntry(k, <String, dynamic>{ r'$1': e.$1, r'$2': e.$2, 'truth': e.truth, @@ -5687,11 +5695,12 @@ SimpleClassOfUriToRecord _$SimpleClassOfUriToRecordFromJson( Map<String, dynamic> _$SimpleClassOfUriToRecordToJson( SimpleClassOfUriToRecord instance) => <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toString(), { - r'$1': e.$1, - r'$2': e.$2, - 'truth': e.truth, - })), + 'value': + instance.value.map((k, e) => MapEntry(k.toString(), <String, dynamic>{ + r'$1': e.$1, + r'$2': e.$2, + 'truth': e.truth, + })), }; SimpleClassNullableOfUriToRecord _$SimpleClassNullableOfUriToRecordFromJson( @@ -5714,11 +5723,12 @@ SimpleClassNullableOfUriToRecord _$SimpleClassNullableOfUriToRecordFromJson( Map<String, dynamic> _$SimpleClassNullableOfUriToRecordToJson( SimpleClassNullableOfUriToRecord instance) => <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), { - r'$1': e.$1, - r'$2': e.$2, - 'truth': e.truth, - })), + 'value': instance.value + ?.map((k, e) => MapEntry(k.toString(), <String, dynamic>{ + r'$1': e.$1, + r'$2': e.$2, + 'truth': e.truth, + })), }; SimpleClassOfBigIntToString _$SimpleClassOfBigIntToStringFromJson( diff --git a/json_serializable/test/supported_types/input.type_num.g.dart b/json_serializable/test/supported_types/input.type_num.g.dart index fbd27bbba..f25274d8f 100644 --- a/json_serializable/test/supported_types/input.type_num.g.dart +++ b/json_serializable/test/supported_types/input.type_num.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal, inference_failure_on_function_invocation, inference_failure_on_collection_literal part of 'input.type_num.dart'; diff --git a/json_serializable/test/supported_types/input.type_object.g.dart b/json_serializable/test/supported_types/input.type_object.g.dart index 7959daa78..b35be59b6 100644 --- a/json_serializable/test/supported_types/input.type_object.g.dart +++ b/json_serializable/test/supported_types/input.type_object.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal, inference_failure_on_function_invocation, inference_failure_on_collection_literal part of 'input.type_object.dart'; diff --git a/json_serializable/test/supported_types/input.type_record.g.dart b/json_serializable/test/supported_types/input.type_record.g.dart index 19f2da859..5c96d58c8 100644 --- a/json_serializable/test/supported_types/input.type_record.g.dart +++ b/json_serializable/test/supported_types/input.type_record.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal, inference_failure_on_function_invocation, inference_failure_on_collection_literal part of 'input.type_record.dart'; @@ -14,7 +14,7 @@ SimpleClass _$SimpleClassFromJson(Map<String, dynamic> json) => SimpleClass( Map<String, dynamic> _$SimpleClassToJson(SimpleClass instance) => <String, dynamic>{ - 'value': {}, + 'value': <String, dynamic>{}, }; SimpleClassNullable _$SimpleClassNullableFromJson(Map<String, dynamic> json) => @@ -25,7 +25,7 @@ SimpleClassNullable _$SimpleClassNullableFromJson(Map<String, dynamic> json) => Map<String, dynamic> _$SimpleClassNullableToJson( SimpleClassNullable instance) => <String, dynamic>{ - 'value': instance.value == null ? null : {}, + 'value': instance.value == null ? null : <String, dynamic>{}, }; SimpleClassOfBigInt _$SimpleClassOfBigIntFromJson(Map<String, dynamic> json) => @@ -42,7 +42,7 @@ SimpleClassOfBigInt _$SimpleClassOfBigIntFromJson(Map<String, dynamic> json) => Map<String, dynamic> _$SimpleClassOfBigIntToJson( SimpleClassOfBigInt instance) => <String, dynamic>{ - 'value': { + 'value': <String, dynamic>{ r'$1': instance.value.$1.toString(), 'named': instance.value.named.toString(), }, @@ -71,7 +71,7 @@ Map<String, dynamic> _$SimpleClassNullableOfBigIntToJson( <String, dynamic>{ 'value': instance.value == null ? null - : { + : <String, dynamic>{ r'$1': instance.value!.$1.toString(), 'named': instance.value!.named.toString(), }, @@ -102,7 +102,7 @@ SimpleClassOfBigIntNullable _$SimpleClassOfBigIntNullableFromJson( Map<String, dynamic> _$SimpleClassOfBigIntNullableToJson( SimpleClassOfBigIntNullable instance) => <String, dynamic>{ - 'value': { + 'value': <String, dynamic>{ r'$1': instance.value.$1?.toString(), 'named': instance.value.named?.toString(), }, @@ -129,7 +129,7 @@ Map<String, dynamic> _$SimpleClassNullableOfBigIntNullableToJson( <String, dynamic>{ 'value': instance.value == null ? null - : { + : <String, dynamic>{ r'$1': instance.value!.$1?.toString(), 'named': instance.value!.named?.toString(), }, @@ -148,7 +148,7 @@ SimpleClassOfBool _$SimpleClassOfBoolFromJson(Map<String, dynamic> json) => Map<String, dynamic> _$SimpleClassOfBoolToJson(SimpleClassOfBool instance) => <String, dynamic>{ - 'value': { + 'value': <String, dynamic>{ r'$1': instance.value.$1, 'named': instance.value.named, }, @@ -171,7 +171,7 @@ Map<String, dynamic> _$SimpleClassNullableOfBoolToJson( <String, dynamic>{ 'value': instance.value == null ? null - : { + : <String, dynamic>{ r'$1': instance.value!.$1, 'named': instance.value!.named, }, @@ -192,7 +192,7 @@ SimpleClassOfBoolNullable _$SimpleClassOfBoolNullableFromJson( Map<String, dynamic> _$SimpleClassOfBoolNullableToJson( SimpleClassOfBoolNullable instance) => <String, dynamic>{ - 'value': { + 'value': <String, dynamic>{ r'$1': instance.value.$1, 'named': instance.value.named, }, @@ -215,7 +215,7 @@ Map<String, dynamic> _$SimpleClassNullableOfBoolNullableToJson( <String, dynamic>{ 'value': instance.value == null ? null - : { + : <String, dynamic>{ r'$1': instance.value!.$1, 'named': instance.value!.named, }, @@ -236,7 +236,7 @@ SimpleClassOfDateTime _$SimpleClassOfDateTimeFromJson( Map<String, dynamic> _$SimpleClassOfDateTimeToJson( SimpleClassOfDateTime instance) => <String, dynamic>{ - 'value': { + 'value': <String, dynamic>{ r'$1': instance.value.$1.toIso8601String(), 'named': instance.value.named.toIso8601String(), }, @@ -259,7 +259,7 @@ Map<String, dynamic> _$SimpleClassNullableOfDateTimeToJson( <String, dynamic>{ 'value': instance.value == null ? null - : { + : <String, dynamic>{ r'$1': instance.value!.$1.toIso8601String(), 'named': instance.value!.named.toIso8601String(), }, @@ -284,7 +284,7 @@ SimpleClassOfDateTimeNullable _$SimpleClassOfDateTimeNullableFromJson( Map<String, dynamic> _$SimpleClassOfDateTimeNullableToJson( SimpleClassOfDateTimeNullable instance) => <String, dynamic>{ - 'value': { + 'value': <String, dynamic>{ r'$1': instance.value.$1?.toIso8601String(), 'named': instance.value.named?.toIso8601String(), }, @@ -312,7 +312,7 @@ Map<String, dynamic> _$SimpleClassNullableOfDateTimeNullableToJson( <String, dynamic>{ 'value': instance.value == null ? null - : { + : <String, dynamic>{ r'$1': instance.value!.$1?.toIso8601String(), 'named': instance.value!.named?.toIso8601String(), }, @@ -332,7 +332,7 @@ SimpleClassOfDouble _$SimpleClassOfDoubleFromJson(Map<String, dynamic> json) => Map<String, dynamic> _$SimpleClassOfDoubleToJson( SimpleClassOfDouble instance) => <String, dynamic>{ - 'value': { + 'value': <String, dynamic>{ r'$1': instance.value.$1, 'named': instance.value.named, }, @@ -355,7 +355,7 @@ Map<String, dynamic> _$SimpleClassNullableOfDoubleToJson( <String, dynamic>{ 'value': instance.value == null ? null - : { + : <String, dynamic>{ r'$1': instance.value!.$1, 'named': instance.value!.named, }, @@ -376,7 +376,7 @@ SimpleClassOfDoubleNullable _$SimpleClassOfDoubleNullableFromJson( Map<String, dynamic> _$SimpleClassOfDoubleNullableToJson( SimpleClassOfDoubleNullable instance) => <String, dynamic>{ - 'value': { + 'value': <String, dynamic>{ r'$1': instance.value.$1, 'named': instance.value.named, }, @@ -399,7 +399,7 @@ Map<String, dynamic> _$SimpleClassNullableOfDoubleNullableToJson( <String, dynamic>{ 'value': instance.value == null ? null - : { + : <String, dynamic>{ r'$1': instance.value!.$1, 'named': instance.value!.named, }, @@ -420,7 +420,7 @@ SimpleClassOfDuration _$SimpleClassOfDurationFromJson( Map<String, dynamic> _$SimpleClassOfDurationToJson( SimpleClassOfDuration instance) => <String, dynamic>{ - 'value': { + 'value': <String, dynamic>{ r'$1': instance.value.$1.inMicroseconds, 'named': instance.value.named.inMicroseconds, }, @@ -443,7 +443,7 @@ Map<String, dynamic> _$SimpleClassNullableOfDurationToJson( <String, dynamic>{ 'value': instance.value == null ? null - : { + : <String, dynamic>{ r'$1': instance.value!.$1.inMicroseconds, 'named': instance.value!.named.inMicroseconds, }, @@ -468,7 +468,7 @@ SimpleClassOfDurationNullable _$SimpleClassOfDurationNullableFromJson( Map<String, dynamic> _$SimpleClassOfDurationNullableToJson( SimpleClassOfDurationNullable instance) => <String, dynamic>{ - 'value': { + 'value': <String, dynamic>{ r'$1': instance.value.$1?.inMicroseconds, 'named': instance.value.named?.inMicroseconds, }, @@ -496,7 +496,7 @@ Map<String, dynamic> _$SimpleClassNullableOfDurationNullableToJson( <String, dynamic>{ 'value': instance.value == null ? null - : { + : <String, dynamic>{ r'$1': instance.value!.$1?.inMicroseconds, 'named': instance.value!.named?.inMicroseconds, }, @@ -517,7 +517,7 @@ SimpleClassOfDynamic _$SimpleClassOfDynamicFromJson( Map<String, dynamic> _$SimpleClassOfDynamicToJson( SimpleClassOfDynamic instance) => <String, dynamic>{ - 'value': { + 'value': <String, dynamic>{ r'$1': instance.value.$1, 'named': instance.value.named, }, @@ -540,7 +540,7 @@ Map<String, dynamic> _$SimpleClassNullableOfDynamicToJson( <String, dynamic>{ 'value': instance.value == null ? null - : { + : <String, dynamic>{ r'$1': instance.value!.$1, 'named': instance.value!.named, }, @@ -561,7 +561,7 @@ SimpleClassOfEnumType _$SimpleClassOfEnumTypeFromJson( Map<String, dynamic> _$SimpleClassOfEnumTypeToJson( SimpleClassOfEnumType instance) => <String, dynamic>{ - 'value': { + 'value': <String, dynamic>{ r'$1': _$EnumTypeEnumMap[instance.value.$1]!, 'named': _$EnumTypeEnumMap[instance.value.named]!, }, @@ -591,7 +591,7 @@ Map<String, dynamic> _$SimpleClassNullableOfEnumTypeToJson( <String, dynamic>{ 'value': instance.value == null ? null - : { + : <String, dynamic>{ r'$1': _$EnumTypeEnumMap[instance.value!.$1]!, 'named': _$EnumTypeEnumMap[instance.value!.named]!, }, @@ -612,7 +612,7 @@ SimpleClassOfEnumTypeNullable _$SimpleClassOfEnumTypeNullableFromJson( Map<String, dynamic> _$SimpleClassOfEnumTypeNullableToJson( SimpleClassOfEnumTypeNullable instance) => <String, dynamic>{ - 'value': { + 'value': <String, dynamic>{ r'$1': _$EnumTypeEnumMap[instance.value.$1], 'named': _$EnumTypeEnumMap[instance.value.named], }, @@ -637,7 +637,7 @@ Map<String, dynamic> _$SimpleClassNullableOfEnumTypeNullableToJson( <String, dynamic>{ 'value': instance.value == null ? null - : { + : <String, dynamic>{ r'$1': _$EnumTypeEnumMap[instance.value!.$1], 'named': _$EnumTypeEnumMap[instance.value!.named], }, @@ -658,7 +658,7 @@ SimpleClassOfFromJsonDynamicParam _$SimpleClassOfFromJsonDynamicParamFromJson( Map<String, dynamic> _$SimpleClassOfFromJsonDynamicParamToJson( SimpleClassOfFromJsonDynamicParam instance) => <String, dynamic>{ - 'value': { + 'value': <String, dynamic>{ r'$1': instance.value.$1, 'named': instance.value.named, }, @@ -682,7 +682,7 @@ Map<String, dynamic> _$SimpleClassNullableOfFromJsonDynamicParamToJson( <String, dynamic>{ 'value': instance.value == null ? null - : { + : <String, dynamic>{ r'$1': instance.value!.$1, 'named': instance.value!.named, }, @@ -704,7 +704,7 @@ SimpleClassOfFromJsonNullableObjectParam Map<String, dynamic> _$SimpleClassOfFromJsonNullableObjectParamToJson( SimpleClassOfFromJsonNullableObjectParam instance) => <String, dynamic>{ - 'value': { + 'value': <String, dynamic>{ r'$1': instance.value.$1, 'named': instance.value.named, }, @@ -728,7 +728,7 @@ Map<String, dynamic> _$SimpleClassNullableOfFromJsonNullableObjectParamToJson( <String, dynamic>{ 'value': instance.value == null ? null - : { + : <String, dynamic>{ r'$1': instance.value!.$1, 'named': instance.value!.named, }, @@ -749,7 +749,7 @@ SimpleClassOfFromJsonObjectParam _$SimpleClassOfFromJsonObjectParamFromJson( Map<String, dynamic> _$SimpleClassOfFromJsonObjectParamToJson( SimpleClassOfFromJsonObjectParam instance) => <String, dynamic>{ - 'value': { + 'value': <String, dynamic>{ r'$1': instance.value.$1, 'named': instance.value.named, }, @@ -774,7 +774,7 @@ Map<String, dynamic> _$SimpleClassNullableOfFromJsonObjectParamToJson( <String, dynamic>{ 'value': instance.value == null ? null - : { + : <String, dynamic>{ r'$1': instance.value!.$1, 'named': instance.value!.named, }, @@ -793,7 +793,7 @@ SimpleClassOfInt _$SimpleClassOfIntFromJson(Map<String, dynamic> json) => Map<String, dynamic> _$SimpleClassOfIntToJson(SimpleClassOfInt instance) => <String, dynamic>{ - 'value': { + 'value': <String, dynamic>{ r'$1': instance.value.$1, 'named': instance.value.named, }, @@ -816,7 +816,7 @@ Map<String, dynamic> _$SimpleClassNullableOfIntToJson( <String, dynamic>{ 'value': instance.value == null ? null - : { + : <String, dynamic>{ r'$1': instance.value!.$1, 'named': instance.value!.named, }, @@ -837,7 +837,7 @@ SimpleClassOfIntNullable _$SimpleClassOfIntNullableFromJson( Map<String, dynamic> _$SimpleClassOfIntNullableToJson( SimpleClassOfIntNullable instance) => <String, dynamic>{ - 'value': { + 'value': <String, dynamic>{ r'$1': instance.value.$1, 'named': instance.value.named, }, @@ -860,7 +860,7 @@ Map<String, dynamic> _$SimpleClassNullableOfIntNullableToJson( <String, dynamic>{ 'value': instance.value == null ? null - : { + : <String, dynamic>{ r'$1': instance.value!.$1, 'named': instance.value!.named, }, @@ -879,7 +879,7 @@ SimpleClassOfNum _$SimpleClassOfNumFromJson(Map<String, dynamic> json) => Map<String, dynamic> _$SimpleClassOfNumToJson(SimpleClassOfNum instance) => <String, dynamic>{ - 'value': { + 'value': <String, dynamic>{ r'$1': instance.value.$1, 'named': instance.value.named, }, @@ -902,7 +902,7 @@ Map<String, dynamic> _$SimpleClassNullableOfNumToJson( <String, dynamic>{ 'value': instance.value == null ? null - : { + : <String, dynamic>{ r'$1': instance.value!.$1, 'named': instance.value!.named, }, @@ -923,7 +923,7 @@ SimpleClassOfNumNullable _$SimpleClassOfNumNullableFromJson( Map<String, dynamic> _$SimpleClassOfNumNullableToJson( SimpleClassOfNumNullable instance) => <String, dynamic>{ - 'value': { + 'value': <String, dynamic>{ r'$1': instance.value.$1, 'named': instance.value.named, }, @@ -946,7 +946,7 @@ Map<String, dynamic> _$SimpleClassNullableOfNumNullableToJson( <String, dynamic>{ 'value': instance.value == null ? null - : { + : <String, dynamic>{ r'$1': instance.value!.$1, 'named': instance.value!.named, }, @@ -966,7 +966,7 @@ SimpleClassOfObject _$SimpleClassOfObjectFromJson(Map<String, dynamic> json) => Map<String, dynamic> _$SimpleClassOfObjectToJson( SimpleClassOfObject instance) => <String, dynamic>{ - 'value': { + 'value': <String, dynamic>{ r'$1': instance.value.$1, 'named': instance.value.named, }, @@ -989,7 +989,7 @@ Map<String, dynamic> _$SimpleClassNullableOfObjectToJson( <String, dynamic>{ 'value': instance.value == null ? null - : { + : <String, dynamic>{ r'$1': instance.value!.$1, 'named': instance.value!.named, }, @@ -1010,7 +1010,7 @@ SimpleClassOfObjectNullable _$SimpleClassOfObjectNullableFromJson( Map<String, dynamic> _$SimpleClassOfObjectNullableToJson( SimpleClassOfObjectNullable instance) => <String, dynamic>{ - 'value': { + 'value': <String, dynamic>{ r'$1': instance.value.$1, 'named': instance.value.named, }, @@ -1033,7 +1033,7 @@ Map<String, dynamic> _$SimpleClassNullableOfObjectNullableToJson( <String, dynamic>{ 'value': instance.value == null ? null - : { + : <String, dynamic>{ r'$1': instance.value!.$1, 'named': instance.value!.named, }, @@ -1067,13 +1067,13 @@ SimpleClassOfRecord _$SimpleClassOfRecordFromJson(Map<String, dynamic> json) => Map<String, dynamic> _$SimpleClassOfRecordToJson( SimpleClassOfRecord instance) => <String, dynamic>{ - 'value': { - r'$1': { + 'value': <String, dynamic>{ + r'$1': <String, dynamic>{ r'$1': instance.value.$1.$1, r'$2': instance.value.$1.$2, 'truth': instance.value.$1.truth, }, - 'named': { + 'named': <String, dynamic>{ r'$1': instance.value.named.$1, r'$2': instance.value.named.$2, 'truth': instance.value.named.truth, @@ -1112,13 +1112,13 @@ Map<String, dynamic> _$SimpleClassNullableOfRecordToJson( <String, dynamic>{ 'value': instance.value == null ? null - : { - r'$1': { + : <String, dynamic>{ + r'$1': <String, dynamic>{ r'$1': instance.value!.$1.$1, r'$2': instance.value!.$1.$2, 'truth': instance.value!.$1.truth, }, - 'named': { + 'named': <String, dynamic>{ r'$1': instance.value!.named.$1, r'$2': instance.value!.named.$2, 'truth': instance.value!.named.truth, @@ -1140,7 +1140,7 @@ SimpleClassOfString _$SimpleClassOfStringFromJson(Map<String, dynamic> json) => Map<String, dynamic> _$SimpleClassOfStringToJson( SimpleClassOfString instance) => <String, dynamic>{ - 'value': { + 'value': <String, dynamic>{ r'$1': instance.value.$1, 'named': instance.value.named, }, @@ -1163,7 +1163,7 @@ Map<String, dynamic> _$SimpleClassNullableOfStringToJson( <String, dynamic>{ 'value': instance.value == null ? null - : { + : <String, dynamic>{ r'$1': instance.value!.$1, 'named': instance.value!.named, }, @@ -1184,7 +1184,7 @@ SimpleClassOfStringNullable _$SimpleClassOfStringNullableFromJson( Map<String, dynamic> _$SimpleClassOfStringNullableToJson( SimpleClassOfStringNullable instance) => <String, dynamic>{ - 'value': { + 'value': <String, dynamic>{ r'$1': instance.value.$1, 'named': instance.value.named, }, @@ -1207,7 +1207,7 @@ Map<String, dynamic> _$SimpleClassNullableOfStringNullableToJson( <String, dynamic>{ 'value': instance.value == null ? null - : { + : <String, dynamic>{ r'$1': instance.value!.$1, 'named': instance.value!.named, }, @@ -1226,7 +1226,7 @@ SimpleClassOfUri _$SimpleClassOfUriFromJson(Map<String, dynamic> json) => Map<String, dynamic> _$SimpleClassOfUriToJson(SimpleClassOfUri instance) => <String, dynamic>{ - 'value': { + 'value': <String, dynamic>{ r'$1': instance.value.$1.toString(), 'named': instance.value.named.toString(), }, @@ -1249,7 +1249,7 @@ Map<String, dynamic> _$SimpleClassNullableOfUriToJson( <String, dynamic>{ 'value': instance.value == null ? null - : { + : <String, dynamic>{ r'$1': instance.value!.$1.toString(), 'named': instance.value!.named.toString(), }, @@ -1274,7 +1274,7 @@ SimpleClassOfUriNullable _$SimpleClassOfUriNullableFromJson( Map<String, dynamic> _$SimpleClassOfUriNullableToJson( SimpleClassOfUriNullable instance) => <String, dynamic>{ - 'value': { + 'value': <String, dynamic>{ r'$1': instance.value.$1?.toString(), 'named': instance.value.named?.toString(), }, @@ -1301,7 +1301,7 @@ Map<String, dynamic> _$SimpleClassNullableOfUriNullableToJson( <String, dynamic>{ 'value': instance.value == null ? null - : { + : <String, dynamic>{ r'$1': instance.value!.$1?.toString(), 'named': instance.value!.named?.toString(), }, diff --git a/json_serializable/test/supported_types/input.type_set.g.dart b/json_serializable/test/supported_types/input.type_set.g.dart index 861b0c4fe..73866adf9 100644 --- a/json_serializable/test/supported_types/input.type_set.g.dart +++ b/json_serializable/test/supported_types/input.type_set.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal, inference_failure_on_function_invocation, inference_failure_on_collection_literal part of 'input.type_set.dart'; @@ -637,7 +637,7 @@ Map<String, dynamic> _$SimpleClassOfRecordToJson( SimpleClassOfRecord instance) => <String, dynamic>{ 'value': instance.value - .map((e) => { + .map((e) => <String, dynamic>{ r'$1': e.$1, r'$2': e.$2, 'truth': e.truth, @@ -670,7 +670,7 @@ Map<String, dynamic> _$SimpleClassNullableOfRecordToJson( SimpleClassNullableOfRecord instance) => <String, dynamic>{ 'value': instance.value - ?.map((e) => { + ?.map((e) => <String, dynamic>{ r'$1': e.$1, r'$2': e.$2, 'truth': e.truth, diff --git a/json_serializable/test/supported_types/input.type_string.g.dart b/json_serializable/test/supported_types/input.type_string.g.dart index 4b1c64a20..6db4a402d 100644 --- a/json_serializable/test/supported_types/input.type_string.g.dart +++ b/json_serializable/test/supported_types/input.type_string.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal, inference_failure_on_function_invocation, inference_failure_on_collection_literal part of 'input.type_string.dart'; diff --git a/json_serializable/test/supported_types/input.type_uri.g.dart b/json_serializable/test/supported_types/input.type_uri.g.dart index e224f7036..b13890e87 100644 --- a/json_serializable/test/supported_types/input.type_uri.g.dart +++ b/json_serializable/test/supported_types/input.type_uri.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal, inference_failure_on_function_invocation, inference_failure_on_collection_literal part of 'input.type_uri.dart'; diff --git a/json_serializable/tool/readme/readme_examples.g.dart b/json_serializable/tool/readme/readme_examples.g.dart index be265dd6d..c22e9025b 100644 --- a/json_serializable/tool/readme/readme_examples.g.dart +++ b/json_serializable/tool/readme/readme_examples.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal, inference_failure_on_function_invocation, inference_failure_on_collection_literal part of 'readme_examples.dart'; diff --git a/json_serializable/tool/test_builder.dart b/json_serializable/tool/test_builder.dart index a0926b098..c2e5379b0 100644 --- a/json_serializable/tool/test_builder.dart +++ b/json_serializable/tool/test_builder.dart @@ -21,8 +21,7 @@ class _TestBuilder implements Builder { final sourceContent = await buildStep.readAsString(buildStep.inputId); - final factories = - SplayTreeMap.from({'$_kitchenSinkBaseName.dart': 'normal'}); + final factories = SplayTreeMap.of({'$_kitchenSinkBaseName.dart': 'normal'}); for (var config in _fileConfigurationMap[baseName]!) { final extension = _configToExtension(config); diff --git a/shared_test/pubspec.yaml b/shared_test/pubspec.yaml index c52b9527e..6cb35af92 100644 --- a/shared_test/pubspec.yaml +++ b/shared_test/pubspec.yaml @@ -8,4 +8,4 @@ dependencies: test: ^1.6.0 dev_dependencies: - dart_flutter_team_lints: ^1.0.0 + dart_flutter_team_lints: ^2.0.0 From f7cb51662b21d11b3fdb6c5e0fdd46431cec59d4 Mon Sep 17 00:00:00 2001 From: Lasindu Weerasinghe <lasindunuwanga@gmail.com> Date: Sun, 29 Oct 2023 03:13:06 +0530 Subject: [PATCH 506/569] flutter pub run notice removed (#1364) --- example/README.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/example/README.md b/example/README.md index 65fc28f59..bb6cf3c79 100644 --- a/example/README.md +++ b/example/README.md @@ -32,9 +32,6 @@ Run `dart run build_runner build` to generate files into your source directory. [INFO] Build: Succeeded after 4687ms with 1 outputs ``` -_NOTE_: If you're using Flutter, replace `dart run` with -`flutter pub run`. - [example]: lib/example.dart [example_g]: lib/example.g.dart [json_annotation]: https://pub.dev/packages/json_annotation From a072c014ae7bd652926d4ee73fa1fb4cabd8a4b4 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Wed, 20 Dec 2023 10:03:58 -0800 Subject: [PATCH 507/569] blast_repo fixes (#1383) no-response --- .github/workflows/no-response.yml | 36 +++++++++++++++++-------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/.github/workflows/no-response.yml b/.github/workflows/no-response.yml index 599c7c209..d60d9fa7f 100644 --- a/.github/workflows/no-response.yml +++ b/.github/workflows/no-response.yml @@ -1,12 +1,10 @@ # A workflow to close issues where the author hasn't responded to a request for -# more information; see https://github.com/godofredoc/no-response for docs. +# more information; see https://github.com/actions/stale. name: No Response -# Both `issue_comment` and `scheduled` event types are required. +# Run as a daily cron. on: - issue_comment: - types: [created] schedule: # Every day at 8am - cron: '0 8 * * *' @@ -14,20 +12,26 @@ on: # All permissions not specified are set to 'none'. permissions: issues: write + pull-requests: write jobs: - noResponse: + no-response: runs-on: ubuntu-latest if: ${{ github.repository_owner == 'google' }} steps: - - uses: godofredoc/no-response@0ce2dc0e63e1c7d2b87752ceed091f6d32c9df09 - with: - responseRequiredLabel: "State: needs info" - daysUntilClose: 14 - # Comment to post when closing an Issue for lack of response. - closeComment: > - Without additional information we're not able to resolve this - issue, so it will be closed at this time. You're still free to add - more info and respond to any questions above, though. We'll reopen - the case if you do. Thanks for your contribution! - token: ${{ github.token }} + - uses: actions/stale@1160a2240286f5da8ec72b1c0816ce2481aabf84 + with: + # Don't automatically mark inactive issues+PRs as stale. + days-before-stale: -1 + # Close needs-info issues and PRs after 14 days of inactivity. + days-before-close: 14 + stale-issue-label: "needs-info" + close-issue-message: > + Without additional information we're not able to resolve this issue. + Feel free to add more info or respond to any questions above and we + can reopen the case. Thanks for your contribution! + stale-pr-label: "needs-info" + close-pr-message: > + Without additional information we're not able to resolve this PR. + Feel free to add more info or respond to any questions above. + Thanks for your contribution! From ce2de93a1749088ebbb97e5550fdb91e2b510715 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 1 Jan 2024 10:16:59 -0800 Subject: [PATCH 508/569] Bump actions/stale from 8.0.0 to 9.0.0 (#1387) Bumps [actions/stale](https://github.com/actions/stale) from 8.0.0 to 9.0.0. - [Release notes](https://github.com/actions/stale/releases) - [Changelog](https://github.com/actions/stale/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/stale/compare/1160a2240286f5da8ec72b1c0816ce2481aabf84...28ca1036281a5e5922ead5184a1bbf96e5fc984e) --- updated-dependencies: - dependency-name: actions/stale dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/no-response.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/no-response.yml b/.github/workflows/no-response.yml index d60d9fa7f..9cd84a5d2 100644 --- a/.github/workflows/no-response.yml +++ b/.github/workflows/no-response.yml @@ -19,7 +19,7 @@ jobs: runs-on: ubuntu-latest if: ${{ github.repository_owner == 'google' }} steps: - - uses: actions/stale@1160a2240286f5da8ec72b1c0816ce2481aabf84 + - uses: actions/stale@28ca1036281a5e5922ead5184a1bbf96e5fc984e with: # Don't automatically mark inactive issues+PRs as stale. days-before-stale: -1 From ac8b94176468416a3fe00e5a1e24fba05823137e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 1 Jan 2024 10:17:20 -0800 Subject: [PATCH 509/569] Bump actions/setup-node from 3.8.1 to 4.0.1 (#1386) Bumps [actions/setup-node](https://github.com/actions/setup-node) from 3.8.1 to 4.0.1. - [Release notes](https://github.com/actions/setup-node/releases) - [Commits](https://github.com/actions/setup-node/compare/5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d...b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8) --- updated-dependencies: - dependency-name: actions/setup-node dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/markdown_linter.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/markdown_linter.yml b/.github/workflows/markdown_linter.yml index b6243be61..0b313ee1f 100644 --- a/.github/workflows/markdown_linter.yml +++ b/.github/workflows/markdown_linter.yml @@ -21,7 +21,7 @@ jobs: steps: - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d + uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 with: node-version: ${{ matrix.node-version }} - name: Install dependencies From 71621345d687fb879539e0af86a4fdfad6c81980 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 1 Jan 2024 10:27:59 -0800 Subject: [PATCH 510/569] Bump actions/checkout from 4.1.0 to 4.1.1 (#1366) Bumps [actions/checkout](https://github.com/actions/checkout) from 4.1.0 to 4.1.1. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/8ade135a41bc03ea155e62e844d188df1ea18608...b4ffde65f46336ab88eb53be808477a3936bae11) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/dart.yml | 26 +++++++++++++------------- .github/workflows/markdown_linter.yml | 4 ++-- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 8311a9857..fcfcc05f1 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -34,7 +34,7 @@ jobs: sdk: stable - id: checkout name: Checkout repository - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - name: mono_repo self validate run: dart pub global activate mono_repo 6.5.7 - name: mono_repo self validate @@ -59,7 +59,7 @@ jobs: sdk: "3.0.0" - id: checkout name: Checkout repository - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -125,7 +125,7 @@ jobs: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -211,7 +211,7 @@ jobs: sdk: "3.0.0" - id: checkout name: Checkout repository - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -272,7 +272,7 @@ jobs: sdk: "3.0.0" - id: checkout name: Checkout repository - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -306,7 +306,7 @@ jobs: sdk: "3.0.0" - id: checkout name: Checkout repository - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -340,7 +340,7 @@ jobs: sdk: "3.0.0" - id: checkout name: Checkout repository - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -374,7 +374,7 @@ jobs: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -435,7 +435,7 @@ jobs: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -469,7 +469,7 @@ jobs: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -503,7 +503,7 @@ jobs: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -537,7 +537,7 @@ jobs: sdk: "3.0.0" - id: checkout name: Checkout repository - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -597,7 +597,7 @@ jobs: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade diff --git a/.github/workflows/markdown_linter.yml b/.github/workflows/markdown_linter.yml index 0b313ee1f..0ab645c93 100644 --- a/.github/workflows/markdown_linter.yml +++ b/.github/workflows/markdown_linter.yml @@ -11,7 +11,7 @@ jobs: markdown-link-check: runs-on: ubuntu-latest steps: - - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - uses: gaurav-nelson/github-action-markdown-link-check@v1 markdown_lint: runs-on: ubuntu-latest @@ -19,7 +19,7 @@ jobs: matrix: node-version: [ 14.x ] steps: - - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 with: From 7f1c19290e25321571d21e4001d3af0da1fbbd42 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 1 Jan 2024 10:28:23 -0800 Subject: [PATCH 511/569] Bump dart-lang/setup-dart from 1.5.1 to 1.6.0 (#1367) Bumps [dart-lang/setup-dart](https://github.com/dart-lang/setup-dart) from 1.5.1 to 1.6.0. - [Release notes](https://github.com/dart-lang/setup-dart/releases) - [Changelog](https://github.com/dart-lang/setup-dart/blob/main/CHANGELOG.md) - [Commits](https://github.com/dart-lang/setup-dart/compare/8a4b97ea2017cc079571daec46542f76189836b1...b64355ae6ca0b5d484f0106a033dd1388965d06d) --- updated-dependencies: - dependency-name: dart-lang/setup-dart dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/dart.yml | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index fcfcc05f1..674fc83fc 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -29,7 +29,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@8a4b97ea2017cc079571daec46542f76189836b1 + uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d with: sdk: stable - id: checkout @@ -54,7 +54,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@8a4b97ea2017cc079571daec46542f76189836b1 + uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d with: sdk: "3.0.0" - id: checkout @@ -120,7 +120,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@8a4b97ea2017cc079571daec46542f76189836b1 + uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d with: sdk: dev - id: checkout @@ -206,7 +206,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@8a4b97ea2017cc079571daec46542f76189836b1 + uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d with: sdk: "3.0.0" - id: checkout @@ -267,7 +267,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@8a4b97ea2017cc079571daec46542f76189836b1 + uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d with: sdk: "3.0.0" - id: checkout @@ -301,7 +301,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@8a4b97ea2017cc079571daec46542f76189836b1 + uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d with: sdk: "3.0.0" - id: checkout @@ -335,7 +335,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@8a4b97ea2017cc079571daec46542f76189836b1 + uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d with: sdk: "3.0.0" - id: checkout @@ -369,7 +369,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@8a4b97ea2017cc079571daec46542f76189836b1 + uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d with: sdk: dev - id: checkout @@ -430,7 +430,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@8a4b97ea2017cc079571daec46542f76189836b1 + uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d with: sdk: dev - id: checkout @@ -464,7 +464,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@8a4b97ea2017cc079571daec46542f76189836b1 + uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d with: sdk: dev - id: checkout @@ -498,7 +498,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@8a4b97ea2017cc079571daec46542f76189836b1 + uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d with: sdk: dev - id: checkout @@ -532,7 +532,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@8a4b97ea2017cc079571daec46542f76189836b1 + uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d with: sdk: "3.0.0" - id: checkout @@ -592,7 +592,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@8a4b97ea2017cc079571daec46542f76189836b1 + uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d with: sdk: dev - id: checkout From 84e3c2ab25469d49a7c91f2ca427702b506117d9 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Mon, 15 Jan 2024 13:39:53 -0800 Subject: [PATCH 512/569] CI: fix markdown lint (#1389) --- .github/workflows/markdown_linter.yml | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/.github/workflows/markdown_linter.yml b/.github/workflows/markdown_linter.yml index 0ab645c93..3d3431175 100644 --- a/.github/workflows/markdown_linter.yml +++ b/.github/workflows/markdown_linter.yml @@ -15,16 +15,6 @@ jobs: - uses: gaurav-nelson/github-action-markdown-link-check@v1 markdown_lint: runs-on: ubuntu-latest - strategy: - matrix: - node-version: [ 14.x ] steps: - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 - with: - node-version: ${{ matrix.node-version }} - - name: Install dependencies - run: npm install --global markdownlint-cli2 - - name: Run lint check - run: markdownlint-cli2-fix "**/*.md" + - uses: DavidAnson/markdownlint-cli2-action@v9 From e9527ee1a984afdeeba79579efb983bfd84e6694 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Mon, 15 Jan 2024 15:06:47 -0800 Subject: [PATCH 513/569] blast_repo fixes (#1390) auto-publish, dependabot, github-actions, no-response --- .github/dependabot.yml | 8 +++-- .github/workflows/dart.yml | 52 +++++++++++++-------------- .github/workflows/markdown_linter.yml | 4 +-- .github/workflows/publish.yaml | 3 ++ 4 files changed, 36 insertions(+), 31 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 2a0f49229..f4169fa24 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -4,7 +4,9 @@ version: 2 updates: -- package-ecosystem: "github-actions" - directory: "/" +- package-ecosystem: github-actions + directory: / schedule: - interval: "monthly" + interval: monthly + labels: + - autosubmit diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 674fc83fc..abfef05fa 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -21,7 +21,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 + uses: actions/cache@e12d46a63a90f2fae62d114769bbf2a179198b5c with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:stable" @@ -29,7 +29,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d + uses: dart-lang/setup-dart@ca7e6fee45ffbd82b555a7ebfc236d2c86439f5b with: sdk: stable - id: checkout @@ -44,7 +44,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 + uses: actions/cache@e12d46a63a90f2fae62d114769bbf2a179198b5c with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:analyze_1" @@ -54,7 +54,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d + uses: dart-lang/setup-dart@ca7e6fee45ffbd82b555a7ebfc236d2c86439f5b with: sdk: "3.0.0" - id: checkout @@ -110,7 +110,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 + uses: actions/cache@e12d46a63a90f2fae62d114769bbf2a179198b5c with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:format-analyze_0" @@ -120,7 +120,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d + uses: dart-lang/setup-dart@ca7e6fee45ffbd82b555a7ebfc236d2c86439f5b with: sdk: dev - id: checkout @@ -196,7 +196,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 + uses: actions/cache@e12d46a63a90f2fae62d114769bbf2a179198b5c with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" @@ -206,7 +206,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d + uses: dart-lang/setup-dart@ca7e6fee45ffbd82b555a7ebfc236d2c86439f5b with: sdk: "3.0.0" - id: checkout @@ -257,7 +257,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 + uses: actions/cache@e12d46a63a90f2fae62d114769bbf2a179198b5c with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:json_serializable;commands:test_3" @@ -267,7 +267,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d + uses: dart-lang/setup-dart@ca7e6fee45ffbd82b555a7ebfc236d2c86439f5b with: sdk: "3.0.0" - id: checkout @@ -291,7 +291,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 + uses: actions/cache@e12d46a63a90f2fae62d114769bbf2a179198b5c with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:json_serializable;commands:test_1" @@ -301,7 +301,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d + uses: dart-lang/setup-dart@ca7e6fee45ffbd82b555a7ebfc236d2c86439f5b with: sdk: "3.0.0" - id: checkout @@ -325,7 +325,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 + uses: actions/cache@e12d46a63a90f2fae62d114769bbf2a179198b5c with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:json_serializable;commands:test_2" @@ -335,7 +335,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d + uses: dart-lang/setup-dart@ca7e6fee45ffbd82b555a7ebfc236d2c86439f5b with: sdk: "3.0.0" - id: checkout @@ -359,7 +359,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 + uses: actions/cache@e12d46a63a90f2fae62d114769bbf2a179198b5c with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" @@ -369,7 +369,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d + uses: dart-lang/setup-dart@ca7e6fee45ffbd82b555a7ebfc236d2c86439f5b with: sdk: dev - id: checkout @@ -420,7 +420,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 + uses: actions/cache@e12d46a63a90f2fae62d114769bbf2a179198b5c with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:json_serializable;commands:test_3" @@ -430,7 +430,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d + uses: dart-lang/setup-dart@ca7e6fee45ffbd82b555a7ebfc236d2c86439f5b with: sdk: dev - id: checkout @@ -454,7 +454,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 + uses: actions/cache@e12d46a63a90f2fae62d114769bbf2a179198b5c with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:json_serializable;commands:test_1" @@ -464,7 +464,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d + uses: dart-lang/setup-dart@ca7e6fee45ffbd82b555a7ebfc236d2c86439f5b with: sdk: dev - id: checkout @@ -488,7 +488,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 + uses: actions/cache@e12d46a63a90f2fae62d114769bbf2a179198b5c with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:json_serializable;commands:test_2" @@ -498,7 +498,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d + uses: dart-lang/setup-dart@ca7e6fee45ffbd82b555a7ebfc236d2c86439f5b with: sdk: dev - id: checkout @@ -522,7 +522,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 + uses: actions/cache@e12d46a63a90f2fae62d114769bbf2a179198b5c with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:_test_yaml-checked_yaml-example;commands:test_1" @@ -532,7 +532,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d + uses: dart-lang/setup-dart@ca7e6fee45ffbd82b555a7ebfc236d2c86439f5b with: sdk: "3.0.0" - id: checkout @@ -582,7 +582,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 + uses: actions/cache@e12d46a63a90f2fae62d114769bbf2a179198b5c with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:_test_yaml-checked_yaml-example;commands:test_1" @@ -592,7 +592,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d + uses: dart-lang/setup-dart@ca7e6fee45ffbd82b555a7ebfc236d2c86439f5b with: sdk: dev - id: checkout diff --git a/.github/workflows/markdown_linter.yml b/.github/workflows/markdown_linter.yml index 3d3431175..15f176ba1 100644 --- a/.github/workflows/markdown_linter.yml +++ b/.github/workflows/markdown_linter.yml @@ -12,9 +12,9 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - - uses: gaurav-nelson/github-action-markdown-link-check@v1 + - uses: gaurav-nelson/github-action-markdown-link-check@5c5dfc0ac2e225883c0e5f03a85311ec2830d368 markdown_lint: runs-on: ubuntu-latest steps: - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - - uses: DavidAnson/markdownlint-cli2-action@v9 + - uses: DavidAnson/markdownlint-cli2-action@455b6612a7b7a80f28be9e019b70abdd11696e4e diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 8c8f07d14..afff618d2 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -12,3 +12,6 @@ jobs: publish: if: ${{ github.repository_owner == 'google' }} uses: dart-lang/ecosystem/.github/workflows/publish.yaml@main + permissions: + id-token: write # Required for authentication using OIDC + pull-requests: write # Required for writing the pull request note From 28f7c9a6909934a8c225889432cd084cefc6c6cd Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 28 Feb 2024 15:17:17 -0800 Subject: [PATCH 514/569] Bump actions/cache from 3.3.3 to 4.0.0 (#1397) Bumps [actions/cache](https://github.com/actions/cache) from 3.3.3 to 4.0.0. - [Release notes](https://github.com/actions/cache/releases) - [Changelog](https://github.com/actions/cache/blob/main/RELEASES.md) - [Commits](https://github.com/actions/cache/compare/e12d46a63a90f2fae62d114769bbf2a179198b5c...13aacd865c20de90d75de3b17ebe84f7a17d57d2) --- updated-dependencies: - dependency-name: actions/cache dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/dart.yml | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index abfef05fa..99da436cf 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -21,7 +21,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@e12d46a63a90f2fae62d114769bbf2a179198b5c + uses: actions/cache@13aacd865c20de90d75de3b17ebe84f7a17d57d2 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:stable" @@ -44,7 +44,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@e12d46a63a90f2fae62d114769bbf2a179198b5c + uses: actions/cache@13aacd865c20de90d75de3b17ebe84f7a17d57d2 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:analyze_1" @@ -110,7 +110,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@e12d46a63a90f2fae62d114769bbf2a179198b5c + uses: actions/cache@13aacd865c20de90d75de3b17ebe84f7a17d57d2 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:format-analyze_0" @@ -196,7 +196,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@e12d46a63a90f2fae62d114769bbf2a179198b5c + uses: actions/cache@13aacd865c20de90d75de3b17ebe84f7a17d57d2 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" @@ -257,7 +257,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@e12d46a63a90f2fae62d114769bbf2a179198b5c + uses: actions/cache@13aacd865c20de90d75de3b17ebe84f7a17d57d2 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:json_serializable;commands:test_3" @@ -291,7 +291,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@e12d46a63a90f2fae62d114769bbf2a179198b5c + uses: actions/cache@13aacd865c20de90d75de3b17ebe84f7a17d57d2 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:json_serializable;commands:test_1" @@ -325,7 +325,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@e12d46a63a90f2fae62d114769bbf2a179198b5c + uses: actions/cache@13aacd865c20de90d75de3b17ebe84f7a17d57d2 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:json_serializable;commands:test_2" @@ -359,7 +359,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@e12d46a63a90f2fae62d114769bbf2a179198b5c + uses: actions/cache@13aacd865c20de90d75de3b17ebe84f7a17d57d2 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" @@ -420,7 +420,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@e12d46a63a90f2fae62d114769bbf2a179198b5c + uses: actions/cache@13aacd865c20de90d75de3b17ebe84f7a17d57d2 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:json_serializable;commands:test_3" @@ -454,7 +454,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@e12d46a63a90f2fae62d114769bbf2a179198b5c + uses: actions/cache@13aacd865c20de90d75de3b17ebe84f7a17d57d2 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:json_serializable;commands:test_1" @@ -488,7 +488,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@e12d46a63a90f2fae62d114769bbf2a179198b5c + uses: actions/cache@13aacd865c20de90d75de3b17ebe84f7a17d57d2 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:json_serializable;commands:test_2" @@ -522,7 +522,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@e12d46a63a90f2fae62d114769bbf2a179198b5c + uses: actions/cache@13aacd865c20de90d75de3b17ebe84f7a17d57d2 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:_test_yaml-checked_yaml-example;commands:test_1" @@ -582,7 +582,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@e12d46a63a90f2fae62d114769bbf2a179198b5c + uses: actions/cache@13aacd865c20de90d75de3b17ebe84f7a17d57d2 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:_test_yaml-checked_yaml-example;commands:test_1" From 3a833d983ab4e158ad435346bfaa8396c0f58e1d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 28 Feb 2024 15:27:44 -0800 Subject: [PATCH 515/569] Bump DavidAnson/markdownlint-cli2-action from 14.0.0 to 15.0.0 (#1395) Bumps [DavidAnson/markdownlint-cli2-action](https://github.com/davidanson/markdownlint-cli2-action) from 14.0.0 to 15.0.0. - [Release notes](https://github.com/davidanson/markdownlint-cli2-action/releases) - [Commits](https://github.com/davidanson/markdownlint-cli2-action/compare/455b6612a7b7a80f28be9e019b70abdd11696e4e...510b996878fc0d1a46c8a04ec86b06dbfba09de7) --- updated-dependencies: - dependency-name: DavidAnson/markdownlint-cli2-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/markdown_linter.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/markdown_linter.yml b/.github/workflows/markdown_linter.yml index 15f176ba1..f7bab67dc 100644 --- a/.github/workflows/markdown_linter.yml +++ b/.github/workflows/markdown_linter.yml @@ -17,4 +17,4 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - - uses: DavidAnson/markdownlint-cli2-action@455b6612a7b7a80f28be9e019b70abdd11696e4e + - uses: DavidAnson/markdownlint-cli2-action@510b996878fc0d1a46c8a04ec86b06dbfba09de7 From 24a830c32f5a54c22f52bb207d70c4f6cbd9179c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 28 Feb 2024 15:27:50 -0800 Subject: [PATCH 516/569] Bump dart-lang/setup-dart from 1.6.1 to 1.6.2 (#1396) Bumps [dart-lang/setup-dart](https://github.com/dart-lang/setup-dart) from 1.6.1 to 1.6.2. - [Release notes](https://github.com/dart-lang/setup-dart/releases) - [Changelog](https://github.com/dart-lang/setup-dart/blob/main/CHANGELOG.md) - [Commits](https://github.com/dart-lang/setup-dart/compare/ca7e6fee45ffbd82b555a7ebfc236d2c86439f5b...fedb1266e91cf51be2fdb382869461a434b920a3) --- updated-dependencies: - dependency-name: dart-lang/setup-dart dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/dart.yml | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 99da436cf..ab3c13d9b 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -29,7 +29,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@ca7e6fee45ffbd82b555a7ebfc236d2c86439f5b + uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3 with: sdk: stable - id: checkout @@ -54,7 +54,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@ca7e6fee45ffbd82b555a7ebfc236d2c86439f5b + uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3 with: sdk: "3.0.0" - id: checkout @@ -120,7 +120,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@ca7e6fee45ffbd82b555a7ebfc236d2c86439f5b + uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3 with: sdk: dev - id: checkout @@ -206,7 +206,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@ca7e6fee45ffbd82b555a7ebfc236d2c86439f5b + uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3 with: sdk: "3.0.0" - id: checkout @@ -267,7 +267,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@ca7e6fee45ffbd82b555a7ebfc236d2c86439f5b + uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3 with: sdk: "3.0.0" - id: checkout @@ -301,7 +301,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@ca7e6fee45ffbd82b555a7ebfc236d2c86439f5b + uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3 with: sdk: "3.0.0" - id: checkout @@ -335,7 +335,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@ca7e6fee45ffbd82b555a7ebfc236d2c86439f5b + uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3 with: sdk: "3.0.0" - id: checkout @@ -369,7 +369,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@ca7e6fee45ffbd82b555a7ebfc236d2c86439f5b + uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3 with: sdk: dev - id: checkout @@ -430,7 +430,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@ca7e6fee45ffbd82b555a7ebfc236d2c86439f5b + uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3 with: sdk: dev - id: checkout @@ -464,7 +464,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@ca7e6fee45ffbd82b555a7ebfc236d2c86439f5b + uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3 with: sdk: dev - id: checkout @@ -498,7 +498,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@ca7e6fee45ffbd82b555a7ebfc236d2c86439f5b + uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3 with: sdk: dev - id: checkout @@ -532,7 +532,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@ca7e6fee45ffbd82b555a7ebfc236d2c86439f5b + uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3 with: sdk: "3.0.0" - id: checkout @@ -592,7 +592,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@ca7e6fee45ffbd82b555a7ebfc236d2c86439f5b + uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3 with: sdk: dev - id: checkout From 324acee3c6a3cdfda9d1d797daf8cdc01793a862 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 1 Mar 2024 11:42:41 -0800 Subject: [PATCH 517/569] Bump actions/cache from 4.0.0 to 4.0.1 (#1404) Bumps [actions/cache](https://github.com/actions/cache) from 4.0.0 to 4.0.1. - [Release notes](https://github.com/actions/cache/releases) - [Changelog](https://github.com/actions/cache/blob/main/RELEASES.md) - [Commits](https://github.com/actions/cache/compare/13aacd865c20de90d75de3b17ebe84f7a17d57d2...ab5e6d0c87105b4c9c2047343972218f562e4319) --- updated-dependencies: - dependency-name: actions/cache dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/dart.yml | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index ab3c13d9b..09c4122c2 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -21,7 +21,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@13aacd865c20de90d75de3b17ebe84f7a17d57d2 + uses: actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:stable" @@ -44,7 +44,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@13aacd865c20de90d75de3b17ebe84f7a17d57d2 + uses: actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:analyze_1" @@ -110,7 +110,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@13aacd865c20de90d75de3b17ebe84f7a17d57d2 + uses: actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:format-analyze_0" @@ -196,7 +196,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@13aacd865c20de90d75de3b17ebe84f7a17d57d2 + uses: actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" @@ -257,7 +257,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@13aacd865c20de90d75de3b17ebe84f7a17d57d2 + uses: actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:json_serializable;commands:test_3" @@ -291,7 +291,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@13aacd865c20de90d75de3b17ebe84f7a17d57d2 + uses: actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:json_serializable;commands:test_1" @@ -325,7 +325,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@13aacd865c20de90d75de3b17ebe84f7a17d57d2 + uses: actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:json_serializable;commands:test_2" @@ -359,7 +359,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@13aacd865c20de90d75de3b17ebe84f7a17d57d2 + uses: actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" @@ -420,7 +420,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@13aacd865c20de90d75de3b17ebe84f7a17d57d2 + uses: actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:json_serializable;commands:test_3" @@ -454,7 +454,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@13aacd865c20de90d75de3b17ebe84f7a17d57d2 + uses: actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:json_serializable;commands:test_1" @@ -488,7 +488,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@13aacd865c20de90d75de3b17ebe84f7a17d57d2 + uses: actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:json_serializable;commands:test_2" @@ -522,7 +522,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@13aacd865c20de90d75de3b17ebe84f7a17d57d2 + uses: actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:_test_yaml-checked_yaml-example;commands:test_1" @@ -582,7 +582,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@13aacd865c20de90d75de3b17ebe84f7a17d57d2 + uses: actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:_test_yaml-checked_yaml-example;commands:test_1" From 5b46ef9d17b94c64d002b00ddb2908a3714159af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sym=C3=A9on=20ROUGEVIN-B=C3=82VILLE?= <61052165+ChreSyr@users.noreply.github.com> Date: Sun, 3 Mar 2024 01:22:18 +0100 Subject: [PATCH 518/569] Added createJsonKeys (#1401) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes https://github.com/google/json_serializable.dart/issues/1400 Co-authored-by: Syméon ROUGEVIN <symeon@oclocher.fr> Co-authored-by: Kevin Moore <kevmoo@google.com> --- json_annotation/CHANGELOG.md | 4 ++- .../lib/src/json_serializable.dart | 16 ++++++++++ .../lib/src/json_serializable.g.dart | 5 +++ json_annotation/pubspec.yaml | 2 +- json_serializable/CHANGELOG.md | 4 ++- json_serializable/README.md | 19 +++++------ json_serializable/lib/src/encoder_helper.dart | 22 +++++++++++++ .../lib/src/generator_helper.dart | 4 +++ .../lib/src/type_helpers/config_types.dart | 6 ++++ json_serializable/lib/src/utils.dart | 2 ++ json_serializable/pubspec.yaml | 6 +++- json_serializable/test/config_test.dart | 1 + .../test/integration/integration_test.dart | 5 +++ .../test/integration/json_keys_example.dart | 32 +++++++++++++++++++ .../test/integration/json_keys_example.g.dart | 24 ++++++++++++++ json_serializable/test/shared_config.dart | 1 + .../test/test_sources/test_sources.dart | 1 + .../tool/readme/readme_template.md | 1 + 18 files changed, 142 insertions(+), 13 deletions(-) create mode 100644 json_serializable/test/integration/json_keys_example.dart create mode 100644 json_serializable/test/integration/json_keys_example.g.dart diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index 5929a6840..1b3d6be21 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -1,6 +1,8 @@ -## 4.8.2-wip +## 4.9.0-wip - Require Dart 3.0 +- Added `JsonSerializable(createJsonKeys: true)`. + ([#1401](https://github.com/google/json_serializable.dart/pull/1401)) ## 4.8.1 diff --git a/json_annotation/lib/src/json_serializable.dart b/json_annotation/lib/src/json_serializable.dart index 71a6e4550..fe9b5cc98 100644 --- a/json_annotation/lib/src/json_serializable.dart +++ b/json_annotation/lib/src/json_serializable.dart @@ -87,6 +87,21 @@ class JsonSerializable { /// such as [fieldRename]. final bool? createFieldMap; + /// If `true` (defaults to false), a private class `_$ExampleJsonKeys` + /// constant is created in the generated part file. + /// + /// This class will contain every property, with the json key as value, + /// exposing a secured way to access the json key from the property. + /// + /// ```dart + /// @JsonSerializable(createJsonKeys: true) + /// class Example { + /// // ... + /// static const jsonKeys = _$PublicationImplJsonKeys(); + /// } + /// ``` + final bool? createJsonKeys; + /// If `true` (defaults to false), a private, static `_$ExamplePerFieldToJson` /// abstract class will be generated in the part file. /// @@ -247,6 +262,7 @@ class JsonSerializable { this.checked, this.constructor, this.createFieldMap, + this.createJsonKeys, this.createFactory, this.createToJson, this.disallowUnrecognizedKeys, diff --git a/json_annotation/lib/src/json_serializable.g.dart b/json_annotation/lib/src/json_serializable.g.dart index 9d02a187c..80614717e 100644 --- a/json_annotation/lib/src/json_serializable.g.dart +++ b/json_annotation/lib/src/json_serializable.g.dart @@ -19,6 +19,7 @@ JsonSerializable _$JsonSerializableFromJson(Map<String, dynamic> json) => 'constructor', 'create_factory', 'create_field_map', + 'create_json_keys', 'create_per_field_to_json', 'create_to_json', 'disallow_unrecognized_keys', @@ -35,6 +36,8 @@ JsonSerializable _$JsonSerializableFromJson(Map<String, dynamic> json) => constructor: $checkedConvert('constructor', (v) => v as String?), createFieldMap: $checkedConvert('create_field_map', (v) => v as bool?), + createJsonKeys: + $checkedConvert('create_json_keys', (v) => v as bool?), createFactory: $checkedConvert('create_factory', (v) => v as bool?), createToJson: $checkedConvert('create_to_json', (v) => v as bool?), disallowUnrecognizedKeys: @@ -56,6 +59,7 @@ JsonSerializable _$JsonSerializableFromJson(Map<String, dynamic> json) => fieldKeyMap: const { 'anyMap': 'any_map', 'createFieldMap': 'create_field_map', + 'createJsonKeys': 'create_json_keys', 'createFactory': 'create_factory', 'createToJson': 'create_to_json', 'disallowUnrecognizedKeys': 'disallow_unrecognized_keys', @@ -75,6 +79,7 @@ Map<String, dynamic> _$JsonSerializableToJson(JsonSerializable instance) => 'constructor': instance.constructor, 'create_factory': instance.createFactory, 'create_field_map': instance.createFieldMap, + 'create_json_keys': instance.createJsonKeys, 'create_per_field_to_json': instance.createPerFieldToJson, 'create_to_json': instance.createToJson, 'disallow_unrecognized_keys': instance.disallowUnrecognizedKeys, diff --git a/json_annotation/pubspec.yaml b/json_annotation/pubspec.yaml index a6b97a231..aabbd9681 100644 --- a/json_annotation/pubspec.yaml +++ b/json_annotation/pubspec.yaml @@ -1,5 +1,5 @@ name: json_annotation -version: 4.8.2-wip +version: 4.9.0-wip description: >- Classes and helper functions that support JSON code generation via the `json_serializable` package. diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 0d36ca8af..845d563b2 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,6 +1,8 @@ -## 6.7.2-wip +## 6.8.0-wip - Add type arguments to `Map` literals used for `Record` serialization. +- Added support for generating `ExampleJsonKeys`, exposing a secured way to access the json keys from the properties. + ([#1164](https://github.com/google/json_serializable.dart/pull/1164)) ## 6.7.1 diff --git a/json_serializable/README.md b/json_serializable/README.md index cb1eec619..5d30efd16 100644 --- a/json_serializable/README.md +++ b/json_serializable/README.md @@ -276,6 +276,7 @@ targets: constructor: "" create_factory: true create_field_map: false + create_json_keys: false create_per_field_to_json: false create_to_json: true disallow_unrecognized_keys: false @@ -297,15 +298,15 @@ targets: [`Enum`]: https://api.dart.dev/stable/dart-core/Enum-class.html [`int`]: https://api.dart.dev/stable/dart-core/int-class.html [`Iterable`]: https://api.dart.dev/stable/dart-core/Iterable-class.html -[`JsonConverter`]: https://pub.dev/documentation/json_annotation/4.8.1/json_annotation/JsonConverter-class.html -[`JsonEnum.valueField`]: https://pub.dev/documentation/json_annotation/4.8.1/json_annotation/JsonEnum/valueField.html -[`JsonEnum`]: https://pub.dev/documentation/json_annotation/4.8.1/json_annotation/JsonEnum-class.html -[`JsonKey.fromJson`]: https://pub.dev/documentation/json_annotation/4.8.1/json_annotation/JsonKey/fromJson.html -[`JsonKey.toJson`]: https://pub.dev/documentation/json_annotation/4.8.1/json_annotation/JsonKey/toJson.html -[`JsonKey`]: https://pub.dev/documentation/json_annotation/4.8.1/json_annotation/JsonKey-class.html -[`JsonLiteral`]: https://pub.dev/documentation/json_annotation/4.8.1/json_annotation/JsonLiteral-class.html -[`JsonSerializable`]: https://pub.dev/documentation/json_annotation/4.8.1/json_annotation/JsonSerializable-class.html -[`JsonValue`]: https://pub.dev/documentation/json_annotation/4.8.1/json_annotation/JsonValue-class.html +[`JsonConverter`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonConverter-class.html +[`JsonEnum.valueField`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonEnum/valueField.html +[`JsonEnum`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonEnum-class.html +[`JsonKey.fromJson`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/fromJson.html +[`JsonKey.toJson`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/toJson.html +[`JsonKey`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey-class.html +[`JsonLiteral`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonLiteral-class.html +[`JsonSerializable`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable-class.html +[`JsonValue`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonValue-class.html [`List`]: https://api.dart.dev/stable/dart-core/List-class.html [`Map`]: https://api.dart.dev/stable/dart-core/Map-class.html [`num`]: https://api.dart.dev/stable/dart-core/num-class.html diff --git a/json_serializable/lib/src/encoder_helper.dart b/json_serializable/lib/src/encoder_helper.dart index cfc70b3af..05d4c714d 100644 --- a/json_serializable/lib/src/encoder_helper.dart +++ b/json_serializable/lib/src/encoder_helper.dart @@ -63,6 +63,28 @@ mixin EncodeHelper implements HelperCore { return buffer.toString(); } + /// Generates an object containing metadatas related to the encoding, + /// destined to be used by other code-generators. + String createJsonKeys(Set<FieldElement> accessibleFieldSet) { + assert(config.createJsonKeys); + + final buffer = StringBuffer( + 'abstract final class _\$${element.name.nonPrivate}JsonKeys {', + ); + // ..write('static const _\$${element.name.nonPrivate}JsonKeys();'); + + for (final field in accessibleFieldSet) { + buffer.writeln( + 'static const String ${field.name} = ' + '${escapeDartString(nameAccess(field))};', + ); + } + + buffer.write('}'); + + return buffer.toString(); + } + Iterable<String> createToJson(Set<FieldElement> accessibleFields) sync* { assert(config.createToJson); diff --git a/json_serializable/lib/src/generator_helper.dart b/json_serializable/lib/src/generator_helper.dart index 501df9469..8c0e13b4a 100644 --- a/json_serializable/lib/src/generator_helper.dart +++ b/json_serializable/lib/src/generator_helper.dart @@ -132,6 +132,10 @@ class GeneratorHelper extends HelperCore with EncodeHelper, DecodeHelper { yield createFieldMap(accessibleFieldSet); } + if (config.createJsonKeys) { + yield createJsonKeys(accessibleFieldSet); + } + if (config.createPerFieldToJson) { yield createPerFieldToJson(accessibleFieldSet); } diff --git a/json_serializable/lib/src/type_helpers/config_types.dart b/json_serializable/lib/src/type_helpers/config_types.dart index c4bdc260a..227f1890b 100644 --- a/json_serializable/lib/src/type_helpers/config_types.dart +++ b/json_serializable/lib/src/type_helpers/config_types.dart @@ -49,6 +49,7 @@ class ClassConfig { final bool createFactory; final bool createToJson; final bool createFieldMap; + final bool createJsonKeys; final bool createPerFieldToJson; final bool disallowUnrecognizedKeys; final bool explicitToJson; @@ -66,6 +67,7 @@ class ClassConfig { required this.createFactory, required this.createToJson, required this.createFieldMap, + required this.createJsonKeys, required this.createPerFieldToJson, required this.disallowUnrecognizedKeys, required this.explicitToJson, @@ -85,6 +87,8 @@ class ClassConfig { constructor: config.constructor ?? ClassConfig.defaults.constructor, createFieldMap: config.createFieldMap ?? ClassConfig.defaults.createFieldMap, + createJsonKeys: + config.createJsonKeys ?? ClassConfig.defaults.createJsonKeys, createPerFieldToJson: config.createPerFieldToJson ?? ClassConfig.defaults.createPerFieldToJson, createFactory: @@ -113,6 +117,7 @@ class ClassConfig { createFactory: true, createToJson: true, createFieldMap: false, + createJsonKeys: false, createPerFieldToJson: false, disallowUnrecognizedKeys: false, explicitToJson: false, @@ -129,6 +134,7 @@ class ClassConfig { createFactory: createFactory, createToJson: createToJson, createFieldMap: createFieldMap, + createJsonKeys: createJsonKeys, createPerFieldToJson: createPerFieldToJson, ignoreUnannotated: ignoreUnannotated, explicitToJson: explicitToJson, diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index c8c727f7d..c74cda361 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -58,6 +58,7 @@ JsonSerializable _valueForAnnotation(ConstantReader reader) => JsonSerializable( createFactory: reader.read('createFactory').literalValue as bool?, createToJson: reader.read('createToJson').literalValue as bool?, createFieldMap: reader.read('createFieldMap').literalValue as bool?, + createJsonKeys: reader.read('createJsonKeys').literalValue as bool?, createPerFieldToJson: reader.read('createPerFieldToJson').literalValue as bool?, disallowUnrecognizedKeys: @@ -106,6 +107,7 @@ ClassConfig mergeConfig( createFactory: annotation.createFactory ?? config.createFactory, createToJson: annotation.createToJson ?? config.createToJson, createFieldMap: annotation.createFieldMap ?? config.createFieldMap, + createJsonKeys: annotation.createJsonKeys ?? config.createJsonKeys, createPerFieldToJson: annotation.createPerFieldToJson ?? config.createPerFieldToJson, disallowUnrecognizedKeys: diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 8f55a01f0..307e1f76c 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 6.7.2-wip +version: 6.8.0-wip description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. @@ -29,6 +29,10 @@ dependencies: source_gen: ^1.3.2 source_helper: ^1.3.0 +dependency_overrides: + json_annotation: + path: ../json_annotation + dev_dependencies: _json_serial_shared_test: path: ../shared_test diff --git a/json_serializable/test/config_test.dart b/json_serializable/test/config_test.dart index 15767a319..2bcaa242a 100644 --- a/json_serializable/test/config_test.dart +++ b/json_serializable/test/config_test.dart @@ -153,6 +153,7 @@ const _invalidConfig = { 'constructor': 42, 'create_factory': 42, 'create_field_map': 42, + 'create_json_keys': 42, 'create_per_field_to_json': 42, 'create_to_json': 42, 'disallow_unrecognized_keys': 42, diff --git a/json_serializable/test/integration/integration_test.dart b/json_serializable/test/integration/integration_test.dart index 9305b4f9b..8c5827ee8 100644 --- a/json_serializable/test/integration/integration_test.dart +++ b/json_serializable/test/integration/integration_test.dart @@ -10,6 +10,7 @@ import 'converter_examples.dart'; import 'create_per_field_to_json_example.dart'; import 'field_map_example.dart'; import 'json_enum_example.dart'; +import 'json_keys_example.dart' as js_keys; import 'json_test_common.dart' show Category, Platform, StatusCode; import 'json_test_example.dart'; @@ -471,4 +472,8 @@ void main() { test('value field index fun', () { expect(enumValueFieldIndexValues, [0, 701, 2]); }); + + test('ModelJsonKeys', () { + expect(js_keys.keys, {'first-name', 'LAST_NAME'}); + }); } diff --git a/json_serializable/test/integration/json_keys_example.dart b/json_serializable/test/integration/json_keys_example.dart new file mode 100644 index 000000000..e8a6895a2 --- /dev/null +++ b/json_serializable/test/integration/json_keys_example.dart @@ -0,0 +1,32 @@ +import 'package:json_annotation/json_annotation.dart'; + +part 'json_keys_example.g.dart'; + +@JsonSerializable(createJsonKeys: true, fieldRename: FieldRename.kebab) +class Model { + Model({ + required this.firstName, + required this.lastName, + this.ignoredName, + }); + + factory Model.fromJson(Map<String, Object?> json) => _$ModelFromJson(json); + + final String firstName; + + @JsonKey(name: 'LAST_NAME') + final String lastName; + + @JsonKey(includeFromJson: false, includeToJson: false) + final String? ignoredName; + + String get fullName => '$firstName $lastName'; + + Map<String, Object?> toJson() => _$ModelToJson(this); +} + +// TODO: use this once https://github.com/dart-lang/sdk/issues/54543 is fixed +typedef ModelJsonKeys = _$ModelJsonKeys; + +// Work-around until https://github.com/dart-lang/sdk/issues/54543 is fixed +Set<String> get keys => {_$ModelJsonKeys.firstName, _$ModelJsonKeys.lastName}; diff --git a/json_serializable/test/integration/json_keys_example.g.dart b/json_serializable/test/integration/json_keys_example.g.dart new file mode 100644 index 000000000..f68ca8d09 --- /dev/null +++ b/json_serializable/test/integration/json_keys_example.g.dart @@ -0,0 +1,24 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal, inference_failure_on_function_invocation, inference_failure_on_collection_literal + +part of 'json_keys_example.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +Model _$ModelFromJson(Map<String, dynamic> json) => Model( + firstName: json['first-name'] as String, + lastName: json['LAST_NAME'] as String, + ); + +abstract final class _$ModelJsonKeys { + static const String firstName = 'first-name'; + static const String lastName = 'LAST_NAME'; +} + +Map<String, dynamic> _$ModelToJson(Model instance) => <String, dynamic>{ + 'first-name': instance.firstName, + 'LAST_NAME': instance.lastName, + }; diff --git a/json_serializable/test/shared_config.dart b/json_serializable/test/shared_config.dart index 957728da3..fcae4282e 100644 --- a/json_serializable/test/shared_config.dart +++ b/json_serializable/test/shared_config.dart @@ -20,6 +20,7 @@ final generatorConfigNonDefaultJson = createFactory: false, createToJson: false, createFieldMap: true, + createJsonKeys: true, createPerFieldToJson: true, disallowUnrecognizedKeys: true, explicitToJson: true, diff --git a/json_serializable/test/test_sources/test_sources.dart b/json_serializable/test/test_sources/test_sources.dart index 06cc495f3..786931080 100644 --- a/json_serializable/test/test_sources/test_sources.dart +++ b/json_serializable/test/test_sources/test_sources.dart @@ -16,6 +16,7 @@ class ConfigurationImplicitDefaults { createFactory: true, createToJson: true, createFieldMap: false, + createJsonKeys: false, createPerFieldToJson: false, disallowUnrecognizedKeys: false, explicitToJson: false, diff --git a/json_serializable/tool/readme/readme_template.md b/json_serializable/tool/readme/readme_template.md index 79ac1c7dd..c3d6815ab 100644 --- a/json_serializable/tool/readme/readme_template.md +++ b/json_serializable/tool/readme/readme_template.md @@ -141,6 +141,7 @@ targets: constructor: "" create_factory: true create_field_map: false + create_json_keys: false create_per_field_to_json: false create_to_json: true disallow_unrecognized_keys: false From 1bfb616fe6878bae858792d9e03e6ee1085982ff Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 4 Apr 2024 18:13:12 -0700 Subject: [PATCH 519/569] Bump actions/cache from 4.0.1 to 4.0.2 (#1411) Bumps [actions/cache](https://github.com/actions/cache) from 4.0.1 to 4.0.2. - [Release notes](https://github.com/actions/cache/releases) - [Changelog](https://github.com/actions/cache/blob/main/RELEASES.md) - [Commits](https://github.com/actions/cache/compare/ab5e6d0c87105b4c9c2047343972218f562e4319...0c45773b623bea8c8e75f6c82b208c3cf94ea4f9) --- updated-dependencies: - dependency-name: actions/cache dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/dart.yml | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 09c4122c2..4f8a75cf9 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -21,7 +21,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319 + uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:stable" @@ -44,7 +44,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319 + uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:analyze_1" @@ -110,7 +110,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319 + uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:format-analyze_0" @@ -196,7 +196,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319 + uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" @@ -257,7 +257,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319 + uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:json_serializable;commands:test_3" @@ -291,7 +291,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319 + uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:json_serializable;commands:test_1" @@ -325,7 +325,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319 + uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:json_serializable;commands:test_2" @@ -359,7 +359,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319 + uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" @@ -420,7 +420,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319 + uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:json_serializable;commands:test_3" @@ -454,7 +454,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319 + uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:json_serializable;commands:test_1" @@ -488,7 +488,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319 + uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:json_serializable;commands:test_2" @@ -522,7 +522,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319 + uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:_test_yaml-checked_yaml-example;commands:test_1" @@ -582,7 +582,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319 + uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:_test_yaml-checked_yaml-example;commands:test_1" From 1694d6f1e3b8e01ca621c9ffb35666389ecbab46 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 4 Apr 2024 18:13:33 -0700 Subject: [PATCH 520/569] Bump actions/checkout from 4.1.1 to 4.1.2 (#1410) Bumps [actions/checkout](https://github.com/actions/checkout) from 4.1.1 to 4.1.2. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/b4ffde65f46336ab88eb53be808477a3936bae11...9bb56186c3b09b4f86b1c65136769dd318469633) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/dart.yml | 26 +++++++++++++------------- .github/workflows/markdown_linter.yml | 4 ++-- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 4f8a75cf9..0be82d568 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -34,7 +34,7 @@ jobs: sdk: stable - id: checkout name: Checkout repository - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 + uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 - name: mono_repo self validate run: dart pub global activate mono_repo 6.5.7 - name: mono_repo self validate @@ -59,7 +59,7 @@ jobs: sdk: "3.0.0" - id: checkout name: Checkout repository - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 + uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -125,7 +125,7 @@ jobs: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 + uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -211,7 +211,7 @@ jobs: sdk: "3.0.0" - id: checkout name: Checkout repository - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 + uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -272,7 +272,7 @@ jobs: sdk: "3.0.0" - id: checkout name: Checkout repository - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 + uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -306,7 +306,7 @@ jobs: sdk: "3.0.0" - id: checkout name: Checkout repository - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 + uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -340,7 +340,7 @@ jobs: sdk: "3.0.0" - id: checkout name: Checkout repository - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 + uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -374,7 +374,7 @@ jobs: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 + uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -435,7 +435,7 @@ jobs: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 + uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -469,7 +469,7 @@ jobs: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 + uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -503,7 +503,7 @@ jobs: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 + uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -537,7 +537,7 @@ jobs: sdk: "3.0.0" - id: checkout name: Checkout repository - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 + uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -597,7 +597,7 @@ jobs: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 + uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade diff --git a/.github/workflows/markdown_linter.yml b/.github/workflows/markdown_linter.yml index f7bab67dc..6cf4457c5 100644 --- a/.github/workflows/markdown_linter.yml +++ b/.github/workflows/markdown_linter.yml @@ -11,10 +11,10 @@ jobs: markdown-link-check: runs-on: ubuntu-latest steps: - - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 + - uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 - uses: gaurav-nelson/github-action-markdown-link-check@5c5dfc0ac2e225883c0e5f03a85311ec2830d368 markdown_lint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 + - uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 - uses: DavidAnson/markdownlint-cli2-action@510b996878fc0d1a46c8a04ec86b06dbfba09de7 From dbe976a864c599774e64aaa478aef0f0d44cb8e0 Mon Sep 17 00:00:00 2001 From: Jackson Gardner <eyebrowsoffire@gmail.com> Date: Wed, 24 Apr 2024 11:38:18 -0700 Subject: [PATCH 521/569] Make casts to int safe in dart2wasm. (#1416) Co-authored-by: Kevin Moore <kevmoo@google.com> --- _test_yaml/pubspec.yaml | 2 +- _test_yaml/test/src/build_config.g.dart | 4 +- example/lib/example.g.dart | 13 +- .../lib/generic_response_class_example.g.dart | 8 +- example/lib/json_converter_example.g.dart | 10 +- example/lib/tuple_example.g.dart | 8 +- .../lib/src/json_serializable.dart | 2 +- json_serializable/CHANGELOG.md | 5 +- json_serializable/lib/src/lambda_result.dart | 35 ++-- .../lib/src/type_helpers/duration_helper.dart | 2 +- .../lib/src/type_helpers/value_helper.dart | 22 +-- json_serializable/lib/src/utils.dart | 28 +++ .../test/default_value/default_value.g.dart | 10 +- .../default_value.g_any_map__checked.g.dart | 15 +- .../implicit_default_value.g.dart | 10 +- .../field_matrix_test.field_matrix.g.dart | 90 ++++----- .../generic_argument_factories.g.dart | 2 +- ...generic_argument_factories_nullable.g.dart | 2 +- .../test/generic_files/generic_class.dart | 3 + .../test/generic_files/generic_class.g.dart | 6 +- .../test/generic_files/generic_test.dart | 6 +- .../integration/converter_examples.g.dart | 2 +- .../create_per_field_to_json_example.g.dart | 2 +- .../test/integration/integration_test.dart | 15 +- .../test/integration/json_test_common.dart | 5 + .../test/integration/json_test_example.dart | 3 + .../test/integration/json_test_example.g.dart | 35 ++-- .../json_test_example.g_any_map.dart | 3 + .../json_test_example.g_any_map.g.dart | 35 ++-- .../test/kitchen_sink/kitchen_sink.g.dart | 39 ++-- .../kitchen_sink.g_any_map.g.dart | 39 ++-- .../kitchen_sink.g_any_map__checked.g.dart | 51 ++--- .../kitchen_sink.g_exclude_null.g.dart | 39 ++-- .../kitchen_sink.g_explicit_to_json.g.dart | 39 ++-- .../test/kitchen_sink/simple_object.g.dart | 2 +- .../kitchen_sink/strict_keys_object.g.dart | 2 +- .../src/_json_serializable_test_input.dart | 21 ++- .../test/src/default_value_input.dart | 6 +- .../test/src/inheritance_test_input.dart | 8 +- .../test/src/json_converter_test_input.dart | 22 +-- .../test/src/map_key_variety_test_input.dart | 2 +- .../test/src/to_from_json_test_input.dart | 2 +- .../test/supported_types/enum_type.dart | 6 +- .../input.type_duration.g.dart | 4 +- .../supported_types/input.type_int.g.dart | 8 +- .../input.type_iterable.g.dart | 24 +-- .../supported_types/input.type_list.g.dart | 28 ++- .../supported_types/input.type_map.g.dart | 178 +++++++++--------- .../supported_types/input.type_record.g.dart | 41 ++-- .../supported_types/input.type_set.g.dart | 24 ++- .../tool/readme/readme_examples.g.dart | 6 +- 51 files changed, 551 insertions(+), 423 deletions(-) diff --git a/_test_yaml/pubspec.yaml b/_test_yaml/pubspec.yaml index f682e6e88..57f7a275b 100644 --- a/_test_yaml/pubspec.yaml +++ b/_test_yaml/pubspec.yaml @@ -11,7 +11,7 @@ dev_dependencies: build_verify: ^3.0.0 checked_yaml: any dart_flutter_team_lints: ^2.0.0 - json_annotation: ^4.7.0 + json_annotation: ^4.8.1 json_serializable: any path: ^1.8.2 test: ^1.6.0 diff --git a/_test_yaml/test/src/build_config.g.dart b/_test_yaml/test/src/build_config.g.dart index 332000dd1..61e578ec4 100644 --- a/_test_yaml/test/src/build_config.g.dart +++ b/_test_yaml/test/src/build_config.g.dart @@ -24,8 +24,8 @@ Config _$ConfigFromJson(Map json) => $checkedCreate( $checkedConvert( 'weights', (v) => val.weights = (v as Map?)?.map( - (k, e) => - MapEntry($enumDecode(_$AutoApplyEnumMap, k), e as int?), + (k, e) => MapEntry( + $enumDecode(_$AutoApplyEnumMap, k), (e as num?)?.toInt()), )); return val; }, diff --git a/example/lib/example.g.dart b/example/lib/example.g.dart index 40e7e4e9c..b4cf7de11 100644 --- a/example/lib/example.g.dart +++ b/example/lib/example.g.dart @@ -39,15 +39,16 @@ Map<String, dynamic> _$PersonToJson(Person instance) { } Order _$OrderFromJson(Map<String, dynamic> json) => Order( - Order._dateTimeFromEpochUs(json['date'] as int), + Order._dateTimeFromEpochUs((json['date'] as num).toInt()), ) - ..count = json['count'] as int? - ..itemNumber = json['itemNumber'] as int? + ..count = (json['count'] as num?)?.toInt() + ..itemNumber = (json['itemNumber'] as num?)?.toInt() ..isRushed = json['isRushed'] as bool? ..item = json['item'] == null ? null : Item.fromJson(json['item'] as Map<String, dynamic>) - ..prepTime = Order._durationFromMilliseconds(json['prep-time'] as int?); + ..prepTime = + Order._durationFromMilliseconds((json['prep-time'] as num?)?.toInt()); Map<String, dynamic> _$OrderToJson(Order instance) { final val = <String, dynamic>{}; @@ -68,8 +69,8 @@ Map<String, dynamic> _$OrderToJson(Order instance) { } Item _$ItemFromJson(Map<String, dynamic> json) => Item() - ..count = json['count'] as int? - ..itemNumber = json['itemNumber'] as int? + ..count = (json['count'] as num?)?.toInt() + ..itemNumber = (json['itemNumber'] as num?)?.toInt() ..isRushed = json['isRushed'] as bool?; Map<String, dynamic> _$ItemToJson(Item instance) => <String, dynamic>{ diff --git a/example/lib/generic_response_class_example.g.dart b/example/lib/generic_response_class_example.g.dart index 6b2e9325a..e61f09efc 100644 --- a/example/lib/generic_response_class_example.g.dart +++ b/example/lib/generic_response_class_example.g.dart @@ -8,13 +8,13 @@ part of 'generic_response_class_example.dart'; BaseResponse<T> _$BaseResponseFromJson<T>(Map<String, dynamic> json) => BaseResponse<T>( - status: json['status'] as int?, + status: (json['status'] as num?)?.toInt(), msg: json['msg'] as String?, data: BaseResponse._dataFromJson(json['data'] as Object), ); Article _$ArticleFromJson(Map<String, dynamic> json) => Article( - id: json['id'] as int, + id: (json['id'] as num).toInt(), title: json['title'] as String, author: json['author'] == null ? null @@ -25,11 +25,11 @@ Article _$ArticleFromJson(Map<String, dynamic> json) => Article( ); User _$UserFromJson(Map<String, dynamic> json) => User( - id: json['id'] as int?, + id: (json['id'] as num?)?.toInt(), email: json['email'] as String?, ); Comment _$CommentFromJson(Map<String, dynamic> json) => Comment( - id: json['id'] as int?, + id: (json['id'] as num?)?.toInt(), content: json['content'] as String?, ); diff --git a/example/lib/json_converter_example.g.dart b/example/lib/json_converter_example.g.dart index 526177be7..01b2e46f5 100644 --- a/example/lib/json_converter_example.g.dart +++ b/example/lib/json_converter_example.g.dart @@ -8,7 +8,7 @@ part of 'json_converter_example.dart'; DateTimeExample _$DateTimeExampleFromJson(Map<String, dynamic> json) => DateTimeExample( - const _DateTimeEpochConverter().fromJson(json['when'] as int), + const _DateTimeEpochConverter().fromJson((json['when'] as num).toInt()), ); Map<String, dynamic> _$DateTimeExampleToJson(DateTimeExample instance) => @@ -19,9 +19,9 @@ Map<String, dynamic> _$DateTimeExampleToJson(DateTimeExample instance) => GenericCollection<T> _$GenericCollectionFromJson<T>( Map<String, dynamic> json) => GenericCollection<T>( - page: json['page'] as int?, - totalResults: json['total_results'] as int?, - totalPages: json['total_pages'] as int?, + page: (json['page'] as num?)?.toInt(), + totalResults: (json['total_results'] as num?)?.toInt(), + totalPages: (json['total_pages'] as num?)?.toInt(), results: (json['results'] as List<dynamic>?) ?.map(_Converter<T>().fromJson) .toList(), @@ -38,7 +38,7 @@ Map<String, dynamic> _$GenericCollectionToJson<T>( CustomResult _$CustomResultFromJson(Map<String, dynamic> json) => CustomResult( json['name'] as String, - json['size'] as int, + (json['size'] as num).toInt(), ); Map<String, dynamic> _$CustomResultToJson(CustomResult instance) => diff --git a/example/lib/tuple_example.g.dart b/example/lib/tuple_example.g.dart index e90d91a1d..f4a537901 100644 --- a/example/lib/tuple_example.g.dart +++ b/example/lib/tuple_example.g.dart @@ -28,11 +28,13 @@ Map<String, dynamic> _$TupleToJson<T, S>( ConcreteClass _$ConcreteClassFromJson(Map<String, dynamic> json) => ConcreteClass( - Tuple<int, DateTime>.fromJson(json['tuple1'] as Map<String, dynamic>, - (value) => value as int, (value) => DateTime.parse(value as String)), + Tuple<int, DateTime>.fromJson( + json['tuple1'] as Map<String, dynamic>, + (value) => (value as num).toInt(), + (value) => DateTime.parse(value as String)), Tuple<Duration, BigInt>.fromJson( json['tuple2'] as Map<String, dynamic>, - (value) => Duration(microseconds: value as int), + (value) => Duration(microseconds: (value as num).toInt()), (value) => BigInt.parse(value as String)), ); diff --git a/json_annotation/lib/src/json_serializable.dart b/json_annotation/lib/src/json_serializable.dart index fe9b5cc98..91600f097 100644 --- a/json_annotation/lib/src/json_serializable.dart +++ b/json_annotation/lib/src/json_serializable.dart @@ -181,7 +181,7 @@ class JsonSerializable { /// T Function(Object json) fromJsonT, /// ) { /// return Response<T>() - /// ..status = json['status'] as int + /// ..status = (json['status'] as num).toInt() /// ..value = fromJsonT(json['value']); /// } /// diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 845d563b2..9ae8f098d 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,8 +1,11 @@ ## 6.8.0-wip - Add type arguments to `Map` literals used for `Record` serialization. -- Added support for generating `ExampleJsonKeys`, exposing a secured way to access the json keys from the properties. +- Added support for generating `ExampleJsonKeys`, exposing a secured way to + access the json keys from the properties. ([#1164](https://github.com/google/json_serializable.dart/pull/1164)) +- Handle decoding an `int` value from a `double` literal. + This now matches the behavior of `double` values being encoded as `int`. ## 6.7.1 diff --git a/json_serializable/lib/src/lambda_result.dart b/json_serializable/lib/src/lambda_result.dart index 0531cc20f..c5aa510ff 100644 --- a/json_serializable/lib/src/lambda_result.dart +++ b/json_serializable/lib/src/lambda_result.dart @@ -20,9 +20,8 @@ class LambdaResult { final String lambda; final DartType? asContent; - String get _asContent => asContent == null ? '' : _asStatement(asContent!); - - String get _fullExpression => '$expression$_asContent'; + String get _fullExpression => + asContent != null ? _cast(expression, asContent!) : expression; LambdaResult(this.expression, this.lambda, {this.asContent}); @@ -35,29 +34,35 @@ class LambdaResult { : '($closureArg) => $subField'; } -String _asStatement(DartType type) { - if (type.isLikeDynamic) { - return ''; +String _cast(String expression, DartType targetType) { + if (targetType.isLikeDynamic) { + return expression; } - final nullableSuffix = type.isNullableType ? '?' : ''; + final nullableSuffix = targetType.isNullableType ? '?' : ''; - if (coreIterableTypeChecker.isAssignableFromType(type)) { - final itemType = coreIterableGenericType(type); + if (coreIterableTypeChecker.isAssignableFromType(targetType)) { + final itemType = coreIterableGenericType(targetType); if (itemType.isLikeDynamic) { - return ' as List$nullableSuffix'; + return '$expression as List$nullableSuffix'; } } - if (coreMapTypeChecker.isAssignableFromType(type)) { - final args = type.typeArgumentsOf(coreMapTypeChecker)!; + if (coreMapTypeChecker.isAssignableFromType(targetType)) { + final args = targetType.typeArgumentsOf(coreMapTypeChecker)!; assert(args.length == 2); if (args.every((e) => e.isLikeDynamic)) { - return ' as Map$nullableSuffix'; + return '$expression as Map$nullableSuffix'; } } - final typeCode = typeToCode(type); - return ' as $typeCode'; + final defaultDecodeValue = defaultDecodeLogic(targetType, expression); + + if (defaultDecodeValue != null) { + return defaultDecodeValue; + } + + final typeCode = typeToCode(targetType); + return '$expression as $typeCode'; } diff --git a/json_serializable/lib/src/type_helpers/duration_helper.dart b/json_serializable/lib/src/type_helpers/duration_helper.dart index d45cb4222..6cf4d6bdd 100644 --- a/json_serializable/lib/src/type_helpers/duration_helper.dart +++ b/json_serializable/lib/src/type_helpers/duration_helper.dart @@ -46,7 +46,7 @@ class DurationHelper extends TypeHelper { return DefaultContainer( expression, - 'Duration(microseconds: $expression as int)', + 'Duration(microseconds: ($expression as num).toInt())', ); } } diff --git a/json_serializable/lib/src/type_helpers/value_helper.dart b/json_serializable/lib/src/type_helpers/value_helper.dart index 49f7372f4..d9f8411db 100644 --- a/json_serializable/lib/src/type_helpers/value_helper.dart +++ b/json_serializable/lib/src/type_helpers/value_helper.dart @@ -3,7 +3,6 @@ // BSD-style license that can be found in the LICENSE file. import 'package:analyzer/dart/element/type.dart'; -import 'package:source_helper/source_helper.dart'; import '../shared_checkers.dart'; import '../type_helper.dart'; @@ -35,22 +34,7 @@ class ValueHelper extends TypeHelper { String expression, TypeHelperContext context, bool defaultProvided, - ) { - if (targetType.isDartCoreObject && !targetType.isNullableType) { - final question = defaultProvided ? '?' : ''; - return '$expression as Object$question'; - } else if (targetType.isDartCoreObject || targetType is DynamicType) { - // just return it as-is. We'll hope it's safe. - return expression; - } else if (targetType.isDartCoreDouble) { - final targetTypeNullable = defaultProvided || targetType.isNullableType; - final question = targetTypeNullable ? '?' : ''; - return '($expression as num$question)$question.toDouble()'; - } else if (simpleJsonTypeChecker.isAssignableFromType(targetType)) { - final typeCode = typeToCode(targetType, forceNullable: defaultProvided); - return '$expression as $typeCode'; - } - - return null; - } + ) => + defaultDecodeLogic(targetType, expression, + defaultProvided: defaultProvided); } diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index c74cda361..0bf6dba64 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -9,6 +9,7 @@ import 'package:json_annotation/json_annotation.dart'; import 'package:source_gen/source_gen.dart'; import 'package:source_helper/source_helper.dart'; +import 'shared_checkers.dart'; import 'type_helpers/config_types.dart'; const _jsonKeyChecker = TypeChecker.fromRuntime(JsonKey); @@ -220,6 +221,33 @@ String typeToCode( throw UnimplementedError('(${type.runtimeType}) $type'); } +String? defaultDecodeLogic( + DartType targetType, + String expression, { + bool defaultProvided = false, +}) { + if (targetType.isDartCoreObject && !targetType.isNullableType) { + final question = defaultProvided ? '?' : ''; + return '$expression as Object$question'; + } else if (targetType.isDartCoreObject || targetType is DynamicType) { + // just return it as-is. We'll hope it's safe. + return expression; + } else if (targetType.isDartCoreDouble) { + final targetTypeNullable = defaultProvided || targetType.isNullableType; + final question = targetTypeNullable ? '?' : ''; + return '($expression as num$question)$question.toDouble()'; + } else if (targetType.isDartCoreInt) { + final targetTypeNullable = defaultProvided || targetType.isNullableType; + final question = targetTypeNullable ? '?' : ''; + return '($expression as num$question)$question.toInt()'; + } else if (simpleJsonTypeChecker.isAssignableFromType(targetType)) { + final typeCode = typeToCode(targetType, forceNullable: defaultProvided); + return '$expression as $typeCode'; + } + + return null; +} + extension ExecutableElementExtension on ExecutableElement { /// Returns the name of `this` qualified with the class name if it's a /// [MethodElement]. diff --git a/json_serializable/test/default_value/default_value.g.dart b/json_serializable/test/default_value/default_value.g.dart index 0614284e6..6bc4525d5 100644 --- a/json_serializable/test/default_value/default_value.g.dart +++ b/json_serializable/test/default_value/default_value.g.dart @@ -11,13 +11,13 @@ part of 'default_value.dart'; DefaultValue _$DefaultValueFromJson(Map<String, dynamic> json) => DefaultValue( json['fieldBool'] as bool? ?? true, json['fieldString'] as String? ?? 'string', - json['fieldInt'] as int? ?? 42, + (json['fieldInt'] as num?)?.toInt() ?? 42, (json['fieldDouble'] as num?)?.toDouble() ?? 3.14, json['fieldListEmpty'] as List<dynamic>? ?? [], (json['fieldSetEmpty'] as List<dynamic>?)?.toSet() ?? {}, json['fieldMapEmpty'] as Map<String, dynamic>? ?? {}, (json['fieldListSimple'] as List<dynamic>?) - ?.map((e) => e as int) + ?.map((e) => (e as num).toInt()) .toList() ?? [1, 2, 3], (json['fieldSetSimple'] as List<dynamic>?) @@ -25,7 +25,7 @@ DefaultValue _$DefaultValueFromJson(Map<String, dynamic> json) => DefaultValue( .toSet() ?? {'entry1', 'entry2'}, (json['fieldMapSimple'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, e as int), + (k, e) => MapEntry(k, (e as num).toInt()), ) ?? {'answer': 42}, (json['fieldMapListString'] as Map<String, dynamic>?)?.map( @@ -38,7 +38,7 @@ DefaultValue _$DefaultValueFromJson(Map<String, dynamic> json) => DefaultValue( $enumDecodeNullable(_$GreekEnumMap, json['fieldEnum']) ?? Greek.beta, durationField: json['durationField'] == null ? Duration.zero - : Duration(microseconds: json['durationField'] as int), + : Duration(microseconds: (json['durationField'] as num).toInt()), constClass: json['constClass'] == null ? const ConstClass('value') : ConstClass.fromJson(json['constClass'] as Map<String, dynamic>), @@ -50,7 +50,7 @@ DefaultValue _$DefaultValueFromJson(Map<String, dynamic> json) => DefaultValue( ? const ConstClass('value') : constClassFromJson(json['valueFromFunction'] as String), intDefaultValueFromFunction: - json['intDefaultValueFromFunction'] as int? ?? + (json['intDefaultValueFromFunction'] as num?)?.toInt() ?? intDefaultValueFunction(), valueFromDefaultValueDefaultConstructor: json['valueFromDefaultValueDefaultConstructor'] == null diff --git a/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart b/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart index 24be86d8a..9ce12321f 100644 --- a/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart +++ b/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart @@ -15,7 +15,7 @@ DefaultValue _$DefaultValueFromJson(Map json) => $checkedCreate( final val = DefaultValue( $checkedConvert('fieldBool', (v) => v as bool? ?? true), $checkedConvert('fieldString', (v) => v as String? ?? 'string'), - $checkedConvert('fieldInt', (v) => v as int? ?? 42), + $checkedConvert('fieldInt', (v) => (v as num?)?.toInt() ?? 42), $checkedConvert( 'fieldDouble', (v) => (v as num?)?.toDouble() ?? 3.14), $checkedConvert('fieldListEmpty', (v) => v as List<dynamic>? ?? []), @@ -25,7 +25,9 @@ DefaultValue _$DefaultValueFromJson(Map json) => $checkedCreate( $checkedConvert( 'fieldListSimple', (v) => - (v as List<dynamic>?)?.map((e) => e as int).toList() ?? + (v as List<dynamic>?) + ?.map((e) => (e as num).toInt()) + .toList() ?? [1, 2, 3]), $checkedConvert( 'fieldSetSimple', @@ -36,7 +38,7 @@ DefaultValue _$DefaultValueFromJson(Map json) => $checkedCreate( 'fieldMapSimple', (v) => (v as Map?)?.map( - (k, e) => MapEntry(k as String, e as int), + (k, e) => MapEntry(k as String, (e as num).toInt()), ) ?? {'answer': 42}), $checkedConvert( @@ -53,8 +55,9 @@ DefaultValue _$DefaultValueFromJson(Map json) => $checkedCreate( (v) => $enumDecodeNullable(_$GreekEnumMap, v) ?? Greek.beta), durationField: $checkedConvert( 'durationField', - (v) => - v == null ? Duration.zero : Duration(microseconds: v as int)), + (v) => v == null + ? Duration.zero + : Duration(microseconds: (v as num).toInt())), constClass: $checkedConvert( 'constClass', (v) => v == null @@ -72,7 +75,7 @@ DefaultValue _$DefaultValueFromJson(Map json) => $checkedCreate( : constClassFromJson(v as String)), intDefaultValueFromFunction: $checkedConvert( 'intDefaultValueFromFunction', - (v) => v as int? ?? intDefaultValueFunction()), + (v) => (v as num?)?.toInt() ?? intDefaultValueFunction()), valueFromDefaultValueDefaultConstructor: $checkedConvert( 'valueFromDefaultValueDefaultConstructor', (v) => v == null diff --git a/json_serializable/test/default_value/implicit_default_value.g.dart b/json_serializable/test/default_value/implicit_default_value.g.dart index 9bd1f19e0..408c1f0b2 100644 --- a/json_serializable/test/default_value/implicit_default_value.g.dart +++ b/json_serializable/test/default_value/implicit_default_value.g.dart @@ -13,14 +13,14 @@ DefaultValueImplicit _$DefaultValueImplicitFromJson( DefaultValueImplicit( fieldBool: json['fieldBool'] as bool? ?? true, fieldString: json['fieldString'] as String? ?? 'string', - fieldInt: json['fieldInt'] as int? ?? 42, + fieldInt: (json['fieldInt'] as num?)?.toInt() ?? 42, fieldDouble: (json['fieldDouble'] as num?)?.toDouble() ?? 3.14, fieldListEmpty: json['fieldListEmpty'] as List<dynamic>? ?? const [], fieldSetEmpty: (json['fieldSetEmpty'] as List<dynamic>?)?.toSet() ?? const {}, fieldMapEmpty: json['fieldMapEmpty'] as Map<String, dynamic>? ?? const {}, fieldListSimple: (json['fieldListSimple'] as List<dynamic>?) - ?.map((e) => e as int) + ?.map((e) => (e as num).toInt()) .toList() ?? const [1, 2, 3], fieldSetSimple: (json['fieldSetSimple'] as List<dynamic>?) @@ -28,7 +28,7 @@ DefaultValueImplicit _$DefaultValueImplicitFromJson( .toSet() ?? const {'entry1', 'entry2'}, fieldMapSimple: (json['fieldMapSimple'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, e as int), + (k, e) => MapEntry(k, (e as num).toInt()), ) ?? const {'answer': 42}, fieldMapListString: @@ -43,7 +43,7 @@ DefaultValueImplicit _$DefaultValueImplicitFromJson( $enumDecodeNullable(_$GreekEnumMap, json['fieldEnum']) ?? Greek.beta, durationField: json['durationField'] == null ? const Duration() - : Duration(microseconds: json['durationField'] as int), + : Duration(microseconds: (json['durationField'] as num).toInt()), constClass: json['constClass'] == null ? const ConstClass('value') : ConstClass.fromJson(json['constClass'] as Map<String, dynamic>), @@ -55,7 +55,7 @@ DefaultValueImplicit _$DefaultValueImplicitFromJson( ? const ConstClass('value') : constClassFromJson(json['valueFromFunction'] as String), intDefaultValueFromFunction: - json['intDefaultValueFromFunction'] as int? ?? 43, + (json['intDefaultValueFromFunction'] as num?)?.toInt() ?? 43, valueFromDefaultValueDefaultConstructor: json['valueFromDefaultValueDefaultConstructor'] == null ? const ConstClass() diff --git a/json_serializable/test/field_matrix_test.field_matrix.g.dart b/json_serializable/test/field_matrix_test.field_matrix.g.dart index 84891ef9a..aa18728ba 100644 --- a/json_serializable/test/field_matrix_test.field_matrix.g.dart +++ b/json_serializable/test/field_matrix_test.field_matrix.g.dart @@ -11,9 +11,9 @@ part of 'field_matrix_test.field_matrix.dart'; ToJsonNullFromJsonNullPublic _$ToJsonNullFromJsonNullPublicFromJson( Map<String, dynamic> json) => ToJsonNullFromJsonNullPublic() - ..aField = json['aField'] as int? - ..field = json['field'] as int? - ..zField = json['zField'] as int?; + ..aField = (json['aField'] as num?)?.toInt() + ..field = (json['field'] as num?)?.toInt() + ..zField = (json['zField'] as num?)?.toInt(); Map<String, dynamic> _$ToJsonNullFromJsonNullPublicToJson( ToJsonNullFromJsonNullPublic instance) => @@ -26,9 +26,9 @@ Map<String, dynamic> _$ToJsonNullFromJsonNullPublicToJson( ToJsonNullFromJsonTruePublic _$ToJsonNullFromJsonTruePublicFromJson( Map<String, dynamic> json) => ToJsonNullFromJsonTruePublic() - ..aField = json['aField'] as int? - ..field = json['field'] as int? - ..zField = json['zField'] as int?; + ..aField = (json['aField'] as num?)?.toInt() + ..field = (json['field'] as num?)?.toInt() + ..zField = (json['zField'] as num?)?.toInt(); Map<String, dynamic> _$ToJsonNullFromJsonTruePublicToJson( ToJsonNullFromJsonTruePublic instance) => @@ -41,8 +41,8 @@ Map<String, dynamic> _$ToJsonNullFromJsonTruePublicToJson( ToJsonNullFromJsonFalsePublic _$ToJsonNullFromJsonFalsePublicFromJson( Map<String, dynamic> json) => ToJsonNullFromJsonFalsePublic() - ..aField = json['aField'] as int? - ..zField = json['zField'] as int?; + ..aField = (json['aField'] as num?)?.toInt() + ..zField = (json['zField'] as num?)?.toInt(); Map<String, dynamic> _$ToJsonNullFromJsonFalsePublicToJson( ToJsonNullFromJsonFalsePublic instance) => @@ -54,9 +54,9 @@ Map<String, dynamic> _$ToJsonNullFromJsonFalsePublicToJson( ToJsonTrueFromJsonNullPublic _$ToJsonTrueFromJsonNullPublicFromJson( Map<String, dynamic> json) => ToJsonTrueFromJsonNullPublic() - ..aField = json['aField'] as int? - ..field = json['field'] as int? - ..zField = json['zField'] as int?; + ..aField = (json['aField'] as num?)?.toInt() + ..field = (json['field'] as num?)?.toInt() + ..zField = (json['zField'] as num?)?.toInt(); Map<String, dynamic> _$ToJsonTrueFromJsonNullPublicToJson( ToJsonTrueFromJsonNullPublic instance) => @@ -69,9 +69,9 @@ Map<String, dynamic> _$ToJsonTrueFromJsonNullPublicToJson( ToJsonTrueFromJsonTruePublic _$ToJsonTrueFromJsonTruePublicFromJson( Map<String, dynamic> json) => ToJsonTrueFromJsonTruePublic() - ..aField = json['aField'] as int? - ..field = json['field'] as int? - ..zField = json['zField'] as int?; + ..aField = (json['aField'] as num?)?.toInt() + ..field = (json['field'] as num?)?.toInt() + ..zField = (json['zField'] as num?)?.toInt(); Map<String, dynamic> _$ToJsonTrueFromJsonTruePublicToJson( ToJsonTrueFromJsonTruePublic instance) => @@ -84,8 +84,8 @@ Map<String, dynamic> _$ToJsonTrueFromJsonTruePublicToJson( ToJsonTrueFromJsonFalsePublic _$ToJsonTrueFromJsonFalsePublicFromJson( Map<String, dynamic> json) => ToJsonTrueFromJsonFalsePublic() - ..aField = json['aField'] as int? - ..zField = json['zField'] as int?; + ..aField = (json['aField'] as num?)?.toInt() + ..zField = (json['zField'] as num?)?.toInt(); Map<String, dynamic> _$ToJsonTrueFromJsonFalsePublicToJson( ToJsonTrueFromJsonFalsePublic instance) => @@ -98,9 +98,9 @@ Map<String, dynamic> _$ToJsonTrueFromJsonFalsePublicToJson( ToJsonFalseFromJsonNullPublic _$ToJsonFalseFromJsonNullPublicFromJson( Map<String, dynamic> json) => ToJsonFalseFromJsonNullPublic() - ..aField = json['aField'] as int? - ..field = json['field'] as int? - ..zField = json['zField'] as int?; + ..aField = (json['aField'] as num?)?.toInt() + ..field = (json['field'] as num?)?.toInt() + ..zField = (json['zField'] as num?)?.toInt(); Map<String, dynamic> _$ToJsonFalseFromJsonNullPublicToJson( ToJsonFalseFromJsonNullPublic instance) => @@ -112,9 +112,9 @@ Map<String, dynamic> _$ToJsonFalseFromJsonNullPublicToJson( ToJsonFalseFromJsonTruePublic _$ToJsonFalseFromJsonTruePublicFromJson( Map<String, dynamic> json) => ToJsonFalseFromJsonTruePublic() - ..aField = json['aField'] as int? - ..field = json['field'] as int? - ..zField = json['zField'] as int?; + ..aField = (json['aField'] as num?)?.toInt() + ..field = (json['field'] as num?)?.toInt() + ..zField = (json['zField'] as num?)?.toInt(); Map<String, dynamic> _$ToJsonFalseFromJsonTruePublicToJson( ToJsonFalseFromJsonTruePublic instance) => @@ -126,8 +126,8 @@ Map<String, dynamic> _$ToJsonFalseFromJsonTruePublicToJson( ToJsonFalseFromJsonFalsePublic _$ToJsonFalseFromJsonFalsePublicFromJson( Map<String, dynamic> json) => ToJsonFalseFromJsonFalsePublic() - ..aField = json['aField'] as int? - ..zField = json['zField'] as int?; + ..aField = (json['aField'] as num?)?.toInt() + ..zField = (json['zField'] as num?)?.toInt(); Map<String, dynamic> _$ToJsonFalseFromJsonFalsePublicToJson( ToJsonFalseFromJsonFalsePublic instance) => @@ -139,8 +139,8 @@ Map<String, dynamic> _$ToJsonFalseFromJsonFalsePublicToJson( ToJsonNullFromJsonNullPrivate _$ToJsonNullFromJsonNullPrivateFromJson( Map<String, dynamic> json) => ToJsonNullFromJsonNullPrivate() - ..aField = json['aField'] as int? - ..zField = json['zField'] as int?; + ..aField = (json['aField'] as num?)?.toInt() + ..zField = (json['zField'] as num?)?.toInt(); Map<String, dynamic> _$ToJsonNullFromJsonNullPrivateToJson( ToJsonNullFromJsonNullPrivate instance) => @@ -152,9 +152,9 @@ Map<String, dynamic> _$ToJsonNullFromJsonNullPrivateToJson( ToJsonNullFromJsonTruePrivate _$ToJsonNullFromJsonTruePrivateFromJson( Map<String, dynamic> json) => ToJsonNullFromJsonTruePrivate() - ..aField = json['aField'] as int? - .._field = json['field'] as int? - ..zField = json['zField'] as int?; + ..aField = (json['aField'] as num?)?.toInt() + .._field = (json['field'] as num?)?.toInt() + ..zField = (json['zField'] as num?)?.toInt(); Map<String, dynamic> _$ToJsonNullFromJsonTruePrivateToJson( ToJsonNullFromJsonTruePrivate instance) => @@ -167,8 +167,8 @@ Map<String, dynamic> _$ToJsonNullFromJsonTruePrivateToJson( ToJsonNullFromJsonFalsePrivate _$ToJsonNullFromJsonFalsePrivateFromJson( Map<String, dynamic> json) => ToJsonNullFromJsonFalsePrivate() - ..aField = json['aField'] as int? - ..zField = json['zField'] as int?; + ..aField = (json['aField'] as num?)?.toInt() + ..zField = (json['zField'] as num?)?.toInt(); Map<String, dynamic> _$ToJsonNullFromJsonFalsePrivateToJson( ToJsonNullFromJsonFalsePrivate instance) => @@ -180,8 +180,8 @@ Map<String, dynamic> _$ToJsonNullFromJsonFalsePrivateToJson( ToJsonTrueFromJsonNullPrivate _$ToJsonTrueFromJsonNullPrivateFromJson( Map<String, dynamic> json) => ToJsonTrueFromJsonNullPrivate() - ..aField = json['aField'] as int? - ..zField = json['zField'] as int?; + ..aField = (json['aField'] as num?)?.toInt() + ..zField = (json['zField'] as num?)?.toInt(); Map<String, dynamic> _$ToJsonTrueFromJsonNullPrivateToJson( ToJsonTrueFromJsonNullPrivate instance) => @@ -194,9 +194,9 @@ Map<String, dynamic> _$ToJsonTrueFromJsonNullPrivateToJson( ToJsonTrueFromJsonTruePrivate _$ToJsonTrueFromJsonTruePrivateFromJson( Map<String, dynamic> json) => ToJsonTrueFromJsonTruePrivate() - ..aField = json['aField'] as int? - .._field = json['field'] as int? - ..zField = json['zField'] as int?; + ..aField = (json['aField'] as num?)?.toInt() + .._field = (json['field'] as num?)?.toInt() + ..zField = (json['zField'] as num?)?.toInt(); Map<String, dynamic> _$ToJsonTrueFromJsonTruePrivateToJson( ToJsonTrueFromJsonTruePrivate instance) => @@ -209,8 +209,8 @@ Map<String, dynamic> _$ToJsonTrueFromJsonTruePrivateToJson( ToJsonTrueFromJsonFalsePrivate _$ToJsonTrueFromJsonFalsePrivateFromJson( Map<String, dynamic> json) => ToJsonTrueFromJsonFalsePrivate() - ..aField = json['aField'] as int? - ..zField = json['zField'] as int?; + ..aField = (json['aField'] as num?)?.toInt() + ..zField = (json['zField'] as num?)?.toInt(); Map<String, dynamic> _$ToJsonTrueFromJsonFalsePrivateToJson( ToJsonTrueFromJsonFalsePrivate instance) => @@ -223,8 +223,8 @@ Map<String, dynamic> _$ToJsonTrueFromJsonFalsePrivateToJson( ToJsonFalseFromJsonNullPrivate _$ToJsonFalseFromJsonNullPrivateFromJson( Map<String, dynamic> json) => ToJsonFalseFromJsonNullPrivate() - ..aField = json['aField'] as int? - ..zField = json['zField'] as int?; + ..aField = (json['aField'] as num?)?.toInt() + ..zField = (json['zField'] as num?)?.toInt(); Map<String, dynamic> _$ToJsonFalseFromJsonNullPrivateToJson( ToJsonFalseFromJsonNullPrivate instance) => @@ -236,9 +236,9 @@ Map<String, dynamic> _$ToJsonFalseFromJsonNullPrivateToJson( ToJsonFalseFromJsonTruePrivate _$ToJsonFalseFromJsonTruePrivateFromJson( Map<String, dynamic> json) => ToJsonFalseFromJsonTruePrivate() - ..aField = json['aField'] as int? - .._field = json['field'] as int? - ..zField = json['zField'] as int?; + ..aField = (json['aField'] as num?)?.toInt() + .._field = (json['field'] as num?)?.toInt() + ..zField = (json['zField'] as num?)?.toInt(); Map<String, dynamic> _$ToJsonFalseFromJsonTruePrivateToJson( ToJsonFalseFromJsonTruePrivate instance) => @@ -250,8 +250,8 @@ Map<String, dynamic> _$ToJsonFalseFromJsonTruePrivateToJson( ToJsonFalseFromJsonFalsePrivate _$ToJsonFalseFromJsonFalsePrivateFromJson( Map<String, dynamic> json) => ToJsonFalseFromJsonFalsePrivate() - ..aField = json['aField'] as int? - ..zField = json['zField'] as int?; + ..aField = (json['aField'] as num?)?.toInt() + ..zField = (json['zField'] as num?)?.toInt(); Map<String, dynamic> _$ToJsonFalseFromJsonFalsePrivateToJson( ToJsonFalseFromJsonFalsePrivate instance) => diff --git a/json_serializable/test/generic_files/generic_argument_factories.g.dart b/json_serializable/test/generic_files/generic_argument_factories.g.dart index 188ac7116..3ae8ac8e1 100644 --- a/json_serializable/test/generic_files/generic_argument_factories.g.dart +++ b/json_serializable/test/generic_files/generic_argument_factories.g.dart @@ -34,7 +34,7 @@ ConcreteClass _$ConcreteClassFromJson(Map<String, dynamic> json) => ConcreteClass( GenericClassWithHelpers<int, String>.fromJson( json['value'] as Map<String, dynamic>, - (value) => value as int, + (value) => (value as num).toInt(), (value) => value as String), GenericClassWithHelpers<double, BigInt>.fromJson( json['value2'] as Map<String, dynamic>, diff --git a/json_serializable/test/generic_files/generic_argument_factories_nullable.g.dart b/json_serializable/test/generic_files/generic_argument_factories_nullable.g.dart index 17b278eed..626fa171a 100644 --- a/json_serializable/test/generic_files/generic_argument_factories_nullable.g.dart +++ b/json_serializable/test/generic_files/generic_argument_factories_nullable.g.dart @@ -56,7 +56,7 @@ ConcreteClassNullable _$ConcreteClassNullableFromJson( ConcreteClassNullable( GenericClassWithHelpersNullable<int, String>.fromJson( json['value'] as Map<String, dynamic>, - (value) => value as int, + (value) => (value as num).toInt(), (value) => value as String), GenericClassWithHelpersNullable<double, BigInt>.fromJson( json['value2'] as Map<String, dynamic>, diff --git a/json_serializable/test/generic_files/generic_class.dart b/json_serializable/test/generic_files/generic_class.dart index 0870c956f..0ebfe7d1e 100644 --- a/json_serializable/test/generic_files/generic_class.dart +++ b/json_serializable/test/generic_files/generic_class.dart @@ -48,12 +48,15 @@ class GenericClass<T extends num, S> { @_DurationMillisecondConverter.named() @_DurationListMillisecondConverter() class GenericClassWithConverter<T extends num, S> { + // TODO: this annotation is a no-op. Need to figure out what to do about it! @_SimpleConverter() Object? fieldObject; + // TODO: this annotation is a no-op. Need to figure out what to do about it! @_SimpleConverter() dynamic fieldDynamic; + // TODO: this annotation is a no-op. Need to figure out what to do about it! @_SimpleConverter() int? fieldInt; diff --git a/json_serializable/test/generic_files/generic_class.g.dart b/json_serializable/test/generic_files/generic_class.g.dart index c5809241c..104eec1d6 100644 --- a/json_serializable/test/generic_files/generic_class.g.dart +++ b/json_serializable/test/generic_files/generic_class.g.dart @@ -38,15 +38,15 @@ GenericClassWithConverter<T, S> GenericClassWithConverter<T, S>() ..fieldObject = json['fieldObject'] ..fieldDynamic = json['fieldDynamic'] - ..fieldInt = json['fieldInt'] as int? + ..fieldInt = (json['fieldInt'] as num?)?.toInt() ..fieldT = _$JsonConverterFromJson<Map<String, dynamic>, T>( json['fieldT'], _SimpleConverter<T?>().fromJson) ..fieldS = _$JsonConverterFromJson<Map<String, dynamic>, S>( json['fieldS'], _SimpleConverter<S?>().fromJson) ..duration = const _DurationMillisecondConverter.named() - .fromJson(json['duration'] as int?) + .fromJson((json['duration'] as num?)?.toInt()) ..listDuration = const _DurationListMillisecondConverter() - .fromJson(json['listDuration'] as int?); + .fromJson((json['listDuration'] as num?)?.toInt()); Map<String, dynamic> _$GenericClassWithConverterToJson<T extends num, S>( GenericClassWithConverter<T, S> instance) => diff --git a/json_serializable/test/generic_files/generic_test.dart b/json_serializable/test/generic_files/generic_test.dart index e4f82d6f3..ea509a471 100644 --- a/json_serializable/test/generic_files/generic_test.dart +++ b/json_serializable/test/generic_files/generic_test.dart @@ -76,7 +76,7 @@ void main() { final decoded = GenericClassWithHelpers<DateTime, Duration>.fromJson( jsonDecode(encodedJson) as Map<String, dynamic>, (value) => DateTime.parse(value as String), - (value) => Duration(milliseconds: value as int), + (value) => Duration(milliseconds: (value as num).toInt()), ); final encodedJson2 = loudEncode( @@ -194,7 +194,7 @@ void main() { GenericClassWithHelpersNullable<DateTime, Duration>.fromJson( jsonDecode(encodedJson) as Map<String, dynamic>, (value) => DateTime.parse(value as String), - (value) => Duration(milliseconds: value as int), + (value) => Duration(milliseconds: (value as num).toInt()), ); final encodedJson2 = loudEncode( @@ -225,7 +225,7 @@ void main() { GenericClassWithHelpersNullable<DateTime, Duration>.fromJson( jsonDecode(encodedJson) as Map<String, dynamic>, (value) => DateTime.parse(value as String), - (value) => Duration(milliseconds: value as int), + (value) => Duration(milliseconds: (value as num).toInt()), ); final encodedJson2 = loudEncode( diff --git a/json_serializable/test/integration/converter_examples.g.dart b/json_serializable/test/integration/converter_examples.g.dart index 26da277f0..2829672a9 100644 --- a/json_serializable/test/integration/converter_examples.g.dart +++ b/json_serializable/test/integration/converter_examples.g.dart @@ -12,7 +12,7 @@ Issue1202RegressionClass _$Issue1202RegressionClassFromJson( Map<String, dynamic> json) => Issue1202RegressionClass( value: $enumDecode(_$Issue1202RegressionEnumEnumMap, json['value']), - normalNullableValue: json['normalNullableValue'] as int?, + normalNullableValue: (json['normalNullableValue'] as num?)?.toInt(), notNullableValueWithNullableConverter: const _Issue1202RegressionConverter().fromJson( json['notNullableValueWithNullableConverter'] as String?), diff --git a/json_serializable/test/integration/create_per_field_to_json_example.g.dart b/json_serializable/test/integration/create_per_field_to_json_example.g.dart index 0587c26ba..1c4b0fe88 100644 --- a/json_serializable/test/integration/create_per_field_to_json_example.g.dart +++ b/json_serializable/test/integration/create_per_field_to_json_example.g.dart @@ -23,7 +23,7 @@ Model _$ModelFromJson(Map<String, dynamic> json) => Model( ? null : GenericFactory<int>.fromJson( json['nestedGeneric'] as Map<String, dynamic>, - (value) => value as int), + (value) => (value as num).toInt()), ); // ignore: unused_element diff --git a/json_serializable/test/integration/integration_test.dart b/json_serializable/test/integration/integration_test.dart index 8c5827ee8..6aef150f2 100644 --- a/json_serializable/test/integration/integration_test.dart +++ b/json_serializable/test/integration/integration_test.dart @@ -258,18 +258,23 @@ void main() { test('support ints as doubles', () { final value = { 'doubles': [0, 0.0], - 'nnDoubles': [0, 0.0] + 'nnDoubles': [0, 0.0], + 'doubleAsString': 3, }; - roundTripNumber(Numbers.fromJson(value)); + final output = roundTripObject(Numbers.fromJson(value), Numbers.fromJson); + expect(output.doubleAsString, 3.0.toString()); }); - test('does not support doubles as ints', () { + test('support doubles as ints', () { final value = { - 'ints': [3.14, 0], + 'ints': [3, 3.0, 3.14, 0], }; - expect(() => Numbers.fromJson(value), throwsTypeError); + final output = roundTripObject(Numbers.fromJson(value), Numbers.fromJson); + + // NOTE: all of the double values are truncated + expect(output.ints, [3, 3, 3, 0]); }); }); diff --git a/json_serializable/test/integration/json_test_common.dart b/json_serializable/test/integration/json_test_common.dart index d16c3b954..27415fb81 100644 --- a/json_serializable/test/integration/json_test_common.dart +++ b/json_serializable/test/integration/json_test_common.dart @@ -38,6 +38,11 @@ Duration? durationFromInt(int? ms) => int? durationToInt(Duration? duration) => duration?.inMilliseconds; +String? stringFromDouble(double? value) => value?.toString(); + +double? stringToDouble(String? value) => + value == null ? null : double.parse(value); + DateTime? dateTimeFromEpochUs(int? us) => us == null ? null : DateTime.fromMicrosecondsSinceEpoch(us); diff --git a/json_serializable/test/integration/json_test_example.dart b/json_serializable/test/integration/json_test_example.dart index d69be6022..7f3482935 100644 --- a/json_serializable/test/integration/json_test_example.dart +++ b/json_serializable/test/integration/json_test_example.dart @@ -155,6 +155,9 @@ class Numbers { @JsonKey(fromJson: durationFromInt, toJson: durationToInt) Duration? duration; + @JsonKey(fromJson: stringFromDouble, toJson: stringToDouble) + String? doubleAsString; + @JsonKey(fromJson: dateTimeFromEpochUs, toJson: dateTimeToEpochUs) DateTime? date; diff --git a/json_serializable/test/integration/json_test_example.g.dart b/json_serializable/test/integration/json_test_example.g.dart index b6a5330d4..ec12eb554 100644 --- a/json_serializable/test/integration/json_test_example.g.dart +++ b/json_serializable/test/integration/json_test_example.g.dart @@ -29,7 +29,8 @@ Person _$PersonFromJson(Map<String, dynamic> json) => Person( (k, e) => MapEntry(k, $enumDecode(_$CategoryEnumMap, e)), ) ..categoryCounts = (json['categoryCounts'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry($enumDecode(_$CategoryEnumMap, k), e as int), + (k, e) => + MapEntry($enumDecode(_$CategoryEnumMap, k), (e as num).toInt()), ); Map<String, dynamic> _$PersonToJson(Person instance) => <String, dynamic>{ @@ -66,11 +67,11 @@ Order _$OrderFromJson(Map<String, dynamic> json) { (json['items'] as List<dynamic>?) ?.map((e) => Item.fromJson(e as Map<String, dynamic>)), ) - ..count = json['count'] as int? + ..count = (json['count'] as num?)?.toInt() ..isRushed = json['isRushed'] as bool? ..duration = json['duration'] == null ? null - : Duration(microseconds: json['duration'] as int) + : Duration(microseconds: (json['duration'] as num).toInt()) ..platform = json['platform'] == null ? null : Platform.fromJson(json['platform'] as String) @@ -113,13 +114,15 @@ const _$StatusCodeEnumMap = { }; Item _$ItemFromJson(Map<String, dynamic> json) => Item( - json['price'] as int?, + (json['price'] as num?)?.toInt(), ) - ..itemNumber = json['item-number'] as int? + ..itemNumber = (json['item-number'] as num?)?.toInt() ..saleDates = (json['saleDates'] as List<dynamic>?) ?.map((e) => DateTime.parse(e as String)) .toList() - ..rates = (json['rates'] as List<dynamic>?)?.map((e) => e as int).toList() + ..rates = (json['rates'] as List<dynamic>?) + ?.map((e) => (e as num).toInt()) + .toList() ..geoPoint = _fromJsonGeoPoint(json['geoPoint'] as Map<String, dynamic>?); Map<String, dynamic> _$ItemToJson(Item instance) { @@ -142,7 +145,8 @@ Map<String, dynamic> _$ItemToJson(Item instance) { } Numbers _$NumbersFromJson(Map<String, dynamic> json) => Numbers() - ..ints = (json['ints'] as List<dynamic>?)?.map((e) => e as int).toList() + ..ints = + (json['ints'] as List<dynamic>?)?.map((e) => (e as num).toInt()).toList() ..nums = (json['nums'] as List<dynamic>?)?.map((e) => e as num).toList() ..doubles = (json['doubles'] as List<dynamic>?) ?.map((e) => (e as num).toDouble()) @@ -150,8 +154,10 @@ Numbers _$NumbersFromJson(Map<String, dynamic> json) => Numbers() ..nnDoubles = (json['nnDoubles'] as List<dynamic>?) ?.map((e) => (e as num).toDouble()) .toList() - ..duration = durationFromInt(json['duration'] as int?) - ..date = dateTimeFromEpochUs(json['date'] as int?); + ..duration = durationFromInt((json['duration'] as num?)?.toInt()) + ..doubleAsString = + stringFromDouble((json['doubleAsString'] as num?)?.toDouble()) + ..date = dateTimeFromEpochUs((json['date'] as num?)?.toInt()); Map<String, dynamic> _$NumbersToJson(Numbers instance) => <String, dynamic>{ 'ints': instance.ints, @@ -159,22 +165,23 @@ Map<String, dynamic> _$NumbersToJson(Numbers instance) => <String, dynamic>{ 'doubles': instance.doubles, 'nnDoubles': instance.nnDoubles, 'duration': durationToInt(instance.duration), + 'doubleAsString': stringToDouble(instance.doubleAsString), 'date': dateTimeToEpochUs(instance.date), }; MapKeyVariety _$MapKeyVarietyFromJson(Map<String, dynamic> json) => MapKeyVariety() ..intIntMap = (json['intIntMap'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(int.parse(k), e as int), + (k, e) => MapEntry(int.parse(k), (e as num).toInt()), ) ..uriIntMap = (json['uriIntMap'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(Uri.parse(k), e as int), + (k, e) => MapEntry(Uri.parse(k), (e as num).toInt()), ) ..dateTimeIntMap = (json['dateTimeIntMap'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(DateTime.parse(k), e as int), + (k, e) => MapEntry(DateTime.parse(k), (e as num).toInt()), ) ..bigIntMap = (json['bigIntMap'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(BigInt.parse(k), e as int), + (k, e) => MapEntry(BigInt.parse(k), (e as num).toInt()), ); Map<String, dynamic> _$MapKeyVarietyToJson(MapKeyVariety instance) => @@ -204,7 +211,7 @@ UnknownEnumValue _$UnknownEnumValueFromJson(Map<String, dynamic> json) => PrivateConstructor _$PrivateConstructorFromJson(Map<String, dynamic> json) => PrivateConstructor._( - json['id'] as int, + (json['id'] as num).toInt(), json['value'] as String, ); diff --git a/json_serializable/test/integration/json_test_example.g_any_map.dart b/json_serializable/test/integration/json_test_example.g_any_map.dart index 2c6b51bda..b4789725d 100644 --- a/json_serializable/test/integration/json_test_example.g_any_map.dart +++ b/json_serializable/test/integration/json_test_example.g_any_map.dart @@ -161,6 +161,9 @@ class Numbers { @JsonKey(fromJson: durationFromInt, toJson: durationToInt) Duration? duration; + @JsonKey(fromJson: stringFromDouble, toJson: stringToDouble) + String? doubleAsString; + @JsonKey(fromJson: dateTimeFromEpochUs, toJson: dateTimeToEpochUs) DateTime? date; diff --git a/json_serializable/test/integration/json_test_example.g_any_map.g.dart b/json_serializable/test/integration/json_test_example.g_any_map.g.dart index b8ba1f9f4..5fe79152e 100644 --- a/json_serializable/test/integration/json_test_example.g_any_map.g.dart +++ b/json_serializable/test/integration/json_test_example.g_any_map.g.dart @@ -29,7 +29,8 @@ Person _$PersonFromJson(Map json) => Person( (k, e) => MapEntry(k as String, $enumDecode(_$CategoryEnumMap, e)), ) ..categoryCounts = (json['categoryCounts'] as Map?)?.map( - (k, e) => MapEntry($enumDecode(_$CategoryEnumMap, k), e as int), + (k, e) => + MapEntry($enumDecode(_$CategoryEnumMap, k), (e as num).toInt()), ); Map<String, dynamic> _$PersonToJson(Person instance) => <String, dynamic>{ @@ -66,11 +67,11 @@ Order _$OrderFromJson(Map json) { (json['items'] as List<dynamic>?) ?.map((e) => Item.fromJson(Map<String, dynamic>.from(e as Map))), ) - ..count = json['count'] as int? + ..count = (json['count'] as num?)?.toInt() ..isRushed = json['isRushed'] as bool? ..duration = json['duration'] == null ? null - : Duration(microseconds: json['duration'] as int) + : Duration(microseconds: (json['duration'] as num).toInt()) ..platform = json['platform'] == null ? null : Platform.fromJson(json['platform'] as String) @@ -113,13 +114,15 @@ const _$StatusCodeEnumMap = { }; Item _$ItemFromJson(Map json) => Item( - json['price'] as int?, + (json['price'] as num?)?.toInt(), ) - ..itemNumber = json['item-number'] as int? + ..itemNumber = (json['item-number'] as num?)?.toInt() ..saleDates = (json['saleDates'] as List<dynamic>?) ?.map((e) => DateTime.parse(e as String)) .toList() - ..rates = (json['rates'] as List<dynamic>?)?.map((e) => e as int).toList() + ..rates = (json['rates'] as List<dynamic>?) + ?.map((e) => (e as num).toInt()) + .toList() ..geoPoint = _fromJsonGeoPoint(json['geoPoint'] as Map<String, dynamic>?); Map<String, dynamic> _$ItemToJson(Item instance) { @@ -142,7 +145,8 @@ Map<String, dynamic> _$ItemToJson(Item instance) { } Numbers _$NumbersFromJson(Map json) => Numbers() - ..ints = (json['ints'] as List<dynamic>?)?.map((e) => e as int).toList() + ..ints = + (json['ints'] as List<dynamic>?)?.map((e) => (e as num).toInt()).toList() ..nums = (json['nums'] as List<dynamic>?)?.map((e) => e as num).toList() ..doubles = (json['doubles'] as List<dynamic>?) ?.map((e) => (e as num).toDouble()) @@ -150,8 +154,10 @@ Numbers _$NumbersFromJson(Map json) => Numbers() ..nnDoubles = (json['nnDoubles'] as List<dynamic>?) ?.map((e) => (e as num).toDouble()) .toList() - ..duration = durationFromInt(json['duration'] as int?) - ..date = dateTimeFromEpochUs(json['date'] as int?); + ..duration = durationFromInt((json['duration'] as num?)?.toInt()) + ..doubleAsString = + stringFromDouble((json['doubleAsString'] as num?)?.toDouble()) + ..date = dateTimeFromEpochUs((json['date'] as num?)?.toInt()); Map<String, dynamic> _$NumbersToJson(Numbers instance) => <String, dynamic>{ 'ints': instance.ints, @@ -159,21 +165,22 @@ Map<String, dynamic> _$NumbersToJson(Numbers instance) => <String, dynamic>{ 'doubles': instance.doubles, 'nnDoubles': instance.nnDoubles, 'duration': durationToInt(instance.duration), + 'doubleAsString': stringToDouble(instance.doubleAsString), 'date': dateTimeToEpochUs(instance.date), }; MapKeyVariety _$MapKeyVarietyFromJson(Map json) => MapKeyVariety() ..intIntMap = (json['intIntMap'] as Map?)?.map( - (k, e) => MapEntry(int.parse(k as String), e as int), + (k, e) => MapEntry(int.parse(k as String), (e as num).toInt()), ) ..uriIntMap = (json['uriIntMap'] as Map?)?.map( - (k, e) => MapEntry(Uri.parse(k as String), e as int), + (k, e) => MapEntry(Uri.parse(k as String), (e as num).toInt()), ) ..dateTimeIntMap = (json['dateTimeIntMap'] as Map?)?.map( - (k, e) => MapEntry(DateTime.parse(k as String), e as int), + (k, e) => MapEntry(DateTime.parse(k as String), (e as num).toInt()), ) ..bigIntMap = (json['bigIntMap'] as Map?)?.map( - (k, e) => MapEntry(BigInt.parse(k as String), e as int), + (k, e) => MapEntry(BigInt.parse(k as String), (e as num).toInt()), ); Map<String, dynamic> _$MapKeyVarietyToJson(MapKeyVariety instance) => @@ -202,7 +209,7 @@ UnknownEnumValue _$UnknownEnumValueFromJson(Map json) => UnknownEnumValue() PrivateConstructor _$PrivateConstructorFromJson(Map json) => PrivateConstructor._( - json['id'] as int, + (json['id'] as num).toInt(), json['value'] as String, ); diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g.dart index d9230fbc5..6d376fdfe 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g.dart @@ -9,13 +9,13 @@ part of 'kitchen_sink.dart'; // ************************************************************************** KitchenSink _$KitchenSinkFromJson(Map<String, dynamic> json) => KitchenSink( - ctorValidatedNo42: json['no-42'] as int?, + ctorValidatedNo42: (json['no-42'] as num?)?.toInt(), iterable: _valueAccessor(json, 'iterable') as List<dynamic>?, dynamicIterable: json['dynamicIterable'] as List<dynamic>?, objectIterable: (json['objectIterable'] as List<dynamic>?)?.map((e) => e as Object), - intIterable: - (json['intIterable'] as List<dynamic>?)?.map((e) => e as int), + intIterable: (json['intIterable'] as List<dynamic>?) + ?.map((e) => (e as num).toInt()), dateTimeIterable: (json['datetime-iterable'] as List<dynamic>?) ?.map((e) => DateTime.parse(e as String)), ) @@ -28,7 +28,9 @@ KitchenSink _$KitchenSinkFromJson(Map<String, dynamic> json) => KitchenSink( ..dynamicSet = (json['dynamicSet'] as List<dynamic>).toSet() ..objectSet = (json['objectSet'] as List<dynamic>).map((e) => e as Object).toSet() - ..intSet = (json['intSet'] as List<dynamic>).map((e) => e as int).toSet() + ..intSet = (json['intSet'] as List<dynamic>) + .map((e) => (e as num).toInt()) + .toSet() ..dateTimeSet = (json['dateTimeSet'] as List<dynamic>) .map((e) => DateTime.parse(e as String)) .toSet() @@ -36,8 +38,9 @@ KitchenSink _$KitchenSinkFromJson(Map<String, dynamic> json) => KitchenSink( ..dynamicList = json['dynamicList'] as List<dynamic> ..objectList = (json['objectList'] as List<dynamic>).map((e) => e as Object).toList() - ..intList = - (json['intList'] as List<dynamic>).map((e) => e as int).toList() + ..intList = (json['intList'] as List<dynamic>) + .map((e) => (e as num).toInt()) + .toList() ..dateTimeList = (json['dateTimeList'] as List<dynamic>) .map((e) => DateTime.parse(e as String)) .toList() @@ -85,11 +88,11 @@ KitchenSink _$KitchenSinkFromJson(Map<String, dynamic> json) => KitchenSink( SimpleObject.fromJson(json['simpleObject'] as Map<String, dynamic>) ..strictKeysObject = StrictKeysObject.fromJson( json['strictKeysObject'] as Map<String, dynamic>) - ..validatedPropertyNo42 = json['validatedPropertyNo42'] as int? + ..validatedPropertyNo42 = (json['validatedPropertyNo42'] as num?)?.toInt() ..recordField = _$recordConvertNullable( json['recordField'], ($jsonValue) => ( - $jsonValue[r'$1'] as int, + ($jsonValue[r'$1'] as num).toInt(), $jsonValue[r'$2'] as String, truth: $jsonValue['truth'] as bool, ), @@ -158,9 +161,11 @@ $Rec? _$recordConvertNullable<$Rec>( JsonConverterTestClass _$JsonConverterTestClassFromJson( Map<String, dynamic> json) => JsonConverterTestClass( - const DurationMillisecondConverter().fromJson(json['duration'] as int?), + const DurationMillisecondConverter() + .fromJson((json['duration'] as num?)?.toInt()), (json['durationList'] as List<dynamic>) - .map((e) => const DurationMillisecondConverter().fromJson(e as int?)) + .map((e) => const DurationMillisecondConverter() + .fromJson((e as num?)?.toInt())) .toList(), const BigIntStringConverter().fromJson(json['bigInt'] as String), (json['bigIntMap'] as Map<String, dynamic>).map( @@ -175,16 +180,20 @@ JsonConverterTestClass _$JsonConverterTestClassFromJson( _$JsonConverterFromJson<String, BigInt>( e, const BigIntStringConverter().fromJson)), ), - TrivialNumberConverter.instance.fromJson(json['numberSilly'] as int?), + TrivialNumberConverter.instance + .fromJson((json['numberSilly'] as num?)?.toInt()), (json['numberSillySet'] as List<dynamic>) - .map((e) => TrivialNumberConverter.instance.fromJson(e as int?)) + .map((e) => + TrivialNumberConverter.instance.fromJson((e as num?)?.toInt())) .toSet(), - const EpochDateTimeConverter().fromJson(json['dateTime'] as int?), + const EpochDateTimeConverter() + .fromJson((json['dateTime'] as num?)?.toInt()), trivialStringConverter.fromJson(json['trivialString'] as String?), TrivialNumberConverter.instance - .fromJson(json['nullableNumberSilly'] as int?), + .fromJson((json['nullableNumberSilly'] as num?)?.toInt()), (json['nullableNumberSillySet'] as List<dynamic>) - .map((e) => TrivialNumberConverter.instance.fromJson(e as int?)) + .map((e) => + TrivialNumberConverter.instance.fromJson((e as num?)?.toInt())) .toSet(), ); diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart index 74a348f5e..69301303d 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart @@ -9,13 +9,13 @@ part of 'kitchen_sink.g_any_map.dart'; // ************************************************************************** KitchenSink _$KitchenSinkFromJson(Map json) => KitchenSink( - ctorValidatedNo42: json['no-42'] as int?, + ctorValidatedNo42: (json['no-42'] as num?)?.toInt(), iterable: _valueAccessor(json, 'iterable') as List<dynamic>?, dynamicIterable: json['dynamicIterable'] as List<dynamic>?, objectIterable: (json['objectIterable'] as List<dynamic>?)?.map((e) => e as Object), - intIterable: - (json['intIterable'] as List<dynamic>?)?.map((e) => e as int), + intIterable: (json['intIterable'] as List<dynamic>?) + ?.map((e) => (e as num).toInt()), dateTimeIterable: (json['datetime-iterable'] as List<dynamic>?) ?.map((e) => DateTime.parse(e as String)), ) @@ -28,7 +28,9 @@ KitchenSink _$KitchenSinkFromJson(Map json) => KitchenSink( ..dynamicSet = (json['dynamicSet'] as List<dynamic>).toSet() ..objectSet = (json['objectSet'] as List<dynamic>).map((e) => e as Object).toSet() - ..intSet = (json['intSet'] as List<dynamic>).map((e) => e as int).toSet() + ..intSet = (json['intSet'] as List<dynamic>) + .map((e) => (e as num).toInt()) + .toSet() ..dateTimeSet = (json['dateTimeSet'] as List<dynamic>) .map((e) => DateTime.parse(e as String)) .toSet() @@ -36,8 +38,9 @@ KitchenSink _$KitchenSinkFromJson(Map json) => KitchenSink( ..dynamicList = json['dynamicList'] as List<dynamic> ..objectList = (json['objectList'] as List<dynamic>).map((e) => e as Object).toList() - ..intList = - (json['intList'] as List<dynamic>).map((e) => e as int).toList() + ..intList = (json['intList'] as List<dynamic>) + .map((e) => (e as num).toInt()) + .toList() ..dateTimeList = (json['dateTimeList'] as List<dynamic>) .map((e) => DateTime.parse(e as String)) .toList() @@ -77,11 +80,11 @@ KitchenSink _$KitchenSinkFromJson(Map json) => KitchenSink( ..simpleObject = SimpleObject.fromJson(json['simpleObject'] as Map) ..strictKeysObject = StrictKeysObject.fromJson(json['strictKeysObject'] as Map) - ..validatedPropertyNo42 = json['validatedPropertyNo42'] as int? + ..validatedPropertyNo42 = (json['validatedPropertyNo42'] as num?)?.toInt() ..recordField = _$recordConvertAnyNullable( json['recordField'], ($jsonValue) => ( - $jsonValue[r'$1'] as int, + ($jsonValue[r'$1'] as num).toInt(), $jsonValue[r'$2'] as String, truth: $jsonValue['truth'] as bool, ), @@ -149,9 +152,11 @@ $Rec? _$recordConvertAnyNullable<$Rec>( JsonConverterTestClass _$JsonConverterTestClassFromJson(Map json) => JsonConverterTestClass( - const DurationMillisecondConverter().fromJson(json['duration'] as int?), + const DurationMillisecondConverter() + .fromJson((json['duration'] as num?)?.toInt()), (json['durationList'] as List<dynamic>) - .map((e) => const DurationMillisecondConverter().fromJson(e as int?)) + .map((e) => const DurationMillisecondConverter() + .fromJson((e as num?)?.toInt())) .toList(), const BigIntStringConverter().fromJson(json['bigInt'] as String), (json['bigIntMap'] as Map).map( @@ -166,16 +171,20 @@ JsonConverterTestClass _$JsonConverterTestClassFromJson(Map json) => _$JsonConverterFromJson<String, BigInt>( e, const BigIntStringConverter().fromJson)), ), - TrivialNumberConverter.instance.fromJson(json['numberSilly'] as int?), + TrivialNumberConverter.instance + .fromJson((json['numberSilly'] as num?)?.toInt()), (json['numberSillySet'] as List<dynamic>) - .map((e) => TrivialNumberConverter.instance.fromJson(e as int?)) + .map((e) => + TrivialNumberConverter.instance.fromJson((e as num?)?.toInt())) .toSet(), - const EpochDateTimeConverter().fromJson(json['dateTime'] as int?), + const EpochDateTimeConverter() + .fromJson((json['dateTime'] as num?)?.toInt()), trivialStringConverter.fromJson(json['trivialString'] as String?), TrivialNumberConverter.instance - .fromJson(json['nullableNumberSilly'] as int?), + .fromJson((json['nullableNumberSilly'] as num?)?.toInt()), (json['nullableNumberSillySet'] as List<dynamic>) - .map((e) => TrivialNumberConverter.instance.fromJson(e as int?)) + .map((e) => + TrivialNumberConverter.instance.fromJson((e as num?)?.toInt())) .toSet(), ); diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.g.dart index d08da32c5..c004dcc74 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.g.dart @@ -13,7 +13,8 @@ KitchenSink _$KitchenSinkFromJson(Map json) => $checkedCreate( json, ($checkedConvert) { final val = KitchenSink( - ctorValidatedNo42: $checkedConvert('no-42', (v) => v as int?), + ctorValidatedNo42: + $checkedConvert('no-42', (v) => (v as num?)?.toInt()), iterable: $checkedConvert( 'iterable', (v) => v as List<dynamic>?, @@ -24,7 +25,7 @@ KitchenSink _$KitchenSinkFromJson(Map json) => $checkedCreate( objectIterable: $checkedConvert('objectIterable', (v) => (v as List<dynamic>?)?.map((e) => e as Object)), intIterable: $checkedConvert('intIterable', - (v) => (v as List<dynamic>?)?.map((e) => e as int)), + (v) => (v as List<dynamic>?)?.map((e) => (e as num).toInt())), dateTimeIterable: $checkedConvert( 'datetime-iterable', (v) => (v as List<dynamic>?) @@ -45,8 +46,8 @@ KitchenSink _$KitchenSinkFromJson(Map json) => $checkedCreate( (v as List<dynamic>).map((e) => e as Object).toSet()); $checkedConvert( 'intSet', - (v) => - val.intSet = (v as List<dynamic>).map((e) => e as int).toSet()); + (v) => val.intSet = + (v as List<dynamic>).map((e) => (e as num).toInt()).toSet()); $checkedConvert( 'dateTimeSet', (v) => val.dateTimeSet = (v as List<dynamic>) @@ -62,7 +63,7 @@ KitchenSink _$KitchenSinkFromJson(Map json) => $checkedCreate( $checkedConvert( 'intList', (v) => val.intList = - (v as List<dynamic>).map((e) => e as int).toList()); + (v as List<dynamic>).map((e) => (e as num).toInt()).toList()); $checkedConvert( 'dateTimeList', (v) => val.dateTimeList = (v as List<dynamic>) @@ -120,13 +121,13 @@ KitchenSink _$KitchenSinkFromJson(Map json) => $checkedCreate( $checkedConvert('strictKeysObject', (v) => val.strictKeysObject = StrictKeysObject.fromJson(v as Map)); $checkedConvert('validatedPropertyNo42', - (v) => val.validatedPropertyNo42 = v as int?); + (v) => val.validatedPropertyNo42 = (v as num?)?.toInt()); $checkedConvert( 'recordField', (v) => val.recordField = _$recordConvertAnyNullable( v, ($jsonValue) => ( - $jsonValue[r'$1'] as int, + ($jsonValue[r'$1'] as num).toInt(), $jsonValue[r'$2'] as String, truth: $jsonValue['truth'] as bool, ), @@ -206,13 +207,15 @@ JsonConverterTestClass _$JsonConverterTestClassFromJson(Map json) => json, ($checkedConvert) { final val = JsonConverterTestClass( - $checkedConvert('duration', - (v) => const DurationMillisecondConverter().fromJson(v as int?)), + $checkedConvert( + 'duration', + (v) => const DurationMillisecondConverter() + .fromJson((v as num?)?.toInt())), $checkedConvert( 'durationList', (v) => (v as List<dynamic>) - .map((e) => - const DurationMillisecondConverter().fromJson(e as int?)) + .map((e) => const DurationMillisecondConverter() + .fromJson((e as num?)?.toInt())) .toList()), $checkedConvert('bigInt', (v) => const BigIntStringConverter().fromJson(v as String)), @@ -234,25 +237,31 @@ JsonConverterTestClass _$JsonConverterTestClassFromJson(Map json) => _$JsonConverterFromJson<String, BigInt>( e, const BigIntStringConverter().fromJson)), )), - $checkedConvert('numberSilly', - (v) => TrivialNumberConverter.instance.fromJson(v as int?)), + $checkedConvert( + 'numberSilly', + (v) => TrivialNumberConverter.instance + .fromJson((v as num?)?.toInt())), $checkedConvert( 'numberSillySet', (v) => (v as List<dynamic>) - .map((e) => - TrivialNumberConverter.instance.fromJson(e as int?)) + .map((e) => TrivialNumberConverter.instance + .fromJson((e as num?)?.toInt())) .toSet()), - $checkedConvert('dateTime', - (v) => const EpochDateTimeConverter().fromJson(v as int?)), + $checkedConvert( + 'dateTime', + (v) => const EpochDateTimeConverter() + .fromJson((v as num?)?.toInt())), $checkedConvert('trivialString', (v) => trivialStringConverter.fromJson(v as String?)), - $checkedConvert('nullableNumberSilly', - (v) => TrivialNumberConverter.instance.fromJson(v as int?)), + $checkedConvert( + 'nullableNumberSilly', + (v) => TrivialNumberConverter.instance + .fromJson((v as num?)?.toInt())), $checkedConvert( 'nullableNumberSillySet', (v) => (v as List<dynamic>) - .map((e) => - TrivialNumberConverter.instance.fromJson(e as int?)) + .map((e) => TrivialNumberConverter.instance + .fromJson((e as num?)?.toInt())) .toSet()), ); return val; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart index 76504317c..a3a8f8550 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart @@ -9,13 +9,13 @@ part of 'kitchen_sink.g_exclude_null.dart'; // ************************************************************************** KitchenSink _$KitchenSinkFromJson(Map<String, dynamic> json) => KitchenSink( - ctorValidatedNo42: json['no-42'] as int?, + ctorValidatedNo42: (json['no-42'] as num?)?.toInt(), iterable: _valueAccessor(json, 'iterable') as List<dynamic>?, dynamicIterable: json['dynamicIterable'] as List<dynamic>?, objectIterable: (json['objectIterable'] as List<dynamic>?)?.map((e) => e as Object), - intIterable: - (json['intIterable'] as List<dynamic>?)?.map((e) => e as int), + intIterable: (json['intIterable'] as List<dynamic>?) + ?.map((e) => (e as num).toInt()), dateTimeIterable: (json['datetime-iterable'] as List<dynamic>?) ?.map((e) => DateTime.parse(e as String)), ) @@ -28,7 +28,9 @@ KitchenSink _$KitchenSinkFromJson(Map<String, dynamic> json) => KitchenSink( ..dynamicSet = (json['dynamicSet'] as List<dynamic>).toSet() ..objectSet = (json['objectSet'] as List<dynamic>).map((e) => e as Object).toSet() - ..intSet = (json['intSet'] as List<dynamic>).map((e) => e as int).toSet() + ..intSet = (json['intSet'] as List<dynamic>) + .map((e) => (e as num).toInt()) + .toSet() ..dateTimeSet = (json['dateTimeSet'] as List<dynamic>) .map((e) => DateTime.parse(e as String)) .toSet() @@ -36,8 +38,9 @@ KitchenSink _$KitchenSinkFromJson(Map<String, dynamic> json) => KitchenSink( ..dynamicList = json['dynamicList'] as List<dynamic> ..objectList = (json['objectList'] as List<dynamic>).map((e) => e as Object).toList() - ..intList = - (json['intList'] as List<dynamic>).map((e) => e as int).toList() + ..intList = (json['intList'] as List<dynamic>) + .map((e) => (e as num).toInt()) + .toList() ..dateTimeList = (json['dateTimeList'] as List<dynamic>) .map((e) => DateTime.parse(e as String)) .toList() @@ -85,11 +88,11 @@ KitchenSink _$KitchenSinkFromJson(Map<String, dynamic> json) => KitchenSink( SimpleObject.fromJson(json['simpleObject'] as Map<String, dynamic>) ..strictKeysObject = StrictKeysObject.fromJson( json['strictKeysObject'] as Map<String, dynamic>) - ..validatedPropertyNo42 = json['validatedPropertyNo42'] as int? + ..validatedPropertyNo42 = (json['validatedPropertyNo42'] as num?)?.toInt() ..recordField = _$recordConvertNullable( json['recordField'], ($jsonValue) => ( - $jsonValue[r'$1'] as int, + ($jsonValue[r'$1'] as num).toInt(), $jsonValue[r'$2'] as String, truth: $jsonValue['truth'] as bool, ), @@ -168,9 +171,11 @@ $Rec? _$recordConvertNullable<$Rec>( JsonConverterTestClass _$JsonConverterTestClassFromJson( Map<String, dynamic> json) => JsonConverterTestClass( - const DurationMillisecondConverter().fromJson(json['duration'] as int?), + const DurationMillisecondConverter() + .fromJson((json['duration'] as num?)?.toInt()), (json['durationList'] as List<dynamic>) - .map((e) => const DurationMillisecondConverter().fromJson(e as int?)) + .map((e) => const DurationMillisecondConverter() + .fromJson((e as num?)?.toInt())) .toList(), const BigIntStringConverter().fromJson(json['bigInt'] as String), (json['bigIntMap'] as Map<String, dynamic>).map( @@ -185,16 +190,20 @@ JsonConverterTestClass _$JsonConverterTestClassFromJson( _$JsonConverterFromJson<String, BigInt>( e, const BigIntStringConverter().fromJson)), ), - TrivialNumberConverter.instance.fromJson(json['numberSilly'] as int?), + TrivialNumberConverter.instance + .fromJson((json['numberSilly'] as num?)?.toInt()), (json['numberSillySet'] as List<dynamic>) - .map((e) => TrivialNumberConverter.instance.fromJson(e as int?)) + .map((e) => + TrivialNumberConverter.instance.fromJson((e as num?)?.toInt())) .toSet(), - const EpochDateTimeConverter().fromJson(json['dateTime'] as int?), + const EpochDateTimeConverter() + .fromJson((json['dateTime'] as num?)?.toInt()), trivialStringConverter.fromJson(json['trivialString'] as String?), TrivialNumberConverter.instance - .fromJson(json['nullableNumberSilly'] as int?), + .fromJson((json['nullableNumberSilly'] as num?)?.toInt()), (json['nullableNumberSillySet'] as List<dynamic>) - .map((e) => TrivialNumberConverter.instance.fromJson(e as int?)) + .map((e) => + TrivialNumberConverter.instance.fromJson((e as num?)?.toInt())) .toSet(), ); diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart index ff092269c..0115b3fff 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart @@ -9,13 +9,13 @@ part of 'kitchen_sink.g_explicit_to_json.dart'; // ************************************************************************** KitchenSink _$KitchenSinkFromJson(Map<String, dynamic> json) => KitchenSink( - ctorValidatedNo42: json['no-42'] as int?, + ctorValidatedNo42: (json['no-42'] as num?)?.toInt(), iterable: _valueAccessor(json, 'iterable') as List<dynamic>?, dynamicIterable: json['dynamicIterable'] as List<dynamic>?, objectIterable: (json['objectIterable'] as List<dynamic>?)?.map((e) => e as Object), - intIterable: - (json['intIterable'] as List<dynamic>?)?.map((e) => e as int), + intIterable: (json['intIterable'] as List<dynamic>?) + ?.map((e) => (e as num).toInt()), dateTimeIterable: (json['datetime-iterable'] as List<dynamic>?) ?.map((e) => DateTime.parse(e as String)), ) @@ -28,7 +28,9 @@ KitchenSink _$KitchenSinkFromJson(Map<String, dynamic> json) => KitchenSink( ..dynamicSet = (json['dynamicSet'] as List<dynamic>).toSet() ..objectSet = (json['objectSet'] as List<dynamic>).map((e) => e as Object).toSet() - ..intSet = (json['intSet'] as List<dynamic>).map((e) => e as int).toSet() + ..intSet = (json['intSet'] as List<dynamic>) + .map((e) => (e as num).toInt()) + .toSet() ..dateTimeSet = (json['dateTimeSet'] as List<dynamic>) .map((e) => DateTime.parse(e as String)) .toSet() @@ -36,8 +38,9 @@ KitchenSink _$KitchenSinkFromJson(Map<String, dynamic> json) => KitchenSink( ..dynamicList = json['dynamicList'] as List<dynamic> ..objectList = (json['objectList'] as List<dynamic>).map((e) => e as Object).toList() - ..intList = - (json['intList'] as List<dynamic>).map((e) => e as int).toList() + ..intList = (json['intList'] as List<dynamic>) + .map((e) => (e as num).toInt()) + .toList() ..dateTimeList = (json['dateTimeList'] as List<dynamic>) .map((e) => DateTime.parse(e as String)) .toList() @@ -85,11 +88,11 @@ KitchenSink _$KitchenSinkFromJson(Map<String, dynamic> json) => KitchenSink( SimpleObject.fromJson(json['simpleObject'] as Map<String, dynamic>) ..strictKeysObject = StrictKeysObject.fromJson( json['strictKeysObject'] as Map<String, dynamic>) - ..validatedPropertyNo42 = json['validatedPropertyNo42'] as int? + ..validatedPropertyNo42 = (json['validatedPropertyNo42'] as num?)?.toInt() ..recordField = _$recordConvertNullable( json['recordField'], ($jsonValue) => ( - $jsonValue[r'$1'] as int, + ($jsonValue[r'$1'] as num).toInt(), $jsonValue[r'$2'] as String, truth: $jsonValue['truth'] as bool, ), @@ -160,9 +163,11 @@ $Rec? _$recordConvertNullable<$Rec>( JsonConverterTestClass _$JsonConverterTestClassFromJson( Map<String, dynamic> json) => JsonConverterTestClass( - const DurationMillisecondConverter().fromJson(json['duration'] as int?), + const DurationMillisecondConverter() + .fromJson((json['duration'] as num?)?.toInt()), (json['durationList'] as List<dynamic>) - .map((e) => const DurationMillisecondConverter().fromJson(e as int?)) + .map((e) => const DurationMillisecondConverter() + .fromJson((e as num?)?.toInt())) .toList(), const BigIntStringConverter().fromJson(json['bigInt'] as String), (json['bigIntMap'] as Map<String, dynamic>).map( @@ -177,16 +182,20 @@ JsonConverterTestClass _$JsonConverterTestClassFromJson( _$JsonConverterFromJson<String, BigInt>( e, const BigIntStringConverter().fromJson)), ), - TrivialNumberConverter.instance.fromJson(json['numberSilly'] as int?), + TrivialNumberConverter.instance + .fromJson((json['numberSilly'] as num?)?.toInt()), (json['numberSillySet'] as List<dynamic>) - .map((e) => TrivialNumberConverter.instance.fromJson(e as int?)) + .map((e) => + TrivialNumberConverter.instance.fromJson((e as num?)?.toInt())) .toSet(), - const EpochDateTimeConverter().fromJson(json['dateTime'] as int?), + const EpochDateTimeConverter() + .fromJson((json['dateTime'] as num?)?.toInt()), trivialStringConverter.fromJson(json['trivialString'] as String?), TrivialNumberConverter.instance - .fromJson(json['nullableNumberSilly'] as int?), + .fromJson((json['nullableNumberSilly'] as num?)?.toInt()), (json['nullableNumberSillySet'] as List<dynamic>) - .map((e) => TrivialNumberConverter.instance.fromJson(e as int?)) + .map((e) => + TrivialNumberConverter.instance.fromJson((e as num?)?.toInt())) .toSet(), ); diff --git a/json_serializable/test/kitchen_sink/simple_object.g.dart b/json_serializable/test/kitchen_sink/simple_object.g.dart index b0bbfbef0..53442bc1b 100644 --- a/json_serializable/test/kitchen_sink/simple_object.g.dart +++ b/json_serializable/test/kitchen_sink/simple_object.g.dart @@ -9,7 +9,7 @@ part of 'simple_object.dart'; // ************************************************************************** SimpleObject _$SimpleObjectFromJson(Map json) => SimpleObject( - json['value'] as int, + (json['value'] as num).toInt(), ); Map<String, dynamic> _$SimpleObjectToJson(SimpleObject instance) => diff --git a/json_serializable/test/kitchen_sink/strict_keys_object.g.dart b/json_serializable/test/kitchen_sink/strict_keys_object.g.dart index b6b00cce3..820d237ee 100644 --- a/json_serializable/test/kitchen_sink/strict_keys_object.g.dart +++ b/json_serializable/test/kitchen_sink/strict_keys_object.g.dart @@ -15,7 +15,7 @@ StrictKeysObject _$StrictKeysObjectFromJson(Map json) { requiredKeys: const ['value', 'custom_field'], ); return StrictKeysObject( - json['value'] as int, + (json['value'] as num).toInt(), json['custom_field'] as String, ); } diff --git a/json_serializable/test/src/_json_serializable_test_input.dart b/json_serializable/test/src/_json_serializable_test_input.dart index af82c8440..1458630ff 100644 --- a/json_serializable/test/src/_json_serializable_test_input.dart +++ b/json_serializable/test/src/_json_serializable_test_input.dart @@ -55,12 +55,13 @@ GeneralTestClass1 _$GeneralTestClass1FromJson(Map<String, dynamic> json) => GeneralTestClass1() ..firstName = json['firstName'] as String ..lastName = json['lastName'] as String - ..height = json['h'] as int + ..height = (json['h'] as num).toInt() ..dateOfBirth = DateTime.parse(json['dateOfBirth'] as String) ..dynamicType = json['dynamicType'] ..varType = json['varType'] - ..listOfInts = - (json['listOfInts'] as List<dynamic>).map((e) => e as int).toList(); + ..listOfInts = (json['listOfInts'] as List<dynamic>) + .map((e) => (e as num).toInt()) + .toList(); Map<String, dynamic> _$GeneralTestClass1ToJson(GeneralTestClass1 instance) => <String, dynamic>{ @@ -89,7 +90,7 @@ class GeneralTestClass1 { @ShouldGenerate(r''' GeneralTestClass2 _$GeneralTestClass2FromJson(Map<String, dynamic> json) => GeneralTestClass2( - json['height'] as int, + (json['height'] as num).toInt(), json['firstName'] as String, json['lastName'] as String?, )..dateOfBirth = DateTime.parse(json['dateOfBirth'] as String); @@ -117,7 +118,7 @@ class GeneralTestClass2 { @ShouldGenerate(r''' FinalFields _$FinalFieldsFromJson(Map<String, dynamic> json) => FinalFields( - json['a'] as int, + (json['a'] as num).toInt(), ); Map<String, dynamic> _$FinalFieldsToJson(FinalFields instance) => @@ -154,7 +155,7 @@ class FinalFieldsNotSetInCtor { @ShouldGenerate(r''' SetSupport _$SetSupportFromJson(Map<String, dynamic> json) => SetSupport( - (json['values'] as List<dynamic>).map((e) => e as int).toSet(), + (json['values'] as List<dynamic>).map((e) => (e as num).toInt()).toSet(), ); Map<String, dynamic> _$SetSupportToJson(SetSupport instance) => @@ -455,8 +456,8 @@ mixin _PropInMixinI448RegressionMixin { PropInMixinI448Regression _$PropInMixinI448RegressionFromJson( Map<String, dynamic> json) => PropInMixinI448Regression() - ..nullable = json['nullable'] as int - ..notNullable = json['notNullable'] as int; + ..nullable = (json['nullable'] as num).toInt() + ..notNullable = (json['notNullable'] as num).toInt(); Map<String, dynamic> _$PropInMixinI448RegressionToJson( PropInMixinI448Regression instance) => @@ -474,7 +475,7 @@ class PropInMixinI448Regression with _PropInMixinI448RegressionMixin { @ShouldGenerate( r''' IgnoreUnannotated _$IgnoreUnannotatedFromJson(Map<String, dynamic> json) => - IgnoreUnannotated()..annotated = json['annotated'] as int; + IgnoreUnannotated()..annotated = (json['annotated'] as num).toInt(); Map<String, dynamic> _$IgnoreUnannotatedToJson(IgnoreUnannotated instance) => <String, dynamic>{ @@ -493,7 +494,7 @@ class IgnoreUnannotated { @ShouldGenerate( r''' SubclassedJsonKey _$SubclassedJsonKeyFromJson(Map<String, dynamic> json) => - SubclassedJsonKey()..annotatedWithSubclass = json['bob'] as int; + SubclassedJsonKey()..annotatedWithSubclass = (json['bob'] as num).toInt(); Map<String, dynamic> _$SubclassedJsonKeyToJson(SubclassedJsonKey instance) => <String, dynamic>{ diff --git a/json_serializable/test/src/default_value_input.dart b/json_serializable/test/src/default_value_input.dart index a594aa761..7bdd1a35b 100644 --- a/json_serializable/test/src/default_value_input.dart +++ b/json_serializable/test/src/default_value_input.dart @@ -137,7 +137,7 @@ DefaultWithDisallowNullRequiredClass disallowNullValues: const ['theField'], ); return DefaultWithDisallowNullRequiredClass() - ..theField = json['theField'] as int? ?? 7; + ..theField = (json['theField'] as num?)?.toInt() ?? 7; } ''', expectedLogItems: [ @@ -159,7 +159,7 @@ CtorDefaultValueAndJsonKeyDefaultValue _$CtorDefaultValueAndJsonKeyDefaultValueFromJson( Map<String, dynamic> json) => CtorDefaultValueAndJsonKeyDefaultValue( - json['theField'] as int? ?? 7, + (json['theField'] as num?)?.toInt() ?? 7, ); ''', expectedLogItems: [ @@ -181,7 +181,7 @@ class CtorDefaultValueAndJsonKeyDefaultValue { SameCtorAndJsonKeyDefaultValue _$SameCtorAndJsonKeyDefaultValueFromJson( Map<String, dynamic> json) => SameCtorAndJsonKeyDefaultValue( - json['theField'] as int? ?? 3, + (json['theField'] as num?)?.toInt() ?? 3, ); ''', expectedLogItems: [ diff --git a/json_serializable/test/src/inheritance_test_input.dart b/json_serializable/test/src/inheritance_test_input.dart index afd6a6552..875743fc7 100644 --- a/json_serializable/test/src/inheritance_test_input.dart +++ b/json_serializable/test/src/inheritance_test_input.dart @@ -2,11 +2,11 @@ part of '_json_serializable_test_input.dart'; @ShouldGenerate(r''' SubType _$SubTypeFromJson(Map<String, dynamic> json) => SubType( - json['subTypeViaCtor'] as int, - json['super-final-field'] as int, + (json['subTypeViaCtor'] as num).toInt(), + (json['super-final-field'] as num).toInt(), ) - ..superReadWriteField = json['superReadWriteField'] as int? - ..subTypeReadWrite = json['subTypeReadWrite'] as int; + ..superReadWriteField = (json['superReadWriteField'] as num?)?.toInt() + ..subTypeReadWrite = (json['subTypeReadWrite'] as num).toInt(); Map<String, dynamic> _$SubTypeToJson(SubType instance) { final val = <String, dynamic>{ diff --git a/json_serializable/test/src/json_converter_test_input.dart b/json_serializable/test/src/json_converter_test_input.dart index 865ee06a6..5f4075b82 100644 --- a/json_serializable/test/src/json_converter_test_input.dart +++ b/json_serializable/test/src/json_converter_test_input.dart @@ -11,11 +11,11 @@ JsonConverterNamedCtor<E> _$JsonConverterNamedCtorFromJson<E>( Map<String, dynamic> json) => JsonConverterNamedCtor<E>() ..value = const _DurationMillisecondConverter.named() - .fromJson(json['value'] as int) - ..genericValue = - _GenericConverter<E>.named().fromJson(json['genericValue'] as int) - ..keyAnnotationFirst = - JsonConverterNamedCtor._fromJson(json['keyAnnotationFirst'] as int); + .fromJson((json['value'] as num).toInt()) + ..genericValue = _GenericConverter<E>.named() + .fromJson((json['genericValue'] as num).toInt()) + ..keyAnnotationFirst = JsonConverterNamedCtor._fromJson( + (json['keyAnnotationFirst'] as num).toInt()); Map<String, dynamic> _$JsonConverterNamedCtorToJson<E>( JsonConverterNamedCtor<E> instance) => @@ -49,13 +49,13 @@ JsonConvertOnField<E> _$JsonConvertOnFieldFromJson<E>( Map<String, dynamic> json) => JsonConvertOnField<E>() ..annotatedField = const _DurationMillisecondConverter() - .fromJson(json['annotatedField'] as int) + .fromJson((json['annotatedField'] as num).toInt()) ..annotatedWithNamedCtor = const _DurationMillisecondConverter.named() - .fromJson(json['annotatedWithNamedCtor'] as int) - ..classAnnotatedWithField = - _durationConverter.fromJson(json['classAnnotatedWithField'] as int) - ..genericValue = - _GenericConverter<E>().fromJson(json['genericValue'] as int); + .fromJson((json['annotatedWithNamedCtor'] as num).toInt()) + ..classAnnotatedWithField = _durationConverter + .fromJson((json['classAnnotatedWithField'] as num).toInt()) + ..genericValue = _GenericConverter<E>() + .fromJson((json['genericValue'] as num).toInt()); Map<String, dynamic> _$JsonConvertOnFieldToJson<E>( JsonConvertOnField<E> instance) => diff --git a/json_serializable/test/src/map_key_variety_test_input.dart b/json_serializable/test/src/map_key_variety_test_input.dart index 861512f18..2f07cf703 100644 --- a/json_serializable/test/src/map_key_variety_test_input.dart +++ b/json_serializable/test/src/map_key_variety_test_input.dart @@ -4,7 +4,7 @@ part of '_json_serializable_test_input.dart'; MapKeyVariety _$MapKeyVarietyFromJson(Map<String, dynamic> json) => MapKeyVariety() ..intIntMap = (json['intIntMap'] as Map<String, dynamic>).map( - (k, e) => MapEntry(int.parse(k), e as int), + (k, e) => MapEntry(int.parse(k), (e as num).toInt()), ); Map<String, dynamic> _$MapKeyVarietyToJson(MapKeyVariety instance) => diff --git a/json_serializable/test/src/to_from_json_test_input.dart b/json_serializable/test/src/to_from_json_test_input.dart index 11ce9f447..7e5f57965 100644 --- a/json_serializable/test/src/to_from_json_test_input.dart +++ b/json_serializable/test/src/to_from_json_test_input.dart @@ -122,7 +122,7 @@ class Reproduce869NullableGenericTypeWithDefault { } List<int>? _fromList(List? pairs) => - pairs?.map((it) => it as int).toList(growable: false); + pairs?.map((it) => (it as num).toInt()).toList(growable: false); List<List>? _toList(List<int>? pairs) => pairs?.map((it) => [it]).toList(growable: false); diff --git a/json_serializable/test/supported_types/enum_type.dart b/json_serializable/test/supported_types/enum_type.dart index 6e31deaf2..91750dd6b 100644 --- a/json_serializable/test/supported_types/enum_type.dart +++ b/json_serializable/test/supported_types/enum_type.dart @@ -10,7 +10,7 @@ class FromJsonDynamicParam { final int value; factory FromJsonDynamicParam.fromJson(dynamic json) => - FromJsonDynamicParam(value: json as int); + FromJsonDynamicParam(value: (json as num).toInt()); dynamic toJson() => null; } @@ -21,7 +21,7 @@ class FromJsonNullableObjectParam { final int value; factory FromJsonNullableObjectParam.fromJson(Object? json) => - FromJsonNullableObjectParam(value: json as int); + FromJsonNullableObjectParam(value: (json as num).toInt()); Object? toJson() => null; } @@ -32,7 +32,7 @@ class FromJsonObjectParam { final int value; factory FromJsonObjectParam.fromJson(Object json) => - FromJsonObjectParam(value: json as int); + FromJsonObjectParam(value: (json as num).toInt()); dynamic toJson() => null; } diff --git a/json_serializable/test/supported_types/input.type_duration.g.dart b/json_serializable/test/supported_types/input.type_duration.g.dart index 7ea4c7da6..9d57d843c 100644 --- a/json_serializable/test/supported_types/input.type_duration.g.dart +++ b/json_serializable/test/supported_types/input.type_duration.g.dart @@ -9,7 +9,7 @@ part of 'input.type_duration.dart'; // ************************************************************************** SimpleClass _$SimpleClassFromJson(Map<String, dynamic> json) => SimpleClass( - Duration(microseconds: json['value'] as int), + Duration(microseconds: (json['value'] as num).toInt()), ); Map<String, dynamic> _$SimpleClassToJson(SimpleClass instance) => @@ -21,7 +21,7 @@ SimpleClassNullable _$SimpleClassNullableFromJson(Map<String, dynamic> json) => SimpleClassNullable( json['value'] == null ? null - : Duration(microseconds: json['value'] as int), + : Duration(microseconds: (json['value'] as num).toInt()), ); Map<String, dynamic> _$SimpleClassNullableToJson( diff --git a/json_serializable/test/supported_types/input.type_int.g.dart b/json_serializable/test/supported_types/input.type_int.g.dart index ddb06ed57..2f248b74a 100644 --- a/json_serializable/test/supported_types/input.type_int.g.dart +++ b/json_serializable/test/supported_types/input.type_int.g.dart @@ -9,8 +9,8 @@ part of 'input.type_int.dart'; // ************************************************************************** SimpleClass _$SimpleClassFromJson(Map<String, dynamic> json) => SimpleClass( - json['value'] as int, - json['withDefault'] as int? ?? 42, + (json['value'] as num).toInt(), + (json['withDefault'] as num?)?.toInt() ?? 42, ); Map<String, dynamic> _$SimpleClassToJson(SimpleClass instance) => @@ -21,8 +21,8 @@ Map<String, dynamic> _$SimpleClassToJson(SimpleClass instance) => SimpleClassNullable _$SimpleClassNullableFromJson(Map<String, dynamic> json) => SimpleClassNullable( - json['value'] as int?, - json['withDefault'] as int? ?? 42, + (json['value'] as num?)?.toInt(), + (json['withDefault'] as num?)?.toInt() ?? 42, ); Map<String, dynamic> _$SimpleClassNullableToJson( diff --git a/json_serializable/test/supported_types/input.type_iterable.g.dart b/json_serializable/test/supported_types/input.type_iterable.g.dart index 95c3e0557..a9264f393 100644 --- a/json_serializable/test/supported_types/input.type_iterable.g.dart +++ b/json_serializable/test/supported_types/input.type_iterable.g.dart @@ -231,7 +231,7 @@ SimpleClassOfDuration _$SimpleClassOfDurationFromJson( Map<String, dynamic> json) => SimpleClassOfDuration( (json['value'] as List<dynamic>) - .map((e) => Duration(microseconds: e as int)), + .map((e) => Duration(microseconds: (e as num).toInt())), ); Map<String, dynamic> _$SimpleClassOfDurationToJson( @@ -244,7 +244,7 @@ SimpleClassNullableOfDuration _$SimpleClassNullableOfDurationFromJson( Map<String, dynamic> json) => SimpleClassNullableOfDuration( (json['value'] as List<dynamic>?) - ?.map((e) => Duration(microseconds: e as int)), + ?.map((e) => Duration(microseconds: (e as num).toInt())), ); Map<String, dynamic> _$SimpleClassNullableOfDurationToJson( @@ -256,8 +256,8 @@ Map<String, dynamic> _$SimpleClassNullableOfDurationToJson( SimpleClassOfDurationNullable _$SimpleClassOfDurationNullableFromJson( Map<String, dynamic> json) => SimpleClassOfDurationNullable( - (json['value'] as List<dynamic>) - .map((e) => e == null ? null : Duration(microseconds: e as int)), + (json['value'] as List<dynamic>).map( + (e) => e == null ? null : Duration(microseconds: (e as num).toInt())), ); Map<String, dynamic> _$SimpleClassOfDurationNullableToJson( @@ -270,8 +270,8 @@ SimpleClassNullableOfDurationNullable _$SimpleClassNullableOfDurationNullableFromJson( Map<String, dynamic> json) => SimpleClassNullableOfDurationNullable( - (json['value'] as List<dynamic>?) - ?.map((e) => e == null ? null : Duration(microseconds: e as int)), + (json['value'] as List<dynamic>?)?.map((e) => + e == null ? null : Duration(microseconds: (e as num).toInt())), ); Map<String, dynamic> _$SimpleClassNullableOfDurationNullableToJson( @@ -446,7 +446,7 @@ Map<String, dynamic> _$SimpleClassNullableOfFromJsonObjectParamToJson( SimpleClassOfInt _$SimpleClassOfIntFromJson(Map<String, dynamic> json) => SimpleClassOfInt( - (json['value'] as List<dynamic>).map((e) => e as int), + (json['value'] as List<dynamic>).map((e) => (e as num).toInt()), ); Map<String, dynamic> _$SimpleClassOfIntToJson(SimpleClassOfInt instance) => @@ -457,7 +457,7 @@ Map<String, dynamic> _$SimpleClassOfIntToJson(SimpleClassOfInt instance) => SimpleClassNullableOfInt _$SimpleClassNullableOfIntFromJson( Map<String, dynamic> json) => SimpleClassNullableOfInt( - (json['value'] as List<dynamic>?)?.map((e) => e as int), + (json['value'] as List<dynamic>?)?.map((e) => (e as num).toInt()), ); Map<String, dynamic> _$SimpleClassNullableOfIntToJson( @@ -469,7 +469,7 @@ Map<String, dynamic> _$SimpleClassNullableOfIntToJson( SimpleClassOfIntNullable _$SimpleClassOfIntNullableFromJson( Map<String, dynamic> json) => SimpleClassOfIntNullable( - (json['value'] as List<dynamic>).map((e) => e as int?), + (json['value'] as List<dynamic>).map((e) => (e as num?)?.toInt()), ); Map<String, dynamic> _$SimpleClassOfIntNullableToJson( @@ -481,7 +481,7 @@ Map<String, dynamic> _$SimpleClassOfIntNullableToJson( SimpleClassNullableOfIntNullable _$SimpleClassNullableOfIntNullableFromJson( Map<String, dynamic> json) => SimpleClassNullableOfIntNullable( - (json['value'] as List<dynamic>?)?.map((e) => e as int?), + (json['value'] as List<dynamic>?)?.map((e) => (e as num?)?.toInt()), ); Map<String, dynamic> _$SimpleClassNullableOfIntNullableToJson( @@ -588,7 +588,7 @@ SimpleClassOfRecord _$SimpleClassOfRecordFromJson(Map<String, dynamic> json) => (json['value'] as List<dynamic>).map((e) => _$recordConvert( e, ($jsonValue) => ( - $jsonValue[r'$1'] as int, + ($jsonValue[r'$1'] as num).toInt(), $jsonValue[r'$2'] as String, truth: $jsonValue['truth'] as bool, ), @@ -619,7 +619,7 @@ SimpleClassNullableOfRecord _$SimpleClassNullableOfRecordFromJson( (json['value'] as List<dynamic>?)?.map((e) => _$recordConvert( e, ($jsonValue) => ( - $jsonValue[r'$1'] as int, + ($jsonValue[r'$1'] as num).toInt(), $jsonValue[r'$2'] as String, truth: $jsonValue['truth'] as bool, ), diff --git a/json_serializable/test/supported_types/input.type_list.g.dart b/json_serializable/test/supported_types/input.type_list.g.dart index 2f4497581..f86a6d00c 100644 --- a/json_serializable/test/supported_types/input.type_list.g.dart +++ b/json_serializable/test/supported_types/input.type_list.g.dart @@ -249,7 +249,7 @@ SimpleClassOfDuration _$SimpleClassOfDurationFromJson( Map<String, dynamic> json) => SimpleClassOfDuration( (json['value'] as List<dynamic>) - .map((e) => Duration(microseconds: e as int)) + .map((e) => Duration(microseconds: (e as num).toInt())) .toList(), ); @@ -263,7 +263,7 @@ SimpleClassNullableOfDuration _$SimpleClassNullableOfDurationFromJson( Map<String, dynamic> json) => SimpleClassNullableOfDuration( (json['value'] as List<dynamic>?) - ?.map((e) => Duration(microseconds: e as int)) + ?.map((e) => Duration(microseconds: (e as num).toInt())) .toList(), ); @@ -277,7 +277,8 @@ SimpleClassOfDurationNullable _$SimpleClassOfDurationNullableFromJson( Map<String, dynamic> json) => SimpleClassOfDurationNullable( (json['value'] as List<dynamic>) - .map((e) => e == null ? null : Duration(microseconds: e as int)) + .map((e) => + e == null ? null : Duration(microseconds: (e as num).toInt())) .toList(), ); @@ -292,7 +293,8 @@ SimpleClassNullableOfDurationNullable Map<String, dynamic> json) => SimpleClassNullableOfDurationNullable( (json['value'] as List<dynamic>?) - ?.map((e) => e == null ? null : Duration(microseconds: e as int)) + ?.map((e) => + e == null ? null : Duration(microseconds: (e as num).toInt())) .toList(), ); @@ -480,7 +482,7 @@ Map<String, dynamic> _$SimpleClassNullableOfFromJsonObjectParamToJson( SimpleClassOfInt _$SimpleClassOfIntFromJson(Map<String, dynamic> json) => SimpleClassOfInt( - (json['value'] as List<dynamic>).map((e) => e as int).toList(), + (json['value'] as List<dynamic>).map((e) => (e as num).toInt()).toList(), ); Map<String, dynamic> _$SimpleClassOfIntToJson(SimpleClassOfInt instance) => @@ -491,7 +493,9 @@ Map<String, dynamic> _$SimpleClassOfIntToJson(SimpleClassOfInt instance) => SimpleClassNullableOfInt _$SimpleClassNullableOfIntFromJson( Map<String, dynamic> json) => SimpleClassNullableOfInt( - (json['value'] as List<dynamic>?)?.map((e) => e as int).toList(), + (json['value'] as List<dynamic>?) + ?.map((e) => (e as num).toInt()) + .toList(), ); Map<String, dynamic> _$SimpleClassNullableOfIntToJson( @@ -503,7 +507,9 @@ Map<String, dynamic> _$SimpleClassNullableOfIntToJson( SimpleClassOfIntNullable _$SimpleClassOfIntNullableFromJson( Map<String, dynamic> json) => SimpleClassOfIntNullable( - (json['value'] as List<dynamic>).map((e) => e as int?).toList(), + (json['value'] as List<dynamic>) + .map((e) => (e as num?)?.toInt()) + .toList(), ); Map<String, dynamic> _$SimpleClassOfIntNullableToJson( @@ -515,7 +521,9 @@ Map<String, dynamic> _$SimpleClassOfIntNullableToJson( SimpleClassNullableOfIntNullable _$SimpleClassNullableOfIntNullableFromJson( Map<String, dynamic> json) => SimpleClassNullableOfIntNullable( - (json['value'] as List<dynamic>?)?.map((e) => e as int?).toList(), + (json['value'] as List<dynamic>?) + ?.map((e) => (e as num?)?.toInt()) + .toList(), ); Map<String, dynamic> _$SimpleClassNullableOfIntNullableToJson( @@ -623,7 +631,7 @@ SimpleClassOfRecord _$SimpleClassOfRecordFromJson(Map<String, dynamic> json) => .map((e) => _$recordConvert( e, ($jsonValue) => ( - $jsonValue[r'$1'] as int, + ($jsonValue[r'$1'] as num).toInt(), $jsonValue[r'$2'] as String, truth: $jsonValue['truth'] as bool, ), @@ -656,7 +664,7 @@ SimpleClassNullableOfRecord _$SimpleClassNullableOfRecordFromJson( ?.map((e) => _$recordConvert( e, ($jsonValue) => ( - $jsonValue[r'$1'] as int, + ($jsonValue[r'$1'] as num).toInt(), $jsonValue[r'$2'] as String, truth: $jsonValue['truth'] as bool, ), diff --git a/json_serializable/test/supported_types/input.type_map.g.dart b/json_serializable/test/supported_types/input.type_map.g.dart index 5f29d60ab..5c8a3ea82 100644 --- a/json_serializable/test/supported_types/input.type_map.g.dart +++ b/json_serializable/test/supported_types/input.type_map.g.dart @@ -1953,7 +1953,8 @@ SimpleClassOfBigIntToDuration _$SimpleClassOfBigIntToDurationFromJson( Map<String, dynamic> json) => SimpleClassOfBigIntToDuration( (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(BigInt.parse(k), Duration(microseconds: e as int)), + (k, e) => MapEntry( + BigInt.parse(k), Duration(microseconds: (e as num).toInt())), ), ); @@ -1969,8 +1970,8 @@ SimpleClassNullableOfBigIntToDuration Map<String, dynamic> json) => SimpleClassNullableOfBigIntToDuration( (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => - MapEntry(BigInt.parse(k), Duration(microseconds: e as int)), + (k, e) => MapEntry( + BigInt.parse(k), Duration(microseconds: (e as num).toInt())), ), ); @@ -1985,7 +1986,8 @@ SimpleClassOfDateTimeToDuration _$SimpleClassOfDateTimeToDurationFromJson( Map<String, dynamic> json) => SimpleClassOfDateTimeToDuration( (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(DateTime.parse(k), Duration(microseconds: e as int)), + (k, e) => MapEntry( + DateTime.parse(k), Duration(microseconds: (e as num).toInt())), ), ); @@ -2001,8 +2003,8 @@ SimpleClassNullableOfDateTimeToDuration Map<String, dynamic> json) => SimpleClassNullableOfDateTimeToDuration( (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => - MapEntry(DateTime.parse(k), Duration(microseconds: e as int)), + (k, e) => MapEntry( + DateTime.parse(k), Duration(microseconds: (e as num).toInt())), ), ); @@ -2017,7 +2019,7 @@ SimpleClassOfDynamicToDuration _$SimpleClassOfDynamicToDurationFromJson( Map<String, dynamic> json) => SimpleClassOfDynamicToDuration( (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(k, Duration(microseconds: e as int)), + (k, e) => MapEntry(k, Duration(microseconds: (e as num).toInt())), ), ); @@ -2032,7 +2034,7 @@ SimpleClassNullableOfDynamicToDuration Map<String, dynamic> json) => SimpleClassNullableOfDynamicToDuration( (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, Duration(microseconds: e as int)), + (k, e) => MapEntry(k, Duration(microseconds: (e as num).toInt())), ), ); @@ -2047,7 +2049,7 @@ SimpleClassOfEnumTypeToDuration _$SimpleClassOfEnumTypeToDurationFromJson( SimpleClassOfEnumTypeToDuration( (json['value'] as Map<String, dynamic>).map( (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), - Duration(microseconds: e as int)), + Duration(microseconds: (e as num).toInt())), ), ); @@ -2064,7 +2066,7 @@ SimpleClassNullableOfEnumTypeToDuration SimpleClassNullableOfEnumTypeToDuration( (json['value'] as Map<String, dynamic>?)?.map( (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), - Duration(microseconds: e as int)), + Duration(microseconds: (e as num).toInt())), ), ); @@ -2079,7 +2081,8 @@ SimpleClassOfIntToDuration _$SimpleClassOfIntToDurationFromJson( Map<String, dynamic> json) => SimpleClassOfIntToDuration( (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(int.parse(k), Duration(microseconds: e as int)), + (k, e) => + MapEntry(int.parse(k), Duration(microseconds: (e as num).toInt())), ), ); @@ -2094,7 +2097,8 @@ SimpleClassNullableOfIntToDuration _$SimpleClassNullableOfIntToDurationFromJson( Map<String, dynamic> json) => SimpleClassNullableOfIntToDuration( (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(int.parse(k), Duration(microseconds: e as int)), + (k, e) => + MapEntry(int.parse(k), Duration(microseconds: (e as num).toInt())), ), ); @@ -2109,7 +2113,7 @@ SimpleClassOfObjectToDuration _$SimpleClassOfObjectToDurationFromJson( Map<String, dynamic> json) => SimpleClassOfObjectToDuration( (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(k, Duration(microseconds: e as int)), + (k, e) => MapEntry(k, Duration(microseconds: (e as num).toInt())), ), ); @@ -2124,7 +2128,7 @@ SimpleClassNullableOfObjectToDuration Map<String, dynamic> json) => SimpleClassNullableOfObjectToDuration( (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, Duration(microseconds: e as int)), + (k, e) => MapEntry(k, Duration(microseconds: (e as num).toInt())), ), ); @@ -2138,7 +2142,7 @@ SimpleClassOfStringToDuration _$SimpleClassOfStringToDurationFromJson( Map<String, dynamic> json) => SimpleClassOfStringToDuration( (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(k, Duration(microseconds: e as int)), + (k, e) => MapEntry(k, Duration(microseconds: (e as num).toInt())), ), ); @@ -2153,7 +2157,7 @@ SimpleClassNullableOfStringToDuration Map<String, dynamic> json) => SimpleClassNullableOfStringToDuration( (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, Duration(microseconds: e as int)), + (k, e) => MapEntry(k, Duration(microseconds: (e as num).toInt())), ), ); @@ -2167,7 +2171,8 @@ SimpleClassOfUriToDuration _$SimpleClassOfUriToDurationFromJson( Map<String, dynamic> json) => SimpleClassOfUriToDuration( (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(Uri.parse(k), Duration(microseconds: e as int)), + (k, e) => + MapEntry(Uri.parse(k), Duration(microseconds: (e as num).toInt())), ), ); @@ -2182,7 +2187,8 @@ SimpleClassNullableOfUriToDuration _$SimpleClassNullableOfUriToDurationFromJson( Map<String, dynamic> json) => SimpleClassNullableOfUriToDuration( (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(Uri.parse(k), Duration(microseconds: e as int)), + (k, e) => + MapEntry(Uri.parse(k), Duration(microseconds: (e as num).toInt())), ), ); @@ -2199,7 +2205,7 @@ SimpleClassOfBigIntToDurationNullable SimpleClassOfBigIntToDurationNullable( (json['value'] as Map<String, dynamic>).map( (k, e) => MapEntry(BigInt.parse(k), - e == null ? null : Duration(microseconds: e as int)), + e == null ? null : Duration(microseconds: (e as num).toInt())), ), ); @@ -2216,7 +2222,7 @@ SimpleClassNullableOfBigIntToDurationNullable SimpleClassNullableOfBigIntToDurationNullable( (json['value'] as Map<String, dynamic>?)?.map( (k, e) => MapEntry(BigInt.parse(k), - e == null ? null : Duration(microseconds: e as int)), + e == null ? null : Duration(microseconds: (e as num).toInt())), ), ); @@ -2233,7 +2239,7 @@ SimpleClassOfDateTimeToDurationNullable SimpleClassOfDateTimeToDurationNullable( (json['value'] as Map<String, dynamic>).map( (k, e) => MapEntry(DateTime.parse(k), - e == null ? null : Duration(microseconds: e as int)), + e == null ? null : Duration(microseconds: (e as num).toInt())), ), ); @@ -2250,7 +2256,7 @@ SimpleClassNullableOfDateTimeToDurationNullable SimpleClassNullableOfDateTimeToDurationNullable( (json['value'] as Map<String, dynamic>?)?.map( (k, e) => MapEntry(DateTime.parse(k), - e == null ? null : Duration(microseconds: e as int)), + e == null ? null : Duration(microseconds: (e as num).toInt())), ), ); @@ -2266,8 +2272,8 @@ SimpleClassOfDynamicToDurationNullable Map<String, dynamic> json) => SimpleClassOfDynamicToDurationNullable( (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry( - k, e == null ? null : Duration(microseconds: e as int)), + (k, e) => MapEntry(k, + e == null ? null : Duration(microseconds: (e as num).toInt())), ), ); @@ -2282,8 +2288,8 @@ SimpleClassNullableOfDynamicToDurationNullable Map<String, dynamic> json) => SimpleClassNullableOfDynamicToDurationNullable( (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry( - k, e == null ? null : Duration(microseconds: e as int)), + (k, e) => MapEntry(k, + e == null ? null : Duration(microseconds: (e as num).toInt())), ), ); @@ -2299,7 +2305,7 @@ SimpleClassOfEnumTypeToDurationNullable SimpleClassOfEnumTypeToDurationNullable( (json['value'] as Map<String, dynamic>).map( (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), - e == null ? null : Duration(microseconds: e as int)), + e == null ? null : Duration(microseconds: (e as num).toInt())), ), ); @@ -2316,7 +2322,7 @@ SimpleClassNullableOfEnumTypeToDurationNullable SimpleClassNullableOfEnumTypeToDurationNullable( (json['value'] as Map<String, dynamic>?)?.map( (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), - e == null ? null : Duration(microseconds: e as int)), + e == null ? null : Duration(microseconds: (e as num).toInt())), ), ); @@ -2331,8 +2337,8 @@ SimpleClassOfIntToDurationNullable _$SimpleClassOfIntToDurationNullableFromJson( Map<String, dynamic> json) => SimpleClassOfIntToDurationNullable( (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry( - int.parse(k), e == null ? null : Duration(microseconds: e as int)), + (k, e) => MapEntry(int.parse(k), + e == null ? null : Duration(microseconds: (e as num).toInt())), ), ); @@ -2349,7 +2355,7 @@ SimpleClassNullableOfIntToDurationNullable SimpleClassNullableOfIntToDurationNullable( (json['value'] as Map<String, dynamic>?)?.map( (k, e) => MapEntry(int.parse(k), - e == null ? null : Duration(microseconds: e as int)), + e == null ? null : Duration(microseconds: (e as num).toInt())), ), ); @@ -2365,8 +2371,8 @@ SimpleClassOfObjectToDurationNullable Map<String, dynamic> json) => SimpleClassOfObjectToDurationNullable( (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry( - k, e == null ? null : Duration(microseconds: e as int)), + (k, e) => MapEntry(k, + e == null ? null : Duration(microseconds: (e as num).toInt())), ), ); @@ -2381,8 +2387,8 @@ SimpleClassNullableOfObjectToDurationNullable Map<String, dynamic> json) => SimpleClassNullableOfObjectToDurationNullable( (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry( - k, e == null ? null : Duration(microseconds: e as int)), + (k, e) => MapEntry(k, + e == null ? null : Duration(microseconds: (e as num).toInt())), ), ); @@ -2397,8 +2403,8 @@ SimpleClassOfStringToDurationNullable Map<String, dynamic> json) => SimpleClassOfStringToDurationNullable( (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry( - k, e == null ? null : Duration(microseconds: e as int)), + (k, e) => MapEntry(k, + e == null ? null : Duration(microseconds: (e as num).toInt())), ), ); @@ -2413,8 +2419,8 @@ SimpleClassNullableOfStringToDurationNullable Map<String, dynamic> json) => SimpleClassNullableOfStringToDurationNullable( (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry( - k, e == null ? null : Duration(microseconds: e as int)), + (k, e) => MapEntry(k, + e == null ? null : Duration(microseconds: (e as num).toInt())), ), ); @@ -2428,8 +2434,8 @@ SimpleClassOfUriToDurationNullable _$SimpleClassOfUriToDurationNullableFromJson( Map<String, dynamic> json) => SimpleClassOfUriToDurationNullable( (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry( - Uri.parse(k), e == null ? null : Duration(microseconds: e as int)), + (k, e) => MapEntry(Uri.parse(k), + e == null ? null : Duration(microseconds: (e as num).toInt())), ), ); @@ -2446,7 +2452,7 @@ SimpleClassNullableOfUriToDurationNullable SimpleClassNullableOfUriToDurationNullable( (json['value'] as Map<String, dynamic>?)?.map( (k, e) => MapEntry(Uri.parse(k), - e == null ? null : Duration(microseconds: e as int)), + e == null ? null : Duration(microseconds: (e as num).toInt())), ), ); @@ -3943,7 +3949,7 @@ SimpleClassOfBigIntToInt _$SimpleClassOfBigIntToIntFromJson( Map<String, dynamic> json) => SimpleClassOfBigIntToInt( (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(BigInt.parse(k), e as int), + (k, e) => MapEntry(BigInt.parse(k), (e as num).toInt()), ), ); @@ -3957,7 +3963,7 @@ SimpleClassNullableOfBigIntToInt _$SimpleClassNullableOfBigIntToIntFromJson( Map<String, dynamic> json) => SimpleClassNullableOfBigIntToInt( (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(BigInt.parse(k), e as int), + (k, e) => MapEntry(BigInt.parse(k), (e as num).toInt()), ), ); @@ -3971,7 +3977,7 @@ SimpleClassOfDateTimeToInt _$SimpleClassOfDateTimeToIntFromJson( Map<String, dynamic> json) => SimpleClassOfDateTimeToInt( (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(DateTime.parse(k), e as int), + (k, e) => MapEntry(DateTime.parse(k), (e as num).toInt()), ), ); @@ -3985,7 +3991,7 @@ SimpleClassNullableOfDateTimeToInt _$SimpleClassNullableOfDateTimeToIntFromJson( Map<String, dynamic> json) => SimpleClassNullableOfDateTimeToInt( (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(DateTime.parse(k), e as int), + (k, e) => MapEntry(DateTime.parse(k), (e as num).toInt()), ), ); @@ -4011,7 +4017,7 @@ SimpleClassNullableOfDynamicToInt _$SimpleClassNullableOfDynamicToIntFromJson( Map<String, dynamic> json) => SimpleClassNullableOfDynamicToInt( (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, e as int), + (k, e) => MapEntry(k, (e as num).toInt()), ), ); @@ -4025,7 +4031,8 @@ SimpleClassOfEnumTypeToInt _$SimpleClassOfEnumTypeToIntFromJson( Map<String, dynamic> json) => SimpleClassOfEnumTypeToInt( (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e as int), + (k, e) => + MapEntry($enumDecode(_$EnumTypeEnumMap, k), (e as num).toInt()), ), ); @@ -4039,7 +4046,8 @@ SimpleClassNullableOfEnumTypeToInt _$SimpleClassNullableOfEnumTypeToIntFromJson( Map<String, dynamic> json) => SimpleClassNullableOfEnumTypeToInt( (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e as int), + (k, e) => + MapEntry($enumDecode(_$EnumTypeEnumMap, k), (e as num).toInt()), ), ); @@ -4054,7 +4062,7 @@ SimpleClassOfIntToInt _$SimpleClassOfIntToIntFromJson( Map<String, dynamic> json) => SimpleClassOfIntToInt( (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(int.parse(k), e as int), + (k, e) => MapEntry(int.parse(k), (e as num).toInt()), ), ); @@ -4068,7 +4076,7 @@ SimpleClassNullableOfIntToInt _$SimpleClassNullableOfIntToIntFromJson( Map<String, dynamic> json) => SimpleClassNullableOfIntToInt( (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(int.parse(k), e as int), + (k, e) => MapEntry(int.parse(k), (e as num).toInt()), ), ); @@ -4094,7 +4102,7 @@ SimpleClassNullableOfObjectToInt _$SimpleClassNullableOfObjectToIntFromJson( Map<String, dynamic> json) => SimpleClassNullableOfObjectToInt( (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, e as int), + (k, e) => MapEntry(k, (e as num).toInt()), ), ); @@ -4120,7 +4128,7 @@ SimpleClassNullableOfStringToInt _$SimpleClassNullableOfStringToIntFromJson( Map<String, dynamic> json) => SimpleClassNullableOfStringToInt( (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, e as int), + (k, e) => MapEntry(k, (e as num).toInt()), ), ); @@ -4134,7 +4142,7 @@ SimpleClassOfUriToInt _$SimpleClassOfUriToIntFromJson( Map<String, dynamic> json) => SimpleClassOfUriToInt( (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(Uri.parse(k), e as int), + (k, e) => MapEntry(Uri.parse(k), (e as num).toInt()), ), ); @@ -4148,7 +4156,7 @@ SimpleClassNullableOfUriToInt _$SimpleClassNullableOfUriToIntFromJson( Map<String, dynamic> json) => SimpleClassNullableOfUriToInt( (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(Uri.parse(k), e as int), + (k, e) => MapEntry(Uri.parse(k), (e as num).toInt()), ), ); @@ -4162,7 +4170,7 @@ SimpleClassOfBigIntToIntNullable _$SimpleClassOfBigIntToIntNullableFromJson( Map<String, dynamic> json) => SimpleClassOfBigIntToIntNullable( (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(BigInt.parse(k), e as int?), + (k, e) => MapEntry(BigInt.parse(k), (e as num?)?.toInt()), ), ); @@ -4177,7 +4185,7 @@ SimpleClassNullableOfBigIntToIntNullable Map<String, dynamic> json) => SimpleClassNullableOfBigIntToIntNullable( (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(BigInt.parse(k), e as int?), + (k, e) => MapEntry(BigInt.parse(k), (e as num?)?.toInt()), ), ); @@ -4191,7 +4199,7 @@ SimpleClassOfDateTimeToIntNullable _$SimpleClassOfDateTimeToIntNullableFromJson( Map<String, dynamic> json) => SimpleClassOfDateTimeToIntNullable( (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(DateTime.parse(k), e as int?), + (k, e) => MapEntry(DateTime.parse(k), (e as num?)?.toInt()), ), ); @@ -4206,7 +4214,7 @@ SimpleClassNullableOfDateTimeToIntNullable Map<String, dynamic> json) => SimpleClassNullableOfDateTimeToIntNullable( (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(DateTime.parse(k), e as int?), + (k, e) => MapEntry(DateTime.parse(k), (e as num?)?.toInt()), ), ); @@ -4233,7 +4241,7 @@ SimpleClassNullableOfDynamicToIntNullable Map<String, dynamic> json) => SimpleClassNullableOfDynamicToIntNullable( (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, e as int?), + (k, e) => MapEntry(k, (e as num?)?.toInt()), ), ); @@ -4247,7 +4255,8 @@ SimpleClassOfEnumTypeToIntNullable _$SimpleClassOfEnumTypeToIntNullableFromJson( Map<String, dynamic> json) => SimpleClassOfEnumTypeToIntNullable( (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e as int?), + (k, e) => + MapEntry($enumDecode(_$EnumTypeEnumMap, k), (e as num?)?.toInt()), ), ); @@ -4262,7 +4271,8 @@ SimpleClassNullableOfEnumTypeToIntNullable Map<String, dynamic> json) => SimpleClassNullableOfEnumTypeToIntNullable( (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e as int?), + (k, e) => MapEntry( + $enumDecode(_$EnumTypeEnumMap, k), (e as num?)?.toInt()), ), ); @@ -4277,7 +4287,7 @@ SimpleClassOfIntToIntNullable _$SimpleClassOfIntToIntNullableFromJson( Map<String, dynamic> json) => SimpleClassOfIntToIntNullable( (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(int.parse(k), e as int?), + (k, e) => MapEntry(int.parse(k), (e as num?)?.toInt()), ), ); @@ -4292,7 +4302,7 @@ SimpleClassNullableOfIntToIntNullable Map<String, dynamic> json) => SimpleClassNullableOfIntToIntNullable( (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(int.parse(k), e as int?), + (k, e) => MapEntry(int.parse(k), (e as num?)?.toInt()), ), ); @@ -4319,7 +4329,7 @@ SimpleClassNullableOfObjectToIntNullable Map<String, dynamic> json) => SimpleClassNullableOfObjectToIntNullable( (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, e as int?), + (k, e) => MapEntry(k, (e as num?)?.toInt()), ), ); @@ -4346,7 +4356,7 @@ SimpleClassNullableOfStringToIntNullable Map<String, dynamic> json) => SimpleClassNullableOfStringToIntNullable( (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, e as int?), + (k, e) => MapEntry(k, (e as num?)?.toInt()), ), ); @@ -4360,7 +4370,7 @@ SimpleClassOfUriToIntNullable _$SimpleClassOfUriToIntNullableFromJson( Map<String, dynamic> json) => SimpleClassOfUriToIntNullable( (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(Uri.parse(k), e as int?), + (k, e) => MapEntry(Uri.parse(k), (e as num?)?.toInt()), ), ); @@ -4375,7 +4385,7 @@ SimpleClassNullableOfUriToIntNullable Map<String, dynamic> json) => SimpleClassNullableOfUriToIntNullable( (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(Uri.parse(k), e as int?), + (k, e) => MapEntry(Uri.parse(k), (e as num?)?.toInt()), ), ); @@ -5290,7 +5300,7 @@ SimpleClassOfBigIntToRecord _$SimpleClassOfBigIntToRecordFromJson( _$recordConvert( e, ($jsonValue) => ( - $jsonValue[r'$1'] as int, + ($jsonValue[r'$1'] as num).toInt(), $jsonValue[r'$2'] as String, truth: $jsonValue['truth'] as bool, ), @@ -5324,7 +5334,7 @@ SimpleClassNullableOfBigIntToRecord _$recordConvert( e, ($jsonValue) => ( - $jsonValue[r'$1'] as int, + ($jsonValue[r'$1'] as num).toInt(), $jsonValue[r'$2'] as String, truth: $jsonValue['truth'] as bool, ), @@ -5352,7 +5362,7 @@ SimpleClassOfDateTimeToRecord _$SimpleClassOfDateTimeToRecordFromJson( _$recordConvert( e, ($jsonValue) => ( - $jsonValue[r'$1'] as int, + ($jsonValue[r'$1'] as num).toInt(), $jsonValue[r'$2'] as String, truth: $jsonValue['truth'] as bool, ), @@ -5381,7 +5391,7 @@ SimpleClassNullableOfDateTimeToRecord _$recordConvert( e, ($jsonValue) => ( - $jsonValue[r'$1'] as int, + ($jsonValue[r'$1'] as num).toInt(), $jsonValue[r'$2'] as String, truth: $jsonValue['truth'] as bool, ), @@ -5409,7 +5419,7 @@ SimpleClassOfDynamicToRecord _$SimpleClassOfDynamicToRecordFromJson( _$recordConvert( e, ($jsonValue) => ( - $jsonValue[r'$1'] as int, + ($jsonValue[r'$1'] as num).toInt(), $jsonValue[r'$2'] as String, truth: $jsonValue['truth'] as bool, ), @@ -5436,7 +5446,7 @@ SimpleClassNullableOfDynamicToRecord _$recordConvert( e, ($jsonValue) => ( - $jsonValue[r'$1'] as int, + ($jsonValue[r'$1'] as num).toInt(), $jsonValue[r'$2'] as String, truth: $jsonValue['truth'] as bool, ), @@ -5463,7 +5473,7 @@ SimpleClassOfEnumTypeToRecord _$SimpleClassOfEnumTypeToRecordFromJson( _$recordConvert( e, ($jsonValue) => ( - $jsonValue[r'$1'] as int, + ($jsonValue[r'$1'] as num).toInt(), $jsonValue[r'$2'] as String, truth: $jsonValue['truth'] as bool, ), @@ -5492,7 +5502,7 @@ SimpleClassNullableOfEnumTypeToRecord _$recordConvert( e, ($jsonValue) => ( - $jsonValue[r'$1'] as int, + ($jsonValue[r'$1'] as num).toInt(), $jsonValue[r'$2'] as String, truth: $jsonValue['truth'] as bool, ), @@ -5520,7 +5530,7 @@ SimpleClassOfIntToRecord _$SimpleClassOfIntToRecordFromJson( _$recordConvert( e, ($jsonValue) => ( - $jsonValue[r'$1'] as int, + ($jsonValue[r'$1'] as num).toInt(), $jsonValue[r'$2'] as String, truth: $jsonValue['truth'] as bool, ), @@ -5548,7 +5558,7 @@ SimpleClassNullableOfIntToRecord _$SimpleClassNullableOfIntToRecordFromJson( _$recordConvert( e, ($jsonValue) => ( - $jsonValue[r'$1'] as int, + ($jsonValue[r'$1'] as num).toInt(), $jsonValue[r'$2'] as String, truth: $jsonValue['truth'] as bool, ), @@ -5576,7 +5586,7 @@ SimpleClassOfObjectToRecord _$SimpleClassOfObjectToRecordFromJson( _$recordConvert( e, ($jsonValue) => ( - $jsonValue[r'$1'] as int, + ($jsonValue[r'$1'] as num).toInt(), $jsonValue[r'$2'] as String, truth: $jsonValue['truth'] as bool, ), @@ -5603,7 +5613,7 @@ SimpleClassNullableOfObjectToRecord _$recordConvert( e, ($jsonValue) => ( - $jsonValue[r'$1'] as int, + ($jsonValue[r'$1'] as num).toInt(), $jsonValue[r'$2'] as String, truth: $jsonValue['truth'] as bool, ), @@ -5630,7 +5640,7 @@ SimpleClassOfStringToRecord _$SimpleClassOfStringToRecordFromJson( _$recordConvert( e, ($jsonValue) => ( - $jsonValue[r'$1'] as int, + ($jsonValue[r'$1'] as num).toInt(), $jsonValue[r'$2'] as String, truth: $jsonValue['truth'] as bool, ), @@ -5657,7 +5667,7 @@ SimpleClassNullableOfStringToRecord _$recordConvert( e, ($jsonValue) => ( - $jsonValue[r'$1'] as int, + ($jsonValue[r'$1'] as num).toInt(), $jsonValue[r'$2'] as String, truth: $jsonValue['truth'] as bool, ), @@ -5684,7 +5694,7 @@ SimpleClassOfUriToRecord _$SimpleClassOfUriToRecordFromJson( _$recordConvert( e, ($jsonValue) => ( - $jsonValue[r'$1'] as int, + ($jsonValue[r'$1'] as num).toInt(), $jsonValue[r'$2'] as String, truth: $jsonValue['truth'] as bool, ), @@ -5712,7 +5722,7 @@ SimpleClassNullableOfUriToRecord _$SimpleClassNullableOfUriToRecordFromJson( _$recordConvert( e, ($jsonValue) => ( - $jsonValue[r'$1'] as int, + ($jsonValue[r'$1'] as num).toInt(), $jsonValue[r'$2'] as String, truth: $jsonValue['truth'] as bool, ), diff --git a/json_serializable/test/supported_types/input.type_record.g.dart b/json_serializable/test/supported_types/input.type_record.g.dart index 5c96d58c8..bc37b7cd2 100644 --- a/json_serializable/test/supported_types/input.type_record.g.dart +++ b/json_serializable/test/supported_types/input.type_record.g.dart @@ -411,8 +411,8 @@ SimpleClassOfDuration _$SimpleClassOfDurationFromJson( _$recordConvert( json['value'], ($jsonValue) => ( - Duration(microseconds: $jsonValue[r'$1'] as int), - named: Duration(microseconds: $jsonValue['named'] as int), + Duration(microseconds: ($jsonValue[r'$1'] as num).toInt()), + named: Duration(microseconds: ($jsonValue['named'] as num).toInt()), ), ), ); @@ -432,8 +432,8 @@ SimpleClassNullableOfDuration _$SimpleClassNullableOfDurationFromJson( _$recordConvertNullable( json['value'], ($jsonValue) => ( - Duration(microseconds: $jsonValue[r'$1'] as int), - named: Duration(microseconds: $jsonValue['named'] as int), + Duration(microseconds: ($jsonValue[r'$1'] as num).toInt()), + named: Duration(microseconds: ($jsonValue['named'] as num).toInt()), ), ), ); @@ -457,10 +457,10 @@ SimpleClassOfDurationNullable _$SimpleClassOfDurationNullableFromJson( ($jsonValue) => ( $jsonValue[r'$1'] == null ? null - : Duration(microseconds: $jsonValue[r'$1'] as int), + : Duration(microseconds: ($jsonValue[r'$1'] as num).toInt()), named: $jsonValue['named'] == null ? null - : Duration(microseconds: $jsonValue['named'] as int), + : Duration(microseconds: ($jsonValue['named'] as num).toInt()), ), ), ); @@ -483,10 +483,11 @@ SimpleClassNullableOfDurationNullable ($jsonValue) => ( $jsonValue[r'$1'] == null ? null - : Duration(microseconds: $jsonValue[r'$1'] as int), + : Duration(microseconds: ($jsonValue[r'$1'] as num).toInt()), named: $jsonValue['named'] == null ? null - : Duration(microseconds: $jsonValue['named'] as int), + : Duration( + microseconds: ($jsonValue['named'] as num).toInt()), ), ), ); @@ -785,8 +786,8 @@ SimpleClassOfInt _$SimpleClassOfIntFromJson(Map<String, dynamic> json) => _$recordConvert( json['value'], ($jsonValue) => ( - $jsonValue[r'$1'] as int, - named: $jsonValue['named'] as int, + ($jsonValue[r'$1'] as num).toInt(), + named: ($jsonValue['named'] as num).toInt(), ), ), ); @@ -805,8 +806,8 @@ SimpleClassNullableOfInt _$SimpleClassNullableOfIntFromJson( _$recordConvertNullable( json['value'], ($jsonValue) => ( - $jsonValue[r'$1'] as int, - named: $jsonValue['named'] as int, + ($jsonValue[r'$1'] as num).toInt(), + named: ($jsonValue['named'] as num).toInt(), ), ), ); @@ -828,8 +829,8 @@ SimpleClassOfIntNullable _$SimpleClassOfIntNullableFromJson( _$recordConvert( json['value'], ($jsonValue) => ( - $jsonValue[r'$1'] as int?, - named: $jsonValue['named'] as int?, + ($jsonValue[r'$1'] as num?)?.toInt(), + named: ($jsonValue['named'] as num?)?.toInt(), ), ), ); @@ -849,8 +850,8 @@ SimpleClassNullableOfIntNullable _$SimpleClassNullableOfIntNullableFromJson( _$recordConvertNullable( json['value'], ($jsonValue) => ( - $jsonValue[r'$1'] as int?, - named: $jsonValue['named'] as int?, + ($jsonValue[r'$1'] as num?)?.toInt(), + named: ($jsonValue['named'] as num?)?.toInt(), ), ), ); @@ -1047,7 +1048,7 @@ SimpleClassOfRecord _$SimpleClassOfRecordFromJson(Map<String, dynamic> json) => _$recordConvert( $jsonValue[r'$1'], ($jsonValue) => ( - $jsonValue[r'$1'] as int, + ($jsonValue[r'$1'] as num).toInt(), $jsonValue[r'$2'] as String, truth: $jsonValue['truth'] as bool, ), @@ -1055,7 +1056,7 @@ SimpleClassOfRecord _$SimpleClassOfRecordFromJson(Map<String, dynamic> json) => named: _$recordConvert( $jsonValue['named'], ($jsonValue) => ( - $jsonValue[r'$1'] as int, + ($jsonValue[r'$1'] as num).toInt(), $jsonValue[r'$2'] as String, truth: $jsonValue['truth'] as bool, ), @@ -1090,7 +1091,7 @@ SimpleClassNullableOfRecord _$SimpleClassNullableOfRecordFromJson( _$recordConvert( $jsonValue[r'$1'], ($jsonValue) => ( - $jsonValue[r'$1'] as int, + ($jsonValue[r'$1'] as num).toInt(), $jsonValue[r'$2'] as String, truth: $jsonValue['truth'] as bool, ), @@ -1098,7 +1099,7 @@ SimpleClassNullableOfRecord _$SimpleClassNullableOfRecordFromJson( named: _$recordConvert( $jsonValue['named'], ($jsonValue) => ( - $jsonValue[r'$1'] as int, + ($jsonValue[r'$1'] as num).toInt(), $jsonValue[r'$2'] as String, truth: $jsonValue['truth'] as bool, ), diff --git a/json_serializable/test/supported_types/input.type_set.g.dart b/json_serializable/test/supported_types/input.type_set.g.dart index 73866adf9..234afad93 100644 --- a/json_serializable/test/supported_types/input.type_set.g.dart +++ b/json_serializable/test/supported_types/input.type_set.g.dart @@ -251,7 +251,7 @@ SimpleClassOfDuration _$SimpleClassOfDurationFromJson( Map<String, dynamic> json) => SimpleClassOfDuration( (json['value'] as List<dynamic>) - .map((e) => Duration(microseconds: e as int)) + .map((e) => Duration(microseconds: (e as num).toInt())) .toSet(), ); @@ -265,7 +265,7 @@ SimpleClassNullableOfDuration _$SimpleClassNullableOfDurationFromJson( Map<String, dynamic> json) => SimpleClassNullableOfDuration( (json['value'] as List<dynamic>?) - ?.map((e) => Duration(microseconds: e as int)) + ?.map((e) => Duration(microseconds: (e as num).toInt())) .toSet(), ); @@ -279,7 +279,8 @@ SimpleClassOfDurationNullable _$SimpleClassOfDurationNullableFromJson( Map<String, dynamic> json) => SimpleClassOfDurationNullable( (json['value'] as List<dynamic>) - .map((e) => e == null ? null : Duration(microseconds: e as int)) + .map((e) => + e == null ? null : Duration(microseconds: (e as num).toInt())) .toSet(), ); @@ -294,7 +295,8 @@ SimpleClassNullableOfDurationNullable Map<String, dynamic> json) => SimpleClassNullableOfDurationNullable( (json['value'] as List<dynamic>?) - ?.map((e) => e == null ? null : Duration(microseconds: e as int)) + ?.map((e) => + e == null ? null : Duration(microseconds: (e as num).toInt())) .toSet(), ); @@ -482,7 +484,7 @@ Map<String, dynamic> _$SimpleClassNullableOfFromJsonObjectParamToJson( SimpleClassOfInt _$SimpleClassOfIntFromJson(Map<String, dynamic> json) => SimpleClassOfInt( - (json['value'] as List<dynamic>).map((e) => e as int).toSet(), + (json['value'] as List<dynamic>).map((e) => (e as num).toInt()).toSet(), ); Map<String, dynamic> _$SimpleClassOfIntToJson(SimpleClassOfInt instance) => @@ -493,7 +495,7 @@ Map<String, dynamic> _$SimpleClassOfIntToJson(SimpleClassOfInt instance) => SimpleClassNullableOfInt _$SimpleClassNullableOfIntFromJson( Map<String, dynamic> json) => SimpleClassNullableOfInt( - (json['value'] as List<dynamic>?)?.map((e) => e as int).toSet(), + (json['value'] as List<dynamic>?)?.map((e) => (e as num).toInt()).toSet(), ); Map<String, dynamic> _$SimpleClassNullableOfIntToJson( @@ -505,7 +507,7 @@ Map<String, dynamic> _$SimpleClassNullableOfIntToJson( SimpleClassOfIntNullable _$SimpleClassOfIntNullableFromJson( Map<String, dynamic> json) => SimpleClassOfIntNullable( - (json['value'] as List<dynamic>).map((e) => e as int?).toSet(), + (json['value'] as List<dynamic>).map((e) => (e as num?)?.toInt()).toSet(), ); Map<String, dynamic> _$SimpleClassOfIntNullableToJson( @@ -517,7 +519,9 @@ Map<String, dynamic> _$SimpleClassOfIntNullableToJson( SimpleClassNullableOfIntNullable _$SimpleClassNullableOfIntNullableFromJson( Map<String, dynamic> json) => SimpleClassNullableOfIntNullable( - (json['value'] as List<dynamic>?)?.map((e) => e as int?).toSet(), + (json['value'] as List<dynamic>?) + ?.map((e) => (e as num?)?.toInt()) + .toSet(), ); Map<String, dynamic> _$SimpleClassNullableOfIntNullableToJson( @@ -625,7 +629,7 @@ SimpleClassOfRecord _$SimpleClassOfRecordFromJson(Map<String, dynamic> json) => .map((e) => _$recordConvert( e, ($jsonValue) => ( - $jsonValue[r'$1'] as int, + ($jsonValue[r'$1'] as num).toInt(), $jsonValue[r'$2'] as String, truth: $jsonValue['truth'] as bool, ), @@ -658,7 +662,7 @@ SimpleClassNullableOfRecord _$SimpleClassNullableOfRecordFromJson( ?.map((e) => _$recordConvert( e, ($jsonValue) => ( - $jsonValue[r'$1'] as int, + ($jsonValue[r'$1'] as num).toInt(), $jsonValue[r'$2'] as String, truth: $jsonValue['truth'] as bool, ), diff --git a/json_serializable/tool/readme/readme_examples.g.dart b/json_serializable/tool/readme/readme_examples.g.dart index c22e9025b..b3a60ab36 100644 --- a/json_serializable/tool/readme/readme_examples.g.dart +++ b/json_serializable/tool/readme/readme_examples.g.dart @@ -9,7 +9,7 @@ part of 'readme_examples.dart'; // ************************************************************************** Sample1 _$Sample1FromJson(Map<String, dynamic> json) => Sample1( - Sample2.fromJson(json['value'] as int), + Sample2.fromJson((json['value'] as num).toInt()), ); Map<String, dynamic> _$Sample1ToJson(Sample1 instance) => <String, dynamic>{ @@ -17,7 +17,7 @@ Map<String, dynamic> _$Sample1ToJson(Sample1 instance) => <String, dynamic>{ }; Sample3 _$Sample3FromJson(Map<String, dynamic> json) => Sample3( - Sample3._fromJson(json['value'] as int), + Sample3._fromJson((json['value'] as num).toInt()), ); Map<String, dynamic> _$Sample3ToJson(Sample3 instance) => <String, dynamic>{ @@ -25,7 +25,7 @@ Map<String, dynamic> _$Sample3ToJson(Sample3 instance) => <String, dynamic>{ }; Sample4 _$Sample4FromJson(Map<String, dynamic> json) => Sample4( - const EpochDateTimeConverter().fromJson(json['value'] as int), + const EpochDateTimeConverter().fromJson((json['value'] as num).toInt()), ); Map<String, dynamic> _$Sample4ToJson(Sample4 instance) => <String, dynamic>{ From eea959d5f9e971faae8887bc5aaa42b00534972e Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Wed, 24 Apr 2024 12:47:41 -0700 Subject: [PATCH 522/569] json_annotation: prepare to release v4.9.0 (#1417) --- json_annotation/CHANGELOG.md | 4 ++-- json_annotation/lib/src/json_serializable.dart | 13 ++++++++----- json_annotation/pubspec.yaml | 2 +- json_serializable/CHANGELOG.md | 5 ++--- json_serializable/README.md | 18 +++++++++--------- 5 files changed, 22 insertions(+), 20 deletions(-) diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index 1b3d6be21..3b95a5887 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -1,7 +1,7 @@ -## 4.9.0-wip +## 4.9.0 - Require Dart 3.0 -- Added `JsonSerializable(createJsonKeys: true)`. +- Add `JsonSerializable(createJsonKeys: true)`. ([#1401](https://github.com/google/json_serializable.dart/pull/1401)) ## 4.8.1 diff --git a/json_annotation/lib/src/json_serializable.dart b/json_annotation/lib/src/json_serializable.dart index 91600f097..fb4d8eade 100644 --- a/json_annotation/lib/src/json_serializable.dart +++ b/json_annotation/lib/src/json_serializable.dart @@ -88,16 +88,19 @@ class JsonSerializable { final bool? createFieldMap; /// If `true` (defaults to false), a private class `_$ExampleJsonKeys` - /// constant is created in the generated part file. + /// class is created in the generated part file. /// - /// This class will contain every property, with the json key as value, - /// exposing a secured way to access the json key from the property. + /// This class will contain every property as a [String] field with the JSON + /// key as the value. /// /// ```dart /// @JsonSerializable(createJsonKeys: true) /// class Example { - /// // ... - /// static const jsonKeys = _$PublicationImplJsonKeys(); + /// @JsonKey(name: 'LAST_NAME') + /// String? firstName; + /// + /// // Will have the value `LAST_NAME` + /// static const firstName = _$ExampleJsonKeys.firstName; /// } /// ``` final bool? createJsonKeys; diff --git a/json_annotation/pubspec.yaml b/json_annotation/pubspec.yaml index aabbd9681..5d748a0e9 100644 --- a/json_annotation/pubspec.yaml +++ b/json_annotation/pubspec.yaml @@ -1,5 +1,5 @@ name: json_annotation -version: 4.9.0-wip +version: 4.9.0 description: >- Classes and helper functions that support JSON code generation via the `json_serializable` package. diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 9ae8f098d..77bf34c15 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,9 +1,8 @@ ## 6.8.0-wip - Add type arguments to `Map` literals used for `Record` serialization. -- Added support for generating `ExampleJsonKeys`, exposing a secured way to - access the json keys from the properties. - ([#1164](https://github.com/google/json_serializable.dart/pull/1164)) +- Add support for `JsonSerializable(createJsonKeys: true)`. + ([#1401](https://github.com/google/json_serializable.dart/pull/1401)) - Handle decoding an `int` value from a `double` literal. This now matches the behavior of `double` values being encoded as `int`. diff --git a/json_serializable/README.md b/json_serializable/README.md index 5d30efd16..d30a13659 100644 --- a/json_serializable/README.md +++ b/json_serializable/README.md @@ -298,15 +298,15 @@ targets: [`Enum`]: https://api.dart.dev/stable/dart-core/Enum-class.html [`int`]: https://api.dart.dev/stable/dart-core/int-class.html [`Iterable`]: https://api.dart.dev/stable/dart-core/Iterable-class.html -[`JsonConverter`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonConverter-class.html -[`JsonEnum.valueField`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonEnum/valueField.html -[`JsonEnum`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonEnum-class.html -[`JsonKey.fromJson`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/fromJson.html -[`JsonKey.toJson`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/toJson.html -[`JsonKey`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey-class.html -[`JsonLiteral`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonLiteral-class.html -[`JsonSerializable`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable-class.html -[`JsonValue`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonValue-class.html +[`JsonConverter`]: https://pub.dev/documentation/json_annotation/4.9.0/json_annotation/JsonConverter-class.html +[`JsonEnum.valueField`]: https://pub.dev/documentation/json_annotation/4.9.0/json_annotation/JsonEnum/valueField.html +[`JsonEnum`]: https://pub.dev/documentation/json_annotation/4.9.0/json_annotation/JsonEnum-class.html +[`JsonKey.fromJson`]: https://pub.dev/documentation/json_annotation/4.9.0/json_annotation/JsonKey/fromJson.html +[`JsonKey.toJson`]: https://pub.dev/documentation/json_annotation/4.9.0/json_annotation/JsonKey/toJson.html +[`JsonKey`]: https://pub.dev/documentation/json_annotation/4.9.0/json_annotation/JsonKey-class.html +[`JsonLiteral`]: https://pub.dev/documentation/json_annotation/4.9.0/json_annotation/JsonLiteral-class.html +[`JsonSerializable`]: https://pub.dev/documentation/json_annotation/4.9.0/json_annotation/JsonSerializable-class.html +[`JsonValue`]: https://pub.dev/documentation/json_annotation/4.9.0/json_annotation/JsonValue-class.html [`List`]: https://api.dart.dev/stable/dart-core/List-class.html [`Map`]: https://api.dart.dev/stable/dart-core/Map-class.html [`num`]: https://api.dart.dev/stable/dart-core/num-class.html From 9694cc5d5ebd08e131484c7de7784eefcc45db37 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Wed, 24 Apr 2024 13:15:13 -0700 Subject: [PATCH 523/569] json_serializable: publish v6.8.0 (#1418) --- json_serializable/CHANGELOG.md | 2 +- json_serializable/lib/src/check_dependencies.dart | 2 +- json_serializable/pubspec.yaml | 8 ++------ 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 77bf34c15..36ae2f96c 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,4 +1,4 @@ -## 6.8.0-wip +## 6.8.0 - Add type arguments to `Map` literals used for `Record` serialization. - Add support for `JsonSerializable(createJsonKeys: true)`. diff --git a/json_serializable/lib/src/check_dependencies.dart b/json_serializable/lib/src/check_dependencies.dart index 63512589d..7ea84bef4 100644 --- a/json_serializable/lib/src/check_dependencies.dart +++ b/json_serializable/lib/src/check_dependencies.dart @@ -10,7 +10,7 @@ import 'package:pubspec_parse/pubspec_parse.dart'; const _productionDirectories = {'lib', 'bin'}; const _annotationPkgName = 'json_annotation'; -final requiredJsonAnnotationMinVersion = Version.parse('4.8.1'); +final requiredJsonAnnotationMinVersion = Version.parse('4.9.0'); Future<void> pubspecHasRightVersion(BuildStep buildStep) async { final segments = buildStep.inputId.pathSegments; diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 307e1f76c..e6d66865d 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 6.8.0-wip +version: 6.8.0 description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. @@ -21,7 +21,7 @@ dependencies: # Use a tight version constraint to ensure that a constraint on # `json_annotation` properly constrains all features it provides. - json_annotation: '>=4.8.1 <4.9.0' + json_annotation: '>=4.9.0 <4.10.0' meta: ^1.3.0 path: ^1.8.0 pub_semver: ^2.0.0 @@ -29,10 +29,6 @@ dependencies: source_gen: ^1.3.2 source_helper: ^1.3.0 -dependency_overrides: - json_annotation: - path: ../json_annotation - dev_dependencies: _json_serial_shared_test: path: ../shared_test From 02e17e56c5364ea734444148493c36939bc78648 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Wed, 24 Apr 2024 14:07:37 -0700 Subject: [PATCH 524/569] checked_yaml: fix test source (#1419) --- checked_yaml/example/example.g.dart | 2 +- checked_yaml/test/example_test.dart | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/checked_yaml/example/example.g.dart b/checked_yaml/example/example.g.dart index c4d01aefb..96f10dae8 100644 --- a/checked_yaml/example/example.g.dart +++ b/checked_yaml/example/example.g.dart @@ -17,7 +17,7 @@ Configuration _$ConfigurationFromJson(Map json) => $checkedCreate( ); final val = Configuration( name: $checkedConvert('name', (v) => v as String), - count: $checkedConvert('count', (v) => v as int), + count: $checkedConvert('count', (v) => (v as num).toInt()), ); return val; }, diff --git a/checked_yaml/test/example_test.dart b/checked_yaml/test/example_test.dart index 08ff6f358..7761c36f5 100644 --- a/checked_yaml/test/example_test.dart +++ b/checked_yaml/test/example_test.dart @@ -33,7 +33,7 @@ line 1, column 1: Required keys are missing: name. _expectThrows( '{"name":"something"}', r''' -line 1, column 1: Missing key "count". type 'Null' is not a subtype of type 'int' in type cast +line 1, column 1: Missing key "count". type 'Null' is not a subtype of type 'num' in type cast ╷ 1 │ {"name":"something"} │ ^^^^^^^^^^^^^^^^^^^^ From 629d369f1f225da0b14c970a70d91c15cdc18c9b Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Mon, 20 May 2024 14:13:02 -0700 Subject: [PATCH 525/569] Update analyzer version and min SDK constraint and fix analysis issues (#1428) --- .github/workflows/dart.yml | 64 +++++++++---------- _test_yaml/pubspec.yaml | 14 ++-- _test_yaml/test/ensure_build_test.dart | 2 +- _test_yaml/test/yaml_test.dart | 2 +- checked_yaml/CHANGELOG.md | 2 +- checked_yaml/pubspec.yaml | 10 +-- checked_yaml/test/ensure_build_test.dart | 2 +- example/README.md | 4 +- example/pubspec.yaml | 10 +-- example/test/ensure_build_test.dart | 2 +- example/test/readme_test.dart | 4 +- json_annotation/CHANGELOG.md | 4 ++ json_annotation/lib/json_annotation.dart | 2 +- json_annotation/pubspec.yaml | 6 +- json_serializable/CHANGELOG.md | 4 ++ json_serializable/lib/builder.dart | 2 +- json_serializable/lib/src/decode_helper.dart | 5 +- json_serializable/lib/src/field_helpers.dart | 4 +- json_serializable/lib/src/helper_core.dart | 2 +- json_serializable/lib/src/json_key_utils.dart | 4 +- .../lib/src/json_serializable_generator.dart | 8 --- .../type_helpers/generic_factory_helper.dart | 5 +- .../lib/src/type_helpers/map_helper.dart | 2 +- json_serializable/lib/src/utils.dart | 8 ++- json_serializable/pubspec.yaml | 34 +++++----- .../test/annotation_version_test.dart | 2 +- json_serializable/test/config_test.dart | 2 +- .../test/custom_configuration_test.dart | 2 +- json_serializable/test/ensure_build_test.dart | 2 +- json_serializable/test/enum_helper_test.dart | 2 +- .../test/json_serializable_test.dart | 2 +- .../test/literal/json_literal_test.dart | 2 +- .../test/supported_types/extra_map_test.dart | 2 +- .../type_test.bigint_test.dart | 2 +- .../supported_types/type_test.bool_test.dart | 2 +- .../test/supported_types/type_test.dart | 2 +- .../type_test.datetime_test.dart | 2 +- .../type_test.double_test.dart | 2 +- .../type_test.duration_test.dart | 2 +- .../type_test.enumtype_test.dart | 2 +- .../supported_types/type_test.int_test.dart | 2 +- .../type_test.iterable_test.dart | 2 +- .../supported_types/type_test.list_test.dart | 2 +- .../supported_types/type_test.map_test.dart | 2 +- .../supported_types/type_test.num_test.dart | 2 +- .../type_test.object_test.dart | 2 +- .../supported_types/type_test.set_test.dart | 2 +- .../type_test.string_test.dart | 2 +- .../supported_types/type_test.uri_test.dart | 2 +- shared_test/pubspec.yaml | 4 +- tool/ci.sh | 18 ++---- 51 files changed, 141 insertions(+), 135 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 0be82d568..121296a69 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -1,4 +1,4 @@ -# Created with package:mono_repo v6.5.7 +# Created with package:mono_repo v6.6.1 name: Dart CI on: push: @@ -36,27 +36,27 @@ jobs: name: Checkout repository uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 - name: mono_repo self validate - run: dart pub global activate mono_repo 6.5.7 + run: dart pub global activate mono_repo 6.6.1 - name: mono_repo self validate run: dart pub global run mono_repo generate --validate job_002: - name: "analyzer_and_format; Dart 3.0.0; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; `dart analyze`" + name: "analyzer_and_format; Dart 3.4.0; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; `dart analyze`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:analyze_1" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.4.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:analyze_1" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable - os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0 + os:ubuntu-latest;pub-cache-hosted;sdk:3.4.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable + os:ubuntu-latest;pub-cache-hosted;sdk:3.4.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3 with: - sdk: "3.0.0" + sdk: "3.4.0" - id: checkout name: Checkout repository uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 @@ -192,23 +192,23 @@ jobs: if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" working-directory: json_serializable job_004: - name: "unit_test; Dart 3.0.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; `dart test`" + name: "unit_test; Dart 3.4.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; `dart test`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.4.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:_test_yaml-checked_yaml-example-json_serializable - os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0 + os:ubuntu-latest;pub-cache-hosted;sdk:3.4.0;packages:_test_yaml-checked_yaml-example-json_serializable + os:ubuntu-latest;pub-cache-hosted;sdk:3.4.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3 with: - sdk: "3.0.0" + sdk: "3.4.0" - id: checkout name: Checkout repository uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 @@ -253,23 +253,23 @@ jobs: - job_002 - job_003 job_005: - name: "unit_test; Dart 3.0.0; PKG: json_serializable; `dart test --run-skipped -t presubmit-only test/annotation_version_test.dart`" + name: "unit_test; Dart 3.4.0; PKG: json_serializable; `dart test --run-skipped -t presubmit-only test/annotation_version_test.dart`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:json_serializable;commands:test_3" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.4.0;packages:json_serializable;commands:test_3" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:json_serializable - os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0 + os:ubuntu-latest;pub-cache-hosted;sdk:3.4.0;packages:json_serializable + os:ubuntu-latest;pub-cache-hosted;sdk:3.4.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3 with: - sdk: "3.0.0" + sdk: "3.4.0" - id: checkout name: Checkout repository uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 @@ -287,23 +287,23 @@ jobs: - job_002 - job_003 job_006: - name: "unit_test; Dart 3.0.0; PKG: json_serializable; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" + name: "unit_test; Dart 3.4.0; PKG: json_serializable; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:json_serializable;commands:test_1" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.4.0;packages:json_serializable;commands:test_1" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:json_serializable - os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0 + os:ubuntu-latest;pub-cache-hosted;sdk:3.4.0;packages:json_serializable + os:ubuntu-latest;pub-cache-hosted;sdk:3.4.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3 with: - sdk: "3.0.0" + sdk: "3.4.0" - id: checkout name: Checkout repository uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 @@ -321,23 +321,23 @@ jobs: - job_002 - job_003 job_007: - name: "unit_test; Dart 3.0.0; PKG: json_serializable; `dart test -p chrome`" + name: "unit_test; Dart 3.4.0; PKG: json_serializable; `dart test -p chrome`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:json_serializable;commands:test_2" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.4.0;packages:json_serializable;commands:test_2" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:json_serializable - os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0 + os:ubuntu-latest;pub-cache-hosted;sdk:3.4.0;packages:json_serializable + os:ubuntu-latest;pub-cache-hosted;sdk:3.4.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3 with: - sdk: "3.0.0" + sdk: "3.4.0" - id: checkout name: Checkout repository uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 @@ -518,23 +518,23 @@ jobs: - job_002 - job_003 job_012: - name: "ensure_build; Dart 3.0.0; PKGS: _test_yaml, checked_yaml, example; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" + name: "ensure_build; Dart 3.4.0; PKGS: _test_yaml, checked_yaml, example; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:_test_yaml-checked_yaml-example;commands:test_1" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.4.0;packages:_test_yaml-checked_yaml-example;commands:test_1" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:_test_yaml-checked_yaml-example - os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0 + os:ubuntu-latest;pub-cache-hosted;sdk:3.4.0;packages:_test_yaml-checked_yaml-example + os:ubuntu-latest;pub-cache-hosted;sdk:3.4.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3 with: - sdk: "3.0.0" + sdk: "3.4.0" - id: checkout name: Checkout repository uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 diff --git a/_test_yaml/pubspec.yaml b/_test_yaml/pubspec.yaml index 57f7a275b..8bf18a935 100644 --- a/_test_yaml/pubspec.yaml +++ b/_test_yaml/pubspec.yaml @@ -2,19 +2,19 @@ name: _test_yaml publish_to: none environment: - sdk: ^3.0.0 + sdk: ^3.4.0 dev_dependencies: _json_serial_shared_test: path: ../shared_test - build_runner: ^2.0.0 + build_runner: ^2.2.1 build_verify: ^3.0.0 - checked_yaml: any - dart_flutter_team_lints: ^2.0.0 - json_annotation: ^4.8.1 - json_serializable: any + checked_yaml: ^2.0.4-wip + dart_flutter_team_lints: ^3.0.0 + json_annotation: ^4.9.0 + json_serializable: ^6.8.0 path: ^1.8.2 - test: ^1.6.0 + test: ^1.21.6 yaml: ^3.0.0 dependency_overrides: diff --git a/_test_yaml/test/ensure_build_test.dart b/_test_yaml/test/ensure_build_test.dart index 868332ed6..406a1aa77 100644 --- a/_test_yaml/test/ensure_build_test.dart +++ b/_test_yaml/test/ensure_build_test.dart @@ -4,7 +4,7 @@ @TestOn('vm') @Tags(['presubmit-only']) -library test; +library; import 'package:build_verify/build_verify.dart'; import 'package:test/test.dart'; diff --git a/_test_yaml/test/yaml_test.dart b/_test_yaml/test/yaml_test.dart index 96f698b05..29856bf8c 100644 --- a/_test_yaml/test/yaml_test.dart +++ b/_test_yaml/test/yaml_test.dart @@ -3,7 +3,7 @@ // BSD-style license that can be found in the LICENSE file. @TestOn('vm') -library test; +library; import 'dart:io'; diff --git a/checked_yaml/CHANGELOG.md b/checked_yaml/CHANGELOG.md index 18603be88..543b0ce5e 100644 --- a/checked_yaml/CHANGELOG.md +++ b/checked_yaml/CHANGELOG.md @@ -1,6 +1,6 @@ ## 2.0.4-wip -- Require Dart 3.0 +- Require Dart 3.4 ## 2.0.3 diff --git a/checked_yaml/pubspec.yaml b/checked_yaml/pubspec.yaml index 821c9de5e..2be93cc62 100644 --- a/checked_yaml/pubspec.yaml +++ b/checked_yaml/pubspec.yaml @@ -13,7 +13,7 @@ topics: - codegen environment: - sdk: ^3.0.0 + sdk: ^3.4.0 dependencies: json_annotation: ^4.3.0 @@ -21,12 +21,12 @@ dependencies: yaml: ^3.0.0 dev_dependencies: - build_runner: ^2.0.0 + build_runner: ^2.0.6 build_verify: ^3.0.0 - dart_flutter_team_lints: ^2.0.0 + dart_flutter_team_lints: ^3.0.0 json_serializable: ^6.0.0 - path: ^1.0.0 - test: ^1.16.0 + path: ^1.8.0 + test: ^1.17.10 test_process: ^2.0.0 #dependency_overrides: diff --git a/checked_yaml/test/ensure_build_test.dart b/checked_yaml/test/ensure_build_test.dart index 0a5935d7b..ec5871f3c 100644 --- a/checked_yaml/test/ensure_build_test.dart +++ b/checked_yaml/test/ensure_build_test.dart @@ -4,7 +4,7 @@ @TestOn('vm') @Tags(['presubmit-only']) -library test; +library; import 'package:build_verify/build_verify.dart'; import 'package:test/test.dart'; diff --git a/example/README.md b/example/README.md index bb6cf3c79..7eff2e695 100644 --- a/example/README.md +++ b/example/README.md @@ -5,11 +5,11 @@ dependencies to your `pubspec.yaml`. ```yaml dependencies: - json_annotation: ^4.8.0 + json_annotation: ^4.9.0 dev_dependencies: build_runner: ^2.3.3 - json_serializable: ^6.6.0 + json_serializable: ^6.8.0 ``` Annotate your code with classes defined in diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 6191089bd..be24d38a3 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -2,10 +2,10 @@ name: example publish_to: none environment: - sdk: ^3.0.0 + sdk: ^3.4.0 dependencies: - json_annotation: ^4.8.0 + json_annotation: ^4.9.0 dev_dependencies: # Used by tests. Not required to use `json_serializable`. @@ -19,14 +19,14 @@ dev_dependencies: build_verify: ^3.0.0 # Not required to use `json_serializable`. - dart_flutter_team_lints: ^2.0.0 + dart_flutter_team_lints: ^3.0.0 # REQUIRED! - json_serializable: ^6.6.0 + json_serializable: ^6.8.0 # Not required to use `json_serializable`. path: ^1.8.0 - test: ^1.16.0 + test: ^1.21.6 # This section is used to verify changes to these packages. Do not include in # your code! diff --git a/example/test/ensure_build_test.dart b/example/test/ensure_build_test.dart index 5d06a2fd1..8d3d473e9 100644 --- a/example/test/ensure_build_test.dart +++ b/example/test/ensure_build_test.dart @@ -3,7 +3,7 @@ // BSD-style license that can be found in the LICENSE file. @Tags(['presubmit-only']) -library test; +library; import 'package:build_verify/build_verify.dart'; import 'package:test/test.dart'; diff --git a/example/test/readme_test.dart b/example/test/readme_test.dart index ab3267f8b..9ab00e93b 100644 --- a/example/test/readme_test.dart +++ b/example/test/readme_test.dart @@ -25,9 +25,9 @@ void _expect(String fileName) { const _pubspecContent = r''' dependencies: - json_annotation: ^4.8.0 + json_annotation: ^4.9.0 dev_dependencies: build_runner: ^2.3.3 - json_serializable: ^6.6.0 + json_serializable: ^6.8.0 '''; diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index 3b95a5887..911e1d671 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -1,3 +1,7 @@ +## 4.9.1-wip + +- Require Dart 3.4 + ## 4.9.0 - Require Dart 3.0 diff --git a/json_annotation/lib/json_annotation.dart b/json_annotation/lib/json_annotation.dart index 2dc5d00b1..05b3a8a8c 100644 --- a/json_annotation/lib/json_annotation.dart +++ b/json_annotation/lib/json_annotation.dart @@ -8,7 +8,7 @@ /// Also contains helper functions and classes – prefixed with `$` used by /// `json_serializable` when the `use_wrappers` or `checked` options are /// enabled. -library json_annotation; +library; export 'src/allowed_keys_helpers.dart'; export 'src/checked_helpers.dart'; diff --git a/json_annotation/pubspec.yaml b/json_annotation/pubspec.yaml index 5d748a0e9..917f8e111 100644 --- a/json_annotation/pubspec.yaml +++ b/json_annotation/pubspec.yaml @@ -1,5 +1,5 @@ name: json_annotation -version: 4.9.0 +version: 4.9.1-wip description: >- Classes and helper functions that support JSON code generation via the `json_serializable` package. @@ -11,13 +11,13 @@ topics: - codegen environment: - sdk: ^3.0.0 + sdk: ^3.4.0 dependencies: meta: ^1.4.0 dev_dependencies: - dart_flutter_team_lints: ^2.0.0 + dart_flutter_team_lints: ^3.0.0 # When changing JsonSerializable class. # build_runner: ^2.0.0 # json_serializable: any diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 36ae2f96c..35c941633 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,7 @@ +## 6.8.1-wip + +- Require Dart 3.4 + ## 6.8.0 - Add type arguments to `Map` literals used for `Record` serialization. diff --git a/json_serializable/lib/builder.dart b/json_serializable/lib/builder.dart index 93a3aa2f5..833efcec3 100644 --- a/json_serializable/lib/builder.dart +++ b/json_serializable/lib/builder.dart @@ -10,7 +10,7 @@ /// This library is **not** intended to be imported by typical end-users unless /// you are creating a custom compilation pipeline. See documentation for /// details, and `build.yaml` for how these builders are configured by default. -library json_serializable.builder; +library; import 'package:build/build.dart'; import 'package:json_annotation/json_annotation.dart'; diff --git a/json_serializable/lib/src/decode_helper.dart b/json_serializable/lib/src/decode_helper.dart index a4a76d1ff..488e93ef3 100644 --- a/json_serializable/lib/src/decode_helper.dart +++ b/json_serializable/lib/src/decode_helper.dart @@ -61,7 +61,10 @@ mixin DecodeHelper implements HelperCore { config.constructor, accessibleFields.keys, accessibleFields.values - .where((fe) => element.lookUpSetter(fe.name, element.library) != null) + .where((fe) => + element.augmented + .lookUpSetter(name: fe.name, library: element.library) != + null) .map((fe) => fe.name) .toList(), unavailableReasons, diff --git a/json_serializable/lib/src/field_helpers.dart b/json_serializable/lib/src/field_helpers.dart index 4b6608f3f..f0b7828e9 100644 --- a/json_serializable/lib/src/field_helpers.dart +++ b/json_serializable/lib/src/field_helpers.dart @@ -88,8 +88,8 @@ List<FieldElement> createSortedFieldSet(ClassElement element) { } if (v is PropertyAccessorElement && v.isGetter) { - assert(v.variable is FieldElement); - final variable = v.variable as FieldElement; + assert(v.variable2 is FieldElement); + final variable = v.variable2 as FieldElement; assert(!inheritedFields.containsKey(variable.name)); inheritedFields[variable.name] = variable; } diff --git a/json_serializable/lib/src/helper_core.dart b/json_serializable/lib/src/helper_core.dart index 5a8248c66..0a054f828 100644 --- a/json_serializable/lib/src/helper_core.dart +++ b/json_serializable/lib/src/helper_core.dart @@ -66,7 +66,7 @@ InvalidGenerationSourceError createInvalidGenerationError( String? todo; if (error.type is TypeParameterType) { message = '$message because of type ' - '`${error.type.getDisplayString(withNullability: false)}` ' + '`${error.type.toStringNonNullable()}` ' '(type parameter)'; todo = ''' diff --git a/json_serializable/lib/src/json_key_utils.dart b/json_serializable/lib/src/json_key_utils.dart index 42eb0cfce..addccaae8 100644 --- a/json_serializable/lib/src/json_key_utils.dart +++ b/json_serializable/lib/src/json_key_utils.dart @@ -176,9 +176,9 @@ KeyConfig _from(FieldElement element, ClassConfig classAnnotation) { throwUnsupported( element, '`$fieldName` has type ' - '`${targetEnumType.getDisplayString(withNullability: false)}`, but ' + '`${targetEnumType.toStringNonNullable()}`, but ' 'the provided unknownEnumValue is of type ' - '`${annotationType.getDisplayString(withNullability: false)}`.', + '`${annotationType.toStringNonNullable()}`.', ); } } diff --git a/json_serializable/lib/src/json_serializable_generator.dart b/json_serializable/lib/src/json_serializable_generator.dart index 611056131..2ff7b6dbf 100644 --- a/json_serializable/lib/src/json_serializable_generator.dart +++ b/json_serializable/lib/src/json_serializable_generator.dart @@ -61,14 +61,6 @@ class JsonSerializableGenerator ConstantReader annotation, BuildStep buildStep, ) { - if (!element.library!.isNonNullableByDefault) { - throw InvalidGenerationSourceError( - 'Generator cannot target libraries that have not been migrated to ' - 'null-safety.', - element: element, - ); - } - if (element is! ClassElement || element is EnumElement) { throw InvalidGenerationSourceError( '`@JsonSerializable` can only be used on classes.', diff --git a/json_serializable/lib/src/type_helpers/generic_factory_helper.dart b/json_serializable/lib/src/type_helpers/generic_factory_helper.dart index 3b807550c..6a005f4c6 100644 --- a/json_serializable/lib/src/type_helpers/generic_factory_helper.dart +++ b/json_serializable/lib/src/type_helpers/generic_factory_helper.dart @@ -7,6 +7,7 @@ import 'package:source_helper/source_helper.dart'; import '../lambda_result.dart'; import '../type_helper.dart'; +import '../utils.dart'; class GenericFactoryHelper extends TypeHelper<TypeHelperContextWithConfig> { const GenericFactoryHelper(); @@ -75,11 +76,11 @@ Object? $_toJsonHelperName<T>( '''; String toJsonForType(TypeParameterType type) => - toJsonForName(type.getDisplayString(withNullability: false)); + toJsonForName(type.toStringNonNullable()); String toJsonForName(String genericType) => 'toJson$genericType'; String fromJsonForType(TypeParameterType type) => - fromJsonForName(type.getDisplayString(withNullability: false)); + fromJsonForName(type.toStringNonNullable()); String fromJsonForName(String genericType) => 'fromJson$genericType'; diff --git a/json_serializable/lib/src/type_helpers/map_helper.dart b/json_serializable/lib/src/type_helpers/map_helper.dart index 806c7074e..51cb3a0a5 100644 --- a/json_serializable/lib/src/type_helpers/map_helper.dart +++ b/json_serializable/lib/src/type_helpers/map_helper.dart @@ -94,7 +94,7 @@ class MapHelper extends TypeHelper<TypeHelperContextWithConfig> { // `toDouble` on input values valueArg.isSimpleJsonTypeNotDouble)) { // No mapping of the values or null check required! - final valueString = valueArg.getDisplayString(withNullability: true); + final valueString = valueArg.getDisplayString(); return 'Map<String, $valueString>.from($expression as Map)'; } } diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index 0bf6dba64..782eeb53d 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -177,6 +177,12 @@ Iterable<FieldElement>? iterateEnumFields(DartType targetType) { extension DartTypeExtension on DartType { DartType promoteNonNullable() => element?.library?.typeSystem.promoteToNonNull(this) ?? this; + + String toStringNonNullable() { + final val = getDisplayString(); + if (val.endsWith('?')) return val.substring(0, val.length - 1); + return val; + } } String ifNullOrElse(String test, String ifNull, String ifNotNull) => @@ -216,7 +222,7 @@ String typeToCode( } if (type is TypeParameterType) { - return type.getDisplayString(withNullability: false); + return type.toStringNonNullable(); } throw UnimplementedError('(${type.runtimeType}) $type'); } diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index e6d66865d..2ad1e7a1d 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,11 +1,11 @@ name: json_serializable -version: 6.8.0 +version: 6.8.1-wip description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. repository: https://github.com/google/json_serializable.dart/tree/master/json_serializable environment: - sdk: ^3.0.0 + sdk: ^3.4.0 topics: - json - build-runner @@ -13,32 +13,32 @@ topics: - codegen dependencies: - analyzer: '>=5.12.0 <7.0.0' - async: ^2.8.0 - build: ^2.0.0 - build_config: '>=0.4.4 <2.0.0' - collection: ^1.14.0 + analyzer: ^6.5.0 + async: ^2.10.0 + build: ^2.4.1 + build_config: ^1.1.0 + collection: ^1.17.0 # Use a tight version constraint to ensure that a constraint on # `json_annotation` properly constrains all features it provides. json_annotation: '>=4.9.0 <4.10.0' - meta: ^1.3.0 - path: ^1.8.0 - pub_semver: ^2.0.0 + meta: ^1.14.0 + path: ^1.9.0 + pub_semver: ^2.1.4 pubspec_parse: ^1.0.0 - source_gen: ^1.3.2 - source_helper: ^1.3.0 + source_gen: ^1.4.0 + source_helper: ^1.3.4 dev_dependencies: _json_serial_shared_test: path: ../shared_test - build_runner: ^2.0.0 + build_runner: ^2.4.6 build_verify: ^3.0.0 - dart_flutter_team_lints: ^2.0.0 - dart_style: ^2.0.0 + dart_flutter_team_lints: ^3.0.0 + dart_style: ^2.3.2 logging: ^1.0.0 - source_gen_test: ^1.0.0 - test: ^1.16.0 + source_gen_test: ^1.0.6 + test: ^1.24.4 test_descriptor: ^2.0.0 test_process: ^2.0.0 yaml: ^3.0.0 diff --git a/json_serializable/test/annotation_version_test.dart b/json_serializable/test/annotation_version_test.dart index a12d3398b..1aed36547 100644 --- a/json_serializable/test/annotation_version_test.dart +++ b/json_serializable/test/annotation_version_test.dart @@ -5,7 +5,7 @@ @TestOn('vm') @Tags(['presubmit-only']) @Timeout.factor(2) -library test; +library; import 'dart:io'; diff --git a/json_serializable/test/config_test.dart b/json_serializable/test/config_test.dart index 2bcaa242a..318697f54 100644 --- a/json_serializable/test/config_test.dart +++ b/json_serializable/test/config_test.dart @@ -3,7 +3,7 @@ // BSD-style license that can be found in the LICENSE file. @TestOn('vm') -library test; +library; import 'dart:io'; diff --git a/json_serializable/test/custom_configuration_test.dart b/json_serializable/test/custom_configuration_test.dart index 8fc7ce097..a717b7bb8 100644 --- a/json_serializable/test/custom_configuration_test.dart +++ b/json_serializable/test/custom_configuration_test.dart @@ -3,7 +3,7 @@ // BSD-style license that can be found in the LICENSE file. @TestOn('vm') -library test; +library; import 'dart:async'; diff --git a/json_serializable/test/ensure_build_test.dart b/json_serializable/test/ensure_build_test.dart index a8c75e638..9dac5390d 100644 --- a/json_serializable/test/ensure_build_test.dart +++ b/json_serializable/test/ensure_build_test.dart @@ -4,7 +4,7 @@ @TestOn('vm') @Tags(['presubmit-only']) -library test; +library; import 'package:build_verify/build_verify.dart'; import 'package:test/test.dart'; diff --git a/json_serializable/test/enum_helper_test.dart b/json_serializable/test/enum_helper_test.dart index cfc18ad9b..280ff9e28 100644 --- a/json_serializable/test/enum_helper_test.dart +++ b/json_serializable/test/enum_helper_test.dart @@ -3,7 +3,7 @@ // BSD-style license that can be found in the LICENSE file. @TestOn('vm') -library test; +library; import 'package:json_serializable/src/type_helpers/enum_helper.dart'; import 'package:test/test.dart'; diff --git a/json_serializable/test/json_serializable_test.dart b/json_serializable/test/json_serializable_test.dart index 5644b51cb..b6ff36789 100644 --- a/json_serializable/test/json_serializable_test.dart +++ b/json_serializable/test/json_serializable_test.dart @@ -3,7 +3,7 @@ // BSD-style license that can be found in the LICENSE file. @TestOn('vm') -library test; +library; import 'package:json_serializable/json_serializable.dart'; import 'package:path/path.dart' as p; diff --git a/json_serializable/test/literal/json_literal_test.dart b/json_serializable/test/literal/json_literal_test.dart index edcb7855f..a3f66f836 100644 --- a/json_serializable/test/literal/json_literal_test.dart +++ b/json_serializable/test/literal/json_literal_test.dart @@ -3,7 +3,7 @@ // BSD-style license that can be found in the LICENSE file. @TestOn('vm') -library test; +library; import 'dart:convert'; import 'dart:io'; diff --git a/json_serializable/test/supported_types/extra_map_test.dart b/json_serializable/test/supported_types/extra_map_test.dart index 449a8d9ba..e4fc69c1d 100644 --- a/json_serializable/test/supported_types/extra_map_test.dart +++ b/json_serializable/test/supported_types/extra_map_test.dart @@ -4,7 +4,7 @@ // ignore_for_file: prefer_const_declarations @TestOn('vm') -library test; +library; import 'dart:convert'; diff --git a/json_serializable/test/supported_types/type_test.bigint_test.dart b/json_serializable/test/supported_types/type_test.bigint_test.dart index 26e7a001b..1fa7140da 100644 --- a/json_serializable/test/supported_types/type_test.bigint_test.dart +++ b/json_serializable/test/supported_types/type_test.bigint_test.dart @@ -4,7 +4,7 @@ // ignore_for_file: prefer_const_declarations @TestOn('vm') -library test; +library; import 'dart:convert'; diff --git a/json_serializable/test/supported_types/type_test.bool_test.dart b/json_serializable/test/supported_types/type_test.bool_test.dart index 19247a81c..33d1e9bcc 100644 --- a/json_serializable/test/supported_types/type_test.bool_test.dart +++ b/json_serializable/test/supported_types/type_test.bool_test.dart @@ -4,7 +4,7 @@ // ignore_for_file: prefer_const_declarations @TestOn('vm') -library test; +library; import 'dart:convert'; diff --git a/json_serializable/test/supported_types/type_test.dart b/json_serializable/test/supported_types/type_test.dart index 1d5d72ded..2e7c63a3a 100644 --- a/json_serializable/test/supported_types/type_test.dart +++ b/json_serializable/test/supported_types/type_test.dart @@ -4,7 +4,7 @@ // ignore_for_file: prefer_const_declarations @TestOn('vm') -library test; +library; import 'dart:convert'; diff --git a/json_serializable/test/supported_types/type_test.datetime_test.dart b/json_serializable/test/supported_types/type_test.datetime_test.dart index dee0b5cf5..690cde74c 100644 --- a/json_serializable/test/supported_types/type_test.datetime_test.dart +++ b/json_serializable/test/supported_types/type_test.datetime_test.dart @@ -4,7 +4,7 @@ // ignore_for_file: prefer_const_declarations @TestOn('vm') -library test; +library; import 'dart:convert'; diff --git a/json_serializable/test/supported_types/type_test.double_test.dart b/json_serializable/test/supported_types/type_test.double_test.dart index 4704157ff..31c72aa00 100644 --- a/json_serializable/test/supported_types/type_test.double_test.dart +++ b/json_serializable/test/supported_types/type_test.double_test.dart @@ -4,7 +4,7 @@ // ignore_for_file: prefer_const_declarations @TestOn('vm') -library test; +library; import 'dart:convert'; diff --git a/json_serializable/test/supported_types/type_test.duration_test.dart b/json_serializable/test/supported_types/type_test.duration_test.dart index f7651278c..a928fd914 100644 --- a/json_serializable/test/supported_types/type_test.duration_test.dart +++ b/json_serializable/test/supported_types/type_test.duration_test.dart @@ -4,7 +4,7 @@ // ignore_for_file: prefer_const_declarations @TestOn('vm') -library test; +library; import 'dart:convert'; diff --git a/json_serializable/test/supported_types/type_test.enumtype_test.dart b/json_serializable/test/supported_types/type_test.enumtype_test.dart index cd2b527e4..3c2e8bc9a 100644 --- a/json_serializable/test/supported_types/type_test.enumtype_test.dart +++ b/json_serializable/test/supported_types/type_test.enumtype_test.dart @@ -4,7 +4,7 @@ // ignore_for_file: prefer_const_declarations @TestOn('vm') -library test; +library; import 'dart:convert'; diff --git a/json_serializable/test/supported_types/type_test.int_test.dart b/json_serializable/test/supported_types/type_test.int_test.dart index 9f36677dd..b9f36ec4f 100644 --- a/json_serializable/test/supported_types/type_test.int_test.dart +++ b/json_serializable/test/supported_types/type_test.int_test.dart @@ -4,7 +4,7 @@ // ignore_for_file: prefer_const_declarations @TestOn('vm') -library test; +library; import 'dart:convert'; diff --git a/json_serializable/test/supported_types/type_test.iterable_test.dart b/json_serializable/test/supported_types/type_test.iterable_test.dart index a9c34fee7..b31313d97 100644 --- a/json_serializable/test/supported_types/type_test.iterable_test.dart +++ b/json_serializable/test/supported_types/type_test.iterable_test.dart @@ -4,7 +4,7 @@ // ignore_for_file: prefer_const_declarations @TestOn('vm') -library test; +library; import 'dart:convert'; diff --git a/json_serializable/test/supported_types/type_test.list_test.dart b/json_serializable/test/supported_types/type_test.list_test.dart index 007a386a3..6791be995 100644 --- a/json_serializable/test/supported_types/type_test.list_test.dart +++ b/json_serializable/test/supported_types/type_test.list_test.dart @@ -4,7 +4,7 @@ // ignore_for_file: prefer_const_declarations @TestOn('vm') -library test; +library; import 'dart:convert'; diff --git a/json_serializable/test/supported_types/type_test.map_test.dart b/json_serializable/test/supported_types/type_test.map_test.dart index 54a37fa9c..2ccce34e6 100644 --- a/json_serializable/test/supported_types/type_test.map_test.dart +++ b/json_serializable/test/supported_types/type_test.map_test.dart @@ -4,7 +4,7 @@ // ignore_for_file: prefer_const_declarations @TestOn('vm') -library test; +library; import 'dart:convert'; diff --git a/json_serializable/test/supported_types/type_test.num_test.dart b/json_serializable/test/supported_types/type_test.num_test.dart index 8bc9e72b5..7cd62d61b 100644 --- a/json_serializable/test/supported_types/type_test.num_test.dart +++ b/json_serializable/test/supported_types/type_test.num_test.dart @@ -4,7 +4,7 @@ // ignore_for_file: prefer_const_declarations @TestOn('vm') -library test; +library; import 'dart:convert'; diff --git a/json_serializable/test/supported_types/type_test.object_test.dart b/json_serializable/test/supported_types/type_test.object_test.dart index c7f28dd71..f6333fa7a 100644 --- a/json_serializable/test/supported_types/type_test.object_test.dart +++ b/json_serializable/test/supported_types/type_test.object_test.dart @@ -4,7 +4,7 @@ // ignore_for_file: prefer_const_declarations @TestOn('vm') -library test; +library; import 'dart:convert'; diff --git a/json_serializable/test/supported_types/type_test.set_test.dart b/json_serializable/test/supported_types/type_test.set_test.dart index 4dfc0b82f..12f2521ee 100644 --- a/json_serializable/test/supported_types/type_test.set_test.dart +++ b/json_serializable/test/supported_types/type_test.set_test.dart @@ -4,7 +4,7 @@ // ignore_for_file: prefer_const_declarations @TestOn('vm') -library test; +library; import 'dart:convert'; diff --git a/json_serializable/test/supported_types/type_test.string_test.dart b/json_serializable/test/supported_types/type_test.string_test.dart index f7ed73127..a868de260 100644 --- a/json_serializable/test/supported_types/type_test.string_test.dart +++ b/json_serializable/test/supported_types/type_test.string_test.dart @@ -4,7 +4,7 @@ // ignore_for_file: prefer_const_declarations @TestOn('vm') -library test; +library; import 'dart:convert'; diff --git a/json_serializable/test/supported_types/type_test.uri_test.dart b/json_serializable/test/supported_types/type_test.uri_test.dart index 4b8493ca4..c49a890fa 100644 --- a/json_serializable/test/supported_types/type_test.uri_test.dart +++ b/json_serializable/test/supported_types/type_test.uri_test.dart @@ -4,7 +4,7 @@ // ignore_for_file: prefer_const_declarations @TestOn('vm') -library test; +library; import 'dart:convert'; diff --git a/shared_test/pubspec.yaml b/shared_test/pubspec.yaml index 6cb35af92..975abe375 100644 --- a/shared_test/pubspec.yaml +++ b/shared_test/pubspec.yaml @@ -1,11 +1,11 @@ name: _json_serial_shared_test publish_to: none environment: - sdk: ^3.0.0 + sdk: ^3.4.0 dependencies: stack_trace: ^1.10.0 test: ^1.6.0 dev_dependencies: - dart_flutter_team_lints: ^2.0.0 + dart_flutter_team_lints: ^3.0.0 diff --git a/tool/ci.sh b/tool/ci.sh index 436465312..deac64920 100755 --- a/tool/ci.sh +++ b/tool/ci.sh @@ -1,9 +1,10 @@ #!/bin/bash -# Created with package:mono_repo v6.5.7 +# Created with package:mono_repo v6.6.1 # Support built in commands on windows out of the box. + # When it is a flutter repo (check the pubspec.yaml for "sdk: flutter") -# then "flutter" is called instead of "pub". +# then "flutter pub" is called instead of "dart pub". # This assumes that the Flutter SDK has been installed in a previous step. function pub() { if grep -Fq "sdk: flutter" "${PWD}/pubspec.yaml"; then @@ -12,18 +13,13 @@ function pub() { command dart pub "$@" fi } -# When it is a flutter repo (check the pubspec.yaml for "sdk: flutter") -# then "flutter" is called instead of "pub". -# This assumes that the Flutter SDK has been installed in a previous step. + function format() { - if grep -Fq "sdk: flutter" "${PWD}/pubspec.yaml"; then - command flutter format "$@" - else - command dart format "$@" - fi + command dart format "$@" } + # When it is a flutter repo (check the pubspec.yaml for "sdk: flutter") -# then "flutter" is called instead of "pub". +# then "flutter analyze" is called instead of "dart analyze". # This assumes that the Flutter SDK has been installed in a previous step. function analyze() { if grep -Fq "sdk: flutter" "${PWD}/pubspec.yaml"; then From a7f3893e87bc38339503dc5da09acf6df3784777 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 20 May 2024 15:15:19 -0700 Subject: [PATCH 526/569] --- (#1429) updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/dart.yml | 26 +++++++++++++------------- .github/workflows/markdown_linter.yml | 4 ++-- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 121296a69..49573086a 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -34,7 +34,7 @@ jobs: sdk: stable - id: checkout name: Checkout repository - uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 + uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 - name: mono_repo self validate run: dart pub global activate mono_repo 6.6.1 - name: mono_repo self validate @@ -59,7 +59,7 @@ jobs: sdk: "3.4.0" - id: checkout name: Checkout repository - uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 + uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -125,7 +125,7 @@ jobs: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 + uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -211,7 +211,7 @@ jobs: sdk: "3.4.0" - id: checkout name: Checkout repository - uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 + uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -272,7 +272,7 @@ jobs: sdk: "3.4.0" - id: checkout name: Checkout repository - uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 + uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -306,7 +306,7 @@ jobs: sdk: "3.4.0" - id: checkout name: Checkout repository - uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 + uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -340,7 +340,7 @@ jobs: sdk: "3.4.0" - id: checkout name: Checkout repository - uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 + uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -374,7 +374,7 @@ jobs: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 + uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -435,7 +435,7 @@ jobs: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 + uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -469,7 +469,7 @@ jobs: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 + uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -503,7 +503,7 @@ jobs: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 + uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -537,7 +537,7 @@ jobs: sdk: "3.4.0" - id: checkout name: Checkout repository - uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 + uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -597,7 +597,7 @@ jobs: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 + uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade diff --git a/.github/workflows/markdown_linter.yml b/.github/workflows/markdown_linter.yml index 6cf4457c5..d0a51ba90 100644 --- a/.github/workflows/markdown_linter.yml +++ b/.github/workflows/markdown_linter.yml @@ -11,10 +11,10 @@ jobs: markdown-link-check: runs-on: ubuntu-latest steps: - - uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 + - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 - uses: gaurav-nelson/github-action-markdown-link-check@5c5dfc0ac2e225883c0e5f03a85311ec2830d368 markdown_lint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 + - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 - uses: DavidAnson/markdownlint-cli2-action@510b996878fc0d1a46c8a04ec86b06dbfba09de7 From c672f2d8769275782b8a70efc479b588034813bf Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 20 May 2024 15:15:46 -0700 Subject: [PATCH 527/569] Bump dart-lang/setup-dart from 1.6.2 to 1.6.4 (#1424) Bumps [dart-lang/setup-dart](https://github.com/dart-lang/setup-dart) from 1.6.2 to 1.6.4. - [Release notes](https://github.com/dart-lang/setup-dart/releases) - [Changelog](https://github.com/dart-lang/setup-dart/blob/main/CHANGELOG.md) - [Commits](https://github.com/dart-lang/setup-dart/compare/fedb1266e91cf51be2fdb382869461a434b920a3...f0ead981b4d9a35b37f30d36160575d60931ec30) --- updated-dependencies: - dependency-name: dart-lang/setup-dart dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/dart.yml | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 49573086a..44490feec 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -29,7 +29,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3 + uses: dart-lang/setup-dart@f0ead981b4d9a35b37f30d36160575d60931ec30 with: sdk: stable - id: checkout @@ -54,7 +54,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3 + uses: dart-lang/setup-dart@f0ead981b4d9a35b37f30d36160575d60931ec30 with: sdk: "3.4.0" - id: checkout @@ -120,7 +120,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3 + uses: dart-lang/setup-dart@f0ead981b4d9a35b37f30d36160575d60931ec30 with: sdk: dev - id: checkout @@ -206,7 +206,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3 + uses: dart-lang/setup-dart@f0ead981b4d9a35b37f30d36160575d60931ec30 with: sdk: "3.4.0" - id: checkout @@ -267,7 +267,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3 + uses: dart-lang/setup-dart@f0ead981b4d9a35b37f30d36160575d60931ec30 with: sdk: "3.4.0" - id: checkout @@ -301,7 +301,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3 + uses: dart-lang/setup-dart@f0ead981b4d9a35b37f30d36160575d60931ec30 with: sdk: "3.4.0" - id: checkout @@ -335,7 +335,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3 + uses: dart-lang/setup-dart@f0ead981b4d9a35b37f30d36160575d60931ec30 with: sdk: "3.4.0" - id: checkout @@ -369,7 +369,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3 + uses: dart-lang/setup-dart@f0ead981b4d9a35b37f30d36160575d60931ec30 with: sdk: dev - id: checkout @@ -430,7 +430,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3 + uses: dart-lang/setup-dart@f0ead981b4d9a35b37f30d36160575d60931ec30 with: sdk: dev - id: checkout @@ -464,7 +464,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3 + uses: dart-lang/setup-dart@f0ead981b4d9a35b37f30d36160575d60931ec30 with: sdk: dev - id: checkout @@ -498,7 +498,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3 + uses: dart-lang/setup-dart@f0ead981b4d9a35b37f30d36160575d60931ec30 with: sdk: dev - id: checkout @@ -532,7 +532,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3 + uses: dart-lang/setup-dart@f0ead981b4d9a35b37f30d36160575d60931ec30 with: sdk: "3.4.0" - id: checkout @@ -592,7 +592,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3 + uses: dart-lang/setup-dart@f0ead981b4d9a35b37f30d36160575d60931ec30 with: sdk: dev - id: checkout From a58b190949647dc4aa87be3d6cbc217470408f46 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 20 May 2024 15:26:35 -0700 Subject: [PATCH 528/569] Bump DavidAnson/markdownlint-cli2-action from 15.0.0 to 16.0.0 (#1423) Bumps [DavidAnson/markdownlint-cli2-action](https://github.com/davidanson/markdownlint-cli2-action) from 15.0.0 to 16.0.0. - [Release notes](https://github.com/davidanson/markdownlint-cli2-action/releases) - [Commits](https://github.com/davidanson/markdownlint-cli2-action/compare/510b996878fc0d1a46c8a04ec86b06dbfba09de7...b4c9feab76d8025d1e83c653fa3990936df0e6c8) --- updated-dependencies: - dependency-name: DavidAnson/markdownlint-cli2-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/markdown_linter.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/markdown_linter.yml b/.github/workflows/markdown_linter.yml index d0a51ba90..7951d1884 100644 --- a/.github/workflows/markdown_linter.yml +++ b/.github/workflows/markdown_linter.yml @@ -17,4 +17,4 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 - - uses: DavidAnson/markdownlint-cli2-action@510b996878fc0d1a46c8a04ec86b06dbfba09de7 + - uses: DavidAnson/markdownlint-cli2-action@b4c9feab76d8025d1e83c653fa3990936df0e6c8 From 23dd460fe0f53d6c3915cc7f3a500f3c82f35790 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Mon, 20 May 2024 15:28:47 -0700 Subject: [PATCH 529/569] blast_repo fixes (#1430) dependabot --- .github/dependabot.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index f4169fa24..5524d4ed5 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -10,3 +10,7 @@ updates: interval: monthly labels: - autosubmit + groups: + dependencies: + patterns: + - "*" From ca77b65f505a21d43c41c2b230f9459f3ec6cda7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 30 Jun 2024 21:14:57 -0700 Subject: [PATCH 530/569] Bump the dependencies group with 2 updates (#1434) Bumps the dependencies group with 2 updates: [dart-lang/setup-dart](https://github.com/dart-lang/setup-dart) and [actions/checkout](https://github.com/actions/checkout). Updates `dart-lang/setup-dart` from 1.6.4 to 1.6.5 - [Release notes](https://github.com/dart-lang/setup-dart/releases) - [Changelog](https://github.com/dart-lang/setup-dart/blob/main/CHANGELOG.md) - [Commits](https://github.com/dart-lang/setup-dart/compare/f0ead981b4d9a35b37f30d36160575d60931ec30...0a8a0fc875eb934c15d08629302413c671d3f672) Updates `actions/checkout` from 4.1.6 to 4.1.7 - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/a5ac7e51b41094c92402da3b24376905380afc29...692973e3d937129bcbf40652eb9f2f61becf3332) --- updated-dependencies: - dependency-name: dart-lang/setup-dart dependency-type: direct:production update-type: version-update:semver-patch dependency-group: dependencies - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-patch dependency-group: dependencies ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/dart.yml | 52 +++++++++++++-------------- .github/workflows/markdown_linter.yml | 4 +-- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 44490feec..d03227527 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -29,12 +29,12 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@f0ead981b4d9a35b37f30d36160575d60931ec30 + uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672 with: sdk: stable - id: checkout name: Checkout repository - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 - name: mono_repo self validate run: dart pub global activate mono_repo 6.6.1 - name: mono_repo self validate @@ -54,12 +54,12 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@f0ead981b4d9a35b37f30d36160575d60931ec30 + uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672 with: sdk: "3.4.0" - id: checkout name: Checkout repository - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -120,12 +120,12 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@f0ead981b4d9a35b37f30d36160575d60931ec30 + uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672 with: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -206,12 +206,12 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@f0ead981b4d9a35b37f30d36160575d60931ec30 + uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672 with: sdk: "3.4.0" - id: checkout name: Checkout repository - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -267,12 +267,12 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@f0ead981b4d9a35b37f30d36160575d60931ec30 + uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672 with: sdk: "3.4.0" - id: checkout name: Checkout repository - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -301,12 +301,12 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@f0ead981b4d9a35b37f30d36160575d60931ec30 + uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672 with: sdk: "3.4.0" - id: checkout name: Checkout repository - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -335,12 +335,12 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@f0ead981b4d9a35b37f30d36160575d60931ec30 + uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672 with: sdk: "3.4.0" - id: checkout name: Checkout repository - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -369,12 +369,12 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@f0ead981b4d9a35b37f30d36160575d60931ec30 + uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672 with: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -430,12 +430,12 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@f0ead981b4d9a35b37f30d36160575d60931ec30 + uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672 with: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -464,12 +464,12 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@f0ead981b4d9a35b37f30d36160575d60931ec30 + uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672 with: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -498,12 +498,12 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@f0ead981b4d9a35b37f30d36160575d60931ec30 + uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672 with: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -532,12 +532,12 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@f0ead981b4d9a35b37f30d36160575d60931ec30 + uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672 with: sdk: "3.4.0" - id: checkout name: Checkout repository - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -592,12 +592,12 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@f0ead981b4d9a35b37f30d36160575d60931ec30 + uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672 with: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade diff --git a/.github/workflows/markdown_linter.yml b/.github/workflows/markdown_linter.yml index 7951d1884..9e838ec6d 100644 --- a/.github/workflows/markdown_linter.yml +++ b/.github/workflows/markdown_linter.yml @@ -11,10 +11,10 @@ jobs: markdown-link-check: runs-on: ubuntu-latest steps: - - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 + - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 - uses: gaurav-nelson/github-action-markdown-link-check@5c5dfc0ac2e225883c0e5f03a85311ec2830d368 markdown_lint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 + - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 - uses: DavidAnson/markdownlint-cli2-action@b4c9feab76d8025d1e83c653fa3990936df0e6c8 From ac55cd4ce052b6ab15e643150641f142d7bb18ee Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Mon, 5 Aug 2024 14:25:50 -0700 Subject: [PATCH 531/569] Move to use (experimental) workspaces (#1433) --- .github/workflows/dart.yml | 64 +++++++++++----------- _test_yaml/pubspec.yaml | 12 +--- checked_yaml/pubspec.yaml | 10 +--- example/pubspec.yaml | 12 +--- json_annotation/pubspec.yaml | 4 +- json_serializable/README.md | 18 +++--- json_serializable/pubspec.yaml | 4 +- json_serializable/tool/readme_builder.dart | 14 ++--- pubspec.yaml | 15 +++++ shared_test/pubspec.yaml | 4 +- tool/ci.sh | 2 +- 11 files changed, 82 insertions(+), 77 deletions(-) create mode 100644 pubspec.yaml diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index d03227527..cffabe4cf 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -1,4 +1,4 @@ -# Created with package:mono_repo v6.6.1 +# Created with package:mono_repo v6.6.2 name: Dart CI on: push: @@ -36,27 +36,27 @@ jobs: name: Checkout repository uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 - name: mono_repo self validate - run: dart pub global activate mono_repo 6.6.1 + run: dart pub global activate mono_repo 6.6.2 - name: mono_repo self validate run: dart pub global run mono_repo generate --validate job_002: - name: "analyzer_and_format; Dart 3.4.0; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; `dart analyze`" + name: "analyzer_and_format; Dart 3.5.0-259.0.dev; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; `dart analyze`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.4.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:analyze_1" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0-259.0.dev;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:analyze_1" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:3.4.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable - os:ubuntu-latest;pub-cache-hosted;sdk:3.4.0 + os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0-259.0.dev;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable + os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0-259.0.dev os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672 with: - sdk: "3.4.0" + sdk: "3.5.0-259.0.dev" - id: checkout name: Checkout repository uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 @@ -192,23 +192,23 @@ jobs: if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" working-directory: json_serializable job_004: - name: "unit_test; Dart 3.4.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; `dart test`" + name: "unit_test; Dart 3.5.0-259.0.dev; PKGS: _test_yaml, checked_yaml, example, json_serializable; `dart test`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.4.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0-259.0.dev;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:3.4.0;packages:_test_yaml-checked_yaml-example-json_serializable - os:ubuntu-latest;pub-cache-hosted;sdk:3.4.0 + os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0-259.0.dev;packages:_test_yaml-checked_yaml-example-json_serializable + os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0-259.0.dev os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672 with: - sdk: "3.4.0" + sdk: "3.5.0-259.0.dev" - id: checkout name: Checkout repository uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 @@ -253,23 +253,23 @@ jobs: - job_002 - job_003 job_005: - name: "unit_test; Dart 3.4.0; PKG: json_serializable; `dart test --run-skipped -t presubmit-only test/annotation_version_test.dart`" + name: "unit_test; Dart 3.5.0-259.0.dev; PKG: json_serializable; `dart test --run-skipped -t presubmit-only test/annotation_version_test.dart`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.4.0;packages:json_serializable;commands:test_3" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0-259.0.dev;packages:json_serializable;commands:test_3" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:3.4.0;packages:json_serializable - os:ubuntu-latest;pub-cache-hosted;sdk:3.4.0 + os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0-259.0.dev;packages:json_serializable + os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0-259.0.dev os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672 with: - sdk: "3.4.0" + sdk: "3.5.0-259.0.dev" - id: checkout name: Checkout repository uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 @@ -287,23 +287,23 @@ jobs: - job_002 - job_003 job_006: - name: "unit_test; Dart 3.4.0; PKG: json_serializable; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" + name: "unit_test; Dart 3.5.0-259.0.dev; PKG: json_serializable; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.4.0;packages:json_serializable;commands:test_1" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0-259.0.dev;packages:json_serializable;commands:test_1" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:3.4.0;packages:json_serializable - os:ubuntu-latest;pub-cache-hosted;sdk:3.4.0 + os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0-259.0.dev;packages:json_serializable + os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0-259.0.dev os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672 with: - sdk: "3.4.0" + sdk: "3.5.0-259.0.dev" - id: checkout name: Checkout repository uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 @@ -321,23 +321,23 @@ jobs: - job_002 - job_003 job_007: - name: "unit_test; Dart 3.4.0; PKG: json_serializable; `dart test -p chrome`" + name: "unit_test; Dart 3.5.0-259.0.dev; PKG: json_serializable; `dart test -p chrome`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.4.0;packages:json_serializable;commands:test_2" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0-259.0.dev;packages:json_serializable;commands:test_2" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:3.4.0;packages:json_serializable - os:ubuntu-latest;pub-cache-hosted;sdk:3.4.0 + os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0-259.0.dev;packages:json_serializable + os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0-259.0.dev os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672 with: - sdk: "3.4.0" + sdk: "3.5.0-259.0.dev" - id: checkout name: Checkout repository uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 @@ -518,23 +518,23 @@ jobs: - job_002 - job_003 job_012: - name: "ensure_build; Dart 3.4.0; PKGS: _test_yaml, checked_yaml, example; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" + name: "ensure_build; Dart 3.5.0-259.0.dev; PKGS: _test_yaml, checked_yaml, example; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.4.0;packages:_test_yaml-checked_yaml-example;commands:test_1" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0-259.0.dev;packages:_test_yaml-checked_yaml-example;commands:test_1" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:3.4.0;packages:_test_yaml-checked_yaml-example - os:ubuntu-latest;pub-cache-hosted;sdk:3.4.0 + os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0-259.0.dev;packages:_test_yaml-checked_yaml-example + os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0-259.0.dev os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672 with: - sdk: "3.4.0" + sdk: "3.5.0-259.0.dev" - id: checkout name: Checkout repository uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 diff --git a/_test_yaml/pubspec.yaml b/_test_yaml/pubspec.yaml index 8bf18a935..967c84111 100644 --- a/_test_yaml/pubspec.yaml +++ b/_test_yaml/pubspec.yaml @@ -2,7 +2,9 @@ name: _test_yaml publish_to: none environment: - sdk: ^3.4.0 + sdk: ^3.5.0-259.0.dev + +resolution: workspace dev_dependencies: _json_serial_shared_test: @@ -16,11 +18,3 @@ dev_dependencies: path: ^1.8.2 test: ^1.21.6 yaml: ^3.0.0 - -dependency_overrides: - checked_yaml: - path: ../checked_yaml - json_annotation: - path: ../json_annotation - json_serializable: - path: ../json_serializable diff --git a/checked_yaml/pubspec.yaml b/checked_yaml/pubspec.yaml index 2be93cc62..bc8bcc7e0 100644 --- a/checked_yaml/pubspec.yaml +++ b/checked_yaml/pubspec.yaml @@ -13,7 +13,9 @@ topics: - codegen environment: - sdk: ^3.4.0 + sdk: ^3.5.0-259.0.dev + +resolution: workspace dependencies: json_annotation: ^4.3.0 @@ -28,9 +30,3 @@ dev_dependencies: path: ^1.8.0 test: ^1.17.10 test_process: ^2.0.0 - -#dependency_overrides: -# json_annotation: -# path: ../json_annotation -# json_serializable: -# path: ../json_serializable diff --git a/example/pubspec.yaml b/example/pubspec.yaml index be24d38a3..6e7e6362d 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -2,7 +2,9 @@ name: example publish_to: none environment: - sdk: ^3.4.0 + sdk: ^3.5.0-259.0.dev + +resolution: workspace dependencies: json_annotation: ^4.9.0 @@ -27,11 +29,3 @@ dev_dependencies: # Not required to use `json_serializable`. path: ^1.8.0 test: ^1.21.6 - -# This section is used to verify changes to these packages. Do not include in -# your code! -dependency_overrides: - json_annotation: - path: ../json_annotation - json_serializable: - path: ../json_serializable diff --git a/json_annotation/pubspec.yaml b/json_annotation/pubspec.yaml index 917f8e111..b1bff234c 100644 --- a/json_annotation/pubspec.yaml +++ b/json_annotation/pubspec.yaml @@ -11,7 +11,9 @@ topics: - codegen environment: - sdk: ^3.4.0 + sdk: ^3.5.0-259.0.dev + +resolution: workspace dependencies: meta: ^1.4.0 diff --git a/json_serializable/README.md b/json_serializable/README.md index d30a13659..5d30efd16 100644 --- a/json_serializable/README.md +++ b/json_serializable/README.md @@ -298,15 +298,15 @@ targets: [`Enum`]: https://api.dart.dev/stable/dart-core/Enum-class.html [`int`]: https://api.dart.dev/stable/dart-core/int-class.html [`Iterable`]: https://api.dart.dev/stable/dart-core/Iterable-class.html -[`JsonConverter`]: https://pub.dev/documentation/json_annotation/4.9.0/json_annotation/JsonConverter-class.html -[`JsonEnum.valueField`]: https://pub.dev/documentation/json_annotation/4.9.0/json_annotation/JsonEnum/valueField.html -[`JsonEnum`]: https://pub.dev/documentation/json_annotation/4.9.0/json_annotation/JsonEnum-class.html -[`JsonKey.fromJson`]: https://pub.dev/documentation/json_annotation/4.9.0/json_annotation/JsonKey/fromJson.html -[`JsonKey.toJson`]: https://pub.dev/documentation/json_annotation/4.9.0/json_annotation/JsonKey/toJson.html -[`JsonKey`]: https://pub.dev/documentation/json_annotation/4.9.0/json_annotation/JsonKey-class.html -[`JsonLiteral`]: https://pub.dev/documentation/json_annotation/4.9.0/json_annotation/JsonLiteral-class.html -[`JsonSerializable`]: https://pub.dev/documentation/json_annotation/4.9.0/json_annotation/JsonSerializable-class.html -[`JsonValue`]: https://pub.dev/documentation/json_annotation/4.9.0/json_annotation/JsonValue-class.html +[`JsonConverter`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonConverter-class.html +[`JsonEnum.valueField`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonEnum/valueField.html +[`JsonEnum`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonEnum-class.html +[`JsonKey.fromJson`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/fromJson.html +[`JsonKey.toJson`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/toJson.html +[`JsonKey`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey-class.html +[`JsonLiteral`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonLiteral-class.html +[`JsonSerializable`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable-class.html +[`JsonValue`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonValue-class.html [`List`]: https://api.dart.dev/stable/dart-core/List-class.html [`Map`]: https://api.dart.dev/stable/dart-core/Map-class.html [`num`]: https://api.dart.dev/stable/dart-core/num-class.html diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 2ad1e7a1d..5773ec736 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -5,13 +5,15 @@ description: >- Dart classes. repository: https://github.com/google/json_serializable.dart/tree/master/json_serializable environment: - sdk: ^3.4.0 + sdk: ^3.5.0-259.0.dev topics: - json - build-runner - json-serializable - codegen +resolution: workspace + dependencies: analyzer: ^6.5.0 async: ^2.10.0 diff --git a/json_serializable/tool/readme_builder.dart b/json_serializable/tool/readme_builder.dart index 5de07dfe3..cd832eab5 100644 --- a/json_serializable/tool/readme_builder.dart +++ b/json_serializable/tool/readme_builder.dart @@ -154,13 +154,13 @@ extension on BuildStep { AssetId assetIdForInputPackage(String path) => AssetId(inputId.package, path); Future<String> jsonAnnotationVersion() async { - final lockFileAssetId = assetIdForInputPackage('pubspec.lock'); - final lockFileContent = await readAsString(lockFileAssetId); - final lockFileYaml = - loadYaml(lockFileContent, sourceUrl: lockFileAssetId.uri) as YamlMap; - final pkgMap = lockFileYaml['packages'] as YamlMap; - final jsonAnnotationMap = pkgMap['json_annotation'] as YamlMap; - final jsonAnnotationVersionString = jsonAnnotationMap['version'] as String; + final jsonAnnotationPubspecAssetId = + AssetId('json_annotation', 'pubspec.yaml'); + final jsonAnnotationPubspecContent = + await readAsString(jsonAnnotationPubspecAssetId); + final pubspecYaml = loadYaml(jsonAnnotationPubspecContent, + sourceUrl: jsonAnnotationPubspecAssetId.uri) as YamlMap; + final jsonAnnotationVersionString = pubspecYaml['version'] as String; final jsonAnnotationVersion = Version.parse(jsonAnnotationVersionString.trim()); diff --git a/pubspec.yaml b/pubspec.yaml new file mode 100644 index 000000000..2f7c7b72f --- /dev/null +++ b/pubspec.yaml @@ -0,0 +1,15 @@ +name: json_serial_workspace # Can be anything +environment: + sdk: ^3.5.0-259.0.dev # Must be ^3.5.0 or later for workspace to be allowed + +publish_to: none + +dev_dependencies: + dart_flutter_team_lints: ^3.1.0 +workspace: + - _test_yaml + - checked_yaml + - example + - json_annotation + - json_serializable + - shared_test diff --git a/shared_test/pubspec.yaml b/shared_test/pubspec.yaml index 975abe375..f88ea12db 100644 --- a/shared_test/pubspec.yaml +++ b/shared_test/pubspec.yaml @@ -1,7 +1,9 @@ name: _json_serial_shared_test publish_to: none environment: - sdk: ^3.4.0 + sdk: ^3.5.0-259.0.dev + +resolution: workspace dependencies: stack_trace: ^1.10.0 diff --git a/tool/ci.sh b/tool/ci.sh index deac64920..c6a601c34 100755 --- a/tool/ci.sh +++ b/tool/ci.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Created with package:mono_repo v6.6.1 +# Created with package:mono_repo v6.6.2 # Support built in commands on windows out of the box. From 27df6994e14028dde3901b157c00bdd04d6f3d4c Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Tue, 6 Aug 2024 09:58:43 -0700 Subject: [PATCH 532/569] Move SDK constraint to map to 3.5 stable (#1440) --- .github/workflows/dart.yml | 60 +++++++++++++++++----------------- _test_yaml/pubspec.yaml | 2 +- checked_yaml/CHANGELOG.md | 2 +- checked_yaml/pubspec.yaml | 2 +- example/pubspec.yaml | 2 +- json_annotation/CHANGELOG.md | 2 +- json_annotation/pubspec.yaml | 2 +- json_serializable/CHANGELOG.md | 2 +- json_serializable/pubspec.yaml | 2 +- pubspec.yaml | 2 +- shared_test/pubspec.yaml | 2 +- 11 files changed, 40 insertions(+), 40 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index cffabe4cf..85a9d8d5b 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -40,23 +40,23 @@ jobs: - name: mono_repo self validate run: dart pub global run mono_repo generate --validate job_002: - name: "analyzer_and_format; Dart 3.5.0-259.0.dev; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; `dart analyze`" + name: "analyzer_and_format; Dart 3.5.0; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; `dart analyze`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0-259.0.dev;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:analyze_1" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:analyze_1" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0-259.0.dev;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable - os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0-259.0.dev + os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable + os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672 with: - sdk: "3.5.0-259.0.dev" + sdk: "3.5.0" - id: checkout name: Checkout repository uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 @@ -192,23 +192,23 @@ jobs: if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" working-directory: json_serializable job_004: - name: "unit_test; Dart 3.5.0-259.0.dev; PKGS: _test_yaml, checked_yaml, example, json_serializable; `dart test`" + name: "unit_test; Dart 3.5.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; `dart test`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0-259.0.dev;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0-259.0.dev;packages:_test_yaml-checked_yaml-example-json_serializable - os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0-259.0.dev + os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0;packages:_test_yaml-checked_yaml-example-json_serializable + os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672 with: - sdk: "3.5.0-259.0.dev" + sdk: "3.5.0" - id: checkout name: Checkout repository uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 @@ -253,23 +253,23 @@ jobs: - job_002 - job_003 job_005: - name: "unit_test; Dart 3.5.0-259.0.dev; PKG: json_serializable; `dart test --run-skipped -t presubmit-only test/annotation_version_test.dart`" + name: "unit_test; Dart 3.5.0; PKG: json_serializable; `dart test --run-skipped -t presubmit-only test/annotation_version_test.dart`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0-259.0.dev;packages:json_serializable;commands:test_3" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0;packages:json_serializable;commands:test_3" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0-259.0.dev;packages:json_serializable - os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0-259.0.dev + os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0;packages:json_serializable + os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672 with: - sdk: "3.5.0-259.0.dev" + sdk: "3.5.0" - id: checkout name: Checkout repository uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 @@ -287,23 +287,23 @@ jobs: - job_002 - job_003 job_006: - name: "unit_test; Dart 3.5.0-259.0.dev; PKG: json_serializable; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" + name: "unit_test; Dart 3.5.0; PKG: json_serializable; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0-259.0.dev;packages:json_serializable;commands:test_1" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0;packages:json_serializable;commands:test_1" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0-259.0.dev;packages:json_serializable - os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0-259.0.dev + os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0;packages:json_serializable + os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672 with: - sdk: "3.5.0-259.0.dev" + sdk: "3.5.0" - id: checkout name: Checkout repository uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 @@ -321,23 +321,23 @@ jobs: - job_002 - job_003 job_007: - name: "unit_test; Dart 3.5.0-259.0.dev; PKG: json_serializable; `dart test -p chrome`" + name: "unit_test; Dart 3.5.0; PKG: json_serializable; `dart test -p chrome`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0-259.0.dev;packages:json_serializable;commands:test_2" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0;packages:json_serializable;commands:test_2" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0-259.0.dev;packages:json_serializable - os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0-259.0.dev + os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0;packages:json_serializable + os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672 with: - sdk: "3.5.0-259.0.dev" + sdk: "3.5.0" - id: checkout name: Checkout repository uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 @@ -518,23 +518,23 @@ jobs: - job_002 - job_003 job_012: - name: "ensure_build; Dart 3.5.0-259.0.dev; PKGS: _test_yaml, checked_yaml, example; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" + name: "ensure_build; Dart 3.5.0; PKGS: _test_yaml, checked_yaml, example; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0-259.0.dev;packages:_test_yaml-checked_yaml-example;commands:test_1" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0;packages:_test_yaml-checked_yaml-example;commands:test_1" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0-259.0.dev;packages:_test_yaml-checked_yaml-example - os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0-259.0.dev + os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0;packages:_test_yaml-checked_yaml-example + os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672 with: - sdk: "3.5.0-259.0.dev" + sdk: "3.5.0" - id: checkout name: Checkout repository uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 diff --git a/_test_yaml/pubspec.yaml b/_test_yaml/pubspec.yaml index 967c84111..e189c8ee8 100644 --- a/_test_yaml/pubspec.yaml +++ b/_test_yaml/pubspec.yaml @@ -2,7 +2,7 @@ name: _test_yaml publish_to: none environment: - sdk: ^3.5.0-259.0.dev + sdk: ^3.5.0 resolution: workspace diff --git a/checked_yaml/CHANGELOG.md b/checked_yaml/CHANGELOG.md index 543b0ce5e..292ecc01a 100644 --- a/checked_yaml/CHANGELOG.md +++ b/checked_yaml/CHANGELOG.md @@ -1,6 +1,6 @@ ## 2.0.4-wip -- Require Dart 3.4 +- Require Dart 3.5 ## 2.0.3 diff --git a/checked_yaml/pubspec.yaml b/checked_yaml/pubspec.yaml index bc8bcc7e0..d86daebf6 100644 --- a/checked_yaml/pubspec.yaml +++ b/checked_yaml/pubspec.yaml @@ -13,7 +13,7 @@ topics: - codegen environment: - sdk: ^3.5.0-259.0.dev + sdk: ^3.5.0 resolution: workspace diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 6e7e6362d..c75056710 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -2,7 +2,7 @@ name: example publish_to: none environment: - sdk: ^3.5.0-259.0.dev + sdk: ^3.5.0 resolution: workspace diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index 911e1d671..0c341a220 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -1,6 +1,6 @@ ## 4.9.1-wip -- Require Dart 3.4 +- Require Dart 3.5 ## 4.9.0 diff --git a/json_annotation/pubspec.yaml b/json_annotation/pubspec.yaml index b1bff234c..86ed2b1ad 100644 --- a/json_annotation/pubspec.yaml +++ b/json_annotation/pubspec.yaml @@ -11,7 +11,7 @@ topics: - codegen environment: - sdk: ^3.5.0-259.0.dev + sdk: ^3.5.0 resolution: workspace diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 35c941633..222e369d9 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,6 +1,6 @@ ## 6.8.1-wip -- Require Dart 3.4 +- Require Dart 3.5 ## 6.8.0 diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 5773ec736..29c37c4cc 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -5,7 +5,7 @@ description: >- Dart classes. repository: https://github.com/google/json_serializable.dart/tree/master/json_serializable environment: - sdk: ^3.5.0-259.0.dev + sdk: ^3.5.0 topics: - json - build-runner diff --git a/pubspec.yaml b/pubspec.yaml index 2f7c7b72f..028d1d235 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: json_serial_workspace # Can be anything environment: - sdk: ^3.5.0-259.0.dev # Must be ^3.5.0 or later for workspace to be allowed + sdk: ^3.5.0 publish_to: none diff --git a/shared_test/pubspec.yaml b/shared_test/pubspec.yaml index f88ea12db..ee379c326 100644 --- a/shared_test/pubspec.yaml +++ b/shared_test/pubspec.yaml @@ -1,7 +1,7 @@ name: _json_serial_shared_test publish_to: none environment: - sdk: ^3.5.0-259.0.dev + sdk: ^3.5.0 resolution: workspace From 9ccbbb2b51c95f4b74d0886be240f48a74cf7d48 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Thu, 8 Aug 2024 16:22:22 -0700 Subject: [PATCH 533/569] Update and fix lints (#1442) --- _test_yaml/pubspec.yaml | 1 - checked_yaml/pubspec.yaml | 1 - example/pubspec.yaml | 3 --- json_annotation/lib/src/json_converter.dart | 2 +- json_annotation/lib/src/json_serializable.dart | 2 +- json_annotation/pubspec.yaml | 6 ------ json_serializable/pubspec.yaml | 1 - pubspec.yaml | 2 +- shared_test/pubspec.yaml | 3 --- 9 files changed, 3 insertions(+), 18 deletions(-) diff --git a/_test_yaml/pubspec.yaml b/_test_yaml/pubspec.yaml index e189c8ee8..f54503684 100644 --- a/_test_yaml/pubspec.yaml +++ b/_test_yaml/pubspec.yaml @@ -12,7 +12,6 @@ dev_dependencies: build_runner: ^2.2.1 build_verify: ^3.0.0 checked_yaml: ^2.0.4-wip - dart_flutter_team_lints: ^3.0.0 json_annotation: ^4.9.0 json_serializable: ^6.8.0 path: ^1.8.2 diff --git a/checked_yaml/pubspec.yaml b/checked_yaml/pubspec.yaml index d86daebf6..bb765cb1d 100644 --- a/checked_yaml/pubspec.yaml +++ b/checked_yaml/pubspec.yaml @@ -25,7 +25,6 @@ dependencies: dev_dependencies: build_runner: ^2.0.6 build_verify: ^3.0.0 - dart_flutter_team_lints: ^3.0.0 json_serializable: ^6.0.0 path: ^1.8.0 test: ^1.17.10 diff --git a/example/pubspec.yaml b/example/pubspec.yaml index c75056710..0875abdd3 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -20,9 +20,6 @@ dev_dependencies: # Used by tests. Not required to use `json_serializable`. build_verify: ^3.0.0 - # Not required to use `json_serializable`. - dart_flutter_team_lints: ^3.0.0 - # REQUIRED! json_serializable: ^6.8.0 diff --git a/json_annotation/lib/src/json_converter.dart b/json_annotation/lib/src/json_converter.dart index bd0738e80..d50db4f4b 100644 --- a/json_annotation/lib/src/json_converter.dart +++ b/json_annotation/lib/src/json_converter.dart @@ -7,7 +7,7 @@ /// [T] is the data type you'd like to convert to and from. /// /// [S] is the type of the value stored in JSON. It must be a valid JSON type -/// such as [String], [int], or [Map<String, dynamic>]. +/// such as [String], [int], or [Map]`<String, dynamic>`. /// /// /// [JsonConverter]s can be placed either on the class: diff --git a/json_annotation/lib/src/json_serializable.dart b/json_annotation/lib/src/json_serializable.dart index fb4d8eade..64d1990e0 100644 --- a/json_annotation/lib/src/json_serializable.dart +++ b/json_annotation/lib/src/json_serializable.dart @@ -39,7 +39,7 @@ enum FieldRename { ) @Target({TargetKind.classType}) class JsonSerializable { - /// If `true`, [Map] types are *not* assumed to be [Map<String, dynamic>] + /// If `true`, [Map] types are *not* assumed to be [Map]`<String, dynamic>` /// – which is the default type of [Map] instances return by JSON decode in /// `dart:convert`. /// diff --git a/json_annotation/pubspec.yaml b/json_annotation/pubspec.yaml index 86ed2b1ad..cf334679b 100644 --- a/json_annotation/pubspec.yaml +++ b/json_annotation/pubspec.yaml @@ -17,9 +17,3 @@ resolution: workspace dependencies: meta: ^1.4.0 - -dev_dependencies: - dart_flutter_team_lints: ^3.0.0 -# When changing JsonSerializable class. -# build_runner: ^2.0.0 -# json_serializable: any diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 29c37c4cc..1adf0afb2 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -36,7 +36,6 @@ dev_dependencies: path: ../shared_test build_runner: ^2.4.6 build_verify: ^3.0.0 - dart_flutter_team_lints: ^3.0.0 dart_style: ^2.3.2 logging: ^1.0.0 source_gen_test: ^1.0.6 diff --git a/pubspec.yaml b/pubspec.yaml index 028d1d235..ac2343cc3 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -5,7 +5,7 @@ environment: publish_to: none dev_dependencies: - dart_flutter_team_lints: ^3.1.0 + dart_flutter_team_lints: ^3.2.0 workspace: - _test_yaml - checked_yaml diff --git a/shared_test/pubspec.yaml b/shared_test/pubspec.yaml index ee379c326..09b960f69 100644 --- a/shared_test/pubspec.yaml +++ b/shared_test/pubspec.yaml @@ -8,6 +8,3 @@ resolution: workspace dependencies: stack_trace: ^1.10.0 test: ^1.6.0 - -dev_dependencies: - dart_flutter_team_lints: ^3.0.0 From 55d68f4f57d9fbfca96dff9f53a7cdc0c9208792 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Thu, 8 Aug 2024 21:30:40 -0700 Subject: [PATCH 534/569] Use map syntax to clean up `null` handling in `toJson` functions (#1443) --- _test_yaml/test/src/build_config.g.dart | 39 ++-- example/lib/example.g.dart | 53 ++--- example/test/example_test.dart | 8 +- json_serializable/CHANGELOG.md | 3 +- json_serializable/lib/src/constants.dart | 3 +- json_serializable/lib/src/encoder_helper.dart | 97 ++------- json_serializable/pubspec.yaml | 2 +- .../test/custom_configuration_test.dart | 1 - .../integration/converter_examples.g.dart | 69 +++--- .../create_per_field_to_json_example.g.dart | 31 +-- .../test/integration/json_enum_example.g.dart | 20 +- .../test/integration/json_test_example.g.dart | 56 ++--- .../json_test_example.g_any_map.g.dart | 56 ++--- .../kitchen_sink.g_exclude_null.g.dart | 203 +++++++++--------- .../src/_json_serializable_test_input.dart | 19 +- .../test/src/inheritance_test_input.dart | 45 ++-- .../test/src/to_from_json_test_input.dart | 17 +- 17 files changed, 261 insertions(+), 461 deletions(-) diff --git a/_test_yaml/test/src/build_config.g.dart b/_test_yaml/test/src/build_config.g.dart index 61e578ec4..e4d832e78 100644 --- a/_test_yaml/test/src/build_config.g.dart +++ b/_test_yaml/test/src/build_config.g.dart @@ -103,28 +103,23 @@ Builder _$BuilderFromJson(Map json) => $checkedCreate( }, ); -Map<String, dynamic> _$BuilderToJson(Builder instance) { - final val = <String, dynamic>{}; - - void writeNotNull(String key, dynamic value) { - if (value != null) { - val[key] = value; - } - } - - writeNotNull('target', instance.target); - writeNotNull('import', instance.import); - writeNotNull('is_optional', instance.isOptional); - writeNotNull('configLocation', instance.configLocation?.toString()); - writeNotNull('auto_apply', _$AutoApplyEnumMap[instance.autoApply]); - writeNotNull('build_to', _$BuildToEnumMap[instance.buildTo]); - writeNotNull('defaultEnumTest', _$AutoApplyEnumMap[instance.defaultEnumTest]); - val['builder_factories'] = instance.builderFactories; - writeNotNull('applies_builders', instance.appliesBuilders); - writeNotNull('required_inputs', instance.requiredInputs); - writeNotNull('build_extensions', instance.buildExtensions); - return val; -} +Map<String, dynamic> _$BuilderToJson(Builder instance) => <String, dynamic>{ + if (instance.target case final value?) 'target': value, + if (instance.import case final value?) 'import': value, + if (instance.isOptional case final value?) 'is_optional': value, + if (instance.configLocation?.toString() case final value?) + 'configLocation': value, + if (_$AutoApplyEnumMap[instance.autoApply] case final value?) + 'auto_apply': value, + if (_$BuildToEnumMap[instance.buildTo] case final value?) + 'build_to': value, + if (_$AutoApplyEnumMap[instance.defaultEnumTest] case final value?) + 'defaultEnumTest': value, + 'builder_factories': instance.builderFactories, + if (instance.appliesBuilders case final value?) 'applies_builders': value, + if (instance.requiredInputs case final value?) 'required_inputs': value, + if (instance.buildExtensions case final value?) 'build_extensions': value, + }; const _$BuildToEnumMap = { BuildTo.cache: 'cache', diff --git a/example/lib/example.g.dart b/example/lib/example.g.dart index b4cf7de11..f497bc0e7 100644 --- a/example/lib/example.g.dart +++ b/example/lib/example.g.dart @@ -19,24 +19,14 @@ Person _$PersonFromJson(Map<String, dynamic> json) => Person( .toList(), ); -Map<String, dynamic> _$PersonToJson(Person instance) { - final val = <String, dynamic>{ - 'firstName': instance.firstName, - }; - - void writeNotNull(String key, dynamic value) { - if (value != null) { - val[key] = value; - } - } - - writeNotNull('middleName', instance.middleName); - val['lastName'] = instance.lastName; - val['date-of-birth'] = instance.dateOfBirth.toIso8601String(); - val['last-order'] = instance.lastOrder?.toIso8601String(); - val['orders'] = instance.orders; - return val; -} +Map<String, dynamic> _$PersonToJson(Person instance) => <String, dynamic>{ + 'firstName': instance.firstName, + if (instance.middleName case final value?) 'middleName': value, + 'lastName': instance.lastName, + 'date-of-birth': instance.dateOfBirth.toIso8601String(), + 'last-order': instance.lastOrder?.toIso8601String(), + 'orders': instance.orders, + }; Order _$OrderFromJson(Map<String, dynamic> json) => Order( Order._dateTimeFromEpochUs((json['date'] as num).toInt()), @@ -50,23 +40,16 @@ Order _$OrderFromJson(Map<String, dynamic> json) => Order( ..prepTime = Order._durationFromMilliseconds((json['prep-time'] as num?)?.toInt()); -Map<String, dynamic> _$OrderToJson(Order instance) { - final val = <String, dynamic>{}; - - void writeNotNull(String key, dynamic value) { - if (value != null) { - val[key] = value; - } - } - - writeNotNull('count', instance.count); - writeNotNull('itemNumber', instance.itemNumber); - writeNotNull('isRushed', instance.isRushed); - writeNotNull('item', instance.item); - writeNotNull('prep-time', Order._durationToMilliseconds(instance.prepTime)); - writeNotNull('date', Order._dateTimeToEpochUs(instance.date)); - return val; -} +Map<String, dynamic> _$OrderToJson(Order instance) => <String, dynamic>{ + if (instance.count case final value?) 'count': value, + if (instance.itemNumber case final value?) 'itemNumber': value, + if (instance.isRushed case final value?) 'isRushed': value, + if (instance.item case final value?) 'item': value, + if (Order._durationToMilliseconds(instance.prepTime) case final value?) + 'prep-time': value, + if (Order._dateTimeToEpochUs(instance.date) case final value?) + 'date': value, + }; Item _$ItemFromJson(Map<String, dynamic> json) => Item() ..count = (json['count'] as num?)?.toInt() diff --git a/example/test/example_test.dart b/example/test/example_test.dart index e2abf3424..99dc2ed53 100644 --- a/example/test/example_test.dart +++ b/example/test/example_test.dart @@ -10,8 +10,12 @@ import 'package:test/test.dart'; void main() { test('JsonSerializable', () { - final person = Person('Inigo', 'Montoya', DateTime(1560, 5, 5)) - ..orders = [Order(DateTime.now())..item = (Item()..count = 42)]; + final person = Person( + 'Inigo', + 'Montoya', + DateTime(1560, 5, 5), + middleName: 'Bob', + )..orders = [Order(DateTime.now())..item = (Item()..count = 42)]; final personJson = loudEncode(person); diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 222e369d9..7c14862e2 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,5 +1,6 @@ -## 6.8.1-wip +## 6.9.0-wip +- Use conditional map syntax to clean up `null` handling in `toJson` functions. - Require Dart 3.5 ## 6.8.0 diff --git a/json_serializable/lib/src/constants.dart b/json_serializable/lib/src/constants.dart index 9949b77cc..a151ff034 100644 --- a/json_serializable/lib/src/constants.dart +++ b/json_serializable/lib/src/constants.dart @@ -5,8 +5,7 @@ /// Name used for closure argument when generating calls to `map`. const closureArg = 'e'; -const generatedLocalVarName = 'val'; -const toJsonMapHelperName = 'writeNotNull'; +const generatedLocalVarName = 'value'; const converterOrKeyInstructions = r''' * Use `JsonConverter` diff --git a/json_serializable/lib/src/encoder_helper.dart b/json_serializable/lib/src/encoder_helper.dart index 05d4c714d..4e876b757 100644 --- a/json_serializable/lib/src/encoder_helper.dart +++ b/json_serializable/lib/src/encoder_helper.dart @@ -97,18 +97,22 @@ mixin EncodeHelper implements HelperCore { if (config.genericArgumentFactories) _writeGenericArgumentFactories(buffer); - buffer.write(') '); + buffer + ..write(') ') + ..writeln('=> <String, dynamic>{') + ..writeAll(accessibleFields.map((field) { + final access = _fieldAccess(field); - final canWriteAllJsonValuesWithoutNullCheck = - accessibleFields.every(_canWriteJsonWithoutNullCheck); + final keyExpression = safeNameAccess(field); + final valueExpression = _serializeField(field, access); - if (canWriteAllJsonValuesWithoutNullCheck) { - // write simple `toJson` method that includes all keys... - _writeToJsonSimple(buffer, accessibleFields); - } else { - // At least one field should be excluded if null - _writeToJsonWithNullChecks(buffer, accessibleFields); - } + final keyValuePair = _canWriteJsonWithoutNullCheck(field) + ? '$keyExpression: $valueExpression' + : 'if ($valueExpression case final $generatedLocalVarName?) ' + '$keyExpression: $generatedLocalVarName'; + return ' $keyValuePair,\n'; + })) + ..writeln('};'); yield buffer.toString(); } @@ -125,81 +129,8 @@ mixin EncodeHelper implements HelperCore { } } - void _writeToJsonSimple(StringBuffer buffer, Iterable<FieldElement> fields) { - buffer - ..writeln('=> <String, dynamic>{') - ..writeAll(fields.map((field) { - final access = _fieldAccess(field); - final value = - '${safeNameAccess(field)}: ${_serializeField(field, access)}'; - return ' $value,\n'; - })) - ..writeln('};'); - } - static const _toJsonParamName = 'instance'; - void _writeToJsonWithNullChecks( - StringBuffer buffer, - Iterable<FieldElement> fields, - ) { - buffer - ..writeln('{') - ..writeln(' final $generatedLocalVarName = <String, dynamic>{'); - - // Note that the map literal is left open above. As long as target fields - // don't need to be intercepted by the `only if null` logic, write them - // to the map literal directly. In theory, should allow more efficient - // serialization. - var directWrite = true; - - for (final field in fields) { - var safeFieldAccess = _fieldAccess(field); - final safeJsonKeyString = safeNameAccess(field); - - // If `fieldName` collides with one of the local helpers, prefix - // access with `this.`. - if (safeFieldAccess == generatedLocalVarName || - safeFieldAccess == toJsonMapHelperName) { - safeFieldAccess = 'this.$safeFieldAccess'; - } - - final expression = _serializeField(field, safeFieldAccess); - if (_canWriteJsonWithoutNullCheck(field)) { - if (directWrite) { - buffer.writeln(' $safeJsonKeyString: $expression,'); - } else { - buffer.writeln( - ' $generatedLocalVarName[$safeJsonKeyString] = $expression;'); - } - } else { - if (directWrite) { - // close the still-open map literal - buffer - ..writeln(' };') - ..writeln() - - // write the helper to be used by all following null-excluding - // fields - ..writeln(''' - void $toJsonMapHelperName(String key, dynamic value) { - if (value != null) { - $generatedLocalVarName[key] = value; - } - } -'''); - directWrite = false; - } - buffer.writeln( - ' $toJsonMapHelperName($safeJsonKeyString, $expression);'); - } - } - - buffer - ..writeln(' return $generatedLocalVarName;') - ..writeln(' }'); - } - String _serializeField(FieldElement field, String accessExpression) { try { return getHelperContext(field) diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 1adf0afb2..854f2c7fd 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 6.8.1-wip +version: 6.9.0-wip description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. diff --git a/json_serializable/test/custom_configuration_test.dart b/json_serializable/test/custom_configuration_test.dart index a717b7bb8..4ac5d02ca 100644 --- a/json_serializable/test/custom_configuration_test.dart +++ b/json_serializable/test/custom_configuration_test.dart @@ -214,7 +214,6 @@ Map<String, dynamic> _$TrivialNestedNonNullableToJson( test('some', () async { final output = await runForElementNamed('IncludeIfNullAll'); expect(output, isNot(contains(generatedLocalVarName))); - expect(output, isNot(contains(toJsonMapHelperName))); }); }); } diff --git a/json_serializable/test/integration/converter_examples.g.dart b/json_serializable/test/integration/converter_examples.g.dart index 2829672a9..f19c8fc2e 100644 --- a/json_serializable/test/integration/converter_examples.g.dart +++ b/json_serializable/test/integration/converter_examples.g.dart @@ -26,33 +26,26 @@ Issue1202RegressionClass _$Issue1202RegressionClassFromJson( ); Map<String, dynamic> _$Issue1202RegressionClassToJson( - Issue1202RegressionClass instance) { - final val = <String, dynamic>{ - 'valueWithFunctions': - Issue1202RegressionClass._toJson(instance.valueWithFunctions), - 'notNullableValueWithConverter': - const _Issue1202RegressionNotNullConverter() - .toJson(instance.notNullableValueWithConverter), - }; - - void writeNotNull(String key, dynamic value) { - if (value != null) { - val[key] = value; - } - } - - writeNotNull('value', _$Issue1202RegressionEnumEnumMap[instance.value]); - writeNotNull('normalNullableValue', instance.normalNullableValue); - writeNotNull( - 'notNullableValueWithNullableConverter', - const _Issue1202RegressionConverter() - .toJson(instance.notNullableValueWithNullableConverter)); - writeNotNull( - 'valueWithNullableFunctions', - Issue1202RegressionClass._toJsonNullable( - instance.valueWithNullableFunctions)); - return val; -} + Issue1202RegressionClass instance) => + <String, dynamic>{ + 'valueWithFunctions': + Issue1202RegressionClass._toJson(instance.valueWithFunctions), + 'notNullableValueWithConverter': + const _Issue1202RegressionNotNullConverter() + .toJson(instance.notNullableValueWithConverter), + if (_$Issue1202RegressionEnumEnumMap[instance.value] case final value?) + 'value': value, + if (instance.normalNullableValue case final value?) + 'normalNullableValue': value, + if (const _Issue1202RegressionConverter() + .toJson(instance.notNullableValueWithNullableConverter) + case final value?) + 'notNullableValueWithNullableConverter': value, + if (Issue1202RegressionClass._toJsonNullable( + instance.valueWithNullableFunctions) + case final value?) + 'valueWithNullableFunctions': value, + }; const _$Issue1202RegressionEnumEnumMap = { Issue1202RegressionEnum.normalValue: 42, @@ -65,21 +58,13 @@ Regression1229 _$Regression1229FromJson(Map<String, dynamic> json) => json['date'], const DateTimeConverter().fromJson), ); -Map<String, dynamic> _$Regression1229ToJson(Regression1229 instance) { - final val = <String, dynamic>{}; - - void writeNotNull(String key, dynamic value) { - if (value != null) { - val[key] = value; - } - } - - writeNotNull( - 'date', - _$JsonConverterToJson<String, DateTime>( - instance.date, const DateTimeConverter().toJson)); - return val; -} +Map<String, dynamic> _$Regression1229ToJson(Regression1229 instance) => + <String, dynamic>{ + if (_$JsonConverterToJson<String, DateTime>( + instance.date, const DateTimeConverter().toJson) + case final value?) + 'date': value, + }; Value? _$JsonConverterFromJson<Json, Value>( Object? json, diff --git a/json_serializable/test/integration/create_per_field_to_json_example.g.dart b/json_serializable/test/integration/create_per_field_to_json_example.g.dart index 1c4b0fe88..28f3443a5 100644 --- a/json_serializable/test/integration/create_per_field_to_json_example.g.dart +++ b/json_serializable/test/integration/create_per_field_to_json_example.g.dart @@ -45,26 +45,17 @@ abstract class _$ModelPerFieldToJson { static Object? nestedExcludeIfNull(Nested? instance) => instance?.toJson(); } -Map<String, dynamic> _$ModelToJson(Model instance) { - final val = <String, dynamic>{ - 'firstName': instance.firstName, - 'lastName': instance.lastName, - 'enumValue': _$EnumValueEnumMap[instance.enumValue], - 'nested': instance.nested?.toJson(), - 'nestedGeneric': instance.nestedGeneric?.toJson( - (value) => value, - ), - }; - - void writeNotNull(String key, dynamic value) { - if (value != null) { - val[key] = value; - } - } - - writeNotNull('nestedExcludeIfNull', instance.nestedExcludeIfNull?.toJson()); - return val; -} +Map<String, dynamic> _$ModelToJson(Model instance) => <String, dynamic>{ + 'firstName': instance.firstName, + 'lastName': instance.lastName, + 'enumValue': _$EnumValueEnumMap[instance.enumValue], + 'nested': instance.nested?.toJson(), + 'nestedGeneric': instance.nestedGeneric?.toJson( + (value) => value, + ), + if (instance.nestedExcludeIfNull?.toJson() case final value?) + 'nestedExcludeIfNull': value, + }; const _$EnumValueEnumMap = { EnumValue.first: '1', diff --git a/json_serializable/test/integration/json_enum_example.g.dart b/json_serializable/test/integration/json_enum_example.g.dart index 6408e9e1d..95ae41b17 100644 --- a/json_serializable/test/integration/json_enum_example.g.dart +++ b/json_serializable/test/integration/json_enum_example.g.dart @@ -53,19 +53,13 @@ Issue1226Regression _$Issue1226RegressionFromJson(Map<String, dynamic> json) => _$Issue1145RegressionEnumEnumMap, json['durationType']), ); -Map<String, dynamic> _$Issue1226RegressionToJson(Issue1226Regression instance) { - final val = <String, dynamic>{}; - - void writeNotNull(String key, dynamic value) { - if (value != null) { - val[key] = value; - } - } - - writeNotNull( - 'durationType', _$Issue1145RegressionEnumEnumMap[instance.durationType]); - return val; -} +Map<String, dynamic> _$Issue1226RegressionToJson( + Issue1226Regression instance) => + <String, dynamic>{ + if (_$Issue1145RegressionEnumEnumMap[instance.durationType] + case final value?) + 'durationType': value, + }; const _$StandAloneEnumEnumMap = { StandAloneEnum.alpha: 'a', diff --git a/json_serializable/test/integration/json_test_example.g.dart b/json_serializable/test/integration/json_test_example.g.dart index ec12eb554..bf56859ed 100644 --- a/json_serializable/test/integration/json_test_example.g.dart +++ b/json_serializable/test/integration/json_test_example.g.dart @@ -85,26 +85,17 @@ Order _$OrderFromJson(Map<String, dynamic> json) { StatusCode.success; } -Map<String, dynamic> _$OrderToJson(Order instance) { - final val = <String, dynamic>{}; - - void writeNotNull(String key, dynamic value) { - if (value != null) { - val[key] = value; - } - } - - writeNotNull('count', instance.count); - val['isRushed'] = instance.isRushed; - val['duration'] = instance.duration?.inMicroseconds; - val['category'] = _$CategoryEnumMap[instance.category]; - val['items'] = instance.items; - val['platform'] = instance.platform; - val['altPlatforms'] = instance.altPlatforms; - val['homepage'] = instance.homepage?.toString(); - val['status_code'] = _$StatusCodeEnumMap[instance.statusCode]; - return val; -} +Map<String, dynamic> _$OrderToJson(Order instance) => <String, dynamic>{ + if (instance.count case final value?) 'count': value, + 'isRushed': instance.isRushed, + 'duration': instance.duration?.inMicroseconds, + 'category': _$CategoryEnumMap[instance.category], + 'items': instance.items, + 'platform': instance.platform, + 'altPlatforms': instance.altPlatforms, + 'homepage': instance.homepage?.toString(), + 'status_code': _$StatusCodeEnumMap[instance.statusCode], + }; const _$StatusCodeEnumMap = { StatusCode.success: 200, @@ -125,24 +116,13 @@ Item _$ItemFromJson(Map<String, dynamic> json) => Item( .toList() ..geoPoint = _fromJsonGeoPoint(json['geoPoint'] as Map<String, dynamic>?); -Map<String, dynamic> _$ItemToJson(Item instance) { - final val = <String, dynamic>{ - 'price': instance.price, - }; - - void writeNotNull(String key, dynamic value) { - if (value != null) { - val[key] = value; - } - } - - writeNotNull('item-number', instance.itemNumber); - val['saleDates'] = - instance.saleDates?.map((e) => e.toIso8601String()).toList(); - val['rates'] = instance.rates; - val['geoPoint'] = _toJsonGeoPoint(instance.geoPoint); - return val; -} +Map<String, dynamic> _$ItemToJson(Item instance) => <String, dynamic>{ + 'price': instance.price, + if (instance.itemNumber case final value?) 'item-number': value, + 'saleDates': instance.saleDates?.map((e) => e.toIso8601String()).toList(), + 'rates': instance.rates, + 'geoPoint': _toJsonGeoPoint(instance.geoPoint), + }; Numbers _$NumbersFromJson(Map<String, dynamic> json) => Numbers() ..ints = diff --git a/json_serializable/test/integration/json_test_example.g_any_map.g.dart b/json_serializable/test/integration/json_test_example.g_any_map.g.dart index 5fe79152e..ef2ad4f95 100644 --- a/json_serializable/test/integration/json_test_example.g_any_map.g.dart +++ b/json_serializable/test/integration/json_test_example.g_any_map.g.dart @@ -85,26 +85,17 @@ Order _$OrderFromJson(Map json) { StatusCode.success; } -Map<String, dynamic> _$OrderToJson(Order instance) { - final val = <String, dynamic>{}; - - void writeNotNull(String key, dynamic value) { - if (value != null) { - val[key] = value; - } - } - - writeNotNull('count', instance.count); - val['isRushed'] = instance.isRushed; - val['duration'] = instance.duration?.inMicroseconds; - val['category'] = _$CategoryEnumMap[instance.category]; - val['items'] = instance.items; - val['platform'] = instance.platform; - val['altPlatforms'] = instance.altPlatforms; - val['homepage'] = instance.homepage?.toString(); - val['status_code'] = _$StatusCodeEnumMap[instance.statusCode]; - return val; -} +Map<String, dynamic> _$OrderToJson(Order instance) => <String, dynamic>{ + if (instance.count case final value?) 'count': value, + 'isRushed': instance.isRushed, + 'duration': instance.duration?.inMicroseconds, + 'category': _$CategoryEnumMap[instance.category], + 'items': instance.items, + 'platform': instance.platform, + 'altPlatforms': instance.altPlatforms, + 'homepage': instance.homepage?.toString(), + 'status_code': _$StatusCodeEnumMap[instance.statusCode], + }; const _$StatusCodeEnumMap = { StatusCode.success: 200, @@ -125,24 +116,13 @@ Item _$ItemFromJson(Map json) => Item( .toList() ..geoPoint = _fromJsonGeoPoint(json['geoPoint'] as Map<String, dynamic>?); -Map<String, dynamic> _$ItemToJson(Item instance) { - final val = <String, dynamic>{ - 'price': instance.price, - }; - - void writeNotNull(String key, dynamic value) { - if (value != null) { - val[key] = value; - } - } - - writeNotNull('item-number', instance.itemNumber); - val['saleDates'] = - instance.saleDates?.map((e) => e.toIso8601String()).toList(); - val['rates'] = instance.rates; - val['geoPoint'] = _toJsonGeoPoint(instance.geoPoint); - return val; -} +Map<String, dynamic> _$ItemToJson(Item instance) => <String, dynamic>{ + 'price': instance.price, + if (instance.itemNumber case final value?) 'item-number': value, + 'saleDates': instance.saleDates?.map((e) => e.toIso8601String()).toList(), + 'rates': instance.rates, + 'geoPoint': _toJsonGeoPoint(instance.geoPoint), + }; Numbers _$NumbersFromJson(Map json) => Numbers() ..ints = diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart index a3a8f8550..39b0eb184 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart @@ -98,69 +98,63 @@ KitchenSink _$KitchenSinkFromJson(Map<String, dynamic> json) => KitchenSink( ), ); -Map<String, dynamic> _$KitchenSinkToJson(KitchenSink instance) { - final val = <String, dynamic>{}; - - void writeNotNull(String key, dynamic value) { - if (value != null) { - val[key] = value; - } - } - - writeNotNull('no-42', instance.ctorValidatedNo42); - writeNotNull('dateTime', instance.dateTime?.toIso8601String()); - writeNotNull('bigInt', instance.bigInt?.toString()); - writeNotNull('iterable', instance.iterable?.toList()); - val['dynamicIterable'] = instance.dynamicIterable.toList(); - val['objectIterable'] = instance.objectIterable.toList(); - val['intIterable'] = instance.intIterable.toList(); - val['set'] = instance.set.toList(); - val['dynamicSet'] = instance.dynamicSet.toList(); - val['objectSet'] = instance.objectSet.toList(); - val['intSet'] = instance.intSet.toList(); - val['dateTimeSet'] = - instance.dateTimeSet.map((e) => e.toIso8601String()).toList(); - val['datetime-iterable'] = - instance.dateTimeIterable.map((e) => e.toIso8601String()).toList(); - val['list'] = instance.list; - val['dynamicList'] = instance.dynamicList; - val['objectList'] = instance.objectList; - val['intList'] = instance.intList; - val['dateTimeList'] = - instance.dateTimeList.map((e) => e.toIso8601String()).toList(); - val['nullableSimpleObjectList'] = instance.nullableSimpleObjectList; - val['map'] = instance.map; - val['stringStringMap'] = instance.stringStringMap; - val['dynamicIntMap'] = instance.dynamicIntMap; - val['objectDateTimeMap'] = instance.objectDateTimeMap - .map((k, e) => MapEntry(k, e.toIso8601String())); - val['nullableSimpleObjectMap'] = instance.nullableSimpleObjectMap; - val['crazyComplex'] = instance.crazyComplex - .map((e) => e?.map((k, e) => MapEntry( - k, - e?.map((k, e) => MapEntry( +Map<String, dynamic> _$KitchenSinkToJson(KitchenSink instance) => + <String, dynamic>{ + if (instance.ctorValidatedNo42 case final value?) 'no-42': value, + if (instance.dateTime?.toIso8601String() case final value?) + 'dateTime': value, + if (instance.bigInt?.toString() case final value?) 'bigInt': value, + if (instance.iterable?.toList() case final value?) 'iterable': value, + 'dynamicIterable': instance.dynamicIterable.toList(), + 'objectIterable': instance.objectIterable.toList(), + 'intIterable': instance.intIterable.toList(), + 'set': instance.set.toList(), + 'dynamicSet': instance.dynamicSet.toList(), + 'objectSet': instance.objectSet.toList(), + 'intSet': instance.intSet.toList(), + 'dateTimeSet': + instance.dateTimeSet.map((e) => e.toIso8601String()).toList(), + 'datetime-iterable': + instance.dateTimeIterable.map((e) => e.toIso8601String()).toList(), + 'list': instance.list, + 'dynamicList': instance.dynamicList, + 'objectList': instance.objectList, + 'intList': instance.intList, + 'dateTimeList': + instance.dateTimeList.map((e) => e.toIso8601String()).toList(), + 'nullableSimpleObjectList': instance.nullableSimpleObjectList, + 'map': instance.map, + 'stringStringMap': instance.stringStringMap, + 'dynamicIntMap': instance.dynamicIntMap, + 'objectDateTimeMap': instance.objectDateTimeMap + .map((k, e) => MapEntry(k, e.toIso8601String())), + 'nullableSimpleObjectMap': instance.nullableSimpleObjectMap, + 'crazyComplex': instance.crazyComplex + .map((e) => e?.map((k, e) => MapEntry( k, - e - ?.map((e) => e?.map((e) => e.toIso8601String()).toList()) - .toList()))))) - .toList(); - val['val'] = instance.val; - writeNotNull('writeNotNull', instance.writeNotNull); - writeNotNull(r'$string', instance.string); - val['simpleObject'] = instance.simpleObject; - val['strictKeysObject'] = instance.strictKeysObject; - writeNotNull('validatedPropertyNo42', instance.validatedPropertyNo42); - writeNotNull( - 'recordField', - instance.recordField == null - ? null - : <String, dynamic>{ - r'$1': instance.recordField!.$1, - r'$2': instance.recordField!.$2, - 'truth': instance.recordField!.truth, - }); - return val; -} + e?.map((k, e) => MapEntry( + k, + e + ?.map((e) => e?.map((e) => e.toIso8601String()).toList()) + .toList()))))) + .toList(), + 'val': instance.val, + if (instance.writeNotNull case final value?) 'writeNotNull': value, + if (instance.string case final value?) r'$string': value, + 'simpleObject': instance.simpleObject, + 'strictKeysObject': instance.strictKeysObject, + if (instance.validatedPropertyNo42 case final value?) + 'validatedPropertyNo42': value, + if (instance.recordField == null + ? null + : <String, dynamic>{ + r'$1': instance.recordField!.$1, + r'$2': instance.recordField!.$2, + 'truth': instance.recordField!.truth, + } + case final value?) + 'recordField': value, + }; $Rec? _$recordConvertNullable<$Rec>( Object? value, @@ -208,50 +202,47 @@ JsonConverterTestClass _$JsonConverterTestClassFromJson( ); Map<String, dynamic> _$JsonConverterTestClassToJson( - JsonConverterTestClass instance) { - final val = <String, dynamic>{}; - - void writeNotNull(String key, dynamic value) { - if (value != null) { - val[key] = value; - } - } - - writeNotNull('duration', - const DurationMillisecondConverter().toJson(instance.duration)); - val['durationList'] = instance.durationList - .map(const DurationMillisecondConverter().toJson) - .toList(); - val['bigInt'] = const BigIntStringConverter().toJson(instance.bigInt); - val['bigIntMap'] = instance.bigIntMap - .map((k, e) => MapEntry(k, const BigIntStringConverter().toJson(e))); - writeNotNull( - 'nullableBigInt', - _$JsonConverterToJson<String, BigInt>( - instance.nullableBigInt, const BigIntStringConverter().toJson)); - val['nullableBigIntMap'] = instance.nullableBigIntMap.map((k, e) => MapEntry( - k, - _$JsonConverterToJson<String, BigInt>( - e, const BigIntStringConverter().toJson))); - writeNotNull('numberSilly', - TrivialNumberConverter.instance.toJson(instance.numberSilly)); - val['numberSillySet'] = instance.numberSillySet - .map(TrivialNumberConverter.instance.toJson) - .toList(); - writeNotNull( - 'dateTime', const EpochDateTimeConverter().toJson(instance.dateTime)); - writeNotNull( - 'trivialString', trivialStringConverter.toJson(instance.trivialString)); - writeNotNull( - 'nullableNumberSilly', - _$JsonConverterToJson<int?, TrivialNumber>(instance.nullableNumberSilly, - TrivialNumberConverter.instance.toJson)); - val['nullableNumberSillySet'] = instance.nullableNumberSillySet - .map((e) => _$JsonConverterToJson<int?, TrivialNumber>( - e, TrivialNumberConverter.instance.toJson)) - .toList(); - return val; -} + JsonConverterTestClass instance) => + <String, dynamic>{ + if (const DurationMillisecondConverter().toJson(instance.duration) + case final value?) + 'duration': value, + 'durationList': instance.durationList + .map(const DurationMillisecondConverter().toJson) + .toList(), + 'bigInt': const BigIntStringConverter().toJson(instance.bigInt), + 'bigIntMap': instance.bigIntMap + .map((k, e) => MapEntry(k, const BigIntStringConverter().toJson(e))), + if (_$JsonConverterToJson<String, BigInt>( + instance.nullableBigInt, const BigIntStringConverter().toJson) + case final value?) + 'nullableBigInt': value, + 'nullableBigIntMap': instance.nullableBigIntMap.map((k, e) => MapEntry( + k, + _$JsonConverterToJson<String, BigInt>( + e, const BigIntStringConverter().toJson))), + if (TrivialNumberConverter.instance.toJson(instance.numberSilly) + case final value?) + 'numberSilly': value, + 'numberSillySet': instance.numberSillySet + .map(TrivialNumberConverter.instance.toJson) + .toList(), + if (const EpochDateTimeConverter().toJson(instance.dateTime) + case final value?) + 'dateTime': value, + if (trivialStringConverter.toJson(instance.trivialString) + case final value?) + 'trivialString': value, + if (_$JsonConverterToJson<int?, TrivialNumber>( + instance.nullableNumberSilly, + TrivialNumberConverter.instance.toJson) + case final value?) + 'nullableNumberSilly': value, + 'nullableNumberSillySet': instance.nullableNumberSillySet + .map((e) => _$JsonConverterToJson<int?, TrivialNumber>( + e, TrivialNumberConverter.instance.toJson)) + .toList(), + }; Value? _$JsonConverterFromJson<Json, Value>( Object? json, diff --git a/json_serializable/test/src/_json_serializable_test_input.dart b/json_serializable/test/src/_json_serializable_test_input.dart index 1458630ff..f8537f346 100644 --- a/json_serializable/test/src/_json_serializable_test_input.dart +++ b/json_serializable/test/src/_json_serializable_test_input.dart @@ -215,20 +215,11 @@ class NoDeserializeBadKey { @ShouldGenerate( r''' Map<String, dynamic> _$IncludeIfNullOverrideToJson( - IncludeIfNullOverride instance) { - final val = <String, dynamic>{ - 'number': instance.number, - }; - - void writeNotNull(String key, dynamic value) { - if (value != null) { - val[key] = value; - } - } - - writeNotNull('str', instance.str); - return val; -} + IncludeIfNullOverride instance) => + <String, dynamic>{ + 'number': instance.number, + if (instance.str case final value?) 'str': value, + }; ''', ) @JsonSerializable(createFactory: false, includeIfNull: false) diff --git a/json_serializable/test/src/inheritance_test_input.dart b/json_serializable/test/src/inheritance_test_input.dart index 875743fc7..921e442e3 100644 --- a/json_serializable/test/src/inheritance_test_input.dart +++ b/json_serializable/test/src/inheritance_test_input.dart @@ -8,22 +8,13 @@ SubType _$SubTypeFromJson(Map<String, dynamic> json) => SubType( ..superReadWriteField = (json['superReadWriteField'] as num?)?.toInt() ..subTypeReadWrite = (json['subTypeReadWrite'] as num).toInt(); -Map<String, dynamic> _$SubTypeToJson(SubType instance) { - final val = <String, dynamic>{ - 'super-final-field': instance.superFinalField, - }; - - void writeNotNull(String key, dynamic value) { - if (value != null) { - val[key] = value; - } - } - - writeNotNull('superReadWriteField', instance.superReadWriteField); - val['subTypeViaCtor'] = instance.subTypeViaCtor; - val['subTypeReadWrite'] = instance.subTypeReadWrite; - return val; -} +Map<String, dynamic> _$SubTypeToJson(SubType instance) => <String, dynamic>{ + 'super-final-field': instance.superFinalField, + if (instance.superReadWriteField case final value?) + 'superReadWriteField': value, + 'subTypeViaCtor': instance.subTypeViaCtor, + 'subTypeReadWrite': instance.subTypeReadWrite, + }; ''') @JsonSerializable() class SubType extends SuperType { @@ -54,21 +45,13 @@ class SuperType { @ShouldGenerate(r''' Map<String, dynamic> _$SubTypeWithAnnotatedFieldOverrideExtendsToJson( - SubTypeWithAnnotatedFieldOverrideExtends instance) { - final val = <String, dynamic>{ - 'super-final-field': instance.superFinalField, - }; - - void writeNotNull(String key, dynamic value) { - if (value != null) { - val[key] = value; - } - } - - writeNotNull('superReadWriteField', instance.superReadWriteField); - val['priceHalf'] = instance.priceHalf; - return val; -} + SubTypeWithAnnotatedFieldOverrideExtends instance) => + <String, dynamic>{ + 'super-final-field': instance.superFinalField, + if (instance.superReadWriteField case final value?) + 'superReadWriteField': value, + 'priceHalf': instance.priceHalf, + }; ''') @JsonSerializable(createFactory: false) class SubTypeWithAnnotatedFieldOverrideExtends extends SuperType { diff --git a/json_serializable/test/src/to_from_json_test_input.dart b/json_serializable/test/src/to_from_json_test_input.dart index 7e5f57965..abeb24be2 100644 --- a/json_serializable/test/src/to_from_json_test_input.dart +++ b/json_serializable/test/src/to_from_json_test_input.dart @@ -175,18 +175,11 @@ String? _toStringNullOnEmpty(String input) => input.isEmpty ? null : input; @ShouldGenerate( r''' Map<String, dynamic> _$ToJsonNullableFalseIncludeIfNullFalseToJson( - ToJsonNullableFalseIncludeIfNullFalse instance) { - final val = <String, dynamic>{}; - - void writeNotNull(String key, dynamic value) { - if (value != null) { - val[key] = value; - } - } - - writeNotNull('field', _toStringNullOnEmpty(instance.field)); - return val; -} + ToJsonNullableFalseIncludeIfNullFalse instance) => + <String, dynamic>{ + if (_toStringNullOnEmpty(instance.field) case final value?) + 'field': value, + }; ''', ) @JsonSerializable(createFactory: false) From 59c6376a497a382e25ad3721215a4715dd7baa28 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Mon, 30 Sep 2024 10:37:51 -0700 Subject: [PATCH 535/569] Ignore lint about deprecated pkg:analyzer API (#1447) Can't move to the new API until Dart 3.6 is stable --- json_serializable/lib/src/field_helpers.dart | 4 ++++ .../lib/src/type_helpers/json_converter_helper.dart | 1 + json_serializable/lib/src/utils.dart | 4 ++++ 3 files changed, 9 insertions(+) diff --git a/json_serializable/lib/src/field_helpers.dart b/json_serializable/lib/src/field_helpers.dart index f0b7828e9..b315a1401 100644 --- a/json_serializable/lib/src/field_helpers.dart +++ b/json_serializable/lib/src/field_helpers.dart @@ -2,6 +2,10 @@ // 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. +// TODO: Waiting until Dart 3.6 so we can pin a stable Dart SDK compatible w/ latest +// analyzer +// ignore_for_file: deprecated_member_use + import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/src/dart/element/inheritance_manager3.dart' // ignore: implementation_imports show diff --git a/json_serializable/lib/src/type_helpers/json_converter_helper.dart b/json_serializable/lib/src/type_helpers/json_converter_helper.dart index ce78f19d1..4f1192703 100644 --- a/json_serializable/lib/src/type_helpers/json_converter_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_converter_helper.dart @@ -214,6 +214,7 @@ _JsonConvertData? _typeConverterFrom( final annotationElement = match.elementAnnotation?.element; if (annotationElement is PropertyAccessorElement) { + // ignore: deprecated_member_use final enclosing = annotationElement.enclosingElement; var accessString = annotationElement.name; diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index 782eeb53d..84ef4695b 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -2,6 +2,10 @@ // 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. +// TODO: Waiting until Dart 3.6 so we can pin a stable Dart SDK compatible w/ latest +// analyzer +// ignore_for_file: deprecated_member_use + import 'package:analyzer/dart/constant/value.dart'; import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/type.dart'; From 3e4dbe3ff6b7989e99e835a6533ce6fcfb2a8e51 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 8 Oct 2024 10:41:04 -0700 Subject: [PATCH 536/569] Bump the dependencies group with 2 updates (#1448) Bumps the dependencies group with 2 updates: [actions/checkout](https://github.com/actions/checkout) and [DavidAnson/markdownlint-cli2-action](https://github.com/davidanson/markdownlint-cli2-action). Updates `actions/checkout` from 4.1.7 to 4.2.0 - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/692973e3d937129bcbf40652eb9f2f61becf3332...d632683dd7b4114ad314bca15554477dd762a938) Updates `DavidAnson/markdownlint-cli2-action` from 16.0.0 to 17.0.0 - [Release notes](https://github.com/davidanson/markdownlint-cli2-action/releases) - [Commits](https://github.com/davidanson/markdownlint-cli2-action/compare/b4c9feab76d8025d1e83c653fa3990936df0e6c8...db43aef879112c3119a410d69f66701e0d530809) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-minor dependency-group: dependencies - dependency-name: DavidAnson/markdownlint-cli2-action dependency-type: direct:production update-type: version-update:semver-major dependency-group: dependencies ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/dart.yml | 26 +++++++++++++------------- .github/workflows/markdown_linter.yml | 6 +++--- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 85a9d8d5b..473dfcac0 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -34,7 +34,7 @@ jobs: sdk: stable - id: checkout name: Checkout repository - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 - name: mono_repo self validate run: dart pub global activate mono_repo 6.6.2 - name: mono_repo self validate @@ -59,7 +59,7 @@ jobs: sdk: "3.5.0" - id: checkout name: Checkout repository - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -125,7 +125,7 @@ jobs: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -211,7 +211,7 @@ jobs: sdk: "3.5.0" - id: checkout name: Checkout repository - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -272,7 +272,7 @@ jobs: sdk: "3.5.0" - id: checkout name: Checkout repository - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -306,7 +306,7 @@ jobs: sdk: "3.5.0" - id: checkout name: Checkout repository - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -340,7 +340,7 @@ jobs: sdk: "3.5.0" - id: checkout name: Checkout repository - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -374,7 +374,7 @@ jobs: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -435,7 +435,7 @@ jobs: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -469,7 +469,7 @@ jobs: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -503,7 +503,7 @@ jobs: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -537,7 +537,7 @@ jobs: sdk: "3.5.0" - id: checkout name: Checkout repository - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -597,7 +597,7 @@ jobs: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade diff --git a/.github/workflows/markdown_linter.yml b/.github/workflows/markdown_linter.yml index 9e838ec6d..19a330eab 100644 --- a/.github/workflows/markdown_linter.yml +++ b/.github/workflows/markdown_linter.yml @@ -11,10 +11,10 @@ jobs: markdown-link-check: runs-on: ubuntu-latest steps: - - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 + - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 - uses: gaurav-nelson/github-action-markdown-link-check@5c5dfc0ac2e225883c0e5f03a85311ec2830d368 markdown_lint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 - - uses: DavidAnson/markdownlint-cli2-action@b4c9feab76d8025d1e83c653fa3990936df0e6c8 + - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 + - uses: DavidAnson/markdownlint-cli2-action@db43aef879112c3119a410d69f66701e0d530809 From 2c2c78d2757e0a7af1a155d1afc4f38bdecf304b Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Tue, 29 Oct 2024 07:14:00 -0700 Subject: [PATCH 537/569] blast_repo fixes (#1452) This PR contains changes created by the blast repo tool. - `drop-lint` --- analysis_options.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index 4786eef5b..f45a2193b 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -19,12 +19,10 @@ linter: - literal_only_boolean_expressions - missing_whitespace_between_adjacent_strings - no_runtimeType_toString - - package_api_docs - prefer_const_declarations - prefer_expression_function_bodies - prefer_final_locals - sort_child_properties_last - unnecessary_breaks - - unsafe_html - use_full_hex_values_for_flutter_colors - use_string_buffers From 2cb379b6d45e21afd101bab633fd0d4334b3c707 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 31 Oct 2024 21:53:31 -0700 Subject: [PATCH 538/569] Bump the dependencies group with 2 updates (#1453) Bumps the dependencies group with 2 updates: [actions/cache](https://github.com/actions/cache) and [actions/checkout](https://github.com/actions/checkout). Updates `actions/cache` from 4.0.2 to 4.1.2 - [Release notes](https://github.com/actions/cache/releases) - [Changelog](https://github.com/actions/cache/blob/main/RELEASES.md) - [Commits](https://github.com/actions/cache/compare/0c45773b623bea8c8e75f6c82b208c3cf94ea4f9...6849a6489940f00c2f30c0fb92c6274307ccb58a) Updates `actions/checkout` from 4.2.0 to 4.2.2 - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/d632683dd7b4114ad314bca15554477dd762a938...11bd71901bbe5b1630ceea73d27597364c9af683) --- updated-dependencies: - dependency-name: actions/cache dependency-type: direct:production update-type: version-update:semver-minor dependency-group: dependencies - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-patch dependency-group: dependencies ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/dart.yml | 52 +++++++++++++-------------- .github/workflows/markdown_linter.yml | 4 +-- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 473dfcac0..9ec40b575 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -21,7 +21,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 + uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:stable" @@ -34,7 +34,7 @@ jobs: sdk: stable - id: checkout name: Checkout repository - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 - name: mono_repo self validate run: dart pub global activate mono_repo 6.6.2 - name: mono_repo self validate @@ -44,7 +44,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 + uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:analyze_1" @@ -59,7 +59,7 @@ jobs: sdk: "3.5.0" - id: checkout name: Checkout repository - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -110,7 +110,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 + uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:format-analyze_0" @@ -125,7 +125,7 @@ jobs: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -196,7 +196,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 + uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" @@ -211,7 +211,7 @@ jobs: sdk: "3.5.0" - id: checkout name: Checkout repository - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -257,7 +257,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 + uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0;packages:json_serializable;commands:test_3" @@ -272,7 +272,7 @@ jobs: sdk: "3.5.0" - id: checkout name: Checkout repository - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -291,7 +291,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 + uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0;packages:json_serializable;commands:test_1" @@ -306,7 +306,7 @@ jobs: sdk: "3.5.0" - id: checkout name: Checkout repository - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -325,7 +325,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 + uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0;packages:json_serializable;commands:test_2" @@ -340,7 +340,7 @@ jobs: sdk: "3.5.0" - id: checkout name: Checkout repository - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -359,7 +359,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 + uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" @@ -374,7 +374,7 @@ jobs: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -420,7 +420,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 + uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:json_serializable;commands:test_3" @@ -435,7 +435,7 @@ jobs: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -454,7 +454,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 + uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:json_serializable;commands:test_1" @@ -469,7 +469,7 @@ jobs: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -488,7 +488,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 + uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:json_serializable;commands:test_2" @@ -503,7 +503,7 @@ jobs: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 - id: json_serializable_pub_upgrade name: json_serializable; dart pub upgrade run: dart pub upgrade @@ -522,7 +522,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 + uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0;packages:_test_yaml-checked_yaml-example;commands:test_1" @@ -537,7 +537,7 @@ jobs: sdk: "3.5.0" - id: checkout name: Checkout repository - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade @@ -582,7 +582,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 + uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:_test_yaml-checked_yaml-example;commands:test_1" @@ -597,7 +597,7 @@ jobs: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 - id: _test_yaml_pub_upgrade name: _test_yaml; dart pub upgrade run: dart pub upgrade diff --git a/.github/workflows/markdown_linter.yml b/.github/workflows/markdown_linter.yml index 19a330eab..61ee20394 100644 --- a/.github/workflows/markdown_linter.yml +++ b/.github/workflows/markdown_linter.yml @@ -11,10 +11,10 @@ jobs: markdown-link-check: runs-on: ubuntu-latest steps: - - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 - uses: gaurav-nelson/github-action-markdown-link-check@5c5dfc0ac2e225883c0e5f03a85311ec2830d368 markdown_lint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 - uses: DavidAnson/markdownlint-cli2-action@db43aef879112c3119a410d69f66701e0d530809 From 396ef693a6750420ccee2407ad45482be45bf1dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20P=C3=A9rez?= <dnv7.soft@gmail.com> Date: Mon, 11 Nov 2024 21:50:24 -0300 Subject: [PATCH 539/569] Refactor JsonKey class documentation to improve code readability and consistency (#1456) --- json_annotation/lib/src/json_key.dart | 76 +++++++++++++-------------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/json_annotation/lib/src/json_key.dart b/json_annotation/lib/src/json_key.dart index d7c97b65b..1dc7653bc 100644 --- a/json_annotation/lib/src/json_key.dart +++ b/json_annotation/lib/src/json_key.dart @@ -1,4 +1,4 @@ -// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file +// Copyright (c) 2018, 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. @@ -19,13 +19,13 @@ class JsonKey { final Object? defaultValue; /// If `true`, generated code will throw a [DisallowedNullValueException] if - /// the corresponding key exists, but the value is `null`. + /// the corresponding key exists, but its value is `null`. /// /// Note: this value does not affect the behavior of a JSON map *without* the /// associated key. /// /// If [disallowNullValue] is `true`, [includeIfNull] will be treated as - /// `false` to ensure compatibility between `toJson` and `fromJson`. + /// `false` to ensure consistency between `toJson` and `fromJson`. /// /// If both [includeIfNull] and [disallowNullValue] are set to `true` on the /// same field, an exception will be thrown during code generation. @@ -39,8 +39,9 @@ class JsonKey { /// type of the annotated field. /// /// When creating a class that supports both `toJson` and `fromJson` - /// (the default), you should also set [toJson] if you set [fromJson]. - /// Values returned by [toJson] should "round-trip" through [fromJson]. + /// (the default behavior), it is recommended to also set [toJson] if + /// [fromJson] is set. Values returned by [toJson] should "round-trip" + /// through [fromJson]. final Function? fromJson; /// `true` if the generator should ignore this field completely. @@ -48,7 +49,7 @@ class JsonKey { /// If `null` (the default) or `false`, the field will be considered for /// serialization. /// - /// This field is DEPRECATED use [includeFromJson] and [includeToJson] + /// This field is DEPRECATED; use [includeFromJson] and [includeToJson] /// instead. @Deprecated( 'Use `includeFromJson` and `includeToJson` with a value of `false` ' @@ -56,23 +57,23 @@ class JsonKey { ) final bool? ignore; - /// Used to force a field to be included (or excluded) when decoding a object - /// from JSON. + /// Determines whether a field should be included (or excluded) when decoding + /// an object from JSON. /// - /// `null` (the default) means the field will be handled with the default - /// semantics that take into account if it's private or if it can be cleanly - /// round-tripped to-from JSON. + /// `null` (the default) means the field will be handled with default + /// semantics that consider whether it's private or if it can be cleanly + /// round-tripped to and from JSON. /// - /// `true` means the field should always be decoded, even if it's private. + /// `true` forces the field to always be decoded, even if it's private. /// - /// `false` means the field should never be decoded. + /// `false` prevents the field from being decoded. final bool? includeFromJson; - /// Whether the generator should include fields with `null` values in the + /// Specifies whether fields with `null` values should be included in the /// serialized output. /// - /// If `true`, the generator should include the field in the serialized - /// output, even if the value is `null`. + /// If `true`, the field will be included in the serialized output even if its + /// value is `null`. /// /// The default value, `null`, indicates that the behavior should be /// acquired from the [JsonSerializable.includeIfNull] annotation on the @@ -85,44 +86,43 @@ class JsonKey { /// same field, an exception will be thrown during code generation. final bool? includeIfNull; - /// Used to force a field to be included (or excluded) when encoding a object - /// to JSON. + /// Determines whether a field should be included (or excluded) when encoding + /// an object to JSON. /// /// `null` (the default) means the field will be handled with the default /// semantics that take into account if it's private or if it can be cleanly /// round-tripped to-from JSON. /// - /// `true` means the field should always be encoded, even if it's private. + /// `true` forces the field to always be encoded, even if it's private. /// - /// `false` means the field should never be encoded. + /// `false` prevents the field from being encoded. final bool? includeToJson; - /// The key in a JSON map to use when reading and writing values corresponding - /// to the annotated fields. + /// The key to use in the JSON map when reading and writing values for the + /// annotated field. /// - /// If `null`, the field name is used. + /// If `null`, the field name will be used as the key. final String? name; - /// Specialize how a value is read from the source JSON map. + /// Customizes how a value is read from the source JSON map. /// /// Typically, the value corresponding to a given key is read directly from /// the JSON map using `map[key]`. At times it's convenient to customize this /// behavior to support alternative names or to support logic that requires /// accessing multiple values at once. /// - /// The provided, the [Function] must be a top-level or static within the - /// using class. + /// The provided [Function] must be either a top-level function or a static + /// method within the class. /// /// Note: using this feature does not change any of the subsequent decoding /// logic for the field. For instance, if the field is of type [DateTime] we /// expect the function provided here to return a [String]. final Object? Function(Map, String)? readValue; - /// When `true`, generated code for `fromJson` will verify that the source - /// JSON map contains the associated key. + /// If `true`, generated code for `fromJson` will verify that the source JSON + /// map contains the associated key. /// - /// If the key does not exist, a [MissingRequiredKeysException] exception is - /// thrown. + /// If the key is missing, a [MissingRequiredKeysException] will be thrown. /// /// Note: only the existence of the key is checked. A key with a `null` value /// is considered valid. @@ -135,23 +135,23 @@ class JsonKey { /// returns a JSON-compatible value. /// /// When creating a class that supports both `toJson` and `fromJson` - /// (the default), you should also set [fromJson] if you set [toJson]. - /// Values returned by [toJson] should "round-trip" through [fromJson]. + /// (the default behavior), it is recommended to also set [fromJson] if + /// [toJson] is set. Values returned by [toJson] should "round-trip" through + /// [fromJson]. final Function? toJson; - /// The value to use for an enum field when the value provided is not in the - /// source enum. + /// The value to use for an enum field when the provided value does not match + /// any of the values in the source enum. /// /// Valid only on enum fields with a compatible enum value. /// - /// If you want to use the value `null` when encountering an unknown value, - /// use the value of [JsonKey.nullForUndefinedEnumValue] instead. This is only - /// valid on a nullable enum field. + /// To use `null` for unknown values, use [JsonKey.nullForUndefinedEnumValue]. + /// This is only valid for nullable enum fields. final Enum? unknownEnumValue; /// Creates a new [JsonKey] instance. /// - /// Only required when the default behavior is not desired. + /// Use this constructor when the default behavior is not desired. const JsonKey({ @Deprecated('Has no effect') bool? nullable, this.defaultValue, From 37b2a65f314ade57bb43630322b4f0f5f87100b2 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Mon, 18 Nov 2024 09:04:02 -0800 Subject: [PATCH 540/569] Fix lints and docs (#1457) --- json_serializable/README.md | 34 +++++++++---------- .../tool/readme/readme_template.md | 2 +- json_serializable/tool/readme_builder.dart | 2 +- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/json_serializable/README.md b/json_serializable/README.md index 5d30efd16..713ff4c1e 100644 --- a/json_serializable/README.md +++ b/json_serializable/README.md @@ -146,7 +146,7 @@ enum StatusCodeEnhanced { # Supported types Out of the box, `json_serializable` supports many common types in the -[dart:core](https://api.dart.dev/stable/dart-core/dart-core-library.html) +[dart:core](https://api.dart.dev/dart-core/dart-core-library.html) library: [`BigInt`], [`bool`], [`DateTime`], [`double`], [`Duration`], [`Enum`], [`int`], [`Iterable`], [`List`], [`Map`], [`num`], [`Object`], [`Record`], [`Set`], @@ -290,14 +290,14 @@ targets: [example]: https://github.com/google/json_serializable.dart/tree/master/example [dart build system]: https://github.com/dart-lang/build [package:json_annotation]: https://pub.dev/packages/json_annotation -[`BigInt`]: https://api.dart.dev/stable/dart-core/BigInt-class.html -[`bool`]: https://api.dart.dev/stable/dart-core/bool-class.html -[`DateTime`]: https://api.dart.dev/stable/dart-core/DateTime-class.html -[`double`]: https://api.dart.dev/stable/dart-core/double-class.html -[`Duration`]: https://api.dart.dev/stable/dart-core/Duration-class.html -[`Enum`]: https://api.dart.dev/stable/dart-core/Enum-class.html -[`int`]: https://api.dart.dev/stable/dart-core/int-class.html -[`Iterable`]: https://api.dart.dev/stable/dart-core/Iterable-class.html +[`BigInt`]: https://api.dart.dev/dart-core/BigInt-class.html +[`bool`]: https://api.dart.dev/dart-core/bool-class.html +[`DateTime`]: https://api.dart.dev/dart-core/DateTime-class.html +[`double`]: https://api.dart.dev/dart-core/double-class.html +[`Duration`]: https://api.dart.dev/dart-core/Duration-class.html +[`Enum`]: https://api.dart.dev/dart-core/Enum-class.html +[`int`]: https://api.dart.dev/dart-core/int-class.html +[`Iterable`]: https://api.dart.dev/dart-core/Iterable-class.html [`JsonConverter`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonConverter-class.html [`JsonEnum.valueField`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonEnum/valueField.html [`JsonEnum`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonEnum-class.html @@ -307,11 +307,11 @@ targets: [`JsonLiteral`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonLiteral-class.html [`JsonSerializable`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable-class.html [`JsonValue`]: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonValue-class.html -[`List`]: https://api.dart.dev/stable/dart-core/List-class.html -[`Map`]: https://api.dart.dev/stable/dart-core/Map-class.html -[`num`]: https://api.dart.dev/stable/dart-core/num-class.html -[`Object`]: https://api.dart.dev/stable/dart-core/Object-class.html -[`Record`]: https://api.dart.dev/stable/dart-core/Record-class.html -[`Set`]: https://api.dart.dev/stable/dart-core/Set-class.html -[`String`]: https://api.dart.dev/stable/dart-core/String-class.html -[`Uri`]: https://api.dart.dev/stable/dart-core/Uri-class.html +[`List`]: https://api.dart.dev/dart-core/List-class.html +[`Map`]: https://api.dart.dev/dart-core/Map-class.html +[`num`]: https://api.dart.dev/dart-core/num-class.html +[`Object`]: https://api.dart.dev/dart-core/Object-class.html +[`Record`]: https://api.dart.dev/dart-core/Record-class.html +[`Set`]: https://api.dart.dev/dart-core/Set-class.html +[`String`]: https://api.dart.dev/dart-core/String-class.html +[`Uri`]: https://api.dart.dev/dart-core/Uri-class.html diff --git a/json_serializable/tool/readme/readme_template.md b/json_serializable/tool/readme/readme_template.md index c3d6815ab..adba60f1c 100644 --- a/json_serializable/tool/readme/readme_template.md +++ b/json_serializable/tool/readme/readme_template.md @@ -84,7 +84,7 @@ serialized value. # Supported types Out of the box, `json_serializable` supports many common types in the -[dart:core](https://api.dart.dev/stable/dart-core/dart-core-library.html) +[dart:core](https://api.dart.dev/dart-core/dart-core-library.html) library: <!-- REPLACE supported_types --> diff --git a/json_serializable/tool/readme_builder.dart b/json_serializable/tool/readme_builder.dart index cd832eab5..4daf44ae0 100644 --- a/json_serializable/tool/readme_builder.dart +++ b/json_serializable/tool/readme_builder.dart @@ -103,7 +103,7 @@ const _templatePath = 'tool/readme/readme_template.md'; const _readmePath = 'README.md'; String _coreTypeUri(String type) => - 'https://api.dart.dev/stable/dart-core/$type-class.html'; + 'https://api.dart.dev/dart-core/$type-class.html'; String _classCleanAndSort(Iterable<String> classes) { final initial = (classes.map((e) => e == customEnumType ? 'Enum' : e).toList() From f76e7dfd1c35999f5febedade93ebdb53de39ee7 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Tue, 19 Nov 2024 13:11:06 -0800 Subject: [PATCH 541/569] Prepare release 6.9 (#1458) --- json_serializable/CHANGELOG.md | 3 ++- json_serializable/pubspec.yaml | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 7c14862e2..cd0ff76f0 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,6 +1,7 @@ -## 6.9.0-wip +## 6.9.0 - Use conditional map syntax to clean up `null` handling in `toJson` functions. +- Fix core Dart type links in docs. - Require Dart 3.5 ## 6.8.0 diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 854f2c7fd..3a31df77e 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 6.9.0-wip +version: 6.9.0 description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. From d3cee9920173ca9bde2e2d4b2a35d8552ce75f9f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 1 Dec 2024 08:45:34 -0800 Subject: [PATCH 542/569] Bump the dependencies group with 2 updates (#1461) Bumps the dependencies group with 2 updates: [dart-lang/setup-dart](https://github.com/dart-lang/setup-dart) and [DavidAnson/markdownlint-cli2-action](https://github.com/davidanson/markdownlint-cli2-action). Updates `dart-lang/setup-dart` from 1.6.5 to 1.7.0 - [Release notes](https://github.com/dart-lang/setup-dart/releases) - [Changelog](https://github.com/dart-lang/setup-dart/blob/main/CHANGELOG.md) - [Commits](https://github.com/dart-lang/setup-dart/compare/0a8a0fc875eb934c15d08629302413c671d3f672...e630b99d28a3b71860378cafdc2a067c71107f94) Updates `DavidAnson/markdownlint-cli2-action` from 17.0.0 to 18.0.0 - [Release notes](https://github.com/davidanson/markdownlint-cli2-action/releases) - [Commits](https://github.com/davidanson/markdownlint-cli2-action/compare/db43aef879112c3119a410d69f66701e0d530809...eb5ca3ab411449c66620fe7f1b3c9e10547144b0) --- updated-dependencies: - dependency-name: dart-lang/setup-dart dependency-type: direct:production update-type: version-update:semver-minor dependency-group: dependencies - dependency-name: DavidAnson/markdownlint-cli2-action dependency-type: direct:production update-type: version-update:semver-major dependency-group: dependencies ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/dart.yml | 26 +++++++++++++------------- .github/workflows/markdown_linter.yml | 2 +- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 9ec40b575..eddf9ec47 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -29,7 +29,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672 + uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94 with: sdk: stable - id: checkout @@ -54,7 +54,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672 + uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94 with: sdk: "3.5.0" - id: checkout @@ -120,7 +120,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672 + uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94 with: sdk: dev - id: checkout @@ -206,7 +206,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672 + uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94 with: sdk: "3.5.0" - id: checkout @@ -267,7 +267,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672 + uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94 with: sdk: "3.5.0" - id: checkout @@ -301,7 +301,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672 + uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94 with: sdk: "3.5.0" - id: checkout @@ -335,7 +335,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672 + uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94 with: sdk: "3.5.0" - id: checkout @@ -369,7 +369,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672 + uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94 with: sdk: dev - id: checkout @@ -430,7 +430,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672 + uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94 with: sdk: dev - id: checkout @@ -464,7 +464,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672 + uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94 with: sdk: dev - id: checkout @@ -498,7 +498,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672 + uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94 with: sdk: dev - id: checkout @@ -532,7 +532,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672 + uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94 with: sdk: "3.5.0" - id: checkout @@ -592,7 +592,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672 + uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94 with: sdk: dev - id: checkout diff --git a/.github/workflows/markdown_linter.yml b/.github/workflows/markdown_linter.yml index 61ee20394..fae4cd498 100644 --- a/.github/workflows/markdown_linter.yml +++ b/.github/workflows/markdown_linter.yml @@ -17,4 +17,4 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 - - uses: DavidAnson/markdownlint-cli2-action@db43aef879112c3119a410d69f66701e0d530809 + - uses: DavidAnson/markdownlint-cli2-action@eb5ca3ab411449c66620fe7f1b3c9e10547144b0 From 52c25ccdbecbbf1cf1adfb512833dd371fd6eba2 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Tue, 17 Dec 2024 16:42:09 -0600 Subject: [PATCH 543/569] Support latest packages, bump min SDK to 3.6 (#1465) --- .github/workflows/dart.yml | 60 +++++++++---------- _test_yaml/pubspec.yaml | 2 +- checked_yaml/CHANGELOG.md | 2 +- checked_yaml/pubspec.yaml | 2 +- example/pubspec.yaml | 2 +- json_annotation/CHANGELOG.md | 2 +- json_annotation/pubspec.yaml | 2 +- json_serializable/CHANGELOG.md | 5 ++ json_serializable/lib/builder.dart | 7 +-- json_serializable/lib/src/field_helpers.dart | 16 ++--- .../lib/src/json_part_builder.dart | 9 ++- .../type_helpers/json_converter_helper.dart | 2 +- json_serializable/lib/src/utils.dart | 10 +--- json_serializable/pubspec.yaml | 10 ++-- .../test/custom_configuration_test.dart | 20 +++---- .../src/_json_serializable_test_input.dart | 2 + .../test/src/checked_test_input.dart | 2 + .../test/src/constants_copy.dart | 2 + .../test/src/core_subclass_type_input.dart | 2 + .../test/src/default_value_input.dart | 2 + .../test/src/field_namer_input.dart | 2 + .../test/src/generic_test_input.dart | 2 + .../test/src/inheritance_test_input.dart | 2 + .../test/src/json_converter_test_input.dart | 2 + .../test/src/map_key_variety_test_input.dart | 2 + .../test/src/setter_test_input.dart | 2 + .../test/src/to_from_json_test_input.dart | 2 + .../src/unknown_enum_value_test_input.dart | 2 + .../tool/field_matrix_builder.dart | 2 + json_serializable/tool/shared.dart | 7 ++- json_serializable/tool/test_builder.dart | 2 + json_serializable/tool/test_type_builder.dart | 2 + shared_test/pubspec.yaml | 2 +- 33 files changed, 112 insertions(+), 80 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index eddf9ec47..ac10f084d 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -40,23 +40,23 @@ jobs: - name: mono_repo self validate run: dart pub global run mono_repo generate --validate job_002: - name: "analyzer_and_format; Dart 3.5.0; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; `dart analyze`" + name: "analyzer_and_format; Dart 3.6.0; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; `dart analyze`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:analyze_1" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:analyze_1" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable - os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0 + os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable + os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94 with: - sdk: "3.5.0" + sdk: "3.6.0" - id: checkout name: Checkout repository uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 @@ -192,23 +192,23 @@ jobs: if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" working-directory: json_serializable job_004: - name: "unit_test; Dart 3.5.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; `dart test`" + name: "unit_test; Dart 3.6.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; `dart test`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0;packages:_test_yaml-checked_yaml-example-json_serializable - os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0 + os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:_test_yaml-checked_yaml-example-json_serializable + os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94 with: - sdk: "3.5.0" + sdk: "3.6.0" - id: checkout name: Checkout repository uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 @@ -253,23 +253,23 @@ jobs: - job_002 - job_003 job_005: - name: "unit_test; Dart 3.5.0; PKG: json_serializable; `dart test --run-skipped -t presubmit-only test/annotation_version_test.dart`" + name: "unit_test; Dart 3.6.0; PKG: json_serializable; `dart test --run-skipped -t presubmit-only test/annotation_version_test.dart`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0;packages:json_serializable;commands:test_3" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:json_serializable;commands:test_3" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0;packages:json_serializable - os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0 + os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:json_serializable + os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94 with: - sdk: "3.5.0" + sdk: "3.6.0" - id: checkout name: Checkout repository uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 @@ -287,23 +287,23 @@ jobs: - job_002 - job_003 job_006: - name: "unit_test; Dart 3.5.0; PKG: json_serializable; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" + name: "unit_test; Dart 3.6.0; PKG: json_serializable; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0;packages:json_serializable;commands:test_1" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:json_serializable;commands:test_1" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0;packages:json_serializable - os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0 + os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:json_serializable + os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94 with: - sdk: "3.5.0" + sdk: "3.6.0" - id: checkout name: Checkout repository uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 @@ -321,23 +321,23 @@ jobs: - job_002 - job_003 job_007: - name: "unit_test; Dart 3.5.0; PKG: json_serializable; `dart test -p chrome`" + name: "unit_test; Dart 3.6.0; PKG: json_serializable; `dart test -p chrome`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0;packages:json_serializable;commands:test_2" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:json_serializable;commands:test_2" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0;packages:json_serializable - os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0 + os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:json_serializable + os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94 with: - sdk: "3.5.0" + sdk: "3.6.0" - id: checkout name: Checkout repository uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 @@ -518,23 +518,23 @@ jobs: - job_002 - job_003 job_012: - name: "ensure_build; Dart 3.5.0; PKGS: _test_yaml, checked_yaml, example; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" + name: "ensure_build; Dart 3.6.0; PKGS: _test_yaml, checked_yaml, example; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0;packages:_test_yaml-checked_yaml-example;commands:test_1" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:_test_yaml-checked_yaml-example;commands:test_1" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0;packages:_test_yaml-checked_yaml-example - os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0 + os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:_test_yaml-checked_yaml-example + os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94 with: - sdk: "3.5.0" + sdk: "3.6.0" - id: checkout name: Checkout repository uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 diff --git a/_test_yaml/pubspec.yaml b/_test_yaml/pubspec.yaml index f54503684..5fa5ac1ac 100644 --- a/_test_yaml/pubspec.yaml +++ b/_test_yaml/pubspec.yaml @@ -2,7 +2,7 @@ name: _test_yaml publish_to: none environment: - sdk: ^3.5.0 + sdk: ^3.6.0 resolution: workspace diff --git a/checked_yaml/CHANGELOG.md b/checked_yaml/CHANGELOG.md index 292ecc01a..6099e85b3 100644 --- a/checked_yaml/CHANGELOG.md +++ b/checked_yaml/CHANGELOG.md @@ -1,6 +1,6 @@ ## 2.0.4-wip -- Require Dart 3.5 +- Require Dart 3.6 ## 2.0.3 diff --git a/checked_yaml/pubspec.yaml b/checked_yaml/pubspec.yaml index bb765cb1d..7e7fbc9d4 100644 --- a/checked_yaml/pubspec.yaml +++ b/checked_yaml/pubspec.yaml @@ -13,7 +13,7 @@ topics: - codegen environment: - sdk: ^3.5.0 + sdk: ^3.6.0 resolution: workspace diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 0875abdd3..3926249e9 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -2,7 +2,7 @@ name: example publish_to: none environment: - sdk: ^3.5.0 + sdk: ^3.6.0 resolution: workspace diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index 0c341a220..810c9d3d1 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -1,6 +1,6 @@ ## 4.9.1-wip -- Require Dart 3.5 +- Require Dart 3.6 ## 4.9.0 diff --git a/json_annotation/pubspec.yaml b/json_annotation/pubspec.yaml index cf334679b..4c3da5f3e 100644 --- a/json_annotation/pubspec.yaml +++ b/json_annotation/pubspec.yaml @@ -11,7 +11,7 @@ topics: - codegen environment: - sdk: ^3.5.0 + sdk: ^3.6.0 resolution: workspace diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index cd0ff76f0..8ebbd107f 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,8 @@ +## 6.9.1 + +- Support the latest `package:analyzer` and `package:source_gen`. +- Require Dart 3.6 + ## 6.9.0 - Use conditional map syntax to clean up `null` handling in `toJson` functions. diff --git a/json_serializable/lib/builder.dart b/json_serializable/lib/builder.dart index 833efcec3..b68eb7587 100644 --- a/json_serializable/lib/builder.dart +++ b/json_serializable/lib/builder.dart @@ -39,11 +39,6 @@ Builder jsonSerializable(BuilderOptions options) { lines.add(e.innerError.toString()); } - throw StateError( - lines - .join('\n') - // TODO(kevmoo) remove when dart-lang/sdk#50756 is fixed! - .replaceAll(" of ' in type cast'", ' in type cast'), - ); + throw StateError(lines.join('\n')); } } diff --git a/json_serializable/lib/src/field_helpers.dart b/json_serializable/lib/src/field_helpers.dart index b315a1401..c14d0d4b4 100644 --- a/json_serializable/lib/src/field_helpers.dart +++ b/json_serializable/lib/src/field_helpers.dart @@ -2,10 +2,6 @@ // 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. -// TODO: Waiting until Dart 3.6 so we can pin a stable Dart SDK compatible w/ latest -// analyzer -// ignore_for_file: deprecated_member_use - import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/src/dart/element/inheritance_manager3.dart' // ignore: implementation_imports show @@ -41,21 +37,21 @@ class _FieldSet implements Comparable<_FieldSet> { static int _sortByLocation(FieldElement a, FieldElement b) { final checkerA = TypeChecker.fromStatic( - (a.enclosingElement as InterfaceElement).thisType, + (a.enclosingElement3 as InterfaceElement).thisType, ); - if (!checkerA.isExactly(b.enclosingElement)) { + if (!checkerA.isExactly(b.enclosingElement3)) { // in this case, you want to prioritize the enclosingElement that is more // "super". - if (checkerA.isAssignableFrom(b.enclosingElement)) { + if (checkerA.isAssignableFrom(b.enclosingElement3)) { return -1; } final checkerB = TypeChecker.fromStatic( - (b.enclosingElement as InterfaceElement).thisType); + (b.enclosingElement3 as InterfaceElement).thisType); - if (checkerB.isAssignableFrom(a.enclosingElement)) { + if (checkerB.isAssignableFrom(a.enclosingElement3)) { return 1; } } @@ -87,7 +83,7 @@ List<FieldElement> createSortedFieldSet(ClassElement element) { for (final v in manager.getInheritedConcreteMap2(element).values) { assert(v is! FieldElement); - if (_dartCoreObjectChecker.isExactly(v.enclosingElement)) { + if (_dartCoreObjectChecker.isExactly(v.enclosingElement3)) { continue; } diff --git a/json_serializable/lib/src/json_part_builder.dart b/json_serializable/lib/src/json_part_builder.dart index 17e2c7fb6..a5013f8d6 100644 --- a/json_serializable/lib/src/json_part_builder.dart +++ b/json_serializable/lib/src/json_part_builder.dart @@ -3,7 +3,9 @@ // BSD-style license that can be found in the LICENSE file. import 'package:build/build.dart'; +import 'package:dart_style/dart_style.dart'; import 'package:json_annotation/json_annotation.dart'; +import 'package:pub_semver/pub_semver.dart'; import 'package:source_gen/source_gen.dart'; import 'check_dependencies.dart'; @@ -18,7 +20,7 @@ import 'settings.dart'; /// [formatOutput] is called to format the generated code. If not provided, /// the default Dart code formatter is used. Builder jsonPartBuilder({ - String Function(String code)? formatOutput, + String Function(String code, Version languageVersion)? formatOutput, JsonSerializable? config, }) { final settings = Settings(config: config); @@ -32,7 +34,7 @@ Builder jsonPartBuilder({ const JsonLiteralGenerator(), ], 'json_serializable', - formatOutput: formatOutput, + formatOutput: formatOutput ?? defaultFormatOutput, ); } @@ -99,3 +101,6 @@ Iterable<String> _normalizeGeneratorOutput(Object? value) { ArgumentError _argError(Object value) => ArgumentError( 'Must be a String or be an Iterable containing String values. ' 'Found `${Error.safeToString(value)}` (${value.runtimeType}).'); + +String defaultFormatOutput(String code, Version languageVersion) => + DartFormatter(languageVersion: languageVersion).format(code); diff --git a/json_serializable/lib/src/type_helpers/json_converter_helper.dart b/json_serializable/lib/src/type_helpers/json_converter_helper.dart index 4f1192703..2722b4bc6 100644 --- a/json_serializable/lib/src/type_helpers/json_converter_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_converter_helper.dart @@ -215,7 +215,7 @@ _JsonConvertData? _typeConverterFrom( final annotationElement = match.elementAnnotation?.element; if (annotationElement is PropertyAccessorElement) { // ignore: deprecated_member_use - final enclosing = annotationElement.enclosingElement; + final enclosing = annotationElement.enclosingElement3; var accessString = annotationElement.name; diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index 84ef4695b..d2f5f3342 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -2,10 +2,6 @@ // 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. -// TODO: Waiting until Dart 3.6 so we can pin a stable Dart SDK compatible w/ latest -// analyzer -// ignore_for_file: deprecated_member_use - import 'package:analyzer/dart/constant/value.dart'; import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/type.dart'; @@ -267,15 +263,15 @@ extension ExecutableElementExtension on ExecutableElement { } if (this is MethodElement) { - return '${enclosingElement.name}.$name'; + return '${enclosingElement3.name}.$name'; } if (this is ConstructorElement) { // Ignore the default constructor. if (name.isEmpty) { - return '${enclosingElement.name}'; + return '${enclosingElement3.name}'; } - return '${enclosingElement.name}.$name'; + return '${enclosingElement3.name}.$name'; } throw UnsupportedError( diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 3a31df77e..9df24fd0b 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,11 +1,11 @@ name: json_serializable -version: 6.9.0 +version: 6.9.1 description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. repository: https://github.com/google/json_serializable.dart/tree/master/json_serializable environment: - sdk: ^3.5.0 + sdk: ^3.6.0 topics: - json - build-runner @@ -15,11 +15,12 @@ topics: resolution: workspace dependencies: - analyzer: ^6.5.0 + analyzer: '>=6.5.0 <7.0.0' async: ^2.10.0 build: ^2.4.1 build_config: ^1.1.0 collection: ^1.17.0 + dart_style: '>=2.3.7 <4.0.0' # Use a tight version constraint to ensure that a constraint on # `json_annotation` properly constrains all features it provides. @@ -28,7 +29,7 @@ dependencies: path: ^1.9.0 pub_semver: ^2.1.4 pubspec_parse: ^1.0.0 - source_gen: ^1.4.0 + source_gen: ^2.0.0 source_helper: ^1.3.4 dev_dependencies: @@ -36,7 +37,6 @@ dev_dependencies: path: ../shared_test build_runner: ^2.4.6 build_verify: ^3.0.0 - dart_style: ^2.3.2 logging: ^1.0.0 source_gen_test: ^1.0.6 test: ^1.24.4 diff --git a/json_serializable/test/custom_configuration_test.dart b/json_serializable/test/custom_configuration_test.dart index 4ac5d02ca..1c96f0925 100644 --- a/json_serializable/test/custom_configuration_test.dart +++ b/json_serializable/test/custom_configuration_test.dart @@ -142,11 +142,11 @@ void _registerTests(JsonSerializable generator) { const expected = r''' Map<String, dynamic> _$TrivialNestedNullableToJson( - TrivialNestedNullable instance) => - <String, dynamic>{ - 'child': instance.child?.toJson(), - 'otherField': instance.otherField, - }; + TrivialNestedNullable instance, +) => <String, dynamic>{ + 'child': instance.child?.toJson(), + 'otherField': instance.otherField, +}; '''; expect(output, expected); @@ -157,11 +157,11 @@ Map<String, dynamic> _$TrivialNestedNullableToJson( const expected = r''' Map<String, dynamic> _$TrivialNestedNonNullableToJson( - TrivialNestedNonNullable instance) => - <String, dynamic>{ - 'child': instance.child.toJson(), - 'otherField': instance.otherField, - }; + TrivialNestedNonNullable instance, +) => <String, dynamic>{ + 'child': instance.child.toJson(), + 'otherField': instance.otherField, +}; '''; expect(output, expected); diff --git a/json_serializable/test/src/_json_serializable_test_input.dart b/json_serializable/test/src/_json_serializable_test_input.dart index f8537f346..0f792b495 100644 --- a/json_serializable/test/src/_json_serializable_test_input.dart +++ b/json_serializable/test/src/_json_serializable_test_input.dart @@ -2,6 +2,8 @@ // 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. +// @dart=3.6 + import 'dart:collection'; import 'package:json_annotation/json_annotation.dart'; diff --git a/json_serializable/test/src/checked_test_input.dart b/json_serializable/test/src/checked_test_input.dart index bfbc62457..167b7039f 100644 --- a/json_serializable/test/src/checked_test_input.dart +++ b/json_serializable/test/src/checked_test_input.dart @@ -1,3 +1,5 @@ +// @dart=3.6 + part of '_json_serializable_test_input.dart'; @ShouldGenerate(r''' diff --git a/json_serializable/test/src/constants_copy.dart b/json_serializable/test/src/constants_copy.dart index a4b0f1086..fa1c485bb 100644 --- a/json_serializable/test/src/constants_copy.dart +++ b/json_serializable/test/src/constants_copy.dart @@ -2,6 +2,8 @@ // 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. +// @dart=3.6 + part of '_json_serializable_test_input.dart'; // TODO: remove this and return link to lib/src/constants.dart once this diff --git a/json_serializable/test/src/core_subclass_type_input.dart b/json_serializable/test/src/core_subclass_type_input.dart index 4165a4525..b764b9fe8 100644 --- a/json_serializable/test/src/core_subclass_type_input.dart +++ b/json_serializable/test/src/core_subclass_type_input.dart @@ -1,3 +1,5 @@ +// @dart=3.6 + part of '_json_serializable_test_input.dart'; @ShouldThrow( diff --git a/json_serializable/test/src/default_value_input.dart b/json_serializable/test/src/default_value_input.dart index 7bdd1a35b..6636f085f 100644 --- a/json_serializable/test/src/default_value_input.dart +++ b/json_serializable/test/src/default_value_input.dart @@ -2,6 +2,8 @@ // 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. +// @dart=3.6 + part of '_json_serializable_test_input.dart'; @ShouldThrow( diff --git a/json_serializable/test/src/field_namer_input.dart b/json_serializable/test/src/field_namer_input.dart index 98cbadd8c..ac9e1363c 100644 --- a/json_serializable/test/src/field_namer_input.dart +++ b/json_serializable/test/src/field_namer_input.dart @@ -1,3 +1,5 @@ +// @dart=3.6 + part of '_json_serializable_test_input.dart'; @ShouldGenerate(r''' diff --git a/json_serializable/test/src/generic_test_input.dart b/json_serializable/test/src/generic_test_input.dart index 8baaa433f..f7b4ec45e 100644 --- a/json_serializable/test/src/generic_test_input.dart +++ b/json_serializable/test/src/generic_test_input.dart @@ -2,6 +2,8 @@ // 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. +// @dart=3.6 + part of '_json_serializable_test_input.dart'; @ShouldThrow( diff --git a/json_serializable/test/src/inheritance_test_input.dart b/json_serializable/test/src/inheritance_test_input.dart index 921e442e3..86c43c420 100644 --- a/json_serializable/test/src/inheritance_test_input.dart +++ b/json_serializable/test/src/inheritance_test_input.dart @@ -1,3 +1,5 @@ +// @dart=3.6 + part of '_json_serializable_test_input.dart'; @ShouldGenerate(r''' diff --git a/json_serializable/test/src/json_converter_test_input.dart b/json_serializable/test/src/json_converter_test_input.dart index 5f4075b82..6e40125fe 100644 --- a/json_serializable/test/src/json_converter_test_input.dart +++ b/json_serializable/test/src/json_converter_test_input.dart @@ -2,6 +2,8 @@ // 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. +// @dart=3.6 + // ignore_for_file: inference_failure_on_instance_creation part of '_json_serializable_test_input.dart'; diff --git a/json_serializable/test/src/map_key_variety_test_input.dart b/json_serializable/test/src/map_key_variety_test_input.dart index 2f07cf703..9d55e3bcf 100644 --- a/json_serializable/test/src/map_key_variety_test_input.dart +++ b/json_serializable/test/src/map_key_variety_test_input.dart @@ -1,3 +1,5 @@ +// @dart=3.6 + part of '_json_serializable_test_input.dart'; @ShouldGenerate(r''' diff --git a/json_serializable/test/src/setter_test_input.dart b/json_serializable/test/src/setter_test_input.dart index f9dddf4bd..81db156bc 100644 --- a/json_serializable/test/src/setter_test_input.dart +++ b/json_serializable/test/src/setter_test_input.dart @@ -1,3 +1,5 @@ +// @dart=3.6 + part of '_json_serializable_test_input.dart'; @ShouldGenerate( diff --git a/json_serializable/test/src/to_from_json_test_input.dart b/json_serializable/test/src/to_from_json_test_input.dart index abeb24be2..21bb81bd7 100644 --- a/json_serializable/test/src/to_from_json_test_input.dart +++ b/json_serializable/test/src/to_from_json_test_input.dart @@ -2,6 +2,8 @@ // 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. +// @dart=3.6 + part of '_json_serializable_test_input.dart'; int _toInt(bool input) => 42; diff --git a/json_serializable/test/src/unknown_enum_value_test_input.dart b/json_serializable/test/src/unknown_enum_value_test_input.dart index c2f745899..7dec6feaa 100644 --- a/json_serializable/test/src/unknown_enum_value_test_input.dart +++ b/json_serializable/test/src/unknown_enum_value_test_input.dart @@ -1,3 +1,5 @@ +// @dart=3.6 + part of '_json_serializable_test_input.dart'; @ShouldGenerate( diff --git a/json_serializable/tool/field_matrix_builder.dart b/json_serializable/tool/field_matrix_builder.dart index 4288bd782..885357c17 100644 --- a/json_serializable/tool/field_matrix_builder.dart +++ b/json_serializable/tool/field_matrix_builder.dart @@ -15,6 +15,8 @@ Builder builder([_]) => _FieldMatrixBuilder(); class _FieldMatrixBuilder extends Builder { @override FutureOr<void> build(BuildStep buildStep) async { + final formatter = await buildStep.formatter(); + final inputBaseName = p.basenameWithoutExtension(buildStep.inputId.path); final output = buildStep.allowedOutputs.single; diff --git a/json_serializable/tool/shared.dart b/json_serializable/tool/shared.dart index 6565baf9d..265031a22 100644 --- a/json_serializable/tool/shared.dart +++ b/json_serializable/tool/shared.dart @@ -8,8 +8,6 @@ import 'package:build/build.dart'; import 'package:dart_style/dart_style.dart'; import 'package:yaml/yaml.dart'; -final formatter = DartFormatter(); - // Until we have verification in pkg:build and friends // https://github.com/dart-lang/build/issues/590 Builder validate(String builderName, Builder builder) { @@ -72,3 +70,8 @@ class Replacement { return outputContent.replaceAll(',)', ',\n)'); } } + +extension BuildStepExtension on BuildStep { + Future<DartFormatter> formatter() async => DartFormatter( + languageVersion: (await inputLibrary).languageVersion.effective); +} diff --git a/json_serializable/tool/test_builder.dart b/json_serializable/tool/test_builder.dart index c2e5379b0..de50e3dac 100644 --- a/json_serializable/tool/test_builder.dart +++ b/json_serializable/tool/test_builder.dart @@ -17,6 +17,8 @@ class _TestBuilder implements Builder { @override FutureOr<void> build(BuildStep buildStep) async { + final formatter = await buildStep.formatter(); + final baseName = p.basenameWithoutExtension(buildStep.inputId.path); final sourceContent = await buildStep.readAsString(buildStep.inputId); diff --git a/json_serializable/tool/test_type_builder.dart b/json_serializable/tool/test_type_builder.dart index 050231041..8b25a0815 100644 --- a/json_serializable/tool/test_type_builder.dart +++ b/json_serializable/tool/test_type_builder.dart @@ -125,6 +125,8 @@ class _TypeBuilder implements Builder { @override FutureOr<void> build(BuildStep buildStep) async { + final formatter = await buildStep.formatter(); + final inputId = buildStep.inputId; final sourceContent = await buildStep.readAsString(inputId); diff --git a/shared_test/pubspec.yaml b/shared_test/pubspec.yaml index 09b960f69..23aed093a 100644 --- a/shared_test/pubspec.yaml +++ b/shared_test/pubspec.yaml @@ -1,7 +1,7 @@ name: _json_serial_shared_test publish_to: none environment: - sdk: ^3.5.0 + sdk: ^3.6.0 resolution: workspace From d8311be1823007344bd17eb7f5f00b885ab2b033 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Tue, 17 Dec 2024 16:54:51 -0600 Subject: [PATCH 544/569] Actually bump pkg:analyzer dep (#1466) --- json_serializable/CHANGELOG.md | 6 +++++- json_serializable/pubspec.yaml | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 8ebbd107f..a0e2db27b 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,6 +1,10 @@ +## 6.9.2 + +- Support the latest `package:analyzer`. + ## 6.9.1 -- Support the latest `package:analyzer` and `package:source_gen`. +- Support the latest `package:source_gen`. - Require Dart 3.6 ## 6.9.0 diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 9df24fd0b..4a3c00a20 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 6.9.1 +version: 6.9.2 description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. @@ -15,7 +15,7 @@ topics: resolution: workspace dependencies: - analyzer: '>=6.5.0 <7.0.0' + analyzer: '>=6.5.0 <8.0.0' async: ^2.10.0 build: ^2.4.1 build_config: ^1.1.0 From 958e520d8d004c20c71410b4b7c4a741827b3d9e Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Thu, 2 Jan 2025 10:07:31 -0600 Subject: [PATCH 545/569] Fix newly added strict_top_level_inference everywhere (#1467) --- .../test/src/_json_serializable_test_input.dart | 2 +- json_serializable/test/src/to_from_json_test_input.dart | 2 ++ json_serializable/test/test_sources/test_sources.dart | 2 +- json_serializable/tool/field_matrix_builder.dart | 2 +- json_serializable/tool/readme_builder.dart | 2 +- json_serializable/tool/test_builder.dart | 3 ++- json_serializable/tool/test_type_builder.dart | 5 +++-- 7 files changed, 11 insertions(+), 7 deletions(-) diff --git a/json_serializable/test/src/_json_serializable_test_input.dart b/json_serializable/test/src/_json_serializable_test_input.dart index 0f792b495..bdd061d00 100644 --- a/json_serializable/test/src/_json_serializable_test_input.dart +++ b/json_serializable/test/src/_json_serializable_test_input.dart @@ -84,7 +84,7 @@ class GeneralTestClass1 { late DateTime dateOfBirth; dynamic dynamicType; - //ignore: prefer_typing_uninitialized_variables,type_annotate_public_apis,inference_failure_on_uninitialized_variable + //ignore: prefer_typing_uninitialized_variables,type_annotate_public_apis,inference_failure_on_uninitialized_variable, strict_top_level_inference var varType; late List<int> listOfInts; } diff --git a/json_serializable/test/src/to_from_json_test_input.dart b/json_serializable/test/src/to_from_json_test_input.dart index 21bb81bd7..d352e3027 100644 --- a/json_serializable/test/src/to_from_json_test_input.dart +++ b/json_serializable/test/src/to_from_json_test_input.dart @@ -4,6 +4,8 @@ // @dart=3.6 +// ignore_for_file: strict_top_level_inference + part of '_json_serializable_test_input.dart'; int _toInt(bool input) => 42; diff --git a/json_serializable/test/test_sources/test_sources.dart b/json_serializable/test/test_sources/test_sources.dart index 786931080..80a08aa3b 100644 --- a/json_serializable/test/test_sources/test_sources.dart +++ b/json_serializable/test/test_sources/test_sources.dart @@ -44,7 +44,7 @@ class FromJsonOptionalParameters { } class ChildWithFromJson { - //ignore: avoid_unused_constructor_parameters + //ignore: avoid_unused_constructor_parameters, strict_top_level_inference ChildWithFromJson.fromJson(json, {initValue = false}); } diff --git a/json_serializable/tool/field_matrix_builder.dart b/json_serializable/tool/field_matrix_builder.dart index 885357c17..32084658b 100644 --- a/json_serializable/tool/field_matrix_builder.dart +++ b/json_serializable/tool/field_matrix_builder.dart @@ -10,7 +10,7 @@ import 'package:source_helper/source_helper.dart'; import 'shared.dart'; -Builder builder([_]) => _FieldMatrixBuilder(); +Builder builder([BuilderOptions? _]) => _FieldMatrixBuilder(); class _FieldMatrixBuilder extends Builder { @override diff --git a/json_serializable/tool/readme_builder.dart b/json_serializable/tool/readme_builder.dart index 4daf44ae0..1de8c6398 100644 --- a/json_serializable/tool/readme_builder.dart +++ b/json_serializable/tool/readme_builder.dart @@ -13,7 +13,7 @@ import 'package:yaml/yaml.dart'; import 'test_type_builder.dart'; import 'test_type_data.dart'; -Builder readmeBuilder([_]) => _ReadmeBuilder(); +Builder readmeBuilder([BuilderOptions? _]) => _ReadmeBuilder(); class _ReadmeBuilder extends Builder { @override diff --git a/json_serializable/tool/test_builder.dart b/json_serializable/tool/test_builder.dart index de50e3dac..8f742241c 100644 --- a/json_serializable/tool/test_builder.dart +++ b/json_serializable/tool/test_builder.dart @@ -10,7 +10,8 @@ import 'package:path/path.dart' as p; import 'shared.dart'; -Builder testBuilder([_]) => validate('_test_builder', const _TestBuilder()); +Builder testBuilder([BuilderOptions? _]) => + validate('_test_builder', const _TestBuilder()); class _TestBuilder implements Builder { const _TestBuilder(); diff --git a/json_serializable/tool/test_type_builder.dart b/json_serializable/tool/test_type_builder.dart index 8b25a0815..2c23c8d3a 100644 --- a/json_serializable/tool/test_type_builder.dart +++ b/json_serializable/tool/test_type_builder.dart @@ -118,7 +118,8 @@ final _iterableGenericArgs = ([ const _defaultCollectionExpressions = '42, true, false, null'; const _altCollectionExpressions = '43, false'; -Builder typeBuilder([_]) => validate('_type_builder', const _TypeBuilder()); +Builder typeBuilder([BuilderOptions? _]) => + validate('_type_builder', const _TypeBuilder()); class _TypeBuilder implements Builder { const _TypeBuilder(); @@ -147,7 +148,7 @@ class _TypeBuilder implements Builder { {'.dart': _allTypes.keys.map(toTypeExtension).toSet().toList()..sort()}; } -Builder typeTestBuilder([_]) => +Builder typeTestBuilder([BuilderOptions? _]) => validate('_type_test_builder', const _TypeTestBuilder()); class _TypeTestBuilder implements Builder { From ca038a45d4df8dc5d5a1048da3a218086a375b05 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 2 Jan 2025 08:10:16 -0800 Subject: [PATCH 546/569] Bump the dependencies group with 2 updates (#1469) Bumps the dependencies group with 2 updates: [actions/cache](https://github.com/actions/cache) and [DavidAnson/markdownlint-cli2-action](https://github.com/davidanson/markdownlint-cli2-action). Updates `actions/cache` from 4.1.2 to 4.2.0 - [Release notes](https://github.com/actions/cache/releases) - [Changelog](https://github.com/actions/cache/blob/main/RELEASES.md) - [Commits](https://github.com/actions/cache/compare/6849a6489940f00c2f30c0fb92c6274307ccb58a...1bd1e32a3bdc45362d1e726936510720a7c30a57) Updates `DavidAnson/markdownlint-cli2-action` from 18.0.0 to 19.0.0 - [Release notes](https://github.com/davidanson/markdownlint-cli2-action/releases) - [Commits](https://github.com/davidanson/markdownlint-cli2-action/compare/eb5ca3ab411449c66620fe7f1b3c9e10547144b0...a23dae216ce3fee4db69da41fed90d2a4af801cf) --- updated-dependencies: - dependency-name: actions/cache dependency-type: direct:production update-type: version-update:semver-minor dependency-group: dependencies - dependency-name: DavidAnson/markdownlint-cli2-action dependency-type: direct:production update-type: version-update:semver-major dependency-group: dependencies ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/dart.yml | 26 +++++++++++++------------- .github/workflows/markdown_linter.yml | 2 +- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index ac10f084d..b0c87c7ce 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -21,7 +21,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a + uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:stable" @@ -44,7 +44,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a + uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:analyze_1" @@ -110,7 +110,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a + uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:format-analyze_0" @@ -196,7 +196,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a + uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" @@ -257,7 +257,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a + uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:json_serializable;commands:test_3" @@ -291,7 +291,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a + uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:json_serializable;commands:test_1" @@ -325,7 +325,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a + uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:json_serializable;commands:test_2" @@ -359,7 +359,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a + uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" @@ -420,7 +420,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a + uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:json_serializable;commands:test_3" @@ -454,7 +454,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a + uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:json_serializable;commands:test_1" @@ -488,7 +488,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a + uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:json_serializable;commands:test_2" @@ -522,7 +522,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a + uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:_test_yaml-checked_yaml-example;commands:test_1" @@ -582,7 +582,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a + uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:_test_yaml-checked_yaml-example;commands:test_1" diff --git a/.github/workflows/markdown_linter.yml b/.github/workflows/markdown_linter.yml index fae4cd498..af996543b 100644 --- a/.github/workflows/markdown_linter.yml +++ b/.github/workflows/markdown_linter.yml @@ -17,4 +17,4 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 - - uses: DavidAnson/markdownlint-cli2-action@eb5ca3ab411449c66620fe7f1b3c9e10547144b0 + - uses: DavidAnson/markdownlint-cli2-action@a23dae216ce3fee4db69da41fed90d2a4af801cf From 3318916000a5aed8e4d2cfcae4ccb87a2a33a38a Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Thu, 2 Jan 2025 11:43:39 -0600 Subject: [PATCH 547/569] Update no-response.yml (#1470) Update label to `State: needs info` --- .github/workflows/no-response.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/no-response.yml b/.github/workflows/no-response.yml index 9cd84a5d2..a78b29737 100644 --- a/.github/workflows/no-response.yml +++ b/.github/workflows/no-response.yml @@ -25,12 +25,12 @@ jobs: days-before-stale: -1 # Close needs-info issues and PRs after 14 days of inactivity. days-before-close: 14 - stale-issue-label: "needs-info" + stale-issue-label: "State: needs info" close-issue-message: > Without additional information we're not able to resolve this issue. Feel free to add more info or respond to any questions above and we can reopen the case. Thanks for your contribution! - stale-pr-label: "needs-info" + stale-pr-label: "State: needs info" close-pr-message: > Without additional information we're not able to resolve this PR. Feel free to add more info or respond to any questions above. From 3dd67672dc69ded0873d198a2664271e079d72c8 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Mon, 13 Jan 2025 13:50:09 -0600 Subject: [PATCH 548/569] Error out if the language version of the target package is too low (#1474) Much be at least 3.0 since we generate code with case statements Fixes https://github.com/google/json_serializable.dart/issues/1462 --- json_serializable/CHANGELOG.md | 5 ++ .../lib/src/check_dependencies.dart | 41 +++++++++--- json_serializable/lib/src/constants.dart | 4 ++ json_serializable/pubspec.yaml | 2 +- .../test/annotation_version_test.dart | 63 +++++++++++++++---- 5 files changed, 91 insertions(+), 24 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index a0e2db27b..d8c5b5391 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,8 @@ +## 6.9.3 + +- Error out if the target package does not have a language version of `3.0` or + greater. + ## 6.9.2 - Support the latest `package:analyzer`. diff --git a/json_serializable/lib/src/check_dependencies.dart b/json_serializable/lib/src/check_dependencies.dart index 7ea84bef4..13117f268 100644 --- a/json_serializable/lib/src/check_dependencies.dart +++ b/json_serializable/lib/src/check_dependencies.dart @@ -8,8 +8,12 @@ import 'package:build/build.dart'; import 'package:pub_semver/pub_semver.dart'; import 'package:pubspec_parse/pubspec_parse.dart'; +import 'constants.dart'; + const _productionDirectories = {'lib', 'bin'}; const _annotationPkgName = 'json_annotation'; +final _supportLanguageRange = + VersionConstraint.parse(supportedLanguageConstraint); final requiredJsonAnnotationMinVersion = Version.parse('4.9.0'); Future<void> pubspecHasRightVersion(BuildStep buildStep) async { @@ -37,21 +41,38 @@ Future<void> _validatePubspec(bool production, BuildStep buildStep) async { return; } - Future<Pubspec> readPubspec(AssetId asset) async { - final string = await buildStep.readAsString(asset); - return Pubspec.parse(string, sourceUrl: asset.uri); + final string = await buildStep.readAsString(pubspecAssetId); + final pubspec = Pubspec.parse(string, sourceUrl: pubspecAssetId.uri); + + if (_checkAnnotationConstraint(pubspec, !production) + case final errorMessage?) { + log.warning(errorMessage); } - final pubspec = await readPubspec(pubspecAssetId); + // + // Ensure the current package language version is at least the minimum. + // + final currentPackageName = pubspec.name; + final packageConfig = await buildStep.packageConfig; + final thisPackage = packageConfig[currentPackageName]!; + + // build_runner will error out without an SDK version - so assuming + // `languageVersion` is not null. + final thisPackageVersion = thisPackage.languageVersion!; - final errorMessage = _checkAnnotationConstraint( - pubspec, - !production, - ); + final thisPackageVer = Version.parse('$thisPackageVersion.0'); + if (!_supportLanguageRange.allows(thisPackageVer)) { + log.warning( + ''' +The language version ($thisPackageVer) of this package ($currentPackageName) does not match the required range `$supportedLanguageConstraint`. - if (errorMessage == null) return; +Edit pubspec.yaml to include an SDK constraint of at least $supportedLanguageConstraint. - log.warning(errorMessage); +environment: + sdk: $supportedLanguageConstraint +''', + ); + } } String? _checkAnnotationConstraint( diff --git a/json_serializable/lib/src/constants.dart b/json_serializable/lib/src/constants.dart index a151ff034..70e85216f 100644 --- a/json_serializable/lib/src/constants.dart +++ b/json_serializable/lib/src/constants.dart @@ -13,3 +13,7 @@ const converterOrKeyInstructions = r''' * Use `JsonKey` fields `fromJson` and `toJson` https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/fromJson.html https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/toJson.html'''; + +/// This package generates code that uses case statements, which were introduced +/// in Dart 3.0. +const supportedLanguageConstraint = '^3.0.0'; diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 4a3c00a20..80c9658aa 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 6.9.2 +version: 6.9.3 description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. diff --git a/json_serializable/test/annotation_version_test.dart b/json_serializable/test/annotation_version_test.dart index 1aed36547..607634ee1 100644 --- a/json_serializable/test/annotation_version_test.dart +++ b/json_serializable/test/annotation_version_test.dart @@ -10,6 +10,7 @@ library; import 'dart:io'; import 'package:json_serializable/src/check_dependencies.dart'; +import 'package:json_serializable/src/constants.dart'; import 'package:path/path.dart' as p; import 'package:pub_semver/pub_semver.dart'; import 'package:pubspec_parse/pubspec_parse.dart'; @@ -20,7 +21,7 @@ import 'package:test_process/test_process.dart'; import 'test_utils.dart'; void main() { - test('validate pubspec constraint', () { + test('validate pubspec constraint', () async { final annotationConstraint = _jsonSerialPubspec.dependencies['json_annotation'] as HostedDependency; final versionRange = annotationConstraint.version as VersionRange; @@ -29,10 +30,35 @@ void main() { expect(versionRange.min, requiredJsonAnnotationMinVersion); }); + group('language version', () { + test('is less than required', () async { + const sdkLowerBound = '2.12.0'; + await _structurePackage( + environment: const {'sdk': '^$sdkLowerBound'}, + dependencies: {'json_annotation': _annotationLowerBound}, + message: ''' +The language version ($sdkLowerBound) of this package ($_testPkgName) does not match the required range `$supportedLanguageConstraint`. + +Edit pubspec.yaml to include an SDK constraint of at least $supportedLanguageConstraint. + +environment: + sdk: $supportedLanguageConstraint +''', + ); + }); + + test( + 'is at least the required `$supportedLanguageConstraint`', + () async => await _structurePackage( + dependencies: {'json_annotation': _annotationLowerBound}, + message: null, + ), + ); + }); + test( 'missing dependency in production code', () => _structurePackage( - sourceDirectory: 'lib', message: _missingProductionDep, ), ); @@ -50,7 +76,6 @@ void main() { test( 'dev dependency with a production usage', () => _structurePackage( - sourceDirectory: 'lib', devDependencies: {'json_annotation': _annotationLowerBound}, message: _missingProductionDep, ), @@ -59,7 +84,6 @@ void main() { test( 'dependency with `null` constraint', () => _structurePackage( - sourceDirectory: 'lib', dependencies: {'json_annotation': null}, message: 'The version constraint "any" on json_annotation allows versions ' @@ -70,7 +94,6 @@ void main() { test( 'dependency with "any" constraint', () => _structurePackage( - sourceDirectory: 'lib', dependencies: {'json_annotation': 'any'}, message: 'The version constraint "any" on json_annotation allows versions ' @@ -81,7 +104,6 @@ void main() { test( 'dependency with too low version range', () => _structurePackage( - sourceDirectory: 'lib', dependencies: {'json_annotation': '^4.0.0'}, message: 'The version constraint "^4.0.0" on json_annotation allows versions ' @@ -114,16 +136,19 @@ final _missingProductionDep = '"dependencies" section of your pubspec with a lower bound of at least ' '"$_annotationLowerBound".'; +const _testPkgName = '_test_pkg'; + Future<void> _structurePackage({ - required String sourceDirectory, - required String message, + String sourceDirectory = 'lib', + required String? message, + Map<String, dynamic> environment = const {'sdk': supportedLanguageConstraint}, Map<String, dynamic> dependencies = const {}, Map<String, dynamic> devDependencies = const {}, }) async { final pubspec = loudEncode( { - 'name': '_test_pkg', - 'environment': {'sdk': '>=2.14.0 <3.0.0'}, + 'name': _testPkgName, + 'environment': environment, 'dependencies': dependencies, 'dev_dependencies': { ...devDependencies, @@ -162,9 +187,8 @@ class SomeClass{} ) ], ).create(); - final proc = await TestProcess.start( - 'dart', + Platform.resolvedExecutable, ['run', 'build_runner', 'build'], workingDirectory: d.sandbox, ); @@ -175,9 +199,22 @@ class SomeClass{} print(line); } - expect(lines.toString(), contains(''' + final output = lines.toString(); + final expectedWarningCount = message == null ? 0 : 1; + final warningCount = '[WARNING]'.allMatches(output).length; + expect( + warningCount, + expectedWarningCount, + reason: + 'Expected the number of output warnings ($warningCount) to match the ' + 'number of expected warnings ($expectedWarningCount).', + ); + + if (message != null) { + expect(output, contains(''' [WARNING] json_serializable on $sourceDirectory/sample.dart: $message''')); + } await proc.shouldExit(0); } From 83377d09c381713b33156a91f9cf6019b51f6346 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 4 Feb 2025 12:28:41 -0800 Subject: [PATCH 549/569] Bump the dependencies group with 2 updates (#1476) Bumps the dependencies group with 2 updates: [DavidAnson/markdownlint-cli2-action](https://github.com/davidanson/markdownlint-cli2-action) and [actions/stale](https://github.com/actions/stale). Updates `DavidAnson/markdownlint-cli2-action` from 19.0.0 to 19.1.0 - [Release notes](https://github.com/davidanson/markdownlint-cli2-action/releases) - [Commits](https://github.com/davidanson/markdownlint-cli2-action/compare/a23dae216ce3fee4db69da41fed90d2a4af801cf...05f32210e84442804257b2a6f20b273450ec8265) Updates `actions/stale` from 9.0.0 to 9.1.0 - [Release notes](https://github.com/actions/stale/releases) - [Changelog](https://github.com/actions/stale/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/stale/compare/28ca1036281a5e5922ead5184a1bbf96e5fc984e...5bef64f19d7facfb25b37b414482c7164d639639) --- updated-dependencies: - dependency-name: DavidAnson/markdownlint-cli2-action dependency-type: direct:production update-type: version-update:semver-minor dependency-group: dependencies - dependency-name: actions/stale dependency-type: direct:production update-type: version-update:semver-minor dependency-group: dependencies ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/markdown_linter.yml | 2 +- .github/workflows/no-response.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/markdown_linter.yml b/.github/workflows/markdown_linter.yml index af996543b..5cd903b1b 100644 --- a/.github/workflows/markdown_linter.yml +++ b/.github/workflows/markdown_linter.yml @@ -17,4 +17,4 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 - - uses: DavidAnson/markdownlint-cli2-action@a23dae216ce3fee4db69da41fed90d2a4af801cf + - uses: DavidAnson/markdownlint-cli2-action@05f32210e84442804257b2a6f20b273450ec8265 diff --git a/.github/workflows/no-response.yml b/.github/workflows/no-response.yml index a78b29737..7a9d48f4c 100644 --- a/.github/workflows/no-response.yml +++ b/.github/workflows/no-response.yml @@ -19,7 +19,7 @@ jobs: runs-on: ubuntu-latest if: ${{ github.repository_owner == 'google' }} steps: - - uses: actions/stale@28ca1036281a5e5922ead5184a1bbf96e5fc984e + - uses: actions/stale@5bef64f19d7facfb25b37b414482c7164d639639 with: # Don't automatically mark inactive issues+PRs as stale. days-before-stale: -1 From 51c214246f15dbd2ea9c19782970cc164479b4d6 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Thu, 6 Feb 2025 15:46:42 -0600 Subject: [PATCH 550/569] Enable and fix unnecessary_ignore lint (#1477) --- analysis_options.yaml | 1 + .../lib/src/type_helpers/json_converter_helper.dart | 1 - json_serializable/lib/src/utils.dart | 1 - .../test/supported_types/extra_map_test.dart | 1 - .../test/supported_types/type_test.bigint_test.dart | 5 ++--- .../test/supported_types/type_test.bool_test.dart | 5 ++--- json_serializable/test/supported_types/type_test.dart | 5 ++--- .../test/supported_types/type_test.datetime_test.dart | 5 ++--- .../test/supported_types/type_test.double_test.dart | 5 ++--- .../test/supported_types/type_test.duration_test.dart | 5 ++--- .../test/supported_types/type_test.enumtype_test.dart | 5 ++--- .../test/supported_types/type_test.int_test.dart | 5 ++--- .../test/supported_types/type_test.iterable_test.dart | 5 ++--- .../test/supported_types/type_test.list_test.dart | 5 ++--- .../test/supported_types/type_test.map_test.dart | 5 ++--- .../test/supported_types/type_test.num_test.dart | 5 ++--- .../test/supported_types/type_test.object_test.dart | 5 ++--- .../test/supported_types/type_test.set_test.dart | 5 ++--- .../test/supported_types/type_test.string_test.dart | 5 ++--- .../test/supported_types/type_test.uri_test.dart | 5 ++--- json_serializable/tool/test_type_data.dart | 8 ++++---- 21 files changed, 37 insertions(+), 55 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index f45a2193b..5381bdab6 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -26,3 +26,4 @@ linter: - unnecessary_breaks - use_full_hex_values_for_flutter_colors - use_string_buffers + - unnecessary_ignore diff --git a/json_serializable/lib/src/type_helpers/json_converter_helper.dart b/json_serializable/lib/src/type_helpers/json_converter_helper.dart index 2722b4bc6..9958368af 100644 --- a/json_serializable/lib/src/type_helpers/json_converter_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_converter_helper.dart @@ -214,7 +214,6 @@ _JsonConvertData? _typeConverterFrom( final annotationElement = match.elementAnnotation?.element; if (annotationElement is PropertyAccessorElement) { - // ignore: deprecated_member_use final enclosing = annotationElement.enclosingElement3; var accessString = annotationElement.name; diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index d2f5f3342..4d346b41e 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -131,7 +131,6 @@ ConstructorElement? _constructorByNameOrNull( ) { try { return constructorByName(classElement, name); - // ignore: avoid_catching_errors } on InvalidGenerationSourceError { return null; } diff --git a/json_serializable/test/supported_types/extra_map_test.dart b/json_serializable/test/supported_types/extra_map_test.dart index e4fc69c1d..c5ad878b2 100644 --- a/json_serializable/test/supported_types/extra_map_test.dart +++ b/json_serializable/test/supported_types/extra_map_test.dart @@ -2,7 +2,6 @@ // 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. -// ignore_for_file: prefer_const_declarations @TestOn('vm') library; diff --git a/json_serializable/test/supported_types/type_test.bigint_test.dart b/json_serializable/test/supported_types/type_test.bigint_test.dart index 1fa7140da..83cfa4031 100644 --- a/json_serializable/test/supported_types/type_test.bigint_test.dart +++ b/json_serializable/test/supported_types/type_test.bigint_test.dart @@ -2,7 +2,6 @@ // 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. -// ignore_for_file: prefer_const_declarations @TestOn('vm') library; @@ -87,8 +86,8 @@ void main() { }); // end nullable group } -final _defaultValue = '12345'; -final _altValue = '67890'; +const _defaultValue = '12345'; +const _altValue = '67890'; final _defaultInput = <String, Object?>{ 'value': _defaultValue, diff --git a/json_serializable/test/supported_types/type_test.bool_test.dart b/json_serializable/test/supported_types/type_test.bool_test.dart index 33d1e9bcc..dc28ab84c 100644 --- a/json_serializable/test/supported_types/type_test.bool_test.dart +++ b/json_serializable/test/supported_types/type_test.bool_test.dart @@ -2,7 +2,6 @@ // 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. -// ignore_for_file: prefer_const_declarations @TestOn('vm') library; @@ -87,8 +86,8 @@ void main() { }); // end nullable group } -final _defaultValue = true; -final _altValue = false; +const _defaultValue = true; +const _altValue = false; final _defaultInput = <String, Object?>{ 'value': _defaultValue, diff --git a/json_serializable/test/supported_types/type_test.dart b/json_serializable/test/supported_types/type_test.dart index 2e7c63a3a..7cc6fc069 100644 --- a/json_serializable/test/supported_types/type_test.dart +++ b/json_serializable/test/supported_types/type_test.dart @@ -2,7 +2,6 @@ // 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. -// ignore_for_file: prefer_const_declarations @TestOn('vm') library; @@ -53,8 +52,8 @@ void main() { }); // end non-nullable group } -final _defaultValue = 42; -final _altValue = 43; +const _defaultValue = 42; +const _altValue = 43; final _defaultInput = <String, Object?>{ 'value': _defaultValue, diff --git a/json_serializable/test/supported_types/type_test.datetime_test.dart b/json_serializable/test/supported_types/type_test.datetime_test.dart index 690cde74c..88d5f53db 100644 --- a/json_serializable/test/supported_types/type_test.datetime_test.dart +++ b/json_serializable/test/supported_types/type_test.datetime_test.dart @@ -2,7 +2,6 @@ // 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. -// ignore_for_file: prefer_const_declarations @TestOn('vm') library; @@ -87,8 +86,8 @@ void main() { }); // end nullable group } -final _defaultValue = '2020-01-01T00:00:00.000'; -final _altValue = '2018-01-01T00:00:00.000'; +const _defaultValue = '2020-01-01T00:00:00.000'; +const _altValue = '2018-01-01T00:00:00.000'; final _defaultInput = <String, Object?>{ 'value': _defaultValue, diff --git a/json_serializable/test/supported_types/type_test.double_test.dart b/json_serializable/test/supported_types/type_test.double_test.dart index 31c72aa00..5a55d9c93 100644 --- a/json_serializable/test/supported_types/type_test.double_test.dart +++ b/json_serializable/test/supported_types/type_test.double_test.dart @@ -2,7 +2,6 @@ // 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. -// ignore_for_file: prefer_const_declarations @TestOn('vm') library; @@ -87,8 +86,8 @@ void main() { }); // end nullable group } -final _defaultValue = 3.14; -final _altValue = 6.28; +const _defaultValue = 3.14; +const _altValue = 6.28; final _defaultInput = <String, Object?>{ 'value': _defaultValue, diff --git a/json_serializable/test/supported_types/type_test.duration_test.dart b/json_serializable/test/supported_types/type_test.duration_test.dart index a928fd914..4d5f71814 100644 --- a/json_serializable/test/supported_types/type_test.duration_test.dart +++ b/json_serializable/test/supported_types/type_test.duration_test.dart @@ -2,7 +2,6 @@ // 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. -// ignore_for_file: prefer_const_declarations @TestOn('vm') library; @@ -87,8 +86,8 @@ void main() { }); // end nullable group } -final _defaultValue = 1234; -final _altValue = 2345; +const _defaultValue = 1234; +const _altValue = 2345; final _defaultInput = <String, Object?>{ 'value': _defaultValue, diff --git a/json_serializable/test/supported_types/type_test.enumtype_test.dart b/json_serializable/test/supported_types/type_test.enumtype_test.dart index 3c2e8bc9a..363d1ab9a 100644 --- a/json_serializable/test/supported_types/type_test.enumtype_test.dart +++ b/json_serializable/test/supported_types/type_test.enumtype_test.dart @@ -2,7 +2,6 @@ // 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. -// ignore_for_file: prefer_const_declarations @TestOn('vm') library; @@ -87,8 +86,8 @@ void main() { }); // end nullable group } -final _defaultValue = 'alpha'; -final _altValue = 'beta'; +const _defaultValue = 'alpha'; +const _altValue = 'beta'; final _defaultInput = <String, Object?>{ 'value': _defaultValue, diff --git a/json_serializable/test/supported_types/type_test.int_test.dart b/json_serializable/test/supported_types/type_test.int_test.dart index b9f36ec4f..4e8c0cb27 100644 --- a/json_serializable/test/supported_types/type_test.int_test.dart +++ b/json_serializable/test/supported_types/type_test.int_test.dart @@ -2,7 +2,6 @@ // 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. -// ignore_for_file: prefer_const_declarations @TestOn('vm') library; @@ -87,8 +86,8 @@ void main() { }); // end nullable group } -final _defaultValue = 42; -final _altValue = 43; +const _defaultValue = 42; +const _altValue = 43; final _defaultInput = <String, Object?>{ 'value': _defaultValue, diff --git a/json_serializable/test/supported_types/type_test.iterable_test.dart b/json_serializable/test/supported_types/type_test.iterable_test.dart index b31313d97..1a2ae5960 100644 --- a/json_serializable/test/supported_types/type_test.iterable_test.dart +++ b/json_serializable/test/supported_types/type_test.iterable_test.dart @@ -2,7 +2,6 @@ // 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. -// ignore_for_file: prefer_const_declarations @TestOn('vm') library; @@ -87,8 +86,8 @@ void main() { }); // end nullable group } -final _defaultValue = [42, true, false, null]; -final _altValue = [43, false]; +const _defaultValue = [42, true, false, null]; +const _altValue = [43, false]; final _defaultInput = <String, Object?>{ 'value': _defaultValue, diff --git a/json_serializable/test/supported_types/type_test.list_test.dart b/json_serializable/test/supported_types/type_test.list_test.dart index 6791be995..36e673318 100644 --- a/json_serializable/test/supported_types/type_test.list_test.dart +++ b/json_serializable/test/supported_types/type_test.list_test.dart @@ -2,7 +2,6 @@ // 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. -// ignore_for_file: prefer_const_declarations @TestOn('vm') library; @@ -87,8 +86,8 @@ void main() { }); // end nullable group } -final _defaultValue = [42, true, false, null]; -final _altValue = [43, false]; +const _defaultValue = [42, true, false, null]; +const _altValue = [43, false]; final _defaultInput = <String, Object?>{ 'value': _defaultValue, diff --git a/json_serializable/test/supported_types/type_test.map_test.dart b/json_serializable/test/supported_types/type_test.map_test.dart index 2ccce34e6..925f233c2 100644 --- a/json_serializable/test/supported_types/type_test.map_test.dart +++ b/json_serializable/test/supported_types/type_test.map_test.dart @@ -2,7 +2,6 @@ // 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. -// ignore_for_file: prefer_const_declarations @TestOn('vm') library; @@ -87,8 +86,8 @@ void main() { }); // end nullable group } -final _defaultValue = {'a': 1}; -final _altValue = {'b': 2}; +const _defaultValue = {'a': 1}; +const _altValue = {'b': 2}; final _defaultInput = <String, Object?>{ 'value': _defaultValue, diff --git a/json_serializable/test/supported_types/type_test.num_test.dart b/json_serializable/test/supported_types/type_test.num_test.dart index 7cd62d61b..8489d5ff7 100644 --- a/json_serializable/test/supported_types/type_test.num_test.dart +++ b/json_serializable/test/supported_types/type_test.num_test.dart @@ -2,7 +2,6 @@ // 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. -// ignore_for_file: prefer_const_declarations @TestOn('vm') library; @@ -87,8 +86,8 @@ void main() { }); // end nullable group } -final _defaultValue = 88.6; -final _altValue = 29; +const _defaultValue = 88.6; +const _altValue = 29; final _defaultInput = <String, Object?>{ 'value': _defaultValue, diff --git a/json_serializable/test/supported_types/type_test.object_test.dart b/json_serializable/test/supported_types/type_test.object_test.dart index f6333fa7a..5cad9da25 100644 --- a/json_serializable/test/supported_types/type_test.object_test.dart +++ b/json_serializable/test/supported_types/type_test.object_test.dart @@ -2,7 +2,6 @@ // 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. -// ignore_for_file: prefer_const_declarations @TestOn('vm') library; @@ -87,8 +86,8 @@ void main() { }); // end nullable group } -final _defaultValue = 'o1'; -final _altValue = 'o2'; +const _defaultValue = 'o1'; +const _altValue = 'o2'; final _defaultInput = <String, Object?>{ 'value': _defaultValue, diff --git a/json_serializable/test/supported_types/type_test.set_test.dart b/json_serializable/test/supported_types/type_test.set_test.dart index 12f2521ee..b0af7da12 100644 --- a/json_serializable/test/supported_types/type_test.set_test.dart +++ b/json_serializable/test/supported_types/type_test.set_test.dart @@ -2,7 +2,6 @@ // 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. -// ignore_for_file: prefer_const_declarations @TestOn('vm') library; @@ -87,8 +86,8 @@ void main() { }); // end nullable group } -final _defaultValue = [42, true, false, null]; -final _altValue = [43, false]; +const _defaultValue = [42, true, false, null]; +const _altValue = [43, false]; final _defaultInput = <String, Object?>{ 'value': _defaultValue, diff --git a/json_serializable/test/supported_types/type_test.string_test.dart b/json_serializable/test/supported_types/type_test.string_test.dart index a868de260..2943b4424 100644 --- a/json_serializable/test/supported_types/type_test.string_test.dart +++ b/json_serializable/test/supported_types/type_test.string_test.dart @@ -2,7 +2,6 @@ // 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. -// ignore_for_file: prefer_const_declarations @TestOn('vm') library; @@ -87,8 +86,8 @@ void main() { }); // end nullable group } -final _defaultValue = 'a string'; -final _altValue = 'another string'; +const _defaultValue = 'a string'; +const _altValue = 'another string'; final _defaultInput = <String, Object?>{ 'value': _defaultValue, diff --git a/json_serializable/test/supported_types/type_test.uri_test.dart b/json_serializable/test/supported_types/type_test.uri_test.dart index c49a890fa..1d69a3c6f 100644 --- a/json_serializable/test/supported_types/type_test.uri_test.dart +++ b/json_serializable/test/supported_types/type_test.uri_test.dart @@ -2,7 +2,6 @@ // 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. -// ignore_for_file: prefer_const_declarations @TestOn('vm') library; @@ -87,8 +86,8 @@ void main() { }); // end nullable group } -final _defaultValue = 'https://example.com'; -final _altValue = 'https://dart.dev'; +const _defaultValue = 'https://example.com'; +const _altValue = 'https://dart.dev'; final _defaultInput = <String, Object?>{ 'value': _defaultValue, diff --git a/json_serializable/tool/test_type_data.dart b/json_serializable/tool/test_type_data.dart index 53ffb5b1c..6d785a448 100644 --- a/json_serializable/tool/test_type_data.dart +++ b/json_serializable/tool/test_type_data.dart @@ -242,12 +242,12 @@ class TestTypeData { yield Replacement( ''' -final _defaultValue = 42; -final _altValue = 43; +const _defaultValue = 42; +const _altValue = 43; ''', ''' -final _defaultValue = $jsonExpression; -final _altValue = $altJsonExpression; +const _defaultValue = $jsonExpression; +const _altValue = $altJsonExpression; ''', ); From 9e8c2fd289bd3d69f01792dfc93cdfd4a0ac3411 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Wed, 12 Feb 2025 10:58:03 -0600 Subject: [PATCH 551/569] Fix extra line with Dart 3.7 syntax (#1478) Since this package is using 3.6, you can't see the result here Verified with a one-off in this package and another package to make sure nothing breaks --- json_serializable/CHANGELOG.md | 4 +++ json_serializable/lib/src/decode_helper.dart | 33 +++++++------------- json_serializable/pubspec.yaml | 2 +- 3 files changed, 17 insertions(+), 22 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index d8c5b5391..186aa799c 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,7 @@ +## 6.9.4 + +- Fix extra line being generated when targetting Dart 3.7 package. + ## 6.9.3 - Error out if the target package does not have a language version of `3.0` or diff --git a/json_serializable/lib/src/decode_helper.dart b/json_serializable/lib/src/decode_helper.dart index 488e93ef3..ea3eb3798 100644 --- a/json_serializable/lib/src/decode_helper.dart +++ b/json_serializable/lib/src/decode_helper.dart @@ -317,27 +317,18 @@ _ConstructorData _writeConstructorInvocation( '$className' '${genericClassArguments(classElement, false)}' '$constructorExtra(', - ); - if (constructorArguments.isNotEmpty) { - buffer - ..writeln() - ..writeAll(constructorArguments.map((paramElement) { - final content = - deserializeForField(paramElement.name, ctorParam: paramElement); - return ' $content,\n'; - })); - } - if (namedConstructorArguments.isNotEmpty) { - buffer - ..writeln() - ..writeAll(namedConstructorArguments.map((paramElement) { - final value = - deserializeForField(paramElement.name, ctorParam: paramElement); - return ' ${paramElement.name}: $value,\n'; - })); - } - - buffer.write(')'); + ) + ..writeAll(constructorArguments.map((paramElement) { + final content = + deserializeForField(paramElement.name, ctorParam: paramElement); + return ' $content,\n'; + })) + ..writeAll(namedConstructorArguments.map((paramElement) { + final value = + deserializeForField(paramElement.name, ctorParam: paramElement); + return ' ${paramElement.name}: $value,\n'; + })) + ..write(')'); usedCtorParamsAndFields.addAll(remainingFieldsForInvocationBody); diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 80c9658aa..a28a6509c 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 6.9.3 +version: 6.9.4 description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. From 5716df7fb1f1735de23f3246db304953df8eed8b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 2 Mar 2025 12:18:56 -0800 Subject: [PATCH 552/569] Bump the dependencies group with 2 updates (#1482) Bumps the dependencies group with 2 updates: [actions/cache](https://github.com/actions/cache) and [dart-lang/setup-dart](https://github.com/dart-lang/setup-dart). Updates `actions/cache` from 4.2.0 to 4.2.2 - [Release notes](https://github.com/actions/cache/releases) - [Changelog](https://github.com/actions/cache/blob/main/RELEASES.md) - [Commits](https://github.com/actions/cache/compare/1bd1e32a3bdc45362d1e726936510720a7c30a57...d4323d4df104b026a6aa633fdb11d772146be0bf) Updates `dart-lang/setup-dart` from 1.7.0 to 1.7.1 - [Release notes](https://github.com/dart-lang/setup-dart/releases) - [Changelog](https://github.com/dart-lang/setup-dart/blob/main/CHANGELOG.md) - [Commits](https://github.com/dart-lang/setup-dart/compare/e630b99d28a3b71860378cafdc2a067c71107f94...e51d8e571e22473a2ddebf0ef8a2123f0ab2c02c) --- updated-dependencies: - dependency-name: actions/cache dependency-type: direct:production update-type: version-update:semver-patch dependency-group: dependencies - dependency-name: dart-lang/setup-dart dependency-type: direct:production update-type: version-update:semver-patch dependency-group: dependencies ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/dart.yml | 52 +++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index b0c87c7ce..07f4ee8e5 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -21,7 +21,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 + uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:stable" @@ -29,7 +29,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94 + uses: dart-lang/setup-dart@e51d8e571e22473a2ddebf0ef8a2123f0ab2c02c with: sdk: stable - id: checkout @@ -44,7 +44,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 + uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:analyze_1" @@ -54,7 +54,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94 + uses: dart-lang/setup-dart@e51d8e571e22473a2ddebf0ef8a2123f0ab2c02c with: sdk: "3.6.0" - id: checkout @@ -110,7 +110,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 + uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:format-analyze_0" @@ -120,7 +120,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94 + uses: dart-lang/setup-dart@e51d8e571e22473a2ddebf0ef8a2123f0ab2c02c with: sdk: dev - id: checkout @@ -196,7 +196,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 + uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" @@ -206,7 +206,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94 + uses: dart-lang/setup-dart@e51d8e571e22473a2ddebf0ef8a2123f0ab2c02c with: sdk: "3.6.0" - id: checkout @@ -257,7 +257,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 + uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:json_serializable;commands:test_3" @@ -267,7 +267,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94 + uses: dart-lang/setup-dart@e51d8e571e22473a2ddebf0ef8a2123f0ab2c02c with: sdk: "3.6.0" - id: checkout @@ -291,7 +291,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 + uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:json_serializable;commands:test_1" @@ -301,7 +301,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94 + uses: dart-lang/setup-dart@e51d8e571e22473a2ddebf0ef8a2123f0ab2c02c with: sdk: "3.6.0" - id: checkout @@ -325,7 +325,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 + uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:json_serializable;commands:test_2" @@ -335,7 +335,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94 + uses: dart-lang/setup-dart@e51d8e571e22473a2ddebf0ef8a2123f0ab2c02c with: sdk: "3.6.0" - id: checkout @@ -359,7 +359,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 + uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" @@ -369,7 +369,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94 + uses: dart-lang/setup-dart@e51d8e571e22473a2ddebf0ef8a2123f0ab2c02c with: sdk: dev - id: checkout @@ -420,7 +420,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 + uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:json_serializable;commands:test_3" @@ -430,7 +430,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94 + uses: dart-lang/setup-dart@e51d8e571e22473a2ddebf0ef8a2123f0ab2c02c with: sdk: dev - id: checkout @@ -454,7 +454,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 + uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:json_serializable;commands:test_1" @@ -464,7 +464,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94 + uses: dart-lang/setup-dart@e51d8e571e22473a2ddebf0ef8a2123f0ab2c02c with: sdk: dev - id: checkout @@ -488,7 +488,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 + uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:json_serializable;commands:test_2" @@ -498,7 +498,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94 + uses: dart-lang/setup-dart@e51d8e571e22473a2ddebf0ef8a2123f0ab2c02c with: sdk: dev - id: checkout @@ -522,7 +522,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 + uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:_test_yaml-checked_yaml-example;commands:test_1" @@ -532,7 +532,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94 + uses: dart-lang/setup-dart@e51d8e571e22473a2ddebf0ef8a2123f0ab2c02c with: sdk: "3.6.0" - id: checkout @@ -582,7 +582,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 + uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:_test_yaml-checked_yaml-example;commands:test_1" @@ -592,7 +592,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94 + uses: dart-lang/setup-dart@e51d8e571e22473a2ddebf0ef8a2123f0ab2c02c with: sdk: dev - id: checkout From a4edc02315e387a195e599b41c9568f8e1ecf5e5 Mon Sep 17 00:00:00 2001 From: Travis Mortimer <110429180+travis-mortimer@users.noreply.github.com> Date: Sun, 2 Mar 2025 17:54:39 -0700 Subject: [PATCH 553/569] Update README.md (#1475) This seems to be a common question that is quite difficult to answer. The most visible solution I found previously was to use the `remove_from_coverage` package to remove generated files from the coverage report. That solution complicates CLI commands and requires updating CI/CD pipelines. --- json_serializable/README.md | 12 ++++++++++++ json_serializable/tool/readme/readme_template.md | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/json_serializable/README.md b/json_serializable/README.md index 713ff4c1e..d53e3138e 100644 --- a/json_serializable/README.md +++ b/json_serializable/README.md @@ -287,6 +287,18 @@ targets: include_if_null: true ``` +To exclude generated files from coverage, you can further configure `build.yaml`. + +```yaml +targets: + $default: + builders: + source_gen:combining_builder: + options: + preamble: | + // coverage:ignore-file +``` + [example]: https://github.com/google/json_serializable.dart/tree/master/example [dart build system]: https://github.com/dart-lang/build [package:json_annotation]: https://pub.dev/packages/json_annotation diff --git a/json_serializable/tool/readme/readme_template.md b/json_serializable/tool/readme/readme_template.md index adba60f1c..d99c3ec78 100644 --- a/json_serializable/tool/readme/readme_template.md +++ b/json_serializable/tool/readme/readme_template.md @@ -152,6 +152,18 @@ targets: include_if_null: true ``` +To exclude generated files from coverage, you can further configure `build.yaml`. + +```yaml +targets: + $default: + builders: + source_gen:combining_builder: + options: + preamble: | + // coverage:ignore-file +``` + [example]: https://github.com/google/json_serializable.dart/tree/master/example [dart build system]: https://github.com/dart-lang/build [package:json_annotation]: https://pub.dev/packages/json_annotation From d05428ee759cd925f94ca9083efa20a16cebee86 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 31 Mar 2025 21:23:56 -0700 Subject: [PATCH 554/569] Bump actions/cache from 4.2.2 to 4.2.3 in the dependencies group (#1484) Bumps the dependencies group with 1 update: [actions/cache](https://github.com/actions/cache). Updates `actions/cache` from 4.2.2 to 4.2.3 - [Release notes](https://github.com/actions/cache/releases) - [Changelog](https://github.com/actions/cache/blob/main/RELEASES.md) - [Commits](https://github.com/actions/cache/compare/d4323d4df104b026a6aa633fdb11d772146be0bf...5a3ec84eff668545956fd18022155c47e93e2684) --- updated-dependencies: - dependency-name: actions/cache dependency-version: 4.2.3 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: dependencies ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/dart.yml | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 07f4ee8e5..4af5af68b 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -21,7 +21,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf + uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:stable" @@ -44,7 +44,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf + uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:analyze_1" @@ -110,7 +110,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf + uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:format-analyze_0" @@ -196,7 +196,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf + uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" @@ -257,7 +257,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf + uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:json_serializable;commands:test_3" @@ -291,7 +291,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf + uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:json_serializable;commands:test_1" @@ -325,7 +325,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf + uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:json_serializable;commands:test_2" @@ -359,7 +359,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf + uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" @@ -420,7 +420,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf + uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:json_serializable;commands:test_3" @@ -454,7 +454,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf + uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:json_serializable;commands:test_1" @@ -488,7 +488,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf + uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:json_serializable;commands:test_2" @@ -522,7 +522,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf + uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:_test_yaml-checked_yaml-example;commands:test_1" @@ -582,7 +582,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf + uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:_test_yaml-checked_yaml-example;commands:test_1" From cd1cf2e371f8136f0bf4d26212f17d9a531639a0 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Thu, 17 Apr 2025 13:08:12 -0500 Subject: [PATCH 555/569] Fix for latest analyzer (#1487) Fixes https://github.com/google/json_serializable.dart/issues/1485 --- analysis_options.yaml | 3 +++ json_serializable/CHANGELOG.md | 7 ++++++- json_serializable/lib/src/decode_helper.dart | 5 +---- json_serializable/lib/src/field_helpers.dart | 14 ++++++++++---- json_serializable/pubspec.yaml | 4 ++-- 5 files changed, 22 insertions(+), 11 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index 5381bdab6..629e6274d 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -4,6 +4,9 @@ include: package:dart_flutter_team_lints/analysis_options.yaml analyzer: language: strict-casts: true + errors: + # Analyzer v7.4.0 crazy + deprecated_member_use: ignore linter: rules: diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 186aa799c..332e9a493 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,6 +1,11 @@ +## 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 targetting Dart 3.7 package. +- Fix extra line being generated when targeting Dart 3.7 package. ## 6.9.3 diff --git a/json_serializable/lib/src/decode_helper.dart b/json_serializable/lib/src/decode_helper.dart index ea3eb3798..3a20abbbc 100644 --- a/json_serializable/lib/src/decode_helper.dart +++ b/json_serializable/lib/src/decode_helper.dart @@ -61,10 +61,7 @@ mixin DecodeHelper implements HelperCore { config.constructor, accessibleFields.keys, accessibleFields.values - .where((fe) => - element.augmented - .lookUpSetter(name: fe.name, library: element.library) != - null) + .where((fe) => element.lookUpSetter(fe.name, element.library) != null) .map((fe) => fe.name) .toList(), unavailableReasons, diff --git a/json_serializable/lib/src/field_helpers.dart b/json_serializable/lib/src/field_helpers.dart index c14d0d4b4..8f8811f47 100644 --- a/json_serializable/lib/src/field_helpers.dart +++ b/json_serializable/lib/src/field_helpers.dart @@ -3,6 +3,9 @@ // BSD-style license that can be found in the LICENSE file. import 'package:analyzer/dart/element/element.dart'; +import 'package:analyzer/src/dart/element/element.dart' // ignore: implementation_imports + show + InterfaceElementImpl; import 'package:analyzer/src/dart/element/inheritance_manager3.dart' // ignore: implementation_imports show InheritanceManager3; @@ -81,15 +84,18 @@ List<FieldElement> createSortedFieldSet(ClassElement element) { final inheritedFields = <String, FieldElement>{}; final manager = InheritanceManager3(); - for (final v in manager.getInheritedConcreteMap2(element).values) { + for (final v in manager + .getInheritedConcreteMap2(element as InterfaceElementImpl) + .values) { assert(v is! FieldElement); if (_dartCoreObjectChecker.isExactly(v.enclosingElement3)) { continue; } - if (v is PropertyAccessorElement && v.isGetter) { - assert(v.variable2 is FieldElement); - final variable = v.variable2 as FieldElement; + if (v is PropertyAccessorElement && + (v as PropertyAccessorElement).isGetter) { + assert((v as PropertyAccessorElement).variable2 is FieldElement); + final variable = (v as PropertyAccessorElement).variable2 as FieldElement; assert(!inheritedFields.containsKey(variable.name)); inheritedFields[variable.name] = variable; } diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index a28a6509c..94d1cdfa6 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 6.9.4 +version: 6.9.5 description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. @@ -15,7 +15,7 @@ topics: resolution: workspace dependencies: - analyzer: '>=6.5.0 <8.0.0' + analyzer: '>=6.9.0 <8.0.0' async: ^2.10.0 build: ^2.4.1 build_config: ^1.1.0 From 062771bb6727a5d4b67ae0f300d5982af64521d6 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Thu, 17 Apr 2025 13:32:56 -0500 Subject: [PATCH 556/569] Drop pkg:collection usage in lib (#1488) --- json_serializable/CHANGELOG.md | 4 ++++ .../lib/src/type_helpers/json_converter_helper.dart | 10 +++++----- .../lib/src/type_helpers/json_helper.dart | 7 ++++--- json_serializable/lib/src/type_helpers/map_helper.dart | 3 +-- json_serializable/pubspec.yaml | 4 ++-- .../test/generic_files/generic_class.dart | 3 +-- json_serializable/test/test_utils.dart | 2 ++ 7 files changed, 19 insertions(+), 14 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 332e9a493..e49cc7918 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,7 @@ +## 6.9.6-wip + +- Move `package:collection` to a dev dependency. + ## 6.9.5 - Support the `analyzer: '>=6.9.0 <8.0.0'`. diff --git a/json_serializable/lib/src/type_helpers/json_converter_helper.dart b/json_serializable/lib/src/type_helpers/json_converter_helper.dart index 9958368af..20ec0fc25 100644 --- a/json_serializable/lib/src/type_helpers/json_converter_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_converter_helper.dart @@ -5,7 +5,6 @@ import 'package:analyzer/dart/constant/value.dart'; import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/type.dart'; -import 'package:collection/collection.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:source_gen/source_gen.dart'; import 'package:source_helper/source_helper.dart'; @@ -280,10 +279,11 @@ _ConverterMatch? _compatibleMatch( ) { final converterClassElement = constantValue.type!.element as ClassElement; - final jsonConverterSuper = - converterClassElement.allSupertypes.singleWhereOrNull( - (e) => _jsonConverterChecker.isExactly(e.element), - ); + final jsonConverterSuper = converterClassElement.allSupertypes + .where( + (e) => _jsonConverterChecker.isExactly(e.element), + ) + .singleOrNull; if (jsonConverterSuper == null) { return null; diff --git a/json_serializable/lib/src/type_helpers/json_helper.dart b/json_serializable/lib/src/type_helpers/json_helper.dart index fe10a3fea..d66ab772e 100644 --- a/json_serializable/lib/src/type_helpers/json_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_helper.dart @@ -4,7 +4,6 @@ import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/type.dart'; -import 'package:collection/collection.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:source_gen/source_gen.dart'; import 'package:source_helper/source_helper.dart'; @@ -79,7 +78,8 @@ class JsonHelper extends TypeHelper<TypeHelperContextWithConfig> { final classElement = targetType.element; final fromJsonCtor = classElement.constructors - .singleWhereOrNull((ce) => ce.name == 'fromJson'); + .where((ce) => ce.name == 'fromJson') + .singleOrNull; var output = expression; if (fromJsonCtor != null) { @@ -291,4 +291,5 @@ ClassConfig? _annotation(ClassConfig config, InterfaceType source) { MethodElement? _toJsonMethod(DartType type) => type.typeImplementations .map((dt) => dt is InterfaceType ? dt.getMethod('toJson') : null) - .firstWhereOrNull((me) => me != null); + .where((me) => me != null) + .firstOrNull; diff --git a/json_serializable/lib/src/type_helpers/map_helper.dart b/json_serializable/lib/src/type_helpers/map_helper.dart index 51cb3a0a5..e0c6ef560 100644 --- a/json_serializable/lib/src/type_helpers/map_helper.dart +++ b/json_serializable/lib/src/type_helpers/map_helper.dart @@ -3,7 +3,6 @@ // BSD-style license that can be found in the LICENSE file. import 'package:analyzer/dart/element/type.dart'; -import 'package:collection/collection.dart'; import 'package:source_helper/source_helper.dart'; import '../constants.dart'; @@ -147,7 +146,7 @@ final _instances = [ ]; ToFromStringHelper? _forType(DartType type) => - _instances.singleWhereOrNull((i) => i.matches(type)); + _instances.where((i) => i.matches(type)).singleOrNull; /// Returns `true` if [keyType] can be automatically converted to/from String – /// and is therefor usable as a key in a [Map]. diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 94d1cdfa6..10e7ec8aa 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 6.9.5 +version: 6.9.6-wip description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. @@ -19,7 +19,6 @@ dependencies: async: ^2.10.0 build: ^2.4.1 build_config: ^1.1.0 - collection: ^1.17.0 dart_style: '>=2.3.7 <4.0.0' # Use a tight version constraint to ensure that a constraint on @@ -37,6 +36,7 @@ dev_dependencies: path: ../shared_test build_runner: ^2.4.6 build_verify: ^3.0.0 + collection: ^1.17.0 logging: ^1.0.0 source_gen_test: ^1.0.6 test: ^1.24.4 diff --git a/json_serializable/test/generic_files/generic_class.dart b/json_serializable/test/generic_files/generic_class.dart index 0ebfe7d1e..8c8b8d715 100644 --- a/json_serializable/test/generic_files/generic_class.dart +++ b/json_serializable/test/generic_files/generic_class.dart @@ -4,7 +4,6 @@ // ignore_for_file: inference_failure_on_instance_creation -import 'package:collection/collection.dart'; import 'package:json_annotation/json_annotation.dart'; import '../test_utils.dart'; @@ -146,7 +145,7 @@ class Issue980ParentClass { other is Issue980ParentClass && deepEquals(list, other.list); @override - int get hashCode => const DeepCollectionEquality().hash(list); + int get hashCode => deepHash(list); } @JsonSerializable(genericArgumentFactories: true) diff --git a/json_serializable/test/test_utils.dart b/json_serializable/test/test_utils.dart index 7d09c427c..fce40a9d1 100644 --- a/json_serializable/test/test_utils.dart +++ b/json_serializable/test/test_utils.dart @@ -6,5 +6,7 @@ import 'package:collection/collection.dart'; export 'package:_json_serial_shared_test/shared_test.dart'; +int deepHash(List value) => const DeepCollectionEquality().hash(value); + bool deepEquals(dynamic a, dynamic b) => const DeepCollectionEquality().equals(a, b); From cacecd2ae5e2e2b0a4a3974ba330c43fc18f8ca5 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Sat, 31 May 2025 17:18:35 -0500 Subject: [PATCH 557/569] Swap out link to StackOverflow, which fails verification (#1495) --- .github/ISSUE_TEMPLATE.md | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index b13533755..912e13757 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -4,9 +4,5 @@ In order to route, prioritize, and act on this, please include the entire output of either `dart --version` or `flutter --version`, depending on what you're using. -Is it really an issue? For general questions consider starting with Stack -Overflow: -https://stackoverflow.com/questions/tagged/dart - -Also consider our Gitter channel for light-weight/quick discussions: -https://gitter.im/dart-lang/build +Is it really an issue? For general questions consider starting with community +resources: https://dart.dev/community From 5848ba83a20fa536c9178834cf103414a17971c2 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 1 Jun 2025 14:21:17 -0700 Subject: [PATCH 558/569] Bump DavidAnson/markdownlint-cli2-action in the dependencies group (#1497) Bumps the dependencies group with 1 update: [DavidAnson/markdownlint-cli2-action](https://github.com/davidanson/markdownlint-cli2-action). Updates `DavidAnson/markdownlint-cli2-action` from 19.1.0 to 20.0.0 - [Release notes](https://github.com/davidanson/markdownlint-cli2-action/releases) - [Commits](https://github.com/davidanson/markdownlint-cli2-action/compare/05f32210e84442804257b2a6f20b273450ec8265...992badcdf24e3b8eb7e87ff9287fe931bcb00c6e) --- updated-dependencies: - dependency-name: DavidAnson/markdownlint-cli2-action dependency-version: 20.0.0 dependency-type: direct:production update-type: version-update:semver-major dependency-group: dependencies ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/markdown_linter.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/markdown_linter.yml b/.github/workflows/markdown_linter.yml index 5cd903b1b..840a93d4d 100644 --- a/.github/workflows/markdown_linter.yml +++ b/.github/workflows/markdown_linter.yml @@ -17,4 +17,4 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 - - uses: DavidAnson/markdownlint-cli2-action@05f32210e84442804257b2a6f20b273450ec8265 + - uses: DavidAnson/markdownlint-cli2-action@992badcdf24e3b8eb7e87ff9287fe931bcb00c6e From 83e79058f3da3f912965dd9356796f25c41ae1b3 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Mon, 2 Jun 2025 12:27:23 -0500 Subject: [PATCH 559/569] new Dart version, new format (#1494) --- .github/workflows/dart.yml | 64 +- _test_yaml/pubspec.yaml | 2 +- _test_yaml/test/src/build_config.dart | 23 +- _test_yaml/test/src/build_config.g.dart | 217 +- _test_yaml/test/yaml_test.dart | 8 +- analysis_options.yaml | 2 +- checked_yaml/CHANGELOG.md | 2 +- checked_yaml/README.md | 8 +- checked_yaml/example/example.dart | 6 +- checked_yaml/example/example.g.dart | 34 +- checked_yaml/lib/checked_yaml.dart | 25 +- checked_yaml/pubspec.yaml | 2 +- checked_yaml/test/custom_error_test.dart | 19 +- checked_yaml/test/example_test.dart | 80 +- checked_yaml/test/readme_test.dart | 27 +- example/lib/example.dart | 7 +- example/lib/example.g.dart | 83 +- .../lib/generic_response_class_example.dart | 21 +- .../lib/generic_response_class_example.g.dart | 30 +- example/lib/json_converter_example.g.dart | 43 +- example/lib/nested_values_example.dart | 14 +- example/lib/nested_values_example.g.dart | 5 +- example/lib/tuple_example.dart | 6 +- example/lib/tuple_example.g.dart | 29 +- example/pubspec.yaml | 2 +- example/test/example_test.dart | 5 +- example/test/generic_response_class_test.dart | 8 +- example/test/json_convert_example_test.dart | 64 +- json_annotation/CHANGELOG.md | 2 +- .../lib/src/allowed_keys_helpers.dart | 20 +- json_annotation/lib/src/checked_helpers.dart | 34 +- .../lib/src/json_serializable.dart | 28 +- .../lib/src/json_serializable.g.dart | 134 +- json_annotation/pubspec.yaml | 2 +- json_serializable/CHANGELOG.md | 1 + json_serializable/README.md | 25 +- json_serializable/example/example.g.dart | 20 +- json_serializable/lib/builder.dart | 2 +- .../lib/src/check_dependencies.dart | 16 +- json_serializable/lib/src/decode_helper.dart | 101 +- json_serializable/lib/src/encoder_helper.dart | 44 +- json_serializable/lib/src/enum_utils.dart | 18 +- json_serializable/lib/src/field_helpers.dart | 43 +- .../lib/src/generator_helper.dart | 48 +- json_serializable/lib/src/helper_core.dart | 33 +- .../lib/src/json_enum_generator.dart | 10 +- json_serializable/lib/src/json_key_utils.dart | 65 +- .../lib/src/json_literal_generator.dart | 9 +- .../lib/src/json_part_builder.dart | 32 +- .../lib/src/json_serializable_generator.dart | 21 +- json_serializable/lib/src/lambda_result.dart | 4 +- json_serializable/lib/src/settings.dart | 29 +- .../lib/src/shared_checkers.dart | 2 +- .../lib/src/type_helper_ctx.dart | 61 +- .../lib/src/type_helpers/big_int_helper.dart | 19 +- .../lib/src/type_helpers/config_types.dart | 41 +- .../lib/src/type_helpers/convert_helper.dart | 6 +- .../src/type_helpers/date_time_helper.dart | 24 +- .../type_helpers/generic_factory_helper.dart | 6 +- .../type_helpers/json_converter_helper.dart | 27 +- .../lib/src/type_helpers/json_helper.dart | 26 +- .../lib/src/type_helpers/map_helper.dart | 29 +- .../lib/src/type_helpers/record_helper.dart | 25 +- .../lib/src/type_helpers/to_from_string.dart | 25 +- .../lib/src/type_helpers/uri_helper.dart | 16 +- .../lib/src/type_helpers/value_helper.dart | 8 +- json_serializable/lib/src/utils.dart | 80 +- json_serializable/pubspec.yaml | 2 +- .../test/annotation_version_test.dart | 75 +- json_serializable/test/config_test.dart | 49 +- .../test/custom_configuration_test.dart | 116 +- .../test/default_value/default_value.dart | 8 +- .../test/default_value/default_value.g.dart | 117 +- .../default_value.g_any_map__checked.dart | 13 +- .../default_value.g_any_map__checked.g.dart | 180 +- .../default_value_interface.dart | 9 +- .../default_value/default_value_test.dart | 4 +- .../default_value/implicit_default_value.dart | 2 +- .../implicit_default_value.g.dart | 175 +- json_serializable/test/enum_helper_test.dart | 2 +- json_serializable/test/field_matrix_test.dart | 54 +- .../test/field_matrix_test.field_matrix.dart | 36 +- .../field_matrix_test.field_matrix.g.dart | 333 +- .../generic_argument_factories.dart | 12 +- .../generic_argument_factories.g.dart | 48 +- .../generic_argument_factories_nullable.dart | 12 +- ...generic_argument_factories_nullable.g.dart | 106 +- .../test/generic_files/generic_class.dart | 30 +- .../test/generic_files/generic_class.g.dart | 169 +- .../test/generic_files/generic_test.dart | 73 +- .../test/integration/converter_examples.dart | 4 +- .../integration/converter_examples.g.dart | 86 +- .../create_per_field_to_json_example.dart | 18 +- .../create_per_field_to_json_example.g.dart | 102 +- .../test/integration/field_map_example.dart | 6 +- .../test/integration/field_map_example.g.dart | 20 +- .../test/integration/integration_test.dart | 197 +- .../test/integration/json_enum_example.dart | 38 +- .../test/integration/json_enum_example.g.dart | 45 +- .../test/integration/json_keys_example.dart | 6 +- .../test/integration/json_keys_example.g.dart | 12 +- .../test/integration/json_test_common.dart | 10 +- .../test/integration/json_test_example.dart | 14 +- .../test/integration/json_test_example.g.dart | 205 +- .../json_test_example.g_any_map.dart | 34 +- .../json_test_example.g_any_map.g.dart | 220 +- .../test/kitchen_sink/kitchen_sink.dart | 78 +- .../test/kitchen_sink/kitchen_sink.g.dart | 426 +- .../kitchen_sink/kitchen_sink.g_any_map.dart | 87 +- .../kitchen_sink.g_any_map.g.dart | 406 +- .../kitchen_sink.g_any_map__checked.dart | 90 +- .../kitchen_sink.g_any_map__checked.g.dart | 714 +- .../kitchen_sink.g_exclude_null.dart | 87 +- .../kitchen_sink.g_exclude_null.g.dart | 455 +- .../kitchen_sink.g_explicit_to_json.dart | 87 +- .../kitchen_sink.g_explicit_to_json.g.dart | 432 +- .../kitchen_sink/kitchen_sink_interface.dart | 6 +- .../test/kitchen_sink/kitchen_sink_test.dart | 73 +- .../kitchen_sink_test_shared.dart | 13 +- .../kitchen_sink/kitchen_sink_yaml_test.dart | 37 +- .../test/kitchen_sink/simple_object.g.dart | 9 +- .../test/literal/json_literal.g.dart | 14 +- .../test/literal/json_literal_test.dart | 7 +- json_serializable/test/shared_config.dart | 35 +- .../src/_json_serializable_test_input.dart | 184 +- .../test/src/checked_test_input.dart | 36 +- .../test/src/constants_copy.dart | 2 +- .../test/src/core_subclass_type_input.dart | 44 +- .../test/src/default_value_input.dart | 74 +- .../test/src/field_namer_input.dart | 12 +- .../test/src/generic_test_input.dart | 42 +- .../test/src/inheritance_test_input.dart | 64 +- .../test/src/json_converter_test_input.dart | 101 +- .../test/src/map_key_variety_test_input.dart | 14 +- .../test/src/setter_test_input.dart | 6 +- .../test/src/to_from_json_test_input.dart | 129 +- .../src/unknown_enum_value_test_input.dart | 21 +- .../test/supported_types/extra_map_test.dart | 4 +- .../test/supported_types/input.dart | 5 +- .../test/supported_types/input.g.dart | 6 +- .../supported_types/input.type_bigint.dart | 10 +- .../supported_types/input.type_bigint.g.dart | 20 +- .../test/supported_types/input.type_bool.dart | 10 +- .../supported_types/input.type_bool.g.dart | 16 +- .../supported_types/input.type_datetime.dart | 10 +- .../input.type_datetime.g.dart | 20 +- .../supported_types/input.type_double.dart | 10 +- .../supported_types/input.type_double.g.dart | 16 +- .../supported_types/input.type_duration.dart | 8 +- .../input.type_duration.g.dart | 15 +- .../supported_types/input.type_enumtype.dart | 10 +- .../input.type_enumtype.g.dart | 17 +- .../test/supported_types/input.type_int.dart | 10 +- .../supported_types/input.type_int.g.dart | 16 +- .../supported_types/input.type_iterable.dart | 294 +- .../input.type_iterable.g.dart | 850 +- .../test/supported_types/input.type_list.dart | 294 +- .../supported_types/input.type_list.g.dart | 905 +- .../test/supported_types/input.type_map.dart | 2991 ++--- .../supported_types/input.type_map.g.dart | 9672 ++++++++--------- .../test/supported_types/input.type_num.dart | 10 +- .../supported_types/input.type_num.g.dart | 16 +- .../supported_types/input.type_object.dart | 10 +- .../supported_types/input.type_object.g.dart | 21 +- .../supported_types/input.type_record.dart | 300 +- .../supported_types/input.type_record.g.dart | 1796 ++- .../test/supported_types/input.type_set.dart | 294 +- .../supported_types/input.type_set.g.dart | 900 +- .../supported_types/input.type_string.dart | 10 +- .../supported_types/input.type_string.g.dart | 16 +- .../test/supported_types/input.type_uri.dart | 10 +- .../supported_types/input.type_uri.g.dart | 20 +- .../support_types_extra_test.dart | 24 +- .../type_test.bigint_test.dart | 24 +- .../supported_types/type_test.bool_test.dart | 24 +- .../test/supported_types/type_test.dart | 25 +- .../type_test.datetime_test.dart | 24 +- .../type_test.double_test.dart | 24 +- .../type_test.duration_test.dart | 21 +- .../type_test.enumtype_test.dart | 24 +- .../supported_types/type_test.int_test.dart | 24 +- .../type_test.iterable_test.dart | 24 +- .../supported_types/type_test.list_test.dart | 24 +- .../supported_types/type_test.map_test.dart | 24 +- .../supported_types/type_test.num_test.dart | 24 +- .../type_test.object_test.dart | 24 +- .../supported_types/type_test.set_test.dart | 24 +- .../type_test.string_test.dart | 24 +- .../supported_types/type_test.uri_test.dart | 24 +- .../tool/field_matrix_builder.dart | 12 +- .../tool/readme/readme_examples.dart | 5 +- .../tool/readme/readme_examples.g.dart | 26 +- json_serializable/tool/readme_builder.dart | 77 +- json_serializable/tool/shared.dart | 17 +- json_serializable/tool/test_builder.dart | 52 +- json_serializable/tool/test_type_builder.dart | 56 +- json_serializable/tool/test_type_data.dart | 98 +- pubspec.yaml | 2 +- shared_test/pubspec.yaml | 2 +- tool/ci.sh | 2 +- 200 files changed, 12889 insertions(+), 14877 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 4af5af68b..db6794a07 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -1,4 +1,4 @@ -# Created with package:mono_repo v6.6.2 +# Created with package:mono_repo v6.6.3 name: Dart CI on: push: @@ -36,27 +36,27 @@ jobs: name: Checkout repository uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 - name: mono_repo self validate - run: dart pub global activate mono_repo 6.6.2 + run: dart pub global activate mono_repo 6.6.3 - name: mono_repo self validate run: dart pub global run mono_repo generate --validate job_002: - name: "analyzer_and_format; Dart 3.6.0; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; `dart analyze`" + name: "analyzer_and_format; Dart 3.8.0; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; `dart analyze`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:analyze_1" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.8.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:analyze_1" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable - os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0 + os:ubuntu-latest;pub-cache-hosted;sdk:3.8.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable + os:ubuntu-latest;pub-cache-hosted;sdk:3.8.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK uses: dart-lang/setup-dart@e51d8e571e22473a2ddebf0ef8a2123f0ab2c02c with: - sdk: "3.6.0" + sdk: "3.8.0" - id: checkout name: Checkout repository uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 @@ -192,23 +192,23 @@ jobs: if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'" working-directory: json_serializable job_004: - name: "unit_test; Dart 3.6.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; `dart test`" + name: "unit_test; Dart 3.8.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; `dart test`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.8.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:_test_yaml-checked_yaml-example-json_serializable - os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0 + os:ubuntu-latest;pub-cache-hosted;sdk:3.8.0;packages:_test_yaml-checked_yaml-example-json_serializable + os:ubuntu-latest;pub-cache-hosted;sdk:3.8.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK uses: dart-lang/setup-dart@e51d8e571e22473a2ddebf0ef8a2123f0ab2c02c with: - sdk: "3.6.0" + sdk: "3.8.0" - id: checkout name: Checkout repository uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 @@ -253,23 +253,23 @@ jobs: - job_002 - job_003 job_005: - name: "unit_test; Dart 3.6.0; PKG: json_serializable; `dart test --run-skipped -t presubmit-only test/annotation_version_test.dart`" + name: "unit_test; Dart 3.8.0; PKG: json_serializable; `dart test --run-skipped -t presubmit-only test/annotation_version_test.dart`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:json_serializable;commands:test_3" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.8.0;packages:json_serializable;commands:test_3" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:json_serializable - os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0 + os:ubuntu-latest;pub-cache-hosted;sdk:3.8.0;packages:json_serializable + os:ubuntu-latest;pub-cache-hosted;sdk:3.8.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK uses: dart-lang/setup-dart@e51d8e571e22473a2ddebf0ef8a2123f0ab2c02c with: - sdk: "3.6.0" + sdk: "3.8.0" - id: checkout name: Checkout repository uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 @@ -287,23 +287,23 @@ jobs: - job_002 - job_003 job_006: - name: "unit_test; Dart 3.6.0; PKG: json_serializable; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" + name: "unit_test; Dart 3.8.0; PKG: json_serializable; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:json_serializable;commands:test_1" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.8.0;packages:json_serializable;commands:test_1" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:json_serializable - os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0 + os:ubuntu-latest;pub-cache-hosted;sdk:3.8.0;packages:json_serializable + os:ubuntu-latest;pub-cache-hosted;sdk:3.8.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK uses: dart-lang/setup-dart@e51d8e571e22473a2ddebf0ef8a2123f0ab2c02c with: - sdk: "3.6.0" + sdk: "3.8.0" - id: checkout name: Checkout repository uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 @@ -321,23 +321,23 @@ jobs: - job_002 - job_003 job_007: - name: "unit_test; Dart 3.6.0; PKG: json_serializable; `dart test -p chrome`" + name: "unit_test; Dart 3.8.0; PKG: json_serializable; `dart test -p chrome`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:json_serializable;commands:test_2" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.8.0;packages:json_serializable;commands:test_2" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:json_serializable - os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0 + os:ubuntu-latest;pub-cache-hosted;sdk:3.8.0;packages:json_serializable + os:ubuntu-latest;pub-cache-hosted;sdk:3.8.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK uses: dart-lang/setup-dart@e51d8e571e22473a2ddebf0ef8a2123f0ab2c02c with: - sdk: "3.6.0" + sdk: "3.8.0" - id: checkout name: Checkout repository uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 @@ -518,23 +518,23 @@ jobs: - job_002 - job_003 job_012: - name: "ensure_build; Dart 3.6.0; PKGS: _test_yaml, checked_yaml, example; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" + name: "ensure_build; Dart 3.8.0; PKGS: _test_yaml, checked_yaml, example; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:_test_yaml-checked_yaml-example;commands:test_1" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.8.0;packages:_test_yaml-checked_yaml-example;commands:test_1" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:_test_yaml-checked_yaml-example - os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0 + os:ubuntu-latest;pub-cache-hosted;sdk:3.8.0;packages:_test_yaml-checked_yaml-example + os:ubuntu-latest;pub-cache-hosted;sdk:3.8.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK uses: dart-lang/setup-dart@e51d8e571e22473a2ddebf0ef8a2123f0ab2c02c with: - sdk: "3.6.0" + sdk: "3.8.0" - id: checkout name: Checkout repository uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 diff --git a/_test_yaml/pubspec.yaml b/_test_yaml/pubspec.yaml index 5fa5ac1ac..a2496e7ce 100644 --- a/_test_yaml/pubspec.yaml +++ b/_test_yaml/pubspec.yaml @@ -2,7 +2,7 @@ name: _test_yaml publish_to: none environment: - sdk: ^3.6.0 + sdk: ^3.8.0 resolution: workspace diff --git a/_test_yaml/test/src/build_config.dart b/_test_yaml/test/src/build_config.dart index a31c1c5b6..958329f8d 100644 --- a/_test_yaml/test/src/build_config.dart +++ b/_test_yaml/test/src/build_config.dart @@ -22,10 +22,11 @@ class Config { } @JsonSerializable( - includeIfNull: false, - disallowUnrecognizedKeys: true, - checked: true, - anyMap: true) + includeIfNull: false, + disallowUnrecognizedKeys: true, + checked: true, + anyMap: true, +) class Builder { final String? target; @@ -71,8 +72,11 @@ class Builder { this.configLocation, }) { if (builderFactories.isEmpty) { - throw ArgumentError.value(builderFactories, 'builderFactories', - 'Must have at least one value.'); + throw ArgumentError.value( + builderFactories, + 'builderFactories', + 'Must have at least one value.', + ); } } @@ -82,11 +86,6 @@ class Builder { } @JsonEnum(fieldRename: FieldRename.snake) -enum AutoApply { - none, - dependents, - allPackages, - rootPackage, -} +enum AutoApply { none, dependents, allPackages, rootPackage } enum BuildTo { cache, source } diff --git a/_test_yaml/test/src/build_config.g.dart b/_test_yaml/test/src/build_config.g.dart index e4d832e78..78bb619b9 100644 --- a/_test_yaml/test/src/build_config.g.dart +++ b/_test_yaml/test/src/build_config.g.dart @@ -6,36 +6,34 @@ part of 'build_config.dart'; // JsonSerializableGenerator // ************************************************************************** -Config _$ConfigFromJson(Map json) => $checkedCreate( - 'Config', - json, - ($checkedConvert) { - $checkKeys( - json, - requiredKeys: const ['builders'], - ); - final val = Config( - builders: $checkedConvert( - 'builders', - (v) => (v as Map).map( - (k, e) => MapEntry(k as String, Builder.fromJson(e as Map)), - )), - ); - $checkedConvert( - 'weights', - (v) => val.weights = (v as Map?)?.map( - (k, e) => MapEntry( - $enumDecode(_$AutoApplyEnumMap, k), (e as num?)?.toInt()), - )); - return val; - }, - ); +Config _$ConfigFromJson(Map json) => $checkedCreate('Config', json, ( + $checkedConvert, +) { + $checkKeys(json, requiredKeys: const ['builders']); + final val = Config( + builders: $checkedConvert( + 'builders', + (v) => (v as Map).map( + (k, e) => MapEntry(k as String, Builder.fromJson(e as Map)), + ), + ), + ); + $checkedConvert( + 'weights', + (v) => val.weights = (v as Map?)?.map( + (k, e) => + MapEntry($enumDecode(_$AutoApplyEnumMap, k), (e as num?)?.toInt()), + ), + ); + return val; +}); Map<String, dynamic> _$ConfigToJson(Config instance) => <String, dynamic>{ - 'builders': instance.builders, - 'weights': - instance.weights?.map((k, e) => MapEntry(_$AutoApplyEnumMap[k]!, e)), - }; + 'builders': instance.builders, + 'weights': instance.weights?.map( + (k, e) => MapEntry(_$AutoApplyEnumMap[k]!, e), + ), +}; const _$AutoApplyEnumMap = { AutoApply.none: 'none', @@ -45,83 +43,96 @@ const _$AutoApplyEnumMap = { }; Builder _$BuilderFromJson(Map json) => $checkedCreate( - 'Builder', + 'Builder', + json, + ($checkedConvert) { + $checkKeys( json, - ($checkedConvert) { - $checkKeys( - json, - allowedKeys: const [ - 'target', - 'import', - 'is_optional', - 'configLocation', - 'auto_apply', - 'build_to', - 'defaultEnumTest', - 'builder_factories', - 'applies_builders', - 'required_inputs', - 'build_extensions' - ], - disallowNullValues: const ['configLocation', 'auto_apply'], - ); - final val = Builder( - import: $checkedConvert('import', (v) => v as String?), - target: $checkedConvert('target', (v) => v as String?), - isOptional: $checkedConvert('is_optional', (v) => v as bool?), - autoApply: $checkedConvert( - 'auto_apply', (v) => $enumDecodeNullable(_$AutoApplyEnumMap, v)), - buildTo: $checkedConvert( - 'build_to', (v) => $enumDecodeNullable(_$BuildToEnumMap, v)), - defaultEnumTest: $checkedConvert('defaultEnumTest', - (v) => $enumDecodeNullable(_$AutoApplyEnumMap, v)), - builderFactories: $checkedConvert('builder_factories', - (v) => (v as List<dynamic>).map((e) => e as String).toList()), - appliesBuilders: $checkedConvert('applies_builders', - (v) => (v as List<dynamic>?)?.map((e) => e as String).toList()), - requiredInputs: $checkedConvert('required_inputs', - (v) => (v as List<dynamic>?)?.map((e) => e as String).toList()), - buildExtensions: $checkedConvert( - 'build_extensions', - (v) => (v as Map?)?.map( - (k, e) => MapEntry(k as String, - (e as List<dynamic>).map((e) => e as String).toList()), - )), - configLocation: $checkedConvert('configLocation', - (v) => v == null ? null : Uri.parse(v as String)), - ); - return val; - }, - fieldKeyMap: const { - 'isOptional': 'is_optional', - 'autoApply': 'auto_apply', - 'buildTo': 'build_to', - 'builderFactories': 'builder_factories', - 'appliesBuilders': 'applies_builders', - 'requiredInputs': 'required_inputs', - 'buildExtensions': 'build_extensions' - }, + allowedKeys: const [ + 'target', + 'import', + 'is_optional', + 'configLocation', + 'auto_apply', + 'build_to', + 'defaultEnumTest', + 'builder_factories', + 'applies_builders', + 'required_inputs', + 'build_extensions', + ], + disallowNullValues: const ['configLocation', 'auto_apply'], ); + final val = Builder( + import: $checkedConvert('import', (v) => v as String?), + target: $checkedConvert('target', (v) => v as String?), + isOptional: $checkedConvert('is_optional', (v) => v as bool?), + autoApply: $checkedConvert( + 'auto_apply', + (v) => $enumDecodeNullable(_$AutoApplyEnumMap, v), + ), + buildTo: $checkedConvert( + 'build_to', + (v) => $enumDecodeNullable(_$BuildToEnumMap, v), + ), + defaultEnumTest: $checkedConvert( + 'defaultEnumTest', + (v) => $enumDecodeNullable(_$AutoApplyEnumMap, v), + ), + builderFactories: $checkedConvert( + 'builder_factories', + (v) => (v as List<dynamic>).map((e) => e as String).toList(), + ), + appliesBuilders: $checkedConvert( + 'applies_builders', + (v) => (v as List<dynamic>?)?.map((e) => e as String).toList(), + ), + requiredInputs: $checkedConvert( + 'required_inputs', + (v) => (v as List<dynamic>?)?.map((e) => e as String).toList(), + ), + buildExtensions: $checkedConvert( + 'build_extensions', + (v) => (v as Map?)?.map( + (k, e) => MapEntry( + k as String, + (e as List<dynamic>).map((e) => e as String).toList(), + ), + ), + ), + configLocation: $checkedConvert( + 'configLocation', + (v) => v == null ? null : Uri.parse(v as String), + ), + ); + return val; + }, + fieldKeyMap: const { + 'isOptional': 'is_optional', + 'autoApply': 'auto_apply', + 'buildTo': 'build_to', + 'builderFactories': 'builder_factories', + 'appliesBuilders': 'applies_builders', + 'requiredInputs': 'required_inputs', + 'buildExtensions': 'build_extensions', + }, +); Map<String, dynamic> _$BuilderToJson(Builder instance) => <String, dynamic>{ - if (instance.target case final value?) 'target': value, - if (instance.import case final value?) 'import': value, - if (instance.isOptional case final value?) 'is_optional': value, - if (instance.configLocation?.toString() case final value?) - 'configLocation': value, - if (_$AutoApplyEnumMap[instance.autoApply] case final value?) - 'auto_apply': value, - if (_$BuildToEnumMap[instance.buildTo] case final value?) - 'build_to': value, - if (_$AutoApplyEnumMap[instance.defaultEnumTest] case final value?) - 'defaultEnumTest': value, - 'builder_factories': instance.builderFactories, - if (instance.appliesBuilders case final value?) 'applies_builders': value, - if (instance.requiredInputs case final value?) 'required_inputs': value, - if (instance.buildExtensions case final value?) 'build_extensions': value, - }; - -const _$BuildToEnumMap = { - BuildTo.cache: 'cache', - BuildTo.source: 'source', + if (instance.target case final value?) 'target': value, + if (instance.import case final value?) 'import': value, + if (instance.isOptional case final value?) 'is_optional': value, + if (instance.configLocation?.toString() case final value?) + 'configLocation': value, + if (_$AutoApplyEnumMap[instance.autoApply] case final value?) + 'auto_apply': value, + if (_$BuildToEnumMap[instance.buildTo] case final value?) 'build_to': value, + if (_$AutoApplyEnumMap[instance.defaultEnumTest] case final value?) + 'defaultEnumTest': value, + 'builder_factories': instance.builderFactories, + if (instance.appliesBuilders case final value?) 'applies_builders': value, + if (instance.requiredInputs case final value?) 'required_inputs': value, + if (instance.buildExtensions case final value?) 'build_extensions': value, }; + +const _$BuildToEnumMap = {BuildTo.cache: 'cache', BuildTo.source: 'source'}; diff --git a/_test_yaml/test/yaml_test.dart b/_test_yaml/test/yaml_test.dart index 29856bf8c..06a49a665 100644 --- a/_test_yaml/test/yaml_test.dart +++ b/_test_yaml/test/yaml_test.dart @@ -27,10 +27,8 @@ void main() { for (final filePath in _tests) { test(p.basenameWithoutExtension(filePath), () { final content = File(filePath).readAsStringSync(); - final yamlContent = loadYaml( - content, - sourceUrl: Uri.file(filePath), - ) as YamlMap; + final yamlContent = + loadYaml(content, sourceUrl: Uri.file(filePath)) as YamlMap; try { final config = Config.fromJson(yamlContent); @@ -157,5 +155,5 @@ line 4, column 21 of file.yaml: Unsupported value for "configLocation". Illegal ╷ 4 │ configLocation: "user@host:invalid/uri" │ ^^^^^^^^^^^^^^^^^^^^^^^ - ╵''' + ╵''', }; diff --git a/analysis_options.yaml b/analysis_options.yaml index 629e6274d..f87c95a72 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -27,6 +27,6 @@ linter: - prefer_final_locals - sort_child_properties_last - unnecessary_breaks + - unnecessary_ignore - use_full_hex_values_for_flutter_colors - use_string_buffers - - unnecessary_ignore diff --git a/checked_yaml/CHANGELOG.md b/checked_yaml/CHANGELOG.md index 6099e85b3..a3b7dac72 100644 --- a/checked_yaml/CHANGELOG.md +++ b/checked_yaml/CHANGELOG.md @@ -1,6 +1,6 @@ ## 2.0.4-wip -- Require Dart 3.6 +- Require Dart 3.8 ## 2.0.3 diff --git a/checked_yaml/README.md b/checked_yaml/README.md index 1a56f1e23..d5f83e9d6 100644 --- a/checked_yaml/README.md +++ b/checked_yaml/README.md @@ -1,7 +1,7 @@ [![Pub Package](https://img.shields.io/pub/v/checked_yaml.svg)](https://pub.dev/packages/checked_yaml) `package:checked_yaml` provides a `checkedYamlDecode` function that wraps the -the creation of classes annotated for [`package:json_serializable`] it helps +creation of classes annotated for [`package:json_serializable`] it helps provide more helpful exceptions when the provided YAML is not compatible with the target type. @@ -10,11 +10,7 @@ the target type. for the class annotation. ```dart -@JsonSerializable( - anyMap: true, - checked: true, - disallowUnrecognizedKeys: true, -) +@JsonSerializable(anyMap: true, checked: true, disallowUnrecognizedKeys: true) class Configuration { @JsonKey(required: true) final String name; diff --git a/checked_yaml/example/example.dart b/checked_yaml/example/example.dart index f89308843..416ca3a8b 100644 --- a/checked_yaml/example/example.dart +++ b/checked_yaml/example/example.dart @@ -9,11 +9,7 @@ import 'package:json_annotation/json_annotation.dart'; part 'example.g.dart'; -@JsonSerializable( - anyMap: true, - checked: true, - disallowUnrecognizedKeys: true, -) +@JsonSerializable(anyMap: true, checked: true, disallowUnrecognizedKeys: true) class Configuration { @JsonKey(required: true) final String name; diff --git a/checked_yaml/example/example.g.dart b/checked_yaml/example/example.g.dart index 96f10dae8..b5547e94f 100644 --- a/checked_yaml/example/example.g.dart +++ b/checked_yaml/example/example.g.dart @@ -6,25 +6,19 @@ part of 'example.dart'; // JsonSerializableGenerator // ************************************************************************** -Configuration _$ConfigurationFromJson(Map json) => $checkedCreate( - 'Configuration', - json, - ($checkedConvert) { - $checkKeys( - json, - allowedKeys: const ['name', 'count'], - requiredKeys: const ['name'], - ); - final val = Configuration( - name: $checkedConvert('name', (v) => v as String), - count: $checkedConvert('count', (v) => (v as num).toInt()), - ); - return val; - }, - ); +Configuration _$ConfigurationFromJson(Map json) => + $checkedCreate('Configuration', json, ($checkedConvert) { + $checkKeys( + json, + allowedKeys: const ['name', 'count'], + requiredKeys: const ['name'], + ); + final val = Configuration( + name: $checkedConvert('name', (v) => v as String), + count: $checkedConvert('count', (v) => (v as num).toInt()), + ); + return val; + }); Map<String, dynamic> _$ConfigurationToJson(Configuration instance) => - <String, dynamic>{ - 'name': instance.name, - 'count': instance.count, - }; + <String, dynamic>{'name': instance.name, 'count': instance.count}; diff --git a/checked_yaml/lib/checked_yaml.dart b/checked_yaml/lib/checked_yaml.dart index c9a75ee56..17c5ce0c1 100644 --- a/checked_yaml/lib/checked_yaml.dart +++ b/checked_yaml/lib/checked_yaml.dart @@ -66,14 +66,13 @@ ParsedYamlException toParsedYamlException( ? innerError.unrecognizedKeys.first : exception.key; - final node = yamlMap.nodes.keys.singleWhere( - (k) => (k as YamlScalar).value == key, - orElse: () => yamlMap) as YamlNode; - return ParsedYamlException( - exception.message!, - node, - innerError: exception, - ); + final node = + yamlMap.nodes.keys.singleWhere( + (k) => (k as YamlScalar).value == key, + orElse: () => yamlMap, + ) + as YamlNode; + return ParsedYamlException(exception.message!, node, innerError: exception); } else { if (exception.key == null) { return ParsedYamlException( @@ -119,13 +118,9 @@ class ParsedYamlException implements Exception { /// contains the source error object. final Object? innerError; - ParsedYamlException( - String message, - YamlNode this.yamlNode, { - this.innerError, - }) : - // TODO(kevmoo) remove when dart-lang/sdk#50756 is fixed! - message = message.replaceAll(" of ' in type cast'", ' in type cast'); + ParsedYamlException(String message, YamlNode this.yamlNode, {this.innerError}) + : // TODO(kevmoo) remove when dart-lang/sdk#50756 is fixed! + message = message.replaceAll(" of ' in type cast'", ' in type cast'); factory ParsedYamlException.fromYamlException(YamlException exception) => _WrappedYamlException(exception); diff --git a/checked_yaml/pubspec.yaml b/checked_yaml/pubspec.yaml index 7e7fbc9d4..ada787451 100644 --- a/checked_yaml/pubspec.yaml +++ b/checked_yaml/pubspec.yaml @@ -13,7 +13,7 @@ topics: - codegen environment: - sdk: ^3.6.0 + sdk: ^3.8.0 resolution: workspace diff --git a/checked_yaml/test/custom_error_test.dart b/checked_yaml/test/custom_error_test.dart index 6ce0e42e1..6c17bda9d 100644 --- a/checked_yaml/test/custom_error_test.dart +++ b/checked_yaml/test/custom_error_test.dart @@ -6,17 +6,14 @@ import 'package:yaml/yaml.dart'; void main() { test('bob', () { expect( - () => checkedYamlDecode( - '{"innerMap": {}}', - (m) { - throw CheckedFromJsonException( - m!['innerMap'] as YamlMap, - null, - 'nothing', - null, - ); - }, - ), + () => checkedYamlDecode('{"innerMap": {}}', (m) { + throw CheckedFromJsonException( + m!['innerMap'] as YamlMap, + null, + 'nothing', + null, + ); + }), throwsA( isA<ParsedYamlException>() .having( diff --git a/checked_yaml/test/example_test.dart b/checked_yaml/test/example_test.dart index 7761c36f5..fe56b19ad 100644 --- a/checked_yaml/test/example_test.dart +++ b/checked_yaml/test/example_test.dart @@ -18,114 +18,90 @@ Configuration: {name: bob, count: 42} }); test('empty map', () { - _expectThrows( - '{}', - r''' + _expectThrows('{}', r''' line 1, column 1: Required keys are missing: name. ╷ 1 │ {} │ ^^ - ╵''', - ); + ╵'''); }); test('missing count', () { - _expectThrows( - '{"name":"something"}', - r''' + _expectThrows('{"name":"something"}', r''' line 1, column 1: Missing key "count". type 'Null' is not a subtype of type 'num' in type cast ╷ 1 │ {"name":"something"} │ ^^^^^^^^^^^^^^^^^^^^ - ╵''', - ); + ╵'''); }); test('not a map', () { - _expectThrows( - '42', - r''' + _expectThrows('42', r''' line 1, column 1: Not a map ╷ 1 │ 42 │ ^^ - ╵''', - ); + ╵'''); }); test('invalid yaml', () { - _expectThrows( - '{', - r''' + _expectThrows('{', r''' line 1, column 2: Expected node content. ╷ 1 │ { │ ^ - ╵''', - ); + ╵'''); }); test('duplicate keys', () { - _expectThrows( - '{"a":null, "a":null}', - r''' + _expectThrows('{"a":null, "a":null}', r''' line 1, column 12: Duplicate mapping key. ╷ 1 │ {"a":null, "a":null} │ ^^^ - ╵''', - ); + ╵'''); }); test('unexpected key', () { - _expectThrows( - '{"bob": 42}', - r''' + _expectThrows('{"bob": 42}', r''' line 1, column 2: Unrecognized keys: [bob]; supported keys: [name, count] ╷ 1 │ {"bob": 42} │ ^^^^^ - ╵''', - ); + ╵'''); }); test('bad name type', () { - _expectThrows( - '{"name": 42, "count": 42}', - r''' + _expectThrows('{"name": 42, "count": 42}', r''' line 1, column 10: Unsupported value for "name". type 'int' is not a subtype of type 'String' in type cast ╷ 1 │ {"name": 42, "count": 42} │ ^^ - ╵''', - ); + ╵'''); }); test('bad name contents', () { - _expectThrows( - '{"name": "", "count": 42}', - r''' + _expectThrows('{"name": "", "count": 42}', r''' line 1, column 10: Unsupported value for "name". Cannot be empty. ╷ 1 │ {"name": "", "count": 42} │ ^^ - ╵''', - ); + ╵'''); }); } void _expectThrows(String yamlContent, String matcher) => expect( - () => _run(yamlContent), - throwsA( - isA<ParsedYamlException>().having( - (e) { - printOnFailure("r'''\n${e.formattedMessage}'''"); - return e.formattedMessage; - }, - 'formattedMessage', - matcher, - ), - ), - ); + () => _run(yamlContent), + throwsA( + isA<ParsedYamlException>().having( + (e) { + printOnFailure("r'''\n${e.formattedMessage}'''"); + return e.formattedMessage; + }, + 'formattedMessage', + matcher, + ), + ), +); void _run(String yamlContent) => example.main([yamlContent]); diff --git a/checked_yaml/test/readme_test.dart b/checked_yaml/test/readme_test.dart index 21f530d06..813ed6f43 100644 --- a/checked_yaml/test/readme_test.dart +++ b/checked_yaml/test/readme_test.dart @@ -23,14 +23,18 @@ void _member(String startToken) { final classEnd = _exampleContent.indexOf(_memberEnd, start); expect(classEnd, greaterThan(start)); - final content = - _exampleContent.substring(start, classEnd + _memberEnd.length).trim(); + final content = _exampleContent + .substring(start, classEnd + _memberEnd.length) + .trim(); - expect(_readmeContent, contains(''' + expect( + _readmeContent, + contains(''' ```dart $content ``` -''')); +'''), + ); } void main() { @@ -52,16 +56,19 @@ ParsedYamlException: line 1, column 10: Unsupported value for "name". Cannot be │ ^^ ╵'''; - expect(_readmeContent, contains(''' + expect( + _readmeContent, + contains(''' ```console \$ dart example/example.dart '$inputContent' $errorContent -```''')); - - final proc = await TestProcess.start( - Platform.resolvedExecutable, - [_examplePath, inputContent], +```'''), ); + + final proc = await TestProcess.start(Platform.resolvedExecutable, [ + _examplePath, + inputContent, + ]); await expectLater( proc.stderr, emitsInOrder(LineSplitter.split(errorContent)), diff --git a/example/lib/example.dart b/example/lib/example.dart index c928b5508..8fc8f5bc5 100644 --- a/example/lib/example.dart +++ b/example/lib/example.dart @@ -43,9 +43,10 @@ class Order { Item? item; @JsonKey( - name: 'prep-time', - fromJson: _durationFromMilliseconds, - toJson: _durationToMilliseconds) + name: 'prep-time', + fromJson: _durationFromMilliseconds, + toJson: _durationToMilliseconds, + ) Duration? prepTime; @JsonKey(fromJson: _dateTimeFromEpochUs, toJson: _dateTimeToEpochUs) diff --git a/example/lib/example.g.dart b/example/lib/example.g.dart index f497bc0e7..c35c960af 100644 --- a/example/lib/example.g.dart +++ b/example/lib/example.g.dart @@ -7,49 +7,48 @@ part of 'example.dart'; // ************************************************************************** Person _$PersonFromJson(Map<String, dynamic> json) => Person( - json['firstName'] as String, - json['lastName'] as String, - DateTime.parse(json['date-of-birth'] as String), - middleName: json['middleName'] as String?, - lastOrder: json['last-order'] == null - ? null - : DateTime.parse(json['last-order'] as String), - orders: (json['orders'] as List<dynamic>?) - ?.map((e) => Order.fromJson(e as Map<String, dynamic>)) - .toList(), - ); + json['firstName'] as String, + json['lastName'] as String, + DateTime.parse(json['date-of-birth'] as String), + middleName: json['middleName'] as String?, + lastOrder: json['last-order'] == null + ? null + : DateTime.parse(json['last-order'] as String), + orders: (json['orders'] as List<dynamic>?) + ?.map((e) => Order.fromJson(e as Map<String, dynamic>)) + .toList(), +); Map<String, dynamic> _$PersonToJson(Person instance) => <String, dynamic>{ - 'firstName': instance.firstName, - if (instance.middleName case final value?) 'middleName': value, - 'lastName': instance.lastName, - 'date-of-birth': instance.dateOfBirth.toIso8601String(), - 'last-order': instance.lastOrder?.toIso8601String(), - 'orders': instance.orders, - }; + 'firstName': instance.firstName, + if (instance.middleName case final value?) 'middleName': value, + 'lastName': instance.lastName, + 'date-of-birth': instance.dateOfBirth.toIso8601String(), + 'last-order': instance.lastOrder?.toIso8601String(), + 'orders': instance.orders, +}; -Order _$OrderFromJson(Map<String, dynamic> json) => Order( - Order._dateTimeFromEpochUs((json['date'] as num).toInt()), - ) +Order _$OrderFromJson(Map<String, dynamic> json) => + Order(Order._dateTimeFromEpochUs((json['date'] as num).toInt())) ..count = (json['count'] as num?)?.toInt() ..itemNumber = (json['itemNumber'] as num?)?.toInt() ..isRushed = json['isRushed'] as bool? ..item = json['item'] == null ? null : Item.fromJson(json['item'] as Map<String, dynamic>) - ..prepTime = - Order._durationFromMilliseconds((json['prep-time'] as num?)?.toInt()); + ..prepTime = Order._durationFromMilliseconds( + (json['prep-time'] as num?)?.toInt(), + ); Map<String, dynamic> _$OrderToJson(Order instance) => <String, dynamic>{ - if (instance.count case final value?) 'count': value, - if (instance.itemNumber case final value?) 'itemNumber': value, - if (instance.isRushed case final value?) 'isRushed': value, - if (instance.item case final value?) 'item': value, - if (Order._durationToMilliseconds(instance.prepTime) case final value?) - 'prep-time': value, - if (Order._dateTimeToEpochUs(instance.date) case final value?) - 'date': value, - }; + if (instance.count case final value?) 'count': value, + if (instance.itemNumber case final value?) 'itemNumber': value, + if (instance.isRushed case final value?) 'isRushed': value, + if (instance.item case final value?) 'item': value, + if (Order._durationToMilliseconds(instance.prepTime) case final value?) + 'prep-time': value, + if (Order._dateTimeToEpochUs(instance.date) case final value?) 'date': value, +}; Item _$ItemFromJson(Map<String, dynamic> json) => Item() ..count = (json['count'] as num?)?.toInt() @@ -57,10 +56,10 @@ Item _$ItemFromJson(Map<String, dynamic> json) => Item() ..isRushed = json['isRushed'] as bool?; Map<String, dynamic> _$ItemToJson(Item instance) => <String, dynamic>{ - 'count': instance.count, - 'itemNumber': instance.itemNumber, - 'isRushed': instance.isRushed, - }; + 'count': instance.count, + 'itemNumber': instance.itemNumber, + 'isRushed': instance.isRushed, +}; // ************************************************************************** // JsonLiteralGenerator @@ -80,11 +79,11 @@ final _$glossaryDataJsonLiteral = { 'Abbrev': 'ISO 8879:1986', 'GlossDef': { 'para': 'A meta-markup language, used to create markup languages.', - 'GlossSeeAlso': ['GML', 'XML'] + 'GlossSeeAlso': ['GML', 'XML'], }, - 'GlossSee': 'markup' - } - } - } - } + 'GlossSee': 'markup', + }, + }, + }, + }, }; diff --git a/example/lib/generic_response_class_example.dart b/example/lib/generic_response_class_example.dart index 5565aed8d..928957695 100644 --- a/example/lib/generic_response_class_example.dart +++ b/example/lib/generic_response_class_example.dart @@ -18,11 +18,7 @@ class BaseResponse<T> { @JsonKey(fromJson: _dataFromJson) final T? data; - const BaseResponse({ - this.status, - this.msg, - this.data, - }); + const BaseResponse({this.status, this.msg, this.data}); factory BaseResponse.fromJson(Map<String, dynamic> json) => _$BaseResponseFromJson(json); @@ -43,8 +39,9 @@ class BaseResponse<T> { // necessary to "peek" into non-empty lists to determine the type! return json - .map((e) => Article.fromJson(e as Map<String, dynamic>)) - .toList() as T; + .map((e) => Article.fromJson(e as Map<String, dynamic>)) + .toList() + as T; } throw ArgumentError.value( @@ -80,10 +77,7 @@ class User { final int? id; final String? email; - const User({ - this.id, - this.email, - }); + const User({this.id, this.email}); factory User.fromJson(Map<String, dynamic> json) => _$UserFromJson(json); } @@ -93,10 +87,7 @@ class Comment { final String? content; final int? id; - const Comment({ - this.id, - this.content, - }); + const Comment({this.id, this.content}); factory Comment.fromJson(Map<String, dynamic> json) => _$CommentFromJson(json); diff --git a/example/lib/generic_response_class_example.g.dart b/example/lib/generic_response_class_example.g.dart index e61f09efc..4ee26fa88 100644 --- a/example/lib/generic_response_class_example.g.dart +++ b/example/lib/generic_response_class_example.g.dart @@ -14,22 +14,20 @@ BaseResponse<T> _$BaseResponseFromJson<T>(Map<String, dynamic> json) => ); Article _$ArticleFromJson(Map<String, dynamic> json) => Article( - id: (json['id'] as num).toInt(), - title: json['title'] as String, - author: json['author'] == null - ? null - : User.fromJson(json['author'] as Map<String, dynamic>), - comments: (json['comments'] as List<dynamic>?) - ?.map((e) => Comment.fromJson(e as Map<String, dynamic>)) - .toList(), - ); + id: (json['id'] as num).toInt(), + title: json['title'] as String, + author: json['author'] == null + ? null + : User.fromJson(json['author'] as Map<String, dynamic>), + comments: (json['comments'] as List<dynamic>?) + ?.map((e) => Comment.fromJson(e as Map<String, dynamic>)) + .toList(), +); -User _$UserFromJson(Map<String, dynamic> json) => User( - id: (json['id'] as num?)?.toInt(), - email: json['email'] as String?, - ); +User _$UserFromJson(Map<String, dynamic> json) => + User(id: (json['id'] as num?)?.toInt(), email: json['email'] as String?); Comment _$CommentFromJson(Map<String, dynamic> json) => Comment( - id: (json['id'] as num?)?.toInt(), - content: json['content'] as String?, - ); + id: (json['id'] as num?)?.toInt(), + content: json['content'] as String?, +); diff --git a/example/lib/json_converter_example.g.dart b/example/lib/json_converter_example.g.dart index 01b2e46f5..ccea4f967 100644 --- a/example/lib/json_converter_example.g.dart +++ b/example/lib/json_converter_example.g.dart @@ -17,32 +17,27 @@ Map<String, dynamic> _$DateTimeExampleToJson(DateTimeExample instance) => }; GenericCollection<T> _$GenericCollectionFromJson<T>( - Map<String, dynamic> json) => - GenericCollection<T>( - page: (json['page'] as num?)?.toInt(), - totalResults: (json['total_results'] as num?)?.toInt(), - totalPages: (json['total_pages'] as num?)?.toInt(), - results: (json['results'] as List<dynamic>?) - ?.map(_Converter<T>().fromJson) - .toList(), - ); + Map<String, dynamic> json, +) => GenericCollection<T>( + page: (json['page'] as num?)?.toInt(), + totalResults: (json['total_results'] as num?)?.toInt(), + totalPages: (json['total_pages'] as num?)?.toInt(), + results: (json['results'] as List<dynamic>?) + ?.map(_Converter<T>().fromJson) + .toList(), +); Map<String, dynamic> _$GenericCollectionToJson<T>( - GenericCollection<T> instance) => - <String, dynamic>{ - 'page': instance.page, - 'total_results': instance.totalResults, - 'total_pages': instance.totalPages, - 'results': instance.results?.map(_Converter<T>().toJson).toList(), - }; + GenericCollection<T> instance, +) => <String, dynamic>{ + 'page': instance.page, + 'total_results': instance.totalResults, + 'total_pages': instance.totalPages, + 'results': instance.results?.map(_Converter<T>().toJson).toList(), +}; -CustomResult _$CustomResultFromJson(Map<String, dynamic> json) => CustomResult( - json['name'] as String, - (json['size'] as num).toInt(), - ); +CustomResult _$CustomResultFromJson(Map<String, dynamic> json) => + CustomResult(json['name'] as String, (json['size'] as num).toInt()); Map<String, dynamic> _$CustomResultToJson(CustomResult instance) => - <String, dynamic>{ - 'name': instance.name, - 'size': instance.size, - }; + <String, dynamic>{'name': instance.name, 'size': instance.size}; diff --git a/example/lib/nested_values_example.dart b/example/lib/nested_values_example.dart index 3bd1e47f6..79c54d0ee 100644 --- a/example/lib/nested_values_example.dart +++ b/example/lib/nested_values_example.dart @@ -24,14 +24,14 @@ class _NestedListConverter @override List<String> fromJson(Map<String, dynamic> json) => [ - for (var e in json['items'] as List) - (e as Map<String, dynamic>)['name'] as String - ]; + for (var e in json['items'] as List) + (e as Map<String, dynamic>)['name'] as String, + ]; @override Map<String, dynamic> toJson(List<String> object) => { - 'items': [ - for (var item in object) {'name': item} - ] - }; + 'items': [ + for (var item in object) {'name': item}, + ], + }; } diff --git a/example/lib/nested_values_example.g.dart b/example/lib/nested_values_example.g.dart index 39dc2b8c2..ee41d257d 100644 --- a/example/lib/nested_values_example.g.dart +++ b/example/lib/nested_values_example.g.dart @@ -8,8 +8,9 @@ part of 'nested_values_example.dart'; NestedValueExample _$NestedValueExampleFromJson(Map<String, dynamic> json) => NestedValueExample( - const _NestedListConverter() - .fromJson(json['root_items'] as Map<String, dynamic>), + const _NestedListConverter().fromJson( + json['root_items'] as Map<String, dynamic>, + ), ); Map<String, dynamic> _$NestedValueExampleToJson(NestedValueExample instance) => diff --git a/example/lib/tuple_example.dart b/example/lib/tuple_example.dart index 35bcbe6a7..806a49ae8 100644 --- a/example/lib/tuple_example.dart +++ b/example/lib/tuple_example.dart @@ -18,14 +18,12 @@ class Tuple<T, S> { Map<String, dynamic> json, T Function(Object? json) fromJsonT, S Function(Object? json) fromJsonS, - ) => - _$TupleFromJson(json, fromJsonT, fromJsonS); + ) => _$TupleFromJson(json, fromJsonT, fromJsonS); Map<String, dynamic> toJson( Object Function(T value) toJsonT, Object Function(S value) toJsonS, - ) => - _$TupleToJson(this, toJsonT, toJsonS); + ) => _$TupleToJson(this, toJsonT, toJsonS); } @JsonSerializable() diff --git a/example/lib/tuple_example.g.dart b/example/lib/tuple_example.g.dart index f4a537901..71aff0c6f 100644 --- a/example/lib/tuple_example.g.dart +++ b/example/lib/tuple_example.g.dart @@ -10,32 +10,29 @@ Tuple<T, S> _$TupleFromJson<T, S>( Map<String, dynamic> json, T Function(Object? json) fromJsonT, S Function(Object? json) fromJsonS, -) => - Tuple<T, S>( - fromJsonT(json['value1']), - fromJsonS(json['value2']), - ); +) => Tuple<T, S>(fromJsonT(json['value1']), fromJsonS(json['value2'])); Map<String, dynamic> _$TupleToJson<T, S>( Tuple<T, S> instance, Object? Function(T value) toJsonT, Object? Function(S value) toJsonS, -) => - <String, dynamic>{ - 'value1': toJsonT(instance.value1), - 'value2': toJsonS(instance.value2), - }; +) => <String, dynamic>{ + 'value1': toJsonT(instance.value1), + 'value2': toJsonS(instance.value2), +}; ConcreteClass _$ConcreteClassFromJson(Map<String, dynamic> json) => ConcreteClass( Tuple<int, DateTime>.fromJson( - json['tuple1'] as Map<String, dynamic>, - (value) => (value as num).toInt(), - (value) => DateTime.parse(value as String)), + json['tuple1'] as Map<String, dynamic>, + (value) => (value as num).toInt(), + (value) => DateTime.parse(value as String), + ), Tuple<Duration, BigInt>.fromJson( - json['tuple2'] as Map<String, dynamic>, - (value) => Duration(microseconds: (value as num).toInt()), - (value) => BigInt.parse(value as String)), + json['tuple2'] as Map<String, dynamic>, + (value) => Duration(microseconds: (value as num).toInt()), + (value) => BigInt.parse(value as String), + ), ); Map<String, dynamic> _$ConcreteClassToJson(ConcreteClass instance) => diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 3926249e9..392a1cd2f 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -2,7 +2,7 @@ name: example publish_to: none environment: - sdk: ^3.6.0 + sdk: ^3.8.0 resolution: workspace diff --git a/example/test/example_test.dart b/example/test/example_test.dart index 99dc2ed53..6a33c796c 100644 --- a/example/test/example_test.dart +++ b/example/test/example_test.dart @@ -19,8 +19,9 @@ void main() { final personJson = loudEncode(person); - final person2 = - Person.fromJson(json.decode(personJson) as Map<String, dynamic>); + final person2 = Person.fromJson( + json.decode(personJson) as Map<String, dynamic>, + ); expect(person.firstName, person2.firstName); expect(person.lastName, person2.lastName); diff --git a/example/test/generic_response_class_test.dart b/example/test/generic_response_class_test.dart index 8faaf39ec..d922938a2 100644 --- a/example/test/generic_response_class_test.dart +++ b/example/test/generic_response_class_test.dart @@ -8,7 +8,7 @@ import 'package:test/test.dart'; const _jsonUser = { 'status': 200, 'msg': 'success', - 'data': {'id': 1, 'email': 'test@test.com'} + 'data': {'id': 1, 'email': 'test@test.com'}, }; final _jsonArticle = { @@ -21,8 +21,8 @@ final _jsonArticle = { 'comments': [ {'content': 'comment context', 'id': 1}, {'content': 'comment context', 'id': 2}, - ] - } + ], + }, }; final _jsonArticleList = { @@ -31,7 +31,7 @@ final _jsonArticleList = { 'data': [ {'id': 1, 'title': 'title1'}, _jsonArticle['data'], - ] + ], }; void _testResponse<T>(BaseResponse response, void Function(T) testFunction) { diff --git a/example/test/json_convert_example_test.dart b/example/test/json_convert_example_test.dart index 5751b72de..bd8a152d8 100644 --- a/example/test/json_convert_example_test.dart +++ b/example/test/json_convert_example_test.dart @@ -19,18 +19,24 @@ void main() { "when": $value }'''); - final copy = - DateTimeExample.fromJson(jsonDecode(json) as Map<String, dynamic>); + final copy = DateTimeExample.fromJson( + jsonDecode(json) as Map<String, dynamic>, + ); expect(copy.when, epochDateTime); }); test('trivial case', () { final collection = GenericCollection<int>( - page: 0, totalPages: 3, totalResults: 10, results: [1, 2, 3]); + page: 0, + totalPages: 3, + totalResults: 10, + results: [1, 2, 3], + ); final encoded = loudEncode(collection); final collection2 = GenericCollection<int>.fromJson( - jsonDecode(encoded) as Map<String, dynamic>); + jsonDecode(encoded) as Map<String, dynamic>, + ); expect(collection2.results, [1, 2, 3]); @@ -39,14 +45,16 @@ void main() { test('custom result', () { final collection = GenericCollection<CustomResult>( - page: 0, - totalPages: 3, - totalResults: 10, - results: [CustomResult('bob', 42)]); + page: 0, + totalPages: 3, + totalResults: 10, + results: [CustomResult('bob', 42)], + ); final encoded = loudEncode(collection); final collection2 = GenericCollection<CustomResult>.fromJson( - jsonDecode(encoded) as Map<String, dynamic>); + jsonDecode(encoded) as Map<String, dynamic>, + ); expect(collection2.results, [CustomResult('bob', 42)]); @@ -54,37 +62,45 @@ void main() { }); test('mixed values in generic collection', () { - final collection = - GenericCollection(page: 0, totalPages: 3, totalResults: 10, results: [ - 1, - 3.14, - null, - 'bob', - ['list'], - {'map': 'map'}, - CustomResult('bob', 42) - ]); + final collection = GenericCollection( + page: 0, + totalPages: 3, + totalResults: 10, + results: [ + 1, + 3.14, + null, + 'bob', + ['list'], + {'map': 'map'}, + CustomResult('bob', 42), + ], + ); final encoded = loudEncode(collection); expect( () => GenericCollection<CustomResult>.fromJson( - jsonDecode(encoded) as Map<String, dynamic>), + jsonDecode(encoded) as Map<String, dynamic>, + ), throwsTypeError, ); expect( () => GenericCollection<int>.fromJson( - jsonDecode(encoded) as Map<String, dynamic>), + jsonDecode(encoded) as Map<String, dynamic>, + ), throwsTypeError, ); expect( () => GenericCollection<String>.fromJson( - jsonDecode(encoded) as Map<String, dynamic>), + jsonDecode(encoded) as Map<String, dynamic>, + ), throwsTypeError, ); final collection2 = GenericCollection<dynamic>.fromJson( - jsonDecode(encoded) as Map<String, dynamic>); + jsonDecode(encoded) as Map<String, dynamic>, + ); expect(collection2.results, [ 1, @@ -93,7 +109,7 @@ void main() { 'bob', ['list'], {'map': 'map'}, - CustomResult('bob', 42) + CustomResult('bob', 42), ]); expect(loudEncode(collection2), encoded); diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index 810c9d3d1..ae0b4d43d 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -1,6 +1,6 @@ ## 4.9.1-wip -- Require Dart 3.6 +- Require Dart 3.8 ## 4.9.0 diff --git a/json_annotation/lib/src/allowed_keys_helpers.dart b/json_annotation/lib/src/allowed_keys_helpers.dart index 48c3689b7..5ea896a79 100644 --- a/json_annotation/lib/src/allowed_keys_helpers.dart +++ b/json_annotation/lib/src/allowed_keys_helpers.dart @@ -14,16 +14,19 @@ void $checkKeys( List<String>? disallowNullValues, }) { if (allowedKeys != null) { - final invalidKeys = - map.keys.cast<String>().where((k) => !allowedKeys.contains(k)).toList(); + final invalidKeys = map.keys + .cast<String>() + .where((k) => !allowedKeys.contains(k)) + .toList(); if (invalidKeys.isNotEmpty) { throw UnrecognizedKeysException(invalidKeys, map, allowedKeys); } } if (requiredKeys != null) { - final missingKeys = - requiredKeys.where((k) => !map.keys.contains(k)).toList(); + final missingKeys = requiredKeys + .where((k) => !map.keys.contains(k)) + .toList(); if (missingKeys.isNotEmpty) { throw MissingRequiredKeysException(missingKeys, map); } @@ -73,7 +76,7 @@ class UnrecognizedKeysException extends BadKeyException { '[${allowedKeys.join(', ')}]'; UnrecognizedKeysException(this.unrecognizedKeys, Map map, this.allowedKeys) - : super._(map); + : super._(map); } /// Exception thrown if there are missing required keys in a JSON map that was @@ -86,8 +89,8 @@ class MissingRequiredKeysException extends BadKeyException { String get message => 'Required keys are missing: ${missingKeys.join(', ')}.'; MissingRequiredKeysException(this.missingKeys, Map map) - : assert(missingKeys.isNotEmpty), - super._(map); + : assert(missingKeys.isNotEmpty), + super._(map); } /// Exception thrown if there are keys with disallowed `null` values in a JSON @@ -98,6 +101,7 @@ class DisallowedNullValueException extends BadKeyException { DisallowedNullValueException(this.keysWithNullValues, Map map) : super._(map); @override - String get message => 'These keys had `null` values, ' + String get message => + 'These keys had `null` values, ' 'which is not allowed: $keysWithNullValues'; } diff --git a/json_annotation/lib/src/checked_helpers.dart b/json_annotation/lib/src/checked_helpers.dart index 04c54d871..15d0e7b67 100644 --- a/json_annotation/lib/src/checked_helpers.dart +++ b/json_annotation/lib/src/checked_helpers.dart @@ -17,15 +17,15 @@ T $checkedCreate<T>( S Function(Object?), { Object? Function(Map, String)? readValue, }), - ) constructor, { + ) + constructor, { Map<String, String> fieldKeyMap = const {}, }) { Q checkedConvert<Q>( String key, Q Function(Object?) convertFunction, { Object? Function(Map, String)? readValue, - }) => - $checkedConvert<Q>(map, key, convertFunction, readValue: readValue); + }) => $checkedConvert<Q>(map, key, convertFunction, readValue: readValue); return $checkedNew( className, @@ -135,9 +135,9 @@ class CheckedFromJsonException implements Exception { String className, this.message, { this.badKey = false, - }) : _className = className, - innerError = null, - innerStack = null; + }) : _className = className, + innerError = null, + innerStack = null; CheckedFromJsonException._( Object this.innerError, @@ -145,9 +145,9 @@ class CheckedFromJsonException implements Exception { this.map, this.key, { String? className, - }) : _className = className, - badKey = innerError is BadKeyException, - message = _getMessage(innerError); + }) : _className = className, + badKey = innerError is BadKeyException, + message = _getMessage(innerError); static String _getMessage(Object error) { if (error is ArgumentError) { @@ -171,12 +171,12 @@ class CheckedFromJsonException implements Exception { @override String toString() => <String>[ - 'CheckedFromJsonException', - if (_className != null) 'Could not create `$_className`.', - if (key != null) 'There is a problem with "$key".', - if (message != null) - message! - else if (innerError != null) - innerError.toString(), - ].join('\n'); + 'CheckedFromJsonException', + if (_className != null) 'Could not create `$_className`.', + if (key != null) 'There is a problem with "$key".', + if (message != null) + message! + else if (innerError != null) + innerError.toString(), + ].join('\n'); } diff --git a/json_annotation/lib/src/json_serializable.dart b/json_annotation/lib/src/json_serializable.dart index 64d1990e0..7c82e2f2e 100644 --- a/json_annotation/lib/src/json_serializable.dart +++ b/json_annotation/lib/src/json_serializable.dart @@ -305,20 +305,20 @@ class JsonSerializable { /// [defaults]. @Deprecated('Was only ever included to support builder infrastructure.') JsonSerializable withDefaults() => JsonSerializable( - anyMap: anyMap ?? defaults.anyMap, - checked: checked ?? defaults.checked, - constructor: constructor ?? defaults.constructor, - createFactory: createFactory ?? defaults.createFactory, - createToJson: createToJson ?? defaults.createToJson, - disallowUnrecognizedKeys: - disallowUnrecognizedKeys ?? defaults.disallowUnrecognizedKeys, - explicitToJson: explicitToJson ?? defaults.explicitToJson, - fieldRename: fieldRename ?? defaults.fieldRename, - ignoreUnannotated: ignoreUnannotated ?? defaults.ignoreUnannotated, - includeIfNull: includeIfNull ?? defaults.includeIfNull, - genericArgumentFactories: - genericArgumentFactories ?? defaults.genericArgumentFactories, - ); + anyMap: anyMap ?? defaults.anyMap, + checked: checked ?? defaults.checked, + constructor: constructor ?? defaults.constructor, + createFactory: createFactory ?? defaults.createFactory, + createToJson: createToJson ?? defaults.createToJson, + disallowUnrecognizedKeys: + disallowUnrecognizedKeys ?? defaults.disallowUnrecognizedKeys, + explicitToJson: explicitToJson ?? defaults.explicitToJson, + fieldRename: fieldRename ?? defaults.fieldRename, + ignoreUnannotated: ignoreUnannotated ?? defaults.ignoreUnannotated, + includeIfNull: includeIfNull ?? defaults.includeIfNull, + genericArgumentFactories: + genericArgumentFactories ?? defaults.genericArgumentFactories, + ); Map<String, dynamic> toJson() => _$JsonSerializableToJson(this); } diff --git a/json_annotation/lib/src/json_serializable.g.dart b/json_annotation/lib/src/json_serializable.g.dart index 80614717e..80a3e4c86 100644 --- a/json_annotation/lib/src/json_serializable.g.dart +++ b/json_annotation/lib/src/json_serializable.g.dart @@ -6,71 +6,79 @@ part of 'json_serializable.dart'; // JsonSerializableGenerator // ************************************************************************** -JsonSerializable _$JsonSerializableFromJson(Map<String, dynamic> json) => - $checkedCreate( - 'JsonSerializable', +JsonSerializable _$JsonSerializableFromJson( + Map<String, dynamic> json, +) => $checkedCreate( + 'JsonSerializable', + json, + ($checkedConvert) { + $checkKeys( json, - ($checkedConvert) { - $checkKeys( - json, - allowedKeys: const [ - 'any_map', - 'checked', - 'constructor', - 'create_factory', - 'create_field_map', - 'create_json_keys', - 'create_per_field_to_json', - 'create_to_json', - 'disallow_unrecognized_keys', - 'explicit_to_json', - 'field_rename', - 'generic_argument_factories', - 'ignore_unannotated', - 'include_if_null' - ], - ); - final val = JsonSerializable( - anyMap: $checkedConvert('any_map', (v) => v as bool?), - checked: $checkedConvert('checked', (v) => v as bool?), - constructor: $checkedConvert('constructor', (v) => v as String?), - createFieldMap: - $checkedConvert('create_field_map', (v) => v as bool?), - createJsonKeys: - $checkedConvert('create_json_keys', (v) => v as bool?), - createFactory: $checkedConvert('create_factory', (v) => v as bool?), - createToJson: $checkedConvert('create_to_json', (v) => v as bool?), - disallowUnrecognizedKeys: - $checkedConvert('disallow_unrecognized_keys', (v) => v as bool?), - explicitToJson: - $checkedConvert('explicit_to_json', (v) => v as bool?), - fieldRename: $checkedConvert('field_rename', - (v) => $enumDecodeNullable(_$FieldRenameEnumMap, v)), - ignoreUnannotated: - $checkedConvert('ignore_unannotated', (v) => v as bool?), - includeIfNull: $checkedConvert('include_if_null', (v) => v as bool?), - genericArgumentFactories: - $checkedConvert('generic_argument_factories', (v) => v as bool?), - createPerFieldToJson: - $checkedConvert('create_per_field_to_json', (v) => v as bool?), - ); - return val; - }, - fieldKeyMap: const { - 'anyMap': 'any_map', - 'createFieldMap': 'create_field_map', - 'createJsonKeys': 'create_json_keys', - 'createFactory': 'create_factory', - 'createToJson': 'create_to_json', - 'disallowUnrecognizedKeys': 'disallow_unrecognized_keys', - 'explicitToJson': 'explicit_to_json', - 'fieldRename': 'field_rename', - 'ignoreUnannotated': 'ignore_unannotated', - 'includeIfNull': 'include_if_null', - 'genericArgumentFactories': 'generic_argument_factories', - 'createPerFieldToJson': 'create_per_field_to_json' - }, + allowedKeys: const [ + 'any_map', + 'checked', + 'constructor', + 'create_factory', + 'create_field_map', + 'create_json_keys', + 'create_per_field_to_json', + 'create_to_json', + 'disallow_unrecognized_keys', + 'explicit_to_json', + 'field_rename', + 'generic_argument_factories', + 'ignore_unannotated', + 'include_if_null', + ], ); + final val = JsonSerializable( + anyMap: $checkedConvert('any_map', (v) => v as bool?), + checked: $checkedConvert('checked', (v) => v as bool?), + constructor: $checkedConvert('constructor', (v) => v as String?), + createFieldMap: $checkedConvert('create_field_map', (v) => v as bool?), + createJsonKeys: $checkedConvert('create_json_keys', (v) => v as bool?), + createFactory: $checkedConvert('create_factory', (v) => v as bool?), + createToJson: $checkedConvert('create_to_json', (v) => v as bool?), + disallowUnrecognizedKeys: $checkedConvert( + 'disallow_unrecognized_keys', + (v) => v as bool?, + ), + explicitToJson: $checkedConvert('explicit_to_json', (v) => v as bool?), + fieldRename: $checkedConvert( + 'field_rename', + (v) => $enumDecodeNullable(_$FieldRenameEnumMap, v), + ), + ignoreUnannotated: $checkedConvert( + 'ignore_unannotated', + (v) => v as bool?, + ), + includeIfNull: $checkedConvert('include_if_null', (v) => v as bool?), + genericArgumentFactories: $checkedConvert( + 'generic_argument_factories', + (v) => v as bool?, + ), + createPerFieldToJson: $checkedConvert( + 'create_per_field_to_json', + (v) => v as bool?, + ), + ); + return val; + }, + fieldKeyMap: const { + 'anyMap': 'any_map', + 'createFieldMap': 'create_field_map', + 'createJsonKeys': 'create_json_keys', + 'createFactory': 'create_factory', + 'createToJson': 'create_to_json', + 'disallowUnrecognizedKeys': 'disallow_unrecognized_keys', + 'explicitToJson': 'explicit_to_json', + 'fieldRename': 'field_rename', + 'ignoreUnannotated': 'ignore_unannotated', + 'includeIfNull': 'include_if_null', + 'genericArgumentFactories': 'generic_argument_factories', + 'createPerFieldToJson': 'create_per_field_to_json', + }, +); Map<String, dynamic> _$JsonSerializableToJson(JsonSerializable instance) => <String, dynamic>{ diff --git a/json_annotation/pubspec.yaml b/json_annotation/pubspec.yaml index 4c3da5f3e..f1cd2c79b 100644 --- a/json_annotation/pubspec.yaml +++ b/json_annotation/pubspec.yaml @@ -11,7 +11,7 @@ topics: - codegen environment: - sdk: ^3.6.0 + sdk: ^3.8.0 resolution: workspace diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index e49cc7918..4d1b7a639 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,6 +1,7 @@ ## 6.9.6-wip - Move `package:collection` to a dev dependency. +- Require Dart 3.8 ## 6.9.5 diff --git a/json_serializable/README.md b/json_serializable/README.md index d53e3138e..47c0d0cbb 100644 --- a/json_serializable/README.md +++ b/json_serializable/README.md @@ -56,18 +56,18 @@ Building creates the corresponding part `example.g.dart`: part of 'example.dart'; Person _$PersonFromJson(Map<String, dynamic> json) => Person( - firstName: json['firstName'] as String, - lastName: json['lastName'] as String, - dateOfBirth: json['dateOfBirth'] == null - ? null - : DateTime.parse(json['dateOfBirth'] as String), - ); + firstName: json['firstName'] as String, + lastName: json['lastName'] as String, + dateOfBirth: json['dateOfBirth'] == null + ? null + : DateTime.parse(json['dateOfBirth'] as String), +); Map<String, dynamic> _$PersonToJson(Person instance) => <String, dynamic>{ - 'firstName': instance.firstName, - 'lastName': instance.lastName, - 'dateOfBirth': instance.dateOfBirth?.toIso8601String(), - }; + 'firstName': instance.firstName, + 'lastName': instance.lastName, + 'dateOfBirth': instance.dateOfBirth?.toIso8601String(), +}; ``` # Running the code generator @@ -211,10 +211,7 @@ customize the encoding/decoding of any type, you have a few options. factory Sample3.fromJson(Map<String, dynamic> json) => _$Sample3FromJson(json); - @JsonKey( - toJson: _toJson, - fromJson: _fromJson, - ) + @JsonKey(toJson: _toJson, fromJson: _fromJson) final DateTime value; Map<String, dynamic> toJson() => _$Sample3ToJson(this); diff --git a/json_serializable/example/example.g.dart b/json_serializable/example/example.g.dart index 0ed069cae..8dceaa3f8 100644 --- a/json_serializable/example/example.g.dart +++ b/json_serializable/example/example.g.dart @@ -9,15 +9,15 @@ part of 'example.dart'; // ************************************************************************** Person _$PersonFromJson(Map<String, dynamic> json) => Person( - firstName: json['firstName'] as String, - lastName: json['lastName'] as String, - dateOfBirth: json['dateOfBirth'] == null - ? null - : DateTime.parse(json['dateOfBirth'] as String), - ); + firstName: json['firstName'] as String, + lastName: json['lastName'] as String, + dateOfBirth: json['dateOfBirth'] == null + ? null + : DateTime.parse(json['dateOfBirth'] as String), +); Map<String, dynamic> _$PersonToJson(Person instance) => <String, dynamic>{ - 'firstName': instance.firstName, - 'lastName': instance.lastName, - 'dateOfBirth': instance.dateOfBirth?.toIso8601String(), - }; + 'firstName': instance.firstName, + 'lastName': instance.lastName, + 'dateOfBirth': instance.dateOfBirth?.toIso8601String(), +}; diff --git a/json_serializable/lib/builder.dart b/json_serializable/lib/builder.dart index b68eb7587..9c90094ce 100644 --- a/json_serializable/lib/builder.dart +++ b/json_serializable/lib/builder.dart @@ -27,7 +27,7 @@ Builder jsonSerializable(BuilderOptions options) { return jsonPartBuilder(config: config); } on CheckedFromJsonException catch (e) { final lines = <String>[ - 'Could not parse the options provided for `json_serializable`.' + 'Could not parse the options provided for `json_serializable`.', ]; if (e.key != null) { diff --git a/json_serializable/lib/src/check_dependencies.dart b/json_serializable/lib/src/check_dependencies.dart index 13117f268..21de3153c 100644 --- a/json_serializable/lib/src/check_dependencies.dart +++ b/json_serializable/lib/src/check_dependencies.dart @@ -12,16 +12,18 @@ import 'constants.dart'; const _productionDirectories = {'lib', 'bin'}; const _annotationPkgName = 'json_annotation'; -final _supportLanguageRange = - VersionConstraint.parse(supportedLanguageConstraint); +final _supportLanguageRange = VersionConstraint.parse( + supportedLanguageConstraint, +); final requiredJsonAnnotationMinVersion = Version.parse('4.9.0'); Future<void> pubspecHasRightVersion(BuildStep buildStep) async { final segments = buildStep.inputId.pathSegments; final productionDependency = segments.length > 1 && _productionDirectories.contains(segments.first); - final resource = - productionDependency ? _productionDependency : _developmentDependency; + final resource = productionDependency + ? _productionDependency + : _developmentDependency; await resource.run(buildStep); } @@ -62,16 +64,14 @@ Future<void> _validatePubspec(bool production, BuildStep buildStep) async { final thisPackageVer = Version.parse('$thisPackageVersion.0'); if (!_supportLanguageRange.allows(thisPackageVer)) { - log.warning( - ''' + log.warning(''' The language version ($thisPackageVer) of this package ($currentPackageName) does not match the required range `$supportedLanguageConstraint`. Edit pubspec.yaml to include an SDK constraint of at least $supportedLanguageConstraint. environment: sdk: $supportedLanguageConstraint -''', - ); +'''); } } diff --git a/json_serializable/lib/src/decode_helper.dart b/json_serializable/lib/src/decode_helper.dart index 3a20abbbc..633935e7d 100644 --- a/json_serializable/lib/src/decode_helper.dart +++ b/json_serializable/lib/src/decode_helper.dart @@ -30,9 +30,11 @@ mixin DecodeHelper implements HelperCore { final buffer = StringBuffer(); final mapType = config.anyMap ? 'Map' : 'Map<String, dynamic>'; - buffer.write('$targetClassReference ' - '${prefix}FromJson${genericClassArgumentsImpl(withConstraints: true)}' - '($mapType json'); + buffer.write( + '$targetClassReference ' + '${prefix}FromJson${genericClassArgumentsImpl(withConstraints: true)}' + '($mapType json', + ); if (config.genericArgumentFactories) { for (var arg in element.typeParameters) { @@ -51,10 +53,13 @@ mixin DecodeHelper implements HelperCore { final fromJsonLines = <String>[]; - String deserializeFun(String paramOrFieldName, - {ParameterElement? ctorParam}) => - _deserializeForField(accessibleFields[paramOrFieldName]!, - ctorParam: ctorParam); + String deserializeFun( + String paramOrFieldName, { + ParameterElement? ctorParam, + }) => _deserializeForField( + accessibleFields[paramOrFieldName]!, + ctorParam: ctorParam, + ); final data = _writeConstructorInvocation( element, @@ -69,8 +74,9 @@ mixin DecodeHelper implements HelperCore { ); final checks = _checkKeys( - accessibleFields.values - .where((fe) => data.usedCtorParamsAndFields.contains(fe.name)), + accessibleFields.values.where( + (fe) => data.usedCtorParamsAndFields.contains(fe.name), + ), ).toList(); if (config.checked) { @@ -94,9 +100,7 @@ mixin DecodeHelper implements HelperCore { ..write(''' \$checkedConvert($safeName, (v) => ''') ..write('val.$fieldName = ') - ..write( - _deserializeForField(fieldValue, checkedProperty: true), - ); + ..write(_deserializeForField(fieldValue, checkedProperty: true)); final readValueFunc = jsonKeyFor(fieldValue).readValueFunctionName; if (readValueFunc != null) { @@ -109,9 +113,11 @@ mixin DecodeHelper implements HelperCore { sectionBuffer.write('''\n return val; }'''); - final fieldKeyMap = Map.fromEntries(data.usedCtorParamsAndFields - .map((k) => MapEntry(k, nameAccess(accessibleFields[k]!))) - .where((me) => me.key != me.value)); + final fieldKeyMap = Map.fromEntries( + data.usedCtorParamsAndFields + .map((k) => MapEntry(k, nameAccess(accessibleFields[k]!))) + .where((me) => me.key != me.value), + ); String fieldKeyMapArg; if (fieldKeyMap.isEmpty) { @@ -128,7 +134,8 @@ mixin DecodeHelper implements HelperCore { } else { fromJsonLines.addAll(checks); - final sectionBuffer = StringBuffer()..write(''' + final sectionBuffer = StringBuffer() + ..write(''' ${data.content}'''); for (final field in data.fieldsToSet) { sectionBuffer @@ -168,8 +175,9 @@ mixin DecodeHelper implements HelperCore { args.add('allowedKeys: $allowKeysLiteral'); } - final requiredKeys = - accessibleFields.where((fe) => jsonKeyFor(fe).required).toList(); + final requiredKeys = accessibleFields + .where((fe) => jsonKeyFor(fe).required) + .toList(); if (requiredKeys.isNotEmpty) { final requiredKeyLiteral = constantList(requiredKeys); @@ -205,11 +213,7 @@ mixin DecodeHelper implements HelperCore { final readValueFunc = jsonKey.readValueFunctionName; String deserialize(String expression) => contextHelper - .deserialize( - targetType, - expression, - defaultValue: defaultValue, - ) + .deserialize(targetType, expression, defaultValue: defaultValue) .toString(); String value; @@ -217,8 +221,9 @@ mixin DecodeHelper implements HelperCore { if (config.checked) { value = deserialize('v'); if (!checkedProperty) { - final readValueBit = - readValueFunc == null ? '' : ',readValue: $readValueFunc,'; + final readValueBit = readValueFunc == null + ? '' + : ',readValue: $readValueFunc,'; value = '\$checkedConvert($jsonKeyName, (v) => $value$readValueBit)'; } } else { @@ -240,9 +245,11 @@ mixin DecodeHelper implements HelperCore { if (defaultValue != null) { if (jsonKey.disallowNullValue && jsonKey.required) { - log.warning('The `defaultValue` on field `${field.name}` will have no ' - 'effect because both `disallowNullValue` and `required` are set to ' - '`true`.'); + log.warning( + 'The `defaultValue` on field `${field.name}` will have no ' + 'effect because both `disallowNullValue` and `required` are set to ' + '`true`.', + ); } } return value; @@ -266,7 +273,7 @@ _ConstructorData _writeConstructorInvocation( Iterable<String> writableFields, Map<String, String> unavailableReasons, String Function(String paramOrFieldName, {ParameterElement ctorParam}) - deserializeForField, + deserializeForField, ) { final className = classElement.name; @@ -279,7 +286,8 @@ _ConstructorData _writeConstructorInvocation( for (final arg in ctor.parameters) { if (!availableConstructorParameters.contains(arg.name)) { if (arg.isRequired) { - var msg = 'Cannot populate the required constructor ' + var msg = + 'Cannot populate the required constructor ' 'argument: ${arg.name}.'; final additionalInfo = unavailableReasons[arg.name]; @@ -304,8 +312,9 @@ _ConstructorData _writeConstructorInvocation( } // fields that aren't already set by the constructor and that aren't final - final remainingFieldsForInvocationBody = - writableFields.toSet().difference(usedCtorParamsAndFields); + final remainingFieldsForInvocationBody = writableFields.toSet().difference( + usedCtorParamsAndFields, + ); final constructorExtra = constructorName.isEmpty ? '' : '.$constructorName'; @@ -315,16 +324,24 @@ _ConstructorData _writeConstructorInvocation( '${genericClassArguments(classElement, false)}' '$constructorExtra(', ) - ..writeAll(constructorArguments.map((paramElement) { - final content = - deserializeForField(paramElement.name, ctorParam: paramElement); - return ' $content,\n'; - })) - ..writeAll(namedConstructorArguments.map((paramElement) { - final value = - deserializeForField(paramElement.name, ctorParam: paramElement); - return ' ${paramElement.name}: $value,\n'; - })) + ..writeAll( + constructorArguments.map((paramElement) { + final content = deserializeForField( + paramElement.name, + ctorParam: paramElement, + ); + return ' $content,\n'; + }), + ) + ..writeAll( + namedConstructorArguments.map((paramElement) { + final value = deserializeForField( + paramElement.name, + ctorParam: paramElement, + ); + return ' ${paramElement.name}: $value,\n'; + }), + ) ..write(')'); usedCtorParamsAndFields.addAll(remainingFieldsForInvocationBody); diff --git a/json_serializable/lib/src/encoder_helper.dart b/json_serializable/lib/src/encoder_helper.dart index 4e876b757..dc7e8a9ec 100644 --- a/json_serializable/lib/src/encoder_helper.dart +++ b/json_serializable/lib/src/encoder_helper.dart @@ -92,26 +92,30 @@ mixin EncodeHelper implements HelperCore { final functionName = '${prefix}ToJson${genericClassArgumentsImpl(withConstraints: true)}'; - buffer.write('Map<String, dynamic> ' - '$functionName($targetClassReference $_toJsonParamName'); + buffer.write( + 'Map<String, dynamic> ' + '$functionName($targetClassReference $_toJsonParamName', + ); if (config.genericArgumentFactories) _writeGenericArgumentFactories(buffer); buffer ..write(') ') ..writeln('=> <String, dynamic>{') - ..writeAll(accessibleFields.map((field) { - final access = _fieldAccess(field); - - final keyExpression = safeNameAccess(field); - final valueExpression = _serializeField(field, access); - - final keyValuePair = _canWriteJsonWithoutNullCheck(field) - ? '$keyExpression: $valueExpression' - : 'if ($valueExpression case final $generatedLocalVarName?) ' - '$keyExpression: $generatedLocalVarName'; - return ' $keyValuePair,\n'; - })) + ..writeAll( + accessibleFields.map((field) { + final access = _fieldAccess(field); + + final keyExpression = safeNameAccess(field); + final valueExpression = _serializeField(field, access); + + final keyValuePair = _canWriteJsonWithoutNullCheck(field) + ? '$keyExpression: $valueExpression' + : 'if ($valueExpression case final $generatedLocalVarName?) ' + '$keyExpression: $generatedLocalVarName'; + return ' $keyValuePair,\n'; + }), + ) ..writeln('};'); yield buffer.toString(); @@ -133,9 +137,9 @@ mixin EncodeHelper implements HelperCore { String _serializeField(FieldElement field, String accessExpression) { try { - return getHelperContext(field) - .serialize(field.type, accessExpression) - .toString(); + return getHelperContext( + field, + ).serialize(field.type, accessExpression).toString(); } on UnsupportedTypeError catch (e) // ignore: avoid_catching_errors { throw createInvalidGenerationError('toJson', field, e); @@ -158,8 +162,10 @@ mixin EncodeHelper implements HelperCore { return !serializeConvertData.returnType.isNullableType; } - final nullableEncodeConverter = - hasConverterNullEncode(field.type, helperContext); + final nullableEncodeConverter = hasConverterNullEncode( + field.type, + helperContext, + ); if (nullableEncodeConverter != null) { return !nullableEncodeConverter && !field.type.isNullableType; diff --git a/json_serializable/lib/src/enum_utils.dart b/json_serializable/lib/src/enum_utils.dart index d5aa4d2d2..00f0cbc0f 100644 --- a/json_serializable/lib/src/enum_utils.dart +++ b/json_serializable/lib/src/enum_utils.dart @@ -35,14 +35,19 @@ String? enumValueMapFromType( DartType targetType, { bool nullWithNoAnnotation = false, }) { - final enumMap = - _enumMap(targetType, nullWithNoAnnotation: nullWithNoAnnotation); + final enumMap = _enumMap( + targetType, + nullWithNoAnnotation: nullWithNoAnnotation, + ); if (enumMap == null) return null; final items = enumMap.entries - .map((e) => ' ${targetType.element!.name}.${e.key.name}: ' - '${jsonLiteralAsDart(e.value)},') + .map( + (e) => + ' ${targetType.element!.name}.${e.key.name}: ' + '${jsonLiteralAsDart(e.value)},', + ) .join(); return 'const ${constMapName(targetType)} = {\n$items\n};'; @@ -78,8 +83,9 @@ Object? _generateEntry({ required JsonEnum jsonEnum, required DartType targetType, }) { - final annotation = - const TypeChecker.fromRuntime(JsonValue).firstAnnotationOfExact(field); + final annotation = const TypeChecker.fromRuntime( + JsonValue, + ).firstAnnotationOfExact(field); if (annotation == null) { final valueField = jsonEnum.valueField; diff --git a/json_serializable/lib/src/field_helpers.dart b/json_serializable/lib/src/field_helpers.dart index 8f8811f47..bc9d6133f 100644 --- a/json_serializable/lib/src/field_helpers.dart +++ b/json_serializable/lib/src/field_helpers.dart @@ -4,11 +4,9 @@ import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/src/dart/element/element.dart' // ignore: implementation_imports - show - InterfaceElementImpl; + show InterfaceElementImpl; import 'package:analyzer/src/dart/element/inheritance_manager3.dart' // ignore: implementation_imports - show - InheritanceManager3; + show InheritanceManager3; import 'package:source_gen/source_gen.dart'; import 'utils.dart'; @@ -18,7 +16,7 @@ class _FieldSet implements Comparable<_FieldSet> { final FieldElement sortField; _FieldSet._(this.field, this.sortField) - : assert(field.name == sortField.name); + : assert(field.name == sortField.name); factory _FieldSet(FieldElement? classField, FieldElement? superField) { // At least one of these will != null, perhaps both. @@ -29,8 +27,10 @@ class _FieldSet implements Comparable<_FieldSet> { // Prefer the field that's annotated with `JsonKey`, if any. // If not, use the class field. - final fieldHasJsonKey = - fields.firstWhere(hasJsonKeyAnnotation, orElse: () => fields.first); + final fieldHasJsonKey = fields.firstWhere( + hasJsonKeyAnnotation, + orElse: () => fields.first, + ); return _FieldSet._(fieldHasJsonKey, sortField); } @@ -52,7 +52,8 @@ class _FieldSet implements Comparable<_FieldSet> { } final checkerB = TypeChecker.fromStatic( - (b.enclosingElement3 as InterfaceElement).thisType); + (b.enclosingElement3 as InterfaceElement).thisType, + ); if (checkerB.isAssignableFrom(a.enclosingElement3)) { return 1; @@ -79,14 +80,16 @@ List<FieldElement> createSortedFieldSet(ClassElement element) { // Get all of the fields that need to be assigned // TODO: support overriding the field set with an annotation option final elementInstanceFields = Map.fromEntries( - element.fields.where((e) => !e.isStatic).map((e) => MapEntry(e.name, e))); + element.fields.where((e) => !e.isStatic).map((e) => MapEntry(e.name, e)), + ); final inheritedFields = <String, FieldElement>{}; final manager = InheritanceManager3(); - for (final v in manager - .getInheritedConcreteMap2(element as InterfaceElementImpl) - .values) { + for (final v + in manager + .getInheritedConcreteMap2(element as InterfaceElementImpl) + .values) { assert(v is! FieldElement); if (_dartCoreObjectChecker.isExactly(v.enclosingElement3)) { continue; @@ -102,13 +105,15 @@ List<FieldElement> createSortedFieldSet(ClassElement element) { } // Get the list of all fields for `element` - final allFields = - elementInstanceFields.keys.toSet().union(inheritedFields.keys.toSet()); - - final fields = allFields - .map((e) => _FieldSet(elementInstanceFields[e], inheritedFields[e])) - .toList() - ..sort(); + final allFields = elementInstanceFields.keys.toSet().union( + inheritedFields.keys.toSet(), + ); + + final fields = + allFields + .map((e) => _FieldSet(elementInstanceFields[e], inheritedFields[e])) + .toList() + ..sort(); return fields.map((fs) => fs.field).toList(growable: false); } diff --git a/json_serializable/lib/src/generator_helper.dart b/json_serializable/lib/src/generator_helper.dart index 8c0e13b4a..ef1bf16e0 100644 --- a/json_serializable/lib/src/generator_helper.dart +++ b/json_serializable/lib/src/generator_helper.dart @@ -23,12 +23,9 @@ class GeneratorHelper extends HelperCore with EncodeHelper, DecodeHelper { ClassElement element, ConstantReader annotation, ) : super( - element, - mergeConfig( - _generator.config, - annotation, - classElement: element, - )); + element, + mergeConfig(_generator.config, annotation, classElement: element), + ); @override void addMember(String memberContent) { @@ -93,40 +90,37 @@ class GeneratorHelper extends HelperCore with EncodeHelper, DecodeHelper { // Need to add candidates BACK even if they are not used in the factory if // they are forced to be used for toJSON - for (var candidate in sortedFields.where((element) => - jsonKeyFor(element).explicitYesToJson && - !fieldsToUse.contains(element))) { + for (var candidate in sortedFields.where( + (element) => + jsonKeyFor(element).explicitYesToJson && + !fieldsToUse.contains(element), + )) { fieldsToUse.add(candidate); } // Need the fields to maintain the original source ordering fieldsToUse.sort( - (a, b) => sortedFields.indexOf(a).compareTo(sortedFields.indexOf(b))); + (a, b) => sortedFields.indexOf(a).compareTo(sortedFields.indexOf(b)), + ); accessibleFieldSet = fieldsToUse.toSet(); } accessibleFieldSet - ..removeWhere( - (element) => jsonKeyFor(element).explicitNoToJson, - ) - + ..removeWhere((element) => jsonKeyFor(element).explicitNoToJson) // Check for duplicate JSON keys due to colliding annotations. // We do this now, since we have a final field list after any pruning done // by `_writeCtor`. - ..fold( - <String>{}, - (Set<String> set, fe) { - final jsonKey = nameAccess(fe); - if (!set.add(jsonKey)) { - throw InvalidGenerationSourceError( - 'More than one field has the JSON key for name "$jsonKey".', - element: fe, - ); - } - return set; - }, - ); + ..fold(<String>{}, (Set<String> set, fe) { + final jsonKey = nameAccess(fe); + if (!set.add(jsonKey)) { + throw InvalidGenerationSourceError( + 'More than one field has the JSON key for name "$jsonKey".', + element: fe, + ); + } + return set; + }); if (config.createFieldMap) { yield createFieldMap(accessibleFieldSet); diff --git a/json_serializable/lib/src/helper_core.dart b/json_serializable/lib/src/helper_core.dart index 0a054f828..6e9e731ab 100644 --- a/json_serializable/lib/src/helper_core.dart +++ b/json_serializable/lib/src/helper_core.dart @@ -65,11 +65,13 @@ InvalidGenerationSourceError createInvalidGenerationError( String? todo; if (error.type is TypeParameterType) { - message = '$message because of type ' + message = + '$message because of type ' '`${error.type.toStringNonNullable()}` ' '(type parameter)'; - todo = ''' + todo = + ''' To support type parameters (generic types) you can: $converterOrKeyInstructions * Set `JsonSerializable.genericArgumentFactories` to `true` @@ -78,17 +80,14 @@ $converterOrKeyInstructions message = '$message because of type `${typeToCode(error.type)}`'; } else { final element = error.type.element?.name; - todo = ''' + todo = + ''' To support the type `${element ?? error.type}` you can: $converterOrKeyInstructions'''; } return InvalidGenerationSourceError( - [ - '$message.', - if (error.reason != null) error.reason, - if (todo != null) todo, - ].join('\n'), + ['$message.', if (error.reason != null) error.reason, ?todo].join('\n'), element: field, ); } @@ -119,13 +118,15 @@ String genericClassArguments(ClassElement element, bool? withConstraints) { if (withConstraints == null || element.typeParameters.isEmpty) { return ''; } - final values = element.typeParameters.map((t) { - if (withConstraints && t.bound != null) { - final boundCode = typeToCode(t.bound!); - return '${t.name} extends $boundCode'; - } else { - return t.name; - } - }).join(', '); + final values = element.typeParameters + .map((t) { + if (withConstraints && t.bound != null) { + final boundCode = typeToCode(t.bound!); + return '${t.name} extends $boundCode'; + } else { + return t.name; + } + }) + .join(', '); return '<$values>'; } diff --git a/json_serializable/lib/src/json_enum_generator.dart b/json_serializable/lib/src/json_enum_generator.dart index e72657add..17fe4bd8b 100644 --- a/json_serializable/lib/src/json_enum_generator.dart +++ b/json_serializable/lib/src/json_enum_generator.dart @@ -25,11 +25,11 @@ class JsonEnumGenerator extends GeneratorForAnnotation<JsonEnum> { ); } - final value = - enumValueMapFromType(element.thisType, nullWithNoAnnotation: true); + final value = enumValueMapFromType( + element.thisType, + nullWithNoAnnotation: true, + ); - return [ - if (value != null) value, - ]; + return [?value]; } } diff --git a/json_serializable/lib/src/json_key_utils.dart b/json_serializable/lib/src/json_key_utils.dart index addccaae8..a17e45666 100644 --- a/json_serializable/lib/src/json_key_utils.dart +++ b/json_serializable/lib/src/json_key_utils.dart @@ -18,8 +18,10 @@ import 'utils.dart'; final _jsonKeyExpando = Expando<Map<ClassConfig, KeyConfig>>(); KeyConfig jsonKeyForField(FieldElement field, ClassConfig classAnnotation) => - (_jsonKeyExpando[field] ??= Map.identity())[classAnnotation] ??= - _from(field, classAnnotation); + (_jsonKeyExpando[field] ??= Map.identity())[classAnnotation] ??= _from( + field, + classAnnotation, + ); KeyConfig _from(FieldElement element, ClassConfig classAnnotation) { // If an annotation exists on `element` the source is a 'real' field. @@ -82,28 +84,19 @@ KeyConfig _from(FieldElement element, ClassConfig classAnnotation) { if (reader.isList) { return [ for (var e in reader.listValue) - literalForObject(fieldName, e, [ - ...typeInformation, - 'List', - ]) + literalForObject(fieldName, e, [...typeInformation, 'List']), ]; } if (reader.isSet) { return { for (var e in reader.setValue) - literalForObject(fieldName, e, [ - ...typeInformation, - 'Set', - ]) + literalForObject(fieldName, e, [...typeInformation, 'Set']), }; } if (reader.isMap) { - final mapTypeInformation = [ - ...typeInformation, - 'Map', - ]; + final mapTypeInformation = [...typeInformation, 'Map']; return reader.mapValue.map( (k, v) => MapEntry( literalForObject(fieldName, k!, mapTypeInformation), @@ -147,8 +140,8 @@ KeyConfig _from(FieldElement element, ClassConfig classAnnotation) { final invokeConst = functionValue is ConstructorElement && functionValue.isConst - ? 'const ' - : ''; + ? 'const ' + : ''; return '$invokeConst${functionValue.qualifiedName}()'; } @@ -191,11 +184,15 @@ KeyConfig _from(FieldElement element, ClassConfig classAnnotation) { ); } - final enumValueNames = - enumFields.map((p) => p.name).toList(growable: false); + final enumValueNames = enumFields + .map((p) => p.name) + .toList(growable: false); - final enumValueName = - enumValueForDartObject<String>(objectValue, enumValueNames, (n) => n); + final enumValueName = enumValueForDartObject<String>( + objectValue, + enumValueNames, + (n) => n, + ); return '${annotationType.element!.name}.$enumValueName'; } else { @@ -233,8 +230,9 @@ KeyConfig _from(FieldElement element, ClassConfig classAnnotation) { String? readValueFunctionName; final readValue = obj.read('readValue'); if (!readValue.isNull) { - readValueFunctionName = - readValue.objectValue.toFunctionValue()!.qualifiedName; + readValueFunctionName = readValue.objectValue + .toFunctionValue()! + .qualifiedName; } final ignore = obj.read('ignore').literalValue as bool?; @@ -269,8 +267,10 @@ KeyConfig _from(FieldElement element, ClassConfig classAnnotation) { name: obj.read('name').literalValue as String?, readValueFunctionName: readValueFunctionName, required: obj.read('required').literalValue as bool?, - unknownEnumValue: - createAnnotationValue('unknownEnumValue', mustBeEnum: true), + unknownEnumValue: createAnnotationValue( + 'unknownEnumValue', + mustBeEnum: true, + ), includeToJson: includeToJson, includeFromJson: includeFromJson, ); @@ -292,9 +292,10 @@ KeyConfig _populateJsonKey( if (disallowNullValue == true) { if (includeIfNull == true) { throwUnsupported( - element, - 'Cannot set both `disallowNullValue` and `includeIfNull` to `true`. ' - 'This leads to incompatible `toJson` and `fromJson` behavior.'); + element, + 'Cannot set both `disallowNullValue` and `includeIfNull` to `true`. ' + 'This leads to incompatible `toJson` and `fromJson` behavior.', + ); } } @@ -302,7 +303,10 @@ KeyConfig _populateJsonKey( defaultValue: defaultValue, disallowNullValue: disallowNullValue ?? false, includeIfNull: _includeIfNull( - includeIfNull, disallowNullValue, classAnnotation.includeIfNull), + includeIfNull, + disallowNullValue, + classAnnotation.includeIfNull, + ), name: name ?? encodedFieldName(classAnnotation.fieldRename, element.name), readValueFunctionName: readValueFunctionName, required: required ?? false, @@ -335,5 +339,6 @@ bool _interfaceTypesEqual(DartType a, DartType b) { const jsonKeyNullForUndefinedEnumValueFieldName = 'JsonKey.nullForUndefinedEnumValue'; -final _nullAsUnknownChecker = - TypeChecker.fromRuntime(JsonKey.nullForUndefinedEnumValue.runtimeType); +final _nullAsUnknownChecker = TypeChecker.fromRuntime( + JsonKey.nullForUndefinedEnumValue.runtimeType, +); diff --git a/json_serializable/lib/src/json_literal_generator.dart b/json_serializable/lib/src/json_literal_generator.dart index dd6189fa2..87f0acc08 100644 --- a/json_serializable/lib/src/json_literal_generator.dart +++ b/json_serializable/lib/src/json_literal_generator.dart @@ -23,12 +23,15 @@ class JsonLiteralGenerator extends GeneratorForAnnotation<JsonLiteral> { ) async { if (p.isAbsolute(annotation.read('path').stringValue)) { throw ArgumentError( - '`annotation.path` must be relative path to the source file.'); + '`annotation.path` must be relative path to the source file.', + ); } final sourcePathDir = p.dirname(buildStep.inputId.path); - final fileId = AssetId(buildStep.inputId.package, - p.join(sourcePathDir, annotation.read('path').stringValue)); + final fileId = AssetId( + buildStep.inputId.package, + p.join(sourcePathDir, annotation.read('path').stringValue), + ); final content = json.decode(await buildStep.readAsString(fileId)); final asConst = annotation.read('asConst').boolValue; diff --git a/json_serializable/lib/src/json_part_builder.dart b/json_serializable/lib/src/json_part_builder.dart index a5013f8d6..53ad3f039 100644 --- a/json_serializable/lib/src/json_part_builder.dart +++ b/json_serializable/lib/src/json_part_builder.dart @@ -57,12 +57,16 @@ class _UnifiedGenerator extends Generator { final values = <String>{}; for (var generator in _generators) { - for (var annotatedElement - in library.annotatedWith(generator.typeChecker)) { + for (var annotatedElement in library.annotatedWith( + generator.typeChecker, + )) { await pubspecHasRightVersion(buildStep); final generatedValue = generator.generateForAnnotatedElement( - annotatedElement.element, annotatedElement.annotation, buildStep); + annotatedElement.element, + annotatedElement.annotation, + buildStep, + ); for (var value in _normalizeGeneratorOutput(generatedValue)) { assert(value.length == value.trim().length); values.add(value); @@ -86,21 +90,25 @@ Iterable<String> _normalizeGeneratorOutput(Object? value) { } if (value is Iterable) { - return value.where((e) => e != null).map((e) { - if (e is String) { - return e.trim(); - } - - throw _argError(e as Object); - }).where((e) => e.isNotEmpty); + return value + .where((e) => e != null) + .map((e) { + if (e is String) { + return e.trim(); + } + + throw _argError(e as Object); + }) + .where((e) => e.isNotEmpty); } throw _argError(value); } // Borrowed from `package:source_gen` ArgumentError _argError(Object value) => ArgumentError( - 'Must be a String or be an Iterable containing String values. ' - 'Found `${Error.safeToString(value)}` (${value.runtimeType}).'); + 'Must be a String or be an Iterable containing String values. ' + 'Found `${Error.safeToString(value)}` (${value.runtimeType}).', +); String defaultFormatOutput(String code, Version languageVersion) => DartFormatter(languageVersion: languageVersion).format(code); diff --git a/json_serializable/lib/src/json_serializable_generator.dart b/json_serializable/lib/src/json_serializable_generator.dart index 2ff7b6dbf..c69e86796 100644 --- a/json_serializable/lib/src/json_serializable_generator.dart +++ b/json_serializable/lib/src/json_serializable_generator.dart @@ -32,11 +32,9 @@ class JsonSerializableGenerator factory JsonSerializableGenerator({ JsonSerializable? config, List<TypeHelper>? typeHelpers, - }) => - JsonSerializableGenerator.fromSettings(Settings( - config: config, - typeHelpers: typeHelpers, - )); + }) => JsonSerializableGenerator.fromSettings( + Settings(config: config, typeHelpers: typeHelpers), + ); /// Creates an instance of [JsonSerializableGenerator]. /// @@ -47,13 +45,12 @@ class JsonSerializableGenerator factory JsonSerializableGenerator.withDefaultHelpers( Iterable<TypeHelper> typeHelpers, { JsonSerializable? config, - }) => - JsonSerializableGenerator( - config: config, - typeHelpers: List.unmodifiable( - typeHelpers.followedBy(Settings.defaultHelpers), - ), - ); + }) => JsonSerializableGenerator( + config: config, + typeHelpers: List.unmodifiable( + typeHelpers.followedBy(Settings.defaultHelpers), + ), + ); @override Iterable<String> generateForAnnotatedElement( diff --git a/json_serializable/lib/src/lambda_result.dart b/json_serializable/lib/src/lambda_result.dart index c5aa510ff..9cc95e998 100644 --- a/json_serializable/lib/src/lambda_result.dart +++ b/json_serializable/lib/src/lambda_result.dart @@ -30,8 +30,8 @@ class LambdaResult { static String process(Object subField) => (subField is LambdaResult && closureArg == subField._fullExpression) - ? subField.lambda - : '($closureArg) => $subField'; + ? subField.lambda + : '($closureArg) => $subField'; } String _cast(String expression, DartType targetType) { diff --git a/json_serializable/lib/src/settings.dart b/json_serializable/lib/src/settings.dart index 62d35a93c..e996f99a3 100644 --- a/json_serializable/lib/src/settings.dart +++ b/json_serializable/lib/src/settings.dart @@ -40,10 +40,10 @@ class Settings { final List<TypeHelper> _typeHelpers; Iterable<TypeHelper> get allHelpers => const <TypeHelper>[ - ConvertHelper(), - JsonConverterHelper(), - GenericFactoryHelper(), - ].followedBy(_typeHelpers).followedBy(_coreHelpers); + ConvertHelper(), + JsonConverterHelper(), + GenericFactoryHelper(), + ].followedBy(_typeHelpers).followedBy(_coreHelpers); final ClassConfig config; @@ -52,13 +52,11 @@ class Settings { /// If [typeHelpers] is not provided, the built-in helpers are used: /// [BigIntHelper], [DateTimeHelper], [DurationHelper], [JsonHelper], and /// [UriHelper]. - Settings({ - JsonSerializable? config, - List<TypeHelper>? typeHelpers, - }) : config = config != null - ? ClassConfig.fromJsonSerializable(config) - : ClassConfig.defaults, - _typeHelpers = typeHelpers ?? defaultHelpers; + Settings({JsonSerializable? config, List<TypeHelper>? typeHelpers}) + : config = config != null + ? ClassConfig.fromJsonSerializable(config) + : ClassConfig.defaults, + _typeHelpers = typeHelpers ?? defaultHelpers; /// Creates an instance of [Settings]. /// @@ -69,9 +67,8 @@ class Settings { factory Settings.withDefaultHelpers( Iterable<TypeHelper> typeHelpers, { JsonSerializable? config, - }) => - Settings( - config: config, - typeHelpers: List.unmodifiable(typeHelpers.followedBy(defaultHelpers)), - ); + }) => Settings( + config: config, + typeHelpers: List.unmodifiable(typeHelpers.followedBy(defaultHelpers)), + ); } diff --git a/json_serializable/lib/src/shared_checkers.dart b/json_serializable/lib/src/shared_checkers.dart index d2da8dbe8..0ac8b8d79 100644 --- a/json_serializable/lib/src/shared_checkers.dart +++ b/json_serializable/lib/src/shared_checkers.dart @@ -23,5 +23,5 @@ DartType coreIterableGenericType(DartType type) => const simpleJsonTypeChecker = TypeChecker.any([ coreStringTypeChecker, TypeChecker.fromUrl('dart:core#bool'), - TypeChecker.fromUrl('dart:core#num') + TypeChecker.fromUrl('dart:core#num'), ]); diff --git a/json_serializable/lib/src/type_helper_ctx.dart b/json_serializable/lib/src/type_helper_ctx.dart index b49008504..f6d355b15 100644 --- a/json_serializable/lib/src/type_helper_ctx.dart +++ b/json_serializable/lib/src/type_helper_ctx.dart @@ -18,8 +18,7 @@ import 'utils.dart'; TypeHelperCtx typeHelperContext( HelperCore helperCore, FieldElement fieldElement, -) => - TypeHelperCtx._(helperCore, fieldElement); +) => TypeHelperCtx._(helperCore, fieldElement); class TypeHelperCtx implements TypeHelperContextWithConfig, TypeHelperContextWithConvert { @@ -51,10 +50,10 @@ class TypeHelperCtx @override Object? serialize(DartType targetType, String expression) => _run( - targetType, - expression, - (TypeHelper th) => th.serialize(targetType, expression, this), - ); + targetType, + expression, + (TypeHelper th) => th.serialize(targetType, expression, this), + ); @override Object deserialize( @@ -65,12 +64,8 @@ class TypeHelperCtx final value = _run( targetType, expression, - (TypeHelper th) => th.deserialize( - targetType, - expression, - this, - defaultValue != null, - ), + (TypeHelper th) => + th.deserialize(targetType, expression, this, defaultValue != null), ); return DefaultContainer.deserialize( @@ -85,10 +80,14 @@ class TypeHelperCtx String expression, Object? Function(TypeHelper) invoke, ) => - _helperCore.allTypeHelpers.map(invoke).firstWhere( - (r) => r != null, - orElse: () => throw UnsupportedTypeError(targetType, expression), - ) as Object; + _helperCore.allTypeHelpers + .map(invoke) + .firstWhere( + (r) => r != null, + orElse: () => + throw UnsupportedTypeError(targetType, expression), + ) + as Object; } class _ConvertPair { @@ -130,16 +129,18 @@ ConvertData? _convertData(DartObject obj, FieldElement element, bool isFrom) { executableElement.parameters.first.isNamed || executableElement.parameters.where((pe) => !pe.isOptional).length > 1) { throwUnsupported( - element, - 'The `$paramName` function `${executableElement.name}` must have one ' - 'positional parameter.'); + element, + 'The `$paramName` function `${executableElement.name}` must have one ' + 'positional parameter.', + ); } final returnType = executableElement.returnType; final argType = executableElement.parameters.first.type; if (isFrom) { - final hasDefaultValue = - !jsonKeyAnnotation(element).read('defaultValue').isNull; + final hasDefaultValue = !jsonKeyAnnotation( + element, + ).read('defaultValue').isNull; if (returnType is TypeParameterType) { // We keep things simple in this case. We rely on inferred type arguments @@ -153,10 +154,11 @@ ConvertData? _convertData(DartObject obj, FieldElement element, bool isFrom) { final returnTypeCode = typeToCode(returnType); final elementTypeCode = typeToCode(element.type); throwUnsupported( - element, - 'The `$paramName` function `${executableElement.name}` return type ' - '`$returnTypeCode` is not compatible with field type ' - '`$elementTypeCode`.'); + element, + 'The `$paramName` function `${executableElement.name}` return type ' + '`$returnTypeCode` is not compatible with field type ' + '`$elementTypeCode`.', + ); } } } else { @@ -168,10 +170,11 @@ ConvertData? _convertData(DartObject obj, FieldElement element, bool isFrom) { final argTypeCode = typeToCode(argType); final elementTypeCode = typeToCode(element.type); throwUnsupported( - element, - 'The `$paramName` function `${executableElement.name}` argument type ' - '`$argTypeCode` is not compatible with field type' - ' `$elementTypeCode`.'); + element, + 'The `$paramName` function `${executableElement.name}` argument type ' + '`$argTypeCode` is not compatible with field type' + ' `$elementTypeCode`.', + ); } } diff --git a/json_serializable/lib/src/type_helpers/big_int_helper.dart b/json_serializable/lib/src/type_helpers/big_int_helper.dart index 3c5c4316d..b2634730f 100644 --- a/json_serializable/lib/src/type_helpers/big_int_helper.dart +++ b/json_serializable/lib/src/type_helpers/big_int_helper.dart @@ -18,11 +18,7 @@ class BigIntHelper extends TypeHelper { String expression, TypeHelperContext context, ) => - bigIntString.serialize( - targetType, - expression, - targetType.isNullableType, - ); + bigIntString.serialize(targetType, expression, targetType.isNullableType); @override DefaultContainer? deserialize( @@ -30,11 +26,10 @@ class BigIntHelper extends TypeHelper { String expression, TypeHelperContext context, bool defaultProvided, - ) => - bigIntString.deserialize( - targetType, - expression, - targetType.isNullableType, - false, - ); + ) => bigIntString.deserialize( + targetType, + expression, + targetType.isNullableType, + false, + ); } diff --git a/json_serializable/lib/src/type_helpers/config_types.dart b/json_serializable/lib/src/type_helpers/config_types.dart index 227f1890b..80d258589 100644 --- a/json_serializable/lib/src/type_helpers/config_types.dart +++ b/json_serializable/lib/src/type_helpers/config_types.dart @@ -89,7 +89,8 @@ class ClassConfig { config.createFieldMap ?? ClassConfig.defaults.createFieldMap, createJsonKeys: config.createJsonKeys ?? ClassConfig.defaults.createJsonKeys, - createPerFieldToJson: config.createPerFieldToJson ?? + createPerFieldToJson: + config.createPerFieldToJson ?? ClassConfig.defaults.createPerFieldToJson, createFactory: config.createFactory ?? ClassConfig.defaults.createFactory, @@ -100,10 +101,12 @@ class ClassConfig { config.explicitToJson ?? ClassConfig.defaults.explicitToJson, includeIfNull: config.includeIfNull ?? ClassConfig.defaults.includeIfNull, - genericArgumentFactories: config.genericArgumentFactories ?? + genericArgumentFactories: + config.genericArgumentFactories ?? ClassConfig.defaults.genericArgumentFactories, fieldRename: config.fieldRename ?? ClassConfig.defaults.fieldRename, - disallowUnrecognizedKeys: config.disallowUnrecognizedKeys ?? + disallowUnrecognizedKeys: + config.disallowUnrecognizedKeys ?? ClassConfig.defaults.disallowUnrecognizedKeys, // TODO typeConverters = [] ); @@ -128,20 +131,20 @@ class ClassConfig { ); JsonSerializable toJsonSerializable() => JsonSerializable( - checked: checked, - anyMap: anyMap, - constructor: constructor, - createFactory: createFactory, - createToJson: createToJson, - createFieldMap: createFieldMap, - createJsonKeys: createJsonKeys, - createPerFieldToJson: createPerFieldToJson, - ignoreUnannotated: ignoreUnannotated, - explicitToJson: explicitToJson, - includeIfNull: includeIfNull, - genericArgumentFactories: genericArgumentFactories, - fieldRename: fieldRename, - disallowUnrecognizedKeys: disallowUnrecognizedKeys, - // TODO typeConverters = [] - ); + checked: checked, + anyMap: anyMap, + constructor: constructor, + createFactory: createFactory, + createToJson: createToJson, + createFieldMap: createFieldMap, + createJsonKeys: createJsonKeys, + createPerFieldToJson: createPerFieldToJson, + ignoreUnannotated: ignoreUnannotated, + explicitToJson: explicitToJson, + includeIfNull: includeIfNull, + genericArgumentFactories: genericArgumentFactories, + fieldRename: fieldRename, + disallowUnrecognizedKeys: disallowUnrecognizedKeys, + // TODO typeConverters = [] + ); } diff --git a/json_serializable/lib/src/type_helpers/convert_helper.dart b/json_serializable/lib/src/type_helpers/convert_helper.dart index 6657a9e60..45e969431 100644 --- a/json_serializable/lib/src/type_helpers/convert_helper.dart +++ b/json_serializable/lib/src/type_helpers/convert_helper.dart @@ -39,8 +39,10 @@ class ConvertHelper extends TypeHelper<TypeHelperContextWithConvert> { return null; } - assert(toJsonData.paramType is TypeParameterType || - targetType.isAssignableTo(toJsonData.paramType)); + assert( + toJsonData.paramType is TypeParameterType || + targetType.isAssignableTo(toJsonData.paramType), + ); return LambdaResult(expression, toJsonData.name); } diff --git a/json_serializable/lib/src/type_helpers/date_time_helper.dart b/json_serializable/lib/src/type_helpers/date_time_helper.dart index 89a526013..64c582057 100644 --- a/json_serializable/lib/src/type_helpers/date_time_helper.dart +++ b/json_serializable/lib/src/type_helpers/date_time_helper.dart @@ -17,12 +17,11 @@ class DateTimeHelper extends TypeHelper { DartType targetType, String expression, TypeHelperContext context, - ) => - dateTimeString.serialize( - targetType, - expression, - targetType.isNullableType, - ); + ) => dateTimeString.serialize( + targetType, + expression, + targetType.isNullableType, + ); @override DefaultContainer? deserialize( @@ -30,11 +29,10 @@ class DateTimeHelper extends TypeHelper { String expression, TypeHelperContext context, bool defaultProvided, - ) => - dateTimeString.deserialize( - targetType, - expression, - targetType.isNullableType, - false, - ); + ) => dateTimeString.deserialize( + targetType, + expression, + targetType.isNullableType, + false, + ); } diff --git a/json_serializable/lib/src/type_helpers/generic_factory_helper.dart b/json_serializable/lib/src/type_helpers/generic_factory_helper.dart index 6a005f4c6..5d2900998 100644 --- a/json_serializable/lib/src/type_helpers/generic_factory_helper.dart +++ b/json_serializable/lib/src/type_helpers/generic_factory_helper.dart @@ -57,7 +57,8 @@ class GenericFactoryHelper extends TypeHelper<TypeHelperContextWithConfig> { const _fromJsonHelperName = r'_$nullableGenericFromJson'; -const _fromJsonHelper = ''' +const _fromJsonHelper = + ''' T? $_fromJsonHelperName<T>( Object? input, T Function(Object? json) fromJson, @@ -67,7 +68,8 @@ T? $_fromJsonHelperName<T>( const _toJsonHelperName = r'_$nullableGenericToJson'; -const _toJsonHelper = ''' +const _toJsonHelper = + ''' Object? $_toJsonHelperName<T>( T? input, Object? Function(T value) toJson, diff --git a/json_serializable/lib/src/type_helpers/json_converter_helper.dart b/json_serializable/lib/src/type_helpers/json_converter_helper.dart index 20ec0fc25..778ffeeae 100644 --- a/json_serializable/lib/src/type_helpers/json_converter_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_converter_helper.dart @@ -116,8 +116,8 @@ class _JsonConvertData { String accessor, this.jsonType, this.fieldType, - ) : accessString = 'const $className${_withAccessor(accessor)}()', - isGeneric = false; + ) : accessString = 'const $className${_withAccessor(accessor)}()', + isGeneric = false; _JsonConvertData.genericClass( String className, @@ -125,9 +125,8 @@ class _JsonConvertData { String accessor, this.jsonType, this.fieldType, - ) : accessString = - '$className<$genericTypeArg>${_withAccessor(accessor)}()', - isGeneric = true; + ) : accessString = '$className<$genericTypeArg>${_withAccessor(accessor)}()', + isGeneric = true; _JsonConvertData.propertyAccess( this.accessString, @@ -175,8 +174,9 @@ _JsonConvertData? _typeConverter( var matchingAnnotations = converterMatches(ctx.fieldElement.metadata); if (matchingAnnotations.isEmpty) { - matchingAnnotations = - converterMatches(ctx.fieldElement.getter?.metadata ?? []); + matchingAnnotations = converterMatches( + ctx.fieldElement.getter?.metadata ?? [], + ); if (matchingAnnotations.isEmpty) { matchingAnnotations = converterMatches(ctx.classElement.metadata); @@ -280,9 +280,7 @@ _ConverterMatch? _compatibleMatch( final converterClassElement = constantValue.type!.element as ClassElement; final jsonConverterSuper = converterClassElement.allSupertypes - .where( - (e) => _jsonConverterChecker.isExactly(e.element), - ) + .where((e) => _jsonConverterChecker.isExactly(e.element)) .singleOrNull; if (jsonConverterSuper == null) { @@ -310,10 +308,11 @@ _ConverterMatch? _compatibleMatch( assert(converterClassElement.typeParameters.isNotEmpty); if (converterClassElement.typeParameters.length > 1) { throw InvalidGenerationSourceError( - '`JsonConverter` implementations can have no more than one type ' - 'argument. `${converterClassElement.name}` has ' - '${converterClassElement.typeParameters.length}.', - element: converterClassElement); + '`JsonConverter` implementations can have no more than one type ' + 'argument. `${converterClassElement.name}` has ' + '${converterClassElement.typeParameters.length}.', + element: converterClassElement, + ); } return _ConverterMatch( diff --git a/json_serializable/lib/src/type_helpers/json_helper.dart b/json_serializable/lib/src/type_helpers/json_helper.dart index d66ab772e..c2121ac80 100644 --- a/json_serializable/lib/src/type_helpers/json_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_helper.dart @@ -154,8 +154,9 @@ List<String> _helperParams( final args = <String>[]; for (var helperArg in rest) { - final typeParamIndex = - type.element.typeParameters.indexOf(helperArg.element); + final typeParamIndex = type.element.typeParameters.indexOf( + helperArg.element, + ); // TODO: throw here if `typeParamIndex` is -1 ? final typeArg = type.typeArguments[typeParamIndex]; @@ -166,10 +167,7 @@ List<String> _helperParams( return args; } -TypeParameterType _decodeHelper( - ParameterElement param, - Element targetElement, -) { +TypeParameterType _decodeHelper(ParameterElement param, Element targetElement) { final type = param.type; if (type is FunctionType && @@ -197,10 +195,7 @@ TypeParameterType _decodeHelper( ); } -TypeParameterType _encodeHelper( - ParameterElement param, - Element targetElement, -) { +TypeParameterType _encodeHelper(ParameterElement param, Element targetElement) { final type = param.type; if (type is FunctionType && @@ -249,8 +244,9 @@ InterfaceType? _instantiate( ) { final argTypes = ctorParamType.typeArguments.map((arg) { final typeParamIndex = classType.element.typeParameters.indexWhere( - // TODO: not 100% sure `nullabilitySuffix` is right - (e) => e.instantiate(nullabilitySuffix: arg.nullabilitySuffix) == arg); + // TODO: not 100% sure `nullabilitySuffix` is right + (e) => e.instantiate(nullabilitySuffix: arg.nullabilitySuffix) == arg, + ); if (typeParamIndex >= 0) { return classType.typeArguments[typeParamIndex]; } else { @@ -274,9 +270,9 @@ ClassConfig? _annotation(ClassConfig config, InterfaceType source) { if (source.isEnum) { return null; } - final annotations = const TypeChecker.fromRuntime(JsonSerializable) - .annotationsOfExact(source.element, throwOnUnresolved: false) - .toList(); + final annotations = const TypeChecker.fromRuntime( + JsonSerializable, + ).annotationsOfExact(source.element, throwOnUnresolved: false).toList(); if (annotations.isEmpty) { return null; diff --git a/json_serializable/lib/src/type_helpers/map_helper.dart b/json_serializable/lib/src/type_helpers/map_helper.dart index e0c6ef560..9792faed0 100644 --- a/json_serializable/lib/src/type_helpers/map_helper.dart +++ b/json_serializable/lib/src/type_helpers/map_helper.dart @@ -36,7 +36,7 @@ class MapHelper extends TypeHelper<TypeHelperContextWithConfig> { final subFieldValue = context.serialize(valueType, closureArg); final subKeyValue = _forType(keyType)?.serialize(keyType, _keyParam, false) ?? - context.serialize(keyType, _keyParam); + context.serialize(keyType, _keyParam); if (closureArg == subFieldValue && _keyParam == subKeyValue) { return expression; @@ -67,7 +67,8 @@ class MapHelper extends TypeHelper<TypeHelperContextWithConfig> { _checkSafeKeyType(expression, keyArg); - final valueArgIsAny = valueArg is DynamicType || + final valueArgIsAny = + valueArg is DynamicType || (valueArg.isDartCoreObject && valueArg.isNullableType); final isKeyStringable = _isKeyStringable(keyArg); @@ -125,8 +126,9 @@ class MapHelper extends TypeHelper<TypeHelperContextWithConfig> { final toFromString = _forType(keyArg); if (toFromString != null) { - keyUsage = - toFromString.deserialize(keyArg, keyUsage, false, true).toString(); + keyUsage = toFromString + .deserialize(keyArg, keyUsage, false, true) + .toString(); } return '($expression $mapCast)$optionalQuestion.map( ' @@ -138,12 +140,7 @@ final _intString = ToFromStringHelper('int.parse', 'toString()', 'int'); /// [ToFromStringHelper] instances representing non-String types that can /// be used as [Map] keys. -final _instances = [ - bigIntString, - dateTimeString, - _intString, - uriString, -]; +final _instances = [bigIntString, dateTimeString, _intString, uriString]; ToFromStringHelper? _forType(DartType type) => _instances.where((i) => i.matches(type)).singleOrNull; @@ -176,12 +173,12 @@ void _checkSafeKeyType(String expression, DartType keyArg) { /// Used in [_checkSafeKeyType] to provide a helpful error with unsupported /// types. List<String> get allowedMapKeyTypes => [ - 'Object', - 'dynamic', - 'enum', - 'String', - ..._instances.map((i) => i.coreTypeName) - ]; + 'Object', + 'dynamic', + 'enum', + 'String', + ..._instances.map((i) => i.coreTypeName), +]; extension on DartType { bool get isSimpleJsonTypeNotDouble => diff --git a/json_serializable/lib/src/type_helpers/record_helper.dart b/json_serializable/lib/src/type_helpers/record_helper.dart index 42b13025e..8d0fab4df 100644 --- a/json_serializable/lib/src/type_helpers/record_helper.dart +++ b/json_serializable/lib/src/type_helpers/record_helper.dart @@ -23,9 +23,7 @@ class RecordHelper extends TypeHelper<TypeHelperContextWithConfig> { var index = 1; for (var field in targetType.positionalFields) { final indexer = escapeDartString('\$$index'); - items.add( - context.deserialize(field.type, '$paramName[$indexer]')!, - ); + items.add(context.deserialize(field.type, '$paramName[$indexer]')!); index++; } for (var field in targetType.namedFields) { @@ -42,7 +40,9 @@ class RecordHelper extends TypeHelper<TypeHelperContextWithConfig> { context.addMember( _recordConvertImpl( - nullable: targetType.isNullableType, anyMap: context.config.anyMap), + nullable: targetType.isNullableType, + anyMap: context.config.anyMap, + ), ); final recordLiteral = '(${items.map((e) => '$e,').join()})'; @@ -82,22 +82,17 @@ $helperName( } for (var field in targetType.namedFields) { final indexer = escapeDartString(field.name); - items.add( - '$indexer:${context.serialize( - field.type, - '$expression$maybeBang.${field.name}', - )!}', - ); + final key = context.serialize( + field.type, + '$expression$maybeBang.${field.name}', + )!; + items.add('$indexer:$key'); } final mapValue = '<String, dynamic>{${items.map((e) => '$e,').join()}}'; return targetType.isNullableType - ? ifNullOrElse( - expression, - 'null', - mapValue, - ) + ? ifNullOrElse(expression, 'null', mapValue) : mapValue; } } diff --git a/json_serializable/lib/src/type_helpers/to_from_string.dart b/json_serializable/lib/src/type_helpers/to_from_string.dart index 5c6174ad0..cb9a30d71 100644 --- a/json_serializable/lib/src/type_helpers/to_from_string.dart +++ b/json_serializable/lib/src/type_helpers/to_from_string.dart @@ -7,11 +7,7 @@ import 'package:source_gen/source_gen.dart'; import '../default_container.dart'; -final bigIntString = ToFromStringHelper( - 'BigInt.parse', - 'toString()', - 'BigInt', -); +final bigIntString = ToFromStringHelper('BigInt.parse', 'toString()', 'BigInt'); final dateTimeString = ToFromStringHelper( 'DateTime.parse', @@ -19,11 +15,7 @@ final dateTimeString = ToFromStringHelper( 'DateTime', ); -final uriString = ToFromStringHelper( - 'Uri.parse', - 'toString()', - 'Uri', -); +final uriString = ToFromStringHelper('Uri.parse', 'toString()', 'Uri'); /// Package-internal helper that unifies implementations of [Type]s that convert /// trivially to-from [String]. @@ -44,15 +36,11 @@ class ToFromStringHelper { final TypeChecker _checker; ToFromStringHelper(this._parse, this._toString, this.coreTypeName) - : _checker = TypeChecker.fromUrl('dart:core#$coreTypeName'); + : _checker = TypeChecker.fromUrl('dart:core#$coreTypeName'); bool matches(DartType type) => _checker.isExactlyType(type); - String? serialize( - DartType type, - String expression, - bool nullable, - ) { + String? serialize(DartType type, String expression, bool nullable) { if (!matches(type)) { return null; } @@ -78,9 +66,6 @@ class ToFromStringHelper { final output = '$_parse($parseParam)'; - return DefaultContainer( - expression, - output, - ); + return DefaultContainer(expression, output); } } diff --git a/json_serializable/lib/src/type_helpers/uri_helper.dart b/json_serializable/lib/src/type_helpers/uri_helper.dart index 49dea856a..6c482f21e 100644 --- a/json_serializable/lib/src/type_helpers/uri_helper.dart +++ b/json_serializable/lib/src/type_helpers/uri_helper.dart @@ -17,12 +17,7 @@ class UriHelper extends TypeHelper { DartType targetType, String expression, TypeHelperContext context, - ) => - uriString.serialize( - targetType, - expression, - targetType.isNullableType, - ); + ) => uriString.serialize(targetType, expression, targetType.isNullableType); @override DefaultContainer? deserialize( @@ -30,7 +25,10 @@ class UriHelper extends TypeHelper { String expression, TypeHelperContext context, bool defaultProvided, - ) => - uriString.deserialize( - targetType, expression, targetType.isNullableType, false); + ) => uriString.deserialize( + targetType, + expression, + targetType.isNullableType, + false, + ); } diff --git a/json_serializable/lib/src/type_helpers/value_helper.dart b/json_serializable/lib/src/type_helpers/value_helper.dart index d9f8411db..0ed4d1923 100644 --- a/json_serializable/lib/src/type_helpers/value_helper.dart +++ b/json_serializable/lib/src/type_helpers/value_helper.dart @@ -34,7 +34,9 @@ class ValueHelper extends TypeHelper { String expression, TypeHelperContext context, bool defaultProvided, - ) => - defaultDecodeLogic(targetType, expression, - defaultProvided: defaultProvided); + ) => defaultDecodeLogic( + targetType, + expression, + defaultProvided: defaultProvided, + ); } diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index 4d346b41e..9f1d34bc7 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -35,42 +35,37 @@ Never throwUnsupported(FieldElement element, String message) => T? readEnum<T extends Enum>(ConstantReader reader, List<T> values) => reader.isNull - ? null - : enumValueForDartObject<T>( - reader.objectValue, - values, - (f) => f.name, - ); + ? null + : enumValueForDartObject<T>(reader.objectValue, values, (f) => f.name); T enumValueForDartObject<T>( DartObject source, List<T> items, String Function(T) name, -) => - items[source.getField('index')!.toIntValue()!]; +) => items[source.getField('index')!.toIntValue()!]; /// Return an instance of [JsonSerializable] corresponding to the provided /// [reader]. // #CHANGE WHEN UPDATING json_annotation JsonSerializable _valueForAnnotation(ConstantReader reader) => JsonSerializable( - anyMap: reader.read('anyMap').literalValue as bool?, - checked: reader.read('checked').literalValue as bool?, - constructor: reader.read('constructor').literalValue as String?, - createFactory: reader.read('createFactory').literalValue as bool?, - createToJson: reader.read('createToJson').literalValue as bool?, - createFieldMap: reader.read('createFieldMap').literalValue as bool?, - createJsonKeys: reader.read('createJsonKeys').literalValue as bool?, - createPerFieldToJson: - reader.read('createPerFieldToJson').literalValue as bool?, - disallowUnrecognizedKeys: - reader.read('disallowUnrecognizedKeys').literalValue as bool?, - explicitToJson: reader.read('explicitToJson').literalValue as bool?, - fieldRename: readEnum(reader.read('fieldRename'), FieldRename.values), - genericArgumentFactories: - reader.read('genericArgumentFactories').literalValue as bool?, - ignoreUnannotated: reader.read('ignoreUnannotated').literalValue as bool?, - includeIfNull: reader.read('includeIfNull').literalValue as bool?, - ); + anyMap: reader.read('anyMap').literalValue as bool?, + checked: reader.read('checked').literalValue as bool?, + constructor: reader.read('constructor').literalValue as String?, + createFactory: reader.read('createFactory').literalValue as bool?, + createToJson: reader.read('createToJson').literalValue as bool?, + createFieldMap: reader.read('createFieldMap').literalValue as bool?, + createJsonKeys: reader.read('createJsonKeys').literalValue as bool?, + createPerFieldToJson: + reader.read('createPerFieldToJson').literalValue as bool?, + disallowUnrecognizedKeys: + reader.read('disallowUnrecognizedKeys').literalValue as bool?, + explicitToJson: reader.read('explicitToJson').literalValue as bool?, + fieldRename: readEnum(reader.read('fieldRename'), FieldRename.values), + genericArgumentFactories: + reader.read('genericArgumentFactories').literalValue as bool?, + ignoreUnannotated: reader.read('ignoreUnannotated').literalValue as bool?, + includeIfNull: reader.read('includeIfNull').literalValue as bool?, +); /// Returns a [ClassConfig] with values from the [JsonSerializable] /// instance represented by [reader]. @@ -90,14 +85,18 @@ ClassConfig mergeConfig( assert(config.ctorParamDefaults.isEmpty); final constructor = annotation.constructor ?? config.constructor; - final constructorInstance = - _constructorByNameOrNull(classElement, constructor); + final constructorInstance = _constructorByNameOrNull( + classElement, + constructor, + ); final paramDefaultValueMap = constructorInstance == null ? <String, String>{} - : Map<String, String>.fromEntries(constructorInstance.parameters - .where((element) => element.hasDefaultValue) - .map((e) => MapEntry(e.name, e.defaultValueCode!))); + : Map<String, String>.fromEntries( + constructorInstance.parameters + .where((element) => element.hasDefaultValue) + .map((e) => MapEntry(e.name, e.defaultValueCode!)), + ); final converters = reader.read('converters'); @@ -115,7 +114,8 @@ ClassConfig mergeConfig( annotation.disallowUnrecognizedKeys ?? config.disallowUnrecognizedKeys, explicitToJson: annotation.explicitToJson ?? config.explicitToJson, fieldRename: annotation.fieldRename ?? config.fieldRename, - genericArgumentFactories: annotation.genericArgumentFactories ?? + genericArgumentFactories: + annotation.genericArgumentFactories ?? (classElement.typeParameters.isNotEmpty && config.genericArgumentFactories), ignoreUnannotated: annotation.ignoreUnannotated ?? config.ignoreUnannotated, @@ -187,16 +187,13 @@ extension DartTypeExtension on DartType { String ifNullOrElse(String test, String ifNull, String ifNotNull) => '$test == null ? $ifNull : $ifNotNull'; -String encodedFieldName( - FieldRename fieldRename, - String declaredName, -) => +String encodedFieldName(FieldRename fieldRename, String declaredName) => switch (fieldRename) { FieldRename.none => declaredName, FieldRename.snake => declaredName.snake, FieldRename.screamingSnake => declaredName.snake.toUpperCase(), FieldRename.kebab => declaredName.kebab, - FieldRename.pascal => declaredName.pascal + FieldRename.pascal => declaredName.pascal, }; /// Return the Dart code presentation for the given [type]. @@ -205,10 +202,7 @@ String encodedFieldName( /// types and locations of these files in code. Specifically, it supports /// only [InterfaceType]s, with optional type arguments that are also should /// be [InterfaceType]s. -String typeToCode( - DartType type, { - bool forceNullable = false, -}) { +String typeToCode(DartType type, {bool forceNullable = false}) { if (type is DynamicType) { return 'dynamic'; } else if (type is InterfaceType) { @@ -273,8 +267,6 @@ extension ExecutableElementExtension on ExecutableElement { return '${enclosingElement3.name}.$name'; } - throw UnsupportedError( - 'Not sure how to support typeof $runtimeType', - ); + throw UnsupportedError('Not sure how to support typeof $runtimeType'); } } diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 10e7ec8aa..ec6022f17 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -5,7 +5,7 @@ description: >- Dart classes. repository: https://github.com/google/json_serializable.dart/tree/master/json_serializable environment: - sdk: ^3.6.0 + sdk: ^3.8.0 topics: - json - build-runner diff --git a/json_serializable/test/annotation_version_test.dart b/json_serializable/test/annotation_version_test.dart index 607634ee1..7084abd28 100644 --- a/json_serializable/test/annotation_version_test.dart +++ b/json_serializable/test/annotation_version_test.dart @@ -36,7 +36,8 @@ void main() { await _structurePackage( environment: const {'sdk': '^$sdkLowerBound'}, dependencies: {'json_annotation': _annotationLowerBound}, - message: ''' + message: + ''' The language version ($sdkLowerBound) of this package ($_testPkgName) does not match the required range `$supportedLanguageConstraint`. Edit pubspec.yaml to include an SDK constraint of at least $supportedLanguageConstraint. @@ -58,9 +59,7 @@ environment: test( 'missing dependency in production code', - () => _structurePackage( - message: _missingProductionDep, - ), + () => _structurePackage(message: _missingProductionDep), ); test( @@ -126,7 +125,7 @@ String _fixPath(String path) { final _jsonSerialPathDependencyOverrides = { for (var entry in _jsonSerialPubspec.dependencyOverrides.entries) if (entry.value is PathDependency) - entry.key: {'path': _fixPath((entry.value as PathDependency).path)} + entry.key: {'path': _fixPath((entry.value as PathDependency).path)}, }; final _annotationLowerBound = requiredJsonAnnotationMinVersion.toString(); @@ -145,53 +144,42 @@ Future<void> _structurePackage({ Map<String, dynamic> dependencies = const {}, Map<String, dynamic> devDependencies = const {}, }) async { - final pubspec = loudEncode( - { - 'name': _testPkgName, - 'environment': environment, - 'dependencies': dependencies, - 'dev_dependencies': { - ...devDependencies, - 'build_runner': 'any', - 'json_serializable': {'path': p.current}, - }, - 'dependency_overrides': _jsonSerialPathDependencyOverrides, + final pubspec = loudEncode({ + 'name': _testPkgName, + 'environment': environment, + 'dependencies': dependencies, + 'dev_dependencies': { + ...devDependencies, + 'build_runner': 'any', + 'json_serializable': {'path': p.current}, }, - ); + 'dependency_overrides': _jsonSerialPathDependencyOverrides, + }); await d.file('pubspec.yaml', pubspec).create(); /// A file in the lib directory without JsonSerializable should do nothing! - await d.dir( - 'lib', - [ - d.file('no_op.dart', ''' + await d.dir('lib', [ + d.file('no_op.dart', ''' class NoOp {} -''') - ], - ).create(); - - await d.dir( - sourceDirectory, - [ - d.file( - 'sample.dart', - ''' +'''), + ]).create(); + + await d.dir(sourceDirectory, [ + d.file('sample.dart', ''' import 'package:json_annotation/json_annotation.dart'; part 'sample.g.dart'; @JsonSerializable() class SomeClass{} -''', - ) - ], - ).create(); - final proc = await TestProcess.start( - Platform.resolvedExecutable, - ['run', 'build_runner', 'build'], - workingDirectory: d.sandbox, - ); +'''), + ]).create(); + final proc = await TestProcess.start(Platform.resolvedExecutable, [ + 'run', + 'build_runner', + 'build', + ], workingDirectory: d.sandbox); final lines = StringBuffer(); await for (var line in proc.stdoutStream()) { @@ -211,9 +199,12 @@ class SomeClass{} ); if (message != null) { - expect(output, contains(''' + expect( + output, + contains(''' [WARNING] json_serializable on $sourceDirectory/sample.dart: -$message''')); +$message'''), + ); } await proc.shouldExit(0); diff --git a/json_serializable/test/config_test.dart b/json_serializable/test/config_test.dart index 318697f54..b29ffac12 100644 --- a/json_serializable/test/config_test.dart +++ b/json_serializable/test/config_test.dart @@ -18,8 +18,10 @@ import 'shared_config.dart'; void main() { test('fields in JsonSerializable are sorted', () { - expect(generatorConfigDefaultJson.keys, - orderedEquals(generatorConfigDefaultJson.keys.toList()..sort())); + expect( + generatorConfigDefaultJson.keys, + orderedEquals(generatorConfigDefaultJson.keys.toList()..sort()), + ); }); test('empty', () async { @@ -28,29 +30,36 @@ void main() { }); test('valid default config', () async { - final builder = - jsonSerializable(BuilderOptions(generatorConfigDefaultJson)); + final builder = jsonSerializable( + BuilderOptions(generatorConfigDefaultJson), + ); expect(builder, isNotNull); }); test('valid, non-default config', () { - expect(generatorConfigNonDefaultJson.keys, - unorderedEquals(generatorConfigDefaultJson.keys)); + expect( + generatorConfigNonDefaultJson.keys, + unorderedEquals(generatorConfigDefaultJson.keys), + ); for (var entry in generatorConfigDefaultJson.entries) { - expect(generatorConfigNonDefaultJson, - containsPair(entry.key, isNot(entry.value)), - reason: 'should have values that are different than the defaults'); + expect( + generatorConfigNonDefaultJson, + containsPair(entry.key, isNot(entry.value)), + reason: 'should have values that are different than the defaults', + ); } - final builder = - jsonSerializable(BuilderOptions(generatorConfigNonDefaultJson)); + final builder = jsonSerializable( + BuilderOptions(generatorConfigNonDefaultJson), + ); expect(builder, isNotNull); }); test('config is null-protected when passed to JsonSerializableGenerator', () { final nullValueMap = Map.fromEntries( - generatorConfigDefaultJson.entries.map((e) => MapEntry(e.key, null))); + generatorConfigDefaultJson.entries.map((e) => MapEntry(e.key, null)), + ); final config = JsonSerializable.fromJson(nullValueMap); final generator = JsonSerializableGenerator(config: config); expect(generator.config.toJson(), generatorConfigDefaultJson); @@ -71,7 +80,7 @@ void main() { r'$default', 'builders', 'json_serializable', - 'options' + 'options', ]) { yaml = yaml[key] as YamlMap; } @@ -81,7 +90,8 @@ void main() { expect( configMap.keys, unorderedEquals(generatorConfigDefaultJson.keys), - reason: 'All supported keys are documented. ' + reason: + 'All supported keys are documented. ' 'Did you forget to change README.md?', ); @@ -104,8 +114,9 @@ void main() { ); expect( - () => jsonSerializable(const BuilderOptions({'unsupported': 'config'})), - throwsA(matcher)); + () => jsonSerializable(const BuilderOptions({'unsupported': 'config'})), + throwsA(matcher), + ); }); group('invalid config', () { @@ -128,7 +139,7 @@ void main() { 'create_to_json' => "type 'int' is not a subtype of type 'bool?' in type " 'cast', - _ => "type 'int' is not a subtype of type 'bool?' in type cast" + _ => "type 'int' is not a subtype of type 'bool?' in type cast", }; final matcher = isA<StateError>().having( @@ -140,7 +151,9 @@ There is a problem with "${entry.key}". $lastLine''', ); expect( - () => jsonSerializable(BuilderOptions(config)), throwsA(matcher)); + () => jsonSerializable(BuilderOptions(config)), + throwsA(matcher), + ); }); } }); diff --git a/json_serializable/test/custom_configuration_test.dart b/json_serializable/test/custom_configuration_test.dart index 1c96f0925..4b70d8c9a 100644 --- a/json_serializable/test/custom_configuration_test.dart +++ b/json_serializable/test/custom_configuration_test.dart @@ -39,12 +39,17 @@ Future<void> main() async { group('configuration', () { Future<void> runWithConfigAndLogger( - JsonSerializable? config, String className) async { + JsonSerializable? config, + String className, + ) async { await generateForElement( - JsonSerializableGenerator( - config: config, typeHelpers: const [_ConfigLogger()]), - _libraryReader, - className); + JsonSerializableGenerator( + config: config, + typeHelpers: const [_ConfigLogger()], + ), + _libraryReader, + className, + ); } setUp(_ConfigLogger.configurations.clear); @@ -60,46 +65,59 @@ Future<void> main() async { test(testDescription, () async { await runWithConfigAndLogger( - nullConfig ? null : const JsonSerializable(), className); + nullConfig ? null : const JsonSerializable(), + className, + ); expect(_ConfigLogger.configurations, hasLength(2)); expect( _ConfigLogger.configurations.first.toJson(), _ConfigLogger.configurations.last.toJson(), ); - expect(_ConfigLogger.configurations.first.toJson(), - generatorConfigDefaultJson); + expect( + _ConfigLogger.configurations.first.toJson(), + generatorConfigDefaultJson, + ); }); } } }); test( - 'values in config override unconfigured (default) values in annotation', - () async { - await runWithConfigAndLogger( + 'values in config override unconfigured (default) values in annotation', + () async { + await runWithConfigAndLogger( JsonSerializable.fromJson(generatorConfigNonDefaultJson), - 'ConfigurationImplicitDefaults'); + 'ConfigurationImplicitDefaults', + ); - expect(_ConfigLogger.configurations, isEmpty, - reason: 'all generation is disabled'); + expect( + _ConfigLogger.configurations, + isEmpty, + reason: 'all generation is disabled', + ); - // Create a configuration with just `create_to_json` set to true so we - // can validate the configuration that is run with - final configMap = - Map<String, dynamic>.from(generatorConfigNonDefaultJson); - configMap['create_to_json'] = true; + // Create a configuration with just `create_to_json` set to true so we + // can validate the configuration that is run with + final configMap = Map<String, dynamic>.from( + generatorConfigNonDefaultJson, + ); + configMap['create_to_json'] = true; - await runWithConfigAndLogger(JsonSerializable.fromJson(configMap), - 'ConfigurationImplicitDefaults'); - }); + await runWithConfigAndLogger( + JsonSerializable.fromJson(configMap), + 'ConfigurationImplicitDefaults', + ); + }, + ); test( 'explicit values in annotation override corresponding settings in config', () async { await runWithConfigAndLogger( - JsonSerializable.fromJson(generatorConfigNonDefaultJson), - 'ConfigurationExplicitDefaults'); + JsonSerializable.fromJson(generatorConfigNonDefaultJson), + 'ConfigurationExplicitDefaults', + ); expect(_ConfigLogger.configurations, hasLength(2)); expect( @@ -110,8 +128,9 @@ Future<void> main() async { // The effective configuration should be non-Default configuration, but // with all fields set from JsonSerializable as the defaults - final expected = - Map<String, dynamic>.from(generatorConfigNonDefaultJson); + final expected = Map<String, dynamic>.from( + generatorConfigNonDefaultJson, + ); for (var jsonSerialKey in jsonSerializableFields) { expected[jsonSerialKey] = generatorConfigDefaultJson[jsonSerialKey]; } @@ -138,7 +157,9 @@ void _registerTests(JsonSerializable generator) { group('explicit toJson', () { test('nullable', () async { final output = await _runForElementNamed( - const JsonSerializable(), 'TrivialNestedNullable'); + const JsonSerializable(), + 'TrivialNestedNullable', + ); const expected = r''' Map<String, dynamic> _$TrivialNestedNullableToJson( @@ -153,7 +174,9 @@ Map<String, dynamic> _$TrivialNestedNullableToJson( }); test('non-nullable', () async { final output = await _runForElementNamed( - const JsonSerializable(), 'TrivialNestedNonNullable'); + const JsonSerializable(), + 'TrivialNestedNonNullable', + ); const expected = r''' Map<String, dynamic> _$TrivialNestedNonNullableToJson( @@ -169,25 +192,32 @@ Map<String, dynamic> _$TrivialNestedNonNullableToJson( }); group('valid inputs', () { - test('class with fromJson() constructor with optional parameters', - () async { - final output = await runForElementNamed('FromJsonOptionalParameters'); + test( + 'class with fromJson() constructor with optional parameters', + () async { + final output = await runForElementNamed('FromJsonOptionalParameters'); - expect(output, contains('ChildWithFromJson.fromJson')); - }); + expect(output, contains('ChildWithFromJson.fromJson')); + }, + ); test('class with child json-able object', () async { final output = await runForElementNamed('ParentObject'); expect( - output, - contains("ChildObject.fromJson(json['child'] " - 'as Map<String, dynamic>)')); + output, + contains( + "ChildObject.fromJson(json['child'] " + 'as Map<String, dynamic>)', + ), + ); }); test('class with child json-able object - anyMap', () async { final output = await _runForElementNamed( - const JsonSerializable(anyMap: true), 'ParentObject'); + const JsonSerializable(anyMap: true), + 'ParentObject', + ); expect(output, contains("ChildObject.fromJson(json['child'] as Map)")); }); @@ -200,8 +230,9 @@ Map<String, dynamic> _$TrivialNestedNonNullableToJson( }); test('class with child list of dynamic objects is left alone', () async { - final output = - await runForElementNamed('ParentObjectWithDynamicChildren'); + final output = await runForElementNamed( + 'ParentObjectWithDynamicChildren', + ); expect( output, @@ -235,8 +266,11 @@ class _ConfigLogger implements TypeHelper<TypeHelperContextWithConfig> { } @override - Object? serialize(DartType targetType, String expression, - TypeHelperContextWithConfig context) { + Object? serialize( + DartType targetType, + String expression, + TypeHelperContextWithConfig context, + ) { configurations.add(context.config.toJsonSerializable()); return null; } diff --git a/json_serializable/test/default_value/default_value.dart b/json_serializable/test/default_value/default_value.dart index 0894af857..3fff09ab0 100644 --- a/json_serializable/test/default_value/default_value.dart +++ b/json_serializable/test/default_value/default_value.dart @@ -55,9 +55,11 @@ class DefaultValue implements dvi.DefaultValue { @JsonKey(defaultValue: {'answer': 42}) Map<String, int> fieldMapSimple; - @JsonKey(defaultValue: { - 'root': ['child'] - }) + @JsonKey( + defaultValue: { + 'root': ['child'], + }, + ) Map<String, List<String>> fieldMapListString; Duration durationField; diff --git a/json_serializable/test/default_value/default_value.g.dart b/json_serializable/test/default_value/default_value.g.dart index 6bc4525d5..af6395178 100644 --- a/json_serializable/test/default_value/default_value.g.dart +++ b/json_serializable/test/default_value/default_value.g.dart @@ -9,62 +9,62 @@ part of 'default_value.dart'; // ************************************************************************** DefaultValue _$DefaultValueFromJson(Map<String, dynamic> json) => DefaultValue( - json['fieldBool'] as bool? ?? true, - json['fieldString'] as String? ?? 'string', - (json['fieldInt'] as num?)?.toInt() ?? 42, - (json['fieldDouble'] as num?)?.toDouble() ?? 3.14, - json['fieldListEmpty'] as List<dynamic>? ?? [], - (json['fieldSetEmpty'] as List<dynamic>?)?.toSet() ?? {}, - json['fieldMapEmpty'] as Map<String, dynamic>? ?? {}, - (json['fieldListSimple'] as List<dynamic>?) - ?.map((e) => (e as num).toInt()) - .toList() ?? - [1, 2, 3], - (json['fieldSetSimple'] as List<dynamic>?) - ?.map((e) => e as String) - .toSet() ?? - {'entry1', 'entry2'}, - (json['fieldMapSimple'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, (e as num).toInt()), - ) ?? - {'answer': 42}, - (json['fieldMapListString'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry( - k, (e as List<dynamic>).map((e) => e as String).toList()), - ) ?? - { - 'root': ['child'] - }, - $enumDecodeNullable(_$GreekEnumMap, json['fieldEnum']) ?? Greek.beta, - durationField: json['durationField'] == null - ? Duration.zero - : Duration(microseconds: (json['durationField'] as num).toInt()), - constClass: json['constClass'] == null - ? const ConstClass('value') - : ConstClass.fromJson(json['constClass'] as Map<String, dynamic>), - valueFromConverter: json['valueFromConverter'] == null - ? const ConstClass('value') - : const ConstClassConverter() - .fromJson(json['valueFromConverter'] as String), - valueFromFunction: json['valueFromFunction'] == null - ? const ConstClass('value') - : constClassFromJson(json['valueFromFunction'] as String), - intDefaultValueFromFunction: - (json['intDefaultValueFromFunction'] as num?)?.toInt() ?? - intDefaultValueFunction(), - valueFromDefaultValueDefaultConstructor: - json['valueFromDefaultValueDefaultConstructor'] == null - ? const ConstClass() - : ConstClass.fromJson( - json['valueFromDefaultValueDefaultConstructor'] - as Map<String, dynamic>), - valueFromDefaultValueNamedConstructor: - json['valueFromDefaultValueNamedConstructor'] == null - ? ConstClass.easy() - : ConstClass.fromJson( - json['valueFromDefaultValueNamedConstructor'] - as Map<String, dynamic>), - ); + json['fieldBool'] as bool? ?? true, + json['fieldString'] as String? ?? 'string', + (json['fieldInt'] as num?)?.toInt() ?? 42, + (json['fieldDouble'] as num?)?.toDouble() ?? 3.14, + json['fieldListEmpty'] as List<dynamic>? ?? [], + (json['fieldSetEmpty'] as List<dynamic>?)?.toSet() ?? {}, + json['fieldMapEmpty'] as Map<String, dynamic>? ?? {}, + (json['fieldListSimple'] as List<dynamic>?) + ?.map((e) => (e as num).toInt()) + .toList() ?? + [1, 2, 3], + (json['fieldSetSimple'] as List<dynamic>?)?.map((e) => e as String).toSet() ?? + {'entry1', 'entry2'}, + (json['fieldMapSimple'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, (e as num).toInt()), + ) ?? + {'answer': 42}, + (json['fieldMapListString'] as Map<String, dynamic>?)?.map( + (k, e) => + MapEntry(k, (e as List<dynamic>).map((e) => e as String).toList()), + ) ?? + { + 'root': ['child'], + }, + $enumDecodeNullable(_$GreekEnumMap, json['fieldEnum']) ?? Greek.beta, + durationField: json['durationField'] == null + ? Duration.zero + : Duration(microseconds: (json['durationField'] as num).toInt()), + constClass: json['constClass'] == null + ? const ConstClass('value') + : ConstClass.fromJson(json['constClass'] as Map<String, dynamic>), + valueFromConverter: json['valueFromConverter'] == null + ? const ConstClass('value') + : const ConstClassConverter().fromJson( + json['valueFromConverter'] as String, + ), + valueFromFunction: json['valueFromFunction'] == null + ? const ConstClass('value') + : constClassFromJson(json['valueFromFunction'] as String), + intDefaultValueFromFunction: + (json['intDefaultValueFromFunction'] as num?)?.toInt() ?? + intDefaultValueFunction(), + valueFromDefaultValueDefaultConstructor: + json['valueFromDefaultValueDefaultConstructor'] == null + ? const ConstClass() + : ConstClass.fromJson( + json['valueFromDefaultValueDefaultConstructor'] + as Map<String, dynamic>, + ), + valueFromDefaultValueNamedConstructor: + json['valueFromDefaultValueNamedConstructor'] == null + ? ConstClass.easy() + : ConstClass.fromJson( + json['valueFromDefaultValueNamedConstructor'] as Map<String, dynamic>, + ), +); Map<String, dynamic> _$DefaultValueToJson(DefaultValue instance) => <String, dynamic>{ @@ -82,8 +82,9 @@ Map<String, dynamic> _$DefaultValueToJson(DefaultValue instance) => 'durationField': instance.durationField.inMicroseconds, 'fieldEnum': _$GreekEnumMap[instance.fieldEnum]!, 'constClass': instance.constClass, - 'valueFromConverter': - const ConstClassConverter().toJson(instance.valueFromConverter), + 'valueFromConverter': const ConstClassConverter().toJson( + instance.valueFromConverter, + ), 'valueFromFunction': constClassToJson(instance.valueFromFunction), 'intDefaultValueFromFunction': instance.intDefaultValueFromFunction, 'valueFromDefaultValueDefaultConstructor': diff --git a/json_serializable/test/default_value/default_value.g_any_map__checked.dart b/json_serializable/test/default_value/default_value.g_any_map__checked.dart index be46b0133..40e559936 100644 --- a/json_serializable/test/default_value/default_value.g_any_map__checked.dart +++ b/json_serializable/test/default_value/default_value.g_any_map__checked.dart @@ -23,10 +23,7 @@ const _intValue = 42; dvi.DefaultValue fromJson(Map<String, dynamic> json) => _$DefaultValueFromJson(json); -@JsonSerializable( - checked: true, - anyMap: true, -) +@JsonSerializable(checked: true, anyMap: true) class DefaultValue implements dvi.DefaultValue { @JsonKey(defaultValue: true) bool fieldBool; @@ -58,9 +55,11 @@ class DefaultValue implements dvi.DefaultValue { @JsonKey(defaultValue: {'answer': 42}) Map<String, int> fieldMapSimple; - @JsonKey(defaultValue: { - 'root': ['child'] - }) + @JsonKey( + defaultValue: { + 'root': ['child'], + }, + ) Map<String, List<String>> fieldMapListString; Duration durationField; diff --git a/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart b/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart index 9ce12321f..0462bd167 100644 --- a/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart +++ b/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart @@ -8,88 +8,99 @@ part of 'default_value.g_any_map__checked.dart'; // JsonSerializableGenerator // ************************************************************************** -DefaultValue _$DefaultValueFromJson(Map json) => $checkedCreate( - 'DefaultValue', - json, - ($checkedConvert) { - final val = DefaultValue( - $checkedConvert('fieldBool', (v) => v as bool? ?? true), - $checkedConvert('fieldString', (v) => v as String? ?? 'string'), - $checkedConvert('fieldInt', (v) => (v as num?)?.toInt() ?? 42), - $checkedConvert( - 'fieldDouble', (v) => (v as num?)?.toDouble() ?? 3.14), - $checkedConvert('fieldListEmpty', (v) => v as List<dynamic>? ?? []), - $checkedConvert( - 'fieldSetEmpty', (v) => (v as List<dynamic>?)?.toSet() ?? {}), - $checkedConvert('fieldMapEmpty', (v) => v as Map? ?? {}), - $checkedConvert( - 'fieldListSimple', - (v) => - (v as List<dynamic>?) - ?.map((e) => (e as num).toInt()) - .toList() ?? - [1, 2, 3]), - $checkedConvert( - 'fieldSetSimple', - (v) => - (v as List<dynamic>?)?.map((e) => e as String).toSet() ?? - {'entry1', 'entry2'}), - $checkedConvert( - 'fieldMapSimple', - (v) => - (v as Map?)?.map( - (k, e) => MapEntry(k as String, (e as num).toInt()), - ) ?? - {'answer': 42}), - $checkedConvert( - 'fieldMapListString', - (v) => - (v as Map?)?.map( - (k, e) => MapEntry(k as String, - (e as List<dynamic>).map((e) => e as String).toList()), - ) ?? - { - 'root': ['child'] - }), - $checkedConvert('fieldEnum', - (v) => $enumDecodeNullable(_$GreekEnumMap, v) ?? Greek.beta), - durationField: $checkedConvert( - 'durationField', - (v) => v == null - ? Duration.zero - : Duration(microseconds: (v as num).toInt())), - constClass: $checkedConvert( - 'constClass', - (v) => v == null - ? const ConstClass('value') - : ConstClass.fromJson(Map<String, dynamic>.from(v as Map))), - valueFromConverter: $checkedConvert( - 'valueFromConverter', - (v) => v == null - ? const ConstClass('value') - : const ConstClassConverter().fromJson(v as String)), - valueFromFunction: $checkedConvert( - 'valueFromFunction', - (v) => v == null - ? const ConstClass('value') - : constClassFromJson(v as String)), - intDefaultValueFromFunction: $checkedConvert( - 'intDefaultValueFromFunction', - (v) => (v as num?)?.toInt() ?? intDefaultValueFunction()), - valueFromDefaultValueDefaultConstructor: $checkedConvert( - 'valueFromDefaultValueDefaultConstructor', - (v) => v == null - ? const ConstClass() - : ConstClass.fromJson(Map<String, dynamic>.from(v as Map))), - valueFromDefaultValueNamedConstructor: $checkedConvert( - 'valueFromDefaultValueNamedConstructor', - (v) => v == null - ? ConstClass.easy() - : ConstClass.fromJson(Map<String, dynamic>.from(v as Map))), - ); - return val; - }, - ); +DefaultValue _$DefaultValueFromJson(Map json) => + $checkedCreate('DefaultValue', json, ($checkedConvert) { + final val = DefaultValue( + $checkedConvert('fieldBool', (v) => v as bool? ?? true), + $checkedConvert('fieldString', (v) => v as String? ?? 'string'), + $checkedConvert('fieldInt', (v) => (v as num?)?.toInt() ?? 42), + $checkedConvert('fieldDouble', (v) => (v as num?)?.toDouble() ?? 3.14), + $checkedConvert('fieldListEmpty', (v) => v as List<dynamic>? ?? []), + $checkedConvert( + 'fieldSetEmpty', + (v) => (v as List<dynamic>?)?.toSet() ?? {}, + ), + $checkedConvert('fieldMapEmpty', (v) => v as Map? ?? {}), + $checkedConvert( + 'fieldListSimple', + (v) => + (v as List<dynamic>?)?.map((e) => (e as num).toInt()).toList() ?? + [1, 2, 3], + ), + $checkedConvert( + 'fieldSetSimple', + (v) => + (v as List<dynamic>?)?.map((e) => e as String).toSet() ?? + {'entry1', 'entry2'}, + ), + $checkedConvert( + 'fieldMapSimple', + (v) => + (v as Map?)?.map( + (k, e) => MapEntry(k as String, (e as num).toInt()), + ) ?? + {'answer': 42}, + ), + $checkedConvert( + 'fieldMapListString', + (v) => + (v as Map?)?.map( + (k, e) => MapEntry( + k as String, + (e as List<dynamic>).map((e) => e as String).toList(), + ), + ) ?? + { + 'root': ['child'], + }, + ), + $checkedConvert( + 'fieldEnum', + (v) => $enumDecodeNullable(_$GreekEnumMap, v) ?? Greek.beta, + ), + durationField: $checkedConvert( + 'durationField', + (v) => v == null + ? Duration.zero + : Duration(microseconds: (v as num).toInt()), + ), + constClass: $checkedConvert( + 'constClass', + (v) => v == null + ? const ConstClass('value') + : ConstClass.fromJson(Map<String, dynamic>.from(v as Map)), + ), + valueFromConverter: $checkedConvert( + 'valueFromConverter', + (v) => v == null + ? const ConstClass('value') + : const ConstClassConverter().fromJson(v as String), + ), + valueFromFunction: $checkedConvert( + 'valueFromFunction', + (v) => v == null + ? const ConstClass('value') + : constClassFromJson(v as String), + ), + intDefaultValueFromFunction: $checkedConvert( + 'intDefaultValueFromFunction', + (v) => (v as num?)?.toInt() ?? intDefaultValueFunction(), + ), + valueFromDefaultValueDefaultConstructor: $checkedConvert( + 'valueFromDefaultValueDefaultConstructor', + (v) => v == null + ? const ConstClass() + : ConstClass.fromJson(Map<String, dynamic>.from(v as Map)), + ), + valueFromDefaultValueNamedConstructor: $checkedConvert( + 'valueFromDefaultValueNamedConstructor', + (v) => v == null + ? ConstClass.easy() + : ConstClass.fromJson(Map<String, dynamic>.from(v as Map)), + ), + ); + return val; + }); Map<String, dynamic> _$DefaultValueToJson(DefaultValue instance) => <String, dynamic>{ @@ -107,8 +118,9 @@ Map<String, dynamic> _$DefaultValueToJson(DefaultValue instance) => 'durationField': instance.durationField.inMicroseconds, 'fieldEnum': _$GreekEnumMap[instance.fieldEnum]!, 'constClass': instance.constClass, - 'valueFromConverter': - const ConstClassConverter().toJson(instance.valueFromConverter), + 'valueFromConverter': const ConstClassConverter().toJson( + instance.valueFromConverter, + ), 'valueFromFunction': constClassToJson(instance.valueFromFunction), 'intDefaultValueFromFunction': instance.intDefaultValueFromFunction, 'valueFromDefaultValueDefaultConstructor': diff --git a/json_serializable/test/default_value/default_value_interface.dart b/json_serializable/test/default_value/default_value_interface.dart index 2a2cb1cbc..3fa93ed24 100644 --- a/json_serializable/test/default_value/default_value_interface.dart +++ b/json_serializable/test/default_value/default_value_interface.dart @@ -54,13 +54,10 @@ class ConstClass { ConstClass.easy() : field = 'easy'; - factory ConstClass.fromJson(Map<String, dynamic> json) => ConstClass( - json['field'] as String, - ); + factory ConstClass.fromJson(Map<String, dynamic> json) => + ConstClass(json['field'] as String); - Map<String, dynamic> toJson() => <String, dynamic>{ - 'field': field, - }; + Map<String, dynamic> toJson() => <String, dynamic>{'field': field}; } ConstClass constClassFromJson(String json) => ConstClass(json); diff --git a/json_serializable/test/default_value/default_value_test.dart b/json_serializable/test/default_value/default_value_test.dart index d2d057c28..d53a4fb47 100644 --- a/json_serializable/test/default_value/default_value_test.dart +++ b/json_serializable/test/default_value/default_value_test.dart @@ -22,7 +22,7 @@ const _defaultInstance = { 'fieldSetSimple': ['entry1', 'entry2'], 'fieldMapSimple': <String, dynamic>{'answer': 42}, 'fieldMapListString': { - 'root': ['child'] + 'root': ['child'], }, 'durationField': 0, 'fieldEnum': 'beta', @@ -46,7 +46,7 @@ const _otherValues = { 'fieldSetSimple': ['entry3'], 'fieldMapSimple': <String, dynamic>{}, 'fieldMapListString': { - 'root2': ['alpha'] + 'root2': ['alpha'], }, 'durationField': 1, 'fieldEnum': 'delta', diff --git a/json_serializable/test/default_value/implicit_default_value.dart b/json_serializable/test/default_value/implicit_default_value.dart index 49bf57999..8b7d3def5 100644 --- a/json_serializable/test/default_value/implicit_default_value.dart +++ b/json_serializable/test/default_value/implicit_default_value.dart @@ -64,7 +64,7 @@ class DefaultValueImplicit implements dvi.DefaultValue { this.fieldSetSimple = const {'entry1', 'entry2'}, this.fieldMapSimple = const {'answer': 42}, this.fieldMapListString = const { - 'root': ['child'] + 'root': ['child'], }, this.fieldEnum = Greek.beta, this.durationField = const Duration(), diff --git a/json_serializable/test/default_value/implicit_default_value.g.dart b/json_serializable/test/default_value/implicit_default_value.g.dart index 408c1f0b2..06cb4a462 100644 --- a/json_serializable/test/default_value/implicit_default_value.g.dart +++ b/json_serializable/test/default_value/implicit_default_value.g.dart @@ -9,93 +9,98 @@ part of 'implicit_default_value.dart'; // ************************************************************************** DefaultValueImplicit _$DefaultValueImplicitFromJson( - Map<String, dynamic> json) => - DefaultValueImplicit( - fieldBool: json['fieldBool'] as bool? ?? true, - fieldString: json['fieldString'] as String? ?? 'string', - fieldInt: (json['fieldInt'] as num?)?.toInt() ?? 42, - fieldDouble: (json['fieldDouble'] as num?)?.toDouble() ?? 3.14, - fieldListEmpty: json['fieldListEmpty'] as List<dynamic>? ?? const [], - fieldSetEmpty: - (json['fieldSetEmpty'] as List<dynamic>?)?.toSet() ?? const {}, - fieldMapEmpty: json['fieldMapEmpty'] as Map<String, dynamic>? ?? const {}, - fieldListSimple: (json['fieldListSimple'] as List<dynamic>?) - ?.map((e) => (e as num).toInt()) - .toList() ?? - const [1, 2, 3], - fieldSetSimple: (json['fieldSetSimple'] as List<dynamic>?) - ?.map((e) => e as String) - .toSet() ?? - const {'entry1', 'entry2'}, - fieldMapSimple: (json['fieldMapSimple'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, (e as num).toInt()), - ) ?? - const {'answer': 42}, - fieldMapListString: - (json['fieldMapListString'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry( - k, (e as List<dynamic>).map((e) => e as String).toList()), - ) ?? - const { - 'root': ['child'] - }, - fieldEnum: - $enumDecodeNullable(_$GreekEnumMap, json['fieldEnum']) ?? Greek.beta, - durationField: json['durationField'] == null - ? const Duration() - : Duration(microseconds: (json['durationField'] as num).toInt()), - constClass: json['constClass'] == null - ? const ConstClass('value') - : ConstClass.fromJson(json['constClass'] as Map<String, dynamic>), - valueFromConverter: json['valueFromConverter'] == null - ? const ConstClass('value') - : const ConstClassConverter() - .fromJson(json['valueFromConverter'] as String), - valueFromFunction: json['valueFromFunction'] == null - ? const ConstClass('value') - : constClassFromJson(json['valueFromFunction'] as String), - intDefaultValueFromFunction: - (json['intDefaultValueFromFunction'] as num?)?.toInt() ?? 43, - valueFromDefaultValueDefaultConstructor: - json['valueFromDefaultValueDefaultConstructor'] == null - ? const ConstClass() - : ConstClass.fromJson( - json['valueFromDefaultValueDefaultConstructor'] - as Map<String, dynamic>), - valueFromDefaultValueNamedConstructor: - json['valueFromDefaultValueNamedConstructor'] == null - ? const ConstClass('easy') - : ConstClass.fromJson( - json['valueFromDefaultValueNamedConstructor'] - as Map<String, dynamic>), - ); + Map<String, dynamic> json, +) => DefaultValueImplicit( + fieldBool: json['fieldBool'] as bool? ?? true, + fieldString: json['fieldString'] as String? ?? 'string', + fieldInt: (json['fieldInt'] as num?)?.toInt() ?? 42, + fieldDouble: (json['fieldDouble'] as num?)?.toDouble() ?? 3.14, + fieldListEmpty: json['fieldListEmpty'] as List<dynamic>? ?? const [], + fieldSetEmpty: (json['fieldSetEmpty'] as List<dynamic>?)?.toSet() ?? const {}, + fieldMapEmpty: json['fieldMapEmpty'] as Map<String, dynamic>? ?? const {}, + fieldListSimple: + (json['fieldListSimple'] as List<dynamic>?) + ?.map((e) => (e as num).toInt()) + .toList() ?? + const [1, 2, 3], + fieldSetSimple: + (json['fieldSetSimple'] as List<dynamic>?) + ?.map((e) => e as String) + .toSet() ?? + const {'entry1', 'entry2'}, + fieldMapSimple: + (json['fieldMapSimple'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, (e as num).toInt()), + ) ?? + const {'answer': 42}, + fieldMapListString: + (json['fieldMapListString'] as Map<String, dynamic>?)?.map( + (k, e) => + MapEntry(k, (e as List<dynamic>).map((e) => e as String).toList()), + ) ?? + const { + 'root': ['child'], + }, + fieldEnum: + $enumDecodeNullable(_$GreekEnumMap, json['fieldEnum']) ?? Greek.beta, + durationField: json['durationField'] == null + ? const Duration() + : Duration(microseconds: (json['durationField'] as num).toInt()), + constClass: json['constClass'] == null + ? const ConstClass('value') + : ConstClass.fromJson(json['constClass'] as Map<String, dynamic>), + valueFromConverter: json['valueFromConverter'] == null + ? const ConstClass('value') + : const ConstClassConverter().fromJson( + json['valueFromConverter'] as String, + ), + valueFromFunction: json['valueFromFunction'] == null + ? const ConstClass('value') + : constClassFromJson(json['valueFromFunction'] as String), + intDefaultValueFromFunction: + (json['intDefaultValueFromFunction'] as num?)?.toInt() ?? 43, + valueFromDefaultValueDefaultConstructor: + json['valueFromDefaultValueDefaultConstructor'] == null + ? const ConstClass() + : ConstClass.fromJson( + json['valueFromDefaultValueDefaultConstructor'] + as Map<String, dynamic>, + ), + valueFromDefaultValueNamedConstructor: + json['valueFromDefaultValueNamedConstructor'] == null + ? const ConstClass('easy') + : ConstClass.fromJson( + json['valueFromDefaultValueNamedConstructor'] as Map<String, dynamic>, + ), +); Map<String, dynamic> _$DefaultValueImplicitToJson( - DefaultValueImplicit instance) => - <String, dynamic>{ - 'fieldBool': instance.fieldBool, - 'fieldString': instance.fieldString, - 'fieldInt': instance.fieldInt, - 'fieldDouble': instance.fieldDouble, - 'fieldListEmpty': instance.fieldListEmpty, - 'fieldSetEmpty': instance.fieldSetEmpty.toList(), - 'fieldMapEmpty': instance.fieldMapEmpty, - 'fieldListSimple': instance.fieldListSimple, - 'fieldSetSimple': instance.fieldSetSimple.toList(), - 'fieldMapSimple': instance.fieldMapSimple, - 'fieldMapListString': instance.fieldMapListString, - 'durationField': instance.durationField.inMicroseconds, - 'fieldEnum': _$GreekEnumMap[instance.fieldEnum]!, - 'constClass': instance.constClass, - 'valueFromConverter': - const ConstClassConverter().toJson(instance.valueFromConverter), - 'valueFromFunction': constClassToJson(instance.valueFromFunction), - 'intDefaultValueFromFunction': instance.intDefaultValueFromFunction, - 'valueFromDefaultValueDefaultConstructor': - instance.valueFromDefaultValueDefaultConstructor, - 'valueFromDefaultValueNamedConstructor': - instance.valueFromDefaultValueNamedConstructor, - }; + DefaultValueImplicit instance, +) => <String, dynamic>{ + 'fieldBool': instance.fieldBool, + 'fieldString': instance.fieldString, + 'fieldInt': instance.fieldInt, + 'fieldDouble': instance.fieldDouble, + 'fieldListEmpty': instance.fieldListEmpty, + 'fieldSetEmpty': instance.fieldSetEmpty.toList(), + 'fieldMapEmpty': instance.fieldMapEmpty, + 'fieldListSimple': instance.fieldListSimple, + 'fieldSetSimple': instance.fieldSetSimple.toList(), + 'fieldMapSimple': instance.fieldMapSimple, + 'fieldMapListString': instance.fieldMapListString, + 'durationField': instance.durationField.inMicroseconds, + 'fieldEnum': _$GreekEnumMap[instance.fieldEnum]!, + 'constClass': instance.constClass, + 'valueFromConverter': const ConstClassConverter().toJson( + instance.valueFromConverter, + ), + 'valueFromFunction': constClassToJson(instance.valueFromFunction), + 'intDefaultValueFromFunction': instance.intDefaultValueFromFunction, + 'valueFromDefaultValueDefaultConstructor': + instance.valueFromDefaultValueDefaultConstructor, + 'valueFromDefaultValueNamedConstructor': + instance.valueFromDefaultValueNamedConstructor, +}; const _$GreekEnumMap = { Greek.alpha: 'alpha', diff --git a/json_serializable/test/enum_helper_test.dart b/json_serializable/test/enum_helper_test.dart index 280ff9e28..2355b0aa4 100644 --- a/json_serializable/test/enum_helper_test.dart +++ b/json_serializable/test/enum_helper_test.dart @@ -16,7 +16,7 @@ void main() { 'HELLO', 'hi_to', '_private', - 'weird_' + 'weird_', ]) { test(expression, () { expect(simpleExpression.hasMatch(expression), isTrue); diff --git a/json_serializable/test/field_matrix_test.dart b/json_serializable/test/field_matrix_test.dart index 8f1abff1a..dd4c68251 100644 --- a/json_serializable/test/field_matrix_test.dart +++ b/json_serializable/test/field_matrix_test.dart @@ -6,13 +6,15 @@ import 'field_matrix_test.field_matrix.dart'; void main() { test('test', () { - final result = Map.fromEntries(fromJsonFactories.map((e) { - final instance = e({'field': 42}); - return MapEntry(instance.toString(), { - 'with': instance, - 'without': e({}), - }); - })); + final result = Map.fromEntries( + fromJsonFactories.map((e) { + final instance = e({'field': 42}); + return MapEntry(instance.toString(), { + 'with': instance, + 'without': e({}), + }); + }), + ); expect(jsonDecode(jsonEncode(result)), _expectedResult); }); @@ -21,74 +23,74 @@ void main() { const _expectedResult = { 'ToJsonNullFromJsonNullPublic: field: 42': { 'with': {'aField': null, 'field': 42, 'zField': null}, - 'without': {'aField': null, 'field': null, 'zField': null} + 'without': {'aField': null, 'field': null, 'zField': null}, }, 'ToJsonNullFromJsonTruePublic: field: 42': { 'with': {'aField': null, 'field': 42, 'zField': null}, - 'without': {'aField': null, 'field': null, 'zField': null} + 'without': {'aField': null, 'field': null, 'zField': null}, }, 'ToJsonNullFromJsonFalsePublic: field: null': { 'with': {'aField': null, 'zField': null}, - 'without': {'aField': null, 'zField': null} + 'without': {'aField': null, 'zField': null}, }, 'ToJsonTrueFromJsonNullPublic: field: 42': { 'with': {'aField': null, 'field': 42, 'zField': null}, - 'without': {'aField': null, 'field': null, 'zField': null} + 'without': {'aField': null, 'field': null, 'zField': null}, }, 'ToJsonTrueFromJsonTruePublic: field: 42': { 'with': {'aField': null, 'field': 42, 'zField': null}, - 'without': {'aField': null, 'field': null, 'zField': null} + 'without': {'aField': null, 'field': null, 'zField': null}, }, 'ToJsonTrueFromJsonFalsePublic: field: null': { 'with': {'aField': null, 'field': null, 'zField': null}, - 'without': {'aField': null, 'field': null, 'zField': null} + 'without': {'aField': null, 'field': null, 'zField': null}, }, 'ToJsonFalseFromJsonNullPublic: field: 42': { 'with': {'aField': null, 'zField': null}, - 'without': {'aField': null, 'zField': null} + 'without': {'aField': null, 'zField': null}, }, 'ToJsonFalseFromJsonTruePublic: field: 42': { 'with': {'aField': null, 'zField': null}, - 'without': {'aField': null, 'zField': null} + 'without': {'aField': null, 'zField': null}, }, 'ToJsonFalseFromJsonFalsePublic: field: null': { 'with': {'aField': null, 'zField': null}, - 'without': {'aField': null, 'zField': null} + 'without': {'aField': null, 'zField': null}, }, 'ToJsonNullFromJsonNullPrivate: _field: null': { 'with': {'aField': null, 'zField': null}, - 'without': {'aField': null, 'zField': null} + 'without': {'aField': null, 'zField': null}, }, 'ToJsonNullFromJsonTruePrivate: _field: 42': { 'with': {'aField': null, 'field': 42, 'zField': null}, - 'without': {'aField': null, 'field': null, 'zField': null} + 'without': {'aField': null, 'field': null, 'zField': null}, }, 'ToJsonNullFromJsonFalsePrivate: _field: null': { 'with': {'aField': null, 'zField': null}, - 'without': {'aField': null, 'zField': null} + 'without': {'aField': null, 'zField': null}, }, 'ToJsonTrueFromJsonNullPrivate: _field: null': { 'with': {'aField': null, 'field': null, 'zField': null}, - 'without': {'aField': null, 'field': null, 'zField': null} + 'without': {'aField': null, 'field': null, 'zField': null}, }, 'ToJsonTrueFromJsonTruePrivate: _field: 42': { 'with': {'aField': null, 'field': 42, 'zField': null}, - 'without': {'aField': null, 'field': null, 'zField': null} + 'without': {'aField': null, 'field': null, 'zField': null}, }, 'ToJsonTrueFromJsonFalsePrivate: _field: null': { 'with': {'aField': null, 'field': null, 'zField': null}, - 'without': {'aField': null, 'field': null, 'zField': null} + 'without': {'aField': null, 'field': null, 'zField': null}, }, 'ToJsonFalseFromJsonNullPrivate: _field: null': { 'with': {'aField': null, 'zField': null}, - 'without': {'aField': null, 'zField': null} + 'without': {'aField': null, 'zField': null}, }, 'ToJsonFalseFromJsonTruePrivate: _field: 42': { 'with': {'aField': null, 'zField': null}, - 'without': {'aField': null, 'zField': null} + 'without': {'aField': null, 'zField': null}, }, 'ToJsonFalseFromJsonFalsePrivate: _field: null': { 'with': {'aField': null, 'zField': null}, - 'without': {'aField': null, 'zField': null} - } + 'without': {'aField': null, 'zField': null}, + }, }; diff --git a/json_serializable/test/field_matrix_test.field_matrix.dart b/json_serializable/test/field_matrix_test.field_matrix.dart index fd1c52b5f..8515129ff 100644 --- a/json_serializable/test/field_matrix_test.field_matrix.dart +++ b/json_serializable/test/field_matrix_test.field_matrix.dart @@ -27,9 +27,7 @@ class ToJsonNullFromJsonTruePublic { int? aField; - @JsonKey( - includeFromJson: true, - ) + @JsonKey(includeFromJson: true) int? field; int? zField; @@ -49,9 +47,7 @@ class ToJsonNullFromJsonFalsePublic { int? aField; - @JsonKey( - includeFromJson: false, - ) + @JsonKey(includeFromJson: false) int? field; int? zField; @@ -71,9 +67,7 @@ class ToJsonTrueFromJsonNullPublic { int? aField; - @JsonKey( - includeToJson: true, - ) + @JsonKey(includeToJson: true) int? field; int? zField; @@ -93,10 +87,7 @@ class ToJsonTrueFromJsonTruePublic { int? aField; - @JsonKey( - includeFromJson: true, - includeToJson: true, - ) + @JsonKey(includeFromJson: true, includeToJson: true) int? field; int? zField; @@ -116,10 +107,7 @@ class ToJsonTrueFromJsonFalsePublic { int? aField; - @JsonKey( - includeFromJson: false, - includeToJson: true, - ) + @JsonKey(includeFromJson: false, includeToJson: true) int? field; int? zField; @@ -139,9 +127,7 @@ class ToJsonFalseFromJsonNullPublic { int? aField; - @JsonKey( - includeToJson: false, - ) + @JsonKey(includeToJson: false) int? field; int? zField; @@ -161,10 +147,7 @@ class ToJsonFalseFromJsonTruePublic { int? aField; - @JsonKey( - includeFromJson: true, - includeToJson: false, - ) + @JsonKey(includeFromJson: true, includeToJson: false) int? field; int? zField; @@ -184,10 +167,7 @@ class ToJsonFalseFromJsonFalsePublic { int? aField; - @JsonKey( - includeFromJson: false, - includeToJson: false, - ) + @JsonKey(includeFromJson: false, includeToJson: false) int? field; int? zField; diff --git a/json_serializable/test/field_matrix_test.field_matrix.g.dart b/json_serializable/test/field_matrix_test.field_matrix.g.dart index aa18728ba..d61a2566d 100644 --- a/json_serializable/test/field_matrix_test.field_matrix.g.dart +++ b/json_serializable/test/field_matrix_test.field_matrix.g.dart @@ -9,253 +9,226 @@ part of 'field_matrix_test.field_matrix.dart'; // ************************************************************************** ToJsonNullFromJsonNullPublic _$ToJsonNullFromJsonNullPublicFromJson( - Map<String, dynamic> json) => - ToJsonNullFromJsonNullPublic() - ..aField = (json['aField'] as num?)?.toInt() - ..field = (json['field'] as num?)?.toInt() - ..zField = (json['zField'] as num?)?.toInt(); + Map<String, dynamic> json, +) => ToJsonNullFromJsonNullPublic() + ..aField = (json['aField'] as num?)?.toInt() + ..field = (json['field'] as num?)?.toInt() + ..zField = (json['zField'] as num?)?.toInt(); Map<String, dynamic> _$ToJsonNullFromJsonNullPublicToJson( - ToJsonNullFromJsonNullPublic instance) => - <String, dynamic>{ - 'aField': instance.aField, - 'field': instance.field, - 'zField': instance.zField, - }; + ToJsonNullFromJsonNullPublic instance, +) => <String, dynamic>{ + 'aField': instance.aField, + 'field': instance.field, + 'zField': instance.zField, +}; ToJsonNullFromJsonTruePublic _$ToJsonNullFromJsonTruePublicFromJson( - Map<String, dynamic> json) => - ToJsonNullFromJsonTruePublic() - ..aField = (json['aField'] as num?)?.toInt() - ..field = (json['field'] as num?)?.toInt() - ..zField = (json['zField'] as num?)?.toInt(); + Map<String, dynamic> json, +) => ToJsonNullFromJsonTruePublic() + ..aField = (json['aField'] as num?)?.toInt() + ..field = (json['field'] as num?)?.toInt() + ..zField = (json['zField'] as num?)?.toInt(); Map<String, dynamic> _$ToJsonNullFromJsonTruePublicToJson( - ToJsonNullFromJsonTruePublic instance) => - <String, dynamic>{ - 'aField': instance.aField, - 'field': instance.field, - 'zField': instance.zField, - }; + ToJsonNullFromJsonTruePublic instance, +) => <String, dynamic>{ + 'aField': instance.aField, + 'field': instance.field, + 'zField': instance.zField, +}; ToJsonNullFromJsonFalsePublic _$ToJsonNullFromJsonFalsePublicFromJson( - Map<String, dynamic> json) => - ToJsonNullFromJsonFalsePublic() - ..aField = (json['aField'] as num?)?.toInt() - ..zField = (json['zField'] as num?)?.toInt(); + Map<String, dynamic> json, +) => ToJsonNullFromJsonFalsePublic() + ..aField = (json['aField'] as num?)?.toInt() + ..zField = (json['zField'] as num?)?.toInt(); Map<String, dynamic> _$ToJsonNullFromJsonFalsePublicToJson( - ToJsonNullFromJsonFalsePublic instance) => - <String, dynamic>{ - 'aField': instance.aField, - 'zField': instance.zField, - }; + ToJsonNullFromJsonFalsePublic instance, +) => <String, dynamic>{'aField': instance.aField, 'zField': instance.zField}; ToJsonTrueFromJsonNullPublic _$ToJsonTrueFromJsonNullPublicFromJson( - Map<String, dynamic> json) => - ToJsonTrueFromJsonNullPublic() - ..aField = (json['aField'] as num?)?.toInt() - ..field = (json['field'] as num?)?.toInt() - ..zField = (json['zField'] as num?)?.toInt(); + Map<String, dynamic> json, +) => ToJsonTrueFromJsonNullPublic() + ..aField = (json['aField'] as num?)?.toInt() + ..field = (json['field'] as num?)?.toInt() + ..zField = (json['zField'] as num?)?.toInt(); Map<String, dynamic> _$ToJsonTrueFromJsonNullPublicToJson( - ToJsonTrueFromJsonNullPublic instance) => - <String, dynamic>{ - 'aField': instance.aField, - 'field': instance.field, - 'zField': instance.zField, - }; + ToJsonTrueFromJsonNullPublic instance, +) => <String, dynamic>{ + 'aField': instance.aField, + 'field': instance.field, + 'zField': instance.zField, +}; ToJsonTrueFromJsonTruePublic _$ToJsonTrueFromJsonTruePublicFromJson( - Map<String, dynamic> json) => - ToJsonTrueFromJsonTruePublic() - ..aField = (json['aField'] as num?)?.toInt() - ..field = (json['field'] as num?)?.toInt() - ..zField = (json['zField'] as num?)?.toInt(); + Map<String, dynamic> json, +) => ToJsonTrueFromJsonTruePublic() + ..aField = (json['aField'] as num?)?.toInt() + ..field = (json['field'] as num?)?.toInt() + ..zField = (json['zField'] as num?)?.toInt(); Map<String, dynamic> _$ToJsonTrueFromJsonTruePublicToJson( - ToJsonTrueFromJsonTruePublic instance) => - <String, dynamic>{ - 'aField': instance.aField, - 'field': instance.field, - 'zField': instance.zField, - }; + ToJsonTrueFromJsonTruePublic instance, +) => <String, dynamic>{ + 'aField': instance.aField, + 'field': instance.field, + 'zField': instance.zField, +}; ToJsonTrueFromJsonFalsePublic _$ToJsonTrueFromJsonFalsePublicFromJson( - Map<String, dynamic> json) => - ToJsonTrueFromJsonFalsePublic() - ..aField = (json['aField'] as num?)?.toInt() - ..zField = (json['zField'] as num?)?.toInt(); + Map<String, dynamic> json, +) => ToJsonTrueFromJsonFalsePublic() + ..aField = (json['aField'] as num?)?.toInt() + ..zField = (json['zField'] as num?)?.toInt(); Map<String, dynamic> _$ToJsonTrueFromJsonFalsePublicToJson( - ToJsonTrueFromJsonFalsePublic instance) => - <String, dynamic>{ - 'aField': instance.aField, - 'field': instance.field, - 'zField': instance.zField, - }; + ToJsonTrueFromJsonFalsePublic instance, +) => <String, dynamic>{ + 'aField': instance.aField, + 'field': instance.field, + 'zField': instance.zField, +}; ToJsonFalseFromJsonNullPublic _$ToJsonFalseFromJsonNullPublicFromJson( - Map<String, dynamic> json) => - ToJsonFalseFromJsonNullPublic() - ..aField = (json['aField'] as num?)?.toInt() - ..field = (json['field'] as num?)?.toInt() - ..zField = (json['zField'] as num?)?.toInt(); + Map<String, dynamic> json, +) => ToJsonFalseFromJsonNullPublic() + ..aField = (json['aField'] as num?)?.toInt() + ..field = (json['field'] as num?)?.toInt() + ..zField = (json['zField'] as num?)?.toInt(); Map<String, dynamic> _$ToJsonFalseFromJsonNullPublicToJson( - ToJsonFalseFromJsonNullPublic instance) => - <String, dynamic>{ - 'aField': instance.aField, - 'zField': instance.zField, - }; + ToJsonFalseFromJsonNullPublic instance, +) => <String, dynamic>{'aField': instance.aField, 'zField': instance.zField}; ToJsonFalseFromJsonTruePublic _$ToJsonFalseFromJsonTruePublicFromJson( - Map<String, dynamic> json) => - ToJsonFalseFromJsonTruePublic() - ..aField = (json['aField'] as num?)?.toInt() - ..field = (json['field'] as num?)?.toInt() - ..zField = (json['zField'] as num?)?.toInt(); + Map<String, dynamic> json, +) => ToJsonFalseFromJsonTruePublic() + ..aField = (json['aField'] as num?)?.toInt() + ..field = (json['field'] as num?)?.toInt() + ..zField = (json['zField'] as num?)?.toInt(); Map<String, dynamic> _$ToJsonFalseFromJsonTruePublicToJson( - ToJsonFalseFromJsonTruePublic instance) => - <String, dynamic>{ - 'aField': instance.aField, - 'zField': instance.zField, - }; + ToJsonFalseFromJsonTruePublic instance, +) => <String, dynamic>{'aField': instance.aField, 'zField': instance.zField}; ToJsonFalseFromJsonFalsePublic _$ToJsonFalseFromJsonFalsePublicFromJson( - Map<String, dynamic> json) => - ToJsonFalseFromJsonFalsePublic() - ..aField = (json['aField'] as num?)?.toInt() - ..zField = (json['zField'] as num?)?.toInt(); + Map<String, dynamic> json, +) => ToJsonFalseFromJsonFalsePublic() + ..aField = (json['aField'] as num?)?.toInt() + ..zField = (json['zField'] as num?)?.toInt(); Map<String, dynamic> _$ToJsonFalseFromJsonFalsePublicToJson( - ToJsonFalseFromJsonFalsePublic instance) => - <String, dynamic>{ - 'aField': instance.aField, - 'zField': instance.zField, - }; + ToJsonFalseFromJsonFalsePublic instance, +) => <String, dynamic>{'aField': instance.aField, 'zField': instance.zField}; ToJsonNullFromJsonNullPrivate _$ToJsonNullFromJsonNullPrivateFromJson( - Map<String, dynamic> json) => - ToJsonNullFromJsonNullPrivate() - ..aField = (json['aField'] as num?)?.toInt() - ..zField = (json['zField'] as num?)?.toInt(); + Map<String, dynamic> json, +) => ToJsonNullFromJsonNullPrivate() + ..aField = (json['aField'] as num?)?.toInt() + ..zField = (json['zField'] as num?)?.toInt(); Map<String, dynamic> _$ToJsonNullFromJsonNullPrivateToJson( - ToJsonNullFromJsonNullPrivate instance) => - <String, dynamic>{ - 'aField': instance.aField, - 'zField': instance.zField, - }; + ToJsonNullFromJsonNullPrivate instance, +) => <String, dynamic>{'aField': instance.aField, 'zField': instance.zField}; ToJsonNullFromJsonTruePrivate _$ToJsonNullFromJsonTruePrivateFromJson( - Map<String, dynamic> json) => - ToJsonNullFromJsonTruePrivate() - ..aField = (json['aField'] as num?)?.toInt() - .._field = (json['field'] as num?)?.toInt() - ..zField = (json['zField'] as num?)?.toInt(); + Map<String, dynamic> json, +) => ToJsonNullFromJsonTruePrivate() + ..aField = (json['aField'] as num?)?.toInt() + .._field = (json['field'] as num?)?.toInt() + ..zField = (json['zField'] as num?)?.toInt(); Map<String, dynamic> _$ToJsonNullFromJsonTruePrivateToJson( - ToJsonNullFromJsonTruePrivate instance) => - <String, dynamic>{ - 'aField': instance.aField, - 'field': instance._field, - 'zField': instance.zField, - }; + ToJsonNullFromJsonTruePrivate instance, +) => <String, dynamic>{ + 'aField': instance.aField, + 'field': instance._field, + 'zField': instance.zField, +}; ToJsonNullFromJsonFalsePrivate _$ToJsonNullFromJsonFalsePrivateFromJson( - Map<String, dynamic> json) => - ToJsonNullFromJsonFalsePrivate() - ..aField = (json['aField'] as num?)?.toInt() - ..zField = (json['zField'] as num?)?.toInt(); + Map<String, dynamic> json, +) => ToJsonNullFromJsonFalsePrivate() + ..aField = (json['aField'] as num?)?.toInt() + ..zField = (json['zField'] as num?)?.toInt(); Map<String, dynamic> _$ToJsonNullFromJsonFalsePrivateToJson( - ToJsonNullFromJsonFalsePrivate instance) => - <String, dynamic>{ - 'aField': instance.aField, - 'zField': instance.zField, - }; + ToJsonNullFromJsonFalsePrivate instance, +) => <String, dynamic>{'aField': instance.aField, 'zField': instance.zField}; ToJsonTrueFromJsonNullPrivate _$ToJsonTrueFromJsonNullPrivateFromJson( - Map<String, dynamic> json) => - ToJsonTrueFromJsonNullPrivate() - ..aField = (json['aField'] as num?)?.toInt() - ..zField = (json['zField'] as num?)?.toInt(); + Map<String, dynamic> json, +) => ToJsonTrueFromJsonNullPrivate() + ..aField = (json['aField'] as num?)?.toInt() + ..zField = (json['zField'] as num?)?.toInt(); Map<String, dynamic> _$ToJsonTrueFromJsonNullPrivateToJson( - ToJsonTrueFromJsonNullPrivate instance) => - <String, dynamic>{ - 'aField': instance.aField, - 'field': instance._field, - 'zField': instance.zField, - }; + ToJsonTrueFromJsonNullPrivate instance, +) => <String, dynamic>{ + 'aField': instance.aField, + 'field': instance._field, + 'zField': instance.zField, +}; ToJsonTrueFromJsonTruePrivate _$ToJsonTrueFromJsonTruePrivateFromJson( - Map<String, dynamic> json) => - ToJsonTrueFromJsonTruePrivate() - ..aField = (json['aField'] as num?)?.toInt() - .._field = (json['field'] as num?)?.toInt() - ..zField = (json['zField'] as num?)?.toInt(); + Map<String, dynamic> json, +) => ToJsonTrueFromJsonTruePrivate() + ..aField = (json['aField'] as num?)?.toInt() + .._field = (json['field'] as num?)?.toInt() + ..zField = (json['zField'] as num?)?.toInt(); Map<String, dynamic> _$ToJsonTrueFromJsonTruePrivateToJson( - ToJsonTrueFromJsonTruePrivate instance) => - <String, dynamic>{ - 'aField': instance.aField, - 'field': instance._field, - 'zField': instance.zField, - }; + ToJsonTrueFromJsonTruePrivate instance, +) => <String, dynamic>{ + 'aField': instance.aField, + 'field': instance._field, + 'zField': instance.zField, +}; ToJsonTrueFromJsonFalsePrivate _$ToJsonTrueFromJsonFalsePrivateFromJson( - Map<String, dynamic> json) => - ToJsonTrueFromJsonFalsePrivate() - ..aField = (json['aField'] as num?)?.toInt() - ..zField = (json['zField'] as num?)?.toInt(); + Map<String, dynamic> json, +) => ToJsonTrueFromJsonFalsePrivate() + ..aField = (json['aField'] as num?)?.toInt() + ..zField = (json['zField'] as num?)?.toInt(); Map<String, dynamic> _$ToJsonTrueFromJsonFalsePrivateToJson( - ToJsonTrueFromJsonFalsePrivate instance) => - <String, dynamic>{ - 'aField': instance.aField, - 'field': instance._field, - 'zField': instance.zField, - }; + ToJsonTrueFromJsonFalsePrivate instance, +) => <String, dynamic>{ + 'aField': instance.aField, + 'field': instance._field, + 'zField': instance.zField, +}; ToJsonFalseFromJsonNullPrivate _$ToJsonFalseFromJsonNullPrivateFromJson( - Map<String, dynamic> json) => - ToJsonFalseFromJsonNullPrivate() - ..aField = (json['aField'] as num?)?.toInt() - ..zField = (json['zField'] as num?)?.toInt(); + Map<String, dynamic> json, +) => ToJsonFalseFromJsonNullPrivate() + ..aField = (json['aField'] as num?)?.toInt() + ..zField = (json['zField'] as num?)?.toInt(); Map<String, dynamic> _$ToJsonFalseFromJsonNullPrivateToJson( - ToJsonFalseFromJsonNullPrivate instance) => - <String, dynamic>{ - 'aField': instance.aField, - 'zField': instance.zField, - }; + ToJsonFalseFromJsonNullPrivate instance, +) => <String, dynamic>{'aField': instance.aField, 'zField': instance.zField}; ToJsonFalseFromJsonTruePrivate _$ToJsonFalseFromJsonTruePrivateFromJson( - Map<String, dynamic> json) => - ToJsonFalseFromJsonTruePrivate() - ..aField = (json['aField'] as num?)?.toInt() - .._field = (json['field'] as num?)?.toInt() - ..zField = (json['zField'] as num?)?.toInt(); + Map<String, dynamic> json, +) => ToJsonFalseFromJsonTruePrivate() + ..aField = (json['aField'] as num?)?.toInt() + .._field = (json['field'] as num?)?.toInt() + ..zField = (json['zField'] as num?)?.toInt(); Map<String, dynamic> _$ToJsonFalseFromJsonTruePrivateToJson( - ToJsonFalseFromJsonTruePrivate instance) => - <String, dynamic>{ - 'aField': instance.aField, - 'zField': instance.zField, - }; + ToJsonFalseFromJsonTruePrivate instance, +) => <String, dynamic>{'aField': instance.aField, 'zField': instance.zField}; ToJsonFalseFromJsonFalsePrivate _$ToJsonFalseFromJsonFalsePrivateFromJson( - Map<String, dynamic> json) => - ToJsonFalseFromJsonFalsePrivate() - ..aField = (json['aField'] as num?)?.toInt() - ..zField = (json['zField'] as num?)?.toInt(); + Map<String, dynamic> json, +) => ToJsonFalseFromJsonFalsePrivate() + ..aField = (json['aField'] as num?)?.toInt() + ..zField = (json['zField'] as num?)?.toInt(); Map<String, dynamic> _$ToJsonFalseFromJsonFalsePrivateToJson( - ToJsonFalseFromJsonFalsePrivate instance) => - <String, dynamic>{ - 'aField': instance.aField, - 'zField': instance.zField, - }; + ToJsonFalseFromJsonFalsePrivate instance, +) => <String, dynamic>{'aField': instance.aField, 'zField': instance.zField}; diff --git a/json_serializable/test/generic_files/generic_argument_factories.dart b/json_serializable/test/generic_files/generic_argument_factories.dart index 0ebb09d69..b87154632 100644 --- a/json_serializable/test/generic_files/generic_argument_factories.dart +++ b/json_serializable/test/generic_files/generic_argument_factories.dart @@ -14,24 +14,18 @@ class GenericClassWithHelpers<T, S> { final Set<S> someSet; - GenericClassWithHelpers( - this.value, - this.list, - this.someSet, - ); + GenericClassWithHelpers(this.value, this.list, this.someSet); factory GenericClassWithHelpers.fromJson( Map<String, dynamic> json, T Function(Object? json) fromJsonT, S Function(Object? json) fromJsonS, - ) => - _$GenericClassWithHelpersFromJson(json, fromJsonT, fromJsonS); + ) => _$GenericClassWithHelpersFromJson(json, fromJsonT, fromJsonS); Map<String, dynamic> toJson( Object? Function(T value) toJsonT, Object? Function(S value) toJsonS, - ) => - _$GenericClassWithHelpersToJson(this, toJsonT, toJsonS); + ) => _$GenericClassWithHelpersToJson(this, toJsonT, toJsonS); } @JsonSerializable() diff --git a/json_serializable/test/generic_files/generic_argument_factories.g.dart b/json_serializable/test/generic_files/generic_argument_factories.g.dart index 3ae8ac8e1..a4d098d52 100644 --- a/json_serializable/test/generic_files/generic_argument_factories.g.dart +++ b/json_serializable/test/generic_files/generic_argument_factories.g.dart @@ -12,46 +12,44 @@ GenericClassWithHelpers<T, S> _$GenericClassWithHelpersFromJson<T, S>( Map<String, dynamic> json, T Function(Object? json) fromJsonT, S Function(Object? json) fromJsonS, -) => - GenericClassWithHelpers<T, S>( - fromJsonT(json['value']), - (json['list'] as List<dynamic>).map(fromJsonT).toList(), - (json['someSet'] as List<dynamic>).map(fromJsonS).toSet(), - ); +) => GenericClassWithHelpers<T, S>( + fromJsonT(json['value']), + (json['list'] as List<dynamic>).map(fromJsonT).toList(), + (json['someSet'] as List<dynamic>).map(fromJsonS).toSet(), +); Map<String, dynamic> _$GenericClassWithHelpersToJson<T, S>( GenericClassWithHelpers<T, S> instance, Object? Function(T value) toJsonT, Object? Function(S value) toJsonS, -) => - <String, dynamic>{ - 'value': toJsonT(instance.value), - 'list': instance.list.map(toJsonT).toList(), - 'someSet': instance.someSet.map(toJsonS).toList(), - }; +) => <String, dynamic>{ + 'value': toJsonT(instance.value), + 'list': instance.list.map(toJsonT).toList(), + 'someSet': instance.someSet.map(toJsonS).toList(), +}; ConcreteClass _$ConcreteClassFromJson(Map<String, dynamic> json) => ConcreteClass( GenericClassWithHelpers<int, String>.fromJson( - json['value'] as Map<String, dynamic>, - (value) => (value as num).toInt(), - (value) => value as String), + json['value'] as Map<String, dynamic>, + (value) => (value as num).toInt(), + (value) => value as String, + ), GenericClassWithHelpers<double, BigInt>.fromJson( - json['value2'] as Map<String, dynamic>, - (value) => (value as num).toDouble(), - (value) => BigInt.parse(value as String)), + json['value2'] as Map<String, dynamic>, + (value) => (value as num).toDouble(), + (value) => BigInt.parse(value as String), + ), GenericClassWithHelpers<double?, BigInt?>.fromJson( - json['value3'] as Map<String, dynamic>, - (value) => (value as num?)?.toDouble(), - (value) => value == null ? null : BigInt.parse(value as String)), + json['value3'] as Map<String, dynamic>, + (value) => (value as num?)?.toDouble(), + (value) => value == null ? null : BigInt.parse(value as String), + ), ); Map<String, dynamic> _$ConcreteClassToJson(ConcreteClass instance) => <String, dynamic>{ - 'value': instance.value.toJson( - (value) => value, - (value) => value, - ), + 'value': instance.value.toJson((value) => value, (value) => value), 'value2': instance.value2.toJson( (value) => value, (value) => value.toString(), diff --git a/json_serializable/test/generic_files/generic_argument_factories_nullable.dart b/json_serializable/test/generic_files/generic_argument_factories_nullable.dart index 882ad4de5..f883c140f 100644 --- a/json_serializable/test/generic_files/generic_argument_factories_nullable.dart +++ b/json_serializable/test/generic_files/generic_argument_factories_nullable.dart @@ -14,24 +14,18 @@ class GenericClassWithHelpersNullable<T, S> { final Set<S?>? someSet; - GenericClassWithHelpersNullable({ - this.value, - this.list, - this.someSet, - }); + GenericClassWithHelpersNullable({this.value, this.list, this.someSet}); factory GenericClassWithHelpersNullable.fromJson( Map<String, dynamic> json, T Function(Object? json) fromJsonT, S Function(Object? json) fromJsonS, - ) => - _$GenericClassWithHelpersNullableFromJson(json, fromJsonT, fromJsonS); + ) => _$GenericClassWithHelpersNullableFromJson(json, fromJsonT, fromJsonS); Map<String, dynamic> toJson( Object? Function(T value) toJsonT, Object? Function(S value) toJsonS, - ) => - _$GenericClassWithHelpersNullableToJson(this, toJsonT, toJsonS); + ) => _$GenericClassWithHelpersNullableToJson(this, toJsonT, toJsonS); } @JsonSerializable() diff --git a/json_serializable/test/generic_files/generic_argument_factories_nullable.g.dart b/json_serializable/test/generic_files/generic_argument_factories_nullable.g.dart index 626fa171a..556ec9de1 100644 --- a/json_serializable/test/generic_files/generic_argument_factories_nullable.g.dart +++ b/json_serializable/test/generic_files/generic_argument_factories_nullable.g.dart @@ -9,78 +9,74 @@ part of 'generic_argument_factories_nullable.dart'; // ************************************************************************** GenericClassWithHelpersNullable<T, S> - _$GenericClassWithHelpersNullableFromJson<T, S>( +_$GenericClassWithHelpersNullableFromJson<T, S>( Map<String, dynamic> json, T Function(Object? json) fromJsonT, S Function(Object? json) fromJsonS, -) => - GenericClassWithHelpersNullable<T, S>( - value: _$nullableGenericFromJson(json['value'], fromJsonT), - list: (json['list'] as List<dynamic>?) - ?.map((e) => _$nullableGenericFromJson(e, fromJsonT)) - .toList(), - someSet: (json['someSet'] as List<dynamic>?) - ?.map((e) => _$nullableGenericFromJson(e, fromJsonS)) - .toSet(), - ); +) => GenericClassWithHelpersNullable<T, S>( + value: _$nullableGenericFromJson(json['value'], fromJsonT), + list: (json['list'] as List<dynamic>?) + ?.map((e) => _$nullableGenericFromJson(e, fromJsonT)) + .toList(), + someSet: (json['someSet'] as List<dynamic>?) + ?.map((e) => _$nullableGenericFromJson(e, fromJsonS)) + .toSet(), +); Map<String, dynamic> _$GenericClassWithHelpersNullableToJson<T, S>( GenericClassWithHelpersNullable<T, S> instance, Object? Function(T value) toJsonT, Object? Function(S value) toJsonS, -) => - <String, dynamic>{ - 'value': _$nullableGenericToJson(instance.value, toJsonT), - 'list': instance.list - ?.map((e) => _$nullableGenericToJson(e, toJsonT)) - .toList(), - 'someSet': instance.someSet - ?.map((e) => _$nullableGenericToJson(e, toJsonS)) - .toList(), - }; +) => <String, dynamic>{ + 'value': _$nullableGenericToJson(instance.value, toJsonT), + 'list': instance.list + ?.map((e) => _$nullableGenericToJson(e, toJsonT)) + .toList(), + 'someSet': instance.someSet + ?.map((e) => _$nullableGenericToJson(e, toJsonS)) + .toList(), +}; T? _$nullableGenericFromJson<T>( Object? input, T Function(Object? json) fromJson, -) => - input == null ? null : fromJson(input); +) => input == null ? null : fromJson(input); Object? _$nullableGenericToJson<T>( T? input, Object? Function(T value) toJson, -) => - input == null ? null : toJson(input); +) => input == null ? null : toJson(input); ConcreteClassNullable _$ConcreteClassNullableFromJson( - Map<String, dynamic> json) => - ConcreteClassNullable( - GenericClassWithHelpersNullable<int, String>.fromJson( - json['value'] as Map<String, dynamic>, - (value) => (value as num).toInt(), - (value) => value as String), - GenericClassWithHelpersNullable<double, BigInt>.fromJson( - json['value2'] as Map<String, dynamic>, - (value) => (value as num).toDouble(), - (value) => BigInt.parse(value as String)), - GenericClassWithHelpersNullable<double?, BigInt?>.fromJson( - json['value3'] as Map<String, dynamic>, - (value) => (value as num?)?.toDouble(), - (value) => value == null ? null : BigInt.parse(value as String)), - ); + Map<String, dynamic> json, +) => ConcreteClassNullable( + GenericClassWithHelpersNullable<int, String>.fromJson( + json['value'] as Map<String, dynamic>, + (value) => (value as num).toInt(), + (value) => value as String, + ), + GenericClassWithHelpersNullable<double, BigInt>.fromJson( + json['value2'] as Map<String, dynamic>, + (value) => (value as num).toDouble(), + (value) => BigInt.parse(value as String), + ), + GenericClassWithHelpersNullable<double?, BigInt?>.fromJson( + json['value3'] as Map<String, dynamic>, + (value) => (value as num?)?.toDouble(), + (value) => value == null ? null : BigInt.parse(value as String), + ), +); Map<String, dynamic> _$ConcreteClassNullableToJson( - ConcreteClassNullable instance) => - <String, dynamic>{ - 'value': instance.value.toJson( - (value) => value, - (value) => value, - ), - 'value2': instance.value2.toJson( - (value) => value, - (value) => value.toString(), - ), - 'value3': instance.value3.toJson( - (value) => value, - (value) => value?.toString(), - ), - }; + ConcreteClassNullable instance, +) => <String, dynamic>{ + 'value': instance.value.toJson((value) => value, (value) => value), + 'value2': instance.value2.toJson( + (value) => value, + (value) => value.toString(), + ), + 'value3': instance.value3.toJson( + (value) => value, + (value) => value?.toString(), + ), +}; diff --git a/json_serializable/test/generic_files/generic_class.dart b/json_serializable/test/generic_files/generic_class.dart index 8c8b8d715..196bfeaca 100644 --- a/json_serializable/test/generic_files/generic_class.dart +++ b/json_serializable/test/generic_files/generic_class.dart @@ -34,13 +34,17 @@ class GenericClass<T extends num, S> { Map<String, dynamic> toJson() => _$GenericClassToJson(this); - static T _dataFromJson<T, S, U>(Map<String, dynamic> input, - [S? other1, U? other2]) => - input['value'] as T; - - static Map<String, dynamic> _dataToJson<T, S, U>(T input, - [S? other1, U? other2]) => - {'value': input}; + static T _dataFromJson<T, S, U>( + Map<String, dynamic> input, [ + S? other1, + U? other2, + ]) => input['value'] as T; + + static Map<String, dynamic> _dataToJson<T, S, U>( + T input, [ + S? other1, + U? other2, + ]) => {'value': input}; } @JsonSerializable() @@ -153,8 +157,9 @@ class Issue1047ParentClass<T> { Issue1047ParentClass({required this.edges}); factory Issue1047ParentClass.fromJson( - Map<String, dynamic> json, T Function(Object? json) fromJsonT) => - _$Issue1047ParentClassFromJson<T>(json, fromJsonT); + Map<String, dynamic> json, + T Function(Object? json) fromJsonT, + ) => _$Issue1047ParentClassFromJson<T>(json, fromJsonT); final List<Issue1047Class<T>> edges; @@ -164,15 +169,12 @@ class Issue1047ParentClass<T> { @JsonSerializable(genericArgumentFactories: true) class Issue1047Class<T> { - Issue1047Class({ - required this.node, - }); + Issue1047Class({required this.node}); factory Issue1047Class.fromJson( Map<String, dynamic> json, T Function(Object? json) fromJsonT, - ) => - _$Issue1047ClassFromJson<T>(json, fromJsonT); + ) => _$Issue1047ClassFromJson<T>(json, fromJsonT); final T node; diff --git a/json_serializable/test/generic_files/generic_class.g.dart b/json_serializable/test/generic_files/generic_class.g.dart index 104eec1d6..4b260a766 100644 --- a/json_serializable/test/generic_files/generic_class.g.dart +++ b/json_serializable/test/generic_files/generic_class.g.dart @@ -9,122 +9,127 @@ part of 'generic_class.dart'; // ************************************************************************** GenericClass<T, S> _$GenericClassFromJson<T extends num, S>( - Map<String, dynamic> json) => - GenericClass<T, S>() - ..fieldObject = GenericClass._dataFromJson( - json['fieldObject'] as Map<String, dynamic>) - ..fieldDynamic = GenericClass._dataFromJson( - json['fieldDynamic'] as Map<String, dynamic>) - ..fieldInt = - GenericClass._dataFromJson(json['fieldInt'] as Map<String, dynamic>) - ..fieldT = - GenericClass._dataFromJson(json['fieldT'] as Map<String, dynamic>) - ..fieldS = - GenericClass._dataFromJson(json['fieldS'] as Map<String, dynamic>); + Map<String, dynamic> json, +) => GenericClass<T, S>() + ..fieldObject = GenericClass._dataFromJson( + json['fieldObject'] as Map<String, dynamic>, + ) + ..fieldDynamic = GenericClass._dataFromJson( + json['fieldDynamic'] as Map<String, dynamic>, + ) + ..fieldInt = GenericClass._dataFromJson( + json['fieldInt'] as Map<String, dynamic>, + ) + ..fieldT = GenericClass._dataFromJson(json['fieldT'] as Map<String, dynamic>) + ..fieldS = GenericClass._dataFromJson(json['fieldS'] as Map<String, dynamic>); Map<String, dynamic> _$GenericClassToJson<T extends num, S>( - GenericClass<T, S> instance) => - <String, dynamic>{ - 'fieldObject': GenericClass._dataToJson(instance.fieldObject), - 'fieldDynamic': GenericClass._dataToJson(instance.fieldDynamic), - 'fieldInt': GenericClass._dataToJson(instance.fieldInt), - 'fieldT': GenericClass._dataToJson(instance.fieldT), - 'fieldS': GenericClass._dataToJson(instance.fieldS), - }; + GenericClass<T, S> instance, +) => <String, dynamic>{ + 'fieldObject': GenericClass._dataToJson(instance.fieldObject), + 'fieldDynamic': GenericClass._dataToJson(instance.fieldDynamic), + 'fieldInt': GenericClass._dataToJson(instance.fieldInt), + 'fieldT': GenericClass._dataToJson(instance.fieldT), + 'fieldS': GenericClass._dataToJson(instance.fieldS), +}; -GenericClassWithConverter<T, S> - _$GenericClassWithConverterFromJson<T extends num, S>( - Map<String, dynamic> json) => - GenericClassWithConverter<T, S>() - ..fieldObject = json['fieldObject'] - ..fieldDynamic = json['fieldDynamic'] - ..fieldInt = (json['fieldInt'] as num?)?.toInt() - ..fieldT = _$JsonConverterFromJson<Map<String, dynamic>, T>( - json['fieldT'], _SimpleConverter<T?>().fromJson) - ..fieldS = _$JsonConverterFromJson<Map<String, dynamic>, S>( - json['fieldS'], _SimpleConverter<S?>().fromJson) - ..duration = const _DurationMillisecondConverter.named() - .fromJson((json['duration'] as num?)?.toInt()) - ..listDuration = const _DurationListMillisecondConverter() - .fromJson((json['listDuration'] as num?)?.toInt()); +GenericClassWithConverter<T, S> _$GenericClassWithConverterFromJson< + T extends num, + S +>(Map<String, dynamic> json) => GenericClassWithConverter<T, S>() + ..fieldObject = json['fieldObject'] + ..fieldDynamic = json['fieldDynamic'] + ..fieldInt = (json['fieldInt'] as num?)?.toInt() + ..fieldT = _$JsonConverterFromJson<Map<String, dynamic>, T>( + json['fieldT'], + _SimpleConverter<T?>().fromJson, + ) + ..fieldS = _$JsonConverterFromJson<Map<String, dynamic>, S>( + json['fieldS'], + _SimpleConverter<S?>().fromJson, + ) + ..duration = const _DurationMillisecondConverter.named().fromJson( + (json['duration'] as num?)?.toInt(), + ) + ..listDuration = const _DurationListMillisecondConverter().fromJson( + (json['listDuration'] as num?)?.toInt(), + ); Map<String, dynamic> _$GenericClassWithConverterToJson<T extends num, S>( - GenericClassWithConverter<T, S> instance) => - <String, dynamic>{ - 'fieldObject': instance.fieldObject, - 'fieldDynamic': instance.fieldDynamic, - 'fieldInt': instance.fieldInt, - 'fieldT': _$JsonConverterToJson<Map<String, dynamic>, T>( - instance.fieldT, _SimpleConverter<T?>().toJson), - 'fieldS': _$JsonConverterToJson<Map<String, dynamic>, S>( - instance.fieldS, _SimpleConverter<S?>().toJson), - 'duration': - const _DurationMillisecondConverter.named().toJson(instance.duration), - 'listDuration': const _DurationListMillisecondConverter() - .toJson(instance.listDuration), - }; + GenericClassWithConverter<T, S> instance, +) => <String, dynamic>{ + 'fieldObject': instance.fieldObject, + 'fieldDynamic': instance.fieldDynamic, + 'fieldInt': instance.fieldInt, + 'fieldT': _$JsonConverterToJson<Map<String, dynamic>, T>( + instance.fieldT, + _SimpleConverter<T?>().toJson, + ), + 'fieldS': _$JsonConverterToJson<Map<String, dynamic>, S>( + instance.fieldS, + _SimpleConverter<S?>().toJson, + ), + 'duration': const _DurationMillisecondConverter.named().toJson( + instance.duration, + ), + 'listDuration': const _DurationListMillisecondConverter().toJson( + instance.listDuration, + ), +}; Value? _$JsonConverterFromJson<Json, Value>( Object? json, Value? Function(Json json) fromJson, -) => - json == null ? null : fromJson(json as Json); +) => json == null ? null : fromJson(json as Json); Json? _$JsonConverterToJson<Json, Value>( Value? value, Json? Function(Value value) toJson, -) => - value == null ? null : toJson(value); +) => value == null ? null : toJson(value); Issue980ParentClass _$Issue980ParentClassFromJson(Map<String, dynamic> json) => Issue980ParentClass( (json['list'] as List<dynamic>) - .map((e) => - Issue980GenericClass<int>.fromJson(e as Map<String, dynamic>)) + .map( + (e) => + Issue980GenericClass<int>.fromJson(e as Map<String, dynamic>), + ) .toList(), ); Map<String, dynamic> _$Issue980ParentClassToJson( - Issue980ParentClass instance) => - <String, dynamic>{ - 'list': instance.list, - }; + Issue980ParentClass instance, +) => <String, dynamic>{'list': instance.list}; Issue1047ParentClass<T> _$Issue1047ParentClassFromJson<T>( Map<String, dynamic> json, T Function(Object? json) fromJsonT, -) => - Issue1047ParentClass<T>( - edges: (json['edges'] as List<dynamic>) - .map((e) => Issue1047Class<T>.fromJson( - e as Map<String, dynamic>, (value) => fromJsonT(value))) - .toList(), - ); +) => Issue1047ParentClass<T>( + edges: (json['edges'] as List<dynamic>) + .map( + (e) => Issue1047Class<T>.fromJson( + e as Map<String, dynamic>, + (value) => fromJsonT(value), + ), + ) + .toList(), +); Map<String, dynamic> _$Issue1047ParentClassToJson<T>( Issue1047ParentClass<T> instance, Object? Function(T value) toJsonT, -) => - <String, dynamic>{ - 'edges': instance.edges - .map((e) => e.toJson( - (value) => toJsonT(value), - )) - .toList(), - }; +) => <String, dynamic>{ + 'edges': instance.edges + .map((e) => e.toJson((value) => toJsonT(value))) + .toList(), +}; Issue1047Class<T> _$Issue1047ClassFromJson<T>( Map<String, dynamic> json, T Function(Object? json) fromJsonT, -) => - Issue1047Class<T>( - node: fromJsonT(json['node']), - ); +) => Issue1047Class<T>(node: fromJsonT(json['node'])); Map<String, dynamic> _$Issue1047ClassToJson<T>( Issue1047Class<T> instance, Object? Function(T value) toJsonT, -) => - <String, dynamic>{ - 'node': toJsonT(instance.node), - }; +) => <String, dynamic>{'node': toJsonT(instance.node)}; diff --git a/json_serializable/test/generic_files/generic_test.dart b/json_serializable/test/generic_files/generic_test.dart index ea509a471..9cdc7daa5 100644 --- a/json_serializable/test/generic_files/generic_test.dart +++ b/json_serializable/test/generic_files/generic_test.dart @@ -14,36 +14,43 @@ import 'generic_class.dart'; void main() { group('generic', () { GenericClass<T, S> roundTripGenericClass<T extends num, S>( - GenericClass<T, S> p) { + GenericClass<T, S> p, + ) { final outputJson = loudEncode(p); final p2 = GenericClass<T, S>.fromJson( - jsonDecode(outputJson) as Map<String, dynamic>); + jsonDecode(outputJson) as Map<String, dynamic>, + ); final outputJson2 = loudEncode(p2); expect(outputJson2, outputJson); return p2; } test('no type args', () { - // ignore: inference_failure_on_instance_creation - roundTripGenericClass(GenericClass() - ..fieldDynamic = 1 - ..fieldInt = 2 - ..fieldObject = 3 - ..fieldT = 5 - ..fieldS = 'six'); + roundTripGenericClass( + // ignore: inference_failure_on_instance_creation + GenericClass() + ..fieldDynamic = 1 + ..fieldInt = 2 + ..fieldObject = 3 + ..fieldT = 5 + ..fieldS = 'six', + ); }); test('with type arguments', () { - roundTripGenericClass(GenericClass<double, String>() - ..fieldDynamic = 1 - ..fieldInt = 2 - ..fieldObject = 3 - ..fieldT = 5.0 - ..fieldS = 'six'); + roundTripGenericClass( + GenericClass<double, String>() + ..fieldDynamic = 1 + ..fieldInt = 2 + ..fieldObject = 3 + ..fieldT = 5.0 + ..fieldS = 'six', + ); }); test('with bad arguments', () { expect( - () => GenericClass<double, String>() - ..fieldT = (true as dynamic) as double, + () => + GenericClass<double, String>() + ..fieldT = (true as dynamic) as double, throwsTypeError, ); }); @@ -179,7 +186,7 @@ void main() { ], someSet: { const Duration(milliseconds: 3), - const Duration(milliseconds: 4) + const Duration(milliseconds: 4), }, ); @@ -192,10 +199,10 @@ void main() { final decoded = GenericClassWithHelpersNullable<DateTime, Duration>.fromJson( - jsonDecode(encodedJson) as Map<String, dynamic>, - (value) => DateTime.parse(value as String), - (value) => Duration(milliseconds: (value as num).toInt()), - ); + jsonDecode(encodedJson) as Map<String, dynamic>, + (value) => DateTime.parse(value as String), + (value) => Duration(milliseconds: (value as num).toInt()), + ); final encodedJson2 = loudEncode( decoded.toJson(encodeDateTime, encodeDuration), @@ -207,10 +214,7 @@ void main() { test('basic round-trip with null values', () { final instance = GenericClassWithHelpersNullable<DateTime, Duration>( //value: null, // value is null by omission - list: [ - null, - DateTime.fromMillisecondsSinceEpoch(2).toUtc(), - ], + list: [null, DateTime.fromMillisecondsSinceEpoch(2).toUtc()], someSet: {null, const Duration(milliseconds: 4)}, ); @@ -223,10 +227,10 @@ void main() { final decoded = GenericClassWithHelpersNullable<DateTime, Duration>.fromJson( - jsonDecode(encodedJson) as Map<String, dynamic>, - (value) => DateTime.parse(value as String), - (value) => Duration(milliseconds: (value as num).toInt()), - ); + jsonDecode(encodedJson) as Map<String, dynamic>, + (value) => DateTime.parse(value as String), + (value) => Duration(milliseconds: (value as num).toInt()), + ); final encodedJson2 = loudEncode( decoded.toJson(encodeDateTime, encodeDuration), @@ -320,10 +324,7 @@ void main() { test('issue 980 regression test', () { roundTripObject( - Issue980ParentClass([ - Issue980GenericClass(45), - Issue980GenericClass(42), - ]), + Issue980ParentClass([Issue980GenericClass(45), Issue980GenericClass(42)]), Issue980ParentClass.fromJson, ); }); @@ -332,8 +333,8 @@ void main() { _roundTrip( sourceJson: { 'edges': [ - {'node': '42'} - ] + {'node': '42'}, + ], }, genericEncode: (o) => o.toString(), genericDecode: (o) => int.parse(o as String), diff --git a/json_serializable/test/integration/converter_examples.dart b/json_serializable/test/integration/converter_examples.dart index 9641b966b..73be3828f 100644 --- a/json_serializable/test/integration/converter_examples.dart +++ b/json_serializable/test/integration/converter_examples.dart @@ -110,9 +110,7 @@ class Regression1229 { @JsonKey(includeIfNull: false) final DateTime? date; - Regression1229({ - this.date, - }); + Regression1229({this.date}); factory Regression1229.fromJson(Map<String, dynamic> json) => _$Regression1229FromJson(json); diff --git a/json_serializable/test/integration/converter_examples.g.dart b/json_serializable/test/integration/converter_examples.g.dart index f19c8fc2e..d91d76d93 100644 --- a/json_serializable/test/integration/converter_examples.g.dart +++ b/json_serializable/test/integration/converter_examples.g.dart @@ -9,43 +9,45 @@ part of 'converter_examples.dart'; // ************************************************************************** Issue1202RegressionClass _$Issue1202RegressionClassFromJson( - Map<String, dynamic> json) => - Issue1202RegressionClass( - value: $enumDecode(_$Issue1202RegressionEnumEnumMap, json['value']), - normalNullableValue: (json['normalNullableValue'] as num?)?.toInt(), - notNullableValueWithNullableConverter: - const _Issue1202RegressionConverter().fromJson( - json['notNullableValueWithNullableConverter'] as String?), - notNullableValueWithConverter: - const _Issue1202RegressionNotNullConverter() - .fromJson(json['notNullableValueWithConverter'] as String), - valueWithFunctions: Issue1202RegressionClass._fromJson( - json['valueWithFunctions'] as String), - valueWithNullableFunctions: Issue1202RegressionClass._fromJsonNullable( - json['valueWithNullableFunctions'] as String?), - ); + Map<String, dynamic> json, +) => Issue1202RegressionClass( + value: $enumDecode(_$Issue1202RegressionEnumEnumMap, json['value']), + normalNullableValue: (json['normalNullableValue'] as num?)?.toInt(), + notNullableValueWithNullableConverter: const _Issue1202RegressionConverter() + .fromJson(json['notNullableValueWithNullableConverter'] as String?), + notNullableValueWithConverter: const _Issue1202RegressionNotNullConverter() + .fromJson(json['notNullableValueWithConverter'] as String), + valueWithFunctions: Issue1202RegressionClass._fromJson( + json['valueWithFunctions'] as String, + ), + valueWithNullableFunctions: Issue1202RegressionClass._fromJsonNullable( + json['valueWithNullableFunctions'] as String?, + ), +); Map<String, dynamic> _$Issue1202RegressionClassToJson( - Issue1202RegressionClass instance) => - <String, dynamic>{ - 'valueWithFunctions': - Issue1202RegressionClass._toJson(instance.valueWithFunctions), - 'notNullableValueWithConverter': - const _Issue1202RegressionNotNullConverter() - .toJson(instance.notNullableValueWithConverter), - if (_$Issue1202RegressionEnumEnumMap[instance.value] case final value?) - 'value': value, - if (instance.normalNullableValue case final value?) - 'normalNullableValue': value, - if (const _Issue1202RegressionConverter() - .toJson(instance.notNullableValueWithNullableConverter) - case final value?) - 'notNullableValueWithNullableConverter': value, - if (Issue1202RegressionClass._toJsonNullable( - instance.valueWithNullableFunctions) - case final value?) - 'valueWithNullableFunctions': value, - }; + Issue1202RegressionClass instance, +) => <String, dynamic>{ + 'valueWithFunctions': Issue1202RegressionClass._toJson( + instance.valueWithFunctions, + ), + 'notNullableValueWithConverter': const _Issue1202RegressionNotNullConverter() + .toJson(instance.notNullableValueWithConverter), + if (_$Issue1202RegressionEnumEnumMap[instance.value] case final value?) + 'value': value, + if (instance.normalNullableValue case final value?) + 'normalNullableValue': value, + if (const _Issue1202RegressionConverter().toJson( + instance.notNullableValueWithNullableConverter, + ) + case final value?) + 'notNullableValueWithNullableConverter': value, + if (Issue1202RegressionClass._toJsonNullable( + instance.valueWithNullableFunctions, + ) + case final value?) + 'valueWithNullableFunctions': value, +}; const _$Issue1202RegressionEnumEnumMap = { Issue1202RegressionEnum.normalValue: 42, @@ -55,13 +57,17 @@ const _$Issue1202RegressionEnumEnumMap = { Regression1229 _$Regression1229FromJson(Map<String, dynamic> json) => Regression1229( date: _$JsonConverterFromJson<String, DateTime>( - json['date'], const DateTimeConverter().fromJson), + json['date'], + const DateTimeConverter().fromJson, + ), ); Map<String, dynamic> _$Regression1229ToJson(Regression1229 instance) => <String, dynamic>{ if (_$JsonConverterToJson<String, DateTime>( - instance.date, const DateTimeConverter().toJson) + instance.date, + const DateTimeConverter().toJson, + ) case final value?) 'date': value, }; @@ -69,11 +75,9 @@ Map<String, dynamic> _$Regression1229ToJson(Regression1229 instance) => Value? _$JsonConverterFromJson<Json, Value>( Object? json, Value? Function(Json json) fromJson, -) => - json == null ? null : fromJson(json as Json); +) => json == null ? null : fromJson(json as Json); Json? _$JsonConverterToJson<Json, Value>( Value? value, Json? Function(Value value) toJson, -) => - value == null ? null : toJson(value); +) => value == null ? null : toJson(value); diff --git a/json_serializable/test/integration/create_per_field_to_json_example.dart b/json_serializable/test/integration/create_per_field_to_json_example.dart index 8eb3f5e9e..d086253f3 100644 --- a/json_serializable/test/integration/create_per_field_to_json_example.dart +++ b/json_serializable/test/integration/create_per_field_to_json_example.dart @@ -2,10 +2,7 @@ import 'package:json_annotation/json_annotation.dart'; part 'create_per_field_to_json_example.g.dart'; -@JsonSerializable( - createPerFieldToJson: true, - explicitToJson: true, -) +@JsonSerializable(createPerFieldToJson: true, explicitToJson: true) class Model { Model({ required this.firstName, @@ -56,21 +53,14 @@ class Nested { Map<String, Object?> toJson() => _$NestedToJson(this); } -@JsonSerializable( - createPerFieldToJson: true, - genericArgumentFactories: true, -) +@JsonSerializable(createPerFieldToJson: true, genericArgumentFactories: true) class GenericFactory<T> { - GenericFactory( - this.value, - this.map, - ); + GenericFactory(this.value, this.map); factory GenericFactory.fromJson( Map<String, Object?> json, T Function(Object? json) fromJsonT, - ) => - _$GenericFactoryFromJson(json, fromJsonT); + ) => _$GenericFactoryFromJson(json, fromJsonT); final T value; final Map<String, T> map; diff --git a/json_serializable/test/integration/create_per_field_to_json_example.g.dart b/json_serializable/test/integration/create_per_field_to_json_example.g.dart index 28f3443a5..14d7d9f0f 100644 --- a/json_serializable/test/integration/create_per_field_to_json_example.g.dart +++ b/json_serializable/test/integration/create_per_field_to_json_example.g.dart @@ -9,22 +9,22 @@ part of 'create_per_field_to_json_example.dart'; // ************************************************************************** Model _$ModelFromJson(Map<String, dynamic> json) => Model( - firstName: json['firstName'] as String, - lastName: json['lastName'] as String, - enumValue: $enumDecodeNullable(_$EnumValueEnumMap, json['enumValue']), - nested: json['nested'] == null - ? null - : Nested.fromJson(json['nested'] as Map<String, dynamic>), - nestedExcludeIfNull: json['nestedExcludeIfNull'] == null - ? null - : Nested.fromJson( - json['nestedExcludeIfNull'] as Map<String, dynamic>), - nestedGeneric: json['nestedGeneric'] == null - ? null - : GenericFactory<int>.fromJson( - json['nestedGeneric'] as Map<String, dynamic>, - (value) => (value as num).toInt()), - ); + firstName: json['firstName'] as String, + lastName: json['lastName'] as String, + enumValue: $enumDecodeNullable(_$EnumValueEnumMap, json['enumValue']), + nested: json['nested'] == null + ? null + : Nested.fromJson(json['nested'] as Map<String, dynamic>), + nestedExcludeIfNull: json['nestedExcludeIfNull'] == null + ? null + : Nested.fromJson(json['nestedExcludeIfNull'] as Map<String, dynamic>), + nestedGeneric: json['nestedGeneric'] == null + ? null + : GenericFactory<int>.fromJson( + json['nestedGeneric'] as Map<String, dynamic>, + (value) => (value as num).toInt(), + ), +); // ignore: unused_element abstract class _$ModelPerFieldToJson { @@ -38,73 +38,59 @@ abstract class _$ModelPerFieldToJson { static Object? nested(Nested? instance) => instance?.toJson(); // ignore: unused_element static Object? nestedGeneric(GenericFactory<int>? instance) => - instance?.toJson( - (value) => value, - ); + instance?.toJson((value) => value); // ignore: unused_element static Object? nestedExcludeIfNull(Nested? instance) => instance?.toJson(); } Map<String, dynamic> _$ModelToJson(Model instance) => <String, dynamic>{ - 'firstName': instance.firstName, - 'lastName': instance.lastName, - 'enumValue': _$EnumValueEnumMap[instance.enumValue], - 'nested': instance.nested?.toJson(), - 'nestedGeneric': instance.nestedGeneric?.toJson( - (value) => value, - ), - if (instance.nestedExcludeIfNull?.toJson() case final value?) - 'nestedExcludeIfNull': value, - }; - -const _$EnumValueEnumMap = { - EnumValue.first: '1', - EnumValue.second: 'second', + 'firstName': instance.firstName, + 'lastName': instance.lastName, + 'enumValue': _$EnumValueEnumMap[instance.enumValue], + 'nested': instance.nested?.toJson(), + 'nestedGeneric': instance.nestedGeneric?.toJson((value) => value), + if (instance.nestedExcludeIfNull?.toJson() case final value?) + 'nestedExcludeIfNull': value, }; -Nested _$NestedFromJson(Map<String, dynamic> json) => Nested( - json['value'] as String, - ); +const _$EnumValueEnumMap = {EnumValue.first: '1', EnumValue.second: 'second'}; + +Nested _$NestedFromJson(Map<String, dynamic> json) => + Nested(json['value'] as String); Map<String, dynamic> _$NestedToJson(Nested instance) => <String, dynamic>{ - 'value': instance.value, - }; + 'value': instance.value, +}; GenericFactory<T> _$GenericFactoryFromJson<T>( Map<String, dynamic> json, T Function(Object? json) fromJsonT, -) => - GenericFactory<T>( - fromJsonT(json['value']), - (json['map'] as Map<String, dynamic>).map( - (k, e) => MapEntry(k, fromJsonT(e)), - ), - ); +) => GenericFactory<T>( + fromJsonT(json['value']), + (json['map'] as Map<String, dynamic>).map( + (k, e) => MapEntry(k, fromJsonT(e)), + ), +); // ignore: unused_element abstract class _$GenericFactoryPerFieldToJson { // ignore: unused_element - static Object? value<T>( - T instance, - Object? Function(T value) toJsonT, - ) => + static Object? value<T>(T instance, Object? Function(T value) toJsonT) => toJsonT(instance); // ignore: unused_element static Object? map<T>( Map<String, T> instance, Object? Function(T value) toJsonT, - ) => - instance.map((k, e) => MapEntry(k, toJsonT(e))); + ) => instance.map((k, e) => MapEntry(k, toJsonT(e))); } Map<String, dynamic> _$GenericFactoryToJson<T>( GenericFactory<T> instance, Object? Function(T value) toJsonT, -) => - <String, dynamic>{ - 'value': toJsonT(instance.value), - 'map': instance.map.map((k, e) => MapEntry(k, toJsonT(e))), - }; +) => <String, dynamic>{ + 'value': toJsonT(instance.value), + 'map': instance.map.map((k, e) => MapEntry(k, toJsonT(e))), +}; // ignore: unused_element abstract class _$PrivateModelPerFieldToJson { @@ -113,6 +99,4 @@ abstract class _$PrivateModelPerFieldToJson { } Map<String, dynamic> _$PrivateModelToJson(_PrivateModel instance) => - <String, dynamic>{ - 'full-name': instance.fullName, - }; + <String, dynamic>{'full-name': instance.fullName}; diff --git a/json_serializable/test/integration/field_map_example.dart b/json_serializable/test/integration/field_map_example.dart index a9dba2475..3eef44693 100644 --- a/json_serializable/test/integration/field_map_example.dart +++ b/json_serializable/test/integration/field_map_example.dart @@ -4,11 +4,7 @@ part 'field_map_example.g.dart'; @JsonSerializable(createFieldMap: true, fieldRename: FieldRename.kebab) class Model { - Model({ - required this.firstName, - required this.lastName, - this.ignoredName, - }); + Model({required this.firstName, required this.lastName, this.ignoredName}); factory Model.fromJson(Map<String, Object?> json) => _$ModelFromJson(json); diff --git a/json_serializable/test/integration/field_map_example.g.dart b/json_serializable/test/integration/field_map_example.g.dart index d47e01793..fcf6cb864 100644 --- a/json_serializable/test/integration/field_map_example.g.dart +++ b/json_serializable/test/integration/field_map_example.g.dart @@ -9,9 +9,9 @@ part of 'field_map_example.dart'; // ************************************************************************** Model _$ModelFromJson(Map<String, dynamic> json) => Model( - firstName: json['first-name'] as String, - lastName: json['LAST_NAME'] as String, - ); + firstName: json['first-name'] as String, + lastName: json['LAST_NAME'] as String, +); const _$ModelFieldMap = <String, String>{ 'firstName': 'first-name', @@ -19,15 +19,11 @@ const _$ModelFieldMap = <String, String>{ }; Map<String, dynamic> _$ModelToJson(Model instance) => <String, dynamic>{ - 'first-name': instance.firstName, - 'LAST_NAME': instance.lastName, - }; - -const _$PrivateModelFieldMap = <String, String>{ - 'fullName': 'full-name', + 'first-name': instance.firstName, + 'LAST_NAME': instance.lastName, }; +const _$PrivateModelFieldMap = <String, String>{'fullName': 'full-name'}; + Map<String, dynamic> _$PrivateModelToJson(_PrivateModel instance) => - <String, dynamic>{ - 'full-name': instance.fullName, - }; + <String, dynamic>{'full-name': instance.fullName}; diff --git a/json_serializable/test/integration/integration_test.dart b/json_serializable/test/integration/integration_test.dart index 6aef150f2..9cc5d0948 100644 --- a/json_serializable/test/integration/integration_test.dart +++ b/json_serializable/test/integration/integration_test.dart @@ -24,13 +24,27 @@ void main() { } test('now', () { - roundTripPerson(Person('a', 'b', Category.charmed, - middleName: 'c', dateOfBirth: DateTime.now())); + roundTripPerson( + Person( + 'a', + 'b', + Category.charmed, + middleName: 'c', + dateOfBirth: DateTime.now(), + ), + ); }); test('now toUtc', () { - roundTripPerson(Person('a', 'b', Category.bottom, - middleName: 'c', dateOfBirth: DateTime.now().toUtc())); + roundTripPerson( + Person( + 'a', + 'b', + Category.bottom, + middleName: 'c', + dateOfBirth: DateTime.now().toUtc(), + ), + ); }); test('empty json', () { @@ -59,25 +73,30 @@ void main() { test('null', () { roundTripOrder( - Order.custom(Category.charmed)..statusCode = StatusCode.success); + Order.custom(Category.charmed)..statusCode = StatusCode.success, + ); }); test('empty', () { - roundTripOrder(Order.custom(Category.strange, const []) - ..statusCode = StatusCode.success - ..count = 0 - ..isRushed = false); + roundTripOrder( + Order.custom(Category.strange, const []) + ..statusCode = StatusCode.success + ..count = 0 + ..isRushed = false, + ); }); test('simple', () { - roundTripOrder(Order.custom(Category.top, <Item>[ - Item(24) - ..itemNumber = 42 - ..saleDates = [DateTime.now()] - ]) - ..statusCode = StatusCode.success - ..count = 42 - ..isRushed = true); + roundTripOrder( + Order.custom(Category.top, <Item>[ + Item(24) + ..itemNumber = 42 + ..saleDates = [DateTime.now()], + ]) + ..statusCode = StatusCode.success + ..count = 42 + ..isRushed = true, + ); }); test('almost empty json', () { @@ -94,29 +113,29 @@ void main() { test('required, but missing enum value fails', () { expect( - () => Person.fromJson({ - 'firstName': 'a', - 'lastName': 'b', - }), - _throwsArgumentError('A value must be provided. Supported values: ' - 'top, bottom, strange, charmed, up, down, not_discovered_yet')); + () => Person.fromJson({'firstName': 'a', 'lastName': 'b'}), + _throwsArgumentError( + 'A value must be provided. Supported values: ' + 'top, bottom, strange, charmed, up, down, not_discovered_yet', + ), + ); }); test('mismatched enum value fails', () { expect( - () => Order.fromJson({'category': 'weird'}), - _throwsArgumentError('`weird` is not one of the supported values: ' - 'top, bottom, strange, charmed, up, down, not_discovered_yet')); + () => Order.fromJson({'category': 'weird'}), + _throwsArgumentError( + '`weird` is not one of the supported values: ' + 'top, bottom, strange, charmed, up, down, not_discovered_yet', + ), + ); }); test('platform', () { final order = Order.custom(Category.charmed) ..statusCode = StatusCode.success ..platform = Platform.undefined - ..altPlatforms = { - 'u': Platform.undefined, - 'f': Platform.foo, - }; + ..altPlatforms = {'u': Platform.undefined, 'f': Platform.foo}; roundTripOrder(order); }); @@ -125,35 +144,35 @@ void main() { final order = Order.custom(Category.charmed) ..platform = Platform.undefined ..statusCode = StatusCode.success - ..altPlatforms = { - 'u': Platform.undefined, - 'f': Platform.foo, - } + ..altPlatforms = {'u': Platform.undefined, 'f': Platform.foo} ..homepage = Uri.parse('https://dart.dev'); roundTripOrder(order); }); test('statusCode', () { - final order = Order.fromJson( - {'category': 'not_discovered_yet', 'status_code': 404}, - ); + final order = Order.fromJson({ + 'category': 'not_discovered_yet', + 'status_code': 404, + }); expect(order.statusCode, StatusCode.notFound); roundTripOrder(order); }); test('statusCode "500" - weird', () { - final order = Order.fromJson( - {'category': 'not_discovered_yet', 'status_code': '500'}, - ); + final order = Order.fromJson({ + 'category': 'not_discovered_yet', + 'status_code': '500', + }); expect(order.statusCode, StatusCode.weird); roundTripOrder(order); }); test('statusCode `500` - unknown', () { - final order = Order.fromJson( - {'category': 'not_discovered_yet', 'status_code': 500}, - ); + final order = Order.fromJson({ + 'category': 'not_discovered_yet', + 'status_code': 500, + }); expect(order.statusCode, StatusCode.unknown); roundTripOrder(order); }); @@ -179,15 +198,18 @@ void main() { 'duration': 190473023012, }); expect( - order.duration, - equals(const Duration( + order.duration, + equals( + const Duration( days: 2, hours: 4, minutes: 54, seconds: 33, milliseconds: 23, microseconds: 12, - ))); + ), + ), + ); roundTripOrder(order); }); }); @@ -204,12 +226,7 @@ void main() { expect( item.toJson().keys, - orderedEquals([ - 'price', - 'saleDates', - 'rates', - 'geoPoint', - ]), + orderedEquals(['price', 'saleDates', 'rates', 'geoPoint']), reason: 'Omits null `itemNumber`', ); }); @@ -239,13 +256,15 @@ void main() { } test('simple', () { - roundTripNumber(Numbers() - ..nums = [0, 0.0] - ..doubles = [0.0] - ..nnDoubles = [0.0] - ..ints = [0] - ..duration = const Duration(seconds: 1) - ..date = DateTime.now()); + roundTripNumber( + Numbers() + ..nums = [0, 0.0] + ..doubles = [0.0] + ..nnDoubles = [0.0] + ..ints = [0] + ..duration = const Duration(seconds: 1) + ..date = DateTime.now(), + ); }); test('custom DateTime', () { @@ -313,17 +332,16 @@ void main() { expect(dayTypeEnumValues, ['no-good', 'rotten', 'very-bad']); }); - test( - 'serializing a non-nullable enum as a key in a map should produce a ' + test('serializing a non-nullable enum as a key in a map should produce a ' 'non-nullable string key', () { - final cls = - Issue1145RegressionA(status: {Issue1145RegressionEnum.gamma: true}); + final cls = Issue1145RegressionA( + status: {Issue1145RegressionEnum.gamma: true}, + ); // Due to issue 1145 this resulted in Map<String?, dynamic> expect(cls.toJson()['status'], const TypeMatcher<Map<String, dynamic>>()); }); - test( - 'serializing a nullable enum in a list should produce a list with' + test('serializing a nullable enum in a list should produce a list with' ' nullable entries', () { final cls = Issue1145RegressionB(status: [Issue1145RegressionEnum.gamma]); // Issue 1145 should not have affected nullable enums @@ -343,29 +361,19 @@ void main() { Issue559Regression.fromJson({'status': 'gamma'}).status, Issue559RegressionEnum.gamma, ); - expect( - Issue559Regression.fromJson({'status': 'bob'}).status, - isNull, - ); + expect(Issue559Regression.fromJson({'status': 'bob'}).status, isNull); }); test(r'_$ModelFieldMap', () { - expect( - modelFieldMap, - { - 'firstName': 'first-name', - 'lastName': 'LAST_NAME', - }, - ); + expect(modelFieldMap, {'firstName': 'first-name', 'lastName': 'LAST_NAME'}); }); - test(r'Generates _$PrivateModelFieldMap instead of __$PrivateModelFieldMap', - () { - expect( - privateModelFieldMap, - {'fullName': 'full-name'}, - ); - }); + test( + r'Generates _$PrivateModelFieldMap instead of __$PrivateModelFieldMap', + () { + expect(privateModelFieldMap, {'fullName': 'full-name'}); + }, + ); test(r'_$ModelPerFieldToJson', () { expect(ModelPerFieldToJson.firstName('foo'), 'foo'); @@ -375,18 +383,14 @@ void main() { expect(ModelPerFieldToJson.nested(Nested('foo')), {'value': 'foo'}); expect(ModelPerFieldToJson.nested(null), null); - expect( - ModelPerFieldToJson.nestedExcludeIfNull(Nested('foo')), - {'value': 'foo'}, - ); + expect(ModelPerFieldToJson.nestedExcludeIfNull(Nested('foo')), { + 'value': 'foo', + }); expect(ModelPerFieldToJson.nestedExcludeIfNull(null), null); - expect( - ModelPerFieldToJson.nestedGeneric(GenericFactory(42, {'key': 21})), - { - 'value': 42, - 'map': {'key': 21}, - }, - ); + expect(ModelPerFieldToJson.nestedGeneric(GenericFactory(42, {'key': 21})), { + 'value': 42, + 'map': {'key': 21}, + }); }); test(r'_$GenericFactoryPerFieldToJson', () { @@ -394,10 +398,7 @@ void main() { GenericFactoryPerFieldToJson.value<int>(42, (value) => '$value'), '42', ); - expect( - GenericFactoryPerFieldToJson.value<String>('42', int.tryParse), - 42, - ); + expect(GenericFactoryPerFieldToJson.value<String>('42', int.tryParse), 42); expect( GenericFactoryPerFieldToJson.map<int>({'foo': 21}, (value) => '$value'), diff --git a/json_serializable/test/integration/json_enum_example.dart b/json_serializable/test/integration/json_enum_example.dart index 9f8cee0a8..f36159cc1 100644 --- a/json_serializable/test/integration/json_enum_example.dart +++ b/json_serializable/test/integration/json_enum_example.dart @@ -17,11 +17,7 @@ enum StandAloneEnum { Iterable<String> get standAloneEnumValues => _$StandAloneEnumEnumMap.values; @JsonEnum(alwaysCreate: true, fieldRename: FieldRename.kebab) -enum DayType { - noGood, - rotten, - veryBad, -} +enum DayType { noGood, rotten, veryBad } Iterable<String> get dayTypeEnumValues => _$DayTypeEnumMap.values; @@ -55,13 +51,9 @@ enum EnumValueFieldIndex { Iterable<int> get enumValueFieldIndexValues => _$EnumValueFieldIndexEnumMap.values; -@JsonSerializable( - createToJson: false, -) +@JsonSerializable(createToJson: false) class Issue559Regression { - Issue559Regression({ - required this.status, - }); + Issue559Regression({required this.status}); factory Issue559Regression.fromJson(Map<String, dynamic> json) => _$Issue559RegressionFromJson(json); @@ -74,34 +66,20 @@ class Issue559Regression { final Issue559RegressionEnum? status; } -enum Issue559RegressionEnum { - alpha, - beta, - gamma, -} +enum Issue559RegressionEnum { alpha, beta, gamma } -enum Issue1145RegressionEnum { - alpha, - beta, - gamma, -} +enum Issue1145RegressionEnum { alpha, beta, gamma } -@JsonSerializable( - createFactory: false, -) +@JsonSerializable(createFactory: false) class Issue1145RegressionA { - Issue1145RegressionA({ - required this.status, - }); + Issue1145RegressionA({required this.status}); Map<String, dynamic> toJson() => _$Issue1145RegressionAToJson(this); final Map<Issue1145RegressionEnum, bool> status; } -@JsonSerializable( - createFactory: false, -) +@JsonSerializable(createFactory: false) class Issue1145RegressionB { Issue1145RegressionB({required this.status}); diff --git a/json_serializable/test/integration/json_enum_example.g.dart b/json_serializable/test/integration/json_enum_example.g.dart index 95ae41b17..3558c1a75 100644 --- a/json_serializable/test/integration/json_enum_example.g.dart +++ b/json_serializable/test/integration/json_enum_example.g.dart @@ -15,8 +15,11 @@ Issue559Regression _$Issue559RegressionFromJson(Map<String, dynamic> json) { disallowNullValues: const ['status'], ); return Issue559Regression( - status: $enumDecodeNullable(_$Issue559RegressionEnumEnumMap, json['status'], - unknownValue: JsonKey.nullForUndefinedEnumValue), + status: $enumDecodeNullable( + _$Issue559RegressionEnumEnumMap, + json['status'], + unknownValue: JsonKey.nullForUndefinedEnumValue, + ), ); } @@ -27,11 +30,12 @@ const _$Issue559RegressionEnumEnumMap = { }; Map<String, dynamic> _$Issue1145RegressionAToJson( - Issue1145RegressionA instance) => - <String, dynamic>{ - 'status': instance.status - .map((k, e) => MapEntry(_$Issue1145RegressionEnumEnumMap[k]!, e)), - }; + Issue1145RegressionA instance, +) => <String, dynamic>{ + 'status': instance.status.map( + (k, e) => MapEntry(_$Issue1145RegressionEnumEnumMap[k]!, e), + ), +}; const _$Issue1145RegressionEnumEnumMap = { Issue1145RegressionEnum.alpha: 'alpha', @@ -40,26 +44,27 @@ const _$Issue1145RegressionEnumEnumMap = { }; Map<String, dynamic> _$Issue1145RegressionBToJson( - Issue1145RegressionB instance) => - <String, dynamic>{ - 'status': instance.status - .map((e) => _$Issue1145RegressionEnumEnumMap[e]) - .toList(), - }; + Issue1145RegressionB instance, +) => <String, dynamic>{ + 'status': instance.status + .map((e) => _$Issue1145RegressionEnumEnumMap[e]) + .toList(), +}; Issue1226Regression _$Issue1226RegressionFromJson(Map<String, dynamic> json) => Issue1226Regression( durationType: $enumDecodeNullable( - _$Issue1145RegressionEnumEnumMap, json['durationType']), + _$Issue1145RegressionEnumEnumMap, + json['durationType'], + ), ); Map<String, dynamic> _$Issue1226RegressionToJson( - Issue1226Regression instance) => - <String, dynamic>{ - if (_$Issue1145RegressionEnumEnumMap[instance.durationType] - case final value?) - 'durationType': value, - }; + Issue1226Regression instance, +) => <String, dynamic>{ + if (_$Issue1145RegressionEnumEnumMap[instance.durationType] case final value?) + 'durationType': value, +}; const _$StandAloneEnumEnumMap = { StandAloneEnum.alpha: 'a', diff --git a/json_serializable/test/integration/json_keys_example.dart b/json_serializable/test/integration/json_keys_example.dart index e8a6895a2..985979d28 100644 --- a/json_serializable/test/integration/json_keys_example.dart +++ b/json_serializable/test/integration/json_keys_example.dart @@ -4,11 +4,7 @@ part 'json_keys_example.g.dart'; @JsonSerializable(createJsonKeys: true, fieldRename: FieldRename.kebab) class Model { - Model({ - required this.firstName, - required this.lastName, - this.ignoredName, - }); + Model({required this.firstName, required this.lastName, this.ignoredName}); factory Model.fromJson(Map<String, Object?> json) => _$ModelFromJson(json); diff --git a/json_serializable/test/integration/json_keys_example.g.dart b/json_serializable/test/integration/json_keys_example.g.dart index f68ca8d09..fc9429301 100644 --- a/json_serializable/test/integration/json_keys_example.g.dart +++ b/json_serializable/test/integration/json_keys_example.g.dart @@ -9,9 +9,9 @@ part of 'json_keys_example.dart'; // ************************************************************************** Model _$ModelFromJson(Map<String, dynamic> json) => Model( - firstName: json['first-name'] as String, - lastName: json['LAST_NAME'] as String, - ); + firstName: json['first-name'] as String, + lastName: json['LAST_NAME'] as String, +); abstract final class _$ModelJsonKeys { static const String firstName = 'first-name'; @@ -19,6 +19,6 @@ abstract final class _$ModelJsonKeys { } Map<String, dynamic> _$ModelToJson(Model instance) => <String, dynamic>{ - 'first-name': instance.firstName, - 'LAST_NAME': instance.lastName, - }; + 'first-name': instance.firstName, + 'LAST_NAME': instance.lastName, +}; diff --git a/json_serializable/test/integration/json_test_common.dart b/json_serializable/test/integration/json_test_common.dart index 27415fb81..95372161e 100644 --- a/json_serializable/test/integration/json_test_common.dart +++ b/json_serializable/test/integration/json_test_common.dart @@ -16,7 +16,7 @@ enum Category { down, // NOTE: this should override the kebab bits below! @JsonValue('not_discovered_yet') - notDiscoveredYet + notDiscoveredYet, } enum StatusCode { @@ -57,10 +57,10 @@ class Platform { const Platform._(this.description); factory Platform.fromJson(String value) => switch (value) { - 'foo' => foo, - 'undefined' => undefined, - _ => throw ArgumentError.value(value, 'value', 'Not a supported value.') - }; + 'foo' => foo, + 'undefined' => undefined, + _ => throw ArgumentError.value(value, 'value', 'Not a supported value.'), + }; String toJson() => description; } diff --git a/json_serializable/test/integration/json_test_example.dart b/json_serializable/test/integration/json_test_example.dart index 7f3482935..963cdc27e 100644 --- a/json_serializable/test/integration/json_test_example.dart +++ b/json_serializable/test/integration/json_test_example.dart @@ -27,8 +27,13 @@ class Person { Map<String, Category>? houseMap; Map<Category, int>? categoryCounts; - Person(this.firstName, this.lastName, this.house, - {this.middleName, this.dateOfBirth}); + Person( + this.firstName, + this.lastName, + this.house, { + this.middleName, + this.dateOfBirth, + }); factory Person.fromJson(Map<String, dynamic> json) => _$PersonFromJson(json); @@ -82,8 +87,9 @@ class Order { bool? shouldBeCached; Order.custom(this.category, [Iterable<Item>? items]) - : items = UnmodifiableListView<Item>( - List<Item>.unmodifiable(items ?? const <Item>[])); + : items = UnmodifiableListView<Item>( + List<Item>.unmodifiable(items ?? const <Item>[]), + ); factory Order.fromJson(Map<String, dynamic> json) => _$OrderFromJson(json); diff --git a/json_serializable/test/integration/json_test_example.g.dart b/json_serializable/test/integration/json_test_example.g.dart index bf56859ed..cd32ac924 100644 --- a/json_serializable/test/integration/json_test_example.g.dart +++ b/json_serializable/test/integration/json_test_example.g.dart @@ -8,23 +8,26 @@ part of 'json_test_example.dart'; // JsonSerializableGenerator // ************************************************************************** -Person _$PersonFromJson(Map<String, dynamic> json) => Person( - json['firstName'] as String, - json['lastName'] as String, - $enumDecode(_$CategoryEnumMap, json[r'$house']), - middleName: json['middleName'] as String?, - dateOfBirth: json['dateOfBirth'] == null - ? null - : DateTime.parse(json['dateOfBirth'] as String), - ) +Person _$PersonFromJson(Map<String, dynamic> json) => + Person( + json['firstName'] as String, + json['lastName'] as String, + $enumDecode(_$CategoryEnumMap, json[r'$house']), + middleName: json['middleName'] as String?, + dateOfBirth: json['dateOfBirth'] == null + ? null + : DateTime.parse(json['dateOfBirth'] as String), + ) ..order = json['order'] == null ? null : Order.fromJson(json['order'] as Map<String, dynamic>) ..customOrders = json['customOrders'] == null ? null - : MyList<Order>.fromJson((json['customOrders'] as List<dynamic>) - .map((e) => Order.fromJson(e as Map<String, dynamic>)) - .toList()) + : MyList<Order>.fromJson( + (json['customOrders'] as List<dynamic>) + .map((e) => Order.fromJson(e as Map<String, dynamic>)) + .toList(), + ) ..houseMap = (json['houseMap'] as Map<String, dynamic>?)?.map( (k, e) => MapEntry(k, $enumDecode(_$CategoryEnumMap, e)), ) @@ -34,18 +37,20 @@ Person _$PersonFromJson(Map<String, dynamic> json) => Person( ); Map<String, dynamic> _$PersonToJson(Person instance) => <String, dynamic>{ - 'firstName': instance.firstName, - 'lastName': instance.lastName, - 'middleName': instance.middleName, - 'dateOfBirth': instance.dateOfBirth?.toIso8601String(), - r'$house': _$CategoryEnumMap[instance.house]!, - 'order': instance.order, - 'customOrders': instance.customOrders, - 'houseMap': - instance.houseMap?.map((k, e) => MapEntry(k, _$CategoryEnumMap[e]!)), - 'categoryCounts': instance.categoryCounts - ?.map((k, e) => MapEntry(_$CategoryEnumMap[k]!, e)), - }; + 'firstName': instance.firstName, + 'lastName': instance.lastName, + 'middleName': instance.middleName, + 'dateOfBirth': instance.dateOfBirth?.toIso8601String(), + r'$house': _$CategoryEnumMap[instance.house]!, + 'order': instance.order, + 'customOrders': instance.customOrders, + 'houseMap': instance.houseMap?.map( + (k, e) => MapEntry(k, _$CategoryEnumMap[e]!), + ), + 'categoryCounts': instance.categoryCounts?.map( + (k, e) => MapEntry(_$CategoryEnumMap[k]!, e), + ), +}; const _$CategoryEnumMap = { Category.top: 'top', @@ -58,15 +63,13 @@ const _$CategoryEnumMap = { }; Order _$OrderFromJson(Map<String, dynamic> json) { - $checkKeys( - json, - disallowNullValues: const ['count'], - ); + $checkKeys(json, disallowNullValues: const ['count']); return Order.custom( - $enumDecodeNullable(_$CategoryEnumMap, json['category']), - (json['items'] as List<dynamic>?) - ?.map((e) => Item.fromJson(e as Map<String, dynamic>)), - ) + $enumDecodeNullable(_$CategoryEnumMap, json['category']), + (json['items'] as List<dynamic>?)?.map( + (e) => Item.fromJson(e as Map<String, dynamic>), + ), + ) ..count = (json['count'] as num?)?.toInt() ..isRushed = json['isRushed'] as bool? ..duration = json['duration'] == null @@ -78,24 +81,29 @@ Order _$OrderFromJson(Map<String, dynamic> json) { ..altPlatforms = (json['altPlatforms'] as Map<String, dynamic>?)?.map( (k, e) => MapEntry(k, Platform.fromJson(e as String)), ) - ..homepage = - json['homepage'] == null ? null : Uri.parse(json['homepage'] as String) - ..statusCode = $enumDecodeNullable(_$StatusCodeEnumMap, json['status_code'], - unknownValue: StatusCode.unknown) ?? + ..homepage = json['homepage'] == null + ? null + : Uri.parse(json['homepage'] as String) + ..statusCode = + $enumDecodeNullable( + _$StatusCodeEnumMap, + json['status_code'], + unknownValue: StatusCode.unknown, + ) ?? StatusCode.success; } Map<String, dynamic> _$OrderToJson(Order instance) => <String, dynamic>{ - if (instance.count case final value?) 'count': value, - 'isRushed': instance.isRushed, - 'duration': instance.duration?.inMicroseconds, - 'category': _$CategoryEnumMap[instance.category], - 'items': instance.items, - 'platform': instance.platform, - 'altPlatforms': instance.altPlatforms, - 'homepage': instance.homepage?.toString(), - 'status_code': _$StatusCodeEnumMap[instance.statusCode], - }; + if (instance.count case final value?) 'count': value, + 'isRushed': instance.isRushed, + 'duration': instance.duration?.inMicroseconds, + 'category': _$CategoryEnumMap[instance.category], + 'items': instance.items, + 'platform': instance.platform, + 'altPlatforms': instance.altPlatforms, + 'homepage': instance.homepage?.toString(), + 'status_code': _$StatusCodeEnumMap[instance.statusCode], +}; const _$StatusCodeEnumMap = { StatusCode.success: 200, @@ -104,9 +112,8 @@ const _$StatusCodeEnumMap = { StatusCode.unknown: 'unknown', }; -Item _$ItemFromJson(Map<String, dynamic> json) => Item( - (json['price'] as num?)?.toInt(), - ) +Item _$ItemFromJson(Map<String, dynamic> json) => + Item((json['price'] as num?)?.toInt()) ..itemNumber = (json['item-number'] as num?)?.toInt() ..saleDates = (json['saleDates'] as List<dynamic>?) ?.map((e) => DateTime.parse(e as String)) @@ -117,16 +124,17 @@ Item _$ItemFromJson(Map<String, dynamic> json) => Item( ..geoPoint = _fromJsonGeoPoint(json['geoPoint'] as Map<String, dynamic>?); Map<String, dynamic> _$ItemToJson(Item instance) => <String, dynamic>{ - 'price': instance.price, - if (instance.itemNumber case final value?) 'item-number': value, - 'saleDates': instance.saleDates?.map((e) => e.toIso8601String()).toList(), - 'rates': instance.rates, - 'geoPoint': _toJsonGeoPoint(instance.geoPoint), - }; + 'price': instance.price, + if (instance.itemNumber case final value?) 'item-number': value, + 'saleDates': instance.saleDates?.map((e) => e.toIso8601String()).toList(), + 'rates': instance.rates, + 'geoPoint': _toJsonGeoPoint(instance.geoPoint), +}; Numbers _$NumbersFromJson(Map<String, dynamic> json) => Numbers() - ..ints = - (json['ints'] as List<dynamic>?)?.map((e) => (e as num).toInt()).toList() + ..ints = (json['ints'] as List<dynamic>?) + ?.map((e) => (e as num).toInt()) + .toList() ..nums = (json['nums'] as List<dynamic>?)?.map((e) => e as num).toList() ..doubles = (json['doubles'] as List<dynamic>?) ?.map((e) => (e as num).toDouble()) @@ -135,19 +143,20 @@ Numbers _$NumbersFromJson(Map<String, dynamic> json) => Numbers() ?.map((e) => (e as num).toDouble()) .toList() ..duration = durationFromInt((json['duration'] as num?)?.toInt()) - ..doubleAsString = - stringFromDouble((json['doubleAsString'] as num?)?.toDouble()) + ..doubleAsString = stringFromDouble( + (json['doubleAsString'] as num?)?.toDouble(), + ) ..date = dateTimeFromEpochUs((json['date'] as num?)?.toInt()); Map<String, dynamic> _$NumbersToJson(Numbers instance) => <String, dynamic>{ - 'ints': instance.ints, - 'nums': instance.nums, - 'doubles': instance.doubles, - 'nnDoubles': instance.nnDoubles, - 'duration': durationToInt(instance.duration), - 'doubleAsString': stringToDouble(instance.doubleAsString), - 'date': dateTimeToEpochUs(instance.date), - }; + 'ints': instance.ints, + 'nums': instance.nums, + 'doubles': instance.doubles, + 'nnDoubles': instance.nnDoubles, + 'duration': durationToInt(instance.duration), + 'doubleAsString': stringToDouble(instance.doubleAsString), + 'date': dateTimeToEpochUs(instance.date), +}; MapKeyVariety _$MapKeyVarietyFromJson(Map<String, dynamic> json) => MapKeyVariety() @@ -168,47 +177,55 @@ Map<String, dynamic> _$MapKeyVarietyToJson(MapKeyVariety instance) => <String, dynamic>{ 'intIntMap': instance.intIntMap?.map((k, e) => MapEntry(k.toString(), e)), 'uriIntMap': instance.uriIntMap?.map((k, e) => MapEntry(k.toString(), e)), - 'dateTimeIntMap': instance.dateTimeIntMap - ?.map((k, e) => MapEntry(k.toIso8601String(), e)), + 'dateTimeIntMap': instance.dateTimeIntMap?.map( + (k, e) => MapEntry(k.toIso8601String(), e), + ), 'bigIntMap': instance.bigIntMap?.map((k, e) => MapEntry(k.toString(), e)), }; UnknownEnumValue _$UnknownEnumValueFromJson(Map<String, dynamic> json) => UnknownEnumValue() - ..enumValue = $enumDecode(_$CategoryEnumMap, json['enumValue'], - unknownValue: Category.notDiscoveredYet) - ..enumIterable = (json['enumIterable'] as List<dynamic>).map((e) => - $enumDecode(_$CategoryEnumMap, e, - unknownValue: Category.notDiscoveredYet)) + ..enumValue = $enumDecode( + _$CategoryEnumMap, + json['enumValue'], + unknownValue: Category.notDiscoveredYet, + ) + ..enumIterable = (json['enumIterable'] as List<dynamic>).map( + (e) => $enumDecode( + _$CategoryEnumMap, + e, + unknownValue: Category.notDiscoveredYet, + ), + ) ..enumList = (json['enumList'] as List<dynamic>) - .map((e) => $enumDecode(_$CategoryEnumMap, e, - unknownValue: Category.notDiscoveredYet)) + .map( + (e) => $enumDecode( + _$CategoryEnumMap, + e, + unknownValue: Category.notDiscoveredYet, + ), + ) .toList() ..enumSet = (json['enumSet'] as List<dynamic>) - .map((e) => $enumDecode(_$CategoryEnumMap, e, - unknownValue: Category.notDiscoveredYet)) + .map( + (e) => $enumDecode( + _$CategoryEnumMap, + e, + unknownValue: Category.notDiscoveredYet, + ), + ) .toSet(); PrivateConstructor _$PrivateConstructorFromJson(Map<String, dynamic> json) => - PrivateConstructor._( - (json['id'] as num).toInt(), - json['value'] as String, - ); + PrivateConstructor._((json['id'] as num).toInt(), json['value'] as String); Map<String, dynamic> _$PrivateConstructorToJson(PrivateConstructor instance) => - <String, dynamic>{ - 'id': instance.id, - 'value': instance.value, - }; + <String, dynamic>{'id': instance.id, 'value': instance.value}; RegressionTestIssue1210 _$RegressionTestIssue1210FromJson( - Map<String, dynamic> json) => - RegressionTestIssue1210( - json['field'] as String, - ); + Map<String, dynamic> json, +) => RegressionTestIssue1210(json['field'] as String); Map<String, dynamic> _$RegressionTestIssue1210ToJson( - RegressionTestIssue1210 instance) => - <String, dynamic>{ - 'field': instance.field, - }; + RegressionTestIssue1210 instance, +) => <String, dynamic>{'field': instance.field}; diff --git a/json_serializable/test/integration/json_test_example.g_any_map.dart b/json_serializable/test/integration/json_test_example.g_any_map.dart index b4789725d..f499eb13d 100644 --- a/json_serializable/test/integration/json_test_example.g_any_map.dart +++ b/json_serializable/test/integration/json_test_example.g_any_map.dart @@ -12,9 +12,7 @@ import 'json_test_common.dart'; part 'json_test_example.g_any_map.g.dart'; -@JsonSerializable( - anyMap: true, -) +@JsonSerializable(anyMap: true) class Person { final String firstName, lastName; final String? middleName; @@ -29,8 +27,13 @@ class Person { Map<String, Category>? houseMap; Map<Category, int>? categoryCounts; - Person(this.firstName, this.lastName, this.house, - {this.middleName, this.dateOfBirth}); + Person( + this.firstName, + this.lastName, + this.house, { + this.middleName, + this.dateOfBirth, + }); factory Person.fromJson(Map<String, dynamic> json) => _$PersonFromJson(json); @@ -84,8 +87,9 @@ class Order { bool? shouldBeCached; Order.custom(this.category, [Iterable<Item>? items]) - : items = UnmodifiableListView<Item>( - List<Item>.unmodifiable(items ?? const <Item>[])); + : items = UnmodifiableListView<Item>( + List<Item>.unmodifiable(items ?? const <Item>[]), + ); factory Order.fromJson(Map<String, dynamic> json) => _$OrderFromJson(json); @@ -100,9 +104,7 @@ class Order { deepEquals(altPlatforms, other.altPlatforms); } -@JsonSerializable( - anyMap: true, -) +@JsonSerializable(anyMap: true) class Item extends ItemCore { @JsonKey(includeIfNull: false, name: 'item-number') int? itemNumber; @@ -148,9 +150,7 @@ class GeoPoint { GeoPoint(this.latitude, this.longitude); } -@JsonSerializable( - anyMap: true, -) +@JsonSerializable(anyMap: true) class Numbers { List<int>? ints; List<num>? nums; @@ -185,9 +185,7 @@ class Numbers { deepEquals(date, other.date); } -@JsonSerializable( - anyMap: true, -) +@JsonSerializable(anyMap: true) class MapKeyVariety { Map<int, int>? intIntMap; Map<Uri, int>? uriIntMap; @@ -258,9 +256,7 @@ mixin RegressionTestIssue1210Mixin { int get hashCode => identityHashCode(this); } -@JsonSerializable( - anyMap: true, -) +@JsonSerializable(anyMap: true) class RegressionTestIssue1210 with RegressionTestIssue1210Mixin { const RegressionTestIssue1210(this.field); diff --git a/json_serializable/test/integration/json_test_example.g_any_map.g.dart b/json_serializable/test/integration/json_test_example.g_any_map.g.dart index ef2ad4f95..f277591ba 100644 --- a/json_serializable/test/integration/json_test_example.g_any_map.g.dart +++ b/json_serializable/test/integration/json_test_example.g_any_map.g.dart @@ -8,23 +8,28 @@ part of 'json_test_example.g_any_map.dart'; // JsonSerializableGenerator // ************************************************************************** -Person _$PersonFromJson(Map json) => Person( - json['firstName'] as String, - json['lastName'] as String, - $enumDecode(_$CategoryEnumMap, json[r'$house']), - middleName: json['middleName'] as String?, - dateOfBirth: json['dateOfBirth'] == null - ? null - : DateTime.parse(json['dateOfBirth'] as String), - ) +Person _$PersonFromJson(Map json) => + Person( + json['firstName'] as String, + json['lastName'] as String, + $enumDecode(_$CategoryEnumMap, json[r'$house']), + middleName: json['middleName'] as String?, + dateOfBirth: json['dateOfBirth'] == null + ? null + : DateTime.parse(json['dateOfBirth'] as String), + ) ..order = json['order'] == null ? null : Order.fromJson(Map<String, dynamic>.from(json['order'] as Map)) ..customOrders = json['customOrders'] == null ? null - : MyList<Order>.fromJson((json['customOrders'] as List<dynamic>) - .map((e) => Order.fromJson(Map<String, dynamic>.from(e as Map))) - .toList()) + : MyList<Order>.fromJson( + (json['customOrders'] as List<dynamic>) + .map( + (e) => Order.fromJson(Map<String, dynamic>.from(e as Map)), + ) + .toList(), + ) ..houseMap = (json['houseMap'] as Map?)?.map( (k, e) => MapEntry(k as String, $enumDecode(_$CategoryEnumMap, e)), ) @@ -34,18 +39,20 @@ Person _$PersonFromJson(Map json) => Person( ); Map<String, dynamic> _$PersonToJson(Person instance) => <String, dynamic>{ - 'firstName': instance.firstName, - 'lastName': instance.lastName, - 'middleName': instance.middleName, - 'dateOfBirth': instance.dateOfBirth?.toIso8601String(), - r'$house': _$CategoryEnumMap[instance.house]!, - 'order': instance.order, - 'customOrders': instance.customOrders, - 'houseMap': - instance.houseMap?.map((k, e) => MapEntry(k, _$CategoryEnumMap[e]!)), - 'categoryCounts': instance.categoryCounts - ?.map((k, e) => MapEntry(_$CategoryEnumMap[k]!, e)), - }; + 'firstName': instance.firstName, + 'lastName': instance.lastName, + 'middleName': instance.middleName, + 'dateOfBirth': instance.dateOfBirth?.toIso8601String(), + r'$house': _$CategoryEnumMap[instance.house]!, + 'order': instance.order, + 'customOrders': instance.customOrders, + 'houseMap': instance.houseMap?.map( + (k, e) => MapEntry(k, _$CategoryEnumMap[e]!), + ), + 'categoryCounts': instance.categoryCounts?.map( + (k, e) => MapEntry(_$CategoryEnumMap[k]!, e), + ), +}; const _$CategoryEnumMap = { Category.top: 'top', @@ -58,15 +65,13 @@ const _$CategoryEnumMap = { }; Order _$OrderFromJson(Map json) { - $checkKeys( - json, - disallowNullValues: const ['count'], - ); + $checkKeys(json, disallowNullValues: const ['count']); return Order.custom( - $enumDecodeNullable(_$CategoryEnumMap, json['category']), - (json['items'] as List<dynamic>?) - ?.map((e) => Item.fromJson(Map<String, dynamic>.from(e as Map))), - ) + $enumDecodeNullable(_$CategoryEnumMap, json['category']), + (json['items'] as List<dynamic>?)?.map( + (e) => Item.fromJson(Map<String, dynamic>.from(e as Map)), + ), + ) ..count = (json['count'] as num?)?.toInt() ..isRushed = json['isRushed'] as bool? ..duration = json['duration'] == null @@ -78,24 +83,29 @@ Order _$OrderFromJson(Map json) { ..altPlatforms = (json['altPlatforms'] as Map?)?.map( (k, e) => MapEntry(k as String, Platform.fromJson(e as String)), ) - ..homepage = - json['homepage'] == null ? null : Uri.parse(json['homepage'] as String) - ..statusCode = $enumDecodeNullable(_$StatusCodeEnumMap, json['status_code'], - unknownValue: StatusCode.unknown) ?? + ..homepage = json['homepage'] == null + ? null + : Uri.parse(json['homepage'] as String) + ..statusCode = + $enumDecodeNullable( + _$StatusCodeEnumMap, + json['status_code'], + unknownValue: StatusCode.unknown, + ) ?? StatusCode.success; } Map<String, dynamic> _$OrderToJson(Order instance) => <String, dynamic>{ - if (instance.count case final value?) 'count': value, - 'isRushed': instance.isRushed, - 'duration': instance.duration?.inMicroseconds, - 'category': _$CategoryEnumMap[instance.category], - 'items': instance.items, - 'platform': instance.platform, - 'altPlatforms': instance.altPlatforms, - 'homepage': instance.homepage?.toString(), - 'status_code': _$StatusCodeEnumMap[instance.statusCode], - }; + if (instance.count case final value?) 'count': value, + 'isRushed': instance.isRushed, + 'duration': instance.duration?.inMicroseconds, + 'category': _$CategoryEnumMap[instance.category], + 'items': instance.items, + 'platform': instance.platform, + 'altPlatforms': instance.altPlatforms, + 'homepage': instance.homepage?.toString(), + 'status_code': _$StatusCodeEnumMap[instance.statusCode], +}; const _$StatusCodeEnumMap = { StatusCode.success: 200, @@ -104,29 +114,28 @@ const _$StatusCodeEnumMap = { StatusCode.unknown: 'unknown', }; -Item _$ItemFromJson(Map json) => Item( - (json['price'] as num?)?.toInt(), - ) - ..itemNumber = (json['item-number'] as num?)?.toInt() - ..saleDates = (json['saleDates'] as List<dynamic>?) - ?.map((e) => DateTime.parse(e as String)) - .toList() - ..rates = (json['rates'] as List<dynamic>?) - ?.map((e) => (e as num).toInt()) - .toList() - ..geoPoint = _fromJsonGeoPoint(json['geoPoint'] as Map<String, dynamic>?); +Item _$ItemFromJson(Map json) => Item((json['price'] as num?)?.toInt()) + ..itemNumber = (json['item-number'] as num?)?.toInt() + ..saleDates = (json['saleDates'] as List<dynamic>?) + ?.map((e) => DateTime.parse(e as String)) + .toList() + ..rates = (json['rates'] as List<dynamic>?) + ?.map((e) => (e as num).toInt()) + .toList() + ..geoPoint = _fromJsonGeoPoint(json['geoPoint'] as Map<String, dynamic>?); Map<String, dynamic> _$ItemToJson(Item instance) => <String, dynamic>{ - 'price': instance.price, - if (instance.itemNumber case final value?) 'item-number': value, - 'saleDates': instance.saleDates?.map((e) => e.toIso8601String()).toList(), - 'rates': instance.rates, - 'geoPoint': _toJsonGeoPoint(instance.geoPoint), - }; + 'price': instance.price, + if (instance.itemNumber case final value?) 'item-number': value, + 'saleDates': instance.saleDates?.map((e) => e.toIso8601String()).toList(), + 'rates': instance.rates, + 'geoPoint': _toJsonGeoPoint(instance.geoPoint), +}; Numbers _$NumbersFromJson(Map json) => Numbers() - ..ints = - (json['ints'] as List<dynamic>?)?.map((e) => (e as num).toInt()).toList() + ..ints = (json['ints'] as List<dynamic>?) + ?.map((e) => (e as num).toInt()) + .toList() ..nums = (json['nums'] as List<dynamic>?)?.map((e) => e as num).toList() ..doubles = (json['doubles'] as List<dynamic>?) ?.map((e) => (e as num).toDouble()) @@ -135,19 +144,20 @@ Numbers _$NumbersFromJson(Map json) => Numbers() ?.map((e) => (e as num).toDouble()) .toList() ..duration = durationFromInt((json['duration'] as num?)?.toInt()) - ..doubleAsString = - stringFromDouble((json['doubleAsString'] as num?)?.toDouble()) + ..doubleAsString = stringFromDouble( + (json['doubleAsString'] as num?)?.toDouble(), + ) ..date = dateTimeFromEpochUs((json['date'] as num?)?.toInt()); Map<String, dynamic> _$NumbersToJson(Numbers instance) => <String, dynamic>{ - 'ints': instance.ints, - 'nums': instance.nums, - 'doubles': instance.doubles, - 'nnDoubles': instance.nnDoubles, - 'duration': durationToInt(instance.duration), - 'doubleAsString': stringToDouble(instance.doubleAsString), - 'date': dateTimeToEpochUs(instance.date), - }; + 'ints': instance.ints, + 'nums': instance.nums, + 'doubles': instance.doubles, + 'nnDoubles': instance.nnDoubles, + 'duration': durationToInt(instance.duration), + 'doubleAsString': stringToDouble(instance.doubleAsString), + 'date': dateTimeToEpochUs(instance.date), +}; MapKeyVariety _$MapKeyVarietyFromJson(Map json) => MapKeyVariety() ..intIntMap = (json['intIntMap'] as Map?)?.map( @@ -167,45 +177,53 @@ Map<String, dynamic> _$MapKeyVarietyToJson(MapKeyVariety instance) => <String, dynamic>{ 'intIntMap': instance.intIntMap?.map((k, e) => MapEntry(k.toString(), e)), 'uriIntMap': instance.uriIntMap?.map((k, e) => MapEntry(k.toString(), e)), - 'dateTimeIntMap': instance.dateTimeIntMap - ?.map((k, e) => MapEntry(k.toIso8601String(), e)), + 'dateTimeIntMap': instance.dateTimeIntMap?.map( + (k, e) => MapEntry(k.toIso8601String(), e), + ), 'bigIntMap': instance.bigIntMap?.map((k, e) => MapEntry(k.toString(), e)), }; UnknownEnumValue _$UnknownEnumValueFromJson(Map json) => UnknownEnumValue() - ..enumValue = $enumDecode(_$CategoryEnumMap, json['enumValue'], - unknownValue: Category.notDiscoveredYet) - ..enumIterable = (json['enumIterable'] as List<dynamic>).map((e) => - $enumDecode(_$CategoryEnumMap, e, - unknownValue: Category.notDiscoveredYet)) + ..enumValue = $enumDecode( + _$CategoryEnumMap, + json['enumValue'], + unknownValue: Category.notDiscoveredYet, + ) + ..enumIterable = (json['enumIterable'] as List<dynamic>).map( + (e) => $enumDecode( + _$CategoryEnumMap, + e, + unknownValue: Category.notDiscoveredYet, + ), + ) ..enumList = (json['enumList'] as List<dynamic>) - .map((e) => $enumDecode(_$CategoryEnumMap, e, - unknownValue: Category.notDiscoveredYet)) + .map( + (e) => $enumDecode( + _$CategoryEnumMap, + e, + unknownValue: Category.notDiscoveredYet, + ), + ) .toList() ..enumSet = (json['enumSet'] as List<dynamic>) - .map((e) => $enumDecode(_$CategoryEnumMap, e, - unknownValue: Category.notDiscoveredYet)) + .map( + (e) => $enumDecode( + _$CategoryEnumMap, + e, + unknownValue: Category.notDiscoveredYet, + ), + ) .toSet(); PrivateConstructor _$PrivateConstructorFromJson(Map json) => - PrivateConstructor._( - (json['id'] as num).toInt(), - json['value'] as String, - ); + PrivateConstructor._((json['id'] as num).toInt(), json['value'] as String); Map<String, dynamic> _$PrivateConstructorToJson(PrivateConstructor instance) => - <String, dynamic>{ - 'id': instance.id, - 'value': instance.value, - }; + <String, dynamic>{'id': instance.id, 'value': instance.value}; RegressionTestIssue1210 _$RegressionTestIssue1210FromJson(Map json) => - RegressionTestIssue1210( - json['field'] as String, - ); + RegressionTestIssue1210(json['field'] as String); Map<String, dynamic> _$RegressionTestIssue1210ToJson( - RegressionTestIssue1210 instance) => - <String, dynamic>{ - 'field': instance.field, - }; + RegressionTestIssue1210 instance, +) => <String, dynamic>{'field': instance.field}; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.dart b/json_serializable/test/kitchen_sink/kitchen_sink.dart index 86525d9c8..d9a304478 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.dart @@ -48,33 +48,32 @@ class _Factory implements k.KitchenSinkFactory<String, dynamic> { Iterable<Object>? objectIterable, Iterable<int>? intIterable, Iterable<DateTime>? dateTimeIterable, - }) => - KitchenSink( - ctorValidatedNo42: ctorValidatedNo42, - iterable: iterable, - dynamicIterable: dynamicIterable, - objectIterable: objectIterable, - intIterable: intIterable, - dateTimeIterable: dateTimeIterable, - ); + }) => KitchenSink( + ctorValidatedNo42: ctorValidatedNo42, + iterable: iterable, + dynamicIterable: dynamicIterable, + objectIterable: objectIterable, + intIterable: intIterable, + dateTimeIterable: dateTimeIterable, + ); k.KitchenSink fromJson(Map<String, dynamic> json) => KitchenSink.fromJson(json); k.JsonConverterTestClass jsonConverterCtor() => JsonConverterTestClass( - const Duration(), - [], - BigInt.zero, - {}, - BigInt.zero, - {}, - TrivialNumber(0), - {}, - DateTime.fromMillisecondsSinceEpoch(0), - TrivialString(''), - TrivialNumber(0), - {}, - ); + const Duration(), + [], + BigInt.zero, + {}, + BigInt.zero, + {}, + TrivialNumber(0), + {}, + DateTime.fromMillisecondsSinceEpoch(0), + TrivialString(''), + TrivialNumber(0), + {}, + ); k.JsonConverterTestClass jsonConverterFromJson(Map<String, dynamic> json) => JsonConverterTestClass.fromJson(json); @@ -108,14 +107,17 @@ class KitchenSink implements k.KitchenSink { Iterable<Object>? objectIterable, Iterable<int>? intIterable, Iterable<DateTime>? dateTimeIterable, - }) : _iterable = iterable?.toList(), - _dynamicIterable = dynamicIterable?.toList() ?? _defaultList(), - _objectIterable = objectIterable?.toList() ?? _defaultList(), - _intIterable = intIterable?.toList() ?? _defaultList(), - _dateTimeIterable = dateTimeIterable?.toList() ?? _defaultList() { + }) : _iterable = iterable?.toList(), + _dynamicIterable = dynamicIterable?.toList() ?? _defaultList(), + _objectIterable = objectIterable?.toList() ?? _defaultList(), + _intIterable = intIterable?.toList() ?? _defaultList(), + _dateTimeIterable = dateTimeIterable?.toList() ?? _defaultList() { if (ctorValidatedNo42 == 42) { throw ArgumentError.value( - 42, 'ctorValidatedNo42', 'The value `42` is not allowed.'); + 42, + 'ctorValidatedNo42', + 'The value `42` is not allowed.', + ); } } @@ -197,12 +199,14 @@ class KitchenSink implements k.KitchenSink { } } -@JsonSerializable(converters: [ - // referencing a top-level field should work - durationConverter, - // referencing via a const constructor should work - BigIntStringConverter(), -]) +@JsonSerializable( + converters: [ + // referencing a top-level field should work + durationConverter, + // referencing via a const constructor should work + BigIntStringConverter(), + ], +) // referencing a top-level field should work @trivialStringConverter @TrivialNumberConverter.instance @@ -256,11 +260,7 @@ class JsonConverterGeneric<S, T, U> { List<T> itemList; Map<String, U> itemMap; - JsonConverterGeneric( - this.item, - this.itemList, - this.itemMap, - ); + JsonConverterGeneric(this.item, this.itemList, this.itemMap); factory JsonConverterGeneric.fromJson(Map<String, dynamic> json) => _$JsonConverterGenericFromJson(json); diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g.dart index 6d376fdfe..0e2d4e93b 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g.dart @@ -8,26 +8,32 @@ part of 'kitchen_sink.dart'; // JsonSerializableGenerator // ************************************************************************** -KitchenSink _$KitchenSinkFromJson(Map<String, dynamic> json) => KitchenSink( - ctorValidatedNo42: (json['no-42'] as num?)?.toInt(), - iterable: _valueAccessor(json, 'iterable') as List<dynamic>?, - dynamicIterable: json['dynamicIterable'] as List<dynamic>?, - objectIterable: - (json['objectIterable'] as List<dynamic>?)?.map((e) => e as Object), - intIterable: (json['intIterable'] as List<dynamic>?) - ?.map((e) => (e as num).toInt()), - dateTimeIterable: (json['datetime-iterable'] as List<dynamic>?) - ?.map((e) => DateTime.parse(e as String)), - ) +KitchenSink _$KitchenSinkFromJson(Map<String, dynamic> json) => + KitchenSink( + ctorValidatedNo42: (json['no-42'] as num?)?.toInt(), + iterable: _valueAccessor(json, 'iterable') as List<dynamic>?, + dynamicIterable: json['dynamicIterable'] as List<dynamic>?, + objectIterable: (json['objectIterable'] as List<dynamic>?)?.map( + (e) => e as Object, + ), + intIterable: (json['intIterable'] as List<dynamic>?)?.map( + (e) => (e as num).toInt(), + ), + dateTimeIterable: (json['datetime-iterable'] as List<dynamic>?)?.map( + (e) => DateTime.parse(e as String), + ), + ) ..dateTime = json['dateTime'] == null ? null : DateTime.parse(json['dateTime'] as String) - ..bigInt = - json['bigInt'] == null ? null : BigInt.parse(json['bigInt'] as String) + ..bigInt = json['bigInt'] == null + ? null + : BigInt.parse(json['bigInt'] as String) ..set = (json['set'] as List<dynamic>).toSet() ..dynamicSet = (json['dynamicSet'] as List<dynamic>).toSet() - ..objectSet = - (json['objectSet'] as List<dynamic>).map((e) => e as Object).toSet() + ..objectSet = (json['objectSet'] as List<dynamic>) + .map((e) => e as Object) + .toSet() ..intSet = (json['intSet'] as List<dynamic>) .map((e) => (e as num).toInt()) .toSet() @@ -36,8 +42,9 @@ KitchenSink _$KitchenSinkFromJson(Map<String, dynamic> json) => KitchenSink( .toSet() ..list = json['list'] as List<dynamic> ..dynamicList = json['dynamicList'] as List<dynamic> - ..objectList = - (json['objectList'] as List<dynamic>).map((e) => e as Object).toList() + ..objectList = (json['objectList'] as List<dynamic>) + .map((e) => e as Object) + .toList() ..intList = (json['intList'] as List<dynamic>) .map((e) => (e as num).toInt()) .toList() @@ -46,48 +53,58 @@ KitchenSink _$KitchenSinkFromJson(Map<String, dynamic> json) => KitchenSink( .toList() ..nullableSimpleObjectList = (json['nullableSimpleObjectList'] as List<dynamic>) - .map((e) => e == null - ? null - : SimpleObject.fromJson(e as Map<String, dynamic>)) + .map( + (e) => e == null + ? null + : SimpleObject.fromJson(e as Map<String, dynamic>), + ) .toList() ..map = json['map'] as Map<String, dynamic> - ..stringStringMap = - Map<String, String>.from(json['stringStringMap'] as Map) - ..dynamicIntMap = Map<String, int>.from(json['dynamicIntMap'] as Map) - ..objectDateTimeMap = - (json['objectDateTimeMap'] as Map<String, dynamic>).map( - (k, e) => MapEntry(k, DateTime.parse(e as String)), + ..stringStringMap = Map<String, String>.from( + json['stringStringMap'] as Map, ) + ..dynamicIntMap = Map<String, int>.from(json['dynamicIntMap'] as Map) + ..objectDateTimeMap = (json['objectDateTimeMap'] as Map<String, dynamic>) + .map((k, e) => MapEntry(k, DateTime.parse(e as String))) ..nullableSimpleObjectMap = (json['nullableSimpleObjectMap'] as Map<String, dynamic>).map( - (k, e) => MapEntry( - k, - e == null - ? null - : SimpleObject.fromJson(e as Map<String, dynamic>)), - ) + (k, e) => MapEntry( + k, + e == null + ? null + : SimpleObject.fromJson(e as Map<String, dynamic>), + ), + ) ..crazyComplex = (json['crazyComplex'] as List<dynamic>) - .map((e) => (e as Map<String, dynamic>?)?.map( - (k, e) => MapEntry( + .map( + (e) => (e as Map<String, dynamic>?)?.map( + (k, e) => MapEntry( + k, + (e as Map<String, dynamic>?)?.map( + (k, e) => MapEntry( k, - (e as Map<String, dynamic>?)?.map( - (k, e) => MapEntry( - k, - (e as List<dynamic>?) - ?.map((e) => (e as List<dynamic>?) - ?.map((e) => DateTime.parse(e as String)) - .toList()) - .toList()), - )), - )) + (e as List<dynamic>?) + ?.map( + (e) => (e as List<dynamic>?) + ?.map((e) => DateTime.parse(e as String)) + .toList(), + ) + .toList(), + ), + ), + ), + ), + ) .toList() ..val = Map<String, bool>.from(json['val'] as Map) ..writeNotNull = json['writeNotNull'] as bool? ..string = KitchenSink._trickyValueAccessor(json, r'$string') as String? - ..simpleObject = - SimpleObject.fromJson(json['simpleObject'] as Map<String, dynamic>) + ..simpleObject = SimpleObject.fromJson( + json['simpleObject'] as Map<String, dynamic>, + ) ..strictKeysObject = StrictKeysObject.fromJson( - json['strictKeysObject'] as Map<String, dynamic>) + json['strictKeysObject'] as Map<String, dynamic>, + ) ..validatedPropertyNo42 = (json['validatedPropertyNo42'] as num?)?.toInt() ..recordField = _$recordConvertNullable( json['recordField'], @@ -98,167 +115,198 @@ KitchenSink _$KitchenSinkFromJson(Map<String, dynamic> json) => KitchenSink( ), ); -Map<String, dynamic> _$KitchenSinkToJson(KitchenSink instance) => - <String, dynamic>{ - 'no-42': instance.ctorValidatedNo42, - 'dateTime': instance.dateTime?.toIso8601String(), - 'bigInt': instance.bigInt?.toString(), - 'iterable': instance.iterable?.toList(), - 'dynamicIterable': instance.dynamicIterable.toList(), - 'objectIterable': instance.objectIterable.toList(), - 'intIterable': instance.intIterable.toList(), - 'set': instance.set.toList(), - 'dynamicSet': instance.dynamicSet.toList(), - 'objectSet': instance.objectSet.toList(), - 'intSet': instance.intSet.toList(), - 'dateTimeSet': - instance.dateTimeSet.map((e) => e.toIso8601String()).toList(), - 'datetime-iterable': - instance.dateTimeIterable.map((e) => e.toIso8601String()).toList(), - 'list': instance.list, - 'dynamicList': instance.dynamicList, - 'objectList': instance.objectList, - 'intList': instance.intList, - 'dateTimeList': - instance.dateTimeList.map((e) => e.toIso8601String()).toList(), - 'nullableSimpleObjectList': instance.nullableSimpleObjectList, - 'map': instance.map, - 'stringStringMap': instance.stringStringMap, - 'dynamicIntMap': instance.dynamicIntMap, - 'objectDateTimeMap': instance.objectDateTimeMap - .map((k, e) => MapEntry(k, e.toIso8601String())), - 'nullableSimpleObjectMap': instance.nullableSimpleObjectMap, - 'crazyComplex': instance.crazyComplex - .map((e) => e?.map((k, e) => MapEntry( - k, - e?.map((k, e) => MapEntry( - k, - e - ?.map((e) => e?.map((e) => e.toIso8601String()).toList()) - .toList()))))) - .toList(), - 'val': instance.val, - 'writeNotNull': instance.writeNotNull, - r'$string': instance.string, - 'simpleObject': instance.simpleObject, - 'strictKeysObject': instance.strictKeysObject, - 'validatedPropertyNo42': instance.validatedPropertyNo42, - 'recordField': instance.recordField == null - ? null - : <String, dynamic>{ - r'$1': instance.recordField!.$1, - r'$2': instance.recordField!.$2, - 'truth': instance.recordField!.truth, - }, - }; +Map<String, dynamic> _$KitchenSinkToJson( + KitchenSink instance, +) => <String, dynamic>{ + 'no-42': instance.ctorValidatedNo42, + 'dateTime': instance.dateTime?.toIso8601String(), + 'bigInt': instance.bigInt?.toString(), + 'iterable': instance.iterable?.toList(), + 'dynamicIterable': instance.dynamicIterable.toList(), + 'objectIterable': instance.objectIterable.toList(), + 'intIterable': instance.intIterable.toList(), + 'set': instance.set.toList(), + 'dynamicSet': instance.dynamicSet.toList(), + 'objectSet': instance.objectSet.toList(), + 'intSet': instance.intSet.toList(), + 'dateTimeSet': instance.dateTimeSet.map((e) => e.toIso8601String()).toList(), + 'datetime-iterable': instance.dateTimeIterable + .map((e) => e.toIso8601String()) + .toList(), + 'list': instance.list, + 'dynamicList': instance.dynamicList, + 'objectList': instance.objectList, + 'intList': instance.intList, + 'dateTimeList': instance.dateTimeList + .map((e) => e.toIso8601String()) + .toList(), + 'nullableSimpleObjectList': instance.nullableSimpleObjectList, + 'map': instance.map, + 'stringStringMap': instance.stringStringMap, + 'dynamicIntMap': instance.dynamicIntMap, + 'objectDateTimeMap': instance.objectDateTimeMap.map( + (k, e) => MapEntry(k, e.toIso8601String()), + ), + 'nullableSimpleObjectMap': instance.nullableSimpleObjectMap, + 'crazyComplex': instance.crazyComplex + .map( + (e) => e?.map( + (k, e) => MapEntry( + k, + e?.map( + (k, e) => MapEntry( + k, + e + ?.map((e) => e?.map((e) => e.toIso8601String()).toList()) + .toList(), + ), + ), + ), + ), + ) + .toList(), + 'val': instance.val, + 'writeNotNull': instance.writeNotNull, + r'$string': instance.string, + 'simpleObject': instance.simpleObject, + 'strictKeysObject': instance.strictKeysObject, + 'validatedPropertyNo42': instance.validatedPropertyNo42, + 'recordField': instance.recordField == null + ? null + : <String, dynamic>{ + r'$1': instance.recordField!.$1, + r'$2': instance.recordField!.$2, + 'truth': instance.recordField!.truth, + }, +}; $Rec? _$recordConvertNullable<$Rec>( Object? value, $Rec Function(Map) convert, -) => - value == null ? null : convert(value as Map<String, dynamic>); +) => value == null ? null : convert(value as Map<String, dynamic>); JsonConverterTestClass _$JsonConverterTestClassFromJson( - Map<String, dynamic> json) => - JsonConverterTestClass( - const DurationMillisecondConverter() - .fromJson((json['duration'] as num?)?.toInt()), - (json['durationList'] as List<dynamic>) - .map((e) => const DurationMillisecondConverter() - .fromJson((e as num?)?.toInt())) - .toList(), - const BigIntStringConverter().fromJson(json['bigInt'] as String), - (json['bigIntMap'] as Map<String, dynamic>).map( - (k, e) => - MapEntry(k, const BigIntStringConverter().fromJson(e as String)), - ), + Map<String, dynamic> json, +) => JsonConverterTestClass( + const DurationMillisecondConverter().fromJson( + (json['duration'] as num?)?.toInt(), + ), + (json['durationList'] as List<dynamic>) + .map( + (e) => + const DurationMillisecondConverter().fromJson((e as num?)?.toInt()), + ) + .toList(), + const BigIntStringConverter().fromJson(json['bigInt'] as String), + (json['bigIntMap'] as Map<String, dynamic>).map( + (k, e) => MapEntry(k, const BigIntStringConverter().fromJson(e as String)), + ), + _$JsonConverterFromJson<String, BigInt>( + json['nullableBigInt'], + const BigIntStringConverter().fromJson, + ), + (json['nullableBigIntMap'] as Map<String, dynamic>).map( + (k, e) => MapEntry( + k, _$JsonConverterFromJson<String, BigInt>( - json['nullableBigInt'], const BigIntStringConverter().fromJson), - (json['nullableBigIntMap'] as Map<String, dynamic>).map( - (k, e) => MapEntry( - k, - _$JsonConverterFromJson<String, BigInt>( - e, const BigIntStringConverter().fromJson)), + e, + const BigIntStringConverter().fromJson, ), - TrivialNumberConverter.instance - .fromJson((json['numberSilly'] as num?)?.toInt()), - (json['numberSillySet'] as List<dynamic>) - .map((e) => - TrivialNumberConverter.instance.fromJson((e as num?)?.toInt())) - .toSet(), - const EpochDateTimeConverter() - .fromJson((json['dateTime'] as num?)?.toInt()), - trivialStringConverter.fromJson(json['trivialString'] as String?), - TrivialNumberConverter.instance - .fromJson((json['nullableNumberSilly'] as num?)?.toInt()), - (json['nullableNumberSillySet'] as List<dynamic>) - .map((e) => - TrivialNumberConverter.instance.fromJson((e as num?)?.toInt())) - .toSet(), - ); + ), + ), + TrivialNumberConverter.instance.fromJson( + (json['numberSilly'] as num?)?.toInt(), + ), + (json['numberSillySet'] as List<dynamic>) + .map( + (e) => TrivialNumberConverter.instance.fromJson((e as num?)?.toInt()), + ) + .toSet(), + const EpochDateTimeConverter().fromJson((json['dateTime'] as num?)?.toInt()), + trivialStringConverter.fromJson(json['trivialString'] as String?), + TrivialNumberConverter.instance.fromJson( + (json['nullableNumberSilly'] as num?)?.toInt(), + ), + (json['nullableNumberSillySet'] as List<dynamic>) + .map( + (e) => TrivialNumberConverter.instance.fromJson((e as num?)?.toInt()), + ) + .toSet(), +); Map<String, dynamic> _$JsonConverterTestClassToJson( - JsonConverterTestClass instance) => - <String, dynamic>{ - 'duration': - const DurationMillisecondConverter().toJson(instance.duration), - 'durationList': instance.durationList - .map(const DurationMillisecondConverter().toJson) - .toList(), - 'bigInt': const BigIntStringConverter().toJson(instance.bigInt), - 'bigIntMap': instance.bigIntMap - .map((k, e) => MapEntry(k, const BigIntStringConverter().toJson(e))), - 'nullableBigInt': _$JsonConverterToJson<String, BigInt>( - instance.nullableBigInt, const BigIntStringConverter().toJson), - 'nullableBigIntMap': instance.nullableBigIntMap.map((k, e) => MapEntry( - k, - _$JsonConverterToJson<String, BigInt>( - e, const BigIntStringConverter().toJson))), - 'numberSilly': - TrivialNumberConverter.instance.toJson(instance.numberSilly), - 'numberSillySet': instance.numberSillySet - .map(TrivialNumberConverter.instance.toJson) - .toList(), - 'dateTime': const EpochDateTimeConverter().toJson(instance.dateTime), - 'trivialString': trivialStringConverter.toJson(instance.trivialString), - 'nullableNumberSilly': _$JsonConverterToJson<int?, TrivialNumber>( - instance.nullableNumberSilly, TrivialNumberConverter.instance.toJson), - 'nullableNumberSillySet': instance.nullableNumberSillySet - .map((e) => _$JsonConverterToJson<int?, TrivialNumber>( - e, TrivialNumberConverter.instance.toJson)) - .toList(), - }; + JsonConverterTestClass instance, +) => <String, dynamic>{ + 'duration': const DurationMillisecondConverter().toJson(instance.duration), + 'durationList': instance.durationList + .map(const DurationMillisecondConverter().toJson) + .toList(), + 'bigInt': const BigIntStringConverter().toJson(instance.bigInt), + 'bigIntMap': instance.bigIntMap.map( + (k, e) => MapEntry(k, const BigIntStringConverter().toJson(e)), + ), + 'nullableBigInt': _$JsonConverterToJson<String, BigInt>( + instance.nullableBigInt, + const BigIntStringConverter().toJson, + ), + 'nullableBigIntMap': instance.nullableBigIntMap.map( + (k, e) => MapEntry( + k, + _$JsonConverterToJson<String, BigInt>( + e, + const BigIntStringConverter().toJson, + ), + ), + ), + 'numberSilly': TrivialNumberConverter.instance.toJson(instance.numberSilly), + 'numberSillySet': instance.numberSillySet + .map(TrivialNumberConverter.instance.toJson) + .toList(), + 'dateTime': const EpochDateTimeConverter().toJson(instance.dateTime), + 'trivialString': trivialStringConverter.toJson(instance.trivialString), + 'nullableNumberSilly': _$JsonConverterToJson<int?, TrivialNumber>( + instance.nullableNumberSilly, + TrivialNumberConverter.instance.toJson, + ), + 'nullableNumberSillySet': instance.nullableNumberSillySet + .map( + (e) => _$JsonConverterToJson<int?, TrivialNumber>( + e, + TrivialNumberConverter.instance.toJson, + ), + ) + .toList(), +}; Value? _$JsonConverterFromJson<Json, Value>( Object? json, Value? Function(Json json) fromJson, -) => - json == null ? null : fromJson(json as Json); +) => json == null ? null : fromJson(json as Json); Json? _$JsonConverterToJson<Json, Value>( Value? value, Json? Function(Value value) toJson, -) => - value == null ? null : toJson(value); +) => value == null ? null : toJson(value); JsonConverterGeneric<S, T, U> _$JsonConverterGenericFromJson<S, T, U>( - Map<String, dynamic> json) => - JsonConverterGeneric<S, T, U>( - GenericConverter<S>().fromJson(json['item'] as Map<String, dynamic>), - (json['itemList'] as List<dynamic>) - .map((e) => GenericConverter<T>().fromJson(e as Map<String, dynamic>)) - .toList(), - (json['itemMap'] as Map<String, dynamic>).map( - (k, e) => MapEntry( - k, GenericConverter<U>().fromJson(e as Map<String, dynamic>)), - ), - ); + Map<String, dynamic> json, +) => JsonConverterGeneric<S, T, U>( + GenericConverter<S>().fromJson(json['item'] as Map<String, dynamic>), + (json['itemList'] as List<dynamic>) + .map((e) => GenericConverter<T>().fromJson(e as Map<String, dynamic>)) + .toList(), + (json['itemMap'] as Map<String, dynamic>).map( + (k, e) => + MapEntry(k, GenericConverter<U>().fromJson(e as Map<String, dynamic>)), + ), +); Map<String, dynamic> _$JsonConverterGenericToJson<S, T, U>( - JsonConverterGeneric<S, T, U> instance) => - <String, dynamic>{ - 'item': GenericConverter<S>().toJson(instance.item), - 'itemList': instance.itemList.map(GenericConverter<T>().toJson).toList(), - 'itemMap': instance.itemMap - .map((k, e) => MapEntry(k, GenericConverter<U>().toJson(e))), - }; + JsonConverterGeneric<S, T, U> instance, +) => <String, dynamic>{ + 'item': GenericConverter<S>().toJson(instance.item), + 'itemList': instance.itemList.map(GenericConverter<T>().toJson).toList(), + 'itemMap': instance.itemMap.map( + (k, e) => MapEntry(k, GenericConverter<U>().toJson(e)), + ), +}; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart index f00f38ebc..39efca774 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart @@ -48,32 +48,31 @@ class _Factory implements k.KitchenSinkFactory<dynamic, dynamic> { Iterable<Object>? objectIterable, Iterable<int>? intIterable, Iterable<DateTime>? dateTimeIterable, - }) => - KitchenSink( - ctorValidatedNo42: ctorValidatedNo42, - iterable: iterable, - dynamicIterable: dynamicIterable, - objectIterable: objectIterable, - intIterable: intIterable, - dateTimeIterable: dateTimeIterable, - ); + }) => KitchenSink( + ctorValidatedNo42: ctorValidatedNo42, + iterable: iterable, + dynamicIterable: dynamicIterable, + objectIterable: objectIterable, + intIterable: intIterable, + dateTimeIterable: dateTimeIterable, + ); k.KitchenSink fromJson(Map json) => KitchenSink.fromJson(json); k.JsonConverterTestClass jsonConverterCtor() => JsonConverterTestClass( - const Duration(), - [], - BigInt.zero, - {}, - BigInt.zero, - {}, - TrivialNumber(0), - {}, - DateTime.fromMillisecondsSinceEpoch(0), - TrivialString(''), - TrivialNumber(0), - {}, - ); + const Duration(), + [], + BigInt.zero, + {}, + BigInt.zero, + {}, + TrivialNumber(0), + {}, + DateTime.fromMillisecondsSinceEpoch(0), + TrivialString(''), + TrivialNumber(0), + {}, + ); k.JsonConverterTestClass jsonConverterFromJson(Map<String, dynamic> json) => JsonConverterTestClass.fromJson(json); @@ -87,9 +86,7 @@ Object? _valueAccessor(Map json, String key) { return json[key]; } -@JsonSerializable( - anyMap: true, -) +@JsonSerializable(anyMap: true) class KitchenSink implements k.KitchenSink { // NOTE: exposing these as Iterable, but storing the values as List // to make the equality test work trivially. @@ -109,14 +106,17 @@ class KitchenSink implements k.KitchenSink { Iterable<Object>? objectIterable, Iterable<int>? intIterable, Iterable<DateTime>? dateTimeIterable, - }) : _iterable = iterable?.toList(), - _dynamicIterable = dynamicIterable?.toList() ?? _defaultList(), - _objectIterable = objectIterable?.toList() ?? _defaultList(), - _intIterable = intIterable?.toList() ?? _defaultList(), - _dateTimeIterable = dateTimeIterable?.toList() ?? _defaultList() { + }) : _iterable = iterable?.toList(), + _dynamicIterable = dynamicIterable?.toList() ?? _defaultList(), + _objectIterable = objectIterable?.toList() ?? _defaultList(), + _intIterable = intIterable?.toList() ?? _defaultList(), + _dateTimeIterable = dateTimeIterable?.toList() ?? _defaultList() { if (ctorValidatedNo42 == 42) { throw ArgumentError.value( - 42, 'ctorValidatedNo42', 'The value `42` is not allowed.'); + 42, + 'ctorValidatedNo42', + 'The value `42` is not allowed.', + ); } } @@ -197,12 +197,15 @@ class KitchenSink implements k.KitchenSink { } } -@JsonSerializable(anyMap: true, converters: [ - // referencing a top-level field should work - durationConverter, - // referencing via a const constructor should work - BigIntStringConverter(), -]) +@JsonSerializable( + anyMap: true, + converters: [ + // referencing a top-level field should work + durationConverter, + // referencing via a const constructor should work + BigIntStringConverter(), + ], +) // referencing a top-level field should work @trivialStringConverter @TrivialNumberConverter.instance @@ -248,9 +251,7 @@ class JsonConverterTestClass implements k.JsonConverterTestClass { Set<TrivialNumber?> nullableNumberSillySet; } -@JsonSerializable( - anyMap: true, -) +@JsonSerializable(anyMap: true) // ignore: inference_failure_on_instance_creation @GenericConverter() class JsonConverterGeneric<S, T, U> { @@ -258,11 +259,7 @@ class JsonConverterGeneric<S, T, U> { List<T> itemList; Map<String, U> itemMap; - JsonConverterGeneric( - this.item, - this.itemList, - this.itemMap, - ); + JsonConverterGeneric(this.item, this.itemList, this.itemMap); factory JsonConverterGeneric.fromJson(Map<String, dynamic> json) => _$JsonConverterGenericFromJson(json); diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart index 69301303d..326f7e80e 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart @@ -8,26 +8,32 @@ part of 'kitchen_sink.g_any_map.dart'; // JsonSerializableGenerator // ************************************************************************** -KitchenSink _$KitchenSinkFromJson(Map json) => KitchenSink( - ctorValidatedNo42: (json['no-42'] as num?)?.toInt(), - iterable: _valueAccessor(json, 'iterable') as List<dynamic>?, - dynamicIterable: json['dynamicIterable'] as List<dynamic>?, - objectIterable: - (json['objectIterable'] as List<dynamic>?)?.map((e) => e as Object), - intIterable: (json['intIterable'] as List<dynamic>?) - ?.map((e) => (e as num).toInt()), - dateTimeIterable: (json['datetime-iterable'] as List<dynamic>?) - ?.map((e) => DateTime.parse(e as String)), - ) +KitchenSink _$KitchenSinkFromJson(Map json) => + KitchenSink( + ctorValidatedNo42: (json['no-42'] as num?)?.toInt(), + iterable: _valueAccessor(json, 'iterable') as List<dynamic>?, + dynamicIterable: json['dynamicIterable'] as List<dynamic>?, + objectIterable: (json['objectIterable'] as List<dynamic>?)?.map( + (e) => e as Object, + ), + intIterable: (json['intIterable'] as List<dynamic>?)?.map( + (e) => (e as num).toInt(), + ), + dateTimeIterable: (json['datetime-iterable'] as List<dynamic>?)?.map( + (e) => DateTime.parse(e as String), + ), + ) ..dateTime = json['dateTime'] == null ? null : DateTime.parse(json['dateTime'] as String) - ..bigInt = - json['bigInt'] == null ? null : BigInt.parse(json['bigInt'] as String) + ..bigInt = json['bigInt'] == null + ? null + : BigInt.parse(json['bigInt'] as String) ..set = (json['set'] as List<dynamic>).toSet() ..dynamicSet = (json['dynamicSet'] as List<dynamic>).toSet() - ..objectSet = - (json['objectSet'] as List<dynamic>).map((e) => e as Object).toSet() + ..objectSet = (json['objectSet'] as List<dynamic>) + .map((e) => e as Object) + .toSet() ..intSet = (json['intSet'] as List<dynamic>) .map((e) => (e as num).toInt()) .toSet() @@ -36,8 +42,9 @@ KitchenSink _$KitchenSinkFromJson(Map json) => KitchenSink( .toSet() ..list = json['list'] as List<dynamic> ..dynamicList = json['dynamicList'] as List<dynamic> - ..objectList = - (json['objectList'] as List<dynamic>).map((e) => e as Object).toList() + ..objectList = (json['objectList'] as List<dynamic>) + .map((e) => e as Object) + .toList() ..intList = (json['intList'] as List<dynamic>) .map((e) => (e as num).toInt()) .toList() @@ -49,37 +56,47 @@ KitchenSink _$KitchenSinkFromJson(Map json) => KitchenSink( .map((e) => e == null ? null : SimpleObject.fromJson(e as Map)) .toList() ..map = json['map'] as Map - ..stringStringMap = - Map<String, String>.from(json['stringStringMap'] as Map) + ..stringStringMap = Map<String, String>.from( + json['stringStringMap'] as Map, + ) ..dynamicIntMap = Map<String, int>.from(json['dynamicIntMap'] as Map) ..objectDateTimeMap = (json['objectDateTimeMap'] as Map).map( (k, e) => MapEntry(k as Object, DateTime.parse(e as String)), ) ..nullableSimpleObjectMap = (json['nullableSimpleObjectMap'] as Map).map( (k, e) => MapEntry( - k as String, e == null ? null : SimpleObject.fromJson(e as Map)), + k as String, + e == null ? null : SimpleObject.fromJson(e as Map), + ), ) ..crazyComplex = (json['crazyComplex'] as List<dynamic>) - .map((e) => (e as Map?)?.map( - (k, e) => MapEntry( + .map( + (e) => (e as Map?)?.map( + (k, e) => MapEntry( + k as String, + (e as Map?)?.map( + (k, e) => MapEntry( k as String, - (e as Map?)?.map( - (k, e) => MapEntry( - k as String, - (e as List<dynamic>?) - ?.map((e) => (e as List<dynamic>?) - ?.map((e) => DateTime.parse(e as String)) - .toList()) - .toList()), - )), - )) + (e as List<dynamic>?) + ?.map( + (e) => (e as List<dynamic>?) + ?.map((e) => DateTime.parse(e as String)) + .toList(), + ) + .toList(), + ), + ), + ), + ), + ) .toList() ..val = Map<String, bool>.from(json['val'] as Map) ..writeNotNull = json['writeNotNull'] as bool? ..string = KitchenSink._trickyValueAccessor(json, r'$string') as String? ..simpleObject = SimpleObject.fromJson(json['simpleObject'] as Map) - ..strictKeysObject = - StrictKeysObject.fromJson(json['strictKeysObject'] as Map) + ..strictKeysObject = StrictKeysObject.fromJson( + json['strictKeysObject'] as Map, + ) ..validatedPropertyNo42 = (json['validatedPropertyNo42'] as num?)?.toInt() ..recordField = _$recordConvertAnyNullable( json['recordField'], @@ -90,166 +107,203 @@ KitchenSink _$KitchenSinkFromJson(Map json) => KitchenSink( ), ); -Map<String, dynamic> _$KitchenSinkToJson(KitchenSink instance) => - <String, dynamic>{ - 'no-42': instance.ctorValidatedNo42, - 'dateTime': instance.dateTime?.toIso8601String(), - 'bigInt': instance.bigInt?.toString(), - 'iterable': instance.iterable?.toList(), - 'dynamicIterable': instance.dynamicIterable.toList(), - 'objectIterable': instance.objectIterable.toList(), - 'intIterable': instance.intIterable.toList(), - 'set': instance.set.toList(), - 'dynamicSet': instance.dynamicSet.toList(), - 'objectSet': instance.objectSet.toList(), - 'intSet': instance.intSet.toList(), - 'dateTimeSet': - instance.dateTimeSet.map((e) => e.toIso8601String()).toList(), - 'datetime-iterable': - instance.dateTimeIterable.map((e) => e.toIso8601String()).toList(), - 'list': instance.list, - 'dynamicList': instance.dynamicList, - 'objectList': instance.objectList, - 'intList': instance.intList, - 'dateTimeList': - instance.dateTimeList.map((e) => e.toIso8601String()).toList(), - 'nullableSimpleObjectList': instance.nullableSimpleObjectList, - 'map': instance.map, - 'stringStringMap': instance.stringStringMap, - 'dynamicIntMap': instance.dynamicIntMap, - 'objectDateTimeMap': instance.objectDateTimeMap - .map((k, e) => MapEntry(k, e.toIso8601String())), - 'nullableSimpleObjectMap': instance.nullableSimpleObjectMap, - 'crazyComplex': instance.crazyComplex - .map((e) => e?.map((k, e) => MapEntry( - k, - e?.map((k, e) => MapEntry( - k, - e - ?.map((e) => e?.map((e) => e.toIso8601String()).toList()) - .toList()))))) - .toList(), - 'val': instance.val, - 'writeNotNull': instance.writeNotNull, - r'$string': instance.string, - 'simpleObject': instance.simpleObject, - 'strictKeysObject': instance.strictKeysObject, - 'validatedPropertyNo42': instance.validatedPropertyNo42, - 'recordField': instance.recordField == null - ? null - : <String, dynamic>{ - r'$1': instance.recordField!.$1, - r'$2': instance.recordField!.$2, - 'truth': instance.recordField!.truth, - }, - }; +Map<String, dynamic> _$KitchenSinkToJson( + KitchenSink instance, +) => <String, dynamic>{ + 'no-42': instance.ctorValidatedNo42, + 'dateTime': instance.dateTime?.toIso8601String(), + 'bigInt': instance.bigInt?.toString(), + 'iterable': instance.iterable?.toList(), + 'dynamicIterable': instance.dynamicIterable.toList(), + 'objectIterable': instance.objectIterable.toList(), + 'intIterable': instance.intIterable.toList(), + 'set': instance.set.toList(), + 'dynamicSet': instance.dynamicSet.toList(), + 'objectSet': instance.objectSet.toList(), + 'intSet': instance.intSet.toList(), + 'dateTimeSet': instance.dateTimeSet.map((e) => e.toIso8601String()).toList(), + 'datetime-iterable': instance.dateTimeIterable + .map((e) => e.toIso8601String()) + .toList(), + 'list': instance.list, + 'dynamicList': instance.dynamicList, + 'objectList': instance.objectList, + 'intList': instance.intList, + 'dateTimeList': instance.dateTimeList + .map((e) => e.toIso8601String()) + .toList(), + 'nullableSimpleObjectList': instance.nullableSimpleObjectList, + 'map': instance.map, + 'stringStringMap': instance.stringStringMap, + 'dynamicIntMap': instance.dynamicIntMap, + 'objectDateTimeMap': instance.objectDateTimeMap.map( + (k, e) => MapEntry(k, e.toIso8601String()), + ), + 'nullableSimpleObjectMap': instance.nullableSimpleObjectMap, + 'crazyComplex': instance.crazyComplex + .map( + (e) => e?.map( + (k, e) => MapEntry( + k, + e?.map( + (k, e) => MapEntry( + k, + e + ?.map((e) => e?.map((e) => e.toIso8601String()).toList()) + .toList(), + ), + ), + ), + ), + ) + .toList(), + 'val': instance.val, + 'writeNotNull': instance.writeNotNull, + r'$string': instance.string, + 'simpleObject': instance.simpleObject, + 'strictKeysObject': instance.strictKeysObject, + 'validatedPropertyNo42': instance.validatedPropertyNo42, + 'recordField': instance.recordField == null + ? null + : <String, dynamic>{ + r'$1': instance.recordField!.$1, + r'$2': instance.recordField!.$2, + 'truth': instance.recordField!.truth, + }, +}; $Rec? _$recordConvertAnyNullable<$Rec>( Object? value, $Rec Function(Map) convert, -) => - value == null ? null : convert(value as Map); +) => value == null ? null : convert(value as Map); -JsonConverterTestClass _$JsonConverterTestClassFromJson(Map json) => - JsonConverterTestClass( - const DurationMillisecondConverter() - .fromJson((json['duration'] as num?)?.toInt()), - (json['durationList'] as List<dynamic>) - .map((e) => const DurationMillisecondConverter() - .fromJson((e as num?)?.toInt())) - .toList(), - const BigIntStringConverter().fromJson(json['bigInt'] as String), - (json['bigIntMap'] as Map).map( - (k, e) => MapEntry( - k as String, const BigIntStringConverter().fromJson(e as String)), - ), +JsonConverterTestClass _$JsonConverterTestClassFromJson( + Map json, +) => JsonConverterTestClass( + const DurationMillisecondConverter().fromJson( + (json['duration'] as num?)?.toInt(), + ), + (json['durationList'] as List<dynamic>) + .map( + (e) => + const DurationMillisecondConverter().fromJson((e as num?)?.toInt()), + ) + .toList(), + const BigIntStringConverter().fromJson(json['bigInt'] as String), + (json['bigIntMap'] as Map).map( + (k, e) => MapEntry( + k as String, + const BigIntStringConverter().fromJson(e as String), + ), + ), + _$JsonConverterFromJson<String, BigInt>( + json['nullableBigInt'], + const BigIntStringConverter().fromJson, + ), + (json['nullableBigIntMap'] as Map).map( + (k, e) => MapEntry( + k as String, _$JsonConverterFromJson<String, BigInt>( - json['nullableBigInt'], const BigIntStringConverter().fromJson), - (json['nullableBigIntMap'] as Map).map( - (k, e) => MapEntry( - k as String, - _$JsonConverterFromJson<String, BigInt>( - e, const BigIntStringConverter().fromJson)), + e, + const BigIntStringConverter().fromJson, ), - TrivialNumberConverter.instance - .fromJson((json['numberSilly'] as num?)?.toInt()), - (json['numberSillySet'] as List<dynamic>) - .map((e) => - TrivialNumberConverter.instance.fromJson((e as num?)?.toInt())) - .toSet(), - const EpochDateTimeConverter() - .fromJson((json['dateTime'] as num?)?.toInt()), - trivialStringConverter.fromJson(json['trivialString'] as String?), - TrivialNumberConverter.instance - .fromJson((json['nullableNumberSilly'] as num?)?.toInt()), - (json['nullableNumberSillySet'] as List<dynamic>) - .map((e) => - TrivialNumberConverter.instance.fromJson((e as num?)?.toInt())) - .toSet(), - ); + ), + ), + TrivialNumberConverter.instance.fromJson( + (json['numberSilly'] as num?)?.toInt(), + ), + (json['numberSillySet'] as List<dynamic>) + .map( + (e) => TrivialNumberConverter.instance.fromJson((e as num?)?.toInt()), + ) + .toSet(), + const EpochDateTimeConverter().fromJson((json['dateTime'] as num?)?.toInt()), + trivialStringConverter.fromJson(json['trivialString'] as String?), + TrivialNumberConverter.instance.fromJson( + (json['nullableNumberSilly'] as num?)?.toInt(), + ), + (json['nullableNumberSillySet'] as List<dynamic>) + .map( + (e) => TrivialNumberConverter.instance.fromJson((e as num?)?.toInt()), + ) + .toSet(), +); Map<String, dynamic> _$JsonConverterTestClassToJson( - JsonConverterTestClass instance) => - <String, dynamic>{ - 'duration': - const DurationMillisecondConverter().toJson(instance.duration), - 'durationList': instance.durationList - .map(const DurationMillisecondConverter().toJson) - .toList(), - 'bigInt': const BigIntStringConverter().toJson(instance.bigInt), - 'bigIntMap': instance.bigIntMap - .map((k, e) => MapEntry(k, const BigIntStringConverter().toJson(e))), - 'nullableBigInt': _$JsonConverterToJson<String, BigInt>( - instance.nullableBigInt, const BigIntStringConverter().toJson), - 'nullableBigIntMap': instance.nullableBigIntMap.map((k, e) => MapEntry( - k, - _$JsonConverterToJson<String, BigInt>( - e, const BigIntStringConverter().toJson))), - 'numberSilly': - TrivialNumberConverter.instance.toJson(instance.numberSilly), - 'numberSillySet': instance.numberSillySet - .map(TrivialNumberConverter.instance.toJson) - .toList(), - 'dateTime': const EpochDateTimeConverter().toJson(instance.dateTime), - 'trivialString': trivialStringConverter.toJson(instance.trivialString), - 'nullableNumberSilly': _$JsonConverterToJson<int?, TrivialNumber>( - instance.nullableNumberSilly, TrivialNumberConverter.instance.toJson), - 'nullableNumberSillySet': instance.nullableNumberSillySet - .map((e) => _$JsonConverterToJson<int?, TrivialNumber>( - e, TrivialNumberConverter.instance.toJson)) - .toList(), - }; + JsonConverterTestClass instance, +) => <String, dynamic>{ + 'duration': const DurationMillisecondConverter().toJson(instance.duration), + 'durationList': instance.durationList + .map(const DurationMillisecondConverter().toJson) + .toList(), + 'bigInt': const BigIntStringConverter().toJson(instance.bigInt), + 'bigIntMap': instance.bigIntMap.map( + (k, e) => MapEntry(k, const BigIntStringConverter().toJson(e)), + ), + 'nullableBigInt': _$JsonConverterToJson<String, BigInt>( + instance.nullableBigInt, + const BigIntStringConverter().toJson, + ), + 'nullableBigIntMap': instance.nullableBigIntMap.map( + (k, e) => MapEntry( + k, + _$JsonConverterToJson<String, BigInt>( + e, + const BigIntStringConverter().toJson, + ), + ), + ), + 'numberSilly': TrivialNumberConverter.instance.toJson(instance.numberSilly), + 'numberSillySet': instance.numberSillySet + .map(TrivialNumberConverter.instance.toJson) + .toList(), + 'dateTime': const EpochDateTimeConverter().toJson(instance.dateTime), + 'trivialString': trivialStringConverter.toJson(instance.trivialString), + 'nullableNumberSilly': _$JsonConverterToJson<int?, TrivialNumber>( + instance.nullableNumberSilly, + TrivialNumberConverter.instance.toJson, + ), + 'nullableNumberSillySet': instance.nullableNumberSillySet + .map( + (e) => _$JsonConverterToJson<int?, TrivialNumber>( + e, + TrivialNumberConverter.instance.toJson, + ), + ) + .toList(), +}; Value? _$JsonConverterFromJson<Json, Value>( Object? json, Value? Function(Json json) fromJson, -) => - json == null ? null : fromJson(json as Json); +) => json == null ? null : fromJson(json as Json); Json? _$JsonConverterToJson<Json, Value>( Value? value, Json? Function(Value value) toJson, -) => - value == null ? null : toJson(value); +) => value == null ? null : toJson(value); JsonConverterGeneric<S, T, U> _$JsonConverterGenericFromJson<S, T, U>( - Map json) => - JsonConverterGeneric<S, T, U>( - GenericConverter<S>().fromJson(json['item'] as Map<String, dynamic>), - (json['itemList'] as List<dynamic>) - .map((e) => GenericConverter<T>().fromJson(e as Map<String, dynamic>)) - .toList(), - (json['itemMap'] as Map).map( - (k, e) => MapEntry(k as String, - GenericConverter<U>().fromJson(e as Map<String, dynamic>)), - ), - ); + Map json, +) => JsonConverterGeneric<S, T, U>( + GenericConverter<S>().fromJson(json['item'] as Map<String, dynamic>), + (json['itemList'] as List<dynamic>) + .map((e) => GenericConverter<T>().fromJson(e as Map<String, dynamic>)) + .toList(), + (json['itemMap'] as Map).map( + (k, e) => MapEntry( + k as String, + GenericConverter<U>().fromJson(e as Map<String, dynamic>), + ), + ), +); Map<String, dynamic> _$JsonConverterGenericToJson<S, T, U>( - JsonConverterGeneric<S, T, U> instance) => - <String, dynamic>{ - 'item': GenericConverter<S>().toJson(instance.item), - 'itemList': instance.itemList.map(GenericConverter<T>().toJson).toList(), - 'itemMap': instance.itemMap - .map((k, e) => MapEntry(k, GenericConverter<U>().toJson(e))), - }; + JsonConverterGeneric<S, T, U> instance, +) => <String, dynamic>{ + 'item': GenericConverter<S>().toJson(instance.item), + 'itemList': instance.itemList.map(GenericConverter<T>().toJson).toList(), + 'itemMap': instance.itemMap.map( + (k, e) => MapEntry(k, GenericConverter<U>().toJson(e)), + ), +}; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.dart index 0d9dc1144..05f287f39 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.dart @@ -48,32 +48,31 @@ class _Factory implements k.KitchenSinkFactory<dynamic, dynamic> { Iterable<Object>? objectIterable, Iterable<int>? intIterable, Iterable<DateTime>? dateTimeIterable, - }) => - KitchenSink( - ctorValidatedNo42: ctorValidatedNo42, - iterable: iterable, - dynamicIterable: dynamicIterable, - objectIterable: objectIterable, - intIterable: intIterable, - dateTimeIterable: dateTimeIterable, - ); + }) => KitchenSink( + ctorValidatedNo42: ctorValidatedNo42, + iterable: iterable, + dynamicIterable: dynamicIterable, + objectIterable: objectIterable, + intIterable: intIterable, + dateTimeIterable: dateTimeIterable, + ); k.KitchenSink fromJson(Map json) => KitchenSink.fromJson(json); k.JsonConverterTestClass jsonConverterCtor() => JsonConverterTestClass( - const Duration(), - [], - BigInt.zero, - {}, - BigInt.zero, - {}, - TrivialNumber(0), - {}, - DateTime.fromMillisecondsSinceEpoch(0), - TrivialString(''), - TrivialNumber(0), - {}, - ); + const Duration(), + [], + BigInt.zero, + {}, + BigInt.zero, + {}, + TrivialNumber(0), + {}, + DateTime.fromMillisecondsSinceEpoch(0), + TrivialString(''), + TrivialNumber(0), + {}, + ); k.JsonConverterTestClass jsonConverterFromJson(Map<String, dynamic> json) => JsonConverterTestClass.fromJson(json); @@ -87,10 +86,7 @@ Object? _valueAccessor(Map json, String key) { return json[key]; } -@JsonSerializable( - checked: true, - anyMap: true, -) +@JsonSerializable(checked: true, anyMap: true) class KitchenSink implements k.KitchenSink { // NOTE: exposing these as Iterable, but storing the values as List // to make the equality test work trivially. @@ -110,14 +106,17 @@ class KitchenSink implements k.KitchenSink { Iterable<Object>? objectIterable, Iterable<int>? intIterable, Iterable<DateTime>? dateTimeIterable, - }) : _iterable = iterable?.toList(), - _dynamicIterable = dynamicIterable?.toList() ?? _defaultList(), - _objectIterable = objectIterable?.toList() ?? _defaultList(), - _intIterable = intIterable?.toList() ?? _defaultList(), - _dateTimeIterable = dateTimeIterable?.toList() ?? _defaultList() { + }) : _iterable = iterable?.toList(), + _dynamicIterable = dynamicIterable?.toList() ?? _defaultList(), + _objectIterable = objectIterable?.toList() ?? _defaultList(), + _intIterable = intIterable?.toList() ?? _defaultList(), + _dateTimeIterable = dateTimeIterable?.toList() ?? _defaultList() { if (ctorValidatedNo42 == 42) { throw ArgumentError.value( - 42, 'ctorValidatedNo42', 'The value `42` is not allowed.'); + 42, + 'ctorValidatedNo42', + 'The value `42` is not allowed.', + ); } } @@ -198,12 +197,16 @@ class KitchenSink implements k.KitchenSink { } } -@JsonSerializable(checked: true, anyMap: true, converters: [ - // referencing a top-level field should work - durationConverter, - // referencing via a const constructor should work - BigIntStringConverter(), -]) +@JsonSerializable( + checked: true, + anyMap: true, + converters: [ + // referencing a top-level field should work + durationConverter, + // referencing via a const constructor should work + BigIntStringConverter(), + ], +) // referencing a top-level field should work @trivialStringConverter @TrivialNumberConverter.instance @@ -249,10 +252,7 @@ class JsonConverterTestClass implements k.JsonConverterTestClass { Set<TrivialNumber?> nullableNumberSillySet; } -@JsonSerializable( - checked: true, - anyMap: true, -) +@JsonSerializable(checked: true, anyMap: true) // ignore: inference_failure_on_instance_creation @GenericConverter() class JsonConverterGeneric<S, T, U> { @@ -260,11 +260,7 @@ class JsonConverterGeneric<S, T, U> { List<T> itemList; Map<String, U> itemMap; - JsonConverterGeneric( - this.item, - this.itemList, - this.itemMap, - ); + JsonConverterGeneric(this.item, this.itemList, this.itemMap); factory JsonConverterGeneric.fromJson(Map<String, dynamic> json) => _$JsonConverterGenericFromJson(json); diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.g.dart index c004dcc74..25cfabf1c 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.g.dart @@ -9,342 +9,422 @@ part of 'kitchen_sink.g_any_map__checked.dart'; // ************************************************************************** KitchenSink _$KitchenSinkFromJson(Map json) => $checkedCreate( - 'KitchenSink', - json, - ($checkedConvert) { - final val = KitchenSink( - ctorValidatedNo42: - $checkedConvert('no-42', (v) => (v as num?)?.toInt()), - iterable: $checkedConvert( - 'iterable', - (v) => v as List<dynamic>?, - readValue: _valueAccessor, - ), - dynamicIterable: - $checkedConvert('dynamicIterable', (v) => v as List<dynamic>?), - objectIterable: $checkedConvert('objectIterable', - (v) => (v as List<dynamic>?)?.map((e) => e as Object)), - intIterable: $checkedConvert('intIterable', - (v) => (v as List<dynamic>?)?.map((e) => (e as num).toInt())), - dateTimeIterable: $checkedConvert( - 'datetime-iterable', - (v) => (v as List<dynamic>?) - ?.map((e) => DateTime.parse(e as String))), - ); - $checkedConvert( - 'dateTime', - (v) => - val.dateTime = v == null ? null : DateTime.parse(v as String)); - $checkedConvert('bigInt', - (v) => val.bigInt = v == null ? null : BigInt.parse(v as String)); - $checkedConvert('set', (v) => val.set = (v as List<dynamic>).toSet()); - $checkedConvert( - 'dynamicSet', (v) => val.dynamicSet = (v as List<dynamic>).toSet()); - $checkedConvert( - 'objectSet', - (v) => val.objectSet = - (v as List<dynamic>).map((e) => e as Object).toSet()); - $checkedConvert( - 'intSet', - (v) => val.intSet = - (v as List<dynamic>).map((e) => (e as num).toInt()).toSet()); - $checkedConvert( - 'dateTimeSet', - (v) => val.dateTimeSet = (v as List<dynamic>) - .map((e) => DateTime.parse(e as String)) - .toSet()); - $checkedConvert('list', (v) => val.list = v as List<dynamic>); - $checkedConvert( - 'dynamicList', (v) => val.dynamicList = v as List<dynamic>); - $checkedConvert( - 'objectList', - (v) => val.objectList = - (v as List<dynamic>).map((e) => e as Object).toList()); - $checkedConvert( - 'intList', - (v) => val.intList = - (v as List<dynamic>).map((e) => (e as num).toInt()).toList()); - $checkedConvert( - 'dateTimeList', - (v) => val.dateTimeList = (v as List<dynamic>) - .map((e) => DateTime.parse(e as String)) - .toList()); - $checkedConvert( - 'nullableSimpleObjectList', - (v) => val.nullableSimpleObjectList = (v as List<dynamic>) - .map((e) => e == null ? null : SimpleObject.fromJson(e as Map)) - .toList()); - $checkedConvert('map', (v) => val.map = v as Map); - $checkedConvert('stringStringMap', - (v) => val.stringStringMap = Map<String, String>.from(v as Map)); - $checkedConvert('dynamicIntMap', - (v) => val.dynamicIntMap = Map<String, int>.from(v as Map)); - $checkedConvert( - 'objectDateTimeMap', - (v) => val.objectDateTimeMap = (v as Map).map( - (k, e) => MapEntry(k as Object, DateTime.parse(e as String)), - )); - $checkedConvert( - 'nullableSimpleObjectMap', - (v) => val.nullableSimpleObjectMap = (v as Map).map( - (k, e) => MapEntry(k as String, - e == null ? null : SimpleObject.fromJson(e as Map)), - )); - $checkedConvert( - 'crazyComplex', - (v) => val.crazyComplex = (v as List<dynamic>) - .map((e) => (e as Map?)?.map( - (k, e) => MapEntry( - k as String, - (e as Map?)?.map( - (k, e) => MapEntry( - k as String, - (e as List<dynamic>?) - ?.map((e) => (e as List<dynamic>?) - ?.map( - (e) => DateTime.parse(e as String)) - .toList()) - .toList()), - )), - )) - .toList()); - $checkedConvert( - 'val', (v) => val.val = Map<String, bool>.from(v as Map)); - $checkedConvert('writeNotNull', (v) => val.writeNotNull = v as bool?); - $checkedConvert( - r'$string', - (v) => val.string = v as String?, - readValue: KitchenSink._trickyValueAccessor, - ); - $checkedConvert('simpleObject', - (v) => val.simpleObject = SimpleObject.fromJson(v as Map)); - $checkedConvert('strictKeysObject', - (v) => val.strictKeysObject = StrictKeysObject.fromJson(v as Map)); - $checkedConvert('validatedPropertyNo42', - (v) => val.validatedPropertyNo42 = (v as num?)?.toInt()); - $checkedConvert( - 'recordField', - (v) => val.recordField = _$recordConvertAnyNullable( - v, - ($jsonValue) => ( - ($jsonValue[r'$1'] as num).toInt(), - $jsonValue[r'$2'] as String, - truth: $jsonValue['truth'] as bool, + 'KitchenSink', + json, + ($checkedConvert) { + final val = KitchenSink( + ctorValidatedNo42: $checkedConvert('no-42', (v) => (v as num?)?.toInt()), + iterable: $checkedConvert( + 'iterable', + (v) => v as List<dynamic>?, + readValue: _valueAccessor, + ), + dynamicIterable: $checkedConvert( + 'dynamicIterable', + (v) => v as List<dynamic>?, + ), + objectIterable: $checkedConvert( + 'objectIterable', + (v) => (v as List<dynamic>?)?.map((e) => e as Object), + ), + intIterable: $checkedConvert( + 'intIterable', + (v) => (v as List<dynamic>?)?.map((e) => (e as num).toInt()), + ), + dateTimeIterable: $checkedConvert( + 'datetime-iterable', + (v) => (v as List<dynamic>?)?.map((e) => DateTime.parse(e as String)), + ), + ); + $checkedConvert( + 'dateTime', + (v) => val.dateTime = v == null ? null : DateTime.parse(v as String), + ); + $checkedConvert( + 'bigInt', + (v) => val.bigInt = v == null ? null : BigInt.parse(v as String), + ); + $checkedConvert('set', (v) => val.set = (v as List<dynamic>).toSet()); + $checkedConvert( + 'dynamicSet', + (v) => val.dynamicSet = (v as List<dynamic>).toSet(), + ); + $checkedConvert( + 'objectSet', + (v) => + val.objectSet = (v as List<dynamic>).map((e) => e as Object).toSet(), + ); + $checkedConvert( + 'intSet', + (v) => val.intSet = (v as List<dynamic>) + .map((e) => (e as num).toInt()) + .toSet(), + ); + $checkedConvert( + 'dateTimeSet', + (v) => val.dateTimeSet = (v as List<dynamic>) + .map((e) => DateTime.parse(e as String)) + .toSet(), + ); + $checkedConvert('list', (v) => val.list = v as List<dynamic>); + $checkedConvert('dynamicList', (v) => val.dynamicList = v as List<dynamic>); + $checkedConvert( + 'objectList', + (v) => val.objectList = (v as List<dynamic>) + .map((e) => e as Object) + .toList(), + ); + $checkedConvert( + 'intList', + (v) => val.intList = (v as List<dynamic>) + .map((e) => (e as num).toInt()) + .toList(), + ); + $checkedConvert( + 'dateTimeList', + (v) => val.dateTimeList = (v as List<dynamic>) + .map((e) => DateTime.parse(e as String)) + .toList(), + ); + $checkedConvert( + 'nullableSimpleObjectList', + (v) => val.nullableSimpleObjectList = (v as List<dynamic>) + .map((e) => e == null ? null : SimpleObject.fromJson(e as Map)) + .toList(), + ); + $checkedConvert('map', (v) => val.map = v as Map); + $checkedConvert( + 'stringStringMap', + (v) => val.stringStringMap = Map<String, String>.from(v as Map), + ); + $checkedConvert( + 'dynamicIntMap', + (v) => val.dynamicIntMap = Map<String, int>.from(v as Map), + ); + $checkedConvert( + 'objectDateTimeMap', + (v) => val.objectDateTimeMap = (v as Map).map( + (k, e) => MapEntry(k as Object, DateTime.parse(e as String)), + ), + ); + $checkedConvert( + 'nullableSimpleObjectMap', + (v) => val.nullableSimpleObjectMap = (v as Map).map( + (k, e) => MapEntry( + k as String, + e == null ? null : SimpleObject.fromJson(e as Map), + ), + ), + ); + $checkedConvert( + 'crazyComplex', + (v) => val.crazyComplex = (v as List<dynamic>) + .map( + (e) => (e as Map?)?.map( + (k, e) => MapEntry( + k as String, + (e as Map?)?.map( + (k, e) => MapEntry( + k as String, + (e as List<dynamic>?) + ?.map( + (e) => (e as List<dynamic>?) + ?.map((e) => DateTime.parse(e as String)) + .toList(), + ) + .toList(), ), - )); - return val; - }, - fieldKeyMap: const { - 'ctorValidatedNo42': 'no-42', - 'dateTimeIterable': 'datetime-iterable', - 'string': r'$string' - }, + ), + ), + ), + ) + .toList(), + ); + $checkedConvert('val', (v) => val.val = Map<String, bool>.from(v as Map)); + $checkedConvert('writeNotNull', (v) => val.writeNotNull = v as bool?); + $checkedConvert( + r'$string', + (v) => val.string = v as String?, + readValue: KitchenSink._trickyValueAccessor, + ); + $checkedConvert( + 'simpleObject', + (v) => val.simpleObject = SimpleObject.fromJson(v as Map), ); + $checkedConvert( + 'strictKeysObject', + (v) => val.strictKeysObject = StrictKeysObject.fromJson(v as Map), + ); + $checkedConvert( + 'validatedPropertyNo42', + (v) => val.validatedPropertyNo42 = (v as num?)?.toInt(), + ); + $checkedConvert( + 'recordField', + (v) => val.recordField = _$recordConvertAnyNullable( + v, + ($jsonValue) => ( + ($jsonValue[r'$1'] as num).toInt(), + $jsonValue[r'$2'] as String, + truth: $jsonValue['truth'] as bool, + ), + ), + ); + return val; + }, + fieldKeyMap: const { + 'ctorValidatedNo42': 'no-42', + 'dateTimeIterable': 'datetime-iterable', + 'string': r'$string', + }, +); -Map<String, dynamic> _$KitchenSinkToJson(KitchenSink instance) => - <String, dynamic>{ - 'no-42': instance.ctorValidatedNo42, - 'dateTime': instance.dateTime?.toIso8601String(), - 'bigInt': instance.bigInt?.toString(), - 'iterable': instance.iterable?.toList(), - 'dynamicIterable': instance.dynamicIterable.toList(), - 'objectIterable': instance.objectIterable.toList(), - 'intIterable': instance.intIterable.toList(), - 'set': instance.set.toList(), - 'dynamicSet': instance.dynamicSet.toList(), - 'objectSet': instance.objectSet.toList(), - 'intSet': instance.intSet.toList(), - 'dateTimeSet': - instance.dateTimeSet.map((e) => e.toIso8601String()).toList(), - 'datetime-iterable': - instance.dateTimeIterable.map((e) => e.toIso8601String()).toList(), - 'list': instance.list, - 'dynamicList': instance.dynamicList, - 'objectList': instance.objectList, - 'intList': instance.intList, - 'dateTimeList': - instance.dateTimeList.map((e) => e.toIso8601String()).toList(), - 'nullableSimpleObjectList': instance.nullableSimpleObjectList, - 'map': instance.map, - 'stringStringMap': instance.stringStringMap, - 'dynamicIntMap': instance.dynamicIntMap, - 'objectDateTimeMap': instance.objectDateTimeMap - .map((k, e) => MapEntry(k, e.toIso8601String())), - 'nullableSimpleObjectMap': instance.nullableSimpleObjectMap, - 'crazyComplex': instance.crazyComplex - .map((e) => e?.map((k, e) => MapEntry( - k, - e?.map((k, e) => MapEntry( - k, - e - ?.map((e) => e?.map((e) => e.toIso8601String()).toList()) - .toList()))))) - .toList(), - 'val': instance.val, - 'writeNotNull': instance.writeNotNull, - r'$string': instance.string, - 'simpleObject': instance.simpleObject, - 'strictKeysObject': instance.strictKeysObject, - 'validatedPropertyNo42': instance.validatedPropertyNo42, - 'recordField': instance.recordField == null - ? null - : <String, dynamic>{ - r'$1': instance.recordField!.$1, - r'$2': instance.recordField!.$2, - 'truth': instance.recordField!.truth, - }, - }; +Map<String, dynamic> _$KitchenSinkToJson( + KitchenSink instance, +) => <String, dynamic>{ + 'no-42': instance.ctorValidatedNo42, + 'dateTime': instance.dateTime?.toIso8601String(), + 'bigInt': instance.bigInt?.toString(), + 'iterable': instance.iterable?.toList(), + 'dynamicIterable': instance.dynamicIterable.toList(), + 'objectIterable': instance.objectIterable.toList(), + 'intIterable': instance.intIterable.toList(), + 'set': instance.set.toList(), + 'dynamicSet': instance.dynamicSet.toList(), + 'objectSet': instance.objectSet.toList(), + 'intSet': instance.intSet.toList(), + 'dateTimeSet': instance.dateTimeSet.map((e) => e.toIso8601String()).toList(), + 'datetime-iterable': instance.dateTimeIterable + .map((e) => e.toIso8601String()) + .toList(), + 'list': instance.list, + 'dynamicList': instance.dynamicList, + 'objectList': instance.objectList, + 'intList': instance.intList, + 'dateTimeList': instance.dateTimeList + .map((e) => e.toIso8601String()) + .toList(), + 'nullableSimpleObjectList': instance.nullableSimpleObjectList, + 'map': instance.map, + 'stringStringMap': instance.stringStringMap, + 'dynamicIntMap': instance.dynamicIntMap, + 'objectDateTimeMap': instance.objectDateTimeMap.map( + (k, e) => MapEntry(k, e.toIso8601String()), + ), + 'nullableSimpleObjectMap': instance.nullableSimpleObjectMap, + 'crazyComplex': instance.crazyComplex + .map( + (e) => e?.map( + (k, e) => MapEntry( + k, + e?.map( + (k, e) => MapEntry( + k, + e + ?.map((e) => e?.map((e) => e.toIso8601String()).toList()) + .toList(), + ), + ), + ), + ), + ) + .toList(), + 'val': instance.val, + 'writeNotNull': instance.writeNotNull, + r'$string': instance.string, + 'simpleObject': instance.simpleObject, + 'strictKeysObject': instance.strictKeysObject, + 'validatedPropertyNo42': instance.validatedPropertyNo42, + 'recordField': instance.recordField == null + ? null + : <String, dynamic>{ + r'$1': instance.recordField!.$1, + r'$2': instance.recordField!.$2, + 'truth': instance.recordField!.truth, + }, +}; $Rec? _$recordConvertAnyNullable<$Rec>( Object? value, $Rec Function(Map) convert, -) => - value == null ? null : convert(value as Map); +) => value == null ? null : convert(value as Map); -JsonConverterTestClass _$JsonConverterTestClassFromJson(Map json) => - $checkedCreate( - 'JsonConverterTestClass', - json, - ($checkedConvert) { - final val = JsonConverterTestClass( - $checkedConvert( - 'duration', - (v) => const DurationMillisecondConverter() - .fromJson((v as num?)?.toInt())), - $checkedConvert( - 'durationList', - (v) => (v as List<dynamic>) - .map((e) => const DurationMillisecondConverter() - .fromJson((e as num?)?.toInt())) - .toList()), - $checkedConvert('bigInt', - (v) => const BigIntStringConverter().fromJson(v as String)), - $checkedConvert( - 'bigIntMap', - (v) => (v as Map).map( - (k, e) => MapEntry(k as String, - const BigIntStringConverter().fromJson(e as String)), - )), - $checkedConvert( - 'nullableBigInt', - (v) => _$JsonConverterFromJson<String, BigInt>( - v, const BigIntStringConverter().fromJson)), - $checkedConvert( - 'nullableBigIntMap', - (v) => (v as Map).map( - (k, e) => MapEntry( - k as String, - _$JsonConverterFromJson<String, BigInt>( - e, const BigIntStringConverter().fromJson)), - )), - $checkedConvert( - 'numberSilly', - (v) => TrivialNumberConverter.instance - .fromJson((v as num?)?.toInt())), - $checkedConvert( - 'numberSillySet', - (v) => (v as List<dynamic>) - .map((e) => TrivialNumberConverter.instance - .fromJson((e as num?)?.toInt())) - .toSet()), - $checkedConvert( - 'dateTime', - (v) => const EpochDateTimeConverter() - .fromJson((v as num?)?.toInt())), - $checkedConvert('trivialString', - (v) => trivialStringConverter.fromJson(v as String?)), - $checkedConvert( - 'nullableNumberSilly', - (v) => TrivialNumberConverter.instance - .fromJson((v as num?)?.toInt())), - $checkedConvert( - 'nullableNumberSillySet', - (v) => (v as List<dynamic>) - .map((e) => TrivialNumberConverter.instance - .fromJson((e as num?)?.toInt())) - .toSet()), - ); - return val; - }, - ); +JsonConverterTestClass _$JsonConverterTestClassFromJson( + Map json, +) => $checkedCreate('JsonConverterTestClass', json, ($checkedConvert) { + final val = JsonConverterTestClass( + $checkedConvert( + 'duration', + (v) => + const DurationMillisecondConverter().fromJson((v as num?)?.toInt()), + ), + $checkedConvert( + 'durationList', + (v) => (v as List<dynamic>) + .map( + (e) => const DurationMillisecondConverter().fromJson( + (e as num?)?.toInt(), + ), + ) + .toList(), + ), + $checkedConvert( + 'bigInt', + (v) => const BigIntStringConverter().fromJson(v as String), + ), + $checkedConvert( + 'bigIntMap', + (v) => (v as Map).map( + (k, e) => MapEntry( + k as String, + const BigIntStringConverter().fromJson(e as String), + ), + ), + ), + $checkedConvert( + 'nullableBigInt', + (v) => _$JsonConverterFromJson<String, BigInt>( + v, + const BigIntStringConverter().fromJson, + ), + ), + $checkedConvert( + 'nullableBigIntMap', + (v) => (v as Map).map( + (k, e) => MapEntry( + k as String, + _$JsonConverterFromJson<String, BigInt>( + e, + const BigIntStringConverter().fromJson, + ), + ), + ), + ), + $checkedConvert( + 'numberSilly', + (v) => TrivialNumberConverter.instance.fromJson((v as num?)?.toInt()), + ), + $checkedConvert( + 'numberSillySet', + (v) => (v as List<dynamic>) + .map( + (e) => + TrivialNumberConverter.instance.fromJson((e as num?)?.toInt()), + ) + .toSet(), + ), + $checkedConvert( + 'dateTime', + (v) => const EpochDateTimeConverter().fromJson((v as num?)?.toInt()), + ), + $checkedConvert( + 'trivialString', + (v) => trivialStringConverter.fromJson(v as String?), + ), + $checkedConvert( + 'nullableNumberSilly', + (v) => TrivialNumberConverter.instance.fromJson((v as num?)?.toInt()), + ), + $checkedConvert( + 'nullableNumberSillySet', + (v) => (v as List<dynamic>) + .map( + (e) => + TrivialNumberConverter.instance.fromJson((e as num?)?.toInt()), + ) + .toSet(), + ), + ); + return val; +}); Map<String, dynamic> _$JsonConverterTestClassToJson( - JsonConverterTestClass instance) => - <String, dynamic>{ - 'duration': - const DurationMillisecondConverter().toJson(instance.duration), - 'durationList': instance.durationList - .map(const DurationMillisecondConverter().toJson) - .toList(), - 'bigInt': const BigIntStringConverter().toJson(instance.bigInt), - 'bigIntMap': instance.bigIntMap - .map((k, e) => MapEntry(k, const BigIntStringConverter().toJson(e))), - 'nullableBigInt': _$JsonConverterToJson<String, BigInt>( - instance.nullableBigInt, const BigIntStringConverter().toJson), - 'nullableBigIntMap': instance.nullableBigIntMap.map((k, e) => MapEntry( - k, - _$JsonConverterToJson<String, BigInt>( - e, const BigIntStringConverter().toJson))), - 'numberSilly': - TrivialNumberConverter.instance.toJson(instance.numberSilly), - 'numberSillySet': instance.numberSillySet - .map(TrivialNumberConverter.instance.toJson) - .toList(), - 'dateTime': const EpochDateTimeConverter().toJson(instance.dateTime), - 'trivialString': trivialStringConverter.toJson(instance.trivialString), - 'nullableNumberSilly': _$JsonConverterToJson<int?, TrivialNumber>( - instance.nullableNumberSilly, TrivialNumberConverter.instance.toJson), - 'nullableNumberSillySet': instance.nullableNumberSillySet - .map((e) => _$JsonConverterToJson<int?, TrivialNumber>( - e, TrivialNumberConverter.instance.toJson)) - .toList(), - }; + JsonConverterTestClass instance, +) => <String, dynamic>{ + 'duration': const DurationMillisecondConverter().toJson(instance.duration), + 'durationList': instance.durationList + .map(const DurationMillisecondConverter().toJson) + .toList(), + 'bigInt': const BigIntStringConverter().toJson(instance.bigInt), + 'bigIntMap': instance.bigIntMap.map( + (k, e) => MapEntry(k, const BigIntStringConverter().toJson(e)), + ), + 'nullableBigInt': _$JsonConverterToJson<String, BigInt>( + instance.nullableBigInt, + const BigIntStringConverter().toJson, + ), + 'nullableBigIntMap': instance.nullableBigIntMap.map( + (k, e) => MapEntry( + k, + _$JsonConverterToJson<String, BigInt>( + e, + const BigIntStringConverter().toJson, + ), + ), + ), + 'numberSilly': TrivialNumberConverter.instance.toJson(instance.numberSilly), + 'numberSillySet': instance.numberSillySet + .map(TrivialNumberConverter.instance.toJson) + .toList(), + 'dateTime': const EpochDateTimeConverter().toJson(instance.dateTime), + 'trivialString': trivialStringConverter.toJson(instance.trivialString), + 'nullableNumberSilly': _$JsonConverterToJson<int?, TrivialNumber>( + instance.nullableNumberSilly, + TrivialNumberConverter.instance.toJson, + ), + 'nullableNumberSillySet': instance.nullableNumberSillySet + .map( + (e) => _$JsonConverterToJson<int?, TrivialNumber>( + e, + TrivialNumberConverter.instance.toJson, + ), + ) + .toList(), +}; Value? _$JsonConverterFromJson<Json, Value>( Object? json, Value? Function(Json json) fromJson, -) => - json == null ? null : fromJson(json as Json); +) => json == null ? null : fromJson(json as Json); Json? _$JsonConverterToJson<Json, Value>( Value? value, Json? Function(Value value) toJson, -) => - value == null ? null : toJson(value); +) => value == null ? null : toJson(value); JsonConverterGeneric<S, T, U> _$JsonConverterGenericFromJson<S, T, U>( - Map json) => - $checkedCreate( - 'JsonConverterGeneric', - json, - ($checkedConvert) { - final val = JsonConverterGeneric<S, T, U>( - $checkedConvert('item', - (v) => GenericConverter<S>().fromJson(v as Map<String, dynamic>)), - $checkedConvert( - 'itemList', - (v) => (v as List<dynamic>) - .map((e) => - GenericConverter<T>().fromJson(e as Map<String, dynamic>)) - .toList()), - $checkedConvert( - 'itemMap', - (v) => (v as Map).map( - (k, e) => MapEntry( - k as String, - GenericConverter<U>() - .fromJson(e as Map<String, dynamic>)), - )), - ); - return val; - }, - ); + Map json, +) => $checkedCreate('JsonConverterGeneric', json, ($checkedConvert) { + final val = JsonConverterGeneric<S, T, U>( + $checkedConvert( + 'item', + (v) => GenericConverter<S>().fromJson(v as Map<String, dynamic>), + ), + $checkedConvert( + 'itemList', + (v) => (v as List<dynamic>) + .map((e) => GenericConverter<T>().fromJson(e as Map<String, dynamic>)) + .toList(), + ), + $checkedConvert( + 'itemMap', + (v) => (v as Map).map( + (k, e) => MapEntry( + k as String, + GenericConverter<U>().fromJson(e as Map<String, dynamic>), + ), + ), + ), + ); + return val; +}); Map<String, dynamic> _$JsonConverterGenericToJson<S, T, U>( - JsonConverterGeneric<S, T, U> instance) => - <String, dynamic>{ - 'item': GenericConverter<S>().toJson(instance.item), - 'itemList': instance.itemList.map(GenericConverter<T>().toJson).toList(), - 'itemMap': instance.itemMap - .map((k, e) => MapEntry(k, GenericConverter<U>().toJson(e))), - }; + JsonConverterGeneric<S, T, U> instance, +) => <String, dynamic>{ + 'item': GenericConverter<S>().toJson(instance.item), + 'itemList': instance.itemList.map(GenericConverter<T>().toJson).toList(), + 'itemMap': instance.itemMap.map( + (k, e) => MapEntry(k, GenericConverter<U>().toJson(e)), + ), +}; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.dart index 5dda14726..a5b701cd7 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.dart @@ -48,33 +48,32 @@ class _Factory implements k.KitchenSinkFactory<String, dynamic> { Iterable<Object>? objectIterable, Iterable<int>? intIterable, Iterable<DateTime>? dateTimeIterable, - }) => - KitchenSink( - ctorValidatedNo42: ctorValidatedNo42, - iterable: iterable, - dynamicIterable: dynamicIterable, - objectIterable: objectIterable, - intIterable: intIterable, - dateTimeIterable: dateTimeIterable, - ); + }) => KitchenSink( + ctorValidatedNo42: ctorValidatedNo42, + iterable: iterable, + dynamicIterable: dynamicIterable, + objectIterable: objectIterable, + intIterable: intIterable, + dateTimeIterable: dateTimeIterable, + ); k.KitchenSink fromJson(Map<String, dynamic> json) => KitchenSink.fromJson(json); k.JsonConverterTestClass jsonConverterCtor() => JsonConverterTestClass( - const Duration(), - [], - BigInt.zero, - {}, - BigInt.zero, - {}, - TrivialNumber(0), - {}, - DateTime.fromMillisecondsSinceEpoch(0), - TrivialString(''), - TrivialNumber(0), - {}, - ); + const Duration(), + [], + BigInt.zero, + {}, + BigInt.zero, + {}, + TrivialNumber(0), + {}, + DateTime.fromMillisecondsSinceEpoch(0), + TrivialString(''), + TrivialNumber(0), + {}, + ); k.JsonConverterTestClass jsonConverterFromJson(Map<String, dynamic> json) => JsonConverterTestClass.fromJson(json); @@ -88,9 +87,7 @@ Object? _valueAccessor(Map json, String key) { return json[key]; } -@JsonSerializable( - includeIfNull: false, -) +@JsonSerializable(includeIfNull: false) class KitchenSink implements k.KitchenSink { // NOTE: exposing these as Iterable, but storing the values as List // to make the equality test work trivially. @@ -110,14 +107,17 @@ class KitchenSink implements k.KitchenSink { Iterable<Object>? objectIterable, Iterable<int>? intIterable, Iterable<DateTime>? dateTimeIterable, - }) : _iterable = iterable?.toList(), - _dynamicIterable = dynamicIterable?.toList() ?? _defaultList(), - _objectIterable = objectIterable?.toList() ?? _defaultList(), - _intIterable = intIterable?.toList() ?? _defaultList(), - _dateTimeIterable = dateTimeIterable?.toList() ?? _defaultList() { + }) : _iterable = iterable?.toList(), + _dynamicIterable = dynamicIterable?.toList() ?? _defaultList(), + _objectIterable = objectIterable?.toList() ?? _defaultList(), + _intIterable = intIterable?.toList() ?? _defaultList(), + _dateTimeIterable = dateTimeIterable?.toList() ?? _defaultList() { if (ctorValidatedNo42 == 42) { throw ArgumentError.value( - 42, 'ctorValidatedNo42', 'The value `42` is not allowed.'); + 42, + 'ctorValidatedNo42', + 'The value `42` is not allowed.', + ); } } @@ -199,12 +199,15 @@ class KitchenSink implements k.KitchenSink { } } -@JsonSerializable(includeIfNull: false, converters: [ - // referencing a top-level field should work - durationConverter, - // referencing via a const constructor should work - BigIntStringConverter(), -]) +@JsonSerializable( + includeIfNull: false, + converters: [ + // referencing a top-level field should work + durationConverter, + // referencing via a const constructor should work + BigIntStringConverter(), + ], +) // referencing a top-level field should work @trivialStringConverter @TrivialNumberConverter.instance @@ -250,9 +253,7 @@ class JsonConverterTestClass implements k.JsonConverterTestClass { Set<TrivialNumber?> nullableNumberSillySet; } -@JsonSerializable( - includeIfNull: false, -) +@JsonSerializable(includeIfNull: false) // ignore: inference_failure_on_instance_creation @GenericConverter() class JsonConverterGeneric<S, T, U> { @@ -260,11 +261,7 @@ class JsonConverterGeneric<S, T, U> { List<T> itemList; Map<String, U> itemMap; - JsonConverterGeneric( - this.item, - this.itemList, - this.itemMap, - ); + JsonConverterGeneric(this.item, this.itemList, this.itemMap); factory JsonConverterGeneric.fromJson(Map<String, dynamic> json) => _$JsonConverterGenericFromJson(json); diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart index 39b0eb184..3ea352ae7 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart @@ -8,26 +8,32 @@ part of 'kitchen_sink.g_exclude_null.dart'; // JsonSerializableGenerator // ************************************************************************** -KitchenSink _$KitchenSinkFromJson(Map<String, dynamic> json) => KitchenSink( - ctorValidatedNo42: (json['no-42'] as num?)?.toInt(), - iterable: _valueAccessor(json, 'iterable') as List<dynamic>?, - dynamicIterable: json['dynamicIterable'] as List<dynamic>?, - objectIterable: - (json['objectIterable'] as List<dynamic>?)?.map((e) => e as Object), - intIterable: (json['intIterable'] as List<dynamic>?) - ?.map((e) => (e as num).toInt()), - dateTimeIterable: (json['datetime-iterable'] as List<dynamic>?) - ?.map((e) => DateTime.parse(e as String)), - ) +KitchenSink _$KitchenSinkFromJson(Map<String, dynamic> json) => + KitchenSink( + ctorValidatedNo42: (json['no-42'] as num?)?.toInt(), + iterable: _valueAccessor(json, 'iterable') as List<dynamic>?, + dynamicIterable: json['dynamicIterable'] as List<dynamic>?, + objectIterable: (json['objectIterable'] as List<dynamic>?)?.map( + (e) => e as Object, + ), + intIterable: (json['intIterable'] as List<dynamic>?)?.map( + (e) => (e as num).toInt(), + ), + dateTimeIterable: (json['datetime-iterable'] as List<dynamic>?)?.map( + (e) => DateTime.parse(e as String), + ), + ) ..dateTime = json['dateTime'] == null ? null : DateTime.parse(json['dateTime'] as String) - ..bigInt = - json['bigInt'] == null ? null : BigInt.parse(json['bigInt'] as String) + ..bigInt = json['bigInt'] == null + ? null + : BigInt.parse(json['bigInt'] as String) ..set = (json['set'] as List<dynamic>).toSet() ..dynamicSet = (json['dynamicSet'] as List<dynamic>).toSet() - ..objectSet = - (json['objectSet'] as List<dynamic>).map((e) => e as Object).toSet() + ..objectSet = (json['objectSet'] as List<dynamic>) + .map((e) => e as Object) + .toSet() ..intSet = (json['intSet'] as List<dynamic>) .map((e) => (e as num).toInt()) .toSet() @@ -36,8 +42,9 @@ KitchenSink _$KitchenSinkFromJson(Map<String, dynamic> json) => KitchenSink( .toSet() ..list = json['list'] as List<dynamic> ..dynamicList = json['dynamicList'] as List<dynamic> - ..objectList = - (json['objectList'] as List<dynamic>).map((e) => e as Object).toList() + ..objectList = (json['objectList'] as List<dynamic>) + .map((e) => e as Object) + .toList() ..intList = (json['intList'] as List<dynamic>) .map((e) => (e as num).toInt()) .toList() @@ -46,48 +53,58 @@ KitchenSink _$KitchenSinkFromJson(Map<String, dynamic> json) => KitchenSink( .toList() ..nullableSimpleObjectList = (json['nullableSimpleObjectList'] as List<dynamic>) - .map((e) => e == null - ? null - : SimpleObject.fromJson(e as Map<String, dynamic>)) + .map( + (e) => e == null + ? null + : SimpleObject.fromJson(e as Map<String, dynamic>), + ) .toList() ..map = json['map'] as Map<String, dynamic> - ..stringStringMap = - Map<String, String>.from(json['stringStringMap'] as Map) - ..dynamicIntMap = Map<String, int>.from(json['dynamicIntMap'] as Map) - ..objectDateTimeMap = - (json['objectDateTimeMap'] as Map<String, dynamic>).map( - (k, e) => MapEntry(k, DateTime.parse(e as String)), + ..stringStringMap = Map<String, String>.from( + json['stringStringMap'] as Map, ) + ..dynamicIntMap = Map<String, int>.from(json['dynamicIntMap'] as Map) + ..objectDateTimeMap = (json['objectDateTimeMap'] as Map<String, dynamic>) + .map((k, e) => MapEntry(k, DateTime.parse(e as String))) ..nullableSimpleObjectMap = (json['nullableSimpleObjectMap'] as Map<String, dynamic>).map( - (k, e) => MapEntry( - k, - e == null - ? null - : SimpleObject.fromJson(e as Map<String, dynamic>)), - ) + (k, e) => MapEntry( + k, + e == null + ? null + : SimpleObject.fromJson(e as Map<String, dynamic>), + ), + ) ..crazyComplex = (json['crazyComplex'] as List<dynamic>) - .map((e) => (e as Map<String, dynamic>?)?.map( - (k, e) => MapEntry( + .map( + (e) => (e as Map<String, dynamic>?)?.map( + (k, e) => MapEntry( + k, + (e as Map<String, dynamic>?)?.map( + (k, e) => MapEntry( k, - (e as Map<String, dynamic>?)?.map( - (k, e) => MapEntry( - k, - (e as List<dynamic>?) - ?.map((e) => (e as List<dynamic>?) - ?.map((e) => DateTime.parse(e as String)) - .toList()) - .toList()), - )), - )) + (e as List<dynamic>?) + ?.map( + (e) => (e as List<dynamic>?) + ?.map((e) => DateTime.parse(e as String)) + .toList(), + ) + .toList(), + ), + ), + ), + ), + ) .toList() ..val = Map<String, bool>.from(json['val'] as Map) ..writeNotNull = json['writeNotNull'] as bool? ..string = KitchenSink._trickyValueAccessor(json, r'$string') as String? - ..simpleObject = - SimpleObject.fromJson(json['simpleObject'] as Map<String, dynamic>) + ..simpleObject = SimpleObject.fromJson( + json['simpleObject'] as Map<String, dynamic>, + ) ..strictKeysObject = StrictKeysObject.fromJson( - json['strictKeysObject'] as Map<String, dynamic>) + json['strictKeysObject'] as Map<String, dynamic>, + ) ..validatedPropertyNo42 = (json['validatedPropertyNo42'] as num?)?.toInt() ..recordField = _$recordConvertNullable( json['recordField'], @@ -98,182 +115,212 @@ KitchenSink _$KitchenSinkFromJson(Map<String, dynamic> json) => KitchenSink( ), ); -Map<String, dynamic> _$KitchenSinkToJson(KitchenSink instance) => - <String, dynamic>{ - if (instance.ctorValidatedNo42 case final value?) 'no-42': value, - if (instance.dateTime?.toIso8601String() case final value?) - 'dateTime': value, - if (instance.bigInt?.toString() case final value?) 'bigInt': value, - if (instance.iterable?.toList() case final value?) 'iterable': value, - 'dynamicIterable': instance.dynamicIterable.toList(), - 'objectIterable': instance.objectIterable.toList(), - 'intIterable': instance.intIterable.toList(), - 'set': instance.set.toList(), - 'dynamicSet': instance.dynamicSet.toList(), - 'objectSet': instance.objectSet.toList(), - 'intSet': instance.intSet.toList(), - 'dateTimeSet': - instance.dateTimeSet.map((e) => e.toIso8601String()).toList(), - 'datetime-iterable': - instance.dateTimeIterable.map((e) => e.toIso8601String()).toList(), - 'list': instance.list, - 'dynamicList': instance.dynamicList, - 'objectList': instance.objectList, - 'intList': instance.intList, - 'dateTimeList': - instance.dateTimeList.map((e) => e.toIso8601String()).toList(), - 'nullableSimpleObjectList': instance.nullableSimpleObjectList, - 'map': instance.map, - 'stringStringMap': instance.stringStringMap, - 'dynamicIntMap': instance.dynamicIntMap, - 'objectDateTimeMap': instance.objectDateTimeMap - .map((k, e) => MapEntry(k, e.toIso8601String())), - 'nullableSimpleObjectMap': instance.nullableSimpleObjectMap, - 'crazyComplex': instance.crazyComplex - .map((e) => e?.map((k, e) => MapEntry( - k, - e?.map((k, e) => MapEntry( - k, - e - ?.map((e) => e?.map((e) => e.toIso8601String()).toList()) - .toList()))))) - .toList(), - 'val': instance.val, - if (instance.writeNotNull case final value?) 'writeNotNull': value, - if (instance.string case final value?) r'$string': value, - 'simpleObject': instance.simpleObject, - 'strictKeysObject': instance.strictKeysObject, - if (instance.validatedPropertyNo42 case final value?) - 'validatedPropertyNo42': value, - if (instance.recordField == null - ? null - : <String, dynamic>{ - r'$1': instance.recordField!.$1, - r'$2': instance.recordField!.$2, - 'truth': instance.recordField!.truth, - } - case final value?) - 'recordField': value, - }; +Map<String, dynamic> _$KitchenSinkToJson( + KitchenSink instance, +) => <String, dynamic>{ + if (instance.ctorValidatedNo42 case final value?) 'no-42': value, + if (instance.dateTime?.toIso8601String() case final value?) 'dateTime': value, + if (instance.bigInt?.toString() case final value?) 'bigInt': value, + if (instance.iterable?.toList() case final value?) 'iterable': value, + 'dynamicIterable': instance.dynamicIterable.toList(), + 'objectIterable': instance.objectIterable.toList(), + 'intIterable': instance.intIterable.toList(), + 'set': instance.set.toList(), + 'dynamicSet': instance.dynamicSet.toList(), + 'objectSet': instance.objectSet.toList(), + 'intSet': instance.intSet.toList(), + 'dateTimeSet': instance.dateTimeSet.map((e) => e.toIso8601String()).toList(), + 'datetime-iterable': instance.dateTimeIterable + .map((e) => e.toIso8601String()) + .toList(), + 'list': instance.list, + 'dynamicList': instance.dynamicList, + 'objectList': instance.objectList, + 'intList': instance.intList, + 'dateTimeList': instance.dateTimeList + .map((e) => e.toIso8601String()) + .toList(), + 'nullableSimpleObjectList': instance.nullableSimpleObjectList, + 'map': instance.map, + 'stringStringMap': instance.stringStringMap, + 'dynamicIntMap': instance.dynamicIntMap, + 'objectDateTimeMap': instance.objectDateTimeMap.map( + (k, e) => MapEntry(k, e.toIso8601String()), + ), + 'nullableSimpleObjectMap': instance.nullableSimpleObjectMap, + 'crazyComplex': instance.crazyComplex + .map( + (e) => e?.map( + (k, e) => MapEntry( + k, + e?.map( + (k, e) => MapEntry( + k, + e + ?.map((e) => e?.map((e) => e.toIso8601String()).toList()) + .toList(), + ), + ), + ), + ), + ) + .toList(), + 'val': instance.val, + if (instance.writeNotNull case final value?) 'writeNotNull': value, + if (instance.string case final value?) r'$string': value, + 'simpleObject': instance.simpleObject, + 'strictKeysObject': instance.strictKeysObject, + if (instance.validatedPropertyNo42 case final value?) + 'validatedPropertyNo42': value, + if (instance.recordField == null + ? null + : <String, dynamic>{ + r'$1': instance.recordField!.$1, + r'$2': instance.recordField!.$2, + 'truth': instance.recordField!.truth, + } + case final value?) + 'recordField': value, +}; $Rec? _$recordConvertNullable<$Rec>( Object? value, $Rec Function(Map) convert, -) => - value == null ? null : convert(value as Map<String, dynamic>); +) => value == null ? null : convert(value as Map<String, dynamic>); JsonConverterTestClass _$JsonConverterTestClassFromJson( - Map<String, dynamic> json) => - JsonConverterTestClass( - const DurationMillisecondConverter() - .fromJson((json['duration'] as num?)?.toInt()), - (json['durationList'] as List<dynamic>) - .map((e) => const DurationMillisecondConverter() - .fromJson((e as num?)?.toInt())) - .toList(), - const BigIntStringConverter().fromJson(json['bigInt'] as String), - (json['bigIntMap'] as Map<String, dynamic>).map( - (k, e) => - MapEntry(k, const BigIntStringConverter().fromJson(e as String)), - ), + Map<String, dynamic> json, +) => JsonConverterTestClass( + const DurationMillisecondConverter().fromJson( + (json['duration'] as num?)?.toInt(), + ), + (json['durationList'] as List<dynamic>) + .map( + (e) => + const DurationMillisecondConverter().fromJson((e as num?)?.toInt()), + ) + .toList(), + const BigIntStringConverter().fromJson(json['bigInt'] as String), + (json['bigIntMap'] as Map<String, dynamic>).map( + (k, e) => MapEntry(k, const BigIntStringConverter().fromJson(e as String)), + ), + _$JsonConverterFromJson<String, BigInt>( + json['nullableBigInt'], + const BigIntStringConverter().fromJson, + ), + (json['nullableBigIntMap'] as Map<String, dynamic>).map( + (k, e) => MapEntry( + k, _$JsonConverterFromJson<String, BigInt>( - json['nullableBigInt'], const BigIntStringConverter().fromJson), - (json['nullableBigIntMap'] as Map<String, dynamic>).map( - (k, e) => MapEntry( - k, - _$JsonConverterFromJson<String, BigInt>( - e, const BigIntStringConverter().fromJson)), + e, + const BigIntStringConverter().fromJson, ), - TrivialNumberConverter.instance - .fromJson((json['numberSilly'] as num?)?.toInt()), - (json['numberSillySet'] as List<dynamic>) - .map((e) => - TrivialNumberConverter.instance.fromJson((e as num?)?.toInt())) - .toSet(), - const EpochDateTimeConverter() - .fromJson((json['dateTime'] as num?)?.toInt()), - trivialStringConverter.fromJson(json['trivialString'] as String?), - TrivialNumberConverter.instance - .fromJson((json['nullableNumberSilly'] as num?)?.toInt()), - (json['nullableNumberSillySet'] as List<dynamic>) - .map((e) => - TrivialNumberConverter.instance.fromJson((e as num?)?.toInt())) - .toSet(), - ); + ), + ), + TrivialNumberConverter.instance.fromJson( + (json['numberSilly'] as num?)?.toInt(), + ), + (json['numberSillySet'] as List<dynamic>) + .map( + (e) => TrivialNumberConverter.instance.fromJson((e as num?)?.toInt()), + ) + .toSet(), + const EpochDateTimeConverter().fromJson((json['dateTime'] as num?)?.toInt()), + trivialStringConverter.fromJson(json['trivialString'] as String?), + TrivialNumberConverter.instance.fromJson( + (json['nullableNumberSilly'] as num?)?.toInt(), + ), + (json['nullableNumberSillySet'] as List<dynamic>) + .map( + (e) => TrivialNumberConverter.instance.fromJson((e as num?)?.toInt()), + ) + .toSet(), +); Map<String, dynamic> _$JsonConverterTestClassToJson( - JsonConverterTestClass instance) => - <String, dynamic>{ - if (const DurationMillisecondConverter().toJson(instance.duration) - case final value?) - 'duration': value, - 'durationList': instance.durationList - .map(const DurationMillisecondConverter().toJson) - .toList(), - 'bigInt': const BigIntStringConverter().toJson(instance.bigInt), - 'bigIntMap': instance.bigIntMap - .map((k, e) => MapEntry(k, const BigIntStringConverter().toJson(e))), - if (_$JsonConverterToJson<String, BigInt>( - instance.nullableBigInt, const BigIntStringConverter().toJson) - case final value?) - 'nullableBigInt': value, - 'nullableBigIntMap': instance.nullableBigIntMap.map((k, e) => MapEntry( - k, - _$JsonConverterToJson<String, BigInt>( - e, const BigIntStringConverter().toJson))), - if (TrivialNumberConverter.instance.toJson(instance.numberSilly) - case final value?) - 'numberSilly': value, - 'numberSillySet': instance.numberSillySet - .map(TrivialNumberConverter.instance.toJson) - .toList(), - if (const EpochDateTimeConverter().toJson(instance.dateTime) - case final value?) - 'dateTime': value, - if (trivialStringConverter.toJson(instance.trivialString) - case final value?) - 'trivialString': value, - if (_$JsonConverterToJson<int?, TrivialNumber>( - instance.nullableNumberSilly, - TrivialNumberConverter.instance.toJson) - case final value?) - 'nullableNumberSilly': value, - 'nullableNumberSillySet': instance.nullableNumberSillySet - .map((e) => _$JsonConverterToJson<int?, TrivialNumber>( - e, TrivialNumberConverter.instance.toJson)) - .toList(), - }; + JsonConverterTestClass instance, +) => <String, dynamic>{ + if (const DurationMillisecondConverter().toJson(instance.duration) + case final value?) + 'duration': value, + 'durationList': instance.durationList + .map(const DurationMillisecondConverter().toJson) + .toList(), + 'bigInt': const BigIntStringConverter().toJson(instance.bigInt), + 'bigIntMap': instance.bigIntMap.map( + (k, e) => MapEntry(k, const BigIntStringConverter().toJson(e)), + ), + if (_$JsonConverterToJson<String, BigInt>( + instance.nullableBigInt, + const BigIntStringConverter().toJson, + ) + case final value?) + 'nullableBigInt': value, + 'nullableBigIntMap': instance.nullableBigIntMap.map( + (k, e) => MapEntry( + k, + _$JsonConverterToJson<String, BigInt>( + e, + const BigIntStringConverter().toJson, + ), + ), + ), + if (TrivialNumberConverter.instance.toJson(instance.numberSilly) + case final value?) + 'numberSilly': value, + 'numberSillySet': instance.numberSillySet + .map(TrivialNumberConverter.instance.toJson) + .toList(), + if (const EpochDateTimeConverter().toJson(instance.dateTime) + case final value?) + 'dateTime': value, + if (trivialStringConverter.toJson(instance.trivialString) case final value?) + 'trivialString': value, + if (_$JsonConverterToJson<int?, TrivialNumber>( + instance.nullableNumberSilly, + TrivialNumberConverter.instance.toJson, + ) + case final value?) + 'nullableNumberSilly': value, + 'nullableNumberSillySet': instance.nullableNumberSillySet + .map( + (e) => _$JsonConverterToJson<int?, TrivialNumber>( + e, + TrivialNumberConverter.instance.toJson, + ), + ) + .toList(), +}; Value? _$JsonConverterFromJson<Json, Value>( Object? json, Value? Function(Json json) fromJson, -) => - json == null ? null : fromJson(json as Json); +) => json == null ? null : fromJson(json as Json); Json? _$JsonConverterToJson<Json, Value>( Value? value, Json? Function(Value value) toJson, -) => - value == null ? null : toJson(value); +) => value == null ? null : toJson(value); JsonConverterGeneric<S, T, U> _$JsonConverterGenericFromJson<S, T, U>( - Map<String, dynamic> json) => - JsonConverterGeneric<S, T, U>( - GenericConverter<S>().fromJson(json['item'] as Map<String, dynamic>), - (json['itemList'] as List<dynamic>) - .map((e) => GenericConverter<T>().fromJson(e as Map<String, dynamic>)) - .toList(), - (json['itemMap'] as Map<String, dynamic>).map( - (k, e) => MapEntry( - k, GenericConverter<U>().fromJson(e as Map<String, dynamic>)), - ), - ); + Map<String, dynamic> json, +) => JsonConverterGeneric<S, T, U>( + GenericConverter<S>().fromJson(json['item'] as Map<String, dynamic>), + (json['itemList'] as List<dynamic>) + .map((e) => GenericConverter<T>().fromJson(e as Map<String, dynamic>)) + .toList(), + (json['itemMap'] as Map<String, dynamic>).map( + (k, e) => + MapEntry(k, GenericConverter<U>().fromJson(e as Map<String, dynamic>)), + ), +); Map<String, dynamic> _$JsonConverterGenericToJson<S, T, U>( - JsonConverterGeneric<S, T, U> instance) => - <String, dynamic>{ - 'item': GenericConverter<S>().toJson(instance.item), - 'itemList': instance.itemList.map(GenericConverter<T>().toJson).toList(), - 'itemMap': instance.itemMap - .map((k, e) => MapEntry(k, GenericConverter<U>().toJson(e))), - }; + JsonConverterGeneric<S, T, U> instance, +) => <String, dynamic>{ + 'item': GenericConverter<S>().toJson(instance.item), + 'itemList': instance.itemList.map(GenericConverter<T>().toJson).toList(), + 'itemMap': instance.itemMap.map( + (k, e) => MapEntry(k, GenericConverter<U>().toJson(e)), + ), +}; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.dart index efccc8f08..bebc9da38 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.dart @@ -48,33 +48,32 @@ class _Factory implements k.KitchenSinkFactory<String, dynamic> { Iterable<Object>? objectIterable, Iterable<int>? intIterable, Iterable<DateTime>? dateTimeIterable, - }) => - KitchenSink( - ctorValidatedNo42: ctorValidatedNo42, - iterable: iterable, - dynamicIterable: dynamicIterable, - objectIterable: objectIterable, - intIterable: intIterable, - dateTimeIterable: dateTimeIterable, - ); + }) => KitchenSink( + ctorValidatedNo42: ctorValidatedNo42, + iterable: iterable, + dynamicIterable: dynamicIterable, + objectIterable: objectIterable, + intIterable: intIterable, + dateTimeIterable: dateTimeIterable, + ); k.KitchenSink fromJson(Map<String, dynamic> json) => KitchenSink.fromJson(json); k.JsonConverterTestClass jsonConverterCtor() => JsonConverterTestClass( - const Duration(), - [], - BigInt.zero, - {}, - BigInt.zero, - {}, - TrivialNumber(0), - {}, - DateTime.fromMillisecondsSinceEpoch(0), - TrivialString(''), - TrivialNumber(0), - {}, - ); + const Duration(), + [], + BigInt.zero, + {}, + BigInt.zero, + {}, + TrivialNumber(0), + {}, + DateTime.fromMillisecondsSinceEpoch(0), + TrivialString(''), + TrivialNumber(0), + {}, + ); k.JsonConverterTestClass jsonConverterFromJson(Map<String, dynamic> json) => JsonConverterTestClass.fromJson(json); @@ -88,9 +87,7 @@ Object? _valueAccessor(Map json, String key) { return json[key]; } -@JsonSerializable( - explicitToJson: true, -) +@JsonSerializable(explicitToJson: true) class KitchenSink implements k.KitchenSink { // NOTE: exposing these as Iterable, but storing the values as List // to make the equality test work trivially. @@ -110,14 +107,17 @@ class KitchenSink implements k.KitchenSink { Iterable<Object>? objectIterable, Iterable<int>? intIterable, Iterable<DateTime>? dateTimeIterable, - }) : _iterable = iterable?.toList(), - _dynamicIterable = dynamicIterable?.toList() ?? _defaultList(), - _objectIterable = objectIterable?.toList() ?? _defaultList(), - _intIterable = intIterable?.toList() ?? _defaultList(), - _dateTimeIterable = dateTimeIterable?.toList() ?? _defaultList() { + }) : _iterable = iterable?.toList(), + _dynamicIterable = dynamicIterable?.toList() ?? _defaultList(), + _objectIterable = objectIterable?.toList() ?? _defaultList(), + _intIterable = intIterable?.toList() ?? _defaultList(), + _dateTimeIterable = dateTimeIterable?.toList() ?? _defaultList() { if (ctorValidatedNo42 == 42) { throw ArgumentError.value( - 42, 'ctorValidatedNo42', 'The value `42` is not allowed.'); + 42, + 'ctorValidatedNo42', + 'The value `42` is not allowed.', + ); } } @@ -199,12 +199,15 @@ class KitchenSink implements k.KitchenSink { } } -@JsonSerializable(explicitToJson: true, converters: [ - // referencing a top-level field should work - durationConverter, - // referencing via a const constructor should work - BigIntStringConverter(), -]) +@JsonSerializable( + explicitToJson: true, + converters: [ + // referencing a top-level field should work + durationConverter, + // referencing via a const constructor should work + BigIntStringConverter(), + ], +) // referencing a top-level field should work @trivialStringConverter @TrivialNumberConverter.instance @@ -250,9 +253,7 @@ class JsonConverterTestClass implements k.JsonConverterTestClass { Set<TrivialNumber?> nullableNumberSillySet; } -@JsonSerializable( - explicitToJson: true, -) +@JsonSerializable(explicitToJson: true) // ignore: inference_failure_on_instance_creation @GenericConverter() class JsonConverterGeneric<S, T, U> { @@ -260,11 +261,7 @@ class JsonConverterGeneric<S, T, U> { List<T> itemList; Map<String, U> itemMap; - JsonConverterGeneric( - this.item, - this.itemList, - this.itemMap, - ); + JsonConverterGeneric(this.item, this.itemList, this.itemMap); factory JsonConverterGeneric.fromJson(Map<String, dynamic> json) => _$JsonConverterGenericFromJson(json); diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart index 0115b3fff..366035c7c 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart @@ -8,26 +8,32 @@ part of 'kitchen_sink.g_explicit_to_json.dart'; // JsonSerializableGenerator // ************************************************************************** -KitchenSink _$KitchenSinkFromJson(Map<String, dynamic> json) => KitchenSink( - ctorValidatedNo42: (json['no-42'] as num?)?.toInt(), - iterable: _valueAccessor(json, 'iterable') as List<dynamic>?, - dynamicIterable: json['dynamicIterable'] as List<dynamic>?, - objectIterable: - (json['objectIterable'] as List<dynamic>?)?.map((e) => e as Object), - intIterable: (json['intIterable'] as List<dynamic>?) - ?.map((e) => (e as num).toInt()), - dateTimeIterable: (json['datetime-iterable'] as List<dynamic>?) - ?.map((e) => DateTime.parse(e as String)), - ) +KitchenSink _$KitchenSinkFromJson(Map<String, dynamic> json) => + KitchenSink( + ctorValidatedNo42: (json['no-42'] as num?)?.toInt(), + iterable: _valueAccessor(json, 'iterable') as List<dynamic>?, + dynamicIterable: json['dynamicIterable'] as List<dynamic>?, + objectIterable: (json['objectIterable'] as List<dynamic>?)?.map( + (e) => e as Object, + ), + intIterable: (json['intIterable'] as List<dynamic>?)?.map( + (e) => (e as num).toInt(), + ), + dateTimeIterable: (json['datetime-iterable'] as List<dynamic>?)?.map( + (e) => DateTime.parse(e as String), + ), + ) ..dateTime = json['dateTime'] == null ? null : DateTime.parse(json['dateTime'] as String) - ..bigInt = - json['bigInt'] == null ? null : BigInt.parse(json['bigInt'] as String) + ..bigInt = json['bigInt'] == null + ? null + : BigInt.parse(json['bigInt'] as String) ..set = (json['set'] as List<dynamic>).toSet() ..dynamicSet = (json['dynamicSet'] as List<dynamic>).toSet() - ..objectSet = - (json['objectSet'] as List<dynamic>).map((e) => e as Object).toSet() + ..objectSet = (json['objectSet'] as List<dynamic>) + .map((e) => e as Object) + .toSet() ..intSet = (json['intSet'] as List<dynamic>) .map((e) => (e as num).toInt()) .toSet() @@ -36,8 +42,9 @@ KitchenSink _$KitchenSinkFromJson(Map<String, dynamic> json) => KitchenSink( .toSet() ..list = json['list'] as List<dynamic> ..dynamicList = json['dynamicList'] as List<dynamic> - ..objectList = - (json['objectList'] as List<dynamic>).map((e) => e as Object).toList() + ..objectList = (json['objectList'] as List<dynamic>) + .map((e) => e as Object) + .toList() ..intList = (json['intList'] as List<dynamic>) .map((e) => (e as num).toInt()) .toList() @@ -46,48 +53,58 @@ KitchenSink _$KitchenSinkFromJson(Map<String, dynamic> json) => KitchenSink( .toList() ..nullableSimpleObjectList = (json['nullableSimpleObjectList'] as List<dynamic>) - .map((e) => e == null - ? null - : SimpleObject.fromJson(e as Map<String, dynamic>)) + .map( + (e) => e == null + ? null + : SimpleObject.fromJson(e as Map<String, dynamic>), + ) .toList() ..map = json['map'] as Map<String, dynamic> - ..stringStringMap = - Map<String, String>.from(json['stringStringMap'] as Map) - ..dynamicIntMap = Map<String, int>.from(json['dynamicIntMap'] as Map) - ..objectDateTimeMap = - (json['objectDateTimeMap'] as Map<String, dynamic>).map( - (k, e) => MapEntry(k, DateTime.parse(e as String)), + ..stringStringMap = Map<String, String>.from( + json['stringStringMap'] as Map, ) + ..dynamicIntMap = Map<String, int>.from(json['dynamicIntMap'] as Map) + ..objectDateTimeMap = (json['objectDateTimeMap'] as Map<String, dynamic>) + .map((k, e) => MapEntry(k, DateTime.parse(e as String))) ..nullableSimpleObjectMap = (json['nullableSimpleObjectMap'] as Map<String, dynamic>).map( - (k, e) => MapEntry( - k, - e == null - ? null - : SimpleObject.fromJson(e as Map<String, dynamic>)), - ) + (k, e) => MapEntry( + k, + e == null + ? null + : SimpleObject.fromJson(e as Map<String, dynamic>), + ), + ) ..crazyComplex = (json['crazyComplex'] as List<dynamic>) - .map((e) => (e as Map<String, dynamic>?)?.map( - (k, e) => MapEntry( + .map( + (e) => (e as Map<String, dynamic>?)?.map( + (k, e) => MapEntry( + k, + (e as Map<String, dynamic>?)?.map( + (k, e) => MapEntry( k, - (e as Map<String, dynamic>?)?.map( - (k, e) => MapEntry( - k, - (e as List<dynamic>?) - ?.map((e) => (e as List<dynamic>?) - ?.map((e) => DateTime.parse(e as String)) - .toList()) - .toList()), - )), - )) + (e as List<dynamic>?) + ?.map( + (e) => (e as List<dynamic>?) + ?.map((e) => DateTime.parse(e as String)) + .toList(), + ) + .toList(), + ), + ), + ), + ), + ) .toList() ..val = Map<String, bool>.from(json['val'] as Map) ..writeNotNull = json['writeNotNull'] as bool? ..string = KitchenSink._trickyValueAccessor(json, r'$string') as String? - ..simpleObject = - SimpleObject.fromJson(json['simpleObject'] as Map<String, dynamic>) + ..simpleObject = SimpleObject.fromJson( + json['simpleObject'] as Map<String, dynamic>, + ) ..strictKeysObject = StrictKeysObject.fromJson( - json['strictKeysObject'] as Map<String, dynamic>) + json['strictKeysObject'] as Map<String, dynamic>, + ) ..validatedPropertyNo42 = (json['validatedPropertyNo42'] as num?)?.toInt() ..recordField = _$recordConvertNullable( json['recordField'], @@ -98,169 +115,202 @@ KitchenSink _$KitchenSinkFromJson(Map<String, dynamic> json) => KitchenSink( ), ); -Map<String, dynamic> _$KitchenSinkToJson(KitchenSink instance) => - <String, dynamic>{ - 'no-42': instance.ctorValidatedNo42, - 'dateTime': instance.dateTime?.toIso8601String(), - 'bigInt': instance.bigInt?.toString(), - 'iterable': instance.iterable?.toList(), - 'dynamicIterable': instance.dynamicIterable.toList(), - 'objectIterable': instance.objectIterable.toList(), - 'intIterable': instance.intIterable.toList(), - 'set': instance.set.toList(), - 'dynamicSet': instance.dynamicSet.toList(), - 'objectSet': instance.objectSet.toList(), - 'intSet': instance.intSet.toList(), - 'dateTimeSet': - instance.dateTimeSet.map((e) => e.toIso8601String()).toList(), - 'datetime-iterable': - instance.dateTimeIterable.map((e) => e.toIso8601String()).toList(), - 'list': instance.list, - 'dynamicList': instance.dynamicList, - 'objectList': instance.objectList, - 'intList': instance.intList, - 'dateTimeList': - instance.dateTimeList.map((e) => e.toIso8601String()).toList(), - 'nullableSimpleObjectList': - instance.nullableSimpleObjectList.map((e) => e?.toJson()).toList(), - 'map': instance.map, - 'stringStringMap': instance.stringStringMap, - 'dynamicIntMap': instance.dynamicIntMap, - 'objectDateTimeMap': instance.objectDateTimeMap - .map((k, e) => MapEntry(k, e.toIso8601String())), - 'nullableSimpleObjectMap': instance.nullableSimpleObjectMap - .map((k, e) => MapEntry(k, e?.toJson())), - 'crazyComplex': instance.crazyComplex - .map((e) => e?.map((k, e) => MapEntry( - k, - e?.map((k, e) => MapEntry( - k, - e - ?.map((e) => e?.map((e) => e.toIso8601String()).toList()) - .toList()))))) - .toList(), - 'val': instance.val, - 'writeNotNull': instance.writeNotNull, - r'$string': instance.string, - 'simpleObject': instance.simpleObject.toJson(), - 'strictKeysObject': instance.strictKeysObject.toJson(), - 'validatedPropertyNo42': instance.validatedPropertyNo42, - 'recordField': instance.recordField == null - ? null - : <String, dynamic>{ - r'$1': instance.recordField!.$1, - r'$2': instance.recordField!.$2, - 'truth': instance.recordField!.truth, - }, - }; +Map<String, dynamic> _$KitchenSinkToJson( + KitchenSink instance, +) => <String, dynamic>{ + 'no-42': instance.ctorValidatedNo42, + 'dateTime': instance.dateTime?.toIso8601String(), + 'bigInt': instance.bigInt?.toString(), + 'iterable': instance.iterable?.toList(), + 'dynamicIterable': instance.dynamicIterable.toList(), + 'objectIterable': instance.objectIterable.toList(), + 'intIterable': instance.intIterable.toList(), + 'set': instance.set.toList(), + 'dynamicSet': instance.dynamicSet.toList(), + 'objectSet': instance.objectSet.toList(), + 'intSet': instance.intSet.toList(), + 'dateTimeSet': instance.dateTimeSet.map((e) => e.toIso8601String()).toList(), + 'datetime-iterable': instance.dateTimeIterable + .map((e) => e.toIso8601String()) + .toList(), + 'list': instance.list, + 'dynamicList': instance.dynamicList, + 'objectList': instance.objectList, + 'intList': instance.intList, + 'dateTimeList': instance.dateTimeList + .map((e) => e.toIso8601String()) + .toList(), + 'nullableSimpleObjectList': instance.nullableSimpleObjectList + .map((e) => e?.toJson()) + .toList(), + 'map': instance.map, + 'stringStringMap': instance.stringStringMap, + 'dynamicIntMap': instance.dynamicIntMap, + 'objectDateTimeMap': instance.objectDateTimeMap.map( + (k, e) => MapEntry(k, e.toIso8601String()), + ), + 'nullableSimpleObjectMap': instance.nullableSimpleObjectMap.map( + (k, e) => MapEntry(k, e?.toJson()), + ), + 'crazyComplex': instance.crazyComplex + .map( + (e) => e?.map( + (k, e) => MapEntry( + k, + e?.map( + (k, e) => MapEntry( + k, + e + ?.map((e) => e?.map((e) => e.toIso8601String()).toList()) + .toList(), + ), + ), + ), + ), + ) + .toList(), + 'val': instance.val, + 'writeNotNull': instance.writeNotNull, + r'$string': instance.string, + 'simpleObject': instance.simpleObject.toJson(), + 'strictKeysObject': instance.strictKeysObject.toJson(), + 'validatedPropertyNo42': instance.validatedPropertyNo42, + 'recordField': instance.recordField == null + ? null + : <String, dynamic>{ + r'$1': instance.recordField!.$1, + r'$2': instance.recordField!.$2, + 'truth': instance.recordField!.truth, + }, +}; $Rec? _$recordConvertNullable<$Rec>( Object? value, $Rec Function(Map) convert, -) => - value == null ? null : convert(value as Map<String, dynamic>); +) => value == null ? null : convert(value as Map<String, dynamic>); JsonConverterTestClass _$JsonConverterTestClassFromJson( - Map<String, dynamic> json) => - JsonConverterTestClass( - const DurationMillisecondConverter() - .fromJson((json['duration'] as num?)?.toInt()), - (json['durationList'] as List<dynamic>) - .map((e) => const DurationMillisecondConverter() - .fromJson((e as num?)?.toInt())) - .toList(), - const BigIntStringConverter().fromJson(json['bigInt'] as String), - (json['bigIntMap'] as Map<String, dynamic>).map( - (k, e) => - MapEntry(k, const BigIntStringConverter().fromJson(e as String)), - ), + Map<String, dynamic> json, +) => JsonConverterTestClass( + const DurationMillisecondConverter().fromJson( + (json['duration'] as num?)?.toInt(), + ), + (json['durationList'] as List<dynamic>) + .map( + (e) => + const DurationMillisecondConverter().fromJson((e as num?)?.toInt()), + ) + .toList(), + const BigIntStringConverter().fromJson(json['bigInt'] as String), + (json['bigIntMap'] as Map<String, dynamic>).map( + (k, e) => MapEntry(k, const BigIntStringConverter().fromJson(e as String)), + ), + _$JsonConverterFromJson<String, BigInt>( + json['nullableBigInt'], + const BigIntStringConverter().fromJson, + ), + (json['nullableBigIntMap'] as Map<String, dynamic>).map( + (k, e) => MapEntry( + k, _$JsonConverterFromJson<String, BigInt>( - json['nullableBigInt'], const BigIntStringConverter().fromJson), - (json['nullableBigIntMap'] as Map<String, dynamic>).map( - (k, e) => MapEntry( - k, - _$JsonConverterFromJson<String, BigInt>( - e, const BigIntStringConverter().fromJson)), + e, + const BigIntStringConverter().fromJson, ), - TrivialNumberConverter.instance - .fromJson((json['numberSilly'] as num?)?.toInt()), - (json['numberSillySet'] as List<dynamic>) - .map((e) => - TrivialNumberConverter.instance.fromJson((e as num?)?.toInt())) - .toSet(), - const EpochDateTimeConverter() - .fromJson((json['dateTime'] as num?)?.toInt()), - trivialStringConverter.fromJson(json['trivialString'] as String?), - TrivialNumberConverter.instance - .fromJson((json['nullableNumberSilly'] as num?)?.toInt()), - (json['nullableNumberSillySet'] as List<dynamic>) - .map((e) => - TrivialNumberConverter.instance.fromJson((e as num?)?.toInt())) - .toSet(), - ); + ), + ), + TrivialNumberConverter.instance.fromJson( + (json['numberSilly'] as num?)?.toInt(), + ), + (json['numberSillySet'] as List<dynamic>) + .map( + (e) => TrivialNumberConverter.instance.fromJson((e as num?)?.toInt()), + ) + .toSet(), + const EpochDateTimeConverter().fromJson((json['dateTime'] as num?)?.toInt()), + trivialStringConverter.fromJson(json['trivialString'] as String?), + TrivialNumberConverter.instance.fromJson( + (json['nullableNumberSilly'] as num?)?.toInt(), + ), + (json['nullableNumberSillySet'] as List<dynamic>) + .map( + (e) => TrivialNumberConverter.instance.fromJson((e as num?)?.toInt()), + ) + .toSet(), +); Map<String, dynamic> _$JsonConverterTestClassToJson( - JsonConverterTestClass instance) => - <String, dynamic>{ - 'duration': - const DurationMillisecondConverter().toJson(instance.duration), - 'durationList': instance.durationList - .map(const DurationMillisecondConverter().toJson) - .toList(), - 'bigInt': const BigIntStringConverter().toJson(instance.bigInt), - 'bigIntMap': instance.bigIntMap - .map((k, e) => MapEntry(k, const BigIntStringConverter().toJson(e))), - 'nullableBigInt': _$JsonConverterToJson<String, BigInt>( - instance.nullableBigInt, const BigIntStringConverter().toJson), - 'nullableBigIntMap': instance.nullableBigIntMap.map((k, e) => MapEntry( - k, - _$JsonConverterToJson<String, BigInt>( - e, const BigIntStringConverter().toJson))), - 'numberSilly': - TrivialNumberConverter.instance.toJson(instance.numberSilly), - 'numberSillySet': instance.numberSillySet - .map(TrivialNumberConverter.instance.toJson) - .toList(), - 'dateTime': const EpochDateTimeConverter().toJson(instance.dateTime), - 'trivialString': trivialStringConverter.toJson(instance.trivialString), - 'nullableNumberSilly': _$JsonConverterToJson<int?, TrivialNumber>( - instance.nullableNumberSilly, TrivialNumberConverter.instance.toJson), - 'nullableNumberSillySet': instance.nullableNumberSillySet - .map((e) => _$JsonConverterToJson<int?, TrivialNumber>( - e, TrivialNumberConverter.instance.toJson)) - .toList(), - }; + JsonConverterTestClass instance, +) => <String, dynamic>{ + 'duration': const DurationMillisecondConverter().toJson(instance.duration), + 'durationList': instance.durationList + .map(const DurationMillisecondConverter().toJson) + .toList(), + 'bigInt': const BigIntStringConverter().toJson(instance.bigInt), + 'bigIntMap': instance.bigIntMap.map( + (k, e) => MapEntry(k, const BigIntStringConverter().toJson(e)), + ), + 'nullableBigInt': _$JsonConverterToJson<String, BigInt>( + instance.nullableBigInt, + const BigIntStringConverter().toJson, + ), + 'nullableBigIntMap': instance.nullableBigIntMap.map( + (k, e) => MapEntry( + k, + _$JsonConverterToJson<String, BigInt>( + e, + const BigIntStringConverter().toJson, + ), + ), + ), + 'numberSilly': TrivialNumberConverter.instance.toJson(instance.numberSilly), + 'numberSillySet': instance.numberSillySet + .map(TrivialNumberConverter.instance.toJson) + .toList(), + 'dateTime': const EpochDateTimeConverter().toJson(instance.dateTime), + 'trivialString': trivialStringConverter.toJson(instance.trivialString), + 'nullableNumberSilly': _$JsonConverterToJson<int?, TrivialNumber>( + instance.nullableNumberSilly, + TrivialNumberConverter.instance.toJson, + ), + 'nullableNumberSillySet': instance.nullableNumberSillySet + .map( + (e) => _$JsonConverterToJson<int?, TrivialNumber>( + e, + TrivialNumberConverter.instance.toJson, + ), + ) + .toList(), +}; Value? _$JsonConverterFromJson<Json, Value>( Object? json, Value? Function(Json json) fromJson, -) => - json == null ? null : fromJson(json as Json); +) => json == null ? null : fromJson(json as Json); Json? _$JsonConverterToJson<Json, Value>( Value? value, Json? Function(Value value) toJson, -) => - value == null ? null : toJson(value); +) => value == null ? null : toJson(value); JsonConverterGeneric<S, T, U> _$JsonConverterGenericFromJson<S, T, U>( - Map<String, dynamic> json) => - JsonConverterGeneric<S, T, U>( - GenericConverter<S>().fromJson(json['item'] as Map<String, dynamic>), - (json['itemList'] as List<dynamic>) - .map((e) => GenericConverter<T>().fromJson(e as Map<String, dynamic>)) - .toList(), - (json['itemMap'] as Map<String, dynamic>).map( - (k, e) => MapEntry( - k, GenericConverter<U>().fromJson(e as Map<String, dynamic>)), - ), - ); + Map<String, dynamic> json, +) => JsonConverterGeneric<S, T, U>( + GenericConverter<S>().fromJson(json['item'] as Map<String, dynamic>), + (json['itemList'] as List<dynamic>) + .map((e) => GenericConverter<T>().fromJson(e as Map<String, dynamic>)) + .toList(), + (json['itemMap'] as Map<String, dynamic>).map( + (k, e) => + MapEntry(k, GenericConverter<U>().fromJson(e as Map<String, dynamic>)), + ), +); Map<String, dynamic> _$JsonConverterGenericToJson<S, T, U>( - JsonConverterGeneric<S, T, U> instance) => - <String, dynamic>{ - 'item': GenericConverter<S>().toJson(instance.item), - 'itemList': instance.itemList.map(GenericConverter<T>().toJson).toList(), - 'itemMap': instance.itemMap - .map((k, e) => MapEntry(k, GenericConverter<U>().toJson(e))), - }; + JsonConverterGeneric<S, T, U> instance, +) => <String, dynamic>{ + 'item': GenericConverter<S>().toJson(instance.item), + 'itemList': instance.itemList.map(GenericConverter<T>().toJson).toList(), + 'itemMap': instance.itemMap.map( + (k, e) => MapEntry(k, GenericConverter<U>().toJson(e)), + ), +}; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart b/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart index 57673b70f..e862c9708 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart @@ -125,11 +125,7 @@ abstract class KitchenSink { Map<String, dynamic> toJson(); } -typedef RecordSample = ( - int, - String, { - bool truth, -}); +typedef RecordSample = (int, String, {bool truth}); // TODO: finish this... bool sinkEquals(KitchenSink a, Object other) => diff --git a/json_serializable/test/kitchen_sink/kitchen_sink_test.dart b/json_serializable/test/kitchen_sink/kitchen_sink_test.dart index 3cd0c399f..e3c43efdd 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink_test.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink_test.dart @@ -13,8 +13,11 @@ import 'kitchen_sink_test_shared.dart'; import 'strict_keys_object.dart'; Matcher _isMissingKeyException(String expectedMessage) => - isA<MissingRequiredKeysException>() - .having((e) => e.message, 'message', expectedMessage); + isA<MissingRequiredKeysException>().having( + (e) => e.message, + 'message', + expectedMessage, + ); void main() { test('valid values covers all keys', () { @@ -34,9 +37,13 @@ void main() { test('required keys', () { expect( - () => StrictKeysObject.fromJson({}), - throwsA(_isMissingKeyException( - 'Required keys are missing: value, custom_field.'))); + () => StrictKeysObject.fromJson({}), + throwsA( + _isMissingKeyException( + 'Required keys are missing: value, custom_field.', + ), + ), + ); }); for (var factory in factories) { @@ -163,10 +170,10 @@ void _nullableTests(KitchenSinkFactory factory) { 'items': [ null, [], - [DateTime.now()] - ] - } - } + [DateTime.now()], + ], + }, + }, ]; roundTripSink(item); }); @@ -178,10 +185,10 @@ void _sharedTests(KitchenSinkFactory factory) { final aliasName = factory.fromJson( <String, dynamic>{ - ...validValues, - 'theIterable': validValues['iterable'], - 'STRING': validValues[trickyKeyName] - } + ...validValues, + 'theIterable': validValues['iterable'], + 'STRING': validValues[trickyKeyName], + } ..remove('iterable') ..remove(trickyKeyName), ); @@ -225,27 +232,29 @@ void _sharedTests(KitchenSinkFactory factory) { 'empty': [], 'items': [ [], - [DateTime.now()] - ] - } - } + [DateTime.now()], + ], + }, + }, ]; roundTripObject(item, factory.fromJson); }); test('round trip valid, empty values', () { - final values = Map.fromEntries(validValues.entries.map((e) { - var value = e.value; - if (_iterableMapKeys.contains(e.key)) { - if (value is List) { - value = []; - } else { - assert(value is Map); - value = <String, dynamic>{}; + final values = Map.fromEntries( + validValues.entries.map((e) { + var value = e.value; + if (_iterableMapKeys.contains(e.key)) { + if (value is List) { + value = []; + } else { + assert(value is Map); + value = <String, dynamic>{}; + } } - } - return MapEntry(e.key, value); - })); + return MapEntry(e.key, value); + }), + ); final validInstance = factory.fromJson(values); @@ -290,16 +299,12 @@ const _nonNullableFields = { 'nullableSimpleObjectMap', 'crazyComplex', 'val', - 'simpleObject', - 'strictKeysObject' -}; - -const _encodedAsMapKeys = { 'simpleObject', 'strictKeysObject', - 'recordField', }; +const _encodedAsMapKeys = {'simpleObject', 'strictKeysObject', 'recordField'}; + const _iterableMapKeys = { 'bigIntMap', 'crazyComplex', diff --git a/json_serializable/test/kitchen_sink/kitchen_sink_test_shared.dart b/json_serializable/test/kitchen_sink/kitchen_sink_test_shared.dart index fc235bc05..9ded8bccf 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink_test_shared.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink_test_shared.dart @@ -24,7 +24,7 @@ const validValues = <String, dynamic>{ 'dateTimeList': ['2018-05-10T14:20:58.927'], 'nullableSimpleObjectList': [ {'value': 42}, - null + null, ], 'map': <String, dynamic>{'key': true}, 'stringStringMap': <String, dynamic>{'key': 'vaule'}, @@ -41,11 +41,7 @@ const validValues = <String, dynamic>{ 'simpleObject': {'value': 42}, 'strictKeysObject': {'value': 10, 'custom_field': 'cool'}, 'validatedPropertyNo42': 0, - 'recordField': { - '\$1': 0, - '\$2': 'string', - 'truth': true, - }, + 'recordField': {'\$1': 0, '\$2': 'string', 'truth': true}, }; const invalidValueTypes = { @@ -78,10 +74,7 @@ const invalidValueTypes = { _toJsonMapHelperName: 42, trickyKeyName: true, 'simpleObject': 42, - 'strictKeysObject': { - 'value': 10, - 'invalid_key': true, - }, + 'strictKeysObject': {'value': 10, 'invalid_key': true}, 'validatedPropertyNo42': true, 'recordField': true, }; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink_yaml_test.dart b/json_serializable/test/kitchen_sink/kitchen_sink_yaml_test.dart index 951a90df7..19c7fd3c4 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink_yaml_test.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink_yaml_test.dart @@ -35,22 +35,28 @@ void _anyMapTests(KitchenSinkFactory factory) { }); } -void _testBadValue(String key, Object? badValue, KitchenSinkFactory factory, - bool checkedAssignment) { +void _testBadValue( + String key, + Object? badValue, + KitchenSinkFactory factory, + bool checkedAssignment, +) { final matcher = _getMatcher(factory.checked, key, checkedAssignment); for (final isJson in [true, false]) { - test('`$key` fails with value `$badValue`- ${isJson ? 'json' : 'yaml'}', - () { - var copy = Map<dynamic, dynamic>.of(validValues); - copy[key] = badValue; + test( + '`$key` fails with value `$badValue`- ${isJson ? 'json' : 'yaml'}', + () { + var copy = Map<dynamic, dynamic>.of(validValues); + copy[key] = badValue; - if (!isJson) { - copy = loadYaml(loudEncode(copy)) as YamlMap; - } + if (!isJson) { + copy = loadYaml(loudEncode(copy)) as YamlMap; + } - expect(() => factory.fromJson(copy), matcher); - }); + expect(() => factory.fromJson(copy), matcher); + }, + ); } } @@ -80,7 +86,7 @@ Matcher _getMatcher(bool checked, String? expectedKey, bool checkedAssignment) { 'strictKeysObject' => _isAUnrecognizedKeysException('bob'), 'intIterable' => isTypeError, 'datetime-iterable' => isTypeError, - _ => throw StateError('Not expected! - $expectedKey') + _ => throw StateError('Not expected! - $expectedKey'), }; } } @@ -89,8 +95,11 @@ Matcher _getMatcher(bool checked, String? expectedKey, bool checkedAssignment) { } Matcher _isAUnrecognizedKeysException(String expectedMessage) => - isA<UnrecognizedKeysException>() - .having((e) => e.message, 'message', expectedMessage); + isA<UnrecognizedKeysException>().having( + (e) => e.message, + 'message', + expectedMessage, + ); /// Invalid values that are found after the property set or ctor call const _invalidCheckedValues = { diff --git a/json_serializable/test/kitchen_sink/simple_object.g.dart b/json_serializable/test/kitchen_sink/simple_object.g.dart index 53442bc1b..ebb31411a 100644 --- a/json_serializable/test/kitchen_sink/simple_object.g.dart +++ b/json_serializable/test/kitchen_sink/simple_object.g.dart @@ -8,11 +8,8 @@ part of 'simple_object.dart'; // JsonSerializableGenerator // ************************************************************************** -SimpleObject _$SimpleObjectFromJson(Map json) => SimpleObject( - (json['value'] as num).toInt(), - ); +SimpleObject _$SimpleObjectFromJson(Map json) => + SimpleObject((json['value'] as num).toInt()); Map<String, dynamic> _$SimpleObjectToJson(SimpleObject instance) => - <String, dynamic>{ - 'value': instance.value, - }; + <String, dynamic>{'value': instance.value}; diff --git a/json_serializable/test/literal/json_literal.g.dart b/json_serializable/test/literal/json_literal.g.dart index 9e0993dde..8449ee4c8 100644 --- a/json_serializable/test/literal/json_literal.g.dart +++ b/json_serializable/test/literal/json_literal.g.dart @@ -16,7 +16,7 @@ final _$dataJsonLiteral = [ 'vertical tab': '\v', 'form feed': '\r', 'carriage return': '\r', - 'delete': '\x7F' + 'delete': '\x7F', }, 'simple string', "'string with single quotes'", @@ -47,8 +47,8 @@ final _$dataJsonLiteral = [ 'double': 42.0, 'string': 'string', 'list': [], - 'bool': true - } + 'bool': true, + }, ]; const _$asConstJsonLiteral = [ @@ -59,7 +59,7 @@ const _$asConstJsonLiteral = [ 'vertical tab': '\v', 'form feed': '\r', 'carriage return': '\r', - 'delete': '\x7F' + 'delete': '\x7F', }, 'simple string', "'string with single quotes'", @@ -90,8 +90,8 @@ const _$asConstJsonLiteral = [ 'double': 42.0, 'string': 'string', 'list': [], - 'bool': true - } + 'bool': true, + }, ]; const _$naughtyStringsJsonLiteral = [ @@ -601,5 +601,5 @@ const _$naughtyStringsJsonLiteral = [ 'Roses are \x1B[0;31mred\x1B[0m, violets are \x1B[0;34mblue. Hope you enjoy terminal hue', 'But now...\x1B[20Cfor my greatest trick...\x1B[8m', 'The quic\b\b\b\b\b\bk brown fo\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07x... [Beeeep]', - 'Powerلُلُصّبُلُلصّبُررً ॣ ॣh ॣ ॣ冗' + 'Powerلُلُصّبُلُلصّبُررً ॣ ॣh ॣ ॣ冗', ]; diff --git a/json_serializable/test/literal/json_literal_test.dart b/json_serializable/test/literal/json_literal_test.dart index a3f66f836..afc2d18b8 100644 --- a/json_serializable/test/literal/json_literal_test.dart +++ b/json_serializable/test/literal/json_literal_test.dart @@ -29,8 +29,11 @@ void main() { }); test('naughty strings', () { - final dataFilePath = - p.join('test', 'literal', 'big-list-of-naughty-strings.json'); + final dataFilePath = p.join( + 'test', + 'literal', + 'big-list-of-naughty-strings.json', + ); final dataFile = File(dataFilePath); final dataString = loudEncode(json.decode(dataFile.readAsStringSync())); diff --git a/json_serializable/test/shared_config.dart b/json_serializable/test/shared_config.dart index fcae4282e..510250175 100644 --- a/json_serializable/test/shared_config.dart +++ b/json_serializable/test/shared_config.dart @@ -12,20 +12,21 @@ final generatorConfigDefaultJson = Map<String, dynamic>.unmodifiable( ); // #CHANGE WHEN UPDATING json_annotation -final generatorConfigNonDefaultJson = - Map<String, dynamic>.unmodifiable(const JsonSerializable( - anyMap: true, - checked: true, - constructor: 'something', - createFactory: false, - createToJson: false, - createFieldMap: true, - createJsonKeys: true, - createPerFieldToJson: true, - disallowUnrecognizedKeys: true, - explicitToJson: true, - fieldRename: FieldRename.kebab, - ignoreUnannotated: true, - includeIfNull: false, - genericArgumentFactories: true, -).toJson()); +final generatorConfigNonDefaultJson = Map<String, dynamic>.unmodifiable( + const JsonSerializable( + anyMap: true, + checked: true, + constructor: 'something', + createFactory: false, + createToJson: false, + createFieldMap: true, + createJsonKeys: true, + createPerFieldToJson: true, + disallowUnrecognizedKeys: true, + explicitToJson: true, + fieldRename: FieldRename.kebab, + ignoreUnannotated: true, + includeIfNull: false, + genericArgumentFactories: true, + ).toJson(), +); diff --git a/json_serializable/test/src/_json_serializable_test_input.dart b/json_serializable/test/src/_json_serializable_test_input.dart index bdd061d00..c7fbd5088 100644 --- a/json_serializable/test/src/_json_serializable_test_input.dart +++ b/json_serializable/test/src/_json_serializable_test_input.dart @@ -2,7 +2,7 @@ // 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. -// @dart=3.6 +// @dart=3.8 import 'dart:collection'; @@ -34,15 +34,13 @@ enum UnsupportedEnum { not, valid } @JsonSerializable() // ignore: invalid_annotation_target Object annotatedMethod() => throw UnimplementedError(); -@ShouldGenerate( - r''' +@ShouldGenerate(r''' OnlyStaticMembers _$OnlyStaticMembersFromJson(Map<String, dynamic> json) => OnlyStaticMembers(); Map<String, dynamic> _$OnlyStaticMembersToJson(OnlyStaticMembers instance) => <String, dynamic>{}; -''', -) +''') @JsonSerializable() class OnlyStaticMembers { // To ensure static members are not considered for serialization. @@ -113,20 +111,16 @@ class GeneralTestClass2 { late DateTime dateOfBirth; GeneralTestClass2(this.height, String firstName, [this.lastName]) - : - // ignore: prefer_initializing_formals - firstName = firstName; + // ignore: prefer_initializing_formals + : firstName = firstName; } @ShouldGenerate(r''' -FinalFields _$FinalFieldsFromJson(Map<String, dynamic> json) => FinalFields( - (json['a'] as num).toInt(), - ); +FinalFields _$FinalFieldsFromJson(Map<String, dynamic> json) => + FinalFields((json['a'] as num).toInt()); Map<String, dynamic> _$FinalFieldsToJson(FinalFields instance) => - <String, dynamic>{ - 'a': instance.a, - }; + <String, dynamic>{'a': instance.a}; ''') @JsonSerializable() class FinalFields { @@ -137,17 +131,15 @@ class FinalFields { FinalFields(this.a); } -@ShouldGenerate( - r''' +@ShouldGenerate(r''' FinalFieldsNotSetInCtor _$FinalFieldsNotSetInCtorFromJson( - Map<String, dynamic> json) => - FinalFieldsNotSetInCtor(); + Map<String, dynamic> json, +) => FinalFieldsNotSetInCtor(); Map<String, dynamic> _$FinalFieldsNotSetInCtorToJson( - FinalFieldsNotSetInCtor instance) => - <String, dynamic>{}; -''', -) + FinalFieldsNotSetInCtor instance, +) => <String, dynamic>{}; +''') @JsonSerializable() class FinalFieldsNotSetInCtor { final int a = 1; @@ -157,13 +149,11 @@ class FinalFieldsNotSetInCtor { @ShouldGenerate(r''' SetSupport _$SetSupportFromJson(Map<String, dynamic> json) => SetSupport( - (json['values'] as List<dynamic>).map((e) => (e as num).toInt()).toSet(), - ); + (json['values'] as List<dynamic>).map((e) => (e as num).toInt()).toSet(), +); Map<String, dynamic> _$SetSupportToJson(SetSupport instance) => - <String, dynamic>{ - 'values': instance.values.toList(), - }; + <String, dynamic>{'values': instance.values.toList()}; ''') @JsonSerializable() class SetSupport { @@ -172,58 +162,48 @@ class SetSupport { SetSupport(this.values); } -@ShouldThrow( - ''' +@ShouldThrow(''' Could not generate `toJson` code for `watch`. To support the type `Stopwatch` you can: -$converterOrKeyInstructions''', -) +$converterOrKeyInstructions''') @JsonSerializable(createFactory: false) class NoSerializeFieldType { Stopwatch? watch; } -@ShouldThrow( - ''' +@ShouldThrow(''' Could not generate `fromJson` code for `watch`. To support the type `Stopwatch` you can: -$converterOrKeyInstructions''', -) +$converterOrKeyInstructions''') @JsonSerializable(createToJson: false) class NoDeserializeFieldType { Stopwatch? watch; } -@ShouldThrow( - ''' +@ShouldThrow(''' Could not generate `toJson` code for `durationDateTimeMap` because of type `Duration`. -Map keys must be one of: Object, dynamic, enum, String, BigInt, DateTime, int, Uri.''', -) +Map keys must be one of: Object, dynamic, enum, String, BigInt, DateTime, int, Uri.''') @JsonSerializable(createFactory: false) class NoSerializeBadKey { late Map<Duration, DateTime> durationDateTimeMap; } -@ShouldThrow( - ''' +@ShouldThrow(''' Could not generate `fromJson` code for `durationDateTimeMap` because of type `Duration`. -Map keys must be one of: Object, dynamic, enum, String, BigInt, DateTime, int, Uri.''', -) +Map keys must be one of: Object, dynamic, enum, String, BigInt, DateTime, int, Uri.''') @JsonSerializable(createToJson: false) class NoDeserializeBadKey { late Map<Duration, DateTime> durationDateTimeMap; } -@ShouldGenerate( - r''' +@ShouldGenerate(r''' Map<String, dynamic> _$IncludeIfNullOverrideToJson( - IncludeIfNullOverride instance) => - <String, dynamic>{ - 'number': instance.number, - if (instance.str case final value?) 'str': value, - }; -''', -) + IncludeIfNullOverride instance, +) => <String, dynamic>{ + 'number': instance.number, + if (instance.str case final value?) 'str': value, +}; +''') @JsonSerializable(createFactory: false, includeIfNull: false) class IncludeIfNullOverride { @JsonKey(includeIfNull: true) @@ -232,9 +212,7 @@ class IncludeIfNullOverride { } // https://github.com/google/json_serializable.dart/issues/7 regression -@ShouldThrow( - 'The class `NoCtorClass` has no default constructor.', -) +@ShouldThrow('The class `NoCtorClass` has no default constructor.') @JsonSerializable() class NoCtorClass { late final int member; @@ -373,7 +351,7 @@ class JsonValueWithBool { enum BadEnum { @JsonValue(true) - value + value, } @ShouldGenerate(r'''const _$GoodEnumEnumMap = { @@ -398,19 +376,20 @@ enum GoodEnum { @JsonValue(42) intValue, @JsonValue(null) - nullValue + nullValue, } @ShouldGenerate(r''' FieldWithFromJsonCtorAndTypeParams _$FieldWithFromJsonCtorAndTypeParamsFromJson( - Map<String, dynamic> json) => - FieldWithFromJsonCtorAndTypeParams() - ..customOrders = json['customOrders'] == null - ? null - : MyList<GeneralTestClass2, int>.fromJson((json['customOrders'] - as List<dynamic>) + Map<String, dynamic> json, +) => FieldWithFromJsonCtorAndTypeParams() + ..customOrders = json['customOrders'] == null + ? null + : MyList<GeneralTestClass2, int>.fromJson( + (json['customOrders'] as List<dynamic>) .map((e) => GeneralTestClass2.fromJson(e as Map<String, dynamic>)) - .toList()); + .toList(), + ); ''') @JsonSerializable(createToJson: false) class FieldWithFromJsonCtorAndTypeParams { @@ -447,17 +426,17 @@ mixin _PropInMixinI448RegressionMixin { @ShouldGenerate(r''' PropInMixinI448Regression _$PropInMixinI448RegressionFromJson( - Map<String, dynamic> json) => - PropInMixinI448Regression() - ..nullable = (json['nullable'] as num).toInt() - ..notNullable = (json['notNullable'] as num).toInt(); + Map<String, dynamic> json, +) => PropInMixinI448Regression() + ..nullable = (json['nullable'] as num).toInt() + ..notNullable = (json['notNullable'] as num).toInt(); Map<String, dynamic> _$PropInMixinI448RegressionToJson( - PropInMixinI448Regression instance) => - <String, dynamic>{ - 'nullable': instance.nullable, - 'notNullable': instance.notNullable, - }; + PropInMixinI448Regression instance, +) => <String, dynamic>{ + 'nullable': instance.nullable, + 'notNullable': instance.notNullable, +}; ''') @JsonSerializable() class PropInMixinI448Regression with _PropInMixinI448RegressionMixin { @@ -465,17 +444,13 @@ class PropInMixinI448Regression with _PropInMixinI448RegressionMixin { late int notNullable; } -@ShouldGenerate( - r''' +@ShouldGenerate(r''' IgnoreUnannotated _$IgnoreUnannotatedFromJson(Map<String, dynamic> json) => IgnoreUnannotated()..annotated = (json['annotated'] as num).toInt(); Map<String, dynamic> _$IgnoreUnannotatedToJson(IgnoreUnannotated instance) => - <String, dynamic>{ - 'annotated': instance.annotated, - }; -''', -) + <String, dynamic>{'annotated': instance.annotated}; +''') @JsonSerializable(ignoreUnannotated: true) class IgnoreUnannotated { @JsonKey() @@ -484,17 +459,13 @@ class IgnoreUnannotated { late int unannotated; } -@ShouldGenerate( - r''' +@ShouldGenerate(r''' SubclassedJsonKey _$SubclassedJsonKeyFromJson(Map<String, dynamic> json) => SubclassedJsonKey()..annotatedWithSubclass = (json['bob'] as num).toInt(); Map<String, dynamic> _$SubclassedJsonKeyToJson(SubclassedJsonKey instance) => - <String, dynamic>{ - 'bob': instance.annotatedWithSubclass, - }; -''', -) + <String, dynamic>{'bob': instance.annotatedWithSubclass}; +''') @JsonSerializable(ignoreUnannotated: true) class SubclassedJsonKey { @MyJsonKey() @@ -505,19 +476,15 @@ class MyJsonKey extends JsonKey { const MyJsonKey() : super(name: 'bob'); } -@ShouldGenerate( - r''' +@ShouldGenerate(r''' OverrideGetterExampleI613 _$OverrideGetterExampleI613FromJson( - Map<String, dynamic> json) => - OverrideGetterExampleI613()..id = json['id'] as String; + Map<String, dynamic> json, +) => OverrideGetterExampleI613()..id = json['id'] as String; Map<String, dynamic> _$OverrideGetterExampleI613ToJson( - OverrideGetterExampleI613 instance) => - <String, dynamic>{ - 'id': instance.id, - }; -''', -) + OverrideGetterExampleI613 instance, +) => <String, dynamic>{'id': instance.id}; +''') @JsonSerializable() class OverrideGetterExampleI613 extends OverrideGetterExampleI613Super { @override @@ -584,11 +551,8 @@ class ExtraParamToJson { @ShouldGenerate(r''' Map<String, dynamic> _$Issue1038RegressionTestToJson( - Issue1038RegressionTest instance) => - <String, dynamic>{ - 'id': instance.id, - 'ean': instance.ean, - }; + Issue1038RegressionTest instance, +) => <String, dynamic>{'id': instance.id, 'ean': instance.ean}; ''') @JsonSerializable(createFactory: false) class Issue1038RegressionTest { @@ -600,16 +564,14 @@ class Issue1038RegressionTest { Issue1038RegressionTest.ean(this.ean) : id = null; } -@ShouldGenerate( - r''' +@ShouldGenerate(r''' TearOffFromJsonClass _$TearOffFromJsonClassFromJson( - Map<String, dynamic> json) => - TearOffFromJsonClass( - TearOffValueClass(json['value'] as String), - TearOffValueClass.fromJson(json['factoryValue'] as String), - ); -''', -) + Map<String, dynamic> json, +) => TearOffFromJsonClass( + TearOffValueClass(json['value'] as String), + TearOffValueClass.fromJson(json['factoryValue'] as String), +); +''') @JsonSerializable(createToJson: false) class TearOffFromJsonClass { TearOffFromJsonClass(this.value, this.factoryValue); diff --git a/json_serializable/test/src/checked_test_input.dart b/json_serializable/test/src/checked_test_input.dart index 167b7039f..f37360139 100644 --- a/json_serializable/test/src/checked_test_input.dart +++ b/json_serializable/test/src/checked_test_input.dart @@ -1,27 +1,25 @@ -// @dart=3.6 +// @dart=3.8 part of '_json_serializable_test_input.dart'; @ShouldGenerate(r''' WithANonCtorGetterChecked _$WithANonCtorGetterCheckedFromJson( - Map<String, dynamic> json) => - $checkedCreate( - 'WithANonCtorGetterChecked', - json, - ($checkedConvert) { - $checkKeys( - json, - allowedKeys: const ['items'], - requiredKeys: const ['items'], - disallowNullValues: const ['items'], - ); - final val = WithANonCtorGetterChecked( - $checkedConvert('items', - (v) => (v as List<dynamic>).map((e) => e as String).toList()), - ); - return val; - }, - ); + Map<String, dynamic> json, +) => $checkedCreate('WithANonCtorGetterChecked', json, ($checkedConvert) { + $checkKeys( + json, + allowedKeys: const ['items'], + requiredKeys: const ['items'], + disallowNullValues: const ['items'], + ); + final val = WithANonCtorGetterChecked( + $checkedConvert( + 'items', + (v) => (v as List<dynamic>).map((e) => e as String).toList(), + ), + ); + return val; +}); ''') @JsonSerializable( disallowUnrecognizedKeys: true, diff --git a/json_serializable/test/src/constants_copy.dart b/json_serializable/test/src/constants_copy.dart index fa1c485bb..3229cbaba 100644 --- a/json_serializable/test/src/constants_copy.dart +++ b/json_serializable/test/src/constants_copy.dart @@ -2,7 +2,7 @@ // 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. -// @dart=3.6 +// @dart=3.8 part of '_json_serializable_test_input.dart'; diff --git a/json_serializable/test/src/core_subclass_type_input.dart b/json_serializable/test/src/core_subclass_type_input.dart index b764b9fe8..1d45aca3d 100644 --- a/json_serializable/test/src/core_subclass_type_input.dart +++ b/json_serializable/test/src/core_subclass_type_input.dart @@ -1,38 +1,29 @@ -// @dart=3.6 +// @dart=3.8 part of '_json_serializable_test_input.dart'; -@ShouldThrow( - ''' +@ShouldThrow(''' Could not generate `fromJson` code for `mapView`. To support the type `MapView` you can: -$converterOrKeyInstructions''', - element: 'mapView', -) +$converterOrKeyInstructions''', element: 'mapView') @JsonSerializable(createToJson: false) class UnsupportedMapField { late MapView mapView; } -@ShouldThrow( - ''' +@ShouldThrow(''' Could not generate `fromJson` code for `listView`. To support the type `UnmodifiableListView` you can: -$converterOrKeyInstructions''', - element: 'listView', -) +$converterOrKeyInstructions''', element: 'listView') @JsonSerializable(createToJson: false) class UnsupportedListField { late UnmodifiableListView listView; } -@ShouldThrow( - ''' +@ShouldThrow(''' Could not generate `fromJson` code for `customSet`. To support the type `CustomSet` you can: -$converterOrKeyInstructions''', - element: 'customSet', -) +$converterOrKeyInstructions''', element: 'customSet') @JsonSerializable(createToJson: false) class UnsupportedSetField { late CustomSet customSet; @@ -40,13 +31,10 @@ class UnsupportedSetField { abstract class CustomSet implements Set {} -@ShouldThrow( - ''' +@ShouldThrow(''' Could not generate `fromJson` code for `customDuration`. To support the type `CustomDuration` you can: -$converterOrKeyInstructions''', - element: 'customDuration', -) +$converterOrKeyInstructions''', element: 'customDuration') @JsonSerializable(createToJson: false) class UnsupportedDurationField { late CustomDuration customDuration; @@ -54,13 +42,10 @@ class UnsupportedDurationField { abstract class CustomDuration implements Duration {} -@ShouldThrow( - ''' +@ShouldThrow(''' Could not generate `fromJson` code for `customUri`. To support the type `CustomUri` you can: -$converterOrKeyInstructions''', - element: 'customUri', -) +$converterOrKeyInstructions''', element: 'customUri') @JsonSerializable(createToJson: false) class UnsupportedUriField { CustomUri? customUri; @@ -68,13 +53,10 @@ class UnsupportedUriField { abstract class CustomUri implements Uri {} -@ShouldThrow( - ''' +@ShouldThrow(''' Could not generate `fromJson` code for `customDateTime`. To support the type `CustomDateTime` you can: -$converterOrKeyInstructions''', - element: 'customDateTime', -) +$converterOrKeyInstructions''', element: 'customDateTime') @JsonSerializable(createToJson: false) class UnsupportedDateTimeField { late CustomDateTime customDateTime; diff --git a/json_serializable/test/src/default_value_input.dart b/json_serializable/test/src/default_value_input.dart index 6636f085f..aa9ac4f0b 100644 --- a/json_serializable/test/src/default_value_input.dart +++ b/json_serializable/test/src/default_value_input.dart @@ -2,7 +2,7 @@ // 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. -// @dart=3.6 +// @dart=3.8 part of '_json_serializable_test_input.dart'; @@ -21,18 +21,14 @@ class DefaultWithSymbol { int _function() => 42; -@ShouldGenerate( - r''' +@ShouldGenerate(r''' DefaultWithFunction _$DefaultWithFunctionFromJson(Map<String, dynamic> json) => DefaultWithFunction()..field = json['field'] ?? _function(); Map<String, dynamic> _$DefaultWithFunctionToJson( - DefaultWithFunction instance) => - <String, dynamic>{ - 'field': instance.field, - }; -''', -) + DefaultWithFunction instance, +) => <String, dynamic>{'field': instance.field}; +''') @JsonSerializable() class DefaultWithFunction { @JsonKey(defaultValue: _function) @@ -108,17 +104,16 @@ class BadEnumDefaultValue { BadEnumDefaultValue(); } -@ShouldGenerate( - r''' +@ShouldGenerate(r''' DefaultWithToJsonClass _$DefaultWithToJsonClassFromJson( - Map<String, dynamic> json) => - DefaultWithToJsonClass() - ..fieldDefaultValueToJson = json['fieldDefaultValueToJson'] == null - ? 7 - : DefaultWithToJsonClass._fromJson( - json['fieldDefaultValueToJson'] as String); -''', -) + Map<String, dynamic> json, +) => DefaultWithToJsonClass() + ..fieldDefaultValueToJson = json['fieldDefaultValueToJson'] == null + ? 7 + : DefaultWithToJsonClass._fromJson( + json['fieldDefaultValueToJson'] as String, + ); +''') @JsonSerializable(createToJson: false) class DefaultWithToJsonClass { @JsonKey(defaultValue: 7, fromJson: _fromJson) @@ -132,7 +127,7 @@ class DefaultWithToJsonClass { @ShouldGenerate( r''' DefaultWithDisallowNullRequiredClass - _$DefaultWithDisallowNullRequiredClassFromJson(Map<String, dynamic> json) { +_$DefaultWithDisallowNullRequiredClassFromJson(Map<String, dynamic> json) { $checkKeys( json, requiredKeys: const ['theField'], @@ -158,11 +153,10 @@ class DefaultWithDisallowNullRequiredClass { @ShouldGenerate( r''' CtorDefaultValueAndJsonKeyDefaultValue - _$CtorDefaultValueAndJsonKeyDefaultValueFromJson( - Map<String, dynamic> json) => - CtorDefaultValueAndJsonKeyDefaultValue( - (json['theField'] as num?)?.toInt() ?? 7, - ); +_$CtorDefaultValueAndJsonKeyDefaultValueFromJson(Map<String, dynamic> json) => + CtorDefaultValueAndJsonKeyDefaultValue( + (json['theField'] as num?)?.toInt() ?? 7, + ); ''', expectedLogItems: [ 'The constructor parameter for `theField` has a default value `6`, but the ' @@ -181,10 +175,8 @@ class CtorDefaultValueAndJsonKeyDefaultValue { @ShouldGenerate( r''' SameCtorAndJsonKeyDefaultValue _$SameCtorAndJsonKeyDefaultValueFromJson( - Map<String, dynamic> json) => - SameCtorAndJsonKeyDefaultValue( - (json['theField'] as num?)?.toInt() ?? 3, - ); + Map<String, dynamic> json, +) => SameCtorAndJsonKeyDefaultValue((json['theField'] as num?)?.toInt() ?? 3); ''', expectedLogItems: [ 'The default value `3` for `theField` is defined twice ' @@ -201,18 +193,18 @@ class SameCtorAndJsonKeyDefaultValue { @ShouldGenerate(r''' DefaultDoubleConstants _$DefaultDoubleConstantsFromJson( - Map<String, dynamic> json) => - DefaultDoubleConstants() - ..defaultNan = (json['defaultNan'] as num?)?.toDouble() ?? double.nan - ..defaultNegativeInfinity = - (json['defaultNegativeInfinity'] as num?)?.toDouble() ?? - double.negativeInfinity - ..defaultInfinity = - (json['defaultInfinity'] as num?)?.toDouble() ?? double.infinity - ..defaultMinPositive = - (json['defaultMinPositive'] as num?)?.toDouble() ?? 5e-324 - ..defaultMaxFinite = (json['defaultMaxFinite'] as num?)?.toDouble() ?? - 1.7976931348623157e+308; + Map<String, dynamic> json, +) => DefaultDoubleConstants() + ..defaultNan = (json['defaultNan'] as num?)?.toDouble() ?? double.nan + ..defaultNegativeInfinity = + (json['defaultNegativeInfinity'] as num?)?.toDouble() ?? + double.negativeInfinity + ..defaultInfinity = + (json['defaultInfinity'] as num?)?.toDouble() ?? double.infinity + ..defaultMinPositive = + (json['defaultMinPositive'] as num?)?.toDouble() ?? 5e-324 + ..defaultMaxFinite = + (json['defaultMaxFinite'] as num?)?.toDouble() ?? 1.7976931348623157e+308; ''') @JsonSerializable(createToJson: false) class DefaultDoubleConstants { diff --git a/json_serializable/test/src/field_namer_input.dart b/json_serializable/test/src/field_namer_input.dart index ac9e1363c..6541857e5 100644 --- a/json_serializable/test/src/field_namer_input.dart +++ b/json_serializable/test/src/field_namer_input.dart @@ -1,4 +1,4 @@ -// @dart=3.6 +// @dart=3.8 part of '_json_serializable_test_input.dart'; @@ -64,11 +64,11 @@ class FieldNamerSnake { @ShouldGenerate(r''' Map<String, dynamic> _$FieldNamerScreamingSnakeToJson( - FieldNamerScreamingSnake instance) => - <String, dynamic>{ - 'THE_FIELD': instance.theField, - 'nameOverride': instance.nameOverride, - }; + FieldNamerScreamingSnake instance, +) => <String, dynamic>{ + 'THE_FIELD': instance.theField, + 'nameOverride': instance.nameOverride, +}; ''') @JsonSerializable(fieldRename: FieldRename.screamingSnake, createFactory: false) class FieldNamerScreamingSnake { diff --git a/json_serializable/test/src/generic_test_input.dart b/json_serializable/test/src/generic_test_input.dart index f7b4ec45e..810c5a674 100644 --- a/json_serializable/test/src/generic_test_input.dart +++ b/json_serializable/test/src/generic_test_input.dart @@ -2,7 +2,7 @@ // 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. -// @dart=3.6 +// @dart=3.8 part of '_json_serializable_test_input.dart'; @@ -22,23 +22,23 @@ class Issue713<TResult> { @ShouldGenerate(r''' GenericClass<T, S> _$GenericClassFromJson<T extends num, S>( - Map<String, dynamic> json) => - GenericClass<T, S>() - ..fieldObject = _dataFromJson(json['fieldObject']) - ..fieldDynamic = _dataFromJson(json['fieldDynamic']) - ..fieldInt = _dataFromJson(json['fieldInt']) - ..fieldT = _dataFromJson(json['fieldT']) - ..fieldS = _dataFromJson(json['fieldS']); + Map<String, dynamic> json, +) => GenericClass<T, S>() + ..fieldObject = _dataFromJson(json['fieldObject']) + ..fieldDynamic = _dataFromJson(json['fieldDynamic']) + ..fieldInt = _dataFromJson(json['fieldInt']) + ..fieldT = _dataFromJson(json['fieldT']) + ..fieldS = _dataFromJson(json['fieldS']); Map<String, dynamic> _$GenericClassToJson<T extends num, S>( - GenericClass<T, S> instance) => - <String, dynamic>{ - 'fieldObject': _dataToJson(instance.fieldObject), - 'fieldDynamic': _dataToJson(instance.fieldDynamic), - 'fieldInt': _dataToJson(instance.fieldInt), - 'fieldT': _dataToJson(instance.fieldT), - 'fieldS': _dataToJson(instance.fieldS), - }; + GenericClass<T, S> instance, +) => <String, dynamic>{ + 'fieldObject': _dataToJson(instance.fieldObject), + 'fieldDynamic': _dataToJson(instance.fieldDynamic), + 'fieldInt': _dataToJson(instance.fieldInt), + 'fieldT': _dataToJson(instance.fieldT), + 'fieldS': _dataToJson(instance.fieldS), +}; ''') @JsonSerializable() class GenericClass<T extends num, S> { @@ -67,13 +67,13 @@ Object _dataToJson<T extends num>(T input) => throw UnimplementedError(); @ShouldGenerate( r''' GenericArgumentFactoriesFlagWithoutGenericType - _$GenericArgumentFactoriesFlagWithoutGenericTypeFromJson( - Map<String, dynamic> json) => - GenericArgumentFactoriesFlagWithoutGenericType(); +_$GenericArgumentFactoriesFlagWithoutGenericTypeFromJson( + Map<String, dynamic> json, +) => GenericArgumentFactoriesFlagWithoutGenericType(); Map<String, dynamic> _$GenericArgumentFactoriesFlagWithoutGenericTypeToJson( - GenericArgumentFactoriesFlagWithoutGenericType instance) => - <String, dynamic>{}; + GenericArgumentFactoriesFlagWithoutGenericType instance, +) => <String, dynamic>{}; ''', expectedLogItems: [ 'The class `GenericArgumentFactoriesFlagWithoutGenericType` is annotated ' diff --git a/json_serializable/test/src/inheritance_test_input.dart b/json_serializable/test/src/inheritance_test_input.dart index 86c43c420..76caaed23 100644 --- a/json_serializable/test/src/inheritance_test_input.dart +++ b/json_serializable/test/src/inheritance_test_input.dart @@ -1,22 +1,23 @@ -// @dart=3.6 +// @dart=3.8 part of '_json_serializable_test_input.dart'; @ShouldGenerate(r''' -SubType _$SubTypeFromJson(Map<String, dynamic> json) => SubType( - (json['subTypeViaCtor'] as num).toInt(), - (json['super-final-field'] as num).toInt(), - ) +SubType _$SubTypeFromJson(Map<String, dynamic> json) => + SubType( + (json['subTypeViaCtor'] as num).toInt(), + (json['super-final-field'] as num).toInt(), + ) ..superReadWriteField = (json['superReadWriteField'] as num?)?.toInt() ..subTypeReadWrite = (json['subTypeReadWrite'] as num).toInt(); Map<String, dynamic> _$SubTypeToJson(SubType instance) => <String, dynamic>{ - 'super-final-field': instance.superFinalField, - if (instance.superReadWriteField case final value?) - 'superReadWriteField': value, - 'subTypeViaCtor': instance.subTypeViaCtor, - 'subTypeReadWrite': instance.subTypeReadWrite, - }; + 'super-final-field': instance.superFinalField, + if (instance.superReadWriteField case final value?) + 'superReadWriteField': value, + 'subTypeViaCtor': instance.subTypeViaCtor, + 'subTypeReadWrite': instance.subTypeReadWrite, +}; ''') @JsonSerializable() class SubType extends SuperType { @@ -47,13 +48,13 @@ class SuperType { @ShouldGenerate(r''' Map<String, dynamic> _$SubTypeWithAnnotatedFieldOverrideExtendsToJson( - SubTypeWithAnnotatedFieldOverrideExtends instance) => - <String, dynamic>{ - 'super-final-field': instance.superFinalField, - if (instance.superReadWriteField case final value?) - 'superReadWriteField': value, - 'priceHalf': instance.priceHalf, - }; + SubTypeWithAnnotatedFieldOverrideExtends instance, +) => <String, dynamic>{ + 'super-final-field': instance.superFinalField, + if (instance.superReadWriteField case final value?) + 'superReadWriteField': value, + 'priceHalf': instance.priceHalf, +}; ''') @JsonSerializable(createFactory: false) class SubTypeWithAnnotatedFieldOverrideExtends extends SuperType { @@ -62,18 +63,19 @@ class SubTypeWithAnnotatedFieldOverrideExtends extends SuperType { @ShouldGenerate(r''' Map<String, dynamic> - _$SubTypeWithAnnotatedFieldOverrideExtendsWithOverridesToJson( - SubTypeWithAnnotatedFieldOverrideExtendsWithOverrides instance) => - <String, dynamic>{ - 'priceHalf': instance.priceHalf, - 'superReadWriteField': instance.superReadWriteField, - 'super-final-field': instance.superFinalField, - }; +_$SubTypeWithAnnotatedFieldOverrideExtendsWithOverridesToJson( + SubTypeWithAnnotatedFieldOverrideExtendsWithOverrides instance, +) => <String, dynamic>{ + 'priceHalf': instance.priceHalf, + 'superReadWriteField': instance.superReadWriteField, + 'super-final-field': instance.superFinalField, +}; ''') @JsonSerializable(createFactory: false) class SubTypeWithAnnotatedFieldOverrideExtendsWithOverrides extends SuperType { SubTypeWithAnnotatedFieldOverrideExtendsWithOverrides( - int super.superTypeViaCtor); + int super.superTypeViaCtor, + ); /// The annotation applied here overrides the annotation in [SuperType]. @JsonKey(includeIfNull: true) @@ -93,11 +95,11 @@ class SubTypeWithAnnotatedFieldOverrideExtendsWithOverrides extends SuperType { @ShouldGenerate(r''' Map<String, dynamic> _$SubTypeWithAnnotatedFieldOverrideImplementsToJson( - SubTypeWithAnnotatedFieldOverrideImplements instance) => - <String, dynamic>{ - 'superReadWriteField': instance.superReadWriteField, - 'superFinalField': instance.superFinalField, - }; + SubTypeWithAnnotatedFieldOverrideImplements instance, +) => <String, dynamic>{ + 'superReadWriteField': instance.superReadWriteField, + 'superFinalField': instance.superFinalField, +}; ''') @JsonSerializable(createFactory: false) class SubTypeWithAnnotatedFieldOverrideImplements implements SuperType { diff --git a/json_serializable/test/src/json_converter_test_input.dart b/json_serializable/test/src/json_converter_test_input.dart index 6e40125fe..c06cc3fd2 100644 --- a/json_serializable/test/src/json_converter_test_input.dart +++ b/json_serializable/test/src/json_converter_test_input.dart @@ -2,7 +2,7 @@ // 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. -// @dart=3.6 +// @dart=3.8 // ignore_for_file: inference_failure_on_instance_creation @@ -10,25 +10,27 @@ part of '_json_serializable_test_input.dart'; @ShouldGenerate(r''' JsonConverterNamedCtor<E> _$JsonConverterNamedCtorFromJson<E>( - Map<String, dynamic> json) => - JsonConverterNamedCtor<E>() - ..value = const _DurationMillisecondConverter.named() - .fromJson((json['value'] as num).toInt()) - ..genericValue = _GenericConverter<E>.named() - .fromJson((json['genericValue'] as num).toInt()) - ..keyAnnotationFirst = JsonConverterNamedCtor._fromJson( - (json['keyAnnotationFirst'] as num).toInt()); + Map<String, dynamic> json, +) => JsonConverterNamedCtor<E>() + ..value = const _DurationMillisecondConverter.named().fromJson( + (json['value'] as num).toInt(), + ) + ..genericValue = _GenericConverter<E>.named().fromJson( + (json['genericValue'] as num).toInt(), + ) + ..keyAnnotationFirst = JsonConverterNamedCtor._fromJson( + (json['keyAnnotationFirst'] as num).toInt(), + ); Map<String, dynamic> _$JsonConverterNamedCtorToJson<E>( - JsonConverterNamedCtor<E> instance) => - <String, dynamic>{ - 'value': - const _DurationMillisecondConverter.named().toJson(instance.value), - 'genericValue': - _GenericConverter<E>.named().toJson(instance.genericValue), - 'keyAnnotationFirst': - JsonConverterNamedCtor._toJson(instance.keyAnnotationFirst), - }; + JsonConverterNamedCtor<E> instance, +) => <String, dynamic>{ + 'value': const _DurationMillisecondConverter.named().toJson(instance.value), + 'genericValue': _GenericConverter<E>.named().toJson(instance.genericValue), + 'keyAnnotationFirst': JsonConverterNamedCtor._toJson( + instance.keyAnnotationFirst, + ), +}; ''') @JsonSerializable() @_DurationMillisecondConverter.named() @@ -48,28 +50,34 @@ class JsonConverterNamedCtor<E> { @ShouldGenerate(r''' JsonConvertOnField<E> _$JsonConvertOnFieldFromJson<E>( - Map<String, dynamic> json) => - JsonConvertOnField<E>() - ..annotatedField = const _DurationMillisecondConverter() - .fromJson((json['annotatedField'] as num).toInt()) - ..annotatedWithNamedCtor = const _DurationMillisecondConverter.named() - .fromJson((json['annotatedWithNamedCtor'] as num).toInt()) - ..classAnnotatedWithField = _durationConverter - .fromJson((json['classAnnotatedWithField'] as num).toInt()) - ..genericValue = _GenericConverter<E>() - .fromJson((json['genericValue'] as num).toInt()); + Map<String, dynamic> json, +) => JsonConvertOnField<E>() + ..annotatedField = const _DurationMillisecondConverter().fromJson( + (json['annotatedField'] as num).toInt(), + ) + ..annotatedWithNamedCtor = const _DurationMillisecondConverter.named() + .fromJson((json['annotatedWithNamedCtor'] as num).toInt()) + ..classAnnotatedWithField = _durationConverter.fromJson( + (json['classAnnotatedWithField'] as num).toInt(), + ) + ..genericValue = _GenericConverter<E>().fromJson( + (json['genericValue'] as num).toInt(), + ); Map<String, dynamic> _$JsonConvertOnFieldToJson<E>( - JsonConvertOnField<E> instance) => - <String, dynamic>{ - 'annotatedField': - const _DurationMillisecondConverter().toJson(instance.annotatedField), - 'annotatedWithNamedCtor': const _DurationMillisecondConverter.named() - .toJson(instance.annotatedWithNamedCtor), - 'classAnnotatedWithField': - _durationConverter.toJson(instance.classAnnotatedWithField), - 'genericValue': _GenericConverter<E>().toJson(instance.genericValue), - }; + JsonConvertOnField<E> instance, +) => <String, dynamic>{ + 'annotatedField': const _DurationMillisecondConverter().toJson( + instance.annotatedField, + ), + 'annotatedWithNamedCtor': const _DurationMillisecondConverter.named().toJson( + instance.annotatedWithNamedCtor, + ), + 'classAnnotatedWithField': _durationConverter.toJson( + instance.classAnnotatedWithField, + ), + 'genericValue': _GenericConverter<E>().toJson(instance.genericValue), +}; ''') @JsonSerializable() @_durationConverter @@ -168,11 +176,12 @@ class _ConverterWithCtorParams implements JsonConverter<Duration, int> { @ShouldGenerate(r''' Map<String, dynamic> _$JsonConverterOnGetterToJson( - JsonConverterOnGetter instance) => - <String, dynamic>{ - 'annotatedGetter': - const _NeedsConversionConverter().toJson(instance.annotatedGetter), - }; + JsonConverterOnGetter instance, +) => <String, dynamic>{ + 'annotatedGetter': const _NeedsConversionConverter().toJson( + instance.annotatedGetter, + ), +}; ''') @JsonSerializable(createFactory: false) class JsonConverterOnGetter { @@ -193,12 +202,10 @@ class _NeedsConversionConverter implements JsonConverter<NeedsConversion, int> { int toJson(NeedsConversion object) => 0; } -@ShouldThrow( - ''' +@ShouldThrow(''' Could not generate `fromJson` code for `value`. To support the type `NeedsConversion` you can: -$converterOrKeyInstructions''', -) +$converterOrKeyInstructions''') @_NullableConverter() @JsonSerializable() class JsonConverterNullableToNonNullable { diff --git a/json_serializable/test/src/map_key_variety_test_input.dart b/json_serializable/test/src/map_key_variety_test_input.dart index 9d55e3bcf..d81b0bca0 100644 --- a/json_serializable/test/src/map_key_variety_test_input.dart +++ b/json_serializable/test/src/map_key_variety_test_input.dart @@ -1,4 +1,4 @@ -// @dart=3.6 +// @dart=3.8 part of '_json_serializable_test_input.dart'; @@ -19,21 +19,17 @@ class MapKeyVariety { late Map<int, int> intIntMap; } -@ShouldThrow( - r''' +@ShouldThrow(r''' Could not generate `fromJson` code for `value` because of type `Object?`. -Map keys must be one of: Object, dynamic, enum, String, BigInt, DateTime, int, Uri.''', -) +Map keys must be one of: Object, dynamic, enum, String, BigInt, DateTime, int, Uri.''') @JsonSerializable() class MapKeyNoNullableObject { late Map<Object?, int> value; } -@ShouldThrow( - r''' +@ShouldThrow(r''' Could not generate `fromJson` code for `value` because of type `String?`. -Map keys must be one of: Object, dynamic, enum, String, BigInt, DateTime, int, Uri.''', -) +Map keys must be one of: Object, dynamic, enum, String, BigInt, DateTime, int, Uri.''') @JsonSerializable() class MapKeyNoNullableString { late Map<String?, int> value; diff --git a/json_serializable/test/src/setter_test_input.dart b/json_serializable/test/src/setter_test_input.dart index 81db156bc..678a5419d 100644 --- a/json_serializable/test/src/setter_test_input.dart +++ b/json_serializable/test/src/setter_test_input.dart @@ -1,4 +1,4 @@ -// @dart=3.6 +// @dart=3.8 part of '_json_serializable_test_input.dart'; @@ -31,8 +31,8 @@ class JustSetterNoToJson { @ShouldGenerate( r''' Map<String, dynamic> _$JustSetterNoFromJsonToJson( - JustSetterNoFromJson instance) => - <String, dynamic>{}; + JustSetterNoFromJson instance, +) => <String, dynamic>{}; ''', expectedLogItems: ['Setters are ignored: JustSetterNoFromJson.someSetter'], ) diff --git a/json_serializable/test/src/to_from_json_test_input.dart b/json_serializable/test/src/to_from_json_test_input.dart index d352e3027..d93db4188 100644 --- a/json_serializable/test/src/to_from_json_test_input.dart +++ b/json_serializable/test/src/to_from_json_test_input.dart @@ -2,7 +2,7 @@ // 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. -// @dart=3.6 +// @dart=3.8 // ignore_for_file: strict_top_level_inference @@ -40,20 +40,19 @@ class InvalidFromFunc2Args { late String field; } -@ShouldGenerate( - r''' +@ShouldGenerate(r''' ValidToFromFuncClassStatic _$ValidToFromFuncClassStaticFromJson( - Map<String, dynamic> json) => + Map<String, dynamic> json, +) => ValidToFromFuncClassStatic() ..field = ValidToFromFuncClassStatic._staticFunc(json['field'] as String); Map<String, dynamic> _$ValidToFromFuncClassStaticToJson( - ValidToFromFuncClassStatic instance) => - <String, dynamic>{ - 'field': ValidToFromFuncClassStatic._staticFunc(instance.field), - }; -''', -) + ValidToFromFuncClassStatic instance, +) => <String, dynamic>{ + 'field': ValidToFromFuncClassStatic._staticFunc(instance.field), +}; +''') @JsonSerializable() class ValidToFromFuncClassStatic { static String _staticFunc(String param) => throw UnimplementedError(); @@ -88,26 +87,23 @@ class Reproduce869NullableGenericType { late final List<int> values; } -@ShouldGenerate( - r''' +@ShouldGenerate(r''' Reproduce869NullableGenericTypeWithDefault - _$Reproduce869NullableGenericTypeWithDefaultFromJson( - Map<String, dynamic> json) => - Reproduce869NullableGenericTypeWithDefault() - ..values = - json['values'] == null ? [] : _fromList(json['values'] as List?) - ..valuesNullable = json['valuesNullable'] == null - ? [] - : _fromList(json['valuesNullable'] as List?); +_$Reproduce869NullableGenericTypeWithDefaultFromJson( + Map<String, dynamic> json, +) => Reproduce869NullableGenericTypeWithDefault() + ..values = json['values'] == null ? [] : _fromList(json['values'] as List?) + ..valuesNullable = json['valuesNullable'] == null + ? [] + : _fromList(json['valuesNullable'] as List?); Map<String, dynamic> _$Reproduce869NullableGenericTypeWithDefaultToJson( - Reproduce869NullableGenericTypeWithDefault instance) => - <String, dynamic>{ - 'values': _toList(instance.values), - 'valuesNullable': _toList(instance.valuesNullable), - }; -''', -) + Reproduce869NullableGenericTypeWithDefault instance, +) => <String, dynamic>{ + 'values': _toList(instance.values), + 'valuesNullable': _toList(instance.valuesNullable), +}; +''') @JsonSerializable() class Reproduce869NullableGenericTypeWithDefault { @JsonKey( @@ -142,20 +138,14 @@ class InvalidToFunc2Args { late String field; } -@ShouldGenerate( - "_toStringFromObject(json['field'])", - contains: true, -) +@ShouldGenerate("_toStringFromObject(json['field'])", contains: true) @JsonSerializable() class ObjectConvertMethods { @JsonKey(fromJson: _toStringFromObject, toJson: _toObject) late String field; } -@ShouldGenerate( - "_toDynamic(json['field'])", - contains: true, -) +@ShouldGenerate("_toDynamic(json['field'])", contains: true) @JsonSerializable() class DynamicConvertMethods { @JsonKey(fromJson: _toDynamic, toJson: _toDynamic) @@ -164,10 +154,7 @@ class DynamicConvertMethods { String _toString(String input) => 'null'; -@ShouldGenerate( - "_toString(json['field'] as String)", - contains: true, -) +@ShouldGenerate("_toString(json['field'] as String)", contains: true) @JsonSerializable() class TypedConvertMethods { @JsonKey(fromJson: _toString, toJson: _toString) @@ -176,16 +163,13 @@ class TypedConvertMethods { String? _toStringNullOnEmpty(String input) => input.isEmpty ? null : input; -@ShouldGenerate( - r''' +@ShouldGenerate(r''' Map<String, dynamic> _$ToJsonNullableFalseIncludeIfNullFalseToJson( - ToJsonNullableFalseIncludeIfNullFalse instance) => - <String, dynamic>{ - if (_toStringNullOnEmpty(instance.field) case final value?) - 'field': value, - }; -''', -) + ToJsonNullableFalseIncludeIfNullFalse instance, +) => <String, dynamic>{ + if (_toStringNullOnEmpty(instance.field) case final value?) 'field': value, +}; +''') @JsonSerializable(createFactory: false) class ToJsonNullableFalseIncludeIfNullFalse { @JsonKey(toJson: _toStringNullOnEmpty, includeIfNull: false) @@ -198,16 +182,14 @@ String _fromDynamicList(List input) => 'null'; String _fromDynamicIterable(Iterable input) => 'null'; -@ShouldGenerate( - r''' +@ShouldGenerate(r''' FromDynamicCollection _$FromDynamicCollectionFromJson( - Map<String, dynamic> json) => - FromDynamicCollection() - ..mapField = _fromDynamicMap(json['mapField'] as Map) - ..listField = _fromDynamicList(json['listField'] as List) - ..iterableField = _fromDynamicIterable(json['iterableField'] as List); -''', -) + Map<String, dynamic> json, +) => FromDynamicCollection() + ..mapField = _fromDynamicMap(json['mapField'] as Map) + ..listField = _fromDynamicList(json['listField'] as List) + ..iterableField = _fromDynamicIterable(json['iterableField'] as List); +''') @JsonSerializable(createToJson: false) class FromDynamicCollection { @JsonKey(fromJson: _fromDynamicMap) @@ -224,17 +206,16 @@ String _fromNullableDynamicList(List? input) => 'null'; String _fromNullableDynamicIterable(Iterable? input) => 'null'; -@ShouldGenerate( - r''' +@ShouldGenerate(r''' FromNullableDynamicCollection _$FromNullableDynamicCollectionFromJson( - Map<String, dynamic> json) => - FromNullableDynamicCollection() - ..mapField = _fromNullableDynamicMap(json['mapField'] as Map?) - ..listField = _fromNullableDynamicList(json['listField'] as List?) - ..iterableField = - _fromNullableDynamicIterable(json['iterableField'] as List?); -''', -) + Map<String, dynamic> json, +) => FromNullableDynamicCollection() + ..mapField = _fromNullableDynamicMap(json['mapField'] as Map?) + ..listField = _fromNullableDynamicList(json['listField'] as List?) + ..iterableField = _fromNullableDynamicIterable( + json['iterableField'] as List?, + ); +''') @JsonSerializable(createToJson: false) class FromNullableDynamicCollection { @JsonKey(fromJson: _fromNullableDynamicMap) @@ -311,19 +292,13 @@ class OkayOnlyOptionalPositional { String? field; } -@ShouldGenerate( - r''' +@ShouldGenerate(r''' _BetterPrivateNames _$BetterPrivateNamesFromJson(Map<String, dynamic> json) => - _BetterPrivateNames( - name: json['name'] as String, - ); + _BetterPrivateNames(name: json['name'] as String); Map<String, dynamic> _$BetterPrivateNamesToJson(_BetterPrivateNames instance) => - <String, dynamic>{ - 'name': instance.name, - }; -''', -) + <String, dynamic>{'name': instance.name}; +''') @JsonSerializable(createFactory: true, createToJson: true) // ignore: unused_element class _BetterPrivateNames { diff --git a/json_serializable/test/src/unknown_enum_value_test_input.dart b/json_serializable/test/src/unknown_enum_value_test_input.dart index 7dec6feaa..3e9bd27c8 100644 --- a/json_serializable/test/src/unknown_enum_value_test_input.dart +++ b/json_serializable/test/src/unknown_enum_value_test_input.dart @@ -1,14 +1,16 @@ -// @dart=3.6 +// @dart=3.8 part of '_json_serializable_test_input.dart'; -@ShouldGenerate( - r''' +@ShouldGenerate(r''' UnknownEnumValue _$UnknownEnumValueFromJson(Map<String, dynamic> json) => UnknownEnumValue() - ..value = $enumDecodeNullable( - _$UnknownEnumValueItemsEnumMap, json['value'], - unknownValue: UnknownEnumValueItems.vUnknown) ?? + ..value = + $enumDecodeNullable( + _$UnknownEnumValueItemsEnumMap, + json['value'], + unknownValue: UnknownEnumValueItems.vUnknown, + ) ?? UnknownEnumValueItems.vNull; const _$UnknownEnumValueItemsEnumMap = { @@ -18,11 +20,8 @@ const _$UnknownEnumValueItemsEnumMap = { UnknownEnumValueItems.vUnknown: 'vUnknown', UnknownEnumValueItems.vNull: 'vNull', }; -''', -) -@JsonSerializable( - createToJson: false, -) +''') +@JsonSerializable(createToJson: false) class UnknownEnumValue { @JsonKey( defaultValue: UnknownEnumValueItems.vNull, diff --git a/json_serializable/test/supported_types/extra_map_test.dart b/json_serializable/test/supported_types/extra_map_test.dart index c5ad878b2..922b57730 100644 --- a/json_serializable/test/supported_types/extra_map_test.dart +++ b/json_serializable/test/supported_types/extra_map_test.dart @@ -16,11 +16,11 @@ void main() { for (var input in const <Map<String, Object?>>{ {'value': {}}, { - 'value': {'key': 'value'} + 'value': {'key': 'value'}, }, { // Regression case for https://github.com/google/json_serializable.dart/issues/864 - 'value': {'key': null} + 'value': {'key': null}, }, }) { test(input, () { diff --git a/json_serializable/test/supported_types/input.dart b/json_serializable/test/supported_types/input.dart index 8a43e9fcc..be9300aee 100644 --- a/json_serializable/test/supported_types/input.dart +++ b/json_serializable/test/supported_types/input.dart @@ -13,10 +13,7 @@ class SimpleClass { @JsonKey(defaultValue: 42) dynamic withDefault; - SimpleClass( - this.value, - this.withDefault, - ); + SimpleClass(this.value, this.withDefault); factory SimpleClass.fromJson(Map<String, Object?> json) => _$SimpleClassFromJson(json); diff --git a/json_serializable/test/supported_types/input.g.dart b/json_serializable/test/supported_types/input.g.dart index 4c7e8053d..5657db18b 100644 --- a/json_serializable/test/supported_types/input.g.dart +++ b/json_serializable/test/supported_types/input.g.dart @@ -8,10 +8,8 @@ part of 'input.dart'; // JsonSerializableGenerator // ************************************************************************** -SimpleClass _$SimpleClassFromJson(Map<String, dynamic> json) => SimpleClass( - json['value'], - json['withDefault'] ?? 42, - ); +SimpleClass _$SimpleClassFromJson(Map<String, dynamic> json) => + SimpleClass(json['value'], json['withDefault'] ?? 42); Map<String, dynamic> _$SimpleClassToJson(SimpleClass instance) => <String, dynamic>{ diff --git a/json_serializable/test/supported_types/input.type_bigint.dart b/json_serializable/test/supported_types/input.type_bigint.dart index f376da7a1..d965e2925 100644 --- a/json_serializable/test/supported_types/input.type_bigint.dart +++ b/json_serializable/test/supported_types/input.type_bigint.dart @@ -13,10 +13,7 @@ class SimpleClass { @JsonKey(defaultValue: _defaultValueFunc) BigInt withDefault; - SimpleClass( - this.value, - this.withDefault, - ); + SimpleClass(this.value, this.withDefault); factory SimpleClass.fromJson(Map<String, Object?> json) => _$SimpleClassFromJson(json); @@ -31,10 +28,7 @@ class SimpleClassNullable { @JsonKey(defaultValue: _defaultValueFunc) BigInt? withDefault; - SimpleClassNullable( - this.value, - this.withDefault, - ); + SimpleClassNullable(this.value, this.withDefault); factory SimpleClassNullable.fromJson(Map<String, Object?> json) => _$SimpleClassNullableFromJson(json); diff --git a/json_serializable/test/supported_types/input.type_bigint.g.dart b/json_serializable/test/supported_types/input.type_bigint.g.dart index 379bdbd50..fd9be38b5 100644 --- a/json_serializable/test/supported_types/input.type_bigint.g.dart +++ b/json_serializable/test/supported_types/input.type_bigint.g.dart @@ -9,11 +9,11 @@ part of 'input.type_bigint.dart'; // ************************************************************************** SimpleClass _$SimpleClassFromJson(Map<String, dynamic> json) => SimpleClass( - BigInt.parse(json['value'] as String), - json['withDefault'] == null - ? _defaultValueFunc() - : BigInt.parse(json['withDefault'] as String), - ); + BigInt.parse(json['value'] as String), + json['withDefault'] == null + ? _defaultValueFunc() + : BigInt.parse(json['withDefault'] as String), +); Map<String, dynamic> _$SimpleClassToJson(SimpleClass instance) => <String, dynamic>{ @@ -30,8 +30,8 @@ SimpleClassNullable _$SimpleClassNullableFromJson(Map<String, dynamic> json) => ); Map<String, dynamic> _$SimpleClassNullableToJson( - SimpleClassNullable instance) => - <String, dynamic>{ - 'value': instance.value?.toString(), - 'withDefault': instance.withDefault?.toString(), - }; + SimpleClassNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.toString(), + 'withDefault': instance.withDefault?.toString(), +}; diff --git a/json_serializable/test/supported_types/input.type_bool.dart b/json_serializable/test/supported_types/input.type_bool.dart index e3fd6078c..f90c87aa4 100644 --- a/json_serializable/test/supported_types/input.type_bool.dart +++ b/json_serializable/test/supported_types/input.type_bool.dart @@ -13,10 +13,7 @@ class SimpleClass { @JsonKey(defaultValue: true) bool withDefault; - SimpleClass( - this.value, - this.withDefault, - ); + SimpleClass(this.value, this.withDefault); factory SimpleClass.fromJson(Map<String, Object?> json) => _$SimpleClassFromJson(json); @@ -31,10 +28,7 @@ class SimpleClassNullable { @JsonKey(defaultValue: true) bool? withDefault; - SimpleClassNullable( - this.value, - this.withDefault, - ); + SimpleClassNullable(this.value, this.withDefault); factory SimpleClassNullable.fromJson(Map<String, Object?> json) => _$SimpleClassNullableFromJson(json); diff --git a/json_serializable/test/supported_types/input.type_bool.g.dart b/json_serializable/test/supported_types/input.type_bool.g.dart index 4077ce108..90b889703 100644 --- a/json_serializable/test/supported_types/input.type_bool.g.dart +++ b/json_serializable/test/supported_types/input.type_bool.g.dart @@ -8,10 +8,8 @@ part of 'input.type_bool.dart'; // JsonSerializableGenerator // ************************************************************************** -SimpleClass _$SimpleClassFromJson(Map<String, dynamic> json) => SimpleClass( - json['value'] as bool, - json['withDefault'] as bool? ?? true, - ); +SimpleClass _$SimpleClassFromJson(Map<String, dynamic> json) => + SimpleClass(json['value'] as bool, json['withDefault'] as bool? ?? true); Map<String, dynamic> _$SimpleClassToJson(SimpleClass instance) => <String, dynamic>{ @@ -26,8 +24,8 @@ SimpleClassNullable _$SimpleClassNullableFromJson(Map<String, dynamic> json) => ); Map<String, dynamic> _$SimpleClassNullableToJson( - SimpleClassNullable instance) => - <String, dynamic>{ - 'value': instance.value, - 'withDefault': instance.withDefault, - }; + SimpleClassNullable instance, +) => <String, dynamic>{ + 'value': instance.value, + 'withDefault': instance.withDefault, +}; diff --git a/json_serializable/test/supported_types/input.type_datetime.dart b/json_serializable/test/supported_types/input.type_datetime.dart index 08d2dd797..24b91514f 100644 --- a/json_serializable/test/supported_types/input.type_datetime.dart +++ b/json_serializable/test/supported_types/input.type_datetime.dart @@ -13,10 +13,7 @@ class SimpleClass { @JsonKey(defaultValue: _defaultValueFunc) DateTime withDefault; - SimpleClass( - this.value, - this.withDefault, - ); + SimpleClass(this.value, this.withDefault); factory SimpleClass.fromJson(Map<String, Object?> json) => _$SimpleClassFromJson(json); @@ -31,10 +28,7 @@ class SimpleClassNullable { @JsonKey(defaultValue: _defaultValueFunc) DateTime? withDefault; - SimpleClassNullable( - this.value, - this.withDefault, - ); + SimpleClassNullable(this.value, this.withDefault); factory SimpleClassNullable.fromJson(Map<String, Object?> json) => _$SimpleClassNullableFromJson(json); diff --git a/json_serializable/test/supported_types/input.type_datetime.g.dart b/json_serializable/test/supported_types/input.type_datetime.g.dart index 461e30ebb..fdc0aff3f 100644 --- a/json_serializable/test/supported_types/input.type_datetime.g.dart +++ b/json_serializable/test/supported_types/input.type_datetime.g.dart @@ -9,11 +9,11 @@ part of 'input.type_datetime.dart'; // ************************************************************************** SimpleClass _$SimpleClassFromJson(Map<String, dynamic> json) => SimpleClass( - DateTime.parse(json['value'] as String), - json['withDefault'] == null - ? _defaultValueFunc() - : DateTime.parse(json['withDefault'] as String), - ); + DateTime.parse(json['value'] as String), + json['withDefault'] == null + ? _defaultValueFunc() + : DateTime.parse(json['withDefault'] as String), +); Map<String, dynamic> _$SimpleClassToJson(SimpleClass instance) => <String, dynamic>{ @@ -30,8 +30,8 @@ SimpleClassNullable _$SimpleClassNullableFromJson(Map<String, dynamic> json) => ); Map<String, dynamic> _$SimpleClassNullableToJson( - SimpleClassNullable instance) => - <String, dynamic>{ - 'value': instance.value?.toIso8601String(), - 'withDefault': instance.withDefault?.toIso8601String(), - }; + SimpleClassNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.toIso8601String(), + 'withDefault': instance.withDefault?.toIso8601String(), +}; diff --git a/json_serializable/test/supported_types/input.type_double.dart b/json_serializable/test/supported_types/input.type_double.dart index c51a0e35b..4ea8dafb0 100644 --- a/json_serializable/test/supported_types/input.type_double.dart +++ b/json_serializable/test/supported_types/input.type_double.dart @@ -13,10 +13,7 @@ class SimpleClass { @JsonKey(defaultValue: 3.14) double withDefault; - SimpleClass( - this.value, - this.withDefault, - ); + SimpleClass(this.value, this.withDefault); factory SimpleClass.fromJson(Map<String, Object?> json) => _$SimpleClassFromJson(json); @@ -31,10 +28,7 @@ class SimpleClassNullable { @JsonKey(defaultValue: 3.14) double? withDefault; - SimpleClassNullable( - this.value, - this.withDefault, - ); + SimpleClassNullable(this.value, this.withDefault); factory SimpleClassNullable.fromJson(Map<String, Object?> json) => _$SimpleClassNullableFromJson(json); diff --git a/json_serializable/test/supported_types/input.type_double.g.dart b/json_serializable/test/supported_types/input.type_double.g.dart index 163485d5a..3261dce7f 100644 --- a/json_serializable/test/supported_types/input.type_double.g.dart +++ b/json_serializable/test/supported_types/input.type_double.g.dart @@ -9,9 +9,9 @@ part of 'input.type_double.dart'; // ************************************************************************** SimpleClass _$SimpleClassFromJson(Map<String, dynamic> json) => SimpleClass( - (json['value'] as num).toDouble(), - (json['withDefault'] as num?)?.toDouble() ?? 3.14, - ); + (json['value'] as num).toDouble(), + (json['withDefault'] as num?)?.toDouble() ?? 3.14, +); Map<String, dynamic> _$SimpleClassToJson(SimpleClass instance) => <String, dynamic>{ @@ -26,8 +26,8 @@ SimpleClassNullable _$SimpleClassNullableFromJson(Map<String, dynamic> json) => ); Map<String, dynamic> _$SimpleClassNullableToJson( - SimpleClassNullable instance) => - <String, dynamic>{ - 'value': instance.value, - 'withDefault': instance.withDefault, - }; + SimpleClassNullable instance, +) => <String, dynamic>{ + 'value': instance.value, + 'withDefault': instance.withDefault, +}; diff --git a/json_serializable/test/supported_types/input.type_duration.dart b/json_serializable/test/supported_types/input.type_duration.dart index 7ecdef825..c040b4b6e 100644 --- a/json_serializable/test/supported_types/input.type_duration.dart +++ b/json_serializable/test/supported_types/input.type_duration.dart @@ -10,9 +10,7 @@ part 'input.type_duration.g.dart'; class SimpleClass { final Duration value; - SimpleClass( - this.value, - ); + SimpleClass(this.value); factory SimpleClass.fromJson(Map<String, Object?> json) => _$SimpleClassFromJson(json); @@ -24,9 +22,7 @@ class SimpleClass { class SimpleClassNullable { final Duration? value; - SimpleClassNullable( - this.value, - ); + SimpleClassNullable(this.value); factory SimpleClassNullable.fromJson(Map<String, Object?> json) => _$SimpleClassNullableFromJson(json); diff --git a/json_serializable/test/supported_types/input.type_duration.g.dart b/json_serializable/test/supported_types/input.type_duration.g.dart index 9d57d843c..bcb4bc291 100644 --- a/json_serializable/test/supported_types/input.type_duration.g.dart +++ b/json_serializable/test/supported_types/input.type_duration.g.dart @@ -8,14 +8,11 @@ part of 'input.type_duration.dart'; // JsonSerializableGenerator // ************************************************************************** -SimpleClass _$SimpleClassFromJson(Map<String, dynamic> json) => SimpleClass( - Duration(microseconds: (json['value'] as num).toInt()), - ); +SimpleClass _$SimpleClassFromJson(Map<String, dynamic> json) => + SimpleClass(Duration(microseconds: (json['value'] as num).toInt())); Map<String, dynamic> _$SimpleClassToJson(SimpleClass instance) => - <String, dynamic>{ - 'value': instance.value.inMicroseconds, - }; + <String, dynamic>{'value': instance.value.inMicroseconds}; SimpleClassNullable _$SimpleClassNullableFromJson(Map<String, dynamic> json) => SimpleClassNullable( @@ -25,7 +22,5 @@ SimpleClassNullable _$SimpleClassNullableFromJson(Map<String, dynamic> json) => ); Map<String, dynamic> _$SimpleClassNullableToJson( - SimpleClassNullable instance) => - <String, dynamic>{ - 'value': instance.value?.inMicroseconds, - }; + SimpleClassNullable instance, +) => <String, dynamic>{'value': instance.value?.inMicroseconds}; diff --git a/json_serializable/test/supported_types/input.type_enumtype.dart b/json_serializable/test/supported_types/input.type_enumtype.dart index 9225db715..117e9a6f7 100644 --- a/json_serializable/test/supported_types/input.type_enumtype.dart +++ b/json_serializable/test/supported_types/input.type_enumtype.dart @@ -14,10 +14,7 @@ class SimpleClass { @JsonKey(defaultValue: EnumType.alpha) EnumType withDefault; - SimpleClass( - this.value, - this.withDefault, - ); + SimpleClass(this.value, this.withDefault); factory SimpleClass.fromJson(Map<String, Object?> json) => _$SimpleClassFromJson(json); @@ -32,10 +29,7 @@ class SimpleClassNullable { @JsonKey(defaultValue: EnumType.alpha) EnumType? withDefault; - SimpleClassNullable( - this.value, - this.withDefault, - ); + SimpleClassNullable(this.value, this.withDefault); factory SimpleClassNullable.fromJson(Map<String, Object?> json) => _$SimpleClassNullableFromJson(json); diff --git a/json_serializable/test/supported_types/input.type_enumtype.g.dart b/json_serializable/test/supported_types/input.type_enumtype.g.dart index 77d67e064..3e25a0194 100644 --- a/json_serializable/test/supported_types/input.type_enumtype.g.dart +++ b/json_serializable/test/supported_types/input.type_enumtype.g.dart @@ -9,10 +9,9 @@ part of 'input.type_enumtype.dart'; // ************************************************************************** SimpleClass _$SimpleClassFromJson(Map<String, dynamic> json) => SimpleClass( - $enumDecode(_$EnumTypeEnumMap, json['value']), - $enumDecodeNullable(_$EnumTypeEnumMap, json['withDefault']) ?? - EnumType.alpha, - ); + $enumDecode(_$EnumTypeEnumMap, json['value']), + $enumDecodeNullable(_$EnumTypeEnumMap, json['withDefault']) ?? EnumType.alpha, +); Map<String, dynamic> _$SimpleClassToJson(SimpleClass instance) => <String, dynamic>{ @@ -35,8 +34,8 @@ SimpleClassNullable _$SimpleClassNullableFromJson(Map<String, dynamic> json) => ); Map<String, dynamic> _$SimpleClassNullableToJson( - SimpleClassNullable instance) => - <String, dynamic>{ - 'value': _$EnumTypeEnumMap[instance.value], - 'withDefault': _$EnumTypeEnumMap[instance.withDefault], - }; + SimpleClassNullable instance, +) => <String, dynamic>{ + 'value': _$EnumTypeEnumMap[instance.value], + 'withDefault': _$EnumTypeEnumMap[instance.withDefault], +}; diff --git a/json_serializable/test/supported_types/input.type_int.dart b/json_serializable/test/supported_types/input.type_int.dart index 6d80dc79c..62b5a882e 100644 --- a/json_serializable/test/supported_types/input.type_int.dart +++ b/json_serializable/test/supported_types/input.type_int.dart @@ -13,10 +13,7 @@ class SimpleClass { @JsonKey(defaultValue: 42) int withDefault; - SimpleClass( - this.value, - this.withDefault, - ); + SimpleClass(this.value, this.withDefault); factory SimpleClass.fromJson(Map<String, Object?> json) => _$SimpleClassFromJson(json); @@ -31,10 +28,7 @@ class SimpleClassNullable { @JsonKey(defaultValue: 42) int? withDefault; - SimpleClassNullable( - this.value, - this.withDefault, - ); + SimpleClassNullable(this.value, this.withDefault); factory SimpleClassNullable.fromJson(Map<String, Object?> json) => _$SimpleClassNullableFromJson(json); diff --git a/json_serializable/test/supported_types/input.type_int.g.dart b/json_serializable/test/supported_types/input.type_int.g.dart index 2f248b74a..00fd9ba1b 100644 --- a/json_serializable/test/supported_types/input.type_int.g.dart +++ b/json_serializable/test/supported_types/input.type_int.g.dart @@ -9,9 +9,9 @@ part of 'input.type_int.dart'; // ************************************************************************** SimpleClass _$SimpleClassFromJson(Map<String, dynamic> json) => SimpleClass( - (json['value'] as num).toInt(), - (json['withDefault'] as num?)?.toInt() ?? 42, - ); + (json['value'] as num).toInt(), + (json['withDefault'] as num?)?.toInt() ?? 42, +); Map<String, dynamic> _$SimpleClassToJson(SimpleClass instance) => <String, dynamic>{ @@ -26,8 +26,8 @@ SimpleClassNullable _$SimpleClassNullableFromJson(Map<String, dynamic> json) => ); Map<String, dynamic> _$SimpleClassNullableToJson( - SimpleClassNullable instance) => - <String, dynamic>{ - 'value': instance.value, - 'withDefault': instance.withDefault, - }; + SimpleClassNullable instance, +) => <String, dynamic>{ + 'value': instance.value, + 'withDefault': instance.withDefault, +}; diff --git a/json_serializable/test/supported_types/input.type_iterable.dart b/json_serializable/test/supported_types/input.type_iterable.dart index d01b49a20..b1b39e080 100644 --- a/json_serializable/test/supported_types/input.type_iterable.dart +++ b/json_serializable/test/supported_types/input.type_iterable.dart @@ -14,10 +14,7 @@ class SimpleClass { @JsonKey(defaultValue: [42, true, false, null]) Iterable withDefault; - SimpleClass( - this.value, - this.withDefault, - ); + SimpleClass(this.value, this.withDefault); factory SimpleClass.fromJson(Map<String, Object?> json) => _$SimpleClassFromJson(json); @@ -32,10 +29,7 @@ class SimpleClassNullable { @JsonKey(defaultValue: [42, true, false, null]) Iterable? withDefault; - SimpleClassNullable( - this.value, - this.withDefault, - ); + SimpleClassNullable(this.value, this.withDefault); factory SimpleClassNullable.fromJson(Map<String, Object?> json) => _$SimpleClassNullableFromJson(json); @@ -47,9 +41,7 @@ class SimpleClassNullable { class SimpleClassOfBigInt { final Iterable<BigInt> value; - SimpleClassOfBigInt( - this.value, - ); + SimpleClassOfBigInt(this.value); factory SimpleClassOfBigInt.fromJson(Map<String, Object?> json) => _$SimpleClassOfBigIntFromJson(json); @@ -61,9 +53,7 @@ class SimpleClassOfBigInt { class SimpleClassNullableOfBigInt { final Iterable<BigInt>? value; - SimpleClassNullableOfBigInt( - this.value, - ); + SimpleClassNullableOfBigInt(this.value); factory SimpleClassNullableOfBigInt.fromJson(Map<String, Object?> json) => _$SimpleClassNullableOfBigIntFromJson(json); @@ -75,9 +65,7 @@ class SimpleClassNullableOfBigInt { class SimpleClassOfBigIntNullable { final Iterable<BigInt?> value; - SimpleClassOfBigIntNullable( - this.value, - ); + SimpleClassOfBigIntNullable(this.value); factory SimpleClassOfBigIntNullable.fromJson(Map<String, Object?> json) => _$SimpleClassOfBigIntNullableFromJson(json); @@ -89,13 +77,11 @@ class SimpleClassOfBigIntNullable { class SimpleClassNullableOfBigIntNullable { final Iterable<BigInt?>? value; - SimpleClassNullableOfBigIntNullable( - this.value, - ); + SimpleClassNullableOfBigIntNullable(this.value); factory SimpleClassNullableOfBigIntNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfBigIntNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfBigIntNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfBigIntNullableToJson(this); @@ -105,9 +91,7 @@ class SimpleClassNullableOfBigIntNullable { class SimpleClassOfBool { final Iterable<bool> value; - SimpleClassOfBool( - this.value, - ); + SimpleClassOfBool(this.value); factory SimpleClassOfBool.fromJson(Map<String, Object?> json) => _$SimpleClassOfBoolFromJson(json); @@ -119,9 +103,7 @@ class SimpleClassOfBool { class SimpleClassNullableOfBool { final Iterable<bool>? value; - SimpleClassNullableOfBool( - this.value, - ); + SimpleClassNullableOfBool(this.value); factory SimpleClassNullableOfBool.fromJson(Map<String, Object?> json) => _$SimpleClassNullableOfBoolFromJson(json); @@ -133,9 +115,7 @@ class SimpleClassNullableOfBool { class SimpleClassOfBoolNullable { final Iterable<bool?> value; - SimpleClassOfBoolNullable( - this.value, - ); + SimpleClassOfBoolNullable(this.value); factory SimpleClassOfBoolNullable.fromJson(Map<String, Object?> json) => _$SimpleClassOfBoolNullableFromJson(json); @@ -147,13 +127,11 @@ class SimpleClassOfBoolNullable { class SimpleClassNullableOfBoolNullable { final Iterable<bool?>? value; - SimpleClassNullableOfBoolNullable( - this.value, - ); + SimpleClassNullableOfBoolNullable(this.value); factory SimpleClassNullableOfBoolNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfBoolNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfBoolNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfBoolNullableToJson(this); @@ -163,9 +141,7 @@ class SimpleClassNullableOfBoolNullable { class SimpleClassOfDateTime { final Iterable<DateTime> value; - SimpleClassOfDateTime( - this.value, - ); + SimpleClassOfDateTime(this.value); factory SimpleClassOfDateTime.fromJson(Map<String, Object?> json) => _$SimpleClassOfDateTimeFromJson(json); @@ -177,9 +153,7 @@ class SimpleClassOfDateTime { class SimpleClassNullableOfDateTime { final Iterable<DateTime>? value; - SimpleClassNullableOfDateTime( - this.value, - ); + SimpleClassNullableOfDateTime(this.value); factory SimpleClassNullableOfDateTime.fromJson(Map<String, Object?> json) => _$SimpleClassNullableOfDateTimeFromJson(json); @@ -191,9 +165,7 @@ class SimpleClassNullableOfDateTime { class SimpleClassOfDateTimeNullable { final Iterable<DateTime?> value; - SimpleClassOfDateTimeNullable( - this.value, - ); + SimpleClassOfDateTimeNullable(this.value); factory SimpleClassOfDateTimeNullable.fromJson(Map<String, Object?> json) => _$SimpleClassOfDateTimeNullableFromJson(json); @@ -205,13 +177,11 @@ class SimpleClassOfDateTimeNullable { class SimpleClassNullableOfDateTimeNullable { final Iterable<DateTime?>? value; - SimpleClassNullableOfDateTimeNullable( - this.value, - ); + SimpleClassNullableOfDateTimeNullable(this.value); factory SimpleClassNullableOfDateTimeNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfDateTimeNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfDateTimeNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfDateTimeNullableToJson(this); @@ -221,9 +191,7 @@ class SimpleClassNullableOfDateTimeNullable { class SimpleClassOfDouble { final Iterable<double> value; - SimpleClassOfDouble( - this.value, - ); + SimpleClassOfDouble(this.value); factory SimpleClassOfDouble.fromJson(Map<String, Object?> json) => _$SimpleClassOfDoubleFromJson(json); @@ -235,9 +203,7 @@ class SimpleClassOfDouble { class SimpleClassNullableOfDouble { final Iterable<double>? value; - SimpleClassNullableOfDouble( - this.value, - ); + SimpleClassNullableOfDouble(this.value); factory SimpleClassNullableOfDouble.fromJson(Map<String, Object?> json) => _$SimpleClassNullableOfDoubleFromJson(json); @@ -249,9 +215,7 @@ class SimpleClassNullableOfDouble { class SimpleClassOfDoubleNullable { final Iterable<double?> value; - SimpleClassOfDoubleNullable( - this.value, - ); + SimpleClassOfDoubleNullable(this.value); factory SimpleClassOfDoubleNullable.fromJson(Map<String, Object?> json) => _$SimpleClassOfDoubleNullableFromJson(json); @@ -263,13 +227,11 @@ class SimpleClassOfDoubleNullable { class SimpleClassNullableOfDoubleNullable { final Iterable<double?>? value; - SimpleClassNullableOfDoubleNullable( - this.value, - ); + SimpleClassNullableOfDoubleNullable(this.value); factory SimpleClassNullableOfDoubleNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfDoubleNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfDoubleNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfDoubleNullableToJson(this); @@ -279,9 +241,7 @@ class SimpleClassNullableOfDoubleNullable { class SimpleClassOfDuration { final Iterable<Duration> value; - SimpleClassOfDuration( - this.value, - ); + SimpleClassOfDuration(this.value); factory SimpleClassOfDuration.fromJson(Map<String, Object?> json) => _$SimpleClassOfDurationFromJson(json); @@ -293,9 +253,7 @@ class SimpleClassOfDuration { class SimpleClassNullableOfDuration { final Iterable<Duration>? value; - SimpleClassNullableOfDuration( - this.value, - ); + SimpleClassNullableOfDuration(this.value); factory SimpleClassNullableOfDuration.fromJson(Map<String, Object?> json) => _$SimpleClassNullableOfDurationFromJson(json); @@ -307,9 +265,7 @@ class SimpleClassNullableOfDuration { class SimpleClassOfDurationNullable { final Iterable<Duration?> value; - SimpleClassOfDurationNullable( - this.value, - ); + SimpleClassOfDurationNullable(this.value); factory SimpleClassOfDurationNullable.fromJson(Map<String, Object?> json) => _$SimpleClassOfDurationNullableFromJson(json); @@ -321,13 +277,11 @@ class SimpleClassOfDurationNullable { class SimpleClassNullableOfDurationNullable { final Iterable<Duration?>? value; - SimpleClassNullableOfDurationNullable( - this.value, - ); + SimpleClassNullableOfDurationNullable(this.value); factory SimpleClassNullableOfDurationNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfDurationNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfDurationNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfDurationNullableToJson(this); @@ -337,9 +291,7 @@ class SimpleClassNullableOfDurationNullable { class SimpleClassOfDynamic { final Iterable<dynamic> value; - SimpleClassOfDynamic( - this.value, - ); + SimpleClassOfDynamic(this.value); factory SimpleClassOfDynamic.fromJson(Map<String, Object?> json) => _$SimpleClassOfDynamicFromJson(json); @@ -351,9 +303,7 @@ class SimpleClassOfDynamic { class SimpleClassNullableOfDynamic { final Iterable<dynamic>? value; - SimpleClassNullableOfDynamic( - this.value, - ); + SimpleClassNullableOfDynamic(this.value); factory SimpleClassNullableOfDynamic.fromJson(Map<String, Object?> json) => _$SimpleClassNullableOfDynamicFromJson(json); @@ -365,9 +315,7 @@ class SimpleClassNullableOfDynamic { class SimpleClassOfEnumType { final Iterable<EnumType> value; - SimpleClassOfEnumType( - this.value, - ); + SimpleClassOfEnumType(this.value); factory SimpleClassOfEnumType.fromJson(Map<String, Object?> json) => _$SimpleClassOfEnumTypeFromJson(json); @@ -379,9 +327,7 @@ class SimpleClassOfEnumType { class SimpleClassNullableOfEnumType { final Iterable<EnumType>? value; - SimpleClassNullableOfEnumType( - this.value, - ); + SimpleClassNullableOfEnumType(this.value); factory SimpleClassNullableOfEnumType.fromJson(Map<String, Object?> json) => _$SimpleClassNullableOfEnumTypeFromJson(json); @@ -393,9 +339,7 @@ class SimpleClassNullableOfEnumType { class SimpleClassOfEnumTypeNullable { final Iterable<EnumType?> value; - SimpleClassOfEnumTypeNullable( - this.value, - ); + SimpleClassOfEnumTypeNullable(this.value); factory SimpleClassOfEnumTypeNullable.fromJson(Map<String, Object?> json) => _$SimpleClassOfEnumTypeNullableFromJson(json); @@ -407,13 +351,11 @@ class SimpleClassOfEnumTypeNullable { class SimpleClassNullableOfEnumTypeNullable { final Iterable<EnumType?>? value; - SimpleClassNullableOfEnumTypeNullable( - this.value, - ); + SimpleClassNullableOfEnumTypeNullable(this.value); factory SimpleClassNullableOfEnumTypeNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfEnumTypeNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfEnumTypeNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfEnumTypeNullableToJson(this); @@ -423,13 +365,11 @@ class SimpleClassNullableOfEnumTypeNullable { class SimpleClassOfFromJsonDynamicParam { final Iterable<FromJsonDynamicParam> value; - SimpleClassOfFromJsonDynamicParam( - this.value, - ); + SimpleClassOfFromJsonDynamicParam(this.value); factory SimpleClassOfFromJsonDynamicParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfFromJsonDynamicParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfFromJsonDynamicParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfFromJsonDynamicParamToJson(this); @@ -439,13 +379,11 @@ class SimpleClassOfFromJsonDynamicParam { class SimpleClassNullableOfFromJsonDynamicParam { final Iterable<FromJsonDynamicParam>? value; - SimpleClassNullableOfFromJsonDynamicParam( - this.value, - ); + SimpleClassNullableOfFromJsonDynamicParam(this.value); factory SimpleClassNullableOfFromJsonDynamicParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfFromJsonDynamicParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfFromJsonDynamicParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfFromJsonDynamicParamToJson(this); @@ -455,13 +393,11 @@ class SimpleClassNullableOfFromJsonDynamicParam { class SimpleClassOfFromJsonNullableObjectParam { final Iterable<FromJsonNullableObjectParam> value; - SimpleClassOfFromJsonNullableObjectParam( - this.value, - ); + SimpleClassOfFromJsonNullableObjectParam(this.value); factory SimpleClassOfFromJsonNullableObjectParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfFromJsonNullableObjectParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfFromJsonNullableObjectParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfFromJsonNullableObjectParamToJson(this); @@ -471,13 +407,11 @@ class SimpleClassOfFromJsonNullableObjectParam { class SimpleClassNullableOfFromJsonNullableObjectParam { final Iterable<FromJsonNullableObjectParam>? value; - SimpleClassNullableOfFromJsonNullableObjectParam( - this.value, - ); + SimpleClassNullableOfFromJsonNullableObjectParam(this.value); factory SimpleClassNullableOfFromJsonNullableObjectParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfFromJsonNullableObjectParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfFromJsonNullableObjectParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfFromJsonNullableObjectParamToJson(this); @@ -487,13 +421,11 @@ class SimpleClassNullableOfFromJsonNullableObjectParam { class SimpleClassOfFromJsonObjectParam { final Iterable<FromJsonObjectParam> value; - SimpleClassOfFromJsonObjectParam( - this.value, - ); + SimpleClassOfFromJsonObjectParam(this.value); factory SimpleClassOfFromJsonObjectParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfFromJsonObjectParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfFromJsonObjectParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfFromJsonObjectParamToJson(this); @@ -503,13 +435,11 @@ class SimpleClassOfFromJsonObjectParam { class SimpleClassNullableOfFromJsonObjectParam { final Iterable<FromJsonObjectParam>? value; - SimpleClassNullableOfFromJsonObjectParam( - this.value, - ); + SimpleClassNullableOfFromJsonObjectParam(this.value); factory SimpleClassNullableOfFromJsonObjectParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfFromJsonObjectParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfFromJsonObjectParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfFromJsonObjectParamToJson(this); @@ -519,9 +449,7 @@ class SimpleClassNullableOfFromJsonObjectParam { class SimpleClassOfInt { final Iterable<int> value; - SimpleClassOfInt( - this.value, - ); + SimpleClassOfInt(this.value); factory SimpleClassOfInt.fromJson(Map<String, Object?> json) => _$SimpleClassOfIntFromJson(json); @@ -533,9 +461,7 @@ class SimpleClassOfInt { class SimpleClassNullableOfInt { final Iterable<int>? value; - SimpleClassNullableOfInt( - this.value, - ); + SimpleClassNullableOfInt(this.value); factory SimpleClassNullableOfInt.fromJson(Map<String, Object?> json) => _$SimpleClassNullableOfIntFromJson(json); @@ -547,9 +473,7 @@ class SimpleClassNullableOfInt { class SimpleClassOfIntNullable { final Iterable<int?> value; - SimpleClassOfIntNullable( - this.value, - ); + SimpleClassOfIntNullable(this.value); factory SimpleClassOfIntNullable.fromJson(Map<String, Object?> json) => _$SimpleClassOfIntNullableFromJson(json); @@ -561,13 +485,11 @@ class SimpleClassOfIntNullable { class SimpleClassNullableOfIntNullable { final Iterable<int?>? value; - SimpleClassNullableOfIntNullable( - this.value, - ); + SimpleClassNullableOfIntNullable(this.value); factory SimpleClassNullableOfIntNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfIntNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfIntNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfIntNullableToJson(this); @@ -577,9 +499,7 @@ class SimpleClassNullableOfIntNullable { class SimpleClassOfNum { final Iterable<num> value; - SimpleClassOfNum( - this.value, - ); + SimpleClassOfNum(this.value); factory SimpleClassOfNum.fromJson(Map<String, Object?> json) => _$SimpleClassOfNumFromJson(json); @@ -591,9 +511,7 @@ class SimpleClassOfNum { class SimpleClassNullableOfNum { final Iterable<num>? value; - SimpleClassNullableOfNum( - this.value, - ); + SimpleClassNullableOfNum(this.value); factory SimpleClassNullableOfNum.fromJson(Map<String, Object?> json) => _$SimpleClassNullableOfNumFromJson(json); @@ -605,9 +523,7 @@ class SimpleClassNullableOfNum { class SimpleClassOfNumNullable { final Iterable<num?> value; - SimpleClassOfNumNullable( - this.value, - ); + SimpleClassOfNumNullable(this.value); factory SimpleClassOfNumNullable.fromJson(Map<String, Object?> json) => _$SimpleClassOfNumNullableFromJson(json); @@ -619,13 +535,11 @@ class SimpleClassOfNumNullable { class SimpleClassNullableOfNumNullable { final Iterable<num?>? value; - SimpleClassNullableOfNumNullable( - this.value, - ); + SimpleClassNullableOfNumNullable(this.value); factory SimpleClassNullableOfNumNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfNumNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfNumNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfNumNullableToJson(this); @@ -635,9 +549,7 @@ class SimpleClassNullableOfNumNullable { class SimpleClassOfObject { final Iterable<Object> value; - SimpleClassOfObject( - this.value, - ); + SimpleClassOfObject(this.value); factory SimpleClassOfObject.fromJson(Map<String, Object?> json) => _$SimpleClassOfObjectFromJson(json); @@ -649,9 +561,7 @@ class SimpleClassOfObject { class SimpleClassNullableOfObject { final Iterable<Object>? value; - SimpleClassNullableOfObject( - this.value, - ); + SimpleClassNullableOfObject(this.value); factory SimpleClassNullableOfObject.fromJson(Map<String, Object?> json) => _$SimpleClassNullableOfObjectFromJson(json); @@ -663,9 +573,7 @@ class SimpleClassNullableOfObject { class SimpleClassOfObjectNullable { final Iterable<Object?> value; - SimpleClassOfObjectNullable( - this.value, - ); + SimpleClassOfObjectNullable(this.value); factory SimpleClassOfObjectNullable.fromJson(Map<String, Object?> json) => _$SimpleClassOfObjectNullableFromJson(json); @@ -677,13 +585,11 @@ class SimpleClassOfObjectNullable { class SimpleClassNullableOfObjectNullable { final Iterable<Object?>? value; - SimpleClassNullableOfObjectNullable( - this.value, - ); + SimpleClassNullableOfObjectNullable(this.value); factory SimpleClassNullableOfObjectNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfObjectNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfObjectNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfObjectNullableToJson(this); @@ -693,9 +599,7 @@ class SimpleClassNullableOfObjectNullable { class SimpleClassOfRecord { final Iterable<(int, String, {bool truth})> value; - SimpleClassOfRecord( - this.value, - ); + SimpleClassOfRecord(this.value); factory SimpleClassOfRecord.fromJson(Map<String, Object?> json) => _$SimpleClassOfRecordFromJson(json); @@ -707,9 +611,7 @@ class SimpleClassOfRecord { class SimpleClassNullableOfRecord { final Iterable<(int, String, {bool truth})>? value; - SimpleClassNullableOfRecord( - this.value, - ); + SimpleClassNullableOfRecord(this.value); factory SimpleClassNullableOfRecord.fromJson(Map<String, Object?> json) => _$SimpleClassNullableOfRecordFromJson(json); @@ -721,9 +623,7 @@ class SimpleClassNullableOfRecord { class SimpleClassOfString { final Iterable<String> value; - SimpleClassOfString( - this.value, - ); + SimpleClassOfString(this.value); factory SimpleClassOfString.fromJson(Map<String, Object?> json) => _$SimpleClassOfStringFromJson(json); @@ -735,9 +635,7 @@ class SimpleClassOfString { class SimpleClassNullableOfString { final Iterable<String>? value; - SimpleClassNullableOfString( - this.value, - ); + SimpleClassNullableOfString(this.value); factory SimpleClassNullableOfString.fromJson(Map<String, Object?> json) => _$SimpleClassNullableOfStringFromJson(json); @@ -749,9 +647,7 @@ class SimpleClassNullableOfString { class SimpleClassOfStringNullable { final Iterable<String?> value; - SimpleClassOfStringNullable( - this.value, - ); + SimpleClassOfStringNullable(this.value); factory SimpleClassOfStringNullable.fromJson(Map<String, Object?> json) => _$SimpleClassOfStringNullableFromJson(json); @@ -763,13 +659,11 @@ class SimpleClassOfStringNullable { class SimpleClassNullableOfStringNullable { final Iterable<String?>? value; - SimpleClassNullableOfStringNullable( - this.value, - ); + SimpleClassNullableOfStringNullable(this.value); factory SimpleClassNullableOfStringNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfStringNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfStringNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfStringNullableToJson(this); @@ -779,9 +673,7 @@ class SimpleClassNullableOfStringNullable { class SimpleClassOfUri { final Iterable<Uri> value; - SimpleClassOfUri( - this.value, - ); + SimpleClassOfUri(this.value); factory SimpleClassOfUri.fromJson(Map<String, Object?> json) => _$SimpleClassOfUriFromJson(json); @@ -793,9 +685,7 @@ class SimpleClassOfUri { class SimpleClassNullableOfUri { final Iterable<Uri>? value; - SimpleClassNullableOfUri( - this.value, - ); + SimpleClassNullableOfUri(this.value); factory SimpleClassNullableOfUri.fromJson(Map<String, Object?> json) => _$SimpleClassNullableOfUriFromJson(json); @@ -807,9 +697,7 @@ class SimpleClassNullableOfUri { class SimpleClassOfUriNullable { final Iterable<Uri?> value; - SimpleClassOfUriNullable( - this.value, - ); + SimpleClassOfUriNullable(this.value); factory SimpleClassOfUriNullable.fromJson(Map<String, Object?> json) => _$SimpleClassOfUriNullableFromJson(json); @@ -821,13 +709,11 @@ class SimpleClassOfUriNullable { class SimpleClassNullableOfUriNullable { final Iterable<Uri?>? value; - SimpleClassNullableOfUriNullable( - this.value, - ); + SimpleClassNullableOfUriNullable(this.value); factory SimpleClassNullableOfUriNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfUriNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfUriNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfUriNullableToJson(this); diff --git a/json_serializable/test/supported_types/input.type_iterable.g.dart b/json_serializable/test/supported_types/input.type_iterable.g.dart index a9264f393..6f2df94a4 100644 --- a/json_serializable/test/supported_types/input.type_iterable.g.dart +++ b/json_serializable/test/supported_types/input.type_iterable.g.dart @@ -9,9 +9,9 @@ part of 'input.type_iterable.dart'; // ************************************************************************** SimpleClass _$SimpleClassFromJson(Map<String, dynamic> json) => SimpleClass( - json['value'] as List<dynamic>, - json['withDefault'] as List<dynamic>? ?? [42, true, false, null], - ); + json['value'] as List<dynamic>, + json['withDefault'] as List<dynamic>? ?? [42, true, false, null], +); Map<String, dynamic> _$SimpleClassToJson(SimpleClass instance) => <String, dynamic>{ @@ -26,11 +26,11 @@ SimpleClassNullable _$SimpleClassNullableFromJson(Map<String, dynamic> json) => ); Map<String, dynamic> _$SimpleClassNullableToJson( - SimpleClassNullable instance) => - <String, dynamic>{ - 'value': instance.value?.toList(), - 'withDefault': instance.withDefault?.toList(), - }; + SimpleClassNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.toList(), + 'withDefault': instance.withDefault?.toList(), +}; SimpleClassOfBigInt _$SimpleClassOfBigIntFromJson(Map<String, dynamic> json) => SimpleClassOfBigInt( @@ -38,146 +38,138 @@ SimpleClassOfBigInt _$SimpleClassOfBigIntFromJson(Map<String, dynamic> json) => ); Map<String, dynamic> _$SimpleClassOfBigIntToJson( - SimpleClassOfBigInt instance) => - <String, dynamic>{ - 'value': instance.value.map((e) => e.toString()).toList(), - }; + SimpleClassOfBigInt instance, +) => <String, dynamic>{ + 'value': instance.value.map((e) => e.toString()).toList(), +}; SimpleClassNullableOfBigInt _$SimpleClassNullableOfBigIntFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfBigInt( - (json['value'] as List<dynamic>?)?.map((e) => BigInt.parse(e as String)), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfBigInt( + (json['value'] as List<dynamic>?)?.map((e) => BigInt.parse(e as String)), +); Map<String, dynamic> _$SimpleClassNullableOfBigIntToJson( - SimpleClassNullableOfBigInt instance) => - <String, dynamic>{ - 'value': instance.value?.map((e) => e.toString()).toList(), - }; + SimpleClassNullableOfBigInt instance, +) => <String, dynamic>{ + 'value': instance.value?.map((e) => e.toString()).toList(), +}; SimpleClassOfBigIntNullable _$SimpleClassOfBigIntNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfBigIntNullable( - (json['value'] as List<dynamic>) - .map((e) => e == null ? null : BigInt.parse(e as String)), - ); + Map<String, dynamic> json, +) => SimpleClassOfBigIntNullable( + (json['value'] as List<dynamic>).map( + (e) => e == null ? null : BigInt.parse(e as String), + ), +); Map<String, dynamic> _$SimpleClassOfBigIntNullableToJson( - SimpleClassOfBigIntNullable instance) => - <String, dynamic>{ - 'value': instance.value.map((e) => e?.toString()).toList(), - }; + SimpleClassOfBigIntNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map((e) => e?.toString()).toList(), +}; SimpleClassNullableOfBigIntNullable - _$SimpleClassNullableOfBigIntNullableFromJson(Map<String, dynamic> json) => - SimpleClassNullableOfBigIntNullable( - (json['value'] as List<dynamic>?) - ?.map((e) => e == null ? null : BigInt.parse(e as String)), - ); +_$SimpleClassNullableOfBigIntNullableFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfBigIntNullable( + (json['value'] as List<dynamic>?)?.map( + (e) => e == null ? null : BigInt.parse(e as String), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfBigIntNullableToJson( - SimpleClassNullableOfBigIntNullable instance) => - <String, dynamic>{ - 'value': instance.value?.map((e) => e?.toString()).toList(), - }; + SimpleClassNullableOfBigIntNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map((e) => e?.toString()).toList(), +}; SimpleClassOfBool _$SimpleClassOfBoolFromJson(Map<String, dynamic> json) => - SimpleClassOfBool( - (json['value'] as List<dynamic>).map((e) => e as bool), - ); + SimpleClassOfBool((json['value'] as List<dynamic>).map((e) => e as bool)); Map<String, dynamic> _$SimpleClassOfBoolToJson(SimpleClassOfBool instance) => - <String, dynamic>{ - 'value': instance.value.toList(), - }; + <String, dynamic>{'value': instance.value.toList()}; SimpleClassNullableOfBool _$SimpleClassNullableOfBoolFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfBool( - (json['value'] as List<dynamic>?)?.map((e) => e as bool), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfBool( + (json['value'] as List<dynamic>?)?.map((e) => e as bool), +); Map<String, dynamic> _$SimpleClassNullableOfBoolToJson( - SimpleClassNullableOfBool instance) => - <String, dynamic>{ - 'value': instance.value?.toList(), - }; + SimpleClassNullableOfBool instance, +) => <String, dynamic>{'value': instance.value?.toList()}; SimpleClassOfBoolNullable _$SimpleClassOfBoolNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfBoolNullable( - (json['value'] as List<dynamic>).map((e) => e as bool?), - ); + Map<String, dynamic> json, +) => SimpleClassOfBoolNullable( + (json['value'] as List<dynamic>).map((e) => e as bool?), +); Map<String, dynamic> _$SimpleClassOfBoolNullableToJson( - SimpleClassOfBoolNullable instance) => - <String, dynamic>{ - 'value': instance.value.toList(), - }; + SimpleClassOfBoolNullable instance, +) => <String, dynamic>{'value': instance.value.toList()}; SimpleClassNullableOfBoolNullable _$SimpleClassNullableOfBoolNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfBoolNullable( - (json['value'] as List<dynamic>?)?.map((e) => e as bool?), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfBoolNullable( + (json['value'] as List<dynamic>?)?.map((e) => e as bool?), +); Map<String, dynamic> _$SimpleClassNullableOfBoolNullableToJson( - SimpleClassNullableOfBoolNullable instance) => - <String, dynamic>{ - 'value': instance.value?.toList(), - }; + SimpleClassNullableOfBoolNullable instance, +) => <String, dynamic>{'value': instance.value?.toList()}; SimpleClassOfDateTime _$SimpleClassOfDateTimeFromJson( - Map<String, dynamic> json) => - SimpleClassOfDateTime( - (json['value'] as List<dynamic>).map((e) => DateTime.parse(e as String)), - ); + Map<String, dynamic> json, +) => SimpleClassOfDateTime( + (json['value'] as List<dynamic>).map((e) => DateTime.parse(e as String)), +); Map<String, dynamic> _$SimpleClassOfDateTimeToJson( - SimpleClassOfDateTime instance) => - <String, dynamic>{ - 'value': instance.value.map((e) => e.toIso8601String()).toList(), - }; + SimpleClassOfDateTime instance, +) => <String, dynamic>{ + 'value': instance.value.map((e) => e.toIso8601String()).toList(), +}; SimpleClassNullableOfDateTime _$SimpleClassNullableOfDateTimeFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDateTime( - (json['value'] as List<dynamic>?) - ?.map((e) => DateTime.parse(e as String)), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfDateTime( + (json['value'] as List<dynamic>?)?.map((e) => DateTime.parse(e as String)), +); Map<String, dynamic> _$SimpleClassNullableOfDateTimeToJson( - SimpleClassNullableOfDateTime instance) => - <String, dynamic>{ - 'value': instance.value?.map((e) => e.toIso8601String()).toList(), - }; + SimpleClassNullableOfDateTime instance, +) => <String, dynamic>{ + 'value': instance.value?.map((e) => e.toIso8601String()).toList(), +}; SimpleClassOfDateTimeNullable _$SimpleClassOfDateTimeNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfDateTimeNullable( - (json['value'] as List<dynamic>) - .map((e) => e == null ? null : DateTime.parse(e as String)), - ); + Map<String, dynamic> json, +) => SimpleClassOfDateTimeNullable( + (json['value'] as List<dynamic>).map( + (e) => e == null ? null : DateTime.parse(e as String), + ), +); Map<String, dynamic> _$SimpleClassOfDateTimeNullableToJson( - SimpleClassOfDateTimeNullable instance) => - <String, dynamic>{ - 'value': instance.value.map((e) => e?.toIso8601String()).toList(), - }; + SimpleClassOfDateTimeNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map((e) => e?.toIso8601String()).toList(), +}; SimpleClassNullableOfDateTimeNullable - _$SimpleClassNullableOfDateTimeNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDateTimeNullable( - (json['value'] as List<dynamic>?) - ?.map((e) => e == null ? null : DateTime.parse(e as String)), - ); +_$SimpleClassNullableOfDateTimeNullableFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfDateTimeNullable( + (json['value'] as List<dynamic>?)?.map( + (e) => e == null ? null : DateTime.parse(e as String), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfDateTimeNullableToJson( - SimpleClassNullableOfDateTimeNullable instance) => - <String, dynamic>{ - 'value': instance.value?.map((e) => e?.toIso8601String()).toList(), - }; + SimpleClassNullableOfDateTimeNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map((e) => e?.toIso8601String()).toList(), +}; SimpleClassOfDouble _$SimpleClassOfDoubleFromJson(Map<String, dynamic> json) => SimpleClassOfDouble( @@ -185,137 +177,124 @@ SimpleClassOfDouble _$SimpleClassOfDoubleFromJson(Map<String, dynamic> json) => ); Map<String, dynamic> _$SimpleClassOfDoubleToJson( - SimpleClassOfDouble instance) => - <String, dynamic>{ - 'value': instance.value.toList(), - }; + SimpleClassOfDouble instance, +) => <String, dynamic>{'value': instance.value.toList()}; SimpleClassNullableOfDouble _$SimpleClassNullableOfDoubleFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDouble( - (json['value'] as List<dynamic>?)?.map((e) => (e as num).toDouble()), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfDouble( + (json['value'] as List<dynamic>?)?.map((e) => (e as num).toDouble()), +); Map<String, dynamic> _$SimpleClassNullableOfDoubleToJson( - SimpleClassNullableOfDouble instance) => - <String, dynamic>{ - 'value': instance.value?.toList(), - }; + SimpleClassNullableOfDouble instance, +) => <String, dynamic>{'value': instance.value?.toList()}; SimpleClassOfDoubleNullable _$SimpleClassOfDoubleNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfDoubleNullable( - (json['value'] as List<dynamic>).map((e) => (e as num?)?.toDouble()), - ); + Map<String, dynamic> json, +) => SimpleClassOfDoubleNullable( + (json['value'] as List<dynamic>).map((e) => (e as num?)?.toDouble()), +); Map<String, dynamic> _$SimpleClassOfDoubleNullableToJson( - SimpleClassOfDoubleNullable instance) => - <String, dynamic>{ - 'value': instance.value.toList(), - }; + SimpleClassOfDoubleNullable instance, +) => <String, dynamic>{'value': instance.value.toList()}; SimpleClassNullableOfDoubleNullable - _$SimpleClassNullableOfDoubleNullableFromJson(Map<String, dynamic> json) => - SimpleClassNullableOfDoubleNullable( - (json['value'] as List<dynamic>?) - ?.map((e) => (e as num?)?.toDouble()), - ); +_$SimpleClassNullableOfDoubleNullableFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfDoubleNullable( + (json['value'] as List<dynamic>?)?.map((e) => (e as num?)?.toDouble()), + ); Map<String, dynamic> _$SimpleClassNullableOfDoubleNullableToJson( - SimpleClassNullableOfDoubleNullable instance) => - <String, dynamic>{ - 'value': instance.value?.toList(), - }; + SimpleClassNullableOfDoubleNullable instance, +) => <String, dynamic>{'value': instance.value?.toList()}; SimpleClassOfDuration _$SimpleClassOfDurationFromJson( - Map<String, dynamic> json) => - SimpleClassOfDuration( - (json['value'] as List<dynamic>) - .map((e) => Duration(microseconds: (e as num).toInt())), - ); + Map<String, dynamic> json, +) => SimpleClassOfDuration( + (json['value'] as List<dynamic>).map( + (e) => Duration(microseconds: (e as num).toInt()), + ), +); Map<String, dynamic> _$SimpleClassOfDurationToJson( - SimpleClassOfDuration instance) => - <String, dynamic>{ - 'value': instance.value.map((e) => e.inMicroseconds).toList(), - }; + SimpleClassOfDuration instance, +) => <String, dynamic>{ + 'value': instance.value.map((e) => e.inMicroseconds).toList(), +}; SimpleClassNullableOfDuration _$SimpleClassNullableOfDurationFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDuration( - (json['value'] as List<dynamic>?) - ?.map((e) => Duration(microseconds: (e as num).toInt())), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfDuration( + (json['value'] as List<dynamic>?)?.map( + (e) => Duration(microseconds: (e as num).toInt()), + ), +); Map<String, dynamic> _$SimpleClassNullableOfDurationToJson( - SimpleClassNullableOfDuration instance) => - <String, dynamic>{ - 'value': instance.value?.map((e) => e.inMicroseconds).toList(), - }; + SimpleClassNullableOfDuration instance, +) => <String, dynamic>{ + 'value': instance.value?.map((e) => e.inMicroseconds).toList(), +}; SimpleClassOfDurationNullable _$SimpleClassOfDurationNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfDurationNullable( - (json['value'] as List<dynamic>).map( - (e) => e == null ? null : Duration(microseconds: (e as num).toInt())), - ); + Map<String, dynamic> json, +) => SimpleClassOfDurationNullable( + (json['value'] as List<dynamic>).map( + (e) => e == null ? null : Duration(microseconds: (e as num).toInt()), + ), +); Map<String, dynamic> _$SimpleClassOfDurationNullableToJson( - SimpleClassOfDurationNullable instance) => - <String, dynamic>{ - 'value': instance.value.map((e) => e?.inMicroseconds).toList(), - }; + SimpleClassOfDurationNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map((e) => e?.inMicroseconds).toList(), +}; SimpleClassNullableOfDurationNullable - _$SimpleClassNullableOfDurationNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDurationNullable( - (json['value'] as List<dynamic>?)?.map((e) => - e == null ? null : Duration(microseconds: (e as num).toInt())), - ); +_$SimpleClassNullableOfDurationNullableFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfDurationNullable( + (json['value'] as List<dynamic>?)?.map( + (e) => e == null ? null : Duration(microseconds: (e as num).toInt()), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfDurationNullableToJson( - SimpleClassNullableOfDurationNullable instance) => - <String, dynamic>{ - 'value': instance.value?.map((e) => e?.inMicroseconds).toList(), - }; + SimpleClassNullableOfDurationNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map((e) => e?.inMicroseconds).toList(), +}; SimpleClassOfDynamic _$SimpleClassOfDynamicFromJson( - Map<String, dynamic> json) => - SimpleClassOfDynamic( - json['value'] as List<dynamic>, - ); + Map<String, dynamic> json, +) => SimpleClassOfDynamic(json['value'] as List<dynamic>); Map<String, dynamic> _$SimpleClassOfDynamicToJson( - SimpleClassOfDynamic instance) => - <String, dynamic>{ - 'value': instance.value.toList(), - }; + SimpleClassOfDynamic instance, +) => <String, dynamic>{'value': instance.value.toList()}; SimpleClassNullableOfDynamic _$SimpleClassNullableOfDynamicFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDynamic( - json['value'] as List<dynamic>?, - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfDynamic(json['value'] as List<dynamic>?); Map<String, dynamic> _$SimpleClassNullableOfDynamicToJson( - SimpleClassNullableOfDynamic instance) => - <String, dynamic>{ - 'value': instance.value?.toList(), - }; + SimpleClassNullableOfDynamic instance, +) => <String, dynamic>{'value': instance.value?.toList()}; SimpleClassOfEnumType _$SimpleClassOfEnumTypeFromJson( - Map<String, dynamic> json) => - SimpleClassOfEnumType( - (json['value'] as List<dynamic>) - .map((e) => $enumDecode(_$EnumTypeEnumMap, e)), - ); + Map<String, dynamic> json, +) => SimpleClassOfEnumType( + (json['value'] as List<dynamic>).map( + (e) => $enumDecode(_$EnumTypeEnumMap, e), + ), +); Map<String, dynamic> _$SimpleClassOfEnumTypeToJson( - SimpleClassOfEnumType instance) => - <String, dynamic>{ - 'value': instance.value.map((e) => _$EnumTypeEnumMap[e]!).toList(), - }; + SimpleClassOfEnumType instance, +) => <String, dynamic>{ + 'value': instance.value.map((e) => _$EnumTypeEnumMap[e]!).toList(), +}; const _$EnumTypeEnumMap = { EnumType.alpha: 'alpha', @@ -325,124 +304,114 @@ const _$EnumTypeEnumMap = { }; SimpleClassNullableOfEnumType _$SimpleClassNullableOfEnumTypeFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfEnumType( - (json['value'] as List<dynamic>?) - ?.map((e) => $enumDecode(_$EnumTypeEnumMap, e)), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfEnumType( + (json['value'] as List<dynamic>?)?.map( + (e) => $enumDecode(_$EnumTypeEnumMap, e), + ), +); Map<String, dynamic> _$SimpleClassNullableOfEnumTypeToJson( - SimpleClassNullableOfEnumType instance) => - <String, dynamic>{ - 'value': instance.value?.map((e) => _$EnumTypeEnumMap[e]!).toList(), - }; + SimpleClassNullableOfEnumType instance, +) => <String, dynamic>{ + 'value': instance.value?.map((e) => _$EnumTypeEnumMap[e]!).toList(), +}; SimpleClassOfEnumTypeNullable _$SimpleClassOfEnumTypeNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfEnumTypeNullable( - (json['value'] as List<dynamic>) - .map((e) => $enumDecodeNullable(_$EnumTypeEnumMap, e)), - ); + Map<String, dynamic> json, +) => SimpleClassOfEnumTypeNullable( + (json['value'] as List<dynamic>).map( + (e) => $enumDecodeNullable(_$EnumTypeEnumMap, e), + ), +); Map<String, dynamic> _$SimpleClassOfEnumTypeNullableToJson( - SimpleClassOfEnumTypeNullable instance) => - <String, dynamic>{ - 'value': instance.value.map((e) => _$EnumTypeEnumMap[e]).toList(), - }; + SimpleClassOfEnumTypeNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map((e) => _$EnumTypeEnumMap[e]).toList(), +}; SimpleClassNullableOfEnumTypeNullable - _$SimpleClassNullableOfEnumTypeNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfEnumTypeNullable( - (json['value'] as List<dynamic>?) - ?.map((e) => $enumDecodeNullable(_$EnumTypeEnumMap, e)), - ); +_$SimpleClassNullableOfEnumTypeNullableFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfEnumTypeNullable( + (json['value'] as List<dynamic>?)?.map( + (e) => $enumDecodeNullable(_$EnumTypeEnumMap, e), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfEnumTypeNullableToJson( - SimpleClassNullableOfEnumTypeNullable instance) => - <String, dynamic>{ - 'value': instance.value?.map((e) => _$EnumTypeEnumMap[e]).toList(), - }; + SimpleClassNullableOfEnumTypeNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map((e) => _$EnumTypeEnumMap[e]).toList(), +}; SimpleClassOfFromJsonDynamicParam _$SimpleClassOfFromJsonDynamicParamFromJson( - Map<String, dynamic> json) => - SimpleClassOfFromJsonDynamicParam( - (json['value'] as List<dynamic>).map(FromJsonDynamicParam.fromJson), - ); + Map<String, dynamic> json, +) => SimpleClassOfFromJsonDynamicParam( + (json['value'] as List<dynamic>).map(FromJsonDynamicParam.fromJson), +); Map<String, dynamic> _$SimpleClassOfFromJsonDynamicParamToJson( - SimpleClassOfFromJsonDynamicParam instance) => - <String, dynamic>{ - 'value': instance.value.toList(), - }; + SimpleClassOfFromJsonDynamicParam instance, +) => <String, dynamic>{'value': instance.value.toList()}; SimpleClassNullableOfFromJsonDynamicParam - _$SimpleClassNullableOfFromJsonDynamicParamFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfFromJsonDynamicParam( - (json['value'] as List<dynamic>?)?.map(FromJsonDynamicParam.fromJson), - ); +_$SimpleClassNullableOfFromJsonDynamicParamFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfFromJsonDynamicParam( + (json['value'] as List<dynamic>?)?.map(FromJsonDynamicParam.fromJson), +); Map<String, dynamic> _$SimpleClassNullableOfFromJsonDynamicParamToJson( - SimpleClassNullableOfFromJsonDynamicParam instance) => - <String, dynamic>{ - 'value': instance.value?.toList(), - }; + SimpleClassNullableOfFromJsonDynamicParam instance, +) => <String, dynamic>{'value': instance.value?.toList()}; SimpleClassOfFromJsonNullableObjectParam - _$SimpleClassOfFromJsonNullableObjectParamFromJson( - Map<String, dynamic> json) => - SimpleClassOfFromJsonNullableObjectParam( - (json['value'] as List<dynamic>) - .map(FromJsonNullableObjectParam.fromJson), - ); +_$SimpleClassOfFromJsonNullableObjectParamFromJson(Map<String, dynamic> json) => + SimpleClassOfFromJsonNullableObjectParam( + (json['value'] as List<dynamic>).map( + FromJsonNullableObjectParam.fromJson, + ), + ); Map<String, dynamic> _$SimpleClassOfFromJsonNullableObjectParamToJson( - SimpleClassOfFromJsonNullableObjectParam instance) => - <String, dynamic>{ - 'value': instance.value.toList(), - }; + SimpleClassOfFromJsonNullableObjectParam instance, +) => <String, dynamic>{'value': instance.value.toList()}; SimpleClassNullableOfFromJsonNullableObjectParam - _$SimpleClassNullableOfFromJsonNullableObjectParamFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfFromJsonNullableObjectParam( - (json['value'] as List<dynamic>?) - ?.map(FromJsonNullableObjectParam.fromJson), - ); +_$SimpleClassNullableOfFromJsonNullableObjectParamFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfFromJsonNullableObjectParam( + (json['value'] as List<dynamic>?)?.map(FromJsonNullableObjectParam.fromJson), +); Map<String, dynamic> _$SimpleClassNullableOfFromJsonNullableObjectParamToJson( - SimpleClassNullableOfFromJsonNullableObjectParam instance) => - <String, dynamic>{ - 'value': instance.value?.toList(), - }; + SimpleClassNullableOfFromJsonNullableObjectParam instance, +) => <String, dynamic>{'value': instance.value?.toList()}; SimpleClassOfFromJsonObjectParam _$SimpleClassOfFromJsonObjectParamFromJson( - Map<String, dynamic> json) => - SimpleClassOfFromJsonObjectParam( - (json['value'] as List<dynamic>) - .map((e) => FromJsonObjectParam.fromJson(e as Object)), - ); + Map<String, dynamic> json, +) => SimpleClassOfFromJsonObjectParam( + (json['value'] as List<dynamic>).map( + (e) => FromJsonObjectParam.fromJson(e as Object), + ), +); Map<String, dynamic> _$SimpleClassOfFromJsonObjectParamToJson( - SimpleClassOfFromJsonObjectParam instance) => - <String, dynamic>{ - 'value': instance.value.toList(), - }; + SimpleClassOfFromJsonObjectParam instance, +) => <String, dynamic>{'value': instance.value.toList()}; SimpleClassNullableOfFromJsonObjectParam - _$SimpleClassNullableOfFromJsonObjectParamFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfFromJsonObjectParam( - (json['value'] as List<dynamic>?) - ?.map((e) => FromJsonObjectParam.fromJson(e as Object)), - ); +_$SimpleClassNullableOfFromJsonObjectParamFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfFromJsonObjectParam( + (json['value'] as List<dynamic>?)?.map( + (e) => FromJsonObjectParam.fromJson(e as Object), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfFromJsonObjectParamToJson( - SimpleClassNullableOfFromJsonObjectParam instance) => - <String, dynamic>{ - 'value': instance.value?.toList(), - }; + SimpleClassNullableOfFromJsonObjectParam instance, +) => <String, dynamic>{'value': instance.value?.toList()}; SimpleClassOfInt _$SimpleClassOfIntFromJson(Map<String, dynamic> json) => SimpleClassOfInt( @@ -450,91 +419,73 @@ SimpleClassOfInt _$SimpleClassOfIntFromJson(Map<String, dynamic> json) => ); Map<String, dynamic> _$SimpleClassOfIntToJson(SimpleClassOfInt instance) => - <String, dynamic>{ - 'value': instance.value.toList(), - }; + <String, dynamic>{'value': instance.value.toList()}; SimpleClassNullableOfInt _$SimpleClassNullableOfIntFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfInt( - (json['value'] as List<dynamic>?)?.map((e) => (e as num).toInt()), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfInt( + (json['value'] as List<dynamic>?)?.map((e) => (e as num).toInt()), +); Map<String, dynamic> _$SimpleClassNullableOfIntToJson( - SimpleClassNullableOfInt instance) => - <String, dynamic>{ - 'value': instance.value?.toList(), - }; + SimpleClassNullableOfInt instance, +) => <String, dynamic>{'value': instance.value?.toList()}; SimpleClassOfIntNullable _$SimpleClassOfIntNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfIntNullable( - (json['value'] as List<dynamic>).map((e) => (e as num?)?.toInt()), - ); + Map<String, dynamic> json, +) => SimpleClassOfIntNullable( + (json['value'] as List<dynamic>).map((e) => (e as num?)?.toInt()), +); Map<String, dynamic> _$SimpleClassOfIntNullableToJson( - SimpleClassOfIntNullable instance) => - <String, dynamic>{ - 'value': instance.value.toList(), - }; + SimpleClassOfIntNullable instance, +) => <String, dynamic>{'value': instance.value.toList()}; SimpleClassNullableOfIntNullable _$SimpleClassNullableOfIntNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfIntNullable( - (json['value'] as List<dynamic>?)?.map((e) => (e as num?)?.toInt()), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfIntNullable( + (json['value'] as List<dynamic>?)?.map((e) => (e as num?)?.toInt()), +); Map<String, dynamic> _$SimpleClassNullableOfIntNullableToJson( - SimpleClassNullableOfIntNullable instance) => - <String, dynamic>{ - 'value': instance.value?.toList(), - }; + SimpleClassNullableOfIntNullable instance, +) => <String, dynamic>{'value': instance.value?.toList()}; SimpleClassOfNum _$SimpleClassOfNumFromJson(Map<String, dynamic> json) => - SimpleClassOfNum( - (json['value'] as List<dynamic>).map((e) => e as num), - ); + SimpleClassOfNum((json['value'] as List<dynamic>).map((e) => e as num)); Map<String, dynamic> _$SimpleClassOfNumToJson(SimpleClassOfNum instance) => - <String, dynamic>{ - 'value': instance.value.toList(), - }; + <String, dynamic>{'value': instance.value.toList()}; SimpleClassNullableOfNum _$SimpleClassNullableOfNumFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfNum( - (json['value'] as List<dynamic>?)?.map((e) => e as num), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfNum( + (json['value'] as List<dynamic>?)?.map((e) => e as num), +); Map<String, dynamic> _$SimpleClassNullableOfNumToJson( - SimpleClassNullableOfNum instance) => - <String, dynamic>{ - 'value': instance.value?.toList(), - }; + SimpleClassNullableOfNum instance, +) => <String, dynamic>{'value': instance.value?.toList()}; SimpleClassOfNumNullable _$SimpleClassOfNumNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfNumNullable( - (json['value'] as List<dynamic>).map((e) => e as num?), - ); + Map<String, dynamic> json, +) => SimpleClassOfNumNullable( + (json['value'] as List<dynamic>).map((e) => e as num?), +); Map<String, dynamic> _$SimpleClassOfNumNullableToJson( - SimpleClassOfNumNullable instance) => - <String, dynamic>{ - 'value': instance.value.toList(), - }; + SimpleClassOfNumNullable instance, +) => <String, dynamic>{'value': instance.value.toList()}; SimpleClassNullableOfNumNullable _$SimpleClassNullableOfNumNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfNumNullable( - (json['value'] as List<dynamic>?)?.map((e) => e as num?), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfNumNullable( + (json['value'] as List<dynamic>?)?.map((e) => e as num?), +); Map<String, dynamic> _$SimpleClassNullableOfNumNullableToJson( - SimpleClassNullableOfNumNullable instance) => - <String, dynamic>{ - 'value': instance.value?.toList(), - }; + SimpleClassNullableOfNumNullable instance, +) => <String, dynamic>{'value': instance.value?.toList()}; SimpleClassOfObject _$SimpleClassOfObjectFromJson(Map<String, dynamic> json) => SimpleClassOfObject( @@ -542,101 +493,84 @@ SimpleClassOfObject _$SimpleClassOfObjectFromJson(Map<String, dynamic> json) => ); Map<String, dynamic> _$SimpleClassOfObjectToJson( - SimpleClassOfObject instance) => - <String, dynamic>{ - 'value': instance.value.toList(), - }; + SimpleClassOfObject instance, +) => <String, dynamic>{'value': instance.value.toList()}; SimpleClassNullableOfObject _$SimpleClassNullableOfObjectFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfObject( - (json['value'] as List<dynamic>?)?.map((e) => e as Object), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfObject( + (json['value'] as List<dynamic>?)?.map((e) => e as Object), +); Map<String, dynamic> _$SimpleClassNullableOfObjectToJson( - SimpleClassNullableOfObject instance) => - <String, dynamic>{ - 'value': instance.value?.toList(), - }; + SimpleClassNullableOfObject instance, +) => <String, dynamic>{'value': instance.value?.toList()}; SimpleClassOfObjectNullable _$SimpleClassOfObjectNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfObjectNullable( - json['value'] as List<dynamic>, - ); + Map<String, dynamic> json, +) => SimpleClassOfObjectNullable(json['value'] as List<dynamic>); Map<String, dynamic> _$SimpleClassOfObjectNullableToJson( - SimpleClassOfObjectNullable instance) => - <String, dynamic>{ - 'value': instance.value.toList(), - }; + SimpleClassOfObjectNullable instance, +) => <String, dynamic>{'value': instance.value.toList()}; SimpleClassNullableOfObjectNullable - _$SimpleClassNullableOfObjectNullableFromJson(Map<String, dynamic> json) => - SimpleClassNullableOfObjectNullable( - json['value'] as List<dynamic>?, - ); +_$SimpleClassNullableOfObjectNullableFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfObjectNullable(json['value'] as List<dynamic>?); Map<String, dynamic> _$SimpleClassNullableOfObjectNullableToJson( - SimpleClassNullableOfObjectNullable instance) => - <String, dynamic>{ - 'value': instance.value?.toList(), - }; + SimpleClassNullableOfObjectNullable instance, +) => <String, dynamic>{'value': instance.value?.toList()}; SimpleClassOfRecord _$SimpleClassOfRecordFromJson(Map<String, dynamic> json) => SimpleClassOfRecord( - (json['value'] as List<dynamic>).map((e) => _$recordConvert( - e, - ($jsonValue) => ( - ($jsonValue[r'$1'] as num).toInt(), - $jsonValue[r'$2'] as String, - truth: $jsonValue['truth'] as bool, - ), - )), + (json['value'] as List<dynamic>).map( + (e) => _$recordConvert( + e, + ($jsonValue) => ( + ($jsonValue[r'$1'] as num).toInt(), + $jsonValue[r'$2'] as String, + truth: $jsonValue['truth'] as bool, + ), + ), + ), ); Map<String, dynamic> _$SimpleClassOfRecordToJson( - SimpleClassOfRecord instance) => - <String, dynamic>{ - 'value': instance.value - .map((e) => <String, dynamic>{ - r'$1': e.$1, - r'$2': e.$2, - 'truth': e.truth, - }) - .toList(), - }; + SimpleClassOfRecord instance, +) => <String, dynamic>{ + 'value': instance.value + .map((e) => <String, dynamic>{r'$1': e.$1, r'$2': e.$2, 'truth': e.truth}) + .toList(), +}; -$Rec _$recordConvert<$Rec>( - Object? value, - $Rec Function(Map) convert, -) => +$Rec _$recordConvert<$Rec>(Object? value, $Rec Function(Map) convert) => convert(value as Map<String, dynamic>); SimpleClassNullableOfRecord _$SimpleClassNullableOfRecordFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfRecord( - (json['value'] as List<dynamic>?)?.map((e) => _$recordConvert( - e, - ($jsonValue) => ( - ($jsonValue[r'$1'] as num).toInt(), - $jsonValue[r'$2'] as String, - truth: $jsonValue['truth'] as bool, - ), - )), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfRecord( + (json['value'] as List<dynamic>?)?.map( + (e) => _$recordConvert( + e, + ($jsonValue) => ( + ($jsonValue[r'$1'] as num).toInt(), + $jsonValue[r'$2'] as String, + truth: $jsonValue['truth'] as bool, + ), + ), + ), +); Map<String, dynamic> _$SimpleClassNullableOfRecordToJson( - SimpleClassNullableOfRecord instance) => - <String, dynamic>{ - 'value': instance.value - ?.map((e) => <String, dynamic>{ - r'$1': e.$1, - r'$2': e.$2, - 'truth': e.truth, - }) - .toList(), - }; + SimpleClassNullableOfRecord instance, +) => <String, dynamic>{ + 'value': instance.value + ?.map( + (e) => <String, dynamic>{r'$1': e.$1, r'$2': e.$2, 'truth': e.truth}, + ) + .toList(), +}; SimpleClassOfString _$SimpleClassOfStringFromJson(Map<String, dynamic> json) => SimpleClassOfString( @@ -644,46 +578,38 @@ SimpleClassOfString _$SimpleClassOfStringFromJson(Map<String, dynamic> json) => ); Map<String, dynamic> _$SimpleClassOfStringToJson( - SimpleClassOfString instance) => - <String, dynamic>{ - 'value': instance.value.toList(), - }; + SimpleClassOfString instance, +) => <String, dynamic>{'value': instance.value.toList()}; SimpleClassNullableOfString _$SimpleClassNullableOfStringFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfString( - (json['value'] as List<dynamic>?)?.map((e) => e as String), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfString( + (json['value'] as List<dynamic>?)?.map((e) => e as String), +); Map<String, dynamic> _$SimpleClassNullableOfStringToJson( - SimpleClassNullableOfString instance) => - <String, dynamic>{ - 'value': instance.value?.toList(), - }; + SimpleClassNullableOfString instance, +) => <String, dynamic>{'value': instance.value?.toList()}; SimpleClassOfStringNullable _$SimpleClassOfStringNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfStringNullable( - (json['value'] as List<dynamic>).map((e) => e as String?), - ); + Map<String, dynamic> json, +) => SimpleClassOfStringNullable( + (json['value'] as List<dynamic>).map((e) => e as String?), +); Map<String, dynamic> _$SimpleClassOfStringNullableToJson( - SimpleClassOfStringNullable instance) => - <String, dynamic>{ - 'value': instance.value.toList(), - }; + SimpleClassOfStringNullable instance, +) => <String, dynamic>{'value': instance.value.toList()}; SimpleClassNullableOfStringNullable - _$SimpleClassNullableOfStringNullableFromJson(Map<String, dynamic> json) => - SimpleClassNullableOfStringNullable( - (json['value'] as List<dynamic>?)?.map((e) => e as String?), - ); +_$SimpleClassNullableOfStringNullableFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfStringNullable( + (json['value'] as List<dynamic>?)?.map((e) => e as String?), + ); Map<String, dynamic> _$SimpleClassNullableOfStringNullableToJson( - SimpleClassNullableOfStringNullable instance) => - <String, dynamic>{ - 'value': instance.value?.toList(), - }; + SimpleClassNullableOfStringNullable instance, +) => <String, dynamic>{'value': instance.value?.toList()}; SimpleClassOfUri _$SimpleClassOfUriFromJson(Map<String, dynamic> json) => SimpleClassOfUri( @@ -696,39 +622,41 @@ Map<String, dynamic> _$SimpleClassOfUriToJson(SimpleClassOfUri instance) => }; SimpleClassNullableOfUri _$SimpleClassNullableOfUriFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfUri( - (json['value'] as List<dynamic>?)?.map((e) => Uri.parse(e as String)), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfUri( + (json['value'] as List<dynamic>?)?.map((e) => Uri.parse(e as String)), +); Map<String, dynamic> _$SimpleClassNullableOfUriToJson( - SimpleClassNullableOfUri instance) => - <String, dynamic>{ - 'value': instance.value?.map((e) => e.toString()).toList(), - }; + SimpleClassNullableOfUri instance, +) => <String, dynamic>{ + 'value': instance.value?.map((e) => e.toString()).toList(), +}; SimpleClassOfUriNullable _$SimpleClassOfUriNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfUriNullable( - (json['value'] as List<dynamic>) - .map((e) => e == null ? null : Uri.parse(e as String)), - ); + Map<String, dynamic> json, +) => SimpleClassOfUriNullable( + (json['value'] as List<dynamic>).map( + (e) => e == null ? null : Uri.parse(e as String), + ), +); Map<String, dynamic> _$SimpleClassOfUriNullableToJson( - SimpleClassOfUriNullable instance) => - <String, dynamic>{ - 'value': instance.value.map((e) => e?.toString()).toList(), - }; + SimpleClassOfUriNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map((e) => e?.toString()).toList(), +}; SimpleClassNullableOfUriNullable _$SimpleClassNullableOfUriNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfUriNullable( - (json['value'] as List<dynamic>?) - ?.map((e) => e == null ? null : Uri.parse(e as String)), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfUriNullable( + (json['value'] as List<dynamic>?)?.map( + (e) => e == null ? null : Uri.parse(e as String), + ), +); Map<String, dynamic> _$SimpleClassNullableOfUriNullableToJson( - SimpleClassNullableOfUriNullable instance) => - <String, dynamic>{ - 'value': instance.value?.map((e) => e?.toString()).toList(), - }; + SimpleClassNullableOfUriNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map((e) => e?.toString()).toList(), +}; diff --git a/json_serializable/test/supported_types/input.type_list.dart b/json_serializable/test/supported_types/input.type_list.dart index 205e97195..dd23ca6dc 100644 --- a/json_serializable/test/supported_types/input.type_list.dart +++ b/json_serializable/test/supported_types/input.type_list.dart @@ -14,10 +14,7 @@ class SimpleClass { @JsonKey(defaultValue: [42, true, false, null]) List withDefault; - SimpleClass( - this.value, - this.withDefault, - ); + SimpleClass(this.value, this.withDefault); factory SimpleClass.fromJson(Map<String, Object?> json) => _$SimpleClassFromJson(json); @@ -32,10 +29,7 @@ class SimpleClassNullable { @JsonKey(defaultValue: [42, true, false, null]) List? withDefault; - SimpleClassNullable( - this.value, - this.withDefault, - ); + SimpleClassNullable(this.value, this.withDefault); factory SimpleClassNullable.fromJson(Map<String, Object?> json) => _$SimpleClassNullableFromJson(json); @@ -47,9 +41,7 @@ class SimpleClassNullable { class SimpleClassOfBigInt { final List<BigInt> value; - SimpleClassOfBigInt( - this.value, - ); + SimpleClassOfBigInt(this.value); factory SimpleClassOfBigInt.fromJson(Map<String, Object?> json) => _$SimpleClassOfBigIntFromJson(json); @@ -61,9 +53,7 @@ class SimpleClassOfBigInt { class SimpleClassNullableOfBigInt { final List<BigInt>? value; - SimpleClassNullableOfBigInt( - this.value, - ); + SimpleClassNullableOfBigInt(this.value); factory SimpleClassNullableOfBigInt.fromJson(Map<String, Object?> json) => _$SimpleClassNullableOfBigIntFromJson(json); @@ -75,9 +65,7 @@ class SimpleClassNullableOfBigInt { class SimpleClassOfBigIntNullable { final List<BigInt?> value; - SimpleClassOfBigIntNullable( - this.value, - ); + SimpleClassOfBigIntNullable(this.value); factory SimpleClassOfBigIntNullable.fromJson(Map<String, Object?> json) => _$SimpleClassOfBigIntNullableFromJson(json); @@ -89,13 +77,11 @@ class SimpleClassOfBigIntNullable { class SimpleClassNullableOfBigIntNullable { final List<BigInt?>? value; - SimpleClassNullableOfBigIntNullable( - this.value, - ); + SimpleClassNullableOfBigIntNullable(this.value); factory SimpleClassNullableOfBigIntNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfBigIntNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfBigIntNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfBigIntNullableToJson(this); @@ -105,9 +91,7 @@ class SimpleClassNullableOfBigIntNullable { class SimpleClassOfBool { final List<bool> value; - SimpleClassOfBool( - this.value, - ); + SimpleClassOfBool(this.value); factory SimpleClassOfBool.fromJson(Map<String, Object?> json) => _$SimpleClassOfBoolFromJson(json); @@ -119,9 +103,7 @@ class SimpleClassOfBool { class SimpleClassNullableOfBool { final List<bool>? value; - SimpleClassNullableOfBool( - this.value, - ); + SimpleClassNullableOfBool(this.value); factory SimpleClassNullableOfBool.fromJson(Map<String, Object?> json) => _$SimpleClassNullableOfBoolFromJson(json); @@ -133,9 +115,7 @@ class SimpleClassNullableOfBool { class SimpleClassOfBoolNullable { final List<bool?> value; - SimpleClassOfBoolNullable( - this.value, - ); + SimpleClassOfBoolNullable(this.value); factory SimpleClassOfBoolNullable.fromJson(Map<String, Object?> json) => _$SimpleClassOfBoolNullableFromJson(json); @@ -147,13 +127,11 @@ class SimpleClassOfBoolNullable { class SimpleClassNullableOfBoolNullable { final List<bool?>? value; - SimpleClassNullableOfBoolNullable( - this.value, - ); + SimpleClassNullableOfBoolNullable(this.value); factory SimpleClassNullableOfBoolNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfBoolNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfBoolNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfBoolNullableToJson(this); @@ -163,9 +141,7 @@ class SimpleClassNullableOfBoolNullable { class SimpleClassOfDateTime { final List<DateTime> value; - SimpleClassOfDateTime( - this.value, - ); + SimpleClassOfDateTime(this.value); factory SimpleClassOfDateTime.fromJson(Map<String, Object?> json) => _$SimpleClassOfDateTimeFromJson(json); @@ -177,9 +153,7 @@ class SimpleClassOfDateTime { class SimpleClassNullableOfDateTime { final List<DateTime>? value; - SimpleClassNullableOfDateTime( - this.value, - ); + SimpleClassNullableOfDateTime(this.value); factory SimpleClassNullableOfDateTime.fromJson(Map<String, Object?> json) => _$SimpleClassNullableOfDateTimeFromJson(json); @@ -191,9 +165,7 @@ class SimpleClassNullableOfDateTime { class SimpleClassOfDateTimeNullable { final List<DateTime?> value; - SimpleClassOfDateTimeNullable( - this.value, - ); + SimpleClassOfDateTimeNullable(this.value); factory SimpleClassOfDateTimeNullable.fromJson(Map<String, Object?> json) => _$SimpleClassOfDateTimeNullableFromJson(json); @@ -205,13 +177,11 @@ class SimpleClassOfDateTimeNullable { class SimpleClassNullableOfDateTimeNullable { final List<DateTime?>? value; - SimpleClassNullableOfDateTimeNullable( - this.value, - ); + SimpleClassNullableOfDateTimeNullable(this.value); factory SimpleClassNullableOfDateTimeNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfDateTimeNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfDateTimeNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfDateTimeNullableToJson(this); @@ -221,9 +191,7 @@ class SimpleClassNullableOfDateTimeNullable { class SimpleClassOfDouble { final List<double> value; - SimpleClassOfDouble( - this.value, - ); + SimpleClassOfDouble(this.value); factory SimpleClassOfDouble.fromJson(Map<String, Object?> json) => _$SimpleClassOfDoubleFromJson(json); @@ -235,9 +203,7 @@ class SimpleClassOfDouble { class SimpleClassNullableOfDouble { final List<double>? value; - SimpleClassNullableOfDouble( - this.value, - ); + SimpleClassNullableOfDouble(this.value); factory SimpleClassNullableOfDouble.fromJson(Map<String, Object?> json) => _$SimpleClassNullableOfDoubleFromJson(json); @@ -249,9 +215,7 @@ class SimpleClassNullableOfDouble { class SimpleClassOfDoubleNullable { final List<double?> value; - SimpleClassOfDoubleNullable( - this.value, - ); + SimpleClassOfDoubleNullable(this.value); factory SimpleClassOfDoubleNullable.fromJson(Map<String, Object?> json) => _$SimpleClassOfDoubleNullableFromJson(json); @@ -263,13 +227,11 @@ class SimpleClassOfDoubleNullable { class SimpleClassNullableOfDoubleNullable { final List<double?>? value; - SimpleClassNullableOfDoubleNullable( - this.value, - ); + SimpleClassNullableOfDoubleNullable(this.value); factory SimpleClassNullableOfDoubleNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfDoubleNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfDoubleNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfDoubleNullableToJson(this); @@ -279,9 +241,7 @@ class SimpleClassNullableOfDoubleNullable { class SimpleClassOfDuration { final List<Duration> value; - SimpleClassOfDuration( - this.value, - ); + SimpleClassOfDuration(this.value); factory SimpleClassOfDuration.fromJson(Map<String, Object?> json) => _$SimpleClassOfDurationFromJson(json); @@ -293,9 +253,7 @@ class SimpleClassOfDuration { class SimpleClassNullableOfDuration { final List<Duration>? value; - SimpleClassNullableOfDuration( - this.value, - ); + SimpleClassNullableOfDuration(this.value); factory SimpleClassNullableOfDuration.fromJson(Map<String, Object?> json) => _$SimpleClassNullableOfDurationFromJson(json); @@ -307,9 +265,7 @@ class SimpleClassNullableOfDuration { class SimpleClassOfDurationNullable { final List<Duration?> value; - SimpleClassOfDurationNullable( - this.value, - ); + SimpleClassOfDurationNullable(this.value); factory SimpleClassOfDurationNullable.fromJson(Map<String, Object?> json) => _$SimpleClassOfDurationNullableFromJson(json); @@ -321,13 +277,11 @@ class SimpleClassOfDurationNullable { class SimpleClassNullableOfDurationNullable { final List<Duration?>? value; - SimpleClassNullableOfDurationNullable( - this.value, - ); + SimpleClassNullableOfDurationNullable(this.value); factory SimpleClassNullableOfDurationNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfDurationNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfDurationNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfDurationNullableToJson(this); @@ -337,9 +291,7 @@ class SimpleClassNullableOfDurationNullable { class SimpleClassOfDynamic { final List<dynamic> value; - SimpleClassOfDynamic( - this.value, - ); + SimpleClassOfDynamic(this.value); factory SimpleClassOfDynamic.fromJson(Map<String, Object?> json) => _$SimpleClassOfDynamicFromJson(json); @@ -351,9 +303,7 @@ class SimpleClassOfDynamic { class SimpleClassNullableOfDynamic { final List<dynamic>? value; - SimpleClassNullableOfDynamic( - this.value, - ); + SimpleClassNullableOfDynamic(this.value); factory SimpleClassNullableOfDynamic.fromJson(Map<String, Object?> json) => _$SimpleClassNullableOfDynamicFromJson(json); @@ -365,9 +315,7 @@ class SimpleClassNullableOfDynamic { class SimpleClassOfEnumType { final List<EnumType> value; - SimpleClassOfEnumType( - this.value, - ); + SimpleClassOfEnumType(this.value); factory SimpleClassOfEnumType.fromJson(Map<String, Object?> json) => _$SimpleClassOfEnumTypeFromJson(json); @@ -379,9 +327,7 @@ class SimpleClassOfEnumType { class SimpleClassNullableOfEnumType { final List<EnumType>? value; - SimpleClassNullableOfEnumType( - this.value, - ); + SimpleClassNullableOfEnumType(this.value); factory SimpleClassNullableOfEnumType.fromJson(Map<String, Object?> json) => _$SimpleClassNullableOfEnumTypeFromJson(json); @@ -393,9 +339,7 @@ class SimpleClassNullableOfEnumType { class SimpleClassOfEnumTypeNullable { final List<EnumType?> value; - SimpleClassOfEnumTypeNullable( - this.value, - ); + SimpleClassOfEnumTypeNullable(this.value); factory SimpleClassOfEnumTypeNullable.fromJson(Map<String, Object?> json) => _$SimpleClassOfEnumTypeNullableFromJson(json); @@ -407,13 +351,11 @@ class SimpleClassOfEnumTypeNullable { class SimpleClassNullableOfEnumTypeNullable { final List<EnumType?>? value; - SimpleClassNullableOfEnumTypeNullable( - this.value, - ); + SimpleClassNullableOfEnumTypeNullable(this.value); factory SimpleClassNullableOfEnumTypeNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfEnumTypeNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfEnumTypeNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfEnumTypeNullableToJson(this); @@ -423,13 +365,11 @@ class SimpleClassNullableOfEnumTypeNullable { class SimpleClassOfFromJsonDynamicParam { final List<FromJsonDynamicParam> value; - SimpleClassOfFromJsonDynamicParam( - this.value, - ); + SimpleClassOfFromJsonDynamicParam(this.value); factory SimpleClassOfFromJsonDynamicParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfFromJsonDynamicParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfFromJsonDynamicParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfFromJsonDynamicParamToJson(this); @@ -439,13 +379,11 @@ class SimpleClassOfFromJsonDynamicParam { class SimpleClassNullableOfFromJsonDynamicParam { final List<FromJsonDynamicParam>? value; - SimpleClassNullableOfFromJsonDynamicParam( - this.value, - ); + SimpleClassNullableOfFromJsonDynamicParam(this.value); factory SimpleClassNullableOfFromJsonDynamicParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfFromJsonDynamicParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfFromJsonDynamicParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfFromJsonDynamicParamToJson(this); @@ -455,13 +393,11 @@ class SimpleClassNullableOfFromJsonDynamicParam { class SimpleClassOfFromJsonNullableObjectParam { final List<FromJsonNullableObjectParam> value; - SimpleClassOfFromJsonNullableObjectParam( - this.value, - ); + SimpleClassOfFromJsonNullableObjectParam(this.value); factory SimpleClassOfFromJsonNullableObjectParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfFromJsonNullableObjectParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfFromJsonNullableObjectParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfFromJsonNullableObjectParamToJson(this); @@ -471,13 +407,11 @@ class SimpleClassOfFromJsonNullableObjectParam { class SimpleClassNullableOfFromJsonNullableObjectParam { final List<FromJsonNullableObjectParam>? value; - SimpleClassNullableOfFromJsonNullableObjectParam( - this.value, - ); + SimpleClassNullableOfFromJsonNullableObjectParam(this.value); factory SimpleClassNullableOfFromJsonNullableObjectParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfFromJsonNullableObjectParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfFromJsonNullableObjectParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfFromJsonNullableObjectParamToJson(this); @@ -487,13 +421,11 @@ class SimpleClassNullableOfFromJsonNullableObjectParam { class SimpleClassOfFromJsonObjectParam { final List<FromJsonObjectParam> value; - SimpleClassOfFromJsonObjectParam( - this.value, - ); + SimpleClassOfFromJsonObjectParam(this.value); factory SimpleClassOfFromJsonObjectParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfFromJsonObjectParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfFromJsonObjectParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfFromJsonObjectParamToJson(this); @@ -503,13 +435,11 @@ class SimpleClassOfFromJsonObjectParam { class SimpleClassNullableOfFromJsonObjectParam { final List<FromJsonObjectParam>? value; - SimpleClassNullableOfFromJsonObjectParam( - this.value, - ); + SimpleClassNullableOfFromJsonObjectParam(this.value); factory SimpleClassNullableOfFromJsonObjectParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfFromJsonObjectParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfFromJsonObjectParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfFromJsonObjectParamToJson(this); @@ -519,9 +449,7 @@ class SimpleClassNullableOfFromJsonObjectParam { class SimpleClassOfInt { final List<int> value; - SimpleClassOfInt( - this.value, - ); + SimpleClassOfInt(this.value); factory SimpleClassOfInt.fromJson(Map<String, Object?> json) => _$SimpleClassOfIntFromJson(json); @@ -533,9 +461,7 @@ class SimpleClassOfInt { class SimpleClassNullableOfInt { final List<int>? value; - SimpleClassNullableOfInt( - this.value, - ); + SimpleClassNullableOfInt(this.value); factory SimpleClassNullableOfInt.fromJson(Map<String, Object?> json) => _$SimpleClassNullableOfIntFromJson(json); @@ -547,9 +473,7 @@ class SimpleClassNullableOfInt { class SimpleClassOfIntNullable { final List<int?> value; - SimpleClassOfIntNullable( - this.value, - ); + SimpleClassOfIntNullable(this.value); factory SimpleClassOfIntNullable.fromJson(Map<String, Object?> json) => _$SimpleClassOfIntNullableFromJson(json); @@ -561,13 +485,11 @@ class SimpleClassOfIntNullable { class SimpleClassNullableOfIntNullable { final List<int?>? value; - SimpleClassNullableOfIntNullable( - this.value, - ); + SimpleClassNullableOfIntNullable(this.value); factory SimpleClassNullableOfIntNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfIntNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfIntNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfIntNullableToJson(this); @@ -577,9 +499,7 @@ class SimpleClassNullableOfIntNullable { class SimpleClassOfNum { final List<num> value; - SimpleClassOfNum( - this.value, - ); + SimpleClassOfNum(this.value); factory SimpleClassOfNum.fromJson(Map<String, Object?> json) => _$SimpleClassOfNumFromJson(json); @@ -591,9 +511,7 @@ class SimpleClassOfNum { class SimpleClassNullableOfNum { final List<num>? value; - SimpleClassNullableOfNum( - this.value, - ); + SimpleClassNullableOfNum(this.value); factory SimpleClassNullableOfNum.fromJson(Map<String, Object?> json) => _$SimpleClassNullableOfNumFromJson(json); @@ -605,9 +523,7 @@ class SimpleClassNullableOfNum { class SimpleClassOfNumNullable { final List<num?> value; - SimpleClassOfNumNullable( - this.value, - ); + SimpleClassOfNumNullable(this.value); factory SimpleClassOfNumNullable.fromJson(Map<String, Object?> json) => _$SimpleClassOfNumNullableFromJson(json); @@ -619,13 +535,11 @@ class SimpleClassOfNumNullable { class SimpleClassNullableOfNumNullable { final List<num?>? value; - SimpleClassNullableOfNumNullable( - this.value, - ); + SimpleClassNullableOfNumNullable(this.value); factory SimpleClassNullableOfNumNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfNumNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfNumNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfNumNullableToJson(this); @@ -635,9 +549,7 @@ class SimpleClassNullableOfNumNullable { class SimpleClassOfObject { final List<Object> value; - SimpleClassOfObject( - this.value, - ); + SimpleClassOfObject(this.value); factory SimpleClassOfObject.fromJson(Map<String, Object?> json) => _$SimpleClassOfObjectFromJson(json); @@ -649,9 +561,7 @@ class SimpleClassOfObject { class SimpleClassNullableOfObject { final List<Object>? value; - SimpleClassNullableOfObject( - this.value, - ); + SimpleClassNullableOfObject(this.value); factory SimpleClassNullableOfObject.fromJson(Map<String, Object?> json) => _$SimpleClassNullableOfObjectFromJson(json); @@ -663,9 +573,7 @@ class SimpleClassNullableOfObject { class SimpleClassOfObjectNullable { final List<Object?> value; - SimpleClassOfObjectNullable( - this.value, - ); + SimpleClassOfObjectNullable(this.value); factory SimpleClassOfObjectNullable.fromJson(Map<String, Object?> json) => _$SimpleClassOfObjectNullableFromJson(json); @@ -677,13 +585,11 @@ class SimpleClassOfObjectNullable { class SimpleClassNullableOfObjectNullable { final List<Object?>? value; - SimpleClassNullableOfObjectNullable( - this.value, - ); + SimpleClassNullableOfObjectNullable(this.value); factory SimpleClassNullableOfObjectNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfObjectNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfObjectNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfObjectNullableToJson(this); @@ -693,9 +599,7 @@ class SimpleClassNullableOfObjectNullable { class SimpleClassOfRecord { final List<(int, String, {bool truth})> value; - SimpleClassOfRecord( - this.value, - ); + SimpleClassOfRecord(this.value); factory SimpleClassOfRecord.fromJson(Map<String, Object?> json) => _$SimpleClassOfRecordFromJson(json); @@ -707,9 +611,7 @@ class SimpleClassOfRecord { class SimpleClassNullableOfRecord { final List<(int, String, {bool truth})>? value; - SimpleClassNullableOfRecord( - this.value, - ); + SimpleClassNullableOfRecord(this.value); factory SimpleClassNullableOfRecord.fromJson(Map<String, Object?> json) => _$SimpleClassNullableOfRecordFromJson(json); @@ -721,9 +623,7 @@ class SimpleClassNullableOfRecord { class SimpleClassOfString { final List<String> value; - SimpleClassOfString( - this.value, - ); + SimpleClassOfString(this.value); factory SimpleClassOfString.fromJson(Map<String, Object?> json) => _$SimpleClassOfStringFromJson(json); @@ -735,9 +635,7 @@ class SimpleClassOfString { class SimpleClassNullableOfString { final List<String>? value; - SimpleClassNullableOfString( - this.value, - ); + SimpleClassNullableOfString(this.value); factory SimpleClassNullableOfString.fromJson(Map<String, Object?> json) => _$SimpleClassNullableOfStringFromJson(json); @@ -749,9 +647,7 @@ class SimpleClassNullableOfString { class SimpleClassOfStringNullable { final List<String?> value; - SimpleClassOfStringNullable( - this.value, - ); + SimpleClassOfStringNullable(this.value); factory SimpleClassOfStringNullable.fromJson(Map<String, Object?> json) => _$SimpleClassOfStringNullableFromJson(json); @@ -763,13 +659,11 @@ class SimpleClassOfStringNullable { class SimpleClassNullableOfStringNullable { final List<String?>? value; - SimpleClassNullableOfStringNullable( - this.value, - ); + SimpleClassNullableOfStringNullable(this.value); factory SimpleClassNullableOfStringNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfStringNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfStringNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfStringNullableToJson(this); @@ -779,9 +673,7 @@ class SimpleClassNullableOfStringNullable { class SimpleClassOfUri { final List<Uri> value; - SimpleClassOfUri( - this.value, - ); + SimpleClassOfUri(this.value); factory SimpleClassOfUri.fromJson(Map<String, Object?> json) => _$SimpleClassOfUriFromJson(json); @@ -793,9 +685,7 @@ class SimpleClassOfUri { class SimpleClassNullableOfUri { final List<Uri>? value; - SimpleClassNullableOfUri( - this.value, - ); + SimpleClassNullableOfUri(this.value); factory SimpleClassNullableOfUri.fromJson(Map<String, Object?> json) => _$SimpleClassNullableOfUriFromJson(json); @@ -807,9 +697,7 @@ class SimpleClassNullableOfUri { class SimpleClassOfUriNullable { final List<Uri?> value; - SimpleClassOfUriNullable( - this.value, - ); + SimpleClassOfUriNullable(this.value); factory SimpleClassOfUriNullable.fromJson(Map<String, Object?> json) => _$SimpleClassOfUriNullableFromJson(json); @@ -821,13 +709,11 @@ class SimpleClassOfUriNullable { class SimpleClassNullableOfUriNullable { final List<Uri?>? value; - SimpleClassNullableOfUriNullable( - this.value, - ); + SimpleClassNullableOfUriNullable(this.value); factory SimpleClassNullableOfUriNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfUriNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfUriNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfUriNullableToJson(this); diff --git a/json_serializable/test/supported_types/input.type_list.g.dart b/json_serializable/test/supported_types/input.type_list.g.dart index f86a6d00c..c89d184e0 100644 --- a/json_serializable/test/supported_types/input.type_list.g.dart +++ b/json_serializable/test/supported_types/input.type_list.g.dart @@ -9,9 +9,9 @@ part of 'input.type_list.dart'; // ************************************************************************** SimpleClass _$SimpleClassFromJson(Map<String, dynamic> json) => SimpleClass( - json['value'] as List<dynamic>, - json['withDefault'] as List<dynamic>? ?? [42, true, false, null], - ); + json['value'] as List<dynamic>, + json['withDefault'] as List<dynamic>? ?? [42, true, false, null], +); Map<String, dynamic> _$SimpleClassToJson(SimpleClass instance) => <String, dynamic>{ @@ -26,11 +26,11 @@ SimpleClassNullable _$SimpleClassNullableFromJson(Map<String, dynamic> json) => ); Map<String, dynamic> _$SimpleClassNullableToJson( - SimpleClassNullable instance) => - <String, dynamic>{ - 'value': instance.value, - 'withDefault': instance.withDefault, - }; + SimpleClassNullable instance, +) => <String, dynamic>{ + 'value': instance.value, + 'withDefault': instance.withDefault, +}; SimpleClassOfBigInt _$SimpleClassOfBigIntFromJson(Map<String, dynamic> json) => SimpleClassOfBigInt( @@ -40,52 +40,52 @@ SimpleClassOfBigInt _$SimpleClassOfBigIntFromJson(Map<String, dynamic> json) => ); Map<String, dynamic> _$SimpleClassOfBigIntToJson( - SimpleClassOfBigInt instance) => - <String, dynamic>{ - 'value': instance.value.map((e) => e.toString()).toList(), - }; + SimpleClassOfBigInt instance, +) => <String, dynamic>{ + 'value': instance.value.map((e) => e.toString()).toList(), +}; SimpleClassNullableOfBigInt _$SimpleClassNullableOfBigIntFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfBigInt( - (json['value'] as List<dynamic>?) - ?.map((e) => BigInt.parse(e as String)) - .toList(), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfBigInt( + (json['value'] as List<dynamic>?) + ?.map((e) => BigInt.parse(e as String)) + .toList(), +); Map<String, dynamic> _$SimpleClassNullableOfBigIntToJson( - SimpleClassNullableOfBigInt instance) => - <String, dynamic>{ - 'value': instance.value?.map((e) => e.toString()).toList(), - }; + SimpleClassNullableOfBigInt instance, +) => <String, dynamic>{ + 'value': instance.value?.map((e) => e.toString()).toList(), +}; SimpleClassOfBigIntNullable _$SimpleClassOfBigIntNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfBigIntNullable( - (json['value'] as List<dynamic>) - .map((e) => e == null ? null : BigInt.parse(e as String)) - .toList(), - ); + Map<String, dynamic> json, +) => SimpleClassOfBigIntNullable( + (json['value'] as List<dynamic>) + .map((e) => e == null ? null : BigInt.parse(e as String)) + .toList(), +); Map<String, dynamic> _$SimpleClassOfBigIntNullableToJson( - SimpleClassOfBigIntNullable instance) => - <String, dynamic>{ - 'value': instance.value.map((e) => e?.toString()).toList(), - }; + SimpleClassOfBigIntNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map((e) => e?.toString()).toList(), +}; SimpleClassNullableOfBigIntNullable - _$SimpleClassNullableOfBigIntNullableFromJson(Map<String, dynamic> json) => - SimpleClassNullableOfBigIntNullable( - (json['value'] as List<dynamic>?) - ?.map((e) => e == null ? null : BigInt.parse(e as String)) - .toList(), - ); +_$SimpleClassNullableOfBigIntNullableFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfBigIntNullable( + (json['value'] as List<dynamic>?) + ?.map((e) => e == null ? null : BigInt.parse(e as String)) + .toList(), + ); Map<String, dynamic> _$SimpleClassNullableOfBigIntNullableToJson( - SimpleClassNullableOfBigIntNullable instance) => - <String, dynamic>{ - 'value': instance.value?.map((e) => e?.toString()).toList(), - }; + SimpleClassNullableOfBigIntNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map((e) => e?.toString()).toList(), +}; SimpleClassOfBool _$SimpleClassOfBoolFromJson(Map<String, dynamic> json) => SimpleClassOfBool( @@ -93,102 +93,93 @@ SimpleClassOfBool _$SimpleClassOfBoolFromJson(Map<String, dynamic> json) => ); Map<String, dynamic> _$SimpleClassOfBoolToJson(SimpleClassOfBool instance) => - <String, dynamic>{ - 'value': instance.value, - }; + <String, dynamic>{'value': instance.value}; SimpleClassNullableOfBool _$SimpleClassNullableOfBoolFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfBool( - (json['value'] as List<dynamic>?)?.map((e) => e as bool).toList(), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfBool( + (json['value'] as List<dynamic>?)?.map((e) => e as bool).toList(), +); Map<String, dynamic> _$SimpleClassNullableOfBoolToJson( - SimpleClassNullableOfBool instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassNullableOfBool instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassOfBoolNullable _$SimpleClassOfBoolNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfBoolNullable( - (json['value'] as List<dynamic>).map((e) => e as bool?).toList(), - ); + Map<String, dynamic> json, +) => SimpleClassOfBoolNullable( + (json['value'] as List<dynamic>).map((e) => e as bool?).toList(), +); Map<String, dynamic> _$SimpleClassOfBoolNullableToJson( - SimpleClassOfBoolNullable instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassOfBoolNullable instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassNullableOfBoolNullable _$SimpleClassNullableOfBoolNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfBoolNullable( - (json['value'] as List<dynamic>?)?.map((e) => e as bool?).toList(), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfBoolNullable( + (json['value'] as List<dynamic>?)?.map((e) => e as bool?).toList(), +); Map<String, dynamic> _$SimpleClassNullableOfBoolNullableToJson( - SimpleClassNullableOfBoolNullable instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassNullableOfBoolNullable instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassOfDateTime _$SimpleClassOfDateTimeFromJson( - Map<String, dynamic> json) => - SimpleClassOfDateTime( - (json['value'] as List<dynamic>) - .map((e) => DateTime.parse(e as String)) - .toList(), - ); + Map<String, dynamic> json, +) => SimpleClassOfDateTime( + (json['value'] as List<dynamic>) + .map((e) => DateTime.parse(e as String)) + .toList(), +); Map<String, dynamic> _$SimpleClassOfDateTimeToJson( - SimpleClassOfDateTime instance) => - <String, dynamic>{ - 'value': instance.value.map((e) => e.toIso8601String()).toList(), - }; + SimpleClassOfDateTime instance, +) => <String, dynamic>{ + 'value': instance.value.map((e) => e.toIso8601String()).toList(), +}; SimpleClassNullableOfDateTime _$SimpleClassNullableOfDateTimeFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDateTime( - (json['value'] as List<dynamic>?) - ?.map((e) => DateTime.parse(e as String)) - .toList(), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfDateTime( + (json['value'] as List<dynamic>?) + ?.map((e) => DateTime.parse(e as String)) + .toList(), +); Map<String, dynamic> _$SimpleClassNullableOfDateTimeToJson( - SimpleClassNullableOfDateTime instance) => - <String, dynamic>{ - 'value': instance.value?.map((e) => e.toIso8601String()).toList(), - }; + SimpleClassNullableOfDateTime instance, +) => <String, dynamic>{ + 'value': instance.value?.map((e) => e.toIso8601String()).toList(), +}; SimpleClassOfDateTimeNullable _$SimpleClassOfDateTimeNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfDateTimeNullable( - (json['value'] as List<dynamic>) - .map((e) => e == null ? null : DateTime.parse(e as String)) - .toList(), - ); + Map<String, dynamic> json, +) => SimpleClassOfDateTimeNullable( + (json['value'] as List<dynamic>) + .map((e) => e == null ? null : DateTime.parse(e as String)) + .toList(), +); Map<String, dynamic> _$SimpleClassOfDateTimeNullableToJson( - SimpleClassOfDateTimeNullable instance) => - <String, dynamic>{ - 'value': instance.value.map((e) => e?.toIso8601String()).toList(), - }; + SimpleClassOfDateTimeNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map((e) => e?.toIso8601String()).toList(), +}; SimpleClassNullableOfDateTimeNullable - _$SimpleClassNullableOfDateTimeNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDateTimeNullable( - (json['value'] as List<dynamic>?) - ?.map((e) => e == null ? null : DateTime.parse(e as String)) - .toList(), - ); +_$SimpleClassNullableOfDateTimeNullableFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfDateTimeNullable( + (json['value'] as List<dynamic>?) + ?.map((e) => e == null ? null : DateTime.parse(e as String)) + .toList(), + ); Map<String, dynamic> _$SimpleClassNullableOfDateTimeNullableToJson( - SimpleClassNullableOfDateTimeNullable instance) => - <String, dynamic>{ - 'value': instance.value?.map((e) => e?.toIso8601String()).toList(), - }; + SimpleClassNullableOfDateTimeNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map((e) => e?.toIso8601String()).toList(), +}; SimpleClassOfDouble _$SimpleClassOfDoubleFromJson(Map<String, dynamic> json) => SimpleClassOfDouble( @@ -198,149 +189,129 @@ SimpleClassOfDouble _$SimpleClassOfDoubleFromJson(Map<String, dynamic> json) => ); Map<String, dynamic> _$SimpleClassOfDoubleToJson( - SimpleClassOfDouble instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassOfDouble instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassNullableOfDouble _$SimpleClassNullableOfDoubleFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDouble( - (json['value'] as List<dynamic>?) - ?.map((e) => (e as num).toDouble()) - .toList(), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfDouble( + (json['value'] as List<dynamic>?)?.map((e) => (e as num).toDouble()).toList(), +); Map<String, dynamic> _$SimpleClassNullableOfDoubleToJson( - SimpleClassNullableOfDouble instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassNullableOfDouble instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassOfDoubleNullable _$SimpleClassOfDoubleNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfDoubleNullable( - (json['value'] as List<dynamic>) - .map((e) => (e as num?)?.toDouble()) - .toList(), - ); + Map<String, dynamic> json, +) => SimpleClassOfDoubleNullable( + (json['value'] as List<dynamic>).map((e) => (e as num?)?.toDouble()).toList(), +); Map<String, dynamic> _$SimpleClassOfDoubleNullableToJson( - SimpleClassOfDoubleNullable instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassOfDoubleNullable instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassNullableOfDoubleNullable - _$SimpleClassNullableOfDoubleNullableFromJson(Map<String, dynamic> json) => - SimpleClassNullableOfDoubleNullable( - (json['value'] as List<dynamic>?) - ?.map((e) => (e as num?)?.toDouble()) - .toList(), - ); +_$SimpleClassNullableOfDoubleNullableFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfDoubleNullable( + (json['value'] as List<dynamic>?) + ?.map((e) => (e as num?)?.toDouble()) + .toList(), + ); Map<String, dynamic> _$SimpleClassNullableOfDoubleNullableToJson( - SimpleClassNullableOfDoubleNullable instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassNullableOfDoubleNullable instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassOfDuration _$SimpleClassOfDurationFromJson( - Map<String, dynamic> json) => - SimpleClassOfDuration( - (json['value'] as List<dynamic>) - .map((e) => Duration(microseconds: (e as num).toInt())) - .toList(), - ); + Map<String, dynamic> json, +) => SimpleClassOfDuration( + (json['value'] as List<dynamic>) + .map((e) => Duration(microseconds: (e as num).toInt())) + .toList(), +); Map<String, dynamic> _$SimpleClassOfDurationToJson( - SimpleClassOfDuration instance) => - <String, dynamic>{ - 'value': instance.value.map((e) => e.inMicroseconds).toList(), - }; + SimpleClassOfDuration instance, +) => <String, dynamic>{ + 'value': instance.value.map((e) => e.inMicroseconds).toList(), +}; SimpleClassNullableOfDuration _$SimpleClassNullableOfDurationFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDuration( - (json['value'] as List<dynamic>?) - ?.map((e) => Duration(microseconds: (e as num).toInt())) - .toList(), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfDuration( + (json['value'] as List<dynamic>?) + ?.map((e) => Duration(microseconds: (e as num).toInt())) + .toList(), +); Map<String, dynamic> _$SimpleClassNullableOfDurationToJson( - SimpleClassNullableOfDuration instance) => - <String, dynamic>{ - 'value': instance.value?.map((e) => e.inMicroseconds).toList(), - }; + SimpleClassNullableOfDuration instance, +) => <String, dynamic>{ + 'value': instance.value?.map((e) => e.inMicroseconds).toList(), +}; SimpleClassOfDurationNullable _$SimpleClassOfDurationNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfDurationNullable( - (json['value'] as List<dynamic>) - .map((e) => - e == null ? null : Duration(microseconds: (e as num).toInt())) - .toList(), - ); + Map<String, dynamic> json, +) => SimpleClassOfDurationNullable( + (json['value'] as List<dynamic>) + .map((e) => e == null ? null : Duration(microseconds: (e as num).toInt())) + .toList(), +); Map<String, dynamic> _$SimpleClassOfDurationNullableToJson( - SimpleClassOfDurationNullable instance) => - <String, dynamic>{ - 'value': instance.value.map((e) => e?.inMicroseconds).toList(), - }; + SimpleClassOfDurationNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map((e) => e?.inMicroseconds).toList(), +}; SimpleClassNullableOfDurationNullable - _$SimpleClassNullableOfDurationNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDurationNullable( - (json['value'] as List<dynamic>?) - ?.map((e) => - e == null ? null : Duration(microseconds: (e as num).toInt())) - .toList(), - ); +_$SimpleClassNullableOfDurationNullableFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfDurationNullable( + (json['value'] as List<dynamic>?) + ?.map( + (e) => + e == null ? null : Duration(microseconds: (e as num).toInt()), + ) + .toList(), + ); Map<String, dynamic> _$SimpleClassNullableOfDurationNullableToJson( - SimpleClassNullableOfDurationNullable instance) => - <String, dynamic>{ - 'value': instance.value?.map((e) => e?.inMicroseconds).toList(), - }; + SimpleClassNullableOfDurationNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map((e) => e?.inMicroseconds).toList(), +}; SimpleClassOfDynamic _$SimpleClassOfDynamicFromJson( - Map<String, dynamic> json) => - SimpleClassOfDynamic( - json['value'] as List<dynamic>, - ); + Map<String, dynamic> json, +) => SimpleClassOfDynamic(json['value'] as List<dynamic>); Map<String, dynamic> _$SimpleClassOfDynamicToJson( - SimpleClassOfDynamic instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassOfDynamic instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassNullableOfDynamic _$SimpleClassNullableOfDynamicFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDynamic( - json['value'] as List<dynamic>?, - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfDynamic(json['value'] as List<dynamic>?); Map<String, dynamic> _$SimpleClassNullableOfDynamicToJson( - SimpleClassNullableOfDynamic instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassNullableOfDynamic instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassOfEnumType _$SimpleClassOfEnumTypeFromJson( - Map<String, dynamic> json) => - SimpleClassOfEnumType( - (json['value'] as List<dynamic>) - .map((e) => $enumDecode(_$EnumTypeEnumMap, e)) - .toList(), - ); + Map<String, dynamic> json, +) => SimpleClassOfEnumType( + (json['value'] as List<dynamic>) + .map((e) => $enumDecode(_$EnumTypeEnumMap, e)) + .toList(), +); Map<String, dynamic> _$SimpleClassOfEnumTypeToJson( - SimpleClassOfEnumType instance) => - <String, dynamic>{ - 'value': instance.value.map((e) => _$EnumTypeEnumMap[e]!).toList(), - }; + SimpleClassOfEnumType instance, +) => <String, dynamic>{ + 'value': instance.value.map((e) => _$EnumTypeEnumMap[e]!).toList(), +}; const _$EnumTypeEnumMap = { EnumType.alpha: 'alpha', @@ -350,135 +321,118 @@ const _$EnumTypeEnumMap = { }; SimpleClassNullableOfEnumType _$SimpleClassNullableOfEnumTypeFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfEnumType( - (json['value'] as List<dynamic>?) - ?.map((e) => $enumDecode(_$EnumTypeEnumMap, e)) - .toList(), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfEnumType( + (json['value'] as List<dynamic>?) + ?.map((e) => $enumDecode(_$EnumTypeEnumMap, e)) + .toList(), +); Map<String, dynamic> _$SimpleClassNullableOfEnumTypeToJson( - SimpleClassNullableOfEnumType instance) => - <String, dynamic>{ - 'value': instance.value?.map((e) => _$EnumTypeEnumMap[e]!).toList(), - }; + SimpleClassNullableOfEnumType instance, +) => <String, dynamic>{ + 'value': instance.value?.map((e) => _$EnumTypeEnumMap[e]!).toList(), +}; SimpleClassOfEnumTypeNullable _$SimpleClassOfEnumTypeNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfEnumTypeNullable( - (json['value'] as List<dynamic>) - .map((e) => $enumDecodeNullable(_$EnumTypeEnumMap, e)) - .toList(), - ); + Map<String, dynamic> json, +) => SimpleClassOfEnumTypeNullable( + (json['value'] as List<dynamic>) + .map((e) => $enumDecodeNullable(_$EnumTypeEnumMap, e)) + .toList(), +); Map<String, dynamic> _$SimpleClassOfEnumTypeNullableToJson( - SimpleClassOfEnumTypeNullable instance) => - <String, dynamic>{ - 'value': instance.value.map((e) => _$EnumTypeEnumMap[e]).toList(), - }; + SimpleClassOfEnumTypeNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map((e) => _$EnumTypeEnumMap[e]).toList(), +}; SimpleClassNullableOfEnumTypeNullable - _$SimpleClassNullableOfEnumTypeNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfEnumTypeNullable( - (json['value'] as List<dynamic>?) - ?.map((e) => $enumDecodeNullable(_$EnumTypeEnumMap, e)) - .toList(), - ); +_$SimpleClassNullableOfEnumTypeNullableFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfEnumTypeNullable( + (json['value'] as List<dynamic>?) + ?.map((e) => $enumDecodeNullable(_$EnumTypeEnumMap, e)) + .toList(), + ); Map<String, dynamic> _$SimpleClassNullableOfEnumTypeNullableToJson( - SimpleClassNullableOfEnumTypeNullable instance) => - <String, dynamic>{ - 'value': instance.value?.map((e) => _$EnumTypeEnumMap[e]).toList(), - }; + SimpleClassNullableOfEnumTypeNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map((e) => _$EnumTypeEnumMap[e]).toList(), +}; SimpleClassOfFromJsonDynamicParam _$SimpleClassOfFromJsonDynamicParamFromJson( - Map<String, dynamic> json) => - SimpleClassOfFromJsonDynamicParam( - (json['value'] as List<dynamic>) - .map(FromJsonDynamicParam.fromJson) - .toList(), - ); + Map<String, dynamic> json, +) => SimpleClassOfFromJsonDynamicParam( + (json['value'] as List<dynamic>).map(FromJsonDynamicParam.fromJson).toList(), +); Map<String, dynamic> _$SimpleClassOfFromJsonDynamicParamToJson( - SimpleClassOfFromJsonDynamicParam instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassOfFromJsonDynamicParam instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassNullableOfFromJsonDynamicParam - _$SimpleClassNullableOfFromJsonDynamicParamFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfFromJsonDynamicParam( - (json['value'] as List<dynamic>?) - ?.map(FromJsonDynamicParam.fromJson) - .toList(), - ); +_$SimpleClassNullableOfFromJsonDynamicParamFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfFromJsonDynamicParam( + (json['value'] as List<dynamic>?) + ?.map(FromJsonDynamicParam.fromJson) + .toList(), +); Map<String, dynamic> _$SimpleClassNullableOfFromJsonDynamicParamToJson( - SimpleClassNullableOfFromJsonDynamicParam instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassNullableOfFromJsonDynamicParam instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassOfFromJsonNullableObjectParam - _$SimpleClassOfFromJsonNullableObjectParamFromJson( - Map<String, dynamic> json) => - SimpleClassOfFromJsonNullableObjectParam( - (json['value'] as List<dynamic>) - .map(FromJsonNullableObjectParam.fromJson) - .toList(), - ); +_$SimpleClassOfFromJsonNullableObjectParamFromJson(Map<String, dynamic> json) => + SimpleClassOfFromJsonNullableObjectParam( + (json['value'] as List<dynamic>) + .map(FromJsonNullableObjectParam.fromJson) + .toList(), + ); Map<String, dynamic> _$SimpleClassOfFromJsonNullableObjectParamToJson( - SimpleClassOfFromJsonNullableObjectParam instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassOfFromJsonNullableObjectParam instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassNullableOfFromJsonNullableObjectParam - _$SimpleClassNullableOfFromJsonNullableObjectParamFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfFromJsonNullableObjectParam( - (json['value'] as List<dynamic>?) - ?.map(FromJsonNullableObjectParam.fromJson) - .toList(), - ); +_$SimpleClassNullableOfFromJsonNullableObjectParamFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfFromJsonNullableObjectParam( + (json['value'] as List<dynamic>?) + ?.map(FromJsonNullableObjectParam.fromJson) + .toList(), +); Map<String, dynamic> _$SimpleClassNullableOfFromJsonNullableObjectParamToJson( - SimpleClassNullableOfFromJsonNullableObjectParam instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassNullableOfFromJsonNullableObjectParam instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassOfFromJsonObjectParam _$SimpleClassOfFromJsonObjectParamFromJson( - Map<String, dynamic> json) => - SimpleClassOfFromJsonObjectParam( - (json['value'] as List<dynamic>) - .map((e) => FromJsonObjectParam.fromJson(e as Object)) - .toList(), - ); + Map<String, dynamic> json, +) => SimpleClassOfFromJsonObjectParam( + (json['value'] as List<dynamic>) + .map((e) => FromJsonObjectParam.fromJson(e as Object)) + .toList(), +); Map<String, dynamic> _$SimpleClassOfFromJsonObjectParamToJson( - SimpleClassOfFromJsonObjectParam instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassOfFromJsonObjectParam instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassNullableOfFromJsonObjectParam - _$SimpleClassNullableOfFromJsonObjectParamFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfFromJsonObjectParam( - (json['value'] as List<dynamic>?) - ?.map((e) => FromJsonObjectParam.fromJson(e as Object)) - .toList(), - ); +_$SimpleClassNullableOfFromJsonObjectParamFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfFromJsonObjectParam( + (json['value'] as List<dynamic>?) + ?.map((e) => FromJsonObjectParam.fromJson(e as Object)) + .toList(), + ); Map<String, dynamic> _$SimpleClassNullableOfFromJsonObjectParamToJson( - SimpleClassNullableOfFromJsonObjectParam instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassNullableOfFromJsonObjectParam instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassOfInt _$SimpleClassOfIntFromJson(Map<String, dynamic> json) => SimpleClassOfInt( @@ -486,51 +440,37 @@ SimpleClassOfInt _$SimpleClassOfIntFromJson(Map<String, dynamic> json) => ); Map<String, dynamic> _$SimpleClassOfIntToJson(SimpleClassOfInt instance) => - <String, dynamic>{ - 'value': instance.value, - }; + <String, dynamic>{'value': instance.value}; SimpleClassNullableOfInt _$SimpleClassNullableOfIntFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfInt( - (json['value'] as List<dynamic>?) - ?.map((e) => (e as num).toInt()) - .toList(), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfInt( + (json['value'] as List<dynamic>?)?.map((e) => (e as num).toInt()).toList(), +); Map<String, dynamic> _$SimpleClassNullableOfIntToJson( - SimpleClassNullableOfInt instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassNullableOfInt instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassOfIntNullable _$SimpleClassOfIntNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfIntNullable( - (json['value'] as List<dynamic>) - .map((e) => (e as num?)?.toInt()) - .toList(), - ); + Map<String, dynamic> json, +) => SimpleClassOfIntNullable( + (json['value'] as List<dynamic>).map((e) => (e as num?)?.toInt()).toList(), +); Map<String, dynamic> _$SimpleClassOfIntNullableToJson( - SimpleClassOfIntNullable instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassOfIntNullable instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassNullableOfIntNullable _$SimpleClassNullableOfIntNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfIntNullable( - (json['value'] as List<dynamic>?) - ?.map((e) => (e as num?)?.toInt()) - .toList(), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfIntNullable( + (json['value'] as List<dynamic>?)?.map((e) => (e as num?)?.toInt()).toList(), +); Map<String, dynamic> _$SimpleClassNullableOfIntNullableToJson( - SimpleClassNullableOfIntNullable instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassNullableOfIntNullable instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassOfNum _$SimpleClassOfNumFromJson(Map<String, dynamic> json) => SimpleClassOfNum( @@ -538,45 +478,37 @@ SimpleClassOfNum _$SimpleClassOfNumFromJson(Map<String, dynamic> json) => ); Map<String, dynamic> _$SimpleClassOfNumToJson(SimpleClassOfNum instance) => - <String, dynamic>{ - 'value': instance.value, - }; + <String, dynamic>{'value': instance.value}; SimpleClassNullableOfNum _$SimpleClassNullableOfNumFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfNum( - (json['value'] as List<dynamic>?)?.map((e) => e as num).toList(), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfNum( + (json['value'] as List<dynamic>?)?.map((e) => e as num).toList(), +); Map<String, dynamic> _$SimpleClassNullableOfNumToJson( - SimpleClassNullableOfNum instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassNullableOfNum instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassOfNumNullable _$SimpleClassOfNumNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfNumNullable( - (json['value'] as List<dynamic>).map((e) => e as num?).toList(), - ); + Map<String, dynamic> json, +) => SimpleClassOfNumNullable( + (json['value'] as List<dynamic>).map((e) => e as num?).toList(), +); Map<String, dynamic> _$SimpleClassOfNumNullableToJson( - SimpleClassOfNumNullable instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassOfNumNullable instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassNullableOfNumNullable _$SimpleClassNullableOfNumNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfNumNullable( - (json['value'] as List<dynamic>?)?.map((e) => e as num?).toList(), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfNumNullable( + (json['value'] as List<dynamic>?)?.map((e) => e as num?).toList(), +); Map<String, dynamic> _$SimpleClassNullableOfNumNullableToJson( - SimpleClassNullableOfNumNullable instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassNullableOfNumNullable instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassOfObject _$SimpleClassOfObjectFromJson(Map<String, dynamic> json) => SimpleClassOfObject( @@ -584,105 +516,88 @@ SimpleClassOfObject _$SimpleClassOfObjectFromJson(Map<String, dynamic> json) => ); Map<String, dynamic> _$SimpleClassOfObjectToJson( - SimpleClassOfObject instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassOfObject instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassNullableOfObject _$SimpleClassNullableOfObjectFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfObject( - (json['value'] as List<dynamic>?)?.map((e) => e as Object).toList(), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfObject( + (json['value'] as List<dynamic>?)?.map((e) => e as Object).toList(), +); Map<String, dynamic> _$SimpleClassNullableOfObjectToJson( - SimpleClassNullableOfObject instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassNullableOfObject instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassOfObjectNullable _$SimpleClassOfObjectNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfObjectNullable( - json['value'] as List<dynamic>, - ); + Map<String, dynamic> json, +) => SimpleClassOfObjectNullable(json['value'] as List<dynamic>); Map<String, dynamic> _$SimpleClassOfObjectNullableToJson( - SimpleClassOfObjectNullable instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassOfObjectNullable instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassNullableOfObjectNullable - _$SimpleClassNullableOfObjectNullableFromJson(Map<String, dynamic> json) => - SimpleClassNullableOfObjectNullable( - json['value'] as List<dynamic>?, - ); +_$SimpleClassNullableOfObjectNullableFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfObjectNullable(json['value'] as List<dynamic>?); Map<String, dynamic> _$SimpleClassNullableOfObjectNullableToJson( - SimpleClassNullableOfObjectNullable instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassNullableOfObjectNullable instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassOfRecord _$SimpleClassOfRecordFromJson(Map<String, dynamic> json) => SimpleClassOfRecord( (json['value'] as List<dynamic>) - .map((e) => _$recordConvert( - e, - ($jsonValue) => ( - ($jsonValue[r'$1'] as num).toInt(), - $jsonValue[r'$2'] as String, - truth: $jsonValue['truth'] as bool, - ), - )) + .map( + (e) => _$recordConvert( + e, + ($jsonValue) => ( + ($jsonValue[r'$1'] as num).toInt(), + $jsonValue[r'$2'] as String, + truth: $jsonValue['truth'] as bool, + ), + ), + ) .toList(), ); Map<String, dynamic> _$SimpleClassOfRecordToJson( - SimpleClassOfRecord instance) => - <String, dynamic>{ - 'value': instance.value - .map((e) => <String, dynamic>{ - r'$1': e.$1, - r'$2': e.$2, - 'truth': e.truth, - }) - .toList(), - }; + SimpleClassOfRecord instance, +) => <String, dynamic>{ + 'value': instance.value + .map((e) => <String, dynamic>{r'$1': e.$1, r'$2': e.$2, 'truth': e.truth}) + .toList(), +}; -$Rec _$recordConvert<$Rec>( - Object? value, - $Rec Function(Map) convert, -) => +$Rec _$recordConvert<$Rec>(Object? value, $Rec Function(Map) convert) => convert(value as Map<String, dynamic>); SimpleClassNullableOfRecord _$SimpleClassNullableOfRecordFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfRecord( - (json['value'] as List<dynamic>?) - ?.map((e) => _$recordConvert( - e, - ($jsonValue) => ( - ($jsonValue[r'$1'] as num).toInt(), - $jsonValue[r'$2'] as String, - truth: $jsonValue['truth'] as bool, - ), - )) - .toList(), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfRecord( + (json['value'] as List<dynamic>?) + ?.map( + (e) => _$recordConvert( + e, + ($jsonValue) => ( + ($jsonValue[r'$1'] as num).toInt(), + $jsonValue[r'$2'] as String, + truth: $jsonValue['truth'] as bool, + ), + ), + ) + .toList(), +); Map<String, dynamic> _$SimpleClassNullableOfRecordToJson( - SimpleClassNullableOfRecord instance) => - <String, dynamic>{ - 'value': instance.value - ?.map((e) => <String, dynamic>{ - r'$1': e.$1, - r'$2': e.$2, - 'truth': e.truth, - }) - .toList(), - }; + SimpleClassNullableOfRecord instance, +) => <String, dynamic>{ + 'value': instance.value + ?.map( + (e) => <String, dynamic>{r'$1': e.$1, r'$2': e.$2, 'truth': e.truth}, + ) + .toList(), +}; SimpleClassOfString _$SimpleClassOfStringFromJson(Map<String, dynamic> json) => SimpleClassOfString( @@ -690,46 +605,38 @@ SimpleClassOfString _$SimpleClassOfStringFromJson(Map<String, dynamic> json) => ); Map<String, dynamic> _$SimpleClassOfStringToJson( - SimpleClassOfString instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassOfString instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassNullableOfString _$SimpleClassNullableOfStringFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfString( - (json['value'] as List<dynamic>?)?.map((e) => e as String).toList(), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfString( + (json['value'] as List<dynamic>?)?.map((e) => e as String).toList(), +); Map<String, dynamic> _$SimpleClassNullableOfStringToJson( - SimpleClassNullableOfString instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassNullableOfString instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassOfStringNullable _$SimpleClassOfStringNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfStringNullable( - (json['value'] as List<dynamic>).map((e) => e as String?).toList(), - ); + Map<String, dynamic> json, +) => SimpleClassOfStringNullable( + (json['value'] as List<dynamic>).map((e) => e as String?).toList(), +); Map<String, dynamic> _$SimpleClassOfStringNullableToJson( - SimpleClassOfStringNullable instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassOfStringNullable instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassNullableOfStringNullable - _$SimpleClassNullableOfStringNullableFromJson(Map<String, dynamic> json) => - SimpleClassNullableOfStringNullable( - (json['value'] as List<dynamic>?)?.map((e) => e as String?).toList(), - ); +_$SimpleClassNullableOfStringNullableFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfStringNullable( + (json['value'] as List<dynamic>?)?.map((e) => e as String?).toList(), + ); Map<String, dynamic> _$SimpleClassNullableOfStringNullableToJson( - SimpleClassNullableOfStringNullable instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassNullableOfStringNullable instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassOfUri _$SimpleClassOfUriFromJson(Map<String, dynamic> json) => SimpleClassOfUri( @@ -744,43 +651,43 @@ Map<String, dynamic> _$SimpleClassOfUriToJson(SimpleClassOfUri instance) => }; SimpleClassNullableOfUri _$SimpleClassNullableOfUriFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfUri( - (json['value'] as List<dynamic>?) - ?.map((e) => Uri.parse(e as String)) - .toList(), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfUri( + (json['value'] as List<dynamic>?) + ?.map((e) => Uri.parse(e as String)) + .toList(), +); Map<String, dynamic> _$SimpleClassNullableOfUriToJson( - SimpleClassNullableOfUri instance) => - <String, dynamic>{ - 'value': instance.value?.map((e) => e.toString()).toList(), - }; + SimpleClassNullableOfUri instance, +) => <String, dynamic>{ + 'value': instance.value?.map((e) => e.toString()).toList(), +}; SimpleClassOfUriNullable _$SimpleClassOfUriNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfUriNullable( - (json['value'] as List<dynamic>) - .map((e) => e == null ? null : Uri.parse(e as String)) - .toList(), - ); + Map<String, dynamic> json, +) => SimpleClassOfUriNullable( + (json['value'] as List<dynamic>) + .map((e) => e == null ? null : Uri.parse(e as String)) + .toList(), +); Map<String, dynamic> _$SimpleClassOfUriNullableToJson( - SimpleClassOfUriNullable instance) => - <String, dynamic>{ - 'value': instance.value.map((e) => e?.toString()).toList(), - }; + SimpleClassOfUriNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map((e) => e?.toString()).toList(), +}; SimpleClassNullableOfUriNullable _$SimpleClassNullableOfUriNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfUriNullable( - (json['value'] as List<dynamic>?) - ?.map((e) => e == null ? null : Uri.parse(e as String)) - .toList(), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfUriNullable( + (json['value'] as List<dynamic>?) + ?.map((e) => e == null ? null : Uri.parse(e as String)) + .toList(), +); Map<String, dynamic> _$SimpleClassNullableOfUriNullableToJson( - SimpleClassNullableOfUriNullable instance) => - <String, dynamic>{ - 'value': instance.value?.map((e) => e?.toString()).toList(), - }; + SimpleClassNullableOfUriNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map((e) => e?.toString()).toList(), +}; diff --git a/json_serializable/test/supported_types/input.type_map.dart b/json_serializable/test/supported_types/input.type_map.dart index 985dbe125..59d1a21d0 100644 --- a/json_serializable/test/supported_types/input.type_map.dart +++ b/json_serializable/test/supported_types/input.type_map.dart @@ -14,10 +14,7 @@ class SimpleClass { @JsonKey(defaultValue: {'a': 1}) Map withDefault; - SimpleClass( - this.value, - this.withDefault, - ); + SimpleClass(this.value, this.withDefault); factory SimpleClass.fromJson(Map<String, Object?> json) => _$SimpleClassFromJson(json); @@ -32,10 +29,7 @@ class SimpleClassNullable { @JsonKey(defaultValue: {'a': 1}) Map? withDefault; - SimpleClassNullable( - this.value, - this.withDefault, - ); + SimpleClassNullable(this.value, this.withDefault); factory SimpleClassNullable.fromJson(Map<String, Object?> json) => _$SimpleClassNullableFromJson(json); @@ -47,9 +41,7 @@ class SimpleClassNullable { class SimpleClassOfBigIntToBigInt { final Map<BigInt, BigInt> value; - SimpleClassOfBigIntToBigInt( - this.value, - ); + SimpleClassOfBigIntToBigInt(this.value); factory SimpleClassOfBigIntToBigInt.fromJson(Map<String, Object?> json) => _$SimpleClassOfBigIntToBigIntFromJson(json); @@ -61,13 +53,11 @@ class SimpleClassOfBigIntToBigInt { class SimpleClassNullableOfBigIntToBigInt { final Map<BigInt, BigInt>? value; - SimpleClassNullableOfBigIntToBigInt( - this.value, - ); + SimpleClassNullableOfBigIntToBigInt(this.value); factory SimpleClassNullableOfBigIntToBigInt.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfBigIntToBigIntFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfBigIntToBigIntFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfBigIntToBigIntToJson(this); @@ -77,9 +67,7 @@ class SimpleClassNullableOfBigIntToBigInt { class SimpleClassOfDateTimeToBigInt { final Map<DateTime, BigInt> value; - SimpleClassOfDateTimeToBigInt( - this.value, - ); + SimpleClassOfDateTimeToBigInt(this.value); factory SimpleClassOfDateTimeToBigInt.fromJson(Map<String, Object?> json) => _$SimpleClassOfDateTimeToBigIntFromJson(json); @@ -91,13 +79,11 @@ class SimpleClassOfDateTimeToBigInt { class SimpleClassNullableOfDateTimeToBigInt { final Map<DateTime, BigInt>? value; - SimpleClassNullableOfDateTimeToBigInt( - this.value, - ); + SimpleClassNullableOfDateTimeToBigInt(this.value); factory SimpleClassNullableOfDateTimeToBigInt.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfDateTimeToBigIntFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfDateTimeToBigIntFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfDateTimeToBigIntToJson(this); @@ -107,9 +93,7 @@ class SimpleClassNullableOfDateTimeToBigInt { class SimpleClassOfDynamicToBigInt { final Map<dynamic, BigInt> value; - SimpleClassOfDynamicToBigInt( - this.value, - ); + SimpleClassOfDynamicToBigInt(this.value); factory SimpleClassOfDynamicToBigInt.fromJson(Map<String, Object?> json) => _$SimpleClassOfDynamicToBigIntFromJson(json); @@ -121,13 +105,11 @@ class SimpleClassOfDynamicToBigInt { class SimpleClassNullableOfDynamicToBigInt { final Map<dynamic, BigInt>? value; - SimpleClassNullableOfDynamicToBigInt( - this.value, - ); + SimpleClassNullableOfDynamicToBigInt(this.value); factory SimpleClassNullableOfDynamicToBigInt.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfDynamicToBigIntFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfDynamicToBigIntFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfDynamicToBigIntToJson(this); @@ -137,9 +119,7 @@ class SimpleClassNullableOfDynamicToBigInt { class SimpleClassOfEnumTypeToBigInt { final Map<EnumType, BigInt> value; - SimpleClassOfEnumTypeToBigInt( - this.value, - ); + SimpleClassOfEnumTypeToBigInt(this.value); factory SimpleClassOfEnumTypeToBigInt.fromJson(Map<String, Object?> json) => _$SimpleClassOfEnumTypeToBigIntFromJson(json); @@ -151,13 +131,11 @@ class SimpleClassOfEnumTypeToBigInt { class SimpleClassNullableOfEnumTypeToBigInt { final Map<EnumType, BigInt>? value; - SimpleClassNullableOfEnumTypeToBigInt( - this.value, - ); + SimpleClassNullableOfEnumTypeToBigInt(this.value); factory SimpleClassNullableOfEnumTypeToBigInt.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfEnumTypeToBigIntFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfEnumTypeToBigIntFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfEnumTypeToBigIntToJson(this); @@ -167,9 +145,7 @@ class SimpleClassNullableOfEnumTypeToBigInt { class SimpleClassOfIntToBigInt { final Map<int, BigInt> value; - SimpleClassOfIntToBigInt( - this.value, - ); + SimpleClassOfIntToBigInt(this.value); factory SimpleClassOfIntToBigInt.fromJson(Map<String, Object?> json) => _$SimpleClassOfIntToBigIntFromJson(json); @@ -181,13 +157,11 @@ class SimpleClassOfIntToBigInt { class SimpleClassNullableOfIntToBigInt { final Map<int, BigInt>? value; - SimpleClassNullableOfIntToBigInt( - this.value, - ); + SimpleClassNullableOfIntToBigInt(this.value); factory SimpleClassNullableOfIntToBigInt.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfIntToBigIntFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfIntToBigIntFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfIntToBigIntToJson(this); @@ -197,9 +171,7 @@ class SimpleClassNullableOfIntToBigInt { class SimpleClassOfObjectToBigInt { final Map<Object, BigInt> value; - SimpleClassOfObjectToBigInt( - this.value, - ); + SimpleClassOfObjectToBigInt(this.value); factory SimpleClassOfObjectToBigInt.fromJson(Map<String, Object?> json) => _$SimpleClassOfObjectToBigIntFromJson(json); @@ -211,13 +183,11 @@ class SimpleClassOfObjectToBigInt { class SimpleClassNullableOfObjectToBigInt { final Map<Object, BigInt>? value; - SimpleClassNullableOfObjectToBigInt( - this.value, - ); + SimpleClassNullableOfObjectToBigInt(this.value); factory SimpleClassNullableOfObjectToBigInt.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfObjectToBigIntFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfObjectToBigIntFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfObjectToBigIntToJson(this); @@ -227,9 +197,7 @@ class SimpleClassNullableOfObjectToBigInt { class SimpleClassOfStringToBigInt { final Map<String, BigInt> value; - SimpleClassOfStringToBigInt( - this.value, - ); + SimpleClassOfStringToBigInt(this.value); factory SimpleClassOfStringToBigInt.fromJson(Map<String, Object?> json) => _$SimpleClassOfStringToBigIntFromJson(json); @@ -241,13 +209,11 @@ class SimpleClassOfStringToBigInt { class SimpleClassNullableOfStringToBigInt { final Map<String, BigInt>? value; - SimpleClassNullableOfStringToBigInt( - this.value, - ); + SimpleClassNullableOfStringToBigInt(this.value); factory SimpleClassNullableOfStringToBigInt.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfStringToBigIntFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfStringToBigIntFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfStringToBigIntToJson(this); @@ -257,9 +223,7 @@ class SimpleClassNullableOfStringToBigInt { class SimpleClassOfUriToBigInt { final Map<Uri, BigInt> value; - SimpleClassOfUriToBigInt( - this.value, - ); + SimpleClassOfUriToBigInt(this.value); factory SimpleClassOfUriToBigInt.fromJson(Map<String, Object?> json) => _$SimpleClassOfUriToBigIntFromJson(json); @@ -271,13 +235,11 @@ class SimpleClassOfUriToBigInt { class SimpleClassNullableOfUriToBigInt { final Map<Uri, BigInt>? value; - SimpleClassNullableOfUriToBigInt( - this.value, - ); + SimpleClassNullableOfUriToBigInt(this.value); factory SimpleClassNullableOfUriToBigInt.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfUriToBigIntFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfUriToBigIntFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfUriToBigIntToJson(this); @@ -287,13 +249,11 @@ class SimpleClassNullableOfUriToBigInt { class SimpleClassOfBigIntToBigIntNullable { final Map<BigInt, BigInt?> value; - SimpleClassOfBigIntToBigIntNullable( - this.value, - ); + SimpleClassOfBigIntToBigIntNullable(this.value); factory SimpleClassOfBigIntToBigIntNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfBigIntToBigIntNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfBigIntToBigIntNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfBigIntToBigIntNullableToJson(this); @@ -303,13 +263,11 @@ class SimpleClassOfBigIntToBigIntNullable { class SimpleClassNullableOfBigIntToBigIntNullable { final Map<BigInt, BigInt?>? value; - SimpleClassNullableOfBigIntToBigIntNullable( - this.value, - ); + SimpleClassNullableOfBigIntToBigIntNullable(this.value); factory SimpleClassNullableOfBigIntToBigIntNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfBigIntToBigIntNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfBigIntToBigIntNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfBigIntToBigIntNullableToJson(this); @@ -319,13 +277,11 @@ class SimpleClassNullableOfBigIntToBigIntNullable { class SimpleClassOfDateTimeToBigIntNullable { final Map<DateTime, BigInt?> value; - SimpleClassOfDateTimeToBigIntNullable( - this.value, - ); + SimpleClassOfDateTimeToBigIntNullable(this.value); factory SimpleClassOfDateTimeToBigIntNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfDateTimeToBigIntNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfDateTimeToBigIntNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfDateTimeToBigIntNullableToJson(this); @@ -335,13 +291,11 @@ class SimpleClassOfDateTimeToBigIntNullable { class SimpleClassNullableOfDateTimeToBigIntNullable { final Map<DateTime, BigInt?>? value; - SimpleClassNullableOfDateTimeToBigIntNullable( - this.value, - ); + SimpleClassNullableOfDateTimeToBigIntNullable(this.value); factory SimpleClassNullableOfDateTimeToBigIntNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfDateTimeToBigIntNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfDateTimeToBigIntNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfDateTimeToBigIntNullableToJson(this); @@ -351,13 +305,11 @@ class SimpleClassNullableOfDateTimeToBigIntNullable { class SimpleClassOfDynamicToBigIntNullable { final Map<dynamic, BigInt?> value; - SimpleClassOfDynamicToBigIntNullable( - this.value, - ); + SimpleClassOfDynamicToBigIntNullable(this.value); factory SimpleClassOfDynamicToBigIntNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfDynamicToBigIntNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfDynamicToBigIntNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfDynamicToBigIntNullableToJson(this); @@ -367,13 +319,11 @@ class SimpleClassOfDynamicToBigIntNullable { class SimpleClassNullableOfDynamicToBigIntNullable { final Map<dynamic, BigInt?>? value; - SimpleClassNullableOfDynamicToBigIntNullable( - this.value, - ); + SimpleClassNullableOfDynamicToBigIntNullable(this.value); factory SimpleClassNullableOfDynamicToBigIntNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfDynamicToBigIntNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfDynamicToBigIntNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfDynamicToBigIntNullableToJson(this); @@ -383,13 +333,11 @@ class SimpleClassNullableOfDynamicToBigIntNullable { class SimpleClassOfEnumTypeToBigIntNullable { final Map<EnumType, BigInt?> value; - SimpleClassOfEnumTypeToBigIntNullable( - this.value, - ); + SimpleClassOfEnumTypeToBigIntNullable(this.value); factory SimpleClassOfEnumTypeToBigIntNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfEnumTypeToBigIntNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfEnumTypeToBigIntNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfEnumTypeToBigIntNullableToJson(this); @@ -399,13 +347,11 @@ class SimpleClassOfEnumTypeToBigIntNullable { class SimpleClassNullableOfEnumTypeToBigIntNullable { final Map<EnumType, BigInt?>? value; - SimpleClassNullableOfEnumTypeToBigIntNullable( - this.value, - ); + SimpleClassNullableOfEnumTypeToBigIntNullable(this.value); factory SimpleClassNullableOfEnumTypeToBigIntNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfEnumTypeToBigIntNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfEnumTypeToBigIntNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfEnumTypeToBigIntNullableToJson(this); @@ -415,13 +361,11 @@ class SimpleClassNullableOfEnumTypeToBigIntNullable { class SimpleClassOfIntToBigIntNullable { final Map<int, BigInt?> value; - SimpleClassOfIntToBigIntNullable( - this.value, - ); + SimpleClassOfIntToBigIntNullable(this.value); factory SimpleClassOfIntToBigIntNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfIntToBigIntNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfIntToBigIntNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfIntToBigIntNullableToJson(this); @@ -431,13 +375,11 @@ class SimpleClassOfIntToBigIntNullable { class SimpleClassNullableOfIntToBigIntNullable { final Map<int, BigInt?>? value; - SimpleClassNullableOfIntToBigIntNullable( - this.value, - ); + SimpleClassNullableOfIntToBigIntNullable(this.value); factory SimpleClassNullableOfIntToBigIntNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfIntToBigIntNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfIntToBigIntNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfIntToBigIntNullableToJson(this); @@ -447,13 +389,11 @@ class SimpleClassNullableOfIntToBigIntNullable { class SimpleClassOfObjectToBigIntNullable { final Map<Object, BigInt?> value; - SimpleClassOfObjectToBigIntNullable( - this.value, - ); + SimpleClassOfObjectToBigIntNullable(this.value); factory SimpleClassOfObjectToBigIntNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfObjectToBigIntNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfObjectToBigIntNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfObjectToBigIntNullableToJson(this); @@ -463,13 +403,11 @@ class SimpleClassOfObjectToBigIntNullable { class SimpleClassNullableOfObjectToBigIntNullable { final Map<Object, BigInt?>? value; - SimpleClassNullableOfObjectToBigIntNullable( - this.value, - ); + SimpleClassNullableOfObjectToBigIntNullable(this.value); factory SimpleClassNullableOfObjectToBigIntNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfObjectToBigIntNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfObjectToBigIntNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfObjectToBigIntNullableToJson(this); @@ -479,13 +417,11 @@ class SimpleClassNullableOfObjectToBigIntNullable { class SimpleClassOfStringToBigIntNullable { final Map<String, BigInt?> value; - SimpleClassOfStringToBigIntNullable( - this.value, - ); + SimpleClassOfStringToBigIntNullable(this.value); factory SimpleClassOfStringToBigIntNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfStringToBigIntNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfStringToBigIntNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfStringToBigIntNullableToJson(this); @@ -495,13 +431,11 @@ class SimpleClassOfStringToBigIntNullable { class SimpleClassNullableOfStringToBigIntNullable { final Map<String, BigInt?>? value; - SimpleClassNullableOfStringToBigIntNullable( - this.value, - ); + SimpleClassNullableOfStringToBigIntNullable(this.value); factory SimpleClassNullableOfStringToBigIntNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfStringToBigIntNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfStringToBigIntNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfStringToBigIntNullableToJson(this); @@ -511,13 +445,11 @@ class SimpleClassNullableOfStringToBigIntNullable { class SimpleClassOfUriToBigIntNullable { final Map<Uri, BigInt?> value; - SimpleClassOfUriToBigIntNullable( - this.value, - ); + SimpleClassOfUriToBigIntNullable(this.value); factory SimpleClassOfUriToBigIntNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfUriToBigIntNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfUriToBigIntNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfUriToBigIntNullableToJson(this); @@ -527,13 +459,11 @@ class SimpleClassOfUriToBigIntNullable { class SimpleClassNullableOfUriToBigIntNullable { final Map<Uri, BigInt?>? value; - SimpleClassNullableOfUriToBigIntNullable( - this.value, - ); + SimpleClassNullableOfUriToBigIntNullable(this.value); factory SimpleClassNullableOfUriToBigIntNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfUriToBigIntNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfUriToBigIntNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfUriToBigIntNullableToJson(this); @@ -543,9 +473,7 @@ class SimpleClassNullableOfUriToBigIntNullable { class SimpleClassOfBigIntToBool { final Map<BigInt, bool> value; - SimpleClassOfBigIntToBool( - this.value, - ); + SimpleClassOfBigIntToBool(this.value); factory SimpleClassOfBigIntToBool.fromJson(Map<String, Object?> json) => _$SimpleClassOfBigIntToBoolFromJson(json); @@ -557,13 +485,11 @@ class SimpleClassOfBigIntToBool { class SimpleClassNullableOfBigIntToBool { final Map<BigInt, bool>? value; - SimpleClassNullableOfBigIntToBool( - this.value, - ); + SimpleClassNullableOfBigIntToBool(this.value); factory SimpleClassNullableOfBigIntToBool.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfBigIntToBoolFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfBigIntToBoolFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfBigIntToBoolToJson(this); @@ -573,9 +499,7 @@ class SimpleClassNullableOfBigIntToBool { class SimpleClassOfDateTimeToBool { final Map<DateTime, bool> value; - SimpleClassOfDateTimeToBool( - this.value, - ); + SimpleClassOfDateTimeToBool(this.value); factory SimpleClassOfDateTimeToBool.fromJson(Map<String, Object?> json) => _$SimpleClassOfDateTimeToBoolFromJson(json); @@ -587,13 +511,11 @@ class SimpleClassOfDateTimeToBool { class SimpleClassNullableOfDateTimeToBool { final Map<DateTime, bool>? value; - SimpleClassNullableOfDateTimeToBool( - this.value, - ); + SimpleClassNullableOfDateTimeToBool(this.value); factory SimpleClassNullableOfDateTimeToBool.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfDateTimeToBoolFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfDateTimeToBoolFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfDateTimeToBoolToJson(this); @@ -603,9 +525,7 @@ class SimpleClassNullableOfDateTimeToBool { class SimpleClassOfDynamicToBool { final Map<dynamic, bool> value; - SimpleClassOfDynamicToBool( - this.value, - ); + SimpleClassOfDynamicToBool(this.value); factory SimpleClassOfDynamicToBool.fromJson(Map<String, Object?> json) => _$SimpleClassOfDynamicToBoolFromJson(json); @@ -617,13 +537,11 @@ class SimpleClassOfDynamicToBool { class SimpleClassNullableOfDynamicToBool { final Map<dynamic, bool>? value; - SimpleClassNullableOfDynamicToBool( - this.value, - ); + SimpleClassNullableOfDynamicToBool(this.value); factory SimpleClassNullableOfDynamicToBool.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfDynamicToBoolFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfDynamicToBoolFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfDynamicToBoolToJson(this); @@ -633,9 +551,7 @@ class SimpleClassNullableOfDynamicToBool { class SimpleClassOfEnumTypeToBool { final Map<EnumType, bool> value; - SimpleClassOfEnumTypeToBool( - this.value, - ); + SimpleClassOfEnumTypeToBool(this.value); factory SimpleClassOfEnumTypeToBool.fromJson(Map<String, Object?> json) => _$SimpleClassOfEnumTypeToBoolFromJson(json); @@ -647,13 +563,11 @@ class SimpleClassOfEnumTypeToBool { class SimpleClassNullableOfEnumTypeToBool { final Map<EnumType, bool>? value; - SimpleClassNullableOfEnumTypeToBool( - this.value, - ); + SimpleClassNullableOfEnumTypeToBool(this.value); factory SimpleClassNullableOfEnumTypeToBool.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfEnumTypeToBoolFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfEnumTypeToBoolFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfEnumTypeToBoolToJson(this); @@ -663,9 +577,7 @@ class SimpleClassNullableOfEnumTypeToBool { class SimpleClassOfIntToBool { final Map<int, bool> value; - SimpleClassOfIntToBool( - this.value, - ); + SimpleClassOfIntToBool(this.value); factory SimpleClassOfIntToBool.fromJson(Map<String, Object?> json) => _$SimpleClassOfIntToBoolFromJson(json); @@ -677,9 +589,7 @@ class SimpleClassOfIntToBool { class SimpleClassNullableOfIntToBool { final Map<int, bool>? value; - SimpleClassNullableOfIntToBool( - this.value, - ); + SimpleClassNullableOfIntToBool(this.value); factory SimpleClassNullableOfIntToBool.fromJson(Map<String, Object?> json) => _$SimpleClassNullableOfIntToBoolFromJson(json); @@ -691,9 +601,7 @@ class SimpleClassNullableOfIntToBool { class SimpleClassOfObjectToBool { final Map<Object, bool> value; - SimpleClassOfObjectToBool( - this.value, - ); + SimpleClassOfObjectToBool(this.value); factory SimpleClassOfObjectToBool.fromJson(Map<String, Object?> json) => _$SimpleClassOfObjectToBoolFromJson(json); @@ -705,13 +613,11 @@ class SimpleClassOfObjectToBool { class SimpleClassNullableOfObjectToBool { final Map<Object, bool>? value; - SimpleClassNullableOfObjectToBool( - this.value, - ); + SimpleClassNullableOfObjectToBool(this.value); factory SimpleClassNullableOfObjectToBool.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfObjectToBoolFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfObjectToBoolFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfObjectToBoolToJson(this); @@ -721,9 +627,7 @@ class SimpleClassNullableOfObjectToBool { class SimpleClassOfStringToBool { final Map<String, bool> value; - SimpleClassOfStringToBool( - this.value, - ); + SimpleClassOfStringToBool(this.value); factory SimpleClassOfStringToBool.fromJson(Map<String, Object?> json) => _$SimpleClassOfStringToBoolFromJson(json); @@ -735,13 +639,11 @@ class SimpleClassOfStringToBool { class SimpleClassNullableOfStringToBool { final Map<String, bool>? value; - SimpleClassNullableOfStringToBool( - this.value, - ); + SimpleClassNullableOfStringToBool(this.value); factory SimpleClassNullableOfStringToBool.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfStringToBoolFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfStringToBoolFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfStringToBoolToJson(this); @@ -751,9 +653,7 @@ class SimpleClassNullableOfStringToBool { class SimpleClassOfUriToBool { final Map<Uri, bool> value; - SimpleClassOfUriToBool( - this.value, - ); + SimpleClassOfUriToBool(this.value); factory SimpleClassOfUriToBool.fromJson(Map<String, Object?> json) => _$SimpleClassOfUriToBoolFromJson(json); @@ -765,9 +665,7 @@ class SimpleClassOfUriToBool { class SimpleClassNullableOfUriToBool { final Map<Uri, bool>? value; - SimpleClassNullableOfUriToBool( - this.value, - ); + SimpleClassNullableOfUriToBool(this.value); factory SimpleClassNullableOfUriToBool.fromJson(Map<String, Object?> json) => _$SimpleClassNullableOfUriToBoolFromJson(json); @@ -779,13 +677,11 @@ class SimpleClassNullableOfUriToBool { class SimpleClassOfBigIntToBoolNullable { final Map<BigInt, bool?> value; - SimpleClassOfBigIntToBoolNullable( - this.value, - ); + SimpleClassOfBigIntToBoolNullable(this.value); factory SimpleClassOfBigIntToBoolNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfBigIntToBoolNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfBigIntToBoolNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfBigIntToBoolNullableToJson(this); @@ -795,13 +691,11 @@ class SimpleClassOfBigIntToBoolNullable { class SimpleClassNullableOfBigIntToBoolNullable { final Map<BigInt, bool?>? value; - SimpleClassNullableOfBigIntToBoolNullable( - this.value, - ); + SimpleClassNullableOfBigIntToBoolNullable(this.value); factory SimpleClassNullableOfBigIntToBoolNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfBigIntToBoolNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfBigIntToBoolNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfBigIntToBoolNullableToJson(this); @@ -811,13 +705,11 @@ class SimpleClassNullableOfBigIntToBoolNullable { class SimpleClassOfDateTimeToBoolNullable { final Map<DateTime, bool?> value; - SimpleClassOfDateTimeToBoolNullable( - this.value, - ); + SimpleClassOfDateTimeToBoolNullable(this.value); factory SimpleClassOfDateTimeToBoolNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfDateTimeToBoolNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfDateTimeToBoolNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfDateTimeToBoolNullableToJson(this); @@ -827,13 +719,11 @@ class SimpleClassOfDateTimeToBoolNullable { class SimpleClassNullableOfDateTimeToBoolNullable { final Map<DateTime, bool?>? value; - SimpleClassNullableOfDateTimeToBoolNullable( - this.value, - ); + SimpleClassNullableOfDateTimeToBoolNullable(this.value); factory SimpleClassNullableOfDateTimeToBoolNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfDateTimeToBoolNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfDateTimeToBoolNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfDateTimeToBoolNullableToJson(this); @@ -843,13 +733,11 @@ class SimpleClassNullableOfDateTimeToBoolNullable { class SimpleClassOfDynamicToBoolNullable { final Map<dynamic, bool?> value; - SimpleClassOfDynamicToBoolNullable( - this.value, - ); + SimpleClassOfDynamicToBoolNullable(this.value); factory SimpleClassOfDynamicToBoolNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfDynamicToBoolNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfDynamicToBoolNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfDynamicToBoolNullableToJson(this); @@ -859,13 +747,11 @@ class SimpleClassOfDynamicToBoolNullable { class SimpleClassNullableOfDynamicToBoolNullable { final Map<dynamic, bool?>? value; - SimpleClassNullableOfDynamicToBoolNullable( - this.value, - ); + SimpleClassNullableOfDynamicToBoolNullable(this.value); factory SimpleClassNullableOfDynamicToBoolNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfDynamicToBoolNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfDynamicToBoolNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfDynamicToBoolNullableToJson(this); @@ -875,13 +761,11 @@ class SimpleClassNullableOfDynamicToBoolNullable { class SimpleClassOfEnumTypeToBoolNullable { final Map<EnumType, bool?> value; - SimpleClassOfEnumTypeToBoolNullable( - this.value, - ); + SimpleClassOfEnumTypeToBoolNullable(this.value); factory SimpleClassOfEnumTypeToBoolNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfEnumTypeToBoolNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfEnumTypeToBoolNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfEnumTypeToBoolNullableToJson(this); @@ -891,13 +775,11 @@ class SimpleClassOfEnumTypeToBoolNullable { class SimpleClassNullableOfEnumTypeToBoolNullable { final Map<EnumType, bool?>? value; - SimpleClassNullableOfEnumTypeToBoolNullable( - this.value, - ); + SimpleClassNullableOfEnumTypeToBoolNullable(this.value); factory SimpleClassNullableOfEnumTypeToBoolNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfEnumTypeToBoolNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfEnumTypeToBoolNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfEnumTypeToBoolNullableToJson(this); @@ -907,9 +789,7 @@ class SimpleClassNullableOfEnumTypeToBoolNullable { class SimpleClassOfIntToBoolNullable { final Map<int, bool?> value; - SimpleClassOfIntToBoolNullable( - this.value, - ); + SimpleClassOfIntToBoolNullable(this.value); factory SimpleClassOfIntToBoolNullable.fromJson(Map<String, Object?> json) => _$SimpleClassOfIntToBoolNullableFromJson(json); @@ -921,13 +801,11 @@ class SimpleClassOfIntToBoolNullable { class SimpleClassNullableOfIntToBoolNullable { final Map<int, bool?>? value; - SimpleClassNullableOfIntToBoolNullable( - this.value, - ); + SimpleClassNullableOfIntToBoolNullable(this.value); factory SimpleClassNullableOfIntToBoolNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfIntToBoolNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfIntToBoolNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfIntToBoolNullableToJson(this); @@ -937,13 +815,11 @@ class SimpleClassNullableOfIntToBoolNullable { class SimpleClassOfObjectToBoolNullable { final Map<Object, bool?> value; - SimpleClassOfObjectToBoolNullable( - this.value, - ); + SimpleClassOfObjectToBoolNullable(this.value); factory SimpleClassOfObjectToBoolNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfObjectToBoolNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfObjectToBoolNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfObjectToBoolNullableToJson(this); @@ -953,13 +829,11 @@ class SimpleClassOfObjectToBoolNullable { class SimpleClassNullableOfObjectToBoolNullable { final Map<Object, bool?>? value; - SimpleClassNullableOfObjectToBoolNullable( - this.value, - ); + SimpleClassNullableOfObjectToBoolNullable(this.value); factory SimpleClassNullableOfObjectToBoolNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfObjectToBoolNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfObjectToBoolNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfObjectToBoolNullableToJson(this); @@ -969,13 +843,11 @@ class SimpleClassNullableOfObjectToBoolNullable { class SimpleClassOfStringToBoolNullable { final Map<String, bool?> value; - SimpleClassOfStringToBoolNullable( - this.value, - ); + SimpleClassOfStringToBoolNullable(this.value); factory SimpleClassOfStringToBoolNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfStringToBoolNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfStringToBoolNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfStringToBoolNullableToJson(this); @@ -985,13 +857,11 @@ class SimpleClassOfStringToBoolNullable { class SimpleClassNullableOfStringToBoolNullable { final Map<String, bool?>? value; - SimpleClassNullableOfStringToBoolNullable( - this.value, - ); + SimpleClassNullableOfStringToBoolNullable(this.value); factory SimpleClassNullableOfStringToBoolNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfStringToBoolNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfStringToBoolNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfStringToBoolNullableToJson(this); @@ -1001,9 +871,7 @@ class SimpleClassNullableOfStringToBoolNullable { class SimpleClassOfUriToBoolNullable { final Map<Uri, bool?> value; - SimpleClassOfUriToBoolNullable( - this.value, - ); + SimpleClassOfUriToBoolNullable(this.value); factory SimpleClassOfUriToBoolNullable.fromJson(Map<String, Object?> json) => _$SimpleClassOfUriToBoolNullableFromJson(json); @@ -1015,13 +883,11 @@ class SimpleClassOfUriToBoolNullable { class SimpleClassNullableOfUriToBoolNullable { final Map<Uri, bool?>? value; - SimpleClassNullableOfUriToBoolNullable( - this.value, - ); + SimpleClassNullableOfUriToBoolNullable(this.value); factory SimpleClassNullableOfUriToBoolNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfUriToBoolNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfUriToBoolNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfUriToBoolNullableToJson(this); @@ -1031,9 +897,7 @@ class SimpleClassNullableOfUriToBoolNullable { class SimpleClassOfBigIntToDateTime { final Map<BigInt, DateTime> value; - SimpleClassOfBigIntToDateTime( - this.value, - ); + SimpleClassOfBigIntToDateTime(this.value); factory SimpleClassOfBigIntToDateTime.fromJson(Map<String, Object?> json) => _$SimpleClassOfBigIntToDateTimeFromJson(json); @@ -1045,13 +909,11 @@ class SimpleClassOfBigIntToDateTime { class SimpleClassNullableOfBigIntToDateTime { final Map<BigInt, DateTime>? value; - SimpleClassNullableOfBigIntToDateTime( - this.value, - ); + SimpleClassNullableOfBigIntToDateTime(this.value); factory SimpleClassNullableOfBigIntToDateTime.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfBigIntToDateTimeFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfBigIntToDateTimeFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfBigIntToDateTimeToJson(this); @@ -1061,9 +923,7 @@ class SimpleClassNullableOfBigIntToDateTime { class SimpleClassOfDateTimeToDateTime { final Map<DateTime, DateTime> value; - SimpleClassOfDateTimeToDateTime( - this.value, - ); + SimpleClassOfDateTimeToDateTime(this.value); factory SimpleClassOfDateTimeToDateTime.fromJson(Map<String, Object?> json) => _$SimpleClassOfDateTimeToDateTimeFromJson(json); @@ -1076,13 +936,11 @@ class SimpleClassOfDateTimeToDateTime { class SimpleClassNullableOfDateTimeToDateTime { final Map<DateTime, DateTime>? value; - SimpleClassNullableOfDateTimeToDateTime( - this.value, - ); + SimpleClassNullableOfDateTimeToDateTime(this.value); factory SimpleClassNullableOfDateTimeToDateTime.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfDateTimeToDateTimeFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfDateTimeToDateTimeFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfDateTimeToDateTimeToJson(this); @@ -1092,9 +950,7 @@ class SimpleClassNullableOfDateTimeToDateTime { class SimpleClassOfDynamicToDateTime { final Map<dynamic, DateTime> value; - SimpleClassOfDynamicToDateTime( - this.value, - ); + SimpleClassOfDynamicToDateTime(this.value); factory SimpleClassOfDynamicToDateTime.fromJson(Map<String, Object?> json) => _$SimpleClassOfDynamicToDateTimeFromJson(json); @@ -1106,13 +962,11 @@ class SimpleClassOfDynamicToDateTime { class SimpleClassNullableOfDynamicToDateTime { final Map<dynamic, DateTime>? value; - SimpleClassNullableOfDynamicToDateTime( - this.value, - ); + SimpleClassNullableOfDynamicToDateTime(this.value); factory SimpleClassNullableOfDynamicToDateTime.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfDynamicToDateTimeFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfDynamicToDateTimeFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfDynamicToDateTimeToJson(this); @@ -1122,9 +976,7 @@ class SimpleClassNullableOfDynamicToDateTime { class SimpleClassOfEnumTypeToDateTime { final Map<EnumType, DateTime> value; - SimpleClassOfEnumTypeToDateTime( - this.value, - ); + SimpleClassOfEnumTypeToDateTime(this.value); factory SimpleClassOfEnumTypeToDateTime.fromJson(Map<String, Object?> json) => _$SimpleClassOfEnumTypeToDateTimeFromJson(json); @@ -1137,13 +989,11 @@ class SimpleClassOfEnumTypeToDateTime { class SimpleClassNullableOfEnumTypeToDateTime { final Map<EnumType, DateTime>? value; - SimpleClassNullableOfEnumTypeToDateTime( - this.value, - ); + SimpleClassNullableOfEnumTypeToDateTime(this.value); factory SimpleClassNullableOfEnumTypeToDateTime.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfEnumTypeToDateTimeFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfEnumTypeToDateTimeFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfEnumTypeToDateTimeToJson(this); @@ -1153,9 +1003,7 @@ class SimpleClassNullableOfEnumTypeToDateTime { class SimpleClassOfIntToDateTime { final Map<int, DateTime> value; - SimpleClassOfIntToDateTime( - this.value, - ); + SimpleClassOfIntToDateTime(this.value); factory SimpleClassOfIntToDateTime.fromJson(Map<String, Object?> json) => _$SimpleClassOfIntToDateTimeFromJson(json); @@ -1167,13 +1015,11 @@ class SimpleClassOfIntToDateTime { class SimpleClassNullableOfIntToDateTime { final Map<int, DateTime>? value; - SimpleClassNullableOfIntToDateTime( - this.value, - ); + SimpleClassNullableOfIntToDateTime(this.value); factory SimpleClassNullableOfIntToDateTime.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfIntToDateTimeFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfIntToDateTimeFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfIntToDateTimeToJson(this); @@ -1183,9 +1029,7 @@ class SimpleClassNullableOfIntToDateTime { class SimpleClassOfObjectToDateTime { final Map<Object, DateTime> value; - SimpleClassOfObjectToDateTime( - this.value, - ); + SimpleClassOfObjectToDateTime(this.value); factory SimpleClassOfObjectToDateTime.fromJson(Map<String, Object?> json) => _$SimpleClassOfObjectToDateTimeFromJson(json); @@ -1197,13 +1041,11 @@ class SimpleClassOfObjectToDateTime { class SimpleClassNullableOfObjectToDateTime { final Map<Object, DateTime>? value; - SimpleClassNullableOfObjectToDateTime( - this.value, - ); + SimpleClassNullableOfObjectToDateTime(this.value); factory SimpleClassNullableOfObjectToDateTime.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfObjectToDateTimeFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfObjectToDateTimeFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfObjectToDateTimeToJson(this); @@ -1213,9 +1055,7 @@ class SimpleClassNullableOfObjectToDateTime { class SimpleClassOfStringToDateTime { final Map<String, DateTime> value; - SimpleClassOfStringToDateTime( - this.value, - ); + SimpleClassOfStringToDateTime(this.value); factory SimpleClassOfStringToDateTime.fromJson(Map<String, Object?> json) => _$SimpleClassOfStringToDateTimeFromJson(json); @@ -1227,13 +1067,11 @@ class SimpleClassOfStringToDateTime { class SimpleClassNullableOfStringToDateTime { final Map<String, DateTime>? value; - SimpleClassNullableOfStringToDateTime( - this.value, - ); + SimpleClassNullableOfStringToDateTime(this.value); factory SimpleClassNullableOfStringToDateTime.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfStringToDateTimeFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfStringToDateTimeFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfStringToDateTimeToJson(this); @@ -1243,9 +1081,7 @@ class SimpleClassNullableOfStringToDateTime { class SimpleClassOfUriToDateTime { final Map<Uri, DateTime> value; - SimpleClassOfUriToDateTime( - this.value, - ); + SimpleClassOfUriToDateTime(this.value); factory SimpleClassOfUriToDateTime.fromJson(Map<String, Object?> json) => _$SimpleClassOfUriToDateTimeFromJson(json); @@ -1257,13 +1093,11 @@ class SimpleClassOfUriToDateTime { class SimpleClassNullableOfUriToDateTime { final Map<Uri, DateTime>? value; - SimpleClassNullableOfUriToDateTime( - this.value, - ); + SimpleClassNullableOfUriToDateTime(this.value); factory SimpleClassNullableOfUriToDateTime.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfUriToDateTimeFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfUriToDateTimeFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfUriToDateTimeToJson(this); @@ -1273,13 +1107,11 @@ class SimpleClassNullableOfUriToDateTime { class SimpleClassOfBigIntToDateTimeNullable { final Map<BigInt, DateTime?> value; - SimpleClassOfBigIntToDateTimeNullable( - this.value, - ); + SimpleClassOfBigIntToDateTimeNullable(this.value); factory SimpleClassOfBigIntToDateTimeNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfBigIntToDateTimeNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfBigIntToDateTimeNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfBigIntToDateTimeNullableToJson(this); @@ -1289,13 +1121,11 @@ class SimpleClassOfBigIntToDateTimeNullable { class SimpleClassNullableOfBigIntToDateTimeNullable { final Map<BigInt, DateTime?>? value; - SimpleClassNullableOfBigIntToDateTimeNullable( - this.value, - ); + SimpleClassNullableOfBigIntToDateTimeNullable(this.value); factory SimpleClassNullableOfBigIntToDateTimeNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfBigIntToDateTimeNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfBigIntToDateTimeNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfBigIntToDateTimeNullableToJson(this); @@ -1305,13 +1135,11 @@ class SimpleClassNullableOfBigIntToDateTimeNullable { class SimpleClassOfDateTimeToDateTimeNullable { final Map<DateTime, DateTime?> value; - SimpleClassOfDateTimeToDateTimeNullable( - this.value, - ); + SimpleClassOfDateTimeToDateTimeNullable(this.value); factory SimpleClassOfDateTimeToDateTimeNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfDateTimeToDateTimeNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfDateTimeToDateTimeNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfDateTimeToDateTimeNullableToJson(this); @@ -1321,13 +1149,11 @@ class SimpleClassOfDateTimeToDateTimeNullable { class SimpleClassNullableOfDateTimeToDateTimeNullable { final Map<DateTime, DateTime?>? value; - SimpleClassNullableOfDateTimeToDateTimeNullable( - this.value, - ); + SimpleClassNullableOfDateTimeToDateTimeNullable(this.value); factory SimpleClassNullableOfDateTimeToDateTimeNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfDateTimeToDateTimeNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfDateTimeToDateTimeNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfDateTimeToDateTimeNullableToJson(this); @@ -1337,13 +1163,11 @@ class SimpleClassNullableOfDateTimeToDateTimeNullable { class SimpleClassOfDynamicToDateTimeNullable { final Map<dynamic, DateTime?> value; - SimpleClassOfDynamicToDateTimeNullable( - this.value, - ); + SimpleClassOfDynamicToDateTimeNullable(this.value); factory SimpleClassOfDynamicToDateTimeNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfDynamicToDateTimeNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfDynamicToDateTimeNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfDynamicToDateTimeNullableToJson(this); @@ -1353,13 +1177,11 @@ class SimpleClassOfDynamicToDateTimeNullable { class SimpleClassNullableOfDynamicToDateTimeNullable { final Map<dynamic, DateTime?>? value; - SimpleClassNullableOfDynamicToDateTimeNullable( - this.value, - ); + SimpleClassNullableOfDynamicToDateTimeNullable(this.value); factory SimpleClassNullableOfDynamicToDateTimeNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfDynamicToDateTimeNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfDynamicToDateTimeNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfDynamicToDateTimeNullableToJson(this); @@ -1369,13 +1191,11 @@ class SimpleClassNullableOfDynamicToDateTimeNullable { class SimpleClassOfEnumTypeToDateTimeNullable { final Map<EnumType, DateTime?> value; - SimpleClassOfEnumTypeToDateTimeNullable( - this.value, - ); + SimpleClassOfEnumTypeToDateTimeNullable(this.value); factory SimpleClassOfEnumTypeToDateTimeNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfEnumTypeToDateTimeNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfEnumTypeToDateTimeNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfEnumTypeToDateTimeNullableToJson(this); @@ -1385,13 +1205,11 @@ class SimpleClassOfEnumTypeToDateTimeNullable { class SimpleClassNullableOfEnumTypeToDateTimeNullable { final Map<EnumType, DateTime?>? value; - SimpleClassNullableOfEnumTypeToDateTimeNullable( - this.value, - ); + SimpleClassNullableOfEnumTypeToDateTimeNullable(this.value); factory SimpleClassNullableOfEnumTypeToDateTimeNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfEnumTypeToDateTimeNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfEnumTypeToDateTimeNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfEnumTypeToDateTimeNullableToJson(this); @@ -1401,13 +1219,11 @@ class SimpleClassNullableOfEnumTypeToDateTimeNullable { class SimpleClassOfIntToDateTimeNullable { final Map<int, DateTime?> value; - SimpleClassOfIntToDateTimeNullable( - this.value, - ); + SimpleClassOfIntToDateTimeNullable(this.value); factory SimpleClassOfIntToDateTimeNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfIntToDateTimeNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfIntToDateTimeNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfIntToDateTimeNullableToJson(this); @@ -1417,13 +1233,11 @@ class SimpleClassOfIntToDateTimeNullable { class SimpleClassNullableOfIntToDateTimeNullable { final Map<int, DateTime?>? value; - SimpleClassNullableOfIntToDateTimeNullable( - this.value, - ); + SimpleClassNullableOfIntToDateTimeNullable(this.value); factory SimpleClassNullableOfIntToDateTimeNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfIntToDateTimeNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfIntToDateTimeNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfIntToDateTimeNullableToJson(this); @@ -1433,13 +1247,11 @@ class SimpleClassNullableOfIntToDateTimeNullable { class SimpleClassOfObjectToDateTimeNullable { final Map<Object, DateTime?> value; - SimpleClassOfObjectToDateTimeNullable( - this.value, - ); + SimpleClassOfObjectToDateTimeNullable(this.value); factory SimpleClassOfObjectToDateTimeNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfObjectToDateTimeNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfObjectToDateTimeNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfObjectToDateTimeNullableToJson(this); @@ -1449,13 +1261,11 @@ class SimpleClassOfObjectToDateTimeNullable { class SimpleClassNullableOfObjectToDateTimeNullable { final Map<Object, DateTime?>? value; - SimpleClassNullableOfObjectToDateTimeNullable( - this.value, - ); + SimpleClassNullableOfObjectToDateTimeNullable(this.value); factory SimpleClassNullableOfObjectToDateTimeNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfObjectToDateTimeNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfObjectToDateTimeNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfObjectToDateTimeNullableToJson(this); @@ -1465,13 +1275,11 @@ class SimpleClassNullableOfObjectToDateTimeNullable { class SimpleClassOfStringToDateTimeNullable { final Map<String, DateTime?> value; - SimpleClassOfStringToDateTimeNullable( - this.value, - ); + SimpleClassOfStringToDateTimeNullable(this.value); factory SimpleClassOfStringToDateTimeNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfStringToDateTimeNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfStringToDateTimeNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfStringToDateTimeNullableToJson(this); @@ -1481,13 +1289,11 @@ class SimpleClassOfStringToDateTimeNullable { class SimpleClassNullableOfStringToDateTimeNullable { final Map<String, DateTime?>? value; - SimpleClassNullableOfStringToDateTimeNullable( - this.value, - ); + SimpleClassNullableOfStringToDateTimeNullable(this.value); factory SimpleClassNullableOfStringToDateTimeNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfStringToDateTimeNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfStringToDateTimeNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfStringToDateTimeNullableToJson(this); @@ -1497,13 +1303,11 @@ class SimpleClassNullableOfStringToDateTimeNullable { class SimpleClassOfUriToDateTimeNullable { final Map<Uri, DateTime?> value; - SimpleClassOfUriToDateTimeNullable( - this.value, - ); + SimpleClassOfUriToDateTimeNullable(this.value); factory SimpleClassOfUriToDateTimeNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfUriToDateTimeNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfUriToDateTimeNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfUriToDateTimeNullableToJson(this); @@ -1513,13 +1317,11 @@ class SimpleClassOfUriToDateTimeNullable { class SimpleClassNullableOfUriToDateTimeNullable { final Map<Uri, DateTime?>? value; - SimpleClassNullableOfUriToDateTimeNullable( - this.value, - ); + SimpleClassNullableOfUriToDateTimeNullable(this.value); factory SimpleClassNullableOfUriToDateTimeNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfUriToDateTimeNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfUriToDateTimeNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfUriToDateTimeNullableToJson(this); @@ -1529,9 +1331,7 @@ class SimpleClassNullableOfUriToDateTimeNullable { class SimpleClassOfBigIntToDouble { final Map<BigInt, double> value; - SimpleClassOfBigIntToDouble( - this.value, - ); + SimpleClassOfBigIntToDouble(this.value); factory SimpleClassOfBigIntToDouble.fromJson(Map<String, Object?> json) => _$SimpleClassOfBigIntToDoubleFromJson(json); @@ -1543,13 +1343,11 @@ class SimpleClassOfBigIntToDouble { class SimpleClassNullableOfBigIntToDouble { final Map<BigInt, double>? value; - SimpleClassNullableOfBigIntToDouble( - this.value, - ); + SimpleClassNullableOfBigIntToDouble(this.value); factory SimpleClassNullableOfBigIntToDouble.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfBigIntToDoubleFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfBigIntToDoubleFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfBigIntToDoubleToJson(this); @@ -1559,9 +1357,7 @@ class SimpleClassNullableOfBigIntToDouble { class SimpleClassOfDateTimeToDouble { final Map<DateTime, double> value; - SimpleClassOfDateTimeToDouble( - this.value, - ); + SimpleClassOfDateTimeToDouble(this.value); factory SimpleClassOfDateTimeToDouble.fromJson(Map<String, Object?> json) => _$SimpleClassOfDateTimeToDoubleFromJson(json); @@ -1573,13 +1369,11 @@ class SimpleClassOfDateTimeToDouble { class SimpleClassNullableOfDateTimeToDouble { final Map<DateTime, double>? value; - SimpleClassNullableOfDateTimeToDouble( - this.value, - ); + SimpleClassNullableOfDateTimeToDouble(this.value); factory SimpleClassNullableOfDateTimeToDouble.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfDateTimeToDoubleFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfDateTimeToDoubleFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfDateTimeToDoubleToJson(this); @@ -1589,9 +1383,7 @@ class SimpleClassNullableOfDateTimeToDouble { class SimpleClassOfDynamicToDouble { final Map<dynamic, double> value; - SimpleClassOfDynamicToDouble( - this.value, - ); + SimpleClassOfDynamicToDouble(this.value); factory SimpleClassOfDynamicToDouble.fromJson(Map<String, Object?> json) => _$SimpleClassOfDynamicToDoubleFromJson(json); @@ -1603,13 +1395,11 @@ class SimpleClassOfDynamicToDouble { class SimpleClassNullableOfDynamicToDouble { final Map<dynamic, double>? value; - SimpleClassNullableOfDynamicToDouble( - this.value, - ); + SimpleClassNullableOfDynamicToDouble(this.value); factory SimpleClassNullableOfDynamicToDouble.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfDynamicToDoubleFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfDynamicToDoubleFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfDynamicToDoubleToJson(this); @@ -1619,9 +1409,7 @@ class SimpleClassNullableOfDynamicToDouble { class SimpleClassOfEnumTypeToDouble { final Map<EnumType, double> value; - SimpleClassOfEnumTypeToDouble( - this.value, - ); + SimpleClassOfEnumTypeToDouble(this.value); factory SimpleClassOfEnumTypeToDouble.fromJson(Map<String, Object?> json) => _$SimpleClassOfEnumTypeToDoubleFromJson(json); @@ -1633,13 +1421,11 @@ class SimpleClassOfEnumTypeToDouble { class SimpleClassNullableOfEnumTypeToDouble { final Map<EnumType, double>? value; - SimpleClassNullableOfEnumTypeToDouble( - this.value, - ); + SimpleClassNullableOfEnumTypeToDouble(this.value); factory SimpleClassNullableOfEnumTypeToDouble.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfEnumTypeToDoubleFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfEnumTypeToDoubleFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfEnumTypeToDoubleToJson(this); @@ -1649,9 +1435,7 @@ class SimpleClassNullableOfEnumTypeToDouble { class SimpleClassOfIntToDouble { final Map<int, double> value; - SimpleClassOfIntToDouble( - this.value, - ); + SimpleClassOfIntToDouble(this.value); factory SimpleClassOfIntToDouble.fromJson(Map<String, Object?> json) => _$SimpleClassOfIntToDoubleFromJson(json); @@ -1663,13 +1447,11 @@ class SimpleClassOfIntToDouble { class SimpleClassNullableOfIntToDouble { final Map<int, double>? value; - SimpleClassNullableOfIntToDouble( - this.value, - ); + SimpleClassNullableOfIntToDouble(this.value); factory SimpleClassNullableOfIntToDouble.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfIntToDoubleFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfIntToDoubleFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfIntToDoubleToJson(this); @@ -1679,9 +1461,7 @@ class SimpleClassNullableOfIntToDouble { class SimpleClassOfObjectToDouble { final Map<Object, double> value; - SimpleClassOfObjectToDouble( - this.value, - ); + SimpleClassOfObjectToDouble(this.value); factory SimpleClassOfObjectToDouble.fromJson(Map<String, Object?> json) => _$SimpleClassOfObjectToDoubleFromJson(json); @@ -1693,13 +1473,11 @@ class SimpleClassOfObjectToDouble { class SimpleClassNullableOfObjectToDouble { final Map<Object, double>? value; - SimpleClassNullableOfObjectToDouble( - this.value, - ); + SimpleClassNullableOfObjectToDouble(this.value); factory SimpleClassNullableOfObjectToDouble.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfObjectToDoubleFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfObjectToDoubleFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfObjectToDoubleToJson(this); @@ -1709,9 +1487,7 @@ class SimpleClassNullableOfObjectToDouble { class SimpleClassOfStringToDouble { final Map<String, double> value; - SimpleClassOfStringToDouble( - this.value, - ); + SimpleClassOfStringToDouble(this.value); factory SimpleClassOfStringToDouble.fromJson(Map<String, Object?> json) => _$SimpleClassOfStringToDoubleFromJson(json); @@ -1723,13 +1499,11 @@ class SimpleClassOfStringToDouble { class SimpleClassNullableOfStringToDouble { final Map<String, double>? value; - SimpleClassNullableOfStringToDouble( - this.value, - ); + SimpleClassNullableOfStringToDouble(this.value); factory SimpleClassNullableOfStringToDouble.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfStringToDoubleFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfStringToDoubleFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfStringToDoubleToJson(this); @@ -1739,9 +1513,7 @@ class SimpleClassNullableOfStringToDouble { class SimpleClassOfUriToDouble { final Map<Uri, double> value; - SimpleClassOfUriToDouble( - this.value, - ); + SimpleClassOfUriToDouble(this.value); factory SimpleClassOfUriToDouble.fromJson(Map<String, Object?> json) => _$SimpleClassOfUriToDoubleFromJson(json); @@ -1753,13 +1525,11 @@ class SimpleClassOfUriToDouble { class SimpleClassNullableOfUriToDouble { final Map<Uri, double>? value; - SimpleClassNullableOfUriToDouble( - this.value, - ); + SimpleClassNullableOfUriToDouble(this.value); factory SimpleClassNullableOfUriToDouble.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfUriToDoubleFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfUriToDoubleFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfUriToDoubleToJson(this); @@ -1769,13 +1539,11 @@ class SimpleClassNullableOfUriToDouble { class SimpleClassOfBigIntToDoubleNullable { final Map<BigInt, double?> value; - SimpleClassOfBigIntToDoubleNullable( - this.value, - ); + SimpleClassOfBigIntToDoubleNullable(this.value); factory SimpleClassOfBigIntToDoubleNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfBigIntToDoubleNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfBigIntToDoubleNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfBigIntToDoubleNullableToJson(this); @@ -1785,13 +1553,11 @@ class SimpleClassOfBigIntToDoubleNullable { class SimpleClassNullableOfBigIntToDoubleNullable { final Map<BigInt, double?>? value; - SimpleClassNullableOfBigIntToDoubleNullable( - this.value, - ); + SimpleClassNullableOfBigIntToDoubleNullable(this.value); factory SimpleClassNullableOfBigIntToDoubleNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfBigIntToDoubleNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfBigIntToDoubleNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfBigIntToDoubleNullableToJson(this); @@ -1801,13 +1567,11 @@ class SimpleClassNullableOfBigIntToDoubleNullable { class SimpleClassOfDateTimeToDoubleNullable { final Map<DateTime, double?> value; - SimpleClassOfDateTimeToDoubleNullable( - this.value, - ); + SimpleClassOfDateTimeToDoubleNullable(this.value); factory SimpleClassOfDateTimeToDoubleNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfDateTimeToDoubleNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfDateTimeToDoubleNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfDateTimeToDoubleNullableToJson(this); @@ -1817,13 +1581,11 @@ class SimpleClassOfDateTimeToDoubleNullable { class SimpleClassNullableOfDateTimeToDoubleNullable { final Map<DateTime, double?>? value; - SimpleClassNullableOfDateTimeToDoubleNullable( - this.value, - ); + SimpleClassNullableOfDateTimeToDoubleNullable(this.value); factory SimpleClassNullableOfDateTimeToDoubleNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfDateTimeToDoubleNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfDateTimeToDoubleNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfDateTimeToDoubleNullableToJson(this); @@ -1833,13 +1595,11 @@ class SimpleClassNullableOfDateTimeToDoubleNullable { class SimpleClassOfDynamicToDoubleNullable { final Map<dynamic, double?> value; - SimpleClassOfDynamicToDoubleNullable( - this.value, - ); + SimpleClassOfDynamicToDoubleNullable(this.value); factory SimpleClassOfDynamicToDoubleNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfDynamicToDoubleNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfDynamicToDoubleNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfDynamicToDoubleNullableToJson(this); @@ -1849,13 +1609,11 @@ class SimpleClassOfDynamicToDoubleNullable { class SimpleClassNullableOfDynamicToDoubleNullable { final Map<dynamic, double?>? value; - SimpleClassNullableOfDynamicToDoubleNullable( - this.value, - ); + SimpleClassNullableOfDynamicToDoubleNullable(this.value); factory SimpleClassNullableOfDynamicToDoubleNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfDynamicToDoubleNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfDynamicToDoubleNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfDynamicToDoubleNullableToJson(this); @@ -1865,13 +1623,11 @@ class SimpleClassNullableOfDynamicToDoubleNullable { class SimpleClassOfEnumTypeToDoubleNullable { final Map<EnumType, double?> value; - SimpleClassOfEnumTypeToDoubleNullable( - this.value, - ); + SimpleClassOfEnumTypeToDoubleNullable(this.value); factory SimpleClassOfEnumTypeToDoubleNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfEnumTypeToDoubleNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfEnumTypeToDoubleNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfEnumTypeToDoubleNullableToJson(this); @@ -1881,13 +1637,11 @@ class SimpleClassOfEnumTypeToDoubleNullable { class SimpleClassNullableOfEnumTypeToDoubleNullable { final Map<EnumType, double?>? value; - SimpleClassNullableOfEnumTypeToDoubleNullable( - this.value, - ); + SimpleClassNullableOfEnumTypeToDoubleNullable(this.value); factory SimpleClassNullableOfEnumTypeToDoubleNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfEnumTypeToDoubleNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfEnumTypeToDoubleNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfEnumTypeToDoubleNullableToJson(this); @@ -1897,13 +1651,11 @@ class SimpleClassNullableOfEnumTypeToDoubleNullable { class SimpleClassOfIntToDoubleNullable { final Map<int, double?> value; - SimpleClassOfIntToDoubleNullable( - this.value, - ); + SimpleClassOfIntToDoubleNullable(this.value); factory SimpleClassOfIntToDoubleNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfIntToDoubleNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfIntToDoubleNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfIntToDoubleNullableToJson(this); @@ -1913,13 +1665,11 @@ class SimpleClassOfIntToDoubleNullable { class SimpleClassNullableOfIntToDoubleNullable { final Map<int, double?>? value; - SimpleClassNullableOfIntToDoubleNullable( - this.value, - ); + SimpleClassNullableOfIntToDoubleNullable(this.value); factory SimpleClassNullableOfIntToDoubleNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfIntToDoubleNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfIntToDoubleNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfIntToDoubleNullableToJson(this); @@ -1929,13 +1679,11 @@ class SimpleClassNullableOfIntToDoubleNullable { class SimpleClassOfObjectToDoubleNullable { final Map<Object, double?> value; - SimpleClassOfObjectToDoubleNullable( - this.value, - ); + SimpleClassOfObjectToDoubleNullable(this.value); factory SimpleClassOfObjectToDoubleNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfObjectToDoubleNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfObjectToDoubleNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfObjectToDoubleNullableToJson(this); @@ -1945,13 +1693,11 @@ class SimpleClassOfObjectToDoubleNullable { class SimpleClassNullableOfObjectToDoubleNullable { final Map<Object, double?>? value; - SimpleClassNullableOfObjectToDoubleNullable( - this.value, - ); + SimpleClassNullableOfObjectToDoubleNullable(this.value); factory SimpleClassNullableOfObjectToDoubleNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfObjectToDoubleNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfObjectToDoubleNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfObjectToDoubleNullableToJson(this); @@ -1961,13 +1707,11 @@ class SimpleClassNullableOfObjectToDoubleNullable { class SimpleClassOfStringToDoubleNullable { final Map<String, double?> value; - SimpleClassOfStringToDoubleNullable( - this.value, - ); + SimpleClassOfStringToDoubleNullable(this.value); factory SimpleClassOfStringToDoubleNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfStringToDoubleNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfStringToDoubleNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfStringToDoubleNullableToJson(this); @@ -1977,13 +1721,11 @@ class SimpleClassOfStringToDoubleNullable { class SimpleClassNullableOfStringToDoubleNullable { final Map<String, double?>? value; - SimpleClassNullableOfStringToDoubleNullable( - this.value, - ); + SimpleClassNullableOfStringToDoubleNullable(this.value); factory SimpleClassNullableOfStringToDoubleNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfStringToDoubleNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfStringToDoubleNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfStringToDoubleNullableToJson(this); @@ -1993,13 +1735,11 @@ class SimpleClassNullableOfStringToDoubleNullable { class SimpleClassOfUriToDoubleNullable { final Map<Uri, double?> value; - SimpleClassOfUriToDoubleNullable( - this.value, - ); + SimpleClassOfUriToDoubleNullable(this.value); factory SimpleClassOfUriToDoubleNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfUriToDoubleNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfUriToDoubleNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfUriToDoubleNullableToJson(this); @@ -2009,13 +1749,11 @@ class SimpleClassOfUriToDoubleNullable { class SimpleClassNullableOfUriToDoubleNullable { final Map<Uri, double?>? value; - SimpleClassNullableOfUriToDoubleNullable( - this.value, - ); + SimpleClassNullableOfUriToDoubleNullable(this.value); factory SimpleClassNullableOfUriToDoubleNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfUriToDoubleNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfUriToDoubleNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfUriToDoubleNullableToJson(this); @@ -2025,9 +1763,7 @@ class SimpleClassNullableOfUriToDoubleNullable { class SimpleClassOfBigIntToDuration { final Map<BigInt, Duration> value; - SimpleClassOfBigIntToDuration( - this.value, - ); + SimpleClassOfBigIntToDuration(this.value); factory SimpleClassOfBigIntToDuration.fromJson(Map<String, Object?> json) => _$SimpleClassOfBigIntToDurationFromJson(json); @@ -2039,13 +1775,11 @@ class SimpleClassOfBigIntToDuration { class SimpleClassNullableOfBigIntToDuration { final Map<BigInt, Duration>? value; - SimpleClassNullableOfBigIntToDuration( - this.value, - ); + SimpleClassNullableOfBigIntToDuration(this.value); factory SimpleClassNullableOfBigIntToDuration.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfBigIntToDurationFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfBigIntToDurationFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfBigIntToDurationToJson(this); @@ -2055,9 +1789,7 @@ class SimpleClassNullableOfBigIntToDuration { class SimpleClassOfDateTimeToDuration { final Map<DateTime, Duration> value; - SimpleClassOfDateTimeToDuration( - this.value, - ); + SimpleClassOfDateTimeToDuration(this.value); factory SimpleClassOfDateTimeToDuration.fromJson(Map<String, Object?> json) => _$SimpleClassOfDateTimeToDurationFromJson(json); @@ -2070,13 +1802,11 @@ class SimpleClassOfDateTimeToDuration { class SimpleClassNullableOfDateTimeToDuration { final Map<DateTime, Duration>? value; - SimpleClassNullableOfDateTimeToDuration( - this.value, - ); + SimpleClassNullableOfDateTimeToDuration(this.value); factory SimpleClassNullableOfDateTimeToDuration.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfDateTimeToDurationFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfDateTimeToDurationFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfDateTimeToDurationToJson(this); @@ -2086,9 +1816,7 @@ class SimpleClassNullableOfDateTimeToDuration { class SimpleClassOfDynamicToDuration { final Map<dynamic, Duration> value; - SimpleClassOfDynamicToDuration( - this.value, - ); + SimpleClassOfDynamicToDuration(this.value); factory SimpleClassOfDynamicToDuration.fromJson(Map<String, Object?> json) => _$SimpleClassOfDynamicToDurationFromJson(json); @@ -2100,13 +1828,11 @@ class SimpleClassOfDynamicToDuration { class SimpleClassNullableOfDynamicToDuration { final Map<dynamic, Duration>? value; - SimpleClassNullableOfDynamicToDuration( - this.value, - ); + SimpleClassNullableOfDynamicToDuration(this.value); factory SimpleClassNullableOfDynamicToDuration.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfDynamicToDurationFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfDynamicToDurationFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfDynamicToDurationToJson(this); @@ -2116,9 +1842,7 @@ class SimpleClassNullableOfDynamicToDuration { class SimpleClassOfEnumTypeToDuration { final Map<EnumType, Duration> value; - SimpleClassOfEnumTypeToDuration( - this.value, - ); + SimpleClassOfEnumTypeToDuration(this.value); factory SimpleClassOfEnumTypeToDuration.fromJson(Map<String, Object?> json) => _$SimpleClassOfEnumTypeToDurationFromJson(json); @@ -2131,13 +1855,11 @@ class SimpleClassOfEnumTypeToDuration { class SimpleClassNullableOfEnumTypeToDuration { final Map<EnumType, Duration>? value; - SimpleClassNullableOfEnumTypeToDuration( - this.value, - ); + SimpleClassNullableOfEnumTypeToDuration(this.value); factory SimpleClassNullableOfEnumTypeToDuration.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfEnumTypeToDurationFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfEnumTypeToDurationFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfEnumTypeToDurationToJson(this); @@ -2147,9 +1869,7 @@ class SimpleClassNullableOfEnumTypeToDuration { class SimpleClassOfIntToDuration { final Map<int, Duration> value; - SimpleClassOfIntToDuration( - this.value, - ); + SimpleClassOfIntToDuration(this.value); factory SimpleClassOfIntToDuration.fromJson(Map<String, Object?> json) => _$SimpleClassOfIntToDurationFromJson(json); @@ -2161,13 +1881,11 @@ class SimpleClassOfIntToDuration { class SimpleClassNullableOfIntToDuration { final Map<int, Duration>? value; - SimpleClassNullableOfIntToDuration( - this.value, - ); + SimpleClassNullableOfIntToDuration(this.value); factory SimpleClassNullableOfIntToDuration.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfIntToDurationFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfIntToDurationFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfIntToDurationToJson(this); @@ -2177,9 +1895,7 @@ class SimpleClassNullableOfIntToDuration { class SimpleClassOfObjectToDuration { final Map<Object, Duration> value; - SimpleClassOfObjectToDuration( - this.value, - ); + SimpleClassOfObjectToDuration(this.value); factory SimpleClassOfObjectToDuration.fromJson(Map<String, Object?> json) => _$SimpleClassOfObjectToDurationFromJson(json); @@ -2191,13 +1907,11 @@ class SimpleClassOfObjectToDuration { class SimpleClassNullableOfObjectToDuration { final Map<Object, Duration>? value; - SimpleClassNullableOfObjectToDuration( - this.value, - ); + SimpleClassNullableOfObjectToDuration(this.value); factory SimpleClassNullableOfObjectToDuration.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfObjectToDurationFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfObjectToDurationFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfObjectToDurationToJson(this); @@ -2207,9 +1921,7 @@ class SimpleClassNullableOfObjectToDuration { class SimpleClassOfStringToDuration { final Map<String, Duration> value; - SimpleClassOfStringToDuration( - this.value, - ); + SimpleClassOfStringToDuration(this.value); factory SimpleClassOfStringToDuration.fromJson(Map<String, Object?> json) => _$SimpleClassOfStringToDurationFromJson(json); @@ -2221,13 +1933,11 @@ class SimpleClassOfStringToDuration { class SimpleClassNullableOfStringToDuration { final Map<String, Duration>? value; - SimpleClassNullableOfStringToDuration( - this.value, - ); + SimpleClassNullableOfStringToDuration(this.value); factory SimpleClassNullableOfStringToDuration.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfStringToDurationFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfStringToDurationFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfStringToDurationToJson(this); @@ -2237,9 +1947,7 @@ class SimpleClassNullableOfStringToDuration { class SimpleClassOfUriToDuration { final Map<Uri, Duration> value; - SimpleClassOfUriToDuration( - this.value, - ); + SimpleClassOfUriToDuration(this.value); factory SimpleClassOfUriToDuration.fromJson(Map<String, Object?> json) => _$SimpleClassOfUriToDurationFromJson(json); @@ -2251,13 +1959,11 @@ class SimpleClassOfUriToDuration { class SimpleClassNullableOfUriToDuration { final Map<Uri, Duration>? value; - SimpleClassNullableOfUriToDuration( - this.value, - ); + SimpleClassNullableOfUriToDuration(this.value); factory SimpleClassNullableOfUriToDuration.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfUriToDurationFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfUriToDurationFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfUriToDurationToJson(this); @@ -2267,13 +1973,11 @@ class SimpleClassNullableOfUriToDuration { class SimpleClassOfBigIntToDurationNullable { final Map<BigInt, Duration?> value; - SimpleClassOfBigIntToDurationNullable( - this.value, - ); + SimpleClassOfBigIntToDurationNullable(this.value); factory SimpleClassOfBigIntToDurationNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfBigIntToDurationNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfBigIntToDurationNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfBigIntToDurationNullableToJson(this); @@ -2283,13 +1987,11 @@ class SimpleClassOfBigIntToDurationNullable { class SimpleClassNullableOfBigIntToDurationNullable { final Map<BigInt, Duration?>? value; - SimpleClassNullableOfBigIntToDurationNullable( - this.value, - ); + SimpleClassNullableOfBigIntToDurationNullable(this.value); factory SimpleClassNullableOfBigIntToDurationNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfBigIntToDurationNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfBigIntToDurationNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfBigIntToDurationNullableToJson(this); @@ -2299,13 +2001,11 @@ class SimpleClassNullableOfBigIntToDurationNullable { class SimpleClassOfDateTimeToDurationNullable { final Map<DateTime, Duration?> value; - SimpleClassOfDateTimeToDurationNullable( - this.value, - ); + SimpleClassOfDateTimeToDurationNullable(this.value); factory SimpleClassOfDateTimeToDurationNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfDateTimeToDurationNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfDateTimeToDurationNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfDateTimeToDurationNullableToJson(this); @@ -2315,13 +2015,11 @@ class SimpleClassOfDateTimeToDurationNullable { class SimpleClassNullableOfDateTimeToDurationNullable { final Map<DateTime, Duration?>? value; - SimpleClassNullableOfDateTimeToDurationNullable( - this.value, - ); + SimpleClassNullableOfDateTimeToDurationNullable(this.value); factory SimpleClassNullableOfDateTimeToDurationNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfDateTimeToDurationNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfDateTimeToDurationNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfDateTimeToDurationNullableToJson(this); @@ -2331,13 +2029,11 @@ class SimpleClassNullableOfDateTimeToDurationNullable { class SimpleClassOfDynamicToDurationNullable { final Map<dynamic, Duration?> value; - SimpleClassOfDynamicToDurationNullable( - this.value, - ); + SimpleClassOfDynamicToDurationNullable(this.value); factory SimpleClassOfDynamicToDurationNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfDynamicToDurationNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfDynamicToDurationNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfDynamicToDurationNullableToJson(this); @@ -2347,13 +2043,11 @@ class SimpleClassOfDynamicToDurationNullable { class SimpleClassNullableOfDynamicToDurationNullable { final Map<dynamic, Duration?>? value; - SimpleClassNullableOfDynamicToDurationNullable( - this.value, - ); + SimpleClassNullableOfDynamicToDurationNullable(this.value); factory SimpleClassNullableOfDynamicToDurationNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfDynamicToDurationNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfDynamicToDurationNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfDynamicToDurationNullableToJson(this); @@ -2363,13 +2057,11 @@ class SimpleClassNullableOfDynamicToDurationNullable { class SimpleClassOfEnumTypeToDurationNullable { final Map<EnumType, Duration?> value; - SimpleClassOfEnumTypeToDurationNullable( - this.value, - ); + SimpleClassOfEnumTypeToDurationNullable(this.value); factory SimpleClassOfEnumTypeToDurationNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfEnumTypeToDurationNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfEnumTypeToDurationNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfEnumTypeToDurationNullableToJson(this); @@ -2379,13 +2071,11 @@ class SimpleClassOfEnumTypeToDurationNullable { class SimpleClassNullableOfEnumTypeToDurationNullable { final Map<EnumType, Duration?>? value; - SimpleClassNullableOfEnumTypeToDurationNullable( - this.value, - ); + SimpleClassNullableOfEnumTypeToDurationNullable(this.value); factory SimpleClassNullableOfEnumTypeToDurationNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfEnumTypeToDurationNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfEnumTypeToDurationNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfEnumTypeToDurationNullableToJson(this); @@ -2395,13 +2085,11 @@ class SimpleClassNullableOfEnumTypeToDurationNullable { class SimpleClassOfIntToDurationNullable { final Map<int, Duration?> value; - SimpleClassOfIntToDurationNullable( - this.value, - ); + SimpleClassOfIntToDurationNullable(this.value); factory SimpleClassOfIntToDurationNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfIntToDurationNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfIntToDurationNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfIntToDurationNullableToJson(this); @@ -2411,13 +2099,11 @@ class SimpleClassOfIntToDurationNullable { class SimpleClassNullableOfIntToDurationNullable { final Map<int, Duration?>? value; - SimpleClassNullableOfIntToDurationNullable( - this.value, - ); + SimpleClassNullableOfIntToDurationNullable(this.value); factory SimpleClassNullableOfIntToDurationNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfIntToDurationNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfIntToDurationNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfIntToDurationNullableToJson(this); @@ -2427,13 +2113,11 @@ class SimpleClassNullableOfIntToDurationNullable { class SimpleClassOfObjectToDurationNullable { final Map<Object, Duration?> value; - SimpleClassOfObjectToDurationNullable( - this.value, - ); + SimpleClassOfObjectToDurationNullable(this.value); factory SimpleClassOfObjectToDurationNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfObjectToDurationNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfObjectToDurationNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfObjectToDurationNullableToJson(this); @@ -2443,13 +2127,11 @@ class SimpleClassOfObjectToDurationNullable { class SimpleClassNullableOfObjectToDurationNullable { final Map<Object, Duration?>? value; - SimpleClassNullableOfObjectToDurationNullable( - this.value, - ); + SimpleClassNullableOfObjectToDurationNullable(this.value); factory SimpleClassNullableOfObjectToDurationNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfObjectToDurationNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfObjectToDurationNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfObjectToDurationNullableToJson(this); @@ -2459,13 +2141,11 @@ class SimpleClassNullableOfObjectToDurationNullable { class SimpleClassOfStringToDurationNullable { final Map<String, Duration?> value; - SimpleClassOfStringToDurationNullable( - this.value, - ); + SimpleClassOfStringToDurationNullable(this.value); factory SimpleClassOfStringToDurationNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfStringToDurationNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfStringToDurationNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfStringToDurationNullableToJson(this); @@ -2475,13 +2155,11 @@ class SimpleClassOfStringToDurationNullable { class SimpleClassNullableOfStringToDurationNullable { final Map<String, Duration?>? value; - SimpleClassNullableOfStringToDurationNullable( - this.value, - ); + SimpleClassNullableOfStringToDurationNullable(this.value); factory SimpleClassNullableOfStringToDurationNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfStringToDurationNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfStringToDurationNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfStringToDurationNullableToJson(this); @@ -2491,13 +2169,11 @@ class SimpleClassNullableOfStringToDurationNullable { class SimpleClassOfUriToDurationNullable { final Map<Uri, Duration?> value; - SimpleClassOfUriToDurationNullable( - this.value, - ); + SimpleClassOfUriToDurationNullable(this.value); factory SimpleClassOfUriToDurationNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfUriToDurationNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfUriToDurationNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfUriToDurationNullableToJson(this); @@ -2507,13 +2183,11 @@ class SimpleClassOfUriToDurationNullable { class SimpleClassNullableOfUriToDurationNullable { final Map<Uri, Duration?>? value; - SimpleClassNullableOfUriToDurationNullable( - this.value, - ); + SimpleClassNullableOfUriToDurationNullable(this.value); factory SimpleClassNullableOfUriToDurationNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfUriToDurationNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfUriToDurationNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfUriToDurationNullableToJson(this); @@ -2523,9 +2197,7 @@ class SimpleClassNullableOfUriToDurationNullable { class SimpleClassOfBigIntToDynamic { final Map<BigInt, dynamic> value; - SimpleClassOfBigIntToDynamic( - this.value, - ); + SimpleClassOfBigIntToDynamic(this.value); factory SimpleClassOfBigIntToDynamic.fromJson(Map<String, Object?> json) => _$SimpleClassOfBigIntToDynamicFromJson(json); @@ -2537,13 +2209,11 @@ class SimpleClassOfBigIntToDynamic { class SimpleClassNullableOfBigIntToDynamic { final Map<BigInt, dynamic>? value; - SimpleClassNullableOfBigIntToDynamic( - this.value, - ); + SimpleClassNullableOfBigIntToDynamic(this.value); factory SimpleClassNullableOfBigIntToDynamic.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfBigIntToDynamicFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfBigIntToDynamicFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfBigIntToDynamicToJson(this); @@ -2553,9 +2223,7 @@ class SimpleClassNullableOfBigIntToDynamic { class SimpleClassOfDateTimeToDynamic { final Map<DateTime, dynamic> value; - SimpleClassOfDateTimeToDynamic( - this.value, - ); + SimpleClassOfDateTimeToDynamic(this.value); factory SimpleClassOfDateTimeToDynamic.fromJson(Map<String, Object?> json) => _$SimpleClassOfDateTimeToDynamicFromJson(json); @@ -2567,13 +2235,11 @@ class SimpleClassOfDateTimeToDynamic { class SimpleClassNullableOfDateTimeToDynamic { final Map<DateTime, dynamic>? value; - SimpleClassNullableOfDateTimeToDynamic( - this.value, - ); + SimpleClassNullableOfDateTimeToDynamic(this.value); factory SimpleClassNullableOfDateTimeToDynamic.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfDateTimeToDynamicFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfDateTimeToDynamicFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfDateTimeToDynamicToJson(this); @@ -2583,9 +2249,7 @@ class SimpleClassNullableOfDateTimeToDynamic { class SimpleClassOfDynamicToDynamic { final Map<dynamic, dynamic> value; - SimpleClassOfDynamicToDynamic( - this.value, - ); + SimpleClassOfDynamicToDynamic(this.value); factory SimpleClassOfDynamicToDynamic.fromJson(Map<String, Object?> json) => _$SimpleClassOfDynamicToDynamicFromJson(json); @@ -2597,13 +2261,11 @@ class SimpleClassOfDynamicToDynamic { class SimpleClassNullableOfDynamicToDynamic { final Map<dynamic, dynamic>? value; - SimpleClassNullableOfDynamicToDynamic( - this.value, - ); + SimpleClassNullableOfDynamicToDynamic(this.value); factory SimpleClassNullableOfDynamicToDynamic.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfDynamicToDynamicFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfDynamicToDynamicFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfDynamicToDynamicToJson(this); @@ -2613,9 +2275,7 @@ class SimpleClassNullableOfDynamicToDynamic { class SimpleClassOfEnumTypeToDynamic { final Map<EnumType, dynamic> value; - SimpleClassOfEnumTypeToDynamic( - this.value, - ); + SimpleClassOfEnumTypeToDynamic(this.value); factory SimpleClassOfEnumTypeToDynamic.fromJson(Map<String, Object?> json) => _$SimpleClassOfEnumTypeToDynamicFromJson(json); @@ -2627,13 +2287,11 @@ class SimpleClassOfEnumTypeToDynamic { class SimpleClassNullableOfEnumTypeToDynamic { final Map<EnumType, dynamic>? value; - SimpleClassNullableOfEnumTypeToDynamic( - this.value, - ); + SimpleClassNullableOfEnumTypeToDynamic(this.value); factory SimpleClassNullableOfEnumTypeToDynamic.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfEnumTypeToDynamicFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfEnumTypeToDynamicFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfEnumTypeToDynamicToJson(this); @@ -2643,9 +2301,7 @@ class SimpleClassNullableOfEnumTypeToDynamic { class SimpleClassOfIntToDynamic { final Map<int, dynamic> value; - SimpleClassOfIntToDynamic( - this.value, - ); + SimpleClassOfIntToDynamic(this.value); factory SimpleClassOfIntToDynamic.fromJson(Map<String, Object?> json) => _$SimpleClassOfIntToDynamicFromJson(json); @@ -2657,13 +2313,11 @@ class SimpleClassOfIntToDynamic { class SimpleClassNullableOfIntToDynamic { final Map<int, dynamic>? value; - SimpleClassNullableOfIntToDynamic( - this.value, - ); + SimpleClassNullableOfIntToDynamic(this.value); factory SimpleClassNullableOfIntToDynamic.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfIntToDynamicFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfIntToDynamicFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfIntToDynamicToJson(this); @@ -2673,9 +2327,7 @@ class SimpleClassNullableOfIntToDynamic { class SimpleClassOfObjectToDynamic { final Map<Object, dynamic> value; - SimpleClassOfObjectToDynamic( - this.value, - ); + SimpleClassOfObjectToDynamic(this.value); factory SimpleClassOfObjectToDynamic.fromJson(Map<String, Object?> json) => _$SimpleClassOfObjectToDynamicFromJson(json); @@ -2687,13 +2339,11 @@ class SimpleClassOfObjectToDynamic { class SimpleClassNullableOfObjectToDynamic { final Map<Object, dynamic>? value; - SimpleClassNullableOfObjectToDynamic( - this.value, - ); + SimpleClassNullableOfObjectToDynamic(this.value); factory SimpleClassNullableOfObjectToDynamic.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfObjectToDynamicFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfObjectToDynamicFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfObjectToDynamicToJson(this); @@ -2703,9 +2353,7 @@ class SimpleClassNullableOfObjectToDynamic { class SimpleClassOfStringToDynamic { final Map<String, dynamic> value; - SimpleClassOfStringToDynamic( - this.value, - ); + SimpleClassOfStringToDynamic(this.value); factory SimpleClassOfStringToDynamic.fromJson(Map<String, Object?> json) => _$SimpleClassOfStringToDynamicFromJson(json); @@ -2717,13 +2365,11 @@ class SimpleClassOfStringToDynamic { class SimpleClassNullableOfStringToDynamic { final Map<String, dynamic>? value; - SimpleClassNullableOfStringToDynamic( - this.value, - ); + SimpleClassNullableOfStringToDynamic(this.value); factory SimpleClassNullableOfStringToDynamic.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfStringToDynamicFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfStringToDynamicFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfStringToDynamicToJson(this); @@ -2733,9 +2379,7 @@ class SimpleClassNullableOfStringToDynamic { class SimpleClassOfUriToDynamic { final Map<Uri, dynamic> value; - SimpleClassOfUriToDynamic( - this.value, - ); + SimpleClassOfUriToDynamic(this.value); factory SimpleClassOfUriToDynamic.fromJson(Map<String, Object?> json) => _$SimpleClassOfUriToDynamicFromJson(json); @@ -2747,13 +2391,11 @@ class SimpleClassOfUriToDynamic { class SimpleClassNullableOfUriToDynamic { final Map<Uri, dynamic>? value; - SimpleClassNullableOfUriToDynamic( - this.value, - ); + SimpleClassNullableOfUriToDynamic(this.value); factory SimpleClassNullableOfUriToDynamic.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfUriToDynamicFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfUriToDynamicFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfUriToDynamicToJson(this); @@ -2763,9 +2405,7 @@ class SimpleClassNullableOfUriToDynamic { class SimpleClassOfBigIntToEnumType { final Map<BigInt, EnumType> value; - SimpleClassOfBigIntToEnumType( - this.value, - ); + SimpleClassOfBigIntToEnumType(this.value); factory SimpleClassOfBigIntToEnumType.fromJson(Map<String, Object?> json) => _$SimpleClassOfBigIntToEnumTypeFromJson(json); @@ -2777,13 +2417,11 @@ class SimpleClassOfBigIntToEnumType { class SimpleClassNullableOfBigIntToEnumType { final Map<BigInt, EnumType>? value; - SimpleClassNullableOfBigIntToEnumType( - this.value, - ); + SimpleClassNullableOfBigIntToEnumType(this.value); factory SimpleClassNullableOfBigIntToEnumType.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfBigIntToEnumTypeFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfBigIntToEnumTypeFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfBigIntToEnumTypeToJson(this); @@ -2793,9 +2431,7 @@ class SimpleClassNullableOfBigIntToEnumType { class SimpleClassOfDateTimeToEnumType { final Map<DateTime, EnumType> value; - SimpleClassOfDateTimeToEnumType( - this.value, - ); + SimpleClassOfDateTimeToEnumType(this.value); factory SimpleClassOfDateTimeToEnumType.fromJson(Map<String, Object?> json) => _$SimpleClassOfDateTimeToEnumTypeFromJson(json); @@ -2808,13 +2444,11 @@ class SimpleClassOfDateTimeToEnumType { class SimpleClassNullableOfDateTimeToEnumType { final Map<DateTime, EnumType>? value; - SimpleClassNullableOfDateTimeToEnumType( - this.value, - ); + SimpleClassNullableOfDateTimeToEnumType(this.value); factory SimpleClassNullableOfDateTimeToEnumType.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfDateTimeToEnumTypeFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfDateTimeToEnumTypeFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfDateTimeToEnumTypeToJson(this); @@ -2824,9 +2458,7 @@ class SimpleClassNullableOfDateTimeToEnumType { class SimpleClassOfDynamicToEnumType { final Map<dynamic, EnumType> value; - SimpleClassOfDynamicToEnumType( - this.value, - ); + SimpleClassOfDynamicToEnumType(this.value); factory SimpleClassOfDynamicToEnumType.fromJson(Map<String, Object?> json) => _$SimpleClassOfDynamicToEnumTypeFromJson(json); @@ -2838,13 +2470,11 @@ class SimpleClassOfDynamicToEnumType { class SimpleClassNullableOfDynamicToEnumType { final Map<dynamic, EnumType>? value; - SimpleClassNullableOfDynamicToEnumType( - this.value, - ); + SimpleClassNullableOfDynamicToEnumType(this.value); factory SimpleClassNullableOfDynamicToEnumType.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfDynamicToEnumTypeFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfDynamicToEnumTypeFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfDynamicToEnumTypeToJson(this); @@ -2854,9 +2484,7 @@ class SimpleClassNullableOfDynamicToEnumType { class SimpleClassOfEnumTypeToEnumType { final Map<EnumType, EnumType> value; - SimpleClassOfEnumTypeToEnumType( - this.value, - ); + SimpleClassOfEnumTypeToEnumType(this.value); factory SimpleClassOfEnumTypeToEnumType.fromJson(Map<String, Object?> json) => _$SimpleClassOfEnumTypeToEnumTypeFromJson(json); @@ -2869,13 +2497,11 @@ class SimpleClassOfEnumTypeToEnumType { class SimpleClassNullableOfEnumTypeToEnumType { final Map<EnumType, EnumType>? value; - SimpleClassNullableOfEnumTypeToEnumType( - this.value, - ); + SimpleClassNullableOfEnumTypeToEnumType(this.value); factory SimpleClassNullableOfEnumTypeToEnumType.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfEnumTypeToEnumTypeFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfEnumTypeToEnumTypeFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfEnumTypeToEnumTypeToJson(this); @@ -2885,9 +2511,7 @@ class SimpleClassNullableOfEnumTypeToEnumType { class SimpleClassOfIntToEnumType { final Map<int, EnumType> value; - SimpleClassOfIntToEnumType( - this.value, - ); + SimpleClassOfIntToEnumType(this.value); factory SimpleClassOfIntToEnumType.fromJson(Map<String, Object?> json) => _$SimpleClassOfIntToEnumTypeFromJson(json); @@ -2899,13 +2523,11 @@ class SimpleClassOfIntToEnumType { class SimpleClassNullableOfIntToEnumType { final Map<int, EnumType>? value; - SimpleClassNullableOfIntToEnumType( - this.value, - ); + SimpleClassNullableOfIntToEnumType(this.value); factory SimpleClassNullableOfIntToEnumType.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfIntToEnumTypeFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfIntToEnumTypeFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfIntToEnumTypeToJson(this); @@ -2915,9 +2537,7 @@ class SimpleClassNullableOfIntToEnumType { class SimpleClassOfObjectToEnumType { final Map<Object, EnumType> value; - SimpleClassOfObjectToEnumType( - this.value, - ); + SimpleClassOfObjectToEnumType(this.value); factory SimpleClassOfObjectToEnumType.fromJson(Map<String, Object?> json) => _$SimpleClassOfObjectToEnumTypeFromJson(json); @@ -2929,13 +2549,11 @@ class SimpleClassOfObjectToEnumType { class SimpleClassNullableOfObjectToEnumType { final Map<Object, EnumType>? value; - SimpleClassNullableOfObjectToEnumType( - this.value, - ); + SimpleClassNullableOfObjectToEnumType(this.value); factory SimpleClassNullableOfObjectToEnumType.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfObjectToEnumTypeFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfObjectToEnumTypeFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfObjectToEnumTypeToJson(this); @@ -2945,9 +2563,7 @@ class SimpleClassNullableOfObjectToEnumType { class SimpleClassOfStringToEnumType { final Map<String, EnumType> value; - SimpleClassOfStringToEnumType( - this.value, - ); + SimpleClassOfStringToEnumType(this.value); factory SimpleClassOfStringToEnumType.fromJson(Map<String, Object?> json) => _$SimpleClassOfStringToEnumTypeFromJson(json); @@ -2959,13 +2575,11 @@ class SimpleClassOfStringToEnumType { class SimpleClassNullableOfStringToEnumType { final Map<String, EnumType>? value; - SimpleClassNullableOfStringToEnumType( - this.value, - ); + SimpleClassNullableOfStringToEnumType(this.value); factory SimpleClassNullableOfStringToEnumType.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfStringToEnumTypeFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfStringToEnumTypeFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfStringToEnumTypeToJson(this); @@ -2975,9 +2589,7 @@ class SimpleClassNullableOfStringToEnumType { class SimpleClassOfUriToEnumType { final Map<Uri, EnumType> value; - SimpleClassOfUriToEnumType( - this.value, - ); + SimpleClassOfUriToEnumType(this.value); factory SimpleClassOfUriToEnumType.fromJson(Map<String, Object?> json) => _$SimpleClassOfUriToEnumTypeFromJson(json); @@ -2989,13 +2601,11 @@ class SimpleClassOfUriToEnumType { class SimpleClassNullableOfUriToEnumType { final Map<Uri, EnumType>? value; - SimpleClassNullableOfUriToEnumType( - this.value, - ); + SimpleClassNullableOfUriToEnumType(this.value); factory SimpleClassNullableOfUriToEnumType.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfUriToEnumTypeFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfUriToEnumTypeFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfUriToEnumTypeToJson(this); @@ -3005,13 +2615,11 @@ class SimpleClassNullableOfUriToEnumType { class SimpleClassOfBigIntToEnumTypeNullable { final Map<BigInt, EnumType?> value; - SimpleClassOfBigIntToEnumTypeNullable( - this.value, - ); + SimpleClassOfBigIntToEnumTypeNullable(this.value); factory SimpleClassOfBigIntToEnumTypeNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfBigIntToEnumTypeNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfBigIntToEnumTypeNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfBigIntToEnumTypeNullableToJson(this); @@ -3021,13 +2629,11 @@ class SimpleClassOfBigIntToEnumTypeNullable { class SimpleClassNullableOfBigIntToEnumTypeNullable { final Map<BigInt, EnumType?>? value; - SimpleClassNullableOfBigIntToEnumTypeNullable( - this.value, - ); + SimpleClassNullableOfBigIntToEnumTypeNullable(this.value); factory SimpleClassNullableOfBigIntToEnumTypeNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfBigIntToEnumTypeNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfBigIntToEnumTypeNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfBigIntToEnumTypeNullableToJson(this); @@ -3037,13 +2643,11 @@ class SimpleClassNullableOfBigIntToEnumTypeNullable { class SimpleClassOfDateTimeToEnumTypeNullable { final Map<DateTime, EnumType?> value; - SimpleClassOfDateTimeToEnumTypeNullable( - this.value, - ); + SimpleClassOfDateTimeToEnumTypeNullable(this.value); factory SimpleClassOfDateTimeToEnumTypeNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfDateTimeToEnumTypeNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfDateTimeToEnumTypeNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfDateTimeToEnumTypeNullableToJson(this); @@ -3053,13 +2657,11 @@ class SimpleClassOfDateTimeToEnumTypeNullable { class SimpleClassNullableOfDateTimeToEnumTypeNullable { final Map<DateTime, EnumType?>? value; - SimpleClassNullableOfDateTimeToEnumTypeNullable( - this.value, - ); + SimpleClassNullableOfDateTimeToEnumTypeNullable(this.value); factory SimpleClassNullableOfDateTimeToEnumTypeNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfDateTimeToEnumTypeNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfDateTimeToEnumTypeNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfDateTimeToEnumTypeNullableToJson(this); @@ -3069,13 +2671,11 @@ class SimpleClassNullableOfDateTimeToEnumTypeNullable { class SimpleClassOfDynamicToEnumTypeNullable { final Map<dynamic, EnumType?> value; - SimpleClassOfDynamicToEnumTypeNullable( - this.value, - ); + SimpleClassOfDynamicToEnumTypeNullable(this.value); factory SimpleClassOfDynamicToEnumTypeNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfDynamicToEnumTypeNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfDynamicToEnumTypeNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfDynamicToEnumTypeNullableToJson(this); @@ -3085,13 +2685,11 @@ class SimpleClassOfDynamicToEnumTypeNullable { class SimpleClassNullableOfDynamicToEnumTypeNullable { final Map<dynamic, EnumType?>? value; - SimpleClassNullableOfDynamicToEnumTypeNullable( - this.value, - ); + SimpleClassNullableOfDynamicToEnumTypeNullable(this.value); factory SimpleClassNullableOfDynamicToEnumTypeNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfDynamicToEnumTypeNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfDynamicToEnumTypeNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfDynamicToEnumTypeNullableToJson(this); @@ -3101,13 +2699,11 @@ class SimpleClassNullableOfDynamicToEnumTypeNullable { class SimpleClassOfEnumTypeToEnumTypeNullable { final Map<EnumType, EnumType?> value; - SimpleClassOfEnumTypeToEnumTypeNullable( - this.value, - ); + SimpleClassOfEnumTypeToEnumTypeNullable(this.value); factory SimpleClassOfEnumTypeToEnumTypeNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfEnumTypeToEnumTypeNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfEnumTypeToEnumTypeNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfEnumTypeToEnumTypeNullableToJson(this); @@ -3117,13 +2713,11 @@ class SimpleClassOfEnumTypeToEnumTypeNullable { class SimpleClassNullableOfEnumTypeToEnumTypeNullable { final Map<EnumType, EnumType?>? value; - SimpleClassNullableOfEnumTypeToEnumTypeNullable( - this.value, - ); + SimpleClassNullableOfEnumTypeToEnumTypeNullable(this.value); factory SimpleClassNullableOfEnumTypeToEnumTypeNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfEnumTypeToEnumTypeNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfEnumTypeToEnumTypeNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfEnumTypeToEnumTypeNullableToJson(this); @@ -3133,13 +2727,11 @@ class SimpleClassNullableOfEnumTypeToEnumTypeNullable { class SimpleClassOfIntToEnumTypeNullable { final Map<int, EnumType?> value; - SimpleClassOfIntToEnumTypeNullable( - this.value, - ); + SimpleClassOfIntToEnumTypeNullable(this.value); factory SimpleClassOfIntToEnumTypeNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfIntToEnumTypeNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfIntToEnumTypeNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfIntToEnumTypeNullableToJson(this); @@ -3149,13 +2741,11 @@ class SimpleClassOfIntToEnumTypeNullable { class SimpleClassNullableOfIntToEnumTypeNullable { final Map<int, EnumType?>? value; - SimpleClassNullableOfIntToEnumTypeNullable( - this.value, - ); + SimpleClassNullableOfIntToEnumTypeNullable(this.value); factory SimpleClassNullableOfIntToEnumTypeNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfIntToEnumTypeNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfIntToEnumTypeNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfIntToEnumTypeNullableToJson(this); @@ -3165,13 +2755,11 @@ class SimpleClassNullableOfIntToEnumTypeNullable { class SimpleClassOfObjectToEnumTypeNullable { final Map<Object, EnumType?> value; - SimpleClassOfObjectToEnumTypeNullable( - this.value, - ); + SimpleClassOfObjectToEnumTypeNullable(this.value); factory SimpleClassOfObjectToEnumTypeNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfObjectToEnumTypeNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfObjectToEnumTypeNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfObjectToEnumTypeNullableToJson(this); @@ -3181,13 +2769,11 @@ class SimpleClassOfObjectToEnumTypeNullable { class SimpleClassNullableOfObjectToEnumTypeNullable { final Map<Object, EnumType?>? value; - SimpleClassNullableOfObjectToEnumTypeNullable( - this.value, - ); + SimpleClassNullableOfObjectToEnumTypeNullable(this.value); factory SimpleClassNullableOfObjectToEnumTypeNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfObjectToEnumTypeNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfObjectToEnumTypeNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfObjectToEnumTypeNullableToJson(this); @@ -3197,13 +2783,11 @@ class SimpleClassNullableOfObjectToEnumTypeNullable { class SimpleClassOfStringToEnumTypeNullable { final Map<String, EnumType?> value; - SimpleClassOfStringToEnumTypeNullable( - this.value, - ); + SimpleClassOfStringToEnumTypeNullable(this.value); factory SimpleClassOfStringToEnumTypeNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfStringToEnumTypeNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfStringToEnumTypeNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfStringToEnumTypeNullableToJson(this); @@ -3213,13 +2797,11 @@ class SimpleClassOfStringToEnumTypeNullable { class SimpleClassNullableOfStringToEnumTypeNullable { final Map<String, EnumType?>? value; - SimpleClassNullableOfStringToEnumTypeNullable( - this.value, - ); + SimpleClassNullableOfStringToEnumTypeNullable(this.value); factory SimpleClassNullableOfStringToEnumTypeNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfStringToEnumTypeNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfStringToEnumTypeNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfStringToEnumTypeNullableToJson(this); @@ -3229,13 +2811,11 @@ class SimpleClassNullableOfStringToEnumTypeNullable { class SimpleClassOfUriToEnumTypeNullable { final Map<Uri, EnumType?> value; - SimpleClassOfUriToEnumTypeNullable( - this.value, - ); + SimpleClassOfUriToEnumTypeNullable(this.value); factory SimpleClassOfUriToEnumTypeNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfUriToEnumTypeNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfUriToEnumTypeNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfUriToEnumTypeNullableToJson(this); @@ -3245,13 +2825,11 @@ class SimpleClassOfUriToEnumTypeNullable { class SimpleClassNullableOfUriToEnumTypeNullable { final Map<Uri, EnumType?>? value; - SimpleClassNullableOfUriToEnumTypeNullable( - this.value, - ); + SimpleClassNullableOfUriToEnumTypeNullable(this.value); factory SimpleClassNullableOfUriToEnumTypeNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfUriToEnumTypeNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfUriToEnumTypeNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfUriToEnumTypeNullableToJson(this); @@ -3261,13 +2839,11 @@ class SimpleClassNullableOfUriToEnumTypeNullable { class SimpleClassOfBigIntToFromJsonDynamicParam { final Map<BigInt, FromJsonDynamicParam> value; - SimpleClassOfBigIntToFromJsonDynamicParam( - this.value, - ); + SimpleClassOfBigIntToFromJsonDynamicParam(this.value); factory SimpleClassOfBigIntToFromJsonDynamicParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfBigIntToFromJsonDynamicParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfBigIntToFromJsonDynamicParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfBigIntToFromJsonDynamicParamToJson(this); @@ -3277,13 +2853,11 @@ class SimpleClassOfBigIntToFromJsonDynamicParam { class SimpleClassNullableOfBigIntToFromJsonDynamicParam { final Map<BigInt, FromJsonDynamicParam>? value; - SimpleClassNullableOfBigIntToFromJsonDynamicParam( - this.value, - ); + SimpleClassNullableOfBigIntToFromJsonDynamicParam(this.value); factory SimpleClassNullableOfBigIntToFromJsonDynamicParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfBigIntToFromJsonDynamicParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfBigIntToFromJsonDynamicParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfBigIntToFromJsonDynamicParamToJson(this); @@ -3293,13 +2867,11 @@ class SimpleClassNullableOfBigIntToFromJsonDynamicParam { class SimpleClassOfDateTimeToFromJsonDynamicParam { final Map<DateTime, FromJsonDynamicParam> value; - SimpleClassOfDateTimeToFromJsonDynamicParam( - this.value, - ); + SimpleClassOfDateTimeToFromJsonDynamicParam(this.value); factory SimpleClassOfDateTimeToFromJsonDynamicParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfDateTimeToFromJsonDynamicParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfDateTimeToFromJsonDynamicParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfDateTimeToFromJsonDynamicParamToJson(this); @@ -3309,13 +2881,11 @@ class SimpleClassOfDateTimeToFromJsonDynamicParam { class SimpleClassNullableOfDateTimeToFromJsonDynamicParam { final Map<DateTime, FromJsonDynamicParam>? value; - SimpleClassNullableOfDateTimeToFromJsonDynamicParam( - this.value, - ); + SimpleClassNullableOfDateTimeToFromJsonDynamicParam(this.value); factory SimpleClassNullableOfDateTimeToFromJsonDynamicParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfDateTimeToFromJsonDynamicParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfDateTimeToFromJsonDynamicParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfDateTimeToFromJsonDynamicParamToJson(this); @@ -3325,13 +2895,11 @@ class SimpleClassNullableOfDateTimeToFromJsonDynamicParam { class SimpleClassOfDynamicToFromJsonDynamicParam { final Map<dynamic, FromJsonDynamicParam> value; - SimpleClassOfDynamicToFromJsonDynamicParam( - this.value, - ); + SimpleClassOfDynamicToFromJsonDynamicParam(this.value); factory SimpleClassOfDynamicToFromJsonDynamicParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfDynamicToFromJsonDynamicParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfDynamicToFromJsonDynamicParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfDynamicToFromJsonDynamicParamToJson(this); @@ -3341,13 +2909,11 @@ class SimpleClassOfDynamicToFromJsonDynamicParam { class SimpleClassNullableOfDynamicToFromJsonDynamicParam { final Map<dynamic, FromJsonDynamicParam>? value; - SimpleClassNullableOfDynamicToFromJsonDynamicParam( - this.value, - ); + SimpleClassNullableOfDynamicToFromJsonDynamicParam(this.value); factory SimpleClassNullableOfDynamicToFromJsonDynamicParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfDynamicToFromJsonDynamicParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfDynamicToFromJsonDynamicParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfDynamicToFromJsonDynamicParamToJson(this); @@ -3357,13 +2923,11 @@ class SimpleClassNullableOfDynamicToFromJsonDynamicParam { class SimpleClassOfEnumTypeToFromJsonDynamicParam { final Map<EnumType, FromJsonDynamicParam> value; - SimpleClassOfEnumTypeToFromJsonDynamicParam( - this.value, - ); + SimpleClassOfEnumTypeToFromJsonDynamicParam(this.value); factory SimpleClassOfEnumTypeToFromJsonDynamicParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfEnumTypeToFromJsonDynamicParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfEnumTypeToFromJsonDynamicParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfEnumTypeToFromJsonDynamicParamToJson(this); @@ -3373,13 +2937,11 @@ class SimpleClassOfEnumTypeToFromJsonDynamicParam { class SimpleClassNullableOfEnumTypeToFromJsonDynamicParam { final Map<EnumType, FromJsonDynamicParam>? value; - SimpleClassNullableOfEnumTypeToFromJsonDynamicParam( - this.value, - ); + SimpleClassNullableOfEnumTypeToFromJsonDynamicParam(this.value); factory SimpleClassNullableOfEnumTypeToFromJsonDynamicParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfEnumTypeToFromJsonDynamicParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfEnumTypeToFromJsonDynamicParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfEnumTypeToFromJsonDynamicParamToJson(this); @@ -3389,13 +2951,11 @@ class SimpleClassNullableOfEnumTypeToFromJsonDynamicParam { class SimpleClassOfIntToFromJsonDynamicParam { final Map<int, FromJsonDynamicParam> value; - SimpleClassOfIntToFromJsonDynamicParam( - this.value, - ); + SimpleClassOfIntToFromJsonDynamicParam(this.value); factory SimpleClassOfIntToFromJsonDynamicParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfIntToFromJsonDynamicParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfIntToFromJsonDynamicParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfIntToFromJsonDynamicParamToJson(this); @@ -3405,13 +2965,11 @@ class SimpleClassOfIntToFromJsonDynamicParam { class SimpleClassNullableOfIntToFromJsonDynamicParam { final Map<int, FromJsonDynamicParam>? value; - SimpleClassNullableOfIntToFromJsonDynamicParam( - this.value, - ); + SimpleClassNullableOfIntToFromJsonDynamicParam(this.value); factory SimpleClassNullableOfIntToFromJsonDynamicParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfIntToFromJsonDynamicParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfIntToFromJsonDynamicParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfIntToFromJsonDynamicParamToJson(this); @@ -3421,13 +2979,11 @@ class SimpleClassNullableOfIntToFromJsonDynamicParam { class SimpleClassOfObjectToFromJsonDynamicParam { final Map<Object, FromJsonDynamicParam> value; - SimpleClassOfObjectToFromJsonDynamicParam( - this.value, - ); + SimpleClassOfObjectToFromJsonDynamicParam(this.value); factory SimpleClassOfObjectToFromJsonDynamicParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfObjectToFromJsonDynamicParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfObjectToFromJsonDynamicParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfObjectToFromJsonDynamicParamToJson(this); @@ -3437,13 +2993,11 @@ class SimpleClassOfObjectToFromJsonDynamicParam { class SimpleClassNullableOfObjectToFromJsonDynamicParam { final Map<Object, FromJsonDynamicParam>? value; - SimpleClassNullableOfObjectToFromJsonDynamicParam( - this.value, - ); + SimpleClassNullableOfObjectToFromJsonDynamicParam(this.value); factory SimpleClassNullableOfObjectToFromJsonDynamicParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfObjectToFromJsonDynamicParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfObjectToFromJsonDynamicParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfObjectToFromJsonDynamicParamToJson(this); @@ -3453,13 +3007,11 @@ class SimpleClassNullableOfObjectToFromJsonDynamicParam { class SimpleClassOfStringToFromJsonDynamicParam { final Map<String, FromJsonDynamicParam> value; - SimpleClassOfStringToFromJsonDynamicParam( - this.value, - ); + SimpleClassOfStringToFromJsonDynamicParam(this.value); factory SimpleClassOfStringToFromJsonDynamicParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfStringToFromJsonDynamicParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfStringToFromJsonDynamicParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfStringToFromJsonDynamicParamToJson(this); @@ -3469,13 +3021,11 @@ class SimpleClassOfStringToFromJsonDynamicParam { class SimpleClassNullableOfStringToFromJsonDynamicParam { final Map<String, FromJsonDynamicParam>? value; - SimpleClassNullableOfStringToFromJsonDynamicParam( - this.value, - ); + SimpleClassNullableOfStringToFromJsonDynamicParam(this.value); factory SimpleClassNullableOfStringToFromJsonDynamicParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfStringToFromJsonDynamicParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfStringToFromJsonDynamicParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfStringToFromJsonDynamicParamToJson(this); @@ -3485,13 +3035,11 @@ class SimpleClassNullableOfStringToFromJsonDynamicParam { class SimpleClassOfUriToFromJsonDynamicParam { final Map<Uri, FromJsonDynamicParam> value; - SimpleClassOfUriToFromJsonDynamicParam( - this.value, - ); + SimpleClassOfUriToFromJsonDynamicParam(this.value); factory SimpleClassOfUriToFromJsonDynamicParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfUriToFromJsonDynamicParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfUriToFromJsonDynamicParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfUriToFromJsonDynamicParamToJson(this); @@ -3501,13 +3049,11 @@ class SimpleClassOfUriToFromJsonDynamicParam { class SimpleClassNullableOfUriToFromJsonDynamicParam { final Map<Uri, FromJsonDynamicParam>? value; - SimpleClassNullableOfUriToFromJsonDynamicParam( - this.value, - ); + SimpleClassNullableOfUriToFromJsonDynamicParam(this.value); factory SimpleClassNullableOfUriToFromJsonDynamicParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfUriToFromJsonDynamicParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfUriToFromJsonDynamicParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfUriToFromJsonDynamicParamToJson(this); @@ -3517,13 +3063,11 @@ class SimpleClassNullableOfUriToFromJsonDynamicParam { class SimpleClassOfBigIntToFromJsonNullableObjectParam { final Map<BigInt, FromJsonNullableObjectParam> value; - SimpleClassOfBigIntToFromJsonNullableObjectParam( - this.value, - ); + SimpleClassOfBigIntToFromJsonNullableObjectParam(this.value); factory SimpleClassOfBigIntToFromJsonNullableObjectParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfBigIntToFromJsonNullableObjectParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfBigIntToFromJsonNullableObjectParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfBigIntToFromJsonNullableObjectParamToJson(this); @@ -3533,13 +3077,11 @@ class SimpleClassOfBigIntToFromJsonNullableObjectParam { class SimpleClassNullableOfBigIntToFromJsonNullableObjectParam { final Map<BigInt, FromJsonNullableObjectParam>? value; - SimpleClassNullableOfBigIntToFromJsonNullableObjectParam( - this.value, - ); + SimpleClassNullableOfBigIntToFromJsonNullableObjectParam(this.value); factory SimpleClassNullableOfBigIntToFromJsonNullableObjectParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfBigIntToFromJsonNullableObjectParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfBigIntToFromJsonNullableObjectParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfBigIntToFromJsonNullableObjectParamToJson(this); @@ -3549,13 +3091,11 @@ class SimpleClassNullableOfBigIntToFromJsonNullableObjectParam { class SimpleClassOfDateTimeToFromJsonNullableObjectParam { final Map<DateTime, FromJsonNullableObjectParam> value; - SimpleClassOfDateTimeToFromJsonNullableObjectParam( - this.value, - ); + SimpleClassOfDateTimeToFromJsonNullableObjectParam(this.value); factory SimpleClassOfDateTimeToFromJsonNullableObjectParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfDateTimeToFromJsonNullableObjectParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfDateTimeToFromJsonNullableObjectParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfDateTimeToFromJsonNullableObjectParamToJson(this); @@ -3565,14 +3105,13 @@ class SimpleClassOfDateTimeToFromJsonNullableObjectParam { class SimpleClassNullableOfDateTimeToFromJsonNullableObjectParam { final Map<DateTime, FromJsonNullableObjectParam>? value; - SimpleClassNullableOfDateTimeToFromJsonNullableObjectParam( - this.value, - ); + SimpleClassNullableOfDateTimeToFromJsonNullableObjectParam(this.value); factory SimpleClassNullableOfDateTimeToFromJsonNullableObjectParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfDateTimeToFromJsonNullableObjectParamFromJson( - json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfDateTimeToFromJsonNullableObjectParamFromJson( + json, + ); Map<String, Object?> toJson() => _$SimpleClassNullableOfDateTimeToFromJsonNullableObjectParamToJson(this); @@ -3582,13 +3121,11 @@ class SimpleClassNullableOfDateTimeToFromJsonNullableObjectParam { class SimpleClassOfDynamicToFromJsonNullableObjectParam { final Map<dynamic, FromJsonNullableObjectParam> value; - SimpleClassOfDynamicToFromJsonNullableObjectParam( - this.value, - ); + SimpleClassOfDynamicToFromJsonNullableObjectParam(this.value); factory SimpleClassOfDynamicToFromJsonNullableObjectParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfDynamicToFromJsonNullableObjectParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfDynamicToFromJsonNullableObjectParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfDynamicToFromJsonNullableObjectParamToJson(this); @@ -3598,12 +3135,11 @@ class SimpleClassOfDynamicToFromJsonNullableObjectParam { class SimpleClassNullableOfDynamicToFromJsonNullableObjectParam { final Map<dynamic, FromJsonNullableObjectParam>? value; - SimpleClassNullableOfDynamicToFromJsonNullableObjectParam( - this.value, - ); + SimpleClassNullableOfDynamicToFromJsonNullableObjectParam(this.value); factory SimpleClassNullableOfDynamicToFromJsonNullableObjectParam.fromJson( - Map<String, Object?> json) => + Map<String, Object?> json, + ) => _$SimpleClassNullableOfDynamicToFromJsonNullableObjectParamFromJson(json); Map<String, Object?> toJson() => @@ -3614,13 +3150,11 @@ class SimpleClassNullableOfDynamicToFromJsonNullableObjectParam { class SimpleClassOfEnumTypeToFromJsonNullableObjectParam { final Map<EnumType, FromJsonNullableObjectParam> value; - SimpleClassOfEnumTypeToFromJsonNullableObjectParam( - this.value, - ); + SimpleClassOfEnumTypeToFromJsonNullableObjectParam(this.value); factory SimpleClassOfEnumTypeToFromJsonNullableObjectParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfEnumTypeToFromJsonNullableObjectParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfEnumTypeToFromJsonNullableObjectParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfEnumTypeToFromJsonNullableObjectParamToJson(this); @@ -3630,14 +3164,13 @@ class SimpleClassOfEnumTypeToFromJsonNullableObjectParam { class SimpleClassNullableOfEnumTypeToFromJsonNullableObjectParam { final Map<EnumType, FromJsonNullableObjectParam>? value; - SimpleClassNullableOfEnumTypeToFromJsonNullableObjectParam( - this.value, - ); + SimpleClassNullableOfEnumTypeToFromJsonNullableObjectParam(this.value); factory SimpleClassNullableOfEnumTypeToFromJsonNullableObjectParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfEnumTypeToFromJsonNullableObjectParamFromJson( - json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfEnumTypeToFromJsonNullableObjectParamFromJson( + json, + ); Map<String, Object?> toJson() => _$SimpleClassNullableOfEnumTypeToFromJsonNullableObjectParamToJson(this); @@ -3647,13 +3180,11 @@ class SimpleClassNullableOfEnumTypeToFromJsonNullableObjectParam { class SimpleClassOfIntToFromJsonNullableObjectParam { final Map<int, FromJsonNullableObjectParam> value; - SimpleClassOfIntToFromJsonNullableObjectParam( - this.value, - ); + SimpleClassOfIntToFromJsonNullableObjectParam(this.value); factory SimpleClassOfIntToFromJsonNullableObjectParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfIntToFromJsonNullableObjectParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfIntToFromJsonNullableObjectParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfIntToFromJsonNullableObjectParamToJson(this); @@ -3663,13 +3194,11 @@ class SimpleClassOfIntToFromJsonNullableObjectParam { class SimpleClassNullableOfIntToFromJsonNullableObjectParam { final Map<int, FromJsonNullableObjectParam>? value; - SimpleClassNullableOfIntToFromJsonNullableObjectParam( - this.value, - ); + SimpleClassNullableOfIntToFromJsonNullableObjectParam(this.value); factory SimpleClassNullableOfIntToFromJsonNullableObjectParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfIntToFromJsonNullableObjectParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfIntToFromJsonNullableObjectParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfIntToFromJsonNullableObjectParamToJson(this); @@ -3679,13 +3208,11 @@ class SimpleClassNullableOfIntToFromJsonNullableObjectParam { class SimpleClassOfObjectToFromJsonNullableObjectParam { final Map<Object, FromJsonNullableObjectParam> value; - SimpleClassOfObjectToFromJsonNullableObjectParam( - this.value, - ); + SimpleClassOfObjectToFromJsonNullableObjectParam(this.value); factory SimpleClassOfObjectToFromJsonNullableObjectParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfObjectToFromJsonNullableObjectParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfObjectToFromJsonNullableObjectParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfObjectToFromJsonNullableObjectParamToJson(this); @@ -3695,13 +3222,11 @@ class SimpleClassOfObjectToFromJsonNullableObjectParam { class SimpleClassNullableOfObjectToFromJsonNullableObjectParam { final Map<Object, FromJsonNullableObjectParam>? value; - SimpleClassNullableOfObjectToFromJsonNullableObjectParam( - this.value, - ); + SimpleClassNullableOfObjectToFromJsonNullableObjectParam(this.value); factory SimpleClassNullableOfObjectToFromJsonNullableObjectParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfObjectToFromJsonNullableObjectParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfObjectToFromJsonNullableObjectParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfObjectToFromJsonNullableObjectParamToJson(this); @@ -3711,13 +3236,11 @@ class SimpleClassNullableOfObjectToFromJsonNullableObjectParam { class SimpleClassOfStringToFromJsonNullableObjectParam { final Map<String, FromJsonNullableObjectParam> value; - SimpleClassOfStringToFromJsonNullableObjectParam( - this.value, - ); + SimpleClassOfStringToFromJsonNullableObjectParam(this.value); factory SimpleClassOfStringToFromJsonNullableObjectParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfStringToFromJsonNullableObjectParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfStringToFromJsonNullableObjectParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfStringToFromJsonNullableObjectParamToJson(this); @@ -3727,13 +3250,11 @@ class SimpleClassOfStringToFromJsonNullableObjectParam { class SimpleClassNullableOfStringToFromJsonNullableObjectParam { final Map<String, FromJsonNullableObjectParam>? value; - SimpleClassNullableOfStringToFromJsonNullableObjectParam( - this.value, - ); + SimpleClassNullableOfStringToFromJsonNullableObjectParam(this.value); factory SimpleClassNullableOfStringToFromJsonNullableObjectParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfStringToFromJsonNullableObjectParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfStringToFromJsonNullableObjectParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfStringToFromJsonNullableObjectParamToJson(this); @@ -3743,13 +3264,11 @@ class SimpleClassNullableOfStringToFromJsonNullableObjectParam { class SimpleClassOfUriToFromJsonNullableObjectParam { final Map<Uri, FromJsonNullableObjectParam> value; - SimpleClassOfUriToFromJsonNullableObjectParam( - this.value, - ); + SimpleClassOfUriToFromJsonNullableObjectParam(this.value); factory SimpleClassOfUriToFromJsonNullableObjectParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfUriToFromJsonNullableObjectParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfUriToFromJsonNullableObjectParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfUriToFromJsonNullableObjectParamToJson(this); @@ -3759,13 +3278,11 @@ class SimpleClassOfUriToFromJsonNullableObjectParam { class SimpleClassNullableOfUriToFromJsonNullableObjectParam { final Map<Uri, FromJsonNullableObjectParam>? value; - SimpleClassNullableOfUriToFromJsonNullableObjectParam( - this.value, - ); + SimpleClassNullableOfUriToFromJsonNullableObjectParam(this.value); factory SimpleClassNullableOfUriToFromJsonNullableObjectParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfUriToFromJsonNullableObjectParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfUriToFromJsonNullableObjectParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfUriToFromJsonNullableObjectParamToJson(this); @@ -3775,13 +3292,11 @@ class SimpleClassNullableOfUriToFromJsonNullableObjectParam { class SimpleClassOfBigIntToFromJsonObjectParam { final Map<BigInt, FromJsonObjectParam> value; - SimpleClassOfBigIntToFromJsonObjectParam( - this.value, - ); + SimpleClassOfBigIntToFromJsonObjectParam(this.value); factory SimpleClassOfBigIntToFromJsonObjectParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfBigIntToFromJsonObjectParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfBigIntToFromJsonObjectParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfBigIntToFromJsonObjectParamToJson(this); @@ -3791,13 +3306,11 @@ class SimpleClassOfBigIntToFromJsonObjectParam { class SimpleClassNullableOfBigIntToFromJsonObjectParam { final Map<BigInt, FromJsonObjectParam>? value; - SimpleClassNullableOfBigIntToFromJsonObjectParam( - this.value, - ); + SimpleClassNullableOfBigIntToFromJsonObjectParam(this.value); factory SimpleClassNullableOfBigIntToFromJsonObjectParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfBigIntToFromJsonObjectParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfBigIntToFromJsonObjectParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfBigIntToFromJsonObjectParamToJson(this); @@ -3807,13 +3320,11 @@ class SimpleClassNullableOfBigIntToFromJsonObjectParam { class SimpleClassOfDateTimeToFromJsonObjectParam { final Map<DateTime, FromJsonObjectParam> value; - SimpleClassOfDateTimeToFromJsonObjectParam( - this.value, - ); + SimpleClassOfDateTimeToFromJsonObjectParam(this.value); factory SimpleClassOfDateTimeToFromJsonObjectParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfDateTimeToFromJsonObjectParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfDateTimeToFromJsonObjectParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfDateTimeToFromJsonObjectParamToJson(this); @@ -3823,13 +3334,11 @@ class SimpleClassOfDateTimeToFromJsonObjectParam { class SimpleClassNullableOfDateTimeToFromJsonObjectParam { final Map<DateTime, FromJsonObjectParam>? value; - SimpleClassNullableOfDateTimeToFromJsonObjectParam( - this.value, - ); + SimpleClassNullableOfDateTimeToFromJsonObjectParam(this.value); factory SimpleClassNullableOfDateTimeToFromJsonObjectParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfDateTimeToFromJsonObjectParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfDateTimeToFromJsonObjectParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfDateTimeToFromJsonObjectParamToJson(this); @@ -3839,13 +3348,11 @@ class SimpleClassNullableOfDateTimeToFromJsonObjectParam { class SimpleClassOfDynamicToFromJsonObjectParam { final Map<dynamic, FromJsonObjectParam> value; - SimpleClassOfDynamicToFromJsonObjectParam( - this.value, - ); + SimpleClassOfDynamicToFromJsonObjectParam(this.value); factory SimpleClassOfDynamicToFromJsonObjectParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfDynamicToFromJsonObjectParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfDynamicToFromJsonObjectParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfDynamicToFromJsonObjectParamToJson(this); @@ -3855,13 +3362,11 @@ class SimpleClassOfDynamicToFromJsonObjectParam { class SimpleClassNullableOfDynamicToFromJsonObjectParam { final Map<dynamic, FromJsonObjectParam>? value; - SimpleClassNullableOfDynamicToFromJsonObjectParam( - this.value, - ); + SimpleClassNullableOfDynamicToFromJsonObjectParam(this.value); factory SimpleClassNullableOfDynamicToFromJsonObjectParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfDynamicToFromJsonObjectParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfDynamicToFromJsonObjectParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfDynamicToFromJsonObjectParamToJson(this); @@ -3871,13 +3376,11 @@ class SimpleClassNullableOfDynamicToFromJsonObjectParam { class SimpleClassOfEnumTypeToFromJsonObjectParam { final Map<EnumType, FromJsonObjectParam> value; - SimpleClassOfEnumTypeToFromJsonObjectParam( - this.value, - ); + SimpleClassOfEnumTypeToFromJsonObjectParam(this.value); factory SimpleClassOfEnumTypeToFromJsonObjectParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfEnumTypeToFromJsonObjectParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfEnumTypeToFromJsonObjectParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfEnumTypeToFromJsonObjectParamToJson(this); @@ -3887,13 +3390,11 @@ class SimpleClassOfEnumTypeToFromJsonObjectParam { class SimpleClassNullableOfEnumTypeToFromJsonObjectParam { final Map<EnumType, FromJsonObjectParam>? value; - SimpleClassNullableOfEnumTypeToFromJsonObjectParam( - this.value, - ); + SimpleClassNullableOfEnumTypeToFromJsonObjectParam(this.value); factory SimpleClassNullableOfEnumTypeToFromJsonObjectParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfEnumTypeToFromJsonObjectParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfEnumTypeToFromJsonObjectParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfEnumTypeToFromJsonObjectParamToJson(this); @@ -3903,13 +3404,11 @@ class SimpleClassNullableOfEnumTypeToFromJsonObjectParam { class SimpleClassOfIntToFromJsonObjectParam { final Map<int, FromJsonObjectParam> value; - SimpleClassOfIntToFromJsonObjectParam( - this.value, - ); + SimpleClassOfIntToFromJsonObjectParam(this.value); factory SimpleClassOfIntToFromJsonObjectParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfIntToFromJsonObjectParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfIntToFromJsonObjectParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfIntToFromJsonObjectParamToJson(this); @@ -3919,13 +3418,11 @@ class SimpleClassOfIntToFromJsonObjectParam { class SimpleClassNullableOfIntToFromJsonObjectParam { final Map<int, FromJsonObjectParam>? value; - SimpleClassNullableOfIntToFromJsonObjectParam( - this.value, - ); + SimpleClassNullableOfIntToFromJsonObjectParam(this.value); factory SimpleClassNullableOfIntToFromJsonObjectParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfIntToFromJsonObjectParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfIntToFromJsonObjectParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfIntToFromJsonObjectParamToJson(this); @@ -3935,13 +3432,11 @@ class SimpleClassNullableOfIntToFromJsonObjectParam { class SimpleClassOfObjectToFromJsonObjectParam { final Map<Object, FromJsonObjectParam> value; - SimpleClassOfObjectToFromJsonObjectParam( - this.value, - ); + SimpleClassOfObjectToFromJsonObjectParam(this.value); factory SimpleClassOfObjectToFromJsonObjectParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfObjectToFromJsonObjectParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfObjectToFromJsonObjectParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfObjectToFromJsonObjectParamToJson(this); @@ -3951,13 +3446,11 @@ class SimpleClassOfObjectToFromJsonObjectParam { class SimpleClassNullableOfObjectToFromJsonObjectParam { final Map<Object, FromJsonObjectParam>? value; - SimpleClassNullableOfObjectToFromJsonObjectParam( - this.value, - ); + SimpleClassNullableOfObjectToFromJsonObjectParam(this.value); factory SimpleClassNullableOfObjectToFromJsonObjectParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfObjectToFromJsonObjectParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfObjectToFromJsonObjectParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfObjectToFromJsonObjectParamToJson(this); @@ -3967,13 +3460,11 @@ class SimpleClassNullableOfObjectToFromJsonObjectParam { class SimpleClassOfStringToFromJsonObjectParam { final Map<String, FromJsonObjectParam> value; - SimpleClassOfStringToFromJsonObjectParam( - this.value, - ); + SimpleClassOfStringToFromJsonObjectParam(this.value); factory SimpleClassOfStringToFromJsonObjectParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfStringToFromJsonObjectParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfStringToFromJsonObjectParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfStringToFromJsonObjectParamToJson(this); @@ -3983,13 +3474,11 @@ class SimpleClassOfStringToFromJsonObjectParam { class SimpleClassNullableOfStringToFromJsonObjectParam { final Map<String, FromJsonObjectParam>? value; - SimpleClassNullableOfStringToFromJsonObjectParam( - this.value, - ); + SimpleClassNullableOfStringToFromJsonObjectParam(this.value); factory SimpleClassNullableOfStringToFromJsonObjectParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfStringToFromJsonObjectParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfStringToFromJsonObjectParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfStringToFromJsonObjectParamToJson(this); @@ -3999,13 +3488,11 @@ class SimpleClassNullableOfStringToFromJsonObjectParam { class SimpleClassOfUriToFromJsonObjectParam { final Map<Uri, FromJsonObjectParam> value; - SimpleClassOfUriToFromJsonObjectParam( - this.value, - ); + SimpleClassOfUriToFromJsonObjectParam(this.value); factory SimpleClassOfUriToFromJsonObjectParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfUriToFromJsonObjectParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfUriToFromJsonObjectParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfUriToFromJsonObjectParamToJson(this); @@ -4015,13 +3502,11 @@ class SimpleClassOfUriToFromJsonObjectParam { class SimpleClassNullableOfUriToFromJsonObjectParam { final Map<Uri, FromJsonObjectParam>? value; - SimpleClassNullableOfUriToFromJsonObjectParam( - this.value, - ); + SimpleClassNullableOfUriToFromJsonObjectParam(this.value); factory SimpleClassNullableOfUriToFromJsonObjectParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfUriToFromJsonObjectParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfUriToFromJsonObjectParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfUriToFromJsonObjectParamToJson(this); @@ -4031,9 +3516,7 @@ class SimpleClassNullableOfUriToFromJsonObjectParam { class SimpleClassOfBigIntToInt { final Map<BigInt, int> value; - SimpleClassOfBigIntToInt( - this.value, - ); + SimpleClassOfBigIntToInt(this.value); factory SimpleClassOfBigIntToInt.fromJson(Map<String, Object?> json) => _$SimpleClassOfBigIntToIntFromJson(json); @@ -4045,13 +3528,11 @@ class SimpleClassOfBigIntToInt { class SimpleClassNullableOfBigIntToInt { final Map<BigInt, int>? value; - SimpleClassNullableOfBigIntToInt( - this.value, - ); + SimpleClassNullableOfBigIntToInt(this.value); factory SimpleClassNullableOfBigIntToInt.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfBigIntToIntFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfBigIntToIntFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfBigIntToIntToJson(this); @@ -4061,9 +3542,7 @@ class SimpleClassNullableOfBigIntToInt { class SimpleClassOfDateTimeToInt { final Map<DateTime, int> value; - SimpleClassOfDateTimeToInt( - this.value, - ); + SimpleClassOfDateTimeToInt(this.value); factory SimpleClassOfDateTimeToInt.fromJson(Map<String, Object?> json) => _$SimpleClassOfDateTimeToIntFromJson(json); @@ -4075,13 +3554,11 @@ class SimpleClassOfDateTimeToInt { class SimpleClassNullableOfDateTimeToInt { final Map<DateTime, int>? value; - SimpleClassNullableOfDateTimeToInt( - this.value, - ); + SimpleClassNullableOfDateTimeToInt(this.value); factory SimpleClassNullableOfDateTimeToInt.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfDateTimeToIntFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfDateTimeToIntFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfDateTimeToIntToJson(this); @@ -4091,9 +3568,7 @@ class SimpleClassNullableOfDateTimeToInt { class SimpleClassOfDynamicToInt { final Map<dynamic, int> value; - SimpleClassOfDynamicToInt( - this.value, - ); + SimpleClassOfDynamicToInt(this.value); factory SimpleClassOfDynamicToInt.fromJson(Map<String, Object?> json) => _$SimpleClassOfDynamicToIntFromJson(json); @@ -4105,13 +3580,11 @@ class SimpleClassOfDynamicToInt { class SimpleClassNullableOfDynamicToInt { final Map<dynamic, int>? value; - SimpleClassNullableOfDynamicToInt( - this.value, - ); + SimpleClassNullableOfDynamicToInt(this.value); factory SimpleClassNullableOfDynamicToInt.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfDynamicToIntFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfDynamicToIntFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfDynamicToIntToJson(this); @@ -4121,9 +3594,7 @@ class SimpleClassNullableOfDynamicToInt { class SimpleClassOfEnumTypeToInt { final Map<EnumType, int> value; - SimpleClassOfEnumTypeToInt( - this.value, - ); + SimpleClassOfEnumTypeToInt(this.value); factory SimpleClassOfEnumTypeToInt.fromJson(Map<String, Object?> json) => _$SimpleClassOfEnumTypeToIntFromJson(json); @@ -4135,13 +3606,11 @@ class SimpleClassOfEnumTypeToInt { class SimpleClassNullableOfEnumTypeToInt { final Map<EnumType, int>? value; - SimpleClassNullableOfEnumTypeToInt( - this.value, - ); + SimpleClassNullableOfEnumTypeToInt(this.value); factory SimpleClassNullableOfEnumTypeToInt.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfEnumTypeToIntFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfEnumTypeToIntFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfEnumTypeToIntToJson(this); @@ -4151,9 +3620,7 @@ class SimpleClassNullableOfEnumTypeToInt { class SimpleClassOfIntToInt { final Map<int, int> value; - SimpleClassOfIntToInt( - this.value, - ); + SimpleClassOfIntToInt(this.value); factory SimpleClassOfIntToInt.fromJson(Map<String, Object?> json) => _$SimpleClassOfIntToIntFromJson(json); @@ -4165,9 +3632,7 @@ class SimpleClassOfIntToInt { class SimpleClassNullableOfIntToInt { final Map<int, int>? value; - SimpleClassNullableOfIntToInt( - this.value, - ); + SimpleClassNullableOfIntToInt(this.value); factory SimpleClassNullableOfIntToInt.fromJson(Map<String, Object?> json) => _$SimpleClassNullableOfIntToIntFromJson(json); @@ -4179,9 +3644,7 @@ class SimpleClassNullableOfIntToInt { class SimpleClassOfObjectToInt { final Map<Object, int> value; - SimpleClassOfObjectToInt( - this.value, - ); + SimpleClassOfObjectToInt(this.value); factory SimpleClassOfObjectToInt.fromJson(Map<String, Object?> json) => _$SimpleClassOfObjectToIntFromJson(json); @@ -4193,13 +3656,11 @@ class SimpleClassOfObjectToInt { class SimpleClassNullableOfObjectToInt { final Map<Object, int>? value; - SimpleClassNullableOfObjectToInt( - this.value, - ); + SimpleClassNullableOfObjectToInt(this.value); factory SimpleClassNullableOfObjectToInt.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfObjectToIntFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfObjectToIntFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfObjectToIntToJson(this); @@ -4209,9 +3670,7 @@ class SimpleClassNullableOfObjectToInt { class SimpleClassOfStringToInt { final Map<String, int> value; - SimpleClassOfStringToInt( - this.value, - ); + SimpleClassOfStringToInt(this.value); factory SimpleClassOfStringToInt.fromJson(Map<String, Object?> json) => _$SimpleClassOfStringToIntFromJson(json); @@ -4223,13 +3682,11 @@ class SimpleClassOfStringToInt { class SimpleClassNullableOfStringToInt { final Map<String, int>? value; - SimpleClassNullableOfStringToInt( - this.value, - ); + SimpleClassNullableOfStringToInt(this.value); factory SimpleClassNullableOfStringToInt.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfStringToIntFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfStringToIntFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfStringToIntToJson(this); @@ -4239,9 +3696,7 @@ class SimpleClassNullableOfStringToInt { class SimpleClassOfUriToInt { final Map<Uri, int> value; - SimpleClassOfUriToInt( - this.value, - ); + SimpleClassOfUriToInt(this.value); factory SimpleClassOfUriToInt.fromJson(Map<String, Object?> json) => _$SimpleClassOfUriToIntFromJson(json); @@ -4253,9 +3708,7 @@ class SimpleClassOfUriToInt { class SimpleClassNullableOfUriToInt { final Map<Uri, int>? value; - SimpleClassNullableOfUriToInt( - this.value, - ); + SimpleClassNullableOfUriToInt(this.value); factory SimpleClassNullableOfUriToInt.fromJson(Map<String, Object?> json) => _$SimpleClassNullableOfUriToIntFromJson(json); @@ -4267,13 +3720,11 @@ class SimpleClassNullableOfUriToInt { class SimpleClassOfBigIntToIntNullable { final Map<BigInt, int?> value; - SimpleClassOfBigIntToIntNullable( - this.value, - ); + SimpleClassOfBigIntToIntNullable(this.value); factory SimpleClassOfBigIntToIntNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfBigIntToIntNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfBigIntToIntNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfBigIntToIntNullableToJson(this); @@ -4283,13 +3734,11 @@ class SimpleClassOfBigIntToIntNullable { class SimpleClassNullableOfBigIntToIntNullable { final Map<BigInt, int?>? value; - SimpleClassNullableOfBigIntToIntNullable( - this.value, - ); + SimpleClassNullableOfBigIntToIntNullable(this.value); factory SimpleClassNullableOfBigIntToIntNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfBigIntToIntNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfBigIntToIntNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfBigIntToIntNullableToJson(this); @@ -4299,13 +3748,11 @@ class SimpleClassNullableOfBigIntToIntNullable { class SimpleClassOfDateTimeToIntNullable { final Map<DateTime, int?> value; - SimpleClassOfDateTimeToIntNullable( - this.value, - ); + SimpleClassOfDateTimeToIntNullable(this.value); factory SimpleClassOfDateTimeToIntNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfDateTimeToIntNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfDateTimeToIntNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfDateTimeToIntNullableToJson(this); @@ -4315,13 +3762,11 @@ class SimpleClassOfDateTimeToIntNullable { class SimpleClassNullableOfDateTimeToIntNullable { final Map<DateTime, int?>? value; - SimpleClassNullableOfDateTimeToIntNullable( - this.value, - ); + SimpleClassNullableOfDateTimeToIntNullable(this.value); factory SimpleClassNullableOfDateTimeToIntNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfDateTimeToIntNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfDateTimeToIntNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfDateTimeToIntNullableToJson(this); @@ -4331,13 +3776,11 @@ class SimpleClassNullableOfDateTimeToIntNullable { class SimpleClassOfDynamicToIntNullable { final Map<dynamic, int?> value; - SimpleClassOfDynamicToIntNullable( - this.value, - ); + SimpleClassOfDynamicToIntNullable(this.value); factory SimpleClassOfDynamicToIntNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfDynamicToIntNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfDynamicToIntNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfDynamicToIntNullableToJson(this); @@ -4347,13 +3790,11 @@ class SimpleClassOfDynamicToIntNullable { class SimpleClassNullableOfDynamicToIntNullable { final Map<dynamic, int?>? value; - SimpleClassNullableOfDynamicToIntNullable( - this.value, - ); + SimpleClassNullableOfDynamicToIntNullable(this.value); factory SimpleClassNullableOfDynamicToIntNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfDynamicToIntNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfDynamicToIntNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfDynamicToIntNullableToJson(this); @@ -4363,13 +3804,11 @@ class SimpleClassNullableOfDynamicToIntNullable { class SimpleClassOfEnumTypeToIntNullable { final Map<EnumType, int?> value; - SimpleClassOfEnumTypeToIntNullable( - this.value, - ); + SimpleClassOfEnumTypeToIntNullable(this.value); factory SimpleClassOfEnumTypeToIntNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfEnumTypeToIntNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfEnumTypeToIntNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfEnumTypeToIntNullableToJson(this); @@ -4379,13 +3818,11 @@ class SimpleClassOfEnumTypeToIntNullable { class SimpleClassNullableOfEnumTypeToIntNullable { final Map<EnumType, int?>? value; - SimpleClassNullableOfEnumTypeToIntNullable( - this.value, - ); + SimpleClassNullableOfEnumTypeToIntNullable(this.value); factory SimpleClassNullableOfEnumTypeToIntNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfEnumTypeToIntNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfEnumTypeToIntNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfEnumTypeToIntNullableToJson(this); @@ -4395,9 +3832,7 @@ class SimpleClassNullableOfEnumTypeToIntNullable { class SimpleClassOfIntToIntNullable { final Map<int, int?> value; - SimpleClassOfIntToIntNullable( - this.value, - ); + SimpleClassOfIntToIntNullable(this.value); factory SimpleClassOfIntToIntNullable.fromJson(Map<String, Object?> json) => _$SimpleClassOfIntToIntNullableFromJson(json); @@ -4409,13 +3844,11 @@ class SimpleClassOfIntToIntNullable { class SimpleClassNullableOfIntToIntNullable { final Map<int, int?>? value; - SimpleClassNullableOfIntToIntNullable( - this.value, - ); + SimpleClassNullableOfIntToIntNullable(this.value); factory SimpleClassNullableOfIntToIntNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfIntToIntNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfIntToIntNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfIntToIntNullableToJson(this); @@ -4425,13 +3858,11 @@ class SimpleClassNullableOfIntToIntNullable { class SimpleClassOfObjectToIntNullable { final Map<Object, int?> value; - SimpleClassOfObjectToIntNullable( - this.value, - ); + SimpleClassOfObjectToIntNullable(this.value); factory SimpleClassOfObjectToIntNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfObjectToIntNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfObjectToIntNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfObjectToIntNullableToJson(this); @@ -4441,13 +3872,11 @@ class SimpleClassOfObjectToIntNullable { class SimpleClassNullableOfObjectToIntNullable { final Map<Object, int?>? value; - SimpleClassNullableOfObjectToIntNullable( - this.value, - ); + SimpleClassNullableOfObjectToIntNullable(this.value); factory SimpleClassNullableOfObjectToIntNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfObjectToIntNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfObjectToIntNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfObjectToIntNullableToJson(this); @@ -4457,13 +3886,11 @@ class SimpleClassNullableOfObjectToIntNullable { class SimpleClassOfStringToIntNullable { final Map<String, int?> value; - SimpleClassOfStringToIntNullable( - this.value, - ); + SimpleClassOfStringToIntNullable(this.value); factory SimpleClassOfStringToIntNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfStringToIntNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfStringToIntNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfStringToIntNullableToJson(this); @@ -4473,13 +3900,11 @@ class SimpleClassOfStringToIntNullable { class SimpleClassNullableOfStringToIntNullable { final Map<String, int?>? value; - SimpleClassNullableOfStringToIntNullable( - this.value, - ); + SimpleClassNullableOfStringToIntNullable(this.value); factory SimpleClassNullableOfStringToIntNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfStringToIntNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfStringToIntNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfStringToIntNullableToJson(this); @@ -4489,9 +3914,7 @@ class SimpleClassNullableOfStringToIntNullable { class SimpleClassOfUriToIntNullable { final Map<Uri, int?> value; - SimpleClassOfUriToIntNullable( - this.value, - ); + SimpleClassOfUriToIntNullable(this.value); factory SimpleClassOfUriToIntNullable.fromJson(Map<String, Object?> json) => _$SimpleClassOfUriToIntNullableFromJson(json); @@ -4503,13 +3926,11 @@ class SimpleClassOfUriToIntNullable { class SimpleClassNullableOfUriToIntNullable { final Map<Uri, int?>? value; - SimpleClassNullableOfUriToIntNullable( - this.value, - ); + SimpleClassNullableOfUriToIntNullable(this.value); factory SimpleClassNullableOfUriToIntNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfUriToIntNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfUriToIntNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfUriToIntNullableToJson(this); @@ -4519,9 +3940,7 @@ class SimpleClassNullableOfUriToIntNullable { class SimpleClassOfBigIntToNum { final Map<BigInt, num> value; - SimpleClassOfBigIntToNum( - this.value, - ); + SimpleClassOfBigIntToNum(this.value); factory SimpleClassOfBigIntToNum.fromJson(Map<String, Object?> json) => _$SimpleClassOfBigIntToNumFromJson(json); @@ -4533,13 +3952,11 @@ class SimpleClassOfBigIntToNum { class SimpleClassNullableOfBigIntToNum { final Map<BigInt, num>? value; - SimpleClassNullableOfBigIntToNum( - this.value, - ); + SimpleClassNullableOfBigIntToNum(this.value); factory SimpleClassNullableOfBigIntToNum.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfBigIntToNumFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfBigIntToNumFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfBigIntToNumToJson(this); @@ -4549,9 +3966,7 @@ class SimpleClassNullableOfBigIntToNum { class SimpleClassOfDateTimeToNum { final Map<DateTime, num> value; - SimpleClassOfDateTimeToNum( - this.value, - ); + SimpleClassOfDateTimeToNum(this.value); factory SimpleClassOfDateTimeToNum.fromJson(Map<String, Object?> json) => _$SimpleClassOfDateTimeToNumFromJson(json); @@ -4563,13 +3978,11 @@ class SimpleClassOfDateTimeToNum { class SimpleClassNullableOfDateTimeToNum { final Map<DateTime, num>? value; - SimpleClassNullableOfDateTimeToNum( - this.value, - ); + SimpleClassNullableOfDateTimeToNum(this.value); factory SimpleClassNullableOfDateTimeToNum.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfDateTimeToNumFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfDateTimeToNumFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfDateTimeToNumToJson(this); @@ -4579,9 +3992,7 @@ class SimpleClassNullableOfDateTimeToNum { class SimpleClassOfDynamicToNum { final Map<dynamic, num> value; - SimpleClassOfDynamicToNum( - this.value, - ); + SimpleClassOfDynamicToNum(this.value); factory SimpleClassOfDynamicToNum.fromJson(Map<String, Object?> json) => _$SimpleClassOfDynamicToNumFromJson(json); @@ -4593,13 +4004,11 @@ class SimpleClassOfDynamicToNum { class SimpleClassNullableOfDynamicToNum { final Map<dynamic, num>? value; - SimpleClassNullableOfDynamicToNum( - this.value, - ); + SimpleClassNullableOfDynamicToNum(this.value); factory SimpleClassNullableOfDynamicToNum.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfDynamicToNumFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfDynamicToNumFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfDynamicToNumToJson(this); @@ -4609,9 +4018,7 @@ class SimpleClassNullableOfDynamicToNum { class SimpleClassOfEnumTypeToNum { final Map<EnumType, num> value; - SimpleClassOfEnumTypeToNum( - this.value, - ); + SimpleClassOfEnumTypeToNum(this.value); factory SimpleClassOfEnumTypeToNum.fromJson(Map<String, Object?> json) => _$SimpleClassOfEnumTypeToNumFromJson(json); @@ -4623,13 +4030,11 @@ class SimpleClassOfEnumTypeToNum { class SimpleClassNullableOfEnumTypeToNum { final Map<EnumType, num>? value; - SimpleClassNullableOfEnumTypeToNum( - this.value, - ); + SimpleClassNullableOfEnumTypeToNum(this.value); factory SimpleClassNullableOfEnumTypeToNum.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfEnumTypeToNumFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfEnumTypeToNumFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfEnumTypeToNumToJson(this); @@ -4639,9 +4044,7 @@ class SimpleClassNullableOfEnumTypeToNum { class SimpleClassOfIntToNum { final Map<int, num> value; - SimpleClassOfIntToNum( - this.value, - ); + SimpleClassOfIntToNum(this.value); factory SimpleClassOfIntToNum.fromJson(Map<String, Object?> json) => _$SimpleClassOfIntToNumFromJson(json); @@ -4653,9 +4056,7 @@ class SimpleClassOfIntToNum { class SimpleClassNullableOfIntToNum { final Map<int, num>? value; - SimpleClassNullableOfIntToNum( - this.value, - ); + SimpleClassNullableOfIntToNum(this.value); factory SimpleClassNullableOfIntToNum.fromJson(Map<String, Object?> json) => _$SimpleClassNullableOfIntToNumFromJson(json); @@ -4667,9 +4068,7 @@ class SimpleClassNullableOfIntToNum { class SimpleClassOfObjectToNum { final Map<Object, num> value; - SimpleClassOfObjectToNum( - this.value, - ); + SimpleClassOfObjectToNum(this.value); factory SimpleClassOfObjectToNum.fromJson(Map<String, Object?> json) => _$SimpleClassOfObjectToNumFromJson(json); @@ -4681,13 +4080,11 @@ class SimpleClassOfObjectToNum { class SimpleClassNullableOfObjectToNum { final Map<Object, num>? value; - SimpleClassNullableOfObjectToNum( - this.value, - ); + SimpleClassNullableOfObjectToNum(this.value); factory SimpleClassNullableOfObjectToNum.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfObjectToNumFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfObjectToNumFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfObjectToNumToJson(this); @@ -4697,9 +4094,7 @@ class SimpleClassNullableOfObjectToNum { class SimpleClassOfStringToNum { final Map<String, num> value; - SimpleClassOfStringToNum( - this.value, - ); + SimpleClassOfStringToNum(this.value); factory SimpleClassOfStringToNum.fromJson(Map<String, Object?> json) => _$SimpleClassOfStringToNumFromJson(json); @@ -4711,13 +4106,11 @@ class SimpleClassOfStringToNum { class SimpleClassNullableOfStringToNum { final Map<String, num>? value; - SimpleClassNullableOfStringToNum( - this.value, - ); + SimpleClassNullableOfStringToNum(this.value); factory SimpleClassNullableOfStringToNum.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfStringToNumFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfStringToNumFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfStringToNumToJson(this); @@ -4727,9 +4120,7 @@ class SimpleClassNullableOfStringToNum { class SimpleClassOfUriToNum { final Map<Uri, num> value; - SimpleClassOfUriToNum( - this.value, - ); + SimpleClassOfUriToNum(this.value); factory SimpleClassOfUriToNum.fromJson(Map<String, Object?> json) => _$SimpleClassOfUriToNumFromJson(json); @@ -4741,9 +4132,7 @@ class SimpleClassOfUriToNum { class SimpleClassNullableOfUriToNum { final Map<Uri, num>? value; - SimpleClassNullableOfUriToNum( - this.value, - ); + SimpleClassNullableOfUriToNum(this.value); factory SimpleClassNullableOfUriToNum.fromJson(Map<String, Object?> json) => _$SimpleClassNullableOfUriToNumFromJson(json); @@ -4755,13 +4144,11 @@ class SimpleClassNullableOfUriToNum { class SimpleClassOfBigIntToNumNullable { final Map<BigInt, num?> value; - SimpleClassOfBigIntToNumNullable( - this.value, - ); + SimpleClassOfBigIntToNumNullable(this.value); factory SimpleClassOfBigIntToNumNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfBigIntToNumNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfBigIntToNumNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfBigIntToNumNullableToJson(this); @@ -4771,13 +4158,11 @@ class SimpleClassOfBigIntToNumNullable { class SimpleClassNullableOfBigIntToNumNullable { final Map<BigInt, num?>? value; - SimpleClassNullableOfBigIntToNumNullable( - this.value, - ); + SimpleClassNullableOfBigIntToNumNullable(this.value); factory SimpleClassNullableOfBigIntToNumNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfBigIntToNumNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfBigIntToNumNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfBigIntToNumNullableToJson(this); @@ -4787,13 +4172,11 @@ class SimpleClassNullableOfBigIntToNumNullable { class SimpleClassOfDateTimeToNumNullable { final Map<DateTime, num?> value; - SimpleClassOfDateTimeToNumNullable( - this.value, - ); + SimpleClassOfDateTimeToNumNullable(this.value); factory SimpleClassOfDateTimeToNumNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfDateTimeToNumNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfDateTimeToNumNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfDateTimeToNumNullableToJson(this); @@ -4803,13 +4186,11 @@ class SimpleClassOfDateTimeToNumNullable { class SimpleClassNullableOfDateTimeToNumNullable { final Map<DateTime, num?>? value; - SimpleClassNullableOfDateTimeToNumNullable( - this.value, - ); + SimpleClassNullableOfDateTimeToNumNullable(this.value); factory SimpleClassNullableOfDateTimeToNumNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfDateTimeToNumNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfDateTimeToNumNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfDateTimeToNumNullableToJson(this); @@ -4819,13 +4200,11 @@ class SimpleClassNullableOfDateTimeToNumNullable { class SimpleClassOfDynamicToNumNullable { final Map<dynamic, num?> value; - SimpleClassOfDynamicToNumNullable( - this.value, - ); + SimpleClassOfDynamicToNumNullable(this.value); factory SimpleClassOfDynamicToNumNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfDynamicToNumNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfDynamicToNumNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfDynamicToNumNullableToJson(this); @@ -4835,13 +4214,11 @@ class SimpleClassOfDynamicToNumNullable { class SimpleClassNullableOfDynamicToNumNullable { final Map<dynamic, num?>? value; - SimpleClassNullableOfDynamicToNumNullable( - this.value, - ); + SimpleClassNullableOfDynamicToNumNullable(this.value); factory SimpleClassNullableOfDynamicToNumNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfDynamicToNumNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfDynamicToNumNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfDynamicToNumNullableToJson(this); @@ -4851,13 +4228,11 @@ class SimpleClassNullableOfDynamicToNumNullable { class SimpleClassOfEnumTypeToNumNullable { final Map<EnumType, num?> value; - SimpleClassOfEnumTypeToNumNullable( - this.value, - ); + SimpleClassOfEnumTypeToNumNullable(this.value); factory SimpleClassOfEnumTypeToNumNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfEnumTypeToNumNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfEnumTypeToNumNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfEnumTypeToNumNullableToJson(this); @@ -4867,13 +4242,11 @@ class SimpleClassOfEnumTypeToNumNullable { class SimpleClassNullableOfEnumTypeToNumNullable { final Map<EnumType, num?>? value; - SimpleClassNullableOfEnumTypeToNumNullable( - this.value, - ); + SimpleClassNullableOfEnumTypeToNumNullable(this.value); factory SimpleClassNullableOfEnumTypeToNumNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfEnumTypeToNumNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfEnumTypeToNumNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfEnumTypeToNumNullableToJson(this); @@ -4883,9 +4256,7 @@ class SimpleClassNullableOfEnumTypeToNumNullable { class SimpleClassOfIntToNumNullable { final Map<int, num?> value; - SimpleClassOfIntToNumNullable( - this.value, - ); + SimpleClassOfIntToNumNullable(this.value); factory SimpleClassOfIntToNumNullable.fromJson(Map<String, Object?> json) => _$SimpleClassOfIntToNumNullableFromJson(json); @@ -4897,13 +4268,11 @@ class SimpleClassOfIntToNumNullable { class SimpleClassNullableOfIntToNumNullable { final Map<int, num?>? value; - SimpleClassNullableOfIntToNumNullable( - this.value, - ); + SimpleClassNullableOfIntToNumNullable(this.value); factory SimpleClassNullableOfIntToNumNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfIntToNumNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfIntToNumNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfIntToNumNullableToJson(this); @@ -4913,13 +4282,11 @@ class SimpleClassNullableOfIntToNumNullable { class SimpleClassOfObjectToNumNullable { final Map<Object, num?> value; - SimpleClassOfObjectToNumNullable( - this.value, - ); + SimpleClassOfObjectToNumNullable(this.value); factory SimpleClassOfObjectToNumNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfObjectToNumNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfObjectToNumNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfObjectToNumNullableToJson(this); @@ -4929,13 +4296,11 @@ class SimpleClassOfObjectToNumNullable { class SimpleClassNullableOfObjectToNumNullable { final Map<Object, num?>? value; - SimpleClassNullableOfObjectToNumNullable( - this.value, - ); + SimpleClassNullableOfObjectToNumNullable(this.value); factory SimpleClassNullableOfObjectToNumNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfObjectToNumNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfObjectToNumNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfObjectToNumNullableToJson(this); @@ -4945,13 +4310,11 @@ class SimpleClassNullableOfObjectToNumNullable { class SimpleClassOfStringToNumNullable { final Map<String, num?> value; - SimpleClassOfStringToNumNullable( - this.value, - ); + SimpleClassOfStringToNumNullable(this.value); factory SimpleClassOfStringToNumNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfStringToNumNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfStringToNumNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfStringToNumNullableToJson(this); @@ -4961,13 +4324,11 @@ class SimpleClassOfStringToNumNullable { class SimpleClassNullableOfStringToNumNullable { final Map<String, num?>? value; - SimpleClassNullableOfStringToNumNullable( - this.value, - ); + SimpleClassNullableOfStringToNumNullable(this.value); factory SimpleClassNullableOfStringToNumNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfStringToNumNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfStringToNumNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfStringToNumNullableToJson(this); @@ -4977,9 +4338,7 @@ class SimpleClassNullableOfStringToNumNullable { class SimpleClassOfUriToNumNullable { final Map<Uri, num?> value; - SimpleClassOfUriToNumNullable( - this.value, - ); + SimpleClassOfUriToNumNullable(this.value); factory SimpleClassOfUriToNumNullable.fromJson(Map<String, Object?> json) => _$SimpleClassOfUriToNumNullableFromJson(json); @@ -4991,13 +4350,11 @@ class SimpleClassOfUriToNumNullable { class SimpleClassNullableOfUriToNumNullable { final Map<Uri, num?>? value; - SimpleClassNullableOfUriToNumNullable( - this.value, - ); + SimpleClassNullableOfUriToNumNullable(this.value); factory SimpleClassNullableOfUriToNumNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfUriToNumNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfUriToNumNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfUriToNumNullableToJson(this); @@ -5007,9 +4364,7 @@ class SimpleClassNullableOfUriToNumNullable { class SimpleClassOfBigIntToObject { final Map<BigInt, Object> value; - SimpleClassOfBigIntToObject( - this.value, - ); + SimpleClassOfBigIntToObject(this.value); factory SimpleClassOfBigIntToObject.fromJson(Map<String, Object?> json) => _$SimpleClassOfBigIntToObjectFromJson(json); @@ -5021,13 +4376,11 @@ class SimpleClassOfBigIntToObject { class SimpleClassNullableOfBigIntToObject { final Map<BigInt, Object>? value; - SimpleClassNullableOfBigIntToObject( - this.value, - ); + SimpleClassNullableOfBigIntToObject(this.value); factory SimpleClassNullableOfBigIntToObject.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfBigIntToObjectFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfBigIntToObjectFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfBigIntToObjectToJson(this); @@ -5037,9 +4390,7 @@ class SimpleClassNullableOfBigIntToObject { class SimpleClassOfDateTimeToObject { final Map<DateTime, Object> value; - SimpleClassOfDateTimeToObject( - this.value, - ); + SimpleClassOfDateTimeToObject(this.value); factory SimpleClassOfDateTimeToObject.fromJson(Map<String, Object?> json) => _$SimpleClassOfDateTimeToObjectFromJson(json); @@ -5051,13 +4402,11 @@ class SimpleClassOfDateTimeToObject { class SimpleClassNullableOfDateTimeToObject { final Map<DateTime, Object>? value; - SimpleClassNullableOfDateTimeToObject( - this.value, - ); + SimpleClassNullableOfDateTimeToObject(this.value); factory SimpleClassNullableOfDateTimeToObject.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfDateTimeToObjectFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfDateTimeToObjectFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfDateTimeToObjectToJson(this); @@ -5067,9 +4416,7 @@ class SimpleClassNullableOfDateTimeToObject { class SimpleClassOfDynamicToObject { final Map<dynamic, Object> value; - SimpleClassOfDynamicToObject( - this.value, - ); + SimpleClassOfDynamicToObject(this.value); factory SimpleClassOfDynamicToObject.fromJson(Map<String, Object?> json) => _$SimpleClassOfDynamicToObjectFromJson(json); @@ -5081,13 +4428,11 @@ class SimpleClassOfDynamicToObject { class SimpleClassNullableOfDynamicToObject { final Map<dynamic, Object>? value; - SimpleClassNullableOfDynamicToObject( - this.value, - ); + SimpleClassNullableOfDynamicToObject(this.value); factory SimpleClassNullableOfDynamicToObject.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfDynamicToObjectFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfDynamicToObjectFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfDynamicToObjectToJson(this); @@ -5097,9 +4442,7 @@ class SimpleClassNullableOfDynamicToObject { class SimpleClassOfEnumTypeToObject { final Map<EnumType, Object> value; - SimpleClassOfEnumTypeToObject( - this.value, - ); + SimpleClassOfEnumTypeToObject(this.value); factory SimpleClassOfEnumTypeToObject.fromJson(Map<String, Object?> json) => _$SimpleClassOfEnumTypeToObjectFromJson(json); @@ -5111,13 +4454,11 @@ class SimpleClassOfEnumTypeToObject { class SimpleClassNullableOfEnumTypeToObject { final Map<EnumType, Object>? value; - SimpleClassNullableOfEnumTypeToObject( - this.value, - ); + SimpleClassNullableOfEnumTypeToObject(this.value); factory SimpleClassNullableOfEnumTypeToObject.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfEnumTypeToObjectFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfEnumTypeToObjectFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfEnumTypeToObjectToJson(this); @@ -5127,9 +4468,7 @@ class SimpleClassNullableOfEnumTypeToObject { class SimpleClassOfIntToObject { final Map<int, Object> value; - SimpleClassOfIntToObject( - this.value, - ); + SimpleClassOfIntToObject(this.value); factory SimpleClassOfIntToObject.fromJson(Map<String, Object?> json) => _$SimpleClassOfIntToObjectFromJson(json); @@ -5141,13 +4480,11 @@ class SimpleClassOfIntToObject { class SimpleClassNullableOfIntToObject { final Map<int, Object>? value; - SimpleClassNullableOfIntToObject( - this.value, - ); + SimpleClassNullableOfIntToObject(this.value); factory SimpleClassNullableOfIntToObject.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfIntToObjectFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfIntToObjectFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfIntToObjectToJson(this); @@ -5157,9 +4494,7 @@ class SimpleClassNullableOfIntToObject { class SimpleClassOfObjectToObject { final Map<Object, Object> value; - SimpleClassOfObjectToObject( - this.value, - ); + SimpleClassOfObjectToObject(this.value); factory SimpleClassOfObjectToObject.fromJson(Map<String, Object?> json) => _$SimpleClassOfObjectToObjectFromJson(json); @@ -5171,13 +4506,11 @@ class SimpleClassOfObjectToObject { class SimpleClassNullableOfObjectToObject { final Map<Object, Object>? value; - SimpleClassNullableOfObjectToObject( - this.value, - ); + SimpleClassNullableOfObjectToObject(this.value); factory SimpleClassNullableOfObjectToObject.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfObjectToObjectFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfObjectToObjectFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfObjectToObjectToJson(this); @@ -5187,9 +4520,7 @@ class SimpleClassNullableOfObjectToObject { class SimpleClassOfStringToObject { final Map<String, Object> value; - SimpleClassOfStringToObject( - this.value, - ); + SimpleClassOfStringToObject(this.value); factory SimpleClassOfStringToObject.fromJson(Map<String, Object?> json) => _$SimpleClassOfStringToObjectFromJson(json); @@ -5201,13 +4532,11 @@ class SimpleClassOfStringToObject { class SimpleClassNullableOfStringToObject { final Map<String, Object>? value; - SimpleClassNullableOfStringToObject( - this.value, - ); + SimpleClassNullableOfStringToObject(this.value); factory SimpleClassNullableOfStringToObject.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfStringToObjectFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfStringToObjectFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfStringToObjectToJson(this); @@ -5217,9 +4546,7 @@ class SimpleClassNullableOfStringToObject { class SimpleClassOfUriToObject { final Map<Uri, Object> value; - SimpleClassOfUriToObject( - this.value, - ); + SimpleClassOfUriToObject(this.value); factory SimpleClassOfUriToObject.fromJson(Map<String, Object?> json) => _$SimpleClassOfUriToObjectFromJson(json); @@ -5231,13 +4558,11 @@ class SimpleClassOfUriToObject { class SimpleClassNullableOfUriToObject { final Map<Uri, Object>? value; - SimpleClassNullableOfUriToObject( - this.value, - ); + SimpleClassNullableOfUriToObject(this.value); factory SimpleClassNullableOfUriToObject.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfUriToObjectFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfUriToObjectFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfUriToObjectToJson(this); @@ -5247,13 +4572,11 @@ class SimpleClassNullableOfUriToObject { class SimpleClassOfBigIntToObjectNullable { final Map<BigInt, Object?> value; - SimpleClassOfBigIntToObjectNullable( - this.value, - ); + SimpleClassOfBigIntToObjectNullable(this.value); factory SimpleClassOfBigIntToObjectNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfBigIntToObjectNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfBigIntToObjectNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfBigIntToObjectNullableToJson(this); @@ -5263,13 +4586,11 @@ class SimpleClassOfBigIntToObjectNullable { class SimpleClassNullableOfBigIntToObjectNullable { final Map<BigInt, Object?>? value; - SimpleClassNullableOfBigIntToObjectNullable( - this.value, - ); + SimpleClassNullableOfBigIntToObjectNullable(this.value); factory SimpleClassNullableOfBigIntToObjectNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfBigIntToObjectNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfBigIntToObjectNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfBigIntToObjectNullableToJson(this); @@ -5279,13 +4600,11 @@ class SimpleClassNullableOfBigIntToObjectNullable { class SimpleClassOfDateTimeToObjectNullable { final Map<DateTime, Object?> value; - SimpleClassOfDateTimeToObjectNullable( - this.value, - ); + SimpleClassOfDateTimeToObjectNullable(this.value); factory SimpleClassOfDateTimeToObjectNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfDateTimeToObjectNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfDateTimeToObjectNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfDateTimeToObjectNullableToJson(this); @@ -5295,13 +4614,11 @@ class SimpleClassOfDateTimeToObjectNullable { class SimpleClassNullableOfDateTimeToObjectNullable { final Map<DateTime, Object?>? value; - SimpleClassNullableOfDateTimeToObjectNullable( - this.value, - ); + SimpleClassNullableOfDateTimeToObjectNullable(this.value); factory SimpleClassNullableOfDateTimeToObjectNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfDateTimeToObjectNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfDateTimeToObjectNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfDateTimeToObjectNullableToJson(this); @@ -5311,13 +4628,11 @@ class SimpleClassNullableOfDateTimeToObjectNullable { class SimpleClassOfDynamicToObjectNullable { final Map<dynamic, Object?> value; - SimpleClassOfDynamicToObjectNullable( - this.value, - ); + SimpleClassOfDynamicToObjectNullable(this.value); factory SimpleClassOfDynamicToObjectNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfDynamicToObjectNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfDynamicToObjectNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfDynamicToObjectNullableToJson(this); @@ -5327,13 +4642,11 @@ class SimpleClassOfDynamicToObjectNullable { class SimpleClassNullableOfDynamicToObjectNullable { final Map<dynamic, Object?>? value; - SimpleClassNullableOfDynamicToObjectNullable( - this.value, - ); + SimpleClassNullableOfDynamicToObjectNullable(this.value); factory SimpleClassNullableOfDynamicToObjectNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfDynamicToObjectNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfDynamicToObjectNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfDynamicToObjectNullableToJson(this); @@ -5343,13 +4656,11 @@ class SimpleClassNullableOfDynamicToObjectNullable { class SimpleClassOfEnumTypeToObjectNullable { final Map<EnumType, Object?> value; - SimpleClassOfEnumTypeToObjectNullable( - this.value, - ); + SimpleClassOfEnumTypeToObjectNullable(this.value); factory SimpleClassOfEnumTypeToObjectNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfEnumTypeToObjectNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfEnumTypeToObjectNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfEnumTypeToObjectNullableToJson(this); @@ -5359,13 +4670,11 @@ class SimpleClassOfEnumTypeToObjectNullable { class SimpleClassNullableOfEnumTypeToObjectNullable { final Map<EnumType, Object?>? value; - SimpleClassNullableOfEnumTypeToObjectNullable( - this.value, - ); + SimpleClassNullableOfEnumTypeToObjectNullable(this.value); factory SimpleClassNullableOfEnumTypeToObjectNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfEnumTypeToObjectNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfEnumTypeToObjectNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfEnumTypeToObjectNullableToJson(this); @@ -5375,13 +4684,11 @@ class SimpleClassNullableOfEnumTypeToObjectNullable { class SimpleClassOfIntToObjectNullable { final Map<int, Object?> value; - SimpleClassOfIntToObjectNullable( - this.value, - ); + SimpleClassOfIntToObjectNullable(this.value); factory SimpleClassOfIntToObjectNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfIntToObjectNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfIntToObjectNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfIntToObjectNullableToJson(this); @@ -5391,13 +4698,11 @@ class SimpleClassOfIntToObjectNullable { class SimpleClassNullableOfIntToObjectNullable { final Map<int, Object?>? value; - SimpleClassNullableOfIntToObjectNullable( - this.value, - ); + SimpleClassNullableOfIntToObjectNullable(this.value); factory SimpleClassNullableOfIntToObjectNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfIntToObjectNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfIntToObjectNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfIntToObjectNullableToJson(this); @@ -5407,13 +4712,11 @@ class SimpleClassNullableOfIntToObjectNullable { class SimpleClassOfObjectToObjectNullable { final Map<Object, Object?> value; - SimpleClassOfObjectToObjectNullable( - this.value, - ); + SimpleClassOfObjectToObjectNullable(this.value); factory SimpleClassOfObjectToObjectNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfObjectToObjectNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfObjectToObjectNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfObjectToObjectNullableToJson(this); @@ -5423,13 +4726,11 @@ class SimpleClassOfObjectToObjectNullable { class SimpleClassNullableOfObjectToObjectNullable { final Map<Object, Object?>? value; - SimpleClassNullableOfObjectToObjectNullable( - this.value, - ); + SimpleClassNullableOfObjectToObjectNullable(this.value); factory SimpleClassNullableOfObjectToObjectNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfObjectToObjectNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfObjectToObjectNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfObjectToObjectNullableToJson(this); @@ -5439,13 +4740,11 @@ class SimpleClassNullableOfObjectToObjectNullable { class SimpleClassOfStringToObjectNullable { final Map<String, Object?> value; - SimpleClassOfStringToObjectNullable( - this.value, - ); + SimpleClassOfStringToObjectNullable(this.value); factory SimpleClassOfStringToObjectNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfStringToObjectNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfStringToObjectNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfStringToObjectNullableToJson(this); @@ -5455,13 +4754,11 @@ class SimpleClassOfStringToObjectNullable { class SimpleClassNullableOfStringToObjectNullable { final Map<String, Object?>? value; - SimpleClassNullableOfStringToObjectNullable( - this.value, - ); + SimpleClassNullableOfStringToObjectNullable(this.value); factory SimpleClassNullableOfStringToObjectNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfStringToObjectNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfStringToObjectNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfStringToObjectNullableToJson(this); @@ -5471,13 +4768,11 @@ class SimpleClassNullableOfStringToObjectNullable { class SimpleClassOfUriToObjectNullable { final Map<Uri, Object?> value; - SimpleClassOfUriToObjectNullable( - this.value, - ); + SimpleClassOfUriToObjectNullable(this.value); factory SimpleClassOfUriToObjectNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfUriToObjectNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfUriToObjectNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfUriToObjectNullableToJson(this); @@ -5487,13 +4782,11 @@ class SimpleClassOfUriToObjectNullable { class SimpleClassNullableOfUriToObjectNullable { final Map<Uri, Object?>? value; - SimpleClassNullableOfUriToObjectNullable( - this.value, - ); + SimpleClassNullableOfUriToObjectNullable(this.value); factory SimpleClassNullableOfUriToObjectNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfUriToObjectNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfUriToObjectNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfUriToObjectNullableToJson(this); @@ -5503,9 +4796,7 @@ class SimpleClassNullableOfUriToObjectNullable { class SimpleClassOfBigIntToRecord { final Map<BigInt, (int, String, {bool truth})> value; - SimpleClassOfBigIntToRecord( - this.value, - ); + SimpleClassOfBigIntToRecord(this.value); factory SimpleClassOfBigIntToRecord.fromJson(Map<String, Object?> json) => _$SimpleClassOfBigIntToRecordFromJson(json); @@ -5517,13 +4808,11 @@ class SimpleClassOfBigIntToRecord { class SimpleClassNullableOfBigIntToRecord { final Map<BigInt, (int, String, {bool truth})>? value; - SimpleClassNullableOfBigIntToRecord( - this.value, - ); + SimpleClassNullableOfBigIntToRecord(this.value); factory SimpleClassNullableOfBigIntToRecord.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfBigIntToRecordFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfBigIntToRecordFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfBigIntToRecordToJson(this); @@ -5533,9 +4822,7 @@ class SimpleClassNullableOfBigIntToRecord { class SimpleClassOfDateTimeToRecord { final Map<DateTime, (int, String, {bool truth})> value; - SimpleClassOfDateTimeToRecord( - this.value, - ); + SimpleClassOfDateTimeToRecord(this.value); factory SimpleClassOfDateTimeToRecord.fromJson(Map<String, Object?> json) => _$SimpleClassOfDateTimeToRecordFromJson(json); @@ -5547,13 +4834,11 @@ class SimpleClassOfDateTimeToRecord { class SimpleClassNullableOfDateTimeToRecord { final Map<DateTime, (int, String, {bool truth})>? value; - SimpleClassNullableOfDateTimeToRecord( - this.value, - ); + SimpleClassNullableOfDateTimeToRecord(this.value); factory SimpleClassNullableOfDateTimeToRecord.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfDateTimeToRecordFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfDateTimeToRecordFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfDateTimeToRecordToJson(this); @@ -5563,9 +4848,7 @@ class SimpleClassNullableOfDateTimeToRecord { class SimpleClassOfDynamicToRecord { final Map<dynamic, (int, String, {bool truth})> value; - SimpleClassOfDynamicToRecord( - this.value, - ); + SimpleClassOfDynamicToRecord(this.value); factory SimpleClassOfDynamicToRecord.fromJson(Map<String, Object?> json) => _$SimpleClassOfDynamicToRecordFromJson(json); @@ -5577,13 +4860,11 @@ class SimpleClassOfDynamicToRecord { class SimpleClassNullableOfDynamicToRecord { final Map<dynamic, (int, String, {bool truth})>? value; - SimpleClassNullableOfDynamicToRecord( - this.value, - ); + SimpleClassNullableOfDynamicToRecord(this.value); factory SimpleClassNullableOfDynamicToRecord.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfDynamicToRecordFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfDynamicToRecordFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfDynamicToRecordToJson(this); @@ -5593,9 +4874,7 @@ class SimpleClassNullableOfDynamicToRecord { class SimpleClassOfEnumTypeToRecord { final Map<EnumType, (int, String, {bool truth})> value; - SimpleClassOfEnumTypeToRecord( - this.value, - ); + SimpleClassOfEnumTypeToRecord(this.value); factory SimpleClassOfEnumTypeToRecord.fromJson(Map<String, Object?> json) => _$SimpleClassOfEnumTypeToRecordFromJson(json); @@ -5607,13 +4886,11 @@ class SimpleClassOfEnumTypeToRecord { class SimpleClassNullableOfEnumTypeToRecord { final Map<EnumType, (int, String, {bool truth})>? value; - SimpleClassNullableOfEnumTypeToRecord( - this.value, - ); + SimpleClassNullableOfEnumTypeToRecord(this.value); factory SimpleClassNullableOfEnumTypeToRecord.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfEnumTypeToRecordFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfEnumTypeToRecordFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfEnumTypeToRecordToJson(this); @@ -5623,9 +4900,7 @@ class SimpleClassNullableOfEnumTypeToRecord { class SimpleClassOfIntToRecord { final Map<int, (int, String, {bool truth})> value; - SimpleClassOfIntToRecord( - this.value, - ); + SimpleClassOfIntToRecord(this.value); factory SimpleClassOfIntToRecord.fromJson(Map<String, Object?> json) => _$SimpleClassOfIntToRecordFromJson(json); @@ -5637,13 +4912,11 @@ class SimpleClassOfIntToRecord { class SimpleClassNullableOfIntToRecord { final Map<int, (int, String, {bool truth})>? value; - SimpleClassNullableOfIntToRecord( - this.value, - ); + SimpleClassNullableOfIntToRecord(this.value); factory SimpleClassNullableOfIntToRecord.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfIntToRecordFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfIntToRecordFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfIntToRecordToJson(this); @@ -5653,9 +4926,7 @@ class SimpleClassNullableOfIntToRecord { class SimpleClassOfObjectToRecord { final Map<Object, (int, String, {bool truth})> value; - SimpleClassOfObjectToRecord( - this.value, - ); + SimpleClassOfObjectToRecord(this.value); factory SimpleClassOfObjectToRecord.fromJson(Map<String, Object?> json) => _$SimpleClassOfObjectToRecordFromJson(json); @@ -5667,13 +4938,11 @@ class SimpleClassOfObjectToRecord { class SimpleClassNullableOfObjectToRecord { final Map<Object, (int, String, {bool truth})>? value; - SimpleClassNullableOfObjectToRecord( - this.value, - ); + SimpleClassNullableOfObjectToRecord(this.value); factory SimpleClassNullableOfObjectToRecord.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfObjectToRecordFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfObjectToRecordFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfObjectToRecordToJson(this); @@ -5683,9 +4952,7 @@ class SimpleClassNullableOfObjectToRecord { class SimpleClassOfStringToRecord { final Map<String, (int, String, {bool truth})> value; - SimpleClassOfStringToRecord( - this.value, - ); + SimpleClassOfStringToRecord(this.value); factory SimpleClassOfStringToRecord.fromJson(Map<String, Object?> json) => _$SimpleClassOfStringToRecordFromJson(json); @@ -5697,13 +4964,11 @@ class SimpleClassOfStringToRecord { class SimpleClassNullableOfStringToRecord { final Map<String, (int, String, {bool truth})>? value; - SimpleClassNullableOfStringToRecord( - this.value, - ); + SimpleClassNullableOfStringToRecord(this.value); factory SimpleClassNullableOfStringToRecord.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfStringToRecordFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfStringToRecordFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfStringToRecordToJson(this); @@ -5713,9 +4978,7 @@ class SimpleClassNullableOfStringToRecord { class SimpleClassOfUriToRecord { final Map<Uri, (int, String, {bool truth})> value; - SimpleClassOfUriToRecord( - this.value, - ); + SimpleClassOfUriToRecord(this.value); factory SimpleClassOfUriToRecord.fromJson(Map<String, Object?> json) => _$SimpleClassOfUriToRecordFromJson(json); @@ -5727,13 +4990,11 @@ class SimpleClassOfUriToRecord { class SimpleClassNullableOfUriToRecord { final Map<Uri, (int, String, {bool truth})>? value; - SimpleClassNullableOfUriToRecord( - this.value, - ); + SimpleClassNullableOfUriToRecord(this.value); factory SimpleClassNullableOfUriToRecord.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfUriToRecordFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfUriToRecordFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfUriToRecordToJson(this); @@ -5743,9 +5004,7 @@ class SimpleClassNullableOfUriToRecord { class SimpleClassOfBigIntToString { final Map<BigInt, String> value; - SimpleClassOfBigIntToString( - this.value, - ); + SimpleClassOfBigIntToString(this.value); factory SimpleClassOfBigIntToString.fromJson(Map<String, Object?> json) => _$SimpleClassOfBigIntToStringFromJson(json); @@ -5757,13 +5016,11 @@ class SimpleClassOfBigIntToString { class SimpleClassNullableOfBigIntToString { final Map<BigInt, String>? value; - SimpleClassNullableOfBigIntToString( - this.value, - ); + SimpleClassNullableOfBigIntToString(this.value); factory SimpleClassNullableOfBigIntToString.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfBigIntToStringFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfBigIntToStringFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfBigIntToStringToJson(this); @@ -5773,9 +5030,7 @@ class SimpleClassNullableOfBigIntToString { class SimpleClassOfDateTimeToString { final Map<DateTime, String> value; - SimpleClassOfDateTimeToString( - this.value, - ); + SimpleClassOfDateTimeToString(this.value); factory SimpleClassOfDateTimeToString.fromJson(Map<String, Object?> json) => _$SimpleClassOfDateTimeToStringFromJson(json); @@ -5787,13 +5042,11 @@ class SimpleClassOfDateTimeToString { class SimpleClassNullableOfDateTimeToString { final Map<DateTime, String>? value; - SimpleClassNullableOfDateTimeToString( - this.value, - ); + SimpleClassNullableOfDateTimeToString(this.value); factory SimpleClassNullableOfDateTimeToString.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfDateTimeToStringFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfDateTimeToStringFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfDateTimeToStringToJson(this); @@ -5803,9 +5056,7 @@ class SimpleClassNullableOfDateTimeToString { class SimpleClassOfDynamicToString { final Map<dynamic, String> value; - SimpleClassOfDynamicToString( - this.value, - ); + SimpleClassOfDynamicToString(this.value); factory SimpleClassOfDynamicToString.fromJson(Map<String, Object?> json) => _$SimpleClassOfDynamicToStringFromJson(json); @@ -5817,13 +5068,11 @@ class SimpleClassOfDynamicToString { class SimpleClassNullableOfDynamicToString { final Map<dynamic, String>? value; - SimpleClassNullableOfDynamicToString( - this.value, - ); + SimpleClassNullableOfDynamicToString(this.value); factory SimpleClassNullableOfDynamicToString.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfDynamicToStringFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfDynamicToStringFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfDynamicToStringToJson(this); @@ -5833,9 +5082,7 @@ class SimpleClassNullableOfDynamicToString { class SimpleClassOfEnumTypeToString { final Map<EnumType, String> value; - SimpleClassOfEnumTypeToString( - this.value, - ); + SimpleClassOfEnumTypeToString(this.value); factory SimpleClassOfEnumTypeToString.fromJson(Map<String, Object?> json) => _$SimpleClassOfEnumTypeToStringFromJson(json); @@ -5847,13 +5094,11 @@ class SimpleClassOfEnumTypeToString { class SimpleClassNullableOfEnumTypeToString { final Map<EnumType, String>? value; - SimpleClassNullableOfEnumTypeToString( - this.value, - ); + SimpleClassNullableOfEnumTypeToString(this.value); factory SimpleClassNullableOfEnumTypeToString.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfEnumTypeToStringFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfEnumTypeToStringFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfEnumTypeToStringToJson(this); @@ -5863,9 +5108,7 @@ class SimpleClassNullableOfEnumTypeToString { class SimpleClassOfIntToString { final Map<int, String> value; - SimpleClassOfIntToString( - this.value, - ); + SimpleClassOfIntToString(this.value); factory SimpleClassOfIntToString.fromJson(Map<String, Object?> json) => _$SimpleClassOfIntToStringFromJson(json); @@ -5877,13 +5120,11 @@ class SimpleClassOfIntToString { class SimpleClassNullableOfIntToString { final Map<int, String>? value; - SimpleClassNullableOfIntToString( - this.value, - ); + SimpleClassNullableOfIntToString(this.value); factory SimpleClassNullableOfIntToString.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfIntToStringFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfIntToStringFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfIntToStringToJson(this); @@ -5893,9 +5134,7 @@ class SimpleClassNullableOfIntToString { class SimpleClassOfObjectToString { final Map<Object, String> value; - SimpleClassOfObjectToString( - this.value, - ); + SimpleClassOfObjectToString(this.value); factory SimpleClassOfObjectToString.fromJson(Map<String, Object?> json) => _$SimpleClassOfObjectToStringFromJson(json); @@ -5907,13 +5146,11 @@ class SimpleClassOfObjectToString { class SimpleClassNullableOfObjectToString { final Map<Object, String>? value; - SimpleClassNullableOfObjectToString( - this.value, - ); + SimpleClassNullableOfObjectToString(this.value); factory SimpleClassNullableOfObjectToString.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfObjectToStringFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfObjectToStringFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfObjectToStringToJson(this); @@ -5923,9 +5160,7 @@ class SimpleClassNullableOfObjectToString { class SimpleClassOfStringToString { final Map<String, String> value; - SimpleClassOfStringToString( - this.value, - ); + SimpleClassOfStringToString(this.value); factory SimpleClassOfStringToString.fromJson(Map<String, Object?> json) => _$SimpleClassOfStringToStringFromJson(json); @@ -5937,13 +5172,11 @@ class SimpleClassOfStringToString { class SimpleClassNullableOfStringToString { final Map<String, String>? value; - SimpleClassNullableOfStringToString( - this.value, - ); + SimpleClassNullableOfStringToString(this.value); factory SimpleClassNullableOfStringToString.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfStringToStringFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfStringToStringFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfStringToStringToJson(this); @@ -5953,9 +5186,7 @@ class SimpleClassNullableOfStringToString { class SimpleClassOfUriToString { final Map<Uri, String> value; - SimpleClassOfUriToString( - this.value, - ); + SimpleClassOfUriToString(this.value); factory SimpleClassOfUriToString.fromJson(Map<String, Object?> json) => _$SimpleClassOfUriToStringFromJson(json); @@ -5967,13 +5198,11 @@ class SimpleClassOfUriToString { class SimpleClassNullableOfUriToString { final Map<Uri, String>? value; - SimpleClassNullableOfUriToString( - this.value, - ); + SimpleClassNullableOfUriToString(this.value); factory SimpleClassNullableOfUriToString.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfUriToStringFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfUriToStringFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfUriToStringToJson(this); @@ -5983,13 +5212,11 @@ class SimpleClassNullableOfUriToString { class SimpleClassOfBigIntToStringNullable { final Map<BigInt, String?> value; - SimpleClassOfBigIntToStringNullable( - this.value, - ); + SimpleClassOfBigIntToStringNullable(this.value); factory SimpleClassOfBigIntToStringNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfBigIntToStringNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfBigIntToStringNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfBigIntToStringNullableToJson(this); @@ -5999,13 +5226,11 @@ class SimpleClassOfBigIntToStringNullable { class SimpleClassNullableOfBigIntToStringNullable { final Map<BigInt, String?>? value; - SimpleClassNullableOfBigIntToStringNullable( - this.value, - ); + SimpleClassNullableOfBigIntToStringNullable(this.value); factory SimpleClassNullableOfBigIntToStringNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfBigIntToStringNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfBigIntToStringNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfBigIntToStringNullableToJson(this); @@ -6015,13 +5240,11 @@ class SimpleClassNullableOfBigIntToStringNullable { class SimpleClassOfDateTimeToStringNullable { final Map<DateTime, String?> value; - SimpleClassOfDateTimeToStringNullable( - this.value, - ); + SimpleClassOfDateTimeToStringNullable(this.value); factory SimpleClassOfDateTimeToStringNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfDateTimeToStringNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfDateTimeToStringNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfDateTimeToStringNullableToJson(this); @@ -6031,13 +5254,11 @@ class SimpleClassOfDateTimeToStringNullable { class SimpleClassNullableOfDateTimeToStringNullable { final Map<DateTime, String?>? value; - SimpleClassNullableOfDateTimeToStringNullable( - this.value, - ); + SimpleClassNullableOfDateTimeToStringNullable(this.value); factory SimpleClassNullableOfDateTimeToStringNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfDateTimeToStringNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfDateTimeToStringNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfDateTimeToStringNullableToJson(this); @@ -6047,13 +5268,11 @@ class SimpleClassNullableOfDateTimeToStringNullable { class SimpleClassOfDynamicToStringNullable { final Map<dynamic, String?> value; - SimpleClassOfDynamicToStringNullable( - this.value, - ); + SimpleClassOfDynamicToStringNullable(this.value); factory SimpleClassOfDynamicToStringNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfDynamicToStringNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfDynamicToStringNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfDynamicToStringNullableToJson(this); @@ -6063,13 +5282,11 @@ class SimpleClassOfDynamicToStringNullable { class SimpleClassNullableOfDynamicToStringNullable { final Map<dynamic, String?>? value; - SimpleClassNullableOfDynamicToStringNullable( - this.value, - ); + SimpleClassNullableOfDynamicToStringNullable(this.value); factory SimpleClassNullableOfDynamicToStringNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfDynamicToStringNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfDynamicToStringNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfDynamicToStringNullableToJson(this); @@ -6079,13 +5296,11 @@ class SimpleClassNullableOfDynamicToStringNullable { class SimpleClassOfEnumTypeToStringNullable { final Map<EnumType, String?> value; - SimpleClassOfEnumTypeToStringNullable( - this.value, - ); + SimpleClassOfEnumTypeToStringNullable(this.value); factory SimpleClassOfEnumTypeToStringNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfEnumTypeToStringNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfEnumTypeToStringNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfEnumTypeToStringNullableToJson(this); @@ -6095,13 +5310,11 @@ class SimpleClassOfEnumTypeToStringNullable { class SimpleClassNullableOfEnumTypeToStringNullable { final Map<EnumType, String?>? value; - SimpleClassNullableOfEnumTypeToStringNullable( - this.value, - ); + SimpleClassNullableOfEnumTypeToStringNullable(this.value); factory SimpleClassNullableOfEnumTypeToStringNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfEnumTypeToStringNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfEnumTypeToStringNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfEnumTypeToStringNullableToJson(this); @@ -6111,13 +5324,11 @@ class SimpleClassNullableOfEnumTypeToStringNullable { class SimpleClassOfIntToStringNullable { final Map<int, String?> value; - SimpleClassOfIntToStringNullable( - this.value, - ); + SimpleClassOfIntToStringNullable(this.value); factory SimpleClassOfIntToStringNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfIntToStringNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfIntToStringNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfIntToStringNullableToJson(this); @@ -6127,13 +5338,11 @@ class SimpleClassOfIntToStringNullable { class SimpleClassNullableOfIntToStringNullable { final Map<int, String?>? value; - SimpleClassNullableOfIntToStringNullable( - this.value, - ); + SimpleClassNullableOfIntToStringNullable(this.value); factory SimpleClassNullableOfIntToStringNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfIntToStringNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfIntToStringNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfIntToStringNullableToJson(this); @@ -6143,13 +5352,11 @@ class SimpleClassNullableOfIntToStringNullable { class SimpleClassOfObjectToStringNullable { final Map<Object, String?> value; - SimpleClassOfObjectToStringNullable( - this.value, - ); + SimpleClassOfObjectToStringNullable(this.value); factory SimpleClassOfObjectToStringNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfObjectToStringNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfObjectToStringNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfObjectToStringNullableToJson(this); @@ -6159,13 +5366,11 @@ class SimpleClassOfObjectToStringNullable { class SimpleClassNullableOfObjectToStringNullable { final Map<Object, String?>? value; - SimpleClassNullableOfObjectToStringNullable( - this.value, - ); + SimpleClassNullableOfObjectToStringNullable(this.value); factory SimpleClassNullableOfObjectToStringNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfObjectToStringNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfObjectToStringNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfObjectToStringNullableToJson(this); @@ -6175,13 +5380,11 @@ class SimpleClassNullableOfObjectToStringNullable { class SimpleClassOfStringToStringNullable { final Map<String, String?> value; - SimpleClassOfStringToStringNullable( - this.value, - ); + SimpleClassOfStringToStringNullable(this.value); factory SimpleClassOfStringToStringNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfStringToStringNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfStringToStringNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfStringToStringNullableToJson(this); @@ -6191,13 +5394,11 @@ class SimpleClassOfStringToStringNullable { class SimpleClassNullableOfStringToStringNullable { final Map<String, String?>? value; - SimpleClassNullableOfStringToStringNullable( - this.value, - ); + SimpleClassNullableOfStringToStringNullable(this.value); factory SimpleClassNullableOfStringToStringNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfStringToStringNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfStringToStringNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfStringToStringNullableToJson(this); @@ -6207,13 +5408,11 @@ class SimpleClassNullableOfStringToStringNullable { class SimpleClassOfUriToStringNullable { final Map<Uri, String?> value; - SimpleClassOfUriToStringNullable( - this.value, - ); + SimpleClassOfUriToStringNullable(this.value); factory SimpleClassOfUriToStringNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfUriToStringNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfUriToStringNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfUriToStringNullableToJson(this); @@ -6223,13 +5422,11 @@ class SimpleClassOfUriToStringNullable { class SimpleClassNullableOfUriToStringNullable { final Map<Uri, String?>? value; - SimpleClassNullableOfUriToStringNullable( - this.value, - ); + SimpleClassNullableOfUriToStringNullable(this.value); factory SimpleClassNullableOfUriToStringNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfUriToStringNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfUriToStringNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfUriToStringNullableToJson(this); @@ -6239,9 +5436,7 @@ class SimpleClassNullableOfUriToStringNullable { class SimpleClassOfBigIntToUri { final Map<BigInt, Uri> value; - SimpleClassOfBigIntToUri( - this.value, - ); + SimpleClassOfBigIntToUri(this.value); factory SimpleClassOfBigIntToUri.fromJson(Map<String, Object?> json) => _$SimpleClassOfBigIntToUriFromJson(json); @@ -6253,13 +5448,11 @@ class SimpleClassOfBigIntToUri { class SimpleClassNullableOfBigIntToUri { final Map<BigInt, Uri>? value; - SimpleClassNullableOfBigIntToUri( - this.value, - ); + SimpleClassNullableOfBigIntToUri(this.value); factory SimpleClassNullableOfBigIntToUri.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfBigIntToUriFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfBigIntToUriFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfBigIntToUriToJson(this); @@ -6269,9 +5462,7 @@ class SimpleClassNullableOfBigIntToUri { class SimpleClassOfDateTimeToUri { final Map<DateTime, Uri> value; - SimpleClassOfDateTimeToUri( - this.value, - ); + SimpleClassOfDateTimeToUri(this.value); factory SimpleClassOfDateTimeToUri.fromJson(Map<String, Object?> json) => _$SimpleClassOfDateTimeToUriFromJson(json); @@ -6283,13 +5474,11 @@ class SimpleClassOfDateTimeToUri { class SimpleClassNullableOfDateTimeToUri { final Map<DateTime, Uri>? value; - SimpleClassNullableOfDateTimeToUri( - this.value, - ); + SimpleClassNullableOfDateTimeToUri(this.value); factory SimpleClassNullableOfDateTimeToUri.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfDateTimeToUriFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfDateTimeToUriFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfDateTimeToUriToJson(this); @@ -6299,9 +5488,7 @@ class SimpleClassNullableOfDateTimeToUri { class SimpleClassOfDynamicToUri { final Map<dynamic, Uri> value; - SimpleClassOfDynamicToUri( - this.value, - ); + SimpleClassOfDynamicToUri(this.value); factory SimpleClassOfDynamicToUri.fromJson(Map<String, Object?> json) => _$SimpleClassOfDynamicToUriFromJson(json); @@ -6313,13 +5500,11 @@ class SimpleClassOfDynamicToUri { class SimpleClassNullableOfDynamicToUri { final Map<dynamic, Uri>? value; - SimpleClassNullableOfDynamicToUri( - this.value, - ); + SimpleClassNullableOfDynamicToUri(this.value); factory SimpleClassNullableOfDynamicToUri.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfDynamicToUriFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfDynamicToUriFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfDynamicToUriToJson(this); @@ -6329,9 +5514,7 @@ class SimpleClassNullableOfDynamicToUri { class SimpleClassOfEnumTypeToUri { final Map<EnumType, Uri> value; - SimpleClassOfEnumTypeToUri( - this.value, - ); + SimpleClassOfEnumTypeToUri(this.value); factory SimpleClassOfEnumTypeToUri.fromJson(Map<String, Object?> json) => _$SimpleClassOfEnumTypeToUriFromJson(json); @@ -6343,13 +5526,11 @@ class SimpleClassOfEnumTypeToUri { class SimpleClassNullableOfEnumTypeToUri { final Map<EnumType, Uri>? value; - SimpleClassNullableOfEnumTypeToUri( - this.value, - ); + SimpleClassNullableOfEnumTypeToUri(this.value); factory SimpleClassNullableOfEnumTypeToUri.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfEnumTypeToUriFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfEnumTypeToUriFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfEnumTypeToUriToJson(this); @@ -6359,9 +5540,7 @@ class SimpleClassNullableOfEnumTypeToUri { class SimpleClassOfIntToUri { final Map<int, Uri> value; - SimpleClassOfIntToUri( - this.value, - ); + SimpleClassOfIntToUri(this.value); factory SimpleClassOfIntToUri.fromJson(Map<String, Object?> json) => _$SimpleClassOfIntToUriFromJson(json); @@ -6373,9 +5552,7 @@ class SimpleClassOfIntToUri { class SimpleClassNullableOfIntToUri { final Map<int, Uri>? value; - SimpleClassNullableOfIntToUri( - this.value, - ); + SimpleClassNullableOfIntToUri(this.value); factory SimpleClassNullableOfIntToUri.fromJson(Map<String, Object?> json) => _$SimpleClassNullableOfIntToUriFromJson(json); @@ -6387,9 +5564,7 @@ class SimpleClassNullableOfIntToUri { class SimpleClassOfObjectToUri { final Map<Object, Uri> value; - SimpleClassOfObjectToUri( - this.value, - ); + SimpleClassOfObjectToUri(this.value); factory SimpleClassOfObjectToUri.fromJson(Map<String, Object?> json) => _$SimpleClassOfObjectToUriFromJson(json); @@ -6401,13 +5576,11 @@ class SimpleClassOfObjectToUri { class SimpleClassNullableOfObjectToUri { final Map<Object, Uri>? value; - SimpleClassNullableOfObjectToUri( - this.value, - ); + SimpleClassNullableOfObjectToUri(this.value); factory SimpleClassNullableOfObjectToUri.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfObjectToUriFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfObjectToUriFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfObjectToUriToJson(this); @@ -6417,9 +5590,7 @@ class SimpleClassNullableOfObjectToUri { class SimpleClassOfStringToUri { final Map<String, Uri> value; - SimpleClassOfStringToUri( - this.value, - ); + SimpleClassOfStringToUri(this.value); factory SimpleClassOfStringToUri.fromJson(Map<String, Object?> json) => _$SimpleClassOfStringToUriFromJson(json); @@ -6431,13 +5602,11 @@ class SimpleClassOfStringToUri { class SimpleClassNullableOfStringToUri { final Map<String, Uri>? value; - SimpleClassNullableOfStringToUri( - this.value, - ); + SimpleClassNullableOfStringToUri(this.value); factory SimpleClassNullableOfStringToUri.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfStringToUriFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfStringToUriFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfStringToUriToJson(this); @@ -6447,9 +5616,7 @@ class SimpleClassNullableOfStringToUri { class SimpleClassOfUriToUri { final Map<Uri, Uri> value; - SimpleClassOfUriToUri( - this.value, - ); + SimpleClassOfUriToUri(this.value); factory SimpleClassOfUriToUri.fromJson(Map<String, Object?> json) => _$SimpleClassOfUriToUriFromJson(json); @@ -6461,9 +5628,7 @@ class SimpleClassOfUriToUri { class SimpleClassNullableOfUriToUri { final Map<Uri, Uri>? value; - SimpleClassNullableOfUriToUri( - this.value, - ); + SimpleClassNullableOfUriToUri(this.value); factory SimpleClassNullableOfUriToUri.fromJson(Map<String, Object?> json) => _$SimpleClassNullableOfUriToUriFromJson(json); @@ -6475,13 +5640,11 @@ class SimpleClassNullableOfUriToUri { class SimpleClassOfBigIntToUriNullable { final Map<BigInt, Uri?> value; - SimpleClassOfBigIntToUriNullable( - this.value, - ); + SimpleClassOfBigIntToUriNullable(this.value); factory SimpleClassOfBigIntToUriNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfBigIntToUriNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfBigIntToUriNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfBigIntToUriNullableToJson(this); @@ -6491,13 +5654,11 @@ class SimpleClassOfBigIntToUriNullable { class SimpleClassNullableOfBigIntToUriNullable { final Map<BigInt, Uri?>? value; - SimpleClassNullableOfBigIntToUriNullable( - this.value, - ); + SimpleClassNullableOfBigIntToUriNullable(this.value); factory SimpleClassNullableOfBigIntToUriNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfBigIntToUriNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfBigIntToUriNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfBigIntToUriNullableToJson(this); @@ -6507,13 +5668,11 @@ class SimpleClassNullableOfBigIntToUriNullable { class SimpleClassOfDateTimeToUriNullable { final Map<DateTime, Uri?> value; - SimpleClassOfDateTimeToUriNullable( - this.value, - ); + SimpleClassOfDateTimeToUriNullable(this.value); factory SimpleClassOfDateTimeToUriNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfDateTimeToUriNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfDateTimeToUriNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfDateTimeToUriNullableToJson(this); @@ -6523,13 +5682,11 @@ class SimpleClassOfDateTimeToUriNullable { class SimpleClassNullableOfDateTimeToUriNullable { final Map<DateTime, Uri?>? value; - SimpleClassNullableOfDateTimeToUriNullable( - this.value, - ); + SimpleClassNullableOfDateTimeToUriNullable(this.value); factory SimpleClassNullableOfDateTimeToUriNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfDateTimeToUriNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfDateTimeToUriNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfDateTimeToUriNullableToJson(this); @@ -6539,13 +5696,11 @@ class SimpleClassNullableOfDateTimeToUriNullable { class SimpleClassOfDynamicToUriNullable { final Map<dynamic, Uri?> value; - SimpleClassOfDynamicToUriNullable( - this.value, - ); + SimpleClassOfDynamicToUriNullable(this.value); factory SimpleClassOfDynamicToUriNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfDynamicToUriNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfDynamicToUriNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfDynamicToUriNullableToJson(this); @@ -6555,13 +5710,11 @@ class SimpleClassOfDynamicToUriNullable { class SimpleClassNullableOfDynamicToUriNullable { final Map<dynamic, Uri?>? value; - SimpleClassNullableOfDynamicToUriNullable( - this.value, - ); + SimpleClassNullableOfDynamicToUriNullable(this.value); factory SimpleClassNullableOfDynamicToUriNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfDynamicToUriNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfDynamicToUriNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfDynamicToUriNullableToJson(this); @@ -6571,13 +5724,11 @@ class SimpleClassNullableOfDynamicToUriNullable { class SimpleClassOfEnumTypeToUriNullable { final Map<EnumType, Uri?> value; - SimpleClassOfEnumTypeToUriNullable( - this.value, - ); + SimpleClassOfEnumTypeToUriNullable(this.value); factory SimpleClassOfEnumTypeToUriNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfEnumTypeToUriNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfEnumTypeToUriNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfEnumTypeToUriNullableToJson(this); @@ -6587,13 +5738,11 @@ class SimpleClassOfEnumTypeToUriNullable { class SimpleClassNullableOfEnumTypeToUriNullable { final Map<EnumType, Uri?>? value; - SimpleClassNullableOfEnumTypeToUriNullable( - this.value, - ); + SimpleClassNullableOfEnumTypeToUriNullable(this.value); factory SimpleClassNullableOfEnumTypeToUriNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfEnumTypeToUriNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfEnumTypeToUriNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfEnumTypeToUriNullableToJson(this); @@ -6603,9 +5752,7 @@ class SimpleClassNullableOfEnumTypeToUriNullable { class SimpleClassOfIntToUriNullable { final Map<int, Uri?> value; - SimpleClassOfIntToUriNullable( - this.value, - ); + SimpleClassOfIntToUriNullable(this.value); factory SimpleClassOfIntToUriNullable.fromJson(Map<String, Object?> json) => _$SimpleClassOfIntToUriNullableFromJson(json); @@ -6617,13 +5764,11 @@ class SimpleClassOfIntToUriNullable { class SimpleClassNullableOfIntToUriNullable { final Map<int, Uri?>? value; - SimpleClassNullableOfIntToUriNullable( - this.value, - ); + SimpleClassNullableOfIntToUriNullable(this.value); factory SimpleClassNullableOfIntToUriNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfIntToUriNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfIntToUriNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfIntToUriNullableToJson(this); @@ -6633,13 +5778,11 @@ class SimpleClassNullableOfIntToUriNullable { class SimpleClassOfObjectToUriNullable { final Map<Object, Uri?> value; - SimpleClassOfObjectToUriNullable( - this.value, - ); + SimpleClassOfObjectToUriNullable(this.value); factory SimpleClassOfObjectToUriNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfObjectToUriNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfObjectToUriNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfObjectToUriNullableToJson(this); @@ -6649,13 +5792,11 @@ class SimpleClassOfObjectToUriNullable { class SimpleClassNullableOfObjectToUriNullable { final Map<Object, Uri?>? value; - SimpleClassNullableOfObjectToUriNullable( - this.value, - ); + SimpleClassNullableOfObjectToUriNullable(this.value); factory SimpleClassNullableOfObjectToUriNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfObjectToUriNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfObjectToUriNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfObjectToUriNullableToJson(this); @@ -6665,13 +5806,11 @@ class SimpleClassNullableOfObjectToUriNullable { class SimpleClassOfStringToUriNullable { final Map<String, Uri?> value; - SimpleClassOfStringToUriNullable( - this.value, - ); + SimpleClassOfStringToUriNullable(this.value); factory SimpleClassOfStringToUriNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfStringToUriNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfStringToUriNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfStringToUriNullableToJson(this); @@ -6681,13 +5820,11 @@ class SimpleClassOfStringToUriNullable { class SimpleClassNullableOfStringToUriNullable { final Map<String, Uri?>? value; - SimpleClassNullableOfStringToUriNullable( - this.value, - ); + SimpleClassNullableOfStringToUriNullable(this.value); factory SimpleClassNullableOfStringToUriNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfStringToUriNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfStringToUriNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfStringToUriNullableToJson(this); @@ -6697,9 +5834,7 @@ class SimpleClassNullableOfStringToUriNullable { class SimpleClassOfUriToUriNullable { final Map<Uri, Uri?> value; - SimpleClassOfUriToUriNullable( - this.value, - ); + SimpleClassOfUriToUriNullable(this.value); factory SimpleClassOfUriToUriNullable.fromJson(Map<String, Object?> json) => _$SimpleClassOfUriToUriNullableFromJson(json); @@ -6711,13 +5846,11 @@ class SimpleClassOfUriToUriNullable { class SimpleClassNullableOfUriToUriNullable { final Map<Uri, Uri?>? value; - SimpleClassNullableOfUriToUriNullable( - this.value, - ); + SimpleClassNullableOfUriToUriNullable(this.value); factory SimpleClassNullableOfUriToUriNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfUriToUriNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfUriToUriNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfUriToUriNullableToJson(this); diff --git a/json_serializable/test/supported_types/input.type_map.g.dart b/json_serializable/test/supported_types/input.type_map.g.dart index 5c8a3ea82..7077797f6 100644 --- a/json_serializable/test/supported_types/input.type_map.g.dart +++ b/json_serializable/test/supported_types/input.type_map.g.dart @@ -9,9 +9,9 @@ part of 'input.type_map.dart'; // ************************************************************************** SimpleClass _$SimpleClassFromJson(Map<String, dynamic> json) => SimpleClass( - json['value'] as Map<String, dynamic>, - json['withDefault'] as Map<String, dynamic>? ?? {'a': 1}, - ); + json['value'] as Map<String, dynamic>, + json['withDefault'] as Map<String, dynamic>? ?? {'a': 1}, +); Map<String, dynamic> _$SimpleClassToJson(SimpleClass instance) => <String, dynamic>{ @@ -26,116 +26,116 @@ SimpleClassNullable _$SimpleClassNullableFromJson(Map<String, dynamic> json) => ); Map<String, dynamic> _$SimpleClassNullableToJson( - SimpleClassNullable instance) => - <String, dynamic>{ - 'value': instance.value, - 'withDefault': instance.withDefault, - }; + SimpleClassNullable instance, +) => <String, dynamic>{ + 'value': instance.value, + 'withDefault': instance.withDefault, +}; SimpleClassOfBigIntToBigInt _$SimpleClassOfBigIntToBigIntFromJson( - Map<String, dynamic> json) => - SimpleClassOfBigIntToBigInt( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(BigInt.parse(k), BigInt.parse(e as String)), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfBigIntToBigInt( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(BigInt.parse(k), BigInt.parse(e as String)), + ), +); Map<String, dynamic> _$SimpleClassOfBigIntToBigIntToJson( - SimpleClassOfBigIntToBigInt instance) => - <String, dynamic>{ - 'value': - instance.value.map((k, e) => MapEntry(k.toString(), e.toString())), - }; + SimpleClassOfBigIntToBigInt instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e.toString())), +}; SimpleClassNullableOfBigIntToBigInt - _$SimpleClassNullableOfBigIntToBigIntFromJson(Map<String, dynamic> json) => - SimpleClassNullableOfBigIntToBigInt( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(BigInt.parse(k), BigInt.parse(e as String)), - ), - ); +_$SimpleClassNullableOfBigIntToBigIntFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfBigIntToBigInt( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(BigInt.parse(k), BigInt.parse(e as String)), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfBigIntToBigIntToJson( - SimpleClassNullableOfBigIntToBigInt instance) => - <String, dynamic>{ - 'value': - instance.value?.map((k, e) => MapEntry(k.toString(), e.toString())), - }; + SimpleClassNullableOfBigIntToBigInt instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e.toString())), +}; SimpleClassOfDateTimeToBigInt _$SimpleClassOfDateTimeToBigIntFromJson( - Map<String, dynamic> json) => - SimpleClassOfDateTimeToBigInt( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(DateTime.parse(k), BigInt.parse(e as String)), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfDateTimeToBigInt( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(DateTime.parse(k), BigInt.parse(e as String)), + ), +); Map<String, dynamic> _$SimpleClassOfDateTimeToBigIntToJson( - SimpleClassOfDateTimeToBigInt instance) => - <String, dynamic>{ - 'value': instance.value - .map((k, e) => MapEntry(k.toIso8601String(), e.toString())), - }; + SimpleClassOfDateTimeToBigInt instance, +) => <String, dynamic>{ + 'value': instance.value.map( + (k, e) => MapEntry(k.toIso8601String(), e.toString()), + ), +}; SimpleClassNullableOfDateTimeToBigInt - _$SimpleClassNullableOfDateTimeToBigIntFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDateTimeToBigInt( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(DateTime.parse(k), BigInt.parse(e as String)), - ), - ); +_$SimpleClassNullableOfDateTimeToBigIntFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfDateTimeToBigInt( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(DateTime.parse(k), BigInt.parse(e as String)), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfDateTimeToBigIntToJson( - SimpleClassNullableOfDateTimeToBigInt instance) => - <String, dynamic>{ - 'value': instance.value - ?.map((k, e) => MapEntry(k.toIso8601String(), e.toString())), - }; + SimpleClassNullableOfDateTimeToBigInt instance, +) => <String, dynamic>{ + 'value': instance.value?.map( + (k, e) => MapEntry(k.toIso8601String(), e.toString()), + ), +}; SimpleClassOfDynamicToBigInt _$SimpleClassOfDynamicToBigIntFromJson( - Map<String, dynamic> json) => - SimpleClassOfDynamicToBigInt( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(k, BigInt.parse(e as String)), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfDynamicToBigInt( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(k, BigInt.parse(e as String)), + ), +); Map<String, dynamic> _$SimpleClassOfDynamicToBigIntToJson( - SimpleClassOfDynamicToBigInt instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k, e.toString())), - }; + SimpleClassOfDynamicToBigInt instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k, e.toString())), +}; SimpleClassNullableOfDynamicToBigInt - _$SimpleClassNullableOfDynamicToBigIntFromJson(Map<String, dynamic> json) => - SimpleClassNullableOfDynamicToBigInt( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, BigInt.parse(e as String)), - ), - ); +_$SimpleClassNullableOfDynamicToBigIntFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfDynamicToBigInt( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, BigInt.parse(e as String)), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfDynamicToBigIntToJson( - SimpleClassNullableOfDynamicToBigInt instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k, e.toString())), - }; + SimpleClassNullableOfDynamicToBigInt instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k, e.toString())), +}; SimpleClassOfEnumTypeToBigInt _$SimpleClassOfEnumTypeToBigIntFromJson( - Map<String, dynamic> json) => - SimpleClassOfEnumTypeToBigInt( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry( - $enumDecode(_$EnumTypeEnumMap, k), BigInt.parse(e as String)), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfEnumTypeToBigInt( + (json['value'] as Map<String, dynamic>).map( + (k, e) => + MapEntry($enumDecode(_$EnumTypeEnumMap, k), BigInt.parse(e as String)), + ), +); Map<String, dynamic> _$SimpleClassOfEnumTypeToBigIntToJson( - SimpleClassOfEnumTypeToBigInt instance) => - <String, dynamic>{ - 'value': instance.value - .map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e.toString())), - }; + SimpleClassOfEnumTypeToBigInt instance, +) => <String, dynamic>{ + 'value': instance.value.map( + (k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e.toString()), + ), +}; const _$EnumTypeEnumMap = { EnumType.alpha: 'alpha', @@ -145,6536 +145,6368 @@ const _$EnumTypeEnumMap = { }; SimpleClassNullableOfEnumTypeToBigInt - _$SimpleClassNullableOfEnumTypeToBigIntFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfEnumTypeToBigInt( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry( - $enumDecode(_$EnumTypeEnumMap, k), BigInt.parse(e as String)), - ), - ); +_$SimpleClassNullableOfEnumTypeToBigIntFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfEnumTypeToBigInt( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry( + $enumDecode(_$EnumTypeEnumMap, k), + BigInt.parse(e as String), + ), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfEnumTypeToBigIntToJson( - SimpleClassNullableOfEnumTypeToBigInt instance) => - <String, dynamic>{ - 'value': instance.value - ?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e.toString())), - }; + SimpleClassNullableOfEnumTypeToBigInt instance, +) => <String, dynamic>{ + 'value': instance.value?.map( + (k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e.toString()), + ), +}; SimpleClassOfIntToBigInt _$SimpleClassOfIntToBigIntFromJson( - Map<String, dynamic> json) => - SimpleClassOfIntToBigInt( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(int.parse(k), BigInt.parse(e as String)), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfIntToBigInt( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(int.parse(k), BigInt.parse(e as String)), + ), +); Map<String, dynamic> _$SimpleClassOfIntToBigIntToJson( - SimpleClassOfIntToBigInt instance) => - <String, dynamic>{ - 'value': - instance.value.map((k, e) => MapEntry(k.toString(), e.toString())), - }; + SimpleClassOfIntToBigInt instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e.toString())), +}; SimpleClassNullableOfIntToBigInt _$SimpleClassNullableOfIntToBigIntFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfIntToBigInt( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(int.parse(k), BigInt.parse(e as String)), - ), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfIntToBigInt( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(int.parse(k), BigInt.parse(e as String)), + ), +); Map<String, dynamic> _$SimpleClassNullableOfIntToBigIntToJson( - SimpleClassNullableOfIntToBigInt instance) => - <String, dynamic>{ - 'value': - instance.value?.map((k, e) => MapEntry(k.toString(), e.toString())), - }; + SimpleClassNullableOfIntToBigInt instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e.toString())), +}; SimpleClassOfObjectToBigInt _$SimpleClassOfObjectToBigIntFromJson( - Map<String, dynamic> json) => - SimpleClassOfObjectToBigInt( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(k, BigInt.parse(e as String)), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfObjectToBigInt( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(k, BigInt.parse(e as String)), + ), +); Map<String, dynamic> _$SimpleClassOfObjectToBigIntToJson( - SimpleClassOfObjectToBigInt instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k, e.toString())), - }; + SimpleClassOfObjectToBigInt instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k, e.toString())), +}; SimpleClassNullableOfObjectToBigInt - _$SimpleClassNullableOfObjectToBigIntFromJson(Map<String, dynamic> json) => - SimpleClassNullableOfObjectToBigInt( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, BigInt.parse(e as String)), - ), - ); +_$SimpleClassNullableOfObjectToBigIntFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfObjectToBigInt( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, BigInt.parse(e as String)), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfObjectToBigIntToJson( - SimpleClassNullableOfObjectToBigInt instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k, e.toString())), - }; + SimpleClassNullableOfObjectToBigInt instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k, e.toString())), +}; SimpleClassOfStringToBigInt _$SimpleClassOfStringToBigIntFromJson( - Map<String, dynamic> json) => - SimpleClassOfStringToBigInt( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(k, BigInt.parse(e as String)), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfStringToBigInt( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(k, BigInt.parse(e as String)), + ), +); Map<String, dynamic> _$SimpleClassOfStringToBigIntToJson( - SimpleClassOfStringToBigInt instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k, e.toString())), - }; + SimpleClassOfStringToBigInt instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k, e.toString())), +}; SimpleClassNullableOfStringToBigInt - _$SimpleClassNullableOfStringToBigIntFromJson(Map<String, dynamic> json) => - SimpleClassNullableOfStringToBigInt( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, BigInt.parse(e as String)), - ), - ); +_$SimpleClassNullableOfStringToBigIntFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfStringToBigInt( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, BigInt.parse(e as String)), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfStringToBigIntToJson( - SimpleClassNullableOfStringToBigInt instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k, e.toString())), - }; + SimpleClassNullableOfStringToBigInt instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k, e.toString())), +}; SimpleClassOfUriToBigInt _$SimpleClassOfUriToBigIntFromJson( - Map<String, dynamic> json) => - SimpleClassOfUriToBigInt( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(Uri.parse(k), BigInt.parse(e as String)), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfUriToBigInt( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(Uri.parse(k), BigInt.parse(e as String)), + ), +); Map<String, dynamic> _$SimpleClassOfUriToBigIntToJson( - SimpleClassOfUriToBigInt instance) => - <String, dynamic>{ - 'value': - instance.value.map((k, e) => MapEntry(k.toString(), e.toString())), - }; + SimpleClassOfUriToBigInt instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e.toString())), +}; SimpleClassNullableOfUriToBigInt _$SimpleClassNullableOfUriToBigIntFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfUriToBigInt( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(Uri.parse(k), BigInt.parse(e as String)), - ), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfUriToBigInt( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(Uri.parse(k), BigInt.parse(e as String)), + ), +); Map<String, dynamic> _$SimpleClassNullableOfUriToBigIntToJson( - SimpleClassNullableOfUriToBigInt instance) => - <String, dynamic>{ - 'value': - instance.value?.map((k, e) => MapEntry(k.toString(), e.toString())), - }; + SimpleClassNullableOfUriToBigInt instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e.toString())), +}; SimpleClassOfBigIntToBigIntNullable - _$SimpleClassOfBigIntToBigIntNullableFromJson(Map<String, dynamic> json) => - SimpleClassOfBigIntToBigIntNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry( - BigInt.parse(k), e == null ? null : BigInt.parse(e as String)), - ), - ); +_$SimpleClassOfBigIntToBigIntNullableFromJson(Map<String, dynamic> json) => + SimpleClassOfBigIntToBigIntNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry( + BigInt.parse(k), + e == null ? null : BigInt.parse(e as String), + ), + ), + ); Map<String, dynamic> _$SimpleClassOfBigIntToBigIntNullableToJson( - SimpleClassOfBigIntToBigIntNullable instance) => - <String, dynamic>{ - 'value': - instance.value.map((k, e) => MapEntry(k.toString(), e?.toString())), - }; + SimpleClassOfBigIntToBigIntNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e?.toString())), +}; SimpleClassNullableOfBigIntToBigIntNullable - _$SimpleClassNullableOfBigIntToBigIntNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfBigIntToBigIntNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry( - BigInt.parse(k), e == null ? null : BigInt.parse(e as String)), - ), - ); +_$SimpleClassNullableOfBigIntToBigIntNullableFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfBigIntToBigIntNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => + MapEntry(BigInt.parse(k), e == null ? null : BigInt.parse(e as String)), + ), +); Map<String, dynamic> _$SimpleClassNullableOfBigIntToBigIntNullableToJson( - SimpleClassNullableOfBigIntToBigIntNullable instance) => - <String, dynamic>{ - 'value': - instance.value?.map((k, e) => MapEntry(k.toString(), e?.toString())), - }; + SimpleClassNullableOfBigIntToBigIntNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e?.toString())), +}; SimpleClassOfDateTimeToBigIntNullable - _$SimpleClassOfDateTimeToBigIntNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfDateTimeToBigIntNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(DateTime.parse(k), - e == null ? null : BigInt.parse(e as String)), - ), - ); +_$SimpleClassOfDateTimeToBigIntNullableFromJson(Map<String, dynamic> json) => + SimpleClassOfDateTimeToBigIntNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry( + DateTime.parse(k), + e == null ? null : BigInt.parse(e as String), + ), + ), + ); Map<String, dynamic> _$SimpleClassOfDateTimeToBigIntNullableToJson( - SimpleClassOfDateTimeToBigIntNullable instance) => - <String, dynamic>{ - 'value': instance.value - .map((k, e) => MapEntry(k.toIso8601String(), e?.toString())), - }; + SimpleClassOfDateTimeToBigIntNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map( + (k, e) => MapEntry(k.toIso8601String(), e?.toString()), + ), +}; SimpleClassNullableOfDateTimeToBigIntNullable - _$SimpleClassNullableOfDateTimeToBigIntNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDateTimeToBigIntNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(DateTime.parse(k), - e == null ? null : BigInt.parse(e as String)), - ), - ); +_$SimpleClassNullableOfDateTimeToBigIntNullableFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfDateTimeToBigIntNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry( + DateTime.parse(k), + e == null ? null : BigInt.parse(e as String), + ), + ), +); Map<String, dynamic> _$SimpleClassNullableOfDateTimeToBigIntNullableToJson( - SimpleClassNullableOfDateTimeToBigIntNullable instance) => - <String, dynamic>{ - 'value': instance.value - ?.map((k, e) => MapEntry(k.toIso8601String(), e?.toString())), - }; + SimpleClassNullableOfDateTimeToBigIntNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map( + (k, e) => MapEntry(k.toIso8601String(), e?.toString()), + ), +}; SimpleClassOfDynamicToBigIntNullable - _$SimpleClassOfDynamicToBigIntNullableFromJson(Map<String, dynamic> json) => - SimpleClassOfDynamicToBigIntNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(k, e == null ? null : BigInt.parse(e as String)), - ), - ); +_$SimpleClassOfDynamicToBigIntNullableFromJson(Map<String, dynamic> json) => + SimpleClassOfDynamicToBigIntNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(k, e == null ? null : BigInt.parse(e as String)), + ), + ); Map<String, dynamic> _$SimpleClassOfDynamicToBigIntNullableToJson( - SimpleClassOfDynamicToBigIntNullable instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k, e?.toString())), - }; + SimpleClassOfDynamicToBigIntNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k, e?.toString())), +}; SimpleClassNullableOfDynamicToBigIntNullable - _$SimpleClassNullableOfDynamicToBigIntNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDynamicToBigIntNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, e == null ? null : BigInt.parse(e as String)), - ), - ); +_$SimpleClassNullableOfDynamicToBigIntNullableFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfDynamicToBigIntNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, e == null ? null : BigInt.parse(e as String)), + ), +); Map<String, dynamic> _$SimpleClassNullableOfDynamicToBigIntNullableToJson( - SimpleClassNullableOfDynamicToBigIntNullable instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k, e?.toString())), - }; + SimpleClassNullableOfDynamicToBigIntNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k, e?.toString())), +}; SimpleClassOfEnumTypeToBigIntNullable - _$SimpleClassOfEnumTypeToBigIntNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfEnumTypeToBigIntNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), - e == null ? null : BigInt.parse(e as String)), - ), - ); +_$SimpleClassOfEnumTypeToBigIntNullableFromJson(Map<String, dynamic> json) => + SimpleClassOfEnumTypeToBigIntNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry( + $enumDecode(_$EnumTypeEnumMap, k), + e == null ? null : BigInt.parse(e as String), + ), + ), + ); Map<String, dynamic> _$SimpleClassOfEnumTypeToBigIntNullableToJson( - SimpleClassOfEnumTypeToBigIntNullable instance) => - <String, dynamic>{ - 'value': instance.value - .map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e?.toString())), - }; + SimpleClassOfEnumTypeToBigIntNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map( + (k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e?.toString()), + ), +}; SimpleClassNullableOfEnumTypeToBigIntNullable - _$SimpleClassNullableOfEnumTypeToBigIntNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfEnumTypeToBigIntNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), - e == null ? null : BigInt.parse(e as String)), - ), - ); +_$SimpleClassNullableOfEnumTypeToBigIntNullableFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfEnumTypeToBigIntNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry( + $enumDecode(_$EnumTypeEnumMap, k), + e == null ? null : BigInt.parse(e as String), + ), + ), +); Map<String, dynamic> _$SimpleClassNullableOfEnumTypeToBigIntNullableToJson( - SimpleClassNullableOfEnumTypeToBigIntNullable instance) => - <String, dynamic>{ - 'value': instance.value - ?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e?.toString())), - }; + SimpleClassNullableOfEnumTypeToBigIntNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map( + (k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e?.toString()), + ), +}; SimpleClassOfIntToBigIntNullable _$SimpleClassOfIntToBigIntNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfIntToBigIntNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry( - int.parse(k), e == null ? null : BigInt.parse(e as String)), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfIntToBigIntNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => + MapEntry(int.parse(k), e == null ? null : BigInt.parse(e as String)), + ), +); Map<String, dynamic> _$SimpleClassOfIntToBigIntNullableToJson( - SimpleClassOfIntToBigIntNullable instance) => - <String, dynamic>{ - 'value': - instance.value.map((k, e) => MapEntry(k.toString(), e?.toString())), - }; + SimpleClassOfIntToBigIntNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e?.toString())), +}; SimpleClassNullableOfIntToBigIntNullable - _$SimpleClassNullableOfIntToBigIntNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfIntToBigIntNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry( - int.parse(k), e == null ? null : BigInt.parse(e as String)), - ), - ); +_$SimpleClassNullableOfIntToBigIntNullableFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfIntToBigIntNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry( + int.parse(k), + e == null ? null : BigInt.parse(e as String), + ), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfIntToBigIntNullableToJson( - SimpleClassNullableOfIntToBigIntNullable instance) => - <String, dynamic>{ - 'value': - instance.value?.map((k, e) => MapEntry(k.toString(), e?.toString())), - }; + SimpleClassNullableOfIntToBigIntNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e?.toString())), +}; SimpleClassOfObjectToBigIntNullable - _$SimpleClassOfObjectToBigIntNullableFromJson(Map<String, dynamic> json) => - SimpleClassOfObjectToBigIntNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(k, e == null ? null : BigInt.parse(e as String)), - ), - ); +_$SimpleClassOfObjectToBigIntNullableFromJson(Map<String, dynamic> json) => + SimpleClassOfObjectToBigIntNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(k, e == null ? null : BigInt.parse(e as String)), + ), + ); Map<String, dynamic> _$SimpleClassOfObjectToBigIntNullableToJson( - SimpleClassOfObjectToBigIntNullable instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k, e?.toString())), - }; + SimpleClassOfObjectToBigIntNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k, e?.toString())), +}; SimpleClassNullableOfObjectToBigIntNullable - _$SimpleClassNullableOfObjectToBigIntNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfObjectToBigIntNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, e == null ? null : BigInt.parse(e as String)), - ), - ); +_$SimpleClassNullableOfObjectToBigIntNullableFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfObjectToBigIntNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, e == null ? null : BigInt.parse(e as String)), + ), +); Map<String, dynamic> _$SimpleClassNullableOfObjectToBigIntNullableToJson( - SimpleClassNullableOfObjectToBigIntNullable instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k, e?.toString())), - }; + SimpleClassNullableOfObjectToBigIntNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k, e?.toString())), +}; SimpleClassOfStringToBigIntNullable - _$SimpleClassOfStringToBigIntNullableFromJson(Map<String, dynamic> json) => - SimpleClassOfStringToBigIntNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(k, e == null ? null : BigInt.parse(e as String)), - ), - ); +_$SimpleClassOfStringToBigIntNullableFromJson(Map<String, dynamic> json) => + SimpleClassOfStringToBigIntNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(k, e == null ? null : BigInt.parse(e as String)), + ), + ); Map<String, dynamic> _$SimpleClassOfStringToBigIntNullableToJson( - SimpleClassOfStringToBigIntNullable instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k, e?.toString())), - }; + SimpleClassOfStringToBigIntNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k, e?.toString())), +}; SimpleClassNullableOfStringToBigIntNullable - _$SimpleClassNullableOfStringToBigIntNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfStringToBigIntNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, e == null ? null : BigInt.parse(e as String)), - ), - ); +_$SimpleClassNullableOfStringToBigIntNullableFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfStringToBigIntNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, e == null ? null : BigInt.parse(e as String)), + ), +); Map<String, dynamic> _$SimpleClassNullableOfStringToBigIntNullableToJson( - SimpleClassNullableOfStringToBigIntNullable instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k, e?.toString())), - }; + SimpleClassNullableOfStringToBigIntNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k, e?.toString())), +}; SimpleClassOfUriToBigIntNullable _$SimpleClassOfUriToBigIntNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfUriToBigIntNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry( - Uri.parse(k), e == null ? null : BigInt.parse(e as String)), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfUriToBigIntNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => + MapEntry(Uri.parse(k), e == null ? null : BigInt.parse(e as String)), + ), +); Map<String, dynamic> _$SimpleClassOfUriToBigIntNullableToJson( - SimpleClassOfUriToBigIntNullable instance) => - <String, dynamic>{ - 'value': - instance.value.map((k, e) => MapEntry(k.toString(), e?.toString())), - }; + SimpleClassOfUriToBigIntNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e?.toString())), +}; SimpleClassNullableOfUriToBigIntNullable - _$SimpleClassNullableOfUriToBigIntNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfUriToBigIntNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry( - Uri.parse(k), e == null ? null : BigInt.parse(e as String)), - ), - ); +_$SimpleClassNullableOfUriToBigIntNullableFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfUriToBigIntNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry( + Uri.parse(k), + e == null ? null : BigInt.parse(e as String), + ), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfUriToBigIntNullableToJson( - SimpleClassNullableOfUriToBigIntNullable instance) => - <String, dynamic>{ - 'value': - instance.value?.map((k, e) => MapEntry(k.toString(), e?.toString())), - }; + SimpleClassNullableOfUriToBigIntNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e?.toString())), +}; SimpleClassOfBigIntToBool _$SimpleClassOfBigIntToBoolFromJson( - Map<String, dynamic> json) => - SimpleClassOfBigIntToBool( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(BigInt.parse(k), e as bool), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfBigIntToBool( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(BigInt.parse(k), e as bool), + ), +); Map<String, dynamic> _$SimpleClassOfBigIntToBoolToJson( - SimpleClassOfBigIntToBool instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassOfBigIntToBool instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassNullableOfBigIntToBool _$SimpleClassNullableOfBigIntToBoolFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfBigIntToBool( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(BigInt.parse(k), e as bool), - ), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfBigIntToBool( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(BigInt.parse(k), e as bool), + ), +); Map<String, dynamic> _$SimpleClassNullableOfBigIntToBoolToJson( - SimpleClassNullableOfBigIntToBool instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassNullableOfBigIntToBool instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassOfDateTimeToBool _$SimpleClassOfDateTimeToBoolFromJson( - Map<String, dynamic> json) => - SimpleClassOfDateTimeToBool( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(DateTime.parse(k), e as bool), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfDateTimeToBool( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(DateTime.parse(k), e as bool), + ), +); Map<String, dynamic> _$SimpleClassOfDateTimeToBoolToJson( - SimpleClassOfDateTimeToBool instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toIso8601String(), e)), - }; + SimpleClassOfDateTimeToBool instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toIso8601String(), e)), +}; SimpleClassNullableOfDateTimeToBool - _$SimpleClassNullableOfDateTimeToBoolFromJson(Map<String, dynamic> json) => - SimpleClassNullableOfDateTimeToBool( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(DateTime.parse(k), e as bool), - ), - ); +_$SimpleClassNullableOfDateTimeToBoolFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfDateTimeToBool( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(DateTime.parse(k), e as bool), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfDateTimeToBoolToJson( - SimpleClassNullableOfDateTimeToBool instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toIso8601String(), e)), - }; + SimpleClassNullableOfDateTimeToBool instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toIso8601String(), e)), +}; SimpleClassOfDynamicToBool _$SimpleClassOfDynamicToBoolFromJson( - Map<String, dynamic> json) => - SimpleClassOfDynamicToBool( - Map<String, bool>.from(json['value'] as Map), - ); + Map<String, dynamic> json, +) => SimpleClassOfDynamicToBool(Map<String, bool>.from(json['value'] as Map)); Map<String, dynamic> _$SimpleClassOfDynamicToBoolToJson( - SimpleClassOfDynamicToBool instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassOfDynamicToBool instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassNullableOfDynamicToBool _$SimpleClassNullableOfDynamicToBoolFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDynamicToBool( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, e as bool), - ), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfDynamicToBool( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, e as bool), + ), +); Map<String, dynamic> _$SimpleClassNullableOfDynamicToBoolToJson( - SimpleClassNullableOfDynamicToBool instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassNullableOfDynamicToBool instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassOfEnumTypeToBool _$SimpleClassOfEnumTypeToBoolFromJson( - Map<String, dynamic> json) => - SimpleClassOfEnumTypeToBool( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e as bool), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfEnumTypeToBool( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e as bool), + ), +); Map<String, dynamic> _$SimpleClassOfEnumTypeToBoolToJson( - SimpleClassOfEnumTypeToBool instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), - }; + SimpleClassOfEnumTypeToBool instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), +}; SimpleClassNullableOfEnumTypeToBool - _$SimpleClassNullableOfEnumTypeToBoolFromJson(Map<String, dynamic> json) => - SimpleClassNullableOfEnumTypeToBool( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e as bool), - ), - ); +_$SimpleClassNullableOfEnumTypeToBoolFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfEnumTypeToBool( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e as bool), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfEnumTypeToBoolToJson( - SimpleClassNullableOfEnumTypeToBool instance) => - <String, dynamic>{ - 'value': - instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), - }; + SimpleClassNullableOfEnumTypeToBool instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), +}; SimpleClassOfIntToBool _$SimpleClassOfIntToBoolFromJson( - Map<String, dynamic> json) => - SimpleClassOfIntToBool( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(int.parse(k), e as bool), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfIntToBool( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(int.parse(k), e as bool), + ), +); Map<String, dynamic> _$SimpleClassOfIntToBoolToJson( - SimpleClassOfIntToBool instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassOfIntToBool instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassNullableOfIntToBool _$SimpleClassNullableOfIntToBoolFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfIntToBool( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(int.parse(k), e as bool), - ), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfIntToBool( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(int.parse(k), e as bool), + ), +); Map<String, dynamic> _$SimpleClassNullableOfIntToBoolToJson( - SimpleClassNullableOfIntToBool instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassNullableOfIntToBool instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassOfObjectToBool _$SimpleClassOfObjectToBoolFromJson( - Map<String, dynamic> json) => - SimpleClassOfObjectToBool( - Map<String, bool>.from(json['value'] as Map), - ); + Map<String, dynamic> json, +) => SimpleClassOfObjectToBool(Map<String, bool>.from(json['value'] as Map)); Map<String, dynamic> _$SimpleClassOfObjectToBoolToJson( - SimpleClassOfObjectToBool instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassOfObjectToBool instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassNullableOfObjectToBool _$SimpleClassNullableOfObjectToBoolFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfObjectToBool( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, e as bool), - ), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfObjectToBool( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, e as bool), + ), +); Map<String, dynamic> _$SimpleClassNullableOfObjectToBoolToJson( - SimpleClassNullableOfObjectToBool instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassNullableOfObjectToBool instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassOfStringToBool _$SimpleClassOfStringToBoolFromJson( - Map<String, dynamic> json) => - SimpleClassOfStringToBool( - Map<String, bool>.from(json['value'] as Map), - ); + Map<String, dynamic> json, +) => SimpleClassOfStringToBool(Map<String, bool>.from(json['value'] as Map)); Map<String, dynamic> _$SimpleClassOfStringToBoolToJson( - SimpleClassOfStringToBool instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassOfStringToBool instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassNullableOfStringToBool _$SimpleClassNullableOfStringToBoolFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfStringToBool( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, e as bool), - ), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfStringToBool( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, e as bool), + ), +); Map<String, dynamic> _$SimpleClassNullableOfStringToBoolToJson( - SimpleClassNullableOfStringToBool instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassNullableOfStringToBool instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassOfUriToBool _$SimpleClassOfUriToBoolFromJson( - Map<String, dynamic> json) => - SimpleClassOfUriToBool( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(Uri.parse(k), e as bool), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfUriToBool( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(Uri.parse(k), e as bool), + ), +); Map<String, dynamic> _$SimpleClassOfUriToBoolToJson( - SimpleClassOfUriToBool instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassOfUriToBool instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassNullableOfUriToBool _$SimpleClassNullableOfUriToBoolFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfUriToBool( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(Uri.parse(k), e as bool), - ), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfUriToBool( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(Uri.parse(k), e as bool), + ), +); Map<String, dynamic> _$SimpleClassNullableOfUriToBoolToJson( - SimpleClassNullableOfUriToBool instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassNullableOfUriToBool instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassOfBigIntToBoolNullable _$SimpleClassOfBigIntToBoolNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfBigIntToBoolNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(BigInt.parse(k), e as bool?), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfBigIntToBoolNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(BigInt.parse(k), e as bool?), + ), +); Map<String, dynamic> _$SimpleClassOfBigIntToBoolNullableToJson( - SimpleClassOfBigIntToBoolNullable instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassOfBigIntToBoolNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassNullableOfBigIntToBoolNullable - _$SimpleClassNullableOfBigIntToBoolNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfBigIntToBoolNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(BigInt.parse(k), e as bool?), - ), - ); +_$SimpleClassNullableOfBigIntToBoolNullableFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfBigIntToBoolNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(BigInt.parse(k), e as bool?), + ), +); Map<String, dynamic> _$SimpleClassNullableOfBigIntToBoolNullableToJson( - SimpleClassNullableOfBigIntToBoolNullable instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassNullableOfBigIntToBoolNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassOfDateTimeToBoolNullable - _$SimpleClassOfDateTimeToBoolNullableFromJson(Map<String, dynamic> json) => - SimpleClassOfDateTimeToBoolNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(DateTime.parse(k), e as bool?), - ), - ); +_$SimpleClassOfDateTimeToBoolNullableFromJson(Map<String, dynamic> json) => + SimpleClassOfDateTimeToBoolNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(DateTime.parse(k), e as bool?), + ), + ); Map<String, dynamic> _$SimpleClassOfDateTimeToBoolNullableToJson( - SimpleClassOfDateTimeToBoolNullable instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toIso8601String(), e)), - }; + SimpleClassOfDateTimeToBoolNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toIso8601String(), e)), +}; SimpleClassNullableOfDateTimeToBoolNullable - _$SimpleClassNullableOfDateTimeToBoolNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDateTimeToBoolNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(DateTime.parse(k), e as bool?), - ), - ); +_$SimpleClassNullableOfDateTimeToBoolNullableFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfDateTimeToBoolNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(DateTime.parse(k), e as bool?), + ), +); Map<String, dynamic> _$SimpleClassNullableOfDateTimeToBoolNullableToJson( - SimpleClassNullableOfDateTimeToBoolNullable instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toIso8601String(), e)), - }; + SimpleClassNullableOfDateTimeToBoolNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toIso8601String(), e)), +}; SimpleClassOfDynamicToBoolNullable _$SimpleClassOfDynamicToBoolNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfDynamicToBoolNullable( - Map<String, bool?>.from(json['value'] as Map), - ); + Map<String, dynamic> json, +) => SimpleClassOfDynamicToBoolNullable( + Map<String, bool?>.from(json['value'] as Map), +); Map<String, dynamic> _$SimpleClassOfDynamicToBoolNullableToJson( - SimpleClassOfDynamicToBoolNullable instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassOfDynamicToBoolNullable instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassNullableOfDynamicToBoolNullable - _$SimpleClassNullableOfDynamicToBoolNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDynamicToBoolNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, e as bool?), - ), - ); +_$SimpleClassNullableOfDynamicToBoolNullableFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfDynamicToBoolNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, e as bool?), + ), +); Map<String, dynamic> _$SimpleClassNullableOfDynamicToBoolNullableToJson( - SimpleClassNullableOfDynamicToBoolNullable instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassNullableOfDynamicToBoolNullable instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassOfEnumTypeToBoolNullable - _$SimpleClassOfEnumTypeToBoolNullableFromJson(Map<String, dynamic> json) => - SimpleClassOfEnumTypeToBoolNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e as bool?), - ), - ); +_$SimpleClassOfEnumTypeToBoolNullableFromJson(Map<String, dynamic> json) => + SimpleClassOfEnumTypeToBoolNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e as bool?), + ), + ); Map<String, dynamic> _$SimpleClassOfEnumTypeToBoolNullableToJson( - SimpleClassOfEnumTypeToBoolNullable instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), - }; + SimpleClassOfEnumTypeToBoolNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), +}; SimpleClassNullableOfEnumTypeToBoolNullable - _$SimpleClassNullableOfEnumTypeToBoolNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfEnumTypeToBoolNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e as bool?), - ), - ); +_$SimpleClassNullableOfEnumTypeToBoolNullableFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfEnumTypeToBoolNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e as bool?), + ), +); Map<String, dynamic> _$SimpleClassNullableOfEnumTypeToBoolNullableToJson( - SimpleClassNullableOfEnumTypeToBoolNullable instance) => - <String, dynamic>{ - 'value': - instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), - }; + SimpleClassNullableOfEnumTypeToBoolNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), +}; SimpleClassOfIntToBoolNullable _$SimpleClassOfIntToBoolNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfIntToBoolNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(int.parse(k), e as bool?), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfIntToBoolNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(int.parse(k), e as bool?), + ), +); Map<String, dynamic> _$SimpleClassOfIntToBoolNullableToJson( - SimpleClassOfIntToBoolNullable instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassOfIntToBoolNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassNullableOfIntToBoolNullable - _$SimpleClassNullableOfIntToBoolNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfIntToBoolNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(int.parse(k), e as bool?), - ), - ); +_$SimpleClassNullableOfIntToBoolNullableFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfIntToBoolNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(int.parse(k), e as bool?), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfIntToBoolNullableToJson( - SimpleClassNullableOfIntToBoolNullable instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassNullableOfIntToBoolNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassOfObjectToBoolNullable _$SimpleClassOfObjectToBoolNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfObjectToBoolNullable( - Map<String, bool?>.from(json['value'] as Map), - ); + Map<String, dynamic> json, +) => SimpleClassOfObjectToBoolNullable( + Map<String, bool?>.from(json['value'] as Map), +); Map<String, dynamic> _$SimpleClassOfObjectToBoolNullableToJson( - SimpleClassOfObjectToBoolNullable instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassOfObjectToBoolNullable instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassNullableOfObjectToBoolNullable - _$SimpleClassNullableOfObjectToBoolNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfObjectToBoolNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, e as bool?), - ), - ); +_$SimpleClassNullableOfObjectToBoolNullableFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfObjectToBoolNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, e as bool?), + ), +); Map<String, dynamic> _$SimpleClassNullableOfObjectToBoolNullableToJson( - SimpleClassNullableOfObjectToBoolNullable instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassNullableOfObjectToBoolNullable instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassOfStringToBoolNullable _$SimpleClassOfStringToBoolNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfStringToBoolNullable( - Map<String, bool?>.from(json['value'] as Map), - ); + Map<String, dynamic> json, +) => SimpleClassOfStringToBoolNullable( + Map<String, bool?>.from(json['value'] as Map), +); Map<String, dynamic> _$SimpleClassOfStringToBoolNullableToJson( - SimpleClassOfStringToBoolNullable instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassOfStringToBoolNullable instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassNullableOfStringToBoolNullable - _$SimpleClassNullableOfStringToBoolNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfStringToBoolNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, e as bool?), - ), - ); +_$SimpleClassNullableOfStringToBoolNullableFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfStringToBoolNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, e as bool?), + ), +); Map<String, dynamic> _$SimpleClassNullableOfStringToBoolNullableToJson( - SimpleClassNullableOfStringToBoolNullable instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassNullableOfStringToBoolNullable instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassOfUriToBoolNullable _$SimpleClassOfUriToBoolNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfUriToBoolNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(Uri.parse(k), e as bool?), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfUriToBoolNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(Uri.parse(k), e as bool?), + ), +); Map<String, dynamic> _$SimpleClassOfUriToBoolNullableToJson( - SimpleClassOfUriToBoolNullable instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassOfUriToBoolNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassNullableOfUriToBoolNullable - _$SimpleClassNullableOfUriToBoolNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfUriToBoolNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(Uri.parse(k), e as bool?), - ), - ); +_$SimpleClassNullableOfUriToBoolNullableFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfUriToBoolNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(Uri.parse(k), e as bool?), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfUriToBoolNullableToJson( - SimpleClassNullableOfUriToBoolNullable instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassNullableOfUriToBoolNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassOfBigIntToDateTime _$SimpleClassOfBigIntToDateTimeFromJson( - Map<String, dynamic> json) => - SimpleClassOfBigIntToDateTime( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(BigInt.parse(k), DateTime.parse(e as String)), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfBigIntToDateTime( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(BigInt.parse(k), DateTime.parse(e as String)), + ), +); Map<String, dynamic> _$SimpleClassOfBigIntToDateTimeToJson( - SimpleClassOfBigIntToDateTime instance) => - <String, dynamic>{ - 'value': instance.value - .map((k, e) => MapEntry(k.toString(), e.toIso8601String())), - }; + SimpleClassOfBigIntToDateTime instance, +) => <String, dynamic>{ + 'value': instance.value.map( + (k, e) => MapEntry(k.toString(), e.toIso8601String()), + ), +}; SimpleClassNullableOfBigIntToDateTime - _$SimpleClassNullableOfBigIntToDateTimeFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfBigIntToDateTime( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(BigInt.parse(k), DateTime.parse(e as String)), - ), - ); +_$SimpleClassNullableOfBigIntToDateTimeFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfBigIntToDateTime( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(BigInt.parse(k), DateTime.parse(e as String)), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfBigIntToDateTimeToJson( - SimpleClassNullableOfBigIntToDateTime instance) => - <String, dynamic>{ - 'value': instance.value - ?.map((k, e) => MapEntry(k.toString(), e.toIso8601String())), - }; + SimpleClassNullableOfBigIntToDateTime instance, +) => <String, dynamic>{ + 'value': instance.value?.map( + (k, e) => MapEntry(k.toString(), e.toIso8601String()), + ), +}; SimpleClassOfDateTimeToDateTime _$SimpleClassOfDateTimeToDateTimeFromJson( - Map<String, dynamic> json) => - SimpleClassOfDateTimeToDateTime( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(DateTime.parse(k), DateTime.parse(e as String)), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfDateTimeToDateTime( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(DateTime.parse(k), DateTime.parse(e as String)), + ), +); Map<String, dynamic> _$SimpleClassOfDateTimeToDateTimeToJson( - SimpleClassOfDateTimeToDateTime instance) => - <String, dynamic>{ - 'value': instance.value - .map((k, e) => MapEntry(k.toIso8601String(), e.toIso8601String())), - }; + SimpleClassOfDateTimeToDateTime instance, +) => <String, dynamic>{ + 'value': instance.value.map( + (k, e) => MapEntry(k.toIso8601String(), e.toIso8601String()), + ), +}; SimpleClassNullableOfDateTimeToDateTime - _$SimpleClassNullableOfDateTimeToDateTimeFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDateTimeToDateTime( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(DateTime.parse(k), DateTime.parse(e as String)), - ), - ); +_$SimpleClassNullableOfDateTimeToDateTimeFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfDateTimeToDateTime( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(DateTime.parse(k), DateTime.parse(e as String)), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfDateTimeToDateTimeToJson( - SimpleClassNullableOfDateTimeToDateTime instance) => - <String, dynamic>{ - 'value': instance.value - ?.map((k, e) => MapEntry(k.toIso8601String(), e.toIso8601String())), - }; + SimpleClassNullableOfDateTimeToDateTime instance, +) => <String, dynamic>{ + 'value': instance.value?.map( + (k, e) => MapEntry(k.toIso8601String(), e.toIso8601String()), + ), +}; SimpleClassOfDynamicToDateTime _$SimpleClassOfDynamicToDateTimeFromJson( - Map<String, dynamic> json) => - SimpleClassOfDynamicToDateTime( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(k, DateTime.parse(e as String)), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfDynamicToDateTime( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(k, DateTime.parse(e as String)), + ), +); Map<String, dynamic> _$SimpleClassOfDynamicToDateTimeToJson( - SimpleClassOfDynamicToDateTime instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k, e.toIso8601String())), - }; + SimpleClassOfDynamicToDateTime instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k, e.toIso8601String())), +}; SimpleClassNullableOfDynamicToDateTime - _$SimpleClassNullableOfDynamicToDateTimeFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDynamicToDateTime( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, DateTime.parse(e as String)), - ), - ); +_$SimpleClassNullableOfDynamicToDateTimeFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfDynamicToDateTime( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, DateTime.parse(e as String)), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfDynamicToDateTimeToJson( - SimpleClassNullableOfDynamicToDateTime instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k, e.toIso8601String())), - }; + SimpleClassNullableOfDynamicToDateTime instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k, e.toIso8601String())), +}; SimpleClassOfEnumTypeToDateTime _$SimpleClassOfEnumTypeToDateTimeFromJson( - Map<String, dynamic> json) => - SimpleClassOfEnumTypeToDateTime( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry( - $enumDecode(_$EnumTypeEnumMap, k), DateTime.parse(e as String)), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfEnumTypeToDateTime( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry( + $enumDecode(_$EnumTypeEnumMap, k), + DateTime.parse(e as String), + ), + ), +); Map<String, dynamic> _$SimpleClassOfEnumTypeToDateTimeToJson( - SimpleClassOfEnumTypeToDateTime instance) => - <String, dynamic>{ - 'value': instance.value - .map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e.toIso8601String())), - }; + SimpleClassOfEnumTypeToDateTime instance, +) => <String, dynamic>{ + 'value': instance.value.map( + (k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e.toIso8601String()), + ), +}; SimpleClassNullableOfEnumTypeToDateTime - _$SimpleClassNullableOfEnumTypeToDateTimeFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfEnumTypeToDateTime( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry( - $enumDecode(_$EnumTypeEnumMap, k), DateTime.parse(e as String)), - ), - ); +_$SimpleClassNullableOfEnumTypeToDateTimeFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfEnumTypeToDateTime( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry( + $enumDecode(_$EnumTypeEnumMap, k), + DateTime.parse(e as String), + ), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfEnumTypeToDateTimeToJson( - SimpleClassNullableOfEnumTypeToDateTime instance) => - <String, dynamic>{ - 'value': instance.value - ?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e.toIso8601String())), - }; + SimpleClassNullableOfEnumTypeToDateTime instance, +) => <String, dynamic>{ + 'value': instance.value?.map( + (k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e.toIso8601String()), + ), +}; SimpleClassOfIntToDateTime _$SimpleClassOfIntToDateTimeFromJson( - Map<String, dynamic> json) => - SimpleClassOfIntToDateTime( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(int.parse(k), DateTime.parse(e as String)), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfIntToDateTime( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(int.parse(k), DateTime.parse(e as String)), + ), +); Map<String, dynamic> _$SimpleClassOfIntToDateTimeToJson( - SimpleClassOfIntToDateTime instance) => - <String, dynamic>{ - 'value': instance.value - .map((k, e) => MapEntry(k.toString(), e.toIso8601String())), - }; + SimpleClassOfIntToDateTime instance, +) => <String, dynamic>{ + 'value': instance.value.map( + (k, e) => MapEntry(k.toString(), e.toIso8601String()), + ), +}; SimpleClassNullableOfIntToDateTime _$SimpleClassNullableOfIntToDateTimeFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfIntToDateTime( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(int.parse(k), DateTime.parse(e as String)), - ), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfIntToDateTime( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(int.parse(k), DateTime.parse(e as String)), + ), +); Map<String, dynamic> _$SimpleClassNullableOfIntToDateTimeToJson( - SimpleClassNullableOfIntToDateTime instance) => - <String, dynamic>{ - 'value': instance.value - ?.map((k, e) => MapEntry(k.toString(), e.toIso8601String())), - }; + SimpleClassNullableOfIntToDateTime instance, +) => <String, dynamic>{ + 'value': instance.value?.map( + (k, e) => MapEntry(k.toString(), e.toIso8601String()), + ), +}; SimpleClassOfObjectToDateTime _$SimpleClassOfObjectToDateTimeFromJson( - Map<String, dynamic> json) => - SimpleClassOfObjectToDateTime( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(k, DateTime.parse(e as String)), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfObjectToDateTime( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(k, DateTime.parse(e as String)), + ), +); Map<String, dynamic> _$SimpleClassOfObjectToDateTimeToJson( - SimpleClassOfObjectToDateTime instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k, e.toIso8601String())), - }; + SimpleClassOfObjectToDateTime instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k, e.toIso8601String())), +}; SimpleClassNullableOfObjectToDateTime - _$SimpleClassNullableOfObjectToDateTimeFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfObjectToDateTime( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, DateTime.parse(e as String)), - ), - ); +_$SimpleClassNullableOfObjectToDateTimeFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfObjectToDateTime( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, DateTime.parse(e as String)), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfObjectToDateTimeToJson( - SimpleClassNullableOfObjectToDateTime instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k, e.toIso8601String())), - }; + SimpleClassNullableOfObjectToDateTime instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k, e.toIso8601String())), +}; SimpleClassOfStringToDateTime _$SimpleClassOfStringToDateTimeFromJson( - Map<String, dynamic> json) => - SimpleClassOfStringToDateTime( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(k, DateTime.parse(e as String)), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfStringToDateTime( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(k, DateTime.parse(e as String)), + ), +); Map<String, dynamic> _$SimpleClassOfStringToDateTimeToJson( - SimpleClassOfStringToDateTime instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k, e.toIso8601String())), - }; + SimpleClassOfStringToDateTime instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k, e.toIso8601String())), +}; SimpleClassNullableOfStringToDateTime - _$SimpleClassNullableOfStringToDateTimeFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfStringToDateTime( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, DateTime.parse(e as String)), - ), - ); +_$SimpleClassNullableOfStringToDateTimeFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfStringToDateTime( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, DateTime.parse(e as String)), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfStringToDateTimeToJson( - SimpleClassNullableOfStringToDateTime instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k, e.toIso8601String())), - }; + SimpleClassNullableOfStringToDateTime instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k, e.toIso8601String())), +}; SimpleClassOfUriToDateTime _$SimpleClassOfUriToDateTimeFromJson( - Map<String, dynamic> json) => - SimpleClassOfUriToDateTime( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(Uri.parse(k), DateTime.parse(e as String)), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfUriToDateTime( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(Uri.parse(k), DateTime.parse(e as String)), + ), +); Map<String, dynamic> _$SimpleClassOfUriToDateTimeToJson( - SimpleClassOfUriToDateTime instance) => - <String, dynamic>{ - 'value': instance.value - .map((k, e) => MapEntry(k.toString(), e.toIso8601String())), - }; + SimpleClassOfUriToDateTime instance, +) => <String, dynamic>{ + 'value': instance.value.map( + (k, e) => MapEntry(k.toString(), e.toIso8601String()), + ), +}; SimpleClassNullableOfUriToDateTime _$SimpleClassNullableOfUriToDateTimeFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfUriToDateTime( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(Uri.parse(k), DateTime.parse(e as String)), - ), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfUriToDateTime( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(Uri.parse(k), DateTime.parse(e as String)), + ), +); Map<String, dynamic> _$SimpleClassNullableOfUriToDateTimeToJson( - SimpleClassNullableOfUriToDateTime instance) => - <String, dynamic>{ - 'value': instance.value - ?.map((k, e) => MapEntry(k.toString(), e.toIso8601String())), - }; + SimpleClassNullableOfUriToDateTime instance, +) => <String, dynamic>{ + 'value': instance.value?.map( + (k, e) => MapEntry(k.toString(), e.toIso8601String()), + ), +}; SimpleClassOfBigIntToDateTimeNullable - _$SimpleClassOfBigIntToDateTimeNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfBigIntToDateTimeNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(BigInt.parse(k), - e == null ? null : DateTime.parse(e as String)), - ), - ); +_$SimpleClassOfBigIntToDateTimeNullableFromJson(Map<String, dynamic> json) => + SimpleClassOfBigIntToDateTimeNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry( + BigInt.parse(k), + e == null ? null : DateTime.parse(e as String), + ), + ), + ); Map<String, dynamic> _$SimpleClassOfBigIntToDateTimeNullableToJson( - SimpleClassOfBigIntToDateTimeNullable instance) => - <String, dynamic>{ - 'value': instance.value - .map((k, e) => MapEntry(k.toString(), e?.toIso8601String())), - }; + SimpleClassOfBigIntToDateTimeNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map( + (k, e) => MapEntry(k.toString(), e?.toIso8601String()), + ), +}; SimpleClassNullableOfBigIntToDateTimeNullable - _$SimpleClassNullableOfBigIntToDateTimeNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfBigIntToDateTimeNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(BigInt.parse(k), - e == null ? null : DateTime.parse(e as String)), - ), - ); +_$SimpleClassNullableOfBigIntToDateTimeNullableFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfBigIntToDateTimeNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry( + BigInt.parse(k), + e == null ? null : DateTime.parse(e as String), + ), + ), +); Map<String, dynamic> _$SimpleClassNullableOfBigIntToDateTimeNullableToJson( - SimpleClassNullableOfBigIntToDateTimeNullable instance) => - <String, dynamic>{ - 'value': instance.value - ?.map((k, e) => MapEntry(k.toString(), e?.toIso8601String())), - }; + SimpleClassNullableOfBigIntToDateTimeNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map( + (k, e) => MapEntry(k.toString(), e?.toIso8601String()), + ), +}; SimpleClassOfDateTimeToDateTimeNullable - _$SimpleClassOfDateTimeToDateTimeNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfDateTimeToDateTimeNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(DateTime.parse(k), - e == null ? null : DateTime.parse(e as String)), - ), - ); +_$SimpleClassOfDateTimeToDateTimeNullableFromJson(Map<String, dynamic> json) => + SimpleClassOfDateTimeToDateTimeNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry( + DateTime.parse(k), + e == null ? null : DateTime.parse(e as String), + ), + ), + ); Map<String, dynamic> _$SimpleClassOfDateTimeToDateTimeNullableToJson( - SimpleClassOfDateTimeToDateTimeNullable instance) => - <String, dynamic>{ - 'value': instance.value - .map((k, e) => MapEntry(k.toIso8601String(), e?.toIso8601String())), - }; + SimpleClassOfDateTimeToDateTimeNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map( + (k, e) => MapEntry(k.toIso8601String(), e?.toIso8601String()), + ), +}; SimpleClassNullableOfDateTimeToDateTimeNullable - _$SimpleClassNullableOfDateTimeToDateTimeNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDateTimeToDateTimeNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(DateTime.parse(k), - e == null ? null : DateTime.parse(e as String)), - ), - ); +_$SimpleClassNullableOfDateTimeToDateTimeNullableFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfDateTimeToDateTimeNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry( + DateTime.parse(k), + e == null ? null : DateTime.parse(e as String), + ), + ), +); Map<String, dynamic> _$SimpleClassNullableOfDateTimeToDateTimeNullableToJson( - SimpleClassNullableOfDateTimeToDateTimeNullable instance) => - <String, dynamic>{ - 'value': instance.value - ?.map((k, e) => MapEntry(k.toIso8601String(), e?.toIso8601String())), - }; + SimpleClassNullableOfDateTimeToDateTimeNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map( + (k, e) => MapEntry(k.toIso8601String(), e?.toIso8601String()), + ), +}; SimpleClassOfDynamicToDateTimeNullable - _$SimpleClassOfDynamicToDateTimeNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfDynamicToDateTimeNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => - MapEntry(k, e == null ? null : DateTime.parse(e as String)), - ), - ); +_$SimpleClassOfDynamicToDateTimeNullableFromJson(Map<String, dynamic> json) => + SimpleClassOfDynamicToDateTimeNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(k, e == null ? null : DateTime.parse(e as String)), + ), + ); Map<String, dynamic> _$SimpleClassOfDynamicToDateTimeNullableToJson( - SimpleClassOfDynamicToDateTimeNullable instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k, e?.toIso8601String())), - }; + SimpleClassOfDynamicToDateTimeNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k, e?.toIso8601String())), +}; SimpleClassNullableOfDynamicToDateTimeNullable - _$SimpleClassNullableOfDynamicToDateTimeNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDynamicToDateTimeNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => - MapEntry(k, e == null ? null : DateTime.parse(e as String)), - ), - ); +_$SimpleClassNullableOfDynamicToDateTimeNullableFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfDynamicToDateTimeNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, e == null ? null : DateTime.parse(e as String)), + ), +); Map<String, dynamic> _$SimpleClassNullableOfDynamicToDateTimeNullableToJson( - SimpleClassNullableOfDynamicToDateTimeNullable instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k, e?.toIso8601String())), - }; + SimpleClassNullableOfDynamicToDateTimeNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k, e?.toIso8601String())), +}; SimpleClassOfEnumTypeToDateTimeNullable - _$SimpleClassOfEnumTypeToDateTimeNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfEnumTypeToDateTimeNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), - e == null ? null : DateTime.parse(e as String)), - ), - ); +_$SimpleClassOfEnumTypeToDateTimeNullableFromJson(Map<String, dynamic> json) => + SimpleClassOfEnumTypeToDateTimeNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry( + $enumDecode(_$EnumTypeEnumMap, k), + e == null ? null : DateTime.parse(e as String), + ), + ), + ); Map<String, dynamic> _$SimpleClassOfEnumTypeToDateTimeNullableToJson( - SimpleClassOfEnumTypeToDateTimeNullable instance) => - <String, dynamic>{ - 'value': instance.value - .map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e?.toIso8601String())), - }; + SimpleClassOfEnumTypeToDateTimeNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map( + (k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e?.toIso8601String()), + ), +}; SimpleClassNullableOfEnumTypeToDateTimeNullable - _$SimpleClassNullableOfEnumTypeToDateTimeNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfEnumTypeToDateTimeNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), - e == null ? null : DateTime.parse(e as String)), - ), - ); +_$SimpleClassNullableOfEnumTypeToDateTimeNullableFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfEnumTypeToDateTimeNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry( + $enumDecode(_$EnumTypeEnumMap, k), + e == null ? null : DateTime.parse(e as String), + ), + ), +); Map<String, dynamic> _$SimpleClassNullableOfEnumTypeToDateTimeNullableToJson( - SimpleClassNullableOfEnumTypeToDateTimeNullable instance) => - <String, dynamic>{ - 'value': instance.value?.map( - (k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e?.toIso8601String())), - }; + SimpleClassNullableOfEnumTypeToDateTimeNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map( + (k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e?.toIso8601String()), + ), +}; SimpleClassOfIntToDateTimeNullable _$SimpleClassOfIntToDateTimeNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfIntToDateTimeNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry( - int.parse(k), e == null ? null : DateTime.parse(e as String)), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfIntToDateTimeNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => + MapEntry(int.parse(k), e == null ? null : DateTime.parse(e as String)), + ), +); Map<String, dynamic> _$SimpleClassOfIntToDateTimeNullableToJson( - SimpleClassOfIntToDateTimeNullable instance) => - <String, dynamic>{ - 'value': instance.value - .map((k, e) => MapEntry(k.toString(), e?.toIso8601String())), - }; + SimpleClassOfIntToDateTimeNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map( + (k, e) => MapEntry(k.toString(), e?.toIso8601String()), + ), +}; SimpleClassNullableOfIntToDateTimeNullable - _$SimpleClassNullableOfIntToDateTimeNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfIntToDateTimeNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry( - int.parse(k), e == null ? null : DateTime.parse(e as String)), - ), - ); +_$SimpleClassNullableOfIntToDateTimeNullableFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfIntToDateTimeNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => + MapEntry(int.parse(k), e == null ? null : DateTime.parse(e as String)), + ), +); Map<String, dynamic> _$SimpleClassNullableOfIntToDateTimeNullableToJson( - SimpleClassNullableOfIntToDateTimeNullable instance) => - <String, dynamic>{ - 'value': instance.value - ?.map((k, e) => MapEntry(k.toString(), e?.toIso8601String())), - }; + SimpleClassNullableOfIntToDateTimeNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map( + (k, e) => MapEntry(k.toString(), e?.toIso8601String()), + ), +}; SimpleClassOfObjectToDateTimeNullable - _$SimpleClassOfObjectToDateTimeNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfObjectToDateTimeNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => - MapEntry(k, e == null ? null : DateTime.parse(e as String)), - ), - ); +_$SimpleClassOfObjectToDateTimeNullableFromJson(Map<String, dynamic> json) => + SimpleClassOfObjectToDateTimeNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(k, e == null ? null : DateTime.parse(e as String)), + ), + ); Map<String, dynamic> _$SimpleClassOfObjectToDateTimeNullableToJson( - SimpleClassOfObjectToDateTimeNullable instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k, e?.toIso8601String())), - }; + SimpleClassOfObjectToDateTimeNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k, e?.toIso8601String())), +}; SimpleClassNullableOfObjectToDateTimeNullable - _$SimpleClassNullableOfObjectToDateTimeNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfObjectToDateTimeNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => - MapEntry(k, e == null ? null : DateTime.parse(e as String)), - ), - ); +_$SimpleClassNullableOfObjectToDateTimeNullableFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfObjectToDateTimeNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, e == null ? null : DateTime.parse(e as String)), + ), +); Map<String, dynamic> _$SimpleClassNullableOfObjectToDateTimeNullableToJson( - SimpleClassNullableOfObjectToDateTimeNullable instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k, e?.toIso8601String())), - }; + SimpleClassNullableOfObjectToDateTimeNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k, e?.toIso8601String())), +}; SimpleClassOfStringToDateTimeNullable - _$SimpleClassOfStringToDateTimeNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfStringToDateTimeNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => - MapEntry(k, e == null ? null : DateTime.parse(e as String)), - ), - ); +_$SimpleClassOfStringToDateTimeNullableFromJson(Map<String, dynamic> json) => + SimpleClassOfStringToDateTimeNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(k, e == null ? null : DateTime.parse(e as String)), + ), + ); Map<String, dynamic> _$SimpleClassOfStringToDateTimeNullableToJson( - SimpleClassOfStringToDateTimeNullable instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k, e?.toIso8601String())), - }; + SimpleClassOfStringToDateTimeNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k, e?.toIso8601String())), +}; SimpleClassNullableOfStringToDateTimeNullable - _$SimpleClassNullableOfStringToDateTimeNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfStringToDateTimeNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => - MapEntry(k, e == null ? null : DateTime.parse(e as String)), - ), - ); +_$SimpleClassNullableOfStringToDateTimeNullableFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfStringToDateTimeNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, e == null ? null : DateTime.parse(e as String)), + ), +); Map<String, dynamic> _$SimpleClassNullableOfStringToDateTimeNullableToJson( - SimpleClassNullableOfStringToDateTimeNullable instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k, e?.toIso8601String())), - }; + SimpleClassNullableOfStringToDateTimeNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k, e?.toIso8601String())), +}; SimpleClassOfUriToDateTimeNullable _$SimpleClassOfUriToDateTimeNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfUriToDateTimeNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry( - Uri.parse(k), e == null ? null : DateTime.parse(e as String)), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfUriToDateTimeNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => + MapEntry(Uri.parse(k), e == null ? null : DateTime.parse(e as String)), + ), +); Map<String, dynamic> _$SimpleClassOfUriToDateTimeNullableToJson( - SimpleClassOfUriToDateTimeNullable instance) => - <String, dynamic>{ - 'value': instance.value - .map((k, e) => MapEntry(k.toString(), e?.toIso8601String())), - }; + SimpleClassOfUriToDateTimeNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map( + (k, e) => MapEntry(k.toString(), e?.toIso8601String()), + ), +}; SimpleClassNullableOfUriToDateTimeNullable - _$SimpleClassNullableOfUriToDateTimeNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfUriToDateTimeNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry( - Uri.parse(k), e == null ? null : DateTime.parse(e as String)), - ), - ); +_$SimpleClassNullableOfUriToDateTimeNullableFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfUriToDateTimeNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => + MapEntry(Uri.parse(k), e == null ? null : DateTime.parse(e as String)), + ), +); Map<String, dynamic> _$SimpleClassNullableOfUriToDateTimeNullableToJson( - SimpleClassNullableOfUriToDateTimeNullable instance) => - <String, dynamic>{ - 'value': instance.value - ?.map((k, e) => MapEntry(k.toString(), e?.toIso8601String())), - }; + SimpleClassNullableOfUriToDateTimeNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map( + (k, e) => MapEntry(k.toString(), e?.toIso8601String()), + ), +}; SimpleClassOfBigIntToDouble _$SimpleClassOfBigIntToDoubleFromJson( - Map<String, dynamic> json) => - SimpleClassOfBigIntToDouble( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(BigInt.parse(k), (e as num).toDouble()), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfBigIntToDouble( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(BigInt.parse(k), (e as num).toDouble()), + ), +); Map<String, dynamic> _$SimpleClassOfBigIntToDoubleToJson( - SimpleClassOfBigIntToDouble instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassOfBigIntToDouble instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassNullableOfBigIntToDouble - _$SimpleClassNullableOfBigIntToDoubleFromJson(Map<String, dynamic> json) => - SimpleClassNullableOfBigIntToDouble( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(BigInt.parse(k), (e as num).toDouble()), - ), - ); +_$SimpleClassNullableOfBigIntToDoubleFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfBigIntToDouble( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(BigInt.parse(k), (e as num).toDouble()), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfBigIntToDoubleToJson( - SimpleClassNullableOfBigIntToDouble instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassNullableOfBigIntToDouble instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassOfDateTimeToDouble _$SimpleClassOfDateTimeToDoubleFromJson( - Map<String, dynamic> json) => - SimpleClassOfDateTimeToDouble( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(DateTime.parse(k), (e as num).toDouble()), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfDateTimeToDouble( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(DateTime.parse(k), (e as num).toDouble()), + ), +); Map<String, dynamic> _$SimpleClassOfDateTimeToDoubleToJson( - SimpleClassOfDateTimeToDouble instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toIso8601String(), e)), - }; + SimpleClassOfDateTimeToDouble instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toIso8601String(), e)), +}; SimpleClassNullableOfDateTimeToDouble - _$SimpleClassNullableOfDateTimeToDoubleFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDateTimeToDouble( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(DateTime.parse(k), (e as num).toDouble()), - ), - ); +_$SimpleClassNullableOfDateTimeToDoubleFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfDateTimeToDouble( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(DateTime.parse(k), (e as num).toDouble()), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfDateTimeToDoubleToJson( - SimpleClassNullableOfDateTimeToDouble instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toIso8601String(), e)), - }; + SimpleClassNullableOfDateTimeToDouble instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toIso8601String(), e)), +}; SimpleClassOfDynamicToDouble _$SimpleClassOfDynamicToDoubleFromJson( - Map<String, dynamic> json) => - SimpleClassOfDynamicToDouble( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(k, (e as num).toDouble()), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfDynamicToDouble( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(k, (e as num).toDouble()), + ), +); Map<String, dynamic> _$SimpleClassOfDynamicToDoubleToJson( - SimpleClassOfDynamicToDouble instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassOfDynamicToDouble instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassNullableOfDynamicToDouble - _$SimpleClassNullableOfDynamicToDoubleFromJson(Map<String, dynamic> json) => - SimpleClassNullableOfDynamicToDouble( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, (e as num).toDouble()), - ), - ); +_$SimpleClassNullableOfDynamicToDoubleFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfDynamicToDouble( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, (e as num).toDouble()), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfDynamicToDoubleToJson( - SimpleClassNullableOfDynamicToDouble instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassNullableOfDynamicToDouble instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassOfEnumTypeToDouble _$SimpleClassOfEnumTypeToDoubleFromJson( - Map<String, dynamic> json) => - SimpleClassOfEnumTypeToDouble( - (json['value'] as Map<String, dynamic>).map( - (k, e) => - MapEntry($enumDecode(_$EnumTypeEnumMap, k), (e as num).toDouble()), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfEnumTypeToDouble( + (json['value'] as Map<String, dynamic>).map( + (k, e) => + MapEntry($enumDecode(_$EnumTypeEnumMap, k), (e as num).toDouble()), + ), +); Map<String, dynamic> _$SimpleClassOfEnumTypeToDoubleToJson( - SimpleClassOfEnumTypeToDouble instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), - }; + SimpleClassOfEnumTypeToDouble instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), +}; SimpleClassNullableOfEnumTypeToDouble - _$SimpleClassNullableOfEnumTypeToDoubleFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfEnumTypeToDouble( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry( - $enumDecode(_$EnumTypeEnumMap, k), (e as num).toDouble()), - ), - ); +_$SimpleClassNullableOfEnumTypeToDoubleFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfEnumTypeToDouble( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => + MapEntry($enumDecode(_$EnumTypeEnumMap, k), (e as num).toDouble()), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfEnumTypeToDoubleToJson( - SimpleClassNullableOfEnumTypeToDouble instance) => - <String, dynamic>{ - 'value': - instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), - }; + SimpleClassNullableOfEnumTypeToDouble instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), +}; SimpleClassOfIntToDouble _$SimpleClassOfIntToDoubleFromJson( - Map<String, dynamic> json) => - SimpleClassOfIntToDouble( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(int.parse(k), (e as num).toDouble()), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfIntToDouble( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(int.parse(k), (e as num).toDouble()), + ), +); Map<String, dynamic> _$SimpleClassOfIntToDoubleToJson( - SimpleClassOfIntToDouble instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassOfIntToDouble instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassNullableOfIntToDouble _$SimpleClassNullableOfIntToDoubleFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfIntToDouble( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(int.parse(k), (e as num).toDouble()), - ), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfIntToDouble( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(int.parse(k), (e as num).toDouble()), + ), +); Map<String, dynamic> _$SimpleClassNullableOfIntToDoubleToJson( - SimpleClassNullableOfIntToDouble instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassNullableOfIntToDouble instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassOfObjectToDouble _$SimpleClassOfObjectToDoubleFromJson( - Map<String, dynamic> json) => - SimpleClassOfObjectToDouble( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(k, (e as num).toDouble()), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfObjectToDouble( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(k, (e as num).toDouble()), + ), +); Map<String, dynamic> _$SimpleClassOfObjectToDoubleToJson( - SimpleClassOfObjectToDouble instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassOfObjectToDouble instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassNullableOfObjectToDouble - _$SimpleClassNullableOfObjectToDoubleFromJson(Map<String, dynamic> json) => - SimpleClassNullableOfObjectToDouble( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, (e as num).toDouble()), - ), - ); +_$SimpleClassNullableOfObjectToDoubleFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfObjectToDouble( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, (e as num).toDouble()), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfObjectToDoubleToJson( - SimpleClassNullableOfObjectToDouble instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassNullableOfObjectToDouble instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassOfStringToDouble _$SimpleClassOfStringToDoubleFromJson( - Map<String, dynamic> json) => - SimpleClassOfStringToDouble( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(k, (e as num).toDouble()), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfStringToDouble( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(k, (e as num).toDouble()), + ), +); Map<String, dynamic> _$SimpleClassOfStringToDoubleToJson( - SimpleClassOfStringToDouble instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassOfStringToDouble instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassNullableOfStringToDouble - _$SimpleClassNullableOfStringToDoubleFromJson(Map<String, dynamic> json) => - SimpleClassNullableOfStringToDouble( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, (e as num).toDouble()), - ), - ); +_$SimpleClassNullableOfStringToDoubleFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfStringToDouble( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, (e as num).toDouble()), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfStringToDoubleToJson( - SimpleClassNullableOfStringToDouble instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassNullableOfStringToDouble instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassOfUriToDouble _$SimpleClassOfUriToDoubleFromJson( - Map<String, dynamic> json) => - SimpleClassOfUriToDouble( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(Uri.parse(k), (e as num).toDouble()), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfUriToDouble( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(Uri.parse(k), (e as num).toDouble()), + ), +); Map<String, dynamic> _$SimpleClassOfUriToDoubleToJson( - SimpleClassOfUriToDouble instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassOfUriToDouble instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassNullableOfUriToDouble _$SimpleClassNullableOfUriToDoubleFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfUriToDouble( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(Uri.parse(k), (e as num).toDouble()), - ), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfUriToDouble( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(Uri.parse(k), (e as num).toDouble()), + ), +); Map<String, dynamic> _$SimpleClassNullableOfUriToDoubleToJson( - SimpleClassNullableOfUriToDouble instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassNullableOfUriToDouble instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassOfBigIntToDoubleNullable - _$SimpleClassOfBigIntToDoubleNullableFromJson(Map<String, dynamic> json) => - SimpleClassOfBigIntToDoubleNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(BigInt.parse(k), (e as num?)?.toDouble()), - ), - ); +_$SimpleClassOfBigIntToDoubleNullableFromJson(Map<String, dynamic> json) => + SimpleClassOfBigIntToDoubleNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(BigInt.parse(k), (e as num?)?.toDouble()), + ), + ); Map<String, dynamic> _$SimpleClassOfBigIntToDoubleNullableToJson( - SimpleClassOfBigIntToDoubleNullable instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassOfBigIntToDoubleNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassNullableOfBigIntToDoubleNullable - _$SimpleClassNullableOfBigIntToDoubleNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfBigIntToDoubleNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(BigInt.parse(k), (e as num?)?.toDouble()), - ), - ); +_$SimpleClassNullableOfBigIntToDoubleNullableFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfBigIntToDoubleNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(BigInt.parse(k), (e as num?)?.toDouble()), + ), +); Map<String, dynamic> _$SimpleClassNullableOfBigIntToDoubleNullableToJson( - SimpleClassNullableOfBigIntToDoubleNullable instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassNullableOfBigIntToDoubleNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassOfDateTimeToDoubleNullable - _$SimpleClassOfDateTimeToDoubleNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfDateTimeToDoubleNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(DateTime.parse(k), (e as num?)?.toDouble()), - ), - ); +_$SimpleClassOfDateTimeToDoubleNullableFromJson(Map<String, dynamic> json) => + SimpleClassOfDateTimeToDoubleNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(DateTime.parse(k), (e as num?)?.toDouble()), + ), + ); Map<String, dynamic> _$SimpleClassOfDateTimeToDoubleNullableToJson( - SimpleClassOfDateTimeToDoubleNullable instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toIso8601String(), e)), - }; + SimpleClassOfDateTimeToDoubleNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toIso8601String(), e)), +}; SimpleClassNullableOfDateTimeToDoubleNullable - _$SimpleClassNullableOfDateTimeToDoubleNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDateTimeToDoubleNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(DateTime.parse(k), (e as num?)?.toDouble()), - ), - ); +_$SimpleClassNullableOfDateTimeToDoubleNullableFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfDateTimeToDoubleNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(DateTime.parse(k), (e as num?)?.toDouble()), + ), +); Map<String, dynamic> _$SimpleClassNullableOfDateTimeToDoubleNullableToJson( - SimpleClassNullableOfDateTimeToDoubleNullable instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toIso8601String(), e)), - }; + SimpleClassNullableOfDateTimeToDoubleNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toIso8601String(), e)), +}; SimpleClassOfDynamicToDoubleNullable - _$SimpleClassOfDynamicToDoubleNullableFromJson(Map<String, dynamic> json) => - SimpleClassOfDynamicToDoubleNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(k, (e as num?)?.toDouble()), - ), - ); +_$SimpleClassOfDynamicToDoubleNullableFromJson(Map<String, dynamic> json) => + SimpleClassOfDynamicToDoubleNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(k, (e as num?)?.toDouble()), + ), + ); Map<String, dynamic> _$SimpleClassOfDynamicToDoubleNullableToJson( - SimpleClassOfDynamicToDoubleNullable instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassOfDynamicToDoubleNullable instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassNullableOfDynamicToDoubleNullable - _$SimpleClassNullableOfDynamicToDoubleNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDynamicToDoubleNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, (e as num?)?.toDouble()), - ), - ); +_$SimpleClassNullableOfDynamicToDoubleNullableFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfDynamicToDoubleNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, (e as num?)?.toDouble()), + ), +); Map<String, dynamic> _$SimpleClassNullableOfDynamicToDoubleNullableToJson( - SimpleClassNullableOfDynamicToDoubleNullable instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassNullableOfDynamicToDoubleNullable instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassOfEnumTypeToDoubleNullable - _$SimpleClassOfEnumTypeToDoubleNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfEnumTypeToDoubleNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry( - $enumDecode(_$EnumTypeEnumMap, k), (e as num?)?.toDouble()), - ), - ); +_$SimpleClassOfEnumTypeToDoubleNullableFromJson(Map<String, dynamic> json) => + SimpleClassOfEnumTypeToDoubleNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry( + $enumDecode(_$EnumTypeEnumMap, k), + (e as num?)?.toDouble(), + ), + ), + ); Map<String, dynamic> _$SimpleClassOfEnumTypeToDoubleNullableToJson( - SimpleClassOfEnumTypeToDoubleNullable instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), - }; + SimpleClassOfEnumTypeToDoubleNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), +}; SimpleClassNullableOfEnumTypeToDoubleNullable - _$SimpleClassNullableOfEnumTypeToDoubleNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfEnumTypeToDoubleNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry( - $enumDecode(_$EnumTypeEnumMap, k), (e as num?)?.toDouble()), - ), - ); +_$SimpleClassNullableOfEnumTypeToDoubleNullableFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfEnumTypeToDoubleNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => + MapEntry($enumDecode(_$EnumTypeEnumMap, k), (e as num?)?.toDouble()), + ), +); Map<String, dynamic> _$SimpleClassNullableOfEnumTypeToDoubleNullableToJson( - SimpleClassNullableOfEnumTypeToDoubleNullable instance) => - <String, dynamic>{ - 'value': - instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), - }; + SimpleClassNullableOfEnumTypeToDoubleNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), +}; SimpleClassOfIntToDoubleNullable _$SimpleClassOfIntToDoubleNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfIntToDoubleNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(int.parse(k), (e as num?)?.toDouble()), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfIntToDoubleNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(int.parse(k), (e as num?)?.toDouble()), + ), +); Map<String, dynamic> _$SimpleClassOfIntToDoubleNullableToJson( - SimpleClassOfIntToDoubleNullable instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassOfIntToDoubleNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassNullableOfIntToDoubleNullable - _$SimpleClassNullableOfIntToDoubleNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfIntToDoubleNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(int.parse(k), (e as num?)?.toDouble()), - ), - ); +_$SimpleClassNullableOfIntToDoubleNullableFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfIntToDoubleNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(int.parse(k), (e as num?)?.toDouble()), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfIntToDoubleNullableToJson( - SimpleClassNullableOfIntToDoubleNullable instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassNullableOfIntToDoubleNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassOfObjectToDoubleNullable - _$SimpleClassOfObjectToDoubleNullableFromJson(Map<String, dynamic> json) => - SimpleClassOfObjectToDoubleNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(k, (e as num?)?.toDouble()), - ), - ); +_$SimpleClassOfObjectToDoubleNullableFromJson(Map<String, dynamic> json) => + SimpleClassOfObjectToDoubleNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(k, (e as num?)?.toDouble()), + ), + ); Map<String, dynamic> _$SimpleClassOfObjectToDoubleNullableToJson( - SimpleClassOfObjectToDoubleNullable instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassOfObjectToDoubleNullable instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassNullableOfObjectToDoubleNullable - _$SimpleClassNullableOfObjectToDoubleNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfObjectToDoubleNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, (e as num?)?.toDouble()), - ), - ); +_$SimpleClassNullableOfObjectToDoubleNullableFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfObjectToDoubleNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, (e as num?)?.toDouble()), + ), +); Map<String, dynamic> _$SimpleClassNullableOfObjectToDoubleNullableToJson( - SimpleClassNullableOfObjectToDoubleNullable instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassNullableOfObjectToDoubleNullable instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassOfStringToDoubleNullable - _$SimpleClassOfStringToDoubleNullableFromJson(Map<String, dynamic> json) => - SimpleClassOfStringToDoubleNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(k, (e as num?)?.toDouble()), - ), - ); +_$SimpleClassOfStringToDoubleNullableFromJson(Map<String, dynamic> json) => + SimpleClassOfStringToDoubleNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(k, (e as num?)?.toDouble()), + ), + ); Map<String, dynamic> _$SimpleClassOfStringToDoubleNullableToJson( - SimpleClassOfStringToDoubleNullable instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassOfStringToDoubleNullable instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassNullableOfStringToDoubleNullable - _$SimpleClassNullableOfStringToDoubleNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfStringToDoubleNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, (e as num?)?.toDouble()), - ), - ); +_$SimpleClassNullableOfStringToDoubleNullableFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfStringToDoubleNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, (e as num?)?.toDouble()), + ), +); Map<String, dynamic> _$SimpleClassNullableOfStringToDoubleNullableToJson( - SimpleClassNullableOfStringToDoubleNullable instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassNullableOfStringToDoubleNullable instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassOfUriToDoubleNullable _$SimpleClassOfUriToDoubleNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfUriToDoubleNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(Uri.parse(k), (e as num?)?.toDouble()), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfUriToDoubleNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(Uri.parse(k), (e as num?)?.toDouble()), + ), +); Map<String, dynamic> _$SimpleClassOfUriToDoubleNullableToJson( - SimpleClassOfUriToDoubleNullable instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassOfUriToDoubleNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassNullableOfUriToDoubleNullable - _$SimpleClassNullableOfUriToDoubleNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfUriToDoubleNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(Uri.parse(k), (e as num?)?.toDouble()), - ), - ); +_$SimpleClassNullableOfUriToDoubleNullableFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfUriToDoubleNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(Uri.parse(k), (e as num?)?.toDouble()), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfUriToDoubleNullableToJson( - SimpleClassNullableOfUriToDoubleNullable instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassNullableOfUriToDoubleNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassOfBigIntToDuration _$SimpleClassOfBigIntToDurationFromJson( - Map<String, dynamic> json) => - SimpleClassOfBigIntToDuration( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry( - BigInt.parse(k), Duration(microseconds: (e as num).toInt())), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfBigIntToDuration( + (json['value'] as Map<String, dynamic>).map( + (k, e) => + MapEntry(BigInt.parse(k), Duration(microseconds: (e as num).toInt())), + ), +); Map<String, dynamic> _$SimpleClassOfBigIntToDurationToJson( - SimpleClassOfBigIntToDuration instance) => - <String, dynamic>{ - 'value': instance.value - .map((k, e) => MapEntry(k.toString(), e.inMicroseconds)), - }; + SimpleClassOfBigIntToDuration instance, +) => <String, dynamic>{ + 'value': instance.value.map( + (k, e) => MapEntry(k.toString(), e.inMicroseconds), + ), +}; SimpleClassNullableOfBigIntToDuration - _$SimpleClassNullableOfBigIntToDurationFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfBigIntToDuration( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry( - BigInt.parse(k), Duration(microseconds: (e as num).toInt())), - ), - ); +_$SimpleClassNullableOfBigIntToDurationFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfBigIntToDuration( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry( + BigInt.parse(k), + Duration(microseconds: (e as num).toInt()), + ), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfBigIntToDurationToJson( - SimpleClassNullableOfBigIntToDuration instance) => - <String, dynamic>{ - 'value': instance.value - ?.map((k, e) => MapEntry(k.toString(), e.inMicroseconds)), - }; + SimpleClassNullableOfBigIntToDuration instance, +) => <String, dynamic>{ + 'value': instance.value?.map( + (k, e) => MapEntry(k.toString(), e.inMicroseconds), + ), +}; SimpleClassOfDateTimeToDuration _$SimpleClassOfDateTimeToDurationFromJson( - Map<String, dynamic> json) => - SimpleClassOfDateTimeToDuration( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry( - DateTime.parse(k), Duration(microseconds: (e as num).toInt())), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfDateTimeToDuration( + (json['value'] as Map<String, dynamic>).map( + (k, e) => + MapEntry(DateTime.parse(k), Duration(microseconds: (e as num).toInt())), + ), +); Map<String, dynamic> _$SimpleClassOfDateTimeToDurationToJson( - SimpleClassOfDateTimeToDuration instance) => - <String, dynamic>{ - 'value': instance.value - .map((k, e) => MapEntry(k.toIso8601String(), e.inMicroseconds)), - }; + SimpleClassOfDateTimeToDuration instance, +) => <String, dynamic>{ + 'value': instance.value.map( + (k, e) => MapEntry(k.toIso8601String(), e.inMicroseconds), + ), +}; SimpleClassNullableOfDateTimeToDuration - _$SimpleClassNullableOfDateTimeToDurationFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDateTimeToDuration( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry( - DateTime.parse(k), Duration(microseconds: (e as num).toInt())), - ), - ); +_$SimpleClassNullableOfDateTimeToDurationFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfDateTimeToDuration( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry( + DateTime.parse(k), + Duration(microseconds: (e as num).toInt()), + ), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfDateTimeToDurationToJson( - SimpleClassNullableOfDateTimeToDuration instance) => - <String, dynamic>{ - 'value': instance.value - ?.map((k, e) => MapEntry(k.toIso8601String(), e.inMicroseconds)), - }; + SimpleClassNullableOfDateTimeToDuration instance, +) => <String, dynamic>{ + 'value': instance.value?.map( + (k, e) => MapEntry(k.toIso8601String(), e.inMicroseconds), + ), +}; SimpleClassOfDynamicToDuration _$SimpleClassOfDynamicToDurationFromJson( - Map<String, dynamic> json) => - SimpleClassOfDynamicToDuration( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(k, Duration(microseconds: (e as num).toInt())), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfDynamicToDuration( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(k, Duration(microseconds: (e as num).toInt())), + ), +); Map<String, dynamic> _$SimpleClassOfDynamicToDurationToJson( - SimpleClassOfDynamicToDuration instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k, e.inMicroseconds)), - }; + SimpleClassOfDynamicToDuration instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k, e.inMicroseconds)), +}; SimpleClassNullableOfDynamicToDuration - _$SimpleClassNullableOfDynamicToDurationFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDynamicToDuration( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, Duration(microseconds: (e as num).toInt())), - ), - ); +_$SimpleClassNullableOfDynamicToDurationFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfDynamicToDuration( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, Duration(microseconds: (e as num).toInt())), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfDynamicToDurationToJson( - SimpleClassNullableOfDynamicToDuration instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k, e.inMicroseconds)), - }; + SimpleClassNullableOfDynamicToDuration instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k, e.inMicroseconds)), +}; SimpleClassOfEnumTypeToDuration _$SimpleClassOfEnumTypeToDurationFromJson( - Map<String, dynamic> json) => - SimpleClassOfEnumTypeToDuration( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), - Duration(microseconds: (e as num).toInt())), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfEnumTypeToDuration( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry( + $enumDecode(_$EnumTypeEnumMap, k), + Duration(microseconds: (e as num).toInt()), + ), + ), +); Map<String, dynamic> _$SimpleClassOfEnumTypeToDurationToJson( - SimpleClassOfEnumTypeToDuration instance) => - <String, dynamic>{ - 'value': instance.value - .map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e.inMicroseconds)), - }; + SimpleClassOfEnumTypeToDuration instance, +) => <String, dynamic>{ + 'value': instance.value.map( + (k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e.inMicroseconds), + ), +}; SimpleClassNullableOfEnumTypeToDuration - _$SimpleClassNullableOfEnumTypeToDurationFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfEnumTypeToDuration( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), - Duration(microseconds: (e as num).toInt())), - ), - ); +_$SimpleClassNullableOfEnumTypeToDurationFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfEnumTypeToDuration( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry( + $enumDecode(_$EnumTypeEnumMap, k), + Duration(microseconds: (e as num).toInt()), + ), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfEnumTypeToDurationToJson( - SimpleClassNullableOfEnumTypeToDuration instance) => - <String, dynamic>{ - 'value': instance.value - ?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e.inMicroseconds)), - }; + SimpleClassNullableOfEnumTypeToDuration instance, +) => <String, dynamic>{ + 'value': instance.value?.map( + (k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e.inMicroseconds), + ), +}; SimpleClassOfIntToDuration _$SimpleClassOfIntToDurationFromJson( - Map<String, dynamic> json) => - SimpleClassOfIntToDuration( - (json['value'] as Map<String, dynamic>).map( - (k, e) => - MapEntry(int.parse(k), Duration(microseconds: (e as num).toInt())), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfIntToDuration( + (json['value'] as Map<String, dynamic>).map( + (k, e) => + MapEntry(int.parse(k), Duration(microseconds: (e as num).toInt())), + ), +); Map<String, dynamic> _$SimpleClassOfIntToDurationToJson( - SimpleClassOfIntToDuration instance) => - <String, dynamic>{ - 'value': instance.value - .map((k, e) => MapEntry(k.toString(), e.inMicroseconds)), - }; + SimpleClassOfIntToDuration instance, +) => <String, dynamic>{ + 'value': instance.value.map( + (k, e) => MapEntry(k.toString(), e.inMicroseconds), + ), +}; SimpleClassNullableOfIntToDuration _$SimpleClassNullableOfIntToDurationFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfIntToDuration( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => - MapEntry(int.parse(k), Duration(microseconds: (e as num).toInt())), - ), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfIntToDuration( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => + MapEntry(int.parse(k), Duration(microseconds: (e as num).toInt())), + ), +); Map<String, dynamic> _$SimpleClassNullableOfIntToDurationToJson( - SimpleClassNullableOfIntToDuration instance) => - <String, dynamic>{ - 'value': instance.value - ?.map((k, e) => MapEntry(k.toString(), e.inMicroseconds)), - }; + SimpleClassNullableOfIntToDuration instance, +) => <String, dynamic>{ + 'value': instance.value?.map( + (k, e) => MapEntry(k.toString(), e.inMicroseconds), + ), +}; SimpleClassOfObjectToDuration _$SimpleClassOfObjectToDurationFromJson( - Map<String, dynamic> json) => - SimpleClassOfObjectToDuration( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(k, Duration(microseconds: (e as num).toInt())), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfObjectToDuration( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(k, Duration(microseconds: (e as num).toInt())), + ), +); Map<String, dynamic> _$SimpleClassOfObjectToDurationToJson( - SimpleClassOfObjectToDuration instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k, e.inMicroseconds)), - }; + SimpleClassOfObjectToDuration instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k, e.inMicroseconds)), +}; SimpleClassNullableOfObjectToDuration - _$SimpleClassNullableOfObjectToDurationFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfObjectToDuration( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, Duration(microseconds: (e as num).toInt())), - ), - ); +_$SimpleClassNullableOfObjectToDurationFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfObjectToDuration( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, Duration(microseconds: (e as num).toInt())), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfObjectToDurationToJson( - SimpleClassNullableOfObjectToDuration instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k, e.inMicroseconds)), - }; + SimpleClassNullableOfObjectToDuration instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k, e.inMicroseconds)), +}; SimpleClassOfStringToDuration _$SimpleClassOfStringToDurationFromJson( - Map<String, dynamic> json) => - SimpleClassOfStringToDuration( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(k, Duration(microseconds: (e as num).toInt())), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfStringToDuration( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(k, Duration(microseconds: (e as num).toInt())), + ), +); Map<String, dynamic> _$SimpleClassOfStringToDurationToJson( - SimpleClassOfStringToDuration instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k, e.inMicroseconds)), - }; + SimpleClassOfStringToDuration instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k, e.inMicroseconds)), +}; SimpleClassNullableOfStringToDuration - _$SimpleClassNullableOfStringToDurationFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfStringToDuration( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, Duration(microseconds: (e as num).toInt())), - ), - ); +_$SimpleClassNullableOfStringToDurationFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfStringToDuration( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, Duration(microseconds: (e as num).toInt())), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfStringToDurationToJson( - SimpleClassNullableOfStringToDuration instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k, e.inMicroseconds)), - }; + SimpleClassNullableOfStringToDuration instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k, e.inMicroseconds)), +}; SimpleClassOfUriToDuration _$SimpleClassOfUriToDurationFromJson( - Map<String, dynamic> json) => - SimpleClassOfUriToDuration( - (json['value'] as Map<String, dynamic>).map( - (k, e) => - MapEntry(Uri.parse(k), Duration(microseconds: (e as num).toInt())), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfUriToDuration( + (json['value'] as Map<String, dynamic>).map( + (k, e) => + MapEntry(Uri.parse(k), Duration(microseconds: (e as num).toInt())), + ), +); Map<String, dynamic> _$SimpleClassOfUriToDurationToJson( - SimpleClassOfUriToDuration instance) => - <String, dynamic>{ - 'value': instance.value - .map((k, e) => MapEntry(k.toString(), e.inMicroseconds)), - }; + SimpleClassOfUriToDuration instance, +) => <String, dynamic>{ + 'value': instance.value.map( + (k, e) => MapEntry(k.toString(), e.inMicroseconds), + ), +}; SimpleClassNullableOfUriToDuration _$SimpleClassNullableOfUriToDurationFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfUriToDuration( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => - MapEntry(Uri.parse(k), Duration(microseconds: (e as num).toInt())), - ), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfUriToDuration( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => + MapEntry(Uri.parse(k), Duration(microseconds: (e as num).toInt())), + ), +); Map<String, dynamic> _$SimpleClassNullableOfUriToDurationToJson( - SimpleClassNullableOfUriToDuration instance) => - <String, dynamic>{ - 'value': instance.value - ?.map((k, e) => MapEntry(k.toString(), e.inMicroseconds)), - }; + SimpleClassNullableOfUriToDuration instance, +) => <String, dynamic>{ + 'value': instance.value?.map( + (k, e) => MapEntry(k.toString(), e.inMicroseconds), + ), +}; SimpleClassOfBigIntToDurationNullable - _$SimpleClassOfBigIntToDurationNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfBigIntToDurationNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(BigInt.parse(k), - e == null ? null : Duration(microseconds: (e as num).toInt())), - ), - ); +_$SimpleClassOfBigIntToDurationNullableFromJson(Map<String, dynamic> json) => + SimpleClassOfBigIntToDurationNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry( + BigInt.parse(k), + e == null ? null : Duration(microseconds: (e as num).toInt()), + ), + ), + ); Map<String, dynamic> _$SimpleClassOfBigIntToDurationNullableToJson( - SimpleClassOfBigIntToDurationNullable instance) => - <String, dynamic>{ - 'value': instance.value - .map((k, e) => MapEntry(k.toString(), e?.inMicroseconds)), - }; + SimpleClassOfBigIntToDurationNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map( + (k, e) => MapEntry(k.toString(), e?.inMicroseconds), + ), +}; SimpleClassNullableOfBigIntToDurationNullable - _$SimpleClassNullableOfBigIntToDurationNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfBigIntToDurationNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(BigInt.parse(k), - e == null ? null : Duration(microseconds: (e as num).toInt())), - ), - ); +_$SimpleClassNullableOfBigIntToDurationNullableFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfBigIntToDurationNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry( + BigInt.parse(k), + e == null ? null : Duration(microseconds: (e as num).toInt()), + ), + ), +); Map<String, dynamic> _$SimpleClassNullableOfBigIntToDurationNullableToJson( - SimpleClassNullableOfBigIntToDurationNullable instance) => - <String, dynamic>{ - 'value': instance.value - ?.map((k, e) => MapEntry(k.toString(), e?.inMicroseconds)), - }; + SimpleClassNullableOfBigIntToDurationNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map( + (k, e) => MapEntry(k.toString(), e?.inMicroseconds), + ), +}; SimpleClassOfDateTimeToDurationNullable - _$SimpleClassOfDateTimeToDurationNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfDateTimeToDurationNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(DateTime.parse(k), - e == null ? null : Duration(microseconds: (e as num).toInt())), - ), - ); +_$SimpleClassOfDateTimeToDurationNullableFromJson(Map<String, dynamic> json) => + SimpleClassOfDateTimeToDurationNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry( + DateTime.parse(k), + e == null ? null : Duration(microseconds: (e as num).toInt()), + ), + ), + ); Map<String, dynamic> _$SimpleClassOfDateTimeToDurationNullableToJson( - SimpleClassOfDateTimeToDurationNullable instance) => - <String, dynamic>{ - 'value': instance.value - .map((k, e) => MapEntry(k.toIso8601String(), e?.inMicroseconds)), - }; + SimpleClassOfDateTimeToDurationNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map( + (k, e) => MapEntry(k.toIso8601String(), e?.inMicroseconds), + ), +}; SimpleClassNullableOfDateTimeToDurationNullable - _$SimpleClassNullableOfDateTimeToDurationNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDateTimeToDurationNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(DateTime.parse(k), - e == null ? null : Duration(microseconds: (e as num).toInt())), - ), - ); +_$SimpleClassNullableOfDateTimeToDurationNullableFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfDateTimeToDurationNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry( + DateTime.parse(k), + e == null ? null : Duration(microseconds: (e as num).toInt()), + ), + ), +); Map<String, dynamic> _$SimpleClassNullableOfDateTimeToDurationNullableToJson( - SimpleClassNullableOfDateTimeToDurationNullable instance) => - <String, dynamic>{ - 'value': instance.value - ?.map((k, e) => MapEntry(k.toIso8601String(), e?.inMicroseconds)), - }; + SimpleClassNullableOfDateTimeToDurationNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map( + (k, e) => MapEntry(k.toIso8601String(), e?.inMicroseconds), + ), +}; SimpleClassOfDynamicToDurationNullable - _$SimpleClassOfDynamicToDurationNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfDynamicToDurationNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(k, - e == null ? null : Duration(microseconds: (e as num).toInt())), - ), - ); +_$SimpleClassOfDynamicToDurationNullableFromJson(Map<String, dynamic> json) => + SimpleClassOfDynamicToDurationNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry( + k, + e == null ? null : Duration(microseconds: (e as num).toInt()), + ), + ), + ); Map<String, dynamic> _$SimpleClassOfDynamicToDurationNullableToJson( - SimpleClassOfDynamicToDurationNullable instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k, e?.inMicroseconds)), - }; + SimpleClassOfDynamicToDurationNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k, e?.inMicroseconds)), +}; SimpleClassNullableOfDynamicToDurationNullable - _$SimpleClassNullableOfDynamicToDurationNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDynamicToDurationNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, - e == null ? null : Duration(microseconds: (e as num).toInt())), - ), - ); +_$SimpleClassNullableOfDynamicToDurationNullableFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfDynamicToDurationNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry( + k, + e == null ? null : Duration(microseconds: (e as num).toInt()), + ), + ), +); Map<String, dynamic> _$SimpleClassNullableOfDynamicToDurationNullableToJson( - SimpleClassNullableOfDynamicToDurationNullable instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k, e?.inMicroseconds)), - }; + SimpleClassNullableOfDynamicToDurationNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k, e?.inMicroseconds)), +}; SimpleClassOfEnumTypeToDurationNullable - _$SimpleClassOfEnumTypeToDurationNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfEnumTypeToDurationNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), - e == null ? null : Duration(microseconds: (e as num).toInt())), - ), - ); +_$SimpleClassOfEnumTypeToDurationNullableFromJson(Map<String, dynamic> json) => + SimpleClassOfEnumTypeToDurationNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry( + $enumDecode(_$EnumTypeEnumMap, k), + e == null ? null : Duration(microseconds: (e as num).toInt()), + ), + ), + ); Map<String, dynamic> _$SimpleClassOfEnumTypeToDurationNullableToJson( - SimpleClassOfEnumTypeToDurationNullable instance) => - <String, dynamic>{ - 'value': instance.value - .map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e?.inMicroseconds)), - }; + SimpleClassOfEnumTypeToDurationNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map( + (k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e?.inMicroseconds), + ), +}; SimpleClassNullableOfEnumTypeToDurationNullable - _$SimpleClassNullableOfEnumTypeToDurationNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfEnumTypeToDurationNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), - e == null ? null : Duration(microseconds: (e as num).toInt())), - ), - ); +_$SimpleClassNullableOfEnumTypeToDurationNullableFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfEnumTypeToDurationNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry( + $enumDecode(_$EnumTypeEnumMap, k), + e == null ? null : Duration(microseconds: (e as num).toInt()), + ), + ), +); Map<String, dynamic> _$SimpleClassNullableOfEnumTypeToDurationNullableToJson( - SimpleClassNullableOfEnumTypeToDurationNullable instance) => - <String, dynamic>{ - 'value': instance.value - ?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e?.inMicroseconds)), - }; + SimpleClassNullableOfEnumTypeToDurationNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map( + (k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e?.inMicroseconds), + ), +}; SimpleClassOfIntToDurationNullable _$SimpleClassOfIntToDurationNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfIntToDurationNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(int.parse(k), - e == null ? null : Duration(microseconds: (e as num).toInt())), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfIntToDurationNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry( + int.parse(k), + e == null ? null : Duration(microseconds: (e as num).toInt()), + ), + ), +); Map<String, dynamic> _$SimpleClassOfIntToDurationNullableToJson( - SimpleClassOfIntToDurationNullable instance) => - <String, dynamic>{ - 'value': instance.value - .map((k, e) => MapEntry(k.toString(), e?.inMicroseconds)), - }; + SimpleClassOfIntToDurationNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map( + (k, e) => MapEntry(k.toString(), e?.inMicroseconds), + ), +}; SimpleClassNullableOfIntToDurationNullable - _$SimpleClassNullableOfIntToDurationNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfIntToDurationNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(int.parse(k), - e == null ? null : Duration(microseconds: (e as num).toInt())), - ), - ); +_$SimpleClassNullableOfIntToDurationNullableFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfIntToDurationNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry( + int.parse(k), + e == null ? null : Duration(microseconds: (e as num).toInt()), + ), + ), +); Map<String, dynamic> _$SimpleClassNullableOfIntToDurationNullableToJson( - SimpleClassNullableOfIntToDurationNullable instance) => - <String, dynamic>{ - 'value': instance.value - ?.map((k, e) => MapEntry(k.toString(), e?.inMicroseconds)), - }; + SimpleClassNullableOfIntToDurationNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map( + (k, e) => MapEntry(k.toString(), e?.inMicroseconds), + ), +}; SimpleClassOfObjectToDurationNullable - _$SimpleClassOfObjectToDurationNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfObjectToDurationNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(k, - e == null ? null : Duration(microseconds: (e as num).toInt())), - ), - ); +_$SimpleClassOfObjectToDurationNullableFromJson(Map<String, dynamic> json) => + SimpleClassOfObjectToDurationNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry( + k, + e == null ? null : Duration(microseconds: (e as num).toInt()), + ), + ), + ); Map<String, dynamic> _$SimpleClassOfObjectToDurationNullableToJson( - SimpleClassOfObjectToDurationNullable instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k, e?.inMicroseconds)), - }; + SimpleClassOfObjectToDurationNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k, e?.inMicroseconds)), +}; SimpleClassNullableOfObjectToDurationNullable - _$SimpleClassNullableOfObjectToDurationNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfObjectToDurationNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, - e == null ? null : Duration(microseconds: (e as num).toInt())), - ), - ); +_$SimpleClassNullableOfObjectToDurationNullableFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfObjectToDurationNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry( + k, + e == null ? null : Duration(microseconds: (e as num).toInt()), + ), + ), +); Map<String, dynamic> _$SimpleClassNullableOfObjectToDurationNullableToJson( - SimpleClassNullableOfObjectToDurationNullable instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k, e?.inMicroseconds)), - }; + SimpleClassNullableOfObjectToDurationNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k, e?.inMicroseconds)), +}; SimpleClassOfStringToDurationNullable - _$SimpleClassOfStringToDurationNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfStringToDurationNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(k, - e == null ? null : Duration(microseconds: (e as num).toInt())), - ), - ); +_$SimpleClassOfStringToDurationNullableFromJson(Map<String, dynamic> json) => + SimpleClassOfStringToDurationNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry( + k, + e == null ? null : Duration(microseconds: (e as num).toInt()), + ), + ), + ); Map<String, dynamic> _$SimpleClassOfStringToDurationNullableToJson( - SimpleClassOfStringToDurationNullable instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k, e?.inMicroseconds)), - }; + SimpleClassOfStringToDurationNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k, e?.inMicroseconds)), +}; SimpleClassNullableOfStringToDurationNullable - _$SimpleClassNullableOfStringToDurationNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfStringToDurationNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, - e == null ? null : Duration(microseconds: (e as num).toInt())), - ), - ); +_$SimpleClassNullableOfStringToDurationNullableFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfStringToDurationNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry( + k, + e == null ? null : Duration(microseconds: (e as num).toInt()), + ), + ), +); Map<String, dynamic> _$SimpleClassNullableOfStringToDurationNullableToJson( - SimpleClassNullableOfStringToDurationNullable instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k, e?.inMicroseconds)), - }; + SimpleClassNullableOfStringToDurationNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k, e?.inMicroseconds)), +}; SimpleClassOfUriToDurationNullable _$SimpleClassOfUriToDurationNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfUriToDurationNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(Uri.parse(k), - e == null ? null : Duration(microseconds: (e as num).toInt())), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfUriToDurationNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry( + Uri.parse(k), + e == null ? null : Duration(microseconds: (e as num).toInt()), + ), + ), +); Map<String, dynamic> _$SimpleClassOfUriToDurationNullableToJson( - SimpleClassOfUriToDurationNullable instance) => - <String, dynamic>{ - 'value': instance.value - .map((k, e) => MapEntry(k.toString(), e?.inMicroseconds)), - }; + SimpleClassOfUriToDurationNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map( + (k, e) => MapEntry(k.toString(), e?.inMicroseconds), + ), +}; SimpleClassNullableOfUriToDurationNullable - _$SimpleClassNullableOfUriToDurationNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfUriToDurationNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(Uri.parse(k), - e == null ? null : Duration(microseconds: (e as num).toInt())), - ), - ); +_$SimpleClassNullableOfUriToDurationNullableFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfUriToDurationNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry( + Uri.parse(k), + e == null ? null : Duration(microseconds: (e as num).toInt()), + ), + ), +); Map<String, dynamic> _$SimpleClassNullableOfUriToDurationNullableToJson( - SimpleClassNullableOfUriToDurationNullable instance) => - <String, dynamic>{ - 'value': instance.value - ?.map((k, e) => MapEntry(k.toString(), e?.inMicroseconds)), - }; + SimpleClassNullableOfUriToDurationNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map( + (k, e) => MapEntry(k.toString(), e?.inMicroseconds), + ), +}; SimpleClassOfBigIntToDynamic _$SimpleClassOfBigIntToDynamicFromJson( - Map<String, dynamic> json) => - SimpleClassOfBigIntToDynamic( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(BigInt.parse(k), e), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfBigIntToDynamic( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(BigInt.parse(k), e), + ), +); Map<String, dynamic> _$SimpleClassOfBigIntToDynamicToJson( - SimpleClassOfBigIntToDynamic instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassOfBigIntToDynamic instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassNullableOfBigIntToDynamic - _$SimpleClassNullableOfBigIntToDynamicFromJson(Map<String, dynamic> json) => - SimpleClassNullableOfBigIntToDynamic( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(BigInt.parse(k), e), - ), - ); +_$SimpleClassNullableOfBigIntToDynamicFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfBigIntToDynamic( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(BigInt.parse(k), e), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfBigIntToDynamicToJson( - SimpleClassNullableOfBigIntToDynamic instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassNullableOfBigIntToDynamic instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassOfDateTimeToDynamic _$SimpleClassOfDateTimeToDynamicFromJson( - Map<String, dynamic> json) => - SimpleClassOfDateTimeToDynamic( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(DateTime.parse(k), e), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfDateTimeToDynamic( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(DateTime.parse(k), e), + ), +); Map<String, dynamic> _$SimpleClassOfDateTimeToDynamicToJson( - SimpleClassOfDateTimeToDynamic instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toIso8601String(), e)), - }; + SimpleClassOfDateTimeToDynamic instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toIso8601String(), e)), +}; SimpleClassNullableOfDateTimeToDynamic - _$SimpleClassNullableOfDateTimeToDynamicFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDateTimeToDynamic( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(DateTime.parse(k), e), - ), - ); +_$SimpleClassNullableOfDateTimeToDynamicFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfDateTimeToDynamic( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(DateTime.parse(k), e), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfDateTimeToDynamicToJson( - SimpleClassNullableOfDateTimeToDynamic instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toIso8601String(), e)), - }; + SimpleClassNullableOfDateTimeToDynamic instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toIso8601String(), e)), +}; SimpleClassOfDynamicToDynamic _$SimpleClassOfDynamicToDynamicFromJson( - Map<String, dynamic> json) => - SimpleClassOfDynamicToDynamic( - json['value'] as Map<String, dynamic>, - ); + Map<String, dynamic> json, +) => SimpleClassOfDynamicToDynamic(json['value'] as Map<String, dynamic>); Map<String, dynamic> _$SimpleClassOfDynamicToDynamicToJson( - SimpleClassOfDynamicToDynamic instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassOfDynamicToDynamic instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassNullableOfDynamicToDynamic - _$SimpleClassNullableOfDynamicToDynamicFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDynamicToDynamic( - json['value'] as Map<String, dynamic>?, - ); +_$SimpleClassNullableOfDynamicToDynamicFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfDynamicToDynamic( + json['value'] as Map<String, dynamic>?, + ); Map<String, dynamic> _$SimpleClassNullableOfDynamicToDynamicToJson( - SimpleClassNullableOfDynamicToDynamic instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassNullableOfDynamicToDynamic instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassOfEnumTypeToDynamic _$SimpleClassOfEnumTypeToDynamicFromJson( - Map<String, dynamic> json) => - SimpleClassOfEnumTypeToDynamic( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfEnumTypeToDynamic( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e), + ), +); Map<String, dynamic> _$SimpleClassOfEnumTypeToDynamicToJson( - SimpleClassOfEnumTypeToDynamic instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), - }; + SimpleClassOfEnumTypeToDynamic instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), +}; SimpleClassNullableOfEnumTypeToDynamic - _$SimpleClassNullableOfEnumTypeToDynamicFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfEnumTypeToDynamic( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e), - ), - ); +_$SimpleClassNullableOfEnumTypeToDynamicFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfEnumTypeToDynamic( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfEnumTypeToDynamicToJson( - SimpleClassNullableOfEnumTypeToDynamic instance) => - <String, dynamic>{ - 'value': - instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), - }; + SimpleClassNullableOfEnumTypeToDynamic instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), +}; SimpleClassOfIntToDynamic _$SimpleClassOfIntToDynamicFromJson( - Map<String, dynamic> json) => - SimpleClassOfIntToDynamic( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(int.parse(k), e), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfIntToDynamic( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(int.parse(k), e), + ), +); Map<String, dynamic> _$SimpleClassOfIntToDynamicToJson( - SimpleClassOfIntToDynamic instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassOfIntToDynamic instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassNullableOfIntToDynamic _$SimpleClassNullableOfIntToDynamicFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfIntToDynamic( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(int.parse(k), e), - ), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfIntToDynamic( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(int.parse(k), e), + ), +); Map<String, dynamic> _$SimpleClassNullableOfIntToDynamicToJson( - SimpleClassNullableOfIntToDynamic instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassNullableOfIntToDynamic instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassOfObjectToDynamic _$SimpleClassOfObjectToDynamicFromJson( - Map<String, dynamic> json) => - SimpleClassOfObjectToDynamic( - json['value'] as Map<String, dynamic>, - ); + Map<String, dynamic> json, +) => SimpleClassOfObjectToDynamic(json['value'] as Map<String, dynamic>); Map<String, dynamic> _$SimpleClassOfObjectToDynamicToJson( - SimpleClassOfObjectToDynamic instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassOfObjectToDynamic instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassNullableOfObjectToDynamic - _$SimpleClassNullableOfObjectToDynamicFromJson(Map<String, dynamic> json) => - SimpleClassNullableOfObjectToDynamic( - json['value'] as Map<String, dynamic>?, - ); +_$SimpleClassNullableOfObjectToDynamicFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfObjectToDynamic( + json['value'] as Map<String, dynamic>?, + ); Map<String, dynamic> _$SimpleClassNullableOfObjectToDynamicToJson( - SimpleClassNullableOfObjectToDynamic instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassNullableOfObjectToDynamic instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassOfStringToDynamic _$SimpleClassOfStringToDynamicFromJson( - Map<String, dynamic> json) => - SimpleClassOfStringToDynamic( - json['value'] as Map<String, dynamic>, - ); + Map<String, dynamic> json, +) => SimpleClassOfStringToDynamic(json['value'] as Map<String, dynamic>); Map<String, dynamic> _$SimpleClassOfStringToDynamicToJson( - SimpleClassOfStringToDynamic instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassOfStringToDynamic instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassNullableOfStringToDynamic - _$SimpleClassNullableOfStringToDynamicFromJson(Map<String, dynamic> json) => - SimpleClassNullableOfStringToDynamic( - json['value'] as Map<String, dynamic>?, - ); +_$SimpleClassNullableOfStringToDynamicFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfStringToDynamic( + json['value'] as Map<String, dynamic>?, + ); Map<String, dynamic> _$SimpleClassNullableOfStringToDynamicToJson( - SimpleClassNullableOfStringToDynamic instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassNullableOfStringToDynamic instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassOfUriToDynamic _$SimpleClassOfUriToDynamicFromJson( - Map<String, dynamic> json) => - SimpleClassOfUriToDynamic( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(Uri.parse(k), e), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfUriToDynamic( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(Uri.parse(k), e), + ), +); Map<String, dynamic> _$SimpleClassOfUriToDynamicToJson( - SimpleClassOfUriToDynamic instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassOfUriToDynamic instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassNullableOfUriToDynamic _$SimpleClassNullableOfUriToDynamicFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfUriToDynamic( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(Uri.parse(k), e), - ), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfUriToDynamic( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(Uri.parse(k), e), + ), +); Map<String, dynamic> _$SimpleClassNullableOfUriToDynamicToJson( - SimpleClassNullableOfUriToDynamic instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassNullableOfUriToDynamic instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassOfBigIntToEnumType _$SimpleClassOfBigIntToEnumTypeFromJson( - Map<String, dynamic> json) => - SimpleClassOfBigIntToEnumType( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(BigInt.parse(k), $enumDecode(_$EnumTypeEnumMap, e)), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfBigIntToEnumType( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(BigInt.parse(k), $enumDecode(_$EnumTypeEnumMap, e)), + ), +); Map<String, dynamic> _$SimpleClassOfBigIntToEnumTypeToJson( - SimpleClassOfBigIntToEnumType instance) => - <String, dynamic>{ - 'value': instance.value - .map((k, e) => MapEntry(k.toString(), _$EnumTypeEnumMap[e]!)), - }; + SimpleClassOfBigIntToEnumType instance, +) => <String, dynamic>{ + 'value': instance.value.map( + (k, e) => MapEntry(k.toString(), _$EnumTypeEnumMap[e]!), + ), +}; SimpleClassNullableOfBigIntToEnumType - _$SimpleClassNullableOfBigIntToEnumTypeFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfBigIntToEnumType( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => - MapEntry(BigInt.parse(k), $enumDecode(_$EnumTypeEnumMap, e)), - ), - ); +_$SimpleClassNullableOfBigIntToEnumTypeFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfBigIntToEnumType( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(BigInt.parse(k), $enumDecode(_$EnumTypeEnumMap, e)), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfBigIntToEnumTypeToJson( - SimpleClassNullableOfBigIntToEnumType instance) => - <String, dynamic>{ - 'value': instance.value - ?.map((k, e) => MapEntry(k.toString(), _$EnumTypeEnumMap[e]!)), - }; + SimpleClassNullableOfBigIntToEnumType instance, +) => <String, dynamic>{ + 'value': instance.value?.map( + (k, e) => MapEntry(k.toString(), _$EnumTypeEnumMap[e]!), + ), +}; SimpleClassOfDateTimeToEnumType _$SimpleClassOfDateTimeToEnumTypeFromJson( - Map<String, dynamic> json) => - SimpleClassOfDateTimeToEnumType( - (json['value'] as Map<String, dynamic>).map( - (k, e) => - MapEntry(DateTime.parse(k), $enumDecode(_$EnumTypeEnumMap, e)), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfDateTimeToEnumType( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(DateTime.parse(k), $enumDecode(_$EnumTypeEnumMap, e)), + ), +); Map<String, dynamic> _$SimpleClassOfDateTimeToEnumTypeToJson( - SimpleClassOfDateTimeToEnumType instance) => - <String, dynamic>{ - 'value': instance.value - .map((k, e) => MapEntry(k.toIso8601String(), _$EnumTypeEnumMap[e]!)), - }; + SimpleClassOfDateTimeToEnumType instance, +) => <String, dynamic>{ + 'value': instance.value.map( + (k, e) => MapEntry(k.toIso8601String(), _$EnumTypeEnumMap[e]!), + ), +}; SimpleClassNullableOfDateTimeToEnumType - _$SimpleClassNullableOfDateTimeToEnumTypeFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDateTimeToEnumType( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => - MapEntry(DateTime.parse(k), $enumDecode(_$EnumTypeEnumMap, e)), - ), - ); +_$SimpleClassNullableOfDateTimeToEnumTypeFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfDateTimeToEnumType( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => + MapEntry(DateTime.parse(k), $enumDecode(_$EnumTypeEnumMap, e)), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfDateTimeToEnumTypeToJson( - SimpleClassNullableOfDateTimeToEnumType instance) => - <String, dynamic>{ - 'value': instance.value - ?.map((k, e) => MapEntry(k.toIso8601String(), _$EnumTypeEnumMap[e]!)), - }; + SimpleClassNullableOfDateTimeToEnumType instance, +) => <String, dynamic>{ + 'value': instance.value?.map( + (k, e) => MapEntry(k.toIso8601String(), _$EnumTypeEnumMap[e]!), + ), +}; SimpleClassOfDynamicToEnumType _$SimpleClassOfDynamicToEnumTypeFromJson( - Map<String, dynamic> json) => - SimpleClassOfDynamicToEnumType( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(k, $enumDecode(_$EnumTypeEnumMap, e)), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfDynamicToEnumType( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(k, $enumDecode(_$EnumTypeEnumMap, e)), + ), +); Map<String, dynamic> _$SimpleClassOfDynamicToEnumTypeToJson( - SimpleClassOfDynamicToEnumType instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k, _$EnumTypeEnumMap[e]!)), - }; + SimpleClassOfDynamicToEnumType instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k, _$EnumTypeEnumMap[e]!)), +}; SimpleClassNullableOfDynamicToEnumType - _$SimpleClassNullableOfDynamicToEnumTypeFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDynamicToEnumType( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, $enumDecode(_$EnumTypeEnumMap, e)), - ), - ); +_$SimpleClassNullableOfDynamicToEnumTypeFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfDynamicToEnumType( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, $enumDecode(_$EnumTypeEnumMap, e)), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfDynamicToEnumTypeToJson( - SimpleClassNullableOfDynamicToEnumType instance) => - <String, dynamic>{ - 'value': - instance.value?.map((k, e) => MapEntry(k, _$EnumTypeEnumMap[e]!)), - }; + SimpleClassNullableOfDynamicToEnumType instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k, _$EnumTypeEnumMap[e]!)), +}; SimpleClassOfEnumTypeToEnumType _$SimpleClassOfEnumTypeToEnumTypeFromJson( - Map<String, dynamic> json) => - SimpleClassOfEnumTypeToEnumType( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), - $enumDecode(_$EnumTypeEnumMap, e)), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfEnumTypeToEnumType( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry( + $enumDecode(_$EnumTypeEnumMap, k), + $enumDecode(_$EnumTypeEnumMap, e), + ), + ), +); Map<String, dynamic> _$SimpleClassOfEnumTypeToEnumTypeToJson( - SimpleClassOfEnumTypeToEnumType instance) => - <String, dynamic>{ - 'value': instance.value.map( - (k, e) => MapEntry(_$EnumTypeEnumMap[k]!, _$EnumTypeEnumMap[e]!)), - }; + SimpleClassOfEnumTypeToEnumType instance, +) => <String, dynamic>{ + 'value': instance.value.map( + (k, e) => MapEntry(_$EnumTypeEnumMap[k]!, _$EnumTypeEnumMap[e]!), + ), +}; SimpleClassNullableOfEnumTypeToEnumType - _$SimpleClassNullableOfEnumTypeToEnumTypeFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfEnumTypeToEnumType( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), - $enumDecode(_$EnumTypeEnumMap, e)), - ), - ); +_$SimpleClassNullableOfEnumTypeToEnumTypeFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfEnumTypeToEnumType( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry( + $enumDecode(_$EnumTypeEnumMap, k), + $enumDecode(_$EnumTypeEnumMap, e), + ), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfEnumTypeToEnumTypeToJson( - SimpleClassNullableOfEnumTypeToEnumType instance) => - <String, dynamic>{ - 'value': instance.value?.map( - (k, e) => MapEntry(_$EnumTypeEnumMap[k]!, _$EnumTypeEnumMap[e]!)), - }; + SimpleClassNullableOfEnumTypeToEnumType instance, +) => <String, dynamic>{ + 'value': instance.value?.map( + (k, e) => MapEntry(_$EnumTypeEnumMap[k]!, _$EnumTypeEnumMap[e]!), + ), +}; SimpleClassOfIntToEnumType _$SimpleClassOfIntToEnumTypeFromJson( - Map<String, dynamic> json) => - SimpleClassOfIntToEnumType( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(int.parse(k), $enumDecode(_$EnumTypeEnumMap, e)), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfIntToEnumType( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(int.parse(k), $enumDecode(_$EnumTypeEnumMap, e)), + ), +); Map<String, dynamic> _$SimpleClassOfIntToEnumTypeToJson( - SimpleClassOfIntToEnumType instance) => - <String, dynamic>{ - 'value': instance.value - .map((k, e) => MapEntry(k.toString(), _$EnumTypeEnumMap[e]!)), - }; + SimpleClassOfIntToEnumType instance, +) => <String, dynamic>{ + 'value': instance.value.map( + (k, e) => MapEntry(k.toString(), _$EnumTypeEnumMap[e]!), + ), +}; SimpleClassNullableOfIntToEnumType _$SimpleClassNullableOfIntToEnumTypeFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfIntToEnumType( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(int.parse(k), $enumDecode(_$EnumTypeEnumMap, e)), - ), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfIntToEnumType( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(int.parse(k), $enumDecode(_$EnumTypeEnumMap, e)), + ), +); Map<String, dynamic> _$SimpleClassNullableOfIntToEnumTypeToJson( - SimpleClassNullableOfIntToEnumType instance) => - <String, dynamic>{ - 'value': instance.value - ?.map((k, e) => MapEntry(k.toString(), _$EnumTypeEnumMap[e]!)), - }; + SimpleClassNullableOfIntToEnumType instance, +) => <String, dynamic>{ + 'value': instance.value?.map( + (k, e) => MapEntry(k.toString(), _$EnumTypeEnumMap[e]!), + ), +}; SimpleClassOfObjectToEnumType _$SimpleClassOfObjectToEnumTypeFromJson( - Map<String, dynamic> json) => - SimpleClassOfObjectToEnumType( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(k, $enumDecode(_$EnumTypeEnumMap, e)), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfObjectToEnumType( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(k, $enumDecode(_$EnumTypeEnumMap, e)), + ), +); Map<String, dynamic> _$SimpleClassOfObjectToEnumTypeToJson( - SimpleClassOfObjectToEnumType instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k, _$EnumTypeEnumMap[e]!)), - }; + SimpleClassOfObjectToEnumType instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k, _$EnumTypeEnumMap[e]!)), +}; SimpleClassNullableOfObjectToEnumType - _$SimpleClassNullableOfObjectToEnumTypeFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfObjectToEnumType( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, $enumDecode(_$EnumTypeEnumMap, e)), - ), - ); +_$SimpleClassNullableOfObjectToEnumTypeFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfObjectToEnumType( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, $enumDecode(_$EnumTypeEnumMap, e)), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfObjectToEnumTypeToJson( - SimpleClassNullableOfObjectToEnumType instance) => - <String, dynamic>{ - 'value': - instance.value?.map((k, e) => MapEntry(k, _$EnumTypeEnumMap[e]!)), - }; + SimpleClassNullableOfObjectToEnumType instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k, _$EnumTypeEnumMap[e]!)), +}; SimpleClassOfStringToEnumType _$SimpleClassOfStringToEnumTypeFromJson( - Map<String, dynamic> json) => - SimpleClassOfStringToEnumType( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(k, $enumDecode(_$EnumTypeEnumMap, e)), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfStringToEnumType( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(k, $enumDecode(_$EnumTypeEnumMap, e)), + ), +); Map<String, dynamic> _$SimpleClassOfStringToEnumTypeToJson( - SimpleClassOfStringToEnumType instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k, _$EnumTypeEnumMap[e]!)), - }; + SimpleClassOfStringToEnumType instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k, _$EnumTypeEnumMap[e]!)), +}; SimpleClassNullableOfStringToEnumType - _$SimpleClassNullableOfStringToEnumTypeFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfStringToEnumType( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, $enumDecode(_$EnumTypeEnumMap, e)), - ), - ); +_$SimpleClassNullableOfStringToEnumTypeFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfStringToEnumType( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, $enumDecode(_$EnumTypeEnumMap, e)), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfStringToEnumTypeToJson( - SimpleClassNullableOfStringToEnumType instance) => - <String, dynamic>{ - 'value': - instance.value?.map((k, e) => MapEntry(k, _$EnumTypeEnumMap[e]!)), - }; + SimpleClassNullableOfStringToEnumType instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k, _$EnumTypeEnumMap[e]!)), +}; SimpleClassOfUriToEnumType _$SimpleClassOfUriToEnumTypeFromJson( - Map<String, dynamic> json) => - SimpleClassOfUriToEnumType( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(Uri.parse(k), $enumDecode(_$EnumTypeEnumMap, e)), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfUriToEnumType( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(Uri.parse(k), $enumDecode(_$EnumTypeEnumMap, e)), + ), +); Map<String, dynamic> _$SimpleClassOfUriToEnumTypeToJson( - SimpleClassOfUriToEnumType instance) => - <String, dynamic>{ - 'value': instance.value - .map((k, e) => MapEntry(k.toString(), _$EnumTypeEnumMap[e]!)), - }; + SimpleClassOfUriToEnumType instance, +) => <String, dynamic>{ + 'value': instance.value.map( + (k, e) => MapEntry(k.toString(), _$EnumTypeEnumMap[e]!), + ), +}; SimpleClassNullableOfUriToEnumType _$SimpleClassNullableOfUriToEnumTypeFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfUriToEnumType( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(Uri.parse(k), $enumDecode(_$EnumTypeEnumMap, e)), - ), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfUriToEnumType( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(Uri.parse(k), $enumDecode(_$EnumTypeEnumMap, e)), + ), +); Map<String, dynamic> _$SimpleClassNullableOfUriToEnumTypeToJson( - SimpleClassNullableOfUriToEnumType instance) => - <String, dynamic>{ - 'value': instance.value - ?.map((k, e) => MapEntry(k.toString(), _$EnumTypeEnumMap[e]!)), - }; + SimpleClassNullableOfUriToEnumType instance, +) => <String, dynamic>{ + 'value': instance.value?.map( + (k, e) => MapEntry(k.toString(), _$EnumTypeEnumMap[e]!), + ), +}; SimpleClassOfBigIntToEnumTypeNullable - _$SimpleClassOfBigIntToEnumTypeNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfBigIntToEnumTypeNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry( - BigInt.parse(k), $enumDecodeNullable(_$EnumTypeEnumMap, e)), - ), - ); +_$SimpleClassOfBigIntToEnumTypeNullableFromJson(Map<String, dynamic> json) => + SimpleClassOfBigIntToEnumTypeNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry( + BigInt.parse(k), + $enumDecodeNullable(_$EnumTypeEnumMap, e), + ), + ), + ); Map<String, dynamic> _$SimpleClassOfBigIntToEnumTypeNullableToJson( - SimpleClassOfBigIntToEnumTypeNullable instance) => - <String, dynamic>{ - 'value': instance.value - .map((k, e) => MapEntry(k.toString(), _$EnumTypeEnumMap[e])), - }; + SimpleClassOfBigIntToEnumTypeNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map( + (k, e) => MapEntry(k.toString(), _$EnumTypeEnumMap[e]), + ), +}; SimpleClassNullableOfBigIntToEnumTypeNullable - _$SimpleClassNullableOfBigIntToEnumTypeNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfBigIntToEnumTypeNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry( - BigInt.parse(k), $enumDecodeNullable(_$EnumTypeEnumMap, e)), - ), - ); +_$SimpleClassNullableOfBigIntToEnumTypeNullableFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfBigIntToEnumTypeNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => + MapEntry(BigInt.parse(k), $enumDecodeNullable(_$EnumTypeEnumMap, e)), + ), +); Map<String, dynamic> _$SimpleClassNullableOfBigIntToEnumTypeNullableToJson( - SimpleClassNullableOfBigIntToEnumTypeNullable instance) => - <String, dynamic>{ - 'value': instance.value - ?.map((k, e) => MapEntry(k.toString(), _$EnumTypeEnumMap[e])), - }; + SimpleClassNullableOfBigIntToEnumTypeNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map( + (k, e) => MapEntry(k.toString(), _$EnumTypeEnumMap[e]), + ), +}; SimpleClassOfDateTimeToEnumTypeNullable - _$SimpleClassOfDateTimeToEnumTypeNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfDateTimeToEnumTypeNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry( - DateTime.parse(k), $enumDecodeNullable(_$EnumTypeEnumMap, e)), - ), - ); +_$SimpleClassOfDateTimeToEnumTypeNullableFromJson(Map<String, dynamic> json) => + SimpleClassOfDateTimeToEnumTypeNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry( + DateTime.parse(k), + $enumDecodeNullable(_$EnumTypeEnumMap, e), + ), + ), + ); Map<String, dynamic> _$SimpleClassOfDateTimeToEnumTypeNullableToJson( - SimpleClassOfDateTimeToEnumTypeNullable instance) => - <String, dynamic>{ - 'value': instance.value - .map((k, e) => MapEntry(k.toIso8601String(), _$EnumTypeEnumMap[e])), - }; + SimpleClassOfDateTimeToEnumTypeNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map( + (k, e) => MapEntry(k.toIso8601String(), _$EnumTypeEnumMap[e]), + ), +}; SimpleClassNullableOfDateTimeToEnumTypeNullable - _$SimpleClassNullableOfDateTimeToEnumTypeNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDateTimeToEnumTypeNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry( - DateTime.parse(k), $enumDecodeNullable(_$EnumTypeEnumMap, e)), - ), - ); +_$SimpleClassNullableOfDateTimeToEnumTypeNullableFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfDateTimeToEnumTypeNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => + MapEntry(DateTime.parse(k), $enumDecodeNullable(_$EnumTypeEnumMap, e)), + ), +); Map<String, dynamic> _$SimpleClassNullableOfDateTimeToEnumTypeNullableToJson( - SimpleClassNullableOfDateTimeToEnumTypeNullable instance) => - <String, dynamic>{ - 'value': instance.value - ?.map((k, e) => MapEntry(k.toIso8601String(), _$EnumTypeEnumMap[e])), - }; + SimpleClassNullableOfDateTimeToEnumTypeNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map( + (k, e) => MapEntry(k.toIso8601String(), _$EnumTypeEnumMap[e]), + ), +}; SimpleClassOfDynamicToEnumTypeNullable - _$SimpleClassOfDynamicToEnumTypeNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfDynamicToEnumTypeNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(k, $enumDecodeNullable(_$EnumTypeEnumMap, e)), - ), - ); +_$SimpleClassOfDynamicToEnumTypeNullableFromJson(Map<String, dynamic> json) => + SimpleClassOfDynamicToEnumTypeNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(k, $enumDecodeNullable(_$EnumTypeEnumMap, e)), + ), + ); Map<String, dynamic> _$SimpleClassOfDynamicToEnumTypeNullableToJson( - SimpleClassOfDynamicToEnumTypeNullable instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k, _$EnumTypeEnumMap[e])), - }; + SimpleClassOfDynamicToEnumTypeNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k, _$EnumTypeEnumMap[e])), +}; SimpleClassNullableOfDynamicToEnumTypeNullable - _$SimpleClassNullableOfDynamicToEnumTypeNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDynamicToEnumTypeNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, $enumDecodeNullable(_$EnumTypeEnumMap, e)), - ), - ); +_$SimpleClassNullableOfDynamicToEnumTypeNullableFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfDynamicToEnumTypeNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, $enumDecodeNullable(_$EnumTypeEnumMap, e)), + ), +); Map<String, dynamic> _$SimpleClassNullableOfDynamicToEnumTypeNullableToJson( - SimpleClassNullableOfDynamicToEnumTypeNullable instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k, _$EnumTypeEnumMap[e])), - }; + SimpleClassNullableOfDynamicToEnumTypeNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k, _$EnumTypeEnumMap[e])), +}; SimpleClassOfEnumTypeToEnumTypeNullable - _$SimpleClassOfEnumTypeToEnumTypeNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfEnumTypeToEnumTypeNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), - $enumDecodeNullable(_$EnumTypeEnumMap, e)), - ), - ); +_$SimpleClassOfEnumTypeToEnumTypeNullableFromJson(Map<String, dynamic> json) => + SimpleClassOfEnumTypeToEnumTypeNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry( + $enumDecode(_$EnumTypeEnumMap, k), + $enumDecodeNullable(_$EnumTypeEnumMap, e), + ), + ), + ); Map<String, dynamic> _$SimpleClassOfEnumTypeToEnumTypeNullableToJson( - SimpleClassOfEnumTypeToEnumTypeNullable instance) => - <String, dynamic>{ - 'value': instance.value - .map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, _$EnumTypeEnumMap[e])), - }; + SimpleClassOfEnumTypeToEnumTypeNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map( + (k, e) => MapEntry(_$EnumTypeEnumMap[k]!, _$EnumTypeEnumMap[e]), + ), +}; SimpleClassNullableOfEnumTypeToEnumTypeNullable - _$SimpleClassNullableOfEnumTypeToEnumTypeNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfEnumTypeToEnumTypeNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), - $enumDecodeNullable(_$EnumTypeEnumMap, e)), - ), - ); +_$SimpleClassNullableOfEnumTypeToEnumTypeNullableFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfEnumTypeToEnumTypeNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry( + $enumDecode(_$EnumTypeEnumMap, k), + $enumDecodeNullable(_$EnumTypeEnumMap, e), + ), + ), +); Map<String, dynamic> _$SimpleClassNullableOfEnumTypeToEnumTypeNullableToJson( - SimpleClassNullableOfEnumTypeToEnumTypeNullable instance) => - <String, dynamic>{ - 'value': instance.value?.map( - (k, e) => MapEntry(_$EnumTypeEnumMap[k]!, _$EnumTypeEnumMap[e])), - }; + SimpleClassNullableOfEnumTypeToEnumTypeNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map( + (k, e) => MapEntry(_$EnumTypeEnumMap[k]!, _$EnumTypeEnumMap[e]), + ), +}; SimpleClassOfIntToEnumTypeNullable _$SimpleClassOfIntToEnumTypeNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfIntToEnumTypeNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => - MapEntry(int.parse(k), $enumDecodeNullable(_$EnumTypeEnumMap, e)), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfIntToEnumTypeNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(int.parse(k), $enumDecodeNullable(_$EnumTypeEnumMap, e)), + ), +); Map<String, dynamic> _$SimpleClassOfIntToEnumTypeNullableToJson( - SimpleClassOfIntToEnumTypeNullable instance) => - <String, dynamic>{ - 'value': instance.value - .map((k, e) => MapEntry(k.toString(), _$EnumTypeEnumMap[e])), - }; + SimpleClassOfIntToEnumTypeNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map( + (k, e) => MapEntry(k.toString(), _$EnumTypeEnumMap[e]), + ), +}; SimpleClassNullableOfIntToEnumTypeNullable - _$SimpleClassNullableOfIntToEnumTypeNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfIntToEnumTypeNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry( - int.parse(k), $enumDecodeNullable(_$EnumTypeEnumMap, e)), - ), - ); +_$SimpleClassNullableOfIntToEnumTypeNullableFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfIntToEnumTypeNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(int.parse(k), $enumDecodeNullable(_$EnumTypeEnumMap, e)), + ), +); Map<String, dynamic> _$SimpleClassNullableOfIntToEnumTypeNullableToJson( - SimpleClassNullableOfIntToEnumTypeNullable instance) => - <String, dynamic>{ - 'value': instance.value - ?.map((k, e) => MapEntry(k.toString(), _$EnumTypeEnumMap[e])), - }; + SimpleClassNullableOfIntToEnumTypeNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map( + (k, e) => MapEntry(k.toString(), _$EnumTypeEnumMap[e]), + ), +}; SimpleClassOfObjectToEnumTypeNullable - _$SimpleClassOfObjectToEnumTypeNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfObjectToEnumTypeNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(k, $enumDecodeNullable(_$EnumTypeEnumMap, e)), - ), - ); +_$SimpleClassOfObjectToEnumTypeNullableFromJson(Map<String, dynamic> json) => + SimpleClassOfObjectToEnumTypeNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(k, $enumDecodeNullable(_$EnumTypeEnumMap, e)), + ), + ); Map<String, dynamic> _$SimpleClassOfObjectToEnumTypeNullableToJson( - SimpleClassOfObjectToEnumTypeNullable instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k, _$EnumTypeEnumMap[e])), - }; + SimpleClassOfObjectToEnumTypeNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k, _$EnumTypeEnumMap[e])), +}; SimpleClassNullableOfObjectToEnumTypeNullable - _$SimpleClassNullableOfObjectToEnumTypeNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfObjectToEnumTypeNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, $enumDecodeNullable(_$EnumTypeEnumMap, e)), - ), - ); +_$SimpleClassNullableOfObjectToEnumTypeNullableFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfObjectToEnumTypeNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, $enumDecodeNullable(_$EnumTypeEnumMap, e)), + ), +); Map<String, dynamic> _$SimpleClassNullableOfObjectToEnumTypeNullableToJson( - SimpleClassNullableOfObjectToEnumTypeNullable instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k, _$EnumTypeEnumMap[e])), - }; + SimpleClassNullableOfObjectToEnumTypeNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k, _$EnumTypeEnumMap[e])), +}; SimpleClassOfStringToEnumTypeNullable - _$SimpleClassOfStringToEnumTypeNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfStringToEnumTypeNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(k, $enumDecodeNullable(_$EnumTypeEnumMap, e)), - ), - ); +_$SimpleClassOfStringToEnumTypeNullableFromJson(Map<String, dynamic> json) => + SimpleClassOfStringToEnumTypeNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(k, $enumDecodeNullable(_$EnumTypeEnumMap, e)), + ), + ); Map<String, dynamic> _$SimpleClassOfStringToEnumTypeNullableToJson( - SimpleClassOfStringToEnumTypeNullable instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k, _$EnumTypeEnumMap[e])), - }; + SimpleClassOfStringToEnumTypeNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k, _$EnumTypeEnumMap[e])), +}; SimpleClassNullableOfStringToEnumTypeNullable - _$SimpleClassNullableOfStringToEnumTypeNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfStringToEnumTypeNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, $enumDecodeNullable(_$EnumTypeEnumMap, e)), - ), - ); +_$SimpleClassNullableOfStringToEnumTypeNullableFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfStringToEnumTypeNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, $enumDecodeNullable(_$EnumTypeEnumMap, e)), + ), +); Map<String, dynamic> _$SimpleClassNullableOfStringToEnumTypeNullableToJson( - SimpleClassNullableOfStringToEnumTypeNullable instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k, _$EnumTypeEnumMap[e])), - }; + SimpleClassNullableOfStringToEnumTypeNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k, _$EnumTypeEnumMap[e])), +}; SimpleClassOfUriToEnumTypeNullable _$SimpleClassOfUriToEnumTypeNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfUriToEnumTypeNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => - MapEntry(Uri.parse(k), $enumDecodeNullable(_$EnumTypeEnumMap, e)), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfUriToEnumTypeNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(Uri.parse(k), $enumDecodeNullable(_$EnumTypeEnumMap, e)), + ), +); Map<String, dynamic> _$SimpleClassOfUriToEnumTypeNullableToJson( - SimpleClassOfUriToEnumTypeNullable instance) => - <String, dynamic>{ - 'value': instance.value - .map((k, e) => MapEntry(k.toString(), _$EnumTypeEnumMap[e])), - }; + SimpleClassOfUriToEnumTypeNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map( + (k, e) => MapEntry(k.toString(), _$EnumTypeEnumMap[e]), + ), +}; SimpleClassNullableOfUriToEnumTypeNullable - _$SimpleClassNullableOfUriToEnumTypeNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfUriToEnumTypeNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry( - Uri.parse(k), $enumDecodeNullable(_$EnumTypeEnumMap, e)), - ), - ); +_$SimpleClassNullableOfUriToEnumTypeNullableFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfUriToEnumTypeNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(Uri.parse(k), $enumDecodeNullable(_$EnumTypeEnumMap, e)), + ), +); Map<String, dynamic> _$SimpleClassNullableOfUriToEnumTypeNullableToJson( - SimpleClassNullableOfUriToEnumTypeNullable instance) => - <String, dynamic>{ - 'value': instance.value - ?.map((k, e) => MapEntry(k.toString(), _$EnumTypeEnumMap[e])), - }; + SimpleClassNullableOfUriToEnumTypeNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map( + (k, e) => MapEntry(k.toString(), _$EnumTypeEnumMap[e]), + ), +}; SimpleClassOfBigIntToFromJsonDynamicParam - _$SimpleClassOfBigIntToFromJsonDynamicParamFromJson( - Map<String, dynamic> json) => - SimpleClassOfBigIntToFromJsonDynamicParam( - (json['value'] as Map<String, dynamic>).map( - (k, e) => - MapEntry(BigInt.parse(k), FromJsonDynamicParam.fromJson(e)), - ), - ); +_$SimpleClassOfBigIntToFromJsonDynamicParamFromJson( + Map<String, dynamic> json, +) => SimpleClassOfBigIntToFromJsonDynamicParam( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(BigInt.parse(k), FromJsonDynamicParam.fromJson(e)), + ), +); Map<String, dynamic> _$SimpleClassOfBigIntToFromJsonDynamicParamToJson( - SimpleClassOfBigIntToFromJsonDynamicParam instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassOfBigIntToFromJsonDynamicParam instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassNullableOfBigIntToFromJsonDynamicParam - _$SimpleClassNullableOfBigIntToFromJsonDynamicParamFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfBigIntToFromJsonDynamicParam( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => - MapEntry(BigInt.parse(k), FromJsonDynamicParam.fromJson(e)), - ), - ); +_$SimpleClassNullableOfBigIntToFromJsonDynamicParamFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfBigIntToFromJsonDynamicParam( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(BigInt.parse(k), FromJsonDynamicParam.fromJson(e)), + ), +); Map<String, dynamic> _$SimpleClassNullableOfBigIntToFromJsonDynamicParamToJson( - SimpleClassNullableOfBigIntToFromJsonDynamicParam instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassNullableOfBigIntToFromJsonDynamicParam instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassOfDateTimeToFromJsonDynamicParam - _$SimpleClassOfDateTimeToFromJsonDynamicParamFromJson( - Map<String, dynamic> json) => - SimpleClassOfDateTimeToFromJsonDynamicParam( - (json['value'] as Map<String, dynamic>).map( - (k, e) => - MapEntry(DateTime.parse(k), FromJsonDynamicParam.fromJson(e)), - ), - ); +_$SimpleClassOfDateTimeToFromJsonDynamicParamFromJson( + Map<String, dynamic> json, +) => SimpleClassOfDateTimeToFromJsonDynamicParam( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(DateTime.parse(k), FromJsonDynamicParam.fromJson(e)), + ), +); Map<String, dynamic> _$SimpleClassOfDateTimeToFromJsonDynamicParamToJson( - SimpleClassOfDateTimeToFromJsonDynamicParam instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toIso8601String(), e)), - }; + SimpleClassOfDateTimeToFromJsonDynamicParam instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toIso8601String(), e)), +}; SimpleClassNullableOfDateTimeToFromJsonDynamicParam - _$SimpleClassNullableOfDateTimeToFromJsonDynamicParamFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDateTimeToFromJsonDynamicParam( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => - MapEntry(DateTime.parse(k), FromJsonDynamicParam.fromJson(e)), - ), - ); +_$SimpleClassNullableOfDateTimeToFromJsonDynamicParamFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfDateTimeToFromJsonDynamicParam( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(DateTime.parse(k), FromJsonDynamicParam.fromJson(e)), + ), +); Map<String, dynamic> - _$SimpleClassNullableOfDateTimeToFromJsonDynamicParamToJson( - SimpleClassNullableOfDateTimeToFromJsonDynamicParam instance) => - <String, dynamic>{ - 'value': - instance.value?.map((k, e) => MapEntry(k.toIso8601String(), e)), - }; +_$SimpleClassNullableOfDateTimeToFromJsonDynamicParamToJson( + SimpleClassNullableOfDateTimeToFromJsonDynamicParam instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toIso8601String(), e)), +}; SimpleClassOfDynamicToFromJsonDynamicParam - _$SimpleClassOfDynamicToFromJsonDynamicParamFromJson( - Map<String, dynamic> json) => - SimpleClassOfDynamicToFromJsonDynamicParam( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(k, FromJsonDynamicParam.fromJson(e)), - ), - ); +_$SimpleClassOfDynamicToFromJsonDynamicParamFromJson( + Map<String, dynamic> json, +) => SimpleClassOfDynamicToFromJsonDynamicParam( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(k, FromJsonDynamicParam.fromJson(e)), + ), +); Map<String, dynamic> _$SimpleClassOfDynamicToFromJsonDynamicParamToJson( - SimpleClassOfDynamicToFromJsonDynamicParam instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassOfDynamicToFromJsonDynamicParam instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassNullableOfDynamicToFromJsonDynamicParam - _$SimpleClassNullableOfDynamicToFromJsonDynamicParamFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDynamicToFromJsonDynamicParam( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, FromJsonDynamicParam.fromJson(e)), - ), - ); +_$SimpleClassNullableOfDynamicToFromJsonDynamicParamFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfDynamicToFromJsonDynamicParam( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, FromJsonDynamicParam.fromJson(e)), + ), +); Map<String, dynamic> _$SimpleClassNullableOfDynamicToFromJsonDynamicParamToJson( - SimpleClassNullableOfDynamicToFromJsonDynamicParam instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassNullableOfDynamicToFromJsonDynamicParam instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassOfEnumTypeToFromJsonDynamicParam - _$SimpleClassOfEnumTypeToFromJsonDynamicParamFromJson( - Map<String, dynamic> json) => - SimpleClassOfEnumTypeToFromJsonDynamicParam( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), - FromJsonDynamicParam.fromJson(e)), - ), - ); +_$SimpleClassOfEnumTypeToFromJsonDynamicParamFromJson( + Map<String, dynamic> json, +) => SimpleClassOfEnumTypeToFromJsonDynamicParam( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry( + $enumDecode(_$EnumTypeEnumMap, k), + FromJsonDynamicParam.fromJson(e), + ), + ), +); Map<String, dynamic> _$SimpleClassOfEnumTypeToFromJsonDynamicParamToJson( - SimpleClassOfEnumTypeToFromJsonDynamicParam instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), - }; + SimpleClassOfEnumTypeToFromJsonDynamicParam instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), +}; SimpleClassNullableOfEnumTypeToFromJsonDynamicParam - _$SimpleClassNullableOfEnumTypeToFromJsonDynamicParamFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfEnumTypeToFromJsonDynamicParam( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), - FromJsonDynamicParam.fromJson(e)), - ), - ); +_$SimpleClassNullableOfEnumTypeToFromJsonDynamicParamFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfEnumTypeToFromJsonDynamicParam( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry( + $enumDecode(_$EnumTypeEnumMap, k), + FromJsonDynamicParam.fromJson(e), + ), + ), +); Map<String, dynamic> - _$SimpleClassNullableOfEnumTypeToFromJsonDynamicParamToJson( - SimpleClassNullableOfEnumTypeToFromJsonDynamicParam instance) => - <String, dynamic>{ - 'value': - instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), - }; +_$SimpleClassNullableOfEnumTypeToFromJsonDynamicParamToJson( + SimpleClassNullableOfEnumTypeToFromJsonDynamicParam instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), +}; SimpleClassOfIntToFromJsonDynamicParam - _$SimpleClassOfIntToFromJsonDynamicParamFromJson( - Map<String, dynamic> json) => - SimpleClassOfIntToFromJsonDynamicParam( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(int.parse(k), FromJsonDynamicParam.fromJson(e)), - ), - ); +_$SimpleClassOfIntToFromJsonDynamicParamFromJson(Map<String, dynamic> json) => + SimpleClassOfIntToFromJsonDynamicParam( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(int.parse(k), FromJsonDynamicParam.fromJson(e)), + ), + ); Map<String, dynamic> _$SimpleClassOfIntToFromJsonDynamicParamToJson( - SimpleClassOfIntToFromJsonDynamicParam instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassOfIntToFromJsonDynamicParam instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassNullableOfIntToFromJsonDynamicParam - _$SimpleClassNullableOfIntToFromJsonDynamicParamFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfIntToFromJsonDynamicParam( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(int.parse(k), FromJsonDynamicParam.fromJson(e)), - ), - ); +_$SimpleClassNullableOfIntToFromJsonDynamicParamFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfIntToFromJsonDynamicParam( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(int.parse(k), FromJsonDynamicParam.fromJson(e)), + ), +); Map<String, dynamic> _$SimpleClassNullableOfIntToFromJsonDynamicParamToJson( - SimpleClassNullableOfIntToFromJsonDynamicParam instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassNullableOfIntToFromJsonDynamicParam instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassOfObjectToFromJsonDynamicParam - _$SimpleClassOfObjectToFromJsonDynamicParamFromJson( - Map<String, dynamic> json) => - SimpleClassOfObjectToFromJsonDynamicParam( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(k, FromJsonDynamicParam.fromJson(e)), - ), - ); +_$SimpleClassOfObjectToFromJsonDynamicParamFromJson( + Map<String, dynamic> json, +) => SimpleClassOfObjectToFromJsonDynamicParam( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(k, FromJsonDynamicParam.fromJson(e)), + ), +); Map<String, dynamic> _$SimpleClassOfObjectToFromJsonDynamicParamToJson( - SimpleClassOfObjectToFromJsonDynamicParam instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassOfObjectToFromJsonDynamicParam instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassNullableOfObjectToFromJsonDynamicParam - _$SimpleClassNullableOfObjectToFromJsonDynamicParamFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfObjectToFromJsonDynamicParam( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, FromJsonDynamicParam.fromJson(e)), - ), - ); +_$SimpleClassNullableOfObjectToFromJsonDynamicParamFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfObjectToFromJsonDynamicParam( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, FromJsonDynamicParam.fromJson(e)), + ), +); Map<String, dynamic> _$SimpleClassNullableOfObjectToFromJsonDynamicParamToJson( - SimpleClassNullableOfObjectToFromJsonDynamicParam instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassNullableOfObjectToFromJsonDynamicParam instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassOfStringToFromJsonDynamicParam - _$SimpleClassOfStringToFromJsonDynamicParamFromJson( - Map<String, dynamic> json) => - SimpleClassOfStringToFromJsonDynamicParam( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(k, FromJsonDynamicParam.fromJson(e)), - ), - ); +_$SimpleClassOfStringToFromJsonDynamicParamFromJson( + Map<String, dynamic> json, +) => SimpleClassOfStringToFromJsonDynamicParam( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(k, FromJsonDynamicParam.fromJson(e)), + ), +); Map<String, dynamic> _$SimpleClassOfStringToFromJsonDynamicParamToJson( - SimpleClassOfStringToFromJsonDynamicParam instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassOfStringToFromJsonDynamicParam instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassNullableOfStringToFromJsonDynamicParam - _$SimpleClassNullableOfStringToFromJsonDynamicParamFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfStringToFromJsonDynamicParam( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, FromJsonDynamicParam.fromJson(e)), - ), - ); +_$SimpleClassNullableOfStringToFromJsonDynamicParamFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfStringToFromJsonDynamicParam( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, FromJsonDynamicParam.fromJson(e)), + ), +); Map<String, dynamic> _$SimpleClassNullableOfStringToFromJsonDynamicParamToJson( - SimpleClassNullableOfStringToFromJsonDynamicParam instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassNullableOfStringToFromJsonDynamicParam instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassOfUriToFromJsonDynamicParam - _$SimpleClassOfUriToFromJsonDynamicParamFromJson( - Map<String, dynamic> json) => - SimpleClassOfUriToFromJsonDynamicParam( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(Uri.parse(k), FromJsonDynamicParam.fromJson(e)), - ), - ); +_$SimpleClassOfUriToFromJsonDynamicParamFromJson(Map<String, dynamic> json) => + SimpleClassOfUriToFromJsonDynamicParam( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(Uri.parse(k), FromJsonDynamicParam.fromJson(e)), + ), + ); Map<String, dynamic> _$SimpleClassOfUriToFromJsonDynamicParamToJson( - SimpleClassOfUriToFromJsonDynamicParam instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassOfUriToFromJsonDynamicParam instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassNullableOfUriToFromJsonDynamicParam - _$SimpleClassNullableOfUriToFromJsonDynamicParamFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfUriToFromJsonDynamicParam( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(Uri.parse(k), FromJsonDynamicParam.fromJson(e)), - ), - ); +_$SimpleClassNullableOfUriToFromJsonDynamicParamFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfUriToFromJsonDynamicParam( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(Uri.parse(k), FromJsonDynamicParam.fromJson(e)), + ), +); Map<String, dynamic> _$SimpleClassNullableOfUriToFromJsonDynamicParamToJson( - SimpleClassNullableOfUriToFromJsonDynamicParam instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassNullableOfUriToFromJsonDynamicParam instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassOfBigIntToFromJsonNullableObjectParam - _$SimpleClassOfBigIntToFromJsonNullableObjectParamFromJson( - Map<String, dynamic> json) => - SimpleClassOfBigIntToFromJsonNullableObjectParam( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry( - BigInt.parse(k), FromJsonNullableObjectParam.fromJson(e)), - ), - ); +_$SimpleClassOfBigIntToFromJsonNullableObjectParamFromJson( + Map<String, dynamic> json, +) => SimpleClassOfBigIntToFromJsonNullableObjectParam( + (json['value'] as Map<String, dynamic>).map( + (k, e) => + MapEntry(BigInt.parse(k), FromJsonNullableObjectParam.fromJson(e)), + ), +); Map<String, dynamic> _$SimpleClassOfBigIntToFromJsonNullableObjectParamToJson( - SimpleClassOfBigIntToFromJsonNullableObjectParam instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassOfBigIntToFromJsonNullableObjectParam instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassNullableOfBigIntToFromJsonNullableObjectParam - _$SimpleClassNullableOfBigIntToFromJsonNullableObjectParamFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfBigIntToFromJsonNullableObjectParam( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry( - BigInt.parse(k), FromJsonNullableObjectParam.fromJson(e)), - ), - ); +_$SimpleClassNullableOfBigIntToFromJsonNullableObjectParamFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfBigIntToFromJsonNullableObjectParam( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => + MapEntry(BigInt.parse(k), FromJsonNullableObjectParam.fromJson(e)), + ), +); -Map<String, - dynamic> _$SimpleClassNullableOfBigIntToFromJsonNullableObjectParamToJson( - SimpleClassNullableOfBigIntToFromJsonNullableObjectParam instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - }; +Map<String, dynamic> +_$SimpleClassNullableOfBigIntToFromJsonNullableObjectParamToJson( + SimpleClassNullableOfBigIntToFromJsonNullableObjectParam instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassOfDateTimeToFromJsonNullableObjectParam - _$SimpleClassOfDateTimeToFromJsonNullableObjectParamFromJson( - Map<String, dynamic> json) => - SimpleClassOfDateTimeToFromJsonNullableObjectParam( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry( - DateTime.parse(k), FromJsonNullableObjectParam.fromJson(e)), - ), - ); +_$SimpleClassOfDateTimeToFromJsonNullableObjectParamFromJson( + Map<String, dynamic> json, +) => SimpleClassOfDateTimeToFromJsonNullableObjectParam( + (json['value'] as Map<String, dynamic>).map( + (k, e) => + MapEntry(DateTime.parse(k), FromJsonNullableObjectParam.fromJson(e)), + ), +); Map<String, dynamic> _$SimpleClassOfDateTimeToFromJsonNullableObjectParamToJson( - SimpleClassOfDateTimeToFromJsonNullableObjectParam instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toIso8601String(), e)), - }; + SimpleClassOfDateTimeToFromJsonNullableObjectParam instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toIso8601String(), e)), +}; SimpleClassNullableOfDateTimeToFromJsonNullableObjectParam - _$SimpleClassNullableOfDateTimeToFromJsonNullableObjectParamFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDateTimeToFromJsonNullableObjectParam( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry( - DateTime.parse(k), FromJsonNullableObjectParam.fromJson(e)), - ), - ); +_$SimpleClassNullableOfDateTimeToFromJsonNullableObjectParamFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfDateTimeToFromJsonNullableObjectParam( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => + MapEntry(DateTime.parse(k), FromJsonNullableObjectParam.fromJson(e)), + ), +); -Map<String, - dynamic> _$SimpleClassNullableOfDateTimeToFromJsonNullableObjectParamToJson( - SimpleClassNullableOfDateTimeToFromJsonNullableObjectParam instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toIso8601String(), e)), - }; +Map<String, dynamic> +_$SimpleClassNullableOfDateTimeToFromJsonNullableObjectParamToJson( + SimpleClassNullableOfDateTimeToFromJsonNullableObjectParam instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toIso8601String(), e)), +}; SimpleClassOfDynamicToFromJsonNullableObjectParam - _$SimpleClassOfDynamicToFromJsonNullableObjectParamFromJson( - Map<String, dynamic> json) => - SimpleClassOfDynamicToFromJsonNullableObjectParam( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(k, FromJsonNullableObjectParam.fromJson(e)), - ), - ); +_$SimpleClassOfDynamicToFromJsonNullableObjectParamFromJson( + Map<String, dynamic> json, +) => SimpleClassOfDynamicToFromJsonNullableObjectParam( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(k, FromJsonNullableObjectParam.fromJson(e)), + ), +); Map<String, dynamic> _$SimpleClassOfDynamicToFromJsonNullableObjectParamToJson( - SimpleClassOfDynamicToFromJsonNullableObjectParam instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassOfDynamicToFromJsonNullableObjectParam instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassNullableOfDynamicToFromJsonNullableObjectParam - _$SimpleClassNullableOfDynamicToFromJsonNullableObjectParamFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDynamicToFromJsonNullableObjectParam( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, FromJsonNullableObjectParam.fromJson(e)), - ), - ); +_$SimpleClassNullableOfDynamicToFromJsonNullableObjectParamFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfDynamicToFromJsonNullableObjectParam( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, FromJsonNullableObjectParam.fromJson(e)), + ), +); -Map<String, - dynamic> _$SimpleClassNullableOfDynamicToFromJsonNullableObjectParamToJson( - SimpleClassNullableOfDynamicToFromJsonNullableObjectParam instance) => - <String, dynamic>{ - 'value': instance.value, - }; +Map<String, dynamic> +_$SimpleClassNullableOfDynamicToFromJsonNullableObjectParamToJson( + SimpleClassNullableOfDynamicToFromJsonNullableObjectParam instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassOfEnumTypeToFromJsonNullableObjectParam - _$SimpleClassOfEnumTypeToFromJsonNullableObjectParamFromJson( - Map<String, dynamic> json) => - SimpleClassOfEnumTypeToFromJsonNullableObjectParam( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), - FromJsonNullableObjectParam.fromJson(e)), - ), - ); +_$SimpleClassOfEnumTypeToFromJsonNullableObjectParamFromJson( + Map<String, dynamic> json, +) => SimpleClassOfEnumTypeToFromJsonNullableObjectParam( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry( + $enumDecode(_$EnumTypeEnumMap, k), + FromJsonNullableObjectParam.fromJson(e), + ), + ), +); Map<String, dynamic> _$SimpleClassOfEnumTypeToFromJsonNullableObjectParamToJson( - SimpleClassOfEnumTypeToFromJsonNullableObjectParam instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), - }; + SimpleClassOfEnumTypeToFromJsonNullableObjectParam instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), +}; SimpleClassNullableOfEnumTypeToFromJsonNullableObjectParam - _$SimpleClassNullableOfEnumTypeToFromJsonNullableObjectParamFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfEnumTypeToFromJsonNullableObjectParam( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), - FromJsonNullableObjectParam.fromJson(e)), - ), - ); +_$SimpleClassNullableOfEnumTypeToFromJsonNullableObjectParamFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfEnumTypeToFromJsonNullableObjectParam( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry( + $enumDecode(_$EnumTypeEnumMap, k), + FromJsonNullableObjectParam.fromJson(e), + ), + ), +); -Map<String, - dynamic> _$SimpleClassNullableOfEnumTypeToFromJsonNullableObjectParamToJson( - SimpleClassNullableOfEnumTypeToFromJsonNullableObjectParam instance) => - <String, dynamic>{ - 'value': - instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), - }; +Map<String, dynamic> +_$SimpleClassNullableOfEnumTypeToFromJsonNullableObjectParamToJson( + SimpleClassNullableOfEnumTypeToFromJsonNullableObjectParam instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), +}; SimpleClassOfIntToFromJsonNullableObjectParam - _$SimpleClassOfIntToFromJsonNullableObjectParamFromJson( - Map<String, dynamic> json) => - SimpleClassOfIntToFromJsonNullableObjectParam( - (json['value'] as Map<String, dynamic>).map( - (k, e) => - MapEntry(int.parse(k), FromJsonNullableObjectParam.fromJson(e)), - ), - ); +_$SimpleClassOfIntToFromJsonNullableObjectParamFromJson( + Map<String, dynamic> json, +) => SimpleClassOfIntToFromJsonNullableObjectParam( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(int.parse(k), FromJsonNullableObjectParam.fromJson(e)), + ), +); Map<String, dynamic> _$SimpleClassOfIntToFromJsonNullableObjectParamToJson( - SimpleClassOfIntToFromJsonNullableObjectParam instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassOfIntToFromJsonNullableObjectParam instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassNullableOfIntToFromJsonNullableObjectParam - _$SimpleClassNullableOfIntToFromJsonNullableObjectParamFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfIntToFromJsonNullableObjectParam( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => - MapEntry(int.parse(k), FromJsonNullableObjectParam.fromJson(e)), - ), - ); +_$SimpleClassNullableOfIntToFromJsonNullableObjectParamFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfIntToFromJsonNullableObjectParam( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(int.parse(k), FromJsonNullableObjectParam.fromJson(e)), + ), +); Map<String, dynamic> - _$SimpleClassNullableOfIntToFromJsonNullableObjectParamToJson( - SimpleClassNullableOfIntToFromJsonNullableObjectParam instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - }; +_$SimpleClassNullableOfIntToFromJsonNullableObjectParamToJson( + SimpleClassNullableOfIntToFromJsonNullableObjectParam instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassOfObjectToFromJsonNullableObjectParam - _$SimpleClassOfObjectToFromJsonNullableObjectParamFromJson( - Map<String, dynamic> json) => - SimpleClassOfObjectToFromJsonNullableObjectParam( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(k, FromJsonNullableObjectParam.fromJson(e)), - ), - ); +_$SimpleClassOfObjectToFromJsonNullableObjectParamFromJson( + Map<String, dynamic> json, +) => SimpleClassOfObjectToFromJsonNullableObjectParam( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(k, FromJsonNullableObjectParam.fromJson(e)), + ), +); Map<String, dynamic> _$SimpleClassOfObjectToFromJsonNullableObjectParamToJson( - SimpleClassOfObjectToFromJsonNullableObjectParam instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassOfObjectToFromJsonNullableObjectParam instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassNullableOfObjectToFromJsonNullableObjectParam - _$SimpleClassNullableOfObjectToFromJsonNullableObjectParamFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfObjectToFromJsonNullableObjectParam( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, FromJsonNullableObjectParam.fromJson(e)), - ), - ); +_$SimpleClassNullableOfObjectToFromJsonNullableObjectParamFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfObjectToFromJsonNullableObjectParam( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, FromJsonNullableObjectParam.fromJson(e)), + ), +); -Map<String, - dynamic> _$SimpleClassNullableOfObjectToFromJsonNullableObjectParamToJson( - SimpleClassNullableOfObjectToFromJsonNullableObjectParam instance) => - <String, dynamic>{ - 'value': instance.value, - }; +Map<String, dynamic> +_$SimpleClassNullableOfObjectToFromJsonNullableObjectParamToJson( + SimpleClassNullableOfObjectToFromJsonNullableObjectParam instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassOfStringToFromJsonNullableObjectParam - _$SimpleClassOfStringToFromJsonNullableObjectParamFromJson( - Map<String, dynamic> json) => - SimpleClassOfStringToFromJsonNullableObjectParam( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(k, FromJsonNullableObjectParam.fromJson(e)), - ), - ); +_$SimpleClassOfStringToFromJsonNullableObjectParamFromJson( + Map<String, dynamic> json, +) => SimpleClassOfStringToFromJsonNullableObjectParam( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(k, FromJsonNullableObjectParam.fromJson(e)), + ), +); Map<String, dynamic> _$SimpleClassOfStringToFromJsonNullableObjectParamToJson( - SimpleClassOfStringToFromJsonNullableObjectParam instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassOfStringToFromJsonNullableObjectParam instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassNullableOfStringToFromJsonNullableObjectParam - _$SimpleClassNullableOfStringToFromJsonNullableObjectParamFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfStringToFromJsonNullableObjectParam( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, FromJsonNullableObjectParam.fromJson(e)), - ), - ); +_$SimpleClassNullableOfStringToFromJsonNullableObjectParamFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfStringToFromJsonNullableObjectParam( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, FromJsonNullableObjectParam.fromJson(e)), + ), +); -Map<String, - dynamic> _$SimpleClassNullableOfStringToFromJsonNullableObjectParamToJson( - SimpleClassNullableOfStringToFromJsonNullableObjectParam instance) => - <String, dynamic>{ - 'value': instance.value, - }; +Map<String, dynamic> +_$SimpleClassNullableOfStringToFromJsonNullableObjectParamToJson( + SimpleClassNullableOfStringToFromJsonNullableObjectParam instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassOfUriToFromJsonNullableObjectParam - _$SimpleClassOfUriToFromJsonNullableObjectParamFromJson( - Map<String, dynamic> json) => - SimpleClassOfUriToFromJsonNullableObjectParam( - (json['value'] as Map<String, dynamic>).map( - (k, e) => - MapEntry(Uri.parse(k), FromJsonNullableObjectParam.fromJson(e)), - ), - ); +_$SimpleClassOfUriToFromJsonNullableObjectParamFromJson( + Map<String, dynamic> json, +) => SimpleClassOfUriToFromJsonNullableObjectParam( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(Uri.parse(k), FromJsonNullableObjectParam.fromJson(e)), + ), +); Map<String, dynamic> _$SimpleClassOfUriToFromJsonNullableObjectParamToJson( - SimpleClassOfUriToFromJsonNullableObjectParam instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassOfUriToFromJsonNullableObjectParam instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassNullableOfUriToFromJsonNullableObjectParam - _$SimpleClassNullableOfUriToFromJsonNullableObjectParamFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfUriToFromJsonNullableObjectParam( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => - MapEntry(Uri.parse(k), FromJsonNullableObjectParam.fromJson(e)), - ), - ); +_$SimpleClassNullableOfUriToFromJsonNullableObjectParamFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfUriToFromJsonNullableObjectParam( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(Uri.parse(k), FromJsonNullableObjectParam.fromJson(e)), + ), +); Map<String, dynamic> - _$SimpleClassNullableOfUriToFromJsonNullableObjectParamToJson( - SimpleClassNullableOfUriToFromJsonNullableObjectParam instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - }; +_$SimpleClassNullableOfUriToFromJsonNullableObjectParamToJson( + SimpleClassNullableOfUriToFromJsonNullableObjectParam instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassOfBigIntToFromJsonObjectParam - _$SimpleClassOfBigIntToFromJsonObjectParamFromJson( - Map<String, dynamic> json) => - SimpleClassOfBigIntToFromJsonObjectParam( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry( - BigInt.parse(k), FromJsonObjectParam.fromJson(e as Object)), - ), - ); +_$SimpleClassOfBigIntToFromJsonObjectParamFromJson(Map<String, dynamic> json) => + SimpleClassOfBigIntToFromJsonObjectParam( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry( + BigInt.parse(k), + FromJsonObjectParam.fromJson(e as Object), + ), + ), + ); Map<String, dynamic> _$SimpleClassOfBigIntToFromJsonObjectParamToJson( - SimpleClassOfBigIntToFromJsonObjectParam instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassOfBigIntToFromJsonObjectParam instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassNullableOfBigIntToFromJsonObjectParam - _$SimpleClassNullableOfBigIntToFromJsonObjectParamFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfBigIntToFromJsonObjectParam( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry( - BigInt.parse(k), FromJsonObjectParam.fromJson(e as Object)), - ), - ); +_$SimpleClassNullableOfBigIntToFromJsonObjectParamFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfBigIntToFromJsonObjectParam( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => + MapEntry(BigInt.parse(k), FromJsonObjectParam.fromJson(e as Object)), + ), +); Map<String, dynamic> _$SimpleClassNullableOfBigIntToFromJsonObjectParamToJson( - SimpleClassNullableOfBigIntToFromJsonObjectParam instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassNullableOfBigIntToFromJsonObjectParam instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassOfDateTimeToFromJsonObjectParam - _$SimpleClassOfDateTimeToFromJsonObjectParamFromJson( - Map<String, dynamic> json) => - SimpleClassOfDateTimeToFromJsonObjectParam( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry( - DateTime.parse(k), FromJsonObjectParam.fromJson(e as Object)), - ), - ); +_$SimpleClassOfDateTimeToFromJsonObjectParamFromJson( + Map<String, dynamic> json, +) => SimpleClassOfDateTimeToFromJsonObjectParam( + (json['value'] as Map<String, dynamic>).map( + (k, e) => + MapEntry(DateTime.parse(k), FromJsonObjectParam.fromJson(e as Object)), + ), +); Map<String, dynamic> _$SimpleClassOfDateTimeToFromJsonObjectParamToJson( - SimpleClassOfDateTimeToFromJsonObjectParam instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toIso8601String(), e)), - }; + SimpleClassOfDateTimeToFromJsonObjectParam instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toIso8601String(), e)), +}; SimpleClassNullableOfDateTimeToFromJsonObjectParam - _$SimpleClassNullableOfDateTimeToFromJsonObjectParamFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDateTimeToFromJsonObjectParam( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry( - DateTime.parse(k), FromJsonObjectParam.fromJson(e as Object)), - ), - ); +_$SimpleClassNullableOfDateTimeToFromJsonObjectParamFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfDateTimeToFromJsonObjectParam( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => + MapEntry(DateTime.parse(k), FromJsonObjectParam.fromJson(e as Object)), + ), +); Map<String, dynamic> _$SimpleClassNullableOfDateTimeToFromJsonObjectParamToJson( - SimpleClassNullableOfDateTimeToFromJsonObjectParam instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toIso8601String(), e)), - }; + SimpleClassNullableOfDateTimeToFromJsonObjectParam instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toIso8601String(), e)), +}; SimpleClassOfDynamicToFromJsonObjectParam - _$SimpleClassOfDynamicToFromJsonObjectParamFromJson( - Map<String, dynamic> json) => - SimpleClassOfDynamicToFromJsonObjectParam( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(k, FromJsonObjectParam.fromJson(e as Object)), - ), - ); +_$SimpleClassOfDynamicToFromJsonObjectParamFromJson( + Map<String, dynamic> json, +) => SimpleClassOfDynamicToFromJsonObjectParam( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(k, FromJsonObjectParam.fromJson(e as Object)), + ), +); Map<String, dynamic> _$SimpleClassOfDynamicToFromJsonObjectParamToJson( - SimpleClassOfDynamicToFromJsonObjectParam instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassOfDynamicToFromJsonObjectParam instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassNullableOfDynamicToFromJsonObjectParam - _$SimpleClassNullableOfDynamicToFromJsonObjectParamFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDynamicToFromJsonObjectParam( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, FromJsonObjectParam.fromJson(e as Object)), - ), - ); +_$SimpleClassNullableOfDynamicToFromJsonObjectParamFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfDynamicToFromJsonObjectParam( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, FromJsonObjectParam.fromJson(e as Object)), + ), +); Map<String, dynamic> _$SimpleClassNullableOfDynamicToFromJsonObjectParamToJson( - SimpleClassNullableOfDynamicToFromJsonObjectParam instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassNullableOfDynamicToFromJsonObjectParam instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassOfEnumTypeToFromJsonObjectParam - _$SimpleClassOfEnumTypeToFromJsonObjectParamFromJson( - Map<String, dynamic> json) => - SimpleClassOfEnumTypeToFromJsonObjectParam( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), - FromJsonObjectParam.fromJson(e as Object)), - ), - ); +_$SimpleClassOfEnumTypeToFromJsonObjectParamFromJson( + Map<String, dynamic> json, +) => SimpleClassOfEnumTypeToFromJsonObjectParam( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry( + $enumDecode(_$EnumTypeEnumMap, k), + FromJsonObjectParam.fromJson(e as Object), + ), + ), +); Map<String, dynamic> _$SimpleClassOfEnumTypeToFromJsonObjectParamToJson( - SimpleClassOfEnumTypeToFromJsonObjectParam instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), - }; + SimpleClassOfEnumTypeToFromJsonObjectParam instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), +}; SimpleClassNullableOfEnumTypeToFromJsonObjectParam - _$SimpleClassNullableOfEnumTypeToFromJsonObjectParamFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfEnumTypeToFromJsonObjectParam( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), - FromJsonObjectParam.fromJson(e as Object)), - ), - ); +_$SimpleClassNullableOfEnumTypeToFromJsonObjectParamFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfEnumTypeToFromJsonObjectParam( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry( + $enumDecode(_$EnumTypeEnumMap, k), + FromJsonObjectParam.fromJson(e as Object), + ), + ), +); Map<String, dynamic> _$SimpleClassNullableOfEnumTypeToFromJsonObjectParamToJson( - SimpleClassNullableOfEnumTypeToFromJsonObjectParam instance) => - <String, dynamic>{ - 'value': - instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), - }; + SimpleClassNullableOfEnumTypeToFromJsonObjectParam instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), +}; SimpleClassOfIntToFromJsonObjectParam - _$SimpleClassOfIntToFromJsonObjectParamFromJson( - Map<String, dynamic> json) => - SimpleClassOfIntToFromJsonObjectParam( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry( - int.parse(k), FromJsonObjectParam.fromJson(e as Object)), - ), - ); +_$SimpleClassOfIntToFromJsonObjectParamFromJson(Map<String, dynamic> json) => + SimpleClassOfIntToFromJsonObjectParam( + (json['value'] as Map<String, dynamic>).map( + (k, e) => + MapEntry(int.parse(k), FromJsonObjectParam.fromJson(e as Object)), + ), + ); Map<String, dynamic> _$SimpleClassOfIntToFromJsonObjectParamToJson( - SimpleClassOfIntToFromJsonObjectParam instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassOfIntToFromJsonObjectParam instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassNullableOfIntToFromJsonObjectParam - _$SimpleClassNullableOfIntToFromJsonObjectParamFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfIntToFromJsonObjectParam( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry( - int.parse(k), FromJsonObjectParam.fromJson(e as Object)), - ), - ); +_$SimpleClassNullableOfIntToFromJsonObjectParamFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfIntToFromJsonObjectParam( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(int.parse(k), FromJsonObjectParam.fromJson(e as Object)), + ), +); Map<String, dynamic> _$SimpleClassNullableOfIntToFromJsonObjectParamToJson( - SimpleClassNullableOfIntToFromJsonObjectParam instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassNullableOfIntToFromJsonObjectParam instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassOfObjectToFromJsonObjectParam - _$SimpleClassOfObjectToFromJsonObjectParamFromJson( - Map<String, dynamic> json) => - SimpleClassOfObjectToFromJsonObjectParam( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(k, FromJsonObjectParam.fromJson(e as Object)), - ), - ); +_$SimpleClassOfObjectToFromJsonObjectParamFromJson(Map<String, dynamic> json) => + SimpleClassOfObjectToFromJsonObjectParam( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(k, FromJsonObjectParam.fromJson(e as Object)), + ), + ); Map<String, dynamic> _$SimpleClassOfObjectToFromJsonObjectParamToJson( - SimpleClassOfObjectToFromJsonObjectParam instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassOfObjectToFromJsonObjectParam instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassNullableOfObjectToFromJsonObjectParam - _$SimpleClassNullableOfObjectToFromJsonObjectParamFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfObjectToFromJsonObjectParam( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, FromJsonObjectParam.fromJson(e as Object)), - ), - ); +_$SimpleClassNullableOfObjectToFromJsonObjectParamFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfObjectToFromJsonObjectParam( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, FromJsonObjectParam.fromJson(e as Object)), + ), +); Map<String, dynamic> _$SimpleClassNullableOfObjectToFromJsonObjectParamToJson( - SimpleClassNullableOfObjectToFromJsonObjectParam instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassNullableOfObjectToFromJsonObjectParam instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassOfStringToFromJsonObjectParam - _$SimpleClassOfStringToFromJsonObjectParamFromJson( - Map<String, dynamic> json) => - SimpleClassOfStringToFromJsonObjectParam( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(k, FromJsonObjectParam.fromJson(e as Object)), - ), - ); +_$SimpleClassOfStringToFromJsonObjectParamFromJson(Map<String, dynamic> json) => + SimpleClassOfStringToFromJsonObjectParam( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(k, FromJsonObjectParam.fromJson(e as Object)), + ), + ); Map<String, dynamic> _$SimpleClassOfStringToFromJsonObjectParamToJson( - SimpleClassOfStringToFromJsonObjectParam instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassOfStringToFromJsonObjectParam instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassNullableOfStringToFromJsonObjectParam - _$SimpleClassNullableOfStringToFromJsonObjectParamFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfStringToFromJsonObjectParam( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, FromJsonObjectParam.fromJson(e as Object)), - ), - ); +_$SimpleClassNullableOfStringToFromJsonObjectParamFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfStringToFromJsonObjectParam( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, FromJsonObjectParam.fromJson(e as Object)), + ), +); Map<String, dynamic> _$SimpleClassNullableOfStringToFromJsonObjectParamToJson( - SimpleClassNullableOfStringToFromJsonObjectParam instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassNullableOfStringToFromJsonObjectParam instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassOfUriToFromJsonObjectParam - _$SimpleClassOfUriToFromJsonObjectParamFromJson( - Map<String, dynamic> json) => - SimpleClassOfUriToFromJsonObjectParam( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry( - Uri.parse(k), FromJsonObjectParam.fromJson(e as Object)), - ), - ); +_$SimpleClassOfUriToFromJsonObjectParamFromJson(Map<String, dynamic> json) => + SimpleClassOfUriToFromJsonObjectParam( + (json['value'] as Map<String, dynamic>).map( + (k, e) => + MapEntry(Uri.parse(k), FromJsonObjectParam.fromJson(e as Object)), + ), + ); Map<String, dynamic> _$SimpleClassOfUriToFromJsonObjectParamToJson( - SimpleClassOfUriToFromJsonObjectParam instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassOfUriToFromJsonObjectParam instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassNullableOfUriToFromJsonObjectParam - _$SimpleClassNullableOfUriToFromJsonObjectParamFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfUriToFromJsonObjectParam( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry( - Uri.parse(k), FromJsonObjectParam.fromJson(e as Object)), - ), - ); +_$SimpleClassNullableOfUriToFromJsonObjectParamFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfUriToFromJsonObjectParam( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(Uri.parse(k), FromJsonObjectParam.fromJson(e as Object)), + ), +); Map<String, dynamic> _$SimpleClassNullableOfUriToFromJsonObjectParamToJson( - SimpleClassNullableOfUriToFromJsonObjectParam instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassNullableOfUriToFromJsonObjectParam instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassOfBigIntToInt _$SimpleClassOfBigIntToIntFromJson( - Map<String, dynamic> json) => - SimpleClassOfBigIntToInt( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(BigInt.parse(k), (e as num).toInt()), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfBigIntToInt( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(BigInt.parse(k), (e as num).toInt()), + ), +); Map<String, dynamic> _$SimpleClassOfBigIntToIntToJson( - SimpleClassOfBigIntToInt instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassOfBigIntToInt instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassNullableOfBigIntToInt _$SimpleClassNullableOfBigIntToIntFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfBigIntToInt( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(BigInt.parse(k), (e as num).toInt()), - ), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfBigIntToInt( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(BigInt.parse(k), (e as num).toInt()), + ), +); Map<String, dynamic> _$SimpleClassNullableOfBigIntToIntToJson( - SimpleClassNullableOfBigIntToInt instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassNullableOfBigIntToInt instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassOfDateTimeToInt _$SimpleClassOfDateTimeToIntFromJson( - Map<String, dynamic> json) => - SimpleClassOfDateTimeToInt( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(DateTime.parse(k), (e as num).toInt()), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfDateTimeToInt( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(DateTime.parse(k), (e as num).toInt()), + ), +); Map<String, dynamic> _$SimpleClassOfDateTimeToIntToJson( - SimpleClassOfDateTimeToInt instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toIso8601String(), e)), - }; + SimpleClassOfDateTimeToInt instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toIso8601String(), e)), +}; SimpleClassNullableOfDateTimeToInt _$SimpleClassNullableOfDateTimeToIntFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDateTimeToInt( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(DateTime.parse(k), (e as num).toInt()), - ), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfDateTimeToInt( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(DateTime.parse(k), (e as num).toInt()), + ), +); Map<String, dynamic> _$SimpleClassNullableOfDateTimeToIntToJson( - SimpleClassNullableOfDateTimeToInt instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toIso8601String(), e)), - }; + SimpleClassNullableOfDateTimeToInt instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toIso8601String(), e)), +}; SimpleClassOfDynamicToInt _$SimpleClassOfDynamicToIntFromJson( - Map<String, dynamic> json) => - SimpleClassOfDynamicToInt( - Map<String, int>.from(json['value'] as Map), - ); + Map<String, dynamic> json, +) => SimpleClassOfDynamicToInt(Map<String, int>.from(json['value'] as Map)); Map<String, dynamic> _$SimpleClassOfDynamicToIntToJson( - SimpleClassOfDynamicToInt instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassOfDynamicToInt instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassNullableOfDynamicToInt _$SimpleClassNullableOfDynamicToIntFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDynamicToInt( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, (e as num).toInt()), - ), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfDynamicToInt( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, (e as num).toInt()), + ), +); Map<String, dynamic> _$SimpleClassNullableOfDynamicToIntToJson( - SimpleClassNullableOfDynamicToInt instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassNullableOfDynamicToInt instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassOfEnumTypeToInt _$SimpleClassOfEnumTypeToIntFromJson( - Map<String, dynamic> json) => - SimpleClassOfEnumTypeToInt( - (json['value'] as Map<String, dynamic>).map( - (k, e) => - MapEntry($enumDecode(_$EnumTypeEnumMap, k), (e as num).toInt()), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfEnumTypeToInt( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), (e as num).toInt()), + ), +); Map<String, dynamic> _$SimpleClassOfEnumTypeToIntToJson( - SimpleClassOfEnumTypeToInt instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), - }; + SimpleClassOfEnumTypeToInt instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), +}; SimpleClassNullableOfEnumTypeToInt _$SimpleClassNullableOfEnumTypeToIntFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfEnumTypeToInt( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => - MapEntry($enumDecode(_$EnumTypeEnumMap, k), (e as num).toInt()), - ), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfEnumTypeToInt( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), (e as num).toInt()), + ), +); Map<String, dynamic> _$SimpleClassNullableOfEnumTypeToIntToJson( - SimpleClassNullableOfEnumTypeToInt instance) => - <String, dynamic>{ - 'value': - instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), - }; + SimpleClassNullableOfEnumTypeToInt instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), +}; SimpleClassOfIntToInt _$SimpleClassOfIntToIntFromJson( - Map<String, dynamic> json) => - SimpleClassOfIntToInt( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(int.parse(k), (e as num).toInt()), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfIntToInt( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(int.parse(k), (e as num).toInt()), + ), +); Map<String, dynamic> _$SimpleClassOfIntToIntToJson( - SimpleClassOfIntToInt instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassOfIntToInt instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassNullableOfIntToInt _$SimpleClassNullableOfIntToIntFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfIntToInt( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(int.parse(k), (e as num).toInt()), - ), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfIntToInt( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(int.parse(k), (e as num).toInt()), + ), +); Map<String, dynamic> _$SimpleClassNullableOfIntToIntToJson( - SimpleClassNullableOfIntToInt instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassNullableOfIntToInt instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassOfObjectToInt _$SimpleClassOfObjectToIntFromJson( - Map<String, dynamic> json) => - SimpleClassOfObjectToInt( - Map<String, int>.from(json['value'] as Map), - ); + Map<String, dynamic> json, +) => SimpleClassOfObjectToInt(Map<String, int>.from(json['value'] as Map)); Map<String, dynamic> _$SimpleClassOfObjectToIntToJson( - SimpleClassOfObjectToInt instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassOfObjectToInt instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassNullableOfObjectToInt _$SimpleClassNullableOfObjectToIntFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfObjectToInt( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, (e as num).toInt()), - ), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfObjectToInt( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, (e as num).toInt()), + ), +); Map<String, dynamic> _$SimpleClassNullableOfObjectToIntToJson( - SimpleClassNullableOfObjectToInt instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassNullableOfObjectToInt instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassOfStringToInt _$SimpleClassOfStringToIntFromJson( - Map<String, dynamic> json) => - SimpleClassOfStringToInt( - Map<String, int>.from(json['value'] as Map), - ); + Map<String, dynamic> json, +) => SimpleClassOfStringToInt(Map<String, int>.from(json['value'] as Map)); Map<String, dynamic> _$SimpleClassOfStringToIntToJson( - SimpleClassOfStringToInt instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassOfStringToInt instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassNullableOfStringToInt _$SimpleClassNullableOfStringToIntFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfStringToInt( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, (e as num).toInt()), - ), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfStringToInt( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, (e as num).toInt()), + ), +); Map<String, dynamic> _$SimpleClassNullableOfStringToIntToJson( - SimpleClassNullableOfStringToInt instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassNullableOfStringToInt instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassOfUriToInt _$SimpleClassOfUriToIntFromJson( - Map<String, dynamic> json) => - SimpleClassOfUriToInt( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(Uri.parse(k), (e as num).toInt()), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfUriToInt( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(Uri.parse(k), (e as num).toInt()), + ), +); Map<String, dynamic> _$SimpleClassOfUriToIntToJson( - SimpleClassOfUriToInt instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassOfUriToInt instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassNullableOfUriToInt _$SimpleClassNullableOfUriToIntFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfUriToInt( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(Uri.parse(k), (e as num).toInt()), - ), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfUriToInt( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(Uri.parse(k), (e as num).toInt()), + ), +); Map<String, dynamic> _$SimpleClassNullableOfUriToIntToJson( - SimpleClassNullableOfUriToInt instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassNullableOfUriToInt instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassOfBigIntToIntNullable _$SimpleClassOfBigIntToIntNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfBigIntToIntNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(BigInt.parse(k), (e as num?)?.toInt()), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfBigIntToIntNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(BigInt.parse(k), (e as num?)?.toInt()), + ), +); Map<String, dynamic> _$SimpleClassOfBigIntToIntNullableToJson( - SimpleClassOfBigIntToIntNullable instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassOfBigIntToIntNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassNullableOfBigIntToIntNullable - _$SimpleClassNullableOfBigIntToIntNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfBigIntToIntNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(BigInt.parse(k), (e as num?)?.toInt()), - ), - ); +_$SimpleClassNullableOfBigIntToIntNullableFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfBigIntToIntNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(BigInt.parse(k), (e as num?)?.toInt()), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfBigIntToIntNullableToJson( - SimpleClassNullableOfBigIntToIntNullable instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassNullableOfBigIntToIntNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassOfDateTimeToIntNullable _$SimpleClassOfDateTimeToIntNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfDateTimeToIntNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(DateTime.parse(k), (e as num?)?.toInt()), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfDateTimeToIntNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(DateTime.parse(k), (e as num?)?.toInt()), + ), +); Map<String, dynamic> _$SimpleClassOfDateTimeToIntNullableToJson( - SimpleClassOfDateTimeToIntNullable instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toIso8601String(), e)), - }; + SimpleClassOfDateTimeToIntNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toIso8601String(), e)), +}; SimpleClassNullableOfDateTimeToIntNullable - _$SimpleClassNullableOfDateTimeToIntNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDateTimeToIntNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(DateTime.parse(k), (e as num?)?.toInt()), - ), - ); +_$SimpleClassNullableOfDateTimeToIntNullableFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfDateTimeToIntNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(DateTime.parse(k), (e as num?)?.toInt()), + ), +); Map<String, dynamic> _$SimpleClassNullableOfDateTimeToIntNullableToJson( - SimpleClassNullableOfDateTimeToIntNullable instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toIso8601String(), e)), - }; + SimpleClassNullableOfDateTimeToIntNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toIso8601String(), e)), +}; SimpleClassOfDynamicToIntNullable _$SimpleClassOfDynamicToIntNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfDynamicToIntNullable( - Map<String, int?>.from(json['value'] as Map), - ); + Map<String, dynamic> json, +) => SimpleClassOfDynamicToIntNullable( + Map<String, int?>.from(json['value'] as Map), +); Map<String, dynamic> _$SimpleClassOfDynamicToIntNullableToJson( - SimpleClassOfDynamicToIntNullable instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassOfDynamicToIntNullable instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassNullableOfDynamicToIntNullable - _$SimpleClassNullableOfDynamicToIntNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDynamicToIntNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, (e as num?)?.toInt()), - ), - ); +_$SimpleClassNullableOfDynamicToIntNullableFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfDynamicToIntNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, (e as num?)?.toInt()), + ), +); Map<String, dynamic> _$SimpleClassNullableOfDynamicToIntNullableToJson( - SimpleClassNullableOfDynamicToIntNullable instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassNullableOfDynamicToIntNullable instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassOfEnumTypeToIntNullable _$SimpleClassOfEnumTypeToIntNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfEnumTypeToIntNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => - MapEntry($enumDecode(_$EnumTypeEnumMap, k), (e as num?)?.toInt()), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfEnumTypeToIntNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), (e as num?)?.toInt()), + ), +); Map<String, dynamic> _$SimpleClassOfEnumTypeToIntNullableToJson( - SimpleClassOfEnumTypeToIntNullable instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), - }; + SimpleClassOfEnumTypeToIntNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), +}; SimpleClassNullableOfEnumTypeToIntNullable - _$SimpleClassNullableOfEnumTypeToIntNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfEnumTypeToIntNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry( - $enumDecode(_$EnumTypeEnumMap, k), (e as num?)?.toInt()), - ), - ); +_$SimpleClassNullableOfEnumTypeToIntNullableFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfEnumTypeToIntNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), (e as num?)?.toInt()), + ), +); Map<String, dynamic> _$SimpleClassNullableOfEnumTypeToIntNullableToJson( - SimpleClassNullableOfEnumTypeToIntNullable instance) => - <String, dynamic>{ - 'value': - instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), - }; + SimpleClassNullableOfEnumTypeToIntNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), +}; SimpleClassOfIntToIntNullable _$SimpleClassOfIntToIntNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfIntToIntNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(int.parse(k), (e as num?)?.toInt()), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfIntToIntNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(int.parse(k), (e as num?)?.toInt()), + ), +); Map<String, dynamic> _$SimpleClassOfIntToIntNullableToJson( - SimpleClassOfIntToIntNullable instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassOfIntToIntNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassNullableOfIntToIntNullable - _$SimpleClassNullableOfIntToIntNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfIntToIntNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(int.parse(k), (e as num?)?.toInt()), - ), - ); +_$SimpleClassNullableOfIntToIntNullableFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfIntToIntNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(int.parse(k), (e as num?)?.toInt()), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfIntToIntNullableToJson( - SimpleClassNullableOfIntToIntNullable instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassNullableOfIntToIntNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassOfObjectToIntNullable _$SimpleClassOfObjectToIntNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfObjectToIntNullable( - Map<String, int?>.from(json['value'] as Map), - ); + Map<String, dynamic> json, +) => SimpleClassOfObjectToIntNullable( + Map<String, int?>.from(json['value'] as Map), +); Map<String, dynamic> _$SimpleClassOfObjectToIntNullableToJson( - SimpleClassOfObjectToIntNullable instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassOfObjectToIntNullable instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassNullableOfObjectToIntNullable - _$SimpleClassNullableOfObjectToIntNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfObjectToIntNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, (e as num?)?.toInt()), - ), - ); +_$SimpleClassNullableOfObjectToIntNullableFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfObjectToIntNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, (e as num?)?.toInt()), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfObjectToIntNullableToJson( - SimpleClassNullableOfObjectToIntNullable instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassNullableOfObjectToIntNullable instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassOfStringToIntNullable _$SimpleClassOfStringToIntNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfStringToIntNullable( - Map<String, int?>.from(json['value'] as Map), - ); + Map<String, dynamic> json, +) => SimpleClassOfStringToIntNullable( + Map<String, int?>.from(json['value'] as Map), +); Map<String, dynamic> _$SimpleClassOfStringToIntNullableToJson( - SimpleClassOfStringToIntNullable instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassOfStringToIntNullable instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassNullableOfStringToIntNullable - _$SimpleClassNullableOfStringToIntNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfStringToIntNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, (e as num?)?.toInt()), - ), - ); +_$SimpleClassNullableOfStringToIntNullableFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfStringToIntNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, (e as num?)?.toInt()), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfStringToIntNullableToJson( - SimpleClassNullableOfStringToIntNullable instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassNullableOfStringToIntNullable instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassOfUriToIntNullable _$SimpleClassOfUriToIntNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfUriToIntNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(Uri.parse(k), (e as num?)?.toInt()), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfUriToIntNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(Uri.parse(k), (e as num?)?.toInt()), + ), +); Map<String, dynamic> _$SimpleClassOfUriToIntNullableToJson( - SimpleClassOfUriToIntNullable instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassOfUriToIntNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassNullableOfUriToIntNullable - _$SimpleClassNullableOfUriToIntNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfUriToIntNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(Uri.parse(k), (e as num?)?.toInt()), - ), - ); +_$SimpleClassNullableOfUriToIntNullableFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfUriToIntNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(Uri.parse(k), (e as num?)?.toInt()), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfUriToIntNullableToJson( - SimpleClassNullableOfUriToIntNullable instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassNullableOfUriToIntNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassOfBigIntToNum _$SimpleClassOfBigIntToNumFromJson( - Map<String, dynamic> json) => - SimpleClassOfBigIntToNum( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(BigInt.parse(k), e as num), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfBigIntToNum( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(BigInt.parse(k), e as num), + ), +); Map<String, dynamic> _$SimpleClassOfBigIntToNumToJson( - SimpleClassOfBigIntToNum instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassOfBigIntToNum instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassNullableOfBigIntToNum _$SimpleClassNullableOfBigIntToNumFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfBigIntToNum( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(BigInt.parse(k), e as num), - ), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfBigIntToNum( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(BigInt.parse(k), e as num), + ), +); Map<String, dynamic> _$SimpleClassNullableOfBigIntToNumToJson( - SimpleClassNullableOfBigIntToNum instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassNullableOfBigIntToNum instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassOfDateTimeToNum _$SimpleClassOfDateTimeToNumFromJson( - Map<String, dynamic> json) => - SimpleClassOfDateTimeToNum( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(DateTime.parse(k), e as num), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfDateTimeToNum( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(DateTime.parse(k), e as num), + ), +); Map<String, dynamic> _$SimpleClassOfDateTimeToNumToJson( - SimpleClassOfDateTimeToNum instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toIso8601String(), e)), - }; + SimpleClassOfDateTimeToNum instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toIso8601String(), e)), +}; SimpleClassNullableOfDateTimeToNum _$SimpleClassNullableOfDateTimeToNumFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDateTimeToNum( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(DateTime.parse(k), e as num), - ), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfDateTimeToNum( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(DateTime.parse(k), e as num), + ), +); Map<String, dynamic> _$SimpleClassNullableOfDateTimeToNumToJson( - SimpleClassNullableOfDateTimeToNum instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toIso8601String(), e)), - }; + SimpleClassNullableOfDateTimeToNum instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toIso8601String(), e)), +}; SimpleClassOfDynamicToNum _$SimpleClassOfDynamicToNumFromJson( - Map<String, dynamic> json) => - SimpleClassOfDynamicToNum( - Map<String, num>.from(json['value'] as Map), - ); + Map<String, dynamic> json, +) => SimpleClassOfDynamicToNum(Map<String, num>.from(json['value'] as Map)); Map<String, dynamic> _$SimpleClassOfDynamicToNumToJson( - SimpleClassOfDynamicToNum instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassOfDynamicToNum instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassNullableOfDynamicToNum _$SimpleClassNullableOfDynamicToNumFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDynamicToNum( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, e as num), - ), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfDynamicToNum( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, e as num), + ), +); Map<String, dynamic> _$SimpleClassNullableOfDynamicToNumToJson( - SimpleClassNullableOfDynamicToNum instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassNullableOfDynamicToNum instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassOfEnumTypeToNum _$SimpleClassOfEnumTypeToNumFromJson( - Map<String, dynamic> json) => - SimpleClassOfEnumTypeToNum( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e as num), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfEnumTypeToNum( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e as num), + ), +); Map<String, dynamic> _$SimpleClassOfEnumTypeToNumToJson( - SimpleClassOfEnumTypeToNum instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), - }; + SimpleClassOfEnumTypeToNum instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), +}; SimpleClassNullableOfEnumTypeToNum _$SimpleClassNullableOfEnumTypeToNumFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfEnumTypeToNum( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e as num), - ), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfEnumTypeToNum( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e as num), + ), +); Map<String, dynamic> _$SimpleClassNullableOfEnumTypeToNumToJson( - SimpleClassNullableOfEnumTypeToNum instance) => - <String, dynamic>{ - 'value': - instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), - }; + SimpleClassNullableOfEnumTypeToNum instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), +}; SimpleClassOfIntToNum _$SimpleClassOfIntToNumFromJson( - Map<String, dynamic> json) => - SimpleClassOfIntToNum( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(int.parse(k), e as num), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfIntToNum( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(int.parse(k), e as num), + ), +); Map<String, dynamic> _$SimpleClassOfIntToNumToJson( - SimpleClassOfIntToNum instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassOfIntToNum instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassNullableOfIntToNum _$SimpleClassNullableOfIntToNumFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfIntToNum( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(int.parse(k), e as num), - ), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfIntToNum( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(int.parse(k), e as num), + ), +); Map<String, dynamic> _$SimpleClassNullableOfIntToNumToJson( - SimpleClassNullableOfIntToNum instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassNullableOfIntToNum instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassOfObjectToNum _$SimpleClassOfObjectToNumFromJson( - Map<String, dynamic> json) => - SimpleClassOfObjectToNum( - Map<String, num>.from(json['value'] as Map), - ); + Map<String, dynamic> json, +) => SimpleClassOfObjectToNum(Map<String, num>.from(json['value'] as Map)); Map<String, dynamic> _$SimpleClassOfObjectToNumToJson( - SimpleClassOfObjectToNum instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassOfObjectToNum instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassNullableOfObjectToNum _$SimpleClassNullableOfObjectToNumFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfObjectToNum( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, e as num), - ), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfObjectToNum( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, e as num), + ), +); Map<String, dynamic> _$SimpleClassNullableOfObjectToNumToJson( - SimpleClassNullableOfObjectToNum instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassNullableOfObjectToNum instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassOfStringToNum _$SimpleClassOfStringToNumFromJson( - Map<String, dynamic> json) => - SimpleClassOfStringToNum( - Map<String, num>.from(json['value'] as Map), - ); + Map<String, dynamic> json, +) => SimpleClassOfStringToNum(Map<String, num>.from(json['value'] as Map)); Map<String, dynamic> _$SimpleClassOfStringToNumToJson( - SimpleClassOfStringToNum instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassOfStringToNum instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassNullableOfStringToNum _$SimpleClassNullableOfStringToNumFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfStringToNum( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, e as num), - ), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfStringToNum( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, e as num), + ), +); Map<String, dynamic> _$SimpleClassNullableOfStringToNumToJson( - SimpleClassNullableOfStringToNum instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassNullableOfStringToNum instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassOfUriToNum _$SimpleClassOfUriToNumFromJson( - Map<String, dynamic> json) => - SimpleClassOfUriToNum( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(Uri.parse(k), e as num), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfUriToNum( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(Uri.parse(k), e as num), + ), +); Map<String, dynamic> _$SimpleClassOfUriToNumToJson( - SimpleClassOfUriToNum instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassOfUriToNum instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassNullableOfUriToNum _$SimpleClassNullableOfUriToNumFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfUriToNum( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(Uri.parse(k), e as num), - ), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfUriToNum( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(Uri.parse(k), e as num), + ), +); Map<String, dynamic> _$SimpleClassNullableOfUriToNumToJson( - SimpleClassNullableOfUriToNum instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassNullableOfUriToNum instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassOfBigIntToNumNullable _$SimpleClassOfBigIntToNumNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfBigIntToNumNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(BigInt.parse(k), e as num?), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfBigIntToNumNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(BigInt.parse(k), e as num?), + ), +); Map<String, dynamic> _$SimpleClassOfBigIntToNumNullableToJson( - SimpleClassOfBigIntToNumNullable instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassOfBigIntToNumNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassNullableOfBigIntToNumNullable - _$SimpleClassNullableOfBigIntToNumNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfBigIntToNumNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(BigInt.parse(k), e as num?), - ), - ); +_$SimpleClassNullableOfBigIntToNumNullableFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfBigIntToNumNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(BigInt.parse(k), e as num?), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfBigIntToNumNullableToJson( - SimpleClassNullableOfBigIntToNumNullable instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassNullableOfBigIntToNumNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassOfDateTimeToNumNullable _$SimpleClassOfDateTimeToNumNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfDateTimeToNumNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(DateTime.parse(k), e as num?), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfDateTimeToNumNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(DateTime.parse(k), e as num?), + ), +); Map<String, dynamic> _$SimpleClassOfDateTimeToNumNullableToJson( - SimpleClassOfDateTimeToNumNullable instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toIso8601String(), e)), - }; + SimpleClassOfDateTimeToNumNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toIso8601String(), e)), +}; SimpleClassNullableOfDateTimeToNumNullable - _$SimpleClassNullableOfDateTimeToNumNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDateTimeToNumNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(DateTime.parse(k), e as num?), - ), - ); +_$SimpleClassNullableOfDateTimeToNumNullableFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfDateTimeToNumNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(DateTime.parse(k), e as num?), + ), +); Map<String, dynamic> _$SimpleClassNullableOfDateTimeToNumNullableToJson( - SimpleClassNullableOfDateTimeToNumNullable instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toIso8601String(), e)), - }; + SimpleClassNullableOfDateTimeToNumNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toIso8601String(), e)), +}; SimpleClassOfDynamicToNumNullable _$SimpleClassOfDynamicToNumNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfDynamicToNumNullable( - Map<String, num?>.from(json['value'] as Map), - ); + Map<String, dynamic> json, +) => SimpleClassOfDynamicToNumNullable( + Map<String, num?>.from(json['value'] as Map), +); Map<String, dynamic> _$SimpleClassOfDynamicToNumNullableToJson( - SimpleClassOfDynamicToNumNullable instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassOfDynamicToNumNullable instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassNullableOfDynamicToNumNullable - _$SimpleClassNullableOfDynamicToNumNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDynamicToNumNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, e as num?), - ), - ); +_$SimpleClassNullableOfDynamicToNumNullableFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfDynamicToNumNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, e as num?), + ), +); Map<String, dynamic> _$SimpleClassNullableOfDynamicToNumNullableToJson( - SimpleClassNullableOfDynamicToNumNullable instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassNullableOfDynamicToNumNullable instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassOfEnumTypeToNumNullable _$SimpleClassOfEnumTypeToNumNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfEnumTypeToNumNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e as num?), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfEnumTypeToNumNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e as num?), + ), +); Map<String, dynamic> _$SimpleClassOfEnumTypeToNumNullableToJson( - SimpleClassOfEnumTypeToNumNullable instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), - }; + SimpleClassOfEnumTypeToNumNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), +}; SimpleClassNullableOfEnumTypeToNumNullable - _$SimpleClassNullableOfEnumTypeToNumNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfEnumTypeToNumNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e as num?), - ), - ); +_$SimpleClassNullableOfEnumTypeToNumNullableFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfEnumTypeToNumNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e as num?), + ), +); Map<String, dynamic> _$SimpleClassNullableOfEnumTypeToNumNullableToJson( - SimpleClassNullableOfEnumTypeToNumNullable instance) => - <String, dynamic>{ - 'value': - instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), - }; + SimpleClassNullableOfEnumTypeToNumNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), +}; SimpleClassOfIntToNumNullable _$SimpleClassOfIntToNumNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfIntToNumNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(int.parse(k), e as num?), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfIntToNumNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(int.parse(k), e as num?), + ), +); Map<String, dynamic> _$SimpleClassOfIntToNumNullableToJson( - SimpleClassOfIntToNumNullable instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassOfIntToNumNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassNullableOfIntToNumNullable - _$SimpleClassNullableOfIntToNumNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfIntToNumNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(int.parse(k), e as num?), - ), - ); +_$SimpleClassNullableOfIntToNumNullableFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfIntToNumNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(int.parse(k), e as num?), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfIntToNumNullableToJson( - SimpleClassNullableOfIntToNumNullable instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassNullableOfIntToNumNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassOfObjectToNumNullable _$SimpleClassOfObjectToNumNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfObjectToNumNullable( - Map<String, num?>.from(json['value'] as Map), - ); + Map<String, dynamic> json, +) => SimpleClassOfObjectToNumNullable( + Map<String, num?>.from(json['value'] as Map), +); Map<String, dynamic> _$SimpleClassOfObjectToNumNullableToJson( - SimpleClassOfObjectToNumNullable instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassOfObjectToNumNullable instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassNullableOfObjectToNumNullable - _$SimpleClassNullableOfObjectToNumNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfObjectToNumNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, e as num?), - ), - ); +_$SimpleClassNullableOfObjectToNumNullableFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfObjectToNumNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, e as num?), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfObjectToNumNullableToJson( - SimpleClassNullableOfObjectToNumNullable instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassNullableOfObjectToNumNullable instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassOfStringToNumNullable _$SimpleClassOfStringToNumNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfStringToNumNullable( - Map<String, num?>.from(json['value'] as Map), - ); + Map<String, dynamic> json, +) => SimpleClassOfStringToNumNullable( + Map<String, num?>.from(json['value'] as Map), +); Map<String, dynamic> _$SimpleClassOfStringToNumNullableToJson( - SimpleClassOfStringToNumNullable instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassOfStringToNumNullable instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassNullableOfStringToNumNullable - _$SimpleClassNullableOfStringToNumNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfStringToNumNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, e as num?), - ), - ); +_$SimpleClassNullableOfStringToNumNullableFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfStringToNumNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, e as num?), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfStringToNumNullableToJson( - SimpleClassNullableOfStringToNumNullable instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassNullableOfStringToNumNullable instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassOfUriToNumNullable _$SimpleClassOfUriToNumNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfUriToNumNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(Uri.parse(k), e as num?), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfUriToNumNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(Uri.parse(k), e as num?), + ), +); Map<String, dynamic> _$SimpleClassOfUriToNumNullableToJson( - SimpleClassOfUriToNumNullable instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassOfUriToNumNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassNullableOfUriToNumNullable - _$SimpleClassNullableOfUriToNumNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfUriToNumNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(Uri.parse(k), e as num?), - ), - ); +_$SimpleClassNullableOfUriToNumNullableFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfUriToNumNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(Uri.parse(k), e as num?), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfUriToNumNullableToJson( - SimpleClassNullableOfUriToNumNullable instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassNullableOfUriToNumNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassOfBigIntToObject _$SimpleClassOfBigIntToObjectFromJson( - Map<String, dynamic> json) => - SimpleClassOfBigIntToObject( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(BigInt.parse(k), e as Object), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfBigIntToObject( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(BigInt.parse(k), e as Object), + ), +); Map<String, dynamic> _$SimpleClassOfBigIntToObjectToJson( - SimpleClassOfBigIntToObject instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassOfBigIntToObject instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassNullableOfBigIntToObject - _$SimpleClassNullableOfBigIntToObjectFromJson(Map<String, dynamic> json) => - SimpleClassNullableOfBigIntToObject( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(BigInt.parse(k), e as Object), - ), - ); +_$SimpleClassNullableOfBigIntToObjectFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfBigIntToObject( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(BigInt.parse(k), e as Object), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfBigIntToObjectToJson( - SimpleClassNullableOfBigIntToObject instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassNullableOfBigIntToObject instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassOfDateTimeToObject _$SimpleClassOfDateTimeToObjectFromJson( - Map<String, dynamic> json) => - SimpleClassOfDateTimeToObject( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(DateTime.parse(k), e as Object), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfDateTimeToObject( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(DateTime.parse(k), e as Object), + ), +); Map<String, dynamic> _$SimpleClassOfDateTimeToObjectToJson( - SimpleClassOfDateTimeToObject instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toIso8601String(), e)), - }; + SimpleClassOfDateTimeToObject instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toIso8601String(), e)), +}; SimpleClassNullableOfDateTimeToObject - _$SimpleClassNullableOfDateTimeToObjectFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDateTimeToObject( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(DateTime.parse(k), e as Object), - ), - ); +_$SimpleClassNullableOfDateTimeToObjectFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfDateTimeToObject( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(DateTime.parse(k), e as Object), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfDateTimeToObjectToJson( - SimpleClassNullableOfDateTimeToObject instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toIso8601String(), e)), - }; + SimpleClassNullableOfDateTimeToObject instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toIso8601String(), e)), +}; SimpleClassOfDynamicToObject _$SimpleClassOfDynamicToObjectFromJson( - Map<String, dynamic> json) => - SimpleClassOfDynamicToObject( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(k, e as Object), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfDynamicToObject( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(k, e as Object), + ), +); Map<String, dynamic> _$SimpleClassOfDynamicToObjectToJson( - SimpleClassOfDynamicToObject instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassOfDynamicToObject instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassNullableOfDynamicToObject - _$SimpleClassNullableOfDynamicToObjectFromJson(Map<String, dynamic> json) => - SimpleClassNullableOfDynamicToObject( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, e as Object), - ), - ); +_$SimpleClassNullableOfDynamicToObjectFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfDynamicToObject( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, e as Object), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfDynamicToObjectToJson( - SimpleClassNullableOfDynamicToObject instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassNullableOfDynamicToObject instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassOfEnumTypeToObject _$SimpleClassOfEnumTypeToObjectFromJson( - Map<String, dynamic> json) => - SimpleClassOfEnumTypeToObject( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e as Object), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfEnumTypeToObject( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e as Object), + ), +); Map<String, dynamic> _$SimpleClassOfEnumTypeToObjectToJson( - SimpleClassOfEnumTypeToObject instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), - }; + SimpleClassOfEnumTypeToObject instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), +}; SimpleClassNullableOfEnumTypeToObject - _$SimpleClassNullableOfEnumTypeToObjectFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfEnumTypeToObject( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e as Object), - ), - ); +_$SimpleClassNullableOfEnumTypeToObjectFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfEnumTypeToObject( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e as Object), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfEnumTypeToObjectToJson( - SimpleClassNullableOfEnumTypeToObject instance) => - <String, dynamic>{ - 'value': - instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), - }; + SimpleClassNullableOfEnumTypeToObject instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), +}; SimpleClassOfIntToObject _$SimpleClassOfIntToObjectFromJson( - Map<String, dynamic> json) => - SimpleClassOfIntToObject( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(int.parse(k), e as Object), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfIntToObject( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(int.parse(k), e as Object), + ), +); Map<String, dynamic> _$SimpleClassOfIntToObjectToJson( - SimpleClassOfIntToObject instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassOfIntToObject instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassNullableOfIntToObject _$SimpleClassNullableOfIntToObjectFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfIntToObject( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(int.parse(k), e as Object), - ), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfIntToObject( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(int.parse(k), e as Object), + ), +); Map<String, dynamic> _$SimpleClassNullableOfIntToObjectToJson( - SimpleClassNullableOfIntToObject instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassNullableOfIntToObject instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassOfObjectToObject _$SimpleClassOfObjectToObjectFromJson( - Map<String, dynamic> json) => - SimpleClassOfObjectToObject( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(k, e as Object), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfObjectToObject( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(k, e as Object), + ), +); Map<String, dynamic> _$SimpleClassOfObjectToObjectToJson( - SimpleClassOfObjectToObject instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassOfObjectToObject instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassNullableOfObjectToObject - _$SimpleClassNullableOfObjectToObjectFromJson(Map<String, dynamic> json) => - SimpleClassNullableOfObjectToObject( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, e as Object), - ), - ); +_$SimpleClassNullableOfObjectToObjectFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfObjectToObject( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, e as Object), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfObjectToObjectToJson( - SimpleClassNullableOfObjectToObject instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassNullableOfObjectToObject instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassOfStringToObject _$SimpleClassOfStringToObjectFromJson( - Map<String, dynamic> json) => - SimpleClassOfStringToObject( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(k, e as Object), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfStringToObject( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(k, e as Object), + ), +); Map<String, dynamic> _$SimpleClassOfStringToObjectToJson( - SimpleClassOfStringToObject instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassOfStringToObject instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassNullableOfStringToObject - _$SimpleClassNullableOfStringToObjectFromJson(Map<String, dynamic> json) => - SimpleClassNullableOfStringToObject( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, e as Object), - ), - ); +_$SimpleClassNullableOfStringToObjectFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfStringToObject( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, e as Object), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfStringToObjectToJson( - SimpleClassNullableOfStringToObject instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassNullableOfStringToObject instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassOfUriToObject _$SimpleClassOfUriToObjectFromJson( - Map<String, dynamic> json) => - SimpleClassOfUriToObject( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(Uri.parse(k), e as Object), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfUriToObject( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(Uri.parse(k), e as Object), + ), +); Map<String, dynamic> _$SimpleClassOfUriToObjectToJson( - SimpleClassOfUriToObject instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassOfUriToObject instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassNullableOfUriToObject _$SimpleClassNullableOfUriToObjectFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfUriToObject( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(Uri.parse(k), e as Object), - ), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfUriToObject( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(Uri.parse(k), e as Object), + ), +); Map<String, dynamic> _$SimpleClassNullableOfUriToObjectToJson( - SimpleClassNullableOfUriToObject instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassNullableOfUriToObject instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassOfBigIntToObjectNullable - _$SimpleClassOfBigIntToObjectNullableFromJson(Map<String, dynamic> json) => - SimpleClassOfBigIntToObjectNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(BigInt.parse(k), e), - ), - ); +_$SimpleClassOfBigIntToObjectNullableFromJson(Map<String, dynamic> json) => + SimpleClassOfBigIntToObjectNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(BigInt.parse(k), e), + ), + ); Map<String, dynamic> _$SimpleClassOfBigIntToObjectNullableToJson( - SimpleClassOfBigIntToObjectNullable instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassOfBigIntToObjectNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassNullableOfBigIntToObjectNullable - _$SimpleClassNullableOfBigIntToObjectNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfBigIntToObjectNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(BigInt.parse(k), e), - ), - ); +_$SimpleClassNullableOfBigIntToObjectNullableFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfBigIntToObjectNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(BigInt.parse(k), e), + ), +); Map<String, dynamic> _$SimpleClassNullableOfBigIntToObjectNullableToJson( - SimpleClassNullableOfBigIntToObjectNullable instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassNullableOfBigIntToObjectNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassOfDateTimeToObjectNullable - _$SimpleClassOfDateTimeToObjectNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfDateTimeToObjectNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(DateTime.parse(k), e), - ), - ); +_$SimpleClassOfDateTimeToObjectNullableFromJson(Map<String, dynamic> json) => + SimpleClassOfDateTimeToObjectNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(DateTime.parse(k), e), + ), + ); Map<String, dynamic> _$SimpleClassOfDateTimeToObjectNullableToJson( - SimpleClassOfDateTimeToObjectNullable instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toIso8601String(), e)), - }; + SimpleClassOfDateTimeToObjectNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toIso8601String(), e)), +}; SimpleClassNullableOfDateTimeToObjectNullable - _$SimpleClassNullableOfDateTimeToObjectNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDateTimeToObjectNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(DateTime.parse(k), e), - ), - ); +_$SimpleClassNullableOfDateTimeToObjectNullableFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfDateTimeToObjectNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(DateTime.parse(k), e), + ), +); Map<String, dynamic> _$SimpleClassNullableOfDateTimeToObjectNullableToJson( - SimpleClassNullableOfDateTimeToObjectNullable instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toIso8601String(), e)), - }; + SimpleClassNullableOfDateTimeToObjectNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toIso8601String(), e)), +}; SimpleClassOfDynamicToObjectNullable - _$SimpleClassOfDynamicToObjectNullableFromJson(Map<String, dynamic> json) => - SimpleClassOfDynamicToObjectNullable( - json['value'] as Map<String, dynamic>, - ); +_$SimpleClassOfDynamicToObjectNullableFromJson(Map<String, dynamic> json) => + SimpleClassOfDynamicToObjectNullable(json['value'] as Map<String, dynamic>); Map<String, dynamic> _$SimpleClassOfDynamicToObjectNullableToJson( - SimpleClassOfDynamicToObjectNullable instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassOfDynamicToObjectNullable instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassNullableOfDynamicToObjectNullable - _$SimpleClassNullableOfDynamicToObjectNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDynamicToObjectNullable( - json['value'] as Map<String, dynamic>?, - ); +_$SimpleClassNullableOfDynamicToObjectNullableFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfDynamicToObjectNullable( + json['value'] as Map<String, dynamic>?, +); Map<String, dynamic> _$SimpleClassNullableOfDynamicToObjectNullableToJson( - SimpleClassNullableOfDynamicToObjectNullable instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassNullableOfDynamicToObjectNullable instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassOfEnumTypeToObjectNullable - _$SimpleClassOfEnumTypeToObjectNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfEnumTypeToObjectNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e), - ), - ); +_$SimpleClassOfEnumTypeToObjectNullableFromJson(Map<String, dynamic> json) => + SimpleClassOfEnumTypeToObjectNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e), + ), + ); Map<String, dynamic> _$SimpleClassOfEnumTypeToObjectNullableToJson( - SimpleClassOfEnumTypeToObjectNullable instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), - }; + SimpleClassOfEnumTypeToObjectNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), +}; SimpleClassNullableOfEnumTypeToObjectNullable - _$SimpleClassNullableOfEnumTypeToObjectNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfEnumTypeToObjectNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e), - ), - ); +_$SimpleClassNullableOfEnumTypeToObjectNullableFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfEnumTypeToObjectNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e), + ), +); Map<String, dynamic> _$SimpleClassNullableOfEnumTypeToObjectNullableToJson( - SimpleClassNullableOfEnumTypeToObjectNullable instance) => - <String, dynamic>{ - 'value': - instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), - }; + SimpleClassNullableOfEnumTypeToObjectNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), +}; SimpleClassOfIntToObjectNullable _$SimpleClassOfIntToObjectNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfIntToObjectNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(int.parse(k), e), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfIntToObjectNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(int.parse(k), e), + ), +); Map<String, dynamic> _$SimpleClassOfIntToObjectNullableToJson( - SimpleClassOfIntToObjectNullable instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassOfIntToObjectNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassNullableOfIntToObjectNullable - _$SimpleClassNullableOfIntToObjectNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfIntToObjectNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(int.parse(k), e), - ), - ); +_$SimpleClassNullableOfIntToObjectNullableFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfIntToObjectNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(int.parse(k), e), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfIntToObjectNullableToJson( - SimpleClassNullableOfIntToObjectNullable instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassNullableOfIntToObjectNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassOfObjectToObjectNullable - _$SimpleClassOfObjectToObjectNullableFromJson(Map<String, dynamic> json) => - SimpleClassOfObjectToObjectNullable( - json['value'] as Map<String, dynamic>, - ); +_$SimpleClassOfObjectToObjectNullableFromJson(Map<String, dynamic> json) => + SimpleClassOfObjectToObjectNullable(json['value'] as Map<String, dynamic>); Map<String, dynamic> _$SimpleClassOfObjectToObjectNullableToJson( - SimpleClassOfObjectToObjectNullable instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassOfObjectToObjectNullable instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassNullableOfObjectToObjectNullable - _$SimpleClassNullableOfObjectToObjectNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfObjectToObjectNullable( - json['value'] as Map<String, dynamic>?, - ); +_$SimpleClassNullableOfObjectToObjectNullableFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfObjectToObjectNullable( + json['value'] as Map<String, dynamic>?, +); Map<String, dynamic> _$SimpleClassNullableOfObjectToObjectNullableToJson( - SimpleClassNullableOfObjectToObjectNullable instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassNullableOfObjectToObjectNullable instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassOfStringToObjectNullable - _$SimpleClassOfStringToObjectNullableFromJson(Map<String, dynamic> json) => - SimpleClassOfStringToObjectNullable( - json['value'] as Map<String, dynamic>, - ); +_$SimpleClassOfStringToObjectNullableFromJson(Map<String, dynamic> json) => + SimpleClassOfStringToObjectNullable(json['value'] as Map<String, dynamic>); Map<String, dynamic> _$SimpleClassOfStringToObjectNullableToJson( - SimpleClassOfStringToObjectNullable instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassOfStringToObjectNullable instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassNullableOfStringToObjectNullable - _$SimpleClassNullableOfStringToObjectNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfStringToObjectNullable( - json['value'] as Map<String, dynamic>?, - ); +_$SimpleClassNullableOfStringToObjectNullableFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfStringToObjectNullable( + json['value'] as Map<String, dynamic>?, +); Map<String, dynamic> _$SimpleClassNullableOfStringToObjectNullableToJson( - SimpleClassNullableOfStringToObjectNullable instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassNullableOfStringToObjectNullable instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassOfUriToObjectNullable _$SimpleClassOfUriToObjectNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfUriToObjectNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(Uri.parse(k), e), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfUriToObjectNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(Uri.parse(k), e), + ), +); Map<String, dynamic> _$SimpleClassOfUriToObjectNullableToJson( - SimpleClassOfUriToObjectNullable instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassOfUriToObjectNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassNullableOfUriToObjectNullable - _$SimpleClassNullableOfUriToObjectNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfUriToObjectNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(Uri.parse(k), e), - ), - ); - -Map<String, dynamic> _$SimpleClassNullableOfUriToObjectNullableToJson( - SimpleClassNullableOfUriToObjectNullable instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - }; - -SimpleClassOfBigIntToRecord _$SimpleClassOfBigIntToRecordFromJson( - Map<String, dynamic> json) => - SimpleClassOfBigIntToRecord( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry( - BigInt.parse(k), - _$recordConvert( - e, - ($jsonValue) => ( - ($jsonValue[r'$1'] as num).toInt(), - $jsonValue[r'$2'] as String, - truth: $jsonValue['truth'] as bool, - ), - )), +_$SimpleClassNullableOfUriToObjectNullableFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfUriToObjectNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(Uri.parse(k), e), ), ); +Map<String, dynamic> _$SimpleClassNullableOfUriToObjectNullableToJson( + SimpleClassNullableOfUriToObjectNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), +}; + +SimpleClassOfBigIntToRecord _$SimpleClassOfBigIntToRecordFromJson( + Map<String, dynamic> json, +) => SimpleClassOfBigIntToRecord( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry( + BigInt.parse(k), + _$recordConvert( + e, + ($jsonValue) => ( + ($jsonValue[r'$1'] as num).toInt(), + $jsonValue[r'$2'] as String, + truth: $jsonValue['truth'] as bool, + ), + ), + ), + ), +); + Map<String, dynamic> _$SimpleClassOfBigIntToRecordToJson( - SimpleClassOfBigIntToRecord instance) => - <String, dynamic>{ - 'value': - instance.value.map((k, e) => MapEntry(k.toString(), <String, dynamic>{ - r'$1': e.$1, - r'$2': e.$2, - 'truth': e.truth, - })), - }; + SimpleClassOfBigIntToRecord instance, +) => <String, dynamic>{ + 'value': instance.value.map( + (k, e) => MapEntry(k.toString(), <String, dynamic>{ + r'$1': e.$1, + r'$2': e.$2, + 'truth': e.truth, + }), + ), +}; -$Rec _$recordConvert<$Rec>( - Object? value, - $Rec Function(Map) convert, -) => +$Rec _$recordConvert<$Rec>(Object? value, $Rec Function(Map) convert) => convert(value as Map<String, dynamic>); SimpleClassNullableOfBigIntToRecord - _$SimpleClassNullableOfBigIntToRecordFromJson(Map<String, dynamic> json) => - SimpleClassNullableOfBigIntToRecord( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry( - BigInt.parse(k), - _$recordConvert( - e, - ($jsonValue) => ( - ($jsonValue[r'$1'] as num).toInt(), - $jsonValue[r'$2'] as String, - truth: $jsonValue['truth'] as bool, - ), - )), +_$SimpleClassNullableOfBigIntToRecordFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfBigIntToRecord( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry( + BigInt.parse(k), + _$recordConvert( + e, + ($jsonValue) => ( + ($jsonValue[r'$1'] as num).toInt(), + $jsonValue[r'$2'] as String, + truth: $jsonValue['truth'] as bool, + ), ), - ); + ), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfBigIntToRecordToJson( - SimpleClassNullableOfBigIntToRecord instance) => - <String, dynamic>{ - 'value': instance.value - ?.map((k, e) => MapEntry(k.toString(), <String, dynamic>{ - r'$1': e.$1, - r'$2': e.$2, - 'truth': e.truth, - })), - }; + SimpleClassNullableOfBigIntToRecord instance, +) => <String, dynamic>{ + 'value': instance.value?.map( + (k, e) => MapEntry(k.toString(), <String, dynamic>{ + r'$1': e.$1, + r'$2': e.$2, + 'truth': e.truth, + }), + ), +}; SimpleClassOfDateTimeToRecord _$SimpleClassOfDateTimeToRecordFromJson( - Map<String, dynamic> json) => - SimpleClassOfDateTimeToRecord( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry( - DateTime.parse(k), - _$recordConvert( - e, - ($jsonValue) => ( - ($jsonValue[r'$1'] as num).toInt(), - $jsonValue[r'$2'] as String, - truth: $jsonValue['truth'] as bool, - ), - )), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfDateTimeToRecord( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry( + DateTime.parse(k), + _$recordConvert( + e, + ($jsonValue) => ( + ($jsonValue[r'$1'] as num).toInt(), + $jsonValue[r'$2'] as String, + truth: $jsonValue['truth'] as bool, + ), + ), + ), + ), +); Map<String, dynamic> _$SimpleClassOfDateTimeToRecordToJson( - SimpleClassOfDateTimeToRecord instance) => - <String, dynamic>{ - 'value': instance.value - .map((k, e) => MapEntry(k.toIso8601String(), <String, dynamic>{ - r'$1': e.$1, - r'$2': e.$2, - 'truth': e.truth, - })), - }; + SimpleClassOfDateTimeToRecord instance, +) => <String, dynamic>{ + 'value': instance.value.map( + (k, e) => MapEntry(k.toIso8601String(), <String, dynamic>{ + r'$1': e.$1, + r'$2': e.$2, + 'truth': e.truth, + }), + ), +}; SimpleClassNullableOfDateTimeToRecord - _$SimpleClassNullableOfDateTimeToRecordFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDateTimeToRecord( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry( - DateTime.parse(k), - _$recordConvert( - e, - ($jsonValue) => ( - ($jsonValue[r'$1'] as num).toInt(), - $jsonValue[r'$2'] as String, - truth: $jsonValue['truth'] as bool, - ), - )), +_$SimpleClassNullableOfDateTimeToRecordFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfDateTimeToRecord( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry( + DateTime.parse(k), + _$recordConvert( + e, + ($jsonValue) => ( + ($jsonValue[r'$1'] as num).toInt(), + $jsonValue[r'$2'] as String, + truth: $jsonValue['truth'] as bool, + ), ), - ); + ), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfDateTimeToRecordToJson( - SimpleClassNullableOfDateTimeToRecord instance) => - <String, dynamic>{ - 'value': instance.value - ?.map((k, e) => MapEntry(k.toIso8601String(), <String, dynamic>{ - r'$1': e.$1, - r'$2': e.$2, - 'truth': e.truth, - })), - }; + SimpleClassNullableOfDateTimeToRecord instance, +) => <String, dynamic>{ + 'value': instance.value?.map( + (k, e) => MapEntry(k.toIso8601String(), <String, dynamic>{ + r'$1': e.$1, + r'$2': e.$2, + 'truth': e.truth, + }), + ), +}; SimpleClassOfDynamicToRecord _$SimpleClassOfDynamicToRecordFromJson( - Map<String, dynamic> json) => - SimpleClassOfDynamicToRecord( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry( - k, - _$recordConvert( - e, - ($jsonValue) => ( - ($jsonValue[r'$1'] as num).toInt(), - $jsonValue[r'$2'] as String, - truth: $jsonValue['truth'] as bool, - ), - )), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfDynamicToRecord( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry( + k, + _$recordConvert( + e, + ($jsonValue) => ( + ($jsonValue[r'$1'] as num).toInt(), + $jsonValue[r'$2'] as String, + truth: $jsonValue['truth'] as bool, + ), + ), + ), + ), +); Map<String, dynamic> _$SimpleClassOfDynamicToRecordToJson( - SimpleClassOfDynamicToRecord instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k, <String, dynamic>{ - r'$1': e.$1, - r'$2': e.$2, - 'truth': e.truth, - })), - }; + SimpleClassOfDynamicToRecord instance, +) => <String, dynamic>{ + 'value': instance.value.map( + (k, e) => MapEntry(k, <String, dynamic>{ + r'$1': e.$1, + r'$2': e.$2, + 'truth': e.truth, + }), + ), +}; SimpleClassNullableOfDynamicToRecord - _$SimpleClassNullableOfDynamicToRecordFromJson(Map<String, dynamic> json) => - SimpleClassNullableOfDynamicToRecord( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry( - k, - _$recordConvert( - e, - ($jsonValue) => ( - ($jsonValue[r'$1'] as num).toInt(), - $jsonValue[r'$2'] as String, - truth: $jsonValue['truth'] as bool, - ), - )), +_$SimpleClassNullableOfDynamicToRecordFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfDynamicToRecord( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry( + k, + _$recordConvert( + e, + ($jsonValue) => ( + ($jsonValue[r'$1'] as num).toInt(), + $jsonValue[r'$2'] as String, + truth: $jsonValue['truth'] as bool, + ), ), - ); + ), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfDynamicToRecordToJson( - SimpleClassNullableOfDynamicToRecord instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k, <String, dynamic>{ - r'$1': e.$1, - r'$2': e.$2, - 'truth': e.truth, - })), - }; + SimpleClassNullableOfDynamicToRecord instance, +) => <String, dynamic>{ + 'value': instance.value?.map( + (k, e) => MapEntry(k, <String, dynamic>{ + r'$1': e.$1, + r'$2': e.$2, + 'truth': e.truth, + }), + ), +}; SimpleClassOfEnumTypeToRecord _$SimpleClassOfEnumTypeToRecordFromJson( - Map<String, dynamic> json) => - SimpleClassOfEnumTypeToRecord( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry( - $enumDecode(_$EnumTypeEnumMap, k), - _$recordConvert( - e, - ($jsonValue) => ( - ($jsonValue[r'$1'] as num).toInt(), - $jsonValue[r'$2'] as String, - truth: $jsonValue['truth'] as bool, - ), - )), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfEnumTypeToRecord( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry( + $enumDecode(_$EnumTypeEnumMap, k), + _$recordConvert( + e, + ($jsonValue) => ( + ($jsonValue[r'$1'] as num).toInt(), + $jsonValue[r'$2'] as String, + truth: $jsonValue['truth'] as bool, + ), + ), + ), + ), +); Map<String, dynamic> _$SimpleClassOfEnumTypeToRecordToJson( - SimpleClassOfEnumTypeToRecord instance) => - <String, dynamic>{ - 'value': instance.value - .map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, <String, dynamic>{ - r'$1': e.$1, - r'$2': e.$2, - 'truth': e.truth, - })), - }; + SimpleClassOfEnumTypeToRecord instance, +) => <String, dynamic>{ + 'value': instance.value.map( + (k, e) => MapEntry(_$EnumTypeEnumMap[k]!, <String, dynamic>{ + r'$1': e.$1, + r'$2': e.$2, + 'truth': e.truth, + }), + ), +}; SimpleClassNullableOfEnumTypeToRecord - _$SimpleClassNullableOfEnumTypeToRecordFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfEnumTypeToRecord( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry( - $enumDecode(_$EnumTypeEnumMap, k), - _$recordConvert( - e, - ($jsonValue) => ( - ($jsonValue[r'$1'] as num).toInt(), - $jsonValue[r'$2'] as String, - truth: $jsonValue['truth'] as bool, - ), - )), +_$SimpleClassNullableOfEnumTypeToRecordFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfEnumTypeToRecord( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry( + $enumDecode(_$EnumTypeEnumMap, k), + _$recordConvert( + e, + ($jsonValue) => ( + ($jsonValue[r'$1'] as num).toInt(), + $jsonValue[r'$2'] as String, + truth: $jsonValue['truth'] as bool, + ), ), - ); + ), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfEnumTypeToRecordToJson( - SimpleClassNullableOfEnumTypeToRecord instance) => - <String, dynamic>{ - 'value': instance.value - ?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, <String, dynamic>{ - r'$1': e.$1, - r'$2': e.$2, - 'truth': e.truth, - })), - }; + SimpleClassNullableOfEnumTypeToRecord instance, +) => <String, dynamic>{ + 'value': instance.value?.map( + (k, e) => MapEntry(_$EnumTypeEnumMap[k]!, <String, dynamic>{ + r'$1': e.$1, + r'$2': e.$2, + 'truth': e.truth, + }), + ), +}; SimpleClassOfIntToRecord _$SimpleClassOfIntToRecordFromJson( - Map<String, dynamic> json) => - SimpleClassOfIntToRecord( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry( - int.parse(k), - _$recordConvert( - e, - ($jsonValue) => ( - ($jsonValue[r'$1'] as num).toInt(), - $jsonValue[r'$2'] as String, - truth: $jsonValue['truth'] as bool, - ), - )), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfIntToRecord( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry( + int.parse(k), + _$recordConvert( + e, + ($jsonValue) => ( + ($jsonValue[r'$1'] as num).toInt(), + $jsonValue[r'$2'] as String, + truth: $jsonValue['truth'] as bool, + ), + ), + ), + ), +); Map<String, dynamic> _$SimpleClassOfIntToRecordToJson( - SimpleClassOfIntToRecord instance) => - <String, dynamic>{ - 'value': - instance.value.map((k, e) => MapEntry(k.toString(), <String, dynamic>{ - r'$1': e.$1, - r'$2': e.$2, - 'truth': e.truth, - })), - }; + SimpleClassOfIntToRecord instance, +) => <String, dynamic>{ + 'value': instance.value.map( + (k, e) => MapEntry(k.toString(), <String, dynamic>{ + r'$1': e.$1, + r'$2': e.$2, + 'truth': e.truth, + }), + ), +}; SimpleClassNullableOfIntToRecord _$SimpleClassNullableOfIntToRecordFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfIntToRecord( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry( - int.parse(k), - _$recordConvert( - e, - ($jsonValue) => ( - ($jsonValue[r'$1'] as num).toInt(), - $jsonValue[r'$2'] as String, - truth: $jsonValue['truth'] as bool, - ), - )), - ), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfIntToRecord( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry( + int.parse(k), + _$recordConvert( + e, + ($jsonValue) => ( + ($jsonValue[r'$1'] as num).toInt(), + $jsonValue[r'$2'] as String, + truth: $jsonValue['truth'] as bool, + ), + ), + ), + ), +); Map<String, dynamic> _$SimpleClassNullableOfIntToRecordToJson( - SimpleClassNullableOfIntToRecord instance) => - <String, dynamic>{ - 'value': instance.value - ?.map((k, e) => MapEntry(k.toString(), <String, dynamic>{ - r'$1': e.$1, - r'$2': e.$2, - 'truth': e.truth, - })), - }; + SimpleClassNullableOfIntToRecord instance, +) => <String, dynamic>{ + 'value': instance.value?.map( + (k, e) => MapEntry(k.toString(), <String, dynamic>{ + r'$1': e.$1, + r'$2': e.$2, + 'truth': e.truth, + }), + ), +}; SimpleClassOfObjectToRecord _$SimpleClassOfObjectToRecordFromJson( - Map<String, dynamic> json) => - SimpleClassOfObjectToRecord( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry( - k, - _$recordConvert( - e, - ($jsonValue) => ( - ($jsonValue[r'$1'] as num).toInt(), - $jsonValue[r'$2'] as String, - truth: $jsonValue['truth'] as bool, - ), - )), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfObjectToRecord( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry( + k, + _$recordConvert( + e, + ($jsonValue) => ( + ($jsonValue[r'$1'] as num).toInt(), + $jsonValue[r'$2'] as String, + truth: $jsonValue['truth'] as bool, + ), + ), + ), + ), +); Map<String, dynamic> _$SimpleClassOfObjectToRecordToJson( - SimpleClassOfObjectToRecord instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k, <String, dynamic>{ - r'$1': e.$1, - r'$2': e.$2, - 'truth': e.truth, - })), - }; + SimpleClassOfObjectToRecord instance, +) => <String, dynamic>{ + 'value': instance.value.map( + (k, e) => MapEntry(k, <String, dynamic>{ + r'$1': e.$1, + r'$2': e.$2, + 'truth': e.truth, + }), + ), +}; SimpleClassNullableOfObjectToRecord - _$SimpleClassNullableOfObjectToRecordFromJson(Map<String, dynamic> json) => - SimpleClassNullableOfObjectToRecord( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry( - k, - _$recordConvert( - e, - ($jsonValue) => ( - ($jsonValue[r'$1'] as num).toInt(), - $jsonValue[r'$2'] as String, - truth: $jsonValue['truth'] as bool, - ), - )), +_$SimpleClassNullableOfObjectToRecordFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfObjectToRecord( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry( + k, + _$recordConvert( + e, + ($jsonValue) => ( + ($jsonValue[r'$1'] as num).toInt(), + $jsonValue[r'$2'] as String, + truth: $jsonValue['truth'] as bool, + ), ), - ); + ), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfObjectToRecordToJson( - SimpleClassNullableOfObjectToRecord instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k, <String, dynamic>{ - r'$1': e.$1, - r'$2': e.$2, - 'truth': e.truth, - })), - }; + SimpleClassNullableOfObjectToRecord instance, +) => <String, dynamic>{ + 'value': instance.value?.map( + (k, e) => MapEntry(k, <String, dynamic>{ + r'$1': e.$1, + r'$2': e.$2, + 'truth': e.truth, + }), + ), +}; SimpleClassOfStringToRecord _$SimpleClassOfStringToRecordFromJson( - Map<String, dynamic> json) => - SimpleClassOfStringToRecord( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry( - k, - _$recordConvert( - e, - ($jsonValue) => ( - ($jsonValue[r'$1'] as num).toInt(), - $jsonValue[r'$2'] as String, - truth: $jsonValue['truth'] as bool, - ), - )), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfStringToRecord( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry( + k, + _$recordConvert( + e, + ($jsonValue) => ( + ($jsonValue[r'$1'] as num).toInt(), + $jsonValue[r'$2'] as String, + truth: $jsonValue['truth'] as bool, + ), + ), + ), + ), +); Map<String, dynamic> _$SimpleClassOfStringToRecordToJson( - SimpleClassOfStringToRecord instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k, <String, dynamic>{ - r'$1': e.$1, - r'$2': e.$2, - 'truth': e.truth, - })), - }; + SimpleClassOfStringToRecord instance, +) => <String, dynamic>{ + 'value': instance.value.map( + (k, e) => MapEntry(k, <String, dynamic>{ + r'$1': e.$1, + r'$2': e.$2, + 'truth': e.truth, + }), + ), +}; SimpleClassNullableOfStringToRecord - _$SimpleClassNullableOfStringToRecordFromJson(Map<String, dynamic> json) => - SimpleClassNullableOfStringToRecord( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry( - k, - _$recordConvert( - e, - ($jsonValue) => ( - ($jsonValue[r'$1'] as num).toInt(), - $jsonValue[r'$2'] as String, - truth: $jsonValue['truth'] as bool, - ), - )), +_$SimpleClassNullableOfStringToRecordFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfStringToRecord( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry( + k, + _$recordConvert( + e, + ($jsonValue) => ( + ($jsonValue[r'$1'] as num).toInt(), + $jsonValue[r'$2'] as String, + truth: $jsonValue['truth'] as bool, + ), ), - ); + ), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfStringToRecordToJson( - SimpleClassNullableOfStringToRecord instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k, <String, dynamic>{ - r'$1': e.$1, - r'$2': e.$2, - 'truth': e.truth, - })), - }; + SimpleClassNullableOfStringToRecord instance, +) => <String, dynamic>{ + 'value': instance.value?.map( + (k, e) => MapEntry(k, <String, dynamic>{ + r'$1': e.$1, + r'$2': e.$2, + 'truth': e.truth, + }), + ), +}; SimpleClassOfUriToRecord _$SimpleClassOfUriToRecordFromJson( - Map<String, dynamic> json) => - SimpleClassOfUriToRecord( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry( - Uri.parse(k), - _$recordConvert( - e, - ($jsonValue) => ( - ($jsonValue[r'$1'] as num).toInt(), - $jsonValue[r'$2'] as String, - truth: $jsonValue['truth'] as bool, - ), - )), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfUriToRecord( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry( + Uri.parse(k), + _$recordConvert( + e, + ($jsonValue) => ( + ($jsonValue[r'$1'] as num).toInt(), + $jsonValue[r'$2'] as String, + truth: $jsonValue['truth'] as bool, + ), + ), + ), + ), +); Map<String, dynamic> _$SimpleClassOfUriToRecordToJson( - SimpleClassOfUriToRecord instance) => - <String, dynamic>{ - 'value': - instance.value.map((k, e) => MapEntry(k.toString(), <String, dynamic>{ - r'$1': e.$1, - r'$2': e.$2, - 'truth': e.truth, - })), - }; + SimpleClassOfUriToRecord instance, +) => <String, dynamic>{ + 'value': instance.value.map( + (k, e) => MapEntry(k.toString(), <String, dynamic>{ + r'$1': e.$1, + r'$2': e.$2, + 'truth': e.truth, + }), + ), +}; SimpleClassNullableOfUriToRecord _$SimpleClassNullableOfUriToRecordFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfUriToRecord( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry( - Uri.parse(k), - _$recordConvert( - e, - ($jsonValue) => ( - ($jsonValue[r'$1'] as num).toInt(), - $jsonValue[r'$2'] as String, - truth: $jsonValue['truth'] as bool, - ), - )), - ), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfUriToRecord( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry( + Uri.parse(k), + _$recordConvert( + e, + ($jsonValue) => ( + ($jsonValue[r'$1'] as num).toInt(), + $jsonValue[r'$2'] as String, + truth: $jsonValue['truth'] as bool, + ), + ), + ), + ), +); Map<String, dynamic> _$SimpleClassNullableOfUriToRecordToJson( - SimpleClassNullableOfUriToRecord instance) => - <String, dynamic>{ - 'value': instance.value - ?.map((k, e) => MapEntry(k.toString(), <String, dynamic>{ - r'$1': e.$1, - r'$2': e.$2, - 'truth': e.truth, - })), - }; + SimpleClassNullableOfUriToRecord instance, +) => <String, dynamic>{ + 'value': instance.value?.map( + (k, e) => MapEntry(k.toString(), <String, dynamic>{ + r'$1': e.$1, + r'$2': e.$2, + 'truth': e.truth, + }), + ), +}; SimpleClassOfBigIntToString _$SimpleClassOfBigIntToStringFromJson( - Map<String, dynamic> json) => - SimpleClassOfBigIntToString( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(BigInt.parse(k), e as String), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfBigIntToString( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(BigInt.parse(k), e as String), + ), +); Map<String, dynamic> _$SimpleClassOfBigIntToStringToJson( - SimpleClassOfBigIntToString instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassOfBigIntToString instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassNullableOfBigIntToString - _$SimpleClassNullableOfBigIntToStringFromJson(Map<String, dynamic> json) => - SimpleClassNullableOfBigIntToString( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(BigInt.parse(k), e as String), - ), - ); +_$SimpleClassNullableOfBigIntToStringFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfBigIntToString( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(BigInt.parse(k), e as String), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfBigIntToStringToJson( - SimpleClassNullableOfBigIntToString instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassNullableOfBigIntToString instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassOfDateTimeToString _$SimpleClassOfDateTimeToStringFromJson( - Map<String, dynamic> json) => - SimpleClassOfDateTimeToString( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(DateTime.parse(k), e as String), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfDateTimeToString( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(DateTime.parse(k), e as String), + ), +); Map<String, dynamic> _$SimpleClassOfDateTimeToStringToJson( - SimpleClassOfDateTimeToString instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toIso8601String(), e)), - }; + SimpleClassOfDateTimeToString instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toIso8601String(), e)), +}; SimpleClassNullableOfDateTimeToString - _$SimpleClassNullableOfDateTimeToStringFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDateTimeToString( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(DateTime.parse(k), e as String), - ), - ); +_$SimpleClassNullableOfDateTimeToStringFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfDateTimeToString( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(DateTime.parse(k), e as String), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfDateTimeToStringToJson( - SimpleClassNullableOfDateTimeToString instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toIso8601String(), e)), - }; + SimpleClassNullableOfDateTimeToString instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toIso8601String(), e)), +}; SimpleClassOfDynamicToString _$SimpleClassOfDynamicToStringFromJson( - Map<String, dynamic> json) => - SimpleClassOfDynamicToString( - Map<String, String>.from(json['value'] as Map), - ); + Map<String, dynamic> json, +) => SimpleClassOfDynamicToString( + Map<String, String>.from(json['value'] as Map), +); Map<String, dynamic> _$SimpleClassOfDynamicToStringToJson( - SimpleClassOfDynamicToString instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassOfDynamicToString instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassNullableOfDynamicToString - _$SimpleClassNullableOfDynamicToStringFromJson(Map<String, dynamic> json) => - SimpleClassNullableOfDynamicToString( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, e as String), - ), - ); +_$SimpleClassNullableOfDynamicToStringFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfDynamicToString( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, e as String), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfDynamicToStringToJson( - SimpleClassNullableOfDynamicToString instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassNullableOfDynamicToString instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassOfEnumTypeToString _$SimpleClassOfEnumTypeToStringFromJson( - Map<String, dynamic> json) => - SimpleClassOfEnumTypeToString( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e as String), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfEnumTypeToString( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e as String), + ), +); Map<String, dynamic> _$SimpleClassOfEnumTypeToStringToJson( - SimpleClassOfEnumTypeToString instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), - }; + SimpleClassOfEnumTypeToString instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), +}; SimpleClassNullableOfEnumTypeToString - _$SimpleClassNullableOfEnumTypeToStringFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfEnumTypeToString( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e as String), - ), - ); +_$SimpleClassNullableOfEnumTypeToStringFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfEnumTypeToString( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e as String), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfEnumTypeToStringToJson( - SimpleClassNullableOfEnumTypeToString instance) => - <String, dynamic>{ - 'value': - instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), - }; + SimpleClassNullableOfEnumTypeToString instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), +}; SimpleClassOfIntToString _$SimpleClassOfIntToStringFromJson( - Map<String, dynamic> json) => - SimpleClassOfIntToString( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(int.parse(k), e as String), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfIntToString( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(int.parse(k), e as String), + ), +); Map<String, dynamic> _$SimpleClassOfIntToStringToJson( - SimpleClassOfIntToString instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassOfIntToString instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassNullableOfIntToString _$SimpleClassNullableOfIntToStringFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfIntToString( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(int.parse(k), e as String), - ), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfIntToString( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(int.parse(k), e as String), + ), +); Map<String, dynamic> _$SimpleClassNullableOfIntToStringToJson( - SimpleClassNullableOfIntToString instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassNullableOfIntToString instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassOfObjectToString _$SimpleClassOfObjectToStringFromJson( - Map<String, dynamic> json) => - SimpleClassOfObjectToString( - Map<String, String>.from(json['value'] as Map), - ); + Map<String, dynamic> json, +) => + SimpleClassOfObjectToString(Map<String, String>.from(json['value'] as Map)); Map<String, dynamic> _$SimpleClassOfObjectToStringToJson( - SimpleClassOfObjectToString instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassOfObjectToString instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassNullableOfObjectToString - _$SimpleClassNullableOfObjectToStringFromJson(Map<String, dynamic> json) => - SimpleClassNullableOfObjectToString( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, e as String), - ), - ); +_$SimpleClassNullableOfObjectToStringFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfObjectToString( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, e as String), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfObjectToStringToJson( - SimpleClassNullableOfObjectToString instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassNullableOfObjectToString instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassOfStringToString _$SimpleClassOfStringToStringFromJson( - Map<String, dynamic> json) => - SimpleClassOfStringToString( - Map<String, String>.from(json['value'] as Map), - ); + Map<String, dynamic> json, +) => + SimpleClassOfStringToString(Map<String, String>.from(json['value'] as Map)); Map<String, dynamic> _$SimpleClassOfStringToStringToJson( - SimpleClassOfStringToString instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassOfStringToString instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassNullableOfStringToString - _$SimpleClassNullableOfStringToStringFromJson(Map<String, dynamic> json) => - SimpleClassNullableOfStringToString( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, e as String), - ), - ); +_$SimpleClassNullableOfStringToStringFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfStringToString( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, e as String), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfStringToStringToJson( - SimpleClassNullableOfStringToString instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassNullableOfStringToString instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassOfUriToString _$SimpleClassOfUriToStringFromJson( - Map<String, dynamic> json) => - SimpleClassOfUriToString( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(Uri.parse(k), e as String), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfUriToString( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(Uri.parse(k), e as String), + ), +); Map<String, dynamic> _$SimpleClassOfUriToStringToJson( - SimpleClassOfUriToString instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassOfUriToString instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassNullableOfUriToString _$SimpleClassNullableOfUriToStringFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfUriToString( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(Uri.parse(k), e as String), - ), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfUriToString( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(Uri.parse(k), e as String), + ), +); Map<String, dynamic> _$SimpleClassNullableOfUriToStringToJson( - SimpleClassNullableOfUriToString instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassNullableOfUriToString instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassOfBigIntToStringNullable - _$SimpleClassOfBigIntToStringNullableFromJson(Map<String, dynamic> json) => - SimpleClassOfBigIntToStringNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(BigInt.parse(k), e as String?), - ), - ); +_$SimpleClassOfBigIntToStringNullableFromJson(Map<String, dynamic> json) => + SimpleClassOfBigIntToStringNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(BigInt.parse(k), e as String?), + ), + ); Map<String, dynamic> _$SimpleClassOfBigIntToStringNullableToJson( - SimpleClassOfBigIntToStringNullable instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassOfBigIntToStringNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassNullableOfBigIntToStringNullable - _$SimpleClassNullableOfBigIntToStringNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfBigIntToStringNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(BigInt.parse(k), e as String?), - ), - ); +_$SimpleClassNullableOfBigIntToStringNullableFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfBigIntToStringNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(BigInt.parse(k), e as String?), + ), +); Map<String, dynamic> _$SimpleClassNullableOfBigIntToStringNullableToJson( - SimpleClassNullableOfBigIntToStringNullable instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassNullableOfBigIntToStringNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassOfDateTimeToStringNullable - _$SimpleClassOfDateTimeToStringNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfDateTimeToStringNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(DateTime.parse(k), e as String?), - ), - ); +_$SimpleClassOfDateTimeToStringNullableFromJson(Map<String, dynamic> json) => + SimpleClassOfDateTimeToStringNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(DateTime.parse(k), e as String?), + ), + ); Map<String, dynamic> _$SimpleClassOfDateTimeToStringNullableToJson( - SimpleClassOfDateTimeToStringNullable instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toIso8601String(), e)), - }; + SimpleClassOfDateTimeToStringNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toIso8601String(), e)), +}; SimpleClassNullableOfDateTimeToStringNullable - _$SimpleClassNullableOfDateTimeToStringNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDateTimeToStringNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(DateTime.parse(k), e as String?), - ), - ); +_$SimpleClassNullableOfDateTimeToStringNullableFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfDateTimeToStringNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(DateTime.parse(k), e as String?), + ), +); Map<String, dynamic> _$SimpleClassNullableOfDateTimeToStringNullableToJson( - SimpleClassNullableOfDateTimeToStringNullable instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toIso8601String(), e)), - }; + SimpleClassNullableOfDateTimeToStringNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toIso8601String(), e)), +}; SimpleClassOfDynamicToStringNullable - _$SimpleClassOfDynamicToStringNullableFromJson(Map<String, dynamic> json) => - SimpleClassOfDynamicToStringNullable( - Map<String, String?>.from(json['value'] as Map), - ); +_$SimpleClassOfDynamicToStringNullableFromJson(Map<String, dynamic> json) => + SimpleClassOfDynamicToStringNullable( + Map<String, String?>.from(json['value'] as Map), + ); Map<String, dynamic> _$SimpleClassOfDynamicToStringNullableToJson( - SimpleClassOfDynamicToStringNullable instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassOfDynamicToStringNullable instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassNullableOfDynamicToStringNullable - _$SimpleClassNullableOfDynamicToStringNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDynamicToStringNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, e as String?), - ), - ); +_$SimpleClassNullableOfDynamicToStringNullableFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfDynamicToStringNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, e as String?), + ), +); Map<String, dynamic> _$SimpleClassNullableOfDynamicToStringNullableToJson( - SimpleClassNullableOfDynamicToStringNullable instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassNullableOfDynamicToStringNullable instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassOfEnumTypeToStringNullable - _$SimpleClassOfEnumTypeToStringNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfEnumTypeToStringNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e as String?), - ), - ); +_$SimpleClassOfEnumTypeToStringNullableFromJson(Map<String, dynamic> json) => + SimpleClassOfEnumTypeToStringNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e as String?), + ), + ); Map<String, dynamic> _$SimpleClassOfEnumTypeToStringNullableToJson( - SimpleClassOfEnumTypeToStringNullable instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), - }; + SimpleClassOfEnumTypeToStringNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), +}; SimpleClassNullableOfEnumTypeToStringNullable - _$SimpleClassNullableOfEnumTypeToStringNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfEnumTypeToStringNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e as String?), - ), - ); +_$SimpleClassNullableOfEnumTypeToStringNullableFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfEnumTypeToStringNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), e as String?), + ), +); Map<String, dynamic> _$SimpleClassNullableOfEnumTypeToStringNullableToJson( - SimpleClassNullableOfEnumTypeToStringNullable instance) => - <String, dynamic>{ - 'value': - instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), - }; + SimpleClassNullableOfEnumTypeToStringNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e)), +}; SimpleClassOfIntToStringNullable _$SimpleClassOfIntToStringNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfIntToStringNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(int.parse(k), e as String?), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfIntToStringNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(int.parse(k), e as String?), + ), +); Map<String, dynamic> _$SimpleClassOfIntToStringNullableToJson( - SimpleClassOfIntToStringNullable instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassOfIntToStringNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassNullableOfIntToStringNullable - _$SimpleClassNullableOfIntToStringNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfIntToStringNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(int.parse(k), e as String?), - ), - ); +_$SimpleClassNullableOfIntToStringNullableFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfIntToStringNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(int.parse(k), e as String?), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfIntToStringNullableToJson( - SimpleClassNullableOfIntToStringNullable instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassNullableOfIntToStringNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassOfObjectToStringNullable - _$SimpleClassOfObjectToStringNullableFromJson(Map<String, dynamic> json) => - SimpleClassOfObjectToStringNullable( - Map<String, String?>.from(json['value'] as Map), - ); +_$SimpleClassOfObjectToStringNullableFromJson(Map<String, dynamic> json) => + SimpleClassOfObjectToStringNullable( + Map<String, String?>.from(json['value'] as Map), + ); Map<String, dynamic> _$SimpleClassOfObjectToStringNullableToJson( - SimpleClassOfObjectToStringNullable instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassOfObjectToStringNullable instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassNullableOfObjectToStringNullable - _$SimpleClassNullableOfObjectToStringNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfObjectToStringNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, e as String?), - ), - ); +_$SimpleClassNullableOfObjectToStringNullableFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfObjectToStringNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, e as String?), + ), +); Map<String, dynamic> _$SimpleClassNullableOfObjectToStringNullableToJson( - SimpleClassNullableOfObjectToStringNullable instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassNullableOfObjectToStringNullable instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassOfStringToStringNullable - _$SimpleClassOfStringToStringNullableFromJson(Map<String, dynamic> json) => - SimpleClassOfStringToStringNullable( - Map<String, String?>.from(json['value'] as Map), - ); +_$SimpleClassOfStringToStringNullableFromJson(Map<String, dynamic> json) => + SimpleClassOfStringToStringNullable( + Map<String, String?>.from(json['value'] as Map), + ); Map<String, dynamic> _$SimpleClassOfStringToStringNullableToJson( - SimpleClassOfStringToStringNullable instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassOfStringToStringNullable instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassNullableOfStringToStringNullable - _$SimpleClassNullableOfStringToStringNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfStringToStringNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, e as String?), - ), - ); +_$SimpleClassNullableOfStringToStringNullableFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfStringToStringNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, e as String?), + ), +); Map<String, dynamic> _$SimpleClassNullableOfStringToStringNullableToJson( - SimpleClassNullableOfStringToStringNullable instance) => - <String, dynamic>{ - 'value': instance.value, - }; + SimpleClassNullableOfStringToStringNullable instance, +) => <String, dynamic>{'value': instance.value}; SimpleClassOfUriToStringNullable _$SimpleClassOfUriToStringNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfUriToStringNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(Uri.parse(k), e as String?), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfUriToStringNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(Uri.parse(k), e as String?), + ), +); Map<String, dynamic> _$SimpleClassOfUriToStringNullableToJson( - SimpleClassOfUriToStringNullable instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassOfUriToStringNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassNullableOfUriToStringNullable - _$SimpleClassNullableOfUriToStringNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfUriToStringNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(Uri.parse(k), e as String?), - ), - ); +_$SimpleClassNullableOfUriToStringNullableFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfUriToStringNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(Uri.parse(k), e as String?), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfUriToStringNullableToJson( - SimpleClassNullableOfUriToStringNullable instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), - }; + SimpleClassNullableOfUriToStringNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e)), +}; SimpleClassOfBigIntToUri _$SimpleClassOfBigIntToUriFromJson( - Map<String, dynamic> json) => - SimpleClassOfBigIntToUri( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(BigInt.parse(k), Uri.parse(e as String)), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfBigIntToUri( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(BigInt.parse(k), Uri.parse(e as String)), + ), +); Map<String, dynamic> _$SimpleClassOfBigIntToUriToJson( - SimpleClassOfBigIntToUri instance) => - <String, dynamic>{ - 'value': - instance.value.map((k, e) => MapEntry(k.toString(), e.toString())), - }; + SimpleClassOfBigIntToUri instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e.toString())), +}; SimpleClassNullableOfBigIntToUri _$SimpleClassNullableOfBigIntToUriFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfBigIntToUri( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(BigInt.parse(k), Uri.parse(e as String)), - ), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfBigIntToUri( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(BigInt.parse(k), Uri.parse(e as String)), + ), +); Map<String, dynamic> _$SimpleClassNullableOfBigIntToUriToJson( - SimpleClassNullableOfBigIntToUri instance) => - <String, dynamic>{ - 'value': - instance.value?.map((k, e) => MapEntry(k.toString(), e.toString())), - }; + SimpleClassNullableOfBigIntToUri instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e.toString())), +}; SimpleClassOfDateTimeToUri _$SimpleClassOfDateTimeToUriFromJson( - Map<String, dynamic> json) => - SimpleClassOfDateTimeToUri( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(DateTime.parse(k), Uri.parse(e as String)), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfDateTimeToUri( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(DateTime.parse(k), Uri.parse(e as String)), + ), +); Map<String, dynamic> _$SimpleClassOfDateTimeToUriToJson( - SimpleClassOfDateTimeToUri instance) => - <String, dynamic>{ - 'value': instance.value - .map((k, e) => MapEntry(k.toIso8601String(), e.toString())), - }; + SimpleClassOfDateTimeToUri instance, +) => <String, dynamic>{ + 'value': instance.value.map( + (k, e) => MapEntry(k.toIso8601String(), e.toString()), + ), +}; SimpleClassNullableOfDateTimeToUri _$SimpleClassNullableOfDateTimeToUriFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDateTimeToUri( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(DateTime.parse(k), Uri.parse(e as String)), - ), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfDateTimeToUri( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(DateTime.parse(k), Uri.parse(e as String)), + ), +); Map<String, dynamic> _$SimpleClassNullableOfDateTimeToUriToJson( - SimpleClassNullableOfDateTimeToUri instance) => - <String, dynamic>{ - 'value': instance.value - ?.map((k, e) => MapEntry(k.toIso8601String(), e.toString())), - }; + SimpleClassNullableOfDateTimeToUri instance, +) => <String, dynamic>{ + 'value': instance.value?.map( + (k, e) => MapEntry(k.toIso8601String(), e.toString()), + ), +}; SimpleClassOfDynamicToUri _$SimpleClassOfDynamicToUriFromJson( - Map<String, dynamic> json) => - SimpleClassOfDynamicToUri( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(k, Uri.parse(e as String)), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfDynamicToUri( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(k, Uri.parse(e as String)), + ), +); Map<String, dynamic> _$SimpleClassOfDynamicToUriToJson( - SimpleClassOfDynamicToUri instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k, e.toString())), - }; + SimpleClassOfDynamicToUri instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k, e.toString())), +}; SimpleClassNullableOfDynamicToUri _$SimpleClassNullableOfDynamicToUriFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDynamicToUri( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, Uri.parse(e as String)), - ), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfDynamicToUri( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, Uri.parse(e as String)), + ), +); Map<String, dynamic> _$SimpleClassNullableOfDynamicToUriToJson( - SimpleClassNullableOfDynamicToUri instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k, e.toString())), - }; + SimpleClassNullableOfDynamicToUri instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k, e.toString())), +}; SimpleClassOfEnumTypeToUri _$SimpleClassOfEnumTypeToUriFromJson( - Map<String, dynamic> json) => - SimpleClassOfEnumTypeToUri( - (json['value'] as Map<String, dynamic>).map( - (k, e) => - MapEntry($enumDecode(_$EnumTypeEnumMap, k), Uri.parse(e as String)), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfEnumTypeToUri( + (json['value'] as Map<String, dynamic>).map( + (k, e) => + MapEntry($enumDecode(_$EnumTypeEnumMap, k), Uri.parse(e as String)), + ), +); Map<String, dynamic> _$SimpleClassOfEnumTypeToUriToJson( - SimpleClassOfEnumTypeToUri instance) => - <String, dynamic>{ - 'value': instance.value - .map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e.toString())), - }; + SimpleClassOfEnumTypeToUri instance, +) => <String, dynamic>{ + 'value': instance.value.map( + (k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e.toString()), + ), +}; SimpleClassNullableOfEnumTypeToUri _$SimpleClassNullableOfEnumTypeToUriFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfEnumTypeToUri( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => - MapEntry($enumDecode(_$EnumTypeEnumMap, k), Uri.parse(e as String)), - ), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfEnumTypeToUri( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => + MapEntry($enumDecode(_$EnumTypeEnumMap, k), Uri.parse(e as String)), + ), +); Map<String, dynamic> _$SimpleClassNullableOfEnumTypeToUriToJson( - SimpleClassNullableOfEnumTypeToUri instance) => - <String, dynamic>{ - 'value': instance.value - ?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e.toString())), - }; + SimpleClassNullableOfEnumTypeToUri instance, +) => <String, dynamic>{ + 'value': instance.value?.map( + (k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e.toString()), + ), +}; SimpleClassOfIntToUri _$SimpleClassOfIntToUriFromJson( - Map<String, dynamic> json) => - SimpleClassOfIntToUri( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(int.parse(k), Uri.parse(e as String)), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfIntToUri( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(int.parse(k), Uri.parse(e as String)), + ), +); Map<String, dynamic> _$SimpleClassOfIntToUriToJson( - SimpleClassOfIntToUri instance) => - <String, dynamic>{ - 'value': - instance.value.map((k, e) => MapEntry(k.toString(), e.toString())), - }; + SimpleClassOfIntToUri instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e.toString())), +}; SimpleClassNullableOfIntToUri _$SimpleClassNullableOfIntToUriFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfIntToUri( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(int.parse(k), Uri.parse(e as String)), - ), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfIntToUri( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(int.parse(k), Uri.parse(e as String)), + ), +); Map<String, dynamic> _$SimpleClassNullableOfIntToUriToJson( - SimpleClassNullableOfIntToUri instance) => - <String, dynamic>{ - 'value': - instance.value?.map((k, e) => MapEntry(k.toString(), e.toString())), - }; + SimpleClassNullableOfIntToUri instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e.toString())), +}; SimpleClassOfObjectToUri _$SimpleClassOfObjectToUriFromJson( - Map<String, dynamic> json) => - SimpleClassOfObjectToUri( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(k, Uri.parse(e as String)), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfObjectToUri( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(k, Uri.parse(e as String)), + ), +); Map<String, dynamic> _$SimpleClassOfObjectToUriToJson( - SimpleClassOfObjectToUri instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k, e.toString())), - }; + SimpleClassOfObjectToUri instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k, e.toString())), +}; SimpleClassNullableOfObjectToUri _$SimpleClassNullableOfObjectToUriFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfObjectToUri( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, Uri.parse(e as String)), - ), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfObjectToUri( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, Uri.parse(e as String)), + ), +); Map<String, dynamic> _$SimpleClassNullableOfObjectToUriToJson( - SimpleClassNullableOfObjectToUri instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k, e.toString())), - }; + SimpleClassNullableOfObjectToUri instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k, e.toString())), +}; SimpleClassOfStringToUri _$SimpleClassOfStringToUriFromJson( - Map<String, dynamic> json) => - SimpleClassOfStringToUri( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(k, Uri.parse(e as String)), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfStringToUri( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(k, Uri.parse(e as String)), + ), +); Map<String, dynamic> _$SimpleClassOfStringToUriToJson( - SimpleClassOfStringToUri instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k, e.toString())), - }; + SimpleClassOfStringToUri instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k, e.toString())), +}; SimpleClassNullableOfStringToUri _$SimpleClassNullableOfStringToUriFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfStringToUri( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, Uri.parse(e as String)), - ), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfStringToUri( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, Uri.parse(e as String)), + ), +); Map<String, dynamic> _$SimpleClassNullableOfStringToUriToJson( - SimpleClassNullableOfStringToUri instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k, e.toString())), - }; + SimpleClassNullableOfStringToUri instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k, e.toString())), +}; SimpleClassOfUriToUri _$SimpleClassOfUriToUriFromJson( - Map<String, dynamic> json) => - SimpleClassOfUriToUri( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(Uri.parse(k), Uri.parse(e as String)), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfUriToUri( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(Uri.parse(k), Uri.parse(e as String)), + ), +); Map<String, dynamic> _$SimpleClassOfUriToUriToJson( - SimpleClassOfUriToUri instance) => - <String, dynamic>{ - 'value': - instance.value.map((k, e) => MapEntry(k.toString(), e.toString())), - }; + SimpleClassOfUriToUri instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e.toString())), +}; SimpleClassNullableOfUriToUri _$SimpleClassNullableOfUriToUriFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfUriToUri( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(Uri.parse(k), Uri.parse(e as String)), - ), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfUriToUri( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(Uri.parse(k), Uri.parse(e as String)), + ), +); Map<String, dynamic> _$SimpleClassNullableOfUriToUriToJson( - SimpleClassNullableOfUriToUri instance) => - <String, dynamic>{ - 'value': - instance.value?.map((k, e) => MapEntry(k.toString(), e.toString())), - }; + SimpleClassNullableOfUriToUri instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e.toString())), +}; SimpleClassOfBigIntToUriNullable _$SimpleClassOfBigIntToUriNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfBigIntToUriNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry( - BigInt.parse(k), e == null ? null : Uri.parse(e as String)), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfBigIntToUriNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => + MapEntry(BigInt.parse(k), e == null ? null : Uri.parse(e as String)), + ), +); Map<String, dynamic> _$SimpleClassOfBigIntToUriNullableToJson( - SimpleClassOfBigIntToUriNullable instance) => - <String, dynamic>{ - 'value': - instance.value.map((k, e) => MapEntry(k.toString(), e?.toString())), - }; + SimpleClassOfBigIntToUriNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e?.toString())), +}; SimpleClassNullableOfBigIntToUriNullable - _$SimpleClassNullableOfBigIntToUriNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfBigIntToUriNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry( - BigInt.parse(k), e == null ? null : Uri.parse(e as String)), - ), - ); +_$SimpleClassNullableOfBigIntToUriNullableFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfBigIntToUriNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry( + BigInt.parse(k), + e == null ? null : Uri.parse(e as String), + ), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfBigIntToUriNullableToJson( - SimpleClassNullableOfBigIntToUriNullable instance) => - <String, dynamic>{ - 'value': - instance.value?.map((k, e) => MapEntry(k.toString(), e?.toString())), - }; + SimpleClassNullableOfBigIntToUriNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e?.toString())), +}; SimpleClassOfDateTimeToUriNullable _$SimpleClassOfDateTimeToUriNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfDateTimeToUriNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry( - DateTime.parse(k), e == null ? null : Uri.parse(e as String)), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfDateTimeToUriNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => + MapEntry(DateTime.parse(k), e == null ? null : Uri.parse(e as String)), + ), +); Map<String, dynamic> _$SimpleClassOfDateTimeToUriNullableToJson( - SimpleClassOfDateTimeToUriNullable instance) => - <String, dynamic>{ - 'value': instance.value - .map((k, e) => MapEntry(k.toIso8601String(), e?.toString())), - }; + SimpleClassOfDateTimeToUriNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map( + (k, e) => MapEntry(k.toIso8601String(), e?.toString()), + ), +}; SimpleClassNullableOfDateTimeToUriNullable - _$SimpleClassNullableOfDateTimeToUriNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDateTimeToUriNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry( - DateTime.parse(k), e == null ? null : Uri.parse(e as String)), - ), - ); +_$SimpleClassNullableOfDateTimeToUriNullableFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfDateTimeToUriNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => + MapEntry(DateTime.parse(k), e == null ? null : Uri.parse(e as String)), + ), +); Map<String, dynamic> _$SimpleClassNullableOfDateTimeToUriNullableToJson( - SimpleClassNullableOfDateTimeToUriNullable instance) => - <String, dynamic>{ - 'value': instance.value - ?.map((k, e) => MapEntry(k.toIso8601String(), e?.toString())), - }; + SimpleClassNullableOfDateTimeToUriNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map( + (k, e) => MapEntry(k.toIso8601String(), e?.toString()), + ), +}; SimpleClassOfDynamicToUriNullable _$SimpleClassOfDynamicToUriNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfDynamicToUriNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(k, e == null ? null : Uri.parse(e as String)), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfDynamicToUriNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(k, e == null ? null : Uri.parse(e as String)), + ), +); Map<String, dynamic> _$SimpleClassOfDynamicToUriNullableToJson( - SimpleClassOfDynamicToUriNullable instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k, e?.toString())), - }; + SimpleClassOfDynamicToUriNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k, e?.toString())), +}; SimpleClassNullableOfDynamicToUriNullable - _$SimpleClassNullableOfDynamicToUriNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDynamicToUriNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, e == null ? null : Uri.parse(e as String)), - ), - ); +_$SimpleClassNullableOfDynamicToUriNullableFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfDynamicToUriNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, e == null ? null : Uri.parse(e as String)), + ), +); Map<String, dynamic> _$SimpleClassNullableOfDynamicToUriNullableToJson( - SimpleClassNullableOfDynamicToUriNullable instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k, e?.toString())), - }; + SimpleClassNullableOfDynamicToUriNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k, e?.toString())), +}; SimpleClassOfEnumTypeToUriNullable _$SimpleClassOfEnumTypeToUriNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfEnumTypeToUriNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), - e == null ? null : Uri.parse(e as String)), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfEnumTypeToUriNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry( + $enumDecode(_$EnumTypeEnumMap, k), + e == null ? null : Uri.parse(e as String), + ), + ), +); Map<String, dynamic> _$SimpleClassOfEnumTypeToUriNullableToJson( - SimpleClassOfEnumTypeToUriNullable instance) => - <String, dynamic>{ - 'value': instance.value - .map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e?.toString())), - }; + SimpleClassOfEnumTypeToUriNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map( + (k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e?.toString()), + ), +}; SimpleClassNullableOfEnumTypeToUriNullable - _$SimpleClassNullableOfEnumTypeToUriNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfEnumTypeToUriNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry($enumDecode(_$EnumTypeEnumMap, k), - e == null ? null : Uri.parse(e as String)), - ), - ); +_$SimpleClassNullableOfEnumTypeToUriNullableFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfEnumTypeToUriNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry( + $enumDecode(_$EnumTypeEnumMap, k), + e == null ? null : Uri.parse(e as String), + ), + ), +); Map<String, dynamic> _$SimpleClassNullableOfEnumTypeToUriNullableToJson( - SimpleClassNullableOfEnumTypeToUriNullable instance) => - <String, dynamic>{ - 'value': instance.value - ?.map((k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e?.toString())), - }; + SimpleClassNullableOfEnumTypeToUriNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map( + (k, e) => MapEntry(_$EnumTypeEnumMap[k]!, e?.toString()), + ), +}; SimpleClassOfIntToUriNullable _$SimpleClassOfIntToUriNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfIntToUriNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => - MapEntry(int.parse(k), e == null ? null : Uri.parse(e as String)), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfIntToUriNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(int.parse(k), e == null ? null : Uri.parse(e as String)), + ), +); Map<String, dynamic> _$SimpleClassOfIntToUriNullableToJson( - SimpleClassOfIntToUriNullable instance) => - <String, dynamic>{ - 'value': - instance.value.map((k, e) => MapEntry(k.toString(), e?.toString())), - }; + SimpleClassOfIntToUriNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e?.toString())), +}; SimpleClassNullableOfIntToUriNullable - _$SimpleClassNullableOfIntToUriNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfIntToUriNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry( - int.parse(k), e == null ? null : Uri.parse(e as String)), - ), - ); +_$SimpleClassNullableOfIntToUriNullableFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfIntToUriNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => + MapEntry(int.parse(k), e == null ? null : Uri.parse(e as String)), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfIntToUriNullableToJson( - SimpleClassNullableOfIntToUriNullable instance) => - <String, dynamic>{ - 'value': - instance.value?.map((k, e) => MapEntry(k.toString(), e?.toString())), - }; + SimpleClassNullableOfIntToUriNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e?.toString())), +}; SimpleClassOfObjectToUriNullable _$SimpleClassOfObjectToUriNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfObjectToUriNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(k, e == null ? null : Uri.parse(e as String)), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfObjectToUriNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(k, e == null ? null : Uri.parse(e as String)), + ), +); Map<String, dynamic> _$SimpleClassOfObjectToUriNullableToJson( - SimpleClassOfObjectToUriNullable instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k, e?.toString())), - }; + SimpleClassOfObjectToUriNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k, e?.toString())), +}; SimpleClassNullableOfObjectToUriNullable - _$SimpleClassNullableOfObjectToUriNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfObjectToUriNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, e == null ? null : Uri.parse(e as String)), - ), - ); +_$SimpleClassNullableOfObjectToUriNullableFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfObjectToUriNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, e == null ? null : Uri.parse(e as String)), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfObjectToUriNullableToJson( - SimpleClassNullableOfObjectToUriNullable instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k, e?.toString())), - }; + SimpleClassNullableOfObjectToUriNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k, e?.toString())), +}; SimpleClassOfStringToUriNullable _$SimpleClassOfStringToUriNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfStringToUriNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => MapEntry(k, e == null ? null : Uri.parse(e as String)), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfStringToUriNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(k, e == null ? null : Uri.parse(e as String)), + ), +); Map<String, dynamic> _$SimpleClassOfStringToUriNullableToJson( - SimpleClassOfStringToUriNullable instance) => - <String, dynamic>{ - 'value': instance.value.map((k, e) => MapEntry(k, e?.toString())), - }; + SimpleClassOfStringToUriNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k, e?.toString())), +}; SimpleClassNullableOfStringToUriNullable - _$SimpleClassNullableOfStringToUriNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfStringToUriNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry(k, e == null ? null : Uri.parse(e as String)), - ), - ); +_$SimpleClassNullableOfStringToUriNullableFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfStringToUriNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => MapEntry(k, e == null ? null : Uri.parse(e as String)), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfStringToUriNullableToJson( - SimpleClassNullableOfStringToUriNullable instance) => - <String, dynamic>{ - 'value': instance.value?.map((k, e) => MapEntry(k, e?.toString())), - }; + SimpleClassNullableOfStringToUriNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k, e?.toString())), +}; SimpleClassOfUriToUriNullable _$SimpleClassOfUriToUriNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfUriToUriNullable( - (json['value'] as Map<String, dynamic>).map( - (k, e) => - MapEntry(Uri.parse(k), e == null ? null : Uri.parse(e as String)), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfUriToUriNullable( + (json['value'] as Map<String, dynamic>).map( + (k, e) => MapEntry(Uri.parse(k), e == null ? null : Uri.parse(e as String)), + ), +); Map<String, dynamic> _$SimpleClassOfUriToUriNullableToJson( - SimpleClassOfUriToUriNullable instance) => - <String, dynamic>{ - 'value': - instance.value.map((k, e) => MapEntry(k.toString(), e?.toString())), - }; + SimpleClassOfUriToUriNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map((k, e) => MapEntry(k.toString(), e?.toString())), +}; SimpleClassNullableOfUriToUriNullable - _$SimpleClassNullableOfUriToUriNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfUriToUriNullable( - (json['value'] as Map<String, dynamic>?)?.map( - (k, e) => MapEntry( - Uri.parse(k), e == null ? null : Uri.parse(e as String)), - ), - ); +_$SimpleClassNullableOfUriToUriNullableFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfUriToUriNullable( + (json['value'] as Map<String, dynamic>?)?.map( + (k, e) => + MapEntry(Uri.parse(k), e == null ? null : Uri.parse(e as String)), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfUriToUriNullableToJson( - SimpleClassNullableOfUriToUriNullable instance) => - <String, dynamic>{ - 'value': - instance.value?.map((k, e) => MapEntry(k.toString(), e?.toString())), - }; + SimpleClassNullableOfUriToUriNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map((k, e) => MapEntry(k.toString(), e?.toString())), +}; diff --git a/json_serializable/test/supported_types/input.type_num.dart b/json_serializable/test/supported_types/input.type_num.dart index 57631ce62..e354dd244 100644 --- a/json_serializable/test/supported_types/input.type_num.dart +++ b/json_serializable/test/supported_types/input.type_num.dart @@ -13,10 +13,7 @@ class SimpleClass { @JsonKey(defaultValue: 88.6) num withDefault; - SimpleClass( - this.value, - this.withDefault, - ); + SimpleClass(this.value, this.withDefault); factory SimpleClass.fromJson(Map<String, Object?> json) => _$SimpleClassFromJson(json); @@ -31,10 +28,7 @@ class SimpleClassNullable { @JsonKey(defaultValue: 88.6) num? withDefault; - SimpleClassNullable( - this.value, - this.withDefault, - ); + SimpleClassNullable(this.value, this.withDefault); factory SimpleClassNullable.fromJson(Map<String, Object?> json) => _$SimpleClassNullableFromJson(json); diff --git a/json_serializable/test/supported_types/input.type_num.g.dart b/json_serializable/test/supported_types/input.type_num.g.dart index f25274d8f..f84779b51 100644 --- a/json_serializable/test/supported_types/input.type_num.g.dart +++ b/json_serializable/test/supported_types/input.type_num.g.dart @@ -8,10 +8,8 @@ part of 'input.type_num.dart'; // JsonSerializableGenerator // ************************************************************************** -SimpleClass _$SimpleClassFromJson(Map<String, dynamic> json) => SimpleClass( - json['value'] as num, - json['withDefault'] as num? ?? 88.6, - ); +SimpleClass _$SimpleClassFromJson(Map<String, dynamic> json) => + SimpleClass(json['value'] as num, json['withDefault'] as num? ?? 88.6); Map<String, dynamic> _$SimpleClassToJson(SimpleClass instance) => <String, dynamic>{ @@ -26,8 +24,8 @@ SimpleClassNullable _$SimpleClassNullableFromJson(Map<String, dynamic> json) => ); Map<String, dynamic> _$SimpleClassNullableToJson( - SimpleClassNullable instance) => - <String, dynamic>{ - 'value': instance.value, - 'withDefault': instance.withDefault, - }; + SimpleClassNullable instance, +) => <String, dynamic>{ + 'value': instance.value, + 'withDefault': instance.withDefault, +}; diff --git a/json_serializable/test/supported_types/input.type_object.dart b/json_serializable/test/supported_types/input.type_object.dart index 193bd440a..57e8f78e3 100644 --- a/json_serializable/test/supported_types/input.type_object.dart +++ b/json_serializable/test/supported_types/input.type_object.dart @@ -13,10 +13,7 @@ class SimpleClass { @JsonKey(defaultValue: 'o1') Object withDefault; - SimpleClass( - this.value, - this.withDefault, - ); + SimpleClass(this.value, this.withDefault); factory SimpleClass.fromJson(Map<String, Object?> json) => _$SimpleClassFromJson(json); @@ -31,10 +28,7 @@ class SimpleClassNullable { @JsonKey(defaultValue: 'o1') Object? withDefault; - SimpleClassNullable( - this.value, - this.withDefault, - ); + SimpleClassNullable(this.value, this.withDefault); factory SimpleClassNullable.fromJson(Map<String, Object?> json) => _$SimpleClassNullableFromJson(json); diff --git a/json_serializable/test/supported_types/input.type_object.g.dart b/json_serializable/test/supported_types/input.type_object.g.dart index b35be59b6..ac5a9aa57 100644 --- a/json_serializable/test/supported_types/input.type_object.g.dart +++ b/json_serializable/test/supported_types/input.type_object.g.dart @@ -9,9 +9,9 @@ part of 'input.type_object.dart'; // ************************************************************************** SimpleClass _$SimpleClassFromJson(Map<String, dynamic> json) => SimpleClass( - json['value'] as Object, - json['withDefault'] as Object? ?? 'o1', - ); + json['value'] as Object, + json['withDefault'] as Object? ?? 'o1', +); Map<String, dynamic> _$SimpleClassToJson(SimpleClass instance) => <String, dynamic>{ @@ -20,14 +20,11 @@ Map<String, dynamic> _$SimpleClassToJson(SimpleClass instance) => }; SimpleClassNullable _$SimpleClassNullableFromJson(Map<String, dynamic> json) => - SimpleClassNullable( - json['value'], - json['withDefault'] ?? 'o1', - ); + SimpleClassNullable(json['value'], json['withDefault'] ?? 'o1'); Map<String, dynamic> _$SimpleClassNullableToJson( - SimpleClassNullable instance) => - <String, dynamic>{ - 'value': instance.value, - 'withDefault': instance.withDefault, - }; + SimpleClassNullable instance, +) => <String, dynamic>{ + 'value': instance.value, + 'withDefault': instance.withDefault, +}; diff --git a/json_serializable/test/supported_types/input.type_record.dart b/json_serializable/test/supported_types/input.type_record.dart index 4f26ab82e..c19ed9532 100644 --- a/json_serializable/test/supported_types/input.type_record.dart +++ b/json_serializable/test/supported_types/input.type_record.dart @@ -13,9 +13,7 @@ typedef RecordTypeDef = (); class SimpleClass { final RecordTypeDef value; - SimpleClass( - this.value, - ); + SimpleClass(this.value); factory SimpleClass.fromJson(Map<String, Object?> json) => _$SimpleClassFromJson(json); @@ -27,9 +25,7 @@ class SimpleClass { class SimpleClassNullable { final RecordTypeDef? value; - SimpleClassNullable( - this.value, - ); + SimpleClassNullable(this.value); factory SimpleClassNullable.fromJson(Map<String, Object?> json) => _$SimpleClassNullableFromJson(json); @@ -43,9 +39,7 @@ typedef SimpleClassOfBigIntTypeDef = (BigInt, {BigInt named}); class SimpleClassOfBigInt { final SimpleClassOfBigIntTypeDef value; - SimpleClassOfBigInt( - this.value, - ); + SimpleClassOfBigInt(this.value); factory SimpleClassOfBigInt.fromJson(Map<String, Object?> json) => _$SimpleClassOfBigIntFromJson(json); @@ -57,9 +51,7 @@ class SimpleClassOfBigInt { class SimpleClassNullableOfBigInt { final SimpleClassOfBigIntTypeDef? value; - SimpleClassNullableOfBigInt( - this.value, - ); + SimpleClassNullableOfBigInt(this.value); factory SimpleClassNullableOfBigInt.fromJson(Map<String, Object?> json) => _$SimpleClassNullableOfBigIntFromJson(json); @@ -73,9 +65,7 @@ typedef SimpleClassOfBigIntNullableTypeDef = (BigInt?, {BigInt? named}); class SimpleClassOfBigIntNullable { final SimpleClassOfBigIntNullableTypeDef value; - SimpleClassOfBigIntNullable( - this.value, - ); + SimpleClassOfBigIntNullable(this.value); factory SimpleClassOfBigIntNullable.fromJson(Map<String, Object?> json) => _$SimpleClassOfBigIntNullableFromJson(json); @@ -87,13 +77,11 @@ class SimpleClassOfBigIntNullable { class SimpleClassNullableOfBigIntNullable { final SimpleClassOfBigIntNullableTypeDef? value; - SimpleClassNullableOfBigIntNullable( - this.value, - ); + SimpleClassNullableOfBigIntNullable(this.value); factory SimpleClassNullableOfBigIntNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfBigIntNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfBigIntNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfBigIntNullableToJson(this); @@ -105,9 +93,7 @@ typedef SimpleClassOfBoolTypeDef = (bool, {bool named}); class SimpleClassOfBool { final SimpleClassOfBoolTypeDef value; - SimpleClassOfBool( - this.value, - ); + SimpleClassOfBool(this.value); factory SimpleClassOfBool.fromJson(Map<String, Object?> json) => _$SimpleClassOfBoolFromJson(json); @@ -119,9 +105,7 @@ class SimpleClassOfBool { class SimpleClassNullableOfBool { final SimpleClassOfBoolTypeDef? value; - SimpleClassNullableOfBool( - this.value, - ); + SimpleClassNullableOfBool(this.value); factory SimpleClassNullableOfBool.fromJson(Map<String, Object?> json) => _$SimpleClassNullableOfBoolFromJson(json); @@ -135,9 +119,7 @@ typedef SimpleClassOfBoolNullableTypeDef = (bool?, {bool? named}); class SimpleClassOfBoolNullable { final SimpleClassOfBoolNullableTypeDef value; - SimpleClassOfBoolNullable( - this.value, - ); + SimpleClassOfBoolNullable(this.value); factory SimpleClassOfBoolNullable.fromJson(Map<String, Object?> json) => _$SimpleClassOfBoolNullableFromJson(json); @@ -149,13 +131,11 @@ class SimpleClassOfBoolNullable { class SimpleClassNullableOfBoolNullable { final SimpleClassOfBoolNullableTypeDef? value; - SimpleClassNullableOfBoolNullable( - this.value, - ); + SimpleClassNullableOfBoolNullable(this.value); factory SimpleClassNullableOfBoolNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfBoolNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfBoolNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfBoolNullableToJson(this); @@ -167,9 +147,7 @@ typedef SimpleClassOfDateTimeTypeDef = (DateTime, {DateTime named}); class SimpleClassOfDateTime { final SimpleClassOfDateTimeTypeDef value; - SimpleClassOfDateTime( - this.value, - ); + SimpleClassOfDateTime(this.value); factory SimpleClassOfDateTime.fromJson(Map<String, Object?> json) => _$SimpleClassOfDateTimeFromJson(json); @@ -181,9 +159,7 @@ class SimpleClassOfDateTime { class SimpleClassNullableOfDateTime { final SimpleClassOfDateTimeTypeDef? value; - SimpleClassNullableOfDateTime( - this.value, - ); + SimpleClassNullableOfDateTime(this.value); factory SimpleClassNullableOfDateTime.fromJson(Map<String, Object?> json) => _$SimpleClassNullableOfDateTimeFromJson(json); @@ -197,9 +173,7 @@ typedef SimpleClassOfDateTimeNullableTypeDef = (DateTime?, {DateTime? named}); class SimpleClassOfDateTimeNullable { final SimpleClassOfDateTimeNullableTypeDef value; - SimpleClassOfDateTimeNullable( - this.value, - ); + SimpleClassOfDateTimeNullable(this.value); factory SimpleClassOfDateTimeNullable.fromJson(Map<String, Object?> json) => _$SimpleClassOfDateTimeNullableFromJson(json); @@ -211,13 +185,11 @@ class SimpleClassOfDateTimeNullable { class SimpleClassNullableOfDateTimeNullable { final SimpleClassOfDateTimeNullableTypeDef? value; - SimpleClassNullableOfDateTimeNullable( - this.value, - ); + SimpleClassNullableOfDateTimeNullable(this.value); factory SimpleClassNullableOfDateTimeNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfDateTimeNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfDateTimeNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfDateTimeNullableToJson(this); @@ -229,9 +201,7 @@ typedef SimpleClassOfDoubleTypeDef = (double, {double named}); class SimpleClassOfDouble { final SimpleClassOfDoubleTypeDef value; - SimpleClassOfDouble( - this.value, - ); + SimpleClassOfDouble(this.value); factory SimpleClassOfDouble.fromJson(Map<String, Object?> json) => _$SimpleClassOfDoubleFromJson(json); @@ -243,9 +213,7 @@ class SimpleClassOfDouble { class SimpleClassNullableOfDouble { final SimpleClassOfDoubleTypeDef? value; - SimpleClassNullableOfDouble( - this.value, - ); + SimpleClassNullableOfDouble(this.value); factory SimpleClassNullableOfDouble.fromJson(Map<String, Object?> json) => _$SimpleClassNullableOfDoubleFromJson(json); @@ -259,9 +227,7 @@ typedef SimpleClassOfDoubleNullableTypeDef = (double?, {double? named}); class SimpleClassOfDoubleNullable { final SimpleClassOfDoubleNullableTypeDef value; - SimpleClassOfDoubleNullable( - this.value, - ); + SimpleClassOfDoubleNullable(this.value); factory SimpleClassOfDoubleNullable.fromJson(Map<String, Object?> json) => _$SimpleClassOfDoubleNullableFromJson(json); @@ -273,13 +239,11 @@ class SimpleClassOfDoubleNullable { class SimpleClassNullableOfDoubleNullable { final SimpleClassOfDoubleNullableTypeDef? value; - SimpleClassNullableOfDoubleNullable( - this.value, - ); + SimpleClassNullableOfDoubleNullable(this.value); factory SimpleClassNullableOfDoubleNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfDoubleNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfDoubleNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfDoubleNullableToJson(this); @@ -291,9 +255,7 @@ typedef SimpleClassOfDurationTypeDef = (Duration, {Duration named}); class SimpleClassOfDuration { final SimpleClassOfDurationTypeDef value; - SimpleClassOfDuration( - this.value, - ); + SimpleClassOfDuration(this.value); factory SimpleClassOfDuration.fromJson(Map<String, Object?> json) => _$SimpleClassOfDurationFromJson(json); @@ -305,9 +267,7 @@ class SimpleClassOfDuration { class SimpleClassNullableOfDuration { final SimpleClassOfDurationTypeDef? value; - SimpleClassNullableOfDuration( - this.value, - ); + SimpleClassNullableOfDuration(this.value); factory SimpleClassNullableOfDuration.fromJson(Map<String, Object?> json) => _$SimpleClassNullableOfDurationFromJson(json); @@ -321,9 +281,7 @@ typedef SimpleClassOfDurationNullableTypeDef = (Duration?, {Duration? named}); class SimpleClassOfDurationNullable { final SimpleClassOfDurationNullableTypeDef value; - SimpleClassOfDurationNullable( - this.value, - ); + SimpleClassOfDurationNullable(this.value); factory SimpleClassOfDurationNullable.fromJson(Map<String, Object?> json) => _$SimpleClassOfDurationNullableFromJson(json); @@ -335,13 +293,11 @@ class SimpleClassOfDurationNullable { class SimpleClassNullableOfDurationNullable { final SimpleClassOfDurationNullableTypeDef? value; - SimpleClassNullableOfDurationNullable( - this.value, - ); + SimpleClassNullableOfDurationNullable(this.value); factory SimpleClassNullableOfDurationNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfDurationNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfDurationNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfDurationNullableToJson(this); @@ -353,9 +309,7 @@ typedef SimpleClassOfDynamicTypeDef = (dynamic, {dynamic named}); class SimpleClassOfDynamic { final SimpleClassOfDynamicTypeDef value; - SimpleClassOfDynamic( - this.value, - ); + SimpleClassOfDynamic(this.value); factory SimpleClassOfDynamic.fromJson(Map<String, Object?> json) => _$SimpleClassOfDynamicFromJson(json); @@ -367,9 +321,7 @@ class SimpleClassOfDynamic { class SimpleClassNullableOfDynamic { final SimpleClassOfDynamicTypeDef? value; - SimpleClassNullableOfDynamic( - this.value, - ); + SimpleClassNullableOfDynamic(this.value); factory SimpleClassNullableOfDynamic.fromJson(Map<String, Object?> json) => _$SimpleClassNullableOfDynamicFromJson(json); @@ -383,9 +335,7 @@ typedef SimpleClassOfEnumTypeTypeDef = (EnumType, {EnumType named}); class SimpleClassOfEnumType { final SimpleClassOfEnumTypeTypeDef value; - SimpleClassOfEnumType( - this.value, - ); + SimpleClassOfEnumType(this.value); factory SimpleClassOfEnumType.fromJson(Map<String, Object?> json) => _$SimpleClassOfEnumTypeFromJson(json); @@ -397,9 +347,7 @@ class SimpleClassOfEnumType { class SimpleClassNullableOfEnumType { final SimpleClassOfEnumTypeTypeDef? value; - SimpleClassNullableOfEnumType( - this.value, - ); + SimpleClassNullableOfEnumType(this.value); factory SimpleClassNullableOfEnumType.fromJson(Map<String, Object?> json) => _$SimpleClassNullableOfEnumTypeFromJson(json); @@ -413,9 +361,7 @@ typedef SimpleClassOfEnumTypeNullableTypeDef = (EnumType?, {EnumType? named}); class SimpleClassOfEnumTypeNullable { final SimpleClassOfEnumTypeNullableTypeDef value; - SimpleClassOfEnumTypeNullable( - this.value, - ); + SimpleClassOfEnumTypeNullable(this.value); factory SimpleClassOfEnumTypeNullable.fromJson(Map<String, Object?> json) => _$SimpleClassOfEnumTypeNullableFromJson(json); @@ -427,13 +373,11 @@ class SimpleClassOfEnumTypeNullable { class SimpleClassNullableOfEnumTypeNullable { final SimpleClassOfEnumTypeNullableTypeDef? value; - SimpleClassNullableOfEnumTypeNullable( - this.value, - ); + SimpleClassNullableOfEnumTypeNullable(this.value); factory SimpleClassNullableOfEnumTypeNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfEnumTypeNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfEnumTypeNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfEnumTypeNullableToJson(this); @@ -441,20 +385,18 @@ class SimpleClassNullableOfEnumTypeNullable { typedef SimpleClassOfFromJsonDynamicParamTypeDef = ( FromJsonDynamicParam, { - FromJsonDynamicParam named + FromJsonDynamicParam named, }); @JsonSerializable() class SimpleClassOfFromJsonDynamicParam { final SimpleClassOfFromJsonDynamicParamTypeDef value; - SimpleClassOfFromJsonDynamicParam( - this.value, - ); + SimpleClassOfFromJsonDynamicParam(this.value); factory SimpleClassOfFromJsonDynamicParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfFromJsonDynamicParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfFromJsonDynamicParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfFromJsonDynamicParamToJson(this); @@ -464,13 +406,11 @@ class SimpleClassOfFromJsonDynamicParam { class SimpleClassNullableOfFromJsonDynamicParam { final SimpleClassOfFromJsonDynamicParamTypeDef? value; - SimpleClassNullableOfFromJsonDynamicParam( - this.value, - ); + SimpleClassNullableOfFromJsonDynamicParam(this.value); factory SimpleClassNullableOfFromJsonDynamicParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfFromJsonDynamicParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfFromJsonDynamicParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfFromJsonDynamicParamToJson(this); @@ -478,20 +418,18 @@ class SimpleClassNullableOfFromJsonDynamicParam { typedef SimpleClassOfFromJsonNullableObjectParamTypeDef = ( FromJsonNullableObjectParam, { - FromJsonNullableObjectParam named + FromJsonNullableObjectParam named, }); @JsonSerializable() class SimpleClassOfFromJsonNullableObjectParam { final SimpleClassOfFromJsonNullableObjectParamTypeDef value; - SimpleClassOfFromJsonNullableObjectParam( - this.value, - ); + SimpleClassOfFromJsonNullableObjectParam(this.value); factory SimpleClassOfFromJsonNullableObjectParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfFromJsonNullableObjectParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfFromJsonNullableObjectParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfFromJsonNullableObjectParamToJson(this); @@ -501,13 +439,11 @@ class SimpleClassOfFromJsonNullableObjectParam { class SimpleClassNullableOfFromJsonNullableObjectParam { final SimpleClassOfFromJsonNullableObjectParamTypeDef? value; - SimpleClassNullableOfFromJsonNullableObjectParam( - this.value, - ); + SimpleClassNullableOfFromJsonNullableObjectParam(this.value); factory SimpleClassNullableOfFromJsonNullableObjectParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfFromJsonNullableObjectParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfFromJsonNullableObjectParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfFromJsonNullableObjectParamToJson(this); @@ -515,20 +451,18 @@ class SimpleClassNullableOfFromJsonNullableObjectParam { typedef SimpleClassOfFromJsonObjectParamTypeDef = ( FromJsonObjectParam, { - FromJsonObjectParam named + FromJsonObjectParam named, }); @JsonSerializable() class SimpleClassOfFromJsonObjectParam { final SimpleClassOfFromJsonObjectParamTypeDef value; - SimpleClassOfFromJsonObjectParam( - this.value, - ); + SimpleClassOfFromJsonObjectParam(this.value); factory SimpleClassOfFromJsonObjectParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfFromJsonObjectParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfFromJsonObjectParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfFromJsonObjectParamToJson(this); @@ -538,13 +472,11 @@ class SimpleClassOfFromJsonObjectParam { class SimpleClassNullableOfFromJsonObjectParam { final SimpleClassOfFromJsonObjectParamTypeDef? value; - SimpleClassNullableOfFromJsonObjectParam( - this.value, - ); + SimpleClassNullableOfFromJsonObjectParam(this.value); factory SimpleClassNullableOfFromJsonObjectParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfFromJsonObjectParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfFromJsonObjectParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfFromJsonObjectParamToJson(this); @@ -556,9 +488,7 @@ typedef SimpleClassOfIntTypeDef = (int, {int named}); class SimpleClassOfInt { final SimpleClassOfIntTypeDef value; - SimpleClassOfInt( - this.value, - ); + SimpleClassOfInt(this.value); factory SimpleClassOfInt.fromJson(Map<String, Object?> json) => _$SimpleClassOfIntFromJson(json); @@ -570,9 +500,7 @@ class SimpleClassOfInt { class SimpleClassNullableOfInt { final SimpleClassOfIntTypeDef? value; - SimpleClassNullableOfInt( - this.value, - ); + SimpleClassNullableOfInt(this.value); factory SimpleClassNullableOfInt.fromJson(Map<String, Object?> json) => _$SimpleClassNullableOfIntFromJson(json); @@ -586,9 +514,7 @@ typedef SimpleClassOfIntNullableTypeDef = (int?, {int? named}); class SimpleClassOfIntNullable { final SimpleClassOfIntNullableTypeDef value; - SimpleClassOfIntNullable( - this.value, - ); + SimpleClassOfIntNullable(this.value); factory SimpleClassOfIntNullable.fromJson(Map<String, Object?> json) => _$SimpleClassOfIntNullableFromJson(json); @@ -600,13 +526,11 @@ class SimpleClassOfIntNullable { class SimpleClassNullableOfIntNullable { final SimpleClassOfIntNullableTypeDef? value; - SimpleClassNullableOfIntNullable( - this.value, - ); + SimpleClassNullableOfIntNullable(this.value); factory SimpleClassNullableOfIntNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfIntNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfIntNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfIntNullableToJson(this); @@ -618,9 +542,7 @@ typedef SimpleClassOfNumTypeDef = (num, {num named}); class SimpleClassOfNum { final SimpleClassOfNumTypeDef value; - SimpleClassOfNum( - this.value, - ); + SimpleClassOfNum(this.value); factory SimpleClassOfNum.fromJson(Map<String, Object?> json) => _$SimpleClassOfNumFromJson(json); @@ -632,9 +554,7 @@ class SimpleClassOfNum { class SimpleClassNullableOfNum { final SimpleClassOfNumTypeDef? value; - SimpleClassNullableOfNum( - this.value, - ); + SimpleClassNullableOfNum(this.value); factory SimpleClassNullableOfNum.fromJson(Map<String, Object?> json) => _$SimpleClassNullableOfNumFromJson(json); @@ -648,9 +568,7 @@ typedef SimpleClassOfNumNullableTypeDef = (num?, {num? named}); class SimpleClassOfNumNullable { final SimpleClassOfNumNullableTypeDef value; - SimpleClassOfNumNullable( - this.value, - ); + SimpleClassOfNumNullable(this.value); factory SimpleClassOfNumNullable.fromJson(Map<String, Object?> json) => _$SimpleClassOfNumNullableFromJson(json); @@ -662,13 +580,11 @@ class SimpleClassOfNumNullable { class SimpleClassNullableOfNumNullable { final SimpleClassOfNumNullableTypeDef? value; - SimpleClassNullableOfNumNullable( - this.value, - ); + SimpleClassNullableOfNumNullable(this.value); factory SimpleClassNullableOfNumNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfNumNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfNumNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfNumNullableToJson(this); @@ -680,9 +596,7 @@ typedef SimpleClassOfObjectTypeDef = (Object, {Object named}); class SimpleClassOfObject { final SimpleClassOfObjectTypeDef value; - SimpleClassOfObject( - this.value, - ); + SimpleClassOfObject(this.value); factory SimpleClassOfObject.fromJson(Map<String, Object?> json) => _$SimpleClassOfObjectFromJson(json); @@ -694,9 +608,7 @@ class SimpleClassOfObject { class SimpleClassNullableOfObject { final SimpleClassOfObjectTypeDef? value; - SimpleClassNullableOfObject( - this.value, - ); + SimpleClassNullableOfObject(this.value); factory SimpleClassNullableOfObject.fromJson(Map<String, Object?> json) => _$SimpleClassNullableOfObjectFromJson(json); @@ -710,9 +622,7 @@ typedef SimpleClassOfObjectNullableTypeDef = (Object?, {Object? named}); class SimpleClassOfObjectNullable { final SimpleClassOfObjectNullableTypeDef value; - SimpleClassOfObjectNullable( - this.value, - ); + SimpleClassOfObjectNullable(this.value); factory SimpleClassOfObjectNullable.fromJson(Map<String, Object?> json) => _$SimpleClassOfObjectNullableFromJson(json); @@ -724,13 +634,11 @@ class SimpleClassOfObjectNullable { class SimpleClassNullableOfObjectNullable { final SimpleClassOfObjectNullableTypeDef? value; - SimpleClassNullableOfObjectNullable( - this.value, - ); + SimpleClassNullableOfObjectNullable(this.value); factory SimpleClassNullableOfObjectNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfObjectNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfObjectNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfObjectNullableToJson(this); @@ -738,16 +646,14 @@ class SimpleClassNullableOfObjectNullable { typedef SimpleClassOfRecordTypeDef = ( (int, String, {bool truth}), { - (int, String, {bool truth}) named + (int, String, {bool truth}) named, }); @JsonSerializable() class SimpleClassOfRecord { final SimpleClassOfRecordTypeDef value; - SimpleClassOfRecord( - this.value, - ); + SimpleClassOfRecord(this.value); factory SimpleClassOfRecord.fromJson(Map<String, Object?> json) => _$SimpleClassOfRecordFromJson(json); @@ -759,9 +665,7 @@ class SimpleClassOfRecord { class SimpleClassNullableOfRecord { final SimpleClassOfRecordTypeDef? value; - SimpleClassNullableOfRecord( - this.value, - ); + SimpleClassNullableOfRecord(this.value); factory SimpleClassNullableOfRecord.fromJson(Map<String, Object?> json) => _$SimpleClassNullableOfRecordFromJson(json); @@ -775,9 +679,7 @@ typedef SimpleClassOfStringTypeDef = (String, {String named}); class SimpleClassOfString { final SimpleClassOfStringTypeDef value; - SimpleClassOfString( - this.value, - ); + SimpleClassOfString(this.value); factory SimpleClassOfString.fromJson(Map<String, Object?> json) => _$SimpleClassOfStringFromJson(json); @@ -789,9 +691,7 @@ class SimpleClassOfString { class SimpleClassNullableOfString { final SimpleClassOfStringTypeDef? value; - SimpleClassNullableOfString( - this.value, - ); + SimpleClassNullableOfString(this.value); factory SimpleClassNullableOfString.fromJson(Map<String, Object?> json) => _$SimpleClassNullableOfStringFromJson(json); @@ -805,9 +705,7 @@ typedef SimpleClassOfStringNullableTypeDef = (String?, {String? named}); class SimpleClassOfStringNullable { final SimpleClassOfStringNullableTypeDef value; - SimpleClassOfStringNullable( - this.value, - ); + SimpleClassOfStringNullable(this.value); factory SimpleClassOfStringNullable.fromJson(Map<String, Object?> json) => _$SimpleClassOfStringNullableFromJson(json); @@ -819,13 +717,11 @@ class SimpleClassOfStringNullable { class SimpleClassNullableOfStringNullable { final SimpleClassOfStringNullableTypeDef? value; - SimpleClassNullableOfStringNullable( - this.value, - ); + SimpleClassNullableOfStringNullable(this.value); factory SimpleClassNullableOfStringNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfStringNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfStringNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfStringNullableToJson(this); @@ -837,9 +733,7 @@ typedef SimpleClassOfUriTypeDef = (Uri, {Uri named}); class SimpleClassOfUri { final SimpleClassOfUriTypeDef value; - SimpleClassOfUri( - this.value, - ); + SimpleClassOfUri(this.value); factory SimpleClassOfUri.fromJson(Map<String, Object?> json) => _$SimpleClassOfUriFromJson(json); @@ -851,9 +745,7 @@ class SimpleClassOfUri { class SimpleClassNullableOfUri { final SimpleClassOfUriTypeDef? value; - SimpleClassNullableOfUri( - this.value, - ); + SimpleClassNullableOfUri(this.value); factory SimpleClassNullableOfUri.fromJson(Map<String, Object?> json) => _$SimpleClassNullableOfUriFromJson(json); @@ -867,9 +759,7 @@ typedef SimpleClassOfUriNullableTypeDef = (Uri?, {Uri? named}); class SimpleClassOfUriNullable { final SimpleClassOfUriNullableTypeDef value; - SimpleClassOfUriNullable( - this.value, - ); + SimpleClassOfUriNullable(this.value); factory SimpleClassOfUriNullable.fromJson(Map<String, Object?> json) => _$SimpleClassOfUriNullableFromJson(json); @@ -881,13 +771,11 @@ class SimpleClassOfUriNullable { class SimpleClassNullableOfUriNullable { final SimpleClassOfUriNullableTypeDef? value; - SimpleClassNullableOfUriNullable( - this.value, - ); + SimpleClassNullableOfUriNullable(this.value); factory SimpleClassNullableOfUriNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfUriNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfUriNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfUriNullableToJson(this); diff --git a/json_serializable/test/supported_types/input.type_record.g.dart b/json_serializable/test/supported_types/input.type_record.g.dart index bc37b7cd2..98e183040 100644 --- a/json_serializable/test/supported_types/input.type_record.g.dart +++ b/json_serializable/test/supported_types/input.type_record.g.dart @@ -8,25 +8,19 @@ part of 'input.type_record.dart'; // JsonSerializableGenerator // ************************************************************************** -SimpleClass _$SimpleClassFromJson(Map<String, dynamic> json) => SimpleClass( - (), - ); +SimpleClass _$SimpleClassFromJson(Map<String, dynamic> json) => SimpleClass(()); Map<String, dynamic> _$SimpleClassToJson(SimpleClass instance) => - <String, dynamic>{ - 'value': <String, dynamic>{}, - }; + <String, dynamic>{'value': <String, dynamic>{}}; SimpleClassNullable _$SimpleClassNullableFromJson(Map<String, dynamic> json) => - SimpleClassNullable( - (), - ); + SimpleClassNullable(()); Map<String, dynamic> _$SimpleClassNullableToJson( - SimpleClassNullable instance) => - <String, dynamic>{ - 'value': instance.value == null ? null : <String, dynamic>{}, - }; + SimpleClassNullable instance, +) => <String, dynamic>{ + 'value': instance.value == null ? null : <String, dynamic>{}, +}; SimpleClassOfBigInt _$SimpleClassOfBigIntFromJson(Map<String, dynamic> json) => SimpleClassOfBigInt( @@ -40,53 +34,74 @@ SimpleClassOfBigInt _$SimpleClassOfBigIntFromJson(Map<String, dynamic> json) => ); Map<String, dynamic> _$SimpleClassOfBigIntToJson( - SimpleClassOfBigInt instance) => - <String, dynamic>{ - 'value': <String, dynamic>{ - r'$1': instance.value.$1.toString(), - 'named': instance.value.named.toString(), - }, - }; + SimpleClassOfBigInt instance, +) => <String, dynamic>{ + 'value': <String, dynamic>{ + r'$1': instance.value.$1.toString(), + 'named': instance.value.named.toString(), + }, +}; -$Rec _$recordConvert<$Rec>( - Object? value, - $Rec Function(Map) convert, -) => +$Rec _$recordConvert<$Rec>(Object? value, $Rec Function(Map) convert) => convert(value as Map<String, dynamic>); SimpleClassNullableOfBigInt _$SimpleClassNullableOfBigIntFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfBigInt( - _$recordConvertNullable( - json['value'], - ($jsonValue) => ( - BigInt.parse($jsonValue[r'$1'] as String), - named: BigInt.parse($jsonValue['named'] as String), - ), - ), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfBigInt( + _$recordConvertNullable( + json['value'], + ($jsonValue) => ( + BigInt.parse($jsonValue[r'$1'] as String), + named: BigInt.parse($jsonValue['named'] as String), + ), + ), +); Map<String, dynamic> _$SimpleClassNullableOfBigIntToJson( - SimpleClassNullableOfBigInt instance) => - <String, dynamic>{ - 'value': instance.value == null - ? null - : <String, dynamic>{ - r'$1': instance.value!.$1.toString(), - 'named': instance.value!.named.toString(), - }, - }; + SimpleClassNullableOfBigInt instance, +) => <String, dynamic>{ + 'value': instance.value == null + ? null + : <String, dynamic>{ + r'$1': instance.value!.$1.toString(), + 'named': instance.value!.named.toString(), + }, +}; $Rec? _$recordConvertNullable<$Rec>( Object? value, $Rec Function(Map) convert, -) => - value == null ? null : convert(value as Map<String, dynamic>); +) => value == null ? null : convert(value as Map<String, dynamic>); SimpleClassOfBigIntNullable _$SimpleClassOfBigIntNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfBigIntNullable( - _$recordConvert( + Map<String, dynamic> json, +) => SimpleClassOfBigIntNullable( + _$recordConvert( + json['value'], + ($jsonValue) => ( + $jsonValue[r'$1'] == null + ? null + : BigInt.parse($jsonValue[r'$1'] as String), + named: $jsonValue['named'] == null + ? null + : BigInt.parse($jsonValue['named'] as String), + ), + ), +); + +Map<String, dynamic> _$SimpleClassOfBigIntNullableToJson( + SimpleClassOfBigIntNullable instance, +) => <String, dynamic>{ + 'value': <String, dynamic>{ + r'$1': instance.value.$1?.toString(), + 'named': instance.value.named?.toString(), + }, +}; + +SimpleClassNullableOfBigIntNullable +_$SimpleClassNullableOfBigIntNullableFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfBigIntNullable( + _$recordConvertNullable( json['value'], ($jsonValue) => ( $jsonValue[r'$1'] == null @@ -99,50 +114,23 @@ SimpleClassOfBigIntNullable _$SimpleClassOfBigIntNullableFromJson( ), ); -Map<String, dynamic> _$SimpleClassOfBigIntNullableToJson( - SimpleClassOfBigIntNullable instance) => - <String, dynamic>{ - 'value': <String, dynamic>{ - r'$1': instance.value.$1?.toString(), - 'named': instance.value.named?.toString(), - }, - }; - -SimpleClassNullableOfBigIntNullable - _$SimpleClassNullableOfBigIntNullableFromJson(Map<String, dynamic> json) => - SimpleClassNullableOfBigIntNullable( - _$recordConvertNullable( - json['value'], - ($jsonValue) => ( - $jsonValue[r'$1'] == null - ? null - : BigInt.parse($jsonValue[r'$1'] as String), - named: $jsonValue['named'] == null - ? null - : BigInt.parse($jsonValue['named'] as String), - ), - ), - ); - Map<String, dynamic> _$SimpleClassNullableOfBigIntNullableToJson( - SimpleClassNullableOfBigIntNullable instance) => - <String, dynamic>{ - 'value': instance.value == null - ? null - : <String, dynamic>{ - r'$1': instance.value!.$1?.toString(), - 'named': instance.value!.named?.toString(), - }, - }; + SimpleClassNullableOfBigIntNullable instance, +) => <String, dynamic>{ + 'value': instance.value == null + ? null + : <String, dynamic>{ + r'$1': instance.value!.$1?.toString(), + 'named': instance.value!.named?.toString(), + }, +}; SimpleClassOfBool _$SimpleClassOfBoolFromJson(Map<String, dynamic> json) => SimpleClassOfBool( _$recordConvert( json['value'], - ($jsonValue) => ( - $jsonValue[r'$1'] as bool, - named: $jsonValue['named'] as bool, - ), + ($jsonValue) => + ($jsonValue[r'$1'] as bool, named: $jsonValue['named'] as bool), ), ); @@ -155,120 +143,139 @@ Map<String, dynamic> _$SimpleClassOfBoolToJson(SimpleClassOfBool instance) => }; SimpleClassNullableOfBool _$SimpleClassNullableOfBoolFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfBool( - _$recordConvertNullable( - json['value'], - ($jsonValue) => ( - $jsonValue[r'$1'] as bool, - named: $jsonValue['named'] as bool, - ), - ), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfBool( + _$recordConvertNullable( + json['value'], + ($jsonValue) => + ($jsonValue[r'$1'] as bool, named: $jsonValue['named'] as bool), + ), +); Map<String, dynamic> _$SimpleClassNullableOfBoolToJson( - SimpleClassNullableOfBool instance) => - <String, dynamic>{ - 'value': instance.value == null - ? null - : <String, dynamic>{ - r'$1': instance.value!.$1, - 'named': instance.value!.named, - }, - }; + SimpleClassNullableOfBool instance, +) => <String, dynamic>{ + 'value': instance.value == null + ? null + : <String, dynamic>{ + r'$1': instance.value!.$1, + 'named': instance.value!.named, + }, +}; SimpleClassOfBoolNullable _$SimpleClassOfBoolNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfBoolNullable( - _$recordConvert( - json['value'], - ($jsonValue) => ( - $jsonValue[r'$1'] as bool?, - named: $jsonValue['named'] as bool?, - ), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfBoolNullable( + _$recordConvert( + json['value'], + ($jsonValue) => + ($jsonValue[r'$1'] as bool?, named: $jsonValue['named'] as bool?), + ), +); Map<String, dynamic> _$SimpleClassOfBoolNullableToJson( - SimpleClassOfBoolNullable instance) => - <String, dynamic>{ - 'value': <String, dynamic>{ - r'$1': instance.value.$1, - 'named': instance.value.named, - }, - }; + SimpleClassOfBoolNullable instance, +) => <String, dynamic>{ + 'value': <String, dynamic>{ + r'$1': instance.value.$1, + 'named': instance.value.named, + }, +}; SimpleClassNullableOfBoolNullable _$SimpleClassNullableOfBoolNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfBoolNullable( - _$recordConvertNullable( - json['value'], - ($jsonValue) => ( - $jsonValue[r'$1'] as bool?, - named: $jsonValue['named'] as bool?, - ), - ), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfBoolNullable( + _$recordConvertNullable( + json['value'], + ($jsonValue) => + ($jsonValue[r'$1'] as bool?, named: $jsonValue['named'] as bool?), + ), +); Map<String, dynamic> _$SimpleClassNullableOfBoolNullableToJson( - SimpleClassNullableOfBoolNullable instance) => - <String, dynamic>{ - 'value': instance.value == null - ? null - : <String, dynamic>{ - r'$1': instance.value!.$1, - 'named': instance.value!.named, - }, - }; + SimpleClassNullableOfBoolNullable instance, +) => <String, dynamic>{ + 'value': instance.value == null + ? null + : <String, dynamic>{ + r'$1': instance.value!.$1, + 'named': instance.value!.named, + }, +}; SimpleClassOfDateTime _$SimpleClassOfDateTimeFromJson( - Map<String, dynamic> json) => - SimpleClassOfDateTime( - _$recordConvert( - json['value'], - ($jsonValue) => ( - DateTime.parse($jsonValue[r'$1'] as String), - named: DateTime.parse($jsonValue['named'] as String), - ), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfDateTime( + _$recordConvert( + json['value'], + ($jsonValue) => ( + DateTime.parse($jsonValue[r'$1'] as String), + named: DateTime.parse($jsonValue['named'] as String), + ), + ), +); Map<String, dynamic> _$SimpleClassOfDateTimeToJson( - SimpleClassOfDateTime instance) => - <String, dynamic>{ - 'value': <String, dynamic>{ - r'$1': instance.value.$1.toIso8601String(), - 'named': instance.value.named.toIso8601String(), - }, - }; + SimpleClassOfDateTime instance, +) => <String, dynamic>{ + 'value': <String, dynamic>{ + r'$1': instance.value.$1.toIso8601String(), + 'named': instance.value.named.toIso8601String(), + }, +}; SimpleClassNullableOfDateTime _$SimpleClassNullableOfDateTimeFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDateTime( - _$recordConvertNullable( - json['value'], - ($jsonValue) => ( - DateTime.parse($jsonValue[r'$1'] as String), - named: DateTime.parse($jsonValue['named'] as String), - ), - ), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfDateTime( + _$recordConvertNullable( + json['value'], + ($jsonValue) => ( + DateTime.parse($jsonValue[r'$1'] as String), + named: DateTime.parse($jsonValue['named'] as String), + ), + ), +); Map<String, dynamic> _$SimpleClassNullableOfDateTimeToJson( - SimpleClassNullableOfDateTime instance) => - <String, dynamic>{ - 'value': instance.value == null - ? null - : <String, dynamic>{ - r'$1': instance.value!.$1.toIso8601String(), - 'named': instance.value!.named.toIso8601String(), - }, - }; + SimpleClassNullableOfDateTime instance, +) => <String, dynamic>{ + 'value': instance.value == null + ? null + : <String, dynamic>{ + r'$1': instance.value!.$1.toIso8601String(), + 'named': instance.value!.named.toIso8601String(), + }, +}; SimpleClassOfDateTimeNullable _$SimpleClassOfDateTimeNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfDateTimeNullable( - _$recordConvert( + Map<String, dynamic> json, +) => SimpleClassOfDateTimeNullable( + _$recordConvert( + json['value'], + ($jsonValue) => ( + $jsonValue[r'$1'] == null + ? null + : DateTime.parse($jsonValue[r'$1'] as String), + named: $jsonValue['named'] == null + ? null + : DateTime.parse($jsonValue['named'] as String), + ), + ), +); + +Map<String, dynamic> _$SimpleClassOfDateTimeNullableToJson( + SimpleClassOfDateTimeNullable instance, +) => <String, dynamic>{ + 'value': <String, dynamic>{ + r'$1': instance.value.$1?.toIso8601String(), + 'named': instance.value.named?.toIso8601String(), + }, +}; + +SimpleClassNullableOfDateTimeNullable +_$SimpleClassNullableOfDateTimeNullableFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfDateTimeNullable( + _$recordConvertNullable( json['value'], ($jsonValue) => ( $jsonValue[r'$1'] == null @@ -281,42 +288,16 @@ SimpleClassOfDateTimeNullable _$SimpleClassOfDateTimeNullableFromJson( ), ); -Map<String, dynamic> _$SimpleClassOfDateTimeNullableToJson( - SimpleClassOfDateTimeNullable instance) => - <String, dynamic>{ - 'value': <String, dynamic>{ - r'$1': instance.value.$1?.toIso8601String(), - 'named': instance.value.named?.toIso8601String(), - }, - }; - -SimpleClassNullableOfDateTimeNullable - _$SimpleClassNullableOfDateTimeNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDateTimeNullable( - _$recordConvertNullable( - json['value'], - ($jsonValue) => ( - $jsonValue[r'$1'] == null - ? null - : DateTime.parse($jsonValue[r'$1'] as String), - named: $jsonValue['named'] == null - ? null - : DateTime.parse($jsonValue['named'] as String), - ), - ), - ); - Map<String, dynamic> _$SimpleClassNullableOfDateTimeNullableToJson( - SimpleClassNullableOfDateTimeNullable instance) => - <String, dynamic>{ - 'value': instance.value == null - ? null - : <String, dynamic>{ - r'$1': instance.value!.$1?.toIso8601String(), - 'named': instance.value!.named?.toIso8601String(), - }, - }; + SimpleClassNullableOfDateTimeNullable instance, +) => <String, dynamic>{ + 'value': instance.value == null + ? null + : <String, dynamic>{ + r'$1': instance.value!.$1?.toIso8601String(), + 'named': instance.value!.named?.toIso8601String(), + }, +}; SimpleClassOfDouble _$SimpleClassOfDoubleFromJson(Map<String, dynamic> json) => SimpleClassOfDouble( @@ -330,41 +311,62 @@ SimpleClassOfDouble _$SimpleClassOfDoubleFromJson(Map<String, dynamic> json) => ); Map<String, dynamic> _$SimpleClassOfDoubleToJson( - SimpleClassOfDouble instance) => - <String, dynamic>{ - 'value': <String, dynamic>{ - r'$1': instance.value.$1, - 'named': instance.value.named, - }, - }; + SimpleClassOfDouble instance, +) => <String, dynamic>{ + 'value': <String, dynamic>{ + r'$1': instance.value.$1, + 'named': instance.value.named, + }, +}; SimpleClassNullableOfDouble _$SimpleClassNullableOfDoubleFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDouble( - _$recordConvertNullable( - json['value'], - ($jsonValue) => ( - ($jsonValue[r'$1'] as num).toDouble(), - named: ($jsonValue['named'] as num).toDouble(), - ), - ), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfDouble( + _$recordConvertNullable( + json['value'], + ($jsonValue) => ( + ($jsonValue[r'$1'] as num).toDouble(), + named: ($jsonValue['named'] as num).toDouble(), + ), + ), +); Map<String, dynamic> _$SimpleClassNullableOfDoubleToJson( - SimpleClassNullableOfDouble instance) => - <String, dynamic>{ - 'value': instance.value == null - ? null - : <String, dynamic>{ - r'$1': instance.value!.$1, - 'named': instance.value!.named, - }, - }; + SimpleClassNullableOfDouble instance, +) => <String, dynamic>{ + 'value': instance.value == null + ? null + : <String, dynamic>{ + r'$1': instance.value!.$1, + 'named': instance.value!.named, + }, +}; SimpleClassOfDoubleNullable _$SimpleClassOfDoubleNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfDoubleNullable( - _$recordConvert( + Map<String, dynamic> json, +) => SimpleClassOfDoubleNullable( + _$recordConvert( + json['value'], + ($jsonValue) => ( + ($jsonValue[r'$1'] as num?)?.toDouble(), + named: ($jsonValue['named'] as num?)?.toDouble(), + ), + ), +); + +Map<String, dynamic> _$SimpleClassOfDoubleNullableToJson( + SimpleClassOfDoubleNullable instance, +) => <String, dynamic>{ + 'value': <String, dynamic>{ + r'$1': instance.value.$1, + 'named': instance.value.named, + }, +}; + +SimpleClassNullableOfDoubleNullable +_$SimpleClassNullableOfDoubleNullableFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfDoubleNullable( + _$recordConvertNullable( json['value'], ($jsonValue) => ( ($jsonValue[r'$1'] as num?)?.toDouble(), @@ -373,86 +375,90 @@ SimpleClassOfDoubleNullable _$SimpleClassOfDoubleNullableFromJson( ), ); -Map<String, dynamic> _$SimpleClassOfDoubleNullableToJson( - SimpleClassOfDoubleNullable instance) => - <String, dynamic>{ - 'value': <String, dynamic>{ - r'$1': instance.value.$1, - 'named': instance.value.named, - }, - }; - -SimpleClassNullableOfDoubleNullable - _$SimpleClassNullableOfDoubleNullableFromJson(Map<String, dynamic> json) => - SimpleClassNullableOfDoubleNullable( - _$recordConvertNullable( - json['value'], - ($jsonValue) => ( - ($jsonValue[r'$1'] as num?)?.toDouble(), - named: ($jsonValue['named'] as num?)?.toDouble(), - ), - ), - ); - Map<String, dynamic> _$SimpleClassNullableOfDoubleNullableToJson( - SimpleClassNullableOfDoubleNullable instance) => - <String, dynamic>{ - 'value': instance.value == null - ? null - : <String, dynamic>{ - r'$1': instance.value!.$1, - 'named': instance.value!.named, - }, - }; + SimpleClassNullableOfDoubleNullable instance, +) => <String, dynamic>{ + 'value': instance.value == null + ? null + : <String, dynamic>{ + r'$1': instance.value!.$1, + 'named': instance.value!.named, + }, +}; SimpleClassOfDuration _$SimpleClassOfDurationFromJson( - Map<String, dynamic> json) => - SimpleClassOfDuration( - _$recordConvert( - json['value'], - ($jsonValue) => ( - Duration(microseconds: ($jsonValue[r'$1'] as num).toInt()), - named: Duration(microseconds: ($jsonValue['named'] as num).toInt()), - ), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfDuration( + _$recordConvert( + json['value'], + ($jsonValue) => ( + Duration(microseconds: ($jsonValue[r'$1'] as num).toInt()), + named: Duration(microseconds: ($jsonValue['named'] as num).toInt()), + ), + ), +); Map<String, dynamic> _$SimpleClassOfDurationToJson( - SimpleClassOfDuration instance) => - <String, dynamic>{ - 'value': <String, dynamic>{ - r'$1': instance.value.$1.inMicroseconds, - 'named': instance.value.named.inMicroseconds, - }, - }; + SimpleClassOfDuration instance, +) => <String, dynamic>{ + 'value': <String, dynamic>{ + r'$1': instance.value.$1.inMicroseconds, + 'named': instance.value.named.inMicroseconds, + }, +}; SimpleClassNullableOfDuration _$SimpleClassNullableOfDurationFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDuration( - _$recordConvertNullable( - json['value'], - ($jsonValue) => ( - Duration(microseconds: ($jsonValue[r'$1'] as num).toInt()), - named: Duration(microseconds: ($jsonValue['named'] as num).toInt()), - ), - ), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfDuration( + _$recordConvertNullable( + json['value'], + ($jsonValue) => ( + Duration(microseconds: ($jsonValue[r'$1'] as num).toInt()), + named: Duration(microseconds: ($jsonValue['named'] as num).toInt()), + ), + ), +); Map<String, dynamic> _$SimpleClassNullableOfDurationToJson( - SimpleClassNullableOfDuration instance) => - <String, dynamic>{ - 'value': instance.value == null - ? null - : <String, dynamic>{ - r'$1': instance.value!.$1.inMicroseconds, - 'named': instance.value!.named.inMicroseconds, - }, - }; + SimpleClassNullableOfDuration instance, +) => <String, dynamic>{ + 'value': instance.value == null + ? null + : <String, dynamic>{ + r'$1': instance.value!.$1.inMicroseconds, + 'named': instance.value!.named.inMicroseconds, + }, +}; SimpleClassOfDurationNullable _$SimpleClassOfDurationNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfDurationNullable( - _$recordConvert( + Map<String, dynamic> json, +) => SimpleClassOfDurationNullable( + _$recordConvert( + json['value'], + ($jsonValue) => ( + $jsonValue[r'$1'] == null + ? null + : Duration(microseconds: ($jsonValue[r'$1'] as num).toInt()), + named: $jsonValue['named'] == null + ? null + : Duration(microseconds: ($jsonValue['named'] as num).toInt()), + ), + ), +); + +Map<String, dynamic> _$SimpleClassOfDurationNullableToJson( + SimpleClassOfDurationNullable instance, +) => <String, dynamic>{ + 'value': <String, dynamic>{ + r'$1': instance.value.$1?.inMicroseconds, + 'named': instance.value.named?.inMicroseconds, + }, +}; + +SimpleClassNullableOfDurationNullable +_$SimpleClassNullableOfDurationNullableFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfDurationNullable( + _$recordConvertNullable( json['value'], ($jsonValue) => ( $jsonValue[r'$1'] == null @@ -465,108 +471,75 @@ SimpleClassOfDurationNullable _$SimpleClassOfDurationNullableFromJson( ), ); -Map<String, dynamic> _$SimpleClassOfDurationNullableToJson( - SimpleClassOfDurationNullable instance) => - <String, dynamic>{ - 'value': <String, dynamic>{ - r'$1': instance.value.$1?.inMicroseconds, - 'named': instance.value.named?.inMicroseconds, - }, - }; - -SimpleClassNullableOfDurationNullable - _$SimpleClassNullableOfDurationNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDurationNullable( - _$recordConvertNullable( - json['value'], - ($jsonValue) => ( - $jsonValue[r'$1'] == null - ? null - : Duration(microseconds: ($jsonValue[r'$1'] as num).toInt()), - named: $jsonValue['named'] == null - ? null - : Duration( - microseconds: ($jsonValue['named'] as num).toInt()), - ), - ), - ); - Map<String, dynamic> _$SimpleClassNullableOfDurationNullableToJson( - SimpleClassNullableOfDurationNullable instance) => - <String, dynamic>{ - 'value': instance.value == null - ? null - : <String, dynamic>{ - r'$1': instance.value!.$1?.inMicroseconds, - 'named': instance.value!.named?.inMicroseconds, - }, - }; + SimpleClassNullableOfDurationNullable instance, +) => <String, dynamic>{ + 'value': instance.value == null + ? null + : <String, dynamic>{ + r'$1': instance.value!.$1?.inMicroseconds, + 'named': instance.value!.named?.inMicroseconds, + }, +}; SimpleClassOfDynamic _$SimpleClassOfDynamicFromJson( - Map<String, dynamic> json) => - SimpleClassOfDynamic( - _$recordConvert( - json['value'], - ($jsonValue) => ( - $jsonValue[r'$1'], - named: $jsonValue['named'], - ), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfDynamic( + _$recordConvert( + json['value'], + ($jsonValue) => ($jsonValue[r'$1'], named: $jsonValue['named']), + ), +); Map<String, dynamic> _$SimpleClassOfDynamicToJson( - SimpleClassOfDynamic instance) => - <String, dynamic>{ - 'value': <String, dynamic>{ - r'$1': instance.value.$1, - 'named': instance.value.named, - }, - }; + SimpleClassOfDynamic instance, +) => <String, dynamic>{ + 'value': <String, dynamic>{ + r'$1': instance.value.$1, + 'named': instance.value.named, + }, +}; SimpleClassNullableOfDynamic _$SimpleClassNullableOfDynamicFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDynamic( - _$recordConvertNullable( - json['value'], - ($jsonValue) => ( - $jsonValue[r'$1'], - named: $jsonValue['named'], - ), - ), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfDynamic( + _$recordConvertNullable( + json['value'], + ($jsonValue) => ($jsonValue[r'$1'], named: $jsonValue['named']), + ), +); Map<String, dynamic> _$SimpleClassNullableOfDynamicToJson( - SimpleClassNullableOfDynamic instance) => - <String, dynamic>{ - 'value': instance.value == null - ? null - : <String, dynamic>{ - r'$1': instance.value!.$1, - 'named': instance.value!.named, - }, - }; + SimpleClassNullableOfDynamic instance, +) => <String, dynamic>{ + 'value': instance.value == null + ? null + : <String, dynamic>{ + r'$1': instance.value!.$1, + 'named': instance.value!.named, + }, +}; SimpleClassOfEnumType _$SimpleClassOfEnumTypeFromJson( - Map<String, dynamic> json) => - SimpleClassOfEnumType( - _$recordConvert( - json['value'], - ($jsonValue) => ( - $enumDecode(_$EnumTypeEnumMap, $jsonValue[r'$1']), - named: $enumDecode(_$EnumTypeEnumMap, $jsonValue['named']), - ), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfEnumType( + _$recordConvert( + json['value'], + ($jsonValue) => ( + $enumDecode(_$EnumTypeEnumMap, $jsonValue[r'$1']), + named: $enumDecode(_$EnumTypeEnumMap, $jsonValue['named']), + ), + ), +); Map<String, dynamic> _$SimpleClassOfEnumTypeToJson( - SimpleClassOfEnumType instance) => - <String, dynamic>{ - 'value': <String, dynamic>{ - r'$1': _$EnumTypeEnumMap[instance.value.$1]!, - 'named': _$EnumTypeEnumMap[instance.value.named]!, - }, - }; + SimpleClassOfEnumType instance, +) => <String, dynamic>{ + 'value': <String, dynamic>{ + r'$1': _$EnumTypeEnumMap[instance.value.$1]!, + 'named': _$EnumTypeEnumMap[instance.value.named]!, + }, +}; const _$EnumTypeEnumMap = { EnumType.alpha: 'alpha', @@ -576,32 +549,53 @@ const _$EnumTypeEnumMap = { }; SimpleClassNullableOfEnumType _$SimpleClassNullableOfEnumTypeFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfEnumType( - _$recordConvertNullable( - json['value'], - ($jsonValue) => ( - $enumDecode(_$EnumTypeEnumMap, $jsonValue[r'$1']), - named: $enumDecode(_$EnumTypeEnumMap, $jsonValue['named']), - ), - ), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfEnumType( + _$recordConvertNullable( + json['value'], + ($jsonValue) => ( + $enumDecode(_$EnumTypeEnumMap, $jsonValue[r'$1']), + named: $enumDecode(_$EnumTypeEnumMap, $jsonValue['named']), + ), + ), +); Map<String, dynamic> _$SimpleClassNullableOfEnumTypeToJson( - SimpleClassNullableOfEnumType instance) => - <String, dynamic>{ - 'value': instance.value == null - ? null - : <String, dynamic>{ - r'$1': _$EnumTypeEnumMap[instance.value!.$1]!, - 'named': _$EnumTypeEnumMap[instance.value!.named]!, - }, - }; + SimpleClassNullableOfEnumType instance, +) => <String, dynamic>{ + 'value': instance.value == null + ? null + : <String, dynamic>{ + r'$1': _$EnumTypeEnumMap[instance.value!.$1]!, + 'named': _$EnumTypeEnumMap[instance.value!.named]!, + }, +}; SimpleClassOfEnumTypeNullable _$SimpleClassOfEnumTypeNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfEnumTypeNullable( - _$recordConvert( + Map<String, dynamic> json, +) => SimpleClassOfEnumTypeNullable( + _$recordConvert( + json['value'], + ($jsonValue) => ( + $enumDecodeNullable(_$EnumTypeEnumMap, $jsonValue[r'$1']), + named: $enumDecodeNullable(_$EnumTypeEnumMap, $jsonValue['named']), + ), + ), +); + +Map<String, dynamic> _$SimpleClassOfEnumTypeNullableToJson( + SimpleClassOfEnumTypeNullable instance, +) => <String, dynamic>{ + 'value': <String, dynamic>{ + r'$1': _$EnumTypeEnumMap[instance.value.$1], + 'named': _$EnumTypeEnumMap[instance.value.named], + }, +}; + +SimpleClassNullableOfEnumTypeNullable +_$SimpleClassNullableOfEnumTypeNullableFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfEnumTypeNullable( + _$recordConvertNullable( json['value'], ($jsonValue) => ( $enumDecodeNullable(_$EnumTypeEnumMap, $jsonValue[r'$1']), @@ -610,176 +604,150 @@ SimpleClassOfEnumTypeNullable _$SimpleClassOfEnumTypeNullableFromJson( ), ); -Map<String, dynamic> _$SimpleClassOfEnumTypeNullableToJson( - SimpleClassOfEnumTypeNullable instance) => - <String, dynamic>{ - 'value': <String, dynamic>{ - r'$1': _$EnumTypeEnumMap[instance.value.$1], - 'named': _$EnumTypeEnumMap[instance.value.named], - }, - }; - -SimpleClassNullableOfEnumTypeNullable - _$SimpleClassNullableOfEnumTypeNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfEnumTypeNullable( - _$recordConvertNullable( - json['value'], - ($jsonValue) => ( - $enumDecodeNullable(_$EnumTypeEnumMap, $jsonValue[r'$1']), - named: - $enumDecodeNullable(_$EnumTypeEnumMap, $jsonValue['named']), - ), - ), - ); - Map<String, dynamic> _$SimpleClassNullableOfEnumTypeNullableToJson( - SimpleClassNullableOfEnumTypeNullable instance) => - <String, dynamic>{ - 'value': instance.value == null - ? null - : <String, dynamic>{ - r'$1': _$EnumTypeEnumMap[instance.value!.$1], - 'named': _$EnumTypeEnumMap[instance.value!.named], - }, - }; + SimpleClassNullableOfEnumTypeNullable instance, +) => <String, dynamic>{ + 'value': instance.value == null + ? null + : <String, dynamic>{ + r'$1': _$EnumTypeEnumMap[instance.value!.$1], + 'named': _$EnumTypeEnumMap[instance.value!.named], + }, +}; SimpleClassOfFromJsonDynamicParam _$SimpleClassOfFromJsonDynamicParamFromJson( - Map<String, dynamic> json) => - SimpleClassOfFromJsonDynamicParam( - _$recordConvert( - json['value'], - ($jsonValue) => ( - FromJsonDynamicParam.fromJson($jsonValue[r'$1']), - named: FromJsonDynamicParam.fromJson($jsonValue['named']), - ), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfFromJsonDynamicParam( + _$recordConvert( + json['value'], + ($jsonValue) => ( + FromJsonDynamicParam.fromJson($jsonValue[r'$1']), + named: FromJsonDynamicParam.fromJson($jsonValue['named']), + ), + ), +); Map<String, dynamic> _$SimpleClassOfFromJsonDynamicParamToJson( - SimpleClassOfFromJsonDynamicParam instance) => - <String, dynamic>{ - 'value': <String, dynamic>{ - r'$1': instance.value.$1, - 'named': instance.value.named, - }, - }; + SimpleClassOfFromJsonDynamicParam instance, +) => <String, dynamic>{ + 'value': <String, dynamic>{ + r'$1': instance.value.$1, + 'named': instance.value.named, + }, +}; SimpleClassNullableOfFromJsonDynamicParam - _$SimpleClassNullableOfFromJsonDynamicParamFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfFromJsonDynamicParam( - _$recordConvertNullable( - json['value'], - ($jsonValue) => ( - FromJsonDynamicParam.fromJson($jsonValue[r'$1']), - named: FromJsonDynamicParam.fromJson($jsonValue['named']), - ), - ), - ); +_$SimpleClassNullableOfFromJsonDynamicParamFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfFromJsonDynamicParam( + _$recordConvertNullable( + json['value'], + ($jsonValue) => ( + FromJsonDynamicParam.fromJson($jsonValue[r'$1']), + named: FromJsonDynamicParam.fromJson($jsonValue['named']), + ), + ), +); Map<String, dynamic> _$SimpleClassNullableOfFromJsonDynamicParamToJson( - SimpleClassNullableOfFromJsonDynamicParam instance) => - <String, dynamic>{ - 'value': instance.value == null - ? null - : <String, dynamic>{ - r'$1': instance.value!.$1, - 'named': instance.value!.named, - }, - }; + SimpleClassNullableOfFromJsonDynamicParam instance, +) => <String, dynamic>{ + 'value': instance.value == null + ? null + : <String, dynamic>{ + r'$1': instance.value!.$1, + 'named': instance.value!.named, + }, +}; SimpleClassOfFromJsonNullableObjectParam - _$SimpleClassOfFromJsonNullableObjectParamFromJson( - Map<String, dynamic> json) => - SimpleClassOfFromJsonNullableObjectParam( - _$recordConvert( - json['value'], - ($jsonValue) => ( - FromJsonNullableObjectParam.fromJson($jsonValue[r'$1']), - named: FromJsonNullableObjectParam.fromJson($jsonValue['named']), - ), - ), - ); +_$SimpleClassOfFromJsonNullableObjectParamFromJson(Map<String, dynamic> json) => + SimpleClassOfFromJsonNullableObjectParam( + _$recordConvert( + json['value'], + ($jsonValue) => ( + FromJsonNullableObjectParam.fromJson($jsonValue[r'$1']), + named: FromJsonNullableObjectParam.fromJson($jsonValue['named']), + ), + ), + ); Map<String, dynamic> _$SimpleClassOfFromJsonNullableObjectParamToJson( - SimpleClassOfFromJsonNullableObjectParam instance) => - <String, dynamic>{ - 'value': <String, dynamic>{ - r'$1': instance.value.$1, - 'named': instance.value.named, - }, - }; + SimpleClassOfFromJsonNullableObjectParam instance, +) => <String, dynamic>{ + 'value': <String, dynamic>{ + r'$1': instance.value.$1, + 'named': instance.value.named, + }, +}; SimpleClassNullableOfFromJsonNullableObjectParam - _$SimpleClassNullableOfFromJsonNullableObjectParamFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfFromJsonNullableObjectParam( - _$recordConvertNullable( - json['value'], - ($jsonValue) => ( - FromJsonNullableObjectParam.fromJson($jsonValue[r'$1']), - named: FromJsonNullableObjectParam.fromJson($jsonValue['named']), - ), - ), - ); +_$SimpleClassNullableOfFromJsonNullableObjectParamFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfFromJsonNullableObjectParam( + _$recordConvertNullable( + json['value'], + ($jsonValue) => ( + FromJsonNullableObjectParam.fromJson($jsonValue[r'$1']), + named: FromJsonNullableObjectParam.fromJson($jsonValue['named']), + ), + ), +); Map<String, dynamic> _$SimpleClassNullableOfFromJsonNullableObjectParamToJson( - SimpleClassNullableOfFromJsonNullableObjectParam instance) => - <String, dynamic>{ - 'value': instance.value == null - ? null - : <String, dynamic>{ - r'$1': instance.value!.$1, - 'named': instance.value!.named, - }, - }; + SimpleClassNullableOfFromJsonNullableObjectParam instance, +) => <String, dynamic>{ + 'value': instance.value == null + ? null + : <String, dynamic>{ + r'$1': instance.value!.$1, + 'named': instance.value!.named, + }, +}; SimpleClassOfFromJsonObjectParam _$SimpleClassOfFromJsonObjectParamFromJson( - Map<String, dynamic> json) => - SimpleClassOfFromJsonObjectParam( - _$recordConvert( - json['value'], - ($jsonValue) => ( - FromJsonObjectParam.fromJson($jsonValue[r'$1'] as Object), - named: FromJsonObjectParam.fromJson($jsonValue['named'] as Object), - ), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfFromJsonObjectParam( + _$recordConvert( + json['value'], + ($jsonValue) => ( + FromJsonObjectParam.fromJson($jsonValue[r'$1'] as Object), + named: FromJsonObjectParam.fromJson($jsonValue['named'] as Object), + ), + ), +); Map<String, dynamic> _$SimpleClassOfFromJsonObjectParamToJson( - SimpleClassOfFromJsonObjectParam instance) => - <String, dynamic>{ - 'value': <String, dynamic>{ - r'$1': instance.value.$1, - 'named': instance.value.named, - }, - }; + SimpleClassOfFromJsonObjectParam instance, +) => <String, dynamic>{ + 'value': <String, dynamic>{ + r'$1': instance.value.$1, + 'named': instance.value.named, + }, +}; SimpleClassNullableOfFromJsonObjectParam - _$SimpleClassNullableOfFromJsonObjectParamFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfFromJsonObjectParam( - _$recordConvertNullable( - json['value'], - ($jsonValue) => ( - FromJsonObjectParam.fromJson($jsonValue[r'$1'] as Object), - named: - FromJsonObjectParam.fromJson($jsonValue['named'] as Object), - ), - ), - ); +_$SimpleClassNullableOfFromJsonObjectParamFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfFromJsonObjectParam( + _$recordConvertNullable( + json['value'], + ($jsonValue) => ( + FromJsonObjectParam.fromJson($jsonValue[r'$1'] as Object), + named: FromJsonObjectParam.fromJson($jsonValue['named'] as Object), + ), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfFromJsonObjectParamToJson( - SimpleClassNullableOfFromJsonObjectParam instance) => - <String, dynamic>{ - 'value': instance.value == null - ? null - : <String, dynamic>{ - r'$1': instance.value!.$1, - 'named': instance.value!.named, - }, - }; + SimpleClassNullableOfFromJsonObjectParam instance, +) => <String, dynamic>{ + 'value': instance.value == null + ? null + : <String, dynamic>{ + r'$1': instance.value!.$1, + 'named': instance.value!.named, + }, +}; SimpleClassOfInt _$SimpleClassOfIntFromJson(Map<String, dynamic> json) => SimpleClassOfInt( @@ -801,80 +769,78 @@ Map<String, dynamic> _$SimpleClassOfIntToJson(SimpleClassOfInt instance) => }; SimpleClassNullableOfInt _$SimpleClassNullableOfIntFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfInt( - _$recordConvertNullable( - json['value'], - ($jsonValue) => ( - ($jsonValue[r'$1'] as num).toInt(), - named: ($jsonValue['named'] as num).toInt(), - ), - ), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfInt( + _$recordConvertNullable( + json['value'], + ($jsonValue) => ( + ($jsonValue[r'$1'] as num).toInt(), + named: ($jsonValue['named'] as num).toInt(), + ), + ), +); Map<String, dynamic> _$SimpleClassNullableOfIntToJson( - SimpleClassNullableOfInt instance) => - <String, dynamic>{ - 'value': instance.value == null - ? null - : <String, dynamic>{ - r'$1': instance.value!.$1, - 'named': instance.value!.named, - }, - }; + SimpleClassNullableOfInt instance, +) => <String, dynamic>{ + 'value': instance.value == null + ? null + : <String, dynamic>{ + r'$1': instance.value!.$1, + 'named': instance.value!.named, + }, +}; SimpleClassOfIntNullable _$SimpleClassOfIntNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfIntNullable( - _$recordConvert( - json['value'], - ($jsonValue) => ( - ($jsonValue[r'$1'] as num?)?.toInt(), - named: ($jsonValue['named'] as num?)?.toInt(), - ), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfIntNullable( + _$recordConvert( + json['value'], + ($jsonValue) => ( + ($jsonValue[r'$1'] as num?)?.toInt(), + named: ($jsonValue['named'] as num?)?.toInt(), + ), + ), +); Map<String, dynamic> _$SimpleClassOfIntNullableToJson( - SimpleClassOfIntNullable instance) => - <String, dynamic>{ - 'value': <String, dynamic>{ - r'$1': instance.value.$1, - 'named': instance.value.named, - }, - }; + SimpleClassOfIntNullable instance, +) => <String, dynamic>{ + 'value': <String, dynamic>{ + r'$1': instance.value.$1, + 'named': instance.value.named, + }, +}; SimpleClassNullableOfIntNullable _$SimpleClassNullableOfIntNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfIntNullable( - _$recordConvertNullable( - json['value'], - ($jsonValue) => ( - ($jsonValue[r'$1'] as num?)?.toInt(), - named: ($jsonValue['named'] as num?)?.toInt(), - ), - ), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfIntNullable( + _$recordConvertNullable( + json['value'], + ($jsonValue) => ( + ($jsonValue[r'$1'] as num?)?.toInt(), + named: ($jsonValue['named'] as num?)?.toInt(), + ), + ), +); Map<String, dynamic> _$SimpleClassNullableOfIntNullableToJson( - SimpleClassNullableOfIntNullable instance) => - <String, dynamic>{ - 'value': instance.value == null - ? null - : <String, dynamic>{ - r'$1': instance.value!.$1, - 'named': instance.value!.named, - }, - }; + SimpleClassNullableOfIntNullable instance, +) => <String, dynamic>{ + 'value': instance.value == null + ? null + : <String, dynamic>{ + r'$1': instance.value!.$1, + 'named': instance.value!.named, + }, +}; SimpleClassOfNum _$SimpleClassOfNumFromJson(Map<String, dynamic> json) => SimpleClassOfNum( _$recordConvert( json['value'], - ($jsonValue) => ( - $jsonValue[r'$1'] as num, - named: $jsonValue['named'] as num, - ), + ($jsonValue) => + ($jsonValue[r'$1'] as num, named: $jsonValue['named'] as num), ), ); @@ -887,158 +853,142 @@ Map<String, dynamic> _$SimpleClassOfNumToJson(SimpleClassOfNum instance) => }; SimpleClassNullableOfNum _$SimpleClassNullableOfNumFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfNum( - _$recordConvertNullable( - json['value'], - ($jsonValue) => ( - $jsonValue[r'$1'] as num, - named: $jsonValue['named'] as num, - ), - ), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfNum( + _$recordConvertNullable( + json['value'], + ($jsonValue) => + ($jsonValue[r'$1'] as num, named: $jsonValue['named'] as num), + ), +); Map<String, dynamic> _$SimpleClassNullableOfNumToJson( - SimpleClassNullableOfNum instance) => - <String, dynamic>{ - 'value': instance.value == null - ? null - : <String, dynamic>{ - r'$1': instance.value!.$1, - 'named': instance.value!.named, - }, - }; + SimpleClassNullableOfNum instance, +) => <String, dynamic>{ + 'value': instance.value == null + ? null + : <String, dynamic>{ + r'$1': instance.value!.$1, + 'named': instance.value!.named, + }, +}; SimpleClassOfNumNullable _$SimpleClassOfNumNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfNumNullable( - _$recordConvert( - json['value'], - ($jsonValue) => ( - $jsonValue[r'$1'] as num?, - named: $jsonValue['named'] as num?, - ), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfNumNullable( + _$recordConvert( + json['value'], + ($jsonValue) => + ($jsonValue[r'$1'] as num?, named: $jsonValue['named'] as num?), + ), +); Map<String, dynamic> _$SimpleClassOfNumNullableToJson( - SimpleClassOfNumNullable instance) => - <String, dynamic>{ - 'value': <String, dynamic>{ - r'$1': instance.value.$1, - 'named': instance.value.named, - }, - }; + SimpleClassOfNumNullable instance, +) => <String, dynamic>{ + 'value': <String, dynamic>{ + r'$1': instance.value.$1, + 'named': instance.value.named, + }, +}; SimpleClassNullableOfNumNullable _$SimpleClassNullableOfNumNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfNumNullable( - _$recordConvertNullable( - json['value'], - ($jsonValue) => ( - $jsonValue[r'$1'] as num?, - named: $jsonValue['named'] as num?, - ), - ), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfNumNullable( + _$recordConvertNullable( + json['value'], + ($jsonValue) => + ($jsonValue[r'$1'] as num?, named: $jsonValue['named'] as num?), + ), +); Map<String, dynamic> _$SimpleClassNullableOfNumNullableToJson( - SimpleClassNullableOfNumNullable instance) => - <String, dynamic>{ - 'value': instance.value == null - ? null - : <String, dynamic>{ - r'$1': instance.value!.$1, - 'named': instance.value!.named, - }, - }; + SimpleClassNullableOfNumNullable instance, +) => <String, dynamic>{ + 'value': instance.value == null + ? null + : <String, dynamic>{ + r'$1': instance.value!.$1, + 'named': instance.value!.named, + }, +}; SimpleClassOfObject _$SimpleClassOfObjectFromJson(Map<String, dynamic> json) => SimpleClassOfObject( _$recordConvert( json['value'], - ($jsonValue) => ( - $jsonValue[r'$1'] as Object, - named: $jsonValue['named'] as Object, - ), + ($jsonValue) => + ($jsonValue[r'$1'] as Object, named: $jsonValue['named'] as Object), ), ); Map<String, dynamic> _$SimpleClassOfObjectToJson( - SimpleClassOfObject instance) => - <String, dynamic>{ - 'value': <String, dynamic>{ - r'$1': instance.value.$1, - 'named': instance.value.named, - }, - }; + SimpleClassOfObject instance, +) => <String, dynamic>{ + 'value': <String, dynamic>{ + r'$1': instance.value.$1, + 'named': instance.value.named, + }, +}; SimpleClassNullableOfObject _$SimpleClassNullableOfObjectFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfObject( - _$recordConvertNullable( - json['value'], - ($jsonValue) => ( - $jsonValue[r'$1'] as Object, - named: $jsonValue['named'] as Object, - ), - ), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfObject( + _$recordConvertNullable( + json['value'], + ($jsonValue) => + ($jsonValue[r'$1'] as Object, named: $jsonValue['named'] as Object), + ), +); Map<String, dynamic> _$SimpleClassNullableOfObjectToJson( - SimpleClassNullableOfObject instance) => - <String, dynamic>{ - 'value': instance.value == null - ? null - : <String, dynamic>{ - r'$1': instance.value!.$1, - 'named': instance.value!.named, - }, - }; + SimpleClassNullableOfObject instance, +) => <String, dynamic>{ + 'value': instance.value == null + ? null + : <String, dynamic>{ + r'$1': instance.value!.$1, + 'named': instance.value!.named, + }, +}; SimpleClassOfObjectNullable _$SimpleClassOfObjectNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfObjectNullable( - _$recordConvert( - json['value'], - ($jsonValue) => ( - $jsonValue[r'$1'], - named: $jsonValue['named'], - ), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfObjectNullable( + _$recordConvert( + json['value'], + ($jsonValue) => ($jsonValue[r'$1'], named: $jsonValue['named']), + ), +); Map<String, dynamic> _$SimpleClassOfObjectNullableToJson( - SimpleClassOfObjectNullable instance) => - <String, dynamic>{ - 'value': <String, dynamic>{ - r'$1': instance.value.$1, - 'named': instance.value.named, - }, - }; + SimpleClassOfObjectNullable instance, +) => <String, dynamic>{ + 'value': <String, dynamic>{ + r'$1': instance.value.$1, + 'named': instance.value.named, + }, +}; SimpleClassNullableOfObjectNullable - _$SimpleClassNullableOfObjectNullableFromJson(Map<String, dynamic> json) => - SimpleClassNullableOfObjectNullable( - _$recordConvertNullable( - json['value'], - ($jsonValue) => ( - $jsonValue[r'$1'], - named: $jsonValue['named'], - ), - ), - ); +_$SimpleClassNullableOfObjectNullableFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfObjectNullable( + _$recordConvertNullable( + json['value'], + ($jsonValue) => ($jsonValue[r'$1'], named: $jsonValue['named']), + ), + ); Map<String, dynamic> _$SimpleClassNullableOfObjectNullableToJson( - SimpleClassNullableOfObjectNullable instance) => - <String, dynamic>{ - 'value': instance.value == null - ? null - : <String, dynamic>{ - r'$1': instance.value!.$1, - 'named': instance.value!.named, - }, - }; + SimpleClassNullableOfObjectNullable instance, +) => <String, dynamic>{ + 'value': instance.value == null + ? null + : <String, dynamic>{ + r'$1': instance.value!.$1, + 'named': instance.value!.named, + }, +}; SimpleClassOfRecord _$SimpleClassOfRecordFromJson(Map<String, dynamic> json) => SimpleClassOfRecord( @@ -1066,114 +1016,129 @@ SimpleClassOfRecord _$SimpleClassOfRecordFromJson(Map<String, dynamic> json) => ); Map<String, dynamic> _$SimpleClassOfRecordToJson( - SimpleClassOfRecord instance) => - <String, dynamic>{ - 'value': <String, dynamic>{ - r'$1': <String, dynamic>{ - r'$1': instance.value.$1.$1, - r'$2': instance.value.$1.$2, - 'truth': instance.value.$1.truth, - }, - 'named': <String, dynamic>{ - r'$1': instance.value.named.$1, - r'$2': instance.value.named.$2, - 'truth': instance.value.named.truth, - }, - }, - }; + SimpleClassOfRecord instance, +) => <String, dynamic>{ + 'value': <String, dynamic>{ + r'$1': <String, dynamic>{ + r'$1': instance.value.$1.$1, + r'$2': instance.value.$1.$2, + 'truth': instance.value.$1.truth, + }, + 'named': <String, dynamic>{ + r'$1': instance.value.named.$1, + r'$2': instance.value.named.$2, + 'truth': instance.value.named.truth, + }, + }, +}; SimpleClassNullableOfRecord _$SimpleClassNullableOfRecordFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfRecord( - _$recordConvertNullable( - json['value'], + Map<String, dynamic> json, +) => SimpleClassNullableOfRecord( + _$recordConvertNullable( + json['value'], + ($jsonValue) => ( + _$recordConvert( + $jsonValue[r'$1'], ($jsonValue) => ( - _$recordConvert( - $jsonValue[r'$1'], - ($jsonValue) => ( - ($jsonValue[r'$1'] as num).toInt(), - $jsonValue[r'$2'] as String, - truth: $jsonValue['truth'] as bool, - ), - ), - named: _$recordConvert( - $jsonValue['named'], - ($jsonValue) => ( - ($jsonValue[r'$1'] as num).toInt(), - $jsonValue[r'$2'] as String, - truth: $jsonValue['truth'] as bool, - ), - ), + ($jsonValue[r'$1'] as num).toInt(), + $jsonValue[r'$2'] as String, + truth: $jsonValue['truth'] as bool, ), ), - ); + named: _$recordConvert( + $jsonValue['named'], + ($jsonValue) => ( + ($jsonValue[r'$1'] as num).toInt(), + $jsonValue[r'$2'] as String, + truth: $jsonValue['truth'] as bool, + ), + ), + ), + ), +); Map<String, dynamic> _$SimpleClassNullableOfRecordToJson( - SimpleClassNullableOfRecord instance) => - <String, dynamic>{ - 'value': instance.value == null - ? null - : <String, dynamic>{ - r'$1': <String, dynamic>{ - r'$1': instance.value!.$1.$1, - r'$2': instance.value!.$1.$2, - 'truth': instance.value!.$1.truth, - }, - 'named': <String, dynamic>{ - r'$1': instance.value!.named.$1, - r'$2': instance.value!.named.$2, - 'truth': instance.value!.named.truth, - }, - }, - }; + SimpleClassNullableOfRecord instance, +) => <String, dynamic>{ + 'value': instance.value == null + ? null + : <String, dynamic>{ + r'$1': <String, dynamic>{ + r'$1': instance.value!.$1.$1, + r'$2': instance.value!.$1.$2, + 'truth': instance.value!.$1.truth, + }, + 'named': <String, dynamic>{ + r'$1': instance.value!.named.$1, + r'$2': instance.value!.named.$2, + 'truth': instance.value!.named.truth, + }, + }, +}; SimpleClassOfString _$SimpleClassOfStringFromJson(Map<String, dynamic> json) => SimpleClassOfString( _$recordConvert( json['value'], - ($jsonValue) => ( - $jsonValue[r'$1'] as String, - named: $jsonValue['named'] as String, - ), + ($jsonValue) => + ($jsonValue[r'$1'] as String, named: $jsonValue['named'] as String), ), ); Map<String, dynamic> _$SimpleClassOfStringToJson( - SimpleClassOfString instance) => - <String, dynamic>{ - 'value': <String, dynamic>{ - r'$1': instance.value.$1, - 'named': instance.value.named, - }, - }; + SimpleClassOfString instance, +) => <String, dynamic>{ + 'value': <String, dynamic>{ + r'$1': instance.value.$1, + 'named': instance.value.named, + }, +}; SimpleClassNullableOfString _$SimpleClassNullableOfStringFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfString( - _$recordConvertNullable( - json['value'], - ($jsonValue) => ( - $jsonValue[r'$1'] as String, - named: $jsonValue['named'] as String, - ), - ), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfString( + _$recordConvertNullable( + json['value'], + ($jsonValue) => + ($jsonValue[r'$1'] as String, named: $jsonValue['named'] as String), + ), +); Map<String, dynamic> _$SimpleClassNullableOfStringToJson( - SimpleClassNullableOfString instance) => - <String, dynamic>{ - 'value': instance.value == null - ? null - : <String, dynamic>{ - r'$1': instance.value!.$1, - 'named': instance.value!.named, - }, - }; + SimpleClassNullableOfString instance, +) => <String, dynamic>{ + 'value': instance.value == null + ? null + : <String, dynamic>{ + r'$1': instance.value!.$1, + 'named': instance.value!.named, + }, +}; SimpleClassOfStringNullable _$SimpleClassOfStringNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfStringNullable( - _$recordConvert( + Map<String, dynamic> json, +) => SimpleClassOfStringNullable( + _$recordConvert( + json['value'], + ($jsonValue) => + ($jsonValue[r'$1'] as String?, named: $jsonValue['named'] as String?), + ), +); + +Map<String, dynamic> _$SimpleClassOfStringNullableToJson( + SimpleClassOfStringNullable instance, +) => <String, dynamic>{ + 'value': <String, dynamic>{ + r'$1': instance.value.$1, + 'named': instance.value.named, + }, +}; + +SimpleClassNullableOfStringNullable +_$SimpleClassNullableOfStringNullableFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfStringNullable( + _$recordConvertNullable( json['value'], ($jsonValue) => ( $jsonValue[r'$1'] as String?, @@ -1182,37 +1147,16 @@ SimpleClassOfStringNullable _$SimpleClassOfStringNullableFromJson( ), ); -Map<String, dynamic> _$SimpleClassOfStringNullableToJson( - SimpleClassOfStringNullable instance) => - <String, dynamic>{ - 'value': <String, dynamic>{ - r'$1': instance.value.$1, - 'named': instance.value.named, - }, - }; - -SimpleClassNullableOfStringNullable - _$SimpleClassNullableOfStringNullableFromJson(Map<String, dynamic> json) => - SimpleClassNullableOfStringNullable( - _$recordConvertNullable( - json['value'], - ($jsonValue) => ( - $jsonValue[r'$1'] as String?, - named: $jsonValue['named'] as String?, - ), - ), - ); - Map<String, dynamic> _$SimpleClassNullableOfStringNullableToJson( - SimpleClassNullableOfStringNullable instance) => - <String, dynamic>{ - 'value': instance.value == null - ? null - : <String, dynamic>{ - r'$1': instance.value!.$1, - 'named': instance.value!.named, - }, - }; + SimpleClassNullableOfStringNullable instance, +) => <String, dynamic>{ + 'value': instance.value == null + ? null + : <String, dynamic>{ + r'$1': instance.value!.$1, + 'named': instance.value!.named, + }, +}; SimpleClassOfUri _$SimpleClassOfUriFromJson(Map<String, dynamic> json) => SimpleClassOfUri( @@ -1234,76 +1178,72 @@ Map<String, dynamic> _$SimpleClassOfUriToJson(SimpleClassOfUri instance) => }; SimpleClassNullableOfUri _$SimpleClassNullableOfUriFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfUri( - _$recordConvertNullable( - json['value'], - ($jsonValue) => ( - Uri.parse($jsonValue[r'$1'] as String), - named: Uri.parse($jsonValue['named'] as String), - ), - ), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfUri( + _$recordConvertNullable( + json['value'], + ($jsonValue) => ( + Uri.parse($jsonValue[r'$1'] as String), + named: Uri.parse($jsonValue['named'] as String), + ), + ), +); Map<String, dynamic> _$SimpleClassNullableOfUriToJson( - SimpleClassNullableOfUri instance) => - <String, dynamic>{ - 'value': instance.value == null - ? null - : <String, dynamic>{ - r'$1': instance.value!.$1.toString(), - 'named': instance.value!.named.toString(), - }, - }; + SimpleClassNullableOfUri instance, +) => <String, dynamic>{ + 'value': instance.value == null + ? null + : <String, dynamic>{ + r'$1': instance.value!.$1.toString(), + 'named': instance.value!.named.toString(), + }, +}; SimpleClassOfUriNullable _$SimpleClassOfUriNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfUriNullable( - _$recordConvert( - json['value'], - ($jsonValue) => ( - $jsonValue[r'$1'] == null - ? null - : Uri.parse($jsonValue[r'$1'] as String), - named: $jsonValue['named'] == null - ? null - : Uri.parse($jsonValue['named'] as String), - ), - ), - ); + Map<String, dynamic> json, +) => SimpleClassOfUriNullable( + _$recordConvert( + json['value'], + ($jsonValue) => ( + $jsonValue[r'$1'] == null ? null : Uri.parse($jsonValue[r'$1'] as String), + named: $jsonValue['named'] == null + ? null + : Uri.parse($jsonValue['named'] as String), + ), + ), +); Map<String, dynamic> _$SimpleClassOfUriNullableToJson( - SimpleClassOfUriNullable instance) => - <String, dynamic>{ - 'value': <String, dynamic>{ - r'$1': instance.value.$1?.toString(), - 'named': instance.value.named?.toString(), - }, - }; + SimpleClassOfUriNullable instance, +) => <String, dynamic>{ + 'value': <String, dynamic>{ + r'$1': instance.value.$1?.toString(), + 'named': instance.value.named?.toString(), + }, +}; SimpleClassNullableOfUriNullable _$SimpleClassNullableOfUriNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfUriNullable( - _$recordConvertNullable( - json['value'], - ($jsonValue) => ( - $jsonValue[r'$1'] == null - ? null - : Uri.parse($jsonValue[r'$1'] as String), - named: $jsonValue['named'] == null - ? null - : Uri.parse($jsonValue['named'] as String), - ), - ), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfUriNullable( + _$recordConvertNullable( + json['value'], + ($jsonValue) => ( + $jsonValue[r'$1'] == null ? null : Uri.parse($jsonValue[r'$1'] as String), + named: $jsonValue['named'] == null + ? null + : Uri.parse($jsonValue['named'] as String), + ), + ), +); Map<String, dynamic> _$SimpleClassNullableOfUriNullableToJson( - SimpleClassNullableOfUriNullable instance) => - <String, dynamic>{ - 'value': instance.value == null - ? null - : <String, dynamic>{ - r'$1': instance.value!.$1?.toString(), - 'named': instance.value!.named?.toString(), - }, - }; + SimpleClassNullableOfUriNullable instance, +) => <String, dynamic>{ + 'value': instance.value == null + ? null + : <String, dynamic>{ + r'$1': instance.value!.$1?.toString(), + 'named': instance.value!.named?.toString(), + }, +}; diff --git a/json_serializable/test/supported_types/input.type_set.dart b/json_serializable/test/supported_types/input.type_set.dart index 398e3f7aa..f22d10928 100644 --- a/json_serializable/test/supported_types/input.type_set.dart +++ b/json_serializable/test/supported_types/input.type_set.dart @@ -14,10 +14,7 @@ class SimpleClass { @JsonKey(defaultValue: {42, true, false, null}) Set withDefault; - SimpleClass( - this.value, - this.withDefault, - ); + SimpleClass(this.value, this.withDefault); factory SimpleClass.fromJson(Map<String, Object?> json) => _$SimpleClassFromJson(json); @@ -32,10 +29,7 @@ class SimpleClassNullable { @JsonKey(defaultValue: {42, true, false, null}) Set? withDefault; - SimpleClassNullable( - this.value, - this.withDefault, - ); + SimpleClassNullable(this.value, this.withDefault); factory SimpleClassNullable.fromJson(Map<String, Object?> json) => _$SimpleClassNullableFromJson(json); @@ -47,9 +41,7 @@ class SimpleClassNullable { class SimpleClassOfBigInt { final Set<BigInt> value; - SimpleClassOfBigInt( - this.value, - ); + SimpleClassOfBigInt(this.value); factory SimpleClassOfBigInt.fromJson(Map<String, Object?> json) => _$SimpleClassOfBigIntFromJson(json); @@ -61,9 +53,7 @@ class SimpleClassOfBigInt { class SimpleClassNullableOfBigInt { final Set<BigInt>? value; - SimpleClassNullableOfBigInt( - this.value, - ); + SimpleClassNullableOfBigInt(this.value); factory SimpleClassNullableOfBigInt.fromJson(Map<String, Object?> json) => _$SimpleClassNullableOfBigIntFromJson(json); @@ -75,9 +65,7 @@ class SimpleClassNullableOfBigInt { class SimpleClassOfBigIntNullable { final Set<BigInt?> value; - SimpleClassOfBigIntNullable( - this.value, - ); + SimpleClassOfBigIntNullable(this.value); factory SimpleClassOfBigIntNullable.fromJson(Map<String, Object?> json) => _$SimpleClassOfBigIntNullableFromJson(json); @@ -89,13 +77,11 @@ class SimpleClassOfBigIntNullable { class SimpleClassNullableOfBigIntNullable { final Set<BigInt?>? value; - SimpleClassNullableOfBigIntNullable( - this.value, - ); + SimpleClassNullableOfBigIntNullable(this.value); factory SimpleClassNullableOfBigIntNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfBigIntNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfBigIntNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfBigIntNullableToJson(this); @@ -105,9 +91,7 @@ class SimpleClassNullableOfBigIntNullable { class SimpleClassOfBool { final Set<bool> value; - SimpleClassOfBool( - this.value, - ); + SimpleClassOfBool(this.value); factory SimpleClassOfBool.fromJson(Map<String, Object?> json) => _$SimpleClassOfBoolFromJson(json); @@ -119,9 +103,7 @@ class SimpleClassOfBool { class SimpleClassNullableOfBool { final Set<bool>? value; - SimpleClassNullableOfBool( - this.value, - ); + SimpleClassNullableOfBool(this.value); factory SimpleClassNullableOfBool.fromJson(Map<String, Object?> json) => _$SimpleClassNullableOfBoolFromJson(json); @@ -133,9 +115,7 @@ class SimpleClassNullableOfBool { class SimpleClassOfBoolNullable { final Set<bool?> value; - SimpleClassOfBoolNullable( - this.value, - ); + SimpleClassOfBoolNullable(this.value); factory SimpleClassOfBoolNullable.fromJson(Map<String, Object?> json) => _$SimpleClassOfBoolNullableFromJson(json); @@ -147,13 +127,11 @@ class SimpleClassOfBoolNullable { class SimpleClassNullableOfBoolNullable { final Set<bool?>? value; - SimpleClassNullableOfBoolNullable( - this.value, - ); + SimpleClassNullableOfBoolNullable(this.value); factory SimpleClassNullableOfBoolNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfBoolNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfBoolNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfBoolNullableToJson(this); @@ -163,9 +141,7 @@ class SimpleClassNullableOfBoolNullable { class SimpleClassOfDateTime { final Set<DateTime> value; - SimpleClassOfDateTime( - this.value, - ); + SimpleClassOfDateTime(this.value); factory SimpleClassOfDateTime.fromJson(Map<String, Object?> json) => _$SimpleClassOfDateTimeFromJson(json); @@ -177,9 +153,7 @@ class SimpleClassOfDateTime { class SimpleClassNullableOfDateTime { final Set<DateTime>? value; - SimpleClassNullableOfDateTime( - this.value, - ); + SimpleClassNullableOfDateTime(this.value); factory SimpleClassNullableOfDateTime.fromJson(Map<String, Object?> json) => _$SimpleClassNullableOfDateTimeFromJson(json); @@ -191,9 +165,7 @@ class SimpleClassNullableOfDateTime { class SimpleClassOfDateTimeNullable { final Set<DateTime?> value; - SimpleClassOfDateTimeNullable( - this.value, - ); + SimpleClassOfDateTimeNullable(this.value); factory SimpleClassOfDateTimeNullable.fromJson(Map<String, Object?> json) => _$SimpleClassOfDateTimeNullableFromJson(json); @@ -205,13 +177,11 @@ class SimpleClassOfDateTimeNullable { class SimpleClassNullableOfDateTimeNullable { final Set<DateTime?>? value; - SimpleClassNullableOfDateTimeNullable( - this.value, - ); + SimpleClassNullableOfDateTimeNullable(this.value); factory SimpleClassNullableOfDateTimeNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfDateTimeNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfDateTimeNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfDateTimeNullableToJson(this); @@ -221,9 +191,7 @@ class SimpleClassNullableOfDateTimeNullable { class SimpleClassOfDouble { final Set<double> value; - SimpleClassOfDouble( - this.value, - ); + SimpleClassOfDouble(this.value); factory SimpleClassOfDouble.fromJson(Map<String, Object?> json) => _$SimpleClassOfDoubleFromJson(json); @@ -235,9 +203,7 @@ class SimpleClassOfDouble { class SimpleClassNullableOfDouble { final Set<double>? value; - SimpleClassNullableOfDouble( - this.value, - ); + SimpleClassNullableOfDouble(this.value); factory SimpleClassNullableOfDouble.fromJson(Map<String, Object?> json) => _$SimpleClassNullableOfDoubleFromJson(json); @@ -249,9 +215,7 @@ class SimpleClassNullableOfDouble { class SimpleClassOfDoubleNullable { final Set<double?> value; - SimpleClassOfDoubleNullable( - this.value, - ); + SimpleClassOfDoubleNullable(this.value); factory SimpleClassOfDoubleNullable.fromJson(Map<String, Object?> json) => _$SimpleClassOfDoubleNullableFromJson(json); @@ -263,13 +227,11 @@ class SimpleClassOfDoubleNullable { class SimpleClassNullableOfDoubleNullable { final Set<double?>? value; - SimpleClassNullableOfDoubleNullable( - this.value, - ); + SimpleClassNullableOfDoubleNullable(this.value); factory SimpleClassNullableOfDoubleNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfDoubleNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfDoubleNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfDoubleNullableToJson(this); @@ -279,9 +241,7 @@ class SimpleClassNullableOfDoubleNullable { class SimpleClassOfDuration { final Set<Duration> value; - SimpleClassOfDuration( - this.value, - ); + SimpleClassOfDuration(this.value); factory SimpleClassOfDuration.fromJson(Map<String, Object?> json) => _$SimpleClassOfDurationFromJson(json); @@ -293,9 +253,7 @@ class SimpleClassOfDuration { class SimpleClassNullableOfDuration { final Set<Duration>? value; - SimpleClassNullableOfDuration( - this.value, - ); + SimpleClassNullableOfDuration(this.value); factory SimpleClassNullableOfDuration.fromJson(Map<String, Object?> json) => _$SimpleClassNullableOfDurationFromJson(json); @@ -307,9 +265,7 @@ class SimpleClassNullableOfDuration { class SimpleClassOfDurationNullable { final Set<Duration?> value; - SimpleClassOfDurationNullable( - this.value, - ); + SimpleClassOfDurationNullable(this.value); factory SimpleClassOfDurationNullable.fromJson(Map<String, Object?> json) => _$SimpleClassOfDurationNullableFromJson(json); @@ -321,13 +277,11 @@ class SimpleClassOfDurationNullable { class SimpleClassNullableOfDurationNullable { final Set<Duration?>? value; - SimpleClassNullableOfDurationNullable( - this.value, - ); + SimpleClassNullableOfDurationNullable(this.value); factory SimpleClassNullableOfDurationNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfDurationNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfDurationNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfDurationNullableToJson(this); @@ -337,9 +291,7 @@ class SimpleClassNullableOfDurationNullable { class SimpleClassOfDynamic { final Set<dynamic> value; - SimpleClassOfDynamic( - this.value, - ); + SimpleClassOfDynamic(this.value); factory SimpleClassOfDynamic.fromJson(Map<String, Object?> json) => _$SimpleClassOfDynamicFromJson(json); @@ -351,9 +303,7 @@ class SimpleClassOfDynamic { class SimpleClassNullableOfDynamic { final Set<dynamic>? value; - SimpleClassNullableOfDynamic( - this.value, - ); + SimpleClassNullableOfDynamic(this.value); factory SimpleClassNullableOfDynamic.fromJson(Map<String, Object?> json) => _$SimpleClassNullableOfDynamicFromJson(json); @@ -365,9 +315,7 @@ class SimpleClassNullableOfDynamic { class SimpleClassOfEnumType { final Set<EnumType> value; - SimpleClassOfEnumType( - this.value, - ); + SimpleClassOfEnumType(this.value); factory SimpleClassOfEnumType.fromJson(Map<String, Object?> json) => _$SimpleClassOfEnumTypeFromJson(json); @@ -379,9 +327,7 @@ class SimpleClassOfEnumType { class SimpleClassNullableOfEnumType { final Set<EnumType>? value; - SimpleClassNullableOfEnumType( - this.value, - ); + SimpleClassNullableOfEnumType(this.value); factory SimpleClassNullableOfEnumType.fromJson(Map<String, Object?> json) => _$SimpleClassNullableOfEnumTypeFromJson(json); @@ -393,9 +339,7 @@ class SimpleClassNullableOfEnumType { class SimpleClassOfEnumTypeNullable { final Set<EnumType?> value; - SimpleClassOfEnumTypeNullable( - this.value, - ); + SimpleClassOfEnumTypeNullable(this.value); factory SimpleClassOfEnumTypeNullable.fromJson(Map<String, Object?> json) => _$SimpleClassOfEnumTypeNullableFromJson(json); @@ -407,13 +351,11 @@ class SimpleClassOfEnumTypeNullable { class SimpleClassNullableOfEnumTypeNullable { final Set<EnumType?>? value; - SimpleClassNullableOfEnumTypeNullable( - this.value, - ); + SimpleClassNullableOfEnumTypeNullable(this.value); factory SimpleClassNullableOfEnumTypeNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfEnumTypeNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfEnumTypeNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfEnumTypeNullableToJson(this); @@ -423,13 +365,11 @@ class SimpleClassNullableOfEnumTypeNullable { class SimpleClassOfFromJsonDynamicParam { final Set<FromJsonDynamicParam> value; - SimpleClassOfFromJsonDynamicParam( - this.value, - ); + SimpleClassOfFromJsonDynamicParam(this.value); factory SimpleClassOfFromJsonDynamicParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfFromJsonDynamicParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfFromJsonDynamicParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfFromJsonDynamicParamToJson(this); @@ -439,13 +379,11 @@ class SimpleClassOfFromJsonDynamicParam { class SimpleClassNullableOfFromJsonDynamicParam { final Set<FromJsonDynamicParam>? value; - SimpleClassNullableOfFromJsonDynamicParam( - this.value, - ); + SimpleClassNullableOfFromJsonDynamicParam(this.value); factory SimpleClassNullableOfFromJsonDynamicParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfFromJsonDynamicParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfFromJsonDynamicParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfFromJsonDynamicParamToJson(this); @@ -455,13 +393,11 @@ class SimpleClassNullableOfFromJsonDynamicParam { class SimpleClassOfFromJsonNullableObjectParam { final Set<FromJsonNullableObjectParam> value; - SimpleClassOfFromJsonNullableObjectParam( - this.value, - ); + SimpleClassOfFromJsonNullableObjectParam(this.value); factory SimpleClassOfFromJsonNullableObjectParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfFromJsonNullableObjectParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfFromJsonNullableObjectParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfFromJsonNullableObjectParamToJson(this); @@ -471,13 +407,11 @@ class SimpleClassOfFromJsonNullableObjectParam { class SimpleClassNullableOfFromJsonNullableObjectParam { final Set<FromJsonNullableObjectParam>? value; - SimpleClassNullableOfFromJsonNullableObjectParam( - this.value, - ); + SimpleClassNullableOfFromJsonNullableObjectParam(this.value); factory SimpleClassNullableOfFromJsonNullableObjectParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfFromJsonNullableObjectParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfFromJsonNullableObjectParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfFromJsonNullableObjectParamToJson(this); @@ -487,13 +421,11 @@ class SimpleClassNullableOfFromJsonNullableObjectParam { class SimpleClassOfFromJsonObjectParam { final Set<FromJsonObjectParam> value; - SimpleClassOfFromJsonObjectParam( - this.value, - ); + SimpleClassOfFromJsonObjectParam(this.value); factory SimpleClassOfFromJsonObjectParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassOfFromJsonObjectParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassOfFromJsonObjectParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassOfFromJsonObjectParamToJson(this); @@ -503,13 +435,11 @@ class SimpleClassOfFromJsonObjectParam { class SimpleClassNullableOfFromJsonObjectParam { final Set<FromJsonObjectParam>? value; - SimpleClassNullableOfFromJsonObjectParam( - this.value, - ); + SimpleClassNullableOfFromJsonObjectParam(this.value); factory SimpleClassNullableOfFromJsonObjectParam.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfFromJsonObjectParamFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfFromJsonObjectParamFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfFromJsonObjectParamToJson(this); @@ -519,9 +449,7 @@ class SimpleClassNullableOfFromJsonObjectParam { class SimpleClassOfInt { final Set<int> value; - SimpleClassOfInt( - this.value, - ); + SimpleClassOfInt(this.value); factory SimpleClassOfInt.fromJson(Map<String, Object?> json) => _$SimpleClassOfIntFromJson(json); @@ -533,9 +461,7 @@ class SimpleClassOfInt { class SimpleClassNullableOfInt { final Set<int>? value; - SimpleClassNullableOfInt( - this.value, - ); + SimpleClassNullableOfInt(this.value); factory SimpleClassNullableOfInt.fromJson(Map<String, Object?> json) => _$SimpleClassNullableOfIntFromJson(json); @@ -547,9 +473,7 @@ class SimpleClassNullableOfInt { class SimpleClassOfIntNullable { final Set<int?> value; - SimpleClassOfIntNullable( - this.value, - ); + SimpleClassOfIntNullable(this.value); factory SimpleClassOfIntNullable.fromJson(Map<String, Object?> json) => _$SimpleClassOfIntNullableFromJson(json); @@ -561,13 +485,11 @@ class SimpleClassOfIntNullable { class SimpleClassNullableOfIntNullable { final Set<int?>? value; - SimpleClassNullableOfIntNullable( - this.value, - ); + SimpleClassNullableOfIntNullable(this.value); factory SimpleClassNullableOfIntNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfIntNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfIntNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfIntNullableToJson(this); @@ -577,9 +499,7 @@ class SimpleClassNullableOfIntNullable { class SimpleClassOfNum { final Set<num> value; - SimpleClassOfNum( - this.value, - ); + SimpleClassOfNum(this.value); factory SimpleClassOfNum.fromJson(Map<String, Object?> json) => _$SimpleClassOfNumFromJson(json); @@ -591,9 +511,7 @@ class SimpleClassOfNum { class SimpleClassNullableOfNum { final Set<num>? value; - SimpleClassNullableOfNum( - this.value, - ); + SimpleClassNullableOfNum(this.value); factory SimpleClassNullableOfNum.fromJson(Map<String, Object?> json) => _$SimpleClassNullableOfNumFromJson(json); @@ -605,9 +523,7 @@ class SimpleClassNullableOfNum { class SimpleClassOfNumNullable { final Set<num?> value; - SimpleClassOfNumNullable( - this.value, - ); + SimpleClassOfNumNullable(this.value); factory SimpleClassOfNumNullable.fromJson(Map<String, Object?> json) => _$SimpleClassOfNumNullableFromJson(json); @@ -619,13 +535,11 @@ class SimpleClassOfNumNullable { class SimpleClassNullableOfNumNullable { final Set<num?>? value; - SimpleClassNullableOfNumNullable( - this.value, - ); + SimpleClassNullableOfNumNullable(this.value); factory SimpleClassNullableOfNumNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfNumNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfNumNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfNumNullableToJson(this); @@ -635,9 +549,7 @@ class SimpleClassNullableOfNumNullable { class SimpleClassOfObject { final Set<Object> value; - SimpleClassOfObject( - this.value, - ); + SimpleClassOfObject(this.value); factory SimpleClassOfObject.fromJson(Map<String, Object?> json) => _$SimpleClassOfObjectFromJson(json); @@ -649,9 +561,7 @@ class SimpleClassOfObject { class SimpleClassNullableOfObject { final Set<Object>? value; - SimpleClassNullableOfObject( - this.value, - ); + SimpleClassNullableOfObject(this.value); factory SimpleClassNullableOfObject.fromJson(Map<String, Object?> json) => _$SimpleClassNullableOfObjectFromJson(json); @@ -663,9 +573,7 @@ class SimpleClassNullableOfObject { class SimpleClassOfObjectNullable { final Set<Object?> value; - SimpleClassOfObjectNullable( - this.value, - ); + SimpleClassOfObjectNullable(this.value); factory SimpleClassOfObjectNullable.fromJson(Map<String, Object?> json) => _$SimpleClassOfObjectNullableFromJson(json); @@ -677,13 +585,11 @@ class SimpleClassOfObjectNullable { class SimpleClassNullableOfObjectNullable { final Set<Object?>? value; - SimpleClassNullableOfObjectNullable( - this.value, - ); + SimpleClassNullableOfObjectNullable(this.value); factory SimpleClassNullableOfObjectNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfObjectNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfObjectNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfObjectNullableToJson(this); @@ -693,9 +599,7 @@ class SimpleClassNullableOfObjectNullable { class SimpleClassOfRecord { final Set<(int, String, {bool truth})> value; - SimpleClassOfRecord( - this.value, - ); + SimpleClassOfRecord(this.value); factory SimpleClassOfRecord.fromJson(Map<String, Object?> json) => _$SimpleClassOfRecordFromJson(json); @@ -707,9 +611,7 @@ class SimpleClassOfRecord { class SimpleClassNullableOfRecord { final Set<(int, String, {bool truth})>? value; - SimpleClassNullableOfRecord( - this.value, - ); + SimpleClassNullableOfRecord(this.value); factory SimpleClassNullableOfRecord.fromJson(Map<String, Object?> json) => _$SimpleClassNullableOfRecordFromJson(json); @@ -721,9 +623,7 @@ class SimpleClassNullableOfRecord { class SimpleClassOfString { final Set<String> value; - SimpleClassOfString( - this.value, - ); + SimpleClassOfString(this.value); factory SimpleClassOfString.fromJson(Map<String, Object?> json) => _$SimpleClassOfStringFromJson(json); @@ -735,9 +635,7 @@ class SimpleClassOfString { class SimpleClassNullableOfString { final Set<String>? value; - SimpleClassNullableOfString( - this.value, - ); + SimpleClassNullableOfString(this.value); factory SimpleClassNullableOfString.fromJson(Map<String, Object?> json) => _$SimpleClassNullableOfStringFromJson(json); @@ -749,9 +647,7 @@ class SimpleClassNullableOfString { class SimpleClassOfStringNullable { final Set<String?> value; - SimpleClassOfStringNullable( - this.value, - ); + SimpleClassOfStringNullable(this.value); factory SimpleClassOfStringNullable.fromJson(Map<String, Object?> json) => _$SimpleClassOfStringNullableFromJson(json); @@ -763,13 +659,11 @@ class SimpleClassOfStringNullable { class SimpleClassNullableOfStringNullable { final Set<String?>? value; - SimpleClassNullableOfStringNullable( - this.value, - ); + SimpleClassNullableOfStringNullable(this.value); factory SimpleClassNullableOfStringNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfStringNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfStringNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfStringNullableToJson(this); @@ -779,9 +673,7 @@ class SimpleClassNullableOfStringNullable { class SimpleClassOfUri { final Set<Uri> value; - SimpleClassOfUri( - this.value, - ); + SimpleClassOfUri(this.value); factory SimpleClassOfUri.fromJson(Map<String, Object?> json) => _$SimpleClassOfUriFromJson(json); @@ -793,9 +685,7 @@ class SimpleClassOfUri { class SimpleClassNullableOfUri { final Set<Uri>? value; - SimpleClassNullableOfUri( - this.value, - ); + SimpleClassNullableOfUri(this.value); factory SimpleClassNullableOfUri.fromJson(Map<String, Object?> json) => _$SimpleClassNullableOfUriFromJson(json); @@ -807,9 +697,7 @@ class SimpleClassNullableOfUri { class SimpleClassOfUriNullable { final Set<Uri?> value; - SimpleClassOfUriNullable( - this.value, - ); + SimpleClassOfUriNullable(this.value); factory SimpleClassOfUriNullable.fromJson(Map<String, Object?> json) => _$SimpleClassOfUriNullableFromJson(json); @@ -821,13 +709,11 @@ class SimpleClassOfUriNullable { class SimpleClassNullableOfUriNullable { final Set<Uri?>? value; - SimpleClassNullableOfUriNullable( - this.value, - ); + SimpleClassNullableOfUriNullable(this.value); factory SimpleClassNullableOfUriNullable.fromJson( - Map<String, Object?> json) => - _$SimpleClassNullableOfUriNullableFromJson(json); + Map<String, Object?> json, + ) => _$SimpleClassNullableOfUriNullableFromJson(json); Map<String, Object?> toJson() => _$SimpleClassNullableOfUriNullableToJson(this); diff --git a/json_serializable/test/supported_types/input.type_set.g.dart b/json_serializable/test/supported_types/input.type_set.g.dart index 234afad93..f7100e175 100644 --- a/json_serializable/test/supported_types/input.type_set.g.dart +++ b/json_serializable/test/supported_types/input.type_set.g.dart @@ -9,10 +9,9 @@ part of 'input.type_set.dart'; // ************************************************************************** SimpleClass _$SimpleClassFromJson(Map<String, dynamic> json) => SimpleClass( - (json['value'] as List<dynamic>).toSet(), - (json['withDefault'] as List<dynamic>?)?.toSet() ?? - {42, true, false, null}, - ); + (json['value'] as List<dynamic>).toSet(), + (json['withDefault'] as List<dynamic>?)?.toSet() ?? {42, true, false, null}, +); Map<String, dynamic> _$SimpleClassToJson(SimpleClass instance) => <String, dynamic>{ @@ -28,11 +27,11 @@ SimpleClassNullable _$SimpleClassNullableFromJson(Map<String, dynamic> json) => ); Map<String, dynamic> _$SimpleClassNullableToJson( - SimpleClassNullable instance) => - <String, dynamic>{ - 'value': instance.value?.toList(), - 'withDefault': instance.withDefault?.toList(), - }; + SimpleClassNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.toList(), + 'withDefault': instance.withDefault?.toList(), +}; SimpleClassOfBigInt _$SimpleClassOfBigIntFromJson(Map<String, dynamic> json) => SimpleClassOfBigInt( @@ -42,52 +41,52 @@ SimpleClassOfBigInt _$SimpleClassOfBigIntFromJson(Map<String, dynamic> json) => ); Map<String, dynamic> _$SimpleClassOfBigIntToJson( - SimpleClassOfBigInt instance) => - <String, dynamic>{ - 'value': instance.value.map((e) => e.toString()).toList(), - }; + SimpleClassOfBigInt instance, +) => <String, dynamic>{ + 'value': instance.value.map((e) => e.toString()).toList(), +}; SimpleClassNullableOfBigInt _$SimpleClassNullableOfBigIntFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfBigInt( - (json['value'] as List<dynamic>?) - ?.map((e) => BigInt.parse(e as String)) - .toSet(), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfBigInt( + (json['value'] as List<dynamic>?) + ?.map((e) => BigInt.parse(e as String)) + .toSet(), +); Map<String, dynamic> _$SimpleClassNullableOfBigIntToJson( - SimpleClassNullableOfBigInt instance) => - <String, dynamic>{ - 'value': instance.value?.map((e) => e.toString()).toList(), - }; + SimpleClassNullableOfBigInt instance, +) => <String, dynamic>{ + 'value': instance.value?.map((e) => e.toString()).toList(), +}; SimpleClassOfBigIntNullable _$SimpleClassOfBigIntNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfBigIntNullable( - (json['value'] as List<dynamic>) - .map((e) => e == null ? null : BigInt.parse(e as String)) - .toSet(), - ); + Map<String, dynamic> json, +) => SimpleClassOfBigIntNullable( + (json['value'] as List<dynamic>) + .map((e) => e == null ? null : BigInt.parse(e as String)) + .toSet(), +); Map<String, dynamic> _$SimpleClassOfBigIntNullableToJson( - SimpleClassOfBigIntNullable instance) => - <String, dynamic>{ - 'value': instance.value.map((e) => e?.toString()).toList(), - }; + SimpleClassOfBigIntNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map((e) => e?.toString()).toList(), +}; SimpleClassNullableOfBigIntNullable - _$SimpleClassNullableOfBigIntNullableFromJson(Map<String, dynamic> json) => - SimpleClassNullableOfBigIntNullable( - (json['value'] as List<dynamic>?) - ?.map((e) => e == null ? null : BigInt.parse(e as String)) - .toSet(), - ); +_$SimpleClassNullableOfBigIntNullableFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfBigIntNullable( + (json['value'] as List<dynamic>?) + ?.map((e) => e == null ? null : BigInt.parse(e as String)) + .toSet(), + ); Map<String, dynamic> _$SimpleClassNullableOfBigIntNullableToJson( - SimpleClassNullableOfBigIntNullable instance) => - <String, dynamic>{ - 'value': instance.value?.map((e) => e?.toString()).toList(), - }; + SimpleClassNullableOfBigIntNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map((e) => e?.toString()).toList(), +}; SimpleClassOfBool _$SimpleClassOfBoolFromJson(Map<String, dynamic> json) => SimpleClassOfBool( @@ -95,102 +94,93 @@ SimpleClassOfBool _$SimpleClassOfBoolFromJson(Map<String, dynamic> json) => ); Map<String, dynamic> _$SimpleClassOfBoolToJson(SimpleClassOfBool instance) => - <String, dynamic>{ - 'value': instance.value.toList(), - }; + <String, dynamic>{'value': instance.value.toList()}; SimpleClassNullableOfBool _$SimpleClassNullableOfBoolFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfBool( - (json['value'] as List<dynamic>?)?.map((e) => e as bool).toSet(), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfBool( + (json['value'] as List<dynamic>?)?.map((e) => e as bool).toSet(), +); Map<String, dynamic> _$SimpleClassNullableOfBoolToJson( - SimpleClassNullableOfBool instance) => - <String, dynamic>{ - 'value': instance.value?.toList(), - }; + SimpleClassNullableOfBool instance, +) => <String, dynamic>{'value': instance.value?.toList()}; SimpleClassOfBoolNullable _$SimpleClassOfBoolNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfBoolNullable( - (json['value'] as List<dynamic>).map((e) => e as bool?).toSet(), - ); + Map<String, dynamic> json, +) => SimpleClassOfBoolNullable( + (json['value'] as List<dynamic>).map((e) => e as bool?).toSet(), +); Map<String, dynamic> _$SimpleClassOfBoolNullableToJson( - SimpleClassOfBoolNullable instance) => - <String, dynamic>{ - 'value': instance.value.toList(), - }; + SimpleClassOfBoolNullable instance, +) => <String, dynamic>{'value': instance.value.toList()}; SimpleClassNullableOfBoolNullable _$SimpleClassNullableOfBoolNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfBoolNullable( - (json['value'] as List<dynamic>?)?.map((e) => e as bool?).toSet(), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfBoolNullable( + (json['value'] as List<dynamic>?)?.map((e) => e as bool?).toSet(), +); Map<String, dynamic> _$SimpleClassNullableOfBoolNullableToJson( - SimpleClassNullableOfBoolNullable instance) => - <String, dynamic>{ - 'value': instance.value?.toList(), - }; + SimpleClassNullableOfBoolNullable instance, +) => <String, dynamic>{'value': instance.value?.toList()}; SimpleClassOfDateTime _$SimpleClassOfDateTimeFromJson( - Map<String, dynamic> json) => - SimpleClassOfDateTime( - (json['value'] as List<dynamic>) - .map((e) => DateTime.parse(e as String)) - .toSet(), - ); + Map<String, dynamic> json, +) => SimpleClassOfDateTime( + (json['value'] as List<dynamic>) + .map((e) => DateTime.parse(e as String)) + .toSet(), +); Map<String, dynamic> _$SimpleClassOfDateTimeToJson( - SimpleClassOfDateTime instance) => - <String, dynamic>{ - 'value': instance.value.map((e) => e.toIso8601String()).toList(), - }; + SimpleClassOfDateTime instance, +) => <String, dynamic>{ + 'value': instance.value.map((e) => e.toIso8601String()).toList(), +}; SimpleClassNullableOfDateTime _$SimpleClassNullableOfDateTimeFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDateTime( - (json['value'] as List<dynamic>?) - ?.map((e) => DateTime.parse(e as String)) - .toSet(), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfDateTime( + (json['value'] as List<dynamic>?) + ?.map((e) => DateTime.parse(e as String)) + .toSet(), +); Map<String, dynamic> _$SimpleClassNullableOfDateTimeToJson( - SimpleClassNullableOfDateTime instance) => - <String, dynamic>{ - 'value': instance.value?.map((e) => e.toIso8601String()).toList(), - }; + SimpleClassNullableOfDateTime instance, +) => <String, dynamic>{ + 'value': instance.value?.map((e) => e.toIso8601String()).toList(), +}; SimpleClassOfDateTimeNullable _$SimpleClassOfDateTimeNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfDateTimeNullable( - (json['value'] as List<dynamic>) - .map((e) => e == null ? null : DateTime.parse(e as String)) - .toSet(), - ); + Map<String, dynamic> json, +) => SimpleClassOfDateTimeNullable( + (json['value'] as List<dynamic>) + .map((e) => e == null ? null : DateTime.parse(e as String)) + .toSet(), +); Map<String, dynamic> _$SimpleClassOfDateTimeNullableToJson( - SimpleClassOfDateTimeNullable instance) => - <String, dynamic>{ - 'value': instance.value.map((e) => e?.toIso8601String()).toList(), - }; + SimpleClassOfDateTimeNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map((e) => e?.toIso8601String()).toList(), +}; SimpleClassNullableOfDateTimeNullable - _$SimpleClassNullableOfDateTimeNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDateTimeNullable( - (json['value'] as List<dynamic>?) - ?.map((e) => e == null ? null : DateTime.parse(e as String)) - .toSet(), - ); +_$SimpleClassNullableOfDateTimeNullableFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfDateTimeNullable( + (json['value'] as List<dynamic>?) + ?.map((e) => e == null ? null : DateTime.parse(e as String)) + .toSet(), + ); Map<String, dynamic> _$SimpleClassNullableOfDateTimeNullableToJson( - SimpleClassNullableOfDateTimeNullable instance) => - <String, dynamic>{ - 'value': instance.value?.map((e) => e?.toIso8601String()).toList(), - }; + SimpleClassNullableOfDateTimeNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map((e) => e?.toIso8601String()).toList(), +}; SimpleClassOfDouble _$SimpleClassOfDoubleFromJson(Map<String, dynamic> json) => SimpleClassOfDouble( @@ -200,149 +190,129 @@ SimpleClassOfDouble _$SimpleClassOfDoubleFromJson(Map<String, dynamic> json) => ); Map<String, dynamic> _$SimpleClassOfDoubleToJson( - SimpleClassOfDouble instance) => - <String, dynamic>{ - 'value': instance.value.toList(), - }; + SimpleClassOfDouble instance, +) => <String, dynamic>{'value': instance.value.toList()}; SimpleClassNullableOfDouble _$SimpleClassNullableOfDoubleFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDouble( - (json['value'] as List<dynamic>?) - ?.map((e) => (e as num).toDouble()) - .toSet(), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfDouble( + (json['value'] as List<dynamic>?)?.map((e) => (e as num).toDouble()).toSet(), +); Map<String, dynamic> _$SimpleClassNullableOfDoubleToJson( - SimpleClassNullableOfDouble instance) => - <String, dynamic>{ - 'value': instance.value?.toList(), - }; + SimpleClassNullableOfDouble instance, +) => <String, dynamic>{'value': instance.value?.toList()}; SimpleClassOfDoubleNullable _$SimpleClassOfDoubleNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfDoubleNullable( - (json['value'] as List<dynamic>) - .map((e) => (e as num?)?.toDouble()) - .toSet(), - ); + Map<String, dynamic> json, +) => SimpleClassOfDoubleNullable( + (json['value'] as List<dynamic>).map((e) => (e as num?)?.toDouble()).toSet(), +); Map<String, dynamic> _$SimpleClassOfDoubleNullableToJson( - SimpleClassOfDoubleNullable instance) => - <String, dynamic>{ - 'value': instance.value.toList(), - }; + SimpleClassOfDoubleNullable instance, +) => <String, dynamic>{'value': instance.value.toList()}; SimpleClassNullableOfDoubleNullable - _$SimpleClassNullableOfDoubleNullableFromJson(Map<String, dynamic> json) => - SimpleClassNullableOfDoubleNullable( - (json['value'] as List<dynamic>?) - ?.map((e) => (e as num?)?.toDouble()) - .toSet(), - ); +_$SimpleClassNullableOfDoubleNullableFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfDoubleNullable( + (json['value'] as List<dynamic>?) + ?.map((e) => (e as num?)?.toDouble()) + .toSet(), + ); Map<String, dynamic> _$SimpleClassNullableOfDoubleNullableToJson( - SimpleClassNullableOfDoubleNullable instance) => - <String, dynamic>{ - 'value': instance.value?.toList(), - }; + SimpleClassNullableOfDoubleNullable instance, +) => <String, dynamic>{'value': instance.value?.toList()}; SimpleClassOfDuration _$SimpleClassOfDurationFromJson( - Map<String, dynamic> json) => - SimpleClassOfDuration( - (json['value'] as List<dynamic>) - .map((e) => Duration(microseconds: (e as num).toInt())) - .toSet(), - ); + Map<String, dynamic> json, +) => SimpleClassOfDuration( + (json['value'] as List<dynamic>) + .map((e) => Duration(microseconds: (e as num).toInt())) + .toSet(), +); Map<String, dynamic> _$SimpleClassOfDurationToJson( - SimpleClassOfDuration instance) => - <String, dynamic>{ - 'value': instance.value.map((e) => e.inMicroseconds).toList(), - }; + SimpleClassOfDuration instance, +) => <String, dynamic>{ + 'value': instance.value.map((e) => e.inMicroseconds).toList(), +}; SimpleClassNullableOfDuration _$SimpleClassNullableOfDurationFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDuration( - (json['value'] as List<dynamic>?) - ?.map((e) => Duration(microseconds: (e as num).toInt())) - .toSet(), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfDuration( + (json['value'] as List<dynamic>?) + ?.map((e) => Duration(microseconds: (e as num).toInt())) + .toSet(), +); Map<String, dynamic> _$SimpleClassNullableOfDurationToJson( - SimpleClassNullableOfDuration instance) => - <String, dynamic>{ - 'value': instance.value?.map((e) => e.inMicroseconds).toList(), - }; + SimpleClassNullableOfDuration instance, +) => <String, dynamic>{ + 'value': instance.value?.map((e) => e.inMicroseconds).toList(), +}; SimpleClassOfDurationNullable _$SimpleClassOfDurationNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfDurationNullable( - (json['value'] as List<dynamic>) - .map((e) => - e == null ? null : Duration(microseconds: (e as num).toInt())) - .toSet(), - ); + Map<String, dynamic> json, +) => SimpleClassOfDurationNullable( + (json['value'] as List<dynamic>) + .map((e) => e == null ? null : Duration(microseconds: (e as num).toInt())) + .toSet(), +); Map<String, dynamic> _$SimpleClassOfDurationNullableToJson( - SimpleClassOfDurationNullable instance) => - <String, dynamic>{ - 'value': instance.value.map((e) => e?.inMicroseconds).toList(), - }; + SimpleClassOfDurationNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map((e) => e?.inMicroseconds).toList(), +}; SimpleClassNullableOfDurationNullable - _$SimpleClassNullableOfDurationNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDurationNullable( - (json['value'] as List<dynamic>?) - ?.map((e) => - e == null ? null : Duration(microseconds: (e as num).toInt())) - .toSet(), - ); +_$SimpleClassNullableOfDurationNullableFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfDurationNullable( + (json['value'] as List<dynamic>?) + ?.map( + (e) => + e == null ? null : Duration(microseconds: (e as num).toInt()), + ) + .toSet(), + ); Map<String, dynamic> _$SimpleClassNullableOfDurationNullableToJson( - SimpleClassNullableOfDurationNullable instance) => - <String, dynamic>{ - 'value': instance.value?.map((e) => e?.inMicroseconds).toList(), - }; + SimpleClassNullableOfDurationNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map((e) => e?.inMicroseconds).toList(), +}; SimpleClassOfDynamic _$SimpleClassOfDynamicFromJson( - Map<String, dynamic> json) => - SimpleClassOfDynamic( - (json['value'] as List<dynamic>).toSet(), - ); + Map<String, dynamic> json, +) => SimpleClassOfDynamic((json['value'] as List<dynamic>).toSet()); Map<String, dynamic> _$SimpleClassOfDynamicToJson( - SimpleClassOfDynamic instance) => - <String, dynamic>{ - 'value': instance.value.toList(), - }; + SimpleClassOfDynamic instance, +) => <String, dynamic>{'value': instance.value.toList()}; SimpleClassNullableOfDynamic _$SimpleClassNullableOfDynamicFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfDynamic( - (json['value'] as List<dynamic>?)?.toSet(), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfDynamic((json['value'] as List<dynamic>?)?.toSet()); Map<String, dynamic> _$SimpleClassNullableOfDynamicToJson( - SimpleClassNullableOfDynamic instance) => - <String, dynamic>{ - 'value': instance.value?.toList(), - }; + SimpleClassNullableOfDynamic instance, +) => <String, dynamic>{'value': instance.value?.toList()}; SimpleClassOfEnumType _$SimpleClassOfEnumTypeFromJson( - Map<String, dynamic> json) => - SimpleClassOfEnumType( - (json['value'] as List<dynamic>) - .map((e) => $enumDecode(_$EnumTypeEnumMap, e)) - .toSet(), - ); + Map<String, dynamic> json, +) => SimpleClassOfEnumType( + (json['value'] as List<dynamic>) + .map((e) => $enumDecode(_$EnumTypeEnumMap, e)) + .toSet(), +); Map<String, dynamic> _$SimpleClassOfEnumTypeToJson( - SimpleClassOfEnumType instance) => - <String, dynamic>{ - 'value': instance.value.map((e) => _$EnumTypeEnumMap[e]!).toList(), - }; + SimpleClassOfEnumType instance, +) => <String, dynamic>{ + 'value': instance.value.map((e) => _$EnumTypeEnumMap[e]!).toList(), +}; const _$EnumTypeEnumMap = { EnumType.alpha: 'alpha', @@ -352,135 +322,116 @@ const _$EnumTypeEnumMap = { }; SimpleClassNullableOfEnumType _$SimpleClassNullableOfEnumTypeFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfEnumType( - (json['value'] as List<dynamic>?) - ?.map((e) => $enumDecode(_$EnumTypeEnumMap, e)) - .toSet(), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfEnumType( + (json['value'] as List<dynamic>?) + ?.map((e) => $enumDecode(_$EnumTypeEnumMap, e)) + .toSet(), +); Map<String, dynamic> _$SimpleClassNullableOfEnumTypeToJson( - SimpleClassNullableOfEnumType instance) => - <String, dynamic>{ - 'value': instance.value?.map((e) => _$EnumTypeEnumMap[e]!).toList(), - }; + SimpleClassNullableOfEnumType instance, +) => <String, dynamic>{ + 'value': instance.value?.map((e) => _$EnumTypeEnumMap[e]!).toList(), +}; SimpleClassOfEnumTypeNullable _$SimpleClassOfEnumTypeNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfEnumTypeNullable( - (json['value'] as List<dynamic>) - .map((e) => $enumDecodeNullable(_$EnumTypeEnumMap, e)) - .toSet(), - ); + Map<String, dynamic> json, +) => SimpleClassOfEnumTypeNullable( + (json['value'] as List<dynamic>) + .map((e) => $enumDecodeNullable(_$EnumTypeEnumMap, e)) + .toSet(), +); Map<String, dynamic> _$SimpleClassOfEnumTypeNullableToJson( - SimpleClassOfEnumTypeNullable instance) => - <String, dynamic>{ - 'value': instance.value.map((e) => _$EnumTypeEnumMap[e]).toList(), - }; + SimpleClassOfEnumTypeNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map((e) => _$EnumTypeEnumMap[e]).toList(), +}; SimpleClassNullableOfEnumTypeNullable - _$SimpleClassNullableOfEnumTypeNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfEnumTypeNullable( - (json['value'] as List<dynamic>?) - ?.map((e) => $enumDecodeNullable(_$EnumTypeEnumMap, e)) - .toSet(), - ); +_$SimpleClassNullableOfEnumTypeNullableFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfEnumTypeNullable( + (json['value'] as List<dynamic>?) + ?.map((e) => $enumDecodeNullable(_$EnumTypeEnumMap, e)) + .toSet(), + ); Map<String, dynamic> _$SimpleClassNullableOfEnumTypeNullableToJson( - SimpleClassNullableOfEnumTypeNullable instance) => - <String, dynamic>{ - 'value': instance.value?.map((e) => _$EnumTypeEnumMap[e]).toList(), - }; + SimpleClassNullableOfEnumTypeNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map((e) => _$EnumTypeEnumMap[e]).toList(), +}; SimpleClassOfFromJsonDynamicParam _$SimpleClassOfFromJsonDynamicParamFromJson( - Map<String, dynamic> json) => - SimpleClassOfFromJsonDynamicParam( - (json['value'] as List<dynamic>) - .map(FromJsonDynamicParam.fromJson) - .toSet(), - ); + Map<String, dynamic> json, +) => SimpleClassOfFromJsonDynamicParam( + (json['value'] as List<dynamic>).map(FromJsonDynamicParam.fromJson).toSet(), +); Map<String, dynamic> _$SimpleClassOfFromJsonDynamicParamToJson( - SimpleClassOfFromJsonDynamicParam instance) => - <String, dynamic>{ - 'value': instance.value.toList(), - }; + SimpleClassOfFromJsonDynamicParam instance, +) => <String, dynamic>{'value': instance.value.toList()}; SimpleClassNullableOfFromJsonDynamicParam - _$SimpleClassNullableOfFromJsonDynamicParamFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfFromJsonDynamicParam( - (json['value'] as List<dynamic>?) - ?.map(FromJsonDynamicParam.fromJson) - .toSet(), - ); +_$SimpleClassNullableOfFromJsonDynamicParamFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfFromJsonDynamicParam( + (json['value'] as List<dynamic>?)?.map(FromJsonDynamicParam.fromJson).toSet(), +); Map<String, dynamic> _$SimpleClassNullableOfFromJsonDynamicParamToJson( - SimpleClassNullableOfFromJsonDynamicParam instance) => - <String, dynamic>{ - 'value': instance.value?.toList(), - }; + SimpleClassNullableOfFromJsonDynamicParam instance, +) => <String, dynamic>{'value': instance.value?.toList()}; SimpleClassOfFromJsonNullableObjectParam - _$SimpleClassOfFromJsonNullableObjectParamFromJson( - Map<String, dynamic> json) => - SimpleClassOfFromJsonNullableObjectParam( - (json['value'] as List<dynamic>) - .map(FromJsonNullableObjectParam.fromJson) - .toSet(), - ); +_$SimpleClassOfFromJsonNullableObjectParamFromJson(Map<String, dynamic> json) => + SimpleClassOfFromJsonNullableObjectParam( + (json['value'] as List<dynamic>) + .map(FromJsonNullableObjectParam.fromJson) + .toSet(), + ); Map<String, dynamic> _$SimpleClassOfFromJsonNullableObjectParamToJson( - SimpleClassOfFromJsonNullableObjectParam instance) => - <String, dynamic>{ - 'value': instance.value.toList(), - }; + SimpleClassOfFromJsonNullableObjectParam instance, +) => <String, dynamic>{'value': instance.value.toList()}; SimpleClassNullableOfFromJsonNullableObjectParam - _$SimpleClassNullableOfFromJsonNullableObjectParamFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfFromJsonNullableObjectParam( - (json['value'] as List<dynamic>?) - ?.map(FromJsonNullableObjectParam.fromJson) - .toSet(), - ); +_$SimpleClassNullableOfFromJsonNullableObjectParamFromJson( + Map<String, dynamic> json, +) => SimpleClassNullableOfFromJsonNullableObjectParam( + (json['value'] as List<dynamic>?) + ?.map(FromJsonNullableObjectParam.fromJson) + .toSet(), +); Map<String, dynamic> _$SimpleClassNullableOfFromJsonNullableObjectParamToJson( - SimpleClassNullableOfFromJsonNullableObjectParam instance) => - <String, dynamic>{ - 'value': instance.value?.toList(), - }; + SimpleClassNullableOfFromJsonNullableObjectParam instance, +) => <String, dynamic>{'value': instance.value?.toList()}; SimpleClassOfFromJsonObjectParam _$SimpleClassOfFromJsonObjectParamFromJson( - Map<String, dynamic> json) => - SimpleClassOfFromJsonObjectParam( - (json['value'] as List<dynamic>) - .map((e) => FromJsonObjectParam.fromJson(e as Object)) - .toSet(), - ); + Map<String, dynamic> json, +) => SimpleClassOfFromJsonObjectParam( + (json['value'] as List<dynamic>) + .map((e) => FromJsonObjectParam.fromJson(e as Object)) + .toSet(), +); Map<String, dynamic> _$SimpleClassOfFromJsonObjectParamToJson( - SimpleClassOfFromJsonObjectParam instance) => - <String, dynamic>{ - 'value': instance.value.toList(), - }; + SimpleClassOfFromJsonObjectParam instance, +) => <String, dynamic>{'value': instance.value.toList()}; SimpleClassNullableOfFromJsonObjectParam - _$SimpleClassNullableOfFromJsonObjectParamFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfFromJsonObjectParam( - (json['value'] as List<dynamic>?) - ?.map((e) => FromJsonObjectParam.fromJson(e as Object)) - .toSet(), - ); +_$SimpleClassNullableOfFromJsonObjectParamFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfFromJsonObjectParam( + (json['value'] as List<dynamic>?) + ?.map((e) => FromJsonObjectParam.fromJson(e as Object)) + .toSet(), + ); Map<String, dynamic> _$SimpleClassNullableOfFromJsonObjectParamToJson( - SimpleClassNullableOfFromJsonObjectParam instance) => - <String, dynamic>{ - 'value': instance.value?.toList(), - }; + SimpleClassNullableOfFromJsonObjectParam instance, +) => <String, dynamic>{'value': instance.value?.toList()}; SimpleClassOfInt _$SimpleClassOfIntFromJson(Map<String, dynamic> json) => SimpleClassOfInt( @@ -488,47 +439,37 @@ SimpleClassOfInt _$SimpleClassOfIntFromJson(Map<String, dynamic> json) => ); Map<String, dynamic> _$SimpleClassOfIntToJson(SimpleClassOfInt instance) => - <String, dynamic>{ - 'value': instance.value.toList(), - }; + <String, dynamic>{'value': instance.value.toList()}; SimpleClassNullableOfInt _$SimpleClassNullableOfIntFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfInt( - (json['value'] as List<dynamic>?)?.map((e) => (e as num).toInt()).toSet(), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfInt( + (json['value'] as List<dynamic>?)?.map((e) => (e as num).toInt()).toSet(), +); Map<String, dynamic> _$SimpleClassNullableOfIntToJson( - SimpleClassNullableOfInt instance) => - <String, dynamic>{ - 'value': instance.value?.toList(), - }; + SimpleClassNullableOfInt instance, +) => <String, dynamic>{'value': instance.value?.toList()}; SimpleClassOfIntNullable _$SimpleClassOfIntNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfIntNullable( - (json['value'] as List<dynamic>).map((e) => (e as num?)?.toInt()).toSet(), - ); + Map<String, dynamic> json, +) => SimpleClassOfIntNullable( + (json['value'] as List<dynamic>).map((e) => (e as num?)?.toInt()).toSet(), +); Map<String, dynamic> _$SimpleClassOfIntNullableToJson( - SimpleClassOfIntNullable instance) => - <String, dynamic>{ - 'value': instance.value.toList(), - }; + SimpleClassOfIntNullable instance, +) => <String, dynamic>{'value': instance.value.toList()}; SimpleClassNullableOfIntNullable _$SimpleClassNullableOfIntNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfIntNullable( - (json['value'] as List<dynamic>?) - ?.map((e) => (e as num?)?.toInt()) - .toSet(), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfIntNullable( + (json['value'] as List<dynamic>?)?.map((e) => (e as num?)?.toInt()).toSet(), +); Map<String, dynamic> _$SimpleClassNullableOfIntNullableToJson( - SimpleClassNullableOfIntNullable instance) => - <String, dynamic>{ - 'value': instance.value?.toList(), - }; + SimpleClassNullableOfIntNullable instance, +) => <String, dynamic>{'value': instance.value?.toList()}; SimpleClassOfNum _$SimpleClassOfNumFromJson(Map<String, dynamic> json) => SimpleClassOfNum( @@ -536,45 +477,37 @@ SimpleClassOfNum _$SimpleClassOfNumFromJson(Map<String, dynamic> json) => ); Map<String, dynamic> _$SimpleClassOfNumToJson(SimpleClassOfNum instance) => - <String, dynamic>{ - 'value': instance.value.toList(), - }; + <String, dynamic>{'value': instance.value.toList()}; SimpleClassNullableOfNum _$SimpleClassNullableOfNumFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfNum( - (json['value'] as List<dynamic>?)?.map((e) => e as num).toSet(), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfNum( + (json['value'] as List<dynamic>?)?.map((e) => e as num).toSet(), +); Map<String, dynamic> _$SimpleClassNullableOfNumToJson( - SimpleClassNullableOfNum instance) => - <String, dynamic>{ - 'value': instance.value?.toList(), - }; + SimpleClassNullableOfNum instance, +) => <String, dynamic>{'value': instance.value?.toList()}; SimpleClassOfNumNullable _$SimpleClassOfNumNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfNumNullable( - (json['value'] as List<dynamic>).map((e) => e as num?).toSet(), - ); + Map<String, dynamic> json, +) => SimpleClassOfNumNullable( + (json['value'] as List<dynamic>).map((e) => e as num?).toSet(), +); Map<String, dynamic> _$SimpleClassOfNumNullableToJson( - SimpleClassOfNumNullable instance) => - <String, dynamic>{ - 'value': instance.value.toList(), - }; + SimpleClassOfNumNullable instance, +) => <String, dynamic>{'value': instance.value.toList()}; SimpleClassNullableOfNumNullable _$SimpleClassNullableOfNumNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfNumNullable( - (json['value'] as List<dynamic>?)?.map((e) => e as num?).toSet(), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfNumNullable( + (json['value'] as List<dynamic>?)?.map((e) => e as num?).toSet(), +); Map<String, dynamic> _$SimpleClassNullableOfNumNullableToJson( - SimpleClassNullableOfNumNullable instance) => - <String, dynamic>{ - 'value': instance.value?.toList(), - }; + SimpleClassNullableOfNumNullable instance, +) => <String, dynamic>{'value': instance.value?.toList()}; SimpleClassOfObject _$SimpleClassOfObjectFromJson(Map<String, dynamic> json) => SimpleClassOfObject( @@ -582,105 +515,90 @@ SimpleClassOfObject _$SimpleClassOfObjectFromJson(Map<String, dynamic> json) => ); Map<String, dynamic> _$SimpleClassOfObjectToJson( - SimpleClassOfObject instance) => - <String, dynamic>{ - 'value': instance.value.toList(), - }; + SimpleClassOfObject instance, +) => <String, dynamic>{'value': instance.value.toList()}; SimpleClassNullableOfObject _$SimpleClassNullableOfObjectFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfObject( - (json['value'] as List<dynamic>?)?.map((e) => e as Object).toSet(), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfObject( + (json['value'] as List<dynamic>?)?.map((e) => e as Object).toSet(), +); Map<String, dynamic> _$SimpleClassNullableOfObjectToJson( - SimpleClassNullableOfObject instance) => - <String, dynamic>{ - 'value': instance.value?.toList(), - }; + SimpleClassNullableOfObject instance, +) => <String, dynamic>{'value': instance.value?.toList()}; SimpleClassOfObjectNullable _$SimpleClassOfObjectNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfObjectNullable( - (json['value'] as List<dynamic>).toSet(), - ); + Map<String, dynamic> json, +) => SimpleClassOfObjectNullable((json['value'] as List<dynamic>).toSet()); Map<String, dynamic> _$SimpleClassOfObjectNullableToJson( - SimpleClassOfObjectNullable instance) => - <String, dynamic>{ - 'value': instance.value.toList(), - }; + SimpleClassOfObjectNullable instance, +) => <String, dynamic>{'value': instance.value.toList()}; SimpleClassNullableOfObjectNullable - _$SimpleClassNullableOfObjectNullableFromJson(Map<String, dynamic> json) => - SimpleClassNullableOfObjectNullable( - (json['value'] as List<dynamic>?)?.toSet(), - ); +_$SimpleClassNullableOfObjectNullableFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfObjectNullable( + (json['value'] as List<dynamic>?)?.toSet(), + ); Map<String, dynamic> _$SimpleClassNullableOfObjectNullableToJson( - SimpleClassNullableOfObjectNullable instance) => - <String, dynamic>{ - 'value': instance.value?.toList(), - }; + SimpleClassNullableOfObjectNullable instance, +) => <String, dynamic>{'value': instance.value?.toList()}; SimpleClassOfRecord _$SimpleClassOfRecordFromJson(Map<String, dynamic> json) => SimpleClassOfRecord( (json['value'] as List<dynamic>) - .map((e) => _$recordConvert( - e, - ($jsonValue) => ( - ($jsonValue[r'$1'] as num).toInt(), - $jsonValue[r'$2'] as String, - truth: $jsonValue['truth'] as bool, - ), - )) + .map( + (e) => _$recordConvert( + e, + ($jsonValue) => ( + ($jsonValue[r'$1'] as num).toInt(), + $jsonValue[r'$2'] as String, + truth: $jsonValue['truth'] as bool, + ), + ), + ) .toSet(), ); Map<String, dynamic> _$SimpleClassOfRecordToJson( - SimpleClassOfRecord instance) => - <String, dynamic>{ - 'value': instance.value - .map((e) => <String, dynamic>{ - r'$1': e.$1, - r'$2': e.$2, - 'truth': e.truth, - }) - .toList(), - }; + SimpleClassOfRecord instance, +) => <String, dynamic>{ + 'value': instance.value + .map((e) => <String, dynamic>{r'$1': e.$1, r'$2': e.$2, 'truth': e.truth}) + .toList(), +}; -$Rec _$recordConvert<$Rec>( - Object? value, - $Rec Function(Map) convert, -) => +$Rec _$recordConvert<$Rec>(Object? value, $Rec Function(Map) convert) => convert(value as Map<String, dynamic>); SimpleClassNullableOfRecord _$SimpleClassNullableOfRecordFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfRecord( - (json['value'] as List<dynamic>?) - ?.map((e) => _$recordConvert( - e, - ($jsonValue) => ( - ($jsonValue[r'$1'] as num).toInt(), - $jsonValue[r'$2'] as String, - truth: $jsonValue['truth'] as bool, - ), - )) - .toSet(), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfRecord( + (json['value'] as List<dynamic>?) + ?.map( + (e) => _$recordConvert( + e, + ($jsonValue) => ( + ($jsonValue[r'$1'] as num).toInt(), + $jsonValue[r'$2'] as String, + truth: $jsonValue['truth'] as bool, + ), + ), + ) + .toSet(), +); Map<String, dynamic> _$SimpleClassNullableOfRecordToJson( - SimpleClassNullableOfRecord instance) => - <String, dynamic>{ - 'value': instance.value - ?.map((e) => <String, dynamic>{ - r'$1': e.$1, - r'$2': e.$2, - 'truth': e.truth, - }) - .toList(), - }; + SimpleClassNullableOfRecord instance, +) => <String, dynamic>{ + 'value': instance.value + ?.map( + (e) => <String, dynamic>{r'$1': e.$1, r'$2': e.$2, 'truth': e.truth}, + ) + .toList(), +}; SimpleClassOfString _$SimpleClassOfStringFromJson(Map<String, dynamic> json) => SimpleClassOfString( @@ -688,46 +606,38 @@ SimpleClassOfString _$SimpleClassOfStringFromJson(Map<String, dynamic> json) => ); Map<String, dynamic> _$SimpleClassOfStringToJson( - SimpleClassOfString instance) => - <String, dynamic>{ - 'value': instance.value.toList(), - }; + SimpleClassOfString instance, +) => <String, dynamic>{'value': instance.value.toList()}; SimpleClassNullableOfString _$SimpleClassNullableOfStringFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfString( - (json['value'] as List<dynamic>?)?.map((e) => e as String).toSet(), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfString( + (json['value'] as List<dynamic>?)?.map((e) => e as String).toSet(), +); Map<String, dynamic> _$SimpleClassNullableOfStringToJson( - SimpleClassNullableOfString instance) => - <String, dynamic>{ - 'value': instance.value?.toList(), - }; + SimpleClassNullableOfString instance, +) => <String, dynamic>{'value': instance.value?.toList()}; SimpleClassOfStringNullable _$SimpleClassOfStringNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfStringNullable( - (json['value'] as List<dynamic>).map((e) => e as String?).toSet(), - ); + Map<String, dynamic> json, +) => SimpleClassOfStringNullable( + (json['value'] as List<dynamic>).map((e) => e as String?).toSet(), +); Map<String, dynamic> _$SimpleClassOfStringNullableToJson( - SimpleClassOfStringNullable instance) => - <String, dynamic>{ - 'value': instance.value.toList(), - }; + SimpleClassOfStringNullable instance, +) => <String, dynamic>{'value': instance.value.toList()}; SimpleClassNullableOfStringNullable - _$SimpleClassNullableOfStringNullableFromJson(Map<String, dynamic> json) => - SimpleClassNullableOfStringNullable( - (json['value'] as List<dynamic>?)?.map((e) => e as String?).toSet(), - ); +_$SimpleClassNullableOfStringNullableFromJson(Map<String, dynamic> json) => + SimpleClassNullableOfStringNullable( + (json['value'] as List<dynamic>?)?.map((e) => e as String?).toSet(), + ); Map<String, dynamic> _$SimpleClassNullableOfStringNullableToJson( - SimpleClassNullableOfStringNullable instance) => - <String, dynamic>{ - 'value': instance.value?.toList(), - }; + SimpleClassNullableOfStringNullable instance, +) => <String, dynamic>{'value': instance.value?.toList()}; SimpleClassOfUri _$SimpleClassOfUriFromJson(Map<String, dynamic> json) => SimpleClassOfUri( @@ -742,43 +652,41 @@ Map<String, dynamic> _$SimpleClassOfUriToJson(SimpleClassOfUri instance) => }; SimpleClassNullableOfUri _$SimpleClassNullableOfUriFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfUri( - (json['value'] as List<dynamic>?) - ?.map((e) => Uri.parse(e as String)) - .toSet(), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfUri( + (json['value'] as List<dynamic>?)?.map((e) => Uri.parse(e as String)).toSet(), +); Map<String, dynamic> _$SimpleClassNullableOfUriToJson( - SimpleClassNullableOfUri instance) => - <String, dynamic>{ - 'value': instance.value?.map((e) => e.toString()).toList(), - }; + SimpleClassNullableOfUri instance, +) => <String, dynamic>{ + 'value': instance.value?.map((e) => e.toString()).toList(), +}; SimpleClassOfUriNullable _$SimpleClassOfUriNullableFromJson( - Map<String, dynamic> json) => - SimpleClassOfUriNullable( - (json['value'] as List<dynamic>) - .map((e) => e == null ? null : Uri.parse(e as String)) - .toSet(), - ); + Map<String, dynamic> json, +) => SimpleClassOfUriNullable( + (json['value'] as List<dynamic>) + .map((e) => e == null ? null : Uri.parse(e as String)) + .toSet(), +); Map<String, dynamic> _$SimpleClassOfUriNullableToJson( - SimpleClassOfUriNullable instance) => - <String, dynamic>{ - 'value': instance.value.map((e) => e?.toString()).toList(), - }; + SimpleClassOfUriNullable instance, +) => <String, dynamic>{ + 'value': instance.value.map((e) => e?.toString()).toList(), +}; SimpleClassNullableOfUriNullable _$SimpleClassNullableOfUriNullableFromJson( - Map<String, dynamic> json) => - SimpleClassNullableOfUriNullable( - (json['value'] as List<dynamic>?) - ?.map((e) => e == null ? null : Uri.parse(e as String)) - .toSet(), - ); + Map<String, dynamic> json, +) => SimpleClassNullableOfUriNullable( + (json['value'] as List<dynamic>?) + ?.map((e) => e == null ? null : Uri.parse(e as String)) + .toSet(), +); Map<String, dynamic> _$SimpleClassNullableOfUriNullableToJson( - SimpleClassNullableOfUriNullable instance) => - <String, dynamic>{ - 'value': instance.value?.map((e) => e?.toString()).toList(), - }; + SimpleClassNullableOfUriNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.map((e) => e?.toString()).toList(), +}; diff --git a/json_serializable/test/supported_types/input.type_string.dart b/json_serializable/test/supported_types/input.type_string.dart index d199b13c0..4931a3af1 100644 --- a/json_serializable/test/supported_types/input.type_string.dart +++ b/json_serializable/test/supported_types/input.type_string.dart @@ -13,10 +13,7 @@ class SimpleClass { @JsonKey(defaultValue: 'a string') String withDefault; - SimpleClass( - this.value, - this.withDefault, - ); + SimpleClass(this.value, this.withDefault); factory SimpleClass.fromJson(Map<String, Object?> json) => _$SimpleClassFromJson(json); @@ -31,10 +28,7 @@ class SimpleClassNullable { @JsonKey(defaultValue: 'a string') String? withDefault; - SimpleClassNullable( - this.value, - this.withDefault, - ); + SimpleClassNullable(this.value, this.withDefault); factory SimpleClassNullable.fromJson(Map<String, Object?> json) => _$SimpleClassNullableFromJson(json); diff --git a/json_serializable/test/supported_types/input.type_string.g.dart b/json_serializable/test/supported_types/input.type_string.g.dart index 6db4a402d..7e69d3b37 100644 --- a/json_serializable/test/supported_types/input.type_string.g.dart +++ b/json_serializable/test/supported_types/input.type_string.g.dart @@ -9,9 +9,9 @@ part of 'input.type_string.dart'; // ************************************************************************** SimpleClass _$SimpleClassFromJson(Map<String, dynamic> json) => SimpleClass( - json['value'] as String, - json['withDefault'] as String? ?? 'a string', - ); + json['value'] as String, + json['withDefault'] as String? ?? 'a string', +); Map<String, dynamic> _$SimpleClassToJson(SimpleClass instance) => <String, dynamic>{ @@ -26,8 +26,8 @@ SimpleClassNullable _$SimpleClassNullableFromJson(Map<String, dynamic> json) => ); Map<String, dynamic> _$SimpleClassNullableToJson( - SimpleClassNullable instance) => - <String, dynamic>{ - 'value': instance.value, - 'withDefault': instance.withDefault, - }; + SimpleClassNullable instance, +) => <String, dynamic>{ + 'value': instance.value, + 'withDefault': instance.withDefault, +}; diff --git a/json_serializable/test/supported_types/input.type_uri.dart b/json_serializable/test/supported_types/input.type_uri.dart index 1be4d40f9..86e13bbc1 100644 --- a/json_serializable/test/supported_types/input.type_uri.dart +++ b/json_serializable/test/supported_types/input.type_uri.dart @@ -13,10 +13,7 @@ class SimpleClass { @JsonKey(defaultValue: _defaultValueFunc) Uri withDefault; - SimpleClass( - this.value, - this.withDefault, - ); + SimpleClass(this.value, this.withDefault); factory SimpleClass.fromJson(Map<String, Object?> json) => _$SimpleClassFromJson(json); @@ -31,10 +28,7 @@ class SimpleClassNullable { @JsonKey(defaultValue: _defaultValueFunc) Uri? withDefault; - SimpleClassNullable( - this.value, - this.withDefault, - ); + SimpleClassNullable(this.value, this.withDefault); factory SimpleClassNullable.fromJson(Map<String, Object?> json) => _$SimpleClassNullableFromJson(json); diff --git a/json_serializable/test/supported_types/input.type_uri.g.dart b/json_serializable/test/supported_types/input.type_uri.g.dart index b13890e87..33b5951d8 100644 --- a/json_serializable/test/supported_types/input.type_uri.g.dart +++ b/json_serializable/test/supported_types/input.type_uri.g.dart @@ -9,11 +9,11 @@ part of 'input.type_uri.dart'; // ************************************************************************** SimpleClass _$SimpleClassFromJson(Map<String, dynamic> json) => SimpleClass( - Uri.parse(json['value'] as String), - json['withDefault'] == null - ? _defaultValueFunc() - : Uri.parse(json['withDefault'] as String), - ); + Uri.parse(json['value'] as String), + json['withDefault'] == null + ? _defaultValueFunc() + : Uri.parse(json['withDefault'] as String), +); Map<String, dynamic> _$SimpleClassToJson(SimpleClass instance) => <String, dynamic>{ @@ -30,8 +30,8 @@ SimpleClassNullable _$SimpleClassNullableFromJson(Map<String, dynamic> json) => ); Map<String, dynamic> _$SimpleClassNullableToJson( - SimpleClassNullable instance) => - <String, dynamic>{ - 'value': instance.value?.toString(), - 'withDefault': instance.withDefault?.toString(), - }; + SimpleClassNullable instance, +) => <String, dynamic>{ + 'value': instance.value?.toString(), + 'withDefault': instance.withDefault?.toString(), +}; diff --git a/json_serializable/test/supported_types/support_types_extra_test.dart b/json_serializable/test/supported_types/support_types_extra_test.dart index 4a02b2ade..ada23d236 100644 --- a/json_serializable/test/supported_types/support_types_extra_test.dart +++ b/json_serializable/test/supported_types/support_types_extra_test.dart @@ -12,10 +12,7 @@ import 'input.type_map.dart'; void main() { test('SimpleClassOfStringToDouble', () { const value = { - 'value': { - 'double': 1.0, - 'int': 1, - } + 'value': {'double': 1.0, 'int': 1}, }; final object = SimpleClassOfStringToDouble.fromJson(value); @@ -28,7 +25,7 @@ void main() { 'double': 1.0, // Note! Encoded as a double on output! 'int': 1.0, - } + }, }), ); @@ -40,9 +37,7 @@ void main() { test('SimpleClassOfStringToInt', () { const value = { - 'value': { - 'int': 1, - } + 'value': {'int': 1}, }; final object = SimpleClassOfStringToInt.fromJson(value); @@ -58,10 +53,7 @@ void main() { test('SimpleClassOfStringToNum', () { const value = { - 'value': { - 'double': 1.0, - 'int': 1, - } + 'value': {'double': 1.0, 'int': 1}, }; final object = SimpleClassOfStringToNum.fromJson(value); @@ -78,12 +70,8 @@ void main() { test('SimpleClassOfStringToRecord', () { const value = { 'value': { - 'key': { - r'$1': 1, - r'$2': 'string', - 'truth': false, - } - } + 'key': {r'$1': 1, r'$2': 'string', 'truth': false}, + }, }; final object = SimpleClassOfStringToRecord.fromJson(value); diff --git a/json_serializable/test/supported_types/type_test.bigint_test.dart b/json_serializable/test/supported_types/type_test.bigint_test.dart index 83cfa4031..b7af11dae 100644 --- a/json_serializable/test/supported_types/type_test.bigint_test.dart +++ b/json_serializable/test/supported_types/type_test.bigint_test.dart @@ -27,10 +27,7 @@ void main() { }); test('round trip null', () { - expect( - () => loudEncode(SimpleClass.fromJson({})), - throwsTypeError, - ); + expect(() => loudEncode(SimpleClass.fromJson({})), throwsTypeError); }); test('round trip alternate values', () { @@ -89,21 +86,10 @@ void main() { const _defaultValue = '12345'; const _altValue = '67890'; -final _defaultInput = <String, Object?>{ - 'value': _defaultValue, -}; +final _defaultInput = <String, Object?>{'value': _defaultValue}; -final _defaultOutput = { - 'value': _defaultValue, - 'withDefault': _defaultValue, -}; +final _defaultOutput = {'value': _defaultValue, 'withDefault': _defaultValue}; -final _nullableDefaultOutput = { - 'value': null, - 'withDefault': _defaultValue, -}; +final _nullableDefaultOutput = {'value': null, 'withDefault': _defaultValue}; -final _nonDefaultJson = { - 'value': _altValue, - 'withDefault': _altValue, -}; +final _nonDefaultJson = {'value': _altValue, 'withDefault': _altValue}; diff --git a/json_serializable/test/supported_types/type_test.bool_test.dart b/json_serializable/test/supported_types/type_test.bool_test.dart index dc28ab84c..fd5492a3c 100644 --- a/json_serializable/test/supported_types/type_test.bool_test.dart +++ b/json_serializable/test/supported_types/type_test.bool_test.dart @@ -27,10 +27,7 @@ void main() { }); test('round trip null', () { - expect( - () => loudEncode(SimpleClass.fromJson({})), - throwsTypeError, - ); + expect(() => loudEncode(SimpleClass.fromJson({})), throwsTypeError); }); test('round trip alternate values', () { @@ -89,21 +86,10 @@ void main() { const _defaultValue = true; const _altValue = false; -final _defaultInput = <String, Object?>{ - 'value': _defaultValue, -}; +final _defaultInput = <String, Object?>{'value': _defaultValue}; -final _defaultOutput = { - 'value': _defaultValue, - 'withDefault': _defaultValue, -}; +final _defaultOutput = {'value': _defaultValue, 'withDefault': _defaultValue}; -final _nullableDefaultOutput = { - 'value': null, - 'withDefault': _defaultValue, -}; +final _nullableDefaultOutput = {'value': null, 'withDefault': _defaultValue}; -final _nonDefaultJson = { - 'value': _altValue, - 'withDefault': _altValue, -}; +final _nonDefaultJson = {'value': _altValue, 'withDefault': _altValue}; diff --git a/json_serializable/test/supported_types/type_test.dart b/json_serializable/test/supported_types/type_test.dart index 7cc6fc069..e65d9a7b3 100644 --- a/json_serializable/test/supported_types/type_test.dart +++ b/json_serializable/test/supported_types/type_test.dart @@ -55,21 +55,10 @@ void main() { const _defaultValue = 42; const _altValue = 43; -final _defaultInput = <String, Object?>{ - 'value': _defaultValue, -}; - -final _defaultOutput = { - 'value': _defaultValue, - 'withDefault': _defaultValue, -}; - -final _nullableDefaultOutput = { - 'value': null, - 'withDefault': _defaultValue, -}; - -final _nonDefaultJson = { - 'value': _altValue, - 'withDefault': _altValue, -}; +final _defaultInput = <String, Object?>{'value': _defaultValue}; + +final _defaultOutput = {'value': _defaultValue, 'withDefault': _defaultValue}; + +final _nullableDefaultOutput = {'value': null, 'withDefault': _defaultValue}; + +final _nonDefaultJson = {'value': _altValue, 'withDefault': _altValue}; diff --git a/json_serializable/test/supported_types/type_test.datetime_test.dart b/json_serializable/test/supported_types/type_test.datetime_test.dart index 88d5f53db..495e5ab74 100644 --- a/json_serializable/test/supported_types/type_test.datetime_test.dart +++ b/json_serializable/test/supported_types/type_test.datetime_test.dart @@ -27,10 +27,7 @@ void main() { }); test('round trip null', () { - expect( - () => loudEncode(SimpleClass.fromJson({})), - throwsTypeError, - ); + expect(() => loudEncode(SimpleClass.fromJson({})), throwsTypeError); }); test('round trip alternate values', () { @@ -89,21 +86,10 @@ void main() { const _defaultValue = '2020-01-01T00:00:00.000'; const _altValue = '2018-01-01T00:00:00.000'; -final _defaultInput = <String, Object?>{ - 'value': _defaultValue, -}; +final _defaultInput = <String, Object?>{'value': _defaultValue}; -final _defaultOutput = { - 'value': _defaultValue, - 'withDefault': _defaultValue, -}; +final _defaultOutput = {'value': _defaultValue, 'withDefault': _defaultValue}; -final _nullableDefaultOutput = { - 'value': null, - 'withDefault': _defaultValue, -}; +final _nullableDefaultOutput = {'value': null, 'withDefault': _defaultValue}; -final _nonDefaultJson = { - 'value': _altValue, - 'withDefault': _altValue, -}; +final _nonDefaultJson = {'value': _altValue, 'withDefault': _altValue}; diff --git a/json_serializable/test/supported_types/type_test.double_test.dart b/json_serializable/test/supported_types/type_test.double_test.dart index 5a55d9c93..bf3ebdb02 100644 --- a/json_serializable/test/supported_types/type_test.double_test.dart +++ b/json_serializable/test/supported_types/type_test.double_test.dart @@ -27,10 +27,7 @@ void main() { }); test('round trip null', () { - expect( - () => loudEncode(SimpleClass.fromJson({})), - throwsTypeError, - ); + expect(() => loudEncode(SimpleClass.fromJson({})), throwsTypeError); }); test('round trip alternate values', () { @@ -89,21 +86,10 @@ void main() { const _defaultValue = 3.14; const _altValue = 6.28; -final _defaultInput = <String, Object?>{ - 'value': _defaultValue, -}; +final _defaultInput = <String, Object?>{'value': _defaultValue}; -final _defaultOutput = { - 'value': _defaultValue, - 'withDefault': _defaultValue, -}; +final _defaultOutput = {'value': _defaultValue, 'withDefault': _defaultValue}; -final _nullableDefaultOutput = { - 'value': null, - 'withDefault': _defaultValue, -}; +final _nullableDefaultOutput = {'value': null, 'withDefault': _defaultValue}; -final _nonDefaultJson = { - 'value': _altValue, - 'withDefault': _altValue, -}; +final _nonDefaultJson = {'value': _altValue, 'withDefault': _altValue}; diff --git a/json_serializable/test/supported_types/type_test.duration_test.dart b/json_serializable/test/supported_types/type_test.duration_test.dart index 4d5f71814..3a5ca238b 100644 --- a/json_serializable/test/supported_types/type_test.duration_test.dart +++ b/json_serializable/test/supported_types/type_test.duration_test.dart @@ -27,10 +27,7 @@ void main() { }); test('round trip null', () { - expect( - () => loudEncode(SimpleClass.fromJson({})), - throwsTypeError, - ); + expect(() => loudEncode(SimpleClass.fromJson({})), throwsTypeError); }); test('round trip alternate values', () { @@ -89,18 +86,10 @@ void main() { const _defaultValue = 1234; const _altValue = 2345; -final _defaultInput = <String, Object?>{ - 'value': _defaultValue, -}; +final _defaultInput = <String, Object?>{'value': _defaultValue}; -final _defaultOutput = { - 'value': _defaultValue, -}; +final _defaultOutput = {'value': _defaultValue}; -final _nullableDefaultOutput = { - 'value': null, -}; +final _nullableDefaultOutput = {'value': null}; -final _nonDefaultJson = { - 'value': _altValue, -}; +final _nonDefaultJson = {'value': _altValue}; diff --git a/json_serializable/test/supported_types/type_test.enumtype_test.dart b/json_serializable/test/supported_types/type_test.enumtype_test.dart index 363d1ab9a..d16fa7651 100644 --- a/json_serializable/test/supported_types/type_test.enumtype_test.dart +++ b/json_serializable/test/supported_types/type_test.enumtype_test.dart @@ -27,10 +27,7 @@ void main() { }); test('round trip null', () { - expect( - () => loudEncode(SimpleClass.fromJson({})), - throwsArgumentError, - ); + expect(() => loudEncode(SimpleClass.fromJson({})), throwsArgumentError); }); test('round trip alternate values', () { @@ -89,21 +86,10 @@ void main() { const _defaultValue = 'alpha'; const _altValue = 'beta'; -final _defaultInput = <String, Object?>{ - 'value': _defaultValue, -}; +final _defaultInput = <String, Object?>{'value': _defaultValue}; -final _defaultOutput = { - 'value': _defaultValue, - 'withDefault': _defaultValue, -}; +final _defaultOutput = {'value': _defaultValue, 'withDefault': _defaultValue}; -final _nullableDefaultOutput = { - 'value': null, - 'withDefault': _defaultValue, -}; +final _nullableDefaultOutput = {'value': null, 'withDefault': _defaultValue}; -final _nonDefaultJson = { - 'value': _altValue, - 'withDefault': _altValue, -}; +final _nonDefaultJson = {'value': _altValue, 'withDefault': _altValue}; diff --git a/json_serializable/test/supported_types/type_test.int_test.dart b/json_serializable/test/supported_types/type_test.int_test.dart index 4e8c0cb27..e3ef71a68 100644 --- a/json_serializable/test/supported_types/type_test.int_test.dart +++ b/json_serializable/test/supported_types/type_test.int_test.dart @@ -27,10 +27,7 @@ void main() { }); test('round trip null', () { - expect( - () => loudEncode(SimpleClass.fromJson({})), - throwsTypeError, - ); + expect(() => loudEncode(SimpleClass.fromJson({})), throwsTypeError); }); test('round trip alternate values', () { @@ -89,21 +86,10 @@ void main() { const _defaultValue = 42; const _altValue = 43; -final _defaultInput = <String, Object?>{ - 'value': _defaultValue, -}; +final _defaultInput = <String, Object?>{'value': _defaultValue}; -final _defaultOutput = { - 'value': _defaultValue, - 'withDefault': _defaultValue, -}; +final _defaultOutput = {'value': _defaultValue, 'withDefault': _defaultValue}; -final _nullableDefaultOutput = { - 'value': null, - 'withDefault': _defaultValue, -}; +final _nullableDefaultOutput = {'value': null, 'withDefault': _defaultValue}; -final _nonDefaultJson = { - 'value': _altValue, - 'withDefault': _altValue, -}; +final _nonDefaultJson = {'value': _altValue, 'withDefault': _altValue}; diff --git a/json_serializable/test/supported_types/type_test.iterable_test.dart b/json_serializable/test/supported_types/type_test.iterable_test.dart index 1a2ae5960..81cab5c49 100644 --- a/json_serializable/test/supported_types/type_test.iterable_test.dart +++ b/json_serializable/test/supported_types/type_test.iterable_test.dart @@ -27,10 +27,7 @@ void main() { }); test('round trip null', () { - expect( - () => loudEncode(SimpleClass.fromJson({})), - throwsTypeError, - ); + expect(() => loudEncode(SimpleClass.fromJson({})), throwsTypeError); }); test('round trip alternate values', () { @@ -89,21 +86,10 @@ void main() { const _defaultValue = [42, true, false, null]; const _altValue = [43, false]; -final _defaultInput = <String, Object?>{ - 'value': _defaultValue, -}; +final _defaultInput = <String, Object?>{'value': _defaultValue}; -final _defaultOutput = { - 'value': _defaultValue, - 'withDefault': _defaultValue, -}; +final _defaultOutput = {'value': _defaultValue, 'withDefault': _defaultValue}; -final _nullableDefaultOutput = { - 'value': null, - 'withDefault': _defaultValue, -}; +final _nullableDefaultOutput = {'value': null, 'withDefault': _defaultValue}; -final _nonDefaultJson = { - 'value': _altValue, - 'withDefault': _altValue, -}; +final _nonDefaultJson = {'value': _altValue, 'withDefault': _altValue}; diff --git a/json_serializable/test/supported_types/type_test.list_test.dart b/json_serializable/test/supported_types/type_test.list_test.dart index 36e673318..74c165a28 100644 --- a/json_serializable/test/supported_types/type_test.list_test.dart +++ b/json_serializable/test/supported_types/type_test.list_test.dart @@ -27,10 +27,7 @@ void main() { }); test('round trip null', () { - expect( - () => loudEncode(SimpleClass.fromJson({})), - throwsTypeError, - ); + expect(() => loudEncode(SimpleClass.fromJson({})), throwsTypeError); }); test('round trip alternate values', () { @@ -89,21 +86,10 @@ void main() { const _defaultValue = [42, true, false, null]; const _altValue = [43, false]; -final _defaultInput = <String, Object?>{ - 'value': _defaultValue, -}; +final _defaultInput = <String, Object?>{'value': _defaultValue}; -final _defaultOutput = { - 'value': _defaultValue, - 'withDefault': _defaultValue, -}; +final _defaultOutput = {'value': _defaultValue, 'withDefault': _defaultValue}; -final _nullableDefaultOutput = { - 'value': null, - 'withDefault': _defaultValue, -}; +final _nullableDefaultOutput = {'value': null, 'withDefault': _defaultValue}; -final _nonDefaultJson = { - 'value': _altValue, - 'withDefault': _altValue, -}; +final _nonDefaultJson = {'value': _altValue, 'withDefault': _altValue}; diff --git a/json_serializable/test/supported_types/type_test.map_test.dart b/json_serializable/test/supported_types/type_test.map_test.dart index 925f233c2..ea4b475e1 100644 --- a/json_serializable/test/supported_types/type_test.map_test.dart +++ b/json_serializable/test/supported_types/type_test.map_test.dart @@ -27,10 +27,7 @@ void main() { }); test('round trip null', () { - expect( - () => loudEncode(SimpleClass.fromJson({})), - throwsTypeError, - ); + expect(() => loudEncode(SimpleClass.fromJson({})), throwsTypeError); }); test('round trip alternate values', () { @@ -89,21 +86,10 @@ void main() { const _defaultValue = {'a': 1}; const _altValue = {'b': 2}; -final _defaultInput = <String, Object?>{ - 'value': _defaultValue, -}; +final _defaultInput = <String, Object?>{'value': _defaultValue}; -final _defaultOutput = { - 'value': _defaultValue, - 'withDefault': _defaultValue, -}; +final _defaultOutput = {'value': _defaultValue, 'withDefault': _defaultValue}; -final _nullableDefaultOutput = { - 'value': null, - 'withDefault': _defaultValue, -}; +final _nullableDefaultOutput = {'value': null, 'withDefault': _defaultValue}; -final _nonDefaultJson = { - 'value': _altValue, - 'withDefault': _altValue, -}; +final _nonDefaultJson = {'value': _altValue, 'withDefault': _altValue}; diff --git a/json_serializable/test/supported_types/type_test.num_test.dart b/json_serializable/test/supported_types/type_test.num_test.dart index 8489d5ff7..b365ac6c4 100644 --- a/json_serializable/test/supported_types/type_test.num_test.dart +++ b/json_serializable/test/supported_types/type_test.num_test.dart @@ -27,10 +27,7 @@ void main() { }); test('round trip null', () { - expect( - () => loudEncode(SimpleClass.fromJson({})), - throwsTypeError, - ); + expect(() => loudEncode(SimpleClass.fromJson({})), throwsTypeError); }); test('round trip alternate values', () { @@ -89,21 +86,10 @@ void main() { const _defaultValue = 88.6; const _altValue = 29; -final _defaultInput = <String, Object?>{ - 'value': _defaultValue, -}; +final _defaultInput = <String, Object?>{'value': _defaultValue}; -final _defaultOutput = { - 'value': _defaultValue, - 'withDefault': _defaultValue, -}; +final _defaultOutput = {'value': _defaultValue, 'withDefault': _defaultValue}; -final _nullableDefaultOutput = { - 'value': null, - 'withDefault': _defaultValue, -}; +final _nullableDefaultOutput = {'value': null, 'withDefault': _defaultValue}; -final _nonDefaultJson = { - 'value': _altValue, - 'withDefault': _altValue, -}; +final _nonDefaultJson = {'value': _altValue, 'withDefault': _altValue}; diff --git a/json_serializable/test/supported_types/type_test.object_test.dart b/json_serializable/test/supported_types/type_test.object_test.dart index 5cad9da25..29fcabb63 100644 --- a/json_serializable/test/supported_types/type_test.object_test.dart +++ b/json_serializable/test/supported_types/type_test.object_test.dart @@ -27,10 +27,7 @@ void main() { }); test('round trip null', () { - expect( - () => loudEncode(SimpleClass.fromJson({})), - throwsTypeError, - ); + expect(() => loudEncode(SimpleClass.fromJson({})), throwsTypeError); }); test('round trip alternate values', () { @@ -89,21 +86,10 @@ void main() { const _defaultValue = 'o1'; const _altValue = 'o2'; -final _defaultInput = <String, Object?>{ - 'value': _defaultValue, -}; +final _defaultInput = <String, Object?>{'value': _defaultValue}; -final _defaultOutput = { - 'value': _defaultValue, - 'withDefault': _defaultValue, -}; +final _defaultOutput = {'value': _defaultValue, 'withDefault': _defaultValue}; -final _nullableDefaultOutput = { - 'value': null, - 'withDefault': _defaultValue, -}; +final _nullableDefaultOutput = {'value': null, 'withDefault': _defaultValue}; -final _nonDefaultJson = { - 'value': _altValue, - 'withDefault': _altValue, -}; +final _nonDefaultJson = {'value': _altValue, 'withDefault': _altValue}; diff --git a/json_serializable/test/supported_types/type_test.set_test.dart b/json_serializable/test/supported_types/type_test.set_test.dart index b0af7da12..293f87be9 100644 --- a/json_serializable/test/supported_types/type_test.set_test.dart +++ b/json_serializable/test/supported_types/type_test.set_test.dart @@ -27,10 +27,7 @@ void main() { }); test('round trip null', () { - expect( - () => loudEncode(SimpleClass.fromJson({})), - throwsTypeError, - ); + expect(() => loudEncode(SimpleClass.fromJson({})), throwsTypeError); }); test('round trip alternate values', () { @@ -89,21 +86,10 @@ void main() { const _defaultValue = [42, true, false, null]; const _altValue = [43, false]; -final _defaultInput = <String, Object?>{ - 'value': _defaultValue, -}; +final _defaultInput = <String, Object?>{'value': _defaultValue}; -final _defaultOutput = { - 'value': _defaultValue, - 'withDefault': _defaultValue, -}; +final _defaultOutput = {'value': _defaultValue, 'withDefault': _defaultValue}; -final _nullableDefaultOutput = { - 'value': null, - 'withDefault': _defaultValue, -}; +final _nullableDefaultOutput = {'value': null, 'withDefault': _defaultValue}; -final _nonDefaultJson = { - 'value': _altValue, - 'withDefault': _altValue, -}; +final _nonDefaultJson = {'value': _altValue, 'withDefault': _altValue}; diff --git a/json_serializable/test/supported_types/type_test.string_test.dart b/json_serializable/test/supported_types/type_test.string_test.dart index 2943b4424..4eaee4811 100644 --- a/json_serializable/test/supported_types/type_test.string_test.dart +++ b/json_serializable/test/supported_types/type_test.string_test.dart @@ -27,10 +27,7 @@ void main() { }); test('round trip null', () { - expect( - () => loudEncode(SimpleClass.fromJson({})), - throwsTypeError, - ); + expect(() => loudEncode(SimpleClass.fromJson({})), throwsTypeError); }); test('round trip alternate values', () { @@ -89,21 +86,10 @@ void main() { const _defaultValue = 'a string'; const _altValue = 'another string'; -final _defaultInput = <String, Object?>{ - 'value': _defaultValue, -}; +final _defaultInput = <String, Object?>{'value': _defaultValue}; -final _defaultOutput = { - 'value': _defaultValue, - 'withDefault': _defaultValue, -}; +final _defaultOutput = {'value': _defaultValue, 'withDefault': _defaultValue}; -final _nullableDefaultOutput = { - 'value': null, - 'withDefault': _defaultValue, -}; +final _nullableDefaultOutput = {'value': null, 'withDefault': _defaultValue}; -final _nonDefaultJson = { - 'value': _altValue, - 'withDefault': _altValue, -}; +final _nonDefaultJson = {'value': _altValue, 'withDefault': _altValue}; diff --git a/json_serializable/test/supported_types/type_test.uri_test.dart b/json_serializable/test/supported_types/type_test.uri_test.dart index 1d69a3c6f..5dc504981 100644 --- a/json_serializable/test/supported_types/type_test.uri_test.dart +++ b/json_serializable/test/supported_types/type_test.uri_test.dart @@ -27,10 +27,7 @@ void main() { }); test('round trip null', () { - expect( - () => loudEncode(SimpleClass.fromJson({})), - throwsTypeError, - ); + expect(() => loudEncode(SimpleClass.fromJson({})), throwsTypeError); }); test('round trip alternate values', () { @@ -89,21 +86,10 @@ void main() { const _defaultValue = 'https://example.com'; const _altValue = 'https://dart.dev'; -final _defaultInput = <String, Object?>{ - 'value': _defaultValue, -}; +final _defaultInput = <String, Object?>{'value': _defaultValue}; -final _defaultOutput = { - 'value': _defaultValue, - 'withDefault': _defaultValue, -}; +final _defaultOutput = {'value': _defaultValue, 'withDefault': _defaultValue}; -final _nullableDefaultOutput = { - 'value': null, - 'withDefault': _defaultValue, -}; +final _nullableDefaultOutput = {'value': null, 'withDefault': _defaultValue}; -final _nonDefaultJson = { - 'value': _altValue, - 'withDefault': _altValue, -}; +final _nonDefaultJson = {'value': _altValue, 'withDefault': _altValue}; diff --git a/json_serializable/tool/field_matrix_builder.dart b/json_serializable/tool/field_matrix_builder.dart index 32084658b..9455f2cb7 100644 --- a/json_serializable/tool/field_matrix_builder.dart +++ b/json_serializable/tool/field_matrix_builder.dart @@ -32,7 +32,8 @@ part '$inputBaseName.field_matrix.g.dart'; for (var isPublic in [true, false]) { for (var includeToJson in [null, true, false]) { for (var includeFromJson in [null, true, false]) { - final className = 'ToJson${includeToJson.toString().pascal}' + final className = + 'ToJson${includeToJson.toString().pascal}' 'FromJson${includeFromJson.toString().pascal}' '${isPublic ? 'Public' : 'Private'}'; @@ -46,8 +47,9 @@ part '$inputBaseName.field_matrix.g.dart'; if (!isPublic) "name: 'field'", ]; - final fieldAnnotation = - bits.isEmpty ? '' : '@JsonKey(${bits.join()})'; + final fieldAnnotation = bits.isEmpty + ? '' + : '@JsonKey(${bits.join()})'; content.writeln(''' @JsonSerializable() @@ -85,6 +87,6 @@ const fromJsonFactories = <Object Function(Map<String, dynamic>)>{ @override Map<String, List<String>> get buildExtensions => const { - '.dart': ['.field_matrix.dart'], - }; + '.dart': ['.field_matrix.dart'], + }; } diff --git a/json_serializable/tool/readme/readme_examples.dart b/json_serializable/tool/readme/readme_examples.dart index 0abc70fc5..0c684bcaa 100644 --- a/json_serializable/tool/readme/readme_examples.dart +++ b/json_serializable/tool/readme/readme_examples.dart @@ -63,10 +63,7 @@ class Sample3 { factory Sample3.fromJson(Map<String, dynamic> json) => _$Sample3FromJson(json); - @JsonKey( - toJson: _toJson, - fromJson: _fromJson, - ) + @JsonKey(toJson: _toJson, fromJson: _fromJson) final DateTime value; Map<String, dynamic> toJson() => _$Sample3ToJson(this); diff --git a/json_serializable/tool/readme/readme_examples.g.dart b/json_serializable/tool/readme/readme_examples.g.dart index b3a60ab36..5390b6d59 100644 --- a/json_serializable/tool/readme/readme_examples.g.dart +++ b/json_serializable/tool/readme/readme_examples.g.dart @@ -8,26 +8,24 @@ part of 'readme_examples.dart'; // JsonSerializableGenerator // ************************************************************************** -Sample1 _$Sample1FromJson(Map<String, dynamic> json) => Sample1( - Sample2.fromJson((json['value'] as num).toInt()), - ); +Sample1 _$Sample1FromJson(Map<String, dynamic> json) => + Sample1(Sample2.fromJson((json['value'] as num).toInt())); Map<String, dynamic> _$Sample1ToJson(Sample1 instance) => <String, dynamic>{ - 'value': instance.value, - }; + 'value': instance.value, +}; -Sample3 _$Sample3FromJson(Map<String, dynamic> json) => Sample3( - Sample3._fromJson((json['value'] as num).toInt()), - ); +Sample3 _$Sample3FromJson(Map<String, dynamic> json) => + Sample3(Sample3._fromJson((json['value'] as num).toInt())); Map<String, dynamic> _$Sample3ToJson(Sample3 instance) => <String, dynamic>{ - 'value': Sample3._toJson(instance.value), - }; + 'value': Sample3._toJson(instance.value), +}; Sample4 _$Sample4FromJson(Map<String, dynamic> json) => Sample4( - const EpochDateTimeConverter().fromJson((json['value'] as num).toInt()), - ); + const EpochDateTimeConverter().fromJson((json['value'] as num).toInt()), +); Map<String, dynamic> _$Sample4ToJson(Sample4 instance) => <String, dynamic>{ - 'value': const EpochDateTimeConverter().toJson(instance.value), - }; + 'value': const EpochDateTimeConverter().toJson(instance.value), +}; diff --git a/json_serializable/tool/readme_builder.dart b/json_serializable/tool/readme_builder.dart index 1de8c6398..3709ee017 100644 --- a/json_serializable/tool/readme_builder.dart +++ b/json_serializable/tool/readme_builder.dart @@ -18,8 +18,9 @@ Builder readmeBuilder([BuilderOptions? _]) => _ReadmeBuilder(); class _ReadmeBuilder extends Builder { @override FutureOr<void> build(BuildStep buildStep) async { - final templateAssetId = - buildStep.assetIdForInputPackage('tool/readme/readme_template.md'); + final templateAssetId = buildStep.assetIdForInputPackage( + 'tool/readme/readme_template.md', + ); final replacements = { ...await buildStep.getExampleContent('example/example.dart'), @@ -38,8 +39,8 @@ class _ReadmeBuilder extends Builder { String jsonAnnotationUri(String className, [String? member]) => member == null - ? '$jsonAnnotationBaseUri/$className-class.html' - : '$jsonAnnotationBaseUri/$className/$member.html'; + ? '$jsonAnnotationBaseUri/$className-class.html' + : '$jsonAnnotationBaseUri/$className/$member.html'; final foundClasses = SplayTreeMap<String, String>(compareAsciiLowerCase); @@ -62,11 +63,11 @@ class _ReadmeBuilder extends Builder { linkValue = switch (context) { 'core' => _coreTypeUri(className), 'ja' => jsonAnnotationUri(className, memberName?.substring(1)), - _ => 'https://unknown.com/$context/$className' + _ => 'https://unknown.com/$context/$className', }; foundClasses[linkContent] = linkValue; return linkContent; - } + }, }; var content = (await buildStep.readAsString(templateAssetId)).trim(); @@ -81,7 +82,8 @@ class _ReadmeBuilder extends Builder { ); } - content = ''' + content = + ''' <!-- This content is generated. See $_templatePath --> $content ${foundClasses.entries.map((e) => '${e.key}: ${e.value}').join('\n')} @@ -95,7 +97,7 @@ ${foundClasses.entries.map((e) => '${e.key}: ${e.value}').join('\n')} @override final buildExtensions = const { - _templatePath: [_readmePath] + _templatePath: [_readmePath], }; } @@ -106,13 +108,14 @@ String _coreTypeUri(String type) => 'https://api.dart.dev/dart-core/$type-class.html'; String _classCleanAndSort(Iterable<String> classes) { - final initial = (classes.map((e) => e == customEnumType ? 'Enum' : e).toList() - ..sort(compareAsciiLowerCase)) - // Dropping `dynamic` – it's not linkable! - .where((element) => element != 'dynamic') - // Start by mapping to the output format – so we wrap correctly - .map((e) => '[`$e`]') - .join(', '); + final initial = + (classes.map((e) => e == customEnumType ? 'Enum' : e).toList() + ..sort(compareAsciiLowerCase)) + // Dropping `dynamic` – it's not linkable! + .where((element) => element != 'dynamic') + // Start by mapping to the output format – so we wrap correctly + .map((e) => '[`$e`]') + .join(', '); if (initial.length <= 80) { return initial; @@ -143,7 +146,9 @@ String _classCleanAndSort(Iterable<String> classes) { lines.add(currentLine); } - return lines.join('\n').replaceAllMapped( + return lines + .join('\n') + .replaceAllMapped( // Now put in the core: logic so we autolink correctly RegExp(r'\[`(\w+)`\]'), (match) => '`core:${match[1]}`', @@ -154,16 +159,24 @@ extension on BuildStep { AssetId assetIdForInputPackage(String path) => AssetId(inputId.package, path); Future<String> jsonAnnotationVersion() async { - final jsonAnnotationPubspecAssetId = - AssetId('json_annotation', 'pubspec.yaml'); - final jsonAnnotationPubspecContent = - await readAsString(jsonAnnotationPubspecAssetId); - final pubspecYaml = loadYaml(jsonAnnotationPubspecContent, - sourceUrl: jsonAnnotationPubspecAssetId.uri) as YamlMap; + final jsonAnnotationPubspecAssetId = AssetId( + 'json_annotation', + 'pubspec.yaml', + ); + final jsonAnnotationPubspecContent = await readAsString( + jsonAnnotationPubspecAssetId, + ); + final pubspecYaml = + loadYaml( + jsonAnnotationPubspecContent, + sourceUrl: jsonAnnotationPubspecAssetId.uri, + ) + as YamlMap; final jsonAnnotationVersionString = pubspecYaml['version'] as String; - final jsonAnnotationVersion = - Version.parse(jsonAnnotationVersionString.trim()); + final jsonAnnotationVersion = Version.parse( + jsonAnnotationVersionString.trim(), + ); final targetVersion = jsonAnnotationVersion.isPreRelease ? 'latest' @@ -173,9 +186,7 @@ extension on BuildStep { } Future<Map<String, String>> getExampleContent(String fileName) async { - final content = await readAsString( - assetIdForInputPackage(fileName), - ); + final content = await readAsString(assetIdForInputPackage(fileName)); final lines = LineSplitter.split(content); @@ -249,12 +260,11 @@ extension on BuildStep { if (currentBlock != null) finishBlock(); - return result - .map((key, value) => MapEntry('$fileName-$key', value.dartBlock)); + return result.map( + (key, value) => MapEntry('$fileName-$key', value.dartBlock), + ); } else { - return { - fileName: cleanedSourceLines.join('\n').dartBlock, - }; + return {fileName: cleanedSourceLines.join('\n').dartBlock}; } } } @@ -270,7 +280,8 @@ extension on String { return substring(start).trim(); } - String get dartBlock => ''' + String get dartBlock => + ''' ```dart ${trim()} ```'''; diff --git a/json_serializable/tool/shared.dart b/json_serializable/tool/shared.dart index 265031a22..ca7068d4c 100644 --- a/json_serializable/tool/shared.dart +++ b/json_serializable/tool/shared.dart @@ -11,10 +11,12 @@ import 'package:yaml/yaml.dart'; // Until we have verification in pkg:build and friends // https://github.com/dart-lang/build/issues/590 Builder validate(String builderName, Builder builder) { - var buildYaml = loadYaml( - File('build.yaml').readAsStringSync(), - sourceUrl: Uri.parse('build.yaml'), - ) as YamlMap; + var buildYaml = + loadYaml( + File('build.yaml').readAsStringSync(), + sourceUrl: Uri.parse('build.yaml'), + ) + as YamlMap; for (var key in ['builders', builderName, 'build_extensions']) { buildYaml = buildYaml[key] as YamlMap; @@ -50,8 +52,8 @@ class Replacement { const Replacement(this.existing, this.replacement); const Replacement.addJsonSerializableKey(String key, bool value) - : existing = '@JsonSerializable(', - replacement = '@JsonSerializable(\n $key: $value,'; + : existing = '@JsonSerializable(', + replacement = '@JsonSerializable(\n $key: $value,'; static String generate( String inputContent, @@ -73,5 +75,6 @@ class Replacement { extension BuildStepExtension on BuildStep { Future<DartFormatter> formatter() async => DartFormatter( - languageVersion: (await inputLibrary).languageVersion.effective); + languageVersion: (await inputLibrary).languageVersion.effective, + ); } diff --git a/json_serializable/tool/test_builder.dart b/json_serializable/tool/test_builder.dart index 8f742241c..4e325882a 100644 --- a/json_serializable/tool/test_builder.dart +++ b/json_serializable/tool/test_builder.dart @@ -36,15 +36,17 @@ class _TestBuilder implements Builder { Replacement( "part '$baseName.g.dart';", "part '$baseName$partName.g.dart';", - ) + ), ]; if (baseName == _kitchenSinkBaseName) { final description = _configToName(config.toSet()); - replacements.add(Replacement( - "String get description => '--defaults--';", - "String get description => '$description';", - )); + replacements.add( + Replacement( + "String get description => '--defaults--';", + "String get description => '$description';", + ), + ); factories['$baseName$partName.dart'] = description; } @@ -77,24 +79,24 @@ class _TestBuilder implements Builder { } @override - Map<String, List<String>> get buildExtensions => - {'.dart': _fileConfigurations}; + Map<String, List<String>> get buildExtensions => { + '.dart': _fileConfigurations, + }; } const _configReplacements = { 'any_map': Replacement.addJsonSerializableKey('anyMap', true), 'checked': Replacement.addJsonSerializableKey('checked', true), - 'explicit_to_json': - Replacement.addJsonSerializableKey('explicitToJson', true), + 'explicit_to_json': Replacement.addJsonSerializableKey( + 'explicitToJson', + true, + ), 'exclude_null': Replacement.addJsonSerializableKey('includeIfNull', false), }; const _kitchenSinkReplacements = { 'any_map': [ - Replacement( - 'bool get anyMap => false;', - 'bool get anyMap => true;', - ), + Replacement('bool get anyMap => false;', 'bool get anyMap => true;'), Replacement( 'class _Factory implements k.KitchenSinkFactory<String, dynamic>', 'class _Factory implements k.KitchenSinkFactory<dynamic, dynamic>', @@ -109,10 +111,7 @@ const _kitchenSinkReplacements = { ), ], 'checked': [ - Replacement( - 'bool get checked => false;', - 'bool get checked => true;', - ) + Replacement('bool get checked => false;', 'bool get checked => true;'), ], 'exclude_null': [ Replacement( @@ -135,7 +134,9 @@ const _kitchenSinkReplacements = { }; Iterable<Replacement> _optionReplacement( - String baseName, String optionKey) sync* { + String baseName, + String optionKey, +) sync* { final value = _configReplacements[optionKey]; if (value == null) { log.warning('no replacement thingy for `$optionKey`.'); @@ -155,13 +156,14 @@ String _configToExtension(Iterable<String> config) => String _configToName(Set<String> config) => (config.toList()..sort()).join('__'); -List<String> get _fileConfigurations => _fileConfigurationMap.values - .expand((v) => v) - .map(_configToExtension) - .followedBy(['.factories.dart']) - .toSet() - .toList() - ..sort(); +List<String> get _fileConfigurations => + _fileConfigurationMap.values + .expand((v) => v) + .map(_configToExtension) + .followedBy(['.factories.dart']) + .toSet() + .toList() + ..sort(); const _kitchenSinkBaseName = 'kitchen_sink'; diff --git a/json_serializable/tool/test_type_builder.dart b/json_serializable/tool/test_type_builder.dart index 2c23c8d3a..54ef05688 100644 --- a/json_serializable/tool/test_type_builder.dart +++ b/json_serializable/tool/test_type_builder.dart @@ -16,39 +16,21 @@ const _trivialTypesToTest = { jsonExpression: "'12345'", altJsonExpression: "'67890'", ), - 'bool': TestTypeData( - defaultExpression: 'true', - altJsonExpression: 'false', - ), + 'bool': TestTypeData(defaultExpression: 'true', altJsonExpression: 'false'), 'DateTime': TestTypeData.defaultFunc( jsonExpression: "'2020-01-01T00:00:00.000'", altJsonExpression: "'2018-01-01T00:00:00.000'", ), - 'double': TestTypeData( - defaultExpression: '3.14', - altJsonExpression: '6.28', - ), - 'Duration': TestTypeData( - jsonExpression: '1234', - altJsonExpression: '2345', - ), + 'double': TestTypeData(defaultExpression: '3.14', altJsonExpression: '6.28'), + 'Duration': TestTypeData(jsonExpression: '1234', altJsonExpression: '2345'), customEnumType: TestTypeData( defaultExpression: '$customEnumType.alpha', jsonExpression: "'alpha'", altJsonExpression: "'beta'", ), - 'int': TestTypeData( - defaultExpression: '42', - altJsonExpression: '43', - ), - 'num': TestTypeData( - defaultExpression: '88.6', - altJsonExpression: '29', - ), - 'Object': TestTypeData( - defaultExpression: "'o1'", - altJsonExpression: "'o2'", - ), + 'int': TestTypeData(defaultExpression: '42', altJsonExpression: '43'), + 'num': TestTypeData(defaultExpression: '88.6', altJsonExpression: '29'), + 'Object': TestTypeData(defaultExpression: "'o1'", altJsonExpression: "'o2'"), 'String': TestTypeData( defaultExpression: "'a string'", altJsonExpression: "'another string'", @@ -90,13 +72,10 @@ final _collectionTypes = { recordType: TestTypeData( altJsonExpression: '{}', genericArgs: _iterableGenericArgs, - ) + ), }; -final _allTypes = { - ..._trivialTypesToTest, - ..._collectionTypes, -}; +final _allTypes = {..._trivialTypesToTest, ..._collectionTypes}; final _typesToTest = Map.of(_allTypes)..remove(recordType); @@ -112,8 +91,7 @@ final _iterableGenericArgs = ([ 'FromJsonObjectParam', 'dynamic', recordType, -]..sort(compareAsciiLowerCase)) - .toSet(); +]..sort(compareAsciiLowerCase)).toSet(); const _defaultCollectionExpressions = '42, true, false, null'; const _altCollectionExpressions = '43, false'; @@ -144,8 +122,9 @@ class _TypeBuilder implements Builder { } @override - Map<String, List<String>> get buildExtensions => - {'.dart': _allTypes.keys.map(toTypeExtension).toSet().toList()..sort()}; + Map<String, List<String>> get buildExtensions => { + '.dart': _allTypes.keys.map(toTypeExtension).toSet().toList()..sort(), + }; } Builder typeTestBuilder([BuilderOptions? _]) => @@ -162,8 +141,9 @@ class _TypeTestBuilder implements Builder { for (var entry in _typesToTest.entries) { final type = entry.key; - final newId = - buildStep.inputId.changeExtension(_toTypeTestExtension(type)); + final newId = buildStep.inputId.changeExtension( + _toTypeTestExtension(type), + ); await buildStep.writeAsString( newId, @@ -174,9 +154,9 @@ class _TypeTestBuilder implements Builder { @override Map<String, List<String>> get buildExtensions => { - '.dart': _typesToTest.keys.map(_toTypeTestExtension).toSet().toList() - ..sort() - }; + '.dart': _typesToTest.keys.map(_toTypeTestExtension).toSet().toList() + ..sort(), + }; } String _toTypeTestExtension(String e) => '.${typeToPathPart(e)}_test.dart'; diff --git a/json_serializable/tool/test_type_data.dart b/json_serializable/tool/test_type_data.dart index 6d785a448..dd09e8bb0 100644 --- a/json_serializable/tool/test_type_data.dart +++ b/json_serializable/tool/test_type_data.dart @@ -1,3 +1,6 @@ +import 'package:dart_style/dart_style.dart'; +import 'package:pub_semver/pub_semver.dart'; + import 'shared.dart'; const customEnumType = 'EnumType'; @@ -19,18 +22,18 @@ class TestTypeData { String? jsonExpression, required String? altJsonExpression, this.genericArgs = const {}, - }) : jsonExpression = jsonExpression ?? defaultExpression, - altJsonExpression = - altJsonExpression ?? jsonExpression ?? defaultExpression, - stringParseType = false; + }) : jsonExpression = jsonExpression ?? defaultExpression, + altJsonExpression = + altJsonExpression ?? jsonExpression ?? defaultExpression, + stringParseType = false; const TestTypeData.defaultFunc({ this.jsonExpression, required String? altJsonExpression, - }) : altJsonExpression = altJsonExpression ?? jsonExpression, - genericArgs = const {}, - defaultExpression = null, - stringParseType = true; + }) : altJsonExpression = altJsonExpression ?? jsonExpression, + genericArgs = const {}, + defaultExpression = null, + stringParseType = true; String libContent(String source, String type) { const classAnnotationSplit = '@JsonSerializable()'; @@ -49,14 +52,12 @@ class TestTypeData { '$_annotationImport' "import 'enum_type.dart';", ), - Replacement( - "part 'input.g.dart';", - "part 'input$newPart.g.dart';", - ) + Replacement("part 'input.g.dart';", "part 'input$newPart.g.dart';"), ]; - final buffer = - StringBuffer(Replacement.generate(split[0], headerReplacements)); + final buffer = StringBuffer( + Replacement.generate(split[0], headerReplacements), + ); if (type == recordType) { buffer.writeln('typedef RecordTypeDef = ();'); @@ -75,10 +76,7 @@ class TestTypeData { ) ..write( Replacement.generate( - simpleClassContent.replaceAll( - 'SimpleClass', - 'SimpleClassNullable', - ), + simpleClassContent.replaceAll('SimpleClass', 'SimpleClassNullable'), _libReplacements('$simpleLiteral?'), ), ); @@ -101,8 +99,9 @@ class TestTypeData { ',$sampleRecordDefinition', ); - final genericType = - type == recordType ? '${theName}TypeDef' : '$type<$genericArgFixed>'; + final genericType = type == recordType + ? '${theName}TypeDef' + : '$type<$genericArgFixed>'; if (type == recordType) { buffer.writeln( @@ -114,10 +113,7 @@ class TestTypeData { buffer ..write( Replacement.generate( - simpleClassContent.replaceAll( - 'SimpleClass', - theName, - ), + simpleClassContent.replaceAll('SimpleClass', theName), _libReplacements(genericType), ), ) @@ -158,33 +154,25 @@ class TestTypeData { } Iterable<Replacement> _libReplacements(String type) sync* { - yield Replacement( - 'final dynamic value;', - 'final $type value;', - ); + yield Replacement('final dynamic value;', 'final $type value;'); final defaultNotSupported = - _annotationDefaultValue == null // no default provided + _annotationDefaultValue == + null // no default provided || - type.contains('<') // no support for default values and generic args + type.contains('<') // no support for default values and generic args ; final defaultReplacement = defaultNotSupported ? '' : _defaultSource - .replaceFirst('42', _annotationDefaultValue!) - .replaceFirst('dynamic', type); + .replaceFirst('42', _annotationDefaultValue!) + .replaceFirst('dynamic', type); - yield Replacement( - _defaultSource, - defaultReplacement, - ); + yield Replacement(_defaultSource, defaultReplacement); if (defaultNotSupported) { - yield const Replacement( - ' this.withDefault,', - '', - ); + yield const Replacement('this.withDefault', ''); } } @@ -201,8 +189,9 @@ class TestTypeData { .replaceAll('non-nullable', 'nullable') .replaceAll('SimpleClass', 'SimpleClassNullable'); - final thrownError = - type == customEnumType ? 'throwsArgumentError' : 'throwsTypeError'; + final thrownError = type == customEnumType + ? 'throwsArgumentError' + : 'throwsTypeError'; final newGroupContent = groupContent.replaceAll( r''' @@ -228,10 +217,12 @@ class TestTypeData { sourceContent.substring(endIndex), ].join(); - return Replacement.generate( + final value = Replacement.generate( updatedSourceContent, _testReplacements(type), ); + + return _formatter.format(value); } Iterable<Replacement> _testReplacements(String type) sync* { @@ -252,14 +243,8 @@ const _altValue = $altJsonExpression; ); if (defaultExpression == null && !stringParseType) { - yield const Replacement( - " 'withDefault': _defaultValue,\n", - '', - ); - yield const Replacement( - " 'withDefault': _altValue,\n", - '', - ); + yield const Replacement("'withDefault': _defaultValue", ''); + yield const Replacement("'withDefault': _altValue", ''); } } @@ -270,13 +255,16 @@ const _altValue = $altJsonExpression; '''; } +final _formatter = DartFormatter( + languageVersion: + // Using parse here so searching for the version string is easier! + Version.parse('3.8.0'), +); + String _genericClassPart(String genericArg) => genericArg .replaceAll('?', 'Nullable') .split(',') - .map((e) => [ - e.substring(0, 1).toUpperCase(), - e.substring(1), - ].join()) + .map((e) => [e.substring(0, 1).toUpperCase(), e.substring(1)].join()) .join('To'); String toTypeExtension(String e, {bool includeDotDart = true}) => diff --git a/pubspec.yaml b/pubspec.yaml index ac2343cc3..a5ba24d13 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: json_serial_workspace # Can be anything environment: - sdk: ^3.5.0 + sdk: ^3.8.0 publish_to: none diff --git a/shared_test/pubspec.yaml b/shared_test/pubspec.yaml index 23aed093a..9b6990a4b 100644 --- a/shared_test/pubspec.yaml +++ b/shared_test/pubspec.yaml @@ -1,7 +1,7 @@ name: _json_serial_shared_test publish_to: none environment: - sdk: ^3.6.0 + sdk: ^3.8.0 resolution: workspace diff --git a/tool/ci.sh b/tool/ci.sh index c6a601c34..8cecb2e3d 100755 --- a/tool/ci.sh +++ b/tool/ci.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Created with package:mono_repo v6.6.2 +# Created with package:mono_repo v6.6.3 # Support built in commands on windows out of the box. From 275eba6083cf4657b2f1c6413c0a4797247061dc Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Wed, 4 Jun 2025 16:35:21 -0500 Subject: [PATCH 560/569] Default to new, null-aware element feature in Dart 3.8 (#1498) --- _test_yaml/test/src/build_config.g.dart | 23 +++---- analysis_options.yaml | 1 + example/lib/example.g.dart | 15 ++--- json_serializable/CHANGELOG.md | 1 + json_serializable/lib/src/constants.dart | 6 +- json_serializable/lib/src/encoder_helper.dart | 8 +-- .../test/annotation_version_test.dart | 2 +- .../integration/converter_examples.g.dart | 31 ++++----- .../create_per_field_to_json_example.g.dart | 3 +- .../test/integration/json_enum_example.g.dart | 3 +- .../test/integration/json_test_example.g.dart | 4 +- .../json_test_example.g_any_map.g.dart | 4 +- .../kitchen_sink.g_exclude_null.g.dart | 66 ++++++++----------- .../src/_json_serializable_test_input.dart | 5 +- .../test/src/inheritance_test_input.dart | 6 +- .../test/src/to_from_json_test_input.dart | 4 +- 16 files changed, 74 insertions(+), 108 deletions(-) diff --git a/_test_yaml/test/src/build_config.g.dart b/_test_yaml/test/src/build_config.g.dart index 78bb619b9..e453d996c 100644 --- a/_test_yaml/test/src/build_config.g.dart +++ b/_test_yaml/test/src/build_config.g.dart @@ -119,20 +119,17 @@ Builder _$BuilderFromJson(Map json) => $checkedCreate( ); Map<String, dynamic> _$BuilderToJson(Builder instance) => <String, dynamic>{ - if (instance.target case final value?) 'target': value, - if (instance.import case final value?) 'import': value, - if (instance.isOptional case final value?) 'is_optional': value, - if (instance.configLocation?.toString() case final value?) - 'configLocation': value, - if (_$AutoApplyEnumMap[instance.autoApply] case final value?) - 'auto_apply': value, - if (_$BuildToEnumMap[instance.buildTo] case final value?) 'build_to': value, - if (_$AutoApplyEnumMap[instance.defaultEnumTest] case final value?) - 'defaultEnumTest': value, + 'target': ?instance.target, + 'import': ?instance.import, + 'is_optional': ?instance.isOptional, + 'configLocation': ?instance.configLocation?.toString(), + 'auto_apply': ?_$AutoApplyEnumMap[instance.autoApply], + 'build_to': ?_$BuildToEnumMap[instance.buildTo], + 'defaultEnumTest': ?_$AutoApplyEnumMap[instance.defaultEnumTest], 'builder_factories': instance.builderFactories, - if (instance.appliesBuilders case final value?) 'applies_builders': value, - if (instance.requiredInputs case final value?) 'required_inputs': value, - if (instance.buildExtensions case final value?) 'build_extensions': value, + 'applies_builders': ?instance.appliesBuilders, + 'required_inputs': ?instance.requiredInputs, + 'build_extensions': ?instance.buildExtensions, }; const _$BuildToEnumMap = {BuildTo.cache: 'cache', BuildTo.source: 'source'}; diff --git a/analysis_options.yaml b/analysis_options.yaml index f87c95a72..24ad09c26 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -29,4 +29,5 @@ linter: - unnecessary_breaks - unnecessary_ignore - use_full_hex_values_for_flutter_colors + - use_null_aware_elements - use_string_buffers diff --git a/example/lib/example.g.dart b/example/lib/example.g.dart index c35c960af..6c1d3cb06 100644 --- a/example/lib/example.g.dart +++ b/example/lib/example.g.dart @@ -21,7 +21,7 @@ Person _$PersonFromJson(Map<String, dynamic> json) => Person( Map<String, dynamic> _$PersonToJson(Person instance) => <String, dynamic>{ 'firstName': instance.firstName, - if (instance.middleName case final value?) 'middleName': value, + 'middleName': ?instance.middleName, 'lastName': instance.lastName, 'date-of-birth': instance.dateOfBirth.toIso8601String(), 'last-order': instance.lastOrder?.toIso8601String(), @@ -41,13 +41,12 @@ Order _$OrderFromJson(Map<String, dynamic> json) => ); Map<String, dynamic> _$OrderToJson(Order instance) => <String, dynamic>{ - if (instance.count case final value?) 'count': value, - if (instance.itemNumber case final value?) 'itemNumber': value, - if (instance.isRushed case final value?) 'isRushed': value, - if (instance.item case final value?) 'item': value, - if (Order._durationToMilliseconds(instance.prepTime) case final value?) - 'prep-time': value, - if (Order._dateTimeToEpochUs(instance.date) case final value?) 'date': value, + 'count': ?instance.count, + 'itemNumber': ?instance.itemNumber, + 'isRushed': ?instance.isRushed, + 'item': ?instance.item, + 'prep-time': ?Order._durationToMilliseconds(instance.prepTime), + 'date': ?Order._dateTimeToEpochUs(instance.date), }; Item _$ItemFromJson(Map<String, dynamic> json) => Item() diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 4d1b7a639..43ab453da 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,6 +1,7 @@ ## 6.9.6-wip - Move `package:collection` to a dev dependency. +- Use new `null-aware element` feature in generated code. - Require Dart 3.8 ## 6.9.5 diff --git a/json_serializable/lib/src/constants.dart b/json_serializable/lib/src/constants.dart index 70e85216f..f10fd8065 100644 --- a/json_serializable/lib/src/constants.dart +++ b/json_serializable/lib/src/constants.dart @@ -14,6 +14,6 @@ const converterOrKeyInstructions = r''' https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/fromJson.html https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/toJson.html'''; -/// This package generates code that uses case statements, which were introduced -/// in Dart 3.0. -const supportedLanguageConstraint = '^3.0.0'; +/// This package generates code that uses null-aware elements, which were +/// introduced in Dart 3.8. +const supportedLanguageConstraint = '^3.8.0'; diff --git a/json_serializable/lib/src/encoder_helper.dart b/json_serializable/lib/src/encoder_helper.dart index dc7e8a9ec..7effcd05e 100644 --- a/json_serializable/lib/src/encoder_helper.dart +++ b/json_serializable/lib/src/encoder_helper.dart @@ -6,7 +6,6 @@ import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/nullability_suffix.dart'; import 'package:source_helper/source_helper.dart'; -import 'constants.dart'; import 'enum_utils.dart'; import 'helper_core.dart'; import 'type_helpers/generic_factory_helper.dart'; @@ -109,10 +108,9 @@ mixin EncodeHelper implements HelperCore { final keyExpression = safeNameAccess(field); final valueExpression = _serializeField(field, access); - final keyValuePair = _canWriteJsonWithoutNullCheck(field) - ? '$keyExpression: $valueExpression' - : 'if ($valueExpression case final $generatedLocalVarName?) ' - '$keyExpression: $generatedLocalVarName'; + final maybeQuestion = _canWriteJsonWithoutNullCheck(field) ? '' : '?'; + + final keyValuePair = '$keyExpression: $maybeQuestion$valueExpression'; return ' $keyValuePair,\n'; }), ) diff --git a/json_serializable/test/annotation_version_test.dart b/json_serializable/test/annotation_version_test.dart index 7084abd28..b15d89987 100644 --- a/json_serializable/test/annotation_version_test.dart +++ b/json_serializable/test/annotation_version_test.dart @@ -32,7 +32,7 @@ void main() { group('language version', () { test('is less than required', () async { - const sdkLowerBound = '2.12.0'; + const sdkLowerBound = '3.7.0'; await _structurePackage( environment: const {'sdk': '^$sdkLowerBound'}, dependencies: {'json_annotation': _annotationLowerBound}, diff --git a/json_serializable/test/integration/converter_examples.g.dart b/json_serializable/test/integration/converter_examples.g.dart index d91d76d93..7315b4a30 100644 --- a/json_serializable/test/integration/converter_examples.g.dart +++ b/json_serializable/test/integration/converter_examples.g.dart @@ -33,20 +33,15 @@ Map<String, dynamic> _$Issue1202RegressionClassToJson( ), 'notNullableValueWithConverter': const _Issue1202RegressionNotNullConverter() .toJson(instance.notNullableValueWithConverter), - if (_$Issue1202RegressionEnumEnumMap[instance.value] case final value?) - 'value': value, - if (instance.normalNullableValue case final value?) - 'normalNullableValue': value, - if (const _Issue1202RegressionConverter().toJson( + 'value': ?_$Issue1202RegressionEnumEnumMap[instance.value], + 'normalNullableValue': ?instance.normalNullableValue, + 'notNullableValueWithNullableConverter': + ?const _Issue1202RegressionConverter().toJson( instance.notNullableValueWithNullableConverter, - ) - case final value?) - 'notNullableValueWithNullableConverter': value, - if (Issue1202RegressionClass._toJsonNullable( - instance.valueWithNullableFunctions, - ) - case final value?) - 'valueWithNullableFunctions': value, + ), + 'valueWithNullableFunctions': ?Issue1202RegressionClass._toJsonNullable( + instance.valueWithNullableFunctions, + ), }; const _$Issue1202RegressionEnumEnumMap = { @@ -64,12 +59,10 @@ Regression1229 _$Regression1229FromJson(Map<String, dynamic> json) => Map<String, dynamic> _$Regression1229ToJson(Regression1229 instance) => <String, dynamic>{ - if (_$JsonConverterToJson<String, DateTime>( - instance.date, - const DateTimeConverter().toJson, - ) - case final value?) - 'date': value, + 'date': ?_$JsonConverterToJson<String, DateTime>( + instance.date, + const DateTimeConverter().toJson, + ), }; Value? _$JsonConverterFromJson<Json, Value>( diff --git a/json_serializable/test/integration/create_per_field_to_json_example.g.dart b/json_serializable/test/integration/create_per_field_to_json_example.g.dart index 14d7d9f0f..f77139ee1 100644 --- a/json_serializable/test/integration/create_per_field_to_json_example.g.dart +++ b/json_serializable/test/integration/create_per_field_to_json_example.g.dart @@ -49,8 +49,7 @@ Map<String, dynamic> _$ModelToJson(Model instance) => <String, dynamic>{ 'enumValue': _$EnumValueEnumMap[instance.enumValue], 'nested': instance.nested?.toJson(), 'nestedGeneric': instance.nestedGeneric?.toJson((value) => value), - if (instance.nestedExcludeIfNull?.toJson() case final value?) - 'nestedExcludeIfNull': value, + 'nestedExcludeIfNull': ?instance.nestedExcludeIfNull?.toJson(), }; const _$EnumValueEnumMap = {EnumValue.first: '1', EnumValue.second: 'second'}; diff --git a/json_serializable/test/integration/json_enum_example.g.dart b/json_serializable/test/integration/json_enum_example.g.dart index 3558c1a75..0cbe2616f 100644 --- a/json_serializable/test/integration/json_enum_example.g.dart +++ b/json_serializable/test/integration/json_enum_example.g.dart @@ -62,8 +62,7 @@ Issue1226Regression _$Issue1226RegressionFromJson(Map<String, dynamic> json) => Map<String, dynamic> _$Issue1226RegressionToJson( Issue1226Regression instance, ) => <String, dynamic>{ - if (_$Issue1145RegressionEnumEnumMap[instance.durationType] case final value?) - 'durationType': value, + 'durationType': ?_$Issue1145RegressionEnumEnumMap[instance.durationType], }; const _$StandAloneEnumEnumMap = { diff --git a/json_serializable/test/integration/json_test_example.g.dart b/json_serializable/test/integration/json_test_example.g.dart index cd32ac924..1f1b456ee 100644 --- a/json_serializable/test/integration/json_test_example.g.dart +++ b/json_serializable/test/integration/json_test_example.g.dart @@ -94,7 +94,7 @@ Order _$OrderFromJson(Map<String, dynamic> json) { } Map<String, dynamic> _$OrderToJson(Order instance) => <String, dynamic>{ - if (instance.count case final value?) 'count': value, + 'count': ?instance.count, 'isRushed': instance.isRushed, 'duration': instance.duration?.inMicroseconds, 'category': _$CategoryEnumMap[instance.category], @@ -125,7 +125,7 @@ Item _$ItemFromJson(Map<String, dynamic> json) => Map<String, dynamic> _$ItemToJson(Item instance) => <String, dynamic>{ 'price': instance.price, - if (instance.itemNumber case final value?) 'item-number': value, + 'item-number': ?instance.itemNumber, 'saleDates': instance.saleDates?.map((e) => e.toIso8601String()).toList(), 'rates': instance.rates, 'geoPoint': _toJsonGeoPoint(instance.geoPoint), diff --git a/json_serializable/test/integration/json_test_example.g_any_map.g.dart b/json_serializable/test/integration/json_test_example.g_any_map.g.dart index f277591ba..f25c7971e 100644 --- a/json_serializable/test/integration/json_test_example.g_any_map.g.dart +++ b/json_serializable/test/integration/json_test_example.g_any_map.g.dart @@ -96,7 +96,7 @@ Order _$OrderFromJson(Map json) { } Map<String, dynamic> _$OrderToJson(Order instance) => <String, dynamic>{ - if (instance.count case final value?) 'count': value, + 'count': ?instance.count, 'isRushed': instance.isRushed, 'duration': instance.duration?.inMicroseconds, 'category': _$CategoryEnumMap[instance.category], @@ -126,7 +126,7 @@ Item _$ItemFromJson(Map json) => Item((json['price'] as num?)?.toInt()) Map<String, dynamic> _$ItemToJson(Item instance) => <String, dynamic>{ 'price': instance.price, - if (instance.itemNumber case final value?) 'item-number': value, + 'item-number': ?instance.itemNumber, 'saleDates': instance.saleDates?.map((e) => e.toIso8601String()).toList(), 'rates': instance.rates, 'geoPoint': _toJsonGeoPoint(instance.geoPoint), diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart index 3ea352ae7..57ca82487 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart @@ -118,10 +118,10 @@ KitchenSink _$KitchenSinkFromJson(Map<String, dynamic> json) => Map<String, dynamic> _$KitchenSinkToJson( KitchenSink instance, ) => <String, dynamic>{ - if (instance.ctorValidatedNo42 case final value?) 'no-42': value, - if (instance.dateTime?.toIso8601String() case final value?) 'dateTime': value, - if (instance.bigInt?.toString() case final value?) 'bigInt': value, - if (instance.iterable?.toList() case final value?) 'iterable': value, + 'no-42': ?instance.ctorValidatedNo42, + 'dateTime': ?instance.dateTime?.toIso8601String(), + 'bigInt': ?instance.bigInt?.toString(), + 'iterable': ?instance.iterable?.toList(), 'dynamicIterable': instance.dynamicIterable.toList(), 'objectIterable': instance.objectIterable.toList(), 'intIterable': instance.intIterable.toList(), @@ -166,21 +166,18 @@ Map<String, dynamic> _$KitchenSinkToJson( ) .toList(), 'val': instance.val, - if (instance.writeNotNull case final value?) 'writeNotNull': value, - if (instance.string case final value?) r'$string': value, + 'writeNotNull': ?instance.writeNotNull, + r'$string': ?instance.string, 'simpleObject': instance.simpleObject, 'strictKeysObject': instance.strictKeysObject, - if (instance.validatedPropertyNo42 case final value?) - 'validatedPropertyNo42': value, - if (instance.recordField == null - ? null - : <String, dynamic>{ - r'$1': instance.recordField!.$1, - r'$2': instance.recordField!.$2, - 'truth': instance.recordField!.truth, - } - case final value?) - 'recordField': value, + 'validatedPropertyNo42': ?instance.validatedPropertyNo42, + 'recordField': ?instance.recordField == null + ? null + : <String, dynamic>{ + r'$1': instance.recordField!.$1, + r'$2': instance.recordField!.$2, + 'truth': instance.recordField!.truth, + }, }; $Rec? _$recordConvertNullable<$Rec>( @@ -240,9 +237,7 @@ JsonConverterTestClass _$JsonConverterTestClassFromJson( Map<String, dynamic> _$JsonConverterTestClassToJson( JsonConverterTestClass instance, ) => <String, dynamic>{ - if (const DurationMillisecondConverter().toJson(instance.duration) - case final value?) - 'duration': value, + 'duration': ?const DurationMillisecondConverter().toJson(instance.duration), 'durationList': instance.durationList .map(const DurationMillisecondConverter().toJson) .toList(), @@ -250,12 +245,10 @@ Map<String, dynamic> _$JsonConverterTestClassToJson( 'bigIntMap': instance.bigIntMap.map( (k, e) => MapEntry(k, const BigIntStringConverter().toJson(e)), ), - if (_$JsonConverterToJson<String, BigInt>( - instance.nullableBigInt, - const BigIntStringConverter().toJson, - ) - case final value?) - 'nullableBigInt': value, + 'nullableBigInt': ?_$JsonConverterToJson<String, BigInt>( + instance.nullableBigInt, + const BigIntStringConverter().toJson, + ), 'nullableBigIntMap': instance.nullableBigIntMap.map( (k, e) => MapEntry( k, @@ -265,23 +258,16 @@ Map<String, dynamic> _$JsonConverterTestClassToJson( ), ), ), - if (TrivialNumberConverter.instance.toJson(instance.numberSilly) - case final value?) - 'numberSilly': value, + 'numberSilly': ?TrivialNumberConverter.instance.toJson(instance.numberSilly), 'numberSillySet': instance.numberSillySet .map(TrivialNumberConverter.instance.toJson) .toList(), - if (const EpochDateTimeConverter().toJson(instance.dateTime) - case final value?) - 'dateTime': value, - if (trivialStringConverter.toJson(instance.trivialString) case final value?) - 'trivialString': value, - if (_$JsonConverterToJson<int?, TrivialNumber>( - instance.nullableNumberSilly, - TrivialNumberConverter.instance.toJson, - ) - case final value?) - 'nullableNumberSilly': value, + 'dateTime': ?const EpochDateTimeConverter().toJson(instance.dateTime), + 'trivialString': ?trivialStringConverter.toJson(instance.trivialString), + 'nullableNumberSilly': ?_$JsonConverterToJson<int?, TrivialNumber>( + instance.nullableNumberSilly, + TrivialNumberConverter.instance.toJson, + ), 'nullableNumberSillySet': instance.nullableNumberSillySet .map( (e) => _$JsonConverterToJson<int?, TrivialNumber>( diff --git a/json_serializable/test/src/_json_serializable_test_input.dart b/json_serializable/test/src/_json_serializable_test_input.dart index c7fbd5088..4db90e56f 100644 --- a/json_serializable/test/src/_json_serializable_test_input.dart +++ b/json_serializable/test/src/_json_serializable_test_input.dart @@ -199,10 +199,7 @@ class NoDeserializeBadKey { @ShouldGenerate(r''' Map<String, dynamic> _$IncludeIfNullOverrideToJson( IncludeIfNullOverride instance, -) => <String, dynamic>{ - 'number': instance.number, - if (instance.str case final value?) 'str': value, -}; +) => <String, dynamic>{'number': instance.number, 'str': ?instance.str}; ''') @JsonSerializable(createFactory: false, includeIfNull: false) class IncludeIfNullOverride { diff --git a/json_serializable/test/src/inheritance_test_input.dart b/json_serializable/test/src/inheritance_test_input.dart index 76caaed23..0aac74d82 100644 --- a/json_serializable/test/src/inheritance_test_input.dart +++ b/json_serializable/test/src/inheritance_test_input.dart @@ -13,8 +13,7 @@ SubType _$SubTypeFromJson(Map<String, dynamic> json) => Map<String, dynamic> _$SubTypeToJson(SubType instance) => <String, dynamic>{ 'super-final-field': instance.superFinalField, - if (instance.superReadWriteField case final value?) - 'superReadWriteField': value, + 'superReadWriteField': ?instance.superReadWriteField, 'subTypeViaCtor': instance.subTypeViaCtor, 'subTypeReadWrite': instance.subTypeReadWrite, }; @@ -51,8 +50,7 @@ Map<String, dynamic> _$SubTypeWithAnnotatedFieldOverrideExtendsToJson( SubTypeWithAnnotatedFieldOverrideExtends instance, ) => <String, dynamic>{ 'super-final-field': instance.superFinalField, - if (instance.superReadWriteField case final value?) - 'superReadWriteField': value, + 'superReadWriteField': ?instance.superReadWriteField, 'priceHalf': instance.priceHalf, }; ''') diff --git a/json_serializable/test/src/to_from_json_test_input.dart b/json_serializable/test/src/to_from_json_test_input.dart index d93db4188..f811d6a39 100644 --- a/json_serializable/test/src/to_from_json_test_input.dart +++ b/json_serializable/test/src/to_from_json_test_input.dart @@ -166,9 +166,7 @@ String? _toStringNullOnEmpty(String input) => input.isEmpty ? null : input; @ShouldGenerate(r''' Map<String, dynamic> _$ToJsonNullableFalseIncludeIfNullFalseToJson( ToJsonNullableFalseIncludeIfNullFalse instance, -) => <String, dynamic>{ - if (_toStringNullOnEmpty(instance.field) case final value?) 'field': value, -}; +) => <String, dynamic>{'field': ?_toStringNullOnEmpty(instance.field)}; ''') @JsonSerializable(createFactory: false) class ToJsonNullableFalseIncludeIfNullFalse { From d30c2fdb0598d548c25705931531842957623fdd Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Wed, 4 Jun 2025 19:40:16 -0500 Subject: [PATCH 561/569] checked_yaml: prepare release (#1500) Did some cleanup of the implementation so the control flow reads easier Added a missing test to handle the `null` case. --- checked_yaml/CHANGELOG.md | 2 +- checked_yaml/lib/checked_yaml.dart | 61 ++++++++++-------------- checked_yaml/pubspec.yaml | 2 +- checked_yaml/test/custom_error_test.dart | 33 ++++++++++++- 4 files changed, 59 insertions(+), 39 deletions(-) diff --git a/checked_yaml/CHANGELOG.md b/checked_yaml/CHANGELOG.md index a3b7dac72..567d14795 100644 --- a/checked_yaml/CHANGELOG.md +++ b/checked_yaml/CHANGELOG.md @@ -1,4 +1,4 @@ -## 2.0.4-wip +## 2.0.4 - Require Dart 3.8 diff --git a/checked_yaml/lib/checked_yaml.dart b/checked_yaml/lib/checked_yaml.dart index 17c5ce0c1..1b6ad05df 100644 --- a/checked_yaml/lib/checked_yaml.dart +++ b/checked_yaml/lib/checked_yaml.dart @@ -36,7 +36,6 @@ T checkedYamlDecode<T>( if (yaml is YamlMap) { map = yaml; } else if (allowNull && yaml is YamlScalar && yaml.value == null) { - // TODO: test this case! map = null; } else { throw ParsedYamlException('Not a map', yaml); @@ -73,34 +72,29 @@ ParsedYamlException toParsedYamlException( ) as YamlNode; return ParsedYamlException(exception.message!, node, innerError: exception); - } else { - if (exception.key == null) { - return ParsedYamlException( - exception.message ?? 'There was an error parsing the map.', - yamlMap, - innerError: exception, - ); - } else if (!yamlMap.containsKey(exception.key)) { - return ParsedYamlException( - [ - 'Missing key "${exception.key}".', - if (exception.message != null) exception.message!, - ].join(' '), - yamlMap, - innerError: exception, - ); - } else { - var message = 'Unsupported value for "${exception.key}".'; - if (exception.message != null) { - message = '$message ${exception.message}'; - } - return ParsedYamlException( - message, - yamlMap.nodes[exception.key] ?? yamlMap, - innerError: exception, - ); - } } + + if (exception.key == null) { + return ParsedYamlException( + exception.message ?? 'There was an error parsing the map.', + yamlMap, + innerError: exception, + ); + } + + if (!yamlMap.containsKey(exception.key)) { + return ParsedYamlException( + ['Missing key "${exception.key}".', ?exception.message].join(' '), + yamlMap, + innerError: exception, + ); + } + + return ParsedYamlException( + ['Unsupported value for "${exception.key}".', ?exception.message].join(' '), + yamlMap.nodes[exception.key] ?? yamlMap, + innerError: exception, + ); } /// An exception thrown when parsing YAML that contains information about the @@ -118,12 +112,10 @@ class ParsedYamlException implements Exception { /// contains the source error object. final Object? innerError; - ParsedYamlException(String message, YamlNode this.yamlNode, {this.innerError}) - : // TODO(kevmoo) remove when dart-lang/sdk#50756 is fixed! - message = message.replaceAll(" of ' in type cast'", ' in type cast'); + ParsedYamlException(this.message, YamlNode this.yamlNode, {this.innerError}); - factory ParsedYamlException.fromYamlException(YamlException exception) => - _WrappedYamlException(exception); + factory ParsedYamlException.fromYamlException(YamlException exception) = + _WrappedYamlException; /// Returns [message] formatted with source information provided by /// [yamlNode]. @@ -147,7 +139,4 @@ class _WrappedYamlException implements ParsedYamlException { @override YamlNode? get yamlNode => null; - - @override - String toString() => 'ParsedYamlException: $formattedMessage'; } diff --git a/checked_yaml/pubspec.yaml b/checked_yaml/pubspec.yaml index ada787451..6195805df 100644 --- a/checked_yaml/pubspec.yaml +++ b/checked_yaml/pubspec.yaml @@ -1,5 +1,5 @@ name: checked_yaml -version: 2.0.4-wip +version: 2.0.4 description: >- Generate more helpful exceptions when decoding YAML documents using diff --git a/checked_yaml/test/custom_error_test.dart b/checked_yaml/test/custom_error_test.dart index 6c17bda9d..b4d8826ca 100644 --- a/checked_yaml/test/custom_error_test.dart +++ b/checked_yaml/test/custom_error_test.dart @@ -4,7 +4,7 @@ import 'package:test/test.dart'; import 'package:yaml/yaml.dart'; void main() { - test('bob', () { + test('simple test', () { expect( () => checkedYamlDecode('{"innerMap": {}}', (m) { throw CheckedFromJsonException( @@ -36,4 +36,35 @@ line 1, column 14: There was an error parsing the map. ), ); }); + + test('null map - allowed', () { + expect( + () => checkedYamlDecode(allowNull: true, 'null', (m) => Object()), + isA<Object>(), + ); + }); + + test('null map - not allowed', () { + expect( + () => checkedYamlDecode('null', (m) { + throw TestFailure('should never get here!'); + }), + throwsA( + isA<ParsedYamlException>() + .having((e) => e.message, 'message', 'Not a map') + .having( + (e) => e.yamlNode, + 'yamlNode', + isA<YamlScalar>().having((s) => s.value, 'value', isNull), + ) + .having((e) => e.innerError, 'innerError', isNull) + .having((e) => e.formattedMessage, 'formattedMessage', ''' +line 1, column 1: Not a map + ╷ +1 │ null + │ ^^^^ + ╵'''), + ), + ); + }); } From a908779ae97ffef7533b320261b895c98284ea10 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Wed, 2 Jul 2025 13:06:27 -0700 Subject: [PATCH 562/569] Update test logic for validating warnings (#1506) pkg:build changed --- json_serializable/test/annotation_version_test.dart | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/json_serializable/test/annotation_version_test.dart b/json_serializable/test/annotation_version_test.dart index b15d89987..3bd7e989e 100644 --- a/json_serializable/test/annotation_version_test.dart +++ b/json_serializable/test/annotation_version_test.dart @@ -7,6 +7,7 @@ @Timeout.factor(2) library; +import 'dart:convert'; import 'dart:io'; import 'package:json_serializable/src/check_dependencies.dart'; @@ -189,7 +190,7 @@ class SomeClass{} final output = lines.toString(); final expectedWarningCount = message == null ? 0 : 1; - final warningCount = '[WARNING]'.allMatches(output).length; + final warningCount = _warningStartOfLine.allMatches(output).length; expect( warningCount, expectedWarningCount, @@ -202,10 +203,12 @@ class SomeClass{} expect( output, contains(''' -[WARNING] json_serializable on $sourceDirectory/sample.dart: -$message'''), +W json_serializable on $sourceDirectory/sample.dart: +${LineSplitter.split(message).map((line) => ' $line').join('\n')}'''), ); } await proc.shouldExit(0); } + +final _warningStartOfLine = RegExp(r'^W ', multiLine: true); From bc8fcb9a88b2fe45baaea8fda0c8122da91cca7e Mon Sep 17 00:00:00 2001 From: "Morgan :)" <davidmorgan@google.com> Date: Thu, 10 Jul 2025 19:49:48 +0200 Subject: [PATCH 563/569] Migrate to element2 APIs (#1504) * Prepare to publish 6.10.0-dev. --- json_serializable/CHANGELOG.md | 3 +- json_serializable/lib/src/decode_helper.dart | 65 ++++++++++--------- json_serializable/lib/src/encoder_helper.dart | 37 ++++++----- json_serializable/lib/src/enum_utils.dart | 22 +++---- json_serializable/lib/src/field_helpers.dart | 63 ++++++++---------- .../lib/src/generator_helper.dart | 27 ++++---- json_serializable/lib/src/helper_core.dart | 30 ++++----- .../lib/src/json_enum_generator.dart | 6 +- json_serializable/lib/src/json_key_utils.dart | 24 +++---- .../lib/src/json_literal_generator.dart | 6 +- .../lib/src/json_serializable_generator.dart | 6 +- json_serializable/lib/src/type_helper.dart | 6 +- .../lib/src/type_helper_ctx.dart | 29 +++++---- .../type_helpers/json_converter_helper.dart | 42 ++++++------ .../lib/src/type_helpers/json_helper.dart | 47 ++++++++------ json_serializable/lib/src/utils.dart | 64 +++++++++--------- json_serializable/pubspec.yaml | 8 +-- .../src/_json_serializable_test_input.dart | 4 +- .../test/src/json_converter_test_input.dart | 4 +- 19 files changed, 255 insertions(+), 238 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 43ab453da..34b778c9f 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,5 +1,6 @@ -## 6.9.6-wip +## 6.10.0-dev +- Switch to analyzer element2 model and `build: ^3.0.0-dev`. - Move `package:collection` to a dev dependency. - Use new `null-aware element` feature in generated code. - Require Dart 3.8 diff --git a/json_serializable/lib/src/decode_helper.dart b/json_serializable/lib/src/decode_helper.dart index 633935e7d..2668b4243 100644 --- a/json_serializable/lib/src/decode_helper.dart +++ b/json_serializable/lib/src/decode_helper.dart @@ -2,7 +2,7 @@ // 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:analyzer/dart/element/element.dart'; +import 'package:analyzer/dart/element/element2.dart'; import 'package:analyzer/dart/element/nullability_suffix.dart'; import 'package:build/build.dart'; import 'package:source_gen/source_gen.dart'; @@ -23,7 +23,7 @@ class CreateFactoryResult { mixin DecodeHelper implements HelperCore { CreateFactoryResult createFactory( - Map<String, FieldElement> accessibleFields, + Map<String, FieldElement2> accessibleFields, Map<String, String> unavailableReasons, ) { assert(config.createFactory); @@ -37,14 +37,14 @@ mixin DecodeHelper implements HelperCore { ); if (config.genericArgumentFactories) { - for (var arg in element.typeParameters) { + for (var arg in element.typeParameters2) { final helperName = fromJsonForType( arg.instantiate(nullabilitySuffix: NullabilitySuffix.none), ); - buffer.write(', ${arg.name} Function(Object? json) $helperName'); + buffer.write(', ${arg.name3} Function(Object? json) $helperName'); } - if (element.typeParameters.isNotEmpty) { + if (element.typeParameters2.isNotEmpty) { buffer.write(','); } } @@ -55,7 +55,7 @@ mixin DecodeHelper implements HelperCore { String deserializeFun( String paramOrFieldName, { - ParameterElement? ctorParam, + FormalParameterElement? ctorParam, }) => _deserializeForField( accessibleFields[paramOrFieldName]!, ctorParam: ctorParam, @@ -66,8 +66,15 @@ mixin DecodeHelper implements HelperCore { config.constructor, accessibleFields.keys, accessibleFields.values - .where((fe) => element.lookUpSetter(fe.name, element.library) != null) - .map((fe) => fe.name) + .where( + (fe) => + element.lookUpSetter2( + name: fe.name3!, + library: element.library2, + ) != + null, + ) + .map((fe) => fe.name3!) .toList(), unavailableReasons, deserializeFun, @@ -75,12 +82,12 @@ mixin DecodeHelper implements HelperCore { final checks = _checkKeys( accessibleFields.values.where( - (fe) => data.usedCtorParamsAndFields.contains(fe.name), + (fe) => data.usedCtorParamsAndFields.contains(fe.name3), ), ).toList(); if (config.checked) { - final classLiteral = escapeDartString(element.name); + final classLiteral = escapeDartString(element.name3!); final sectionBuffer = StringBuffer() ..write(''' @@ -163,11 +170,11 @@ mixin DecodeHelper implements HelperCore { return CreateFactoryResult(buffer.toString(), data.usedCtorParamsAndFields); } - Iterable<String> _checkKeys(Iterable<FieldElement> accessibleFields) sync* { + Iterable<String> _checkKeys(Iterable<FieldElement2> accessibleFields) sync* { final args = <String>[]; - String constantList(Iterable<FieldElement> things) => - 'const ${jsonLiteralAsDart(things.map(nameAccess).toList())}'; + String constantList(Iterable<FieldElement2> things) => + 'const ${jsonLiteralAsDart(things.map<String>(nameAccess).toList())}'; if (config.disallowUnrecognizedKeys) { final allowKeysLiteral = constantList(accessibleFields); @@ -201,8 +208,8 @@ mixin DecodeHelper implements HelperCore { /// If [checkedProperty] is `true`, we're using this function to write to a /// setter. String _deserializeForField( - FieldElement field, { - ParameterElement? ctorParam, + FieldElement2 field, { + FormalParameterElement? ctorParam, bool checkedProperty = false, }) { final jsonKeyName = safeNameAccess(field); @@ -246,7 +253,7 @@ mixin DecodeHelper implements HelperCore { if (defaultValue != null) { if (jsonKey.disallowNullValue && jsonKey.required) { log.warning( - 'The `defaultValue` on field `${field.name}` will have no ' + 'The `defaultValue` on field `${field.name3}` will have no ' 'effect because both `disallowNullValue` and `required` are set to ' '`true`.', ); @@ -267,30 +274,30 @@ mixin DecodeHelper implements HelperCore { /// [writableFields] are also populated, but only if they have not already /// been defined by a constructor parameter with the same name. _ConstructorData _writeConstructorInvocation( - ClassElement classElement, + ClassElement2 classElement, String constructorName, Iterable<String> availableConstructorParameters, Iterable<String> writableFields, Map<String, String> unavailableReasons, - String Function(String paramOrFieldName, {ParameterElement ctorParam}) + String Function(String paramOrFieldName, {FormalParameterElement ctorParam}) deserializeForField, ) { - final className = classElement.name; + final className = classElement.name3; final ctor = constructorByName(classElement, constructorName); final usedCtorParamsAndFields = <String>{}; - final constructorArguments = <ParameterElement>[]; - final namedConstructorArguments = <ParameterElement>[]; + final constructorArguments = <FormalParameterElement>[]; + final namedConstructorArguments = <FormalParameterElement>[]; - for (final arg in ctor.parameters) { - if (!availableConstructorParameters.contains(arg.name)) { + for (final arg in ctor.formalParameters) { + if (!availableConstructorParameters.contains(arg.name3)) { if (arg.isRequired) { var msg = 'Cannot populate the required constructor ' - 'argument: ${arg.name}.'; + 'argument: ${arg.name3}.'; - final additionalInfo = unavailableReasons[arg.name]; + final additionalInfo = unavailableReasons[arg.name3]; if (additionalInfo != null) { msg = '$msg $additionalInfo'; @@ -308,7 +315,7 @@ _ConstructorData _writeConstructorInvocation( } else { constructorArguments.add(arg); } - usedCtorParamsAndFields.add(arg.name); + usedCtorParamsAndFields.add(arg.name3!); } // fields that aren't already set by the constructor and that aren't final @@ -327,7 +334,7 @@ _ConstructorData _writeConstructorInvocation( ..writeAll( constructorArguments.map((paramElement) { final content = deserializeForField( - paramElement.name, + paramElement.name3!, ctorParam: paramElement, ); return ' $content,\n'; @@ -336,10 +343,10 @@ _ConstructorData _writeConstructorInvocation( ..writeAll( namedConstructorArguments.map((paramElement) { final value = deserializeForField( - paramElement.name, + paramElement.name3!, ctorParam: paramElement, ); - return ' ${paramElement.name}: $value,\n'; + return ' ${paramElement.name3!}: $value,\n'; }), ) ..write(')'); diff --git a/json_serializable/lib/src/encoder_helper.dart b/json_serializable/lib/src/encoder_helper.dart index 7effcd05e..6536cddda 100644 --- a/json_serializable/lib/src/encoder_helper.dart +++ b/json_serializable/lib/src/encoder_helper.dart @@ -2,7 +2,7 @@ // 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:analyzer/dart/element/element.dart'; +import 'package:analyzer/dart/element/element2.dart'; import 'package:analyzer/dart/element/nullability_suffix.dart'; import 'package:source_helper/source_helper.dart'; @@ -13,18 +13,21 @@ import 'type_helpers/json_converter_helper.dart'; import 'unsupported_type_error.dart'; mixin EncodeHelper implements HelperCore { - String _fieldAccess(FieldElement field) => '$_toJsonParamName.${field.name}'; + String _fieldAccess(FieldElement2 field) => + '$_toJsonParamName.${field.name3!}'; - String createPerFieldToJson(Set<FieldElement> accessibleFieldSet) { + String createPerFieldToJson(Set<FieldElement2> accessibleFieldSet) { final buffer = StringBuffer() ..writeln('// ignore: unused_element') - ..writeln('abstract class _\$${element.name.nonPrivate}PerFieldToJson {'); + ..writeln( + 'abstract class _\$${element.name3!.nonPrivate}PerFieldToJson {', + ); for (final field in accessibleFieldSet) { buffer ..writeln(' // ignore: unused_element') ..write( - 'static Object? ${field.name}' + 'static Object? ${field.name3!}' '${genericClassArgumentsImpl(withConstraints: true)}' '(${field.type} $_toJsonParamName', ); @@ -43,16 +46,16 @@ mixin EncodeHelper implements HelperCore { /// Generates an object containing metadatas related to the encoding, /// destined to be used by other code-generators. - String createFieldMap(Set<FieldElement> accessibleFieldSet) { + String createFieldMap(Set<FieldElement2> accessibleFieldSet) { assert(config.createFieldMap); final buffer = StringBuffer( - 'const _\$${element.name.nonPrivate}FieldMap = <String, String> {', + 'const _\$${element.name3!.nonPrivate}FieldMap = <String, String> {', ); for (final field in accessibleFieldSet) { buffer.writeln( - '${escapeDartString(field.name)}: ' + '${escapeDartString(field.name3!)}: ' '${escapeDartString(nameAccess(field))},', ); } @@ -64,17 +67,17 @@ mixin EncodeHelper implements HelperCore { /// Generates an object containing metadatas related to the encoding, /// destined to be used by other code-generators. - String createJsonKeys(Set<FieldElement> accessibleFieldSet) { + String createJsonKeys(Set<FieldElement2> accessibleFieldSet) { assert(config.createJsonKeys); final buffer = StringBuffer( - 'abstract final class _\$${element.name.nonPrivate}JsonKeys {', + 'abstract final class _\$${element.name3!.nonPrivate}JsonKeys {', ); // ..write('static const _\$${element.name.nonPrivate}JsonKeys();'); for (final field in accessibleFieldSet) { buffer.writeln( - 'static const String ${field.name} = ' + 'static const String ${field.name3} = ' '${escapeDartString(nameAccess(field))};', ); } @@ -84,7 +87,7 @@ mixin EncodeHelper implements HelperCore { return buffer.toString(); } - Iterable<String> createToJson(Set<FieldElement> accessibleFields) sync* { + Iterable<String> createToJson(Set<FieldElement2> accessibleFields) sync* { assert(config.createToJson); final buffer = StringBuffer(); @@ -120,20 +123,20 @@ mixin EncodeHelper implements HelperCore { } void _writeGenericArgumentFactories(StringBuffer buffer) { - for (var arg in element.typeParameters) { + for (var arg in element.typeParameters2) { final helperName = toJsonForType( arg.instantiate(nullabilitySuffix: NullabilitySuffix.none), ); - buffer.write(',Object? Function(${arg.name} value) $helperName'); + buffer.write(',Object? Function(${arg.name3} value) $helperName'); } - if (element.typeParameters.isNotEmpty) { + if (element.typeParameters2.isNotEmpty) { buffer.write(','); } } static const _toJsonParamName = 'instance'; - String _serializeField(FieldElement field, String accessExpression) { + String _serializeField(FieldElement2 field, String accessExpression) { try { return getHelperContext( field, @@ -146,7 +149,7 @@ mixin EncodeHelper implements HelperCore { /// Returns `true` if the field can be written to JSON 'naively' – meaning /// we can avoid checking for `null`. - bool _canWriteJsonWithoutNullCheck(FieldElement field) { + bool _canWriteJsonWithoutNullCheck(FieldElement2 field) { final jsonKey = jsonKeyFor(field); if (jsonKey.includeIfNull) { diff --git a/json_serializable/lib/src/enum_utils.dart b/json_serializable/lib/src/enum_utils.dart index 00f0cbc0f..c5d5d1b54 100644 --- a/json_serializable/lib/src/enum_utils.dart +++ b/json_serializable/lib/src/enum_utils.dart @@ -3,7 +3,7 @@ // BSD-style license that can be found in the LICENSE file. import 'package:analyzer/dart/constant/value.dart'; -import 'package:analyzer/dart/element/element.dart'; +import 'package:analyzer/dart/element/element2.dart'; import 'package:analyzer/dart/element/type.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:source_gen/source_gen.dart'; @@ -45,7 +45,7 @@ String? enumValueMapFromType( final items = enumMap.entries .map( (e) => - ' ${targetType.element!.name}.${e.key.name}: ' + ' ${targetType.element!.name}.${e.key.name3}: ' '${jsonLiteralAsDart(e.value)},', ) .join(); @@ -53,7 +53,7 @@ String? enumValueMapFromType( return 'const ${constMapName(targetType)} = {\n$items\n};'; } -Map<FieldElement, Object?>? _enumMap( +Map<FieldElement2, Object?>? _enumMap( DartType targetType, { bool nullWithNoAnnotation = false, }) { @@ -79,7 +79,7 @@ Map<FieldElement, Object?>? _enumMap( } Object? _generateEntry({ - required FieldElement field, + required FieldElement2 field, required JsonEnum jsonEnum, required DartType targetType, }) { @@ -92,12 +92,12 @@ Object? _generateEntry({ if (valueField != null) { // TODO: fieldRename is pointless here!!! At least log a warning! - final fieldElementType = field.type.element as EnumElement; + final fieldElementType = field.type.element3 as EnumElement2; - final e = fieldElementType.getField(valueField); + final e = fieldElementType.getField2(valueField); if (e == null && valueField == 'index') { - return fieldElementType.fields + return fieldElementType.fields2 .where((element) => element.isEnumConstant) .toList(growable: false) .indexOf(field); @@ -108,7 +108,7 @@ Object? _generateEntry({ '`JsonEnum.valueField` was set to "$valueField", but ' 'that is not a valid, instance field on ' '`${typeToCode(targetType)}`.', - element: targetType.element, + element: targetType.element3, ); } @@ -120,11 +120,11 @@ Object? _generateEntry({ throw InvalidGenerationSourceError( '`JsonEnum.valueField` was set to "$valueField", but ' 'that field does not have a type of String, int, or null.', - element: targetType.element, + element: targetType.element3, ); } } else { - return encodedFieldName(jsonEnum.fieldRename, field.name); + return encodedFieldName(jsonEnum.fieldRename, field.name3!); } } else { final reader = ConstantReader(annotation); @@ -136,7 +136,7 @@ Object? _generateEntry({ } else { final targetTypeCode = typeToCode(targetType); throw InvalidGenerationSourceError( - 'The `JsonValue` annotation on `$targetTypeCode.${field.name}` does ' + 'The `JsonValue` annotation on `$targetTypeCode.${field.name3}` does ' 'not have a value of type String, int, or null.', element: field, ); diff --git a/json_serializable/lib/src/field_helpers.dart b/json_serializable/lib/src/field_helpers.dart index bc9d6133f..4539c7e53 100644 --- a/json_serializable/lib/src/field_helpers.dart +++ b/json_serializable/lib/src/field_helpers.dart @@ -2,9 +2,7 @@ // 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:analyzer/dart/element/element.dart'; -import 'package:analyzer/src/dart/element/element.dart' // ignore: implementation_imports - show InterfaceElementImpl; +import 'package:analyzer/dart/element/element2.dart'; import 'package:analyzer/src/dart/element/inheritance_manager3.dart' // ignore: implementation_imports show InheritanceManager3; import 'package:source_gen/source_gen.dart'; @@ -12,15 +10,15 @@ import 'package:source_gen/source_gen.dart'; import 'utils.dart'; class _FieldSet implements Comparable<_FieldSet> { - final FieldElement field; - final FieldElement sortField; + final FieldElement2 field; + final FieldElement2 sortField; _FieldSet._(this.field, this.sortField) - : assert(field.name == sortField.name); + : assert(field.name3 == sortField.name3); - factory _FieldSet(FieldElement? classField, FieldElement? superField) { + factory _FieldSet(FieldElement2? classField, FieldElement2? superField) { // At least one of these will != null, perhaps both. - final fields = [classField, superField].whereType<FieldElement>().toList(); + final fields = [classField, superField].whereType<FieldElement2>().toList(); // Prefer the class field over the inherited field when sorting. final sortField = fields.first; @@ -38,69 +36,60 @@ class _FieldSet implements Comparable<_FieldSet> { @override int compareTo(_FieldSet other) => _sortByLocation(sortField, other.sortField); - static int _sortByLocation(FieldElement a, FieldElement b) { - final checkerA = TypeChecker.fromStatic( - (a.enclosingElement3 as InterfaceElement).thisType, - ); + static int _sortByLocation(FieldElement2 a, FieldElement2 b) { + final checkerA = TypeChecker.fromStatic(a.enclosingElement2.thisType); - if (!checkerA.isExactly(b.enclosingElement3)) { + if (!checkerA.isExactly(b.enclosingElement2)) { // in this case, you want to prioritize the enclosingElement that is more // "super". - if (checkerA.isAssignableFrom(b.enclosingElement3)) { + if (checkerA.isAssignableFrom(b.enclosingElement2)) { return -1; } - final checkerB = TypeChecker.fromStatic( - (b.enclosingElement3 as InterfaceElement).thisType, - ); + final checkerB = TypeChecker.fromStatic(b.enclosingElement2.thisType); - if (checkerB.isAssignableFrom(a.enclosingElement3)) { + if (checkerB.isAssignableFrom(a.enclosingElement2)) { return 1; } } /// Returns the offset of given field/property in its source file – with a /// preference for the getter if it's defined. - int offsetFor(FieldElement e) { + int offsetFor(FieldElement2 e) { if (e.isSynthetic) { - return (e.getter ?? e.setter)!.nameOffset; + return (e.getter2 ?? e.setter2)!.firstFragment.nameOffset2!; } - return e.nameOffset; + return e.firstFragment.nameOffset2!; } return offsetFor(a).compareTo(offsetFor(b)); } } -/// Returns a [List] of all instance [FieldElement] items for [element] and +/// Returns a [List] of all instance [FieldElement2] items for [element] and /// super classes, sorted first by their location in the inheritance hierarchy /// (super first) and then by their location in the source file. -List<FieldElement> createSortedFieldSet(ClassElement element) { +List<FieldElement2> createSortedFieldSet(ClassElement2 element) { // Get all of the fields that need to be assigned // TODO: support overriding the field set with an annotation option final elementInstanceFields = Map.fromEntries( - element.fields.where((e) => !e.isStatic).map((e) => MapEntry(e.name, e)), + element.fields2.where((e) => !e.isStatic).map((e) => MapEntry(e.name3, e)), ); - final inheritedFields = <String, FieldElement>{}; + final inheritedFields = <String, FieldElement2>{}; final manager = InheritanceManager3(); - for (final v - in manager - .getInheritedConcreteMap2(element as InterfaceElementImpl) - .values) { - assert(v is! FieldElement); - if (_dartCoreObjectChecker.isExactly(v.enclosingElement3)) { + for (final v in manager.getInheritedConcreteMap(element).values) { + assert(v is! FieldElement2); + if (_dartCoreObjectChecker.isExactly(v.enclosingElement2!)) { continue; } - if (v is PropertyAccessorElement && - (v as PropertyAccessorElement).isGetter) { - assert((v as PropertyAccessorElement).variable2 is FieldElement); - final variable = (v as PropertyAccessorElement).variable2 as FieldElement; - assert(!inheritedFields.containsKey(variable.name)); - inheritedFields[variable.name] = variable; + if (v is GetterElement) { + final variable = v.variable3 as FieldElement2; + assert(!inheritedFields.containsKey(variable.name3)); + inheritedFields[variable.name3!] = variable; } } diff --git a/json_serializable/lib/src/generator_helper.dart b/json_serializable/lib/src/generator_helper.dart index ef1bf16e0..ff5577472 100644 --- a/json_serializable/lib/src/generator_helper.dart +++ b/json_serializable/lib/src/generator_helper.dart @@ -2,7 +2,7 @@ // 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:analyzer/dart/element/element.dart'; +import 'package:analyzer/dart/element/element2.dart'; import 'package:build/build.dart'; import 'package:source_gen/source_gen.dart'; @@ -20,7 +20,7 @@ class GeneratorHelper extends HelperCore with EncodeHelper, DecodeHelper { GeneratorHelper( this._generator, - ClassElement element, + ClassElement2 element, ConstantReader annotation, ) : super( element, @@ -38,7 +38,7 @@ class GeneratorHelper extends HelperCore with EncodeHelper, DecodeHelper { Iterable<String> generate() sync* { assert(_addedMembers.isEmpty); - if (config.genericArgumentFactories && element.typeParameters.isEmpty) { + if (config.genericArgumentFactories && element.typeParameters2.isEmpty) { log.warning( 'The class `${element.displayName}` is annotated ' 'with `JsonSerializable` field `genericArgumentFactories: true`. ' @@ -55,23 +55,24 @@ class GeneratorHelper extends HelperCore with EncodeHelper, DecodeHelper { // these fields. final unavailableReasons = <String, String>{}; - final accessibleFields = sortedFields.fold<Map<String, FieldElement>>( - <String, FieldElement>{}, + final accessibleFields = sortedFields.fold<Map<String, FieldElement2>>( + <String, FieldElement2>{}, (map, field) { final jsonKey = jsonKeyFor(field); if (!field.isPublic && !jsonKey.explicitYesFromJson) { - unavailableReasons[field.name] = 'It is assigned to a private field.'; - } else if (field.getter == null) { - assert(field.setter != null); - unavailableReasons[field.name] = + unavailableReasons[field.name3!] = + 'It is assigned to a private field.'; + } else if (field.getter2 == null) { + assert(field.setter2 != null); + unavailableReasons[field.name3!] = 'Setter-only properties are not supported.'; - log.warning('Setters are ignored: ${element.name}.${field.name}'); + log.warning('Setters are ignored: ${element.name3!}.${field.name3!}'); } else if (jsonKey.explicitNoFromJson) { - unavailableReasons[field.name] = + unavailableReasons[field.name3!] = 'It is assigned to a field not meant to be used in fromJson.'; } else { - assert(!map.containsKey(field.name)); - map[field.name] = field; + assert(!map.containsKey(field.name3)); + map[field.name3!] = field; } return map; diff --git a/json_serializable/lib/src/helper_core.dart b/json_serializable/lib/src/helper_core.dart index 6e9e731ab..b30bc36e0 100644 --- a/json_serializable/lib/src/helper_core.dart +++ b/json_serializable/lib/src/helper_core.dart @@ -2,7 +2,7 @@ // 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:analyzer/dart/element/element.dart'; +import 'package:analyzer/dart/element/element2.dart'; import 'package:analyzer/dart/element/type.dart'; import 'package:meta/meta.dart'; import 'package:source_gen/source_gen.dart'; @@ -17,7 +17,7 @@ import 'unsupported_type_error.dart'; import 'utils.dart'; abstract class HelperCore { - final ClassElement element; + final ClassElement2 element; final ClassConfig config; HelperCore(this.element, this.config); @@ -28,17 +28,17 @@ abstract class HelperCore { @protected String get targetClassReference => - '${element.name}${genericClassArgumentsImpl(withConstraints: false)}'; + '${element.name3}${genericClassArgumentsImpl(withConstraints: false)}'; @protected - String nameAccess(FieldElement field) => jsonKeyFor(field).name; + String nameAccess(FieldElement2 field) => jsonKeyFor(field).name; @protected - String safeNameAccess(FieldElement field) => + String safeNameAccess(FieldElement2 field) => escapeDartString(nameAccess(field)); @protected - String get prefix => '_\$${element.name.nonPrivate}'; + String get prefix => '_\$${element.name3!.nonPrivate}'; /// Returns a [String] representing the type arguments that exist on /// [element]. @@ -49,19 +49,19 @@ abstract class HelperCore { genericClassArguments(element, withConstraints); @protected - KeyConfig jsonKeyFor(FieldElement field) => jsonKeyForField(field, config); + KeyConfig jsonKeyFor(FieldElement2 field) => jsonKeyForField(field, config); @protected - TypeHelperCtx getHelperContext(FieldElement field) => + TypeHelperCtx getHelperContext(FieldElement2 field) => typeHelperContext(this, field); } InvalidGenerationSourceError createInvalidGenerationError( String targetMember, - FieldElement field, + FieldElement2 field, UnsupportedTypeError error, ) { - var message = 'Could not generate `$targetMember` code for `${field.name}`'; + var message = 'Could not generate `$targetMember` code for `${field.name3!}`'; String? todo; if (error.type is TypeParameterType) { @@ -114,17 +114,17 @@ $converterOrKeyInstructions'''; /// ``` /// "<T as num, S>" /// ``` -String genericClassArguments(ClassElement element, bool? withConstraints) { - if (withConstraints == null || element.typeParameters.isEmpty) { +String genericClassArguments(ClassElement2 element, bool? withConstraints) { + if (withConstraints == null || element.typeParameters2.isEmpty) { return ''; } - final values = element.typeParameters + final values = element.typeParameters2 .map((t) { if (withConstraints && t.bound != null) { final boundCode = typeToCode(t.bound!); - return '${t.name} extends $boundCode'; + return '${t.name3!} extends $boundCode'; } else { - return t.name; + return t.name3!; } }) .join(', '); diff --git a/json_serializable/lib/src/json_enum_generator.dart b/json_serializable/lib/src/json_enum_generator.dart index 17fe4bd8b..2c6fb3530 100644 --- a/json_serializable/lib/src/json_enum_generator.dart +++ b/json_serializable/lib/src/json_enum_generator.dart @@ -2,7 +2,7 @@ // 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:analyzer/dart/element/element.dart'; +import 'package:analyzer/dart/element/element2.dart'; import 'package:build/build.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:source_gen/source_gen.dart'; @@ -14,11 +14,11 @@ class JsonEnumGenerator extends GeneratorForAnnotation<JsonEnum> { @override List<String> generateForAnnotatedElement( - Element element, + Element2 element, ConstantReader annotation, BuildStep buildStep, ) { - if (element is! EnumElement) { + if (element is! EnumElement2) { throw InvalidGenerationSourceError( '`@JsonEnum` can only be used on enum elements.', element: element, diff --git a/json_serializable/lib/src/json_key_utils.dart b/json_serializable/lib/src/json_key_utils.dart index a17e45666..4ab7742be 100644 --- a/json_serializable/lib/src/json_key_utils.dart +++ b/json_serializable/lib/src/json_key_utils.dart @@ -3,7 +3,7 @@ // BSD-style license that can be found in the LICENSE file. import 'package:analyzer/dart/constant/value.dart'; -import 'package:analyzer/dart/element/element.dart'; +import 'package:analyzer/dart/element/element2.dart'; import 'package:analyzer/dart/element/type.dart'; import 'package:build/build.dart'; import 'package:json_annotation/json_annotation.dart'; @@ -17,19 +17,19 @@ import 'utils.dart'; final _jsonKeyExpando = Expando<Map<ClassConfig, KeyConfig>>(); -KeyConfig jsonKeyForField(FieldElement field, ClassConfig classAnnotation) => +KeyConfig jsonKeyForField(FieldElement2 field, ClassConfig classAnnotation) => (_jsonKeyExpando[field] ??= Map.identity())[classAnnotation] ??= _from( field, classAnnotation, ); -KeyConfig _from(FieldElement element, ClassConfig classAnnotation) { +KeyConfig _from(FieldElement2 element, ClassConfig classAnnotation) { // If an annotation exists on `element` the source is a 'real' field. // If the result is `null`, check the getter – it is a property. // TODO: setters: github.com/google/json_serializable.dart/issues/24 final obj = jsonKeyAnnotation(element); - final ctorParamDefault = classAnnotation.ctorParamDefaults[element.name]; + final ctorParamDefault = classAnnotation.ctorParamDefaults[element.name3]; if (obj.isNull) { return _populateJsonKey( @@ -136,10 +136,10 @@ KeyConfig _from(FieldElement element, ClassConfig classAnnotation) { // the generated code will be invalid, so skipping until we're bored // later - final functionValue = objectValue.toFunctionValue()!; + final functionValue = objectValue.toFunctionValue2()!; final invokeConst = - functionValue is ConstructorElement && functionValue.isConst + functionValue is ConstructorElement2 && functionValue.isConst ? 'const ' : ''; @@ -185,7 +185,7 @@ KeyConfig _from(FieldElement element, ClassConfig classAnnotation) { } final enumValueNames = enumFields - .map((p) => p.name) + .map((p) => p.name3!) .toList(growable: false); final enumValueName = enumValueForDartObject<String>( @@ -214,12 +214,12 @@ KeyConfig _from(FieldElement element, ClassConfig classAnnotation) { if (defaultValue != null && ctorParamDefault != null) { if (defaultValue == ctorParamDefault) { log.info( - 'The default value `$defaultValue` for `${element.name}` is defined ' + 'The default value `$defaultValue` for `${element.name3!}` is defined ' 'twice in the constructor and in the `JsonKey.defaultValue`.', ); } else { log.warning( - 'The constructor parameter for `${element.name}` has a default value ' + 'The constructor parameter for `${element.name3!}` has a default value ' '`$ctorParamDefault`, but the `JsonKey.defaultValue` value ' '`$defaultValue` will be used for missing or `null` values in JSON ' 'decoding.', @@ -231,7 +231,7 @@ KeyConfig _from(FieldElement element, ClassConfig classAnnotation) { final readValue = obj.read('readValue'); if (!readValue.isNull) { readValueFunctionName = readValue.objectValue - .toFunctionValue()! + .toFunctionValue2()! .qualifiedName; } @@ -278,7 +278,7 @@ KeyConfig _from(FieldElement element, ClassConfig classAnnotation) { KeyConfig _populateJsonKey( ClassConfig classAnnotation, - FieldElement element, { + FieldElement2 element, { required String? defaultValue, bool? disallowNullValue, bool? includeIfNull, @@ -307,7 +307,7 @@ KeyConfig _populateJsonKey( disallowNullValue, classAnnotation.includeIfNull, ), - name: name ?? encodedFieldName(classAnnotation.fieldRename, element.name), + name: name ?? encodedFieldName(classAnnotation.fieldRename, element.name3!), readValueFunctionName: readValueFunctionName, required: required ?? false, unknownEnumValue: unknownEnumValue, diff --git a/json_serializable/lib/src/json_literal_generator.dart b/json_serializable/lib/src/json_literal_generator.dart index 87f0acc08..9ce34d13a 100644 --- a/json_serializable/lib/src/json_literal_generator.dart +++ b/json_serializable/lib/src/json_literal_generator.dart @@ -5,7 +5,7 @@ import 'dart:async'; import 'dart:convert'; -import 'package:analyzer/dart/element/element.dart'; +import 'package:analyzer/dart/element/element2.dart'; import 'package:build/build.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:path/path.dart' as p; @@ -17,7 +17,7 @@ class JsonLiteralGenerator extends GeneratorForAnnotation<JsonLiteral> { @override Future<String> generateForAnnotatedElement( - Element element, + Element2 element, ConstantReader annotation, BuildStep buildStep, ) async { @@ -39,7 +39,7 @@ class JsonLiteralGenerator extends GeneratorForAnnotation<JsonLiteral> { final thing = jsonLiteralAsDart(content).toString(); final marked = asConst ? 'const' : 'final'; - return '$marked _\$${element.name}JsonLiteral = $thing;'; + return '$marked _\$${element.name3}JsonLiteral = $thing;'; } } diff --git a/json_serializable/lib/src/json_serializable_generator.dart b/json_serializable/lib/src/json_serializable_generator.dart index c69e86796..32b2796b3 100644 --- a/json_serializable/lib/src/json_serializable_generator.dart +++ b/json_serializable/lib/src/json_serializable_generator.dart @@ -2,7 +2,7 @@ // 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:analyzer/dart/element/element.dart'; +import 'package:analyzer/dart/element/element2.dart'; import 'package:build/build.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:source_gen/source_gen.dart'; @@ -54,11 +54,11 @@ class JsonSerializableGenerator @override Iterable<String> generateForAnnotatedElement( - Element element, + Element2 element, ConstantReader annotation, BuildStep buildStep, ) { - if (element is! ClassElement || element is EnumElement) { + if (element is! ClassElement2 || element is EnumElement2) { throw InvalidGenerationSourceError( '`@JsonSerializable` can only be used on classes.', element: element, diff --git a/json_serializable/lib/src/type_helper.dart b/json_serializable/lib/src/type_helper.dart index 01add6bcf..868f3d9c5 100644 --- a/json_serializable/lib/src/type_helper.dart +++ b/json_serializable/lib/src/type_helper.dart @@ -2,7 +2,7 @@ // 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:analyzer/dart/element/element.dart'; +import 'package:analyzer/dart/element/element2.dart'; import 'package:analyzer/dart/element/type.dart'; import 'type_helpers/config_types.dart'; @@ -11,10 +11,10 @@ import 'type_helpers/config_types.dart'; /// [TypeHelper.deserialize]. abstract class TypeHelperContext { /// The annotated class that code is being generated for. - ClassElement get classElement; + ClassElement2 get classElement; /// The field that code is being generated for. - FieldElement get fieldElement; + FieldElement2 get fieldElement; /// [expression] may be just the name of the field or it may an expression /// representing the serialization of a value. diff --git a/json_serializable/lib/src/type_helper_ctx.dart b/json_serializable/lib/src/type_helper_ctx.dart index f6d355b15..f1433e05e 100644 --- a/json_serializable/lib/src/type_helper_ctx.dart +++ b/json_serializable/lib/src/type_helper_ctx.dart @@ -3,7 +3,7 @@ // BSD-style license that can be found in the LICENSE file. import 'package:analyzer/dart/constant/value.dart'; -import 'package:analyzer/dart/element/element.dart'; +import 'package:analyzer/dart/element/element2.dart'; import 'package:analyzer/dart/element/type.dart'; import 'package:source_helper/source_helper.dart'; @@ -17,7 +17,7 @@ import 'utils.dart'; TypeHelperCtx typeHelperContext( HelperCore helperCore, - FieldElement fieldElement, + FieldElement2 fieldElement, ) => TypeHelperCtx._(helperCore, fieldElement); class TypeHelperCtx @@ -25,10 +25,10 @@ class TypeHelperCtx final HelperCore _helperCore; @override - final FieldElement fieldElement; + final FieldElement2 fieldElement; @override - ClassElement get classElement => _helperCore.element; + ClassElement2 get classElement => _helperCore.element; @override ClassConfig get config => _helperCore.config; @@ -97,7 +97,7 @@ class _ConvertPair { _ConvertPair._(this.fromJson, this.toJson); - factory _ConvertPair(FieldElement element) { + factory _ConvertPair(FieldElement2 element) { var pair = _expando[element]; if (pair == null) { @@ -115,7 +115,7 @@ class _ConvertPair { } } -ConvertData? _convertData(DartObject obj, FieldElement element, bool isFrom) { +ConvertData? _convertData(DartObject obj, FieldElement2 element, bool isFrom) { final paramName = isFrom ? 'fromJson' : 'toJson'; final objectValue = obj.getField(paramName); @@ -123,20 +123,21 @@ ConvertData? _convertData(DartObject obj, FieldElement element, bool isFrom) { return null; } - final executableElement = objectValue.toFunctionValue()!; + final executableElement = objectValue.toFunctionValue2()!; - if (executableElement.parameters.isEmpty || - executableElement.parameters.first.isNamed || - executableElement.parameters.where((pe) => !pe.isOptional).length > 1) { + if (executableElement.formalParameters.isEmpty || + executableElement.formalParameters.first.isNamed || + executableElement.formalParameters.where((pe) => !pe.isOptional).length > + 1) { throwUnsupported( element, - 'The `$paramName` function `${executableElement.name}` must have one ' + 'The `$paramName` function `${executableElement.name3}` must have one ' 'positional parameter.', ); } final returnType = executableElement.returnType; - final argType = executableElement.parameters.first.type; + final argType = executableElement.formalParameters.first.type; if (isFrom) { final hasDefaultValue = !jsonKeyAnnotation( element, @@ -155,7 +156,7 @@ ConvertData? _convertData(DartObject obj, FieldElement element, bool isFrom) { final elementTypeCode = typeToCode(element.type); throwUnsupported( element, - 'The `$paramName` function `${executableElement.name}` return type ' + 'The `$paramName` function `${executableElement.name3}` return type ' '`$returnTypeCode` is not compatible with field type ' '`$elementTypeCode`.', ); @@ -171,7 +172,7 @@ ConvertData? _convertData(DartObject obj, FieldElement element, bool isFrom) { final elementTypeCode = typeToCode(element.type); throwUnsupported( element, - 'The `$paramName` function `${executableElement.name}` argument type ' + 'The `$paramName` function `${executableElement.name3}` argument type ' '`$argTypeCode` is not compatible with field type' ' `$elementTypeCode`.', ); diff --git a/json_serializable/lib/src/type_helpers/json_converter_helper.dart b/json_serializable/lib/src/type_helpers/json_converter_helper.dart index 778ffeeae..dc8a5c2ac 100644 --- a/json_serializable/lib/src/type_helpers/json_converter_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_converter_helper.dart @@ -3,7 +3,7 @@ // BSD-style license that can be found in the LICENSE file. import 'package:analyzer/dart/constant/value.dart'; -import 'package:analyzer/dart/element/element.dart'; +import 'package:analyzer/dart/element/element2.dart'; import 'package:analyzer/dart/element/type.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:source_gen/source_gen.dart'; @@ -171,15 +171,19 @@ _JsonConvertData? _typeConverter( .whereType<_ConverterMatch>() .toList(); - var matchingAnnotations = converterMatches(ctx.fieldElement.metadata); + var matchingAnnotations = converterMatches( + ctx.fieldElement.getter2?.metadata2.annotations ?? [], + ); if (matchingAnnotations.isEmpty) { matchingAnnotations = converterMatches( - ctx.fieldElement.getter?.metadata ?? [], + ctx.fieldElement.metadata2.annotations, ); if (matchingAnnotations.isEmpty) { - matchingAnnotations = converterMatches(ctx.classElement.metadata); + matchingAnnotations = converterMatches( + ctx.classElement.metadata2.annotations, + ); if (matchingAnnotations.isEmpty) { matchingAnnotations = ctx.config.converters @@ -205,20 +209,20 @@ _JsonConvertData? _typeConverterFrom( final targetTypeCode = typeToCode(targetType); throw InvalidGenerationSourceError( 'Found more than one matching converter for `$targetTypeCode`.', - element: matchingAnnotations[1].elementAnnotation?.element, + element: matchingAnnotations[1].elementAnnotation?.element2, ); } final match = matchingAnnotations.single; - final annotationElement = match.elementAnnotation?.element; - if (annotationElement is PropertyAccessorElement) { - final enclosing = annotationElement.enclosingElement3; + final annotationElement = match.elementAnnotation?.element2; + if (annotationElement is PropertyAccessorElement2) { + final enclosing = annotationElement.enclosingElement2; - var accessString = annotationElement.name; + var accessString = annotationElement.name3!; - if (enclosing is ClassElement) { - accessString = '${enclosing.name}.$accessString'; + if (enclosing is ClassElement2) { + accessString = '${enclosing.name3}.$accessString'; } return _JsonConvertData.propertyAccess( @@ -234,7 +238,7 @@ _JsonConvertData? _typeConverterFrom( reviver.positionalArguments.isNotEmpty) { throw InvalidGenerationSourceError( 'Generators with constructor arguments are not supported.', - element: match.elementAnnotation?.element, + element: match.elementAnnotation?.element2, ); } @@ -277,10 +281,10 @@ _ConverterMatch? _compatibleMatch( ElementAnnotation? annotation, DartObject constantValue, ) { - final converterClassElement = constantValue.type!.element as ClassElement; + final converterClassElement = constantValue.type!.element3 as ClassElement2; final jsonConverterSuper = converterClassElement.allSupertypes - .where((e) => _jsonConverterChecker.isExactly(e.element)) + .where((e) => _jsonConverterChecker.isExactly(e.element3)) .singleOrNull; if (jsonConverterSuper == null) { @@ -304,13 +308,13 @@ _ConverterMatch? _compatibleMatch( } if (fieldType is TypeParameterType && targetType is TypeParameterType) { - assert(annotation?.element is! PropertyAccessorElement); - assert(converterClassElement.typeParameters.isNotEmpty); - if (converterClassElement.typeParameters.length > 1) { + assert(annotation?.element is! PropertyAccessorElement2); + assert(converterClassElement.typeParameters2.isNotEmpty); + if (converterClassElement.typeParameters2.length > 1) { throw InvalidGenerationSourceError( '`JsonConverter` implementations can have no more than one type ' - 'argument. `${converterClassElement.name}` has ' - '${converterClassElement.typeParameters.length}.', + 'argument. `${converterClassElement.name3}` has ' + '${converterClassElement.typeParameters2.length}.', element: converterClassElement, ); } diff --git a/json_serializable/lib/src/type_helpers/json_helper.dart b/json_serializable/lib/src/type_helpers/json_helper.dart index c2121ac80..4b9b2621b 100644 --- a/json_serializable/lib/src/type_helpers/json_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_helper.dart @@ -2,7 +2,8 @@ // 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:analyzer/dart/element/element.dart'; +// import 'package:analyzer/dart/ast/ast.dart'; +import 'package:analyzer/dart/element/element2.dart'; import 'package:analyzer/dart/element/type.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:source_gen/source_gen.dart'; @@ -42,16 +43,18 @@ class JsonHelper extends TypeHelper<TypeHelperContextWithConfig> { var toJson = _toJsonMethod(interfaceType); if (toJson != null) { - // Using the `declaration` here so we get the original definition – + // Using the `baseElement` here so we get the original definition – // and not one with the generics already populated. - toJson = toJson.declaration; + toJson = toJson.baseElement; toJsonArgs.addAll( _helperParams( context.serialize, _encodeHelper, interfaceType, - toJson.parameters.where((element) => element.isRequiredPositional), + toJson.formalParameters.where( + (element) => element.isRequiredPositional, + ), toJson, ), ); @@ -75,15 +78,15 @@ class JsonHelper extends TypeHelper<TypeHelperContextWithConfig> { return null; } - final classElement = targetType.element; + final classElement = targetType.element3; - final fromJsonCtor = classElement.constructors - .where((ce) => ce.name == 'fromJson') + final fromJsonCtor = classElement.constructors2 + .where((ce) => ce.name3 == 'fromJson') .singleOrNull; var output = expression; if (fromJsonCtor != null) { - final positionalParams = fromJsonCtor.parameters + final positionalParams = fromJsonCtor.formalParameters .where((element) => element.isPositional) .toList(); @@ -141,10 +144,10 @@ class JsonHelper extends TypeHelper<TypeHelperContextWithConfig> { List<String> _helperParams( Object? Function(DartType, String) execute, - TypeParameterType Function(ParameterElement, Element) paramMapper, + TypeParameterType Function(FormalParameterElement, Element2) paramMapper, InterfaceType type, - Iterable<ParameterElement> positionalParams, - Element targetElement, + Iterable<FormalParameterElement> positionalParams, + Element2 targetElement, ) { final rest = <TypeParameterType>[]; for (var param in positionalParams) { @@ -167,7 +170,10 @@ List<String> _helperParams( return args; } -TypeParameterType _decodeHelper(ParameterElement param, Element targetElement) { +TypeParameterType _decodeHelper( + FormalParameterElement param, + Element2 targetElement, +) { final type = param.type; if (type is FunctionType && @@ -175,7 +181,7 @@ TypeParameterType _decodeHelper(ParameterElement param, Element targetElement) { type.normalParameterTypes.length == 1) { final funcReturnType = type.returnType; - if (param.name == fromJsonForName(funcReturnType.element!.name!)) { + if (param.name3 == fromJsonForName(funcReturnType.element!.name!)) { final funcParamType = type.normalParameterTypes.single; if ((funcParamType.isDartCoreObject && funcParamType.isNullableType) || @@ -195,7 +201,10 @@ TypeParameterType _decodeHelper(ParameterElement param, Element targetElement) { ); } -TypeParameterType _encodeHelper(ParameterElement param, Element targetElement) { +TypeParameterType _encodeHelper( + FormalParameterElement param, + Element2 targetElement, +) { final type = param.type; if (type is FunctionType && @@ -203,7 +212,7 @@ TypeParameterType _encodeHelper(ParameterElement param, Element targetElement) { type.normalParameterTypes.length == 1) { final funcParamType = type.normalParameterTypes.single; - if (param.name == toJsonForName(funcParamType.element!.name!)) { + if (param.name3 == toJsonForName(funcParamType.element!.name!)) { if (funcParamType is TypeParameterType) { return funcParamType; } @@ -272,7 +281,7 @@ ClassConfig? _annotation(ClassConfig config, InterfaceType source) { } final annotations = const TypeChecker.fromRuntime( JsonSerializable, - ).annotationsOfExact(source.element, throwOnUnresolved: false).toList(); + ).annotationsOfExact(source.element3, throwOnUnresolved: false).toList(); if (annotations.isEmpty) { return null; @@ -281,11 +290,11 @@ ClassConfig? _annotation(ClassConfig config, InterfaceType source) { return mergeConfig( config, ConstantReader(annotations.single), - classElement: source.element as ClassElement, + classElement: source.element3 as ClassElement2, ); } -MethodElement? _toJsonMethod(DartType type) => type.typeImplementations - .map((dt) => dt is InterfaceType ? dt.getMethod('toJson') : null) +MethodElement2? _toJsonMethod(DartType type) => type.typeImplementations + .map((dt) => dt is InterfaceType ? dt.getMethod2('toJson') : null) .where((me) => me != null) .firstOrNull; diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index 9f1d34bc7..42dffb9bf 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -4,6 +4,7 @@ import 'package:analyzer/dart/constant/value.dart'; import 'package:analyzer/dart/element/element.dart'; +import 'package:analyzer/dart/element/element2.dart'; import 'package:analyzer/dart/element/type.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:source_gen/source_gen.dart'; @@ -14,22 +15,22 @@ import 'type_helpers/config_types.dart'; const _jsonKeyChecker = TypeChecker.fromRuntime(JsonKey); -DartObject? _jsonKeyAnnotation(FieldElement element) => +DartObject? _jsonKeyAnnotation(FieldElement2 element) => _jsonKeyChecker.firstAnnotationOf(element) ?? - (element.getter == null + (element.getter2 == null ? null - : _jsonKeyChecker.firstAnnotationOf(element.getter!)); + : _jsonKeyChecker.firstAnnotationOf(element.getter2!)); -ConstantReader jsonKeyAnnotation(FieldElement element) => +ConstantReader jsonKeyAnnotation(FieldElement2 element) => ConstantReader(_jsonKeyAnnotation(element)); /// Returns `true` if [element] is annotated with [JsonKey]. -bool hasJsonKeyAnnotation(FieldElement element) => +bool hasJsonKeyAnnotation(FieldElement2 element) => _jsonKeyAnnotation(element) != null; -Never throwUnsupported(FieldElement element, String message) => +Never throwUnsupported(FieldElement2 element, String message) => throw InvalidGenerationSourceError( - 'Error with `@JsonKey` on the `${element.name}` field. $message', + 'Error with `@JsonKey` on the `${element.name3}` field. $message', element: element, ); @@ -79,7 +80,7 @@ JsonSerializable _valueForAnnotation(ConstantReader reader) => JsonSerializable( ClassConfig mergeConfig( ClassConfig config, ConstantReader reader, { - required ClassElement classElement, + required ClassElement2 classElement, }) { final annotation = _valueForAnnotation(reader); assert(config.ctorParamDefaults.isEmpty); @@ -93,9 +94,9 @@ ClassConfig mergeConfig( final paramDefaultValueMap = constructorInstance == null ? <String, String>{} : Map<String, String>.fromEntries( - constructorInstance.parameters + constructorInstance.formalParameters .where((element) => element.hasDefaultValue) - .map((e) => MapEntry(e.name, e.defaultValueCode!)), + .map((e) => MapEntry(e.name3!, e.defaultValueCode!)), ); final converters = reader.read('converters'); @@ -116,7 +117,7 @@ ClassConfig mergeConfig( fieldRename: annotation.fieldRename ?? config.fieldRename, genericArgumentFactories: annotation.genericArgumentFactories ?? - (classElement.typeParameters.isNotEmpty && + (classElement.typeParameters2.isNotEmpty && config.genericArgumentFactories), ignoreUnannotated: annotation.ignoreUnannotated ?? config.ignoreUnannotated, includeIfNull: annotation.includeIfNull ?? config.includeIfNull, @@ -125,8 +126,8 @@ ClassConfig mergeConfig( ); } -ConstructorElement? _constructorByNameOrNull( - ClassElement classElement, +ConstructorElement2? _constructorByNameOrNull( + ClassElement2 classElement, String name, ) { try { @@ -136,12 +137,12 @@ ConstructorElement? _constructorByNameOrNull( } } -ConstructorElement constructorByName(ClassElement classElement, String name) { - final className = classElement.name; +ConstructorElement2 constructorByName(ClassElement2 classElement, String name) { + final className = classElement.name3; - ConstructorElement? ctor; + ConstructorElement2? ctor; if (name.isEmpty) { - ctor = classElement.unnamedConstructor; + ctor = classElement.unnamedConstructor2; if (ctor == null) { throw InvalidGenerationSourceError( 'The class `$className` has no default constructor.', @@ -149,7 +150,7 @@ ConstructorElement constructorByName(ClassElement classElement, String name) { ); } } else { - ctor = classElement.getNamedConstructor(name); + ctor = classElement.getNamedConstructor2(name); if (ctor == null) { throw InvalidGenerationSourceError( 'The class `$className` does not have a constructor with the name ' @@ -166,9 +167,10 @@ ConstructorElement constructorByName(ClassElement classElement, String name) { /// with its values. /// /// Otherwise, `null`. -Iterable<FieldElement>? iterateEnumFields(DartType targetType) { - if (targetType is InterfaceType && targetType.element is EnumElement) { - return targetType.element.fields.where((element) => element.isEnumConstant); +Iterable<FieldElement2>? iterateEnumFields(DartType targetType) { + if ( /*targetType is InterfaceType && */ targetType.element3 + is EnumElement2) { + return (targetType.element3 as EnumElement2).constants2; } return null; } @@ -247,24 +249,24 @@ String? defaultDecodeLogic( return null; } -extension ExecutableElementExtension on ExecutableElement { +extension ExecutableElementExtension on ExecutableElement2 { /// Returns the name of `this` qualified with the class name if it's a /// [MethodElement]. String get qualifiedName { - if (this is FunctionElement) { - return name; + if (this is TopLevelFunctionElement) { + return name3!; } - if (this is MethodElement) { - return '${enclosingElement3.name}.$name'; + if (this is MethodElement2) { + return '${enclosingElement2!.name3!}.${name3!}'; } - if (this is ConstructorElement) { - // Ignore the default constructor. - if (name.isEmpty) { - return '${enclosingElement3.name}'; + if (this is ConstructorElement2) { + // The default constructor. + if (name3 == 'new') { + return enclosingElement2!.name3!; } - return '${enclosingElement3.name}.$name'; + return '${enclosingElement2!.name3!}.${name3!}'; } throw UnsupportedError('Not sure how to support typeof $runtimeType'); diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index ec6022f17..c32d46ee8 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 6.9.6-wip +version: 6.10.0-dev description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. @@ -17,7 +17,7 @@ resolution: workspace dependencies: analyzer: '>=6.9.0 <8.0.0' async: ^2.10.0 - build: ^2.4.1 + build: ^3.0.0-dev build_config: ^1.1.0 dart_style: '>=2.3.7 <4.0.0' @@ -28,7 +28,7 @@ dependencies: path: ^1.9.0 pub_semver: ^2.1.4 pubspec_parse: ^1.0.0 - source_gen: ^2.0.0 + source_gen: ^3.0.0-dev source_helper: ^1.3.4 dev_dependencies: @@ -38,7 +38,7 @@ dev_dependencies: build_verify: ^3.0.0 collection: ^1.17.0 logging: ^1.0.0 - source_gen_test: ^1.0.6 + source_gen_test: ^1.3.0-dev test: ^1.24.4 test_descriptor: ^2.0.0 test_process: ^2.0.0 diff --git a/json_serializable/test/src/_json_serializable_test_input.dart b/json_serializable/test/src/_json_serializable_test_input.dart index 4db90e56f..09deed525 100644 --- a/json_serializable/test/src/_json_serializable_test_input.dart +++ b/json_serializable/test/src/_json_serializable_test_input.dart @@ -277,7 +277,7 @@ class IgnoredFieldClass { @ShouldThrow( 'Cannot populate the required constructor argument: ignoredTrueField. It is ' 'assigned to a field not meant to be used in fromJson.', - element: '', + element: 'new', ) @JsonSerializable() class IgnoredFieldCtorClass { @@ -314,7 +314,7 @@ class IgnoreAndIncludeFromJsonFieldCtorClass { @ShouldThrow( 'Cannot populate the required constructor argument: ' '_privateField. It is assigned to a private field.', - element: '', + element: 'new', ) @JsonSerializable() class PrivateFieldCtorClass { diff --git a/json_serializable/test/src/json_converter_test_input.dart b/json_serializable/test/src/json_converter_test_input.dart index c06cc3fd2..1c082dd4c 100644 --- a/json_serializable/test/src/json_converter_test_input.dart +++ b/json_serializable/test/src/json_converter_test_input.dart @@ -129,7 +129,7 @@ class _BadConverter<T, S> implements JsonConverter<S, int> { @ShouldThrow( 'Found more than one matching converter for `Duration`.', - element: '', + element: 'new', ) @JsonSerializable() @_durationConverter @@ -154,7 +154,7 @@ class _DurationMillisecondConverter implements JsonConverter<Duration, int> { @ShouldThrow( 'Generators with constructor arguments are not supported.', - element: '', + element: 'new', ) @JsonSerializable() @_ConverterWithCtorParams(42) From 57e04de9a9cae1735f149481d9da4bede359a8e5 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Wed, 16 Jul 2025 13:46:31 -0700 Subject: [PATCH 564/569] Update to latest analyzer release and fix deprecations (#1510) --- analysis_options.yaml | 3 --- json_serializable/CHANGELOG.md | 4 ++++ json_serializable/lib/src/enum_utils.dart | 6 +++--- json_serializable/lib/src/helper_core.dart | 2 +- json_serializable/lib/src/json_key_utils.dart | 6 +++--- .../lib/src/type_helpers/json_converter_helper.dart | 10 +++++----- .../lib/src/type_helpers/json_helper.dart | 12 ++++++------ json_serializable/lib/src/utils.dart | 9 ++++----- json_serializable/pubspec.yaml | 4 ++-- 9 files changed, 28 insertions(+), 28 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index 24ad09c26..e6a95071e 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -4,9 +4,6 @@ include: package:dart_flutter_team_lints/analysis_options.yaml analyzer: language: strict-casts: true - errors: - # Analyzer v7.4.0 crazy - deprecated_member_use: ignore linter: rules: diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 34b778c9f..1f49c4ea3 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,7 @@ +## 6.10.0-wip + +- Required `analyzer: ^7.4.0`. + ## 6.10.0-dev - Switch to analyzer element2 model and `build: ^3.0.0-dev`. diff --git a/json_serializable/lib/src/enum_utils.dart b/json_serializable/lib/src/enum_utils.dart index c5d5d1b54..77518c13d 100644 --- a/json_serializable/lib/src/enum_utils.dart +++ b/json_serializable/lib/src/enum_utils.dart @@ -13,7 +13,7 @@ import 'json_literal_generator.dart'; import 'utils.dart'; String constMapName(DartType targetType) => - '_\$${targetType.element!.name}EnumMap'; + '_\$${targetType.element3!.name3}EnumMap'; /// If [targetType] is not an enum, return `null`. /// @@ -45,7 +45,7 @@ String? enumValueMapFromType( final items = enumMap.entries .map( (e) => - ' ${targetType.element!.name}.${e.key.name3}: ' + ' ${targetType.element3!.name3}.${e.key.name3}: ' '${jsonLiteralAsDart(e.value)},', ) .join(); @@ -57,7 +57,7 @@ Map<FieldElement2, Object?>? _enumMap( DartType targetType, { bool nullWithNoAnnotation = false, }) { - final targetTypeElement = targetType.element; + final targetTypeElement = targetType.element3; if (targetTypeElement == null) return null; final annotation = _jsonEnumChecker.firstAnnotationOf(targetTypeElement); final jsonEnum = _fromAnnotation(annotation); diff --git a/json_serializable/lib/src/helper_core.dart b/json_serializable/lib/src/helper_core.dart index b30bc36e0..43a78303e 100644 --- a/json_serializable/lib/src/helper_core.dart +++ b/json_serializable/lib/src/helper_core.dart @@ -79,7 +79,7 @@ $converterOrKeyInstructions } else if (field.type != error.type) { message = '$message because of type `${typeToCode(error.type)}`'; } else { - final element = error.type.element?.name; + final element = error.type.element3?.name3; todo = ''' To support the type `${element ?? error.type}` you can: diff --git a/json_serializable/lib/src/json_key_utils.dart b/json_serializable/lib/src/json_key_utils.dart index 4ab7742be..4d4f0a4c4 100644 --- a/json_serializable/lib/src/json_key_utils.dart +++ b/json_serializable/lib/src/json_key_utils.dart @@ -66,7 +66,7 @@ KeyConfig _from(FieldElement2 element, ClassConfig classAnnotation) { // literal, which is NOT supported! badType = 'Function'; } else if (!reader.isLiteral) { - badType = dartObject.type!.element?.name; + badType = dartObject.type!.element3?.name3; } if (badType != null) { @@ -194,7 +194,7 @@ KeyConfig _from(FieldElement2 element, ClassConfig classAnnotation) { (n) => n, ); - return '${annotationType.element!.name}.$enumValueName'; + return '${annotationType.element3!.name3}.$enumValueName'; } else { final defaultValueLiteral = literalForObject(fieldName, objectValue, []); if (defaultValueLiteral == null) { @@ -331,7 +331,7 @@ bool _includeIfNull( bool _interfaceTypesEqual(DartType a, DartType b) { if (a is InterfaceType && b is InterfaceType) { // Handle nullability case. Pretty sure this is fine for enums. - return a.element == b.element; + return a.element3 == b.element3; } return a == b; } diff --git a/json_serializable/lib/src/type_helpers/json_converter_helper.dart b/json_serializable/lib/src/type_helpers/json_converter_helper.dart index dc8a5c2ac..00ba9042f 100644 --- a/json_serializable/lib/src/type_helpers/json_converter_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_converter_helper.dart @@ -244,7 +244,7 @@ _JsonConvertData? _typeConverterFrom( if (match.genericTypeArg != null) { return _JsonConvertData.genericClass( - match.annotation.type!.element!.name!, + match.annotation.type!.element3!.name3!, match.genericTypeArg!, reviver.accessor, match.jsonType, @@ -253,7 +253,7 @@ _JsonConvertData? _typeConverterFrom( } return _JsonConvertData.className( - match.annotation.type!.element!.name!, + match.annotation.type!.element3!.name3!, reviver.accessor, match.jsonType, match.fieldType, @@ -291,7 +291,7 @@ _ConverterMatch? _compatibleMatch( return null; } - assert(jsonConverterSuper.element.typeParameters.length == 2); + assert(jsonConverterSuper.element3.typeParameters2.length == 2); assert(jsonConverterSuper.typeArguments.length == 2); final fieldType = jsonConverterSuper.typeArguments[0]; @@ -308,7 +308,7 @@ _ConverterMatch? _compatibleMatch( } if (fieldType is TypeParameterType && targetType is TypeParameterType) { - assert(annotation?.element is! PropertyAccessorElement2); + assert(annotation?.element2 is! PropertyAccessorElement2); assert(converterClassElement.typeParameters2.isNotEmpty); if (converterClassElement.typeParameters2.length > 1) { throw InvalidGenerationSourceError( @@ -323,7 +323,7 @@ _ConverterMatch? _compatibleMatch( annotation, constantValue, jsonConverterSuper.typeArguments[1], - '${targetType.element.name}${targetType.isNullableType ? '?' : ''}', + '${targetType.element3.name3}${targetType.isNullableType ? '?' : ''}', fieldType, ); } diff --git a/json_serializable/lib/src/type_helpers/json_helper.dart b/json_serializable/lib/src/type_helpers/json_helper.dart index 4b9b2621b..c2cd52a4c 100644 --- a/json_serializable/lib/src/type_helpers/json_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_helper.dart @@ -157,8 +157,8 @@ List<String> _helperParams( final args = <String>[]; for (var helperArg in rest) { - final typeParamIndex = type.element.typeParameters.indexOf( - helperArg.element, + final typeParamIndex = type.element3.typeParameters2.indexOf( + helperArg.element3, ); // TODO: throw here if `typeParamIndex` is -1 ? @@ -181,7 +181,7 @@ TypeParameterType _decodeHelper( type.normalParameterTypes.length == 1) { final funcReturnType = type.returnType; - if (param.name3 == fromJsonForName(funcReturnType.element!.name!)) { + if (param.name3 == fromJsonForName(funcReturnType.element3!.name3!)) { final funcParamType = type.normalParameterTypes.single; if ((funcParamType.isDartCoreObject && funcParamType.isNullableType) || @@ -212,7 +212,7 @@ TypeParameterType _encodeHelper( type.normalParameterTypes.length == 1) { final funcParamType = type.normalParameterTypes.single; - if (param.name3 == toJsonForName(funcParamType.element!.name!)) { + if (param.name3 == toJsonForName(funcParamType.element3!.name3!)) { if (funcParamType is TypeParameterType) { return funcParamType; } @@ -252,7 +252,7 @@ InterfaceType? _instantiate( InterfaceType classType, ) { final argTypes = ctorParamType.typeArguments.map((arg) { - final typeParamIndex = classType.element.typeParameters.indexWhere( + final typeParamIndex = classType.element3.typeParameters2.indexWhere( // TODO: not 100% sure `nullabilitySuffix` is right (e) => e.instantiate(nullabilitySuffix: arg.nullabilitySuffix) == arg, ); @@ -269,7 +269,7 @@ InterfaceType? _instantiate( return null; } - return ctorParamType.element.instantiate( + return ctorParamType.element3.instantiate( typeArguments: argTypes.cast<DartType>(), nullabilitySuffix: ctorParamType.nullabilitySuffix, ); diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index 42dffb9bf..f7a014ab1 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -3,7 +3,6 @@ // BSD-style license that can be found in the LICENSE file. import 'package:analyzer/dart/constant/value.dart'; -import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/element2.dart'; import 'package:analyzer/dart/element/type.dart'; import 'package:json_annotation/json_annotation.dart'; @@ -163,7 +162,7 @@ ConstructorElement2 constructorByName(ClassElement2 classElement, String name) { return ctor; } -/// If [targetType] is an enum, returns the [FieldElement] instances associated +/// If [targetType] is an enum, returns the [FieldElement2] instances associated /// with its values. /// /// Otherwise, `null`. @@ -177,7 +176,7 @@ Iterable<FieldElement2>? iterateEnumFields(DartType targetType) { extension DartTypeExtension on DartType { DartType promoteNonNullable() => - element?.library?.typeSystem.promoteToNonNull(this) ?? this; + element3?.library2?.typeSystem.promoteToNonNull(this) ?? this; String toStringNonNullable() { final val = getDisplayString(); @@ -209,7 +208,7 @@ String typeToCode(DartType type, {bool forceNullable = false}) { return 'dynamic'; } else if (type is InterfaceType) { return [ - type.element.name, + type.element3.name3, if (type.typeArguments.isNotEmpty) '<${type.typeArguments.map(typeToCode).join(', ')}>', (type.isNullableType || forceNullable) ? '?' : '', @@ -251,7 +250,7 @@ String? defaultDecodeLogic( extension ExecutableElementExtension on ExecutableElement2 { /// Returns the name of `this` qualified with the class name if it's a - /// [MethodElement]. + /// [MethodElement2]. String get qualifiedName { if (this is TopLevelFunctionElement) { return name3!; diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index c32d46ee8..06c449b15 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 6.10.0-dev +version: 6.10.0-wip description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. @@ -15,7 +15,7 @@ topics: resolution: workspace dependencies: - analyzer: '>=6.9.0 <8.0.0' + analyzer: ^7.4.0 async: ^2.10.0 build: ^3.0.0-dev build_config: ^1.1.0 From e1381aa217895bb9ed804447a3979a2eaf01e3d0 Mon Sep 17 00:00:00 2001 From: "Morgan :)" <davidmorgan@google.com> Date: Thu, 17 Jul 2025 19:47:01 +0200 Subject: [PATCH 565/569] Release 6.10.0. (#1511) --- json_serializable/CHANGELOG.md | 5 +---- json_serializable/pubspec.yaml | 8 ++++---- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 1f49c4ea3..f8c38271e 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,9 +1,6 @@ -## 6.10.0-wip +## 6.10.0 - Required `analyzer: ^7.4.0`. - -## 6.10.0-dev - - Switch to analyzer element2 model and `build: ^3.0.0-dev`. - Move `package:collection` to a dev dependency. - Use new `null-aware element` feature in generated code. diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index 06c449b15..d2184e4b9 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 6.10.0-wip +version: 6.10.0 description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. @@ -17,7 +17,7 @@ resolution: workspace dependencies: analyzer: ^7.4.0 async: ^2.10.0 - build: ^3.0.0-dev + build: ^3.0.0 build_config: ^1.1.0 dart_style: '>=2.3.7 <4.0.0' @@ -28,7 +28,7 @@ dependencies: path: ^1.9.0 pub_semver: ^2.1.4 pubspec_parse: ^1.0.0 - source_gen: ^3.0.0-dev + source_gen: ^3.0.0 source_helper: ^1.3.4 dev_dependencies: @@ -38,7 +38,7 @@ dev_dependencies: build_verify: ^3.0.0 collection: ^1.17.0 logging: ^1.0.0 - source_gen_test: ^1.3.0-dev + source_gen_test: ^1.3.0 test: ^1.24.4 test_descriptor: ^2.0.0 test_process: ^2.0.0 From 4c9e1e6678ad88cc6d47d6e530f09cb9d078ef1e Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Thu, 31 Jul 2025 11:33:38 -0700 Subject: [PATCH 566/569] CI fix to handle analyzer/SDK language version changing (#1513) * fix lint --- json_serializable/test/annotation_version_test.dart | 10 +++++++++- json_serializable/test/src/inheritance_test_input.dart | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/json_serializable/test/annotation_version_test.dart b/json_serializable/test/annotation_version_test.dart index 3bd7e989e..48e0749a5 100644 --- a/json_serializable/test/annotation_version_test.dart +++ b/json_serializable/test/annotation_version_test.dart @@ -189,7 +189,15 @@ class SomeClass{} } final output = lines.toString(); - final expectedWarningCount = message == null ? 0 : 1; + var expectedWarningCount = message == null ? 0 : 1; + + // If pkg:analyzer is out of sync with the current SDK, we can get a warning + // about the "SDK language version". In that case, just expect one more + // warning and proceed. + if (output.contains('W SDK language version ')) { + expectedWarningCount++; + } + final warningCount = _warningStartOfLine.allMatches(output).length; expect( warningCount, diff --git a/json_serializable/test/src/inheritance_test_input.dart b/json_serializable/test/src/inheritance_test_input.dart index 0aac74d82..f62ed38b4 100644 --- a/json_serializable/test/src/inheritance_test_input.dart +++ b/json_serializable/test/src/inheritance_test_input.dart @@ -81,6 +81,7 @@ class SubTypeWithAnnotatedFieldOverrideExtendsWithOverrides extends SuperType { int? get superReadWriteField => super.superReadWriteField; @override + // ignore: unnecessary_overrides set superReadWriteField(int? value) { super.superReadWriteField = value; } From 7d8d5106646e333cdd43b0f65848351fa92ab54c Mon Sep 17 00:00:00 2001 From: Fichtelcoder <de.frankenapps@gmail.com> Date: Mon, 4 Aug 2025 21:26:35 +0200 Subject: [PATCH 567/569] Fix bug running code generation for classes inheriting from `ListBase` (#1514) * Add regression test for #1512 --- json_serializable/lib/src/field_helpers.dart | 4 +-- .../test/integration/json_test_example.dart | 31 +++++++++++++++++++ .../test/integration/json_test_example.g.dart | 12 +++++++ .../json_test_example.g_any_map.dart | 31 +++++++++++++++++++ .../json_test_example.g_any_map.g.dart | 12 +++++++ 5 files changed, 88 insertions(+), 2 deletions(-) diff --git a/json_serializable/lib/src/field_helpers.dart b/json_serializable/lib/src/field_helpers.dart index 4539c7e53..c2de4ca54 100644 --- a/json_serializable/lib/src/field_helpers.dart +++ b/json_serializable/lib/src/field_helpers.dart @@ -58,9 +58,9 @@ class _FieldSet implements Comparable<_FieldSet> { /// preference for the getter if it's defined. int offsetFor(FieldElement2 e) { if (e.isSynthetic) { - return (e.getter2 ?? e.setter2)!.firstFragment.nameOffset2!; + return (e.getter2 ?? e.setter2)!.firstFragment.nameOffset2 ?? 0; } - return e.firstFragment.nameOffset2!; + return e.firstFragment.nameOffset2 ?? 0; } return offsetFor(a).compareTo(offsetFor(b)); diff --git a/json_serializable/test/integration/json_test_example.dart b/json_serializable/test/integration/json_test_example.dart index 963cdc27e..5b6a55810 100644 --- a/json_serializable/test/integration/json_test_example.dart +++ b/json_serializable/test/integration/json_test_example.dart @@ -266,3 +266,34 @@ class RegressionTestIssue1210 with RegressionTestIssue1210Mixin { Map<String, dynamic> toJson() => _$RegressionTestIssue1210ToJson(this); } + +@JsonSerializable() +class CustomList extends ListBase<String> { + // Regression test for issue: + // https://github.com/google/json_serializable.dart/issues/1512 + + final List<String> _innerList = []; + + CustomList(); + + @override + int get length => _innerList.length; + + @override + set length(int newLength) { + _innerList.length = newLength; + } + + @override + String operator [](int index) => _innerList[index]; + + @override + void operator []=(int index, String value) { + _innerList[index] = value; + } + + factory CustomList.fromJson(Map<String, dynamic> json) => + _$CustomListFromJson(json); + + Map<String, dynamic> toJson() => _$CustomListToJson(this); +} diff --git a/json_serializable/test/integration/json_test_example.g.dart b/json_serializable/test/integration/json_test_example.g.dart index 1f1b456ee..66b12fa7a 100644 --- a/json_serializable/test/integration/json_test_example.g.dart +++ b/json_serializable/test/integration/json_test_example.g.dart @@ -229,3 +229,15 @@ RegressionTestIssue1210 _$RegressionTestIssue1210FromJson( Map<String, dynamic> _$RegressionTestIssue1210ToJson( RegressionTestIssue1210 instance, ) => <String, dynamic>{'field': instance.field}; + +CustomList _$CustomListFromJson(Map<String, dynamic> json) => CustomList() + ..first = json['first'] as String + ..last = json['last'] as String + ..length = (json['length'] as num).toInt(); + +Map<String, dynamic> _$CustomListToJson(CustomList instance) => + <String, dynamic>{ + 'first': instance.first, + 'last': instance.last, + 'length': instance.length, + }; diff --git a/json_serializable/test/integration/json_test_example.g_any_map.dart b/json_serializable/test/integration/json_test_example.g_any_map.dart index f499eb13d..d4458416c 100644 --- a/json_serializable/test/integration/json_test_example.g_any_map.dart +++ b/json_serializable/test/integration/json_test_example.g_any_map.dart @@ -266,3 +266,34 @@ class RegressionTestIssue1210 with RegressionTestIssue1210Mixin { Map<String, dynamic> toJson() => _$RegressionTestIssue1210ToJson(this); } + +@JsonSerializable(anyMap: true) +class CustomList extends ListBase<String> { + // Regression test for issue: + // https://github.com/google/json_serializable.dart/issues/1512 + + final List<String> _innerList = []; + + CustomList(); + + @override + int get length => _innerList.length; + + @override + set length(int newLength) { + _innerList.length = newLength; + } + + @override + String operator [](int index) => _innerList[index]; + + @override + void operator []=(int index, String value) { + _innerList[index] = value; + } + + factory CustomList.fromJson(Map<String, dynamic> json) => + _$CustomListFromJson(json); + + Map<String, dynamic> toJson() => _$CustomListToJson(this); +} diff --git a/json_serializable/test/integration/json_test_example.g_any_map.g.dart b/json_serializable/test/integration/json_test_example.g_any_map.g.dart index f25c7971e..fdcd10b2d 100644 --- a/json_serializable/test/integration/json_test_example.g_any_map.g.dart +++ b/json_serializable/test/integration/json_test_example.g_any_map.g.dart @@ -227,3 +227,15 @@ RegressionTestIssue1210 _$RegressionTestIssue1210FromJson(Map json) => Map<String, dynamic> _$RegressionTestIssue1210ToJson( RegressionTestIssue1210 instance, ) => <String, dynamic>{'field': instance.field}; + +CustomList _$CustomListFromJson(Map json) => CustomList() + ..first = json['first'] as String + ..last = json['last'] as String + ..length = (json['length'] as num).toInt(); + +Map<String, dynamic> _$CustomListToJson(CustomList instance) => + <String, dynamic>{ + 'first': instance.first, + 'last': instance.last, + 'length': instance.length, + }; From 4298f97d1e6f4d0716a5d3ec98d4decbf97d04cc Mon Sep 17 00:00:00 2001 From: hhh <65709676+huanghui1998hhh@users.noreply.github.com> Date: Fri, 8 Aug 2025 07:03:00 +0800 Subject: [PATCH 568/569] Allow `@JsonKey` to be used on constructor parameters (#1505) --- json_annotation/CHANGELOG.md | 1 + json_annotation/lib/src/json_key.dart | 5 +- json_serializable/CHANGELOG.md | 4 ++ json_serializable/lib/src/json_key_utils.dart | 54 ++++++++++++----- .../lib/src/type_helpers/config_types.dart | 5 +- json_serializable/lib/src/utils.dart | 20 ++++--- json_serializable/pubspec.yaml | 2 +- .../test/json_serializable_test.dart | 2 + .../src/_json_serializable_test_input.dart | 1 + .../test/src/extends_jsonkey_override.dart | 59 +++++++++++++++++++ 10 files changed, 126 insertions(+), 27 deletions(-) create mode 100644 json_serializable/test/src/extends_jsonkey_override.dart diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index ae0b4d43d..c43793a76 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -1,6 +1,7 @@ ## 4.9.1-wip - Require Dart 3.8 +- Support `JsonKey` annotation on constructor parameters. ## 4.9.0 diff --git a/json_annotation/lib/src/json_key.dart b/json_annotation/lib/src/json_key.dart index 1dc7653bc..752219944 100644 --- a/json_annotation/lib/src/json_key.dart +++ b/json_annotation/lib/src/json_key.dart @@ -8,7 +8,10 @@ import 'allowed_keys_helpers.dart'; import 'json_serializable.dart'; /// An annotation used to specify how a field is serialized. -@Target({TargetKind.field, TargetKind.getter}) +/// +/// This annotation can be used on both class properties and constructor +/// parameters. +@Target({TargetKind.field, TargetKind.getter, TargetKind.parameter}) class JsonKey { /// The value to use if the source JSON does not contain this key or if the /// value is `null`. diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index f8c38271e..531396ea1 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,7 @@ +## 6.11.0 + +- Support `JsonKey` annotation on constructor parameters. + ## 6.10.0 - Required `analyzer: ^7.4.0`. diff --git a/json_serializable/lib/src/json_key_utils.dart b/json_serializable/lib/src/json_key_utils.dart index 4d4f0a4c4..99ea02842 100644 --- a/json_serializable/lib/src/json_key_utils.dart +++ b/json_serializable/lib/src/json_key_utils.dart @@ -24,14 +24,38 @@ KeyConfig jsonKeyForField(FieldElement2 field, ClassConfig classAnnotation) => ); KeyConfig _from(FieldElement2 element, ClassConfig classAnnotation) { - // If an annotation exists on `element` the source is a 'real' field. - // If the result is `null`, check the getter – it is a property. - // TODO: setters: github.com/google/json_serializable.dart/issues/24 final obj = jsonKeyAnnotation(element); + final ctorParam = classAnnotation.ctorParams + .where((e) => e.name3 == element.name3) + .singleOrNull; + final ctorObj = ctorParam == null + ? null + : jsonKeyAnnotationForCtorParam(ctorParam); + + ConstantReader fallbackObjRead(String field) { + if (ctorObj != null && !ctorObj.isNull) { + final ctorReadResult = ctorObj.read(field); + if (!ctorReadResult.isNull) { + if (!obj.isNull && !obj.read(field).isNull) { + log.warning( + 'Field `${element.name3}` has conflicting `JsonKey.$field` ' + 'annotations: both constructor parameter and class field have ' + 'this annotation. Using constructor parameter value.', + ); + } + + return ctorReadResult; + } + } + if (obj.isNull) { + return ConstantReader(null); + } + return obj.read(field); + } - final ctorParamDefault = classAnnotation.ctorParamDefaults[element.name3]; + final ctorParamDefault = ctorParam?.defaultValueCode; - if (obj.isNull) { + if (obj.isNull && (ctorObj == null || ctorObj.isNull)) { return _populateJsonKey( classAnnotation, element, @@ -121,7 +145,7 @@ KeyConfig _from(FieldElement2 element, ClassConfig classAnnotation) { /// either the annotated field is not an `enum` or `List` or if the value in /// [fieldName] is not an `enum` value. String? createAnnotationValue(String fieldName, {bool mustBeEnum = false}) { - final annotationValue = obj.read(fieldName); + final annotationValue = fallbackObjRead(fieldName); if (annotationValue.isNull) { return null; @@ -228,16 +252,17 @@ KeyConfig _from(FieldElement2 element, ClassConfig classAnnotation) { } String? readValueFunctionName; - final readValue = obj.read('readValue'); + final readValue = fallbackObjRead('readValue'); if (!readValue.isNull) { readValueFunctionName = readValue.objectValue .toFunctionValue2()! .qualifiedName; } - final ignore = obj.read('ignore').literalValue as bool?; - var includeFromJson = obj.read('includeFromJson').literalValue as bool?; - var includeToJson = obj.read('includeToJson').literalValue as bool?; + final ignore = fallbackObjRead('ignore').literalValue as bool?; + var includeFromJson = + fallbackObjRead('includeFromJson').literalValue as bool?; + var includeToJson = fallbackObjRead('includeToJson').literalValue as bool?; if (ignore != null) { if (includeFromJson != null) { @@ -262,11 +287,12 @@ KeyConfig _from(FieldElement2 element, ClassConfig classAnnotation) { classAnnotation, element, defaultValue: defaultValue ?? ctorParamDefault, - disallowNullValue: obj.read('disallowNullValue').literalValue as bool?, - includeIfNull: obj.read('includeIfNull').literalValue as bool?, - name: obj.read('name').literalValue as String?, + disallowNullValue: + fallbackObjRead('disallowNullValue').literalValue as bool?, + includeIfNull: fallbackObjRead('includeIfNull').literalValue as bool?, + name: fallbackObjRead('name').literalValue as String?, readValueFunctionName: readValueFunctionName, - required: obj.read('required').literalValue as bool?, + required: fallbackObjRead('required').literalValue as bool?, unknownEnumValue: createAnnotationValue( 'unknownEnumValue', mustBeEnum: true, diff --git a/json_serializable/lib/src/type_helpers/config_types.dart b/json_serializable/lib/src/type_helpers/config_types.dart index 80d258589..bce6e0ec8 100644 --- a/json_serializable/lib/src/type_helpers/config_types.dart +++ b/json_serializable/lib/src/type_helpers/config_types.dart @@ -3,6 +3,7 @@ // BSD-style license that can be found in the LICENSE file. import 'package:analyzer/dart/constant/value.dart'; +import 'package:analyzer/dart/element/element2.dart'; import 'package:json_annotation/json_annotation.dart'; /// Represents values from [JsonKey] when merged with local configuration. @@ -57,7 +58,7 @@ class ClassConfig { final bool genericArgumentFactories; final bool ignoreUnannotated; final bool includeIfNull; - final Map<String, String> ctorParamDefaults; + final List<FormalParameterElement> ctorParams; final List<DartObject> converters; const ClassConfig({ @@ -76,7 +77,7 @@ class ClassConfig { required this.ignoreUnannotated, required this.includeIfNull, this.converters = const [], - this.ctorParamDefaults = const {}, + this.ctorParams = const [], }); factory ClassConfig.fromJsonSerializable(JsonSerializable config) => diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index f7a014ab1..132207ef7 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -14,6 +14,9 @@ import 'type_helpers/config_types.dart'; const _jsonKeyChecker = TypeChecker.fromRuntime(JsonKey); +/// If an annotation exists on `element` the source is a 'real' field. +/// If the result is `null`, check the getter – it is a property. +// TODO: setters: github.com/google/json_serializable.dart/issues/24 DartObject? _jsonKeyAnnotation(FieldElement2 element) => _jsonKeyChecker.firstAnnotationOf(element) ?? (element.getter2 == null @@ -27,6 +30,9 @@ ConstantReader jsonKeyAnnotation(FieldElement2 element) => bool hasJsonKeyAnnotation(FieldElement2 element) => _jsonKeyAnnotation(element) != null; +ConstantReader jsonKeyAnnotationForCtorParam(FormalParameterElement element) => + ConstantReader(_jsonKeyChecker.firstAnnotationOf(element)); + Never throwUnsupported(FieldElement2 element, String message) => throw InvalidGenerationSourceError( 'Error with `@JsonKey` on the `${element.name3}` field. $message', @@ -82,7 +88,7 @@ ClassConfig mergeConfig( required ClassElement2 classElement, }) { final annotation = _valueForAnnotation(reader); - assert(config.ctorParamDefaults.isEmpty); + assert(config.ctorParams.isEmpty); final constructor = annotation.constructor ?? config.constructor; final constructorInstance = _constructorByNameOrNull( @@ -90,13 +96,9 @@ ClassConfig mergeConfig( constructor, ); - final paramDefaultValueMap = constructorInstance == null - ? <String, String>{} - : Map<String, String>.fromEntries( - constructorInstance.formalParameters - .where((element) => element.hasDefaultValue) - .map((e) => MapEntry(e.name3!, e.defaultValueCode!)), - ); + final ctorParams = <FormalParameterElement>[ + ...?constructorInstance?.formalParameters, + ]; final converters = reader.read('converters'); @@ -120,7 +122,7 @@ ClassConfig mergeConfig( config.genericArgumentFactories), ignoreUnannotated: annotation.ignoreUnannotated ?? config.ignoreUnannotated, includeIfNull: annotation.includeIfNull ?? config.includeIfNull, - ctorParamDefaults: paramDefaultValueMap, + ctorParams: ctorParams, converters: converters.isNull ? const [] : converters.listValue, ); } diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index d2184e4b9..a9d4c9fb1 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 6.10.0 +version: 6.11.0 description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. diff --git a/json_serializable/test/json_serializable_test.dart b/json_serializable/test/json_serializable_test.dart index b6ff36789..0f58f71ba 100644 --- a/json_serializable/test/json_serializable_test.dart +++ b/json_serializable/test/json_serializable_test.dart @@ -49,6 +49,8 @@ const _expectedAnnotatedTests = { 'BadToFuncReturnType', 'BadTwoRequiredPositional', 'CtorDefaultValueAndJsonKeyDefaultValue', + 'CtorParamJsonKey', + 'CtorParamJsonKeyWithExtends', 'DefaultDoubleConstants', 'DefaultWithConstObject', 'DefaultWithDisallowNullRequiredClass', diff --git a/json_serializable/test/src/_json_serializable_test_input.dart b/json_serializable/test/src/_json_serializable_test_input.dart index 09deed525..20cd8739d 100644 --- a/json_serializable/test/src/_json_serializable_test_input.dart +++ b/json_serializable/test/src/_json_serializable_test_input.dart @@ -14,6 +14,7 @@ part 'constants_copy.dart'; part 'core_subclass_type_input.dart'; part 'default_value_input.dart'; part 'field_namer_input.dart'; +part 'extends_jsonkey_override.dart'; part 'generic_test_input.dart'; part 'inheritance_test_input.dart'; part 'json_converter_test_input.dart'; diff --git a/json_serializable/test/src/extends_jsonkey_override.dart b/json_serializable/test/src/extends_jsonkey_override.dart new file mode 100644 index 000000000..04c1c5b34 --- /dev/null +++ b/json_serializable/test/src/extends_jsonkey_override.dart @@ -0,0 +1,59 @@ +// @dart=3.8 + +part of '_json_serializable_test_input.dart'; + +// https://github.com/google/json_serializable.dart/issues/1437 +@ShouldGenerate( + r''' +CtorParamJsonKey _$CtorParamJsonKeyFromJson(Map<String, dynamic> json) => + CtorParamJsonKey( + attributeOne: json['first'] as String, + attributeTwo: json['second'] as String, + ); + +Map<String, dynamic> _$CtorParamJsonKeyToJson(CtorParamJsonKey instance) => + <String, dynamic>{ + 'first': instance.attributeOne, + 'second': instance.attributeTwo, + }; +''', + expectedLogItems: [ + 'Field `attributeOne` has conflicting `JsonKey.name` annotations: both ' + 'constructor parameter and class field have this annotation. Using ' + 'constructor parameter value.', + ], +) +@JsonSerializable() +class CtorParamJsonKey { + CtorParamJsonKey({ + @JsonKey(name: 'first') required this.attributeOne, + @JsonKey(name: 'second') required this.attributeTwo, + }); + + @JsonKey(name: 'fake_first') + final String attributeOne; + final String attributeTwo; +} + +@ShouldGenerate(r''' +CtorParamJsonKeyWithExtends _$CtorParamJsonKeyWithExtendsFromJson( + Map<String, dynamic> json, +) => CtorParamJsonKeyWithExtends( + attributeOne: json['fake_first'] as String, + attributeTwo: json['two'] as String, +); + +Map<String, dynamic> _$CtorParamJsonKeyWithExtendsToJson( + CtorParamJsonKeyWithExtends instance, +) => <String, dynamic>{ + 'fake_first': instance.attributeOne, + 'two': instance.attributeTwo, +}; +''') +@JsonSerializable() +class CtorParamJsonKeyWithExtends extends CtorParamJsonKey { + CtorParamJsonKeyWithExtends({ + required super.attributeOne, + @JsonKey(name: 'two') required super.attributeTwo, + }); +} From 426f5a2b9fb5cb0a19feff2a7576bcc955341a80 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@users.noreply.github.com> Date: Mon, 11 Aug 2025 13:09:35 -0700 Subject: [PATCH 569/569] Support latest dependencies (#1516) --- _test_yaml/pubspec.yaml | 10 +++++----- analysis_options.yaml | 3 +++ checked_yaml/CHANGELOG.md | 4 ++++ checked_yaml/pubspec.yaml | 10 +++++----- example/README.md | 4 ++-- example/pubspec.yaml | 8 ++++---- example/test/readme_test.dart | 4 ++-- json_annotation/CHANGELOG.md | 3 ++- json_annotation/pubspec.yaml | 2 +- json_serializable/CHANGELOG.md | 6 +++++- json_serializable/pubspec.yaml | 20 ++++++++++---------- shared_test/pubspec.yaml | 2 +- 12 files changed, 44 insertions(+), 32 deletions(-) diff --git a/_test_yaml/pubspec.yaml b/_test_yaml/pubspec.yaml index a2496e7ce..e9d4c7ec1 100644 --- a/_test_yaml/pubspec.yaml +++ b/_test_yaml/pubspec.yaml @@ -9,11 +9,11 @@ resolution: workspace dev_dependencies: _json_serial_shared_test: path: ../shared_test - build_runner: ^2.2.1 + build_runner: ^2.6.0 build_verify: ^3.0.0 - checked_yaml: ^2.0.4-wip + checked_yaml: ^2.0.4 json_annotation: ^4.9.0 json_serializable: ^6.8.0 - path: ^1.8.2 - test: ^1.21.6 - yaml: ^3.0.0 + path: ^1.9.0 + test: ^1.25.9 + yaml: ^3.1.2 diff --git a/analysis_options.yaml b/analysis_options.yaml index e6a95071e..83c1850b7 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -2,6 +2,9 @@ include: package:dart_flutter_team_lints/analysis_options.yaml analyzer: + errors: + # For source_gen and analyzer deprecations + deprecated_member_use: ignore language: strict-casts: true diff --git a/checked_yaml/CHANGELOG.md b/checked_yaml/CHANGELOG.md index 567d14795..5f4e47d88 100644 --- a/checked_yaml/CHANGELOG.md +++ b/checked_yaml/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.0.5-wip + +- Require `yaml: ^3.1.2` + ## 2.0.4 - Require Dart 3.8 diff --git a/checked_yaml/pubspec.yaml b/checked_yaml/pubspec.yaml index 6195805df..82b34cbe1 100644 --- a/checked_yaml/pubspec.yaml +++ b/checked_yaml/pubspec.yaml @@ -1,5 +1,5 @@ name: checked_yaml -version: 2.0.4 +version: 2.0.5-wip description: >- Generate more helpful exceptions when decoding YAML documents using @@ -20,12 +20,12 @@ resolution: workspace dependencies: json_annotation: ^4.3.0 source_span: ^1.8.0 - yaml: ^3.0.0 + yaml: ^3.1.2 dev_dependencies: - build_runner: ^2.0.6 + build_runner: ^2.6.0 build_verify: ^3.0.0 json_serializable: ^6.0.0 - path: ^1.8.0 - test: ^1.17.10 + path: ^1.9.0 + test: ^1.25.9 test_process: ^2.0.0 diff --git a/example/README.md b/example/README.md index 7eff2e695..92da62e03 100644 --- a/example/README.md +++ b/example/README.md @@ -8,8 +8,8 @@ dependencies: json_annotation: ^4.9.0 dev_dependencies: - build_runner: ^2.3.3 - json_serializable: ^6.8.0 + build_runner: ^2.6.0 + json_serializable: ^6.10.0 ``` Annotate your code with classes defined in diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 392a1cd2f..3fee74647 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -15,14 +15,14 @@ dev_dependencies: path: ../shared_test # REQUIRED! - build_runner: ^2.3.3 + build_runner: ^2.6.0 # Used by tests. Not required to use `json_serializable`. build_verify: ^3.0.0 # REQUIRED! - json_serializable: ^6.8.0 + json_serializable: ^6.10.0 # Not required to use `json_serializable`. - path: ^1.8.0 - test: ^1.21.6 + path: ^1.9.0 + test: ^1.25.9 diff --git a/example/test/readme_test.dart b/example/test/readme_test.dart index 9ab00e93b..c30313e06 100644 --- a/example/test/readme_test.dart +++ b/example/test/readme_test.dart @@ -28,6 +28,6 @@ dependencies: json_annotation: ^4.9.0 dev_dependencies: - build_runner: ^2.3.3 - json_serializable: ^6.8.0 + build_runner: ^2.6.0 + json_serializable: ^6.10.0 '''; diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index c43793a76..decb812dc 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -1,7 +1,8 @@ ## 4.9.1-wip -- Require Dart 3.8 - Support `JsonKey` annotation on constructor parameters. +- Require `meta: ^1.15.0` +- Require Dart 3.8 ## 4.9.0 diff --git a/json_annotation/pubspec.yaml b/json_annotation/pubspec.yaml index f1cd2c79b..eaae8a868 100644 --- a/json_annotation/pubspec.yaml +++ b/json_annotation/pubspec.yaml @@ -16,4 +16,4 @@ environment: resolution: workspace dependencies: - meta: ^1.4.0 + meta: ^1.15.0 diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 531396ea1..cbd317849 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,6 +1,10 @@ -## 6.11.0 +## 6.11.0-wip - Support `JsonKey` annotation 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` ## 6.10.0 diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index a9d4c9fb1..c6e15f772 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 6.11.0 +version: 6.11.0-wip description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. @@ -15,31 +15,31 @@ topics: resolution: workspace dependencies: - analyzer: ^7.4.0 + analyzer: '>=7.4.0 <9.0.0' async: ^2.10.0 build: ^3.0.0 build_config: ^1.1.0 - dart_style: '>=2.3.7 <4.0.0' + dart_style: ^3.0.0 # Use a tight version constraint to ensure that a constraint on # `json_annotation` properly constrains all features it provides. json_annotation: '>=4.9.0 <4.10.0' - meta: ^1.14.0 + meta: ^1.15.0 path: ^1.9.0 pub_semver: ^2.1.4 pubspec_parse: ^1.0.0 source_gen: ^3.0.0 - source_helper: ^1.3.4 + source_helper: ^1.3.6 dev_dependencies: _json_serial_shared_test: path: ../shared_test - build_runner: ^2.4.6 + build_runner: ^2.6.0 build_verify: ^3.0.0 - collection: ^1.17.0 - logging: ^1.0.0 + collection: ^1.19.0 + logging: ^1.2.0 source_gen_test: ^1.3.0 - test: ^1.24.4 + test: ^1.25.9 test_descriptor: ^2.0.0 test_process: ^2.0.0 - yaml: ^3.0.0 + yaml: ^3.1.2 diff --git a/shared_test/pubspec.yaml b/shared_test/pubspec.yaml index 9b6990a4b..cc11f4b5c 100644 --- a/shared_test/pubspec.yaml +++ b/shared_test/pubspec.yaml @@ -7,4 +7,4 @@ resolution: workspace dependencies: stack_trace: ^1.10.0 - test: ^1.6.0 + test: ^1.25.9